From: Denis Ovsienko Date: Fri, 14 Mar 2014 16:05:27 +0000 (+0400) Subject: NDOize DCCP, Linux socket and RPKI-Router decoders X-Git-Tag: tcpdump-4.6.0~175 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/85a2dd977cad3e21b475abbedeb795989207b8db NDOize DCCP, Linux socket and RPKI-Router decoders --- diff --git a/interface.h b/interface.h index 5a46b5cc..686997a0 100644 --- a/interface.h +++ b/interface.h @@ -213,7 +213,6 @@ extern void cisco_autorp_print(const u_char *, u_int); extern void rsvp_print(const u_char *, u_int); extern void ldp_print(const u_char *, u_int); extern void lldp_print(const u_char *, u_int); -extern void rpki_rtr_print(const u_char *, u_int); extern void lmp_print(const u_char *, u_int); extern void lspping_print(const u_char *, u_int); extern void lwapp_control_print(const u_char *, u_int, int); @@ -244,7 +243,6 @@ extern u_int juniper_ether_print(const struct pcap_pkthdr *, const u_char *); extern u_int juniper_ppp_print(const struct pcap_pkthdr *, const u_char *); extern u_int juniper_frelay_print(const struct pcap_pkthdr *, const u_char *); extern u_int juniper_chdlc_print(const struct pcap_pkthdr *, const u_char *); -extern u_int sll_if_print(const struct pcap_pkthdr *, const u_char *); extern void snmp_print(const u_char *, u_int); extern void tcp_print(const u_char *, u_int, const u_char *, int); extern void tftp_print(const u_char *, u_int); @@ -273,7 +271,6 @@ extern void stp_print(const u_char *, u_int); extern void radius_print(const u_char *, u_int); extern void lwres_print(const u_char *, u_int); extern void pptp_print(const u_char *); -extern void dccp_print(const u_char *, const u_char *, u_int); extern void sctp_print(const u_char *, const u_char *, u_int); extern void forces_print(const u_char *, u_int); extern void mpls_lsp_ping_print(const u_char *, u_int); diff --git a/netdissect.h b/netdissect.h index 50780f2d..f64961dc 100644 --- a/netdissect.h +++ b/netdissect.h @@ -417,6 +417,9 @@ extern void zephyr_print(netdissect_options *, const u_char *, int); extern void fddi_print(netdissect_options *, const u_char *, u_int, u_int); extern u_int fddi_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern void mpcp_print(netdissect_options *, const u_char *, u_int); +extern void rpki_rtr_print(netdissect_options *, const u_char *, u_int); +extern u_int sll_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); +extern void dccp_print(netdissect_options *, const u_char *, const u_char *, u_int); /* stuff that has not yet been rototiled */ extern const u_char * ns_nprint (register const u_char *, register const u_char *); @@ -487,7 +490,6 @@ extern void ppp_bsdos_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); extern void rip_print(netdissect_options *,const u_char *, u_int); -extern void rpki_rtr_print(netdissect_options *,const u_char *, u_int); extern void sctp_print(netdissect_options *ndo, const u_char *bp, const u_char *bp2, diff --git a/print-dccp.c b/print-dccp.c index 3d996fb7..f0f67152 100644 --- a/print-dccp.c +++ b/print-dccp.c @@ -224,26 +224,26 @@ static inline unsigned int dccp_basic_hdr_len(const struct dccp_hdr *dh) return DCCPH_X(dh) ? sizeof(struct dccp_hdr_ext) : sizeof(struct dccp_hdr); } -static void dccp_print_ack_no(const u_char *bp) +static void dccp_print_ack_no(netdissect_options *ndo, const u_char *bp) { const struct dccp_hdr *dh = (const struct dccp_hdr *)bp; const u_char *ackp = bp + dccp_basic_hdr_len(dh); u_int64_t ackno; if (DCCPH_X(dh) != 0) { - TCHECK2(*ackp, 8); + ND_TCHECK2(*ackp, 8); ackno = EXTRACT_48BITS(ackp + 2); } else { - TCHECK2(*ackp, 4); + ND_TCHECK2(*ackp, 4); ackno = EXTRACT_24BITS(ackp + 1); } - (void)printf("(ack=%" PRIu64 ") ", ackno); + ND_PRINT((ndo, "(ack=%" PRIu64 ") ", ackno)); trunc: return; } -static int dccp_print_option(const u_char *option, u_int hlen); +static int dccp_print_option(netdissect_options *, const u_char *, u_int); /** * dccp_print - show dccp packet @@ -251,7 +251,8 @@ static int dccp_print_option(const u_char *option, u_int hlen); * @data2 - beginning of enclosing * @len - lenght of ip packet */ -void dccp_print(const u_char *bp, const u_char *data2, u_int len) +void dccp_print(netdissect_options *ndo, const u_char *bp, const u_char *data2, + u_int len) { const struct dccp_hdr *dh; const struct ip *ip; @@ -275,24 +276,24 @@ void dccp_print(const u_char *bp, const u_char *data2, u_int len) /* make sure we have enough data to look at the X bit */ cp = (const u_char *)(dh + 1); - if (cp > snapend) { - printf("[Invalid packet|dccp]"); + if (cp > ndo->ndo_snapend) { + ND_PRINT((ndo, "[Invalid packet|dccp]")); return; } if (len < sizeof(struct dccp_hdr)) { - printf("truncated-dccp - %u bytes missing!", - len - (u_int)sizeof(struct dccp_hdr)); + ND_PRINT((ndo, "truncated-dccp - %u bytes missing!", + len - (u_int)sizeof(struct dccp_hdr))); return; } /* get the length of the generic header */ fixed_hdrlen = dccp_basic_hdr_len(dh); if (len < fixed_hdrlen) { - printf("truncated-dccp - %u bytes missing!", - len - fixed_hdrlen); + ND_PRINT((ndo, "truncated-dccp - %u bytes missing!", + len - fixed_hdrlen)); return; } - TCHECK2(*dh, fixed_hdrlen); + ND_TCHECK2(*dh, fixed_hdrlen); sport = EXTRACT_16BITS(&dh->dccph_sport); dport = EXTRACT_16BITS(&dh->dccph_dport); @@ -300,38 +301,38 @@ void dccp_print(const u_char *bp, const u_char *data2, u_int len) #ifdef INET6 if (ip6) { - (void)printf("%s.%d > %s.%d: ", + ND_PRINT((ndo, "%s.%d > %s.%d: ", ip6addr_string(&ip6->ip6_src), sport, - ip6addr_string(&ip6->ip6_dst), dport); + ip6addr_string(&ip6->ip6_dst), dport)); } else #endif /*INET6*/ { - (void)printf("%s.%d > %s.%d: ", + ND_PRINT((ndo, "%s.%d > %s.%d: ", ipaddr_string(&ip->ip_src), sport, - ipaddr_string(&ip->ip_dst), dport); + ipaddr_string(&ip->ip_dst), dport)); } fflush(stdout); - if (qflag) { - (void)printf(" %d", len - hlen); + if (ndo->ndo_qflag) { + ND_PRINT((ndo, " %d", len - hlen)); if (hlen > len) { - (void)printf("dccp [bad hdr length %u - too long, > %u]", - hlen, len); + ND_PRINT((ndo, "dccp [bad hdr length %u - too long, > %u]", + hlen, len)); } return; } /* other variables in generic header */ - if (vflag) { - (void)printf("CCVal %d, CsCov %d, ", DCCPH_CCVAL(dh), DCCPH_CSCOV(dh)); + if (ndo->ndo_vflag) { + ND_PRINT((ndo, "CCVal %d, CsCov %d, ", DCCPH_CCVAL(dh), DCCPH_CSCOV(dh))); } /* checksum calculation */ - if (vflag && TTEST2(bp[0], len)) { + if (ndo->ndo_vflag && ND_TTEST2(bp[0], len)) { u_int16_t sum = 0, dccp_sum; dccp_sum = EXTRACT_16BITS(&dh->dccph_checksum); - (void)printf("cksum 0x%04x ", dccp_sum); + ND_PRINT((ndo, "cksum 0x%04x ", dccp_sum)); if (IP_V(ip) == 4) sum = dccp_cksum(ip, dh, len); #ifdef INET6 @@ -339,9 +340,9 @@ void dccp_print(const u_char *bp, const u_char *data2, u_int len) sum = dccp6_cksum(ip6, dh, len); #endif if (sum != 0) - (void)printf("(incorrect -> 0x%04x), ",in_cksum_shouldbe(dccp_sum, sum)); + ND_PRINT((ndo, "(incorrect -> 0x%04x), ",in_cksum_shouldbe(dccp_sum, sum))); else - (void)printf("(correct), "); + ND_PRINT((ndo, "(correct), ")); } switch (DCCPH_TYPE(dh)) { @@ -350,13 +351,13 @@ void dccp_print(const u_char *bp, const u_char *data2, u_int len) (struct dccp_hdr_request *)(bp + fixed_hdrlen); fixed_hdrlen += 4; if (len < fixed_hdrlen) { - printf("truncated-dccp request - %u bytes missing!", - len - fixed_hdrlen); + ND_PRINT((ndo, "truncated-dccp request - %u bytes missing!", + len - fixed_hdrlen)); return; } - TCHECK(*dhr); - (void)printf("request (service=%d) ", - EXTRACT_32BITS(&dhr->dccph_req_service)); + ND_TCHECK(*dhr); + ND_PRINT((ndo, "request (service=%d) ", + EXTRACT_32BITS(&dhr->dccph_req_service))); break; } case DCCP_PKT_RESPONSE: { @@ -364,125 +365,125 @@ void dccp_print(const u_char *bp, const u_char *data2, u_int len) (struct dccp_hdr_response *)(bp + fixed_hdrlen); fixed_hdrlen += 12; if (len < fixed_hdrlen) { - printf("truncated-dccp response - %u bytes missing!", - len - fixed_hdrlen); + ND_PRINT((ndo, "truncated-dccp response - %u bytes missing!", + len - fixed_hdrlen)); return; } - TCHECK(*dhr); - (void)printf("response (service=%d) ", - EXTRACT_32BITS(&dhr->dccph_resp_service)); + ND_TCHECK(*dhr); + ND_PRINT((ndo, "response (service=%d) ", + EXTRACT_32BITS(&dhr->dccph_resp_service))); break; } case DCCP_PKT_DATA: - (void)printf("data "); + ND_PRINT((ndo, "data ")); break; case DCCP_PKT_ACK: { fixed_hdrlen += 8; if (len < fixed_hdrlen) { - printf("truncated-dccp ack - %u bytes missing!", - len - fixed_hdrlen); + ND_PRINT((ndo, "truncated-dccp ack - %u bytes missing!", + len - fixed_hdrlen)); return; } - (void)printf("ack "); + ND_PRINT((ndo, "ack ")); break; } case DCCP_PKT_DATAACK: { fixed_hdrlen += 8; if (len < fixed_hdrlen) { - printf("truncated-dccp dataack - %u bytes missing!", - len - fixed_hdrlen); + ND_PRINT((ndo, "truncated-dccp dataack - %u bytes missing!", + len - fixed_hdrlen)); return; } - (void)printf("dataack "); + ND_PRINT((ndo, "dataack ")); break; } case DCCP_PKT_CLOSEREQ: fixed_hdrlen += 8; if (len < fixed_hdrlen) { - printf("truncated-dccp closereq - %u bytes missing!", - len - fixed_hdrlen); + ND_PRINT((ndo, "truncated-dccp closereq - %u bytes missing!", + len - fixed_hdrlen)); return; } - (void)printf("closereq "); + ND_PRINT((ndo, "closereq ")); break; case DCCP_PKT_CLOSE: fixed_hdrlen += 8; if (len < fixed_hdrlen) { - printf("truncated-dccp close - %u bytes missing!", - len - fixed_hdrlen); + ND_PRINT((ndo, "truncated-dccp close - %u bytes missing!", + len - fixed_hdrlen)); return; } - (void)printf("close "); + ND_PRINT((ndo, "close ")); break; case DCCP_PKT_RESET: { struct dccp_hdr_reset *dhr = (struct dccp_hdr_reset *)(bp + fixed_hdrlen); fixed_hdrlen += 12; if (len < fixed_hdrlen) { - printf("truncated-dccp reset - %u bytes missing!", - len - fixed_hdrlen); + ND_PRINT((ndo, "truncated-dccp reset - %u bytes missing!", + len - fixed_hdrlen)); return; } - TCHECK(*dhr); - (void)printf("reset (code=%s) ", - dccp_reset_code(dhr->dccph_reset_code)); + ND_TCHECK(*dhr); + ND_PRINT((ndo, "reset (code=%s) ", + dccp_reset_code(dhr->dccph_reset_code))); break; } case DCCP_PKT_SYNC: fixed_hdrlen += 8; if (len < fixed_hdrlen) { - printf("truncated-dccp sync - %u bytes missing!", - len - fixed_hdrlen); + ND_PRINT((ndo, "truncated-dccp sync - %u bytes missing!", + len - fixed_hdrlen)); return; } - (void)printf("sync "); + ND_PRINT((ndo, "sync ")); break; case DCCP_PKT_SYNCACK: fixed_hdrlen += 8; if (len < fixed_hdrlen) { - printf("truncated-dccp syncack - %u bytes missing!", - len - fixed_hdrlen); + ND_PRINT((ndo, "truncated-dccp syncack - %u bytes missing!", + len - fixed_hdrlen)); return; } - (void)printf("syncack "); + ND_PRINT((ndo, "syncack ")); break; default: - (void)printf("invalid "); + ND_PRINT((ndo, "invalid ")); break; } if ((DCCPH_TYPE(dh) != DCCP_PKT_DATA) && (DCCPH_TYPE(dh) != DCCP_PKT_REQUEST)) - dccp_print_ack_no(bp); + dccp_print_ack_no(ndo, bp); - if (vflag < 2) + if (ndo->ndo_vflag < 2) return; - (void)printf("seq %" PRIu64, dccp_seqno(bp)); + ND_PRINT((ndo, "seq %" PRIu64, dccp_seqno(bp))); /* process options */ if (hlen > fixed_hdrlen){ const u_char *cp; u_int optlen; cp = bp + fixed_hdrlen; - printf(" <"); + ND_PRINT((ndo, " <")); hlen -= fixed_hdrlen; while(1){ - optlen = dccp_print_option(cp, hlen); + optlen = dccp_print_option(ndo, cp, hlen); if (!optlen) break; if (hlen <= optlen) break; hlen -= optlen; cp += optlen; - printf(", "); + ND_PRINT((ndo, ", ")); } - printf(">"); + ND_PRINT((ndo, ">")); } return; trunc: - printf("%s", tstr); + ND_PRINT((ndo, "%s", tstr)); return; } @@ -506,21 +507,21 @@ static const struct tok dccp_option_values[] = { { 0, NULL } }; -static int dccp_print_option(const u_char *option, u_int hlen) +static int dccp_print_option(netdissect_options *ndo, const u_char *option, u_int hlen) { u_int8_t optlen, i; - TCHECK(*option); + ND_TCHECK(*option); if (*option >= 32) { - TCHECK(*(option+1)); + ND_TCHECK(*(option+1)); optlen = *(option +1); if (optlen < 2) { if (*option >= 128) - printf("CCID option %u optlen too short", *option); + ND_PRINT((ndo, "CCID option %u optlen too short", *option)); else - printf("%s optlen too short", - tok2str(dccp_option_values, "Option %u", *option)); + ND_PRINT((ndo, "%s optlen too short", + tok2str(dccp_option_values, "Option %u", *option))); return 0; } } else @@ -528,101 +529,101 @@ static int dccp_print_option(const u_char *option, u_int hlen) if (hlen < optlen) { if (*option >= 128) - printf("CCID option %u optlen goes past header length", - *option); + ND_PRINT((ndo, "CCID option %u optlen goes past header length", + *option)); else - printf("%s optlen goes past header length", - tok2str(dccp_option_values, "Option %u", *option)); + ND_PRINT((ndo, "%s optlen goes past header length", + tok2str(dccp_option_values, "Option %u", *option))); return 0; } - TCHECK2(*option, optlen); + ND_TCHECK2(*option, optlen); if (*option >= 128) { - printf("CCID option %d", *option); + ND_PRINT((ndo, "CCID option %d", *option)); switch (optlen) { case 4: - printf(" %u", EXTRACT_16BITS(option + 2)); + ND_PRINT((ndo, " %u", EXTRACT_16BITS(option + 2))); break; case 6: - printf(" %u", EXTRACT_32BITS(option + 2)); + ND_PRINT((ndo, " %u", EXTRACT_32BITS(option + 2))); break; default: break; } } else { - printf("%s", tok2str(dccp_option_values, "Option %u", *option)); + ND_PRINT((ndo, "%s", tok2str(dccp_option_values, "Option %u", *option))); switch (*option) { case 32: case 33: case 34: case 35: if (optlen < 3) { - printf(" optlen too short"); + ND_PRINT((ndo, " optlen too short")); return optlen; } if (*(option + 2) < 10){ - printf(" %s", dccp_feature_nums[*(option + 2)]); + ND_PRINT((ndo, " %s", dccp_feature_nums[*(option + 2)])); for (i = 0; i < optlen - 3; i++) - printf(" %d", *(option + 3 + i)); + ND_PRINT((ndo, " %d", *(option + 3 + i))); } break; case 36: if (optlen > 2) { - printf(" 0x"); + ND_PRINT((ndo, " 0x")); for (i = 0; i < optlen - 2; i++) - printf("%02x", *(option + 2 + i)); + ND_PRINT((ndo, "%02x", *(option + 2 + i))); } break; case 37: for (i = 0; i < optlen - 2; i++) - printf(" %d", *(option + 2 + i)); + ND_PRINT((ndo, " %d", *(option + 2 + i))); break; case 38: if (optlen > 2) { - printf(" 0x"); + ND_PRINT((ndo, " 0x")); for (i = 0; i < optlen - 2; i++) - printf("%02x", *(option + 2 + i)); + ND_PRINT((ndo, "%02x", *(option + 2 + i))); } break; case 39: if (optlen > 2) { - printf(" 0x"); + ND_PRINT((ndo, " 0x")); for (i = 0; i < optlen - 2; i++) - printf("%02x", *(option + 2 + i)); + ND_PRINT((ndo, "%02x", *(option + 2 + i))); } break; case 40: if (optlen > 2) { - printf(" 0x"); + ND_PRINT((ndo, " 0x")); for (i = 0; i < optlen - 2; i++) - printf("%02x", *(option + 2 + i)); + ND_PRINT((ndo, "%02x", *(option + 2 + i))); } break; case 41: if (optlen == 4) - printf(" %u", EXTRACT_32BITS(option + 2)); + ND_PRINT((ndo, " %u", EXTRACT_32BITS(option + 2))); else - printf(" optlen != 4"); + ND_PRINT((ndo, " optlen != 4")); break; case 42: if (optlen == 4) - printf(" %u", EXTRACT_32BITS(option + 2)); + ND_PRINT((ndo, " %u", EXTRACT_32BITS(option + 2))); else - printf(" optlen != 4"); + ND_PRINT((ndo, " optlen != 4")); break; case 43: if (optlen == 6) - printf(" %u", EXTRACT_32BITS(option + 2)); + ND_PRINT((ndo, " %u", EXTRACT_32BITS(option + 2))); else if (optlen == 4) - printf(" %u", EXTRACT_16BITS(option + 2)); + ND_PRINT((ndo, " %u", EXTRACT_16BITS(option + 2))); else - printf(" optlen != 4 or 6"); + ND_PRINT((ndo, " optlen != 4 or 6")); break; case 44: if (optlen > 2) { - printf(" "); + ND_PRINT((ndo, " ")); for (i = 0; i < optlen - 2; i++) - printf("%02x", *(option + 2 + i)); + ND_PRINT((ndo, "%02x", *(option + 2 + i))); } break; } @@ -630,6 +631,6 @@ static int dccp_print_option(const u_char *option, u_int hlen) return optlen; trunc: - printf("%s", tstr); + ND_PRINT((ndo, "%s", tstr)); return 0; } diff --git a/print-ip.c b/print-ip.c index 977f50fa..2970c126 100644 --- a/print-ip.c +++ b/print-ip.c @@ -365,7 +365,7 @@ again: break; case IPPROTO_DCCP: - dccp_print(ipds->cp, (const u_char *)ipds->ip, ipds->len); + dccp_print(ndo, ipds->cp, (const u_char *)ipds->ip, ipds->len); break; case IPPROTO_TCP: diff --git a/print-ip6.c b/print-ip6.c index 946971a3..04584361 100644 --- a/print-ip6.c +++ b/print-ip6.c @@ -191,7 +191,7 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length) sctp_print(cp, (const u_char *)ip6, len); return; case IPPROTO_DCCP: - dccp_print(cp, (const u_char *)ip6, len); + dccp_print(ndo, cp, (const u_char *)ip6, len); return; case IPPROTO_TCP: tcp_print(cp, len, (const u_char *)ip6, fragmented); diff --git a/print-rpki-rtr.c b/print-rpki-rtr.c index 5e4e4539..fa7adac5 100644 --- a/print-rpki-rtr.c +++ b/print-rpki-rtr.c @@ -23,11 +23,9 @@ #include -#include -#include #include -#include "interface.h" +#include "netdissect.h" #include "extract.h" #include "addrtoname.h" @@ -170,7 +168,7 @@ indent_string (u_int indent) * Print a single PDU. */ static void -rpki_rtr_pdu_print (const u_char *tptr, u_int indent) +rpki_rtr_pdu_print (netdissect_options *ndo, const u_char *tptr, u_int indent) { const rpki_rtr_pdu *pdu_header; u_int pdu_type, pdu_len, hexdump; @@ -181,11 +179,11 @@ rpki_rtr_pdu_print (const u_char *tptr, u_int indent) pdu_len = EXTRACT_32BITS(pdu_header->length); hexdump = FALSE; - printf("%sRPKI-RTRv%u, %s PDU (%u), length: %u", + ND_PRINT((ndo, "%sRPKI-RTRv%u, %s PDU (%u), length: %u", indent_string(8), pdu_header->version, tok2str(rpki_rtr_pdu_values, "Unknown", pdu_type), - pdu_type, pdu_len); + pdu_type, pdu_len)); switch (pdu_type) { @@ -196,10 +194,10 @@ rpki_rtr_pdu_print (const u_char *tptr, u_int indent) case RPKI_RTR_SERIAL_QUERY_PDU: case RPKI_RTR_END_OF_DATA_PDU: msg = (const u_char *)(pdu_header + 1); - printf("%sSession ID: 0x%04x, Serial: %u", + ND_PRINT((ndo, "%sSession ID: 0x%04x, Serial: %u", indent_string(indent+2), EXTRACT_16BITS(pdu_header->u.session_id), - EXTRACT_32BITS(msg)); + EXTRACT_32BITS(msg))); break; /* @@ -214,9 +212,9 @@ rpki_rtr_pdu_print (const u_char *tptr, u_int indent) break; case RPKI_RTR_CACHE_RESPONSE_PDU: - printf("%sSession ID: 0x%04x", + ND_PRINT((ndo, "%sSession ID: 0x%04x", indent_string(indent+2), - EXTRACT_16BITS(pdu_header->u.session_id)); + EXTRACT_16BITS(pdu_header->u.session_id))); break; case RPKI_RTR_IPV4_PREFIX_PDU: @@ -224,11 +222,11 @@ rpki_rtr_pdu_print (const u_char *tptr, u_int indent) rpki_rtr_pdu_ipv4_prefix *pdu; pdu = (rpki_rtr_pdu_ipv4_prefix *)tptr; - printf("%sIPv4 Prefix %s/%u-%u, origin-as %u, flags 0x%02x", + ND_PRINT((ndo, "%sIPv4 Prefix %s/%u-%u, origin-as %u, flags 0x%02x", indent_string(indent+2), ipaddr_string(pdu->prefix), pdu->prefix_length, pdu->max_length, - EXTRACT_32BITS(pdu->as), pdu->flags); + EXTRACT_32BITS(pdu->as), pdu->flags)); } break; @@ -238,11 +236,11 @@ rpki_rtr_pdu_print (const u_char *tptr, u_int indent) rpki_rtr_pdu_ipv6_prefix *pdu; pdu = (rpki_rtr_pdu_ipv6_prefix *)tptr; - printf("%sIPv6 Prefix %s/%u-%u, origin-as %u, flags 0x%02x", + ND_PRINT((ndo, "%sIPv6 Prefix %s/%u-%u, origin-as %u, flags 0x%02x", indent_string(indent+2), ip6addr_string(pdu->prefix), pdu->prefix_length, pdu->max_length, - EXTRACT_32BITS(pdu->as), pdu->flags); + EXTRACT_32BITS(pdu->as), pdu->flags)); } break; #endif @@ -258,10 +256,10 @@ rpki_rtr_pdu_print (const u_char *tptr, u_int indent) tlen = pdu_len; error_code = EXTRACT_16BITS(pdu->pdu_header.u.error_code); - printf("%sError code: %s (%u), Encapsulated PDU length: %u", + ND_PRINT((ndo, "%sError code: %s (%u), Encapsulated PDU length: %u", indent_string(indent+2), tok2str(rpki_rtr_error_codes, "Unknown", error_code), - error_code, encapsulated_pdu_length); + error_code, encapsulated_pdu_length)); tptr += sizeof(*pdu); tlen -= sizeof(*pdu); @@ -271,8 +269,8 @@ rpki_rtr_pdu_print (const u_char *tptr, u_int indent) */ if (encapsulated_pdu_length && (encapsulated_pdu_length <= tlen)) { - printf("%s-----encapsulated PDU-----", indent_string(indent+4)); - rpki_rtr_pdu_print(tptr, indent+2); + ND_PRINT((ndo, "%s-----encapsulated PDU-----", indent_string(indent+4))); + rpki_rtr_pdu_print(ndo, tptr, indent+2); } tptr += encapsulated_pdu_length; @@ -290,7 +288,7 @@ rpki_rtr_pdu_print (const u_char *tptr, u_int indent) if (text_length && (text_length <= tlen )) { memcpy(buf, tptr, MIN(sizeof(buf)-1, text_length)); buf[text_length] = '\0'; - printf("%sError text: %s", indent_string(indent+2), buf); + ND_PRINT((ndo, "%sError text: %s", indent_string(indent+2), buf)); } } break; @@ -304,13 +302,13 @@ rpki_rtr_pdu_print (const u_char *tptr, u_int indent) } /* do we also want to see a hex dump ? */ - if (vflag > 1 || (vflag && hexdump)) { - print_unknown_data(gndo,tptr,"\n\t ", pdu_len); + if (ndo->ndo_vflag > 1 || (ndo->ndo_vflag && hexdump)) { + print_unknown_data(ndo,tptr,"\n\t ", pdu_len); } } void -rpki_rtr_print(register const u_char *pptr, register u_int len) { +rpki_rtr_print(netdissect_options *ndo, register const u_char *pptr, register u_int len) { u_int tlen, pdu_type, pdu_len; const u_char *tptr; @@ -319,14 +317,14 @@ rpki_rtr_print(register const u_char *pptr, register u_int len) { tptr = pptr; tlen = len; - if (!vflag) { - printf(", RPKI-RTR"); + if (!ndo->ndo_vflag) { + ND_PRINT((ndo, ", RPKI-RTR")); return; } while (tlen >= sizeof(rpki_rtr_pdu)) { - TCHECK2(*tptr, sizeof(rpki_rtr_pdu)); + ND_TCHECK2(*tptr, sizeof(rpki_rtr_pdu)); pdu_header = (rpki_rtr_pdu *)tptr; pdu_type = pdu_header->pdu_type; @@ -337,7 +335,7 @@ rpki_rtr_print(register const u_char *pptr, register u_int len) { break; } - TCHECK2(*tptr, pdu_len); + ND_TCHECK2(*tptr, pdu_len); if (tlen < pdu_len) { goto trunc; } @@ -345,14 +343,14 @@ rpki_rtr_print(register const u_char *pptr, register u_int len) { /* * Print the PDU. */ - rpki_rtr_pdu_print(tptr, 8); + rpki_rtr_pdu_print(ndo, tptr, 8); tlen -= pdu_len; tptr += pdu_len; } return; trunc: - printf("\n\t[|RPKI-RTR]"); + ND_PRINT((ndo, "\n\t[|RPKI-RTR]")); } /* diff --git a/print-sll.c b/print-sll.c index 9818e2ee..878bb796 100644 --- a/print-sll.c +++ b/print-sll.c @@ -25,9 +25,6 @@ #include -#include -#include - #include "interface.h" #include "addrtoname.h" #include "ethertype.h" @@ -133,11 +130,11 @@ static const struct tok sll_pkttype_values[] = { }; static inline void -sll_print(register const struct sll_header *sllp, u_int length) +sll_print(netdissect_options *ndo, register const struct sll_header *sllp, u_int length) { u_short ether_type; - printf("%3s ",tok2str(sll_pkttype_values,"?",EXTRACT_16BITS(&sllp->sll_pkttype))); + ND_PRINT((ndo, "%3s ",tok2str(sll_pkttype_values,"?",EXTRACT_16BITS(&sllp->sll_pkttype)))); /* * XXX - check the link-layer address type value? @@ -145,9 +142,9 @@ sll_print(register const struct sll_header *sllp, u_int length) * XXX - print others as strings of hex? */ if (EXTRACT_16BITS(&sllp->sll_halen) == 6) - (void)printf("%s ", etheraddr_string(sllp->sll_addr)); + ND_PRINT((ndo, "%s ", etheraddr_string(sllp->sll_addr))); - if (!qflag) { + if (!ndo->ndo_qflag) { ether_type = EXTRACT_16BITS(&sllp->sll_protocol); if (ether_type <= ETHERMTU) { @@ -160,30 +157,30 @@ sll_print(register const struct sll_header *sllp, u_int length) /* * Ethernet_802.3 IPX frame. */ - (void)printf("802.3"); + ND_PRINT((ndo, "802.3")); break; case LINUX_SLL_P_802_2: /* * 802.2. */ - (void)printf("802.2"); + ND_PRINT((ndo, "802.2")); break; default: /* * What is it? */ - (void)printf("ethertype Unknown (0x%04x)", - ether_type); + ND_PRINT((ndo, "ethertype Unknown (0x%04x)", + ether_type)); break; } } else { - (void)printf("ethertype %s (0x%04x)", + ND_PRINT((ndo, "ethertype %s (0x%04x)", tok2str(ethertype_values, "Unknown", ether_type), - ether_type); + ether_type)); } - (void)printf(", length %u: ", length); + ND_PRINT((ndo, ", length %u: ", length)); } } @@ -194,7 +191,7 @@ sll_print(register const struct sll_header *sllp, u_int length) * is the number of bytes actually captured. */ u_int -sll_if_print(const struct pcap_pkthdr *h, const u_char *p) +sll_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) { u_int caplen = h->caplen; u_int length = h->len; @@ -208,14 +205,14 @@ sll_if_print(const struct pcap_pkthdr *h, const u_char *p) * adds this many bytes of header to every packet in a * cooked socket capture. */ - printf("[|sll]"); + ND_PRINT((ndo, "[|sll]")); return (caplen); } sllp = (const struct sll_header *)p; - if (eflag) - sll_print(sllp, length); + if (ndo->ndo_eflag) + sll_print(ndo, sllp, length); /* * Go past the cooked-mode header. @@ -241,7 +238,7 @@ recurse: /* * Ethernet_802.3 IPX frame. */ - ipx_print(gndo, p, length); + ipx_print(ndo, p, length); break; case LINUX_SLL_P_802_2: @@ -260,14 +257,14 @@ recurse: unknown: /* ether_type not known, print raw packet */ - if (!eflag) - sll_print(sllp, length + SLL_HDR_LEN); + if (!ndo->ndo_eflag) + sll_print(ndo, sllp, length + SLL_HDR_LEN); if (extracted_ethertype) { - printf("(LLC %s) ", - etherproto_string(htons(extracted_ethertype))); + ND_PRINT((ndo, "(LLC %s) ", + etherproto_string(htons(extracted_ethertype)))); } - if (!suppress_default_print) - default_print(p, caplen); + if (!ndo->ndo_suppress_default_print) + ndo->ndo_default_print(ndo, p, caplen); break; } } else if (ether_type == ETHERTYPE_8021Q) { @@ -276,36 +273,36 @@ recurse: * the enclosed type field. */ if (caplen < 4 || length < 4) { - printf("[|vlan]"); + ND_PRINT((ndo, "[|vlan]")); return (SLL_HDR_LEN); } - if (eflag) { + if (ndo->ndo_eflag) { u_int16_t tag = EXTRACT_16BITS(p); - printf("vlan %u, p %u%s, ", + ND_PRINT((ndo, "vlan %u, p %u%s, ", tag & 0xfff, tag >> 13, - (tag & 0x1000) ? ", CFI" : ""); + (tag & 0x1000) ? ", CFI" : "")); } ether_type = EXTRACT_16BITS(p + 2); if (ether_type <= ETHERMTU) ether_type = LINUX_SLL_P_802_2; - if (!qflag) { - (void)printf("ethertype %s, ", - tok2str(ethertype_values, "Unknown", ether_type)); + if (!ndo->ndo_qflag) { + ND_PRINT((ndo, "ethertype %s, ", + tok2str(ethertype_values, "Unknown", ether_type))); } p += 4; length -= 4; caplen -= 4; goto recurse; } else { - if (ethertype_print(gndo, ether_type, p, length, caplen) == 0) { + if (ethertype_print(ndo, ether_type, p, length, caplen) == 0) { /* ether_type not known, print raw packet */ - if (!eflag) - sll_print(sllp, length + SLL_HDR_LEN); - if (!suppress_default_print) - default_print(p, caplen); + if (!ndo->ndo_eflag) + sll_print(ndo, sllp, length + SLL_HDR_LEN); + if (!ndo->ndo_suppress_default_print) + ndo->ndo_default_print(ndo, p, caplen); } } diff --git a/print-tcp.c b/print-tcp.c index 27620d66..ef6bb517 100644 --- a/print-tcp.c +++ b/print-tcp.c @@ -697,7 +697,7 @@ tcp_print(register const u_char *bp, register u_int length, } else if (sport == MSDP_PORT || dport == MSDP_PORT) { msdp_print(gndo, bp, length); } else if (sport == RPKI_RTR_PORT || dport == RPKI_RTR_PORT) { - rpki_rtr_print(bp, length); + rpki_rtr_print(gndo, bp, length); } else if (length > 0 && (sport == LDP_PORT || dport == LDP_PORT)) { ldp_print(bp, length); diff --git a/tcpdump.c b/tcpdump.c index 37c76e2a..6809d005 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -182,9 +182,6 @@ static const struct printer printers[] = { #ifdef DLT_PPP_SERIAL { ppp_hdlc_if_print, DLT_PPP_SERIAL }, #endif -#ifdef DLT_LINUX_SLL - { sll_if_print, DLT_LINUX_SLL }, -#endif #ifdef DLT_IEEE802_11 { ieee802_11_if_print, DLT_IEEE802_11}, #endif @@ -344,6 +341,9 @@ static const struct ndo_printer ndo_printers[] = { #endif { token_if_print, DLT_IEEE802 }, { fddi_if_print, DLT_FDDI }, +#ifdef DLT_LINUX_SLL + { sll_if_print, DLT_LINUX_SLL }, +#endif { NULL, 0 }, };