xref: /illumos-gate/usr/src/cmd/cmd-inet/usr.lib/in.ndpd/tables.h (revision f63f7506be0210195779706f51c58646e568cc40)
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 	uint_t		pr_attempts;	/* attempts to configure */
207 };
208 
209 /*
210  * Flags used for pr_kernel_state and pr_state where the latter is
211  * user-level state.
212  */
213 #define	PR_ONLINK	0x01		/* On-link */
214 #define	PR_AUTO		0x02		/* Stateless addrconf */
215 #define	PR_DEPRECATED	0x04		/* Address is deprecated */
216 #define	PR_STATIC	0x08		/* Not created by ndpd */
217 
218 /*
219  * The sum of all possible state string lengths, plus terminating
220  * null character; if new states are added, this needs to be updated.
221  * Useful for passing an appropriately sized buffer to prefix_print_state().
222  *
223  * Current strings: "ONLINK ", "AUTO ", "DEPRECATED ", "STATIC ", "\n"
224  *                      7     +   5    +     11       +    7     +  1
225  */
226 #define	PREFIX_STATESTRLEN	31
227 
228 /* Prefix used for storing advertisement specific stuff */
229 struct adv_prefix {
230 	struct adv_prefix	*adv_pr_next;	/* Next prefix */
231 	struct adv_prefix	*adv_pr_prev;	/* Prev prefix */
232 	struct phyint		*adv_pr_physical;	/* Back pointer */
233 
234 	struct in6_addr		adv_pr_prefix;	/* Used to indentify prefix */
235 	uint_t			adv_pr_prefix_len;	/* Num bits valid */
236 
237 	/* Used when sending advertisements */
238 	struct confvar		adv_pr_config[I_PREFIXSIZE];
239 #define	adv_pr_AdvValidLifetime	adv_pr_config[I_AdvValidLifetime].cf_value
240 #define	adv_pr_AdvOnLinkFlag	adv_pr_config[I_AdvOnLinkFlag].cf_value
241 #define	adv_pr_AdvPreferredLifetime	\
242 			adv_pr_config[I_AdvPreferredLifetime].cf_value
243 #define	adv_pr_AdvAutonomousFlag	\
244 			adv_pr_config[I_AdvAutonomousFlag].cf_value
245 #define	adv_pr_AdvValidExpiration	\
246 			adv_pr_config[I_AdvValidExpiration].cf_value
247 #define	adv_pr_AdvPreferredExpiration	\
248 			adv_pr_config[I_AdvPreferredExpiration].cf_value
249 	/* The two below are set if the timers decrement in real time */
250 #define	adv_pr_AdvValidRealTime		\
251 			adv_pr_config[I_AdvValidExpiration].cf_notdefault
252 #define	adv_pr_AdvPreferredRealTime	\
253 			adv_pr_config[I_AdvPreferredExpiration].cf_notdefault
254 };
255 
256 /*
257  * Doubly-linked list of default routers on a phyint.
258  */
259 struct router {
260 	struct router	*dr_next;	/* Next router for this physical */
261 	struct router	*dr_prev;	/* Prev router for this physical */
262 	struct phyint	*dr_physical;	/* Back pointer */
263 
264 	struct in6_addr	dr_address;	/* Used to identify the router */
265 	uint_t		dr_lifetime;	/* In milliseconds */
266 	boolean_t	dr_inkernel;	/* Route added to kernel */
267 };
268 
269 /*
270  * Globals
271  */
272 extern struct phyint *phyints;
273 
274 
275 /*
276  * Functions
277  */
278 extern uint_t		getcurrenttime(void);
279 
280 extern struct phyint	*phyint_lookup(char *name);
281 extern struct phyint	*phyint_lookup_on_index(uint_t ifindex);
282 extern struct phyint	*phyint_create(char *name);
283 extern int		phyint_init_from_k(struct phyint *pi);
284 extern void		phyint_delete(struct phyint *pi);
285 extern uint_t		phyint_timer(struct phyint *pi, uint_t elapsed);
286 extern void		phyint_print_all(void);
287 extern void		phyint_reach_random(struct phyint *pi,
288 			    boolean_t set_needed);
289 extern void		phyint_cleanup(struct phyint *pi);
290 
291 extern boolean_t	tmptoken_create(struct phyint *pi);
292 extern void		tmptoken_delete(struct phyint *pi);
293 extern uint_t		tmptoken_timer(struct phyint *pi, uint_t elapsed);
294 extern boolean_t	token_equal(struct in6_addr t1, struct in6_addr t2,
295 			    int bits);
296 
297 extern struct prefix	*prefix_create(struct phyint *pi, struct in6_addr addr,
298 			    int addrlen, uint64_t flags);
299 extern struct prefix	*prefix_lookup_name(struct phyint *pi, char *name);
300 extern struct prefix	*prefix_lookup_addr_match(struct prefix *pr);
301 extern struct prefix	*prefix_create_name(struct phyint *pi, char *name);
302 extern int		prefix_init_from_k(struct prefix *pr);
303 extern void		prefix_delete(struct prefix *pr);
304 extern boolean_t	prefix_equal(struct in6_addr p1, struct in6_addr p2,
305 			    int bits);
306 extern void		prefix_update_k(struct prefix *pr);
307 extern uint_t		prefix_timer(struct prefix *pr, uint_t elapsed);
308 extern uint_t		adv_prefix_timer(struct adv_prefix *adv_pr,
309 			    uint_t elapsed);
310 extern boolean_t	prefix_token_match(struct phyint *pi,
311 			    struct prefix *pr, uint64_t flags);
312 extern struct prefix	*prefix_lookup_addr(struct phyint *pi,
313 			    struct in6_addr prefix);
314 
315 extern struct adv_prefix *adv_prefix_lookup(struct phyint *pi,
316 			    struct in6_addr addr, int addrlen);
317 extern struct adv_prefix *adv_prefix_create(struct phyint *pi,
318 			    struct in6_addr addr, int addrlen);
319 
320 extern struct router	*router_lookup(struct phyint *pi, struct in6_addr addr);
321 extern struct router	*router_create(struct phyint *pi, struct in6_addr addr,
322 			    uint_t lifetime);
323 extern void		router_update_k(struct router *dr);
324 extern uint_t		router_timer(struct router *dr, uint_t elapsed);
325 
326 
327 extern void	check_to_advertise(struct phyint *pi, enum adv_events event);
328 extern void	check_to_solicit(struct phyint *pi,
329 		    enum solicit_events event);
330 extern uint_t	advertise_event(struct phyint *pi, enum adv_events event,
331 		    uint_t elapsed);
332 extern uint_t	solicit_event(struct phyint *pi, enum solicit_events event,
333 		    uint_t elapsed);
334 
335 extern void	print_route_sol(char *str, struct phyint *pi,
336 		    struct nd_router_solicit *rs, int len,
337 		    struct sockaddr_in6 *addr);
338 extern void	print_route_adv(char *str, struct phyint *pi,
339 		    struct nd_router_advert *ra, int len,
340 		    struct sockaddr_in6 *addr);
341 extern void	print_iflist(struct confvar *confvar);
342 extern void	print_prefixlist(struct confvar *confvar);
343 
344 extern void	in_data(struct phyint *pi);
345 
346 extern void	incoming_ra(struct phyint *pi, struct nd_router_advert *ra,
347 		    int len, struct sockaddr_in6 *from, boolean_t loopback);
348 
349 extern boolean_t incoming_prefix_addrconf_process(struct phyint *pi,
350 		    struct prefix *pr, uchar_t *opt,
351 		    struct sockaddr_in6 *from, boolean_t loopback,
352 		    boolean_t new_prefix);
353 
354 extern void	incoming_prefix_onlink_process(struct prefix *pr,
355 		    uchar_t *opt);
356 
357 #ifdef	__cplusplus
358 }
359 #endif
360 
361 #endif	/* _NDPD_TABLES_H */
362