summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2018-06-05 14:51:43 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-06-05 20:07:09 +0900
commitb285fb2475ecf0543a1c3cbfbff1b195d12678d5 (patch)
tree0b99e254e85a34bb5b742b72c2152db98ae45281
parentc78328019756dca6912b69d7ecfcb850f727513f (diff)
config: Accept CLUSTER_ID as an integer value
Currently, only IPv4 address is acceptable for the CLUSTER_ID setting, this patch enables to specify the CLUSTER_ID as a 32-bit unsigned integer. With this expansion, "Config.RouteReflectorClusterId" stores the raw configured value for the CLUSTER_ID and "State.RouteReflectorClusterId" stores the value used for construct the CLUSTER_LIST attribute. Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
-rw-r--r--api/grpc_server.go2
-rw-r--r--config/default.go17
-rw-r--r--table/destination.go4
-rw-r--r--table/path.go6
4 files changed, 20 insertions, 9 deletions
diff --git a/api/grpc_server.go b/api/grpc_server.go
index 8284a8be..b10eef79 100644
--- a/api/grpc_server.go
+++ b/api/grpc_server.go
@@ -323,7 +323,7 @@ func NewPeerFromConfigStruct(pconf *config.Neighbor) *Peer {
},
RouteReflector: &RouteReflector{
RouteReflectorClient: pconf.RouteReflector.Config.RouteReflectorClient,
- RouteReflectorClusterId: string(pconf.RouteReflector.Config.RouteReflectorClusterId),
+ RouteReflectorClusterId: string(pconf.RouteReflector.State.RouteReflectorClusterId),
},
RouteServer: &RouteServer{
RouteServerClient: pconf.RouteServer.Config.RouteServerClient,
diff --git a/config/default.go b/config/default.go
index f5bf809e..3529c4e4 100644
--- a/config/default.go
+++ b/config/default.go
@@ -1,10 +1,12 @@
package config
import (
+ "encoding/binary"
"fmt"
"math"
"net"
"reflect"
+ "strconv"
"github.com/spf13/viper"
@@ -240,9 +242,18 @@ func setDefaultNeighborConfigValuesWithViper(v *viper.Viper, n *Neighbor, g *Glo
if n.RouteReflector.Config.RouteReflectorClient {
if n.RouteReflector.Config.RouteReflectorClusterId == "" {
- n.RouteReflector.Config.RouteReflectorClusterId = RrClusterIdType(g.Config.RouterId)
- } else if id := net.ParseIP(string(n.RouteReflector.Config.RouteReflectorClusterId)).To4(); id == nil {
- return fmt.Errorf("route-reflector-cluster-id should be specified in IPv4 address format")
+ n.RouteReflector.State.RouteReflectorClusterId = RrClusterIdType(g.Config.RouterId)
+ } else {
+ id := string(n.RouteReflector.Config.RouteReflectorClusterId)
+ if ip := net.ParseIP(id).To4(); ip != nil {
+ n.RouteReflector.State.RouteReflectorClusterId = n.RouteReflector.Config.RouteReflectorClusterId
+ } else if num, err := strconv.ParseUint(id, 10, 32); err == nil {
+ ip = make(net.IP, 4)
+ binary.BigEndian.PutUint32(ip, uint32(num))
+ n.RouteReflector.State.RouteReflectorClusterId = RrClusterIdType(ip.String())
+ } else {
+ return fmt.Errorf("route-reflector-cluster-id should be specified as IPv4 address or 32-bit unsigned integer")
+ }
}
}
diff --git a/table/destination.go b/table/destination.go
index a37d2114..bf375cd4 100644
--- a/table/destination.go
+++ b/table/destination.go
@@ -150,7 +150,7 @@ func (i *PeerInfo) String() string {
}
func NewPeerInfo(g *config.Global, p *config.Neighbor) *PeerInfo {
- id := net.ParseIP(string(p.RouteReflector.Config.RouteReflectorClusterId)).To4()
+ clusterID := net.ParseIP(string(p.RouteReflector.State.RouteReflectorClusterId)).To4()
// exclude zone info
naddr, _ := net.ResolveIPAddr("ip", p.State.NeighborAddress)
return &PeerInfo{
@@ -159,7 +159,7 @@ func NewPeerInfo(g *config.Global, p *config.Neighbor) *PeerInfo {
LocalID: net.ParseIP(g.Config.RouterId).To4(),
RouteReflectorClient: p.RouteReflector.Config.RouteReflectorClient,
Address: naddr.IP,
- RouteReflectorClusterID: id,
+ RouteReflectorClusterID: clusterID,
MultihopTtl: p.EbgpMultihop.Config.MultihopTtl,
Confederation: p.IsConfederationMember(g),
}
diff --git a/table/path.go b/table/path.go
index 62f277d4..e22f5780 100644
--- a/table/path.go
+++ b/table/path.go
@@ -289,16 +289,16 @@ func UpdatePathAttrs(global *config.Global, peer *config.Neighbor, info *PeerInf
}
// When an RR reflects a route, it MUST prepend the local CLUSTER_ID to the CLUSTER_LIST.
// If the CLUSTER_LIST is empty, it MUST create a new one.
- id := string(peer.RouteReflector.Config.RouteReflectorClusterId)
+ clusterID := string(peer.RouteReflector.State.RouteReflectorClusterId)
if p := path.getPathAttr(bgp.BGP_ATTR_TYPE_CLUSTER_LIST); p == nil {
- path.setPathAttr(bgp.NewPathAttributeClusterList([]string{id}))
+ path.setPathAttr(bgp.NewPathAttributeClusterList([]string{clusterID}))
} else {
clusterList := p.(*bgp.PathAttributeClusterList)
newClusterList := make([]string, 0, len(clusterList.Value))
for _, ip := range clusterList.Value {
newClusterList = append(newClusterList, ip.String())
}
- path.setPathAttr(bgp.NewPathAttributeClusterList(append([]string{id}, newClusterList...)))
+ path.setPathAttr(bgp.NewPathAttributeClusterList(append([]string{clusterID}, newClusterList...)))
}
}