xref: /titanic_44/usr/src/cmd/cmd-inet/usr.lib/in.ndpd/tables.h (revision 39c23413b8df94a95f67b34cfd4a4dfc3fd0b48d)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_NDPD_TABLES_H
27 #define	_NDPD_TABLES_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #include <protocols/ndpd.h>
36 
37 enum adv_states { NO_ADV = 0, REG_ADV, INIT_ADV, SOLICIT_ADV, FINAL_ADV };
38 enum adv_events { ADV_OFF, START_INIT_ADV, START_FINAL_ADV, RECEIVED_SOLICIT,
39 			ADV_TIMER };
40 
41 enum solicit_states { NO_SOLICIT = 0, INIT_SOLICIT, DONE_SOLICIT };
42 enum solicit_events { SOLICIT_OFF, START_INIT_SOLICIT, SOL_TIMER,
43 			SOLICIT_DONE };
44 /*
45  * A doubly linked list of all physical interfaces that each contain a
46  * doubly linked list of prefixes (i.e. logical interfaces) and default
47  * routers.
48  */
49 struct phyint {
50 	struct phyint	*pi_next;
51 	struct phyint	*pi_prev;
52 	struct prefix	*pi_prefix_list;	/* Doubly linked prefixes */
53 	struct router	*pi_router_list;	/* Doubly linked routers */
54 	struct adv_prefix *pi_adv_prefix_list;	/* Doubly linked adv.prefixes */
55 
56 	uint_t		pi_index;		/* Identifier > 0 */
57 	char		pi_name[LIFNAMSIZ];	/* Used to identify it */
58 	int		pi_sock;		/* For sending and receiving */
59 	struct in6_addr	pi_ifaddr;		/* Local address */
60 	uint_t		pi_flags;		/* IFF_* flags */
61 	uint_t		pi_hdw_addr_len;
62 	uchar_t		pi_hdw_addr[ND_MAX_HDW_LEN];
63 	uint_t		pi_mtu;			/* From SIOCGLIFMTU */
64 	struct in6_addr pi_token;
65 	uint_t		pi_token_length;
66 	struct in6_addr	pi_tmp_token;		/* For RFC3041 addrs */
67 	struct in6_addr	pi_dst_token;		/* For POINTOPOINT */
68 
69 	uint_t		pi_state;		/* PI_* below */
70 	uint_t		pi_kernel_state;	/* PI_* below */
71 	uint_t		pi_num_k_routers;	/* # routers in kernel */
72 	uint_t		pi_reach_time_since_random;	/* In milliseconds */
73 
74 	/* Applies if pi_AdvSendAdvertisements */
75 	uint_t		pi_adv_time_left;	/* In milliseconds */
76 	uint_t		pi_adv_time_since_sent;	/* In milliseconds */
77 	enum adv_states	pi_adv_state;
78 	uint_t		pi_adv_count;
79 
80 	/* Applies if not pi_AdvSendAdvertisements */
81 	uint_t		pi_sol_time_left;	/* In milliseconds */
82 	enum solicit_states pi_sol_state;
83 	uint_t		pi_sol_count;
84 
85 	/* Interface specific configurable variables */
86 	struct confvar	pi_config[I_IFSIZE];
87 #define	pi_DupAddrDetectTransmits pi_config[I_DupAddrDetectTransmits].cf_value
88 #define	pi_AdvSendAdvertisements pi_config[I_AdvSendAdvertisements].cf_value
89 #define	pi_MaxRtrAdvInterval	pi_config[I_MaxRtrAdvInterval].cf_value
90 #define	pi_MinRtrAdvInterval	pi_config[I_MinRtrAdvInterval].cf_value
91 #define	pi_AdvManagedFlag	pi_config[I_AdvManagedFlag].cf_value
92 #define	pi_AdvOtherConfigFlag	pi_config[I_AdvOtherConfigFlag].cf_value
93 #define	pi_AdvLinkMTU		pi_config[I_AdvLinkMTU].cf_value
94 #define	pi_AdvReachableTime	pi_config[I_AdvReachableTime].cf_value
95 #define	pi_AdvRetransTimer	pi_config[I_AdvRetransTimer].cf_value
96 #define	pi_AdvCurHopLimit	pi_config[I_AdvCurHopLimit].cf_value
97 #define	pi_AdvDefaultLifetime	pi_config[I_AdvDefaultLifetime].cf_value
98 #define	pi_StatelessAddrConf	pi_config[I_StatelessAddrConf].cf_value
99 #define	pi_TmpAddrsEnabled	pi_config[I_TmpAddrsEnabled].cf_value
100 #define	pi_TmpValidLifetime	pi_config[I_TmpValidLifetime].cf_value
101 #define	pi_TmpPreferredLifetime	pi_config[I_TmpPreferredLifetime].cf_value
102 #define	pi_TmpRegenAdvance	pi_config[I_TmpRegenAdvance].cf_value
103 #define	pi_TmpMaxDesyncFactor	pi_config[I_TmpMaxDesyncFactor].cf_value
104 
105 	/* Recorded variables for RFC3041 addresses */
106 	uint_t		pi_TmpDesyncFactor;		/* In milliseconds */
107 	uint_t		pi_TmpRegenCountdown;		/* In milliseconds */
108 
109 	/* Recorded variables on node/host */
110 	uint_t		pi_LinkMTU;
111 	uint_t		pi_CurHopLimit;
112 	uint_t		pi_BaseReachableTime;		/* In milliseconds */
113 	uint_t		pi_ReachableTime;		/* In milliseconds */
114 	/*
115 	 * The above value should be a uniformly-distributed random
116 	 * value between ND_MIN_RANDOM_FACTOR and
117 	 * ND_MAX_RANDOM_FACTOR times BaseReachableTime
118 	 * milliseconds.  A new random value should be
119 	 * calculated when BaseReachableTime changes (due to
120 	 * Router Advertisements) or at least every few hours
121 	 * even if no Router Advertisements are received.
122 	 * Tracked using pi_each_time_since_random.
123 	 */
124 	uint_t		pi_RetransTimer;		/* In milliseconds */
125 	char		*pi_group_name;
126 };
127 
128 /*
129  * pi_state/pr_kernel_state values
130  */
131 #define	PI_PRESENT		0x01
132 #define	PI_JOINED_ALLNODES	0x02	/* allnodes multicast joined */
133 #define	PI_JOINED_ALLROUTERS	0x04	/* allrouters multicast joined */
134 
135 /*
136  * Prefix configuration variable indices
137  */
138 #define	I_AdvValidLifetime	0	/* In seconds */
139 #define	I_AdvOnLinkFlag		1
140 #define	I_AdvPreferredLifetime	2	/* In seconds */
141 #define	I_AdvAutonomousFlag	3
142 #define	I_AdvValidExpiration	4	/* Seconds left */
143 #define	I_AdvPreferredExpiration 5	/* Seconds left */
144 #define	I_PREFIXSIZE		6	/* # of variables */
145 
146 /*
147  * A doubly linked list of prefixes for onlink and addrconf.
148  */
149 struct prefix {
150 	struct prefix	*pr_next;	/* Next prefix for this physical */
151 	struct prefix	*pr_prev;	/* Prev prefix for this physical */
152 	struct phyint	*pr_physical;	/* Back pointer */
153 
154 	struct in6_addr	pr_prefix;	/* Used to indentify prefix */
155 	uint_t		pr_prefix_len;	/* Num bits valid */
156 
157 	char		pr_name[LIFNAMSIZ];
158 	struct in6_addr	pr_address;
159 	uint64_t	pr_flags;	/* IFF_* flags */
160 
161 	uint_t		pr_state;	/* PR_ONLINK | PR_AUTO etc */
162 	uint_t		pr_kernel_state; /* PR_ONLINK | PR_AUTO etc */
163 	boolean_t	pr_in_use;	/* To detect removed prefixes */
164 
165 	/* Recorded variables on node/host */
166 	uint_t		pr_ValidLifetime;	/* In ms w/ 2 hour rule */
167 	uint_t		pr_PreferredLifetime;	/* In millseconds */
168 	uint_t		pr_OnLinkLifetime;	/* ms valid w/o 2 hour rule */
169 	boolean_t	pr_OnLinkFlag;
170 	boolean_t	pr_AutonomousFlag;
171 
172 	uint_t		pr_CreateTime;		/* tmpaddr creation time */
173 						/* in SECONDS */
174 	uint_t		pr_attempts;	/* attempts to configure */
175 };
176 
177 /*
178  * Flags used for pr_kernel_state and pr_state where the latter is
179  * user-level state.
180  */
181 #define	PR_ONLINK	0x01		/* On-link */
182 #define	PR_AUTO		0x02		/* Stateless addrconf */
183 #define	PR_DEPRECATED	0x04		/* Address is deprecated */
184 #define	PR_STATIC	0x08		/* Not created by ndpd */
185 
186 /*
187  * The sum of all possible state string lengths, plus terminating
188  * null character; if new states are added, this needs to be updated.
189  * Useful for passing an appropriately sized buffer to prefix_print_state().
190  *
191  * Current strings: "ONLINK ", "AUTO ", "DEPRECATED ", "STATIC ", "\n"
192  *                      7     +   5    +     11       +    7     +  1
193  */
194 #define	PREFIX_STATESTRLEN	31
195 
196 /* Prefix used for storing advertisement specific stuff */
197 struct adv_prefix {
198 	struct adv_prefix	*adv_pr_next;	/* Next prefix */
199 	struct adv_prefix	*adv_pr_prev;	/* Prev prefix */
200 	struct phyint		*adv_pr_physical;	/* Back pointer */
201 
202 	struct in6_addr		adv_pr_prefix;	/* Used to indentify prefix */
203 	uint_t			adv_pr_prefix_len;	/* Num bits valid */
204 
205 	/* Used when sending advertisements */
206 	struct confvar		adv_pr_config[I_PREFIXSIZE];
207 #define	adv_pr_AdvValidLifetime	adv_pr_config[I_AdvValidLifetime].cf_value
208 #define	adv_pr_AdvOnLinkFlag	adv_pr_config[I_AdvOnLinkFlag].cf_value
209 #define	adv_pr_AdvPreferredLifetime	\
210 			adv_pr_config[I_AdvPreferredLifetime].cf_value
211 #define	adv_pr_AdvAutonomousFlag	\
212 			adv_pr_config[I_AdvAutonomousFlag].cf_value
213 #define	adv_pr_AdvValidExpiration	\
214 			adv_pr_config[I_AdvValidExpiration].cf_value
215 #define	adv_pr_AdvPreferredExpiration	\
216 			adv_pr_config[I_AdvPreferredExpiration].cf_value
217 	/* The two below are set if the timers decrement in real time */
218 #define	adv_pr_AdvValidRealTime		\
219 			adv_pr_config[I_AdvValidExpiration].cf_notdefault
220 #define	adv_pr_AdvPreferredRealTime	\
221 			adv_pr_config[I_AdvPreferredExpiration].cf_notdefault
222 };
223 
224 /*
225  * Doubly-linked list of default routers on a phyint.
226  */
227 struct router {
228 	struct router	*dr_next;	/* Next router for this physical */
229 	struct router	*dr_prev;	/* Prev router for this physical */
230 	struct phyint	*dr_physical;	/* Back pointer */
231 
232 	struct in6_addr	dr_address;	/* Used to identify the router */
233 	uint_t		dr_lifetime;	/* In milliseconds */
234 	boolean_t	dr_inkernel;	/* Route added to kernel */
235 };
236 
237 /*
238  * Globals
239  */
240 extern struct phyint *phyints;
241 extern int num_of_phyints;
242 
243 
244 /*
245  * Functions
246  */
247 extern uint_t		getcurrenttime(void);
248 
249 extern struct phyint	*phyint_lookup(char *name);
250 extern struct phyint	*phyint_lookup_on_index(uint_t ifindex);
251 extern struct phyint	*phyint_create(char *name);
252 extern int		phyint_init_from_k(struct phyint *pi);
253 extern void		phyint_delete(struct phyint *pi);
254 extern uint_t		phyint_timer(struct phyint *pi, uint_t elapsed);
255 extern void		phyint_print_all(void);
256 extern void		phyint_reach_random(struct phyint *pi,
257 			    boolean_t set_needed);
258 extern void		phyint_cleanup(struct phyint *pi);
259 
260 extern boolean_t	tmptoken_create(struct phyint *pi);
261 extern void		tmptoken_delete(struct phyint *pi);
262 extern uint_t		tmptoken_timer(struct phyint *pi, uint_t elapsed);
263 extern boolean_t	token_equal(struct in6_addr t1, struct in6_addr t2,
264 			    int bits);
265 
266 extern struct prefix	*prefix_create(struct phyint *pi, struct in6_addr addr,
267 			    int addrlen, uint64_t flags);
268 extern struct prefix	*prefix_lookup_name(struct phyint *pi, char *name);
269 extern struct prefix	*prefix_lookup_addr_match(struct prefix *pr);
270 extern struct prefix	*prefix_create_name(struct phyint *pi, char *name);
271 extern int		prefix_init_from_k(struct prefix *pr);
272 extern void		prefix_delete(struct prefix *pr);
273 extern boolean_t	prefix_equal(struct in6_addr p1, struct in6_addr p2,
274 			    int bits);
275 extern void		prefix_update_k(struct prefix *pr);
276 extern uint_t		prefix_timer(struct prefix *pr, uint_t elapsed);
277 extern uint_t		adv_prefix_timer(struct adv_prefix *adv_pr,
278 			    uint_t elapsed);
279 extern boolean_t	prefix_token_match(struct phyint *pi,
280 			    struct prefix *pr, uint64_t flags);
281 extern struct prefix	*prefix_lookup_addr(struct phyint *pi,
282 			    struct in6_addr prefix);
283 
284 extern struct adv_prefix *adv_prefix_lookup(struct phyint *pi,
285 			    struct in6_addr addr, int addrlen);
286 extern struct adv_prefix *adv_prefix_create(struct phyint *pi,
287 			    struct in6_addr addr, int addrlen);
288 
289 extern struct router	*router_lookup(struct phyint *pi, struct in6_addr addr);
290 extern struct router	*router_create(struct phyint *pi, struct in6_addr addr,
291 			    uint_t lifetime);
292 extern void		router_update_k(struct router *dr);
293 extern uint_t		router_timer(struct router *dr, uint_t elapsed);
294 
295 
296 extern void	check_to_advertise(struct phyint *pi, enum adv_events event);
297 extern void	check_to_solicit(struct phyint *pi,
298 		    enum solicit_events event);
299 extern uint_t	advertise_event(struct phyint *pi, enum adv_events event,
300 		    uint_t elapsed);
301 extern uint_t	solicit_event(struct phyint *pi, enum solicit_events event,
302 		    uint_t elapsed);
303 
304 extern void	print_route_sol(char *str, struct phyint *pi,
305 		    struct nd_router_solicit *rs, int len,
306 		    struct sockaddr_in6 *addr);
307 extern void	print_route_adv(char *str, struct phyint *pi,
308 		    struct nd_router_advert *ra, int len,
309 		    struct sockaddr_in6 *addr);
310 extern void	print_iflist(struct confvar *confvar);
311 extern void	print_prefixlist(struct confvar *confvar);
312 
313 extern void	in_data(struct phyint *pi);
314 
315 extern void	incoming_ra(struct phyint *pi, struct nd_router_advert *ra,
316 		    int len, struct sockaddr_in6 *from, boolean_t loopback);
317 
318 extern boolean_t incoming_prefix_addrconf_process(struct phyint *pi,
319 		    struct prefix *pr, uchar_t *opt,
320 		    struct sockaddr_in6 *from, boolean_t loopback,
321 		    boolean_t new_prefix);
322 
323 extern void	incoming_prefix_onlink_process(struct prefix *pr,
324 		    uchar_t *opt);
325 
326 #ifdef	__cplusplus
327 }
328 #endif
329 
330 #endif	/* _NDPD_TABLES_H */
331