From 3e695cf2fb5c12c054781aab5ca32400ac4780f8 Mon Sep 17 00:00:00 2001 From: Trekkie Coder Date: Wed, 25 Oct 2023 12:54:36 +0900 Subject: [PATCH] bgp multihop support --- api/models/b_g_p_neigh.go | 3 +++ api/restapi/embedded_spec.go | 8 ++++++++ api/restapi/handler/gobgp.go | 3 +++ api/swagger.yml | 3 +++ common/common.go | 1 + loxinet/apiclient.go | 4 ++-- loxinet/gobgpclient.go | 9 ++++++++- 7 files changed, 28 insertions(+), 3 deletions(-) diff --git a/api/models/b_g_p_neigh.go b/api/models/b_g_p_neigh.go index 2671eab50..2da79cbc4 100644 --- a/api/models/b_g_p_neigh.go +++ b/api/models/b_g_p_neigh.go @@ -25,6 +25,9 @@ type BGPNeigh struct { // Remote Connect Port (default 179) RemotePort int64 `json:"remotePort,omitempty"` + + // Enable multi-hop peering (if needed) + SetMultiHop bool `json:"setMultiHop,omitempty"` } // Validate validates this b g p neigh diff --git a/api/restapi/embedded_spec.go b/api/restapi/embedded_spec.go index 63efa87b0..b7e8f4e45 100644 --- a/api/restapi/embedded_spec.go +++ b/api/restapi/embedded_spec.go @@ -3264,6 +3264,10 @@ func init() { "remotePort": { "description": "Remote Connect Port (default 179)", "type": "integer" + }, + "setMultiHop": { + "description": "Enable multi-hop peering (if needed)", + "type": "boolean" } } }, @@ -7639,6 +7643,10 @@ func init() { "remotePort": { "description": "Remote Connect Port (default 179)", "type": "integer" + }, + "setMultiHop": { + "description": "Enable multi-hop peering (if needed)", + "type": "boolean" } } }, diff --git a/api/restapi/handler/gobgp.go b/api/restapi/handler/gobgp.go index b1b4d2040..2e1be1f23 100644 --- a/api/restapi/handler/gobgp.go +++ b/api/restapi/handler/gobgp.go @@ -36,6 +36,9 @@ func ConfigPostBGPNeigh(params operations.PostConfigBgpNeighParams) middleware.R // Remote Port bgpNeighMod.RemotePort = uint16(params.Attr.RemotePort) + // Multi-hop or not + bgpNeighMod.MultiHop = params.Attr.SetMultiHop + tk.LogIt(tk.LogDebug, "[API] GoBGP neighAdd : %v\n", bgpNeighMod) _, err := ApiHooks.NetGoBGPNeighAdd(&bgpNeighMod) if err != nil { diff --git a/api/swagger.yml b/api/swagger.yml index 1c64a999b..d7e81ae5a 100644 --- a/api/swagger.yml +++ b/api/swagger.yml @@ -3100,6 +3100,9 @@ definitions: remotePort: type: integer description: Remote Connect Port (default 179) + setMultiHop: + type: boolean + description: Enable multi-hop peering (if needed) BGPGlobalConfig: type: object diff --git a/common/common.go b/common/common.go index dd6ae1d8d..1a6a217d7 100644 --- a/common/common.go +++ b/common/common.go @@ -605,6 +605,7 @@ type GoBGPNeighMod struct { Addr net.IP `json:"neighIP"` RemoteAS uint32 `json:"remoteAS"` RemotePort uint16 `json:"remotePort"` + MultiHop bool `json:"multiHop"` } // Equal - check if two session tunnel entries are equal diff --git a/loxinet/apiclient.go b/loxinet/apiclient.go index 921fedae1..2f1e8c208 100644 --- a/loxinet/apiclient.go +++ b/loxinet/apiclient.go @@ -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, uint32(param.RemotePort)) + return mh.bgp.BGPNeighMod(true, param.Addr, param.RemoteAS, uint32(param.RemotePort), param.MultiHop) } tk.LogIt(tk.LogDebug, "loxilb BGP mode is disabled \n") return 0, errors.New("loxilb BGP mode is disabled") @@ -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, uint32(param.RemotePort)) + return mh.bgp.BGPNeighMod(false, param.Addr, param.RemoteAS, uint32(param.RemotePort), param.MultiHop) } tk.LogIt(tk.LogDebug, "loxilb BGP mode is disabled \n") return 0, errors.New("loxilb BGP mode is disabled") diff --git a/loxinet/gobgpclient.go b/loxinet/gobgpclient.go index ef119f07e..abb31d700 100644 --- a/loxinet/gobgpclient.go +++ b/loxinet/gobgpclient.go @@ -909,7 +909,7 @@ func (gbh *GoBgpH) resetBGPMed(toLow bool) error { } // BGPNeighMod - Routine to add BGP neigh to goBGP server -func (gbh *GoBgpH) BGPNeighMod(add bool, neigh net.IP, ras uint32, rPort uint32) (int, error) { +func (gbh *GoBgpH) BGPNeighMod(add bool, neigh net.IP, ras uint32, rPort uint32, mhop bool) (int, error) { var peer *api.Peer var err error @@ -930,6 +930,13 @@ func (gbh *GoBgpH) BGPNeighMod(add bool, neigh net.IP, ras uint32, rPort uint32) peer.Transport.RemotePort = 179 } + if mhop { + peer.EbgpMultihop = &api.EbgpMultihop{ + Enabled: true, + MultihopTtl: uint32(8), + } + } + ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel()