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