diff options
-rw-r--r-- | gobgp/cmd/global.go | 51 |
1 files changed, 16 insertions, 35 deletions
diff --git a/gobgp/cmd/global.go b/gobgp/cmd/global.go index 77e9c81c..317ff0ee 100644 --- a/gobgp/cmd/global.go +++ b/gobgp/cmd/global.go @@ -542,48 +542,29 @@ func ParsePath(rf bgp.RouteFamily, args []string) (*api.Path, error) { Pattrs: make([][]byte, 0), } - args, origin, err := extractOrigin(args) - if err != nil { - return nil, err - } - attrs = append(attrs, origin) - - args, nexthop, err := extractNexthop(rf, args) - if err != nil { - return nil, err - } - - args, med, err := extractMed(args) - if err != nil { - return nil, err - } - if med != nil { - attrs = append(attrs, med) - } - - args, localPref, err := extractLocalPref(args) - if err != nil { - return nil, err - } - if localPref != nil { - attrs = append(attrs, localPref) + fns := []func([]string) ([]string, bgp.PathAttributeInterface, error){ + extractOrigin, + extractMed, + extractLocalPref, + extractCommunity, + extractAigp, } - args, community, err := extractCommunity(args) - if err != nil { - return nil, err - } - if community != nil { - attrs = append(attrs, community) + for _, fn := range fns { + var a bgp.PathAttributeInterface + args, a, err = fn(args) + if err != nil { + return nil, err + } + if a != nil { + attrs = append(attrs, a) + } } - args, aigp, err := extractAigp(args) + args, nexthop, err := extractNexthop(rf, args) if err != nil { return nil, err } - if aigp != nil { - attrs = append(attrs, aigp) - } switch rf { case bgp.RF_IPv4_UC, bgp.RF_IPv6_UC: |