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