ipv6.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172
  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 = kzalloc(sizeof(*addr), GFP_ATOMIC);
  93. if (addr) {
  94. addr->a.v6.sin6_family = AF_INET6;
  95. addr->a.v6.sin6_addr = ifa->addr;
  96. addr->a.v6.sin6_scope_id = ifa->idev->dev->ifindex;
  97. addr->valid = 1;
  98. spin_lock_bh(&net->sctp.local_addr_lock);
  99. list_add_tail_rcu(&addr->list, &net->sctp.local_addr_list);
  100. sctp_addr_wq_mgmt(net, addr, SCTP_ADDR_NEW);
  101. spin_unlock_bh(&net->sctp.local_addr_lock);
  102. }
  103. break;
  104. case NETDEV_DOWN:
  105. spin_lock_bh(&net->sctp.local_addr_lock);
  106. list_for_each_entry_safe(addr, temp,
  107. &net->sctp.local_addr_list, list) {
  108. if (addr->a.sa.sa_family == AF_INET6 &&
  109. ipv6_addr_equal(&addr->a.v6.sin6_addr,
  110. &ifa->addr)) {
  111. sctp_addr_wq_mgmt(net, addr, SCTP_ADDR_DEL);
  112. found = 1;
  113. addr->valid = 0;
  114. list_del_rcu(&addr->list);
  115. break;
  116. }
  117. }
  118. spin_unlock_bh(&net->sctp.local_addr_lock);
  119. if (found)
  120. kfree_rcu(addr, rcu);
  121. break;
  122. }
  123. return NOTIFY_DONE;
  124. }
  125. static struct notifier_block sctp_inet6addr_notifier = {
  126. .notifier_call = sctp_inet6addr_event,
  127. };
  128. /* ICMP error handler. */
  129. static void sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
  130. u8 type, u8 code, int offset, __be32 info)
  131. {
  132. struct inet6_dev *idev;
  133. struct sock *sk;
  134. struct sctp_association *asoc;
  135. struct sctp_transport *transport;
  136. struct ipv6_pinfo *np;
  137. __u16 saveip, savesctp;
  138. int err;
  139. struct net *net = dev_net(skb->dev);
  140. idev = in6_dev_get(skb->dev);
  141. /* Fix up skb to look at the embedded net header. */
  142. saveip = skb->network_header;
  143. savesctp = skb->transport_header;
  144. skb_reset_network_header(skb);
  145. skb_set_transport_header(skb, offset);
  146. sk = sctp_err_lookup(net, AF_INET6, skb, sctp_hdr(skb), &asoc, &transport);
  147. /* Put back, the original pointers. */
  148. skb->network_header = saveip;
  149. skb->transport_header = savesctp;
  150. if (!sk) {
  151. __ICMP6_INC_STATS(net, idev, ICMP6_MIB_INERRORS);
  152. goto out;
  153. }
  154. /* Warning: The sock lock is held. Remember to call
  155. * sctp_err_finish!
  156. */
  157. switch (type) {
  158. case ICMPV6_PKT_TOOBIG:
  159. if (ip6_sk_accept_pmtu(sk))
  160. sctp_icmp_frag_needed(sk, asoc, transport, ntohl(info));
  161. goto out_unlock;
  162. case ICMPV6_PARAMPROB:
  163. if (ICMPV6_UNK_NEXTHDR == code) {
  164. sctp_icmp_proto_unreachable(sk, asoc, transport);
  165. goto out_unlock;
  166. }
  167. break;
  168. case NDISC_REDIRECT:
  169. sctp_icmp_redirect(sk, transport, skb);
  170. goto out_unlock;
  171. default:
  172. break;
  173. }
  174. np = inet6_sk(sk);
  175. icmpv6_err_convert(type, code, &err);
  176. if (!sock_owned_by_user(sk) && np->recverr) {
  177. sk->sk_err = err;
  178. sk->sk_error_report(sk);
  179. } else { /* Only an error on timeout */
  180. sk->sk_err_soft = err;
  181. }
  182. out_unlock:
  183. sctp_err_finish(sk, transport);
  184. out:
  185. if (likely(idev != NULL))
  186. in6_dev_put(idev);
  187. }
  188. static int sctp_v6_xmit(struct sk_buff *skb, struct sctp_transport *transport)
  189. {
  190. struct sock *sk = skb->sk;
  191. struct ipv6_pinfo *np = inet6_sk(sk);
  192. struct flowi6 *fl6 = &transport->fl.u.ip6;
  193. __u8 tclass = np->tclass;
  194. int res;
  195. pr_debug("%s: skb:%p, len:%d, src:%pI6 dst:%pI6\n", __func__, skb,
  196. skb->len, &fl6->saddr, &fl6->daddr);
  197. if (transport->dscp & SCTP_DSCP_SET_MASK)
  198. tclass = transport->dscp & SCTP_DSCP_VAL_MASK;
  199. if (INET_ECN_is_capable(tclass))
  200. IP6_ECN_flow_xmit(sk, fl6->flowlabel);
  201. if (!(transport->param_flags & SPP_PMTUD_ENABLE))
  202. skb->ignore_df = 1;
  203. SCTP_INC_STATS(sock_net(sk), SCTP_MIB_OUTSCTPPACKS);
  204. rcu_read_lock();
  205. res = ip6_xmit(sk, skb, fl6, sk->sk_mark, rcu_dereference(np->opt),
  206. tclass);
  207. rcu_read_unlock();
  208. return res;
  209. }
  210. /* Returns the dst cache entry for the given source and destination ip
  211. * addresses.
  212. */
  213. static void sctp_v6_get_dst(struct sctp_transport *t, union sctp_addr *saddr,
  214. struct flowi *fl, struct sock *sk)
  215. {
  216. struct sctp_association *asoc = t->asoc;
  217. struct dst_entry *dst = NULL;
  218. struct flowi6 *fl6 = &fl->u.ip6;
  219. struct sctp_bind_addr *bp;
  220. struct ipv6_pinfo *np = inet6_sk(sk);
  221. struct sctp_sockaddr_entry *laddr;
  222. union sctp_addr *daddr = &t->ipaddr;
  223. union sctp_addr dst_saddr;
  224. struct in6_addr *final_p, final;
  225. enum sctp_scope scope;
  226. __u8 matchlen = 0;
  227. memset(fl6, 0, sizeof(struct flowi6));
  228. fl6->daddr = daddr->v6.sin6_addr;
  229. fl6->fl6_dport = daddr->v6.sin6_port;
  230. fl6->flowi6_proto = IPPROTO_SCTP;
  231. if (ipv6_addr_type(&daddr->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL)
  232. fl6->flowi6_oif = daddr->v6.sin6_scope_id;
  233. else if (asoc)
  234. fl6->flowi6_oif = asoc->base.sk->sk_bound_dev_if;
  235. if (t->flowlabel & SCTP_FLOWLABEL_SET_MASK)
  236. fl6->flowlabel = htonl(t->flowlabel & SCTP_FLOWLABEL_VAL_MASK);
  237. if (np->sndflow && (fl6->flowlabel & IPV6_FLOWLABEL_MASK)) {
  238. struct ip6_flowlabel *flowlabel;
  239. flowlabel = fl6_sock_lookup(sk, fl6->flowlabel);
  240. if (!flowlabel)
  241. goto out;
  242. fl6_sock_release(flowlabel);
  243. }
  244. pr_debug("%s: dst=%pI6 ", __func__, &fl6->daddr);
  245. if (asoc)
  246. fl6->fl6_sport = htons(asoc->base.bind_addr.port);
  247. if (saddr) {
  248. fl6->saddr = saddr->v6.sin6_addr;
  249. if (!fl6->fl6_sport)
  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_addr = ifp->addr;
  381. addr->a.v6.sin6_scope_id = dev->ifindex;
  382. addr->valid = 1;
  383. INIT_LIST_HEAD(&addr->list);
  384. list_add_tail(&addr->list, addrlist);
  385. }
  386. }
  387. read_unlock_bh(&in6_dev->lock);
  388. rcu_read_unlock();
  389. }
  390. /* Copy over any ip options */
  391. static void sctp_v6_copy_ip_options(struct sock *sk, struct sock *newsk)
  392. {
  393. struct ipv6_pinfo *newnp, *np = inet6_sk(sk);
  394. struct ipv6_txoptions *opt;
  395. newnp = inet6_sk(newsk);
  396. rcu_read_lock();
  397. opt = rcu_dereference(np->opt);
  398. if (opt) {
  399. opt = ipv6_dup_options(newsk, opt);
  400. if (!opt)
  401. pr_err("%s: Failed to copy ip options\n", __func__);
  402. }
  403. RCU_INIT_POINTER(newnp->opt, opt);
  404. rcu_read_unlock();
  405. }
  406. /* Account for the IP options */
  407. static int sctp_v6_ip_options_len(struct sock *sk)
  408. {
  409. struct ipv6_pinfo *np = inet6_sk(sk);
  410. struct ipv6_txoptions *opt;
  411. int len = 0;
  412. rcu_read_lock();
  413. opt = rcu_dereference(np->opt);
  414. if (opt)
  415. len = opt->opt_flen + opt->opt_nflen;
  416. rcu_read_unlock();
  417. return len;
  418. }
  419. /* Initialize a sockaddr_storage from in incoming skb. */
  420. static void sctp_v6_from_skb(union sctp_addr *addr, struct sk_buff *skb,
  421. int is_saddr)
  422. {
  423. /* Always called on head skb, so this is safe */
  424. struct sctphdr *sh = sctp_hdr(skb);
  425. struct sockaddr_in6 *sa = &addr->v6;
  426. addr->v6.sin6_family = AF_INET6;
  427. addr->v6.sin6_flowinfo = 0; /* FIXME */
  428. addr->v6.sin6_scope_id = ((struct inet6_skb_parm *)skb->cb)->iif;
  429. if (is_saddr) {
  430. sa->sin6_port = sh->source;
  431. sa->sin6_addr = ipv6_hdr(skb)->saddr;
  432. } else {
  433. sa->sin6_port = sh->dest;
  434. sa->sin6_addr = ipv6_hdr(skb)->daddr;
  435. }
  436. }
  437. /* Initialize an sctp_addr from a socket. */
  438. static void sctp_v6_from_sk(union sctp_addr *addr, struct sock *sk)
  439. {
  440. addr->v6.sin6_family = AF_INET6;
  441. addr->v6.sin6_port = 0;
  442. addr->v6.sin6_addr = sk->sk_v6_rcv_saddr;
  443. }
  444. /* Initialize sk->sk_rcv_saddr from sctp_addr. */
  445. static void sctp_v6_to_sk_saddr(union sctp_addr *addr, struct sock *sk)
  446. {
  447. if (addr->sa.sa_family == AF_INET) {
  448. sk->sk_v6_rcv_saddr.s6_addr32[0] = 0;
  449. sk->sk_v6_rcv_saddr.s6_addr32[1] = 0;
  450. sk->sk_v6_rcv_saddr.s6_addr32[2] = htonl(0x0000ffff);
  451. sk->sk_v6_rcv_saddr.s6_addr32[3] =
  452. addr->v4.sin_addr.s_addr;
  453. } else {
  454. sk->sk_v6_rcv_saddr = addr->v6.sin6_addr;
  455. }
  456. }
  457. /* Initialize sk->sk_daddr from sctp_addr. */
  458. static void sctp_v6_to_sk_daddr(union sctp_addr *addr, struct sock *sk)
  459. {
  460. if (addr->sa.sa_family == AF_INET) {
  461. sk->sk_v6_daddr.s6_addr32[0] = 0;
  462. sk->sk_v6_daddr.s6_addr32[1] = 0;
  463. sk->sk_v6_daddr.s6_addr32[2] = htonl(0x0000ffff);
  464. sk->sk_v6_daddr.s6_addr32[3] = addr->v4.sin_addr.s_addr;
  465. } else {
  466. sk->sk_v6_daddr = addr->v6.sin6_addr;
  467. }
  468. }
  469. /* Initialize a sctp_addr from an address parameter. */
  470. static void sctp_v6_from_addr_param(union sctp_addr *addr,
  471. union sctp_addr_param *param,
  472. __be16 port, int iif)
  473. {
  474. addr->v6.sin6_family = AF_INET6;
  475. addr->v6.sin6_port = port;
  476. addr->v6.sin6_flowinfo = 0; /* BUG */
  477. addr->v6.sin6_addr = param->v6.addr;
  478. addr->v6.sin6_scope_id = iif;
  479. }
  480. /* Initialize an address parameter from a sctp_addr and return the length
  481. * of the address parameter.
  482. */
  483. static int sctp_v6_to_addr_param(const union sctp_addr *addr,
  484. union sctp_addr_param *param)
  485. {
  486. int length = sizeof(struct sctp_ipv6addr_param);
  487. param->v6.param_hdr.type = SCTP_PARAM_IPV6_ADDRESS;
  488. param->v6.param_hdr.length = htons(length);
  489. param->v6.addr = addr->v6.sin6_addr;
  490. return length;
  491. }
  492. /* Initialize a sctp_addr from struct in6_addr. */
  493. static void sctp_v6_to_addr(union sctp_addr *addr, struct in6_addr *saddr,
  494. __be16 port)
  495. {
  496. addr->sa.sa_family = AF_INET6;
  497. addr->v6.sin6_port = port;
  498. addr->v6.sin6_flowinfo = 0;
  499. addr->v6.sin6_addr = *saddr;
  500. addr->v6.sin6_scope_id = 0;
  501. }
  502. static int __sctp_v6_cmp_addr(const union sctp_addr *addr1,
  503. const union sctp_addr *addr2)
  504. {
  505. if (addr1->sa.sa_family != addr2->sa.sa_family) {
  506. if (addr1->sa.sa_family == AF_INET &&
  507. addr2->sa.sa_family == AF_INET6 &&
  508. ipv6_addr_v4mapped(&addr2->v6.sin6_addr) &&
  509. addr2->v6.sin6_addr.s6_addr32[3] ==
  510. addr1->v4.sin_addr.s_addr)
  511. return 1;
  512. if (addr2->sa.sa_family == AF_INET &&
  513. addr1->sa.sa_family == AF_INET6 &&
  514. ipv6_addr_v4mapped(&addr1->v6.sin6_addr) &&
  515. addr1->v6.sin6_addr.s6_addr32[3] ==
  516. addr2->v4.sin_addr.s_addr)
  517. return 1;
  518. return 0;
  519. }
  520. if (!ipv6_addr_equal(&addr1->v6.sin6_addr, &addr2->v6.sin6_addr))
  521. return 0;
  522. /* If this is a linklocal address, compare the scope_id. */
  523. if ((ipv6_addr_type(&addr1->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL) &&
  524. addr1->v6.sin6_scope_id && addr2->v6.sin6_scope_id &&
  525. addr1->v6.sin6_scope_id != addr2->v6.sin6_scope_id)
  526. return 0;
  527. return 1;
  528. }
  529. /* Compare addresses exactly.
  530. * v4-mapped-v6 is also in consideration.
  531. */
  532. static int sctp_v6_cmp_addr(const union sctp_addr *addr1,
  533. const union sctp_addr *addr2)
  534. {
  535. return __sctp_v6_cmp_addr(addr1, addr2) &&
  536. addr1->v6.sin6_port == addr2->v6.sin6_port;
  537. }
  538. /* Initialize addr struct to INADDR_ANY. */
  539. static void sctp_v6_inaddr_any(union sctp_addr *addr, __be16 port)
  540. {
  541. memset(addr, 0x00, sizeof(union sctp_addr));
  542. addr->v6.sin6_family = AF_INET6;
  543. addr->v6.sin6_port = port;
  544. }
  545. /* Is this a wildcard address? */
  546. static int sctp_v6_is_any(const union sctp_addr *addr)
  547. {
  548. return ipv6_addr_any(&addr->v6.sin6_addr);
  549. }
  550. /* Should this be available for binding? */
  551. static int sctp_v6_available(union sctp_addr *addr, struct sctp_sock *sp)
  552. {
  553. int type;
  554. struct net *net = sock_net(&sp->inet.sk);
  555. const struct in6_addr *in6 = (const struct in6_addr *)&addr->v6.sin6_addr;
  556. type = ipv6_addr_type(in6);
  557. if (IPV6_ADDR_ANY == type)
  558. return 1;
  559. if (type == IPV6_ADDR_MAPPED) {
  560. if (sp && ipv6_only_sock(sctp_opt2sk(sp)))
  561. return 0;
  562. sctp_v6_map_v4(addr);
  563. return sctp_get_af_specific(AF_INET)->available(addr, sp);
  564. }
  565. if (!(type & IPV6_ADDR_UNICAST))
  566. return 0;
  567. return sp->inet.freebind || net->ipv6.sysctl.ip_nonlocal_bind ||
  568. ipv6_chk_addr(net, in6, NULL, 0);
  569. }
  570. /* This function checks if the address is a valid address to be used for
  571. * SCTP.
  572. *
  573. * Output:
  574. * Return 0 - If the address is a non-unicast or an illegal address.
  575. * Return 1 - If the address is a unicast.
  576. */
  577. static int sctp_v6_addr_valid(union sctp_addr *addr,
  578. struct sctp_sock *sp,
  579. const struct sk_buff *skb)
  580. {
  581. int ret = ipv6_addr_type(&addr->v6.sin6_addr);
  582. /* Support v4-mapped-v6 address. */
  583. if (ret == IPV6_ADDR_MAPPED) {
  584. /* Note: This routine is used in input, so v4-mapped-v6
  585. * are disallowed here when there is no sctp_sock.
  586. */
  587. if (sp && ipv6_only_sock(sctp_opt2sk(sp)))
  588. return 0;
  589. sctp_v6_map_v4(addr);
  590. return sctp_get_af_specific(AF_INET)->addr_valid(addr, sp, skb);
  591. }
  592. /* Is this a non-unicast address */
  593. if (!(ret & IPV6_ADDR_UNICAST))
  594. return 0;
  595. return 1;
  596. }
  597. /* What is the scope of 'addr'? */
  598. static enum sctp_scope sctp_v6_scope(union sctp_addr *addr)
  599. {
  600. enum sctp_scope retval;
  601. int v6scope;
  602. /* The IPv6 scope is really a set of bit fields.
  603. * See IFA_* in <net/if_inet6.h>. Map to a generic SCTP scope.
  604. */
  605. v6scope = ipv6_addr_scope(&addr->v6.sin6_addr);
  606. switch (v6scope) {
  607. case IFA_HOST:
  608. retval = SCTP_SCOPE_LOOPBACK;
  609. break;
  610. case IFA_LINK:
  611. retval = SCTP_SCOPE_LINK;
  612. break;
  613. case IFA_SITE:
  614. retval = SCTP_SCOPE_PRIVATE;
  615. break;
  616. default:
  617. retval = SCTP_SCOPE_GLOBAL;
  618. break;
  619. }
  620. return retval;
  621. }
  622. /* Create and initialize a new sk for the socket to be returned by accept(). */
  623. static struct sock *sctp_v6_create_accept_sk(struct sock *sk,
  624. struct sctp_association *asoc,
  625. bool kern)
  626. {
  627. struct sock *newsk;
  628. struct ipv6_pinfo *newnp, *np = inet6_sk(sk);
  629. struct sctp6_sock *newsctp6sk;
  630. newsk = sk_alloc(sock_net(sk), PF_INET6, GFP_KERNEL, sk->sk_prot, kern);
  631. if (!newsk)
  632. goto out;
  633. sock_init_data(NULL, newsk);
  634. sctp_copy_sock(newsk, sk, asoc);
  635. sock_reset_flag(sk, SOCK_ZAPPED);
  636. newsctp6sk = (struct sctp6_sock *)newsk;
  637. inet_sk(newsk)->pinet6 = &newsctp6sk->inet6;
  638. sctp_sk(newsk)->v4mapped = sctp_sk(sk)->v4mapped;
  639. newnp = inet6_sk(newsk);
  640. memcpy(newnp, np, sizeof(struct ipv6_pinfo));
  641. newnp->ipv6_mc_list = NULL;
  642. newnp->ipv6_ac_list = NULL;
  643. newnp->ipv6_fl_list = NULL;
  644. sctp_v6_copy_ip_options(sk, newsk);
  645. /* Initialize sk's sport, dport, rcv_saddr and daddr for getsockname()
  646. * and getpeername().
  647. */
  648. sctp_v6_to_sk_daddr(&asoc->peer.primary_addr, newsk);
  649. newsk->sk_v6_rcv_saddr = sk->sk_v6_rcv_saddr;
  650. sk_refcnt_debug_inc(newsk);
  651. if (newsk->sk_prot->init(newsk)) {
  652. sk_common_release(newsk);
  653. newsk = NULL;
  654. }
  655. out:
  656. return newsk;
  657. }
  658. /* Format a sockaddr for return to user space. This makes sure the return is
  659. * AF_INET or AF_INET6 depending on the SCTP_I_WANT_MAPPED_V4_ADDR option.
  660. */
  661. static int sctp_v6_addr_to_user(struct sctp_sock *sp, union sctp_addr *addr)
  662. {
  663. if (sp->v4mapped) {
  664. if (addr->sa.sa_family == AF_INET)
  665. sctp_v4_map_v6(addr);
  666. } else {
  667. if (addr->sa.sa_family == AF_INET6 &&
  668. ipv6_addr_v4mapped(&addr->v6.sin6_addr))
  669. sctp_v6_map_v4(addr);
  670. }
  671. if (addr->sa.sa_family == AF_INET) {
  672. memset(addr->v4.sin_zero, 0, sizeof(addr->v4.sin_zero));
  673. return sizeof(struct sockaddr_in);
  674. }
  675. return sizeof(struct sockaddr_in6);
  676. }
  677. /* Where did this skb come from? */
  678. static int sctp_v6_skb_iif(const struct sk_buff *skb)
  679. {
  680. return IP6CB(skb)->iif;
  681. }
  682. /* Was this packet marked by Explicit Congestion Notification? */
  683. static int sctp_v6_is_ce(const struct sk_buff *skb)
  684. {
  685. return *((__u32 *)(ipv6_hdr(skb))) & (__force __u32)htonl(1 << 20);
  686. }
  687. /* Dump the v6 addr to the seq file. */
  688. static void sctp_v6_seq_dump_addr(struct seq_file *seq, union sctp_addr *addr)
  689. {
  690. seq_printf(seq, "%pI6 ", &addr->v6.sin6_addr);
  691. }
  692. static void sctp_v6_ecn_capable(struct sock *sk)
  693. {
  694. inet6_sk(sk)->tclass |= INET_ECN_ECT_0;
  695. }
  696. /* Initialize a PF_INET msgname from a ulpevent. */
  697. static void sctp_inet6_event_msgname(struct sctp_ulpevent *event,
  698. char *msgname, int *addrlen)
  699. {
  700. union sctp_addr *addr;
  701. struct sctp_association *asoc;
  702. union sctp_addr *paddr;
  703. if (!msgname)
  704. return;
  705. addr = (union sctp_addr *)msgname;
  706. asoc = event->asoc;
  707. paddr = &asoc->peer.primary_addr;
  708. if (paddr->sa.sa_family == AF_INET) {
  709. addr->v4.sin_family = AF_INET;
  710. addr->v4.sin_port = htons(asoc->peer.port);
  711. addr->v4.sin_addr = paddr->v4.sin_addr;
  712. } else {
  713. addr->v6.sin6_family = AF_INET6;
  714. addr->v6.sin6_flowinfo = 0;
  715. if (ipv6_addr_type(&paddr->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL)
  716. addr->v6.sin6_scope_id = paddr->v6.sin6_scope_id;
  717. else
  718. addr->v6.sin6_scope_id = 0;
  719. addr->v6.sin6_port = htons(asoc->peer.port);
  720. addr->v6.sin6_addr = paddr->v6.sin6_addr;
  721. }
  722. *addrlen = sctp_v6_addr_to_user(sctp_sk(asoc->base.sk), addr);
  723. }
  724. /* Initialize a msg_name from an inbound skb. */
  725. static void sctp_inet6_skb_msgname(struct sk_buff *skb, char *msgname,
  726. int *addr_len)
  727. {
  728. union sctp_addr *addr;
  729. struct sctphdr *sh;
  730. if (!msgname)
  731. return;
  732. addr = (union sctp_addr *)msgname;
  733. sh = sctp_hdr(skb);
  734. if (ip_hdr(skb)->version == 4) {
  735. addr->v4.sin_family = AF_INET;
  736. addr->v4.sin_port = sh->source;
  737. addr->v4.sin_addr.s_addr = ip_hdr(skb)->saddr;
  738. } else {
  739. addr->v6.sin6_family = AF_INET6;
  740. addr->v6.sin6_flowinfo = 0;
  741. addr->v6.sin6_port = sh->source;
  742. addr->v6.sin6_addr = ipv6_hdr(skb)->saddr;
  743. if (ipv6_addr_type(&addr->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL)
  744. addr->v6.sin6_scope_id = sctp_v6_skb_iif(skb);
  745. else
  746. addr->v6.sin6_scope_id = 0;
  747. }
  748. *addr_len = sctp_v6_addr_to_user(sctp_sk(skb->sk), addr);
  749. }
  750. /* Do we support this AF? */
  751. static int sctp_inet6_af_supported(sa_family_t family, struct sctp_sock *sp)
  752. {
  753. switch (family) {
  754. case AF_INET6:
  755. return 1;
  756. /* v4-mapped-v6 addresses */
  757. case AF_INET:
  758. if (!__ipv6_only_sock(sctp_opt2sk(sp)))
  759. return 1;
  760. /* fallthru */
  761. default:
  762. return 0;
  763. }
  764. }
  765. /* Address matching with wildcards allowed. This extra level
  766. * of indirection lets us choose whether a PF_INET6 should
  767. * disallow any v4 addresses if we so choose.
  768. */
  769. static int sctp_inet6_cmp_addr(const union sctp_addr *addr1,
  770. const union sctp_addr *addr2,
  771. struct sctp_sock *opt)
  772. {
  773. struct sock *sk = sctp_opt2sk(opt);
  774. struct sctp_af *af1, *af2;
  775. af1 = sctp_get_af_specific(addr1->sa.sa_family);
  776. af2 = sctp_get_af_specific(addr2->sa.sa_family);
  777. if (!af1 || !af2)
  778. return 0;
  779. /* If the socket is IPv6 only, v4 addrs will not match */
  780. if (__ipv6_only_sock(sk) && af1 != af2)
  781. return 0;
  782. /* Today, wildcard AF_INET/AF_INET6. */
  783. if (sctp_is_any(sk, addr1) || sctp_is_any(sk, addr2))
  784. return 1;
  785. if (addr1->sa.sa_family == AF_INET && addr2->sa.sa_family == AF_INET)
  786. return addr1->v4.sin_addr.s_addr == addr2->v4.sin_addr.s_addr;
  787. return __sctp_v6_cmp_addr(addr1, addr2);
  788. }
  789. /* Verify that the provided sockaddr looks bindable. Common verification,
  790. * has already been taken care of.
  791. */
  792. static int sctp_inet6_bind_verify(struct sctp_sock *opt, union sctp_addr *addr)
  793. {
  794. struct sctp_af *af;
  795. /* ASSERT: address family has already been verified. */
  796. if (addr->sa.sa_family != AF_INET6)
  797. af = sctp_get_af_specific(addr->sa.sa_family);
  798. else {
  799. int type = ipv6_addr_type(&addr->v6.sin6_addr);
  800. struct net_device *dev;
  801. if (type & IPV6_ADDR_LINKLOCAL) {
  802. struct net *net;
  803. if (!addr->v6.sin6_scope_id)
  804. return 0;
  805. net = sock_net(&opt->inet.sk);
  806. rcu_read_lock();
  807. dev = dev_get_by_index_rcu(net, addr->v6.sin6_scope_id);
  808. if (!dev || !(opt->inet.freebind ||
  809. net->ipv6.sysctl.ip_nonlocal_bind ||
  810. ipv6_chk_addr(net, &addr->v6.sin6_addr,
  811. dev, 0))) {
  812. rcu_read_unlock();
  813. return 0;
  814. }
  815. rcu_read_unlock();
  816. }
  817. af = opt->pf->af;
  818. }
  819. return af->available(addr, opt);
  820. }
  821. /* Verify that the provided sockaddr looks sendable. Common verification,
  822. * has already been taken care of.
  823. */
  824. static int sctp_inet6_send_verify(struct sctp_sock *opt, union sctp_addr *addr)
  825. {
  826. struct sctp_af *af = NULL;
  827. /* ASSERT: address family has already been verified. */
  828. if (addr->sa.sa_family != AF_INET6)
  829. af = sctp_get_af_specific(addr->sa.sa_family);
  830. else {
  831. int type = ipv6_addr_type(&addr->v6.sin6_addr);
  832. struct net_device *dev;
  833. if (type & IPV6_ADDR_LINKLOCAL) {
  834. if (!addr->v6.sin6_scope_id)
  835. return 0;
  836. rcu_read_lock();
  837. dev = dev_get_by_index_rcu(sock_net(&opt->inet.sk),
  838. addr->v6.sin6_scope_id);
  839. rcu_read_unlock();
  840. if (!dev)
  841. return 0;
  842. }
  843. af = opt->pf->af;
  844. }
  845. return af != NULL;
  846. }
  847. /* Fill in Supported Address Type information for INIT and INIT-ACK
  848. * chunks. Note: In the future, we may want to look at sock options
  849. * to determine whether a PF_INET6 socket really wants to have IPV4
  850. * addresses.
  851. * Returns number of addresses supported.
  852. */
  853. static int sctp_inet6_supported_addrs(const struct sctp_sock *opt,
  854. __be16 *types)
  855. {
  856. types[0] = SCTP_PARAM_IPV6_ADDRESS;
  857. if (!opt || !ipv6_only_sock(sctp_opt2sk(opt))) {
  858. types[1] = SCTP_PARAM_IPV4_ADDRESS;
  859. return 2;
  860. }
  861. return 1;
  862. }
  863. /* Handle SCTP_I_WANT_MAPPED_V4_ADDR for getpeername() and getsockname() */
  864. static int sctp_getname(struct socket *sock, struct sockaddr *uaddr,
  865. int peer)
  866. {
  867. int rc;
  868. rc = inet6_getname(sock, uaddr, peer);
  869. if (rc < 0)
  870. return rc;
  871. rc = sctp_v6_addr_to_user(sctp_sk(sock->sk),
  872. (union sctp_addr *)uaddr);
  873. return rc;
  874. }
  875. static const struct proto_ops inet6_seqpacket_ops = {
  876. .family = PF_INET6,
  877. .owner = THIS_MODULE,
  878. .release = inet6_release,
  879. .bind = inet6_bind,
  880. .connect = sctp_inet_connect,
  881. .socketpair = sock_no_socketpair,
  882. .accept = inet_accept,
  883. .getname = sctp_getname,
  884. .poll = sctp_poll,
  885. .ioctl = inet6_ioctl,
  886. .listen = sctp_inet_listen,
  887. .shutdown = inet_shutdown,
  888. .setsockopt = sock_common_setsockopt,
  889. .getsockopt = sock_common_getsockopt,
  890. .sendmsg = inet_sendmsg,
  891. .recvmsg = inet_recvmsg,
  892. .mmap = sock_no_mmap,
  893. #ifdef CONFIG_COMPAT
  894. .compat_setsockopt = compat_sock_common_setsockopt,
  895. .compat_getsockopt = compat_sock_common_getsockopt,
  896. #endif
  897. };
  898. static struct inet_protosw sctpv6_seqpacket_protosw = {
  899. .type = SOCK_SEQPACKET,
  900. .protocol = IPPROTO_SCTP,
  901. .prot = &sctpv6_prot,
  902. .ops = &inet6_seqpacket_ops,
  903. .flags = SCTP_PROTOSW_FLAG
  904. };
  905. static struct inet_protosw sctpv6_stream_protosw = {
  906. .type = SOCK_STREAM,
  907. .protocol = IPPROTO_SCTP,
  908. .prot = &sctpv6_prot,
  909. .ops = &inet6_seqpacket_ops,
  910. .flags = SCTP_PROTOSW_FLAG,
  911. };
  912. static int sctp6_rcv(struct sk_buff *skb)
  913. {
  914. return sctp_rcv(skb) ? -1 : 0;
  915. }
  916. static const struct inet6_protocol sctpv6_protocol = {
  917. .handler = sctp6_rcv,
  918. .err_handler = sctp_v6_err,
  919. .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
  920. };
  921. static struct sctp_af sctp_af_inet6 = {
  922. .sa_family = AF_INET6,
  923. .sctp_xmit = sctp_v6_xmit,
  924. .setsockopt = ipv6_setsockopt,
  925. .getsockopt = ipv6_getsockopt,
  926. .get_dst = sctp_v6_get_dst,
  927. .get_saddr = sctp_v6_get_saddr,
  928. .copy_addrlist = sctp_v6_copy_addrlist,
  929. .from_skb = sctp_v6_from_skb,
  930. .from_sk = sctp_v6_from_sk,
  931. .from_addr_param = sctp_v6_from_addr_param,
  932. .to_addr_param = sctp_v6_to_addr_param,
  933. .cmp_addr = sctp_v6_cmp_addr,
  934. .scope = sctp_v6_scope,
  935. .addr_valid = sctp_v6_addr_valid,
  936. .inaddr_any = sctp_v6_inaddr_any,
  937. .is_any = sctp_v6_is_any,
  938. .available = sctp_v6_available,
  939. .skb_iif = sctp_v6_skb_iif,
  940. .is_ce = sctp_v6_is_ce,
  941. .seq_dump_addr = sctp_v6_seq_dump_addr,
  942. .ecn_capable = sctp_v6_ecn_capable,
  943. .net_header_len = sizeof(struct ipv6hdr),
  944. .sockaddr_len = sizeof(struct sockaddr_in6),
  945. .ip_options_len = sctp_v6_ip_options_len,
  946. #ifdef CONFIG_COMPAT
  947. .compat_setsockopt = compat_ipv6_setsockopt,
  948. .compat_getsockopt = compat_ipv6_getsockopt,
  949. #endif
  950. };
  951. static struct sctp_pf sctp_pf_inet6 = {
  952. .event_msgname = sctp_inet6_event_msgname,
  953. .skb_msgname = sctp_inet6_skb_msgname,
  954. .af_supported = sctp_inet6_af_supported,
  955. .cmp_addr = sctp_inet6_cmp_addr,
  956. .bind_verify = sctp_inet6_bind_verify,
  957. .send_verify = sctp_inet6_send_verify,
  958. .supported_addrs = sctp_inet6_supported_addrs,
  959. .create_accept_sk = sctp_v6_create_accept_sk,
  960. .addr_to_user = sctp_v6_addr_to_user,
  961. .to_sk_saddr = sctp_v6_to_sk_saddr,
  962. .to_sk_daddr = sctp_v6_to_sk_daddr,
  963. .copy_ip_options = sctp_v6_copy_ip_options,
  964. .af = &sctp_af_inet6,
  965. };
  966. /* Initialize IPv6 support and register with socket layer. */
  967. void sctp_v6_pf_init(void)
  968. {
  969. /* Register the SCTP specific PF_INET6 functions. */
  970. sctp_register_pf(&sctp_pf_inet6, PF_INET6);
  971. /* Register the SCTP specific AF_INET6 functions. */
  972. sctp_register_af(&sctp_af_inet6);
  973. }
  974. void sctp_v6_pf_exit(void)
  975. {
  976. list_del(&sctp_af_inet6.list);
  977. }
  978. /* Initialize IPv6 support and register with socket layer. */
  979. int sctp_v6_protosw_init(void)
  980. {
  981. int rc;
  982. rc = proto_register(&sctpv6_prot, 1);
  983. if (rc)
  984. return rc;
  985. /* Add SCTPv6(UDP and TCP style) to inetsw6 linked list. */
  986. inet6_register_protosw(&sctpv6_seqpacket_protosw);
  987. inet6_register_protosw(&sctpv6_stream_protosw);
  988. return 0;
  989. }
  990. void sctp_v6_protosw_exit(void)
  991. {
  992. inet6_unregister_protosw(&sctpv6_seqpacket_protosw);
  993. inet6_unregister_protosw(&sctpv6_stream_protosw);
  994. proto_unregister(&sctpv6_prot);
  995. }
  996. /* Register with inet6 layer. */
  997. int sctp_v6_add_protocol(void)
  998. {
  999. /* Register notifier for inet6 address additions/deletions. */
  1000. register_inet6addr_notifier(&sctp_inet6addr_notifier);
  1001. if (inet6_add_protocol(&sctpv6_protocol, IPPROTO_SCTP) < 0)
  1002. return -EAGAIN;
  1003. return 0;
  1004. }
  1005. /* Unregister with inet6 layer. */
  1006. void sctp_v6_del_protocol(void)
  1007. {
  1008. inet6_del_protocol(&sctpv6_protocol, IPPROTO_SCTP);
  1009. unregister_inet6addr_notifier(&sctp_inet6addr_notifier);
  1010. }