xref: /freebsd/contrib/tcpdump/ipproto.c (revision a03411e84728e9b267056fd31c7d1d9d1dc1b01e)
1 /*
2  * Redistribution and use in source and binary forms, with or without
3  * modification, are permitted provided that: (1) source code
4  * distributions retain the above copyright notice and this paragraph
5  * in its entirety, and (2) distributions including binary code include
6  * the above copyright notice and this paragraph in its entirety in
7  * the documentation or other materials provided with the distribution.
8  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
9  * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
10  * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
11  * FOR A PARTICULAR PURPOSE.
12  *
13  * Original code by Hannes Gredler (hannes@gredler.at)
14  */
15 
16 #ifdef HAVE_CONFIG_H
17 #include <config.h>
18 #endif
19 
20 #include "netdissect-stdinc.h"
21 
22 #include "netdissect.h"
23 #include "ipproto.h"
24 
25 const struct tok ipproto_values[] = {
26     { IPPROTO_HOPOPTS, "Options" },
27     { IPPROTO_ICMP, "ICMP" },
28     { IPPROTO_IGMP, "IGMP" },
29     { IPPROTO_IPV4, "IPIP" },
30     { IPPROTO_TCP, "TCP" },
31     { IPPROTO_EGP, "EGP" },
32     { IPPROTO_PIGP, "IGRP" },
33     { IPPROTO_UDP, "UDP" },
34     { IPPROTO_DCCP, "DCCP" },
35     { IPPROTO_IPV6, "IPv6" },
36     { IPPROTO_ROUTING, "Routing" },
37     { IPPROTO_FRAGMENT, "Fragment" },
38     { IPPROTO_RSVP, "RSVP" },
39     { IPPROTO_GRE, "GRE" },
40     { IPPROTO_ESP, "ESP" },
41     { IPPROTO_AH, "AH" },
42     { IPPROTO_MOBILE, "Mobile IP" },
43     { IPPROTO_ICMPV6, "ICMPv6" },
44     { IPPROTO_MOBILITY_OLD, "Mobile IP (old)" },
45     { IPPROTO_EIGRP, "EIGRP" },
46     { IPPROTO_OSPF, "OSPF" },
47     { IPPROTO_PIM, "PIM" },
48     { IPPROTO_IPCOMP, "Compressed IP" },
49     { IPPROTO_VRRP, "VRRP" }, /* See also CARP. */
50     { IPPROTO_PGM, "PGM" },
51     { IPPROTO_SCTP, "SCTP" },
52     { IPPROTO_MOBILITY, "Mobility" },
53     { IPPROTO_PFSYNC, "pfsync" },
54     { IPPROTO_ETHERNET, "Ethernet" },
55     { 0, NULL }
56 };
57 
58 /*
59  * For completeness the number space in the array below comes from IANA:
60  * https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml
61  * However, the spelling tries to match that of /etc/protocols to achieve as
62  * much consistency as possible with the previously implemented behaviour,
63  * which was based on getprotobynumber (3).
64  */
65 static const char *netdb_protocol_names[256] = {
66 	"hopopt",            /* 0 (IPPROTO_HOPOPTS, IPv6 Hop-by-Hop Option) */
67 	"icmp",              /* 1 (IPPROTO_ICMP, Internet Control Message) */
68 	"igmp",              /* 2 (IPPROTO_IGMP, Internet Group Management) */
69 	"ggp",               /* 3 (Gateway-to-Gateway) */
70 	"ipencap",           /* 4 (IPPROTO_IPV4, IPv4 encapsulation) */
71 	"st",                /* 5 (Stream, ST datagram mode) */
72 	"tcp",               /* 6 (IPPROTO_TCP, Transmission Control) */
73 	"cbt",               /* 7 (CBT) */
74 	"egp",               /* 8 (IPPROTO_EGP, Exterior Gateway Protocol) */
75 	"igp",               /* 9 (IPPROTO_PIGP, "any private interior gateway
76 	                      *   (used by Cisco for their IGRP)")
77 	                      */
78 	"bbn-rcc-mon",       /* 10 (BBN RCC Monitoring) */
79 	"nvp-ii",            /* 11 (Network Voice Protocol) */
80 	"pup",               /* 12 (PARC universal packet protocol) */
81 	"argus",             /* 13 (ARGUS) */
82 	"emcon",             /* 14 (EMCON) */
83 	"xnet",              /* 15 (Cross Net Debugger) */
84 	"chaos",             /* 16 (Chaos) */
85 	"udp",               /* 17 (IPPROTO_UDP, User Datagram) */
86 	"mux",               /* 18 (Multiplexing) */
87 	"dcn-meas",          /* 19 (DCN Measurement Subsystems) */
88 	"hmp",               /* 20 (Host Monitoring) */
89 	"prm",               /* 21 (Packet Radio Measurement) */
90 	"xns-idp",           /* 22 (XEROX NS IDP) */
91 	"trunk-1",           /* 23 (Trunk-1) */
92 	"trunk-2",           /* 24 (Trunk-2) */
93 	"leaf-1",            /* 25 (Leaf-1) */
94 	"leaf-2",            /* 26 (Leaf-2) */
95 	"rdp",               /* 27 (Reliable Data Protocol) */
96 	"irtp",              /* 28 (Internet Reliable Transaction) */
97 	"iso-tp4",           /* 29 (ISO Transport Protocol Class 4) */
98 	"netblt",            /* 30 (Bulk Data Transfer Protocol) */
99 	"mfe-nsp",           /* 31 (MFE Network Services Protocol) */
100 	"merit-inp",         /* 32 (MERIT Internodal Protocol) */
101 	"dccp",              /* 33 (IPPROTO_DCCP, Datagram Congestion
102 	                      *    Control Protocol)
103 	                      */
104 	"3pc",               /* 34 (Third Party Connect Protocol) */
105 	"idpr",              /* 35 (Inter-Domain Policy Routing Protocol) */
106 	"xtp",               /* 36 (Xpress Transfer Protocol) */
107 	"ddp",               /* 37 (Datagram Delivery Protocol) */
108 	"idpr-cmtp",         /* 38 (IDPR Control Message Transport Proto) */
109 	"tp++",              /* 39 (TP++ Transport Protocol) */
110 	"il",                /* 40 (IL Transport Protocol) */
111 	"ipv6",              /* 41 (IPPROTO_IPV6, IPv6 encapsulation) */
112 	"sdrp",              /* 42 (Source Demand Routing Protocol) */
113 	"ipv6-route",        /* 43 (IPPROTO_ROUTING, Routing Header for IPv6) */
114 	"ipv6-frag",         /* 44 (IPPROTO_FRAGMENT, Fragment Header for
115 	                      *    IPv6)
116 	                      */
117 	"idrp",              /* 45 (Inter-Domain Routing Protocol) */
118 	"rsvp",              /* 46 (IPPROTO_RSVP, Reservation Protocol) */
119 	"gre",               /* 47 (IPPROTO_GRE, Generic Routing
120 	                      *    Encapsulation)
121 	                      */
122 	"dsr",               /* 48 (Dynamic Source Routing Protocol) */
123 	"bna",               /* 49 (BNA) */
124 	"esp",               /* 50 (IPPROTO_ESP, Encap Security Payload) */
125 	"ah",                /* 51 (IPPROTO_AH, Authentication Header) */
126 	"i-nlsp",            /* 52 (Integrated Net Layer Security TUBA) */
127 	"swipe",             /* 53 (IP with Encryption) */
128 	"narp",              /* 54 (NBMA Address Resolution Protocol) */
129 	"mobile",            /* 55 (IPPROTO_MOBILE, IP Mobility) */
130 	"tlsp",              /* 56 (Transport Layer Security Protocol using
131 	                      *    Kryptonet key management)
132 	                      */
133 	"skip",              /* 57 (SKIP) */
134 	"ipv6-icmp",         /* 58 (IPPROTO_ICMPV6, ICMP for IPv6) */
135 	"ipv6-nonxt",        /* 59 (IPPROTO_NONE, No Next Header for IPv6) */
136 	"ipv6-opts",         /* 60 (IPPROTO_DSTOPTS, Destination Options for
137 	                      *    IPv6)
138 	                      */
139 	NULL,                /* 61 (any host internal protocol) */
140 	"cftp",              /* 62 (IPPROTO_MOBILITY_OLD, CFTP, see the note
141 	                      *    in ipproto.h)
142 	                      */
143 	NULL,                /* 63 (any local network) */
144 	"sat-expak",         /* 64 (SATNET and Backroom EXPAK) */
145 	"kryptolan",         /* 65 (Kryptolan) */
146 	"rvd",               /* 66 (MIT Remote Virtual Disk Protocol) */
147 	"ippc",              /* 67 (Internet Pluribus Packet Core) */
148 	NULL,                /* 68 (any distributed file system) */
149 	"sat-mon",           /* 69 (SATNET Monitoring) */
150 	"visa",              /* 70 (VISA Protocol) */
151 	"ipcv",              /* 71 (Internet Packet Core Utility) */
152 	"cpnx",              /* 72 (Computer Protocol Network Executive) */
153 	"rspf",              /* 73 (Radio Shortest Path First, CPHB -- Computer
154 	                      *    Protocol Heart Beat -- in IANA)
155 	                      */
156 	"wsn",               /* 74 (Wang Span Network) */
157 	"pvp",               /* 75 (Packet Video Protocol) */
158 	"br-sat-mon",        /* 76 (Backroom SATNET Monitoring) */
159 	"sun-nd",            /* 77 (IPPROTO_ND, SUN ND PROTOCOL-Temporary) */
160 	"wb-mon",            /* 78 (WIDEBAND Monitoring) */
161 	"wb-expak",          /* 79 (WIDEBAND EXPAK) */
162 	"iso-ip",            /* 80 (ISO Internet Protocol) */
163 	"vmtp",              /* 81 (Versatile Message Transport) */
164 	"secure-vmtp",       /* 82 (Secure VMTP) */
165 	"vines",             /* 83 (VINES) */
166 	"ttp",               /* 84 (Transaction Transport Protocol, also IPTM --
167 	                      *    Internet Protocol Traffic Manager)
168 	                      */
169 	"nsfnet-igp",        /* 85 (NSFNET-IGP) */
170 	"dgp",               /* 86 (Dissimilar Gateway Protocol) */
171 	"tcf",               /* 87 (TCF) */
172 	"eigrp",             /* 88 (IPPROTO_EIGRP, Cisco EIGRP) */
173 	"ospf",              /* 89 (IPPROTO_OSPF, Open Shortest Path First
174 	                      *    IGP)
175 	                      */
176 	"sprite-rpc",        /* 90 (Sprite RPC Protocol) */
177 	"larp",              /* 91 (Locus Address Resolution Protocol) */
178 	"mtp",               /* 92 (Multicast Transport Protocol) */
179 	"ax.25",             /* 93 (AX.25 Frames) */
180 	"ipip",              /* 94 (IP-within-IP Encapsulation Protocol) */
181 	"micp",              /* 95 (Mobile Internetworking Control Pro.) */
182 	"scc-sp",            /* 96 (Semaphore Communications Sec. Pro.) */
183 	"etherip",           /* 97 (Ethernet-within-IP Encapsulation) */
184 	"encap",             /* 98 (Encapsulation Header) */
185 	NULL,                /* 99 (any private encryption scheme) */
186 	"gmtp",              /* 100 (GMTP) */
187 	"ifmp",              /* 101 (Ipsilon Flow Management Protocol) */
188 	"pnni",              /* 102 (PNNI over IP) */
189 	"pim",               /* 103 (IPPROTO_PIM, Protocol Independent
190 	                      *     Multicast)
191 	                      */
192 	"aris",              /* 104 (ARIS) */
193 	"scps",              /* 105 (SCPS) */
194 	"qnx",               /* 106 (QNX) */
195 	"a/n",               /* 107 (Active Networks) */
196 	"ipcomp",            /* 108 (IPPROTO_IPCOMP, IP Payload Compression
197 	                      *     Protocol)
198 	                      */
199 	"snp",               /* 109 (Sitara Networks Protocol) */
200 	"compaq-peer",       /* 110 (Compaq Peer Protocol) */
201 	"ipx-in-ip",         /* 111 (IPX in IP) */
202 	"vrrp",              /* 112 (IPPROTO_VRRP, Virtual Router Redundancy
203 	                      *     Protocol)
204 	                      */
205 	"pgm",               /* 113 (IPPROTO_PGM, PGM Reliable Transport
206 	                      *     Protocol)
207 	                      */
208 	NULL,                /* 114 (any 0-hop protocol) */
209 	"l2tp",              /* 115 (Layer Two Tunneling Protocol) */
210 	"ddx",               /* 116 (D-II Data Exchange (DDX)) */
211 	"iatp",              /* 117 (Interactive Agent Transfer Protocol) */
212 	"stp",               /* 118 (Schedule Transfer Protocol) */
213 	"srp",               /* 119 (SpectraLink Radio Protocol) */
214 	"uti",               /* 120 (UTI) */
215 	"smp",               /* 121 (Simple Message Protocol) */
216 	"sm",                /* 122 (Simple Multicast Protocol) */
217 	"ptp",               /* 123 (Performance Transparency Protocol) */
218 	"isis",              /* 124 (ISIS over IPv4) */
219 	"fire",              /* 125 (FIRE) */
220 	"crtp",              /* 126 (Combat Radio Transport Protocol) */
221 	"crudp",             /* 127 (Combat Radio User Datagram) */
222 	"sscopmce",          /* 128 (SSCOPMCE) */
223 	"iplt",              /* 129 (IPLT) */
224 	"sps",               /* 130 (Secure Packet Shield) */
225 	"pipe",              /* 131 (Private IP Encapsulation within IP) */
226 	"sctp",              /* 132 (IPPROTO_SCTP, Stream Control Transmission
227 	                      *     Protocol)
228 	                      */
229 	"fc",                /* 133 (Fibre Channel) */
230 	"rsvp-e2e-ignore",   /* 134 (RSVP-E2E-IGNORE) */
231 	"mobility-header",   /* 135 (IPPROTO_MOBILITY, Mobility Header) */
232 	"udplite",           /* 136 (UDPLite) */
233 	"mpls-in-ip",        /* 137 (MPLS-in-IP) */
234 	"manet",             /* 138 (MANET Protocols) */
235 	"hip",               /* 139 (Host Identity Protocol) */
236 	"shim6",             /* 140 (Shim6 Protocol) */
237 	"wesp",              /* 141 (Wrapped Encapsulating Security Payload) */
238 	"rohc",              /* 142 (Robust Header Compression) */
239 	NULL,                /* 143 (unassigned) */
240 	NULL,                /* 144 (unassigned) */
241 	NULL,                /* 145 (unassigned) */
242 	NULL,                /* 146 (unassigned) */
243 	NULL,                /* 147 (unassigned) */
244 	NULL,                /* 148 (unassigned) */
245 	NULL,                /* 149 (unassigned) */
246 	NULL,                /* 150 (unassigned) */
247 	NULL,                /* 151 (unassigned) */
248 	NULL,                /* 152 (unassigned) */
249 	NULL,                /* 153 (unassigned) */
250 	NULL,                /* 154 (unassigned) */
251 	NULL,                /* 155 (unassigned) */
252 	NULL,                /* 156 (unassigned) */
253 	NULL,                /* 157 (unassigned) */
254 	NULL,                /* 158 (unassigned) */
255 	NULL,                /* 159 (unassigned) */
256 	NULL,                /* 160 (unassigned) */
257 	NULL,                /* 161 (unassigned) */
258 	NULL,                /* 162 (unassigned) */
259 	NULL,                /* 163 (unassigned) */
260 	NULL,                /* 164 (unassigned) */
261 	NULL,                /* 165 (unassigned) */
262 	NULL,                /* 166 (unassigned) */
263 	NULL,                /* 167 (unassigned) */
264 	NULL,                /* 168 (unassigned) */
265 	NULL,                /* 169 (unassigned) */
266 	NULL,                /* 170 (unassigned) */
267 	NULL,                /* 171 (unassigned) */
268 	NULL,                /* 172 (unassigned) */
269 	NULL,                /* 173 (unassigned) */
270 	NULL,                /* 174 (unassigned) */
271 	NULL,                /* 175 (unassigned) */
272 	NULL,                /* 176 (unassigned) */
273 	NULL,                /* 177 (unassigned) */
274 	NULL,                /* 178 (unassigned) */
275 	NULL,                /* 179 (unassigned) */
276 	NULL,                /* 180 (unassigned) */
277 	NULL,                /* 181 (unassigned) */
278 	NULL,                /* 182 (unassigned) */
279 	NULL,                /* 183 (unassigned) */
280 	NULL,                /* 184 (unassigned) */
281 	NULL,                /* 185 (unassigned) */
282 	NULL,                /* 186 (unassigned) */
283 	NULL,                /* 187 (unassigned) */
284 	NULL,                /* 188 (unassigned) */
285 	NULL,                /* 189 (unassigned) */
286 	NULL,                /* 190 (unassigned) */
287 	NULL,                /* 191 (unassigned) */
288 	NULL,                /* 192 (unassigned) */
289 	NULL,                /* 193 (unassigned) */
290 	NULL,                /* 194 (unassigned) */
291 	NULL,                /* 195 (unassigned) */
292 	NULL,                /* 196 (unassigned) */
293 	NULL,                /* 197 (unassigned) */
294 	NULL,                /* 198 (unassigned) */
295 	NULL,                /* 199 (unassigned) */
296 	NULL,                /* 200 (unassigned) */
297 	NULL,                /* 201 (unassigned) */
298 	NULL,                /* 202 (unassigned) */
299 	NULL,                /* 203 (unassigned) */
300 	NULL,                /* 204 (unassigned) */
301 	NULL,                /* 205 (unassigned) */
302 	NULL,                /* 206 (unassigned) */
303 	NULL,                /* 207 (unassigned) */
304 	NULL,                /* 208 (unassigned) */
305 	NULL,                /* 209 (unassigned) */
306 	NULL,                /* 210 (unassigned) */
307 	NULL,                /* 211 (unassigned) */
308 	NULL,                /* 212 (unassigned) */
309 	NULL,                /* 213 (unassigned) */
310 	NULL,                /* 214 (unassigned) */
311 	NULL,                /* 215 (unassigned) */
312 	NULL,                /* 216 (unassigned) */
313 	NULL,                /* 217 (unassigned) */
314 	NULL,                /* 218 (unassigned) */
315 	NULL,                /* 219 (unassigned) */
316 	NULL,                /* 220 (unassigned) */
317 	NULL,                /* 221 (unassigned) */
318 	NULL,                /* 222 (unassigned) */
319 	NULL,                /* 223 (unassigned) */
320 	NULL,                /* 224 (unassigned) */
321 	NULL,                /* 225 (unassigned) */
322 	NULL,                /* 226 (unassigned) */
323 	NULL,                /* 227 (unassigned) */
324 	NULL,                /* 228 (unassigned) */
325 	NULL,                /* 229 (unassigned) */
326 	NULL,                /* 230 (unassigned) */
327 	NULL,                /* 231 (unassigned) */
328 	NULL,                /* 232 (unassigned) */
329 	NULL,                /* 233 (unassigned) */
330 	NULL,                /* 234 (unassigned) */
331 	NULL,                /* 235 (unassigned) */
332 	NULL,                /* 236 (unassigned) */
333 	NULL,                /* 237 (unassigned) */
334 	NULL,                /* 238 (unassigned) */
335 	NULL,                /* 239 (unassigned) */
336 	NULL,                /* 240 (unassigned) */
337 	NULL,                /* 241 (unassigned) */
338 	NULL,                /* 242 (unassigned) */
339 	NULL,                /* 243 (unassigned) */
340 	NULL,                /* 244 (unassigned) */
341 	NULL,                /* 245 (unassigned) */
342 	NULL,                /* 246 (unassigned) */
343 	NULL,                /* 247 (unassigned) */
344 	NULL,                /* 248 (unassigned) */
345 	NULL,                /* 249 (unassigned) */
346 	NULL,                /* 250 (unassigned) */
347 	NULL,                /* 251 (unassigned) */
348 	NULL,                /* 252 (unassigned) */
349 	"exptest-253",       /* 253 (Use for experimentation and testing,
350 	                      *     RFC 3692)
351 	                      */
352 	"exptest-254",       /* 254 (Use for experimentation and testing,
353 	                      *     RFC 3692)
354 	                      */
355 	"reserved",          /* 255 (reserved) */
356 };
357 
358 /* The function enforces the array index to be 8-bit. */
359 const char *
360 netdb_protoname (const uint8_t protoid)
361 {
362 	return netdb_protocol_names[protoid];
363 }
364