Skip to content

Commit

Permalink
Custom remote port support for gobgp
Browse files Browse the repository at this point in the history
  • Loading branch information
TrekkieCoder committed Jul 31, 2023
1 parent 82c7b65 commit 098b893
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 9 deletions.
5 changes: 4 additions & 1 deletion api/models/b_g_p_neigh.go

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

12 changes: 10 additions & 2 deletions api/restapi/embedded_spec.go

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

3 changes: 3 additions & 0 deletions api/restapi/handler/gobgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ func ConfigPostBGPNeigh(params operations.PostConfigBgpNeighParams) middleware.R
// Remote AS
bgpNeighMod.RemoteAS = uint32(params.Attr.RemoteAs)

// Remote Port
bgpNeighMod.RemotePort = uint16(params.Attr.RemotePort)

tk.LogIt(tk.LogDebug, "[API] GoBGP neighAdd : %v\n", bgpNeighMod)
_, err := ApiHooks.NetGoBGPNeighAdd(&bgpNeighMod)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion api/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3090,10 +3090,13 @@ definitions:
properties:
ipAddress:
type: string
description: BGP Nieghbor IP address
description: BGP Neighbor IP address
remoteAs:
type: integer
description: Remote AS number
remotePort:
type: integer
description: Remote Connect Port (default 179)

BGPGlobalConfig:
type: object
Expand Down
5 changes: 3 additions & 2 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,9 @@ type GoBGPGlobalConfig struct {

// GoBGPNeighMod - Info related to goBGP neigh
type GoBGPNeighMod struct {
Addr net.IP `json:"neighIP"`
RemoteAS uint32 `json:"remoteAS"`
Addr net.IP `json:"neighIP"`
RemoteAS uint32 `json:"remoteAS"`
RemotePort uint16 `json:"remotePort"`
}

// Equal - check if two session tunnel entries are equal
Expand Down
4 changes: 2 additions & 2 deletions loxinet/apiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ func (na *NetAPIStruct) NetParamGet(param *cmn.ParamMod) (int, error) {
// NetGoBGPNeighAdd - Add bgp neigh to gobgp
func (na *NetAPIStruct) NetGoBGPNeighAdd(param *cmn.GoBGPNeighMod) (int, error) {
if mh.bgp != nil {
return mh.bgp.BGPNeighMod(true, param.Addr, param.RemoteAS)
return mh.bgp.BGPNeighMod(true, param.Addr, param.RemoteAS, uint32(param.RemotePort))
}
tk.LogIt(tk.LogDebug, "loxilb BGP mode is disabled \n")
return 0, errors.New("loxilb BGP mode is disabled")
Expand All @@ -600,7 +600,7 @@ func (na *NetAPIStruct) NetGoBGPNeighAdd(param *cmn.GoBGPNeighMod) (int, error)
// NetGoBGPNeighDel - Del bgp neigh from gobgp
func (na *NetAPIStruct) NetGoBGPNeighDel(param *cmn.GoBGPNeighMod) (int, error) {
if mh.bgp != nil {
return mh.bgp.BGPNeighMod(false, param.Addr, param.RemoteAS)
return mh.bgp.BGPNeighMod(false, param.Addr, param.RemoteAS, uint32(param.RemotePort))
}
tk.LogIt(tk.LogDebug, "loxilb BGP mode is disabled \n")
return 0, errors.New("loxilb BGP mode is disabled")
Expand Down
9 changes: 8 additions & 1 deletion loxinet/gobgpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ func (gbh *GoBgpH) UpdateCIState(instance string, state int, vip net.IP) {
}

// BGPNeighMod - Routine to add BGP neigh to goBGP server
func (gbh *GoBgpH) BGPNeighMod(add bool, neigh net.IP, ras uint32) (int, error) {
func (gbh *GoBgpH) BGPNeighMod(add bool, neigh net.IP, ras uint32, rPort uint32) (int, error) {
var peer *api.Peer
var err error

Expand All @@ -748,10 +748,17 @@ func (gbh *GoBgpH) BGPNeighMod(add bool, neigh net.IP, ras uint32) (int, error)
State: &api.PeerState{},
RouteServer: &api.RouteServer{},
RouteReflector: &api.RouteReflector{},
Transport: &api.Transport{},
}
peer.Conf.NeighborAddress = neigh.String()
peer.State.NeighborAddress = neigh.String()
peer.Conf.PeerAsn = ras
if rPort != 0 {
peer.Transport.RemotePort = rPort
} else {
peer.Transport.RemotePort = 179
}

if add {
_, err = gbh.client.AddPeer(context.Background(),
&api.AddPeerRequest{
Expand Down

0 comments on commit 098b893

Please sign in to comment.