ip6_var.h 13 KB

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