1 /* $OpenBSD: ip6_var.h,v 1.44 2012/01/09 14:47:53 bluhm Exp $ */ 2 /* $KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $ */ 3 4 /* 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of the project nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33 /* 34 * Copyright (c) 1982, 1986, 1993 35 * The Regents of the University of California. All rights reserved. 36 * 37 * Redistribution and use in source and binary forms, with or without 38 * modification, are permitted provided that the following conditions 39 * are met: 40 * 1. Redistributions of source code must retain the above copyright 41 * notice, this list of conditions and the following disclaimer. 42 * 2. Redistributions in binary form must reproduce the above copyright 43 * notice, this list of conditions and the following disclaimer in the 44 * documentation and/or other materials provided with the distribution. 45 * 3. Neither the name of the University nor the names of its contributors 46 * may be used to endorse or promote products derived from this software 47 * without specific prior written permission. 48 * 49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 59 * SUCH DAMAGE. 60 * 61 * @(#)ip_var.h 8.1 (Berkeley) 6/10/93 62 */ 63 64 #ifndef _NETINET6_IP6_VAR_H_ 65 #define _NETINET6_IP6_VAR_H_ 66 67 /* 68 * IP6 reassembly queue structure. Each fragment 69 * being reassembled is attached to one of these structures. 70 */ 71 struct ip6q { 72 TAILQ_ENTRY(ip6q) ip6q_queue; 73 LIST_HEAD(ip6asfrag_list, ip6asfrag) ip6q_asfrag; 74 struct in6_addr ip6q_src, ip6q_dst; 75 int ip6q_unfrglen; /* len of unfragmentable part */ 76 int ip6q_nfrag; /* # of fragments */ 77 u_int32_t ip6q_ident; /* fragment identification */ 78 u_int8_t ip6q_nxt; /* ip6f_nxt in first fragment */ 79 u_int8_t ip6q_ttl; /* time to live in slowtimo units */ 80 }; 81 82 struct ip6asfrag { 83 LIST_ENTRY(ip6asfrag) ip6af_list; 84 struct mbuf *ip6af_m; 85 int ip6af_offset; /* offset in ip6af_m to next header */ 86 int ip6af_frglen; /* fragmentable part length */ 87 int ip6af_off; /* fragment offset */ 88 u_int32_t ip6af_flow; /* ip header flow id */ 89 u_int16_t ip6af_mff; /* more fragment bit in frag off */ 90 }; 91 92 #define IP6_REASS_MBUF(ip6af) ((ip6af)->ip6af_m) 93 94 struct ip6_moptions { 95 struct ifnet *im6o_multicast_ifp; /* ifp for outgoing multicasts */ 96 u_char im6o_multicast_hlim; /* hoplimit for outgoing multicasts */ 97 u_char im6o_multicast_loop; /* 1 >= hear sends if a member */ 98 LIST_HEAD(, in6_multi_mship) im6o_memberships; 99 }; 100 101 /* 102 * Control options for outgoing packets 103 */ 104 105 /* Routing header related info */ 106 struct ip6po_rhinfo { 107 struct ip6_rthdr *ip6po_rhi_rthdr; /* Routing header */ 108 struct route_in6 ip6po_rhi_route; /* Route to the 1st hop */ 109 }; 110 #define ip6po_rthdr ip6po_rhinfo.ip6po_rhi_rthdr 111 #define ip6po_route ip6po_rhinfo.ip6po_rhi_route 112 113 /* Nexthop related info */ 114 struct ip6po_nhinfo { 115 struct sockaddr *ip6po_nhi_nexthop; 116 struct route_in6 ip6po_nhi_route; 117 }; 118 #define ip6po_nexthop ip6po_nhinfo.ip6po_nhi_nexthop 119 #define ip6po_nextroute ip6po_nhinfo.ip6po_nhi_route 120 121 struct ip6_pktopts { 122 /* Hoplimit for outgoing packets */ 123 int ip6po_hlim; 124 125 /* Outgoing IF/address information */ 126 struct in6_pktinfo *ip6po_pktinfo; 127 128 /* Next-hop address information */ 129 struct ip6po_nhinfo ip6po_nhinfo; 130 131 /* Hop-by-Hop options header */ 132 struct ip6_hbh *ip6po_hbh; 133 134 /* Destination options header (before a routing header) */ 135 struct ip6_dest *ip6po_dest1; 136 137 /* Routing header related info. */ 138 struct ip6po_rhinfo ip6po_rhinfo; 139 140 /* Destination options header (after a routing header) */ 141 struct ip6_dest *ip6po_dest2; 142 143 /* traffic class */ 144 int ip6po_tclass; 145 146 /* fragment vs PMTU discovery policy */ 147 int ip6po_minmtu; 148 #define IP6PO_MINMTU_MCASTONLY -1 /* default: send at min MTU for multicast */ 149 #define IP6PO_MINMTU_DISABLE 0 /* always perform pmtu disc */ 150 #define IP6PO_MINMTU_ALL 1 /* always send at min MTU */ 151 152 int ip6po_flags; 153 #define IP6PO_DONTFRAG 0x04 /* disable fragmentation (IPV6_DONTFRAG) */ 154 }; 155 156 struct ip6stat { 157 u_int64_t ip6s_total; /* total packets received */ 158 u_int64_t ip6s_tooshort; /* packet too short */ 159 u_int64_t ip6s_toosmall; /* not enough data */ 160 u_int64_t ip6s_fragments; /* fragments received */ 161 u_int64_t ip6s_fragdropped; /* frags dropped(dups, out of space) */ 162 u_int64_t ip6s_fragtimeout; /* fragments timed out */ 163 u_int64_t ip6s_fragoverflow; /* fragments that exceeded limit */ 164 u_int64_t ip6s_forward; /* packets forwarded */ 165 u_int64_t ip6s_cantforward; /* packets rcvd for unreachable dest */ 166 u_int64_t ip6s_redirectsent; /* packets forwarded on same net */ 167 u_int64_t ip6s_delivered; /* datagrams delivered to upper level*/ 168 u_int64_t ip6s_localout; /* total ip packets generated here */ 169 u_int64_t ip6s_odropped; /* lost packets due to nobufs, etc. */ 170 u_int64_t ip6s_reassembled; /* total packets reassembled ok */ 171 u_int64_t ip6s_fragmented; /* datagrams successfully fragmented */ 172 u_int64_t ip6s_ofragments; /* output fragments created */ 173 u_int64_t ip6s_cantfrag; /* don't fragment flag was set, etc. */ 174 u_int64_t ip6s_badoptions; /* error in option processing */ 175 u_int64_t ip6s_noroute; /* packets discarded due to no route */ 176 u_int64_t ip6s_badvers; /* ip6 version != 6 */ 177 u_int64_t ip6s_rawout; /* total raw ip packets generated */ 178 u_int64_t ip6s_badscope; /* scope error */ 179 u_int64_t ip6s_notmember; /* don't join this multicast group */ 180 u_int64_t ip6s_nxthist[256]; /* next header history */ 181 u_int64_t ip6s_m1; /* one mbuf */ 182 u_int64_t ip6s_m2m[32]; /* two or more mbuf */ 183 u_int64_t ip6s_mext1; /* one ext mbuf */ 184 u_int64_t ip6s_mext2m; /* two or more ext mbuf */ 185 u_int64_t ip6s_nogif; /* no match gif found */ 186 u_int64_t ip6s_toomanyhdr; /* discarded due to too many headers */ 187 188 /* 189 * statistics for improvement of the source address selection 190 * algorithm: 191 * XXX: hardcoded 16 = # of ip6 multicast scope types + 1 192 */ 193 /* number of times that address selection fails */ 194 u_int64_t ip6s_sources_none; 195 /* number of times that an address on the outgoing I/F is chosen */ 196 u_int64_t ip6s_sources_sameif[16]; 197 /* number of times that an address on a non-outgoing I/F is chosen */ 198 u_int64_t ip6s_sources_otherif[16]; 199 /* 200 * number of times that an address that has the same scope 201 * from the destination is chosen. 202 */ 203 u_int64_t ip6s_sources_samescope[16]; 204 /* 205 * number of times that an address that has a different scope 206 * from the destination is chosen. 207 */ 208 u_int64_t ip6s_sources_otherscope[16]; 209 /* number of times that an deprecated address is chosen */ 210 u_int64_t ip6s_sources_deprecated[16]; 211 212 u_int64_t ip6s_forward_cachehit; 213 u_int64_t ip6s_forward_cachemiss; 214 }; 215 216 #ifdef _KERNEL 217 /* flags passed to ip6_output as last parameter */ 218 #define IPV6_UNSPECSRC 0x01 /* allow :: as the source address */ 219 #define IPV6_FORWARDING 0x02 /* most of IPv6 header exists */ 220 #define IPV6_MINMTU 0x04 /* use minimum MTU (IPV6_USE_MIN_MTU) */ 221 222 extern struct ip6stat ip6stat; /* statistics */ 223 extern int ip6_defhlim; /* default hop limit */ 224 extern int ip6_defmcasthlim; /* default multicast hop limit */ 225 extern int ip6_forwarding; /* act as router? */ 226 extern int ip6_mforwarding; /* act as multicast router? */ 227 extern int ip6_multipath; /* use multipath routes */ 228 extern int ip6_sendredirect; /* send ICMPv6 redirect? */ 229 extern int ip6_use_deprecated; /* allow deprecated addr as source */ 230 extern int ip6_rr_prune; /* router renumbering prefix 231 * walk list every 5 sec. */ 232 extern int ip6_mcast_pmtu; /* path MTU discovery for multicast */ 233 extern const int ip6_v6only; 234 extern int ip6_neighborgcthresh; /* Threshold # of NDP entries for GC */ 235 extern int ip6_maxifprefixes; /* Max acceptable prefixes via RA per IF */ 236 extern int ip6_maxifdefrouters; /* Max acceptable def routers via RA */ 237 extern int ip6_maxdynroutes; /* Max # of routes created via redirect */ 238 239 extern struct socket *ip6_mrouter; /* multicast routing daemon */ 240 extern int ip6_sendredirects; /* send IP redirects when forwarding? */ 241 extern int ip6_maxfragpackets; /* Maximum packets in reassembly queue */ 242 extern int ip6_maxfrags; /* Maximum fragments in reassembly queue */ 243 extern int ip6_accept_rtadv; /* Acts as a host not a router */ 244 extern int ip6_keepfaith; /* Firewall Aided Internet Translator */ 245 extern int ip6_log_interval; 246 extern time_t ip6_log_time; 247 extern int ip6_hdrnestlimit; /* upper limit of # of extension headers */ 248 extern int ip6_dad_count; /* DupAddrDetectionTransmits */ 249 extern int ip6_dad_pending; /* number of currently running DADs */ 250 251 extern int ip6_auto_flowlabel; 252 extern int ip6_auto_linklocal; 253 254 struct in6pcb; 255 struct inpcb; 256 257 int icmp6_ctloutput(int, struct socket *, int, int, struct mbuf **); 258 259 void ip6_init(void); 260 void ip6intr(void); 261 void ip6_input(struct mbuf *); 262 void ip6_freepcbopts(struct ip6_pktopts *); 263 void ip6_freemoptions(struct ip6_moptions *); 264 int ip6_unknown_opt(u_int8_t *, struct mbuf *, int); 265 u_int8_t *ip6_get_prevhdr(struct mbuf *, int); 266 int ip6_nexthdr(struct mbuf *, int, int, int *); 267 int ip6_lasthdr(struct mbuf *, int, int, int *); 268 int ip6_mforward(struct ip6_hdr *, struct ifnet *, struct mbuf *); 269 int ip6_process_hopopts(struct mbuf *, u_int8_t *, int, u_int32_t *, 270 u_int32_t *); 271 void ip6_savecontrol(struct inpcb *, struct mbuf *, struct mbuf **); 272 int ip6_sysctl(int *, u_int, void *, size_t *, void *, size_t); 273 274 void ip6_forward(struct mbuf *, int); 275 276 void ip6_mloopback(struct ifnet *, struct mbuf *, struct sockaddr_in6 *); 277 int ip6_output(struct mbuf *, struct ip6_pktopts *, struct route_in6 *, int, 278 struct ip6_moptions *, struct ifnet **, struct inpcb *); 279 int ip6_fragment(struct mbuf *, int, u_char, u_long); 280 int ip6_ctloutput(int, struct socket *, int, int, struct mbuf **); 281 int ip6_raw_ctloutput(int, struct socket *, int, int, struct mbuf **); 282 void ip6_initpktopts(struct ip6_pktopts *); 283 int ip6_setpktopts(struct mbuf *, struct ip6_pktopts *, 284 struct ip6_pktopts *, int, int); 285 void ip6_clearpktopts(struct ip6_pktopts *, int); 286 void ip6_randomid_init(void); 287 u_int32_t ip6_randomid(void); 288 289 int route6_input(struct mbuf **, int *, int); 290 291 void frag6_init(void); 292 int frag6_input(struct mbuf **, int *, int); 293 int frag6_deletefraghdr(struct mbuf *, int); 294 void frag6_slowtimo(void); 295 void frag6_drain(void); 296 297 void rip6_init(void); 298 int rip6_input(struct mbuf **mp, int *offp, int proto); 299 void rip6_ctlinput(int, struct sockaddr *, void *); 300 int rip6_ctloutput(int, struct socket *, int, int, struct mbuf **); 301 int rip6_output(struct mbuf *, ...); 302 int rip6_usrreq(struct socket *, 303 int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); 304 int rip6_sysctl(int *, u_int, void *, size_t *, void *, size_t); 305 306 int dest6_input(struct mbuf **, int *, int); 307 int none_input(struct mbuf **, int *, int); 308 309 struct in6_addr *in6_selectsrc(struct sockaddr_in6 *, struct ip6_pktopts *, 310 struct ip6_moptions *, struct route_in6 *, struct in6_addr *, 311 int *, u_int); 312 int in6_selectroute(struct sockaddr_in6 *, struct ip6_pktopts *, 313 struct ip6_moptions *, struct route_in6 *, struct ifnet **, 314 struct rtentry **, u_int rtableid); 315 316 u_int32_t ip6_randomflowlabel(void); 317 #endif /* _KERNEL */ 318 319 #endif /* !_NETINET6_IP6_VAR_H_ */ 320