1 /* $FreeBSD: src/sys/netinet6/ip6_var.h,v 1.2.2.4 2003/01/23 21:06:47 sam Exp $ */ 2 /* $DragonFly: src/sys/netinet6/ip6_var.h,v 1.13 2008/09/04 09:08:22 hasso Exp $ */ 3 /* $KAME: ip6_var.h,v 1.62 2001/05/03 14:51:48 itojun Exp $ */ 4 5 /* 6 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. Neither the name of the project nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34 /* 35 * Copyright (c) 1982, 1986, 1993 36 * The Regents of the University of California. All rights reserved. 37 * 38 * Redistribution and use in source and binary forms, with or without 39 * modification, are permitted provided that the following conditions 40 * are met: 41 * 1. Redistributions of source code must retain the above copyright 42 * notice, this list of conditions and the following disclaimer. 43 * 2. Redistributions in binary form must reproduce the above copyright 44 * notice, this list of conditions and the following disclaimer in the 45 * documentation and/or other materials provided with the distribution. 46 * 3. Neither the name of the University nor the names of its contributors 47 * may be used to endorse or promote products derived from this software 48 * without specific prior written permission. 49 * 50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 60 * SUCH DAMAGE. 61 * 62 * @(#)ip_var.h 8.1 (Berkeley) 6/10/93 63 */ 64 65 #ifndef _NETINET6_IP6_VAR_H_ 66 #define _NETINET6_IP6_VAR_H_ 67 68 #ifndef _SYS_TYPES_H_ 69 #include <sys/types.h> 70 #endif 71 #ifndef _SYS_QUEUE_H_ 72 #include <sys/queue.h> 73 #endif 74 #ifndef _NETINET_IN_H_ 75 #include <netinet/in.h> 76 #endif 77 78 /* 79 * IP6 reassembly queue structure. Each fragment 80 * being reassembled is attached to one of these structures. 81 */ 82 struct ip6q { 83 u_int32_t ip6q_head; 84 u_int16_t ip6q_len; 85 u_int8_t ip6q_nxt; /* ip6f_nxt in first fragment */ 86 u_int8_t ip6q_hlim; 87 struct ip6asfrag *ip6q_down; 88 struct ip6asfrag *ip6q_up; 89 u_int32_t ip6q_ident; 90 u_int8_t ip6q_arrive; 91 u_int8_t ip6q_ttl; 92 struct in6_addr ip6q_src, ip6q_dst; 93 struct ip6q *ip6q_next; 94 struct ip6q *ip6q_prev; 95 int ip6q_unfrglen; /* len of unfragmentable part */ 96 #ifdef notyet 97 u_char *ip6q_nxtp; 98 #endif 99 int ip6q_nfrag; /* # of fragments */ 100 }; 101 102 struct ip6asfrag { 103 u_int32_t ip6af_head; 104 u_int16_t ip6af_len; 105 u_int8_t ip6af_nxt; 106 u_int8_t ip6af_hlim; 107 /* must not override the above members during reassembling */ 108 struct ip6asfrag *ip6af_down; 109 struct ip6asfrag *ip6af_up; 110 struct mbuf *ip6af_m; 111 int ip6af_offset; /* offset in ip6af_m to next header */ 112 int ip6af_frglen; /* fragmentable part length */ 113 int ip6af_off; /* fragment offset */ 114 u_int16_t ip6af_mff; /* more fragment bit in frag off */ 115 }; 116 117 #define IP6_REASS_MBUF(ip6af) (*(struct mbuf **)&((ip6af)->ip6af_m)) 118 119 struct ip6_moptions { 120 struct ifnet *im6o_multicast_ifp; /* ifp for outgoing multicasts */ 121 u_char im6o_multicast_hlim; /* hoplimit for outgoing multicasts */ 122 u_char im6o_multicast_loop; /* 1 >= hear sends if a member */ 123 LIST_HEAD(, in6_multi_mship) im6o_memberships; 124 }; 125 126 /* 127 * Control options for outgoing packets 128 */ 129 130 /* Routing header related info */ 131 struct ip6po_rhinfo { 132 struct ip6_rthdr *ip6po_rhi_rthdr; /* Routing header */ 133 struct route_in6 ip6po_rhi_route; /* Route to the 1st hop */ 134 }; 135 #define ip6po_rthdr ip6po_rhinfo.ip6po_rhi_rthdr 136 #define ip6po_route ip6po_rhinfo.ip6po_rhi_route 137 138 /* Nexthop related info */ 139 struct ip6po_nhinfo { 140 struct sockaddr *ip6po_nhi_nexthop; 141 struct route_in6 ip6po_nhi_route; /* Route to the nexthop */ 142 }; 143 #define ip6po_nexthop ip6po_nhinfo.ip6po_nhi_nexthop 144 #define ip6po_nextroute ip6po_nhinfo.ip6po_nhi_route 145 146 struct ip6_pktopts { 147 struct mbuf *ip6po_m; /* Pointer to mbuf storing the data */ 148 int ip6po_hlim; /* Hoplimit for outgoing packets */ 149 150 /* Outgoing IF/address information */ 151 struct in6_pktinfo *ip6po_pktinfo; 152 153 /* Next-hop address information */ 154 struct ip6po_nhinfo ip6po_nhinfo; 155 156 struct ip6_hbh *ip6po_hbh; /* Hop-by-Hop options header */ 157 158 /* Destination options header (before a routing header) */ 159 struct ip6_dest *ip6po_dest1; 160 161 /* Routing header related info. */ 162 struct ip6po_rhinfo ip6po_rhinfo; 163 164 /* Destination options header (after a routing header) */ 165 struct ip6_dest *ip6po_dest2; 166 /* 167 * below fields are introduced in RFC3542 168 */ 169 int ip6po_tclass; /* traffic class */ 170 int ip6po_minmtu; /* fragment vs PMTU discovery policy */ 171 #define IP6PO_MINMTU_MCASTONLY -1 /* default; send at min MTU for multicast*/ 172 #define IP6PO_MINMTU_DISABLE 0 /* always perform pmtu disc */ 173 #define IP6PO_MINMTU_ALL 1 /* always send at min MTU */ 174 int ip6po_prefer_tempaddr; /* whether temporary addresses are 175 preferred as source address */ 176 #define IP6PO_TEMPADDR_SYSTEM -1 /* follow the system default */ 177 #define IP6PO_TEMPADDR_NOTPREFER 0 /* not prefer temporary address */ 178 #define IP6PO_TEMPADDR_PREFER 1 /* prefer temporary address */ 179 180 int ip6po_flags; 181 #if 0 /* Parameters in this block are obsolete. Do not reuse the values. */ 182 #define IP6PO_REACHCONF 0x01 /* upper-layer reachability confirmation. */ 183 #define IP6PO_MINMTU 0x02 /* use minimum MTU (IPV6_USE_MIN_MTU) */ 184 #endif 185 #define IP6PO_DONTFRAG 0x04 /* disable fragmentation (IPV6_DONTFRAG) */ 186 #define IP6PO_USECOA 0x08 /* use care of address */ 187 }; 188 189 /* 190 * Control options for incoming packets 191 */ 192 struct ip6stat { 193 u_quad_t ip6s_total; /* total packets received */ 194 u_quad_t ip6s_tooshort; /* packet too short */ 195 u_quad_t ip6s_toosmall; /* not enough data */ 196 u_quad_t ip6s_fragments; /* fragments received */ 197 u_quad_t ip6s_fragdropped; /* frags dropped(dups, out of space) */ 198 u_quad_t ip6s_fragtimeout; /* fragments timed out */ 199 u_quad_t ip6s_fragoverflow; /* fragments that exceeded limit */ 200 u_quad_t ip6s_forward; /* packets forwarded */ 201 u_quad_t ip6s_cantforward; /* packets rcvd for unreachable dest */ 202 u_quad_t ip6s_redirectsent; /* packets forwarded on same net */ 203 u_quad_t ip6s_delivered; /* datagrams delivered to upper level*/ 204 u_quad_t ip6s_localout; /* total ip packets generated here */ 205 u_quad_t ip6s_odropped; /* lost packets due to nobufs, etc. */ 206 u_quad_t ip6s_reassembled; /* total packets reassembled ok */ 207 u_quad_t ip6s_fragmented; /* datagrams successfully fragmented */ 208 u_quad_t ip6s_ofragments; /* output fragments created */ 209 u_quad_t ip6s_cantfrag; /* don't fragment flag was set, etc. */ 210 u_quad_t ip6s_badoptions; /* error in option processing */ 211 u_quad_t ip6s_noroute; /* packets discarded due to no route */ 212 u_quad_t ip6s_badvers; /* ip6 version != 6 */ 213 u_quad_t ip6s_rawout; /* total raw ip packets generated */ 214 u_quad_t ip6s_badscope; /* scope error */ 215 u_quad_t ip6s_notmember; /* don't join this multicast group */ 216 u_quad_t ip6s_nxthist[256]; /* next header history */ 217 u_quad_t ip6s_m1; /* one mbuf */ 218 u_quad_t ip6s_m2m[32]; /* two or more mbuf */ 219 u_quad_t ip6s_mext1; /* one ext mbuf */ 220 u_quad_t ip6s_mext2m; /* two or more ext mbuf */ 221 u_quad_t ip6s_exthdrtoolong; /* ext hdr are not continuous */ 222 u_quad_t ip6s_nogif; /* no match gif found */ 223 u_quad_t ip6s_toomanyhdr; /* discarded due to too many headers */ 224 225 /* 226 * statistics for improvement of the source address selection 227 * algorithm: 228 * XXX: hardcoded 16 = # of ip6 multicast scope types + 1 229 */ 230 /* number of times that address selection fails */ 231 u_quad_t ip6s_sources_none; 232 /* number of times that an address on the outgoing I/F is chosen */ 233 u_quad_t ip6s_sources_sameif[16]; 234 /* number of times that an address on a non-outgoing I/F is chosen */ 235 u_quad_t ip6s_sources_otherif[16]; 236 /* 237 * number of times that an address that has the same scope 238 * from the destination is chosen. 239 */ 240 u_quad_t ip6s_sources_samescope[16]; 241 /* 242 * number of times that an address that has a different scope 243 * from the destination is chosen. 244 */ 245 u_quad_t ip6s_sources_otherscope[16]; 246 /* number of times that an deprecated address is chosen */ 247 u_quad_t ip6s_sources_deprecated[16]; 248 249 u_quad_t ip6s_forward_cachehit; 250 u_quad_t ip6s_forward_cachemiss; 251 }; 252 253 #ifdef _KERNEL 254 /* 255 * IPv6 onion peeling state. 256 * it will be initialized when we come into ip6_input(). 257 * XXX do not make it a kitchen sink! 258 */ 259 struct ip6aux { 260 u_int32_t ip6a_flags; 261 #define IP6A_SWAP 0x01 /* swapped home/care-of on packet */ 262 #define IP6A_HASEEN 0x02 /* HA was present */ 263 #define IP6A_BRUID 0x04 /* BR Unique Identifier was present */ 264 #define IP6A_RTALERTSEEN 0x08 /* rtalert present */ 265 266 /* ip6.ip6_src */ 267 struct in6_addr ip6a_careof; /* care-of address of the peer */ 268 struct in6_addr ip6a_home; /* home address of the peer */ 269 u_int16_t ip6a_bruid; /* BR unique identifier */ 270 271 /* ip6.ip6_dst */ 272 struct in6_ifaddr *ip6a_dstia6; /* my ifaddr that matches ip6_dst */ 273 274 /* rtalert */ 275 u_int16_t ip6a_rtalert; /* rtalert option value */ 276 277 /* 278 * decapsulation history will be here. 279 * with IPsec it may not be accurate. 280 */ 281 }; 282 #endif 283 284 #ifdef _KERNEL 285 /* flags passed to ip6_output as last parameter */ 286 #define IPV6_DADOUTPUT 0x01 /* DAD */ 287 #define IPV6_FORWARDING 0x02 /* most of IPv6 header exists */ 288 #define IPV6_MINMTU 0x04 /* use minimum MTU (IPV6_USE_MIN_MTU) */ 289 290 /* direction passed to ip_hashfn as last parameter */ 291 #define IP6_MPORT_IN 0 /* Find lwkt port for incoming packets */ 292 #define IP6_MPORT_OUT 1 /* Find lwkt port for outgoing packets */ 293 294 extern struct ip6stat ip6stat; /* statistics */ 295 extern u_int32_t ip6_id; /* fragment identifier */ 296 extern int ip6_minhlim; /* minimum hop limit */ 297 extern int ip6_defhlim; /* default hop limit */ 298 extern int ip6_defmcasthlim; /* default multicast hop limit */ 299 extern int ip6_forwarding; /* act as router? */ 300 extern int ip6_forward_srcrt; /* forward src-routed? */ 301 extern int ip6_gif_hlim; /* Hop limit for gif encap packet */ 302 extern int ip6_use_deprecated; /* allow deprecated addr as source */ 303 extern int ip6_rr_prune; /* router renumbering prefix 304 * walk list every 5 sec. */ 305 306 extern struct socket *ip6_mrouter; /* multicast routing daemon */ 307 extern int ip6_sendredirects; /* send IP redirects when forwarding? */ 308 extern int ip6_maxfragpackets; /* Maximum packets in reassembly queue */ 309 extern int ip6_maxfrags; /* Maximum fragments in reassembly queue */ 310 extern int ip6_sourcecheck; /* Verify source interface */ 311 extern int ip6_sourcecheck_interval; /* Interval between log messages */ 312 extern int ip6_accept_rtadv; /* Acts as a host not a router */ 313 extern int ip6_keepfaith; /* Firewall Aided Internet Translator */ 314 extern int ip6_log_interval; 315 extern time_t ip6_log_time; 316 extern int ip6_hdrnestlimit; /* upper limit of # of extension headers */ 317 extern int ip6_dad_count; /* DupAddrDetectionTransmits */ 318 319 extern u_int32_t ip6_flow_seq; 320 extern int ip6_auto_flowlabel; 321 extern int ip6_auto_linklocal; 322 323 extern int ip6_anonportmin; /* minimum ephemeral port */ 324 extern int ip6_anonportmax; /* maximum ephemeral port */ 325 extern int ip6_lowportmin; /* minimum reserved port */ 326 extern int ip6_lowportmax; /* maximum reserved port */ 327 328 extern int ip6_use_tempaddr; /* whether to use temporary addresses. */ 329 330 extern struct pfil_head inet6_pfil_hook; 331 332 extern struct pr_usrreqs rip6_usrreqs; 333 334 struct proc; 335 struct inpcb; 336 struct sockopt; 337 struct in6_ifaddr; 338 struct ip6_hdr; 339 union netmsg; 340 341 void icmp6_ctloutput (union netmsg *); 342 343 void ip6_init (void); 344 void ip6intr (void); 345 struct in6_ifaddr *ip6_getdstifaddr (struct mbuf *); 346 void ip6_freepcbopts (struct ip6_pktopts *); 347 void ip6_freemoptions (struct ip6_moptions *); 348 int ip6_unknown_opt (u_int8_t *, struct mbuf *, int); 349 char * ip6_get_prevhdr (struct mbuf *, int); 350 int ip6_nexthdr (struct mbuf *, int, int, int *); 351 int ip6_lasthdr (struct mbuf *, int, int, int *); 352 353 struct ip6aux *ip6_addaux (struct mbuf *); 354 struct ip6aux *ip6_findaux (struct mbuf *); 355 void ip6_delaux (struct mbuf *); 356 357 int ip6_mforward (struct ip6_hdr *, struct ifnet *, struct mbuf *); 358 int ip6_process_hopopts (struct mbuf *, u_int8_t *, int, u_int32_t *, 359 u_int32_t *); 360 void ip6_savecontrol (struct inpcb *, struct mbuf **, struct ip6_hdr *, 361 struct mbuf *); 362 void ip6_notify_pmtu (struct inpcb *, struct sockaddr_in6 *, 363 u_int32_t *); 364 int ip6_sysctl (int *, u_int, void *, size_t *, void *, size_t); 365 366 void ip6_forward (struct mbuf *, int); 367 368 void ip6_mloopback (struct ifnet *, struct mbuf *, struct sockaddr_in6 *); 369 int ip6_output (struct mbuf *, struct ip6_pktopts *, 370 struct route_in6 *, 371 int, 372 struct ip6_moptions *, struct ifnet **, 373 struct inpcb *); 374 void ip6_ctloutput_dispatch(netmsg_t msg); 375 int ip6_ctloutput (struct socket *, struct sockopt *); 376 int ip6_raw_ctloutput (struct socket *, struct sockopt *); 377 void init_ip6pktopts (struct ip6_pktopts *); 378 int 379 ip6_setpktoptions(struct mbuf *, struct ip6_pktopts *, 380 struct ip6_pktopts *, int , int); 381 void ip6_clearpktopts (struct ip6_pktopts *, int); 382 struct ip6_pktopts *ip6_copypktopts (struct ip6_pktopts *, int); 383 int ip6_optlen (struct inpcb *); 384 385 int route6_input (struct mbuf **, int *, int); 386 387 void frag6_init (void); 388 int frag6_input (struct mbuf **, int *, int); 389 void frag6_slowtimo (void); 390 void frag6_drain (void); 391 392 void rip6_init (void); 393 int rip6_input (struct mbuf **, int *, int); 394 void rip6_ctlinput (union netmsg *); 395 void rip6_ctloutput (union netmsg *); 396 int rip6_output (struct mbuf *, struct socket *, ...); 397 int rip6_usrreq (struct socket *, 398 int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); 399 400 int dest6_input (struct mbuf **, int *, int); 401 int none_input (struct mbuf **, int *, int); 402 #endif /* _KERNEL */ 403 404 #endif /* !_NETINET6_IP6_VAR_H_ */ 405