77#ifndef _H_BPF_SKB_UTILS
88#define _H_BPF_SKB_UTILS
99
10+ #include <kheaders.h>
11+ #include <bpf/bpf_helpers.h>
12+ #include <bpf/bpf_endian.h>
13+ #include <bpf/bpf_tracing.h>
1014#include <bpf/bpf_core_read.h>
1115
1216#include "skb_macro.h"
@@ -46,6 +50,7 @@ const volatile bool bpf_func_exist[BPF_LOCAL_FUNC_MAX] = {0};
4650#endif
4751
4852#define skb_cb (__skb ) ((void *)(__skb) + bpf_core_field_offset(typeof(*__skb), cb))
53+ #define __ptr (a ) ((void *)(a))
4954
5055#define CONFIG () ({ \
5156 int _key = 0; \
@@ -439,7 +444,7 @@ static inline int probe_parse_sk(struct sock *sk, sock_t *ske,
439444
440445 switch (l4_proto ) {
441446 case IPPROTO_TCP : {
442- struct tcp_sock * tp = ( void * ) sk ;
447+ struct tcp_sock * tp = __ptr ( sk ) ;
443448
444449 if (bpf_core_type_exists (struct tcp_sock )) {
445450 ske -> l4 .tcp .packets_out = _C (tp , packets_out );
@@ -472,7 +477,7 @@ static inline int probe_parse_sk(struct sock *sk, sock_t *ske,
472477 if (!bpf_core_type_exists (struct inet_connection_sock ))
473478 return 0 ;
474479
475- icsk = ( void * ) sk ;
480+ icsk = __ptr ( sk ) ;
476481 bpf_probe_read_kernel (& ske -> ca_state , sizeof (u8 ),
477482 (u8 * )icsk +
478483 bpf_core_field_offset (struct inet_connection_sock ,
@@ -566,7 +571,7 @@ static inline int probe_parse_skb_sk(struct sock *sk, struct sk_buff *skb,
566571 /* parse L4 information from the socket */
567572 switch (l4_proto ) {
568573 case IPPROTO_TCP : {
569- struct tcp_sock * tp = ( void * ) sk ;
574+ struct tcp_sock * tp = __ptr ( sk ) ;
570575 struct tcp_skb_cb * cb ;
571576
572577 cb = skb_cb (skb );
@@ -664,7 +669,7 @@ static __always_inline int probe_parse_skb(struct sk_buff *skb, struct sock *sk,
664669 /* mac header is set properly, we can use it directly. */
665670 struct ethhdr * eth = ctx -> data + ctx -> mac_header ;
666671
667- l3 = ( void * ) eth + ETH_HLEN ;
672+ l3 = __ptr ( eth ) + ETH_HLEN ;
668673 l3_proto = bpf_ntohs (_ (eth -> h_proto ));
669674 }
670675
@@ -697,9 +702,9 @@ static inline int direct_parse_skb(struct __sk_buff *skb, packet_t *pkt,
697702 pkt_args_t * bpf_args )
698703{
699704 struct ethhdr * eth = SKB_DATA (skb );
700- struct iphdr * ip = ( void * ) (eth + 1 );
705+ struct iphdr * ip = __ptr (eth + 1 );
701706
702- if (( void * ) ip > SKB_END (skb ))
707+ if (__ptr ( ip ) > SKB_END (skb ))
703708 goto err ;
704709
705710 if (bpf_args && args_check (bpf_args , l3_proto , eth -> h_proto ))
@@ -714,8 +719,8 @@ static inline int direct_parse_skb(struct __sk_buff *skb, packet_t *pkt,
714719 args_check (bpf_args , daddr , ip -> daddr )))
715720 goto err ;
716721
717- l4_min_t * l4_p = ( void * ) (ip + 1 );
718- struct tcphdr * tcp = ( void * ) l4_p ;
722+ l4_min_t * l4_p = __ptr (ip + 1 );
723+ struct tcphdr * tcp = __ptr ( l4_p ) ;
719724
720725 switch (ip -> protocol ) {
721726 case IPPROTO_UDP :
@@ -733,7 +738,7 @@ static inline int direct_parse_skb(struct __sk_buff *skb, packet_t *pkt,
733738 pkt -> l4 .min = * l4_p ;
734739 break ;
735740 case IPPROTO_ICMP : {
736- struct icmphdr * icmp = ( void * ) l4_p ;
741+ struct icmphdr * icmp = __ptr ( l4_p ) ;
737742 if (SKB_CHECK_ICMP (skb ))
738743 goto err ;
739744
0 commit comments