diff options
-rw-r--r-- | gobgp/cmd/global.go | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/gobgp/cmd/global.go b/gobgp/cmd/global.go index d4e4882c..80728c03 100644 --- a/gobgp/cmd/global.go +++ b/gobgp/cmd/global.go @@ -411,6 +411,21 @@ func extractLocalPref(args []string) ([]string, []byte, error) { return args, nil, nil } +func extractMed(args []string) ([]string, []byte, error) { + for idx, arg := range args { + if arg == "med" && len(args) > (idx+1) { + metric, err := strconv.Atoi(args[idx+1]) + if err != nil { + return nil, nil, err + } + args = append(args[:idx], args[idx+2:]...) + med, _ := bgp.NewPathAttributeMultiExitDisc(uint32(metric)).Serialize() + return args, med, nil + } + } + return args, nil, nil +} + func extractAigp(args []string) ([]string, []byte, error) { for idx, arg := range args { if arg == "aigp" { @@ -448,6 +463,15 @@ func ParsePath(rf bgp.RouteFamily, args []string) (*api.Path, error) { return nil, err } + var med []byte + args, med, err = extractMed(args) + if err != nil { + return nil, err + } + if med != nil { + path.Pattrs = append(path.Pattrs, med) + } + var localPref []byte args, localPref, err = extractLocalPref(args) if err != nil { @@ -581,8 +605,8 @@ func modPath(resource api.Resource, name, modtype string, args []string) error { } flags := strings.Join(ss, ", ") helpErrMap := map[bgp.RouteFamily]error{} - helpErrMap[bgp.RF_IPv4_UC] = fmt.Errorf("usage: %s rib %s <PREFIX> [nexthop <ADDRESS>] [aigp metric <METRIC>] [local-pref <VALUE>] -a ipv4", cmdstr, modtype) - helpErrMap[bgp.RF_IPv6_UC] = fmt.Errorf("usage: %s rib %s <PREFIX> [nexthop <ADDRESS>] [aigp metric <METRIC>] [local-pref <VALUE>] -a ipv6", cmdstr, modtype) + helpErrMap[bgp.RF_IPv4_UC] = fmt.Errorf("usage: %s rib %s <PREFIX> [nexthop <ADDRESS>] [med <VALUE>] [local-pref <VALUE>] [aigp metric <METRIC>] -a ipv4", cmdstr, modtype) + helpErrMap[bgp.RF_IPv6_UC] = fmt.Errorf("usage: %s rib %s <PREFIX> [nexthop <ADDRESS>] [med <VALUE>] [local-pref <VALUE>] [aigp metric <METRIC>] -a ipv6", cmdstr, modtype) fsHelpMsgFmt := fmt.Sprintf(`err: %s usage: %s rib %s match <MATCH_EXPR> then <THEN_EXPR> -a %%s <MATCH_EXPR> : { %s <PREFIX> [<OFFSET>] | %s <PREFIX> [<OFFSET>] | |