]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[283-perfdhcp-sending-thread] [343-put-socket-control-buffer-in-the-stack] Moved...
authorFrancis Dupont <fdupont@isc.org>
Wed, 12 Dec 2018 15:39:48 +0000 (16:39 +0100)
committerFrancis Dupont <fdupont@isc.org>
Sun, 30 Dec 2018 00:26:28 +0000 (01:26 +0100)
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 9953e8780c049d371326b43f57515de1fd585954..7245065e3466e2ec805bf854f1d5ba2caafc0dc3 100644 (file)
@@ -17,13 +17,8 @@ using namespace isc::asiolink;
 namespace isc {
 namespace dhcp {
 
-PktFilterInet::PktFilterInet()
-    : 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_])
-{
-}
+const size_t
+PktFilterInet::CONTROL_BUF_LEN = CMSG_SPACE(sizeof(struct in6_pktinfo));
 
 SocketInfo
 PktFilterInet::openSocket(Iface& iface,
@@ -31,7 +26,6 @@ PktFilterInet::openSocket(Iface& iface,
                           const uint16_t port,
                           const bool receive_bcast,
                           const bool send_bcast) {
-
     struct sockaddr_in addr4;
     memset(&addr4, 0, sizeof(sockaddr));
     addr4.sin_family = AF_INET;
@@ -113,8 +107,9 @@ Pkt4Ptr
 PktFilterInet::receive(Iface& iface, const SocketInfo& socket_info) {
     struct sockaddr_in from_addr;
     uint8_t buf[IfaceMgr::RCVBUFSIZE];
+    uint8_t control_buf[CONTROL_BUF_LEN];
 
-    memset(&recv_control_buf_[0], 0, recv_control_buf_len_);
+    memset(&control_buf[0], 0, CONTROL_BUF_LEN);
     memset(&from_addr, 0, sizeof(from_addr));
 
     // Initialize our message header structure.
@@ -137,8 +132,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 = &recv_control_buf_[0];
-    m.msg_controllen = recv_control_buf_len_;
+    m.msg_control = &control_buf[0];
+    m.msg_controllen = CONTROL_BUF_LEN;
 
     int result = recvmsg(socket_info.sockfd_, &m, 0);
     if (result < 0) {
@@ -213,7 +208,8 @@ PktFilterInet::receive(Iface& iface, const SocketInfo& socket_info) {
 int
 PktFilterInet::send(const Iface&, uint16_t sockfd,
                     const Pkt4Ptr& pkt) {
-    memset(&send_control_buf_[0], 0, send_control_buf_len_);
+    uint8_t control_buf[CONTROL_BUF_LEN];
+    memset(&control_buf[0], 0, CONTROL_BUF_LEN);
 
     // Set the target address we're sending to.
     sockaddr_in to;
@@ -249,8 +245,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 = &send_control_buf_[0];
-    m.msg_controllen = send_control_buf_len_;
+    m.msg_control = &control_buf[0];
+    m.msg_controllen = CONTROL_BUF_LEN;
     struct cmsghdr* cmsg = CMSG_FIRSTHDR(&m);
     cmsg->cmsg_level = IPPROTO_IP;
     cmsg->cmsg_type = IP_PKTINFO;
index b1b6f9309638507c41d261a23c340fc9cabbe369..8b6b02c47c082f84961dc56aca3b86266765702e 100644 (file)
@@ -20,11 +20,6 @@ namespace dhcp {
 class PktFilterInet : public PktFilter {
 public:
 
-    /// @brief Constructor
-    ///
-    /// Allocates control buffers.
-    PktFilterInet();
-
     /// @brief Check if packet can be sent to the host without address directly.
     ///
     /// This Packet Filter sends packets through AF_INET datagram sockets, so
@@ -85,16 +80,8 @@ public:
                      const Pkt4Ptr& pkt);
 
 private:
-    /// 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_;
+    /// Length of the socket control buffer.
+    static const size_t CONTROL_BUF_LEN;
 };
 
 } // namespace isc::dhcp
index eede050a711a43a6950d3e5ac8db728beb8ab5d0..7e7a37c210fa1c0ef51d1bcd660a8a92ff1552fe 100644 (file)
@@ -19,12 +19,8 @@ using namespace isc::asiolink;
 namespace isc {
 namespace dhcp {
 
-PktFilterInet6::PktFilterInet6()
-: 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_]) {
-}
+const size_t
+PktFilterInet6::CONTROL_BUF_LEN = CMSG_SPACE(sizeof(struct in6_pktinfo));
 
 SocketInfo
 PktFilterInet6::openSocket(const Iface& iface,
@@ -137,7 +133,8 @@ 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(&recv_control_buf_[0], 0, recv_control_buf_len_);
+    uint8_t control_buf[CONTROL_BUF_LEN];
+    memset(&control_buf[0], 0, CONTROL_BUF_LEN);
     struct sockaddr_in6 from;
     memset(&from, 0, sizeof(from));
 
@@ -165,8 +162,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 = &recv_control_buf_[0];
-    m.msg_controllen = recv_control_buf_len_;
+    m.msg_control = &control_buf[0];
+    m.msg_controllen = CONTROL_BUF_LEN;
 
     int result = recvmsg(socket_info.sockfd_, &m, 0);
 
@@ -247,7 +244,8 @@ PktFilterInet6::receive(const SocketInfo& socket_info) {
 int
 PktFilterInet6::send(const Iface&, uint16_t sockfd, const Pkt6Ptr& pkt) {
 
-    memset(&send_control_buf_[0], 0, send_control_buf_len_);
+    uint8_t control_buf[CONTROL_BUF_LEN];
+    memset(&control_buf[0], 0, CONTROL_BUF_LEN);
 
     // Set the target address we're sending to.
     sockaddr_in6 to;
@@ -289,8 +287,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 = &send_control_buf_[0];
-    m.msg_controllen = send_control_buf_len_;
+    m.msg_control = &control_buf[0];
+    m.msg_controllen = CONTROL_BUF_LEN;
     struct cmsghdr *cmsg = CMSG_FIRSTHDR(&m);
 
     // FIXME: Code below assumes that cmsg is not NULL, but
index 39a059d73d7a79a8c0627d72bd6ed39b91e6c372..d641065bdfe53f31311f63758cd8a9896dc89b0c 100644 (file)
@@ -21,12 +21,6 @@ namespace dhcp {
 class PktFilterInet6 : public PktFilter6 {
 public:
 
-    /// @brief Constructor.
-    ///
-    /// Initializes control buffers used in message transmission and
-    /// reception.
-    PktFilterInet6();
-
     /// @brief Opens a socket.
     ///
     /// This function opens an IPv6 socket on an interface and binds it to a
@@ -85,16 +79,8 @@ public:
                      const Pkt6Ptr& pkt);
 
 private:
-    /// 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_;
+    /// Length of the socket control buffer.
+    static const size_t CONTROL_BUF_LEN;
 };
 
 } // namespace isc::dhcp