1 |
1275 |
phoenix |
/* SCTP kernel reference Implementation
|
2 |
|
|
* Copyright (c) 2001 Nokia, Inc.
|
3 |
|
|
* Copyright (c) 2001 La Monte H.P. Yarroll
|
4 |
|
|
* Copyright (c) 2002-2003 International Business Machines, Corp.
|
5 |
|
|
* Copyright (c) 2002-2003 Intel Corp.
|
6 |
|
|
*
|
7 |
|
|
* This file is part of the SCTP kernel reference Implementation
|
8 |
|
|
*
|
9 |
|
|
* SCTP over IPv6.
|
10 |
|
|
*
|
11 |
|
|
* The SCTP reference 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 |
|
|
* The SCTP reference 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, write to
|
25 |
|
|
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
26 |
|
|
* Boston, MA 02111-1307, USA.
|
27 |
|
|
*
|
28 |
|
|
* Please send any bug reports or fixes you make to the
|
29 |
|
|
* email address(es):
|
30 |
|
|
* lksctp developers <lksctp-developers@lists.sourceforge.net>
|
31 |
|
|
*
|
32 |
|
|
* Or submit a bug report through the following website:
|
33 |
|
|
* http://www.sf.net/projects/lksctp
|
34 |
|
|
*
|
35 |
|
|
* Written or modified by:
|
36 |
|
|
* Le Yanqun <yanqun.le@nokia.com>
|
37 |
|
|
* Hui Huang <hui.huang@nokia.com>
|
38 |
|
|
* La Monte H.P. Yarroll <piggy@acm.org>
|
39 |
|
|
* Sridhar Samudrala <sri@us.ibm.com>
|
40 |
|
|
* Jon Grimm <jgrimm@us.ibm.com>
|
41 |
|
|
* Ardelle Fan <ardelle.fan@intel.com>
|
42 |
|
|
*
|
43 |
|
|
* Based on:
|
44 |
|
|
* linux/net/ipv6/tcp_ipv6.c
|
45 |
|
|
*
|
46 |
|
|
* Any bugs reported given to us we will try to fix... any fixes shared will
|
47 |
|
|
* be incorporated into the next SCTP release.
|
48 |
|
|
*/
|
49 |
|
|
|
50 |
|
|
#include <linux/module.h>
|
51 |
|
|
#include <linux/errno.h>
|
52 |
|
|
#include <linux/types.h>
|
53 |
|
|
#include <linux/socket.h>
|
54 |
|
|
#include <linux/sockios.h>
|
55 |
|
|
#include <linux/net.h>
|
56 |
|
|
#include <linux/sched.h>
|
57 |
|
|
#include <linux/in.h>
|
58 |
|
|
#include <linux/in6.h>
|
59 |
|
|
#include <linux/netdevice.h>
|
60 |
|
|
#include <linux/init.h>
|
61 |
|
|
#include <linux/ipsec.h>
|
62 |
|
|
|
63 |
|
|
#include <linux/ipv6.h>
|
64 |
|
|
#include <linux/icmpv6.h>
|
65 |
|
|
#include <linux/random.h>
|
66 |
|
|
#include <linux/seq_file.h>
|
67 |
|
|
|
68 |
|
|
#include <net/protocol.h>
|
69 |
|
|
#include <net/tcp.h>
|
70 |
|
|
#include <net/ndisc.h>
|
71 |
|
|
#include <net/ipv6.h>
|
72 |
|
|
#include <net/transp_v6.h>
|
73 |
|
|
#include <net/addrconf.h>
|
74 |
|
|
#include <net/ip6_route.h>
|
75 |
|
|
#include <net/inet_common.h>
|
76 |
|
|
#include <net/inet_ecn.h>
|
77 |
|
|
#include <net/sctp/sctp.h>
|
78 |
|
|
|
79 |
|
|
#include <asm/uaccess.h>
|
80 |
|
|
|
81 |
|
|
extern struct notifier_block sctp_inetaddr_notifier;
|
82 |
|
|
|
83 |
|
|
/* FIXME: This macro needs to be moved to a common header file. */
|
84 |
|
|
#define NIP6(addr) \
|
85 |
|
|
ntohs((addr)->s6_addr16[0]), \
|
86 |
|
|
ntohs((addr)->s6_addr16[1]), \
|
87 |
|
|
ntohs((addr)->s6_addr16[2]), \
|
88 |
|
|
ntohs((addr)->s6_addr16[3]), \
|
89 |
|
|
ntohs((addr)->s6_addr16[4]), \
|
90 |
|
|
ntohs((addr)->s6_addr16[5]), \
|
91 |
|
|
ntohs((addr)->s6_addr16[6]), \
|
92 |
|
|
ntohs((addr)->s6_addr16[7])
|
93 |
|
|
|
94 |
|
|
/* ICMP error handler. */
|
95 |
|
|
void sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
|
96 |
|
|
int type, int code, int offset, __u32 info)
|
97 |
|
|
{
|
98 |
|
|
struct inet6_dev *idev;
|
99 |
|
|
struct ipv6hdr *iph = (struct ipv6hdr *)skb->data;
|
100 |
|
|
struct sctphdr *sh = (struct sctphdr *)(skb->data + offset);
|
101 |
|
|
struct sock *sk;
|
102 |
|
|
struct sctp_endpoint *ep;
|
103 |
|
|
struct sctp_association *asoc;
|
104 |
|
|
struct sctp_transport *transport;
|
105 |
|
|
struct ipv6_pinfo *np;
|
106 |
|
|
char *saveip, *savesctp;
|
107 |
|
|
int err;
|
108 |
|
|
|
109 |
|
|
idev = in6_dev_get(skb->dev);
|
110 |
|
|
|
111 |
|
|
/* Fix up skb to look at the embedded net header. */
|
112 |
|
|
saveip = skb->nh.raw;
|
113 |
|
|
savesctp = skb->h.raw;
|
114 |
|
|
skb->nh.ipv6h = iph;
|
115 |
|
|
skb->h.raw = (char *)sh;
|
116 |
|
|
sk = sctp_err_lookup(AF_INET6, skb, sh, &ep, &asoc, &transport);
|
117 |
|
|
/* Put back, the original pointers. */
|
118 |
|
|
skb->nh.raw = saveip;
|
119 |
|
|
skb->h.raw = savesctp;
|
120 |
|
|
if (!sk) {
|
121 |
|
|
ICMP6_INC_STATS_BH(Icmp6InErrors);
|
122 |
|
|
goto out;
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
/* Warning: The sock lock is held. Remember to call
|
126 |
|
|
* sctp_err_finish!
|
127 |
|
|
*/
|
128 |
|
|
|
129 |
|
|
switch (type) {
|
130 |
|
|
case ICMPV6_PKT_TOOBIG:
|
131 |
|
|
sctp_icmp_frag_needed(sk, asoc, transport, ntohl(info));
|
132 |
|
|
goto out_unlock;
|
133 |
|
|
default:
|
134 |
|
|
break;
|
135 |
|
|
}
|
136 |
|
|
|
137 |
|
|
np = inet6_sk(sk);
|
138 |
|
|
icmpv6_err_convert(type, code, &err);
|
139 |
|
|
if (!sock_owned_by_user(sk) && np->recverr) {
|
140 |
|
|
sk->sk_err = err;
|
141 |
|
|
sk->sk_error_report(sk);
|
142 |
|
|
} else { /* Only an error on timeout */
|
143 |
|
|
sk->sk_err_soft = err;
|
144 |
|
|
}
|
145 |
|
|
|
146 |
|
|
out_unlock:
|
147 |
|
|
sctp_err_finish(sk, ep, asoc);
|
148 |
|
|
out:
|
149 |
|
|
if (likely(idev != NULL))
|
150 |
|
|
in6_dev_put(idev);
|
151 |
|
|
}
|
152 |
|
|
|
153 |
|
|
/* Based on tcp_v6_xmit() in tcp_ipv6.c. */
|
154 |
|
|
static int sctp_v6_xmit(struct sk_buff *skb, struct sctp_transport *transport,
|
155 |
|
|
int ipfragok)
|
156 |
|
|
{
|
157 |
|
|
struct sock *sk = skb->sk;
|
158 |
|
|
struct ipv6_pinfo *np = inet6_sk(sk);
|
159 |
|
|
struct flowi fl;
|
160 |
|
|
|
161 |
|
|
memset(&fl, 0, sizeof(fl));
|
162 |
|
|
|
163 |
|
|
fl.proto = sk->sk_protocol;
|
164 |
|
|
|
165 |
|
|
/* Fill in the dest address from the route entry passed with the skb
|
166 |
|
|
* and the source address from the transport.
|
167 |
|
|
*/
|
168 |
|
|
fl.fl6_dst = &transport->ipaddr.v6.sin6_addr;
|
169 |
|
|
fl.fl6_src = &transport->saddr.v6.sin6_addr;
|
170 |
|
|
|
171 |
|
|
fl.fl6_flowlabel = np->flow_label;
|
172 |
|
|
IP6_ECN_flow_xmit(sk, fl.fl6_flowlabel);
|
173 |
|
|
if (ipv6_addr_type(fl.fl6_src) & IPV6_ADDR_LINKLOCAL)
|
174 |
|
|
fl.oif = transport->saddr.v6.sin6_scope_id;
|
175 |
|
|
else
|
176 |
|
|
fl.oif = sk->sk_bound_dev_if;
|
177 |
|
|
fl.uli_u.ports.sport = sk->sport;
|
178 |
|
|
fl.uli_u.ports.dport = transport->ipaddr.v6.sin6_port;
|
179 |
|
|
|
180 |
|
|
if (np->opt && np->opt->srcrt) {
|
181 |
|
|
struct rt0_hdr *rt0 = (struct rt0_hdr *) np->opt->srcrt;
|
182 |
|
|
fl.fl6_dst = rt0->addr;
|
183 |
|
|
}
|
184 |
|
|
|
185 |
|
|
SCTP_DEBUG_PRINTK("%s: skb:%p, len:%d, "
|
186 |
|
|
"src:%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x "
|
187 |
|
|
"dst:%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
|
188 |
|
|
__FUNCTION__, skb, skb->len,
|
189 |
|
|
NIP6(fl.fl6_src), NIP6(fl.fl6_dst));
|
190 |
|
|
|
191 |
|
|
SCTP_INC_STATS(SctpOutSCTPPacks);
|
192 |
|
|
|
193 |
|
|
return ip6_xmit(sk, skb, &fl, np->opt);
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
/* Returns the dst cache entry for the given source and destination ip
|
197 |
|
|
* addresses.
|
198 |
|
|
*/
|
199 |
|
|
struct dst_entry *sctp_v6_get_dst(struct sctp_association *asoc,
|
200 |
|
|
union sctp_addr *daddr,
|
201 |
|
|
union sctp_addr *saddr)
|
202 |
|
|
{
|
203 |
|
|
struct dst_entry *dst;
|
204 |
|
|
struct flowi fl;
|
205 |
|
|
|
206 |
|
|
memset(&fl, 0, sizeof(fl));
|
207 |
|
|
fl.fl6_dst = &daddr->v6.sin6_addr;
|
208 |
|
|
if (ipv6_addr_type(&daddr->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL)
|
209 |
|
|
fl.oif = daddr->v6.sin6_scope_id;
|
210 |
|
|
|
211 |
|
|
|
212 |
|
|
SCTP_DEBUG_PRINTK("%s: DST=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ",
|
213 |
|
|
__FUNCTION__, NIP6(fl.fl6_dst));
|
214 |
|
|
|
215 |
|
|
if (saddr) {
|
216 |
|
|
fl.fl6_src = &saddr->v6.sin6_addr;
|
217 |
|
|
SCTP_DEBUG_PRINTK(
|
218 |
|
|
"SRC=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x - ",
|
219 |
|
|
NIP6(fl.fl6_src));
|
220 |
|
|
}
|
221 |
|
|
|
222 |
|
|
dst = ip6_route_output(NULL, &fl);
|
223 |
|
|
if (dst) {
|
224 |
|
|
struct rt6_info *rt;
|
225 |
|
|
rt = (struct rt6_info *)dst;
|
226 |
|
|
SCTP_DEBUG_PRINTK(
|
227 |
|
|
"rt6_dst:%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x "
|
228 |
|
|
"rt6_src:%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
|
229 |
|
|
NIP6(&rt->rt6i_dst.addr), NIP6(&rt->rt6i_src.addr));
|
230 |
|
|
} else {
|
231 |
|
|
SCTP_DEBUG_PRINTK("NO ROUTE\n");
|
232 |
|
|
}
|
233 |
|
|
|
234 |
|
|
return dst;
|
235 |
|
|
}
|
236 |
|
|
|
237 |
|
|
/* Returns the number of consecutive initial bits that match in the 2 ipv6
|
238 |
|
|
* addresses.
|
239 |
|
|
*/
|
240 |
|
|
static inline int sctp_v6_addr_match_len(union sctp_addr *s1,
|
241 |
|
|
union sctp_addr *s2)
|
242 |
|
|
{
|
243 |
|
|
struct in6_addr *a1 = &s1->v6.sin6_addr;
|
244 |
|
|
struct in6_addr *a2 = &s2->v6.sin6_addr;
|
245 |
|
|
int i, j;
|
246 |
|
|
|
247 |
|
|
for (i = 0; i < 4 ; i++) {
|
248 |
|
|
__u32 a1xora2;
|
249 |
|
|
|
250 |
|
|
a1xora2 = a1->s6_addr32[i] ^ a2->s6_addr32[i];
|
251 |
|
|
|
252 |
|
|
if ((j = fls(ntohl(a1xora2))))
|
253 |
|
|
return (i * 32 + 32 - j);
|
254 |
|
|
}
|
255 |
|
|
|
256 |
|
|
return (i*32);
|
257 |
|
|
}
|
258 |
|
|
|
259 |
|
|
/* Fills in the source address(saddr) based on the destination address(daddr)
|
260 |
|
|
* and asoc's bind address list.
|
261 |
|
|
*/
|
262 |
|
|
void sctp_v6_get_saddr(struct sctp_association *asoc, struct dst_entry *dst,
|
263 |
|
|
union sctp_addr *daddr, union sctp_addr *saddr)
|
264 |
|
|
{
|
265 |
|
|
struct sctp_bind_addr *bp;
|
266 |
|
|
rwlock_t *addr_lock;
|
267 |
|
|
struct sctp_sockaddr_entry *laddr;
|
268 |
|
|
struct list_head *pos;
|
269 |
|
|
sctp_scope_t scope;
|
270 |
|
|
union sctp_addr *baddr = NULL;
|
271 |
|
|
__u8 matchlen = 0;
|
272 |
|
|
__u8 bmatchlen;
|
273 |
|
|
|
274 |
|
|
SCTP_DEBUG_PRINTK("%s: asoc:%p dst:%p "
|
275 |
|
|
"daddr:%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ",
|
276 |
|
|
__FUNCTION__, asoc, dst, NIP6(&daddr->v6.sin6_addr));
|
277 |
|
|
|
278 |
|
|
if (!asoc) {
|
279 |
|
|
ipv6_get_saddr(dst, &daddr->v6.sin6_addr,&saddr->v6.sin6_addr);
|
280 |
|
|
SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: "
|
281 |
|
|
"%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
|
282 |
|
|
NIP6(&saddr->v6.sin6_addr));
|
283 |
|
|
return;
|
284 |
|
|
}
|
285 |
|
|
|
286 |
|
|
scope = sctp_scope(daddr);
|
287 |
|
|
|
288 |
|
|
bp = &asoc->base.bind_addr;
|
289 |
|
|
addr_lock = &asoc->base.addr_lock;
|
290 |
|
|
|
291 |
|
|
/* Go through the bind address list and find the best source address
|
292 |
|
|
* that matches the scope of the destination address.
|
293 |
|
|
*/
|
294 |
|
|
sctp_read_lock(addr_lock);
|
295 |
|
|
list_for_each(pos, &bp->address_list) {
|
296 |
|
|
laddr = list_entry(pos, struct sctp_sockaddr_entry, list);
|
297 |
|
|
if ((laddr->a.sa.sa_family == AF_INET6) &&
|
298 |
|
|
(scope <= sctp_scope(&laddr->a))) {
|
299 |
|
|
bmatchlen = sctp_v6_addr_match_len(daddr, &laddr->a);
|
300 |
|
|
if (!baddr || (matchlen < bmatchlen)) {
|
301 |
|
|
baddr = &laddr->a;
|
302 |
|
|
matchlen = bmatchlen;
|
303 |
|
|
}
|
304 |
|
|
}
|
305 |
|
|
}
|
306 |
|
|
|
307 |
|
|
if (baddr) {
|
308 |
|
|
memcpy(saddr, baddr, sizeof(union sctp_addr));
|
309 |
|
|
SCTP_DEBUG_PRINTK("saddr: "
|
310 |
|
|
"%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
|
311 |
|
|
NIP6(&saddr->v6.sin6_addr));
|
312 |
|
|
} else {
|
313 |
|
|
printk(KERN_ERR "%s: asoc:%p Could not find a valid source "
|
314 |
|
|
"address for the "
|
315 |
|
|
"dest:%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
|
316 |
|
|
__FUNCTION__, asoc, NIP6(&daddr->v6.sin6_addr));
|
317 |
|
|
}
|
318 |
|
|
|
319 |
|
|
sctp_read_unlock(addr_lock);
|
320 |
|
|
}
|
321 |
|
|
|
322 |
|
|
/* Make a copy of all potential local addresses. */
|
323 |
|
|
static void sctp_v6_copy_addrlist(struct list_head *addrlist,
|
324 |
|
|
struct net_device *dev)
|
325 |
|
|
{
|
326 |
|
|
struct inet6_dev *in6_dev;
|
327 |
|
|
struct inet6_ifaddr *ifp;
|
328 |
|
|
struct sctp_sockaddr_entry *addr;
|
329 |
|
|
|
330 |
|
|
read_lock(&addrconf_lock);
|
331 |
|
|
if ((in6_dev = __in6_dev_get(dev)) == NULL) {
|
332 |
|
|
read_unlock(&addrconf_lock);
|
333 |
|
|
return;
|
334 |
|
|
}
|
335 |
|
|
|
336 |
|
|
read_lock(&in6_dev->lock);
|
337 |
|
|
for (ifp = in6_dev->addr_list; ifp; ifp = ifp->if_next) {
|
338 |
|
|
/* Add the address to the local list. */
|
339 |
|
|
addr = t_new(struct sctp_sockaddr_entry, GFP_ATOMIC);
|
340 |
|
|
if (addr) {
|
341 |
|
|
addr->a.v6.sin6_family = AF_INET6;
|
342 |
|
|
addr->a.v6.sin6_port = 0;
|
343 |
|
|
addr->a.v6.sin6_addr = ifp->addr;
|
344 |
|
|
addr->a.v6.sin6_scope_id = dev->ifindex;
|
345 |
|
|
INIT_LIST_HEAD(&addr->list);
|
346 |
|
|
list_add_tail(&addr->list, addrlist);
|
347 |
|
|
}
|
348 |
|
|
}
|
349 |
|
|
|
350 |
|
|
read_unlock(&in6_dev->lock);
|
351 |
|
|
read_unlock(&addrconf_lock);
|
352 |
|
|
}
|
353 |
|
|
|
354 |
|
|
/* Initialize a sockaddr_storage from in incoming skb. */
|
355 |
|
|
static void sctp_v6_from_skb(union sctp_addr *addr,struct sk_buff *skb,
|
356 |
|
|
int is_saddr)
|
357 |
|
|
{
|
358 |
|
|
void *from;
|
359 |
|
|
__u16 *port;
|
360 |
|
|
struct sctphdr *sh;
|
361 |
|
|
|
362 |
|
|
port = &addr->v6.sin6_port;
|
363 |
|
|
addr->v6.sin6_family = AF_INET6;
|
364 |
|
|
addr->v6.sin6_flowinfo = 0; /* FIXME */
|
365 |
|
|
addr->v6.sin6_scope_id = ((struct inet6_skb_parm *)skb->cb)->iif;
|
366 |
|
|
|
367 |
|
|
sh = (struct sctphdr *) skb->h.raw;
|
368 |
|
|
if (is_saddr) {
|
369 |
|
|
*port = ntohs(sh->source);
|
370 |
|
|
from = &skb->nh.ipv6h->saddr;
|
371 |
|
|
} else {
|
372 |
|
|
*port = ntohs(sh->dest);
|
373 |
|
|
from = &skb->nh.ipv6h->daddr;
|
374 |
|
|
}
|
375 |
|
|
ipv6_addr_copy(&addr->v6.sin6_addr, from);
|
376 |
|
|
}
|
377 |
|
|
|
378 |
|
|
/* Initialize an sctp_addr from a socket. */
|
379 |
|
|
static void sctp_v6_from_sk(union sctp_addr *addr, struct sock *sk)
|
380 |
|
|
{
|
381 |
|
|
addr->v6.sin6_family = AF_INET6;
|
382 |
|
|
addr->v6.sin6_port = sk->num;
|
383 |
|
|
addr->v6.sin6_addr = inet6_sk(sk)->rcv_saddr;
|
384 |
|
|
}
|
385 |
|
|
|
386 |
|
|
/* Initialize sk->sk_rcv_saddr from sctp_addr. */
|
387 |
|
|
static void sctp_v6_to_sk_saddr(union sctp_addr *addr, struct sock *sk)
|
388 |
|
|
{
|
389 |
|
|
if (addr->sa.sa_family == AF_INET && sctp_sk(sk)->v4mapped) {
|
390 |
|
|
inet6_sk(sk)->rcv_saddr.s6_addr32[0] = 0;
|
391 |
|
|
inet6_sk(sk)->rcv_saddr.s6_addr32[1] = 0;
|
392 |
|
|
inet6_sk(sk)->rcv_saddr.s6_addr32[2] = htonl(0x0000ffff);
|
393 |
|
|
inet6_sk(sk)->rcv_saddr.s6_addr32[3] =
|
394 |
|
|
addr->v4.sin_addr.s_addr;
|
395 |
|
|
} else {
|
396 |
|
|
inet6_sk(sk)->rcv_saddr = addr->v6.sin6_addr;
|
397 |
|
|
}
|
398 |
|
|
}
|
399 |
|
|
|
400 |
|
|
/* Initialize sk->sk_daddr from sctp_addr. */
|
401 |
|
|
static void sctp_v6_to_sk_daddr(union sctp_addr *addr, struct sock *sk)
|
402 |
|
|
{
|
403 |
|
|
if (addr->sa.sa_family == AF_INET && sctp_sk(sk)->v4mapped) {
|
404 |
|
|
inet6_sk(sk)->daddr.s6_addr32[0] = 0;
|
405 |
|
|
inet6_sk(sk)->daddr.s6_addr32[1] = 0;
|
406 |
|
|
inet6_sk(sk)->daddr.s6_addr32[2] = htonl(0x0000ffff);
|
407 |
|
|
inet6_sk(sk)->daddr.s6_addr32[3] = addr->v4.sin_addr.s_addr;
|
408 |
|
|
} else {
|
409 |
|
|
inet6_sk(sk)->daddr = addr->v6.sin6_addr;
|
410 |
|
|
}
|
411 |
|
|
}
|
412 |
|
|
|
413 |
|
|
/* Initialize a sctp_addr from an address parameter. */
|
414 |
|
|
static void sctp_v6_from_addr_param(union sctp_addr *addr,
|
415 |
|
|
union sctp_addr_param *param,
|
416 |
|
|
__u16 port, int iif)
|
417 |
|
|
{
|
418 |
|
|
addr->v6.sin6_family = AF_INET6;
|
419 |
|
|
addr->v6.sin6_port = port;
|
420 |
|
|
addr->v6.sin6_flowinfo = 0; /* BUG */
|
421 |
|
|
ipv6_addr_copy(&addr->v6.sin6_addr, ¶m->v6.addr);
|
422 |
|
|
addr->v6.sin6_scope_id = iif;
|
423 |
|
|
}
|
424 |
|
|
|
425 |
|
|
/* Initialize an address parameter from a sctp_addr and return the length
|
426 |
|
|
* of the address parameter.
|
427 |
|
|
*/
|
428 |
|
|
static int sctp_v6_to_addr_param(const union sctp_addr *addr,
|
429 |
|
|
union sctp_addr_param *param)
|
430 |
|
|
{
|
431 |
|
|
int length = sizeof(sctp_ipv6addr_param_t);
|
432 |
|
|
|
433 |
|
|
param->v6.param_hdr.type = SCTP_PARAM_IPV6_ADDRESS;
|
434 |
|
|
param->v6.param_hdr.length = ntohs(length);
|
435 |
|
|
ipv6_addr_copy(¶m->v6.addr, &addr->v6.sin6_addr);
|
436 |
|
|
|
437 |
|
|
return length;
|
438 |
|
|
}
|
439 |
|
|
|
440 |
|
|
/* Initialize a sctp_addr from a dst_entry. */
|
441 |
|
|
static void sctp_v6_dst_saddr(union sctp_addr *addr, struct dst_entry *dst,
|
442 |
|
|
unsigned short port)
|
443 |
|
|
{
|
444 |
|
|
struct rt6_info *rt = (struct rt6_info *)dst;
|
445 |
|
|
addr->sa.sa_family = AF_INET6;
|
446 |
|
|
addr->v6.sin6_port = port;
|
447 |
|
|
ipv6_addr_copy(&addr->v6.sin6_addr, &rt->rt6i_src.addr);
|
448 |
|
|
}
|
449 |
|
|
|
450 |
|
|
/* Compare addresses exactly.
|
451 |
|
|
* v4-mapped-v6 is also in consideration.
|
452 |
|
|
*/
|
453 |
|
|
static int sctp_v6_cmp_addr(const union sctp_addr *addr1,
|
454 |
|
|
const union sctp_addr *addr2)
|
455 |
|
|
{
|
456 |
|
|
if (addr1->sa.sa_family != addr2->sa.sa_family) {
|
457 |
|
|
if (addr1->sa.sa_family == AF_INET &&
|
458 |
|
|
addr2->sa.sa_family == AF_INET6 &&
|
459 |
|
|
IPV6_ADDR_MAPPED == ipv6_addr_type(&addr2->v6.sin6_addr)) {
|
460 |
|
|
if (addr2->v6.sin6_port == addr1->v4.sin_port &&
|
461 |
|
|
addr2->v6.sin6_addr.s6_addr32[3] ==
|
462 |
|
|
addr1->v4.sin_addr.s_addr)
|
463 |
|
|
return 1;
|
464 |
|
|
}
|
465 |
|
|
if (addr2->sa.sa_family == AF_INET &&
|
466 |
|
|
addr1->sa.sa_family == AF_INET6 &&
|
467 |
|
|
IPV6_ADDR_MAPPED == ipv6_addr_type(&addr1->v6.sin6_addr)) {
|
468 |
|
|
if (addr1->v6.sin6_port == addr2->v4.sin_port &&
|
469 |
|
|
addr1->v6.sin6_addr.s6_addr32[3] ==
|
470 |
|
|
addr2->v4.sin_addr.s_addr)
|
471 |
|
|
return 1;
|
472 |
|
|
}
|
473 |
|
|
return 0;
|
474 |
|
|
}
|
475 |
|
|
if (ipv6_addr_cmp(&addr1->v6.sin6_addr, &addr2->v6.sin6_addr))
|
476 |
|
|
return 0;
|
477 |
|
|
/* If this is a linklocal address, compare the scope_id. */
|
478 |
|
|
if (ipv6_addr_type(&addr1->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL) {
|
479 |
|
|
if (addr1->v6.sin6_scope_id && addr2->v6.sin6_scope_id &&
|
480 |
|
|
(addr1->v6.sin6_scope_id != addr2->v6.sin6_scope_id)) {
|
481 |
|
|
return 0;
|
482 |
|
|
}
|
483 |
|
|
}
|
484 |
|
|
|
485 |
|
|
return 1;
|
486 |
|
|
}
|
487 |
|
|
|
488 |
|
|
/* Initialize addr struct to INADDR_ANY. */
|
489 |
|
|
static void sctp_v6_inaddr_any(union sctp_addr *addr, unsigned short port)
|
490 |
|
|
{
|
491 |
|
|
memset(addr, 0x00, sizeof(union sctp_addr));
|
492 |
|
|
addr->v6.sin6_family = AF_INET6;
|
493 |
|
|
addr->v6.sin6_port = port;
|
494 |
|
|
}
|
495 |
|
|
|
496 |
|
|
/* Is this a wildcard address? */
|
497 |
|
|
static int sctp_v6_is_any(const union sctp_addr *addr)
|
498 |
|
|
{
|
499 |
|
|
int type;
|
500 |
|
|
type = ipv6_addr_type((struct in6_addr *)&addr->v6.sin6_addr);
|
501 |
|
|
return IPV6_ADDR_ANY == type;
|
502 |
|
|
}
|
503 |
|
|
|
504 |
|
|
/* Should this be available for binding? */
|
505 |
|
|
static int sctp_v6_available(union sctp_addr *addr, struct sctp_opt *sp)
|
506 |
|
|
{
|
507 |
|
|
int type;
|
508 |
|
|
struct in6_addr *in6 = (struct in6_addr *)&addr->v6.sin6_addr;
|
509 |
|
|
|
510 |
|
|
type = ipv6_addr_type(in6);
|
511 |
|
|
if (IPV6_ADDR_ANY == type)
|
512 |
|
|
return 1;
|
513 |
|
|
if (type == IPV6_ADDR_MAPPED) {
|
514 |
|
|
if (sp && !sp->v4mapped)
|
515 |
|
|
return 0;
|
516 |
|
|
if (sp && ipv6_only_sock(sctp_opt2sk(sp)))
|
517 |
|
|
return 0;
|
518 |
|
|
sctp_v6_map_v4(addr);
|
519 |
|
|
return sctp_get_af_specific(AF_INET)->available(addr, sp);
|
520 |
|
|
}
|
521 |
|
|
if (!(type & IPV6_ADDR_UNICAST))
|
522 |
|
|
return 0;
|
523 |
|
|
|
524 |
|
|
return ipv6_chk_addr(in6, NULL);
|
525 |
|
|
}
|
526 |
|
|
|
527 |
|
|
/* This function checks if the address is a valid address to be used for
|
528 |
|
|
* SCTP.
|
529 |
|
|
*
|
530 |
|
|
* Output:
|
531 |
|
|
* Return 0 - If the address is a non-unicast or an illegal address.
|
532 |
|
|
* Return 1 - If the address is a unicast.
|
533 |
|
|
*/
|
534 |
|
|
static int sctp_v6_addr_valid(union sctp_addr *addr, struct sctp_opt *sp)
|
535 |
|
|
{
|
536 |
|
|
int ret = ipv6_addr_type(&addr->v6.sin6_addr);
|
537 |
|
|
|
538 |
|
|
/* Support v4-mapped-v6 address. */
|
539 |
|
|
if (ret == IPV6_ADDR_MAPPED) {
|
540 |
|
|
/* Note: This routine is used in input, so v4-mapped-v6
|
541 |
|
|
* are disallowed here when there is no sctp_opt.
|
542 |
|
|
*/
|
543 |
|
|
if (!sp || !sp->v4mapped)
|
544 |
|
|
return 0;
|
545 |
|
|
if (sp && ipv6_only_sock(sctp_opt2sk(sp)))
|
546 |
|
|
return 0;
|
547 |
|
|
sctp_v6_map_v4(addr);
|
548 |
|
|
return sctp_get_af_specific(AF_INET)->addr_valid(addr, sp);
|
549 |
|
|
}
|
550 |
|
|
|
551 |
|
|
/* Is this a non-unicast address */
|
552 |
|
|
if (!(ret & IPV6_ADDR_UNICAST))
|
553 |
|
|
return 0;
|
554 |
|
|
|
555 |
|
|
return 1;
|
556 |
|
|
}
|
557 |
|
|
|
558 |
|
|
/* What is the scope of 'addr'? */
|
559 |
|
|
static sctp_scope_t sctp_v6_scope(union sctp_addr *addr)
|
560 |
|
|
{
|
561 |
|
|
int v6scope;
|
562 |
|
|
sctp_scope_t retval;
|
563 |
|
|
|
564 |
|
|
/* The IPv6 scope is really a set of bit fields.
|
565 |
|
|
* See IFA_* in <net/if_inet6.h>. Map to a generic SCTP scope.
|
566 |
|
|
*/
|
567 |
|
|
|
568 |
|
|
v6scope = ipv6_addr_scope(&addr->v6.sin6_addr);
|
569 |
|
|
switch (v6scope) {
|
570 |
|
|
case IFA_HOST:
|
571 |
|
|
retval = SCTP_SCOPE_LOOPBACK;
|
572 |
|
|
break;
|
573 |
|
|
case IFA_LINK:
|
574 |
|
|
retval = SCTP_SCOPE_LINK;
|
575 |
|
|
break;
|
576 |
|
|
case IFA_SITE:
|
577 |
|
|
retval = SCTP_SCOPE_PRIVATE;
|
578 |
|
|
break;
|
579 |
|
|
default:
|
580 |
|
|
retval = SCTP_SCOPE_GLOBAL;
|
581 |
|
|
break;
|
582 |
|
|
};
|
583 |
|
|
|
584 |
|
|
return retval;
|
585 |
|
|
}
|
586 |
|
|
|
587 |
|
|
/* Create and initialize a new sk for the socket to be returned by accept(). */
|
588 |
|
|
struct sock *sctp_v6_create_accept_sk(struct sock *sk,
|
589 |
|
|
struct sctp_association *asoc)
|
590 |
|
|
{
|
591 |
|
|
struct sock *newsk;
|
592 |
|
|
struct inet_opt *newinet;
|
593 |
|
|
struct ipv6_pinfo *newnp, *np = inet6_sk(sk);
|
594 |
|
|
|
595 |
|
|
newsk = sk_alloc(PF_INET6, GFP_KERNEL, sizeof(struct sock));
|
596 |
|
|
if (!newsk)
|
597 |
|
|
goto out;
|
598 |
|
|
|
599 |
|
|
sock_init_data(NULL, newsk);
|
600 |
|
|
sk_set_owner(newsk, THIS_MODULE);
|
601 |
|
|
|
602 |
|
|
newsk->sk_type = SOCK_STREAM;
|
603 |
|
|
|
604 |
|
|
newsk->sk_prot = sk->sk_prot;
|
605 |
|
|
newsk->sk_no_check = sk->sk_no_check;
|
606 |
|
|
newsk->sk_reuse = sk->sk_reuse;
|
607 |
|
|
|
608 |
|
|
newsk->sk_destruct = inet_sock_destruct;
|
609 |
|
|
newsk->sk_zapped = 0;
|
610 |
|
|
newsk->sk_family = PF_INET6;
|
611 |
|
|
newsk->sk_protocol = IPPROTO_SCTP;
|
612 |
|
|
newsk->sk_backlog_rcv = sk->sk_prot->backlog_rcv;
|
613 |
|
|
newsk->sk_shutdown = sk->sk_shutdown;
|
614 |
|
|
|
615 |
|
|
newinet = inet_sk(newsk);
|
616 |
|
|
newnp = inet6_sk(newsk);
|
617 |
|
|
|
618 |
|
|
memcpy(newnp, np, sizeof(struct ipv6_pinfo));
|
619 |
|
|
|
620 |
|
|
/* Initialize sk's sport, dport, rcv_saddr and daddr for getsockname()
|
621 |
|
|
* and getpeername().
|
622 |
|
|
*/
|
623 |
|
|
newsk->sport = sk->sport;
|
624 |
|
|
newsk->saddr = sk->saddr;
|
625 |
|
|
newnp->rcv_saddr = np->rcv_saddr;
|
626 |
|
|
newsk->dport = htons(asoc->peer.port);
|
627 |
|
|
sctp_v6_to_sk_daddr(&asoc->peer.primary_addr, newsk);
|
628 |
|
|
|
629 |
|
|
/* Init the ipv4 part of the socket since we can have sockets
|
630 |
|
|
* using v6 API for ipv4.
|
631 |
|
|
*/
|
632 |
|
|
newinet->ttl = sysctl_ip_default_ttl;
|
633 |
|
|
newinet->mc_loop = 1;
|
634 |
|
|
newinet->mc_ttl = 1;
|
635 |
|
|
newinet->mc_index = 0;
|
636 |
|
|
newinet->mc_list = NULL;
|
637 |
|
|
|
638 |
|
|
if (ipv4_config.no_pmtu_disc)
|
639 |
|
|
newinet->pmtudisc = IP_PMTUDISC_DONT;
|
640 |
|
|
else
|
641 |
|
|
newinet->pmtudisc = IP_PMTUDISC_WANT;
|
642 |
|
|
|
643 |
|
|
#ifdef INET_REFCNT_DEBUG
|
644 |
|
|
atomic_inc(&inet6_sock_nr);
|
645 |
|
|
atomic_inc(&inet_sock_nr);
|
646 |
|
|
#endif
|
647 |
|
|
|
648 |
|
|
if (newsk->sk_prot->init(newsk)) {
|
649 |
|
|
inet_sock_release(newsk);
|
650 |
|
|
newsk = NULL;
|
651 |
|
|
}
|
652 |
|
|
|
653 |
|
|
out:
|
654 |
|
|
return newsk;
|
655 |
|
|
}
|
656 |
|
|
|
657 |
|
|
/* Map v4 address to mapped v6 address */
|
658 |
|
|
static void sctp_v6_addr_v4map(struct sctp_opt *sp, union sctp_addr *addr)
|
659 |
|
|
{
|
660 |
|
|
if (sp->v4mapped && AF_INET == addr->sa.sa_family)
|
661 |
|
|
sctp_v4_map_v6(addr);
|
662 |
|
|
}
|
663 |
|
|
|
664 |
|
|
/* Where did this skb come from? */
|
665 |
|
|
static int sctp_v6_skb_iif(const struct sk_buff *skb)
|
666 |
|
|
{
|
667 |
|
|
struct inet6_skb_parm *opt = (struct inet6_skb_parm *) skb->cb;
|
668 |
|
|
return opt->iif;
|
669 |
|
|
}
|
670 |
|
|
|
671 |
|
|
/* Was this packet marked by Explicit Congestion Notification? */
|
672 |
|
|
static int sctp_v6_is_ce(const struct sk_buff *skb)
|
673 |
|
|
{
|
674 |
|
|
return *((__u32 *)(skb->nh.ipv6h)) & htonl(1<<20);
|
675 |
|
|
}
|
676 |
|
|
|
677 |
|
|
/* Dump the v6 addr to the seq file. */
|
678 |
|
|
static void sctp_v6_seq_dump_addr(struct seq_file *seq, union sctp_addr *addr)
|
679 |
|
|
{
|
680 |
|
|
seq_printf(seq, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ",
|
681 |
|
|
NIP6(&addr->v6.sin6_addr));
|
682 |
|
|
}
|
683 |
|
|
|
684 |
|
|
/* Initialize a PF_INET6 socket msg_name. */
|
685 |
|
|
static void sctp_inet6_msgname(char *msgname, int *addr_len)
|
686 |
|
|
{
|
687 |
|
|
struct sockaddr_in6 *sin6;
|
688 |
|
|
|
689 |
|
|
sin6 = (struct sockaddr_in6 *)msgname;
|
690 |
|
|
sin6->sin6_family = AF_INET6;
|
691 |
|
|
sin6->sin6_flowinfo = 0;
|
692 |
|
|
sin6->sin6_scope_id = 0; /*FIXME */
|
693 |
|
|
*addr_len = sizeof(struct sockaddr_in6);
|
694 |
|
|
}
|
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 |
|
|
struct sockaddr_in6 *sin6, *sin6from;
|
701 |
|
|
|
702 |
|
|
if (msgname) {
|
703 |
|
|
union sctp_addr *addr;
|
704 |
|
|
struct sctp_association *asoc;
|
705 |
|
|
|
706 |
|
|
asoc = event->sndrcvinfo.sinfo_assoc_id;
|
707 |
|
|
sctp_inet6_msgname(msgname, addrlen);
|
708 |
|
|
sin6 = (struct sockaddr_in6 *)msgname;
|
709 |
|
|
sin6->sin6_port = htons(asoc->peer.port);
|
710 |
|
|
addr = &asoc->peer.primary_addr;
|
711 |
|
|
|
712 |
|
|
/* Note: If we go to a common v6 format, this code
|
713 |
|
|
* will change.
|
714 |
|
|
*/
|
715 |
|
|
|
716 |
|
|
/* Map ipv4 address into v4-mapped-on-v6 address. */
|
717 |
|
|
if (sctp_sk(asoc->base.sk)->v4mapped &&
|
718 |
|
|
AF_INET == addr->sa.sa_family) {
|
719 |
|
|
sctp_v4_map_v6((union sctp_addr *)sin6);
|
720 |
|
|
sin6->sin6_addr.s6_addr32[3] =
|
721 |
|
|
addr->v4.sin_addr.s_addr;
|
722 |
|
|
return;
|
723 |
|
|
}
|
724 |
|
|
|
725 |
|
|
sin6from = &asoc->peer.primary_addr.v6;
|
726 |
|
|
ipv6_addr_copy(&sin6->sin6_addr, &sin6from->sin6_addr);
|
727 |
|
|
if (ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL)
|
728 |
|
|
sin6->sin6_scope_id = sin6from->sin6_scope_id;
|
729 |
|
|
}
|
730 |
|
|
}
|
731 |
|
|
|
732 |
|
|
/* Initialize a msg_name from an inbound skb. */
|
733 |
|
|
static void sctp_inet6_skb_msgname(struct sk_buff *skb, char *msgname,
|
734 |
|
|
int *addr_len)
|
735 |
|
|
{
|
736 |
|
|
struct sctphdr *sh;
|
737 |
|
|
struct sockaddr_in6 *sin6;
|
738 |
|
|
|
739 |
|
|
if (msgname) {
|
740 |
|
|
sctp_inet6_msgname(msgname, addr_len);
|
741 |
|
|
sin6 = (struct sockaddr_in6 *)msgname;
|
742 |
|
|
sh = (struct sctphdr *)skb->h.raw;
|
743 |
|
|
sin6->sin6_port = sh->source;
|
744 |
|
|
|
745 |
|
|
/* Map ipv4 address into v4-mapped-on-v6 address. */
|
746 |
|
|
if (sctp_sk(skb->sk)->v4mapped &&
|
747 |
|
|
skb->nh.iph->version == 4) {
|
748 |
|
|
sctp_v4_map_v6((union sctp_addr *)sin6);
|
749 |
|
|
sin6->sin6_addr.s6_addr32[3] = skb->nh.iph->saddr;
|
750 |
|
|
return;
|
751 |
|
|
}
|
752 |
|
|
|
753 |
|
|
/* Otherwise, just copy the v6 address. */
|
754 |
|
|
ipv6_addr_copy(&sin6->sin6_addr, &skb->nh.ipv6h->saddr);
|
755 |
|
|
if (ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL) {
|
756 |
|
|
struct sctp_ulpevent *ev = sctp_skb2event(skb);
|
757 |
|
|
sin6->sin6_scope_id = ev->iif;
|
758 |
|
|
}
|
759 |
|
|
}
|
760 |
|
|
}
|
761 |
|
|
|
762 |
|
|
/* Do we support this AF? */
|
763 |
|
|
static int sctp_inet6_af_supported(sa_family_t family, struct sctp_opt *sp)
|
764 |
|
|
{
|
765 |
|
|
switch (family) {
|
766 |
|
|
case AF_INET6:
|
767 |
|
|
return 1;
|
768 |
|
|
/* v4-mapped-v6 addresses */
|
769 |
|
|
case AF_INET:
|
770 |
|
|
if (!__ipv6_only_sock(sctp_opt2sk(sp)) && sp->v4mapped)
|
771 |
|
|
return 1;
|
772 |
|
|
default:
|
773 |
|
|
return 0;
|
774 |
|
|
}
|
775 |
|
|
}
|
776 |
|
|
|
777 |
|
|
/* Address matching with wildcards allowed. This extra level
|
778 |
|
|
* of indirection lets us choose whether a PF_INET6 should
|
779 |
|
|
* disallow any v4 addresses if we so choose.
|
780 |
|
|
*/
|
781 |
|
|
static int sctp_inet6_cmp_addr(const union sctp_addr *addr1,
|
782 |
|
|
const union sctp_addr *addr2,
|
783 |
|
|
struct sctp_opt *opt)
|
784 |
|
|
{
|
785 |
|
|
struct sctp_af *af1, *af2;
|
786 |
|
|
|
787 |
|
|
af1 = sctp_get_af_specific(addr1->sa.sa_family);
|
788 |
|
|
af2 = sctp_get_af_specific(addr2->sa.sa_family);
|
789 |
|
|
|
790 |
|
|
if (!af1 || !af2)
|
791 |
|
|
return 0;
|
792 |
|
|
/* Today, wildcard AF_INET/AF_INET6. */
|
793 |
|
|
if (sctp_is_any(addr1) || sctp_is_any(addr2))
|
794 |
|
|
return 1;
|
795 |
|
|
|
796 |
|
|
if (addr1->sa.sa_family != addr2->sa.sa_family)
|
797 |
|
|
return 0;
|
798 |
|
|
|
799 |
|
|
return af1->cmp_addr(addr1, addr2);
|
800 |
|
|
}
|
801 |
|
|
|
802 |
|
|
/* Verify that the provided sockaddr looks bindable. Common verification,
|
803 |
|
|
* has already been taken care of.
|
804 |
|
|
*/
|
805 |
|
|
static int sctp_inet6_bind_verify(struct sctp_opt *opt, union sctp_addr *addr)
|
806 |
|
|
{
|
807 |
|
|
struct sctp_af *af;
|
808 |
|
|
|
809 |
|
|
/* ASSERT: address family has already been verified. */
|
810 |
|
|
if (addr->sa.sa_family != AF_INET6)
|
811 |
|
|
af = sctp_get_af_specific(addr->sa.sa_family);
|
812 |
|
|
else {
|
813 |
|
|
struct sock *sk;
|
814 |
|
|
int type = ipv6_addr_type(&addr->v6.sin6_addr);
|
815 |
|
|
sk = sctp_opt2sk(opt);
|
816 |
|
|
if (type & IPV6_ADDR_LINKLOCAL) {
|
817 |
|
|
/* Note: Behavior similar to af_inet6.c:
|
818 |
|
|
* 1) Overrides previous bound_dev_if
|
819 |
|
|
* 2) Destructive even if bind isn't successful.
|
820 |
|
|
*/
|
821 |
|
|
|
822 |
|
|
if (addr->v6.sin6_scope_id)
|
823 |
|
|
sk->sk_bound_dev_if = addr->v6.sin6_scope_id;
|
824 |
|
|
if (!sk->sk_bound_dev_if)
|
825 |
|
|
return 0;
|
826 |
|
|
}
|
827 |
|
|
af = opt->pf->af;
|
828 |
|
|
}
|
829 |
|
|
return af->available(addr, opt);
|
830 |
|
|
}
|
831 |
|
|
|
832 |
|
|
/* Verify that the provided sockaddr looks bindable. Common verification,
|
833 |
|
|
* has already been taken care of.
|
834 |
|
|
*/
|
835 |
|
|
static int sctp_inet6_send_verify(struct sctp_opt *opt, union sctp_addr *addr)
|
836 |
|
|
{
|
837 |
|
|
struct sctp_af *af = NULL;
|
838 |
|
|
|
839 |
|
|
/* ASSERT: address family has already been verified. */
|
840 |
|
|
if (addr->sa.sa_family != AF_INET6)
|
841 |
|
|
af = sctp_get_af_specific(addr->sa.sa_family);
|
842 |
|
|
else {
|
843 |
|
|
struct sock *sk;
|
844 |
|
|
int type = ipv6_addr_type(&addr->v6.sin6_addr);
|
845 |
|
|
sk = sctp_opt2sk(opt);
|
846 |
|
|
if (type & IPV6_ADDR_LINKLOCAL) {
|
847 |
|
|
/* Note: Behavior similar to af_inet6.c:
|
848 |
|
|
* 1) Overrides previous bound_dev_if
|
849 |
|
|
* 2) Destructive even if bind isn't successful.
|
850 |
|
|
*/
|
851 |
|
|
|
852 |
|
|
if (addr->v6.sin6_scope_id)
|
853 |
|
|
sk->sk_bound_dev_if = addr->v6.sin6_scope_id;
|
854 |
|
|
if (!sk->sk_bound_dev_if)
|
855 |
|
|
return 0;
|
856 |
|
|
}
|
857 |
|
|
af = opt->pf->af;
|
858 |
|
|
}
|
859 |
|
|
|
860 |
|
|
return af != NULL;
|
861 |
|
|
}
|
862 |
|
|
|
863 |
|
|
/* Fill in Supported Address Type information for INIT and INIT-ACK
|
864 |
|
|
* chunks. Note: In the future, we may want to look at sock options
|
865 |
|
|
* to determine whether a PF_INET6 socket really wants to have IPV4
|
866 |
|
|
* addresses.
|
867 |
|
|
* Returns number of addresses supported.
|
868 |
|
|
*/
|
869 |
|
|
static int sctp_inet6_supported_addrs(const struct sctp_opt *opt,
|
870 |
|
|
__u16 *types)
|
871 |
|
|
{
|
872 |
|
|
types[0] = SCTP_PARAM_IPV4_ADDRESS;
|
873 |
|
|
types[1] = SCTP_PARAM_IPV6_ADDRESS;
|
874 |
|
|
return 2;
|
875 |
|
|
}
|
876 |
|
|
|
877 |
|
|
static struct proto_ops inet6_seqpacket_ops = {
|
878 |
|
|
.family = PF_INET6,
|
879 |
|
|
.release = inet6_release,
|
880 |
|
|
.bind = inet6_bind,
|
881 |
|
|
.connect = inet_dgram_connect,
|
882 |
|
|
.socketpair = sock_no_socketpair,
|
883 |
|
|
.accept = inet_accept,
|
884 |
|
|
.getname = inet6_getname,
|
885 |
|
|
.poll = sctp_poll,
|
886 |
|
|
.ioctl = inet6_ioctl,
|
887 |
|
|
.listen = sctp_inet_listen,
|
888 |
|
|
.shutdown = inet_shutdown,
|
889 |
|
|
.setsockopt = inet_setsockopt,
|
890 |
|
|
.getsockopt = inet_getsockopt,
|
891 |
|
|
.sendmsg = inet_sendmsg,
|
892 |
|
|
.recvmsg = inet_recvmsg,
|
893 |
|
|
.mmap = sock_no_mmap,
|
894 |
|
|
};
|
895 |
|
|
|
896 |
|
|
static struct inet_protosw sctpv6_seqpacket_protosw = {
|
897 |
|
|
.type = SOCK_SEQPACKET,
|
898 |
|
|
.protocol = IPPROTO_SCTP,
|
899 |
|
|
.prot = &sctp_prot,
|
900 |
|
|
.ops = &inet6_seqpacket_ops,
|
901 |
|
|
.capability = -1,
|
902 |
|
|
.no_check = 0,
|
903 |
|
|
.flags = SCTP_PROTOSW_FLAG
|
904 |
|
|
};
|
905 |
|
|
static struct inet_protosw sctpv6_stream_protosw = {
|
906 |
|
|
.type = SOCK_STREAM,
|
907 |
|
|
.protocol = IPPROTO_SCTP,
|
908 |
|
|
.prot = &sctp_prot,
|
909 |
|
|
.ops = &inet6_seqpacket_ops,
|
910 |
|
|
.capability = -1,
|
911 |
|
|
.no_check = 0,
|
912 |
|
|
.flags = SCTP_PROTOSW_FLAG,
|
913 |
|
|
};
|
914 |
|
|
|
915 |
|
|
static struct inet6_protocol sctpv6_protocol = {
|
916 |
|
|
.handler = sctp_rcv,
|
917 |
|
|
.err_handler = sctp_v6_err,
|
918 |
|
|
.next = NULL,
|
919 |
|
|
.protocol = IPPROTO_SCTP,
|
920 |
|
|
.copy = 0,
|
921 |
|
|
.data = NULL,
|
922 |
|
|
.name = "SCTPv6",
|
923 |
|
|
};
|
924 |
|
|
|
925 |
|
|
static struct sctp_af sctp_ipv6_specific = {
|
926 |
|
|
.sctp_xmit = sctp_v6_xmit,
|
927 |
|
|
.setsockopt = ipv6_setsockopt,
|
928 |
|
|
.getsockopt = ipv6_getsockopt,
|
929 |
|
|
.get_dst = sctp_v6_get_dst,
|
930 |
|
|
.get_saddr = sctp_v6_get_saddr,
|
931 |
|
|
.copy_addrlist = sctp_v6_copy_addrlist,
|
932 |
|
|
.from_skb = sctp_v6_from_skb,
|
933 |
|
|
.from_sk = sctp_v6_from_sk,
|
934 |
|
|
.to_sk_saddr = sctp_v6_to_sk_saddr,
|
935 |
|
|
.to_sk_daddr = sctp_v6_to_sk_daddr,
|
936 |
|
|
.from_addr_param = sctp_v6_from_addr_param,
|
937 |
|
|
.to_addr_param = sctp_v6_to_addr_param,
|
938 |
|
|
.dst_saddr = sctp_v6_dst_saddr,
|
939 |
|
|
.cmp_addr = sctp_v6_cmp_addr,
|
940 |
|
|
.scope = sctp_v6_scope,
|
941 |
|
|
.addr_valid = sctp_v6_addr_valid,
|
942 |
|
|
.inaddr_any = sctp_v6_inaddr_any,
|
943 |
|
|
.is_any = sctp_v6_is_any,
|
944 |
|
|
.available = sctp_v6_available,
|
945 |
|
|
.skb_iif = sctp_v6_skb_iif,
|
946 |
|
|
.is_ce = sctp_v6_is_ce,
|
947 |
|
|
.seq_dump_addr = sctp_v6_seq_dump_addr,
|
948 |
|
|
.net_header_len = sizeof(struct ipv6hdr),
|
949 |
|
|
.sockaddr_len = sizeof(struct sockaddr_in6),
|
950 |
|
|
.sa_family = AF_INET6,
|
951 |
|
|
};
|
952 |
|
|
|
953 |
|
|
static struct sctp_pf sctp_pf_inet6_specific = {
|
954 |
|
|
.event_msgname = sctp_inet6_event_msgname,
|
955 |
|
|
.skb_msgname = sctp_inet6_skb_msgname,
|
956 |
|
|
.af_supported = sctp_inet6_af_supported,
|
957 |
|
|
.cmp_addr = sctp_inet6_cmp_addr,
|
958 |
|
|
.bind_verify = sctp_inet6_bind_verify,
|
959 |
|
|
.send_verify = sctp_inet6_send_verify,
|
960 |
|
|
.supported_addrs = sctp_inet6_supported_addrs,
|
961 |
|
|
.create_accept_sk = sctp_v6_create_accept_sk,
|
962 |
|
|
.addr_v4map = sctp_v6_addr_v4map,
|
963 |
|
|
.af = &sctp_ipv6_specific,
|
964 |
|
|
};
|
965 |
|
|
|
966 |
|
|
/* Initialize IPv6 support and register with inet6 stack. */
|
967 |
|
|
int sctp_v6_init(void)
|
968 |
|
|
{
|
969 |
|
|
/* Register inet6 protocol. */
|
970 |
|
|
inet6_add_protocol(&sctpv6_protocol);
|
971 |
|
|
|
972 |
|
|
/* Add SCTPv6(UDP and TCP style) to inetsw6 linked list. */
|
973 |
|
|
inet6_register_protosw(&sctpv6_seqpacket_protosw);
|
974 |
|
|
inet6_register_protosw(&sctpv6_stream_protosw);
|
975 |
|
|
|
976 |
|
|
/* Register the SCTP specific PF_INET6 functions. */
|
977 |
|
|
sctp_register_pf(&sctp_pf_inet6_specific, PF_INET6);
|
978 |
|
|
|
979 |
|
|
/* Register the SCTP specific AF_INET6 functions. */
|
980 |
|
|
sctp_register_af(&sctp_ipv6_specific);
|
981 |
|
|
|
982 |
|
|
/* Register notifier for inet6 address additions/deletions. */
|
983 |
|
|
register_inet6addr_notifier(&sctp_inetaddr_notifier);
|
984 |
|
|
|
985 |
|
|
return 0;
|
986 |
|
|
}
|
987 |
|
|
|
988 |
|
|
/* IPv6 specific exit support. */
|
989 |
|
|
void sctp_v6_exit(void)
|
990 |
|
|
{
|
991 |
|
|
list_del(&sctp_ipv6_specific.list);
|
992 |
|
|
inet6_del_protocol(&sctpv6_protocol);
|
993 |
|
|
inet6_unregister_protosw(&sctpv6_seqpacket_protosw);
|
994 |
|
|
inet6_unregister_protosw(&sctpv6_stream_protosw);
|
995 |
|
|
unregister_inet6addr_notifier(&sctp_inetaddr_notifier);
|
996 |
|
|
}
|