(path *api.Path)
| 604 | } |
| 605 | |
| 606 | func api2apiutilPath(path *api.Path) (*apiutil.Path, error) { |
| 607 | nlri, err := apiutil.GetNativeNlri(path) |
| 608 | if err != nil { |
| 609 | return nil, fmt.Errorf("invalid nlri: %w", err) |
| 610 | } |
| 611 | attrs, err := apiutil.GetNativePathAttributes(path) |
| 612 | if err != nil { |
| 613 | return nil, fmt.Errorf("invalid path attributes: %w", err) |
| 614 | } |
| 615 | // source is optional |
| 616 | src, _ := netip.ParseAddr(path.SourceId) |
| 617 | neighbor, _ := netip.ParseAddr(path.NeighborIp) |
| 618 | p := &apiutil.Path{ |
| 619 | Family: bgp.NewFamily(uint16(path.Family.Afi), uint8(path.Family.Safi)), |
| 620 | Nlri: nlri, |
| 621 | Attrs: attrs, |
| 622 | Age: path.Age.GetSeconds(), |
| 623 | Best: path.Best, |
| 624 | Stale: path.Stale, |
| 625 | Withdrawal: path.IsWithdraw, |
| 626 | PeerASN: path.SourceAsn, |
| 627 | PeerID: src, |
| 628 | PeerAddress: neighbor, |
| 629 | IsFromExternal: path.IsFromExternal, |
| 630 | NoImplicitWithdraw: path.NoImplicitWithdraw, |
| 631 | LocalID: path.LocalIdentifier, |
| 632 | RemoteID: path.Identifier, |
| 633 | } |
| 634 | if p.PeerASN != 0 && !p.PeerID.IsValid() { |
| 635 | return nil, fmt.Errorf("source ID must be set correctly %v", p.PeerID) |
| 636 | } |
| 637 | return p, nil |
| 638 | } |
| 639 | |
| 640 | func (s *server) AddPath(ctx context.Context, r *api.AddPathRequest) (*api.AddPathResponse, error) { |
| 641 | if r.Path == nil { |
searching dependent graphs…