Browse Source

radius: boilerplate code for IPv6

Baptiste Jonglez 7 years ago
parent
commit
66f4aebebf
1 changed files with 30 additions and 11 deletions
  1. 30 11
      src/lib/dhcpsrv/radius_host_data_source.cc

+ 30 - 11
src/lib/dhcpsrv/radius_host_data_source.cc

@@ -336,9 +336,26 @@ RadiusHostDataSource::get4(const SubnetID& subnet_id,
 ConstHostPtr
 RadiusHostDataSource::get6(const SubnetID& subnet_id, const DuidPtr& duid,
                           const HWAddrPtr& hwaddr) const {
-    // TODO: libradcli call
-    ConstHostPtr result = NULL;
-    return (result);
+    if (hwaddr && duid) {
+        isc_throw(BadValue, "Radius host data source get6() called with both"
+                  " hwaddr and duid, only one of them is allowed");
+    }
+    if (!hwaddr && !duid) {
+        isc_throw(BadValue, "Radius host data source get6() called with "
+                  "neither hwaddr or duid specified, one of them is required");
+    }
+
+    // Choosing one of the identifiers
+    if (hwaddr) {
+        return (get6(subnet_id, Host::IDENT_HWADDR, &hwaddr->hwaddr_[0],
+                     hwaddr->hwaddr_.size()));
+
+    } else if (duid) {
+        return (get6(subnet_id, Host::IDENT_DUID, &duid->getDuid()[0],
+                     duid->getDuid().size()));
+    }
+
+    return (ConstHostPtr());
 }
 
 ConstHostPtr
@@ -346,25 +363,27 @@ RadiusHostDataSource::get6(const SubnetID& subnet_id,
                           const Host::IdentifierType& identifier_type,
                           const uint8_t* identifier_begin,
                           const size_t identifier_len) const {
-    // TODO: libradcli call
-    ConstHostPtr result = NULL;
+    ConstHostCollection collection = getAll(identifier_type, identifier_begin, identifier_len);
+    ConstHostPtr result;
+    if (!collection.empty())
+        result = *collection.begin();
     return (result);
 }
 
 ConstHostPtr
 RadiusHostDataSource::get6(const asiolink::IOAddress& prefix,
                           const uint8_t prefix_len) const {
-    // TODO: libradcli call
-    ConstHostPtr result = NULL;
-    return (result);
+    // We always assume that there is no conflict between reserved
+    // prefixes and dynamic prefixes, so just return nothing here.
+    return (ConstHostPtr());
 }
 
 ConstHostPtr
 RadiusHostDataSource::get6(const SubnetID& subnet_id,
                           const asiolink::IOAddress& address) const {
-    // TODO: libradcli call
-    ConstHostPtr result = NULL;
-    return (result);
+    // We always assume that there is no conflict between reserved
+    // addresses and dynamic addresses, so just return nothing here.
+    return (ConstHostPtr());
 }