]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-bootp.c
DHCP: Fix a comment about formats for (un)signed longs/shorts data
[tcpdump] / print-bootp.c
index 1ee979f5d2e02ff05c31d07c5c1a070cf59efeb9..d84ba6f8b48f8cc6fea36eeceb13733c20eefb57 100644 (file)
@@ -21,9 +21,7 @@
 
 /* \summary: BOOTP and IPv4 DHCP printer */
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #include "netdissect-stdinc.h"
 
@@ -147,7 +145,7 @@ struct bootp {
 #define        TAG_NIS_P_DOMAIN        ((uint8_t)  64)
 #define        TAG_NIS_P_SERVERS       ((uint8_t)  65)
 #define        TAG_MOBILE_HOME         ((uint8_t)  68)
-#define        TAG_SMPT_SERVER         ((uint8_t)  69)
+#define        TAG_SMTP_SERVER         ((uint8_t)  69)
 #define        TAG_POP3_SERVER         ((uint8_t)  70)
 #define        TAG_NNTP_SERVER         ((uint8_t)  71)
 #define        TAG_WWW_SERVER          ((uint8_t)  72)
@@ -193,9 +191,11 @@ struct bootp {
 /* RFC 3442 */
 #define TAG_CLASSLESS_STATIC_RT        ((uint8_t) 121)
 #define TAG_CLASSLESS_STA_RT_MS        ((uint8_t) 249)
+/* RFC8572 */
+#define TAG_SZTP_REDIRECT      ((uint8_t) 143)
 /* RFC 5859 - TFTP Server Address Option for DHCPv4 */
 #define        TAG_TFTP_SERVER_ADDRESS ((uint8_t) 150)
-/* ftp://ftp.isi.edu/.../assignments/bootp-dhcp-extensions */
+/* https://www.iana.org/assignments/bootp-dhcp-parameters/bootp-dhcp-parameters.xhtml */
 #define        TAG_SLP_NAMING_AUTH     ((uint8_t)  80)
 #define        TAG_CLIENT_FQDN         ((uint8_t)  81)
 #define        TAG_AGENT_CIRCUIT       ((uint8_t)  82)
@@ -203,15 +203,15 @@ struct bootp {
 #define        TAG_TZ_STRING           ((uint8_t)  88)
 #define        TAG_FQDN_OPTION         ((uint8_t)  89)
 #define        TAG_AUTH                ((uint8_t)  90)
-#define        TAG_VINES_SERVERS       ((uint8_t)  91)
-#define        TAG_SERVER_RANK         ((uint8_t)  92)
+#define        TAG_CLIENT_LAST_TRANSACTION_TIME        ((uint8_t)  91)
+#define        TAG_ASSOCIATED_IP                       ((uint8_t)  92)
 #define        TAG_CLIENT_ARCH         ((uint8_t)  93)
 #define        TAG_CLIENT_NDI          ((uint8_t)  94)
 #define        TAG_CLIENT_GUID         ((uint8_t)  97)
 #define        TAG_LDAP_URL            ((uint8_t)  95)
 /* RFC 4833, TZ codes */
-#define        TAG_TZ_PCODE            ((uint8_t) 100)
-#define        TAG_TZ_TCODE            ((uint8_t) 101)
+#define        TAG_TZ_PCODE            ((uint8_t) 100)
+#define        TAG_TZ_TCODE            ((uint8_t) 101)
 #define        TAG_NETINFO_PARENT      ((uint8_t) 112)
 #define        TAG_NETINFO_PARENT_TAG  ((uint8_t) 113)
 #define        TAG_URL                 ((uint8_t) 114)
@@ -226,6 +226,12 @@ struct bootp {
 #define DHCPNAK                6
 #define DHCPRELEASE    7
 #define DHCPINFORM     8
+/* Defined in RFC4388 */
+#define DHCPLEASEQUERY       10
+#define DHCPLEASEUNASSIGNED  11
+#define DHCPLEASEUNKNOWN     12
+#define DHCPLEASEACTIVE      13
+
 
 /*
  * "vendor" data permitted for CMU bootp clients.
@@ -289,7 +295,7 @@ bootp_print(netdissect_options *ndo,
 
        bp_htype = GET_U_1(bp->bp_htype);
        bp_hlen = GET_U_1(bp->bp_hlen);
-       if (bp_htype == 1 && bp_hlen == 6 && bp_op == BOOTPREQUEST) {
+       if (bp_htype == 1 && bp_hlen == MAC_ADDR_LEN && bp_op == BOOTPREQUEST) {
                ND_PRINT(" from %s", GET_ETHERADDR_STRING(bp->bp_chaddr));
        }
 
@@ -305,7 +311,7 @@ bootp_print(netdissect_options *ndo,
                ND_PRINT(", htype %u", bp_htype);
 
        /* The usual length for 10Mb Ethernet address is 6 bytes */
-       if (bp_htype != 1 || bp_hlen != 6)
+       if (bp_htype != 1 || bp_hlen != MAC_ADDR_LEN)
                ND_PRINT(", hlen %u", bp_hlen);
 
        /* Only print interesting fields */
@@ -338,7 +344,7 @@ bootp_print(netdissect_options *ndo,
                ND_PRINT("\n\t  Gateway-IP %s", GET_IPADDR_STRING(bp->bp_giaddr));
 
        /* Client's Ethernet address */
-       if (bp_htype == 1 && bp_hlen == 6) {
+       if (bp_htype == 1 && bp_hlen == MAC_ADDR_LEN) {
                ND_PRINT("\n\t  Client-Ethernet-Address %s", GET_ETHERADDR_STRING(bp->bp_chaddr));
        }
 
@@ -388,9 +394,9 @@ trunc:
  * The first character specifies the format to print:
  *     i - ip address (32 bits)
  *     p - ip address pairs (32 bits + 32 bits)
- *     l - long (32 bits)
- *     L - unsigned long (32 bits)
- *     s - short (16 bits)
+ *     l - unsigned longs (32 bits)
+ *     L - longs (32 bits)
+ *     s - unsigned shorts (16 bits)
  *     b - period-separated decimal bytes (variable length)
  *     x - colon-separated hex bytes (variable length)
  *     a - ASCII string (variable length)
@@ -455,7 +461,7 @@ static const struct tok tag2str[] = {
        { TAG_NIS_P_DOMAIN,     "sN+D" },
        { TAG_NIS_P_SERVERS,    "iN+S" },
        { TAG_MOBILE_HOME,      "iMH" },
-       { TAG_SMPT_SERVER,      "iSMTP" },
+       { TAG_SMTP_SERVER,      "iSMTP" },
        { TAG_POP3_SERVER,      "iPOP3" },
        { TAG_NNTP_SERVER,      "iNNTP" },
        { TAG_WWW_SERVER,       "iWWW" },
@@ -493,6 +499,8 @@ static const struct tok tag2str[] = {
 /* RFC 3442 */
        { TAG_CLASSLESS_STATIC_RT, "$Classless-Static-Route" },
        { TAG_CLASSLESS_STA_RT_MS, "$Classless-Static-Route-Microsoft" },
+/* RFC 8572 */
+       { TAG_SZTP_REDIRECT,    "$SZTP-Redirect" },
 /* RFC 5859 - TFTP Server Address Option for DHCPv4 */
        { TAG_TFTP_SERVER_ADDRESS, "iTFTP-Server-Address" },
 /* https://www.iana.org/assignments/bootp-dhcp-parameters/bootp-dhcp-parameters.xhtml#options */
@@ -503,14 +511,14 @@ static const struct tok tag2str[] = {
        { TAG_TZ_STRING,        "aTZSTR" },
        { TAG_FQDN_OPTION,      "bFQDNS" },     /* XXX 'b' */
        { TAG_AUTH,             "bAUTH" },      /* XXX 'b' */
-       { TAG_VINES_SERVERS,    "iVINES" },
-       { TAG_SERVER_RANK,      "sRANK" },
+       { TAG_CLIENT_LAST_TRANSACTION_TIME, "LLast-Transaction-Time" },
+       { TAG_ASSOCIATED_IP,    "iAssociated-IP" },
        { TAG_CLIENT_ARCH,      "sARCH" },
        { TAG_CLIENT_NDI,       "bNDI" },       /* XXX 'b' */
        { TAG_CLIENT_GUID,      "bGUID" },      /* XXX 'b' */
        { TAG_LDAP_URL,         "aLDAP" },
-       { TAG_TZ_PCODE,         "aPOSIX-TZ" },
-       { TAG_TZ_TCODE,         "aTZ-Name" },
+       { TAG_TZ_PCODE,         "aPOSIX-TZ" },
+       { TAG_TZ_TCODE,         "aTZ-Name" },
        { TAG_NETINFO_PARENT,   "iNI" },
        { TAG_NETINFO_PARENT_TAG, "aNITAG" },
        { TAG_URL,              "aURL" },
@@ -547,14 +555,18 @@ static const struct tok arp2str[] = {
 };
 
 static const struct tok dhcp_msg_values[] = {
-       { DHCPDISCOVER, "Discover" },
-       { DHCPOFFER,    "Offer" },
-       { DHCPREQUEST,  "Request" },
-       { DHCPDECLINE,  "Decline" },
-       { DHCPACK,      "ACK" },
-       { DHCPNAK,      "NACK" },
-       { DHCPRELEASE,  "Release" },
-       { DHCPINFORM,   "Inform" },
+       { DHCPDISCOVER,        "Discover" },
+       { DHCPOFFER,           "Offer" },
+       { DHCPREQUEST,         "Request" },
+       { DHCPDECLINE,         "Decline" },
+       { DHCPACK,             "ACK" },
+       { DHCPNAK,             "NACK" },
+       { DHCPRELEASE,         "Release" },
+       { DHCPINFORM,          "Inform" },
+       { DHCPLEASEQUERY,      "LeaseQuery" },
+       { DHCPLEASEUNASSIGNED, "LeaseUnassigned" },
+       { DHCPLEASEUNKNOWN,    "LeaseUnknown" },
+       { DHCPLEASEACTIVE,     "LeaseActive" },
        { 0, NULL }
 };
 
@@ -705,7 +717,7 @@ rfc1048_print(netdissect_options *ndo,
                        break;
 
                case 's':
-                       /* shorts */
+                       /* unsigned shorts */
                        while (len >= 2) {
                                if (!first)
                                        ND_PRINT(",");
@@ -989,6 +1001,41 @@ rfc1048_print(netdissect_options *ndo,
                                break;
                            }
 
+
+                       case TAG_SZTP_REDIRECT:
+                               /* as per https://datatracker.ietf.org/doc/html/rfc8572#section-8.3
+                                +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...-+-+-+-+-+-+-+
+                                |        uri-length             |          URI                  |
+                                +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...-+-+-+-+-+-+-+
+
+                                * uri-length: 2 octets long; specifies the length of the URI data.
+                                * URI: URI of the SZTP bootstrap server.
+                                */
+                               while (len >= 2) {
+                                       uint16_t suboptlen2;
+
+                                       suboptlen2 = GET_BE_U_2(bp);
+                                       bp += 2;
+                                       len -= 2;
+                                       ND_PRINT("\n\t      ");
+                                       ND_PRINT("length %u: ", suboptlen2);
+                                       if (len < suboptlen2) {
+                                               ND_PRINT("length goes past end of option");
+                                               bp += len;
+                                               len = 0;
+                                               break;
+                                       }
+                                       ND_PRINT("\"");
+                                       nd_printjn(ndo, bp, suboptlen2);
+                                       ND_PRINT("\"");
+                                       len -= suboptlen2;
+                                       bp += suboptlen2;
+                               }
+                               if (len != 0) {
+                                       ND_PRINT("[ERROR: length < 2 bytes]");
+                               }
+                               break;
+
                        default:
                                ND_PRINT("[unknown special tag %u, size %u]",
                                          tag, len);