print-pptp.c 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  1. /*
  2. * Copyright (c) 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. * PPTP support contributed by Motonori Shindo (mshindo@mshindo.net)
  22. */
  23. /* \summary: Point-to-Point Tunnelling Protocol (PPTP) printer */
  24. #ifdef HAVE_CONFIG_H
  25. #include "config.h"
  26. #endif
  27. #include <netdissect-stdinc.h>
  28. #include "netdissect.h"
  29. #include "extract.h"
  30. static const char tstr[] = " [|pptp]";
  31. #define PPTP_MSG_TYPE_CTRL 1 /* Control Message */
  32. #define PPTP_MSG_TYPE_MGMT 2 /* Management Message (currently not used */
  33. #define PPTP_MAGIC_COOKIE 0x1a2b3c4d /* for sanity check */
  34. #define PPTP_CTRL_MSG_TYPE_SCCRQ 1
  35. #define PPTP_CTRL_MSG_TYPE_SCCRP 2
  36. #define PPTP_CTRL_MSG_TYPE_StopCCRQ 3
  37. #define PPTP_CTRL_MSG_TYPE_StopCCRP 4
  38. #define PPTP_CTRL_MSG_TYPE_ECHORQ 5
  39. #define PPTP_CTRL_MSG_TYPE_ECHORP 6
  40. #define PPTP_CTRL_MSG_TYPE_OCRQ 7
  41. #define PPTP_CTRL_MSG_TYPE_OCRP 8
  42. #define PPTP_CTRL_MSG_TYPE_ICRQ 9
  43. #define PPTP_CTRL_MSG_TYPE_ICRP 10
  44. #define PPTP_CTRL_MSG_TYPE_ICCN 11
  45. #define PPTP_CTRL_MSG_TYPE_CCRQ 12
  46. #define PPTP_CTRL_MSG_TYPE_CDN 13
  47. #define PPTP_CTRL_MSG_TYPE_WEN 14
  48. #define PPTP_CTRL_MSG_TYPE_SLI 15
  49. #define PPTP_FRAMING_CAP_ASYNC_MASK 0x00000001 /* Aynchronous */
  50. #define PPTP_FRAMING_CAP_SYNC_MASK 0x00000002 /* Synchronous */
  51. #define PPTP_BEARER_CAP_ANALOG_MASK 0x00000001 /* Analog */
  52. #define PPTP_BEARER_CAP_DIGITAL_MASK 0x00000002 /* Digital */
  53. static const char *pptp_message_type_string[] = {
  54. "NOT_DEFINED", /* 0 Not defined in the RFC2637 */
  55. "SCCRQ", /* 1 Start-Control-Connection-Request */
  56. "SCCRP", /* 2 Start-Control-Connection-Reply */
  57. "StopCCRQ", /* 3 Stop-Control-Connection-Request */
  58. "StopCCRP", /* 4 Stop-Control-Connection-Reply */
  59. "ECHORQ", /* 5 Echo Request */
  60. "ECHORP", /* 6 Echo Reply */
  61. "OCRQ", /* 7 Outgoing-Call-Request */
  62. "OCRP", /* 8 Outgoing-Call-Reply */
  63. "ICRQ", /* 9 Incoming-Call-Request */
  64. "ICRP", /* 10 Incoming-Call-Reply */
  65. "ICCN", /* 11 Incoming-Call-Connected */
  66. "CCRQ", /* 12 Call-Clear-Request */
  67. "CDN", /* 13 Call-Disconnect-Notify */
  68. "WEN", /* 14 WAN-Error-Notify */
  69. "SLI" /* 15 Set-Link-Info */
  70. #define PPTP_MAX_MSGTYPE_INDEX 16
  71. };
  72. /* common for all PPTP control messages */
  73. struct pptp_hdr {
  74. uint16_t length;
  75. uint16_t msg_type;
  76. uint32_t magic_cookie;
  77. uint16_t ctrl_msg_type;
  78. uint16_t reserved0;
  79. };
  80. struct pptp_msg_sccrq {
  81. uint16_t proto_ver;
  82. uint16_t reserved1;
  83. uint32_t framing_cap;
  84. uint32_t bearer_cap;
  85. uint16_t max_channel;
  86. uint16_t firm_rev;
  87. u_char hostname[64];
  88. u_char vendor[64];
  89. };
  90. struct pptp_msg_sccrp {
  91. uint16_t proto_ver;
  92. uint8_t result_code;
  93. uint8_t err_code;
  94. uint32_t framing_cap;
  95. uint32_t bearer_cap;
  96. uint16_t max_channel;
  97. uint16_t firm_rev;
  98. u_char hostname[64];
  99. u_char vendor[64];
  100. };
  101. struct pptp_msg_stopccrq {
  102. uint8_t reason;
  103. uint8_t reserved1;
  104. uint16_t reserved2;
  105. };
  106. struct pptp_msg_stopccrp {
  107. uint8_t result_code;
  108. uint8_t err_code;
  109. uint16_t reserved1;
  110. };
  111. struct pptp_msg_echorq {
  112. uint32_t id;
  113. };
  114. struct pptp_msg_echorp {
  115. uint32_t id;
  116. uint8_t result_code;
  117. uint8_t err_code;
  118. uint16_t reserved1;
  119. };
  120. struct pptp_msg_ocrq {
  121. uint16_t call_id;
  122. uint16_t call_ser;
  123. uint32_t min_bps;
  124. uint32_t max_bps;
  125. uint32_t bearer_type;
  126. uint32_t framing_type;
  127. uint16_t recv_winsiz;
  128. uint16_t pkt_proc_delay;
  129. uint16_t phone_no_len;
  130. uint16_t reserved1;
  131. u_char phone_no[64];
  132. u_char subaddr[64];
  133. };
  134. struct pptp_msg_ocrp {
  135. uint16_t call_id;
  136. uint16_t peer_call_id;
  137. uint8_t result_code;
  138. uint8_t err_code;
  139. uint16_t cause_code;
  140. uint32_t conn_speed;
  141. uint16_t recv_winsiz;
  142. uint16_t pkt_proc_delay;
  143. uint32_t phy_chan_id;
  144. };
  145. struct pptp_msg_icrq {
  146. uint16_t call_id;
  147. uint16_t call_ser;
  148. uint32_t bearer_type;
  149. uint32_t phy_chan_id;
  150. uint16_t dialed_no_len;
  151. uint16_t dialing_no_len;
  152. u_char dialed_no[64]; /* DNIS */
  153. u_char dialing_no[64]; /* CLID */
  154. u_char subaddr[64];
  155. };
  156. struct pptp_msg_icrp {
  157. uint16_t call_id;
  158. uint16_t peer_call_id;
  159. uint8_t result_code;
  160. uint8_t err_code;
  161. uint16_t recv_winsiz;
  162. uint16_t pkt_proc_delay;
  163. uint16_t reserved1;
  164. };
  165. struct pptp_msg_iccn {
  166. uint16_t peer_call_id;
  167. uint16_t reserved1;
  168. uint32_t conn_speed;
  169. uint16_t recv_winsiz;
  170. uint16_t pkt_proc_delay;
  171. uint32_t framing_type;
  172. };
  173. struct pptp_msg_ccrq {
  174. uint16_t call_id;
  175. uint16_t reserved1;
  176. };
  177. struct pptp_msg_cdn {
  178. uint16_t call_id;
  179. uint8_t result_code;
  180. uint8_t err_code;
  181. uint16_t cause_code;
  182. uint16_t reserved1;
  183. u_char call_stats[128];
  184. };
  185. struct pptp_msg_wen {
  186. uint16_t peer_call_id;
  187. uint16_t reserved1;
  188. uint32_t crc_err;
  189. uint32_t framing_err;
  190. uint32_t hardware_overrun;
  191. uint32_t buffer_overrun;
  192. uint32_t timeout_err;
  193. uint32_t align_err;
  194. };
  195. struct pptp_msg_sli {
  196. uint16_t peer_call_id;
  197. uint16_t reserved1;
  198. uint32_t send_accm;
  199. uint32_t recv_accm;
  200. };
  201. /* attributes that appear more than once in above messages:
  202. Number of
  203. occurence attributes
  204. --------------------------------------
  205. 2 uint32_t bearer_cap;
  206. 2 uint32_t bearer_type;
  207. 6 uint16_t call_id;
  208. 2 uint16_t call_ser;
  209. 2 uint16_t cause_code;
  210. 2 uint32_t conn_speed;
  211. 6 uint8_t err_code;
  212. 2 uint16_t firm_rev;
  213. 2 uint32_t framing_cap;
  214. 2 uint32_t framing_type;
  215. 2 u_char hostname[64];
  216. 2 uint32_t id;
  217. 2 uint16_t max_channel;
  218. 5 uint16_t peer_call_id;
  219. 2 uint32_t phy_chan_id;
  220. 4 uint16_t pkt_proc_delay;
  221. 2 uint16_t proto_ver;
  222. 4 uint16_t recv_winsiz;
  223. 2 uint8_t reserved1;
  224. 9 uint16_t reserved1;
  225. 6 uint8_t result_code;
  226. 2 u_char subaddr[64];
  227. 2 u_char vendor[64];
  228. so I will prepare print out functions for these attributes (except for
  229. reserved*).
  230. */
  231. /******************************************/
  232. /* Attribute-specific print out functions */
  233. /******************************************/
  234. /* In these attribute-specific print-out functions, it't not necessary
  235. to do ND_TCHECK because they are already checked in the caller of
  236. these functions. */
  237. static void
  238. pptp_bearer_cap_print(netdissect_options *ndo,
  239. const uint32_t *bearer_cap)
  240. {
  241. ND_PRINT((ndo, " BEARER_CAP(%s%s)",
  242. EXTRACT_32BITS(bearer_cap) & PPTP_BEARER_CAP_DIGITAL_MASK ? "D" : "",
  243. EXTRACT_32BITS(bearer_cap) & PPTP_BEARER_CAP_ANALOG_MASK ? "A" : ""));
  244. }
  245. static const struct tok pptp_btype_str[] = {
  246. { 1, "A" }, /* Analog */
  247. { 2, "D" }, /* Digital */
  248. { 3, "Any" },
  249. { 0, NULL }
  250. };
  251. static void
  252. pptp_bearer_type_print(netdissect_options *ndo,
  253. const uint32_t *bearer_type)
  254. {
  255. ND_PRINT((ndo, " BEARER_TYPE(%s)",
  256. tok2str(pptp_btype_str, "?", EXTRACT_32BITS(bearer_type))));
  257. }
  258. static void
  259. pptp_call_id_print(netdissect_options *ndo,
  260. const uint16_t *call_id)
  261. {
  262. ND_PRINT((ndo, " CALL_ID(%u)", EXTRACT_16BITS(call_id)));
  263. }
  264. static void
  265. pptp_call_ser_print(netdissect_options *ndo,
  266. const uint16_t *call_ser)
  267. {
  268. ND_PRINT((ndo, " CALL_SER_NUM(%u)", EXTRACT_16BITS(call_ser)));
  269. }
  270. static void
  271. pptp_cause_code_print(netdissect_options *ndo,
  272. const uint16_t *cause_code)
  273. {
  274. ND_PRINT((ndo, " CAUSE_CODE(%u)", EXTRACT_16BITS(cause_code)));
  275. }
  276. static void
  277. pptp_conn_speed_print(netdissect_options *ndo,
  278. const uint32_t *conn_speed)
  279. {
  280. ND_PRINT((ndo, " CONN_SPEED(%u)", EXTRACT_32BITS(conn_speed)));
  281. }
  282. static const struct tok pptp_errcode_str[] = {
  283. { 0, "None" },
  284. { 1, "Not-Connected" },
  285. { 2, "Bad-Format" },
  286. { 3, "Bad-Value" },
  287. { 4, "No-Resource" },
  288. { 5, "Bad-Call-ID" },
  289. { 6, "PAC-Error" },
  290. { 0, NULL }
  291. };
  292. static void
  293. pptp_err_code_print(netdissect_options *ndo,
  294. const uint8_t *err_code)
  295. {
  296. ND_PRINT((ndo, " ERR_CODE(%u", *err_code));
  297. if (ndo->ndo_vflag) {
  298. ND_PRINT((ndo, ":%s", tok2str(pptp_errcode_str, "?", *err_code)));
  299. }
  300. ND_PRINT((ndo, ")"));
  301. }
  302. static void
  303. pptp_firm_rev_print(netdissect_options *ndo,
  304. const uint16_t *firm_rev)
  305. {
  306. ND_PRINT((ndo, " FIRM_REV(%u)", EXTRACT_16BITS(firm_rev)));
  307. }
  308. static void
  309. pptp_framing_cap_print(netdissect_options *ndo,
  310. const uint32_t *framing_cap)
  311. {
  312. ND_PRINT((ndo, " FRAME_CAP("));
  313. if (EXTRACT_32BITS(framing_cap) & PPTP_FRAMING_CAP_ASYNC_MASK) {
  314. ND_PRINT((ndo, "A")); /* Async */
  315. }
  316. if (EXTRACT_32BITS(framing_cap) & PPTP_FRAMING_CAP_SYNC_MASK) {
  317. ND_PRINT((ndo, "S")); /* Sync */
  318. }
  319. ND_PRINT((ndo, ")"));
  320. }
  321. static const struct tok pptp_ftype_str[] = {
  322. { 1, "A" }, /* Async */
  323. { 2, "S" }, /* Sync */
  324. { 3, "E" }, /* Either */
  325. { 0, NULL }
  326. };
  327. static void
  328. pptp_framing_type_print(netdissect_options *ndo,
  329. const uint32_t *framing_type)
  330. {
  331. ND_PRINT((ndo, " FRAME_TYPE(%s)",
  332. tok2str(pptp_ftype_str, "?", EXTRACT_32BITS(framing_type))));
  333. }
  334. static void
  335. pptp_hostname_print(netdissect_options *ndo,
  336. const u_char *hostname)
  337. {
  338. ND_PRINT((ndo, " HOSTNAME(%.64s)", hostname));
  339. }
  340. static void
  341. pptp_id_print(netdissect_options *ndo,
  342. const uint32_t *id)
  343. {
  344. ND_PRINT((ndo, " ID(%u)", EXTRACT_32BITS(id)));
  345. }
  346. static void
  347. pptp_max_channel_print(netdissect_options *ndo,
  348. const uint16_t *max_channel)
  349. {
  350. ND_PRINT((ndo, " MAX_CHAN(%u)", EXTRACT_16BITS(max_channel)));
  351. }
  352. static void
  353. pptp_peer_call_id_print(netdissect_options *ndo,
  354. const uint16_t *peer_call_id)
  355. {
  356. ND_PRINT((ndo, " PEER_CALL_ID(%u)", EXTRACT_16BITS(peer_call_id)));
  357. }
  358. static void
  359. pptp_phy_chan_id_print(netdissect_options *ndo,
  360. const uint32_t *phy_chan_id)
  361. {
  362. ND_PRINT((ndo, " PHY_CHAN_ID(%u)", EXTRACT_32BITS(phy_chan_id)));
  363. }
  364. static void
  365. pptp_pkt_proc_delay_print(netdissect_options *ndo,
  366. const uint16_t *pkt_proc_delay)
  367. {
  368. ND_PRINT((ndo, " PROC_DELAY(%u)", EXTRACT_16BITS(pkt_proc_delay)));
  369. }
  370. static void
  371. pptp_proto_ver_print(netdissect_options *ndo,
  372. const uint16_t *proto_ver)
  373. {
  374. ND_PRINT((ndo, " PROTO_VER(%u.%u)", /* Version.Revision */
  375. EXTRACT_16BITS(proto_ver) >> 8,
  376. EXTRACT_16BITS(proto_ver) & 0xff));
  377. }
  378. static void
  379. pptp_recv_winsiz_print(netdissect_options *ndo,
  380. const uint16_t *recv_winsiz)
  381. {
  382. ND_PRINT((ndo, " RECV_WIN(%u)", EXTRACT_16BITS(recv_winsiz)));
  383. }
  384. static const struct tok pptp_scrrp_str[] = {
  385. { 1, "Successful channel establishment" },
  386. { 2, "General error" },
  387. { 3, "Command channel already exists" },
  388. { 4, "Requester is not authorized to establish a command channel" },
  389. { 5, "The protocol version of the requester is not supported" },
  390. { 0, NULL }
  391. };
  392. static const struct tok pptp_echorp_str[] = {
  393. { 1, "OK" },
  394. { 2, "General Error" },
  395. { 0, NULL }
  396. };
  397. static const struct tok pptp_ocrp_str[] = {
  398. { 1, "Connected" },
  399. { 2, "General Error" },
  400. { 3, "No Carrier" },
  401. { 4, "Busy" },
  402. { 5, "No Dial Tone" },
  403. { 6, "Time-out" },
  404. { 7, "Do Not Accept" },
  405. { 0, NULL }
  406. };
  407. static const struct tok pptp_icrp_str[] = {
  408. { 1, "Connect" },
  409. { 2, "General Error" },
  410. { 3, "Do Not Accept" },
  411. { 0, NULL }
  412. };
  413. static const struct tok pptp_cdn_str[] = {
  414. { 1, "Lost Carrier" },
  415. { 2, "General Error" },
  416. { 3, "Admin Shutdown" },
  417. { 4, "Request" },
  418. { 0, NULL }
  419. };
  420. static void
  421. pptp_result_code_print(netdissect_options *ndo,
  422. const uint8_t *result_code, int ctrl_msg_type)
  423. {
  424. ND_PRINT((ndo, " RESULT_CODE(%u", *result_code));
  425. if (ndo->ndo_vflag) {
  426. const struct tok *dict =
  427. ctrl_msg_type == PPTP_CTRL_MSG_TYPE_SCCRP ? pptp_scrrp_str :
  428. ctrl_msg_type == PPTP_CTRL_MSG_TYPE_StopCCRP ? pptp_echorp_str :
  429. ctrl_msg_type == PPTP_CTRL_MSG_TYPE_ECHORP ? pptp_echorp_str :
  430. ctrl_msg_type == PPTP_CTRL_MSG_TYPE_OCRP ? pptp_ocrp_str :
  431. ctrl_msg_type == PPTP_CTRL_MSG_TYPE_ICRP ? pptp_icrp_str :
  432. ctrl_msg_type == PPTP_CTRL_MSG_TYPE_CDN ? pptp_cdn_str :
  433. NULL; /* assertion error */
  434. if (dict != NULL)
  435. ND_PRINT((ndo, ":%s", tok2str(dict, "?", *result_code)));
  436. }
  437. ND_PRINT((ndo, ")"));
  438. }
  439. static void
  440. pptp_subaddr_print(netdissect_options *ndo,
  441. const u_char *subaddr)
  442. {
  443. ND_PRINT((ndo, " SUB_ADDR(%.64s)", subaddr));
  444. }
  445. static void
  446. pptp_vendor_print(netdissect_options *ndo,
  447. const u_char *vendor)
  448. {
  449. ND_PRINT((ndo, " VENDOR(%.64s)", vendor));
  450. }
  451. /************************************/
  452. /* PPTP message print out functions */
  453. /************************************/
  454. static void
  455. pptp_sccrq_print(netdissect_options *ndo,
  456. const u_char *dat)
  457. {
  458. const struct pptp_msg_sccrq *ptr = (const struct pptp_msg_sccrq *)dat;
  459. ND_TCHECK(ptr->proto_ver);
  460. pptp_proto_ver_print(ndo, &ptr->proto_ver);
  461. ND_TCHECK(ptr->reserved1);
  462. ND_TCHECK(ptr->framing_cap);
  463. pptp_framing_cap_print(ndo, &ptr->framing_cap);
  464. ND_TCHECK(ptr->bearer_cap);
  465. pptp_bearer_cap_print(ndo, &ptr->bearer_cap);
  466. ND_TCHECK(ptr->max_channel);
  467. pptp_max_channel_print(ndo, &ptr->max_channel);
  468. ND_TCHECK(ptr->firm_rev);
  469. pptp_firm_rev_print(ndo, &ptr->firm_rev);
  470. ND_TCHECK(ptr->hostname);
  471. pptp_hostname_print(ndo, &ptr->hostname[0]);
  472. ND_TCHECK(ptr->vendor);
  473. pptp_vendor_print(ndo, &ptr->vendor[0]);
  474. return;
  475. trunc:
  476. ND_PRINT((ndo, "%s", tstr));
  477. }
  478. static void
  479. pptp_sccrp_print(netdissect_options *ndo,
  480. const u_char *dat)
  481. {
  482. const struct pptp_msg_sccrp *ptr = (const struct pptp_msg_sccrp *)dat;
  483. ND_TCHECK(ptr->proto_ver);
  484. pptp_proto_ver_print(ndo, &ptr->proto_ver);
  485. ND_TCHECK(ptr->result_code);
  486. pptp_result_code_print(ndo, &ptr->result_code, PPTP_CTRL_MSG_TYPE_SCCRP);
  487. ND_TCHECK(ptr->err_code);
  488. pptp_err_code_print(ndo, &ptr->err_code);
  489. ND_TCHECK(ptr->framing_cap);
  490. pptp_framing_cap_print(ndo, &ptr->framing_cap);
  491. ND_TCHECK(ptr->bearer_cap);
  492. pptp_bearer_cap_print(ndo, &ptr->bearer_cap);
  493. ND_TCHECK(ptr->max_channel);
  494. pptp_max_channel_print(ndo, &ptr->max_channel);
  495. ND_TCHECK(ptr->firm_rev);
  496. pptp_firm_rev_print(ndo, &ptr->firm_rev);
  497. ND_TCHECK(ptr->hostname);
  498. pptp_hostname_print(ndo, &ptr->hostname[0]);
  499. ND_TCHECK(ptr->vendor);
  500. pptp_vendor_print(ndo, &ptr->vendor[0]);
  501. return;
  502. trunc:
  503. ND_PRINT((ndo, "%s", tstr));
  504. }
  505. static void
  506. pptp_stopccrq_print(netdissect_options *ndo,
  507. const u_char *dat)
  508. {
  509. const struct pptp_msg_stopccrq *ptr = (const struct pptp_msg_stopccrq *)dat;
  510. ND_TCHECK(ptr->reason);
  511. ND_PRINT((ndo, " REASON(%u", ptr->reason));
  512. if (ndo->ndo_vflag) {
  513. switch (ptr->reason) {
  514. case 1:
  515. ND_PRINT((ndo, ":None"));
  516. break;
  517. case 2:
  518. ND_PRINT((ndo, ":Stop-Protocol"));
  519. break;
  520. case 3:
  521. ND_PRINT((ndo, ":Stop-Local-Shutdown"));
  522. break;
  523. default:
  524. ND_PRINT((ndo, ":?"));
  525. break;
  526. }
  527. }
  528. ND_PRINT((ndo, ")"));
  529. ND_TCHECK(ptr->reserved1);
  530. ND_TCHECK(ptr->reserved2);
  531. return;
  532. trunc:
  533. ND_PRINT((ndo, "%s", tstr));
  534. }
  535. static void
  536. pptp_stopccrp_print(netdissect_options *ndo,
  537. const u_char *dat)
  538. {
  539. const struct pptp_msg_stopccrp *ptr = (const struct pptp_msg_stopccrp *)dat;
  540. ND_TCHECK(ptr->result_code);
  541. pptp_result_code_print(ndo, &ptr->result_code, PPTP_CTRL_MSG_TYPE_StopCCRP);
  542. ND_TCHECK(ptr->err_code);
  543. pptp_err_code_print(ndo, &ptr->err_code);
  544. ND_TCHECK(ptr->reserved1);
  545. return;
  546. trunc:
  547. ND_PRINT((ndo, "%s", tstr));
  548. }
  549. static void
  550. pptp_echorq_print(netdissect_options *ndo,
  551. const u_char *dat)
  552. {
  553. const struct pptp_msg_echorq *ptr = (const struct pptp_msg_echorq *)dat;
  554. ND_TCHECK(ptr->id);
  555. pptp_id_print(ndo, &ptr->id);
  556. return;
  557. trunc:
  558. ND_PRINT((ndo, "%s", tstr));
  559. }
  560. static void
  561. pptp_echorp_print(netdissect_options *ndo,
  562. const u_char *dat)
  563. {
  564. const struct pptp_msg_echorp *ptr = (const struct pptp_msg_echorp *)dat;
  565. ND_TCHECK(ptr->id);
  566. pptp_id_print(ndo, &ptr->id);
  567. ND_TCHECK(ptr->result_code);
  568. pptp_result_code_print(ndo, &ptr->result_code, PPTP_CTRL_MSG_TYPE_ECHORP);
  569. ND_TCHECK(ptr->err_code);
  570. pptp_err_code_print(ndo, &ptr->err_code);
  571. ND_TCHECK(ptr->reserved1);
  572. return;
  573. trunc:
  574. ND_PRINT((ndo, "%s", tstr));
  575. }
  576. static void
  577. pptp_ocrq_print(netdissect_options *ndo,
  578. const u_char *dat)
  579. {
  580. const struct pptp_msg_ocrq *ptr = (const struct pptp_msg_ocrq *)dat;
  581. ND_TCHECK(ptr->call_id);
  582. pptp_call_id_print(ndo, &ptr->call_id);
  583. ND_TCHECK(ptr->call_ser);
  584. pptp_call_ser_print(ndo, &ptr->call_ser);
  585. ND_TCHECK(ptr->min_bps);
  586. ND_PRINT((ndo, " MIN_BPS(%u)", EXTRACT_32BITS(&ptr->min_bps)));
  587. ND_TCHECK(ptr->max_bps);
  588. ND_PRINT((ndo, " MAX_BPS(%u)", EXTRACT_32BITS(&ptr->max_bps)));
  589. ND_TCHECK(ptr->bearer_type);
  590. pptp_bearer_type_print(ndo, &ptr->bearer_type);
  591. ND_TCHECK(ptr->framing_type);
  592. pptp_framing_type_print(ndo, &ptr->framing_type);
  593. ND_TCHECK(ptr->recv_winsiz);
  594. pptp_recv_winsiz_print(ndo, &ptr->recv_winsiz);
  595. ND_TCHECK(ptr->pkt_proc_delay);
  596. pptp_pkt_proc_delay_print(ndo, &ptr->pkt_proc_delay);
  597. ND_TCHECK(ptr->phone_no_len);
  598. ND_PRINT((ndo, " PHONE_NO_LEN(%u)", EXTRACT_16BITS(&ptr->phone_no_len)));
  599. ND_TCHECK(ptr->reserved1);
  600. ND_TCHECK(ptr->phone_no);
  601. ND_PRINT((ndo, " PHONE_NO(%.64s)", ptr->phone_no));
  602. ND_TCHECK(ptr->subaddr);
  603. pptp_subaddr_print(ndo, &ptr->subaddr[0]);
  604. return;
  605. trunc:
  606. ND_PRINT((ndo, "%s", tstr));
  607. }
  608. static void
  609. pptp_ocrp_print(netdissect_options *ndo,
  610. const u_char *dat)
  611. {
  612. const struct pptp_msg_ocrp *ptr = (const struct pptp_msg_ocrp *)dat;
  613. ND_TCHECK(ptr->call_id);
  614. pptp_call_id_print(ndo, &ptr->call_id);
  615. ND_TCHECK(ptr->peer_call_id);
  616. pptp_peer_call_id_print(ndo, &ptr->peer_call_id);
  617. ND_TCHECK(ptr->result_code);
  618. pptp_result_code_print(ndo, &ptr->result_code, PPTP_CTRL_MSG_TYPE_OCRP);
  619. ND_TCHECK(ptr->err_code);
  620. pptp_err_code_print(ndo, &ptr->err_code);
  621. ND_TCHECK(ptr->cause_code);
  622. pptp_cause_code_print(ndo, &ptr->cause_code);
  623. ND_TCHECK(ptr->conn_speed);
  624. pptp_conn_speed_print(ndo, &ptr->conn_speed);
  625. ND_TCHECK(ptr->recv_winsiz);
  626. pptp_recv_winsiz_print(ndo, &ptr->recv_winsiz);
  627. ND_TCHECK(ptr->pkt_proc_delay);
  628. pptp_pkt_proc_delay_print(ndo, &ptr->pkt_proc_delay);
  629. ND_TCHECK(ptr->phy_chan_id);
  630. pptp_phy_chan_id_print(ndo, &ptr->phy_chan_id);
  631. return;
  632. trunc:
  633. ND_PRINT((ndo, "%s", tstr));
  634. }
  635. static void
  636. pptp_icrq_print(netdissect_options *ndo,
  637. const u_char *dat)
  638. {
  639. const struct pptp_msg_icrq *ptr = (const struct pptp_msg_icrq *)dat;
  640. ND_TCHECK(ptr->call_id);
  641. pptp_call_id_print(ndo, &ptr->call_id);
  642. ND_TCHECK(ptr->call_ser);
  643. pptp_call_ser_print(ndo, &ptr->call_ser);
  644. ND_TCHECK(ptr->bearer_type);
  645. pptp_bearer_type_print(ndo, &ptr->bearer_type);
  646. ND_TCHECK(ptr->phy_chan_id);
  647. pptp_phy_chan_id_print(ndo, &ptr->phy_chan_id);
  648. ND_TCHECK(ptr->dialed_no_len);
  649. ND_PRINT((ndo, " DIALED_NO_LEN(%u)", EXTRACT_16BITS(&ptr->dialed_no_len)));
  650. ND_TCHECK(ptr->dialing_no_len);
  651. ND_PRINT((ndo, " DIALING_NO_LEN(%u)", EXTRACT_16BITS(&ptr->dialing_no_len)));
  652. ND_TCHECK(ptr->dialed_no);
  653. ND_PRINT((ndo, " DIALED_NO(%.64s)", ptr->dialed_no));
  654. ND_TCHECK(ptr->dialing_no);
  655. ND_PRINT((ndo, " DIALING_NO(%.64s)", ptr->dialing_no));
  656. ND_TCHECK(ptr->subaddr);
  657. pptp_subaddr_print(ndo, &ptr->subaddr[0]);
  658. return;
  659. trunc:
  660. ND_PRINT((ndo, "%s", tstr));
  661. }
  662. static void
  663. pptp_icrp_print(netdissect_options *ndo,
  664. const u_char *dat)
  665. {
  666. const struct pptp_msg_icrp *ptr = (const struct pptp_msg_icrp *)dat;
  667. ND_TCHECK(ptr->call_id);
  668. pptp_call_id_print(ndo, &ptr->call_id);
  669. ND_TCHECK(ptr->peer_call_id);
  670. pptp_peer_call_id_print(ndo, &ptr->peer_call_id);
  671. ND_TCHECK(ptr->result_code);
  672. pptp_result_code_print(ndo, &ptr->result_code, PPTP_CTRL_MSG_TYPE_ICRP);
  673. ND_TCHECK(ptr->err_code);
  674. pptp_err_code_print(ndo, &ptr->err_code);
  675. ND_TCHECK(ptr->recv_winsiz);
  676. pptp_recv_winsiz_print(ndo, &ptr->recv_winsiz);
  677. ND_TCHECK(ptr->pkt_proc_delay);
  678. pptp_pkt_proc_delay_print(ndo, &ptr->pkt_proc_delay);
  679. ND_TCHECK(ptr->reserved1);
  680. return;
  681. trunc:
  682. ND_PRINT((ndo, "%s", tstr));
  683. }
  684. static void
  685. pptp_iccn_print(netdissect_options *ndo,
  686. const u_char *dat)
  687. {
  688. const struct pptp_msg_iccn *ptr = (const struct pptp_msg_iccn *)dat;
  689. ND_TCHECK(ptr->peer_call_id);
  690. pptp_peer_call_id_print(ndo, &ptr->peer_call_id);
  691. ND_TCHECK(ptr->reserved1);
  692. ND_TCHECK(ptr->conn_speed);
  693. pptp_conn_speed_print(ndo, &ptr->conn_speed);
  694. ND_TCHECK(ptr->recv_winsiz);
  695. pptp_recv_winsiz_print(ndo, &ptr->recv_winsiz);
  696. ND_TCHECK(ptr->pkt_proc_delay);
  697. pptp_pkt_proc_delay_print(ndo, &ptr->pkt_proc_delay);
  698. ND_TCHECK(ptr->framing_type);
  699. pptp_framing_type_print(ndo, &ptr->framing_type);
  700. return;
  701. trunc:
  702. ND_PRINT((ndo, "%s", tstr));
  703. }
  704. static void
  705. pptp_ccrq_print(netdissect_options *ndo,
  706. const u_char *dat)
  707. {
  708. const struct pptp_msg_ccrq *ptr = (const struct pptp_msg_ccrq *)dat;
  709. ND_TCHECK(ptr->call_id);
  710. pptp_call_id_print(ndo, &ptr->call_id);
  711. ND_TCHECK(ptr->reserved1);
  712. return;
  713. trunc:
  714. ND_PRINT((ndo, "%s", tstr));
  715. }
  716. static void
  717. pptp_cdn_print(netdissect_options *ndo,
  718. const u_char *dat)
  719. {
  720. const struct pptp_msg_cdn *ptr = (const struct pptp_msg_cdn *)dat;
  721. ND_TCHECK(ptr->call_id);
  722. pptp_call_id_print(ndo, &ptr->call_id);
  723. ND_TCHECK(ptr->result_code);
  724. pptp_result_code_print(ndo, &ptr->result_code, PPTP_CTRL_MSG_TYPE_CDN);
  725. ND_TCHECK(ptr->err_code);
  726. pptp_err_code_print(ndo, &ptr->err_code);
  727. ND_TCHECK(ptr->cause_code);
  728. pptp_cause_code_print(ndo, &ptr->cause_code);
  729. ND_TCHECK(ptr->reserved1);
  730. ND_TCHECK(ptr->call_stats);
  731. ND_PRINT((ndo, " CALL_STATS(%.128s)", ptr->call_stats));
  732. return;
  733. trunc:
  734. ND_PRINT((ndo, "%s", tstr));
  735. }
  736. static void
  737. pptp_wen_print(netdissect_options *ndo,
  738. const u_char *dat)
  739. {
  740. const struct pptp_msg_wen *ptr = (const struct pptp_msg_wen *)dat;
  741. ND_TCHECK(ptr->peer_call_id);
  742. pptp_peer_call_id_print(ndo, &ptr->peer_call_id);
  743. ND_TCHECK(ptr->reserved1);
  744. ND_TCHECK(ptr->crc_err);
  745. ND_PRINT((ndo, " CRC_ERR(%u)", EXTRACT_32BITS(&ptr->crc_err)));
  746. ND_TCHECK(ptr->framing_err);
  747. ND_PRINT((ndo, " FRAMING_ERR(%u)", EXTRACT_32BITS(&ptr->framing_err)));
  748. ND_TCHECK(ptr->hardware_overrun);
  749. ND_PRINT((ndo, " HARDWARE_OVERRUN(%u)", EXTRACT_32BITS(&ptr->hardware_overrun)));
  750. ND_TCHECK(ptr->buffer_overrun);
  751. ND_PRINT((ndo, " BUFFER_OVERRUN(%u)", EXTRACT_32BITS(&ptr->buffer_overrun)));
  752. ND_TCHECK(ptr->timeout_err);
  753. ND_PRINT((ndo, " TIMEOUT_ERR(%u)", EXTRACT_32BITS(&ptr->timeout_err)));
  754. ND_TCHECK(ptr->align_err);
  755. ND_PRINT((ndo, " ALIGN_ERR(%u)", EXTRACT_32BITS(&ptr->align_err)));
  756. return;
  757. trunc:
  758. ND_PRINT((ndo, "%s", tstr));
  759. }
  760. static void
  761. pptp_sli_print(netdissect_options *ndo,
  762. const u_char *dat)
  763. {
  764. const struct pptp_msg_sli *ptr = (const struct pptp_msg_sli *)dat;
  765. ND_TCHECK(ptr->peer_call_id);
  766. pptp_peer_call_id_print(ndo, &ptr->peer_call_id);
  767. ND_TCHECK(ptr->reserved1);
  768. ND_TCHECK(ptr->send_accm);
  769. ND_PRINT((ndo, " SEND_ACCM(0x%08x)", EXTRACT_32BITS(&ptr->send_accm)));
  770. ND_TCHECK(ptr->recv_accm);
  771. ND_PRINT((ndo, " RECV_ACCM(0x%08x)", EXTRACT_32BITS(&ptr->recv_accm)));
  772. return;
  773. trunc:
  774. ND_PRINT((ndo, "%s", tstr));
  775. }
  776. void
  777. pptp_print(netdissect_options *ndo,
  778. const u_char *dat)
  779. {
  780. const struct pptp_hdr *hdr;
  781. uint32_t mc;
  782. uint16_t ctrl_msg_type;
  783. ND_PRINT((ndo, ": pptp"));
  784. hdr = (const struct pptp_hdr *)dat;
  785. ND_TCHECK(hdr->length);
  786. if (ndo->ndo_vflag) {
  787. ND_PRINT((ndo, " Length=%u", EXTRACT_16BITS(&hdr->length)));
  788. }
  789. ND_TCHECK(hdr->msg_type);
  790. if (ndo->ndo_vflag) {
  791. switch(EXTRACT_16BITS(&hdr->msg_type)) {
  792. case PPTP_MSG_TYPE_CTRL:
  793. ND_PRINT((ndo, " CTRL-MSG"));
  794. break;
  795. case PPTP_MSG_TYPE_MGMT:
  796. ND_PRINT((ndo, " MGMT-MSG"));
  797. break;
  798. default:
  799. ND_PRINT((ndo, " UNKNOWN-MSG-TYPE"));
  800. break;
  801. }
  802. }
  803. ND_TCHECK(hdr->magic_cookie);
  804. mc = EXTRACT_32BITS(&hdr->magic_cookie);
  805. if (mc != PPTP_MAGIC_COOKIE) {
  806. ND_PRINT((ndo, " UNEXPECTED Magic-Cookie!!(%08x)", mc));
  807. }
  808. if (ndo->ndo_vflag || mc != PPTP_MAGIC_COOKIE) {
  809. ND_PRINT((ndo, " Magic-Cookie=%08x", mc));
  810. }
  811. ND_TCHECK(hdr->ctrl_msg_type);
  812. ctrl_msg_type = EXTRACT_16BITS(&hdr->ctrl_msg_type);
  813. if (ctrl_msg_type < PPTP_MAX_MSGTYPE_INDEX) {
  814. ND_PRINT((ndo, " CTRL_MSGTYPE=%s",
  815. pptp_message_type_string[ctrl_msg_type]));
  816. } else {
  817. ND_PRINT((ndo, " UNKNOWN_CTRL_MSGTYPE(%u)", ctrl_msg_type));
  818. }
  819. ND_TCHECK(hdr->reserved0);
  820. dat += 12;
  821. switch(ctrl_msg_type) {
  822. case PPTP_CTRL_MSG_TYPE_SCCRQ:
  823. pptp_sccrq_print(ndo, dat);
  824. break;
  825. case PPTP_CTRL_MSG_TYPE_SCCRP:
  826. pptp_sccrp_print(ndo, dat);
  827. break;
  828. case PPTP_CTRL_MSG_TYPE_StopCCRQ:
  829. pptp_stopccrq_print(ndo, dat);
  830. break;
  831. case PPTP_CTRL_MSG_TYPE_StopCCRP:
  832. pptp_stopccrp_print(ndo, dat);
  833. break;
  834. case PPTP_CTRL_MSG_TYPE_ECHORQ:
  835. pptp_echorq_print(ndo, dat);
  836. break;
  837. case PPTP_CTRL_MSG_TYPE_ECHORP:
  838. pptp_echorp_print(ndo, dat);
  839. break;
  840. case PPTP_CTRL_MSG_TYPE_OCRQ:
  841. pptp_ocrq_print(ndo, dat);
  842. break;
  843. case PPTP_CTRL_MSG_TYPE_OCRP:
  844. pptp_ocrp_print(ndo, dat);
  845. break;
  846. case PPTP_CTRL_MSG_TYPE_ICRQ:
  847. pptp_icrq_print(ndo, dat);
  848. break;
  849. case PPTP_CTRL_MSG_TYPE_ICRP:
  850. pptp_icrp_print(ndo, dat);
  851. break;
  852. case PPTP_CTRL_MSG_TYPE_ICCN:
  853. pptp_iccn_print(ndo, dat);
  854. break;
  855. case PPTP_CTRL_MSG_TYPE_CCRQ:
  856. pptp_ccrq_print(ndo, dat);
  857. break;
  858. case PPTP_CTRL_MSG_TYPE_CDN:
  859. pptp_cdn_print(ndo, dat);
  860. break;
  861. case PPTP_CTRL_MSG_TYPE_WEN:
  862. pptp_wen_print(ndo, dat);
  863. break;
  864. case PPTP_CTRL_MSG_TYPE_SLI:
  865. pptp_sli_print(ndo, dat);
  866. break;
  867. default:
  868. /* do nothing */
  869. break;
  870. }
  871. return;
  872. trunc:
  873. ND_PRINT((ndo, "%s", tstr));
  874. }