]> The Tcpdump Group git mirrors - tcpdump/blob - print-ip-demux.c
IPv4/IPv6 demux: ICMPv6 in IPv4 is invalid
[tcpdump] / print-ip-demux.c
1 /*
2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 */
21
22 /* \summary: IPv4/IPv6 payload printer */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include "netdissect-stdinc.h"
29
30 #include <string.h>
31
32 #include "netdissect.h"
33 #include "addrtoname.h"
34 #include "extract.h"
35
36 #include "ip.h"
37 #include "ipproto.h"
38
39 void
40 ip_demux_print(netdissect_options *ndo,
41 const u_char *bp,
42 u_int length, u_int ver, int fragmented, u_int ttl_hl,
43 uint8_t nh, const u_char *iph)
44 {
45 int advance;
46 const char *p_name;
47
48 advance = 0;
49
50 again:
51 switch (nh) {
52
53 case IPPROTO_AH:
54 if (!ND_TTEST_1(bp)) {
55 ndo->ndo_protocol = "ah";
56 nd_print_trunc(ndo);
57 break;
58 }
59 nh = GET_U_1(bp);
60 advance = ah_print(ndo, bp);
61 if (advance <= 0)
62 break;
63 bp += advance;
64 length -= advance;
65 goto again;
66
67 case IPPROTO_ESP:
68 {
69 esp_print(ndo, bp, length, iph, ver, fragmented, ttl_hl);
70 /*
71 * Either this has decrypted the payload and
72 * printed it, in which case there's nothing more
73 * to do, or it hasn't, in which case there's
74 * nothing more to do.
75 */
76 break;
77 }
78
79 case IPPROTO_IPCOMP:
80 {
81 ipcomp_print(ndo, bp);
82 /*
83 * Either this has decompressed the payload and
84 * printed it, in which case there's nothing more
85 * to do, or it hasn't, in which case there's
86 * nothing more to do.
87 */
88 break;
89 }
90
91 case IPPROTO_SCTP:
92 sctp_print(ndo, bp, iph, length);
93 break;
94
95 case IPPROTO_DCCP:
96 dccp_print(ndo, bp, iph, length);
97 break;
98
99 case IPPROTO_TCP:
100 tcp_print(ndo, bp, length, iph, fragmented);
101 break;
102
103 case IPPROTO_UDP:
104 udp_print(ndo, bp, length, iph, fragmented, ttl_hl);
105 break;
106
107 case IPPROTO_ICMP:
108 icmp_print(ndo, bp, length, iph, fragmented);
109 break;
110
111 case IPPROTO_ICMPV6:
112 if (ver == 6)
113 icmp6_print(ndo, bp, length, iph, fragmented);
114 else {
115 ND_PRINT("[%s requires IPv6]",
116 tok2str(ipproto_values,"unknown",nh));
117 nd_print_invalid(ndo);
118 }
119 break;
120
121 case IPPROTO_PIGP:
122 /*
123 * XXX - the current IANA protocol number assignments
124 * page lists 9 as "any private interior gateway
125 * (used by Cisco for their IGRP)" and 88 as
126 * "EIGRP" from Cisco.
127 *
128 * Recent BSD <netinet/in.h> headers define
129 * IP_PROTO_PIGP as 9 and IP_PROTO_IGRP as 88.
130 * We define IP_PROTO_PIGP as 9 and
131 * IP_PROTO_EIGRP as 88; those names better
132 * match was the current protocol number
133 * assignments say.
134 */
135 igrp_print(ndo, bp, length);
136 break;
137
138 case IPPROTO_EIGRP:
139 eigrp_print(ndo, bp, length);
140 break;
141
142 case IPPROTO_ND:
143 ND_PRINT(" nd %u", length);
144 break;
145
146 case IPPROTO_EGP:
147 egp_print(ndo, bp, length);
148 break;
149
150 case IPPROTO_OSPF:
151 if (ver == 6)
152 ospf6_print(ndo, bp, length);
153 else
154 ospf_print(ndo, bp, length, iph);
155 break;
156
157 case IPPROTO_IGMP:
158 igmp_print(ndo, bp, length);
159 break;
160
161 case IPPROTO_IPV4:
162 /* ipv4-in-ip encapsulation */
163 ip_print(ndo, bp, length);
164 break;
165
166 case IPPROTO_IPV6:
167 /* ip6-in-ip encapsulation */
168 ip6_print(ndo, bp, length);
169 break;
170
171 case IPPROTO_RSVP:
172 rsvp_print(ndo, bp, length);
173 break;
174
175 case IPPROTO_GRE:
176 gre_print(ndo, bp, length);
177 break;
178
179 case IPPROTO_MOBILE:
180 mobile_print(ndo, bp, length);
181 break;
182
183 case IPPROTO_PIM:
184 pim_print(ndo, bp, length, iph);
185 break;
186
187 case IPPROTO_VRRP:
188 if (ndo->ndo_packettype == PT_CARP) {
189 carp_print(ndo, bp, length, ttl_hl);
190 } else {
191 vrrp_print(ndo, bp, length, iph, ttl_hl);
192 }
193 break;
194
195 case IPPROTO_PGM:
196 pgm_print(ndo, bp, length, iph);
197 break;
198
199 case IPPROTO_NONE:
200 ND_PRINT("no next header");
201 break;
202
203 default:
204 if (ndo->ndo_nflag==0 && (p_name = netdb_protoname(nh)) != NULL)
205 ND_PRINT(" %s", p_name);
206 else
207 ND_PRINT(" ip-proto-%u", nh);
208 ND_PRINT(" %u", length);
209 break;
210 }
211 }