fix multiple default gw

when the configuration specifies both an IPv4 and IPv6 default route,
the IsFilterV4Gateway and IsFilterV6Gateway flags should both be false,
to allow the gateway configuration.
The logic in CheckGatewayConfig would do the inverse, setting both to
true in case of both IPv4 and IPv6 gateway.

Fixes: d52f2b6a ("Update libcni cache when default-route net selection
is used")
Signed-off-by: Tim Froidcoeur <tim.froidcoeur@tessares.net>
This commit is contained in:
Tim Froidcoeur 2022-08-30 15:29:53 +02:00
parent d93a3bb736
commit 8da20f38ea
2 changed files with 50 additions and 9 deletions

View File

@ -628,16 +628,14 @@ func CheckGatewayConfig(delegates []*DelegateNetConf) error {
// set filter flag for each delegate
for i, delegate := range delegates {
// no GatewayRequest
if delegate.GatewayRequest == nil {
delegates[i].IsFilterV4Gateway = true
delegates[i].IsFilterV6Gateway = true
} else {
delegates[i].IsFilterV4Gateway = true
delegates[i].IsFilterV6Gateway = true
if delegate.GatewayRequest != nil {
for _, gw := range *delegate.GatewayRequest {
if gw.To4() != nil {
delegates[i].IsFilterV6Gateway = true
delegates[i].IsFilterV4Gateway = false
} else {
delegates[i].IsFilterV4Gateway = true
delegates[i].IsFilterV6Gateway = false
}
}
}

View File

@ -928,7 +928,12 @@ var _ = Describe("config operations", func() {
netconf, err := LoadDelegateNetConf([]byte(conf), ns, "", "")
Expect(err).NotTo(HaveOccurred())
Expect(CheckGatewayConfig([]*DelegateNetConf{netconf})).To(Succeed())
Expect(netconf.GatewayRequest).To(BeNil())
Expect(netconf.IsFilterV4Gateway).To(BeTrue())
Expect(netconf.IsFilterV6Gateway).To(BeTrue())
})
It("test LoadDelegateNetConf keeps empty GatewayRequest", func() {
@ -950,8 +955,13 @@ var _ = Describe("config operations", func() {
netconf, err := LoadDelegateNetConf([]byte(conf), ns, "", "")
Expect(err).NotTo(HaveOccurred())
Expect(CheckGatewayConfig([]*DelegateNetConf{netconf})).To(Succeed())
Expect(netconf.GatewayRequest).NotTo(BeNil())
Expect(len(*netconf.GatewayRequest)).To(BeEquivalentTo(0))
Expect(len(*netconf.GatewayRequest)).To(Equal(0))
Expect(netconf.IsFilterV4Gateway).To(BeTrue())
Expect(netconf.IsFilterV6Gateway).To(BeTrue())
})
It("test LoadDelegateNetConf keeps GatewayRequest", func() {
@ -973,8 +983,41 @@ var _ = Describe("config operations", func() {
netconf, err := LoadDelegateNetConf([]byte(conf), ns, "", "")
Expect(err).NotTo(HaveOccurred())
Expect(CheckGatewayConfig([]*DelegateNetConf{netconf})).To(Succeed())
Expect(netconf.GatewayRequest).NotTo(BeNil())
Expect(len(*netconf.GatewayRequest)).To(BeEquivalentTo(1))
Expect(len(*netconf.GatewayRequest)).To(Equal(1))
Expect(netconf.IsFilterV4Gateway).To(BeFalse())
Expect(netconf.IsFilterV6Gateway).To(BeTrue())
})
It("test LoadDelegateNetConf keeps dual GatewayRequest", func() {
conf := `{
"name": "node-cni-network",
"type": "multus",
"kubeconfig": "/etc/kubernetes/node-kubeconfig.yaml",
"delegates": [{
"name": "weave-list",
"plugins": [ {"type" :"weave"} ]
}]
}`
nsJSON := `{ "name": "foobar", "default-route": [ "10.1.1.1", "fc00::1" ] }`
ns := &NetworkSelectionElement{}
err := json.Unmarshal([]byte(nsJSON), ns)
Expect(err).NotTo(HaveOccurred())
netconf, err := LoadDelegateNetConf([]byte(conf), ns, "", "")
Expect(err).NotTo(HaveOccurred())
Expect(CheckGatewayConfig([]*DelegateNetConf{netconf})).To(Succeed())
Expect(netconf.GatewayRequest).NotTo(BeNil())
Expect(len(*netconf.GatewayRequest)).To(Equal(2))
Expect(netconf.IsFilterV4Gateway).To(BeFalse())
Expect(netconf.IsFilterV6Gateway).To(BeFalse())
})
})