diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-05-30 21:26:29 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-05-30 21:44:54 +0900 |
commit | ed3f7b711c92c69bf231bc9e6a06312b23270db0 (patch) | |
tree | 406191f4e07653996916b74d6891473456581ea5 | |
parent | e84ed701c02e2d834d3db23098b3b4c319d9b61a (diff) |
api: fix rpki regression
the commit 8c453bc9369e4cd96d19b9598bebb0ea2e23e991 fixes
NewROAListFromApiStructList() to check an error strictly. However,
this breaks the rpki table command:
$ gobgp rpki table
invalid CIDR address: 1.0.16.0
NewROAListFromApiStructList() has a bug about getting the address
family from an IP address. The address family was not used (other
information are used though) so before the commit, the command worked.
This fixes the bug in NewROAListFromApiStructList().
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | api/util.go | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/api/util.go b/api/util.go index badcb11a..69fdc788 100644 --- a/api/util.go +++ b/api/util.go @@ -148,21 +148,15 @@ func NewROAListFromApiStructList(l []*Roa) ([]*table.ROA, error) { roas := make([]*table.ROA, 0, len(l)) for _, r := range l { ip := net.ParseIP(r.Prefix) - rf, err := func(prefix string) (bgp.RouteFamily, error) { - if a, _, err := net.ParseCIDR(prefix); err != nil { - return -1, err - } else { - if a.To4() != nil { - return bgp.RF_IPv4_UC, nil - } else { - return bgp.RF_IPv6_UC, nil - } + family := bgp.RF_IPv4_UC + if ip == nil { + return nil, fmt.Errorf("invalid prefix %s", r.Prefix) + } else { + if ip.To4() == nil { + family = bgp.RF_IPv6_UC } - }(r.Prefix) - if err != nil { - return nil, err } - afi, _ := bgp.RouteFamilyToAfiSafi(rf) + afi, _ := bgp.RouteFamilyToAfiSafi(family) roa := table.NewROA(int(afi), []byte(ip), uint8(r.Prefixlen), uint8(r.Maxlen), r.As, net.JoinHostPort(r.Conf.Address, r.Conf.RemotePort)) roas = append(roas, roa) } |