dotcloud/docker

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

Summary

Maintainability
F
1 wk
Test Coverage

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

package bridge

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

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

    func (d *driver) CreateEndpoint(ctx context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, _ 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(ctx context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, _ 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

      Method networkConfiguration.fromLabels has a Cognitive Complexity of 36 (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 2 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 24 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 78 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 76 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 21 return statements (exceeds 4 allowed).
            Open

            func (d *driver) CreateEndpoint(ctx context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, _ 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 1 hr to fix

              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.configure has a Cognitive Complexity of 27 (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 12 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 networkConfiguration.fromLabels has 54 lines of code (exceeds 50 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

                    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.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.Join has 8 return statements (exceeds 4 allowed).
                      Open

                      func (d *driver) Join(ctx context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error {
                          ctx, span := otel.Tracer("").Start(ctx, "libnetwork.drivers.bridge.Join", trace.WithAttributes(
                              attribute.String("nid", nid),
                              attribute.String("eid", eid),
                              attribute.String("sboxKey", sboxKey)))
                      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(ctx context.Context, nid, eid string, options map[string]interface{}) error {
                            ctx, span := otel.Tracer("").Start(ctx, "libnetwork.drivers.bridge.ProgramExternalConnectivity", trace.WithAttributes(
                                attribute.String("nid", nid),
                                attribute.String("eid", eid)))
                            defer span.End()
                        Severity: Major
                        Found in libnetwork/drivers/bridge/bridge_linux.go - About 50 mins 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 networkConfiguration.Validate has 7 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 45 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 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.Join has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                  Open

                                  func (d *driver) Join(ctx context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error {
                                  Severity: Minor
                                  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.createNetwork has a Cognitive Complexity of 22 (exceeds 20 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: Minor
                                      Found in libnetwork/drivers/bridge/bridge_linux.go - About 35 mins 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.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.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

                                                        iptables.OnReloaded(func() {
                                                            log.G(context.TODO()).Debugf("Recreating ip6tables chains on firewall reload")
                                                            if _, _, _, _, err := setupIPChains(config, iptables.IPv6); err != nil {
                                                                log.G(context.TODO()).WithError(err).Error("Error reloading ip6tables chains")
                                                            }
                                            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 502..507

                                            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 105.

                                            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

                                                    iptables.OnReloaded(func() {
                                                        log.G(context.TODO()).Debugf("Recreating iptables chains on firewall reload")
                                                        if _, _, _, _, err := setupIPChains(config, iptables.IPv4); err != nil {
                                                            log.G(context.TODO()).WithError(err).Error("Error reloading iptables chains")
                                                        }
                                            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 523..528

                                            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 105.

                                            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 934..938

                                            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 1252..1256

                                            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