// SPDX-License-Identifier: GPL-2.0-only1/*2* Minimal BPF assembler3*4* Instead of libpcap high-level filter expressions, it can be quite5* useful to define filters in low-level BPF assembler (that is kept6* close to Steven McCanne and Van Jacobson's original BPF paper).7* In particular for BPF JIT implementors, JIT security auditors, or8* just for defining BPF expressions that contain extensions which are9* not supported by compilers.10*11* How to get into it:12*13* 1) read Documentation/networking/filter.rst14* 2) Run `bpf_asm [-c] <filter-prog file>` to translate into binary15* blob that is loadable with xt_bpf, cls_bpf et al. Note: -c will16* pretty print a C-like construct.17*18* Copyright 2013 Daniel Borkmann <[email protected]>19*/2021#include <stdbool.h>22#include <stdio.h>23#include <string.h>2425extern void bpf_asm_compile(FILE *fp, bool cstyle);2627int main(int argc, char **argv)28{29FILE *fp = stdin;30bool cstyle = false;31int i;3233for (i = 1; i < argc; i++) {34if (!strncmp("-c", argv[i], 2)) {35cstyle = true;36continue;37}3839fp = fopen(argv[i], "r");40if (!fp) {41fp = stdin;42continue;43}4445break;46}4748bpf_asm_compile(fp, cstyle);4950return 0;51}525354