ipv6.c 31 KB

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