Commit d919490c authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[991] Pass Iface object to classes derived from PktFilter.

parent d9b1da77
......@@ -20,6 +20,9 @@
namespace isc {
namespace dhcp {
/// Forward declaration to the class representing interface
class Iface;
/// @brief Abstract packet handling class
///
/// This class represents low level method to send and receive DHCP packet.
......@@ -39,14 +42,14 @@ public:
/// @brief Open socket.
///
/// @param interface name
/// @param iface interface descriptor
/// @param addr address on the interface to be used to send packets.
/// @param port port number.
/// @param receive_bcast configure socket to receive broadcast messages
/// @param send_bcast configure socket to send broadcast messages.
///
/// @return created socket's descriptor
virtual int openSocket(const std::string& ifname,
virtual int openSocket(const Iface& iface,
const isc::asiolink::IOAddress& addr,
const uint16_t port,
const bool receive_bcast,
......
......@@ -21,8 +21,10 @@ namespace isc {
namespace dhcp {
int
PktFilterInet::openSocket(const std::string& ifname, const isc::asiolink::IOAddress& addr,
const uint16_t port, const bool receive_bcast,
PktFilterInet::openSocket(const Iface& iface,
const isc::asiolink::IOAddress& addr,
const uint16_t port,
const bool receive_bcast,
const bool send_bcast) {
struct sockaddr_in addr4;
......@@ -41,8 +43,8 @@ PktFilterInet::openSocket(const std::string& ifname, const isc::asiolink::IOAddr
if (receive_bcast) {
// Bind to device so as we receive traffic on a specific interface.
if (setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, ifname.c_str(),
ifname.length() + 1) < 0) {
if (setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, iface.getName().c_str(),
iface.getName().length() + 1) < 0) {
close(sock);
isc_throw(SocketConfigError, "Failed to set SO_BINDTODEVICE option"
<< "on socket " << sock);
......
......@@ -29,14 +29,14 @@ public:
/// @brief Open socket.
///
/// @param interface name
/// @param iface interface descriptor
/// @param addr address on the interface to be used to send packets.
/// @param port port number.
/// @param receive_bcast configure socket to receive broadcast messages
/// @param send_bcast configure socket to send broadcast messages.
///
/// @return created socket's descriptor
virtual int openSocket(const std::string& ifname,
virtual int openSocket(const Iface& iface,
const isc::asiolink::IOAddress& addr,
const uint16_t port,
const bool receive_bcast,
......
// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include <config.h>
#include <dhcp/iface_mgr.h>
#include <dhcp/pkt4.h>
#include <dhcp/pkt_filter_lpf.h>
namespace isc {
namespace dhcp {
int
PktFilterLPF::openSocket(const std::string& ifname, const isc::asiolink::IOAddress& addr,
const uint16_t port, const bool receive_bcast,
const bool send_bcast) {
return (-1);
}
} // end of isc::dhcp namespace
} // end of isc namespace
// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#ifndef PKT_FILTER_LPF_H
#define PKT_FILTER_LPF_H
#include <dhcp/pkt_filter.h>
namespace isc {
namespace dhcp {
/// @brief Packet handling class using Linux Packet Filtering
///
/// This class provides methods to send and recive packet using raw sockets
/// and Linux Packet Filtering.
class PktFilterLPF : public PktFilter {
public:
/// @brief Open socket.
///
/// @param interface name
/// @param addr address on the interface to be used to send packets.
/// @param port port number.
/// @param receive_bcast configure socket to receive broadcast messages
/// @param send_bcast configure socket to send broadcast messages.
///
/// @return created socket's descriptor
virtual int openSocket(const std::string& ifname,
const isc::asiolink::IOAddress& addr,
const uint16_t port,
const bool receive_bcast,
const bool send_bcast);
/// @brief Receive packet over specified socket.
///
/// @param sockfd descriptor of a socket to be used for packet reception
/// @param timeout_sec integral part of a timeout.
/// @param timeout_usec fractional part of a timeout (in microseconds).
///
/// @return Received packet
Pkt4Ptr receive(uint16_t sockfd, uint32_t timeout_sec,
uint32_t timeout_usec = 0);
// bool send(const Pkt4Ptr& pkt) = 0;
};
} // namespace isc::dhcp
} // namespace isc
#endif // PKT_FILTER_LPF_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment