af_inet6.c 31 KB

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