ipproto.c 16 KB

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