Skip to content

Commit b153ba3

Browse files
committed
Counter and TUI improvements
1 parent 2b3c17a commit b153ba3

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

counter.c

+15-10
Original file line numberDiff line numberDiff line change
@@ -744,21 +744,25 @@ int BPF_KPROBE(skb_consume_udp, struct sock *sk, struct sk_buff *skb, int len) {
744744
}
745745

746746
/**
747-
* Hook function for kprobe on icmp_send function.
747+
* Hook function for kprobe on __icmp_send function.
748748
*
749-
* Populates the statkey structure with information from the ICMP packet and
749+
* Populates the statkey structure with information from the ICMPv4 packet and
750750
* the process ID associated with the packet, and updates the packet and byte
751751
* counters in the packet count map.
752752
*
753-
* @param skb pointer to the socket buffer containing the ICMP packet
754-
* @param type type of ICMP packet
753+
* @param skb pointer to the socket buffer containing the ICMPv4 packet
754+
* @param type type of ICMPv4 packet
755+
* @param code code of ICMPv4 packet
756+
* @param info additional information for the ICMPv4 packet
757+
* @param opt pointer to the ip_options structure
755758
*
756759
* @return 0
757760
*
758761
* @throws none
759762
*/
760763
SEC("kprobe/__icmp_send")
761-
int BPF_KPROBE(__icmp_send, struct sk_buff *skb, int type) {
764+
int BPF_KPROBE(__icmp_send, struct sk_buff *skb, __u8 type, __u8 code,
765+
__be32 info, const struct ip_options *opt) {
762766
statkey key;
763767
__builtin_memset(&key, 0, sizeof(key));
764768

@@ -782,13 +786,16 @@ int BPF_KPROBE(__icmp_send, struct sk_buff *skb, int type) {
782786
*
783787
* @param skb pointer to the socket buffer containing the ICMPv6 packet
784788
* @param type type of ICMPv6 packet
789+
* @param code code of ICMPv6 packet
790+
* @param info additional information for the ICMPv6 packet
785791
*
786792
* @return 0
787793
*
788794
* @throws none
789795
*/
790796
SEC("kprobe/icmp6_send")
791-
int BPF_KPROBE(icmp6_send, struct sk_buff *skb, int type) {
797+
int BPF_KPROBE(icmp6_send, struct sk_buff *skb, __u8 type, __u8 code,
798+
__u32 info) {
792799
statkey key;
793800
__builtin_memset(&key, 0, sizeof(key));
794801

@@ -811,14 +818,13 @@ int BPF_KPROBE(icmp6_send, struct sk_buff *skb, int type) {
811818
* counters in the packet count map.
812819
*
813820
* @param skb pointer to the socket buffer containing the ICMP packet
814-
* @param type type of ICMP packet
815821
*
816822
* @return 0
817823
*
818824
* @throws none
819825
*/
820826
SEC("kprobe/icmp_rcv")
821-
int BPF_KPROBE(icmp_rcv, struct sk_buff *skb, int type) {
827+
int BPF_KPROBE(icmp_rcv, struct sk_buff *skb) {
822828
statkey key;
823829
__builtin_memset(&key, 0, sizeof(key));
824830

@@ -841,14 +847,13 @@ int BPF_KPROBE(icmp_rcv, struct sk_buff *skb, int type) {
841847
* counters in the packet count map.
842848
*
843849
* @param skb pointer to the socket buffer containing the ICMPv6 packet
844-
* @param type type of ICMPv6 packet
845850
*
846851
* @return 0
847852
*
848853
* @throws none
849854
*/
850855
SEC("kprobe/icmpv6_rcv")
851-
int BPF_KPROBE(icmpv6_rcv, struct sk_buff *skb, int type) {
856+
int BPF_KPROBE(icmpv6_rcv, struct sk_buff *skb) {
852857
statkey key;
853858
__builtin_memset(&key, 0, sizeof(key));
854859

main.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func main() {
8787
links = startXDP(objs, iface, links)
8888
// TC
8989
default:
90-
startTC(objs, iface, links)
90+
links = startTC(objs, iface, links)
9191
}
9292

9393
c1, cancel := context.WithCancel(context.Background())
@@ -108,6 +108,8 @@ func main() {
108108
}()
109109

110110
if *timeout > 0 {
111+
log.Printf("Listening for %v before exiting", durafmt.Parse(*timeout))
112+
111113
go func() {
112114
time.Sleep(*timeout)
113115
cancel()
@@ -173,8 +175,7 @@ func startKProbes(hooks []kprobeHook, links []link.Link) []link.Link {
173175
links = append(links, l)
174176
}
175177

176-
log.Printf("Using KProbes mode w/ PID tracking, listening for %v",
177-
durafmt.Parse(*timeout))
178+
log.Printf("Using KProbes mode w/ PID/comm tracking")
178179

179180
return links
180181
}
@@ -222,9 +223,9 @@ func startXDP(objs counterObjects, iface *net.Interface, links []link.Link) []li
222223

223224
links = append(links, l)
224225

225-
log.Printf("Starting on interface %q using XDP (eXpress Data Path) eBPF mode, listening for %v",
226-
*ifname, durafmt.Parse(*timeout))
226+
log.Printf("Starting on interface %q using XDP (eXpress Data Path) eBPF mode", *ifname)
227227
log.Printf("Due to XDP mode, egress statistics are not available. Upon program exit, interface reset may happen on some cards.")
228+
228229
return links
229230
}
230231

@@ -247,7 +248,7 @@ func startXDP(objs counterObjects, iface *net.Interface, links []link.Link) []li
247248
//
248249
// []link.Link: The updated slice of link.Link objects, now including the newly
249250
// attached TC links.
250-
func startTC(objs counterObjects, iface *net.Interface, links []link.Link) {
251+
func startTC(objs counterObjects, iface *net.Interface, links []link.Link) []link.Link {
251252
var l link.Link
252253

253254
err := features.HaveProgramType(ebpf.SchedACT)
@@ -284,6 +285,7 @@ func startTC(objs counterObjects, iface *net.Interface, links []link.Link) {
284285

285286
links = append(links, l)
286287

287-
log.Printf("Starting on interface %q using TC (Traffic Control) eBPF mode, listening for %v",
288-
*ifname, durafmt.Parse(*timeout))
288+
log.Printf("Starting on interface %q using TC (Traffic Control) eBPF mode", *ifname)
289+
290+
return links
289291
}

tui.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func drawTUI(objs counterObjects, startTime time.Time) {
9090
// navigation
9191
naviView := tview.NewTextView().
9292
SetTextColor(tcell.ColorYellow)
93-
naviView.SetText("Press 'q' or 'x' to exit. Press 'r' or 'l' for a redraw.")
93+
naviView.SetText("Use cursor keys to move through the table. Press 'q' or 'x' to exit. Press 'r' or 'l' for a redraw.")
9494

9595
// grid layout
9696
grid := tview.NewGrid().SetRows(2, 0, 2).

0 commit comments

Comments
 (0)