//AddIp it receives a CIDR Address and add it to the given interface
324015
func AddIp(ip, iface string) error {
	link, err := netlink.LinkByName(iface)
	if err != nil {
		return err
	}

	addr, err := netlink.ParseAddr(ip)
	if err != nil {
		return err
	}

	return netlink.AddrAdd(link, addr)
}
830577
func AddIPRoute(cidr, gw string) error {

	_, dst, err := net.ParseCIDR(cidr)
	if err != nil {
		return err
	}

	gwIP := net.ParseIP(gw)
	if gwIP == nil {
		return fmt.Errorf("Unable to parse gw %s", gw)
	}

	match, err := netlink.RouteListFiltered(netlink.FAMILY_V4,
		&netlink.Route{Dst: dst}, netlink.RT_FILTER_DST)

	if err == nil && len(match) != 0 {
		if len(match) == 1 && match[0].Gw.Equal(gwIP) {
			// the exact same route exists -- be idempotent
			log.Infof("Route %s --> %s present", cidr, gw)
			return nil
		}
		log.Errorf("AddIPRoute(%s, %s): exists %+v", cidr, gw, match)
		return fmt.Errorf("Route exists")
	}

	newRoute := netlink.Route{
		Dst: dst,
		Gw:  gwIP,
	}

	return netlink.RouteAdd(&newRoute)
}
723389
func getIP(showAddress string) string {
	list := strings.SplitN(showAddress, ":", 2)
	if len(list) != 2 {
		return ""
	}
	return strings.TrimSpace(list[1])
}
1111446
func (assign AddressAssignment) EqualIP(b AddressAssignment) bool {
	if assign.PoolID != b.PoolID {
		return false
	} else if assign.IPAddr == b.IPAddr {
		return false
	} else if assign.Port != b.Port {
		return false
	} else if assign.ServiceID != b.ServiceID {
		return false
	} else if assign.EndpointName != b.EndpointName {
		return false
	}
	return true
}
921463
func (s *DedicatedIp) SetIp(v string) *DedicatedIp {
	s.Ip = &v
	return s
}
1211977
func (c *whoisClient) LookupIP(ip net.IP) (*Response, error) {
	resp, err := c.LookupIPs([]net.IP{ip})
	if len(resp) == 0 {
		return nil, err
	}
	return &resp[0], err
}
919538
func (c *CIDR) FirstIP() net.IP {
	var ip net.IP
	for ip = IncIP(c.ip.Mask(c.ipnet.Mask)); c.ipnet.Contains(ip); IncIP(ip) {
		break
	}
	return ip
}
1109337
func GetIP() string {
	ifaces, err := net.Interfaces()
	if err != nil {
		return "127.0.0.1"
	}
	for _, i := range ifaces {
		addrs, err := i.Addrs()
		if err != nil {
			return "127.0.0.1"
		}
		for _, addr := range addrs {
			var ip net.IP
			switch v := addr.(type) {
			case *net.IPAddr:
				ip = v.IP
			case *net.IPNet:
				ip = v.IP
			}
			if ip == nil || ip.IsLoopback() {
				continue
			}
			ip = ip.To4()
			if ip == nil {
				continue // not an ipv4 address
			}
			return ip.String()
		}
	}
	return "127.0.0.1"
}
368777
func SetInterfaceIP(name string, ipstr string) error {
	iface, err := netlink.LinkByName(name)
	if err != nil {
		return err
	}
	ipaddr, err := netlink.ParseAddr(ipstr)
	if err != nil {
		return err
	}
	netlink.LinkSetUp(iface)
	return netlink.AddrAdd(iface, ipaddr)
}
19041
func AssignIP(dhcpHandler *DHCPHandler, ipRange string) (map[string]uint32, []net.IP) {
	couple := make(map[string]uint32)
	var iplist []net.IP
	if ipRange != "" {
		rgx, _ := regexp.Compile("((?:[0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}):((?:[0-9]{1,3}.){3}(?:[0-9]{1,3}))")
		ipRangeArray := strings.Split(ipRange, ",")
		if len(ipRangeArray) >= 1 {
			for _, rangeip := range ipRangeArray {
				result := rgx.FindStringSubmatch(rangeip)
				position := uint32(binary.BigEndian.Uint32(net.ParseIP(result[2]).To4())) - uint32(binary.BigEndian.Uint32(dhcpHandler.start.To4()))
				// Remove the position in the roaming bitmap
				dhcpHandler.available.ReserveIPIndex(uint64(position), result[1])
				couple[result[1]] = position
				iplist = append(iplist, net.ParseIP(result[2]))
			}
		}
	}
	return couple, iplist
}
1042723
func (s *GetDedicatedIpOutput) SetDedicatedIp(v *DedicatedIp) *GetDedicatedIpOutput {
	s.DedicatedIp = v
	return s
}
710399
func resolveIP(n *healthNode, addr *ciliumModels.NodeAddressingElement, proto string, primary bool) (string, *net.IPAddr) {
	node := n.NodeElement
	network := "ip6:icmp"
	if isIPv4(addr.IP) {
		network = "ip4:icmp"
	}
	scopedLog := log.WithFields(logrus.Fields{
		logfields.NodeName: node.Name,
		logfields.IPAddr:   addr.IP,
		"primary":          primary,
	})

	if skipAddress(addr) {
		scopedLog.Debug("Skipping probe for address")
		return "", nil
	}

	ra, err := net.ResolveIPAddr(network, addr.IP)
	if err != nil {
		scopedLog.Debug("Unable to resolve address")
		return "", nil
	}

	scopedLog.WithField("protocol", proto).Debug("Probing for connectivity to node")
	return node.Name, ra
}
311207
func defaultIP(addr *net.TCPAddr) string {
	if !addr.IP.IsUnspecified() {
		return addr.IP.String()
	}

	nics, err := net.Interfaces()
	if err != nil {
		return addr.IP.String()
	}

	for _, nic := range nics {
		if nic.Name == "docker0" || strings.HasPrefix(nic.Name, "vmnet") {
			continue
		}
		addrs, aerr := nic.Addrs()
		if aerr != nil {
			continue
		}
		for _, addr := range addrs {
			if ip, ok := addr.(*net.IPNet); ok && !ip.IP.IsLoopback() {
				if ip.IP.To4() != nil {
					return ip.IP.String()
				}
			}
		}
	}

	return addr.IP.String()
}
261051
func (_m *API) AssignIP(_a0 api.IPConfig) error {
	ret := _m.Called(_a0)

	var r0 error
	if rf, ok := ret.Get(0).(func(api.IPConfig) error); ok {
		r0 = rf(_a0)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
14262
func (mg *MailgunImpl) AddDomainIP(ctx context.Context, ip string) error {
	r := newHTTPRequest(generatePublicApiUrl(mg, domainsEndpoint) + "/" + mg.domain + "/ips")
	r.setClient(mg.Client())
	r.setBasicAuth(basicAuthUser, mg.APIKey())

	payload := newUrlEncodedPayload()
	payload.addValue("ip", ip)
	_, err := makePostRequest(ctx, r, payload)
	return err
}
1055801
func InterfaceIPs(device string) (ips []net.IP, _ error) {
	var networks []net.Addr

	if iface, err := net.InterfaceByName(device); err != nil {
		return nil, err
	} else if networks, err = iface.Addrs(); err != nil {
		return nil, err
	}

	for _, network := range networks {
		if ipNet, castable := network.(*net.IPNet); castable {
			ips = append(ips, ipNet.IP)
		}
	}

	// Note that on non-IP interfaces it will be an empty slice
	// and no error indicator. Maybe that's not super-perfect.
	return ips, nil
}
1264581
func (f *ConntrackFilter) AddIP(tp ConntrackFilterType, ip net.IP) error {
	if f.ipFilter == nil {
		f.ipFilter = make(map[ConntrackFilterType]net.IP)
	}
	if _, ok := f.ipFilter[tp]; ok {
		return errors.New("Filter attribute already present")
	}
	f.ipFilter[tp] = ip
	return nil
}