Merge pull request #98 from yetifrisstlama/icmp

icmp: only send a ping reply to type 8 (ping request) packets
This commit is contained in:
enjoy-digital 2022-01-05 08:35:20 +01:00 committed by GitHub
commit b317dc3558
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 Constants/Header ----------------------------------------------------------------------------
icmp_protocol = 0x01 icmp_protocol = 0x01
icmp_type_ping_reply = 0
icmp_type_ping_request = 8
icmp_header_length = 8 icmp_header_length = 8
icmp_header_fields = { icmp_header_fields = {
"msgtype": HeaderField(0, 0, 8), "msgtype": HeaderField(0, 0, 8),

View File

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