Lines Matching refs:cstate

434 bpf_set_error(compiler_state_t *cstate, const char *fmt, ...)  in bpf_set_error()  argument
439 (void)pcap_vsnprintf(cstate->bpf_pcap->errbuf, PCAP_ERRBUF_SIZE, in bpf_set_error()
452 bpf_error(compiler_state_t *cstate, const char *fmt, ...) in bpf_error() argument
457 (void)pcap_vsnprintf(cstate->bpf_pcap->errbuf, PCAP_ERRBUF_SIZE, in bpf_error()
460 longjmp(cstate->top_ctx, 1); in bpf_error()
470 static void initchunks(compiler_state_t *cstate);
471 static void *newchunk_nolongjmp(compiler_state_t *cstate, size_t);
472 static void *newchunk(compiler_state_t *cstate, size_t);
473 static void freechunks(compiler_state_t *cstate);
474 static inline struct block *new_block(compiler_state_t *cstate, int);
475 static inline struct slist *new_stmt(compiler_state_t *cstate, int);
476 static struct block *gen_retblk(compiler_state_t *cstate, int);
477 static inline void syntax(compiler_state_t *cstate);
566 static struct block *gen_geneve_ll_check(compiler_state_t *cstate);
575 initchunks(compiler_state_t *cstate) in initchunks() argument
580 cstate->chunks[i].n_left = 0; in initchunks()
581 cstate->chunks[i].m = NULL; in initchunks()
583 cstate->cur_chunk = 0; in initchunks()
587 newchunk_nolongjmp(compiler_state_t *cstate, size_t n) in newchunk_nolongjmp() argument
601 cp = &cstate->chunks[cstate->cur_chunk]; in newchunk_nolongjmp()
604 k = ++cstate->cur_chunk; in newchunk_nolongjmp()
606 bpf_set_error(cstate, "out of memory"); in newchunk_nolongjmp()
612 bpf_set_error(cstate, "out of memory"); in newchunk_nolongjmp()
618 bpf_set_error(cstate, "out of memory"); in newchunk_nolongjmp()
627 newchunk(compiler_state_t *cstate, size_t n) in newchunk() argument
631 p = newchunk_nolongjmp(cstate, n); in newchunk()
633 longjmp(cstate->top_ctx, 1); in newchunk()
640 freechunks(compiler_state_t *cstate) in freechunks() argument
645 if (cstate->chunks[i].m != NULL) in freechunks()
646 free(cstate->chunks[i].m); in freechunks()
656 sdup(compiler_state_t *cstate, const char *s) in sdup() argument
659 char *cp = newchunk_nolongjmp(cstate, n); in sdup()
668 new_block(compiler_state_t *cstate, int code) in new_block() argument
672 p = (struct block *)newchunk(cstate, sizeof(*p)); in new_block()
680 new_stmt(compiler_state_t *cstate, int code) in new_stmt() argument
684 p = (struct slist *)newchunk(cstate, sizeof(*p)); in new_stmt()
691 gen_retblk(compiler_state_t *cstate, int v) in gen_retblk() argument
693 struct block *b = new_block(cstate, BPF_RET|BPF_K); in gen_retblk()
700 syntax(compiler_state_t *cstate) in syntax() argument
702 bpf_error(cstate, "syntax error in filter expression"); in syntax()
712 compiler_state_t cstate; in pcap_compile() local
756 initchunks(&cstate); in pcap_compile()
757 cstate.no_optimize = 0; in pcap_compile()
759 cstate.ai = NULL; in pcap_compile()
761 cstate.e = NULL; in pcap_compile()
762 cstate.ic.root = NULL; in pcap_compile()
763 cstate.ic.cur_mark = 0; in pcap_compile()
764 cstate.bpf_pcap = p; in pcap_compile()
765 init_regs(&cstate); in pcap_compile()
767 cstate.netmask = mask; in pcap_compile()
769 cstate.snaplen = pcap_snapshot(p); in pcap_compile()
770 if (cstate.snaplen == 0) { in pcap_compile()
786 pcap_set_extra(&cstate, scanner); in pcap_compile()
788 if (init_linktype(&cstate, p) == -1) { in pcap_compile()
792 if (pcap_parse(scanner, &cstate) != 0) { in pcap_compile()
794 if (cstate.ai != NULL) in pcap_compile()
795 freeaddrinfo(cstate.ai); in pcap_compile()
797 if (cstate.e != NULL) in pcap_compile()
798 free(cstate.e); in pcap_compile()
803 if (cstate.ic.root == NULL) { in pcap_compile()
807 if (setjmp(cstate.top_ctx)) { in pcap_compile()
811 cstate.ic.root = gen_retblk(&cstate, cstate.snaplen); in pcap_compile()
814 if (optimize && !cstate.no_optimize) { in pcap_compile()
815 if (bpf_optimize(&cstate.ic, p->errbuf) == -1) { in pcap_compile()
820 if (cstate.ic.root == NULL || in pcap_compile()
821 (cstate.ic.root->s.code == (BPF_RET|BPF_K) && cstate.ic.root->s.k == 0)) { in pcap_compile()
828 program->bf_insns = icode_to_fcode(&cstate.ic, in pcap_compile()
829 cstate.ic.root, &len, p->errbuf); in pcap_compile()
851 freechunks(&cstate); in pcap_compile()
931 finish_parse(compiler_state_t *cstate, struct block *p) in finish_parse() argument
939 if (setjmp(cstate->top_ctx)) in finish_parse()
961 insert_compute_vloffsets(cstate, p->head); in finish_parse()
976 ppi_dlt_check = gen_ppi_dlt_check(cstate); in finish_parse()
980 backpatch(p, gen_retblk(cstate, cstate->snaplen)); in finish_parse()
982 backpatch(p, gen_retblk(cstate, 0)); in finish_parse()
983 cstate->ic.root = p->head; in finish_parse()
1015 gen_cmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_cmp() argument
1018 return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JEQ, 0, v); in gen_cmp()
1022 gen_cmp_gt(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_cmp_gt() argument
1025 return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JGT, 0, v); in gen_cmp_gt()
1029 gen_cmp_ge(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_cmp_ge() argument
1032 return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JGE, 0, v); in gen_cmp_ge()
1036 gen_cmp_lt(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_cmp_lt() argument
1039 return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JGE, 1, v); in gen_cmp_lt()
1043 gen_cmp_le(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_cmp_le() argument
1046 return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JGT, 1, v); in gen_cmp_le()
1050 gen_mcmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_mcmp() argument
1053 return gen_ncmp(cstate, offrel, offset, size, mask, BPF_JEQ, 0, v); in gen_mcmp()
1057 gen_bcmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_bcmp() argument
1076 tmp = gen_cmp(cstate, offrel, offset + size - 4, BPF_W, in gen_bcmp()
1086 tmp = gen_cmp(cstate, offrel, offset + size - 2, BPF_H, in gen_bcmp()
1094 tmp = gen_cmp(cstate, offrel, offset, BPF_B, (bpf_int32)v[0]); in gen_bcmp()
1109 gen_ncmp(compiler_state_t *cstate, enum e_offrel offrel, bpf_u_int32 offset, in gen_ncmp() argument
1116 s = gen_load_a(cstate, offrel, offset, size); in gen_ncmp()
1119 s2 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K); in gen_ncmp()
1124 b = new_block(cstate, JMP(jtype)); in gen_ncmp()
1133 init_linktype(compiler_state_t *cstate, pcap_t *p) in init_linktype() argument
1135 cstate->pcap_fddipad = p->fddipad; in init_linktype()
1140 cstate->outermostlinktype = pcap_datalink(p); in init_linktype()
1141 cstate->off_outermostlinkhdr.constant_part = 0; in init_linktype()
1142 cstate->off_outermostlinkhdr.is_variable = 0; in init_linktype()
1143 cstate->off_outermostlinkhdr.reg = -1; in init_linktype()
1145 cstate->prevlinktype = cstate->outermostlinktype; in init_linktype()
1146 cstate->off_prevlinkhdr.constant_part = 0; in init_linktype()
1147 cstate->off_prevlinkhdr.is_variable = 0; in init_linktype()
1148 cstate->off_prevlinkhdr.reg = -1; in init_linktype()
1150 cstate->linktype = cstate->outermostlinktype; in init_linktype()
1151 cstate->off_linkhdr.constant_part = 0; in init_linktype()
1152 cstate->off_linkhdr.is_variable = 0; in init_linktype()
1153 cstate->off_linkhdr.reg = -1; in init_linktype()
1158 cstate->off_linkpl.constant_part = 0; in init_linktype()
1159 cstate->off_linkpl.is_variable = 0; in init_linktype()
1160 cstate->off_linkpl.reg = -1; in init_linktype()
1162 cstate->off_linktype.constant_part = 0; in init_linktype()
1163 cstate->off_linktype.is_variable = 0; in init_linktype()
1164 cstate->off_linktype.reg = -1; in init_linktype()
1169 cstate->is_atm = 0; in init_linktype()
1170 cstate->off_vpi = OFFSET_NOT_SET; in init_linktype()
1171 cstate->off_vci = OFFSET_NOT_SET; in init_linktype()
1172 cstate->off_proto = OFFSET_NOT_SET; in init_linktype()
1173 cstate->off_payload = OFFSET_NOT_SET; in init_linktype()
1178 cstate->is_geneve = 0; in init_linktype()
1183 cstate->is_vlan_vloffset = 0; in init_linktype()
1188 cstate->off_li = OFFSET_NOT_SET; in init_linktype()
1189 cstate->off_li_hsl = OFFSET_NOT_SET; in init_linktype()
1190 cstate->off_sio = OFFSET_NOT_SET; in init_linktype()
1191 cstate->off_opc = OFFSET_NOT_SET; in init_linktype()
1192 cstate->off_dpc = OFFSET_NOT_SET; in init_linktype()
1193 cstate->off_sls = OFFSET_NOT_SET; in init_linktype()
1195 cstate->label_stack_depth = 0; in init_linktype()
1196 cstate->vlan_stack_depth = 0; in init_linktype()
1198 switch (cstate->linktype) { in init_linktype()
1201 cstate->off_linktype.constant_part = 2; in init_linktype()
1202 cstate->off_linkpl.constant_part = 6; in init_linktype()
1203 cstate->off_nl = 0; /* XXX in reality, variable! */ in init_linktype()
1204 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1208 cstate->off_linktype.constant_part = 4; in init_linktype()
1209 cstate->off_linkpl.constant_part = 8; in init_linktype()
1210 cstate->off_nl = 0; /* XXX in reality, variable! */ in init_linktype()
1211 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1215 cstate->off_linktype.constant_part = 12; in init_linktype()
1216 cstate->off_linkpl.constant_part = 14; /* Ethernet header length */ in init_linktype()
1217 cstate->off_nl = 0; /* Ethernet II */ in init_linktype()
1218 cstate->off_nl_nosnap = 3; /* 802.3+802.2 */ in init_linktype()
1226 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1227 cstate->off_linkpl.constant_part = 16; in init_linktype()
1228 cstate->off_nl = 0; in init_linktype()
1229 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1234 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1236 cstate->off_linkpl.constant_part = 24; in init_linktype()
1237 cstate->off_nl = 0; in init_linktype()
1238 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1243 cstate->off_linktype.constant_part = 0; in init_linktype()
1244 cstate->off_linkpl.constant_part = 4; in init_linktype()
1245 cstate->off_nl = 0; in init_linktype()
1246 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1250 cstate->off_linktype.constant_part = 0; in init_linktype()
1251 cstate->off_linkpl.constant_part = 12; in init_linktype()
1252 cstate->off_nl = 0; in init_linktype()
1253 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1260 cstate->off_linktype.constant_part = 2; /* skip HDLC-like framing */ in init_linktype()
1261 cstate->off_linkpl.constant_part = 4; /* skip HDLC-like framing and protocol field */ in init_linktype()
1262 cstate->off_nl = 0; in init_linktype()
1263 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1271 cstate->off_linktype.constant_part = 6; in init_linktype()
1272 cstate->off_linkpl.constant_part = 8; in init_linktype()
1273 cstate->off_nl = 0; in init_linktype()
1274 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1278 cstate->off_linktype.constant_part = 5; in init_linktype()
1279 cstate->off_linkpl.constant_part = 24; in init_linktype()
1280 cstate->off_nl = 0; in init_linktype()
1281 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1293 cstate->off_linktype.constant_part = 13; in init_linktype()
1294 cstate->off_linktype.constant_part += cstate->pcap_fddipad; in init_linktype()
1295 cstate->off_linkpl.constant_part = 13; /* FDDI MAC header length */ in init_linktype()
1296 cstate->off_linkpl.constant_part += cstate->pcap_fddipad; in init_linktype()
1297 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1298 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1325 cstate->off_linktype.constant_part = 14; in init_linktype()
1326 cstate->off_linkpl.constant_part = 14; /* Token Ring MAC header length */ in init_linktype()
1327 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1328 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1334 cstate->off_linkhdr.is_variable = 1; in init_linktype()
1358 cstate->off_linktype.constant_part = 24; in init_linktype()
1359 cstate->off_linkpl.constant_part = 0; /* link-layer header is variable-length */ in init_linktype()
1360 cstate->off_linkpl.is_variable = 1; in init_linktype()
1361 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1362 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1375 cstate->off_linktype.constant_part = 24; in init_linktype()
1376 cstate->off_linkpl.constant_part = 0; /* link-layer header is variable-length */ in init_linktype()
1377 cstate->off_linkpl.is_variable = 1; in init_linktype()
1378 cstate->off_linkhdr.is_variable = 1; in init_linktype()
1379 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1380 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1396 cstate->off_linktype.constant_part = 0; in init_linktype()
1397 cstate->off_linkpl.constant_part = 0; /* packet begins with LLC header */ in init_linktype()
1398 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1399 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1407 cstate->is_atm = 1; in init_linktype()
1408 cstate->off_vpi = SUNATM_VPI_POS; in init_linktype()
1409 cstate->off_vci = SUNATM_VCI_POS; in init_linktype()
1410 cstate->off_proto = PROTO_POS; in init_linktype()
1411 cstate->off_payload = SUNATM_PKT_BEGIN_POS; in init_linktype()
1412 cstate->off_linktype.constant_part = cstate->off_payload; in init_linktype()
1413 cstate->off_linkpl.constant_part = cstate->off_payload; /* if LLC-encapsulated */ in init_linktype()
1414 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1415 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1421 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1422 cstate->off_linkpl.constant_part = 0; in init_linktype()
1423 cstate->off_nl = 0; in init_linktype()
1424 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1428 cstate->off_linktype.constant_part = 14; in init_linktype()
1429 cstate->off_linkpl.constant_part = 16; in init_linktype()
1430 cstate->off_nl = 0; in init_linktype()
1431 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1435 cstate->off_linktype.constant_part = 0; in init_linktype()
1436 cstate->off_linkpl.constant_part = 20; in init_linktype()
1437 cstate->off_nl = 0; in init_linktype()
1438 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1447 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1448 cstate->off_linkpl.constant_part = 0; in init_linktype()
1449 cstate->off_nl = 0; in init_linktype()
1450 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1464 cstate->off_linktype.constant_part = 16; in init_linktype()
1465 cstate->off_linkpl.constant_part = 16; in init_linktype()
1466 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1467 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1475 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1476 cstate->off_linkpl.constant_part = 0; in init_linktype()
1477 cstate->off_nl = 0; in init_linktype()
1478 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1487 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1488 cstate->off_linkpl.constant_part = 0; in init_linktype()
1489 cstate->off_nl = 4; in init_linktype()
1490 cstate->off_nl_nosnap = 0; /* XXX - for now -> no 802.2 LLC */ in init_linktype()
1494 cstate->off_linktype.constant_part = 16; in init_linktype()
1495 cstate->off_linkpl.constant_part = 18; in init_linktype()
1496 cstate->off_nl = 0; in init_linktype()
1497 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1501 cstate->off_linktype.constant_part = 6; in init_linktype()
1502 cstate->off_linkpl.constant_part = 44; in init_linktype()
1503 cstate->off_nl = 0; /* Ethernet II */ in init_linktype()
1504 cstate->off_nl_nosnap = 0; /* XXX - what does it do with 802.3 packets? */ in init_linktype()
1509 cstate->off_linktype.constant_part = 0; in init_linktype()
1510 cstate->off_linkpl.constant_part = PFLOG_HDRLEN; in init_linktype()
1511 cstate->off_nl = 0; in init_linktype()
1512 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1522 cstate->off_linktype.constant_part = 4; in init_linktype()
1523 cstate->off_linkpl.constant_part = 4; in init_linktype()
1524 cstate->off_nl = 0; in init_linktype()
1525 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1529 cstate->off_linktype.constant_part = 4; /* in reality variable between 4-8 */ in init_linktype()
1530 cstate->off_linkpl.constant_part = 4; /* in reality variable between 4-8 */ in init_linktype()
1531 cstate->off_nl = 0; in init_linktype()
1532 cstate->off_nl_nosnap = 10; in init_linktype()
1536 cstate->off_linktype.constant_part = 8; /* in reality variable between 8-12 */ in init_linktype()
1537 cstate->off_linkpl.constant_part = 8; /* in reality variable between 8-12 */ in init_linktype()
1538 cstate->off_nl = 0; in init_linktype()
1539 cstate->off_nl_nosnap = 10; in init_linktype()
1546 cstate->off_linkpl.constant_part = 14; in init_linktype()
1547 cstate->off_linktype.constant_part = 16; in init_linktype()
1548 cstate->off_nl = 18; /* Ethernet II */ in init_linktype()
1549 cstate->off_nl_nosnap = 21; /* 802.3+802.2 */ in init_linktype()
1553 cstate->off_linktype.constant_part = 4; in init_linktype()
1554 cstate->off_linkpl.constant_part = 6; 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 = 6; in init_linktype()
1561 cstate->off_linkpl.constant_part = 12; in init_linktype()
1562 cstate->off_nl = 0; in init_linktype()
1563 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1567 cstate->off_linktype.constant_part = 6; in init_linktype()
1568 …cstate->off_linkpl.constant_part = OFFSET_NOT_SET; /* not really a network layer but raw IP addres… in init_linktype()
1569 cstate->off_nl = OFFSET_NOT_SET; /* not really a network layer but raw IP addresses */ in init_linktype()
1570 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1574 cstate->off_linktype.constant_part = 12; in init_linktype()
1575 cstate->off_linkpl.constant_part = 12; in init_linktype()
1576 cstate->off_nl = 0; /* raw IP/IP6 header */ in init_linktype()
1577 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1581 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1582 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1583 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1584 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1588 cstate->off_linktype.constant_part = 12; in init_linktype()
1589 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; /* L3 proto location dep. on cookie type */ in init_linktype()
1590 cstate->off_nl = OFFSET_NOT_SET; /* L3 proto location dep. on cookie type */ in init_linktype()
1591 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1595 cstate->off_linktype.constant_part = 18; in init_linktype()
1596 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1597 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1598 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1602 cstate->off_linktype.constant_part = 18; in init_linktype()
1603 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1604 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1605 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1609 cstate->off_linktype.constant_part = 8; in init_linktype()
1610 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1611 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1612 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1619 cstate->off_linktype.constant_part = 8; in init_linktype()
1620 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1621 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1622 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1626 cstate->off_li = 2; in init_linktype()
1627 cstate->off_li_hsl = 4; in init_linktype()
1628 cstate->off_sio = 3; in init_linktype()
1629 cstate->off_opc = 4; in init_linktype()
1630 cstate->off_dpc = 4; in init_linktype()
1631 cstate->off_sls = 7; in init_linktype()
1632 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1633 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1634 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1635 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1639 cstate->off_li = 6; in init_linktype()
1640 cstate->off_li_hsl = 8; in init_linktype()
1641 cstate->off_sio = 7; in init_linktype()
1642 cstate->off_opc = 8; in init_linktype()
1643 cstate->off_dpc = 8; in init_linktype()
1644 cstate->off_sls = 11; in init_linktype()
1645 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1646 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1647 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1648 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1652 cstate->off_li = 22; in init_linktype()
1653 cstate->off_li_hsl = 24; in init_linktype()
1654 cstate->off_sio = 23; in init_linktype()
1655 cstate->off_opc = 24; in init_linktype()
1656 cstate->off_dpc = 24; in init_linktype()
1657 cstate->off_sls = 27; in init_linktype()
1658 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1659 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1660 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1661 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1665 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1666 cstate->off_linkpl.constant_part = 4; in init_linktype()
1667 cstate->off_nl = 0; in init_linktype()
1668 cstate->off_nl_nosnap = 0; in init_linktype()
1675 cstate->off_linktype.constant_part = OFFSET_NOT_SET; /* variable, min 15, max 71 steps of 7 */ in init_linktype()
1676 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1677 cstate->off_nl = OFFSET_NOT_SET; /* variable, min 16, max 71 steps of 7 */ in init_linktype()
1678 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1682 cstate->off_linktype.constant_part = 1; in init_linktype()
1683 cstate->off_linkpl.constant_part = 24; /* ipnet header length */ in init_linktype()
1684 cstate->off_nl = 0; in init_linktype()
1685 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1689 cstate->off_linkhdr.constant_part = 4; /* Ethernet header is past 4-byte pseudo-header */ in init_linktype()
1690 cstate->off_linktype.constant_part = cstate->off_linkhdr.constant_part + 12; in init_linktype()
1691 …cstate->off_linkpl.constant_part = cstate->off_linkhdr.constant_part + 14; /* pseudo-header+Ethern… in init_linktype()
1692 cstate->off_nl = 0; /* Ethernet II */ in init_linktype()
1693 cstate->off_nl_nosnap = 3; /* 802.3+802.2 */ in init_linktype()
1697 …cstate->off_linkhdr.constant_part = 12; /* MAC header is past 4-byte pseudo-header, preamble, and … in init_linktype()
1698 cstate->off_linktype.constant_part = cstate->off_linkhdr.constant_part + 12; in init_linktype()
1699 …cstate->off_linkpl.constant_part = cstate->off_linkhdr.constant_part + 14; /* pseudo-header+preamb… in init_linktype()
1700 cstate->off_nl = 0; /* Ethernet II */ in init_linktype()
1701 cstate->off_nl_nosnap = 3; /* 802.3+802.2 */ in init_linktype()
1709 if (cstate->linktype >= DLT_MATCHING_MIN && in init_linktype()
1710 cstate->linktype <= DLT_MATCHING_MAX) { in init_linktype()
1711 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1712 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1713 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1714 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1716 bpf_set_error(cstate, "unknown data link type %d", cstate->linktype); in init_linktype()
1722 cstate->off_outermostlinkhdr = cstate->off_prevlinkhdr = cstate->off_linkhdr; in init_linktype()
1730 gen_load_absoffsetrel(compiler_state_t *cstate, bpf_abs_offset *abs_offset, in gen_load_absoffsetrel() argument
1735 s = gen_abs_offset_varpart(cstate, abs_offset); in gen_load_absoffsetrel()
1752 s2 = new_stmt(cstate, BPF_LD|BPF_IND|size); in gen_load_absoffsetrel()
1760 s = new_stmt(cstate, BPF_LD|BPF_ABS|size); in gen_load_absoffsetrel()
1770 gen_load_a(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_load_a() argument
1791 s = new_stmt(cstate, BPF_LD|BPF_ABS|size); in gen_load_a()
1796 s = gen_load_absoffsetrel(cstate, &cstate->off_linkhdr, offset, size); in gen_load_a()
1800 s = gen_load_absoffsetrel(cstate, &cstate->off_prevlinkhdr, offset, size); in gen_load_a()
1804 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, offset, size); in gen_load_a()
1808 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, cstate->off_nl - 4 + offset, size); in gen_load_a()
1812 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, cstate->off_nl + offset, size); in gen_load_a()
1816 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, cstate->off_nl_nosnap + offset, size); in gen_load_a()
1820 s = gen_load_absoffsetrel(cstate, &cstate->off_linktype, offset, size); in gen_load_a()
1830 s = gen_loadx_iphdrlen(cstate); in gen_load_a()
1843 s2 = new_stmt(cstate, BPF_LD|BPF_IND|size); in gen_load_a()
1844 s2->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + offset; in gen_load_a()
1849 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, cstate->off_nl + 40 + offset, size); in gen_load_a()
1861 gen_loadx_iphdrlen(compiler_state_t *cstate) in gen_loadx_iphdrlen() argument
1865 s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl); in gen_loadx_iphdrlen()
1877 s2 = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_loadx_iphdrlen()
1878 s2->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_loadx_iphdrlen()
1880 s2 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K); in gen_loadx_iphdrlen()
1883 s2 = new_stmt(cstate, BPF_ALU|BPF_LSH|BPF_K); in gen_loadx_iphdrlen()
1893 sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X)); in gen_loadx_iphdrlen()
1894 sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX)); in gen_loadx_iphdrlen()
1908 s = new_stmt(cstate, BPF_LDX|BPF_MSH|BPF_B); in gen_loadx_iphdrlen()
1909 s->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_loadx_iphdrlen()
1916 gen_uncond(compiler_state_t *cstate, int rsense) in gen_uncond() argument
1921 s = new_stmt(cstate, BPF_LD|BPF_IMM); in gen_uncond()
1923 b = new_block(cstate, JMP(BPF_JEQ)); in gen_uncond()
1930 gen_true(compiler_state_t *cstate) in gen_true() argument
1932 return gen_uncond(cstate, 1); in gen_true()
1936 gen_false(compiler_state_t *cstate) in gen_false() argument
1938 return gen_uncond(cstate, 0); in gen_false()
1959 gen_ether_linktype(compiler_state_t *cstate, int proto) in gen_ether_linktype() argument
1980 b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU); in gen_ether_linktype()
1982 b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, (bpf_int32) in gen_ether_linktype()
2020 b0 = gen_cmp(cstate, OR_LLC, 0, BPF_B, (bpf_int32)LLCSAP_IPX); in gen_ether_linktype()
2021 b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, (bpf_int32)0xFFFF); in gen_ether_linktype()
2028 b0 = gen_snap(cstate, 0x000000, ETHERTYPE_IPX); in gen_ether_linktype()
2035 b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU); in gen_ether_linktype()
2051 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)ETHERTYPE_IPX); in gen_ether_linktype()
2067 b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU); in gen_ether_linktype()
2082 b1 = gen_snap(cstate, 0x080007, ETHERTYPE_ATALK); in gen_ether_linktype()
2084 b1 = gen_snap(cstate, 0x000000, ETHERTYPE_AARP); in gen_ether_linktype()
2092 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)proto); in gen_ether_linktype()
2107 b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU); in gen_ether_linktype()
2109 b1 = gen_cmp(cstate, OR_LINKTYPE, 2, BPF_B, (bpf_int32)proto); in gen_ether_linktype()
2122 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, in gen_ether_linktype()
2129 gen_loopback_linktype(compiler_state_t *cstate, int proto) in gen_loopback_linktype() argument
2144 if (cstate->linktype == DLT_NULL || cstate->linktype == DLT_ENC) { in gen_loopback_linktype()
2156 if (cstate->bpf_pcap->rfile != NULL && cstate->bpf_pcap->swapped) in gen_loopback_linktype()
2160 return (gen_cmp(cstate, OR_LINKHDR, 0, BPF_W, (bpf_int32)proto)); in gen_loopback_linktype()
2168 gen_ipnet_linktype(compiler_state_t *cstate, int proto) in gen_ipnet_linktype() argument
2173 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, (bpf_int32)IPH_AF_INET); in gen_ipnet_linktype()
2177 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_ipnet_linktype()
2185 return gen_false(cstate); in gen_ipnet_linktype()
2197 gen_linux_sll_linktype(compiler_state_t *cstate, int proto) in gen_linux_sll_linktype() argument
2218 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, LINUX_SLL_P_802_2); in gen_linux_sll_linktype()
2219 b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, (bpf_int32) in gen_linux_sll_linktype()
2250 b0 = gen_cmp(cstate, OR_LLC, 0, BPF_B, (bpf_int32)LLCSAP_IPX); in gen_linux_sll_linktype()
2251 b1 = gen_snap(cstate, 0x000000, ETHERTYPE_IPX); in gen_linux_sll_linktype()
2253 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, LINUX_SLL_P_802_2); in gen_linux_sll_linktype()
2260 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, LINUX_SLL_P_802_3); in gen_linux_sll_linktype()
2268 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)ETHERTYPE_IPX); in gen_linux_sll_linktype()
2284 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, LINUX_SLL_P_802_2); in gen_linux_sll_linktype()
2298 b1 = gen_snap(cstate, 0x080007, ETHERTYPE_ATALK); in gen_linux_sll_linktype()
2300 b1 = gen_snap(cstate, 0x000000, ETHERTYPE_AARP); in gen_linux_sll_linktype()
2308 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)proto); in gen_linux_sll_linktype()
2322 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, LINUX_SLL_P_802_2); in gen_linux_sll_linktype()
2323 b1 = gen_cmp(cstate, OR_LINKHDR, cstate->off_linkpl.constant_part, BPF_B, in gen_linux_sll_linktype()
2337 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)proto); in gen_linux_sll_linktype()
2343 gen_load_prism_llprefixlen(compiler_state_t *cstate) in gen_load_prism_llprefixlen() argument
2354 cstate->no_optimize = 1; in gen_load_prism_llprefixlen()
2375 if (cstate->off_linkhdr.reg != -1) { in gen_load_prism_llprefixlen()
2379 s1 = new_stmt(cstate, BPF_LD|BPF_W|BPF_ABS); in gen_load_prism_llprefixlen()
2385 s2 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K); in gen_load_prism_llprefixlen()
2392 sjeq_avs_cookie = new_stmt(cstate, JMP(BPF_JEQ)); in gen_load_prism_llprefixlen()
2403 s2 = new_stmt(cstate, BPF_LD|BPF_W|BPF_ABS); in gen_load_prism_llprefixlen()
2416 sjcommon = new_stmt(cstate, JMP(BPF_JA)); in gen_load_prism_llprefixlen()
2426 s2 = new_stmt(cstate, BPF_LD|BPF_W|BPF_IMM); in gen_load_prism_llprefixlen()
2436 s2 = new_stmt(cstate, BPF_ST); in gen_load_prism_llprefixlen()
2437 s2->s.k = cstate->off_linkhdr.reg; in gen_load_prism_llprefixlen()
2444 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_prism_llprefixlen()
2453 gen_load_avs_llprefixlen(compiler_state_t *cstate) in gen_load_avs_llprefixlen() argument
2464 if (cstate->off_linkhdr.reg != -1) { in gen_load_avs_llprefixlen()
2470 s1 = new_stmt(cstate, BPF_LD|BPF_W|BPF_ABS); in gen_load_avs_llprefixlen()
2477 s2 = new_stmt(cstate, BPF_ST); in gen_load_avs_llprefixlen()
2478 s2->s.k = cstate->off_linkhdr.reg; in gen_load_avs_llprefixlen()
2484 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_avs_llprefixlen()
2493 gen_load_radiotap_llprefixlen(compiler_state_t *cstate) in gen_load_radiotap_llprefixlen() argument
2504 if (cstate->off_linkhdr.reg != -1) { in gen_load_radiotap_llprefixlen()
2516 s1 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_load_radiotap_llprefixlen()
2518 s2 = new_stmt(cstate, BPF_ALU|BPF_LSH|BPF_K); in gen_load_radiotap_llprefixlen()
2521 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_radiotap_llprefixlen()
2528 s2 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_load_radiotap_llprefixlen()
2531 s2 = new_stmt(cstate, BPF_ALU|BPF_OR|BPF_X); in gen_load_radiotap_llprefixlen()
2538 s2 = new_stmt(cstate, BPF_ST); in gen_load_radiotap_llprefixlen()
2539 s2->s.k = cstate->off_linkhdr.reg; in gen_load_radiotap_llprefixlen()
2545 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_radiotap_llprefixlen()
2563 gen_load_ppi_llprefixlen(compiler_state_t *cstate) in gen_load_ppi_llprefixlen() argument
2572 if (cstate->off_linkhdr.reg != -1) { in gen_load_ppi_llprefixlen()
2584 s1 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_load_ppi_llprefixlen()
2586 s2 = new_stmt(cstate, BPF_ALU|BPF_LSH|BPF_K); in gen_load_ppi_llprefixlen()
2589 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_ppi_llprefixlen()
2596 s2 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_load_ppi_llprefixlen()
2599 s2 = new_stmt(cstate, BPF_ALU|BPF_OR|BPF_X); in gen_load_ppi_llprefixlen()
2606 s2 = new_stmt(cstate, BPF_ST); in gen_load_ppi_llprefixlen()
2607 s2->s.k = cstate->off_linkhdr.reg; in gen_load_ppi_llprefixlen()
2613 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_ppi_llprefixlen()
2629 gen_load_802_11_header_len(compiler_state_t *cstate, struct slist *s, struct slist *snext) in gen_load_802_11_header_len() argument
2641 if (cstate->off_linkpl.reg == -1) { in gen_load_802_11_header_len()
2656 cstate->no_optimize = 1; in gen_load_802_11_header_len()
2676 s = new_stmt(cstate, BPF_LDX|BPF_IMM); in gen_load_802_11_header_len()
2677 s->s.k = cstate->off_outermostlinkhdr.constant_part; in gen_load_802_11_header_len()
2687 s2 = new_stmt(cstate, BPF_MISC|BPF_TXA); in gen_load_802_11_header_len()
2689 s2 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_load_802_11_header_len()
2692 s2 = new_stmt(cstate, BPF_ST); in gen_load_802_11_header_len()
2693 s2->s.k = cstate->off_linkpl.reg; in gen_load_802_11_header_len()
2696 s2 = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_load_802_11_header_len()
2705 sjset_data_frame_1 = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2713 sjset_data_frame_1->s.jt = sjset_data_frame_2 = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2724 sjset_data_frame_2->s.jf = sjset_qos = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2734 sjset_qos->s.jt = s2 = new_stmt(cstate, BPF_LD|BPF_MEM); in gen_load_802_11_header_len()
2735 s2->s.k = cstate->off_linkpl.reg; in gen_load_802_11_header_len()
2737 s2 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_IMM); in gen_load_802_11_header_len()
2740 s2 = new_stmt(cstate, BPF_ST); in gen_load_802_11_header_len()
2741 s2->s.k = cstate->off_linkpl.reg; in gen_load_802_11_header_len()
2763 if (cstate->linktype == DLT_IEEE802_11_RADIO) { in gen_load_802_11_header_len()
2768 sjset_qos->s.jf = s2 = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_W); in gen_load_802_11_header_len()
2772 sjset_radiotap_flags_present = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2784 sjset_radiotap_ext_present = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2797 sjset_radiotap_tsft_present = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2811 s2 = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_B); in gen_load_802_11_header_len()
2816 sjset_tsft_datapad = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2828 s2 = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_B); in gen_load_802_11_header_len()
2833 sjset_notsft_datapad = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2844 s_roundup = new_stmt(cstate, BPF_LD|BPF_MEM); in gen_load_802_11_header_len()
2845 s_roundup->s.k = cstate->off_linkpl.reg; in gen_load_802_11_header_len()
2847 s2 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_IMM); in gen_load_802_11_header_len()
2850 s2 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_IMM); in gen_load_802_11_header_len()
2853 s2 = new_stmt(cstate, BPF_ST); in gen_load_802_11_header_len()
2854 s2->s.k = cstate->off_linkpl.reg; in gen_load_802_11_header_len()
2868 insert_compute_vloffsets(compiler_state_t *cstate, struct block *b) in insert_compute_vloffsets() argument
2877 if (cstate->off_linkpl.reg != -1 && cstate->off_linkhdr.is_variable && in insert_compute_vloffsets()
2878 cstate->off_linkhdr.reg == -1) in insert_compute_vloffsets()
2879 cstate->off_linkhdr.reg = alloc_reg(cstate); in insert_compute_vloffsets()
2892 switch (cstate->outermostlinktype) { in insert_compute_vloffsets()
2895 s = gen_load_prism_llprefixlen(cstate); in insert_compute_vloffsets()
2899 s = gen_load_avs_llprefixlen(cstate); in insert_compute_vloffsets()
2903 s = gen_load_radiotap_llprefixlen(cstate); in insert_compute_vloffsets()
2907 s = gen_load_ppi_llprefixlen(cstate); in insert_compute_vloffsets()
2920 switch (cstate->outermostlinktype) { in insert_compute_vloffsets()
2927 s = gen_load_802_11_header_len(cstate, s, b->stmts); in insert_compute_vloffsets()
2935 if (s == NULL && cstate->is_vlan_vloffset) { in insert_compute_vloffsets()
2938 if (cstate->off_linkpl.reg == -1) in insert_compute_vloffsets()
2939 cstate->off_linkpl.reg = alloc_reg(cstate); in insert_compute_vloffsets()
2940 if (cstate->off_linktype.reg == -1) in insert_compute_vloffsets()
2941 cstate->off_linktype.reg = alloc_reg(cstate); in insert_compute_vloffsets()
2943 s = new_stmt(cstate, BPF_LD|BPF_W|BPF_IMM); in insert_compute_vloffsets()
2945 s2 = new_stmt(cstate, BPF_ST); in insert_compute_vloffsets()
2946 s2->s.k = cstate->off_linkpl.reg; in insert_compute_vloffsets()
2948 s2 = new_stmt(cstate, BPF_ST); in insert_compute_vloffsets()
2949 s2->s.k = cstate->off_linktype.reg; in insert_compute_vloffsets()
2966 gen_ppi_dlt_check(compiler_state_t *cstate) in gen_ppi_dlt_check() argument
2971 if (cstate->linktype == DLT_PPI) in gen_ppi_dlt_check()
2975 s_load_dlt = new_stmt(cstate, BPF_LD|BPF_W|BPF_ABS); in gen_ppi_dlt_check()
2978 b = new_block(cstate, JMP(BPF_JEQ)); in gen_ppi_dlt_check()
3005 gen_abs_offset_varpart(compiler_state_t *cstate, bpf_abs_offset *off) in gen_abs_offset_varpart() argument
3016 off->reg = alloc_reg(cstate); in gen_abs_offset_varpart()
3023 s = new_stmt(cstate, BPF_LDX|BPF_MEM); in gen_abs_offset_varpart()
3090 gen_prevlinkhdr_check(compiler_state_t *cstate) in gen_prevlinkhdr_check() argument
3094 if (cstate->is_geneve) in gen_prevlinkhdr_check()
3095 return gen_geneve_ll_check(cstate); in gen_prevlinkhdr_check()
3097 switch (cstate->prevlinktype) { in gen_prevlinkhdr_check()
3107 b0 = gen_cmp(cstate, OR_PREVLINKHDR, SUNATM_PKT_BEGIN_POS, BPF_H, 0xFF00); in gen_prevlinkhdr_check()
3136 gen_linktype(compiler_state_t *cstate, int proto) in gen_linktype() argument
3142 if (cstate->label_stack_depth > 0) { in gen_linktype()
3147 return gen_mpls_linktype(cstate, Q_IP); in gen_linktype()
3152 return gen_mpls_linktype(cstate, Q_IPV6); in gen_linktype()
3155 bpf_error(cstate, "unsupported protocol over mpls"); in gen_linktype()
3160 switch (cstate->linktype) { in gen_linktype()
3167 if (!cstate->is_geneve) in gen_linktype()
3168 b0 = gen_prevlinkhdr_check(cstate); in gen_linktype()
3172 b1 = gen_ether_linktype(cstate, proto); in gen_linktype()
3186 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)proto); in gen_linktype()
3198 b0 = gen_check_802_11_data_frame(cstate); in gen_linktype()
3203 b1 = gen_llc_linktype(cstate, proto); in gen_linktype()
3212 return gen_llc_linktype(cstate, proto); in gen_linktype()
3219 return gen_llc_linktype(cstate, proto); in gen_linktype()
3225 return gen_llc_linktype(cstate, proto); in gen_linktype()
3236 b0 = gen_atmfield_code_internal(cstate, A_PROTOTYPE, PT_LLC, BPF_JEQ, 0); in gen_linktype()
3237 b1 = gen_llc_linktype(cstate, proto); in gen_linktype()
3243 return gen_linux_sll_linktype(cstate, proto); in gen_linktype()
3260 return gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, 0x40, 0xF0); in gen_linktype()
3264 return gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, 0x60, 0xF0); in gen_linktype()
3267 return gen_false(cstate); /* always false */ in gen_linktype()
3276 return gen_true(cstate); /* always true */ in gen_linktype()
3279 return gen_false(cstate); in gen_linktype()
3287 return gen_true(cstate); /* always true */ in gen_linktype()
3290 return gen_false(cstate); in gen_linktype()
3302 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)proto); in gen_linktype()
3317 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, PPP_IP); in gen_linktype()
3318 b1 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, PPP_VJC); in gen_linktype()
3320 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, PPP_VJNC); in gen_linktype()
3326 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, in gen_linktype()
3337 return (gen_loopback_linktype(cstate, AF_INET)); in gen_linktype()
3362 if (cstate->bpf_pcap->rfile != NULL) { in gen_linktype()
3367 b0 = gen_loopback_linktype(cstate, BSD_AFNUM_INET6_BSD); in gen_linktype()
3368 b1 = gen_loopback_linktype(cstate, BSD_AFNUM_INET6_FREEBSD); in gen_linktype()
3370 b0 = gen_loopback_linktype(cstate, BSD_AFNUM_INET6_DARWIN); in gen_linktype()
3386 return (gen_loopback_linktype(cstate, 24)); in gen_linktype()
3389 return (gen_loopback_linktype(cstate, AF_INET6)); in gen_linktype()
3395 return gen_false(cstate); in gen_linktype()
3406 return gen_false(cstate); in gen_linktype()
3416 return (gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, af), in gen_linktype()
3419 return (gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, af), in gen_linktype()
3422 return gen_false(cstate); in gen_linktype()
3435 return gen_false(cstate); in gen_linktype()
3438 return (gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3442 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3444 b1 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3450 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3452 b1 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3458 return (gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3462 return (gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3470 return gen_true(cstate); in gen_linktype()
3472 return gen_false(cstate); in gen_linktype()
3487 return gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | 0xcc); in gen_linktype()
3493 return gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | 0x8e); in gen_linktype()
3507 b0 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | ISO8473_CLNP); in gen_linktype()
3508 b1 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | ISO9542_ESIS); in gen_linktype()
3509 b2 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | ISO10589_ISIS); in gen_linktype()
3515 return gen_false(cstate); in gen_linktype()
3520 bpf_error(cstate, "Multi-link Frame Relay link-layer type filtering not implemented"); in gen_linktype()
3552 …return gen_mcmp(cstate, OR_LINKHDR, 0, BPF_W, 0x4d474300, 0xffffff00); /* compare the magic number… in gen_linktype()
3555 return gen_mcmp(cstate, OR_LINKHDR, 0, BPF_W, 0x55FF0000, 0xffff0000); in gen_linktype()
3558 return gen_ipnet_linktype(cstate, proto); in gen_linktype()
3561 bpf_error(cstate, "IrDA link-layer type filtering not implemented"); in gen_linktype()
3564 bpf_error(cstate, "DOCSIS link-layer type filtering not implemented"); in gen_linktype()
3568 bpf_error(cstate, "MTP2 link-layer type filtering not implemented"); in gen_linktype()
3571 bpf_error(cstate, "ERF link-layer type filtering not implemented"); in gen_linktype()
3574 bpf_error(cstate, "PFSYNC link-layer type filtering not implemented"); in gen_linktype()
3577 bpf_error(cstate, "LAPD link-layer type filtering not implemented"); in gen_linktype()
3583 bpf_error(cstate, "USB link-layer type filtering not implemented"); in gen_linktype()
3587 bpf_error(cstate, "Bluetooth link-layer type filtering not implemented"); in gen_linktype()
3591 bpf_error(cstate, "CAN link-layer type filtering not implemented"); in gen_linktype()
3597 bpf_error(cstate, "IEEE 802.15.4 link-layer type filtering not implemented"); in gen_linktype()
3600 bpf_error(cstate, "IEEE 802.16 link-layer type filtering not implemented"); in gen_linktype()
3603 bpf_error(cstate, "SITA link-layer type filtering not implemented"); in gen_linktype()
3606 bpf_error(cstate, "RAIF1 link-layer type filtering not implemented"); in gen_linktype()
3610 bpf_error(cstate, "IPMB link-layer type filtering not implemented"); in gen_linktype()
3613 bpf_error(cstate, "AX.25 link-layer type filtering not implemented"); in gen_linktype()
3620 bpf_error(cstate, "NFLOG link-layer type filtering not implemented"); in gen_linktype()
3629 if (cstate->off_linktype.constant_part != OFFSET_NOT_SET) { in gen_linktype()
3635 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)proto); in gen_linktype()
3641 description = pcap_datalink_val_to_description_or_dlt(cstate->linktype); in gen_linktype()
3642 bpf_error(cstate, "%s link-layer type filtering not implemented", in gen_linktype()
3657 gen_snap(compiler_state_t *cstate, bpf_u_int32 orgcode, bpf_u_int32 ptype) in gen_snap() argument
3669 return gen_bcmp(cstate, OR_LLC, 0, 8, snapblock); in gen_snap()
3676 gen_llc_internal(compiler_state_t *cstate) in gen_llc_internal() argument
3680 switch (cstate->linktype) { in gen_llc_internal()
3687 b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU); in gen_llc_internal()
3694 b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, (bpf_int32)0xFFFF); in gen_llc_internal()
3703 b0 = gen_atmtype_llc(cstate); in gen_llc_internal()
3710 return gen_true(cstate); in gen_llc_internal()
3716 return gen_true(cstate); in gen_llc_internal()
3727 return gen_true(cstate); in gen_llc_internal()
3737 b0 = gen_check_802_11_data_frame(cstate); in gen_llc_internal()
3741 bpf_error(cstate, "'llc' not supported for %s", in gen_llc_internal()
3742 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_llc_internal()
3748 gen_llc(compiler_state_t *cstate) in gen_llc() argument
3754 if (setjmp(cstate->top_ctx)) in gen_llc()
3757 return gen_llc_internal(cstate); in gen_llc()
3761 gen_llc_i(compiler_state_t *cstate) in gen_llc_i() argument
3770 if (setjmp(cstate->top_ctx)) in gen_llc_i()
3776 b0 = gen_llc_internal(cstate); in gen_llc_i()
3782 s = gen_load_a(cstate, OR_LLC, 2, BPF_B); in gen_llc_i()
3783 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_llc_i()
3792 gen_llc_s(compiler_state_t *cstate) in gen_llc_s() argument
3800 if (setjmp(cstate->top_ctx)) in gen_llc_s()
3806 b0 = gen_llc_internal(cstate); in gen_llc_s()
3812 b1 = gen_mcmp(cstate, OR_LLC, 2, BPF_B, LLC_S_FMT, 0x03); in gen_llc_s()
3818 gen_llc_u(compiler_state_t *cstate) in gen_llc_u() argument
3826 if (setjmp(cstate->top_ctx)) in gen_llc_u()
3832 b0 = gen_llc_internal(cstate); in gen_llc_u()
3838 b1 = gen_mcmp(cstate, OR_LLC, 2, BPF_B, LLC_U_FMT, 0x03); in gen_llc_u()
3844 gen_llc_s_subtype(compiler_state_t *cstate, bpf_u_int32 subtype) in gen_llc_s_subtype() argument
3852 if (setjmp(cstate->top_ctx)) in gen_llc_s_subtype()
3858 b0 = gen_llc_internal(cstate); in gen_llc_s_subtype()
3863 b1 = gen_mcmp(cstate, OR_LLC, 2, BPF_B, subtype, LLC_S_CMD_MASK); in gen_llc_s_subtype()
3869 gen_llc_u_subtype(compiler_state_t *cstate, bpf_u_int32 subtype) in gen_llc_u_subtype() argument
3877 if (setjmp(cstate->top_ctx)) in gen_llc_u_subtype()
3883 b0 = gen_llc_internal(cstate); in gen_llc_u_subtype()
3888 b1 = gen_mcmp(cstate, OR_LLC, 2, BPF_B, subtype, LLC_U_CMD_MASK); in gen_llc_u_subtype()
3906 gen_llc_linktype(compiler_state_t *cstate, int proto) in gen_llc_linktype() argument
3921 return gen_cmp(cstate, OR_LLC, 0, BPF_H, (bpf_u_int32) in gen_llc_linktype()
3929 return gen_cmp(cstate, OR_LLC, 0, BPF_B, in gen_llc_linktype()
3942 return gen_snap(cstate, 0x080007, ETHERTYPE_ATALK); in gen_llc_linktype()
3954 return gen_cmp(cstate, OR_LLC, 0, BPF_B, (bpf_int32)proto); in gen_llc_linktype()
3975 return gen_cmp(cstate, OR_LLC, 6, BPF_H, (bpf_int32)proto); in gen_llc_linktype()
3981 gen_hostop(compiler_state_t *cstate, bpf_u_int32 addr, bpf_u_int32 mask, in gen_hostop() argument
3998 b0 = gen_hostop(cstate, addr, mask, Q_SRC, proto, src_off, dst_off); in gen_hostop()
3999 b1 = gen_hostop(cstate, addr, mask, Q_DST, proto, src_off, dst_off); in gen_hostop()
4005 b0 = gen_hostop(cstate, addr, mask, Q_SRC, proto, src_off, dst_off); in gen_hostop()
4006 b1 = gen_hostop(cstate, addr, mask, Q_DST, proto, src_off, dst_off); in gen_hostop()
4011 …bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for addresses other than 802.11… in gen_hostop()
4015 …bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for addresses other than 802.11… in gen_hostop()
4019 …bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for addresses other than 802.11… in gen_hostop()
4023 …bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for addresses other than 802.11… in gen_hostop()
4027 bpf_error(cstate, "'ra' is not a valid qualifier for addresses other than 802.11 MAC addresses"); in gen_hostop()
4031 bpf_error(cstate, "'ta' is not a valid qualifier for addresses other than 802.11 MAC addresses"); in gen_hostop()
4038 b0 = gen_linktype(cstate, proto); in gen_hostop()
4039 b1 = gen_mcmp(cstate, OR_LINKPL, offset, BPF_W, (bpf_int32)addr, mask); in gen_hostop()
4046 gen_hostop6(compiler_state_t *cstate, struct in6_addr *addr, in gen_hostop6() argument
4064 b0 = gen_hostop6(cstate, addr, mask, Q_SRC, proto, src_off, dst_off); in gen_hostop6()
4065 b1 = gen_hostop6(cstate, addr, mask, Q_DST, proto, src_off, dst_off); in gen_hostop6()
4071 b0 = gen_hostop6(cstate, addr, mask, Q_SRC, proto, src_off, dst_off); in gen_hostop6()
4072 b1 = gen_hostop6(cstate, addr, mask, Q_DST, proto, src_off, dst_off); in gen_hostop6()
4077 …bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for addresses other than 802.11… in gen_hostop6()
4081 …bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for addresses other than 802.11… in gen_hostop6()
4085 …bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for addresses other than 802.11… in gen_hostop6()
4089 …bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for addresses other than 802.11… in gen_hostop6()
4093 bpf_error(cstate, "'ra' is not a valid qualifier for addresses other than 802.11 MAC addresses"); in gen_hostop6()
4097 bpf_error(cstate, "'ta' is not a valid qualifier for addresses other than 802.11 MAC addresses"); in gen_hostop6()
4107 b1 = gen_mcmp(cstate, OR_LINKPL, offset + 12, BPF_W, ntohl(a[3]), ntohl(m[3])); in gen_hostop6()
4108 b0 = gen_mcmp(cstate, OR_LINKPL, offset + 8, BPF_W, ntohl(a[2]), ntohl(m[2])); in gen_hostop6()
4110 b0 = gen_mcmp(cstate, OR_LINKPL, offset + 4, BPF_W, ntohl(a[1]), ntohl(m[1])); in gen_hostop6()
4112 b0 = gen_mcmp(cstate, OR_LINKPL, offset + 0, BPF_W, ntohl(a[0]), ntohl(m[0])); in gen_hostop6()
4114 b0 = gen_linktype(cstate, proto); in gen_hostop6()
4121 gen_ehostop(compiler_state_t *cstate, const u_char *eaddr, int dir) in gen_ehostop() argument
4127 return gen_bcmp(cstate, OR_LINKHDR, 6, 6, eaddr); in gen_ehostop()
4130 return gen_bcmp(cstate, OR_LINKHDR, 0, 6, eaddr); in gen_ehostop()
4133 b0 = gen_ehostop(cstate, eaddr, Q_SRC); in gen_ehostop()
4134 b1 = gen_ehostop(cstate, eaddr, Q_DST); in gen_ehostop()
4140 b0 = gen_ehostop(cstate, eaddr, Q_SRC); in gen_ehostop()
4141 b1 = gen_ehostop(cstate, eaddr, Q_DST); in gen_ehostop()
4146 bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11 with 802.11 headers"); in gen_ehostop()
4150 bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11 with 802.11 headers"); in gen_ehostop()
4154 bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11 with 802.11 headers"); in gen_ehostop()
4158 bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11 with 802.11 headers"); in gen_ehostop()
4162 bpf_error(cstate, "'ra' is only supported on 802.11 with 802.11 headers"); in gen_ehostop()
4166 bpf_error(cstate, "'ta' is only supported on 802.11 with 802.11 headers"); in gen_ehostop()
4177 gen_fhostop(compiler_state_t *cstate, const u_char *eaddr, int dir) in gen_fhostop() argument
4183 return gen_bcmp(cstate, OR_LINKHDR, 6 + 1 + cstate->pcap_fddipad, 6, eaddr); in gen_fhostop()
4186 return gen_bcmp(cstate, OR_LINKHDR, 0 + 1 + cstate->pcap_fddipad, 6, eaddr); in gen_fhostop()
4189 b0 = gen_fhostop(cstate, eaddr, Q_SRC); in gen_fhostop()
4190 b1 = gen_fhostop(cstate, eaddr, Q_DST); in gen_fhostop()
4196 b0 = gen_fhostop(cstate, eaddr, Q_SRC); in gen_fhostop()
4197 b1 = gen_fhostop(cstate, eaddr, Q_DST); in gen_fhostop()
4202 bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11"); in gen_fhostop()
4206 bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11"); in gen_fhostop()
4210 bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11"); in gen_fhostop()
4214 bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11"); in gen_fhostop()
4218 bpf_error(cstate, "'ra' is only supported on 802.11"); in gen_fhostop()
4222 bpf_error(cstate, "'ta' is only supported on 802.11"); in gen_fhostop()
4233 gen_thostop(compiler_state_t *cstate, const u_char *eaddr, int dir) in gen_thostop() argument
4239 return gen_bcmp(cstate, OR_LINKHDR, 8, 6, eaddr); in gen_thostop()
4242 return gen_bcmp(cstate, OR_LINKHDR, 2, 6, eaddr); in gen_thostop()
4245 b0 = gen_thostop(cstate, eaddr, Q_SRC); in gen_thostop()
4246 b1 = gen_thostop(cstate, eaddr, Q_DST); in gen_thostop()
4252 b0 = gen_thostop(cstate, eaddr, Q_SRC); in gen_thostop()
4253 b1 = gen_thostop(cstate, eaddr, Q_DST); in gen_thostop()
4258 bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11"); in gen_thostop()
4262 bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11"); in gen_thostop()
4266 bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11"); in gen_thostop()
4270 bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11"); in gen_thostop()
4274 bpf_error(cstate, "'ra' is only supported on 802.11"); in gen_thostop()
4278 bpf_error(cstate, "'ta' is only supported on 802.11"); in gen_thostop()
4290 gen_wlanhostop(compiler_state_t *cstate, const u_char *eaddr, int dir) in gen_wlanhostop() argument
4302 cstate->no_optimize = 1; in gen_wlanhostop()
4332 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_wlanhostop()
4333 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4340 b0 = gen_bcmp(cstate, OR_LINKHDR, 24, 6, eaddr); in gen_wlanhostop()
4347 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_wlanhostop()
4348 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4356 b1 = gen_bcmp(cstate, OR_LINKHDR, 16, 6, eaddr); in gen_wlanhostop()
4370 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_wlanhostop()
4371 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4379 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_wlanhostop()
4380 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4388 b1 = gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr); in gen_wlanhostop()
4402 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4403 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4417 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4418 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4426 b1 = gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr); in gen_wlanhostop()
4444 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4445 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4479 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_wlanhostop()
4480 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4487 b0 = gen_bcmp(cstate, OR_LINKHDR, 16, 6, eaddr); in gen_wlanhostop()
4494 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_wlanhostop()
4495 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4503 b1 = gen_bcmp(cstate, OR_LINKHDR, 4, 6, eaddr); in gen_wlanhostop()
4516 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4517 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4531 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4532 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4540 b1 = gen_bcmp(cstate, OR_LINKHDR, 4, 6, eaddr); in gen_wlanhostop()
4558 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4559 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4572 b0 = gen_wlanhostop(cstate, eaddr, Q_SRC); in gen_wlanhostop()
4573 b1 = gen_wlanhostop(cstate, eaddr, Q_DST); in gen_wlanhostop()
4579 b0 = gen_wlanhostop(cstate, eaddr, Q_SRC); in gen_wlanhostop()
4580 b1 = gen_wlanhostop(cstate, eaddr, Q_DST); in gen_wlanhostop()
4588 return (gen_bcmp(cstate, OR_LINKHDR, 4, 6, eaddr)); in gen_wlanhostop()
4594 b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_TYPE_CTL, in gen_wlanhostop()
4597 b1 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_SUBTYPE_CTS, in gen_wlanhostop()
4600 b2 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_SUBTYPE_ACK, in gen_wlanhostop()
4605 b1 = gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr); in gen_wlanhostop()
4613 b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_TYPE_CTL, in gen_wlanhostop()
4616 b1 = gen_bcmp(cstate, OR_LINKHDR, 16, 6, eaddr); in gen_wlanhostop()
4627 b0 = gen_mcmp(cstate, OR_LINKHDR, 1, BPF_B, in gen_wlanhostop()
4629 b1 = gen_bcmp(cstate, OR_LINKHDR, 24, 6, eaddr); in gen_wlanhostop()
4644 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4645 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4652 b0 = gen_bcmp(cstate, OR_LINKHDR, 4, 6, eaddr); in gen_wlanhostop()
4669 b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_TYPE_CTL, in gen_wlanhostop()
4672 b1 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_SUBTYPE_CTS, in gen_wlanhostop()
4675 b2 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_SUBTYPE_ACK, in gen_wlanhostop()
4686 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4687 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4700 b1 = gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr); in gen_wlanhostop()
4714 gen_ipfchostop(compiler_state_t *cstate, const u_char *eaddr, int dir) in gen_ipfchostop() argument
4720 return gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr); in gen_ipfchostop()
4723 return gen_bcmp(cstate, OR_LINKHDR, 2, 6, eaddr); in gen_ipfchostop()
4726 b0 = gen_ipfchostop(cstate, eaddr, Q_SRC); in gen_ipfchostop()
4727 b1 = gen_ipfchostop(cstate, eaddr, Q_DST); in gen_ipfchostop()
4733 b0 = gen_ipfchostop(cstate, eaddr, Q_SRC); in gen_ipfchostop()
4734 b1 = gen_ipfchostop(cstate, eaddr, Q_DST); in gen_ipfchostop()
4739 bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11"); in gen_ipfchostop()
4743 bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11"); in gen_ipfchostop()
4747 bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11"); in gen_ipfchostop()
4751 bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11"); in gen_ipfchostop()
4755 bpf_error(cstate, "'ra' is only supported on 802.11"); in gen_ipfchostop()
4759 bpf_error(cstate, "'ta' is only supported on 802.11"); in gen_ipfchostop()
4785 gen_dnhostop(compiler_state_t *cstate, bpf_u_int32 addr, int dir) in gen_dnhostop() argument
4805 b0 = gen_dnhostop(cstate, addr, Q_SRC); in gen_dnhostop()
4806 b1 = gen_dnhostop(cstate, addr, Q_DST); in gen_dnhostop()
4813 b0 = gen_dnhostop(cstate, addr, Q_SRC); in gen_dnhostop()
4814 b1 = gen_dnhostop(cstate, addr, Q_DST); in gen_dnhostop()
4819 …bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for addresses other than 802.11… in gen_dnhostop()
4823 …bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for addresses other than 802.11… in gen_dnhostop()
4827 …bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for addresses other than 802.11… in gen_dnhostop()
4831 …bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for addresses other than 802.11… in gen_dnhostop()
4835 bpf_error(cstate, "'ra' is not a valid qualifier for addresses other than 802.11 MAC addresses"); in gen_dnhostop()
4839 bpf_error(cstate, "'ta' is not a valid qualifier for addresses other than 802.11 MAC addresses"); in gen_dnhostop()
4846 b0 = gen_linktype(cstate, ETHERTYPE_DN); in gen_dnhostop()
4848 tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_H, in gen_dnhostop()
4850 b1 = gen_cmp(cstate, OR_LINKPL, 2 + 1 + offset_lh, in gen_dnhostop()
4854 tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_B, (bpf_int32)0x06, (bpf_int32)0x7); in gen_dnhostop()
4855 b2 = gen_cmp(cstate, OR_LINKPL, 2 + offset_lh, BPF_H, (bpf_int32)ntohs((u_short)addr)); in gen_dnhostop()
4859 tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_H, in gen_dnhostop()
4861 b2 = gen_cmp(cstate, OR_LINKPL, 2 + 1 + offset_sh, BPF_H, (bpf_int32)ntohs((u_short)addr)); in gen_dnhostop()
4865 tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_B, (bpf_int32)0x02, (bpf_int32)0x7); in gen_dnhostop()
4866 b2 = gen_cmp(cstate, OR_LINKPL, 2 + offset_sh, BPF_H, (bpf_int32)ntohs((u_short)addr)); in gen_dnhostop()
4881 gen_mpls_linktype(compiler_state_t *cstate, int proto) in gen_mpls_linktype() argument
4889 b0 = gen_mcmp(cstate, OR_LINKPL, (u_int)-2, BPF_B, 0x01, 0x01); in gen_mpls_linktype()
4891 b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_B, 0x40, 0xf0); in gen_mpls_linktype()
4897 b0 = gen_mcmp(cstate, OR_LINKPL, (u_int)-2, BPF_B, 0x01, 0x01); in gen_mpls_linktype()
4899 b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_B, 0x60, 0xf0); in gen_mpls_linktype()
4909 gen_host(compiler_state_t *cstate, bpf_u_int32 addr, bpf_u_int32 mask, in gen_host() argument
4923 b0 = gen_host(cstate, addr, mask, Q_IP, dir, type); in gen_host()
4928 if (cstate->label_stack_depth == 0) { in gen_host()
4929 b1 = gen_host(cstate, addr, mask, Q_ARP, dir, type); in gen_host()
4931 b0 = gen_host(cstate, addr, mask, Q_RARP, dir, type); in gen_host()
4937 bpf_error(cstate, "link-layer modifier applied to %s", typestr); in gen_host()
4940 return gen_hostop(cstate, addr, mask, dir, ETHERTYPE_IP, 12, 16); in gen_host()
4943 return gen_hostop(cstate, addr, mask, dir, ETHERTYPE_REVARP, 14, 24); in gen_host()
4946 return gen_hostop(cstate, addr, mask, dir, ETHERTYPE_ARP, 14, 24); in gen_host()
4949 bpf_error(cstate, "'sctp' modifier applied to %s", typestr); in gen_host()
4952 bpf_error(cstate, "'tcp' modifier applied to %s", typestr); in gen_host()
4955 bpf_error(cstate, "'udp' modifier applied to %s", typestr); in gen_host()
4958 bpf_error(cstate, "'icmp' modifier applied to %s", typestr); in gen_host()
4961 bpf_error(cstate, "'igmp' modifier applied to %s", typestr); in gen_host()
4964 bpf_error(cstate, "'igrp' modifier applied to %s", typestr); in gen_host()
4967 bpf_error(cstate, "AppleTalk host filtering not implemented"); in gen_host()
4970 return gen_dnhostop(cstate, addr, dir); in gen_host()
4973 bpf_error(cstate, "LAT host filtering not implemented"); in gen_host()
4976 bpf_error(cstate, "SCA host filtering not implemented"); in gen_host()
4979 bpf_error(cstate, "MOPRC host filtering not implemented"); in gen_host()
4982 bpf_error(cstate, "MOPDL host filtering not implemented"); in gen_host()
4985 bpf_error(cstate, "'ip6' modifier applied to ip host"); in gen_host()
4988 bpf_error(cstate, "'icmp6' modifier applied to %s", typestr); in gen_host()
4991 bpf_error(cstate, "'ah' modifier applied to %s", typestr); in gen_host()
4994 bpf_error(cstate, "'esp' modifier applied to %s", typestr); in gen_host()
4997 bpf_error(cstate, "'pim' modifier applied to %s", typestr); in gen_host()
5000 bpf_error(cstate, "'vrrp' modifier applied to %s", typestr); in gen_host()
5003 bpf_error(cstate, "AARP host filtering not implemented"); in gen_host()
5006 bpf_error(cstate, "ISO host filtering not implemented"); in gen_host()
5009 bpf_error(cstate, "'esis' modifier applied to %s", typestr); in gen_host()
5012 bpf_error(cstate, "'isis' modifier applied to %s", typestr); in gen_host()
5015 bpf_error(cstate, "'clnp' modifier applied to %s", typestr); in gen_host()
5018 bpf_error(cstate, "'stp' modifier applied to %s", typestr); in gen_host()
5021 bpf_error(cstate, "IPX host filtering not implemented"); in gen_host()
5024 bpf_error(cstate, "'netbeui' modifier applied to %s", typestr); in gen_host()
5027 bpf_error(cstate, "'l1' modifier applied to %s", typestr); in gen_host()
5030 bpf_error(cstate, "'l2' modifier applied to %s", typestr); in gen_host()
5033 bpf_error(cstate, "'iih' modifier applied to %s", typestr); in gen_host()
5036 bpf_error(cstate, "'snp' modifier applied to %s", typestr); in gen_host()
5039 bpf_error(cstate, "'csnp' modifier applied to %s", typestr); in gen_host()
5042 bpf_error(cstate, "'psnp' modifier applied to %s", typestr); in gen_host()
5045 bpf_error(cstate, "'lsp' modifier applied to %s", typestr); in gen_host()
5048 bpf_error(cstate, "'radio' modifier applied to %s", typestr); in gen_host()
5051 bpf_error(cstate, "'carp' modifier applied to %s", typestr); in gen_host()
5061 gen_host6(compiler_state_t *cstate, struct in6_addr *addr, in gen_host6() argument
5074 return gen_host6(cstate, addr, mask, Q_IPV6, dir, type); in gen_host6()
5077 bpf_error(cstate, "link-layer modifier applied to ip6 %s", typestr); in gen_host6()
5080 bpf_error(cstate, "'ip' modifier applied to ip6 %s", typestr); in gen_host6()
5083 bpf_error(cstate, "'rarp' modifier applied to ip6 %s", typestr); in gen_host6()
5086 bpf_error(cstate, "'arp' modifier applied to ip6 %s", typestr); in gen_host6()
5089 bpf_error(cstate, "'sctp' modifier applied to ip6 %s", typestr); in gen_host6()
5092 bpf_error(cstate, "'tcp' modifier applied to ip6 %s", typestr); in gen_host6()
5095 bpf_error(cstate, "'udp' modifier applied to ip6 %s", typestr); in gen_host6()
5098 bpf_error(cstate, "'icmp' modifier applied to ip6 %s", typestr); in gen_host6()
5101 bpf_error(cstate, "'igmp' modifier applied to ip6 %s", typestr); in gen_host6()
5104 bpf_error(cstate, "'igrp' modifier applied to ip6 %s", typestr); in gen_host6()
5107 bpf_error(cstate, "AppleTalk modifier applied to ip6 %s", typestr); in gen_host6()
5110 bpf_error(cstate, "'decnet' modifier applied to ip6 %s", typestr); in gen_host6()
5113 bpf_error(cstate, "'lat' modifier applied to ip6 %s", typestr); in gen_host6()
5116 bpf_error(cstate, "'sca' modifier applied to ip6 %s", typestr); in gen_host6()
5119 bpf_error(cstate, "'moprc' modifier applied to ip6 %s", typestr); in gen_host6()
5122 bpf_error(cstate, "'mopdl' modifier applied to ip6 %s", typestr); in gen_host6()
5125 return gen_hostop6(cstate, addr, mask, dir, ETHERTYPE_IPV6, 8, 24); in gen_host6()
5128 bpf_error(cstate, "'icmp6' modifier applied to ip6 %s", typestr); in gen_host6()
5131 bpf_error(cstate, "'ah' modifier applied to ip6 %s", typestr); in gen_host6()
5134 bpf_error(cstate, "'esp' modifier applied to ip6 %s", typestr); in gen_host6()
5137 bpf_error(cstate, "'pim' modifier applied to ip6 %s", typestr); in gen_host6()
5140 bpf_error(cstate, "'vrrp' modifier applied to ip6 %s", typestr); in gen_host6()
5143 bpf_error(cstate, "'aarp' modifier applied to ip6 %s", typestr); in gen_host6()
5146 bpf_error(cstate, "'iso' modifier applied to ip6 %s", typestr); in gen_host6()
5149 bpf_error(cstate, "'esis' modifier applied to ip6 %s", typestr); in gen_host6()
5152 bpf_error(cstate, "'isis' modifier applied to ip6 %s", typestr); in gen_host6()
5155 bpf_error(cstate, "'clnp' modifier applied to ip6 %s", typestr); in gen_host6()
5158 bpf_error(cstate, "'stp' modifier applied to ip6 %s", typestr); in gen_host6()
5161 bpf_error(cstate, "'ipx' modifier applied to ip6 %s", typestr); in gen_host6()
5164 bpf_error(cstate, "'netbeui' modifier applied to ip6 %s", typestr); in gen_host6()
5167 bpf_error(cstate, "'l1' modifier applied to ip6 %s", typestr); in gen_host6()
5170 bpf_error(cstate, "'l2' modifier applied to ip6 %s", typestr); in gen_host6()
5173 bpf_error(cstate, "'iih' modifier applied to ip6 %s", typestr); in gen_host6()
5176 bpf_error(cstate, "'snp' modifier applied to ip6 %s", typestr); in gen_host6()
5179 bpf_error(cstate, "'csnp' modifier applied to ip6 %s", typestr); in gen_host6()
5182 bpf_error(cstate, "'psnp' modifier applied to ip6 %s", typestr); in gen_host6()
5185 bpf_error(cstate, "'lsp' modifier applied to ip6 %s", typestr); in gen_host6()
5188 bpf_error(cstate, "'radio' modifier applied to ip6 %s", typestr); in gen_host6()
5191 bpf_error(cstate, "'carp' modifier applied to ip6 %s", typestr); in gen_host6()
5202 gen_gateway(compiler_state_t *cstate, const u_char *eaddr, in gen_gateway() argument
5210 bpf_error(cstate, "direction applied to 'gateway'"); in gen_gateway()
5217 switch (cstate->linktype) { in gen_gateway()
5221 b1 = gen_prevlinkhdr_check(cstate); in gen_gateway()
5222 b0 = gen_ehostop(cstate, eaddr, Q_OR); in gen_gateway()
5227 b0 = gen_fhostop(cstate, eaddr, Q_OR); in gen_gateway()
5230 b0 = gen_thostop(cstate, eaddr, Q_OR); in gen_gateway()
5237 b0 = gen_wlanhostop(cstate, eaddr, Q_OR); in gen_gateway()
5245 bpf_error(cstate, in gen_gateway()
5249 b0 = gen_ipfchostop(cstate, eaddr, Q_OR); in gen_gateway()
5252 bpf_error(cstate, in gen_gateway()
5269 tmp = gen_host(cstate, in gen_gateway()
5302 bpf_error(cstate, "illegal modifier of 'gateway'"); in gen_gateway()
5308 gen_proto_abbrev_internal(compiler_state_t *cstate, int proto) in gen_proto_abbrev_internal() argument
5316 b1 = gen_proto(cstate, IPPROTO_SCTP, Q_IP, Q_DEFAULT); in gen_proto_abbrev_internal()
5317 b0 = gen_proto(cstate, IPPROTO_SCTP, Q_IPV6, Q_DEFAULT); in gen_proto_abbrev_internal()
5322 b1 = gen_proto(cstate, IPPROTO_TCP, Q_IP, Q_DEFAULT); in gen_proto_abbrev_internal()
5323 b0 = gen_proto(cstate, IPPROTO_TCP, Q_IPV6, Q_DEFAULT); in gen_proto_abbrev_internal()
5328 b1 = gen_proto(cstate, IPPROTO_UDP, Q_IP, Q_DEFAULT); in gen_proto_abbrev_internal()
5329 b0 = gen_proto(cstate, IPPROTO_UDP, Q_IPV6, Q_DEFAULT); in gen_proto_abbrev_internal()
5334 b1 = gen_proto(cstate, IPPROTO_ICMP, Q_IP, Q_DEFAULT); in gen_proto_abbrev_internal()
5342 b1 = gen_proto(cstate, IPPROTO_IGMP, Q_IP, Q_DEFAULT); in gen_proto_abbrev_internal()
5349 b1 = gen_proto(cstate, IPPROTO_IGRP, Q_IP, Q_DEFAULT); in gen_proto_abbrev_internal()
5357 b1 = gen_proto(cstate, IPPROTO_PIM, Q_IP, Q_DEFAULT); in gen_proto_abbrev_internal()
5358 b0 = gen_proto(cstate, IPPROTO_PIM, Q_IPV6, Q_DEFAULT); in gen_proto_abbrev_internal()
5367 b1 = gen_proto(cstate, IPPROTO_VRRP, Q_IP, Q_DEFAULT); in gen_proto_abbrev_internal()
5375 b1 = gen_proto(cstate, IPPROTO_CARP, Q_IP, Q_DEFAULT); in gen_proto_abbrev_internal()
5379 b1 = gen_linktype(cstate, ETHERTYPE_IP); in gen_proto_abbrev_internal()
5383 b1 = gen_linktype(cstate, ETHERTYPE_ARP); in gen_proto_abbrev_internal()
5387 b1 = gen_linktype(cstate, ETHERTYPE_REVARP); in gen_proto_abbrev_internal()
5391 bpf_error(cstate, "link layer applied in wrong context"); in gen_proto_abbrev_internal()
5394 b1 = gen_linktype(cstate, ETHERTYPE_ATALK); in gen_proto_abbrev_internal()
5398 b1 = gen_linktype(cstate, ETHERTYPE_AARP); in gen_proto_abbrev_internal()
5402 b1 = gen_linktype(cstate, ETHERTYPE_DN); in gen_proto_abbrev_internal()
5406 b1 = gen_linktype(cstate, ETHERTYPE_SCA); in gen_proto_abbrev_internal()
5410 b1 = gen_linktype(cstate, ETHERTYPE_LAT); in gen_proto_abbrev_internal()
5414 b1 = gen_linktype(cstate, ETHERTYPE_MOPDL); in gen_proto_abbrev_internal()
5418 b1 = gen_linktype(cstate, ETHERTYPE_MOPRC); in gen_proto_abbrev_internal()
5422 b1 = gen_linktype(cstate, ETHERTYPE_IPV6); in gen_proto_abbrev_internal()
5429 b1 = gen_proto(cstate, IPPROTO_ICMPV6, Q_IPV6, Q_DEFAULT); in gen_proto_abbrev_internal()
5436 b1 = gen_proto(cstate, IPPROTO_AH, Q_IP, Q_DEFAULT); in gen_proto_abbrev_internal()
5437 b0 = gen_proto(cstate, IPPROTO_AH, Q_IPV6, Q_DEFAULT); in gen_proto_abbrev_internal()
5445 b1 = gen_proto(cstate, IPPROTO_ESP, Q_IP, Q_DEFAULT); in gen_proto_abbrev_internal()
5446 b0 = gen_proto(cstate, IPPROTO_ESP, Q_IPV6, Q_DEFAULT); in gen_proto_abbrev_internal()
5451 b1 = gen_linktype(cstate, LLCSAP_ISONS); in gen_proto_abbrev_internal()
5455 b1 = gen_proto(cstate, ISO9542_ESIS, Q_ISO, Q_DEFAULT); in gen_proto_abbrev_internal()
5459 b1 = gen_proto(cstate, ISO10589_ISIS, Q_ISO, Q_DEFAULT); in gen_proto_abbrev_internal()
5463 b0 = gen_proto(cstate, ISIS_L1_LAN_IIH, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5464 b1 = gen_proto(cstate, ISIS_PTP_IIH, Q_ISIS, Q_DEFAULT); /* FIXME extract the circuit-type bits */ in gen_proto_abbrev_internal()
5466 b0 = gen_proto(cstate, ISIS_L1_LSP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5468 b0 = gen_proto(cstate, ISIS_L1_CSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5470 b0 = gen_proto(cstate, ISIS_L1_PSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5475 b0 = gen_proto(cstate, ISIS_L2_LAN_IIH, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5476 b1 = gen_proto(cstate, ISIS_PTP_IIH, Q_ISIS, Q_DEFAULT); /* FIXME extract the circuit-type bits */ in gen_proto_abbrev_internal()
5478 b0 = gen_proto(cstate, ISIS_L2_LSP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5480 b0 = gen_proto(cstate, ISIS_L2_CSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5482 b0 = gen_proto(cstate, ISIS_L2_PSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5487 b0 = gen_proto(cstate, ISIS_L1_LAN_IIH, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5488 b1 = gen_proto(cstate, ISIS_L2_LAN_IIH, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5490 b0 = gen_proto(cstate, ISIS_PTP_IIH, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5495 b0 = gen_proto(cstate, ISIS_L1_LSP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5496 b1 = gen_proto(cstate, ISIS_L2_LSP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5501 b0 = gen_proto(cstate, ISIS_L1_CSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5502 b1 = gen_proto(cstate, ISIS_L2_CSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5504 b0 = gen_proto(cstate, ISIS_L1_PSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5506 b0 = gen_proto(cstate, ISIS_L2_PSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5511 b0 = gen_proto(cstate, ISIS_L1_CSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5512 b1 = gen_proto(cstate, ISIS_L2_CSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5517 b0 = gen_proto(cstate, ISIS_L1_PSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5518 b1 = gen_proto(cstate, ISIS_L2_PSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5523 b1 = gen_proto(cstate, ISO8473_CLNP, Q_ISO, Q_DEFAULT); in gen_proto_abbrev_internal()
5527 b1 = gen_linktype(cstate, LLCSAP_8021D); in gen_proto_abbrev_internal()
5531 b1 = gen_linktype(cstate, LLCSAP_IPX); in gen_proto_abbrev_internal()
5535 b1 = gen_linktype(cstate, LLCSAP_NETBEUI); in gen_proto_abbrev_internal()
5539 bpf_error(cstate, "'radio' is not a valid protocol type"); in gen_proto_abbrev_internal()
5548 gen_proto_abbrev(compiler_state_t *cstate, int proto) in gen_proto_abbrev() argument
5554 if (setjmp(cstate->top_ctx)) in gen_proto_abbrev()
5557 return gen_proto_abbrev_internal(cstate, proto); in gen_proto_abbrev()
5561 gen_ipfrag(compiler_state_t *cstate) in gen_ipfrag() argument
5567 s = gen_load_a(cstate, OR_LINKPL, 6, BPF_H); in gen_ipfrag()
5568 b = new_block(cstate, JMP(BPF_JSET)); in gen_ipfrag()
5586 gen_portatom(compiler_state_t *cstate, int off, bpf_int32 v) in gen_portatom() argument
5588 return gen_cmp(cstate, OR_TRAN_IPV4, off, BPF_H, v); in gen_portatom()
5592 gen_portatom6(compiler_state_t *cstate, int off, bpf_int32 v) in gen_portatom6() argument
5594 return gen_cmp(cstate, OR_TRAN_IPV6, off, BPF_H, v); in gen_portatom6()
5598 gen_portop(compiler_state_t *cstate, int port, int proto, int dir) in gen_portop() argument
5603 tmp = gen_cmp(cstate, OR_LINKPL, 9, BPF_B, (bpf_int32)proto); in gen_portop()
5604 b0 = gen_ipfrag(cstate); in gen_portop()
5609 b1 = gen_portatom(cstate, 0, (bpf_int32)port); in gen_portop()
5613 b1 = gen_portatom(cstate, 2, (bpf_int32)port); in gen_portop()
5617 tmp = gen_portatom(cstate, 0, (bpf_int32)port); in gen_portop()
5618 b1 = gen_portatom(cstate, 2, (bpf_int32)port); in gen_portop()
5624 tmp = gen_portatom(cstate, 0, (bpf_int32)port); in gen_portop()
5625 b1 = gen_portatom(cstate, 2, (bpf_int32)port); in gen_portop()
5630 bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for ports"); in gen_portop()
5634 bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for ports"); in gen_portop()
5638 bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for ports"); in gen_portop()
5642 bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for ports"); in gen_portop()
5646 bpf_error(cstate, "'ra' is not a valid qualifier for ports"); in gen_portop()
5650 bpf_error(cstate, "'ta' is not a valid qualifier for ports"); in gen_portop()
5663 gen_port(compiler_state_t *cstate, int port, int ip_proto, int dir) in gen_port() argument
5684 b0 = gen_linktype(cstate, ETHERTYPE_IP); in gen_port()
5690 b1 = gen_portop(cstate, port, ip_proto, dir); in gen_port()
5694 tmp = gen_portop(cstate, port, IPPROTO_TCP, dir); in gen_port()
5695 b1 = gen_portop(cstate, port, IPPROTO_UDP, dir); in gen_port()
5697 tmp = gen_portop(cstate, port, IPPROTO_SCTP, dir); in gen_port()
5709 gen_portop6(compiler_state_t *cstate, int port, int proto, int dir) in gen_portop6() argument
5715 b0 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, (bpf_int32)proto); in gen_portop6()
5719 b1 = gen_portatom6(cstate, 0, (bpf_int32)port); in gen_portop6()
5723 b1 = gen_portatom6(cstate, 2, (bpf_int32)port); in gen_portop6()
5727 tmp = gen_portatom6(cstate, 0, (bpf_int32)port); in gen_portop6()
5728 b1 = gen_portatom6(cstate, 2, (bpf_int32)port); in gen_portop6()
5734 tmp = gen_portatom6(cstate, 0, (bpf_int32)port); in gen_portop6()
5735 b1 = gen_portatom6(cstate, 2, (bpf_int32)port); in gen_portop6()
5748 gen_port6(compiler_state_t *cstate, int port, int ip_proto, int dir) in gen_port6() argument
5753 b0 = gen_linktype(cstate, ETHERTYPE_IPV6); in gen_port6()
5759 b1 = gen_portop6(cstate, port, ip_proto, dir); in gen_port6()
5763 tmp = gen_portop6(cstate, port, IPPROTO_TCP, dir); in gen_port6()
5764 b1 = gen_portop6(cstate, port, IPPROTO_UDP, dir); in gen_port6()
5766 tmp = gen_portop6(cstate, port, IPPROTO_SCTP, dir); in gen_port6()
5779 gen_portrangeatom(compiler_state_t *cstate, int off, bpf_int32 v1, in gen_portrangeatom() argument
5795 b1 = gen_cmp_ge(cstate, OR_TRAN_IPV4, off, BPF_H, v1); in gen_portrangeatom()
5796 b2 = gen_cmp_le(cstate, OR_TRAN_IPV4, off, BPF_H, v2); in gen_portrangeatom()
5804 gen_portrangeop(compiler_state_t *cstate, int port1, int port2, int proto, in gen_portrangeop() argument
5810 tmp = gen_cmp(cstate, OR_LINKPL, 9, BPF_B, (bpf_int32)proto); in gen_portrangeop()
5811 b0 = gen_ipfrag(cstate); in gen_portrangeop()
5816 b1 = gen_portrangeatom(cstate, 0, (bpf_int32)port1, (bpf_int32)port2); in gen_portrangeop()
5820 b1 = gen_portrangeatom(cstate, 2, (bpf_int32)port1, (bpf_int32)port2); in gen_portrangeop()
5824 tmp = gen_portrangeatom(cstate, 0, (bpf_int32)port1, (bpf_int32)port2); in gen_portrangeop()
5825 b1 = gen_portrangeatom(cstate, 2, (bpf_int32)port1, (bpf_int32)port2); in gen_portrangeop()
5831 tmp = gen_portrangeatom(cstate, 0, (bpf_int32)port1, (bpf_int32)port2); in gen_portrangeop()
5832 b1 = gen_portrangeatom(cstate, 2, (bpf_int32)port1, (bpf_int32)port2); in gen_portrangeop()
5837 bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for port ranges"); in gen_portrangeop()
5841 bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for port ranges"); in gen_portrangeop()
5845 bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for port ranges"); in gen_portrangeop()
5849 bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for port ranges"); in gen_portrangeop()
5853 bpf_error(cstate, "'ra' is not a valid qualifier for port ranges"); in gen_portrangeop()
5857 bpf_error(cstate, "'ta' is not a valid qualifier for port ranges"); in gen_portrangeop()
5870 gen_portrange(compiler_state_t *cstate, int port1, int port2, int ip_proto, in gen_portrange() argument
5876 b0 = gen_linktype(cstate, ETHERTYPE_IP); in gen_portrange()
5882 b1 = gen_portrangeop(cstate, port1, port2, ip_proto, dir); in gen_portrange()
5886 tmp = gen_portrangeop(cstate, port1, port2, IPPROTO_TCP, dir); in gen_portrange()
5887 b1 = gen_portrangeop(cstate, port1, port2, IPPROTO_UDP, dir); in gen_portrange()
5889 tmp = gen_portrangeop(cstate, port1, port2, IPPROTO_SCTP, dir); in gen_portrange()
5901 gen_portrangeatom6(compiler_state_t *cstate, int off, bpf_int32 v1, in gen_portrangeatom6() argument
5917 b1 = gen_cmp_ge(cstate, OR_TRAN_IPV6, off, BPF_H, v1); in gen_portrangeatom6()
5918 b2 = gen_cmp_le(cstate, OR_TRAN_IPV6, off, BPF_H, v2); in gen_portrangeatom6()
5926 gen_portrangeop6(compiler_state_t *cstate, int port1, int port2, int proto, in gen_portrangeop6() argument
5933 b0 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, (bpf_int32)proto); in gen_portrangeop6()
5937 b1 = gen_portrangeatom6(cstate, 0, (bpf_int32)port1, (bpf_int32)port2); in gen_portrangeop6()
5941 b1 = gen_portrangeatom6(cstate, 2, (bpf_int32)port1, (bpf_int32)port2); in gen_portrangeop6()
5945 tmp = gen_portrangeatom6(cstate, 0, (bpf_int32)port1, (bpf_int32)port2); in gen_portrangeop6()
5946 b1 = gen_portrangeatom6(cstate, 2, (bpf_int32)port1, (bpf_int32)port2); in gen_portrangeop6()
5952 tmp = gen_portrangeatom6(cstate, 0, (bpf_int32)port1, (bpf_int32)port2); in gen_portrangeop6()
5953 b1 = gen_portrangeatom6(cstate, 2, (bpf_int32)port1, (bpf_int32)port2); in gen_portrangeop6()
5966 gen_portrange6(compiler_state_t *cstate, int port1, int port2, int ip_proto, in gen_portrange6() argument
5972 b0 = gen_linktype(cstate, ETHERTYPE_IPV6); in gen_portrange6()
5978 b1 = gen_portrangeop6(cstate, port1, port2, ip_proto, dir); in gen_portrange6()
5982 tmp = gen_portrangeop6(cstate, port1, port2, IPPROTO_TCP, dir); in gen_portrange6()
5983 b1 = gen_portrangeop6(cstate, port1, port2, IPPROTO_UDP, dir); in gen_portrange6()
5985 tmp = gen_portrangeop6(cstate, port1, port2, IPPROTO_SCTP, dir); in gen_portrange6()
5997 lookup_proto(compiler_state_t *cstate, const char *name, int proto) in lookup_proto() argument
6008 bpf_error(cstate, "unknown ip proto '%s'", name); in lookup_proto()
6017 bpf_error(cstate, "unknown ether proto '%s'", name); in lookup_proto()
6029 bpf_error(cstate, "unknown osi proto '%s'", name); in lookup_proto()
6048 gen_protochain(compiler_state_t *cstate, int v, int proto, int dir) in gen_protochain() argument
6051 return gen_proto(cstate, v, proto, dir); in gen_protochain()
6058 int reg2 = alloc_reg(cstate); in gen_protochain()
6068 b0 = gen_protochain(cstate, v, Q_IP, dir); in gen_protochain()
6069 b = gen_protochain(cstate, v, Q_IPV6, dir); in gen_protochain()
6073 bpf_error(cstate, "bad protocol applied for 'protochain'"); in gen_protochain()
6088 if (cstate->off_linkpl.is_variable) in gen_protochain()
6089 bpf_error(cstate, "'protochain' not supported with variable length headers"); in gen_protochain()
6091 cstate->no_optimize = 1; /* this code is not compatible with optimizer yet */ in gen_protochain()
6099 s[i] = new_stmt(cstate, 0); /*dummy*/ in gen_protochain()
6104 b0 = gen_linktype(cstate, ETHERTYPE_IP); in gen_protochain()
6107 s[i] = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_B); in gen_protochain()
6108 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 9; in gen_protochain()
6111 s[i] = new_stmt(cstate, BPF_LDX|BPF_MSH|BPF_B); in gen_protochain()
6112 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_protochain()
6117 b0 = gen_linktype(cstate, ETHERTYPE_IPV6); in gen_protochain()
6120 s[i] = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_B); in gen_protochain()
6121 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 6; in gen_protochain()
6124 s[i] = new_stmt(cstate, BPF_LDX|BPF_IMM); in gen_protochain()
6130 bpf_error(cstate, "unsupported proto to gen_protochain"); in gen_protochain()
6136 s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
6147 s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
6160 s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
6167 s[i - 1]->s.jf = s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
6173 s[i - 1]->s.jf = s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
6179 s[i - 1]->s.jf = s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
6196 s[i] = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_protochain()
6197 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_protochain()
6200 s[i] = new_stmt(cstate, BPF_ST); in gen_protochain()
6204 s[i] = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_protochain()
6205 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 1; in gen_protochain()
6208 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_protochain()
6212 s[i] = new_stmt(cstate, BPF_ALU|BPF_MUL|BPF_K); in gen_protochain()
6216 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X); in gen_protochain()
6220 s[i] = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_protochain()
6223 s[i] = new_stmt(cstate, BPF_LD|BPF_MEM); in gen_protochain()
6228 s[i] = new_stmt(cstate, BPF_JMP|BPF_JA); in gen_protochain()
6238 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_protochain()
6247 s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
6262 s[i - 1]->s.jt = s[i] = new_stmt(cstate, BPF_MISC|BPF_TXA); in gen_protochain()
6265 s[i] = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_protochain()
6266 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_protochain()
6269 s[i] = new_stmt(cstate, BPF_ST); in gen_protochain()
6273 s[i - 1]->s.jt = s[i] = new_stmt(cstate, BPF_MISC|BPF_TXA); in gen_protochain()
6276 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_protochain()
6280 s[i] = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_protochain()
6283 s[i] = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_protochain()
6284 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_protochain()
6287 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_protochain()
6291 s[i] = new_stmt(cstate, BPF_ALU|BPF_MUL|BPF_K); in gen_protochain()
6295 s[i] = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_protochain()
6298 s[i] = new_stmt(cstate, BPF_LD|BPF_MEM); in gen_protochain()
6303 s[i] = new_stmt(cstate, BPF_JMP|BPF_JA); in gen_protochain()
6309 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_protochain()
6327 b = new_block(cstate, JMP(BPF_JEQ)); in gen_protochain()
6331 free_reg(cstate, reg2); in gen_protochain()
6339 gen_check_802_11_data_frame(compiler_state_t *cstate) in gen_check_802_11_data_frame() argument
6348 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_check_802_11_data_frame()
6349 b0 = new_block(cstate, JMP(BPF_JSET)); in gen_check_802_11_data_frame()
6353 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_check_802_11_data_frame()
6354 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_check_802_11_data_frame()
6374 gen_proto(compiler_state_t *cstate, int v, int proto, int dir) in gen_proto() argument
6382 bpf_error(cstate, "direction applied to 'proto'"); in gen_proto()
6386 b0 = gen_proto(cstate, v, Q_IP, dir); in gen_proto()
6387 b1 = gen_proto(cstate, v, Q_IPV6, dir); in gen_proto()
6392 return gen_linktype(cstate, v); in gen_proto()
6410 b0 = gen_linktype(cstate, ETHERTYPE_IP); in gen_proto()
6412 b1 = gen_cmp(cstate, OR_LINKPL, 9, BPF_B, (bpf_int32)v); in gen_proto()
6414 b1 = gen_protochain(cstate, v, Q_IP); in gen_proto()
6420 bpf_error(cstate, "arp does not encapsulate another protocol"); in gen_proto()
6424 bpf_error(cstate, "rarp does not encapsulate another protocol"); in gen_proto()
6428 bpf_error(cstate, "'sctp proto' is bogus"); in gen_proto()
6432 bpf_error(cstate, "'tcp proto' is bogus"); in gen_proto()
6436 bpf_error(cstate, "'udp proto' is bogus"); in gen_proto()
6440 bpf_error(cstate, "'icmp proto' is bogus"); in gen_proto()
6444 bpf_error(cstate, "'igmp proto' is bogus"); in gen_proto()
6448 bpf_error(cstate, "'igrp proto' is bogus"); in gen_proto()
6452 bpf_error(cstate, "AppleTalk encapsulation is not specifiable"); in gen_proto()
6456 bpf_error(cstate, "DECNET encapsulation is not specifiable"); in gen_proto()
6460 bpf_error(cstate, "LAT does not encapsulate another protocol"); in gen_proto()
6464 bpf_error(cstate, "SCA does not encapsulate another protocol"); in gen_proto()
6468 bpf_error(cstate, "MOPRC does not encapsulate another protocol"); in gen_proto()
6472 bpf_error(cstate, "MOPDL does not encapsulate another protocol"); in gen_proto()
6476 b0 = gen_linktype(cstate, ETHERTYPE_IPV6); in gen_proto()
6482 b2 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, IPPROTO_FRAGMENT); in gen_proto()
6483 b1 = gen_cmp(cstate, OR_LINKPL, 40, BPF_B, (bpf_int32)v); in gen_proto()
6485 b2 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, (bpf_int32)v); in gen_proto()
6488 b1 = gen_protochain(cstate, v, Q_IPV6); in gen_proto()
6494 bpf_error(cstate, "'icmp6 proto' is bogus"); in gen_proto()
6498 bpf_error(cstate, "'ah proto' is bogus"); in gen_proto()
6502 bpf_error(cstate, "'ah proto' is bogus"); in gen_proto()
6506 bpf_error(cstate, "'pim proto' is bogus"); in gen_proto()
6510 bpf_error(cstate, "'vrrp proto' is bogus"); in gen_proto()
6514 bpf_error(cstate, "'aarp proto' is bogus"); in gen_proto()
6518 switch (cstate->linktype) { in gen_proto()
6539 return gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | v); in gen_proto()
6547 b0 = gen_linktype(cstate, LLCSAP_ISONS<<8 | LLCSAP_ISONS); in gen_proto()
6549 b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 1, BPF_B, (long)v); in gen_proto()
6554 b0 = gen_linktype(cstate, LLCSAP_ISONS); in gen_proto()
6555 b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 0, BPF_B, (long)v); in gen_proto()
6561 bpf_error(cstate, "'esis proto' is bogus"); in gen_proto()
6565 b0 = gen_proto(cstate, ISO10589_ISIS, Q_ISO, Q_DEFAULT); in gen_proto()
6570 b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 4, BPF_B, (long)v); in gen_proto()
6575 bpf_error(cstate, "'clnp proto' is not supported"); in gen_proto()
6579 bpf_error(cstate, "'stp proto' is bogus"); in gen_proto()
6583 bpf_error(cstate, "'ipx proto' is bogus"); in gen_proto()
6587 bpf_error(cstate, "'netbeui proto' is bogus"); in gen_proto()
6591 bpf_error(cstate, "'l1 proto' is bogus"); in gen_proto()
6595 bpf_error(cstate, "'l2 proto' is bogus"); in gen_proto()
6599 bpf_error(cstate, "'iih proto' is bogus"); in gen_proto()
6603 bpf_error(cstate, "'snp proto' is bogus"); in gen_proto()
6607 bpf_error(cstate, "'csnp proto' is bogus"); in gen_proto()
6611 bpf_error(cstate, "'psnp proto' is bogus"); in gen_proto()
6615 bpf_error(cstate, "'lsp proto' is bogus"); in gen_proto()
6619 bpf_error(cstate, "'radio proto' is bogus"); in gen_proto()
6623 bpf_error(cstate, "'carp proto' is bogus"); in gen_proto()
6634 gen_scode(compiler_state_t *cstate, const char *name, struct qual q) in gen_scode() argument
6656 if (setjmp(cstate->top_ctx)) in gen_scode()
6664 bpf_error(cstate, "unknown network '%s'", name); in gen_scode()
6671 return gen_host(cstate, addr, mask, proto, dir, q.addr); in gen_scode()
6676 switch (cstate->linktype) { in gen_scode()
6683 bpf_error(cstate, in gen_scode()
6685 tmp = gen_prevlinkhdr_check(cstate); in gen_scode()
6686 b = gen_ehostop(cstate, eaddr, dir); in gen_scode()
6695 bpf_error(cstate, in gen_scode()
6697 b = gen_fhostop(cstate, eaddr, dir); in gen_scode()
6704 bpf_error(cstate, in gen_scode()
6706 b = gen_thostop(cstate, eaddr, dir); in gen_scode()
6717 bpf_error(cstate, in gen_scode()
6719 b = gen_wlanhostop(cstate, eaddr, dir); in gen_scode()
6726 bpf_error(cstate, in gen_scode()
6728 b = gen_ipfchostop(cstate, eaddr, dir); in gen_scode()
6733 …bpf_error(cstate, "only ethernet/FDDI/token ring/802.11/ATM LANE/Fibre Channel supports link-level… in gen_scode()
6739 bpf_error(cstate, "unknown decnet host name '%s'\n", name); in gen_scode()
6741 bpf_error(cstate, "decnet name support not included, '%s' cannot be translated\n", in gen_scode()
6749 return (gen_host(cstate, dn_addr, 0, proto, dir, q.addr)); in gen_scode()
6756 bpf_error(cstate, "unknown host '%s'", name); in gen_scode()
6757 cstate->ai = res; in gen_scode()
6763 if (cstate->off_linktype.constant_part == OFFSET_NOT_SET && in gen_scode()
6780 tmp = gen_host(cstate, ntohl(sin4->sin_addr.s_addr), in gen_scode()
6790 tmp = gen_host6(cstate, &sin6->sin6_addr, in gen_scode()
6801 cstate->ai = NULL; in gen_scode()
6804 bpf_error(cstate, "unknown host '%s'%s", name, in gen_scode()
6815 bpf_error(cstate, "illegal qualifier of 'port'"); in gen_scode()
6817 bpf_error(cstate, "unknown port '%s'", name); in gen_scode()
6820 bpf_error(cstate, "port '%s' is tcp", name); in gen_scode()
6822 bpf_error(cstate, "port '%s' is sctp", name); in gen_scode()
6829 bpf_error(cstate, "port '%s' is udp", name); in gen_scode()
6832 bpf_error(cstate, "port '%s' is sctp", name); in gen_scode()
6839 bpf_error(cstate, "port '%s' is udp", name); in gen_scode()
6842 bpf_error(cstate, "port '%s' is tcp", name); in gen_scode()
6848 bpf_error(cstate, "illegal port number %d < 0", port); in gen_scode()
6850 bpf_error(cstate, "illegal port number %d > 65535", port); in gen_scode()
6851 b = gen_port(cstate, port, real_proto, dir); in gen_scode()
6852 gen_or(gen_port6(cstate, port, real_proto, dir), b); in gen_scode()
6858 bpf_error(cstate, "illegal qualifier of 'portrange'"); in gen_scode()
6860 bpf_error(cstate, "unknown port in range '%s'", name); in gen_scode()
6863 bpf_error(cstate, "port in range '%s' is tcp", name); in gen_scode()
6865 bpf_error(cstate, "port in range '%s' is sctp", name); in gen_scode()
6872 bpf_error(cstate, "port in range '%s' is udp", name); in gen_scode()
6874 bpf_error(cstate, "port in range '%s' is sctp", name); in gen_scode()
6881 bpf_error(cstate, "port in range '%s' is udp", name); in gen_scode()
6883 bpf_error(cstate, "port in range '%s' is tcp", name); in gen_scode()
6889 bpf_error(cstate, "illegal port number %d < 0", port1); in gen_scode()
6891 bpf_error(cstate, "illegal port number %d > 65535", port1); in gen_scode()
6893 bpf_error(cstate, "illegal port number %d < 0", port2); in gen_scode()
6895 bpf_error(cstate, "illegal port number %d > 65535", port2); in gen_scode()
6897 b = gen_portrange(cstate, port1, port2, real_proto, dir); in gen_scode()
6898 gen_or(gen_portrange6(cstate, port1, port2, real_proto, dir), b); in gen_scode()
6905 bpf_error(cstate, "unknown ether host: %s", name); in gen_scode()
6908 cstate->ai = res; in gen_scode()
6910 bpf_error(cstate, "unknown host '%s'", name); in gen_scode()
6911 b = gen_gateway(cstate, eaddr, res, proto, dir); in gen_scode()
6912 cstate->ai = NULL; in gen_scode()
6915 bpf_error(cstate, "unknown host '%s'", name); in gen_scode()
6918 bpf_error(cstate, "'gateway' not supported in this configuration"); in gen_scode()
6922 real_proto = lookup_proto(cstate, name, proto); in gen_scode()
6924 return gen_proto(cstate, real_proto, proto, dir); in gen_scode()
6926 bpf_error(cstate, "unknown protocol: %s", name); in gen_scode()
6929 real_proto = lookup_proto(cstate, name, proto); in gen_scode()
6931 return gen_protochain(cstate, real_proto, proto, dir); in gen_scode()
6933 bpf_error(cstate, "unknown protocol: %s", name); in gen_scode()
6936 syntax(cstate); in gen_scode()
6944 gen_mcode(compiler_state_t *cstate, const char *s1, const char *s2, in gen_mcode() argument
6954 if (setjmp(cstate->top_ctx)) in gen_mcode()
6959 bpf_error(cstate, "invalid IPv4 address '%s'", s1); in gen_mcode()
6966 bpf_error(cstate, "invalid IPv4 address '%s'", s2); in gen_mcode()
6970 bpf_error(cstate, "non-network bits set in \"%s mask %s\"", in gen_mcode()
6975 bpf_error(cstate, "mask length must be <= 32"); in gen_mcode()
6985 bpf_error(cstate, "non-network bits set in \"%s/%d\"", in gen_mcode()
6992 return gen_host(cstate, n, m, q.proto, q.dir, q.addr); in gen_mcode()
6995 bpf_error(cstate, "Mask syntax for networks only"); in gen_mcode()
7002 gen_ncode(compiler_state_t *cstate, const char *s, bpf_u_int32 v, struct qual q) in gen_ncode() argument
7013 if (setjmp(cstate->top_ctx)) in gen_ncode()
7023 bpf_error(cstate, "malformed decnet address '%s'", s); in gen_ncode()
7027 bpf_error(cstate, "invalid IPv4 address '%s'", s); in gen_ncode()
7036 return gen_host(cstate, v, 0, proto, dir, q.addr); in gen_ncode()
7038 bpf_error(cstate, "illegal link layer address"); in gen_ncode()
7052 return gen_host(cstate, v, mask, proto, dir, q.addr); in gen_ncode()
7065 bpf_error(cstate, "illegal qualifier of 'port'"); in gen_ncode()
7068 bpf_error(cstate, "illegal port number %u > 65535", v); in gen_ncode()
7072 b = gen_port(cstate, (int)v, proto, dir); in gen_ncode()
7073 gen_or(gen_port6(cstate, (int)v, proto, dir), b); in gen_ncode()
7087 bpf_error(cstate, "illegal qualifier of 'portrange'"); in gen_ncode()
7090 bpf_error(cstate, "illegal port number %u > 65535", v); in gen_ncode()
7094 b = gen_portrange(cstate, (int)v, (int)v, proto, dir); in gen_ncode()
7095 gen_or(gen_portrange6(cstate, (int)v, (int)v, proto, dir), b); in gen_ncode()
7100 bpf_error(cstate, "'gateway' requires a name"); in gen_ncode()
7104 return gen_proto(cstate, (int)v, proto, dir); in gen_ncode()
7107 return gen_protochain(cstate, (int)v, proto, dir); in gen_ncode()
7110 syntax(cstate); in gen_ncode()
7122 gen_mcode6(compiler_state_t *cstate, const char *s1, const char *s2, in gen_mcode6() argument
7135 if (setjmp(cstate->top_ctx)) in gen_mcode6()
7139 bpf_error(cstate, "no mask %s supported", s2); in gen_mcode6()
7143 bpf_error(cstate, "invalid ip6 address %s", s1); in gen_mcode6()
7144 cstate->ai = res; in gen_mcode6()
7146 bpf_error(cstate, "%s resolved to multiple address", s1); in gen_mcode6()
7150 bpf_error(cstate, "mask length must be <= %u", (unsigned int)(sizeof(mask) * 8)); in gen_mcode6()
7162 bpf_error(cstate, "non-network bits set in \"%s/%d\"", s1, masklen); in gen_mcode6()
7170 bpf_error(cstate, "Mask syntax for networks only"); in gen_mcode6()
7174 b = gen_host6(cstate, addr, &mask, q.proto, q.dir, q.addr); in gen_mcode6()
7175 cstate->ai = NULL; in gen_mcode6()
7180 bpf_error(cstate, "invalid qualifier against IPv6 address"); in gen_mcode6()
7187 gen_ecode(compiler_state_t *cstate, const char *s, struct qual q) in gen_ecode() argument
7195 if (setjmp(cstate->top_ctx)) in gen_ecode()
7199 cstate->e = pcap_ether_aton(s); in gen_ecode()
7200 if (cstate->e == NULL) in gen_ecode()
7201 bpf_error(cstate, "malloc"); in gen_ecode()
7202 switch (cstate->linktype) { in gen_ecode()
7206 tmp = gen_prevlinkhdr_check(cstate); in gen_ecode()
7207 b = gen_ehostop(cstate, cstate->e, (int)q.dir); in gen_ecode()
7212 b = gen_fhostop(cstate, cstate->e, (int)q.dir); in gen_ecode()
7215 b = gen_thostop(cstate, cstate->e, (int)q.dir); in gen_ecode()
7222 b = gen_wlanhostop(cstate, cstate->e, (int)q.dir); in gen_ecode()
7225 b = gen_ipfchostop(cstate, cstate->e, (int)q.dir); in gen_ecode()
7228 free(cstate->e); in gen_ecode()
7229 cstate->e = NULL; in gen_ecode()
7230 …bpf_error(cstate, "ethernet addresses supported only on ethernet/FDDI/token ring/802.11/ATM LANE/F… in gen_ecode()
7233 free(cstate->e); in gen_ecode()
7234 cstate->e = NULL; in gen_ecode()
7237 bpf_error(cstate, "ethernet address used in non-ether expression"); in gen_ecode()
7254 xfer_to_x(compiler_state_t *cstate, struct arth *a) in xfer_to_x() argument
7258 s = new_stmt(cstate, BPF_LDX|BPF_MEM); in xfer_to_x()
7264 xfer_to_a(compiler_state_t *cstate, struct arth *a) in xfer_to_a() argument
7268 s = new_stmt(cstate, BPF_LD|BPF_MEM); in xfer_to_a()
7281 gen_load_internal(compiler_state_t *cstate, int proto, struct arth *inst, int size) in gen_load_internal() argument
7285 int regno = alloc_reg(cstate); in gen_load_internal()
7287 free_reg(cstate, inst->regno); in gen_load_internal()
7291 bpf_error(cstate, "data size must be 1, 2, or 4"); in gen_load_internal()
7307 bpf_error(cstate, "unsupported index operation"); in gen_load_internal()
7315 if (cstate->linktype != DLT_IEEE802_11_RADIO_AVS && in gen_load_internal()
7316 cstate->linktype != DLT_IEEE802_11_RADIO && in gen_load_internal()
7317 cstate->linktype != DLT_PRISM_HEADER) in gen_load_internal()
7318 bpf_error(cstate, "radio information not present in capture"); in gen_load_internal()
7324 s = xfer_to_x(cstate, inst); in gen_load_internal()
7329 tmp = new_stmt(cstate, BPF_LD|BPF_IND|size); in gen_load_internal()
7346 s = gen_abs_offset_varpart(cstate, &cstate->off_linkhdr); in gen_load_internal()
7358 sappend(s, xfer_to_a(cstate, inst)); in gen_load_internal()
7359 sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X)); in gen_load_internal()
7360 sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX)); in gen_load_internal()
7362 s = xfer_to_x(cstate, inst); in gen_load_internal()
7371 tmp = new_stmt(cstate, BPF_LD|BPF_IND|size); in gen_load_internal()
7372 tmp->s.k = cstate->off_linkhdr.constant_part; in gen_load_internal()
7393 s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl); in gen_load_internal()
7405 sappend(s, xfer_to_a(cstate, inst)); in gen_load_internal()
7406 sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X)); in gen_load_internal()
7407 sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX)); in gen_load_internal()
7409 s = xfer_to_x(cstate, inst); in gen_load_internal()
7418 tmp = new_stmt(cstate, BPF_LD|BPF_IND|size); in gen_load_internal()
7419 tmp->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_load_internal()
7427 b = gen_proto_abbrev_internal(cstate, proto); in gen_load_internal()
7456 s = gen_loadx_iphdrlen(cstate); in gen_load_internal()
7472 sappend(s, xfer_to_a(cstate, inst)); in gen_load_internal()
7473 sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X)); in gen_load_internal()
7474 sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX)); in gen_load_internal()
7475 sappend(s, tmp = new_stmt(cstate, BPF_LD|BPF_IND|size)); in gen_load_internal()
7476 tmp->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_load_internal()
7485 gen_and(gen_proto_abbrev_internal(cstate, proto), b = gen_ipfrag(cstate)); in gen_load_internal()
7488 gen_and(gen_proto_abbrev_internal(cstate, Q_IP), b); in gen_load_internal()
7496 b = gen_proto_abbrev_internal(cstate, Q_IPV6); in gen_load_internal()
7505 b = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, 58); in gen_load_internal()
7512 s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl); in gen_load_internal()
7523 sappend(s, xfer_to_a(cstate, inst)); in gen_load_internal()
7524 sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X)); in gen_load_internal()
7525 sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX)); in gen_load_internal()
7527 s = xfer_to_x(cstate, inst); in gen_load_internal()
7537 tmp = new_stmt(cstate, BPF_LD|BPF_IND|size); in gen_load_internal()
7538 tmp->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 40; in gen_load_internal()
7546 s = new_stmt(cstate, BPF_ST); in gen_load_internal()
7554 gen_load(compiler_state_t *cstate, int proto, struct arth *inst, int size) in gen_load() argument
7560 if (setjmp(cstate->top_ctx)) in gen_load()
7563 return gen_load_internal(cstate, proto, inst, size); in gen_load()
7567 gen_relation_internal(compiler_state_t *cstate, int code, struct arth *a0, in gen_relation_internal() argument
7573 s0 = xfer_to_x(cstate, a1); in gen_relation_internal()
7574 s1 = xfer_to_a(cstate, a0); in gen_relation_internal()
7576 s2 = new_stmt(cstate, BPF_ALU|BPF_SUB|BPF_X); in gen_relation_internal()
7577 b = new_block(cstate, JMP(code)); in gen_relation_internal()
7581 b = new_block(cstate, BPF_JMP|code|BPF_X); in gen_relation_internal()
7591 free_reg(cstate, a0->regno); in gen_relation_internal()
7592 free_reg(cstate, a1->regno); in gen_relation_internal()
7611 gen_relation(compiler_state_t *cstate, int code, struct arth *a0, in gen_relation() argument
7618 if (setjmp(cstate->top_ctx)) in gen_relation()
7621 return gen_relation_internal(cstate, code, a0, a1, reversed); in gen_relation()
7625 gen_loadlen(compiler_state_t *cstate) in gen_loadlen() argument
7635 if (setjmp(cstate->top_ctx)) in gen_loadlen()
7638 regno = alloc_reg(cstate); in gen_loadlen()
7639 a = (struct arth *)newchunk(cstate, sizeof(*a)); in gen_loadlen()
7640 s = new_stmt(cstate, BPF_LD|BPF_LEN); in gen_loadlen()
7641 s->next = new_stmt(cstate, BPF_ST); in gen_loadlen()
7650 gen_loadi_internal(compiler_state_t *cstate, int val) in gen_loadi_internal() argument
7656 a = (struct arth *)newchunk(cstate, sizeof(*a)); in gen_loadi_internal()
7658 reg = alloc_reg(cstate); in gen_loadi_internal()
7660 s = new_stmt(cstate, BPF_LD|BPF_IMM); in gen_loadi_internal()
7662 s->next = new_stmt(cstate, BPF_ST); in gen_loadi_internal()
7671 gen_loadi(compiler_state_t *cstate, int val) in gen_loadi() argument
7677 if (setjmp(cstate->top_ctx)) in gen_loadi()
7680 return gen_loadi_internal(cstate, val); in gen_loadi()
7689 gen_neg(compiler_state_t *cstate, struct arth *a_arg) in gen_neg() argument
7698 if (setjmp(cstate->top_ctx)) in gen_neg()
7701 s = xfer_to_a(cstate, a); in gen_neg()
7703 s = new_stmt(cstate, BPF_ALU|BPF_NEG); in gen_neg()
7706 s = new_stmt(cstate, BPF_ST); in gen_neg()
7719 gen_arth(compiler_state_t *cstate, int code, struct arth *a0_arg, in gen_arth() argument
7729 if (setjmp(cstate->top_ctx)) in gen_arth()
7741 bpf_error(cstate, "division by zero"); in gen_arth()
7744 bpf_error(cstate, "modulus by zero"); in gen_arth()
7753 bpf_error(cstate, "shift by more than 31 bits"); in gen_arth()
7755 s0 = xfer_to_x(cstate, a1); in gen_arth()
7756 s1 = xfer_to_a(cstate, a0); in gen_arth()
7757 s2 = new_stmt(cstate, BPF_ALU|BPF_X|code); in gen_arth()
7764 free_reg(cstate, a0->regno); in gen_arth()
7765 free_reg(cstate, a1->regno); in gen_arth()
7767 s0 = new_stmt(cstate, BPF_ST); in gen_arth()
7768 a0->regno = s0->s.k = alloc_reg(cstate); in gen_arth()
7778 init_regs(compiler_state_t *cstate) in init_regs() argument
7780 cstate->curreg = 0; in init_regs()
7781 memset(cstate->regused, 0, sizeof cstate->regused); in init_regs()
7788 alloc_reg(compiler_state_t *cstate) in alloc_reg() argument
7793 if (cstate->regused[cstate->curreg]) in alloc_reg()
7794 cstate->curreg = (cstate->curreg + 1) % BPF_MEMWORDS; in alloc_reg()
7796 cstate->regused[cstate->curreg] = 1; in alloc_reg()
7797 return cstate->curreg; in alloc_reg()
7800 bpf_error(cstate, "too many registers needed to evaluate expression"); in alloc_reg()
7809 free_reg(compiler_state_t *cstate, int n) in free_reg() argument
7811 cstate->regused[n] = 0; in free_reg()
7815 gen_len(compiler_state_t *cstate, int jmp, int n) in gen_len() argument
7820 s = new_stmt(cstate, BPF_LD|BPF_LEN); in gen_len()
7821 b = new_block(cstate, JMP(jmp)); in gen_len()
7829 gen_greater(compiler_state_t *cstate, int n) in gen_greater() argument
7835 if (setjmp(cstate->top_ctx)) in gen_greater()
7838 return gen_len(cstate, BPF_JGE, n); in gen_greater()
7845 gen_less(compiler_state_t *cstate, int n) in gen_less() argument
7853 if (setjmp(cstate->top_ctx)) in gen_less()
7856 b = gen_len(cstate, BPF_JGT, n); in gen_less()
7873 gen_byteop(compiler_state_t *cstate, int op, int idx, int val) in gen_byteop() argument
7882 if (setjmp(cstate->top_ctx)) in gen_byteop()
7890 return gen_cmp(cstate, OR_LINKHDR, (u_int)idx, BPF_B, (bpf_int32)val); in gen_byteop()
7893 b = gen_cmp_lt(cstate, OR_LINKHDR, (u_int)idx, BPF_B, (bpf_int32)val); in gen_byteop()
7897 b = gen_cmp_gt(cstate, OR_LINKHDR, (u_int)idx, BPF_B, (bpf_int32)val); in gen_byteop()
7901 s = new_stmt(cstate, BPF_ALU|BPF_OR|BPF_K); in gen_byteop()
7905 s = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K); in gen_byteop()
7909 b = new_block(cstate, JMP(BPF_JEQ)); in gen_byteop()
7919 gen_broadcast(compiler_state_t *cstate, int proto) in gen_broadcast() argument
7929 if (setjmp(cstate->top_ctx)) in gen_broadcast()
7936 switch (cstate->linktype) { in gen_broadcast()
7939 return gen_ahostop(cstate, abroadcast, Q_DST); in gen_broadcast()
7943 b1 = gen_prevlinkhdr_check(cstate); in gen_broadcast()
7944 b0 = gen_ehostop(cstate, ebroadcast, Q_DST); in gen_broadcast()
7949 return gen_fhostop(cstate, ebroadcast, Q_DST); in gen_broadcast()
7951 return gen_thostop(cstate, ebroadcast, Q_DST); in gen_broadcast()
7957 return gen_wlanhostop(cstate, ebroadcast, Q_DST); in gen_broadcast()
7959 return gen_ipfchostop(cstate, ebroadcast, Q_DST); in gen_broadcast()
7961 bpf_error(cstate, "not a broadcast link"); in gen_broadcast()
7971 if (cstate->netmask == PCAP_NETMASK_UNKNOWN) in gen_broadcast()
7972 bpf_error(cstate, "netmask not known, so 'ip broadcast' not supported"); in gen_broadcast()
7973 b0 = gen_linktype(cstate, ETHERTYPE_IP); in gen_broadcast()
7974 hostmask = ~cstate->netmask; in gen_broadcast()
7975 b1 = gen_mcmp(cstate, OR_LINKPL, 16, BPF_W, (bpf_int32)0, hostmask); in gen_broadcast()
7976 b2 = gen_mcmp(cstate, OR_LINKPL, 16, BPF_W, in gen_broadcast()
7982 bpf_error(cstate, "only link-layer/IP broadcast filters supported"); in gen_broadcast()
7991 gen_mac_multicast(compiler_state_t *cstate, int offset) in gen_mac_multicast() argument
7997 s = gen_load_a(cstate, OR_LINKHDR, offset, BPF_B); in gen_mac_multicast()
7998 b0 = new_block(cstate, JMP(BPF_JSET)); in gen_mac_multicast()
8005 gen_multicast(compiler_state_t *cstate, int proto) in gen_multicast() argument
8014 if (setjmp(cstate->top_ctx)) in gen_multicast()
8021 switch (cstate->linktype) { in gen_multicast()
8025 return gen_ahostop(cstate, abroadcast, Q_DST); in gen_multicast()
8029 b1 = gen_prevlinkhdr_check(cstate); in gen_multicast()
8031 b0 = gen_mac_multicast(cstate, 0); in gen_multicast()
8042 return gen_mac_multicast(cstate, 1); in gen_multicast()
8045 return gen_mac_multicast(cstate, 2); in gen_multicast()
8072 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_multicast()
8073 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_multicast()
8080 b0 = gen_mac_multicast(cstate, 16); in gen_multicast()
8087 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_multicast()
8088 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_multicast()
8096 b1 = gen_mac_multicast(cstate, 4); in gen_multicast()
8109 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_multicast()
8110 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_multicast()
8124 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_multicast()
8125 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_multicast()
8133 b1 = gen_mac_multicast(cstate, 4); in gen_multicast()
8151 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_multicast()
8152 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_multicast()
8164 b0 = gen_mac_multicast(cstate, 2); in gen_multicast()
8173 b0 = gen_linktype(cstate, ETHERTYPE_IP); in gen_multicast()
8174 b1 = gen_cmp_ge(cstate, OR_LINKPL, 16, BPF_B, (bpf_int32)224); in gen_multicast()
8179 b0 = gen_linktype(cstate, ETHERTYPE_IPV6); in gen_multicast()
8180 b1 = gen_cmp(cstate, OR_LINKPL, 24, BPF_B, (bpf_int32)255); in gen_multicast()
8184 …bpf_error(cstate, "link-layer multicast filters supported only on ethernet/FDDI/token ring/ARCNET/… in gen_multicast()
8198 gen_inbound(compiler_state_t *cstate, int dir) in gen_inbound() argument
8206 if (setjmp(cstate->top_ctx)) in gen_inbound()
8212 switch (cstate->linktype) { in gen_inbound()
8214 b0 = gen_relation_internal(cstate, BPF_JEQ, in gen_inbound()
8215 gen_load_internal(cstate, Q_LINK, gen_loadi_internal(cstate, 0), 1), in gen_inbound()
8216 gen_loadi_internal(cstate, 0), in gen_inbound()
8223 b0 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, IPNET_OUTBOUND); in gen_inbound()
8226 b0 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, IPNET_INBOUND); in gen_inbound()
8232 b0 = gen_cmp(cstate, OR_LINKHDR, 0, BPF_H, LINUX_SLL_OUTGOING); in gen_inbound()
8241 b0 = gen_cmp(cstate, OR_LINKHDR, 10, BPF_B, LINUX_SLL_OUTGOING); in gen_inbound()
8250 b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, dir), BPF_B, in gen_inbound()
8258 b0 = gen_cmp(cstate, OR_LINKHDR, 0, BPF_B, PPP_PPPD_OUT); in gen_inbound()
8261 b0 = gen_cmp(cstate, OR_LINKHDR, 0, BPF_B, PPP_PPPD_IN); in gen_inbound()
8292 b0 = gen_mcmp(cstate, OR_LINKHDR, 3, BPF_B, 0, 0x01); in gen_inbound()
8295 b0 = gen_mcmp(cstate, OR_LINKHDR, 3, BPF_B, 1, 0x01); in gen_inbound()
8322 if (cstate->bpf_pcap->rfile != NULL) { in gen_inbound()
8324 bpf_error(cstate, "inbound/outbound not supported on %s when reading savefiles", in gen_inbound()
8325 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_inbound()
8330 b0 = gen_cmp(cstate, OR_LINKHDR, SKF_AD_OFF + SKF_AD_PKTTYPE, BPF_H, in gen_inbound()
8337 bpf_error(cstate, "inbound/outbound not supported on %s", in gen_inbound()
8338 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_inbound()
8348 gen_pf_ifname(compiler_state_t *cstate, const char *ifname) in gen_pf_ifname() argument
8357 if (setjmp(cstate->top_ctx)) in gen_pf_ifname()
8360 if (cstate->linktype != DLT_PFLOG) { in gen_pf_ifname()
8361 bpf_error(cstate, "ifname supported only on PF linktype"); in gen_pf_ifname()
8367 bpf_error(cstate, "ifname interface names can only be %d characters", in gen_pf_ifname()
8371 b0 = gen_bcmp(cstate, OR_LINKHDR, off, (u_int)strlen(ifname), in gen_pf_ifname()
8378 gen_pf_ruleset(compiler_state_t *cstate, char *ruleset) in gen_pf_ruleset() argument
8386 if (setjmp(cstate->top_ctx)) in gen_pf_ruleset()
8389 if (cstate->linktype != DLT_PFLOG) { in gen_pf_ruleset()
8390 bpf_error(cstate, "ruleset supported only on PF linktype"); in gen_pf_ruleset()
8395 bpf_error(cstate, "ruleset names can only be %ld characters", in gen_pf_ruleset()
8400 b0 = gen_bcmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, ruleset), in gen_pf_ruleset()
8407 gen_pf_rnr(compiler_state_t *cstate, int rnr) in gen_pf_rnr() argument
8415 if (setjmp(cstate->top_ctx)) in gen_pf_rnr()
8418 if (cstate->linktype != DLT_PFLOG) { in gen_pf_rnr()
8419 bpf_error(cstate, "rnr supported only on PF linktype"); in gen_pf_rnr()
8423 b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, rulenr), BPF_W, in gen_pf_rnr()
8430 gen_pf_srnr(compiler_state_t *cstate, int srnr) in gen_pf_srnr() argument
8438 if (setjmp(cstate->top_ctx)) in gen_pf_srnr()
8441 if (cstate->linktype != DLT_PFLOG) { in gen_pf_srnr()
8442 bpf_error(cstate, "srnr supported only on PF linktype"); in gen_pf_srnr()
8446 b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, subrulenr), BPF_W, in gen_pf_srnr()
8453 gen_pf_reason(compiler_state_t *cstate, int reason) in gen_pf_reason() argument
8461 if (setjmp(cstate->top_ctx)) in gen_pf_reason()
8464 if (cstate->linktype != DLT_PFLOG) { in gen_pf_reason()
8465 bpf_error(cstate, "reason supported only on PF linktype"); in gen_pf_reason()
8469 b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, reason), BPF_B, in gen_pf_reason()
8476 gen_pf_action(compiler_state_t *cstate, int action) in gen_pf_action() argument
8484 if (setjmp(cstate->top_ctx)) in gen_pf_action()
8487 if (cstate->linktype != DLT_PFLOG) { in gen_pf_action()
8488 bpf_error(cstate, "action supported only on PF linktype"); in gen_pf_action()
8492 b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, action), BPF_B, in gen_pf_action()
8498 gen_pf_ifname(compiler_state_t *cstate, const char *ifname _U_) in gen_pf_ifname() argument
8504 if (setjmp(cstate->top_ctx)) in gen_pf_ifname()
8507 bpf_error(cstate, "libpcap was compiled without pf support"); in gen_pf_ifname()
8512 gen_pf_ruleset(compiler_state_t *cstate, char *ruleset _U_) in gen_pf_ruleset() argument
8518 if (setjmp(cstate->top_ctx)) in gen_pf_ruleset()
8521 bpf_error(cstate, "libpcap was compiled on a machine without pf support"); in gen_pf_ruleset()
8526 gen_pf_rnr(compiler_state_t *cstate, int rnr _U_) in gen_pf_rnr() argument
8532 if (setjmp(cstate->top_ctx)) in gen_pf_rnr()
8535 bpf_error(cstate, "libpcap was compiled on a machine without pf support"); in gen_pf_rnr()
8540 gen_pf_srnr(compiler_state_t *cstate, int srnr _U_) in gen_pf_srnr() argument
8546 if (setjmp(cstate->top_ctx)) in gen_pf_srnr()
8549 bpf_error(cstate, "libpcap was compiled on a machine without pf support"); in gen_pf_srnr()
8554 gen_pf_reason(compiler_state_t *cstate, int reason _U_) in gen_pf_reason() argument
8560 if (setjmp(cstate->top_ctx)) in gen_pf_reason()
8563 bpf_error(cstate, "libpcap was compiled on a machine without pf support"); in gen_pf_reason()
8568 gen_pf_action(compiler_state_t *cstate, int action _U_) in gen_pf_action() argument
8574 if (setjmp(cstate->top_ctx)) in gen_pf_action()
8577 bpf_error(cstate, "libpcap was compiled on a machine without pf support"); in gen_pf_action()
8584 gen_p80211_type(compiler_state_t *cstate, int type, int mask) in gen_p80211_type() argument
8592 if (setjmp(cstate->top_ctx)) in gen_p80211_type()
8595 switch (cstate->linktype) { in gen_p80211_type()
8601 b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, (bpf_int32)type, in gen_p80211_type()
8606 bpf_error(cstate, "802.11 link-layer types supported only on 802.11"); in gen_p80211_type()
8614 gen_p80211_fcdir(compiler_state_t *cstate, int fcdir) in gen_p80211_fcdir() argument
8622 if (setjmp(cstate->top_ctx)) in gen_p80211_fcdir()
8625 switch (cstate->linktype) { in gen_p80211_fcdir()
8634 bpf_error(cstate, "frame direction supported only with 802.11 headers"); in gen_p80211_fcdir()
8638 b0 = gen_mcmp(cstate, OR_LINKHDR, 1, BPF_B, (bpf_int32)fcdir, in gen_p80211_fcdir()
8645 gen_acode(compiler_state_t *cstate, const char *s, struct qual q) in gen_acode() argument
8653 if (setjmp(cstate->top_ctx)) in gen_acode()
8656 switch (cstate->linktype) { in gen_acode()
8662 cstate->e = pcap_ether_aton(s); in gen_acode()
8663 if (cstate->e == NULL) in gen_acode()
8664 bpf_error(cstate, "malloc"); in gen_acode()
8665 b = gen_ahostop(cstate, cstate->e, (int)q.dir); in gen_acode()
8666 free(cstate->e); in gen_acode()
8667 cstate->e = NULL; in gen_acode()
8670 bpf_error(cstate, "ARCnet address used in non-arc expression"); in gen_acode()
8674 bpf_error(cstate, "aid supported only on ARCnet"); in gen_acode()
8680 gen_ahostop(compiler_state_t *cstate, const u_char *eaddr, int dir) in gen_ahostop() argument
8687 return gen_bcmp(cstate, OR_LINKHDR, 0, 1, eaddr); in gen_ahostop()
8690 return gen_bcmp(cstate, OR_LINKHDR, 1, 1, eaddr); in gen_ahostop()
8693 b0 = gen_ahostop(cstate, eaddr, Q_SRC); in gen_ahostop()
8694 b1 = gen_ahostop(cstate, eaddr, Q_DST); in gen_ahostop()
8700 b0 = gen_ahostop(cstate, eaddr, Q_SRC); in gen_ahostop()
8701 b1 = gen_ahostop(cstate, eaddr, Q_DST); in gen_ahostop()
8706 bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11"); in gen_ahostop()
8710 bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11"); in gen_ahostop()
8714 bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11"); in gen_ahostop()
8718 bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11"); in gen_ahostop()
8722 bpf_error(cstate, "'ra' is only supported on 802.11"); in gen_ahostop()
8726 bpf_error(cstate, "'ta' is only supported on 802.11"); in gen_ahostop()
8734 gen_vlan_tpid_test(compiler_state_t *cstate) in gen_vlan_tpid_test() argument
8739 b0 = gen_linktype(cstate, ETHERTYPE_8021Q); in gen_vlan_tpid_test()
8740 b1 = gen_linktype(cstate, ETHERTYPE_8021AD); in gen_vlan_tpid_test()
8743 b1 = gen_linktype(cstate, ETHERTYPE_8021QINQ); in gen_vlan_tpid_test()
8750 gen_vlan_vid_test(compiler_state_t *cstate, bpf_u_int32 vlan_num) in gen_vlan_vid_test() argument
8753 bpf_error(cstate, "VLAN tag %u greater than maximum %u", in gen_vlan_vid_test()
8756 return gen_mcmp(cstate, OR_LINKPL, 0, BPF_H, (bpf_int32)vlan_num, 0x0fff); in gen_vlan_vid_test()
8760 gen_vlan_no_bpf_extensions(compiler_state_t *cstate, bpf_u_int32 vlan_num, in gen_vlan_no_bpf_extensions() argument
8765 b0 = gen_vlan_tpid_test(cstate); in gen_vlan_no_bpf_extensions()
8768 b1 = gen_vlan_vid_test(cstate, vlan_num); in gen_vlan_no_bpf_extensions()
8777 cstate->off_linkpl.constant_part += 4; in gen_vlan_no_bpf_extensions()
8778 cstate->off_linktype.constant_part += 4; in gen_vlan_no_bpf_extensions()
8786 gen_vlan_vloffset_add(compiler_state_t *cstate, bpf_abs_offset *off, int v, struct slist *s) in gen_vlan_vloffset_add() argument
8793 off->reg = alloc_reg(cstate); in gen_vlan_vloffset_add()
8795 s2 = new_stmt(cstate, BPF_LD|BPF_MEM); in gen_vlan_vloffset_add()
8798 s2 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_IMM); in gen_vlan_vloffset_add()
8801 s2 = new_stmt(cstate, BPF_ST); in gen_vlan_vloffset_add()
8811 gen_vlan_patch_tpid_test(compiler_state_t *cstate, struct block *b_tpid) in gen_vlan_patch_tpid_test() argument
8817 cstate->is_vlan_vloffset = 1; in gen_vlan_patch_tpid_test()
8818 gen_vlan_vloffset_add(cstate, &cstate->off_linkpl, 4, &s); in gen_vlan_patch_tpid_test()
8819 gen_vlan_vloffset_add(cstate, &cstate->off_linktype, 4, &s); in gen_vlan_patch_tpid_test()
8831 gen_vlan_patch_vid_test(compiler_state_t *cstate, struct block *b_vid) in gen_vlan_patch_vid_test() argument
8836 s = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_vlan_patch_vid_test()
8840 sjeq = new_stmt(cstate, JMP(BPF_JEQ)); in gen_vlan_patch_vid_test()
8845 s2 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_vlan_patch_vid_test()
8857 s2 = new_stmt(cstate, JMP(BPF_JA)); in gen_vlan_patch_vid_test()
8875 gen_vlan_bpf_extensions(compiler_state_t *cstate, bpf_u_int32 vlan_num, in gen_vlan_bpf_extensions() argument
8883 s = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_vlan_bpf_extensions()
8886 b0 = new_block(cstate, JMP(BPF_JEQ)); in gen_vlan_bpf_extensions()
8900 b_tpid = gen_vlan_tpid_test(cstate); in gen_vlan_bpf_extensions()
8902 b_vid = gen_vlan_vid_test(cstate, vlan_num); in gen_vlan_bpf_extensions()
8904 gen_vlan_patch_tpid_test(cstate, b_tpid); in gen_vlan_bpf_extensions()
8909 gen_vlan_patch_vid_test(cstate, b_vid); in gen_vlan_bpf_extensions()
8922 gen_vlan(compiler_state_t *cstate, bpf_u_int32 vlan_num, int has_vlan_tag) in gen_vlan() argument
8930 if (setjmp(cstate->top_ctx)) in gen_vlan()
8934 if (cstate->label_stack_depth > 0) in gen_vlan()
8935 bpf_error(cstate, "no VLAN match after MPLS"); in gen_vlan()
8968 switch (cstate->linktype) { in gen_vlan()
8976 if (cstate->vlan_stack_depth == 0 && !cstate->off_linkhdr.is_variable && in gen_vlan()
8977 cstate->off_linkhdr.constant_part == in gen_vlan()
8978 cstate->off_outermostlinkhdr.constant_part) { in gen_vlan()
8982 if (cstate->bpf_pcap->bpf_codegen_flags & BPF_SPECIAL_VLAN_HANDLING) in gen_vlan()
8983 b0 = gen_vlan_bpf_extensions(cstate, vlan_num, in gen_vlan()
8986 b0 = gen_vlan_no_bpf_extensions(cstate, in gen_vlan()
8990 b0 = gen_vlan_no_bpf_extensions(cstate, vlan_num, in gen_vlan()
8998 b0 = gen_vlan_no_bpf_extensions(cstate, vlan_num, has_vlan_tag); in gen_vlan()
9002 bpf_error(cstate, "no VLAN support for %s", in gen_vlan()
9003 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_vlan()
9007 cstate->vlan_stack_depth++; in gen_vlan()
9020 gen_mpls(compiler_state_t *cstate, bpf_u_int32 label_num_arg, in gen_mpls() argument
9030 if (setjmp(cstate->top_ctx)) in gen_mpls()
9033 if (cstate->label_stack_depth > 0) { in gen_mpls()
9035 b0 = gen_mcmp(cstate, OR_PREVMPLSHDR, 2, BPF_B, 0, 0x01); in gen_mpls()
9041 switch (cstate->linktype) { in gen_mpls()
9047 b0 = gen_linktype(cstate, ETHERTYPE_MPLS); in gen_mpls()
9051 b0 = gen_linktype(cstate, PPP_MPLS_UCAST); in gen_mpls()
9059 bpf_error(cstate, "no MPLS support for %s", in gen_mpls()
9060 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_mpls()
9068 bpf_error(cstate, "MPLS label %u greater than maximum %u", in gen_mpls()
9072 b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_W, (bpf_int32)label_num, in gen_mpls()
9092 cstate->off_nl_nosnap += 4; in gen_mpls()
9093 cstate->off_nl += 4; in gen_mpls()
9094 cstate->label_stack_depth++; in gen_mpls()
9102 gen_pppoed(compiler_state_t *cstate) in gen_pppoed() argument
9108 if (setjmp(cstate->top_ctx)) in gen_pppoed()
9112 return gen_linktype(cstate, (bpf_int32)ETHERTYPE_PPPOED); in gen_pppoed()
9116 gen_pppoes(compiler_state_t *cstate, bpf_u_int32 sess_num, int has_sess_num) in gen_pppoes() argument
9124 if (setjmp(cstate->top_ctx)) in gen_pppoes()
9130 b0 = gen_linktype(cstate, (bpf_int32)ETHERTYPE_PPPOES); in gen_pppoes()
9135 bpf_error(cstate, "PPPoE session number %u greater than maximum %u", in gen_pppoes()
9138 b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_W, in gen_pppoes()
9162 PUSH_LINKHDR(cstate, DLT_PPP, cstate->off_linkpl.is_variable, in gen_pppoes()
9163 cstate->off_linkpl.constant_part + cstate->off_nl + 6, /* 6 bytes past the PPPoE header */ in gen_pppoes()
9164 cstate->off_linkpl.reg); in gen_pppoes()
9166 cstate->off_linktype = cstate->off_linkhdr; in gen_pppoes()
9167 cstate->off_linkpl.constant_part = cstate->off_linkhdr.constant_part + 2; in gen_pppoes()
9169 cstate->off_nl = 0; in gen_pppoes()
9170 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in gen_pppoes()
9178 gen_geneve_check(compiler_state_t *cstate, in gen_geneve_check() argument
9184 b0 = gen_portfn(cstate, GENEVE_PORT, IPPROTO_UDP, Q_DST); in gen_geneve_check()
9189 b1 = gen_mcmp(cstate, offrel, 8, BPF_B, (bpf_int32)0, 0xc0); in gen_geneve_check()
9195 bpf_error(cstate, "Geneve VNI %u greater than maximum %u", in gen_geneve_check()
9199 b1 = gen_mcmp(cstate, offrel, 12, BPF_W, (bpf_int32)vni, in gen_geneve_check()
9214 gen_geneve4(compiler_state_t *cstate, bpf_u_int32 vni, int has_vni) in gen_geneve4() argument
9219 b0 = gen_geneve_check(cstate, gen_port, OR_TRAN_IPV4, vni, has_vni); in gen_geneve4()
9222 s = gen_loadx_iphdrlen(cstate); in gen_geneve4()
9224 s1 = new_stmt(cstate, BPF_MISC|BPF_TXA); in gen_geneve4()
9230 b1 = new_block(cstate, BPF_JMP|BPF_JEQ|BPF_X); in gen_geneve4()
9240 gen_geneve6(compiler_state_t *cstate, bpf_u_int32 vni, int has_vni) in gen_geneve6() argument
9245 b0 = gen_geneve_check(cstate, gen_port6, OR_TRAN_IPV6, vni, has_vni); in gen_geneve6()
9249 s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl); in gen_geneve6()
9251 s1 = new_stmt(cstate, BPF_LD|BPF_IMM); in gen_geneve6()
9255 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X); in gen_geneve6()
9259 s = new_stmt(cstate, BPF_LD|BPF_IMM); in gen_geneve6()
9266 s1 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_geneve6()
9269 b1 = new_block(cstate, BPF_JMP|BPF_JEQ|BPF_X); in gen_geneve6()
9283 gen_geneve_offsets(compiler_state_t *cstate) in gen_geneve_offsets() argument
9292 s = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_geneve_offsets()
9293 s->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 8; in gen_geneve_offsets()
9296 s1 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_geneve_offsets()
9301 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_geneve_offsets()
9305 cstate->off_linktype.reg = alloc_reg(cstate); in gen_geneve_offsets()
9306 cstate->off_linktype.is_variable = 1; in gen_geneve_offsets()
9307 cstate->off_linktype.constant_part = 0; in gen_geneve_offsets()
9309 s1 = new_stmt(cstate, BPF_ST); in gen_geneve_offsets()
9310 s1->s.k = cstate->off_linktype.reg; in gen_geneve_offsets()
9316 s1 = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_geneve_offsets()
9320 s1 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K); in gen_geneve_offsets()
9324 s1 = new_stmt(cstate, BPF_ALU|BPF_MUL|BPF_K); in gen_geneve_offsets()
9329 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_geneve_offsets()
9334 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X); in gen_geneve_offsets()
9346 PUSH_LINKHDR(cstate, DLT_EN10MB, 1, 0, alloc_reg(cstate)); in gen_geneve_offsets()
9348 s1 = new_stmt(cstate, BPF_ST); in gen_geneve_offsets()
9349 s1->s.k = cstate->off_linkhdr.reg; in gen_geneve_offsets()
9358 cstate->no_optimize = 1; in gen_geneve_offsets()
9361 s1 = new_stmt(cstate, BPF_LD|BPF_IND|BPF_H); in gen_geneve_offsets()
9366 s1 = new_stmt(cstate, BPF_LDX|BPF_MEM); in gen_geneve_offsets()
9367 s1->s.k = cstate->off_linkhdr.reg; in gen_geneve_offsets()
9373 s_proto = new_stmt(cstate, JMP(BPF_JEQ)); in gen_geneve_offsets()
9377 s1 = new_stmt(cstate, BPF_MISC|BPF_TXA); in gen_geneve_offsets()
9383 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_geneve_offsets()
9387 s1 = new_stmt(cstate, BPF_ST); in gen_geneve_offsets()
9388 s1->s.k = cstate->off_linktype.reg; in gen_geneve_offsets()
9393 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_geneve_offsets()
9398 s1 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_geneve_offsets()
9402 cstate->off_linkpl.reg = alloc_reg(cstate); in gen_geneve_offsets()
9403 cstate->off_linkpl.is_variable = 1; in gen_geneve_offsets()
9404 cstate->off_linkpl.constant_part = 0; in gen_geneve_offsets()
9406 s1 = new_stmt(cstate, BPF_STX); in gen_geneve_offsets()
9407 s1->s.k = cstate->off_linkpl.reg; in gen_geneve_offsets()
9411 cstate->off_nl = 0; in gen_geneve_offsets()
9418 gen_geneve(compiler_state_t *cstate, bpf_u_int32 vni, int has_vni) in gen_geneve() argument
9427 if (setjmp(cstate->top_ctx)) in gen_geneve()
9430 b0 = gen_geneve4(cstate, vni, has_vni); in gen_geneve()
9431 b1 = gen_geneve6(cstate, vni, has_vni); in gen_geneve()
9439 s = gen_geneve_offsets(cstate); in gen_geneve()
9441 b1 = gen_true(cstate); in gen_geneve()
9447 cstate->is_geneve = 1; in gen_geneve()
9455 gen_geneve_ll_check(compiler_state_t *cstate) in gen_geneve_ll_check() argument
9466 s = new_stmt(cstate, BPF_LD|BPF_MEM); in gen_geneve_ll_check()
9467 s->s.k = cstate->off_linkhdr.reg; in gen_geneve_ll_check()
9469 s1 = new_stmt(cstate, BPF_LDX|BPF_MEM); in gen_geneve_ll_check()
9470 s1->s.k = cstate->off_linkpl.reg; in gen_geneve_ll_check()
9473 b0 = new_block(cstate, BPF_JMP|BPF_JEQ|BPF_X); in gen_geneve_ll_check()
9482 gen_atmfield_code_internal(compiler_state_t *cstate, int atmfield, in gen_atmfield_code_internal() argument
9490 if (!cstate->is_atm) in gen_atmfield_code_internal()
9491 bpf_error(cstate, "'vpi' supported only on raw ATM"); in gen_atmfield_code_internal()
9492 if (cstate->off_vpi == OFFSET_NOT_SET) in gen_atmfield_code_internal()
9494 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_vpi, BPF_B, 0xffffffff, jtype, in gen_atmfield_code_internal()
9499 if (!cstate->is_atm) in gen_atmfield_code_internal()
9500 bpf_error(cstate, "'vci' supported only on raw ATM"); in gen_atmfield_code_internal()
9501 if (cstate->off_vci == OFFSET_NOT_SET) in gen_atmfield_code_internal()
9503 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_vci, BPF_H, 0xffffffff, jtype, in gen_atmfield_code_internal()
9508 if (cstate->off_proto == OFFSET_NOT_SET) in gen_atmfield_code_internal()
9510 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_proto, BPF_B, 0x0f, jtype, in gen_atmfield_code_internal()
9515 if (cstate->off_payload == OFFSET_NOT_SET) in gen_atmfield_code_internal()
9517 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_payload + MSG_TYPE_POS, BPF_B, in gen_atmfield_code_internal()
9522 if (!cstate->is_atm) in gen_atmfield_code_internal()
9523 bpf_error(cstate, "'callref' supported only on raw ATM"); in gen_atmfield_code_internal()
9524 if (cstate->off_proto == OFFSET_NOT_SET) in gen_atmfield_code_internal()
9526 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_proto, BPF_B, 0xffffffff, in gen_atmfield_code_internal()
9537 gen_atmtype_metac(compiler_state_t *cstate) in gen_atmtype_metac() argument
9541 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmtype_metac()
9542 b1 = gen_atmfield_code_internal(cstate, A_VCI, 1, BPF_JEQ, 0); in gen_atmtype_metac()
9548 gen_atmtype_sc(compiler_state_t *cstate) in gen_atmtype_sc() argument
9552 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmtype_sc()
9553 b1 = gen_atmfield_code_internal(cstate, A_VCI, 5, BPF_JEQ, 0); in gen_atmtype_sc()
9559 gen_atmtype_llc(compiler_state_t *cstate) in gen_atmtype_llc() argument
9563 b0 = gen_atmfield_code_internal(cstate, A_PROTOTYPE, PT_LLC, BPF_JEQ, 0); in gen_atmtype_llc()
9564 cstate->linktype = cstate->prevlinktype; in gen_atmtype_llc()
9569 gen_atmfield_code(compiler_state_t *cstate, int atmfield, in gen_atmfield_code() argument
9576 if (setjmp(cstate->top_ctx)) in gen_atmfield_code()
9579 return gen_atmfield_code_internal(cstate, atmfield, jvalue, jtype, in gen_atmfield_code()
9584 gen_atmtype_abbrev(compiler_state_t *cstate, int type) in gen_atmtype_abbrev() argument
9592 if (setjmp(cstate->top_ctx)) in gen_atmtype_abbrev()
9599 if (!cstate->is_atm) in gen_atmtype_abbrev()
9600 bpf_error(cstate, "'metac' supported only on raw ATM"); in gen_atmtype_abbrev()
9601 b1 = gen_atmtype_metac(cstate); in gen_atmtype_abbrev()
9606 if (!cstate->is_atm) in gen_atmtype_abbrev()
9607 bpf_error(cstate, "'bcc' supported only on raw ATM"); in gen_atmtype_abbrev()
9608 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmtype_abbrev()
9609 b1 = gen_atmfield_code_internal(cstate, A_VCI, 2, BPF_JEQ, 0); in gen_atmtype_abbrev()
9615 if (!cstate->is_atm) in gen_atmtype_abbrev()
9616 bpf_error(cstate, "'oam4sc' supported only on raw ATM"); in gen_atmtype_abbrev()
9617 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmtype_abbrev()
9618 b1 = gen_atmfield_code_internal(cstate, A_VCI, 3, BPF_JEQ, 0); in gen_atmtype_abbrev()
9624 if (!cstate->is_atm) in gen_atmtype_abbrev()
9625 bpf_error(cstate, "'oam4ec' supported only on raw ATM"); in gen_atmtype_abbrev()
9626 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmtype_abbrev()
9627 b1 = gen_atmfield_code_internal(cstate, A_VCI, 4, BPF_JEQ, 0); in gen_atmtype_abbrev()
9633 if (!cstate->is_atm) in gen_atmtype_abbrev()
9634 bpf_error(cstate, "'sc' supported only on raw ATM"); in gen_atmtype_abbrev()
9635 b1 = gen_atmtype_sc(cstate); in gen_atmtype_abbrev()
9640 if (!cstate->is_atm) in gen_atmtype_abbrev()
9641 bpf_error(cstate, "'ilmic' supported only on raw ATM"); in gen_atmtype_abbrev()
9642 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmtype_abbrev()
9643 b1 = gen_atmfield_code_internal(cstate, A_VCI, 16, BPF_JEQ, 0); in gen_atmtype_abbrev()
9649 if (!cstate->is_atm) in gen_atmtype_abbrev()
9650 bpf_error(cstate, "'lane' supported only on raw ATM"); in gen_atmtype_abbrev()
9651 b1 = gen_atmfield_code_internal(cstate, A_PROTOTYPE, PT_LANE, BPF_JEQ, 0); in gen_atmtype_abbrev()
9661 PUSH_LINKHDR(cstate, DLT_EN10MB, 0, in gen_atmtype_abbrev()
9662 cstate->off_payload + 2, /* Ethernet header */ in gen_atmtype_abbrev()
9664 cstate->off_linktype.constant_part = cstate->off_linkhdr.constant_part + 12; in gen_atmtype_abbrev()
9665 cstate->off_linkpl.constant_part = cstate->off_linkhdr.constant_part + 14; /* Ethernet */ in gen_atmtype_abbrev()
9666 cstate->off_nl = 0; /* Ethernet II */ in gen_atmtype_abbrev()
9667 cstate->off_nl_nosnap = 3; /* 802.3+802.2 */ in gen_atmtype_abbrev()
9672 if (!cstate->is_atm) in gen_atmtype_abbrev()
9673 bpf_error(cstate, "'llc' supported only on raw ATM"); in gen_atmtype_abbrev()
9674 b1 = gen_atmtype_llc(cstate); in gen_atmtype_abbrev()
9691 gen_mtp2type_abbrev(compiler_state_t *cstate, int type) in gen_mtp2type_abbrev() argument
9699 if (setjmp(cstate->top_ctx)) in gen_mtp2type_abbrev()
9705 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
9706 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
9707 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
9708 bpf_error(cstate, "'fisu' supported only on MTP2"); in gen_mtp2type_abbrev()
9710 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B, 0x3f, BPF_JEQ, 0, 0); in gen_mtp2type_abbrev()
9714 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
9715 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
9716 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
9717 bpf_error(cstate, "'lssu' supported only on MTP2"); in gen_mtp2type_abbrev()
9718 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B, 0x3f, BPF_JGT, 1, 2); in gen_mtp2type_abbrev()
9719 b1 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B, 0x3f, BPF_JGT, 0, 0); in gen_mtp2type_abbrev()
9724 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
9725 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
9726 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
9727 bpf_error(cstate, "'msu' supported only on MTP2"); in gen_mtp2type_abbrev()
9728 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B, 0x3f, BPF_JGT, 0, 2); in gen_mtp2type_abbrev()
9732 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
9733 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
9734 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
9735 bpf_error(cstate, "'hfisu' supported only on MTP2_HSL"); in gen_mtp2type_abbrev()
9737 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H, 0xff80, BPF_JEQ, 0, 0); in gen_mtp2type_abbrev()
9741 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
9742 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
9743 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
9744 bpf_error(cstate, "'hlssu' supported only on MTP2_HSL"); in gen_mtp2type_abbrev()
9745 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H, 0xff80, BPF_JGT, 1, 0x0100); in gen_mtp2type_abbrev()
9746 b1 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H, 0xff80, BPF_JGT, 0, 0); in gen_mtp2type_abbrev()
9751 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
9752 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
9753 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
9754 bpf_error(cstate, "'hmsu' supported only on MTP2_HSL"); in gen_mtp2type_abbrev()
9755 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H, 0xff80, BPF_JGT, 0, 0x0100); in gen_mtp2type_abbrev()
9770 gen_mtp3field_code(compiler_state_t *cstate, int mtp3field, in gen_mtp3field_code() argument
9785 if (setjmp(cstate->top_ctx)) in gen_mtp3field_code()
9788 newoff_sio = cstate->off_sio; in gen_mtp3field_code()
9789 newoff_opc = cstate->off_opc; in gen_mtp3field_code()
9790 newoff_dpc = cstate->off_dpc; in gen_mtp3field_code()
9791 newoff_sls = cstate->off_sls; in gen_mtp3field_code()
9799 if (cstate->off_sio == OFFSET_NOT_SET) in gen_mtp3field_code()
9800 bpf_error(cstate, "'sio' supported only on SS7"); in gen_mtp3field_code()
9803 bpf_error(cstate, "sio value %u too big; max value = 255", in gen_mtp3field_code()
9805 b0 = gen_ncmp(cstate, OR_PACKET, newoff_sio, BPF_B, 0xffffffff, in gen_mtp3field_code()
9814 if (cstate->off_opc == OFFSET_NOT_SET) in gen_mtp3field_code()
9815 bpf_error(cstate, "'opc' supported only on SS7"); in gen_mtp3field_code()
9818 bpf_error(cstate, "opc value %u too big; max value = 16383", in gen_mtp3field_code()
9829 b0 = gen_ncmp(cstate, OR_PACKET, newoff_opc, BPF_W, 0x00c0ff0f, in gen_mtp3field_code()
9838 if (cstate->off_dpc == OFFSET_NOT_SET) in gen_mtp3field_code()
9839 bpf_error(cstate, "'dpc' supported only on SS7"); in gen_mtp3field_code()
9842 bpf_error(cstate, "dpc value %u too big; max value = 16383", in gen_mtp3field_code()
9851 b0 = gen_ncmp(cstate, OR_PACKET, newoff_dpc, BPF_W, 0xff3f0000, in gen_mtp3field_code()
9860 if (cstate->off_sls == OFFSET_NOT_SET) in gen_mtp3field_code()
9861 bpf_error(cstate, "'sls' supported only on SS7"); in gen_mtp3field_code()
9864 bpf_error(cstate, "sls value %u too big; max value = 15", in gen_mtp3field_code()
9869 b0 = gen_ncmp(cstate, OR_PACKET, newoff_sls, BPF_B, 0xf0, in gen_mtp3field_code()
9880 gen_msg_abbrev(compiler_state_t *cstate, int type) in gen_msg_abbrev() argument
9891 b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, SETUP, BPF_JEQ, 0); in gen_msg_abbrev()
9895 b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, CALL_PROCEED, BPF_JEQ, 0); in gen_msg_abbrev()
9899 b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, CONNECT, BPF_JEQ, 0); in gen_msg_abbrev()
9903 b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, CONNECT_ACK, BPF_JEQ, 0); in gen_msg_abbrev()
9907 b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, RELEASE, BPF_JEQ, 0); in gen_msg_abbrev()
9911 b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, RELEASE_DONE, BPF_JEQ, 0); in gen_msg_abbrev()
9921 gen_atmmulti_abbrev(compiler_state_t *cstate, int type) in gen_atmmulti_abbrev() argument
9929 if (setjmp(cstate->top_ctx)) in gen_atmmulti_abbrev()
9935 if (!cstate->is_atm) in gen_atmmulti_abbrev()
9936 bpf_error(cstate, "'oam' supported only on raw ATM"); in gen_atmmulti_abbrev()
9938 b0 = gen_atmfield_code_internal(cstate, A_VCI, 3, BPF_JEQ, 0); in gen_atmmulti_abbrev()
9939 b1 = gen_atmfield_code_internal(cstate, A_VCI, 4, BPF_JEQ, 0); in gen_atmmulti_abbrev()
9941 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmmulti_abbrev()
9946 if (!cstate->is_atm) in gen_atmmulti_abbrev()
9947 bpf_error(cstate, "'oamf4' supported only on raw ATM"); in gen_atmmulti_abbrev()
9949 b0 = gen_atmfield_code_internal(cstate, A_VCI, 3, BPF_JEQ, 0); in gen_atmmulti_abbrev()
9950 b1 = gen_atmfield_code_internal(cstate, A_VCI, 4, BPF_JEQ, 0); in gen_atmmulti_abbrev()
9952 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmmulti_abbrev()
9961 if (!cstate->is_atm) in gen_atmmulti_abbrev()
9962 bpf_error(cstate, "'connectmsg' supported only on raw ATM"); in gen_atmmulti_abbrev()
9963 b0 = gen_msg_abbrev(cstate, A_SETUP); in gen_atmmulti_abbrev()
9964 b1 = gen_msg_abbrev(cstate, A_CALLPROCEED); in gen_atmmulti_abbrev()
9966 b0 = gen_msg_abbrev(cstate, A_CONNECT); in gen_atmmulti_abbrev()
9968 b0 = gen_msg_abbrev(cstate, A_CONNECTACK); in gen_atmmulti_abbrev()
9970 b0 = gen_msg_abbrev(cstate, A_RELEASE); in gen_atmmulti_abbrev()
9972 b0 = gen_msg_abbrev(cstate, A_RELEASE_DONE); in gen_atmmulti_abbrev()
9974 b0 = gen_atmtype_sc(cstate); in gen_atmmulti_abbrev()
9979 if (!cstate->is_atm) in gen_atmmulti_abbrev()
9980 bpf_error(cstate, "'metaconnect' supported only on raw ATM"); in gen_atmmulti_abbrev()
9981 b0 = gen_msg_abbrev(cstate, A_SETUP); in gen_atmmulti_abbrev()
9982 b1 = gen_msg_abbrev(cstate, A_CALLPROCEED); in gen_atmmulti_abbrev()
9984 b0 = gen_msg_abbrev(cstate, A_CONNECT); in gen_atmmulti_abbrev()
9986 b0 = gen_msg_abbrev(cstate, A_RELEASE); in gen_atmmulti_abbrev()
9988 b0 = gen_msg_abbrev(cstate, A_RELEASE_DONE); in gen_atmmulti_abbrev()
9990 b0 = gen_atmtype_metac(cstate); in gen_atmmulti_abbrev()