|
@@ -26,6 +26,7 @@ type nwIface struct {
|
|
|
mac net.HardwareAddr
|
|
|
address *net.IPNet
|
|
|
addressIPv6 *net.IPNet
|
|
|
+ ipAliases []*net.IPNet
|
|
|
llAddrs []*net.IPNet
|
|
|
routes []*net.IPNet
|
|
|
bridge bool
|
|
@@ -96,6 +97,13 @@ func (i *nwIface) LinkLocalAddresses() []*net.IPNet {
|
|
|
return i.llAddrs
|
|
|
}
|
|
|
|
|
|
+func (i *nwIface) IPAliases() []*net.IPNet {
|
|
|
+ i.Lock()
|
|
|
+ defer i.Unlock()
|
|
|
+
|
|
|
+ return i.ipAliases
|
|
|
+}
|
|
|
+
|
|
|
func (i *nwIface) Routes() []*net.IPNet {
|
|
|
i.Lock()
|
|
|
defer i.Unlock()
|
|
@@ -122,28 +130,6 @@ func (n *networkNamespace) Interfaces() []Interface {
|
|
|
return ifaces
|
|
|
}
|
|
|
|
|
|
-func (i *nwIface) SetAliasIP(ip *net.IPNet, add bool) error {
|
|
|
- i.Lock()
|
|
|
- n := i.ns
|
|
|
- i.Unlock()
|
|
|
-
|
|
|
- n.Lock()
|
|
|
- nlh := n.nlHandle
|
|
|
- n.Unlock()
|
|
|
-
|
|
|
- // Find the network interface identified by the DstName attribute.
|
|
|
- iface, err := nlh.LinkByName(i.DstName())
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
-
|
|
|
- ipAddr := &netlink.Addr{IPNet: ip, Label: ""}
|
|
|
- if add {
|
|
|
- return nlh.AddrAdd(iface, ipAddr)
|
|
|
- }
|
|
|
- return nlh.AddrDel(iface, ipAddr)
|
|
|
-}
|
|
|
-
|
|
|
func (i *nwIface) Remove() error {
|
|
|
i.Lock()
|
|
|
n := i.ns
|
|
@@ -347,6 +333,7 @@ func configureInterface(nlh *netlink.Handle, iface netlink.Link, i *nwIface) err
|
|
|
{setInterfaceIPv6, fmt.Sprintf("error setting interface %q IPv6 to %v", ifaceName, i.AddressIPv6())},
|
|
|
{setInterfaceMaster, fmt.Sprintf("error setting interface %q master to %q", ifaceName, i.DstMaster())},
|
|
|
{setInterfaceLinkLocalIPs, fmt.Sprintf("error setting interface %q link local IPs to %v", ifaceName, i.LinkLocalAddresses())},
|
|
|
+ {setInterfaceIPAliases, fmt.Sprintf("error setting interface %q IP Aliases to %v", ifaceName, i.IPAliases())},
|
|
|
}
|
|
|
|
|
|
for _, config := range ifaceConfigurators {
|
|
@@ -405,6 +392,16 @@ func setInterfaceLinkLocalIPs(nlh *netlink.Handle, iface netlink.Link, i *nwIfac
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+func setInterfaceIPAliases(nlh *netlink.Handle, iface netlink.Link, i *nwIface) error {
|
|
|
+ for _, si := range i.IPAliases() {
|
|
|
+ ipAddr := &netlink.Addr{IPNet: si}
|
|
|
+ if err := nlh.AddrAdd(iface, ipAddr); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
func setInterfaceName(nlh *netlink.Handle, iface netlink.Link, i *nwIface) error {
|
|
|
return nlh.LinkSetName(iface, i.DstName())
|
|
|
}
|