Skip to content

Commit

Permalink
Refactoring post process handling to gracefully handle user space int…
Browse files Browse the repository at this point in the history
…erfaces

The problem corrected in the first commit was just one symptom of ungraceful handling of user space interfaces.
The real, and generic correction is delivered by this commit.
Post-processing in general is now skipped for links not managed by the kernel.
A warning message is also written when this happens, so post-mortem debugging for kernel managed links is still possible.
  • Loading branch information
Levovar committed Oct 14, 2020
1 parent 8eb17f0 commit de42312
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
15 changes: 9 additions & 6 deletions pkg/danmep/danmep.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,20 @@ func PostProcessInterface(ep *danmtypes.DanmEp, dnet *danmtypes.DanmNet) error {
return errors.New("failed to create dummy kernel interface for " + ep.Spec.Iface.Name + " because:" + err.Error())
}
}
link, err := netlink.LinkByName(ep.Spec.Iface.Name)
if err != nil {
log.Println("WARNING: Interface post-processing was skipped for Pod:" + ep.Spec.Pod + " and link:" + ep.Spec.Iface.Name + " because it does not exist in the kernel. If it is not a user space interface, you should investigate!!!")
return nil
}
err = setDanmEpSysctls(ep)
if err != nil {
return errors.New("failed to set kernel configs for interface" + ep.Spec.Iface.Name + " because:" + err.Error())
}
err = disableDadOnIface(ep, isVfAttachedToDpdkDriver)
err = disableDadOnIface(link, ep)
if err != nil {
return errors.New("failed to disable DAD for address" + ep.Spec.Iface.AddressIPv6 + " because:" + err.Error())
}
return addIpRoutes(ep,dnet)
return addIpRoutes(link, ep, dnet)
}

func setDanmEpSysctls(ep *danmtypes.DanmEp) error {
Expand All @@ -232,16 +237,14 @@ func setDanmEpSysctls(ep *danmtypes.DanmEp) error {
}

func isIPv6Needed(ep *danmtypes.DanmEp) bool {
_, err := os.Stat(V6SysPath + ep.Spec.Iface.Name)
if err == nil && ep.Spec.Iface.AddressIPv6 != "" {
if ep.Spec.Iface.AddressIPv6 != "" {
return true
}
return false
}

func isIPv6NotNeeded(ep *danmtypes.DanmEp) bool {
_, err := os.Stat(V6SysPath + ep.Spec.Iface.Name)
if err == nil && ep.Spec.Iface.AddressIPv6 == "" {
if ep.Spec.Iface.AddressIPv6 == "" {
return true
}
return false
Expand Down
16 changes: 4 additions & 12 deletions pkg/danmep/ep.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,9 @@ func addIpToLink(ip string, iface netlink.Link) error {
return nil
}

func addIpRoutes(ep *danmtypes.DanmEp, dnet *danmtypes.DanmNet) error {
func addIpRoutes(link netlink.Link, ep *danmtypes.DanmEp, dnet *danmtypes.DanmNet) error {
defaultRoutingTable := 0
link, err := netlink.LinkByName(ep.Spec.Iface.Name)
if err != nil {
return errors.New("cannot find Pod interface: " + ep.Spec.Iface.Name + " for adding IP route because:" + err.Error())
}
err = addRouteForLink(dnet.Spec.Options.Routes, ep.Spec.Iface.Address, defaultRoutingTable, link)
err := addRouteForLink(dnet.Spec.Options.Routes, ep.Spec.Iface.Address, defaultRoutingTable, link)
if err != nil {
return err
}
Expand Down Expand Up @@ -341,14 +337,10 @@ func createDummyInterface(ep *danmtypes.DanmEp, dnet *danmtypes.DanmNet) error {
return configureLink(iface, ep)
}

func disableDadOnIface(ep *danmtypes.DanmEp, isDummyIface bool) error {
if isDummyIface || ep.Spec.NetworkType == "ipvlan" || ep.Spec.Iface.AddressIPv6 == "" || ep.Spec.Iface.AddressIPv6 == ipam.NoneAllocType {
func disableDadOnIface(link netlink.Link, ep *danmtypes.DanmEp) error {
if ep.Spec.NetworkType == "ipvlan" || ep.Spec.Iface.AddressIPv6 == "" || ep.Spec.Iface.AddressIPv6 == ipam.NoneAllocType {
return nil
}
link, err := netlink.LinkByName(ep.Spec.Iface.Name)
if err != nil {
return errors.New("cannot find interface to disable DAD on its V6 address because:" + err.Error())
}
addr, pref, _ := net.ParseCIDR(ep.Spec.Iface.AddressIPv6)
dadlessAddress := &netlink.Addr{IPNet: &net.IPNet{IP: addr, Mask: pref.Mask}, Flags: syscall.IFA_F_NODAD,}
return netlink.AddrReplace(link, dadlessAddress)
Expand Down

0 comments on commit de42312

Please sign in to comment.