/* * BPF asm code parser * * This program is free software; you can distribute it and/or modify * it under the terms of the GNU General Public License as published * by the Free Software Foundation; either version 2 of the License, * or (at your option) any later version. * * Syntax kept close to: * * Steven McCanne and Van Jacobson. 1993. The BSD packet filter: a new * architecture for user-level packet capture. In Proceedings of the * USENIX Winter 1993 Conference Proceedings on USENIX Winter 1993 * Conference Proceedings (USENIX'93). USENIX Association, Berkeley, * CA, USA, 2-2. * * Copyright 2013 Daniel Borkmann * Licensed under the GNU General Public License, version 2.0 (GPLv2) */ %{ #include #include #include #include #include #include #include #include #include #include "bpf_exp.yacc.h" enum jmp_type { JTL, JFL, JKL }; extern FILE *yyin; extern int yylex(void); extern void yyerror(const char *str); extern void bpf_asm_compile(FILE *fp, bool cstyle); static void bpf_set_curr_instr(uint16_t op, uint8_t jt, uint8_t jf, uint32_t k); static void bpf_set_curr_label(char *label); static void bpf_set_jmp_label(char *label, enum jmp_type type); %} %union { char *label; uint32_t number; } %token OP_LDB OP_LDH OP_LD OP_LDX OP_ST OP_STX OP_JMP OP_JEQ OP_JGT OP_JGE %token OP_JSET OP_ADD OP_SUB OP_MUL OP_DIV OP_AND OP_OR OP_XOR OP_LSH OP_RSH %token OP_RET OP_TAX OP_TXA OP_LDXB OP_MOD OP_NEG OP_JNEQ OP_JLT OP_JLE OP_LDI %token OP_LDXI %token K_PKT_LEN K_PROTO K_TYPE K_NLATTR K_NLATTR_NEST K_MARK K_QUEUE K_HATYPE %token K_RXHASH K_CPU K_IFIDX K_VLANT K_VLANP K_POFF K_RAND %token ':' ',' '[' ']' '(' ')' 'x' 'a' '+' 'M' '*' '&' '#' '%' %token number label %type