Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions pkg/cni-plugin/plugin/ovs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions pkg/cni-plugin/plugin/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
30 changes: 29 additions & 1 deletion pkg/cni-plugin/plugin/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := &current.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
}

Expand Down Expand Up @@ -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 {
Expand Down
Loading