]> The Tcpdump Group git mirrors - tcpdump/commitdiff
vsock: Update the link-layer dissector to a void function
authorFrancois-Xavier Le Bail <[email protected]>
Sun, 26 Jul 2020 19:19:37 +0000 (21:19 +0200)
committerFrancois-Xavier Le Bail <[email protected]>
Mon, 27 Jul 2020 07:06:59 +0000 (09:06 +0200)
Moreover:
Rename some variables/parameters from 'len' to 'caplen' because
they store the capture length.

netdissect.h
print-vsock.c
print.c

index 56bfb51fccc170fbca13cf14249be44ec983b498..481bebe0d4df8dc3806aa10e17c3b6342f520b3f 100644 (file)
@@ -527,7 +527,7 @@ extern u_int token_if_print IF_PRINTER_ARGS;
 extern void unsupported_if_print IF_PRINTER_ARGS;
 extern void usb_linux_48_byte_if_print IF_PRINTER_ARGS;
 extern void usb_linux_64_byte_if_print IF_PRINTER_ARGS;
-extern u_int vsock_if_print IF_PRINTER_ARGS;
+extern void vsock_if_print IF_PRINTER_ARGS;
 
 /*
  * Structure passed to some printers to allow them to print
index f93e0a2eb5c05e8e8fc2d4df1b74a0268a66d80f..bb18c92b8cefdda4babf9f82318b7eaa210e4eb1 100644 (file)
@@ -165,12 +165,12 @@ vsock_transport_hdr_size(uint16_t transport)
 /* Returns 0 on success, -1 on truncation */
 static int
 vsock_transport_hdr_print(netdissect_options *ndo, uint16_t transport,
-                          const u_char *p, const u_int len)
+                          const u_char *p, const u_int caplen)
 {
        u_int transport_size = vsock_transport_hdr_size(transport);
        const void *hdr;
 
-       if (len < sizeof(struct af_vsockmon_hdr) + transport_size) {
+       if (caplen < sizeof(struct af_vsockmon_hdr) + transport_size) {
                return -1;
        }
 
@@ -188,7 +188,7 @@ vsock_transport_hdr_print(netdissect_options *ndo, uint16_t transport,
 }
 
 static void
-vsock_hdr_print(netdissect_options *ndo, const u_char *p, const u_int len)
+vsock_hdr_print(netdissect_options *ndo, const u_char *p, const u_int caplen)
 {
        const struct af_vsockmon_hdr *hdr = (const struct af_vsockmon_hdr *)p;
        uint16_t hdr_transport, hdr_op;
@@ -204,7 +204,7 @@ vsock_hdr_print(netdissect_options *ndo, const u_char *p, const u_int len)
 
        /* If verbose level is more than 0 print transport details */
        if (ndo->ndo_vflag) {
-               ret = vsock_transport_hdr_print(ndo, hdr_transport, p, len);
+               ret = vsock_transport_hdr_print(ndo, hdr_transport, p, caplen);
                if (ret == 0)
                        ND_PRINT("\n\t");
        } else
@@ -219,7 +219,7 @@ vsock_hdr_print(netdissect_options *ndo, const u_char *p, const u_int len)
                 hdr_src_cid, hdr_src_port,
                 hdr_dst_cid, hdr_dst_port,
                 tok2str(vsock_op, " invalid op (%u)", hdr_op),
-                len);
+                caplen);
 
        if (ret < 0)
                goto trunc;
@@ -229,12 +229,12 @@ vsock_hdr_print(netdissect_options *ndo, const u_char *p, const u_int len)
        total_hdr_size = (u_int)sizeof(struct af_vsockmon_hdr) +
                         vsock_transport_hdr_size(hdr_transport);
        if (ndo->ndo_vflag > 1 && hdr_op == AF_VSOCK_OP_PAYLOAD) {
-               if (len > total_hdr_size) {
+               if (caplen > total_hdr_size) {
                        const u_char *payload = p + total_hdr_size;
 
                        ND_PRINT("\n");
                        print_unknown_data(ndo, payload, "\t",
-                                          len - total_hdr_size);
+                                          caplen - total_hdr_size);
                } else
                        goto trunc;
        }
@@ -244,18 +244,19 @@ trunc:
        nd_print_trunc(ndo);
 }
 
-u_int
+void
 vsock_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h,
               const u_char *cp)
 {
-       u_int len = h->caplen;
+       u_int caplen = h->caplen;
 
        ndo->ndo_protocol = "vsock";
 
-       if (len < sizeof(struct af_vsockmon_hdr))
+       if (caplen < sizeof(struct af_vsockmon_hdr)) {
                nd_print_trunc(ndo);
-       else
-               vsock_hdr_print(ndo, cp, len);
-
-       return len;
+               ndo->ndo_ll_hdr_len += caplen;
+               return;
+       }
+       ndo->ndo_ll_hdr_len += sizeof(struct af_vsockmon_hdr);
+       vsock_hdr_print(ndo, cp, caplen);
 }
diff --git a/print.c b/print.c
index af770ba6621247499ffea55e0f3f5c8cf4b2cf29..b63e6806eac0580da28fa52f0ee446c79edc2524 100644 (file)
--- a/print.c
+++ b/print.c
@@ -173,9 +173,6 @@ static const struct uint_printer uint_printers[] = {
 #endif
 #ifdef DLT_PPP_SERIAL
        { ppp_hdlc_if_print,    DLT_PPP_SERIAL },
-#endif
-#ifdef DLT_VSOCK
-       { vsock_if_print,       DLT_VSOCK },
 #endif
        { NULL,                 0 },
 };
@@ -255,6 +252,9 @@ static const struct void_printer void_printers[] = {
 #ifdef DLT_USB_LINUX_MMAPPED
        { usb_linux_64_byte_if_print, DLT_USB_LINUX_MMAPPED},
 #endif /* DLT_USB_LINUX_MMAPPED */
+#ifdef DLT_VSOCK
+       { vsock_if_print,       DLT_VSOCK },
+#endif
        { NULL,                 0 },
 };