Lines Matching defs:cstate
427 bpf_set_error(compiler_state_t *cstate, const char *fmt, ...)
440 if (!cstate->error_set) {
442 (void)vsnprintf(cstate->bpf_pcap->errbuf, PCAP_ERRBUF_SIZE,
445 cstate->error_set = 1;
457 bpf_error(compiler_state_t *cstate, const char *fmt, ...)
462 (void)vsnprintf(cstate->bpf_pcap->errbuf, PCAP_ERRBUF_SIZE,
465 longjmp(cstate->top_ctx, 1);
478 static void initchunks(compiler_state_t *cstate);
479 static void *newchunk_nolongjmp(compiler_state_t *cstate, size_t);
480 static void *newchunk(compiler_state_t *cstate, size_t);
481 static void freechunks(compiler_state_t *cstate);
482 static inline struct block *new_block(compiler_state_t *cstate, int);
483 static inline struct slist *new_stmt(compiler_state_t *cstate, int);
484 static struct block *gen_retblk(compiler_state_t *cstate, int);
485 static inline void syntax(compiler_state_t *cstate);
579 static struct block *gen_geneve_ll_check(compiler_state_t *cstate);
588 initchunks(compiler_state_t *cstate)
593 cstate->chunks[i].n_left = 0;
594 cstate->chunks[i].m = NULL;
596 cstate->cur_chunk = 0;
600 newchunk_nolongjmp(compiler_state_t *cstate, size_t n)
614 cp = &cstate->chunks[cstate->cur_chunk];
617 k = ++cstate->cur_chunk;
619 bpf_set_error(cstate, "out of memory");
625 bpf_set_error(cstate, "out of memory");
631 bpf_set_error(cstate, "out of memory");
640 newchunk(compiler_state_t *cstate, size_t n)
644 p = newchunk_nolongjmp(cstate, n);
646 longjmp(cstate->top_ctx, 1);
653 freechunks(compiler_state_t *cstate)
658 if (cstate->chunks[i].m != NULL)
659 free(cstate->chunks[i].m);
669 sdup(compiler_state_t *cstate, const char *s)
672 char *cp = newchunk_nolongjmp(cstate, n);
681 new_block(compiler_state_t *cstate, int code)
685 p = (struct block *)newchunk(cstate, sizeof(*p));
693 new_stmt(compiler_state_t *cstate, int code)
697 p = (struct slist *)newchunk(cstate, sizeof(*p));
704 gen_retblk(compiler_state_t *cstate, int v)
706 struct block *b = new_block(cstate, BPF_RET|BPF_K);
713 syntax(compiler_state_t *cstate)
715 bpf_error(cstate, "syntax error in filter expression");
725 compiler_state_t cstate;
770 initchunks(&cstate);
771 cstate.no_optimize = 0;
773 cstate.ai = NULL;
775 cstate.e = NULL;
776 cstate.ic.root = NULL;
777 cstate.ic.cur_mark = 0;
778 cstate.bpf_pcap = p;
779 cstate.error_set = 0;
780 init_regs(&cstate);
782 cstate.netmask = mask;
784 cstate.snaplen = pcap_snapshot(p);
785 if (cstate.snaplen == 0) {
804 pcap_set_extra(&cstate, scanner);
806 if (init_linktype(&cstate, p) == -1) {
810 if (pcap_parse(scanner, &cstate) != 0) {
812 if (cstate.ai != NULL)
813 freeaddrinfo(cstate.ai);
815 if (cstate.e != NULL)
816 free(cstate.e);
821 if (cstate.ic.root == NULL) {
825 if (setjmp(cstate.top_ctx)) {
829 cstate.ic.root = gen_retblk(&cstate, cstate.snaplen);
832 if (optimize && !cstate.no_optimize) {
833 if (bpf_optimize(&cstate.ic, p->errbuf) == -1) {
838 if (cstate.ic.root == NULL ||
839 (cstate.ic.root->s.code == (BPF_RET|BPF_K) && cstate.ic.root->s.k == 0)) {
846 program->bf_insns = icode_to_fcode(&cstate.ic,
847 cstate.ic.root, &len, p->errbuf);
869 freechunks(&cstate);
949 finish_parse(compiler_state_t *cstate, struct block *p)
957 if (setjmp(cstate->top_ctx))
979 insert_compute_vloffsets(cstate, p->head);
994 ppi_dlt_check = gen_ppi_dlt_check(cstate);
998 backpatch(p, gen_retblk(cstate, cstate->snaplen));
1000 backpatch(p, gen_retblk(cstate, 0));
1001 cstate->ic.root = p->head;
1033 gen_cmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset,
1036 return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JEQ, 0, v);
1040 gen_cmp_gt(compiler_state_t *cstate, enum e_offrel offrel, u_int offset,
1043 return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JGT, 0, v);
1047 gen_cmp_ge(compiler_state_t *cstate, enum e_offrel offrel, u_int offset,
1050 return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JGE, 0, v);
1054 gen_cmp_lt(compiler_state_t *cstate, enum e_offrel offrel, u_int offset,
1057 return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JGE, 1, v);
1061 gen_cmp_le(compiler_state_t *cstate, enum e_offrel offrel, u_int offset,
1064 return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JGT, 1, v);
1068 gen_mcmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset,
1071 return gen_ncmp(cstate, offrel, offset, size, mask, BPF_JEQ, 0, v);
1075 gen_bcmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset,
1084 tmp = gen_cmp(cstate, offrel, offset + size - 4, BPF_W,
1094 tmp = gen_cmp(cstate, offrel, offset + size - 2, BPF_H,
1102 tmp = gen_cmp(cstate, offrel, offset, BPF_B, v[0]);
1117 gen_ncmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset,
1124 s = gen_load_a(cstate, offrel, offset, size);
1127 s2 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K);
1132 b = new_block(cstate, JMP(jtype));
1141 init_linktype(compiler_state_t *cstate, pcap_t *p)
1143 cstate->pcap_fddipad = p->fddipad;
1148 cstate->outermostlinktype = pcap_datalink(p);
1149 cstate->off_outermostlinkhdr.constant_part = 0;
1150 cstate->off_outermostlinkhdr.is_variable = 0;
1151 cstate->off_outermostlinkhdr.reg = -1;
1153 cstate->prevlinktype = cstate->outermostlinktype;
1154 cstate->off_prevlinkhdr.constant_part = 0;
1155 cstate->off_prevlinkhdr.is_variable = 0;
1156 cstate->off_prevlinkhdr.reg = -1;
1158 cstate->linktype = cstate->outermostlinktype;
1159 cstate->off_linkhdr.constant_part = 0;
1160 cstate->off_linkhdr.is_variable = 0;
1161 cstate->off_linkhdr.reg = -1;
1166 cstate->off_linkpl.constant_part = 0;
1167 cstate->off_linkpl.is_variable = 0;
1168 cstate->off_linkpl.reg = -1;
1170 cstate->off_linktype.constant_part = 0;
1171 cstate->off_linktype.is_variable = 0;
1172 cstate->off_linktype.reg = -1;
1177 cstate->is_atm = 0;
1178 cstate->off_vpi = OFFSET_NOT_SET;
1179 cstate->off_vci = OFFSET_NOT_SET;
1180 cstate->off_proto = OFFSET_NOT_SET;
1181 cstate->off_payload = OFFSET_NOT_SET;
1186 cstate->is_geneve = 0;
1191 cstate->is_vlan_vloffset = 0;
1196 cstate->off_li = OFFSET_NOT_SET;
1197 cstate->off_li_hsl = OFFSET_NOT_SET;
1198 cstate->off_sio = OFFSET_NOT_SET;
1199 cstate
1200 cstate->off_dpc = OFFSET_NOT_SET;
1201 cstate->off_sls = OFFSET_NOT_SET;
1203 cstate->label_stack_depth = 0;
1204 cstate->vlan_stack_depth = 0;
1206 switch (cstate->linktype) {
1209 cstate->off_linktype.constant_part = 2;
1210 cstate->off_linkpl.constant_part = 6;
1211 cstate->off_nl = 0; /* XXX in reality, variable! */
1212 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */
1216 cstate->off_linktype.constant_part = 4;
1217 cstate->off_linkpl.constant_part = 8;
1218 cstate->off_nl = 0; /* XXX in reality, variable! */
1219 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */
1223 cstate->off_linktype.constant_part = 12;
1224 cstate->off_linkpl.constant_part = 14; /* Ethernet header length */
1225 cstate->off_nl = 0; /* Ethernet II */
1226 cstate->off_nl_nosnap = 3; /* 802.3+802.2 */
1234 cstate->off_linktype.constant_part = OFFSET_NOT_SET;
1235 cstate->off_linkpl.constant_part = 16;
1236 cstate->off_nl = 0;
1237 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */
1242 cstate->off_linktype.constant_part = OFFSET_NOT_SET;
1244 cstate->off_linkpl.constant_part = 24;
1245 cstate->off_nl = 0;
1246 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */
1251 cstate->off_linktype.constant_part = 0;
1252 cstate->off_linkpl.constant_part = 4;
1253 cstate->off_nl = 0;
1254 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */
1258 cstate->off_linktype.constant_part = 0;
1259 cstate->off_linkpl.constant_part = 12;
1260 cstate->off_nl = 0;
1261 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */
1269 cstate->off_linktype.constant_part = 2; /* skip HDLC-like framing */
1270 cstate->off_linkpl.constant_part = 4; /* skip HDLC-like framing and protocol field */
1271 cstate->off_nl = 0;
1272 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */
1280 cstate->off_linktype.constant_part = 6;
1281 cstate->off_linkpl.constant_part = 8;
1282 cstate->off_nl = 0;
1283 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */
1287 cstate->off_linktype.constant_part = 5;
1288 cstate->off_linkpl.constant_part = 24;
1289 cstate->off_nl = 0;
1290 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */
1302 cstate->off_linktype.constant_part = 13;
1303 cstate->off_linktype.constant_part += cstate->pcap_fddipad;
1304 cstate->off_linkpl.constant_part = 13; /* FDDI MAC header length */
1305 cstate->off_linkpl.constant_part += cstate->pcap_fddipad;
1306 cstate->off_nl = 8; /* 802.2+SNAP */
1307 cstate->off_nl_nosnap = 3; /* 802.2 */
1334 cstate->off_linktype.constant_part = 14;
1335 cstate->off_linkpl.constant_part = 14; /* Token Ring MAC header length */
1336 cstate->off_nl = 8; /* 802.2+SNAP */
1337 cstate->off_nl_nosnap = 3; /* 802.2 */
1343 cstate->off_linkhdr.is_variable = 1;
1367 cstate->off_linktype.constant_part = 24;
1368 cstate->off_linkpl.constant_part = 0; /* link-layer header is variable-length */
1369 cstate->off_linkpl.is_variable = 1;
1370 cstate->off_nl = 8; /* 802.2+SNAP */
1371 cstate->off_nl_nosnap = 3; /* 802.2 */
1384 cstate->off_linktype.constant_part = 24;
1385 cstate->off_linkpl.constant_part = 0; /* link-layer header is variable-length */
1386 cstate->off_linkpl.is_variable = 1;
1387 cstate->off_linkhdr.is_variable = 1;
1388 cstate->off_nl = 8; /* 802.2+SNAP */
1389 cstate->off_nl_nosnap = 3; /* 802.2 */
1405 cstate->off_linktype.constant_part = 0;
1406 cstate->off_linkpl.constant_part = 0; /* packet begins with LLC header */
1407 cstate->off_nl = 8; /* 802.2+SNAP */
1408 cstate->off_nl_nosnap = 3; /* 802.2 */
1416 cstate->is_atm = 1;
1417 cstate->off_vpi = SUNATM_VPI_POS;
1418 cstate->off_vci = SUNATM_VCI_POS;
1419 cstate->off_proto = PROTO_POS;
1420 cstate->off_payload = SUNATM_PKT_BEGIN_POS;
1421 cstate->off_linktype.constant_part = cstate->off_payload;
1422 cstate->off_linkpl.constant_part = cstate->off_payload; /* if LLC-encapsulated */
1423 cstate->off_nl = 8; /* 802.2+SNAP */
1424 cstate->off_nl_nosnap = 3; /* 802.2 */
1430 cstate->off_linktype.constant_part = OFFSET_NOT_SET;
1431 cstate->off_linkpl.constant_part = 0;
1432 cstate->off_nl = 0;
1433 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */
1437 cstate->off_linktype.constant_part = 14;
1438 cstate->off_linkpl.constant_part = 16;
1439 cstate->off_nl = 0;
1440 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */
1444 cstate->off_linktype.constant_part = 0;
1445 cstate->off_linkpl.constant_part = 20;
1446 cstate->off_nl = 0;
1447 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */
1456 cstate->off_linktype.constant_part = OFFSET_NOT_SET;
1457 cstate->off_linkpl.constant_part = 0;
1458 cstate->off_nl = 0;
1459 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */
1473 cstate->off_linktype.constant_part = 16;
1474 cstate->off_linkpl.constant_part = 16;
1475 cstate->off_nl = 8; /* 802.2+SNAP */
1476 cstate->off_nl_nosnap = 3; /* 802.2 */
1484 cstate->off_linktype.constant_part = OFFSET_NOT_SET;
1485 cstate->off_linkpl.constant_part = 0;
1486 cstate->off_nl = 0;
1487 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */
1496 cstate->off_linktype.constant_part = OFFSET_NOT_SET;
1497 cstate->off_linkpl.constant_part = 0;
1498 cstate->off_nl = 4;
1499 cstate->off_nl_nosnap = 0; /* XXX - for now -> no 802.2 LLC */
1503 cstate->off_linktype.constant_part = 16;
1504 cstate->off_linkpl.constant_part = 18;
1505 cstate->off_nl = 0;
1506 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */
1510 cstate->off_linktype.constant_part = 6;
1511 cstate->off_linkpl.constant_part = 44;
1512 cstate->off_nl = 0; /* Ethernet II */
1513 cstate->off_nl_nosnap = 0; /* XXX - what does it do with 802.3 packets? */
1517 cstate->off_linktype.constant_part = 0;
1518 cstate->off_linkpl.constant_part = 0; /* link-layer header is variable-length */
1519 cstate->off_linkpl.is_variable = 1;
1520 cstate->off_nl = 0;
1521 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */
1530 cstate->off_linktype.constant_part = 4;
1531 cstate->off_linkpl.constant_part = 4;
1532 cstate->off_nl = 0;
1533 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */
1537 cstate->off_linktype.constant_part = 4; /* in reality variable between 4-8 */
1538 cstate->off_linkpl.constant_part = 4; /* in reality variable between 4-8 */
1539 cstate->off_nl = 0;
1540 cstate->off_nl_nosnap = 10;
1544 cstate->off_linktype.constant_part = 8; /* in reality variable between 8-12 */
1545 cstate->off_linkpl.constant_part = 8; /* in reality variable between 8-12 */
1546 cstate->off_nl = 0;
1547 cstate->off_nl_nosnap = 10;
1554 cstate->off_linkpl.constant_part = 14;
1555 cstate->off_linktype.constant_part = 16;
1556 cstate->off_nl = 18; /* Ethernet II */
1557 cstate->off_nl_nosnap = 21; /* 802.3+802.2 */
1561 cstate->off_linktype.constant_part = 4;
1562 cstate->off_linkpl.constant_part = 6;
1563 cstate->off_nl = 0;
1564 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */
1568 cstate->off_linktype.constant_part = 6;
1569 cstate->off_linkpl.constant_part = 12;
1570 cstate->off_nl = 0;
1571 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */
1575 cstate->off_linktype.constant_part = 6;
1576 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; /* not really a network layer but raw IP addresses */
1577 cstate->off_nl = OFFSET_NOT_SET; /* not really a network layer but raw IP addresses */
1578 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */
1582 cstate->off_linktype.constant_part = 12;
1583 cstate->off_linkpl.constant_part = 12;
1584 cstate->off_nl = 0; /* raw IP/IP6 header */
1585 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */
1589 cstate->off_linktype.constant_part = OFFSET_NOT_SET;
1590 cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
1591 cstate->off_nl = OFFSET_NOT_SET;
1592 cstate->off_nl_nosnap = OFFSET_NOT_SET;
1596 cstate->off_linktype.constant_part = 12;
1597 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; /* L3 proto location dep. on cookie type */
1598 cstate->off_nl = OFFSET_NOT_SET; /* L3 proto location dep. on cookie type */
1599 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */
1603 cstate->off_linktype.constant_part = 18;
1604 cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
1605 cstate->off_nl = OFFSET_NOT_SET;
1606 cstate->off_nl_nosnap = OFFSET_NOT_SET;
1610 cstate->off_linktype.constant_part = 18;
1611 cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
1612 cstate->off_nl = OFFSET_NOT_SET;
1613 cstate->off_nl_nosnap = OFFSET_NOT_SET;
1617 cstate->off_linktype.constant_part = 8;
1618 cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
1619 cstate->off_nl = OFFSET_NOT_SET;
1620 cstate->off_nl_nosnap = OFFSET_NOT_SET;
1627 cstate->off_linktype.constant_part = 8;
1628 cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
1629 cstate->off_nl = OFFSET_NOT_SET;
1630 cstate->off_nl_nosnap = OFFSET_NOT_SET;
1634 cstate->off_li = 2;
1635 cstate->off_li_hsl = 4;
1636 cstate->off_sio = 3;
1637 cstate->off_opc = 4;
1638 cstate->off_dpc = 4;
1639 cstate->off_sls = 7;
1640 cstate->off_linktype.constant_part = OFFSET_NOT_SET;
1641 cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
1642 cstate->off_nl = OFFSET_NOT_SET;
1643 cstate->off_nl_nosnap = OFFSET_NOT_SET;
1647 cstate->off_li = 6;
1648 cstate->off_li_hsl = 8;
1649 cstate->off_sio = 7;
1650 cstate->off_opc = 8;
1651 cstate->off_dpc = 8;
1652 cstate->off_sls = 11;
1653 cstate->off_linktype.constant_part = OFFSET_NOT_SET;
1654 cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
1655 cstate->off_nl = OFFSET_NOT_SET;
1656 cstate->off_nl_nosnap = OFFSET_NOT_SET;
1660 cstate->off_li = 22;
1661 cstate->off_li_hsl = 24;
1662 cstate->off_sio = 23;
1663 cstate->off_opc = 24;
1664 cstate->off_dpc = 24;
1665 cstate->off_sls = 27;
1666 cstate->off_linktype.constant_part = OFFSET_NOT_SET;
1667 cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
1668 cstate->off_nl = OFFSET_NOT_SET;
1669 cstate->off_nl_nosnap = OFFSET_NOT_SET;
1673 cstate->off_linktype.constant_part = OFFSET_NOT_SET;
1674 cstate->off_linkpl.constant_part = 4;
1675 cstate->off_nl = 0;
1676 cstate->off_nl_nosnap = 0;
1683 cstate->off_linktype.constant_part = OFFSET_NOT_SET; /* variable, min 15, max 71 steps of 7 */
1684 cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
1685 cstate->off_nl = OFFSET_NOT_SET; /* variable, min 16, max 71 steps of 7 */
1686 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */
1690 cstate->off_linktype.constant_part = 1;
1691 cstate->off_linkpl.constant_part = 24; /* ipnet header length */
1692 cstate->off_nl = 0;
1693 cstate->off_nl_nosnap = OFFSET_NOT_SET;
1697 cstate
1698 cstate->off_linktype.constant_part = cstate->off_linkhdr.constant_part + 12;
1699 cstate->off_linkpl.constant_part = cstate->off_linkhdr.constant_part + 14; /* pseudo-header+Ethernet header length */
1700 cstate->off_nl = 0; /* Ethernet II */
1701 cstate->off_nl_nosnap = 3; /* 802.3+802.2 */
1705 cstate->off_linkhdr.constant_part = 12; /* MAC header is past 4-byte pseudo-header, preamble, and SFD */
1706 cstate->off_linktype.constant_part = cstate->off_linkhdr.constant_part + 12;
1707 cstate->off_linkpl.constant_part = cstate->off_linkhdr.constant_part + 14; /* pseudo-header+preamble+SFD+Ethernet header length */
1708 cstate->off_nl = 0; /* Ethernet II */
1709 cstate->off_nl_nosnap = 3; /* 802.3+802.2 */
1717 if (cstate->linktype >= DLT_HIGH_MATCHING_MIN &&
1718 cstate->linktype <= DLT_HIGH_MATCHING_MAX) {
1719 cstate->off_linktype.constant_part = OFFSET_NOT_SET;
1720 cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
1721 cstate->off_nl = OFFSET_NOT_SET;
1722 cstate->off_nl_nosnap = OFFSET_NOT_SET;
1724 bpf_set_error(cstate, "unknown data link type %d (min %d, max %d)",
1725 cstate->linktype, DLT_HIGH_MATCHING_MIN, DLT_HIGH_MATCHING_MAX);
1731 cstate->off_outermostlinkhdr = cstate->off_prevlinkhdr = cstate->off_linkhdr;
1739 gen_load_absoffsetrel(compiler_state_t *cstate, bpf_abs_offset *abs_offset,
1744 s = gen_abs_offset_varpart(cstate, abs_offset);
1761 s2 = new_stmt(cstate, BPF_LD|BPF_IND|size);
1769 s = new_stmt(cstate, BPF_LD|BPF_ABS|size);
1779 gen_load_a(compiler_state_t *cstate, enum e_offrel offrel, u_int offset,
1800 s = new_stmt(cstate, BPF_LD|BPF_ABS|size);
1805 s = gen_load_absoffsetrel(cstate, &cstate->off_linkhdr, offset, size);
1809 s = gen_load_absoffsetrel(cstate, &cstate->off_prevlinkhdr, offset, size);
1813 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, offset, size);
1817 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, cstate->off_nl - 4 + offset, size);
1821 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, cstate->off_nl + offset, size);
1825 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, cstate->off_nl_nosnap + offset, size);
1829 s = gen_load_absoffsetrel(cstate, &cstate->off_linktype, offset, size);
1839 s = gen_loadx_iphdrlen(cstate);
1852 s2 = new_stmt(cstate, BPF_LD|BPF_IND|size);
1853 s2->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + offset;
1858 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, cstate->off_nl + 40 + offset, size);
1870 gen_loadx_iphdrlen(compiler_state_t *cstate)
1874 s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl);
1886 s2 = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B);
1887 s2->s.k = cstate->off_linkpl.constant_part + cstate->off_nl;
1889 s2 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K);
1892 s2 = new_stmt(cstate, BPF_ALU|BPF_LSH|BPF_K);
1902 sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X));
1903 sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX));
1912 * is at an offset of cstate->off_nl from the beginning of
1914 * cstate->off_linkpl.constant_part + cstate->off_nl from the beginning
1917 s = new_stmt(cstate, BPF_LDX|BPF_MSH|BPF_B);
1918 s->s.k = cstate->off_linkpl.constant_part + cstate->off_nl;
1925 gen_uncond(compiler_state_t *cstate, int rsense)
1930 s = new_stmt(cstate, BPF_LD|BPF_IMM);
1932 b = new_block(cstate, JMP(BPF_JEQ));
1939 gen_true(compiler_state_t *cstate)
1941 return gen_uncond(cstate, 1);
1945 gen_false(compiler_state_t *cstate)
1947 return gen_uncond(cstate, 0);
1968 gen_ether_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto)
1989 b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU);
1991 b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, (ll_proto << 8) | ll_proto);
2028 b0 = gen_cmp(cstate, OR_LLC, 0, BPF_B, LLCSAP_IPX);
2029 b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, 0xFFFF);
2036 b0 = gen_snap(cstate, 0x000000, ETHERTYPE_IPX);
2043 b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU);
2059 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ETHERTYPE_IPX);
2075 b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU);
2090 b1 = gen_snap(cstate, 0x080007, ETHERTYPE_ATALK);
2092 b1 = gen_snap(cstate, 0x000000, ETHERTYPE_AARP);
2100 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ll_proto);
2115 b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU);
2117 b1 = gen_cmp(cstate, OR_LINKTYPE, 2, BPF_B, ll_proto);
2130 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ll_proto);
2136 gen_loopback_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto)
2151 if (cstate->linktype == DLT_NULL || cstate->linktype == DLT_ENC) {
2163 if (cstate->bpf_pcap->rfile != NULL && cstate->bpf_pcap->swapped)
2167 return (gen_cmp(cstate, OR_LINKHDR, 0, BPF_W, ll_proto));
2175 gen_ipnet_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto)
2180 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, IPH_AF_INET);
2184 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, IPH_AF_INET6);
2191 return gen_false(cstate);
2203 gen_linux_sll_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto)
2224 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, LINUX_SLL_P_802_2);
2225 b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, (ll_proto << 8) | ll_proto);
2255 b0 = gen_cmp(cstate, OR_LLC, 0, BPF_B, LLCSAP_IPX);
2256 b1 = gen_snap(cstate, 0x000000, ETHERTYPE_IPX);
2258 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, LINUX_SLL_P_802_2);
2265 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, LINUX_SLL_P_802_3);
2273 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ETHERTYPE_IPX);
2289 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, LINUX_SLL_P_802_2);
2303 b1 = gen_snap(cstate, 0x080007, ETHERTYPE_ATALK);
2305 b1 = gen_snap(cstate, 0x000000, ETHERTYPE_AARP);
2313 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ll_proto);
2327 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, LINUX_SLL_P_802_2);
2328 b1 = gen_cmp(cstate, OR_LINKHDR, cstate->off_linkpl.constant_part, BPF_B,
2342 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ll_proto);
2352 gen_load_pflog_llprefixlen(compiler_state_t *cstate)
2363 if (cstate->off_linkpl.reg != -1) {
2367 s1 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS);
2374 s2 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K);
2377 s2 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K);
2385 s2 = new_stmt(cstate, BPF_ST);
2386 s2->s.k = cstate->off_linkpl.reg;
2392 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX);
2401 gen_load_prism_llprefixlen(compiler_state_t *cstate)
2412 cstate->no_optimize = 1;
2433 if (cstate->off_linkhdr.reg != -1) {
2437 s1 = new_stmt(cstate, BPF_LD|BPF_W|BPF_ABS);
2443 s2 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K);
2450 sjeq_avs_cookie = new_stmt(cstate, JMP(BPF_JEQ));
2461 s2 = new_stmt(cstate, BPF_LD|BPF_W|BPF_ABS);
2474 sjcommon = new_stmt(cstate, JMP(BPF_JA));
2484 s2 = new_stmt(cstate, BPF_LD|BPF_W|BPF_IMM);
2494 s2 = new_stmt(cstate, BPF_ST);
2495 s2->s.k = cstate->off_linkhdr.reg;
2502 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX);
2511 gen_load_avs_llprefixlen(compiler_state_t *cstate)
2522 if (cstate->off_linkhdr.reg != -1) {
2528 s1 = new_stmt(cstate, BPF_LD|BPF_W|BPF_ABS);
2535 s2 = new_stmt(cstate, BPF_ST);
2536 s2->s.k = cstate->off_linkhdr.reg;
2542 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX);
2551 gen_load_radiotap_llprefixlen(compiler_state_t *cstate)
2562 if (cstate->off_linkhdr.reg != -1) {
2574 s1 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS);
2576 s2 = new_stmt(cstate, BPF_ALU|BPF_LSH|BPF_K);
2579 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX);
2586 s2 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS);
2589 s2 = new_stmt(cstate, BPF_ALU|BPF_OR|BPF_X);
2596 s2 = new_stmt(cstate, BPF_ST);
2597 s2->s.k = cstate->off_linkhdr.reg;
2603 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX);
2621 gen_load_ppi_llprefixlen(compiler_state_t *cstate)
2630 if (cstate->off_linkhdr.reg != -1) {
2642 s1 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS);
2644 s2 = new_stmt(cstate, BPF_ALU|BPF_LSH|BPF_K);
2647 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX);
2654 s2 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS);
2657 s2 = new_stmt(cstate, BPF_ALU|BPF_OR|BPF_X);
2664 s2 = new_stmt(cstate, BPF_ST);
2665 s2->s.k = cstate->off_linkhdr.reg;
2671 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX);
2687 gen_load_802_11_header_len(compiler_state_t *cstate, struct slist *s, struct slist *snext)
2699 if (cstate->off_linkpl.reg == -1) {
2714 cstate->no_optimize = 1;
2731 * and store it in the cstate->off_linkpl.reg register.
2734 s = new_stmt(cstate, BPF_LDX|BPF_IMM);
2735 s->s.k = cstate->off_outermostlinkhdr.constant_part;
2742 * in cstate->off_linkpl.reg, and then load the Frame Control field,
2745 s2 = new_stmt(cstate, BPF_MISC|BPF_TXA);
2747 s2 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K);
2750 s2 = new_stmt(cstate, BPF_ST);
2751 s2->s.k = cstate->off_linkpl.reg;
2754 s2 = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B);
2763 sjset_data_frame_1 = new_stmt(cstate, JMP(BPF_JSET));
2771 sjset_data_frame_1->s.jt = sjset_data_frame_2 = new_stmt(cstate, JMP(BPF_JSET));
2782 sjset_data_frame_2->s.jf = sjset_qos = new_stmt(cstate, JMP(BPF_JSET));
2787 * If it's set, add 2 to cstate->off_linkpl.reg, to skip the QoS
2792 sjset_qos->s.jt = s2 = new_stmt(cstate, BPF_LD|BPF_MEM);
2793 s2->s.k = cstate->off_linkpl.reg;
2795 s2 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_IMM);
2798 s2 = new_stmt(cstate, BPF_ST);
2799 s2->s.k = cstate->off_linkpl.reg;
2821 if (cstate->linktype == DLT_IEEE802_11_RADIO) {
2826 sjset_qos->s.jf = s2 = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_W);
2830 sjset_radiotap_flags_present = new_stmt(cstate, JMP(BPF_JSET));
2842 sjset_radiotap_ext_present = new_stmt(cstate, JMP(BPF_JSET));
2855 sjset_radiotap_tsft_present = new_stmt(cstate, JMP(BPF_JSET));
2869 s2 = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_B);
2874 sjset_tsft_datapad = new_stmt(cstate, JMP(BPF_JSET));
2886 s2 = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_B);
2891 sjset_notsft_datapad = new_stmt(cstate, JMP(BPF_JSET));
2902 s_roundup = new_stmt(cstate, BPF_LD|BPF_MEM);
2903 s_roundup->s.k = cstate->off_linkpl.reg;
2905 s2 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_IMM);
2908 s2 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_IMM);
2911 s2 = new_stmt(cstate, BPF_ST);
2912 s2->s.k = cstate->off_linkpl.reg;
2926 insert_compute_vloffsets(compiler_state_t *cstate, struct block *b)
2935 if (cstate->off_linkpl.reg != -1 && cstate->off_linkhdr.is_variable &&
2936 cstate->off_linkhdr.reg == -1)
2937 cstate->off_linkhdr.reg = alloc_reg(cstate);
2950 switch (cstate->outermostlinktype) {
2953 s = gen_load_prism_llprefixlen(cstate);
2957 s = gen_load_avs_llprefixlen(cstate);
2961 s = gen_load_radiotap_llprefixlen(cstate);
2965 s = gen_load_ppi_llprefixlen(cstate);
2978 switch (cstate->outermostlinktype) {
2985 s = gen_load_802_11_header_len(cstate, s, b->stmts);
2989 s = gen_load_pflog_llprefixlen(cstate);
2997 if (s == NULL && cstate->is_vlan_vloffset) {
3000 if (cstate->off_linkpl.reg == -1)
3001 cstate->off_linkpl.reg = alloc_reg(cstate);
3002 if (cstate->off_linktype.reg == -1)
3003 cstate->off_linktype.reg = alloc_reg(cstate);
3005 s = new_stmt(cstate, BPF_LD|BPF_W|BPF_IMM);
3007 s2 = new_stmt(cstate, BPF_ST);
3008 s2->s.k = cstate->off_linkpl.reg;
3010 s2 = new_stmt(cstate, BPF_ST);
3011 s2->s.k = cstate->off_linktype.reg;
3028 gen_ppi_dlt_check(compiler_state_t *cstate)
3033 if (cstate->linktype == DLT_PPI)
3037 s_load_dlt = new_stmt(cstate, BPF_LD|BPF_W|BPF_ABS);
3040 b = new_block(cstate, JMP(BPF_JEQ));
3067 gen_abs_offset_varpart(compiler_state_t *cstate, bpf_abs_offset *off)
3078 off->reg = alloc_reg(cstate);
3085 s = new_stmt(cstate, BPF_LDX|BPF_MEM);
3152 gen_prevlinkhdr_check(compiler_state_t *cstate)
3156 if (cstate->is_geneve)
3157 return gen_geneve_ll_check(cstate);
3159 switch (cstate->prevlinktype) {
3169 b0 = gen_cmp(cstate, OR_PREVLINKHDR, SUNATM_PKT_BEGIN_POS, BPF_H, 0xFF00);
3198 gen_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto)
3204 if (cstate->label_stack_depth > 0)
3205 return gen_mpls_linktype(cstate, ll_proto);
3207 switch (cstate->linktype) {
3214 if (!cstate->is_geneve)
3215 b0 = gen_prevlinkhdr_check(cstate);
3219 b1 = gen_ether_linktype(cstate, ll_proto);
3234 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ll_proto);
3246 b0 = gen_check_802_11_data_frame(cstate);
3251 b1 = gen_llc_linktype(cstate, ll_proto);
3260 return gen_llc_linktype(cstate, ll_proto);
3267 return gen_llc_linktype(cstate, ll_proto);
3273 return gen_llc_linktype(cstate, ll_proto);
3284 b0 = gen_atmfield_code_internal(cstate, A_PROTOTYPE, PT_LLC, BPF_JEQ, 0);
3285 b1 = gen_llc_linktype(cstate, ll_proto);
3291 return gen_linux_sll_linktype(cstate, ll_proto);
3308 return gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, 0x40, 0xF0);
3312 return gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, 0x60, 0xF0);
3315 return gen_false(cstate); /* always false */
3324 return gen_true(cstate); /* always true */
3327 return gen_false(cstate);
3335 return gen_true(cstate); /* always true */
3338 return gen_false(cstate);
3349 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H,
3365 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, PPP_IP);
3366 b1 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, PPP_VJC);
3368 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, PPP_VJNC);
3373 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H,
3384 return (gen_loopback_linktype(cstate, AF_INET));
3409 if (cstate->bpf_pcap->rfile != NULL) {
3414 b0 = gen_loopback_linktype(cstate, BSD_AFNUM_INET6_BSD);
3415 b1 = gen_loopback_linktype(cstate, BSD_AFNUM_INET6_FREEBSD);
3417 b0 = gen_loopback_linktype(cstate, BSD_AFNUM_INET6_DARWIN);
3433 return (gen_loopback_linktype(cstate, 24));
3436 return (gen_loopback_linktype(cstate, AF_INET6));
3442 return gen_false(cstate);
3453 return gen_false(cstate);
3462 return (gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, af),
3465 return (gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, af),
3468 return gen_false(cstate);
3480 return gen_false(cstate);
3483 return (gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B,
3487 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B,
3489 b1 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B,
3495 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B,
3497 b1 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B,
3503 return (gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B,
3507 return (gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B,
3515 return gen_true(cstate);
3517 return gen_false(cstate);
3532 return gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | 0xcc);
3538 return gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | 0x8e);
3552 b0 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | ISO8473_CLNP);
3553 b1 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | ISO9542_ESIS);
3554 b2 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | ISO10589_ISIS);
3560 return gen_false(cstate);
3565 bpf_error(cstate, "Multi-link Frame Relay link-layer type filtering not implemented");
3597 return gen_mcmp(cstate, OR_LINKHDR, 0, BPF_W, 0x4d474300, 0xffffff00); /* compare the magic number */
3600 return gen_mcmp(cstate, OR_LINKHDR, 0, BPF_W, 0x55FF0000, 0xffff0000);
3603 return gen_ipnet_linktype(cstate, ll_proto);
3606 bpf_error(cstate, "IrDA link-layer type filtering not implemented");
3609 bpf_error(cstate, "DOCSIS link-layer type filtering not implemented");
3613 bpf_error(cstate, "MTP2 link-layer type filtering not implemented");
3616 bpf_error(cstate, "ERF link-layer type filtering not implemented");
3619 bpf_error(cstate, "PFSYNC link-layer type filtering not implemented");
3622 bpf_error(cstate, "LAPD link-layer type filtering not implemented");
3628 bpf_error(cstate, "USB link-layer type filtering not implemented");
3632 bpf_error(cstate, "Bluetooth link-layer type filtering not implemented");
3636 bpf_error(cstate, "CAN link-layer type filtering not implemented");
3643 bpf_error(cstate, "IEEE 802.15.4 link-layer type filtering not implemented");
3646 bpf_error(cstate, "IEEE 802.16 link-layer type filtering not implemented");
3649 bpf_error(cstate, "SITA link-layer type filtering not implemented");
3652 bpf_error(cstate, "RAIF1 link-layer type filtering not implemented");
3656 bpf_error(cstate, "IPMB link-layer type filtering not implemented");
3659 bpf_error(cstate, "AX.25 link-layer type filtering not implemented");
3666 bpf_error(cstate, "NFLOG link-layer type filtering not implemented");
3675 if (cstate->off_linktype.constant_part != OFFSET_NOT_SET) {
3681 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ll_proto);
3687 description = pcap_datalink_val_to_description_or_dlt(cstate->linktype);
3688 bpf_error(cstate, "%s link-layer type filtering not implemented",
3703 gen_snap(compiler_state_t *cstate, bpf_u_int32 orgcode, bpf_u_int32 ptype)
3715 return gen_bcmp(cstate, OR_LLC, 0, 8, snapblock);
3722 gen_llc_internal(compiler_state_t *cstate)
3726 switch (cstate->linktype) {
3733 b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU);
3740 b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, 0xFFFF);
3749 b0 = gen_atmtype_llc(cstate);
3756 return gen_true(cstate);
3762 return gen_true(cstate);
3773 return gen_true(cstate);
3783 b0 = gen_check_802_11_data_frame(cstate);
3787 bpf_error(cstate, "'llc' not supported for %s",
3788 pcap_datalink_val_to_description_or_dlt(cstate->linktype));
3794 gen_llc(compiler_state_t *cstate)
3800 if (setjmp(cstate->top_ctx))
3803 return gen_llc_internal(cstate);
3807 gen_llc_i(compiler_state_t *cstate)
3816 if (setjmp(cstate->top_ctx))
3822 b0 = gen_llc_internal(cstate);
3828 s = gen_load_a(cstate, OR_LLC, 2, BPF_B);
3829 b1 = new_block(cstate, JMP(BPF_JSET));
3838 gen_llc_s(compiler_state_t *cstate)
3846 if (setjmp(cstate->top_ctx))
3852 b0 = gen_llc_internal(cstate);
3858 b1 = gen_mcmp(cstate, OR_LLC, 2, BPF_B, LLC_S_FMT, 0x03);
3864 gen_llc_u(compiler_state_t *cstate)
3872 if (setjmp(cstate->top_ctx))
3878 b0 = gen_llc_internal(cstate);
3884 b1 = gen_mcmp(cstate, OR_LLC, 2, BPF_B, LLC_U_FMT, 0x03);
3890 gen_llc_s_subtype(compiler_state_t *cstate, bpf_u_int32 subtype)
3898 if (setjmp(cstate->top_ctx))
3904 b0 = gen_llc_internal(cstate);
3909 b1 = gen_mcmp(cstate, OR_LLC, 2, BPF_B, subtype, LLC_S_CMD_MASK);
3915 gen_llc_u_subtype(compiler_state_t *cstate, bpf_u_int32 subtype)
3923 if (setjmp(cstate->top_ctx))
3929 b0 = gen_llc_internal(cstate);
3934 b1 = gen_mcmp(cstate, OR_LLC, 2, BPF_B, subtype, LLC_U_CMD_MASK);
3952 gen_llc_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto)
3967 return gen_cmp(cstate, OR_LLC, 0, BPF_H, (bpf_u_int32)
3975 return gen_cmp(cstate, OR_LLC, 0, BPF_B, LLCSAP_IPX);
3987 return gen_snap(cstate, 0x080007, ETHERTYPE_ATALK);
3999 return gen_cmp(cstate, OR_LLC, 0, BPF_B, ll_proto);
4014 * return gen_snap(cstate, 0x000000, ll_proto);
4020 return gen_cmp(cstate, OR_LLC, 6, BPF_H, ll_proto);
4026 gen_hostop(compiler_state_t *cstate, bpf_u_int32 addr, bpf_u_int32 mask,
4043 b0 = gen_hostop(cstate, addr, mask, Q_SRC, ll_proto, src_off, dst_off);
4044 b1 = gen_hostop(cstate, addr, mask, Q_DST, ll_proto, src_off, dst_off);
4050 b0 = gen_hostop(cstate, addr, mask, Q_SRC, ll_proto, src_off, dst_off);
4051 b1 = gen_hostop(cstate, addr, mask, Q_DST, ll_proto, src_off, dst_off);
4056 bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for addresses other than 802.11 MAC addresses");
4060 bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for addresses other than 802.11 MAC addresses");
4064 bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for addresses other than 802.11 MAC addresses");
4068 bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for addresses other than 802.11 MAC addresses");
4072 bpf_error(cstate, "'ra' is not a valid qualifier for addresses other than 802.11 MAC addresses");
4076 bpf_error(cstate, "'ta' is not a valid qualifier for addresses other than 802.11 MAC addresses");
4083 b0 = gen_linktype(cstate, ll_proto);
4084 b1 = gen_mcmp(cstate, OR_LINKPL, offset, BPF_W, addr, mask);
4091 gen_hostop6(compiler_state_t *cstate, struct in6_addr *addr,
4119 b0 = gen_hostop6(cstate, addr, mask, Q_SRC, ll_proto, src_off, dst_off);
4120 cstate, addr, mask, Q_DST, ll_proto, src_off, dst_off);
4126 b0 = gen_hostop6(cstate, addr, mask, Q_SRC, ll_proto, src_off, dst_off);
4127 b1 = gen_hostop6(cstate, addr, mask, Q_DST, ll_proto, src_off, dst_off);
4132 bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for addresses other than 802.11 MAC addresses");
4136 bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for addresses other than 802.11 MAC addresses");
4140 bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for addresses other than 802.11 MAC addresses");
4144 bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for addresses other than 802.11 MAC addresses");
4148 bpf_error(cstate, "'ra' is not a valid qualifier for addresses other than 802.11 MAC addresses");
4152 bpf_error(cstate, "'ta' is not a valid qualifier for addresses other than 802.11 MAC addresses");
4162 b1 = gen_mcmp(cstate, OR_LINKPL, offset + 12, BPF_W, ntohl(a[3]), ntohl(m[3]));
4163 b0 = gen_mcmp(cstate, OR_LINKPL, offset + 8, BPF_W, ntohl(a[2]), ntohl(m[2]));
4165 b0 = gen_mcmp(cstate, OR_LINKPL, offset + 4, BPF_W, ntohl(a[1]), ntohl(m[1]));
4167 b0 = gen_mcmp(cstate, OR_LINKPL, offset + 0, BPF_W, ntohl(a[0]), ntohl(m[0]));
4169 b0 = gen_linktype(cstate, ll_proto);
4176 gen_ehostop(compiler_state_t *cstate, const u_char *eaddr, int dir)
4182 return gen_bcmp(cstate, OR_LINKHDR, 6, 6, eaddr);
4185 return gen_bcmp(cstate, OR_LINKHDR, 0, 6, eaddr);
4188 b0 = gen_ehostop(cstate, eaddr, Q_SRC);
4189 b1 = gen_ehostop(cstate, eaddr, Q_DST);
4195 b0 = gen_ehostop(cstate, eaddr, Q_SRC);
4196 b1 = gen_ehostop(cstate, eaddr, Q_DST);
4201 bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11 with 802.11 headers");
4205 bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11 with 802.11 headers");
4209 bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11 with 802.11 headers");
4213 bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11 with 802.11 headers");
4217 bpf_error(cstate, "'ra' is only supported on 802.11 with 802.11 headers");
4221 bpf_error(cstate, "'ta' is only supported on 802.11 with 802.11 headers");
4232 gen_fhostop(compiler_state_t *cstate, const u_char *eaddr, int dir)
4238 return gen_bcmp(cstate, OR_LINKHDR, 6 + 1 + cstate->pcap_fddipad, 6, eaddr);
4241 return gen_bcmp(cstate, OR_LINKHDR, 0 + 1 + cstate->pcap_fddipad, 6, eaddr);
4244 b0 = gen_fhostop(cstate, eaddr, Q_SRC);
4245 b1 = gen_fhostop(cstate, eaddr, Q_DST);
4251 b0 = gen_fhostop(cstate, eaddr, Q_SRC);
4252 b1 = gen_fhostop(cstate, eaddr, Q_DST);
4257 bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11");
4261 bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11");
4265 bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11");
4269 bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11");
4273 bpf_error(cstate, "'ra' is only supported on 802.11");
4277 bpf_error(cstate, "'ta' is only supported on 802.11");
4288 gen_thostop(compiler_state_t *cstate, const u_char *eaddr, int dir)
4294 return gen_bcmp(cstate, OR_LINKHDR, 8, 6, eaddr);
4297 return gen_bcmp(cstate, OR_LINKHDR, 2, 6, eaddr);
4300 b0 = gen_thostop(cstate, eaddr, Q_SRC);
4301 b1 = gen_thostop(cstate, eaddr, Q_DST);
4307 b0 = gen_thostop(cstate, eaddr, Q_SRC);
4308 b1 = gen_thostop(cstate, eaddr, Q_DST);
4313 bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11");
4317 bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11");
4321 bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11");
4325 bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11");
4329 bpf_error(cstate, "'ra' is only supported on 802.11");
4333 bpf_error(cstate, "'ta' is only supported on 802.11");
4345 gen_wlanhostop(compiler_state_t *cstate, const u_char *eaddr, int dir)
4357 cstate->no_optimize = 1;
4387 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B);
4388 b1 = new_block(cstate, JMP(BPF_JSET));
4395 b0 = gen_bcmp(cstate, OR_LINKHDR, 24, 6, eaddr);
4402 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B);
4403 b2 = new_block(cstate, JMP(BPF_JSET));
4411 b1 = gen_bcmp(cstate, OR_LINKHDR, 16, 6, eaddr);
4425 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B);
4426 b1 = new_block(cstate, JMP(BPF_JSET));
4434 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B);
4435 b2 = new_block(cstate, JMP(BPF_JSET));
4443 b1 = gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr);
4457 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B);
4458 b1 = new_block(cstate, JMP(BPF_JSET));
4472 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B);
4473 b2 = new_block(cstate, JMP(BPF_JSET));
4481 b1 = gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr);
4499 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B);
4500 b1 = new_block(cstate, JMP(BPF_JSET));
4534 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B);
4535 b1 = new_block(cstate, JMP(BPF_JSET));
4542 b0 = gen_bcmp(cstate, OR_LINKHDR, 16, 6, eaddr);
4549 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B);
4550 b2 = new_block(cstate, JMP(BPF_JSET));
4558 b1 = gen_bcmp(cstate, OR_LINKHDR, 4, 6, eaddr);
4571 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B);
4572 b1 = new_block(cstate, JMP(BPF_JSET));
4586 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B);
4587 b2 = new_block(cstate, JMP(BPF_JSET));
4595 b1 = gen_bcmp(cstate, OR_LINKHDR, 4, 6, eaddr);
4613 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B);
4614 b1 = new_block(cstate, JMP(BPF_JSET));
4627 b0 = gen_wlanhostop(cstate, eaddr, Q_SRC);
4628 b1 = gen_wlanhostop(cstate, eaddr, Q_DST);
4634 b0 = gen_wlanhostop(cstate, eaddr, Q_SRC);
4635 b1 = gen_wlanhostop(cstate, eaddr, Q_DST);
4643 return (gen_bcmp(cstate, OR_LINKHDR, 4, 6, eaddr));
4649 b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_TYPE_CTL,
4652 b1 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_SUBTYPE_CTS,
4655 b2 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_SUBTYPE_ACK,
4660 b1 = gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr);
4668 b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_TYPE_CTL,
4671 b1 = gen_bcmp(cstate, OR_LINKHDR, 16, 6, eaddr);
4682 b0 = gen_mcmp(cstate, OR_LINKHDR, 1, BPF_B,
4684 b1 = gen_bcmp(cstate, OR_LINKHDR, 24, 6, eaddr);
4699 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B);
4700 b1 = new_block(cstate, JMP(BPF_JSET));
4707 b0 = gen_bcmp(cstate, OR_LINKHDR, 4, 6, eaddr);
4724 b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_TYPE_CTL,
4727 b1 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_SUBTYPE_CTS,
4730 b2 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_SUBTYPE_ACK,
4741 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B);
4742 b1 = new_block(cstate, JMP(BPF_JSET));
4755 b1 = gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr);
4769 gen_ipfchostop(compiler_state_t *cstate, const u_char *eaddr, int dir)
4775 return gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr);
4778 return gen_bcmp(cstate, OR_LINKHDR, 2, 6, eaddr);
4781 b0 = gen_ipfchostop(cstate, eaddr, Q_SRC);
4782 b1 = gen_ipfchostop(cstate, eaddr, Q_DST);
4788 b0 = gen_ipfchostop(cstate, eaddr, Q_SRC);
4789 b1 = gen_ipfchostop(cstate, eaddr, Q_DST);
4794 bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11");
4798 bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11");
4802 bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11");
4806 bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11");
4810 bpf_error(cstate, "'ra' is only supported on 802.11");
4814 bpf_error(cstate, "'ta' is only supported on 802.11");
4840 gen_dnhostop(compiler_state_t *cstate, bpf_u_int32 addr, int dir)
4860 b0 = gen_dnhostop(cstate, addr, Q_SRC);
4861 b1 = gen_dnhostop(cstate, addr, Q_DST);
4868 b0 = gen_dnhostop(cstate, addr, Q_SRC);
4869 b1 = gen_dnhostop(cstate, addr, Q_DST);
4874 bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for addresses other than 802.11 MAC addresses");
4878 bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for addresses other than 802.11 MAC addresses");
4882 bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for addresses other than 802.11 MAC addresses");
4886 bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for addresses other than 802.11 MAC addresses");
4890 bpf_error(cstate, "'ra' is not a valid qualifier for addresses other than 802.11 MAC addresses");
4894 bpf_error(cstate, "'ta' is not a valid qualifier for addresses other than 802.11 MAC addresses");
4901 b0 = gen_linktype(cstate, ETHERTYPE_DN);
4903 tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_H,
4905 b1 = gen_cmp(cstate, OR_LINKPL, 2 + 1 + offset_lh,
4909 tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_B, (bpf_u_int32)0x06,
4911 b2 = gen_cmp(cstate, OR_LINKPL, 2 + offset_lh, BPF_H,
4916 tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_H,
4918 b2 = gen_cmp(cstate, OR_LINKPL, 2 + 1 + offset_sh, BPF_H,
4923 tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_B, (bpf_u_int32)0x02,
4925 b2 = gen_cmp(cstate, OR_LINKPL, 2 + offset_sh, BPF_H,
4930 /* Combine with test for cstate->linktype */
4941 gen_mpls_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto)
4949 b0 = gen_mcmp(cstate, OR_LINKPL, (u_int)-2, BPF_B, 0x01, 0x01);
4951 b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_B, 0x40, 0xf0);
4957 b0 = gen_mcmp(cstate, OR_LINKPL, (u_int)-2, BPF_B, 0x01, 0x01);
4959 b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_B, 0x60, 0xf0);
4965 bpf_error(cstate, "unsupported protocol over mpls");
4971 gen_host(compiler_state_t *cstate, bpf_u_int32 addr, bpf_u_int32 mask,
4985 b0 = gen_host(cstate, addr, mask, Q_IP, dir, type);
4990 if (cstate->label_stack_depth == 0) {
4991 b1 = gen_host(cstate, addr, mask, Q_ARP, dir, type);
4993 b0 = gen_host(cstate, addr, mask, Q_RARP, dir, type);
4999 bpf_error(cstate, "link-layer modifier applied to %s", typestr);
5002 return gen_hostop(cstate, addr, mask, dir, ETHERTYPE_IP, 12, 16);
5005 return gen_hostop(cstate, addr, mask, dir, ETHERTYPE_REVARP, 14, 24);
5008 return gen_hostop(cstate, addr, mask, dir, ETHERTYPE_ARP, 14, 24);
5011 bpf_error(cstate, "'sctp' modifier applied to %s", typestr);
5014 bpf_error(cstate, "'tcp' modifier applied to %s", typestr);
5017 bpf_error(cstate, "'udp' modifier applied to %s", typestr);
5020 bpf_error(cstate, "'icmp' modifier applied to %s", typestr);
5023 bpf_error(cstate, "'igmp' modifier applied to %s", typestr);
5026 bpf_error(cstate, "'igrp' modifier applied to %s", typestr);
5029 bpf_error(cstate, "AppleTalk host filtering not implemented");
5032 return gen_dnhostop(cstate, addr, dir);
5035 bpf_error(cstate, "LAT host filtering not implemented");
5038 bpf_error(cstate, "SCA host filtering not implemented");
5041 bpf_error(cstate, "MOPRC host filtering not implemented");
5044 bpf_error(cstate, "MOPDL host filtering not implemented");
5047 bpf_error(cstate, "'ip6' modifier applied to ip host");
5050 bpf_error(cstate, "'icmp6' modifier applied to %s", typestr);
5053 bpf_error(cstate, "'ah' modifier applied to %s", typestr);
5056 bpf_error(cstate, "'esp' modifier applied to %s", typestr);
5059 bpf_error(cstate, "'pim' modifier applied to %s", typestr);
5062 bpf_error(cstate, "'vrrp' modifier applied to %s", typestr);
5065 bpf_error(cstate, "AARP host filtering not implemented");
5068 bpf_error(cstate, "ISO host filtering not implemented");
5071 bpf_error(cstate, "'esis' modifier applied to %s", typestr);
5074 bpf_error(cstate, "'isis' modifier applied to %s", typestr);
5077 bpf_error(cstate, "'clnp' modifier applied to %s", typestr);
5080 bpf_error(cstate, "'stp' modifier applied to %s", typestr);
5083 bpf_error(cstate, "IPX host filtering not implemented");
5086 bpf_error(cstate, "'netbeui' modifier applied to %s", typestr);
5089 bpf_error(cstate, "'l1' modifier applied to %s", typestr);
5092 bpf_error(cstate, "'l2' modifier applied to %s", typestr);
5095 bpf_error(cstate, "'iih' modifier applied to %s", typestr);
5098 bpf_error(cstate, "'snp' modifier applied to %s", typestr);
5101 bpf_error(cstate, "'csnp' modifier applied to %s", typestr);
5104 bpf_error(cstate, "'psnp' modifier applied to %s", typestr);
5107 bpf_error(cstate, "'lsp' modifier applied to %s", typestr);
5110 bpf_error(cstate, "'radio' modifier applied to %s", typestr);
5113 bpf_error(cstate, "'carp' modifier applied to %s", typestr);
5123 gen_host6(compiler_state_t *cstate, struct in6_addr *addr,
5136 return gen_host6(cstate, addr, mask, Q_IPV6, dir, type);
5139 bpf_error(cstate, "link-layer modifier applied to ip6 %s", typestr);
5142 bpf_error(cstate, "'ip' modifier applied to ip6 %s", typestr);
5145 bpf_error(cstate, "'rarp' modifier applied to ip6 %s", typestr);
5148 bpf_error(cstate, "'arp' modifier applied to ip6 %s", typestr);
5151 bpf_error(cstate, "'sctp' modifier applied to ip6 %s", typestr);
5154 bpf_error(cstate, "'tcp' modifier applied to ip6 %s", typestr);
5157 bpf_error(cstate, "'udp' modifier applied to ip6 %s", typestr);
5160 bpf_error(cstate, "'icmp' modifier applied to ip6 %s", typestr);
5163 bpf_error(cstate, "'igmp' modifier applied to ip6 %s", typestr);
5166 bpf_error(cstate, "'igrp' modifier applied to ip6 %s", typestr);
5169 bpf_error(cstate, "AppleTalk modifier applied to ip6 %s", typestr);
5172 bpf_error(cstate, "'decnet' modifier applied to ip6 %s", typestr);
5175 bpf_error(cstate, "'lat' modifier applied to ip6 %s", typestr);
5178 bpf_error(cstate, "'sca' modifier applied to ip6 %s", typestr);
5181 bpf_error(cstate, "'moprc' modifier applied to ip6 %s", typestr);
5184 bpf_error(cstate, "'mopdl' modifier applied to ip6 %s", typestr);
5187 return gen_hostop6(cstate, addr, mask, dir, ETHERTYPE_IPV6, 8, 24);
5190 bpf_error(cstate, "'icmp6' modifier applied to ip6 %s", typestr);
5193 bpf_error(cstate, "'ah' modifier applied to ip6 %s", typestr);
5196 bpf_error(cstate, "'esp' modifier applied to ip6 %s", typestr);
5199 bpf_error(cstate, "'pim' modifier applied to ip6 %s", typestr);
5202 bpf_error(cstate, "'vrrp' modifier applied to ip6 %s", typestr);
5205 bpf_error(cstate, "'aarp' modifier applied to ip6 %s", typestr);
5208 bpf_error(cstate, "'iso' modifier applied to ip6 %s", typestr);
5211 bpf_error(cstate, "'esis' modifier applied to ip6 %s", typestr);
5214 bpf_error(cstate, "'isis' modifier applied to ip6 %s", typestr);
5217 bpf_error(cstate, "'clnp' modifier applied to ip6 %s", typestr);
5220 bpf_error(cstate, "'stp' modifier applied to ip6 %s", typestr);
5223 bpf_error(cstate, "'ipx' modifier applied to ip6 %s", typestr);
5226 bpf_error(cstate, "'netbeui' modifier applied to ip6 %s", typestr);
5229 bpf_error(cstate, "'l1' modifier applied to ip6 %s", typestr);
5232 bpf_error(cstate, "'l2' modifier applied to ip6 %s", typestr);
5235 bpf_error(cstate, "'iih' modifier applied to ip6 %s", typestr);
5238 bpf_error(cstate, "'snp' modifier applied to ip6 %s", typestr);
5241 bpf_error(cstate, "'csnp' modifier applied to ip6 %s", typestr);
5244 bpf_error(cstate, "'psnp' modifier applied to ip6 %s", typestr);
5247 bpf_error(cstate, "'lsp' modifier applied to ip6 %s", typestr);
5250 bpf_error(cstate, "'radio' modifier applied to ip6 %s", typestr);
5253 bpf_error(cstate, "'carp' modifier applied to ip6 %s", typestr);
5264 gen_gateway(compiler_state_t *cstate, const u_char *eaddr,
5272 bpf_error(cstate, "direction applied to 'gateway'");
5279 switch (cstate->linktype) {
5283 b1 = gen_prevlinkhdr_check(cstate);
5284 b0 = gen_ehostop(cstate, eaddr, Q_OR);
5289 b0 = gen_fhostop(cstate, eaddr, Q_OR);
5292 b0 = gen_thostop(cstate, eaddr, Q_OR);
5299 b0 = gen_wlanhostop(cstate, eaddr, Q_OR);
5304 * LANE, cstate->linktype would have been set to
5307 bpf_error(cstate,
5310 b0 = gen_ipfchostop(cstate, eaddr, Q_OR);
5313 bpf_error(cstate,
5330 tmp = gen_host(cstate,
5363 bpf_error(cstate, "illegal modifier of 'gateway'");
5369 gen_proto_abbrev_internal(compiler_state_t *cstate, int proto)
5377 b1 = gen_proto(cstate, IPPROTO_SCTP, Q_DEFAULT, Q_DEFAULT);
5381 b1 = gen_proto(cstate, IPPROTO_TCP, Q_DEFAULT, Q_DEFAULT);
5385 b1 = gen_proto(cstate, IPPROTO_UDP, Q_DEFAULT, Q_DEFAULT);
5389 b1 = gen_proto(cstate, IPPROTO_ICMP, Q_IP, Q_DEFAULT);
5397 b1 = gen_proto(cstate, IPPROTO_IGMP, Q_IP, Q_DEFAULT);
5404 b1 = gen_proto(cstate, IPPROTO_IGRP, Q_IP, Q_DEFAULT);
5412 b1 = gen_proto(cstate, IPPROTO_PIM, Q_DEFAULT, Q_DEFAULT);
5420 b1 = gen_proto(cstate, IPPROTO_VRRP, Q_IP, Q_DEFAULT);
5428 b1 = gen_proto(cstate, IPPROTO_CARP, Q_IP, Q_DEFAULT);
5432 b1 = gen_linktype(cstate, ETHERTYPE_IP);
5436 cstate, ETHERTYPE_ARP);
5440 b1 = gen_linktype(cstate, ETHERTYPE_REVARP);
5444 bpf_error(cstate, "link layer applied in wrong context");
5447 b1 = gen_linktype(cstate, ETHERTYPE_ATALK);
5451 b1 = gen_linktype(cstate, ETHERTYPE_AARP);
5455 b1 = gen_linktype(cstate, ETHERTYPE_DN);
5459 b1 = gen_linktype(cstate, ETHERTYPE_SCA);
5463 b1 = gen_linktype(cstate, ETHERTYPE_LAT);
5467 b1 = gen_linktype(cstate, ETHERTYPE_MOPDL);
5471 b1 = gen_linktype(cstate, ETHERTYPE_MOPRC);
5475 b1 = gen_linktype(cstate, ETHERTYPE_IPV6);
5482 b1 = gen_proto(cstate, IPPROTO_ICMPV6, Q_IPV6, Q_DEFAULT);
5489 b1 = gen_proto(cstate, IPPROTO_AH, Q_DEFAULT, Q_DEFAULT);
5496 b1 = gen_proto(cstate, IPPROTO_ESP, Q_DEFAULT, Q_DEFAULT);
5500 b1 = gen_linktype(cstate, LLCSAP_ISONS);
5504 b1 = gen_proto(cstate, ISO9542_ESIS, Q_ISO, Q_DEFAULT);
5508 b1 = gen_proto(cstate, ISO10589_ISIS, Q_ISO, Q_DEFAULT);
5512 b0 = gen_proto(cstate, ISIS_L1_LAN_IIH, Q_ISIS, Q_DEFAULT);
5513 b1 = gen_proto(cstate, ISIS_PTP_IIH, Q_ISIS, Q_DEFAULT); /* FIXME extract the circuit-type bits */
5515 b0 = gen_proto(cstate, ISIS_L1_LSP, Q_ISIS, Q_DEFAULT);
5517 b0 = gen_proto(cstate, ISIS_L1_CSNP, Q_ISIS, Q_DEFAULT);
5519 b0 = gen_proto(cstate, ISIS_L1_PSNP, Q_ISIS, Q_DEFAULT);
5524 b0 = gen_proto(cstate, ISIS_L2_LAN_IIH, Q_ISIS, Q_DEFAULT);
5525 b1 = gen_proto(cstate, ISIS_PTP_IIH, Q_ISIS, Q_DEFAULT); /* FIXME extract the circuit-type bits */
5527 b0 = gen_proto(cstate, ISIS_L2_LSP, Q_ISIS, Q_DEFAULT);
5529 b0 = gen_proto(cstate, ISIS_L2_CSNP, Q_ISIS, Q_DEFAULT);
5531 b0 = gen_proto(cstate, ISIS_L2_PSNP, Q_ISIS, Q_DEFAULT);
5536 b0 = gen_proto(cstate, ISIS_L1_LAN_IIH, Q_ISIS, Q_DEFAULT);
5537 b1 = gen_proto(cstate, ISIS_L2_LAN_IIH, Q_ISIS, Q_DEFAULT);
5539 b0 = gen_proto(cstate, ISIS_PTP_IIH, Q_ISIS, Q_DEFAULT);
5544 b0 = gen_proto(cstate, ISIS_L1_LSP, Q_ISIS, Q_DEFAULT);
5545 b1 = gen_proto(cstate, ISIS_L2_LSP, Q_ISIS, Q_DEFAULT);
5550 b0 = gen_proto(cstate, ISIS_L1_CSNP, Q_ISIS, Q_DEFAULT);
5551 b1 = gen_proto(cstate, ISIS_L2_CSNP, Q_ISIS, Q_DEFAULT);
5553 b0 = gen_proto(cstate, ISIS_L1_PSNP, Q_ISIS, Q_DEFAULT);
5555 b0 = gen_proto(cstate, ISIS_L2_PSNP, Q_ISIS, Q_DEFAULT);
5560 b0 = gen_proto(cstate, ISIS_L1_CSNP, Q_ISIS, Q_DEFAULT);
5561 b1 = gen_proto(cstate, ISIS_L2_CSNP, Q_ISIS, Q_DEFAULT);
5566 b0 = gen_proto(cstate, ISIS_L1_PSNP, Q_ISIS, Q_DEFAULT);
5567 b1 = gen_proto(cstate, ISIS_L2_PSNP, Q_ISIS, Q_DEFAULT);
5572 b1 = gen_proto(cstate, ISO8473_CLNP, Q_ISO, Q_DEFAULT);
5576 b1 = gen_linktype(cstate, LLCSAP_8021D);
5580 b1 = gen_linktype(cstate, LLCSAP_IPX);
5584 b1 = gen_linktype(cstate, LLCSAP_NETBEUI);
5588 bpf_error(cstate, "'radio' is not a valid protocol type");
5597 gen_proto_abbrev(compiler_state_t *cstate, int proto)
5603 if (setjmp(cstate->top_ctx))
5606 return gen_proto_abbrev_internal(cstate, proto);
5610 gen_ipfrag(compiler_state_t *cstate)
5616 s = gen_load_a(cstate, OR_LINKPL, 6, BPF_H);
5617 b = new_block(cstate, JMP(BPF_JSET));
5635 gen_portatom(compiler_state_t *cstate, int off, bpf_u_int32 v)
5637 return gen_cmp(cstate, OR_TRAN_IPV4, off, BPF_H, v);
5641 gen_portatom6(compiler_state_t *cstate, int off, bpf_u_int32 v)
5643 return gen_cmp(cstate, OR_TRAN_IPV6, off, BPF_H, v);
5647 gen_portop(compiler_state_t *cstate, u_int port, u_int proto, int dir)
5652 tmp = gen_cmp(cstate, OR_LINKPL, 9, BPF_B, proto);
5653 b0 = gen_ipfrag(cstate);
5658 b1 = gen_portatom(cstate, 0, port);
5662 b1 = gen_portatom(cstate, 2, port);
5666 tmp = gen_portatom(cstate, 0, port);
5667 b1 = gen_portatom(cstate, 2, port);
5673 tmp = gen_portatom(cstate, 0, port);
5674 b1 = gen_portatom(cstate, 2, port);
5679 bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for ports");
5683 bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for ports");
5687 bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for ports");
5691 bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for ports");
5695 bpf_error(cstate, "'ra' is not a valid qualifier for ports");
5699 bpf_error(cstate, "'ta' is not a valid qualifier for ports");
5712 gen_port(compiler_state_t *cstate, u_int port, int ip_proto, int dir)
5733 b0 = gen_linktype(cstate, ETHERTYPE_IP);
5739 b1 = gen_portop(cstate, port, (u_int)ip_proto, dir);
5743 tmp = gen_portop(cstate, port, IPPROTO_TCP, dir);
5744 b1 = gen_portop(cstate, port, IPPROTO_UDP, dir);
5746 tmp = gen_portop(cstate, port, IPPROTO_SCTP, dir);
5758 gen_portop6(compiler_state_t *cstate, u_int port, u_int proto, int dir)
5764 b0 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, proto);
5768 b1 = gen_portatom6(cstate, 0, port);
5772 b1 = gen_portatom6(cstate, 2, port);
5776 tmp = gen_portatom6(cstate, 0, port);
5777 b1 = gen_portatom6(cstate, 2, port);
5783 tmp = gen_portatom6(cstate, 0, port);
5784 b1 = gen_portatom6(cstate, 2, port);
5797 gen_port6(compiler_state_t *cstate, u_int port, int ip_proto, int dir)
5802 b0 = gen_linktype(cstate, ETHERTYPE_IPV6);
5808 b1 = gen_portop6(cstate, port, (u_int)ip_proto, dir);
5812 tmp = gen_portop6(cstate, port, IPPROTO_TCP, dir);
5813 b1 = gen_portop6(cstate, port, IPPROTO_UDP, dir);
5815 tmp = gen_portop6(cstate, port, IPPROTO_SCTP, dir);
5828 gen_portrangeatom(compiler_state_t *cstate, u_int off, bpf_u_int32 v1,
5844 b1 = gen_cmp_ge(cstate, OR_TRAN_IPV4, off, BPF_H, v1);
5845 b2 = gen_cmp_le(cstate, OR_TRAN_IPV4, off, BPF_H, v2);
5853 gen_portrangeop(compiler_state_t *cstate, u_int port1, u_int port2,
5859 tmp = gen_cmp(cstate, OR_LINKPL, 9, BPF_B, proto);
5860 b0 = gen_ipfrag(cstate);
5865 b1 = gen_portrangeatom(cstate, 0, port1, port2);
5869 b1 = gen_portrangeatom(cstate, 2, port1, port2);
5873 tmp = gen_portrangeatom(cstate, 0, port1, port2);
5874 b1 = gen_portrangeatom(cstate, 2, port1, port2);
5880 tmp = gen_portrangeatom(cstate, 0, port1, port2);
5881 b1 = gen_portrangeatom(cstate, 2, port1, port2);
5886 bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for port ranges");
5890 bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for port ranges");
5894 bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for port ranges");
5898 bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for port ranges");
5902 bpf_error(cstate, "'ra' is not a valid qualifier for port ranges");
5906 bpf_error(cstate, "'ta' is not a valid qualifier for port ranges");
5919 gen_portrange(compiler_state_t *cstate, u_int port1, u_int port2, int ip_proto,
5925 b0 = gen_linktype(cstate, ETHERTYPE_IP);
5931 b1 = gen_portrangeop(cstate, port1, port2, (bpf_u_int32)ip_proto,
5936 tmp = gen_portrangeop(cstate, port1, port2, IPPROTO_TCP, dir);
5937 b1 = gen_portrangeop(cstate, port1, port2, IPPROTO_UDP, dir);
5939 tmp = gen_portrangeop(cstate, port1, port2, IPPROTO_SCTP, dir);
5951 gen_portrangeatom6(compiler_state_t *cstate, u_int off, bpf_u_int32 v1,
5967 b1 = gen_cmp_ge(cstate, OR_TRAN_IPV6, off, BPF_H, v1);
5968 b2 = gen_cmp_le(cstate, OR_TRAN_IPV6, off, BPF_H, v2);
5976 gen_portrangeop6(compiler_state_t *cstate, u_int port1, u_int port2,
5983 b0 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, proto);
5987 b1 = gen_portrangeatom6(cstate, 0, port1, port2);
5991 b1 = gen_portrangeatom6(cstate, 2, port1, port2);
5995 tmp = gen_portrangeatom6(cstate, 0, port1, port2);
5996 b1 = gen_portrangeatom6(cstate, 2, port1, port2);
6002 tmp = gen_portrangeatom6(cstate, 0, port1, port2);
6003 b1 = gen_portrangeatom6(cstate, 2, port1, port2);
6016 gen_portrange6(compiler_state_t *cstate, u_int port1, u_int port2, int ip_proto,
6022 b0 = gen_linktype(cstate, ETHERTYPE_IPV6);
6028 b1 = gen_portrangeop6(cstate, port1, port2, (bpf_u_int32)ip_proto,
6033 tmp = gen_portrangeop6(cstate, port1, port2, IPPROTO_TCP, dir);
6034 b1 = gen_portrangeop6(cstate, port1, port2, IPPROTO_UDP, dir);
6036 tmp = gen_portrangeop6(cstate, port1, port2, IPPROTO_SCTP, dir);
6048 lookup_proto(compiler_state_t *cstate, const char *name, int proto)
6059 bpf_error(cstate, "unknown ip proto '%s'", name);
6063 /* XXX should look up h/w protocol type based on cstate->linktype */
6068 bpf_error(cstate, "unknown ether proto '%s'", name);
6080 bpf_error(cstate, "unknown osi proto '%s'", name);
6092 gen_protochain(compiler_state_t *cstate, bpf_u_int32 v, int proto)
6099 int reg2 = alloc_reg(cstate);
6109 b0 = gen_protochain(cstate, v, Q_IP);
6110 b = gen_protochain(cstate, v, Q_IPV6);
6114 bpf_error(cstate, "bad protocol applied for 'protochain'");
6129 if (cstate->off_linkpl.is_variable)
6130 bpf_error(cstate, "'protochain' not supported with variable length headers");
6143 cstate->no_optimize = 1;
6151 s[i] = new_stmt(cstate
6156 b0 = gen_linktype(cstate, ETHERTYPE_IP);
6159 s[i] = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_B);
6160 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 9;
6163 s[i] = new_stmt(cstate, BPF_LDX|BPF_MSH|BPF_B);
6164 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl;
6169 b0 = gen_linktype(cstate, ETHERTYPE_IPV6);
6172 s[i] = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_B);
6173 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 6;
6176 s[i] = new_stmt(cstate, BPF_LDX|BPF_IMM);
6182 bpf_error(cstate, "unsupported proto to gen_protochain");
6188 s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K);
6199 s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K);
6212 s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K);
6219 s[i - 1]->s.jf = s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K);
6225 s[i - 1]->s.jf = s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K);
6231 s[i - 1]->s.jf = s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K);
6248 s[i] = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B);
6249 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl;
6252 s[i] = new_stmt(cstate, BPF_ST);
6256 s[i] = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B);
6257 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 1;
6260 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K);
6264 s[i] = new_stmt(cstate, BPF_ALU|BPF_MUL|BPF_K);
6268 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X);
6272 s[i] = new_stmt(cstate, BPF_MISC|BPF_TAX);
6275 s[i] = new_stmt(cstate, BPF_LD|BPF_MEM);
6280 s[i] = new_stmt(cstate, BPF_JMP|BPF_JA);
6290 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K);
6299 s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K);
6314 s[i - 1]->s.jt = s[i] = new_stmt(cstate, BPF_MISC|BPF_TXA);
6317 s[i] = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B);
6318 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl;
6321 s[i] = new_stmt(cstate, BPF_ST);
6325 s[i - 1]->s.jt = s[i] = new_stmt(cstate, BPF_MISC|BPF_TXA);
6328 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K);
6332 s[i] = new_stmt(cstate, BPF_MISC|BPF_TAX);
6335 s[i] = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B);
6336 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl;
6339 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K);
6343 s[i] = new_stmt(cstate, BPF_ALU|BPF_MUL|BPF_K);
6347 s[i] = new_stmt(cstate, BPF_MISC|BPF_TAX);
6350 s[i] = new_stmt(cstate, BPF_LD|BPF_MEM);
6355 s[i] = new_stmt(cstate, BPF_JMP|BPF_JA);
6361 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K);
6379 b = new_block(cstate, JMP(BPF_JEQ));
6383 free_reg(cstate, reg2);
6391 gen_check_802_11_data_frame(compiler_state_t *cstate)
6400 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B);
6401 b0 = new_block(cstate, JMP(BPF_JSET));
6405 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B);
6406 b1 = new_block(cstate, JMP(BPF_JSET));
6426 gen_proto(compiler_state_t *cstate, bpf_u_int32 v, int proto, int dir)
6432 bpf_error(cstate, "direction applied to 'proto'");
6436 b0 = gen_proto(cstate, v, Q_IP, dir);
6437 b1 = gen_proto(cstate, v, Q_IPV6, dir);
6442 return gen_linktype(cstate, v);
6460 b0 = gen_linktype(cstate, ETHERTYPE_IP);
6461 b1 = gen_cmp(cstate, OR_LINKPL, 9, BPF_B, v);
6466 bpf_error(cstate, "arp does not encapsulate another protocol");
6470 bpf_error(cstate, "rarp does not encapsulate another protocol");
6474 bpf_error(cstate, "'sctp proto' is bogus");
6478 bpf_error(cstate, "'tcp proto' is bogus");
6482 bpf_error(cstate, "'udp proto' is bogus");
6486 bpf_error(cstate, "'icmp proto' is bogus");
6490 bpf_error(cstate, "'igmp proto' is bogus");
6494 bpf_error(cstate, "'igrp proto' is bogus");
6498 bpf_error(cstate, "AppleTalk encapsulation is not specifiable");
6502 bpf_error(cstate, "DECNET encapsulation is not specifiable");
6506 bpf_error(cstate, "LAT does not encapsulate another protocol");
6510 bpf_error(cstate, "SCA does not encapsulate another protocol");
6514 bpf_error(cstate, "MOPRC does not encapsulate another protocol");
6518 bpf_error(cstate, "MOPDL does not encapsulate another protocol");
6522 b0 = gen_linktype(cstate, ETHERTYPE_IPV6);
6527 b2 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, IPPROTO_FRAGMENT);
6528 b1 = gen_cmp(cstate, OR_LINKPL, 40, BPF_B, v);
6530 b2 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, v);
6536 bpf_error(cstate, "'icmp6 proto' is bogus");
6540 bpf_error(cstate, "'ah proto' is bogus");
6544 bpf_error(cstate, "'esp proto' is bogus");
6548 bpf_error(cstate, "'pim proto' is bogus");
6552 bpf_error(cstate, "'vrrp proto' is bogus");
6556 bpf_error(cstate, "'aarp proto' is bogus");
6560 switch (cstate->linktype) {
6565 * NLPID at the beginning; "gen_linktype(cstate, LLCSAP_ISONS)"
6581 return gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | v);
6590 b0 = gen_linktype(cstate, LLCSAP_ISONS<<8 | LLCSAP_ISONS);
6592 b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 1, BPF_B, v);
6597 b0 = gen_linktype(cstate, LLCSAP_ISONS);
6598 b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 0, BPF_B, v);
6604 bpf_error(cstate, "'esis proto' is bogus");
6608 b0 = gen_proto(cstate, ISO10589_ISIS, Q_ISO, Q_DEFAULT);
6613 b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 4, BPF_B, v);
6618 bpf_error(cstate, "'clnp proto' is not supported");
6622 bpf_error(cstate, "'stp proto' is bogus");
6626 bpf_error(cstate, "'ipx proto' is bogus");
6630 bpf_error(cstate, "'netbeui proto' is bogus");
6634 bpf_error(cstate, "'l1 proto' is bogus");
6638 bpf_error(cstate, "'l2 proto' is bogus");
6642 bpf_error(cstate, "'iih proto' is bogus");
6646 bpf_error(cstate, "'snp proto' is bogus");
6650 bpf_error(cstate, "'csnp proto' is bogus");
6654 bpf_error(cstate, "'psnp proto' is bogus");
6658 bpf_error(cstate, "'lsp proto' is bogus");
6662 bpf_error(cstate, "'radio proto' is bogus");
6666 bpf_error(cstate, "'carp proto' is bogus");
6680 nametoport(compiler_state_t *cstate, const char *name, int ipproto)
6720 bpf_set_error(cstate, "getaddrinfo(\"%s\" fails with system error: %d",
6739 bpf_set_error(cstate, "getaddrinfo(\"%s\") fails with error: %d",
6779 stringtoport(compiler_state_t *cstate, const char *string, size_t string_size,
6791 ret = stoulen(string, string_size, &val, cstate);
6808 tcp_port = nametoport(cstate, cpy, IPPROTO_TCP);
6815 longjmp(cstate->top_ctx, 1);
6818 udp_port = nametoport(cstate, cpy, IPPROTO_UDP);
6825 longjmp(cstate->top_ctx, 1);
6867 bpf_set_error(cstate, "'%s' is not a valid port", cpy);
6869 longjmp(cstate->top_ctx, 1);
6874 longjmp(cstate->top_ctx, 1);
6879 bpf_set_error(cstate, "stoulen returned %d - this should not happen", ret);
6880 longjmp(cstate->top_ctx, 1);
6891 stringtoportrange(compiler_state_t *cstate, const char *string,
6900 bpf_error(cstate, "port range '%s' contains no hyphen", string);
6910 bpf_error(cstate, "port range '%s' contains more than one hyphen",
6920 bpf_error(cstate, "port range '%s' has no starting port", string);
6926 *port1 = stringtoport(cstate, first, first_size, proto);
6936 bpf_error(cstate, "port range '%s' has no ending port", string);
6942 *port2 = stringtoport(cstate, second, second_size, proto);
6948 gen_scode(compiler_state_t *cstate, const char *name, struct qual q)
6970 if (setjmp(cstate->top_ctx))
6978 bpf_error(cstate, "unknown network '%s'", name);
6985 return gen_host(cstate, addr, mask, proto, dir, q.addr);
6990 switch (cstate->linktype) {
6997 bpf_error(cstate,
6999 tmp = gen_prevlinkhdr_check(cstate);
7000 b = gen_ehostop(cstate, eaddr, dir);
7009 bpf_error(cstate,
7011 b = gen_fhostop(cstate, eaddr, dir);
7018 bpf_error(cstate,
7020 b = gen_thostop(cstate, eaddr, dir);
7031 bpf_error(cstate,
7033 b = gen_wlanhostop(cstate, eaddr, dir);
7040 bpf_error(cstate,
7042 b = gen_ipfchostop(cstate, eaddr, dir);
7047 bpf_error(cstate, "only ethernet/FDDI/token ring/802.11/ATM LANE/Fibre Channel supports link-level host name");
7053 bpf_error(cstate, "unknown decnet host name '%s'\n", name);
7055 bpf_error(cstate, "decnet name support not included, '%s' cannot be translated\n",
7063 return (gen_host(cstate, dn_addr, 0, proto, dir, q.addr));
7070 bpf_error(cstate, "unknown host '%s'", name);
7071 cstate->ai = res;
7077 if (cstate->off_linktype.constant_part == OFFSET_NOT_SET &&
7094 tmp = gen_host(cstate, ntohl(sin4->sin_addr.s_addr),
7104 tmp = gen_host6(cstate, &sin6->sin6_addr,
7115 cstate->ai = NULL;
7118 bpf_error(cstate, "unknown host '%s'%s", name,
7129 bpf_error(cstate, "illegal qualifier of 'port'");
7131 bpf_error(cstate, "unknown port '%s'", name);
7134 bpf_error(cstate, "port '%s' is tcp", name);
7136 bpf_error(cstate, "port '%s' is sctp", name);
7143 bpf_error(cstate, "port '%s' is udp", name);
7146 bpf_error(cstate, "port '%s' is sctp", name);
7153 bpf_error(cstate, "port '%s' is udp", name);
7156 bpf_error(cstate, "port '%s' is tcp", name);
7162 bpf_error(cstate, "illegal port number %d < 0", port);
7164 bpf_error(cstate, "illegal port number %d > 65535", port);
7165 b = gen_port(cstate, port, real_proto, dir);
7166 gen_or(gen_port6(cstate, port, real_proto, dir), b);
7172 bpf_error(cstate, "illegal qualifier of 'portrange'");
7173 stringtoportrange(cstate, name, &port1, &port2, &real_proto);
7176 bpf_error(cstate, "port in range '%s' is tcp", name);
7178 bpf_error(cstate, "port in range '%s' is sctp", name);
7185 bpf_error(cstate, "port in range '%s' is udp", name);
7187 bpf_error(cstate, "port in range '%s' is sctp", name);
7194 bpf_error(cstate, "port in range '%s' is udp", name);
7196 bpf_error(cstate, "port in range '%s' is tcp", name);
7202 bpf_error(cstate, "illegal port number %d > 65535", port1);
7204 bpf_error(cstate, "illegal port number %d > 65535", port2);
7206 b = gen_portrange(cstate, port1, port2, real_proto, dir);
7207 gen_or(gen_portrange6(cstate, port1, port2, real_proto, dir), b);
7214 bpf_error(cstate, "unknown ether host: %s", name);
7217 cstate->ai = res;
7219 bpf_error(cstate, "unknown host '%s'", name);
7220 b = gen_gateway(cstate, eaddr, res, proto, dir);
7221 cstate->ai = NULL;
7224 bpf_error(cstate, "unknown host '%s'", name);
7227 bpf_error(cstate, "'gateway' not supported in this configuration");
7231 real_proto = lookup_proto(cstate, name, proto);
7233 return gen_proto(cstate, real_proto, proto, dir);
7235 bpf_error(cstate, "unknown protocol: %s", name);
7239 real_proto = lookup_proto(cstate, name, proto);
7241 return gen_protochain(cstate, real_proto, proto);
7243 bpf_error(cstate, "unknown protocol: %s", name);
7247 syntax(cstate);
7255 gen_mcode(compiler_state_t *cstate, const char *s1, const char *s2,
7265 if (setjmp(cstate->top_ctx))
7270 bpf_error(cstate, "invalid IPv4 address '%s'", s1);
7277 bpf_error(cstate, "invalid IPv4 address '%s'", s2);
7281 bpf_error(cstate, "non-network bits set in \"%s mask %s\"",
7286 bpf_error(cstate, "mask length must be <= 32");
7296 bpf_error(cstate, "non-network bits set in \"%s/%d\"",
7303 return gen_host(cstate, n, m, q.proto, q.dir, q.addr);
7306 bpf_error(cstate, "Mask syntax for networks only");
7313 gen_ncode(compiler_state_t *cstate, const char *s, bpf_u_int32 v, struct qual q)
7324 if (setjmp(cstate->top_ctx))
7334 bpf_error(cstate, "malformed decnet address '%s'", s);
7338 bpf_error(cstate, "invalid IPv4 address '%s'", s);
7347 return gen_host(cstate, v, 0, proto, dir, q.addr);
7349 bpf_error(cstate, "illegal link layer address");
7363 return gen_host(cstate, v, mask, proto, dir, q.addr);
7376 bpf_error(cstate, "illegal qualifier of 'port'");
7379 bpf_error(cstate, "illegal port number %u > 65535", v);
7383 b = gen_port(cstate, v, proto, dir);
7384 gen_or(gen_port6(cstate, v, proto, dir), b);
7398 bpf_error(cstate, "illegal qualifier of 'portrange'");
7401 bpf_error(cstate, "illegal port number %u > 65535", v);
7405 b = gen_portrange(cstate, v, v, proto, dir);
7406 gen_or(gen_portrange6(cstate, v, v, proto, dir), b);
7411 bpf_error(cstate, "'gateway' requires a name");
7415 return gen_proto(cstate, v, proto, dir);
7419 return gen_protochain(cstate, v, proto);
7423 syntax(cstate);
7435 gen_mcode6(compiler_state_t *cstate, const char *s, bpf_u_int32 masklen,
7448 if (setjmp(cstate->top_ctx))
7453 bpf_error(cstate, "invalid ip6 address %s", s);
7454 cstate->ai = res;
7456 bpf_error(cstate, "%s resolved to multiple address", s);
7460 bpf_error(cstate, "mask length must be <= %zu", sizeof(mask.s6_addr) * 8);
7472 bpf_error(cstate, "non-network bits set in \"%s/%d\"", s, masklen);
7480 bpf_error(cstate, "Mask syntax for networks only");
7484 b = gen_host6(cstate, addr, &mask, q.proto, q.dir, q.addr);
7485 cstate->ai = NULL;
7490 bpf_error(cstate, "invalid qualifier against IPv6 address");
7497 gen_ecode(compiler_state_t *cstate, const char *s, struct qual q)
7505 if (setjmp(cstate->top_ctx))
7509 cstate->e = pcap_ether_aton(s);
7510 if (cstate->e == NULL)
7511 bpf_error(cstate, "malloc");
7512 switch (cstate->linktype) {
7516 tmp = gen_prevlinkhdr_check(cstate);
7517 b = gen_ehostop(cstate, cstate->e, (int)q.dir);
7522 b = gen_fhostop(cstate, cstate->e, (int)q.dir);
7525 b = gen_thostop(cstate, cstate->e, (int)q.dir);
7532 b = gen_wlanhostop(cstate, cstate->e, (int)q.dir);
7535 b = gen_ipfchostop(cstate, cstate->e, (int)q.dir);
7538 free(cstate->e);
7539 cstate->e = NULL;
7540 bpf_error(cstate, "ethernet addresses supported only on ethernet/FDDI/token ring/802.11/ATM LANE/Fibre Channel");
7543 free(cstate->e);
7544 cstate->e = NULL;
7547 bpf_error(cstate, "ethernet address used in non-ether expression");
7564 xfer_to_x(compiler_state_t *cstate, struct arth *a)
7568 s = new_stmt(cstate, BPF_LDX|BPF_MEM);
7574 xfer_to_a(compiler_state_t *cstate, struct arth *a)
7578 s = new_stmt(cstate, BPF_LD|BPF_MEM);
7591 gen_load_internal(compiler_state_t *cstate, int proto, struct arth *inst,
7597 int regno = alloc_reg(cstate);
7599 free_reg(cstate, inst->regno);
7603 bpf_error(cstate, "data size must be 1, 2, or 4");
7620 bpf_error(cstate, "unsupported index operation");
7628 if (cstate->linktype != DLT_IEEE802_11_RADIO_AVS &&
7629 cstate->linktype != DLT_IEEE802_11_RADIO &&
7630 cstate->linktype != DLT_PRISM_HEADER)
7631 bpf_error(cstate, "radio information not present in capture");
7637 s = xfer_to_x(cstate, inst);
7642 tmp = new_stmt(cstate, BPF_LD|BPF_IND|size_code);
7659 s = gen_abs_offset_varpart(cstate, &cstate->off_linkhdr);
7671 sappend(s, xfer_to_a(cstate, inst));
7672 sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X));
7673 sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX));
7675 s = xfer_to_x(cstate, inst);
7684 tmp = new_stmt(cstate, BPF_LD|BPF_IND|size_code);
7685 tmp->s.k = cstate->off_linkhdr.constant_part;
7704 * cstate->off_nl_nosnap?
7706 s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl);
7718 sappend(s, xfer_to_a(cstate, inst));
7719 sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X));
7720 sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX));
7722 s = xfer_to_x(cstate, inst);
7731 tmp = new_stmt(cstate, BPF_LD|BPF_IND|size_code);
7732 tmp->s.k = cstate->off_linkpl.constant_part + cstate->off_nl;
7740 b = gen_proto_abbrev_internal(cstate, proto);
7764 * cstate->off_nl_nosnap?
7769 s = gen_loadx_iphdrlen(cstate);
7785 sappend(s, xfer_to_a(cstate, inst));
7786 sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X));
7787 sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX));
7788 sappend(s, tmp = new_stmt(cstate, BPF_LD|BPF_IND|size_code));
7789 tmp->s.k = cstate->off_linkpl.constant_part + cstate->off_nl;
7798 gen_and(gen_proto_abbrev_internal(cstate, proto), b = gen_ipfrag(cstate));
7801 gen_and(gen_proto_abbrev_internal(cstate, Q_IP), b);
7809 b = gen_proto_abbrev_internal(cstate, Q_IPV6);
7817 b = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, 58);
7822 s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl);
7833 sappend(s, xfer_to_a(cstate, inst));
7834 sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X));
7835 sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX));
7837 s = xfer_to_x(cstate, inst);
7846 tmp = new_stmt(cstate, BPF_LD|BPF_IND|size_code);
7847 tmp->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 40;
7855 s = new_stmt(cstate, BPF_ST);
7863 gen_load(compiler_state_t *cstate, int proto, struct arth *inst,
7870 if (setjmp(cstate->top_ctx))
7873 return gen_load_internal(cstate, proto, inst, size);
7877 gen_relation_internal(compiler_state_t *cstate, int code, struct arth *a0,
7883 s0 = xfer_to_x(cstate, a1);
7884 s1 = xfer_to_a(cstate, a0);
7886 s2 = new_stmt(cstate, BPF_ALU|BPF_SUB|BPF_X);
7887 b = new_block(cstate, JMP(code));
7891 b = new_block(cstate, BPF_JMP|code|BPF_X);
7901 free_reg(cstate, a0->regno);
7902 free_reg(cstate, a1->regno);
7921 gen_relation(compiler_state_t *cstate, int code, struct arth *a0,
7928 if (setjmp(cstate->top_ctx))
7931 return gen_relation_internal(cstate, code, a0, a1, reversed);
7935 gen_loadlen(compiler_state_t *cstate)
7945 if (setjmp(cstate->top_ctx))
7948 regno = alloc_reg(cstate);
7949 a = (struct arth *)newchunk(cstate, sizeof(*a));
7950 s = new_stmt(cstate, BPF_LD|BPF_LEN);
7951 s->next = new_stmt(cstate, BPF_ST);
7960 gen_loadi_internal(compiler_state_t *cstate, bpf_u_int32 val)
7966 a = (struct arth *)newchunk(cstate, sizeof(*a));
7968 reg = alloc_reg(cstate);
7970 s = new_stmt(cstate, BPF_LD|BPF_IMM);
7972 s->next = new_stmt(cstate, BPF_ST);
7981 gen_loadi(compiler_state_t *cstate, bpf_u_int32 val)
7987 if (setjmp(cstate->top_ctx))
7990 return gen_loadi_internal(cstate, val);
7999 gen_neg(compiler_state_t *cstate, struct arth *a_arg)
8008 if (setjmp(cstate->top_ctx))
8011 s = xfer_to_a(cstate, a);
8013 s = new_stmt(cstate, BPF_ALU|BPF_NEG);
8016 s = new_stmt(cstate, BPF_ST);
8029 gen_arth(compiler_state_t *cstate, int code, struct arth *a0_arg,
8039 if (setjmp(cstate->top_ctx))
8051 bpf_error(cstate, "division by zero");
8054 bpf_error(cstate, "modulus by zero");
8057 bpf_error(cstate, "shift by more than 31 bits");
8059 s0 = xfer_to_x(cstate, a1);
8060 s1 = xfer_to_a(cstate, a0);
8061 s2 = new_stmt(cstate, BPF_ALU|BPF_X|code);
8068 free_reg(cstate, a0->regno);
8069 free_reg(cstate, a1->regno);
8071 s0 = new_stmt(cstate, BPF_ST);
8072 a0->regno = s0->s.k = alloc_reg(cstate);
8082 init_regs(compiler_state_t *cstate)
8084 cstate->curreg = 0;
8085 memset(cstate->regused, 0, sizeof cstate->regused);
8092 alloc_reg(compiler_state_t *cstate)
8097 if (cstate->regused[cstate->curreg])
8098 cstate->curreg = (cstate->curreg + 1) % BPF_MEMWORDS;
8100 cstate->regused[cstate->curreg] = 1;
8101 return cstate->curreg;
8104 bpf_error(cstate, "too many registers needed to evaluate expression");
8113 free_reg(compiler_state_t *cstate, int n)
8115 cstate->regused[n] = 0;
8119 gen_len(compiler_state_t *cstate, int jmp, int n)
8124 s = new_stmt(cstate, BPF_LD|BPF_LEN);
8125 b = new_block(cstate, JMP(jmp));
8133 gen_greater(compiler_state_t *cstate, int n)
8139 if (setjmp(cstate->top_ctx))
8142 return gen_len(cstate, BPF_JGE, n);
8149 gen_less(compiler_state_t *cstate, int n)
8157 if (setjmp(cstate->top_ctx))
8160 b = gen_len(cstate, BPF_JGT, n);
8177 gen_byteop(compiler_state_t *cstate, int op, int idx, bpf_u_int32 val)
8186 if (setjmp(cstate->top_ctx))
8194 return gen_cmp(cstate, OR_LINKHDR, (u_int)idx, BPF_B, val);
8197 b = gen_cmp_lt(cstate, OR_LINKHDR, (u_int)idx, BPF_B, val);
8201 b = gen_cmp_gt(cstate, OR_LINKHDR, (u_int)idx, BPF_B, val);
8205 s = new_stmt(cstate, BPF_ALU|BPF_OR|BPF_K);
8209 s = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K);
8213 b = new_block(cstate, JMP(BPF_JEQ));
8223 gen_broadcast(compiler_state_t *cstate, int proto)
8233 if (setjmp(cstate->top_ctx))
8240 switch (cstate->linktype) {
8243 return gen_ahostop(cstate, abroadcast, Q_DST);
8247 b1 = gen_prevlinkhdr_check(cstate);
8248 b0 = gen_ehostop(cstate, ebroadcast, Q_DST);
8253 return gen_fhostop(cstate, ebroadcast, Q_DST);
8255 return gen_thostop(cstate, ebroadcast, Q_DST);
8261 return gen_wlanhostop(cstate, ebroadcast, Q_DST);
8263 return gen_ipfchostop(cstate, ebroadcast, Q_DST);
8265 bpf_error(cstate, "not a broadcast link");
8275 if (cstate->netmask == PCAP_NETMASK_UNKNOWN)
8276 bpf_error(cstate, "netmask not known, so 'ip broadcast' not supported");
8277 b0 = gen_linktype(cstate, ETHERTYPE_IP);
8278 hostmask = ~cstate->netmask;
8279 b1 = gen_mcmp(cstate, OR_LINKPL, 16, BPF_W, 0, hostmask);
8280 b2 = gen_mcmp(cstate, OR_LINKPL, 16, BPF_W,
8286 bpf_error(cstate, "only link-layer/IP broadcast filters supported");
8295 gen_mac_multicast(compiler_state_t *cstate, int offset)
8301 s = gen_load_a(cstate, OR_LINKHDR, offset, BPF_B);
8302 b0 = new_block(cstate, JMP(BPF_JSET));
8309 gen_multicast(compiler_state_t *cstate, int proto)
8318 if (setjmp(cstate->top_ctx))
8325 switch (cstate->linktype) {
8329 return gen_ahostop(cstate, abroadcast, Q_DST);
8333 b1 = gen_prevlinkhdr_check(cstate);
8335 b0 = gen_mac_multicast(cstate, 0);
8346 return gen_mac_multicast(cstate, 1);
8349 return gen_mac_multicast(cstate, 2);
8376 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B);
8377 b1 = new_block(cstate, JMP(BPF_JSET));
8384 b0 = gen_mac_multicast(cstate, 16);
8391 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B);
8392 b2 = new_block(cstate, JMP(BPF_JSET));
8400 b1 = gen_mac_multicast(cstate, 4);
8413 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B);
8414 b1 = new_block(cstate, JMP(BPF_JSET));
8428 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B);
8429 b2 = new_block(cstate, JMP(BPF_JSET));
8437 b1 = gen_mac_multicast(cstate, 4);
8455 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B);
8456 b1 = new_block(cstate, JMP(BPF_JSET));
8468 b0 = gen_mac_multicast(cstate, 2);
8477 b0 = gen_linktype(cstate, ETHERTYPE_IP);
8478 b1 = gen_cmp_ge(cstate, OR_LINKPL, 16, BPF_B, 224);
8483 b0 = gen_linktype(cstate, ETHERTYPE_IPV6);
8484 b1 = gen_cmp(cstate, OR_LINKPL, 24, BPF_B, 255);
8488 bpf_error(cstate, "link-layer multicast filters supported only on ethernet/FDDI/token ring/ARCNET/802.11/ATM LANE/Fibre Channel");
8493 gen_ifindex(compiler_state_t *cstate, int ifindex)
8501 if (setjmp(cstate->top_ctx))
8507 switch (cstate->linktype) {
8510 b0 = gen_cmp(cstate, OR_LINKHDR, 4, BPF_W, ifindex);
8520 if (cstate->bpf_pcap->rfile != NULL) {
8522 bpf_error(cstate, "ifindex not supported on %s when reading savefiles",
8523 pcap_datalink_val_to_description_or_dlt(cstate->linktype));
8527 b0 = gen_cmp(cstate, OR_LINKHDR, SKF_AD_OFF + SKF_AD_IFINDEX, BPF_W,
8530 bpf_error(cstate, "ifindex not supported on %s",
8531 pcap_datalink_val_to_description_or_dlt(cstate->linktype));
8548 gen_inbound(compiler_state_t *cstate, int dir)
8556 if (setjmp(cstate->top_ctx))
8562 switch (cstate->linktype) {
8564 b0 = gen_relation_internal(cstate, BPF_JEQ,
8565 gen_load_internal(cstate, Q_LINK, gen_loadi_internal(cstate, 0), 1),
8566 gen_loadi_internal(cstate, 0),
8573 b0 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, IPNET_OUTBOUND);
8576 b0 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, IPNET_INBOUND);
8582 b0 = gen_cmp(cstate, OR_LINKHDR, 0, BPF_H, LINUX_SLL_OUTGOING);
8591 b0 = gen_cmp(cstate, OR_LINKHDR, 10, BPF_B, LINUX_SLL_OUTGOING);
8599 b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, dir), BPF_B,
8606 b0 = gen_cmp(cstate, OR_LINKHDR, 0, BPF_B, PPP_PPPD_OUT);
8609 b0 = gen_cmp(cstate, OR_LINKHDR, 0, BPF_B, PPP_PPPD_IN);
8640 b0 = gen_mcmp(cstate, OR_LINKHDR, 3, BPF_B, 0, 0x01);
8643 b0 = gen_mcmp(cstate, OR_LINKHDR, 3, BPF_B, 1, 0x01);
8670 if (cstate->bpf_pcap->rfile != NULL) {
8672 bpf_error(cstate, "inbound/outbound not supported on %s when reading savefiles",
8673 pcap_datalink_val_to_description_or_dlt(cstate->linktype));
8677 b0 = gen_cmp(cstate, OR_LINKHDR, SKF_AD_OFF + SKF_AD_PKTTYPE, BPF_H,
8684 bpf_error(cstate, "inbound/outbound not supported on %s",
8685 pcap_datalink_val_to_description_or_dlt(cstate->linktype));
8694 gen_pf_ifname(compiler_state_t *cstate, const char *ifname)
8703 if (setjmp(cstate->top_ctx))
8706 if (cstate->linktype != DLT_PFLOG) {
8707 bpf_error(cstate, "ifname supported only on PF linktype");
8713 bpf_error(cstate, "ifname interface names can only be %d characters",
8717 b0 = gen_bcmp(cstate, OR_LINKHDR, off, (u_int)strlen(ifname),
8724 gen_pf_ruleset(compiler_state_t *cstate, char *ruleset)
8732 if (setjmp(cstate->top_ctx))
8735 if (cstate->linktype != DLT_PFLOG) {
8736 bpf_error(cstate, "ruleset supported only on PF linktype");
8741 bpf_error(cstate, "ruleset names can only be %ld characters",
8746 b0 = gen_bcmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, ruleset),
8753 gen_pf_rnr(compiler_state_t *cstate, int rnr)
8761 if (setjmp(cstate->top_ctx))
8764 if (cstate->linktype != DLT_PFLOG) {
8765 bpf_error(cstate, "rnr supported only on PF linktype");
8769 b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, rulenr), BPF_W,
8776 gen_pf_srnr(compiler_state_t *cstate, int srnr)
8784 if (setjmp(cstate->top_ctx))
8787 if (cstate->linktype != DLT_PFLOG) {
8788 bpf_error(cstate, "srnr supported only on PF linktype");
8792 b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, subrulenr), BPF_W,
8799 gen_pf_reason(compiler_state_t *cstate, int reason)
8807 if (setjmp(cstate->top_ctx))
8810 if (cstate->linktype != DLT_PFLOG) {
8811 bpf_error(cstate
8815 b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, reason), BPF_B,
8822 gen_pf_action(compiler_state_t *cstate, int action)
8830 if (setjmp(cstate->top_ctx))
8833 if (cstate->linktype != DLT_PFLOG) {
8834 bpf_error(cstate, "action supported only on PF linktype");
8838 b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, action), BPF_B,
8845 gen_p80211_type(compiler_state_t *cstate, bpf_u_int32 type, bpf_u_int32 mask)
8853 if (setjmp(cstate->top_ctx))
8856 switch (cstate->linktype) {
8862 b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, type, mask);
8866 bpf_error(cstate, "802.11 link-layer types supported only on 802.11");
8874 gen_p80211_fcdir(compiler_state_t *cstate, bpf_u_int32 fcdir)
8882 if (setjmp(cstate->top_ctx))
8885 switch (cstate->linktype) {
8894 bpf_error(cstate, "frame direction supported only with 802.11 headers");
8898 b0 = gen_mcmp(cstate, OR_LINKHDR, 1, BPF_B, fcdir,
8905 gen_acode(compiler_state_t *cstate, const char *s, struct qual q)
8913 if (setjmp(cstate->top_ctx))
8916 switch (cstate->linktype) {
8922 cstate->e = pcap_ether_aton(s);
8923 if (cstate->e == NULL)
8924 bpf_error(cstate, "malloc");
8925 b = gen_ahostop(cstate, cstate->e, (int)q.dir);
8926 free(cstate->e);
8927 cstate->e = NULL;
8930 bpf_error(cstate, "ARCnet address used in non-arc expression");
8934 bpf_error(cstate, "aid supported only on ARCnet");
8940 gen_ahostop(compiler_state_t *cstate, const u_char *eaddr, int dir)
8947 return gen_bcmp(cstate, OR_LINKHDR, 0, 1, eaddr);
8950 return gen_bcmp(cstate, OR_LINKHDR, 1, 1, eaddr);
8953 b0 = gen_ahostop(cstate, eaddr, Q_SRC);
8954 b1 = gen_ahostop(cstate, eaddr, Q_DST);
8960 b0 = gen_ahostop(cstate, eaddr, Q_SRC);
8961 b1 = gen_ahostop(cstate, eaddr, Q_DST);
8966 bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11");
8970 bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11");
8974 bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11");
8978 bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11");
8982 bpf_error(cstate, "'ra' is only supported on 802.11");
8986 bpf_error(cstate, "'ta' is only supported on 802.11");
8994 gen_vlan_tpid_test(compiler_state_t *cstate)
8999 b0 = gen_linktype(cstate, ETHERTYPE_8021Q);
9000 b1 = gen_linktype(cstate, ETHERTYPE_8021AD);
9003 b1 = gen_linktype(cstate, ETHERTYPE_8021QINQ);
9010 gen_vlan_vid_test(compiler_state_t *cstate, bpf_u_int32 vlan_num)
9013 bpf_error(cstate, "VLAN tag %u greater than maximum %u",
9016 return gen_mcmp(cstate, OR_LINKPL, 0, BPF_H, vlan_num, 0x0fff);
9020 gen_vlan_no_bpf_extensions(compiler_state_t *cstate, bpf_u_int32 vlan_num,
9025 b0 = gen_vlan_tpid_test(cstate);
9028 b1 = gen_vlan_vid_test(cstate, vlan_num);
9037 cstate->off_linkpl.constant_part += 4;
9038 cstate->off_linktype.constant_part += 4;
9046 gen_vlan_vloffset_add(compiler_state_t *cstate, bpf_abs_offset *off,
9054 off->reg = alloc_reg(cstate);
9056 s2 = new_stmt(cstate, BPF_LD|BPF_MEM);
9059 s2 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_IMM);
9062 s2 = new_stmt(cstate, BPF_ST);
9072 gen_vlan_patch_tpid_test(compiler_state_t *cstate, struct block *b_tpid)
9078 cstate->is_vlan_vloffset = 1;
9079 gen_vlan_vloffset_add(cstate, &cstate->off_linkpl, 4, &s);
9080 gen_vlan_vloffset_add(cstate, &cstate->off_linktype, 4, &s);
9092 gen_vlan_patch_vid_test(compiler_state_t *cstate, struct block *b_vid)
9097 s = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS);
9101 sjeq = new_stmt(cstate, JMP(BPF_JEQ));
9106 s2 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS);
9118 s2 = new_stmt(cstate, JMP(BPF_JA));
9136 gen_vlan_bpf_extensions(compiler_state_t *cstate, bpf_u_int32 vlan_num,
9144 s = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS);
9147 b0 = new_block(cstate, JMP(BPF_JEQ));
9161 b_tpid = gen_vlan_tpid_test(cstate);
9163 b_vid = gen_vlan_vid_test(cstate, vlan_num);
9165 gen_vlan_patch_tpid_test(cstate, b_tpid);
9170 gen_vlan_patch_vid_test(cstate, b_vid);
9183 gen_vlan(compiler_state_t *cstate, bpf_u_int32 vlan_num, int has_vlan_tag)
9191 if (setjmp(cstate->top_ctx))
9195 if (cstate->label_stack_depth > 0)
9196 bpf_error(cstate, "no VLAN match after MPLS");
9229 switch (cstate->linktype) {
9237 if (cstate->vlan_stack_depth == 0 && !cstate->off_linkhdr.is_variable &&
9238 cstate->off_linkhdr.constant_part ==
9239 cstate->off_outermostlinkhdr.constant_part) {
9243 if (cstate->bpf_pcap->bpf_codegen_flags & BPF_SPECIAL_VLAN_HANDLING)
9244 b0 = gen_vlan_bpf_extensions(cstate, vlan_num,
9247 b0 = gen_vlan_no_bpf_extensions(cstate,
9251 b0 = gen_vlan_no_bpf_extensions(cstate, vlan_num,
9259 b0 = gen_vlan_no_bpf_extensions(cstate, vlan_num, has_vlan_tag);
9263 bpf_error(cstate, "no VLAN support for %s",
9264 pcap_datalink_val_to_description_or_dlt(cstate->linktype));
9268 cstate->vlan_stack_depth++;
9281 gen_mpls(compiler_state_t *cstate, bpf_u_int32 label_num_arg,
9291 if (setjmp(cstate->top_ctx))
9294 if (cstate->label_stack_depth > 0) {
9296 b0 = gen_mcmp(cstate, OR_PREVMPLSHDR, 2, BPF_B, 0, 0x01);
9302 switch (cstate->linktype) {
9309 b0 = gen_linktype(cstate, ETHERTYPE_MPLS);
9313 b0 = gen_linktype(cstate, PPP_MPLS_UCAST);
9321 bpf_error(cstate, "no MPLS support for %s",
9322 pcap_datalink_val_to_description_or_dlt(cstate->linktype));
9330 bpf_error(cstate, "MPLS label %u greater than maximum %u",
9334 b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_W, label_num,
9354 cstate->off_nl_nosnap += 4;
9355 cstate->off_nl += 4;
9356 cstate->label_stack_depth++;
9364 gen_pppoed(compiler_state_t *cstate)
9370 if (setjmp(cstate->top_ctx))
9374 return gen_linktype(cstate, ETHERTYPE_PPPOED);
9378 gen_pppoes(compiler_state_t *cstate, bpf_u_int32 sess_num, int has_sess_num)
9386 if (setjmp(cstate->top_ctx))
9392 b0 = gen_linktype(cstate, ETHERTYPE_PPPOES);
9397 bpf_error(cstate, "PPPoE session number %u greater than maximum %u",
9400 b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_W, sess_num, 0x0000ffff);
9421 * it's 6 bytes past cstate->off_nl.
9423 PUSH_LINKHDR(cstate, DLT_PPP, cstate->off_linkpl.is_variable,
9424 cstate->off_linkpl.constant_part + cstate->off_nl + 6, /* 6 bytes past the PPPoE header */
9425 cstate->off_linkpl.reg);
9427 cstate->off_linktype = cstate->off_linkhdr;
9428 cstate->off_linkpl.constant_part = cstate->off_linkhdr.constant_part + 2;
9430 cstate->off_nl = 0;
9431 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */
9439 gen_geneve_check(compiler_state_t *cstate,
9445 b0 = gen_portfn(cstate, GENEVE_PORT, IPPROTO_UDP, Q_DST);
9450 b1 = gen_mcmp(cstate, offrel, 8, BPF_B, 0, 0xc0);
9456 bpf_error(cstate, "Geneve VNI %u greater than maximum %u",
9460 b1 = gen_mcmp(cstate, offrel, 12, BPF_W, vni, 0xffffff00);
9474 gen_geneve4(compiler_state_t *cstate, bpf_u_int32 vni, int has_vni)
9479 b0 = gen_geneve_check(cstate, gen_port, OR_TRAN_IPV4, vni, has_vni);
9482 s = gen_loadx_iphdrlen(cstate);
9484 s1 = new_stmt(cstate, BPF_MISC|BPF_TXA);
9490 b1 = new_block(cstate, BPF_JMP|BPF_JEQ|BPF_X);
9500 gen_geneve6(compiler_state_t *cstate, bpf_u_int32 vni, int has_vni)
9505 b0 = gen_geneve_check(cstate, gen_port6, OR_TRAN_IPV6, vni, has_vni);
9509 s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl);
9511 s1 = new_stmt(cstate, BPF_LD|BPF_IMM);
9515 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X);
9519 s = new_stmt(cstate, BPF_LD|BPF_IMM);
9526 s1 = new_stmt(cstate, BPF_MISC|BPF_TAX);
9529 b1 = new_block(cstate, BPF_JMP|BPF_JEQ|BPF_X);
9543 gen_geneve_offsets(compiler_state_t *cstate)
9552 s = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K);
9553 s->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 8;
9556 s1 = new_stmt(cstate, BPF_MISC|BPF_TAX);
9561 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K);
9565 cstate->off_linktype.reg = alloc_reg(cstate);
9566 cstate->off_linktype.is_variable = 1;
9567 cstate->off_linktype.constant_part = 0;
9569 s1 = new_stmt(cstate, BPF_ST);
9570 s1->s.k = cstate->off_linktype.reg;
9576 s1 = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B);
9580 s1 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K);
9584 s1 = new_stmt(cstate, BPF_ALU|BPF_MUL|BPF_K);
9589 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K);
9594 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X);
9606 PUSH_LINKHDR(cstate, DLT_EN10MB, 1, 0, alloc_reg(cstate));
9608 s1 = new_stmt(cstate, BPF_ST);
9609 s1->s.k = cstate->off_linkhdr.reg;
9618 cstate->no_optimize = 1;
9621 s1 = new_stmt(cstate, BPF_LD|BPF_IND|BPF_H);
9626 s1 = new_stmt(cstate, BPF_LDX|BPF_MEM);
9627 s1->s.k = cstate->off_linkhdr.reg;
9633 s_proto = new_stmt(cstate, JMP(BPF_JEQ));
9637 s1 = new_stmt(cstate, BPF_MISC|BPF_TXA);
9643 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K);
9647 s1 = new_stmt(cstate, BPF_ST);
9648 s1->s.k = cstate->off_linktype.reg;
9653 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K);
9658 s1 = new_stmt(cstate, BPF_MISC|BPF_TAX);
9662 cstate->off_linkpl.reg = alloc_reg(cstate);
9663 cstate->off_linkpl.is_variable = 1;
9664 cstate->off_linkpl.constant_part = 0;
9666 s1 = new_stmt(cstate, BPF_STX);
9667 s1->s.k = cstate->off_linkpl.reg;
9671 cstate->off_nl = 0;
9678 gen_geneve(compiler_state_t *cstate, bpf_u_int32 vni, int has_vni)
9687 if (setjmp(cstate->top_ctx))
9690 b0 = gen_geneve4(cstate, vni, has_vni);
9691 b1 = gen_geneve6(cstate, vni, has_vni);
9699 s = gen_geneve_offsets(cstate);
9701 b1 = gen_true(cstate);
9707 cstate->is_geneve = 1;
9715 gen_geneve_ll_check(compiler_state_t *cstate)
9726 s = new_stmt(cstate, BPF_LD|BPF_MEM);
9727 s->s.k = cstate->off_linkhdr.reg;
9729 s1 = new_stmt(cstate, BPF_LDX|BPF_MEM);
9730 s1->s.k = cstate->off_linkpl.reg;
9733 b0 = new_block(cstate, BPF_JMP|BPF_JEQ|BPF_X);
9742 gen_atmfield_code_internal(compiler_state_t *cstate, int atmfield,
9750 if (!cstate->is_atm)
9751 bpf_error(cstate, "'vpi' supported only on raw ATM");
9752 if (cstate->off_vpi == OFFSET_NOT_SET)
9754 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_vpi, BPF_B,
9759 if (!cstate->is_atm)
9760 bpf_error(cstate, "'vci' supported only on raw ATM");
9761 if (cstate->off_vci == OFFSET_NOT_SET)
9763 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_vci, BPF_H,
9768 if (cstate->off_proto == OFFSET_NOT_SET)
9770 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_proto, BPF_B,
9775 if (cstate->off_payload == OFFSET_NOT_SET)
9777 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_payload + MSG_TYPE_POS, BPF_B,
9782 if (!cstate->is_atm)
9783 bpf_error(cstate, "'callref' supported only on raw ATM");
9784 if (cstate->off_proto == OFFSET_NOT_SET)
9786 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_proto, BPF_B,
9797 gen_atmtype_metac(compiler_state_t *cstate)
9801 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0);
9802 b1 = gen_atmfield_code_internal(cstate, A_VCI, 1, BPF_JEQ, 0);
9808 gen_atmtype_sc(compiler_state_t *cstate)
9812 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0);
9813 b1 = gen_atmfield_code_internal(cstate, A_VCI, 5, BPF_JEQ, 0);
9819 gen_atmtype_llc(compiler_state_t *cstate)
9823 b0 = gen_atmfield_code_internal(cstate, A_PROTOTYPE, PT_LLC, BPF_JEQ, 0);
9824 cstate->linktype = cstate->prevlinktype;
9829 gen_atmfield_code(compiler_state_t *cstate, int atmfield,
9836 if (setjmp(cstate->top_ctx))
9839 return gen_atmfield_code_internal(cstate, atmfield, jvalue, jtype,
9844 gen_atmtype_abbrev(compiler_state_t *cstate, int type)
9852 if (setjmp(cstate->top_ctx))
9859 if (!cstate->is_atm)
9860 bpf_error(cstate, "'metac' supported only on raw ATM");
9861 b1 = gen_atmtype_metac(cstate);
9866 if (!cstate->is_atm)
9867 bpf_error(cstate, "'bcc' supported only on raw ATM");
9868 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0);
9869 b1 = gen_atmfield_code_internal(cstate, A_VCI, 2, BPF_JEQ, 0);
9875 if (!cstate->is_atm)
9876 bpf_error(cstate, "'oam4sc' supported only on raw ATM");
9877 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0);
9878 b1 = gen_atmfield_code_internal(cstate, A_VCI, 3, BPF_JEQ, 0);
9884 if (!cstate->is_atm)
9885 bpf_error(cstate, "'oam4ec' supported only on raw ATM");
9886 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0);
9887 b1 = gen_atmfield_code_internal(cstate, A_VCI, 4, BPF_JEQ, 0);
9893 if (!cstate->is_atm)
9894 bpf_error(cstate, "'sc' supported only on raw ATM");
9895 b1 = gen_atmtype_sc(cstate);
9900 if (!cstate->is_atm)
9901 bpf_error(cstate, "'ilmic' supported only on raw ATM");
9902 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0);
9903 b1 = gen_atmfield_code_internal(cstate, A_VCI, 16, BPF_JEQ, 0);
9909 if (!cstate->is_atm)
9910 bpf_error(cstate, "'lane' supported only on raw ATM");
9911 b1 = gen_atmfield_code_internal(cstate, A_PROTOTYPE, PT_LANE, BPF_JEQ, 0);
9921 PUSH_LINKHDR(cstate, DLT_EN10MB, 0,
9922 cstate->off_payload + 2, /* Ethernet header */
9924 cstate->off_linktype.constant_part = cstate->off_linkhdr.constant_part + 12;
9925 cstate->off_linkpl.constant_part = cstate->off_linkhdr.constant_part + 14; /* Ethernet */
9926 cstate->off_nl = 0; /* Ethernet II */
9927 cstate->off_nl_nosnap = 3; /* 802.3+802.2 */
9932 if (!cstate->is_atm)
9933 bpf_error(cstate, "'llc' supported only on raw ATM");
9934 b1 = gen_atmtype_llc(cstate);
9951 gen_mtp2type_abbrev(compiler_state_t *cstate, int type)
9959 if (setjmp(cstate->top_ctx))
9965 if ( (cstate->linktype != DLT_MTP2) &&
9966 (cstate->linktype != DLT_ERF) &&
9967 (cstate->linktype != DLT_MTP2_WITH_PHDR) )
9968 bpf_error(cstate, "'fisu' supported only on MTP2");
9969 /* gen_ncmp(cstate, offrel, offset, size, mask, jtype, reverse, value) */
9970 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B,
9975 if ( (cstate->linktype != DLT_MTP2) &&
9976 (cstate->linktype != DLT_ERF) &&
9977 (cstate->linktype != DLT_MTP2_WITH_PHDR) )
9978 bpf_error(cstate, "'lssu' supported only on MTP2");
9979 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B,
9981 b1 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B,
9987 if ( (cstate->linktype != DLT_MTP2) &&
9988 (cstate->linktype != DLT_ERF) &&
9989 (cstate->linktype != DLT_MTP2_WITH_PHDR) )
9990 bpf_error(cstate, "'msu' supported only on MTP2");
9991 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B,
9996 if ( (cstate->linktype != DLT_MTP2) &&
9997 (cstate->linktype != DLT_ERF) &&
9998 (cstate->linktype != DLT_MTP2_WITH_PHDR) )
9999 bpf_error(cstate, "'hfisu' supported only on MTP2_HSL");
10000 /* gen_ncmp(cstate, offrel, offset, size, mask, jtype, reverse, value) */
10001 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H,
10006 if ( (cstate
10007 (cstate->linktype != DLT_ERF) &&
10008 (cstate->linktype != DLT_MTP2_WITH_PHDR) )
10009 bpf_error(cstate, "'hlssu' supported only on MTP2_HSL");
10010 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H,
10012 b1 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H,
10018 if ( (cstate->linktype != DLT_MTP2) &&
10019 (cstate->linktype != DLT_ERF) &&
10020 (cstate->linktype != DLT_MTP2_WITH_PHDR) )
10021 bpf_error(cstate, "'hmsu' supported only on MTP2_HSL");
10022 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H,
10038 gen_mtp3field_code(compiler_state_t *cstate, int mtp3field,
10053 if (setjmp(cstate->top_ctx))
10056 newoff_sio = cstate->off_sio;
10057 newoff_opc = cstate->off_opc;
10058 newoff_dpc = cstate->off_dpc;
10059 newoff_sls = cstate->off_sls;
10067 if (cstate->off_sio == OFFSET_NOT_SET)
10068 bpf_error(cstate, "'sio' supported only on SS7");
10071 bpf_error(cstate, "sio value %u too big; max value = 255",
10073 b0 = gen_ncmp(cstate, OR_PACKET, newoff_sio, BPF_B, 0xffffffffU,
10082 if (cstate->off_opc == OFFSET_NOT_SET)
10083 bpf_error(cstate, "'opc' supported only on SS7");
10086 bpf_error(cstate, "opc value %u too big; max value = 16383",
10097 b0 = gen_ncmp(cstate, OR_PACKET, newoff_opc, BPF_W, 0x00c0ff0fU,
10106 if (cstate->off_dpc == OFFSET_NOT_SET)
10107 bpf_error(cstate, "'dpc' supported only on SS7");
10110 bpf_error(cstate, "dpc value %u too big; max value = 16383",
10119 b0 = gen_ncmp(cstate, OR_PACKET, newoff_dpc, BPF_W, 0xff3f0000U,
10128 if (cstate->off_sls == OFFSET_NOT_SET)
10129 bpf_error(cstate, "'sls' supported only on SS7");
10132 bpf_error(cstate, "sls value %u too big; max value = 15",
10137 b0 = gen_ncmp(cstate, OR_PACKET, newoff_sls, BPF_B, 0xf0U,
10148 gen_msg_abbrev(compiler_state_t *cstate, int type)
10159 b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, SETUP, BPF_JEQ, 0);
10163 b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, CALL_PROCEED, BPF_JEQ, 0);
10167 b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, CONNECT, BPF_JEQ, 0);
10171 b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, CONNECT_ACK, BPF_JEQ, 0);
10175 b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, RELEASE, BPF_JEQ, 0);
10179 b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, RELEASE_DONE, BPF_JEQ, 0);
10189 gen_atmmulti_abbrev(compiler_state_t *cstate, int type)
10197 if (setjmp(cstate->top_ctx))
10203 if (!cstate->is_atm)
10204 bpf_error(cstate, "'oam' supported only on raw ATM");
10206 b0 = gen_atmfield_code_internal(cstate, A_VCI, 3, BPF_JEQ, 0);
10207 b1 = gen_atmfield_code_internal(cstate, A_VCI, 4, BPF_JEQ, 0);
10209 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0);
10214 if (!cstate->is_atm)
10215 bpf_error(cstate, "'oamf4' supported only on raw ATM");
10217 b0 = gen_atmfield_code_internal(cstate, A_VCI, 3, BPF_JEQ, 0);
10218 b1 = gen_atmfield_code_internal(cstate, A_VCI, 4, BPF_JEQ, 0);
10220 b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0);
10229 if (!cstate->is_atm)
10230 bpf_error(cstate, "'connectmsg' supported only on raw ATM");
10231 b0 = gen_msg_abbrev(cstate, A_SETUP);
10232 b1 = gen_msg_abbrev(cstate, A_CALLPROCEED);
10234 b0 = gen_msg_abbrev(cstate, A_CONNECT);
10236 b0 = gen_msg_abbrev(cstate, A_CONNECTACK);
10238 b0 = gen_msg_abbrev(cstate, A_RELEASE);
10240 b0 = gen_msg_abbrev(cstate, A_RELEASE_DONE);
10242 b0 = gen_atmtype_sc(cstate);
10247 if (!cstate->is_atm)
10248 bpf_error(cstate, "'metaconnect' supported only on raw ATM");
10249 b0 = gen_msg_abbrev(cstate, A_SETUP);
10250 b1 = gen_msg_abbrev(cstate, A_CALLPROCEED);
10252 b0 = gen_msg_abbrev(cstate, A_CONNECT);
10254 b0 = gen_msg_abbrev(cstate, A_RELEASE);
10256 b0 = gen_msg_abbrev(cstate, A_RELEASE_DONE);
10258 b0 = gen_atmtype_metac(cstate);