Skip to content

Commit

Permalink
Skip linux-bridge filtering if no "bridge" section
Browse files Browse the repository at this point in the history
We have found that at some envs the "bridge" section from linux-bridge
is not present in case the bridge is down, this change ignore the
filtering in this is the case to preveng a segmentation fault.

Signed-off-by: Quique Llorente <[email protected]>
  • Loading branch information
qinqon committed Feb 1, 2021
1 parent e0daac1 commit cedbf10
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
19 changes: 17 additions & 2 deletions pkg/state/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,24 @@ func filterOutDynamicAttributes(iface map[string]interface{}) {
return
}

bridge := iface["bridge"].(map[string]interface{})
bridgeIface, ok := iface["bridge"]
if !ok {
return
}
bridge, ok := bridgeIface.(map[string]interface{})
if !ok {
return
}

optionsIface, ok := bridge["options"]
if !ok {
return
}
options, ok := optionsIface.(map[string]interface{})
if !ok {
return
}

options := bridge["options"].(map[string]interface{})
delete(options, "gc-timer")
delete(options, "hello-timer")
}
Expand Down
62 changes: 62 additions & 0 deletions pkg/state/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,66 @@ routes:
Expect(returnedState).To(MatchYAML(filteredState))
})
})
Context("when there is a linux bridge without 'bridge' options because is down", func() {
BeforeEach(func() {
state = nmstate.NewState(`
interfaces:
- name: eth1
state: up
type: ethernet
- name: br1
type: linux-bridge
state: down
ipv4:
enabled: false
ipv6:
enabled: false
lldp:
enabled: false
mac-address: A2:EE:84:7B:42:4C
mtu: 1500
routes:
config: []
running:
- destination: 0.0.0.0/0
metric: 102
next-hop-address: 192.168.66.2
next-hop-interface: eth1
table-id: 254
`)

filteredState = nmstate.NewState(`
interfaces:
- name: eth1
state: up
type: ethernet
- name: br1
type: linux-bridge
state: down
ipv4:
enabled: false
ipv6:
enabled: false
lldp:
enabled: false
mac-address: A2:EE:84:7B:42:4C
mtu: 1500
routes:
config: []
running:
- destination: 0.0.0.0/0
metric: 102
next-hop-address: 192.168.66.2
next-hop-interface: eth1
table-id: 254
`)
interfacesFilterGlob = glob.MustCompile("")
})
It("should keep the bridge as it is", func() {
returnedState, err := filterOut(state, interfacesFilterGlob)
Expect(err).ToNot(HaveOccurred())
Expect(returnedState).To(MatchYAML(filteredState))
})
})

})

0 comments on commit cedbf10

Please sign in to comment.