net: ipv6: Add IPv6 support to the ping socket.
Subsystems (3)
PATCH 1/1 net: ipv6: Add IPv6 support to the ping socket.
This adds the ability to send ICMPv6 echo requests without a raw socket. The equivalent ability for ICMPv4 was added in 2011.
Instead of having separate code paths for IPv4 and IPv6, make most of the code in net/ipv4/ping.c dual-stack and only add a few IPv6-specific bits (like the protocol definition) to a new net/ipv6/ping.c. Hopefully this will reduce divergence and/or duplication of bugs in the future.
Caveats:
- Setting options via ancillary data (e.g., using IPV6_PKTINFO to specify the outgoing interface) is not yet supported.
- There are no separate security settings for IPv4 and IPv6; everything is controlled by /proc/net/ipv4/ping_group_range.
- The proc interface does not yet display IPv6 ping sockets properly.
Tested with a patched copy of ping6 and using raw socket calls. Compiles and works with all of CONFIG_IPV6={n,m,y}.
--- include/net/ipv6.h | 6 + include/net/ping.h | 49 ++++- include/net/transp_v6.h | 3 + net/ipv4/icmp.c | 5 +- net/ipv4/ping.c | 557 ++++++++++++++++++++++++++++++++++-------------- net/ipv6/Makefile | 2 +- net/ipv6/af_inet6.c | 12 ++ net/ipv6/icmp.c | 19 +- net/ipv6/ping.c | 216 +++++++++++++++++++ 9 files changed, 698 insertions(+), 171 deletions(-) create mode 100644 net/ipv6/ping.c
include/net/ipv6.h +6 -0
@@ -260,6 +260,12 @@ static inline void fl6_sock_release(struct ip6_flowlabel *fl)extern void icmpv6_notify (struct sk_buff *skb,u8 type,u8 code,__be32 info); +int icmpv6_push_pending_frames (struct sock *sk,struct flowi6 *fl6, +struct icmp6hdr *thdr,int len); + +struct dst_entry *icmpv6_route_lookup (struct net *net,struct sk_buff *skb, +struct sock *sk,struct flowi6 *fl6); +extern int ip6_ra_control (struct sock *sk,int sel);extern int ipv6_parse_hopopts (struct sk_buff *skb);
include/net/ping.h +46 -3
74 lines not on this page · raw message
include/net/transp_v6.h +3 -0
@@ -11,6 +11,7 @@ extern struct proto rawv6_prot;extern struct proto udpv6_prot;extern struct proto udplitev6_prot;extern struct proto tcpv6_prot; +extern struct proto pingv6_prot;struct flowi6 ;
@@ -21,6 +22,8 @@ extern int ipv6_frag_init(void);extern void ipv6_frag_exit (void );/* transport protocols */ +extern int pingv6_init (void ); +extern void pingv6_exit (void );extern int rawv6_init (void );extern void rawv6_exit (void );extern int udpv6_init (void );
net/ipv4/icmp.c +3 -2
@@ -939,7 +939,8 @@ error:void icmp_err (struct sk_buff *skb,u32 info) {struct iphdr *iph = (struct iphdr *)skb->data; -struct icmphdr *icmph = (struct icmphdr *)(skb->data+(iph->ihl<<2 )); +int offset = iph->ihl<<2 ; +struct icmphdr *icmph = (struct icmphdr *)(skb->data + offset);int type =icmp_hdr (skb)->type;int code =icmp_hdr (skb)->code;struct net *net =dev_net (skb->dev);
@@ -949,7 +950,7 @@ void icmp_err(struct sk_buff *skb, u32 info)* triggered by ICMP_ECHOREPLY which sent from kernel. */ if (icmph->type !=ICMP_ECHOREPLY ) { -ping_err (skb, info); +ping_err (skb, offset, info);return ; }
net/ipv4/ping.c +397 -160
835 lines not on this page · raw message
net/ipv6/Makefile +1 -1
@@ -7,7 +7,7 @@ obj-$(CONFIG_IPV6) += ipv6.o ipv6-objs := af_inet6.o anycast.o ip6_output.o ip6_input.o addrconf.o \ addrlabel.o \ route.o ip6_fib.o ipv6_sockglue.o ndisc.o udp.o udplite.o \ - raw.o icmp.o mcast.o reassembly.o tcp_ipv6.o \ + raw.o icmp.o mcast.o reassembly.o tcp_ipv6.o ping.o \ exthdrs.o datagram.o ip6_flowlabel.o inet6_connection_sock.o ipv6-offload := ip6_offload.o tcpv6_offload.o udp_offload.o exthdrs_offload.o
net/ipv6/af_inet6.c +12 -0
@@ -49,6 +49,7 @@#include <net/udp.h> #include <net/udplite.h> #include <net/tcp.h> +#include <net/ping.h> #include <net/protocol.h> #include <net/inet_common.h> #include <net/route.h>
@@ -840,6 +841,9 @@ static int __init inet6_init(void)if (err) goto out_unregister_udplite_proto; + err =proto_register (&pingv6_prot,1 ); +if (err) + goto out_unregister_ping_proto;/* We MUST register RAW sockets before we create the ICMP6, * IGMP6, or NDISC control sockets.
@@ -930,6 +934,10 @@ static int __init inet6_init(void)if (err) goto ipv6_packet_fail; + err =pingv6_init (); +if (err) + goto pingv6_fail; +#ifdef CONFIG_SYSCTL err =ipv6_sysctl_register ();if (err)
@@ -942,6 +950,8 @@ out: sysctl_fail:ipv6_packet_cleanup ();#endif +pingv6_fail: +pingv6_exit (); ipv6_packet_fail:tcpv6_exit (); tcpv6_fail:
@@ -985,6 +995,8 @@ register_pernet_fail:rtnl_unregister_all (PF_INET6 ); out_sock_register_fail:rawv6_exit (); +out_unregister_ping_proto: +proto_unregister (&pingv6_prot); out_unregister_raw_proto:proto_unregister (&rawv6_prot); out_unregister_udplite_proto:
net/ipv6/icmp.c +14 -5
@@ -57,6 +57,7 @@#include <net/ipv6.h> #include <net/ip6_checksum.h> +#include <net/ping.h> #include <net/protocol.h> #include <net/raw.h> #include <net/rawv6.h>
@@ -84,12 +85,18 @@ static inline struct sock *icmpv6_sk(struct net *net)static void icmpv6_err (struct sk_buff *skb,struct inet6_skb_parm *opt,u8 type,u8 code,int offset,__be32 info) { +/* icmpv6_notify checks 8 bytes can be pulled, icmp6hdr is 8 bytes */ +struct icmp6hdr *icmp6 = (struct icmp6hdr *) (skb->data + offset);struct net *net =dev_net (skb->dev);if (type ==ICMPV6_PKT_TOOBIG )ip6_update_pmtu (skb, net, info,0 ,0 );else if (type ==NDISC_REDIRECT )ip6_redirect (skb, net,0 ,0 ); + +if (!(type &ICMPV6_INFOMSG_MASK )) +if (icmp6->icmp6_type ==ICMPV6_ECHO_REQUEST ) +ping_err (skb, offset, info); }static int icmpv6_rcv (struct sk_buff *skb);
@@ -224,7 +231,8 @@ static bool opt_unrec(struct sk_buff *skb, __u32 offset)return (*op &0xC0 ) ==0x80 ; } -static int icmpv6_push_pending_frames (struct sock *sk,struct flowi6 *fl6,struct icmp6hdr *thdr,int len) +int icmpv6_push_pending_frames (struct sock *sk,struct flowi6 *fl6, +struct icmp6hdr *thdr,int len) {struct sk_buff *skb;struct icmp6hdr *icmp6h;
@@ -307,8 +315,8 @@ static void mip6_addr_swap(struct sk_buff *skb)static inline void mip6_addr_swap (struct sk_buff *skb) {}#endif -static struct dst_entry *icmpv6_route_lookup (struct net *net,struct sk_buff *skb, -struct sock *sk,struct flowi6 *fl6) +struct dst_entry *icmpv6_route_lookup (struct net *net,struct sk_buff *skb, +struct sock *sk,struct flowi6 *fl6) {struct dst_entry *dst, *dst2;struct flowi6 fl2;
@@ -697,7 +705,8 @@ static int icmpv6_rcv(struct sk_buff *skb) skb->csum = ~csum_unfold (csum_ipv6_magic (saddr, daddr, skb->len,IPPROTO_ICMPV6 ,0 ));if (__skb_checksum_complete (skb)) { -LIMIT_NETDEBUG (KERN_DEBUG "ICMPv6 checksum failed [%pI6 > %pI6]\n" , +LIMIT_NETDEBUG (KERN_DEBUG +"ICMPv6 checksum failed [%pI6c > %pI6c]\n" , saddr, daddr); goto csum_error; }
@@ -718,7 +727,7 @@ static int icmpv6_rcv(struct sk_buff *skb)break ;case ICMPV6_ECHO_REPLY : -/* we couldn't care less */ +ping_rcv (skb);break ;case ICMPV6_PKT_TOOBIG :
net/ipv6/ping.c new file +216 -0
216 lines not on this page · raw message
Signature · 1 line
1.8.2.1
David Miller
maintainerFrom: Lorenzo Colitti <[email protected]>
Date: Thu, 23 May 2013 15:17:31 +0900
Quoted 19 lines
This adds the ability to send ICMPv6 echo requests without a raw socket. The equivalent ability for ICMPv4 was added in 2011.
Instead of having separate code paths for IPv4 and IPv6, make most of the code in
net/ipv4/ping.cdual-stack and only add a few IPv6-specific bits (like the protocol definition) to a newnet/ipv6/ping.c. Hopefully this will reduce divergence and/or duplication of bugs in the future.Caveats:
- Setting options via ancillary data (e.g., using
IPV6_PKTINFOto specify the outgoing interface) is not yet supported.
- There are no separate security settings for IPv4 and IPv6; everything is controlled by/proc/net/ipv4/ping_group_range.
- The proc interface does not yet display IPv6 ping sockets properly.
Quoted 4 lines
Tested with a patched copy of ping6 and using raw socket calls. Compiles and works with all of
CONFIG_IPV6={n,m,y}.Signed-off-by Lorenzo Colitti <[email protected]>
Ok, looks pretty good, applied.