xref: /illumos-gate/usr/src/cmd/cmd-inet/usr.lib/in.ndpd/tables.h (revision 46b592853d0f4f11781b6b0a7533f267c6aee132)
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 2009 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 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #include <ndpd.h>
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, RESTART_INIT_SOLICIT };
42 
43 /*
44  * A doubly linked list of all physical interfaces that each contain a
45  * doubly linked list of prefixes (i.e. logical interfaces) and default
46  * routers.
47  */
48 struct phyint {
49 	struct phyint	*pi_next;
50 	struct phyint	*pi_prev;
51 	struct prefix	*pi_prefix_list;	/* Doubly linked prefixes */
52 	struct router	*pi_router_list;	/* Doubly linked routers */
53 	struct adv_prefix *pi_adv_prefix_list;	/* Doubly linked adv.prefixes */
54 
55 	uint_t		pi_index;		/* Identifier > 0 */
56 	char		pi_name[LIFNAMSIZ];	/* Used to identify it */
57 	int		pi_sock;		/* For sending and receiving */
58 	struct in6_addr	pi_ifaddr;		/* Local address */
59 	uint64_t		pi_flags;		/* IFF_* flags */
60 	uint_t		pi_mtu;			/* From SIOCGLIFMTU */
61 	struct in6_addr pi_token;
62 	uint_t		pi_token_length;
63 	struct in6_addr	pi_tmp_token;		/* For RFC3041 addrs */
64 	struct in6_addr	pi_dst_token;		/* For POINTOPOINT */
65 
66 	uint_t		pi_state;		/* PI_* below */
67 	uint_t		pi_kernel_state;	/* PI_* below */
68 	uint_t		pi_num_k_routers;	/* # routers in kernel */
69 	uint_t		pi_reach_time_since_random;	/* In milliseconds */
70 
71 	/* Applies if pi_AdvSendAdvertisements */
72 	uint_t		pi_adv_time_left;	/* In milliseconds */
73 	uint_t		pi_adv_time_since_sent;	/* In milliseconds */
74 	enum adv_states	pi_adv_state;
75 	uint_t		pi_adv_count;
76 
77 	/* Applies if not pi_AdvSendAdvertisements */
78 	uint_t		pi_sol_time_left;	/* In milliseconds */
79 	enum solicit_states pi_sol_state;
80 	uint_t		pi_sol_count;
81 
82 	/* Interface specific configurable variables */
83 	struct confvar	pi_config[I_IFSIZE];
84 #define	pi_DupAddrDetectTransmits pi_config[I_DupAddrDetectTransmits].cf_value
85 #define	pi_AdvSendAdvertisements pi_config[I_AdvSendAdvertisements].cf_value
86 #define	pi_MaxRtrAdvInterval	pi_config[I_MaxRtrAdvInterval].cf_value
87 #define	pi_MinRtrAdvInterval	pi_config[I_MinRtrAdvInterval].cf_value
88 #define	pi_AdvManagedFlag	pi_config[I_AdvManagedFlag].cf_value
89 #define	pi_AdvOtherConfigFlag	pi_config[I_AdvOtherConfigFlag].cf_value
90 #define	pi_AdvLinkMTU		pi_config[I_AdvLinkMTU].cf_value
91 #define	pi_AdvReachableTime	pi_config[I_AdvReachableTime].cf_value
92 #define	pi_AdvRetransTimer	pi_config[I_AdvRetransTimer].cf_value
93 #define	pi_AdvCurHopLimit	pi_config[I_AdvCurHopLimit].cf_value
94 #define	pi_AdvDefaultLifetime	pi_config[I_AdvDefaultLifetime].cf_value
95 #define	pi_StatelessAddrConf	pi_config[I_StatelessAddrConf].cf_value
96 #define	pi_TmpAddrsEnabled	pi_config[I_TmpAddrsEnabled].cf_value
97 #define	pi_TmpValidLifetime	pi_config[I_TmpValidLifetime].cf_value
98 #define	pi_TmpPreferredLifetime	pi_config[I_TmpPreferredLifetime].cf_value
99 #define	pi_TmpRegenAdvance	pi_config[I_TmpRegenAdvance].cf_value
100 #define	pi_TmpMaxDesyncFactor	pi_config[I_TmpMaxDesyncFactor].cf_value
101 #define	pi_StatefulAddrConf	pi_config[I_StatefulAddrConf].cf_value
102 
103 	/* Recorded variables for RFC3041 addresses */
104 	uint_t		pi_TmpDesyncFactor;		/* In milliseconds */
105 	uint_t		pi_TmpRegenCountdown;		/* In milliseconds */
106 
107 	/* Recorded variables on node/host */
108 	uint_t		pi_LinkMTU;
109 	uint_t		pi_CurHopLimit;
110 	uint_t		pi_BaseReachableTime;		/* In milliseconds */
111 	uint_t		pi_ReachableTime;		/* In milliseconds */
112 	/*
113 	 * The above value should be a uniformly-distributed random
114 	 * value between ND_MIN_RANDOM_FACTOR and
115 	 * ND_MAX_RANDOM_FACTOR times BaseReachableTime
116 	 * milliseconds.  A new random value should be
117 	 * calculated when BaseReachableTime changes (due to
118 	 * Router Advertisements) or at least every few hours
119 	 * even if no Router Advertisements are received.
120 	 * Tracked using pi_each_time_since_random.
121 	 */
122 	uint_t		pi_RetransTimer;		/* In milliseconds */
123 
124 	uint_t		pi_ra_flags;		/* Detect when to start DHCP */
125 };
126 
127 /*
128  * pi_state/pr_kernel_state values
129  */
130 #define	PI_PRESENT		0x01
131 #define	PI_JOINED_ALLNODES	0x02	/* allnodes multicast joined */
132 #define	PI_JOINED_ALLROUTERS	0x04	/* allrouters multicast joined */
133 
134 /*
135  * Prefix configuration variable indices
136  */
137 #define	I_AdvValidLifetime	0	/* In seconds */
138 #define	I_AdvOnLinkFlag		1
139 #define	I_AdvPreferredLifetime	2	/* In seconds */
140 #define	I_AdvAutonomousFlag	3
141 #define	I_AdvValidExpiration	4	/* Seconds left */
142 #define	I_AdvPreferredExpiration 5	/* Seconds left */
143 #define	I_PREFIXSIZE		6	/* # of variables */
144 
145 /*
146  * A doubly-linked list of prefixes for onlink and addrconf.
147  * ("Prefixes" in this context are identical to logical interfaces.)
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  * Functions
245  */
246 extern uint_t		getcurrenttime(void);
247 
248 extern struct phyint	*phyint_lookup(char *name);
249 extern struct phyint	*phyint_lookup_on_index(uint_t ifindex);
250 extern struct phyint	*phyint_create(char *name);
251 extern int		phyint_init_from_k(struct phyint *pi);
252 extern void		phyint_delete(struct phyint *pi);
253 extern uint_t		phyint_timer(struct phyint *pi, uint_t elapsed);
254 extern void		phyint_print_all(void);
255 extern int		phyint_get_lla(struct phyint *pi, struct lifreq *lifrp);
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_dhcp(struct prefix *pr);
276 extern void		prefix_update_k(struct prefix *pr);
277 extern uint_t		prefix_timer(struct prefix *pr, uint_t elapsed);
278 extern uint_t		adv_prefix_timer(struct adv_prefix *adv_pr,
279 			    uint_t elapsed);
280 extern struct prefix	*prefix_lookup_addr(struct phyint *pi,
281 			    struct in6_addr prefix);
282 
283 extern struct adv_prefix *adv_prefix_lookup(struct phyint *pi,
284 			    struct in6_addr addr, int addrlen);
285 extern struct adv_prefix *adv_prefix_create(struct phyint *pi,
286 			    struct in6_addr addr, int addrlen);
287 
288 extern struct router	*router_lookup(struct phyint *pi, struct in6_addr addr);
289 extern struct router	*router_create(struct phyint *pi, struct in6_addr addr,
290 			    uint_t lifetime);
291 extern void		router_update_k(struct router *dr);
292 extern uint_t		router_timer(struct router *dr, uint_t elapsed);
293 
294 extern void	check_to_advertise(struct phyint *pi, enum adv_events event);
295 extern void	check_to_solicit(struct phyint *pi,
296 		    enum solicit_events event);
297 extern uint_t	advertise_event(struct phyint *pi, enum adv_events event,
298 		    uint_t elapsed);
299 extern uint_t	solicit_event(struct phyint *pi, enum solicit_events event,
300 		    uint_t elapsed);
301 
302 extern void	print_route_sol(char *str, struct phyint *pi,
303 		    struct nd_router_solicit *rs, int len,
304 		    struct sockaddr_in6 *addr);
305 extern void	print_route_adv(char *str, struct phyint *pi,
306 		    struct nd_router_advert *ra, int len,
307 		    struct sockaddr_in6 *addr);
308 extern void	print_iflist(struct confvar *confvar);
309 extern void	print_prefixlist(struct confvar *confvar);
310 
311 extern void	in_data(struct phyint *pi);
312 
313 extern void	start_dhcp(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