diff mbox series

[net-next,V6,1/6] icmp: add support for RFC 8335 PROBE

Message ID ba81dcf8097c4d3cc43f4e2ed5cc6f5a7a4c33b6.1617067968.git.andreas.a.roeseler@gmail.com
State New
Headers show
Series [net-next,V6,1/6] icmp: add support for RFC 8335 PROBE | expand

Commit Message

Andreas Roeseler March 30, 2021, 1:45 a.m. UTC
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(+)

Comments

Florian Weimer June 2, 2021, 5:58 p.m. UTC | #1
* 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
Andreas Roeseler June 2, 2021, 6:46 p.m. UTC | #2
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.
Florian Weimer June 2, 2021, 6:51 p.m. UTC | #3
* 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
diff mbox series

Patch

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 */