当前位置: 首页>>代码示例>>Golang>>正文


Golang netutils.CheckRouteOverlaps函数代码示例

本文整理汇总了Golang中github.com/docker/libnetwork/netutils.CheckRouteOverlaps函数的典型用法代码示例。如果您正苦于以下问题:Golang CheckRouteOverlaps函数的具体用法?Golang CheckRouteOverlaps怎么用?Golang CheckRouteOverlaps使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了CheckRouteOverlaps函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: electBridgeIPv4

func electBridgeIPv4(config *NetworkConfiguration) (*net.IPNet, error) {
	// Use the requested IPv4 CIDR when available.
	if config.AddressIPv4 != nil {
		return config.AddressIPv4, nil
	}

	// We don't check for an error here, because we don't really care if we
	// can't read /etc/resolv.conf. So instead we skip the append if resolvConf
	// is nil. It either doesn't exist, or we can't read it for some reason.
	nameservers := []string{}
	if resolvConf, _ := readResolvConf(); resolvConf != nil {
		nameservers = append(nameservers, getNameserversAsCIDR(resolvConf)...)
	}

	// Try to automatically elect appropriate bridge IPv4 settings.
	for _, n := range bridgeNetworks {
		if err := netutils.CheckNameserverOverlaps(nameservers, n); err == nil {
			if err := netutils.CheckRouteOverlaps(n); err == nil {
				return n, nil
			}
		}
	}

	return nil, IPv4AddrRangeError(config.BridgeName)
}
开发者ID:fwalker,项目名称:dashboard,代码行数:25,代码来源:setup_ipv4.go

示例2: TestSetDefaultGw

func TestSetDefaultGw(t *testing.T) {
	defer testutils.SetupTestOSContext(t)()
	d := newDriver()

	if err := d.configure(nil); err != nil {
		t.Fatalf("Failed to setup driver config: %v", err)
	}

	_, subnetv6, _ := net.ParseCIDR("2001:db8:ea9:9abc:b0c4::/80")

	var nw *net.IPNet
	for _, n := range bridgeNetworks {
		if err := netutils.CheckRouteOverlaps(n); err == nil {
			nw = n
			break
		}
	}
	if nw == nil {
		t.Skipf("Skip as no more automatic networks available")
	}

	gw4 := types.GetIPCopy(nw.IP).To4()
	gw4[3] = 254
	gw6 := net.ParseIP("2001:db8:ea9:9abc:b0c4::254")

	config := &networkConfiguration{
		BridgeName:         DefaultBridgeName,
		EnableIPv6:         true,
		FixedCIDRv6:        subnetv6,
		DefaultGatewayIPv4: gw4,
		DefaultGatewayIPv6: gw6,
	}

	genericOption := make(map[string]interface{})
	genericOption[netlabel.GenericData] = config

	err := d.CreateNetwork("dummy", genericOption)
	if err != nil {
		t.Fatalf("Failed to create bridge: %v", err)
	}

	te := &testEndpoint{}
	err = d.CreateEndpoint("dummy", "ep", te, nil)
	if err != nil {
		t.Fatalf("Failed to create endpoint: %v", err)
	}

	err = d.Join("dummy", "ep", "sbox", te, nil)
	if err != nil {
		t.Fatalf("Failed to join endpoint: %v", err)
	}

	if !gw4.Equal(te.gw) {
		t.Fatalf("Failed to configure default gateway. Expected %v. Found %v", gw4, te.gw)
	}

	if !gw6.Equal(te.gw6) {
		t.Fatalf("Failed to configure default gateway. Expected %v. Found %v", gw6, te.gw6)
	}
}
开发者ID:wangxujun163163,项目名称:libnetwork,代码行数:60,代码来源:bridge_test.go

示例3: getFirstAvailablePool

func getFirstAvailablePool(a *Allocator, as string, atLeast int) (int, *net.IPNet, error) {
	i := 0
	for i < len(a.predefined[as])-1 {
		if err := netutils.CheckRouteOverlaps(a.predefined[as][i]); err == nil {
			break
		}
		i++
	}
	if i > len(a.predefined[as])-1-atLeast {
		return 0, nil, fmt.Errorf("Not enough non-overlapping networks to run the test")
	}
	return i, a.predefined[as][i], nil
}
开发者ID:c0b,项目名称:libnetwork,代码行数:13,代码来源:allocator_test.go

示例4: FindAvailableNetwork

// FindAvailableNetwork returns a network from the passed list which does not
// overlap with existing interfaces in the system
func FindAvailableNetwork(list []*net.IPNet) (*net.IPNet, error) {
	// We don't check for an error here, because we don't really care if we
	// can't read /etc/resolv.conf. So instead we skip the append if resolvConf
	// is nil. It either doesn't exist, or we can't read it for some reason.
	var nameservers []string
	if rc, err := resolvconf.Get(); err == nil {
		nameservers = resolvconf.GetNameserversAsCIDR(rc.Content)
	}
	for _, nw := range list {
		if err := netutils.CheckNameserverOverlaps(nameservers, nw); err == nil {
			if err := netutils.CheckRouteOverlaps(nw); err == nil {
				return nw, nil
			}
		}
	}
	return nil, fmt.Errorf("no available network")
}
开发者ID:thieman,项目名称:libnetwork,代码行数:19,代码来源:utils.go

示例5: isOverlap

func isOverlap(nw *net.IPNet) bool {
	var nameservers []string

	if rc, err := resolvconf.Get(); err == nil {
		nameservers = resolvconf.GetNameserversAsCIDR(rc.Content)
	}

	if err := netutils.CheckNameserverOverlaps(nameservers, nw); err != nil {
		return true
	}

	if err := netutils.CheckRouteOverlaps(nw); err != nil {
		return true
	}

	return false
}
开发者ID:hallyn,项目名称:docker,代码行数:17,代码来源:ov_network.go

示例6: checkOverlap

func checkOverlap(nw *net.IPNet) error {
	var nameservers []string

	if rc, err := resolvconf.Get(); err == nil {
		nameservers = resolvconf.GetNameserversAsCIDR(rc.Content)
	}

	if err := netutils.CheckNameserverOverlaps(nameservers, nw); err != nil {
		return fmt.Errorf("overlay subnet %s failed check with nameserver: %v: %v", nw.String(), nameservers, err)
	}

	if err := netutils.CheckRouteOverlaps(nw); err != nil {
		return fmt.Errorf("overlay subnet %s failed check with host route table: %v", nw.String(), err)
	}

	return nil
}
开发者ID:jfrazelle,项目名称:docker,代码行数:17,代码来源:ov_network.go

示例7: getPredefinedPool

func (a *Allocator) getPredefinedPool(as string, ipV6 bool) (*net.IPNet, error) {
	var v ipVersion
	v = v4
	if ipV6 {
		v = v6
	}

	if as != localAddressSpace && as != globalAddressSpace {
		return nil, fmt.Errorf("no default pool availbale for non-default addresss spaces")
	}

	cfg, err := a.getPoolsConfig(as)
	if err != nil {
		return nil, err
	}

	for _, nw := range a.getPredefineds(as) {
		if v != getAddressVersion(nw.IP) {
			continue
		}
		cfg.Lock()
		_, ok := cfg.subnets[SubnetKey{AddressSpace: as, Subnet: nw.String()}]
		cfg.Unlock()
		if ok {
			continue
		}

		if !cfg.contains(as, nw) {
			if as == localAddressSpace {
				if err := netutils.CheckRouteOverlaps(nw); err == nil {
					return nw, nil
				}
				continue
			}
			return nw, nil
		}
	}

	return nil, types.NotFoundErrorf("could not find an available predefined network")
}
开发者ID:c0b,项目名称:libnetwork,代码行数:40,代码来源:allocator.go

示例8: TestSetupBridgeIPv4Auto

func TestSetupBridgeIPv4Auto(t *testing.T) {
	defer osl.SetupTestOSContext(t)()

	var toBeChosen *net.IPNet
	for _, n := range bridgeNetworks {
		if err := netutils.CheckRouteOverlaps(n); err == nil {
			toBeChosen = n
			break
		}
	}
	if toBeChosen == nil {
		t.Skipf("Skip as no more automatic networks available")
	}

	config, br := setupTestInterface(t)
	if err := setupBridgeIPv4(config, br); err != nil {
		t.Fatalf("Failed to setup bridge IPv4: %v", err)
	}

	addrsv4, err := netlink.AddrList(br.Link, netlink.FAMILY_V4)
	if err != nil {
		t.Fatalf("Failed to list device IPv4 addresses: %v", err)
	}

	var found bool
	for _, addr := range addrsv4 {
		if toBeChosen.String() == addr.IPNet.String() {
			found = true
			break
		}
	}

	if !found {
		t.Fatalf("Bridge device does not have the automatic IPv4 address %s", toBeChosen.String())
	}
}
开发者ID:MarouenMechtri,项目名称:libnetwork,代码行数:36,代码来源:setup_ipv4_test.go


注:本文中的github.com/docker/libnetwork/netutils.CheckRouteOverlaps函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。