diff options
-rw-r--r-- | config/default.go | 21 | ||||
-rw-r--r-- | config/serve.go | 7 | ||||
-rw-r--r-- | packet/bgp.go | 66 | ||||
-rw-r--r-- | packet/validate.go | 7 |
4 files changed, 82 insertions, 19 deletions
diff --git a/config/default.go b/config/default.go index df57103b..5820ef01 100644 --- a/config/default.go +++ b/config/default.go @@ -2,6 +2,7 @@ package config import ( "github.com/BurntSushi/toml" + "github.com/osrg/gobgp/packet" "strings" ) @@ -14,7 +15,7 @@ type neighbor struct { attributes map[string]bool } -func SetDefaultConfigValues(md toml.MetaData, bt *Bgp) { +func SetDefaultConfigValues(md toml.MetaData, bt *Bgp) error { neighbors := []neighbor{} nidx := 0 @@ -40,5 +41,23 @@ func SetDefaultConfigValues(md toml.MetaData, bt *Bgp) { if _, ok := n.attributes["NeighborList.Timers.IdleHoldTimeAfterReset"]; !ok { bt.NeighborList[i].Timers.IdleHoldTimeAfterReset = float64(DEFAULT_IDLE_HOLDTIME_AFTER_RESET) } + + if _, ok := n.attributes["NeighborList.AfiSafiList"]; !ok { + if bt.NeighborList[i].NeighborAddress.To4() != nil { + bt.NeighborList[i].AfiSafiList = []AfiSafi{ + AfiSafi{AfiSafiName: "ipv4-unicast"}} + } else { + bt.NeighborList[i].AfiSafiList = []AfiSafi{ + AfiSafi{AfiSafiName: "ipv6-unicast"}} + } + } else { + for _, rf := range bt.NeighborList[i].AfiSafiList { + _, err := bgp.GetRouteFamily(rf.AfiSafiName) + if err != nil { + return err + } + } + } } + return nil } diff --git a/config/serve.go b/config/serve.go index c4aabdec..6832f6b4 100644 --- a/config/serve.go +++ b/config/serve.go @@ -11,10 +11,11 @@ func ReadConfigfileServe(path string, configCh chan Bgp, reloadCh chan bool) { b := Bgp{} md, err := toml.DecodeFile(path, &b) + if err == nil { + err = SetDefaultConfigValues(md, &b) + } if err != nil { - log.Fatal("can't read config file ", path, err) - } else { - SetDefaultConfigValues(md, &b) + log.Fatal("can't read config file ", path, ", ", err) } configCh <- b 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: diff --git a/packet/validate.go b/packet/validate.go index 143aefc9..b412ee8d 100644 --- a/packet/validate.go +++ b/packet/validate.go @@ -3,7 +3,6 @@ package bgp import ( "encoding/binary" "fmt" - "github.com/osrg/gobgp/config" "net" "strconv" ) @@ -104,9 +103,9 @@ func ValidateAttribute(a PathAttributeInterface, rfs []RouteFamily) (bool, error } case *PathAttributeOrigin: v := uint8(p.Value[0]) - if v != config.BGP_ORIGIN_ATTR_TYPE_IGP && - v != config.BGP_ORIGIN_ATTR_TYPE_EGP && - v != config.BGP_ORIGIN_ATTR_TYPE_INCOMPLETE { + if v != BGP_ORIGIN_ATTR_TYPE_IGP && + v != BGP_ORIGIN_ATTR_TYPE_EGP && + v != BGP_ORIGIN_ATTR_TYPE_INCOMPLETE { data, _ := a.Serialize() eMsg := "invalid origin attribute. value : " + strconv.Itoa(int(v)) return false, NewMessageError(eCode, eSubCodeBadOrigin, data, eMsg) |