Skip to content

Commit 6dd4b43

Browse files
dilyevskyclaude
andcommitted
[tunnel] filter out ping packets from TUI traffic view by default
BFD keepalive packets create noise in the traffic panel. Hide them by default and add a 'p' key toggle to show/hide them. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0187328 commit 6dd4b43

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

pkg/cmd/tunnel/tui/keys.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type keyMap struct {
1212
FilterUDP key.Binding
1313
FilterICMP key.Binding
1414
FilterAll key.Binding
15+
ToggleBFD key.Binding
1516
Clear key.Binding
1617
}
1718

@@ -25,17 +26,18 @@ var DefaultKeyMap = keyMap{
2526
FilterUDP: key.NewBinding(key.WithKeys("u"), key.WithHelp("u", "UDP")),
2627
FilterICMP: key.NewBinding(key.WithKeys("i"), key.WithHelp("i", "ICMP")),
2728
FilterAll: key.NewBinding(key.WithKeys("a"), key.WithHelp("a", "all")),
29+
ToggleBFD: key.NewBinding(key.WithKeys("p"), key.WithHelp("p", "toggle pings")),
2830
Clear: key.NewBinding(key.WithKeys("c"), key.WithHelp("c", "clear")),
2931
}
3032

3133
func (k keyMap) ShortHelp() []key.Binding {
32-
return []key.Binding{k.FilterTCP, k.FilterUDP, k.FilterICMP, k.FilterAll, k.Clear, k.Quit}
34+
return []key.Binding{k.FilterTCP, k.FilterUDP, k.FilterICMP, k.FilterAll, k.ToggleBFD, k.Clear, k.Quit}
3335
}
3436

3537
func (k keyMap) FullHelp() [][]key.Binding {
3638
return [][]key.Binding{
3739
{k.ScrollUp, k.ScrollDown, k.Top, k.Bottom},
38-
{k.FilterTCP, k.FilterUDP, k.FilterICMP, k.FilterAll},
40+
{k.FilterTCP, k.FilterUDP, k.FilterICMP, k.FilterAll, k.ToggleBFD},
3941
{k.Clear, k.Quit},
4042
}
4143
}

pkg/cmd/tunnel/tui/model.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
9797
m.traffic.SetFilter(panels.FilterAll)
9898
return m, nil
9999

100+
case key.Matches(msg, m.keys.ToggleBFD):
101+
m.traffic.ToggleBFD()
102+
return m, nil
103+
100104
case key.Matches(msg, m.keys.Clear):
101105
m.traffic.Clear()
102106
return m, nil

pkg/cmd/tunnel/tui/panels/help.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func (p HelpPanel) View() string {
3535
HelpStyle.Render("u") + DimStyle.Render(":UDP"),
3636
HelpStyle.Render("i") + DimStyle.Render(":ICMP"),
3737
HelpStyle.Render("a") + DimStyle.Render(":all"),
38+
HelpStyle.Render("p") + DimStyle.Render(":pings"),
3839
HelpStyle.Render("c") + DimStyle.Render(":clear"),
3940
HelpStyle.Render("q") + DimStyle.Render(":quit"),
4041
}

pkg/cmd/tunnel/tui/panels/traffic.go

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
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.
7695
func (p *TrafficPanel) ScrollUp() {
7796
p.autoTail = false
@@ -121,13 +140,18 @@ func (p *TrafficPanel) visibleLines() int {
121140
}
122141

123142
func (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.
149173
func (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

Comments
 (0)