Skip to content

Commit e46f8d8

Browse files
authored
Merge pull request #98 from coroot/pinger
Clean up Pinger code
2 parents 7fbb8a7 + f98e1c1 commit e46f8d8

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

containers/container.go

+6
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,12 @@ func (c *Container) ping() map[netaddr.IP]float64 {
847847
}
848848
targets := make([]netaddr.IP, 0, len(ips))
849849
for ip := range ips {
850+
if ip.IsLoopback() {
851+
continue
852+
}
853+
if !ip.Is4() { // pinger doesn't support IPv6 yet
854+
continue
855+
}
850856
targets = append(targets, ip)
851857
}
852858
rtt, err := pinger.Ping(netNs, selfNetNs, targets, pingTimeout)

pinger/pinger.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,16 @@ func receive(conn *net.IPConn) (*net.IPAddr, *icmp.Echo, time.Time, error) {
176176
}
177177
return nil, nil, ts, err
178178
}
179-
180-
if ts, err = getTimestampFromOutOfBandData(oob, oobn); err != nil {
181-
return nil, nil, ts, fmt.Errorf("failed to get RX timestamp: %s", err)
182-
}
183-
184179
echo, err := extractEchoFromPacket(pktBuf, n)
185180
if err != nil {
186181
return nil, nil, ts, fmt.Errorf("failed to extract ICMP Echo from IPv4 packet %s: %s", ra, err)
187182
}
183+
if echo == nil {
184+
return nil, nil, ts, nil
185+
}
186+
if ts, err = getTimestampFromOutOfBandData(oob, oobn); err != nil {
187+
return nil, nil, ts, fmt.Errorf("failed to get RX timestamp: %s", err)
188+
}
188189
return ra, echo, ts, nil
189190
}
190191

0 commit comments

Comments
 (0)