Skip to content

Commit

Permalink
Add the possibility to choose the local port in the TCP
Browse files Browse the repository at this point in the history
connection to a peer.

Signed-off-by: Arthur de Kerhor <arthurdekerhor@gmail.com>
hardeker committed Apr 7, 2022
1 parent 2768967 commit 44065ab
Showing 5 changed files with 19 additions and 5 deletions.
11 changes: 9 additions & 2 deletions internal/pkg/config/bgp_configs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/pkg/config/util.go
Original file line number Diff line number Diff line change
@@ -555,6 +555,7 @@ func NewPeerFromConfigStruct(pconf *Neighbor) *api.Peer {
},
Transport: &api.Transport{
RemotePort: uint32(pconf.Transport.Config.RemotePort),
LocalPort: uint32(pconf.Transport.Config.LocalPort),
LocalAddress: localAddress,
PassiveMode: pconf.Transport.Config.PassiveMode,
BindInterface: pconf.Transport.Config.BindInterface,
6 changes: 3 additions & 3 deletions pkg/server/fsm.go
Original file line number Diff line number Diff line change
@@ -493,7 +493,7 @@ func (h *fsmHandler) connectLoop(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done()
fsm := h.fsm

retry, addr, port, password, ttl, ttlMin, localAddress, bindInterface := func() (int, string, int, string, uint8, uint8, string, string) {
retry, addr, port, password, ttl, ttlMin, localAddress, localPort, bindInterface := func() (int, string, int, string, uint8, uint8, string, int, string) {
fsm.lock.RLock()
defer fsm.lock.RUnlock()

@@ -520,7 +520,7 @@ func (h *fsmHandler) connectLoop(ctx context.Context, wg *sync.WaitGroup) {
ttl = fsm.pConf.EbgpMultihop.Config.MultihopTtl
}
}
return tick, addr, port, password, ttl, ttlMin, fsm.pConf.Transport.Config.LocalAddress, fsm.pConf.Transport.Config.BindInterface
return tick, addr, port, password, ttl, ttlMin, fsm.pConf.Transport.Config.LocalAddress, int(fsm.pConf.Transport.Config.LocalPort), fsm.pConf.Transport.Config.BindInterface
}()

tick := minConnectRetryInterval
@@ -542,7 +542,7 @@ func (h *fsmHandler) connectLoop(ctx context.Context, wg *sync.WaitGroup) {
"Key": addr})
}

laddr, err := net.ResolveTCPAddr("tcp", net.JoinHostPort(localAddress, "0"))
laddr, err := net.ResolveTCPAddr("tcp", net.JoinHostPort(localAddress, strconv.Itoa(localPort)))
if err != nil {
fsm.logger.Warn("failed to resolve local address",
log.Fields{
1 change: 1 addition & 0 deletions pkg/server/grpc_server.go
Original file line number Diff line number Diff line change
@@ -718,6 +718,7 @@ func newNeighborFromAPIStruct(a *api.Peer) (*config.Neighbor, error) {
pconf.Transport.Config.LocalAddress = a.Transport.LocalAddress
pconf.Transport.Config.PassiveMode = a.Transport.PassiveMode
pconf.Transport.Config.RemotePort = uint16(a.Transport.RemotePort)
pconf.Transport.Config.LocalPort = uint16(a.Transport.LocalPort)
pconf.Transport.Config.BindInterface = a.Transport.BindInterface
}
if a.EbgpMultihop != nil {
5 changes: 5 additions & 0 deletions tools/pyang_plugins/gobgp.yang
Original file line number Diff line number Diff line change
@@ -926,6 +926,11 @@ module gobgp {
}

augment "/bgp:bgp/bgp:neighbors/bgp:neighbor/bgp:transport/bgp:config" {
leaf local-port {
description "Set the local port (if available) to use for the session.";
type inet:port-number;
}

leaf remote-port {
type inet:port-number;
}

0 comments on commit 44065ab

Please sign in to comment.