Skip to content

Commit

Permalink
Only handle valid CNI_ARGS
Browse files Browse the repository at this point in the history
If arguments fail to parse, continue without additional endpoint
configuration.
  • Loading branch information
mendsley committed Nov 22, 2024
1 parent 1d53425 commit 1c75a46
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions common/core/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,6 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) (resultError error) {
k8sNamespace = string(podConfig.K8S_POD_NAMESPACE)
}

epConfig, err := cni.ParseCniEndpointArgs(args.Args)
if err != nil {
logrus.Errorf("[cni-net] Failed to parse endpoint args, err:%v", err)
return err
}

// Parse network configuration from stdin.
cniConfig, err := cni.ParseNetworkConfig(args.StdinData)
if err != nil {
Expand Down Expand Up @@ -139,14 +133,17 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) (resultError error) {
return err
}

if epConfig.MAC != "" {
hwAddr, err := net.ParseMAC(string(epConfig.MAC))
if err != nil {
logrus.Errorf("[cni-net] Failed to parse MAC addres '%s', err:%v", epConfig.MAC, err)
return err
}
epConfig, err := cni.ParseCniEndpointArgs(args.Args)
if err == nil {
if epConfig.MAC != "" {
hwAddr, err := net.ParseMAC(string(epConfig.MAC))
if err != nil {
logrus.Errorf("[cni-net] Failed to parse MAC addres '%s', err:%v", epConfig.MAC, err)
return err
}

epInfo.MacAddress = hwAddr
epInfo.MacAddress = hwAddr
}
}
epInfo.DualStack = cniConfig.OptionalFlags.EnableDualStack

Expand Down

0 comments on commit 1c75a46

Please sign in to comment.