1139823Simp/*- 21541Srgrimes * Copyright (c) 1982, 1986, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 4. Neither the name of the University nor the names of its contributors 141541Srgrimes * may be used to endorse or promote products derived from this software 151541Srgrimes * without specific prior written permission. 161541Srgrimes * 171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271541Srgrimes * SUCH DAMAGE. 281541Srgrimes * 291541Srgrimes * @(#)ip_icmp.h 8.1 (Berkeley) 6/10/93 3050477Speter * $FreeBSD$ 311541Srgrimes */ 321541Srgrimes 332169Spaul#ifndef _NETINET_IP_ICMP_H_ 342169Spaul#define _NETINET_IP_ICMP_H_ 352169Spaul 361541Srgrimes/* 371541Srgrimes * Interface Control Message Protocol Definitions. 381541Srgrimes * Per RFC 792, September 1981. 391541Srgrimes */ 401541Srgrimes 411541Srgrimes/* 4213486Sfenner * Internal of an ICMP Router Advertisement 4313486Sfenner */ 4413486Sfennerstruct icmp_ra_addr { 4513486Sfenner u_int32_t ira_addr; 4613486Sfenner u_int32_t ira_preference; 4713486Sfenner}; 4813486Sfenner 4913486Sfenner/* 501541Srgrimes * Structure of an icmp header. 511541Srgrimes */ 52145565Sbrooksstruct icmphdr { 53145565Sbrooks u_char icmp_type; /* type of message, see below */ 54145565Sbrooks u_char icmp_code; /* type sub code */ 55145565Sbrooks u_short icmp_cksum; /* ones complement cksum of struct */ 56145565Sbrooks}; 57145565Sbrooks 58145565Sbrooks/* 59145565Sbrooks * Structure of an icmp packet. 60145565Sbrooks * 61145565Sbrooks * XXX: should start with a struct icmphdr. 62145565Sbrooks */ 631541Srgrimesstruct icmp { 641541Srgrimes u_char icmp_type; /* type of message, see below */ 651541Srgrimes u_char icmp_code; /* type sub code */ 661541Srgrimes u_short icmp_cksum; /* ones complement cksum of struct */ 671541Srgrimes union { 681541Srgrimes u_char ih_pptr; /* ICMP_PARAMPROB */ 691541Srgrimes struct in_addr ih_gwaddr; /* ICMP_REDIRECT */ 701541Srgrimes struct ih_idseq { 71188578Sluigi uint16_t icd_id; /* network format */ 72188578Sluigi uint16_t icd_seq; /* network format */ 731541Srgrimes } ih_idseq; 741541Srgrimes int ih_void; 751541Srgrimes 761541Srgrimes /* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */ 771541Srgrimes struct ih_pmtu { 78188578Sluigi uint16_t ipm_void; /* network format */ 79188578Sluigi uint16_t ipm_nextmtu; /* network format */ 801541Srgrimes } ih_pmtu; 8113486Sfenner 8213486Sfenner struct ih_rtradv { 8313486Sfenner u_char irt_num_addrs; 8413486Sfenner u_char irt_wpa; 8513486Sfenner u_int16_t irt_lifetime; 8613486Sfenner } ih_rtradv; 871541Srgrimes } icmp_hun; 881541Srgrimes#define icmp_pptr icmp_hun.ih_pptr 891541Srgrimes#define icmp_gwaddr icmp_hun.ih_gwaddr 901541Srgrimes#define icmp_id icmp_hun.ih_idseq.icd_id 911541Srgrimes#define icmp_seq icmp_hun.ih_idseq.icd_seq 921541Srgrimes#define icmp_void icmp_hun.ih_void 931541Srgrimes#define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void 941541Srgrimes#define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu 9513486Sfenner#define icmp_num_addrs icmp_hun.ih_rtradv.irt_num_addrs 9613486Sfenner#define icmp_wpa icmp_hun.ih_rtradv.irt_wpa 9713486Sfenner#define icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime 981541Srgrimes union { 99112464Smdodd struct id_ts { /* ICMP Timestamp */ 100188578Sluigi /* 101188578Sluigi * The next 3 fields are in network format, 102188578Sluigi * milliseconds since 00:00 GMT 103188578Sluigi */ 104188578Sluigi uint32_t its_otime; /* Originate */ 105188578Sluigi uint32_t its_rtime; /* Receive */ 106188578Sluigi uint32_t its_ttime; /* Transmit */ 1071541Srgrimes } id_ts; 1081541Srgrimes struct id_ip { 1091541Srgrimes struct ip idi_ip; 1101541Srgrimes /* options and then 64 bits of data */ 1111541Srgrimes } id_ip; 11213486Sfenner struct icmp_ra_addr id_radv; 11337621Sbde u_int32_t id_mask; 1141541Srgrimes char id_data[1]; 1151541Srgrimes } icmp_dun; 1161541Srgrimes#define icmp_otime icmp_dun.id_ts.its_otime 1171541Srgrimes#define icmp_rtime icmp_dun.id_ts.its_rtime 1181541Srgrimes#define icmp_ttime icmp_dun.id_ts.its_ttime 1191541Srgrimes#define icmp_ip icmp_dun.id_ip.idi_ip 12013486Sfenner#define icmp_radv icmp_dun.id_radv 1211541Srgrimes#define icmp_mask icmp_dun.id_mask 1221541Srgrimes#define icmp_data icmp_dun.id_data 1231541Srgrimes}; 1241541Srgrimes 1251541Srgrimes/* 1261541Srgrimes * Lower bounds on packet lengths for various types. 1271541Srgrimes * For the error advice packets must first insure that the 12813765Smpp * packet is large enough to contain the returned ip header. 1291541Srgrimes * Only then can we do the check to see if 64 bits of packet 1301541Srgrimes * data have been returned, since we need to check the returned 1311541Srgrimes * ip header length. 1321541Srgrimes */ 1331541Srgrimes#define ICMP_MINLEN 8 /* abs minimum */ 134188578Sluigi#define ICMP_TSLEN (8 + 3 * sizeof (uint32_t)) /* timestamp */ 1351541Srgrimes#define ICMP_MASKLEN 12 /* address mask */ 1361541Srgrimes#define ICMP_ADVLENMIN (8 + sizeof (struct ip) + 8) /* min */ 1371541Srgrimes#define ICMP_ADVLEN(p) (8 + ((p)->icmp_ip.ip_hl << 2) + 8) 1381541Srgrimes /* N.B.: must separately check that ip_hl >= 5 */ 1391541Srgrimes 1401541Srgrimes/* 1411541Srgrimes * Definition of type and code field values. 1421541Srgrimes */ 1431541Srgrimes#define ICMP_ECHOREPLY 0 /* echo reply */ 1441541Srgrimes#define ICMP_UNREACH 3 /* dest unreachable, codes: */ 1451541Srgrimes#define ICMP_UNREACH_NET 0 /* bad net */ 1461541Srgrimes#define ICMP_UNREACH_HOST 1 /* bad host */ 1471541Srgrimes#define ICMP_UNREACH_PROTOCOL 2 /* bad protocol */ 1481541Srgrimes#define ICMP_UNREACH_PORT 3 /* bad port */ 1491541Srgrimes#define ICMP_UNREACH_NEEDFRAG 4 /* IP_DF caused drop */ 1501541Srgrimes#define ICMP_UNREACH_SRCFAIL 5 /* src route failed */ 1511541Srgrimes#define ICMP_UNREACH_NET_UNKNOWN 6 /* unknown net */ 1521541Srgrimes#define ICMP_UNREACH_HOST_UNKNOWN 7 /* unknown host */ 1531541Srgrimes#define ICMP_UNREACH_ISOLATED 8 /* src host isolated */ 1541541Srgrimes#define ICMP_UNREACH_NET_PROHIB 9 /* prohibited access */ 1551541Srgrimes#define ICMP_UNREACH_HOST_PROHIB 10 /* ditto */ 1561541Srgrimes#define ICMP_UNREACH_TOSNET 11 /* bad tos for net */ 1571541Srgrimes#define ICMP_UNREACH_TOSHOST 12 /* bad tos for host */ 15817720Sfenner#define ICMP_UNREACH_FILTER_PROHIB 13 /* admin prohib */ 15917720Sfenner#define ICMP_UNREACH_HOST_PRECEDENCE 14 /* host prec vio. */ 16017720Sfenner#define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 /* prec cutoff */ 1611541Srgrimes#define ICMP_SOURCEQUENCH 4 /* packet lost, slow down */ 1621541Srgrimes#define ICMP_REDIRECT 5 /* shorter route, codes: */ 1631541Srgrimes#define ICMP_REDIRECT_NET 0 /* for network */ 1641541Srgrimes#define ICMP_REDIRECT_HOST 1 /* for host */ 1651541Srgrimes#define ICMP_REDIRECT_TOSNET 2 /* for tos and net */ 1661541Srgrimes#define ICMP_REDIRECT_TOSHOST 3 /* for tos and host */ 167126263Smlaier#define ICMP_ALTHOSTADDR 6 /* alternate host address */ 1681541Srgrimes#define ICMP_ECHO 8 /* echo service */ 1691541Srgrimes#define ICMP_ROUTERADVERT 9 /* router advertisement */ 170126263Smlaier#define ICMP_ROUTERADVERT_NORMAL 0 /* normal advertisement */ 171126263Smlaier#define ICMP_ROUTERADVERT_NOROUTE_COMMON 16 /* selective routing */ 1721541Srgrimes#define ICMP_ROUTERSOLICIT 10 /* router solicitation */ 1731541Srgrimes#define ICMP_TIMXCEED 11 /* time exceeded, code: */ 1741541Srgrimes#define ICMP_TIMXCEED_INTRANS 0 /* ttl==0 in transit */ 1751541Srgrimes#define ICMP_TIMXCEED_REASS 1 /* ttl==0 in reass */ 1761541Srgrimes#define ICMP_PARAMPROB 12 /* ip header bad */ 17753187Sjmb#define ICMP_PARAMPROB_ERRATPTR 0 /* error at param ptr */ 1781541Srgrimes#define ICMP_PARAMPROB_OPTABSENT 1 /* req. opt. absent */ 17953187Sjmb#define ICMP_PARAMPROB_LENGTH 2 /* bad length */ 1801541Srgrimes#define ICMP_TSTAMP 13 /* timestamp request */ 1811541Srgrimes#define ICMP_TSTAMPREPLY 14 /* timestamp reply */ 1821541Srgrimes#define ICMP_IREQ 15 /* information request */ 1831541Srgrimes#define ICMP_IREQREPLY 16 /* information reply */ 1841541Srgrimes#define ICMP_MASKREQ 17 /* address mask request */ 1851541Srgrimes#define ICMP_MASKREPLY 18 /* address mask reply */ 186126263Smlaier#define ICMP_TRACEROUTE 30 /* traceroute */ 187126263Smlaier#define ICMP_DATACONVERR 31 /* data conversion error */ 188126263Smlaier#define ICMP_MOBILE_REDIRECT 32 /* mobile host redirect */ 189126263Smlaier#define ICMP_IPV6_WHEREAREYOU 33 /* IPv6 where-are-you */ 190126263Smlaier#define ICMP_IPV6_IAMHERE 34 /* IPv6 i-am-here */ 191126263Smlaier#define ICMP_MOBILE_REGREQUEST 35 /* mobile registration req */ 192126263Smlaier#define ICMP_MOBILE_REGREPLY 36 /* mobile registration reply */ 193126263Smlaier#define ICMP_SKIP 39 /* SKIP */ 194126263Smlaier#define ICMP_PHOTURIS 40 /* Photuris */ 195126263Smlaier#define ICMP_PHOTURIS_UNKNOWN_INDEX 1 /* unknown sec index */ 196126263Smlaier#define ICMP_PHOTURIS_AUTH_FAILED 2 /* auth failed */ 197126263Smlaier#define ICMP_PHOTURIS_DECRYPT_FAILED 3 /* decrypt failed */ 1981541Srgrimes 199126263Smlaier#define ICMP_MAXTYPE 40 2001541Srgrimes 2011541Srgrimes#define ICMP_INFOTYPE(type) \ 2021541Srgrimes ((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \ 2031541Srgrimes (type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \ 2041541Srgrimes (type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \ 2051541Srgrimes (type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \ 2061541Srgrimes (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY) 2071541Srgrimes 20855205Speter#ifdef _KERNEL 209188578Sluigivoid icmp_error(struct mbuf *, int, int, uint32_t, int); 21092723Salfredvoid icmp_input(struct mbuf *, int); 211145360Sandreint ip_next_mtu(int, int); 2121541Srgrimes#endif 2132169Spaul 2142169Spaul#endif 215