merge net into eth lib; ipv4 owns its IP via ipv4::init/get_ip; drop state struct in favor of eth::get_mac/ipv4::get_ip
This commit is contained in:
18
src/arp.cpp
18
src/arp.cpp
@@ -1,5 +1,6 @@
|
||||
#include "arp.h"
|
||||
#include "net.h"
|
||||
#include "eth.h"
|
||||
#include "ipv4.h"
|
||||
#include "parse_buffer.h"
|
||||
#include "prepend_buffer.h"
|
||||
|
||||
@@ -11,7 +12,8 @@ static constexpr uint16_t ARP_OP_REQUEST = __builtin_bswap16(1);
|
||||
static constexpr uint16_t ARP_OP_REPLY = __builtin_bswap16(2);
|
||||
|
||||
void handle(std::span<const uint8_t> frame, span_writer& tx) {
|
||||
const auto& ns = net::get_state();
|
||||
const auto& mac = eth::get_mac();
|
||||
const auto& ip = ipv4::get_ip();
|
||||
parse_buffer pb(frame);
|
||||
pb.consume<eth::header>();
|
||||
auto* arp_hdr = pb.consume<header>();
|
||||
@@ -21,7 +23,7 @@ void handle(std::span<const uint8_t> frame, span_writer& tx) {
|
||||
if (arp_hdr->ptype != ARP_PTYPE_IPV4) return;
|
||||
if (arp_hdr->hlen != 6 || arp_hdr->plen != 4) return;
|
||||
if (arp_hdr->oper != ARP_OP_REQUEST) return;
|
||||
if (arp_hdr->tpa != ns.ip) return;
|
||||
if (arp_hdr->tpa != ip) return;
|
||||
|
||||
prepend_buffer<4096> buf;
|
||||
auto* reply = buf.template prepend<header>();
|
||||
@@ -30,18 +32,18 @@ void handle(std::span<const uint8_t> frame, span_writer& tx) {
|
||||
reply->hlen = 6;
|
||||
reply->plen = 4;
|
||||
reply->oper = ARP_OP_REPLY;
|
||||
reply->sha = ns.mac;
|
||||
reply->spa = ns.ip;
|
||||
reply->sha = mac;
|
||||
reply->spa = ip;
|
||||
reply->tha = arp_hdr->sha;
|
||||
reply->tpa = arp_hdr->spa;
|
||||
eth::prepend(buf, arp_hdr->sha, ns.mac, eth::ETH_ARP);
|
||||
eth::prepend(buf, arp_hdr->sha, mac, eth::ETH_ARP);
|
||||
|
||||
net::send_raw(buf.span());
|
||||
eth::send_raw(buf.span());
|
||||
}
|
||||
|
||||
__attribute__((constructor))
|
||||
static void register_ethertype() {
|
||||
net::register_ethertype(eth::ETH_ARP, handle);
|
||||
eth::register_ethertype(eth::ETH_ARP, handle);
|
||||
}
|
||||
|
||||
} // namespace arp
|
||||
|
||||
Reference in New Issue
Block a user