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