39
39
#define TC_ACT_UNSPEC -1
40
40
#define AF_INET 2
41
41
#define AF_INET6 10
42
+ #define TASK_COMM_LEN 16
42
43
43
44
#define OK 1
44
45
#define NOK 0
45
46
46
47
// Map key struct for IP traffic
47
48
typedef struct statkey_t {
48
- struct in6_addr srcip ; // source IPv6 address
49
- struct in6_addr dstip ; // destination IPv6 address
50
- __u16 src_port ; // source port
51
- __u16 dst_port ; // destination port
52
- __u8 proto ; // transport protocol
53
- pid_t pid ; // process ID
49
+ struct in6_addr srcip ; // source IPv6 address
50
+ struct in6_addr dstip ; // destination IPv6 address
51
+ __u16 src_port ; // source port
52
+ __u16 dst_port ; // destination port
53
+ __u8 proto ; // transport protocol
54
+ pid_t pid ; // process ID
55
+ char comm [TASK_COMM_LEN ]; // process command
54
56
} statkey ;
55
57
56
58
// Map value struct with counters
@@ -482,8 +484,8 @@ static inline void update_val(statkey *key, size_t size) {
482
484
/**
483
485
* Hook function for kprobe on tcp_sendmsg function.
484
486
*
485
- * Populates the statkey structure with information from the socket and the
486
- * process ID associated with the socket , and updates the packet and byte
487
+ * Populates the statkey structure with information from the UDP packet and the
488
+ * process ID associated with the packet , and updates the packet and byte
487
489
* counters in the packet count map.
488
490
*
489
491
* @param sk pointer to the socket structure
@@ -500,6 +502,7 @@ int BPF_KPROBE(tcp_sendmsg, struct sock *sk, struct msghdr *msg, size_t size) {
500
502
__builtin_memset (& key , 0 , sizeof (key ));
501
503
502
504
pid_t pid = bpf_get_current_pid_tgid () & 0xFFFFFFFF ;
505
+ bpf_get_current_comm (& key .comm , sizeof (key .comm ));
503
506
504
507
process_tcp (sk , & key , pid );
505
508
update_val (& key , size );
@@ -531,6 +534,7 @@ int BPF_KPROBE(tcp_cleanup_rbuf, struct sock *sk, int copied) {
531
534
__builtin_memset (& key , 0 , sizeof (key ));
532
535
533
536
pid_t pid = bpf_get_current_pid_tgid () & 0xFFFFFFFF ;
537
+ bpf_get_current_comm (& key .comm , sizeof (key .comm ));
534
538
535
539
process_tcp (sk , & key , pid );
536
540
update_val (& key , copied );
@@ -541,12 +545,12 @@ int BPF_KPROBE(tcp_cleanup_rbuf, struct sock *sk, int copied) {
541
545
/**
542
546
* Hook function for kprobe on ip_send_skb function.
543
547
*
544
- * Populates the statkey structure with information from the UDP packet and the
545
- * process ID associated with the packet , and updates the packet and byte
548
+ * Populates the statkey structure with information from the socket and the
549
+ * process ID associated with the socket , and updates the packet and byte
546
550
* counters in the packet count map.
547
551
*
548
- * @param net pointer to the network namespace
549
- * @param skb pointer to the socket buffer containing the UDP packet
552
+ * @param net pointer to the network namespace structure
553
+ * @param skb pointer to the socket buffer
550
554
*
551
555
* @return 0
552
556
*
@@ -563,6 +567,7 @@ int BPF_KPROBE(ip_send_skb, struct net *net, struct sk_buff *skb) {
563
567
__builtin_memset (& key , 0 , sizeof (key ));
564
568
565
569
pid_t pid = bpf_get_current_pid_tgid () & 0xFFFFFFFF ;
570
+ bpf_get_current_comm (& key .comm , sizeof (key .comm ));
566
571
567
572
size_t msglen = process_udp_send (skb , & key , pid );
568
573
update_val (& key , msglen );
@@ -591,6 +596,7 @@ int BPF_KPROBE(skb_consume_udp, struct sock *sk, struct sk_buff *skb, int len) {
591
596
__builtin_memset (& key , 0 , sizeof (key ));
592
597
593
598
pid_t pid = bpf_get_current_pid_tgid () & 0xFFFFFFFF ;
599
+ bpf_get_current_comm (& key .comm , sizeof (key .comm ));
594
600
595
601
process_udp_recv (skb , & key , pid );
596
602
update_val (& key , len );
0 commit comments