Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

icmp.h

Go to the documentation of this file.
00001 /*
00002  * icmp.h
00003  *
00004  * Internet Control Message Protocol.
00005  * RFC 792, 950, 1256, 1393, 1475, 2002, 2521
00006  *
00007  * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
00008  *
00009  * $Id: icmp.h,v 1.14 2003/03/16 17:39:17 dugsong Exp $
00010  */
00011 
00012 #ifndef DNET_ICMP_H
00013 #define DNET_ICMP_H
00014 
00015 #define ICMP_HDR_LEN    4       /* base ICMP header length */
00016 #define ICMP_LEN_MIN    8       /* minimum ICMP message size, with header */
00017 
00018 #ifndef __GNUC__
00019 # define __attribute__(x)
00020 # pragma pack(1)
00021 #endif
00022 
00023 /*
00024  * ICMP header
00025  */
00026 struct icmp_hdr {
00027         uint8_t         icmp_type;      /* type of message, see below */
00028         uint8_t         icmp_code;      /* type sub code */
00029         uint16_t        icmp_cksum;     /* ones complement cksum of struct */
00030 };
00031 
00032 /*
00033  * Types (icmp_type) and codes (icmp_code) -
00034  * http://www.iana.org/assignments/icmp-parameters
00035  */
00036 #define         ICMP_CODE_NONE          0       /* for types without codes */
00037 #define ICMP_ECHOREPLY          0               /* echo reply */
00038 #define ICMP_UNREACH            3               /* dest unreachable, codes: */
00039 #define         ICMP_UNREACH_NET                0       /* bad net */
00040 #define         ICMP_UNREACH_HOST               1       /* bad host */
00041 #define         ICMP_UNREACH_PROTO              2       /* bad protocol */
00042 #define         ICMP_UNREACH_PORT               3       /* bad port */
00043 #define         ICMP_UNREACH_NEEDFRAG           4       /* IP_DF caused drop */
00044 #define         ICMP_UNREACH_SRCFAIL            5       /* src route failed */
00045 #define         ICMP_UNREACH_NET_UNKNOWN        6       /* unknown net */
00046 #define         ICMP_UNREACH_HOST_UNKNOWN       7       /* unknown host */
00047 #define         ICMP_UNREACH_ISOLATED           8       /* src host isolated */
00048 #define         ICMP_UNREACH_NET_PROHIB         9       /* for crypto devs */
00049 #define         ICMP_UNREACH_HOST_PROHIB        10      /* ditto */
00050 #define         ICMP_UNREACH_TOSNET             11      /* bad tos for net */
00051 #define         ICMP_UNREACH_TOSHOST            12      /* bad tos for host */
00052 #define         ICMP_UNREACH_FILTER_PROHIB      13      /* prohibited access */
00053 #define         ICMP_UNREACH_HOST_PRECEDENCE    14      /* precedence error */
00054 #define         ICMP_UNREACH_PRECEDENCE_CUTOFF  15      /* precedence cutoff */
00055 #define ICMP_SRCQUENCH          4               /* packet lost, slow down */
00056 #define ICMP_REDIRECT           5               /* shorter route, codes: */
00057 #define         ICMP_REDIRECT_NET               0       /* for network */
00058 #define         ICMP_REDIRECT_HOST              1       /* for host */
00059 #define         ICMP_REDIRECT_TOSNET            2       /* for tos and net */
00060 #define         ICMP_REDIRECT_TOSHOST           3       /* for tos and host */
00061 #define ICMP_ALTHOSTADDR        6               /* alternate host address */
00062 #define ICMP_ECHO               8               /* echo service */
00063 #define ICMP_RTRADVERT          9               /* router advertise, codes: */
00064 #define         ICMP_RTRADVERT_NORMAL           0       /* normal */
00065 #define         ICMP_RTRADVERT_NOROUTE_COMMON 16        /* selective routing */
00066 #define ICMP_RTRSOLICIT         10              /* router solicitation */
00067 #define ICMP_TIMEXCEED          11              /* time exceeded, code: */
00068 #define         ICMP_TIMEXCEED_INTRANS          0       /* ttl==0 in transit */
00069 #define         ICMP_TIMEXCEED_REASS            1       /* ttl==0 in reass */
00070 #define ICMP_PARAMPROB          12              /* ip header bad */
00071 #define         ICMP_PARAMPROB_ERRATPTR         0       /* req. opt. absent */
00072 #define         ICMP_PARAMPROB_OPTABSENT        1       /* req. opt. absent */
00073 #define         ICMP_PARAMPROB_LENGTH           2       /* bad length */
00074 #define ICMP_TSTAMP             13              /* timestamp request */
00075 #define ICMP_TSTAMPREPLY        14              /* timestamp reply */
00076 #define ICMP_INFO               15              /* information request */
00077 #define ICMP_INFOREPLY          16              /* information reply */
00078 #define ICMP_MASK               17              /* address mask request */
00079 #define ICMP_MASKREPLY          18              /* address mask reply */
00080 #define ICMP_TRACEROUTE         30              /* traceroute */
00081 #define ICMP_DATACONVERR        31              /* data conversion error */
00082 #define ICMP_MOBILE_REDIRECT    32              /* mobile host redirect */
00083 #define ICMP_IPV6_WHEREAREYOU   33              /* IPv6 where-are-you */
00084 #define ICMP_IPV6_IAMHERE       34              /* IPv6 i-am-here */
00085 #define ICMP_MOBILE_REG         35              /* mobile registration req */
00086 #define ICMP_MOBILE_REGREPLY    36              /* mobile registration reply */
00087 #define ICMP_DNS                37              /* domain name request */
00088 #define ICMP_DNSREPLY           38              /* domain name reply */
00089 #define ICMP_SKIP               39              /* SKIP */
00090 #define ICMP_PHOTURIS           40              /* Photuris */
00091 #define         ICMP_PHOTURIS_UNKNOWN_INDEX     0       /* unknown sec index */
00092 #define         ICMP_PHOTURIS_AUTH_FAILED       1       /* auth failed */
00093 #define         ICMP_PHOTURIS_DECOMPRESS_FAILED 2       /* decompress failed */
00094 #define         ICMP_PHOTURIS_DECRYPT_FAILED    3       /* decrypt failed */
00095 #define         ICMP_PHOTURIS_NEED_AUTHN        4       /* no authentication */
00096 #define         ICMP_PHOTURIS_NEED_AUTHZ        5       /* no authorization */
00097 #define ICMP_TYPE_MAX           40
00098 
00099 #define ICMP_INFOTYPE(type)                                             \
00100         ((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO ||             \
00101         (type) == ICMP_RTRADVERT || (type) == ICMP_RTRSOLICIT ||        \
00102         (type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY ||          \
00103         (type) == ICMP_INFO || (type) == ICMP_INFOREPLY ||              \
00104         (type) == ICMP_MASK || (type) == ICMP_MASKREPLY)
00105 
00106 /*
00107  * Echo message data
00108  */
00109 struct icmp_msg_echo {
00110         uint16_t        icmp_id;
00111         uint16_t        icmp_seq;
00112         uint8_t         icmp_data __flexarr;    /* optional data */
00113 };
00114 
00115 /*
00116  * Fragmentation-needed (unreachable) message data
00117  */
00118 struct icmp_msg_needfrag {
00119         uint16_t        icmp_void;              /* must be zero */
00120         uint16_t        icmp_mtu;               /* MTU of next-hop network */
00121         uint8_t         icmp_ip __flexarr;      /* IP hdr + 8 bytes of pkt */
00122 };
00123 
00124 /*
00125  *  Unreachable, source quench, redirect, time exceeded,
00126  *  parameter problem message data
00127  */
00128 struct icmp_msg_quote {
00129         uint32_t        icmp_void;              /* must be zero */
00130 #define icmp_gwaddr     icmp_void               /* router IP address to use */
00131 #define icmp_pptr       icmp_void               /* ptr to bad octet field */
00132         uint8_t         icmp_ip __flexarr;      /* IP hdr + 8 bytes of pkt */
00133 };
00134 
00135 /*
00136  * Router advertisement message data, RFC 1256
00137  */
00138 struct icmp_msg_rtradvert {
00139         uint8_t         icmp_num_addrs;         /* # of address / pref pairs */
00140         uint8_t         icmp_wpa;               /* words / address == 2 */
00141         uint16_t        icmp_lifetime;          /* route lifetime in seconds */
00142         struct icmp_msg_rtr_data {
00143                 uint32_t        icmp_void;
00144 #define icmp_gwaddr             icmp_void       /* router IP address */
00145                 uint32_t        icmp_pref;      /* router preference (usu 0) */
00146         } icmp_rtr __flexarr;                   /* variable # of routers */
00147 };
00148 #define ICMP_RTR_PREF_NODEFAULT 0x80000000      /* do not use as default gw */
00149 
00150 /*
00151  * Timestamp message data
00152  */
00153 struct icmp_msg_tstamp {
00154         uint32_t        icmp_id;                /* identifier */
00155         uint32_t        icmp_seq;               /* sequence number */
00156         uint32_t        icmp_ts_orig;           /* originate timestamp */
00157         uint32_t        icmp_ts_rx;             /* receive timestamp */
00158         uint32_t        icmp_ts_tx;             /* transmit timestamp */
00159 };
00160 
00161 /*
00162  * Address mask message data, RFC 950
00163  */
00164 struct icmp_msg_mask {
00165         uint32_t        icmp_id;                /* identifier */
00166         uint32_t        icmp_seq;               /* sequence number */
00167         uint32_t        icmp_mask;              /* address mask */
00168 };
00169 
00170 /*
00171  * Traceroute message data, RFC 1393, RFC 1812
00172  */
00173 struct icmp_msg_traceroute {
00174         uint16_t        icmp_id;                /* identifier */
00175         uint16_t        icmp_void;              /* unused */
00176         uint16_t        icmp_ohc;               /* outbound hop count */
00177         uint16_t        icmp_rhc;               /* return hop count */
00178         uint32_t        icmp_speed;             /* link speed, bytes/sec */
00179         uint32_t        icmp_mtu;               /* MTU in bytes */
00180 };
00181 
00182 /*
00183  * Domain name reply message data, RFC 1788
00184  */
00185 struct icmp_msg_dnsreply {
00186         uint16_t        icmp_id;                /* identifier */
00187         uint16_t        icmp_seq;               /* sequence number */
00188         uint32_t        icmp_ttl;               /* time-to-live */
00189         uint8_t         icmp_names __flexarr;   /* variable number of names */
00190 };
00191 
00192 /*
00193  * Generic identifier, sequence number data
00194  */
00195 struct icmp_msg_idseq {
00196         uint16_t        icmp_id;
00197         uint16_t        icmp_seq;
00198 };
00199 
00200 /*
00201  * ICMP message union
00202  */
00203 union icmp_msg {
00204         struct icmp_msg_echo       echo;        /* ICMP_ECHO{REPLY} */
00205         struct icmp_msg_quote      unreach;     /* ICMP_UNREACH */
00206         struct icmp_msg_needfrag   needfrag;    /* ICMP_UNREACH_NEEDFRAG */
00207         struct icmp_msg_quote      srcquench;   /* ICMP_SRCQUENCH */
00208         struct icmp_msg_quote      redirect;    /* ICMP_REDIRECT (set to 0) */
00209         uint32_t                   rtrsolicit;  /* ICMP_RTRSOLICIT */
00210         struct icmp_msg_rtradvert  rtradvert;   /* ICMP_RTRADVERT */
00211         struct icmp_msg_quote      timexceed;   /* ICMP_TIMEXCEED */
00212         struct icmp_msg_quote      paramprob;   /* ICMP_PARAMPROB */
00213         struct icmp_msg_tstamp     tstamp;      /* ICMP_TSTAMP{REPLY} */
00214         struct icmp_msg_idseq      info;        /* ICMP_INFO{REPLY} */
00215         struct icmp_msg_mask       mask;        /* ICMP_MASK{REPLY} */
00216         struct icmp_msg_traceroute traceroute;  /* ICMP_TRACEROUTE */
00217         struct icmp_msg_idseq      dns;         /* ICMP_DNS */
00218         struct icmp_msg_dnsreply   dnsreply;    /* ICMP_DNSREPLY */
00219 };
00220 
00221 #ifndef __GNUC__
00222 # pragma pack()
00223 #endif
00224 
00225 #define icmp_pack_hdr(hdr, type, code) do {                             \
00226         struct icmp_hdr *icmp_pack_p = (struct icmp_hdr *)(hdr);        \
00227         icmp_pack_p->icmp_type = type; icmp_pack_p->icmp_code = code;   \
00228 } while (0)
00229 
00230 #define icmp_pack_hdr_echo(hdr, type, code, id, seq, data, len) do {    \
00231         struct icmp_msg_echo *echo_pack_p = (struct icmp_msg_echo *)    \
00232                 ((uint8_t *)(hdr) + ICMP_HDR_LEN);                      \
00233         icmp_pack_hdr(hdr, type, code);                                 \
00234         echo_pack_p->icmp_id = htons(id);                               \
00235         echo_pack_p->icmp_seq = htons(seq);                             \
00236         memmove(echo_pack_p->icmp_data, data, len);                     \
00237 } while (0)
00238 
00239 #define icmp_pack_hdr_quote(hdr, type, code, word, pkt, len) do {       \
00240         struct icmp_msg_quote *quote_pack_p = (struct icmp_msg_quote *) \
00241                 ((uint8_t *)(hdr) + ICMP_HDR_LEN);                      \
00242         icmp_pack_hdr(hdr, type, code);                                 \
00243         quote_pack_p->icmp_void = htonl(word);                          \
00244         memmove(quote_pack_p->icmp_ip, pkt, len);                       \
00245 } while (0)
00246 
00247 #define icmp_pack_hdr_mask(hdr, type, code, id, seq, mask) do {         \
00248         struct icmp_msg_mask *mask_pack_p = (struct icmp_msg_mask *)    \
00249                 ((uint8_t *)(hdr) + ICMP_HDR_LEN);                      \
00250         icmp_pack_hdr(hdr, type, code);                                 \
00251         mask_pack_p->icmp_id = htons(id);                               \
00252         mask_pack_p->icmp_seq = htons(seq);                             \
00253         mask_pack_p->icmp_mask = htonl(mask);                           \
00254 } while (0)
00255 
00256 #define icmp_pack_hdr_needfrag(hdr, type, code, mtu, pkt, len) do {     \
00257         struct icmp_msg_needfrag *frag_pack_p =                         \
00258         (struct icmp_msg_needfrag *)((uint8_t *)(hdr) + ICMP_HDR_LEN);  \
00259         icmp_pack_hdr(hdr, type, code);                                 \
00260         frag_pack_p->icmp_void = 0;                                     \
00261         frag_pack_p->icmp_mtu = htons(mtu);                             \
00262         memmove(frag_pack_p->icmp_ip, pkt, len);                        \
00263 } while (0)
00264 
00265 #endif /* DNET_ICMP_H */

Generated on Sun May 14 14:51:10 2006 by  doxygen 1.4.2