in6_proto.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /* $OpenBSD: in6_proto.c,v 1.78 2015/07/18 15:51:17 mpi Exp $ */
  2. /* $KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun 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. * @(#)in_proto.c 8.1 (Berkeley) 6/10/93
  60. */
  61. #include <sys/param.h>
  62. #include <sys/socket.h>
  63. #include <sys/protosw.h>
  64. #include <sys/kernel.h>
  65. #include <sys/domain.h>
  66. #include <sys/mbuf.h>
  67. #include <net/if.h>
  68. #include <net/if_var.h>
  69. #include <net/route.h>
  70. #include <net/rtable.h>
  71. #include <netinet/in.h>
  72. #include <netinet/ip.h>
  73. #include <netinet/ip_var.h>
  74. #include <netinet/in_pcb.h>
  75. #include <netinet/ip6.h>
  76. #include <netinet6/ip6_var.h>
  77. #include <netinet/icmp6.h>
  78. #include <netinet/tcp.h>
  79. #include <netinet/tcp_timer.h>
  80. #include <netinet/tcp_var.h>
  81. #include <netinet/udp.h>
  82. #include <netinet/udp_var.h>
  83. #include <netinet/ip_ipsp.h>
  84. #include <netinet/ip_ah.h>
  85. #include <netinet/ip_esp.h>
  86. #include <netinet/ip_ipip.h>
  87. #ifdef PIM
  88. #include <netinet6/pim6_var.h>
  89. #endif
  90. #include <netinet6/in6_var.h>
  91. #include <netinet6/nd6.h>
  92. #include <netinet6/ip6protosw.h>
  93. #include "gif.h"
  94. #if NGIF > 0
  95. #include <netinet/ip_ether.h>
  96. #include <netinet6/in6_gif.h>
  97. #endif
  98. #include "carp.h"
  99. #if NCARP > 0
  100. #include <netinet/ip_carp.h>
  101. #endif
  102. #include "pf.h"
  103. #if NPF > 0
  104. #include <netinet6/ip6_divert.h>
  105. #endif
  106. /*
  107. * TCP/IP protocol family: IP6, ICMP6, UDP, TCP.
  108. */
  109. u_char ip6_protox[IPPROTO_MAX];
  110. struct ip6protosw inet6sw[] = {
  111. { 0, &inet6domain, IPPROTO_IPV6, 0,
  112. 0, 0, 0, 0,
  113. 0,
  114. ip6_init, 0, frag6_slowtimo, frag6_drain,
  115. ip6_sysctl,
  116. },
  117. { SOCK_DGRAM, &inet6domain, IPPROTO_UDP, PR_ATOMIC|PR_ADDR|PR_SPLICE,
  118. udp6_input, 0, udp6_ctlinput, ip6_ctloutput,
  119. udp_usrreq, 0,
  120. 0, 0, 0,
  121. udp_sysctl,
  122. },
  123. { SOCK_STREAM, &inet6domain, IPPROTO_TCP, PR_CONNREQUIRED|PR_WANTRCVD|PR_ABRTACPTDIS|PR_SPLICE,
  124. tcp6_input, 0, tcp6_ctlinput, tcp_ctloutput,
  125. tcp_usrreq,
  126. 0, 0, 0, 0,
  127. tcp_sysctl,
  128. },
  129. { SOCK_RAW, &inet6domain, IPPROTO_RAW, PR_ATOMIC|PR_ADDR,
  130. rip6_input, rip6_output, rip6_ctlinput, rip6_ctloutput,
  131. rip6_usrreq,
  132. 0, 0, 0, 0, rip6_sysctl
  133. },
  134. { SOCK_RAW, &inet6domain, IPPROTO_ICMPV6, PR_ATOMIC|PR_ADDR,
  135. icmp6_input, rip6_output, rip6_ctlinput, rip6_ctloutput,
  136. rip6_usrreq,
  137. icmp6_init, icmp6_fasttimo, 0, 0,
  138. icmp6_sysctl,
  139. },
  140. { SOCK_RAW, &inet6domain, IPPROTO_DSTOPTS,PR_ATOMIC|PR_ADDR,
  141. dest6_input, 0, 0, 0,
  142. 0,
  143. 0, 0, 0, 0,
  144. },
  145. { SOCK_RAW, &inet6domain, IPPROTO_ROUTING,PR_ATOMIC|PR_ADDR,
  146. route6_input, 0, 0, 0,
  147. 0,
  148. 0, 0, 0, 0,
  149. },
  150. { SOCK_RAW, &inet6domain, IPPROTO_FRAGMENT,PR_ATOMIC|PR_ADDR,
  151. frag6_input, 0, 0, 0,
  152. 0,
  153. 0, 0, 0, 0,
  154. },
  155. #ifdef IPSEC
  156. { SOCK_RAW, &inet6domain, IPPROTO_AH, PR_ATOMIC|PR_ADDR,
  157. ah6_input, rip6_output, 0, rip6_ctloutput,
  158. rip6_usrreq,
  159. 0, 0, 0, 0,
  160. ah_sysctl,
  161. },
  162. { SOCK_RAW, &inet6domain, IPPROTO_ESP, PR_ATOMIC|PR_ADDR,
  163. esp6_input, rip6_output, 0, rip6_ctloutput,
  164. rip6_usrreq,
  165. 0, 0, 0, 0,
  166. esp_sysctl,
  167. },
  168. { SOCK_RAW, &inet6domain, IPPROTO_IPCOMP, PR_ATOMIC|PR_ADDR,
  169. ipcomp6_input, rip6_output, 0, rip6_ctloutput,
  170. rip6_usrreq,
  171. 0, 0, 0, 0,
  172. ipcomp_sysctl,
  173. },
  174. #endif /* IPSEC */
  175. #if NGIF > 0
  176. { SOCK_RAW, &inet6domain, IPPROTO_ETHERIP,PR_ATOMIC|PR_ADDR,
  177. etherip_input6, rip6_output, 0, rip6_ctloutput,
  178. rip6_usrreq,
  179. 0, 0, 0, 0, etherip_sysctl
  180. },
  181. { SOCK_RAW, &inet6domain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR,
  182. in6_gif_input, rip6_output, 0, rip6_ctloutput,
  183. rip6_usrreq, /* XXX */
  184. 0, 0, 0, 0,
  185. },
  186. { SOCK_RAW, &inet6domain, IPPROTO_IPV4, PR_ATOMIC|PR_ADDR,
  187. in6_gif_input, rip6_output, 0, rip6_ctloutput,
  188. rip6_usrreq, /* XXX */
  189. 0, 0, 0, 0,
  190. },
  191. #else /* NGIF */
  192. { SOCK_RAW, &inet6domain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR,
  193. ip4_input6, rip6_output, 0, rip6_ctloutput,
  194. rip6_usrreq, /* XXX */
  195. 0, 0, 0, 0, ipip_sysctl
  196. },
  197. { SOCK_RAW, &inet6domain, IPPROTO_IPV4, PR_ATOMIC|PR_ADDR,
  198. ip4_input6, rip6_output, 0, rip6_ctloutput,
  199. rip6_usrreq, /* XXX */
  200. 0, 0, 0, 0,
  201. },
  202. #endif /* GIF */
  203. #ifdef PIM
  204. { SOCK_RAW, &inet6domain, IPPROTO_PIM, PR_ATOMIC|PR_ADDR,
  205. pim6_input, rip6_output, 0, rip6_ctloutput,
  206. rip6_usrreq,
  207. 0, 0, 0, 0, pim6_sysctl
  208. },
  209. #endif /* PIM */
  210. #if NCARP > 0
  211. { SOCK_RAW, &inet6domain, IPPROTO_CARP, PR_ATOMIC|PR_ADDR,
  212. carp6_proto_input, rip6_output, 0, rip6_ctloutput,
  213. rip6_usrreq,
  214. 0, 0, 0, 0, carp_sysctl
  215. },
  216. #endif /* NCARP */
  217. #if NPF > 0
  218. { SOCK_RAW, &inet6domain, IPPROTO_DIVERT, PR_ATOMIC|PR_ADDR,
  219. divert6_input, 0, 0, rip6_ctloutput,
  220. divert6_usrreq,
  221. divert6_init, 0, 0, 0, divert6_sysctl
  222. },
  223. #endif /* NPF > 0 */
  224. /* raw wildcard */
  225. { SOCK_RAW, &inet6domain, 0, PR_ATOMIC|PR_ADDR,
  226. rip6_input, rip6_output, 0, rip6_ctloutput,
  227. rip6_usrreq, rip6_init,
  228. 0, 0, 0,
  229. },
  230. };
  231. struct domain inet6domain =
  232. { AF_INET6, "internet6", 0, 0, 0,
  233. (struct protosw *)inet6sw,
  234. (struct protosw *)&inet6sw[nitems(inet6sw)], 0,
  235. rtable_attach,
  236. offsetof(struct sockaddr_in6, sin6_addr) << 3,
  237. sizeof(struct sockaddr_in6),
  238. in6_domifattach, in6_domifdetach, };
  239. /*
  240. * Internet configuration info
  241. */
  242. int ip6_forwarding = 0; /* no forwarding unless sysctl'd to enable */
  243. int ip6_mforwarding = 0; /* no multicast forwarding unless ... */
  244. int ip6_multipath = 0; /* no using multipath routes unless ... */
  245. int ip6_sendredirects = 1;
  246. int ip6_defhlim = IPV6_DEFHLIM;
  247. int ip6_defmcasthlim = IPV6_DEFAULT_MULTICAST_HOPS;
  248. int ip6_maxfragpackets = 200;
  249. int ip6_maxfrags = 200;
  250. int ip6_log_interval = 5;
  251. int ip6_hdrnestlimit = 10; /* appropriate? */
  252. int ip6_dad_count = 1; /* DupAddrDetectionTransmits */
  253. int ip6_dad_pending; /* number of currently running DADs */
  254. int ip6_auto_flowlabel = 1;
  255. int ip6_use_deprecated = 1; /* allow deprecated addr (RFC2462 5.5.4) */
  256. int ip6_rr_prune = 5; /* router renumbering prefix
  257. * walk list every 5 sec. */
  258. int ip6_mcast_pmtu = 0; /* enable pMTU discovery for multicast? */
  259. const int ip6_v6only = 1;
  260. int ip6_neighborgcthresh = 2048; /* Threshold # of NDP entries for GC */
  261. int ip6_maxifprefixes = 16; /* Max acceptable prefixes via RA per IF */
  262. int ip6_maxifdefrouters = 16; /* Max acceptable def routers via RA */
  263. int ip6_maxdynroutes = 4096; /* Max # of routes created via redirect */
  264. time_t ip6_log_time = (time_t)0L;
  265. /* raw IP6 parameters */
  266. /*
  267. * Nominal space allocated to a raw ip socket.
  268. */
  269. #define RIPV6SNDQ 8192
  270. #define RIPV6RCVQ 8192
  271. u_long rip6_sendspace = RIPV6SNDQ;
  272. u_long rip6_recvspace = RIPV6RCVQ;
  273. /* ICMPV6 parameters */
  274. int icmp6_redirtimeout = 10 * 60; /* 10 minutes */
  275. int icmp6errppslim = 100; /* 100pps */
  276. int ip6_mtudisc_timeout = IPMTUDISCTIMEOUT;