mirror of
https://github.com/torvalds/linux.git
synced 2024-11-23 04:31:50 +00:00
a7d7a39274
Based on 1 normalized pattern(s): licensed under the gnu general public license version 2 0 gplv2 extracted by the scancode license scanner the SPDX license identifier GPL-2.0-only has been chosen to replace the boilerplate/reference in 3 file(s). Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Armijn Hemel <armijn@tjaldur.nl> Reviewed-by: Alexios Zavras <alexios.zavras@intel.com> Reviewed-by: Allison Randal <allison@lohutok.net> Reviewed-by: Enrico Weigelt <info@metux.net> Cc: linux-spdx@vger.kernel.org Link: https://lkml.kernel.org/r/20190602204653.630925848@linutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
53 lines
1.2 KiB
C
53 lines
1.2 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Minimal BPF assembler
|
|
*
|
|
* Instead of libpcap high-level filter expressions, it can be quite
|
|
* useful to define filters in low-level BPF assembler (that is kept
|
|
* close to Steven McCanne and Van Jacobson's original BPF paper).
|
|
* In particular for BPF JIT implementors, JIT security auditors, or
|
|
* just for defining BPF expressions that contain extensions which are
|
|
* not supported by compilers.
|
|
*
|
|
* How to get into it:
|
|
*
|
|
* 1) read Documentation/networking/filter.txt
|
|
* 2) Run `bpf_asm [-c] <filter-prog file>` to translate into binary
|
|
* blob that is loadable with xt_bpf, cls_bpf et al. Note: -c will
|
|
* pretty print a C-like construct.
|
|
*
|
|
* Copyright 2013 Daniel Borkmann <borkmann@redhat.com>
|
|
*/
|
|
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
extern void bpf_asm_compile(FILE *fp, bool cstyle);
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
FILE *fp = stdin;
|
|
bool cstyle = false;
|
|
int i;
|
|
|
|
for (i = 1; i < argc; i++) {
|
|
if (!strncmp("-c", argv[i], 2)) {
|
|
cstyle = true;
|
|
continue;
|
|
}
|
|
|
|
fp = fopen(argv[i], "r");
|
|
if (!fp) {
|
|
fp = stdin;
|
|
continue;
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
bpf_asm_compile(fp, cstyle);
|
|
|
|
return 0;
|
|
}
|