libnetwork/drivers/bridge/port_mapping_linux.go
Method bridgeNetwork.addPortMappings
has a Cognitive Complexity of 73 (exceeds 20 allowed). Consider refactoring. Open
Open
func (n *bridgeNetwork) addPortMappings(
ctx context.Context,
epAddrV4, epAddrV6 *net.IPNet,
cfg []types.PortBinding,
defHostIP net.IP,
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function attemptBindHostPorts
has a Cognitive Complexity of 55 (exceeds 20 allowed). Consider refactoring. Open
Open
func attemptBindHostPorts(
ctx context.Context,
cfg []portBindingReq,
proto string,
hostPortStart, hostPortEnd uint16,
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
File port_mapping_linux.go
has 664 lines of code (exceeds 500 allowed). Consider refactoring. Open
Open
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.21
package bridge
Method bridgeNetwork.addPortMappings
has 122 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (n *bridgeNetwork) addPortMappings(
ctx context.Context,
epAddrV4, epAddrV6 *net.IPNet,
cfg []types.PortBinding,
defHostIP net.IP,
Function attemptBindHostPorts
has 71 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func attemptBindHostPorts(
ctx context.Context,
cfg []portBindingReq,
proto string,
hostPortStart, hostPortEnd uint16,
Function bindTCPOrUDP
has 56 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func bindTCPOrUDP(cfg portBindingReq, port, typ, proto int) (_ portBinding, retErr error) {
pb := portBinding{PortBinding: cfg.PortBinding.GetCopy()}
pb.HostPort = uint16(port)
pb.HostPortEnd = pb.HostPort
pb.childHostIP = cfg.childHostIP
Method bridgeNetwork.addPortMappings
has 10 return statements (exceeds 4 allowed). Open
Open
func (n *bridgeNetwork) addPortMappings(
ctx context.Context,
epAddrV4, epAddrV6 *net.IPNet,
cfg []types.PortBinding,
defHostIP net.IP,
Function cmpPortBinding
has 8 return statements (exceeds 4 allowed). Open
Open
func cmpPortBinding(a, b types.PortBinding) int {
// Exact host port < host port range.
aIsRange := a.HostPort == 0 || a.HostPort != a.HostPortEnd
bIsRange := b.HostPort == 0 || b.HostPort != b.HostPortEnd
if aIsRange != bIsRange {
Function bindTCPOrUDP
has 7 return statements (exceeds 4 allowed). Open
Open
func bindTCPOrUDP(cfg portBindingReq, port, typ, proto int) (_ portBinding, retErr error) {
pb := portBinding{PortBinding: cfg.PortBinding.GetCopy()}
pb.HostPort = uint16(port)
pb.HostPortEnd = pb.HostPort
pb.childHostIP = cfg.childHostIP
Function configurePortBindingIPv6
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
ctx context.Context,
pdc portDriverClient,
disableNAT bool,
bnd types.PortBinding,
containerIP, defHostIP net.IP,
Function configurePortBindingIPv4
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
ctx context.Context,
pdc portDriverClient,
disableNAT bool,
bnd types.PortBinding,
containerIPv4,
Function attemptBindHostPorts
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
ctx context.Context,
cfg []portBindingReq,
proto string,
hostPortStart, hostPortEnd uint16,
proxyPath string,
Function setPerPortNAT
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
func setPerPortNAT(b portBinding, ipv iptables.IPVersion, proxyPath string, bridgeName string, enable bool) error {
Function configurePortBindingIPv6
has 5 return statements (exceeds 4 allowed). Open
Open
func configurePortBindingIPv6(
ctx context.Context,
pdc portDriverClient,
disableNAT bool,
bnd types.PortBinding,
Method bridgeNetwork.setPerPortIptables
has 5 return statements (exceeds 4 allowed). Open
Open
func (n *bridgeNetwork) setPerPortIptables(b portBinding, enable bool) error {
if (b.IP.To4() != nil) != (b.HostIP.To4() != nil) {
// The binding is between containerV4 and hostV6 (not vice-versa as that
// will have been rejected earlier). It's handled by docker-proxy, so no
// additional iptables rules are required.
Function bindSCTP
has 5 return statements (exceeds 4 allowed). Open
Open
func bindSCTP(cfg portBindingReq, port int) (_ portBinding, retErr error) {
pb := portBinding{PortBinding: cfg.GetCopy()}
pb.HostPort = uint16(port)
pb.HostPortEnd = pb.HostPort
pb.childHostIP = cfg.childHostIP