func()

in cmd/egress-cni-plugin/egressContext.go [243:282]


func (ec *egressContext) cmdAddEgressV4() (err error) {
	if ec.IPTablesIface == nil {
		if ec.IPTablesIface, err = ec.IptCreator(iptables.ProtocolIPv4); err != nil {
			ec.Log.Error("command iptables not found")
			return err
		}
	}
	if err = cniutils.EnableIpForwarding(ec.Procsys, ec.TmpResult.IPs); err != nil {
		return fmt.Errorf("could not enable IP forwarding: %v", err)
	}

	// NB: This uses netConf.IfName NOT args.IfName.
	hostInterface, _, err := ec.setupContainerVethV4()
	if err != nil {
		ec.Log.Debugf("failed to setup container Veth: %v", err)
		return err
	}

	if err = ec.setupHostVethV4(hostInterface.Name); err != nil {
		return err
	}

	ec.Log.Debugf("Node IP: %s", ec.NetConf.NodeIP)
	if ec.NetConf.NodeIP != nil {
		for _, ipc := range ec.TmpResult.IPs {
			if ipc.Address.IP.To4() != nil {
				// add SNAT chain/rules necessary for the container IPv6 egress traffic
				if err = snat.Add(ec.IPTablesIface, ec.NetConf.NodeIP, ipc.Address.IP, ipv4MulticastRange, ec.SnatChain, ec.SnatComment, ec.NetConf.RandomizeSNAT); err != nil {
					return err
				}
			}
		}
	}

	// Copy interfaces over to result, but not IPs.
	ec.Result.Interfaces = append(ec.Result.Interfaces, ec.TmpResult.Interfaces...)

	// Pass through the previous result
	return types.PrintResult(ec.Result, ec.NetConf.CNIVersion)
}