diff --git a/tcpdump/netdissect.h b/tcpdump/netdissect.h index 3e15a57..fed1944 100644 --- a/tcpdump/netdissect.h +++ b/tcpdump/netdissect.h @@ -336,11 +336,12 @@ extern void nd_pop_all_packet_info(netdissect_options *); #define PRMD_FLOWID 0x2000 #define PRMD_TRACETAG 0x4000 #define PRMD_DLT 0x8000 -#define PRMD_DROP_REASON 0x10000 -#define PRMD_DROP_FUNC 0x20000 -#define PRMD_DROP_LINE 0x40000 +#define PRMD_DROP_REASON 0x10000 +#define PRMD_DROP_FUNC 0x20000 +#define PRMD_DROP_LINE 0x40000 +#define PRMD_COMP_GENCNT 0x80000 #define PRMD_DEFAULT (PRMD_IF|PRMD_PNAME|PRMD_PID|PRMD_SVC|PRMD_DIR|PRMD_COMMENT|PRMD_FLAGS|PRMD_DROP_REASON|PRMD_DROP_FUNC|PRMD_DROP_LINE) -#define PRMD_ALL 0x1ffff +#define PRMD_ALL 0xfffff #endif /* __APPLE__ */ /* diff --git a/tcpdump/print_pktap.c b/tcpdump/print_pktap.c index 5247329..11c1f4c 100644 --- a/tcpdump/print_pktap.c +++ b/tcpdump/print_pktap.c @@ -253,25 +253,39 @@ print_pktap_header(struct netdissect_options *ndo, struct pktap_header *pktp_hdr pktp_hdr->pth_flowid); prsep = ", "; } -#ifdef PKTAP_HAS_TRACE_TAG if (ndo->ndo_kflag & PRMD_TRACETAG) { ND_PRINT("%s" "ttag 0x%x", prsep, pktp_hdr->pth_trace_tag); prsep = ", "; } -#endif /* PKTAP_HAS_TRACE_TAG */ if (ndo->ndo_kflag & PRMD_DLT) { ND_PRINT("%s" "dlt 0x%x", prsep, pktp_hdr->pth_dlt); prsep = ", "; } +#ifdef PKTAP_HAS_COMP_GENCNT + if (ndo->ndo_kflag & PRMD_COMP_GENCNT) { + ND_PRINT("%s" "cmpgc 0x%x", + prsep, + pktp_hdr->pth_comp_gencnt); + prsep = ", "; + } +#endif /* PKTAP_HAS_COMP_GENCNT */ if (pktp_hdr->pth_type_next == PTH_TYPE_DROP) { struct droptap_header *dtap_hdr = (struct droptap_header *)pktp_hdr; + const char *reason_str = drop_reason_str(dtap_hdr->dth_dropreason); + char num_str[32]; + + if (reason_str == NULL) { + snprintf(num_str, sizeof(num_str), "reason: 0x%08x", dtap_hdr->dth_dropreason); + reason_str = num_str; + } + ND_PRINT("%s" "%s", - prsep, - drop_reason_str(dtap_hdr->dth_dropreason)); + prsep, + reason_str); prsep = ", "; if (dtap_hdr->dth_dropfunc_size > 0) { ND_PRINT("%s" "%s:%u", diff --git a/tcpdump/tcpdump.c b/tcpdump/tcpdump.c index cf417f9..a038180 100644 --- a/tcpdump/tcpdump.c +++ b/tcpdump/tcpdump.c @@ -1971,6 +1971,9 @@ main(int argc, char **argv) case 'V': val |= PRMD_VERBOSE; break; + case 'c': + val |= PRMD_COMP_GENCNT; + break; case 'f': val |= PRMD_FLOWID; break; @@ -3823,10 +3826,14 @@ dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *s if (ndo->ndo_packet_number) ND_PRINT("%5lu ", packets_captured - skip_packet_cnt); + if (is_pcap_pkthdr_valid(ndo, h) == 0) { + return; + } + ts_print(ndo, &h->ts); if (ndo->ndo_kflag && h->comment[0]) - ND_PRINT("%s ", h->comment); + ND_PRINT("(%s) ", h->comment); pretty_print_packet(ndo, h, sp, (u_int)packets_captured); } @@ -3881,10 +3888,14 @@ dump_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) if (ndo->ndo_packet_number) ND_PRINT("%5lu ", packets_captured - skip_packet_cnt); + if (is_pcap_pkthdr_valid(ndo, h) == 0) { + return; + } + ts_print(ndo, &h->ts); if (ndo->ndo_kflag && h->comment[0]) - ND_PRINT("%s ", h->comment); + ND_PRINT("(%s) ", h->comment); pretty_print_packet(ndo, h, sp, (u_int)packets_captured); } @@ -4482,7 +4493,7 @@ print_pcap(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) ts_print(ndo, &h->ts); if (ndo->ndo_kflag && h->comment[0]) - ND_PRINT("%s ", h->comment); + ND_PRINT("(%s) ", h->comment); pretty_print_packet(ndo, h, sp, (u_int)packets_captured); } @@ -4562,6 +4573,7 @@ print_pcap_ng_block(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) const char *drop_func = NULL; uint16_t drop_line = 0; uint16_t drop_func_len = 0; + uint32_t comp_gencnt = 0; struct pcapng_option_info option_info; block = pcap_ng_block_alloc_with_raw_block(ndo->ndo_pcap, (u_char *)sp); @@ -4690,7 +4702,7 @@ print_pcap_ng_block(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) if (pcap_is_swapped(ndo->ndo_pcap)) packet_flags = SWAPLONG(pmdflags); } -#ifdef PCAPNG_EPB_FLOW_ID + if (pcap_ng_block_get_option(block, PCAPNG_EPB_FLOW_ID, &option_info) == 1) { if (option_info.length != 4) { warning("%s: flow_id option length %u != 4", __func__, option_info.length); @@ -4701,9 +4713,7 @@ print_pcap_ng_block(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) flow_id = SWAPLONG(flow_id); } } -#endif /* PCAPNG_EPB_FLOW_ID */ -#ifdef PCAPNG_EPB_TRACE_TAG if (pcap_ng_block_get_option(block, PCAPNG_EPB_TRACE_TAG, &option_info) == 1) { if (option_info.length != 2) { warning("%s: trace_tag option length %u != 2", __func__, option_info.length); @@ -4714,7 +4724,7 @@ print_pcap_ng_block(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) trace_tag = SWAPSHORT(trace_tag); } } -#endif /* PCAPNG_EPB_TRACE_TAG */ + /* * PCAPNG_EPB_DROP_REASON option is set only for droptap. */ @@ -4743,6 +4753,19 @@ print_pcap_ng_block(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) drop_func = (const char *)(option_info.value); drop_func_len = option_info.length; } +#ifdef PCAPNG_EPB_COMP_GENCNT + if (pcap_ng_block_get_option(block, PCAPNG_EPB_COMP_GENCNT, &option_info) == 1) { + if (option_info.length != 4) { + warning("%s: comp_gencnt option length %u != 4", __func__, option_info.length); + goto done; + } + comp_gencnt = *(uint32_t *)(option_info.value); + if (pcap_is_swapped(ndo->ndo_pcap)) { + comp_gencnt = SWAPLONG(comp_gencnt); + } + } +#endif /* PCAPNG_EPB_COMP_GENCNT */ + if_id = epbp->interface_id; pack_flags_code = PCAPNG_EPB_FLAGS; @@ -4897,6 +4920,10 @@ print_pcap_ng_block(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) if (ndo->ndo_packet_number) ND_PRINT("%5lu ", packets_captured - skip_packet_cnt); + if (is_pcap_pkthdr_valid(ndo, h) == 0) { + return; + } + ts_print(ndo, &h->ts); /* @@ -4984,7 +5011,6 @@ print_pcap_ng_block(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) } } -#ifdef PCAPNG_EPB_FLOW_ID /* * Flow-id */ @@ -4994,8 +5020,7 @@ print_pcap_ng_block(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) flow_id); prsep = ", "; } -#endif /* PCAPNG_EPB_FLOW_ID */ -#ifdef PCAPNG_EPB_TRACE_TAG + /* * trace_tag */ @@ -5005,7 +5030,7 @@ print_pcap_ng_block(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) trace_tag); prsep = ", "; } -#endif /* PCAPNG_EPB_TRACE_TAG */ + if (ndo->ndo_kflag & PRMD_DLT) { ND_PRINT("%s" "dlt 0x%x", prsep, @@ -5013,6 +5038,18 @@ print_pcap_ng_block(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) prsep = ", "; } +#ifdef PKTAP_HAS_COMP_GENCNT + /* + * compression generation count + */ + if (ndo->ndo_kflag & PRMD_COMP_GENCNT) { + ND_PRINT("%s" "cmpgc 0x%x", + prsep, + comp_gencnt); + prsep = ", "; + } +#endif /* PKTAP_HAS_COMP_GENCNT */ + /* * Comment */