}
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) {
}
IfaceMgr::~IfaceMgr() {
- // control_buf_ is deleted automatically (scoped_ptr)
- control_buf_len_ = 0;
-
closeSockets();
}
}
+ 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;
}
}
" 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;
}
// 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.
-// 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
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_])
{
}
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.
// 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) {
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;
// 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;
-// 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
/// @brief Constructor
///
- /// Allocates control buffer.
+ /// Allocates control buffers.
PktFilterInet();
/// @brief Check if packet can be sent to the host without address directly.
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
-// 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
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
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));
// 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);
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;
// 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
-// 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
/// @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.
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