* [PATCH net-next] ipv6: raw: use IPv4 raw_sendmsg on v4-mapped IPv6 destinations
@ 2018-01-25 1:43 Ivan Delalande
2018-01-25 17:07 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Ivan Delalande @ 2018-01-25 1:43 UTC (permalink / raw)
To: David Miller; +Cc: netdev
Make IPv6 SOCK_RAW sockets operate like IPv6 UDP and TCP sockets with
respect to IPv4 mapped addresses by calling IPv4 raw_sendmsg from
rawv6_sendmsg to send those messages out.
Signed-off-by: Travis Brown <travisb@arista.com>
Signed-off-by: Ivan Delalande <colona@arista.com>
---
include/net/raw.h | 1 +
net/ipv4/raw.c | 5 +++--
net/ipv6/raw.c | 14 ++++++++++++++
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/include/net/raw.h b/include/net/raw.h
index 99d26d0c4a19..b4dbf730da54 100644
--- a/include/net/raw.h
+++ b/include/net/raw.h
@@ -33,6 +33,7 @@ void raw_icmp_error(struct sk_buff *, int, u32);
int raw_local_deliver(struct sk_buff *, int);
int raw_rcv(struct sock *, struct sk_buff *);
+int rawv4_sendmsg(struct sock *sk, struct msghdr *msg, size_t len);
#define RAW_HTABLE_SIZE MAX_INET_PROTOS
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
index 136544b36a46..09f719af8642 100644
--- a/net/ipv4/raw.c
+++ b/net/ipv4/raw.c
@@ -499,7 +499,7 @@ static int raw_getfrag(void *from, char *to, int offset, int len, int odd,
return ip_generic_getfrag(rfv->msg, to, offset, len, odd, skb);
}
-static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
+int rawv4_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
{
struct inet_sock *inet = inet_sk(sk);
struct net *net = sock_net(sk);
@@ -692,6 +692,7 @@ static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
err = 0;
goto done;
}
+EXPORT_SYMBOL_GPL(rawv4_sendmsg);
static void raw_close(struct sock *sk, long timeout)
{
@@ -969,7 +970,7 @@ struct proto raw_prot = {
.init = raw_init,
.setsockopt = raw_setsockopt,
.getsockopt = raw_getsockopt,
- .sendmsg = raw_sendmsg,
+ .sendmsg = rawv4_sendmsg,
.recvmsg = raw_recvmsg,
.bind = raw_bind,
.backlog_rcv = raw_rcv_skb,
diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
index ddda7eb3c623..f8513e2f1481 100644
--- a/net/ipv6/raw.c
+++ b/net/ipv6/raw.c
@@ -844,6 +844,20 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
fl6.flowlabel = np->flow_label;
}
+ if (daddr && ipv6_addr_v4mapped(daddr)) {
+ struct sockaddr_in sin;
+
+ sin.sin_family = AF_INET;
+ sin.sin_port = sin6 ? sin6->sin6_port : inet->inet_dport;
+ sin.sin_addr.s_addr = daddr->s6_addr32[3];
+ msg->msg_name = &sin;
+ msg->msg_namelen = sizeof(sin);
+
+ if (__ipv6_only_sock(sk))
+ return -ENETUNREACH;
+ return rawv4_sendmsg(sk, msg, len);
+ }
+
if (fl6.flowi6_oif == 0)
fl6.flowi6_oif = sk->sk_bound_dev_if;
--
2.16.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next] ipv6: raw: use IPv4 raw_sendmsg on v4-mapped IPv6 destinations
2018-01-25 1:43 [PATCH net-next] ipv6: raw: use IPv4 raw_sendmsg on v4-mapped IPv6 destinations Ivan Delalande
@ 2018-01-25 17:07 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2018-01-25 17:07 UTC (permalink / raw)
To: colona; +Cc: netdev
From: Ivan Delalande <colona@arista.com>
Date: Wed, 24 Jan 2018 17:43:43 -0800
> Make IPv6 SOCK_RAW sockets operate like IPv6 UDP and TCP sockets with
> respect to IPv4 mapped addresses by calling IPv4 raw_sendmsg from
> rawv6_sendmsg to send those messages out.
>
> Signed-off-by: Travis Brown <travisb@arista.com>
> Signed-off-by: Ivan Delalande <colona@arista.com>
For RAW sockets this doesn't make any sense.
Especially when header-include is enabled, one expects the application
to provide an address-family appropriate protocol header in it's
buffer.
Which means ipv4 for ipv4 sockets and ipv6 for ipv6 sockets.
So we should interpret the request as an ipv6 one regardless of
whether the ipv6 destination is ipv4 mapped or not.
Thank you.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-01-25 17:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-25 1:43 [PATCH net-next] ipv6: raw: use IPv4 raw_sendmsg on v4-mapped IPv6 destinations Ivan Delalande
2018-01-25 17:07 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).