af_inet6.c 32 KB

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