From f62a464e7e92f212d87a59046df25dea009da08a Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Tue, 2 Sep 2025 12:15:36 +0200 Subject: [PATCH] ipv4: Implement gateway handling Closes #17. --- trashernet/trashernet_ipv4.vhd | 9 ++++++--- trashernet/trashernet_pkg.vhd | 6 ++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/trashernet/trashernet_ipv4.vhd b/trashernet/trashernet_ipv4.vhd index 3760a38..291df5c 100644 --- a/trashernet/trashernet_ipv4.vhd +++ b/trashernet/trashernet_ipv4.vhd @@ -194,6 +194,12 @@ begin if ipv4_in.tx_en then arp_in.arp_query_stb <= '1'; state <= ARP; + + if or((to_std_logic_vector(ipv4_config.gateway) xor to_std_logic_vector(arp_in.arp_ip)) and to_std_logic_vector(ipv4_config.subnet_mask)) then + arp_in.arp_ip <= ipv4_config.gateway; + else + arp_in.arp_ip <= ipv4_in.tx_ip_address; + end if; end if; when ARP => @@ -244,9 +250,6 @@ begin ethernet_ii_in.tx_data <= sr(sr'low); ethernet_ii_in.tx_en <= '1' when (state = HEADER) or (state = PAYLOAD) else '0'; - - arp_in.arp_ip <= ipv4_in.tx_ip_address; - end block tx; end architecture rtl; diff --git a/trashernet/trashernet_pkg.vhd b/trashernet/trashernet_pkg.vhd index 0dfd60c..f2d1d0f 100644 --- a/trashernet/trashernet_pkg.vhd +++ b/trashernet/trashernet_pkg.vhd @@ -32,6 +32,7 @@ package trashernet_pkg is -- IP specific types subtype ip_addr_t is byte_vector(0 to 3); function ip_to_string(constant ip_address : in ip_addr_t) return string; + function to_std_logic_vector(ip_address : ip_addr_t) return std_logic_vector; -- Configuration interface type configuration_t is record @@ -262,6 +263,11 @@ package body trashernet_pkg is ; end function ip_to_string; + function to_std_logic_vector(ip_address : ip_addr_t) return std_logic_vector is + begin + return ip_address(0) & ip_address(1) & ip_address(2) & ip_address(3); + end function to_std_logic_vector; + function to_std_logic(constant bool : boolean) return std_logic is variable ret : std_logic; begin