Parcourir la source

[3512] Loopback interface should not be selected for DHCP traffic reception.

Also, fixed selection of the unicast addresses for receiving DHCP packets.
Marcin Siodelski il y a 10 ans
Parent
commit
dc6da56005
2 fichiers modifiés avec 14 ajouts et 7 suppressions
  1. 9 5
      src/lib/dhcpsrv/iface_cfg.cc
  2. 5 2
      src/lib/dhcpsrv/iface_cfg.h

+ 9 - 5
src/lib/dhcpsrv/iface_cfg.cc

@@ -40,8 +40,9 @@ IfaceCfg::openSockets(const uint16_t port, const bool use_bcast) {
     // If wildcard interface '*' was not specified, set all interfaces to
     // inactive state. We will later enable them selectively using the
     // interface names specified by the user. If wildcard interface was
-    // specified, mark all interfaces active.
-    setState(!wildcard_used_);
+    // specified, mark all interfaces active. In all cases, mark loopback
+    // inactive.
+    setState(!wildcard_used_, true);
     // Remove selection of unicast addresses from all interfaces.
     IfaceMgr::instance().clearUnicasts();
     // If there is no wildcard interface specified, we will have to iterate
@@ -81,6 +82,7 @@ IfaceCfg::openSockets(const uint16_t port, const bool use_bcast) {
                           " exist");
             }
             iface->addUnicast(unicast->second);
+            iface->inactive6_ = false;
         }
     }
 
@@ -115,15 +117,17 @@ IfaceCfg::reset() {
 }
 
 void
-IfaceCfg::setState(const bool inactive) {
+IfaceCfg::setState(const bool inactive, const bool loopback_inactive) {
     IfaceMgr::IfaceCollection ifaces = IfaceMgr::instance().getIfaces();
     for (IfaceMgr::IfaceCollection::iterator iface = ifaces.begin();
          iface != ifaces.end(); ++iface) {
         Iface* iface_ptr = IfaceMgr::instance().getIface(iface->getName());
         if (getFamily() == V4) {
-            iface_ptr->inactive4_ = inactive;
+            iface_ptr->inactive4_ = iface_ptr->flag_loopback_ ?
+                loopback_inactive : inactive;
         } else {
-            iface_ptr->inactive6_ = inactive;
+            iface_ptr->inactive6_ = iface_ptr->flag_loopback_ ?
+                loopback_inactive : inactive;
         }
     }
 }

+ 5 - 2
src/lib/dhcpsrv/iface_cfg.h

@@ -152,14 +152,17 @@ public:
 
 private:
 
-    /// @brief Selects or deselects all interfaces.
+    /// @brief Selects or deselects interfaces.
     ///
     /// This function selects all interfaces to receive DHCP traffic or
     /// deselects all interfaces so as none of them receives a DHCP traffic.
     ///
     /// @param inactive A boolean value which indicates if all interfaces
+    /// (except loopback) should be selected or deselected.
+    /// @param loopback_inactive A boolean value which indicates if loopback
+    /// interface should be selected or deselected.
     /// should be deselected/inactive (true) or selected/active (false).
-    void setState(const bool inactive);
+    void setState(const bool inactive, const bool loopback_inactive);
 
     /// @brief Error handler for executed when opening a socket fail.
     ///