af_inet6.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313
  1. /*
  2. * PF_INET6 socket protocol family
  3. * Linux INET6 implementation
  4. *
  5. * Authors:
  6. * Pedro Roque <roque@di.fc.ul.pt>
  7. *
  8. * Adapted from linux/net/ipv4/af_inet.c
  9. *
  10. * Fixes:
  11. * piggy, Karl Knutson : Socket protocol table
  12. * Hideaki YOSHIFUJI : sin6_scope_id support
  13. * Arnaldo Melo : check proc_net_create return, cleanups
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * as published by the Free Software Foundation; either version
  18. * 2 of the License, or (at your option) any later version.
  19. */
  20. #include <linux/module.h>
  21. #include <linux/capability.h>
  22. #include <linux/errno.h>
  23. #include <linux/types.h>
  24. #include <linux/socket.h>
  25. #include <linux/in.h>
  26. #include <linux/kernel.h>
  27. #include <linux/timer.h>
  28. #include <linux/string.h>
  29. #include <linux/sockios.h>
  30. #include <linux/net.h>
  31. #include <linux/fcntl.h>
  32. #include <linux/mm.h>
  33. #include <linux/interrupt.h>
  34. #include <linux/proc_fs.h>
  35. #include <linux/stat.h>
  36. #include <linux/init.h>
  37. #include <linux/slab.h>
  38. #include <linux/inet.h>
  39. #include <linux/netdevice.h>
  40. #include <linux/icmpv6.h>
  41. #include <linux/netfilter_ipv6.h>
  42. #include <net/ip.h>
  43. #include <net/ipv6.h>
  44. #include <net/udp.h>
  45. #include <net/udplite.h>
  46. #include <net/tcp.h>
  47. #include <net/ipip.h>
  48. #include <net/protocol.h>
  49. #include <net/inet_common.h>
  50. #include <net/route.h>
  51. #include <net/transp_v6.h>
  52. #include <net/ip6_route.h>
  53. #include <net/addrconf.h>
  54. #ifdef CONFIG_IPV6_TUNNEL
  55. #include <net/ip6_tunnel.h>
  56. #endif
  57. #include <asm/uaccess.h>
  58. #include <asm/system.h>
  59. #include <linux/mroute6.h>
  60. MODULE_AUTHOR("Cast of dozens");
  61. MODULE_DESCRIPTION("IPv6 protocol stack for Linux");
  62. MODULE_LICENSE("GPL");
  63. /* The inetsw6 table contains everything that inet6_create needs to
  64. * build a new socket.
  65. */
  66. static struct list_head inetsw6[SOCK_MAX];
  67. static DEFINE_SPINLOCK(inetsw6_lock);
  68. struct ipv6_params ipv6_defaults = {
  69. .disable_ipv6 = 0,
  70. .autoconf = 1,
  71. };
  72. static int disable_ipv6_mod = 0;
  73. module_param_named(disable, disable_ipv6_mod, int, 0444);
  74. MODULE_PARM_DESC(disable, "Disable IPv6 module such that it is non-functional");
  75. module_param_named(disable_ipv6, ipv6_defaults.disable_ipv6, int, 0444);
  76. MODULE_PARM_DESC(disable_ipv6, "Disable IPv6 on all interfaces");
  77. module_param_named(autoconf, ipv6_defaults.autoconf, int, 0444);
  78. MODULE_PARM_DESC(autoconf, "Enable IPv6 address autoconfiguration on all interfaces");
  79. static __inline__ struct ipv6_pinfo *inet6_sk_generic(struct sock *sk)
  80. {
  81. const int offset = sk->sk_prot->obj_size - sizeof(struct ipv6_pinfo);
  82. return (struct ipv6_pinfo *)(((u8 *)sk) + offset);
  83. }
  84. static int inet6_create(struct net *net, struct socket *sock, int protocol,
  85. int kern)
  86. {
  87. struct inet_sock *inet;
  88. struct ipv6_pinfo *np;
  89. struct sock *sk;
  90. struct inet_protosw *answer;
  91. struct proto *answer_prot;
  92. unsigned char answer_flags;
  93. char answer_no_check;
  94. int try_loading_module = 0;
  95. int err;
  96. if (sock->type != SOCK_RAW &&
  97. sock->type != SOCK_DGRAM &&
  98. !inet_ehash_secret)
  99. build_ehash_secret();
  100. /* Look for the requested type/protocol pair. */
  101. lookup_protocol:
  102. err = -ESOCKTNOSUPPORT;
  103. rcu_read_lock();
  104. list_for_each_entry_rcu(answer, &inetsw6[sock->type], list) {
  105. err = 0;
  106. /* Check the non-wild match. */
  107. if (protocol == answer->protocol) {
  108. if (protocol != IPPROTO_IP)
  109. break;
  110. } else {
  111. /* Check for the two wild cases. */
  112. if (IPPROTO_IP == protocol) {
  113. protocol = answer->protocol;
  114. break;
  115. }
  116. if (IPPROTO_IP == answer->protocol)
  117. break;
  118. }
  119. err = -EPROTONOSUPPORT;
  120. }
  121. if (err) {
  122. if (try_loading_module < 2) {
  123. rcu_read_unlock();
  124. /*
  125. * Be more specific, e.g. net-pf-10-proto-132-type-1
  126. * (net-pf-PF_INET6-proto-IPPROTO_SCTP-type-SOCK_STREAM)
  127. */
  128. if (++try_loading_module == 1)
  129. request_module("net-pf-%d-proto-%d-type-%d",
  130. PF_INET6, protocol, sock->type);
  131. /*
  132. * Fall back to generic, e.g. net-pf-10-proto-132
  133. * (net-pf-PF_INET6-proto-IPPROTO_SCTP)
  134. */
  135. else
  136. request_module("net-pf-%d-proto-%d",
  137. PF_INET6, protocol);
  138. goto lookup_protocol;
  139. } else
  140. goto out_rcu_unlock;
  141. }
  142. err = -EPERM;
  143. if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
  144. goto out_rcu_unlock;
  145. sock->ops = answer->ops;
  146. answer_prot = answer->prot;
  147. answer_no_check = answer->no_check;
  148. answer_flags = answer->flags;
  149. rcu_read_unlock();
  150. WARN_ON(answer_prot->slab == NULL);
  151. err = -ENOBUFS;
  152. sk = sk_alloc(net, PF_INET6, GFP_KERNEL, answer_prot);
  153. if (sk == NULL)
  154. goto out;
  155. sock_init_data(sock, sk);
  156. err = 0;
  157. sk->sk_no_check = answer_no_check;
  158. if (INET_PROTOSW_REUSE & answer_flags)
  159. sk->sk_reuse = 1;
  160. inet = inet_sk(sk);
  161. inet->is_icsk = (INET_PROTOSW_ICSK & answer_flags) != 0;
  162. if (SOCK_RAW == sock->type) {
  163. inet->inet_num = protocol;
  164. if (IPPROTO_RAW == protocol)
  165. inet->hdrincl = 1;
  166. }
  167. sk->sk_destruct = inet_sock_destruct;
  168. sk->sk_family = PF_INET6;
  169. sk->sk_protocol = protocol;
  170. sk->sk_backlog_rcv = answer->prot->backlog_rcv;
  171. inet_sk(sk)->pinet6 = np = inet6_sk_generic(sk);
  172. np->hop_limit = -1;
  173. np->mcast_hops = IPV6_DEFAULT_MCASTHOPS;
  174. np->mc_loop = 1;
  175. np->pmtudisc = IPV6_PMTUDISC_WANT;
  176. np->ipv6only = net->ipv6.sysctl.bindv6only;
  177. /* Init the ipv4 part of the socket since we can have sockets
  178. * using v6 API for ipv4.
  179. */
  180. inet->uc_ttl = -1;
  181. inet->mc_loop = 1;
  182. inet->mc_ttl = 1;
  183. inet->mc_index = 0;
  184. inet->mc_list = NULL;
  185. if (ipv4_config.no_pmtu_disc)
  186. inet->pmtudisc = IP_PMTUDISC_DONT;
  187. else
  188. inet->pmtudisc = IP_PMTUDISC_WANT;
  189. /*
  190. * Increment only the relevant sk_prot->socks debug field, this changes
  191. * the previous behaviour of incrementing both the equivalent to
  192. * answer->prot->socks (inet6_sock_nr) and inet_sock_nr.
  193. *
  194. * This allows better debug granularity as we'll know exactly how many
  195. * UDPv6, TCPv6, etc socks were allocated, not the sum of all IPv6
  196. * transport protocol socks. -acme
  197. */
  198. sk_refcnt_debug_inc(sk);
  199. if (inet->inet_num) {
  200. /* It assumes that any protocol which allows
  201. * the user to assign a number at socket
  202. * creation time automatically shares.
  203. */
  204. inet->inet_sport = htons(inet->inet_num);
  205. sk->sk_prot->hash(sk);
  206. }
  207. if (sk->sk_prot->init) {
  208. err = sk->sk_prot->init(sk);
  209. if (err) {
  210. sk_common_release(sk);
  211. goto out;
  212. }
  213. }
  214. out:
  215. return err;
  216. out_rcu_unlock:
  217. rcu_read_unlock();
  218. goto out;
  219. }
  220. /* bind for INET6 API */
  221. int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
  222. {
  223. struct sockaddr_in6 *addr=(struct sockaddr_in6 *)uaddr;
  224. struct sock *sk = sock->sk;
  225. struct inet_sock *inet = inet_sk(sk);
  226. struct ipv6_pinfo *np = inet6_sk(sk);
  227. struct net *net = sock_net(sk);
  228. __be32 v4addr = 0;
  229. unsigned short snum;
  230. int addr_type = 0;
  231. int err = 0;
  232. /* If the socket has its own bind function then use it. */
  233. if (sk->sk_prot->bind)
  234. return sk->sk_prot->bind(sk, uaddr, addr_len);
  235. if (addr_len < SIN6_LEN_RFC2133)
  236. return -EINVAL;
  237. if (addr->sin6_family != AF_INET6)
  238. return -EAFNOSUPPORT;
  239. addr_type = ipv6_addr_type(&addr->sin6_addr);
  240. if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
  241. return -EINVAL;
  242. snum = ntohs(addr->sin6_port);
  243. if (snum && snum < PROT_SOCK && !capable(CAP_NET_BIND_SERVICE))
  244. return -EACCES;
  245. lock_sock(sk);
  246. /* Check these errors (active socket, double bind). */
  247. if (sk->sk_state != TCP_CLOSE || inet->inet_num) {
  248. err = -EINVAL;
  249. goto out;
  250. }
  251. /* Check if the address belongs to the host. */
  252. if (addr_type == IPV6_ADDR_MAPPED) {
  253. int chk_addr_ret;
  254. /* Binding to v4-mapped address on a v6-only socket
  255. * makes no sense
  256. */
  257. if (np->ipv6only) {
  258. err = -EINVAL;
  259. goto out;
  260. }
  261. /* Reproduce AF_INET checks to make the bindings consistent */
  262. v4addr = addr->sin6_addr.s6_addr32[3];
  263. chk_addr_ret = inet_addr_type(net, v4addr);
  264. if (!sysctl_ip_nonlocal_bind &&
  265. !(inet->freebind || inet->transparent) &&
  266. v4addr != htonl(INADDR_ANY) &&
  267. chk_addr_ret != RTN_LOCAL &&
  268. chk_addr_ret != RTN_MULTICAST &&
  269. chk_addr_ret != RTN_BROADCAST) {
  270. err = -EADDRNOTAVAIL;
  271. goto out;
  272. }
  273. } else {
  274. if (addr_type != IPV6_ADDR_ANY) {
  275. struct net_device *dev = NULL;
  276. rcu_read_lock();
  277. if (addr_type & IPV6_ADDR_LINKLOCAL) {
  278. if (addr_len >= sizeof(struct sockaddr_in6) &&
  279. addr->sin6_scope_id) {
  280. /* Override any existing binding, if another one
  281. * is supplied by user.
  282. */
  283. sk->sk_bound_dev_if = addr->sin6_scope_id;
  284. }
  285. /* Binding to link-local address requires an interface */
  286. if (!sk->sk_bound_dev_if) {
  287. err = -EINVAL;
  288. goto out_unlock;
  289. }
  290. dev = dev_get_by_index_rcu(net, sk->sk_bound_dev_if);
  291. if (!dev) {
  292. err = -ENODEV;
  293. goto out_unlock;
  294. }
  295. }
  296. /* ipv4 addr of the socket is invalid. Only the
  297. * unspecified and mapped address have a v4 equivalent.
  298. */
  299. v4addr = LOOPBACK4_IPV6;
  300. if (!(addr_type & IPV6_ADDR_MULTICAST)) {
  301. if (!inet->transparent &&
  302. !ipv6_chk_addr(net, &addr->sin6_addr,
  303. dev, 0)) {
  304. err = -EADDRNOTAVAIL;
  305. goto out_unlock;
  306. }
  307. }
  308. rcu_read_unlock();
  309. }
  310. }
  311. inet->inet_rcv_saddr = v4addr;
  312. inet->inet_saddr = v4addr;
  313. ipv6_addr_copy(&np->rcv_saddr, &addr->sin6_addr);
  314. if (!(addr_type & IPV6_ADDR_MULTICAST))
  315. ipv6_addr_copy(&np->saddr, &addr->sin6_addr);
  316. /* Make sure we are allowed to bind here. */
  317. if (sk->sk_prot->get_port(sk, snum)) {
  318. inet_reset_saddr(sk);
  319. err = -EADDRINUSE;
  320. goto out;
  321. }
  322. if (addr_type != IPV6_ADDR_ANY) {
  323. sk->sk_userlocks |= SOCK_BINDADDR_LOCK;
  324. if (addr_type != IPV6_ADDR_MAPPED)
  325. np->ipv6only = 1;
  326. }
  327. if (snum)
  328. sk->sk_userlocks |= SOCK_BINDPORT_LOCK;
  329. inet->inet_sport = htons(inet->inet_num);
  330. inet->inet_dport = 0;
  331. inet->inet_daddr = 0;
  332. out:
  333. release_sock(sk);
  334. return err;
  335. out_unlock:
  336. rcu_read_unlock();
  337. goto out;
  338. }
  339. EXPORT_SYMBOL(inet6_bind);
  340. int inet6_release(struct socket *sock)
  341. {
  342. struct sock *sk = sock->sk;
  343. if (sk == NULL)
  344. return -EINVAL;
  345. /* Free mc lists */
  346. ipv6_sock_mc_close(sk);
  347. /* Free ac lists */
  348. ipv6_sock_ac_close(sk);
  349. return inet_release(sock);
  350. }
  351. EXPORT_SYMBOL(inet6_release);
  352. void inet6_destroy_sock(struct sock *sk)
  353. {
  354. struct ipv6_pinfo *np = inet6_sk(sk);
  355. struct sk_buff *skb;
  356. struct ipv6_txoptions *opt;
  357. /* Release rx options */
  358. if ((skb = xchg(&np->pktoptions, NULL)) != NULL)
  359. kfree_skb(skb);
  360. if ((skb = xchg(&np->rxpmtu, NULL)) != NULL)
  361. kfree_skb(skb);
  362. /* Free flowlabels */
  363. fl6_free_socklist(sk);
  364. /* Free tx options */
  365. if ((opt = xchg(&np->opt, NULL)) != NULL)
  366. sock_kfree_s(sk, opt, opt->tot_len);
  367. }
  368. EXPORT_SYMBOL_GPL(inet6_destroy_sock);
  369. /*
  370. * This does both peername and sockname.
  371. */
  372. int inet6_getname(struct socket *sock, struct sockaddr *uaddr,
  373. int *uaddr_len, int peer)
  374. {
  375. struct sockaddr_in6 *sin=(struct sockaddr_in6 *)uaddr;
  376. struct sock *sk = sock->sk;
  377. struct inet_sock *inet = inet_sk(sk);
  378. struct ipv6_pinfo *np = inet6_sk(sk);
  379. sin->sin6_family = AF_INET6;
  380. sin->sin6_flowinfo = 0;
  381. sin->sin6_scope_id = 0;
  382. if (peer) {
  383. if (!inet->inet_dport)
  384. return -ENOTCONN;
  385. if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_SYN_SENT)) &&
  386. peer == 1)
  387. return -ENOTCONN;
  388. sin->sin6_port = inet->inet_dport;
  389. ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
  390. if (np->sndflow)
  391. sin->sin6_flowinfo = np->flow_label;
  392. } else {
  393. if (ipv6_addr_any(&np->rcv_saddr))
  394. ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
  395. else
  396. ipv6_addr_copy(&sin->sin6_addr, &np->rcv_saddr);
  397. sin->sin6_port = inet->inet_sport;
  398. }
  399. if (ipv6_addr_type(&sin->sin6_addr) & IPV6_ADDR_LINKLOCAL)
  400. sin->sin6_scope_id = sk->sk_bound_dev_if;
  401. *uaddr_len = sizeof(*sin);
  402. return 0;
  403. }
  404. EXPORT_SYMBOL(inet6_getname);
  405. int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
  406. {
  407. struct sock *sk = sock->sk;
  408. struct net *net = sock_net(sk);
  409. switch(cmd)
  410. {
  411. case SIOCGSTAMP:
  412. return sock_get_timestamp(sk, (struct timeval __user *)arg);
  413. case SIOCGSTAMPNS:
  414. return sock_get_timestampns(sk, (struct timespec __user *)arg);
  415. case SIOCADDRT:
  416. case SIOCDELRT:
  417. return ipv6_route_ioctl(net, cmd, (void __user *)arg);
  418. case SIOCSIFADDR:
  419. return addrconf_add_ifaddr(net, (void __user *) arg);
  420. case SIOCDIFADDR:
  421. return addrconf_del_ifaddr(net, (void __user *) arg);
  422. case SIOCSIFDSTADDR:
  423. return addrconf_set_dstaddr(net, (void __user *) arg);
  424. default:
  425. if (!sk->sk_prot->ioctl)
  426. return -ENOIOCTLCMD;
  427. return sk->sk_prot->ioctl(sk, cmd, arg);
  428. }
  429. /*NOTREACHED*/
  430. return 0;
  431. }
  432. EXPORT_SYMBOL(inet6_ioctl);
  433. const struct proto_ops inet6_stream_ops = {
  434. .family = PF_INET6,
  435. .owner = THIS_MODULE,
  436. .release = inet6_release,
  437. .bind = inet6_bind,
  438. .connect = inet_stream_connect, /* ok */
  439. .socketpair = sock_no_socketpair, /* a do nothing */
  440. .accept = inet_accept, /* ok */
  441. .getname = inet6_getname,
  442. .poll = tcp_poll, /* ok */
  443. .ioctl = inet6_ioctl, /* must change */
  444. .listen = inet_listen, /* ok */
  445. .shutdown = inet_shutdown, /* ok */
  446. .setsockopt = sock_common_setsockopt, /* ok */
  447. .getsockopt = sock_common_getsockopt, /* ok */
  448. .sendmsg = inet_sendmsg, /* ok */
  449. .recvmsg = inet_recvmsg, /* ok */
  450. .mmap = sock_no_mmap,
  451. .sendpage = inet_sendpage,
  452. .splice_read = tcp_splice_read,
  453. #ifdef CONFIG_COMPAT
  454. .compat_setsockopt = compat_sock_common_setsockopt,
  455. .compat_getsockopt = compat_sock_common_getsockopt,
  456. #endif
  457. };
  458. const struct proto_ops inet6_dgram_ops = {
  459. .family = PF_INET6,
  460. .owner = THIS_MODULE,
  461. .release = inet6_release,
  462. .bind = inet6_bind,
  463. .connect = inet_dgram_connect, /* ok */
  464. .socketpair = sock_no_socketpair, /* a do nothing */
  465. .accept = sock_no_accept, /* a do nothing */
  466. .getname = inet6_getname,
  467. .poll = udp_poll, /* ok */
  468. .ioctl = inet6_ioctl, /* must change */
  469. .listen = sock_no_listen, /* ok */
  470. .shutdown = inet_shutdown, /* ok */
  471. .setsockopt = sock_common_setsockopt, /* ok */
  472. .getsockopt = sock_common_getsockopt, /* ok */
  473. .sendmsg = inet_sendmsg, /* ok */
  474. .recvmsg = inet_recvmsg, /* ok */
  475. .mmap = sock_no_mmap,
  476. .sendpage = sock_no_sendpage,
  477. #ifdef CONFIG_COMPAT
  478. .compat_setsockopt = compat_sock_common_setsockopt,
  479. .compat_getsockopt = compat_sock_common_getsockopt,
  480. #endif
  481. };
  482. static const struct net_proto_family inet6_family_ops = {
  483. .family = PF_INET6,
  484. .create = inet6_create,
  485. .owner = THIS_MODULE,
  486. };
  487. int inet6_register_protosw(struct inet_protosw *p)
  488. {
  489. struct list_head *lh;
  490. struct inet_protosw *answer;
  491. struct list_head *last_perm;
  492. int protocol = p->protocol;
  493. int ret;
  494. spin_lock_bh(&inetsw6_lock);
  495. ret = -EINVAL;
  496. if (p->type >= SOCK_MAX)
  497. goto out_illegal;
  498. /* If we are trying to override a permanent protocol, bail. */
  499. answer = NULL;
  500. ret = -EPERM;
  501. last_perm = &inetsw6[p->type];
  502. list_for_each(lh, &inetsw6[p->type]) {
  503. answer = list_entry(lh, struct inet_protosw, list);
  504. /* Check only the non-wild match. */
  505. if (INET_PROTOSW_PERMANENT & answer->flags) {
  506. if (protocol == answer->protocol)
  507. break;
  508. last_perm = lh;
  509. }
  510. answer = NULL;
  511. }
  512. if (answer)
  513. goto out_permanent;
  514. /* Add the new entry after the last permanent entry if any, so that
  515. * the new entry does not override a permanent entry when matched with
  516. * a wild-card protocol. But it is allowed to override any existing
  517. * non-permanent entry. This means that when we remove this entry, the
  518. * system automatically returns to the old behavior.
  519. */
  520. list_add_rcu(&p->list, last_perm);
  521. ret = 0;
  522. out:
  523. spin_unlock_bh(&inetsw6_lock);
  524. return ret;
  525. out_permanent:
  526. printk(KERN_ERR "Attempt to override permanent protocol %d.\n",
  527. protocol);
  528. goto out;
  529. out_illegal:
  530. printk(KERN_ERR
  531. "Ignoring attempt to register invalid socket type %d.\n",
  532. p->type);
  533. goto out;
  534. }
  535. EXPORT_SYMBOL(inet6_register_protosw);
  536. void
  537. inet6_unregister_protosw(struct inet_protosw *p)
  538. {
  539. if (INET_PROTOSW_PERMANENT & p->flags) {
  540. printk(KERN_ERR
  541. "Attempt to unregister permanent protocol %d.\n",
  542. p->protocol);
  543. } else {
  544. spin_lock_bh(&inetsw6_lock);
  545. list_del_rcu(&p->list);
  546. spin_unlock_bh(&inetsw6_lock);
  547. synchronize_net();
  548. }
  549. }
  550. EXPORT_SYMBOL(inet6_unregister_protosw);
  551. int inet6_sk_rebuild_header(struct sock *sk)
  552. {
  553. struct ipv6_pinfo *np = inet6_sk(sk);
  554. struct dst_entry *dst;
  555. dst = __sk_dst_check(sk, np->dst_cookie);
  556. if (dst == NULL) {
  557. struct inet_sock *inet = inet_sk(sk);
  558. struct in6_addr *final_p, final;
  559. struct flowi6 fl6;
  560. memset(&fl6, 0, sizeof(fl6));
  561. fl6.flowi6_proto = sk->sk_protocol;
  562. ipv6_addr_copy(&fl6.daddr, &np->daddr);
  563. ipv6_addr_copy(&fl6.saddr, &np->saddr);
  564. fl6.flowlabel = np->flow_label;
  565. fl6.flowi6_oif = sk->sk_bound_dev_if;
  566. fl6.flowi6_mark = sk->sk_mark;
  567. fl6.fl6_dport = inet->inet_dport;
  568. fl6.fl6_sport = inet->inet_sport;
  569. security_sk_classify_flow(sk, flowi6_to_flowi(&fl6));
  570. final_p = fl6_update_dst(&fl6, np->opt, &final);
  571. dst = ip6_dst_lookup_flow(sk, &fl6, final_p, false);
  572. if (IS_ERR(dst)) {
  573. sk->sk_route_caps = 0;
  574. sk->sk_err_soft = -PTR_ERR(dst);
  575. return PTR_ERR(dst);
  576. }
  577. __ip6_dst_store(sk, dst, NULL, NULL);
  578. }
  579. return 0;
  580. }
  581. EXPORT_SYMBOL_GPL(inet6_sk_rebuild_header);
  582. int ipv6_opt_accepted(struct sock *sk, struct sk_buff *skb)
  583. {
  584. struct ipv6_pinfo *np = inet6_sk(sk);
  585. struct inet6_skb_parm *opt = IP6CB(skb);
  586. if (np->rxopt.all) {
  587. if ((opt->hop && (np->rxopt.bits.hopopts ||
  588. np->rxopt.bits.ohopopts)) ||
  589. ((IPV6_FLOWINFO_MASK &
  590. *(__be32 *)skb_network_header(skb)) &&
  591. np->rxopt.bits.rxflow) ||
  592. (opt->srcrt && (np->rxopt.bits.srcrt ||
  593. np->rxopt.bits.osrcrt)) ||
  594. ((opt->dst1 || opt->dst0) &&
  595. (np->rxopt.bits.dstopts || np->rxopt.bits.odstopts)))
  596. return 1;
  597. }
  598. return 0;
  599. }
  600. EXPORT_SYMBOL_GPL(ipv6_opt_accepted);
  601. static int ipv6_gso_pull_exthdrs(struct sk_buff *skb, int proto)
  602. {
  603. const struct inet6_protocol *ops = NULL;
  604. for (;;) {
  605. struct ipv6_opt_hdr *opth;
  606. int len;
  607. if (proto != NEXTHDR_HOP) {
  608. ops = rcu_dereference(inet6_protos[proto]);
  609. if (unlikely(!ops))
  610. break;
  611. if (!(ops->flags & INET6_PROTO_GSO_EXTHDR))
  612. break;
  613. }
  614. if (unlikely(!pskb_may_pull(skb, 8)))
  615. break;
  616. opth = (void *)skb->data;
  617. len = ipv6_optlen(opth);
  618. if (unlikely(!pskb_may_pull(skb, len)))
  619. break;
  620. proto = opth->nexthdr;
  621. __skb_pull(skb, len);
  622. }
  623. return proto;
  624. }
  625. static int ipv6_gso_send_check(struct sk_buff *skb)
  626. {
  627. const struct ipv6hdr *ipv6h;
  628. const struct inet6_protocol *ops;
  629. int err = -EINVAL;
  630. if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h))))
  631. goto out;
  632. ipv6h = ipv6_hdr(skb);
  633. __skb_pull(skb, sizeof(*ipv6h));
  634. err = -EPROTONOSUPPORT;
  635. rcu_read_lock();
  636. ops = rcu_dereference(inet6_protos[
  637. ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr)]);
  638. if (likely(ops && ops->gso_send_check)) {
  639. skb_reset_transport_header(skb);
  640. err = ops->gso_send_check(skb);
  641. }
  642. rcu_read_unlock();
  643. out:
  644. return err;
  645. }
  646. static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb, u32 features)
  647. {
  648. struct sk_buff *segs = ERR_PTR(-EINVAL);
  649. struct ipv6hdr *ipv6h;
  650. const struct inet6_protocol *ops;
  651. int proto;
  652. struct frag_hdr *fptr;
  653. unsigned int unfrag_ip6hlen;
  654. u8 *prevhdr;
  655. int offset = 0;
  656. if (!(features & NETIF_F_V6_CSUM))
  657. features &= ~NETIF_F_SG;
  658. if (unlikely(skb_shinfo(skb)->gso_type &
  659. ~(SKB_GSO_UDP |
  660. SKB_GSO_DODGY |
  661. SKB_GSO_TCP_ECN |
  662. SKB_GSO_TCPV6 |
  663. 0)))
  664. goto out;
  665. if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h))))
  666. goto out;
  667. ipv6h = ipv6_hdr(skb);
  668. __skb_pull(skb, sizeof(*ipv6h));
  669. segs = ERR_PTR(-EPROTONOSUPPORT);
  670. proto = ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr);
  671. rcu_read_lock();
  672. ops = rcu_dereference(inet6_protos[proto]);
  673. if (likely(ops && ops->gso_segment)) {
  674. skb_reset_transport_header(skb);
  675. segs = ops->gso_segment(skb, features);
  676. }
  677. rcu_read_unlock();
  678. if (IS_ERR(segs))
  679. goto out;
  680. for (skb = segs; skb; skb = skb->next) {
  681. ipv6h = ipv6_hdr(skb);
  682. ipv6h->payload_len = htons(skb->len - skb->mac_len -
  683. sizeof(*ipv6h));
  684. if (proto == IPPROTO_UDP) {
  685. unfrag_ip6hlen = ip6_find_1stfragopt(skb, &prevhdr);
  686. fptr = (struct frag_hdr *)(skb_network_header(skb) +
  687. unfrag_ip6hlen);
  688. fptr->frag_off = htons(offset);
  689. if (skb->next != NULL)
  690. fptr->frag_off |= htons(IP6_MF);
  691. offset += (ntohs(ipv6h->payload_len) -
  692. sizeof(struct frag_hdr));
  693. }
  694. }
  695. out:
  696. return segs;
  697. }
  698. struct ipv6_gro_cb {
  699. struct napi_gro_cb napi;
  700. int proto;
  701. };
  702. #define IPV6_GRO_CB(skb) ((struct ipv6_gro_cb *)(skb)->cb)
  703. static struct sk_buff **ipv6_gro_receive(struct sk_buff **head,
  704. struct sk_buff *skb)
  705. {
  706. const struct inet6_protocol *ops;
  707. struct sk_buff **pp = NULL;
  708. struct sk_buff *p;
  709. struct ipv6hdr *iph;
  710. unsigned int nlen;
  711. unsigned int hlen;
  712. unsigned int off;
  713. int flush = 1;
  714. int proto;
  715. __wsum csum;
  716. off = skb_gro_offset(skb);
  717. hlen = off + sizeof(*iph);
  718. iph = skb_gro_header_fast(skb, off);
  719. if (skb_gro_header_hard(skb, hlen)) {
  720. iph = skb_gro_header_slow(skb, hlen, off);
  721. if (unlikely(!iph))
  722. goto out;
  723. }
  724. skb_gro_pull(skb, sizeof(*iph));
  725. skb_set_transport_header(skb, skb_gro_offset(skb));
  726. flush += ntohs(iph->payload_len) != skb_gro_len(skb);
  727. rcu_read_lock();
  728. proto = iph->nexthdr;
  729. ops = rcu_dereference(inet6_protos[proto]);
  730. if (!ops || !ops->gro_receive) {
  731. __pskb_pull(skb, skb_gro_offset(skb));
  732. proto = ipv6_gso_pull_exthdrs(skb, proto);
  733. skb_gro_pull(skb, -skb_transport_offset(skb));
  734. skb_reset_transport_header(skb);
  735. __skb_push(skb, skb_gro_offset(skb));
  736. if (!ops || !ops->gro_receive)
  737. goto out_unlock;
  738. iph = ipv6_hdr(skb);
  739. }
  740. IPV6_GRO_CB(skb)->proto = proto;
  741. flush--;
  742. nlen = skb_network_header_len(skb);
  743. for (p = *head; p; p = p->next) {
  744. struct ipv6hdr *iph2;
  745. if (!NAPI_GRO_CB(p)->same_flow)
  746. continue;
  747. iph2 = ipv6_hdr(p);
  748. /* All fields must match except length. */
  749. if (nlen != skb_network_header_len(p) ||
  750. memcmp(iph, iph2, offsetof(struct ipv6hdr, payload_len)) ||
  751. memcmp(&iph->nexthdr, &iph2->nexthdr,
  752. nlen - offsetof(struct ipv6hdr, nexthdr))) {
  753. NAPI_GRO_CB(p)->same_flow = 0;
  754. continue;
  755. }
  756. NAPI_GRO_CB(p)->flush |= flush;
  757. }
  758. NAPI_GRO_CB(skb)->flush |= flush;
  759. csum = skb->csum;
  760. skb_postpull_rcsum(skb, iph, skb_network_header_len(skb));
  761. pp = ops->gro_receive(head, skb);
  762. skb->csum = csum;
  763. out_unlock:
  764. rcu_read_unlock();
  765. out:
  766. NAPI_GRO_CB(skb)->flush |= flush;
  767. return pp;
  768. }
  769. static int ipv6_gro_complete(struct sk_buff *skb)
  770. {
  771. const struct inet6_protocol *ops;
  772. struct ipv6hdr *iph = ipv6_hdr(skb);
  773. int err = -ENOSYS;
  774. iph->payload_len = htons(skb->len - skb_network_offset(skb) -
  775. sizeof(*iph));
  776. rcu_read_lock();
  777. ops = rcu_dereference(inet6_protos[IPV6_GRO_CB(skb)->proto]);
  778. if (WARN_ON(!ops || !ops->gro_complete))
  779. goto out_unlock;
  780. err = ops->gro_complete(skb);
  781. out_unlock:
  782. rcu_read_unlock();
  783. return err;
  784. }
  785. static struct packet_type ipv6_packet_type __read_mostly = {
  786. .type = cpu_to_be16(ETH_P_IPV6),
  787. .func = ipv6_rcv,
  788. .gso_send_check = ipv6_gso_send_check,
  789. .gso_segment = ipv6_gso_segment,
  790. .gro_receive = ipv6_gro_receive,
  791. .gro_complete = ipv6_gro_complete,
  792. };
  793. static int __init ipv6_packet_init(void)
  794. {
  795. dev_add_pack(&ipv6_packet_type);
  796. return 0;
  797. }
  798. static void ipv6_packet_cleanup(void)
  799. {
  800. dev_remove_pack(&ipv6_packet_type);
  801. }
  802. static int __net_init ipv6_init_mibs(struct net *net)
  803. {
  804. if (snmp_mib_init((void __percpu **)net->mib.udp_stats_in6,
  805. sizeof(struct udp_mib),
  806. __alignof__(struct udp_mib)) < 0)
  807. return -ENOMEM;
  808. if (snmp_mib_init((void __percpu **)net->mib.udplite_stats_in6,
  809. sizeof(struct udp_mib),
  810. __alignof__(struct udp_mib)) < 0)
  811. goto err_udplite_mib;
  812. if (snmp_mib_init((void __percpu **)net->mib.ipv6_statistics,
  813. sizeof(struct ipstats_mib),
  814. __alignof__(struct ipstats_mib)) < 0)
  815. goto err_ip_mib;
  816. if (snmp_mib_init((void __percpu **)net->mib.icmpv6_statistics,
  817. sizeof(struct icmpv6_mib),
  818. __alignof__(struct icmpv6_mib)) < 0)
  819. goto err_icmp_mib;
  820. if (snmp_mib_init((void __percpu **)net->mib.icmpv6msg_statistics,
  821. sizeof(struct icmpv6msg_mib),
  822. __alignof__(struct icmpv6msg_mib)) < 0)
  823. goto err_icmpmsg_mib;
  824. return 0;
  825. err_icmpmsg_mib:
  826. snmp_mib_free((void __percpu **)net->mib.icmpv6_statistics);
  827. err_icmp_mib:
  828. snmp_mib_free((void __percpu **)net->mib.ipv6_statistics);
  829. err_ip_mib:
  830. snmp_mib_free((void __percpu **)net->mib.udplite_stats_in6);
  831. err_udplite_mib:
  832. snmp_mib_free((void __percpu **)net->mib.udp_stats_in6);
  833. return -ENOMEM;
  834. }
  835. static void ipv6_cleanup_mibs(struct net *net)
  836. {
  837. snmp_mib_free((void __percpu **)net->mib.udp_stats_in6);
  838. snmp_mib_free((void __percpu **)net->mib.udplite_stats_in6);
  839. snmp_mib_free((void __percpu **)net->mib.ipv6_statistics);
  840. snmp_mib_free((void __percpu **)net->mib.icmpv6_statistics);
  841. snmp_mib_free((void __percpu **)net->mib.icmpv6msg_statistics);
  842. }
  843. static int __net_init inet6_net_init(struct net *net)
  844. {
  845. int err = 0;
  846. net->ipv6.sysctl.bindv6only = 0;
  847. net->ipv6.sysctl.icmpv6_time = 1*HZ;
  848. err = ipv6_init_mibs(net);
  849. if (err)
  850. return err;
  851. #ifdef CONFIG_PROC_FS
  852. err = udp6_proc_init(net);
  853. if (err)
  854. goto out;
  855. err = tcp6_proc_init(net);
  856. if (err)
  857. goto proc_tcp6_fail;
  858. err = ac6_proc_init(net);
  859. if (err)
  860. goto proc_ac6_fail;
  861. #endif
  862. return err;
  863. #ifdef CONFIG_PROC_FS
  864. proc_ac6_fail:
  865. tcp6_proc_exit(net);
  866. proc_tcp6_fail:
  867. udp6_proc_exit(net);
  868. out:
  869. ipv6_cleanup_mibs(net);
  870. return err;
  871. #endif
  872. }
  873. static void __net_exit inet6_net_exit(struct net *net)
  874. {
  875. #ifdef CONFIG_PROC_FS
  876. udp6_proc_exit(net);
  877. tcp6_proc_exit(net);
  878. ac6_proc_exit(net);
  879. #endif
  880. ipv6_cleanup_mibs(net);
  881. }
  882. static struct pernet_operations inet6_net_ops = {
  883. .init = inet6_net_init,
  884. .exit = inet6_net_exit,
  885. };
  886. static int __init inet6_init(void)
  887. {
  888. struct sk_buff *dummy_skb;
  889. struct list_head *r;
  890. int err = 0;
  891. BUILD_BUG_ON(sizeof(struct inet6_skb_parm) > sizeof(dummy_skb->cb));
  892. /* Register the socket-side information for inet6_create. */
  893. for(r = &inetsw6[0]; r < &inetsw6[SOCK_MAX]; ++r)
  894. INIT_LIST_HEAD(r);
  895. if (disable_ipv6_mod) {
  896. printk(KERN_INFO
  897. "IPv6: Loaded, but administratively disabled, "
  898. "reboot required to enable\n");
  899. goto out;
  900. }
  901. err = proto_register(&tcpv6_prot, 1);
  902. if (err)
  903. goto out;
  904. err = proto_register(&udpv6_prot, 1);
  905. if (err)
  906. goto out_unregister_tcp_proto;
  907. err = proto_register(&udplitev6_prot, 1);
  908. if (err)
  909. goto out_unregister_udp_proto;
  910. err = proto_register(&rawv6_prot, 1);
  911. if (err)
  912. goto out_unregister_udplite_proto;
  913. /* We MUST register RAW sockets before we create the ICMP6,
  914. * IGMP6, or NDISC control sockets.
  915. */
  916. err = rawv6_init();
  917. if (err)
  918. goto out_unregister_raw_proto;
  919. /* Register the family here so that the init calls below will
  920. * be able to create sockets. (?? is this dangerous ??)
  921. */
  922. err = sock_register(&inet6_family_ops);
  923. if (err)
  924. goto out_sock_register_fail;
  925. #ifdef CONFIG_SYSCTL
  926. err = ipv6_static_sysctl_register();
  927. if (err)
  928. goto static_sysctl_fail;
  929. #endif
  930. /*
  931. * ipngwg API draft makes clear that the correct semantics
  932. * for TCP and UDP is to consider one TCP and UDP instance
  933. * in a host available by both INET and INET6 APIs and
  934. * able to communicate via both network protocols.
  935. */
  936. err = register_pernet_subsys(&inet6_net_ops);
  937. if (err)
  938. goto register_pernet_fail;
  939. err = icmpv6_init();
  940. if (err)
  941. goto icmp_fail;
  942. err = ip6_mr_init();
  943. if (err)
  944. goto ipmr_fail;
  945. err = ndisc_init();
  946. if (err)
  947. goto ndisc_fail;
  948. err = igmp6_init();
  949. if (err)
  950. goto igmp_fail;
  951. err = ipv6_netfilter_init();
  952. if (err)
  953. goto netfilter_fail;
  954. /* Create /proc/foo6 entries. */
  955. #ifdef CONFIG_PROC_FS
  956. err = -ENOMEM;
  957. if (raw6_proc_init())
  958. goto proc_raw6_fail;
  959. if (udplite6_proc_init())
  960. goto proc_udplite6_fail;
  961. if (ipv6_misc_proc_init())
  962. goto proc_misc6_fail;
  963. if (if6_proc_init())
  964. goto proc_if6_fail;
  965. #endif
  966. err = ip6_route_init();
  967. if (err)
  968. goto ip6_route_fail;
  969. err = ip6_flowlabel_init();
  970. if (err)
  971. goto ip6_flowlabel_fail;
  972. err = addrconf_init();
  973. if (err)
  974. goto addrconf_fail;
  975. /* Init v6 extension headers. */
  976. err = ipv6_exthdrs_init();
  977. if (err)
  978. goto ipv6_exthdrs_fail;
  979. err = ipv6_frag_init();
  980. if (err)
  981. goto ipv6_frag_fail;
  982. /* Init v6 transport protocols. */
  983. err = udpv6_init();
  984. if (err)
  985. goto udpv6_fail;
  986. err = udplitev6_init();
  987. if (err)
  988. goto udplitev6_fail;
  989. err = tcpv6_init();
  990. if (err)
  991. goto tcpv6_fail;
  992. err = ipv6_packet_init();
  993. if (err)
  994. goto ipv6_packet_fail;
  995. #ifdef CONFIG_SYSCTL
  996. err = ipv6_sysctl_register();
  997. if (err)
  998. goto sysctl_fail;
  999. #endif
  1000. out:
  1001. return err;
  1002. #ifdef CONFIG_SYSCTL
  1003. sysctl_fail:
  1004. ipv6_packet_cleanup();
  1005. #endif
  1006. ipv6_packet_fail:
  1007. tcpv6_exit();
  1008. tcpv6_fail:
  1009. udplitev6_exit();
  1010. udplitev6_fail:
  1011. udpv6_exit();
  1012. udpv6_fail:
  1013. ipv6_frag_exit();
  1014. ipv6_frag_fail:
  1015. ipv6_exthdrs_exit();
  1016. ipv6_exthdrs_fail:
  1017. addrconf_cleanup();
  1018. addrconf_fail:
  1019. ip6_flowlabel_cleanup();
  1020. ip6_flowlabel_fail:
  1021. ip6_route_cleanup();
  1022. ip6_route_fail:
  1023. #ifdef CONFIG_PROC_FS
  1024. if6_proc_exit();
  1025. proc_if6_fail:
  1026. ipv6_misc_proc_exit();
  1027. proc_misc6_fail:
  1028. udplite6_proc_exit();
  1029. proc_udplite6_fail:
  1030. raw6_proc_exit();
  1031. proc_raw6_fail:
  1032. #endif
  1033. ipv6_netfilter_fini();
  1034. netfilter_fail:
  1035. igmp6_cleanup();
  1036. igmp_fail:
  1037. ndisc_cleanup();
  1038. ndisc_fail:
  1039. ip6_mr_cleanup();
  1040. ipmr_fail:
  1041. icmpv6_cleanup();
  1042. icmp_fail:
  1043. unregister_pernet_subsys(&inet6_net_ops);
  1044. register_pernet_fail:
  1045. #ifdef CONFIG_SYSCTL
  1046. ipv6_static_sysctl_unregister();
  1047. static_sysctl_fail:
  1048. #endif
  1049. sock_unregister(PF_INET6);
  1050. rtnl_unregister_all(PF_INET6);
  1051. out_sock_register_fail:
  1052. rawv6_exit();
  1053. out_unregister_raw_proto:
  1054. proto_unregister(&rawv6_prot);
  1055. out_unregister_udplite_proto:
  1056. proto_unregister(&udplitev6_prot);
  1057. out_unregister_udp_proto:
  1058. proto_unregister(&udpv6_prot);
  1059. out_unregister_tcp_proto:
  1060. proto_unregister(&tcpv6_prot);
  1061. goto out;
  1062. }
  1063. module_init(inet6_init);
  1064. static void __exit inet6_exit(void)
  1065. {
  1066. if (disable_ipv6_mod)
  1067. return;
  1068. /* First of all disallow new sockets creation. */
  1069. sock_unregister(PF_INET6);
  1070. /* Disallow any further netlink messages */
  1071. rtnl_unregister_all(PF_INET6);
  1072. #ifdef CONFIG_SYSCTL
  1073. ipv6_sysctl_unregister();
  1074. #endif
  1075. udpv6_exit();
  1076. udplitev6_exit();
  1077. tcpv6_exit();
  1078. /* Cleanup code parts. */
  1079. ipv6_packet_cleanup();
  1080. ipv6_frag_exit();
  1081. ipv6_exthdrs_exit();
  1082. addrconf_cleanup();
  1083. ip6_flowlabel_cleanup();
  1084. ip6_route_cleanup();
  1085. #ifdef CONFIG_PROC_FS
  1086. /* Cleanup code parts. */
  1087. if6_proc_exit();
  1088. ipv6_misc_proc_exit();
  1089. udplite6_proc_exit();
  1090. raw6_proc_exit();
  1091. #endif
  1092. ipv6_netfilter_fini();
  1093. igmp6_cleanup();
  1094. ndisc_cleanup();
  1095. ip6_mr_cleanup();
  1096. icmpv6_cleanup();
  1097. rawv6_exit();
  1098. unregister_pernet_subsys(&inet6_net_ops);
  1099. #ifdef CONFIG_SYSCTL
  1100. ipv6_static_sysctl_unregister();
  1101. #endif
  1102. proto_unregister(&rawv6_prot);
  1103. proto_unregister(&udplitev6_prot);
  1104. proto_unregister(&udpv6_prot);
  1105. proto_unregister(&tcpv6_prot);
  1106. rcu_barrier(); /* Wait for completion of call_rcu()'s */
  1107. }
  1108. module_exit(inet6_exit);
  1109. MODULE_ALIAS_NETPROTO(PF_INET6);