From cc76329219e1718a2f748ebd4aadf1a487d52b60 Mon Sep 17 00:00:00 2001 From: Danil Sidoruk Date: Sat, 22 Mar 2025 21:36:22 +0300 Subject: [PATCH 1/4] Cleanup CMakeLists.txt, find fmt with find_package --- CMakeLists.txt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c0c3686..83e7908 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,13 +4,11 @@ project(mstack LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) -# find_package (glog REQUIRED) +find_package(fmt REQUIRED) +find_package (glog REQUIRED) + add_compile_options(-g) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) - -# aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src SRC) - add_executable(mstack main.cpp) - -target_link_libraries (mstack glog gflags fmt pthread m) \ No newline at end of file +target_link_libraries(mstack glog::glog fmt::fmt pthread m) \ No newline at end of file From 929f0fc1784ea037df86da2609636b8e43005f58 Mon Sep 17 00:00:00 2001 From: Danil Sidoruk Date: Sat, 22 Mar 2025 21:38:30 +0300 Subject: [PATCH 2/4] Fix compilation with gcc 13.3, fmt 11.0.0 --- include/arp_cache.hpp | 1 + include/utils.hpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/arp_cache.hpp b/include/arp_cache.hpp index 9094a18..58d131c 100644 --- a/include/arp_cache.hpp +++ b/include/arp_cache.hpp @@ -1,4 +1,5 @@ #pragma once +#include #include #include "ipv4_addr.hpp" diff --git a/include/utils.hpp b/include/utils.hpp index 4459407..a58c139 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -1,5 +1,5 @@ #pragma once -#include +#include #include #include @@ -9,7 +9,7 @@ namespace utils { template inline std::string format(std::string format, A&&... a) { std::ostringstream os; - ::fmt::fprintf(os, format, std::forward(a)...); + fmt::print(os, format, std::forward(a)...); return os.str(); } From 6aa94e29275c4b7baae2637e2f3295cd853bd990 Mon Sep 17 00:00:00 2001 From: Danil Sidoruk Date: Sun, 23 Mar 2025 15:41:34 +0300 Subject: [PATCH 3/4] Fix usage of utils::format --- include/ipv4_addr.hpp | 2 +- include/mac_addr.hpp | 2 +- include/utils.hpp | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/ipv4_addr.hpp b/include/ipv4_addr.hpp index 4fa67c9..c680e9f 100644 --- a/include/ipv4_addr.hpp +++ b/include/ipv4_addr.hpp @@ -44,7 +44,7 @@ class ipv4_addr_t { void produce(uint8_t*& ptr) { utils::produce(ptr, _ipv4); } friend std::ostream& operator<<(std::ostream& out, ipv4_addr_t ipv4) { - out << utils::format("%u.%u.%u.%u", (ipv4._ipv4 >> 24) & 0xFF, + out << utils::format("{}.{}.{}.{}", (ipv4._ipv4 >> 24) & 0xFF, (ipv4._ipv4 >> 16) & 0xFF, (ipv4._ipv4 >> 8) & 0xFF, (ipv4._ipv4 >> 0) & 0xFF); return out; diff --git a/include/mac_addr.hpp b/include/mac_addr.hpp index 1f1f96e..957b864 100644 --- a/include/mac_addr.hpp +++ b/include/mac_addr.hpp @@ -67,7 +67,7 @@ struct mac_addr_t { friend std::ostream& operator<<(std::ostream& out, const mac_addr_t& m) { using u = uint32_t; - out << utils::format("%02X:%02X:%02X:%02X:%02X:%02X", + out << utils::format("{:X}:{:X}:{:X}:{:X}:{:X}:{:X}", u(m.mac[0]), u(m.mac[1]), u(m.mac[2]), u(m.mac[3]), u(m.mac[4]), u(m.mac[5])); return out; diff --git a/include/utils.hpp b/include/utils.hpp index a58c139..a6a5973 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -21,14 +21,14 @@ inline static int run_cmd(std::string fmt, A&&... a) { } static int set_interface_route(std::string dev, std::string cidr) { - return run_cmd("ip route add dev %s %s", dev, cidr); + return run_cmd("ip route add dev {} {}", dev, cidr); } static int set_interface_address(std::string dev, std::string cidr) { - return run_cmd("ip address add dev %s local %s", dev, cidr); + return run_cmd("ip address add dev {} local {}", dev, cidr); } -static int set_interface_up(std::string dev) { return run_cmd("ip link set dev %s up", dev); } +static int set_interface_up(std::string dev) { return run_cmd("ip link set dev {} up", dev); } uint32_t ntoh(uint32_t value) { return (value & 0x000000FFU) << 24 | (value & 0x0000FF00U) << 8 | From 85f80e1cf738339260964977ae87c3694ef30cff Mon Sep 17 00:00:00 2001 From: Danil Sidoruk Date: Sun, 23 Mar 2025 15:41:54 +0300 Subject: [PATCH 4/4] Fix compilation warnings --- include/api.hpp | 1 + include/defination.hpp | 1 + include/mac_addr.hpp | 2 ++ include/socket_manager.hpp | 3 +++ include/tcp_transmit.hpp | 4 ++++ 5 files changed, 11 insertions(+) diff --git a/include/api.hpp b/include/api.hpp index 5999b36..fd04c71 100644 --- a/include/api.hpp +++ b/include/api.hpp @@ -19,6 +19,7 @@ int init_logger(int argc, char* argv[]) { gflags::ParseCommandLineFlags(&argc, &argv, true); google::InitGoogleLogging(argv[0]); + return 0; } void init_stack(int argc, char* argv[]) { diff --git a/include/defination.hpp b/include/defination.hpp index a3141a4..a823da7 100644 --- a/include/defination.hpp +++ b/include/defination.hpp @@ -43,5 +43,6 @@ std::string state_to_string(int state) { case TCP_TIME_WAIT: return "TCP_TIME_WAIT"; } + return "UNKNOWN"; } }; // namespace mstack \ No newline at end of file diff --git a/include/mac_addr.hpp b/include/mac_addr.hpp index 957b864..a5cee19 100644 --- a/include/mac_addr.hpp +++ b/include/mac_addr.hpp @@ -25,10 +25,12 @@ struct mac_addr_t { std::copy(std::begin(other.mac), std::end(other.mac), std::begin(mac)); } + return *this; } mac_addr_t& operator=(mac_addr_t&& other) { std::swap(mac, other.mac); + return *this; }; mac_addr_t(std::array other) { diff --git a/include/socket_manager.hpp b/include/socket_manager.hpp index 35580b0..7c08ada 100644 --- a/include/socket_manager.hpp +++ b/include/socket_manager.hpp @@ -50,6 +50,7 @@ class socket_manager { listeners[fd] = listener; auto& tcb_manager = tcb_manager::instance(); tcb_manager.listen_port(listener->local_info.value(), listener); + return 0; }; int accept(int fd) { @@ -87,6 +88,7 @@ class socket_manager { raw_packet r_packet = std::move(socket->tcb.value()->receive_queue.pop_front().value()); r_packet.buffer->export_data(reinterpret_cast(buf), len); + return 0; } int write(int fd, char* buf, int& len) { @@ -98,6 +100,7 @@ class socket_manager { std::make_unique(reinterpret_cast(buf), len); raw_packet r_packet = {.buffer = std::move(out_buffer)}; socket->tcb.value()->send_queue.push_back(std::move(r_packet)); + return 0; } }; }; // namespace mstack \ No newline at end of file diff --git a/include/tcp_transmit.hpp b/include/tcp_transmit.hpp index 21530b3..9a9da1a 100644 --- a/include/tcp_transmit.hpp +++ b/include/tcp_transmit.hpp @@ -44,6 +44,8 @@ class tcp_transmit { if (in_tcp.ACK == 1) { return true; } + + return false; } static bool tcp_handle_listen_state(std::shared_ptr in_tcb, @@ -336,6 +338,8 @@ class tcp_transmit { } } } + + return false; } static void tcp_in(std::shared_ptr in_tcb, tcp_packet_t& in_packet) {