summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--api/grpc_server.go4
-rw-r--r--api/util.go19
-rw-r--r--gobgp/cmd/neighbor.go17
3 files changed, 34 insertions, 6 deletions
diff --git a/api/grpc_server.go b/api/grpc_server.go
index d1b82aeb..161bc826 100644
--- a/api/grpc_server.go
+++ b/api/grpc_server.go
@@ -100,7 +100,7 @@ func NewMpGracefulRestartFromConfigStruct(c *config.MpGracefulRestart) *MpGracef
func NewAfiSafiConfigFromConfigStruct(c *config.AfiSafi) *AfiSafiConfig {
return &AfiSafiConfig{
- Family: uint32(c.State.Family),
+ Family: extractFamilyFromConfigAfiSafi(c),
Enabled: c.Config.Enabled,
}
}
@@ -223,7 +223,7 @@ func NewPeerFromConfigStruct(pconf *config.Neighbor) *Peer {
prefixLimits := make([]*PrefixLimit, 0, len(pconf.AfiSafis))
afiSafis := make([]*AfiSafi, 0, len(pconf.AfiSafis))
for _, f := range pconf.AfiSafis {
- families = append(families, uint32(f.State.Family))
+ families = append(families, extractFamilyFromConfigAfiSafi(&f))
if prefixLimit := NewPrefixLimitFromConfigStruct(&f); prefixLimit != nil {
prefixLimits = append(prefixLimits, prefixLimit)
}
diff --git a/api/util.go b/api/util.go
index ce7a1d02..53a94ed3 100644
--- a/api/util.go
+++ b/api/util.go
@@ -160,3 +160,22 @@ func NewROAListFromApiStructList(l []*Roa) []*table.ROA {
}
return roas
}
+
+func extractFamilyFromConfigAfiSafi(c *config.AfiSafi) uint32 {
+ if c == nil {
+ return 0
+ }
+ // If address family value is already stored in AfiSafiState structure,
+ // we prefer to use this value.
+ if c.State.Family != 0 {
+ return uint32(c.State.Family)
+ }
+ // In case that Neighbor structure came from CLI or gRPC, address family
+ // value in AfiSafiState structure can be omitted.
+ // Here extracts value from AfiSafiName field in AfiSafiConfig structure.
+ if rf, err := bgp.GetRouteFamily(string(c.Config.AfiSafiName)); err == nil {
+ return uint32(rf)
+ }
+ // Ignores invalid address family name
+ return 0
+}
diff --git a/gobgp/cmd/neighbor.go b/gobgp/cmd/neighbor.go
index 45178801..8e18cfa3 100644
--- a/gobgp/cmd/neighbor.go
+++ b/gobgp/cmd/neighbor.go
@@ -983,13 +983,13 @@ func modNeighborPolicy(remoteIP, policyType, cmdType string, args []string) erro
}
func modNeighbor(cmdType string, args []string) error {
- m := extractReserved(args, []string{"interface", "as", "vrf", "route-reflector-client", "route-server-client", "allow-own-as", "remove-private-as", "replace-peer-as"})
- usage := fmt.Sprintf("usage: gobgp neighbor %s [<neighbor-address>| interface <neighbor-interface>]", cmdType)
+ m := extractReserved(args, []string{"interface", "as", "family", "vrf", "route-reflector-client", "route-server-client", "allow-own-as", "remove-private-as", "replace-peer-as"})
+ usage := fmt.Sprintf("usage: gobgp neighbor %s [ <neighbor-address> | interface <neighbor-interface> ]", cmdType)
if cmdType == CMD_ADD {
- usage += " as <VALUE> [ vrf <vrf-name> | route-reflector-client [<cluster-id>] | route-server-client | allow-own-as <num> | remove-private-as (all|replace) | replace-peer-as ]"
+ usage += " as <VALUE> [ family <address-families-list> | vrf <vrf-name> | route-reflector-client [<cluster-id>] | route-server-client | allow-own-as <num> | remove-private-as (all|replace) | replace-peer-as ]"
}
- if (len(m[""]) != 1 && len(m["interface"]) != 1) || len(m["as"]) > 1 || len(m["vrf"]) > 1 || len(m["route-reflector-client"]) > 1 || len(m["allow-own-as"]) > 1 || len(m["remove-private-as"]) > 1 {
+ if (len(m[""]) != 1 && len(m["interface"]) != 1) || len(m["as"]) > 1 || len(m["family"]) > 1 || len(m["vrf"]) > 1 || len(m["route-reflector-client"]) > 1 || len(m["allow-own-as"]) > 1 || len(m["remove-private-as"]) > 1 {
return fmt.Errorf("%s", usage)
}
unnumbered := len(m["interface"]) > 0
@@ -1011,6 +1011,15 @@ func modNeighbor(cmdType string, args []string) error {
peer.Config.NeighborAddress = m[""][0]
peer.State.NeighborAddress = m[""][0]
}
+ if len(m["family"]) == 1 {
+ for _, family := range strings.Split(m["family"][0], ",") {
+ afiSafiName := config.AfiSafiType(family)
+ if afiSafiName.ToInt() == -1 {
+ return nil, fmt.Errorf("invalid family value: %s", family)
+ }
+ peer.AfiSafis = append(peer.AfiSafis, config.AfiSafi{Config: config.AfiSafiConfig{AfiSafiName: afiSafiName}})
+ }
+ }
if len(m["vrf"]) == 1 {
peer.Config.Vrf = m["vrf"][0]
}