Skip to content

Commit

Permalink
feat: add proto placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
0x416e746f6e committed Jun 27, 2024
1 parent a5df3b6 commit c9ae746
Show file tree
Hide file tree
Showing 43 changed files with 409 additions and 244 deletions.
8 changes: 3 additions & 5 deletions .dev/br-lft-act.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ metrics:

default_scripts:
bridge_activate:
- ["sh", "-c", "echo ${bridge_interface} ${bridge_interface_ip} ${bridge_peer_cidr}"]
- ["sleep", "15"]
- ["sh", "-c", "exit 1"]
- ["sh", "-c", "echo ${proto} ${bridge_interface} ${bridge_interface_ip} ${bridge_peer_cidr}"]

interface_activate:
- ["sh", "-c", "echo 'activate ${tunnel_interface} ${tunnel_interface_ip}'"]
- ["sh", "-c", "echo 'activate ${proto} ${tunnel_interface} ${tunnel_interface_ip}'"]

interface_deactivate:
- ["sh", "-c", "echo 'deactivate ${tunnel_interface} ${tunnel_interface_ip}'"]
- ["sh", "-c", "echo 'deactivate ${proto} ${tunnel_interface} ${tunnel_interface_ip}'"]
7 changes: 3 additions & 4 deletions .dev/br-lft-sby.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ metrics:

default_scripts:
bridge_activate:
- ["sh", "-c", "echo ${bridge_interface} ${bridge_interface_ip} ${bridge_peer_cidr}"]
- ["sleep", "15"]
- ["sh", "-c", "echo ${proto} ${bridge_interface} ${bridge_interface_ip} ${bridge_peer_cidr}"]

interface_activate:
- ["sh", "-c", "echo 'activate ${tunnel_interface} ${tunnel_interface_ip}'"]
- ["sh", "-c", "echo 'activate ${proto} ${tunnel_interface} ${tunnel_interface_ip}'"]

interface_deactivate:
- ["sh", "-c", "echo 'deactivate ${tunnel_interface} ${tunnel_interface_ip}'"]
- ["sh", "-c", "echo 'deactivate ${proto} ${tunnel_interface} ${tunnel_interface_ip}'"]
7 changes: 3 additions & 4 deletions .dev/br-rgt-act.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ metrics:

default_scripts:
bridge_activate:
- ["sh", "-c", "echo ${bridge_interface} ${bridge_interface_ip} ${bridge_peer_cidr}"]
- ["sleep", "15"]
- ["sh", "-c", "echo ${proto} ${bridge_interface} ${bridge_interface_ip} ${bridge_peer_cidr}"]

interface_activate:
- ["sh", "-c", "echo 'activate ${tunnel_interface} ${tunnel_interface_ip}'"]
- ["sh", "-c", "echo 'activate ${proto} ${tunnel_interface} ${tunnel_interface_ip}'"]

interface_deactivate:
- ["sh", "-c", "echo 'deactivate ${tunnel_interface} ${tunnel_interface_ip}'"]
- ["sh", "-c", "echo 'deactivate ${proto} ${tunnel_interface} ${tunnel_interface_ip}'"]
7 changes: 3 additions & 4 deletions .dev/br-rgt-sby.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ metrics:

default_scripts:
bridge_activate:
- ["sh", "-c", "echo ${bridge_interface} ${bridge_interface_ip} ${bridge_peer_cidr}"]
- ["sleep", "15"]
- ["sh", "-c", "echo ${proto} ${bridge_interface} ${bridge_interface_ip} ${bridge_peer_cidr}"]

interface_activate:
- ["sh", "-c", "echo 'activate ${tunnel_interface} ${tunnel_interface_ip}'"]
- ["sh", "-c", "echo 'activate ${proto} ${tunnel_interface} ${tunnel_interface_ip}'"]

interface_deactivate:
- ["sh", "-c", "echo 'deactivate ${tunnel_interface} ${tunnel_interface_ip}'"]
- ["sh", "-c", "echo 'deactivate ${proto} ${tunnel_interface} ${tunnel_interface_ip}'"]
18 changes: 18 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Copyright (c) 2024 Flashbots

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the “Software”), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 changes: 23 additions & 15 deletions bridge/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (s *Server) runEventLoop(ctx context.Context, failureSink chan<- error) {
s.eventTunnelProbeSendSuccess(ctx, e, failureSink)
default:
l.Error("Unexpected event",
zap.String("kind", e.EventKind()),
zap.String("kind", e.EvtKind()),
zap.String("type", reflect.TypeOf(e).String()),
)
}
Expand All @@ -87,8 +87,8 @@ func (s *Server) detectTunnelUpDownEvents(e event.TunnelInterfaceEvent, updateMo
s.mxStatus.Lock()
defer s.mxStatus.Unlock()

ifs := s.status.Interfaces[e.TunnelInterface()]
mon := s.monitors[e.TunnelInterface()]
ifs := s.status.Interfaces[e.EvtTunnelInterface()]
mon := s.monitors[e.EvtTunnelInterface()]

updateMonitor(mon)

Expand All @@ -97,17 +97,21 @@ func (s *Server) detectTunnelUpDownEvents(e event.TunnelInterfaceEvent, updateMo
if ifs.Up {
ifs.Up = false
s.events <- &event.TunnelInterfaceWentDown{ // emit event
Interface: e.TunnelInterface(),
Timestamp: e.EventTimestamp(),
BridgeInterface: s.cfg.BridgeInterface,
BridgePeerCIDR: s.cfg.PeerCIDR,
TunnelInterface: e.EvtTunnelInterface(),
Timestamp: e.EvtTimestamp(),
}
}

case monitor.Up:
if !ifs.Up {
ifs.Up = true
s.events <- &event.TunnelInterfaceWentUp{ // emit event
Interface: e.TunnelInterface(),
Timestamp: e.EventTimestamp(),
BridgeInterface: s.cfg.BridgeInterface,
BridgePeerCIDR: s.cfg.PeerCIDR,
TunnelInterface: e.EvtTunnelInterface(),
Timestamp: e.EvtTimestamp(),
}
}
}
Expand All @@ -129,19 +133,23 @@ func (s *Server) deriveBridgeEvents(e event.TunnelInterfaceEvent) {

if up {
s.events <- &event.BridgeWentUp{ // emit event
Timestamp: e.EventTimestamp(),
BridgeInterface: s.cfg.BridgeInterface,
BridgePerCIDR: s.cfg.PeerCIDR,
Timestamp: e.EvtTimestamp(),
}
} else {
s.events <- &event.BridgeWentDown{ // emit event
Timestamp: e.EventTimestamp(),
BridgeInterface: s.cfg.BridgeInterface,
BridgePeerCIDR: s.cfg.PeerCIDR,
Timestamp: e.EvtTimestamp(),
}
}

s.status.Up = up
}

// derivePartnerUpDownEvents derives partner up/down events from partner poll events
func (s *Server) derivePartnerUpDownEvents(e event.PartnerEvent, updateMonitor func(*monitor.Monitor)) {
func (s *Server) derivePartnerUpDownEvents(e event.PartnerPollEvent, updateMonitor func(*monitor.Monitor)) {
s.mxPartnerStatus.Lock()
defer s.mxPartnerStatus.Unlock()

Expand All @@ -163,15 +171,15 @@ func (s *Server) derivePartnerUpDownEvents(e event.PartnerEvent, updateMonitor f
if s.partnerStatus.Up {
s.partnerStatus.Up = false
s.events <- &event.PartnerWentDown{ // emit event
Timestamp: e.EventTimestamp(),
Timestamp: e.EvtTimestamp(),
}
}

case monitor.Up:
if firstContact || !s.partnerStatus.Up {
s.partnerStatus.Up = true
s.events <- &event.PartnerWentUp{ // emit events
Timestamp: e.EventTimestamp(),
Timestamp: e.EvtTimestamp(),
}
}
}
Expand All @@ -185,19 +193,19 @@ func (s *Server) derivePartnerUpDownEvents(e event.PartnerEvent, updateMonitor f
s.events <- &event.PartnerChangedName{ // emit event
OldName: s.partnerStatus.Name,
NewName: newPartnerStatus.Name,
Timestamp: e.EventTimestamp(),
Timestamp: e.EvtTimestamp(),
}
s.partnerStatus.Name = newPartnerStatus.Name
}

if s.partnerStatus.Active != newPartnerStatus.Active {
if newPartnerStatus.Active {
s.events <- &event.PartnerActivated{ // emit event
Timestamp: e.EventTimestamp(),
Timestamp: e.EvtTimestamp(),
}
} else {
s.events <- &event.PartnerDeactivated{ // emit event
Timestamp: e.EventTimestamp(),
Timestamp: e.EvtTimestamp(),
}
}
s.partnerStatus.Active = newPartnerStatus.Active
Expand Down
4 changes: 3 additions & 1 deletion bridge/events_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ func (s *Server) eventBridgeWentDown(ctx context.Context, e *event.BridgeWentDow
if s.status.Active {
s.status.Active = false
s.events <- &event.BridgeDeactivated{ // emit event
Timestamp: e.Timestamp,
BridgeInterface: s.cfg.BridgeInterface,
BridgePeerCIDR: s.cfg.PeerCIDR,
Timestamp: e.Timestamp,
}
}

Expand Down
2 changes: 1 addition & 1 deletion bridge/events_partner.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (s *Server) eventPartnerWentDown(ctx context.Context, e *event.PartnerWentD
if s.partnerStatus.Active {
s.partnerStatus.Active = false
s.events <- &event.PartnerDeactivated{ // emit event
Timestamp: e.EventTimestamp(),
Timestamp: e.EvtTimestamp(),
}
}

Expand Down
30 changes: 15 additions & 15 deletions bridge/events_tunnel_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (s *Server) eventTunnelInterfaceWentDown(ctx context.Context, e *event.Tunn
l.Info("Tunnel interface went down",
zap.String("bridge_name", s.cfg.Name),
zap.String("bridge_uuid", s.uuid.String()),
zap.String("tunnel_interface", e.TunnelInterface()),
zap.String("tunnel_interface", e.EvtTunnelInterface()),
)

s.deriveBridgeEvents(e)
Expand All @@ -28,7 +28,7 @@ func (s *Server) eventTunnelInterfaceWentDown(ctx context.Context, e *event.Tunn
s.mxStatus.Lock()
defer s.mxStatus.Unlock()

ifs := s.status.Interfaces[e.TunnelInterface()]
ifs := s.status.Interfaces[e.EvtTunnelInterface()]
if !ifs.Active {
return
}
Expand All @@ -39,21 +39,21 @@ func (s *Server) eventTunnelInterfaceWentDown(ctx context.Context, e *event.Tunn
s.events <- &event.TunnelInterfaceDeactivated{ // emit event
BridgeInterface: s.cfg.BridgeInterface,
BridgePeerCIDR: s.cfg.PeerCIDR,
Interface: e.TunnelInterface(),
TunnelInterface: e.EvtTunnelInterface(),
Timestamp: e.Timestamp,
}

// then activate another tunnel

for promotedIfsName, promotedIfs := range s.status.Interfaces {
if promotedIfsName == e.TunnelInterface() || !promotedIfs.Up {
if promotedIfsName == e.EvtTunnelInterface() || !promotedIfs.Up {
continue
}
promotedIfs.Active = true
s.events <- &event.TunnelInterfaceActivated{ // emit event
BridgeInterface: s.cfg.BridgeInterface,
BridgePeerCIDR: s.cfg.PeerCIDR,
Interface: promotedIfsName,
TunnelInterface: promotedIfsName,
Timestamp: e.Timestamp,
}
return
Expand All @@ -66,7 +66,7 @@ func (s *Server) eventTunnelInterfaceWentUp(ctx context.Context, e *event.Tunnel
l.Info("Tunnel interface went up",
zap.String("bridge_name", s.cfg.Name),
zap.String("bridge_uuid", s.uuid.String()),
zap.String("tunnel_interface", e.TunnelInterface()),
zap.String("tunnel_interface", e.EvtTunnelInterface()),
)

s.deriveBridgeEvents(e)
Expand All @@ -83,22 +83,22 @@ func (s *Server) eventTunnelInterfaceWentUp(ctx context.Context, e *event.Tunnel
s.mxStatus.Lock()
defer s.mxStatus.Unlock()

ifs := s.status.Interfaces[e.TunnelInterface()]
cfg := s.cfg.TunnelInterfaces[e.TunnelInterface()]
ifs := s.status.Interfaces[e.EvtTunnelInterface()]
cfg := s.cfg.TunnelInterfaces[e.EvtTunnelInterface()]
switch cfg.Role {
case types.RoleActive:
if !ifs.Active {
// first deactivate other tunnel (if needed)

for demotedIfsName, demotedIfs := range s.status.Interfaces {
if demotedIfsName == e.TunnelInterface() || !demotedIfs.Active {
if demotedIfsName == e.EvtTunnelInterface() || !demotedIfs.Active {
continue
}
demotedIfs.Active = false
s.events <- &event.TunnelInterfaceDeactivated{ // emit event
BridgeInterface: s.cfg.BridgeInterface,
BridgePeerCIDR: s.cfg.PeerCIDR,
Interface: demotedIfsName,
TunnelInterface: demotedIfsName,
Timestamp: e.Timestamp,
}
}
Expand All @@ -109,7 +109,7 @@ func (s *Server) eventTunnelInterfaceWentUp(ctx context.Context, e *event.Tunnel
s.events <- &event.TunnelInterfaceActivated{ // emit event
BridgeInterface: s.cfg.BridgeInterface,
BridgePeerCIDR: s.cfg.PeerCIDR,
Interface: e.TunnelInterface(),
TunnelInterface: e.EvtTunnelInterface(),
Timestamp: e.Timestamp,
}

Expand All @@ -118,7 +118,7 @@ func (s *Server) eventTunnelInterfaceWentUp(ctx context.Context, e *event.Tunnel
case types.RoleStandby:
anotherActiveIfsExists := false
for anotherIfsName, anotherIfs := range s.status.Interfaces {
if anotherIfsName == e.TunnelInterface() {
if anotherIfsName == e.EvtTunnelInterface() {
continue
}
if anotherIfs.Active {
Expand All @@ -131,7 +131,7 @@ func (s *Server) eventTunnelInterfaceWentUp(ctx context.Context, e *event.Tunnel
s.events <- &event.TunnelInterfaceActivated{ // emit event
BridgeInterface: s.cfg.BridgeInterface,
BridgePeerCIDR: s.cfg.PeerCIDR,
Interface: e.TunnelInterface(),
TunnelInterface: e.EvtTunnelInterface(),
Timestamp: e.Timestamp,
}
}
Expand All @@ -144,7 +144,7 @@ func (s *Server) eventTunnelInterfaceDeactivated(ctx context.Context, e *event.T
l.Info("Tunnel interface deactivated",
zap.String("bridge_name", s.cfg.Name),
zap.String("bridge_uuid", s.uuid.String()),
zap.String("tunnel_interface", e.TunnelInterface()),
zap.String("tunnel_interface", e.EvtTunnelInterface()),
)

s.executor.ExecuteInterfaceDeactivate(ctx, e)
Expand All @@ -156,7 +156,7 @@ func (s *Server) eventTunnelInterfaceActivated(ctx context.Context, e *event.Tun
l.Info("Tunnel interface activated",
zap.String("bridge_name", s.cfg.Name),
zap.String("bridge_uuid", s.uuid.String()),
zap.String("tunnel_interface", e.TunnelInterface()),
zap.String("tunnel_interface", e.EvtTunnelInterface()),
)

s.executor.ExecuteInterfaceActivate(ctx, e)
Expand Down
Loading

0 comments on commit c9ae746

Please sign in to comment.