summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/grpc_server.go4
-rw-r--r--server/server.go38
2 files changed, 42 insertions, 0 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go
index 25af6dc7..1e81e3ce 100644
--- a/server/grpc_server.go
+++ b/server/grpc_server.go
@@ -89,6 +89,10 @@ func convertAf2Rf(af *api.AddressFamily) (bgp.RouteFamily, error) {
return bgp.RF_IPv4_UC, nil
} else if af.Equal(api.AF_IPV6_UC) {
return bgp.RF_IPv6_UC, nil
+ } else if af.Equal(api.AF_IPV4_VPN) {
+ return bgp.RF_IPv4_VPN, nil
+ } else if af.Equal(api.AF_IPV6_VPN) {
+ return bgp.RF_IPv6_VPN, nil
} else if af.Equal(api.AF_EVPN) {
return bgp.RF_EVPN, nil
} else if af.Equal(api.AF_ENCAP) {
diff --git a/server/server.go b/server/server.go
index 57f7c7ee..a3d512a9 100644
--- a/server/server.go
+++ b/server/server.go
@@ -712,6 +712,44 @@ func handleGlobalRibRequest(grpcReq *GrpcRequest, peerInfo *table.PeerInfo) []*t
pattr = append(pattr, bgp.NewPathAttributeMpReachNLRI("::", []bgp.AddrPrefixInterface{nlri}))
+ case bgp.RF_IPv4_VPN, bgp.RF_IPv6_VPN:
+ var rd bgp.RouteDistinguisherInterface
+ switch path.Nlri.VpnNlri.Rd.Type {
+ case api.ROUTE_DISTINGUISHER_TYPE_TWO_OCTET_AS:
+ a, err := strconv.Atoi(path.Nlri.VpnNlri.Rd.Admin)
+ if err != nil {
+ result.ResponseErr = fmt.Errorf("Invalid admin value: %s", path.Nlri.VpnNlri.Rd.Admin)
+ goto ERR
+ }
+ rd = bgp.NewRouteDistinguisherTwoOctetAS(uint16(a), path.Nlri.VpnNlri.Rd.Assigned)
+ case api.ROUTE_DISTINGUISHER_TYPE_IP4:
+ ip := net.ParseIP(path.Nlri.VpnNlri.Rd.Admin)
+ if ip.To4() == nil {
+ result.ResponseErr = fmt.Errorf("Invalid ipv4 prefix: %s", path.Nlri.VpnNlri.Rd.Admin)
+ goto ERR
+ }
+ assigned := uint16(path.Nlri.VpnNlri.Rd.Assigned)
+ rd = bgp.NewRouteDistinguisherIPAddressAS(path.Nlri.VpnNlri.Rd.Admin, assigned)
+ case api.ROUTE_DISTINGUISHER_TYPE_FOUR_OCTET_AS:
+ a, err := strconv.Atoi(path.Nlri.VpnNlri.Rd.Admin)
+ if err != nil {
+ result.ResponseErr = fmt.Errorf("Invalid admin value: %s", path.Nlri.VpnNlri.Rd.Admin)
+ goto ERR
+ }
+ admin := uint32(a)
+ assigned := uint16(path.Nlri.VpnNlri.Rd.Assigned)
+ rd = bgp.NewRouteDistinguisherFourOctetAS(admin, assigned)
+ }
+
+ mpls := bgp.NewMPLSLabelStack(0)
+ if rf == bgp.RF_IPv4_VPN {
+ nlri = bgp.NewLabeledVPNIPAddrPrefix(uint8(path.Nlri.VpnNlri.IpAddrLen), path.Nlri.VpnNlri.IpAddr, *mpls, rd)
+ pattr = append(pattr, bgp.NewPathAttributeMpReachNLRI("0.0.0.0", []bgp.AddrPrefixInterface{nlri}))
+ } else {
+ nlri = bgp.NewLabeledVPNIPv6AddrPrefix(uint8(path.Nlri.VpnNlri.IpAddrLen), path.Nlri.VpnNlri.IpAddr, *mpls, rd)
+ pattr = append(pattr, bgp.NewPathAttributeMpReachNLRI("::", []bgp.AddrPrefixInterface{nlri}))
+ }
+
case bgp.RF_EVPN:
if peerInfo.AS > (1<<16 - 1) {
result.ResponseErr = fmt.Errorf("evpn path can't be created in 4byte-AS env")