Skip to content

Commit

Permalink
Merge pull request #91 from yaoice/ipvlan_l2_mode
Browse files Browse the repository at this point in the history
update k8s-vlan
  • Loading branch information
chenchun committed Sep 15, 2020
2 parents 8f182e4 + d4d153c commit e31c74b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
8 changes: 7 additions & 1 deletion cni/k8s-vlan/k8s_vlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,15 @@ func setupIPVlan(result *t020.Result, vlanId uint16, args *skel.CmdArgs) error {
if err := d.MaybeCreateVlanDevice(vlanId); err != nil {
return err
}
if err := utils.IPVlanConnectsHostWithContainer(result, args, d.DeviceIndex); err != nil {

if err := utils.IPVlanConnectsHostWithContainer(result, args, d.DeviceIndex, d.GetIPVlanMode()); err != nil {
return err
}

if d.IpVlanMode == "l3" || d.IpVlanMode == "l3s" {
_ = utils.SendGratuitousARP(d.Device, result.IP4.IP.IP.String(), "", d.GratuitousArpRequest)
return nil
}
_ = utils.SendGratuitousARP(args.IfName, result.IP4.IP.IP.String(), args.Netns, d.GratuitousArpRequest)
return nil
}
Expand Down
8 changes: 8 additions & 0 deletions doc/supported-cnis.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type NetConf struct {
Device string `json:"device"`
// Supports macvlan, bridge or pure(which avoid create unnecessary bridge), default bridge
Switch string `json:"switch"`
// Supports ipvlan mode l2, l3, l3s, default is l3
IpVlanMode string `json:"ipvlan_mode"`
// Disable creating default bridge
DisableDefaultBridge *bool `json:"disable_default_bridge"`
// bridge name if no vlan, default docker
Expand All @@ -42,11 +44,17 @@ type NetConf struct {
BridgeNamePrefix string `json:"bridge_name_prefix"`
// vlan name prefix for all vlan device, default vlan
VlanNamePrefix string `json:"vlan_name_prefix"`
// Send arp request
GratuitousArpRequest bool `json:"gratuitous_arp_request"`
}
```

If you want to create vlan device youself, you can set `device=$vlanDev`, otherwise setting it to your network card name, Vlan CNI will create vlan devices.

If you want to use ipvlan when `Switch=ipvlan`, you can also set ipvlan mode, option values like`l2, l3, l3s`, default ipvlan mode is l3.

Note: If you use ipvlan in `l3` or `l3s` mode, you may have to set `gratuitous_arp_request: true`

## SRIOV CNI

SRIOV CNI is a underlay network plugin which makes use of SR-IOV on Ethernet Server Adapters. It allocates a VF device and puts it into
Expand Down
25 changes: 22 additions & 3 deletions pkg/network/vlan/vlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ import (
)

const (
VlanPrefix = "vlan"
BridgePrefix = "docker"
DefaultBridge = "docker"
VlanPrefix = "vlan"
BridgePrefix = "docker"
DefaultBridge = "docker"
DefaultIPVlanMode = "l3"
)

type VlanDriver struct {
Expand All @@ -52,6 +53,8 @@ type NetConf struct {
Device string `json:"device"`
// Supports macvlan, bridge or pure(which avoid create unnecessary bridge), default bridge
Switch string `json:"switch"`
// Supports ipvlan mode l2, l3, l3s, default is l3
IpVlanMode string `json:"ipvlan_mode"`

// Disable creating default bridge
DisableDefaultBridge *bool `json:"disable_default_bridge"`
Expand Down Expand Up @@ -79,6 +82,9 @@ func (d *VlanDriver) LoadConf(bytes []byte) (*NetConf, error) {
if conf.VlanNamePrefix == "" {
conf.VlanNamePrefix = VlanPrefix
}
if conf.IpVlanMode == "" {
conf.IpVlanMode = DefaultIPVlanMode
}
d.NetConf = conf
return conf, nil
}
Expand Down Expand Up @@ -368,3 +374,16 @@ func (d *VlanDriver) IPVlanMode() bool {
func (d *VlanDriver) PureMode() bool {
return d.Switch == "pure"
}

func (d *VlanDriver) GetIPVlanMode() netlink.IPVlanMode {
switch d.IpVlanMode {
case "l2":
return netlink.IPVLAN_MODE_L2
case "l3":
return netlink.IPVLAN_MODE_L3
case "l3s":
return netlink.IPVLAN_MODE_L3S
default:
return netlink.IPVLAN_MODE_L3
}
}
4 changes: 2 additions & 2 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,10 @@ func MacVlanConnectsHostWithContainer(result *t020.Result, args *skel.CmdArgs, p
}

// IPVlanConnectsHostWithContainer creates ipvlan device onto parent device and connects container with host
func IPVlanConnectsHostWithContainer(result *t020.Result, args *skel.CmdArgs, parent int) error {
func IPVlanConnectsHostWithContainer(result *t020.Result, args *skel.CmdArgs, parent int, mode netlink.IPVlanMode) error {
var err error
ipVlan := &netlink.IPVlan{
Mode: netlink.IPVLAN_MODE_L3,
Mode: mode,
LinkAttrs: netlink.LinkAttrs{
Name: HostMacVlanName(args.ContainerID),
MTU: 1500,
Expand Down

0 comments on commit e31c74b

Please sign in to comment.