github.com/kubearmor/cilium@v1.6.12/contrib/codegen/hexgen.c (about)

     1  #include <stdio.h>
     2  #include <linux/pkt_cls.h>
     3  #include <linux/types.h>
     4  #include "hexgen.h"
     5  
     6  int main(void)
     7  {
     8  	struct bpf_insn	insns[] = {
     9  		BPF_LD_MAP_FD(BPF_REG_2, 0xebebebeb),
    10  		BPF_MOV64_IMM(BPF_REG_3, 0),
    11  		BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
    12  			     BPF_FUNC_tail_call),
    13  		BPF_MOV64_IMM(BPF_REG_0, TC_ACT_OK),
    14  		BPF_EXIT_INSN(),
    15  	};
    16  	__u8 *raw = (void *)insns;
    17  	int i;
    18  
    19  	for (i = 1; i <= sizeof(insns); i++) {
    20  		printf("0x%02x, ", raw[i - 1]);
    21  		if (i % 8 == 0)
    22  			printf("\n");
    23  	}
    24  	printf("\n");
    25  	return 0;
    26  }