Skip to content

Commit

Permalink
Append IPv6 address to localIPs (#63)
Browse files Browse the repository at this point in the history
* Appends loadbalancer v6 addr to localIPs

We were already appending the load balancer v4 address to the localIPs variable
so that uuid-annotator would recognize the non-local, public address of the
machine as "local" and not reject it. This change just adds the IPv6 address,
too, since VMs now support both IPv4 and IPv6.

Additionally, this commit removes the redundant call to parseCIDR(), and just
uses the output from a previous invocation of that same function.

* Appends IPv6 address to localIPs in unit test

Additionally, converts the v4 address to a 4 byte representation, which is
apparently the representation of net.IPNet.IP as returned by net.ParseCIDR().
This could be error prone? Maybe we shouldn't be using reflect.DeepEqual() for
comparing slices of IP addresses, since the underlying representation can cause
DeepEqual() to fail, even when the addresses are actually the same.
  • Loading branch information
nkinkade authored Feb 13, 2024
1 parent a9f9600 commit cb531cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
14 changes: 6 additions & 8 deletions siteannotator/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,16 @@ func (g *siteAnnotator) load(ctx context.Context, localIPs []net.IP) (*annotator
if err != nil {
return nil, nil, err
}
// If this is a virtual site, append the site's public IP address to
// localIPs. The public address of the load balancer is not known on any
// interface on the machine. Without adding it to localIPs,
// uuid-annotator will fail to recognize its own public address in
// If this is a virtual site, append the site's public IP addresses to
// localIPs. The public addresses of the load balancer are not known on
// any interface on the machine. Without adding them to localIPs,
// uuid-annotator will fail to recognize its own public addresses in
// either the Src or Dest fields of incoming tcp-info events, and will
// fail to annotate anything.
if v.Type == "virtual" {
// Ignore IPNet and error, since parseCIDR() above has already
// validated the IP addresses.
ip, _, _ := net.ParseCIDR(v.Network.IPv4)
localIPs = append(localIPs, ip)
localIPs = append(localIPs, g.v4.IP, g.v6.IP)
}

return &v.Annotation, localIPs, nil
}
return nil, nil, ErrHostnameNotFound
Expand Down
2 changes: 1 addition & 1 deletion siteannotator/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func Test_srvannotator_load(t *testing.T) {
ASName: "TATA COMMUNICATIONS (AMERICA) INC",
},
},
wantLocalIPs: append(testLocalIPs, net.ParseIP("64.86.148.129")),
wantLocalIPs: append(testLocalIPs, net.ParseIP("64.86.148.129").To4(), net.ParseIP("2001:5a0:4300::")),
},
{
name: "error-bad-ipv4",
Expand Down

0 comments on commit cb531cc

Please sign in to comment.