11#ifndef _H_BPF_SKB_UTILS
22#define _H_BPF_SKB_UTILS
33
4+ /* This file can only be used in eBPF program, can't be used in user space
5+ * code.
6+ */
7+
48#include "macro.h"
5- #include "packet.h"
9+ #include "skb_shared.h"
10+
11+ typedef struct {
12+ pkt_args_t pkt ;
13+ #ifdef DEFINE_BPF_ARGS
14+ DEFINE_BPF_ARGS ( );
15+ #endif
16+ } bpf_args_t ;
617
718struct {
819 __uint (type , BPF_MAP_TYPE_PERF_EVENT_ARRAY );
@@ -22,12 +33,11 @@ struct {
2233 tmp; \
2334})
2435
25- struct bpf_args ;
2636#ifdef MAP_CONFIG
2737struct {
2838 __uint (type , BPF_MAP_TYPE_ARRAY );
2939 __uint (key_size , sizeof (int ));
30- __uint (value_size , CONFIG_MAP_SIZE );
40+ __uint (value_size , sizeof ( bpf_args_t ) );
3141 __uint (max_entries , 1 );
3242} m_config SEC (".maps" );
3343
@@ -36,12 +46,12 @@ struct {
3646 void * _v = bpf_map_lookup_elem(&m_config, &_key); \
3747 if (!_v) \
3848 return 0; /* this can't happen */ \
39- (struct bpf_args * )_v ; \
49+ (bpf_args_t * )_v ; \
4050})
4151
4252#define try_inline __attribute__((always_inline))
4353#else
44- extern struct bpf_args _bpf_args ;
54+ bpf_args_t _bpf_args ;
4555#define CONFIG () &_bpf_args
4656#define try_inline inline
4757#endif
@@ -51,7 +61,7 @@ extern struct bpf_args _bpf_args;
5161
5262#define ARGS_ENABLED (name ) bpf_args->enable_##name
5363#define ARGS_GET (name ) bpf_args->name
54- #define ARGS_GET_CONFIG (name ) ((struct bpf_args *)CONFIG())->name
64+ #define ARGS_GET_CONFIG (name ) ((bpf_args_t *)CONFIG())->name
5565#define ARGS_CHECK (name , val ) \
5666 (ARGS_ENABLED(name) && bpf_args->name != (val))
5767
@@ -137,10 +147,9 @@ static try_inline bool skb_l4_check(u16 l4, u16 l3)
137147 return l4 == 0xFFFF || l4 <= l3 ;
138148}
139149
140- #define CHECK_ATTR (attr ) \
141- ((ARGS_CHECK(attr, d##attr) && \
142- ARGS_CHECK(attr, s##attr)) || \
143- ARGS_CHECK(s##attr, s##attr) || \
150+ #define CHECK_ATTR (attr ) \
151+ ((ARGS_CHECK(attr, d##attr) && ARGS_CHECK(attr, s##attr)) || \
152+ ARGS_CHECK(s##attr, s##attr) || \
144153 ARGS_CHECK(d##attr, d##attr))
145154
146155static try_inline int probe_parse_ip (void * ip , parse_ctx_t * ctx )
@@ -299,7 +308,7 @@ static try_inline int probe_parse_skb(struct sk_buff *skb, packet_t *pkt)
299308}
300309
301310static try_inline int probe_parse_skb_no_filter (struct sk_buff * skb ,
302- packet_t * pkt )
311+ packet_t * pkt )
303312{
304313 parse_ctx_t ctx = {
305314 .args = (void * )CONFIG (),
@@ -379,4 +388,4 @@ static try_inline int direct_parse_skb(struct __sk_buff *skb, packet_t *pkt,
379388 return 1 ;
380389}
381390
382- #endif
391+ #endif
0 commit comments