Deocde DHCP-Vendor-Specific-Information as octets
authorAlan T. DeKok <aland@freeradius.org>
Mon, 15 Jun 2015 16:05:07 +0000 (12:05 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 15 Jun 2015 16:05:07 +0000 (12:05 -0400)
Because creating RADIUS VSAs for DHCP data is a bad idea.

share/dictionary.dhcp
src/modules/proto_dhcp/dhcp.c
src/tests/unit/dhcp.txt

index 535bc0c..cf79ae1 100644 (file)
@@ -245,7 +245,12 @@ ATTRIBUTE  DHCP-RADIUS-Attributes                  82.7    octets
 
 # Horribly complicated
 ATTRIBUTE      DHCP-Authentication-Information         82.8    octets
-ATTRIBUTE      DHCP-Vendor-Specific-Information        82.9    vsa
+
+#
+#  We'll fix this later
+#
+ATTRIBUTE      DHCP-Vendor-Specific-Information        82.9    octets
+
 ATTRIBUTE      DHCP-Relay-Agent-Flags                  82.10   byte
 ATTRIBUTE      DHCP-Server-Identifier-Override         82.11   ipaddr
 
index c49c689..437e844 100644 (file)
@@ -545,118 +545,12 @@ static int fr_dhcp_array_members(size_t *len, DICT_ATTR const *da)
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  @endverbatim
  *
- * So although the vendor is identified, the format of the data isn't specified
- * so we can't actually resolve the suboption to an attribute.
- *
- * To get around that, we create an attribute with a vendor matching the
- * enterprise number, and attr 0.
- *
- * How the suboption data is then processed, is dependent on what type
- * \<iana\>.0 is defined as in the dictionary.
- *
- * @param[in,out] tlv to decode. *tlv will be set to the head of the list of suboptions and original will be freed.
- * @param[in] ctx context to alloc new attributes in.
- * @param[in] data to parse.
- * @param[in] len length of data to parse.
+ * So although the vendor is identified, the format of the data isn't
+ * specified so we can't actually resolve the suboption to an
+ * attribute.  For now, we just convert it to an attribute of
+ * DHCP-Vendor-Specific-Information with raw octets contents.
  */
-static int fr_dhcp_decode_vsa(TALLOC_CTX *ctx, VALUE_PAIR **tlv, uint8_t const *data, size_t len)
-{
-       uint8_t const *p, *q;
-       vp_cursor_t cursor;
-
-       VALUE_PAIR *head;
 
-       if (len < 4) goto malformed;
-
-       p = data;
-       q = p + len;
-       while (p < q) {
-               if (p + 5 >= q) goto malformed;
-               p += sizeof(uint32_t);
-               p += p[0];
-
-               /*
-                *      Check if length > the length of the buffer we have left
-                */
-               if (p >= q) goto malformed;
-               p++;
-       }
-
-       head = NULL;
-       fr_cursor_init(&cursor, &head);
-
-       /*
-        *      Now we know its sane, start decoding!
-        */
-       p = data;
-       while (p < q) {
-               uint32_t vendor;
-               DICT_ATTR const *da;
-               VALUE_PAIR *vp;
-
-               vendor = ntohl(*((uint32_t const *) p));
-               /*
-                *      This is pretty much all we can do.  RFC 4243 doesn't specify
-                *      an attribute field, so it's up to vendors to figure out how
-                *      they want to encode their attributes.
-                */
-               da = dict_attrbyvalue(0, vendor);
-               if (!da) {
-                       da = dict_unknown_afrom_fields(ctx, 0, vendor);
-                       if (!da) {
-                               pairfree(&head);
-                               goto malformed;
-                       }
-               }
-               vp = pairalloc(ctx, da);
-               if (!vp) {
-                       pairfree(&head);
-                       return -1;
-               }
-               vp->op = T_OP_EQ;
-               pairsteal(ctx, vp); /* for unknown attributes hack */
-
-               if (fr_dhcp_attr2vp(ctx, &vp, p + 5, p[4]) < 0) {
-                       dict_attr_free(&da);
-                       pairfree(&head);
-                       return -1;
-               }
-
-               fr_cursor_merge(&cursor, vp);
-               dict_attr_free(&da); /* for unknown attributes hack */
-
-               p += 4 + 1 + p[4];      /* vendor id (4) + len (1) + vsa len (n) */
-       }
-
-       /*
-        *      The caller allocated TLV, if decoding it generated additional
-        *      attributes, we now need to free it, and write the HEAD of our
-        *      new list of attributes in its place.
-        */
-       if (head) {
-               vp_cursor_t tlv_cursor;
-
-               /*
-                *      Free the old TLV attribute
-                */
-               TALLOC_FREE(*tlv);
-
-               /*
-                *      Cursor not necessary but means we don't have to set
-                *      ->next directly.
-                */
-               fr_cursor_init(&tlv_cursor, tlv);
-               fr_cursor_merge(&tlv_cursor, head);
-       }
-
-       return 0;
-
-malformed:
-       pair2unknown(*tlv);
-       pairmemcpy(*tlv, data, len);
-
-       return 0;
-}
 
 /** Decode DHCP suboptions
  *
@@ -917,12 +811,6 @@ static int fr_dhcp_attr2vp(TALLOC_CTX *ctx, VALUE_PAIR **vp_p, uint8_t const *da
        case PW_TYPE_TLV:
                return fr_dhcp_decode_suboption(ctx, vp_p, data, len);
 
-       /*
-        *      For option 82.9
-        */
-       case PW_TYPE_VSA:
-               return fr_dhcp_decode_vsa(ctx, vp_p, data, len);
-
        default:
                fr_strerror_printf("Internal sanity check %d %d", vp->da->type, __LINE__);
                return -1;
index be166e1..11ddd86 100644 (file)
@@ -12,4 +12,11 @@ data DHCP-Subnet-Mask = 255.255.0.0
 #  A long one... with a weird DHCP-specific vendor ID.
 #
 decode-dhcp 3501013d0701001ceaadac1e37070103060f2c2e2f3c094d5346545f495054565232011c4c41424f4c54322065746820312f312f30312f30312f31302f312f3209120000197f0d050b4c4142373336304f4c5432
-data DHCP-Message-Type = DHCP-Discover, DHCP-Client-Identifier = 0x01001ceaadac1e, DHCP-Parameter-Request-List = DHCP-Subnet-Mask, DHCP-Parameter-Request-List = DHCP-Router-Address, DHCP-Parameter-Request-List = DHCP-Domain-Name-Server, DHCP-Parameter-Request-List = DHCP-Domain-Name, DHCP-Parameter-Request-List = DHCP-NETBIOS-Name-Servers, DHCP-Parameter-Request-List = DHCP-NETBIOS-Node-Type, DHCP-Parameter-Request-List = DHCP-NETBIOS, DHCP-Vendor-Class-Identifier = 0x4d5346545f49505456, DHCP-Relay-Circuit-Id = 0x4c41424f4c54322065746820312f312f30312f30312f31302f312f32, Attr-26.6527.0 = 0x050b4c4142373336304f4c5432
+data DHCP-Message-Type = DHCP-Discover, DHCP-Client-Identifier = 0x01001ceaadac1e, DHCP-Parameter-Request-List = DHCP-Subnet-Mask, DHCP-Parameter-Request-List = DHCP-Router-Address, DHCP-Parameter-Request-List = DHCP-Domain-Name-Server, DHCP-Parameter-Request-List = DHCP-Domain-Name, DHCP-Parameter-Request-List = DHCP-NETBIOS-Name-Servers, DHCP-Parameter-Request-List = DHCP-NETBIOS-Node-Type, DHCP-Parameter-Request-List = DHCP-NETBIOS, DHCP-Vendor-Class-Identifier = 0x4d5346545f49505456, DHCP-Relay-Circuit-Id = 0x4c41424f4c54322065746820312f312f30312f30312f31302f312f32, DHCP-Vendor-Specific-Information = 0x0000197f0d050b4c4142373336304f4c5432
+
+
+encode-dhcp DHCP-Agent-Circuit-Id = 0xabcdef, DHCP-Relay-Remote-Id = 0x010203040506
+data 52 0d 01 03 ab cd ef 02 06 01 02 03 04 05 06
+
+decode-dhcp -
+data DHCP-Relay-Circuit-Id = 0xabcdef, DHCP-Relay-Remote-Id = 0x010203040506