af_inet6.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316
  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. addr_type = ipv6_addr_type(&addr->sin6_addr);
  238. if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
  239. return -EINVAL;
  240. snum = ntohs(addr->sin6_port);
  241. if (snum && snum < PROT_SOCK && !capable(CAP_NET_BIND_SERVICE))
  242. return -EACCES;
  243. lock_sock(sk);
  244. /* Check these errors (active socket, double bind). */
  245. if (sk->sk_state != TCP_CLOSE || inet->inet_num) {
  246. err = -EINVAL;
  247. goto out;
  248. }
  249. /* Check if the address belongs to the host. */
  250. if (addr_type == IPV6_ADDR_MAPPED) {
  251. int chk_addr_ret;
  252. /* Binding to v4-mapped address on a v6-only socket
  253. * makes no sense
  254. */
  255. if (np->ipv6only) {
  256. err = -EINVAL;
  257. goto out;
  258. }
  259. /* Reproduce AF_INET checks to make the bindings consitant */
  260. v4addr = addr->sin6_addr.s6_addr32[3];
  261. chk_addr_ret = inet_addr_type(net, v4addr);
  262. if (!sysctl_ip_nonlocal_bind &&
  263. !(inet->freebind || inet->transparent) &&
  264. v4addr != htonl(INADDR_ANY) &&
  265. chk_addr_ret != RTN_LOCAL &&
  266. chk_addr_ret != RTN_MULTICAST &&
  267. chk_addr_ret != RTN_BROADCAST) {
  268. err = -EADDRNOTAVAIL;
  269. goto out;
  270. }
  271. } else {
  272. if (addr_type != IPV6_ADDR_ANY) {
  273. struct net_device *dev = NULL;
  274. rcu_read_lock();
  275. if (addr_type & IPV6_ADDR_LINKLOCAL) {
  276. if (addr_len >= sizeof(struct sockaddr_in6) &&
  277. addr->sin6_scope_id) {
  278. /* Override any existing binding, if another one
  279. * is supplied by user.
  280. */
  281. sk->sk_bound_dev_if = addr->sin6_scope_id;
  282. }
  283. /* Binding to link-local address requires an interface */
  284. if (!sk->sk_bound_dev_if) {
  285. err = -EINVAL;
  286. goto out_unlock;
  287. }
  288. dev = dev_get_by_index_rcu(net, sk->sk_bound_dev_if);
  289. if (!dev) {
  290. err = -ENODEV;
  291. goto out_unlock;
  292. }
  293. }
  294. /* ipv4 addr of the socket is invalid. Only the
  295. * unspecified and mapped address have a v4 equivalent.
  296. */
  297. v4addr = LOOPBACK4_IPV6;
  298. if (!(addr_type & IPV6_ADDR_MULTICAST)) {
  299. if (!inet->transparent &&
  300. !ipv6_chk_addr(net, &addr->sin6_addr,
  301. dev, 0)) {
  302. err = -EADDRNOTAVAIL;
  303. goto out_unlock;
  304. }
  305. }
  306. rcu_read_unlock();
  307. }
  308. }
  309. inet->inet_rcv_saddr = v4addr;
  310. inet->inet_saddr = v4addr;
  311. ipv6_addr_copy(&np->rcv_saddr, &addr->sin6_addr);
  312. if (!(addr_type & IPV6_ADDR_MULTICAST))
  313. ipv6_addr_copy(&np->saddr, &addr->sin6_addr);
  314. /* Make sure we are allowed to bind here. */
  315. if (sk->sk_prot->get_port(sk, snum)) {
  316. inet_reset_saddr(sk);
  317. err = -EADDRINUSE;
  318. goto out;
  319. }
  320. if (addr_type != IPV6_ADDR_ANY) {
  321. sk->sk_userlocks |= SOCK_BINDADDR_LOCK;
  322. if (addr_type != IPV6_ADDR_MAPPED)
  323. np->ipv6only = 1;
  324. }
  325. if (snum)
  326. sk->sk_userlocks |= SOCK_BINDPORT_LOCK;
  327. inet->inet_sport = htons(inet->inet_num);
  328. inet->inet_dport = 0;
  329. inet->inet_daddr = 0;
  330. out:
  331. release_sock(sk);
  332. return err;
  333. out_unlock:
  334. rcu_read_unlock();
  335. goto out;
  336. }
  337. EXPORT_SYMBOL(inet6_bind);
  338. int inet6_release(struct socket *sock)
  339. {
  340. struct sock *sk = sock->sk;
  341. if (sk == NULL)
  342. return -EINVAL;
  343. /* Free mc lists */
  344. ipv6_sock_mc_close(sk);
  345. /* Free ac lists */
  346. ipv6_sock_ac_close(sk);
  347. return inet_release(sock);
  348. }
  349. EXPORT_SYMBOL(inet6_release);
  350. void inet6_destroy_sock(struct sock *sk)
  351. {
  352. struct ipv6_pinfo *np = inet6_sk(sk);
  353. struct sk_buff *skb;
  354. struct ipv6_txoptions *opt;
  355. /* Release rx options */
  356. if ((skb = xchg(&np->pktoptions, NULL)) != NULL)
  357. kfree_skb(skb);
  358. if ((skb = xchg(&np->rxpmtu, NULL)) != NULL)
  359. kfree_skb(skb);
  360. /* Free flowlabels */
  361. fl6_free_socklist(sk);
  362. /* Free tx options */
  363. if ((opt = xchg(&np->opt, NULL)) != NULL)
  364. sock_kfree_s(sk, opt, opt->tot_len);
  365. }
  366. EXPORT_SYMBOL_GPL(inet6_destroy_sock);
  367. /*
  368. * This does both peername and sockname.
  369. */
  370. int inet6_getname(struct socket *sock, struct sockaddr *uaddr,
  371. int *uaddr_len, int peer)
  372. {
  373. struct sockaddr_in6 *sin=(struct sockaddr_in6 *)uaddr;
  374. struct sock *sk = sock->sk;
  375. struct inet_sock *inet = inet_sk(sk);
  376. struct ipv6_pinfo *np = inet6_sk(sk);
  377. sin->sin6_family = AF_INET6;
  378. sin->sin6_flowinfo = 0;
  379. sin->sin6_scope_id = 0;
  380. if (peer) {
  381. if (!inet->inet_dport)
  382. return -ENOTCONN;
  383. if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_SYN_SENT)) &&
  384. peer == 1)
  385. return -ENOTCONN;
  386. sin->sin6_port = inet->inet_dport;
  387. ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
  388. if (np->sndflow)
  389. sin->sin6_flowinfo = np->flow_label;
  390. } else {
  391. if (ipv6_addr_any(&np->rcv_saddr))
  392. ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
  393. else
  394. ipv6_addr_copy(&sin->sin6_addr, &np->rcv_saddr);
  395. sin->sin6_port = inet->inet_sport;
  396. }
  397. if (ipv6_addr_type(&sin->sin6_addr) & IPV6_ADDR_LINKLOCAL)
  398. sin->sin6_scope_id = sk->sk_bound_dev_if;
  399. *uaddr_len = sizeof(*sin);
  400. return 0;
  401. }
  402. EXPORT_SYMBOL(inet6_getname);
  403. int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
  404. {
  405. struct sock *sk = sock->sk;
  406. struct net *net = sock_net(sk);
  407. switch(cmd)
  408. {
  409. case SIOCGSTAMP:
  410. return sock_get_timestamp(sk, (struct timeval __user *)arg);
  411. case SIOCGSTAMPNS:
  412. return sock_get_timestampns(sk, (struct timespec __user *)arg);
  413. case SIOCADDRT:
  414. case SIOCDELRT:
  415. return ipv6_route_ioctl(net, cmd, (void __user *)arg);
  416. case SIOCSIFADDR:
  417. return addrconf_add_ifaddr(net, (void __user *) arg);
  418. case SIOCDIFADDR:
  419. return addrconf_del_ifaddr(net, (void __user *) arg);
  420. case SIOCSIFDSTADDR:
  421. return addrconf_set_dstaddr(net, (void __user *) arg);
  422. default:
  423. if (!sk->sk_prot->ioctl)
  424. return -ENOIOCTLCMD;
  425. return sk->sk_prot->ioctl(sk, cmd, arg);
  426. }
  427. /*NOTREACHED*/
  428. return 0;
  429. }
  430. EXPORT_SYMBOL(inet6_ioctl);
  431. const struct proto_ops inet6_stream_ops = {
  432. .family = PF_INET6,
  433. .owner = THIS_MODULE,
  434. .release = inet6_release,
  435. .bind = inet6_bind,
  436. .connect = inet_stream_connect, /* ok */
  437. .socketpair = sock_no_socketpair, /* a do nothing */
  438. .accept = inet_accept, /* ok */
  439. .getname = inet6_getname,
  440. .poll = tcp_poll, /* ok */
  441. .ioctl = inet6_ioctl, /* must change */
  442. .listen = inet_listen, /* ok */
  443. .shutdown = inet_shutdown, /* ok */
  444. .setsockopt = sock_common_setsockopt, /* ok */
  445. .getsockopt = sock_common_getsockopt, /* ok */
  446. .sendmsg = inet_sendmsg, /* ok */
  447. .recvmsg = inet_recvmsg, /* ok */
  448. .mmap = sock_no_mmap,
  449. .sendpage = inet_sendpage,
  450. .splice_read = tcp_splice_read,
  451. #ifdef CONFIG_COMPAT
  452. .compat_setsockopt = compat_sock_common_setsockopt,
  453. .compat_getsockopt = compat_sock_common_getsockopt,
  454. #endif
  455. };
  456. const struct proto_ops inet6_dgram_ops = {
  457. .family = PF_INET6,
  458. .owner = THIS_MODULE,
  459. .release = inet6_release,
  460. .bind = inet6_bind,
  461. .connect = inet_dgram_connect, /* ok */
  462. .socketpair = sock_no_socketpair, /* a do nothing */
  463. .accept = sock_no_accept, /* a do nothing */
  464. .getname = inet6_getname,
  465. .poll = udp_poll, /* ok */
  466. .ioctl = inet6_ioctl, /* must change */
  467. .listen = sock_no_listen, /* ok */
  468. .shutdown = inet_shutdown, /* ok */
  469. .setsockopt = sock_common_setsockopt, /* ok */
  470. .getsockopt = sock_common_getsockopt, /* ok */
  471. .sendmsg = inet_sendmsg, /* ok */
  472. .recvmsg = inet_recvmsg, /* ok */
  473. .mmap = sock_no_mmap,
  474. .sendpage = sock_no_sendpage,
  475. #ifdef CONFIG_COMPAT
  476. .compat_setsockopt = compat_sock_common_setsockopt,
  477. .compat_getsockopt = compat_sock_common_getsockopt,
  478. #endif
  479. };
  480. static const struct net_proto_family inet6_family_ops = {
  481. .family = PF_INET6,
  482. .create = inet6_create,
  483. .owner = THIS_MODULE,
  484. };
  485. int inet6_register_protosw(struct inet_protosw *p)
  486. {
  487. struct list_head *lh;
  488. struct inet_protosw *answer;
  489. struct list_head *last_perm;
  490. int protocol = p->protocol;
  491. int ret;
  492. spin_lock_bh(&inetsw6_lock);
  493. ret = -EINVAL;
  494. if (p->type >= SOCK_MAX)
  495. goto out_illegal;
  496. /* If we are trying to override a permanent protocol, bail. */
  497. answer = NULL;
  498. ret = -EPERM;
  499. last_perm = &inetsw6[p->type];
  500. list_for_each(lh, &inetsw6[p->type]) {
  501. answer = list_entry(lh, struct inet_protosw, list);
  502. /* Check only the non-wild match. */
  503. if (INET_PROTOSW_PERMANENT & answer->flags) {
  504. if (protocol == answer->protocol)
  505. break;
  506. last_perm = lh;
  507. }
  508. answer = NULL;
  509. }
  510. if (answer)
  511. goto out_permanent;
  512. /* Add the new entry after the last permanent entry if any, so that
  513. * the new entry does not override a permanent entry when matched with
  514. * a wild-card protocol. But it is allowed to override any existing
  515. * non-permanent entry. This means that when we remove this entry, the
  516. * system automatically returns to the old behavior.
  517. */
  518. list_add_rcu(&p->list, last_perm);
  519. ret = 0;
  520. out:
  521. spin_unlock_bh(&inetsw6_lock);
  522. return ret;
  523. out_permanent:
  524. printk(KERN_ERR "Attempt to override permanent protocol %d.\n",
  525. protocol);
  526. goto out;
  527. out_illegal:
  528. printk(KERN_ERR
  529. "Ignoring attempt to register invalid socket type %d.\n",
  530. p->type);
  531. goto out;
  532. }
  533. EXPORT_SYMBOL(inet6_register_protosw);
  534. void
  535. inet6_unregister_protosw(struct inet_protosw *p)
  536. {
  537. if (INET_PROTOSW_PERMANENT & p->flags) {
  538. printk(KERN_ERR
  539. "Attempt to unregister permanent protocol %d.\n",
  540. p->protocol);
  541. } else {
  542. spin_lock_bh(&inetsw6_lock);
  543. list_del_rcu(&p->list);
  544. spin_unlock_bh(&inetsw6_lock);
  545. synchronize_net();
  546. }
  547. }
  548. EXPORT_SYMBOL(inet6_unregister_protosw);
  549. int inet6_sk_rebuild_header(struct sock *sk)
  550. {
  551. int err;
  552. struct dst_entry *dst;
  553. struct ipv6_pinfo *np = inet6_sk(sk);
  554. dst = __sk_dst_check(sk, np->dst_cookie);
  555. if (dst == NULL) {
  556. struct inet_sock *inet = inet_sk(sk);
  557. struct in6_addr *final_p, final;
  558. struct flowi fl;
  559. memset(&fl, 0, sizeof(fl));
  560. fl.proto = sk->sk_protocol;
  561. ipv6_addr_copy(&fl.fl6_dst, &np->daddr);
  562. ipv6_addr_copy(&fl.fl6_src, &np->saddr);
  563. fl.fl6_flowlabel = np->flow_label;
  564. fl.oif = sk->sk_bound_dev_if;
  565. fl.mark = sk->sk_mark;
  566. fl.fl_ip_dport = inet->inet_dport;
  567. fl.fl_ip_sport = inet->inet_sport;
  568. security_sk_classify_flow(sk, &fl);
  569. final_p = fl6_update_dst(&fl, np->opt, &final);
  570. err = ip6_dst_lookup(sk, &dst, &fl);
  571. if (err) {
  572. sk->sk_route_caps = 0;
  573. return err;
  574. }
  575. if (final_p)
  576. ipv6_addr_copy(&fl.fl6_dst, final_p);
  577. if ((err = xfrm_lookup(sock_net(sk), &dst, &fl, sk, 0)) < 0) {
  578. sk->sk_err_soft = -err;
  579. return err;
  580. }
  581. __ip6_dst_store(sk, dst, NULL, NULL);
  582. }
  583. return 0;
  584. }
  585. EXPORT_SYMBOL_GPL(inet6_sk_rebuild_header);
  586. int ipv6_opt_accepted(struct sock *sk, struct sk_buff *skb)
  587. {
  588. struct ipv6_pinfo *np = inet6_sk(sk);
  589. struct inet6_skb_parm *opt = IP6CB(skb);
  590. if (np->rxopt.all) {
  591. if ((opt->hop && (np->rxopt.bits.hopopts ||
  592. np->rxopt.bits.ohopopts)) ||
  593. ((IPV6_FLOWINFO_MASK &
  594. *(__be32 *)skb_network_header(skb)) &&
  595. np->rxopt.bits.rxflow) ||
  596. (opt->srcrt && (np->rxopt.bits.srcrt ||
  597. np->rxopt.bits.osrcrt)) ||
  598. ((opt->dst1 || opt->dst0) &&
  599. (np->rxopt.bits.dstopts || np->rxopt.bits.odstopts)))
  600. return 1;
  601. }
  602. return 0;
  603. }
  604. EXPORT_SYMBOL_GPL(ipv6_opt_accepted);
  605. static int ipv6_gso_pull_exthdrs(struct sk_buff *skb, int proto)
  606. {
  607. const struct inet6_protocol *ops = NULL;
  608. for (;;) {
  609. struct ipv6_opt_hdr *opth;
  610. int len;
  611. if (proto != NEXTHDR_HOP) {
  612. ops = rcu_dereference(inet6_protos[proto]);
  613. if (unlikely(!ops))
  614. break;
  615. if (!(ops->flags & INET6_PROTO_GSO_EXTHDR))
  616. break;
  617. }
  618. if (unlikely(!pskb_may_pull(skb, 8)))
  619. break;
  620. opth = (void *)skb->data;
  621. len = ipv6_optlen(opth);
  622. if (unlikely(!pskb_may_pull(skb, len)))
  623. break;
  624. proto = opth->nexthdr;
  625. __skb_pull(skb, len);
  626. }
  627. return proto;
  628. }
  629. static int ipv6_gso_send_check(struct sk_buff *skb)
  630. {
  631. struct ipv6hdr *ipv6h;
  632. const struct inet6_protocol *ops;
  633. int err = -EINVAL;
  634. if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h))))
  635. goto out;
  636. ipv6h = ipv6_hdr(skb);
  637. __skb_pull(skb, sizeof(*ipv6h));
  638. err = -EPROTONOSUPPORT;
  639. rcu_read_lock();
  640. ops = rcu_dereference(inet6_protos[
  641. ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr)]);
  642. if (likely(ops && ops->gso_send_check)) {
  643. skb_reset_transport_header(skb);
  644. err = ops->gso_send_check(skb);
  645. }
  646. rcu_read_unlock();
  647. out:
  648. return err;
  649. }
  650. static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb, int features)
  651. {
  652. struct sk_buff *segs = ERR_PTR(-EINVAL);
  653. struct ipv6hdr *ipv6h;
  654. const struct inet6_protocol *ops;
  655. int proto;
  656. struct frag_hdr *fptr;
  657. unsigned int unfrag_ip6hlen;
  658. u8 *prevhdr;
  659. int offset = 0;
  660. if (!(features & NETIF_F_V6_CSUM))
  661. features &= ~NETIF_F_SG;
  662. if (unlikely(skb_shinfo(skb)->gso_type &
  663. ~(SKB_GSO_UDP |
  664. SKB_GSO_DODGY |
  665. SKB_GSO_TCP_ECN |
  666. SKB_GSO_TCPV6 |
  667. 0)))
  668. goto out;
  669. if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h))))
  670. goto out;
  671. ipv6h = ipv6_hdr(skb);
  672. __skb_pull(skb, sizeof(*ipv6h));
  673. segs = ERR_PTR(-EPROTONOSUPPORT);
  674. proto = ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr);
  675. rcu_read_lock();
  676. ops = rcu_dereference(inet6_protos[proto]);
  677. if (likely(ops && ops->gso_segment)) {
  678. skb_reset_transport_header(skb);
  679. segs = ops->gso_segment(skb, features);
  680. }
  681. rcu_read_unlock();
  682. if (IS_ERR(segs))
  683. goto out;
  684. for (skb = segs; skb; skb = skb->next) {
  685. ipv6h = ipv6_hdr(skb);
  686. ipv6h->payload_len = htons(skb->len - skb->mac_len -
  687. sizeof(*ipv6h));
  688. if (proto == IPPROTO_UDP) {
  689. unfrag_ip6hlen = ip6_find_1stfragopt(skb, &prevhdr);
  690. fptr = (struct frag_hdr *)(skb_network_header(skb) +
  691. unfrag_ip6hlen);
  692. fptr->frag_off = htons(offset);
  693. if (skb->next != NULL)
  694. fptr->frag_off |= htons(IP6_MF);
  695. offset += (ntohs(ipv6h->payload_len) -
  696. sizeof(struct frag_hdr));
  697. }
  698. }
  699. out:
  700. return segs;
  701. }
  702. struct ipv6_gro_cb {
  703. struct napi_gro_cb napi;
  704. int proto;
  705. };
  706. #define IPV6_GRO_CB(skb) ((struct ipv6_gro_cb *)(skb)->cb)
  707. static struct sk_buff **ipv6_gro_receive(struct sk_buff **head,
  708. struct sk_buff *skb)
  709. {
  710. const struct inet6_protocol *ops;
  711. struct sk_buff **pp = NULL;
  712. struct sk_buff *p;
  713. struct ipv6hdr *iph;
  714. unsigned int nlen;
  715. unsigned int hlen;
  716. unsigned int off;
  717. int flush = 1;
  718. int proto;
  719. __wsum csum;
  720. off = skb_gro_offset(skb);
  721. hlen = off + sizeof(*iph);
  722. iph = skb_gro_header_fast(skb, off);
  723. if (skb_gro_header_hard(skb, hlen)) {
  724. iph = skb_gro_header_slow(skb, hlen, off);
  725. if (unlikely(!iph))
  726. goto out;
  727. }
  728. skb_gro_pull(skb, sizeof(*iph));
  729. skb_set_transport_header(skb, skb_gro_offset(skb));
  730. flush += ntohs(iph->payload_len) != skb_gro_len(skb);
  731. rcu_read_lock();
  732. proto = iph->nexthdr;
  733. ops = rcu_dereference(inet6_protos[proto]);
  734. if (!ops || !ops->gro_receive) {
  735. __pskb_pull(skb, skb_gro_offset(skb));
  736. proto = ipv6_gso_pull_exthdrs(skb, proto);
  737. skb_gro_pull(skb, -skb_transport_offset(skb));
  738. skb_reset_transport_header(skb);
  739. __skb_push(skb, skb_gro_offset(skb));
  740. if (!ops || !ops->gro_receive)
  741. goto out_unlock;
  742. iph = ipv6_hdr(skb);
  743. }
  744. IPV6_GRO_CB(skb)->proto = proto;
  745. flush--;
  746. nlen = skb_network_header_len(skb);
  747. for (p = *head; p; p = p->next) {
  748. struct ipv6hdr *iph2;
  749. if (!NAPI_GRO_CB(p)->same_flow)
  750. continue;
  751. iph2 = ipv6_hdr(p);
  752. /* All fields must match except length. */
  753. if (nlen != skb_network_header_len(p) ||
  754. memcmp(iph, iph2, offsetof(struct ipv6hdr, payload_len)) ||
  755. memcmp(&iph->nexthdr, &iph2->nexthdr,
  756. nlen - offsetof(struct ipv6hdr, nexthdr))) {
  757. NAPI_GRO_CB(p)->same_flow = 0;
  758. continue;
  759. }
  760. NAPI_GRO_CB(p)->flush |= flush;
  761. }
  762. NAPI_GRO_CB(skb)->flush |= flush;
  763. csum = skb->csum;
  764. skb_postpull_rcsum(skb, iph, skb_network_header_len(skb));
  765. pp = ops->gro_receive(head, skb);
  766. skb->csum = csum;
  767. out_unlock:
  768. rcu_read_unlock();
  769. out:
  770. NAPI_GRO_CB(skb)->flush |= flush;
  771. return pp;
  772. }
  773. static int ipv6_gro_complete(struct sk_buff *skb)
  774. {
  775. const struct inet6_protocol *ops;
  776. struct ipv6hdr *iph = ipv6_hdr(skb);
  777. int err = -ENOSYS;
  778. iph->payload_len = htons(skb->len - skb_network_offset(skb) -
  779. sizeof(*iph));
  780. rcu_read_lock();
  781. ops = rcu_dereference(inet6_protos[IPV6_GRO_CB(skb)->proto]);
  782. if (WARN_ON(!ops || !ops->gro_complete))
  783. goto out_unlock;
  784. err = ops->gro_complete(skb);
  785. out_unlock:
  786. rcu_read_unlock();
  787. return err;
  788. }
  789. static struct packet_type ipv6_packet_type __read_mostly = {
  790. .type = cpu_to_be16(ETH_P_IPV6),
  791. .func = ipv6_rcv,
  792. .gso_send_check = ipv6_gso_send_check,
  793. .gso_segment = ipv6_gso_segment,
  794. .gro_receive = ipv6_gro_receive,
  795. .gro_complete = ipv6_gro_complete,
  796. };
  797. static int __init ipv6_packet_init(void)
  798. {
  799. dev_add_pack(&ipv6_packet_type);
  800. return 0;
  801. }
  802. static void ipv6_packet_cleanup(void)
  803. {
  804. dev_remove_pack(&ipv6_packet_type);
  805. }
  806. static int __net_init ipv6_init_mibs(struct net *net)
  807. {
  808. if (snmp_mib_init((void __percpu **)net->mib.udp_stats_in6,
  809. sizeof(struct udp_mib),
  810. __alignof__(struct udp_mib)) < 0)
  811. return -ENOMEM;
  812. if (snmp_mib_init((void __percpu **)net->mib.udplite_stats_in6,
  813. sizeof(struct udp_mib),
  814. __alignof__(struct udp_mib)) < 0)
  815. goto err_udplite_mib;
  816. if (snmp_mib_init((void __percpu **)net->mib.ipv6_statistics,
  817. sizeof(struct ipstats_mib),
  818. __alignof__(struct ipstats_mib)) < 0)
  819. goto err_ip_mib;
  820. if (snmp_mib_init((void __percpu **)net->mib.icmpv6_statistics,
  821. sizeof(struct icmpv6_mib),
  822. __alignof__(struct icmpv6_mib)) < 0)
  823. goto err_icmp_mib;
  824. if (snmp_mib_init((void __percpu **)net->mib.icmpv6msg_statistics,
  825. sizeof(struct icmpv6msg_mib),
  826. __alignof__(struct icmpv6msg_mib)) < 0)
  827. goto err_icmpmsg_mib;
  828. return 0;
  829. err_icmpmsg_mib:
  830. snmp_mib_free((void __percpu **)net->mib.icmpv6_statistics);
  831. err_icmp_mib:
  832. snmp_mib_free((void __percpu **)net->mib.ipv6_statistics);
  833. err_ip_mib:
  834. snmp_mib_free((void __percpu **)net->mib.udplite_stats_in6);
  835. err_udplite_mib:
  836. snmp_mib_free((void __percpu **)net->mib.udp_stats_in6);
  837. return -ENOMEM;
  838. }
  839. static void ipv6_cleanup_mibs(struct net *net)
  840. {
  841. snmp_mib_free((void __percpu **)net->mib.udp_stats_in6);
  842. snmp_mib_free((void __percpu **)net->mib.udplite_stats_in6);
  843. snmp_mib_free((void __percpu **)net->mib.ipv6_statistics);
  844. snmp_mib_free((void __percpu **)net->mib.icmpv6_statistics);
  845. snmp_mib_free((void __percpu **)net->mib.icmpv6msg_statistics);
  846. }
  847. static int __net_init inet6_net_init(struct net *net)
  848. {
  849. int err = 0;
  850. net->ipv6.sysctl.bindv6only = 0;
  851. net->ipv6.sysctl.icmpv6_time = 1*HZ;
  852. err = ipv6_init_mibs(net);
  853. if (err)
  854. return err;
  855. #ifdef CONFIG_PROC_FS
  856. err = udp6_proc_init(net);
  857. if (err)
  858. goto out;
  859. err = tcp6_proc_init(net);
  860. if (err)
  861. goto proc_tcp6_fail;
  862. err = ac6_proc_init(net);
  863. if (err)
  864. goto proc_ac6_fail;
  865. #endif
  866. return err;
  867. #ifdef CONFIG_PROC_FS
  868. proc_ac6_fail:
  869. tcp6_proc_exit(net);
  870. proc_tcp6_fail:
  871. udp6_proc_exit(net);
  872. out:
  873. ipv6_cleanup_mibs(net);
  874. return err;
  875. #endif
  876. }
  877. static void __net_exit inet6_net_exit(struct net *net)
  878. {
  879. #ifdef CONFIG_PROC_FS
  880. udp6_proc_exit(net);
  881. tcp6_proc_exit(net);
  882. ac6_proc_exit(net);
  883. #endif
  884. ipv6_cleanup_mibs(net);
  885. }
  886. static struct pernet_operations inet6_net_ops = {
  887. .init = inet6_net_init,
  888. .exit = inet6_net_exit,
  889. };
  890. static int __init inet6_init(void)
  891. {
  892. struct sk_buff *dummy_skb;
  893. struct list_head *r;
  894. int err = 0;
  895. BUILD_BUG_ON(sizeof(struct inet6_skb_parm) > sizeof(dummy_skb->cb));
  896. /* Register the socket-side information for inet6_create. */
  897. for(r = &inetsw6[0]; r < &inetsw6[SOCK_MAX]; ++r)
  898. INIT_LIST_HEAD(r);
  899. if (disable_ipv6_mod) {
  900. printk(KERN_INFO
  901. "IPv6: Loaded, but administratively disabled, "
  902. "reboot required to enable\n");
  903. goto out;
  904. }
  905. err = proto_register(&tcpv6_prot, 1);
  906. if (err)
  907. goto out;
  908. err = proto_register(&udpv6_prot, 1);
  909. if (err)
  910. goto out_unregister_tcp_proto;
  911. err = proto_register(&udplitev6_prot, 1);
  912. if (err)
  913. goto out_unregister_udp_proto;
  914. err = proto_register(&rawv6_prot, 1);
  915. if (err)
  916. goto out_unregister_udplite_proto;
  917. /* We MUST register RAW sockets before we create the ICMP6,
  918. * IGMP6, or NDISC control sockets.
  919. */
  920. err = rawv6_init();
  921. if (err)
  922. goto out_unregister_raw_proto;
  923. /* Register the family here so that the init calls below will
  924. * be able to create sockets. (?? is this dangerous ??)
  925. */
  926. err = sock_register(&inet6_family_ops);
  927. if (err)
  928. goto out_sock_register_fail;
  929. #ifdef CONFIG_SYSCTL
  930. err = ipv6_static_sysctl_register();
  931. if (err)
  932. goto static_sysctl_fail;
  933. #endif
  934. /*
  935. * ipngwg API draft makes clear that the correct semantics
  936. * for TCP and UDP is to consider one TCP and UDP instance
  937. * in a host availiable by both INET and INET6 APIs and
  938. * able to communicate via both network protocols.
  939. */
  940. err = register_pernet_subsys(&inet6_net_ops);
  941. if (err)
  942. goto register_pernet_fail;
  943. err = icmpv6_init();
  944. if (err)
  945. goto icmp_fail;
  946. err = ip6_mr_init();
  947. if (err)
  948. goto ipmr_fail;
  949. err = ndisc_init();
  950. if (err)
  951. goto ndisc_fail;
  952. err = igmp6_init();
  953. if (err)
  954. goto igmp_fail;
  955. err = ipv6_netfilter_init();
  956. if (err)
  957. goto netfilter_fail;
  958. /* Create /proc/foo6 entries. */
  959. #ifdef CONFIG_PROC_FS
  960. err = -ENOMEM;
  961. if (raw6_proc_init())
  962. goto proc_raw6_fail;
  963. if (udplite6_proc_init())
  964. goto proc_udplite6_fail;
  965. if (ipv6_misc_proc_init())
  966. goto proc_misc6_fail;
  967. if (if6_proc_init())
  968. goto proc_if6_fail;
  969. #endif
  970. err = ip6_route_init();
  971. if (err)
  972. goto ip6_route_fail;
  973. err = ip6_flowlabel_init();
  974. if (err)
  975. goto ip6_flowlabel_fail;
  976. err = addrconf_init();
  977. if (err)
  978. goto addrconf_fail;
  979. /* Init v6 extension headers. */
  980. err = ipv6_exthdrs_init();
  981. if (err)
  982. goto ipv6_exthdrs_fail;
  983. err = ipv6_frag_init();
  984. if (err)
  985. goto ipv6_frag_fail;
  986. /* Init v6 transport protocols. */
  987. err = udpv6_init();
  988. if (err)
  989. goto udpv6_fail;
  990. err = udplitev6_init();
  991. if (err)
  992. goto udplitev6_fail;
  993. err = tcpv6_init();
  994. if (err)
  995. goto tcpv6_fail;
  996. err = ipv6_packet_init();
  997. if (err)
  998. goto ipv6_packet_fail;
  999. #ifdef CONFIG_SYSCTL
  1000. err = ipv6_sysctl_register();
  1001. if (err)
  1002. goto sysctl_fail;
  1003. #endif
  1004. out:
  1005. return err;
  1006. #ifdef CONFIG_SYSCTL
  1007. sysctl_fail:
  1008. ipv6_packet_cleanup();
  1009. #endif
  1010. ipv6_packet_fail:
  1011. tcpv6_exit();
  1012. tcpv6_fail:
  1013. udplitev6_exit();
  1014. udplitev6_fail:
  1015. udpv6_exit();
  1016. udpv6_fail:
  1017. ipv6_frag_exit();
  1018. ipv6_frag_fail:
  1019. ipv6_exthdrs_exit();
  1020. ipv6_exthdrs_fail:
  1021. addrconf_cleanup();
  1022. addrconf_fail:
  1023. ip6_flowlabel_cleanup();
  1024. ip6_flowlabel_fail:
  1025. ip6_route_cleanup();
  1026. ip6_route_fail:
  1027. #ifdef CONFIG_PROC_FS
  1028. if6_proc_exit();
  1029. proc_if6_fail:
  1030. ipv6_misc_proc_exit();
  1031. proc_misc6_fail:
  1032. udplite6_proc_exit();
  1033. proc_udplite6_fail:
  1034. raw6_proc_exit();
  1035. proc_raw6_fail:
  1036. #endif
  1037. ipv6_netfilter_fini();
  1038. netfilter_fail:
  1039. igmp6_cleanup();
  1040. igmp_fail:
  1041. ndisc_cleanup();
  1042. ndisc_fail:
  1043. ip6_mr_cleanup();
  1044. ipmr_fail:
  1045. icmpv6_cleanup();
  1046. icmp_fail:
  1047. unregister_pernet_subsys(&inet6_net_ops);
  1048. register_pernet_fail:
  1049. #ifdef CONFIG_SYSCTL
  1050. ipv6_static_sysctl_unregister();
  1051. static_sysctl_fail:
  1052. #endif
  1053. sock_unregister(PF_INET6);
  1054. rtnl_unregister_all(PF_INET6);
  1055. out_sock_register_fail:
  1056. rawv6_exit();
  1057. out_unregister_raw_proto:
  1058. proto_unregister(&rawv6_prot);
  1059. out_unregister_udplite_proto:
  1060. proto_unregister(&udplitev6_prot);
  1061. out_unregister_udp_proto:
  1062. proto_unregister(&udpv6_prot);
  1063. out_unregister_tcp_proto:
  1064. proto_unregister(&tcpv6_prot);
  1065. goto out;
  1066. }
  1067. module_init(inet6_init);
  1068. static void __exit inet6_exit(void)
  1069. {
  1070. if (disable_ipv6_mod)
  1071. return;
  1072. /* First of all disallow new sockets creation. */
  1073. sock_unregister(PF_INET6);
  1074. /* Disallow any further netlink messages */
  1075. rtnl_unregister_all(PF_INET6);
  1076. #ifdef CONFIG_SYSCTL
  1077. ipv6_sysctl_unregister();
  1078. #endif
  1079. udpv6_exit();
  1080. udplitev6_exit();
  1081. tcpv6_exit();
  1082. /* Cleanup code parts. */
  1083. ipv6_packet_cleanup();
  1084. ipv6_frag_exit();
  1085. ipv6_exthdrs_exit();
  1086. addrconf_cleanup();
  1087. ip6_flowlabel_cleanup();
  1088. ip6_route_cleanup();
  1089. #ifdef CONFIG_PROC_FS
  1090. /* Cleanup code parts. */
  1091. if6_proc_exit();
  1092. ipv6_misc_proc_exit();
  1093. udplite6_proc_exit();
  1094. raw6_proc_exit();
  1095. #endif
  1096. ipv6_netfilter_fini();
  1097. igmp6_cleanup();
  1098. ndisc_cleanup();
  1099. ip6_mr_cleanup();
  1100. icmpv6_cleanup();
  1101. rawv6_exit();
  1102. unregister_pernet_subsys(&inet6_net_ops);
  1103. #ifdef CONFIG_SYSCTL
  1104. ipv6_static_sysctl_unregister();
  1105. #endif
  1106. proto_unregister(&rawv6_prot);
  1107. proto_unregister(&udplitev6_prot);
  1108. proto_unregister(&udpv6_prot);
  1109. proto_unregister(&tcpv6_prot);
  1110. rcu_barrier(); /* Wait for completion of call_rcu()'s */
  1111. }
  1112. module_exit(inet6_exit);
  1113. MODULE_ALIAS_NETPROTO(PF_INET6);