66
77 "github.com/charmbracelet/lipgloss"
88
9+ "github.com/apoxy-dev/apoxy/pkg/tunnel/bfdl"
910 "github.com/apoxy-dev/apoxy/pkg/tunnel/connection"
1011)
1112
@@ -27,6 +28,7 @@ type TrafficPanel struct {
2728 height int
2829 packets []connection.PacketInfo
2930 filter ProtocolFilter
31+ hideBFD bool // hide BFD control packets (UDP port 3784)
3032 scrollY int
3133 autoTail bool // auto-scroll to bottom
3234}
@@ -36,6 +38,7 @@ func NewTrafficPanel() TrafficPanel {
3638 return TrafficPanel {
3739 packets : make ([]connection.PacketInfo , 0 , maxPackets ),
3840 filter : FilterAll ,
41+ hideBFD : true ,
3942 autoTail : true ,
4043 }
4144}
@@ -72,6 +75,22 @@ func (p *TrafficPanel) SetFilter(f ProtocolFilter) {
7275 p .scrollY = 0
7376}
7477
78+ // ToggleBFD toggles visibility of BFD control packets.
79+ func (p * TrafficPanel ) ToggleBFD () {
80+ p .hideBFD = ! p .hideBFD
81+ p .scrollY = 0
82+ }
83+
84+ // HideBFD returns whether BFD packets are currently hidden.
85+ func (p * TrafficPanel ) HideBFD () bool {
86+ return p .hideBFD
87+ }
88+
89+ func isBFDPacket (pkt connection.PacketInfo ) bool {
90+ return pkt .Protocol == connection .ProtocolUDP &&
91+ (pkt .SrcPort == bfdl .BFDPort || pkt .DstPort == bfdl .BFDPort )
92+ }
93+
7594// ScrollUp scrolls up by one line.
7695func (p * TrafficPanel ) ScrollUp () {
7796 p .autoTail = false
@@ -121,13 +140,18 @@ func (p *TrafficPanel) visibleLines() int {
121140}
122141
123142func (p * TrafficPanel ) filteredPackets () []connection.PacketInfo {
124- if p .filter == FilterAll {
143+ if p .filter == FilterAll && ! p . hideBFD {
125144 return p .packets
126145 }
127146
128147 var result []connection.PacketInfo
129148 for _ , pkt := range p .packets {
149+ if p .hideBFD && isBFDPacket (pkt ) {
150+ continue
151+ }
130152 switch p .filter {
153+ case FilterAll :
154+ result = append (result , pkt )
131155 case FilterTCP :
132156 if pkt .Protocol == connection .ProtocolTCP {
133157 result = append (result , pkt )
@@ -147,16 +171,21 @@ func (p *TrafficPanel) filteredPackets() []connection.PacketInfo {
147171
148172// FilterName returns the name of the current filter.
149173func (p * TrafficPanel ) FilterName () string {
174+ var name string
150175 switch p .filter {
151176 case FilterTCP :
152- return "TCP"
177+ name = "TCP"
153178 case FilterUDP :
154- return "UDP"
179+ name = "UDP"
155180 case FilterICMP :
156- return "ICMP"
181+ name = "ICMP"
157182 default :
158- return "all"
183+ name = "all"
184+ }
185+ if p .hideBFD {
186+ name += ", no pings"
159187 }
188+ return name
160189}
161190
162191// View renders the traffic panel.
0 commit comments