docker/docker

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

Summary

Maintainability
F
1 wk
Test Coverage

File bridge_linux.go has 1169 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package bridge

import (
    "bytes"
    "context"
Severity: Major
Found in libnetwork/drivers/bridge/bridge_linux.go - About 2 days to fix

    Method driver.CreateEndpoint has a Cognitive Complexity of 48 (exceeds 20 allowed). Consider refactoring.
    Open

    func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error {
        if ifInfo == nil {
            return errors.New("invalid interface info passed")
        }
    
    
    Severity: Minor
    Found in libnetwork/drivers/bridge/bridge_linux.go - About 4 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

    Method driver.CreateEndpoint has 138 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error {
        if ifInfo == nil {
            return errors.New("invalid interface info passed")
        }
    
    
    Severity: Major
    Found in libnetwork/drivers/bridge/bridge_linux.go - About 4 hrs to fix

      Method driver.link has a Cognitive Complexity of 43 (exceeds 20 allowed). Consider refactoring.
      Open

      func (d *driver) link(network *bridgeNetwork, endpoint *bridgeEndpoint, enable bool) (retErr error) {
          cc := endpoint.containerConfig
          ec := endpoint.extConnConfig
          if cc == nil || ec == nil || (len(cc.ParentEndpoints) == 0 && len(cc.ChildEndpoints) == 0) {
              // nothing to do
      Severity: Minor
      Found in libnetwork/drivers/bridge/bridge_linux.go - About 4 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

      driver has 22 methods (exceeds 20 allowed). Consider refactoring.
      Open

      type driver struct {
          config            configuration
          natChain          *iptables.ChainInfo
          filterChain       *iptables.ChainInfo
          isolationChain1   *iptables.ChainInfo
      Severity: Minor
      Found in libnetwork/drivers/bridge/bridge_linux.go - About 2 hrs to fix

        Method driver.configure has 77 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (d *driver) configure(option map[string]interface{}) error {
            var (
                config            configuration
                err               error
                natChain          *iptables.ChainInfo
        Severity: Major
        Found in libnetwork/drivers/bridge/bridge_linux.go - About 2 hrs to fix

          Method driver.createNetwork has 77 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (d *driver) createNetwork(config *networkConfiguration) (err error) {
              // Initialize handle when needed
              d.Lock()
              if d.nlh == nil {
                  d.nlh = ns.NlHandle()
          Severity: Major
          Found in libnetwork/drivers/bridge/bridge_linux.go - About 2 hrs to fix

            Method driver.CreateEndpoint has 22 return statements (exceeds 4 allowed).
            Open

            func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error {
                if ifInfo == nil {
                    return errors.New("invalid interface info passed")
                }
            
            
            Severity: Major
            Found in libnetwork/drivers/bridge/bridge_linux.go - About 2 hrs to fix

              Method networkConfiguration.fromLabels has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring.
              Open

              func (c *networkConfiguration) fromLabels(labels map[string]string) error {
                  var err error
                  for label, value := range labels {
                      switch label {
                      case BridgeName:
              Severity: Minor
              Found in libnetwork/drivers/bridge/bridge_linux.go - About 1 hr 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

              Method driver.link has 62 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func (d *driver) link(network *bridgeNetwork, endpoint *bridgeEndpoint, enable bool) (retErr error) {
                  cc := endpoint.containerConfig
                  ec := endpoint.extConnConfig
                  if cc == nil || ec == nil || (len(cc.ParentEndpoints) == 0 && len(cc.ChildEndpoints) == 0) {
                      // nothing to do
              Severity: Minor
              Found in libnetwork/drivers/bridge/bridge_linux.go - About 1 hr to fix

                Method driver.link has 11 return statements (exceeds 4 allowed).
                Open

                func (d *driver) link(network *bridgeNetwork, endpoint *bridgeEndpoint, enable bool) (retErr error) {
                    cc := endpoint.containerConfig
                    ec := endpoint.extConnConfig
                    if cc == nil || ec == nil || (len(cc.ParentEndpoints) == 0 && len(cc.ChildEndpoints) == 0) {
                        // nothing to do
                Severity: Major
                Found in libnetwork/drivers/bridge/bridge_linux.go - About 1 hr to fix

                  Method driver.deleteNetwork has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
                  Open

                  func (d *driver) deleteNetwork(nid string) error {
                      var err error
                  
                      // Get network handler and remove it from driver
                      d.Lock()
                  Severity: Minor
                  Found in libnetwork/drivers/bridge/bridge_linux.go - About 1 hr 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

                  Method driver.configure has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
                  Open

                  func (d *driver) configure(option map[string]interface{}) error {
                      var (
                          config            configuration
                          err               error
                          natChain          *iptables.ChainInfo
                  Severity: Minor
                  Found in libnetwork/drivers/bridge/bridge_linux.go - About 1 hr 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

                  Method networkConfiguration.fromLabels has 10 return statements (exceeds 4 allowed).
                  Open

                  func (c *networkConfiguration) fromLabels(labels map[string]string) error {
                      var err error
                      for label, value := range labels {
                          switch label {
                          case BridgeName:
                  Severity: Major
                  Found in libnetwork/drivers/bridge/bridge_linux.go - About 1 hr to fix

                    Method driver.CreateNetwork has 8 return statements (exceeds 4 allowed).
                    Open

                    func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
                        if len(ipV4Data) == 0 || ipV4Data[0].Pool.String() == "0.0.0.0/0" {
                            return types.InvalidParameterErrorf("ipv4 pool is empty")
                        }
                        // Sanity checks
                    Severity: Major
                    Found in libnetwork/drivers/bridge/bridge_linux.go - About 50 mins to fix

                      Method driver.Join has 8 return statements (exceeds 4 allowed).
                      Open

                      func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error {
                          network, err := d.getNetwork(nid)
                          if err != nil {
                              return err
                          }
                      Severity: Major
                      Found in libnetwork/drivers/bridge/bridge_linux.go - About 50 mins to fix

                        Method driver.ProgramExternalConnectivity has 8 return statements (exceeds 4 allowed).
                        Open

                        func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error {
                            network, err := d.getNetwork(nid)
                            if err != nil {
                                return err
                            }
                        Severity: Major
                        Found in libnetwork/drivers/bridge/bridge_linux.go - About 50 mins to fix

                          Method driver.DeleteEndpoint has 6 return statements (exceeds 4 allowed).
                          Open

                          func (d *driver) DeleteEndpoint(nid, eid string) error {
                              var err error
                          
                              // Get the network handler and make sure it exists
                              d.Lock()
                          Severity: Major
                          Found in libnetwork/drivers/bridge/bridge_linux.go - About 40 mins to fix

                            Method driver.EndpointOperInfo has 6 return statements (exceeds 4 allowed).
                            Open

                            func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) {
                                // Get the network handler and make sure it exists
                                d.Lock()
                                n, ok := d.networks[nid]
                                d.Unlock()
                            Severity: Major
                            Found in libnetwork/drivers/bridge/bridge_linux.go - About 40 mins to fix

                              Method networkConfiguration.Validate has 6 return statements (exceeds 4 allowed).
                              Open

                              func (c *networkConfiguration) Validate() error {
                                  if c.Mtu < 0 {
                                      return ErrInvalidMtu(c.Mtu)
                                  }
                              
                              
                              Severity: Major
                              Found in libnetwork/drivers/bridge/bridge_linux.go - About 40 mins to fix

                                Method driver.RevokeExternalConnectivity has 5 return statements (exceeds 4 allowed).
                                Open

                                func (d *driver) RevokeExternalConnectivity(nid, eid string) error {
                                    network, err := d.getNetwork(nid)
                                    if err != nil {
                                        return err
                                    }
                                Severity: Major
                                Found in libnetwork/drivers/bridge/bridge_linux.go - About 35 mins to fix

                                  Method networkConfiguration.Conflicts has 5 return statements (exceeds 4 allowed).
                                  Open

                                  func (c *networkConfiguration) Conflicts(o *networkConfiguration) error {
                                      if o == nil {
                                          return errors.New("same configuration")
                                      }
                                  
                                  
                                  Severity: Major
                                  Found in libnetwork/drivers/bridge/bridge_linux.go - About 35 mins to fix

                                    Method driver.Leave has 5 return statements (exceeds 4 allowed).
                                    Open

                                    func (d *driver) Leave(nid, eid string) error {
                                        network, err := d.getNetwork(nid)
                                        if err != nil {
                                            return types.InternalMaskableErrorf("%s", err)
                                        }
                                    Severity: Major
                                    Found in libnetwork/drivers/bridge/bridge_linux.go - About 35 mins to fix

                                      Method driver.configure has 5 return statements (exceeds 4 allowed).
                                      Open

                                      func (d *driver) configure(option map[string]interface{}) error {
                                          var (
                                              config            configuration
                                              err               error
                                              natChain          *iptables.ChainInfo
                                      Severity: Major
                                      Found in libnetwork/drivers/bridge/bridge_linux.go - About 35 mins to fix

                                        Method driver.createNetwork has 5 return statements (exceeds 4 allowed).
                                        Open

                                        func (d *driver) createNetwork(config *networkConfiguration) (err error) {
                                            // Initialize handle when needed
                                            d.Lock()
                                            if d.nlh == nil {
                                                d.nlh = ns.NlHandle()
                                        Severity: Major
                                        Found in libnetwork/drivers/bridge/bridge_linux.go - About 35 mins to fix

                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                              if config.EnableIP6Tables {
                                                  removeIPChains(iptables.IPv6)
                                          
                                                  natChainV6, filterChainV6, isolationChain1V6, isolationChain2V6, err = setupIPChains(config, iptables.IPv6)
                                                  if err != nil {
                                          Severity: Major
                                          Found in libnetwork/drivers/bridge/bridge_linux.go and 1 other location - About 1 hr to fix
                                          libnetwork/drivers/bridge/bridge_linux.go on lines 432..447

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 157.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                              if config.EnableIPTables {
                                                  removeIPChains(iptables.IPv4)
                                          
                                                  natChain, filterChain, isolationChain1, isolationChain2, err = setupIPChains(config, iptables.IPv4)
                                                  if err != nil {
                                          Severity: Major
                                          Found in libnetwork/drivers/bridge/bridge_linux.go and 1 other location - About 1 hr to fix
                                          libnetwork/drivers/bridge/bridge_linux.go on lines 449..464

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 157.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Identical blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                              if link, err := d.nlh.LinkByName(ep.srcName); err == nil {
                                                  if err := d.nlh.LinkDel(link); err != nil {
                                                      log.G(context.TODO()).WithError(err).Errorf("Failed to delete interface (%s)'s link on endpoint (%s) delete", ep.srcName, ep.id)
                                                  }
                                              }
                                          Severity: Minor
                                          Found in libnetwork/drivers/bridge/bridge_linux.go and 1 other location - About 35 mins to fix
                                          libnetwork/drivers/bridge/bridge_linux.go on lines 859..863

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 104.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Identical blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                                  if link, err := d.nlh.LinkByName(ep.srcName); err == nil {
                                                      if err := d.nlh.LinkDel(link); err != nil {
                                                          log.G(context.TODO()).WithError(err).Errorf("Failed to delete interface (%s)'s link on endpoint (%s) delete", ep.srcName, ep.id)
                                                      }
                                                  }
                                          Severity: Minor
                                          Found in libnetwork/drivers/bridge/bridge_linux.go and 1 other location - About 35 mins to fix
                                          libnetwork/drivers/bridge/bridge_linux.go on lines 1163..1167

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 104.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          There are no issues that match your filters.

                                          Category
                                          Status