print-ppp.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876
  1. /*
  2. * Copyright (c) 1990, 1991, 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. * Extensively modified by Motonori Shindo (mshindo@mshindo.net) for more
  22. * complete PPP support.
  23. */
  24. /* \summary: Point to Point Protocol (PPP) printer */
  25. /*
  26. * TODO:
  27. * o resolve XXX as much as possible
  28. * o MP support
  29. * o BAP support
  30. */
  31. #ifdef HAVE_CONFIG_H
  32. #include "config.h"
  33. #endif
  34. #include <netdissect-stdinc.h>
  35. #ifdef __bsdi__
  36. #include <net/slcompress.h>
  37. #include <net/if_ppp.h>
  38. #endif
  39. #include <stdlib.h>
  40. #include "netdissect.h"
  41. #include "extract.h"
  42. #include "addrtoname.h"
  43. #include "ppp.h"
  44. #include "chdlc.h"
  45. #include "ethertype.h"
  46. #include "oui.h"
  47. /*
  48. * The following constatns are defined by IANA. Please refer to
  49. * http://www.isi.edu/in-notes/iana/assignments/ppp-numbers
  50. * for the up-to-date information.
  51. */
  52. /* Protocol Codes defined in ppp.h */
  53. static const struct tok ppptype2str[] = {
  54. { PPP_IP, "IP" },
  55. { PPP_OSI, "OSI" },
  56. { PPP_NS, "NS" },
  57. { PPP_DECNET, "DECNET" },
  58. { PPP_APPLE, "APPLE" },
  59. { PPP_IPX, "IPX" },
  60. { PPP_VJC, "VJC IP" },
  61. { PPP_VJNC, "VJNC IP" },
  62. { PPP_BRPDU, "BRPDU" },
  63. { PPP_STII, "STII" },
  64. { PPP_VINES, "VINES" },
  65. { PPP_MPLS_UCAST, "MPLS" },
  66. { PPP_MPLS_MCAST, "MPLS" },
  67. { PPP_COMP, "Compressed"},
  68. { PPP_ML, "MLPPP"},
  69. { PPP_IPV6, "IP6"},
  70. { PPP_HELLO, "HELLO" },
  71. { PPP_LUXCOM, "LUXCOM" },
  72. { PPP_SNS, "SNS" },
  73. { PPP_IPCP, "IPCP" },
  74. { PPP_OSICP, "OSICP" },
  75. { PPP_NSCP, "NSCP" },
  76. { PPP_DECNETCP, "DECNETCP" },
  77. { PPP_APPLECP, "APPLECP" },
  78. { PPP_IPXCP, "IPXCP" },
  79. { PPP_STIICP, "STIICP" },
  80. { PPP_VINESCP, "VINESCP" },
  81. { PPP_IPV6CP, "IP6CP" },
  82. { PPP_MPLSCP, "MPLSCP" },
  83. { PPP_LCP, "LCP" },
  84. { PPP_PAP, "PAP" },
  85. { PPP_LQM, "LQM" },
  86. { PPP_CHAP, "CHAP" },
  87. { PPP_EAP, "EAP" },
  88. { PPP_SPAP, "SPAP" },
  89. { PPP_SPAP_OLD, "Old-SPAP" },
  90. { PPP_BACP, "BACP" },
  91. { PPP_BAP, "BAP" },
  92. { PPP_MPCP, "MLPPP-CP" },
  93. { PPP_CCP, "CCP" },
  94. { 0, NULL }
  95. };
  96. /* Control Protocols (LCP/IPCP/CCP etc.) Codes defined in RFC 1661 */
  97. #define CPCODES_VEXT 0 /* Vendor-Specific (RFC2153) */
  98. #define CPCODES_CONF_REQ 1 /* Configure-Request */
  99. #define CPCODES_CONF_ACK 2 /* Configure-Ack */
  100. #define CPCODES_CONF_NAK 3 /* Configure-Nak */
  101. #define CPCODES_CONF_REJ 4 /* Configure-Reject */
  102. #define CPCODES_TERM_REQ 5 /* Terminate-Request */
  103. #define CPCODES_TERM_ACK 6 /* Terminate-Ack */
  104. #define CPCODES_CODE_REJ 7 /* Code-Reject */
  105. #define CPCODES_PROT_REJ 8 /* Protocol-Reject (LCP only) */
  106. #define CPCODES_ECHO_REQ 9 /* Echo-Request (LCP only) */
  107. #define CPCODES_ECHO_RPL 10 /* Echo-Reply (LCP only) */
  108. #define CPCODES_DISC_REQ 11 /* Discard-Request (LCP only) */
  109. #define CPCODES_ID 12 /* Identification (LCP only) RFC1570 */
  110. #define CPCODES_TIME_REM 13 /* Time-Remaining (LCP only) RFC1570 */
  111. #define CPCODES_RESET_REQ 14 /* Reset-Request (CCP only) RFC1962 */
  112. #define CPCODES_RESET_REP 15 /* Reset-Reply (CCP only) */
  113. static const struct tok cpcodes[] = {
  114. {CPCODES_VEXT, "Vendor-Extension"}, /* RFC2153 */
  115. {CPCODES_CONF_REQ, "Conf-Request"},
  116. {CPCODES_CONF_ACK, "Conf-Ack"},
  117. {CPCODES_CONF_NAK, "Conf-Nack"},
  118. {CPCODES_CONF_REJ, "Conf-Reject"},
  119. {CPCODES_TERM_REQ, "Term-Request"},
  120. {CPCODES_TERM_ACK, "Term-Ack"},
  121. {CPCODES_CODE_REJ, "Code-Reject"},
  122. {CPCODES_PROT_REJ, "Prot-Reject"},
  123. {CPCODES_ECHO_REQ, "Echo-Request"},
  124. {CPCODES_ECHO_RPL, "Echo-Reply"},
  125. {CPCODES_DISC_REQ, "Disc-Req"},
  126. {CPCODES_ID, "Ident"}, /* RFC1570 */
  127. {CPCODES_TIME_REM, "Time-Rem"}, /* RFC1570 */
  128. {CPCODES_RESET_REQ, "Reset-Req"}, /* RFC1962 */
  129. {CPCODES_RESET_REP, "Reset-Ack"}, /* RFC1962 */
  130. {0, NULL}
  131. };
  132. /* LCP Config Options */
  133. #define LCPOPT_VEXT 0
  134. #define LCPOPT_MRU 1
  135. #define LCPOPT_ACCM 2
  136. #define LCPOPT_AP 3
  137. #define LCPOPT_QP 4
  138. #define LCPOPT_MN 5
  139. #define LCPOPT_DEP6 6
  140. #define LCPOPT_PFC 7
  141. #define LCPOPT_ACFC 8
  142. #define LCPOPT_FCSALT 9
  143. #define LCPOPT_SDP 10
  144. #define LCPOPT_NUMMODE 11
  145. #define LCPOPT_DEP12 12
  146. #define LCPOPT_CBACK 13
  147. #define LCPOPT_DEP14 14
  148. #define LCPOPT_DEP15 15
  149. #define LCPOPT_DEP16 16
  150. #define LCPOPT_MLMRRU 17
  151. #define LCPOPT_MLSSNHF 18
  152. #define LCPOPT_MLED 19
  153. #define LCPOPT_PROP 20
  154. #define LCPOPT_DCEID 21
  155. #define LCPOPT_MPP 22
  156. #define LCPOPT_LD 23
  157. #define LCPOPT_LCPAOPT 24
  158. #define LCPOPT_COBS 25
  159. #define LCPOPT_PE 26
  160. #define LCPOPT_MLHF 27
  161. #define LCPOPT_I18N 28
  162. #define LCPOPT_SDLOS 29
  163. #define LCPOPT_PPPMUX 30
  164. #define LCPOPT_MIN LCPOPT_VEXT
  165. #define LCPOPT_MAX LCPOPT_PPPMUX
  166. static const char *lcpconfopts[] = {
  167. "Vend-Ext", /* (0) */
  168. "MRU", /* (1) */
  169. "ACCM", /* (2) */
  170. "Auth-Prot", /* (3) */
  171. "Qual-Prot", /* (4) */
  172. "Magic-Num", /* (5) */
  173. "deprecated(6)", /* used to be a Quality Protocol */
  174. "PFC", /* (7) */
  175. "ACFC", /* (8) */
  176. "FCS-Alt", /* (9) */
  177. "SDP", /* (10) */
  178. "Num-Mode", /* (11) */
  179. "deprecated(12)", /* used to be a Multi-Link-Procedure*/
  180. "Call-Back", /* (13) */
  181. "deprecated(14)", /* used to be a Connect-Time */
  182. "deprecated(15)", /* used to be a Compund-Frames */
  183. "deprecated(16)", /* used to be a Nominal-Data-Encap */
  184. "MRRU", /* (17) */
  185. "12-Bit seq #", /* (18) */
  186. "End-Disc", /* (19) */
  187. "Proprietary", /* (20) */
  188. "DCE-Id", /* (21) */
  189. "MP+", /* (22) */
  190. "Link-Disc", /* (23) */
  191. "LCP-Auth-Opt", /* (24) */
  192. "COBS", /* (25) */
  193. "Prefix-elision", /* (26) */
  194. "Multilink-header-Form",/* (27) */
  195. "I18N", /* (28) */
  196. "SDL-over-SONET/SDH", /* (29) */
  197. "PPP-Muxing", /* (30) */
  198. };
  199. /* ECP - to be supported */
  200. /* CCP Config Options */
  201. #define CCPOPT_OUI 0 /* RFC1962 */
  202. #define CCPOPT_PRED1 1 /* RFC1962 */
  203. #define CCPOPT_PRED2 2 /* RFC1962 */
  204. #define CCPOPT_PJUMP 3 /* RFC1962 */
  205. /* 4-15 unassigned */
  206. #define CCPOPT_HPPPC 16 /* RFC1962 */
  207. #define CCPOPT_STACLZS 17 /* RFC1974 */
  208. #define CCPOPT_MPPC 18 /* RFC2118 */
  209. #define CCPOPT_GFZA 19 /* RFC1962 */
  210. #define CCPOPT_V42BIS 20 /* RFC1962 */
  211. #define CCPOPT_BSDCOMP 21 /* RFC1977 */
  212. /* 22 unassigned */
  213. #define CCPOPT_LZSDCP 23 /* RFC1967 */
  214. #define CCPOPT_MVRCA 24 /* RFC1975 */
  215. #define CCPOPT_DEC 25 /* RFC1976 */
  216. #define CCPOPT_DEFLATE 26 /* RFC1979 */
  217. /* 27-254 unassigned */
  218. #define CCPOPT_RESV 255 /* RFC1962 */
  219. static const struct tok ccpconfopts_values[] = {
  220. { CCPOPT_OUI, "OUI" },
  221. { CCPOPT_PRED1, "Pred-1" },
  222. { CCPOPT_PRED2, "Pred-2" },
  223. { CCPOPT_PJUMP, "Puddle" },
  224. { CCPOPT_HPPPC, "HP-PPC" },
  225. { CCPOPT_STACLZS, "Stac-LZS" },
  226. { CCPOPT_MPPC, "MPPC" },
  227. { CCPOPT_GFZA, "Gand-FZA" },
  228. { CCPOPT_V42BIS, "V.42bis" },
  229. { CCPOPT_BSDCOMP, "BSD-Comp" },
  230. { CCPOPT_LZSDCP, "LZS-DCP" },
  231. { CCPOPT_MVRCA, "MVRCA" },
  232. { CCPOPT_DEC, "DEC" },
  233. { CCPOPT_DEFLATE, "Deflate" },
  234. { CCPOPT_RESV, "Reserved"},
  235. {0, NULL}
  236. };
  237. /* BACP Config Options */
  238. #define BACPOPT_FPEER 1 /* RFC2125 */
  239. static const struct tok bacconfopts_values[] = {
  240. { BACPOPT_FPEER, "Favored-Peer" },
  241. {0, NULL}
  242. };
  243. /* SDCP - to be supported */
  244. /* IPCP Config Options */
  245. #define IPCPOPT_2ADDR 1 /* RFC1172, RFC1332 (deprecated) */
  246. #define IPCPOPT_IPCOMP 2 /* RFC1332 */
  247. #define IPCPOPT_ADDR 3 /* RFC1332 */
  248. #define IPCPOPT_MOBILE4 4 /* RFC2290 */
  249. #define IPCPOPT_PRIDNS 129 /* RFC1877 */
  250. #define IPCPOPT_PRINBNS 130 /* RFC1877 */
  251. #define IPCPOPT_SECDNS 131 /* RFC1877 */
  252. #define IPCPOPT_SECNBNS 132 /* RFC1877 */
  253. static const struct tok ipcpopt_values[] = {
  254. { IPCPOPT_2ADDR, "IP-Addrs" },
  255. { IPCPOPT_IPCOMP, "IP-Comp" },
  256. { IPCPOPT_ADDR, "IP-Addr" },
  257. { IPCPOPT_MOBILE4, "Home-Addr" },
  258. { IPCPOPT_PRIDNS, "Pri-DNS" },
  259. { IPCPOPT_PRINBNS, "Pri-NBNS" },
  260. { IPCPOPT_SECDNS, "Sec-DNS" },
  261. { IPCPOPT_SECNBNS, "Sec-NBNS" },
  262. { 0, NULL }
  263. };
  264. #define IPCPOPT_IPCOMP_HDRCOMP 0x61 /* rfc3544 */
  265. #define IPCPOPT_IPCOMP_MINLEN 14
  266. static const struct tok ipcpopt_compproto_values[] = {
  267. { PPP_VJC, "VJ-Comp" },
  268. { IPCPOPT_IPCOMP_HDRCOMP, "IP Header Compression" },
  269. { 0, NULL }
  270. };
  271. static const struct tok ipcpopt_compproto_subopt_values[] = {
  272. { 1, "RTP-Compression" },
  273. { 2, "Enhanced RTP-Compression" },
  274. { 0, NULL }
  275. };
  276. /* IP6CP Config Options */
  277. #define IP6CP_IFID 1
  278. static const struct tok ip6cpopt_values[] = {
  279. { IP6CP_IFID, "Interface-ID" },
  280. { 0, NULL }
  281. };
  282. /* ATCP - to be supported */
  283. /* OSINLCP - to be supported */
  284. /* BVCP - to be supported */
  285. /* BCP - to be supported */
  286. /* IPXCP - to be supported */
  287. /* MPLSCP - to be supported */
  288. /* Auth Algorithms */
  289. /* 0-4 Reserved (RFC1994) */
  290. #define AUTHALG_CHAPMD5 5 /* RFC1994 */
  291. #define AUTHALG_MSCHAP1 128 /* RFC2433 */
  292. #define AUTHALG_MSCHAP2 129 /* RFC2795 */
  293. static const struct tok authalg_values[] = {
  294. { AUTHALG_CHAPMD5, "MD5" },
  295. { AUTHALG_MSCHAP1, "MS-CHAPv1" },
  296. { AUTHALG_MSCHAP2, "MS-CHAPv2" },
  297. { 0, NULL }
  298. };
  299. /* FCS Alternatives - to be supported */
  300. /* Multilink Endpoint Discriminator (RFC1717) */
  301. #define MEDCLASS_NULL 0 /* Null Class */
  302. #define MEDCLASS_LOCAL 1 /* Locally Assigned */
  303. #define MEDCLASS_IPV4 2 /* Internet Protocol (IPv4) */
  304. #define MEDCLASS_MAC 3 /* IEEE 802.1 global MAC address */
  305. #define MEDCLASS_MNB 4 /* PPP Magic Number Block */
  306. #define MEDCLASS_PSNDN 5 /* Public Switched Network Director Number */
  307. /* PPP LCP Callback */
  308. #define CALLBACK_AUTH 0 /* Location determined by user auth */
  309. #define CALLBACK_DSTR 1 /* Dialing string */
  310. #define CALLBACK_LID 2 /* Location identifier */
  311. #define CALLBACK_E164 3 /* E.164 number */
  312. #define CALLBACK_X500 4 /* X.500 distinguished name */
  313. #define CALLBACK_CBCP 6 /* Location is determined during CBCP nego */
  314. static const struct tok ppp_callback_values[] = {
  315. { CALLBACK_AUTH, "UserAuth" },
  316. { CALLBACK_DSTR, "DialString" },
  317. { CALLBACK_LID, "LocalID" },
  318. { CALLBACK_E164, "E.164" },
  319. { CALLBACK_X500, "X.500" },
  320. { CALLBACK_CBCP, "CBCP" },
  321. { 0, NULL }
  322. };
  323. /* CHAP */
  324. #define CHAP_CHAL 1
  325. #define CHAP_RESP 2
  326. #define CHAP_SUCC 3
  327. #define CHAP_FAIL 4
  328. static const struct tok chapcode_values[] = {
  329. { CHAP_CHAL, "Challenge" },
  330. { CHAP_RESP, "Response" },
  331. { CHAP_SUCC, "Success" },
  332. { CHAP_FAIL, "Fail" },
  333. { 0, NULL}
  334. };
  335. /* PAP */
  336. #define PAP_AREQ 1
  337. #define PAP_AACK 2
  338. #define PAP_ANAK 3
  339. static const struct tok papcode_values[] = {
  340. { PAP_AREQ, "Auth-Req" },
  341. { PAP_AACK, "Auth-ACK" },
  342. { PAP_ANAK, "Auth-NACK" },
  343. { 0, NULL }
  344. };
  345. /* BAP */
  346. #define BAP_CALLREQ 1
  347. #define BAP_CALLRES 2
  348. #define BAP_CBREQ 3
  349. #define BAP_CBRES 4
  350. #define BAP_LDQREQ 5
  351. #define BAP_LDQRES 6
  352. #define BAP_CSIND 7
  353. #define BAP_CSRES 8
  354. static int print_lcp_config_options(netdissect_options *, const u_char *p, int);
  355. static int print_ipcp_config_options(netdissect_options *, const u_char *p, int);
  356. static int print_ip6cp_config_options(netdissect_options *, const u_char *p, int);
  357. static int print_ccp_config_options(netdissect_options *, const u_char *p, int);
  358. static int print_bacp_config_options(netdissect_options *, const u_char *p, int);
  359. static void handle_ppp(netdissect_options *, u_int proto, const u_char *p, int length);
  360. /* generic Control Protocol (e.g. LCP, IPCP, CCP, etc.) handler */
  361. static void
  362. handle_ctrl_proto(netdissect_options *ndo,
  363. u_int proto, const u_char *pptr, int length)
  364. {
  365. const char *typestr;
  366. u_int code, len;
  367. int (*pfunc)(netdissect_options *, const u_char *, int);
  368. int x, j;
  369. const u_char *tptr;
  370. tptr=pptr;
  371. typestr = tok2str(ppptype2str, "unknown ctrl-proto (0x%04x)", proto);
  372. ND_PRINT((ndo, "%s, ", typestr));
  373. if (length < 4) /* FIXME weak boundary checking */
  374. goto trunc;
  375. ND_TCHECK2(*tptr, 2);
  376. code = *tptr++;
  377. ND_PRINT((ndo, "%s (0x%02x), id %u, length %u",
  378. tok2str(cpcodes, "Unknown Opcode",code),
  379. code,
  380. *tptr++, /* ID */
  381. length + 2));
  382. if (!ndo->ndo_vflag)
  383. return;
  384. if (length <= 4)
  385. return; /* there may be a NULL confreq etc. */
  386. ND_TCHECK2(*tptr, 2);
  387. len = EXTRACT_16BITS(tptr);
  388. tptr += 2;
  389. ND_PRINT((ndo, "\n\tencoded length %u (=Option(s) length %u)", len, len - 4));
  390. if (ndo->ndo_vflag > 1)
  391. print_unknown_data(ndo, pptr - 2, "\n\t", 6);
  392. switch (code) {
  393. case CPCODES_VEXT:
  394. if (length < 11)
  395. break;
  396. ND_TCHECK2(*tptr, 4);
  397. ND_PRINT((ndo, "\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr)));
  398. tptr += 4;
  399. ND_TCHECK2(*tptr, 3);
  400. ND_PRINT((ndo, " Vendor: %s (%u)",
  401. tok2str(oui_values,"Unknown",EXTRACT_24BITS(tptr)),
  402. EXTRACT_24BITS(tptr)));
  403. /* XXX: need to decode Kind and Value(s)? */
  404. break;
  405. case CPCODES_CONF_REQ:
  406. case CPCODES_CONF_ACK:
  407. case CPCODES_CONF_NAK:
  408. case CPCODES_CONF_REJ:
  409. x = len - 4; /* Code(1), Identifier(1) and Length(2) */
  410. do {
  411. switch (proto) {
  412. case PPP_LCP:
  413. pfunc = print_lcp_config_options;
  414. break;
  415. case PPP_IPCP:
  416. pfunc = print_ipcp_config_options;
  417. break;
  418. case PPP_IPV6CP:
  419. pfunc = print_ip6cp_config_options;
  420. break;
  421. case PPP_CCP:
  422. pfunc = print_ccp_config_options;
  423. break;
  424. case PPP_BACP:
  425. pfunc = print_bacp_config_options;
  426. break;
  427. default:
  428. /*
  429. * No print routine for the options for
  430. * this protocol.
  431. */
  432. pfunc = NULL;
  433. break;
  434. }
  435. if (pfunc == NULL) /* catch the above null pointer if unknown CP */
  436. break;
  437. if ((j = (*pfunc)(ndo, tptr, len)) == 0)
  438. break;
  439. x -= j;
  440. tptr += j;
  441. } while (x > 0);
  442. break;
  443. case CPCODES_TERM_REQ:
  444. case CPCODES_TERM_ACK:
  445. /* XXX: need to decode Data? */
  446. break;
  447. case CPCODES_CODE_REJ:
  448. /* XXX: need to decode Rejected-Packet? */
  449. break;
  450. case CPCODES_PROT_REJ:
  451. if (length < 6)
  452. break;
  453. ND_TCHECK2(*tptr, 2);
  454. ND_PRINT((ndo, "\n\t Rejected %s Protocol (0x%04x)",
  455. tok2str(ppptype2str,"unknown", EXTRACT_16BITS(tptr)),
  456. EXTRACT_16BITS(tptr)));
  457. /* XXX: need to decode Rejected-Information? - hexdump for now */
  458. if (len > 6) {
  459. ND_PRINT((ndo, "\n\t Rejected Packet"));
  460. print_unknown_data(ndo, tptr + 2, "\n\t ", len - 2);
  461. }
  462. break;
  463. case CPCODES_ECHO_REQ:
  464. case CPCODES_ECHO_RPL:
  465. case CPCODES_DISC_REQ:
  466. if (length < 8)
  467. break;
  468. ND_TCHECK2(*tptr, 4);
  469. ND_PRINT((ndo, "\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr)));
  470. /* XXX: need to decode Data? - hexdump for now */
  471. if (len > 8) {
  472. ND_PRINT((ndo, "\n\t -----trailing data-----"));
  473. ND_TCHECK2(tptr[4], len - 8);
  474. print_unknown_data(ndo, tptr + 4, "\n\t ", len - 8);
  475. }
  476. break;
  477. case CPCODES_ID:
  478. if (length < 8)
  479. break;
  480. ND_TCHECK2(*tptr, 4);
  481. ND_PRINT((ndo, "\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr)));
  482. /* RFC 1661 says this is intended to be human readable */
  483. if (len > 8) {
  484. ND_PRINT((ndo, "\n\t Message\n\t "));
  485. if (fn_printn(ndo, tptr + 4, len - 4, ndo->ndo_snapend))
  486. goto trunc;
  487. }
  488. break;
  489. case CPCODES_TIME_REM:
  490. if (length < 12)
  491. break;
  492. ND_TCHECK2(*tptr, 4);
  493. ND_PRINT((ndo, "\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr)));
  494. ND_TCHECK2(*(tptr + 4), 4);
  495. ND_PRINT((ndo, ", Seconds-Remaining %us", EXTRACT_32BITS(tptr + 4)));
  496. /* XXX: need to decode Message? */
  497. break;
  498. default:
  499. /* XXX this is dirty but we do not get the
  500. * original pointer passed to the begin
  501. * the PPP packet */
  502. if (ndo->ndo_vflag <= 1)
  503. print_unknown_data(ndo, pptr - 2, "\n\t ", length + 2);
  504. break;
  505. }
  506. return;
  507. trunc:
  508. ND_PRINT((ndo, "[|%s]", typestr));
  509. }
  510. /* LCP config options */
  511. static int
  512. print_lcp_config_options(netdissect_options *ndo,
  513. const u_char *p, int length)
  514. {
  515. int len, opt;
  516. if (length < 2)
  517. return 0;
  518. ND_TCHECK2(*p, 2);
  519. len = p[1];
  520. opt = p[0];
  521. if (length < len)
  522. return 0;
  523. if (len < 2) {
  524. if ((opt >= LCPOPT_MIN) && (opt <= LCPOPT_MAX))
  525. ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
  526. lcpconfopts[opt], opt, len));
  527. else
  528. ND_PRINT((ndo, "\n\tunknown LCP option 0x%02x", opt));
  529. return 0;
  530. }
  531. if ((opt >= LCPOPT_MIN) && (opt <= LCPOPT_MAX))
  532. ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u", lcpconfopts[opt], opt, len));
  533. else {
  534. ND_PRINT((ndo, "\n\tunknown LCP option 0x%02x", opt));
  535. return len;
  536. }
  537. switch (opt) {
  538. case LCPOPT_VEXT:
  539. if (len < 6) {
  540. ND_PRINT((ndo, " (length bogus, should be >= 6)"));
  541. return len;
  542. }
  543. ND_TCHECK_24BITS(p + 2);
  544. ND_PRINT((ndo, ": Vendor: %s (%u)",
  545. tok2str(oui_values,"Unknown",EXTRACT_24BITS(p+2)),
  546. EXTRACT_24BITS(p + 2)));
  547. #if 0
  548. ND_TCHECK(p[5]);
  549. ND_PRINT((ndo, ", kind: 0x%02x", p[5]));
  550. ND_PRINT((ndo, ", Value: 0x"));
  551. for (i = 0; i < len - 6; i++) {
  552. ND_TCHECK(p[6 + i]);
  553. ND_PRINT((ndo, "%02x", p[6 + i]));
  554. }
  555. #endif
  556. break;
  557. case LCPOPT_MRU:
  558. if (len != 4) {
  559. ND_PRINT((ndo, " (length bogus, should be = 4)"));
  560. return len;
  561. }
  562. ND_TCHECK_16BITS(p + 2);
  563. ND_PRINT((ndo, ": %u", EXTRACT_16BITS(p + 2)));
  564. break;
  565. case LCPOPT_ACCM:
  566. if (len != 6) {
  567. ND_PRINT((ndo, " (length bogus, should be = 6)"));
  568. return len;
  569. }
  570. ND_TCHECK_32BITS(p + 2);
  571. ND_PRINT((ndo, ": 0x%08x", EXTRACT_32BITS(p + 2)));
  572. break;
  573. case LCPOPT_AP:
  574. if (len < 4) {
  575. ND_PRINT((ndo, " (length bogus, should be >= 4)"));
  576. return len;
  577. }
  578. ND_TCHECK_16BITS(p + 2);
  579. ND_PRINT((ndo, ": %s", tok2str(ppptype2str, "Unknown Auth Proto (0x04x)", EXTRACT_16BITS(p + 2))));
  580. switch (EXTRACT_16BITS(p+2)) {
  581. case PPP_CHAP:
  582. ND_TCHECK(p[4]);
  583. ND_PRINT((ndo, ", %s", tok2str(authalg_values, "Unknown Auth Alg %u", p[4])));
  584. break;
  585. case PPP_PAP: /* fall through */
  586. case PPP_EAP:
  587. case PPP_SPAP:
  588. case PPP_SPAP_OLD:
  589. break;
  590. default:
  591. print_unknown_data(ndo, p, "\n\t", len);
  592. }
  593. break;
  594. case LCPOPT_QP:
  595. if (len < 4) {
  596. ND_PRINT((ndo, " (length bogus, should be >= 4)"));
  597. return 0;
  598. }
  599. ND_TCHECK_16BITS(p+2);
  600. if (EXTRACT_16BITS(p+2) == PPP_LQM)
  601. ND_PRINT((ndo, ": LQR"));
  602. else
  603. ND_PRINT((ndo, ": unknown"));
  604. break;
  605. case LCPOPT_MN:
  606. if (len != 6) {
  607. ND_PRINT((ndo, " (length bogus, should be = 6)"));
  608. return 0;
  609. }
  610. ND_TCHECK_32BITS(p + 2);
  611. ND_PRINT((ndo, ": 0x%08x", EXTRACT_32BITS(p + 2)));
  612. break;
  613. case LCPOPT_PFC:
  614. break;
  615. case LCPOPT_ACFC:
  616. break;
  617. case LCPOPT_LD:
  618. if (len != 4) {
  619. ND_PRINT((ndo, " (length bogus, should be = 4)"));
  620. return 0;
  621. }
  622. ND_TCHECK_16BITS(p + 2);
  623. ND_PRINT((ndo, ": 0x%04x", EXTRACT_16BITS(p + 2)));
  624. break;
  625. case LCPOPT_CBACK:
  626. if (len < 3) {
  627. ND_PRINT((ndo, " (length bogus, should be >= 3)"));
  628. return 0;
  629. }
  630. ND_PRINT((ndo, ": "));
  631. ND_TCHECK(p[2]);
  632. ND_PRINT((ndo, ": Callback Operation %s (%u)",
  633. tok2str(ppp_callback_values, "Unknown", p[2]),
  634. p[2]));
  635. break;
  636. case LCPOPT_MLMRRU:
  637. if (len != 4) {
  638. ND_PRINT((ndo, " (length bogus, should be = 4)"));
  639. return 0;
  640. }
  641. ND_TCHECK_16BITS(p + 2);
  642. ND_PRINT((ndo, ": %u", EXTRACT_16BITS(p + 2)));
  643. break;
  644. case LCPOPT_MLED:
  645. if (len < 3) {
  646. ND_PRINT((ndo, " (length bogus, should be >= 3)"));
  647. return 0;
  648. }
  649. ND_TCHECK(p[2]);
  650. switch (p[2]) { /* class */
  651. case MEDCLASS_NULL:
  652. ND_PRINT((ndo, ": Null"));
  653. break;
  654. case MEDCLASS_LOCAL:
  655. ND_PRINT((ndo, ": Local")); /* XXX */
  656. break;
  657. case MEDCLASS_IPV4:
  658. if (len != 7) {
  659. ND_PRINT((ndo, " (length bogus, should be = 7)"));
  660. return 0;
  661. }
  662. ND_TCHECK2(*(p + 3), 4);
  663. ND_PRINT((ndo, ": IPv4 %s", ipaddr_string(ndo, p + 3)));
  664. break;
  665. case MEDCLASS_MAC:
  666. if (len != 9) {
  667. ND_PRINT((ndo, " (length bogus, should be = 9)"));
  668. return 0;
  669. }
  670. ND_TCHECK2(*(p + 3), 6);
  671. ND_PRINT((ndo, ": MAC %s", etheraddr_string(ndo, p + 3)));
  672. break;
  673. case MEDCLASS_MNB:
  674. ND_PRINT((ndo, ": Magic-Num-Block")); /* XXX */
  675. break;
  676. case MEDCLASS_PSNDN:
  677. ND_PRINT((ndo, ": PSNDN")); /* XXX */
  678. break;
  679. default:
  680. ND_PRINT((ndo, ": Unknown class %u", p[2]));
  681. break;
  682. }
  683. break;
  684. /* XXX: to be supported */
  685. #if 0
  686. case LCPOPT_DEP6:
  687. case LCPOPT_FCSALT:
  688. case LCPOPT_SDP:
  689. case LCPOPT_NUMMODE:
  690. case LCPOPT_DEP12:
  691. case LCPOPT_DEP14:
  692. case LCPOPT_DEP15:
  693. case LCPOPT_DEP16:
  694. case LCPOPT_MLSSNHF:
  695. case LCPOPT_PROP:
  696. case LCPOPT_DCEID:
  697. case LCPOPT_MPP:
  698. case LCPOPT_LCPAOPT:
  699. case LCPOPT_COBS:
  700. case LCPOPT_PE:
  701. case LCPOPT_MLHF:
  702. case LCPOPT_I18N:
  703. case LCPOPT_SDLOS:
  704. case LCPOPT_PPPMUX:
  705. break;
  706. #endif
  707. default:
  708. /*
  709. * Unknown option; dump it as raw bytes now if we're
  710. * not going to do so below.
  711. */
  712. if (ndo->ndo_vflag < 2)
  713. print_unknown_data(ndo, &p[2], "\n\t ", len - 2);
  714. break;
  715. }
  716. if (ndo->ndo_vflag > 1)
  717. print_unknown_data(ndo, &p[2], "\n\t ", len - 2); /* exclude TLV header */
  718. return len;
  719. trunc:
  720. ND_PRINT((ndo, "[|lcp]"));
  721. return 0;
  722. }
  723. /* ML-PPP*/
  724. static const struct tok ppp_ml_flag_values[] = {
  725. { 0x80, "begin" },
  726. { 0x40, "end" },
  727. { 0, NULL }
  728. };
  729. static void
  730. handle_mlppp(netdissect_options *ndo,
  731. const u_char *p, int length)
  732. {
  733. if (!ndo->ndo_eflag)
  734. ND_PRINT((ndo, "MLPPP, "));
  735. if (length < 2) {
  736. ND_PRINT((ndo, "[|mlppp]"));
  737. return;
  738. }
  739. if (!ND_TTEST_16BITS(p)) {
  740. ND_PRINT((ndo, "[|mlppp]"));
  741. return;
  742. }
  743. ND_PRINT((ndo, "seq 0x%03x, Flags [%s], length %u",
  744. (EXTRACT_16BITS(p))&0x0fff, /* only support 12-Bit sequence space for now */
  745. bittok2str(ppp_ml_flag_values, "none", *p & 0xc0),
  746. length));
  747. }
  748. /* CHAP */
  749. static void
  750. handle_chap(netdissect_options *ndo,
  751. const u_char *p, int length)
  752. {
  753. u_int code, len;
  754. int val_size, name_size, msg_size;
  755. const u_char *p0;
  756. int i;
  757. p0 = p;
  758. if (length < 1) {
  759. ND_PRINT((ndo, "[|chap]"));
  760. return;
  761. } else if (length < 4) {
  762. ND_TCHECK(*p);
  763. ND_PRINT((ndo, "[|chap 0x%02x]", *p));
  764. return;
  765. }
  766. ND_TCHECK(*p);
  767. code = *p;
  768. ND_PRINT((ndo, "CHAP, %s (0x%02x)",
  769. tok2str(chapcode_values,"unknown",code),
  770. code));
  771. p++;
  772. ND_TCHECK(*p);
  773. ND_PRINT((ndo, ", id %u", *p)); /* ID */
  774. p++;
  775. ND_TCHECK2(*p, 2);
  776. len = EXTRACT_16BITS(p);
  777. p += 2;
  778. /*
  779. * Note that this is a generic CHAP decoding routine. Since we
  780. * don't know which flavor of CHAP (i.e. CHAP-MD5, MS-CHAPv1,
  781. * MS-CHAPv2) is used at this point, we can't decode packet
  782. * specifically to each algorithms. Instead, we simply decode
  783. * the GCD (Gratest Common Denominator) for all algorithms.
  784. */
  785. switch (code) {
  786. case CHAP_CHAL:
  787. case CHAP_RESP:
  788. if (length - (p - p0) < 1)
  789. return;
  790. ND_TCHECK(*p);
  791. val_size = *p; /* value size */
  792. p++;
  793. if (length - (p - p0) < val_size)
  794. return;
  795. ND_PRINT((ndo, ", Value "));
  796. for (i = 0; i < val_size; i++) {
  797. ND_TCHECK(*p);
  798. ND_PRINT((ndo, "%02x", *p++));
  799. }
  800. name_size = len - (p - p0);
  801. ND_PRINT((ndo, ", Name "));
  802. for (i = 0; i < name_size; i++) {
  803. ND_TCHECK(*p);
  804. safeputchar(ndo, *p++);
  805. }
  806. break;
  807. case CHAP_SUCC:
  808. case CHAP_FAIL:
  809. msg_size = len - (p - p0);
  810. ND_PRINT((ndo, ", Msg "));
  811. for (i = 0; i< msg_size; i++) {
  812. ND_TCHECK(*p);
  813. safeputchar(ndo, *p++);
  814. }
  815. break;
  816. }
  817. return;
  818. trunc:
  819. ND_PRINT((ndo, "[|chap]"));
  820. }
  821. /* PAP (see RFC 1334) */
  822. static void
  823. handle_pap(netdissect_options *ndo,
  824. const u_char *p, int length)
  825. {
  826. u_int code, len;
  827. int peerid_len, passwd_len, msg_len;
  828. const u_char *p0;
  829. int i;
  830. p0 = p;
  831. if (length < 1) {
  832. ND_PRINT((ndo, "[|pap]"));
  833. return;
  834. } else if (length < 4) {
  835. ND_TCHECK(*p);
  836. ND_PRINT((ndo, "[|pap 0x%02x]", *p));
  837. return;
  838. }
  839. ND_TCHECK(*p);
  840. code = *p;
  841. ND_PRINT((ndo, "PAP, %s (0x%02x)",
  842. tok2str(papcode_values, "unknown", code),
  843. code));
  844. p++;
  845. ND_TCHECK(*p);
  846. ND_PRINT((ndo, ", id %u", *p)); /* ID */
  847. p++;
  848. ND_TCHECK2(*p, 2);
  849. len = EXTRACT_16BITS(p);
  850. p += 2;
  851. if ((int)len > length) {
  852. ND_PRINT((ndo, ", length %u > packet size", len));
  853. return;
  854. }
  855. length = len;
  856. if (length < (p - p0)) {
  857. ND_PRINT((ndo, ", length %u < PAP header length", length));
  858. return;
  859. }
  860. switch (code) {
  861. case PAP_AREQ:
  862. /* A valid Authenticate-Request is 6 or more octets long. */
  863. if (len < 6)
  864. goto trunc;
  865. if (length - (p - p0) < 1)
  866. return;
  867. ND_TCHECK(*p);
  868. peerid_len = *p; /* Peer-ID Length */
  869. p++;
  870. if (length - (p - p0) < peerid_len)
  871. return;
  872. ND_PRINT((ndo, ", Peer "));
  873. for (i = 0; i < peerid_len; i++) {
  874. ND_TCHECK(*p);
  875. safeputchar(ndo, *p++);
  876. }
  877. if (length - (p - p0) < 1)
  878. return;
  879. ND_TCHECK(*p);
  880. passwd_len = *p; /* Password Length */
  881. p++;
  882. if (length - (p - p0) < passwd_len)
  883. return;
  884. ND_PRINT((ndo, ", Name "));
  885. for (i = 0; i < passwd_len; i++) {
  886. ND_TCHECK(*p);
  887. safeputchar(ndo, *p++);
  888. }
  889. break;
  890. case PAP_AACK:
  891. case PAP_ANAK:
  892. /* Although some implementations ignore truncation at
  893. * this point and at least one generates a truncated
  894. * packet, RFC 1334 section 2.2.2 clearly states that
  895. * both AACK and ANAK are at least 5 bytes long.
  896. */
  897. if (len < 5)
  898. goto trunc;
  899. if (length - (p - p0) < 1)
  900. return;
  901. ND_TCHECK(*p);
  902. msg_len = *p; /* Msg-Length */
  903. p++;
  904. if (length - (p - p0) < msg_len)
  905. return;
  906. ND_PRINT((ndo, ", Msg "));
  907. for (i = 0; i< msg_len; i++) {
  908. ND_TCHECK(*p);
  909. safeputchar(ndo, *p++);
  910. }
  911. break;
  912. }
  913. return;
  914. trunc:
  915. ND_PRINT((ndo, "[|pap]"));
  916. }
  917. /* BAP */
  918. static void
  919. handle_bap(netdissect_options *ndo _U_,
  920. const u_char *p _U_, int length _U_)
  921. {
  922. /* XXX: to be supported!! */
  923. }
  924. /* IPCP config options */
  925. static int
  926. print_ipcp_config_options(netdissect_options *ndo,
  927. const u_char *p, int length)
  928. {
  929. int len, opt;
  930. u_int compproto, ipcomp_subopttotallen, ipcomp_subopt, ipcomp_suboptlen;
  931. if (length < 2)
  932. return 0;
  933. ND_TCHECK2(*p, 2);
  934. len = p[1];
  935. opt = p[0];
  936. if (length < len)
  937. return 0;
  938. if (len < 2) {
  939. ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
  940. tok2str(ipcpopt_values,"unknown",opt),
  941. opt,
  942. len));
  943. return 0;
  944. }
  945. ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u",
  946. tok2str(ipcpopt_values,"unknown",opt),
  947. opt,
  948. len));
  949. switch (opt) {
  950. case IPCPOPT_2ADDR: /* deprecated */
  951. if (len != 10) {
  952. ND_PRINT((ndo, " (length bogus, should be = 10)"));
  953. return len;
  954. }
  955. ND_TCHECK2(*(p + 6), 4);
  956. ND_PRINT((ndo, ": src %s, dst %s",
  957. ipaddr_string(ndo, p + 2),
  958. ipaddr_string(ndo, p + 6)));
  959. break;
  960. case IPCPOPT_IPCOMP:
  961. if (len < 4) {
  962. ND_PRINT((ndo, " (length bogus, should be >= 4)"));
  963. return 0;
  964. }
  965. ND_TCHECK_16BITS(p+2);
  966. compproto = EXTRACT_16BITS(p+2);
  967. ND_PRINT((ndo, ": %s (0x%02x):",
  968. tok2str(ipcpopt_compproto_values, "Unknown", compproto),
  969. compproto));
  970. switch (compproto) {
  971. case PPP_VJC:
  972. /* XXX: VJ-Comp parameters should be decoded */
  973. break;
  974. case IPCPOPT_IPCOMP_HDRCOMP:
  975. if (len < IPCPOPT_IPCOMP_MINLEN) {
  976. ND_PRINT((ndo, " (length bogus, should be >= %u)",
  977. IPCPOPT_IPCOMP_MINLEN));
  978. return 0;
  979. }
  980. ND_TCHECK2(*(p + 2), IPCPOPT_IPCOMP_MINLEN);
  981. ND_PRINT((ndo, "\n\t TCP Space %u, non-TCP Space %u" \
  982. ", maxPeriod %u, maxTime %u, maxHdr %u",
  983. EXTRACT_16BITS(p+4),
  984. EXTRACT_16BITS(p+6),
  985. EXTRACT_16BITS(p+8),
  986. EXTRACT_16BITS(p+10),
  987. EXTRACT_16BITS(p+12)));
  988. /* suboptions present ? */
  989. if (len > IPCPOPT_IPCOMP_MINLEN) {
  990. ipcomp_subopttotallen = len - IPCPOPT_IPCOMP_MINLEN;
  991. p += IPCPOPT_IPCOMP_MINLEN;
  992. ND_PRINT((ndo, "\n\t Suboptions, length %u", ipcomp_subopttotallen));
  993. while (ipcomp_subopttotallen >= 2) {
  994. ND_TCHECK2(*p, 2);
  995. ipcomp_subopt = *p;
  996. ipcomp_suboptlen = *(p+1);
  997. /* sanity check */
  998. if (ipcomp_subopt == 0 ||
  999. ipcomp_suboptlen == 0 )
  1000. break;
  1001. /* XXX: just display the suboptions for now */
  1002. ND_PRINT((ndo, "\n\t\t%s Suboption #%u, length %u",
  1003. tok2str(ipcpopt_compproto_subopt_values,
  1004. "Unknown",
  1005. ipcomp_subopt),
  1006. ipcomp_subopt,
  1007. ipcomp_suboptlen));
  1008. ipcomp_subopttotallen -= ipcomp_suboptlen;
  1009. p += ipcomp_suboptlen;
  1010. }
  1011. }
  1012. break;
  1013. default:
  1014. break;
  1015. }
  1016. break;
  1017. case IPCPOPT_ADDR: /* those options share the same format - fall through */
  1018. case IPCPOPT_MOBILE4:
  1019. case IPCPOPT_PRIDNS:
  1020. case IPCPOPT_PRINBNS:
  1021. case IPCPOPT_SECDNS:
  1022. case IPCPOPT_SECNBNS:
  1023. if (len != 6) {
  1024. ND_PRINT((ndo, " (length bogus, should be = 6)"));
  1025. return 0;
  1026. }
  1027. ND_TCHECK2(*(p + 2), 4);
  1028. ND_PRINT((ndo, ": %s", ipaddr_string(ndo, p + 2)));
  1029. break;
  1030. default:
  1031. /*
  1032. * Unknown option; dump it as raw bytes now if we're
  1033. * not going to do so below.
  1034. */
  1035. if (ndo->ndo_vflag < 2)
  1036. print_unknown_data(ndo, &p[2], "\n\t ", len - 2);
  1037. break;
  1038. }
  1039. if (ndo->ndo_vflag > 1)
  1040. print_unknown_data(ndo, &p[2], "\n\t ", len - 2); /* exclude TLV header */
  1041. return len;
  1042. trunc:
  1043. ND_PRINT((ndo, "[|ipcp]"));
  1044. return 0;
  1045. }
  1046. /* IP6CP config options */
  1047. static int
  1048. print_ip6cp_config_options(netdissect_options *ndo,
  1049. const u_char *p, int length)
  1050. {
  1051. int len, opt;
  1052. if (length < 2)
  1053. return 0;
  1054. ND_TCHECK2(*p, 2);
  1055. len = p[1];
  1056. opt = p[0];
  1057. if (length < len)
  1058. return 0;
  1059. if (len < 2) {
  1060. ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
  1061. tok2str(ip6cpopt_values,"unknown",opt),
  1062. opt,
  1063. len));
  1064. return 0;
  1065. }
  1066. ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u",
  1067. tok2str(ip6cpopt_values,"unknown",opt),
  1068. opt,
  1069. len));
  1070. switch (opt) {
  1071. case IP6CP_IFID:
  1072. if (len != 10) {
  1073. ND_PRINT((ndo, " (length bogus, should be = 10)"));
  1074. return len;
  1075. }
  1076. ND_TCHECK2(*(p + 2), 8);
  1077. ND_PRINT((ndo, ": %04x:%04x:%04x:%04x",
  1078. EXTRACT_16BITS(p + 2),
  1079. EXTRACT_16BITS(p + 4),
  1080. EXTRACT_16BITS(p + 6),
  1081. EXTRACT_16BITS(p + 8)));
  1082. break;
  1083. default:
  1084. /*
  1085. * Unknown option; dump it as raw bytes now if we're
  1086. * not going to do so below.
  1087. */
  1088. if (ndo->ndo_vflag < 2)
  1089. print_unknown_data(ndo, &p[2], "\n\t ", len - 2);
  1090. break;
  1091. }
  1092. if (ndo->ndo_vflag > 1)
  1093. print_unknown_data(ndo, &p[2], "\n\t ", len - 2); /* exclude TLV header */
  1094. return len;
  1095. trunc:
  1096. ND_PRINT((ndo, "[|ip6cp]"));
  1097. return 0;
  1098. }
  1099. /* CCP config options */
  1100. static int
  1101. print_ccp_config_options(netdissect_options *ndo,
  1102. const u_char *p, int length)
  1103. {
  1104. int len, opt;
  1105. if (length < 2)
  1106. return 0;
  1107. ND_TCHECK2(*p, 2);
  1108. len = p[1];
  1109. opt = p[0];
  1110. if (length < len)
  1111. return 0;
  1112. if (len < 2) {
  1113. ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
  1114. tok2str(ccpconfopts_values, "Unknown", opt),
  1115. opt,
  1116. len));
  1117. return 0;
  1118. }
  1119. ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u",
  1120. tok2str(ccpconfopts_values, "Unknown", opt),
  1121. opt,
  1122. len));
  1123. switch (opt) {
  1124. case CCPOPT_BSDCOMP:
  1125. if (len < 3) {
  1126. ND_PRINT((ndo, " (length bogus, should be >= 3)"));
  1127. return len;
  1128. }
  1129. ND_TCHECK(p[2]);
  1130. ND_PRINT((ndo, ": Version: %u, Dictionary Bits: %u",
  1131. p[2] >> 5, p[2] & 0x1f));
  1132. break;
  1133. case CCPOPT_MVRCA:
  1134. if (len < 4) {
  1135. ND_PRINT((ndo, " (length bogus, should be >= 4)"));
  1136. return len;
  1137. }
  1138. ND_TCHECK(p[3]);
  1139. ND_PRINT((ndo, ": Features: %u, PxP: %s, History: %u, #CTX-ID: %u",
  1140. (p[2] & 0xc0) >> 6,
  1141. (p[2] & 0x20) ? "Enabled" : "Disabled",
  1142. p[2] & 0x1f, p[3]));
  1143. break;
  1144. case CCPOPT_DEFLATE:
  1145. if (len < 4) {
  1146. ND_PRINT((ndo, " (length bogus, should be >= 4)"));
  1147. return len;
  1148. }
  1149. ND_TCHECK(p[3]);
  1150. ND_PRINT((ndo, ": Window: %uK, Method: %s (0x%x), MBZ: %u, CHK: %u",
  1151. (p[2] & 0xf0) >> 4,
  1152. ((p[2] & 0x0f) == 8) ? "zlib" : "unknown",
  1153. p[2] & 0x0f, (p[3] & 0xfc) >> 2, p[3] & 0x03));
  1154. break;
  1155. /* XXX: to be supported */
  1156. #if 0
  1157. case CCPOPT_OUI:
  1158. case CCPOPT_PRED1:
  1159. case CCPOPT_PRED2:
  1160. case CCPOPT_PJUMP:
  1161. case CCPOPT_HPPPC:
  1162. case CCPOPT_STACLZS:
  1163. case CCPOPT_MPPC:
  1164. case CCPOPT_GFZA:
  1165. case CCPOPT_V42BIS:
  1166. case CCPOPT_LZSDCP:
  1167. case CCPOPT_DEC:
  1168. case CCPOPT_RESV:
  1169. break;
  1170. #endif
  1171. default:
  1172. /*
  1173. * Unknown option; dump it as raw bytes now if we're
  1174. * not going to do so below.
  1175. */
  1176. if (ndo->ndo_vflag < 2)
  1177. print_unknown_data(ndo, &p[2], "\n\t ", len - 2);
  1178. break;
  1179. }
  1180. if (ndo->ndo_vflag > 1)
  1181. print_unknown_data(ndo, &p[2], "\n\t ", len - 2); /* exclude TLV header */
  1182. return len;
  1183. trunc:
  1184. ND_PRINT((ndo, "[|ccp]"));
  1185. return 0;
  1186. }
  1187. /* BACP config options */
  1188. static int
  1189. print_bacp_config_options(netdissect_options *ndo,
  1190. const u_char *p, int length)
  1191. {
  1192. int len, opt;
  1193. if (length < 2)
  1194. return 0;
  1195. ND_TCHECK2(*p, 2);
  1196. len = p[1];
  1197. opt = p[0];
  1198. if (length < len)
  1199. return 0;
  1200. if (len < 2) {
  1201. ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
  1202. tok2str(bacconfopts_values, "Unknown", opt),
  1203. opt,
  1204. len));
  1205. return 0;
  1206. }
  1207. ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u",
  1208. tok2str(bacconfopts_values, "Unknown", opt),
  1209. opt,
  1210. len));
  1211. switch (opt) {
  1212. case BACPOPT_FPEER:
  1213. if (len != 6) {
  1214. ND_PRINT((ndo, " (length bogus, should be = 6)"));
  1215. return len;
  1216. }
  1217. ND_TCHECK_32BITS(p + 2);
  1218. ND_PRINT((ndo, ": Magic-Num 0x%08x", EXTRACT_32BITS(p + 2)));
  1219. break;
  1220. default:
  1221. /*
  1222. * Unknown option; dump it as raw bytes now if we're
  1223. * not going to do so below.
  1224. */
  1225. if (ndo->ndo_vflag < 2)
  1226. print_unknown_data(ndo, &p[2], "\n\t ", len - 2);
  1227. break;
  1228. }
  1229. if (ndo->ndo_vflag > 1)
  1230. print_unknown_data(ndo, &p[2], "\n\t ", len - 2); /* exclude TLV header */
  1231. return len;
  1232. trunc:
  1233. ND_PRINT((ndo, "[|bacp]"));
  1234. return 0;
  1235. }
  1236. static void
  1237. ppp_hdlc(netdissect_options *ndo,
  1238. const u_char *p, int length)
  1239. {
  1240. u_char *b, *t, c;
  1241. const u_char *s;
  1242. int i, proto;
  1243. const void *se;
  1244. if (length <= 0)
  1245. return;
  1246. b = (u_char *)malloc(length);
  1247. if (b == NULL)
  1248. return;
  1249. /*
  1250. * Unescape all the data into a temporary, private, buffer.
  1251. * Do this so that we dont overwrite the original packet
  1252. * contents.
  1253. */
  1254. for (s = p, t = b, i = length; i > 0 && ND_TTEST(*s); i--) {
  1255. c = *s++;
  1256. if (c == 0x7d) {
  1257. if (i <= 1 || !ND_TTEST(*s))
  1258. break;
  1259. i--;
  1260. c = *s++ ^ 0x20;
  1261. }
  1262. *t++ = c;
  1263. }
  1264. se = ndo->ndo_snapend;
  1265. ndo->ndo_snapend = t;
  1266. length = t - b;
  1267. /* now lets guess about the payload codepoint format */
  1268. if (length < 1)
  1269. goto trunc;
  1270. proto = *b; /* start with a one-octet codepoint guess */
  1271. switch (proto) {
  1272. case PPP_IP:
  1273. ip_print(ndo, b + 1, length - 1);
  1274. goto cleanup;
  1275. case PPP_IPV6:
  1276. ip6_print(ndo, b + 1, length - 1);
  1277. goto cleanup;
  1278. default: /* no luck - try next guess */
  1279. break;
  1280. }
  1281. if (length < 2)
  1282. goto trunc;
  1283. proto = EXTRACT_16BITS(b); /* next guess - load two octets */
  1284. switch (proto) {
  1285. case (PPP_ADDRESS << 8 | PPP_CONTROL): /* looks like a PPP frame */
  1286. if (length < 4)
  1287. goto trunc;
  1288. proto = EXTRACT_16BITS(b+2); /* load the PPP proto-id */
  1289. handle_ppp(ndo, proto, b + 4, length - 4);
  1290. break;
  1291. default: /* last guess - proto must be a PPP proto-id */
  1292. handle_ppp(ndo, proto, b + 2, length - 2);
  1293. break;
  1294. }
  1295. cleanup:
  1296. ndo->ndo_snapend = se;
  1297. free(b);
  1298. return;
  1299. trunc:
  1300. ndo->ndo_snapend = se;
  1301. free(b);
  1302. ND_PRINT((ndo, "[|ppp]"));
  1303. }
  1304. /* PPP */
  1305. static void
  1306. handle_ppp(netdissect_options *ndo,
  1307. u_int proto, const u_char *p, int length)
  1308. {
  1309. if ((proto & 0xff00) == 0x7e00) { /* is this an escape code ? */
  1310. ppp_hdlc(ndo, p - 1, length);
  1311. return;
  1312. }
  1313. switch (proto) {
  1314. case PPP_LCP: /* fall through */
  1315. case PPP_IPCP:
  1316. case PPP_OSICP:
  1317. case PPP_MPLSCP:
  1318. case PPP_IPV6CP:
  1319. case PPP_CCP:
  1320. case PPP_BACP:
  1321. handle_ctrl_proto(ndo, proto, p, length);
  1322. break;
  1323. case PPP_ML:
  1324. handle_mlppp(ndo, p, length);
  1325. break;
  1326. case PPP_CHAP:
  1327. handle_chap(ndo, p, length);
  1328. break;
  1329. case PPP_PAP:
  1330. handle_pap(ndo, p, length);
  1331. break;
  1332. case PPP_BAP: /* XXX: not yet completed */
  1333. handle_bap(ndo, p, length);
  1334. break;
  1335. case ETHERTYPE_IP: /*XXX*/
  1336. case PPP_VJNC:
  1337. case PPP_IP:
  1338. ip_print(ndo, p, length);
  1339. break;
  1340. case ETHERTYPE_IPV6: /*XXX*/
  1341. case PPP_IPV6:
  1342. ip6_print(ndo, p, length);
  1343. break;
  1344. case ETHERTYPE_IPX: /*XXX*/
  1345. case PPP_IPX:
  1346. ipx_print(ndo, p, length);
  1347. break;
  1348. case PPP_OSI:
  1349. isoclns_print(ndo, p, length);
  1350. break;
  1351. case PPP_MPLS_UCAST:
  1352. case PPP_MPLS_MCAST:
  1353. mpls_print(ndo, p, length);
  1354. break;
  1355. case PPP_COMP:
  1356. ND_PRINT((ndo, "compressed PPP data"));
  1357. break;
  1358. default:
  1359. ND_PRINT((ndo, "%s ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", proto)));
  1360. print_unknown_data(ndo, p, "\n\t", length);
  1361. break;
  1362. }
  1363. }
  1364. /* Standard PPP printer */
  1365. u_int
  1366. ppp_print(netdissect_options *ndo,
  1367. register const u_char *p, u_int length)
  1368. {
  1369. u_int proto,ppp_header;
  1370. u_int olen = length; /* _o_riginal length */
  1371. u_int hdr_len = 0;
  1372. /*
  1373. * Here, we assume that p points to the Address and Control
  1374. * field (if they present).
  1375. */
  1376. if (length < 2)
  1377. goto trunc;
  1378. ND_TCHECK2(*p, 2);
  1379. ppp_header = EXTRACT_16BITS(p);
  1380. switch(ppp_header) {
  1381. case (PPP_WITHDIRECTION_IN << 8 | PPP_CONTROL):
  1382. if (ndo->ndo_eflag) ND_PRINT((ndo, "In "));
  1383. p += 2;
  1384. length -= 2;
  1385. hdr_len += 2;
  1386. break;
  1387. case (PPP_WITHDIRECTION_OUT << 8 | PPP_CONTROL):
  1388. if (ndo->ndo_eflag) ND_PRINT((ndo, "Out "));
  1389. p += 2;
  1390. length -= 2;
  1391. hdr_len += 2;
  1392. break;
  1393. case (PPP_ADDRESS << 8 | PPP_CONTROL):
  1394. p += 2; /* ACFC not used */
  1395. length -= 2;
  1396. hdr_len += 2;
  1397. break;
  1398. default:
  1399. break;
  1400. }
  1401. if (length < 2)
  1402. goto trunc;
  1403. ND_TCHECK(*p);
  1404. if (*p % 2) {
  1405. proto = *p; /* PFC is used */
  1406. p++;
  1407. length--;
  1408. hdr_len++;
  1409. } else {
  1410. ND_TCHECK2(*p, 2);
  1411. proto = EXTRACT_16BITS(p);
  1412. p += 2;
  1413. length -= 2;
  1414. hdr_len += 2;
  1415. }
  1416. if (ndo->ndo_eflag)
  1417. ND_PRINT((ndo, "%s (0x%04x), length %u: ",
  1418. tok2str(ppptype2str, "unknown", proto),
  1419. proto,
  1420. olen));
  1421. handle_ppp(ndo, proto, p, length);
  1422. return (hdr_len);
  1423. trunc:
  1424. ND_PRINT((ndo, "[|ppp]"));
  1425. return (0);
  1426. }
  1427. /* PPP I/F printer */
  1428. u_int
  1429. ppp_if_print(netdissect_options *ndo,
  1430. const struct pcap_pkthdr *h, register const u_char *p)
  1431. {
  1432. register u_int length = h->len;
  1433. register u_int caplen = h->caplen;
  1434. if (caplen < PPP_HDRLEN) {
  1435. ND_PRINT((ndo, "[|ppp]"));
  1436. return (caplen);
  1437. }
  1438. #if 0
  1439. /*
  1440. * XXX: seems to assume that there are 2 octets prepended to an
  1441. * actual PPP frame. The 1st octet looks like Input/Output flag
  1442. * while 2nd octet is unknown, at least to me
  1443. * (mshindo@mshindo.net).
  1444. *
  1445. * That was what the original tcpdump code did.
  1446. *
  1447. * FreeBSD's "if_ppp.c" *does* set the first octet to 1 for outbound
  1448. * packets and 0 for inbound packets - but only if the
  1449. * protocol field has the 0x8000 bit set (i.e., it's a network
  1450. * control protocol); it does so before running the packet through
  1451. * "bpf_filter" to see if it should be discarded, and to see
  1452. * if we should update the time we sent the most recent packet...
  1453. *
  1454. * ...but it puts the original address field back after doing
  1455. * so.
  1456. *
  1457. * NetBSD's "if_ppp.c" doesn't set the first octet in that fashion.
  1458. *
  1459. * I don't know if any PPP implementation handed up to a BPF
  1460. * device packets with the first octet being 1 for outbound and
  1461. * 0 for inbound packets, so I (guy@alum.mit.edu) don't know
  1462. * whether that ever needs to be checked or not.
  1463. *
  1464. * Note that NetBSD has a DLT_PPP_SERIAL, which it uses for PPP,
  1465. * and its tcpdump appears to assume that the frame always
  1466. * begins with an address field and a control field, and that
  1467. * the address field might be 0x0f or 0x8f, for Cisco
  1468. * point-to-point with HDLC framing as per section 4.3.1 of RFC
  1469. * 1547, as well as 0xff, for PPP in HDLC-like framing as per
  1470. * RFC 1662.
  1471. *
  1472. * (Is the Cisco framing in question what DLT_C_HDLC, in
  1473. * BSD/OS, is?)
  1474. */
  1475. if (ndo->ndo_eflag)
  1476. ND_PRINT((ndo, "%c %4d %02x ", p[0] ? 'O' : 'I', length, p[1]));
  1477. #endif
  1478. ppp_print(ndo, p, length);
  1479. return (0);
  1480. }
  1481. /*
  1482. * PPP I/F printer to use if we know that RFC 1662-style PPP in HDLC-like
  1483. * framing, or Cisco PPP with HDLC framing as per section 4.3.1 of RFC 1547,
  1484. * is being used (i.e., we don't check for PPP_ADDRESS and PPP_CONTROL,
  1485. * discard them *if* those are the first two octets, and parse the remaining
  1486. * packet as a PPP packet, as "ppp_print()" does).
  1487. *
  1488. * This handles, for example, DLT_PPP_SERIAL in NetBSD.
  1489. */
  1490. u_int
  1491. ppp_hdlc_if_print(netdissect_options *ndo,
  1492. const struct pcap_pkthdr *h, register const u_char *p)
  1493. {
  1494. register u_int length = h->len;
  1495. register u_int caplen = h->caplen;
  1496. u_int proto;
  1497. u_int hdrlen = 0;
  1498. if (caplen < 2) {
  1499. ND_PRINT((ndo, "[|ppp]"));
  1500. return (caplen);
  1501. }
  1502. switch (p[0]) {
  1503. case PPP_ADDRESS:
  1504. if (caplen < 4) {
  1505. ND_PRINT((ndo, "[|ppp]"));
  1506. return (caplen);
  1507. }
  1508. if (ndo->ndo_eflag)
  1509. ND_PRINT((ndo, "%02x %02x %d ", p[0], p[1], length));
  1510. p += 2;
  1511. length -= 2;
  1512. hdrlen += 2;
  1513. proto = EXTRACT_16BITS(p);
  1514. p += 2;
  1515. length -= 2;
  1516. hdrlen += 2;
  1517. ND_PRINT((ndo, "%s: ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", proto)));
  1518. handle_ppp(ndo, proto, p, length);
  1519. break;
  1520. case CHDLC_UNICAST:
  1521. case CHDLC_BCAST:
  1522. return (chdlc_if_print(ndo, h, p));
  1523. default:
  1524. if (caplen < 4) {
  1525. ND_PRINT((ndo, "[|ppp]"));
  1526. return (caplen);
  1527. }
  1528. if (ndo->ndo_eflag)
  1529. ND_PRINT((ndo, "%02x %02x %d ", p[0], p[1], length));
  1530. p += 2;
  1531. hdrlen += 2;
  1532. /*
  1533. * XXX - NetBSD's "ppp_netbsd_serial_if_print()" treats
  1534. * the next two octets as an Ethernet type; does that
  1535. * ever happen?
  1536. */
  1537. ND_PRINT((ndo, "unknown addr %02x; ctrl %02x", p[0], p[1]));
  1538. break;
  1539. }
  1540. return (hdrlen);
  1541. }
  1542. #define PPP_BSDI_HDRLEN 24
  1543. /* BSD/OS specific PPP printer */
  1544. u_int
  1545. ppp_bsdos_if_print(netdissect_options *ndo _U_,
  1546. const struct pcap_pkthdr *h _U_, register const u_char *p _U_)
  1547. {
  1548. register int hdrlength;
  1549. #ifdef __bsdi__
  1550. register u_int length = h->len;
  1551. register u_int caplen = h->caplen;
  1552. uint16_t ptype;
  1553. const u_char *q;
  1554. int i;
  1555. if (caplen < PPP_BSDI_HDRLEN) {
  1556. ND_PRINT((ndo, "[|ppp]"));
  1557. return (caplen)
  1558. }
  1559. hdrlength = 0;
  1560. #if 0
  1561. if (p[0] == PPP_ADDRESS && p[1] == PPP_CONTROL) {
  1562. if (ndo->ndo_eflag)
  1563. ND_PRINT((ndo, "%02x %02x ", p[0], p[1]));
  1564. p += 2;
  1565. hdrlength = 2;
  1566. }
  1567. if (ndo->ndo_eflag)
  1568. ND_PRINT((ndo, "%d ", length));
  1569. /* Retrieve the protocol type */
  1570. if (*p & 01) {
  1571. /* Compressed protocol field */
  1572. ptype = *p;
  1573. if (ndo->ndo_eflag)
  1574. ND_PRINT((ndo, "%02x ", ptype));
  1575. p++;
  1576. hdrlength += 1;
  1577. } else {
  1578. /* Un-compressed protocol field */
  1579. ptype = EXTRACT_16BITS(p);
  1580. if (ndo->ndo_eflag)
  1581. ND_PRINT((ndo, "%04x ", ptype));
  1582. p += 2;
  1583. hdrlength += 2;
  1584. }
  1585. #else
  1586. ptype = 0; /*XXX*/
  1587. if (ndo->ndo_eflag)
  1588. ND_PRINT((ndo, "%c ", p[SLC_DIR] ? 'O' : 'I'));
  1589. if (p[SLC_LLHL]) {
  1590. /* link level header */
  1591. struct ppp_header *ph;
  1592. q = p + SLC_BPFHDRLEN;
  1593. ph = (struct ppp_header *)q;
  1594. if (ph->phdr_addr == PPP_ADDRESS
  1595. && ph->phdr_ctl == PPP_CONTROL) {
  1596. if (ndo->ndo_eflag)
  1597. ND_PRINT((ndo, "%02x %02x ", q[0], q[1]));
  1598. ptype = EXTRACT_16BITS(&ph->phdr_type);
  1599. if (ndo->ndo_eflag && (ptype == PPP_VJC || ptype == PPP_VJNC)) {
  1600. ND_PRINT((ndo, "%s ", tok2str(ppptype2str,
  1601. "proto-#%d", ptype)));
  1602. }
  1603. } else {
  1604. if (ndo->ndo_eflag) {
  1605. ND_PRINT((ndo, "LLH=["));
  1606. for (i = 0; i < p[SLC_LLHL]; i++)
  1607. ND_PRINT((ndo, "%02x", q[i]));
  1608. ND_PRINT((ndo, "] "));
  1609. }
  1610. }
  1611. }
  1612. if (ndo->ndo_eflag)
  1613. ND_PRINT((ndo, "%d ", length));
  1614. if (p[SLC_CHL]) {
  1615. q = p + SLC_BPFHDRLEN + p[SLC_LLHL];
  1616. switch (ptype) {
  1617. case PPP_VJC:
  1618. ptype = vjc_print(ndo, q, ptype);
  1619. hdrlength = PPP_BSDI_HDRLEN;
  1620. p += hdrlength;
  1621. switch (ptype) {
  1622. case PPP_IP:
  1623. ip_print(ndo, p, length);
  1624. break;
  1625. case PPP_IPV6:
  1626. ip6_print(ndo, p, length);
  1627. break;
  1628. case PPP_MPLS_UCAST:
  1629. case PPP_MPLS_MCAST:
  1630. mpls_print(ndo, p, length);
  1631. break;
  1632. }
  1633. goto printx;
  1634. case PPP_VJNC:
  1635. ptype = vjc_print(ndo, q, ptype);
  1636. hdrlength = PPP_BSDI_HDRLEN;
  1637. p += hdrlength;
  1638. switch (ptype) {
  1639. case PPP_IP:
  1640. ip_print(ndo, p, length);
  1641. break;
  1642. case PPP_IPV6:
  1643. ip6_print(ndo, p, length);
  1644. break;
  1645. case PPP_MPLS_UCAST:
  1646. case PPP_MPLS_MCAST:
  1647. mpls_print(ndo, p, length);
  1648. break;
  1649. }
  1650. goto printx;
  1651. default:
  1652. if (ndo->ndo_eflag) {
  1653. ND_PRINT((ndo, "CH=["));
  1654. for (i = 0; i < p[SLC_LLHL]; i++)
  1655. ND_PRINT((ndo, "%02x", q[i]));
  1656. ND_PRINT((ndo, "] "));
  1657. }
  1658. break;
  1659. }
  1660. }
  1661. hdrlength = PPP_BSDI_HDRLEN;
  1662. #endif
  1663. length -= hdrlength;
  1664. p += hdrlength;
  1665. switch (ptype) {
  1666. case PPP_IP:
  1667. ip_print(p, length);
  1668. break;
  1669. case PPP_IPV6:
  1670. ip6_print(ndo, p, length);
  1671. break;
  1672. case PPP_MPLS_UCAST:
  1673. case PPP_MPLS_MCAST:
  1674. mpls_print(ndo, p, length);
  1675. break;
  1676. default:
  1677. ND_PRINT((ndo, "%s ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", ptype)));
  1678. }
  1679. printx:
  1680. #else /* __bsdi */
  1681. hdrlength = 0;
  1682. #endif /* __bsdi__ */
  1683. return (hdrlength);
  1684. }
  1685. /*
  1686. * Local Variables:
  1687. * c-style: whitesmith
  1688. * c-basic-offset: 8
  1689. * End:
  1690. */