Skip to content

Commit 7ac4cf9

Browse files
committed
server: Remove CIDR blocks in refined data
1 parent 7795c15 commit 7ac4cf9

File tree

1 file changed

+3
-44
lines changed

1 file changed

+3
-44
lines changed

server/pkg/api/rest/controller/getRefined.go

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ func doGetRefinedNetworkInfo(networkProperty *inframodel.NetworkProperty, routes
194194
continue
195195
}
196196

197-
if route.Family == "ipv4" {
197+
switch route.Family {
198+
case "ipv4":
198199
if route.Destination == "0.0.0.0" && route.Netmask == "0.0.0.0" {
199200
var gatewayProperty inframodel.GatewayProperty
200201

@@ -203,28 +204,8 @@ func doGetRefinedNetworkInfo(networkProperty *inframodel.NetworkProperty, routes
203204
gatewayProperty.MachineId = *machineID
204205

205206
networkProperty.IPv4Networks.DefaultGateways = append(networkProperty.IPv4Networks.DefaultGateways, gatewayProperty)
206-
} else {
207-
var dup bool
208-
209-
cidr, err := netmaskToCIDR(route.Destination)
210-
if err != nil {
211-
logger.Println(logger.ERROR, true, err.Error())
212-
}
213-
cidrBlock := route.Destination + "/" + strconv.Itoa(cidr)
214-
215-
for _, ipv4CidrBlock := range networkProperty.IPv4Networks.CidrBlocks {
216-
if ipv4CidrBlock == cidrBlock {
217-
dup = true
218-
break
219-
}
220-
}
221-
if dup {
222-
continue
223-
}
224-
225-
networkProperty.IPv4Networks.CidrBlocks = append(networkProperty.IPv4Networks.CidrBlocks, cidrBlock)
226207
}
227-
} else if route.Family == "ipv6" {
208+
case "ipv6":
228209
if route.Destination == "::" && route.Netmask == "/0" {
229210
var gatewayProperty inframodel.GatewayProperty
230211

@@ -233,28 +214,6 @@ func doGetRefinedNetworkInfo(networkProperty *inframodel.NetworkProperty, routes
233214
gatewayProperty.MachineId = *machineID
234215

235216
networkProperty.IPv6Networks.DefaultGateways = append(networkProperty.IPv6Networks.DefaultGateways, gatewayProperty)
236-
} else {
237-
if strings.HasPrefix(route.Destination, "fe80:") { // Skip lick local addresses
238-
continue
239-
} else if strings.HasPrefix(route.Destination, "ff") { // Skip multicast addresses
240-
continue
241-
}
242-
243-
var dup bool
244-
245-
cidrBlock := route.Destination + route.Netmask
246-
247-
for _, ipv6CidrBlock := range networkProperty.IPv6Networks.CidrBlocks {
248-
if ipv6CidrBlock == cidrBlock {
249-
dup = true
250-
break
251-
}
252-
}
253-
if dup {
254-
continue
255-
}
256-
257-
networkProperty.IPv6Networks.CidrBlocks = append(networkProperty.IPv6Networks.CidrBlocks, cidrBlock)
258217
}
259218
}
260219
}

0 commit comments

Comments
 (0)