All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next V6 0/6] add support for RFC 8335 PROBE
@ 2021-03-30  1:45 Andreas Roeseler
  2021-03-30  1:45 ` [PATCH net-next V6 1/6] icmp: " Andreas Roeseler
                   ` (6 more replies)
  0 siblings, 7 replies; 11+ messages in thread
From: Andreas Roeseler @ 2021-03-30  1:45 UTC (permalink / raw)
  To: netdev; +Cc: davem, yoshfuji, dsahern, kuba, Andreas Roeseler

The popular utility ping has several severe limitations, such as the
inability to query specific interfaces on a node and requiring
bidirectional connectivity between the probing and probed interfaces.
RFC 8335 attempts to solve these limitations by creating the new utility
PROBE which is a specialized ICMP message that makes use of the ICMP
Extension Structure outlined in RFC 4884.

This patchset adds definitions for the ICMP Extended Echo Request and
Reply (PROBE) types for both IPV4 and IPV6, adds a sysctl to enable
responses to PROBE messages, expands the list of supported ICMP messages
to accommodate PROBE types, adds ipv6_dev_find into ipv6_stubs, and adds
functionality to respond to PROBE requests.

Changes:
v1 -> v2:
 - Add AFI definitions
 - Switch to functions such as dev_get_by_name and ip_dev_find to lookup
   net devices

v2 -> v3:
Suggested by Willem de Bruijn <willemdebruijn.kernel@gmail.com>
 - Add verification of incoming messages before looking up netdev
 - Add prefix for PROBE specific defined variables
 - Use proc_dointvec_minmax with zero and one for sysctl
 - Create struct icmp_ext_echo_iio for parsing incoming packets
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
 - Include net/addrconf.h library for ipv6_dev_find

v3 -> v4:
 - Use in_addr instead of __be32 for storing IPV4 addresses
 - Use IFNAMSIZ to statically allocate space for name in
   icmp_ext_echo_iio
Suggested by Willem de Bruijn <willemdebruijn.kernel@gmail.com>
 - Use skb_header_pointer to verify fields in incoming message
 - Add check to ensure that extobj_hdr.length is valid
 - Check to ensure object payload is padded with ASCII NULL characters
   when probing by name, as specified by RFC 8335
 - Statically allocate buff using IFNAMSIZ
 - Add rcu blocking around ipv6_dev_find
 - Use __in_dev_get_rcu to access IPV4 addresses of identified
   net_device
 - Remove check for ICMPV6 PROBE types

v4 -> v5:
 - Statically allocate buff to size IFNAMSIZ on declaration
 - Remove goto probe in favor of single branch
 - Remove strict check for incoming PROBE request padding to nearest
   32-bit boundary
Reported-by: kernel test robot <lkp@intel.com>

v5 -> v6: 
 - Add documentation for icmp_echo_enable_probe sysctl
 - Remove RCU locking around ipv6_dev_find()
 - Assign iio based on ctype

Andreas Roeseler (6):
  icmp: add support for RFC 8335 PROBE
  ICMPV6: add support for RFC 8335 PROBE
  net: add sysctl for enabling RFC 8335 PROBE messages
  net: add support for sending RFC 8335 PROBE messages
  ipv6: add ipv6_dev_find to stubs
  icmp: add response to RFC 8335 PROBE messages

 Documentation/networking/ip-sysctl.rst |   6 ++
 include/net/ipv6_stubs.h               |   2 +
 include/net/netns/ipv4.h               |   1 +
 include/uapi/linux/icmp.h              |  42 ++++++++
 include/uapi/linux/icmpv6.h            |   3 +
 net/ipv4/icmp.c                        | 134 ++++++++++++++++++++++---
 net/ipv4/ping.c                        |   4 +-
 net/ipv4/sysctl_net_ipv4.c             |   9 ++
 net/ipv6/addrconf_core.c               |   7 ++
 net/ipv6/af_inet6.c                    |   1 +
 10 files changed, 195 insertions(+), 14 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH net-next V6 1/6] icmp: add support for RFC 8335 PROBE
  2021-03-30  1:45 [PATCH net-next V6 0/6] add support for RFC 8335 PROBE Andreas Roeseler
@ 2021-03-30  1:45 ` Andreas Roeseler
  2021-06-02 17:58   ` Florian Weimer
  2021-03-30  1:45 ` [PATCH net-next V6 2/6] ICMPV6: " Andreas Roeseler
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 11+ messages in thread
From: Andreas Roeseler @ 2021-03-30  1:45 UTC (permalink / raw)
  To: netdev; +Cc: davem, yoshfuji, dsahern, kuba, Andreas Roeseler

Add definitions for PROBE ICMP types and codes.

Add AFI definitions for IP and IPV6 as specified by IANA

Add a struct to represent the additional header when probing by IP
address (ctype == 3) for use in parsing incoming PROBE messages

Add a struct to represent the entire Interface Identification Object
(IIO) section of an incoming PROBE packet

Signed-off-by: Andreas Roeseler <andreas.a.roeseler@gmail.com>
---
Changes:
v1 -> v2:
 - Add AFI_IP and AFI_IP6 definitions

v2 -> v3:
Suggested by Willem de Bruijn <willemdebruijn.kernel@gmail.com>
 - Add prefix for PROBE specific defined variables
 - Create struct icmp_ext_echo_iio for parsing incoming packet

v3 -> v4:
 - Use in_addr instead of __be32 for storing IPV4 addresses
 - Use IFNAMSIZ to statically allocate space for name in
   icmp_ext_echo_iio 

v4 -> v5:
 - Use __be32 instead of __u32 in defined structs
---
 include/uapi/linux/icmp.h | 42 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/include/uapi/linux/icmp.h b/include/uapi/linux/icmp.h
index fb169a50895e..222325d1d80e 100644
--- a/include/uapi/linux/icmp.h
+++ b/include/uapi/linux/icmp.h
@@ -20,6 +20,9 @@
 
 #include <linux/types.h>
 #include <asm/byteorder.h>
+#include <linux/in.h>
+#include <linux/if.h>
+#include <linux/in6.h>
 
 #define ICMP_ECHOREPLY		0	/* Echo Reply			*/
 #define ICMP_DEST_UNREACH	3	/* Destination Unreachable	*/
@@ -66,6 +69,23 @@
 #define ICMP_EXC_TTL		0	/* TTL count exceeded		*/
 #define ICMP_EXC_FRAGTIME	1	/* Fragment Reass time exceeded	*/
 
+/* Codes for EXT_ECHO (PROBE) */
+#define ICMP_EXT_ECHO		42
+#define ICMP_EXT_ECHOREPLY	43
+#define ICMP_EXT_MAL_QUERY	1	/* Malformed Query */
+#define ICMP_EXT_NO_IF		2	/* No such Interface */
+#define ICMP_EXT_NO_TABLE_ENT	3	/* No such Table Entry */
+#define ICMP_EXT_MULT_IFS	4	/* Multiple Interfaces Satisfy Query */
+
+/* Constants for EXT_ECHO (PROBE) */
+#define EXT_ECHOREPLY_ACTIVE	(1 << 2)/* active bit in reply message */
+#define EXT_ECHOREPLY_IPV4	(1 << 1)/* ipv4 bit in reply message */
+#define EXT_ECHOREPLY_IPV6	1	/* ipv6 bit in reply message */
+#define EXT_ECHO_CTYPE_NAME	1
+#define EXT_ECHO_CTYPE_INDEX	2
+#define EXT_ECHO_CTYPE_ADDR	3
+#define ICMP_AFI_IP		1	/* Address Family Identifier for ipv4 */
+#define ICMP_AFI_IP6		2	/* Address Family Identifier for ipv6 */
 
 struct icmphdr {
   __u8		type;
@@ -118,4 +138,26 @@ struct icmp_extobj_hdr {
 	__u8		class_type;
 };
 
+/* RFC 8335: 2.1 Header for c-type 3 payload */
+struct icmp_ext_echo_ctype3_hdr {
+	__be16		afi;
+	__u8		addrlen;
+	__u8		reserved;
+};
+
+/* RFC 8335: 2.1 Interface Identification Object */
+struct icmp_ext_echo_iio {
+	struct icmp_extobj_hdr extobj_hdr;
+	union {
+		char name[IFNAMSIZ];
+		__be32 ifindex;
+		struct {
+			struct icmp_ext_echo_ctype3_hdr ctype3_hdr;
+			union {
+				struct in_addr	ipv4_addr;
+				struct in6_addr	ipv6_addr;
+			} ip_addr;
+		} addr;
+	} ident;
+};
 #endif /* _UAPI_LINUX_ICMP_H */
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next V6 2/6] ICMPV6: add support for RFC 8335 PROBE
  2021-03-30  1:45 [PATCH net-next V6 0/6] add support for RFC 8335 PROBE Andreas Roeseler
  2021-03-30  1:45 ` [PATCH net-next V6 1/6] icmp: " Andreas Roeseler
@ 2021-03-30  1:45 ` Andreas Roeseler
  2021-03-30  1:45 ` [PATCH net-next V6 3/6] net: add sysctl for enabling RFC 8335 PROBE messages Andreas Roeseler
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Andreas Roeseler @ 2021-03-30  1:45 UTC (permalink / raw)
  To: netdev; +Cc: davem, yoshfuji, dsahern, kuba, Andreas Roeseler

Add definitions for the ICMPV6 type of Extended Echo Request and
Extended Echo Reply, as defined by sections 2 and 3 of RFC 8335.

Signed-off-by: Andreas Roeseler <andreas.a.roeseler@gmail.com>
---
 include/uapi/linux/icmpv6.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/uapi/linux/icmpv6.h b/include/uapi/linux/icmpv6.h
index 0564fd7ccde4..ecaece3af38d 100644
--- a/include/uapi/linux/icmpv6.h
+++ b/include/uapi/linux/icmpv6.h
@@ -140,6 +140,9 @@ struct icmp6hdr {
 #define ICMPV6_UNK_OPTION		2
 #define ICMPV6_HDR_INCOMP		3
 
+/* Codes for EXT_ECHO (PROBE) */
+#define ICMPV6_EXT_ECHO_REQUEST		160
+#define ICMPV6_EXT_ECHO_REPLY		161
 /*
  *	constants for (set|get)sockopt
  */
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next V6 3/6] net: add sysctl for enabling RFC 8335 PROBE messages
  2021-03-30  1:45 [PATCH net-next V6 0/6] add support for RFC 8335 PROBE Andreas Roeseler
  2021-03-30  1:45 ` [PATCH net-next V6 1/6] icmp: " Andreas Roeseler
  2021-03-30  1:45 ` [PATCH net-next V6 2/6] ICMPV6: " Andreas Roeseler
@ 2021-03-30  1:45 ` Andreas Roeseler
  2021-03-30  1:45 ` [PATCH net-next V6 4/6] net: add support for sending " Andreas Roeseler
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Andreas Roeseler @ 2021-03-30  1:45 UTC (permalink / raw)
  To: netdev; +Cc: davem, yoshfuji, dsahern, kuba, Andreas Roeseler

Section 8 of RFC 8335 specifies potential security concerns of
responding to PROBE requests, and states that nodes that support PROBE
functionality MUST be able to enable/disable responses and that
responses MUST be disabled by default

Signed-off-by: Andreas Roeseler <andreas.a.roeseler@gmail.com>
---
Changes:
v1 -> v2:
 - Combine patches related to sysctl

v2 -> v3:
Suggested by Willem de Bruijn <willemdebruijn.kernel@gmail.com>
 - Use proc_dointvec_minmax with zero and one

v5 -> v6:
 - Add documentation to ip-sysctl.rst
---
 Documentation/networking/ip-sysctl.rst | 6 ++++++
 include/net/netns/ipv4.h               | 1 +
 net/ipv4/sysctl_net_ipv4.c             | 9 +++++++++
 3 files changed, 16 insertions(+)

diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst
index c7952ac5bd2f..4130bce40765 100644
--- a/Documentation/networking/ip-sysctl.rst
+++ b/Documentation/networking/ip-sysctl.rst
@@ -1143,6 +1143,12 @@ icmp_echo_ignore_all - BOOLEAN
 
 	Default: 0
 
+icmp_echo_enable_probe - BOOLEAN
+        If set to one, then the kernel will respond to RFC 8335 PROBE
+        requests sent to it.
+
+        Default: 0
+
 icmp_echo_ignore_broadcasts - BOOLEAN
 	If set non-zero, then the kernel will ignore all ICMP ECHO and
 	TIMESTAMP requests sent to it via broadcast/multicast.
diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
index d377266d133f..9c8dd424d79b 100644
--- a/include/net/netns/ipv4.h
+++ b/include/net/netns/ipv4.h
@@ -84,6 +84,7 @@ struct netns_ipv4 {
 #endif
 
 	u8 sysctl_icmp_echo_ignore_all;
+	u8 sysctl_icmp_echo_enable_probe;
 	u8 sysctl_icmp_echo_ignore_broadcasts;
 	u8 sysctl_icmp_ignore_bogus_error_responses;
 	u8 sysctl_icmp_errors_use_inbound_ifaddr;
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
index 442ff4be1bde..b1a340e8738f 100644
--- a/net/ipv4/sysctl_net_ipv4.c
+++ b/net/ipv4/sysctl_net_ipv4.c
@@ -599,6 +599,15 @@ static struct ctl_table ipv4_net_table[] = {
 		.mode		= 0644,
 		.proc_handler	= proc_dou8vec_minmax,
 	},
+	{
+		.procname	= "icmp_echo_enable_probe",
+		.data		= &init_net.ipv4.sysctl_icmp_echo_enable_probe,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE
+	},
 	{
 		.procname	= "icmp_echo_ignore_broadcasts",
 		.data		= &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next V6 4/6] net: add support for sending RFC 8335 PROBE messages
  2021-03-30  1:45 [PATCH net-next V6 0/6] add support for RFC 8335 PROBE Andreas Roeseler
                   ` (2 preceding siblings ...)
  2021-03-30  1:45 ` [PATCH net-next V6 3/6] net: add sysctl for enabling RFC 8335 PROBE messages Andreas Roeseler
@ 2021-03-30  1:45 ` Andreas Roeseler
  2021-03-30  1:45 ` [PATCH net-next V6 5/6] ipv6: add ipv6_dev_find to stubs Andreas Roeseler
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Andreas Roeseler @ 2021-03-30  1:45 UTC (permalink / raw)
  To: netdev; +Cc: davem, yoshfuji, dsahern, kuba, Andreas Roeseler

Modify the ping_supported function to support PROBE message types. This
allows tools such as the ping command in the iputils package to be
modified to send PROBE requests through the existing framework for
sending ping requests.

Signed-off-by: Andreas Roeseler <andreas.a.roeseler@gmail.com>
---
 net/ipv4/ping.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
index 8b943f85fff9..1c9f71a37258 100644
--- a/net/ipv4/ping.c
+++ b/net/ipv4/ping.c
@@ -453,7 +453,9 @@ EXPORT_SYMBOL_GPL(ping_bind);
 static inline int ping_supported(int family, int type, int code)
 {
 	return (family == AF_INET && type == ICMP_ECHO && code == 0) ||
-	       (family == AF_INET6 && type == ICMPV6_ECHO_REQUEST && code == 0);
+	       (family == AF_INET && type == ICMP_EXT_ECHO && code == 0) ||
+	       (family == AF_INET6 && type == ICMPV6_ECHO_REQUEST && code == 0) ||
+	       (family == AF_INET6 && type == ICMPV6_EXT_ECHO_REQUEST && code == 0);
 }
 
 /*
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next V6 5/6] ipv6: add ipv6_dev_find to stubs
  2021-03-30  1:45 [PATCH net-next V6 0/6] add support for RFC 8335 PROBE Andreas Roeseler
                   ` (3 preceding siblings ...)
  2021-03-30  1:45 ` [PATCH net-next V6 4/6] net: add support for sending " Andreas Roeseler
@ 2021-03-30  1:45 ` Andreas Roeseler
  2021-03-30  1:45 ` [PATCH net-next V6 6/6] icmp: add response to RFC 8335 PROBE messages Andreas Roeseler
  2021-03-30 20:50 ` [PATCH net-next V6 0/6] add support for RFC 8335 PROBE patchwork-bot+netdevbpf
  6 siblings, 0 replies; 11+ messages in thread
From: Andreas Roeseler @ 2021-03-30  1:45 UTC (permalink / raw)
  To: netdev; +Cc: davem, yoshfuji, dsahern, kuba, Andreas Roeseler

Add ipv6_dev_find to ipv6_stub to allow lookup of net_devices by IPV6
address in net/ipv4/icmp.c.

Signed-off-by: Andreas Roeseler <andreas.a.roeseler@gmail.com>
---
 include/net/ipv6_stubs.h | 2 ++
 net/ipv6/addrconf_core.c | 7 +++++++
 net/ipv6/af_inet6.c      | 1 +
 3 files changed, 10 insertions(+)

diff --git a/include/net/ipv6_stubs.h b/include/net/ipv6_stubs.h
index 8fce558b5fea..afbce90c4480 100644
--- a/include/net/ipv6_stubs.h
+++ b/include/net/ipv6_stubs.h
@@ -66,6 +66,8 @@ struct ipv6_stub {
 
 	int (*ipv6_fragment)(struct net *net, struct sock *sk, struct sk_buff *skb,
 			     int (*output)(struct net *, struct sock *, struct sk_buff *));
+	struct net_device *(*ipv6_dev_find)(struct net *net, const struct in6_addr *addr,
+					    struct net_device *dev);
 };
 extern const struct ipv6_stub *ipv6_stub __read_mostly;
 
diff --git a/net/ipv6/addrconf_core.c b/net/ipv6/addrconf_core.c
index a36626afbc02..1d4054bb345b 100644
--- a/net/ipv6/addrconf_core.c
+++ b/net/ipv6/addrconf_core.c
@@ -198,6 +198,12 @@ static int eafnosupport_ipv6_fragment(struct net *net, struct sock *sk, struct s
 	return -EAFNOSUPPORT;
 }
 
+static struct net_device *eafnosupport_ipv6_dev_find(struct net *net, const struct in6_addr *addr,
+						     struct net_device *dev)
+{
+	return ERR_PTR(-EAFNOSUPPORT);
+}
+
 const struct ipv6_stub *ipv6_stub __read_mostly = &(struct ipv6_stub) {
 	.ipv6_dst_lookup_flow = eafnosupport_ipv6_dst_lookup_flow,
 	.ipv6_route_input  = eafnosupport_ipv6_route_input,
@@ -209,6 +215,7 @@ const struct ipv6_stub *ipv6_stub __read_mostly = &(struct ipv6_stub) {
 	.fib6_nh_init	   = eafnosupport_fib6_nh_init,
 	.ip6_del_rt	   = eafnosupport_ip6_del_rt,
 	.ipv6_fragment	   = eafnosupport_ipv6_fragment,
+	.ipv6_dev_find     = eafnosupport_ipv6_dev_find,
 };
 EXPORT_SYMBOL_GPL(ipv6_stub);
 
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index 3c9bacffc9c3..4f7ca5807046 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -1032,6 +1032,7 @@ static const struct ipv6_stub ipv6_stub_impl = {
 #endif
 	.nd_tbl	= &nd_tbl,
 	.ipv6_fragment = ip6_fragment,
+	.ipv6_dev_find = ipv6_dev_find,
 };
 
 static const struct ipv6_bpf_stub ipv6_bpf_stub_impl = {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next V6 6/6] icmp: add response to RFC 8335 PROBE messages
  2021-03-30  1:45 [PATCH net-next V6 0/6] add support for RFC 8335 PROBE Andreas Roeseler
                   ` (4 preceding siblings ...)
  2021-03-30  1:45 ` [PATCH net-next V6 5/6] ipv6: add ipv6_dev_find to stubs Andreas Roeseler
@ 2021-03-30  1:45 ` Andreas Roeseler
  2021-03-30 20:50 ` [PATCH net-next V6 0/6] add support for RFC 8335 PROBE patchwork-bot+netdevbpf
  6 siblings, 0 replies; 11+ messages in thread
From: Andreas Roeseler @ 2021-03-30  1:45 UTC (permalink / raw)
  To: netdev; +Cc: davem, yoshfuji, dsahern, kuba, Andreas Roeseler

Modify the icmp_rcv function to check PROBE messages and call icmp_echo
if a PROBE request is detected.

Modify the existing icmp_echo function to respond ot both ping and PROBE
requests.

This was tested using a custom modification to the iputils package and
wireshark. It supports IPV4 probing by name, ifindex, and probing by
both IPV4 and IPV6 addresses. It currently does not support responding
to probes off the proxy node (see RFC 8335 Section 2).

The modification to the iputils package is still in development and can
be found here: https://github.com/Juniper-Clinic-2020/iputils.git. It
supports full sending functionality of PROBE requests, but currently
does not parse the response messages, which is why Wireshark is required
to verify the sent and recieved PROBE messages. The modification adds
the ``-e'' flag to the command which allows the user to specify the
interface identifier to query the probed host. An example usage would be
<./ping -4 -e 1 [destination]> to send a PROBE request of ifindex 1 to the
destination node.

Signed-off-by: Andreas Roeseler <andreas.a.roeseler@gmail.com>
---
Changes:
v1 -> v2:
 - Reorder variable declarations to follow coding style
 - Switch to functions such as dev_get_by_name and ip_dev_find to lookup
   net devices

v2 -> v3:
Suggested by Willem de Bruijn <willemdebruijn.kernel@gmail.com>
 - Add verification of incoming messages before looking up netdev
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
 - Include net/addrconf.h library for ipv6_dev_find

v3 -> v4:
Suggested by Willem de Bruijn <willemdebruijn.kernel@gmail.com>
 - Use skb_header_pointer to verify fields in incoming message
 - Add check to ensure that extobj_hdr.length is valid
 - Check to ensure object payload is padded with ASCII NULL characters
   when probing by name, as specified by RFC 8335
 - Statically allocate buff using IFNAMSIZ
 - Add rcu blocking around ipv6_dev_find
 - Use __in_dev_get_rcu to access IPV4 addresses of identified
   net_device
 - Remove check for ICMPV6 PROBE types

v4 -> v5:
 - Statically allocate buff to size IFNAMSIZ on declaration
 - Remove goto probe in favor of single branch
 - Remove strict check for incoming PROBE requests padding to nearest
   32-bit boundary
Reported-by: kernel test robot <lkp@intel.com>
 - Use rcu_dereference when accessing i6_ptr in net_device

v5 -> v6:
 - Remove RCU locking around ipv6_dev_find()
 - Assign iio based on length specified by ctype
---
 net/ipv4/icmp.c | 134 +++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 121 insertions(+), 13 deletions(-)

diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
index 616e2dc1c8fa..76990e13a2f9 100644
--- a/net/ipv4/icmp.c
+++ b/net/ipv4/icmp.c
@@ -971,7 +971,7 @@ static bool icmp_redirect(struct sk_buff *skb)
 }
 
 /*
- *	Handle ICMP_ECHO ("ping") requests.
+ *	Handle ICMP_ECHO ("ping") and ICMP_EXT_ECHO ("PROBE") requests.
  *
  *	RFC 1122: 3.2.2.6 MUST have an echo server that answers ICMP echo
  *		  requests.
@@ -979,27 +979,125 @@ static bool icmp_redirect(struct sk_buff *skb)
  *		  included in the reply.
  *	RFC 1812: 4.3.3.6 SHOULD have a config option for silently ignoring
  *		  echo requests, MUST have default=NOT.
+ *	RFC 8335: 8 MUST have a config option to enable/disable ICMP
+ *		  Extended Echo Functionality, MUST be disabled by default
  *	See also WRT handling of options once they are done and working.
  */
 
 static bool icmp_echo(struct sk_buff *skb)
 {
+	struct icmp_ext_hdr *ext_hdr, _ext_hdr;
+	struct icmp_ext_echo_iio *iio, _iio;
+	struct icmp_bxm icmp_param;
+	struct net_device *dev;
+	char buff[IFNAMSIZ];
 	struct net *net;
+	u16 ident_len;
+	u8 status;
 
 	net = dev_net(skb_dst(skb)->dev);
-	if (!net->ipv4.sysctl_icmp_echo_ignore_all) {
-		struct icmp_bxm icmp_param;
+	/* should there be an ICMP stat for ignored echos? */
+	if (net->ipv4.sysctl_icmp_echo_ignore_all)
+		return true;
+
+	icmp_param.data.icmph	   = *icmp_hdr(skb);
+	icmp_param.skb		   = skb;
+	icmp_param.offset	   = 0;
+	icmp_param.data_len	   = skb->len;
+	icmp_param.head_len	   = sizeof(struct icmphdr);
 
-		icmp_param.data.icmph	   = *icmp_hdr(skb);
+	if (icmp_param.data.icmph.type == ICMP_ECHO) {
 		icmp_param.data.icmph.type = ICMP_ECHOREPLY;
-		icmp_param.skb		   = skb;
-		icmp_param.offset	   = 0;
-		icmp_param.data_len	   = skb->len;
-		icmp_param.head_len	   = sizeof(struct icmphdr);
-		icmp_reply(&icmp_param, skb);
+		goto send_reply;
 	}
-	/* should there be an ICMP stat for ignored echos? */
-	return true;
+	if (!net->ipv4.sysctl_icmp_echo_enable_probe)
+		return true;
+	/* We currently only support probing interfaces on the proxy node
+	 * Check to ensure L-bit is set
+	 */
+	if (!(ntohs(icmp_param.data.icmph.un.echo.sequence) & 1))
+		return true;
+	/* Clear status bits in reply message */
+	icmp_param.data.icmph.un.echo.sequence &= htons(0xFF00);
+	icmp_param.data.icmph.type = ICMP_EXT_ECHOREPLY;
+	ext_hdr = skb_header_pointer(skb, 0, sizeof(_ext_hdr), &_ext_hdr);
+	/* Size of iio is class_type dependent.
+	 * Only check header here and assign length based on ctype in the switch statement
+	 */
+	iio = skb_header_pointer(skb, sizeof(_ext_hdr), sizeof(iio->extobj_hdr), &_iio);
+	if (!ext_hdr || !iio)
+		goto send_mal_query;
+	if (ntohs(iio->extobj_hdr.length) <= sizeof(iio->extobj_hdr))
+		goto send_mal_query;
+	ident_len = ntohs(iio->extobj_hdr.length) - sizeof(iio->extobj_hdr);
+	status = 0;
+	dev = NULL;
+	switch (iio->extobj_hdr.class_type) {
+	case EXT_ECHO_CTYPE_NAME:
+		iio = skb_header_pointer(skb, sizeof(_ext_hdr), sizeof(_iio), &_iio);
+		if (ident_len >= IFNAMSIZ)
+			goto send_mal_query;
+		memset(buff, 0, sizeof(buff));
+		memcpy(buff, &iio->ident.name, ident_len);
+		dev = dev_get_by_name(net, buff);
+		break;
+	case EXT_ECHO_CTYPE_INDEX:
+		iio = skb_header_pointer(skb, sizeof(_ext_hdr), sizeof(iio->extobj_hdr) +
+					 sizeof(iio->ident.ifindex), &_iio);
+		if (ident_len != sizeof(iio->ident.ifindex))
+			goto send_mal_query;
+		dev = dev_get_by_index(net, ntohl(iio->ident.ifindex));
+		break;
+	case EXT_ECHO_CTYPE_ADDR:
+		if (ident_len != sizeof(iio->ident.addr.ctype3_hdr) +
+				 iio->ident.addr.ctype3_hdr.addrlen)
+			goto send_mal_query;
+		switch (ntohs(iio->ident.addr.ctype3_hdr.afi)) {
+		case ICMP_AFI_IP:
+			iio = skb_header_pointer(skb, sizeof(_ext_hdr), sizeof(iio->extobj_hdr) +
+						 sizeof(struct in_addr), &_iio);
+			if (ident_len != sizeof(iio->ident.addr.ctype3_hdr) +
+					 sizeof(struct in_addr))
+				goto send_mal_query;
+			dev = ip_dev_find(net, iio->ident.addr.ip_addr.ipv4_addr.s_addr);
+			break;
+#if IS_ENABLED(CONFIG_IPV6)
+		case ICMP_AFI_IP6:
+			iio = skb_header_pointer(skb, sizeof(_ext_hdr), sizeof(_iio), &_iio);
+			if (ident_len != sizeof(iio->ident.addr.ctype3_hdr) +
+					 sizeof(struct in6_addr))
+				goto send_mal_query;
+			dev = ipv6_stub->ipv6_dev_find(net, &iio->ident.addr.ip_addr.ipv6_addr, dev);
+			if (dev)
+				dev_hold(dev);
+			break;
+#endif
+		default:
+			goto send_mal_query;
+		}
+		break;
+	default:
+		goto send_mal_query;
+	}
+	if (!dev) {
+		icmp_param.data.icmph.code = ICMP_EXT_NO_IF;
+		goto send_reply;
+	}
+	/* Fill bits in reply message */
+	if (dev->flags & IFF_UP)
+		status |= EXT_ECHOREPLY_ACTIVE;
+	if (__in_dev_get_rcu(dev) && __in_dev_get_rcu(dev)->ifa_list)
+		status |= EXT_ECHOREPLY_IPV4;
+	if (!list_empty(&rcu_dereference(dev->ip6_ptr)->addr_list))
+		status |= EXT_ECHOREPLY_IPV6;
+	dev_put(dev);
+	icmp_param.data.icmph.un.echo.sequence |= htons(status);
+send_reply:
+	icmp_reply(&icmp_param, skb);
+		return true;
+send_mal_query:
+	icmp_param.data.icmph.code = ICMP_EXT_MAL_QUERY;
+	goto send_reply;
 }
 
 /*
@@ -1088,6 +1186,16 @@ int icmp_rcv(struct sk_buff *skb)
 	icmph = icmp_hdr(skb);
 
 	ICMPMSGIN_INC_STATS(net, icmph->type);
+
+	/* Check for ICMP Extended Echo (PROBE) messages */
+	if (icmph->type == ICMP_EXT_ECHO) {
+		/* We can't use icmp_pointers[].handler() because it is an array of
+		 * size NR_ICMP_TYPES + 1 (19 elements) and PROBE has code 42.
+		 */
+		success = icmp_echo(skb);
+		goto success_check;
+	}
+
 	/*
 	 *	18 is the highest 'known' ICMP type. Anything else is a mystery
 	 *
@@ -1097,7 +1205,6 @@ int icmp_rcv(struct sk_buff *skb)
 	if (icmph->type > NR_ICMP_TYPES)
 		goto error;
 
-
 	/*
 	 *	Parse the ICMP message
 	 */
@@ -1123,7 +1230,7 @@ int icmp_rcv(struct sk_buff *skb)
 	}
 
 	success = icmp_pointers[icmph->type].handler(skb);
-
+success_check:
 	if (success)  {
 		consume_skb(skb);
 		return NET_RX_SUCCESS;
@@ -1340,6 +1447,7 @@ static int __net_init icmp_sk_init(struct net *net)
 
 	/* Control parameters for ECHO replies. */
 	net->ipv4.sysctl_icmp_echo_ignore_all = 0;
+	net->ipv4.sysctl_icmp_echo_enable_probe = 0;
 	net->ipv4.sysctl_icmp_echo_ignore_broadcasts = 1;
 
 	/* Control parameter - ignore bogus broadcast responses? */
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next V6 0/6] add support for RFC 8335 PROBE
  2021-03-30  1:45 [PATCH net-next V6 0/6] add support for RFC 8335 PROBE Andreas Roeseler
                   ` (5 preceding siblings ...)
  2021-03-30  1:45 ` [PATCH net-next V6 6/6] icmp: add response to RFC 8335 PROBE messages Andreas Roeseler
@ 2021-03-30 20:50 ` patchwork-bot+netdevbpf
  6 siblings, 0 replies; 11+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-03-30 20:50 UTC (permalink / raw)
  To: Andreas Roeseler; +Cc: netdev, davem, yoshfuji, dsahern, kuba

Hello:

This series was applied to netdev/net-next.git (refs/heads/master):

On Mon, 29 Mar 2021 18:45:04 -0700 you wrote:
> The popular utility ping has several severe limitations, such as the
> inability to query specific interfaces on a node and requiring
> bidirectional connectivity between the probing and probed interfaces.
> RFC 8335 attempts to solve these limitations by creating the new utility
> PROBE which is a specialized ICMP message that makes use of the ICMP
> Extension Structure outlined in RFC 4884.
> 
> [...]

Here is the summary with links:
  - [net-next,V6,1/6] icmp: add support for RFC 8335 PROBE
    https://git.kernel.org/netdev/net-next/c/2b246b2569cd
  - [net-next,V6,2/6] ICMPV6: add support for RFC 8335 PROBE
    https://git.kernel.org/netdev/net-next/c/750f4fc2a12f
  - [net-next,V6,3/6] net: add sysctl for enabling RFC 8335 PROBE messages
    https://git.kernel.org/netdev/net-next/c/f1b8fa9fa586
  - [net-next,V6,4/6] net: add support for sending RFC 8335 PROBE messages
    https://git.kernel.org/netdev/net-next/c/08baf54f01f5
  - [net-next,V6,5/6] ipv6: add ipv6_dev_find to stubs
    https://git.kernel.org/netdev/net-next/c/504a40113cc4
  - [net-next,V6,6/6] icmp: add response to RFC 8335 PROBE messages
    https://git.kernel.org/netdev/net-next/c/d329ea5bd884

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next V6 1/6] icmp: add support for RFC 8335 PROBE
  2021-03-30  1:45 ` [PATCH net-next V6 1/6] icmp: " Andreas Roeseler
@ 2021-06-02 17:58   ` Florian Weimer
  2021-06-02 18:46     ` Andreas Roeseler
  0 siblings, 1 reply; 11+ messages in thread
From: Florian Weimer @ 2021-06-02 17:58 UTC (permalink / raw)
  To: Andreas Roeseler; +Cc: netdev, davem, yoshfuji, dsahern, kuba

* Andreas Roeseler:

> diff --git a/include/uapi/linux/icmp.h b/include/uapi/linux/icmp.h
> index fb169a50895e..222325d1d80e 100644
> --- a/include/uapi/linux/icmp.h
> +++ b/include/uapi/linux/icmp.h
> @@ -20,6 +20,9 @@
>  
>  #include <linux/types.h>
>  #include <asm/byteorder.h>
> +#include <linux/in.h>
> +#include <linux/if.h>
> +#include <linux/in6.h>

We have received a report that this breaks compiliation of trinity
because it includes <netinet/in.h> and <linux/icmp.h> at the same time,
and there is no multiple-definition guard for struct in_addr and other
definitions:

In file included from include/net.h:5,
                 from net/proto-ip-raw.c:2:
/usr/include/netinet/in.h:31:8: error: redefinition of ‘struct in_addr’
   31 | struct in_addr
      |        ^~~~~~~
In file included from /usr/include/linux/icmp.h:23,
                 from net/proto-ip-raw.c:1:
/usr/include/linux/in.h:89:8: note: originally defined here
   89 | struct in_addr {
      |        ^~~~~~~
In file included from /usr/include/netinet/in.h:37,
                 from include/net.h:5,
                 from net/proto-ip-raw.c:2:
/usr/include/bits/in.h:150:8: error: redefinition of ‘struct ip_mreqn’
  150 | struct ip_mreqn
      |        ^~~~~~~~
In file included from /usr/include/linux/icmp.h:23,
                 from net/proto-ip-raw.c:1:
/usr/include/linux/in.h:178:8: note: originally defined here
  178 | struct ip_mreqn {
      |        ^~~~~~~~

(More conflicts appear to follow.)

I do not know what the correct way forward is.  Adding the
multiple-definition guards is quite a bit of work and requires updates
in glibc and the kernel to work properly.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next V6 1/6] icmp: add support for RFC 8335 PROBE
  2021-06-02 17:58   ` Florian Weimer
@ 2021-06-02 18:46     ` Andreas Roeseler
  2021-06-02 18:51       ` Florian Weimer
  0 siblings, 1 reply; 11+ messages in thread
From: Andreas Roeseler @ 2021-06-02 18:46 UTC (permalink / raw)
  To: Florian Weimer; +Cc: netdev, davem, yoshfuji, dsahern, kuba

On Wed, 2021-06-02 at 19:58 +0200, Florian Weimer wrote:
> * Andreas Roeseler:
> 
> > diff --git a/include/uapi/linux/icmp.h b/include/uapi/linux/icmp.h
> > index fb169a50895e..222325d1d80e 100644
> > --- a/include/uapi/linux/icmp.h
> > +++ b/include/uapi/linux/icmp.h
> > @@ -20,6 +20,9 @@
> >  
> >  #include <linux/types.h>
> >  #include <asm/byteorder.h>
> > +#include <linux/in.h>
> > +#include <linux/if.h>
> > +#include <linux/in6.h>
> 
> We have received a report that this breaks compiliation of trinity
> because it includes <netinet/in.h> and <linux/icmp.h> at the same
> time,
> and there is no multiple-definition guard for struct in_addr and
> other
> definitions:
> 
> In file included from include/net.h:5,
>                  from net/proto-ip-raw.c:2:
> /usr/include/netinet/in.h:31:8: error: redefinition of ‘struct
> in_addr’
>    31 | struct in_addr
>       |        ^~~~~~~
> In file included from /usr/include/linux/icmp.h:23,
>                  from net/proto-ip-raw.c:1:
> /usr/include/linux/in.h:89:8: note: originally defined here
>    89 | struct in_addr {
>       |        ^~~~~~~
> In file included from /usr/include/netinet/in.h:37,
>                  from include/net.h:5,
>                  from net/proto-ip-raw.c:2:
> /usr/include/bits/in.h:150:8: error: redefinition of ‘struct
> ip_mreqn’
>   150 | struct ip_mreqn
>       |        ^~~~~~~~
> In file included from /usr/include/linux/icmp.h:23,
>                  from net/proto-ip-raw.c:1:
> /usr/include/linux/in.h:178:8: note: originally defined here
>   178 | struct ip_mreqn {
>       |        ^~~~~~~~
> 
> (More conflicts appear to follow.)
> 
> I do not know what the correct way forward is.  Adding the
> multiple-definition guards is quite a bit of work and requires
> updates
> in glibc and the kernel to work properly.
> 
> Thanks,
> Florian
> 

Are <netinet/in.h> and <linux/in.h> the only conflicting files?
<linux/in.h> is only included to gain use of the in_addr struct, but
that can be easily substituted out of the code in favor of __be32.
Therefore we would no longer need to include <linux/in.h> and would
remove the conflict.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next V6 1/6] icmp: add support for RFC 8335 PROBE
  2021-06-02 18:46     ` Andreas Roeseler
@ 2021-06-02 18:51       ` Florian Weimer
  0 siblings, 0 replies; 11+ messages in thread
From: Florian Weimer @ 2021-06-02 18:51 UTC (permalink / raw)
  To: Andreas Roeseler; +Cc: netdev, davem, yoshfuji, dsahern, kuba

* Andreas Roeseler:

> Are <netinet/in.h> and <linux/in.h> the only conflicting files?
> <linux/in.h> is only included to gain use of the in_addr struct, but
> that can be easily substituted out of the code in favor of __be32.
> Therefore we would no longer need to include <linux/in.h> and would
> remove the conflict.

I'm not 100% sure, but it looks this way.  I can include <netinet/in.h>
and both <linux/in6.h> and <linux/if.h> in the same translation unit.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-06-02 18:51 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-30  1:45 [PATCH net-next V6 0/6] add support for RFC 8335 PROBE Andreas Roeseler
2021-03-30  1:45 ` [PATCH net-next V6 1/6] icmp: " Andreas Roeseler
2021-06-02 17:58   ` Florian Weimer
2021-06-02 18:46     ` Andreas Roeseler
2021-06-02 18:51       ` Florian Weimer
2021-03-30  1:45 ` [PATCH net-next V6 2/6] ICMPV6: " Andreas Roeseler
2021-03-30  1:45 ` [PATCH net-next V6 3/6] net: add sysctl for enabling RFC 8335 PROBE messages Andreas Roeseler
2021-03-30  1:45 ` [PATCH net-next V6 4/6] net: add support for sending " Andreas Roeseler
2021-03-30  1:45 ` [PATCH net-next V6 5/6] ipv6: add ipv6_dev_find to stubs Andreas Roeseler
2021-03-30  1:45 ` [PATCH net-next V6 6/6] icmp: add response to RFC 8335 PROBE messages Andreas Roeseler
2021-03-30 20:50 ` [PATCH net-next V6 0/6] add support for RFC 8335 PROBE patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.