25typedef __u32 PortId_t;
26typedef __u64 Timestamp_t;
27typedef __u8 ClassOfService_t;
28typedef __u16 CloneSessionId_t;
29typedef __u32 MulticastGroup_t;
30typedef __u16 EgressInstance_t;
31typedef __u8 MirrorSlotId_t;
32typedef __u16 MirrorSessionId_t;
35typedef __u8 ParserError_t;
36static const ParserError_t NoError = 0;
37static const ParserError_t PacketTooShort = 1;
38static const ParserError_t NoMatch = 2;
39static const ParserError_t StackOutOfBounds = 3;
40static const ParserError_t HeaderTooShort = 4;
41static const ParserError_t ParserTimeout = 5;
42static const ParserError_t ParserInvalidArgument = 6;
45enum PNA_Source_t { FROM_HOST, FROM_NET };
47enum PNA_MeterColor_t { RED, GREEN, YELLOW };
49enum MirrorType { NO_MIRROR, PRE_MODIFY, POST_MODIFY };
54} __attribute__((aligned(4)));
60 Timestamp_t timestamp;
61 ParserError_t parser_error;
62 ClassOfService_t class_of_service;
64} __attribute__((aligned(4)));;
69 ClassOfService_t class_of_service;
70} __attribute__((aligned(4)));
80 enum MirrorType mirror_type;
81 MirrorSlotId_t mirror_slot_id;
82 ParserError_t parser_error;
83 MirrorSessionId_t mirror_session_id;
86} __attribute__((aligned(4)));
91 __u8 class_of_service;
93 __u16 packet_length_bytes;
94} __attribute__((aligned(4)));
96#define send_to_port(x) (compiler_meta__->egress_port = x)
97#define drop_packet() (compiler_meta__->drop = true)
104} __attribute__((preserve_access_index));
106struct __attribute__((__packed__)) p4tc_table_entry_act_bpf {
109 is_default_miss_act:1,
110 is_default_hit_act:1;
119extern struct p4tc_table_entry_act_bpf *bpf_p4tc_tbl_read(
121 const u32 key__sz) __ksym;
122extern struct p4tc_table_entry_act_bpf *bpf_xdp_p4tc_tbl_lookup(
124 const u32 key__sz) __ksym;
128bpf_p4tc_entry_create(
struct __sk_buff *skb_ctx,
130 void *key,
const u32 key__sz,
131 struct p4tc_table_entry_act_bpf *act_bpf) __ksym;
134xdp_p4tc_entry_create(
struct xdp_md *xdp_ctx,
136 void *bpf_key_mask, u32 bpf_key_mask__sz,
137 struct p4tc_table_entry_act_bpf *act_bpf) __ksym;
141bpf_p4tc_entry_create_on_miss(
struct __sk_buff *skb_ctx,
143 void *key,
const u32 key__sz,
144 struct p4tc_table_entry_act_bpf *act_bpf) __ksym;
147xdp_p4tc_entry_create_on_miss(
struct xdp_md *xdp_ctx,
149 void *key,
const u32 key__sz,
150 struct p4tc_table_entry_act_bpf *act_bpf) __ksym;
154bpf_p4tc_entry_update(
struct __sk_buff *skb_ctx,
156 void *key,
const u32 key__sz,
157 struct p4tc_table_entry_act_bpf *act_bpf) __ksym;
160xdp_p4tc_entry_update(
struct xdp_md *xdp_ctx,
162 void *key,
const u32 key__sz,
163 struct p4tc_table_entry_act_bpf *act_bpf) __ksym;
167bpf_p4tc_entry_delete(
struct __sk_buff *skb_ctx,
169 void *key,
const u32 key__sz) __ksym;
172xdp_p4tc_entry_delete(
struct xdp_md *xdp_ctx,
174 void *key,
const u32 key__sz) __ksym;
182struct __attribute__((__packed__)) p4tc_ext_bpf_res {
189bpf_p4tc_extern_indirect_count_pktsnbytes(
struct __sk_buff *skb_ctx,
191 struct p4tc_ext_bpf_res *res) __ksym;
194bpf_p4tc_extern_indirect_count_pktsonly(
struct __sk_buff *skb_ctx,
196 struct p4tc_ext_bpf_res *res) __ksym;
199bpf_p4tc_extern_indirect_count_bytesonly(
struct __sk_buff *skb_ctx,
201 struct p4tc_ext_bpf_res *res) __ksym;
204xdp_p4tc_extern_indirect_count_pktsnbytes(
struct xdp_md *xdp_ctx,
206 struct p4tc_ext_bpf_res *res) __ksym;
209xdp_p4tc_extern_indirect_count_pktsonly(
struct xdp_md *xdp_ctx,
211 struct p4tc_ext_bpf_res *res) __ksym;
214xdp_p4tc_extern_indirect_count_bytesonly(
struct xdp_md *xdp_ctx,
216 struct p4tc_ext_bpf_res *res) __ksym;
218extern int bpf_p4tc_extern_meter_bytes_color(
struct __sk_buff *skb_ctx,
220 struct p4tc_ext_bpf_res *res,
223extern int bpf_p4tc_extern_meter_bytes(
struct __sk_buff *skb_ctx,
225 struct p4tc_ext_bpf_res *res) __ksym;
227extern int bpf_p4tc_extern_meter_pkts_color(
struct __sk_buff *skb_ctx,
229 struct p4tc_ext_bpf_res *res,
232extern int xdp_p4tc_extern_meter_pkts(
struct xdp_md *xdp_ctx,
234 struct p4tc_ext_bpf_res *res) __ksym;
236extern int xdp_p4tc_extern_meter_bytes_color(
struct xdp_md *xdp_ctx,
238 struct p4tc_ext_bpf_res *res,
241extern int xdp_p4tc_extern_meter_bytes(
struct xdp_md *xdp_ctx,
243 struct p4tc_ext_bpf_res *res) __ksym;
245extern int xdp_p4tc_extern_meter_pkts_color(
struct xdp_md *xdp_ctx,
247 struct p4tc_ext_bpf_res *res,
250extern int xdp_p4tc_extern_meter_pkts(
struct xdp_md *xdp_ctx,
252 struct p4tc_ext_bpf_res *res) __ksym;
263 const void *data,
const u32 data__sz) __ksym;
275 const void *data,
const u32 data__sz) __ksym;
289 const void *data,
int len) __ksym;
293 const void *data,
const u32 data__sz) __ksym;
304bpf_p4tc_ext_hash_crc16(
const void *data,
int len, u16 seed) __ksym;
308bpf_p4tc_ext_hash_base_crc16(
const void *data,
const u32 data__sz,
309 u32 base, u32 max, u16 seed) {
310 u16 hash = bpf_p4tc_ext_hash_crc16(data, data__sz, seed);
312 return (base + (hash % max));
317bpf_p4tc_ext_hash_crc32(
const void *data,
const u32 data__sz, u32 seed) __ksym;
321bpf_p4tc_ext_hash_base_crc32(
const void *data,
const u32 data__sz,
322 u32 base, u32 max, u32 seed) {
323 u32 hash = bpf_p4tc_ext_hash_crc32(data, data__sz, seed);
325 return (base + (hash % max));
330bpf_p4tc_ext_hash_16bit_complement(
const void *data,
const u32 data__sz,
335bpf_p4tc_ext_hash_base_16bit_complement(
const void *data,
const u32 data__sz,
336 u32 base, u32 max, u16 seed) {
337 u16 hash = bpf_p4tc_ext_hash_16bit_complement(data, data__sz, seed);
339 return (base + (hash % max));
344extern struct p4tc_ext_bpf_res *
345bpf_skb_p4tc_run_extern(
struct __sk_buff *skb,
347extern struct p4tc_ext_bpf_res *
348bpf_xdp_p4tc_run_extern(
struct xdp_md *skb,
364#define EXTERN_IS_NET_PORT 1234
365#define EXTERN_IS_HOST_PORT 4567
367static bool is_net_port_skb(
struct __sk_buff *skb, u32 ifindex)
370 u32 *index = (u32 *)param.params;
371 struct p4tc_ext_bpf_res *res;
374 param.ext_id = EXTERN_IS_NET_PORT;
377 res = bpf_skb_p4tc_run_extern(skb, ¶m);
382 direction = (u32 *)res->params;
384 return *direction == FROM_NET;
387static bool is_host_port_skb(
struct __sk_buff *skb, u32 ifindex)
390 u32 *index = (u32 *)param.params;
391 struct p4tc_ext_bpf_res *res;
394 param.ext_id = EXTERN_IS_HOST_PORT;
397 res = bpf_skb_p4tc_run_extern(skb, ¶m);
402 direction = (u32 *)res->params;
404 return *direction == FROM_HOST;
407static bool is_net_port_xdp(
struct xdp_md *skb, u32 ifindex)
410 u32 *index = (u32 *)param.params;
411 struct p4tc_ext_bpf_res *res;
414 param.ext_id = EXTERN_IS_NET_PORT;
417 res = bpf_xdp_p4tc_run_extern(skb, ¶m);
422 direction = (u32 *)res->params;
424 return *direction == FROM_NET;
427static bool is_host_port_xdp(
struct xdp_md *skb, u32 ifindex)
430 u32 *index = (u32 *)param.params;
431 struct p4tc_ext_bpf_res *res;
434 param.ext_id = EXTERN_IS_HOST_PORT;
437 res = bpf_xdp_p4tc_run_extern(skb, ¶m);
442 direction = (u32 *)res->params;
444 return *direction == FROM_HOST;
447extern int bpf_p4tc_extern_md_read(
struct __sk_buff *skb_ctx,
449 struct p4tc_ext_bpf_res *res) __ksym;
452extern int bpf_p4tc_extern_md_write(
struct __sk_buff *skb_ctx,
454 struct p4tc_ext_bpf_res *res) __ksym;
457extern int xdp_p4tc_extern_md_read(
struct xdp_md *xdp_ctx,
459 struct p4tc_ext_bpf_res *res) __ksym;
462extern int xdp_p4tc_extern_md_write(
struct xdp_md *xdp_ctx,
464 struct p4tc_ext_bpf_res *res) __ksym;
467static inline u64 bpf_p4tc_extern_timestamp() {
468 return bpf_ktime_get_ns();
471#define U32_MAX ((u32)~0U)
474static inline u32 bpf_p4tc_extern_random(u32 min, u32 max) {
476 return (min + bpf_get_prandom_u32());
478 return (min + bpf_get_prandom_u32()) % (max + 1);