Files
scylladb/net/arp.cc
Gleb Natapov 4e7d8a8506 Introduce packet classification mechanism
Classifier returns what cpu a packets should be processed on. It may
return special broadcast identifier. The patch includes classifier for
tcp, udp and arp. Arp classifier broadcasts arp reply to all cpus. Default
classifier does not forward packet.
2014-10-07 11:03:57 +03:00

59 lines
1.4 KiB
C++

/*
* Copyright (C) 2014 Cloudius Systems, Ltd.
*/
#include "arp.hh"
namespace net {
arp_for_protocol::arp_for_protocol(arp& a, uint16_t proto_num)
: _arp(a), _proto_num(proto_num) {
_arp.add(proto_num, this);
}
arp_for_protocol::~arp_for_protocol() {
_arp.del(_proto_num);
}
arp::arp(interface* netif) : _netif(netif), _proto(netif, 0x0806)
, _rx_packets(_proto.receive([this] (packet p, ethernet_address ea) {
return process_packet(std::move(p), ea);
},
[this](packet& p, size_t off) {
return handle_on_cpu(p, off);
})) {
}
unsigned arp::handle_on_cpu(packet& p, size_t off) {
auto ah = p.get_header<arp_hdr>(off);
auto ptype = ah->ptype;
ntoh(ptype);
auto i = _arp_for_protocol.find(ptype);
if (i != _arp_for_protocol.end()) {
return i->second->forward(p, off);
}
return engine._id;
}
void arp::add(uint16_t proto_num, arp_for_protocol* afp) {
_arp_for_protocol[proto_num] = afp;
}
void arp::del(uint16_t proto_num) {
_arp_for_protocol.erase(proto_num);
}
future<>
arp::process_packet(packet p, ethernet_address from) {
auto ah = p.get_header<arp_hdr>();
ntoh(*ah);
auto i = _arp_for_protocol.find(ah->ptype);
hton(*ah); // return to raw state for further processing
if (i != _arp_for_protocol.end()) {
i->second->received(std::move(p));
}
return make_ready_future<>();
}
}