diff --git a/internal/bgp/bgp.go b/internal/bgp/bgp.go index 26ca27b..60deb58 100644 --- a/internal/bgp/bgp.go +++ b/internal/bgp/bgp.go @@ -9,14 +9,14 @@ import ( "slices" ) -func newBgpPath(prefix *bgpapi.IPAddressPrefix, asn uint32) *bgpapi.Path { +func newBgpPath(prefix *bgpapi.IPAddressPrefix, asn uint32, nh string) *bgpapi.Path { nlri, _ := anypb.New(prefix) a1, _ := anypb.New(&bgpapi.OriginAttribute{ Origin: 1, // IGP }) a2, _ := anypb.New(&bgpapi.NextHopAttribute{ - NextHop: "255.255.255.255", //cfg.AppCfg.Routing().Bgp().Id() + NextHop: nh, }) a3, _ := anypb.New(&bgpapi.AsPathAttribute{ Segments: []*bgpapi.AsSegment{ @@ -42,7 +42,7 @@ func (s *bgpSrv) add(prefix *bgpapi.IPAddressPrefix, asn uint32) error { s.L().Info().Msgf("Adding prefix: %s", prefix.String()) //TODO: pass context if _, e := s.bgp.AddPath(context.Background(), &bgpapi.AddPathRequest{ - Path: newBgpPath(prefix, asn), + Path: newBgpPath(prefix, asn, s.id.String()), }); e != nil { return fmt.Errorf("unable to add path: %v, %w", prefix, e) } @@ -96,7 +96,7 @@ func (s *bgpSrv) remove(prefix *bgpapi.IPAddressPrefix, asn uint32) error { found, _ := s.find([]*bgpapi.IPAddressPrefix{prefix}) if found != nil { e := s.bgp.DeletePath(context.Background(), &bgpapi.DeletePathRequest{ - Path: newBgpPath(prefix, asn), + Path: newBgpPath(prefix, asn, s.id.String()), }) return e } diff --git a/internal/bgp/main.go b/internal/bgp/main.go index dd60aeb..eb09e12 100644 --- a/internal/bgp/main.go +++ b/internal/bgp/main.go @@ -7,6 +7,7 @@ import ( "github.com/red55/bgp-dns/internal/config" "github.com/red55/bgp-dns/internal/log" "github.com/red55/bgp-dns/internal/loop" + "net" "sync" "sync/atomic" ) @@ -20,6 +21,7 @@ type bgpSrv struct { cancel context.CancelFunc wg sync.WaitGroup asn uint32 + id net.IP } @@ -42,6 +44,7 @@ func Serve(ctx context.Context) (e error) { //ipRefCounter: hashmap.New[string, *atomic.Uint64](), ipRefCounter: make(map[string]*atomic.Uint64), asn: cfg.Bgp.Asn, + id: cfg.Bgp.Id, } go func () { _bgp.bgp.Serve()