Compare commits
3 Commits
2d7ff98b82
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
30f3eae111 | ||
|
|
71c07957f8 | ||
|
|
a56e034bfb |
@@ -7,15 +7,15 @@ add_subdirectory(msgpack)
|
||||
add_subdirectory(eth)
|
||||
add_subdirectory(ipv4)
|
||||
add_subdirectory(arp)
|
||||
add_subdirectory(icmp)
|
||||
add_subdirectory(igmp)
|
||||
add_subdirectory(udp)
|
||||
|
||||
add_library(limen STATIC
|
||||
src/dispatch.cpp
|
||||
src/flash.cpp
|
||||
src/handlers.cpp
|
||||
src/icmp.cpp
|
||||
src/igmp.cpp
|
||||
src/test_handlers.cpp
|
||||
src/udp.cpp
|
||||
)
|
||||
|
||||
target_include_directories(limen PUBLIC
|
||||
@@ -32,6 +32,9 @@ target_link_libraries(limen PUBLIC
|
||||
eth
|
||||
ipv4
|
||||
arp
|
||||
icmp
|
||||
igmp
|
||||
udp
|
||||
pico_stdlib
|
||||
pico_sha256
|
||||
)
|
||||
|
||||
@@ -41,10 +41,7 @@ void handle(std::span<const uint8_t> frame, span_writer& tx) {
|
||||
eth::send_raw(buf.span());
|
||||
}
|
||||
|
||||
void init() {}
|
||||
|
||||
__attribute__((constructor))
|
||||
static void register_ethertype() {
|
||||
void init() {
|
||||
eth::register_ethertype(eth::ETH_ARP, handle);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,11 +61,6 @@ void process_frame(std::span<const uint8_t> frame, span_writer& tx) {
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__((constructor))
|
||||
void register_default_mac_filter() {
|
||||
register_mac_filter(default_mac_filter);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void register_ethertype(uint16_t ethertype_be, ethertype_handler fn) {
|
||||
@@ -114,6 +109,8 @@ bool init() {
|
||||
w6300::open_socket(raw_socket, w6300::protocol::macraw, w6300::sock_flag::none);
|
||||
w6300::set_interrupt_mask(w6300::ik_sock_0);
|
||||
|
||||
register_mac_filter(default_mac_filter);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
11
icmp/CMakeLists.txt
Normal file
11
icmp/CMakeLists.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
add_library(icmp STATIC icmp.cpp)
|
||||
|
||||
target_include_directories(icmp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
target_compile_options(icmp PRIVATE -Wall -Wextra -Wno-unused-parameter)
|
||||
|
||||
target_link_libraries(icmp PUBLIC
|
||||
util
|
||||
eth
|
||||
ipv4
|
||||
)
|
||||
@@ -36,8 +36,7 @@ void handle(std::span<const uint8_t> frame, span_writer& tx) {
|
||||
eth::send_raw(buf.span());
|
||||
}
|
||||
|
||||
__attribute__((constructor))
|
||||
static void register_protocol() {
|
||||
void init() {
|
||||
ipv4::register_protocol(1, handle);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ struct __attribute__((packed)) echo {
|
||||
};
|
||||
static_assert(sizeof(echo) == 8);
|
||||
|
||||
void init();
|
||||
void handle(std::span<const uint8_t> frame, span_writer& tx);
|
||||
|
||||
template <typename Buf>
|
||||
11
igmp/CMakeLists.txt
Normal file
11
igmp/CMakeLists.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
add_library(igmp STATIC igmp.cpp)
|
||||
|
||||
target_include_directories(igmp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
target_compile_options(igmp PRIVATE -Wall -Wextra -Wno-unused-parameter)
|
||||
|
||||
target_link_libraries(igmp PUBLIC
|
||||
util
|
||||
eth
|
||||
ipv4
|
||||
)
|
||||
@@ -78,8 +78,7 @@ void handle(std::span<const uint8_t> frame, span_writer& tx) {
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__((constructor))
|
||||
static void register_protocol() {
|
||||
void init() {
|
||||
ipv4::register_protocol(2, handle);
|
||||
eth::register_mac_filter(is_member_mac);
|
||||
ipv4::register_addr_filter(is_member);
|
||||
@@ -17,6 +17,8 @@ struct __attribute__((packed)) message {
|
||||
};
|
||||
static_assert(sizeof(message) == 8);
|
||||
|
||||
void init();
|
||||
|
||||
eth::mac_addr mac_for_ip(const ipv4::ip4_addr& group);
|
||||
bool is_member(const ipv4::ip4_addr& ip);
|
||||
bool is_member_mac(const eth::mac_addr& mac);
|
||||
@@ -31,6 +31,8 @@ bool default_addr_filter(const ip4_addr& dst) {
|
||||
void init() {
|
||||
const auto& mac = eth::get_mac();
|
||||
g_ip = {169, 254, mac[4], mac[5]};
|
||||
eth::register_ethertype(eth::ETH_IPV4, handle);
|
||||
register_addr_filter(default_addr_filter);
|
||||
}
|
||||
|
||||
const ip4_addr& get_ip() {
|
||||
@@ -101,10 +103,4 @@ void handle(std::span<const uint8_t> frame, span_writer& tx) {
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__((constructor))
|
||||
static void register_self() {
|
||||
eth::register_ethertype(eth::ETH_IPV4, handle);
|
||||
register_addr_filter(default_addr_filter);
|
||||
}
|
||||
|
||||
} // namespace ipv4
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "eth.h"
|
||||
#include "ipv4.h"
|
||||
#include "arp.h"
|
||||
#include "icmp.h"
|
||||
#include "igmp.h"
|
||||
#include "udp.h"
|
||||
#include "debug_log.h"
|
||||
@@ -35,10 +36,13 @@ static void on_udp_message(std::span<const uint8_t> payload, const udp::address&
|
||||
|
||||
void dispatch_init(uint16_t port_be) {
|
||||
listen_port_be = port_be;
|
||||
udp::register_port(port_be, on_udp_message);
|
||||
eth::init();
|
||||
ipv4::init();
|
||||
arp::init();
|
||||
icmp::init();
|
||||
igmp::init();
|
||||
udp::init();
|
||||
udp::register_port(port_be, on_udp_message);
|
||||
dispatch_schedule_ms(60000, igmp_reannounce);
|
||||
dlog("dispatch_init complete");
|
||||
}
|
||||
|
||||
12
udp/CMakeLists.txt
Normal file
12
udp/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
add_library(udp STATIC udp.cpp)
|
||||
|
||||
target_include_directories(udp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
target_compile_options(udp PRIVATE -Wall -Wextra -Wno-unused-parameter)
|
||||
|
||||
target_link_libraries(udp PUBLIC
|
||||
util
|
||||
eth
|
||||
ipv4
|
||||
debug_log
|
||||
)
|
||||
@@ -49,8 +49,7 @@ void handle(std::span<const uint8_t> frame, span_writer& tx) {
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__((constructor))
|
||||
static void register_protocol() {
|
||||
void init() {
|
||||
ipv4::register_protocol(17, handle);
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ void prepend(Buf& buf, const eth::mac_addr& dst_mac, const eth::mac_addr& src_ma
|
||||
ipv4::prepend(buf, dst_mac, src_mac, src_ip, dst_ip, 17, sizeof(header) + payload_len, ttl);
|
||||
}
|
||||
|
||||
void init();
|
||||
void handle(std::span<const uint8_t> frame, span_writer& tx);
|
||||
|
||||
using port_handler = void (*)(std::span<const uint8_t> payload, const address& from);
|
||||
Reference in New Issue
Block a user