]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2517] Adding multiple requested vendor options
authorFrancis Dupont <fdupont@isc.org>
Sun, 31 Jul 2022 19:16:53 +0000 (21:16 +0200)
committerFrancis Dupont <fdupont@isc.org>
Wed, 3 Aug 2022 13:26:10 +0000 (15:26 +0200)
src/bin/dhcp6/dhcp6_srv.cc

index 118ba2128ebc19602ba03ddaafa4be13e29e2616..ffd5e8388b377f48a0c43b6715176518d35d3536 100644 (file)
@@ -1523,7 +1523,7 @@ Dhcpv6Srv::appendRequestedOptions(const Pkt6Ptr& question, Pkt6Ptr& answer,
         }
     }
 
-    // Special cases for vendor class. Vendor options are done later.
+    // Special cases for vendor class and options.
     if (requested_opts.count(D6O_VENDOR_CLASS) > 0) {
         set<uint32_t> vendor_ids;
         for (auto opt : answer->getOptions(D6O_VENDOR_CLASS)) {
@@ -1559,6 +1559,42 @@ Dhcpv6Srv::appendRequestedOptions(const Pkt6Ptr& question, Pkt6Ptr& answer,
             }
         }
     }
+
+    if (requested_opts.count(D6O_VENDOR_OPTS) > 0) {
+        set<uint32_t> vendor_ids;
+        for (auto opt : answer->getOptions(D6O_VENDOR_OPTS)) {
+            if (opt.first != D6O_VENDOR_OPTS) {
+                continue;
+            }
+            OptionVendorPtr vendor_opts;
+            vendor_opts = boost::dynamic_pointer_cast<OptionVendor>(opt.second);
+            if (vendor_opts) {
+                int32_t vendor_id = vendor_opts->getVendorId();
+                static_cast<void>(vendor_ids.insert(vendor_id));
+            }
+        }
+        // Iterate on the configured option list
+        for (CfgOptionList::const_iterator copts = co_list.begin();
+             copts != co_list.end(); ++copts) {
+            for (OptionDescriptor desc : (*copts)->getList(DHCP6_OPTION_SPACE,
+                                                           D6O_VENDOR_OPTS)) {
+                if (!desc.option_) {
+                    continue;
+                }
+                OptionVendorPtr vendor_opts =
+                    boost::dynamic_pointer_cast<OptionVendor>(desc.option_);
+                if (!vendor_opts) {
+                    continue;
+                }
+                // Is the vendor id already in the response?
+                if (vendor_ids.count(vendor_opts->getVendorId()) > 0) {
+                    continue;
+                }
+                // Got it: add it.
+                answer->addOption(desc.option_);
+            }
+        }
+    }
 }
 
 void