Skip to content

Commit

Permalink
fix(vrf): create bridge and vxlan only if VNI value is not empty
Browse files Browse the repository at this point in the history
Fixes #105

Signed-off-by: Boris Glimcher <Boris.Glimcher@emc.com>
  • Loading branch information
glimchb committed Aug 9, 2023
1 parent 54491ab commit 9746131
Showing 1 changed file with 49 additions and 46 deletions.
95 changes: 49 additions & 46 deletions pkg/evpn/vrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,52 +81,55 @@ func (s *Server) CreateVrf(_ context.Context, in *pb.CreateVrfRequest) (*pb.Vrf,
// TODO: Add low-prio default route. Otherwise a miss leads to lookup in the next higher table
// Example: ip route add throw default table <routing-table-number> proto evpn-gw-br metric 9999

// Example: ip link add br100 type bridge
bridgeName := fmt.Sprintf("br%d", in.Vrf.Spec.Vni)
bridge := &netlink.Bridge{LinkAttrs: netlink.LinkAttrs{Name: bridgeName}}
if err := netlink.LinkAdd(bridge); err != nil {
fmt.Printf("Failed to create Bridge link: %v", err)
return nil, err
}
// Example: ip link set br100 master blue addrgenmode none
if err := netlink.LinkSetMaster(bridge, vrf); err != nil {
fmt.Printf("Failed to add Bridge to VRF: %v", err)
return nil, err
}
// Example: ip link set br100 addr aa:bb:cc:00:00:02
mac, err := generateRandMAC()
if err != nil {
fmt.Printf("Failed to generate random MAC: %v", err)
return nil, err
}
if err := netlink.LinkSetHardwareAddr(bridge, mac); err != nil {
fmt.Printf("Failed to set MAC on Bridge link: %v", err)
return nil, err
}
// Example: ip link set br100 up
if err := netlink.LinkSetUp(bridge); err != nil {
fmt.Printf("Failed to up Bridge link: %v", err)
return nil, err
}
// Example: ip link add vni100 type vxlan local 10.0.0.4 dstport 4789 id 100 nolearning
vxlanName := fmt.Sprintf("vni%d", in.Vrf.Spec.Vni)
myip := make(net.IP, 4)
binary.BigEndian.PutUint32(myip, in.Vrf.Spec.VtepIpPrefix.Addr.GetV4Addr())
// TODO: take Port from proto instead of hard-coded
vxlan := &netlink.Vxlan{LinkAttrs: netlink.LinkAttrs{Name: vxlanName}, VxlanId: int(in.Vrf.Spec.Vni), Port: 4789, Learning: false, SrcAddr: myip}
if err := netlink.LinkAdd(vxlan); err != nil {
fmt.Printf("Failed to create Vxlan link: %v", err)
return nil, err
}
// Example: ip link set vni100 master br100 addrgenmode none
if err := netlink.LinkSetMaster(vxlan, bridge); err != nil {
fmt.Printf("Failed to add Vxlan to bridge: %v", err)
return nil, err
}
// Example: ip link set vni100 up
if err := netlink.LinkSetUp(vxlan); err != nil {
fmt.Printf("Failed to up Vxlan link: %v", err)
return nil, err
// create bridge and vxlan only if VNI value is not empty
if in.Vrf.Spec.Vni > 0 {
// Example: ip link add br100 type bridge
bridgeName := fmt.Sprintf("br%d", in.Vrf.Spec.Vni)
bridge := &netlink.Bridge{LinkAttrs: netlink.LinkAttrs{Name: bridgeName}}
if err := netlink.LinkAdd(bridge); err != nil {
fmt.Printf("Failed to create Bridge link: %v", err)
return nil, err
}
// Example: ip link set br100 master blue addrgenmode none
if err := netlink.LinkSetMaster(bridge, vrf); err != nil {
fmt.Printf("Failed to add Bridge to VRF: %v", err)
return nil, err
}
// Example: ip link set br100 addr aa:bb:cc:00:00:02
mac, err := generateRandMAC()
if err != nil {
fmt.Printf("Failed to generate random MAC: %v", err)
return nil, err
}
if err := netlink.LinkSetHardwareAddr(bridge, mac); err != nil {
fmt.Printf("Failed to set MAC on Bridge link: %v", err)
return nil, err
}
// Example: ip link set br100 up
if err := netlink.LinkSetUp(bridge); err != nil {
fmt.Printf("Failed to up Bridge link: %v", err)
return nil, err
}
// Example: ip link add vni100 type vxlan local 10.0.0.4 dstport 4789 id 100 nolearning
vxlanName := fmt.Sprintf("vni%d", in.Vrf.Spec.Vni)
myip := make(net.IP, 4)
binary.BigEndian.PutUint32(myip, in.Vrf.Spec.VtepIpPrefix.Addr.GetV4Addr())
// TODO: take Port from proto instead of hard-coded
vxlan := &netlink.Vxlan{LinkAttrs: netlink.LinkAttrs{Name: vxlanName}, VxlanId: int(in.Vrf.Spec.Vni), Port: 4789, Learning: false, SrcAddr: myip}
if err := netlink.LinkAdd(vxlan); err != nil {
fmt.Printf("Failed to create Vxlan link: %v", err)
return nil, err
}
// Example: ip link set vni100 master br100 addrgenmode none
if err := netlink.LinkSetMaster(vxlan, bridge); err != nil {
fmt.Printf("Failed to add Vxlan to bridge: %v", err)
return nil, err
}
// Example: ip link set vni100 up
if err := netlink.LinkSetUp(vxlan); err != nil {
fmt.Printf("Failed to up Vxlan link: %v", err)
return nil, err
}
}
response := proto.Clone(in.Vrf).(*pb.Vrf)
response.Status = &pb.VrfStatus{LocalAs: 4, RoutingTable: tableID, Rmac: mac}
Expand Down

0 comments on commit 9746131

Please sign in to comment.