ipv4: Implement gateway handling

Closes #17.
This commit is contained in:
Markus Koch 2025-09-02 12:15:36 +02:00
parent 9f0f8c2775
commit f62a464e7e
2 changed files with 12 additions and 3 deletions

View File

@ -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;

View File

@ -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