(t *testing.T)
| 54 | } |
| 55 | |
| 56 | func TestDecodeICMP(t *testing.T) { |
| 57 | ipDecoder := NewIPDecoder() |
| 58 | icmpDecoder := NewICMPDecoder() |
| 59 | var ( |
| 60 | ipv4Packet = IP{ |
| 61 | Src: netip.MustParseAddr("172.16.0.1"), |
| 62 | Dst: netip.MustParseAddr("10.0.0.1"), |
| 63 | Protocol: layers.IPProtocolICMPv4, |
| 64 | TTL: DefaultTTL, |
| 65 | } |
| 66 | ipv6Packet = IP{ |
| 67 | Src: netip.MustParseAddr("fd51:2391:523:f4ee::1"), |
| 68 | Dst: netip.MustParseAddr("fd51:2391:697:f4ee::2"), |
| 69 | Protocol: layers.IPProtocolICMPv6, |
| 70 | TTL: DefaultTTL, |
| 71 | } |
| 72 | icmpID = 100 |
| 73 | icmpSeq = 52819 |
| 74 | ) |
| 75 | tests := []struct { |
| 76 | testCase string |
| 77 | packet *ICMP |
| 78 | }{ |
| 79 | { |
| 80 | testCase: "icmpv4 time exceed", |
| 81 | packet: &ICMP{ |
| 82 | IP: &ipv4Packet, |
| 83 | Message: &icmp.Message{ |
| 84 | Type: ipv4.ICMPTypeTimeExceeded, |
| 85 | Code: 0, |
| 86 | Body: &icmp.TimeExceeded{ |
| 87 | Data: []byte("original packet"), |
| 88 | }, |
| 89 | }, |
| 90 | }, |
| 91 | }, |
| 92 | { |
| 93 | testCase: "icmpv4 echo", |
| 94 | packet: &ICMP{ |
| 95 | IP: &ipv4Packet, |
| 96 | Message: &icmp.Message{ |
| 97 | Type: ipv4.ICMPTypeEcho, |
| 98 | Code: 0, |
| 99 | Body: &icmp.Echo{ |
| 100 | ID: icmpID, |
| 101 | Seq: icmpSeq, |
| 102 | Data: []byte("icmpv4 echo"), |
| 103 | }, |
| 104 | }, |
| 105 | }, |
| 106 | }, |
| 107 | { |
| 108 | testCase: "icmpv6 destination unreachable", |
| 109 | packet: &ICMP{ |
| 110 | IP: &ipv6Packet, |
| 111 | Message: &icmp.Message{ |
| 112 | Type: ipv6.ICMPTypeDestinationUnreachable, |
| 113 | Code: 4, |
nothing calls this directly
no test coverage detected