Lines Matching +full:ring +full:- +full:invert

45 #include "pcap-dos.h"
48 #include "pcap-int.h"
64 #include "diag-control.h"
75 #define offsetof(s, e) ((size_t)&((s *)0)->e)
152 #include "os-proto.h"
158 * "Push" the current value of the link-layer header type and link-layer
160 * full-blown stack; we keep only the top two items.)
164 (cs)->prevlinktype = (cs)->linktype; \
165 (cs)->off_prevlinkhdr = (cs)->off_linkhdr; \
166 (cs)->linktype = (new_linktype); \
167 (cs)->off_linkhdr.is_variable = (new_is_variable); \
168 (cs)->off_linkhdr.constant_part = (new_constant_part); \
169 (cs)->off_linkhdr.reg = (new_reg); \
170 (cs)->is_geneve = 0; \
193 * and -1 otherwise.
207 OR_LINKHDR, /* link-layer header */
208 OR_PREVLINKHDR, /* previous link-layer header */
211 OR_LINKTYPE, /* link-layer type */
212 OR_LINKPL, /* link-layer payload */
213 OR_LINKPL_NOSNAP, /* link-layer payload, with no SNAP header at the link layer */
214 OR_TRAN_IPV4, /* transport-layer header, with IPv4 network layer */
215 OR_TRAN_IPV6 /* transport-layer header, with IPv6 network layer */
224 * XXX - this *is* in a library....
283 * Absolute offset of the beginning of the link-layer header.
288 * If we're checking a link-layer header for a packet encapsulated
290 * for the previous layers' link-layer header from the beginning
297 * link-layer header.
302 * Absolute offset of the beginning of the link-layer payload.
307 * "off_linktype" is the offset to information in the link-layer
314 * For link-layer types that always use 802.2 headers, it's the
332 * TRUE if the link layer includes an ATM pseudo-header.
349 * These are offsets for the ATM pseudo-header.
371 * or -1 if there is no ATM pseudo-header.
376 * These are offsets to the beginning of the network-layer header.
377 * They are relative to the beginning of the link-layer payload
435 if (!cstate->error_set) { in bpf_set_error()
437 (void)vsnprintf(cstate->bpf_pcap->errbuf, PCAP_ERRBUF_SIZE, in bpf_set_error()
440 cstate->error_set = 1; in bpf_set_error()
457 (void)vsnprintf(cstate->bpf_pcap->errbuf, PCAP_ERRBUF_SIZE, in bpf_error()
460 longjmp(cstate->top_ctx, 1); in bpf_error()
588 cstate->chunks[i].n_left = 0; in initchunks()
589 cstate->chunks[i].m = NULL; in initchunks()
591 cstate->cur_chunk = 0; in initchunks()
603 n = (n + sizeof(long) - 1) & ~(sizeof(long) - 1); in newchunk_nolongjmp()
609 cp = &cstate->chunks[cstate->cur_chunk]; in newchunk_nolongjmp()
610 if (n > cp->n_left) { in newchunk_nolongjmp()
612 k = ++cstate->cur_chunk; in newchunk_nolongjmp()
618 cp->m = (void *)malloc(size); in newchunk_nolongjmp()
619 if (cp->m == NULL) { in newchunk_nolongjmp()
623 memset((char *)cp->m, 0, size); in newchunk_nolongjmp()
624 cp->n_left = size; in newchunk_nolongjmp()
630 cp->n_left -= n; in newchunk_nolongjmp()
631 return (void *)((char *)cp->m + cp->n_left); in newchunk_nolongjmp()
641 longjmp(cstate->top_ctx, 1); in newchunk()
653 if (cstate->chunks[i].m != NULL) in freechunks()
654 free(cstate->chunks[i].m); in freechunks()
681 p->s.code = code; in new_block()
682 p->head = p; in new_block()
693 p->s.code = code; in new_stmt()
703 b->s.k = v; in gen_retblk()
729 * link-layer type, so we can't use it. in pcap_compile()
731 if (!p->activated) { in pcap_compile()
732 (void)snprintf(p->errbuf, PCAP_ERRBUF_SIZE, in pcap_compile()
733 "not-yet-activated pcap_t passed to pcap_compile"); in pcap_compile()
754 * XXX - the fact that we happen to be compiling a filter in pcap_compile()
761 if (p->save_current_filter_op != NULL) in pcap_compile()
762 (p->save_current_filter_op)(p, buf); in pcap_compile()
781 (void)snprintf(p->errbuf, PCAP_ERRBUF_SIZE, in pcap_compile()
788 pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, in pcap_compile()
801 if (init_linktype(&cstate, p) == -1) { in pcap_compile()
828 if (bpf_optimize(&cstate.ic, p->errbuf) == -1) { in pcap_compile()
834 (cstate.ic.root->s.code == (BPF_RET|BPF_K) && cstate.ic.root->s.k == 0)) { in pcap_compile()
835 (void)snprintf(p->errbuf, PCAP_ERRBUF_SIZE, in pcap_compile()
841 program->bf_insns = icode_to_fcode(&cstate.ic, in pcap_compile()
842 cstate.ic.root, &len, p->errbuf); in pcap_compile()
843 if (program->bf_insns == NULL) { in pcap_compile()
848 program->bf_len = len; in pcap_compile()
896 program->bf_len = 0; in pcap_freecode()
897 if (program->bf_insns != NULL) { in pcap_freecode()
898 free((char *)program->bf_insns); in pcap_freecode()
899 program->bf_insns = NULL; in pcap_freecode()
915 if (!list->sense) { in backpatch()
937 p = !((*p)->sense) ? &JT(*p) : &JF(*p); in merge()
949 * Catch errors reported by us and routines below us, and return -1 in finish_parse()
952 if (setjmp(cstate->top_ctx)) in finish_parse()
953 return (-1); in finish_parse()
957 * statements needed to load the lengths of any variable-length in finish_parse()
960 * XXX - a fancier strategy would be to insert those before the in finish_parse()
974 insert_compute_vloffsets(cstate, p->head); in finish_parse()
977 * For DLT_PPI captures, generate a check of the per-packet in finish_parse()
980 * XXX - TurboCap cards use DLT_PPI for Ethernet. in finish_parse()
981 * Can we just define some DLT_ETHERNET_WITH_PHDR pseudo-header in finish_parse()
984 * the link-layer header type until runtime, which, in the in finish_parse()
993 backpatch(p, gen_retblk(cstate, cstate->snaplen)); in finish_parse()
994 p->sense = !p->sense; in finish_parse()
996 cstate->ic.root = p->head; in finish_parse()
1003 backpatch(b0, b1->head); in gen_and()
1004 b0->sense = !b0->sense; in gen_and()
1005 b1->sense = !b1->sense; in gen_and()
1007 b1->sense = !b1->sense; in gen_and()
1008 b1->head = b0->head; in gen_and()
1014 b0->sense = !b0->sense; in gen_or()
1015 backpatch(b0, b1->head); in gen_or()
1016 b0->sense = !b0->sense; in gen_or()
1018 b1->head = b0->head; in gen_or()
1024 b->sense = !b->sense; in gen_not()
1077 register const u_char *p = &v[size - 4]; in gen_bcmp()
1079 tmp = gen_cmp(cstate, offrel, offset + size - 4, BPF_W, in gen_bcmp()
1084 size -= 4; in gen_bcmp()
1087 register const u_char *p = &v[size - 2]; in gen_bcmp()
1089 tmp = gen_cmp(cstate, offrel, offset + size - 2, BPF_H, in gen_bcmp()
1094 size -= 2; in gen_bcmp()
1123 s2->s.k = mask; in gen_ncmp()
1128 b->stmts = s; in gen_ncmp()
1129 b->s.k = v; in gen_ncmp()
1138 cstate->pcap_fddipad = p->fddipad; in init_linktype()
1141 * We start out with only one link-layer header. in init_linktype()
1143 cstate->outermostlinktype = pcap_datalink(p); in init_linktype()
1144 cstate->off_outermostlinkhdr.constant_part = 0; in init_linktype()
1145 cstate->off_outermostlinkhdr.is_variable = 0; in init_linktype()
1146 cstate->off_outermostlinkhdr.reg = -1; in init_linktype()
1148 cstate->prevlinktype = cstate->outermostlinktype; in init_linktype()
1149 cstate->off_prevlinkhdr.constant_part = 0; in init_linktype()
1150 cstate->off_prevlinkhdr.is_variable = 0; in init_linktype()
1151 cstate->off_prevlinkhdr.reg = -1; in init_linktype()
1153 cstate->linktype = cstate->outermostlinktype; in init_linktype()
1154 cstate->off_linkhdr.constant_part = 0; in init_linktype()
1155 cstate->off_linkhdr.is_variable = 0; in init_linktype()
1156 cstate->off_linkhdr.reg = -1; in init_linktype()
1161 cstate->off_linkpl.constant_part = 0; in init_linktype()
1162 cstate->off_linkpl.is_variable = 0; in init_linktype()
1163 cstate->off_linkpl.reg = -1; in init_linktype()
1165 cstate->off_linktype.constant_part = 0; in init_linktype()
1166 cstate->off_linktype.is_variable = 0; in init_linktype()
1167 cstate->off_linktype.reg = -1; in init_linktype()
1170 * Assume it's not raw ATM with a pseudo-header, for now. in init_linktype()
1172 cstate->is_atm = 0; in init_linktype()
1173 cstate->off_vpi = OFFSET_NOT_SET; in init_linktype()
1174 cstate->off_vci = OFFSET_NOT_SET; in init_linktype()
1175 cstate->off_proto = OFFSET_NOT_SET; in init_linktype()
1176 cstate->off_payload = OFFSET_NOT_SET; in init_linktype()
1181 cstate->is_geneve = 0; in init_linktype()
1186 cstate->is_vlan_vloffset = 0; in init_linktype()
1191 cstate->off_li = OFFSET_NOT_SET; in init_linktype()
1192 cstate->off_li_hsl = OFFSET_NOT_SET; in init_linktype()
1193 cstate->off_sio = OFFSET_NOT_SET; in init_linktype()
1194 cstate->off_opc = OFFSET_NOT_SET; in init_linktype()
1195 cstate->off_dpc = OFFSET_NOT_SET; in init_linktype()
1196 cstate->off_sls = OFFSET_NOT_SET; in init_linktype()
1198 cstate->label_stack_depth = 0; in init_linktype()
1199 cstate->vlan_stack_depth = 0; in init_linktype()
1201 switch (cstate->linktype) { in init_linktype()
1204 cstate->off_linktype.constant_part = 2; in init_linktype()
1205 cstate->off_linkpl.constant_part = 6; in init_linktype()
1206 cstate->off_nl = 0; /* XXX in reality, variable! */ in init_linktype()
1207 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1211 cstate->off_linktype.constant_part = 4; in init_linktype()
1212 cstate->off_linkpl.constant_part = 8; in init_linktype()
1213 cstate->off_nl = 0; /* XXX in reality, variable! */ in init_linktype()
1214 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1218 cstate->off_linktype.constant_part = 12; in init_linktype()
1219 cstate->off_linkpl.constant_part = 14; /* Ethernet header length */ in init_linktype()
1220 cstate->off_nl = 0; /* Ethernet II */ in init_linktype()
1221 cstate->off_nl_nosnap = 3; /* 802.3+802.2 */ in init_linktype()
1229 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1230 cstate->off_linkpl.constant_part = 16; in init_linktype()
1231 cstate->off_nl = 0; in init_linktype()
1232 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1237 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1239 cstate->off_linkpl.constant_part = 24; in init_linktype()
1240 cstate->off_nl = 0; in init_linktype()
1241 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1246 cstate->off_linktype.constant_part = 0; in init_linktype()
1247 cstate->off_linkpl.constant_part = 4; in init_linktype()
1248 cstate->off_nl = 0; in init_linktype()
1249 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1253 cstate->off_linktype.constant_part = 0; in init_linktype()
1254 cstate->off_linkpl.constant_part = 12; in init_linktype()
1255 cstate->off_nl = 0; in init_linktype()
1256 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1264 cstate->off_linktype.constant_part = 2; /* skip HDLC-like framing */ in init_linktype()
1265 cstate->off_linkpl.constant_part = 4; /* skip HDLC-like framing and protocol field */ in init_linktype()
1266 cstate->off_nl = 0; in init_linktype()
1267 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1275 cstate->off_linktype.constant_part = 6; in init_linktype()
1276 cstate->off_linkpl.constant_part = 8; in init_linktype()
1277 cstate->off_nl = 0; in init_linktype()
1278 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1282 cstate->off_linktype.constant_part = 5; in init_linktype()
1283 cstate->off_linkpl.constant_part = 24; in init_linktype()
1284 cstate->off_nl = 0; in init_linktype()
1285 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1290 * FDDI doesn't really have a link-level type field. in init_linktype()
1295 * XXX - should we generate code to check for SNAP? in init_linktype()
1297 cstate->off_linktype.constant_part = 13; in init_linktype()
1298 cstate->off_linktype.constant_part += cstate->pcap_fddipad; in init_linktype()
1299 cstate->off_linkpl.constant_part = 13; /* FDDI MAC header length */ in init_linktype()
1300 cstate->off_linkpl.constant_part += cstate->pcap_fddipad; in init_linktype()
1301 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1302 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1307 * Token Ring doesn't really have a link-level type field. in init_linktype()
1312 * XXX - should we generate code to check for SNAP? in init_linktype()
1314 * XXX - the header is actually variable-length. in init_linktype()
1317 * if a token ring packet has *no* routing in init_linktype()
1318 * information, i.e. is not source-routed, the correct in init_linktype()
1321 * A packet is source-routed iff the uppermost bit in init_linktype()
1324 * packet is source-routed, the total number of bytes in init_linktype()
1326 * the 16-bit value at an offset of 14 (shifted right in init_linktype()
1327 * 8 - figure out which byte that is). in init_linktype()
1329 cstate->off_linktype.constant_part = 14; in init_linktype()
1330 cstate->off_linkpl.constant_part = 14; /* Token Ring MAC header length */ in init_linktype()
1331 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1332 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1338 cstate->off_linkhdr.is_variable = 1; in init_linktype()
1345 * 802.11 doesn't really have a link-level type field. in init_linktype()
1351 * XXX - should we generate code to check for SNAP? in init_linktype()
1353 * We also handle variable-length radio headers here. in init_linktype()
1354 * The Prism header is in theory variable-length, but in in init_linktype()
1360 * variable-length. in init_linktype()
1362 cstate->off_linktype.constant_part = 24; in init_linktype()
1363 cstate->off_linkpl.constant_part = 0; /* link-layer header is variable-length */ in init_linktype()
1364 cstate->off_linkpl.is_variable = 1; in init_linktype()
1365 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1366 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1379 cstate->off_linktype.constant_part = 24; in init_linktype()
1380 cstate->off_linkpl.constant_part = 0; /* link-layer header is variable-length */ in init_linktype()
1381 cstate->off_linkpl.is_variable = 1; in init_linktype()
1382 cstate->off_linkhdr.is_variable = 1; in init_linktype()
1383 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1384 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1390 * assume routed, non-ISO PDUs in init_linktype()
1391 * (i.e., LLC = 0xAA-AA-03, OUT = 0x00-00-00) in init_linktype()
1393 * XXX - what about ISO PDUs, e.g. CLNP, ISIS, ESIS, in init_linktype()
1400 cstate->off_linktype.constant_part = 0; in init_linktype()
1401 cstate->off_linkpl.constant_part = 0; /* packet begins with LLC header */ in init_linktype()
1402 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1403 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1409 * pseudo-header. in init_linktype()
1411 cstate->is_atm = 1; in init_linktype()
1412 cstate->off_vpi = SUNATM_VPI_POS; in init_linktype()
1413 cstate->off_vci = SUNATM_VCI_POS; in init_linktype()
1414 cstate->off_proto = PROTO_POS; in init_linktype()
1415 cstate->off_payload = SUNATM_PKT_BEGIN_POS; in init_linktype()
1416 cstate->off_linktype.constant_part = cstate->off_payload; in init_linktype()
1417 cstate->off_linkpl.constant_part = cstate->off_payload; /* if LLC-encapsulated */ in init_linktype()
1418 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1419 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1425 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1426 cstate->off_linkpl.constant_part = 0; in init_linktype()
1427 cstate->off_nl = 0; in init_linktype()
1428 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1432 cstate->off_linktype.constant_part = 14; in init_linktype()
1433 cstate->off_linkpl.constant_part = 16; in init_linktype()
1434 cstate->off_nl = 0; in init_linktype()
1435 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1439 cstate->off_linktype.constant_part = 0; in init_linktype()
1440 cstate->off_linkpl.constant_part = 20; in init_linktype()
1441 cstate->off_nl = 0; in init_linktype()
1442 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1447 * LocalTalk does have a 1-byte type field in the LLAP header, in init_linktype()
1451 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1452 cstate->off_linkpl.constant_part = 0; in init_linktype()
1453 cstate->off_nl = 0; in init_linktype()
1454 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1459 * RFC 2625 IP-over-Fibre-Channel doesn't really have a in init_linktype()
1460 * link-level type field. We set "off_linktype" to the in init_linktype()
1465 * XXX - should we generate code to check for SNAP? RFC in init_linktype()
1468 cstate->off_linktype.constant_part = 16; in init_linktype()
1469 cstate->off_linkpl.constant_part = 16; in init_linktype()
1470 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1471 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1476 * XXX - we should set this to handle SNAP-encapsulated in init_linktype()
1479 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1480 cstate->off_linkpl.constant_part = 0; in init_linktype()
1481 cstate->off_nl = 0; in init_linktype()
1482 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1486 * the only BPF-interesting FRF.16 frames are non-control frames; in init_linktype()
1487 * Frame Relay has a variable length link-layer in init_linktype()
1491 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1492 cstate->off_linkpl.constant_part = 0; in init_linktype()
1493 cstate->off_nl = 4; in init_linktype()
1494 cstate->off_nl_nosnap = 0; /* XXX - for now -> no 802.2 LLC */ in init_linktype()
1498 cstate->off_linktype.constant_part = 16; in init_linktype()
1499 cstate->off_linkpl.constant_part = 18; in init_linktype()
1500 cstate->off_nl = 0; in init_linktype()
1501 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1505 cstate->off_linktype.constant_part = 6; in init_linktype()
1506 cstate->off_linkpl.constant_part = 44; in init_linktype()
1507 cstate->off_nl = 0; /* Ethernet II */ in init_linktype()
1508 cstate->off_nl_nosnap = 0; /* XXX - what does it do with 802.3 packets? */ in init_linktype()
1512 cstate->off_linktype.constant_part = 0; in init_linktype()
1513 cstate->off_linkpl.constant_part = 0; /* link-layer header is variable-length */ in init_linktype()
1514 cstate->off_linkpl.is_variable = 1; in init_linktype()
1515 cstate->off_nl = 0; in init_linktype()
1516 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1525 cstate->off_linktype.constant_part = 4; in init_linktype()
1526 cstate->off_linkpl.constant_part = 4; in init_linktype()
1527 cstate->off_nl = 0; in init_linktype()
1528 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1532 cstate->off_linktype.constant_part = 4; /* in reality variable between 4-8 */ in init_linktype()
1533 cstate->off_linkpl.constant_part = 4; /* in reality variable between 4-8 */ in init_linktype()
1534 cstate->off_nl = 0; in init_linktype()
1535 cstate->off_nl_nosnap = 10; in init_linktype()
1539 cstate->off_linktype.constant_part = 8; /* in reality variable between 8-12 */ in init_linktype()
1540 cstate->off_linkpl.constant_part = 8; /* in reality variable between 8-12 */ in init_linktype()
1541 cstate->off_nl = 0; in init_linktype()
1542 cstate->off_nl_nosnap = 10; in init_linktype()
1549 cstate->off_linkpl.constant_part = 14; in init_linktype()
1550 cstate->off_linktype.constant_part = 16; in init_linktype()
1551 cstate->off_nl = 18; /* Ethernet II */ in init_linktype()
1552 cstate->off_nl_nosnap = 21; /* 802.3+802.2 */ in init_linktype()
1556 cstate->off_linktype.constant_part = 4; in init_linktype()
1557 cstate->off_linkpl.constant_part = 6; in init_linktype()
1558 cstate->off_nl = 0; in init_linktype()
1559 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1563 cstate->off_linktype.constant_part = 6; in init_linktype()
1564 cstate->off_linkpl.constant_part = 12; in init_linktype()
1565 cstate->off_nl = 0; in init_linktype()
1566 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1570 cstate->off_linktype.constant_part = 6; in init_linktype()
1571 …cstate->off_linkpl.constant_part = OFFSET_NOT_SET; /* not really a network layer but raw IP addres… in init_linktype()
1572 cstate->off_nl = OFFSET_NOT_SET; /* not really a network layer but raw IP addresses */ in init_linktype()
1573 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1577 cstate->off_linktype.constant_part = 12; in init_linktype()
1578 cstate->off_linkpl.constant_part = 12; in init_linktype()
1579 cstate->off_nl = 0; /* raw IP/IP6 header */ in init_linktype()
1580 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1584 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1585 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1586 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1587 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1591 cstate->off_linktype.constant_part = 12; in init_linktype()
1592 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; /* L3 proto location dep. on cookie type */ in init_linktype()
1593 cstate->off_nl = OFFSET_NOT_SET; /* L3 proto location dep. on cookie type */ in init_linktype()
1594 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1598 cstate->off_linktype.constant_part = 18; in init_linktype()
1599 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1600 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1601 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1605 cstate->off_linktype.constant_part = 18; in init_linktype()
1606 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1607 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1608 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1612 cstate->off_linktype.constant_part = 8; in init_linktype()
1613 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1614 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1615 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1622 cstate->off_linktype.constant_part = 8; in init_linktype()
1623 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1624 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1625 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1629 cstate->off_li = 2; in init_linktype()
1630 cstate->off_li_hsl = 4; in init_linktype()
1631 cstate->off_sio = 3; in init_linktype()
1632 cstate->off_opc = 4; in init_linktype()
1633 cstate->off_dpc = 4; in init_linktype()
1634 cstate->off_sls = 7; in init_linktype()
1635 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1636 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1637 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1638 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1642 cstate->off_li = 6; in init_linktype()
1643 cstate->off_li_hsl = 8; in init_linktype()
1644 cstate->off_sio = 7; in init_linktype()
1645 cstate->off_opc = 8; in init_linktype()
1646 cstate->off_dpc = 8; in init_linktype()
1647 cstate->off_sls = 11; in init_linktype()
1648 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1649 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1650 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1651 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1655 cstate->off_li = 22; in init_linktype()
1656 cstate->off_li_hsl = 24; in init_linktype()
1657 cstate->off_sio = 23; in init_linktype()
1658 cstate->off_opc = 24; in init_linktype()
1659 cstate->off_dpc = 24; in init_linktype()
1660 cstate->off_sls = 27; in init_linktype()
1661 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1662 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1663 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1664 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1668 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1669 cstate->off_linkpl.constant_part = 4; in init_linktype()
1670 cstate->off_nl = 0; in init_linktype()
1671 cstate->off_nl_nosnap = 0; in init_linktype()
1678 cstate->off_linktype.constant_part = OFFSET_NOT_SET; /* variable, min 15, max 71 steps of 7 */ in init_linktype()
1679 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1680 cstate->off_nl = OFFSET_NOT_SET; /* variable, min 16, max 71 steps of 7 */ in init_linktype()
1681 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1685 cstate->off_linktype.constant_part = 1; in init_linktype()
1686 cstate->off_linkpl.constant_part = 24; /* ipnet header length */ in init_linktype()
1687 cstate->off_nl = 0; in init_linktype()
1688 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1692 cstate->off_linkhdr.constant_part = 4; /* Ethernet header is past 4-byte pseudo-header */ in init_linktype()
1693 cstate->off_linktype.constant_part = cstate->off_linkhdr.constant_part + 12; in init_linktype()
1694 …cstate->off_linkpl.constant_part = cstate->off_linkhdr.constant_part + 14; /* pseudo-header+Ethern… in init_linktype()
1695 cstate->off_nl = 0; /* Ethernet II */ in init_linktype()
1696 cstate->off_nl_nosnap = 3; /* 802.3+802.2 */ in init_linktype()
1700 …cstate->off_linkhdr.constant_part = 12; /* MAC header is past 4-byte pseudo-header, preamble, and … in init_linktype()
1701 cstate->off_linktype.constant_part = cstate->off_linkhdr.constant_part + 12; in init_linktype()
1702 …cstate->off_linkpl.constant_part = cstate->off_linkhdr.constant_part + 14; /* pseudo-header+preamb… in init_linktype()
1703 cstate->off_nl = 0; /* Ethernet II */ in init_linktype()
1704 cstate->off_nl_nosnap = 3; /* 802.3+802.2 */ in init_linktype()
1712 if (cstate->linktype >= DLT_HIGH_MATCHING_MIN && in init_linktype()
1713 cstate->linktype <= DLT_HIGH_MATCHING_MAX) { in init_linktype()
1714 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1715 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1716 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1717 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1720 cstate->linktype, DLT_HIGH_MATCHING_MIN, DLT_HIGH_MATCHING_MAX); in init_linktype()
1721 return (-1); in init_linktype()
1726 cstate->off_outermostlinkhdr = cstate->off_prevlinkhdr = cstate->off_linkhdr; in init_linktype()
1742 * If "s" is non-null, it has code to arrange that the X register in gen_load_absoffsetrel()
1745 * abs_offset->constant_part + offset. in gen_load_absoffsetrel()
1748 * abs_offset->constant_part + offset. in gen_load_absoffsetrel()
1757 s2->s.k = abs_offset->constant_part + offset; in gen_load_absoffsetrel()
1765 s->s.k = abs_offset->constant_part + offset; in gen_load_absoffsetrel()
1796 s->s.k = offset; in gen_load_a()
1800 s = gen_load_absoffsetrel(cstate, &cstate->off_linkhdr, offset, size); in gen_load_a()
1804 s = gen_load_absoffsetrel(cstate, &cstate->off_prevlinkhdr, offset, size); in gen_load_a()
1808 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, offset, size); in gen_load_a()
1812 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, cstate->off_nl - 4 + offset, size); in gen_load_a()
1816 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, cstate->off_nl + offset, size); in gen_load_a()
1820 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, cstate->off_nl_nosnap + offset, size); in gen_load_a()
1824 s = gen_load_absoffsetrel(cstate, &cstate->off_linktype, offset, size); in gen_load_a()
1830 * (plus the offset of the link-layer header, if it's in gen_load_a()
1831 * preceded by a variable-length header such as a radio in gen_load_a()
1837 * Load the item at {offset of the link-layer payload} + in gen_load_a()
1838 * {offset, relative to the start of the link-layer in gen_load_a()
1842 * If the offset of the link-layer payload is variable, in gen_load_a()
1848 s2->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + offset; in gen_load_a()
1853 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, cstate->off_nl + 40 + offset, size); in gen_load_a()
1861 * the IPv4 header and the variable part of the offset of the link-layer
1869 s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl); in gen_loadx_iphdrlen()
1872 * The offset of the link-layer payload has a variable in gen_loadx_iphdrlen()
1882 s2->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_loadx_iphdrlen()
1885 s2->s.k = 0xf; in gen_loadx_iphdrlen()
1888 s2->s.k = 2; in gen_loadx_iphdrlen()
1894 * the link-layer payload, which is still in the X in gen_loadx_iphdrlen()
1901 * The offset of the link-layer payload is a constant, in gen_loadx_iphdrlen()
1907 * is at an offset of cstate->off_nl from the beginning of in gen_loadx_iphdrlen()
1908 * the link-layer payload, and thus at an offset of in gen_loadx_iphdrlen()
1909 * cstate->off_linkpl.constant_part + cstate->off_nl from the beginning in gen_loadx_iphdrlen()
1913 s->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_loadx_iphdrlen()
1926 s->s.k = !rsense; in gen_uncond()
1928 b->stmts = s; in gen_uncond()
1946 * Byte-swap a 32-bit number.
1947 * ("htonl()" or "ntohl()" won't work - we want to byte-swap even on
1948 * big-endian platforms.)
1976 * LLCSAP_IP checks for IP-over-802.2, rather in gen_ether_linktype()
1977 * than IP-over-Ethernet or IP-over-SNAP. in gen_ether_linktype()
1979 * XXX - should we check both the DSAP and the in gen_ether_linktype()
2015 * XXX - should we generate the same code both in gen_ether_linktype()
2074 * 802.2-encapsulated ETHERTYPE_ATALK packets are in gen_ether_linktype()
2079 * 802.2-encapsulated ETHERTYPE_AARP packets are in gen_ether_linktype()
2134 * For DLT_NULL, the link-layer header is a 32-bit word in gen_loopback_linktype()
2136 * DLT_ENC, the link-layer header begins with a 32-bit in gen_loopback_linktype()
2143 * For DLT_LOOP, the link-layer header is a 32-bit in gen_loopback_linktype()
2146 if (cstate->linktype == DLT_NULL || cstate->linktype == DLT_ENC) { in gen_loopback_linktype()
2152 * with the opposite byte order to ours, we byte-swap in gen_loopback_linktype()
2158 if (cstate->bpf_pcap->rfile != NULL && cstate->bpf_pcap->swapped) in gen_loopback_linktype()
2211 * LLCSAP_IP checks for IP-over-802.2, rather in gen_linux_sll_linktype()
2212 * than IP-over-Ethernet or IP-over-SNAP. in gen_linux_sll_linktype()
2214 * XXX - should we check both the DSAP and the in gen_linux_sll_linktype()
2287 * 802.2-encapsulated ETHERTYPE_ATALK packets are in gen_linux_sll_linktype()
2292 * 802.2-encapsulated ETHERTYPE_AARP packets are in gen_linux_sll_linktype()
2323 b1 = gen_cmp(cstate, OR_LINKHDR, cstate->off_linkpl.constant_part, BPF_B, in gen_linux_sll_linktype()
2343 * Load a value relative to the beginning of the link-layer header after the
2358 if (cstate->off_linkpl.reg != -1) { in gen_load_pflog_llprefixlen()
2363 s1->s.k = 0; in gen_load_pflog_llprefixlen()
2370 s2->s.k = 3; in gen_load_pflog_llprefixlen()
2373 s2->s.k = 0xfffffffc; in gen_load_pflog_llprefixlen()
2381 s2->s.k = cstate->off_linkpl.reg; in gen_load_pflog_llprefixlen()
2407 cstate->no_optimize = 1; in gen_load_prism_llprefixlen()
2418 * We load a 4-byte big-endian value at the beginning of the in gen_load_prism_llprefixlen()
2421 * an AVS header (the masked-out bits are the version number). in gen_load_prism_llprefixlen()
2424 * XXX - the Prism header is also, in theory, variable-length, in gen_load_prism_llprefixlen()
2428 if (cstate->off_linkhdr.reg != -1) { in gen_load_prism_llprefixlen()
2433 s1->s.k = 0; in gen_load_prism_llprefixlen()
2439 s2->s.k = 0xFFFFF000; in gen_load_prism_llprefixlen()
2446 sjeq_avs_cookie->s.k = 0x80211000; in gen_load_prism_llprefixlen()
2454 * That field is big-endian. in gen_load_prism_llprefixlen()
2457 s2->s.k = 4; in gen_load_prism_llprefixlen()
2459 sjeq_avs_cookie->s.jt = s2; in gen_load_prism_llprefixlen()
2470 sjcommon->s.k = 1; in gen_load_prism_llprefixlen()
2480 s2->s.k = 144; in gen_load_prism_llprefixlen()
2482 sjeq_avs_cookie->s.jf = s2; in gen_load_prism_llprefixlen()
2490 s2->s.k = cstate->off_linkhdr.reg; in gen_load_prism_llprefixlen()
2492 sjcommon->s.jf = s2; in gen_load_prism_llprefixlen()
2517 if (cstate->off_linkhdr.reg != -1) { in gen_load_avs_llprefixlen()
2521 * That field is big-endian. in gen_load_avs_llprefixlen()
2524 s1->s.k = 4; in gen_load_avs_llprefixlen()
2531 s2->s.k = cstate->off_linkhdr.reg; in gen_load_avs_llprefixlen()
2557 if (cstate->off_linkhdr.reg != -1) { in gen_load_radiotap_llprefixlen()
2561 * header; unfortunately, it's little-endian, so we have in gen_load_radiotap_llprefixlen()
2566 * Load the high-order byte, at an offset of 3, shift it in gen_load_radiotap_llprefixlen()
2570 s1->s.k = 3; in gen_load_radiotap_llprefixlen()
2573 s2->s.k = 8; in gen_load_radiotap_llprefixlen()
2583 s2->s.k = 2; in gen_load_radiotap_llprefixlen()
2592 s2->s.k = cstate->off_linkhdr.reg; in gen_load_radiotap_llprefixlen()
2625 if (cstate->off_linkhdr.reg != -1) { in gen_load_ppi_llprefixlen()
2629 * header; unfortunately, it's little-endian, so we have in gen_load_ppi_llprefixlen()
2634 * Load the high-order byte, at an offset of 3, shift it in gen_load_ppi_llprefixlen()
2638 s1->s.k = 3; in gen_load_ppi_llprefixlen()
2641 s2->s.k = 8; in gen_load_ppi_llprefixlen()
2651 s2->s.k = 2; in gen_load_ppi_llprefixlen()
2660 s2->s.k = cstate->off_linkhdr.reg; in gen_load_ppi_llprefixlen()
2675 * Load a value relative to the beginning of the link-layer header after the 802.11
2677 * The link-layer header doesn't necessarily begin at the beginning
2678 * of the packet data; there might be a variable-length prefix containing
2694 if (cstate->off_linkpl.reg == -1) { in gen_load_802_11_header_len()
2697 * the link-layer payload, which means nobody needs in gen_load_802_11_header_len()
2698 * it; don't bother computing it - just return in gen_load_802_11_header_len()
2709 cstate->no_optimize = 1; in gen_load_802_11_header_len()
2712 * If "s" is non-null, it has code to arrange that the X register in gen_load_802_11_header_len()
2713 * contains the length of the prefix preceding the link-layer in gen_load_802_11_header_len()
2716 * Otherwise, the length of the prefix preceding the link-layer in gen_load_802_11_header_len()
2721 * There is no variable-length header preceding the in gen_load_802_11_header_len()
2722 * link-layer header. in gen_load_802_11_header_len()
2724 * Load the length of the fixed-length prefix preceding in gen_load_802_11_header_len()
2725 * the link-layer header (if any) into the X register, in gen_load_802_11_header_len()
2726 * and store it in the cstate->off_linkpl.reg register. in gen_load_802_11_header_len()
2730 s->s.k = cstate->off_outermostlinkhdr.constant_part; in gen_load_802_11_header_len()
2735 * link-layer header; add 24, which is the minimum length in gen_load_802_11_header_len()
2737 * in cstate->off_linkpl.reg, and then load the Frame Control field, in gen_load_802_11_header_len()
2743 s2->s.k = 24; in gen_load_802_11_header_len()
2746 s2->s.k = cstate->off_linkpl.reg; in gen_load_802_11_header_len()
2750 s2->s.k = 0; in gen_load_802_11_header_len()
2759 sjset_data_frame_1->s.k = 0x08; in gen_load_802_11_header_len()
2766 sjset_data_frame_1->s.jt = sjset_data_frame_2 = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2767 sjset_data_frame_2->s.k = 0x04; in gen_load_802_11_header_len()
2769 sjset_data_frame_1->s.jf = snext; in gen_load_802_11_header_len()
2776 sjset_data_frame_2->s.jt = snext; in gen_load_802_11_header_len()
2777 sjset_data_frame_2->s.jf = sjset_qos = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2778 sjset_qos->s.k = 0x80; /* QoS bit */ in gen_load_802_11_header_len()
2782 * If it's set, add 2 to cstate->off_linkpl.reg, to skip the QoS in gen_load_802_11_header_len()
2787 sjset_qos->s.jt = s2 = new_stmt(cstate, BPF_LD|BPF_MEM); in gen_load_802_11_header_len()
2788 s2->s.k = cstate->off_linkpl.reg; in gen_load_802_11_header_len()
2791 s2->s.k = 2; in gen_load_802_11_header_len()
2794 s2->s.k = cstate->off_linkpl.reg; in gen_load_802_11_header_len()
2799 * there's Atheros padding between the MAC-layer header in gen_load_802_11_header_len()
2803 * little-endian, so we byte-swap all of the values in gen_load_802_11_header_len()
2804 * we test against, as they will be loaded as big-endian in gen_load_802_11_header_len()
2807 * XXX - in the general case, we would have to scan through in gen_load_802_11_header_len()
2816 if (cstate->linktype == DLT_IEEE802_11_RADIO) { in gen_load_802_11_header_len()
2821 sjset_qos->s.jf = s2 = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_W); in gen_load_802_11_header_len()
2822 s2->s.k = 4; in gen_load_802_11_header_len()
2826 sjset_radiotap_flags_present->s.k = SWAPLONG(0x00000002); in gen_load_802_11_header_len()
2832 sjset_radiotap_flags_present->s.jf = snext; in gen_load_802_11_header_len()
2838 sjset_radiotap_ext_present->s.k = SWAPLONG(0x80000000); in gen_load_802_11_header_len()
2840 sjset_radiotap_flags_present->s.jt = sjset_radiotap_ext_present; in gen_load_802_11_header_len()
2845 sjset_radiotap_ext_present->s.jt = snext; in gen_load_802_11_header_len()
2851 sjset_radiotap_tsft_present->s.k = SWAPLONG(0x00000001); in gen_load_802_11_header_len()
2853 sjset_radiotap_ext_present->s.jf = sjset_radiotap_tsft_present; in gen_load_802_11_header_len()
2865 s2->s.k = 16; in gen_load_802_11_header_len()
2867 sjset_radiotap_tsft_present->s.jt = s2; in gen_load_802_11_header_len()
2870 sjset_tsft_datapad->s.k = 0x20; in gen_load_802_11_header_len()
2882 s2->s.k = 8; in gen_load_802_11_header_len()
2884 sjset_radiotap_tsft_present->s.jf = s2; in gen_load_802_11_header_len()
2887 sjset_notsft_datapad->s.k = 0x20; in gen_load_802_11_header_len()
2898 s_roundup->s.k = cstate->off_linkpl.reg; in gen_load_802_11_header_len()
2901 s2->s.k = 3; in gen_load_802_11_header_len()
2904 s2->s.k = (bpf_u_int32)~3; in gen_load_802_11_header_len()
2907 s2->s.k = cstate->off_linkpl.reg; in gen_load_802_11_header_len()
2910 sjset_tsft_datapad->s.jt = s_roundup; in gen_load_802_11_header_len()
2911 sjset_tsft_datapad->s.jf = snext; in gen_load_802_11_header_len()
2912 sjset_notsft_datapad->s.jt = s_roundup; in gen_load_802_11_header_len()
2913 sjset_notsft_datapad->s.jf = snext; in gen_load_802_11_header_len()
2915 sjset_qos->s.jf = snext; in gen_load_802_11_header_len()
2930 if (cstate->off_linkpl.reg != -1 && cstate->off_linkhdr.is_variable && in insert_compute_vloffsets()
2931 cstate->off_linkhdr.reg == -1) in insert_compute_vloffsets()
2932 cstate->off_linkhdr.reg = alloc_reg(cstate); in insert_compute_vloffsets()
2935 * For link-layer types that have a variable-length header in insert_compute_vloffsets()
2936 * preceding the link-layer header, generate code to load in insert_compute_vloffsets()
2937 * the offset of the link-layer header into the register in insert_compute_vloffsets()
2940 * XXX - this, and the next switch statement, won't handle in insert_compute_vloffsets()
2945 switch (cstate->outermostlinktype) { in insert_compute_vloffsets()
2969 * For link-layer types that have a variable-length link-layer in insert_compute_vloffsets()
2970 * header, generate code to load the offset of the link-layer in insert_compute_vloffsets()
2973 switch (cstate->outermostlinktype) { in insert_compute_vloffsets()
2980 s = gen_load_802_11_header_len(cstate, s, b->stmts); in insert_compute_vloffsets()
2992 if (s == NULL && cstate->is_vlan_vloffset) { in insert_compute_vloffsets()
2995 if (cstate->off_linkpl.reg == -1) in insert_compute_vloffsets()
2996 cstate->off_linkpl.reg = alloc_reg(cstate); in insert_compute_vloffsets()
2997 if (cstate->off_linktype.reg == -1) in insert_compute_vloffsets()
2998 cstate->off_linktype.reg = alloc_reg(cstate); in insert_compute_vloffsets()
3001 s->s.k = 0; in insert_compute_vloffsets()
3003 s2->s.k = cstate->off_linkpl.reg; in insert_compute_vloffsets()
3006 s2->s.k = cstate->off_linktype.reg; in insert_compute_vloffsets()
3011 * If we have any offset-loading code, append all the in insert_compute_vloffsets()
3017 sappend(s, b->stmts); in insert_compute_vloffsets()
3018 b->stmts = s; in insert_compute_vloffsets()
3028 if (cstate->linktype == DLT_PPI) in gen_ppi_dlt_check()
3033 s_load_dlt->s.k = 4; in gen_ppi_dlt_check()
3037 b->stmts = s_load_dlt; in gen_ppi_dlt_check()
3038 b->s.k = SWAPLONG(DLT_IEEE802_11); in gen_ppi_dlt_check()
3055 * a pointer to that code - if no register for that offset has
3066 if (off->is_variable) { in gen_abs_offset_varpart()
3067 if (off->reg == -1) { in gen_abs_offset_varpart()
3070 * variable part of the offset of the link-layer in gen_abs_offset_varpart()
3073 off->reg = alloc_reg(cstate); in gen_abs_offset_varpart()
3078 * offset of the link-layer header into the X register. in gen_abs_offset_varpart()
3081 s->s.k = off->reg; in gen_abs_offset_varpart()
3141 * Generate any tests that, for encapsulation of a link-layer packet
3143 * link-layer packets (and that haven't already been done by a check
3151 if (cstate->is_geneve) in gen_prevlinkhdr_check()
3154 switch (cstate->prevlinktype) { in gen_prevlinkhdr_check()
3158 * This is LANE-encapsulated Ethernet; check that the LANE in gen_prevlinkhdr_check()
3183 #define BSD_AFNUM_INET6_DARWIN 30 /* macOS, iOS, other Darwin-based OSes */
3187 * link-layer type field or fields in the 802.2 LLC header.
3198 /* are we checking MPLS-encapsulated packets? */ in gen_linktype()
3199 if (cstate->label_stack_depth > 0) in gen_linktype()
3202 switch (cstate->linktype) { in gen_linktype()
3209 if (!cstate->is_geneve) in gen_linktype()
3244 * Now check for the specified link-layer type. in gen_linktype()
3253 * XXX - check for LLC frames. in gen_linktype()
3260 * XXX - check for LLC PDUs, as per IEEE 802.5. in gen_linktype()
3273 * Check for an LLC-encapsulated version of this protocol; in gen_linktype()
3296 * XXX - for IPv4, check for a version number of 4, and, in gen_linktype()
3357 * Also check for Van Jacobson-compressed IP. in gen_linktype()
3358 * XXX - do this for other forms of PPP? in gen_linktype()
3383 * AF_ values may, unfortunately, be platform- in gen_linktype()
3404 if (cstate->bpf_pcap->rfile != NULL) { in gen_linktype()
3406 * Savefile - check for all three in gen_linktype()
3445 * XXX - support those that have AF_ values in gen_linktype()
3518 * XXX - assumes a 2-byte Frame Relay header with in gen_linktype()
3560 bpf_error(cstate, "Multi-link Frame Relay link-layer type filtering not implemented"); in gen_linktype()
3585 /* just lets verify the magic number for now - in gen_linktype()
3601 bpf_error(cstate, "IrDA link-layer type filtering not implemented"); in gen_linktype()
3604 bpf_error(cstate, "DOCSIS link-layer type filtering not implemented"); in gen_linktype()
3608 bpf_error(cstate, "MTP2 link-layer type filtering not implemented"); in gen_linktype()
3611 bpf_error(cstate, "ERF link-layer type filtering not implemented"); in gen_linktype()
3614 bpf_error(cstate, "PFSYNC link-layer type filtering not implemented"); in gen_linktype()
3617 bpf_error(cstate, "LAPD link-layer type filtering not implemented"); in gen_linktype()
3623 bpf_error(cstate, "USB link-layer type filtering not implemented"); in gen_linktype()
3627 bpf_error(cstate, "Bluetooth link-layer type filtering not implemented"); in gen_linktype()
3631 bpf_error(cstate, "CAN link-layer type filtering not implemented"); in gen_linktype()
3638 bpf_error(cstate, "IEEE 802.15.4 link-layer type filtering not implemented"); in gen_linktype()
3641 bpf_error(cstate, "IEEE 802.16 link-layer type filtering not implemented"); in gen_linktype()
3644 bpf_error(cstate, "SITA link-layer type filtering not implemented"); in gen_linktype()
3647 bpf_error(cstate, "RAIF1 link-layer type filtering not implemented"); in gen_linktype()
3651 bpf_error(cstate, "IPMB link-layer type filtering not implemented"); in gen_linktype()
3654 bpf_error(cstate, "AX.25 link-layer type filtering not implemented"); in gen_linktype()
3657 /* Using the fixed-size NFLOG header it is possible to tell only in gen_linktype()
3661 bpf_error(cstate, "NFLOG link-layer type filtering not implemented"); in gen_linktype()
3665 * Does this link-layer header type have a field in gen_linktype()
3670 if (cstate->off_linktype.constant_part != OFFSET_NOT_SET) { in gen_linktype()
3682 description = pcap_datalink_val_to_description_or_dlt(cstate->linktype); in gen_linktype()
3683 bpf_error(cstate, "%s link-layer type filtering not implemented", in gen_linktype()
3721 switch (cstate->linktype) { in gen_llc_internal()
3733 * 0xFF, to rule out NetWare-over-802.3. in gen_llc_internal()
3747 case DLT_IEEE802: /* Token Ring */ in gen_llc_internal()
3749 * XXX - check for LLC frames. in gen_llc_internal()
3755 * XXX - check for LLC frames. in gen_llc_internal()
3783 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_llc_internal()
3795 if (setjmp(cstate->top_ctx)) in gen_llc()
3811 if (setjmp(cstate->top_ctx)) in gen_llc_i()
3820 * Load the control byte and test the low-order bit; it must in gen_llc_i()
3825 b1->s.k = 0x01; in gen_llc_i()
3826 b1->stmts = s; in gen_llc_i()
3841 if (setjmp(cstate->top_ctx)) in gen_llc_s()
3850 * Now compare the low-order 2 bit of the control byte against in gen_llc_s()
3867 if (setjmp(cstate->top_ctx)) in gen_llc_u()
3876 * Now compare the low-order 2 bit of the control byte against in gen_llc_u()
3893 if (setjmp(cstate->top_ctx)) in gen_llc_s_subtype()
3918 if (setjmp(cstate->top_ctx)) in gen_llc_u_subtype()
3935 * Generate code to match a particular packet type, for link-layer types
3939 * for that - it handles the D/I/X Ethernet vs. 802.3+802.2 issues.
3950 * XXX - handle token-ring variable-length header. in gen_llc_linktype()
3958 * XXX - should we check both the DSAP and the in gen_llc_linktype()
3967 * XXX - are there ever SNAP frames for IPX on in gen_llc_linktype()
3968 * non-Ethernet 802.x networks? in gen_llc_linktype()
3974 * 802.2-encapsulated ETHERTYPE_ATALK packets are in gen_llc_linktype()
3979 * XXX - check for an organization code of in gen_llc_linktype()
3986 * XXX - we don't have to check for IPX 802.3 in gen_llc_linktype()
4004 * XXX - if we were to check for the SNAP DSAP and in gen_llc_linktype()
4093 * Code below needs to access four separate 32-bit parts of the 128-bit in gen_hostop6()
4095 * s6_addr32 pseudo-member of struct in6_addr, which contains a union of in gen_hostop6()
4096 * 8-, 16- and 32-bit arrays. In other OSes this is not the case, as in gen_hostop6()
4233 return gen_bcmp(cstate, OR_LINKHDR, 6 + 1 + cstate->pcap_fddipad, 6, eaddr); in gen_fhostop()
4236 return gen_bcmp(cstate, OR_LINKHDR, 0 + 1 + cstate->pcap_fddipad, 6, eaddr); in gen_fhostop()
4280 * Like gen_ehostop, but for DLT_IEEE802 (Token Ring)
4352 cstate->no_optimize = 1; in gen_wlanhostop()
4384 b1->s.k = 0x01; /* To DS */ in gen_wlanhostop()
4385 b1->stmts = s; in gen_wlanhostop()
4399 b2->s.k = 0x01; /* To DS */ in gen_wlanhostop()
4400 b2->stmts = s; in gen_wlanhostop()
4418 * the ORed-together checks. in gen_wlanhostop()
4422 b1->s.k = 0x02; /* From DS */ in gen_wlanhostop()
4423 b1->stmts = s; in gen_wlanhostop()
4431 b2->s.k = 0x02; /* From DS */ in gen_wlanhostop()
4432 b2->stmts = s; in gen_wlanhostop()
4454 b1->s.k = 0x08; in gen_wlanhostop()
4455 b1->stmts = s; in gen_wlanhostop()
4463 * If the high-order bit of the type value is 0, this in gen_wlanhostop()
4469 b2->s.k = 0x08; in gen_wlanhostop()
4470 b2->stmts = s; in gen_wlanhostop()
4487 * If the low-order bit of the type value is 1, in gen_wlanhostop()
4496 b1->s.k = 0x04; in gen_wlanhostop()
4497 b1->stmts = s; in gen_wlanhostop()
4531 b1->s.k = 0x01; /* To DS */ in gen_wlanhostop()
4532 b1->stmts = s; in gen_wlanhostop()
4546 b2->s.k = 0x01; /* To DS */ in gen_wlanhostop()
4547 b2->stmts = s; in gen_wlanhostop()
4568 b1->s.k = 0x08; in gen_wlanhostop()
4569 b1->stmts = s; in gen_wlanhostop()
4577 * If the high-order bit of the type value is 0, this in gen_wlanhostop()
4583 b2->s.k = 0x08; in gen_wlanhostop()
4584 b2->stmts = s; in gen_wlanhostop()
4601 * If the low-order bit of the type value is 1, in gen_wlanhostop()
4610 b1->s.k = 0x04; in gen_wlanhostop()
4611 b1->stmts = s; in gen_wlanhostop()
4635 * XXX - add BSSID keyword? in gen_wlanhostop()
4690 * If the high-order bit of the type value is 0, this in gen_wlanhostop()
4696 b1->s.k = 0x08; in gen_wlanhostop()
4697 b1->stmts = s; in gen_wlanhostop()
4732 * If the high-order bit of the type value is 0, this in gen_wlanhostop()
4738 b1->s.k = 0x08; in gen_wlanhostop()
4739 b1->stmts = s; in gen_wlanhostop()
4759 * Like gen_ehostop, but for RFC 2625 IP-over-Fibre-Channel.
4760 * (We assume that the addresses are IEEE 48-bit MAC addresses,
4925 /* Combine with test for cstate->linktype */ in gen_dnhostop()
4931 * Generate a check for IPv4 or IPv6 for MPLS-encapsulated packets;
4932 * test the bottom-of-stack bit, and then check the version number
4943 /* match the bottom-of-stack bit */ in gen_mpls_linktype()
4944 b0 = gen_mcmp(cstate, OR_LINKPL, (u_int)-2, BPF_B, 0x01, 0x01); in gen_mpls_linktype()
4951 /* match the bottom-of-stack bit */ in gen_mpls_linktype()
4952 b0 = gen_mcmp(cstate, OR_LINKPL, (u_int)-2, BPF_B, 0x01, 0x01); in gen_mpls_linktype()
4982 * Only check for non-IPv4 addresses if we're not in gen_host()
4983 * checking MPLS-encapsulated packets. in gen_host()
4985 if (cstate->label_stack_depth == 0) { in gen_host()
4994 bpf_error(cstate, "link-layer modifier applied to %s", typestr); in gen_host()
5134 bpf_error(cstate, "link-layer modifier applied to ip6 %s", typestr); in gen_host6()
5274 switch (cstate->linktype) { in gen_gateway()
5298 * This is LLC-multiplexed traffic; if it were in gen_gateway()
5299 * LANE, cstate->linktype would have been set to in gen_gateway()
5303 "'gateway' supported only on ethernet/FDDI/token ring/802.11/ATM LANE/Fibre Channel"); in gen_gateway()
5309 "'gateway' supported only on ethernet/FDDI/token ring/802.11/ATM LANE/Fibre Channel"); in gen_gateway()
5312 for (ai = alist; ai != NULL; ai = ai->ai_next) { in gen_gateway()
5316 if (ai->ai_addr != NULL) { in gen_gateway()
5320 if (ai->ai_addr->sa_family == AF_INET) { in gen_gateway()
5324 sin = (struct sockaddr_in *)ai->ai_addr; in gen_gateway()
5326 ntohl(sin->sin_addr.s_addr), in gen_gateway()
5506 case Q_ISIS_L1: /* all IS-IS Level1 PDU-Types */ in gen_proto_abbrev_internal()
5508 b1 = gen_proto(cstate, ISIS_PTP_IIH, Q_ISIS, Q_DEFAULT); /* FIXME extract the circuit-type bits */ in gen_proto_abbrev_internal()
5518 case Q_ISIS_L2: /* all IS-IS Level2 PDU-Types */ in gen_proto_abbrev_internal()
5520 b1 = gen_proto(cstate, ISIS_PTP_IIH, Q_ISIS, Q_DEFAULT); /* FIXME extract the circuit-type bits */ in gen_proto_abbrev_internal()
5530 case Q_ISIS_IIH: /* all IS-IS Hello PDU-Types */ in gen_proto_abbrev_internal()
5598 if (setjmp(cstate->top_ctx)) in gen_proto_abbrev()
5613 b->s.k = 0x1fff; in gen_ipfrag()
5614 b->stmts = s; in gen_ipfrag()
5621 * Generate a comparison to a port value in the transport-layer header
5624 * XXX - this handles a variable-length prefix preceding the link-layer
5626 * variable-length link-layer headers (such as Token Ring or 802.11
5717 * For IEEE 802 networks - which includes 802.5 token ring in gen_port()
5718 * (which is what DLT_IEEE802 means) and 802.11 - RFC 1042 in gen_port()
5722 * For LLC-encapsulated ATM/"Classical IP", RFC 1483 and in gen_port()
5758 /* XXX - catch the first fragment of a fragmented packet? */ in gen_portop6()
5977 /* XXX - catch the first fragment of a fragmented packet? */ in gen_portrangeop6()
6058 /* XXX should look up h/w protocol type based on cstate->linktype */ in lookup_proto()
6114 * We don't handle variable-length prefixes before the link-layer in gen_protochain()
6115 * header, or variable-length link-layer headers, here yet. in gen_protochain()
6124 if (cstate->off_linkpl.is_variable) in gen_protochain()
6138 cstate->no_optimize = 1; in gen_protochain()
6153 /* A = ip->ip_p */ in gen_protochain()
6155 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 9; in gen_protochain()
6157 /* X = ip->ip_hl << 2 */ in gen_protochain()
6159 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_protochain()
6166 /* A = ip6->ip_nxt */ in gen_protochain()
6168 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 6; in gen_protochain()
6172 s[i]->s.k = 40; in gen_protochain()
6184 s[i]->s.k = v; in gen_protochain()
6185 s[i]->s.jt = NULL; /*later*/ in gen_protochain()
6186 s[i]->s.jf = NULL; /*update in next stmt*/ in gen_protochain()
6195 s[i]->s.jt = NULL; /*later*/ in gen_protochain()
6196 s[i]->s.jf = NULL; /*update in next stmt*/ in gen_protochain()
6197 s[i]->s.k = IPPROTO_NONE; in gen_protochain()
6198 s[fix5]->s.jf = s[i]; in gen_protochain()
6208 s[i]->s.jt = NULL; /*later*/ in gen_protochain()
6209 s[i]->s.jf = NULL; /*update in next stmt*/ in gen_protochain()
6210 s[i]->s.k = IPPROTO_HOPOPTS; in gen_protochain()
6211 s[fix2]->s.jf = s[i]; in gen_protochain()
6214 s[i - 1]->s.jf = s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
6215 s[i]->s.jt = NULL; /*later*/ in gen_protochain()
6216 s[i]->s.jf = NULL; /*update in next stmt*/ in gen_protochain()
6217 s[i]->s.k = IPPROTO_DSTOPTS; in gen_protochain()
6220 s[i - 1]->s.jf = s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
6221 s[i]->s.jt = NULL; /*later*/ in gen_protochain()
6222 s[i]->s.jf = NULL; /*update in next stmt*/ in gen_protochain()
6223 s[i]->s.k = IPPROTO_ROUTING; in gen_protochain()
6226 s[i - 1]->s.jf = s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
6227 s[i]->s.jt = NULL; /*later*/ in gen_protochain()
6228 s[i]->s.jf = NULL; /*later*/ in gen_protochain()
6229 s[i]->s.k = IPPROTO_FRAGMENT; in gen_protochain()
6244 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_protochain()
6248 s[i]->s.k = reg2; in gen_protochain()
6252 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 1; in gen_protochain()
6256 s[i]->s.k = 1; in gen_protochain()
6260 s[i]->s.k = 8; in gen_protochain()
6264 s[i]->s.k = 0; in gen_protochain()
6271 s[i]->s.k = reg2; in gen_protochain()
6276 s[i]->s.k = again - i - 1; in gen_protochain()
6277 s[i - 1]->s.jf = s[i]; in gen_protochain()
6282 s[j]->s.jt = s[v6advance]; in gen_protochain()
6286 s[i]->s.k = 0; in gen_protochain()
6287 s[fix2]->s.jf = s[i]; in gen_protochain()
6295 s[i]->s.jt = NULL; /*later*/ in gen_protochain()
6296 s[i]->s.jf = NULL; /*later*/ in gen_protochain()
6297 s[i]->s.k = IPPROTO_AH; in gen_protochain()
6299 s[fix3]->s.jf = s[ahcheck]; in gen_protochain()
6309 s[i - 1]->s.jt = s[i] = new_stmt(cstate, BPF_MISC|BPF_TXA); in gen_protochain()
6313 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_protochain()
6317 s[i]->s.k = reg2; in gen_protochain()
6320 s[i - 1]->s.jt = s[i] = new_stmt(cstate, BPF_MISC|BPF_TXA); in gen_protochain()
6324 s[i]->s.k = 1; in gen_protochain()
6331 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_protochain()
6335 s[i]->s.k = 2; in gen_protochain()
6339 s[i]->s.k = 4; in gen_protochain()
6346 s[i]->s.k = reg2; in gen_protochain()
6351 s[i]->s.k = again - i - 1; in gen_protochain()
6357 s[i]->s.k = 0; in gen_protochain()
6358 s[fix2]->s.jt = s[end]; in gen_protochain()
6359 s[fix4]->s.jf = s[end]; in gen_protochain()
6360 s[fix5]->s.jt = s[end]; in gen_protochain()
6367 for (i = 0; i < max - 1; i++) in gen_protochain()
6368 s[i]->next = s[i + 1]; in gen_protochain()
6369 s[max - 1]->next = NULL; in gen_protochain()
6375 b->stmts = s[1]; /*remember, s[0] is dummy*/ in gen_protochain()
6376 b->s.k = v; in gen_protochain()
6397 b0->s.k = 0x08; in gen_check_802_11_data_frame()
6398 b0->stmts = s; in gen_check_802_11_data_frame()
6402 b1->s.k = 0x04; in gen_check_802_11_data_frame()
6403 b1->stmts = s; in gen_check_802_11_data_frame()
6444 * For IEEE 802 networks - which includes 802.5 token ring in gen_proto()
6445 * (which is what DLT_IEEE802 means) and 802.11 - RFC 1042 in gen_proto()
6449 * For LLC-encapsulated ATM/"Classical IP", RFC 1483 and in gen_proto()
6555 switch (cstate->linktype) { in gen_proto()
6571 * XXX - assumes a 2-byte Frame Relay header with in gen_proto()
6574 * XXX - what about SNAP-encapsulated frames? in gen_proto()
6582 * Cisco uses an Ethertype lookalike - for OSI, in gen_proto()
6586 /* OSI in C-HDLC is stuffed with a fudge byte */ in gen_proto()
6605 * 4 is the offset of the PDU type relative to the IS-IS in gen_proto()
6672 * Convert a non-numeric name to a port number.
6683 int port = -1; in nametoport()
6700 * No such port. Just return -1. in nametoport()
6708 * guaranteed to be thread-safe on all platforms in nametoport()
6709 * (probably because it might use a non-thread-local in nametoport()
6717 port = -2; /* a real error */ in nametoport()
6727 * guaranteed to be thread-safe on all platforms in nametoport()
6728 * (probably because it might use a non-thread-local in nametoport()
6736 port = -2; /* a real error */ in nametoport()
6743 for (ai = res; ai != NULL; ai = ai->ai_next) { in nametoport()
6747 if (ai->ai_addr != NULL) { in nametoport()
6751 if (ai->ai_addr->sa_family == AF_INET) { in nametoport()
6752 in4 = (struct sockaddr_in *)ai->ai_addr; in nametoport()
6753 port = ntohs(in4->sin_port); in nametoport()
6757 if (ai->ai_addr->sa_family == AF_INET6) { in nametoport()
6758 in6 = (struct sockaddr_in6 *)ai->ai_addr; in nametoport()
6759 port = ntohs(in6->sin6_port); in nametoport()
6780 int tcp_port = -1; in stringtoport()
6781 int udp_port = -1; in stringtoport()
6790 /* Unknown port type - it's just a number. */ in stringtoport()
6804 if (tcp_port == -2) { in stringtoport()
6810 longjmp(cstate->top_ctx, 1); in stringtoport()
6814 if (udp_port == -2) { in stringtoport()
6820 longjmp(cstate->top_ctx, 1); in stringtoport()
6864 longjmp(cstate->top_ctx, 1); in stringtoport()
6869 longjmp(cstate->top_ctx, 1); in stringtoport()
6874 bpf_set_error(cstate, "stoulen returned %d - this should not happen", ret); in stringtoport()
6875 longjmp(cstate->top_ctx, 1); in stringtoport()
6882 * Convert a string in the form PPP-PPP, which correspond to ports, to
6894 if ((hyphen_off = strchr(string, '-')) == NULL) in stringtoportrange()
6900 * XXX - we support named ports, but there are some port names in stringtoportrange()
6904 if (strchr(hyphen_off + 1, '-') != NULL) in stringtoportrange()
6912 first_size = hyphen_off - string; in stringtoportrange()
6914 /* Range of "-port", which we don't support. */ in stringtoportrange()
6930 /* Range of "port-", which we don't support. */ in stringtoportrange()
6965 if (setjmp(cstate->top_ctx)) in gen_scode()
6985 switch (cstate->linktype) { in gen_scode()
7014 "unknown token ring host '%s'", name); in gen_scode()
7042 …bpf_error(cstate, "only ethernet/FDDI/token ring/802.11/ATM LANE/Fibre Channel supports link-level… in gen_scode()
7066 cstate->ai = res; in gen_scode()
7072 if (cstate->off_linktype.constant_part == OFFSET_NOT_SET && in gen_scode()
7079 for (res = res0; res; res = res->ai_next) { in gen_scode()
7080 switch (res->ai_family) { in gen_scode()
7088 res->ai_addr; in gen_scode()
7089 tmp = gen_host(cstate, ntohl(sin4->sin_addr.s_addr), in gen_scode()
7098 res->ai_addr; in gen_scode()
7099 tmp = gen_host6(cstate, &sin6->sin6_addr, in gen_scode()
7110 cstate->ai = NULL; in gen_scode()
7212 cstate->ai = res; in gen_scode()
7216 cstate->ai = NULL; in gen_scode()
7260 if (setjmp(cstate->top_ctx)) in gen_mcode()
7267 n <<= 32 - nlen; in gen_mcode()
7274 m <<= 32 - mlen; in gen_mcode()
7276 bpf_error(cstate, "non-network bits set in \"%s mask %s\"", in gen_mcode()
7289 m = 0xffffffff << (32 - masklen); in gen_mcode()
7291 bpf_error(cstate, "non-network bits set in \"%s/%d\"", in gen_mcode()
7319 if (setjmp(cstate->top_ctx)) in gen_ncode()
7355 v <<= 32 - vlen; in gen_ncode()
7356 mask <<= 32 - vlen ; in gen_ncode()
7443 if (setjmp(cstate->top_ctx)) in gen_mcode6()
7449 cstate->ai = res; in gen_mcode6()
7450 if (res->ai_next) in gen_mcode6()
7452 addr = &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr; in gen_mcode6()
7460 (0xff << (8 - masklen % 8)) & 0xff; in gen_mcode6()
7467 bpf_error(cstate, "non-network bits set in \"%s/%d\"", s, masklen); in gen_mcode6()
7480 cstate->ai = NULL; in gen_mcode6()
7500 if (setjmp(cstate->top_ctx)) in gen_ecode()
7504 cstate->e = pcap_ether_aton(s); in gen_ecode()
7505 if (cstate->e == NULL) in gen_ecode()
7507 switch (cstate->linktype) { in gen_ecode()
7512 b = gen_ehostop(cstate, cstate->e, (int)q.dir); in gen_ecode()
7517 b = gen_fhostop(cstate, cstate->e, (int)q.dir); in gen_ecode()
7520 b = gen_thostop(cstate, cstate->e, (int)q.dir); in gen_ecode()
7527 b = gen_wlanhostop(cstate, cstate->e, (int)q.dir); in gen_ecode()
7530 b = gen_ipfchostop(cstate, cstate->e, (int)q.dir); in gen_ecode()
7533 free(cstate->e); in gen_ecode()
7534 cstate->e = NULL; in gen_ecode()
7535 …bpf_error(cstate, "ethernet addresses supported only on ethernet/FDDI/token ring/802.11/ATM LANE/F… in gen_ecode()
7538 free(cstate->e); in gen_ecode()
7539 cstate->e = NULL; in gen_ecode()
7542 bpf_error(cstate, "ethernet address used in non-ether expression"); in gen_ecode()
7553 while (s0->next) in sappend()
7554 s0 = s0->next; in sappend()
7555 s0->next = s1; in sappend()
7564 s->s.k = a->regno; in xfer_to_x()
7574 s->s.k = a->regno; in xfer_to_a()
7594 free_reg(cstate, inst->regno); in gen_load_internal()
7623 if (cstate->linktype != DLT_IEEE802_11_RADIO_AVS && in gen_load_internal()
7624 cstate->linktype != DLT_IEEE802_11_RADIO && in gen_load_internal()
7625 cstate->linktype != DLT_PRISM_HEADER) in gen_load_internal()
7639 sappend(inst->s, s); in gen_load_internal()
7645 * the link-layer header. in gen_load_internal()
7647 * XXX - what about ATM LANE? Should the index be in gen_load_internal()
7654 s = gen_abs_offset_varpart(cstate, &cstate->off_linkhdr); in gen_load_internal()
7657 * If "s" is non-null, it has code to arrange that the in gen_load_internal()
7659 * the link-layer header. Add to it the offset computed in gen_load_internal()
7676 * variable-length; that header length is what we put in gen_load_internal()
7680 tmp->s.k = cstate->off_linkhdr.constant_part; in gen_load_internal()
7682 sappend(inst->s, s); in gen_load_internal()
7697 * the network-layer header. in gen_load_internal()
7698 * XXX - are there any cases where we want in gen_load_internal()
7699 * cstate->off_nl_nosnap? in gen_load_internal()
7701 s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl); in gen_load_internal()
7704 * If "s" is non-null, it has code to arrange that the in gen_load_internal()
7706 * of the link-layer payload. Add to it the offset in gen_load_internal()
7722 * layer header from the beginning of the link-layer in gen_load_internal()
7724 * start of the link-layer payload. in gen_load_internal()
7727 tmp->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_load_internal()
7729 sappend(inst->s, s); in gen_load_internal()
7736 if (inst->b) in gen_load_internal()
7737 gen_and(inst->b, b); in gen_load_internal()
7738 inst->b = b; in gen_load_internal()
7752 * the transport-layer header. in gen_load_internal()
7755 * (plus the offset of the link-layer header, if it's in gen_load_internal()
7756 * a variable-length header), in bytes. in gen_load_internal()
7758 * XXX - are there any cases where we want in gen_load_internal()
7759 * cstate->off_nl_nosnap? in gen_load_internal()
7760 * XXX - we should, if we're built with in gen_load_internal()
7768 * part of the offset of the link-layer payload and the in gen_load_internal()
7769 * length of the network-layer header. in gen_load_internal()
7776 * the offset of the link-layer payload and the offset, in gen_load_internal()
7777 * relative to the beginning of the link-layer payload, in gen_load_internal()
7778 * of the network-layer header. in gen_load_internal()
7784 tmp->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_load_internal()
7785 sappend(inst->s, s); in gen_load_internal()
7789 * the protocol in question - which is true only in gen_load_internal()
7794 if (inst->b) in gen_load_internal()
7795 gen_and(inst->b, b); in gen_load_internal()
7797 inst->b = b; in gen_load_internal()
7805 if (inst->b) in gen_load_internal()
7806 gen_and(inst->b, b); in gen_load_internal()
7807 inst->b = b; in gen_load_internal()
7813 if (inst->b) in gen_load_internal()
7814 gen_and(inst->b, b); in gen_load_internal()
7815 inst->b = b; in gen_load_internal()
7817 s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl); in gen_load_internal()
7819 * If "s" is non-null, it has code to arrange that the in gen_load_internal()
7821 * of the link-layer payload. Add to it the offset in gen_load_internal()
7837 * layer header from the beginning of the link-layer in gen_load_internal()
7839 * start of the link-layer payload. in gen_load_internal()
7842 tmp->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 40; in gen_load_internal()
7845 sappend(inst->s, s); in gen_load_internal()
7849 inst->regno = regno; in gen_load_internal()
7851 s->s.k = regno; in gen_load_internal()
7852 sappend(inst->s, s); in gen_load_internal()
7865 if (setjmp(cstate->top_ctx)) in gen_load()
7891 sappend(a1->s, s0); in gen_relation_internal()
7892 sappend(a0->s, a1->s); in gen_relation_internal()
7894 b->stmts = a0->s; in gen_relation_internal()
7896 free_reg(cstate, a0->regno); in gen_relation_internal()
7897 free_reg(cstate, a1->regno); in gen_relation_internal()
7900 if (a0->b) { in gen_relation_internal()
7901 if (a1->b) { in gen_relation_internal()
7902 gen_and(a0->b, tmp = a1->b); in gen_relation_internal()
7905 tmp = a0->b; in gen_relation_internal()
7907 tmp = a1->b; in gen_relation_internal()
7923 if (setjmp(cstate->top_ctx)) in gen_relation()
7940 if (setjmp(cstate->top_ctx)) in gen_loadlen()
7946 s->next = new_stmt(cstate, BPF_ST); in gen_loadlen()
7947 s->next->s.k = regno; in gen_loadlen()
7948 a->s = s; in gen_loadlen()
7949 a->regno = regno; in gen_loadlen()
7966 s->s.k = val; in gen_loadi_internal()
7967 s->next = new_stmt(cstate, BPF_ST); in gen_loadi_internal()
7968 s->next->s.k = reg; in gen_loadi_internal()
7969 a->s = s; in gen_loadi_internal()
7970 a->regno = reg; in gen_loadi_internal()
7982 if (setjmp(cstate->top_ctx)) in gen_loadi()
7990 * a might be clobbered by longjmp - yeah, it might, but *WHO CARES*?
8003 if (setjmp(cstate->top_ctx)) in gen_neg()
8007 sappend(a->s, s); in gen_neg()
8009 s->s.k = 0; in gen_neg()
8010 sappend(a->s, s); in gen_neg()
8012 s->s.k = a->regno; in gen_neg()
8013 sappend(a->s, s); in gen_neg()
8020 * a0 might be clobbered by longjmp - yeah, it might, but *WHO CARES*?
8034 if (setjmp(cstate->top_ctx)) in gen_arth()
8045 if (a1->s->s.code == (BPF_LD|BPF_IMM) && a1->s->s.k == 0) in gen_arth()
8048 if (a1->s->s.code == (BPF_LD|BPF_IMM) && a1->s->s.k == 0) in gen_arth()
8051 if (a1->s->s.code == (BPF_LD|BPF_IMM) && a1->s->s.k > 31) in gen_arth()
8060 sappend(a1->s, s0); in gen_arth()
8061 sappend(a0->s, a1->s); in gen_arth()
8063 free_reg(cstate, a0->regno); in gen_arth()
8064 free_reg(cstate, a1->regno); in gen_arth()
8067 a0->regno = s0->s.k = alloc_reg(cstate); in gen_arth()
8068 sappend(a0->s, s0); in gen_arth()
8079 cstate->curreg = 0; in init_regs()
8080 memset(cstate->regused, 0, sizeof cstate->regused); in init_regs()
8091 while (--n >= 0) { in alloc_reg()
8092 if (cstate->regused[cstate->curreg]) in alloc_reg()
8093 cstate->curreg = (cstate->curreg + 1) % BPF_MEMWORDS; in alloc_reg()
8095 cstate->regused[cstate->curreg] = 1; in alloc_reg()
8096 return cstate->curreg; in alloc_reg()
8110 cstate->regused[n] = 0; in free_reg()
8121 b->stmts = s; in gen_len()
8122 b->s.k = n; in gen_len()
8134 if (setjmp(cstate->top_ctx)) in gen_greater()
8152 if (setjmp(cstate->top_ctx)) in gen_less()
8163 * the beginning of the link-layer header.
8164 * XXX - that means you can't test values in the radiotap header, but
8181 if (setjmp(cstate->top_ctx)) in gen_byteop()
8207 s->s.k = val; in gen_byteop()
8209 b->stmts = s; in gen_byteop()
8228 if (setjmp(cstate->top_ctx)) in gen_broadcast()
8235 switch (cstate->linktype) { in gen_broadcast()
8270 if (cstate->netmask == PCAP_NETMASK_UNKNOWN) in gen_broadcast()
8273 hostmask = ~cstate->netmask; in gen_broadcast()
8281 bpf_error(cstate, "only link-layer/IP broadcast filters supported"); in gen_broadcast()
8286 * Generate code to test the low-order bit of a MAC address (that's
8298 b0->s.k = 1; in gen_mac_multicast()
8299 b0->stmts = s; in gen_mac_multicast()
8313 if (setjmp(cstate->top_ctx)) in gen_multicast()
8320 switch (cstate->linktype) { in gen_multicast()
8338 * XXX - was that referring to bit-order issues? in gen_multicast()
8373 b1->s.k = 0x01; /* To DS */ in gen_multicast()
8374 b1->stmts = s; in gen_multicast()
8388 b2->s.k = 0x01; /* To DS */ in gen_multicast()
8389 b2->stmts = s; in gen_multicast()
8410 b1->s.k = 0x08; in gen_multicast()
8411 b1->stmts = s; in gen_multicast()
8419 * If the high-order bit of the type value is 0, this in gen_multicast()
8425 b2->s.k = 0x08; in gen_multicast()
8426 b2->stmts = s; in gen_multicast()
8443 * If the low-order bit of the type value is 1, in gen_multicast()
8452 b1->s.k = 0x04; in gen_multicast()
8453 b1->stmts = s; in gen_multicast()
8483 …bpf_error(cstate, "link-layer multicast filters supported only on ethernet/FDDI/token ring/ARCNET/… in gen_multicast()
8496 if (setjmp(cstate->top_ctx)) in gen_ifindex()
8502 switch (cstate->linktype) { in gen_ifindex()
8512 * special meta-data in the filter expression; in gen_ifindex()
8515 if (cstate->bpf_pcap->rfile != NULL) { in gen_ifindex()
8518 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_ifindex()
8526 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_ifindex()
8537 * unicast or multicast link-layer address we are not subscribing to).
8540 * better accomplished using a higher-layer filter.
8551 if (setjmp(cstate->top_ctx)) in gen_inbound()
8557 switch (cstate->linktype) { in gen_inbound()
8579 /* to filter on inbound traffic, invert the match */ in gen_inbound()
8588 /* to filter on inbound traffic, invert the match */ in gen_inbound()
8632 * the byte after the 3-byte magic number */ in gen_inbound()
8644 * If we have packet meta-data indicating a direction, in gen_inbound()
8646 * it. Otherwise, give up, as this link-layer type has in gen_inbound()
8650 * check that metadata is Linux with the in-kernel in gen_inbound()
8662 * special meta-data in the filter expression; in gen_inbound()
8665 if (cstate->bpf_pcap->rfile != NULL) { in gen_inbound()
8668 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_inbound()
8675 /* to filter on inbound traffic, invert the match */ in gen_inbound()
8680 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_inbound()
8698 if (setjmp(cstate->top_ctx)) in gen_pf_ifname()
8701 if (cstate->linktype != DLT_PFLOG) { in gen_pf_ifname()
8705 len = sizeof(((struct pfloghdr *)0)->ifname); in gen_pf_ifname()
8709 len-1); in gen_pf_ifname()
8727 if (setjmp(cstate->top_ctx)) in gen_pf_ruleset()
8730 if (cstate->linktype != DLT_PFLOG) { in gen_pf_ruleset()
8735 if (strlen(ruleset) >= sizeof(((struct pfloghdr *)0)->ruleset)) { in gen_pf_ruleset()
8737 (long)(sizeof(((struct pfloghdr *)0)->ruleset) - 1)); in gen_pf_ruleset()
8756 if (setjmp(cstate->top_ctx)) in gen_pf_rnr()
8759 if (cstate->linktype != DLT_PFLOG) { in gen_pf_rnr()
8769 /* PF firewall log sub-rule number */
8779 if (setjmp(cstate->top_ctx)) in gen_pf_srnr()
8782 if (cstate->linktype != DLT_PFLOG) { in gen_pf_srnr()
8802 if (setjmp(cstate->top_ctx)) in gen_pf_reason()
8805 if (cstate->linktype != DLT_PFLOG) { in gen_pf_reason()
8825 if (setjmp(cstate->top_ctx)) in gen_pf_action()
8828 if (cstate->linktype != DLT_PFLOG) { in gen_pf_action()
8848 if (setjmp(cstate->top_ctx)) in gen_p80211_type()
8851 switch (cstate->linktype) { in gen_p80211_type()
8861 bpf_error(cstate, "802.11 link-layer types supported only on 802.11"); in gen_p80211_type()
8877 if (setjmp(cstate->top_ctx)) in gen_p80211_fcdir()
8880 switch (cstate->linktype) { in gen_p80211_fcdir()
8908 if (setjmp(cstate->top_ctx)) in gen_acode()
8911 switch (cstate->linktype) { in gen_acode()
8917 cstate->e = pcap_ether_aton(s); in gen_acode()
8918 if (cstate->e == NULL) in gen_acode()
8920 b = gen_ahostop(cstate, cstate->e, (int)q.dir); in gen_acode()
8921 free(cstate->e); in gen_acode()
8922 cstate->e = NULL; in gen_acode()
8925 bpf_error(cstate, "ARCnet address used in non-arc expression"); in gen_acode()
9032 cstate->off_linkpl.constant_part += 4; in gen_vlan_no_bpf_extensions()
9033 cstate->off_linktype.constant_part += 4; in gen_vlan_no_bpf_extensions()
9046 if (!off->is_variable) in gen_vlan_vloffset_add()
9047 off->is_variable = 1; in gen_vlan_vloffset_add()
9048 if (off->reg == -1) in gen_vlan_vloffset_add()
9049 off->reg = alloc_reg(cstate); in gen_vlan_vloffset_add()
9052 s2->s.k = off->reg; in gen_vlan_vloffset_add()
9055 s2->s.k = v; in gen_vlan_vloffset_add()
9058 s2->s.k = off->reg; in gen_vlan_vloffset_add()
9073 cstate->is_vlan_vloffset = 1; in gen_vlan_patch_tpid_test()
9074 gen_vlan_vloffset_add(cstate, &cstate->off_linkpl, 4, &s); in gen_vlan_patch_tpid_test()
9075 gen_vlan_vloffset_add(cstate, &cstate->off_linktype, 4, &s); in gen_vlan_patch_tpid_test()
9077 /* we get a pointer to a chain of or-ed blocks, patch first of them */ in gen_vlan_patch_tpid_test()
9078 sappend(s.next, b_tpid->head->stmts); in gen_vlan_patch_tpid_test()
9079 b_tpid->head->stmts = s.next; in gen_vlan_patch_tpid_test()
9093 s->s.k = SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT; in gen_vlan_patch_vid_test()
9095 /* true -> next instructions, false -> beginning of b_vid */ in gen_vlan_patch_vid_test()
9097 sjeq->s.k = 1; in gen_vlan_patch_vid_test()
9098 sjeq->s.jf = b_vid->stmts; in gen_vlan_patch_vid_test()
9102 s2->s.k = SKF_AD_OFF + SKF_AD_VLAN_TAG; in gen_vlan_patch_vid_test()
9104 sjeq->s.jt = s2; in gen_vlan_patch_vid_test()
9111 for (s2 = b_vid->stmts; s2; s2 = s2->next) in gen_vlan_patch_vid_test()
9114 s2->s.k = cnt - 1; in gen_vlan_patch_vid_test()
9118 sappend(s, b_vid->stmts); in gen_vlan_patch_vid_test()
9119 b_vid->stmts = s; in gen_vlan_patch_vid_test()
9140 s->s.k = SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT; in gen_vlan_bpf_extensions()
9143 b0->stmts = s; in gen_vlan_bpf_extensions()
9144 b0->s.k = 1; in gen_vlan_bpf_extensions()
9186 if (setjmp(cstate->top_ctx)) in gen_vlan()
9189 /* can't check for VLAN-encapsulated packets inside MPLS */ in gen_vlan()
9190 if (cstate->label_stack_depth > 0) in gen_vlan()
9200 * XXX - this is a bit of a kludge. If we were to split the in gen_vlan()
9214 * both for VLAN-encapsulated IP and IP-over-Ethernet, rather than in gen_vlan()
9215 * checking only for VLAN-encapsulated IP, so that could still in gen_vlan()
9224 switch (cstate->linktype) { in gen_vlan()
9232 if (cstate->vlan_stack_depth == 0 && !cstate->off_linkhdr.is_variable && in gen_vlan()
9233 cstate->off_linkhdr.constant_part == in gen_vlan()
9234 cstate->off_outermostlinkhdr.constant_part) { in gen_vlan()
9238 if (cstate->bpf_pcap->bpf_codegen_flags & BPF_SPECIAL_VLAN_HANDLING) in gen_vlan()
9259 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_vlan()
9263 cstate->vlan_stack_depth++; in gen_vlan()
9272 * label_num might be clobbered by longjmp - yeah, it might, but *WHO CARES*?
9286 if (setjmp(cstate->top_ctx)) in gen_mpls()
9289 if (cstate->label_stack_depth > 0) { in gen_mpls()
9290 /* just match the bottom-of-stack bit clear */ in gen_mpls()
9294 * We're not in an MPLS stack yet, so check the link-layer in gen_mpls()
9297 switch (cstate->linktype) { in gen_mpls()
9312 * for Frame-Relay/and ATM this may get messy due to SNAP headers in gen_mpls()
9317 pcap_datalink_val_to_description_or_dlt(cstate->linktype)); in gen_mpls()
9343 * we're checking MPLS-encapsulated headers, to make sure higher in gen_mpls()
9344 * level code generators don't try to match against IP-related in gen_mpls()
9347 * XXX - this is a bit of a kludge. See comments in gen_vlan(). in gen_mpls()
9349 cstate->off_nl_nosnap += 4; in gen_mpls()
9350 cstate->off_nl += 4; in gen_mpls()
9351 cstate->label_stack_depth++; in gen_mpls()
9365 if (setjmp(cstate->top_ctx)) in gen_pppoed()
9381 if (setjmp(cstate->top_ctx)) in gen_pppoes()
9385 * Test against the PPPoE session link-layer type. in gen_pppoes()
9405 * XXX - this is a bit of a kludge. See the comments in in gen_pppoes()
9408 * The "network-layer" protocol is PPPoE, which has a 6-byte in gen_pppoes()
9412 * encapsulated in PPPoES instead), so the link-layer type in gen_pppoes()
9415 * link-layer payload, including any 802.2 LLC header, so in gen_pppoes()
9416 * it's 6 bytes past cstate->off_nl. in gen_pppoes()
9418 PUSH_LINKHDR(cstate, DLT_PPP, cstate->off_linkpl.is_variable, in gen_pppoes()
9419 cstate->off_linkpl.constant_part + cstate->off_nl + 6, /* 6 bytes past the PPPoE header */ in gen_pppoes()
9420 cstate->off_linkpl.reg); in gen_pppoes()
9422 cstate->off_linktype = cstate->off_linkhdr; in gen_pppoes()
9423 cstate->off_linkpl.constant_part = cstate->off_linkhdr.constant_part + 2; in gen_pppoes()
9425 cstate->off_nl = 0; in gen_pppoes()
9426 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in gen_pppoes()
9464 * - Verify that this actually is Geneve with the right VNI.
9465 * - Place the IP header length (plus variable link prefix if
9486 b1->stmts = s; in gen_geneve4()
9487 b1->s.k = 0; in gen_geneve4()
9504 s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl); in gen_geneve6()
9507 s1->s.k = 40; in gen_geneve6()
9511 s1->s.k = 0; in gen_geneve6()
9515 s->s.k = 40; in gen_geneve6()
9525 b1->stmts = s; in gen_geneve6()
9526 b1->s.k = 0; in gen_geneve6()
9534 * - The offset of the linktype.
9535 * - The offset of the end of the Geneve header.
9536 * - The offset of the end of the encapsulated MAC header. */
9548 s->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 8; in gen_geneve_offsets()
9557 s1->s.k = 2; in gen_geneve_offsets()
9560 cstate->off_linktype.reg = alloc_reg(cstate); in gen_geneve_offsets()
9561 cstate->off_linktype.is_variable = 1; in gen_geneve_offsets()
9562 cstate->off_linktype.constant_part = 0; in gen_geneve_offsets()
9565 s1->s.k = cstate->off_linktype.reg; in gen_geneve_offsets()
9572 s1->s.k = 0; in gen_geneve_offsets()
9576 s1->s.k = 0x3f; in gen_geneve_offsets()
9580 s1->s.k = 4; in gen_geneve_offsets()
9585 s1->s.k = 8; in gen_geneve_offsets()
9590 s1->s.k = 0; in gen_geneve_offsets()
9596 * - The linktype field is always in EtherType format regardless in gen_geneve_offsets()
9598 * - The only link layer that we have specific support for is in gen_geneve_offsets()
9604 s1->s.k = cstate->off_linkhdr.reg; in gen_geneve_offsets()
9613 cstate->no_optimize = 1; in gen_geneve_offsets()
9617 s1->s.k = 2; in gen_geneve_offsets()
9622 s1->s.k = cstate->off_linkhdr.reg; in gen_geneve_offsets()
9627 * the non-Ethernet case, it's already there. */ in gen_geneve_offsets()
9629 s_proto->s.k = ETHERTYPE_TEB; in gen_geneve_offsets()
9634 s_proto->s.jt = s1; in gen_geneve_offsets()
9639 s1->s.k = 12; in gen_geneve_offsets()
9643 s1->s.k = cstate->off_linktype.reg; in gen_geneve_offsets()
9649 s1->s.k = 2; in gen_geneve_offsets()
9657 cstate->off_linkpl.reg = alloc_reg(cstate); in gen_geneve_offsets()
9658 cstate->off_linkpl.is_variable = 1; in gen_geneve_offsets()
9659 cstate->off_linkpl.constant_part = 0; in gen_geneve_offsets()
9662 s1->s.k = cstate->off_linkpl.reg; in gen_geneve_offsets()
9664 s_proto->s.jf = s1; in gen_geneve_offsets()
9666 cstate->off_nl = 0; in gen_geneve_offsets()
9682 if (setjmp(cstate->top_ctx)) in gen_geneve()
9697 sappend(s, b1->stmts); in gen_geneve()
9698 b1->stmts = s; in gen_geneve()
9702 cstate->is_geneve = 1; in gen_geneve()
9722 s->s.k = cstate->off_linkhdr.reg; in gen_geneve_ll_check()
9725 s1->s.k = cstate->off_linkpl.reg; in gen_geneve_ll_check()
9729 b0->stmts = s; in gen_geneve_ll_check()
9730 b0->s.k = 0; in gen_geneve_ll_check()
9745 if (!cstate->is_atm) in gen_atmfield_code_internal()
9747 if (cstate->off_vpi == OFFSET_NOT_SET) in gen_atmfield_code_internal()
9749 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_vpi, BPF_B, in gen_atmfield_code_internal()
9754 if (!cstate->is_atm) in gen_atmfield_code_internal()
9756 if (cstate->off_vci == OFFSET_NOT_SET) in gen_atmfield_code_internal()
9758 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_vci, BPF_H, in gen_atmfield_code_internal()
9763 if (cstate->off_proto == OFFSET_NOT_SET) in gen_atmfield_code_internal()
9764 abort(); /* XXX - this isn't on FreeBSD */ in gen_atmfield_code_internal()
9765 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_proto, BPF_B, in gen_atmfield_code_internal()
9770 if (cstate->off_payload == OFFSET_NOT_SET) in gen_atmfield_code_internal()
9772 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_payload + MSG_TYPE_POS, BPF_B, in gen_atmfield_code_internal()
9777 if (!cstate->is_atm) in gen_atmfield_code_internal()
9779 if (cstate->off_proto == OFFSET_NOT_SET) in gen_atmfield_code_internal()
9781 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_proto, BPF_B, in gen_atmfield_code_internal()
9819 cstate->linktype = cstate->prevlinktype; in gen_atmtype_llc()
9831 if (setjmp(cstate->top_ctx)) in gen_atmfield_code()
9847 if (setjmp(cstate->top_ctx)) in gen_atmtype_abbrev()
9854 if (!cstate->is_atm) in gen_atmtype_abbrev()
9861 if (!cstate->is_atm) in gen_atmtype_abbrev()
9870 if (!cstate->is_atm) in gen_atmtype_abbrev()
9878 /* Get all cells in End-to-End OAM F4 Circuit*/ in gen_atmtype_abbrev()
9879 if (!cstate->is_atm) in gen_atmtype_abbrev()
9888 if (!cstate->is_atm) in gen_atmtype_abbrev()
9895 if (!cstate->is_atm) in gen_atmtype_abbrev()
9904 if (!cstate->is_atm) in gen_atmtype_abbrev()
9910 * rather than LLC-encapsulated packets, and set in gen_atmtype_abbrev()
9911 * the offsets appropriately for LANE-encapsulated in gen_atmtype_abbrev()
9914 * We assume LANE means Ethernet, not Token Ring. in gen_atmtype_abbrev()
9917 cstate->off_payload + 2, /* Ethernet header */ in gen_atmtype_abbrev()
9918 -1); in gen_atmtype_abbrev()
9919 cstate->off_linktype.constant_part = cstate->off_linkhdr.constant_part + 12; in gen_atmtype_abbrev()
9920 cstate->off_linkpl.constant_part = cstate->off_linkhdr.constant_part + 14; /* Ethernet */ in gen_atmtype_abbrev()
9921 cstate->off_nl = 0; /* Ethernet II */ in gen_atmtype_abbrev()
9922 cstate->off_nl_nosnap = 3; /* 802.3+802.2 */ in gen_atmtype_abbrev()
9926 /* Get all LLC-encapsulated packets */ in gen_atmtype_abbrev()
9927 if (!cstate->is_atm) in gen_atmtype_abbrev()
9954 if (setjmp(cstate->top_ctx)) in gen_mtp2type_abbrev()
9960 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
9961 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
9962 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
9965 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B, in gen_mtp2type_abbrev()
9970 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
9971 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
9972 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
9974 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B, in gen_mtp2type_abbrev()
9976 b1 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B, in gen_mtp2type_abbrev()
9982 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
9983 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
9984 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
9986 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B, in gen_mtp2type_abbrev()
9991 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
9992 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
9993 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
9996 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H, in gen_mtp2type_abbrev()
10001 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
10002 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
10003 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
10005 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H, in gen_mtp2type_abbrev()
10007 b1 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H, in gen_mtp2type_abbrev()
10013 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
10014 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
10015 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
10017 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H, in gen_mtp2type_abbrev()
10029 * jvalue might be clobbered by longjmp - yeah, it might, but *WHO CARES*?
10048 if (setjmp(cstate->top_ctx)) in gen_mtp3field_code()
10051 newoff_sio = cstate->off_sio; in gen_mtp3field_code()
10052 newoff_opc = cstate->off_opc; in gen_mtp3field_code()
10053 newoff_dpc = cstate->off_dpc; in gen_mtp3field_code()
10054 newoff_sls = cstate->off_sls; in gen_mtp3field_code()
10062 if (cstate->off_sio == OFFSET_NOT_SET) in gen_mtp3field_code()
10077 if (cstate->off_opc == OFFSET_NOT_SET) in gen_mtp3field_code()
10101 if (cstate->off_dpc == OFFSET_NOT_SET) in gen_mtp3field_code()
10123 if (cstate->off_sls == OFFSET_NOT_SET) in gen_mtp3field_code()
10192 if (setjmp(cstate->top_ctx)) in gen_atmmulti_abbrev()
10198 if (!cstate->is_atm) in gen_atmmulti_abbrev()
10209 if (!cstate->is_atm) in gen_atmmulti_abbrev()
10224 if (!cstate->is_atm) in gen_atmmulti_abbrev()
10242 if (!cstate->is_atm) in gen_atmmulti_abbrev()