| 1 | // Copyright 2015 CNI authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package mainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/ |
| 16 | |
| 17 | import ( |
| 18 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.24.2 `encoding/json`/" |
| 19 | "errorsscip-go gomod github.com/golang/go/src go1.24.2 errors/" |
| 20 | "fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/" |
| 21 | "runtimescip-go gomod github.com/golang/go/src go1.24.2 runtime/" |
| 22 | |
| 23 | "github.com/vishvananda/netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/" |
| 24 | |
| 25 | "github.com/containernetworking/cni/pkg/skelscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/" |
| 26 | "github.com/containernetworking/cni/pkg/typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/" |
| 27 | currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/ "github.com/containernetworking/cni/pkg/types/100scip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/" |
| 28 | "github.com/containernetworking/cni/pkg/versionscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/version`/" |
| 29 | "github.com/containernetworking/plugins/pkg/ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/" |
| 30 | "github.com/containernetworking/plugins/pkg/ipamscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/" |
| 31 | "github.com/containernetworking/plugins/pkg/netlinksafescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/" |
| 32 | "github.com/containernetworking/plugins/pkg/nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/" |
| 33 | bvscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/buildversion`/ "github.com/containernetworking/plugins/pkg/utils/buildversionscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/buildversion`/" |
| 34 | ) |
| 35 | |
| 36 | type NetConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf# struct { |
| 37 | typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/.NetConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#NetConf. |
| 38 | Masterscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#Master. string `json:"master"` |
| 39 | VlanIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#VlanID. int `json:"vlanId"` |
| 40 | MTUscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#MTU. int `json:"mtu,omitempty"` |
| 41 | LinkContNsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#LinkContNs. bool `json:"linkInContainer,omitempty"` |
| 42 | } |
| 43 | |
| 44 | func initscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/init().() { |
| 45 | // this ensures that main runs only on main thread (thread group leader). |
| 46 | // since namespace ops (unshare, setns) are done for a single thread, we |
| 47 | // must ensure that the goroutine does not jump from OS thread to thread |
| 48 | runtimescip-go gomod github.com/golang/go/src go1.24.2 runtime/.LockOSThreadscip-go gomod github.com/golang/go/src go1.24.2 runtime/LockOSThread().() |
| 49 | } |
| 50 | |
| 51 | func loadConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/loadConf().(args *skelscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/.CmdArgsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#) (*NetConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#, string, error) { |
| 52 | n := &NetConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#{} |
| 53 | if err := jsonscip-go gomod github.com/golang/go/src go1.24.2 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.24.2 `encoding/json`/Unmarshal().(args.StdinDatascip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#StdinData., n); err != nil { |
| 54 | return nil, "", fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("failed to load netconf: %v", err) |
| 55 | } |
| 56 | if n.Masterscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#Master. == "" { |
| 57 | return nil, "", fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("\"master\" field is required. It specifies the host interface name to create the VLAN for") |
| 58 | } |
| 59 | if n.VlanIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#VlanID. < 0 || n.VlanIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#VlanID. > 4094 { |
| 60 | return nil, "", fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("invalid VLAN ID %d (must be between 0 and 4095 inclusive)", n.VlanIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#VlanID.) |
| 61 | } |
| 62 | |
| 63 | // check existing and MTU of master interface |
| 64 | masterMTU, err := getMTUByNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/getMTUByName().(n.Masterscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#Master., args.Netnsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Netns., n.LinkContNsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#LinkContNs.) |
| 65 | if err != nil { |
| 66 | return nil, "", err |
| 67 | } |
| 68 | if n.MTUscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#MTU. < 0 || n.MTUscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#MTU. > masterMTU { |
| 69 | return nil, "", fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("invalid MTU %d, must be [0, master MTU(%d)]", n.MTUscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#MTU., masterMTU) |
| 70 | } |
| 71 | return n, n.CNIVersionscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#CNIVersion., nil |
| 72 | } |
| 73 | |
| 74 | func getMTUByNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/getMTUByName().(ifName string, namespace string, inContainer bool) (int, error) { |
| 75 | var link netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Linkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Link# |
| 76 | var err error |
| 77 | if inContainer { |
| 78 | var netns nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS# |
| 79 | netns, err = nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.GetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/GetNS().(namespace) |
| 80 | if err != nil { |
| 81 | return 0, fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("failed to open netns %q: %v", netns, err) |
| 82 | } |
| 83 | defer netns.Closescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Close.() |
| 84 | |
| 85 | err = netns.Doscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Do.(func(_ nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#) error { |
| 86 | link, err = netlinksafescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/.LinkByNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/LinkByName().(ifName) |
| 87 | return err |
| 88 | }) |
| 89 | } else { |
| 90 | link, err = netlinksafescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/.LinkByNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/LinkByName().(ifName) |
| 91 | } |
| 92 | if err != nil { |
| 93 | return 0, err |
| 94 | } |
| 95 | return link.Attrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Link#Attrs().().MTUscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#MTU., nil |
| 96 | } |
| 97 | |
| 98 | func createVlanscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/createVlan().(conf *NetConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#, ifName string, netns nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#) (*currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/.Interfacescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#, error) { |
| 99 | vlan := ¤tscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/.Interfacescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#{} |
| 100 | |
| 101 | var m netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Linkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Link# |
| 102 | var err error |
| 103 | if conf.LinkContNsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#LinkContNs. { |
| 104 | err = netns.Doscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Do.(func(_ nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#) error { |
| 105 | m, err = netlinksafescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/.LinkByNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/LinkByName().(conf.Masterscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#Master.) |
| 106 | return err |
| 107 | }) |
| 108 | } else { |
| 109 | m, err = netlinksafescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/.LinkByNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/LinkByName().(conf.Masterscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#Master.) |
| 110 | } |
| 111 | |
| 112 | if err != nil { |
| 113 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("failed to lookup master %q: %v", conf.Masterscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#Master., err) |
| 114 | } |
| 115 | |
| 116 | // due to kernel bug we have to create with tmpname or it might |
| 117 | // collide with the name on the host and error out |
| 118 | tmpName, err := ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/.RandomVethNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/RandomVethName().() |
| 119 | if err != nil { |
| 120 | return nil, err |
| 121 | } |
| 122 | |
| 123 | linkAttrs := netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.NewLinkAttrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/NewLinkAttrs().() |
| 124 | linkAttrs.MTUscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#MTU. = conf.MTUscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#MTU. |
| 125 | linkAttrs.Namescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#Name. = tmpName |
| 126 | linkAttrs.ParentIndexscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#ParentIndex. = m.Attrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Link#Attrs().().Indexscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#Index. |
| 127 | linkAttrs.Namespacescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#Namespace. = netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.NsFdscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/NsFd#(int(netns.Fdscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Fd.())) |
| 128 | |
| 129 | v := &netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Vlanscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Vlan#{ |
| 130 | LinkAttrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Vlan#LinkAttrs.: linkAttrs, |
| 131 | VlanIdscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Vlan#VlanId.: conf.VlanIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#VlanID., |
| 132 | } |
| 133 | |
| 134 | if conf.LinkContNsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#LinkContNs. { |
| 135 | err = netns.Doscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Do.(func(_ nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#) error { |
| 136 | return netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.LinkAddscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAdd().(v) |
| 137 | }) |
| 138 | } else { |
| 139 | err = netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.LinkAddscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAdd().(v) |
| 140 | } |
| 141 | if err != nil { |
| 142 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("failed to create vlan: %v", err) |
| 143 | } |
| 144 | |
| 145 | err = netns.Doscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Do.(func(_ nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#) error { |
| 146 | err := ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/.RenameLinkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/RenameLink().(tmpName, ifName) |
| 147 | if err != nil { |
| 148 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("failed to rename vlan to %q: %v", ifName, err) |
| 149 | } |
| 150 | vlan.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name. = ifName |
| 151 | |
| 152 | // Re-fetch interface to get all properties/attributes |
| 153 | contVlan, err := netlinksafescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/.LinkByNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/LinkByName().(vlan.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name.) |
| 154 | if err != nil { |
| 155 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("failed to refetch vlan %q: %v", vlan.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name., err) |
| 156 | } |
| 157 | vlan.Macscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Mac. = contVlan.Attrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Link#Attrs().().HardwareAddrscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#HardwareAddr..Stringscip-go gomod github.com/golang/go/src go1.24.2 net/HardwareAddr#String().() |
| 158 | vlan.Sandboxscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Sandbox. = netns.Pathscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Path.() |
| 159 | |
| 160 | return nil |
| 161 | }) |
| 162 | if err != nil { |
| 163 | return nil, err |
| 164 | } |
| 165 | |
| 166 | return vlan, nil |
| 167 | } |
| 168 | |
| 169 | func cmdAddscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/cmdAdd().(args *skelscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/.CmdArgsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#) error { |
| 170 | n, cniVersion, err := loadConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/loadConf().(args) |
| 171 | if err != nil { |
| 172 | return err |
| 173 | } |
| 174 | |
| 175 | netns, err := nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.GetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/GetNS().(args.Netnsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Netns.) |
| 176 | if err != nil { |
| 177 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("failed to open netns %q: %v", args.Netnsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Netns., err) |
| 178 | } |
| 179 | defer netns.Closescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Close.() |
| 180 | |
| 181 | vlanInterface, err := createVlanscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/createVlan().(n, args.IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName., netns) |
| 182 | if err != nil { |
| 183 | return err |
| 184 | } |
| 185 | |
| 186 | // run the IPAM plugin and get back the config to apply |
| 187 | r, err := ipamscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/.ExecAddscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/ExecAdd().(n.IPAMscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#IPAM..Typescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/IPAM#Type., args.StdinDatascip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#StdinData.) |
| 188 | if err != nil { |
| 189 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("failed to execute IPAM delegate: %v", err) |
| 190 | } |
| 191 | |
| 192 | // Invoke ipam del if err to avoid ip leak |
| 193 | defer func() { |
| 194 | if err != nil { |
| 195 | ipamscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/.ExecDelscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/ExecDel().(n.IPAMscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#IPAM..Typescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/IPAM#Type., args.StdinDatascip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#StdinData.) |
| 196 | } |
| 197 | }() |
| 198 | |
| 199 | // Convert whatever the IPAM result was into the current Result type |
| 200 | result, err := currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/.NewResultFromResultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/NewResultFromResult().(r) |
| 201 | if err != nil { |
| 202 | return err |
| 203 | } |
| 204 | |
| 205 | if len(result.IPsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#IPs.) == 0 { |
| 206 | return errorsscip-go gomod github.com/golang/go/src go1.24.2 errors/.Newscip-go gomod github.com/golang/go/src go1.24.2 errors/New().("IPAM plugin returned missing IP config") |
| 207 | } |
| 208 | for _, ipc := range result.IPsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#IPs. { |
| 209 | // All addresses belong to the vlan interface |
| 210 | ipc.Interfacescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/IPConfig#Interface. = currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/.Intscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Int().(0) |
| 211 | } |
| 212 | |
| 213 | result.Interfacesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#Interfaces. = []*currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/.Interfacescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#{vlanInterface} |
| 214 | |
| 215 | err = netns.Doscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Do.(func(_ nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#) error { |
| 216 | return ipamscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/.ConfigureIfacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/ConfigureIface().(args.IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName., result) |
| 217 | }) |
| 218 | if err != nil { |
| 219 | return err |
| 220 | } |
| 221 | |
| 222 | result.DNSscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#DNS. = n.DNSscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#DNS. |
| 223 | |
| 224 | return typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/.PrintResultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PrintResult().(result, cniVersion) |
| 225 | } |
| 226 | |
| 227 | func cmdDelscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/cmdDel().(args *skelscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/.CmdArgsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#) error { |
| 228 | n, _, err := loadConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/loadConf().(args) |
| 229 | if err != nil { |
| 230 | return err |
| 231 | } |
| 232 | |
| 233 | err = ipamscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/.ExecDelscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/ExecDel().(n.IPAMscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#IPAM..Typescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/IPAM#Type., args.StdinDatascip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#StdinData.) |
| 234 | if err != nil { |
| 235 | return err |
| 236 | } |
| 237 | |
| 238 | if args.Netnsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Netns. == "" { |
| 239 | return nil |
| 240 | } |
| 241 | |
| 242 | err = nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.WithNetNSPathscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/WithNetNSPath().(args.Netnsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Netns., func(_ nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#) error { |
| 243 | err = ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/.DelLinkByNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/DelLinkByName().(args.IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName.) |
| 244 | if err != nil && err == ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/.ErrLinkNotFoundscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/ErrLinkNotFound. { |
| 245 | return nil |
| 246 | } |
| 247 | return err |
| 248 | }) |
| 249 | if err != nil { |
| 250 | // if NetNs is passed down by the Cloud Orchestration Engine, or if it called multiple times |
| 251 | // so don't return an error if the device is already removed. |
| 252 | // https://github.com/kubernetes/kubernetes/issues/43014#issuecomment-287164444 |
| 253 | _, ok := err.(nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NSPathNotExistErrscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NSPathNotExistErr#) |
| 254 | if ok { |
| 255 | return nil |
| 256 | } |
| 257 | return err |
| 258 | } |
| 259 | |
| 260 | return err |
| 261 | } |
| 262 | |
| 263 | func mainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/main().() { |
| 264 | skelscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/.PluginMainFuncsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/PluginMainFuncs().(skelscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/.CNIFuncsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CNIFuncs#{ |
| 265 | Addscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CNIFuncs#Add.: cmdAddscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/cmdAdd()., |
| 266 | Checkscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CNIFuncs#Check.: cmdCheckscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/cmdCheck()., |
| 267 | Delscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CNIFuncs#Del.: cmdDelscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/cmdDel()., |
| 268 | Statusscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CNIFuncs#Status.: cmdStatusscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/cmdStatus()., |
| 269 | /* FIXME GC */ |
| 270 | }, versionscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/version`/.Allscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/version`/All., bvscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/buildversion`/.BuildStringscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/buildversion`/BuildString().("vlan")) |
| 271 | } |
| 272 | |
| 273 | func cmdCheckscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/cmdCheck().(args *skelscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/.CmdArgsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#) error { |
| 274 | conf := NetConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#{} |
| 275 | if err := jsonscip-go gomod github.com/golang/go/src go1.24.2 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.24.2 `encoding/json`/Unmarshal().(args.StdinDatascip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#StdinData., &conf); err != nil { |
| 276 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("failed to load netconf: %v", err) |
| 277 | } |
| 278 | |
| 279 | netns, err := nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.GetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/GetNS().(args.Netnsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Netns.) |
| 280 | if err != nil { |
| 281 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("failed to open netns %q: %v", args.Netnsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Netns., err) |
| 282 | } |
| 283 | defer netns.Closescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Close.() |
| 284 | |
| 285 | // run the IPAM plugin and get back the config to apply |
| 286 | err = ipamscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/.ExecCheckscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/ExecCheck().(conf.IPAMscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#IPAM..Typescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/IPAM#Type., args.StdinDatascip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#StdinData.) |
| 287 | if err != nil { |
| 288 | return err |
| 289 | } |
| 290 | if conf.NetConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#NetConf..RawPrevResultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#RawPrevResult. == nil { |
| 291 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("vlan: Required prevResult missing") |
| 292 | } |
| 293 | if err := versionscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/version`/.ParsePrevResultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/version`/ParsePrevResult().(&conf.NetConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#NetConf.); err != nil { |
| 294 | return err |
| 295 | } |
| 296 | // Convert whatever the IPAM result was into the current Result type |
| 297 | result, err := currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/.NewResultFromResultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/NewResultFromResult().(conf.PrevResultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#PrevResult.) |
| 298 | if err != nil { |
| 299 | return err |
| 300 | } |
| 301 | |
| 302 | var contMap currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/.Interfacescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface# |
| 303 | // Find interfaces for name whe know, that of host-device inside container |
| 304 | for _, intf := range result.Interfacesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#Interfaces. { |
| 305 | if args.IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName. == intf.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name. { |
| 306 | if args.Netnsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Netns. == intf.Sandboxscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Sandbox. { |
| 307 | contMap = *intf |
| 308 | continue |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | // The namespace must be the same as what was configured |
| 314 | if args.Netnsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Netns. != contMap.Sandboxscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Sandbox. { |
| 315 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("Sandbox in prevResult %s doesn't match configured netns: %s", |
| 316 | contMap.Sandboxscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Sandbox., args.Netnsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Netns.) |
| 317 | } |
| 318 | |
| 319 | if conf.LinkContNsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#LinkContNs. { |
| 320 | err = netns.Doscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Do.(func(_ nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#) error { |
| 321 | _, err = netlinksafescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/.LinkByNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/LinkByName().(conf.Masterscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#Master.) |
| 322 | return err |
| 323 | }) |
| 324 | } else { |
| 325 | _, err = netlinksafescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/.LinkByNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/LinkByName().(conf.Masterscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#Master.) |
| 326 | } |
| 327 | |
| 328 | if err != nil { |
| 329 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("failed to lookup master %q: %v", conf.Masterscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#Master., err) |
| 330 | } |
| 331 | |
| 332 | // |
| 333 | // Check prevResults for ips, routes and dns against values found in the container |
| 334 | if err := netns.Doscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Do.(func(_ nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#) error { |
| 335 | // Check interface against values found in the container |
| 336 | err := validateCniContainerInterfacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/validateCniContainerInterface().(contMap, conf.VlanIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#VlanID., conf.MTUscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#MTU.) |
| 337 | if err != nil { |
| 338 | return err |
| 339 | } |
| 340 | |
| 341 | err = ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/.ValidateExpectedInterfaceIPsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/ValidateExpectedInterfaceIPs().(args.IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName., result.IPsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#IPs.) |
| 342 | if err != nil { |
| 343 | return err |
| 344 | } |
| 345 | |
| 346 | err = ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/.ValidateExpectedRoutescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/ValidateExpectedRoute().(result.Routesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#Routes.) |
| 347 | if err != nil { |
| 348 | return err |
| 349 | } |
| 350 | return nil |
| 351 | }); err != nil { |
| 352 | return err |
| 353 | } |
| 354 | |
| 355 | return nil |
| 356 | } |
| 357 | |
| 358 | func validateCniContainerInterfacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/validateCniContainerInterface().(intf currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/.Interfacescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#, vlanID int, mtu int) error { |
| 359 | var link netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Linkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Link# |
| 360 | var err error |
| 361 | |
| 362 | if intf.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name. == "" { |
| 363 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("Container interface name missing in prevResult: %v", intf.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name.) |
| 364 | } |
| 365 | link, err = netlinksafescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/.LinkByNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/LinkByName().(intf.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name.) |
| 366 | if err != nil { |
| 367 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("vlan: Container Interface name in prevResult: %s not found", intf.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name.) |
| 368 | } |
| 369 | if intf.Sandboxscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Sandbox. == "" { |
| 370 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("vlan: Error: Container interface %s should not be in host namespace", link.Attrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Link#Attrs().().Namescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#Name.) |
| 371 | } |
| 372 | |
| 373 | vlan, isVlan := link.(*netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Vlanscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Vlan#) |
| 374 | if !isVlan { |
| 375 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("Error: Container interface %s not of type vlan", link.Attrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Link#Attrs().().Namescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#Name.) |
| 376 | } |
| 377 | |
| 378 | // TODO This works when unit testing via cnitool; fails with ./test.sh |
| 379 | // if masterIndex != vlan.Attrs().ParentIndex { |
| 380 | // return fmt.Errorf("Container vlan Master %d does not match expected value: %d", vlan.Attrs().ParentIndex, masterIndex) |
| 381 | //} |
| 382 | |
| 383 | if intf.Macscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Mac. != "" { |
| 384 | if intf.Macscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Mac. != link.Attrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Link#Attrs().().HardwareAddrscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#HardwareAddr..Stringscip-go gomod github.com/golang/go/src go1.24.2 net/HardwareAddr#String().() { |
| 385 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("vlan: Interface %s Mac %s doesn't match container Mac: %s", intf.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name., intf.Macscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Mac., link.Attrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Link#Attrs().().HardwareAddrscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#HardwareAddr.) |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | if vlanID != vlan.VlanIdscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Vlan#VlanId. { |
| 390 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("Error: Tuning link %s configured promisc is %v, current value is %d", |
| 391 | intf.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name., vlanID, vlan.VlanIdscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Vlan#VlanId.) |
| 392 | } |
| 393 | |
| 394 | if mtu != 0 { |
| 395 | if mtu != link.Attrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Link#Attrs().().MTUscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#MTU. { |
| 396 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("Error: Tuning configured MTU of %s is %d, current value is %d", |
| 397 | intf.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name., mtu, link.Attrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Link#Attrs().().MTUscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#MTU.) |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | return nil |
| 402 | } |
| 403 | |
| 404 | func cmdStatusscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/cmdStatus().(args *skelscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/.CmdArgsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#) error { |
| 405 | conf := NetConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/vlan`/NetConf#{} |
| 406 | if err := jsonscip-go gomod github.com/golang/go/src go1.24.2 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.24.2 `encoding/json`/Unmarshal().(args.StdinDatascip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#StdinData., &conf); err != nil { |
| 407 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("failed to load netconf: %w", err) |
| 408 | } |
| 409 | |
| 410 | if err := ipamscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/.ExecStatusscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/ExecStatus().(conf.IPAMscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#IPAM..Typescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/IPAM#Type., args.StdinDatascip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#StdinData.); err != nil { |
| 411 | return err |
| 412 | } |
| 413 | |
| 414 | // TODO: Check if master interface exists. |
| 415 | |
| 416 | return nil |
| 417 | } |