Skip to content

Commit 8823a28

Browse files
Allow public IP and siteinfo netblock mismatch (#44)
1 parent 8018189 commit 8823a28

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

siteannotator/server.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,22 @@ func (g *siteAnnotator) Annotate(ID *inetdiag.SockID, annotations *annotator.Ann
6262
return nil
6363
}
6464

65+
// NOTE: in a cloud environment, the local IP and public IPs will be in
66+
// different netblocks. The siteinfo configuration only knows about the public
67+
// IP address. Rather than exclude annotations for these cases, `annotate()`
68+
// uses the v4 config (if present) for IPv4 src addresses, and the v6 config (if
69+
// present) for IPv6 src addresses.
6570
func (g *siteAnnotator) annotate(src string, server *annotator.ServerAnnotations) {
6671
n := net.ParseIP(src)
67-
if g.v4.Contains(n) || g.v6.Contains(n) {
68-
// NOTE: this will not annotate private IP addrs.
72+
switch {
73+
case n.To4() != nil && g.v4.IP != nil:
74+
// If src and config are IPv4 addresses.
6975
*server = *g.server
70-
if g.v4.Contains(n) {
71-
(*server).Network.CIDR = g.v4.String()
72-
}
73-
if g.v6.Contains(n) {
74-
(*server).Network.CIDR = g.v6.String()
75-
}
76+
(*server).Network.CIDR = g.v4.String()
77+
case n.To4() == nil && g.v6.IP != nil:
78+
// If src and config are IPv6 addresses.
79+
*server = *g.server
80+
(*server).Network.CIDR = g.v6.String()
7681
}
7782
}
7883

siteannotator/server_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func TestNew(t *testing.T) {
115115
},
116116
},
117117
{
118-
name: "success-empty-ipv4-with-ipv6-connection",
118+
name: "success-no-ipv4-config-with-ipv6-connection",
119119
localIPs: []net.IP{net.ParseIP("2001:5a0:4300::2")},
120120
provider: &localRawfile,
121121
hostname: "mlab1.six02.measurement-lab.org",
@@ -130,7 +130,7 @@ func TestNew(t *testing.T) {
130130
},
131131
},
132132
{
133-
name: "success-empty-ipv4-with-ipv4-connection",
133+
name: "success-no-ipv4-config-with-ipv4-connection",
134134
localIPs: []net.IP{net.ParseIP("64.86.148.137")},
135135
provider: &localRawfile,
136136
hostname: "mlab1.six02.measurement-lab.org",
@@ -143,7 +143,7 @@ func TestNew(t *testing.T) {
143143
want: annotator.Annotations{},
144144
},
145145
{
146-
name: "success-empty-ipv6-with-ipv4-connection",
146+
name: "success-no-ipv6-config-with-ipv4-connection",
147147
localIPs: []net.IP{net.ParseIP("64.86.148.130")},
148148
provider: &localRawfile,
149149
hostname: "mlab1.six01.measurement-lab.org",
@@ -158,7 +158,7 @@ func TestNew(t *testing.T) {
158158
},
159159
},
160160
{
161-
name: "success-empty-ipv6-with-ipv6-connection",
161+
name: "success-no-ipv6-config-with-ipv6-connection",
162162
localIPs: []net.IP{net.ParseIP("2001:5a0:4300::2")},
163163
provider: &localRawfile,
164164
hostname: "mlab1.six01.measurement-lab.org",

0 commit comments

Comments
 (0)