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