diff --git a/liteeth/common.py b/liteeth/common.py index f70a97e..81f0a35 100644 --- a/liteeth/common.py +++ b/liteeth/common.py @@ -88,11 +88,11 @@ ipv4_header = Header(ipv4_header_fields, ipv4_header_length, swap_field_bytes=Tr # ICMP Constants/Header ---------------------------------------------------------------------------- -icmp_protocol = 0x01 -icmp_type_ping_reply = 0 +icmp_protocol = 0x01 +icmp_type_ping_reply = 0 icmp_type_ping_request = 8 -icmp_header_length = 8 -icmp_header_fields = { +icmp_header_length = 8 +icmp_header_fields = { "msgtype": HeaderField(0, 0, 8), "code": HeaderField(1, 0, 8), "checksum": HeaderField(2, 0, 16), diff --git a/liteeth/core/icmp.py b/liteeth/core/icmp.py index bf13b2e..294e0dd 100644 --- a/liteeth/core/icmp.py +++ b/liteeth/core/icmp.py @@ -105,7 +105,8 @@ class LiteEthICMPRX(LiteXModule): "quench", "data", "error", - "last_be"}), + "last_be" + }), source.ip_address.eq(sink.ip_address), source.length.eq(sink.length - icmp_header.length), ] @@ -141,7 +142,13 @@ class LiteEthICMPEcho(LiteXModule): buffered = True ) self.comb += [ - sink.connect(self.buffer.sink), + # Connect to buffer when length <= buffer's depth. + If(sink.length <= fifo_depth, + sink.connect(self.buffer.sink) + # Else drop. + ).Else( + sink.ready.eq(1) + ), self.buffer.source.connect(source, omit={"checksum"}), self.source.msgtype.eq(icmp_type_ping_reply), self.source.checksum.eq(self.buffer.source.checksum + 0x800 + (self.buffer.source.checksum >= 0xf800)) diff --git a/liteeth/core/ip.py b/liteeth/core/ip.py index 2320c52..84e8e28 100644 --- a/liteeth/core/ip.py +++ b/liteeth/core/ip.py @@ -235,7 +235,7 @@ class LiteEthIPRX(LiteXModule): "data", "error", "last_be"}), - source.length.eq(depacketizer.source.total_length - (0x5*4)), + source.length.eq(depacketizer.source.total_length - ipv4_header_length), source.ip_address.eq(depacketizer.source.sender_ip), ] fsm.act("RECEIVE",