From a0374eec3365023a907da12316b6506e81efab8c Mon Sep 17 00:00:00 2001 From: Casey Callendrello Date: Wed, 20 Mar 2024 21:17:07 +0100 Subject: [PATCH] plugins/meta: stub CNI v1.1 implementation This adds a basic CNI v1.1 implementation to the meta plugins. For the plugins which do have state (firewall, bandwidth, portmap) this does *not* perform GC. That remains outstanding. Signed-off-by: Casey Callendrello --- plugins/ipam/static/main.go | 7 ++++++- plugins/meta/bandwidth/main.go | 12 +++++++++++- plugins/meta/firewall/firewall.go | 20 +++++++++++++++++++- plugins/meta/portmap/main.go | 7 ++++++- plugins/meta/sbr/main.go | 7 ++++++- plugins/meta/tuning/tuning.go | 7 ++++++- plugins/meta/vrf/main.go | 7 ++++++- 7 files changed, 60 insertions(+), 7 deletions(-) diff --git a/plugins/ipam/static/main.go b/plugins/ipam/static/main.go index bf541d2d6..25731c9d0 100644 --- a/plugins/ipam/static/main.go +++ b/plugins/ipam/static/main.go @@ -68,7 +68,12 @@ type Address struct { } func main() { - skel.PluginMain(cmdAdd, cmdCheck, cmdDel, version.All, bv.BuildString("static")) + skel.PluginMainFuncs( + skel.CNIFuncs{ + Add: cmdAdd, + Check: cmdCheck, + Del: cmdDel, + }, version.All, bv.BuildString("static")) } func loadNetConf(bytes []byte) (*types.NetConf, string, error) { diff --git a/plugins/meta/bandwidth/main.go b/plugins/meta/bandwidth/main.go index 66eae1521..308b7919f 100644 --- a/plugins/meta/bandwidth/main.go +++ b/plugins/meta/bandwidth/main.go @@ -218,6 +218,7 @@ func cmdAdd(args *skel.CmdArgs) error { result.Interfaces = append(result.Interfaces, ¤t.Interface{ Name: ifbDeviceName, Mac: ifbDevice.Attrs().HardwareAddr.String(), + Mtu: mtu, }) err = CreateEgressQdisc(bandwidth.EgressRate, bandwidth.EgressBurst, hostInterface.Name, ifbDeviceName) if err != nil { @@ -240,7 +241,16 @@ func cmdDel(args *skel.CmdArgs) error { } func main() { - skel.PluginMain(cmdAdd, cmdCheck, cmdDel, version.VersionsStartingFrom("0.3.0"), bv.BuildString("bandwidth")) + // TODO: clean up stale IFB devices via GC + // Cannot do this until we can filter out only ifb devices that belong + // to this network. + skel.PluginMainFuncs( + skel.CNIFuncs{ + Add: cmdAdd, + Check: cmdCheck, + Del: cmdDel, + }, + version.VersionsStartingFrom("0.3.0"), bv.BuildString("bandwidth")) } func SafeQdiscList(link netlink.Link) ([]netlink.Qdisc, error) { diff --git a/plugins/meta/firewall/firewall.go b/plugins/meta/firewall/firewall.go index f2f8a4d56..0e0e61c2e 100644 --- a/plugins/meta/firewall/firewall.go +++ b/plugins/meta/firewall/firewall.go @@ -179,7 +179,13 @@ func cmdDel(args *skel.CmdArgs) error { } func main() { - skel.PluginMain(cmdAdd, cmdCheck, cmdDel, version.VersionsStartingFrom("0.4.0"), bv.BuildString("firewall")) + skel.PluginMainFuncs( + skel.CNIFuncs{ + Add: cmdAdd, + Check: cmdCheck, + Del: cmdDel, + Status: cmdStatus, + }, version.VersionsStartingFrom("0.4.0"), bv.BuildString("firewall")) } func cmdCheck(args *skel.CmdArgs) error { @@ -200,3 +206,15 @@ func cmdCheck(args *skel.CmdArgs) error { return backend.Check(conf, result) } + +func cmdStatus(args *skel.CmdArgs) error { + conf := FirewallNetConf{} + if err := json.Unmarshal(args.StdinData, &conf); err != nil { + return fmt.Errorf("failed to load netconf: %v", err) + } + + if conf.Backend == "firewalld" && !isFirewalldRunning() { + return types.NewError(50, "firewalld down", "unable to connect to the firewalld backend") + } + return nil +} diff --git a/plugins/meta/portmap/main.go b/plugins/meta/portmap/main.go index 09af586a5..cfab9a350 100644 --- a/plugins/meta/portmap/main.go +++ b/plugins/meta/portmap/main.go @@ -134,7 +134,12 @@ func cmdDel(args *skel.CmdArgs) error { } func main() { - skel.PluginMain(cmdAdd, cmdCheck, cmdDel, version.All, bv.BuildString("portmap")) + skel.PluginMainFuncs( + skel.CNIFuncs{ + Add: cmdAdd, + Check: cmdCheck, + Del: cmdDel, + }, version.All, bv.BuildString("portmap")) } func cmdCheck(args *skel.CmdArgs) error { diff --git a/plugins/meta/sbr/main.go b/plugins/meta/sbr/main.go index f07e7520f..89be78e11 100644 --- a/plugins/meta/sbr/main.go +++ b/plugins/meta/sbr/main.go @@ -401,7 +401,12 @@ RULE_LOOP: } func main() { - skel.PluginMain(cmdAdd, cmdCheck, cmdDel, version.All, bv.BuildString("sbr")) + skel.PluginMainFuncs( + skel.CNIFuncs{ + Add: cmdAdd, + Check: cmdCheck, + Del: cmdDel, + }, version.All, bv.BuildString("sbr")) } func cmdCheck(_ *skel.CmdArgs) error { diff --git a/plugins/meta/tuning/tuning.go b/plugins/meta/tuning/tuning.go index ed23d9208..cb0ab59dd 100644 --- a/plugins/meta/tuning/tuning.go +++ b/plugins/meta/tuning/tuning.go @@ -433,7 +433,12 @@ func cmdDel(args *skel.CmdArgs) error { } func main() { - skel.PluginMain(cmdAdd, cmdCheck, cmdDel, version.All, bv.BuildString("tuning")) + skel.PluginMainFuncs( + skel.CNIFuncs{ + Add: cmdAdd, + Check: cmdCheck, + Del: cmdDel, + }, version.All, bv.BuildString("tuning")) } func cmdCheck(args *skel.CmdArgs) error { diff --git a/plugins/meta/vrf/main.go b/plugins/meta/vrf/main.go index c83234328..c73363c32 100644 --- a/plugins/meta/vrf/main.go +++ b/plugins/meta/vrf/main.go @@ -39,7 +39,12 @@ type VRFNetConf struct { } func main() { - skel.PluginMain(cmdAdd, cmdCheck, cmdDel, version.VersionsStartingFrom("0.3.1"), bv.BuildString("vrf")) + skel.PluginMainFuncs( + skel.CNIFuncs{ + Add: cmdAdd, + Check: cmdCheck, + Del: cmdDel, + }, version.VersionsStartingFrom("0.3.1"), bv.BuildString("vrf")) } func cmdAdd(args *skel.CmdArgs) error {