Lines Matching refs:cstate
439 bpf_set_error(compiler_state_t *cstate, const char *fmt, ...) in bpf_set_error() argument
452 if (!cstate->error_set) { in bpf_set_error()
454 (void)vsnprintf(cstate->bpf_pcap->errbuf, PCAP_ERRBUF_SIZE, in bpf_set_error()
457 cstate->error_set = 1; in bpf_set_error()
469 bpf_error(compiler_state_t *cstate, const char *fmt, ...) in bpf_error() argument
474 (void)vsnprintf(cstate->bpf_pcap->errbuf, PCAP_ERRBUF_SIZE, in bpf_error()
477 longjmp(cstate->top_ctx, 1); in bpf_error()
490 static void initchunks(compiler_state_t *cstate);
491 static void *newchunk_nolongjmp(compiler_state_t *cstate, size_t);
492 static void *newchunk(compiler_state_t *cstate, size_t);
493 static void freechunks(compiler_state_t *cstate);
494 static inline struct block *new_block(compiler_state_t *cstate, int);
495 static inline struct slist *new_stmt(compiler_state_t *cstate, int);
496 static struct block *gen_retblk(compiler_state_t *cstate, int);
497 static inline void syntax(compiler_state_t *cstate);
591 static struct block *gen_geneve_ll_check(compiler_state_t *cstate);
600 initchunks(compiler_state_t *cstate) in initchunks() argument
605 cstate->chunks[i].n_left = 0; in initchunks()
606 cstate->chunks[i].m = NULL; in initchunks()
608 cstate->cur_chunk = 0; in initchunks()
612 newchunk_nolongjmp(compiler_state_t *cstate, size_t n) in newchunk_nolongjmp() argument
621 cp = &cstate->chunks[cstate->cur_chunk]; in newchunk_nolongjmp()
624 k = ++cstate->cur_chunk; in newchunk_nolongjmp()
626 bpf_set_error(cstate, "out of memory"); in newchunk_nolongjmp()
632 bpf_set_error(cstate, "out of memory"); in newchunk_nolongjmp()
638 bpf_set_error(cstate, "out of memory"); in newchunk_nolongjmp()
647 newchunk(compiler_state_t *cstate, size_t n) in newchunk() argument
651 p = newchunk_nolongjmp(cstate, n); in newchunk()
653 longjmp(cstate->top_ctx, 1); in newchunk()
660 freechunks(compiler_state_t *cstate) in freechunks() argument
665 if (cstate->chunks[i].m != NULL) in freechunks()
666 free(cstate->chunks[i].m); in freechunks()
676 sdup(compiler_state_t *cstate, const char *s) in sdup() argument
679 char *cp = newchunk_nolongjmp(cstate, n); in sdup()
688 new_block(compiler_state_t *cstate, int code) in new_block() argument
692 p = (struct block *)newchunk(cstate, sizeof(*p)); in new_block()
700 new_stmt(compiler_state_t *cstate, int code) in new_stmt() argument
704 p = (struct slist *)newchunk(cstate, sizeof(*p)); in new_stmt()
711 gen_retblk_internal(compiler_state_t *cstate, int v) in gen_retblk_internal() argument
713 struct block *b = new_block(cstate, BPF_RET|BPF_K); in gen_retblk_internal()
720 gen_retblk(compiler_state_t *cstate, int v) in gen_retblk() argument
722 if (setjmp(cstate->top_ctx)) { in gen_retblk()
732 return gen_retblk_internal(cstate, v); in gen_retblk()
736 syntax(compiler_state_t *cstate) in syntax() argument
738 bpf_error(cstate, "syntax error in filter expression"); in syntax()
748 compiler_state_t cstate; in pcap_compile() local
792 initchunks(&cstate); in pcap_compile()
793 cstate.no_optimize = 0; in pcap_compile()
795 cstate.ai = NULL; in pcap_compile()
797 cstate.e = NULL; in pcap_compile()
798 cstate.ic.root = NULL; in pcap_compile()
799 cstate.ic.cur_mark = 0; in pcap_compile()
800 cstate.bpf_pcap = p; in pcap_compile()
801 cstate.error_set = 0; in pcap_compile()
802 init_regs(&cstate); in pcap_compile()
804 cstate.netmask = mask; in pcap_compile()
806 cstate.snaplen = pcap_snapshot(p); in pcap_compile()
807 if (cstate.snaplen == 0) { in pcap_compile()
826 pcap_set_extra(&cstate, scanner); in pcap_compile()
828 if (init_linktype(&cstate, p) == -1) { in pcap_compile()
832 if (pcap_parse(scanner, &cstate) != 0) { in pcap_compile()
834 if (cstate.ai != NULL) in pcap_compile()
835 freeaddrinfo(cstate.ai); in pcap_compile()
837 if (cstate.e != NULL) in pcap_compile()
838 free(cstate.e); in pcap_compile()
843 if (cstate.ic.root == NULL) { in pcap_compile()
844 cstate.ic.root = gen_retblk(&cstate, cstate.snaplen); in pcap_compile()
849 if (cstate.ic.root== NULL) { in pcap_compile()
855 if (optimize && !cstate.no_optimize) { in pcap_compile()
856 if (bpf_optimize(&cstate.ic, p->errbuf) == -1) { in pcap_compile()
861 if (cstate.ic.root == NULL || in pcap_compile()
862 (cstate.ic.root->s.code == (BPF_RET|BPF_K) && cstate.ic.root->s.k == 0)) { in pcap_compile()
869 program->bf_insns = icode_to_fcode(&cstate.ic, in pcap_compile()
870 cstate.ic.root, &len, p->errbuf); in pcap_compile()
892 freechunks(&cstate); in pcap_compile()
972 finish_parse(compiler_state_t *cstate, struct block *p) in finish_parse() argument
980 if (setjmp(cstate->top_ctx)) in finish_parse()
1002 insert_compute_vloffsets(cstate, p->head); in finish_parse()
1017 ppi_dlt_check = gen_ppi_dlt_check(cstate); in finish_parse()
1021 backpatch(p, gen_retblk_internal(cstate, cstate->snaplen)); in finish_parse()
1023 backpatch(p, gen_retblk_internal(cstate, 0)); in finish_parse()
1024 cstate->ic.root = p->head; in finish_parse()
1056 gen_cmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_cmp() argument
1059 return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JEQ, 0, v); in gen_cmp()
1063 gen_cmp_gt(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_cmp_gt() argument
1066 return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JGT, 0, v); in gen_cmp_gt()
1070 gen_cmp_ge(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_cmp_ge() argument
1073 return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JGE, 0, v); in gen_cmp_ge()
1077 gen_cmp_lt(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_cmp_lt() argument
1080 return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JGE, 1, v); in gen_cmp_lt()
1084 gen_cmp_le(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_cmp_le() argument
1087 return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JGT, 1, v); in gen_cmp_le()
1091 gen_mcmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_mcmp() argument
1094 return gen_ncmp(cstate, offrel, offset, size, mask, BPF_JEQ, 0, v); in gen_mcmp()
1098 gen_bcmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_bcmp() argument
1107 tmp = gen_cmp(cstate, offrel, offset + size - 4, BPF_W, in gen_bcmp()
1117 tmp = gen_cmp(cstate, offrel, offset + size - 2, BPF_H, in gen_bcmp()
1125 tmp = gen_cmp(cstate, offrel, offset, BPF_B, v[0]); in gen_bcmp()
1140 gen_ncmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_ncmp() argument
1147 s = gen_load_a(cstate, offrel, offset, size); in gen_ncmp()
1150 s2 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K); in gen_ncmp()
1155 b = new_block(cstate, JMP(jtype)); in gen_ncmp()
1164 init_linktype(compiler_state_t *cstate, pcap_t *p) in init_linktype() argument
1166 cstate->pcap_fddipad = p->fddipad; in init_linktype()
1171 cstate->outermostlinktype = pcap_datalink(p); in init_linktype()
1172 cstate->off_outermostlinkhdr.constant_part = 0; in init_linktype()
1173 cstate->off_outermostlinkhdr.is_variable = 0; in init_linktype()
1174 cstate->off_outermostlinkhdr.reg = -1; in init_linktype()
1176 cstate->prevlinktype = cstate->outermostlinktype; in init_linktype()
1177 cstate->off_prevlinkhdr.constant_part = 0; in init_linktype()
1178 cstate->off_prevlinkhdr.is_variable = 0; in init_linktype()
1179 cstate->off_prevlinkhdr.reg = -1; in init_linktype()
1181 cstate->linktype = cstate->outermostlinktype; in init_linktype()
1182 cstate->off_linkhdr.constant_part = 0; in init_linktype()
1183 cstate->off_linkhdr.is_variable = 0; in init_linktype()
1184 cstate->off_linkhdr.reg = -1; in init_linktype()
1189 cstate->off_linkpl.constant_part = 0; in init_linktype()
1190 cstate->off_linkpl.is_variable = 0; in init_linktype()
1191 cstate->off_linkpl.reg = -1; in init_linktype()
1193 cstate->off_linktype.constant_part = 0; in init_linktype()
1194 cstate->off_linktype.is_variable = 0; in init_linktype()
1195 cstate->off_linktype.reg = -1; in init_linktype()
1200 cstate->is_atm = 0; in init_linktype()
1201 cstate->off_vpi = OFFSET_NOT_SET; in init_linktype()
1202 cstate->off_vci = OFFSET_NOT_SET; in init_linktype()
1203 cstate->off_proto = OFFSET_NOT_SET; in init_linktype()
1204 cstate->off_payload = OFFSET_NOT_SET; in init_linktype()
1209 cstate->is_geneve = 0; in init_linktype()
1214 cstate->is_vlan_vloffset = 0; in init_linktype()
1219 cstate->off_li = OFFSET_NOT_SET; in init_linktype()
1220 cstate->off_li_hsl = OFFSET_NOT_SET; in init_linktype()
1221 cstate->off_sio = OFFSET_NOT_SET; in init_linktype()
1222 cstate->off_opc = OFFSET_NOT_SET; in init_linktype()
1223 cstate->off_dpc = OFFSET_NOT_SET; in init_linktype()
1224 cstate->off_sls = OFFSET_NOT_SET; in init_linktype()
1226 cstate->label_stack_depth = 0; in init_linktype()
1227 cstate->vlan_stack_depth = 0; in init_linktype()
1229 switch (cstate->linktype) { in init_linktype()
1232 cstate->off_linktype.constant_part = 2; in init_linktype()
1233 cstate->off_linkpl.constant_part = 6; in init_linktype()
1234 cstate->off_nl = 0; /* XXX in reality, variable! */ in init_linktype()
1235 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1239 cstate->off_linktype.constant_part = 4; in init_linktype()
1240 cstate->off_linkpl.constant_part = 8; in init_linktype()
1241 cstate->off_nl = 0; /* XXX in reality, variable! */ in init_linktype()
1242 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1246 cstate->off_linktype.constant_part = 12; in init_linktype()
1247 cstate->off_linkpl.constant_part = 14; /* Ethernet header length */ in init_linktype()
1248 cstate->off_nl = 0; /* Ethernet II */ in init_linktype()
1249 cstate->off_nl_nosnap = 3; /* 802.3+802.2 */ in init_linktype()
1257 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1258 cstate->off_linkpl.constant_part = 16; in init_linktype()
1259 cstate->off_nl = 0; in init_linktype()
1260 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1265 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1267 cstate->off_linkpl.constant_part = 24; in init_linktype()
1268 cstate->off_nl = 0; in init_linktype()
1269 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1274 cstate->off_linktype.constant_part = 0; in init_linktype()
1275 cstate->off_linkpl.constant_part = 4; in init_linktype()
1276 cstate->off_nl = 0; in init_linktype()
1277 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1281 cstate->off_linktype.constant_part = 0; in init_linktype()
1282 cstate->off_linkpl.constant_part = 12; in init_linktype()
1283 cstate->off_nl = 0; in init_linktype()
1284 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1292 cstate->off_linktype.constant_part = 2; /* skip HDLC-like framing */ in init_linktype()
1293 cstate->off_linkpl.constant_part = 4; /* skip HDLC-like framing and protocol field */ in init_linktype()
1294 cstate->off_nl = 0; in init_linktype()
1295 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1303 cstate->off_linktype.constant_part = 6; in init_linktype()
1304 cstate->off_linkpl.constant_part = 8; in init_linktype()
1305 cstate->off_nl = 0; in init_linktype()
1306 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1310 cstate->off_linktype.constant_part = 5; in init_linktype()
1311 cstate->off_linkpl.constant_part = 24; in init_linktype()
1312 cstate->off_nl = 0; in init_linktype()
1313 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1325 cstate->off_linktype.constant_part = 13; in init_linktype()
1326 cstate->off_linktype.constant_part += cstate->pcap_fddipad; in init_linktype()
1327 cstate->off_linkpl.constant_part = 13; /* FDDI MAC header length */ in init_linktype()
1328 cstate->off_linkpl.constant_part += cstate->pcap_fddipad; in init_linktype()
1329 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1330 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1357 cstate->off_linktype.constant_part = 14; in init_linktype()
1358 cstate->off_linkpl.constant_part = 14; /* Token Ring MAC header length */ in init_linktype()
1359 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1360 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1366 cstate->off_linkhdr.is_variable = 1; in init_linktype()
1390 cstate->off_linktype.constant_part = 24; in init_linktype()
1391 cstate->off_linkpl.constant_part = 0; /* link-layer header is variable-length */ in init_linktype()
1392 cstate->off_linkpl.is_variable = 1; in init_linktype()
1393 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1394 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1407 cstate->off_linktype.constant_part = 24; in init_linktype()
1408 cstate->off_linkpl.constant_part = 0; /* link-layer header is variable-length */ in init_linktype()
1409 cstate->off_linkpl.is_variable = 1; in init_linktype()
1410 cstate->off_linkhdr.is_variable = 1; in init_linktype()
1411 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1412 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1428 cstate->off_linktype.constant_part = 0; in init_linktype()
1429 cstate->off_linkpl.constant_part = 0; /* packet begins with LLC header */ in init_linktype()
1430 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1431 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1439 cstate->is_atm = 1; in init_linktype()
1440 cstate->off_vpi = SUNATM_VPI_POS; in init_linktype()
1441 cstate->off_vci = SUNATM_VCI_POS; in init_linktype()
1442 cstate->off_proto = PROTO_POS; in init_linktype()
1443 cstate->off_payload = SUNATM_PKT_BEGIN_POS; in init_linktype()
1444 cstate->off_linktype.constant_part = cstate->off_payload; in init_linktype()
1445 cstate->off_linkpl.constant_part = cstate->off_payload; /* if LLC-encapsulated */ in init_linktype()
1446 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1447 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1453 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1454 cstate->off_linkpl.constant_part = 0; in init_linktype()
1455 cstate->off_nl = 0; in init_linktype()
1456 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1460 cstate->off_linktype.constant_part = 14; in init_linktype()
1461 cstate->off_linkpl.constant_part = 16; in init_linktype()
1462 cstate->off_nl = 0; in init_linktype()
1463 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1467 cstate->off_linktype.constant_part = 0; in init_linktype()
1468 cstate->off_linkpl.constant_part = 20; in init_linktype()
1469 cstate->off_nl = 0; in init_linktype()
1470 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1479 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1480 cstate->off_linkpl.constant_part = 0; in init_linktype()
1481 cstate->off_nl = 0; in init_linktype()
1482 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1496 cstate->off_linktype.constant_part = 16; in init_linktype()
1497 cstate->off_linkpl.constant_part = 16; in init_linktype()
1498 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1499 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1507 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1508 cstate->off_linkpl.constant_part = 0; in init_linktype()
1509 cstate->off_nl = 0; in init_linktype()
1510 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1519 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1520 cstate->off_linkpl.constant_part = 0; in init_linktype()
1521 cstate->off_nl = 4; in init_linktype()
1522 cstate->off_nl_nosnap = 0; /* XXX - for now -> no 802.2 LLC */ in init_linktype()
1526 cstate->off_linktype.constant_part = 16; in init_linktype()
1527 cstate->off_linkpl.constant_part = 18; in init_linktype()
1528 cstate->off_nl = 0; in init_linktype()
1529 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1533 cstate->off_linktype.constant_part = 6; in init_linktype()
1534 cstate->off_linkpl.constant_part = 44; in init_linktype()
1535 cstate->off_nl = 0; /* Ethernet II */ in init_linktype()
1536 cstate->off_nl_nosnap = 0; /* XXX - what does it do with 802.3 packets? */ in init_linktype()
1540 cstate->off_linktype.constant_part = 0; in init_linktype()
1541 cstate->off_linkpl.constant_part = 0; /* link-layer header is variable-length */ in init_linktype()
1542 cstate->off_linkpl.is_variable = 1; in init_linktype()
1543 cstate->off_nl = 0; in init_linktype()
1544 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1553 cstate->off_linktype.constant_part = 4; in init_linktype()
1554 cstate->off_linkpl.constant_part = 4; in init_linktype()
1555 cstate->off_nl = 0; in init_linktype()
1556 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1560 cstate->off_linktype.constant_part = 4; /* in reality variable between 4-8 */ in init_linktype()
1561 cstate->off_linkpl.constant_part = 4; /* in reality variable between 4-8 */ in init_linktype()
1562 cstate->off_nl = 0; in init_linktype()
1563 cstate->off_nl_nosnap = 10; in init_linktype()
1567 cstate->off_linktype.constant_part = 8; /* in reality variable between 8-12 */ in init_linktype()
1568 cstate->off_linkpl.constant_part = 8; /* in reality variable between 8-12 */ in init_linktype()
1569 cstate->off_nl = 0; in init_linktype()
1570 cstate->off_nl_nosnap = 10; in init_linktype()
1577 cstate->off_linkpl.constant_part = 14; in init_linktype()
1578 cstate->off_linktype.constant_part = 16; in init_linktype()
1579 cstate->off_nl = 18; /* Ethernet II */ in init_linktype()
1580 cstate->off_nl_nosnap = 21; /* 802.3+802.2 */ in init_linktype()
1584 cstate->off_linktype.constant_part = 4; in init_linktype()
1585 cstate->off_linkpl.constant_part = 6; in init_linktype()
1586 cstate->off_nl = 0; in init_linktype()
1587 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1591 cstate->off_linktype.constant_part = 6; in init_linktype()
1592 cstate->off_linkpl.constant_part = 12; in init_linktype()
1593 cstate->off_nl = 0; in init_linktype()
1594 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1598 cstate->off_linktype.constant_part = 6; in init_linktype()
1599 …cstate->off_linkpl.constant_part = OFFSET_NOT_SET; /* not really a network layer but raw IP addres… in init_linktype()
1600 cstate->off_nl = OFFSET_NOT_SET; /* not really a network layer but raw IP addresses */ in init_linktype()
1601 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1605 cstate->off_linktype.constant_part = 12; in init_linktype()
1606 cstate->off_linkpl.constant_part = 12; in init_linktype()
1607 cstate->off_nl = 0; /* raw IP/IP6 header */ in init_linktype()
1608 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1612 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1613 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1614 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1615 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1619 cstate->off_linktype.constant_part = 12; in init_linktype()
1620 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; /* L3 proto location dep. on cookie type */ in init_linktype()
1621 cstate->off_nl = OFFSET_NOT_SET; /* L3 proto location dep. on cookie type */ in init_linktype()
1622 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1626 cstate->off_linktype.constant_part = 18; in init_linktype()
1627 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1628 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1629 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1633 cstate->off_linktype.constant_part = 18; in init_linktype()
1634 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1635 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1636 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1640 cstate->off_linktype.constant_part = 8; in init_linktype()
1641 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1642 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1643 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1650 cstate->off_linktype.constant_part = 8; in init_linktype()
1651 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1652 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1653 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1657 cstate->off_li = 2; in init_linktype()
1658 cstate->off_li_hsl = 4; in init_linktype()
1659 cstate->off_sio = 3; in init_linktype()
1660 cstate->off_opc = 4; in init_linktype()
1661 cstate->off_dpc = 4; in init_linktype()
1662 cstate->off_sls = 7; in init_linktype()
1663 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1664 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1665 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1666 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1670 cstate->off_li = 6; in init_linktype()
1671 cstate->off_li_hsl = 8; in init_linktype()
1672 cstate->off_sio = 7; in init_linktype()
1673 cstate->off_opc = 8; in init_linktype()
1674 cstate->off_dpc = 8; in init_linktype()
1675 cstate->off_sls = 11; in init_linktype()
1676 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1677 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1678 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1679 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1683 cstate->off_li = 22; in init_linktype()
1684 cstate->off_li_hsl = 24; in init_linktype()
1685 cstate->off_sio = 23; in init_linktype()
1686 cstate->off_opc = 24; in init_linktype()
1687 cstate->off_dpc = 24; in init_linktype()
1688 cstate->off_sls = 27; in init_linktype()
1689 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1690 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1691 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1692 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1696 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1697 cstate->off_linkpl.constant_part = 4; in init_linktype()
1698 cstate->off_nl = 0; in init_linktype()
1699 cstate->off_nl_nosnap = 0; in init_linktype()
1706 cstate->off_linktype.constant_part = OFFSET_NOT_SET; /* variable, min 15, max 71 steps of 7 */ in init_linktype()
1707 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1708 cstate->off_nl = OFFSET_NOT_SET; /* variable, min 16, max 71 steps of 7 */ in init_linktype()
1709 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1713 cstate->off_linktype.constant_part = 1; in init_linktype()
1714 cstate->off_linkpl.constant_part = 24; /* ipnet header length */ in init_linktype()
1715 cstate->off_nl = 0; in init_linktype()
1716 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1720 cstate->off_linkhdr.constant_part = 4; /* Ethernet header is past 4-byte pseudo-header */ in init_linktype()
1721 cstate->off_linktype.constant_part = cstate->off_linkhdr.constant_part + 12; in init_linktype()
1722 …cstate->off_linkpl.constant_part = cstate->off_linkhdr.constant_part + 14; /* pseudo-header+Ethern… in init_linktype()
1723 cstate->off_nl = 0; /* Ethernet II */ in init_linktype()
1724 cstate->off_nl_nosnap = 3; /* 802.3+802.2 */ in init_linktype()
1728 …cstate->off_linkhdr.constant_part = 12; /* MAC header is past 4-byte pseudo-header, preamble, and … in init_linktype()
1729 cstate->off_linktype.constant_part = cstate->off_linkhdr.constant_part + 12; in init_linktype()
1730 …cstate->off_linkpl.constant_part = cstate->off_linkhdr.constant_part + 14; /* pseudo-header+preamb… in init_linktype()
1731 cstate->off_nl = 0; /* Ethernet II */ in init_linktype()
1732 cstate->off_nl_nosnap = 3; /* 802.3+802.2 */ in init_linktype()
1739 cstate->off_linktype.constant_part = OFFSET_NOT_SET; /* variable, min 15, max 71 steps of 7 */ in init_linktype()
1740 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1741 cstate->off_nl = OFFSET_NOT_SET; /* variable, min 16, max 71 steps of 7 */ in init_linktype()
1742 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1749 cstate->off_linktype.constant_part = OFFSET_NOT_SET; /* variable, min 15, max 71 steps of 7 */ in init_linktype()
1750 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1751 cstate->off_nl = OFFSET_NOT_SET; /* variable, min 16, max 71 steps of 7 */ in init_linktype()
1752 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1759 cstate->off_linktype.constant_part = OFFSET_NOT_SET; /* variable, min 15, max 71 steps of 7 */ in init_linktype()
1760 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1761 cstate->off_nl = OFFSET_NOT_SET; /* variable, min 16, max 71 steps of 7 */ in init_linktype()
1762 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1769 cstate->off_linktype.constant_part = OFFSET_NOT_SET; /* variable, min 15, max 71 steps of 7 */ in init_linktype()
1770 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1771 cstate->off_nl = OFFSET_NOT_SET; /* variable, min 16, max 71 steps of 7 */ in init_linktype()
1772 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1780 cstate->off_linktype.constant_part = OFFSET_NOT_SET; /* variable, min 15, max 71 steps of 7 */ in init_linktype()
1781 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1782 cstate->off_nl = OFFSET_NOT_SET; /* variable, min 16, max 71 steps of 7 */ in init_linktype()
1783 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1792 cstate->off_linktype.constant_part = OFFSET_NOT_SET; /* variable, min 15, max 71 steps of 7 */ in init_linktype()
1793 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1794 cstate->off_nl = OFFSET_NOT_SET; /* variable, min 16, max 71 steps of 7 */ in init_linktype()
1795 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1804 cstate->off_linktype.constant_part = OFFSET_NOT_SET; /* variable, min 15, max 71 steps of 7 */ in init_linktype()
1805 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1806 cstate->off_nl = OFFSET_NOT_SET; /* variable, min 16, max 71 steps of 7 */ in init_linktype()
1807 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1817 if (cstate->linktype >= DLT_HIGH_MATCHING_MIN && in init_linktype()
1818 cstate->linktype <= DLT_HIGH_MATCHING_MAX) { in init_linktype()
1819 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1820 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1821 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1822 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1824 bpf_set_error(cstate, "unknown data link type %d", in init_linktype()
1825 cstate->linktype); in init_linktype()
1831 cstate->off_outermostlinkhdr = cstate->off_prevlinkhdr = cstate->off_linkhdr; in init_linktype()
1839 gen_load_absoffsetrel(compiler_state_t *cstate, bpf_abs_offset *abs_offset, in gen_load_absoffsetrel() argument
1844 s = gen_abs_offset_varpart(cstate, abs_offset); in gen_load_absoffsetrel()
1861 s2 = new_stmt(cstate, BPF_LD|BPF_IND|size); in gen_load_absoffsetrel()
1869 s = new_stmt(cstate, BPF_LD|BPF_ABS|size); in gen_load_absoffsetrel()
1879 gen_load_a(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_load_a() argument
1900 s = new_stmt(cstate, BPF_LD|BPF_ABS|size); in gen_load_a()
1905 s = gen_load_absoffsetrel(cstate, &cstate->off_linkhdr, offset, size); in gen_load_a()
1909 s = gen_load_absoffsetrel(cstate, &cstate->off_prevlinkhdr, offset, size); in gen_load_a()
1913 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, offset, size); in gen_load_a()
1917 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, cstate->off_nl - 4 + offset, size); in gen_load_a()
1921 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, cstate->off_nl + offset, size); in gen_load_a()
1925 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, cstate->off_nl_nosnap + offset, size); in gen_load_a()
1929 s = gen_load_absoffsetrel(cstate, &cstate->off_linktype, offset, size); in gen_load_a()
1939 s = gen_loadx_iphdrlen(cstate); in gen_load_a()
1952 s2 = new_stmt(cstate, BPF_LD|BPF_IND|size); in gen_load_a()
1953 s2->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + offset; in gen_load_a()
1958 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, cstate->off_nl + 40 + offset, size); in gen_load_a()
1970 gen_loadx_iphdrlen(compiler_state_t *cstate) in gen_loadx_iphdrlen() argument
1974 s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl); in gen_loadx_iphdrlen()
1986 s2 = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_loadx_iphdrlen()
1987 s2->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_loadx_iphdrlen()
1989 s2 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K); in gen_loadx_iphdrlen()
1992 s2 = new_stmt(cstate, BPF_ALU|BPF_LSH|BPF_K); in gen_loadx_iphdrlen()
2002 sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X)); in gen_loadx_iphdrlen()
2003 sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX)); in gen_loadx_iphdrlen()
2017 s = new_stmt(cstate, BPF_LDX|BPF_MSH|BPF_B); in gen_loadx_iphdrlen()
2018 s->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_loadx_iphdrlen()
2025 gen_uncond(compiler_state_t *cstate, int rsense) in gen_uncond() argument
2030 s = new_stmt(cstate, BPF_LD|BPF_IMM); in gen_uncond()
2032 b = new_block(cstate, JMP(BPF_JEQ)); in gen_uncond()
2039 gen_true(compiler_state_t *cstate) in gen_true() argument
2041 return gen_uncond(cstate, 1); in gen_true()
2045 gen_false(compiler_state_t *cstate) in gen_false() argument
2047 return gen_uncond(cstate, 0); in gen_false()
2068 gen_ether_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto) in gen_ether_linktype() argument
2089 b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU); in gen_ether_linktype()
2091 b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, (ll_proto << 8) | ll_proto); in gen_ether_linktype()
2128 b0 = gen_cmp(cstate, OR_LLC, 0, BPF_B, LLCSAP_IPX); in gen_ether_linktype()
2129 b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, 0xFFFF); in gen_ether_linktype()
2136 b0 = gen_snap(cstate, 0x000000, ETHERTYPE_IPX); in gen_ether_linktype()
2143 b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU); in gen_ether_linktype()
2159 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ETHERTYPE_IPX); in gen_ether_linktype()
2175 b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU); in gen_ether_linktype()
2190 b1 = gen_snap(cstate, 0x080007, ETHERTYPE_ATALK); in gen_ether_linktype()
2192 b1 = gen_snap(cstate, 0x000000, ETHERTYPE_AARP); in gen_ether_linktype()
2200 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ll_proto); in gen_ether_linktype()
2215 b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU); in gen_ether_linktype()
2217 b1 = gen_cmp(cstate, OR_LINKTYPE, 2, BPF_B, ll_proto); in gen_ether_linktype()
2230 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ll_proto); in gen_ether_linktype()
2236 gen_loopback_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto) in gen_loopback_linktype() argument
2251 if (cstate->linktype == DLT_NULL || cstate->linktype == DLT_ENC) { in gen_loopback_linktype()
2263 if (cstate->bpf_pcap->rfile != NULL && cstate->bpf_pcap->swapped) in gen_loopback_linktype()
2267 return (gen_cmp(cstate, OR_LINKHDR, 0, BPF_W, ll_proto)); in gen_loopback_linktype()
2275 gen_ipnet_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto) in gen_ipnet_linktype() argument
2280 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, IPH_AF_INET); in gen_ipnet_linktype()
2284 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, IPH_AF_INET6); in gen_ipnet_linktype()
2291 return gen_false(cstate); in gen_ipnet_linktype()
2303 gen_linux_sll_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto) in gen_linux_sll_linktype() argument
2324 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, LINUX_SLL_P_802_2); in gen_linux_sll_linktype()
2325 b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, (ll_proto << 8) | ll_proto); in gen_linux_sll_linktype()
2355 b0 = gen_cmp(cstate, OR_LLC, 0, BPF_B, LLCSAP_IPX); in gen_linux_sll_linktype()
2356 b1 = gen_snap(cstate, 0x000000, ETHERTYPE_IPX); in gen_linux_sll_linktype()
2358 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, LINUX_SLL_P_802_2); in gen_linux_sll_linktype()
2365 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, LINUX_SLL_P_802_3); in gen_linux_sll_linktype()
2373 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ETHERTYPE_IPX); in gen_linux_sll_linktype()
2389 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, LINUX_SLL_P_802_2); in gen_linux_sll_linktype()
2403 b1 = gen_snap(cstate, 0x080007, ETHERTYPE_ATALK); in gen_linux_sll_linktype()
2405 b1 = gen_snap(cstate, 0x000000, ETHERTYPE_AARP); in gen_linux_sll_linktype()
2413 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ll_proto); in gen_linux_sll_linktype()
2427 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, LINUX_SLL_P_802_2); in gen_linux_sll_linktype()
2428 b1 = gen_cmp(cstate, OR_LINKHDR, cstate->off_linkpl.constant_part, BPF_B, in gen_linux_sll_linktype()
2442 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ll_proto); in gen_linux_sll_linktype()
2452 gen_load_pflog_llprefixlen(compiler_state_t *cstate) in gen_load_pflog_llprefixlen() argument
2463 if (cstate->off_linkpl.reg != -1) { in gen_load_pflog_llprefixlen()
2467 s1 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_load_pflog_llprefixlen()
2474 s2 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_load_pflog_llprefixlen()
2477 s2 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K); in gen_load_pflog_llprefixlen()
2485 s2 = new_stmt(cstate, BPF_ST); in gen_load_pflog_llprefixlen()
2486 s2->s.k = cstate->off_linkpl.reg; in gen_load_pflog_llprefixlen()
2492 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_pflog_llprefixlen()
2501 gen_load_prism_llprefixlen(compiler_state_t *cstate) in gen_load_prism_llprefixlen() argument
2512 cstate->no_optimize = 1; in gen_load_prism_llprefixlen()
2533 if (cstate->off_linkhdr.reg != -1) { in gen_load_prism_llprefixlen()
2537 s1 = new_stmt(cstate, BPF_LD|BPF_W|BPF_ABS); in gen_load_prism_llprefixlen()
2543 s2 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K); in gen_load_prism_llprefixlen()
2550 sjeq_avs_cookie = new_stmt(cstate, JMP(BPF_JEQ)); in gen_load_prism_llprefixlen()
2561 s2 = new_stmt(cstate, BPF_LD|BPF_W|BPF_ABS); in gen_load_prism_llprefixlen()
2574 sjcommon = new_stmt(cstate, JMP(BPF_JA)); in gen_load_prism_llprefixlen()
2584 s2 = new_stmt(cstate, BPF_LD|BPF_W|BPF_IMM); in gen_load_prism_llprefixlen()
2594 s2 = new_stmt(cstate, BPF_ST); in gen_load_prism_llprefixlen()
2595 s2->s.k = cstate->off_linkhdr.reg; in gen_load_prism_llprefixlen()
2602 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_prism_llprefixlen()
2611 gen_load_avs_llprefixlen(compiler_state_t *cstate) in gen_load_avs_llprefixlen() argument
2622 if (cstate->off_linkhdr.reg != -1) { in gen_load_avs_llprefixlen()
2628 s1 = new_stmt(cstate, BPF_LD|BPF_W|BPF_ABS); in gen_load_avs_llprefixlen()
2635 s2 = new_stmt(cstate, BPF_ST); in gen_load_avs_llprefixlen()
2636 s2->s.k = cstate->off_linkhdr.reg; in gen_load_avs_llprefixlen()
2642 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_avs_llprefixlen()
2651 gen_load_radiotap_llprefixlen(compiler_state_t *cstate) in gen_load_radiotap_llprefixlen() argument
2662 if (cstate->off_linkhdr.reg != -1) { in gen_load_radiotap_llprefixlen()
2674 s1 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_load_radiotap_llprefixlen()
2676 s2 = new_stmt(cstate, BPF_ALU|BPF_LSH|BPF_K); in gen_load_radiotap_llprefixlen()
2679 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_radiotap_llprefixlen()
2686 s2 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_load_radiotap_llprefixlen()
2689 s2 = new_stmt(cstate, BPF_ALU|BPF_OR|BPF_X); in gen_load_radiotap_llprefixlen()
2696 s2 = new_stmt(cstate, BPF_ST); in gen_load_radiotap_llprefixlen()
2697 s2->s.k = cstate->off_linkhdr.reg; in gen_load_radiotap_llprefixlen()
2703 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_radiotap_llprefixlen()
2721 gen_load_ppi_llprefixlen(compiler_state_t *cstate) in gen_load_ppi_llprefixlen() argument
2730 if (cstate->off_linkhdr.reg != -1) { in gen_load_ppi_llprefixlen()
2742 s1 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_load_ppi_llprefixlen()
2744 s2 = new_stmt(cstate, BPF_ALU|BPF_LSH|BPF_K); in gen_load_ppi_llprefixlen()
2747 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_ppi_llprefixlen()
2754 s2 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_load_ppi_llprefixlen()
2757 s2 = new_stmt(cstate, BPF_ALU|BPF_OR|BPF_X); in gen_load_ppi_llprefixlen()
2764 s2 = new_stmt(cstate, BPF_ST); in gen_load_ppi_llprefixlen()
2765 s2->s.k = cstate->off_linkhdr.reg; in gen_load_ppi_llprefixlen()
2771 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_ppi_llprefixlen()
2787 gen_load_802_11_header_len(compiler_state_t *cstate, struct slist *s, struct slist *snext) in gen_load_802_11_header_len() argument
2799 if (cstate->off_linkpl.reg == -1) { in gen_load_802_11_header_len()
2814 cstate->no_optimize = 1; in gen_load_802_11_header_len()
2834 s = new_stmt(cstate, BPF_LDX|BPF_IMM); in gen_load_802_11_header_len()
2835 s->s.k = cstate->off_outermostlinkhdr.constant_part; in gen_load_802_11_header_len()
2845 s2 = new_stmt(cstate, BPF_MISC|BPF_TXA); in gen_load_802_11_header_len()
2847 s2 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_load_802_11_header_len()
2850 s2 = new_stmt(cstate, BPF_ST); in gen_load_802_11_header_len()
2851 s2->s.k = cstate->off_linkpl.reg; in gen_load_802_11_header_len()
2854 s2 = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_load_802_11_header_len()
2863 sjset_data_frame_1 = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2871 sjset_data_frame_1->s.jt = sjset_data_frame_2 = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2882 sjset_data_frame_2->s.jf = sjset_qos = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2892 sjset_qos->s.jt = s2 = new_stmt(cstate, BPF_LD|BPF_MEM); in gen_load_802_11_header_len()
2893 s2->s.k = cstate->off_linkpl.reg; in gen_load_802_11_header_len()
2895 s2 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_IMM); in gen_load_802_11_header_len()
2898 s2 = new_stmt(cstate, BPF_ST); in gen_load_802_11_header_len()
2899 s2->s.k = cstate->off_linkpl.reg; in gen_load_802_11_header_len()
2921 if (cstate->linktype == DLT_IEEE802_11_RADIO) { in gen_load_802_11_header_len()
2926 sjset_qos->s.jf = s2 = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_W); in gen_load_802_11_header_len()
2930 sjset_radiotap_flags_present = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2942 sjset_radiotap_ext_present = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2955 sjset_radiotap_tsft_present = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2969 s2 = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_B); in gen_load_802_11_header_len()
2974 sjset_tsft_datapad = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2986 s2 = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_B); in gen_load_802_11_header_len()
2991 sjset_notsft_datapad = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
3002 s_roundup = new_stmt(cstate, BPF_LD|BPF_MEM); in gen_load_802_11_header_len()
3003 s_roundup->s.k = cstate->off_linkpl.reg; in gen_load_802_11_header_len()
3005 s2 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_IMM); in gen_load_802_11_header_len()
3008 s2 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_IMM); in gen_load_802_11_header_len()
3011 s2 = new_stmt(cstate, BPF_ST); in gen_load_802_11_header_len()
3012 s2->s.k = cstate->off_linkpl.reg; in gen_load_802_11_header_len()
3026 insert_compute_vloffsets(compiler_state_t *cstate, struct block *b) in insert_compute_vloffsets() argument
3035 if (cstate->off_linkpl.reg != -1 && cstate->off_linkhdr.is_variable && in insert_compute_vloffsets()
3036 cstate->off_linkhdr.reg == -1) in insert_compute_vloffsets()
3037 cstate->off_linkhdr.reg = alloc_reg(cstate); in insert_compute_vloffsets()
3050 switch (cstate->outermostlinktype) { in insert_compute_vloffsets()
3053 s = gen_load_prism_llprefixlen(cstate); in insert_compute_vloffsets()
3057 s = gen_load_avs_llprefixlen(cstate); in insert_compute_vloffsets()
3061 s = gen_load_radiotap_llprefixlen(cstate); in insert_compute_vloffsets()
3065 s = gen_load_ppi_llprefixlen(cstate); in insert_compute_vloffsets()
3078 switch (cstate->outermostlinktype) { in insert_compute_vloffsets()
3085 s = gen_load_802_11_header_len(cstate, s, b->stmts); in insert_compute_vloffsets()
3089 s = gen_load_pflog_llprefixlen(cstate); in insert_compute_vloffsets()
3097 if (s == NULL && cstate->is_vlan_vloffset) { in insert_compute_vloffsets()
3100 if (cstate->off_linkpl.reg == -1) in insert_compute_vloffsets()
3101 cstate->off_linkpl.reg = alloc_reg(cstate); in insert_compute_vloffsets()
3102 if (cstate->off_linktype.reg == -1) in insert_compute_vloffsets()
3103 cstate->off_linktype.reg = alloc_reg(cstate); in insert_compute_vloffsets()
3105 s = new_stmt(cstate, BPF_LD|BPF_W|BPF_IMM); in insert_compute_vloffsets()
3107 s2 = new_stmt(cstate, BPF_ST); in insert_compute_vloffsets()
3108 s2->s.k = cstate->off_linkpl.reg; in insert_compute_vloffsets()
3110 s2 = new_stmt(cstate, BPF_ST); in insert_compute_vloffsets()
3111 s2->s.k = cstate->off_linktype.reg; in insert_compute_vloffsets()
3128 gen_ppi_dlt_check(compiler_state_t *cstate) in gen_ppi_dlt_check() argument
3133 if (cstate->linktype == DLT_PPI) in gen_ppi_dlt_check()
3137 s_load_dlt = new_stmt(cstate, BPF_LD|BPF_W|BPF_ABS); in gen_ppi_dlt_check()
3140 b = new_block(cstate, JMP(BPF_JEQ)); in gen_ppi_dlt_check()
3167 gen_abs_offset_varpart(compiler_state_t *cstate, bpf_abs_offset *off) in gen_abs_offset_varpart() argument
3178 off->reg = alloc_reg(cstate); in gen_abs_offset_varpart()
3185 s = new_stmt(cstate, BPF_LDX|BPF_MEM); in gen_abs_offset_varpart()
3252 gen_prevlinkhdr_check(compiler_state_t *cstate) in gen_prevlinkhdr_check() argument
3256 if (cstate->is_geneve) in gen_prevlinkhdr_check()
3257 return gen_geneve_ll_check(cstate); in gen_prevlinkhdr_check()
3259 switch (cstate->prevlinktype) { in gen_prevlinkhdr_check()
3269 b0 = gen_cmp(cstate, OR_PREVLINKHDR, SUNATM_PKT_BEGIN_POS, BPF_H, 0xFF00); in gen_prevlinkhdr_check()
3298 gen_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto) in gen_linktype() argument
3304 if (cstate->label_stack_depth > 0) in gen_linktype()
3305 return gen_mpls_linktype(cstate, ll_proto); in gen_linktype()
3307 switch (cstate->linktype) { in gen_linktype()
3314 if (!cstate->is_geneve) in gen_linktype()
3315 b0 = gen_prevlinkhdr_check(cstate); in gen_linktype()
3319 b1 = gen_ether_linktype(cstate, ll_proto); in gen_linktype()
3334 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ll_proto); in gen_linktype()
3346 b0 = gen_check_802_11_data_frame(cstate); in gen_linktype()
3351 b1 = gen_llc_linktype(cstate, ll_proto); in gen_linktype()
3360 return gen_llc_linktype(cstate, ll_proto); in gen_linktype()
3367 return gen_llc_linktype(cstate, ll_proto); in gen_linktype()
3373 return gen_llc_linktype(cstate, ll_proto); in gen_linktype()
3384 b0 = gen_atmfield_code_internal(cstate, A_PROTOTYPE, PT_LLC, BPF_JEQ, 0); in gen_linktype()
3385 b1 = gen_llc_linktype(cstate, ll_proto); in gen_linktype()
3391 return gen_linux_sll_linktype(cstate, ll_proto); in gen_linktype()
3408 return gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, 0x40, 0xF0); in gen_linktype()
3412 return gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, 0x60, 0xF0); in gen_linktype()
3415 return gen_false(cstate); /* always false */ in gen_linktype()
3424 return gen_true(cstate); /* always true */ in gen_linktype()
3427 return gen_false(cstate); in gen_linktype()
3435 return gen_true(cstate); /* always true */ in gen_linktype()
3438 return gen_false(cstate); in gen_linktype()
3449 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, in gen_linktype()
3465 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, PPP_IP); in gen_linktype()
3466 b1 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, PPP_VJC); in gen_linktype()
3468 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, PPP_VJNC); in gen_linktype()
3473 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, in gen_linktype()
3484 return (gen_loopback_linktype(cstate, AF_INET)); in gen_linktype()
3509 if (cstate->bpf_pcap->rfile != NULL) { in gen_linktype()
3514 b0 = gen_loopback_linktype(cstate, BSD_AFNUM_INET6_BSD); in gen_linktype()
3515 b1 = gen_loopback_linktype(cstate, BSD_AFNUM_INET6_FREEBSD); in gen_linktype()
3517 b0 = gen_loopback_linktype(cstate, BSD_AFNUM_INET6_DARWIN); in gen_linktype()
3533 return (gen_loopback_linktype(cstate, 24)); in gen_linktype()
3536 return (gen_loopback_linktype(cstate, AF_INET6)); in gen_linktype()
3542 return gen_false(cstate); in gen_linktype()
3553 return gen_false(cstate); in gen_linktype()
3562 return (gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, af), in gen_linktype()
3565 return (gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, af), in gen_linktype()
3568 return gen_false(cstate); in gen_linktype()
3580 return gen_false(cstate); in gen_linktype()
3583 return (gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3587 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3589 b1 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3595 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3597 b1 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3603 return (gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3607 return (gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3615 return gen_true(cstate); in gen_linktype()
3617 return gen_false(cstate); in gen_linktype()
3632 return gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | 0xcc); in gen_linktype()
3638 return gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | 0x8e); in gen_linktype()
3652 b0 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | ISO8473_CLNP); in gen_linktype()
3653 b1 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | ISO9542_ESIS); in gen_linktype()
3654 b2 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | ISO10589_ISIS); in gen_linktype()
3660 return gen_false(cstate); in gen_linktype()
3665 bpf_error(cstate, "Multi-link Frame Relay link-layer type filtering not implemented"); in gen_linktype()
3697 …return gen_mcmp(cstate, OR_LINKHDR, 0, BPF_W, 0x4d474300, 0xffffff00); /* compare the magic number… in gen_linktype()
3700 return gen_mcmp(cstate, OR_LINKHDR, 0, BPF_W, 0x55FF0000, 0xffff0000); in gen_linktype()
3703 return gen_ipnet_linktype(cstate, ll_proto); in gen_linktype()
3706 bpf_error(cstate, "IrDA link-layer type filtering not implemented"); in gen_linktype()
3709 bpf_error(cstate, "DOCSIS link-layer type filtering not implemented"); in gen_linktype()
3713 bpf_error(cstate, "MTP2 link-layer type filtering not implemented"); in gen_linktype()
3716 bpf_error(cstate, "ERF link-layer type filtering not implemented"); in gen_linktype()
3719 bpf_error(cstate, "PFSYNC link-layer type filtering not implemented"); in gen_linktype()
3722 bpf_error(cstate, "LAPD link-layer type filtering not implemented"); in gen_linktype()
3728 bpf_error(cstate, "USB link-layer type filtering not implemented"); in gen_linktype()
3732 bpf_error(cstate, "Bluetooth link-layer type filtering not implemented"); in gen_linktype()
3736 bpf_error(cstate, "CAN link-layer type filtering not implemented"); in gen_linktype()
3743 bpf_error(cstate, "IEEE 802.15.4 link-layer type filtering not implemented"); in gen_linktype()
3746 bpf_error(cstate, "IEEE 802.16 link-layer type filtering not implemented"); in gen_linktype()
3749 bpf_error(cstate, "SITA link-layer type filtering not implemented"); in gen_linktype()
3752 bpf_error(cstate, "RAIF1 link-layer type filtering not implemented"); in gen_linktype()
3756 bpf_error(cstate, "IPMB link-layer type filtering not implemented"); in gen_linktype()
3759 bpf_error(cstate, "AX.25 link-layer type filtering not implemented"); in gen_linktype()
3766 bpf_error(cstate, "NFLOG link-layer type filtering not implemented"); in gen_linktype()
3775 if (cstate->off_linktype.constant_part != OFFSET_NOT_SET) { in gen_linktype()
3781 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ll_proto); in gen_linktype()
3787 description = pcap_datalink_val_to_description_or_dlt(cstate->linktype); in gen_linktype()
3788 bpf_error(cstate, "%s link-layer type filtering not implemented", in gen_linktype()
3803 gen_snap(compiler_state_t *cstate, bpf_u_int32 orgcode, bpf_u_int32 ptype) in gen_snap() argument
3815 return gen_bcmp(cstate, OR_LLC, 0, 8, snapblock); in gen_snap()
3822 gen_llc_internal(compiler_state_t *cstate) in gen_llc_internal() argument
3826 switch (cstate->linktype) { in gen_llc_internal()
3833 b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU); in gen_llc_internal()
3840 b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, 0xFFFF); in gen_llc_internal()
3849 b0 = gen_atmtype_llc(cstate); in gen_llc_internal()
3856 return gen_true(cstate); in gen_llc_internal()
3862 return gen_true(cstate); in gen_llc_internal()
3873 return gen_true(cstate); in gen_llc_internal()
3883 b0 = gen_check_802_11_data_frame(cstate); in gen_llc_internal()
3887 bpf_error(cstate, "'llc' not supported for %s", in gen_llc_internal()
3888 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_llc_internal()
3894 gen_llc(compiler_state_t *cstate) in gen_llc() argument
3900 if (setjmp(cstate->top_ctx)) in gen_llc()
3903 return gen_llc_internal(cstate); in gen_llc()
3907 gen_llc_i(compiler_state_t *cstate) in gen_llc_i() argument
3916 if (setjmp(cstate->top_ctx)) in gen_llc_i()
3922 b0 = gen_llc_internal(cstate); in gen_llc_i()
3928 s = gen_load_a(cstate, OR_LLC, 2, BPF_B); in gen_llc_i()
3929 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_llc_i()
3938 gen_llc_s(compiler_state_t *cstate) in gen_llc_s() argument
3946 if (setjmp(cstate->top_ctx)) in gen_llc_s()
3952 b0 = gen_llc_internal(cstate); in gen_llc_s()
3958 b1 = gen_mcmp(cstate, OR_LLC, 2, BPF_B, LLC_S_FMT, 0x03); in gen_llc_s()
3964 gen_llc_u(compiler_state_t *cstate) in gen_llc_u() argument
3972 if (setjmp(cstate->top_ctx)) in gen_llc_u()
3978 b0 = gen_llc_internal(cstate); in gen_llc_u()
3984 b1 = gen_mcmp(cstate, OR_LLC, 2, BPF_B, LLC_U_FMT, 0x03); in gen_llc_u()
3990 gen_llc_s_subtype(compiler_state_t *cstate, bpf_u_int32 subtype) in gen_llc_s_subtype() argument
3998 if (setjmp(cstate->top_ctx)) in gen_llc_s_subtype()
4004 b0 = gen_llc_internal(cstate); in gen_llc_s_subtype()
4009 b1 = gen_mcmp(cstate, OR_LLC, 2, BPF_B, subtype, LLC_S_CMD_MASK); in gen_llc_s_subtype()
4015 gen_llc_u_subtype(compiler_state_t *cstate, bpf_u_int32 subtype) in gen_llc_u_subtype() argument
4023 if (setjmp(cstate->top_ctx)) in gen_llc_u_subtype()
4029 b0 = gen_llc_internal(cstate); in gen_llc_u_subtype()
4034 b1 = gen_mcmp(cstate, OR_LLC, 2, BPF_B, subtype, LLC_U_CMD_MASK); in gen_llc_u_subtype()
4052 gen_llc_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto) in gen_llc_linktype() argument
4067 return gen_cmp(cstate, OR_LLC, 0, BPF_H, (bpf_u_int32) in gen_llc_linktype()
4075 return gen_cmp(cstate, OR_LLC, 0, BPF_B, LLCSAP_IPX); in gen_llc_linktype()
4087 return gen_snap(cstate, 0x080007, ETHERTYPE_ATALK); in gen_llc_linktype()
4099 return gen_cmp(cstate, OR_LLC, 0, BPF_B, ll_proto); in gen_llc_linktype()
4120 return gen_cmp(cstate, OR_LLC, 6, BPF_H, ll_proto); in gen_llc_linktype()
4126 gen_hostop(compiler_state_t *cstate, bpf_u_int32 addr, bpf_u_int32 mask, in gen_hostop() argument
4143 b0 = gen_hostop(cstate, addr, mask, Q_SRC, ll_proto, src_off, dst_off); in gen_hostop()
4144 b1 = gen_hostop(cstate, addr, mask, Q_DST, ll_proto, src_off, dst_off); in gen_hostop()
4150 b0 = gen_hostop(cstate, addr, mask, Q_SRC, ll_proto, src_off, dst_off); in gen_hostop()
4151 b1 = gen_hostop(cstate, addr, mask, Q_DST, ll_proto, src_off, dst_off); in gen_hostop()
4156 …bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for addresses other than 802.11… in gen_hostop()
4160 …bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for addresses other than 802.11… in gen_hostop()
4164 …bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for addresses other than 802.11… in gen_hostop()
4168 …bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for addresses other than 802.11… in gen_hostop()
4172 bpf_error(cstate, "'ra' is not a valid qualifier for addresses other than 802.11 MAC addresses"); in gen_hostop()
4176 bpf_error(cstate, "'ta' is not a valid qualifier for addresses other than 802.11 MAC addresses"); in gen_hostop()
4183 b0 = gen_linktype(cstate, ll_proto); in gen_hostop()
4184 b1 = gen_mcmp(cstate, OR_LINKPL, offset, BPF_W, addr, mask); in gen_hostop()
4191 gen_hostop6(compiler_state_t *cstate, struct in6_addr *addr, in gen_hostop6() argument
4219 b0 = gen_hostop6(cstate, addr, mask, Q_SRC, ll_proto, src_off, dst_off); in gen_hostop6()
4220 b1 = gen_hostop6(cstate, addr, mask, Q_DST, ll_proto, src_off, dst_off); in gen_hostop6()
4226 b0 = gen_hostop6(cstate, addr, mask, Q_SRC, ll_proto, src_off, dst_off); in gen_hostop6()
4227 b1 = gen_hostop6(cstate, addr, mask, Q_DST, ll_proto, src_off, dst_off); in gen_hostop6()
4232 …bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for addresses other than 802.11… in gen_hostop6()
4236 …bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for addresses other than 802.11… in gen_hostop6()
4240 …bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for addresses other than 802.11… in gen_hostop6()
4244 …bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for addresses other than 802.11… in gen_hostop6()
4248 bpf_error(cstate, "'ra' is not a valid qualifier for addresses other than 802.11 MAC addresses"); in gen_hostop6()
4252 bpf_error(cstate, "'ta' is not a valid qualifier for addresses other than 802.11 MAC addresses"); in gen_hostop6()
4262 b1 = gen_mcmp(cstate, OR_LINKPL, offset + 12, BPF_W, ntohl(a[3]), ntohl(m[3])); in gen_hostop6()
4263 b0 = gen_mcmp(cstate, OR_LINKPL, offset + 8, BPF_W, ntohl(a[2]), ntohl(m[2])); in gen_hostop6()
4265 b0 = gen_mcmp(cstate, OR_LINKPL, offset + 4, BPF_W, ntohl(a[1]), ntohl(m[1])); in gen_hostop6()
4267 b0 = gen_mcmp(cstate, OR_LINKPL, offset + 0, BPF_W, ntohl(a[0]), ntohl(m[0])); in gen_hostop6()
4269 b0 = gen_linktype(cstate, ll_proto); in gen_hostop6()
4276 gen_ehostop(compiler_state_t *cstate, const u_char *eaddr, int dir) in gen_ehostop() argument
4282 return gen_bcmp(cstate, OR_LINKHDR, 6, 6, eaddr); in gen_ehostop()
4285 return gen_bcmp(cstate, OR_LINKHDR, 0, 6, eaddr); in gen_ehostop()
4288 b0 = gen_ehostop(cstate, eaddr, Q_SRC); in gen_ehostop()
4289 b1 = gen_ehostop(cstate, eaddr, Q_DST); in gen_ehostop()
4295 b0 = gen_ehostop(cstate, eaddr, Q_SRC); in gen_ehostop()
4296 b1 = gen_ehostop(cstate, eaddr, Q_DST); in gen_ehostop()
4301 bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11 with 802.11 headers"); in gen_ehostop()
4305 bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11 with 802.11 headers"); in gen_ehostop()
4309 bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11 with 802.11 headers"); in gen_ehostop()
4313 bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11 with 802.11 headers"); in gen_ehostop()
4317 bpf_error(cstate, "'ra' is only supported on 802.11 with 802.11 headers"); in gen_ehostop()
4321 bpf_error(cstate, "'ta' is only supported on 802.11 with 802.11 headers"); in gen_ehostop()
4332 gen_fhostop(compiler_state_t *cstate, const u_char *eaddr, int dir) in gen_fhostop() argument
4338 return gen_bcmp(cstate, OR_LINKHDR, 6 + 1 + cstate->pcap_fddipad, 6, eaddr); in gen_fhostop()
4341 return gen_bcmp(cstate, OR_LINKHDR, 0 + 1 + cstate->pcap_fddipad, 6, eaddr); in gen_fhostop()
4344 b0 = gen_fhostop(cstate, eaddr, Q_SRC); in gen_fhostop()
4345 b1 = gen_fhostop(cstate, eaddr, Q_DST); in gen_fhostop()
4351 b0 = gen_fhostop(cstate, eaddr, Q_SRC); in gen_fhostop()
4352 b1 = gen_fhostop(cstate, eaddr, Q_DST); in gen_fhostop()
4357 bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11"); in gen_fhostop()
4361 bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11"); in gen_fhostop()
4365 bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11"); in gen_fhostop()
4369 bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11"); in gen_fhostop()
4373 bpf_error(cstate, "'ra' is only supported on 802.11"); in gen_fhostop()
4377 bpf_error(cstate, "'ta' is only supported on 802.11"); in gen_fhostop()
4388 gen_thostop(compiler_state_t *cstate, const u_char *eaddr, int dir) in gen_thostop() argument
4394 return gen_bcmp(cstate, OR_LINKHDR, 8, 6, eaddr); in gen_thostop()
4397 return gen_bcmp(cstate, OR_LINKHDR, 2, 6, eaddr); in gen_thostop()
4400 b0 = gen_thostop(cstate, eaddr, Q_SRC); in gen_thostop()
4401 b1 = gen_thostop(cstate, eaddr, Q_DST); in gen_thostop()
4407 b0 = gen_thostop(cstate, eaddr, Q_SRC); in gen_thostop()
4408 b1 = gen_thostop(cstate, eaddr, Q_DST); in gen_thostop()
4413 bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11"); in gen_thostop()
4417 bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11"); in gen_thostop()
4421 bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11"); in gen_thostop()
4425 bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11"); in gen_thostop()
4429 bpf_error(cstate, "'ra' is only supported on 802.11"); in gen_thostop()
4433 bpf_error(cstate, "'ta' is only supported on 802.11"); in gen_thostop()
4445 gen_wlanhostop(compiler_state_t *cstate, const u_char *eaddr, int dir) in gen_wlanhostop() argument
4457 cstate->no_optimize = 1; in gen_wlanhostop()
4487 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_wlanhostop()
4488 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4495 b0 = gen_bcmp(cstate, OR_LINKHDR, 24, 6, eaddr); in gen_wlanhostop()
4502 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_wlanhostop()
4503 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4511 b1 = gen_bcmp(cstate, OR_LINKHDR, 16, 6, eaddr); in gen_wlanhostop()
4525 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_wlanhostop()
4526 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4534 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_wlanhostop()
4535 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4543 b1 = gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr); in gen_wlanhostop()
4557 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4558 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4572 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4573 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4581 b1 = gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr); in gen_wlanhostop()
4599 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4600 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4634 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_wlanhostop()
4635 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4642 b0 = gen_bcmp(cstate, OR_LINKHDR, 16, 6, eaddr); in gen_wlanhostop()
4649 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_wlanhostop()
4650 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4658 b1 = gen_bcmp(cstate, OR_LINKHDR, 4, 6, eaddr); in gen_wlanhostop()
4671 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4672 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4686 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4687 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4695 b1 = gen_bcmp(cstate, OR_LINKHDR, 4, 6, eaddr); in gen_wlanhostop()
4713 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4714 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4727 b0 = gen_wlanhostop(cstate, eaddr, Q_SRC); in gen_wlanhostop()
4728 b1 = gen_wlanhostop(cstate, eaddr, Q_DST); in gen_wlanhostop()
4734 b0 = gen_wlanhostop(cstate, eaddr, Q_SRC); in gen_wlanhostop()
4735 b1 = gen_wlanhostop(cstate, eaddr, Q_DST); in gen_wlanhostop()
4743 return (gen_bcmp(cstate, OR_LINKHDR, 4, 6, eaddr)); in gen_wlanhostop()
4749 b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_TYPE_CTL, in gen_wlanhostop()
4752 b1 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_SUBTYPE_CTS, in gen_wlanhostop()
4755 b2 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_SUBTYPE_ACK, in gen_wlanhostop()
4760 b1 = gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr); in gen_wlanhostop()
4768 b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_TYPE_CTL, in gen_wlanhostop()
4771 b1 = gen_bcmp(cstate, OR_LINKHDR, 16, 6, eaddr); in gen_wlanhostop()
4782 b0 = gen_mcmp(cstate, OR_LINKHDR, 1, BPF_B, in gen_wlanhostop()
4784 b1 = gen_bcmp(cstate, OR_LINKHDR, 24, 6, eaddr); in gen_wlanhostop()
4799 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4800 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4807 b0 = gen_bcmp(cstate, OR_LINKHDR, 4, 6, eaddr); in gen_wlanhostop()
4824 b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_TYPE_CTL, in gen_wlanhostop()
4827 b1 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_SUBTYPE_CTS, in gen_wlanhostop()
4830 b2 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_SUBTYPE_ACK, in gen_wlanhostop()
4841 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4842 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4855 b1 = gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr); in gen_wlanhostop()
4869 gen_ipfchostop(compiler_state_t *cstate, const u_char *eaddr, int dir) in gen_ipfchostop() argument
4875 return gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr); in gen_ipfchostop()
4878 return gen_bcmp(cstate, OR_LINKHDR, 2, 6, eaddr); in gen_ipfchostop()
4881 b0 = gen_ipfchostop(cstate, eaddr, Q_SRC); in gen_ipfchostop()
4882 b1 = gen_ipfchostop(cstate, eaddr, Q_DST); in gen_ipfchostop()
4888 b0 = gen_ipfchostop(cstate, eaddr, Q_SRC); in gen_ipfchostop()
4889 b1 = gen_ipfchostop(cstate, eaddr, Q_DST); in gen_ipfchostop()
4894 bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11"); in gen_ipfchostop()
4898 bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11"); in gen_ipfchostop()
4902 bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11"); in gen_ipfchostop()
4906 bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11"); in gen_ipfchostop()
4910 bpf_error(cstate, "'ra' is only supported on 802.11"); in gen_ipfchostop()
4914 bpf_error(cstate, "'ta' is only supported on 802.11"); in gen_ipfchostop()
4940 gen_dnhostop(compiler_state_t *cstate, bpf_u_int32 addr, int dir) in gen_dnhostop() argument
4960 b0 = gen_dnhostop(cstate, addr, Q_SRC); in gen_dnhostop()
4961 b1 = gen_dnhostop(cstate, addr, Q_DST); in gen_dnhostop()
4968 b0 = gen_dnhostop(cstate, addr, Q_SRC); in gen_dnhostop()
4969 b1 = gen_dnhostop(cstate, addr, Q_DST); in gen_dnhostop()
4974 …bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for addresses other than 802.11… in gen_dnhostop()
4978 …bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for addresses other than 802.11… in gen_dnhostop()
4982 …bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for addresses other than 802.11… in gen_dnhostop()
4986 …bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for addresses other than 802.11… in gen_dnhostop()
4990 bpf_error(cstate, "'ra' is not a valid qualifier for addresses other than 802.11 MAC addresses"); in gen_dnhostop()
4994 bpf_error(cstate, "'ta' is not a valid qualifier for addresses other than 802.11 MAC addresses"); in gen_dnhostop()
5001 b0 = gen_linktype(cstate, ETHERTYPE_DN); in gen_dnhostop()
5003 tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_H, in gen_dnhostop()
5005 b1 = gen_cmp(cstate, OR_LINKPL, 2 + 1 + offset_lh, in gen_dnhostop()
5009 tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_B, (bpf_u_int32)0x06, in gen_dnhostop()
5011 b2 = gen_cmp(cstate, OR_LINKPL, 2 + offset_lh, BPF_H, in gen_dnhostop()
5016 tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_H, in gen_dnhostop()
5018 b2 = gen_cmp(cstate, OR_LINKPL, 2 + 1 + offset_sh, BPF_H, in gen_dnhostop()
5023 tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_B, (bpf_u_int32)0x02, in gen_dnhostop()
5025 b2 = gen_cmp(cstate, OR_LINKPL, 2 + offset_sh, BPF_H, in gen_dnhostop()
5041 gen_mpls_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto) in gen_mpls_linktype() argument
5049 b0 = gen_mcmp(cstate, OR_LINKPL, (u_int)-2, BPF_B, 0x01, 0x01); in gen_mpls_linktype()
5051 b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_B, 0x40, 0xf0); in gen_mpls_linktype()
5057 b0 = gen_mcmp(cstate, OR_LINKPL, (u_int)-2, BPF_B, 0x01, 0x01); in gen_mpls_linktype()
5059 b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_B, 0x60, 0xf0); in gen_mpls_linktype()
5065 bpf_error(cstate, "unsupported protocol over mpls"); in gen_mpls_linktype()
5071 gen_host(compiler_state_t *cstate, bpf_u_int32 addr, bpf_u_int32 mask, in gen_host() argument
5085 b0 = gen_host(cstate, addr, mask, Q_IP, dir, type); in gen_host()
5090 if (cstate->label_stack_depth == 0) { in gen_host()
5091 b1 = gen_host(cstate, addr, mask, Q_ARP, dir, type); in gen_host()
5093 b0 = gen_host(cstate, addr, mask, Q_RARP, dir, type); in gen_host()
5099 bpf_error(cstate, "link-layer modifier applied to %s", typestr); in gen_host()
5102 return gen_hostop(cstate, addr, mask, dir, ETHERTYPE_IP, 12, 16); in gen_host()
5105 return gen_hostop(cstate, addr, mask, dir, ETHERTYPE_REVARP, 14, 24); in gen_host()
5108 return gen_hostop(cstate, addr, mask, dir, ETHERTYPE_ARP, 14, 24); in gen_host()
5111 bpf_error(cstate, "'sctp' modifier applied to %s", typestr); in gen_host()
5114 bpf_error(cstate, "'tcp' modifier applied to %s", typestr); in gen_host()
5117 bpf_error(cstate, "'udp' modifier applied to %s", typestr); in gen_host()
5120 bpf_error(cstate, "'icmp' modifier applied to %s", typestr); in gen_host()
5123 bpf_error(cstate, "'igmp' modifier applied to %s", typestr); in gen_host()
5126 bpf_error(cstate, "'igrp' modifier applied to %s", typestr); in gen_host()
5129 bpf_error(cstate, "AppleTalk host filtering not implemented"); in gen_host()
5132 return gen_dnhostop(cstate, addr, dir); in gen_host()
5135 bpf_error(cstate, "LAT host filtering not implemented"); in gen_host()
5138 bpf_error(cstate, "SCA host filtering not implemented"); in gen_host()
5141 bpf_error(cstate, "MOPRC host filtering not implemented"); in gen_host()
5144 bpf_error(cstate, "MOPDL host filtering not implemented"); in gen_host()
5147 bpf_error(cstate, "'ip6' modifier applied to ip host"); in gen_host()
5150 bpf_error(cstate, "'icmp6' modifier applied to %s", typestr); in gen_host()
5153 bpf_error(cstate, "'ah' modifier applied to %s", typestr); in gen_host()
5156 bpf_error(cstate, "'esp' modifier applied to %s", typestr); in gen_host()
5159 bpf_error(cstate, "'pim' modifier applied to %s", typestr); in gen_host()
5162 bpf_error(cstate, "'vrrp' modifier applied to %s", typestr); in gen_host()
5165 bpf_error(cstate, "AARP host filtering not implemented"); in gen_host()
5168 bpf_error(cstate, "ISO host filtering not implemented"); in gen_host()
5171 bpf_error(cstate, "'esis' modifier applied to %s", typestr); in gen_host()
5174 bpf_error(cstate, "'isis' modifier applied to %s", typestr); in gen_host()
5177 bpf_error(cstate, "'clnp' modifier applied to %s", typestr); in gen_host()
5180 bpf_error(cstate, "'stp' modifier applied to %s", typestr); in gen_host()
5183 bpf_error(cstate, "IPX host filtering not implemented"); in gen_host()
5186 bpf_error(cstate, "'netbeui' modifier applied to %s", typestr); in gen_host()
5189 bpf_error(cstate, "'l1' modifier applied to %s", typestr); in gen_host()
5192 bpf_error(cstate, "'l2' modifier applied to %s", typestr); in gen_host()
5195 bpf_error(cstate, "'iih' modifier applied to %s", typestr); in gen_host()
5198 bpf_error(cstate, "'snp' modifier applied to %s", typestr); in gen_host()
5201 bpf_error(cstate, "'csnp' modifier applied to %s", typestr); in gen_host()
5204 bpf_error(cstate, "'psnp' modifier applied to %s", typestr); in gen_host()
5207 bpf_error(cstate, "'lsp' modifier applied to %s", typestr); in gen_host()
5210 bpf_error(cstate, "'radio' modifier applied to %s", typestr); in gen_host()
5213 bpf_error(cstate, "'carp' modifier applied to %s", typestr); in gen_host()
5223 gen_host6(compiler_state_t *cstate, struct in6_addr *addr, in gen_host6() argument
5236 return gen_host6(cstate, addr, mask, Q_IPV6, dir, type); in gen_host6()
5239 bpf_error(cstate, "link-layer modifier applied to ip6 %s", typestr); in gen_host6()
5242 bpf_error(cstate, "'ip' modifier applied to ip6 %s", typestr); in gen_host6()
5245 bpf_error(cstate, "'rarp' modifier applied to ip6 %s", typestr); in gen_host6()
5248 bpf_error(cstate, "'arp' modifier applied to ip6 %s", typestr); in gen_host6()
5251 bpf_error(cstate, "'sctp' modifier applied to ip6 %s", typestr); in gen_host6()
5254 bpf_error(cstate, "'tcp' modifier applied to ip6 %s", typestr); in gen_host6()
5257 bpf_error(cstate, "'udp' modifier applied to ip6 %s", typestr); in gen_host6()
5260 bpf_error(cstate, "'icmp' modifier applied to ip6 %s", typestr); in gen_host6()
5263 bpf_error(cstate, "'igmp' modifier applied to ip6 %s", typestr); in gen_host6()
5266 bpf_error(cstate, "'igrp' modifier applied to ip6 %s", typestr); in gen_host6()
5269 bpf_error(cstate, "AppleTalk modifier applied to ip6 %s", typestr); in gen_host6()
5272 bpf_error(cstate, "'decnet' modifier applied to ip6 %s", typestr); in gen_host6()
5275 bpf_error(cstate, "'lat' modifier applied to ip6 %s", typestr); in gen_host6()
5278 bpf_error(cstate, "'sca' modifier applied to ip6 %s", typestr); in gen_host6()
5281 bpf_error(cstate, "'moprc' modifier applied to ip6 %s", typestr); in gen_host6()
5284 bpf_error(cstate, "'mopdl' modifier applied to ip6 %s", typestr); in gen_host6()
5287 return gen_hostop6(cstate, addr, mask, dir, ETHERTYPE_IPV6, 8, 24); in gen_host6()
5290 bpf_error(cstate, "'icmp6' modifier applied to ip6 %s", typestr); in gen_host6()
5293 bpf_error(cstate, "'ah' modifier applied to ip6 %s", typestr); in gen_host6()
5296 bpf_error(cstate, "'esp' modifier applied to ip6 %s", typestr); in gen_host6()
5299 bpf_error(cstate, "'pim' modifier applied to ip6 %s", typestr); in gen_host6()
5302 bpf_error(cstate, "'vrrp' modifier applied to ip6 %s", typestr); in gen_host6()
5305 bpf_error(cstate, "'aarp' modifier applied to ip6 %s", typestr); in gen_host6()
5308 bpf_error(cstate, "'iso' modifier applied to ip6 %s", typestr); in gen_host6()
5311 bpf_error(cstate, "'esis' modifier applied to ip6 %s", typestr); in gen_host6()
5314 bpf_error(cstate, "'isis' modifier applied to ip6 %s", typestr); in gen_host6()
5317 bpf_error(cstate, "'clnp' modifier applied to ip6 %s", typestr); in gen_host6()
5320 bpf_error(cstate, "'stp' modifier applied to ip6 %s", typestr); in gen_host6()
5323 bpf_error(cstate, "'ipx' modifier applied to ip6 %s", typestr); in gen_host6()
5326 bpf_error(cstate, "'netbeui' modifier applied to ip6 %s", typestr); in gen_host6()
5329 bpf_error(cstate, "'l1' modifier applied to ip6 %s", typestr); in gen_host6()
5332 bpf_error(cstate, "'l2' modifier applied to ip6 %s", typestr); in gen_host6()
5335 bpf_error(cstate, "'iih' modifier applied to ip6 %s", typestr); in gen_host6()
5338 bpf_error(cstate, "'snp' modifier applied to ip6 %s", typestr); in gen_host6()
5341 bpf_error(cstate, "'csnp' modifier applied to ip6 %s", typestr); in gen_host6()
5344 bpf_error(cstate, "'psnp' modifier applied to ip6 %s", typestr); in gen_host6()
5347 bpf_error(cstate, "'lsp' modifier applied to ip6 %s", typestr); in gen_host6()
5350 bpf_error(cstate, "'radio' modifier applied to ip6 %s", typestr); in gen_host6()
5353 bpf_error(cstate, "'carp' modifier applied to ip6 %s", typestr); in gen_host6()
5364 gen_gateway(compiler_state_t *cstate, const u_char *eaddr, in gen_gateway() argument
5372 bpf_error(cstate, "direction applied to 'gateway'"); in gen_gateway()
5379 switch (cstate->linktype) { in gen_gateway()
5383 b1 = gen_prevlinkhdr_check(cstate); in gen_gateway()
5384 b0 = gen_ehostop(cstate, eaddr, Q_OR); in gen_gateway()
5389 b0 = gen_fhostop(cstate, eaddr, Q_OR); in gen_gateway()
5392 b0 = gen_thostop(cstate, eaddr, Q_OR); in gen_gateway()
5399 b0 = gen_wlanhostop(cstate, eaddr, Q_OR); in gen_gateway()
5407 bpf_error(cstate, in gen_gateway()
5410 b0 = gen_ipfchostop(cstate, eaddr, Q_OR); in gen_gateway()
5413 bpf_error(cstate, in gen_gateway()
5430 tmp = gen_host(cstate, in gen_gateway()
5463 bpf_error(cstate, "illegal modifier of 'gateway'"); in gen_gateway()
5469 gen_proto_abbrev_internal(compiler_state_t *cstate, int proto) in gen_proto_abbrev_internal() argument
5477 b1 = gen_proto(cstate, IPPROTO_SCTP, Q_DEFAULT, Q_DEFAULT); in gen_proto_abbrev_internal()
5481 b1 = gen_proto(cstate, IPPROTO_TCP, Q_DEFAULT, Q_DEFAULT); in gen_proto_abbrev_internal()
5485 b1 = gen_proto(cstate, IPPROTO_UDP, Q_DEFAULT, Q_DEFAULT); in gen_proto_abbrev_internal()
5489 b1 = gen_proto(cstate, IPPROTO_ICMP, Q_IP, Q_DEFAULT); in gen_proto_abbrev_internal()
5497 b1 = gen_proto(cstate, IPPROTO_IGMP, Q_IP, Q_DEFAULT); in gen_proto_abbrev_internal()
5504 b1 = gen_proto(cstate, IPPROTO_IGRP, Q_IP, Q_DEFAULT); in gen_proto_abbrev_internal()
5512 b1 = gen_proto(cstate, IPPROTO_PIM, Q_DEFAULT, Q_DEFAULT); in gen_proto_abbrev_internal()
5520 b1 = gen_proto(cstate, IPPROTO_VRRP, Q_IP, Q_DEFAULT); in gen_proto_abbrev_internal()
5528 b1 = gen_proto(cstate, IPPROTO_CARP, Q_IP, Q_DEFAULT); in gen_proto_abbrev_internal()
5532 b1 = gen_linktype(cstate, ETHERTYPE_IP); in gen_proto_abbrev_internal()
5536 b1 = gen_linktype(cstate, ETHERTYPE_ARP); in gen_proto_abbrev_internal()
5540 b1 = gen_linktype(cstate, ETHERTYPE_REVARP); in gen_proto_abbrev_internal()
5544 bpf_error(cstate, "link layer applied in wrong context"); in gen_proto_abbrev_internal()
5547 b1 = gen_linktype(cstate, ETHERTYPE_ATALK); in gen_proto_abbrev_internal()
5551 b1 = gen_linktype(cstate, ETHERTYPE_AARP); in gen_proto_abbrev_internal()
5555 b1 = gen_linktype(cstate, ETHERTYPE_DN); in gen_proto_abbrev_internal()
5559 b1 = gen_linktype(cstate, ETHERTYPE_SCA); in gen_proto_abbrev_internal()
5563 b1 = gen_linktype(cstate, ETHERTYPE_LAT); in gen_proto_abbrev_internal()
5567 b1 = gen_linktype(cstate, ETHERTYPE_MOPDL); in gen_proto_abbrev_internal()
5571 b1 = gen_linktype(cstate, ETHERTYPE_MOPRC); in gen_proto_abbrev_internal()
5575 b1 = gen_linktype(cstate, ETHERTYPE_IPV6); in gen_proto_abbrev_internal()
5582 b1 = gen_proto(cstate, IPPROTO_ICMPV6, Q_IPV6, Q_DEFAULT); in gen_proto_abbrev_internal()
5589 b1 = gen_proto(cstate, IPPROTO_AH, Q_DEFAULT, Q_DEFAULT); in gen_proto_abbrev_internal()
5596 b1 = gen_proto(cstate, IPPROTO_ESP, Q_DEFAULT, Q_DEFAULT); in gen_proto_abbrev_internal()
5600 b1 = gen_linktype(cstate, LLCSAP_ISONS); in gen_proto_abbrev_internal()
5604 b1 = gen_proto(cstate, ISO9542_ESIS, Q_ISO, Q_DEFAULT); in gen_proto_abbrev_internal()
5608 b1 = gen_proto(cstate, ISO10589_ISIS, Q_ISO, Q_DEFAULT); in gen_proto_abbrev_internal()
5612 b0 = gen_proto(cstate, ISIS_L1_LAN_IIH, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5613 b1 = gen_proto(cstate, ISIS_PTP_IIH, Q_ISIS, Q_DEFAULT); /* FIXME extract the circuit-type bits */ in gen_proto_abbrev_internal()
5615 b0 = gen_proto(cstate, ISIS_L1_LSP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5617 b0 = gen_proto(cstate, ISIS_L1_CSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5619 b0 = gen_proto(cstate, ISIS_L1_PSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5624 b0 = gen_proto(cstate, ISIS_L2_LAN_IIH, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5625 b1 = gen_proto(cstate, ISIS_PTP_IIH, Q_ISIS, Q_DEFAULT); /* FIXME extract the circuit-type bits */ in gen_proto_abbrev_internal()
5627 b0 = gen_proto(cstate, ISIS_L2_LSP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5629 b0 = gen_proto(cstate, ISIS_L2_CSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5631 b0 = gen_proto(cstate, ISIS_L2_PSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5636 b0 = gen_proto(cstate, ISIS_L1_LAN_IIH, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5637 b1 = gen_proto(cstate, ISIS_L2_LAN_IIH, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5639 b0 = gen_proto(cstate, ISIS_PTP_IIH, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5644 b0 = gen_proto(cstate, ISIS_L1_LSP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5645 b1 = gen_proto(cstate, ISIS_L2_LSP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5650 b0 = gen_proto(cstate, ISIS_L1_CSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5651 b1 = gen_proto(cstate, ISIS_L2_CSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5653 b0 = gen_proto(cstate, ISIS_L1_PSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5655 b0 = gen_proto(cstate, ISIS_L2_PSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5660 b0 = gen_proto(cstate, ISIS_L1_CSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5661 b1 = gen_proto(cstate, ISIS_L2_CSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5666 b0 = gen_proto(cstate, ISIS_L1_PSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5667 b1 = gen_proto(cstate, ISIS_L2_PSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5672 b1 = gen_proto(cstate, ISO8473_CLNP, Q_ISO, Q_DEFAULT); in gen_proto_abbrev_internal()
5676 b1 = gen_linktype(cstate, LLCSAP_8021D); in gen_proto_abbrev_internal()
5680 b1 = gen_linktype(cstate, LLCSAP_IPX); in gen_proto_abbrev_internal()
5684 b1 = gen_linktype(cstate, LLCSAP_NETBEUI); in gen_proto_abbrev_internal()
5688 bpf_error(cstate, "'radio' is not a valid protocol type"); in gen_proto_abbrev_internal()
5697 gen_proto_abbrev(compiler_state_t *cstate, int proto) in gen_proto_abbrev() argument
5703 if (setjmp(cstate->top_ctx)) in gen_proto_abbrev()
5706 return gen_proto_abbrev_internal(cstate, proto); in gen_proto_abbrev()
5710 gen_ipfrag(compiler_state_t *cstate) in gen_ipfrag() argument
5716 s = gen_load_a(cstate, OR_LINKPL, 6, BPF_H); in gen_ipfrag()
5717 b = new_block(cstate, JMP(BPF_JSET)); in gen_ipfrag()
5735 gen_portatom(compiler_state_t *cstate, int off, bpf_u_int32 v) in gen_portatom() argument
5737 return gen_cmp(cstate, OR_TRAN_IPV4, off, BPF_H, v); in gen_portatom()
5741 gen_portatom6(compiler_state_t *cstate, int off, bpf_u_int32 v) in gen_portatom6() argument
5743 return gen_cmp(cstate, OR_TRAN_IPV6, off, BPF_H, v); in gen_portatom6()
5747 gen_portop(compiler_state_t *cstate, u_int port, u_int proto, int dir) in gen_portop() argument
5752 tmp = gen_cmp(cstate, OR_LINKPL, 9, BPF_B, proto); in gen_portop()
5753 b0 = gen_ipfrag(cstate); in gen_portop()
5758 b1 = gen_portatom(cstate, 0, port); in gen_portop()
5762 b1 = gen_portatom(cstate, 2, port); in gen_portop()
5766 tmp = gen_portatom(cstate, 0, port); in gen_portop()
5767 b1 = gen_portatom(cstate, 2, port); in gen_portop()
5773 tmp = gen_portatom(cstate, 0, port); in gen_portop()
5774 b1 = gen_portatom(cstate, 2, port); in gen_portop()
5779 bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for ports"); in gen_portop()
5783 bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for ports"); in gen_portop()
5787 bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for ports"); in gen_portop()
5791 bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for ports"); in gen_portop()
5795 bpf_error(cstate, "'ra' is not a valid qualifier for ports"); in gen_portop()
5799 bpf_error(cstate, "'ta' is not a valid qualifier for ports"); in gen_portop()
5812 gen_port(compiler_state_t *cstate, u_int port, int ip_proto, int dir) in gen_port() argument
5833 b0 = gen_linktype(cstate, ETHERTYPE_IP); in gen_port()
5839 b1 = gen_portop(cstate, port, (u_int)ip_proto, dir); in gen_port()
5843 tmp = gen_portop(cstate, port, IPPROTO_TCP, dir); in gen_port()
5844 b1 = gen_portop(cstate, port, IPPROTO_UDP, dir); in gen_port()
5846 tmp = gen_portop(cstate, port, IPPROTO_SCTP, dir); in gen_port()
5858 gen_portop6(compiler_state_t *cstate, u_int port, u_int proto, int dir) in gen_portop6() argument
5864 b0 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, proto); in gen_portop6()
5868 b1 = gen_portatom6(cstate, 0, port); in gen_portop6()
5872 b1 = gen_portatom6(cstate, 2, port); in gen_portop6()
5876 tmp = gen_portatom6(cstate, 0, port); in gen_portop6()
5877 b1 = gen_portatom6(cstate, 2, port); in gen_portop6()
5883 tmp = gen_portatom6(cstate, 0, port); in gen_portop6()
5884 b1 = gen_portatom6(cstate, 2, port); in gen_portop6()
5897 gen_port6(compiler_state_t *cstate, u_int port, int ip_proto, int dir) in gen_port6() argument
5902 b0 = gen_linktype(cstate, ETHERTYPE_IPV6); in gen_port6()
5908 b1 = gen_portop6(cstate, port, (u_int)ip_proto, dir); in gen_port6()
5912 tmp = gen_portop6(cstate, port, IPPROTO_TCP, dir); in gen_port6()
5913 b1 = gen_portop6(cstate, port, IPPROTO_UDP, dir); in gen_port6()
5915 tmp = gen_portop6(cstate, port, IPPROTO_SCTP, dir); in gen_port6()
5928 gen_portrangeatom(compiler_state_t *cstate, u_int off, bpf_u_int32 v1, in gen_portrangeatom() argument
5944 b1 = gen_cmp_ge(cstate, OR_TRAN_IPV4, off, BPF_H, v1); in gen_portrangeatom()
5945 b2 = gen_cmp_le(cstate, OR_TRAN_IPV4, off, BPF_H, v2); in gen_portrangeatom()
5953 gen_portrangeop(compiler_state_t *cstate, u_int port1, u_int port2, in gen_portrangeop() argument
5959 tmp = gen_cmp(cstate, OR_LINKPL, 9, BPF_B, proto); in gen_portrangeop()
5960 b0 = gen_ipfrag(cstate); in gen_portrangeop()
5965 b1 = gen_portrangeatom(cstate, 0, port1, port2); in gen_portrangeop()
5969 b1 = gen_portrangeatom(cstate, 2, port1, port2); in gen_portrangeop()
5973 tmp = gen_portrangeatom(cstate, 0, port1, port2); in gen_portrangeop()
5974 b1 = gen_portrangeatom(cstate, 2, port1, port2); in gen_portrangeop()
5980 tmp = gen_portrangeatom(cstate, 0, port1, port2); in gen_portrangeop()
5981 b1 = gen_portrangeatom(cstate, 2, port1, port2); in gen_portrangeop()
5986 bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for port ranges"); in gen_portrangeop()
5990 bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for port ranges"); in gen_portrangeop()
5994 bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for port ranges"); in gen_portrangeop()
5998 bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for port ranges"); in gen_portrangeop()
6002 bpf_error(cstate, "'ra' is not a valid qualifier for port ranges"); in gen_portrangeop()
6006 bpf_error(cstate, "'ta' is not a valid qualifier for port ranges"); in gen_portrangeop()
6019 gen_portrange(compiler_state_t *cstate, u_int port1, u_int port2, int ip_proto, in gen_portrange() argument
6025 b0 = gen_linktype(cstate, ETHERTYPE_IP); in gen_portrange()
6031 b1 = gen_portrangeop(cstate, port1, port2, (bpf_u_int32)ip_proto, in gen_portrange()
6036 tmp = gen_portrangeop(cstate, port1, port2, IPPROTO_TCP, dir); in gen_portrange()
6037 b1 = gen_portrangeop(cstate, port1, port2, IPPROTO_UDP, dir); in gen_portrange()
6039 tmp = gen_portrangeop(cstate, port1, port2, IPPROTO_SCTP, dir); in gen_portrange()
6051 gen_portrangeatom6(compiler_state_t *cstate, u_int off, bpf_u_int32 v1, in gen_portrangeatom6() argument
6067 b1 = gen_cmp_ge(cstate, OR_TRAN_IPV6, off, BPF_H, v1); in gen_portrangeatom6()
6068 b2 = gen_cmp_le(cstate, OR_TRAN_IPV6, off, BPF_H, v2); in gen_portrangeatom6()
6076 gen_portrangeop6(compiler_state_t *cstate, u_int port1, u_int port2, in gen_portrangeop6() argument
6083 b0 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, proto); in gen_portrangeop6()
6087 b1 = gen_portrangeatom6(cstate, 0, port1, port2); in gen_portrangeop6()
6091 b1 = gen_portrangeatom6(cstate, 2, port1, port2); in gen_portrangeop6()
6095 tmp = gen_portrangeatom6(cstate, 0, port1, port2); in gen_portrangeop6()
6096 b1 = gen_portrangeatom6(cstate, 2, port1, port2); in gen_portrangeop6()
6102 tmp = gen_portrangeatom6(cstate, 0, port1, port2); in gen_portrangeop6()
6103 b1 = gen_portrangeatom6(cstate, 2, port1, port2); in gen_portrangeop6()
6116 gen_portrange6(compiler_state_t *cstate, u_int port1, u_int port2, int ip_proto, in gen_portrange6() argument
6122 b0 = gen_linktype(cstate, ETHERTYPE_IPV6); in gen_portrange6()
6128 b1 = gen_portrangeop6(cstate, port1, port2, (bpf_u_int32)ip_proto, in gen_portrange6()
6133 tmp = gen_portrangeop6(cstate, port1, port2, IPPROTO_TCP, dir); in gen_portrange6()
6134 b1 = gen_portrangeop6(cstate, port1, port2, IPPROTO_UDP, dir); in gen_portrange6()
6136 tmp = gen_portrangeop6(cstate, port1, port2, IPPROTO_SCTP, dir); in gen_portrange6()
6148 lookup_proto(compiler_state_t *cstate, const char *name, int proto) in lookup_proto() argument
6159 bpf_error(cstate, "unknown ip proto '%s'", name); in lookup_proto()
6168 bpf_error(cstate, "unknown ether proto '%s'", name); in lookup_proto()
6180 bpf_error(cstate, "unknown osi proto '%s'", name); in lookup_proto()
6192 gen_protochain(compiler_state_t *cstate, bpf_u_int32 v, int proto) in gen_protochain() argument
6199 int reg2 = alloc_reg(cstate); in gen_protochain()
6209 b0 = gen_protochain(cstate, v, Q_IP); in gen_protochain()
6210 b = gen_protochain(cstate, v, Q_IPV6); in gen_protochain()
6214 bpf_error(cstate, "bad protocol applied for 'protochain'"); in gen_protochain()
6229 if (cstate->off_linkpl.is_variable) in gen_protochain()
6230 bpf_error(cstate, "'protochain' not supported with variable length headers"); in gen_protochain()
6243 cstate->no_optimize = 1; in gen_protochain()
6251 s[i] = new_stmt(cstate, 0); /*dummy*/ in gen_protochain()
6256 b0 = gen_linktype(cstate, ETHERTYPE_IP); in gen_protochain()
6259 s[i] = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_B); in gen_protochain()
6260 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 9; in gen_protochain()
6263 s[i] = new_stmt(cstate, BPF_LDX|BPF_MSH|BPF_B); in gen_protochain()
6264 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_protochain()
6269 b0 = gen_linktype(cstate, ETHERTYPE_IPV6); in gen_protochain()
6272 s[i] = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_B); in gen_protochain()
6273 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 6; in gen_protochain()
6276 s[i] = new_stmt(cstate, BPF_LDX|BPF_IMM); in gen_protochain()
6282 bpf_error(cstate, "unsupported proto to gen_protochain"); in gen_protochain()
6288 s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
6299 s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
6312 s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
6319 s[i - 1]->s.jf = s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
6325 s[i - 1]->s.jf = s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
6331 s[i - 1]->s.jf = s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
6348 s[i] = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_protochain()
6349 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_protochain()
6352 s[i] = new_stmt(cstate, BPF_ST); in gen_protochain()
6356 s[i] = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_protochain()
6357 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 1; in gen_protochain()
6360 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_protochain()
6364 s[i] = new_stmt(cstate, BPF_ALU|BPF_MUL|BPF_K); in gen_protochain()
6368 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X); in gen_protochain()
6372 s[i] = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_protochain()
6375 s[i] = new_stmt(cstate, BPF_LD|BPF_MEM); in gen_protochain()
6380 s[i] = new_stmt(cstate, BPF_JMP|BPF_JA); in gen_protochain()
6390 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_protochain()
6399 s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
6414 s[i - 1]->s.jt = s[i] = new_stmt(cstate, BPF_MISC|BPF_TXA); in gen_protochain()
6417 s[i] = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_protochain()
6418 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_protochain()
6421 s[i] = new_stmt(cstate, BPF_ST); in gen_protochain()
6425 s[i - 1]->s.jt = s[i] = new_stmt(cstate, BPF_MISC|BPF_TXA); in gen_protochain()
6428 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_protochain()
6432 s[i] = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_protochain()
6435 s[i] = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_protochain()
6436 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_protochain()
6439 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_protochain()
6443 s[i] = new_stmt(cstate, BPF_ALU|BPF_MUL|BPF_K); in gen_protochain()
6447 s[i] = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_protochain()
6450 s[i] = new_stmt(cstate, BPF_LD|BPF_MEM); in gen_protochain()
6455 s[i] = new_stmt(cstate, BPF_JMP|BPF_JA); in gen_protochain()
6461 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_protochain()
6479 b = new_block(cstate, JMP(BPF_JEQ)); in gen_protochain()
6483 free_reg(cstate, reg2); in gen_protochain()
6491 gen_check_802_11_data_frame(compiler_state_t *cstate) in gen_check_802_11_data_frame() argument
6500 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_check_802_11_data_frame()
6501 b0 = new_block(cstate, JMP(BPF_JSET)); in gen_check_802_11_data_frame()
6505 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_check_802_11_data_frame()
6506 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_check_802_11_data_frame()
6526 gen_proto(compiler_state_t *cstate, bpf_u_int32 v, int proto, int dir) in gen_proto() argument
6532 bpf_error(cstate, "direction applied to 'proto'"); in gen_proto()
6536 b0 = gen_proto(cstate, v, Q_IP, dir); in gen_proto()
6537 b1 = gen_proto(cstate, v, Q_IPV6, dir); in gen_proto()
6542 return gen_linktype(cstate, v); in gen_proto()
6560 b0 = gen_linktype(cstate, ETHERTYPE_IP); in gen_proto()
6561 b1 = gen_cmp(cstate, OR_LINKPL, 9, BPF_B, v); in gen_proto()
6566 bpf_error(cstate, "arp does not encapsulate another protocol"); in gen_proto()
6570 bpf_error(cstate, "rarp does not encapsulate another protocol"); in gen_proto()
6574 bpf_error(cstate, "'sctp proto' is bogus"); in gen_proto()
6578 bpf_error(cstate, "'tcp proto' is bogus"); in gen_proto()
6582 bpf_error(cstate, "'udp proto' is bogus"); in gen_proto()
6586 bpf_error(cstate, "'icmp proto' is bogus"); in gen_proto()
6590 bpf_error(cstate, "'igmp proto' is bogus"); in gen_proto()
6594 bpf_error(cstate, "'igrp proto' is bogus"); in gen_proto()
6598 bpf_error(cstate, "AppleTalk encapsulation is not specifiable"); in gen_proto()
6602 bpf_error(cstate, "DECNET encapsulation is not specifiable"); in gen_proto()
6606 bpf_error(cstate, "LAT does not encapsulate another protocol"); in gen_proto()
6610 bpf_error(cstate, "SCA does not encapsulate another protocol"); in gen_proto()
6614 bpf_error(cstate, "MOPRC does not encapsulate another protocol"); in gen_proto()
6618 bpf_error(cstate, "MOPDL does not encapsulate another protocol"); in gen_proto()
6622 b0 = gen_linktype(cstate, ETHERTYPE_IPV6); in gen_proto()
6627 b2 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, IPPROTO_FRAGMENT); in gen_proto()
6628 b1 = gen_cmp(cstate, OR_LINKPL, 40, BPF_B, v); in gen_proto()
6630 b2 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, v); in gen_proto()
6636 bpf_error(cstate, "'icmp6 proto' is bogus"); in gen_proto()
6640 bpf_error(cstate, "'ah proto' is bogus"); in gen_proto()
6644 bpf_error(cstate, "'esp proto' is bogus"); in gen_proto()
6648 bpf_error(cstate, "'pim proto' is bogus"); in gen_proto()
6652 bpf_error(cstate, "'vrrp proto' is bogus"); in gen_proto()
6656 bpf_error(cstate, "'aarp proto' is bogus"); in gen_proto()
6660 switch (cstate->linktype) { in gen_proto()
6681 return gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | v); in gen_proto()
6690 b0 = gen_linktype(cstate, LLCSAP_ISONS<<8 | LLCSAP_ISONS); in gen_proto()
6692 b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 1, BPF_B, v); in gen_proto()
6697 b0 = gen_linktype(cstate, LLCSAP_ISONS); in gen_proto()
6698 b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 0, BPF_B, v); in gen_proto()
6704 bpf_error(cstate, "'esis proto' is bogus"); in gen_proto()
6708 b0 = gen_proto(cstate, ISO10589_ISIS, Q_ISO, Q_DEFAULT); in gen_proto()
6713 b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 4, BPF_B, v); in gen_proto()
6718 bpf_error(cstate, "'clnp proto' is not supported"); in gen_proto()
6722 bpf_error(cstate, "'stp proto' is bogus"); in gen_proto()
6726 bpf_error(cstate, "'ipx proto' is bogus"); in gen_proto()
6730 bpf_error(cstate, "'netbeui proto' is bogus"); in gen_proto()
6734 bpf_error(cstate, "'l1 proto' is bogus"); in gen_proto()
6738 bpf_error(cstate, "'l2 proto' is bogus"); in gen_proto()
6742 bpf_error(cstate, "'iih proto' is bogus"); in gen_proto()
6746 bpf_error(cstate, "'snp proto' is bogus"); in gen_proto()
6750 bpf_error(cstate, "'csnp proto' is bogus"); in gen_proto()
6754 bpf_error(cstate, "'psnp proto' is bogus"); in gen_proto()
6758 bpf_error(cstate, "'lsp proto' is bogus"); in gen_proto()
6762 bpf_error(cstate, "'radio proto' is bogus"); in gen_proto()
6766 bpf_error(cstate, "'carp proto' is bogus"); in gen_proto()
6780 nametoport(compiler_state_t *cstate, const char *name, int ipproto) in nametoport() argument
6820 bpf_set_error(cstate, "getaddrinfo(\"%s\" fails with system error: %d", in nametoport()
6839 bpf_set_error(cstate, "getaddrinfo(\"%s\") fails with error: %d", in nametoport()
6879 stringtoport(compiler_state_t *cstate, const char *string, size_t string_size, in stringtoport() argument
6891 ret = stoulen(string, string_size, &val, cstate); in stringtoport()
6908 tcp_port = nametoport(cstate, cpy, IPPROTO_TCP); in stringtoport()
6915 longjmp(cstate->top_ctx, 1); in stringtoport()
6918 udp_port = nametoport(cstate, cpy, IPPROTO_UDP); in stringtoport()
6925 longjmp(cstate->top_ctx, 1); in stringtoport()
6967 bpf_set_error(cstate, "'%s' is not a valid port", cpy); in stringtoport()
6969 longjmp(cstate->top_ctx, 1); in stringtoport()
6974 longjmp(cstate->top_ctx, 1); in stringtoport()
6979 bpf_set_error(cstate, "stoulen returned %d - this should not happen", ret); in stringtoport()
6980 longjmp(cstate->top_ctx, 1); in stringtoport()
6991 stringtoportrange(compiler_state_t *cstate, const char *string, in stringtoportrange() argument
7000 bpf_error(cstate, "port range '%s' contains no hyphen", string); in stringtoportrange()
7010 bpf_error(cstate, "port range '%s' contains more than one hyphen", in stringtoportrange()
7020 bpf_error(cstate, "port range '%s' has no starting port", string); in stringtoportrange()
7026 *port1 = stringtoport(cstate, first, first_size, proto); in stringtoportrange()
7036 bpf_error(cstate, "port range '%s' has no ending port", string); in stringtoportrange()
7042 *port2 = stringtoport(cstate, second, second_size, proto); in stringtoportrange()
7048 gen_scode(compiler_state_t *cstate, const char *name, struct qual q) in gen_scode() argument
7071 if (setjmp(cstate->top_ctx)) in gen_scode()
7079 bpf_error(cstate, "unknown network '%s'", name); in gen_scode()
7086 return gen_host(cstate, addr, mask, proto, dir, q.addr); in gen_scode()
7091 switch (cstate->linktype) { in gen_scode()
7098 bpf_error(cstate, in gen_scode()
7102 tmp = gen_prevlinkhdr_check(cstate); in gen_scode()
7103 b = gen_ehostop(cstate, eaddr, dir); in gen_scode()
7111 bpf_error(cstate, in gen_scode()
7115 b = gen_fhostop(cstate, eaddr, dir); in gen_scode()
7121 bpf_error(cstate, in gen_scode()
7125 b = gen_thostop(cstate, eaddr, dir); in gen_scode()
7135 bpf_error(cstate, in gen_scode()
7139 b = gen_wlanhostop(cstate, eaddr, dir); in gen_scode()
7145 bpf_error(cstate, in gen_scode()
7149 b = gen_ipfchostop(cstate, eaddr, dir); in gen_scode()
7153 …bpf_error(cstate, "only ethernet/FDDI/token ring/802.11/ATM LANE/Fibre Channel supports link-level… in gen_scode()
7159 bpf_error(cstate, "unknown decnet host name '%s'\n", name); in gen_scode()
7161 bpf_error(cstate, "decnet name support not included, '%s' cannot be translated\n", in gen_scode()
7169 return (gen_host(cstate, dn_addr, 0, proto, dir, q.addr)); in gen_scode()
7176 bpf_error(cstate, "unknown host '%s'", name); in gen_scode()
7177 cstate->ai = res; in gen_scode()
7183 if (cstate->off_linktype.constant_part == OFFSET_NOT_SET && in gen_scode()
7205 tmp = gen_host(cstate, ntohl(sin4->sin_addr.s_addr), in gen_scode()
7221 tmp = gen_host6(cstate, &sin6->sin6_addr, in gen_scode()
7232 cstate->ai = NULL; in gen_scode()
7235 bpf_error(cstate, "unknown host '%s'%s", name, in gen_scode()
7246 bpf_error(cstate, "illegal qualifier of 'port'"); in gen_scode()
7248 bpf_error(cstate, "unknown port '%s'", name); in gen_scode()
7251 bpf_error(cstate, "port '%s' is tcp", name); in gen_scode()
7253 bpf_error(cstate, "port '%s' is sctp", name); in gen_scode()
7260 bpf_error(cstate, "port '%s' is udp", name); in gen_scode()
7263 bpf_error(cstate, "port '%s' is sctp", name); in gen_scode()
7270 bpf_error(cstate, "port '%s' is udp", name); in gen_scode()
7273 bpf_error(cstate, "port '%s' is tcp", name); in gen_scode()
7279 bpf_error(cstate, "illegal port number %d < 0", port); in gen_scode()
7281 bpf_error(cstate, "illegal port number %d > 65535", port); in gen_scode()
7282 b = gen_port(cstate, port, real_proto, dir); in gen_scode()
7283 gen_or(gen_port6(cstate, port, real_proto, dir), b); in gen_scode()
7289 bpf_error(cstate, "illegal qualifier of 'portrange'"); in gen_scode()
7290 stringtoportrange(cstate, name, &port1, &port2, &real_proto); in gen_scode()
7293 bpf_error(cstate, "port in range '%s' is tcp", name); in gen_scode()
7295 bpf_error(cstate, "port in range '%s' is sctp", name); in gen_scode()
7302 bpf_error(cstate, "port in range '%s' is udp", name); in gen_scode()
7304 bpf_error(cstate, "port in range '%s' is sctp", name); in gen_scode()
7311 bpf_error(cstate, "port in range '%s' is udp", name); in gen_scode()
7313 bpf_error(cstate, "port in range '%s' is tcp", name); in gen_scode()
7319 bpf_error(cstate, "illegal port number %d > 65535", port1); in gen_scode()
7321 bpf_error(cstate, "illegal port number %d > 65535", port2); in gen_scode()
7323 b = gen_portrange(cstate, port1, port2, real_proto, dir); in gen_scode()
7324 gen_or(gen_portrange6(cstate, port1, port2, real_proto, dir), b); in gen_scode()
7331 bpf_error(cstate, "unknown ether host: %s", name); in gen_scode()
7336 cstate->ai = res; in gen_scode()
7338 bpf_error(cstate, "unknown host '%s'", name); in gen_scode()
7339 b = gen_gateway(cstate, eaddr, res, proto, dir); in gen_scode()
7340 cstate->ai = NULL; in gen_scode()
7343 bpf_error(cstate, "unknown host '%s'", name); in gen_scode()
7346 bpf_error(cstate, "'gateway' not supported in this configuration"); in gen_scode()
7350 real_proto = lookup_proto(cstate, name, proto); in gen_scode()
7352 return gen_proto(cstate, real_proto, proto, dir); in gen_scode()
7354 bpf_error(cstate, "unknown protocol: %s", name); in gen_scode()
7358 real_proto = lookup_proto(cstate, name, proto); in gen_scode()
7360 return gen_protochain(cstate, real_proto, proto); in gen_scode()
7362 bpf_error(cstate, "unknown protocol: %s", name); in gen_scode()
7366 syntax(cstate); in gen_scode()
7374 gen_mcode(compiler_state_t *cstate, const char *s1, const char *s2, in gen_mcode() argument
7385 if (setjmp(cstate->top_ctx)) in gen_mcode()
7390 bpf_error(cstate, "invalid IPv4 address '%s'", s1); in gen_mcode()
7397 bpf_error(cstate, "invalid IPv4 address '%s'", s2); in gen_mcode()
7401 bpf_error(cstate, "non-network bits set in \"%s mask %s\"", in gen_mcode()
7406 bpf_error(cstate, "mask length must be <= 32"); in gen_mcode()
7410 bpf_error(cstate, "non-network bits set in \"%s/%d\"", in gen_mcode()
7417 return gen_host(cstate, n, m, q.proto, q.dir, q.addr); in gen_mcode()
7420 bpf_error(cstate, "Mask syntax for networks only"); in gen_mcode()
7427 gen_ncode(compiler_state_t *cstate, const char *s, bpf_u_int32 v, struct qual q) in gen_ncode() argument
7438 if (setjmp(cstate->top_ctx)) in gen_ncode()
7448 bpf_error(cstate, "malformed decnet address '%s'", s); in gen_ncode()
7452 bpf_error(cstate, "invalid IPv4 address '%s'", s); in gen_ncode()
7461 return gen_host(cstate, v, 0, proto, dir, q.addr); in gen_ncode()
7463 bpf_error(cstate, "illegal link layer address"); in gen_ncode()
7477 return gen_host(cstate, v, mask, proto, dir, q.addr); in gen_ncode()
7490 bpf_error(cstate, "illegal qualifier of 'port'"); in gen_ncode()
7493 bpf_error(cstate, "illegal port number %u > 65535", v); in gen_ncode()
7497 b = gen_port(cstate, v, proto, dir); in gen_ncode()
7498 gen_or(gen_port6(cstate, v, proto, dir), b); in gen_ncode()
7512 bpf_error(cstate, "illegal qualifier of 'portrange'"); in gen_ncode()
7515 bpf_error(cstate, "illegal port number %u > 65535", v); in gen_ncode()
7519 b = gen_portrange(cstate, v, v, proto, dir); in gen_ncode()
7520 gen_or(gen_portrange6(cstate, v, v, proto, dir), b); in gen_ncode()
7525 bpf_error(cstate, "'gateway' requires a name"); in gen_ncode()
7529 return gen_proto(cstate, v, proto, dir); in gen_ncode()
7533 return gen_protochain(cstate, v, proto); in gen_ncode()
7537 syntax(cstate); in gen_ncode()
7549 gen_mcode6(compiler_state_t *cstate, const char *s, bpf_u_int32 masklen, in gen_mcode6() argument
7562 if (setjmp(cstate->top_ctx)) in gen_mcode6()
7567 bpf_error(cstate, "invalid ip6 address %s", s); in gen_mcode6()
7568 cstate->ai = res; in gen_mcode6()
7570 bpf_error(cstate, "%s resolved to multiple address", s); in gen_mcode6()
7574 bpf_error(cstate, "mask length must be <= %zu", sizeof(mask.s6_addr) * 8); in gen_mcode6()
7586 bpf_error(cstate, "non-network bits set in \"%s/%d\"", s, masklen); in gen_mcode6()
7594 bpf_error(cstate, "Mask syntax for networks only"); in gen_mcode6()
7598 b = gen_host6(cstate, addr, &mask, q.proto, q.dir, q.addr); in gen_mcode6()
7599 cstate->ai = NULL; in gen_mcode6()
7604 bpf_error(cstate, "invalid qualifier against IPv6 address"); in gen_mcode6()
7611 gen_ecode(compiler_state_t *cstate, const char *s, struct qual q) in gen_ecode() argument
7619 if (setjmp(cstate->top_ctx)) in gen_ecode()
7628 cstate->e = pcap_ether_aton(s); in gen_ecode()
7629 if (cstate->e == NULL) in gen_ecode()
7630 bpf_error(cstate, "malloc"); in gen_ecode()
7631 switch (cstate->linktype) { in gen_ecode()
7635 tmp = gen_prevlinkhdr_check(cstate); in gen_ecode()
7636 b = gen_ehostop(cstate, cstate->e, (int)q.dir); in gen_ecode()
7641 b = gen_fhostop(cstate, cstate->e, (int)q.dir); in gen_ecode()
7644 b = gen_thostop(cstate, cstate->e, (int)q.dir); in gen_ecode()
7651 b = gen_wlanhostop(cstate, cstate->e, (int)q.dir); in gen_ecode()
7654 b = gen_ipfchostop(cstate, cstate->e, (int)q.dir); in gen_ecode()
7657 free(cstate->e); in gen_ecode()
7658 cstate->e = NULL; in gen_ecode()
7659 …bpf_error(cstate, "ethernet addresses supported only on ethernet/FDDI/token ring/802.11/ATM LANE/F… in gen_ecode()
7662 free(cstate->e); in gen_ecode()
7663 cstate->e = NULL; in gen_ecode()
7666 bpf_error(cstate, "ethernet address used in non-ether expression"); in gen_ecode()
7683 xfer_to_x(compiler_state_t *cstate, struct arth *a) in xfer_to_x() argument
7687 s = new_stmt(cstate, BPF_LDX|BPF_MEM); in xfer_to_x()
7693 xfer_to_a(compiler_state_t *cstate, struct arth *a) in xfer_to_a() argument
7697 s = new_stmt(cstate, BPF_LD|BPF_MEM); in xfer_to_a()
7710 gen_load_internal(compiler_state_t *cstate, int proto, struct arth *inst, in gen_load_internal() argument
7716 int regno = alloc_reg(cstate); in gen_load_internal()
7718 free_reg(cstate, inst->regno); in gen_load_internal()
7722 bpf_error(cstate, "data size must be 1, 2, or 4"); in gen_load_internal()
7739 bpf_error(cstate, "unsupported index operation"); in gen_load_internal()
7747 if (cstate->linktype != DLT_IEEE802_11_RADIO_AVS && in gen_load_internal()
7748 cstate->linktype != DLT_IEEE802_11_RADIO && in gen_load_internal()
7749 cstate->linktype != DLT_PRISM_HEADER) in gen_load_internal()
7750 bpf_error(cstate, "radio information not present in capture"); in gen_load_internal()
7756 s = xfer_to_x(cstate, inst); in gen_load_internal()
7761 tmp = new_stmt(cstate, BPF_LD|BPF_IND|size_code); in gen_load_internal()
7778 s = gen_abs_offset_varpart(cstate, &cstate->off_linkhdr); in gen_load_internal()
7790 sappend(s, xfer_to_a(cstate, inst)); in gen_load_internal()
7791 sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X)); in gen_load_internal()
7792 sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX)); in gen_load_internal()
7794 s = xfer_to_x(cstate, inst); in gen_load_internal()
7803 tmp = new_stmt(cstate, BPF_LD|BPF_IND|size_code); in gen_load_internal()
7804 tmp->s.k = cstate->off_linkhdr.constant_part; in gen_load_internal()
7825 s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl); in gen_load_internal()
7837 sappend(s, xfer_to_a(cstate, inst)); in gen_load_internal()
7838 sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X)); in gen_load_internal()
7839 sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX)); in gen_load_internal()
7841 s = xfer_to_x(cstate, inst); in gen_load_internal()
7850 tmp = new_stmt(cstate, BPF_LD|BPF_IND|size_code); in gen_load_internal()
7851 tmp->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_load_internal()
7859 b = gen_proto_abbrev_internal(cstate, proto); in gen_load_internal()
7888 s = gen_loadx_iphdrlen(cstate); in gen_load_internal()
7904 sappend(s, xfer_to_a(cstate, inst)); in gen_load_internal()
7905 sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X)); in gen_load_internal()
7906 sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX)); in gen_load_internal()
7907 sappend(s, tmp = new_stmt(cstate, BPF_LD|BPF_IND|size_code)); in gen_load_internal()
7908 tmp->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_load_internal()
7917 gen_and(gen_proto_abbrev_internal(cstate, proto), b = gen_ipfrag(cstate)); in gen_load_internal()
7920 gen_and(gen_proto_abbrev_internal(cstate, Q_IP), b); in gen_load_internal()
7928 b = gen_proto_abbrev_internal(cstate, Q_IPV6); in gen_load_internal()
7936 b = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, 58); in gen_load_internal()
7941 s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl); in gen_load_internal()
7952 sappend(s, xfer_to_a(cstate, inst)); in gen_load_internal()
7953 sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X)); in gen_load_internal()
7954 sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX)); in gen_load_internal()
7956 s = xfer_to_x(cstate, inst); in gen_load_internal()
7965 tmp = new_stmt(cstate, BPF_LD|BPF_IND|size_code); in gen_load_internal()
7966 tmp->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 40; in gen_load_internal()
7974 s = new_stmt(cstate, BPF_ST); in gen_load_internal()
7982 gen_load(compiler_state_t *cstate, int proto, struct arth *inst, in gen_load() argument
7989 if (setjmp(cstate->top_ctx)) in gen_load()
7992 return gen_load_internal(cstate, proto, inst, size); in gen_load()
7996 gen_relation_internal(compiler_state_t *cstate, int code, struct arth *a0, in gen_relation_internal() argument
8002 s0 = xfer_to_x(cstate, a1); in gen_relation_internal()
8003 s1 = xfer_to_a(cstate, a0); in gen_relation_internal()
8005 s2 = new_stmt(cstate, BPF_ALU|BPF_SUB|BPF_X); in gen_relation_internal()
8006 b = new_block(cstate, JMP(code)); in gen_relation_internal()
8010 b = new_block(cstate, BPF_JMP|code|BPF_X); in gen_relation_internal()
8020 free_reg(cstate, a0->regno); in gen_relation_internal()
8021 free_reg(cstate, a1->regno); in gen_relation_internal()
8040 gen_relation(compiler_state_t *cstate, int code, struct arth *a0, in gen_relation() argument
8047 if (setjmp(cstate->top_ctx)) in gen_relation()
8050 return gen_relation_internal(cstate, code, a0, a1, reversed); in gen_relation()
8054 gen_loadlen(compiler_state_t *cstate) in gen_loadlen() argument
8064 if (setjmp(cstate->top_ctx)) in gen_loadlen()
8067 regno = alloc_reg(cstate); in gen_loadlen()
8068 a = (struct arth *)newchunk(cstate, sizeof(*a)); in gen_loadlen()
8069 s = new_stmt(cstate, BPF_LD|BPF_LEN); in gen_loadlen()
8070 s->next = new_stmt(cstate, BPF_ST); in gen_loadlen()
8079 gen_loadi_internal(compiler_state_t *cstate, bpf_u_int32 val) in gen_loadi_internal() argument
8085 a = (struct arth *)newchunk(cstate, sizeof(*a)); in gen_loadi_internal()
8087 reg = alloc_reg(cstate); in gen_loadi_internal()
8089 s = new_stmt(cstate, BPF_LD|BPF_IMM); in gen_loadi_internal()
8091 s->next = new_stmt(cstate, BPF_ST); in gen_loadi_internal()
8100 gen_loadi(compiler_state_t *cstate, bpf_u_int32 val) in gen_loadi() argument
8106 if (setjmp(cstate->top_ctx)) in gen_loadi()
8109 return gen_loadi_internal(cstate, val); in gen_loadi()
8118 gen_neg(compiler_state_t *cstate, struct arth *a_arg) in gen_neg() argument
8127 if (setjmp(cstate->top_ctx)) in gen_neg()
8130 s = xfer_to_a(cstate, a); in gen_neg()
8132 s = new_stmt(cstate, BPF_ALU|BPF_NEG); in gen_neg()
8135 s = new_stmt(cstate, BPF_ST); in gen_neg()
8148 gen_arth(compiler_state_t *cstate, int code, struct arth *a0_arg, in gen_arth() argument
8158 if (setjmp(cstate->top_ctx)) in gen_arth()
8170 bpf_error(cstate, "division by zero"); in gen_arth()
8173 bpf_error(cstate, "modulus by zero"); in gen_arth()
8176 bpf_error(cstate, "shift by more than 31 bits"); in gen_arth()
8178 s0 = xfer_to_x(cstate, a1); in gen_arth()
8179 s1 = xfer_to_a(cstate, a0); in gen_arth()
8180 s2 = new_stmt(cstate, BPF_ALU|BPF_X|code); in gen_arth()
8187 free_reg(cstate, a0->regno); in gen_arth()
8188 free_reg(cstate, a1->regno); in gen_arth()
8190 s0 = new_stmt(cstate, BPF_ST); in gen_arth()
8191 a0->regno = s0->s.k = alloc_reg(cstate); in gen_arth()
8201 init_regs(compiler_state_t *cstate) in init_regs() argument
8203 cstate->curreg = 0; in init_regs()
8204 memset(cstate->regused, 0, sizeof cstate->regused); in init_regs()
8211 alloc_reg(compiler_state_t *cstate) in alloc_reg() argument
8216 if (cstate->regused[cstate->curreg]) in alloc_reg()
8217 cstate->curreg = (cstate->curreg + 1) % BPF_MEMWORDS; in alloc_reg()
8219 cstate->regused[cstate->curreg] = 1; in alloc_reg()
8220 return cstate->curreg; in alloc_reg()
8223 bpf_error(cstate, "too many registers needed to evaluate expression"); in alloc_reg()
8232 free_reg(compiler_state_t *cstate, int n) in free_reg() argument
8234 cstate->regused[n] = 0; in free_reg()
8238 gen_len(compiler_state_t *cstate, int jmp, int n) in gen_len() argument
8243 s = new_stmt(cstate, BPF_LD|BPF_LEN); in gen_len()
8244 b = new_block(cstate, JMP(jmp)); in gen_len()
8252 gen_greater(compiler_state_t *cstate, int n) in gen_greater() argument
8258 if (setjmp(cstate->top_ctx)) in gen_greater()
8261 return gen_len(cstate, BPF_JGE, n); in gen_greater()
8268 gen_less(compiler_state_t *cstate, int n) in gen_less() argument
8276 if (setjmp(cstate->top_ctx)) in gen_less()
8279 b = gen_len(cstate, BPF_JGT, n); in gen_less()
8296 gen_byteop(compiler_state_t *cstate, int op, int idx, bpf_u_int32 val) in gen_byteop() argument
8305 if (setjmp(cstate->top_ctx)) in gen_byteop()
8313 return gen_cmp(cstate, OR_LINKHDR, (u_int)idx, BPF_B, val); in gen_byteop()
8316 b = gen_cmp_lt(cstate, OR_LINKHDR, (u_int)idx, BPF_B, val); in gen_byteop()
8320 b = gen_cmp_gt(cstate, OR_LINKHDR, (u_int)idx, BPF_B, val); in gen_byteop()
8324 s = new_stmt(cstate, BPF_ALU|BPF_OR|BPF_K); in gen_byteop()
8328 s = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K); in gen_byteop()
8332 b = new_block(cstate, JMP(BPF_JEQ)); in gen_byteop()
8340 gen_broadcast(compiler_state_t *cstate, int proto) in gen_broadcast() argument
8350 if (setjmp(cstate->top_ctx)) in gen_broadcast()
8357 switch (cstate->linktype) { in gen_broadcast()
8361 return gen_ahostop(cstate, 0, Q_DST); in gen_broadcast()
8365 b1 = gen_prevlinkhdr_check(cstate); in gen_broadcast()
8366 b0 = gen_ehostop(cstate, ebroadcast, Q_DST); in gen_broadcast()
8371 return gen_fhostop(cstate, ebroadcast, Q_DST); in gen_broadcast()
8373 return gen_thostop(cstate, ebroadcast, Q_DST); in gen_broadcast()
8379 return gen_wlanhostop(cstate, ebroadcast, Q_DST); in gen_broadcast()
8381 return gen_ipfchostop(cstate, ebroadcast, Q_DST); in gen_broadcast()
8383 bpf_error(cstate, "not a broadcast link"); in gen_broadcast()
8393 if (cstate->netmask == PCAP_NETMASK_UNKNOWN) in gen_broadcast()
8394 bpf_error(cstate, "netmask not known, so 'ip broadcast' not supported"); in gen_broadcast()
8395 b0 = gen_linktype(cstate, ETHERTYPE_IP); in gen_broadcast()
8396 hostmask = ~cstate->netmask; in gen_broadcast()
8397 b1 = gen_mcmp(cstate, OR_LINKPL, 16, BPF_W, 0, hostmask); in gen_broadcast()
8398 b2 = gen_mcmp(cstate, OR_LINKPL, 16, BPF_W, in gen_broadcast()
8404 bpf_error(cstate, "only link-layer/IP broadcast filters supported"); in gen_broadcast()
8413 gen_mac_multicast(compiler_state_t *cstate, int offset) in gen_mac_multicast() argument
8419 s = gen_load_a(cstate, OR_LINKHDR, offset, BPF_B); in gen_mac_multicast()
8420 b0 = new_block(cstate, JMP(BPF_JSET)); in gen_mac_multicast()
8427 gen_multicast(compiler_state_t *cstate, int proto) in gen_multicast() argument
8436 if (setjmp(cstate->top_ctx)) in gen_multicast()
8443 switch (cstate->linktype) { in gen_multicast()
8447 return gen_ahostop(cstate, 0, Q_DST); in gen_multicast()
8451 b1 = gen_prevlinkhdr_check(cstate); in gen_multicast()
8453 b0 = gen_mac_multicast(cstate, 0); in gen_multicast()
8464 return gen_mac_multicast(cstate, 1); in gen_multicast()
8467 return gen_mac_multicast(cstate, 2); in gen_multicast()
8494 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_multicast()
8495 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_multicast()
8502 b0 = gen_mac_multicast(cstate, 16); in gen_multicast()
8509 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_multicast()
8510 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_multicast()
8518 b1 = gen_mac_multicast(cstate, 4); in gen_multicast()
8531 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_multicast()
8532 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_multicast()
8546 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_multicast()
8547 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_multicast()
8555 b1 = gen_mac_multicast(cstate, 4); in gen_multicast()
8573 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_multicast()
8574 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_multicast()
8586 b0 = gen_mac_multicast(cstate, 2); in gen_multicast()
8595 b0 = gen_linktype(cstate, ETHERTYPE_IP); in gen_multicast()
8600 b1 = gen_mcmp(cstate, OR_LINKPL, 16, BPF_B, 0xe0, 0xf0); in gen_multicast()
8606 b0 = gen_linktype(cstate, ETHERTYPE_IPV6); in gen_multicast()
8607 b1 = gen_cmp(cstate, OR_LINKPL, 24, BPF_B, 255); in gen_multicast()
8611 …bpf_error(cstate, "link-layer multicast filters supported only on ethernet/FDDI/token ring/ARCNET/… in gen_multicast()
8616 gen_ifindex(compiler_state_t *cstate, int ifindex) in gen_ifindex() argument
8624 if (setjmp(cstate->top_ctx)) in gen_ifindex()
8630 switch (cstate->linktype) { in gen_ifindex()
8633 b0 = gen_cmp(cstate, OR_LINKHDR, 4, BPF_W, ifindex); in gen_ifindex()
8643 if (cstate->bpf_pcap->rfile != NULL) { in gen_ifindex()
8645 bpf_error(cstate, "ifindex not supported on %s when reading savefiles", in gen_ifindex()
8646 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_ifindex()
8650 b0 = gen_cmp(cstate, OR_LINKHDR, SKF_AD_OFF + SKF_AD_IFINDEX, BPF_W, in gen_ifindex()
8653 bpf_error(cstate, "ifindex not supported on %s", in gen_ifindex()
8654 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_ifindex()
8671 gen_inbound(compiler_state_t *cstate, int dir) in gen_inbound() argument
8679 if (setjmp(cstate->top_ctx)) in gen_inbound()
8685 switch (cstate->linktype) { in gen_inbound()
8687 b0 = gen_relation_internal(cstate, BPF_JEQ, in gen_inbound()
8688 gen_load_internal(cstate, Q_LINK, gen_loadi_internal(cstate, 0), 1), in gen_inbound()
8689 gen_loadi_internal(cstate, 0), in gen_inbound()
8696 b0 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, IPNET_OUTBOUND); in gen_inbound()
8699 b0 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, IPNET_INBOUND); in gen_inbound()
8705 b0 = gen_cmp(cstate, OR_LINKHDR, 0, BPF_H, LINUX_SLL_OUTGOING); in gen_inbound()
8714 b0 = gen_cmp(cstate, OR_LINKHDR, 10, BPF_B, LINUX_SLL_OUTGOING); in gen_inbound()
8722 b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, dir), BPF_B, in gen_inbound()
8729 b0 = gen_cmp(cstate, OR_LINKHDR, 0, BPF_B, PPP_PPPD_OUT); in gen_inbound()
8732 b0 = gen_cmp(cstate, OR_LINKHDR, 0, BPF_B, PPP_PPPD_IN); in gen_inbound()
8763 b0 = gen_mcmp(cstate, OR_LINKHDR, 3, BPF_B, 0, 0x01); in gen_inbound()
8766 b0 = gen_mcmp(cstate, OR_LINKHDR, 3, BPF_B, 1, 0x01); in gen_inbound()
8793 if (cstate->bpf_pcap->rfile != NULL) { in gen_inbound()
8795 bpf_error(cstate, "inbound/outbound not supported on %s when reading savefiles", in gen_inbound()
8796 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_inbound()
8800 b0 = gen_cmp(cstate, OR_LINKHDR, SKF_AD_OFF + SKF_AD_PKTTYPE, BPF_H, in gen_inbound()
8807 bpf_error(cstate, "inbound/outbound not supported on %s", in gen_inbound()
8808 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_inbound()
8817 gen_pf_ifname(compiler_state_t *cstate, const char *ifname) in gen_pf_ifname() argument
8826 if (setjmp(cstate->top_ctx)) in gen_pf_ifname()
8829 if (cstate->linktype != DLT_PFLOG) { in gen_pf_ifname()
8830 bpf_error(cstate, "ifname supported only on PF linktype"); in gen_pf_ifname()
8836 bpf_error(cstate, "ifname interface names can only be %d characters", in gen_pf_ifname()
8840 b0 = gen_bcmp(cstate, OR_LINKHDR, off, (u_int)strlen(ifname), in gen_pf_ifname()
8847 gen_pf_ruleset(compiler_state_t *cstate, char *ruleset) in gen_pf_ruleset() argument
8855 if (setjmp(cstate->top_ctx)) in gen_pf_ruleset()
8858 if (cstate->linktype != DLT_PFLOG) { in gen_pf_ruleset()
8859 bpf_error(cstate, "ruleset supported only on PF linktype"); in gen_pf_ruleset()
8864 bpf_error(cstate, "ruleset names can only be %ld characters", in gen_pf_ruleset()
8869 b0 = gen_bcmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, ruleset), in gen_pf_ruleset()
8876 gen_pf_rnr(compiler_state_t *cstate, int rnr) in gen_pf_rnr() argument
8884 if (setjmp(cstate->top_ctx)) in gen_pf_rnr()
8887 if (cstate->linktype != DLT_PFLOG) { in gen_pf_rnr()
8888 bpf_error(cstate, "rnr supported only on PF linktype"); in gen_pf_rnr()
8892 b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, rulenr), BPF_W, in gen_pf_rnr()
8899 gen_pf_srnr(compiler_state_t *cstate, int srnr) in gen_pf_srnr() argument
8907 if (setjmp(cstate->top_ctx)) in gen_pf_srnr()
8910 if (cstate->linktype != DLT_PFLOG) { in gen_pf_srnr()
8911 bpf_error(cstate, "srnr supported only on PF linktype"); in gen_pf_srnr()
8915 b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, subrulenr), BPF_W, in gen_pf_srnr()
8922 gen_pf_reason(compiler_state_t *cstate, int reason) in gen_pf_reason() argument
8930 if (setjmp(cstate->top_ctx)) in gen_pf_reason()
8933 if (cstate->linktype != DLT_PFLOG) { in gen_pf_reason()
8934 bpf_error(cstate, "reason supported only on PF linktype"); in gen_pf_reason()
8938 b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, reason), BPF_B, in gen_pf_reason()
8945 gen_pf_action(compiler_state_t *cstate, int action) in gen_pf_action() argument
8953 if (setjmp(cstate->top_ctx)) in gen_pf_action()
8956 if (cstate->linktype != DLT_PFLOG) { in gen_pf_action()
8957 bpf_error(cstate, "action supported only on PF linktype"); in gen_pf_action()
8961 b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, action), BPF_B, in gen_pf_action()
8968 gen_p80211_type(compiler_state_t *cstate, bpf_u_int32 type, bpf_u_int32 mask) in gen_p80211_type() argument
8976 if (setjmp(cstate->top_ctx)) in gen_p80211_type()
8979 switch (cstate->linktype) { in gen_p80211_type()
8985 b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, type, mask); in gen_p80211_type()
8989 bpf_error(cstate, "802.11 link-layer types supported only on 802.11"); in gen_p80211_type()
8997 gen_p80211_fcdir(compiler_state_t *cstate, bpf_u_int32 fcdir) in gen_p80211_fcdir() argument
9005 if (setjmp(cstate->top_ctx)) in gen_p80211_fcdir()
9008 switch (cstate->linktype) { in gen_p80211_fcdir()
9017 bpf_error(cstate, "frame direction supported only with 802.11 headers"); in gen_p80211_fcdir()
9021 b0 = gen_mcmp(cstate, OR_LINKHDR, 1, BPF_B, fcdir, in gen_p80211_fcdir()
9029 gen_acode(compiler_state_t *cstate, const char *s, struct qual q) in gen_acode() argument
9035 if (setjmp(cstate->top_ctx)) in gen_acode()
9038 switch (cstate->linktype) { in gen_acode()
9052 bpf_error(cstate, "invalid ARCnet address '%s'", s); in gen_acode()
9053 return gen_ahostop(cstate, addr, (int)q.dir); in gen_acode()
9055 bpf_error(cstate, "ARCnet address used in non-arc expression"); in gen_acode()
9059 bpf_error(cstate, "aid supported only on ARCnet"); in gen_acode()
9066 gen_ahostop(compiler_state_t *cstate, const uint8_t eaddr, int dir) in gen_ahostop() argument
9079 return gen_cmp(cstate, OR_LINKHDR, 0, BPF_B, eaddr); in gen_ahostop()
9082 return gen_cmp(cstate, OR_LINKHDR, 1, BPF_B, eaddr); in gen_ahostop()
9085 b0 = gen_ahostop(cstate, eaddr, Q_SRC); in gen_ahostop()
9086 b1 = gen_ahostop(cstate, eaddr, Q_DST); in gen_ahostop()
9092 b0 = gen_ahostop(cstate, eaddr, Q_SRC); in gen_ahostop()
9093 b1 = gen_ahostop(cstate, eaddr, Q_DST); in gen_ahostop()
9098 bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11"); in gen_ahostop()
9102 bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11"); in gen_ahostop()
9106 bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11"); in gen_ahostop()
9110 bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11"); in gen_ahostop()
9114 bpf_error(cstate, "'ra' is only supported on 802.11"); in gen_ahostop()
9118 bpf_error(cstate, "'ta' is only supported on 802.11"); in gen_ahostop()
9126 gen_vlan_tpid_test(compiler_state_t *cstate) in gen_vlan_tpid_test() argument
9131 b0 = gen_linktype(cstate, ETHERTYPE_8021Q); in gen_vlan_tpid_test()
9132 b1 = gen_linktype(cstate, ETHERTYPE_8021AD); in gen_vlan_tpid_test()
9135 b1 = gen_linktype(cstate, ETHERTYPE_8021QINQ); in gen_vlan_tpid_test()
9142 gen_vlan_vid_test(compiler_state_t *cstate, bpf_u_int32 vlan_num) in gen_vlan_vid_test() argument
9145 bpf_error(cstate, "VLAN tag %u greater than maximum %u", in gen_vlan_vid_test()
9148 return gen_mcmp(cstate, OR_LINKPL, 0, BPF_H, vlan_num, 0x0fff); in gen_vlan_vid_test()
9152 gen_vlan_no_bpf_extensions(compiler_state_t *cstate, bpf_u_int32 vlan_num, in gen_vlan_no_bpf_extensions() argument
9157 b0 = gen_vlan_tpid_test(cstate); in gen_vlan_no_bpf_extensions()
9160 b1 = gen_vlan_vid_test(cstate, vlan_num); in gen_vlan_no_bpf_extensions()
9169 cstate->off_linkpl.constant_part += 4; in gen_vlan_no_bpf_extensions()
9170 cstate->off_linktype.constant_part += 4; in gen_vlan_no_bpf_extensions()
9178 gen_vlan_vloffset_add(compiler_state_t *cstate, bpf_abs_offset *off, in gen_vlan_vloffset_add() argument
9186 off->reg = alloc_reg(cstate); in gen_vlan_vloffset_add()
9188 s2 = new_stmt(cstate, BPF_LD|BPF_MEM); in gen_vlan_vloffset_add()
9191 s2 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_IMM); in gen_vlan_vloffset_add()
9194 s2 = new_stmt(cstate, BPF_ST); in gen_vlan_vloffset_add()
9204 gen_vlan_patch_tpid_test(compiler_state_t *cstate, struct block *b_tpid) in gen_vlan_patch_tpid_test() argument
9210 cstate->is_vlan_vloffset = 1; in gen_vlan_patch_tpid_test()
9211 gen_vlan_vloffset_add(cstate, &cstate->off_linkpl, 4, &s); in gen_vlan_patch_tpid_test()
9212 gen_vlan_vloffset_add(cstate, &cstate->off_linktype, 4, &s); in gen_vlan_patch_tpid_test()
9224 gen_vlan_patch_vid_test(compiler_state_t *cstate, struct block *b_vid) in gen_vlan_patch_vid_test() argument
9229 s = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_vlan_patch_vid_test()
9233 sjeq = new_stmt(cstate, JMP(BPF_JEQ)); in gen_vlan_patch_vid_test()
9238 s2 = new_stmt(cstate, BPF_LD|BPF_H|BPF_ABS); in gen_vlan_patch_vid_test()
9250 s2 = new_stmt(cstate, JMP(BPF_JA)); in gen_vlan_patch_vid_test()
9268 gen_vlan_bpf_extensions(compiler_state_t *cstate, bpf_u_int32 vlan_num, in gen_vlan_bpf_extensions() argument
9276 s = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_vlan_bpf_extensions()
9279 b0 = new_block(cstate, JMP(BPF_JEQ)); in gen_vlan_bpf_extensions()
9293 b_tpid = gen_vlan_tpid_test(cstate); in gen_vlan_bpf_extensions()
9295 b_vid = gen_vlan_vid_test(cstate, vlan_num); in gen_vlan_bpf_extensions()
9297 gen_vlan_patch_tpid_test(cstate, b_tpid); in gen_vlan_bpf_extensions()
9302 gen_vlan_patch_vid_test(cstate, b_vid); in gen_vlan_bpf_extensions()
9315 gen_vlan(compiler_state_t *cstate, bpf_u_int32 vlan_num, int has_vlan_tag) in gen_vlan() argument
9323 if (setjmp(cstate->top_ctx)) in gen_vlan()
9327 if (cstate->label_stack_depth > 0) in gen_vlan()
9328 bpf_error(cstate, "no VLAN match after MPLS"); in gen_vlan()
9361 switch (cstate->linktype) { in gen_vlan()
9369 if (cstate->vlan_stack_depth == 0 && !cstate->off_linkhdr.is_variable && in gen_vlan()
9370 cstate->off_linkhdr.constant_part == in gen_vlan()
9371 cstate->off_outermostlinkhdr.constant_part) { in gen_vlan()
9375 if (cstate->bpf_pcap->bpf_codegen_flags & BPF_SPECIAL_VLAN_HANDLING) in gen_vlan()
9376 b0 = gen_vlan_bpf_extensions(cstate, vlan_num, in gen_vlan()
9379 b0 = gen_vlan_no_bpf_extensions(cstate, in gen_vlan()
9383 b0 = gen_vlan_no_bpf_extensions(cstate, vlan_num, in gen_vlan()
9391 b0 = gen_vlan_no_bpf_extensions(cstate, vlan_num, has_vlan_tag); in gen_vlan()
9395 bpf_error(cstate, "no VLAN support for %s", in gen_vlan()
9396 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_vlan()
9400 cstate->vlan_stack_depth++; in gen_vlan()
9413 gen_mpls_internal(compiler_state_t *cstate, bpf_u_int32 label_num, in gen_mpls_internal() argument
9418 if (cstate->label_stack_depth > 0) { in gen_mpls_internal()
9420 b0 = gen_mcmp(cstate, OR_PREVMPLSHDR, 2, BPF_B, 0, 0x01); in gen_mpls_internal()
9426 switch (cstate->linktype) { in gen_mpls_internal()
9433 b0 = gen_linktype(cstate, ETHERTYPE_MPLS); in gen_mpls_internal()
9437 b0 = gen_linktype(cstate, PPP_MPLS_UCAST); in gen_mpls_internal()
9445 bpf_error(cstate, "no MPLS support for %s", in gen_mpls_internal()
9446 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_mpls_internal()
9454 bpf_error(cstate, "MPLS label %u greater than maximum %u", in gen_mpls_internal()
9458 b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_W, label_num, in gen_mpls_internal()
9478 cstate->off_nl_nosnap += 4; in gen_mpls_internal()
9479 cstate->off_nl += 4; in gen_mpls_internal()
9480 cstate->label_stack_depth++; in gen_mpls_internal()
9485 gen_mpls(compiler_state_t *cstate, bpf_u_int32 label_num, int has_label_num) in gen_mpls() argument
9491 if (setjmp(cstate->top_ctx)) in gen_mpls()
9494 return gen_mpls_internal(cstate, label_num, has_label_num); in gen_mpls()
9501 gen_pppoed(compiler_state_t *cstate) in gen_pppoed() argument
9507 if (setjmp(cstate->top_ctx)) in gen_pppoed()
9511 return gen_linktype(cstate, ETHERTYPE_PPPOED); in gen_pppoed()
9515 gen_pppoes(compiler_state_t *cstate, bpf_u_int32 sess_num, int has_sess_num) in gen_pppoes() argument
9523 if (setjmp(cstate->top_ctx)) in gen_pppoes()
9529 b0 = gen_linktype(cstate, ETHERTYPE_PPPOES); in gen_pppoes()
9534 bpf_error(cstate, "PPPoE session number %u greater than maximum %u", in gen_pppoes()
9537 b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_W, sess_num, 0x0000ffff); in gen_pppoes()
9560 PUSH_LINKHDR(cstate, DLT_PPP, cstate->off_linkpl.is_variable, in gen_pppoes()
9561 cstate->off_linkpl.constant_part + cstate->off_nl + 6, /* 6 bytes past the PPPoE header */ in gen_pppoes()
9562 cstate->off_linkpl.reg); in gen_pppoes()
9564 cstate->off_linktype = cstate->off_linkhdr; in gen_pppoes()
9565 cstate->off_linkpl.constant_part = cstate->off_linkhdr.constant_part + 2; in gen_pppoes()
9567 cstate->off_nl = 0; in gen_pppoes()
9568 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in gen_pppoes()
9576 gen_geneve_check(compiler_state_t *cstate, in gen_geneve_check() argument
9582 b0 = gen_portfn(cstate, GENEVE_PORT, IPPROTO_UDP, Q_DST); in gen_geneve_check()
9587 b1 = gen_mcmp(cstate, offrel, 8, BPF_B, 0, 0xc0); in gen_geneve_check()
9593 bpf_error(cstate, "Geneve VNI %u greater than maximum %u", in gen_geneve_check()
9597 b1 = gen_mcmp(cstate, offrel, 12, BPF_W, vni, 0xffffff00); in gen_geneve_check()
9611 gen_geneve4(compiler_state_t *cstate, bpf_u_int32 vni, int has_vni) in gen_geneve4() argument
9616 b0 = gen_geneve_check(cstate, gen_port, OR_TRAN_IPV4, vni, has_vni); in gen_geneve4()
9619 s = gen_loadx_iphdrlen(cstate); in gen_geneve4()
9621 s1 = new_stmt(cstate, BPF_MISC|BPF_TXA); in gen_geneve4()
9627 b1 = new_block(cstate, BPF_JMP|BPF_JEQ|BPF_X); in gen_geneve4()
9637 gen_geneve6(compiler_state_t *cstate, bpf_u_int32 vni, int has_vni) in gen_geneve6() argument
9642 b0 = gen_geneve_check(cstate, gen_port6, OR_TRAN_IPV6, vni, has_vni); in gen_geneve6()
9646 s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl); in gen_geneve6()
9648 s1 = new_stmt(cstate, BPF_LD|BPF_IMM); in gen_geneve6()
9652 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X); in gen_geneve6()
9656 s = new_stmt(cstate, BPF_LD|BPF_IMM); in gen_geneve6()
9663 s1 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_geneve6()
9666 b1 = new_block(cstate, BPF_JMP|BPF_JEQ|BPF_X); in gen_geneve6()
9680 gen_geneve_offsets(compiler_state_t *cstate) in gen_geneve_offsets() argument
9689 s = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_geneve_offsets()
9690 s->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 8; in gen_geneve_offsets()
9693 s1 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_geneve_offsets()
9698 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_geneve_offsets()
9702 cstate->off_linktype.reg = alloc_reg(cstate); in gen_geneve_offsets()
9703 cstate->off_linktype.is_variable = 1; in gen_geneve_offsets()
9704 cstate->off_linktype.constant_part = 0; in gen_geneve_offsets()
9706 s1 = new_stmt(cstate, BPF_ST); in gen_geneve_offsets()
9707 s1->s.k = cstate->off_linktype.reg; in gen_geneve_offsets()
9713 s1 = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_geneve_offsets()
9717 s1 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K); in gen_geneve_offsets()
9721 s1 = new_stmt(cstate, BPF_ALU|BPF_MUL|BPF_K); in gen_geneve_offsets()
9726 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_geneve_offsets()
9731 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X); in gen_geneve_offsets()
9743 PUSH_LINKHDR(cstate, DLT_EN10MB, 1, 0, alloc_reg(cstate)); in gen_geneve_offsets()
9745 s1 = new_stmt(cstate, BPF_ST); in gen_geneve_offsets()
9746 s1->s.k = cstate->off_linkhdr.reg; in gen_geneve_offsets()
9755 cstate->no_optimize = 1; in gen_geneve_offsets()
9758 s1 = new_stmt(cstate, BPF_LD|BPF_IND|BPF_H); in gen_geneve_offsets()
9763 s1 = new_stmt(cstate, BPF_LDX|BPF_MEM); in gen_geneve_offsets()
9764 s1->s.k = cstate->off_linkhdr.reg; in gen_geneve_offsets()
9770 s_proto = new_stmt(cstate, JMP(BPF_JEQ)); in gen_geneve_offsets()
9774 s1 = new_stmt(cstate, BPF_MISC|BPF_TXA); in gen_geneve_offsets()
9780 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_geneve_offsets()
9784 s1 = new_stmt(cstate, BPF_ST); in gen_geneve_offsets()
9785 s1->s.k = cstate->off_linktype.reg; in gen_geneve_offsets()
9790 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_geneve_offsets()
9795 s1 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_geneve_offsets()
9799 cstate->off_linkpl.reg = alloc_reg(cstate); in gen_geneve_offsets()
9800 cstate->off_linkpl.is_variable = 1; in gen_geneve_offsets()
9801 cstate->off_linkpl.constant_part = 0; in gen_geneve_offsets()
9803 s1 = new_stmt(cstate, BPF_STX); in gen_geneve_offsets()
9804 s1->s.k = cstate->off_linkpl.reg; in gen_geneve_offsets()
9808 cstate->off_nl = 0; in gen_geneve_offsets()
9815 gen_geneve(compiler_state_t *cstate, bpf_u_int32 vni, int has_vni) in gen_geneve() argument
9824 if (setjmp(cstate->top_ctx)) in gen_geneve()
9827 b0 = gen_geneve4(cstate, vni, has_vni); in gen_geneve()
9828 b1 = gen_geneve6(cstate, vni, has_vni); in gen_geneve()
9836 s = gen_geneve_offsets(cstate); in gen_geneve()
9838 b1 = gen_true(cstate); in gen_geneve()
9844 cstate->is_geneve = 1; in gen_geneve()
9852 gen_geneve_ll_check(compiler_state_t *cstate) in gen_geneve_ll_check() argument
9863 s = new_stmt(cstate, BPF_LD|BPF_MEM); in gen_geneve_ll_check()
9864 s->s.k = cstate->off_linkhdr.reg; in gen_geneve_ll_check()
9866 s1 = new_stmt(cstate, BPF_LDX|BPF_MEM); in gen_geneve_ll_check()
9867 s1->s.k = cstate->off_linkpl.reg; in gen_geneve_ll_check()
9870 b0 = new_block(cstate, BPF_JMP|BPF_JEQ|BPF_X); in gen_geneve_ll_check()
9879 gen_atmfield_code_internal(compiler_state_t *cstate, int atmfield, in gen_atmfield_code_internal() argument
9887 if (!cstate->is_atm) in gen_atmfield_code_internal()
9888 bpf_error(cstate, "'vpi' supported only on raw ATM"); in gen_atmfield_code_internal()
9889 if (cstate->off_vpi == OFFSET_NOT_SET) in gen_atmfield_code_internal()
9891 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_vpi, BPF_B, in gen_atmfield_code_internal()
9896 if (!cstate->is_atm) in gen_atmfield_code_internal()
9897 bpf_error(cstate, "'vci' supported only on raw ATM"); in gen_atmfield_code_internal()
9898 if (cstate->off_vci == OFFSET_NOT_SET) in gen_atmfield_code_internal()
9900 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_vci, BPF_H, in gen_atmfield_code_internal()
9905 if (cstate->off_proto == OFFSET_NOT_SET) in gen_atmfield_code_internal()
9907 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_proto, BPF_B, in gen_atmfield_code_internal()
9912 if (cstate->off_payload == OFFSET_NOT_SET) in gen_atmfield_code_internal()
9914 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_payload + MSG_TYPE_POS, BPF_B, in gen_atmfield_code_internal()
9919 if (!cstate->is_atm) in gen_atmfield_code_internal()
9920 bpf_error(cstate, "'callref' supported only on raw ATM"); in gen_atmfield_code_internal()
9921 if (cstate->off_proto == OFFSET_NOT_SET) in gen_atmfield_code_internal()
9923 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_proto, BPF_B, in gen_atmfield_code_internal()
9934 gen_atmtype_metac(compiler_state_t *cstate) in gen_atmtype_metac() argument
9938 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmtype_metac()
9939 b1 = gen_atmfield_code_internal(cstate, A_VCI, 1, BPF_JEQ, 0); in gen_atmtype_metac()
9945 gen_atmtype_sc(compiler_state_t *cstate) in gen_atmtype_sc() argument
9949 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmtype_sc()
9950 b1 = gen_atmfield_code_internal(cstate, A_VCI, 5, BPF_JEQ, 0); in gen_atmtype_sc()
9956 gen_atmtype_llc(compiler_state_t *cstate) in gen_atmtype_llc() argument
9960 b0 = gen_atmfield_code_internal(cstate, A_PROTOTYPE, PT_LLC, BPF_JEQ, 0); in gen_atmtype_llc()
9961 cstate->linktype = cstate->prevlinktype; in gen_atmtype_llc()
9966 gen_atmfield_code(compiler_state_t *cstate, int atmfield, in gen_atmfield_code() argument
9973 if (setjmp(cstate->top_ctx)) in gen_atmfield_code()
9976 return gen_atmfield_code_internal(cstate, atmfield, jvalue, jtype, in gen_atmfield_code()
9981 gen_atmtype_abbrev(compiler_state_t *cstate, int type) in gen_atmtype_abbrev() argument
9989 if (setjmp(cstate->top_ctx)) in gen_atmtype_abbrev()
9996 if (!cstate->is_atm) in gen_atmtype_abbrev()
9997 bpf_error(cstate, "'metac' supported only on raw ATM"); in gen_atmtype_abbrev()
9998 b1 = gen_atmtype_metac(cstate); in gen_atmtype_abbrev()
10003 if (!cstate->is_atm) in gen_atmtype_abbrev()
10004 bpf_error(cstate, "'bcc' supported only on raw ATM"); in gen_atmtype_abbrev()
10005 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmtype_abbrev()
10006 b1 = gen_atmfield_code_internal(cstate, A_VCI, 2, BPF_JEQ, 0); in gen_atmtype_abbrev()
10012 if (!cstate->is_atm) in gen_atmtype_abbrev()
10013 bpf_error(cstate, "'oam4sc' supported only on raw ATM"); in gen_atmtype_abbrev()
10014 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmtype_abbrev()
10015 b1 = gen_atmfield_code_internal(cstate, A_VCI, 3, BPF_JEQ, 0); in gen_atmtype_abbrev()
10021 if (!cstate->is_atm) in gen_atmtype_abbrev()
10022 bpf_error(cstate, "'oam4ec' supported only on raw ATM"); in gen_atmtype_abbrev()
10023 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmtype_abbrev()
10024 b1 = gen_atmfield_code_internal(cstate, A_VCI, 4, BPF_JEQ, 0); in gen_atmtype_abbrev()
10030 if (!cstate->is_atm) in gen_atmtype_abbrev()
10031 bpf_error(cstate, "'sc' supported only on raw ATM"); in gen_atmtype_abbrev()
10032 b1 = gen_atmtype_sc(cstate); in gen_atmtype_abbrev()
10037 if (!cstate->is_atm) in gen_atmtype_abbrev()
10038 bpf_error(cstate, "'ilmic' supported only on raw ATM"); in gen_atmtype_abbrev()
10039 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmtype_abbrev()
10040 b1 = gen_atmfield_code_internal(cstate, A_VCI, 16, BPF_JEQ, 0); in gen_atmtype_abbrev()
10046 if (!cstate->is_atm) in gen_atmtype_abbrev()
10047 bpf_error(cstate, "'lane' supported only on raw ATM"); in gen_atmtype_abbrev()
10048 b1 = gen_atmfield_code_internal(cstate, A_PROTOTYPE, PT_LANE, BPF_JEQ, 0); in gen_atmtype_abbrev()
10058 PUSH_LINKHDR(cstate, DLT_EN10MB, 0, in gen_atmtype_abbrev()
10059 cstate->off_payload + 2, /* Ethernet header */ in gen_atmtype_abbrev()
10061 cstate->off_linktype.constant_part = cstate->off_linkhdr.constant_part + 12; in gen_atmtype_abbrev()
10062 cstate->off_linkpl.constant_part = cstate->off_linkhdr.constant_part + 14; /* Ethernet */ in gen_atmtype_abbrev()
10063 cstate->off_nl = 0; /* Ethernet II */ in gen_atmtype_abbrev()
10064 cstate->off_nl_nosnap = 3; /* 802.3+802.2 */ in gen_atmtype_abbrev()
10069 if (!cstate->is_atm) in gen_atmtype_abbrev()
10070 bpf_error(cstate, "'llc' supported only on raw ATM"); in gen_atmtype_abbrev()
10071 b1 = gen_atmtype_llc(cstate); in gen_atmtype_abbrev()
10088 gen_mtp2type_abbrev(compiler_state_t *cstate, int type) in gen_mtp2type_abbrev() argument
10096 if (setjmp(cstate->top_ctx)) in gen_mtp2type_abbrev()
10102 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
10103 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
10104 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
10105 bpf_error(cstate, "'fisu' supported only on MTP2"); in gen_mtp2type_abbrev()
10107 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B, in gen_mtp2type_abbrev()
10112 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
10113 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
10114 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
10115 bpf_error(cstate, "'lssu' supported only on MTP2"); in gen_mtp2type_abbrev()
10116 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B, in gen_mtp2type_abbrev()
10118 b1 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B, in gen_mtp2type_abbrev()
10124 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
10125 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
10126 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
10127 bpf_error(cstate, "'msu' supported only on MTP2"); in gen_mtp2type_abbrev()
10128 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B, in gen_mtp2type_abbrev()
10133 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
10134 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
10135 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
10136 bpf_error(cstate, "'hfisu' supported only on MTP2_HSL"); in gen_mtp2type_abbrev()
10138 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H, in gen_mtp2type_abbrev()
10143 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
10144 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
10145 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
10146 bpf_error(cstate, "'hlssu' supported only on MTP2_HSL"); in gen_mtp2type_abbrev()
10147 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H, in gen_mtp2type_abbrev()
10149 b1 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H, in gen_mtp2type_abbrev()
10155 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
10156 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
10157 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
10158 bpf_error(cstate, "'hmsu' supported only on MTP2_HSL"); in gen_mtp2type_abbrev()
10159 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H, in gen_mtp2type_abbrev()
10170 gen_mtp3field_code_internal(compiler_state_t *cstate, int mtp3field, in gen_mtp3field_code_internal() argument
10180 newoff_sio = cstate->off_sio; in gen_mtp3field_code_internal()
10181 newoff_opc = cstate->off_opc; in gen_mtp3field_code_internal()
10182 newoff_dpc = cstate->off_dpc; in gen_mtp3field_code_internal()
10183 newoff_sls = cstate->off_sls; in gen_mtp3field_code_internal()
10191 if (cstate->off_sio == OFFSET_NOT_SET) in gen_mtp3field_code_internal()
10192 bpf_error(cstate, "'sio' supported only on SS7"); in gen_mtp3field_code_internal()
10195 bpf_error(cstate, "sio value %u too big; max value = 255", in gen_mtp3field_code_internal()
10197 b0 = gen_ncmp(cstate, OR_PACKET, newoff_sio, BPF_B, 0xffffffffU, in gen_mtp3field_code_internal()
10206 if (cstate->off_opc == OFFSET_NOT_SET) in gen_mtp3field_code_internal()
10207 bpf_error(cstate, "'opc' supported only on SS7"); in gen_mtp3field_code_internal()
10210 bpf_error(cstate, "opc value %u too big; max value = 16383", in gen_mtp3field_code_internal()
10221 b0 = gen_ncmp(cstate, OR_PACKET, newoff_opc, BPF_W, 0x00c0ff0fU, in gen_mtp3field_code_internal()
10230 if (cstate->off_dpc == OFFSET_NOT_SET) in gen_mtp3field_code_internal()
10231 bpf_error(cstate, "'dpc' supported only on SS7"); in gen_mtp3field_code_internal()
10234 bpf_error(cstate, "dpc value %u too big; max value = 16383", in gen_mtp3field_code_internal()
10243 b0 = gen_ncmp(cstate, OR_PACKET, newoff_dpc, BPF_W, 0xff3f0000U, in gen_mtp3field_code_internal()
10252 if (cstate->off_sls == OFFSET_NOT_SET) in gen_mtp3field_code_internal()
10253 bpf_error(cstate, "'sls' supported only on SS7"); in gen_mtp3field_code_internal()
10256 bpf_error(cstate, "sls value %u too big; max value = 15", in gen_mtp3field_code_internal()
10261 b0 = gen_ncmp(cstate, OR_PACKET, newoff_sls, BPF_B, 0xf0U, in gen_mtp3field_code_internal()
10272 gen_mtp3field_code(compiler_state_t *cstate, int mtp3field, in gen_mtp3field_code() argument
10279 if (setjmp(cstate->top_ctx)) in gen_mtp3field_code()
10282 return gen_mtp3field_code_internal(cstate, mtp3field, jvalue, jtype, in gen_mtp3field_code()
10287 gen_msg_abbrev(compiler_state_t *cstate, int type) in gen_msg_abbrev() argument
10298 b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, SETUP, BPF_JEQ, 0); in gen_msg_abbrev()
10302 b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, CALL_PROCEED, BPF_JEQ, 0); in gen_msg_abbrev()
10306 b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, CONNECT, BPF_JEQ, 0); in gen_msg_abbrev()
10310 b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, CONNECT_ACK, BPF_JEQ, 0); in gen_msg_abbrev()
10314 b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, RELEASE, BPF_JEQ, 0); in gen_msg_abbrev()
10318 b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, RELEASE_DONE, BPF_JEQ, 0); in gen_msg_abbrev()
10328 gen_atmmulti_abbrev(compiler_state_t *cstate, int type) in gen_atmmulti_abbrev() argument
10336 if (setjmp(cstate->top_ctx)) in gen_atmmulti_abbrev()
10342 if (!cstate->is_atm) in gen_atmmulti_abbrev()
10343 bpf_error(cstate, "'oam' supported only on raw ATM"); in gen_atmmulti_abbrev()
10345 b0 = gen_atmfield_code_internal(cstate, A_VCI, 3, BPF_JEQ, 0); in gen_atmmulti_abbrev()
10346 b1 = gen_atmfield_code_internal(cstate, A_VCI, 4, BPF_JEQ, 0); in gen_atmmulti_abbrev()
10348 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmmulti_abbrev()
10353 if (!cstate->is_atm) in gen_atmmulti_abbrev()
10354 bpf_error(cstate, "'oamf4' supported only on raw ATM"); in gen_atmmulti_abbrev()
10356 b0 = gen_atmfield_code_internal(cstate, A_VCI, 3, BPF_JEQ, 0); in gen_atmmulti_abbrev()
10357 b1 = gen_atmfield_code_internal(cstate, A_VCI, 4, BPF_JEQ, 0); in gen_atmmulti_abbrev()
10359 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmmulti_abbrev()
10368 if (!cstate->is_atm) in gen_atmmulti_abbrev()
10369 bpf_error(cstate, "'connectmsg' supported only on raw ATM"); in gen_atmmulti_abbrev()
10370 b0 = gen_msg_abbrev(cstate, A_SETUP); in gen_atmmulti_abbrev()
10371 b1 = gen_msg_abbrev(cstate, A_CALLPROCEED); in gen_atmmulti_abbrev()
10373 b0 = gen_msg_abbrev(cstate, A_CONNECT); in gen_atmmulti_abbrev()
10375 b0 = gen_msg_abbrev(cstate, A_CONNECTACK); in gen_atmmulti_abbrev()
10377 b0 = gen_msg_abbrev(cstate, A_RELEASE); in gen_atmmulti_abbrev()
10379 b0 = gen_msg_abbrev(cstate, A_RELEASE_DONE); in gen_atmmulti_abbrev()
10381 b0 = gen_atmtype_sc(cstate); in gen_atmmulti_abbrev()
10386 if (!cstate->is_atm) in gen_atmmulti_abbrev()
10387 bpf_error(cstate, "'metaconnect' supported only on raw ATM"); in gen_atmmulti_abbrev()
10388 b0 = gen_msg_abbrev(cstate, A_SETUP); in gen_atmmulti_abbrev()
10389 b1 = gen_msg_abbrev(cstate, A_CALLPROCEED); in gen_atmmulti_abbrev()
10391 b0 = gen_msg_abbrev(cstate, A_CONNECT); in gen_atmmulti_abbrev()
10393 b0 = gen_msg_abbrev(cstate, A_RELEASE); in gen_atmmulti_abbrev()
10395 b0 = gen_msg_abbrev(cstate, A_RELEASE_DONE); in gen_atmmulti_abbrev()
10397 b0 = gen_atmtype_metac(cstate); in gen_atmmulti_abbrev()