]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-rpki-rtr.c
More UNALIGNED_MEM{CPY,CMP} on IP addresses.
[tcpdump] / print-rpki-rtr.c
index d56028681d5dbb7f4f1415e3c084ae2d904d692b..5e4e453975811c0aab4e5526d47d85eaf2cc52f9 100644 (file)
  * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  * FOR A PARTICULAR PURPOSE.
  *
- * support for the The RPKI/Router Protocol Protocol as per draft-ietf-sidr-rpki-rtr-12
+ * support for the The RPKI/Router Protocol as RFC6810
  *
  * Original code by Hannes Gredler ([email protected])
  */
 
-#ifndef lint
-static const char rcsid[] _U_ =
-"@(#) $Header: /tcpdump/master/tcpdump/print-rpki_rtr.c,v 1.10 2008-03-20 09:30:56 hannes Exp $";
-#endif
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -46,12 +41,11 @@ typedef struct rpki_rtr_pdu_ {
     u_char version;            /* Version number */
     u_char pdu_type;           /* PDU type */
     union {
-       u_char cache_nonce[2];  /* Cache Nonce */
+       u_char session_id[2];   /* Session id */
        u_char error_code[2];   /* Error code */
-    };
+    } u;
     u_char length[4];
-    u_char msg[0];             /* message body */
-} __attribute__((packed)) rpki_rtr_pdu;
+} rpki_rtr_pdu;
 #define RPKI_RTR_PDU_OVERHEAD (offsetof(rpki_rtr_pdu, rpki_rtr_pdu_msg))
 
 /*
@@ -65,7 +59,7 @@ typedef struct rpki_rtr_pdu_ipv4_prefix_ {
     u_char zero;
     u_char prefix[4];
     u_char as[4];
-} __attribute__((packed)) rpki_rtr_pdu_ipv4_prefix;
+} rpki_rtr_pdu_ipv4_prefix;
 
 /*
  * IPv6 Prefix PDU.
@@ -78,7 +72,7 @@ typedef struct rpki_rtr_pdu_ipv6_prefix_ {
     u_char zero;
     u_char prefix[16];
     u_char as[4];
-} __attribute__((packed)) rpki_rtr_pdu_ipv6_prefix;
+} rpki_rtr_pdu_ipv6_prefix;
 
 /*
  * Error report PDU.
@@ -86,8 +80,7 @@ typedef struct rpki_rtr_pdu_ipv6_prefix_ {
 typedef struct rpki_rtr_pdu_error_report_ {
     rpki_rtr_pdu pdu_header;
     u_char encapsulated_pdu_length[4]; /* Encapsulated PDU length */
-    u_char variable[0];
-} __attribute__((packed)) rpki_rtr_pdu_error_report;
+} rpki_rtr_pdu_error_report;
 
 /*
  * PDU type codes
@@ -169,22 +162,23 @@ indent_string (u_int indent)
      * Trailing zero.
      */
     buf[idx] = '\0';
-    
+
     return buf;
 }
 
 /*
  * Print a single PDU.
  */
-static int
+static void
 rpki_rtr_pdu_print (const u_char *tptr, u_int indent)
 {
     const rpki_rtr_pdu *pdu_header;
     u_int pdu_type, pdu_len, hexdump;
+    const u_char *msg;
 
     pdu_header = (rpki_rtr_pdu *)tptr;
     pdu_type = pdu_header->pdu_type;
-    pdu_len = pdu_len = EXTRACT_32BITS(pdu_header->length);
+    pdu_len = EXTRACT_32BITS(pdu_header->length);
     hexdump = FALSE;
 
     printf("%sRPKI-RTRv%u, %s PDU (%u), length: %u",
@@ -201,10 +195,11 @@ rpki_rtr_pdu_print (const u_char *tptr, u_int indent)
     case RPKI_RTR_SERIAL_NOTIFY_PDU:
     case RPKI_RTR_SERIAL_QUERY_PDU:
     case RPKI_RTR_END_OF_DATA_PDU:
-       printf("%sCache-Nonce: 0x%04x, Serial: %u",
+        msg = (const u_char *)(pdu_header + 1);
+       printf("%sSession ID: 0x%04x, Serial: %u",
               indent_string(indent+2),
-              EXTRACT_16BITS(pdu_header->cache_nonce),
-              EXTRACT_32BITS(pdu_header->msg));
+              EXTRACT_16BITS(pdu_header->u.session_id),
+              EXTRACT_32BITS(msg));
        break;
 
        /*
@@ -219,9 +214,9 @@ rpki_rtr_pdu_print (const u_char *tptr, u_int indent)
        break;
 
     case RPKI_RTR_CACHE_RESPONSE_PDU:
-       printf("%sCache-Nonce: 0x%04x",
+       printf("%sSession ID: 0x%04x",
               indent_string(indent+2),
-              EXTRACT_16BITS(pdu_header->cache_nonce));
+              EXTRACT_16BITS(pdu_header->u.session_id));
        break;
 
     case RPKI_RTR_IPV4_PREFIX_PDU:
@@ -262,7 +257,7 @@ rpki_rtr_pdu_print (const u_char *tptr, u_int indent)
            encapsulated_pdu_length = EXTRACT_32BITS(pdu->encapsulated_pdu_length);
            tlen = pdu_len;
 
-           error_code = EXTRACT_16BITS(pdu->pdu_header.error_code);
+           error_code = EXTRACT_16BITS(pdu->pdu_header.u.error_code);
            printf("%sError code: %s (%u), Encapsulated PDU length: %u",
                   indent_string(indent+2),
                   tok2str(rpki_rtr_error_codes, "Unknown", error_code),
@@ -285,7 +280,7 @@ rpki_rtr_pdu_print (const u_char *tptr, u_int indent)
 
            /*
             * Extract, trail-zero and print the Error message.
-            */ 
+            */
            text_length = 0;
            if (tlen > 4) {
                text_length = EXTRACT_32BITS(tptr);
@@ -304,13 +299,13 @@ rpki_rtr_pdu_print (const u_char *tptr, u_int indent)
 
        /*
         * Unknown data, please hexdump.
-        */ 
+        */
        hexdump = TRUE;
     }
 
     /* do we also want to see a hex dump ? */
     if (vflag > 1 || (vflag && hexdump)) {
-       print_unknown_data(tptr,"\n\t  ", pdu_len);
+       print_unknown_data(gndo,tptr,"\n\t  ", pdu_len);
     }
 }
 
@@ -320,7 +315,7 @@ rpki_rtr_print(register const u_char *pptr, register u_int len) {
     u_int tlen, pdu_type, pdu_len;
     const u_char *tptr;
     const rpki_rtr_pdu *pdu_header;
-    
+
     tptr = pptr;
     tlen = len;