dotcloud/docker

View on GitHub
libnetwork/drivers/bridge/port_mapping_linux.go

Summary

Maintainability
F
4 days
Test Coverage

Method bridgeNetwork.addPortMappings has a Cognitive Complexity of 73 (exceeds 20 allowed). Consider refactoring.
Open

func (n *bridgeNetwork) addPortMappings(
    ctx context.Context,
    epAddrV4, epAddrV6 *net.IPNet,
    cfg []types.PortBinding,
    defHostIP net.IP,
Severity: Minor
Found in libnetwork/drivers/bridge/port_mapping_linux.go - About 1 day to fix

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

func attemptBindHostPorts(
    ctx context.Context,
    cfg []portBindingReq,
    proto string,
    hostPortStart, hostPortEnd uint16,
Severity: Minor
Found in libnetwork/drivers/bridge/port_mapping_linux.go - About 6 hrs to fix

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

// 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

Severity: Minor
Found in libnetwork/drivers/bridge/port_mapping_linux.go - About 5 hrs to fix

    Method bridgeNetwork.addPortMappings has 122 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (n *bridgeNetwork) addPortMappings(
        ctx context.Context,
        epAddrV4, epAddrV6 *net.IPNet,
        cfg []types.PortBinding,
        defHostIP net.IP,
    Severity: Major
    Found in libnetwork/drivers/bridge/port_mapping_linux.go - About 3 hrs to fix

      Function attemptBindHostPorts has 71 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func attemptBindHostPorts(
          ctx context.Context,
          cfg []portBindingReq,
          proto string,
          hostPortStart, hostPortEnd uint16,
      Severity: Minor
      Found in libnetwork/drivers/bridge/port_mapping_linux.go - About 1 hr to fix

        Function bindTCPOrUDP has 56 lines of code (exceeds 50 allowed). Consider refactoring.
        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
        Severity: Minor
        Found in libnetwork/drivers/bridge/port_mapping_linux.go - About 1 hr to fix

          Method bridgeNetwork.addPortMappings has 10 return statements (exceeds 4 allowed).
          Open

          func (n *bridgeNetwork) addPortMappings(
              ctx context.Context,
              epAddrV4, epAddrV6 *net.IPNet,
              cfg []types.PortBinding,
              defHostIP net.IP,
          Severity: Major
          Found in libnetwork/drivers/bridge/port_mapping_linux.go - About 1 hr to fix

            Function cmpPortBinding has 8 return statements (exceeds 4 allowed).
            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 {
            Severity: Major
            Found in libnetwork/drivers/bridge/port_mapping_linux.go - About 50 mins to fix

              Function bindTCPOrUDP has 7 return statements (exceeds 4 allowed).
              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
              Severity: Major
              Found in libnetwork/drivers/bridge/port_mapping_linux.go - About 45 mins to fix

                Function configurePortBindingIPv6 has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    ctx context.Context,
                    pdc portDriverClient,
                    disableNAT bool,
                    bnd types.PortBinding,
                    containerIP, defHostIP net.IP,
                Severity: Minor
                Found in libnetwork/drivers/bridge/port_mapping_linux.go - About 35 mins to fix

                  Function configurePortBindingIPv4 has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      ctx context.Context,
                      pdc portDriverClient,
                      disableNAT bool,
                      bnd types.PortBinding,
                      containerIPv4,
                  Severity: Minor
                  Found in libnetwork/drivers/bridge/port_mapping_linux.go - About 35 mins to fix

                    Function attemptBindHostPorts has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        ctx context.Context,
                        cfg []portBindingReq,
                        proto string,
                        hostPortStart, hostPortEnd uint16,
                        proxyPath string,
                    Severity: Minor
                    Found in libnetwork/drivers/bridge/port_mapping_linux.go - About 35 mins to fix

                      Function setPerPortNAT has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                      func setPerPortNAT(b portBinding, ipv iptables.IPVersion, proxyPath string, bridgeName string, enable bool) error {
                      Severity: Minor
                      Found in libnetwork/drivers/bridge/port_mapping_linux.go - About 35 mins to fix

                        Function configurePortBindingIPv6 has 5 return statements (exceeds 4 allowed).
                        Open

                        func configurePortBindingIPv6(
                            ctx context.Context,
                            pdc portDriverClient,
                            disableNAT bool,
                            bnd types.PortBinding,
                        Severity: Major
                        Found in libnetwork/drivers/bridge/port_mapping_linux.go - About 35 mins to fix

                          Method bridgeNetwork.setPerPortIptables has 5 return statements (exceeds 4 allowed).
                          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.
                          Severity: Major
                          Found in libnetwork/drivers/bridge/port_mapping_linux.go - About 35 mins to fix

                            Function bindSCTP has 5 return statements (exceeds 4 allowed).
                            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
                            Severity: Major
                            Found in libnetwork/drivers/bridge/port_mapping_linux.go - About 35 mins to fix

                              There are no issues that match your filters.

                              Category
                              Status