net::/ipv4:: namespace, mac/addr filter framework with default filters, dlog on registry overflow
This commit is contained in:
@@ -55,7 +55,7 @@ struct test_state {
|
||||
bool in_flight = false;
|
||||
responder resp;
|
||||
timer_handle timer = nullptr;
|
||||
frame_cb_handle frame_cb = nullptr;
|
||||
net::frame_cb_handle frame_cb = nullptr;
|
||||
|
||||
discovery_data* active_discovery = nullptr;
|
||||
ping_rate_data* active_rate = nullptr;
|
||||
@@ -72,7 +72,7 @@ static test_state ts;
|
||||
|
||||
static void test_end(const ResponseTest& result) {
|
||||
if (ts.timer) { dispatch_cancel_timer(ts.timer); ts.timer = nullptr; }
|
||||
if (ts.frame_cb) { net_remove_frame_callback(ts.frame_cb); ts.frame_cb = nullptr; }
|
||||
if (ts.frame_cb) { net::remove_frame_callback(ts.frame_cb); ts.frame_cb = nullptr; }
|
||||
ts.active_discovery = nullptr;
|
||||
ts.active_rate = nullptr;
|
||||
ts.resp.respond(result);
|
||||
@@ -93,7 +93,7 @@ static bool discover_reply_cb(std::span<const uint8_t> frame) {
|
||||
if (options_len > 0 && !pb.skip(options_len)) return false;
|
||||
auto* uhdr = pb.consume<udp::header>();
|
||||
if (!uhdr || uhdr->src_port != PICOMAP_PORT_BE) return false;
|
||||
if (ip->src == net_get_state().ip) return false;
|
||||
if (ip->src == net::get_state().ip) return false;
|
||||
dispatch_cancel_timer(ts.timer);
|
||||
ts.timer = nullptr;
|
||||
ts.frame_cb = nullptr;
|
||||
@@ -105,7 +105,7 @@ static bool discover_reply_cb(std::span<const uint8_t> frame) {
|
||||
}
|
||||
|
||||
static void discover_timeout_cb() {
|
||||
net_remove_frame_callback(ts.frame_cb);
|
||||
net::remove_frame_callback(ts.frame_cb);
|
||||
ts.frame_cb = nullptr;
|
||||
ts.timer = nullptr;
|
||||
auto cont = ts.active_discovery ? ts.active_discovery->on_timeout : nullptr;
|
||||
@@ -119,7 +119,7 @@ static void discover_peer(discovery_data& d,
|
||||
d.on_timeout = timeout;
|
||||
ts.active_discovery = &d;
|
||||
|
||||
const auto& ns = net_get_state();
|
||||
const auto& ns = net::get_state();
|
||||
eth::mac_addr mcast_mac = igmp::mac_for_ip(PICOMAP_DISCOVERY_GROUP);
|
||||
|
||||
prepend_buffer<4096> buf;
|
||||
@@ -137,10 +137,10 @@ static void discover_peer(discovery_data& d,
|
||||
udp::prepend(buf, mcast_mac, ns.mac, ns.ip, PICOMAP_DISCOVERY_GROUP,
|
||||
PICOMAP_PORT_BE, PICOMAP_PORT_BE, *encoded, 1);
|
||||
|
||||
ts.frame_cb = net_add_frame_callback(discover_reply_cb);
|
||||
ts.frame_cb = net::add_frame_callback(discover_reply_cb);
|
||||
ts.timer = dispatch_schedule_ms(5000, discover_timeout_cb);
|
||||
|
||||
net_send_raw(buf.span());
|
||||
net::send_raw(buf.span());
|
||||
}
|
||||
|
||||
static bool igmp_report_cb(std::span<const uint8_t> frame) {
|
||||
@@ -158,14 +158,14 @@ static void igmp_timeout_cb() {
|
||||
}
|
||||
|
||||
static void test_discovery_igmp() {
|
||||
const auto& ns = net_get_state();
|
||||
const auto& ns = net::get_state();
|
||||
prepend_buffer<4096> buf;
|
||||
igmp::prepend_query(buf, ns.mac, ns.ip, PICOMAP_DISCOVERY_GROUP);
|
||||
|
||||
ts.frame_cb = net_add_frame_callback(igmp_report_cb);
|
||||
ts.frame_cb = net::add_frame_callback(igmp_report_cb);
|
||||
ts.timer = dispatch_schedule_ms(5000, igmp_timeout_cb);
|
||||
|
||||
net_send_raw(buf.span());
|
||||
net::send_raw(buf.span());
|
||||
}
|
||||
|
||||
static void info_found(const peer_info& peer) {
|
||||
@@ -184,7 +184,7 @@ static bool ping_reply_cb(std::span<const uint8_t> frame) {
|
||||
ipv4::ip4_addr src_ip;
|
||||
if (!icmp::parse_echo_reply(frame, src_ip, PING_ECHO_ID)) return false;
|
||||
ts.frame_cb = nullptr;
|
||||
if (src_ip == net_get_state().ip)
|
||||
if (src_ip == net::get_state().ip)
|
||||
test_end({false, {"got reply from self: " + ipv4::to_string(src_ip)}});
|
||||
else
|
||||
test_end({true, {"reply from " + ipv4::to_string(src_ip)}});
|
||||
@@ -197,13 +197,13 @@ static void ping_timeout_cb() {
|
||||
}
|
||||
|
||||
static void start_ping(ipv4::ip4_addr dst_ip) {
|
||||
const auto& ns = net_get_state();
|
||||
const auto& ns = net::get_state();
|
||||
prepend_buffer<4096> buf;
|
||||
icmp::prepend_echo_request(buf, ns.mac, ns.ip,
|
||||
eth::MAC_BROADCAST, dst_ip, PING_ECHO_ID, 1);
|
||||
ts.frame_cb = net_add_frame_callback(ping_reply_cb);
|
||||
ts.frame_cb = net::add_frame_callback(ping_reply_cb);
|
||||
ts.timer = dispatch_schedule_ms(5000, ping_timeout_cb);
|
||||
net_send_raw(buf.span());
|
||||
net::send_raw(buf.span());
|
||||
}
|
||||
|
||||
static void test_ping_subnet() { start_ping({169, 254, 255, 255}); }
|
||||
@@ -215,7 +215,7 @@ static size_t ping_rate_frame_size() {
|
||||
}
|
||||
|
||||
static void ping_rate_send_one() {
|
||||
const auto& ns = net_get_state();
|
||||
const auto& ns = net::get_state();
|
||||
auto& r = *ts.active_rate;
|
||||
prepend_buffer<4096> buf;
|
||||
if (r.payload_len > 0)
|
||||
@@ -223,14 +223,14 @@ static void ping_rate_send_one() {
|
||||
icmp::prepend_echo_request(buf, ns.mac, ns.ip,
|
||||
r.peer.mac, r.peer.ip, PING_RATE_ECHO_ID,
|
||||
r.sent + 1, r.payload_len);
|
||||
net_send_raw(buf.span());
|
||||
net::send_raw(buf.span());
|
||||
r.sent++;
|
||||
}
|
||||
|
||||
static bool ping_rate_reply_cb(std::span<const uint8_t> frame) {
|
||||
ipv4::ip4_addr src_ip;
|
||||
if (!icmp::parse_echo_reply(frame, src_ip, PING_RATE_ECHO_ID)) return false;
|
||||
if (src_ip == net_get_state().ip) return false;
|
||||
if (src_ip == net::get_state().ip) return false;
|
||||
|
||||
auto& r = *ts.active_rate;
|
||||
r.received++;
|
||||
@@ -276,7 +276,7 @@ static void ping_rate_found(const peer_info& peer) {
|
||||
r.received = 0;
|
||||
r.start_us = time_us_32();
|
||||
|
||||
ts.frame_cb = net_add_frame_callback(ping_rate_reply_cb);
|
||||
ts.frame_cb = net::add_frame_callback(ping_rate_reply_cb);
|
||||
ts.timer = dispatch_schedule_ms(10000, ping_rate_timeout_cb);
|
||||
|
||||
for (uint16_t i = 0; i < r.pipeline && r.sent < r.target; i++)
|
||||
|
||||
Reference in New Issue
Block a user