(t *testing.T)
| 147 | } |
| 148 | |
| 149 | func TestShouldHandlePing(t *testing.T) { |
| 150 | srcIP := netip.AddrFrom4([4]byte{1, 2, 3, 4}) |
| 151 | |
| 152 | t.Run("ICMP4", func(t *testing.T) { |
| 153 | dst := netip.MustParseAddr("5.6.7.8") |
| 154 | icmph := packet.ICMP4Header{ |
| 155 | IP4Header: packet.IP4Header{ |
| 156 | IPProto: ipproto.ICMPv4, |
| 157 | Src: srcIP, |
| 158 | Dst: dst, |
| 159 | }, |
| 160 | Type: packet.ICMP4EchoRequest, |
| 161 | Code: packet.ICMP4NoCode, |
| 162 | } |
| 163 | _, payload := packet.ICMPEchoPayload(nil) |
| 164 | icmpPing := packet.Generate(icmph, payload) |
| 165 | pkt := &packet.Parsed{} |
| 166 | pkt.Decode(icmpPing) |
| 167 | |
| 168 | impl := makeNetstack(t, func(impl *Impl) { |
| 169 | impl.ProcessSubnets = true |
| 170 | }) |
| 171 | pingDst, ok := impl.shouldHandlePing(pkt) |
| 172 | if !ok { |
| 173 | t.Errorf("expected shouldHandlePing==true") |
| 174 | } |
| 175 | if pingDst != dst { |
| 176 | t.Errorf("got dst %s; want %s", pingDst, dst) |
| 177 | } |
| 178 | }) |
| 179 | |
| 180 | t.Run("ICMP6-no-via", func(t *testing.T) { |
| 181 | dst := netip.MustParseAddr("2a09:8280:1::4169") |
| 182 | icmph := packet.ICMP6Header{ |
| 183 | IP6Header: packet.IP6Header{ |
| 184 | IPProto: ipproto.ICMPv6, |
| 185 | Src: srcIP, |
| 186 | Dst: dst, |
| 187 | }, |
| 188 | Type: packet.ICMP6EchoRequest, |
| 189 | Code: packet.ICMP6NoCode, |
| 190 | } |
| 191 | _, payload := packet.ICMPEchoPayload(nil) |
| 192 | icmpPing := packet.Generate(icmph, payload) |
| 193 | pkt := &packet.Parsed{} |
| 194 | pkt.Decode(icmpPing) |
| 195 | |
| 196 | impl := makeNetstack(t, func(impl *Impl) { |
| 197 | impl.ProcessSubnets = true |
| 198 | }) |
| 199 | pingDst, ok := impl.shouldHandlePing(pkt) |
| 200 | |
| 201 | // Expect that we handle this since it's going out onto the |
| 202 | // network. |
| 203 | if !ok { |
| 204 | t.Errorf("expected shouldHandlePing==true") |
| 205 | } |
| 206 | if pingDst != dst { |
nothing calls this directly
no test coverage detected
searching dependent graphs…