Blame view
net/ipv6/datagram.c
24.7 KB
2874c5fd2 treewide: Replace... |
1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
1da177e4c Linux-2.6.12-rc2 |
2 3 |
/* * common UDP/RAW code |
1ab1457c4 [NET] IPV6: Fix w... |
4 |
* Linux INET6 implementation |
1da177e4c Linux-2.6.12-rc2 |
5 6 |
* * Authors: |
1ab1457c4 [NET] IPV6: Fix w... |
7 |
* Pedro Roque <roque@di.fc.ul.pt> |
1da177e4c Linux-2.6.12-rc2 |
8 |
*/ |
4fc268d24 [PATCH] capable/c... |
9 |
#include <linux/capability.h> |
1da177e4c Linux-2.6.12-rc2 |
10 11 12 |
#include <linux/errno.h> #include <linux/types.h> #include <linux/kernel.h> |
1da177e4c Linux-2.6.12-rc2 |
13 14 15 16 17 18 |
#include <linux/interrupt.h> #include <linux/socket.h> #include <linux/sockios.h> #include <linux/in6.h> #include <linux/ipv6.h> #include <linux/route.h> |
5a0e3ad6a include cleanup: ... |
19 |
#include <linux/slab.h> |
a495f8364 ipv6: Export ipv6... |
20 |
#include <linux/export.h> |
1da177e4c Linux-2.6.12-rc2 |
21 22 23 24 25 26 |
#include <net/ipv6.h> #include <net/ndisc.h> #include <net/addrconf.h> #include <net/transp_v6.h> #include <net/ip6_route.h> |
c752f0739 [TCP]: Move the t... |
27 |
#include <net/tcp_states.h> |
e7219858a ipv6: Use ipv6_ge... |
28 |
#include <net/dsfield.h> |
acdcecc61 udp: correct reus... |
29 |
#include <net/sock_reuseport.h> |
1da177e4c Linux-2.6.12-rc2 |
30 31 |
#include <linux/errqueue.h> |
7c0f6ba68 Replace <asm/uacc... |
32 |
#include <linux/uaccess.h> |
1da177e4c Linux-2.6.12-rc2 |
33 |
|
a50feda54 ipv6: bool/const ... |
34 |
static bool ipv6_mapped_addr_any(const struct in6_addr *a) |
c15fea2d8 ipv6: check for I... |
35 |
{ |
a50feda54 ipv6: bool/const ... |
36 |
return ipv6_addr_v4mapped(a) && (a->s6_addr32[3] == 0); |
c15fea2d8 ipv6: check for I... |
37 |
} |
80fbdb208 ipv6: datagram: R... |
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
static void ip6_datagram_flow_key_init(struct flowi6 *fl6, struct sock *sk) { struct inet_sock *inet = inet_sk(sk); struct ipv6_pinfo *np = inet6_sk(sk); memset(fl6, 0, sizeof(*fl6)); fl6->flowi6_proto = sk->sk_protocol; fl6->daddr = sk->sk_v6_daddr; fl6->saddr = np->saddr; fl6->flowi6_oif = sk->sk_bound_dev_if; fl6->flowi6_mark = sk->sk_mark; fl6->fl6_dport = inet->inet_dport; fl6->fl6_sport = inet->inet_sport; fl6->flowlabel = np->flow_label; |
e2d118a1c net: inet: Suppor... |
52 |
fl6->flowi6_uid = sk->sk_uid; |
80fbdb208 ipv6: datagram: R... |
53 54 55 56 57 58 59 60 61 |
if (!fl6->flowi6_oif) fl6->flowi6_oif = np->sticky_pktinfo.ipi6_ifindex; if (!fl6->flowi6_oif && ipv6_addr_is_multicast(&fl6->daddr)) fl6->flowi6_oif = np->mcast_oif; security_sk_classify_flow(sk, flowi6_to_flowi(fl6)); } |
33c162a98 ipv6: datagram: U... |
62 |
int ip6_datagram_dst_update(struct sock *sk, bool fix_sk_saddr) |
7e2040db1 ipv6: datagram: R... |
63 64 65 66 67 68 69 70 71 72 73 74 |
{ struct ip6_flowlabel *flowlabel = NULL; struct in6_addr *final_p, final; struct ipv6_txoptions *opt; struct dst_entry *dst; struct inet_sock *inet = inet_sk(sk); struct ipv6_pinfo *np = inet6_sk(sk); struct flowi6 fl6; int err = 0; if (np->sndflow && (np->flow_label & IPV6_FLOWLABEL_MASK)) { flowlabel = fl6_sock_lookup(sk, np->flow_label); |
8975a3abc ipv6: fix potenti... |
75 |
if (IS_ERR(flowlabel)) |
7e2040db1 ipv6: datagram: R... |
76 77 78 79 80 81 82 83 |
return -EINVAL; } ip6_datagram_flow_key_init(&fl6, sk); rcu_read_lock(); opt = flowlabel ? flowlabel->opt : rcu_dereference(np->opt); final_p = fl6_update_dst(&fl6, opt, &final); rcu_read_unlock(); |
8cadbd146 net: ipv6: add ne... |
84 |
dst = ip6_dst_lookup_flow(sock_net(sk), sk, &fl6, final_p); |
7e2040db1 ipv6: datagram: R... |
85 86 87 88 |
if (IS_ERR(dst)) { err = PTR_ERR(dst); goto out; } |
33c162a98 ipv6: datagram: U... |
89 90 91 |
if (fix_sk_saddr) { if (ipv6_addr_any(&np->saddr)) np->saddr = fl6.saddr; |
7e2040db1 ipv6: datagram: R... |
92 |
|
33c162a98 ipv6: datagram: U... |
93 94 95 96 97 98 |
if (ipv6_addr_any(&sk->sk_v6_rcv_saddr)) { sk->sk_v6_rcv_saddr = fl6.saddr; inet->inet_rcv_saddr = LOOPBACK4_IPV6; if (sk->sk_prot->rehash) sk->sk_prot->rehash(sk); } |
7e2040db1 ipv6: datagram: R... |
99 |
} |
7d6850f7c ipv6: add a wrapp... |
100 |
ip6_sk_dst_store_flow(sk, dst, &fl6); |
7e2040db1 ipv6: datagram: R... |
101 102 103 104 105 |
out: fl6_sock_release(flowlabel); return err; } |
e646b657f ipv6: udp: Do a r... |
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
void ip6_datagram_release_cb(struct sock *sk) { struct dst_entry *dst; if (ipv6_addr_v4mapped(&sk->sk_v6_daddr)) return; rcu_read_lock(); dst = __sk_dst_get(sk); if (!dst || !dst->obsolete || dst->ops->check(dst, inet6_sk(sk)->dst_cookie)) { rcu_read_unlock(); return; } rcu_read_unlock(); ip6_datagram_dst_update(sk, false); } EXPORT_SYMBOL_GPL(ip6_datagram_release_cb); |
0382a25af l2tp: lock socket... |
125 126 |
int __ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) |
1da177e4c Linux-2.6.12-rc2 |
127 128 |
{ struct sockaddr_in6 *usin = (struct sockaddr_in6 *) uaddr; |
67ba4152e ipv6: White-space... |
129 130 |
struct inet_sock *inet = inet_sk(sk); struct ipv6_pinfo *np = inet6_sk(sk); |
2f987a76a net: ipv6: keep s... |
131 132 133 |
struct in6_addr *daddr, old_daddr; __be32 fl6_flowlabel = 0; __be32 old_fl6_flowlabel; |
5f2fb802e ipv6: old_dport s... |
134 |
__be16 old_dport; |
1da177e4c Linux-2.6.12-rc2 |
135 136 137 138 139 140 |
int addr_type; int err; if (usin->sin6_family == AF_INET) { if (__ipv6_only_sock(sk)) return -EAFNOSUPPORT; |
03645a11a ipv6: lock socket... |
141 |
err = __ip4_datagram_connect(sk, uaddr, addr_len); |
1da177e4c Linux-2.6.12-rc2 |
142 143 144 145 |
goto ipv4_connected; } if (addr_len < SIN6_LEN_RFC2133) |
1ab1457c4 [NET] IPV6: Fix w... |
146 |
return -EINVAL; |
1da177e4c Linux-2.6.12-rc2 |
147 |
|
1ab1457c4 [NET] IPV6: Fix w... |
148 149 |
if (usin->sin6_family != AF_INET6) return -EAFNOSUPPORT; |
1da177e4c Linux-2.6.12-rc2 |
150 |
|
7e2040db1 ipv6: datagram: R... |
151 |
if (np->sndflow) |
80fbdb208 ipv6: datagram: R... |
152 |
fl6_flowlabel = usin->sin6_flowinfo & IPV6_FLOWINFO_MASK; |
1da177e4c Linux-2.6.12-rc2 |
153 |
|
052d2369d ipv6: Handle IPv4... |
154 |
if (ipv6_addr_any(&usin->sin6_addr)) { |
1da177e4c Linux-2.6.12-rc2 |
155 156 157 |
/* * connect to self */ |
052d2369d ipv6: Handle IPv4... |
158 159 160 161 162 |
if (ipv6_addr_v4mapped(&sk->sk_v6_rcv_saddr)) ipv6_addr_set_v4mapped(htonl(INADDR_LOOPBACK), &usin->sin6_addr); else usin->sin6_addr = in6addr_loopback; |
1da177e4c Linux-2.6.12-rc2 |
163 |
} |
052d2369d ipv6: Handle IPv4... |
164 |
addr_type = ipv6_addr_type(&usin->sin6_addr); |
1da177e4c Linux-2.6.12-rc2 |
165 |
daddr = &usin->sin6_addr; |
052d2369d ipv6: Handle IPv4... |
166 |
if (addr_type & IPV6_ADDR_MAPPED) { |
1da177e4c Linux-2.6.12-rc2 |
167 168 169 170 171 172 173 174 175 |
struct sockaddr_in sin; if (__ipv6_only_sock(sk)) { err = -ENETUNREACH; goto out; } sin.sin_family = AF_INET; sin.sin_addr.s_addr = daddr->s6_addr32[3]; sin.sin_port = usin->sin6_port; |
03645a11a ipv6: lock socket... |
176 177 178 |
err = __ip4_datagram_connect(sk, (struct sockaddr *) &sin, sizeof(sin)); |
1da177e4c Linux-2.6.12-rc2 |
179 180 181 182 |
ipv4_connected: if (err) goto out; |
1ab1457c4 [NET] IPV6: Fix w... |
183 |
|
efe4208f4 ipv6: make lookup... |
184 |
ipv6_addr_set_v4mapped(inet->inet_daddr, &sk->sk_v6_daddr); |
1da177e4c Linux-2.6.12-rc2 |
185 |
|
c15fea2d8 ipv6: check for I... |
186 187 |
if (ipv6_addr_any(&np->saddr) || ipv6_mapped_addr_any(&np->saddr)) |
c720c7e83 inet: rename some... |
188 |
ipv6_addr_set_v4mapped(inet->inet_saddr, &np->saddr); |
b301e82cf IPv6: use ipv6_ad... |
189 |
|
efe4208f4 ipv6: make lookup... |
190 191 |
if (ipv6_addr_any(&sk->sk_v6_rcv_saddr) || ipv6_mapped_addr_any(&sk->sk_v6_rcv_saddr)) { |
c720c7e83 inet: rename some... |
192 |
ipv6_addr_set_v4mapped(inet->inet_rcv_saddr, |
efe4208f4 ipv6: make lookup... |
193 |
&sk->sk_v6_rcv_saddr); |
719f83585 udp: add rehash o... |
194 195 196 |
if (sk->sk_prot->rehash) sk->sk_prot->rehash(sk); } |
1da177e4c Linux-2.6.12-rc2 |
197 |
|
1da177e4c Linux-2.6.12-rc2 |
198 199 |
goto out; } |
842df0739 ipv6: use newly i... |
200 |
if (__ipv6_addr_needs_scope_id(addr_type)) { |
1da177e4c Linux-2.6.12-rc2 |
201 202 |
if (addr_len >= sizeof(struct sockaddr_in6) && usin->sin6_scope_id) { |
54dc3e332 net: ipv6: Allow ... |
203 |
if (!sk_dev_equal_l3scope(sk, usin->sin6_scope_id)) { |
1da177e4c Linux-2.6.12-rc2 |
204 205 206 207 |
err = -EINVAL; goto out; } sk->sk_bound_dev_if = usin->sin6_scope_id; |
1da177e4c Linux-2.6.12-rc2 |
208 |
} |
1ac4f0088 [IPV6]: IPV6_MULT... |
209 210 |
if (!sk->sk_bound_dev_if && (addr_type & IPV6_ADDR_MULTICAST)) sk->sk_bound_dev_if = np->mcast_oif; |
1da177e4c Linux-2.6.12-rc2 |
211 212 213 214 215 216 |
/* Connect to link-local address requires an interface */ if (!sk->sk_bound_dev_if) { err = -EINVAL; goto out; } } |
2f987a76a net: ipv6: keep s... |
217 218 219 220 |
/* save the current peer information before updating it */ old_daddr = sk->sk_v6_daddr; old_fl6_flowlabel = np->flow_label; old_dport = inet->inet_dport; |
efe4208f4 ipv6: make lookup... |
221 |
sk->sk_v6_daddr = *daddr; |
80fbdb208 ipv6: datagram: R... |
222 |
np->flow_label = fl6_flowlabel; |
c720c7e83 inet: rename some... |
223 |
inet->inet_dport = usin->sin6_port; |
1da177e4c Linux-2.6.12-rc2 |
224 225 226 227 228 |
/* * Check for a route to destination an obtain the * destination cache for it. */ |
33c162a98 ipv6: datagram: U... |
229 |
err = ip6_datagram_dst_update(sk, true); |
85cb73ff9 net: ipv6: reset ... |
230 |
if (err) { |
2f987a76a net: ipv6: keep s... |
231 232 |
/* Restore the socket peer info, to keep it consistent with * the old socket state |
85cb73ff9 net: ipv6: reset ... |
233 |
*/ |
2f987a76a net: ipv6: keep s... |
234 235 236 |
sk->sk_v6_daddr = old_daddr; np->flow_label = old_fl6_flowlabel; inet->inet_dport = old_dport; |
1da177e4c Linux-2.6.12-rc2 |
237 |
goto out; |
85cb73ff9 net: ipv6: reset ... |
238 |
} |
1da177e4c Linux-2.6.12-rc2 |
239 |
|
acdcecc61 udp: correct reus... |
240 |
reuseport_has_conns(sk, true); |
1da177e4c Linux-2.6.12-rc2 |
241 |
sk->sk_state = TCP_ESTABLISHED; |
877d1f629 net: Set sk_txhas... |
242 |
sk_set_txhash(sk); |
1da177e4c Linux-2.6.12-rc2 |
243 |
out: |
1da177e4c Linux-2.6.12-rc2 |
244 245 |
return err; } |
0382a25af l2tp: lock socket... |
246 |
EXPORT_SYMBOL_GPL(__ip6_datagram_connect); |
03645a11a ipv6: lock socket... |
247 248 249 250 251 252 253 254 255 256 |
int ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) { int res; lock_sock(sk); res = __ip6_datagram_connect(sk, uaddr, addr_len); release_sock(sk); return res; } |
a495f8364 ipv6: Export ipv6... |
257 |
EXPORT_SYMBOL_GPL(ip6_datagram_connect); |
1da177e4c Linux-2.6.12-rc2 |
258 |
|
82b276cd2 ipv6: protect pro... |
259 260 261 262 263 264 265 266 267 |
int ip6_datagram_connect_v6_only(struct sock *sk, struct sockaddr *uaddr, int addr_len) { DECLARE_SOCKADDR(struct sockaddr_in6 *, sin6, uaddr); if (sin6->sin6_family != AF_INET6) return -EAFNOSUPPORT; return ip6_datagram_connect(sk, uaddr, addr_len); } EXPORT_SYMBOL_GPL(ip6_datagram_connect_v6_only); |
1ab1457c4 [NET] IPV6: Fix w... |
268 |
void ipv6_icmp_error(struct sock *sk, struct sk_buff *skb, int err, |
e69a4adc6 [IPV6]: Misc endi... |
269 |
__be16 port, u32 info, u8 *payload) |
1da177e4c Linux-2.6.12-rc2 |
270 271 |
{ struct ipv6_pinfo *np = inet6_sk(sk); |
cc70ab261 [ICMP6]: Introduc... |
272 |
struct icmp6hdr *icmph = icmp6_hdr(skb); |
1da177e4c Linux-2.6.12-rc2 |
273 274 275 276 277 278 279 280 |
struct sock_exterr_skb *serr; if (!np->recverr) return; skb = skb_clone(skb, GFP_ATOMIC); if (!skb) return; |
d40a4de0b IPv6: fix IPV6_RE... |
281 |
skb->protocol = htons(ETH_P_IPV6); |
1da177e4c Linux-2.6.12-rc2 |
282 283 284 |
serr = SKB_EXT_ERR(skb); serr->ee.ee_errno = err; serr->ee.ee_origin = SO_EE_ORIGIN_ICMP6; |
1ab1457c4 [NET] IPV6: Fix w... |
285 |
serr->ee.ee_type = icmph->icmp6_type; |
1da177e4c Linux-2.6.12-rc2 |
286 287 288 289 |
serr->ee.ee_code = icmph->icmp6_code; serr->ee.ee_pad = 0; serr->ee.ee_info = info; serr->ee.ee_data = 0; |
d56f90a7c [SK_BUFF]: Introd... |
290 291 |
serr->addr_offset = (u8 *)&(((struct ipv6hdr *)(icmph + 1))->daddr) - skb_network_header(skb); |
1da177e4c Linux-2.6.12-rc2 |
292 |
serr->port = port; |
1da177e4c Linux-2.6.12-rc2 |
293 |
__skb_pull(skb, payload - skb->data); |
bd82393ca [SK_BUFF]: More s... |
294 |
skb_reset_transport_header(skb); |
1da177e4c Linux-2.6.12-rc2 |
295 296 297 298 |
if (sock_queue_err_skb(sk, skb)) kfree_skb(skb); } |
4c9483b2f ipv6: Convert to ... |
299 |
void ipv6_local_error(struct sock *sk, int err, struct flowi6 *fl6, u32 info) |
1da177e4c Linux-2.6.12-rc2 |
300 |
{ |
1c1e9d2b6 ipv6: constify ip... |
301 |
const struct ipv6_pinfo *np = inet6_sk(sk); |
1da177e4c Linux-2.6.12-rc2 |
302 303 304 305 306 307 308 309 310 311 |
struct sock_exterr_skb *serr; struct ipv6hdr *iph; struct sk_buff *skb; if (!np->recverr) return; skb = alloc_skb(sizeof(struct ipv6hdr), GFP_ATOMIC); if (!skb) return; |
d40a4de0b IPv6: fix IPV6_RE... |
312 |
skb->protocol = htons(ETH_P_IPV6); |
1ced98e81 [SK_BUFF] ipv6: M... |
313 314 |
skb_put(skb, sizeof(struct ipv6hdr)); skb_reset_network_header(skb); |
0660e03f6 [SK_BUFF]: Introd... |
315 |
iph = ipv6_hdr(skb); |
4e3fd7a06 net: remove ipv6_... |
316 |
iph->daddr = fl6->daddr; |
7d033c9f6 ipv6: fix kernel-... |
317 |
ip6_flow_hdr(iph, 0, 0); |
1da177e4c Linux-2.6.12-rc2 |
318 319 320 321 |
serr = SKB_EXT_ERR(skb); serr->ee.ee_errno = err; serr->ee.ee_origin = SO_EE_ORIGIN_LOCAL; |
1ab1457c4 [NET] IPV6: Fix w... |
322 |
serr->ee.ee_type = 0; |
1da177e4c Linux-2.6.12-rc2 |
323 324 325 326 |
serr->ee.ee_code = 0; serr->ee.ee_pad = 0; serr->ee.ee_info = info; serr->ee.ee_data = 0; |
d56f90a7c [SK_BUFF]: Introd... |
327 |
serr->addr_offset = (u8 *)&iph->daddr - skb_network_header(skb); |
1958b856c net: Put fl6_* ma... |
328 |
serr->port = fl6->fl6_dport; |
1da177e4c Linux-2.6.12-rc2 |
329 |
|
27a884dc3 [SK_BUFF]: Conver... |
330 |
__skb_pull(skb, skb_tail_pointer(skb) - skb->data); |
bd82393ca [SK_BUFF]: More s... |
331 |
skb_reset_transport_header(skb); |
1da177e4c Linux-2.6.12-rc2 |
332 333 334 335 |
if (sock_queue_err_skb(sk, skb)) kfree_skb(skb); } |
4c9483b2f ipv6: Convert to ... |
336 |
void ipv6_local_rxpmtu(struct sock *sk, struct flowi6 *fl6, u32 mtu) |
4b340ae20 IPv6: Complete IP... |
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
{ struct ipv6_pinfo *np = inet6_sk(sk); struct ipv6hdr *iph; struct sk_buff *skb; struct ip6_mtuinfo *mtu_info; if (!np->rxopt.bits.rxpmtu) return; skb = alloc_skb(sizeof(struct ipv6hdr), GFP_ATOMIC); if (!skb) return; skb_put(skb, sizeof(struct ipv6hdr)); skb_reset_network_header(skb); iph = ipv6_hdr(skb); |
4e3fd7a06 net: remove ipv6_... |
353 |
iph->daddr = fl6->daddr; |
4b340ae20 IPv6: Complete IP... |
354 355 |
mtu_info = IP6CBMTU(skb); |
4b340ae20 IPv6: Complete IP... |
356 357 358 359 360 |
mtu_info->ip6m_mtu = mtu; mtu_info->ip6m_addr.sin6_family = AF_INET6; mtu_info->ip6m_addr.sin6_port = 0; mtu_info->ip6m_addr.sin6_flowinfo = 0; |
4c9483b2f ipv6: Convert to ... |
361 |
mtu_info->ip6m_addr.sin6_scope_id = fl6->flowi6_oif; |
4e3fd7a06 net: remove ipv6_... |
362 |
mtu_info->ip6m_addr.sin6_addr = ipv6_hdr(skb)->daddr; |
4b340ae20 IPv6: Complete IP... |
363 364 365 366 367 368 369 |
__skb_pull(skb, skb_tail_pointer(skb) - skb->data); skb_reset_transport_header(skb); skb = xchg(&np->rxpmtu, skb); kfree_skb(skb); } |
34b99df4e ip: report the or... |
370 371 372 373 374 375 376 377 378 |
/* For some errors we have valid addr_offset even with zero payload and * zero port. Also, addr_offset should be supported if port is set. */ static inline bool ipv6_datagram_support_addr(struct sock_exterr_skb *serr) { return serr->ee.ee_origin == SO_EE_ORIGIN_ICMP6 || serr->ee.ee_origin == SO_EE_ORIGIN_ICMP || serr->ee.ee_origin == SO_EE_ORIGIN_LOCAL || serr->port; } |
c247f0534 ip: fix error que... |
379 380 381 382 383 |
/* IPv6 supports cmsg on all origins aside from SO_EE_ORIGIN_LOCAL. * * At one point, excluding local errors was a quick test to identify icmp/icmp6 * errors. This is no longer true, but the test remained, so the v6 stack, * unlike v4, also honors cmsg requests on all wifi and timestamp errors. |
c247f0534 ip: fix error que... |
384 385 386 |
*/ static bool ip6_datagram_support_cmsg(struct sk_buff *skb, struct sock_exterr_skb *serr) |
829ae9d61 net-timestamp: al... |
387 |
{ |
c247f0534 ip: fix error que... |
388 389 390 391 392 393 |
if (serr->ee.ee_origin == SO_EE_ORIGIN_ICMP || serr->ee.ee_origin == SO_EE_ORIGIN_ICMP6) return true; if (serr->ee.ee_origin == SO_EE_ORIGIN_LOCAL) return false; |
1862d6208 net-timestamp: av... |
394 |
if (!IP6CB(skb)->iif) |
c247f0534 ip: fix error que... |
395 |
return false; |
829ae9d61 net-timestamp: al... |
396 |
|
c247f0534 ip: fix error que... |
397 |
return true; |
829ae9d61 net-timestamp: al... |
398 |
} |
1ab1457c4 [NET] IPV6: Fix w... |
399 |
/* |
1da177e4c Linux-2.6.12-rc2 |
400 401 |
* Handle MSG_ERRQUEUE */ |
85fbaa750 inet: fix addr_le... |
402 |
int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len) |
1da177e4c Linux-2.6.12-rc2 |
403 404 405 |
{ struct ipv6_pinfo *np = inet6_sk(sk); struct sock_exterr_skb *serr; |
364a9e932 sock: deduplicate... |
406 |
struct sk_buff *skb; |
342dfc306 net: add build-ti... |
407 |
DECLARE_SOCKADDR(struct sockaddr_in6 *, sin, msg->msg_name); |
1da177e4c Linux-2.6.12-rc2 |
408 409 410 411 412 413 414 415 |
struct { struct sock_extended_err ee; struct sockaddr_in6 offender; } errhdr; int err; int copied; err = -EAGAIN; |
364a9e932 sock: deduplicate... |
416 |
skb = sock_dequeue_err_skb(sk); |
63159f29b ipv6: coding styl... |
417 |
if (!skb) |
1da177e4c Linux-2.6.12-rc2 |
418 419 420 421 422 423 424 |
goto out; copied = skb->len; if (copied > len) { msg->msg_flags |= MSG_TRUNC; copied = len; } |
51f3d02b9 net: Add and use ... |
425 |
err = skb_copy_datagram_msg(skb, 0, msg, copied); |
960a26282 net: better drop ... |
426 427 428 429 |
if (unlikely(err)) { kfree_skb(skb); return err; } |
1da177e4c Linux-2.6.12-rc2 |
430 431 432 |
sock_recv_timestamp(msg, sk, skb); serr = SKB_EXT_ERR(skb); |
34b99df4e ip: report the or... |
433 |
if (sin && ipv6_datagram_support_addr(serr)) { |
d56f90a7c [SK_BUFF]: Introd... |
434 |
const unsigned char *nh = skb_network_header(skb); |
1da177e4c Linux-2.6.12-rc2 |
435 436 |
sin->sin6_family = AF_INET6; sin->sin6_flowinfo = 0; |
1ab1457c4 [NET] IPV6: Fix w... |
437 |
sin->sin6_port = serr->port; |
d40a4de0b IPv6: fix IPV6_RE... |
438 |
if (skb->protocol == htons(ETH_P_IPV6)) { |
6c40d100c ipv6: Use contain... |
439 440 441 |
const struct ipv6hdr *ip6h = container_of((struct in6_addr *)(nh + serr->addr_offset), struct ipv6hdr, daddr); sin->sin6_addr = ip6h->daddr; |
1da177e4c Linux-2.6.12-rc2 |
442 |
if (np->sndflow) |
6502ca527 ipv6: Introduce i... |
443 |
sin->sin6_flowinfo = ip6_flowinfo(ip6h); |
842df0739 ipv6: use newly i... |
444 445 446 |
sin->sin6_scope_id = ipv6_iface_scope_id(&sin->sin6_addr, IP6CB(skb)->iif); |
1da177e4c Linux-2.6.12-rc2 |
447 |
} else { |
b301e82cf IPv6: use ipv6_ad... |
448 449 |
ipv6_addr_set_v4mapped(*(__be32 *)(nh + serr->addr_offset), &sin->sin6_addr); |
842df0739 ipv6: use newly i... |
450 |
sin->sin6_scope_id = 0; |
1da177e4c Linux-2.6.12-rc2 |
451 |
} |
85fbaa750 inet: fix addr_le... |
452 |
*addr_len = sizeof(*sin); |
1da177e4c Linux-2.6.12-rc2 |
453 454 455 456 |
} memcpy(&errhdr.ee, &serr->ee, sizeof(struct sock_extended_err)); sin = &errhdr.offender; |
f812116b1 ip: zero sockaddr... |
457 |
memset(sin, 0, sizeof(*sin)); |
c247f0534 ip: fix error que... |
458 459 |
if (ip6_datagram_support_cmsg(skb, serr)) { |
1da177e4c Linux-2.6.12-rc2 |
460 |
sin->sin6_family = AF_INET6; |
c247f0534 ip: fix error que... |
461 |
if (np->rxopt.all) |
4b261c75a ipv6: make IPV6_R... |
462 |
ip6_datagram_recv_common_ctl(sk, msg, skb); |
d40a4de0b IPv6: fix IPV6_RE... |
463 |
if (skb->protocol == htons(ETH_P_IPV6)) { |
4e3fd7a06 net: remove ipv6_... |
464 |
sin->sin6_addr = ipv6_hdr(skb)->saddr; |
1da177e4c Linux-2.6.12-rc2 |
465 |
if (np->rxopt.all) |
4b261c75a ipv6: make IPV6_R... |
466 |
ip6_datagram_recv_specific_ctl(sk, msg, skb); |
842df0739 ipv6: use newly i... |
467 468 469 |
sin->sin6_scope_id = ipv6_iface_scope_id(&sin->sin6_addr, IP6CB(skb)->iif); |
1da177e4c Linux-2.6.12-rc2 |
470 |
} else { |
b301e82cf IPv6: use ipv6_ad... |
471 472 |
ipv6_addr_set_v4mapped(ip_hdr(skb)->saddr, &sin->sin6_addr); |
f812116b1 ip: zero sockaddr... |
473 |
if (inet_sk(sk)->cmsg_flags) |
1da177e4c Linux-2.6.12-rc2 |
474 475 476 477 478 479 480 481 482 483 |
ip_cmsg_recv(msg, skb); } } put_cmsg(msg, SOL_IPV6, IPV6_RECVERR, sizeof(errhdr), &errhdr); /* Now we could try to dump offended packet options */ msg->msg_flags |= MSG_ERRQUEUE; err = copied; |
960a26282 net: better drop ... |
484 |
consume_skb(skb); |
1da177e4c Linux-2.6.12-rc2 |
485 486 487 |
out: return err; } |
a495f8364 ipv6: Export ipv6... |
488 |
EXPORT_SYMBOL_GPL(ipv6_recv_error); |
1da177e4c Linux-2.6.12-rc2 |
489 |
|
4b340ae20 IPv6: Complete IP... |
490 491 492 |
/* * Handle IPV6_RECVPATHMTU */ |
85fbaa750 inet: fix addr_le... |
493 494 |
int ipv6_recv_rxpmtu(struct sock *sk, struct msghdr *msg, int len, int *addr_len) |
4b340ae20 IPv6: Complete IP... |
495 496 497 |
{ struct ipv6_pinfo *np = inet6_sk(sk); struct sk_buff *skb; |
4b340ae20 IPv6: Complete IP... |
498 |
struct ip6_mtuinfo mtu_info; |
342dfc306 net: add build-ti... |
499 |
DECLARE_SOCKADDR(struct sockaddr_in6 *, sin, msg->msg_name); |
4b340ae20 IPv6: Complete IP... |
500 501 502 503 504 |
int err; int copied; err = -EAGAIN; skb = xchg(&np->rxpmtu, NULL); |
63159f29b ipv6: coding styl... |
505 |
if (!skb) |
4b340ae20 IPv6: Complete IP... |
506 507 508 509 510 511 512 |
goto out; copied = skb->len; if (copied > len) { msg->msg_flags |= MSG_TRUNC; copied = len; } |
51f3d02b9 net: Add and use ... |
513 |
err = skb_copy_datagram_msg(skb, 0, msg, copied); |
4b340ae20 IPv6: Complete IP... |
514 515 516 517 518 519 |
if (err) goto out_free_skb; sock_recv_timestamp(msg, sk, skb); memcpy(&mtu_info, IP6CBMTU(skb), sizeof(mtu_info)); |
4b340ae20 IPv6: Complete IP... |
520 521 522 523 524 |
if (sin) { sin->sin6_family = AF_INET6; sin->sin6_flowinfo = 0; sin->sin6_port = 0; sin->sin6_scope_id = mtu_info.ip6m_addr.sin6_scope_id; |
4e3fd7a06 net: remove ipv6_... |
525 |
sin->sin6_addr = mtu_info.ip6m_addr.sin6_addr; |
85fbaa750 inet: fix addr_le... |
526 |
*addr_len = sizeof(*sin); |
4b340ae20 IPv6: Complete IP... |
527 528 529 530 531 532 533 534 535 536 537 |
} put_cmsg(msg, SOL_IPV6, IPV6_PATHMTU, sizeof(mtu_info), &mtu_info); err = copied; out_free_skb: kfree_skb(skb); out: return err; } |
1da177e4c Linux-2.6.12-rc2 |
538 |
|
4b261c75a ipv6: make IPV6_R... |
539 540 |
void ip6_datagram_recv_common_ctl(struct sock *sk, struct msghdr *msg, struct sk_buff *skb) |
1da177e4c Linux-2.6.12-rc2 |
541 542 |
{ struct ipv6_pinfo *np = inet6_sk(sk); |
4b261c75a ipv6: make IPV6_R... |
543 |
bool is_ipv6 = skb->protocol == htons(ETH_P_IPV6); |
1da177e4c Linux-2.6.12-rc2 |
544 545 546 |
if (np->rxopt.bits.rxinfo) { struct in6_pktinfo src_info; |
4b261c75a ipv6: make IPV6_R... |
547 548 549 550 551 552 553 554 555 |
if (is_ipv6) { src_info.ipi6_ifindex = IP6CB(skb)->iif; src_info.ipi6_addr = ipv6_hdr(skb)->daddr; } else { src_info.ipi6_ifindex = PKTINFO_SKB_CB(skb)->ipi_ifindex; ipv6_addr_set_v4mapped(ip_hdr(skb)->daddr, &src_info.ipi6_addr); } |
829ae9d61 net-timestamp: al... |
556 557 558 559 |
if (src_info.ipi6_ifindex >= 0) put_cmsg(msg, SOL_IPV6, IPV6_PKTINFO, sizeof(src_info), &src_info); |
1da177e4c Linux-2.6.12-rc2 |
560 |
} |
4b261c75a ipv6: make IPV6_R... |
561 562 563 564 565 566 567 568 |
} void ip6_datagram_recv_specific_ctl(struct sock *sk, struct msghdr *msg, struct sk_buff *skb) { struct ipv6_pinfo *np = inet6_sk(sk); struct inet6_skb_parm *opt = IP6CB(skb); unsigned char *nh = skb_network_header(skb); |
1da177e4c Linux-2.6.12-rc2 |
569 570 |
if (np->rxopt.bits.rxhlim) { |
0660e03f6 [SK_BUFF]: Introd... |
571 |
int hlim = ipv6_hdr(skb)->hop_limit; |
1da177e4c Linux-2.6.12-rc2 |
572 573 |
put_cmsg(msg, SOL_IPV6, IPV6_HOPLIMIT, sizeof(hlim), &hlim); } |
41a1f8ea4 [IPV6]: Support I... |
574 |
if (np->rxopt.bits.rxtclass) { |
e7219858a ipv6: Use ipv6_ge... |
575 |
int tclass = ipv6_get_dsfield(ipv6_hdr(skb)); |
41a1f8ea4 [IPV6]: Support I... |
576 577 |
put_cmsg(msg, SOL_IPV6, IPV6_TCLASS, sizeof(tclass), &tclass); } |
6502ca527 ipv6: Introduce i... |
578 579 580 581 |
if (np->rxopt.bits.rxflow) { __be32 flowinfo = ip6_flowinfo((struct ipv6hdr *)nh); if (flowinfo) put_cmsg(msg, SOL_IPV6, IPV6_FLOWINFO, sizeof(flowinfo), &flowinfo); |
1da177e4c Linux-2.6.12-rc2 |
582 |
} |
333fad536 [IPV6]: Support s... |
583 584 |
/* HbH is allowed only once */ |
8b58a3984 ipv6: use flag in... |
585 586 |
if (np->rxopt.bits.hopopts && (opt->flags & IP6SKB_HOPBYHOP)) { u8 *ptr = nh + sizeof(struct ipv6hdr); |
1da177e4c Linux-2.6.12-rc2 |
587 588 |
put_cmsg(msg, SOL_IPV6, IPV6_HOPOPTS, (ptr[1]+1)<<3, ptr); } |
333fad536 [IPV6]: Support s... |
589 590 591 592 593 594 595 596 |
if (opt->lastopt && (np->rxopt.bits.dstopts || np->rxopt.bits.srcrt)) { /* * Silly enough, but we need to reparse in order to * report extension headers (except for HbH) * in order. * |
1ab1457c4 [NET] IPV6: Fix w... |
597 |
* Also note that IPV6_RECVRTHDRDSTOPTS is NOT |
333fad536 [IPV6]: Support s... |
598 599 600 601 |
* (and WILL NOT be) defined because * IPV6_RECVDSTOPTS is more generic. --yoshfuji */ unsigned int off = sizeof(struct ipv6hdr); |
0660e03f6 [SK_BUFF]: Introd... |
602 |
u8 nexthdr = ipv6_hdr(skb)->nexthdr; |
333fad536 [IPV6]: Support s... |
603 604 |
while (off <= opt->lastopt) { |
95c961747 net: cleanup unsi... |
605 |
unsigned int len; |
d56f90a7c [SK_BUFF]: Introd... |
606 |
u8 *ptr = nh + off; |
333fad536 [IPV6]: Support s... |
607 |
|
b5a4257ce net/ipv6/datagram... |
608 |
switch (nexthdr) { |
333fad536 [IPV6]: Support s... |
609 610 611 612 613 614 615 616 617 618 619 620 621 622 |
case IPPROTO_DSTOPTS: nexthdr = ptr[0]; len = (ptr[1] + 1) << 3; if (np->rxopt.bits.dstopts) put_cmsg(msg, SOL_IPV6, IPV6_DSTOPTS, len, ptr); break; case IPPROTO_ROUTING: nexthdr = ptr[0]; len = (ptr[1] + 1) << 3; if (np->rxopt.bits.srcrt) put_cmsg(msg, SOL_IPV6, IPV6_RTHDR, len, ptr); break; case IPPROTO_AH: nexthdr = ptr[0]; |
a30598938 [IPV6]: Fix calcu... |
623 |
len = (ptr[1] + 2) << 2; |
333fad536 [IPV6]: Support s... |
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 |
break; default: nexthdr = ptr[0]; len = (ptr[1] + 1) << 3; break; } off += len; } } /* socket options in old style */ if (np->rxopt.bits.rxoinfo) { struct in6_pktinfo src_info; src_info.ipi6_ifindex = opt->iif; |
4e3fd7a06 net: remove ipv6_... |
640 |
src_info.ipi6_addr = ipv6_hdr(skb)->daddr; |
333fad536 [IPV6]: Support s... |
641 642 643 |
put_cmsg(msg, SOL_IPV6, IPV6_2292PKTINFO, sizeof(src_info), &src_info); } if (np->rxopt.bits.rxohlim) { |
0660e03f6 [SK_BUFF]: Introd... |
644 |
int hlim = ipv6_hdr(skb)->hop_limit; |
333fad536 [IPV6]: Support s... |
645 646 |
put_cmsg(msg, SOL_IPV6, IPV6_2292HOPLIMIT, sizeof(hlim), &hlim); } |
8b58a3984 ipv6: use flag in... |
647 648 |
if (np->rxopt.bits.ohopopts && (opt->flags & IP6SKB_HOPBYHOP)) { u8 *ptr = nh + sizeof(struct ipv6hdr); |
333fad536 [IPV6]: Support s... |
649 650 651 |
put_cmsg(msg, SOL_IPV6, IPV6_2292HOPOPTS, (ptr[1]+1)<<3, ptr); } if (np->rxopt.bits.odstopts && opt->dst0) { |
d56f90a7c [SK_BUFF]: Introd... |
652 |
u8 *ptr = nh + opt->dst0; |
333fad536 [IPV6]: Support s... |
653 |
put_cmsg(msg, SOL_IPV6, IPV6_2292DSTOPTS, (ptr[1]+1)<<3, ptr); |
1da177e4c Linux-2.6.12-rc2 |
654 |
} |
333fad536 [IPV6]: Support s... |
655 |
if (np->rxopt.bits.osrcrt && opt->srcrt) { |
d56f90a7c [SK_BUFF]: Introd... |
656 |
struct ipv6_rt_hdr *rthdr = (struct ipv6_rt_hdr *)(nh + opt->srcrt); |
333fad536 [IPV6]: Support s... |
657 |
put_cmsg(msg, SOL_IPV6, IPV6_2292RTHDR, (rthdr->hdrlen+1) << 3, rthdr); |
1da177e4c Linux-2.6.12-rc2 |
658 |
} |
333fad536 [IPV6]: Support s... |
659 |
if (np->rxopt.bits.odstopts && opt->dst1) { |
d56f90a7c [SK_BUFF]: Introd... |
660 |
u8 *ptr = nh + opt->dst1; |
333fad536 [IPV6]: Support s... |
661 |
put_cmsg(msg, SOL_IPV6, IPV6_2292DSTOPTS, (ptr[1]+1)<<3, ptr); |
1da177e4c Linux-2.6.12-rc2 |
662 |
} |
6c4686228 tproxy: added tpr... |
663 664 |
if (np->rxopt.bits.rxorigdstaddr) { struct sockaddr_in6 sin6; |
4a06fa67c ip: on queued skb... |
665 |
__be16 _ports[2], *ports; |
6c4686228 tproxy: added tpr... |
666 |
|
4a06fa67c ip: on queued skb... |
667 668 669 |
ports = skb_header_pointer(skb, skb_transport_offset(skb), sizeof(_ports), &_ports); if (ports) { |
6c4686228 tproxy: added tpr... |
670 671 672 673 |
/* All current transport protocols have the port numbers in the * first four bytes of the transport header and this function is * written with this assumption in mind. */ |
6c4686228 tproxy: added tpr... |
674 |
sin6.sin6_family = AF_INET6; |
4e3fd7a06 net: remove ipv6_... |
675 |
sin6.sin6_addr = ipv6_hdr(skb)->daddr; |
6c4686228 tproxy: added tpr... |
676 677 |
sin6.sin6_port = ports[1]; sin6.sin6_flowinfo = 0; |
3868b7aa7 ipv6: report sin6... |
678 679 680 |
sin6.sin6_scope_id = ipv6_iface_scope_id(&ipv6_hdr(skb)->daddr, opt->iif); |
6c4686228 tproxy: added tpr... |
681 682 683 684 |
put_cmsg(msg, SOL_IPV6, IPV6_ORIGDSTADDR, sizeof(sin6), &sin6); } } |
0cc0aa614 ipv6: add IPV6_RE... |
685 686 687 688 689 |
if (np->rxopt.bits.recvfragsize && opt->frag_max_size) { int val = opt->frag_max_size; put_cmsg(msg, SOL_IPV6, IPV6_RECVFRAGSIZE, sizeof(val), &val); } |
4b261c75a ipv6: make IPV6_R... |
690 691 692 693 694 695 696 |
} void ip6_datagram_recv_ctl(struct sock *sk, struct msghdr *msg, struct sk_buff *skb) { ip6_datagram_recv_common_ctl(sk, msg, skb); ip6_datagram_recv_specific_ctl(sk, msg, skb); |
1da177e4c Linux-2.6.12-rc2 |
697 |
} |
8e72d37eb ipv6: export ip6_... |
698 |
EXPORT_SYMBOL_GPL(ip6_datagram_recv_ctl); |
1da177e4c Linux-2.6.12-rc2 |
699 |
|
73df66f8b ipv6: rename data... |
700 701 |
int ip6_datagram_send_ctl(struct net *net, struct sock *sk, struct msghdr *msg, struct flowi6 *fl6, |
5fdaa88df ipv6: fold sockcm... |
702 |
struct ipcm6_cookie *ipc6) |
1da177e4c Linux-2.6.12-rc2 |
703 704 705 706 707 |
{ struct in6_pktinfo *src_info; struct cmsghdr *cmsg; struct ipv6_rt_hdr *rthdr; struct ipv6_opt_hdr *hdr; |
26879da58 ipv6: add new str... |
708 |
struct ipv6_txoptions *opt = ipc6->opt; |
1da177e4c Linux-2.6.12-rc2 |
709 710 |
int len; int err = 0; |
f95b414ed net: introduce he... |
711 |
for_each_cmsghdr(cmsg, msg) { |
1da177e4c Linux-2.6.12-rc2 |
712 |
int addr_type; |
1da177e4c Linux-2.6.12-rc2 |
713 714 715 716 717 |
if (!CMSG_OK(msg, cmsg)) { err = -EINVAL; goto exit_f; } |
ad1e46a83 ipv6: process soc... |
718 |
if (cmsg->cmsg_level == SOL_SOCKET) { |
5fdaa88df ipv6: fold sockcm... |
719 |
err = __sock_cmsg_send(sk, msg, cmsg, &ipc6->sockc); |
2632616bc sock: propagate _... |
720 721 |
if (err) return err; |
ad1e46a83 ipv6: process soc... |
722 723 |
continue; } |
1da177e4c Linux-2.6.12-rc2 |
724 725 726 727 |
if (cmsg->cmsg_level != SOL_IPV6) continue; switch (cmsg->cmsg_type) { |
1ab1457c4 [NET] IPV6: Fix w... |
728 729 |
case IPV6_PKTINFO: case IPV6_2292PKTINFO: |
187e38384 [IPV6]: Check out... |
730 731 |
{ struct net_device *dev = NULL; |
6da5b0f02 net: ensure unbou... |
732 |
int src_idx; |
187e38384 [IPV6]: Check out... |
733 |
|
1ab1457c4 [NET] IPV6: Fix w... |
734 |
if (cmsg->cmsg_len < CMSG_LEN(sizeof(struct in6_pktinfo))) { |
1da177e4c Linux-2.6.12-rc2 |
735 736 737 738 739 |
err = -EINVAL; goto exit_f; } src_info = (struct in6_pktinfo *)CMSG_DATA(cmsg); |
6da5b0f02 net: ensure unbou... |
740 |
src_idx = src_info->ipi6_ifindex; |
1ab1457c4 [NET] IPV6: Fix w... |
741 |
|
6da5b0f02 net: ensure unbou... |
742 |
if (src_idx) { |
4c9483b2f ipv6: Convert to ... |
743 |
if (fl6->flowi6_oif && |
6da5b0f02 net: ensure unbou... |
744 745 746 |
src_idx != fl6->flowi6_oif && (sk->sk_bound_dev_if != fl6->flowi6_oif || !sk_dev_equal_l3scope(sk, src_idx))) |
1da177e4c Linux-2.6.12-rc2 |
747 |
return -EINVAL; |
6da5b0f02 net: ensure unbou... |
748 |
fl6->flowi6_oif = src_idx; |
1da177e4c Linux-2.6.12-rc2 |
749 |
} |
187e38384 [IPV6]: Check out... |
750 |
addr_type = __ipv6_addr_type(&src_info->ipi6_addr); |
1da177e4c Linux-2.6.12-rc2 |
751 |
|
536b2e92f ipv6: no more dev... |
752 |
rcu_read_lock(); |
4c9483b2f ipv6: Convert to ... |
753 754 |
if (fl6->flowi6_oif) { dev = dev_get_by_index_rcu(net, fl6->flowi6_oif); |
536b2e92f ipv6: no more dev... |
755 756 |
if (!dev) { rcu_read_unlock(); |
187e38384 [IPV6]: Check out... |
757 |
return -ENODEV; |
536b2e92f ipv6: no more dev... |
758 759 760 |
} } else if (addr_type & IPV6_ADDR_LINKLOCAL) { rcu_read_unlock(); |
187e38384 [IPV6]: Check out... |
761 |
return -EINVAL; |
536b2e92f ipv6: no more dev... |
762 |
} |
1ab1457c4 [NET] IPV6: Fix w... |
763 |
|
187e38384 [IPV6]: Check out... |
764 765 |
if (addr_type != IPV6_ADDR_ANY) { int strict = __ipv6_addr_src_scope(addr_type) <= IPV6_ADDR_SCOPE_LINKLOCAL; |
83ba46451 net: add helpers ... |
766 |
if (!ipv6_can_nonlocal_bind(net, inet_sk(sk)) && |
232378e8d net/ipv6: Change ... |
767 768 769 |
!ipv6_chk_addr_and_flags(net, &src_info->ipi6_addr, dev, !strict, 0, IFA_F_TENTATIVE) && |
7c90cc2d4 ipv6: enable anyc... |
770 771 |
!ipv6_chk_acast_addr_src(net, dev, &src_info->ipi6_addr)) |
187e38384 [IPV6]: Check out... |
772 773 |
err = -EINVAL; else |
4e3fd7a06 net: remove ipv6_... |
774 |
fl6->saddr = src_info->ipi6_addr; |
1da177e4c Linux-2.6.12-rc2 |
775 |
} |
187e38384 [IPV6]: Check out... |
776 |
|
536b2e92f ipv6: no more dev... |
777 |
rcu_read_unlock(); |
1da177e4c Linux-2.6.12-rc2 |
778 |
|
187e38384 [IPV6]: Check out... |
779 780 |
if (err) goto exit_f; |
1da177e4c Linux-2.6.12-rc2 |
781 |
break; |
187e38384 [IPV6]: Check out... |
782 |
} |
1da177e4c Linux-2.6.12-rc2 |
783 784 |
case IPV6_FLOWINFO: |
1ab1457c4 [NET] IPV6: Fix w... |
785 |
if (cmsg->cmsg_len < CMSG_LEN(4)) { |
1da177e4c Linux-2.6.12-rc2 |
786 787 788 |
err = -EINVAL; goto exit_f; } |
4c9483b2f ipv6: Convert to ... |
789 790 |
if (fl6->flowlabel&IPV6_FLOWINFO_MASK) { if ((fl6->flowlabel^*(__be32 *)CMSG_DATA(cmsg))&~IPV6_FLOWINFO_MASK) { |
1da177e4c Linux-2.6.12-rc2 |
791 792 793 794 |
err = -EINVAL; goto exit_f; } } |
4c9483b2f ipv6: Convert to ... |
795 |
fl6->flowlabel = IPV6_FLOWINFO_MASK & *(__be32 *)CMSG_DATA(cmsg); |
1da177e4c Linux-2.6.12-rc2 |
796 |
break; |
333fad536 [IPV6]: Support s... |
797 |
case IPV6_2292HOPOPTS: |
1da177e4c Linux-2.6.12-rc2 |
798 |
case IPV6_HOPOPTS: |
1ab1457c4 [NET] IPV6: Fix w... |
799 |
if (opt->hopopt || cmsg->cmsg_len < CMSG_LEN(sizeof(struct ipv6_opt_hdr))) { |
1da177e4c Linux-2.6.12-rc2 |
800 801 802 803 804 805 806 807 808 809 |
err = -EINVAL; goto exit_f; } hdr = (struct ipv6_opt_hdr *)CMSG_DATA(cmsg); len = ((hdr->hdrlen + 1) << 3); if (cmsg->cmsg_len < CMSG_LEN(len)) { err = -EINVAL; goto exit_f; } |
af31f412c net: Allow userns... |
810 |
if (!ns_capable(net->user_ns, CAP_NET_RAW)) { |
1da177e4c Linux-2.6.12-rc2 |
811 812 813 814 815 816 |
err = -EPERM; goto exit_f; } opt->opt_nflen += len; opt->hopopt = hdr; break; |
333fad536 [IPV6]: Support s... |
817 |
case IPV6_2292DSTOPTS: |
1ab1457c4 [NET] IPV6: Fix w... |
818 |
if (cmsg->cmsg_len < CMSG_LEN(sizeof(struct ipv6_opt_hdr))) { |
1da177e4c Linux-2.6.12-rc2 |
819 820 821 822 823 824 825 826 827 828 |
err = -EINVAL; goto exit_f; } hdr = (struct ipv6_opt_hdr *)CMSG_DATA(cmsg); len = ((hdr->hdrlen + 1) << 3); if (cmsg->cmsg_len < CMSG_LEN(len)) { err = -EINVAL; goto exit_f; } |
af31f412c net: Allow userns... |
829 |
if (!ns_capable(net->user_ns, CAP_NET_RAW)) { |
1da177e4c Linux-2.6.12-rc2 |
830 831 832 833 834 835 836 837 838 839 |
err = -EPERM; goto exit_f; } if (opt->dst1opt) { err = -EINVAL; goto exit_f; } opt->opt_flen += len; opt->dst1opt = hdr; break; |
333fad536 [IPV6]: Support s... |
840 841 842 843 844 845 846 847 848 849 850 851 852 |
case IPV6_DSTOPTS: case IPV6_RTHDRDSTOPTS: if (cmsg->cmsg_len < CMSG_LEN(sizeof(struct ipv6_opt_hdr))) { err = -EINVAL; goto exit_f; } hdr = (struct ipv6_opt_hdr *)CMSG_DATA(cmsg); len = ((hdr->hdrlen + 1) << 3); if (cmsg->cmsg_len < CMSG_LEN(len)) { err = -EINVAL; goto exit_f; } |
af31f412c net: Allow userns... |
853 |
if (!ns_capable(net->user_ns, CAP_NET_RAW)) { |
333fad536 [IPV6]: Support s... |
854 855 856 857 858 859 860 861 862 863 864 865 866 |
err = -EPERM; goto exit_f; } if (cmsg->cmsg_type == IPV6_DSTOPTS) { opt->opt_flen += len; opt->dst1opt = hdr; } else { opt->opt_nflen += len; opt->dst0opt = hdr; } break; case IPV6_2292RTHDR: |
1da177e4c Linux-2.6.12-rc2 |
867 |
case IPV6_RTHDR: |
1ab1457c4 [NET] IPV6: Fix w... |
868 |
if (cmsg->cmsg_len < CMSG_LEN(sizeof(struct ipv6_rt_hdr))) { |
1da177e4c Linux-2.6.12-rc2 |
869 870 871 872 873 |
err = -EINVAL; goto exit_f; } rthdr = (struct ipv6_rt_hdr *)CMSG_DATA(cmsg); |
280a9d340 [IPV6] MIP6: Add ... |
874 |
switch (rthdr->type) { |
07a936260 ipv6: use IS_ENAB... |
875 |
#if IS_ENABLED(CONFIG_IPV6_MIP6) |
280a9d340 [IPV6] MIP6: Add ... |
876 |
case IPV6_SRCRT_TYPE_2: |
6e093d9df ipv6: routing hea... |
877 878 879 880 881 |
if (rthdr->hdrlen != 2 || rthdr->segments_left != 1) { err = -EINVAL; goto exit_f; } |
280a9d340 [IPV6] MIP6: Add ... |
882 |
break; |
bb4dbf9e6 [IPV6]: Do not se... |
883 |
#endif |
280a9d340 [IPV6] MIP6: Add ... |
884 |
default: |
1da177e4c Linux-2.6.12-rc2 |
885 886 887 888 889 |
err = -EINVAL; goto exit_f; } len = ((rthdr->hdrlen + 1) << 3); |
1ab1457c4 [NET] IPV6: Fix w... |
890 |
if (cmsg->cmsg_len < CMSG_LEN(len)) { |
1da177e4c Linux-2.6.12-rc2 |
891 892 893 894 895 896 897 898 899 900 901 902 |
err = -EINVAL; goto exit_f; } /* segments left must also match */ if ((rthdr->hdrlen >> 1) != rthdr->segments_left) { err = -EINVAL; goto exit_f; } opt->opt_nflen += len; opt->srcrt = rthdr; |
333fad536 [IPV6]: Support s... |
903 |
if (cmsg->cmsg_type == IPV6_2292RTHDR && opt->dst1opt) { |
1da177e4c Linux-2.6.12-rc2 |
904 905 906 907 908 909 910 911 912 |
int dsthdrlen = ((opt->dst1opt->hdrlen+1)<<3); opt->opt_nflen += dsthdrlen; opt->dst0opt = opt->dst1opt; opt->dst1opt = NULL; opt->opt_flen -= dsthdrlen; } break; |
333fad536 [IPV6]: Support s... |
913 |
case IPV6_2292HOPLIMIT: |
1da177e4c Linux-2.6.12-rc2 |
914 915 916 917 918 |
case IPV6_HOPLIMIT: if (cmsg->cmsg_len != CMSG_LEN(sizeof(int))) { err = -EINVAL; goto exit_f; } |
26879da58 ipv6: add new str... |
919 920 |
ipc6->hlimit = *(int *)CMSG_DATA(cmsg); if (ipc6->hlimit < -1 || ipc6->hlimit > 0xff) { |
e8766fc86 ipv6: Check the h... |
921 922 923 |
err = -EINVAL; goto exit_f; } |
1da177e4c Linux-2.6.12-rc2 |
924 |
break; |
41a1f8ea4 [IPV6]: Support I... |
925 926 927 928 929 |
case IPV6_TCLASS: { int tc; err = -EINVAL; |
b5a4257ce net/ipv6/datagram... |
930 |
if (cmsg->cmsg_len != CMSG_LEN(sizeof(int))) |
41a1f8ea4 [IPV6]: Support I... |
931 |
goto exit_f; |
41a1f8ea4 [IPV6]: Support I... |
932 933 |
tc = *(int *)CMSG_DATA(cmsg); |
d0ee011f7 [IPV6]: Accept -1... |
934 |
if (tc < -1 || tc > 0xff) |
41a1f8ea4 [IPV6]: Support I... |
935 936 937 |
goto exit_f; err = 0; |
26879da58 ipv6: add new str... |
938 |
ipc6->tclass = tc; |
41a1f8ea4 [IPV6]: Support I... |
939 940 941 |
break; } |
13b52cd44 IPv6: Add dontfra... |
942 943 944 945 946 947 |
case IPV6_DONTFRAG: { int df; err = -EINVAL; |
b5a4257ce net/ipv6/datagram... |
948 |
if (cmsg->cmsg_len != CMSG_LEN(sizeof(int))) |
13b52cd44 IPv6: Add dontfra... |
949 |
goto exit_f; |
13b52cd44 IPv6: Add dontfra... |
950 951 952 953 954 955 |
df = *(int *)CMSG_DATA(cmsg); if (df < 0 || df > 1) goto exit_f; err = 0; |
26879da58 ipv6: add new str... |
956 |
ipc6->dontfrag = df; |
13b52cd44 IPv6: Add dontfra... |
957 958 959 |
break; } |
1da177e4c Linux-2.6.12-rc2 |
960 |
default: |
ba7a46f16 net: Convert LIMI... |
961 962 963 |
net_dbg_ratelimited("invalid cmsg type: %d ", cmsg->cmsg_type); |
1da177e4c Linux-2.6.12-rc2 |
964 |
err = -EINVAL; |
4a36702e0 IPv6: datagram_se... |
965 |
goto exit_f; |
3ff50b799 [NET]: cleanup ex... |
966 |
} |
1da177e4c Linux-2.6.12-rc2 |
967 968 969 970 971 |
} exit_f: return err; } |
73df66f8b ipv6: rename data... |
972 |
EXPORT_SYMBOL_GPL(ip6_datagram_send_ctl); |
17ef66afc net: ipv6: Unify ... |
973 |
|
6c206b200 udp: fix rx queue... |
974 975 |
void __ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp, __u16 srcp, __u16 destp, int rqueue, int bucket) |
17ef66afc net: ipv6: Unify ... |
976 |
{ |
17ef66afc net: ipv6: Unify ... |
977 |
const struct in6_addr *dest, *src; |
efe4208f4 ipv6: make lookup... |
978 979 |
dest = &sp->sk_v6_daddr; src = &sp->sk_v6_rcv_saddr; |
17ef66afc net: ipv6: Unify ... |
980 981 |
seq_printf(seq, "%5d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X " |
ea9a03791 net: Treat sock->... |
982 983 |
"%02X %08X:%08X %02X:%08lX %08X %5u %8d %lu %d %pK %u ", |
17ef66afc net: ipv6: Unify ... |
984 985 986 987 988 989 990 |
bucket, src->s6_addr32[0], src->s6_addr32[1], src->s6_addr32[2], src->s6_addr32[3], srcp, dest->s6_addr32[0], dest->s6_addr32[1], dest->s6_addr32[2], dest->s6_addr32[3], destp, sp->sk_state, sk_wmem_alloc_get(sp), |
6c206b200 udp: fix rx queue... |
991 |
rqueue, |
17ef66afc net: ipv6: Unify ... |
992 993 994 995 |
0, 0L, 0, from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)), 0, sock_i_ino(sp), |
41c6d650f net: convert sock... |
996 |
refcount_read(&sp->sk_refcnt), sp, |
17ef66afc net: ipv6: Unify ... |
997 998 |
atomic_read(&sp->sk_drops)); } |