-
Notifications
You must be signed in to change notification settings - Fork 836
bridge: Enable disabling bridge interface #997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,19 +47,20 @@ const defaultBrName = "cni0" | |
|
|
||
| type NetConf struct { | ||
| types.NetConf | ||
| BrName string `json:"bridge"` | ||
| IsGW bool `json:"isGateway"` | ||
| IsDefaultGW bool `json:"isDefaultGateway"` | ||
| ForceAddress bool `json:"forceAddress"` | ||
| IPMasq bool `json:"ipMasq"` | ||
| MTU int `json:"mtu"` | ||
| HairpinMode bool `json:"hairpinMode"` | ||
| PromiscMode bool `json:"promiscMode"` | ||
| Vlan int `json:"vlan"` | ||
| VlanTrunk []*VlanTrunk `json:"vlanTrunk,omitempty"` | ||
| PreserveDefaultVlan bool `json:"preserveDefaultVlan"` | ||
| MacSpoofChk bool `json:"macspoofchk,omitempty"` | ||
| EnableDad bool `json:"enabledad,omitempty"` | ||
| BrName string `json:"bridge"` | ||
| IsGW bool `json:"isGateway"` | ||
| IsDefaultGW bool `json:"isDefaultGateway"` | ||
| ForceAddress bool `json:"forceAddress"` | ||
| IPMasq bool `json:"ipMasq"` | ||
| MTU int `json:"mtu"` | ||
| HairpinMode bool `json:"hairpinMode"` | ||
| PromiscMode bool `json:"promiscMode"` | ||
| Vlan int `json:"vlan"` | ||
| VlanTrunk []*VlanTrunk `json:"vlanTrunk,omitempty"` | ||
| PreserveDefaultVlan bool `json:"preserveDefaultVlan"` | ||
| MacSpoofChk bool `json:"macspoofchk,omitempty"` | ||
| EnableDad bool `json:"enabledad,omitempty"` | ||
| DisableContainerInterface bool `json:"disableContainerInterface,omitempty"` | ||
|
|
||
| Args struct { | ||
| Cni BridgeArgs `json:"cni,omitempty"` | ||
|
|
@@ -530,6 +531,10 @@ func cmdAdd(args *skel.CmdArgs) error { | |
|
|
||
| isLayer3 := n.IPAM.Type != "" | ||
|
|
||
| if isLayer3 && n.DisableContainerInterface { | ||
| return fmt.Errorf("cannot use IPAM when DisableContainerInterface flag is set") | ||
| } | ||
|
|
||
| if n.IsDefaultGW { | ||
| n.IsGW = true | ||
| } | ||
|
|
@@ -676,12 +681,13 @@ func cmdAdd(args *skel.CmdArgs) error { | |
| } | ||
| } | ||
| } | ||
| } else { | ||
| } else if !n.DisableContainerInterface { | ||
| if err := netns.Do(func(_ ns.NetNS) error { | ||
| link, err := netlink.LinkByName(args.IfName) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to retrieve link: %v", err) | ||
| } | ||
|
|
||
| // If layer 2 we still need to set the container veth to up | ||
| if err = netlink.LinkSetUp(link); err != nil { | ||
| return fmt.Errorf("failed to set %q up: %v", args.IfName, err) | ||
|
|
@@ -692,23 +698,28 @@ func cmdAdd(args *skel.CmdArgs) error { | |
| } | ||
| } | ||
|
|
||
| var hostVeth netlink.Link | ||
| hostVeth, err := netlink.LinkByName(hostInterface.Name) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // check bridge port state | ||
| retries := []int{0, 50, 500, 1000, 1000} | ||
| for idx, sleep := range retries { | ||
| time.Sleep(time.Duration(sleep) * time.Millisecond) | ||
| if !n.DisableContainerInterface { | ||
| // check bridge port state | ||
| retries := []int{0, 50, 500, 1000, 1000} | ||
| for idx, sleep := range retries { | ||
| time.Sleep(time.Duration(sleep) * time.Millisecond) | ||
|
|
||
| hostVeth, err = netlink.LinkByName(hostInterface.Name) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if hostVeth.Attrs().OperState == netlink.OperUp { | ||
| break | ||
| } | ||
| hostVeth, err = netlink.LinkByName(hostInterface.Name) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if hostVeth.Attrs().OperState == netlink.OperUp { | ||
| break | ||
| } | ||
|
|
||
| if idx == len(retries)-1 { | ||
| return fmt.Errorf("bridge port in error state: %s", hostVeth.Attrs().OperState) | ||
| if idx == len(retries)-1 { | ||
| return fmt.Errorf("bridge port in error state: %s", hostVeth.Attrs().OperState) | ||
| } | ||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from line 581 to here, nothing should be run (except hostVeth initialization) when DisableContainerInterface is set, so I think we could encapsulate this in a function to improve readability. We could simply call that function when DisableContainerInterface is false. Or multiple functions, something like: checkBridgePortSTate() WDYT?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have posted a PR for small refactoring around the places this PR change #998
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure |
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.