diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-03-05 22:48:49 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-03-05 22:48:49 +0900 |
commit | af7f4d5531f2116e01f36b99611ffdbcc19a8cdd (patch) | |
tree | 5167ba21a7157da964c35d491287459aef214eb3 /packet/bgp.go | |
parent | 216e376c34ae38acaff3d01c22ce2eb2f1bc4a08 (diff) |
config: validate route family configuraiton
If not specified, use the same AFI with peer IP address as a default.
To avoid circular import, define BGP_ORIGIN_ATTR_TYPE consts bgp.go
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'packet/bgp.go')
-rw-r--r-- | packet/bgp.go | 66 |
1 files changed, 55 insertions, 11 deletions
diff --git a/packet/bgp.go b/packet/bgp.go index cc2166c2..debce3e5 100644 --- a/packet/bgp.go +++ b/packet/bgp.go @@ -25,22 +25,30 @@ import ( "reflect" ) -// move somewhere else - const ( - AFI_IP = 1 - AFI_IP6 = 2 + AFI_IP = 1 + AFI_IP6 = 2 + AFI_L2VPN = 25 ) const ( SAFI_UNICAST = 1 SAFI_MULTICAST = 2 SAFI_MPLS_LABEL = 4 + SAFI_VPLS = 65 + SAFI_EVPN = 70 SAFI_MPLS_VPN = 128 + SAFI_MPLS_VPN_MULTICAST = 129 SAFI_ROUTE_TARGET_CONSTRTAINS = 132 ) const ( + BGP_ORIGIN_ATTR_TYPE_IGP = 0 + BGP_ORIGIN_ATTR_TYPE_EGP = 1 + BGP_ORIGIN_ATTR_TYPE_INCOMPLETE = 2 +) + +const ( _ = iota BGP_MSG_OPEN BGP_MSG_UPDATE @@ -954,15 +962,51 @@ func rfshift(afi uint16, safi uint8) RouteFamily { type RouteFamily int const ( - RF_IPv4_UC RouteFamily = AFI_IP<<16 | SAFI_UNICAST - RF_IPv6_UC RouteFamily = AFI_IP6<<16 | SAFI_UNICAST - RF_IPv4_VPN RouteFamily = AFI_IP<<16 | SAFI_MPLS_VPN - RF_IPv6_VPN RouteFamily = AFI_IP6<<16 | SAFI_MPLS_VPN - RF_IPv4_MPLS RouteFamily = AFI_IP<<16 | SAFI_MPLS_LABEL - RF_IPv6_MPLS RouteFamily = AFI_IP6<<16 | SAFI_MPLS_LABEL - RF_RTC_UC RouteFamily = AFI_IP<<16 | SAFI_ROUTE_TARGET_CONSTRTAINS + RF_IPv4_UC RouteFamily = AFI_IP<<16 | SAFI_UNICAST + RF_IPv6_UC RouteFamily = AFI_IP6<<16 | SAFI_UNICAST + RF_IPv4_MC RouteFamily = AFI_IP<<16 | SAFI_MULTICAST + RF_IPv6_MC RouteFamily = AFI_IP6<<16 | SAFI_MULTICAST + RF_IPv4_VPN RouteFamily = AFI_IP<<16 | SAFI_MPLS_VPN + RF_IPv6_VPN RouteFamily = AFI_IP6<<16 | SAFI_MPLS_VPN + RF_IPv4_VPN_MC RouteFamily = AFI_IP<<16 | SAFI_MPLS_VPN_MULTICAST + RF_IPv6_VPN_MC RouteFamily = AFI_IP6<<16 | SAFI_MPLS_VPN_MULTICAST + RF_IPv4_MPLS RouteFamily = AFI_IP<<16 | SAFI_MPLS_LABEL + RF_IPv6_MPLS RouteFamily = AFI_IP6<<16 | SAFI_MPLS_LABEL + RF_VPLS RouteFamily = AFI_L2VPN<<16 | SAFI_VPLS + RF_EVPN RouteFamily = AFI_L2VPN<<16 | SAFI_EVPN + RF_RTC_UC RouteFamily = AFI_IP<<16 | SAFI_ROUTE_TARGET_CONSTRTAINS ) +func GetRouteFamily(name string) (RouteFamily, error) { + switch name { + case "ipv4-unicast": + return RF_IPv4_UC, nil + case "ipv6-unicast": + return RF_IPv6_UC, nil + case "ipv4-multicast": + return RF_IPv4_MC, nil + case "ipv6-multicast": + return RF_IPv6_MC, nil + case "ipv4-labelled-unicast": + return RF_IPv4_MPLS, nil + case "ipv6-labelled-unicast": + return RF_IPv6_MPLS, nil + case "l3vpn-ipv4-unicast": + return RF_IPv4_VPN, nil + case "l3vpn-ipv6-unicast": + return RF_IPv6_VPN, nil + case "l3vpn-ipv4-multicast": + return RF_IPv4_VPN_MC, nil + case "l3vpn-ipv6-multicast": + return RF_IPv6_VPN_MC, nil + case "l2vpn-vpls": + return RF_VPLS, nil + case "l2vpn-evpn": + return RF_EVPN, nil + } + return RouteFamily(0), fmt.Errorf("%s isn't a valid route family name", name) +} + func routeFamilyPrefix(afi uint16, safi uint8) (prefix AddrPrefixInterface, err error) { switch rfshift(afi, safi) { case RF_IPv4_UC: |