Skip to content
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

Limited bridge netfilter application. #2497

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions drivers/bridge/setup_bridgenetfiltering.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ func checkBridgeNetFiltering(config *networkConfiguration, i *bridgeInterface) e
if err != nil {
logrus.Warnf("failed to check %s forwarding: %v", ipVerName, err)
} else if enabled {
enabled, err := getKernelBoolParam(getBridgeNFKernelParam(ipVer))
enabled, err := getKernelBoolParam(getBridgeNFKernelParam(ipVer, iface))
if err != nil || enabled {
return err
}
return setKernelBoolParam(getBridgeNFKernelParam(ipVer), true)
return setKernelBoolParam(getBridgeNFKernelParam(ipVer, iface), true)
}
return nil
}
Expand Down Expand Up @@ -108,12 +108,12 @@ func getForwardingKernelParam(ipVer ipVersion, iface string) string {

// Get kernel param path saying whether bridged IPv${ipVer} traffic shall be
// passed to ip${ipVer}tables' chains.
func getBridgeNFKernelParam(ipVer ipVersion) string {
func getBridgeNFKernelParam(ipVer ipVersion, bridgeName string) string {
switch ipVer {
case ipv4:
return "/proc/sys/net/bridge/bridge-nf-call-iptables"
return fmt.Sprintf("/sys/class/net/%s/bridge/nf_call_iptables", bridgeName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably use path.Join()

Suggested change
return fmt.Sprintf("/sys/class/net/%s/bridge/nf_call_iptables", bridgeName)
return path.Join("/sys/class/net", bridgeName, "bridge/nf_call_iptables")

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not exactly clear how one is better than the other; both versions still have assumptions about what the path separator is and, anyway, the whole thing is linux-specific. Does swapping to path.Join improve this in some way?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're constructing a path, so we should use a function that's designed for that.

Looking at this, we should also validate bridgeName before use: this value is passed as a label, and we likely don't want ../../ to be used

case ipv6:
return "/proc/sys/net/bridge/bridge-nf-call-ip6tables"
return fmt.Sprintf("/sys/class/net/%s/bridge/nf_call_ip6tables", bridgeName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here;

Suggested change
return fmt.Sprintf("/sys/class/net/%s/bridge/nf_call_ip6tables", bridgeName)
return path.Join("/sys/class/net", bridgeName, "bridge/nf_call_ip6tables")

default:
return ""
}
Expand Down