diff --git a/pkg/cni-plugin/plugin/ovs.go b/pkg/cni-plugin/plugin/ovs.go index 28ffd4fe2..66e0a1eb5 100644 --- a/pkg/cni-plugin/plugin/ovs.go +++ b/pkg/cni-plugin/plugin/ovs.go @@ -12,7 +12,7 @@ import ( ) type OVSClient interface { - AddPort(bridge, port string) error + AddPort(bridge, port string, vlanId int) error DeletePort(bridge, port string) error SetIfaceId(id string, name string) error } @@ -37,11 +37,20 @@ func newTimeoutCtx() context.Context { return ctx } -func (sw *ovsClient) AddPort(bridge, port string) error { - return sw.agentCli.W(sw.agentCli.VSwitch.AddBridgePort(newTimeoutCtx(), &pb.AddBridgePortRequest{ +func (sw *ovsClient) AddPort(bridge, port string, vlanId int) error { + /*return sw.agentCli.W(sw.agentCli.VSwitch.AddBridgePort(newTimeoutCtx(), &pb.AddBridgePortRequest{ Bridge: bridge, Port: port, - })) + }))*/ + args := []string{"add-port", bridge, port} + if vlanId > 1 { + args = append(args, fmt.Sprintf("tag=%d", vlanId)) + } + ovsCmd := exec.Command("ovs-vsctl", args...) + if out, err := ovsCmd.CombinedOutput(); err != nil { + return errors.Wrapf(err, "add port to ovs %v: %s", args, out) + } + return nil } func (sw *ovsClient) SetIfaceId(netId string, ifName string) error { diff --git a/pkg/cni-plugin/plugin/types.go b/pkg/cni-plugin/plugin/types.go index 738b60ecf..771c021b6 100644 --- a/pkg/cni-plugin/plugin/types.go +++ b/pkg/cni-plugin/plugin/types.go @@ -25,15 +25,19 @@ type PodNic struct { Ifname string `json:"ifname"` Interface string `json:"interface"` Ip string `json:"ip"` + Ip6 string `json:"ip6"` Mac string `json:"mac"` Gateway string `json:"gateway"` + Gateway6 string `json:"gateway6"` Bandwidth int `json:"bw"` Dns string `json:"dns"` Mtu int `json:"mtu"` Masklen int `json:"masklen,omitempty"` + Masklen6 int `json:"masklen6,omitempty"` Domain string `json:"domain,omitempty"` NetId string `json:"net_id"` WireId string `json:"wire_id"` + Vlan int `json:"vlan"` Vpc *PodNicVpc `json:"vpc,omitempty"` } diff --git a/pkg/cni-plugin/plugin/utils.go b/pkg/cni-plugin/plugin/utils.go index 369e0be82..1b00170c6 100644 --- a/pkg/cni-plugin/plugin/utils.go +++ b/pkg/cni-plugin/plugin/utils.go @@ -173,7 +173,35 @@ func getNetworkConfig(idx int, nic PodNic, defaultGw bool) (*current.Interface, GW: defaultGateway, } routes = append(routes, route) + + } + // process ipv6 + if nic.Ip6 != "" { + ip6n, err := getIPNet(nic.Ip6, nic.Masklen6) + if err != nil { + return nil, nil, nil, errors.Wrap(err, "get ipv6 network") + } + gatewayIp6 := net.ParseIP(nic.Gateway6) + ip6Config := ¤t.IPConfig{ + Version: "6", + Interface: &idx, + Address: *ip6n, + Gateway: gatewayIp6, + } + ipConfigs = append(ipConfigs, ip6Config) + + // add ipv6 default route if ipv6 is configured + if defaultGw { + _, defaultNet6, _ := net.ParseCIDR("::/0") + defaultGateway6 := net.ParseIP(nic.Gateway6) + route6 := &types.Route{ + Dst: *defaultNet6, + GW: defaultGateway6, + } + routes = append(routes, route6) + } } + return ctrIf, ipConfigs, routes, nil } @@ -250,7 +278,7 @@ func setupVeth( } hostIf.Mac = hostVeth.Attrs().HardwareAddr.String() - if err := cli.AddPort(nic.Bridge, hostIf.Name); err != nil { + if err := cli.AddPort(nic.Bridge, hostIf.Name, nic.Vlan); err != nil { return nil, nil, errors.Wrapf(err, "Add port to OVS: %s -> %s", hostIf.Name, nic.Bridge) } if nic.Vpc != nil && nic.Vpc.Provider == POD_NIC_PROVIDER_OVN {