net::/ipv4:: namespace, mac/addr filter framework with default filters, dlog on registry overflow
This commit is contained in:
@@ -17,15 +17,17 @@ struct responder {
|
||||
|
||||
template <typename T>
|
||||
void respond(const T& msg) const {
|
||||
const auto& ns = net_get_state();
|
||||
const auto& ns = net::get_state();
|
||||
prepend_buffer<4096> buf;
|
||||
span_writer out(buf.payload_ptr(), 2048);
|
||||
auto r = encode_response_into(out, message_id, msg);
|
||||
if (!r) return;
|
||||
if (!r) {
|
||||
return;
|
||||
}
|
||||
buf.append(*r);
|
||||
udp::prepend(buf, reply_to.mac, ns.mac, ns.ip, reply_to.ip,
|
||||
dispatch_listen_port_be(), reply_to.port, *r);
|
||||
net_send_raw(buf.span());
|
||||
net::send_raw(buf.span());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -64,4 +64,7 @@ bool addressed_to_us(ip4_addr dst);
|
||||
using protocol_handler = void (*)(std::span<const uint8_t> frame, span_writer& tx);
|
||||
void register_protocol(uint8_t protocol, protocol_handler fn);
|
||||
|
||||
using addr_filter = bool (*)(const ip4_addr& dst);
|
||||
void register_addr_filter(addr_filter fn);
|
||||
|
||||
} // namespace ipv4
|
||||
|
||||
@@ -6,22 +6,28 @@
|
||||
#include "span_writer.h"
|
||||
#include "callback_list.h"
|
||||
|
||||
struct net_state {
|
||||
namespace net {
|
||||
|
||||
struct state {
|
||||
eth::mac_addr mac;
|
||||
ipv4::ip4_addr ip;
|
||||
};
|
||||
|
||||
using net_frame_callback = bool (*)(std::span<const uint8_t> frame);
|
||||
using frame_callback = bool (*)(std::span<const uint8_t> frame);
|
||||
|
||||
using frame_cb_list = callback_list<net_frame_callback, 16>;
|
||||
using frame_cb_list = callback_list<frame_callback, 16>;
|
||||
using frame_cb_handle = frame_cb_list::node*;
|
||||
|
||||
using ethertype_handler = void (*)(std::span<const uint8_t> frame, span_writer& tx);
|
||||
using mac_filter = bool (*)(const eth::mac_addr& dst);
|
||||
|
||||
bool net_init();
|
||||
const net_state& net_get_state();
|
||||
frame_cb_handle net_add_frame_callback(net_frame_callback cb);
|
||||
void net_remove_frame_callback(frame_cb_handle h);
|
||||
void net_poll(std::span<uint8_t> tx);
|
||||
void net_send_raw(std::span<const uint8_t> data);
|
||||
void net_register_ethertype(uint16_t ethertype_be, ethertype_handler fn);
|
||||
bool init();
|
||||
const state& get_state();
|
||||
frame_cb_handle add_frame_callback(frame_callback cb);
|
||||
void remove_frame_callback(frame_cb_handle h);
|
||||
void poll(std::span<uint8_t> tx);
|
||||
void send_raw(std::span<const uint8_t> data);
|
||||
void register_ethertype(uint16_t ethertype_be, ethertype_handler fn);
|
||||
void register_mac_filter(mac_filter fn);
|
||||
|
||||
} // namespace net
|
||||
|
||||
Reference in New Issue
Block a user