Exemplo n.º 1
0
// externalIP attempts to find an external IP to be reported as the guest IP
func externalIP() string {
	l, err := netlink.LinkByName("client")
	if err != nil {
		log.Warnf("error looking up client interface by name: %s", err)

		l, err = netlink.LinkByAlias("client")
		if err != nil {
			log.Errorf("error looking up client interface by alias: %s", err)
			return ""
		}
	}

	addrs, err := netlink.AddrList(l, netlink.FAMILY_V4)
	if err != nil {
		log.Errorf("error getting address list for client interface: %s", err)
		return ""
	}

	if len(addrs) == 0 {
		log.Warnf("no addresses set on client interface")
		return ""
	}

	return addrs[0].IP.String()
}
Exemplo n.º 2
0
func LinkByAlias(alias string) (Link, error) {
	l, err := netlink.LinkByAlias(alias)
	if err != nil {
		return nil, err
	}

	return newLink(l), nil
}
Exemplo n.º 3
0
func init() {
	portMapper = portmap.NewPortMapper()
	containerByPort = make(map[string]string)

	l, err := netlink.LinkByName(externalIfaceName)
	if l == nil {
		l, err = netlink.LinkByAlias(externalIfaceName)
		if err != nil {
			log.Errorf("interface %s not found", externalIfaceName)
			return
		}
	}

	// don't use interface alias for iptables rules
	externalIfaceName = l.Attrs().Name
}