Skip to content

Commit cb531cc

Browse files
authored
Append IPv6 address to localIPs (#63)
* 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.
1 parent a9f9600 commit cb531cc

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

siteannotator/server.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,16 @@ func (g *siteAnnotator) load(ctx context.Context, localIPs []net.IP) (*annotator
124124
if err != nil {
125125
return nil, nil, err
126126
}
127-
// If this is a virtual site, append the site's public IP address to
128-
// localIPs. The public address of the load balancer is not known on any
129-
// interface on the machine. Without adding it to localIPs,
130-
// uuid-annotator will fail to recognize its own public address in
127+
// If this is a virtual site, append the site's public IP addresses to
128+
// localIPs. The public addresses of the load balancer are not known on
129+
// any interface on the machine. Without adding them to localIPs,
130+
// uuid-annotator will fail to recognize its own public addresses in
131131
// either the Src or Dest fields of incoming tcp-info events, and will
132132
// fail to annotate anything.
133133
if v.Type == "virtual" {
134-
// Ignore IPNet and error, since parseCIDR() above has already
135-
// validated the IP addresses.
136-
ip, _, _ := net.ParseCIDR(v.Network.IPv4)
137-
localIPs = append(localIPs, ip)
134+
localIPs = append(localIPs, g.v4.IP, g.v6.IP)
138135
}
136+
139137
return &v.Annotation, localIPs, nil
140138
}
141139
return nil, nil, ErrHostnameNotFound

siteannotator/server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func Test_srvannotator_load(t *testing.T) {
289289
ASName: "TATA COMMUNICATIONS (AMERICA) INC",
290290
},
291291
},
292-
wantLocalIPs: append(testLocalIPs, net.ParseIP("64.86.148.129")),
292+
wantLocalIPs: append(testLocalIPs, net.ParseIP("64.86.148.129").To4(), net.ParseIP("2001:5a0:4300::")),
293293
},
294294
{
295295
name: "error-bad-ipv4",

0 commit comments

Comments
 (0)