mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-25 15:02:45 +00:00
ipv6: Add support for ipv6
Do not ignore ipv6 addresses and routes. These are now processed along with ipv4 addresses/routes. Add unit tests to verify ipv6. Fixes #147 Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
This commit is contained in:
parent
f1f9414a59
commit
b169476be9
@ -592,7 +592,7 @@ func tapNetworkPair(endpoint Endpoint, queues int, disableVhostNet bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clear the IP addresses from the veth interface to prevent ARP conflict
|
// Clear the IP addresses from the veth interface to prevent ARP conflict
|
||||||
netPair.VirtIface.Addrs, err = netlink.AddrList(link, netlink.FAMILY_V4)
|
netPair.VirtIface.Addrs, err = netlink.AddrList(link, netlink.FAMILY_ALL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Unable to obtain veth IP addresses: %s", err)
|
return fmt.Errorf("Unable to obtain veth IP addresses: %s", err)
|
||||||
}
|
}
|
||||||
@ -954,25 +954,21 @@ func generateInterfacesAndRoutes(networkNS NetworkNamespace) ([]*vcTypes.Interfa
|
|||||||
|
|
||||||
var ipAddresses []*vcTypes.IPAddress
|
var ipAddresses []*vcTypes.IPAddress
|
||||||
for _, addr := range endpoint.Properties().Addrs {
|
for _, addr := range endpoint.Properties().Addrs {
|
||||||
// Skip IPv6 because not supported
|
|
||||||
if addr.IP.To4() == nil {
|
|
||||||
// Skip IPv6 because not supported
|
|
||||||
networkLogger().WithFields(logrus.Fields{
|
|
||||||
"unsupported-address-type": "ipv6",
|
|
||||||
"address": addr,
|
|
||||||
}).Warn("unsupported address")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Skip localhost interface
|
// Skip localhost interface
|
||||||
if addr.IP.IsLoopback() {
|
if addr.IP.IsLoopback() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
netMask, _ := addr.Mask.Size()
|
netMask, _ := addr.Mask.Size()
|
||||||
ipAddress := vcTypes.IPAddress{
|
ipAddress := vcTypes.IPAddress{
|
||||||
Family: netlink.FAMILY_V4,
|
Family: netlink.FAMILY_V4,
|
||||||
Address: addr.IP.String(),
|
Address: addr.IP.String(),
|
||||||
Mask: fmt.Sprintf("%d", netMask),
|
Mask: fmt.Sprintf("%d", netMask),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if addr.IP.To4() == nil {
|
||||||
|
ipAddress.Family = netlink.FAMILY_V6
|
||||||
|
}
|
||||||
ipAddresses = append(ipAddresses, &ipAddress)
|
ipAddresses = append(ipAddresses, &ipAddress)
|
||||||
}
|
}
|
||||||
noarp := endpoint.Properties().Iface.RawFlags & unix.IFF_NOARP
|
noarp := endpoint.Properties().Iface.RawFlags & unix.IFF_NOARP
|
||||||
@ -997,28 +993,10 @@ func generateInterfacesAndRoutes(networkNS NetworkNamespace) ([]*vcTypes.Interfa
|
|||||||
|
|
||||||
if route.Dst != nil {
|
if route.Dst != nil {
|
||||||
r.Dest = route.Dst.String()
|
r.Dest = route.Dst.String()
|
||||||
|
|
||||||
if route.Dst.IP.To4() == nil {
|
|
||||||
// Skip IPv6 because not supported
|
|
||||||
networkLogger().WithFields(logrus.Fields{
|
|
||||||
"unsupported-route-type": "ipv6",
|
|
||||||
"destination": r.Dest,
|
|
||||||
}).Warn("unsupported route")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if route.Gw != nil {
|
if route.Gw != nil {
|
||||||
gateway := route.Gw.String()
|
gateway := route.Gw.String()
|
||||||
|
|
||||||
if route.Gw.To4() == nil {
|
|
||||||
// Skip IPv6 because is is not supported
|
|
||||||
networkLogger().WithFields(logrus.Fields{
|
|
||||||
"unsupported-route-type": "ipv6",
|
|
||||||
"gateway": gateway,
|
|
||||||
}).Warn("unsupported route")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
r.Gateway = gateway
|
r.Gateway = gateway
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
package virtcontainers
|
package virtcontainers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -40,10 +41,12 @@ func TestGenerateInterfacesAndRoutes(t *testing.T) {
|
|||||||
//
|
//
|
||||||
address1 := &net.IPNet{IP: net.IPv4(172, 17, 0, 2), Mask: net.CIDRMask(16, 32)}
|
address1 := &net.IPNet{IP: net.IPv4(172, 17, 0, 2), Mask: net.CIDRMask(16, 32)}
|
||||||
address2 := &net.IPNet{IP: net.IPv4(182, 17, 0, 2), Mask: net.CIDRMask(16, 32)}
|
address2 := &net.IPNet{IP: net.IPv4(182, 17, 0, 2), Mask: net.CIDRMask(16, 32)}
|
||||||
|
address3 := &net.IPNet{IP: net.ParseIP("2001:db8:1::242:ac11:2"), Mask: net.CIDRMask(64, 128)}
|
||||||
|
|
||||||
addrs := []netlink.Addr{
|
addrs := []netlink.Addr{
|
||||||
{IPNet: address1, Label: "phyaddr1"},
|
{IPNet: address1, Label: "phyaddr1"},
|
||||||
{IPNet: address2, Label: "phyaddr2"},
|
{IPNet: address2, Label: "phyaddr2"},
|
||||||
|
{IPNet: address3, Label: "phyaddr3"},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a couple of routes:
|
// Create a couple of routes:
|
||||||
@ -51,9 +54,14 @@ func TestGenerateInterfacesAndRoutes(t *testing.T) {
|
|||||||
src2 := net.IPv4(172, 17, 0, 2)
|
src2 := net.IPv4(172, 17, 0, 2)
|
||||||
gw2 := net.IPv4(172, 17, 0, 1)
|
gw2 := net.IPv4(172, 17, 0, 1)
|
||||||
|
|
||||||
|
dstV6 := &net.IPNet{IP: net.ParseIP("2001:db8:1::"), Mask: net.CIDRMask(64, 128)}
|
||||||
|
gatewayV6 := net.ParseIP("2001:db8:1::1")
|
||||||
|
|
||||||
routes := []netlink.Route{
|
routes := []netlink.Route{
|
||||||
{LinkIndex: 329, Dst: nil, Src: nil, Gw: net.IPv4(172, 17, 0, 1), Scope: netlink.Scope(254)},
|
{LinkIndex: 329, Dst: nil, Src: nil, Gw: net.IPv4(172, 17, 0, 1), Scope: netlink.Scope(254)},
|
||||||
{LinkIndex: 329, Dst: dst2, Src: src2, Gw: gw2},
|
{LinkIndex: 329, Dst: dst2, Src: src2, Gw: gw2},
|
||||||
|
{LinkIndex: 329, Dst: dstV6, Src: nil, Gw: nil},
|
||||||
|
{LinkIndex: 329, Dst: nil, Src: nil, Gw: gatewayV6},
|
||||||
}
|
}
|
||||||
|
|
||||||
networkInfo := NetworkInfo{
|
networkInfo := NetworkInfo{
|
||||||
@ -83,6 +91,7 @@ func TestGenerateInterfacesAndRoutes(t *testing.T) {
|
|||||||
expectedAddresses := []*vcTypes.IPAddress{
|
expectedAddresses := []*vcTypes.IPAddress{
|
||||||
{Family: netlink.FAMILY_V4, Address: "172.17.0.2", Mask: "16"},
|
{Family: netlink.FAMILY_V4, Address: "172.17.0.2", Mask: "16"},
|
||||||
{Family: netlink.FAMILY_V4, Address: "182.17.0.2", Mask: "16"},
|
{Family: netlink.FAMILY_V4, Address: "182.17.0.2", Mask: "16"},
|
||||||
|
{Family: netlink.FAMILY_V6, Address: "2001:db8:1::242:ac11:2", Mask: "64"},
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedInterfaces := []*vcTypes.Interface{
|
expectedInterfaces := []*vcTypes.Interface{
|
||||||
@ -92,6 +101,12 @@ func TestGenerateInterfacesAndRoutes(t *testing.T) {
|
|||||||
expectedRoutes := []*vcTypes.Route{
|
expectedRoutes := []*vcTypes.Route{
|
||||||
{Dest: "", Gateway: "172.17.0.1", Device: "eth0", Source: "", Scope: uint32(254)},
|
{Dest: "", Gateway: "172.17.0.1", Device: "eth0", Source: "", Scope: uint32(254)},
|
||||||
{Dest: "172.17.0.0/16", Gateway: "172.17.0.1", Device: "eth0", Source: "172.17.0.2"},
|
{Dest: "172.17.0.0/16", Gateway: "172.17.0.1", Device: "eth0", Source: "172.17.0.2"},
|
||||||
|
{Dest: "2001:db8:1::/64", Gateway: "", Device: "eth0", Source: ""},
|
||||||
|
{Dest: "", Gateway: "2001:db8:1::1", Device: "eth0", Source: ""},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, r := range resRoutes {
|
||||||
|
fmt.Printf("resRoute: %+v\n", r)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Nil(t, err, "unexpected failure when calling generateKataInterfacesAndRoutes")
|
assert.Nil(t, err, "unexpected failure when calling generateKataInterfacesAndRoutes")
|
||||||
|
Loading…
Reference in New Issue
Block a user