From: Lorenzo Colitti <lorenzo@google.com>
To: netdev@vger.kernel.org
Cc: yoshfuji@linux-ipv6.org, hannes@stressinduktion.org,
davem@davemloft.net, eric.dumazet@gmail.com,
Lorenzo Colitti <lorenzo@google.com>
Subject: [PATCH net-next v3 3/3] net: ipv6: Use ip6_datagram_send_common in ping.
Date: Wed, 23 Apr 2014 00:14:16 +0900 [thread overview]
Message-ID: <1398179656-9313-3-git-send-email-lorenzo@google.com> (raw)
In-Reply-To: <1398179656-9313-1-git-send-email-lorenzo@google.com>
This replaces the ad-hoc code used by ping6_sendmsg with the
implementation now used by UDP, raw and L2TP sockets. This also
adds the ability to set options via ancillary data, proper
flowlabel validation, etc. etc.
Tested: Black-box tested using user-mode Linux.
- IPv6 pings using both connect()/send() and sendto() still work.
- Fragmented IPv6 pings still work.
- Specifying a flowlabel still works.
- Attempting to send a flowlabel that is not first set via
IPV6_FLOWLABEL_MGR now correctly returns EINVAL.
Signed-off-by: Lorenzo Colitti <lorenzo@google.com>
---
net/ipv6/ping.c | 95 +++++++++++++++++++--------------------------------------
1 file changed, 31 insertions(+), 64 deletions(-)
diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
index bda7429..96730c6 100644
--- a/net/ipv6/ping.c
+++ b/net/ipv6/ping.c
@@ -81,16 +81,17 @@ static int dummy_ipv6_chk_addr(struct net *net, const struct in6_addr *addr,
int ping_v6_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
size_t len)
{
+ DECLARE_SOCKADDR(struct sockaddr_in6 *, sin6, msg->msg_name);
struct inet_sock *inet = inet_sk(sk);
- struct ipv6_pinfo *np = inet6_sk(sk);
+ struct ipv6_txoptions *opt, opt_space;
struct icmp6hdr user_icmph;
- int addr_type;
+ int addr_len = msg->msg_namelen;
struct in6_addr *daddr;
- int iif = 0;
struct flowi6 fl6;
int err;
- int hlimit;
- struct dst_entry *dst;
+ int hlimit, tclass, dontfrag;
+ int connected;
+ struct dst_entry *dst = NULL;
struct rt6_info *rt;
struct pingfakehdr pfh;
@@ -101,63 +102,38 @@ int ping_v6_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
if (err)
return err;
- if (msg->msg_name) {
- DECLARE_SOCKADDR(struct sockaddr_in6 *, u, msg->msg_name);
- if (msg->msg_namelen < sizeof(struct sockaddr_in6) ||
- u->sin6_family != AF_INET6) {
+ if (sin6) {
+ if (addr_len < sizeof(struct sockaddr_in6))
return -EINVAL;
- }
- if (sk->sk_bound_dev_if &&
- sk->sk_bound_dev_if != u->sin6_scope_id) {
- return -EINVAL;
- }
- daddr = &(u->sin6_addr);
- iif = u->sin6_scope_id;
+
+ if (sin6->sin6_family != AF_INET6)
+ return -EAFNOSUPPORT;
+
+ daddr = &sin6->sin6_addr;
} else {
- if (sk->sk_state != TCP_ESTABLISHED)
- return -EDESTADDRREQ;
daddr = &sk->sk_v6_daddr;
}
- if (!iif)
- iif = sk->sk_bound_dev_if;
-
- addr_type = ipv6_addr_type(daddr);
- if (__ipv6_addr_needs_scope_id(addr_type) && !iif)
- return -EINVAL;
- if (addr_type & IPV6_ADDR_MAPPED)
+ if (ipv6_addr_v4mapped(daddr))
return -EINVAL;
- /* TODO: use ip6_datagram_send_ctl to get options from cmsg */
-
memset(&fl6, 0, sizeof(fl6));
-
fl6.flowi6_proto = IPPROTO_ICMPV6;
- fl6.saddr = np->saddr;
- fl6.daddr = *daddr;
- fl6.flowi6_mark = sk->sk_mark;
fl6.fl6_icmp_type = user_icmph.icmp6_type;
fl6.fl6_icmp_code = user_icmph.icmp6_code;
- security_sk_classify_flow(sk, flowi6_to_flowi(&fl6));
- if (!fl6.flowi6_oif && ipv6_addr_is_multicast(&fl6.daddr))
- fl6.flowi6_oif = np->mcast_oif;
- else if (!fl6.flowi6_oif)
- fl6.flowi6_oif = np->ucast_oif;
-
- dst = ip6_sk_dst_lookup_flow(sk, &fl6, daddr);
- if (IS_ERR(dst))
- return PTR_ERR(dst);
- rt = (struct rt6_info *) dst;
-
- np = inet6_sk(sk);
- if (!np)
- return -EBADF;
+ err = ip6_datagram_send_common(sk, msg, sin6, addr_len, &fl6, &dst,
+ &opt, &opt_space, &hlimit, &tclass,
+ &dontfrag, &connected);
+ if (err)
+ goto out;
- if (!fl6.flowi6_oif && ipv6_addr_is_multicast(&fl6.daddr))
- fl6.flowi6_oif = np->mcast_oif;
- else if (!fl6.flowi6_oif)
- fl6.flowi6_oif = np->ucast_oif;
+ /* TODO: Move this check into ip6_datagram_sendmsg. */
+ if (__ipv6_addr_needs_scope_id(__ipv6_addr_type(daddr)) &&
+ !fl6.flowi6_oif) {
+ err = -EINVAL;
+ goto out;
+ }
pfh.icmph.type = user_icmph.icmp6_type;
pfh.icmph.code = user_icmph.icmp6_code;
@@ -168,18 +144,10 @@ int ping_v6_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
pfh.wcheck = 0;
pfh.family = AF_INET6;
- if (ipv6_addr_is_multicast(&fl6.daddr))
- hlimit = np->mcast_hops;
- else
- hlimit = np->hop_limit;
- if (hlimit < 0)
- hlimit = ip6_dst_hoplimit(dst);
-
+ rt = (struct rt6_info *) dst;
lock_sock(sk);
- err = ip6_append_data(sk, ping_getfrag, &pfh, len,
- 0, hlimit,
- np->tclass, NULL, &fl6, rt,
- MSG_DONTWAIT, np->dontfrag);
+ err = ip6_append_data(sk, ping_getfrag, &pfh, len, 0, hlimit, tclass,
+ opt, &fl6, rt, msg->msg_flags, dontfrag);
if (err) {
ICMP6_INC_STATS(sock_net(sk), rt->rt6i_idev,
@@ -192,10 +160,9 @@ int ping_v6_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
}
release_sock(sk);
- if (err)
- return err;
-
- return len;
+out:
+ dst_release(dst);
+ return err ? err : len;
}
#ifdef CONFIG_PROC_FS
--
1.9.1.423.g4596e3a
next prev parent reply other threads:[~2014-04-22 15:14 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-22 8:13 [PATCH net-next 1/3] net: ipv6: unduplicate {raw,udp}v6_sendmsg code Lorenzo Colitti
2014-04-22 8:13 ` [PATCH net-next 2/3] net: ipv6: Use ip6_datagram_send_common in L2TP IPv6 Lorenzo Colitti
2014-04-22 8:13 ` [PATCH net-next 3/3] net: ipv6: Use ip6_datagram_send_common in ping Lorenzo Colitti
2014-04-22 9:06 ` [PATCH net-next 1/3] net: ipv6: unduplicate {raw,udp}v6_sendmsg code YOSHIFUJI Hideaki
2014-04-22 9:38 ` [PATCH net-next v2 " Lorenzo Colitti
2014-04-22 9:38 ` [PATCH net-next v2 2/3] net: ipv6: Use ip6_datagram_send_common in L2TP IPv6 Lorenzo Colitti
2014-04-22 14:23 ` Eric Dumazet
2014-04-22 15:11 ` Lorenzo Colitti
2014-04-22 9:38 ` [PATCH net-next v2 3/3] net: ipv6: Use ip6_datagram_send_common in ping Lorenzo Colitti
2014-04-22 15:14 ` [PATCH net-next v3 1/3] net: ipv6: Unduplicate {raw,udp}v6_sendmsg code Lorenzo Colitti
2014-04-22 15:14 ` [PATCH net-next v3 2/3] net: ipv6: Use ip6_datagram_send_common in L2TP IPv6 Lorenzo Colitti
2014-04-22 15:14 ` Lorenzo Colitti [this message]
2014-04-22 15:48 ` [PATCH net-next v3 1/3] net: ipv6: Unduplicate {raw,udp}v6_sendmsg code Hannes Frederic Sowa
2014-04-23 6:37 ` Lorenzo Colitti
2014-04-22 15:59 ` Eric Dumazet
2014-04-23 6:38 ` Lorenzo Colitti
2014-04-23 6:37 ` [PATCH net-next v4 " Lorenzo Colitti
2014-04-23 6:37 ` [PATCH net-next v4 2/3] net: ipv6: Use ip6_datagram_send_common in L2TP IPv6 Lorenzo Colitti
2014-04-23 6:37 ` [PATCH net-next v4 3/3] net: ipv6: Use ip6_datagram_send_common in ping Lorenzo Colitti
2014-04-23 11:11 ` Florent Fourcot
2014-04-23 12:22 ` Lorenzo Colitti
2014-04-24 15:06 ` Hannes Frederic Sowa
2014-04-24 15:35 ` Lorenzo Colitti
2014-04-24 16:06 ` Lorenzo Colitti
2014-04-24 15:00 ` [PATCH net-next v4 1/3] net: ipv6: Unduplicate {raw,udp}v6_sendmsg code Hannes Frederic Sowa
2014-04-24 15:02 ` Hannes Frederic Sowa
2014-04-24 15:13 ` Lorenzo Colitti
2014-04-24 15:43 ` Hannes Frederic Sowa
2014-04-25 11:09 ` Lorenzo Colitti
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1398179656-9313-3-git-send-email-lorenzo@google.com \
--to=lorenzo@google.com \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=hannes@stressinduktion.org \
--cc=netdev@vger.kernel.org \
--cc=yoshfuji@linux-ipv6.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).