Skip to content

Commit

Permalink
Revert "Merge "Adding NAT Adapter" from Takuya"
Browse files Browse the repository at this point in the history
This reverts commit b0c8b80, reversing
changes made to 01337bd.  They caused
breakage to the packet class, breaking memcached.
  • Loading branch information
avikivity committed Jul 28, 2015
1 parent 8d333ae commit 581f262
Show file tree
Hide file tree
Showing 26 changed files with 92 additions and 1,774 deletions.
3 changes: 0 additions & 3 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ def debug_flag(compiler):
'tests/distributed_test',
'tests/rpc',
'tests/semaphore_test',
'tests/packet_test'
]

apps = [
Expand Down Expand Up @@ -206,7 +205,6 @@ def debug_flag(compiler):
'net/udp.cc',
'net/tcp.cc',
'net/dhcp.cc',
'net/nat-adapter.cc',
]

core = [
Expand Down Expand Up @@ -317,7 +315,6 @@ def have_xen():
'tests/fstream_test': ['tests/fstream_test.cc'] + core + boost_test_lib,
'tests/distributed_test': ['tests/distributed_test.cc'] + core,
'tests/rpc': ['tests/rpc.cc'] + core + libnet,
'tests/packet_test': ['tests/packet_test.cc'] + core + libnet,
}

warnings = [
Expand Down
15 changes: 9 additions & 6 deletions core/reactor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
#include "core/enum.hh"
#include <boost/range/irange.hpp>
#include "timer.hh"
#include <sys/uio.h>

#ifdef HAVE_OSV
#include <osv/sched.hh>
Expand Down Expand Up @@ -1146,11 +1145,15 @@ future<> pollable_fd::write_all(const uint8_t* buffer, size_t size) {
inline
future<size_t> pollable_fd::write_some(net::packet& p) {
return engine().writeable(*_s).then([this, &p] () mutable {
auto frags = p.fragment_array();
iovec iov[p.nr_frags()];
for (auto i = 0u; i < p.nr_frags(); i++) {
iov[i] = { frags[i].base, frags[i].size };
}
static_assert(offsetof(iovec, iov_base) == offsetof(net::fragment, base) &&
sizeof(iovec::iov_base) == sizeof(net::fragment::base) &&
offsetof(iovec, iov_len) == offsetof(net::fragment, size) &&
sizeof(iovec::iov_len) == sizeof(net::fragment::size) &&
alignof(iovec) == alignof(net::fragment) &&
sizeof(iovec) == sizeof(net::fragment)
, "net::fragment and iovec should be equivalent");

iovec* iov = reinterpret_cast<iovec*>(p.fragment_array());
auto r = get_file_desc().writev(iov, p.nr_frags());
if (!r) {
return write_some(p);
Expand Down
6 changes: 0 additions & 6 deletions net/arp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/

#include "arp.hh"
#include "nat-adapter.hh"

namespace net {

Expand Down Expand Up @@ -70,11 +69,6 @@ void arp::del(uint16_t proto_num) {

future<>
arp::process_packet(packet p, ethernet_address from) {
if (_nat_adapter) {
auto p1 = p.share();
p1.untrim_front();
_nat_adapter->send(std::move(p1));
}
auto ah = ntoh(*p.get_header<arp_hdr>());
auto i = _arp_for_protocol.find(ah.ptype);
if (i != _arp_for_protocol.end()) {
Expand Down
3 changes: 0 additions & 3 deletions net/arp.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "ethernet.hh"
#include "core/print.hh"
#include <unordered_map>
#include "net/nat-adapter.hh"

namespace net {

Expand All @@ -55,7 +54,6 @@ class arp {
subscription<packet, ethernet_address> _rx_packets;
std::unordered_map<uint16_t, arp_for_protocol*> _arp_for_protocol;
circular_buffer<l3_protocol::l3packet> _packetq;
lw_shared_ptr<nat_adapter> _nat_adapter;
private:
struct arp_hdr {
packed<uint16_t> htype;
Expand All @@ -68,7 +66,6 @@ public:
explicit arp(interface* netif);
void add(uint16_t proto_num, arp_for_protocol* afp);
void del(uint16_t proto_num);
void register_nat_adapter(lw_shared_ptr<nat_adapter> h) { _nat_adapter = h; }
private:
ethernet_address l2self() { return _netif->hw_address(); }
future<> process_packet(packet p, ethernet_address from);
Expand Down
32 changes: 3 additions & 29 deletions net/ip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/

#include "ip.hh"
#include "tcp.hh"
#include "core/print.hh"
#include "core/future-util.hh"
#include "core/shared_ptr.hh"
Expand All @@ -42,7 +41,7 @@ constexpr std::chrono::seconds ipv4::_frag_timeout;
constexpr uint32_t ipv4::_frag_low_thresh;
constexpr uint32_t ipv4::_frag_high_thresh;

ipv4::ipv4(interface* netif, uint16_t local_port_start, uint16_t local_port_end)
ipv4::ipv4(interface* netif)
: _netif(netif)
, _global_arp(netif)
, _arp(_global_arp)
Expand All @@ -54,9 +53,9 @@ ipv4::ipv4(interface* netif, uint16_t local_port_start, uint16_t local_port_end)
return handle_received_packet(std::move(p), ea); },
[this] (forward_hash& out_hash_data, packet& p, size_t off) {
return forward(out_hash_data, p, off);}))
, _tcp(*this, local_port_start, local_port_end)
, _tcp(*this)
, _icmp(*this)
, _udp(*this, local_port_start, local_port_end)
, _udp(*this)
, _l4({ { uint8_t(ip_protocol_num::tcp), &_tcp }, { uint8_t(ip_protocol_num::icmp), &_icmp }, { uint8_t(ip_protocol_num::udp), &_udp }}) {
_frag_timer.set_callback([this] { frag_timeout(); });
}
Expand Down Expand Up @@ -144,10 +143,6 @@ ipv4::handle_received_packet(packet p, ethernet_address from) {
}

if (h.dst_ip != _host_address) {
if (_nat_adapter) {
p.untrim_front();
_nat_adapter->send(std::move(p));
}
// FIXME: forward
return make_ready_future<>();
}
Expand Down Expand Up @@ -227,15 +222,6 @@ future<ethernet_address> ipv4::get_l2_dst_address(ipv4_address to) {
return _arp.lookup(dst);
}

void ipv4::register_nat_adapter(lw_shared_ptr<nat_adapter> h)
{
_nat_adapter = h;
get_tcp().register_nat_adapter(h);
_udp.register_nat_adapter(h);
_icmp.register_nat_adapter(h);
_global_arp.register_nat_adapter(h);
}

void ipv4::send(ipv4_address to, ip_protocol_num proto_num, packet p, ethernet_address e_dst) {
auto needs_frag = this->needs_frag(p, proto_num, hw_features());

Expand Down Expand Up @@ -456,21 +442,9 @@ packet ipv4::frag::get_assembled_packet(ethernet_address from, ethernet_address
return pkt;
}

void ipv4_icmp::register_nat_adapter(lw_shared_ptr<nat_adapter> h) {
_icmp.register_nat_adapter(h);
}

void icmp::register_nat_adapter(lw_shared_ptr<nat_adapter> h) {
_nat_adapter = h;
}

void icmp::received(packet p, ipaddr from, ipaddr to) {
auto hdr = p.get_header<icmp_hdr>(0);
if (!hdr || hdr->type != icmp_hdr::msg_type::echo_request) {
if (_nat_adapter) {
p.untrim_front();
_nat_adapter->send(std::move(p));
}
return;
}
hdr->type = icmp_hdr::msg_type::echo_reply;
Expand Down
23 changes: 5 additions & 18 deletions net/ip.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
#include "core/shared_ptr.hh"
#include "toeplitz.hh"
#include "net/udp.hh"
#include "net/nat-adapter.hh"

namespace net {

Expand Down Expand Up @@ -73,10 +72,6 @@ struct ipv4_address {
friend bool operator!=(ipv4_address x, ipv4_address y) {
return x.ip != y.ip;
}
sstring to_string() const {
boost::asio::ip::address_v4 addr(ip);
return addr.to_string();
}
} __attribute__((packed));

static inline bool is_unspecified(ipv4_address addr) { return addr.ip == 0; }
Expand Down Expand Up @@ -164,7 +159,7 @@ class ipv4_tcp final : public ip_protocol {
ipv4_l4<ip_protocol_num::tcp> _inet_l4;
std::unique_ptr<tcp<ipv4_traits>> _tcp;
public:
ipv4_tcp(ipv4& inet, const uint16_t local_port_start, const uint16_t local_port_end);
ipv4_tcp(ipv4& inet);
~ipv4_tcp();
virtual void received(packet p, ipv4_address from, ipv4_address to);
virtual bool forward(forward_hash& out_hash_data, packet& p, size_t off) override;
Expand Down Expand Up @@ -203,12 +198,10 @@ public:
});
}
void received(packet p, ipaddr from, ipaddr to);
void register_nat_adapter(lw_shared_ptr<nat_adapter> h);
private:
inet_type& _inet;
circular_buffer<ipv4_traits::l4packet> _packetq;
semaphore _queue_space = {212992};
lw_shared_ptr<nat_adapter> _nat_adapter;
};

class ipv4_icmp final : public ip_protocol {
Expand All @@ -219,7 +212,6 @@ public:
virtual void received(packet p, ipv4_address from, ipv4_address to) {
_icmp.received(std::move(p), from, to);
}
void register_nat_adapter(lw_shared_ptr<nat_adapter> h);
friend class ipv4;
};

Expand All @@ -230,14 +222,12 @@ class ipv4_udp : public ip_protocol {
public:
static const int default_queue_size;
private:
static const uint16_t min_anonymous_port = 32768;
ipv4 &_inet;
std::unordered_map<uint16_t, lw_shared_ptr<udp_channel_state>> _channels;
int _queue_size = default_queue_size;
const uint16_t _local_port_start;
const uint16_t _local_port_end;
uint16_t _next_anonymous_port;
uint16_t _next_anonymous_port = min_anonymous_port;
circular_buffer<std::tuple<ipv4_traits::l4packet, lw_shared_ptr<udp_channel_state>, size_t>> _packetq;
lw_shared_ptr<nat_adapter> _nat_adapter;
private:
uint16_t next_port(uint16_t port);
public:
Expand All @@ -257,13 +247,12 @@ public:
}
};

ipv4_udp(ipv4& inet, const uint16_t local_port_start = 49153, const uint16_t local_port_end = 65535);
ipv4_udp(ipv4& inet);
udp_channel make_channel(ipv4_addr addr);
virtual void received(packet p, ipv4_address from, ipv4_address to) override;
void send(uint16_t src_port, ipv4_addr dst, packet &&p, lw_shared_ptr<udp_channel_state> channel);
bool forward(forward_hash& out_hash_data, packet& p, size_t off) override;
void set_queue_size(int size) { _queue_size = size; }
void register_nat_adapter(lw_shared_ptr<nat_adapter> h);
};

struct ip_hdr;
Expand Down Expand Up @@ -343,7 +332,6 @@ private:
timer<lowres_clock> _frag_timer;
circular_buffer<l3_protocol::l3packet> _packetq;
unsigned _pkt_provider_idx = 0;
lw_shared_ptr<nat_adapter> _nat_adapter;
private:
future<> handle_received_packet(packet p, ethernet_address from);
bool forward(forward_hash& out_hash_data, packet& p, size_t off);
Expand All @@ -361,7 +349,7 @@ private:
frag_arm(now);
}
public:
explicit ipv4(interface* netif, const uint16_t local_port_start = 49153, const uint16_t local_port_end = 65535);
explicit ipv4(interface* netif);
void set_host_address(ipv4_address ip);
ipv4_address host_address();
void set_gw_address(ipv4_address ip);
Expand Down Expand Up @@ -389,7 +377,6 @@ public:
_pkt_providers.push_back(std::move(func));
}
future<ethernet_address> get_l2_dst_address(ipv4_address to);
void register_nat_adapter(lw_shared_ptr<nat_adapter> h);
};

template <ip_protocol_num ProtoNum>
Expand Down
Loading

0 comments on commit 581f262

Please sign in to comment.