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