Lines Matching defs:cstate

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