af_inet6.c 32 KB

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