2017-11-01 22:09:13 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
|
2012-10-13 17:46:48 +08:00
|
|
|
/*
|
|
|
|
* INET An implementation of the TCP/IP protocol suite for the LINUX
|
|
|
|
* operating system. INET is implemented using the BSD Socket
|
|
|
|
* interface as the means of communication with the user level.
|
|
|
|
*
|
|
|
|
* Definitions for the ICMP protocol.
|
|
|
|
*
|
|
|
|
* Version: @(#)icmp.h 1.0.3 04/28/93
|
|
|
|
*
|
|
|
|
* Author: Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*/
|
|
|
|
#ifndef _UAPI_LINUX_ICMP_H
|
|
|
|
#define _UAPI_LINUX_ICMP_H
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
icmp: support rfc 4884
Add setsockopt SOL_IP/IP_RECVERR_4884 to return the offset to an
extension struct if present.
ICMP messages may include an extension structure after the original
datagram. RFC 4884 standardized this behavior. It stores the offset
in words to the extension header in u8 icmphdr.un.reserved[1].
The field is valid only for ICMP types destination unreachable, time
exceeded and parameter problem, if length is at least 128 bytes and
entire packet does not exceed 576 bytes.
Return the offset to the start of the extension struct when reading an
ICMP error from the error queue, if it matches the above constraints.
Do not return the raw u8 field. Return the offset from the start of
the user buffer, in bytes. The kernel does not return the network and
transport headers, so subtract those.
Also validate the headers. Return the offset regardless of validation,
as an invalid extension must still not be misinterpreted as part of
the original datagram. Note that !invalid does not imply valid. If
the extension version does not match, no validation can take place,
for instance.
For backward compatibility, make this optional, set by setsockopt
SOL_IP/IP_RECVERR_RFC4884. For API example and feature test, see
github.com/wdebruij/kerneltools/blob/master/tests/recv_icmp_v2.c
For forward compatibility, reserve only setsockopt value 1, leaving
other bits for additional icmp extensions.
Changes
v1->v2:
- convert word offset to byte offset from start of user buffer
- return in ee_data as u8 may be insufficient
- define extension struct and object header structs
- return len only if constraints met
- if returning len, also validate
Signed-off-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-07-10 21:29:02 +08:00
|
|
|
#include <asm/byteorder.h>
|
2012-10-13 17:46:48 +08:00
|
|
|
|
|
|
|
#define ICMP_ECHOREPLY 0 /* Echo Reply */
|
|
|
|
#define ICMP_DEST_UNREACH 3 /* Destination Unreachable */
|
|
|
|
#define ICMP_SOURCE_QUENCH 4 /* Source Quench */
|
|
|
|
#define ICMP_REDIRECT 5 /* Redirect (change route) */
|
|
|
|
#define ICMP_ECHO 8 /* Echo Request */
|
|
|
|
#define ICMP_TIME_EXCEEDED 11 /* Time Exceeded */
|
|
|
|
#define ICMP_PARAMETERPROB 12 /* Parameter Problem */
|
|
|
|
#define ICMP_TIMESTAMP 13 /* Timestamp Request */
|
|
|
|
#define ICMP_TIMESTAMPREPLY 14 /* Timestamp Reply */
|
|
|
|
#define ICMP_INFO_REQUEST 15 /* Information Request */
|
|
|
|
#define ICMP_INFO_REPLY 16 /* Information Reply */
|
|
|
|
#define ICMP_ADDRESS 17 /* Address Mask Request */
|
|
|
|
#define ICMP_ADDRESSREPLY 18 /* Address Mask Reply */
|
|
|
|
#define NR_ICMP_TYPES 18
|
|
|
|
|
|
|
|
|
|
|
|
/* Codes for UNREACH. */
|
|
|
|
#define ICMP_NET_UNREACH 0 /* Network Unreachable */
|
|
|
|
#define ICMP_HOST_UNREACH 1 /* Host Unreachable */
|
|
|
|
#define ICMP_PROT_UNREACH 2 /* Protocol Unreachable */
|
|
|
|
#define ICMP_PORT_UNREACH 3 /* Port Unreachable */
|
|
|
|
#define ICMP_FRAG_NEEDED 4 /* Fragmentation Needed/DF set */
|
|
|
|
#define ICMP_SR_FAILED 5 /* Source Route failed */
|
|
|
|
#define ICMP_NET_UNKNOWN 6
|
|
|
|
#define ICMP_HOST_UNKNOWN 7
|
|
|
|
#define ICMP_HOST_ISOLATED 8
|
|
|
|
#define ICMP_NET_ANO 9
|
|
|
|
#define ICMP_HOST_ANO 10
|
|
|
|
#define ICMP_NET_UNR_TOS 11
|
|
|
|
#define ICMP_HOST_UNR_TOS 12
|
|
|
|
#define ICMP_PKT_FILTERED 13 /* Packet filtered */
|
|
|
|
#define ICMP_PREC_VIOLATION 14 /* Precedence violation */
|
|
|
|
#define ICMP_PREC_CUTOFF 15 /* Precedence cut off */
|
|
|
|
#define NR_ICMP_UNREACH 15 /* instead of hardcoding immediate value */
|
|
|
|
|
|
|
|
/* Codes for REDIRECT. */
|
|
|
|
#define ICMP_REDIR_NET 0 /* Redirect Net */
|
|
|
|
#define ICMP_REDIR_HOST 1 /* Redirect Host */
|
|
|
|
#define ICMP_REDIR_NETTOS 2 /* Redirect Net for TOS */
|
|
|
|
#define ICMP_REDIR_HOSTTOS 3 /* Redirect Host for TOS */
|
|
|
|
|
|
|
|
/* Codes for TIME_EXCEEDED. */
|
|
|
|
#define ICMP_EXC_TTL 0 /* TTL count exceeded */
|
|
|
|
#define ICMP_EXC_FRAGTIME 1 /* Fragment Reass time exceeded */
|
|
|
|
|
|
|
|
|
|
|
|
struct icmphdr {
|
|
|
|
__u8 type;
|
|
|
|
__u8 code;
|
|
|
|
__sum16 checksum;
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
__be16 id;
|
|
|
|
__be16 sequence;
|
|
|
|
} echo;
|
|
|
|
__be32 gateway;
|
|
|
|
struct {
|
|
|
|
__be16 __unused;
|
|
|
|
__be16 mtu;
|
|
|
|
} frag;
|
2016-06-19 12:52:06 +08:00
|
|
|
__u8 reserved[4];
|
2012-10-13 17:46:48 +08:00
|
|
|
} un;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* constants for (set|get)sockopt
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define ICMP_FILTER 1
|
|
|
|
|
|
|
|
struct icmp_filter {
|
|
|
|
__u32 data;
|
|
|
|
};
|
|
|
|
|
icmp: support rfc 4884
Add setsockopt SOL_IP/IP_RECVERR_4884 to return the offset to an
extension struct if present.
ICMP messages may include an extension structure after the original
datagram. RFC 4884 standardized this behavior. It stores the offset
in words to the extension header in u8 icmphdr.un.reserved[1].
The field is valid only for ICMP types destination unreachable, time
exceeded and parameter problem, if length is at least 128 bytes and
entire packet does not exceed 576 bytes.
Return the offset to the start of the extension struct when reading an
ICMP error from the error queue, if it matches the above constraints.
Do not return the raw u8 field. Return the offset from the start of
the user buffer, in bytes. The kernel does not return the network and
transport headers, so subtract those.
Also validate the headers. Return the offset regardless of validation,
as an invalid extension must still not be misinterpreted as part of
the original datagram. Note that !invalid does not imply valid. If
the extension version does not match, no validation can take place,
for instance.
For backward compatibility, make this optional, set by setsockopt
SOL_IP/IP_RECVERR_RFC4884. For API example and feature test, see
github.com/wdebruij/kerneltools/blob/master/tests/recv_icmp_v2.c
For forward compatibility, reserve only setsockopt value 1, leaving
other bits for additional icmp extensions.
Changes
v1->v2:
- convert word offset to byte offset from start of user buffer
- return in ee_data as u8 may be insufficient
- define extension struct and object header structs
- return len only if constraints met
- if returning len, also validate
Signed-off-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-07-10 21:29:02 +08:00
|
|
|
/* RFC 4884 extension struct: one per message */
|
|
|
|
struct icmp_ext_hdr {
|
|
|
|
#if defined(__LITTLE_ENDIAN_BITFIELD)
|
|
|
|
__u8 reserved1:4,
|
|
|
|
version:4;
|
|
|
|
#elif defined(__BIG_ENDIAN_BITFIELD)
|
|
|
|
__u8 version:4,
|
|
|
|
reserved1:4;
|
|
|
|
#else
|
|
|
|
#error "Please fix <asm/byteorder.h>"
|
|
|
|
#endif
|
|
|
|
__u8 reserved2;
|
|
|
|
__sum16 checksum;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* RFC 4884 extension object header: one for each object */
|
|
|
|
struct icmp_extobj_hdr {
|
|
|
|
__be16 length;
|
|
|
|
__u8 class_num;
|
|
|
|
__u8 class_type;
|
|
|
|
};
|
2012-10-13 17:46:48 +08:00
|
|
|
|
|
|
|
#endif /* _UAPI_LINUX_ICMP_H */
|