summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2017-11-22 13:40:32 +0900
committerIWASE Yusuke <iwase.yusuke0@gmail.com>2017-11-24 12:55:31 +0900
commit8fd741dea151f18f1a5fdb00e830489f459105c3 (patch)
treefad3c7c9f54b9017fe8cd0f74f6b667ebc95c707
parentd2c16ca1b62c92951de936242163cb648f0c3025 (diff)
cli: Return error when no RD for VPN FlowSpec
Currently, if Route Distinguisher is not specified for the VPN FlowSpec types via "gobgp" command, the message as following will be displayed: $ gobgp global rib -a l2vpn-flowspec add match vid 100 then accept rpc error: code = Unknown desc = attribute type length is short But this message does not describe which argument should be specified. This patch fixes to output the message about lack of "rd <rd>". Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
-rw-r--r--gobgp/cmd/global.go30
1 files changed, 17 insertions, 13 deletions
diff --git a/gobgp/cmd/global.go b/gobgp/cmd/global.go
index d1aa38a9..9b9e4fdd 100644
--- a/gobgp/cmd/global.go
+++ b/gobgp/cmd/global.go
@@ -323,26 +323,37 @@ func ParseExtendedCommunities(args []string) ([]bgp.ExtendedCommunityInterface,
return exts, nil
}
-func ParseFlowSpecArgs(rf bgp.RouteFamily, args []string, rd bgp.RouteDistinguisherInterface) (bgp.AddrPrefixInterface, []string, error) {
+func ParseFlowSpecArgs(rf bgp.RouteFamily, args []string) (bgp.AddrPrefixInterface, []string, error) {
// Format:
- // match <rule>... [then <action>...] [rt <rt>...]
+ // match <rule>... [then <action>...] [rd <rd>] [rt <rt>...]
req := 3 // match <key1> <arg1> [<key2> <arg2>...]
if len(args) < req {
return nil, nil, fmt.Errorf("%d args required at least, but got %d", req, len(args))
}
- m := extractReserved(args, []string{"match", "then", "rt"})
+ m := extractReserved(args, []string{"match", "then", "rd", "rt"})
if len(m["match"]) == 0 {
return nil, nil, fmt.Errorf("specify filtering rules with keyword 'match'")
}
+ var rd bgp.RouteDistinguisherInterface
extcomms := m["then"]
switch rf {
case bgp.RF_FS_IPv4_VPN, bgp.RF_FS_IPv6_VPN, bgp.RF_FS_L2_VPN:
+ if len(m["rd"]) == 0 {
+ return nil, nil, fmt.Errorf("specify rd")
+ }
+ var err error
+ if rd, err = bgp.ParseRouteDistinguisher(m["rd"][0]); err != nil {
+ return nil, nil, fmt.Errorf("invalid rd: %s", m["rd"][0])
+ }
if len(m["rt"]) > 0 {
extcomms = append(extcomms, "rt")
extcomms = append(extcomms, m["rt"]...)
}
default:
+ if len(m["rd"]) > 0 {
+ return nil, nil, fmt.Errorf("cannot specify rd for %s", rf.String())
+ }
if len(m["rt"]) > 0 {
return nil, nil, fmt.Errorf("cannot specify rt for %s", rf.String())
}
@@ -990,7 +1001,6 @@ func extractRouteDistinguisher(args []string) ([]string, bgp.RouteDistinguisherI
func ParsePath(rf bgp.RouteFamily, args []string) (*table.Path, error) {
var nlri bgp.AddrPrefixInterface
- var rd bgp.RouteDistinguisherInterface
var extcomms []string
var err error
attrs := table.PathAttrs(make([]bgp.PathAttributeInterface, 0, 1))
@@ -1068,7 +1078,7 @@ func ParsePath(rf bgp.RouteFamily, args []string) (*table.Path, error) {
}
mpls := bgp.NewMPLSLabelStack(uint32(label))
- rd, err = bgp.ParseRouteDistinguisher(args[4])
+ rd, err := bgp.ParseRouteDistinguisher(args[4])
if err != nil {
return nil, err
}
@@ -1114,14 +1124,8 @@ func ParsePath(rf bgp.RouteFamily, args []string) (*table.Path, error) {
}
case bgp.RF_EVPN:
nlri, extcomms, err = ParseEvpnArgs(args)
- case bgp.RF_FS_IPv4_VPN, bgp.RF_FS_IPv6_VPN, bgp.RF_FS_L2_VPN:
- args, rd, err = extractRouteDistinguisher(args)
- if err != nil {
- return nil, err
- }
- fallthrough
- case bgp.RF_FS_IPv4_UC, bgp.RF_FS_IPv6_UC:
- nlri, extcomms, err = ParseFlowSpecArgs(rf, args, rd)
+ case bgp.RF_FS_IPv4_UC, bgp.RF_FS_IPv4_VPN, bgp.RF_FS_IPv6_UC, bgp.RF_FS_IPv6_VPN, bgp.RF_FS_L2_VPN:
+ nlri, extcomms, err = ParseFlowSpecArgs(rf, args)
case bgp.RF_OPAQUE:
m := extractReserved(args, []string{"key", "value"})
if len(m["key"]) != 1 {