ipv6.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* SCTP kernel implementation
  3. * (C) Copyright IBM Corp. 2002, 2004
  4. * Copyright (c) 2001 Nokia, Inc.
  5. * Copyright (c) 2001 La Monte H.P. Yarroll
  6. * Copyright (c) 2002-2003 Intel Corp.
  7. *
  8. * This file is part of the SCTP kernel implementation
  9. *
  10. * SCTP over IPv6.
  11. *
  12. * Please send any bug reports or fixes you make to the
  13. * email address(es):
  14. * lksctp developers <linux-sctp@vger.kernel.org>
  15. *
  16. * Written or modified by:
  17. * Le Yanqun <yanqun.le@nokia.com>
  18. * Hui Huang <hui.huang@nokia.com>
  19. * La Monte H.P. Yarroll <piggy@acm.org>
  20. * Sridhar Samudrala <sri@us.ibm.com>
  21. * Jon Grimm <jgrimm@us.ibm.com>
  22. * Ardelle Fan <ardelle.fan@intel.com>
  23. *
  24. * Based on:
  25. * linux/net/ipv6/tcp_ipv6.c
  26. */
  27. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  28. #include <linux/module.h>
  29. #include <linux/errno.h>
  30. #include <linux/types.h>
  31. #include <linux/socket.h>
  32. #include <linux/sockios.h>
  33. #include <linux/net.h>
  34. #include <linux/in.h>
  35. #include <linux/in6.h>
  36. #include <linux/netdevice.h>
  37. #include <linux/init.h>
  38. #include <linux/ipsec.h>
  39. #include <linux/slab.h>
  40. #include <linux/ipv6.h>
  41. #include <linux/icmpv6.h>
  42. #include <linux/random.h>
  43. #include <linux/seq_file.h>
  44. #include <net/protocol.h>
  45. #include <net/ndisc.h>
  46. #include <net/ip.h>
  47. #include <net/ipv6.h>
  48. #include <net/transp_v6.h>
  49. #include <net/addrconf.h>
  50. #include <net/ip6_route.h>
  51. #include <net/inet_common.h>
  52. #include <net/inet_ecn.h>
  53. #include <net/sctp/sctp.h>
  54. #include <net/udp_tunnel.h>
  55. #include <linux/uaccess.h>
  56. static inline int sctp_v6_addr_match_len(union sctp_addr *s1,
  57. union sctp_addr *s2);
  58. static void sctp_v6_to_addr(union sctp_addr *addr, struct in6_addr *saddr,
  59. __be16 port);
  60. static int sctp_v6_cmp_addr(const union sctp_addr *addr1,
  61. const union sctp_addr *addr2);
  62. /* Event handler for inet6 address addition/deletion events.
  63. * The sctp_local_addr_list needs to be protocted by a spin lock since
  64. * multiple notifiers (say IPv4 and IPv6) may be running at the same
  65. * time and thus corrupt the list.
  66. * The reader side is protected with RCU.
  67. */
  68. static int sctp_inet6addr_event(struct notifier_block *this, unsigned long ev,
  69. void *ptr)
  70. {
  71. struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
  72. struct sctp_sockaddr_entry *addr = NULL;
  73. struct sctp_sockaddr_entry *temp;
  74. struct net *net = dev_net(ifa->idev->dev);
  75. int found = 0;
  76. switch (ev) {
  77. case NETDEV_UP:
  78. addr = kzalloc_obj(*addr, GFP_ATOMIC);
  79. if (addr) {
  80. addr->a.v6.sin6_family = AF_INET6;
  81. addr->a.v6.sin6_addr = ifa->addr;
  82. addr->a.v6.sin6_scope_id = ifa->idev->dev->ifindex;
  83. addr->valid = 1;
  84. spin_lock_bh(&net->sctp.local_addr_lock);
  85. list_add_tail_rcu(&addr->list, &net->sctp.local_addr_list);
  86. sctp_addr_wq_mgmt(net, addr, SCTP_ADDR_NEW);
  87. spin_unlock_bh(&net->sctp.local_addr_lock);
  88. }
  89. break;
  90. case NETDEV_DOWN:
  91. spin_lock_bh(&net->sctp.local_addr_lock);
  92. list_for_each_entry_safe(addr, temp,
  93. &net->sctp.local_addr_list, list) {
  94. if (addr->a.sa.sa_family == AF_INET6 &&
  95. ipv6_addr_equal(&addr->a.v6.sin6_addr,
  96. &ifa->addr) &&
  97. addr->a.v6.sin6_scope_id == ifa->idev->dev->ifindex) {
  98. found = 1;
  99. addr->valid = 0;
  100. list_del_rcu(&addr->list);
  101. sctp_addr_wq_mgmt(net, addr, SCTP_ADDR_DEL);
  102. break;
  103. }
  104. }
  105. spin_unlock_bh(&net->sctp.local_addr_lock);
  106. if (found)
  107. kfree_rcu(addr, rcu);
  108. break;
  109. }
  110. return NOTIFY_DONE;
  111. }
  112. static struct notifier_block sctp_inet6addr_notifier = {
  113. .notifier_call = sctp_inet6addr_event,
  114. };
  115. static void sctp_v6_err_handle(struct sctp_transport *t, struct sk_buff *skb,
  116. __u8 type, __u8 code, __u32 info)
  117. {
  118. struct sctp_association *asoc = t->asoc;
  119. struct sock *sk = asoc->base.sk;
  120. int err = 0;
  121. switch (type) {
  122. case ICMPV6_PKT_TOOBIG:
  123. if (ip6_sk_accept_pmtu(sk))
  124. sctp_icmp_frag_needed(sk, asoc, t, info);
  125. return;
  126. case ICMPV6_PARAMPROB:
  127. if (ICMPV6_UNK_NEXTHDR == code) {
  128. sctp_icmp_proto_unreachable(sk, asoc, t);
  129. return;
  130. }
  131. break;
  132. case NDISC_REDIRECT:
  133. sctp_icmp_redirect(sk, t, skb);
  134. return;
  135. default:
  136. break;
  137. }
  138. icmpv6_err_convert(type, code, &err);
  139. if (!sock_owned_by_user(sk) && inet6_test_bit(RECVERR6, sk)) {
  140. sk->sk_err = err;
  141. sk_error_report(sk);
  142. } else {
  143. WRITE_ONCE(sk->sk_err_soft, err);
  144. }
  145. }
  146. /* ICMP error handler. */
  147. static int sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
  148. u8 type, u8 code, int offset, __be32 info)
  149. {
  150. struct net *net = dev_net(skb->dev);
  151. struct sctp_transport *transport;
  152. struct sctp_association *asoc;
  153. __u16 saveip, savesctp;
  154. struct sock *sk;
  155. /* Fix up skb to look at the embedded net header. */
  156. saveip = skb->network_header;
  157. savesctp = skb->transport_header;
  158. skb_reset_network_header(skb);
  159. skb_set_transport_header(skb, offset);
  160. sk = sctp_err_lookup(net, AF_INET6, skb, sctp_hdr(skb), &asoc, &transport);
  161. /* Put back, the original pointers. */
  162. skb->network_header = saveip;
  163. skb->transport_header = savesctp;
  164. if (!sk) {
  165. __ICMP6_INC_STATS(net, __in6_dev_get(skb->dev), ICMP6_MIB_INERRORS);
  166. return -ENOENT;
  167. }
  168. sctp_v6_err_handle(transport, skb, type, code, ntohl(info));
  169. sctp_err_finish(sk, transport);
  170. return 0;
  171. }
  172. int sctp_udp_v6_err(struct sock *sk, struct sk_buff *skb)
  173. {
  174. struct net *net = dev_net(skb->dev);
  175. struct sctp_association *asoc;
  176. struct sctp_transport *t;
  177. struct icmp6hdr *hdr;
  178. __u32 info = 0;
  179. skb->transport_header += sizeof(struct udphdr);
  180. sk = sctp_err_lookup(net, AF_INET6, skb, sctp_hdr(skb), &asoc, &t);
  181. if (!sk) {
  182. __ICMP6_INC_STATS(net, __in6_dev_get(skb->dev), ICMP6_MIB_INERRORS);
  183. return -ENOENT;
  184. }
  185. skb->transport_header -= sizeof(struct udphdr);
  186. hdr = (struct icmp6hdr *)(skb_network_header(skb) - sizeof(struct icmp6hdr));
  187. if (hdr->icmp6_type == NDISC_REDIRECT) {
  188. /* can't be handled without outer ip6hdr known, leave it to udpv6_err */
  189. sctp_err_finish(sk, t);
  190. return 0;
  191. }
  192. if (hdr->icmp6_type == ICMPV6_PKT_TOOBIG)
  193. info = ntohl(hdr->icmp6_mtu);
  194. sctp_v6_err_handle(t, skb, hdr->icmp6_type, hdr->icmp6_code, info);
  195. sctp_err_finish(sk, t);
  196. return 1;
  197. }
  198. static int sctp_v6_xmit(struct sk_buff *skb, struct sctp_transport *t)
  199. {
  200. struct dst_entry *dst = dst_clone(t->dst);
  201. struct flowi6 *fl6 = &t->fl.u.ip6;
  202. struct sock *sk = skb->sk;
  203. struct ipv6_pinfo *np = inet6_sk(sk);
  204. __u8 tclass = np->tclass;
  205. __be32 label;
  206. pr_debug("%s: skb:%p, len:%d, src:%pI6 dst:%pI6\n", __func__, skb,
  207. skb->len, &fl6->saddr, &fl6->daddr);
  208. if (t->dscp & SCTP_DSCP_SET_MASK)
  209. tclass = t->dscp & SCTP_DSCP_VAL_MASK;
  210. if (INET_ECN_is_capable(tclass))
  211. IP6_ECN_flow_xmit(sk, fl6->flowlabel);
  212. if (!(t->param_flags & SPP_PMTUD_ENABLE))
  213. skb->ignore_df = 1;
  214. SCTP_INC_STATS(sock_net(sk), SCTP_MIB_OUTSCTPPACKS);
  215. if (!t->encap_port || !sctp_sk(sk)->udp_port) {
  216. int res;
  217. skb_dst_set(skb, dst);
  218. rcu_read_lock();
  219. res = ip6_xmit(sk, skb, fl6, sk->sk_mark,
  220. rcu_dereference(np->opt),
  221. tclass, READ_ONCE(sk->sk_priority));
  222. rcu_read_unlock();
  223. return res;
  224. }
  225. if (skb_is_gso(skb))
  226. skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL_CSUM;
  227. skb->encapsulation = 1;
  228. skb_reset_inner_mac_header(skb);
  229. skb_reset_inner_transport_header(skb);
  230. skb_set_inner_ipproto(skb, IPPROTO_SCTP);
  231. label = ip6_make_flowlabel(sock_net(sk), skb, fl6->flowlabel, true, fl6);
  232. udp_tunnel6_xmit_skb(dst, sk, skb, NULL, &fl6->saddr, &fl6->daddr,
  233. tclass, ip6_dst_hoplimit(dst), label,
  234. sctp_sk(sk)->udp_port, t->encap_port, false, 0);
  235. return 0;
  236. }
  237. /* Returns the dst cache entry for the given source and destination ip
  238. * addresses.
  239. */
  240. static void sctp_v6_get_dst(struct sctp_transport *t, union sctp_addr *saddr,
  241. struct flowi *fl, struct sock *sk)
  242. {
  243. struct sctp_association *asoc = t->asoc;
  244. struct dst_entry *dst = NULL;
  245. struct flowi _fl;
  246. struct flowi6 *fl6 = &_fl.u.ip6;
  247. struct sctp_bind_addr *bp;
  248. struct ipv6_pinfo *np = inet6_sk(sk);
  249. struct sctp_sockaddr_entry *laddr;
  250. union sctp_addr *daddr = &t->ipaddr;
  251. union sctp_addr dst_saddr;
  252. struct in6_addr *final_p, final;
  253. enum sctp_scope scope;
  254. __u8 matchlen = 0;
  255. memset(&_fl, 0, sizeof(_fl));
  256. fl6->daddr = daddr->v6.sin6_addr;
  257. fl6->fl6_dport = daddr->v6.sin6_port;
  258. fl6->flowi6_proto = IPPROTO_SCTP;
  259. if (ipv6_addr_type(&daddr->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL)
  260. fl6->flowi6_oif = daddr->v6.sin6_scope_id;
  261. else if (asoc)
  262. fl6->flowi6_oif = asoc->base.sk->sk_bound_dev_if;
  263. if (t->flowlabel & SCTP_FLOWLABEL_SET_MASK)
  264. fl6->flowlabel = htonl(t->flowlabel & SCTP_FLOWLABEL_VAL_MASK);
  265. if (inet6_test_bit(SNDFLOW, sk) &&
  266. (fl6->flowlabel & IPV6_FLOWLABEL_MASK)) {
  267. struct ip6_flowlabel *flowlabel;
  268. flowlabel = fl6_sock_lookup(sk, fl6->flowlabel);
  269. if (IS_ERR(flowlabel))
  270. goto out;
  271. fl6_sock_release(flowlabel);
  272. }
  273. pr_debug("%s: dst=%pI6 ", __func__, &fl6->daddr);
  274. if (asoc)
  275. fl6->fl6_sport = htons(asoc->base.bind_addr.port);
  276. if (saddr) {
  277. fl6->saddr = saddr->v6.sin6_addr;
  278. if (!fl6->fl6_sport)
  279. fl6->fl6_sport = saddr->v6.sin6_port;
  280. pr_debug("src=%pI6 - ", &fl6->saddr);
  281. }
  282. rcu_read_lock();
  283. final_p = fl6_update_dst(fl6, rcu_dereference(np->opt), &final);
  284. rcu_read_unlock();
  285. dst = ip6_dst_lookup_flow(sock_net(sk), sk, fl6, final_p);
  286. if (!asoc || saddr) {
  287. t->dst = dst;
  288. memcpy(fl, &_fl, sizeof(_fl));
  289. goto out;
  290. }
  291. bp = &asoc->base.bind_addr;
  292. scope = sctp_scope(daddr);
  293. /* ip6_dst_lookup has filled in the fl6->saddr for us. Check
  294. * to see if we can use it.
  295. */
  296. if (!IS_ERR(dst)) {
  297. /* Walk through the bind address list and look for a bind
  298. * address that matches the source address of the returned dst.
  299. */
  300. sctp_v6_to_addr(&dst_saddr, &fl6->saddr, htons(bp->port));
  301. rcu_read_lock();
  302. list_for_each_entry_rcu(laddr, &bp->address_list, list) {
  303. if (!laddr->valid || laddr->state == SCTP_ADDR_DEL ||
  304. (laddr->state != SCTP_ADDR_SRC &&
  305. !asoc->src_out_of_asoc_ok))
  306. continue;
  307. /* Do not compare against v4 addrs */
  308. if ((laddr->a.sa.sa_family == AF_INET6) &&
  309. (sctp_v6_cmp_addr(&dst_saddr, &laddr->a))) {
  310. rcu_read_unlock();
  311. t->dst = dst;
  312. memcpy(fl, &_fl, sizeof(_fl));
  313. goto out;
  314. }
  315. }
  316. rcu_read_unlock();
  317. /* None of the bound addresses match the source address of the
  318. * dst. So release it.
  319. */
  320. dst_release(dst);
  321. dst = NULL;
  322. }
  323. /* Walk through the bind address list and try to get the
  324. * best source address for a given destination.
  325. */
  326. rcu_read_lock();
  327. list_for_each_entry_rcu(laddr, &bp->address_list, list) {
  328. struct dst_entry *bdst;
  329. __u8 bmatchlen;
  330. if (!laddr->valid ||
  331. laddr->state != SCTP_ADDR_SRC ||
  332. laddr->a.sa.sa_family != AF_INET6 ||
  333. scope > sctp_scope(&laddr->a))
  334. continue;
  335. fl6->saddr = laddr->a.v6.sin6_addr;
  336. fl6->fl6_sport = laddr->a.v6.sin6_port;
  337. final_p = fl6_update_dst(fl6, rcu_dereference(np->opt), &final);
  338. bdst = ip6_dst_lookup_flow(sock_net(sk), sk, fl6, final_p);
  339. if (IS_ERR(bdst))
  340. continue;
  341. if (ipv6_chk_addr(dev_net(bdst->dev),
  342. &laddr->a.v6.sin6_addr, bdst->dev, 1)) {
  343. if (!IS_ERR_OR_NULL(dst))
  344. dst_release(dst);
  345. dst = bdst;
  346. t->dst = dst;
  347. memcpy(fl, &_fl, sizeof(_fl));
  348. break;
  349. }
  350. bmatchlen = sctp_v6_addr_match_len(daddr, &laddr->a);
  351. if (matchlen > bmatchlen) {
  352. dst_release(bdst);
  353. continue;
  354. }
  355. if (!IS_ERR_OR_NULL(dst))
  356. dst_release(dst);
  357. dst = bdst;
  358. matchlen = bmatchlen;
  359. t->dst = dst;
  360. memcpy(fl, &_fl, sizeof(_fl));
  361. }
  362. rcu_read_unlock();
  363. out:
  364. if (!IS_ERR_OR_NULL(dst)) {
  365. struct rt6_info *rt;
  366. rt = dst_rt6_info(dst);
  367. t->dst_cookie = rt6_get_cookie(rt);
  368. pr_debug("rt6_dst:%pI6/%d rt6_src:%pI6\n",
  369. &rt->rt6i_dst.addr, rt->rt6i_dst.plen,
  370. &fl->u.ip6.saddr);
  371. } else {
  372. t->dst = NULL;
  373. pr_debug("no route\n");
  374. }
  375. }
  376. /* Returns the number of consecutive initial bits that match in the 2 ipv6
  377. * addresses.
  378. */
  379. static inline int sctp_v6_addr_match_len(union sctp_addr *s1,
  380. union sctp_addr *s2)
  381. {
  382. return ipv6_addr_diff(&s1->v6.sin6_addr, &s2->v6.sin6_addr);
  383. }
  384. /* Fills in the source address(saddr) based on the destination address(daddr)
  385. * and asoc's bind address list.
  386. */
  387. static void sctp_v6_get_saddr(struct sctp_sock *sk,
  388. struct sctp_transport *t,
  389. struct flowi *fl)
  390. {
  391. struct flowi6 *fl6 = &fl->u.ip6;
  392. union sctp_addr *saddr = &t->saddr;
  393. pr_debug("%s: asoc:%p dst:%p\n", __func__, t->asoc, t->dst);
  394. if (t->dst) {
  395. saddr->v6.sin6_family = AF_INET6;
  396. saddr->v6.sin6_addr = fl6->saddr;
  397. }
  398. }
  399. /* Make a copy of all potential local addresses. */
  400. static void sctp_v6_copy_addrlist(struct list_head *addrlist,
  401. struct net_device *dev)
  402. {
  403. struct inet6_dev *in6_dev;
  404. struct inet6_ifaddr *ifp;
  405. struct sctp_sockaddr_entry *addr;
  406. rcu_read_lock();
  407. if ((in6_dev = __in6_dev_get(dev)) == NULL) {
  408. rcu_read_unlock();
  409. return;
  410. }
  411. read_lock_bh(&in6_dev->lock);
  412. list_for_each_entry(ifp, &in6_dev->addr_list, if_list) {
  413. /* Add the address to the local list. */
  414. addr = kzalloc_obj(*addr, GFP_ATOMIC);
  415. if (addr) {
  416. addr->a.v6.sin6_family = AF_INET6;
  417. addr->a.v6.sin6_addr = ifp->addr;
  418. addr->a.v6.sin6_scope_id = dev->ifindex;
  419. addr->valid = 1;
  420. INIT_LIST_HEAD(&addr->list);
  421. list_add_tail(&addr->list, addrlist);
  422. }
  423. }
  424. read_unlock_bh(&in6_dev->lock);
  425. rcu_read_unlock();
  426. }
  427. /* Copy over any ip options */
  428. static void sctp_v6_copy_ip_options(struct sock *sk, struct sock *newsk)
  429. {
  430. struct ipv6_pinfo *newnp, *np = inet6_sk(sk);
  431. struct ipv6_txoptions *opt;
  432. inet_sk(newsk)->inet_opt = NULL;
  433. newnp = inet6_sk(newsk);
  434. rcu_read_lock();
  435. opt = rcu_dereference(np->opt);
  436. if (opt) {
  437. opt = ipv6_dup_options(newsk, opt);
  438. if (!opt)
  439. pr_err("%s: Failed to copy ip options\n", __func__);
  440. }
  441. RCU_INIT_POINTER(newnp->opt, opt);
  442. rcu_read_unlock();
  443. }
  444. /* Account for the IP options */
  445. static int sctp_v6_ip_options_len(struct sock *sk)
  446. {
  447. struct ipv6_pinfo *np = inet6_sk(sk);
  448. struct ipv6_txoptions *opt;
  449. int len = 0;
  450. rcu_read_lock();
  451. opt = rcu_dereference(np->opt);
  452. if (opt)
  453. len = opt->opt_flen + opt->opt_nflen;
  454. rcu_read_unlock();
  455. return len;
  456. }
  457. /* Initialize a sockaddr_storage from in incoming skb. */
  458. static void sctp_v6_from_skb(union sctp_addr *addr, struct sk_buff *skb,
  459. int is_saddr)
  460. {
  461. /* Always called on head skb, so this is safe */
  462. struct sctphdr *sh = sctp_hdr(skb);
  463. struct sockaddr_in6 *sa = &addr->v6;
  464. addr->v6.sin6_family = AF_INET6;
  465. addr->v6.sin6_flowinfo = 0; /* FIXME */
  466. addr->v6.sin6_scope_id = ((struct inet6_skb_parm *)skb->cb)->iif;
  467. if (is_saddr) {
  468. sa->sin6_port = sh->source;
  469. sa->sin6_addr = ipv6_hdr(skb)->saddr;
  470. } else {
  471. sa->sin6_port = sh->dest;
  472. sa->sin6_addr = ipv6_hdr(skb)->daddr;
  473. }
  474. }
  475. /* Initialize an sctp_addr from a socket. */
  476. static void sctp_v6_from_sk(union sctp_addr *addr, struct sock *sk)
  477. {
  478. addr->v6.sin6_family = AF_INET6;
  479. addr->v6.sin6_port = 0;
  480. addr->v6.sin6_flowinfo = 0;
  481. addr->v6.sin6_addr = sk->sk_v6_rcv_saddr;
  482. addr->v6.sin6_scope_id = 0;
  483. }
  484. /* Initialize sk->sk_rcv_saddr from sctp_addr. */
  485. static void sctp_v6_to_sk_saddr(union sctp_addr *addr, struct sock *sk)
  486. {
  487. if (addr->sa.sa_family == AF_INET) {
  488. sk->sk_v6_rcv_saddr.s6_addr32[0] = 0;
  489. sk->sk_v6_rcv_saddr.s6_addr32[1] = 0;
  490. sk->sk_v6_rcv_saddr.s6_addr32[2] = htonl(0x0000ffff);
  491. sk->sk_v6_rcv_saddr.s6_addr32[3] =
  492. addr->v4.sin_addr.s_addr;
  493. } else {
  494. sk->sk_v6_rcv_saddr = addr->v6.sin6_addr;
  495. }
  496. }
  497. /* Initialize sk->sk_daddr from sctp_addr. */
  498. static void sctp_v6_to_sk_daddr(union sctp_addr *addr, struct sock *sk)
  499. {
  500. if (addr->sa.sa_family == AF_INET) {
  501. sk->sk_v6_daddr.s6_addr32[0] = 0;
  502. sk->sk_v6_daddr.s6_addr32[1] = 0;
  503. sk->sk_v6_daddr.s6_addr32[2] = htonl(0x0000ffff);
  504. sk->sk_v6_daddr.s6_addr32[3] = addr->v4.sin_addr.s_addr;
  505. } else {
  506. sk->sk_v6_daddr = addr->v6.sin6_addr;
  507. }
  508. }
  509. /* Initialize a sctp_addr from an address parameter. */
  510. static bool sctp_v6_from_addr_param(union sctp_addr *addr,
  511. union sctp_addr_param *param,
  512. __be16 port, int iif)
  513. {
  514. if (ntohs(param->v6.param_hdr.length) < sizeof(struct sctp_ipv6addr_param))
  515. return false;
  516. addr->v6.sin6_family = AF_INET6;
  517. addr->v6.sin6_port = port;
  518. addr->v6.sin6_flowinfo = 0; /* BUG */
  519. addr->v6.sin6_addr = param->v6.addr;
  520. addr->v6.sin6_scope_id = iif;
  521. return true;
  522. }
  523. /* Initialize an address parameter from a sctp_addr and return the length
  524. * of the address parameter.
  525. */
  526. static int sctp_v6_to_addr_param(const union sctp_addr *addr,
  527. union sctp_addr_param *param)
  528. {
  529. int length = sizeof(struct sctp_ipv6addr_param);
  530. param->v6.param_hdr.type = SCTP_PARAM_IPV6_ADDRESS;
  531. param->v6.param_hdr.length = htons(length);
  532. param->v6.addr = addr->v6.sin6_addr;
  533. return length;
  534. }
  535. /* Initialize a sctp_addr from struct in6_addr. */
  536. static void sctp_v6_to_addr(union sctp_addr *addr, struct in6_addr *saddr,
  537. __be16 port)
  538. {
  539. addr->sa.sa_family = AF_INET6;
  540. addr->v6.sin6_port = port;
  541. addr->v6.sin6_flowinfo = 0;
  542. addr->v6.sin6_addr = *saddr;
  543. addr->v6.sin6_scope_id = 0;
  544. }
  545. static int __sctp_v6_cmp_addr(const union sctp_addr *addr1,
  546. const union sctp_addr *addr2)
  547. {
  548. if (addr1->sa.sa_family != addr2->sa.sa_family) {
  549. if (addr1->sa.sa_family == AF_INET &&
  550. addr2->sa.sa_family == AF_INET6 &&
  551. ipv6_addr_v4mapped(&addr2->v6.sin6_addr) &&
  552. addr2->v6.sin6_addr.s6_addr32[3] ==
  553. addr1->v4.sin_addr.s_addr)
  554. return 1;
  555. if (addr2->sa.sa_family == AF_INET &&
  556. addr1->sa.sa_family == AF_INET6 &&
  557. ipv6_addr_v4mapped(&addr1->v6.sin6_addr) &&
  558. addr1->v6.sin6_addr.s6_addr32[3] ==
  559. addr2->v4.sin_addr.s_addr)
  560. return 1;
  561. return 0;
  562. }
  563. if (!ipv6_addr_equal(&addr1->v6.sin6_addr, &addr2->v6.sin6_addr))
  564. return 0;
  565. /* If this is a linklocal address, compare the scope_id. */
  566. if ((ipv6_addr_type(&addr1->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL) &&
  567. addr1->v6.sin6_scope_id && addr2->v6.sin6_scope_id &&
  568. addr1->v6.sin6_scope_id != addr2->v6.sin6_scope_id)
  569. return 0;
  570. return 1;
  571. }
  572. /* Compare addresses exactly.
  573. * v4-mapped-v6 is also in consideration.
  574. */
  575. static int sctp_v6_cmp_addr(const union sctp_addr *addr1,
  576. const union sctp_addr *addr2)
  577. {
  578. return __sctp_v6_cmp_addr(addr1, addr2) &&
  579. addr1->v6.sin6_port == addr2->v6.sin6_port;
  580. }
  581. /* Initialize addr struct to INADDR_ANY. */
  582. static void sctp_v6_inaddr_any(union sctp_addr *addr, __be16 port)
  583. {
  584. memset(addr, 0x00, sizeof(union sctp_addr));
  585. addr->v6.sin6_family = AF_INET6;
  586. addr->v6.sin6_port = port;
  587. }
  588. /* Is this a wildcard address? */
  589. static int sctp_v6_is_any(const union sctp_addr *addr)
  590. {
  591. return ipv6_addr_any(&addr->v6.sin6_addr);
  592. }
  593. /* Should this be available for binding? */
  594. static int sctp_v6_available(union sctp_addr *addr, struct sctp_sock *sp)
  595. {
  596. const struct in6_addr *in6 = (const struct in6_addr *)&addr->v6.sin6_addr;
  597. struct sock *sk = &sp->inet.sk;
  598. struct net *net = sock_net(sk);
  599. struct net_device *dev = NULL;
  600. int type, res, bound_dev_if;
  601. type = ipv6_addr_type(in6);
  602. if (IPV6_ADDR_ANY == type)
  603. return 1;
  604. if (type == IPV6_ADDR_MAPPED) {
  605. if (sp && ipv6_only_sock(sctp_opt2sk(sp)))
  606. return 0;
  607. sctp_v6_map_v4(addr);
  608. return sctp_get_af_specific(AF_INET)->available(addr, sp);
  609. }
  610. if (!(type & IPV6_ADDR_UNICAST))
  611. return 0;
  612. rcu_read_lock();
  613. bound_dev_if = READ_ONCE(sk->sk_bound_dev_if);
  614. if (bound_dev_if) {
  615. res = 0;
  616. dev = dev_get_by_index_rcu(net, bound_dev_if);
  617. if (!dev)
  618. goto out;
  619. }
  620. res = ipv6_can_nonlocal_bind(net, &sp->inet) ||
  621. ipv6_chk_addr(net, in6, dev, 0);
  622. out:
  623. rcu_read_unlock();
  624. return res;
  625. }
  626. /* This function checks if the address is a valid address to be used for
  627. * SCTP.
  628. *
  629. * Output:
  630. * Return 0 - If the address is a non-unicast or an illegal address.
  631. * Return 1 - If the address is a unicast.
  632. */
  633. static int sctp_v6_addr_valid(union sctp_addr *addr,
  634. struct sctp_sock *sp,
  635. const struct sk_buff *skb)
  636. {
  637. int ret = ipv6_addr_type(&addr->v6.sin6_addr);
  638. /* Support v4-mapped-v6 address. */
  639. if (ret == IPV6_ADDR_MAPPED) {
  640. /* Note: This routine is used in input, so v4-mapped-v6
  641. * are disallowed here when there is no sctp_sock.
  642. */
  643. if (sp && ipv6_only_sock(sctp_opt2sk(sp)))
  644. return 0;
  645. sctp_v6_map_v4(addr);
  646. return sctp_get_af_specific(AF_INET)->addr_valid(addr, sp, skb);
  647. }
  648. /* Is this a non-unicast address */
  649. if (!(ret & IPV6_ADDR_UNICAST))
  650. return 0;
  651. return 1;
  652. }
  653. /* What is the scope of 'addr'? */
  654. static enum sctp_scope sctp_v6_scope(union sctp_addr *addr)
  655. {
  656. enum sctp_scope retval;
  657. int v6scope;
  658. /* The IPv6 scope is really a set of bit fields.
  659. * See IFA_* in <net/if_inet6.h>. Map to a generic SCTP scope.
  660. */
  661. v6scope = ipv6_addr_scope(&addr->v6.sin6_addr);
  662. switch (v6scope) {
  663. case IFA_HOST:
  664. retval = SCTP_SCOPE_LOOPBACK;
  665. break;
  666. case IFA_LINK:
  667. retval = SCTP_SCOPE_LINK;
  668. break;
  669. case IFA_SITE:
  670. retval = SCTP_SCOPE_PRIVATE;
  671. break;
  672. default:
  673. retval = SCTP_SCOPE_GLOBAL;
  674. break;
  675. }
  676. return retval;
  677. }
  678. /* Format a sockaddr for return to user space. This makes sure the return is
  679. * AF_INET or AF_INET6 depending on the SCTP_I_WANT_MAPPED_V4_ADDR option.
  680. */
  681. static int sctp_v6_addr_to_user(struct sctp_sock *sp, union sctp_addr *addr)
  682. {
  683. if (sp->v4mapped) {
  684. if (addr->sa.sa_family == AF_INET)
  685. sctp_v4_map_v6(addr);
  686. } else {
  687. if (addr->sa.sa_family == AF_INET6 &&
  688. ipv6_addr_v4mapped(&addr->v6.sin6_addr))
  689. sctp_v6_map_v4(addr);
  690. }
  691. if (addr->sa.sa_family == AF_INET) {
  692. memset(addr->v4.sin_zero, 0, sizeof(addr->v4.sin_zero));
  693. return sizeof(struct sockaddr_in);
  694. }
  695. return sizeof(struct sockaddr_in6);
  696. }
  697. /* Where did this skb come from? */
  698. static int sctp_v6_skb_iif(const struct sk_buff *skb)
  699. {
  700. return inet6_iif(skb);
  701. }
  702. static int sctp_v6_skb_sdif(const struct sk_buff *skb)
  703. {
  704. return inet6_sdif(skb);
  705. }
  706. /* Was this packet marked by Explicit Congestion Notification? */
  707. static int sctp_v6_is_ce(const struct sk_buff *skb)
  708. {
  709. return *((__u32 *)(ipv6_hdr(skb))) & (__force __u32)htonl(1 << 20);
  710. }
  711. /* Dump the v6 addr to the seq file. */
  712. static void sctp_v6_seq_dump_addr(struct seq_file *seq, union sctp_addr *addr)
  713. {
  714. seq_printf(seq, "%pI6 ", &addr->v6.sin6_addr);
  715. }
  716. static void sctp_v6_ecn_capable(struct sock *sk)
  717. {
  718. inet6_sk(sk)->tclass |= INET_ECN_ECT_0;
  719. }
  720. /* Initialize a PF_INET msgname from a ulpevent. */
  721. static void sctp_inet6_event_msgname(struct sctp_ulpevent *event,
  722. char *msgname, int *addrlen)
  723. {
  724. union sctp_addr *addr;
  725. struct sctp_association *asoc;
  726. union sctp_addr *paddr;
  727. if (!msgname)
  728. return;
  729. addr = (union sctp_addr *)msgname;
  730. asoc = event->asoc;
  731. paddr = &asoc->peer.primary_addr;
  732. if (paddr->sa.sa_family == AF_INET) {
  733. addr->v4.sin_family = AF_INET;
  734. addr->v4.sin_port = htons(asoc->peer.port);
  735. addr->v4.sin_addr = paddr->v4.sin_addr;
  736. } else {
  737. addr->v6.sin6_family = AF_INET6;
  738. addr->v6.sin6_flowinfo = 0;
  739. if (ipv6_addr_type(&paddr->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL)
  740. addr->v6.sin6_scope_id = paddr->v6.sin6_scope_id;
  741. else
  742. addr->v6.sin6_scope_id = 0;
  743. addr->v6.sin6_port = htons(asoc->peer.port);
  744. addr->v6.sin6_addr = paddr->v6.sin6_addr;
  745. }
  746. *addrlen = sctp_v6_addr_to_user(sctp_sk(asoc->base.sk), addr);
  747. }
  748. /* Initialize a msg_name from an inbound skb. */
  749. static void sctp_inet6_skb_msgname(struct sk_buff *skb, char *msgname,
  750. int *addr_len)
  751. {
  752. union sctp_addr *addr;
  753. struct sctphdr *sh;
  754. if (!msgname)
  755. return;
  756. addr = (union sctp_addr *)msgname;
  757. sh = sctp_hdr(skb);
  758. if (ip_hdr(skb)->version == 4) {
  759. addr->v4.sin_family = AF_INET;
  760. addr->v4.sin_port = sh->source;
  761. addr->v4.sin_addr.s_addr = ip_hdr(skb)->saddr;
  762. } else {
  763. addr->v6.sin6_family = AF_INET6;
  764. addr->v6.sin6_flowinfo = 0;
  765. addr->v6.sin6_port = sh->source;
  766. addr->v6.sin6_addr = ipv6_hdr(skb)->saddr;
  767. if (ipv6_addr_type(&addr->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL)
  768. addr->v6.sin6_scope_id = sctp_v6_skb_iif(skb);
  769. else
  770. addr->v6.sin6_scope_id = 0;
  771. }
  772. *addr_len = sctp_v6_addr_to_user(sctp_sk(skb->sk), addr);
  773. }
  774. /* Do we support this AF? */
  775. static int sctp_inet6_af_supported(sa_family_t family, struct sctp_sock *sp)
  776. {
  777. switch (family) {
  778. case AF_INET6:
  779. return 1;
  780. /* v4-mapped-v6 addresses */
  781. case AF_INET:
  782. if (!ipv6_only_sock(sctp_opt2sk(sp)))
  783. return 1;
  784. fallthrough;
  785. default:
  786. return 0;
  787. }
  788. }
  789. /* Address matching with wildcards allowed. This extra level
  790. * of indirection lets us choose whether a PF_INET6 should
  791. * disallow any v4 addresses if we so choose.
  792. */
  793. static int sctp_inet6_cmp_addr(const union sctp_addr *addr1,
  794. const union sctp_addr *addr2,
  795. struct sctp_sock *opt)
  796. {
  797. struct sock *sk = sctp_opt2sk(opt);
  798. struct sctp_af *af1, *af2;
  799. af1 = sctp_get_af_specific(addr1->sa.sa_family);
  800. af2 = sctp_get_af_specific(addr2->sa.sa_family);
  801. if (!af1 || !af2)
  802. return 0;
  803. /* If the socket is IPv6 only, v4 addrs will not match */
  804. if (ipv6_only_sock(sk) && af1 != af2)
  805. return 0;
  806. /* Today, wildcard AF_INET/AF_INET6. */
  807. if (sctp_is_any(sk, addr1) || sctp_is_any(sk, addr2))
  808. return 1;
  809. if (addr1->sa.sa_family == AF_INET && addr2->sa.sa_family == AF_INET)
  810. return addr1->v4.sin_addr.s_addr == addr2->v4.sin_addr.s_addr;
  811. return __sctp_v6_cmp_addr(addr1, addr2);
  812. }
  813. /* Verify that the provided sockaddr looks bindable. Common verification,
  814. * has already been taken care of.
  815. */
  816. static int sctp_inet6_bind_verify(struct sctp_sock *opt, union sctp_addr *addr)
  817. {
  818. struct sctp_af *af;
  819. /* ASSERT: address family has already been verified. */
  820. if (addr->sa.sa_family != AF_INET6)
  821. af = sctp_get_af_specific(addr->sa.sa_family);
  822. else {
  823. int type = ipv6_addr_type(&addr->v6.sin6_addr);
  824. struct net_device *dev;
  825. if (type & IPV6_ADDR_LINKLOCAL) {
  826. struct net *net;
  827. if (!addr->v6.sin6_scope_id)
  828. return 0;
  829. net = sock_net(&opt->inet.sk);
  830. rcu_read_lock();
  831. dev = dev_get_by_index_rcu(net, addr->v6.sin6_scope_id);
  832. if (!dev || !(ipv6_can_nonlocal_bind(net, &opt->inet) ||
  833. ipv6_chk_addr(net, &addr->v6.sin6_addr,
  834. dev, 0))) {
  835. rcu_read_unlock();
  836. return 0;
  837. }
  838. rcu_read_unlock();
  839. }
  840. af = opt->pf->af;
  841. }
  842. return af->available(addr, opt);
  843. }
  844. /* Verify that the provided sockaddr looks sendable. Common verification,
  845. * has already been taken care of.
  846. */
  847. static int sctp_inet6_send_verify(struct sctp_sock *opt, union sctp_addr *addr)
  848. {
  849. struct sctp_af *af = NULL;
  850. /* ASSERT: address family has already been verified. */
  851. if (addr->sa.sa_family != AF_INET6)
  852. af = sctp_get_af_specific(addr->sa.sa_family);
  853. else {
  854. int type = ipv6_addr_type(&addr->v6.sin6_addr);
  855. struct net_device *dev;
  856. if (type & IPV6_ADDR_LINKLOCAL) {
  857. if (!addr->v6.sin6_scope_id)
  858. return 0;
  859. rcu_read_lock();
  860. dev = dev_get_by_index_rcu(sock_net(&opt->inet.sk),
  861. addr->v6.sin6_scope_id);
  862. rcu_read_unlock();
  863. if (!dev)
  864. return 0;
  865. }
  866. af = opt->pf->af;
  867. }
  868. return af != NULL;
  869. }
  870. /* Fill in Supported Address Type information for INIT and INIT-ACK
  871. * chunks. Note: In the future, we may want to look at sock options
  872. * to determine whether a PF_INET6 socket really wants to have IPV4
  873. * addresses.
  874. * Returns number of addresses supported.
  875. */
  876. static int sctp_inet6_supported_addrs(const struct sctp_sock *opt,
  877. __be16 *types)
  878. {
  879. types[0] = SCTP_PARAM_IPV6_ADDRESS;
  880. if (!opt || !ipv6_only_sock(sctp_opt2sk(opt))) {
  881. types[1] = SCTP_PARAM_IPV4_ADDRESS;
  882. return 2;
  883. }
  884. return 1;
  885. }
  886. /* Handle SCTP_I_WANT_MAPPED_V4_ADDR for getpeername() and getsockname() */
  887. static int sctp_getname(struct socket *sock, struct sockaddr *uaddr,
  888. int peer)
  889. {
  890. int rc;
  891. rc = inet6_getname(sock, uaddr, peer);
  892. if (rc < 0)
  893. return rc;
  894. rc = sctp_v6_addr_to_user(sctp_sk(sock->sk),
  895. (union sctp_addr *)uaddr);
  896. return rc;
  897. }
  898. static const struct proto_ops inet6_seqpacket_ops = {
  899. .family = PF_INET6,
  900. .owner = THIS_MODULE,
  901. .release = inet6_release,
  902. .bind = inet6_bind,
  903. .connect = sctp_inet_connect,
  904. .socketpair = sock_no_socketpair,
  905. .accept = inet_accept,
  906. .getname = sctp_getname,
  907. .poll = sctp_poll,
  908. .ioctl = inet6_ioctl,
  909. .gettstamp = sock_gettstamp,
  910. .listen = sctp_inet_listen,
  911. .shutdown = inet_shutdown,
  912. .setsockopt = sock_common_setsockopt,
  913. .getsockopt = sock_common_getsockopt,
  914. .sendmsg = inet_sendmsg,
  915. .recvmsg = inet_recvmsg,
  916. .mmap = sock_no_mmap,
  917. #ifdef CONFIG_COMPAT
  918. .compat_ioctl = inet6_compat_ioctl,
  919. #endif
  920. };
  921. static struct inet_protosw sctpv6_seqpacket_protosw = {
  922. .type = SOCK_SEQPACKET,
  923. .protocol = IPPROTO_SCTP,
  924. .prot = &sctpv6_prot,
  925. .ops = &inet6_seqpacket_ops,
  926. .flags = SCTP_PROTOSW_FLAG
  927. };
  928. static struct inet_protosw sctpv6_stream_protosw = {
  929. .type = SOCK_STREAM,
  930. .protocol = IPPROTO_SCTP,
  931. .prot = &sctpv6_prot,
  932. .ops = &inet6_seqpacket_ops,
  933. .flags = SCTP_PROTOSW_FLAG,
  934. };
  935. static int sctp6_rcv(struct sk_buff *skb)
  936. {
  937. SCTP_INPUT_CB(skb)->encap_port = 0;
  938. return sctp_rcv(skb) ? -1 : 0;
  939. }
  940. static const struct inet6_protocol sctpv6_protocol = {
  941. .handler = sctp6_rcv,
  942. .err_handler = sctp_v6_err,
  943. .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
  944. };
  945. static struct sctp_af sctp_af_inet6 = {
  946. .sa_family = AF_INET6,
  947. .sctp_xmit = sctp_v6_xmit,
  948. .setsockopt = ipv6_setsockopt,
  949. .getsockopt = ipv6_getsockopt,
  950. .get_dst = sctp_v6_get_dst,
  951. .get_saddr = sctp_v6_get_saddr,
  952. .copy_addrlist = sctp_v6_copy_addrlist,
  953. .from_skb = sctp_v6_from_skb,
  954. .from_sk = sctp_v6_from_sk,
  955. .from_addr_param = sctp_v6_from_addr_param,
  956. .to_addr_param = sctp_v6_to_addr_param,
  957. .cmp_addr = sctp_v6_cmp_addr,
  958. .scope = sctp_v6_scope,
  959. .addr_valid = sctp_v6_addr_valid,
  960. .inaddr_any = sctp_v6_inaddr_any,
  961. .is_any = sctp_v6_is_any,
  962. .available = sctp_v6_available,
  963. .skb_iif = sctp_v6_skb_iif,
  964. .skb_sdif = sctp_v6_skb_sdif,
  965. .is_ce = sctp_v6_is_ce,
  966. .seq_dump_addr = sctp_v6_seq_dump_addr,
  967. .ecn_capable = sctp_v6_ecn_capable,
  968. .net_header_len = sizeof(struct ipv6hdr),
  969. .sockaddr_len = sizeof(struct sockaddr_in6),
  970. .ip_options_len = sctp_v6_ip_options_len,
  971. };
  972. static struct sctp_pf sctp_pf_inet6 = {
  973. .event_msgname = sctp_inet6_event_msgname,
  974. .skb_msgname = sctp_inet6_skb_msgname,
  975. .af_supported = sctp_inet6_af_supported,
  976. .cmp_addr = sctp_inet6_cmp_addr,
  977. .bind_verify = sctp_inet6_bind_verify,
  978. .send_verify = sctp_inet6_send_verify,
  979. .supported_addrs = sctp_inet6_supported_addrs,
  980. .addr_to_user = sctp_v6_addr_to_user,
  981. .to_sk_saddr = sctp_v6_to_sk_saddr,
  982. .to_sk_daddr = sctp_v6_to_sk_daddr,
  983. .copy_ip_options = sctp_v6_copy_ip_options,
  984. .af = &sctp_af_inet6,
  985. };
  986. /* Initialize IPv6 support and register with socket layer. */
  987. void sctp_v6_pf_init(void)
  988. {
  989. /* Register the SCTP specific PF_INET6 functions. */
  990. sctp_register_pf(&sctp_pf_inet6, PF_INET6);
  991. /* Register the SCTP specific AF_INET6 functions. */
  992. sctp_register_af(&sctp_af_inet6);
  993. }
  994. void sctp_v6_pf_exit(void)
  995. {
  996. list_del(&sctp_af_inet6.list);
  997. }
  998. /* Initialize IPv6 support and register with socket layer. */
  999. int sctp_v6_protosw_init(void)
  1000. {
  1001. int rc;
  1002. rc = proto_register(&sctpv6_prot, 1);
  1003. if (rc)
  1004. return rc;
  1005. /* Add SCTPv6(UDP and TCP style) to inetsw6 linked list. */
  1006. inet6_register_protosw(&sctpv6_seqpacket_protosw);
  1007. inet6_register_protosw(&sctpv6_stream_protosw);
  1008. return 0;
  1009. }
  1010. void sctp_v6_protosw_exit(void)
  1011. {
  1012. inet6_unregister_protosw(&sctpv6_seqpacket_protosw);
  1013. inet6_unregister_protosw(&sctpv6_stream_protosw);
  1014. proto_unregister(&sctpv6_prot);
  1015. }
  1016. /* Register with inet6 layer. */
  1017. int sctp_v6_add_protocol(void)
  1018. {
  1019. /* Register notifier for inet6 address additions/deletions. */
  1020. register_inet6addr_notifier(&sctp_inet6addr_notifier);
  1021. if (inet6_add_protocol(&sctpv6_protocol, IPPROTO_SCTP) < 0)
  1022. return -EAGAIN;
  1023. return 0;
  1024. }
  1025. /* Unregister with inet6 layer. */
  1026. void sctp_v6_del_protocol(void)
  1027. {
  1028. inet6_del_protocol(&sctpv6_protocol, IPPROTO_SCTP);
  1029. unregister_inet6addr_notifier(&sctp_inet6addr_notifier);
  1030. }