icmp.py: take icmp type field into account

* only send a ping reply to type 8 (ping request) packets
  * otherwise liteeth would send a ping reply to
    `destination unreachable` packets too, which is not wanted
This commit is contained in:
Michael Betz 2021-12-27 23:39:35 +01:00
parent a8d9c5ef6a
commit bc073a5d2c
2 changed files with 6 additions and 2 deletions

View file

@ -84,6 +84,8 @@ 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_type_ping_request = 8
icmp_header_length = 8
icmp_header_fields = {
"msgtype": HeaderField(0, 0, 8),

View file

@ -86,10 +86,12 @@ class LiteEthICMPRX(Module):
If(depacketizer.source.valid,
NextState("DROP"),
If(sink.protocol == icmp_protocol,
If(depacketizer.source.msgtype == icmp_type_ping_request,
NextState("RECEIVE")
)
)
)
)
self.comb += [
depacketizer.source.connect(source, keep={
"last",
@ -137,7 +139,7 @@ class LiteEthICMPEcho(Module):
self.comb += [
sink.connect(self.buffer.sink),
self.buffer.source.connect(source, omit={"checksum"}),
self.source.msgtype.eq(0x0),
self.source.msgtype.eq(icmp_type_ping_reply),
self.source.checksum.eq(self.buffer.source.checksum + 0x800 + (self.buffer.source.checksum >= 0xf800))
]