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,
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;
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.
// 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) {
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;
// 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;
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
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
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,
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));
// 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);
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;
// 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
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
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