xref: /titanic_50/usr/src/cmd/cmd-inet/usr.lib/in.ndpd/tables.h (revision aa736cbe5210944c799eb1f28b84274eeee4d9e2)
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 2008 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 
128 	uint_t		pi_ra_flags;		/* Detect when to start DHCP */
129 };
130 
131 /*
132  * pi_state/pr_kernel_state values
133  */
134 #define	PI_PRESENT		0x01
135 #define	PI_JOINED_ALLNODES	0x02	/* allnodes multicast joined */
136 #define	PI_JOINED_ALLROUTERS	0x04	/* allrouters multicast joined */
137 
138 /*
139  * Prefix configuration variable indices
140  */
141 #define	I_AdvValidLifetime	0	/* In seconds */
142 #define	I_AdvOnLinkFlag		1
143 #define	I_AdvPreferredLifetime	2	/* In seconds */
144 #define	I_AdvAutonomousFlag	3
145 #define	I_AdvValidExpiration	4	/* Seconds left */
146 #define	I_AdvPreferredExpiration 5	/* Seconds left */
147 #define	I_PREFIXSIZE		6	/* # of variables */
148 
149 /*
150  * A doubly-linked list of prefixes for onlink and addrconf.
151  * ("Prefixes" in this context are identical to logical interfaces.)
152  */
153 struct prefix {
154 	struct prefix	*pr_next;	/* Next prefix for this physical */
155 	struct prefix	*pr_prev;	/* Prev prefix for this physical */
156 	struct phyint	*pr_physical;	/* Back pointer */
157 
158 	struct in6_addr	pr_prefix;	/* Used to indentify prefix */
159 	uint_t		pr_prefix_len;	/* Num bits valid */
160 
161 	char		pr_name[LIFNAMSIZ];
162 	struct in6_addr	pr_address;
163 	uint64_t	pr_flags;	/* IFF_* flags */
164 
165 	uint_t		pr_state;	/* PR_ONLINK | PR_AUTO etc */
166 	uint_t		pr_kernel_state; /* PR_ONLINK | PR_AUTO etc */
167 	boolean_t	pr_in_use;	/* To detect removed prefixes */
168 
169 	/* Recorded variables on node/host */
170 	uint_t		pr_ValidLifetime;	/* In ms w/ 2 hour rule */
171 	uint_t		pr_PreferredLifetime;	/* In millseconds */
172 	uint_t		pr_OnLinkLifetime;	/* ms valid w/o 2 hour rule */
173 	boolean_t	pr_OnLinkFlag;
174 	boolean_t	pr_AutonomousFlag;
175 
176 	uint_t		pr_CreateTime;		/* tmpaddr creation time */
177 						/* in SECONDS */
178 	uint_t		pr_attempts;	/* attempts to configure */
179 };
180 
181 /*
182  * Flags used for pr_kernel_state and pr_state where the latter is
183  * user-level state.
184  */
185 #define	PR_ONLINK	0x01		/* On-link */
186 #define	PR_AUTO		0x02		/* Stateless addrconf */
187 #define	PR_DEPRECATED	0x04		/* Address is deprecated */
188 #define	PR_STATIC	0x08		/* Not created by ndpd */
189 
190 /*
191  * The sum of all possible state string lengths, plus terminating
192  * null character; if new states are added, this needs to be updated.
193  * Useful for passing an appropriately sized buffer to prefix_print_state().
194  *
195  * Current strings: "ONLINK ", "AUTO ", "DEPRECATED ", "STATIC ", "\n"
196  *                      7     +   5    +     11       +    7     +  1
197  */
198 #define	PREFIX_STATESTRLEN	31
199 
200 /* Prefix used for storing advertisement specific stuff */
201 struct adv_prefix {
202 	struct adv_prefix	*adv_pr_next;	/* Next prefix */
203 	struct adv_prefix	*adv_pr_prev;	/* Prev prefix */
204 	struct phyint		*adv_pr_physical;	/* Back pointer */
205 
206 	struct in6_addr		adv_pr_prefix;	/* Used to indentify prefix */
207 	uint_t			adv_pr_prefix_len;	/* Num bits valid */
208 
209 	/* Used when sending advertisements */
210 	struct confvar		adv_pr_config[I_PREFIXSIZE];
211 #define	adv_pr_AdvValidLifetime	adv_pr_config[I_AdvValidLifetime].cf_value
212 #define	adv_pr_AdvOnLinkFlag	adv_pr_config[I_AdvOnLinkFlag].cf_value
213 #define	adv_pr_AdvPreferredLifetime	\
214 			adv_pr_config[I_AdvPreferredLifetime].cf_value
215 #define	adv_pr_AdvAutonomousFlag	\
216 			adv_pr_config[I_AdvAutonomousFlag].cf_value
217 #define	adv_pr_AdvValidExpiration	\
218 			adv_pr_config[I_AdvValidExpiration].cf_value
219 #define	adv_pr_AdvPreferredExpiration	\
220 			adv_pr_config[I_AdvPreferredExpiration].cf_value
221 	/* The two below are set if the timers decrement in real time */
222 #define	adv_pr_AdvValidRealTime		\
223 			adv_pr_config[I_AdvValidExpiration].cf_notdefault
224 #define	adv_pr_AdvPreferredRealTime	\
225 			adv_pr_config[I_AdvPreferredExpiration].cf_notdefault
226 };
227 
228 /*
229  * Doubly-linked list of default routers on a phyint.
230  */
231 struct router {
232 	struct router	*dr_next;	/* Next router for this physical */
233 	struct router	*dr_prev;	/* Prev router for this physical */
234 	struct phyint	*dr_physical;	/* Back pointer */
235 
236 	struct in6_addr	dr_address;	/* Used to identify the router */
237 	uint_t		dr_lifetime;	/* In milliseconds */
238 	boolean_t	dr_inkernel;	/* Route added to kernel */
239 };
240 
241 /*
242  * Globals
243  */
244 extern struct phyint *phyints;
245 extern int num_of_phyints;
246 
247 /*
248  * Functions
249  */
250 extern uint_t		getcurrenttime(void);
251 
252 extern struct phyint	*phyint_lookup(char *name);
253 extern struct phyint	*phyint_lookup_on_index(uint_t ifindex);
254 extern struct phyint	*phyint_create(char *name);
255 extern int		phyint_init_from_k(struct phyint *pi);
256 extern void		phyint_delete(struct phyint *pi);
257 extern uint_t		phyint_timer(struct phyint *pi, uint_t elapsed);
258 extern void		phyint_print_all(void);
259 extern void		phyint_reach_random(struct phyint *pi,
260 			    boolean_t set_needed);
261 extern void		phyint_cleanup(struct phyint *pi);
262 
263 extern boolean_t	tmptoken_create(struct phyint *pi);
264 extern void		tmptoken_delete(struct phyint *pi);
265 extern uint_t		tmptoken_timer(struct phyint *pi, uint_t elapsed);
266 extern boolean_t	token_equal(struct in6_addr t1, struct in6_addr t2,
267 			    int bits);
268 
269 extern struct prefix	*prefix_create(struct phyint *pi, struct in6_addr addr,
270 			    int addrlen, uint64_t flags);
271 extern struct prefix	*prefix_lookup_name(struct phyint *pi, char *name);
272 extern struct prefix	*prefix_lookup_addr_match(struct prefix *pr);
273 extern struct prefix	*prefix_create_name(struct phyint *pi, char *name);
274 extern int		prefix_init_from_k(struct prefix *pr);
275 extern void		prefix_delete(struct prefix *pr);
276 extern boolean_t	prefix_equal(struct in6_addr p1, struct in6_addr p2,
277 			    int bits);
278 extern void		prefix_update_dhcp(struct prefix *pr);
279 extern void		prefix_update_k(struct prefix *pr);
280 extern uint_t		prefix_timer(struct prefix *pr, uint_t elapsed);
281 extern uint_t		adv_prefix_timer(struct adv_prefix *adv_pr,
282 			    uint_t elapsed);
283 extern boolean_t	prefix_token_match(struct phyint *pi,
284 			    struct prefix *pr, uint64_t flags);
285 extern struct prefix	*prefix_lookup_addr(struct phyint *pi,
286 			    struct in6_addr prefix);
287 
288 extern struct adv_prefix *adv_prefix_lookup(struct phyint *pi,
289 			    struct in6_addr addr, int addrlen);
290 extern struct adv_prefix *adv_prefix_create(struct phyint *pi,
291 			    struct in6_addr addr, int addrlen);
292 
293 extern struct router	*router_lookup(struct phyint *pi, struct in6_addr addr);
294 extern struct router	*router_create(struct phyint *pi, struct in6_addr addr,
295 			    uint_t lifetime);
296 extern void		router_update_k(struct router *dr);
297 extern uint_t		router_timer(struct router *dr, uint_t elapsed);
298 
299 extern void	check_to_advertise(struct phyint *pi, enum adv_events event);
300 extern void	check_to_solicit(struct phyint *pi,
301 		    enum solicit_events event);
302 extern uint_t	advertise_event(struct phyint *pi, enum adv_events event,
303 		    uint_t elapsed);
304 extern uint_t	solicit_event(struct phyint *pi, enum solicit_events event,
305 		    uint_t elapsed);
306 
307 extern void	print_route_sol(char *str, struct phyint *pi,
308 		    struct nd_router_solicit *rs, int len,
309 		    struct sockaddr_in6 *addr);
310 extern void	print_route_adv(char *str, struct phyint *pi,
311 		    struct nd_router_advert *ra, int len,
312 		    struct sockaddr_in6 *addr);
313 extern void	print_iflist(struct confvar *confvar);
314 extern void	print_prefixlist(struct confvar *confvar);
315 
316 extern void	in_data(struct phyint *pi);
317 
318 extern void	start_dhcp(struct phyint *pi);
319 
320 extern void	incoming_ra(struct phyint *pi, struct nd_router_advert *ra,
321 		    int len, struct sockaddr_in6 *from, boolean_t loopback);
322 
323 extern boolean_t incoming_prefix_addrconf_process(struct phyint *pi,
324 		    struct prefix *pr, uchar_t *opt,
325 		    struct sockaddr_in6 *from, boolean_t loopback,
326 		    boolean_t new_prefix);
327 
328 extern void	incoming_prefix_onlink_process(struct prefix *pr,
329 		    uchar_t *opt);
330 
331 #ifdef	__cplusplus
332 }
333 #endif
334 
335 #endif	/* _NDPD_TABLES_H */
336