Self-registering IP-protocol and UDP-port dispatch; move picomap-specific constants out of generic net/dispatch layers
This commit is contained in:
@@ -7,13 +7,12 @@
|
||||
|
||||
namespace icmp {
|
||||
|
||||
void handle(std::span<const uint8_t> frame, span_writer& tx,
|
||||
eth::mac_addr our_mac, ipv4::ip4_addr our_ip) {
|
||||
void handle(std::span<const uint8_t> frame, span_writer& tx) {
|
||||
parse_buffer pb(frame);
|
||||
auto* eth_hdr = pb.consume<eth::header>();
|
||||
auto* ip = pb.consume<ipv4::header>();
|
||||
if (!ip) return;
|
||||
if (ip->protocol != 1) return;
|
||||
if (!ipv4::addressed_to_us(ip->dst)) return;
|
||||
|
||||
size_t options_len = ip->header_len() - sizeof(ipv4::header);
|
||||
if (options_len > 0 && !pb.skip(options_len)) return;
|
||||
@@ -25,6 +24,7 @@ void handle(std::span<const uint8_t> frame, span_writer& tx,
|
||||
if (!icmp_pkt) return;
|
||||
if (icmp_pkt->type != 8) return;
|
||||
|
||||
const auto& ns = net_get_state();
|
||||
prepend_buffer<4096> buf;
|
||||
memcpy(buf.append(icmp_len), pb.remaining().data() - sizeof(echo), icmp_len);
|
||||
|
||||
@@ -33,10 +33,15 @@ void handle(std::span<const uint8_t> frame, span_writer& tx,
|
||||
reply->checksum = 0;
|
||||
reply->checksum = ipv4::checksum(reply, icmp_len);
|
||||
|
||||
ipv4::prepend(buf, eth_hdr->src, our_mac, our_ip, ip->src, 1, icmp_len);
|
||||
ipv4::prepend(buf, eth_hdr->src, ns.mac, ns.ip, ip->src, 1, icmp_len);
|
||||
net_send_raw(buf.span());
|
||||
}
|
||||
|
||||
__attribute__((constructor))
|
||||
static void register_protocol() {
|
||||
ipv4::register_protocol(1, handle);
|
||||
}
|
||||
|
||||
bool parse_echo_reply(std::span<const uint8_t> frame, ipv4::ip4_addr& src_ip, uint16_t expected_id) {
|
||||
parse_buffer pb(frame);
|
||||
auto* eth_hdr = pb.consume<eth::header>();
|
||||
|
||||
Reference in New Issue
Block a user