11eaf0ac3Slogwang /*- 2*d4a07e70Sfengbojiang * SPDX-License-Identifier: BSD-3-Clause 3*d4a07e70Sfengbojiang * 41eaf0ac3Slogwang * Copyright (c) 1982, 1986, 1993 51eaf0ac3Slogwang * The Regents of the University of California. All rights reserved. 61eaf0ac3Slogwang * 71eaf0ac3Slogwang * Redistribution and use in source and binary forms, with or without 81eaf0ac3Slogwang * modification, are permitted provided that the following conditions 91eaf0ac3Slogwang * are met: 101eaf0ac3Slogwang * 1. Redistributions of source code must retain the above copyright 111eaf0ac3Slogwang * notice, this list of conditions and the following disclaimer. 121eaf0ac3Slogwang * 2. Redistributions in binary form must reproduce the above copyright 131eaf0ac3Slogwang * notice, this list of conditions and the following disclaimer in the 141eaf0ac3Slogwang * documentation and/or other materials provided with the distribution. 15*d4a07e70Sfengbojiang * 3. Neither the name of the University nor the names of its contributors 161eaf0ac3Slogwang * may be used to endorse or promote products derived from this software 171eaf0ac3Slogwang * without specific prior written permission. 181eaf0ac3Slogwang * 191eaf0ac3Slogwang * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 201eaf0ac3Slogwang * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 211eaf0ac3Slogwang * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 221eaf0ac3Slogwang * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 231eaf0ac3Slogwang * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 241eaf0ac3Slogwang * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 251eaf0ac3Slogwang * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 261eaf0ac3Slogwang * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 271eaf0ac3Slogwang * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 281eaf0ac3Slogwang * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 291eaf0ac3Slogwang * SUCH DAMAGE. 301eaf0ac3Slogwang * 311eaf0ac3Slogwang * @(#)ip_icmp.h 8.1 (Berkeley) 6/10/93 321eaf0ac3Slogwang * $FreeBSD$ 331eaf0ac3Slogwang */ 341eaf0ac3Slogwang 351eaf0ac3Slogwang #ifndef _NETINET_IP_ICMP_H_ 361eaf0ac3Slogwang #define _NETINET_IP_ICMP_H_ 371eaf0ac3Slogwang 381eaf0ac3Slogwang /* 391eaf0ac3Slogwang * Interface Control Message Protocol Definitions. 401eaf0ac3Slogwang * Per RFC 792, September 1981. 411eaf0ac3Slogwang */ 421eaf0ac3Slogwang 431eaf0ac3Slogwang /* 441eaf0ac3Slogwang * Internal of an ICMP Router Advertisement 451eaf0ac3Slogwang */ 461eaf0ac3Slogwang struct icmp_ra_addr { 471eaf0ac3Slogwang u_int32_t ira_addr; 481eaf0ac3Slogwang u_int32_t ira_preference; 491eaf0ac3Slogwang }; 501eaf0ac3Slogwang 511eaf0ac3Slogwang /* 521eaf0ac3Slogwang * Structure of an icmp header. 531eaf0ac3Slogwang */ 541eaf0ac3Slogwang struct icmphdr { 551eaf0ac3Slogwang u_char icmp_type; /* type of message, see below */ 561eaf0ac3Slogwang u_char icmp_code; /* type sub code */ 571eaf0ac3Slogwang u_short icmp_cksum; /* ones complement cksum of struct */ 581eaf0ac3Slogwang }; 591eaf0ac3Slogwang 601eaf0ac3Slogwang /* 611eaf0ac3Slogwang * Structure of an icmp packet. 621eaf0ac3Slogwang * 631eaf0ac3Slogwang * XXX: should start with a struct icmphdr. 641eaf0ac3Slogwang */ 651eaf0ac3Slogwang struct icmp { 661eaf0ac3Slogwang u_char icmp_type; /* type of message, see below */ 671eaf0ac3Slogwang u_char icmp_code; /* type sub code */ 681eaf0ac3Slogwang u_short icmp_cksum; /* ones complement cksum of struct */ 691eaf0ac3Slogwang union { 701eaf0ac3Slogwang u_char ih_pptr; /* ICMP_PARAMPROB */ 711eaf0ac3Slogwang struct in_addr ih_gwaddr; /* ICMP_REDIRECT */ 721eaf0ac3Slogwang struct ih_idseq { 731eaf0ac3Slogwang uint16_t icd_id; /* network format */ 741eaf0ac3Slogwang uint16_t icd_seq; /* network format */ 751eaf0ac3Slogwang } ih_idseq; 761eaf0ac3Slogwang int ih_void; 771eaf0ac3Slogwang 781eaf0ac3Slogwang /* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */ 791eaf0ac3Slogwang struct ih_pmtu { 801eaf0ac3Slogwang uint16_t ipm_void; /* network format */ 811eaf0ac3Slogwang uint16_t ipm_nextmtu; /* network format */ 821eaf0ac3Slogwang } ih_pmtu; 831eaf0ac3Slogwang 841eaf0ac3Slogwang struct ih_rtradv { 851eaf0ac3Slogwang u_char irt_num_addrs; 861eaf0ac3Slogwang u_char irt_wpa; 871eaf0ac3Slogwang u_int16_t irt_lifetime; 881eaf0ac3Slogwang } ih_rtradv; 891eaf0ac3Slogwang } icmp_hun; 901eaf0ac3Slogwang #define icmp_pptr icmp_hun.ih_pptr 911eaf0ac3Slogwang #define icmp_gwaddr icmp_hun.ih_gwaddr 921eaf0ac3Slogwang #define icmp_id icmp_hun.ih_idseq.icd_id 931eaf0ac3Slogwang #define icmp_seq icmp_hun.ih_idseq.icd_seq 941eaf0ac3Slogwang #define icmp_void icmp_hun.ih_void 951eaf0ac3Slogwang #define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void 961eaf0ac3Slogwang #define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu 971eaf0ac3Slogwang #define icmp_num_addrs icmp_hun.ih_rtradv.irt_num_addrs 981eaf0ac3Slogwang #define icmp_wpa icmp_hun.ih_rtradv.irt_wpa 991eaf0ac3Slogwang #define icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime 1001eaf0ac3Slogwang union { 1011eaf0ac3Slogwang struct id_ts { /* ICMP Timestamp */ 1021eaf0ac3Slogwang /* 1031eaf0ac3Slogwang * The next 3 fields are in network format, 1041eaf0ac3Slogwang * milliseconds since 00:00 UTC 1051eaf0ac3Slogwang */ 1061eaf0ac3Slogwang uint32_t its_otime; /* Originate */ 1071eaf0ac3Slogwang uint32_t its_rtime; /* Receive */ 1081eaf0ac3Slogwang uint32_t its_ttime; /* Transmit */ 1091eaf0ac3Slogwang } id_ts; 1101eaf0ac3Slogwang struct id_ip { 1111eaf0ac3Slogwang struct ip idi_ip; 1121eaf0ac3Slogwang /* options and then 64 bits of data */ 1131eaf0ac3Slogwang } id_ip; 1141eaf0ac3Slogwang struct icmp_ra_addr id_radv; 1151eaf0ac3Slogwang u_int32_t id_mask; 1161eaf0ac3Slogwang char id_data[1]; 1171eaf0ac3Slogwang } icmp_dun; 1181eaf0ac3Slogwang #define icmp_otime icmp_dun.id_ts.its_otime 1191eaf0ac3Slogwang #define icmp_rtime icmp_dun.id_ts.its_rtime 1201eaf0ac3Slogwang #define icmp_ttime icmp_dun.id_ts.its_ttime 1211eaf0ac3Slogwang #define icmp_ip icmp_dun.id_ip.idi_ip 1221eaf0ac3Slogwang #define icmp_radv icmp_dun.id_radv 1231eaf0ac3Slogwang #define icmp_mask icmp_dun.id_mask 1241eaf0ac3Slogwang #define icmp_data icmp_dun.id_data 1251eaf0ac3Slogwang }; 1261eaf0ac3Slogwang 1271eaf0ac3Slogwang /* 1281eaf0ac3Slogwang * Lower bounds on packet lengths for various types. 1291eaf0ac3Slogwang * For the error advice packets must first insure that the 1301eaf0ac3Slogwang * packet is large enough to contain the returned ip header. 1311eaf0ac3Slogwang * Only then can we do the check to see if 64 bits of packet 1321eaf0ac3Slogwang * data have been returned, since we need to check the returned 1331eaf0ac3Slogwang * ip header length. 1341eaf0ac3Slogwang */ 1351eaf0ac3Slogwang #define ICMP_MINLEN 8 /* abs minimum */ 1361eaf0ac3Slogwang #define ICMP_TSLEN (8 + 3 * sizeof (uint32_t)) /* timestamp */ 1371eaf0ac3Slogwang #define ICMP_MASKLEN 12 /* address mask */ 1381eaf0ac3Slogwang #define ICMP_ADVLENMIN (8 + sizeof (struct ip) + 8) /* min */ 1391eaf0ac3Slogwang #define ICMP_ADVLEN(p) (8 + ((p)->icmp_ip.ip_hl << 2) + 8) 1401eaf0ac3Slogwang /* N.B.: must separately check that ip_hl >= 5 */ 1411eaf0ac3Slogwang /* This is the minimum length required by RFC 792. */ 1421eaf0ac3Slogwang /* 1431eaf0ac3Slogwang * ICMP_ADVLENPREF is the preferred number of bytes which should be contiguous. 1441eaf0ac3Slogwang * SCTP needs additional 12 bytes to be able to access the initiate tag 1451eaf0ac3Slogwang * in packets containing an INIT chunk. For also supporting SCTP/UDP, 1461eaf0ac3Slogwang * additional 8 bytes are needed. 1471eaf0ac3Slogwang */ 1481eaf0ac3Slogwang #define ICMP_ADVLENPREF(p) (8 + ((p)->icmp_ip.ip_hl << 2) + 8 + 8 + 12) 1491eaf0ac3Slogwang 1501eaf0ac3Slogwang /* 1511eaf0ac3Slogwang * Definition of type and code field values. 1521eaf0ac3Slogwang */ 1531eaf0ac3Slogwang #define ICMP_ECHOREPLY 0 /* echo reply */ 1541eaf0ac3Slogwang #define ICMP_UNREACH 3 /* dest unreachable, codes: */ 1551eaf0ac3Slogwang #define ICMP_UNREACH_NET 0 /* bad net */ 1561eaf0ac3Slogwang #define ICMP_UNREACH_HOST 1 /* bad host */ 1571eaf0ac3Slogwang #define ICMP_UNREACH_PROTOCOL 2 /* bad protocol */ 1581eaf0ac3Slogwang #define ICMP_UNREACH_PORT 3 /* bad port */ 1591eaf0ac3Slogwang #define ICMP_UNREACH_NEEDFRAG 4 /* IP_DF caused drop */ 1601eaf0ac3Slogwang #define ICMP_UNREACH_SRCFAIL 5 /* src route failed */ 1611eaf0ac3Slogwang #define ICMP_UNREACH_NET_UNKNOWN 6 /* unknown net */ 1621eaf0ac3Slogwang #define ICMP_UNREACH_HOST_UNKNOWN 7 /* unknown host */ 1631eaf0ac3Slogwang #define ICMP_UNREACH_ISOLATED 8 /* src host isolated */ 1641eaf0ac3Slogwang #define ICMP_UNREACH_NET_PROHIB 9 /* prohibited access */ 1651eaf0ac3Slogwang #define ICMP_UNREACH_HOST_PROHIB 10 /* ditto */ 1661eaf0ac3Slogwang #define ICMP_UNREACH_TOSNET 11 /* bad tos for net */ 1671eaf0ac3Slogwang #define ICMP_UNREACH_TOSHOST 12 /* bad tos for host */ 1681eaf0ac3Slogwang #define ICMP_UNREACH_FILTER_PROHIB 13 /* admin prohib */ 1691eaf0ac3Slogwang #define ICMP_UNREACH_HOST_PRECEDENCE 14 /* host prec vio. */ 1701eaf0ac3Slogwang #define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 /* prec cutoff */ 1711eaf0ac3Slogwang #define ICMP_SOURCEQUENCH 4 /* packet lost, slow down */ 1721eaf0ac3Slogwang #define ICMP_REDIRECT 5 /* shorter route, codes: */ 1731eaf0ac3Slogwang #define ICMP_REDIRECT_NET 0 /* for network */ 1741eaf0ac3Slogwang #define ICMP_REDIRECT_HOST 1 /* for host */ 1751eaf0ac3Slogwang #define ICMP_REDIRECT_TOSNET 2 /* for tos and net */ 1761eaf0ac3Slogwang #define ICMP_REDIRECT_TOSHOST 3 /* for tos and host */ 1771eaf0ac3Slogwang #define ICMP_ALTHOSTADDR 6 /* alternate host address */ 1781eaf0ac3Slogwang #define ICMP_ECHO 8 /* echo service */ 1791eaf0ac3Slogwang #define ICMP_ROUTERADVERT 9 /* router advertisement */ 1801eaf0ac3Slogwang #define ICMP_ROUTERADVERT_NORMAL 0 /* normal advertisement */ 1811eaf0ac3Slogwang #define ICMP_ROUTERADVERT_NOROUTE_COMMON 16 /* selective routing */ 1821eaf0ac3Slogwang #define ICMP_ROUTERSOLICIT 10 /* router solicitation */ 1831eaf0ac3Slogwang #define ICMP_TIMXCEED 11 /* time exceeded, code: */ 1841eaf0ac3Slogwang #define ICMP_TIMXCEED_INTRANS 0 /* ttl==0 in transit */ 1851eaf0ac3Slogwang #define ICMP_TIMXCEED_REASS 1 /* ttl==0 in reass */ 1861eaf0ac3Slogwang #define ICMP_PARAMPROB 12 /* ip header bad */ 1871eaf0ac3Slogwang #define ICMP_PARAMPROB_ERRATPTR 0 /* error at param ptr */ 1881eaf0ac3Slogwang #define ICMP_PARAMPROB_OPTABSENT 1 /* req. opt. absent */ 1891eaf0ac3Slogwang #define ICMP_PARAMPROB_LENGTH 2 /* bad length */ 1901eaf0ac3Slogwang #define ICMP_TSTAMP 13 /* timestamp request */ 1911eaf0ac3Slogwang #define ICMP_TSTAMPREPLY 14 /* timestamp reply */ 1921eaf0ac3Slogwang #define ICMP_IREQ 15 /* information request */ 1931eaf0ac3Slogwang #define ICMP_IREQREPLY 16 /* information reply */ 1941eaf0ac3Slogwang #define ICMP_MASKREQ 17 /* address mask request */ 1951eaf0ac3Slogwang #define ICMP_MASKREPLY 18 /* address mask reply */ 1961eaf0ac3Slogwang #define ICMP_TRACEROUTE 30 /* traceroute */ 1971eaf0ac3Slogwang #define ICMP_DATACONVERR 31 /* data conversion error */ 1981eaf0ac3Slogwang #define ICMP_MOBILE_REDIRECT 32 /* mobile host redirect */ 1991eaf0ac3Slogwang #define ICMP_IPV6_WHEREAREYOU 33 /* IPv6 where-are-you */ 2001eaf0ac3Slogwang #define ICMP_IPV6_IAMHERE 34 /* IPv6 i-am-here */ 2011eaf0ac3Slogwang #define ICMP_MOBILE_REGREQUEST 35 /* mobile registration req */ 2021eaf0ac3Slogwang #define ICMP_MOBILE_REGREPLY 36 /* mobile registration reply */ 2031eaf0ac3Slogwang #define ICMP_SKIP 39 /* SKIP */ 2041eaf0ac3Slogwang #define ICMP_PHOTURIS 40 /* Photuris */ 2051eaf0ac3Slogwang #define ICMP_PHOTURIS_UNKNOWN_INDEX 1 /* unknown sec index */ 2061eaf0ac3Slogwang #define ICMP_PHOTURIS_AUTH_FAILED 2 /* auth failed */ 2071eaf0ac3Slogwang #define ICMP_PHOTURIS_DECRYPT_FAILED 3 /* decrypt failed */ 2081eaf0ac3Slogwang 2091eaf0ac3Slogwang #define ICMP_MAXTYPE 40 2101eaf0ac3Slogwang 2111eaf0ac3Slogwang #define ICMP_INFOTYPE(type) \ 2121eaf0ac3Slogwang ((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \ 2131eaf0ac3Slogwang (type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \ 2141eaf0ac3Slogwang (type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \ 2151eaf0ac3Slogwang (type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \ 2161eaf0ac3Slogwang (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY) 2171eaf0ac3Slogwang 2181eaf0ac3Slogwang #ifdef _KERNEL 2191eaf0ac3Slogwang void icmp_error(struct mbuf *, int, int, uint32_t, int); 2201eaf0ac3Slogwang int icmp_input(struct mbuf **, int *, int); 2211eaf0ac3Slogwang int ip_next_mtu(int, int); 2221eaf0ac3Slogwang #endif 2231eaf0ac3Slogwang 2241eaf0ac3Slogwang #endif 225