Lines Matching refs:cstate

422 bpf_set_error(compiler_state_t *cstate, const char *fmt, ...)  in bpf_set_error()  argument
435 if (!cstate->error_set) { in bpf_set_error()
437 (void)vsnprintf(cstate->bpf_pcap->errbuf, PCAP_ERRBUF_SIZE, in bpf_set_error()
440 cstate->error_set = 1; in bpf_set_error()
452 bpf_error(compiler_state_t *cstate, const char *fmt, ...) in bpf_error() argument
457 (void)vsnprintf(cstate->bpf_pcap->errbuf, PCAP_ERRBUF_SIZE, in bpf_error()
460 longjmp(cstate->top_ctx, 1); in bpf_error()
473 static void initchunks(compiler_state_t *cstate);
474 static void *newchunk_nolongjmp(compiler_state_t *cstate, size_t);
475 static void *newchunk(compiler_state_t *cstate, size_t);
476 static void freechunks(compiler_state_t *cstate);
477 static inline struct block *new_block(compiler_state_t *cstate, int);
478 static inline struct slist *new_stmt(compiler_state_t *cstate, int);
479 static struct block *gen_retblk(compiler_state_t *cstate, int);
480 static inline void syntax(compiler_state_t *cstate);
574 static struct block *gen_geneve_ll_check(compiler_state_t *cstate);
583 initchunks(compiler_state_t *cstate) in initchunks() argument
588 cstate->chunks[i].n_left = 0; in initchunks()
589 cstate->chunks[i].m = NULL; in initchunks()
591 cstate->cur_chunk = 0; in initchunks()
595 newchunk_nolongjmp(compiler_state_t *cstate, size_t n) in newchunk_nolongjmp() argument
609 cp = &cstate->chunks[cstate->cur_chunk]; in newchunk_nolongjmp()
612 k = ++cstate->cur_chunk; in newchunk_nolongjmp()
614 bpf_set_error(cstate, "out of memory"); in newchunk_nolongjmp()
620 bpf_set_error(cstate, "out of memory"); in newchunk_nolongjmp()
626 bpf_set_error(cstate, "out of memory"); in newchunk_nolongjmp()
635 newchunk(compiler_state_t *cstate, size_t n) in newchunk() argument
639 p = newchunk_nolongjmp(cstate, n); in newchunk()
641 longjmp(cstate->top_ctx, 1); in newchunk()
648 freechunks(compiler_state_t *cstate) in freechunks() argument
653 if (cstate->chunks[i].m != NULL) in freechunks()
654 free(cstate->chunks[i].m); in freechunks()
664 sdup(compiler_state_t *cstate, const char *s) in sdup() argument
667 char *cp = newchunk_nolongjmp(cstate, n); in sdup()
676 new_block(compiler_state_t *cstate, int code) in new_block() argument
680 p = (struct block *)newchunk(cstate, sizeof(*p)); in new_block()
688 new_stmt(compiler_state_t *cstate, int code) in new_stmt() argument
692 p = (struct slist *)newchunk(cstate, sizeof(*p)); in new_stmt()
699 gen_retblk(compiler_state_t *cstate, int v) in gen_retblk() argument
701 struct block *b = new_block(cstate, BPF_RET|BPF_K); in gen_retblk()
708 syntax(compiler_state_t *cstate) in syntax() argument
710 bpf_error(cstate, "syntax error in filter expression"); in syntax()
720 compiler_state_t cstate; in pcap_compile() local
765 initchunks(&cstate); in pcap_compile()
766 cstate.no_optimize = 0; in pcap_compile()
768 cstate.ai = NULL; in pcap_compile()
770 cstate.e = NULL; in pcap_compile()
771 cstate.ic.root = NULL; in pcap_compile()
772 cstate.ic.cur_mark = 0; in pcap_compile()
773 cstate.bpf_pcap = p; in pcap_compile()
774 cstate.error_set = 0; in pcap_compile()
775 init_regs(&cstate); in pcap_compile()
777 cstate.netmask = mask; in pcap_compile()
779 cstate.snaplen = pcap_snapshot(p); in pcap_compile()
780 if (cstate.snaplen == 0) { in pcap_compile()
799 pcap_set_extra(&cstate, scanner); in pcap_compile()
801 if (init_linktype(&cstate, p) == -1) { in pcap_compile()
805 if (pcap_parse(scanner, &cstate) != 0) { in pcap_compile()
807 if (cstate.ai != NULL) in pcap_compile()
808 freeaddrinfo(cstate.ai); in pcap_compile()
810 if (cstate.e != NULL) in pcap_compile()
811 free(cstate.e); in pcap_compile()
816 if (cstate.ic.root == NULL) { in pcap_compile()
820 if (setjmp(cstate.top_ctx)) { in pcap_compile()
824 cstate.ic.root = gen_retblk(&cstate, cstate.snaplen); in pcap_compile()
827 if (optimize && !cstate.no_optimize) { in pcap_compile()
828 if (bpf_optimize(&cstate.ic, p->errbuf) == -1) { in pcap_compile()
833 if (cstate.ic.root == NULL || in pcap_compile()
834 (cstate.ic.root->s.code == (BPF_RET|BPF_K) && cstate.ic.root->s.k == 0)) { in pcap_compile()
841 program->bf_insns = icode_to_fcode(&cstate.ic, in pcap_compile()
842 cstate.ic.root, &len, p->errbuf); in pcap_compile()
864 freechunks(&cstate); in pcap_compile()
944 finish_parse(compiler_state_t *cstate, struct block *p) in finish_parse() argument
952 if (setjmp(cstate->top_ctx)) in finish_parse()
974 insert_compute_vloffsets(cstate, p->head); in finish_parse()
989 ppi_dlt_check = gen_ppi_dlt_check(cstate); in finish_parse()
993 backpatch(p, gen_retblk(cstate, cstate->snaplen)); in finish_parse()
995 backpatch(p, gen_retblk(cstate, 0)); in finish_parse()
996 cstate->ic.root = p->head; in finish_parse()
1028 gen_cmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_cmp() argument
1031 return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JEQ, 0, v); in gen_cmp()
1035 gen_cmp_gt(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_cmp_gt() argument
1038 return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JGT, 0, v); in gen_cmp_gt()
1042 gen_cmp_ge(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_cmp_ge() argument
1045 return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JGE, 0, v); in gen_cmp_ge()
1049 gen_cmp_lt(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_cmp_lt() argument
1052 return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JGE, 1, v); in gen_cmp_lt()
1056 gen_cmp_le(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_cmp_le() argument
1059 return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JGT, 1, v); in gen_cmp_le()
1063 gen_mcmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_mcmp() argument
1066 return gen_ncmp(cstate, offrel, offset, size, mask, BPF_JEQ, 0, v); in gen_mcmp()
1070 gen_bcmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_bcmp() argument
1079 tmp = gen_cmp(cstate, offrel, offset + size - 4, BPF_W, in gen_bcmp()
1089 tmp = gen_cmp(cstate, offrel, offset + size - 2, BPF_H, in gen_bcmp()
1097 tmp = gen_cmp(cstate, offrel, offset, BPF_B, v[0]); in gen_bcmp()
1112 gen_ncmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_ncmp() argument
1119 s = gen_load_a(cstate, offrel, offset, size); in gen_ncmp()
1122 s2 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K); in gen_ncmp()
1127 b = new_block(cstate, JMP(jtype)); in gen_ncmp()
1136 init_linktype(compiler_state_t *cstate, pcap_t *p) in init_linktype() argument
1138 cstate->pcap_fddipad = p->fddipad; in init_linktype()
1143 cstate->outermostlinktype = pcap_datalink(p); in init_linktype()
1144 cstate->off_outermostlinkhdr.constant_part = 0; in init_linktype()
1145 cstate->off_outermostlinkhdr.is_variable = 0; in init_linktype()
1146 cstate->off_outermostlinkhdr.reg = -1; in init_linktype()
1148 cstate->prevlinktype = cstate->outermostlinktype; in init_linktype()
1149 cstate->off_prevlinkhdr.constant_part = 0; in init_linktype()
1150 cstate->off_prevlinkhdr.is_variable = 0; in init_linktype()
1151 cstate->off_prevlinkhdr.reg = -1; in init_linktype()
1153 cstate->linktype = cstate->outermostlinktype; in init_linktype()
1154 cstate->off_linkhdr.constant_part = 0; in init_linktype()
1155 cstate->off_linkhdr.is_variable = 0; in init_linktype()
1156 cstate->off_linkhdr.reg = -1; in init_linktype()
1161 cstate->off_linkpl.constant_part = 0; in init_linktype()
1162 cstate->off_linkpl.is_variable = 0; in init_linktype()
1163 cstate->off_linkpl.reg = -1; in init_linktype()
1165 cstate->off_linktype.constant_part = 0; in init_linktype()
1166 cstate->off_linktype.is_variable = 0; in init_linktype()
1167 cstate->off_linktype.reg = -1; in init_linktype()
1172 cstate->is_atm = 0; in init_linktype()
1173 cstate->off_vpi = OFFSET_NOT_SET; in init_linktype()
1174 cstate->off_vci = OFFSET_NOT_SET; in init_linktype()
1175 cstate->off_proto = OFFSET_NOT_SET; in init_linktype()
1176 cstate->off_payload = OFFSET_NOT_SET; in init_linktype()
1181 cstate->is_geneve = 0; in init_linktype()
1186 cstate->is_vlan_vloffset = 0; in init_linktype()
1191 cstate->off_li = OFFSET_NOT_SET; in init_linktype()
1192 cstate->off_li_hsl = OFFSET_NOT_SET; in init_linktype()
1193 cstate->off_sio = OFFSET_NOT_SET; in init_linktype()
1194 cstate->off_opc = OFFSET_NOT_SET; in init_linktype()
1195 cstate->off_dpc = OFFSET_NOT_SET; in init_linktype()
1196 cstate->off_sls = OFFSET_NOT_SET; in init_linktype()
1198 cstate->label_stack_depth = 0; in init_linktype()
1199 cstate->vlan_stack_depth = 0; in init_linktype()
1201 switch (cstate->linktype) { in init_linktype()
1204 cstate->off_linktype.constant_part = 2; in init_linktype()
1205 cstate->off_linkpl.constant_part = 6; in init_linktype()
1206 cstate->off_nl = 0; /* XXX in reality, variable! */ in init_linktype()
1207 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1211 cstate->off_linktype.constant_part = 4; in init_linktype()
1212 cstate->off_linkpl.constant_part = 8; in init_linktype()
1213 cstate->off_nl = 0; /* XXX in reality, variable! */ in init_linktype()
1214 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1218 cstate->off_linktype.constant_part = 12; in init_linktype()
1219 cstate->off_linkpl.constant_part = 14; /* Ethernet header length */ in init_linktype()
1220 cstate->off_nl = 0; /* Ethernet II */ in init_linktype()
1221 cstate->off_nl_nosnap = 3; /* 802.3+802.2 */ in init_linktype()
1229 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1230 cstate->off_linkpl.constant_part = 16; in init_linktype()
1231 cstate->off_nl = 0; in init_linktype()
1232 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1237 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1239 cstate->off_linkpl.constant_part = 24; in init_linktype()
1240 cstate->off_nl = 0; in init_linktype()
1241 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1246 cstate->off_linktype.constant_part = 0; in init_linktype()
1247 cstate->off_linkpl.constant_part = 4; in init_linktype()
1248 cstate->off_nl = 0; in init_linktype()
1249 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1253 cstate->off_linktype.constant_part = 0; in init_linktype()
1254 cstate->off_linkpl.constant_part = 12; in init_linktype()
1255 cstate->off_nl = 0; in init_linktype()
1256 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1264 cstate->off_linktype.constant_part = 2; /* skip HDLC-like framing */ in init_linktype()
1265 cstate->off_linkpl.constant_part = 4; /* skip HDLC-like framing and protocol field */ in init_linktype()
1266 cstate->off_nl = 0; in init_linktype()
1267 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1275 cstate->off_linktype.constant_part = 6; in init_linktype()
1276 cstate->off_linkpl.constant_part = 8; in init_linktype()
1277 cstate->off_nl = 0; in init_linktype()
1278 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1282 cstate->off_linktype.constant_part = 5; in init_linktype()
1283 cstate->off_linkpl.constant_part = 24; in init_linktype()
1284 cstate->off_nl = 0; in init_linktype()
1285 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1297 cstate->off_linktype.constant_part = 13; in init_linktype()
1298 cstate->off_linktype.constant_part += cstate->pcap_fddipad; in init_linktype()
1299 cstate->off_linkpl.constant_part = 13; /* FDDI MAC header length */ in init_linktype()
1300 cstate->off_linkpl.constant_part += cstate->pcap_fddipad; in init_linktype()
1301 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1302 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1329 cstate->off_linktype.constant_part = 14; in init_linktype()
1330 cstate->off_linkpl.constant_part = 14; /* Token Ring MAC header length */ in init_linktype()
1331 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1332 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1338 cstate->off_linkhdr.is_variable = 1; in init_linktype()
1362 cstate->off_linktype.constant_part = 24; in init_linktype()
1363 cstate->off_linkpl.constant_part = 0; /* link-layer header is variable-length */ in init_linktype()
1364 cstate->off_linkpl.is_variable = 1; in init_linktype()
1365 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1366 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1379 cstate->off_linktype.constant_part = 24; in init_linktype()
1380 cstate->off_linkpl.constant_part = 0; /* link-layer header is variable-length */ in init_linktype()
1381 cstate->off_linkpl.is_variable = 1; in init_linktype()
1382 cstate->off_linkhdr.is_variable = 1; in init_linktype()
1383 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1384 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1400 cstate->off_linktype.constant_part = 0; in init_linktype()
1401 cstate->off_linkpl.constant_part = 0; /* packet begins with LLC header */ in init_linktype()
1402 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1403 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1411 cstate->is_atm = 1; in init_linktype()
1412 cstate->off_vpi = SUNATM_VPI_POS; in init_linktype()
1413 cstate->off_vci = SUNATM_VCI_POS; in init_linktype()
1414 cstate->off_proto = PROTO_POS; in init_linktype()
1415 cstate->off_payload = SUNATM_PKT_BEGIN_POS; in init_linktype()
1416 cstate->off_linktype.constant_part = cstate->off_payload; in init_linktype()
1417 cstate->off_linkpl.constant_part = cstate->off_payload; /* if LLC-encapsulated */ in init_linktype()
1418 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1419 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1425 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1426 cstate->off_linkpl.constant_part = 0; in init_linktype()
1427 cstate->off_nl = 0; in init_linktype()
1428 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1432 cstate->off_linktype.constant_part = 14; in init_linktype()
1433 cstate->off_linkpl.constant_part = 16; in init_linktype()
1434 cstate->off_nl = 0; in init_linktype()
1435 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1439 cstate->off_linktype.constant_part = 0; in init_linktype()
1440 cstate->off_linkpl.constant_part = 20; in init_linktype()
1441 cstate->off_nl = 0; in init_linktype()
1442 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1451 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1452 cstate->off_linkpl.constant_part = 0; in init_linktype()
1453 cstate->off_nl = 0; in init_linktype()
1454 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1468 cstate->off_linktype.constant_part = 16; in init_linktype()
1469 cstate->off_linkpl.constant_part = 16; in init_linktype()
1470 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1471 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1479 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1480 cstate->off_linkpl.constant_part = 0; in init_linktype()
1481 cstate->off_nl = 0; in init_linktype()
1482 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1491 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1492 cstate->off_linkpl.constant_part = 0; in init_linktype()
1493 cstate->off_nl = 4; in init_linktype()
1494 cstate->off_nl_nosnap = 0; /* XXX - for now -> no 802.2 LLC */ in init_linktype()
1498 cstate->off_linktype.constant_part = 16; in init_linktype()
1499 cstate->off_linkpl.constant_part = 18; in init_linktype()
1500 cstate->off_nl = 0; in init_linktype()
1501 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1505 cstate->off_linktype.constant_part = 6; in init_linktype()
1506 cstate->off_linkpl.constant_part = 44; in init_linktype()
1507 cstate->off_nl = 0; /* Ethernet II */ in init_linktype()
1508 cstate->off_nl_nosnap = 0; /* XXX - what does it do with 802.3 packets? */ in init_linktype()
1512 cstate->off_linktype.constant_part = 0; in init_linktype()
1513 cstate->off_linkpl.constant_part = 0; /* link-layer header is variable-length */ in init_linktype()
1514 cstate->off_linkpl.is_variable = 1; in init_linktype()
1515 cstate->off_nl = 0; in init_linktype()
1516 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1525 cstate->off_linktype.constant_part = 4; in init_linktype()
1526 cstate->off_linkpl.constant_part = 4; in init_linktype()
1527 cstate->off_nl = 0; in init_linktype()
1528 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1532 cstate->off_linktype.constant_part = 4; /* in reality variable between 4-8 */ in init_linktype()
1533 cstate->off_linkpl.constant_part = 4; /* in reality variable between 4-8 */ in init_linktype()
1534 cstate->off_nl = 0; in init_linktype()
1535 cstate->off_nl_nosnap = 10; in init_linktype()
1539 cstate->off_linktype.constant_part = 8; /* in reality variable between 8-12 */ in init_linktype()
1540 cstate->off_linkpl.constant_part = 8; /* in reality variable between 8-12 */ in init_linktype()
1541 cstate->off_nl = 0; in init_linktype()
1542 cstate->off_nl_nosnap = 10; in init_linktype()
1549 cstate->off_linkpl.constant_part = 14; in init_linktype()
1550 cstate->off_linktype.constant_part = 16; in init_linktype()
1551 cstate->off_nl = 18; /* Ethernet II */ in init_linktype()
1552 cstate->off_nl_nosnap = 21; /* 802.3+802.2 */ in init_linktype()
1556 cstate->off_linktype.constant_part = 4; in init_linktype()
1557 cstate->off_linkpl.constant_part = 6; in init_linktype()
1558 cstate->off_nl = 0; in init_linktype()
1559 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1563 cstate->off_linktype.constant_part = 6; in init_linktype()
1564 cstate->off_linkpl.constant_part = 12; in init_linktype()
1565 cstate->off_nl = 0; in init_linktype()
1566 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1570 cstate->off_linktype.constant_part = 6; in init_linktype()
1571 …cstate->off_linkpl.constant_part = OFFSET_NOT_SET; /* not really a network layer but raw IP addres… in init_linktype()
1572 cstate->off_nl = OFFSET_NOT_SET; /* not really a network layer but raw IP addresses */ in init_linktype()
1573 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1577 cstate->off_linktype.constant_part = 12; in init_linktype()
1578 cstate->off_linkpl.constant_part = 12; in init_linktype()
1579 cstate->off_nl = 0; /* raw IP/IP6 header */ in init_linktype()
1580 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1584 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1585 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1586 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1587 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1591 cstate->off_linktype.constant_part = 12; in init_linktype()
1592 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; /* L3 proto location dep. on cookie type */ in init_linktype()
1593 cstate->off_nl = OFFSET_NOT_SET; /* L3 proto location dep. on cookie type */ in init_linktype()
1594 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1598 cstate->off_linktype.constant_part = 18; in init_linktype()
1599 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1600 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1601 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1605 cstate->off_linktype.constant_part = 18; in init_linktype()
1606 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1607 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1608 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1612 cstate->off_linktype.constant_part = 8; in init_linktype()
1613 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1614 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1615 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1622 cstate->off_linktype.constant_part = 8; in init_linktype()
1623 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1624 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1625 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1629 cstate->off_li = 2; in init_linktype()
1630 cstate->off_li_hsl = 4; in init_linktype()
1631 cstate->off_sio = 3; in init_linktype()
1632 cstate->off_opc = 4; in init_linktype()
1633 cstate->off_dpc = 4; in init_linktype()
1634 cstate->off_sls = 7; in init_linktype()
1635 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1636 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1637 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1638 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1642 cstate->off_li = 6; in init_linktype()
1643 cstate->off_li_hsl = 8; in init_linktype()
1644 cstate->off_sio = 7; in init_linktype()
1645 cstate->off_opc = 8; in init_linktype()
1646 cstate->off_dpc = 8; in init_linktype()
1647 cstate->off_sls = 11; in init_linktype()
1648 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1649 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1650 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1651 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1655 cstate->off_li = 22; in init_linktype()
1656 cstate->off_li_hsl = 24; in init_linktype()
1657 cstate->off_sio = 23; in init_linktype()
1658 cstate->off_opc = 24; in init_linktype()
1659 cstate->off_dpc = 24; in init_linktype()
1660 cstate->off_sls = 27; in init_linktype()
1661 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1662 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1663 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1664 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1668 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1669 cstate->off_linkpl.constant_part = 4; in init_linktype()
1670 cstate->off_nl = 0; in init_linktype()
1671 cstate->off_nl_nosnap = 0; in init_linktype()
1678 cstate->off_linktype.constant_part = OFFSET_NOT_SET; /* variable, min 15, max 71 steps of 7 */ in init_linktype()
1679 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1680 cstate->off_nl = OFFSET_NOT_SET; /* variable, min 16, max 71 steps of 7 */ in init_linktype()
1681 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1685 cstate->off_linktype.constant_part = 1; in init_linktype()
1686 cstate->off_linkpl.constant_part = 24; /* ipnet header length */ in init_linktype()
1687 cstate->off_nl = 0; in init_linktype()
1688 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1692 cstate->off_linkhdr.constant_part = 4; /* Ethernet header is past 4-byte pseudo-header */ in init_linktype()
1693 cstate->off_linktype.constant_part = cstate->off_linkhdr.constant_part + 12; in init_linktype()
1694 …cstate->off_linkpl.constant_part = cstate->off_linkhdr.constant_part + 14; /* pseudo-header+Ethern… in init_linktype()
1695 cstate->off_nl = 0; /* Ethernet II */ in init_linktype()
1696 cstate->off_nl_nosnap = 3; /* 802.3+802.2 */ in init_linktype()
1700 …cstate->off_linkhdr.constant_part = 12; /* MAC header is past 4-byte pseudo-header, preamble, and … in init_linktype()
1701 cstate->off_linktype.constant_part = cstate->off_linkhdr.constant_part + 12; in init_linktype()
1702 …cstate->off_linkpl.constant_part = cstate->off_linkhdr.constant_part + 14; /* pseudo-header+preamb… in init_linktype()
1703 cstate->off_nl = 0; /* Ethernet II */ in init_linktype()
1704 cstate->off_nl_nosnap = 3; /* 802.3+802.2 */ in init_linktype()
1712 if (cstate->linktype >= DLT_HIGH_MATCHING_MIN && in init_linktype()
1713 cstate->linktype <= DLT_HIGH_MATCHING_MAX) { in init_linktype()
1714 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1715 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1716 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1717 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1719 bpf_set_error(cstate, "unknown data link type %d (min %d, max %d)", in init_linktype()
1720 cstate->linktype, DLT_HIGH_MATCHING_MIN, DLT_HIGH_MATCHING_MAX); in init_linktype()
1726 cstate->off_outermostlinkhdr = cstate->off_prevlinkhdr = cstate->off_linkhdr; in init_linktype()
1734 gen_load_absoffsetrel(compiler_state_t *cstate, bpf_abs_offset *abs_offset, in gen_load_absoffsetrel() argument
1739 s = gen_abs_offset_varpart(cstate, abs_offset); in gen_load_absoffsetrel()
1756 s2 = new_stmt(cstate, BPF_LD|BPF_IND|size); in gen_load_absoffsetrel()
1764 s = new_stmt(cstate, BPF_LD|BPF_ABS|size); in gen_load_absoffsetrel()
1774 gen_load_a(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_load_a() argument
1795 s = new_stmt(cstate, BPF_LD|BPF_ABS|size); in gen_load_a()
1800 s = gen_load_absoffsetrel(cstate, &cstate->off_linkhdr, offset, size); in gen_load_a()
1804 s = gen_load_absoffsetrel(cstate, &cstate->off_prevlinkhdr, offset, size); in gen_load_a()
1808 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, offset, size); in gen_load_a()
1812 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, cstate->off_nl - 4 + offset, size); in gen_load_a()
1816 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, cstate->off_nl + offset, size); in gen_load_a()
1820 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, cstate->off_nl_nosnap + offset, size); in gen_load_a()
1824 s = gen_load_absoffsetrel(cstate, &cstate->off_linktype, offset, size); in gen_load_a()
1834 s = gen_loadx_iphdrlen(cstate); in gen_load_a()
1847 s2 = new_stmt(cstate, BPF_LD|BPF_IND|size); in gen_load_a()
1848 s2->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + offset; in gen_load_a()
1853 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, cstate->off_nl + 40 + offset, size); in gen_load_a()
1865 gen_loadx_iphdrlen(compiler_state_t *cstate) in gen_loadx_iphdrlen() argument
1869 s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl); in gen_loadx_iphdrlen()
1881 s2 = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_loadx_iphdrlen()
1882 s2->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_loadx_iphdrlen()
1884 s2 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K); in gen_loadx_iphdrlen()
1887 s2 = new_stmt(cstate, BPF_ALU|BPF_LSH|BPF_K); in gen_loadx_iphdrlen()
1897 sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X)); in gen_loadx_iphdrlen()
1898 sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX)); in gen_loadx_iphdrlen()
1912 s = new_stmt(cstate, BPF_LDX|BPF_MSH|BPF_B); in gen_loadx_iphdrlen()
1913 s->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_loadx_iphdrlen()
1920 gen_uncond(compiler_state_t *cstate, int rsense) in gen_uncond() argument
1925 s = new_stmt(cstate, BPF_LD|BPF_IMM); in gen_uncond()
1927 b = new_block(cstate, JMP(BPF_JEQ)); in gen_uncond()
1934 gen_true(compiler_state_t *cstate) in gen_true() argument
1936 return gen_uncond(cstate, 1); in gen_true()
1940 gen_false(compiler_state_t *cstate) in gen_false() argument
1942 return gen_uncond(cstate, 0); in gen_false()
1963 gen_ether_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto) in gen_ether_linktype() argument
1984 b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU); in gen_ether_linktype()
1986 b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, (ll_proto << 8) | ll_proto); in gen_ether_linktype()
2023 b0 = gen_cmp(cstate, OR_LLC, 0, BPF_B, LLCSAP_IPX); in gen_ether_linktype()
2024 b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, 0xFFFF); in gen_ether_linktype()
2031 b0 = gen_snap(cstate, 0x000000, ETHERTYPE_IPX); in gen_ether_linktype()
2038 b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU); in gen_ether_linktype()
2054 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ETHERTYPE_IPX); in gen_ether_linktype()
2070 b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU); in gen_ether_linktype()
2085 b1 = gen_snap(cstate, 0x080007, ETHERTYPE_ATALK); in gen_ether_linktype()
2087 b1 = gen_snap(cstate, 0x000000, ETHERTYPE_AARP); in gen_ether_linktype()
2095 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ll_proto); in gen_ether_linktype()
2110 b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU); in gen_ether_linktype()
2112 b1 = gen_cmp(cstate, OR_LINKTYPE, 2, BPF_B, ll_proto); in gen_ether_linktype()
2125 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ll_proto); in gen_ether_linktype()
2131 gen_loopback_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto) in gen_loopback_linktype() argument
2146 if (cstate->linktype == DLT_NULL || cstate->linktype == DLT_ENC) { in gen_loopback_linktype()
2158 if (cstate->bpf_pcap->rfile != NULL && cstate->bpf_pcap->swapped) in gen_loopback_linktype()
2162 return (gen_cmp(cstate, OR_LINKHDR, 0, BPF_W, ll_proto)); in gen_loopback_linktype()
2170 gen_ipnet_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto) in gen_ipnet_linktype() argument
2175 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, IPH_AF_INET); in gen_ipnet_linktype()
2179 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, IPH_AF_INET6); in gen_ipnet_linktype()
2186 return gen_false(cstate); in gen_ipnet_linktype()
2198 gen_linux_sll_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto) in gen_linux_sll_linktype() argument
2219 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, LINUX_SLL_P_802_2); in gen_linux_sll_linktype()
2220 b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, (ll_proto << 8) | ll_proto); in gen_linux_sll_linktype()
2250 b0 = gen_cmp(cstate, OR_LLC, 0, BPF_B, 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, 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, ll_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, ll_proto); in gen_linux_sll_linktype()
2347 gen_load_pflog_llprefixlen(compiler_state_t *cstate) in gen_load_pflog_llprefixlen() argument
2358 if (cstate->off_linkpl.reg != -1) { in gen_load_pflog_llprefixlen()
2362 s1 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_load_pflog_llprefixlen()
2369 s2 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_load_pflog_llprefixlen()
2372 s2 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K); in gen_load_pflog_llprefixlen()
2380 s2 = new_stmt(cstate, BPF_ST); in gen_load_pflog_llprefixlen()
2381 s2->s.k = cstate->off_linkpl.reg; in gen_load_pflog_llprefixlen()
2387 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_pflog_llprefixlen()
2396 gen_load_prism_llprefixlen(compiler_state_t *cstate) in gen_load_prism_llprefixlen() argument
2407 cstate->no_optimize = 1; in gen_load_prism_llprefixlen()
2428 if (cstate->off_linkhdr.reg != -1) { in gen_load_prism_llprefixlen()
2432 s1 = new_stmt(cstate, BPF_LD|BPF_W|BPF_ABS); in gen_load_prism_llprefixlen()
2438 s2 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K); in gen_load_prism_llprefixlen()
2445 sjeq_avs_cookie = new_stmt(cstate, JMP(BPF_JEQ)); in gen_load_prism_llprefixlen()
2456 s2 = new_stmt(cstate, BPF_LD|BPF_W|BPF_ABS); in gen_load_prism_llprefixlen()
2469 sjcommon = new_stmt(cstate, JMP(BPF_JA)); in gen_load_prism_llprefixlen()
2479 s2 = new_stmt(cstate, BPF_LD|BPF_W|BPF_IMM); in gen_load_prism_llprefixlen()
2489 s2 = new_stmt(cstate, BPF_ST); in gen_load_prism_llprefixlen()
2490 s2->s.k = cstate->off_linkhdr.reg; in gen_load_prism_llprefixlen()
2497 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_prism_llprefixlen()
2506 gen_load_avs_llprefixlen(compiler_state_t *cstate) in gen_load_avs_llprefixlen() argument
2517 if (cstate->off_linkhdr.reg != -1) { in gen_load_avs_llprefixlen()
2523 s1 = new_stmt(cstate, BPF_LD|BPF_W|BPF_ABS); in gen_load_avs_llprefixlen()
2530 s2 = new_stmt(cstate, BPF_ST); in gen_load_avs_llprefixlen()
2531 s2->s.k = cstate->off_linkhdr.reg; in gen_load_avs_llprefixlen()
2537 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_avs_llprefixlen()
2546 gen_load_radiotap_llprefixlen(compiler_state_t *cstate) in gen_load_radiotap_llprefixlen() argument
2557 if (cstate->off_linkhdr.reg != -1) { in gen_load_radiotap_llprefixlen()
2569 s1 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_load_radiotap_llprefixlen()
2571 s2 = new_stmt(cstate, BPF_ALU|BPF_LSH|BPF_K); in gen_load_radiotap_llprefixlen()
2574 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_radiotap_llprefixlen()
2581 s2 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_load_radiotap_llprefixlen()
2584 s2 = new_stmt(cstate, BPF_ALU|BPF_OR|BPF_X); in gen_load_radiotap_llprefixlen()
2591 s2 = new_stmt(cstate, BPF_ST); in gen_load_radiotap_llprefixlen()
2592 s2->s.k = cstate->off_linkhdr.reg; in gen_load_radiotap_llprefixlen()
2598 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_radiotap_llprefixlen()
2616 gen_load_ppi_llprefixlen(compiler_state_t *cstate) in gen_load_ppi_llprefixlen() argument
2625 if (cstate->off_linkhdr.reg != -1) { in gen_load_ppi_llprefixlen()
2637 s1 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_load_ppi_llprefixlen()
2639 s2 = new_stmt(cstate, BPF_ALU|BPF_LSH|BPF_K); in gen_load_ppi_llprefixlen()
2642 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_ppi_llprefixlen()
2649 s2 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_load_ppi_llprefixlen()
2652 s2 = new_stmt(cstate, BPF_ALU|BPF_OR|BPF_X); in gen_load_ppi_llprefixlen()
2659 s2 = new_stmt(cstate, BPF_ST); in gen_load_ppi_llprefixlen()
2660 s2->s.k = cstate->off_linkhdr.reg; in gen_load_ppi_llprefixlen()
2666 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_ppi_llprefixlen()
2682 gen_load_802_11_header_len(compiler_state_t *cstate, struct slist *s, struct slist *snext) in gen_load_802_11_header_len() argument
2694 if (cstate->off_linkpl.reg == -1) { in gen_load_802_11_header_len()
2709 cstate->no_optimize = 1; in gen_load_802_11_header_len()
2729 s = new_stmt(cstate, BPF_LDX|BPF_IMM); in gen_load_802_11_header_len()
2730 s->s.k = cstate->off_outermostlinkhdr.constant_part; in gen_load_802_11_header_len()
2740 s2 = new_stmt(cstate, BPF_MISC|BPF_TXA); in gen_load_802_11_header_len()
2742 s2 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_load_802_11_header_len()
2745 s2 = new_stmt(cstate, BPF_ST); in gen_load_802_11_header_len()
2746 s2->s.k = cstate->off_linkpl.reg; in gen_load_802_11_header_len()
2749 s2 = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_load_802_11_header_len()
2758 sjset_data_frame_1 = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2766 sjset_data_frame_1->s.jt = sjset_data_frame_2 = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2777 sjset_data_frame_2->s.jf = sjset_qos = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2787 sjset_qos->s.jt = s2 = new_stmt(cstate, BPF_LD|BPF_MEM); in gen_load_802_11_header_len()
2788 s2->s.k = cstate->off_linkpl.reg; in gen_load_802_11_header_len()
2790 s2 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_IMM); in gen_load_802_11_header_len()
2793 s2 = new_stmt(cstate, BPF_ST); in gen_load_802_11_header_len()
2794 s2->s.k = cstate->off_linkpl.reg; in gen_load_802_11_header_len()
2816 if (cstate->linktype == DLT_IEEE802_11_RADIO) { in gen_load_802_11_header_len()
2821 sjset_qos->s.jf = s2 = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_W); in gen_load_802_11_header_len()
2825 sjset_radiotap_flags_present = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2837 sjset_radiotap_ext_present = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2850 sjset_radiotap_tsft_present = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2864 s2 = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_B); in gen_load_802_11_header_len()
2869 sjset_tsft_datapad = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2881 s2 = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_B); in gen_load_802_11_header_len()
2886 sjset_notsft_datapad = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2897 s_roundup = new_stmt(cstate, BPF_LD|BPF_MEM); in gen_load_802_11_header_len()
2898 s_roundup->s.k = cstate->off_linkpl.reg; in gen_load_802_11_header_len()
2900 s2 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_IMM); in gen_load_802_11_header_len()
2903 s2 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_IMM); in gen_load_802_11_header_len()
2906 s2 = new_stmt(cstate, BPF_ST); in gen_load_802_11_header_len()
2907 s2->s.k = cstate->off_linkpl.reg; in gen_load_802_11_header_len()
2921 insert_compute_vloffsets(compiler_state_t *cstate, struct block *b) in insert_compute_vloffsets() argument
2930 if (cstate->off_linkpl.reg != -1 && cstate->off_linkhdr.is_variable && in insert_compute_vloffsets()
2931 cstate->off_linkhdr.reg == -1) in insert_compute_vloffsets()
2932 cstate->off_linkhdr.reg = alloc_reg(cstate); in insert_compute_vloffsets()
2945 switch (cstate->outermostlinktype) { in insert_compute_vloffsets()
2948 s = gen_load_prism_llprefixlen(cstate); in insert_compute_vloffsets()
2952 s = gen_load_avs_llprefixlen(cstate); in insert_compute_vloffsets()
2956 s = gen_load_radiotap_llprefixlen(cstate); in insert_compute_vloffsets()
2960 s = gen_load_ppi_llprefixlen(cstate); in insert_compute_vloffsets()
2973 switch (cstate->outermostlinktype) { in insert_compute_vloffsets()
2980 s = gen_load_802_11_header_len(cstate, s, b->stmts); in insert_compute_vloffsets()
2984 s = gen_load_pflog_llprefixlen(cstate); in insert_compute_vloffsets()
2992 if (s == NULL && cstate->is_vlan_vloffset) { in insert_compute_vloffsets()
2995 if (cstate->off_linkpl.reg == -1) in insert_compute_vloffsets()
2996 cstate->off_linkpl.reg = alloc_reg(cstate); in insert_compute_vloffsets()
2997 if (cstate->off_linktype.reg == -1) in insert_compute_vloffsets()
2998 cstate->off_linktype.reg = alloc_reg(cstate); in insert_compute_vloffsets()
3000 s = new_stmt(cstate, BPF_LD|BPF_W|BPF_IMM); in insert_compute_vloffsets()
3002 s2 = new_stmt(cstate, BPF_ST); in insert_compute_vloffsets()
3003 s2->s.k = cstate->off_linkpl.reg; in insert_compute_vloffsets()
3005 s2 = new_stmt(cstate, BPF_ST); in insert_compute_vloffsets()
3006 s2->s.k = cstate->off_linktype.reg; in insert_compute_vloffsets()
3023 gen_ppi_dlt_check(compiler_state_t *cstate) in gen_ppi_dlt_check() argument
3028 if (cstate->linktype == DLT_PPI) in gen_ppi_dlt_check()
3032 s_load_dlt = new_stmt(cstate, BPF_LD|BPF_W|BPF_ABS); in gen_ppi_dlt_check()
3035 b = new_block(cstate, JMP(BPF_JEQ)); in gen_ppi_dlt_check()
3062 gen_abs_offset_varpart(compiler_state_t *cstate, bpf_abs_offset *off) in gen_abs_offset_varpart() argument
3073 off->reg = alloc_reg(cstate); in gen_abs_offset_varpart()
3080 s = new_stmt(cstate, BPF_LDX|BPF_MEM); in gen_abs_offset_varpart()
3147 gen_prevlinkhdr_check(compiler_state_t *cstate) in gen_prevlinkhdr_check() argument
3151 if (cstate->is_geneve) in gen_prevlinkhdr_check()
3152 return gen_geneve_ll_check(cstate); in gen_prevlinkhdr_check()
3154 switch (cstate->prevlinktype) { in gen_prevlinkhdr_check()
3164 b0 = gen_cmp(cstate, OR_PREVLINKHDR, SUNATM_PKT_BEGIN_POS, BPF_H, 0xFF00); in gen_prevlinkhdr_check()
3193 gen_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto) in gen_linktype() argument
3199 if (cstate->label_stack_depth > 0) in gen_linktype()
3200 return gen_mpls_linktype(cstate, ll_proto); in gen_linktype()
3202 switch (cstate->linktype) { in gen_linktype()
3209 if (!cstate->is_geneve) in gen_linktype()
3210 b0 = gen_prevlinkhdr_check(cstate); in gen_linktype()
3214 b1 = gen_ether_linktype(cstate, ll_proto); in gen_linktype()
3229 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ll_proto); in gen_linktype()
3241 b0 = gen_check_802_11_data_frame(cstate); in gen_linktype()
3246 b1 = gen_llc_linktype(cstate, ll_proto); in gen_linktype()
3255 return gen_llc_linktype(cstate, ll_proto); in gen_linktype()
3262 return gen_llc_linktype(cstate, ll_proto); in gen_linktype()
3268 return gen_llc_linktype(cstate, ll_proto); in gen_linktype()
3279 b0 = gen_atmfield_code_internal(cstate, A_PROTOTYPE, PT_LLC, BPF_JEQ, 0); in gen_linktype()
3280 b1 = gen_llc_linktype(cstate, ll_proto); in gen_linktype()
3286 return gen_linux_sll_linktype(cstate, ll_proto); in gen_linktype()
3303 return gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, 0x40, 0xF0); in gen_linktype()
3307 return gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, 0x60, 0xF0); in gen_linktype()
3310 return gen_false(cstate); /* always false */ in gen_linktype()
3319 return gen_true(cstate); /* always true */ in gen_linktype()
3322 return gen_false(cstate); in gen_linktype()
3330 return gen_true(cstate); /* always true */ in gen_linktype()
3333 return gen_false(cstate); in gen_linktype()
3344 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, in gen_linktype()
3360 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, PPP_IP); in gen_linktype()
3361 b1 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, PPP_VJC); in gen_linktype()
3363 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, PPP_VJNC); in gen_linktype()
3368 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, in gen_linktype()
3379 return (gen_loopback_linktype(cstate, AF_INET)); in gen_linktype()
3404 if (cstate->bpf_pcap->rfile != NULL) { in gen_linktype()
3409 b0 = gen_loopback_linktype(cstate, BSD_AFNUM_INET6_BSD); in gen_linktype()
3410 b1 = gen_loopback_linktype(cstate, BSD_AFNUM_INET6_FREEBSD); in gen_linktype()
3412 b0 = gen_loopback_linktype(cstate, BSD_AFNUM_INET6_DARWIN); in gen_linktype()
3428 return (gen_loopback_linktype(cstate, 24)); in gen_linktype()
3431 return (gen_loopback_linktype(cstate, AF_INET6)); in gen_linktype()
3437 return gen_false(cstate); in gen_linktype()
3448 return gen_false(cstate); in gen_linktype()
3457 return (gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, af), in gen_linktype()
3460 return (gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, af), in gen_linktype()
3463 return gen_false(cstate); in gen_linktype()
3475 return gen_false(cstate); in gen_linktype()
3478 return (gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3482 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3484 b1 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3490 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3492 b1 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3498 return (gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3502 return (gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3510 return gen_true(cstate); in gen_linktype()
3512 return gen_false(cstate); in gen_linktype()
3527 return gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | 0xcc); in gen_linktype()
3533 return gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | 0x8e); in gen_linktype()
3547 b0 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | ISO8473_CLNP); in gen_linktype()
3548 b1 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | ISO9542_ESIS); in gen_linktype()
3549 b2 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | ISO10589_ISIS); in gen_linktype()
3555 return gen_false(cstate); in gen_linktype()
3560 bpf_error(cstate, "Multi-link Frame Relay link-layer type filtering not implemented"); in gen_linktype()
3592 …return gen_mcmp(cstate, OR_LINKHDR, 0, BPF_W, 0x4d474300, 0xffffff00); /* compare the magic number… in gen_linktype()
3595 return gen_mcmp(cstate, OR_LINKHDR, 0, BPF_W, 0x55FF0000, 0xffff0000); in gen_linktype()
3598 return gen_ipnet_linktype(cstate, ll_proto); in gen_linktype()
3601 bpf_error(cstate, "IrDA link-layer type filtering not implemented"); in gen_linktype()
3604 bpf_error(cstate, "DOCSIS link-layer type filtering not implemented"); in gen_linktype()
3608 bpf_error(cstate, "MTP2 link-layer type filtering not implemented"); in gen_linktype()
3611 bpf_error(cstate, "ERF link-layer type filtering not implemented"); in gen_linktype()
3614 bpf_error(cstate, "PFSYNC link-layer type filtering not implemented"); in gen_linktype()
3617 bpf_error(cstate, "LAPD link-layer type filtering not implemented"); in gen_linktype()
3623 bpf_error(cstate, "USB link-layer type filtering not implemented"); in gen_linktype()
3627 bpf_error(cstate, "Bluetooth link-layer type filtering not implemented"); in gen_linktype()
3631 bpf_error(cstate, "CAN link-layer type filtering not implemented"); in gen_linktype()
3638 bpf_error(cstate, "IEEE 802.15.4 link-layer type filtering not implemented"); in gen_linktype()
3641 bpf_error(cstate, "IEEE 802.16 link-layer type filtering not implemented"); in gen_linktype()
3644 bpf_error(cstate, "SITA link-layer type filtering not implemented"); in gen_linktype()
3647 bpf_error(cstate, "RAIF1 link-layer type filtering not implemented"); in gen_linktype()
3651 bpf_error(cstate, "IPMB link-layer type filtering not implemented"); in gen_linktype()
3654 bpf_error(cstate, "AX.25 link-layer type filtering not implemented"); in gen_linktype()
3661 bpf_error(cstate, "NFLOG link-layer type filtering not implemented"); in gen_linktype()
3670 if (cstate->off_linktype.constant_part != OFFSET_NOT_SET) { in gen_linktype()
3676 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ll_proto); in gen_linktype()
3682 description = pcap_datalink_val_to_description_or_dlt(cstate->linktype); in gen_linktype()
3683 bpf_error(cstate, "%s link-layer type filtering not implemented", in gen_linktype()
3698 gen_snap(compiler_state_t *cstate, bpf_u_int32 orgcode, bpf_u_int32 ptype) in gen_snap() argument
3710 return gen_bcmp(cstate, OR_LLC, 0, 8, snapblock); in gen_snap()
3717 gen_llc_internal(compiler_state_t *cstate) in gen_llc_internal() argument
3721 switch (cstate->linktype) { in gen_llc_internal()
3728 b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU); in gen_llc_internal()
3735 b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, 0xFFFF); in gen_llc_internal()
3744 b0 = gen_atmtype_llc(cstate); in gen_llc_internal()
3751 return gen_true(cstate); in gen_llc_internal()
3757 return gen_true(cstate); in gen_llc_internal()
3768 return gen_true(cstate); in gen_llc_internal()
3778 b0 = gen_check_802_11_data_frame(cstate); in gen_llc_internal()
3782 bpf_error(cstate, "'llc' not supported for %s", in gen_llc_internal()
3783 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_llc_internal()
3789 gen_llc(compiler_state_t *cstate) in gen_llc() argument
3795 if (setjmp(cstate->top_ctx)) in gen_llc()
3798 return gen_llc_internal(cstate); in gen_llc()
3802 gen_llc_i(compiler_state_t *cstate) in gen_llc_i() argument
3811 if (setjmp(cstate->top_ctx)) in gen_llc_i()
3817 b0 = gen_llc_internal(cstate); in gen_llc_i()
3823 s = gen_load_a(cstate, OR_LLC, 2, BPF_B); in gen_llc_i()
3824 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_llc_i()
3833 gen_llc_s(compiler_state_t *cstate) in gen_llc_s() argument
3841 if (setjmp(cstate->top_ctx)) in gen_llc_s()
3847 b0 = gen_llc_internal(cstate); in gen_llc_s()
3853 b1 = gen_mcmp(cstate, OR_LLC, 2, BPF_B, LLC_S_FMT, 0x03); in gen_llc_s()
3859 gen_llc_u(compiler_state_t *cstate) in gen_llc_u() argument
3867 if (setjmp(cstate->top_ctx)) in gen_llc_u()
3873 b0 = gen_llc_internal(cstate); in gen_llc_u()
3879 b1 = gen_mcmp(cstate, OR_LLC, 2, BPF_B, LLC_U_FMT, 0x03); in gen_llc_u()
3885 gen_llc_s_subtype(compiler_state_t *cstate, bpf_u_int32 subtype) in gen_llc_s_subtype() argument
3893 if (setjmp(cstate->top_ctx)) in gen_llc_s_subtype()
3899 b0 = gen_llc_internal(cstate); in gen_llc_s_subtype()
3904 b1 = gen_mcmp(cstate, OR_LLC, 2, BPF_B, subtype, LLC_S_CMD_MASK); in gen_llc_s_subtype()
3910 gen_llc_u_subtype(compiler_state_t *cstate, bpf_u_int32 subtype) in gen_llc_u_subtype() argument
3918 if (setjmp(cstate->top_ctx)) in gen_llc_u_subtype()
3924 b0 = gen_llc_internal(cstate); in gen_llc_u_subtype()
3929 b1 = gen_mcmp(cstate, OR_LLC, 2, BPF_B, subtype, LLC_U_CMD_MASK); in gen_llc_u_subtype()
3947 gen_llc_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto) in gen_llc_linktype() argument
3962 return gen_cmp(cstate, OR_LLC, 0, BPF_H, (bpf_u_int32) in gen_llc_linktype()
3970 return gen_cmp(cstate, OR_LLC, 0, BPF_B, LLCSAP_IPX); in gen_llc_linktype()
3982 return gen_snap(cstate, 0x080007, ETHERTYPE_ATALK); in gen_llc_linktype()
3994 return gen_cmp(cstate, OR_LLC, 0, BPF_B, ll_proto); in gen_llc_linktype()
4015 return gen_cmp(cstate, OR_LLC, 6, BPF_H, ll_proto); in gen_llc_linktype()
4021 gen_hostop(compiler_state_t *cstate, bpf_u_int32 addr, bpf_u_int32 mask, in gen_hostop() argument
4038 b0 = gen_hostop(cstate, addr, mask, Q_SRC, ll_proto, src_off, dst_off); in gen_hostop()
4039 b1 = gen_hostop(cstate, addr, mask, Q_DST, ll_proto, src_off, dst_off); in gen_hostop()
4045 b0 = gen_hostop(cstate, addr, mask, Q_SRC, ll_proto, src_off, dst_off); in gen_hostop()
4046 b1 = gen_hostop(cstate, addr, mask, Q_DST, ll_proto, src_off, dst_off); in gen_hostop()
4051 …bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for addresses other than 802.11… in gen_hostop()
4055 …bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for addresses other than 802.11… in gen_hostop()
4059 …bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for addresses other than 802.11… in gen_hostop()
4063 …bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for addresses other than 802.11… in gen_hostop()
4067 bpf_error(cstate, "'ra' is not a valid qualifier for addresses other than 802.11 MAC addresses"); in gen_hostop()
4071 bpf_error(cstate, "'ta' is not a valid qualifier for addresses other than 802.11 MAC addresses"); in gen_hostop()
4078 b0 = gen_linktype(cstate, ll_proto); in gen_hostop()
4079 b1 = gen_mcmp(cstate, OR_LINKPL, offset, BPF_W, addr, mask); in gen_hostop()
4086 gen_hostop6(compiler_state_t *cstate, struct in6_addr *addr, in gen_hostop6() argument
4114 b0 = gen_hostop6(cstate, addr, mask, Q_SRC, ll_proto, src_off, dst_off); in gen_hostop6()
4115 b1 = gen_hostop6(cstate, addr, mask, Q_DST, ll_proto, src_off, dst_off); in gen_hostop6()
4121 b0 = gen_hostop6(cstate, addr, mask, Q_SRC, ll_proto, src_off, dst_off); in gen_hostop6()
4122 b1 = gen_hostop6(cstate, addr, mask, Q_DST, ll_proto, src_off, dst_off); in gen_hostop6()
4127 …bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for addresses other than 802.11… in gen_hostop6()
4131 …bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for addresses other than 802.11… in gen_hostop6()
4135 …bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for addresses other than 802.11… in gen_hostop6()
4139 …bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for addresses other than 802.11… in gen_hostop6()
4143 bpf_error(cstate, "'ra' is not a valid qualifier for addresses other than 802.11 MAC addresses"); in gen_hostop6()
4147 bpf_error(cstate, "'ta' is not a valid qualifier for addresses other than 802.11 MAC addresses"); in gen_hostop6()
4157 b1 = gen_mcmp(cstate, OR_LINKPL, offset + 12, BPF_W, ntohl(a[3]), ntohl(m[3])); in gen_hostop6()
4158 b0 = gen_mcmp(cstate, OR_LINKPL, offset + 8, BPF_W, ntohl(a[2]), ntohl(m[2])); in gen_hostop6()
4160 b0 = gen_mcmp(cstate, OR_LINKPL, offset + 4, BPF_W, ntohl(a[1]), ntohl(m[1])); in gen_hostop6()
4162 b0 = gen_mcmp(cstate, OR_LINKPL, offset + 0, BPF_W, ntohl(a[0]), ntohl(m[0])); in gen_hostop6()
4164 b0 = gen_linktype(cstate, ll_proto); in gen_hostop6()
4171 gen_ehostop(compiler_state_t *cstate, const u_char *eaddr, int dir) in gen_ehostop() argument
4177 return gen_bcmp(cstate, OR_LINKHDR, 6, 6, eaddr); in gen_ehostop()
4180 return gen_bcmp(cstate, OR_LINKHDR, 0, 6, eaddr); in gen_ehostop()
4183 b0 = gen_ehostop(cstate, eaddr, Q_SRC); in gen_ehostop()
4184 b1 = gen_ehostop(cstate, eaddr, Q_DST); in gen_ehostop()
4190 b0 = gen_ehostop(cstate, eaddr, Q_SRC); in gen_ehostop()
4191 b1 = gen_ehostop(cstate, eaddr, Q_DST); in gen_ehostop()
4196 bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11 with 802.11 headers"); in gen_ehostop()
4200 bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11 with 802.11 headers"); in gen_ehostop()
4204 bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11 with 802.11 headers"); in gen_ehostop()
4208 bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11 with 802.11 headers"); in gen_ehostop()
4212 bpf_error(cstate, "'ra' is only supported on 802.11 with 802.11 headers"); in gen_ehostop()
4216 bpf_error(cstate, "'ta' is only supported on 802.11 with 802.11 headers"); in gen_ehostop()
4227 gen_fhostop(compiler_state_t *cstate, const u_char *eaddr, int dir) in gen_fhostop() argument
4233 return gen_bcmp(cstate, OR_LINKHDR, 6 + 1 + cstate->pcap_fddipad, 6, eaddr); in gen_fhostop()
4236 return gen_bcmp(cstate, OR_LINKHDR, 0 + 1 + cstate->pcap_fddipad, 6, eaddr); in gen_fhostop()
4239 b0 = gen_fhostop(cstate, eaddr, Q_SRC); in gen_fhostop()
4240 b1 = gen_fhostop(cstate, eaddr, Q_DST); in gen_fhostop()
4246 b0 = gen_fhostop(cstate, eaddr, Q_SRC); in gen_fhostop()
4247 b1 = gen_fhostop(cstate, eaddr, Q_DST); in gen_fhostop()
4252 bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11"); in gen_fhostop()
4256 bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11"); in gen_fhostop()
4260 bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11"); in gen_fhostop()
4264 bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11"); in gen_fhostop()
4268 bpf_error(cstate, "'ra' is only supported on 802.11"); in gen_fhostop()
4272 bpf_error(cstate, "'ta' is only supported on 802.11"); in gen_fhostop()
4283 gen_thostop(compiler_state_t *cstate, const u_char *eaddr, int dir) in gen_thostop() argument
4289 return gen_bcmp(cstate, OR_LINKHDR, 8, 6, eaddr); in gen_thostop()
4292 return gen_bcmp(cstate, OR_LINKHDR, 2, 6, eaddr); in gen_thostop()
4295 b0 = gen_thostop(cstate, eaddr, Q_SRC); in gen_thostop()
4296 b1 = gen_thostop(cstate, eaddr, Q_DST); in gen_thostop()
4302 b0 = gen_thostop(cstate, eaddr, Q_SRC); in gen_thostop()
4303 b1 = gen_thostop(cstate, eaddr, Q_DST); in gen_thostop()
4308 bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11"); in gen_thostop()
4312 bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11"); in gen_thostop()
4316 bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11"); in gen_thostop()
4320 bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11"); in gen_thostop()
4324 bpf_error(cstate, "'ra' is only supported on 802.11"); in gen_thostop()
4328 bpf_error(cstate, "'ta' is only supported on 802.11"); in gen_thostop()
4340 gen_wlanhostop(compiler_state_t *cstate, const u_char *eaddr, int dir) in gen_wlanhostop() argument
4352 cstate->no_optimize = 1; in gen_wlanhostop()
4382 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_wlanhostop()
4383 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4390 b0 = gen_bcmp(cstate, OR_LINKHDR, 24, 6, eaddr); in gen_wlanhostop()
4397 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_wlanhostop()
4398 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4406 b1 = gen_bcmp(cstate, OR_LINKHDR, 16, 6, eaddr); in gen_wlanhostop()
4420 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_wlanhostop()
4421 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4429 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_wlanhostop()
4430 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4438 b1 = gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr); in gen_wlanhostop()
4452 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4453 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4467 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4468 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4476 b1 = gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr); in gen_wlanhostop()
4494 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4495 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4529 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_wlanhostop()
4530 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4537 b0 = gen_bcmp(cstate, OR_LINKHDR, 16, 6, eaddr); in gen_wlanhostop()
4544 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_wlanhostop()
4545 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4553 b1 = gen_bcmp(cstate, OR_LINKHDR, 4, 6, eaddr); in gen_wlanhostop()
4566 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4567 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4581 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4582 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4590 b1 = gen_bcmp(cstate, OR_LINKHDR, 4, 6, eaddr); in gen_wlanhostop()
4608 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4609 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4622 b0 = gen_wlanhostop(cstate, eaddr, Q_SRC); in gen_wlanhostop()
4623 b1 = gen_wlanhostop(cstate, eaddr, Q_DST); in gen_wlanhostop()
4629 b0 = gen_wlanhostop(cstate, eaddr, Q_SRC); in gen_wlanhostop()
4630 b1 = gen_wlanhostop(cstate, eaddr, Q_DST); in gen_wlanhostop()
4638 return (gen_bcmp(cstate, OR_LINKHDR, 4, 6, eaddr)); in gen_wlanhostop()
4644 b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_TYPE_CTL, in gen_wlanhostop()
4647 b1 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_SUBTYPE_CTS, in gen_wlanhostop()
4650 b2 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_SUBTYPE_ACK, in gen_wlanhostop()
4655 b1 = gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr); in gen_wlanhostop()
4663 b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_TYPE_CTL, in gen_wlanhostop()
4666 b1 = gen_bcmp(cstate, OR_LINKHDR, 16, 6, eaddr); in gen_wlanhostop()
4677 b0 = gen_mcmp(cstate, OR_LINKHDR, 1, BPF_B, in gen_wlanhostop()
4679 b1 = gen_bcmp(cstate, OR_LINKHDR, 24, 6, eaddr); in gen_wlanhostop()
4694 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4695 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4702 b0 = gen_bcmp(cstate, OR_LINKHDR, 4, 6, eaddr); in gen_wlanhostop()
4719 b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_TYPE_CTL, in gen_wlanhostop()
4722 b1 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_SUBTYPE_CTS, in gen_wlanhostop()
4725 b2 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_SUBTYPE_ACK, in gen_wlanhostop()
4736 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4737 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4750 b1 = gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr); in gen_wlanhostop()
4764 gen_ipfchostop(compiler_state_t *cstate, const u_char *eaddr, int dir) in gen_ipfchostop() argument
4770 return gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr); in gen_ipfchostop()
4773 return gen_bcmp(cstate, OR_LINKHDR, 2, 6, eaddr); in gen_ipfchostop()
4776 b0 = gen_ipfchostop(cstate, eaddr, Q_SRC); in gen_ipfchostop()
4777 b1 = gen_ipfchostop(cstate, eaddr, Q_DST); in gen_ipfchostop()
4783 b0 = gen_ipfchostop(cstate, eaddr, Q_SRC); in gen_ipfchostop()
4784 b1 = gen_ipfchostop(cstate, eaddr, Q_DST); in gen_ipfchostop()
4789 bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11"); in gen_ipfchostop()
4793 bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11"); in gen_ipfchostop()
4797 bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11"); in gen_ipfchostop()
4801 bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11"); in gen_ipfchostop()
4805 bpf_error(cstate, "'ra' is only supported on 802.11"); in gen_ipfchostop()
4809 bpf_error(cstate, "'ta' is only supported on 802.11"); in gen_ipfchostop()
4835 gen_dnhostop(compiler_state_t *cstate, bpf_u_int32 addr, int dir) in gen_dnhostop() argument
4855 b0 = gen_dnhostop(cstate, addr, Q_SRC); in gen_dnhostop()
4856 b1 = gen_dnhostop(cstate, addr, Q_DST); in gen_dnhostop()
4863 b0 = gen_dnhostop(cstate, addr, Q_SRC); in gen_dnhostop()
4864 b1 = gen_dnhostop(cstate, addr, Q_DST); in gen_dnhostop()
4869 …bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for addresses other than 802.11… in gen_dnhostop()
4873 …bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for addresses other than 802.11… in gen_dnhostop()
4877 …bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for addresses other than 802.11… in gen_dnhostop()
4881 …bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for addresses other than 802.11… in gen_dnhostop()
4885 bpf_error(cstate, "'ra' is not a valid qualifier for addresses other than 802.11 MAC addresses"); in gen_dnhostop()
4889 bpf_error(cstate, "'ta' is not a valid qualifier for addresses other than 802.11 MAC addresses"); in gen_dnhostop()
4896 b0 = gen_linktype(cstate, ETHERTYPE_DN); in gen_dnhostop()
4898 tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_H, in gen_dnhostop()
4900 b1 = gen_cmp(cstate, OR_LINKPL, 2 + 1 + offset_lh, in gen_dnhostop()
4904 tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_B, (bpf_u_int32)0x06, in gen_dnhostop()
4906 b2 = gen_cmp(cstate, OR_LINKPL, 2 + offset_lh, BPF_H, in gen_dnhostop()
4911 tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_H, in gen_dnhostop()
4913 b2 = gen_cmp(cstate, OR_LINKPL, 2 + 1 + offset_sh, BPF_H, in gen_dnhostop()
4918 tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_B, (bpf_u_int32)0x02, in gen_dnhostop()
4920 b2 = gen_cmp(cstate, OR_LINKPL, 2 + offset_sh, BPF_H, in gen_dnhostop()
4936 gen_mpls_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto) in gen_mpls_linktype() argument
4944 b0 = gen_mcmp(cstate, OR_LINKPL, (u_int)-2, BPF_B, 0x01, 0x01); in gen_mpls_linktype()
4946 b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_B, 0x40, 0xf0); in gen_mpls_linktype()
4952 b0 = gen_mcmp(cstate, OR_LINKPL, (u_int)-2, BPF_B, 0x01, 0x01); in gen_mpls_linktype()
4954 b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_B, 0x60, 0xf0); in gen_mpls_linktype()
4960 bpf_error(cstate, "unsupported protocol over mpls"); in gen_mpls_linktype()
4966 gen_host(compiler_state_t *cstate, bpf_u_int32 addr, bpf_u_int32 mask, in gen_host() argument
4980 b0 = gen_host(cstate, addr, mask, Q_IP, dir, type); in gen_host()
4985 if (cstate->label_stack_depth == 0) { in gen_host()
4986 b1 = gen_host(cstate, addr, mask, Q_ARP, dir, type); in gen_host()
4988 b0 = gen_host(cstate, addr, mask, Q_RARP, dir, type); in gen_host()
4994 bpf_error(cstate, "link-layer modifier applied to %s", typestr); in gen_host()
4997 return gen_hostop(cstate, addr, mask, dir, ETHERTYPE_IP, 12, 16); in gen_host()
5000 return gen_hostop(cstate, addr, mask, dir, ETHERTYPE_REVARP, 14, 24); in gen_host()
5003 return gen_hostop(cstate, addr, mask, dir, ETHERTYPE_ARP, 14, 24); in gen_host()
5006 bpf_error(cstate, "'sctp' modifier applied to %s", typestr); in gen_host()
5009 bpf_error(cstate, "'tcp' modifier applied to %s", typestr); in gen_host()
5012 bpf_error(cstate, "'udp' modifier applied to %s", typestr); in gen_host()
5015 bpf_error(cstate, "'icmp' modifier applied to %s", typestr); in gen_host()
5018 bpf_error(cstate, "'igmp' modifier applied to %s", typestr); in gen_host()
5021 bpf_error(cstate, "'igrp' modifier applied to %s", typestr); in gen_host()
5024 bpf_error(cstate, "AppleTalk host filtering not implemented"); in gen_host()
5027 return gen_dnhostop(cstate, addr, dir); in gen_host()
5030 bpf_error(cstate, "LAT host filtering not implemented"); in gen_host()
5033 bpf_error(cstate, "SCA host filtering not implemented"); in gen_host()
5036 bpf_error(cstate, "MOPRC host filtering not implemented"); in gen_host()
5039 bpf_error(cstate, "MOPDL host filtering not implemented"); in gen_host()
5042 bpf_error(cstate, "'ip6' modifier applied to ip host"); in gen_host()
5045 bpf_error(cstate, "'icmp6' modifier applied to %s", typestr); in gen_host()
5048 bpf_error(cstate, "'ah' modifier applied to %s", typestr); in gen_host()
5051 bpf_error(cstate, "'esp' modifier applied to %s", typestr); in gen_host()
5054 bpf_error(cstate, "'pim' modifier applied to %s", typestr); in gen_host()
5057 bpf_error(cstate, "'vrrp' modifier applied to %s", typestr); in gen_host()
5060 bpf_error(cstate, "AARP host filtering not implemented"); in gen_host()
5063 bpf_error(cstate, "ISO host filtering not implemented"); in gen_host()
5066 bpf_error(cstate, "'esis' modifier applied to %s", typestr); in gen_host()
5069 bpf_error(cstate, "'isis' modifier applied to %s", typestr); in gen_host()
5072 bpf_error(cstate, "'clnp' modifier applied to %s", typestr); in gen_host()
5075 bpf_error(cstate, "'stp' modifier applied to %s", typestr); in gen_host()
5078 bpf_error(cstate, "IPX host filtering not implemented"); in gen_host()
5081 bpf_error(cstate, "'netbeui' modifier applied to %s", typestr); in gen_host()
5084 bpf_error(cstate, "'l1' modifier applied to %s", typestr); in gen_host()
5087 bpf_error(cstate, "'l2' modifier applied to %s", typestr); in gen_host()
5090 bpf_error(cstate, "'iih' modifier applied to %s", typestr); in gen_host()
5093 bpf_error(cstate, "'snp' modifier applied to %s", typestr); in gen_host()
5096 bpf_error(cstate, "'csnp' modifier applied to %s", typestr); in gen_host()
5099 bpf_error(cstate, "'psnp' modifier applied to %s", typestr); in gen_host()
5102 bpf_error(cstate, "'lsp' modifier applied to %s", typestr); in gen_host()
5105 bpf_error(cstate, "'radio' modifier applied to %s", typestr); in gen_host()
5108 bpf_error(cstate, "'carp' modifier applied to %s", typestr); in gen_host()
5118 gen_host6(compiler_state_t *cstate, struct in6_addr *addr, in gen_host6() argument
5131 return gen_host6(cstate, addr, mask, Q_IPV6, dir, type); in gen_host6()
5134 bpf_error(cstate, "link-layer modifier applied to ip6 %s", typestr); in gen_host6()
5137 bpf_error(cstate, "'ip' modifier applied to ip6 %s", typestr); in gen_host6()
5140 bpf_error(cstate, "'rarp' modifier applied to ip6 %s", typestr); in gen_host6()
5143 bpf_error(cstate, "'arp' modifier applied to ip6 %s", typestr); in gen_host6()
5146 bpf_error(cstate, "'sctp' modifier applied to ip6 %s", typestr); in gen_host6()
5149 bpf_error(cstate, "'tcp' modifier applied to ip6 %s", typestr); in gen_host6()
5152 bpf_error(cstate, "'udp' modifier applied to ip6 %s", typestr); in gen_host6()
5155 bpf_error(cstate, "'icmp' modifier applied to ip6 %s", typestr); in gen_host6()
5158 bpf_error(cstate, "'igmp' modifier applied to ip6 %s", typestr); in gen_host6()
5161 bpf_error(cstate, "'igrp' modifier applied to ip6 %s", typestr); in gen_host6()
5164 bpf_error(cstate, "AppleTalk modifier applied to ip6 %s", typestr); in gen_host6()
5167 bpf_error(cstate, "'decnet' modifier applied to ip6 %s", typestr); in gen_host6()
5170 bpf_error(cstate, "'lat' modifier applied to ip6 %s", typestr); in gen_host6()
5173 bpf_error(cstate, "'sca' modifier applied to ip6 %s", typestr); in gen_host6()
5176 bpf_error(cstate, "'moprc' modifier applied to ip6 %s", typestr); in gen_host6()
5179 bpf_error(cstate, "'mopdl' modifier applied to ip6 %s", typestr); in gen_host6()
5182 return gen_hostop6(cstate, addr, mask, dir, ETHERTYPE_IPV6, 8, 24); in gen_host6()
5185 bpf_error(cstate, "'icmp6' modifier applied to ip6 %s", typestr); in gen_host6()
5188 bpf_error(cstate, "'ah' modifier applied to ip6 %s", typestr); in gen_host6()
5191 bpf_error(cstate, "'esp' modifier applied to ip6 %s", typestr); in gen_host6()
5194 bpf_error(cstate, "'pim' modifier applied to ip6 %s", typestr); in gen_host6()
5197 bpf_error(cstate, "'vrrp' modifier applied to ip6 %s", typestr); in gen_host6()
5200 bpf_error(cstate, "'aarp' modifier applied to ip6 %s", typestr); in gen_host6()
5203 bpf_error(cstate, "'iso' modifier applied to ip6 %s", typestr); in gen_host6()
5206 bpf_error(cstate, "'esis' modifier applied to ip6 %s", typestr); in gen_host6()
5209 bpf_error(cstate, "'isis' modifier applied to ip6 %s", typestr); in gen_host6()
5212 bpf_error(cstate, "'clnp' modifier applied to ip6 %s", typestr); in gen_host6()
5215 bpf_error(cstate, "'stp' modifier applied to ip6 %s", typestr); in gen_host6()
5218 bpf_error(cstate, "'ipx' modifier applied to ip6 %s", typestr); in gen_host6()
5221 bpf_error(cstate, "'netbeui' modifier applied to ip6 %s", typestr); in gen_host6()
5224 bpf_error(cstate, "'l1' modifier applied to ip6 %s", typestr); in gen_host6()
5227 bpf_error(cstate, "'l2' modifier applied to ip6 %s", typestr); in gen_host6()
5230 bpf_error(cstate, "'iih' modifier applied to ip6 %s", typestr); in gen_host6()
5233 bpf_error(cstate, "'snp' modifier applied to ip6 %s", typestr); in gen_host6()
5236 bpf_error(cstate, "'csnp' modifier applied to ip6 %s", typestr); in gen_host6()
5239 bpf_error(cstate, "'psnp' modifier applied to ip6 %s", typestr); in gen_host6()
5242 bpf_error(cstate, "'lsp' modifier applied to ip6 %s", typestr); in gen_host6()
5245 bpf_error(cstate, "'radio' modifier applied to ip6 %s", typestr); in gen_host6()
5248 bpf_error(cstate, "'carp' modifier applied to ip6 %s", typestr); in gen_host6()
5259 gen_gateway(compiler_state_t *cstate, const u_char *eaddr, in gen_gateway() argument
5267 bpf_error(cstate, "direction applied to 'gateway'"); in gen_gateway()
5274 switch (cstate->linktype) { in gen_gateway()
5278 b1 = gen_prevlinkhdr_check(cstate); in gen_gateway()
5279 b0 = gen_ehostop(cstate, eaddr, Q_OR); in gen_gateway()
5284 b0 = gen_fhostop(cstate, eaddr, Q_OR); in gen_gateway()
5287 b0 = gen_thostop(cstate, eaddr, Q_OR); in gen_gateway()
5294 b0 = gen_wlanhostop(cstate, eaddr, Q_OR); in gen_gateway()
5302 bpf_error(cstate, in gen_gateway()
5305 b0 = gen_ipfchostop(cstate, eaddr, Q_OR); in gen_gateway()
5308 bpf_error(cstate, in gen_gateway()
5325 tmp = gen_host(cstate, in gen_gateway()
5358 bpf_error(cstate, "illegal modifier of 'gateway'"); in gen_gateway()
5364 gen_proto_abbrev_internal(compiler_state_t *cstate, int proto) in gen_proto_abbrev_internal() argument
5372 b1 = gen_proto(cstate, IPPROTO_SCTP, Q_DEFAULT, Q_DEFAULT); in gen_proto_abbrev_internal()
5376 b1 = gen_proto(cstate, IPPROTO_TCP, Q_DEFAULT, Q_DEFAULT); in gen_proto_abbrev_internal()
5380 b1 = gen_proto(cstate, IPPROTO_UDP, Q_DEFAULT, Q_DEFAULT); in gen_proto_abbrev_internal()
5384 b1 = gen_proto(cstate, IPPROTO_ICMP, Q_IP, Q_DEFAULT); in gen_proto_abbrev_internal()
5392 b1 = gen_proto(cstate, IPPROTO_IGMP, Q_IP, Q_DEFAULT); in gen_proto_abbrev_internal()
5399 b1 = gen_proto(cstate, IPPROTO_IGRP, Q_IP, Q_DEFAULT); in gen_proto_abbrev_internal()
5407 b1 = gen_proto(cstate, IPPROTO_PIM, Q_DEFAULT, Q_DEFAULT); in gen_proto_abbrev_internal()
5415 b1 = gen_proto(cstate, IPPROTO_VRRP, Q_IP, Q_DEFAULT); in gen_proto_abbrev_internal()
5423 b1 = gen_proto(cstate, IPPROTO_CARP, Q_IP, Q_DEFAULT); in gen_proto_abbrev_internal()
5427 b1 = gen_linktype(cstate, ETHERTYPE_IP); in gen_proto_abbrev_internal()
5431 b1 = gen_linktype(cstate, ETHERTYPE_ARP); in gen_proto_abbrev_internal()
5435 b1 = gen_linktype(cstate, ETHERTYPE_REVARP); in gen_proto_abbrev_internal()
5439 bpf_error(cstate, "link layer applied in wrong context"); in gen_proto_abbrev_internal()
5442 b1 = gen_linktype(cstate, ETHERTYPE_ATALK); in gen_proto_abbrev_internal()
5446 b1 = gen_linktype(cstate, ETHERTYPE_AARP); in gen_proto_abbrev_internal()
5450 b1 = gen_linktype(cstate, ETHERTYPE_DN); in gen_proto_abbrev_internal()
5454 b1 = gen_linktype(cstate, ETHERTYPE_SCA); in gen_proto_abbrev_internal()
5458 b1 = gen_linktype(cstate, ETHERTYPE_LAT); in gen_proto_abbrev_internal()
5462 b1 = gen_linktype(cstate, ETHERTYPE_MOPDL); in gen_proto_abbrev_internal()
5466 b1 = gen_linktype(cstate, ETHERTYPE_MOPRC); in gen_proto_abbrev_internal()
5470 b1 = gen_linktype(cstate, ETHERTYPE_IPV6); in gen_proto_abbrev_internal()
5477 b1 = gen_proto(cstate, IPPROTO_ICMPV6, Q_IPV6, Q_DEFAULT); in gen_proto_abbrev_internal()
5484 b1 = gen_proto(cstate, IPPROTO_AH, Q_DEFAULT, Q_DEFAULT); in gen_proto_abbrev_internal()
5491 b1 = gen_proto(cstate, IPPROTO_ESP, Q_DEFAULT, Q_DEFAULT); in gen_proto_abbrev_internal()
5495 b1 = gen_linktype(cstate, LLCSAP_ISONS); in gen_proto_abbrev_internal()
5499 b1 = gen_proto(cstate, ISO9542_ESIS, Q_ISO, Q_DEFAULT); in gen_proto_abbrev_internal()
5503 b1 = gen_proto(cstate, ISO10589_ISIS, Q_ISO, Q_DEFAULT); in gen_proto_abbrev_internal()
5507 b0 = gen_proto(cstate, ISIS_L1_LAN_IIH, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5508 b1 = gen_proto(cstate, ISIS_PTP_IIH, Q_ISIS, Q_DEFAULT); /* FIXME extract the circuit-type bits */ in gen_proto_abbrev_internal()
5510 b0 = gen_proto(cstate, ISIS_L1_LSP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5512 b0 = gen_proto(cstate, ISIS_L1_CSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5514 b0 = gen_proto(cstate, ISIS_L1_PSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5519 b0 = gen_proto(cstate, ISIS_L2_LAN_IIH, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5520 b1 = gen_proto(cstate, ISIS_PTP_IIH, Q_ISIS, Q_DEFAULT); /* FIXME extract the circuit-type bits */ in gen_proto_abbrev_internal()
5522 b0 = gen_proto(cstate, ISIS_L2_LSP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5524 b0 = gen_proto(cstate, ISIS_L2_CSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5526 b0 = gen_proto(cstate, ISIS_L2_PSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5531 b0 = gen_proto(cstate, ISIS_L1_LAN_IIH, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5532 b1 = gen_proto(cstate, ISIS_L2_LAN_IIH, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5534 b0 = gen_proto(cstate, ISIS_PTP_IIH, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5539 b0 = gen_proto(cstate, ISIS_L1_LSP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5540 b1 = gen_proto(cstate, ISIS_L2_LSP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5545 b0 = gen_proto(cstate, ISIS_L1_CSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5546 b1 = gen_proto(cstate, ISIS_L2_CSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5548 b0 = gen_proto(cstate, ISIS_L1_PSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5550 b0 = gen_proto(cstate, ISIS_L2_PSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5555 b0 = gen_proto(cstate, ISIS_L1_CSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5556 b1 = gen_proto(cstate, ISIS_L2_CSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5561 b0 = gen_proto(cstate, ISIS_L1_PSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5562 b1 = gen_proto(cstate, ISIS_L2_PSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev_internal()
5567 b1 = gen_proto(cstate, ISO8473_CLNP, Q_ISO, Q_DEFAULT); in gen_proto_abbrev_internal()
5571 b1 = gen_linktype(cstate, LLCSAP_8021D); in gen_proto_abbrev_internal()
5575 b1 = gen_linktype(cstate, LLCSAP_IPX); in gen_proto_abbrev_internal()
5579 b1 = gen_linktype(cstate, LLCSAP_NETBEUI); in gen_proto_abbrev_internal()
5583 bpf_error(cstate, "'radio' is not a valid protocol type"); in gen_proto_abbrev_internal()
5592 gen_proto_abbrev(compiler_state_t *cstate, int proto) in gen_proto_abbrev() argument
5598 if (setjmp(cstate->top_ctx)) in gen_proto_abbrev()
5601 return gen_proto_abbrev_internal(cstate, proto); in gen_proto_abbrev()
5605 gen_ipfrag(compiler_state_t *cstate) in gen_ipfrag() argument
5611 s = gen_load_a(cstate, OR_LINKPL, 6, BPF_H); in gen_ipfrag()
5612 b = new_block(cstate, JMP(BPF_JSET)); in gen_ipfrag()
5630 gen_portatom(compiler_state_t *cstate, int off, bpf_u_int32 v) in gen_portatom() argument
5632 return gen_cmp(cstate, OR_TRAN_IPV4, off, BPF_H, v); in gen_portatom()
5636 gen_portatom6(compiler_state_t *cstate, int off, bpf_u_int32 v) in gen_portatom6() argument
5638 return gen_cmp(cstate, OR_TRAN_IPV6, off, BPF_H, v); in gen_portatom6()
5642 gen_portop(compiler_state_t *cstate, u_int port, u_int proto, int dir) in gen_portop() argument
5647 tmp = gen_cmp(cstate, OR_LINKPL, 9, BPF_B, proto); in gen_portop()
5648 b0 = gen_ipfrag(cstate); in gen_portop()
5653 b1 = gen_portatom(cstate, 0, port); in gen_portop()
5657 b1 = gen_portatom(cstate, 2, port); in gen_portop()
5661 tmp = gen_portatom(cstate, 0, port); in gen_portop()
5662 b1 = gen_portatom(cstate, 2, port); in gen_portop()
5668 tmp = gen_portatom(cstate, 0, port); in gen_portop()
5669 b1 = gen_portatom(cstate, 2, port); in gen_portop()
5674 bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for ports"); in gen_portop()
5678 bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for ports"); in gen_portop()
5682 bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for ports"); in gen_portop()
5686 bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for ports"); in gen_portop()
5690 bpf_error(cstate, "'ra' is not a valid qualifier for ports"); in gen_portop()
5694 bpf_error(cstate, "'ta' is not a valid qualifier for ports"); in gen_portop()
5707 gen_port(compiler_state_t *cstate, u_int port, int ip_proto, int dir) in gen_port() argument
5728 b0 = gen_linktype(cstate, ETHERTYPE_IP); in gen_port()
5734 b1 = gen_portop(cstate, port, (u_int)ip_proto, dir); in gen_port()
5738 tmp = gen_portop(cstate, port, IPPROTO_TCP, dir); in gen_port()
5739 b1 = gen_portop(cstate, port, IPPROTO_UDP, dir); in gen_port()
5741 tmp = gen_portop(cstate, port, IPPROTO_SCTP, dir); in gen_port()
5753 gen_portop6(compiler_state_t *cstate, u_int port, u_int proto, int dir) in gen_portop6() argument
5759 b0 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, proto); in gen_portop6()
5763 b1 = gen_portatom6(cstate, 0, port); in gen_portop6()
5767 b1 = gen_portatom6(cstate, 2, port); in gen_portop6()
5771 tmp = gen_portatom6(cstate, 0, port); in gen_portop6()
5772 b1 = gen_portatom6(cstate, 2, port); in gen_portop6()
5778 tmp = gen_portatom6(cstate, 0, port); in gen_portop6()
5779 b1 = gen_portatom6(cstate, 2, port); in gen_portop6()
5792 gen_port6(compiler_state_t *cstate, u_int port, int ip_proto, int dir) in gen_port6() argument
5797 b0 = gen_linktype(cstate, ETHERTYPE_IPV6); in gen_port6()
5803 b1 = gen_portop6(cstate, port, (u_int)ip_proto, dir); in gen_port6()
5807 tmp = gen_portop6(cstate, port, IPPROTO_TCP, dir); in gen_port6()
5808 b1 = gen_portop6(cstate, port, IPPROTO_UDP, dir); in gen_port6()
5810 tmp = gen_portop6(cstate, port, IPPROTO_SCTP, dir); in gen_port6()
5823 gen_portrangeatom(compiler_state_t *cstate, u_int off, bpf_u_int32 v1, in gen_portrangeatom() argument
5839 b1 = gen_cmp_ge(cstate, OR_TRAN_IPV4, off, BPF_H, v1); in gen_portrangeatom()
5840 b2 = gen_cmp_le(cstate, OR_TRAN_IPV4, off, BPF_H, v2); in gen_portrangeatom()
5848 gen_portrangeop(compiler_state_t *cstate, u_int port1, u_int port2, in gen_portrangeop() argument
5854 tmp = gen_cmp(cstate, OR_LINKPL, 9, BPF_B, proto); in gen_portrangeop()
5855 b0 = gen_ipfrag(cstate); in gen_portrangeop()
5860 b1 = gen_portrangeatom(cstate, 0, port1, port2); in gen_portrangeop()
5864 b1 = gen_portrangeatom(cstate, 2, port1, port2); in gen_portrangeop()
5868 tmp = gen_portrangeatom(cstate, 0, port1, port2); in gen_portrangeop()
5869 b1 = gen_portrangeatom(cstate, 2, port1, port2); in gen_portrangeop()
5875 tmp = gen_portrangeatom(cstate, 0, port1, port2); in gen_portrangeop()
5876 b1 = gen_portrangeatom(cstate, 2, port1, port2); in gen_portrangeop()
5881 bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for port ranges"); in gen_portrangeop()
5885 bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for port ranges"); in gen_portrangeop()
5889 bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for port ranges"); in gen_portrangeop()
5893 bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for port ranges"); in gen_portrangeop()
5897 bpf_error(cstate, "'ra' is not a valid qualifier for port ranges"); in gen_portrangeop()
5901 bpf_error(cstate, "'ta' is not a valid qualifier for port ranges"); in gen_portrangeop()
5914 gen_portrange(compiler_state_t *cstate, u_int port1, u_int port2, int ip_proto, in gen_portrange() argument
5920 b0 = gen_linktype(cstate, ETHERTYPE_IP); in gen_portrange()
5926 b1 = gen_portrangeop(cstate, port1, port2, (bpf_u_int32)ip_proto, in gen_portrange()
5931 tmp = gen_portrangeop(cstate, port1, port2, IPPROTO_TCP, dir); in gen_portrange()
5932 b1 = gen_portrangeop(cstate, port1, port2, IPPROTO_UDP, dir); in gen_portrange()
5934 tmp = gen_portrangeop(cstate, port1, port2, IPPROTO_SCTP, dir); in gen_portrange()
5946 gen_portrangeatom6(compiler_state_t *cstate, u_int off, bpf_u_int32 v1, in gen_portrangeatom6() argument
5962 b1 = gen_cmp_ge(cstate, OR_TRAN_IPV6, off, BPF_H, v1); in gen_portrangeatom6()
5963 b2 = gen_cmp_le(cstate, OR_TRAN_IPV6, off, BPF_H, v2); in gen_portrangeatom6()
5971 gen_portrangeop6(compiler_state_t *cstate, u_int port1, u_int port2, in gen_portrangeop6() argument
5978 b0 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, proto); in gen_portrangeop6()
5982 b1 = gen_portrangeatom6(cstate, 0, port1, port2); in gen_portrangeop6()
5986 b1 = gen_portrangeatom6(cstate, 2, port1, port2); in gen_portrangeop6()
5990 tmp = gen_portrangeatom6(cstate, 0, port1, port2); in gen_portrangeop6()
5991 b1 = gen_portrangeatom6(cstate, 2, port1, port2); in gen_portrangeop6()
5997 tmp = gen_portrangeatom6(cstate, 0, port1, port2); in gen_portrangeop6()
5998 b1 = gen_portrangeatom6(cstate, 2, port1, port2); in gen_portrangeop6()
6011 gen_portrange6(compiler_state_t *cstate, u_int port1, u_int port2, int ip_proto, in gen_portrange6() argument
6017 b0 = gen_linktype(cstate, ETHERTYPE_IPV6); in gen_portrange6()
6023 b1 = gen_portrangeop6(cstate, port1, port2, (bpf_u_int32)ip_proto, in gen_portrange6()
6028 tmp = gen_portrangeop6(cstate, port1, port2, IPPROTO_TCP, dir); in gen_portrange6()
6029 b1 = gen_portrangeop6(cstate, port1, port2, IPPROTO_UDP, dir); in gen_portrange6()
6031 tmp = gen_portrangeop6(cstate, port1, port2, IPPROTO_SCTP, dir); in gen_portrange6()
6043 lookup_proto(compiler_state_t *cstate, const char *name, int proto) in lookup_proto() argument
6054 bpf_error(cstate, "unknown ip proto '%s'", name); in lookup_proto()
6063 bpf_error(cstate, "unknown ether proto '%s'", name); in lookup_proto()
6075 bpf_error(cstate, "unknown osi proto '%s'", name); in lookup_proto()
6087 gen_protochain(compiler_state_t *cstate, bpf_u_int32 v, int proto) in gen_protochain() argument
6094 int reg2 = alloc_reg(cstate); in gen_protochain()
6104 b0 = gen_protochain(cstate, v, Q_IP); in gen_protochain()
6105 b = gen_protochain(cstate, v, Q_IPV6); in gen_protochain()
6109 bpf_error(cstate, "bad protocol applied for 'protochain'"); in gen_protochain()
6124 if (cstate->off_linkpl.is_variable) in gen_protochain()
6125 bpf_error(cstate, "'protochain' not supported with variable length headers"); in gen_protochain()
6138 cstate->no_optimize = 1; in gen_protochain()
6146 s[i] = new_stmt(cstate, 0); /*dummy*/ in gen_protochain()
6151 b0 = gen_linktype(cstate, ETHERTYPE_IP); in gen_protochain()
6154 s[i] = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_B); in gen_protochain()
6155 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 9; in gen_protochain()
6158 s[i] = new_stmt(cstate, BPF_LDX|BPF_MSH|BPF_B); in gen_protochain()
6159 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_protochain()
6164 b0 = gen_linktype(cstate, ETHERTYPE_IPV6); in gen_protochain()
6167 s[i] = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_B); in gen_protochain()
6168 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 6; in gen_protochain()
6171 s[i] = new_stmt(cstate, BPF_LDX|BPF_IMM); in gen_protochain()
6177 bpf_error(cstate, "unsupported proto to gen_protochain"); in gen_protochain()
6183 s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
6194 s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
6207 s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
6214 s[i - 1]->s.jf = s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
6220 s[i - 1]->s.jf = s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
6226 s[i - 1]->s.jf = s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
6243 s[i] = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_protochain()
6244 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_protochain()
6247 s[i] = new_stmt(cstate, BPF_ST); in gen_protochain()
6251 s[i] = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_protochain()
6252 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 1; in gen_protochain()
6255 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_protochain()
6259 s[i] = new_stmt(cstate, BPF_ALU|BPF_MUL|BPF_K); in gen_protochain()
6263 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X); in gen_protochain()
6267 s[i] = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_protochain()
6270 s[i] = new_stmt(cstate, BPF_LD|BPF_MEM); in gen_protochain()
6275 s[i] = new_stmt(cstate, BPF_JMP|BPF_JA); in gen_protochain()
6285 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_protochain()
6294 s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
6309 s[i - 1]->s.jt = s[i] = new_stmt(cstate, BPF_MISC|BPF_TXA); in gen_protochain()
6312 s[i] = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_protochain()
6313 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_protochain()
6316 s[i] = new_stmt(cstate, BPF_ST); in gen_protochain()
6320 s[i - 1]->s.jt = s[i] = new_stmt(cstate, BPF_MISC|BPF_TXA); in gen_protochain()
6323 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_protochain()
6327 s[i] = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_protochain()
6330 s[i] = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_protochain()
6331 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_protochain()
6334 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_protochain()
6338 s[i] = new_stmt(cstate, BPF_ALU|BPF_MUL|BPF_K); in gen_protochain()
6342 s[i] = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_protochain()
6345 s[i] = new_stmt(cstate, BPF_LD|BPF_MEM); in gen_protochain()
6350 s[i] = new_stmt(cstate, BPF_JMP|BPF_JA); in gen_protochain()
6356 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_protochain()
6374 b = new_block(cstate, JMP(BPF_JEQ)); in gen_protochain()
6378 free_reg(cstate, reg2); in gen_protochain()
6386 gen_check_802_11_data_frame(compiler_state_t *cstate) in gen_check_802_11_data_frame() argument
6395 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_check_802_11_data_frame()
6396 b0 = new_block(cstate, JMP(BPF_JSET)); in gen_check_802_11_data_frame()
6400 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_check_802_11_data_frame()
6401 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_check_802_11_data_frame()
6421 gen_proto(compiler_state_t *cstate, bpf_u_int32 v, int proto, int dir) in gen_proto() argument
6427 bpf_error(cstate, "direction applied to 'proto'"); in gen_proto()
6431 b0 = gen_proto(cstate, v, Q_IP, dir); in gen_proto()
6432 b1 = gen_proto(cstate, v, Q_IPV6, dir); in gen_proto()
6437 return gen_linktype(cstate, v); in gen_proto()
6455 b0 = gen_linktype(cstate, ETHERTYPE_IP); in gen_proto()
6456 b1 = gen_cmp(cstate, OR_LINKPL, 9, BPF_B, v); in gen_proto()
6461 bpf_error(cstate, "arp does not encapsulate another protocol"); in gen_proto()
6465 bpf_error(cstate, "rarp does not encapsulate another protocol"); in gen_proto()
6469 bpf_error(cstate, "'sctp proto' is bogus"); in gen_proto()
6473 bpf_error(cstate, "'tcp proto' is bogus"); in gen_proto()
6477 bpf_error(cstate, "'udp proto' is bogus"); in gen_proto()
6481 bpf_error(cstate, "'icmp proto' is bogus"); in gen_proto()
6485 bpf_error(cstate, "'igmp proto' is bogus"); in gen_proto()
6489 bpf_error(cstate, "'igrp proto' is bogus"); in gen_proto()
6493 bpf_error(cstate, "AppleTalk encapsulation is not specifiable"); in gen_proto()
6497 bpf_error(cstate, "DECNET encapsulation is not specifiable"); in gen_proto()
6501 bpf_error(cstate, "LAT does not encapsulate another protocol"); in gen_proto()
6505 bpf_error(cstate, "SCA does not encapsulate another protocol"); in gen_proto()
6509 bpf_error(cstate, "MOPRC does not encapsulate another protocol"); in gen_proto()
6513 bpf_error(cstate, "MOPDL does not encapsulate another protocol"); in gen_proto()
6517 b0 = gen_linktype(cstate, ETHERTYPE_IPV6); in gen_proto()
6522 b2 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, IPPROTO_FRAGMENT); in gen_proto()
6523 b1 = gen_cmp(cstate, OR_LINKPL, 40, BPF_B, v); in gen_proto()
6525 b2 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, v); in gen_proto()
6531 bpf_error(cstate, "'icmp6 proto' is bogus"); in gen_proto()
6535 bpf_error(cstate, "'ah proto' is bogus"); in gen_proto()
6539 bpf_error(cstate, "'esp proto' is bogus"); in gen_proto()
6543 bpf_error(cstate, "'pim proto' is bogus"); in gen_proto()
6547 bpf_error(cstate, "'vrrp proto' is bogus"); in gen_proto()
6551 bpf_error(cstate, "'aarp proto' is bogus"); in gen_proto()
6555 switch (cstate->linktype) { in gen_proto()
6576 return gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | v); in gen_proto()
6585 b0 = gen_linktype(cstate, LLCSAP_ISONS<<8 | LLCSAP_ISONS); in gen_proto()
6587 b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 1, BPF_B, v); in gen_proto()
6592 b0 = gen_linktype(cstate, LLCSAP_ISONS); in gen_proto()
6593 b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 0, BPF_B, v); in gen_proto()
6599 bpf_error(cstate, "'esis proto' is bogus"); in gen_proto()
6603 b0 = gen_proto(cstate, ISO10589_ISIS, Q_ISO, Q_DEFAULT); in gen_proto()
6608 b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 4, BPF_B, v); in gen_proto()
6613 bpf_error(cstate, "'clnp proto' is not supported"); in gen_proto()
6617 bpf_error(cstate, "'stp proto' is bogus"); in gen_proto()
6621 bpf_error(cstate, "'ipx proto' is bogus"); in gen_proto()
6625 bpf_error(cstate, "'netbeui proto' is bogus"); in gen_proto()
6629 bpf_error(cstate, "'l1 proto' is bogus"); in gen_proto()
6633 bpf_error(cstate, "'l2 proto' is bogus"); in gen_proto()
6637 bpf_error(cstate, "'iih proto' is bogus"); in gen_proto()
6641 bpf_error(cstate, "'snp proto' is bogus"); in gen_proto()
6645 bpf_error(cstate, "'csnp proto' is bogus"); in gen_proto()
6649 bpf_error(cstate, "'psnp proto' is bogus"); in gen_proto()
6653 bpf_error(cstate, "'lsp proto' is bogus"); in gen_proto()
6657 bpf_error(cstate, "'radio proto' is bogus"); in gen_proto()
6661 bpf_error(cstate, "'carp proto' is bogus"); in gen_proto()
6675 nametoport(compiler_state_t *cstate, const char *name, int ipproto) in nametoport() argument
6715 bpf_set_error(cstate, "getaddrinfo(\"%s\" fails with system error: %d", in nametoport()
6734 bpf_set_error(cstate, "getaddrinfo(\"%s\") fails with error: %d", in nametoport()
6774 stringtoport(compiler_state_t *cstate, const char *string, size_t string_size, in stringtoport() argument
6786 ret = stoulen(string, string_size, &val, cstate); in stringtoport()
6803 tcp_port = nametoport(cstate, cpy, IPPROTO_TCP); in stringtoport()
6810 longjmp(cstate->top_ctx, 1); in stringtoport()
6813 udp_port = nametoport(cstate, cpy, IPPROTO_UDP); in stringtoport()
6820 longjmp(cstate->top_ctx, 1); in stringtoport()
6862 bpf_set_error(cstate, "'%s' is not a valid port", cpy); in stringtoport()
6864 longjmp(cstate->top_ctx, 1); in stringtoport()
6869 longjmp(cstate->top_ctx, 1); in stringtoport()
6874 bpf_set_error(cstate, "stoulen returned %d - this should not happen", ret); in stringtoport()
6875 longjmp(cstate->top_ctx, 1); in stringtoport()
6886 stringtoportrange(compiler_state_t *cstate, const char *string, in stringtoportrange() argument
6895 bpf_error(cstate, "port range '%s' contains no hyphen", string); in stringtoportrange()
6905 bpf_error(cstate, "port range '%s' contains more than one hyphen", in stringtoportrange()
6915 bpf_error(cstate, "port range '%s' has no starting port", string); in stringtoportrange()
6921 *port1 = stringtoport(cstate, first, first_size, proto); in stringtoportrange()
6931 bpf_error(cstate, "port range '%s' has no ending port", string); in stringtoportrange()
6937 *port2 = stringtoport(cstate, second, second_size, proto); in stringtoportrange()
6943 gen_scode(compiler_state_t *cstate, const char *name, struct qual q) in gen_scode() argument
6965 if (setjmp(cstate->top_ctx)) in gen_scode()
6973 bpf_error(cstate, "unknown network '%s'", name); in gen_scode()
6980 return gen_host(cstate, addr, mask, proto, dir, q.addr); in gen_scode()
6985 switch (cstate->linktype) { in gen_scode()
6992 bpf_error(cstate, in gen_scode()
6994 tmp = gen_prevlinkhdr_check(cstate); in gen_scode()
6995 b = gen_ehostop(cstate, eaddr, dir); in gen_scode()
7004 bpf_error(cstate, in gen_scode()
7006 b = gen_fhostop(cstate, eaddr, dir); in gen_scode()
7013 bpf_error(cstate, in gen_scode()
7015 b = gen_thostop(cstate, eaddr, dir); in gen_scode()
7026 bpf_error(cstate, in gen_scode()
7028 b = gen_wlanhostop(cstate, eaddr, dir); in gen_scode()
7035 bpf_error(cstate, in gen_scode()
7037 b = gen_ipfchostop(cstate, eaddr, dir); in gen_scode()
7042 …bpf_error(cstate, "only ethernet/FDDI/token ring/802.11/ATM LANE/Fibre Channel supports link-level… in gen_scode()
7048 bpf_error(cstate, "unknown decnet host name '%s'\n", name); in gen_scode()
7050 bpf_error(cstate, "decnet name support not included, '%s' cannot be translated\n", in gen_scode()
7058 return (gen_host(cstate, dn_addr, 0, proto, dir, q.addr)); in gen_scode()
7065 bpf_error(cstate, "unknown host '%s'", name); in gen_scode()
7066 cstate->ai = res; in gen_scode()
7072 if (cstate->off_linktype.constant_part == OFFSET_NOT_SET && in gen_scode()
7089 tmp = gen_host(cstate, ntohl(sin4->sin_addr.s_addr), in gen_scode()
7099 tmp = gen_host6(cstate, &sin6->sin6_addr, in gen_scode()
7110 cstate->ai = NULL; in gen_scode()
7113 bpf_error(cstate, "unknown host '%s'%s", name, in gen_scode()
7124 bpf_error(cstate, "illegal qualifier of 'port'"); in gen_scode()
7126 bpf_error(cstate, "unknown port '%s'", name); in gen_scode()
7129 bpf_error(cstate, "port '%s' is tcp", name); in gen_scode()
7131 bpf_error(cstate, "port '%s' is sctp", name); in gen_scode()
7138 bpf_error(cstate, "port '%s' is udp", name); in gen_scode()
7141 bpf_error(cstate, "port '%s' is sctp", name); in gen_scode()
7148 bpf_error(cstate, "port '%s' is udp", name); in gen_scode()
7151 bpf_error(cstate, "port '%s' is tcp", name); in gen_scode()
7157 bpf_error(cstate, "illegal port number %d < 0", port); in gen_scode()
7159 bpf_error(cstate, "illegal port number %d > 65535", port); in gen_scode()
7160 b = gen_port(cstate, port, real_proto, dir); in gen_scode()
7161 gen_or(gen_port6(cstate, port, real_proto, dir), b); in gen_scode()
7167 bpf_error(cstate, "illegal qualifier of 'portrange'"); in gen_scode()
7168 stringtoportrange(cstate, name, &port1, &port2, &real_proto); in gen_scode()
7171 bpf_error(cstate, "port in range '%s' is tcp", name); in gen_scode()
7173 bpf_error(cstate, "port in range '%s' is sctp", name); in gen_scode()
7180 bpf_error(cstate, "port in range '%s' is udp", name); in gen_scode()
7182 bpf_error(cstate, "port in range '%s' is sctp", name); in gen_scode()
7189 bpf_error(cstate, "port in range '%s' is udp", name); in gen_scode()
7191 bpf_error(cstate, "port in range '%s' is tcp", name); in gen_scode()
7197 bpf_error(cstate, "illegal port number %d > 65535", port1); in gen_scode()
7199 bpf_error(cstate, "illegal port number %d > 65535", port2); in gen_scode()
7201 b = gen_portrange(cstate, port1, port2, real_proto, dir); in gen_scode()
7202 gen_or(gen_portrange6(cstate, port1, port2, real_proto, dir), b); in gen_scode()
7209 bpf_error(cstate, "unknown ether host: %s", name); in gen_scode()
7212 cstate->ai = res; in gen_scode()
7214 bpf_error(cstate, "unknown host '%s'", name); in gen_scode()
7215 b = gen_gateway(cstate, eaddr, res, proto, dir); in gen_scode()
7216 cstate->ai = NULL; in gen_scode()
7219 bpf_error(cstate, "unknown host '%s'", name); in gen_scode()
7222 bpf_error(cstate, "'gateway' not supported in this configuration"); in gen_scode()
7226 real_proto = lookup_proto(cstate, name, proto); in gen_scode()
7228 return gen_proto(cstate, real_proto, proto, dir); in gen_scode()
7230 bpf_error(cstate, "unknown protocol: %s", name); in gen_scode()
7234 real_proto = lookup_proto(cstate, name, proto); in gen_scode()
7236 return gen_protochain(cstate, real_proto, proto); in gen_scode()
7238 bpf_error(cstate, "unknown protocol: %s", name); in gen_scode()
7242 syntax(cstate); in gen_scode()
7250 gen_mcode(compiler_state_t *cstate, const char *s1, const char *s2, in gen_mcode() argument
7260 if (setjmp(cstate->top_ctx)) in gen_mcode()
7265 bpf_error(cstate, "invalid IPv4 address '%s'", s1); in gen_mcode()
7272 bpf_error(cstate, "invalid IPv4 address '%s'", s2); in gen_mcode()
7276 bpf_error(cstate, "non-network bits set in \"%s mask %s\"", in gen_mcode()
7281 bpf_error(cstate, "mask length must be <= 32"); in gen_mcode()
7291 bpf_error(cstate, "non-network bits set in \"%s/%d\"", in gen_mcode()
7298 return gen_host(cstate, n, m, q.proto, q.dir, q.addr); in gen_mcode()
7301 bpf_error(cstate, "Mask syntax for networks only"); in gen_mcode()
7308 gen_ncode(compiler_state_t *cstate, const char *s, bpf_u_int32 v, struct qual q) in gen_ncode() argument
7319 if (setjmp(cstate->top_ctx)) in gen_ncode()
7329 bpf_error(cstate, "malformed decnet address '%s'", s); in gen_ncode()
7333 bpf_error(cstate, "invalid IPv4 address '%s'", s); in gen_ncode()
7342 return gen_host(cstate, v, 0, proto, dir, q.addr); in gen_ncode()
7344 bpf_error(cstate, "illegal link layer address"); in gen_ncode()
7358 return gen_host(cstate, v, mask, proto, dir, q.addr); in gen_ncode()
7371 bpf_error(cstate, "illegal qualifier of 'port'"); in gen_ncode()
7374 bpf_error(cstate, "illegal port number %u > 65535", v); in gen_ncode()
7378 b = gen_port(cstate, v, proto, dir); in gen_ncode()
7379 gen_or(gen_port6(cstate, v, proto, dir), b); in gen_ncode()
7393 bpf_error(cstate, "illegal qualifier of 'portrange'"); in gen_ncode()
7396 bpf_error(cstate, "illegal port number %u > 65535", v); in gen_ncode()
7400 b = gen_portrange(cstate, v, v, proto, dir); in gen_ncode()
7401 gen_or(gen_portrange6(cstate, v, v, proto, dir), b); in gen_ncode()
7406 bpf_error(cstate, "'gateway' requires a name"); in gen_ncode()
7410 return gen_proto(cstate, v, proto, dir); in gen_ncode()
7414 return gen_protochain(cstate, v, proto); in gen_ncode()
7418 syntax(cstate); in gen_ncode()
7430 gen_mcode6(compiler_state_t *cstate, const char *s, bpf_u_int32 masklen, in gen_mcode6() argument
7443 if (setjmp(cstate->top_ctx)) in gen_mcode6()
7448 bpf_error(cstate, "invalid ip6 address %s", s); in gen_mcode6()
7449 cstate->ai = res; in gen_mcode6()
7451 bpf_error(cstate, "%s resolved to multiple address", s); in gen_mcode6()
7455 bpf_error(cstate, "mask length must be <= %zu", sizeof(mask.s6_addr) * 8); in gen_mcode6()
7467 bpf_error(cstate, "non-network bits set in \"%s/%d\"", s, masklen); in gen_mcode6()
7475 bpf_error(cstate, "Mask syntax for networks only"); in gen_mcode6()
7479 b = gen_host6(cstate, addr, &mask, q.proto, q.dir, q.addr); in gen_mcode6()
7480 cstate->ai = NULL; in gen_mcode6()
7485 bpf_error(cstate, "invalid qualifier against IPv6 address"); in gen_mcode6()
7492 gen_ecode(compiler_state_t *cstate, const char *s, struct qual q) in gen_ecode() argument
7500 if (setjmp(cstate->top_ctx)) in gen_ecode()
7504 cstate->e = pcap_ether_aton(s); in gen_ecode()
7505 if (cstate->e == NULL) in gen_ecode()
7506 bpf_error(cstate, "malloc"); in gen_ecode()
7507 switch (cstate->linktype) { in gen_ecode()
7511 tmp = gen_prevlinkhdr_check(cstate); in gen_ecode()
7512 b = gen_ehostop(cstate, cstate->e, (int)q.dir); in gen_ecode()
7517 b = gen_fhostop(cstate, cstate->e, (int)q.dir); in gen_ecode()
7520 b = gen_thostop(cstate, cstate->e, (int)q.dir); in gen_ecode()
7527 b = gen_wlanhostop(cstate, cstate->e, (int)q.dir); in gen_ecode()
7530 b = gen_ipfchostop(cstate, cstate->e, (int)q.dir); in gen_ecode()
7533 free(cstate->e); in gen_ecode()
7534 cstate->e = NULL; in gen_ecode()
7535 …bpf_error(cstate, "ethernet addresses supported only on ethernet/FDDI/token ring/802.11/ATM LANE/F… in gen_ecode()
7538 free(cstate->e); in gen_ecode()
7539 cstate->e = NULL; in gen_ecode()
7542 bpf_error(cstate, "ethernet address used in non-ether expression"); in gen_ecode()
7559 xfer_to_x(compiler_state_t *cstate, struct arth *a) in xfer_to_x() argument
7563 s = new_stmt(cstate, BPF_LDX|BPF_MEM); in xfer_to_x()
7569 xfer_to_a(compiler_state_t *cstate, struct arth *a) in xfer_to_a() argument
7573 s = new_stmt(cstate, BPF_LD|BPF_MEM); in xfer_to_a()
7586 gen_load_internal(compiler_state_t *cstate, int proto, struct arth *inst, in gen_load_internal() argument
7592 int regno = alloc_reg(cstate); in gen_load_internal()
7594 free_reg(cstate, inst->regno); in gen_load_internal()
7598 bpf_error(cstate, "data size must be 1, 2, or 4"); in gen_load_internal()
7615 bpf_error(cstate, "unsupported index operation"); in gen_load_internal()
7623 if (cstate->linktype != DLT_IEEE802_11_RADIO_AVS && in gen_load_internal()
7624 cstate->linktype != DLT_IEEE802_11_RADIO && in gen_load_internal()
7625 cstate->linktype != DLT_PRISM_HEADER) in gen_load_internal()
7626 bpf_error(cstate, "radio information not present in capture"); in gen_load_internal()
7632 s = xfer_to_x(cstate, inst); in gen_load_internal()
7637 tmp = new_stmt(cstate, BPF_LD|BPF_IND|size_code); in gen_load_internal()
7654 s = gen_abs_offset_varpart(cstate, &cstate->off_linkhdr); in gen_load_internal()
7666 sappend(s, xfer_to_a(cstate, inst)); in gen_load_internal()
7667 sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X)); in gen_load_internal()
7668 sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX)); in gen_load_internal()
7670 s = xfer_to_x(cstate, inst); in gen_load_internal()
7679 tmp = new_stmt(cstate, BPF_LD|BPF_IND|size_code); in gen_load_internal()
7680 tmp->s.k = cstate->off_linkhdr.constant_part; in gen_load_internal()
7701 s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl); in gen_load_internal()
7713 sappend(s, xfer_to_a(cstate, inst)); in gen_load_internal()
7714 sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X)); in gen_load_internal()
7715 sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX)); in gen_load_internal()
7717 s = xfer_to_x(cstate, inst); in gen_load_internal()
7726 tmp = new_stmt(cstate, BPF_LD|BPF_IND|size_code); in gen_load_internal()
7727 tmp->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_load_internal()
7735 b = gen_proto_abbrev_internal(cstate, proto); in gen_load_internal()
7764 s = gen_loadx_iphdrlen(cstate); in gen_load_internal()
7780 sappend(s, xfer_to_a(cstate, inst)); in gen_load_internal()
7781 sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X)); in gen_load_internal()
7782 sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX)); in gen_load_internal()
7783 sappend(s, tmp = new_stmt(cstate, BPF_LD|BPF_IND|size_code)); in gen_load_internal()
7784 tmp->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_load_internal()
7793 gen_and(gen_proto_abbrev_internal(cstate, proto), b = gen_ipfrag(cstate)); in gen_load_internal()
7796 gen_and(gen_proto_abbrev_internal(cstate, Q_IP), b); in gen_load_internal()
7804 b = gen_proto_abbrev_internal(cstate, Q_IPV6); in gen_load_internal()
7812 b = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, 58); in gen_load_internal()
7817 s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl); in gen_load_internal()
7828 sappend(s, xfer_to_a(cstate, inst)); in gen_load_internal()
7829 sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X)); in gen_load_internal()
7830 sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX)); in gen_load_internal()
7832 s = xfer_to_x(cstate, inst); in gen_load_internal()
7841 tmp = new_stmt(cstate, BPF_LD|BPF_IND|size_code); in gen_load_internal()
7842 tmp->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 40; in gen_load_internal()
7850 s = new_stmt(cstate, BPF_ST); in gen_load_internal()
7858 gen_load(compiler_state_t *cstate, int proto, struct arth *inst, in gen_load() argument
7865 if (setjmp(cstate->top_ctx)) in gen_load()
7868 return gen_load_internal(cstate, proto, inst, size); in gen_load()
7872 gen_relation_internal(compiler_state_t *cstate, int code, struct arth *a0, in gen_relation_internal() argument
7878 s0 = xfer_to_x(cstate, a1); in gen_relation_internal()
7879 s1 = xfer_to_a(cstate, a0); in gen_relation_internal()
7881 s2 = new_stmt(cstate, BPF_ALU|BPF_SUB|BPF_X); in gen_relation_internal()
7882 b = new_block(cstate, JMP(code)); in gen_relation_internal()
7886 b = new_block(cstate, BPF_JMP|code|BPF_X); in gen_relation_internal()
7896 free_reg(cstate, a0->regno); in gen_relation_internal()
7897 free_reg(cstate, a1->regno); in gen_relation_internal()
7916 gen_relation(compiler_state_t *cstate, int code, struct arth *a0, in gen_relation() argument
7923 if (setjmp(cstate->top_ctx)) in gen_relation()
7926 return gen_relation_internal(cstate, code, a0, a1, reversed); in gen_relation()
7930 gen_loadlen(compiler_state_t *cstate) in gen_loadlen() argument
7940 if (setjmp(cstate->top_ctx)) in gen_loadlen()
7943 regno = alloc_reg(cstate); in gen_loadlen()
7944 a = (struct arth *)newchunk(cstate, sizeof(*a)); in gen_loadlen()
7945 s = new_stmt(cstate, BPF_LD|BPF_LEN); in gen_loadlen()
7946 s->next = new_stmt(cstate, BPF_ST); in gen_loadlen()
7955 gen_loadi_internal(compiler_state_t *cstate, bpf_u_int32 val) in gen_loadi_internal() argument
7961 a = (struct arth *)newchunk(cstate, sizeof(*a)); in gen_loadi_internal()
7963 reg = alloc_reg(cstate); in gen_loadi_internal()
7965 s = new_stmt(cstate, BPF_LD|BPF_IMM); in gen_loadi_internal()
7967 s->next = new_stmt(cstate, BPF_ST); in gen_loadi_internal()
7976 gen_loadi(compiler_state_t *cstate, bpf_u_int32 val) in gen_loadi() argument
7982 if (setjmp(cstate->top_ctx)) in gen_loadi()
7985 return gen_loadi_internal(cstate, val); in gen_loadi()
7994 gen_neg(compiler_state_t *cstate, struct arth *a_arg) in gen_neg() argument
8003 if (setjmp(cstate->top_ctx)) in gen_neg()
8006 s = xfer_to_a(cstate, a); in gen_neg()
8008 s = new_stmt(cstate, BPF_ALU|BPF_NEG); in gen_neg()
8011 s = new_stmt(cstate, BPF_ST); in gen_neg()
8024 gen_arth(compiler_state_t *cstate, int code, struct arth *a0_arg, in gen_arth() argument
8034 if (setjmp(cstate->top_ctx)) in gen_arth()
8046 bpf_error(cstate, "division by zero"); in gen_arth()
8049 bpf_error(cstate, "modulus by zero"); in gen_arth()
8052 bpf_error(cstate, "shift by more than 31 bits"); in gen_arth()
8054 s0 = xfer_to_x(cstate, a1); in gen_arth()
8055 s1 = xfer_to_a(cstate, a0); in gen_arth()
8056 s2 = new_stmt(cstate, BPF_ALU|BPF_X|code); in gen_arth()
8063 free_reg(cstate, a0->regno); in gen_arth()
8064 free_reg(cstate, a1->regno); in gen_arth()
8066 s0 = new_stmt(cstate, BPF_ST); in gen_arth()
8067 a0->regno = s0->s.k = alloc_reg(cstate); in gen_arth()
8077 init_regs(compiler_state_t *cstate) in init_regs() argument
8079 cstate->curreg = 0; in init_regs()
8080 memset(cstate->regused, 0, sizeof cstate->regused); in init_regs()
8087 alloc_reg(compiler_state_t *cstate) in alloc_reg() argument
8092 if (cstate->regused[cstate->curreg]) in alloc_reg()
8093 cstate->curreg = (cstate->curreg + 1) % BPF_MEMWORDS; in alloc_reg()
8095 cstate->regused[cstate->curreg] = 1; in alloc_reg()
8096 return cstate->curreg; in alloc_reg()
8099 bpf_error(cstate, "too many registers needed to evaluate expression"); in alloc_reg()
8108 free_reg(compiler_state_t *cstate, int n) in free_reg() argument
8110 cstate->regused[n] = 0; in free_reg()
8114 gen_len(compiler_state_t *cstate, int jmp, int n) in gen_len() argument
8119 s = new_stmt(cstate, BPF_LD|BPF_LEN); in gen_len()
8120 b = new_block(cstate, JMP(jmp)); in gen_len()
8128 gen_greater(compiler_state_t *cstate, int n) in gen_greater() argument
8134 if (setjmp(cstate->top_ctx)) in gen_greater()
8137 return gen_len(cstate, BPF_JGE, n); in gen_greater()
8144 gen_less(compiler_state_t *cstate, int n) in gen_less() argument
8152 if (setjmp(cstate->top_ctx)) in gen_less()
8155 b = gen_len(cstate, BPF_JGT, n); in gen_less()
8172 gen_byteop(compiler_state_t *cstate, int op, int idx, bpf_u_int32 val) in gen_byteop() argument
8181 if (setjmp(cstate->top_ctx)) in gen_byteop()
8189 return gen_cmp(cstate, OR_LINKHDR, (u_int)idx, BPF_B, val); in gen_byteop()
8192 b = gen_cmp_lt(cstate, OR_LINKHDR, (u_int)idx, BPF_B, val); in gen_byteop()
8196 b = gen_cmp_gt(cstate, OR_LINKHDR, (u_int)idx, BPF_B, val); in gen_byteop()
8200 s = new_stmt(cstate, BPF_ALU|BPF_OR|BPF_K); in gen_byteop()
8204 s = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K); in gen_byteop()
8208 b = new_block(cstate, JMP(BPF_JEQ)); in gen_byteop()
8218 gen_broadcast(compiler_state_t *cstate, int proto) in gen_broadcast() argument
8228 if (setjmp(cstate->top_ctx)) in gen_broadcast()
8235 switch (cstate->linktype) { in gen_broadcast()
8238 return gen_ahostop(cstate, abroadcast, Q_DST); in gen_broadcast()
8242 b1 = gen_prevlinkhdr_check(cstate); in gen_broadcast()
8243 b0 = gen_ehostop(cstate, ebroadcast, Q_DST); in gen_broadcast()
8248 return gen_fhostop(cstate, ebroadcast, Q_DST); in gen_broadcast()
8250 return gen_thostop(cstate, ebroadcast, Q_DST); in gen_broadcast()
8256 return gen_wlanhostop(cstate, ebroadcast, Q_DST); in gen_broadcast()
8258 return gen_ipfchostop(cstate, ebroadcast, Q_DST); in gen_broadcast()
8260 bpf_error(cstate, "not a broadcast link"); in gen_broadcast()
8270 if (cstate->netmask == PCAP_NETMASK_UNKNOWN) in gen_broadcast()
8271 bpf_error(cstate, "netmask not known, so 'ip broadcast' not supported"); in gen_broadcast()
8272 b0 = gen_linktype(cstate, ETHERTYPE_IP); in gen_broadcast()
8273 hostmask = ~cstate->netmask; in gen_broadcast()
8274 b1 = gen_mcmp(cstate, OR_LINKPL, 16, BPF_W, 0, hostmask); in gen_broadcast()
8275 b2 = gen_mcmp(cstate, OR_LINKPL, 16, BPF_W, in gen_broadcast()
8281 bpf_error(cstate, "only link-layer/IP broadcast filters supported"); in gen_broadcast()
8290 gen_mac_multicast(compiler_state_t *cstate, int offset) in gen_mac_multicast() argument
8296 s = gen_load_a(cstate, OR_LINKHDR, offset, BPF_B); in gen_mac_multicast()
8297 b0 = new_block(cstate, JMP(BPF_JSET)); in gen_mac_multicast()
8304 gen_multicast(compiler_state_t *cstate, int proto) in gen_multicast() argument
8313 if (setjmp(cstate->top_ctx)) in gen_multicast()
8320 switch (cstate->linktype) { in gen_multicast()
8324 return gen_ahostop(cstate, abroadcast, Q_DST); in gen_multicast()
8328 b1 = gen_prevlinkhdr_check(cstate); in gen_multicast()
8330 b0 = gen_mac_multicast(cstate, 0); in gen_multicast()
8341 return gen_mac_multicast(cstate, 1); in gen_multicast()
8344 return gen_mac_multicast(cstate, 2); in gen_multicast()
8371 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_multicast()
8372 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_multicast()
8379 b0 = gen_mac_multicast(cstate, 16); in gen_multicast()
8386 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_multicast()
8387 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_multicast()
8395 b1 = gen_mac_multicast(cstate, 4); in gen_multicast()
8408 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_multicast()
8409 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_multicast()
8423 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_multicast()
8424 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_multicast()
8432 b1 = gen_mac_multicast(cstate, 4); in gen_multicast()
8450 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_multicast()
8451 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_multicast()
8463 b0 = gen_mac_multicast(cstate, 2); in gen_multicast()
8472 b0 = gen_linktype(cstate, ETHERTYPE_IP); in gen_multicast()
8473 b1 = gen_cmp_ge(cstate, OR_LINKPL, 16, BPF_B, 224); in gen_multicast()
8478 b0 = gen_linktype(cstate, ETHERTYPE_IPV6); in gen_multicast()
8479 b1 = gen_cmp(cstate, OR_LINKPL, 24, BPF_B, 255); in gen_multicast()
8483 …bpf_error(cstate, "link-layer multicast filters supported only on ethernet/FDDI/token ring/ARCNET/… in gen_multicast()
8488 gen_ifindex(compiler_state_t *cstate, int ifindex) in gen_ifindex() argument
8496 if (setjmp(cstate->top_ctx)) in gen_ifindex()
8502 switch (cstate->linktype) { in gen_ifindex()
8505 b0 = gen_cmp(cstate, OR_LINKHDR, 4, BPF_W, ifindex); in gen_ifindex()
8515 if (cstate->bpf_pcap->rfile != NULL) { in gen_ifindex()
8517 bpf_error(cstate, "ifindex not supported on %s when reading savefiles", in gen_ifindex()
8518 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_ifindex()
8522 b0 = gen_cmp(cstate, OR_LINKHDR, SKF_AD_OFF + SKF_AD_IFINDEX, BPF_W, in gen_ifindex()
8525 bpf_error(cstate, "ifindex not supported on %s", in gen_ifindex()
8526 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_ifindex()
8543 gen_inbound(compiler_state_t *cstate, int dir) in gen_inbound() argument
8551 if (setjmp(cstate->top_ctx)) in gen_inbound()
8557 switch (cstate->linktype) { in gen_inbound()
8559 b0 = gen_relation_internal(cstate, BPF_JEQ, in gen_inbound()
8560 gen_load_internal(cstate, Q_LINK, gen_loadi_internal(cstate, 0), 1), in gen_inbound()
8561 gen_loadi_internal(cstate, 0), in gen_inbound()
8568 b0 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, IPNET_OUTBOUND); in gen_inbound()
8571 b0 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, IPNET_INBOUND); in gen_inbound()
8577 b0 = gen_cmp(cstate, OR_LINKHDR, 0, BPF_H, LINUX_SLL_OUTGOING); in gen_inbound()
8586 b0 = gen_cmp(cstate, OR_LINKHDR, 10, BPF_B, LINUX_SLL_OUTGOING); in gen_inbound()
8594 b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, dir), BPF_B, in gen_inbound()
8601 b0 = gen_cmp(cstate, OR_LINKHDR, 0, BPF_B, PPP_PPPD_OUT); in gen_inbound()
8604 b0 = gen_cmp(cstate, OR_LINKHDR, 0, BPF_B, PPP_PPPD_IN); in gen_inbound()
8635 b0 = gen_mcmp(cstate, OR_LINKHDR, 3, BPF_B, 0, 0x01); in gen_inbound()
8638 b0 = gen_mcmp(cstate, OR_LINKHDR, 3, BPF_B, 1, 0x01); in gen_inbound()
8665 if (cstate->bpf_pcap->rfile != NULL) { in gen_inbound()
8667 bpf_error(cstate, "inbound/outbound not supported on %s when reading savefiles", in gen_inbound()
8668 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_inbound()
8672 b0 = gen_cmp(cstate, OR_LINKHDR, SKF_AD_OFF + SKF_AD_PKTTYPE, BPF_H, in gen_inbound()
8679 bpf_error(cstate, "inbound/outbound not supported on %s", in gen_inbound()
8680 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_inbound()
8689 gen_pf_ifname(compiler_state_t *cstate, const char *ifname) in gen_pf_ifname() argument
8698 if (setjmp(cstate->top_ctx)) in gen_pf_ifname()
8701 if (cstate->linktype != DLT_PFLOG) { in gen_pf_ifname()
8702 bpf_error(cstate, "ifname supported only on PF linktype"); in gen_pf_ifname()
8708 bpf_error(cstate, "ifname interface names can only be %d characters", in gen_pf_ifname()
8712 b0 = gen_bcmp(cstate, OR_LINKHDR, off, (u_int)strlen(ifname), in gen_pf_ifname()
8719 gen_pf_ruleset(compiler_state_t *cstate, char *ruleset) in gen_pf_ruleset() argument
8727 if (setjmp(cstate->top_ctx)) in gen_pf_ruleset()
8730 if (cstate->linktype != DLT_PFLOG) { in gen_pf_ruleset()
8731 bpf_error(cstate, "ruleset supported only on PF linktype"); in gen_pf_ruleset()
8736 bpf_error(cstate, "ruleset names can only be %ld characters", in gen_pf_ruleset()
8741 b0 = gen_bcmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, ruleset), in gen_pf_ruleset()
8748 gen_pf_rnr(compiler_state_t *cstate, int rnr) in gen_pf_rnr() argument
8756 if (setjmp(cstate->top_ctx)) in gen_pf_rnr()
8759 if (cstate->linktype != DLT_PFLOG) { in gen_pf_rnr()
8760 bpf_error(cstate, "rnr supported only on PF linktype"); in gen_pf_rnr()
8764 b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, rulenr), BPF_W, in gen_pf_rnr()
8771 gen_pf_srnr(compiler_state_t *cstate, int srnr) in gen_pf_srnr() argument
8779 if (setjmp(cstate->top_ctx)) in gen_pf_srnr()
8782 if (cstate->linktype != DLT_PFLOG) { in gen_pf_srnr()
8783 bpf_error(cstate, "srnr supported only on PF linktype"); in gen_pf_srnr()
8787 b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, subrulenr), BPF_W, in gen_pf_srnr()
8794 gen_pf_reason(compiler_state_t *cstate, int reason) in gen_pf_reason() argument
8802 if (setjmp(cstate->top_ctx)) in gen_pf_reason()
8805 if (cstate->linktype != DLT_PFLOG) { in gen_pf_reason()
8806 bpf_error(cstate, "reason supported only on PF linktype"); in gen_pf_reason()
8810 b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, reason), BPF_B, in gen_pf_reason()
8817 gen_pf_action(compiler_state_t *cstate, int action) in gen_pf_action() argument
8825 if (setjmp(cstate->top_ctx)) in gen_pf_action()
8828 if (cstate->linktype != DLT_PFLOG) { in gen_pf_action()
8829 bpf_error(cstate, "action supported only on PF linktype"); in gen_pf_action()
8833 b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, action), BPF_B, in gen_pf_action()
8840 gen_p80211_type(compiler_state_t *cstate, bpf_u_int32 type, bpf_u_int32 mask) in gen_p80211_type() argument
8848 if (setjmp(cstate->top_ctx)) in gen_p80211_type()
8851 switch (cstate->linktype) { in gen_p80211_type()
8857 b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, type, mask); in gen_p80211_type()
8861 bpf_error(cstate, "802.11 link-layer types supported only on 802.11"); in gen_p80211_type()
8869 gen_p80211_fcdir(compiler_state_t *cstate, bpf_u_int32 fcdir) in gen_p80211_fcdir() argument
8877 if (setjmp(cstate->top_ctx)) in gen_p80211_fcdir()
8880 switch (cstate->linktype) { in gen_p80211_fcdir()
8889 bpf_error(cstate, "frame direction supported only with 802.11 headers"); in gen_p80211_fcdir()
8893 b0 = gen_mcmp(cstate, OR_LINKHDR, 1, BPF_B, fcdir, in gen_p80211_fcdir()
8900 gen_acode(compiler_state_t *cstate, const char *s, struct qual q) in gen_acode() argument
8908 if (setjmp(cstate->top_ctx)) in gen_acode()
8911 switch (cstate->linktype) { in gen_acode()
8917 cstate->e = pcap_ether_aton(s); in gen_acode()
8918 if (cstate->e == NULL) in gen_acode()
8919 bpf_error(cstate, "malloc"); in gen_acode()
8920 b = gen_ahostop(cstate, cstate->e, (int)q.dir); in gen_acode()
8921 free(cstate->e); in gen_acode()
8922 cstate->e = NULL; in gen_acode()
8925 bpf_error(cstate, "ARCnet address used in non-arc expression"); in gen_acode()
8929 bpf_error(cstate, "aid supported only on ARCnet"); in gen_acode()
8935 gen_ahostop(compiler_state_t *cstate, const u_char *eaddr, int dir) in gen_ahostop() argument
8942 return gen_bcmp(cstate, OR_LINKHDR, 0, 1, eaddr); in gen_ahostop()
8945 return gen_bcmp(cstate, OR_LINKHDR, 1, 1, eaddr); in gen_ahostop()
8948 b0 = gen_ahostop(cstate, eaddr, Q_SRC); in gen_ahostop()
8949 b1 = gen_ahostop(cstate, eaddr, Q_DST); in gen_ahostop()
8955 b0 = gen_ahostop(cstate, eaddr, Q_SRC); in gen_ahostop()
8956 b1 = gen_ahostop(cstate, eaddr, Q_DST); in gen_ahostop()
8961 bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11"); in gen_ahostop()
8965 bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11"); in gen_ahostop()
8969 bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11"); in gen_ahostop()
8973 bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11"); in gen_ahostop()
8977 bpf_error(cstate, "'ra' is only supported on 802.11"); in gen_ahostop()
8981 bpf_error(cstate, "'ta' is only supported on 802.11"); in gen_ahostop()
8989 gen_vlan_tpid_test(compiler_state_t *cstate) in gen_vlan_tpid_test() argument
8994 b0 = gen_linktype(cstate, ETHERTYPE_8021Q); in gen_vlan_tpid_test()
8995 b1 = gen_linktype(cstate, ETHERTYPE_8021AD); in gen_vlan_tpid_test()
8998 b1 = gen_linktype(cstate, ETHERTYPE_8021QINQ); in gen_vlan_tpid_test()
9005 gen_vlan_vid_test(compiler_state_t *cstate, bpf_u_int32 vlan_num) in gen_vlan_vid_test() argument
9008 bpf_error(cstate, "VLAN tag %u greater than maximum %u", in gen_vlan_vid_test()
9011 return gen_mcmp(cstate, OR_LINKPL, 0, BPF_H, vlan_num, 0x0fff); in gen_vlan_vid_test()
9015 gen_vlan_no_bpf_extensions(compiler_state_t *cstate, bpf_u_int32 vlan_num, in gen_vlan_no_bpf_extensions() argument
9020 b0 = gen_vlan_tpid_test(cstate); in gen_vlan_no_bpf_extensions()
9023 b1 = gen_vlan_vid_test(cstate, vlan_num); in gen_vlan_no_bpf_extensions()
9032 cstate->off_linkpl.constant_part += 4; in gen_vlan_no_bpf_extensions()
9033 cstate->off_linktype.constant_part += 4; in gen_vlan_no_bpf_extensions()
9041 gen_vlan_vloffset_add(compiler_state_t *cstate, bpf_abs_offset *off, in gen_vlan_vloffset_add() argument
9049 off->reg = alloc_reg(cstate); in gen_vlan_vloffset_add()
9051 s2 = new_stmt(cstate, BPF_LD|BPF_MEM); in gen_vlan_vloffset_add()
9054 s2 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_IMM); in gen_vlan_vloffset_add()
9057 s2 = new_stmt(cstate, BPF_ST); in gen_vlan_vloffset_add()
9067 gen_vlan_patch_tpid_test(compiler_state_t *cstate, struct block *b_tpid) in gen_vlan_patch_tpid_test() argument
9073 cstate->is_vlan_vloffset = 1; in gen_vlan_patch_tpid_test()
9074 gen_vlan_vloffset_add(cstate, &cstate->off_linkpl, 4, &s); in gen_vlan_patch_tpid_test()
9075 gen_vlan_vloffset_add(cstate, &cstate->off_linktype, 4, &s); in gen_vlan_patch_tpid_test()
9087 gen_vlan_patch_vid_test(compiler_state_t *cstate, struct block *b_vid) in gen_vlan_patch_vid_test() argument
9092 s = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_vlan_patch_vid_test()
9096 sjeq = new_stmt(cstate, JMP(BPF_JEQ)); in gen_vlan_patch_vid_test()
9101 s2 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_vlan_patch_vid_test()
9113 s2 = new_stmt(cstate, JMP(BPF_JA)); in gen_vlan_patch_vid_test()
9131 gen_vlan_bpf_extensions(compiler_state_t *cstate, bpf_u_int32 vlan_num, in gen_vlan_bpf_extensions() argument
9139 s = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_vlan_bpf_extensions()
9142 b0 = new_block(cstate, JMP(BPF_JEQ)); in gen_vlan_bpf_extensions()
9156 b_tpid = gen_vlan_tpid_test(cstate); in gen_vlan_bpf_extensions()
9158 b_vid = gen_vlan_vid_test(cstate, vlan_num); in gen_vlan_bpf_extensions()
9160 gen_vlan_patch_tpid_test(cstate, b_tpid); in gen_vlan_bpf_extensions()
9165 gen_vlan_patch_vid_test(cstate, b_vid); in gen_vlan_bpf_extensions()
9178 gen_vlan(compiler_state_t *cstate, bpf_u_int32 vlan_num, int has_vlan_tag) in gen_vlan() argument
9186 if (setjmp(cstate->top_ctx)) in gen_vlan()
9190 if (cstate->label_stack_depth > 0) in gen_vlan()
9191 bpf_error(cstate, "no VLAN match after MPLS"); in gen_vlan()
9224 switch (cstate->linktype) { in gen_vlan()
9232 if (cstate->vlan_stack_depth == 0 && !cstate->off_linkhdr.is_variable && in gen_vlan()
9233 cstate->off_linkhdr.constant_part == in gen_vlan()
9234 cstate->off_outermostlinkhdr.constant_part) { in gen_vlan()
9238 if (cstate->bpf_pcap->bpf_codegen_flags & BPF_SPECIAL_VLAN_HANDLING) in gen_vlan()
9239 b0 = gen_vlan_bpf_extensions(cstate, vlan_num, in gen_vlan()
9242 b0 = gen_vlan_no_bpf_extensions(cstate, in gen_vlan()
9246 b0 = gen_vlan_no_bpf_extensions(cstate, vlan_num, in gen_vlan()
9254 b0 = gen_vlan_no_bpf_extensions(cstate, vlan_num, has_vlan_tag); in gen_vlan()
9258 bpf_error(cstate, "no VLAN support for %s", in gen_vlan()
9259 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_vlan()
9263 cstate->vlan_stack_depth++; in gen_vlan()
9276 gen_mpls(compiler_state_t *cstate, bpf_u_int32 label_num_arg, in gen_mpls() argument
9286 if (setjmp(cstate->top_ctx)) in gen_mpls()
9289 if (cstate->label_stack_depth > 0) { in gen_mpls()
9291 b0 = gen_mcmp(cstate, OR_PREVMPLSHDR, 2, BPF_B, 0, 0x01); in gen_mpls()
9297 switch (cstate->linktype) { in gen_mpls()
9304 b0 = gen_linktype(cstate, ETHERTYPE_MPLS); in gen_mpls()
9308 b0 = gen_linktype(cstate, PPP_MPLS_UCAST); in gen_mpls()
9316 bpf_error(cstate, "no MPLS support for %s", in gen_mpls()
9317 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_mpls()
9325 bpf_error(cstate, "MPLS label %u greater than maximum %u", in gen_mpls()
9329 b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_W, label_num, in gen_mpls()
9349 cstate->off_nl_nosnap += 4; in gen_mpls()
9350 cstate->off_nl += 4; in gen_mpls()
9351 cstate->label_stack_depth++; in gen_mpls()
9359 gen_pppoed(compiler_state_t *cstate) in gen_pppoed() argument
9365 if (setjmp(cstate->top_ctx)) in gen_pppoed()
9369 return gen_linktype(cstate, ETHERTYPE_PPPOED); in gen_pppoed()
9373 gen_pppoes(compiler_state_t *cstate, bpf_u_int32 sess_num, int has_sess_num) in gen_pppoes() argument
9381 if (setjmp(cstate->top_ctx)) in gen_pppoes()
9387 b0 = gen_linktype(cstate, ETHERTYPE_PPPOES); in gen_pppoes()
9392 bpf_error(cstate, "PPPoE session number %u greater than maximum %u", in gen_pppoes()
9395 b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_W, sess_num, 0x0000ffff); in gen_pppoes()
9418 PUSH_LINKHDR(cstate, DLT_PPP, cstate->off_linkpl.is_variable, in gen_pppoes()
9419 cstate->off_linkpl.constant_part + cstate->off_nl + 6, /* 6 bytes past the PPPoE header */ in gen_pppoes()
9420 cstate->off_linkpl.reg); in gen_pppoes()
9422 cstate->off_linktype = cstate->off_linkhdr; in gen_pppoes()
9423 cstate->off_linkpl.constant_part = cstate->off_linkhdr.constant_part + 2; in gen_pppoes()
9425 cstate->off_nl = 0; in gen_pppoes()
9426 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in gen_pppoes()
9434 gen_geneve_check(compiler_state_t *cstate, in gen_geneve_check() argument
9440 b0 = gen_portfn(cstate, GENEVE_PORT, IPPROTO_UDP, Q_DST); in gen_geneve_check()
9445 b1 = gen_mcmp(cstate, offrel, 8, BPF_B, 0, 0xc0); in gen_geneve_check()
9451 bpf_error(cstate, "Geneve VNI %u greater than maximum %u", in gen_geneve_check()
9455 b1 = gen_mcmp(cstate, offrel, 12, BPF_W, vni, 0xffffff00); in gen_geneve_check()
9469 gen_geneve4(compiler_state_t *cstate, bpf_u_int32 vni, int has_vni) in gen_geneve4() argument
9474 b0 = gen_geneve_check(cstate, gen_port, OR_TRAN_IPV4, vni, has_vni); in gen_geneve4()
9477 s = gen_loadx_iphdrlen(cstate); in gen_geneve4()
9479 s1 = new_stmt(cstate, BPF_MISC|BPF_TXA); in gen_geneve4()
9485 b1 = new_block(cstate, BPF_JMP|BPF_JEQ|BPF_X); in gen_geneve4()
9495 gen_geneve6(compiler_state_t *cstate, bpf_u_int32 vni, int has_vni) in gen_geneve6() argument
9500 b0 = gen_geneve_check(cstate, gen_port6, OR_TRAN_IPV6, vni, has_vni); in gen_geneve6()
9504 s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl); in gen_geneve6()
9506 s1 = new_stmt(cstate, BPF_LD|BPF_IMM); in gen_geneve6()
9510 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X); in gen_geneve6()
9514 s = new_stmt(cstate, BPF_LD|BPF_IMM); in gen_geneve6()
9521 s1 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_geneve6()
9524 b1 = new_block(cstate, BPF_JMP|BPF_JEQ|BPF_X); in gen_geneve6()
9538 gen_geneve_offsets(compiler_state_t *cstate) in gen_geneve_offsets() argument
9547 s = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_geneve_offsets()
9548 s->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 8; in gen_geneve_offsets()
9551 s1 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_geneve_offsets()
9556 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_geneve_offsets()
9560 cstate->off_linktype.reg = alloc_reg(cstate); in gen_geneve_offsets()
9561 cstate->off_linktype.is_variable = 1; in gen_geneve_offsets()
9562 cstate->off_linktype.constant_part = 0; in gen_geneve_offsets()
9564 s1 = new_stmt(cstate, BPF_ST); in gen_geneve_offsets()
9565 s1->s.k = cstate->off_linktype.reg; in gen_geneve_offsets()
9571 s1 = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_geneve_offsets()
9575 s1 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K); in gen_geneve_offsets()
9579 s1 = new_stmt(cstate, BPF_ALU|BPF_MUL|BPF_K); in gen_geneve_offsets()
9584 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_geneve_offsets()
9589 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X); in gen_geneve_offsets()
9601 PUSH_LINKHDR(cstate, DLT_EN10MB, 1, 0, alloc_reg(cstate)); in gen_geneve_offsets()
9603 s1 = new_stmt(cstate, BPF_ST); in gen_geneve_offsets()
9604 s1->s.k = cstate->off_linkhdr.reg; in gen_geneve_offsets()
9613 cstate->no_optimize = 1; in gen_geneve_offsets()
9616 s1 = new_stmt(cstate, BPF_LD|BPF_IND|BPF_H); in gen_geneve_offsets()
9621 s1 = new_stmt(cstate, BPF_LDX|BPF_MEM); in gen_geneve_offsets()
9622 s1->s.k = cstate->off_linkhdr.reg; in gen_geneve_offsets()
9628 s_proto = new_stmt(cstate, JMP(BPF_JEQ)); in gen_geneve_offsets()
9632 s1 = new_stmt(cstate, BPF_MISC|BPF_TXA); in gen_geneve_offsets()
9638 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_geneve_offsets()
9642 s1 = new_stmt(cstate, BPF_ST); in gen_geneve_offsets()
9643 s1->s.k = cstate->off_linktype.reg; in gen_geneve_offsets()
9648 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_geneve_offsets()
9653 s1 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_geneve_offsets()
9657 cstate->off_linkpl.reg = alloc_reg(cstate); in gen_geneve_offsets()
9658 cstate->off_linkpl.is_variable = 1; in gen_geneve_offsets()
9659 cstate->off_linkpl.constant_part = 0; in gen_geneve_offsets()
9661 s1 = new_stmt(cstate, BPF_STX); in gen_geneve_offsets()
9662 s1->s.k = cstate->off_linkpl.reg; in gen_geneve_offsets()
9666 cstate->off_nl = 0; in gen_geneve_offsets()
9673 gen_geneve(compiler_state_t *cstate, bpf_u_int32 vni, int has_vni) in gen_geneve() argument
9682 if (setjmp(cstate->top_ctx)) in gen_geneve()
9685 b0 = gen_geneve4(cstate, vni, has_vni); in gen_geneve()
9686 b1 = gen_geneve6(cstate, vni, has_vni); in gen_geneve()
9694 s = gen_geneve_offsets(cstate); in gen_geneve()
9696 b1 = gen_true(cstate); in gen_geneve()
9702 cstate->is_geneve = 1; in gen_geneve()
9710 gen_geneve_ll_check(compiler_state_t *cstate) in gen_geneve_ll_check() argument
9721 s = new_stmt(cstate, BPF_LD|BPF_MEM); in gen_geneve_ll_check()
9722 s->s.k = cstate->off_linkhdr.reg; in gen_geneve_ll_check()
9724 s1 = new_stmt(cstate, BPF_LDX|BPF_MEM); in gen_geneve_ll_check()
9725 s1->s.k = cstate->off_linkpl.reg; in gen_geneve_ll_check()
9728 b0 = new_block(cstate, BPF_JMP|BPF_JEQ|BPF_X); in gen_geneve_ll_check()
9737 gen_atmfield_code_internal(compiler_state_t *cstate, int atmfield, in gen_atmfield_code_internal() argument
9745 if (!cstate->is_atm) in gen_atmfield_code_internal()
9746 bpf_error(cstate, "'vpi' supported only on raw ATM"); in gen_atmfield_code_internal()
9747 if (cstate->off_vpi == OFFSET_NOT_SET) in gen_atmfield_code_internal()
9749 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_vpi, BPF_B, in gen_atmfield_code_internal()
9754 if (!cstate->is_atm) in gen_atmfield_code_internal()
9755 bpf_error(cstate, "'vci' supported only on raw ATM"); in gen_atmfield_code_internal()
9756 if (cstate->off_vci == OFFSET_NOT_SET) in gen_atmfield_code_internal()
9758 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_vci, BPF_H, in gen_atmfield_code_internal()
9763 if (cstate->off_proto == OFFSET_NOT_SET) in gen_atmfield_code_internal()
9765 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_proto, BPF_B, in gen_atmfield_code_internal()
9770 if (cstate->off_payload == OFFSET_NOT_SET) in gen_atmfield_code_internal()
9772 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_payload + MSG_TYPE_POS, BPF_B, in gen_atmfield_code_internal()
9777 if (!cstate->is_atm) in gen_atmfield_code_internal()
9778 bpf_error(cstate, "'callref' supported only on raw ATM"); in gen_atmfield_code_internal()
9779 if (cstate->off_proto == OFFSET_NOT_SET) in gen_atmfield_code_internal()
9781 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_proto, BPF_B, in gen_atmfield_code_internal()
9792 gen_atmtype_metac(compiler_state_t *cstate) in gen_atmtype_metac() argument
9796 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmtype_metac()
9797 b1 = gen_atmfield_code_internal(cstate, A_VCI, 1, BPF_JEQ, 0); in gen_atmtype_metac()
9803 gen_atmtype_sc(compiler_state_t *cstate) in gen_atmtype_sc() argument
9807 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmtype_sc()
9808 b1 = gen_atmfield_code_internal(cstate, A_VCI, 5, BPF_JEQ, 0); in gen_atmtype_sc()
9814 gen_atmtype_llc(compiler_state_t *cstate) in gen_atmtype_llc() argument
9818 b0 = gen_atmfield_code_internal(cstate, A_PROTOTYPE, PT_LLC, BPF_JEQ, 0); in gen_atmtype_llc()
9819 cstate->linktype = cstate->prevlinktype; in gen_atmtype_llc()
9824 gen_atmfield_code(compiler_state_t *cstate, int atmfield, in gen_atmfield_code() argument
9831 if (setjmp(cstate->top_ctx)) in gen_atmfield_code()
9834 return gen_atmfield_code_internal(cstate, atmfield, jvalue, jtype, in gen_atmfield_code()
9839 gen_atmtype_abbrev(compiler_state_t *cstate, int type) in gen_atmtype_abbrev() argument
9847 if (setjmp(cstate->top_ctx)) in gen_atmtype_abbrev()
9854 if (!cstate->is_atm) in gen_atmtype_abbrev()
9855 bpf_error(cstate, "'metac' supported only on raw ATM"); in gen_atmtype_abbrev()
9856 b1 = gen_atmtype_metac(cstate); in gen_atmtype_abbrev()
9861 if (!cstate->is_atm) in gen_atmtype_abbrev()
9862 bpf_error(cstate, "'bcc' supported only on raw ATM"); in gen_atmtype_abbrev()
9863 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmtype_abbrev()
9864 b1 = gen_atmfield_code_internal(cstate, A_VCI, 2, BPF_JEQ, 0); in gen_atmtype_abbrev()
9870 if (!cstate->is_atm) in gen_atmtype_abbrev()
9871 bpf_error(cstate, "'oam4sc' supported only on raw ATM"); in gen_atmtype_abbrev()
9872 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmtype_abbrev()
9873 b1 = gen_atmfield_code_internal(cstate, A_VCI, 3, BPF_JEQ, 0); in gen_atmtype_abbrev()
9879 if (!cstate->is_atm) in gen_atmtype_abbrev()
9880 bpf_error(cstate, "'oam4ec' supported only on raw ATM"); in gen_atmtype_abbrev()
9881 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmtype_abbrev()
9882 b1 = gen_atmfield_code_internal(cstate, A_VCI, 4, BPF_JEQ, 0); in gen_atmtype_abbrev()
9888 if (!cstate->is_atm) in gen_atmtype_abbrev()
9889 bpf_error(cstate, "'sc' supported only on raw ATM"); in gen_atmtype_abbrev()
9890 b1 = gen_atmtype_sc(cstate); in gen_atmtype_abbrev()
9895 if (!cstate->is_atm) in gen_atmtype_abbrev()
9896 bpf_error(cstate, "'ilmic' supported only on raw ATM"); in gen_atmtype_abbrev()
9897 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmtype_abbrev()
9898 b1 = gen_atmfield_code_internal(cstate, A_VCI, 16, BPF_JEQ, 0); in gen_atmtype_abbrev()
9904 if (!cstate->is_atm) in gen_atmtype_abbrev()
9905 bpf_error(cstate, "'lane' supported only on raw ATM"); in gen_atmtype_abbrev()
9906 b1 = gen_atmfield_code_internal(cstate, A_PROTOTYPE, PT_LANE, BPF_JEQ, 0); in gen_atmtype_abbrev()
9916 PUSH_LINKHDR(cstate, DLT_EN10MB, 0, in gen_atmtype_abbrev()
9917 cstate->off_payload + 2, /* Ethernet header */ in gen_atmtype_abbrev()
9919 cstate->off_linktype.constant_part = cstate->off_linkhdr.constant_part + 12; in gen_atmtype_abbrev()
9920 cstate->off_linkpl.constant_part = cstate->off_linkhdr.constant_part + 14; /* Ethernet */ in gen_atmtype_abbrev()
9921 cstate->off_nl = 0; /* Ethernet II */ in gen_atmtype_abbrev()
9922 cstate->off_nl_nosnap = 3; /* 802.3+802.2 */ in gen_atmtype_abbrev()
9927 if (!cstate->is_atm) in gen_atmtype_abbrev()
9928 bpf_error(cstate, "'llc' supported only on raw ATM"); in gen_atmtype_abbrev()
9929 b1 = gen_atmtype_llc(cstate); in gen_atmtype_abbrev()
9946 gen_mtp2type_abbrev(compiler_state_t *cstate, int type) in gen_mtp2type_abbrev() argument
9954 if (setjmp(cstate->top_ctx)) in gen_mtp2type_abbrev()
9960 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
9961 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
9962 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
9963 bpf_error(cstate, "'fisu' supported only on MTP2"); in gen_mtp2type_abbrev()
9965 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B, in gen_mtp2type_abbrev()
9970 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
9971 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
9972 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
9973 bpf_error(cstate, "'lssu' supported only on MTP2"); in gen_mtp2type_abbrev()
9974 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B, in gen_mtp2type_abbrev()
9976 b1 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B, in gen_mtp2type_abbrev()
9982 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
9983 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
9984 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
9985 bpf_error(cstate, "'msu' supported only on MTP2"); in gen_mtp2type_abbrev()
9986 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B, in gen_mtp2type_abbrev()
9991 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
9992 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
9993 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
9994 bpf_error(cstate, "'hfisu' supported only on MTP2_HSL"); in gen_mtp2type_abbrev()
9996 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H, in gen_mtp2type_abbrev()
10001 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
10002 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
10003 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
10004 bpf_error(cstate, "'hlssu' supported only on MTP2_HSL"); in gen_mtp2type_abbrev()
10005 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H, in gen_mtp2type_abbrev()
10007 b1 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H, in gen_mtp2type_abbrev()
10013 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
10014 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
10015 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
10016 bpf_error(cstate, "'hmsu' supported only on MTP2_HSL"); in gen_mtp2type_abbrev()
10017 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H, in gen_mtp2type_abbrev()
10033 gen_mtp3field_code(compiler_state_t *cstate, int mtp3field, in gen_mtp3field_code() argument
10048 if (setjmp(cstate->top_ctx)) in gen_mtp3field_code()
10051 newoff_sio = cstate->off_sio; in gen_mtp3field_code()
10052 newoff_opc = cstate->off_opc; in gen_mtp3field_code()
10053 newoff_dpc = cstate->off_dpc; in gen_mtp3field_code()
10054 newoff_sls = cstate->off_sls; in gen_mtp3field_code()
10062 if (cstate->off_sio == OFFSET_NOT_SET) in gen_mtp3field_code()
10063 bpf_error(cstate, "'sio' supported only on SS7"); in gen_mtp3field_code()
10066 bpf_error(cstate, "sio value %u too big; max value = 255", in gen_mtp3field_code()
10068 b0 = gen_ncmp(cstate, OR_PACKET, newoff_sio, BPF_B, 0xffffffffU, in gen_mtp3field_code()
10077 if (cstate->off_opc == OFFSET_NOT_SET) in gen_mtp3field_code()
10078 bpf_error(cstate, "'opc' supported only on SS7"); in gen_mtp3field_code()
10081 bpf_error(cstate, "opc value %u too big; max value = 16383", in gen_mtp3field_code()
10092 b0 = gen_ncmp(cstate, OR_PACKET, newoff_opc, BPF_W, 0x00c0ff0fU, in gen_mtp3field_code()
10101 if (cstate->off_dpc == OFFSET_NOT_SET) in gen_mtp3field_code()
10102 bpf_error(cstate, "'dpc' supported only on SS7"); in gen_mtp3field_code()
10105 bpf_error(cstate, "dpc value %u too big; max value = 16383", in gen_mtp3field_code()
10114 b0 = gen_ncmp(cstate, OR_PACKET, newoff_dpc, BPF_W, 0xff3f0000U, in gen_mtp3field_code()
10123 if (cstate->off_sls == OFFSET_NOT_SET) in gen_mtp3field_code()
10124 bpf_error(cstate, "'sls' supported only on SS7"); in gen_mtp3field_code()
10127 bpf_error(cstate, "sls value %u too big; max value = 15", in gen_mtp3field_code()
10132 b0 = gen_ncmp(cstate, OR_PACKET, newoff_sls, BPF_B, 0xf0U, in gen_mtp3field_code()
10143 gen_msg_abbrev(compiler_state_t *cstate, int type) in gen_msg_abbrev() argument
10154 b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, SETUP, BPF_JEQ, 0); in gen_msg_abbrev()
10158 b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, CALL_PROCEED, BPF_JEQ, 0); in gen_msg_abbrev()
10162 b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, CONNECT, BPF_JEQ, 0); in gen_msg_abbrev()
10166 b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, CONNECT_ACK, BPF_JEQ, 0); in gen_msg_abbrev()
10170 b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, RELEASE, BPF_JEQ, 0); in gen_msg_abbrev()
10174 b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, RELEASE_DONE, BPF_JEQ, 0); in gen_msg_abbrev()
10184 gen_atmmulti_abbrev(compiler_state_t *cstate, int type) in gen_atmmulti_abbrev() argument
10192 if (setjmp(cstate->top_ctx)) in gen_atmmulti_abbrev()
10198 if (!cstate->is_atm) in gen_atmmulti_abbrev()
10199 bpf_error(cstate, "'oam' supported only on raw ATM"); in gen_atmmulti_abbrev()
10201 b0 = gen_atmfield_code_internal(cstate, A_VCI, 3, BPF_JEQ, 0); in gen_atmmulti_abbrev()
10202 b1 = gen_atmfield_code_internal(cstate, A_VCI, 4, BPF_JEQ, 0); in gen_atmmulti_abbrev()
10204 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmmulti_abbrev()
10209 if (!cstate->is_atm) in gen_atmmulti_abbrev()
10210 bpf_error(cstate, "'oamf4' supported only on raw ATM"); in gen_atmmulti_abbrev()
10212 b0 = gen_atmfield_code_internal(cstate, A_VCI, 3, BPF_JEQ, 0); in gen_atmmulti_abbrev()
10213 b1 = gen_atmfield_code_internal(cstate, A_VCI, 4, BPF_JEQ, 0); in gen_atmmulti_abbrev()
10215 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmmulti_abbrev()
10224 if (!cstate->is_atm) in gen_atmmulti_abbrev()
10225 bpf_error(cstate, "'connectmsg' supported only on raw ATM"); in gen_atmmulti_abbrev()
10226 b0 = gen_msg_abbrev(cstate, A_SETUP); in gen_atmmulti_abbrev()
10227 b1 = gen_msg_abbrev(cstate, A_CALLPROCEED); in gen_atmmulti_abbrev()
10229 b0 = gen_msg_abbrev(cstate, A_CONNECT); in gen_atmmulti_abbrev()
10231 b0 = gen_msg_abbrev(cstate, A_CONNECTACK); in gen_atmmulti_abbrev()
10233 b0 = gen_msg_abbrev(cstate, A_RELEASE); in gen_atmmulti_abbrev()
10235 b0 = gen_msg_abbrev(cstate, A_RELEASE_DONE); in gen_atmmulti_abbrev()
10237 b0 = gen_atmtype_sc(cstate); in gen_atmmulti_abbrev()
10242 if (!cstate->is_atm) in gen_atmmulti_abbrev()
10243 bpf_error(cstate, "'metaconnect' supported only on raw ATM"); in gen_atmmulti_abbrev()
10244 b0 = gen_msg_abbrev(cstate, A_SETUP); in gen_atmmulti_abbrev()
10245 b1 = gen_msg_abbrev(cstate, A_CALLPROCEED); in gen_atmmulti_abbrev()
10247 b0 = gen_msg_abbrev(cstate, A_CONNECT); in gen_atmmulti_abbrev()
10249 b0 = gen_msg_abbrev(cstate, A_RELEASE); in gen_atmmulti_abbrev()
10251 b0 = gen_msg_abbrev(cstate, A_RELEASE_DONE); in gen_atmmulti_abbrev()
10253 b0 = gen_atmtype_metac(cstate); in gen_atmmulti_abbrev()