Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
ipv6: Add flag IFA_F_NODAD for ipv6 address.
Browse files Browse the repository at this point in the history
This is done so that interfaces with ipv6 addresses can immediately
be used once the network is up.
A similar flag is set by libnetwork as well.
It should be the responsibility of the upper stack to
make sure ipv6 addresses dont clash.

Depends-on: github.com/#2420

Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
  • Loading branch information
amshinde committed Jan 28, 2020
1 parent 93a901c commit c66b927
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions network.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ func updateLink(netHandle *netlink.Handle, link netlink.Link, iface *types.Inter
netlinkAddrStr := fmt.Sprintf("%s/%s", addr.Address, addr.Mask)
netlinkAddr, err := netlink.ParseAddr(netlinkAddrStr)

// With ipv6 addresses, there is a brief period during which the address is marked as "tentative"
// making it unavailable. A process called duplicate address detection(DAD) is performed during this period.
// Disble DAD so that networking is available once the container is up. The assumption is
// that it is the reponsibility of the upper stack to make sure the addresses assigned to containers
// do not conflict. A similar operation is performed by libnetwork:
// https://github.com/moby/moby/issues/18871

if addr.GetFamily() == types.IPFamily_v6 {
netlinkAddr.Flags = netlinkAddr.Flags | syscall.IFA_F_NODAD
}

if err != nil {
return grpcStatus.Errorf(codes.Internal, "Could not parse %q: %v", netlinkAddrStr, err)
}
Expand Down
11 changes: 11 additions & 0 deletions network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"reflect"
"runtime"
"strings"
"syscall"
"testing"

"github.com/kata-containers/agent/pkg/types"
Expand Down Expand Up @@ -301,6 +302,16 @@ func TestListInterfaces(t *testing.T) {
ip := net.ParseIP(ipAddr.Address)
assert.True(ip.IsLinkLocalUnicast())
}

// Check IFA_F_NODAD flag is set on ipv6 address
l, err := netlink.LinkByName(ifc.Name)
assert.Nil(err)
addrList, err := netlink.AddrList(l, netlink.FAMILY_V6)
assert.Nil(err)

if addrList[0].Flags&syscall.IFA_F_NODAD == 0 {
t.Fatalf("Unexpected interface flags for addr %+v: 0x%x. Expected to contain 0x%x", addrList[0], addrList[0].Flags, syscall.IFA_F_NODAD)
}
}

func TestListRoutes(t *testing.T) {
Expand Down

0 comments on commit c66b927

Please sign in to comment.