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