1c398230bSWarner Losh /*- 251369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 351369649SPedro F. Giffuni * 4df8bae1dSRodney W. Grimes * Copyright (c) 1982, 1986, 1993 5df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved. 6df8bae1dSRodney W. Grimes * 7df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 8df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 9df8bae1dSRodney W. Grimes * are met: 10df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 11df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 12df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 13df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 14df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 15fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors 16df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 17df8bae1dSRodney W. Grimes * without specific prior written permission. 18df8bae1dSRodney W. Grimes * 19df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29df8bae1dSRodney W. Grimes * SUCH DAMAGE. 30df8bae1dSRodney W. Grimes */ 31df8bae1dSRodney W. Grimes 32707f139eSPaul Richards #ifndef _NETINET_IP_ICMP_H_ 33707f139eSPaul Richards #define _NETINET_IP_ICMP_H_ 34707f139eSPaul Richards 35df8bae1dSRodney W. Grimes /* 36df8bae1dSRodney W. Grimes * Interface Control Message Protocol Definitions. 37df8bae1dSRodney W. Grimes * Per RFC 792, September 1981. 38df8bae1dSRodney W. Grimes */ 39df8bae1dSRodney W. Grimes 40df8bae1dSRodney W. Grimes /* 4148405412SBill Fenner * Internal of an ICMP Router Advertisement 4248405412SBill Fenner */ 4348405412SBill Fenner struct icmp_ra_addr { 4448405412SBill Fenner u_int32_t ira_addr; 4548405412SBill Fenner u_int32_t ira_preference; 4648405412SBill Fenner }; 4748405412SBill Fenner 4848405412SBill Fenner /* 49df8bae1dSRodney W. Grimes * Structure of an icmp header. 50df8bae1dSRodney W. Grimes */ 5131519b13SBrooks Davis struct icmphdr { 5231519b13SBrooks Davis u_char icmp_type; /* type of message, see below */ 5331519b13SBrooks Davis u_char icmp_code; /* type sub code */ 5431519b13SBrooks Davis u_short icmp_cksum; /* ones complement cksum of struct */ 5531519b13SBrooks Davis }; 5631519b13SBrooks Davis 5731519b13SBrooks Davis /* 5831519b13SBrooks Davis * Structure of an icmp packet. 5931519b13SBrooks Davis * 6031519b13SBrooks Davis * XXX: should start with a struct icmphdr. 6131519b13SBrooks Davis */ 62df8bae1dSRodney W. Grimes struct icmp { 63df8bae1dSRodney W. Grimes u_char icmp_type; /* type of message, see below */ 64df8bae1dSRodney W. Grimes u_char icmp_code; /* type sub code */ 65df8bae1dSRodney W. Grimes u_short icmp_cksum; /* ones complement cksum of struct */ 66df8bae1dSRodney W. Grimes union { 67df8bae1dSRodney W. Grimes u_char ih_pptr; /* ICMP_PARAMPROB */ 68df8bae1dSRodney W. Grimes struct in_addr ih_gwaddr; /* ICMP_REDIRECT */ 69df8bae1dSRodney W. Grimes struct ih_idseq { 70d685b6eeSLuigi Rizzo uint16_t icd_id; /* network format */ 71d685b6eeSLuigi Rizzo uint16_t icd_seq; /* network format */ 72df8bae1dSRodney W. Grimes } ih_idseq; 73df8bae1dSRodney W. Grimes int ih_void; 74df8bae1dSRodney W. Grimes 75df8bae1dSRodney W. Grimes /* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */ 76df8bae1dSRodney W. Grimes struct ih_pmtu { 77d685b6eeSLuigi Rizzo uint16_t ipm_void; /* network format */ 78d685b6eeSLuigi Rizzo uint16_t ipm_nextmtu; /* network format */ 79df8bae1dSRodney W. Grimes } ih_pmtu; 8048405412SBill Fenner 8148405412SBill Fenner struct ih_rtradv { 8248405412SBill Fenner u_char irt_num_addrs; 8348405412SBill Fenner u_char irt_wpa; 8448405412SBill Fenner u_int16_t irt_lifetime; 8548405412SBill Fenner } ih_rtradv; 86df8bae1dSRodney W. Grimes } icmp_hun; 87df8bae1dSRodney W. Grimes #define icmp_pptr icmp_hun.ih_pptr 88df8bae1dSRodney W. Grimes #define icmp_gwaddr icmp_hun.ih_gwaddr 89df8bae1dSRodney W. Grimes #define icmp_id icmp_hun.ih_idseq.icd_id 90df8bae1dSRodney W. Grimes #define icmp_seq icmp_hun.ih_idseq.icd_seq 91df8bae1dSRodney W. Grimes #define icmp_void icmp_hun.ih_void 92df8bae1dSRodney W. Grimes #define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void 93df8bae1dSRodney W. Grimes #define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu 9448405412SBill Fenner #define icmp_num_addrs icmp_hun.ih_rtradv.irt_num_addrs 9548405412SBill Fenner #define icmp_wpa icmp_hun.ih_rtradv.irt_wpa 9648405412SBill Fenner #define icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime 97df8bae1dSRodney W. Grimes union { 9821150298SMatthew N. Dodd struct id_ts { /* ICMP Timestamp */ 99d685b6eeSLuigi Rizzo /* 100d685b6eeSLuigi Rizzo * The next 3 fields are in network format, 10161f26caeSWarner Losh * milliseconds since 00:00 UTC 102d685b6eeSLuigi Rizzo */ 103d685b6eeSLuigi Rizzo uint32_t its_otime; /* Originate */ 104d685b6eeSLuigi Rizzo uint32_t its_rtime; /* Receive */ 105d685b6eeSLuigi Rizzo uint32_t its_ttime; /* Transmit */ 106df8bae1dSRodney W. Grimes } id_ts; 107df8bae1dSRodney W. Grimes struct id_ip { 108df8bae1dSRodney W. Grimes struct ip idi_ip; 109df8bae1dSRodney W. Grimes /* options and then 64 bits of data */ 110df8bae1dSRodney W. Grimes } id_ip; 11148405412SBill Fenner struct icmp_ra_addr id_radv; 11299c819efSBruce Evans u_int32_t id_mask; 113df8bae1dSRodney W. Grimes char id_data[1]; 114df8bae1dSRodney W. Grimes } icmp_dun; 115df8bae1dSRodney W. Grimes #define icmp_otime icmp_dun.id_ts.its_otime 116df8bae1dSRodney W. Grimes #define icmp_rtime icmp_dun.id_ts.its_rtime 117df8bae1dSRodney W. Grimes #define icmp_ttime icmp_dun.id_ts.its_ttime 118df8bae1dSRodney W. Grimes #define icmp_ip icmp_dun.id_ip.idi_ip 11948405412SBill Fenner #define icmp_radv icmp_dun.id_radv 120df8bae1dSRodney W. Grimes #define icmp_mask icmp_dun.id_mask 121df8bae1dSRodney W. Grimes #define icmp_data icmp_dun.id_data 122df8bae1dSRodney W. Grimes }; 123df8bae1dSRodney W. Grimes 124df8bae1dSRodney W. Grimes /* 125df8bae1dSRodney W. Grimes * Lower bounds on packet lengths for various types. 126df8bae1dSRodney W. Grimes * For the error advice packets must first insure that the 1276c5e9bbdSMike Pritchard * packet is large enough to contain the returned ip header. 128df8bae1dSRodney W. Grimes * Only then can we do the check to see if 64 bits of packet 129df8bae1dSRodney W. Grimes * data have been returned, since we need to check the returned 130df8bae1dSRodney W. Grimes * ip header length. 131df8bae1dSRodney W. Grimes */ 132df8bae1dSRodney W. Grimes #define ICMP_MINLEN 8 /* abs minimum */ 133d685b6eeSLuigi Rizzo #define ICMP_TSLEN (8 + 3 * sizeof (uint32_t)) /* timestamp */ 134df8bae1dSRodney W. Grimes #define ICMP_MASKLEN 12 /* address mask */ 135df8bae1dSRodney W. Grimes #define ICMP_ADVLENMIN (8 + sizeof (struct ip) + 8) /* min */ 136df8bae1dSRodney W. Grimes #define ICMP_ADVLEN(p) (8 + ((p)->icmp_ip.ip_hl << 2) + 8) 137df8bae1dSRodney W. Grimes /* N.B.: must separately check that ip_hl >= 5 */ 138f77b8427SMichael Tuexen /* This is the minimum length required by RFC 792. */ 139f77b8427SMichael Tuexen /* 140f77b8427SMichael Tuexen * ICMP_ADVLENPREF is the preferred number of bytes which should be contiguous. 1414d6b853aSMichael Tuexen * SCTP needs additional 12 bytes to be able to access the initiate tag 142fd7af143SMichael Tuexen * in packets containing an INIT chunk. For also supporting SCTP/UDP, 143fd7af143SMichael Tuexen * additional 8 bytes are needed. 144f77b8427SMichael Tuexen */ 145fd7af143SMichael Tuexen #define ICMP_ADVLENPREF(p) (8 + ((p)->icmp_ip.ip_hl << 2) + 8 + 8 + 12) 146df8bae1dSRodney W. Grimes 147df8bae1dSRodney W. Grimes /* 148df8bae1dSRodney W. Grimes * Definition of type and code field values. 149df8bae1dSRodney W. Grimes */ 150df8bae1dSRodney W. Grimes #define ICMP_ECHOREPLY 0 /* echo reply */ 151df8bae1dSRodney W. Grimes #define ICMP_UNREACH 3 /* dest unreachable, codes: */ 152df8bae1dSRodney W. Grimes #define ICMP_UNREACH_NET 0 /* bad net */ 153df8bae1dSRodney W. Grimes #define ICMP_UNREACH_HOST 1 /* bad host */ 154df8bae1dSRodney W. Grimes #define ICMP_UNREACH_PROTOCOL 2 /* bad protocol */ 155df8bae1dSRodney W. Grimes #define ICMP_UNREACH_PORT 3 /* bad port */ 156df8bae1dSRodney W. Grimes #define ICMP_UNREACH_NEEDFRAG 4 /* IP_DF caused drop */ 157df8bae1dSRodney W. Grimes #define ICMP_UNREACH_SRCFAIL 5 /* src route failed */ 158df8bae1dSRodney W. Grimes #define ICMP_UNREACH_NET_UNKNOWN 6 /* unknown net */ 159df8bae1dSRodney W. Grimes #define ICMP_UNREACH_HOST_UNKNOWN 7 /* unknown host */ 160df8bae1dSRodney W. Grimes #define ICMP_UNREACH_ISOLATED 8 /* src host isolated */ 161df8bae1dSRodney W. Grimes #define ICMP_UNREACH_NET_PROHIB 9 /* prohibited access */ 162df8bae1dSRodney W. Grimes #define ICMP_UNREACH_HOST_PROHIB 10 /* ditto */ 163df8bae1dSRodney W. Grimes #define ICMP_UNREACH_TOSNET 11 /* bad tos for net */ 164df8bae1dSRodney W. Grimes #define ICMP_UNREACH_TOSHOST 12 /* bad tos for host */ 165e329301eSBill Fenner #define ICMP_UNREACH_FILTER_PROHIB 13 /* admin prohib */ 166e329301eSBill Fenner #define ICMP_UNREACH_HOST_PRECEDENCE 14 /* host prec vio. */ 167e329301eSBill Fenner #define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 /* prec cutoff */ 168df8bae1dSRodney W. Grimes #define ICMP_SOURCEQUENCH 4 /* packet lost, slow down */ 169df8bae1dSRodney W. Grimes #define ICMP_REDIRECT 5 /* shorter route, codes: */ 170df8bae1dSRodney W. Grimes #define ICMP_REDIRECT_NET 0 /* for network */ 171df8bae1dSRodney W. Grimes #define ICMP_REDIRECT_HOST 1 /* for host */ 172df8bae1dSRodney W. Grimes #define ICMP_REDIRECT_TOSNET 2 /* for tos and net */ 173df8bae1dSRodney W. Grimes #define ICMP_REDIRECT_TOSHOST 3 /* for tos and host */ 174cc5934f5SMax Laier #define ICMP_ALTHOSTADDR 6 /* alternate host address */ 175df8bae1dSRodney W. Grimes #define ICMP_ECHO 8 /* echo service */ 176df8bae1dSRodney W. Grimes #define ICMP_ROUTERADVERT 9 /* router advertisement */ 177cc5934f5SMax Laier #define ICMP_ROUTERADVERT_NORMAL 0 /* normal advertisement */ 178cc5934f5SMax Laier #define ICMP_ROUTERADVERT_NOROUTE_COMMON 16 /* selective routing */ 179df8bae1dSRodney W. Grimes #define ICMP_ROUTERSOLICIT 10 /* router solicitation */ 180df8bae1dSRodney W. Grimes #define ICMP_TIMXCEED 11 /* time exceeded, code: */ 181df8bae1dSRodney W. Grimes #define ICMP_TIMXCEED_INTRANS 0 /* ttl==0 in transit */ 182df8bae1dSRodney W. Grimes #define ICMP_TIMXCEED_REASS 1 /* ttl==0 in reass */ 183df8bae1dSRodney W. Grimes #define ICMP_PARAMPROB 12 /* ip header bad */ 18440953642SJonathan M. Bresler #define ICMP_PARAMPROB_ERRATPTR 0 /* error at param ptr */ 185df8bae1dSRodney W. Grimes #define ICMP_PARAMPROB_OPTABSENT 1 /* req. opt. absent */ 18640953642SJonathan M. Bresler #define ICMP_PARAMPROB_LENGTH 2 /* bad length */ 187df8bae1dSRodney W. Grimes #define ICMP_TSTAMP 13 /* timestamp request */ 188df8bae1dSRodney W. Grimes #define ICMP_TSTAMPREPLY 14 /* timestamp reply */ 189df8bae1dSRodney W. Grimes #define ICMP_IREQ 15 /* information request */ 190df8bae1dSRodney W. Grimes #define ICMP_IREQREPLY 16 /* information reply */ 191df8bae1dSRodney W. Grimes #define ICMP_MASKREQ 17 /* address mask request */ 192df8bae1dSRodney W. Grimes #define ICMP_MASKREPLY 18 /* address mask reply */ 193cc5934f5SMax Laier #define ICMP_TRACEROUTE 30 /* traceroute */ 194cc5934f5SMax Laier #define ICMP_DATACONVERR 31 /* data conversion error */ 195cc5934f5SMax Laier #define ICMP_MOBILE_REDIRECT 32 /* mobile host redirect */ 196cc5934f5SMax Laier #define ICMP_IPV6_WHEREAREYOU 33 /* IPv6 where-are-you */ 197cc5934f5SMax Laier #define ICMP_IPV6_IAMHERE 34 /* IPv6 i-am-here */ 198cc5934f5SMax Laier #define ICMP_MOBILE_REGREQUEST 35 /* mobile registration req */ 199cc5934f5SMax Laier #define ICMP_MOBILE_REGREPLY 36 /* mobile registration reply */ 200cc5934f5SMax Laier #define ICMP_SKIP 39 /* SKIP */ 201cc5934f5SMax Laier #define ICMP_PHOTURIS 40 /* Photuris */ 202cc5934f5SMax Laier #define ICMP_PHOTURIS_UNKNOWN_INDEX 1 /* unknown sec index */ 203cc5934f5SMax Laier #define ICMP_PHOTURIS_AUTH_FAILED 2 /* auth failed */ 204cc5934f5SMax Laier #define ICMP_PHOTURIS_DECRYPT_FAILED 3 /* decrypt failed */ 205df8bae1dSRodney W. Grimes 206cc5934f5SMax Laier #define ICMP_MAXTYPE 40 207df8bae1dSRodney W. Grimes 208df8bae1dSRodney W. Grimes #define ICMP_INFOTYPE(type) \ 209df8bae1dSRodney W. Grimes ((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \ 210df8bae1dSRodney W. Grimes (type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \ 211df8bae1dSRodney W. Grimes (type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \ 212df8bae1dSRodney W. Grimes (type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \ 213df8bae1dSRodney W. Grimes (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY) 214df8bae1dSRodney W. Grimes 215664a31e4SPeter Wemm #ifdef _KERNEL 216*fcb3f813SGleb Smirnoff int icmp_errmap(const struct icmp *); 217d685b6eeSLuigi Rizzo void icmp_error(struct mbuf *, int, int, uint32_t, int); 2188f5a8818SKevin Lo int icmp_input(struct mbuf **, int *, int); 2191aedbd9cSAndre Oppermann int ip_next_mtu(int, int); 220df8bae1dSRodney W. Grimes #endif 221707f139eSPaul Richards 222707f139eSPaul Richards #endif 223