]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[327-split-transmission-and-reception-control-buffers] Reported dhcp library part...
authorFrancis Dupont <fdupont@isc.org>
Mon, 10 Dec 2018 08:06:50 +0000 (09:06 +0100)
committerFrancis Dupont <fdupont@isc.org>
Tue, 11 Dec 2018 18:34:59 +0000 (13:34 -0500)
src/lib/dhcp/iface_mgr.cc
src/lib/dhcp/iface_mgr.h
src/lib/dhcp/pkt_filter_inet.cc
src/lib/dhcp/pkt_filter_inet.h
src/lib/dhcp/pkt_filter_inet6.cc
src/lib/dhcp/pkt_filter_inet6.h

index d2e32d2233fdc16e1ce7cdde1d3f818447a4f5f4..1cf2e39c78af9899da7b8d357562c38ac1ba8ade 100644 (file)
@@ -180,9 +180,7 @@ bool Iface::delSocket(const uint16_t sockfd) {
 }
 
 IfaceMgr::IfaceMgr()
-    :control_buf_len_(CMSG_SPACE(sizeof(struct in6_pktinfo))),
-     control_buf_(new char[control_buf_len_]),
-     packet_filter_(new PktFilterInet()),
+    :packet_filter_(new PktFilterInet()),
      packet_filter6_(new PktFilterInet6()),
      test_mode_(false),
      allow_loopback_(false) {
@@ -307,9 +305,6 @@ void IfaceMgr::stopDHCPReceiver() {
 }
 
 IfaceMgr::~IfaceMgr() {
-    // control_buf_ is deleted automatically (scoped_ptr)
-    control_buf_len_ = 0;
-
     closeSockets();
 }
 
@@ -506,13 +501,26 @@ IfaceMgr::openSockets4(const uint16_t port, const bool use_bcast,
 
             }
 
+            if (!iface->flag_up_) {
+                IFACEMGR_ERROR(SocketConfigError, error_handler,
+                               "the interface " << iface->getName()
+                               << " is down");
+                continue;
+            }
+
+            if (!iface->flag_running_) {
+                IFACEMGR_ERROR(SocketConfigError, error_handler,
+                               "the interface " << iface->getName()
+                               << " is not running");
+                continue;
+            }
+
             IOAddress out_address("0.0.0.0");
             if (!iface->flag_up_ || !iface->flag_running_ ||
                 !iface->getAddress4(out_address)) {
                 IFACEMGR_ERROR(SocketConfigError, error_handler,
                                "the interface " << iface->getName()
-                               << " is down or has no usable IPv4"
-                               " addresses configured");
+                               << " has no usable IPv4 addresses configured");
                 continue;
             }
         }
@@ -618,11 +626,15 @@ IfaceMgr::openSockets6(const uint16_t port,
                                " interface " << iface->getName());
                 continue;
 
-            } else if (!iface->flag_up_ || !iface->flag_running_) {
+            } else if (!iface->flag_up_) {
+                IFACEMGR_ERROR(SocketConfigError, error_handler,
+                               "the interface " << iface->getName()
+                               << " is down");
+                continue;
+            } else if (!iface->flag_running_) {
                 IFACEMGR_ERROR(SocketConfigError, error_handler,
                                "the interface " << iface->getName()
-                               << " is down or has no usable IPv6"
-                               " addresses configured");
+                               << " is not running");
                 continue;
             }
 
index 3bc7ff0dbc59cdd9d18a756c156ee2a57b2d8277..e771ce2764706970310bdb21613e3c04c69f9c56 100644 (file)
@@ -1255,12 +1255,6 @@ protected:
     // is bound to multicast address. And we all know what happens
     // to people who try to use multicast as source address.
 
-    /// Length of the control_buf_ array
-    size_t control_buf_len_;
-
-    /// Control-buffer, used in transmission and reception.
-    boost::scoped_array<char> control_buf_;
-
 private:
     /// @brief Identifies local network address to be used to
     /// connect to remote address.
index 4311caafac716be840a98cb196057cdd561e1db6..9953e8780c049d371326b43f57515de1fd585954 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2018 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -18,8 +18,10 @@ namespace isc {
 namespace dhcp {
 
 PktFilterInet::PktFilterInet()
-    : control_buf_len_(CMSG_SPACE(sizeof(struct in6_pktinfo))),
-      control_buf_(new char[control_buf_len_])
+    : recv_control_buf_len_(CMSG_SPACE(sizeof(struct in6_pktinfo))),
+      send_control_buf_len_(CMSG_SPACE(sizeof(struct in6_pktinfo))),
+      recv_control_buf_(new char[recv_control_buf_len_]),
+      send_control_buf_(new char[send_control_buf_len_])
 {
 }
 
@@ -112,7 +114,7 @@ PktFilterInet::receive(Iface& iface, const SocketInfo& socket_info) {
     struct sockaddr_in from_addr;
     uint8_t buf[IfaceMgr::RCVBUFSIZE];
 
-    memset(&control_buf_[0], 0, control_buf_len_);
+    memset(&recv_control_buf_[0], 0, recv_control_buf_len_);
     memset(&from_addr, 0, sizeof(from_addr));
 
     // Initialize our message header structure.
@@ -135,8 +137,8 @@ PktFilterInet::receive(Iface& iface, const SocketInfo& socket_info) {
     // previously asked the kernel to give us packet
     // information (when we initialized the interface), so we
     // should get the destination address from that.
-    m.msg_control = &control_buf_[0];
-    m.msg_controllen = control_buf_len_;
+    m.msg_control = &recv_control_buf_[0];
+    m.msg_controllen = recv_control_buf_len_;
 
     int result = recvmsg(socket_info.sockfd_, &m, 0);
     if (result < 0) {
@@ -211,7 +213,7 @@ PktFilterInet::receive(Iface& iface, const SocketInfo& socket_info) {
 int
 PktFilterInet::send(const Iface&, uint16_t sockfd,
                     const Pkt4Ptr& pkt) {
-    memset(&control_buf_[0], 0, control_buf_len_);
+    memset(&send_control_buf_[0], 0, send_control_buf_len_);
 
     // Set the target address we're sending to.
     sockaddr_in to;
@@ -247,8 +249,8 @@ PktFilterInet::send(const Iface&, uint16_t sockfd,
     // We have to create a "control message", and set that to
     // define the IPv4 packet information. We set the source address
     // to handle correctly interfaces with multiple addresses.
-    m.msg_control = &control_buf_[0];
-    m.msg_controllen = control_buf_len_;
+    m.msg_control = &send_control_buf_[0];
+    m.msg_controllen = send_control_buf_len_;
     struct cmsghdr* cmsg = CMSG_FIRSTHDR(&m);
     cmsg->cmsg_level = IPPROTO_IP;
     cmsg->cmsg_type = IP_PKTINFO;
index 6cc9fecb4e2012f3faeebea4fda28595faacf40c..b1b6f9309638507c41d261a23c340fc9cabbe369 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2018 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -22,7 +22,7 @@ public:
 
     /// @brief Constructor
     ///
-    /// Allocates control buffer.
+    /// Allocates control buffers.
     PktFilterInet();
 
     /// @brief Check if packet can be sent to the host without address directly.
@@ -85,10 +85,16 @@ public:
                      const Pkt4Ptr& pkt);
 
 private:
-    /// Length of the control_buf_ array.
-    size_t control_buf_len_;
-    /// Control buffer, used in transmission and reception.
-    boost::scoped_array<char> control_buf_;
+    /// There are separate control buffers for sending and receiving to be able
+    /// to send and receive packets in parallel in two threads.
+    /// Length of the recv_control_buf_ array.
+    size_t recv_control_buf_len_;
+    /// Length of the send_control_buf_ array.
+    size_t send_control_buf_len_;
+    /// Control buffer, used in reception.
+    boost::scoped_array<char> recv_control_buf_;
+    /// Control buffer, used in transmission.
+    boost::scoped_array<char> send_control_buf_;
 };
 
 } // namespace isc::dhcp
index ba706d036113ed6c480b6c8bfe755793fd14ae92..eede050a711a43a6950d3e5ac8db728beb8ab5d0 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2018 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -20,8 +20,10 @@ namespace isc {
 namespace dhcp {
 
 PktFilterInet6::PktFilterInet6()
-: control_buf_len_(CMSG_SPACE(sizeof(struct in6_pktinfo))),
-    control_buf_(new char[control_buf_len_]) {
+: recv_control_buf_len_(CMSG_SPACE(sizeof(struct in6_pktinfo))),
+  send_control_buf_len_(CMSG_SPACE(sizeof(struct in6_pktinfo))),
+  recv_control_buf_(new char[recv_control_buf_len_]),
+  send_control_buf_(new char[send_control_buf_len_]) {
 }
 
 SocketInfo
@@ -135,7 +137,7 @@ Pkt6Ptr
 PktFilterInet6::receive(const SocketInfo& socket_info) {
     // Now we have a socket, let's get some data from it!
     uint8_t buf[IfaceMgr::RCVBUFSIZE];
-    memset(&control_buf_[0], 0, control_buf_len_);
+    memset(&recv_control_buf_[0], 0, recv_control_buf_len_);
     struct sockaddr_in6 from;
     memset(&from, 0, sizeof(from));
 
@@ -163,8 +165,8 @@ PktFilterInet6::receive(const SocketInfo& socket_info) {
     // previously asked the kernel to give us packet
     // information (when we initialized the interface), so we
     // should get the destination address from that.
-    m.msg_control = &control_buf_[0];
-    m.msg_controllen = control_buf_len_;
+    m.msg_control = &recv_control_buf_[0];
+    m.msg_controllen = recv_control_buf_len_;
 
     int result = recvmsg(socket_info.sockfd_, &m, 0);
 
@@ -245,7 +247,7 @@ PktFilterInet6::receive(const SocketInfo& socket_info) {
 int
 PktFilterInet6::send(const Iface&, uint16_t sockfd, const Pkt6Ptr& pkt) {
 
-    memset(&control_buf_[0], 0, control_buf_len_);
+    memset(&send_control_buf_[0], 0, send_control_buf_len_);
 
     // Set the target address we're sending to.
     sockaddr_in6 to;
@@ -287,8 +289,8 @@ PktFilterInet6::send(const Iface&, uint16_t sockfd, const Pkt6Ptr& pkt) {
     // define the IPv6 packet information. We could set the
     // source address if we wanted, but we can safely let the
     // kernel decide what that should be.
-    m.msg_control = &control_buf_[0];
-    m.msg_controllen = control_buf_len_;
+    m.msg_control = &send_control_buf_[0];
+    m.msg_controllen = send_control_buf_len_;
     struct cmsghdr *cmsg = CMSG_FIRSTHDR(&m);
 
     // FIXME: Code below assumes that cmsg is not NULL, but
index 927a0778722dfb44ce794b5adda107fc3c502635..39a059d73d7a79a8c0627d72bd6ed39b91e6c372 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2018 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -23,7 +23,8 @@ public:
 
     /// @brief Constructor.
     ///
-    /// Initializes a control buffer used in the message transmission.
+    /// Initializes control buffers used in message transmission and
+    /// reception.
     PktFilterInet6();
 
     /// @brief Opens a socket.
@@ -84,10 +85,16 @@ public:
                      const Pkt6Ptr& pkt);
 
 private:
-    /// Length of the control_buf_ array.
-    size_t control_buf_len_;
-    /// Control buffer, used in transmission and reception.
-    boost::scoped_array<char> control_buf_;
+    /// There are separate control buffers for sending and receiving to be able
+    /// to send and receive packets in parallel in two threads.
+    /// Length of the recv_control_buf_ array.
+    size_t recv_control_buf_len_;
+    /// Length of the send_control_buf_ array.
+    size_t send_control_buf_len_;
+    /// Control buffer, used in reception.
+    boost::scoped_array<char> recv_control_buf_;
+    /// Control buffer, used in transmission.
+    boost::scoped_array<char> send_control_buf_;
 };
 
 } // namespace isc::dhcp