diff options
author | Satoshi Fujimoto <satoshi.fujimoto7@gmail.com> | 2018-05-11 10:36:50 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-05-22 21:33:07 +0900 |
commit | 8c453bc9369e4cd96d19b9598bebb0ea2e23e991 (patch) | |
tree | 7d09460f41017f940ab758a7f113661a778859df /api | |
parent | ccb4f8cdf08dc85198c353a54f8cef4558d0a360 (diff) |
cmd: Remove uncaught error on ParseCIDR()
Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com>
Diffstat (limited to 'api')
-rw-r--r-- | api/util.go | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/api/util.go b/api/util.go index 177b48a9..badcb11a 100644 --- a/api/util.go +++ b/api/util.go @@ -126,35 +126,47 @@ func (p *Path) ToNativePath(option ...ToNativeOption) (*table.Path, error) { nlri.SetPathIdentifier(p.Identifier) nlri.SetPathLocalIdentifier(p.LocalIdentifier) path := table.NewPath(info, nlri, p.IsWithdraw, pattr, t, false) + + // p.ValidationDetail.* are already validated + matched, _ := NewROAListFromApiStructList(p.ValidationDetail.Matched) + unmatchedAs, _ := NewROAListFromApiStructList(p.ValidationDetail.UnmatchedAs) + unmatchedLength, _ := NewROAListFromApiStructList(p.ValidationDetail.UnmatchedLength) + path.SetValidation(&table.Validation{ Status: config.IntToRpkiValidationResultTypeMap[int(p.Validation)], Reason: table.IntToRpkiValidationReasonTypeMap[int(p.ValidationDetail.Reason)], - Matched: NewROAListFromApiStructList(p.ValidationDetail.Matched), - UnmatchedAs: NewROAListFromApiStructList(p.ValidationDetail.UnmatchedAs), - UnmatchedLength: NewROAListFromApiStructList(p.ValidationDetail.UnmatchedLength), + Matched: matched, + UnmatchedAs: unmatchedAs, + UnmatchedLength: unmatchedLength, }) path.MarkStale(p.Stale) path.IsNexthopInvalid = p.IsNexthopInvalid return path, nil } -func NewROAListFromApiStructList(l []*Roa) []*table.ROA { +func NewROAListFromApiStructList(l []*Roa) ([]*table.ROA, error) { roas := make([]*table.ROA, 0, len(l)) for _, r := range l { ip := net.ParseIP(r.Prefix) - rf := func(prefix string) bgp.RouteFamily { - a, _, _ := net.ParseCIDR(prefix) - if a.To4() != nil { - return bgp.RF_IPv4_UC + rf, err := func(prefix string) (bgp.RouteFamily, error) { + if a, _, err := net.ParseCIDR(prefix); err != nil { + return -1, err } else { - return bgp.RF_IPv6_UC + if a.To4() != nil { + return bgp.RF_IPv4_UC, nil + } else { + return bgp.RF_IPv6_UC, nil + } } }(r.Prefix) + if err != nil { + return nil, err + } afi, _ := bgp.RouteFamilyToAfiSafi(rf) 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) } - return roas + return roas, nil } func extractFamilyFromConfigAfiSafi(c *config.AfiSafi) uint32 { |