blob: 774edfbaf8cefff90aa2b5574737eb4246344340 [file] [log] [blame]
JP Abgrall53f17a92014-02-12 14:02:41 -08001/*
2 * Oracle
3 */
Elliott Hughese2e3bd12017-05-15 10:59:29 -07004
Elliott Hughes820eced2021-08-20 18:00:50 -07005/* \summary: Per-Packet Information (DLT_PPI) printer */
6
7/* Specification:
8 * Per-Packet Information Header Specification - Version 1.0.7
9 * https://web.archive.org/web/20160328114748/http://www.cacetech.com/documents/PPI%20Header%20format%201.0.7.pdf
10 */
Elliott Hughese2e3bd12017-05-15 10:59:29 -070011
JP Abgrall53f17a92014-02-12 14:02:41 -080012#ifdef HAVE_CONFIG_H
Elliott Hughes820eced2021-08-20 18:00:50 -070013#include <config.h>
JP Abgrall53f17a92014-02-12 14:02:41 -080014#endif
15
Elliott Hughes820eced2021-08-20 18:00:50 -070016#include "netdissect-stdinc.h"
JP Abgrall53f17a92014-02-12 14:02:41 -080017
Elliott Hughese2e3bd12017-05-15 10:59:29 -070018#include "netdissect.h"
JP Abgrall53f17a92014-02-12 14:02:41 -080019#include "extract.h"
Elliott Hughes892a68b2015-10-19 14:43:53 -070020
Elliott Hughes820eced2021-08-20 18:00:50 -070021
Elliott Hughes892a68b2015-10-19 14:43:53 -070022typedef struct ppi_header {
Elliott Hughes820eced2021-08-20 18:00:50 -070023 nd_uint8_t ppi_ver; /* Version. Currently 0 */
24 nd_uint8_t ppi_flags; /* Flags. */
25 nd_uint16_t ppi_len; /* Length of entire message, including
26 * this header and TLV payload. */
27 nd_uint32_t ppi_dlt; /* Data Link Type of the captured
28 * packet data. */
Elliott Hughes892a68b2015-10-19 14:43:53 -070029} ppi_header_t;
30
31#define PPI_HDRLEN 8
JP Abgrall53f17a92014-02-12 14:02:41 -080032
33#ifdef DLT_PPI
34
Elliott Hughes820eced2021-08-20 18:00:50 -070035static void
Elliott Hughes892a68b2015-10-19 14:43:53 -070036ppi_header_print(netdissect_options *ndo, const u_char *bp, u_int length)
JP Abgrall53f17a92014-02-12 14:02:41 -080037{
38 const ppi_header_t *hdr;
Elliott Hughes892a68b2015-10-19 14:43:53 -070039 uint16_t len;
40 uint32_t dlt;
Elliott Hughese2e3bd12017-05-15 10:59:29 -070041 const char *dltname;
JP Abgrall53f17a92014-02-12 14:02:41 -080042
43 hdr = (const ppi_header_t *)bp;
44
Elliott Hughes820eced2021-08-20 18:00:50 -070045 len = GET_LE_U_2(hdr->ppi_len);
46 dlt = GET_LE_U_4(hdr->ppi_dlt);
Elliott Hughese2e3bd12017-05-15 10:59:29 -070047 dltname = pcap_datalink_val_to_name(dlt);
JP Abgrall53f17a92014-02-12 14:02:41 -080048
49 if (!ndo->ndo_qflag) {
Elliott Hughes820eced2021-08-20 18:00:50 -070050 ND_PRINT("V.%u DLT %s (%u) len %u", GET_U_1(hdr->ppi_ver),
Elliott Hughese2e3bd12017-05-15 10:59:29 -070051 (dltname != NULL ? dltname : "UNKNOWN"), dlt,
Elliott Hughes820eced2021-08-20 18:00:50 -070052 len);
JP Abgrall53f17a92014-02-12 14:02:41 -080053 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -070054 ND_PRINT("%s", (dltname != NULL ? dltname : "UNKNOWN"));
JP Abgrall53f17a92014-02-12 14:02:41 -080055 }
56
Elliott Hughes820eced2021-08-20 18:00:50 -070057 ND_PRINT(", length %u: ", length);
JP Abgrall53f17a92014-02-12 14:02:41 -080058}
59
Elliott Hughes820eced2021-08-20 18:00:50 -070060/*
61 * This is the top level routine of the printer. 'p' points
62 * to the ether header of the packet, 'h->ts' is the timestamp,
63 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
64 * is the number of bytes actually captured.
65 */
66void
67ppi_if_print(netdissect_options *ndo,
68 const struct pcap_pkthdr *h, const u_char *p)
JP Abgrall53f17a92014-02-12 14:02:41 -080069{
Elliott Hughese2e3bd12017-05-15 10:59:29 -070070 if_printer printer;
71 const ppi_header_t *hdr;
JP Abgrall53f17a92014-02-12 14:02:41 -080072 u_int caplen = h->caplen;
73 u_int length = h->len;
Elliott Hughes892a68b2015-10-19 14:43:53 -070074 uint16_t len;
75 uint32_t dlt;
Elliott Hughese2e3bd12017-05-15 10:59:29 -070076 uint32_t hdrlen;
77 struct pcap_pkthdr nhdr;
JP Abgrall53f17a92014-02-12 14:02:41 -080078
Elliott Hughes820eced2021-08-20 18:00:50 -070079 ndo->ndo_protocol = "ppi";
JP Abgrall53f17a92014-02-12 14:02:41 -080080 if (caplen < sizeof(ppi_header_t)) {
Elliott Hughes820eced2021-08-20 18:00:50 -070081 nd_print_trunc(ndo);
82 ndo->ndo_ll_hdr_len += caplen;
83 return;
JP Abgrall53f17a92014-02-12 14:02:41 -080084 }
Elliott Hughes892a68b2015-10-19 14:43:53 -070085
Elliott Hughese2e3bd12017-05-15 10:59:29 -070086 hdr = (const ppi_header_t *)p;
Elliott Hughes820eced2021-08-20 18:00:50 -070087 len = GET_LE_U_2(hdr->ppi_len);
88 if (len < sizeof(ppi_header_t) || len > 65532) {
89 /* It MUST be between 8 and 65,532 inclusive (spec 3.1.3) */
90 ND_PRINT(" [length %u < %zu or > 65532]", len,
91 sizeof(ppi_header_t));
92 nd_print_invalid(ndo);
93 ndo->ndo_ll_hdr_len += caplen;
94 return;
95 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -070096 if (caplen < len) {
97 /*
98 * If we don't have the entire PPI header, don't
99 * bother.
100 */
Elliott Hughes820eced2021-08-20 18:00:50 -0700101 nd_print_trunc(ndo);
102 ndo->ndo_ll_hdr_len += caplen;
103 return;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700104 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700105 dlt = GET_LE_U_4(hdr->ppi_dlt);
JP Abgrall53f17a92014-02-12 14:02:41 -0800106
107 if (ndo->ndo_eflag)
108 ppi_header_print(ndo, p, length);
109
Elliott Hughes892a68b2015-10-19 14:43:53 -0700110 length -= len;
111 caplen -= len;
112 p += len;
JP Abgrall53f17a92014-02-12 14:02:41 -0800113
Elliott Hughes820eced2021-08-20 18:00:50 -0700114 printer = lookup_printer(dlt);
115 if (printer != NULL) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700116 nhdr = *h;
117 nhdr.caplen = caplen;
118 nhdr.len = length;
Elliott Hughes820eced2021-08-20 18:00:50 -0700119 printer(ndo, &nhdr, p);
120 hdrlen = ndo->ndo_ll_hdr_len;
JP Abgrall53f17a92014-02-12 14:02:41 -0800121 } else {
122 if (!ndo->ndo_eflag)
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700123 ppi_header_print(ndo, (const u_char *)hdr, length + len);
JP Abgrall53f17a92014-02-12 14:02:41 -0800124
125 if (!ndo->ndo_suppress_default_print)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700126 ND_DEFAULTPRINT(p, caplen);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700127 hdrlen = 0;
JP Abgrall53f17a92014-02-12 14:02:41 -0800128 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700129 ndo->ndo_ll_hdr_len += len + hdrlen;
JP Abgrall53f17a92014-02-12 14:02:41 -0800130}
JP Abgrall53f17a92014-02-12 14:02:41 -0800131#endif /* DLT_PPI */