From bc50f352b1c21b24a4e6fed585601b47d599389b Mon Sep 17 00:00:00 2001 From: Trekkie Coder Date: Wed, 25 Oct 2023 12:55:51 +0900 Subject: [PATCH] bgp multihop support --- cmd/loxilb-agent/agent.go | 2 ++ cmd/loxilb-agent/config.go | 2 ++ cmd/loxilb-agent/options.go | 1 + pkg/agent/config/config.go | 1 + pkg/agent/manager/loadbalancer/loadbalancer.go | 15 ++++++++------- pkg/api/bgp.go | 2 ++ 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/cmd/loxilb-agent/agent.go b/cmd/loxilb-agent/agent.go index bb5df98..15be9a6 100644 --- a/cmd/loxilb-agent/agent.go +++ b/cmd/loxilb-agent/agent.go @@ -74,6 +74,7 @@ func run(o *Options) error { klog.Infof("CIDR: %s", o.config.ExternalCIDR) klog.Infof("SetBGP: %v", o.config.SetBGP) klog.Infof("ListenBGPPort: %v", o.config.ListenBGPPort) + klog.Infof("eBGPMultiHop: %v", o.config.EBGPMultiHop) klog.Infof("SetLBMode: %v", o.config.SetLBMode) klog.Infof("ExclIPAM: %v", o.config.ExclIPAM) klog.Infof("Monitor: %v", o.config.Monitor) @@ -88,6 +89,7 @@ func run(o *Options) error { ExternalCIDR6: o.config.ExternalCIDR6, SetBGP: o.config.SetBGP, ListenBGPPort: o.config.ListenBGPPort, + EBGPMultiHop: o.config.EBGPMultiHop, SetRoles: o.config.SetRoles, ExtBGPPeers: o.config.ExtBGPPeers, SetLBMode: o.config.SetLBMode, diff --git a/cmd/loxilb-agent/config.go b/cmd/loxilb-agent/config.go index 0d65b02..9c4713d 100644 --- a/cmd/loxilb-agent/config.go +++ b/cmd/loxilb-agent/config.go @@ -52,6 +52,8 @@ type AgentConfig struct { SetBGP uint16 `yaml:"setBGP,omitempty,default=0"` // Custom BGP Port ListenBGPPort uint16 `yaml:"listenBGPPort,omitempty,default=179"` + // Set eBGP multi-hop + EBGPMultiHop bool `yaml:"eBGPMultiHop"` // loxilb loadbalancer mode SetLBMode uint16 `yaml:"setLBMode,omitempty"` // Shared or exclusive IPAM diff --git a/cmd/loxilb-agent/options.go b/cmd/loxilb-agent/options.go index a24ceb8..073f223 100644 --- a/cmd/loxilb-agent/options.go +++ b/cmd/loxilb-agent/options.go @@ -62,6 +62,7 @@ func (o *Options) addFlags(fs *pflag.FlagSet) { fs.StringVar(&o.config.LoxilbLoadBalancerClass, "loxilbLoadBalancerClass", o.config.LoxilbLoadBalancerClass, "Load-Balancer Class Name") fs.Uint16Var(&o.config.SetBGP, "setBGP", o.config.SetBGP, "Use BGP routing") fs.Uint16Var(&o.config.ListenBGPPort, "listenBGPPort", o.config.ListenBGPPort, "Custom BGP listen port") + fs.BoolVar(&o.config.EBGPMultiHop, "eBGPMultiHop", o.config.EBGPMultiHop, "Enable multi-hop eBGP") fs.StringVar(&extBGPPeers, "extBGPPeers", extBGPPeers, "External BGP Peer(s)") fs.BoolVar(&o.config.ExclIPAM, "setUniqueIP", false, "Use unique IPAM per service") fs.Uint16Var(&o.config.SetLBMode, "setLBMode", o.config.SetLBMode, "LB mode to use") diff --git a/pkg/agent/config/config.go b/pkg/agent/config/config.go index 8ed7705..9d91a2b 100644 --- a/pkg/agent/config/config.go +++ b/pkg/agent/config/config.go @@ -25,6 +25,7 @@ type NetworkConfig struct { ExternalSecondaryCIDRs6 []string SetBGP uint16 ListenBGPPort uint16 + EBGPMultiHop bool ExtBGPPeers []string SetLBMode uint16 Monitor bool diff --git a/pkg/agent/manager/loadbalancer/loadbalancer.go b/pkg/agent/manager/loadbalancer/loadbalancer.go index a8fbf57..7d2a100 100644 --- a/pkg/agent/manager/loadbalancer/loadbalancer.go +++ b/pkg/agent/manager/loadbalancer/loadbalancer.go @@ -1136,7 +1136,7 @@ func (m *Manager) makeLoxiLBBGPGlobalModel(localAS int, selfID string, setNHSelf }, nil } -func (m *Manager) makeLoxiLBBGNeighModel(remoteAS int, IPString string, rPort uint16) (api.BGPNeigh, error) { +func (m *Manager) makeLoxiLBBGNeighModel(remoteAS int, IPString string, rPort uint16, mHopEn bool) (api.BGPNeigh, error) { port := rPort if rPort == 0 { @@ -1144,9 +1144,10 @@ func (m *Manager) makeLoxiLBBGNeighModel(remoteAS int, IPString string, rPort ui } return api.BGPNeigh{ - RemoteAs: int64(remoteAS), - IPAddress: IPString, - RemotePort: int64(port), + RemoteAs: int64(remoteAS), + IPAddress: IPString, + RemotePort: int64(port), + SetMultiHop: mHopEn, }, nil } @@ -1419,7 +1420,7 @@ loop: } for _, bgpPeer := range bgpPeers { - bgpNeighCfg, _ := m.makeLoxiLBBGNeighModel(int(m.networkConfig.SetBGP), bgpPeer.Host, m.networkConfig.ListenBGPPort) + bgpNeighCfg, _ := m.makeLoxiLBBGNeighModel(int(m.networkConfig.SetBGP), bgpPeer.Host, m.networkConfig.ListenBGPPort, false) err := func(bgpNeighCfg *api.BGPNeigh) error { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() @@ -1432,7 +1433,7 @@ loop: m.checkHandleBGPCfgErrors(loxiAliveCh, aliveClient, err) } - bgpNeighCfg1, _ := m.makeLoxiLBBGNeighModel(int(m.networkConfig.SetBGP), aliveClient.Host, m.networkConfig.ListenBGPPort) + bgpNeighCfg1, _ := m.makeLoxiLBBGNeighModel(int(m.networkConfig.SetBGP), aliveClient.Host, m.networkConfig.ListenBGPPort, false) err = func(bgpNeighCfg1 *api.BGPNeigh) error { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() @@ -1463,7 +1464,7 @@ loop: continue } - bgpNeighCfg, _ := m.makeLoxiLBBGNeighModel(int(asid), bgpRemoteIP.String(), 0) + bgpNeighCfg, _ := m.makeLoxiLBBGNeighModel(int(asid), bgpRemoteIP.String(), 0, m.networkConfig.EBGPMultiHop) err = func(bgpNeighCfg *api.BGPNeigh) error { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() diff --git a/pkg/api/bgp.go b/pkg/api/bgp.go index 0cbbbe2..bdf66f2 100644 --- a/pkg/api/bgp.go +++ b/pkg/api/bgp.go @@ -12,6 +12,8 @@ type BGPNeigh struct { RemoteAs int64 `json:"remoteAs,omitempty"` // Remote Connect Port (default 179) RemotePort int64 `json:"remotePort,omitempty"` + // Enable multi-hop peering (if needed) + SetMultiHop bool `json:"setMultiHop,omitempty"` } type BGPGlobalConfig struct {