#pragma once #include #include #include "eth.h" #include "ipv4.h" #include "span_writer.h" #include "callback_list.h" namespace net { struct state { eth::mac_addr mac; ipv4::ip4_addr ip; }; using frame_callback = bool (*)(std::span frame); using frame_cb_list = callback_list; using frame_cb_handle = frame_cb_list::node*; using ethertype_handler = void (*)(std::span frame, span_writer& tx); using mac_filter = bool (*)(const eth::mac_addr& dst); 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 tx); void send_raw(std::span data); void register_ethertype(uint16_t ethertype_be, ethertype_handler fn); void register_mac_filter(mac_filter fn); } // namespace net