core/icmp/LiteEthICMPEcho: Verify packet length before storing in buffer and drop if too long for configurated depth.

This commit is contained in:
Florent Kermarrec 2023-07-10 11:13:52 +02:00
parent 31893a2d25
commit 0d89c59c89
3 changed files with 14 additions and 7 deletions

View File

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

View File

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

View File

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