Skip to content

Commit

Permalink
Merge pull request #98 from coroot/pinger
Browse files Browse the repository at this point in the history
Clean up Pinger code
  • Loading branch information
def authored Jun 13, 2024
2 parents 7fbb8a7 + f98e1c1 commit e46f8d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 6 additions & 0 deletions containers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,12 @@ func (c *Container) ping() map[netaddr.IP]float64 {
}
targets := make([]netaddr.IP, 0, len(ips))
for ip := range ips {
if ip.IsLoopback() {
continue
}
if !ip.Is4() { // pinger doesn't support IPv6 yet
continue
}
targets = append(targets, ip)
}
rtt, err := pinger.Ping(netNs, selfNetNs, targets, pingTimeout)
Expand Down
11 changes: 6 additions & 5 deletions pinger/pinger.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,16 @@ func receive(conn *net.IPConn) (*net.IPAddr, *icmp.Echo, time.Time, error) {
}
return nil, nil, ts, err
}

if ts, err = getTimestampFromOutOfBandData(oob, oobn); err != nil {
return nil, nil, ts, fmt.Errorf("failed to get RX timestamp: %s", err)
}

echo, err := extractEchoFromPacket(pktBuf, n)
if err != nil {
return nil, nil, ts, fmt.Errorf("failed to extract ICMP Echo from IPv4 packet %s: %s", ra, err)
}
if echo == nil {
return nil, nil, ts, nil
}
if ts, err = getTimestampFromOutOfBandData(oob, oobn); err != nil {
return nil, nil, ts, fmt.Errorf("failed to get RX timestamp: %s", err)
}
return ra, echo, ts, nil
}

Expand Down

0 comments on commit e46f8d8

Please sign in to comment.