Skip to content

Commit

Permalink
loopback support CNI CHECK
Browse files Browse the repository at this point in the history
Signed-off-by: Bruce Ma <[email protected]>
  • Loading branch information
mars1024 committed Aug 23, 2019
1 parent 485be65 commit 659a09f
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions plugins/main/loopback/loopback.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
package main

import (
"errors"
"net"

"github.com/vishvananda/netlink"

"github.com/containernetworking/cni/pkg/skel"
Expand Down Expand Up @@ -78,6 +81,18 @@ func main() {
}

func cmdCheck(args *skel.CmdArgs) error {
// TODO: implement
return nil
args.IfName = "lo" // ignore config, this only works for loopback

return ns.WithNetNSPath(args.Netns, func(_ ns.NetNS) error {
link, err := netlink.LinkByName(args.IfName)
if err != nil {
return err
}

if link.Attrs().Flags&net.FlagUp != net.FlagUp {
return errors.New("loopback interface is down")
}

return nil
})
}

0 comments on commit 659a09f

Please sign in to comment.