Self-registering IP-protocol and UDP-port dispatch; move picomap-specific constants out of generic net/dispatch layers

This commit is contained in:
Ian Gulliver
2026-04-19 08:39:13 -07:00
parent 7e493b7d70
commit 4db5c36931
16 changed files with 120 additions and 77 deletions

View File

@@ -34,28 +34,26 @@ bool is_member_mac(const eth::mac_addr& mac) {
return false;
}
static void send_report(const ipv4::ip4_addr& group,
eth::mac_addr our_mac, ipv4::ip4_addr our_ip) {
static void send_report(const ipv4::ip4_addr& group) {
const auto& ns = net_get_state();
prepend_buffer<4096> buf;
prepend_report(buf, our_mac, our_ip, group);
prepend_report(buf, ns.mac, ns.ip, group);
net_send_raw(buf.span());
}
void join(const ipv4::ip4_addr& group,
eth::mac_addr our_mac, ipv4::ip4_addr our_ip) {
void join(const ipv4::ip4_addr& group) {
for (auto& g : groups)
if (g.ip == group) return;
groups.push_back({group, mac_for_ip(group)});
send_report(group, our_mac, our_ip);
send_report(group);
}
void send_all_reports(eth::mac_addr our_mac, ipv4::ip4_addr our_ip) {
void send_all_reports() {
for (auto& g : groups)
send_report(g.ip, our_mac, our_ip);
send_report(g.ip);
}
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);
pb.consume<eth::header>();
auto* ip = pb.consume<ipv4::header>();
@@ -70,17 +68,22 @@ void handle(std::span<const uint8_t> frame, span_writer& tx,
if (msg->group == ipv4::ip4_addr{0, 0, 0, 0}) {
for (auto& g : groups)
send_report(g.ip, our_mac, our_ip);
send_report(g.ip);
} else {
for (auto& g : groups) {
if (g.ip == msg->group) {
send_report(g.ip, our_mac, our_ip);
send_report(g.ip);
break;
}
}
}
}
__attribute__((constructor))
static void register_protocol() {
ipv4::register_protocol(2, handle);
}
bool parse_report(std::span<const uint8_t> frame, ipv4::ip4_addr& group) {
parse_buffer pb(frame);
auto* eth_hdr = pb.consume<eth::header>();