Lines Matching refs:cstate
421 bpf_syntax_error(compiler_state_t *cstate, const char *msg) in bpf_syntax_error() argument
423 bpf_error(cstate, "syntax error in filter expression: %s", msg); in bpf_syntax_error()
429 bpf_error(compiler_state_t *cstate, const char *fmt, ...) in bpf_error() argument
434 if (cstate->bpf_pcap != NULL) in bpf_error()
435 (void)pcap_vsnprintf(pcap_geterr(cstate->bpf_pcap), in bpf_error()
438 longjmp(cstate->top_ctx, 1); in bpf_error()
448 static void initchunks(compiler_state_t *cstate);
449 static void *newchunk(compiler_state_t *cstate, size_t);
450 static void freechunks(compiler_state_t *cstate);
451 static inline struct block *new_block(compiler_state_t *cstate, int);
452 static inline struct slist *new_stmt(compiler_state_t *cstate, int);
453 static struct block *gen_retblk(compiler_state_t *cstate, int);
454 static inline void syntax(compiler_state_t *cstate);
543 static struct block *gen_geneve_ll_check(compiler_state_t *cstate);
549 initchunks(compiler_state_t *cstate) in initchunks() argument
554 cstate->chunks[i].n_left = 0; in initchunks()
555 cstate->chunks[i].m = NULL; in initchunks()
557 cstate->cur_chunk = 0; in initchunks()
561 newchunk(compiler_state_t *cstate, size_t n) in newchunk() argument
575 cp = &cstate->chunks[cstate->cur_chunk]; in newchunk()
578 k = ++cstate->cur_chunk; in newchunk()
580 bpf_error(cstate, "out of memory"); in newchunk()
584 bpf_error(cstate, "out of memory"); in newchunk()
588 bpf_error(cstate, "out of memory"); in newchunk()
595 freechunks(compiler_state_t *cstate) in freechunks() argument
600 if (cstate->chunks[i].m != NULL) in freechunks()
601 free(cstate->chunks[i].m); in freechunks()
608 sdup(compiler_state_t *cstate, const char *s) in sdup() argument
611 char *cp = newchunk(cstate, n); in sdup()
618 new_block(compiler_state_t *cstate, int code) in new_block() argument
622 p = (struct block *)newchunk(cstate, sizeof(*p)); in new_block()
630 new_stmt(compiler_state_t *cstate, int code) in new_stmt() argument
634 p = (struct slist *)newchunk(cstate, sizeof(*p)); in new_stmt()
641 gen_retblk(compiler_state_t *cstate, int v) in gen_retblk() argument
643 struct block *b = new_block(cstate, BPF_RET|BPF_K); in gen_retblk()
650 syntax(compiler_state_t *cstate) in syntax() argument
652 bpf_error(cstate, "syntax error in filter expression"); in syntax()
662 compiler_state_t cstate; in pcap_compile() local
706 initchunks(&cstate); in pcap_compile()
707 cstate.no_optimize = 0; in pcap_compile()
709 cstate.ai = NULL; in pcap_compile()
711 cstate.ic.root = NULL; in pcap_compile()
712 cstate.ic.cur_mark = 0; in pcap_compile()
713 cstate.bpf_pcap = p; in pcap_compile()
714 init_regs(&cstate); in pcap_compile()
716 if (setjmp(cstate.top_ctx)) { in pcap_compile()
718 if (cstate.ai != NULL) in pcap_compile()
719 freeaddrinfo(cstate.ai); in pcap_compile()
725 cstate.netmask = mask; in pcap_compile()
727 cstate.snaplen = pcap_snapshot(p); in pcap_compile()
728 if (cstate.snaplen == 0) { in pcap_compile()
744 pcap_set_extra(&cstate, scanner); in pcap_compile()
746 init_linktype(&cstate, p); in pcap_compile()
747 (void)pcap_parse(scanner, &cstate); in pcap_compile()
749 if (cstate.ic.root == NULL) in pcap_compile()
750 cstate.ic.root = gen_retblk(&cstate, cstate.snaplen); in pcap_compile()
752 if (optimize && !cstate.no_optimize) { in pcap_compile()
753 bpf_optimize(&cstate, &cstate.ic); in pcap_compile()
754 if (cstate.ic.root == NULL || in pcap_compile()
755 (cstate.ic.root->s.code == (BPF_RET|BPF_K) && cstate.ic.root->s.k == 0)) in pcap_compile()
756 bpf_error(&cstate, "expression rejects all packets"); in pcap_compile()
758 program->bf_insns = icode_to_fcode(&cstate, &cstate.ic, cstate.ic.root, &len); in pcap_compile()
775 freechunks(&cstate); in pcap_compile()
855 finish_parse(compiler_state_t *cstate, struct block *p) in finish_parse() argument
878 insert_compute_vloffsets(cstate, p->head); in finish_parse()
893 ppi_dlt_check = gen_ppi_dlt_check(cstate); in finish_parse()
897 backpatch(p, gen_retblk(cstate, cstate->snaplen)); in finish_parse()
899 backpatch(p, gen_retblk(cstate, 0)); in finish_parse()
900 cstate->ic.root = p->head; in finish_parse()
931 gen_cmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_cmp() argument
934 return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JEQ, 0, v); in gen_cmp()
938 gen_cmp_gt(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_cmp_gt() argument
941 return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JGT, 0, v); in gen_cmp_gt()
945 gen_cmp_ge(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_cmp_ge() argument
948 return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JGE, 0, v); in gen_cmp_ge()
952 gen_cmp_lt(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_cmp_lt() argument
955 return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JGE, 1, v); in gen_cmp_lt()
959 gen_cmp_le(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_cmp_le() argument
962 return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JGT, 1, v); in gen_cmp_le()
966 gen_mcmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_mcmp() argument
969 return gen_ncmp(cstate, offrel, offset, size, mask, BPF_JEQ, 0, v); in gen_mcmp()
973 gen_bcmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_bcmp() argument
984 tmp = gen_cmp(cstate, offrel, offset + size - 4, BPF_W, w); in gen_bcmp()
994 tmp = gen_cmp(cstate, offrel, offset + size - 2, BPF_H, w); in gen_bcmp()
1001 tmp = gen_cmp(cstate, offrel, offset, BPF_B, (bpf_int32)v[0]); in gen_bcmp()
1016 gen_ncmp(compiler_state_t *cstate, enum e_offrel offrel, bpf_u_int32 offset, in gen_ncmp() argument
1023 s = gen_load_a(cstate, offrel, offset, size); in gen_ncmp()
1026 s2 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K); in gen_ncmp()
1031 b = new_block(cstate, JMP(jtype)); in gen_ncmp()
1040 init_linktype(compiler_state_t *cstate, pcap_t *p) in init_linktype() argument
1042 cstate->pcap_fddipad = p->fddipad; in init_linktype()
1047 cstate->outermostlinktype = pcap_datalink(p); in init_linktype()
1048 cstate->off_outermostlinkhdr.constant_part = 0; in init_linktype()
1049 cstate->off_outermostlinkhdr.is_variable = 0; in init_linktype()
1050 cstate->off_outermostlinkhdr.reg = -1; in init_linktype()
1052 cstate->prevlinktype = cstate->outermostlinktype; in init_linktype()
1053 cstate->off_prevlinkhdr.constant_part = 0; in init_linktype()
1054 cstate->off_prevlinkhdr.is_variable = 0; in init_linktype()
1055 cstate->off_prevlinkhdr.reg = -1; in init_linktype()
1057 cstate->linktype = cstate->outermostlinktype; in init_linktype()
1058 cstate->off_linkhdr.constant_part = 0; in init_linktype()
1059 cstate->off_linkhdr.is_variable = 0; in init_linktype()
1060 cstate->off_linkhdr.reg = -1; in init_linktype()
1065 cstate->off_linkpl.constant_part = 0; in init_linktype()
1066 cstate->off_linkpl.is_variable = 0; in init_linktype()
1067 cstate->off_linkpl.reg = -1; in init_linktype()
1069 cstate->off_linktype.constant_part = 0; in init_linktype()
1070 cstate->off_linktype.is_variable = 0; in init_linktype()
1071 cstate->off_linktype.reg = -1; in init_linktype()
1076 cstate->is_atm = 0; in init_linktype()
1077 cstate->off_vpi = OFFSET_NOT_SET; in init_linktype()
1078 cstate->off_vci = OFFSET_NOT_SET; in init_linktype()
1079 cstate->off_proto = OFFSET_NOT_SET; in init_linktype()
1080 cstate->off_payload = OFFSET_NOT_SET; in init_linktype()
1085 cstate->is_geneve = 0; in init_linktype()
1090 cstate->is_vlan_vloffset = 0; in init_linktype()
1095 cstate->off_li = OFFSET_NOT_SET; in init_linktype()
1096 cstate->off_li_hsl = OFFSET_NOT_SET; in init_linktype()
1097 cstate->off_sio = OFFSET_NOT_SET; in init_linktype()
1098 cstate->off_opc = OFFSET_NOT_SET; in init_linktype()
1099 cstate->off_dpc = OFFSET_NOT_SET; in init_linktype()
1100 cstate->off_sls = OFFSET_NOT_SET; in init_linktype()
1102 cstate->label_stack_depth = 0; in init_linktype()
1103 cstate->vlan_stack_depth = 0; in init_linktype()
1105 switch (cstate->linktype) { in init_linktype()
1108 cstate->off_linktype.constant_part = 2; in init_linktype()
1109 cstate->off_linkpl.constant_part = 6; in init_linktype()
1110 cstate->off_nl = 0; /* XXX in reality, variable! */ in init_linktype()
1111 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1115 cstate->off_linktype.constant_part = 4; in init_linktype()
1116 cstate->off_linkpl.constant_part = 8; in init_linktype()
1117 cstate->off_nl = 0; /* XXX in reality, variable! */ in init_linktype()
1118 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1122 cstate->off_linktype.constant_part = 12; in init_linktype()
1123 cstate->off_linkpl.constant_part = 14; /* Ethernet header length */ in init_linktype()
1124 cstate->off_nl = 0; /* Ethernet II */ in init_linktype()
1125 cstate->off_nl_nosnap = 3; /* 802.3+802.2 */ in init_linktype()
1133 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1134 cstate->off_linkpl.constant_part = 16; in init_linktype()
1135 cstate->off_nl = 0; in init_linktype()
1136 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1141 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1143 cstate->off_linkpl.constant_part = 24; in init_linktype()
1144 cstate->off_nl = 0; in init_linktype()
1145 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1150 cstate->off_linktype.constant_part = 0; in init_linktype()
1151 cstate->off_linkpl.constant_part = 4; in init_linktype()
1152 cstate->off_nl = 0; in init_linktype()
1153 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1157 cstate->off_linktype.constant_part = 0; in init_linktype()
1158 cstate->off_linkpl.constant_part = 12; in init_linktype()
1159 cstate->off_nl = 0; in init_linktype()
1160 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1167 cstate->off_linktype.constant_part = 2; /* skip HDLC-like framing */ in init_linktype()
1168 cstate->off_linkpl.constant_part = 4; /* skip HDLC-like framing and protocol field */ in init_linktype()
1169 cstate->off_nl = 0; in init_linktype()
1170 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1178 cstate->off_linktype.constant_part = 6; in init_linktype()
1179 cstate->off_linkpl.constant_part = 8; in init_linktype()
1180 cstate->off_nl = 0; in init_linktype()
1181 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1185 cstate->off_linktype.constant_part = 5; in init_linktype()
1186 cstate->off_linkpl.constant_part = 24; in init_linktype()
1187 cstate->off_nl = 0; in init_linktype()
1188 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1200 cstate->off_linktype.constant_part = 13; in init_linktype()
1201 cstate->off_linktype.constant_part += cstate->pcap_fddipad; in init_linktype()
1202 cstate->off_linkpl.constant_part = 13; /* FDDI MAC header length */ in init_linktype()
1203 cstate->off_linkpl.constant_part += cstate->pcap_fddipad; in init_linktype()
1204 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1205 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1232 cstate->off_linktype.constant_part = 14; in init_linktype()
1233 cstate->off_linkpl.constant_part = 14; /* Token Ring MAC header length */ in init_linktype()
1234 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1235 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1241 cstate->off_linkhdr.is_variable = 1; in init_linktype()
1264 cstate->off_linktype.constant_part = 24; in init_linktype()
1265 cstate->off_linkpl.constant_part = 0; /* link-layer header is variable-length */ in init_linktype()
1266 cstate->off_linkpl.is_variable = 1; in init_linktype()
1267 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1268 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1281 cstate->off_linktype.constant_part = 24; in init_linktype()
1282 cstate->off_linkpl.constant_part = 0; /* link-layer header is variable-length */ in init_linktype()
1283 cstate->off_linkpl.is_variable = 1; in init_linktype()
1284 cstate->off_linkhdr.is_variable = 1; in init_linktype()
1285 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1286 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1302 cstate->off_linktype.constant_part = 0; in init_linktype()
1303 cstate->off_linkpl.constant_part = 0; /* packet begins with LLC header */ in init_linktype()
1304 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1305 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1313 cstate->is_atm = 1; in init_linktype()
1314 cstate->off_vpi = SUNATM_VPI_POS; in init_linktype()
1315 cstate->off_vci = SUNATM_VCI_POS; in init_linktype()
1316 cstate->off_proto = PROTO_POS; in init_linktype()
1317 cstate->off_payload = SUNATM_PKT_BEGIN_POS; in init_linktype()
1318 cstate->off_linktype.constant_part = cstate->off_payload; in init_linktype()
1319 cstate->off_linkpl.constant_part = cstate->off_payload; /* if LLC-encapsulated */ in init_linktype()
1320 cstate->off_nl = 8; /* 802.2+SNAP */ in init_linktype()
1321 cstate->off_nl_nosnap = 3; /* 802.2 */ in init_linktype()
1327 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1328 cstate->off_linkpl.constant_part = 0; in init_linktype()
1329 cstate->off_nl = 0; in init_linktype()
1330 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1334 cstate->off_linktype.constant_part = 14; in init_linktype()
1335 cstate->off_linkpl.constant_part = 16; in init_linktype()
1336 cstate->off_nl = 0; in init_linktype()
1337 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1346 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1347 cstate->off_linkpl.constant_part = 0; in init_linktype()
1348 cstate->off_nl = 0; in init_linktype()
1349 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1363 cstate->off_linktype.constant_part = 16; in init_linktype()
1364 cstate->off_linkpl.constant_part = 16; 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()
1374 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1375 cstate->off_linkpl.constant_part = 0; in init_linktype()
1376 cstate->off_nl = 0; in init_linktype()
1377 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1386 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1387 cstate->off_linkpl.constant_part = 0; in init_linktype()
1388 cstate->off_nl = 4; in init_linktype()
1389 cstate->off_nl_nosnap = 0; /* XXX - for now -> no 802.2 LLC */ in init_linktype()
1393 cstate->off_linktype.constant_part = 16; in init_linktype()
1394 cstate->off_linkpl.constant_part = 18; in init_linktype()
1395 cstate->off_nl = 0; in init_linktype()
1396 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1400 cstate->off_linktype.constant_part = 6; in init_linktype()
1401 cstate->off_linkpl.constant_part = 44; in init_linktype()
1402 cstate->off_nl = 0; /* Ethernet II */ in init_linktype()
1403 cstate->off_nl_nosnap = 0; /* XXX - what does it do with 802.3 packets? */ in init_linktype()
1408 cstate->off_linktype.constant_part = 0; in init_linktype()
1409 cstate->off_linkpl.constant_part = PFLOG_HDRLEN; in init_linktype()
1410 cstate->off_nl = 0; in init_linktype()
1411 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in init_linktype()
1421 cstate->off_linktype.constant_part = 4; in init_linktype()
1422 cstate->off_linkpl.constant_part = 4; in init_linktype()
1423 cstate->off_nl = 0; in init_linktype()
1424 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1428 cstate->off_linktype.constant_part = 4; /* in reality variable between 4-8 */ in init_linktype()
1429 cstate->off_linkpl.constant_part = 4; /* in reality variable between 4-8 */ in init_linktype()
1430 cstate->off_nl = 0; in init_linktype()
1431 cstate->off_nl_nosnap = 10; in init_linktype()
1435 cstate->off_linktype.constant_part = 8; /* in reality variable between 8-12 */ in init_linktype()
1436 cstate->off_linkpl.constant_part = 8; /* in reality variable between 8-12 */ in init_linktype()
1437 cstate->off_nl = 0; in init_linktype()
1438 cstate->off_nl_nosnap = 10; in init_linktype()
1445 cstate->off_linkpl.constant_part = 14; in init_linktype()
1446 cstate->off_linktype.constant_part = 16; in init_linktype()
1447 cstate->off_nl = 18; /* Ethernet II */ in init_linktype()
1448 cstate->off_nl_nosnap = 21; /* 802.3+802.2 */ in init_linktype()
1452 cstate->off_linktype.constant_part = 4; in init_linktype()
1453 cstate->off_linkpl.constant_part = 6; in init_linktype()
1454 cstate->off_nl = 0; in init_linktype()
1455 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1459 cstate->off_linktype.constant_part = 6; in init_linktype()
1460 cstate->off_linkpl.constant_part = 12; in init_linktype()
1461 cstate->off_nl = 0; in init_linktype()
1462 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1466 cstate->off_linktype.constant_part = 6; in init_linktype()
1467 …cstate->off_linkpl.constant_part = OFFSET_NOT_SET; /* not really a network layer but raw IP addres… in init_linktype()
1468 cstate->off_nl = OFFSET_NOT_SET; /* not really a network layer but raw IP addresses */ in init_linktype()
1469 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1473 cstate->off_linktype.constant_part = 12; in init_linktype()
1474 cstate->off_linkpl.constant_part = 12; in init_linktype()
1475 cstate->off_nl = 0; /* raw IP/IP6 header */ in init_linktype()
1476 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1480 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1481 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1482 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1483 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1487 cstate->off_linktype.constant_part = 12; in init_linktype()
1488 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; /* L3 proto location dep. on cookie type */ in init_linktype()
1489 cstate->off_nl = OFFSET_NOT_SET; /* L3 proto location dep. on cookie type */ in init_linktype()
1490 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1494 cstate->off_linktype.constant_part = 18; in init_linktype()
1495 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1496 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1497 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1501 cstate->off_linktype.constant_part = 18; in init_linktype()
1502 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1503 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1504 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1508 cstate->off_linktype.constant_part = 8; in init_linktype()
1509 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1510 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1511 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1518 cstate->off_linktype.constant_part = 8; in init_linktype()
1519 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1520 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1521 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1525 cstate->off_li = 2; in init_linktype()
1526 cstate->off_li_hsl = 4; in init_linktype()
1527 cstate->off_sio = 3; in init_linktype()
1528 cstate->off_opc = 4; in init_linktype()
1529 cstate->off_dpc = 4; in init_linktype()
1530 cstate->off_sls = 7; in init_linktype()
1531 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1532 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1533 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1534 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1538 cstate->off_li = 6; in init_linktype()
1539 cstate->off_li_hsl = 8; in init_linktype()
1540 cstate->off_sio = 7; in init_linktype()
1541 cstate->off_opc = 8; in init_linktype()
1542 cstate->off_dpc = 8; in init_linktype()
1543 cstate->off_sls = 11; in init_linktype()
1544 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1545 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1546 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1547 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1551 cstate->off_li = 22; in init_linktype()
1552 cstate->off_li_hsl = 24; in init_linktype()
1553 cstate->off_sio = 23; in init_linktype()
1554 cstate->off_opc = 24; in init_linktype()
1555 cstate->off_dpc = 24; in init_linktype()
1556 cstate->off_sls = 27; in init_linktype()
1557 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1558 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1559 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1560 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1564 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1565 cstate->off_linkpl.constant_part = 4; in init_linktype()
1566 cstate->off_nl = 0; in init_linktype()
1567 cstate->off_nl_nosnap = 0; in init_linktype()
1574 cstate->off_linktype.constant_part = OFFSET_NOT_SET; /* variable, min 15, max 71 steps of 7 */ in init_linktype()
1575 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1576 cstate->off_nl = OFFSET_NOT_SET; /* variable, min 16, max 71 steps of 7 */ in init_linktype()
1577 cstate->off_nl_nosnap = OFFSET_NOT_SET; /* no 802.2 LLC */ in init_linktype()
1581 cstate->off_linktype.constant_part = 1; in init_linktype()
1582 cstate->off_linkpl.constant_part = 24; /* ipnet header length */ in init_linktype()
1583 cstate->off_nl = 0; in init_linktype()
1584 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1588 cstate->off_linkhdr.constant_part = 4; /* Ethernet header is past 4-byte pseudo-header */ in init_linktype()
1589 cstate->off_linktype.constant_part = cstate->off_linkhdr.constant_part + 12; in init_linktype()
1590 …cstate->off_linkpl.constant_part = cstate->off_linkhdr.constant_part + 14; /* pseudo-header+Ethern… in init_linktype()
1591 cstate->off_nl = 0; /* Ethernet II */ in init_linktype()
1592 cstate->off_nl_nosnap = 3; /* 802.3+802.2 */ in init_linktype()
1596 …cstate->off_linkhdr.constant_part = 12; /* MAC header is past 4-byte pseudo-header, preamble, and … in init_linktype()
1597 cstate->off_linktype.constant_part = cstate->off_linkhdr.constant_part + 12; in init_linktype()
1598 …cstate->off_linkpl.constant_part = cstate->off_linkhdr.constant_part + 14; /* pseudo-header+preamb… in init_linktype()
1599 cstate->off_nl = 0; /* Ethernet II */ in init_linktype()
1600 cstate->off_nl_nosnap = 3; /* 802.3+802.2 */ in init_linktype()
1608 if (cstate->linktype >= DLT_MATCHING_MIN && in init_linktype()
1609 cstate->linktype <= DLT_MATCHING_MAX) { in init_linktype()
1610 cstate->off_linktype.constant_part = OFFSET_NOT_SET; in init_linktype()
1611 cstate->off_linkpl.constant_part = OFFSET_NOT_SET; in init_linktype()
1612 cstate->off_nl = OFFSET_NOT_SET; in init_linktype()
1613 cstate->off_nl_nosnap = OFFSET_NOT_SET; in init_linktype()
1615 bpf_error(cstate, "unknown data link type %d", cstate->linktype); in init_linktype()
1620 cstate->off_outermostlinkhdr = cstate->off_prevlinkhdr = cstate->off_linkhdr; in init_linktype()
1627 gen_load_absoffsetrel(compiler_state_t *cstate, bpf_abs_offset *abs_offset, in gen_load_absoffsetrel() argument
1632 s = gen_abs_offset_varpart(cstate, abs_offset); in gen_load_absoffsetrel()
1649 s2 = new_stmt(cstate, BPF_LD|BPF_IND|size); in gen_load_absoffsetrel()
1657 s = new_stmt(cstate, BPF_LD|BPF_ABS|size); in gen_load_absoffsetrel()
1667 gen_load_a(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, in gen_load_a() argument
1675 s = new_stmt(cstate, BPF_LD|BPF_ABS|size); in gen_load_a()
1680 s = gen_load_absoffsetrel(cstate, &cstate->off_linkhdr, offset, size); in gen_load_a()
1684 s = gen_load_absoffsetrel(cstate, &cstate->off_prevlinkhdr, offset, size); in gen_load_a()
1688 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, offset, size); in gen_load_a()
1692 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, cstate->off_nl - 4 + offset, size); in gen_load_a()
1696 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, cstate->off_nl + offset, size); in gen_load_a()
1700 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, cstate->off_nl_nosnap + offset, size); in gen_load_a()
1704 s = gen_load_absoffsetrel(cstate, &cstate->off_linktype, offset, size); in gen_load_a()
1714 s = gen_loadx_iphdrlen(cstate); in gen_load_a()
1727 s2 = new_stmt(cstate, BPF_LD|BPF_IND|size); in gen_load_a()
1728 s2->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + offset; in gen_load_a()
1733 s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, cstate->off_nl + 40 + offset, size); in gen_load_a()
1749 gen_loadx_iphdrlen(compiler_state_t *cstate) in gen_loadx_iphdrlen() argument
1753 s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl); in gen_loadx_iphdrlen()
1765 s2 = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_loadx_iphdrlen()
1766 s2->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_loadx_iphdrlen()
1768 s2 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K); in gen_loadx_iphdrlen()
1771 s2 = new_stmt(cstate, BPF_ALU|BPF_LSH|BPF_K); in gen_loadx_iphdrlen()
1781 sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X)); in gen_loadx_iphdrlen()
1782 sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX)); in gen_loadx_iphdrlen()
1796 s = new_stmt(cstate, BPF_LDX|BPF_MSH|BPF_B); in gen_loadx_iphdrlen()
1797 s->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_loadx_iphdrlen()
1804 gen_uncond(compiler_state_t *cstate, int rsense) in gen_uncond() argument
1809 s = new_stmt(cstate, BPF_LD|BPF_IMM); in gen_uncond()
1811 b = new_block(cstate, JMP(BPF_JEQ)); in gen_uncond()
1818 gen_true(compiler_state_t *cstate) in gen_true() argument
1820 return gen_uncond(cstate, 1); in gen_true()
1824 gen_false(compiler_state_t *cstate) in gen_false() argument
1826 return gen_uncond(cstate, 0); in gen_false()
1847 gen_ether_linktype(compiler_state_t *cstate, int proto) in gen_ether_linktype() argument
1868 b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU); in gen_ether_linktype()
1870 b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, (bpf_int32) in gen_ether_linktype()
1908 b0 = gen_cmp(cstate, OR_LLC, 0, BPF_B, (bpf_int32)LLCSAP_IPX); in gen_ether_linktype()
1909 b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, (bpf_int32)0xFFFF); in gen_ether_linktype()
1916 b0 = gen_snap(cstate, 0x000000, ETHERTYPE_IPX); in gen_ether_linktype()
1923 b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU); in gen_ether_linktype()
1939 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)ETHERTYPE_IPX); in gen_ether_linktype()
1955 b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU); in gen_ether_linktype()
1970 b1 = gen_snap(cstate, 0x080007, ETHERTYPE_ATALK); in gen_ether_linktype()
1972 b1 = gen_snap(cstate, 0x000000, ETHERTYPE_AARP); in gen_ether_linktype()
1980 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)proto); in gen_ether_linktype()
1995 b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU); in gen_ether_linktype()
1997 b1 = gen_cmp(cstate, OR_LINKTYPE, 2, BPF_B, (bpf_int32)proto); in gen_ether_linktype()
2010 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, in gen_ether_linktype()
2017 gen_loopback_linktype(compiler_state_t *cstate, int proto) in gen_loopback_linktype() argument
2032 if (cstate->linktype == DLT_NULL || cstate->linktype == DLT_ENC) { in gen_loopback_linktype()
2044 if (cstate->bpf_pcap->rfile != NULL && cstate->bpf_pcap->swapped) in gen_loopback_linktype()
2048 return (gen_cmp(cstate, OR_LINKHDR, 0, BPF_W, (bpf_int32)proto)); in gen_loopback_linktype()
2056 gen_ipnet_linktype(compiler_state_t *cstate, int proto) in gen_ipnet_linktype() argument
2061 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, (bpf_int32)IPH_AF_INET); in gen_ipnet_linktype()
2065 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_ipnet_linktype()
2073 return gen_false(cstate); in gen_ipnet_linktype()
2085 gen_linux_sll_linktype(compiler_state_t *cstate, int proto) in gen_linux_sll_linktype() argument
2106 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, LINUX_SLL_P_802_2); in gen_linux_sll_linktype()
2107 b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, (bpf_int32) in gen_linux_sll_linktype()
2138 b0 = gen_cmp(cstate, OR_LLC, 0, BPF_B, (bpf_int32)LLCSAP_IPX); in gen_linux_sll_linktype()
2139 b1 = gen_snap(cstate, 0x000000, ETHERTYPE_IPX); in gen_linux_sll_linktype()
2141 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, LINUX_SLL_P_802_2); in gen_linux_sll_linktype()
2148 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, LINUX_SLL_P_802_3); in gen_linux_sll_linktype()
2156 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)ETHERTYPE_IPX); in gen_linux_sll_linktype()
2172 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, LINUX_SLL_P_802_2); in gen_linux_sll_linktype()
2186 b1 = gen_snap(cstate, 0x080007, ETHERTYPE_ATALK); in gen_linux_sll_linktype()
2188 b1 = gen_snap(cstate, 0x000000, ETHERTYPE_AARP); in gen_linux_sll_linktype()
2196 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)proto); in gen_linux_sll_linktype()
2210 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, LINUX_SLL_P_802_2); in gen_linux_sll_linktype()
2211 b1 = gen_cmp(cstate, OR_LINKHDR, cstate->off_linkpl.constant_part, BPF_B, in gen_linux_sll_linktype()
2225 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)proto); in gen_linux_sll_linktype()
2231 gen_load_prism_llprefixlen(compiler_state_t *cstate) in gen_load_prism_llprefixlen() argument
2242 cstate->no_optimize = 1; in gen_load_prism_llprefixlen()
2263 if (cstate->off_linkhdr.reg != -1) { in gen_load_prism_llprefixlen()
2267 s1 = new_stmt(cstate, BPF_LD|BPF_W|BPF_ABS); in gen_load_prism_llprefixlen()
2273 s2 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K); in gen_load_prism_llprefixlen()
2280 sjeq_avs_cookie = new_stmt(cstate, JMP(BPF_JEQ)); in gen_load_prism_llprefixlen()
2291 s2 = new_stmt(cstate, BPF_LD|BPF_W|BPF_ABS); in gen_load_prism_llprefixlen()
2304 sjcommon = new_stmt(cstate, JMP(BPF_JA)); in gen_load_prism_llprefixlen()
2314 s2 = new_stmt(cstate, BPF_LD|BPF_W|BPF_IMM); in gen_load_prism_llprefixlen()
2324 s2 = new_stmt(cstate, BPF_ST); in gen_load_prism_llprefixlen()
2325 s2->s.k = cstate->off_linkhdr.reg; in gen_load_prism_llprefixlen()
2332 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_prism_llprefixlen()
2341 gen_load_avs_llprefixlen(compiler_state_t *cstate) in gen_load_avs_llprefixlen() argument
2352 if (cstate->off_linkhdr.reg != -1) { in gen_load_avs_llprefixlen()
2358 s1 = new_stmt(cstate, BPF_LD|BPF_W|BPF_ABS); in gen_load_avs_llprefixlen()
2365 s2 = new_stmt(cstate, BPF_ST); in gen_load_avs_llprefixlen()
2366 s2->s.k = cstate->off_linkhdr.reg; in gen_load_avs_llprefixlen()
2372 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_avs_llprefixlen()
2381 gen_load_radiotap_llprefixlen(compiler_state_t *cstate) in gen_load_radiotap_llprefixlen() argument
2392 if (cstate->off_linkhdr.reg != -1) { in gen_load_radiotap_llprefixlen()
2404 s1 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_load_radiotap_llprefixlen()
2406 s2 = new_stmt(cstate, BPF_ALU|BPF_LSH|BPF_K); in gen_load_radiotap_llprefixlen()
2409 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_radiotap_llprefixlen()
2416 s2 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_load_radiotap_llprefixlen()
2419 s2 = new_stmt(cstate, BPF_ALU|BPF_OR|BPF_X); in gen_load_radiotap_llprefixlen()
2426 s2 = new_stmt(cstate, BPF_ST); in gen_load_radiotap_llprefixlen()
2427 s2->s.k = cstate->off_linkhdr.reg; in gen_load_radiotap_llprefixlen()
2433 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_radiotap_llprefixlen()
2451 gen_load_ppi_llprefixlen(compiler_state_t *cstate) in gen_load_ppi_llprefixlen() argument
2460 if (cstate->off_linkhdr.reg != -1) { in gen_load_ppi_llprefixlen()
2472 s1 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_load_ppi_llprefixlen()
2474 s2 = new_stmt(cstate, BPF_ALU|BPF_LSH|BPF_K); in gen_load_ppi_llprefixlen()
2477 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_ppi_llprefixlen()
2484 s2 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_load_ppi_llprefixlen()
2487 s2 = new_stmt(cstate, BPF_ALU|BPF_OR|BPF_X); in gen_load_ppi_llprefixlen()
2494 s2 = new_stmt(cstate, BPF_ST); in gen_load_ppi_llprefixlen()
2495 s2->s.k = cstate->off_linkhdr.reg; in gen_load_ppi_llprefixlen()
2501 s2 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_load_ppi_llprefixlen()
2517 gen_load_802_11_header_len(compiler_state_t *cstate, struct slist *s, struct slist *snext) in gen_load_802_11_header_len() argument
2529 if (cstate->off_linkpl.reg == -1) { in gen_load_802_11_header_len()
2544 cstate->no_optimize = 1; in gen_load_802_11_header_len()
2564 s = new_stmt(cstate, BPF_LDX|BPF_IMM); in gen_load_802_11_header_len()
2565 s->s.k = cstate->off_outermostlinkhdr.constant_part; in gen_load_802_11_header_len()
2575 s2 = new_stmt(cstate, BPF_MISC|BPF_TXA); in gen_load_802_11_header_len()
2577 s2 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_load_802_11_header_len()
2580 s2 = new_stmt(cstate, BPF_ST); in gen_load_802_11_header_len()
2581 s2->s.k = cstate->off_linkpl.reg; in gen_load_802_11_header_len()
2584 s2 = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_load_802_11_header_len()
2593 sjset_data_frame_1 = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2601 sjset_data_frame_1->s.jt = sjset_data_frame_2 = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2612 sjset_data_frame_2->s.jf = sjset_qos = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2622 sjset_qos->s.jt = s2 = new_stmt(cstate, BPF_LD|BPF_MEM); in gen_load_802_11_header_len()
2623 s2->s.k = cstate->off_linkpl.reg; in gen_load_802_11_header_len()
2625 s2 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_IMM); in gen_load_802_11_header_len()
2628 s2 = new_stmt(cstate, BPF_ST); in gen_load_802_11_header_len()
2629 s2->s.k = cstate->off_linkpl.reg; in gen_load_802_11_header_len()
2651 if (cstate->linktype == DLT_IEEE802_11_RADIO) { in gen_load_802_11_header_len()
2656 sjset_qos->s.jf = s2 = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_W); in gen_load_802_11_header_len()
2660 sjset_radiotap_flags_present = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2672 sjset_radiotap_ext_present = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2685 sjset_radiotap_tsft_present = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2699 s2 = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_B); in gen_load_802_11_header_len()
2704 sjset_tsft_datapad = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2716 s2 = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_B); in gen_load_802_11_header_len()
2721 sjset_notsft_datapad = new_stmt(cstate, JMP(BPF_JSET)); in gen_load_802_11_header_len()
2732 s_roundup = new_stmt(cstate, BPF_LD|BPF_MEM); in gen_load_802_11_header_len()
2733 s_roundup->s.k = cstate->off_linkpl.reg; in gen_load_802_11_header_len()
2735 s2 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_IMM); in gen_load_802_11_header_len()
2738 s2 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_IMM); in gen_load_802_11_header_len()
2741 s2 = new_stmt(cstate, BPF_ST); in gen_load_802_11_header_len()
2742 s2->s.k = cstate->off_linkpl.reg; in gen_load_802_11_header_len()
2756 insert_compute_vloffsets(compiler_state_t *cstate, struct block *b) in insert_compute_vloffsets() argument
2765 if (cstate->off_linkpl.reg != -1 && cstate->off_linkhdr.is_variable && in insert_compute_vloffsets()
2766 cstate->off_linkhdr.reg == -1) in insert_compute_vloffsets()
2767 cstate->off_linkhdr.reg = alloc_reg(cstate); in insert_compute_vloffsets()
2780 switch (cstate->outermostlinktype) { in insert_compute_vloffsets()
2783 s = gen_load_prism_llprefixlen(cstate); in insert_compute_vloffsets()
2787 s = gen_load_avs_llprefixlen(cstate); in insert_compute_vloffsets()
2791 s = gen_load_radiotap_llprefixlen(cstate); in insert_compute_vloffsets()
2795 s = gen_load_ppi_llprefixlen(cstate); in insert_compute_vloffsets()
2808 switch (cstate->outermostlinktype) { in insert_compute_vloffsets()
2815 s = gen_load_802_11_header_len(cstate, s, b->stmts); in insert_compute_vloffsets()
2823 if (s == NULL && cstate->is_vlan_vloffset) { in insert_compute_vloffsets()
2826 if (cstate->off_linkpl.reg == -1) in insert_compute_vloffsets()
2827 cstate->off_linkpl.reg = alloc_reg(cstate); in insert_compute_vloffsets()
2828 if (cstate->off_linktype.reg == -1) in insert_compute_vloffsets()
2829 cstate->off_linktype.reg = alloc_reg(cstate); in insert_compute_vloffsets()
2831 s = new_stmt(cstate, BPF_LD|BPF_W|BPF_IMM); in insert_compute_vloffsets()
2833 s2 = new_stmt(cstate, BPF_ST); in insert_compute_vloffsets()
2834 s2->s.k = cstate->off_linkpl.reg; in insert_compute_vloffsets()
2836 s2 = new_stmt(cstate, BPF_ST); in insert_compute_vloffsets()
2837 s2->s.k = cstate->off_linktype.reg; in insert_compute_vloffsets()
2854 gen_ppi_dlt_check(compiler_state_t *cstate) in gen_ppi_dlt_check() argument
2859 if (cstate->linktype == DLT_PPI) in gen_ppi_dlt_check()
2863 s_load_dlt = new_stmt(cstate, BPF_LD|BPF_W|BPF_ABS); in gen_ppi_dlt_check()
2866 b = new_block(cstate, JMP(BPF_JEQ)); in gen_ppi_dlt_check()
2893 gen_abs_offset_varpart(compiler_state_t *cstate, bpf_abs_offset *off) in gen_abs_offset_varpart() argument
2904 off->reg = alloc_reg(cstate); in gen_abs_offset_varpart()
2911 s = new_stmt(cstate, BPF_LDX|BPF_MEM); in gen_abs_offset_varpart()
2978 gen_prevlinkhdr_check(compiler_state_t *cstate) in gen_prevlinkhdr_check() argument
2982 if (cstate->is_geneve) in gen_prevlinkhdr_check()
2983 return gen_geneve_ll_check(cstate); in gen_prevlinkhdr_check()
2985 switch (cstate->prevlinktype) { in gen_prevlinkhdr_check()
2995 b0 = gen_cmp(cstate, OR_PREVLINKHDR, SUNATM_PKT_BEGIN_POS, BPF_H, 0xFF00); in gen_prevlinkhdr_check()
3024 gen_linktype(compiler_state_t *cstate, int proto) in gen_linktype() argument
3030 if (cstate->label_stack_depth > 0) { in gen_linktype()
3035 return gen_mpls_linktype(cstate, Q_IP); in gen_linktype()
3040 return gen_mpls_linktype(cstate, Q_IPV6); in gen_linktype()
3043 bpf_error(cstate, "unsupported protocol over mpls"); in gen_linktype()
3048 switch (cstate->linktype) { in gen_linktype()
3055 if (!cstate->is_geneve) in gen_linktype()
3056 b0 = gen_prevlinkhdr_check(cstate); in gen_linktype()
3060 b1 = gen_ether_linktype(cstate, proto); in gen_linktype()
3075 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)proto); in gen_linktype()
3089 b0 = gen_check_802_11_data_frame(cstate); in gen_linktype()
3094 b1 = gen_llc_linktype(cstate, proto); in gen_linktype()
3104 return gen_llc_linktype(cstate, proto); in gen_linktype()
3112 return gen_llc_linktype(cstate, proto); in gen_linktype()
3119 return gen_llc_linktype(cstate, proto); in gen_linktype()
3131 b0 = gen_atmfield_code(cstate, A_PROTOTYPE, PT_LLC, BPF_JEQ, 0); in gen_linktype()
3132 b1 = gen_llc_linktype(cstate, proto); in gen_linktype()
3139 return gen_linux_sll_linktype(cstate, proto); in gen_linktype()
3157 return gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, 0x40, 0xF0); in gen_linktype()
3161 return gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, 0x60, 0xF0); in gen_linktype()
3164 return gen_false(cstate); /* always false */ in gen_linktype()
3174 return gen_true(cstate); /* always true */ in gen_linktype()
3177 return gen_false(cstate); in gen_linktype()
3186 return gen_true(cstate); /* always true */ in gen_linktype()
3189 return gen_false(cstate); in gen_linktype()
3202 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)proto); in gen_linktype()
3218 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, PPP_IP); in gen_linktype()
3219 b1 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, PPP_VJC); in gen_linktype()
3221 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, PPP_VJNC); in gen_linktype()
3227 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, in gen_linktype()
3239 return (gen_loopback_linktype(cstate, AF_INET)); in gen_linktype()
3264 if (cstate->bpf_pcap->rfile != NULL) { in gen_linktype()
3269 b0 = gen_loopback_linktype(cstate, BSD_AFNUM_INET6_BSD); in gen_linktype()
3270 b1 = gen_loopback_linktype(cstate, BSD_AFNUM_INET6_FREEBSD); in gen_linktype()
3272 b0 = gen_loopback_linktype(cstate, BSD_AFNUM_INET6_DARWIN); in gen_linktype()
3288 return (gen_loopback_linktype(cstate, 24)); in gen_linktype()
3291 return (gen_loopback_linktype(cstate, AF_INET6)); in gen_linktype()
3297 return gen_false(cstate); in gen_linktype()
3308 return gen_false(cstate); in gen_linktype()
3318 return (gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, af), in gen_linktype()
3321 return (gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, af), in gen_linktype()
3324 return gen_false(cstate); in gen_linktype()
3338 return gen_false(cstate); in gen_linktype()
3341 return (gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3345 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3347 b1 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3353 b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3355 b1 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3361 return (gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3365 return (gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, in gen_linktype()
3374 return gen_true(cstate); in gen_linktype()
3376 return gen_false(cstate); in gen_linktype()
3392 return gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | 0xcc); in gen_linktype()
3398 return gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | 0x8e); in gen_linktype()
3412 b0 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | ISO8473_CLNP); in gen_linktype()
3413 b1 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | ISO9542_ESIS); in gen_linktype()
3414 b2 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | ISO10589_ISIS); in gen_linktype()
3420 return gen_false(cstate); in gen_linktype()
3426 bpf_error(cstate, "Multi-link Frame Relay link-layer type filtering not implemented"); in gen_linktype()
3458 …return gen_mcmp(cstate, OR_LINKHDR, 0, BPF_W, 0x4d474300, 0xffffff00); /* compare the magic number… in gen_linktype()
3461 return gen_mcmp(cstate, OR_LINKHDR, 0, BPF_W, 0x55FF0000, 0xffff0000); in gen_linktype()
3464 return gen_ipnet_linktype(cstate, proto); in gen_linktype()
3467 bpf_error(cstate, "IrDA link-layer type filtering not implemented"); in gen_linktype()
3470 bpf_error(cstate, "DOCSIS link-layer type filtering not implemented"); in gen_linktype()
3474 bpf_error(cstate, "MTP2 link-layer type filtering not implemented"); in gen_linktype()
3477 bpf_error(cstate, "ERF link-layer type filtering not implemented"); in gen_linktype()
3480 bpf_error(cstate, "PFSYNC link-layer type filtering not implemented"); in gen_linktype()
3483 bpf_error(cstate, "LAPD link-layer type filtering not implemented"); in gen_linktype()
3489 bpf_error(cstate, "USB link-layer type filtering not implemented"); in gen_linktype()
3493 bpf_error(cstate, "Bluetooth link-layer type filtering not implemented"); in gen_linktype()
3497 bpf_error(cstate, "CAN link-layer type filtering not implemented"); in gen_linktype()
3503 bpf_error(cstate, "IEEE 802.15.4 link-layer type filtering not implemented"); in gen_linktype()
3506 bpf_error(cstate, "IEEE 802.16 link-layer type filtering not implemented"); in gen_linktype()
3509 bpf_error(cstate, "SITA link-layer type filtering not implemented"); in gen_linktype()
3512 bpf_error(cstate, "RAIF1 link-layer type filtering not implemented"); in gen_linktype()
3515 bpf_error(cstate, "IPMB link-layer type filtering not implemented"); in gen_linktype()
3518 bpf_error(cstate, "AX.25 link-layer type filtering not implemented"); in gen_linktype()
3525 bpf_error(cstate, "NFLOG link-layer type filtering not implemented"); in gen_linktype()
3534 if (cstate->off_linktype.constant_part != OFFSET_NOT_SET) { in gen_linktype()
3540 return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)proto); in gen_linktype()
3545 description = pcap_datalink_val_to_description(cstate->linktype); in gen_linktype()
3547 bpf_error(cstate, "%s link-layer type filtering not implemented", in gen_linktype()
3550 bpf_error(cstate, "DLT %u link-layer type filtering not implemented", in gen_linktype()
3551 cstate->linktype); in gen_linktype()
3566 gen_snap(compiler_state_t *cstate, bpf_u_int32 orgcode, bpf_u_int32 ptype) in gen_snap() argument
3578 return gen_bcmp(cstate, OR_LLC, 0, 8, snapblock); in gen_snap()
3585 gen_llc(compiler_state_t *cstate) in gen_llc() argument
3589 switch (cstate->linktype) { in gen_llc()
3596 b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU); in gen_llc()
3603 b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, (bpf_int32)0xFFFF); in gen_llc()
3612 b0 = gen_atmtype_abbrev(cstate, A_LLC); in gen_llc()
3619 return gen_true(cstate); in gen_llc()
3625 return gen_true(cstate); in gen_llc()
3636 return gen_true(cstate); in gen_llc()
3646 b0 = gen_check_802_11_data_frame(cstate); in gen_llc()
3650 bpf_error(cstate, "'llc' not supported for linktype %d", cstate->linktype); in gen_llc()
3656 gen_llc_i(compiler_state_t *cstate) in gen_llc_i() argument
3664 b0 = gen_llc(cstate); in gen_llc_i()
3670 s = gen_load_a(cstate, OR_LLC, 2, BPF_B); in gen_llc_i()
3671 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_llc_i()
3680 gen_llc_s(compiler_state_t *cstate) in gen_llc_s() argument
3687 b0 = gen_llc(cstate); in gen_llc_s()
3693 b1 = gen_mcmp(cstate, OR_LLC, 2, BPF_B, LLC_S_FMT, 0x03); in gen_llc_s()
3699 gen_llc_u(compiler_state_t *cstate) in gen_llc_u() argument
3706 b0 = gen_llc(cstate); in gen_llc_u()
3712 b1 = gen_mcmp(cstate, OR_LLC, 2, BPF_B, LLC_U_FMT, 0x03); in gen_llc_u()
3718 gen_llc_s_subtype(compiler_state_t *cstate, bpf_u_int32 subtype) in gen_llc_s_subtype() argument
3725 b0 = gen_llc(cstate); in gen_llc_s_subtype()
3730 b1 = gen_mcmp(cstate, OR_LLC, 2, BPF_B, subtype, LLC_S_CMD_MASK); in gen_llc_s_subtype()
3736 gen_llc_u_subtype(compiler_state_t *cstate, bpf_u_int32 subtype) in gen_llc_u_subtype() argument
3743 b0 = gen_llc(cstate); in gen_llc_u_subtype()
3748 b1 = gen_mcmp(cstate, OR_LLC, 2, BPF_B, subtype, LLC_U_CMD_MASK); in gen_llc_u_subtype()
3766 gen_llc_linktype(compiler_state_t *cstate, int proto) in gen_llc_linktype() argument
3781 return gen_cmp(cstate, OR_LLC, 0, BPF_H, (bpf_u_int32) in gen_llc_linktype()
3789 return gen_cmp(cstate, OR_LLC, 0, BPF_B, in gen_llc_linktype()
3802 return gen_snap(cstate, 0x080007, ETHERTYPE_ATALK); in gen_llc_linktype()
3814 return gen_cmp(cstate, OR_LLC, 0, BPF_B, (bpf_int32)proto); in gen_llc_linktype()
3835 return gen_cmp(cstate, OR_LLC, 6, BPF_H, (bpf_int32)proto); in gen_llc_linktype()
3841 gen_hostop(compiler_state_t *cstate, bpf_u_int32 addr, bpf_u_int32 mask, in gen_hostop() argument
3858 b0 = gen_hostop(cstate, addr, mask, Q_SRC, proto, src_off, dst_off); in gen_hostop()
3859 b1 = gen_hostop(cstate, addr, mask, Q_DST, proto, src_off, dst_off); in gen_hostop()
3865 b0 = gen_hostop(cstate, addr, mask, Q_SRC, proto, src_off, dst_off); in gen_hostop()
3866 b1 = gen_hostop(cstate, addr, mask, Q_DST, proto, src_off, dst_off); in gen_hostop()
3871 …bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for addresses other than 802.11… in gen_hostop()
3875 …bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for addresses other than 802.11… in gen_hostop()
3879 …bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for addresses other than 802.11… in gen_hostop()
3883 …bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for addresses other than 802.11… in gen_hostop()
3887 bpf_error(cstate, "'ra' is not a valid qualifier for addresses other than 802.11 MAC addresses"); in gen_hostop()
3891 bpf_error(cstate, "'ta' is not a valid qualifier for addresses other than 802.11 MAC addresses"); in gen_hostop()
3897 b0 = gen_linktype(cstate, proto); in gen_hostop()
3898 b1 = gen_mcmp(cstate, OR_LINKPL, offset, BPF_W, (bpf_int32)addr, mask); in gen_hostop()
3905 gen_hostop6(compiler_state_t *cstate, struct in6_addr *addr, in gen_hostop6() argument
3923 b0 = gen_hostop6(cstate, addr, mask, Q_SRC, proto, src_off, dst_off); in gen_hostop6()
3924 b1 = gen_hostop6(cstate, addr, mask, Q_DST, proto, src_off, dst_off); in gen_hostop6()
3930 b0 = gen_hostop6(cstate, addr, mask, Q_SRC, proto, src_off, dst_off); in gen_hostop6()
3931 b1 = gen_hostop6(cstate, addr, mask, Q_DST, proto, src_off, dst_off); in gen_hostop6()
3936 …bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for addresses other than 802.11… in gen_hostop6()
3940 …bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for addresses other than 802.11… in gen_hostop6()
3944 …bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for addresses other than 802.11… in gen_hostop6()
3948 …bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for addresses other than 802.11… in gen_hostop6()
3952 bpf_error(cstate, "'ra' is not a valid qualifier for addresses other than 802.11 MAC addresses"); in gen_hostop6()
3956 bpf_error(cstate, "'ta' is not a valid qualifier for addresses other than 802.11 MAC addresses"); in gen_hostop6()
3965 b1 = gen_mcmp(cstate, OR_LINKPL, offset + 12, BPF_W, ntohl(a[3]), ntohl(m[3])); in gen_hostop6()
3966 b0 = gen_mcmp(cstate, OR_LINKPL, offset + 8, BPF_W, ntohl(a[2]), ntohl(m[2])); in gen_hostop6()
3968 b0 = gen_mcmp(cstate, OR_LINKPL, offset + 4, BPF_W, ntohl(a[1]), ntohl(m[1])); in gen_hostop6()
3970 b0 = gen_mcmp(cstate, OR_LINKPL, offset + 0, BPF_W, ntohl(a[0]), ntohl(m[0])); in gen_hostop6()
3972 b0 = gen_linktype(cstate, proto); in gen_hostop6()
3979 gen_ehostop(compiler_state_t *cstate, const u_char *eaddr, int dir) in gen_ehostop() argument
3985 return gen_bcmp(cstate, OR_LINKHDR, 6, 6, eaddr); in gen_ehostop()
3988 return gen_bcmp(cstate, OR_LINKHDR, 0, 6, eaddr); in gen_ehostop()
3991 b0 = gen_ehostop(cstate, eaddr, Q_SRC); in gen_ehostop()
3992 b1 = gen_ehostop(cstate, eaddr, Q_DST); in gen_ehostop()
3998 b0 = gen_ehostop(cstate, eaddr, Q_SRC); in gen_ehostop()
3999 b1 = gen_ehostop(cstate, eaddr, Q_DST); in gen_ehostop()
4004 bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11 with 802.11 headers"); in gen_ehostop()
4008 bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11 with 802.11 headers"); in gen_ehostop()
4012 bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11 with 802.11 headers"); in gen_ehostop()
4016 bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11 with 802.11 headers"); in gen_ehostop()
4020 bpf_error(cstate, "'ra' is only supported on 802.11 with 802.11 headers"); in gen_ehostop()
4024 bpf_error(cstate, "'ta' is only supported on 802.11 with 802.11 headers"); in gen_ehostop()
4035 gen_fhostop(compiler_state_t *cstate, const u_char *eaddr, int dir) in gen_fhostop() argument
4041 return gen_bcmp(cstate, OR_LINKHDR, 6 + 1 + cstate->pcap_fddipad, 6, eaddr); in gen_fhostop()
4044 return gen_bcmp(cstate, OR_LINKHDR, 0 + 1 + cstate->pcap_fddipad, 6, eaddr); in gen_fhostop()
4047 b0 = gen_fhostop(cstate, eaddr, Q_SRC); in gen_fhostop()
4048 b1 = gen_fhostop(cstate, eaddr, Q_DST); in gen_fhostop()
4054 b0 = gen_fhostop(cstate, eaddr, Q_SRC); in gen_fhostop()
4055 b1 = gen_fhostop(cstate, eaddr, Q_DST); in gen_fhostop()
4060 bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11"); in gen_fhostop()
4064 bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11"); in gen_fhostop()
4068 bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11"); in gen_fhostop()
4072 bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11"); in gen_fhostop()
4076 bpf_error(cstate, "'ra' is only supported on 802.11"); in gen_fhostop()
4080 bpf_error(cstate, "'ta' is only supported on 802.11"); in gen_fhostop()
4091 gen_thostop(compiler_state_t *cstate, const u_char *eaddr, int dir) in gen_thostop() argument
4097 return gen_bcmp(cstate, OR_LINKHDR, 8, 6, eaddr); in gen_thostop()
4100 return gen_bcmp(cstate, OR_LINKHDR, 2, 6, eaddr); in gen_thostop()
4103 b0 = gen_thostop(cstate, eaddr, Q_SRC); in gen_thostop()
4104 b1 = gen_thostop(cstate, eaddr, Q_DST); in gen_thostop()
4110 b0 = gen_thostop(cstate, eaddr, Q_SRC); in gen_thostop()
4111 b1 = gen_thostop(cstate, eaddr, Q_DST); in gen_thostop()
4116 bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11"); in gen_thostop()
4120 bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11"); in gen_thostop()
4124 bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11"); in gen_thostop()
4128 bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11"); in gen_thostop()
4132 bpf_error(cstate, "'ra' is only supported on 802.11"); in gen_thostop()
4136 bpf_error(cstate, "'ta' is only supported on 802.11"); in gen_thostop()
4148 gen_wlanhostop(compiler_state_t *cstate, const u_char *eaddr, int dir) in gen_wlanhostop() argument
4160 cstate->no_optimize = 1; in gen_wlanhostop()
4190 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_wlanhostop()
4191 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4198 b0 = gen_bcmp(cstate, OR_LINKHDR, 24, 6, eaddr); in gen_wlanhostop()
4205 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_wlanhostop()
4206 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4214 b1 = gen_bcmp(cstate, OR_LINKHDR, 16, 6, eaddr); in gen_wlanhostop()
4228 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_wlanhostop()
4229 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4237 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_wlanhostop()
4238 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4246 b1 = gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr); in gen_wlanhostop()
4260 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4261 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4275 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4276 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4284 b1 = gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr); in gen_wlanhostop()
4302 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4303 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4337 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_wlanhostop()
4338 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4345 b0 = gen_bcmp(cstate, OR_LINKHDR, 16, 6, eaddr); in gen_wlanhostop()
4352 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_wlanhostop()
4353 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4361 b1 = gen_bcmp(cstate, OR_LINKHDR, 4, 6, eaddr); in gen_wlanhostop()
4374 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4375 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4389 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4390 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4398 b1 = gen_bcmp(cstate, OR_LINKHDR, 4, 6, eaddr); in gen_wlanhostop()
4416 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4417 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4440 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4441 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4448 b0 = gen_bcmp(cstate, OR_LINKHDR, 4, 6, eaddr); in gen_wlanhostop()
4465 b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_TYPE_CTL, in gen_wlanhostop()
4468 b1 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_SUBTYPE_CTS, in gen_wlanhostop()
4471 b2 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_SUBTYPE_ACK, in gen_wlanhostop()
4482 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_wlanhostop()
4483 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_wlanhostop()
4496 b1 = gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr); in gen_wlanhostop()
4504 return (gen_bcmp(cstate, OR_LINKHDR, 4, 6, eaddr)); in gen_wlanhostop()
4510 b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_TYPE_CTL, in gen_wlanhostop()
4513 b1 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_SUBTYPE_CTS, in gen_wlanhostop()
4516 b2 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_SUBTYPE_ACK, in gen_wlanhostop()
4521 b1 = gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr); in gen_wlanhostop()
4529 b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_TYPE_CTL, in gen_wlanhostop()
4532 b1 = gen_bcmp(cstate, OR_LINKHDR, 16, 6, eaddr); in gen_wlanhostop()
4543 b0 = gen_mcmp(cstate, OR_LINKHDR, 1, BPF_B, in gen_wlanhostop()
4545 b1 = gen_bcmp(cstate, OR_LINKHDR, 24, 6, eaddr); in gen_wlanhostop()
4550 b0 = gen_wlanhostop(cstate, eaddr, Q_SRC); in gen_wlanhostop()
4551 b1 = gen_wlanhostop(cstate, eaddr, Q_DST); in gen_wlanhostop()
4557 b0 = gen_wlanhostop(cstate, eaddr, Q_SRC); in gen_wlanhostop()
4558 b1 = gen_wlanhostop(cstate, eaddr, Q_DST); in gen_wlanhostop()
4572 gen_ipfchostop(compiler_state_t *cstate, const u_char *eaddr, int dir) in gen_ipfchostop() argument
4578 return gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr); in gen_ipfchostop()
4581 return gen_bcmp(cstate, OR_LINKHDR, 2, 6, eaddr); in gen_ipfchostop()
4584 b0 = gen_ipfchostop(cstate, eaddr, Q_SRC); in gen_ipfchostop()
4585 b1 = gen_ipfchostop(cstate, eaddr, Q_DST); in gen_ipfchostop()
4591 b0 = gen_ipfchostop(cstate, eaddr, Q_SRC); in gen_ipfchostop()
4592 b1 = gen_ipfchostop(cstate, eaddr, Q_DST); in gen_ipfchostop()
4597 bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11"); in gen_ipfchostop()
4601 bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11"); in gen_ipfchostop()
4605 bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11"); in gen_ipfchostop()
4609 bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11"); in gen_ipfchostop()
4613 bpf_error(cstate, "'ra' is only supported on 802.11"); in gen_ipfchostop()
4617 bpf_error(cstate, "'ta' is only supported on 802.11"); in gen_ipfchostop()
4643 gen_dnhostop(compiler_state_t *cstate, bpf_u_int32 addr, int dir) in gen_dnhostop() argument
4663 b0 = gen_dnhostop(cstate, addr, Q_SRC); in gen_dnhostop()
4664 b1 = gen_dnhostop(cstate, addr, Q_DST); in gen_dnhostop()
4671 b0 = gen_dnhostop(cstate, addr, Q_SRC); in gen_dnhostop()
4672 b1 = gen_dnhostop(cstate, addr, Q_DST); in gen_dnhostop()
4677 bpf_error(cstate, "ISO host filtering not implemented"); in gen_dnhostop()
4682 b0 = gen_linktype(cstate, ETHERTYPE_DN); in gen_dnhostop()
4684 tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_H, in gen_dnhostop()
4686 b1 = gen_cmp(cstate, OR_LINKPL, 2 + 1 + offset_lh, in gen_dnhostop()
4690 tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_B, (bpf_int32)0x06, (bpf_int32)0x7); in gen_dnhostop()
4691 b2 = gen_cmp(cstate, OR_LINKPL, 2 + offset_lh, BPF_H, (bpf_int32)ntohs((u_short)addr)); in gen_dnhostop()
4695 tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_H, in gen_dnhostop()
4697 b2 = gen_cmp(cstate, OR_LINKPL, 2 + 1 + offset_sh, BPF_H, (bpf_int32)ntohs((u_short)addr)); in gen_dnhostop()
4701 tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_B, (bpf_int32)0x02, (bpf_int32)0x7); in gen_dnhostop()
4702 b2 = gen_cmp(cstate, OR_LINKPL, 2 + offset_sh, BPF_H, (bpf_int32)ntohs((u_short)addr)); in gen_dnhostop()
4717 gen_mpls_linktype(compiler_state_t *cstate, int proto) in gen_mpls_linktype() argument
4725 b0 = gen_mcmp(cstate, OR_LINKPL, (u_int)-2, BPF_B, 0x01, 0x01); in gen_mpls_linktype()
4727 b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_B, 0x40, 0xf0); in gen_mpls_linktype()
4733 b0 = gen_mcmp(cstate, OR_LINKPL, (u_int)-2, BPF_B, 0x01, 0x01); in gen_mpls_linktype()
4735 b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_B, 0x60, 0xf0); in gen_mpls_linktype()
4745 gen_host(compiler_state_t *cstate, bpf_u_int32 addr, bpf_u_int32 mask, in gen_host() argument
4759 b0 = gen_host(cstate, addr, mask, Q_IP, dir, type); in gen_host()
4764 if (cstate->label_stack_depth == 0) { in gen_host()
4765 b1 = gen_host(cstate, addr, mask, Q_ARP, dir, type); in gen_host()
4767 b0 = gen_host(cstate, addr, mask, Q_RARP, dir, type); in gen_host()
4773 return gen_hostop(cstate, addr, mask, dir, ETHERTYPE_IP, 12, 16); in gen_host()
4776 return gen_hostop(cstate, addr, mask, dir, ETHERTYPE_REVARP, 14, 24); in gen_host()
4779 return gen_hostop(cstate, addr, mask, dir, ETHERTYPE_ARP, 14, 24); in gen_host()
4782 bpf_error(cstate, "'tcp' modifier applied to %s", typestr); in gen_host()
4785 bpf_error(cstate, "'sctp' modifier applied to %s", typestr); in gen_host()
4788 bpf_error(cstate, "'udp' modifier applied to %s", typestr); in gen_host()
4791 bpf_error(cstate, "'icmp' modifier applied to %s", typestr); in gen_host()
4794 bpf_error(cstate, "'igmp' modifier applied to %s", typestr); in gen_host()
4797 bpf_error(cstate, "'igrp' modifier applied to %s", typestr); in gen_host()
4800 bpf_error(cstate, "'pim' modifier applied to %s", typestr); in gen_host()
4803 bpf_error(cstate, "'vrrp' modifier applied to %s", typestr); in gen_host()
4806 bpf_error(cstate, "'carp' modifier applied to %s", typestr); in gen_host()
4809 bpf_error(cstate, "ATALK host filtering not implemented"); in gen_host()
4812 bpf_error(cstate, "AARP host filtering not implemented"); in gen_host()
4815 return gen_dnhostop(cstate, addr, dir); in gen_host()
4818 bpf_error(cstate, "SCA host filtering not implemented"); in gen_host()
4821 bpf_error(cstate, "LAT host filtering not implemented"); in gen_host()
4824 bpf_error(cstate, "MOPDL host filtering not implemented"); in gen_host()
4827 bpf_error(cstate, "MOPRC host filtering not implemented"); in gen_host()
4830 bpf_error(cstate, "'ip6' modifier applied to ip host"); in gen_host()
4833 bpf_error(cstate, "'icmp6' modifier applied to %s", typestr); in gen_host()
4836 bpf_error(cstate, "'ah' modifier applied to %s", typestr); in gen_host()
4839 bpf_error(cstate, "'esp' modifier applied to %s", typestr); in gen_host()
4842 bpf_error(cstate, "ISO host filtering not implemented"); in gen_host()
4845 bpf_error(cstate, "'esis' modifier applied to %s", typestr); in gen_host()
4848 bpf_error(cstate, "'isis' modifier applied to %s", typestr); in gen_host()
4851 bpf_error(cstate, "'clnp' modifier applied to %s", typestr); in gen_host()
4854 bpf_error(cstate, "'stp' modifier applied to %s", typestr); in gen_host()
4857 bpf_error(cstate, "IPX host filtering not implemented"); in gen_host()
4860 bpf_error(cstate, "'netbeui' modifier applied to %s", typestr); in gen_host()
4863 bpf_error(cstate, "'radio' modifier applied to %s", typestr); in gen_host()
4873 gen_host6(compiler_state_t *cstate, struct in6_addr *addr, in gen_host6() argument
4886 return gen_host6(cstate, addr, mask, Q_IPV6, dir, type); in gen_host6()
4889 bpf_error(cstate, "link-layer modifier applied to ip6 %s", typestr); in gen_host6()
4892 bpf_error(cstate, "'ip' modifier applied to ip6 %s", typestr); in gen_host6()
4895 bpf_error(cstate, "'rarp' modifier applied to ip6 %s", typestr); in gen_host6()
4898 bpf_error(cstate, "'arp' modifier applied to ip6 %s", typestr); in gen_host6()
4901 bpf_error(cstate, "'sctp' modifier applied to %s", typestr); in gen_host6()
4904 bpf_error(cstate, "'tcp' modifier applied to %s", typestr); in gen_host6()
4907 bpf_error(cstate, "'udp' modifier applied to %s", typestr); in gen_host6()
4910 bpf_error(cstate, "'icmp' modifier applied to %s", typestr); in gen_host6()
4913 bpf_error(cstate, "'igmp' modifier applied to %s", typestr); in gen_host6()
4916 bpf_error(cstate, "'igrp' modifier applied to %s", typestr); in gen_host6()
4919 bpf_error(cstate, "'pim' modifier applied to %s", typestr); in gen_host6()
4922 bpf_error(cstate, "'vrrp' modifier applied to %s", typestr); in gen_host6()
4925 bpf_error(cstate, "'carp' modifier applied to %s", typestr); in gen_host6()
4928 bpf_error(cstate, "ATALK host filtering not implemented"); in gen_host6()
4931 bpf_error(cstate, "AARP host filtering not implemented"); in gen_host6()
4934 bpf_error(cstate, "'decnet' modifier applied to ip6 %s", typestr); in gen_host6()
4937 bpf_error(cstate, "SCA host filtering not implemented"); in gen_host6()
4940 bpf_error(cstate, "LAT host filtering not implemented"); in gen_host6()
4943 bpf_error(cstate, "MOPDL host filtering not implemented"); in gen_host6()
4946 bpf_error(cstate, "MOPRC host filtering not implemented"); in gen_host6()
4949 return gen_hostop6(cstate, addr, mask, dir, ETHERTYPE_IPV6, 8, 24); in gen_host6()
4952 bpf_error(cstate, "'icmp6' modifier applied to %s", typestr); in gen_host6()
4955 bpf_error(cstate, "'ah' modifier applied to %s", typestr); in gen_host6()
4958 bpf_error(cstate, "'esp' modifier applied to %s", typestr); in gen_host6()
4961 bpf_error(cstate, "ISO host filtering not implemented"); in gen_host6()
4964 bpf_error(cstate, "'esis' modifier applied to %s", typestr); in gen_host6()
4967 bpf_error(cstate, "'isis' modifier applied to %s", typestr); in gen_host6()
4970 bpf_error(cstate, "'clnp' modifier applied to %s", typestr); in gen_host6()
4973 bpf_error(cstate, "'stp' modifier applied to %s", typestr); in gen_host6()
4976 bpf_error(cstate, "IPX host filtering not implemented"); in gen_host6()
4979 bpf_error(cstate, "'netbeui' modifier applied to %s", typestr); in gen_host6()
4982 bpf_error(cstate, "'radio' modifier applied to %s", typestr); in gen_host6()
4993 gen_gateway(compiler_state_t *cstate, const u_char *eaddr, in gen_gateway() argument
5001 bpf_error(cstate, "direction applied to 'gateway'"); in gen_gateway()
5008 switch (cstate->linktype) { in gen_gateway()
5012 b1 = gen_prevlinkhdr_check(cstate); in gen_gateway()
5013 b0 = gen_ehostop(cstate, eaddr, Q_OR); in gen_gateway()
5018 b0 = gen_fhostop(cstate, eaddr, Q_OR); in gen_gateway()
5021 b0 = gen_thostop(cstate, eaddr, Q_OR); in gen_gateway()
5028 b0 = gen_wlanhostop(cstate, eaddr, Q_OR); in gen_gateway()
5036 bpf_error(cstate, in gen_gateway()
5040 b0 = gen_ipfchostop(cstate, eaddr, Q_OR); in gen_gateway()
5043 bpf_error(cstate, in gen_gateway()
5060 tmp = gen_host(cstate, in gen_gateway()
5093 bpf_error(cstate, "illegal modifier of 'gateway'"); in gen_gateway()
5099 gen_proto_abbrev(compiler_state_t *cstate, int proto) in gen_proto_abbrev() argument
5107 b1 = gen_proto(cstate, IPPROTO_SCTP, Q_IP, Q_DEFAULT); in gen_proto_abbrev()
5108 b0 = gen_proto(cstate, IPPROTO_SCTP, Q_IPV6, Q_DEFAULT); in gen_proto_abbrev()
5113 b1 = gen_proto(cstate, IPPROTO_TCP, Q_IP, Q_DEFAULT); in gen_proto_abbrev()
5114 b0 = gen_proto(cstate, IPPROTO_TCP, Q_IPV6, Q_DEFAULT); in gen_proto_abbrev()
5119 b1 = gen_proto(cstate, IPPROTO_UDP, Q_IP, Q_DEFAULT); in gen_proto_abbrev()
5120 b0 = gen_proto(cstate, IPPROTO_UDP, Q_IPV6, Q_DEFAULT); in gen_proto_abbrev()
5125 b1 = gen_proto(cstate, IPPROTO_ICMP, Q_IP, Q_DEFAULT); in gen_proto_abbrev()
5133 b1 = gen_proto(cstate, IPPROTO_IGMP, Q_IP, Q_DEFAULT); in gen_proto_abbrev()
5140 b1 = gen_proto(cstate, IPPROTO_IGRP, Q_IP, Q_DEFAULT); in gen_proto_abbrev()
5148 b1 = gen_proto(cstate, IPPROTO_PIM, Q_IP, Q_DEFAULT); in gen_proto_abbrev()
5149 b0 = gen_proto(cstate, IPPROTO_PIM, Q_IPV6, Q_DEFAULT); in gen_proto_abbrev()
5158 b1 = gen_proto(cstate, IPPROTO_VRRP, Q_IP, Q_DEFAULT); in gen_proto_abbrev()
5166 b1 = gen_proto(cstate, IPPROTO_CARP, Q_IP, Q_DEFAULT); in gen_proto_abbrev()
5170 b1 = gen_linktype(cstate, ETHERTYPE_IP); in gen_proto_abbrev()
5174 b1 = gen_linktype(cstate, ETHERTYPE_ARP); in gen_proto_abbrev()
5178 b1 = gen_linktype(cstate, ETHERTYPE_REVARP); in gen_proto_abbrev()
5182 bpf_error(cstate, "link layer applied in wrong context"); in gen_proto_abbrev()
5185 b1 = gen_linktype(cstate, ETHERTYPE_ATALK); in gen_proto_abbrev()
5189 b1 = gen_linktype(cstate, ETHERTYPE_AARP); in gen_proto_abbrev()
5193 b1 = gen_linktype(cstate, ETHERTYPE_DN); in gen_proto_abbrev()
5197 b1 = gen_linktype(cstate, ETHERTYPE_SCA); in gen_proto_abbrev()
5201 b1 = gen_linktype(cstate, ETHERTYPE_LAT); in gen_proto_abbrev()
5205 b1 = gen_linktype(cstate, ETHERTYPE_MOPDL); in gen_proto_abbrev()
5209 b1 = gen_linktype(cstate, ETHERTYPE_MOPRC); in gen_proto_abbrev()
5213 b1 = gen_linktype(cstate, ETHERTYPE_IPV6); in gen_proto_abbrev()
5220 b1 = gen_proto(cstate, IPPROTO_ICMPV6, Q_IPV6, Q_DEFAULT); in gen_proto_abbrev()
5227 b1 = gen_proto(cstate, IPPROTO_AH, Q_IP, Q_DEFAULT); in gen_proto_abbrev()
5228 b0 = gen_proto(cstate, IPPROTO_AH, Q_IPV6, Q_DEFAULT); in gen_proto_abbrev()
5236 b1 = gen_proto(cstate, IPPROTO_ESP, Q_IP, Q_DEFAULT); in gen_proto_abbrev()
5237 b0 = gen_proto(cstate, IPPROTO_ESP, Q_IPV6, Q_DEFAULT); in gen_proto_abbrev()
5242 b1 = gen_linktype(cstate, LLCSAP_ISONS); in gen_proto_abbrev()
5246 b1 = gen_proto(cstate, ISO9542_ESIS, Q_ISO, Q_DEFAULT); in gen_proto_abbrev()
5250 b1 = gen_proto(cstate, ISO10589_ISIS, Q_ISO, Q_DEFAULT); in gen_proto_abbrev()
5254 b0 = gen_proto(cstate, ISIS_L1_LAN_IIH, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev()
5255 b1 = gen_proto(cstate, ISIS_PTP_IIH, Q_ISIS, Q_DEFAULT); /* FIXME extract the circuit-type bits */ in gen_proto_abbrev()
5257 b0 = gen_proto(cstate, ISIS_L1_LSP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev()
5259 b0 = gen_proto(cstate, ISIS_L1_CSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev()
5261 b0 = gen_proto(cstate, ISIS_L1_PSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev()
5266 b0 = gen_proto(cstate, ISIS_L2_LAN_IIH, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev()
5267 b1 = gen_proto(cstate, ISIS_PTP_IIH, Q_ISIS, Q_DEFAULT); /* FIXME extract the circuit-type bits */ in gen_proto_abbrev()
5269 b0 = gen_proto(cstate, ISIS_L2_LSP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev()
5271 b0 = gen_proto(cstate, ISIS_L2_CSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev()
5273 b0 = gen_proto(cstate, ISIS_L2_PSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev()
5278 b0 = gen_proto(cstate, ISIS_L1_LAN_IIH, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev()
5279 b1 = gen_proto(cstate, ISIS_L2_LAN_IIH, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev()
5281 b0 = gen_proto(cstate, ISIS_PTP_IIH, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev()
5286 b0 = gen_proto(cstate, ISIS_L1_LSP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev()
5287 b1 = gen_proto(cstate, ISIS_L2_LSP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev()
5292 b0 = gen_proto(cstate, ISIS_L1_CSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev()
5293 b1 = gen_proto(cstate, ISIS_L2_CSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev()
5295 b0 = gen_proto(cstate, ISIS_L1_PSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev()
5297 b0 = gen_proto(cstate, ISIS_L2_PSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev()
5302 b0 = gen_proto(cstate, ISIS_L1_CSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev()
5303 b1 = gen_proto(cstate, ISIS_L2_CSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev()
5308 b0 = gen_proto(cstate, ISIS_L1_PSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev()
5309 b1 = gen_proto(cstate, ISIS_L2_PSNP, Q_ISIS, Q_DEFAULT); in gen_proto_abbrev()
5314 b1 = gen_proto(cstate, ISO8473_CLNP, Q_ISO, Q_DEFAULT); in gen_proto_abbrev()
5318 b1 = gen_linktype(cstate, LLCSAP_8021D); in gen_proto_abbrev()
5322 b1 = gen_linktype(cstate, LLCSAP_IPX); in gen_proto_abbrev()
5326 b1 = gen_linktype(cstate, LLCSAP_NETBEUI); in gen_proto_abbrev()
5330 bpf_error(cstate, "'radio' is not a valid protocol type"); in gen_proto_abbrev()
5339 gen_ipfrag(compiler_state_t *cstate) in gen_ipfrag() argument
5345 s = gen_load_a(cstate, OR_LINKPL, 6, BPF_H); in gen_ipfrag()
5346 b = new_block(cstate, JMP(BPF_JSET)); in gen_ipfrag()
5364 gen_portatom(compiler_state_t *cstate, int off, bpf_int32 v) in gen_portatom() argument
5366 return gen_cmp(cstate, OR_TRAN_IPV4, off, BPF_H, v); in gen_portatom()
5370 gen_portatom6(compiler_state_t *cstate, int off, bpf_int32 v) in gen_portatom6() argument
5372 return gen_cmp(cstate, OR_TRAN_IPV6, off, BPF_H, v); in gen_portatom6()
5376 gen_portop(compiler_state_t *cstate, int port, int proto, int dir) in gen_portop() argument
5381 tmp = gen_cmp(cstate, OR_LINKPL, 9, BPF_B, (bpf_int32)proto); in gen_portop()
5382 b0 = gen_ipfrag(cstate); in gen_portop()
5387 b1 = gen_portatom(cstate, 0, (bpf_int32)port); in gen_portop()
5391 b1 = gen_portatom(cstate, 2, (bpf_int32)port); in gen_portop()
5396 tmp = gen_portatom(cstate, 0, (bpf_int32)port); in gen_portop()
5397 b1 = gen_portatom(cstate, 2, (bpf_int32)port); in gen_portop()
5402 tmp = gen_portatom(cstate, 0, (bpf_int32)port); in gen_portop()
5403 b1 = gen_portatom(cstate, 2, (bpf_int32)port); in gen_portop()
5416 gen_port(compiler_state_t *cstate, int port, int ip_proto, int dir) in gen_port() argument
5437 b0 = gen_linktype(cstate, ETHERTYPE_IP); in gen_port()
5443 b1 = gen_portop(cstate, port, ip_proto, dir); in gen_port()
5447 tmp = gen_portop(cstate, port, IPPROTO_TCP, dir); in gen_port()
5448 b1 = gen_portop(cstate, port, IPPROTO_UDP, dir); in gen_port()
5450 tmp = gen_portop(cstate, port, IPPROTO_SCTP, dir); in gen_port()
5462 gen_portop6(compiler_state_t *cstate, int port, int proto, int dir) in gen_portop6() argument
5468 b0 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, (bpf_int32)proto); in gen_portop6()
5472 b1 = gen_portatom6(cstate, 0, (bpf_int32)port); in gen_portop6()
5476 b1 = gen_portatom6(cstate, 2, (bpf_int32)port); in gen_portop6()
5481 tmp = gen_portatom6(cstate, 0, (bpf_int32)port); in gen_portop6()
5482 b1 = gen_portatom6(cstate, 2, (bpf_int32)port); in gen_portop6()
5487 tmp = gen_portatom6(cstate, 0, (bpf_int32)port); in gen_portop6()
5488 b1 = gen_portatom6(cstate, 2, (bpf_int32)port); in gen_portop6()
5501 gen_port6(compiler_state_t *cstate, int port, int ip_proto, int dir) in gen_port6() argument
5506 b0 = gen_linktype(cstate, ETHERTYPE_IPV6); in gen_port6()
5512 b1 = gen_portop6(cstate, port, ip_proto, dir); in gen_port6()
5516 tmp = gen_portop6(cstate, port, IPPROTO_TCP, dir); in gen_port6()
5517 b1 = gen_portop6(cstate, port, IPPROTO_UDP, dir); in gen_port6()
5519 tmp = gen_portop6(cstate, port, IPPROTO_SCTP, dir); in gen_port6()
5532 gen_portrangeatom(compiler_state_t *cstate, int off, bpf_int32 v1, in gen_portrangeatom() argument
5548 b1 = gen_cmp_ge(cstate, OR_TRAN_IPV4, off, BPF_H, v1); in gen_portrangeatom()
5549 b2 = gen_cmp_le(cstate, OR_TRAN_IPV4, off, BPF_H, v2); in gen_portrangeatom()
5557 gen_portrangeop(compiler_state_t *cstate, int port1, int port2, int proto, in gen_portrangeop() argument
5563 tmp = gen_cmp(cstate, OR_LINKPL, 9, BPF_B, (bpf_int32)proto); in gen_portrangeop()
5564 b0 = gen_ipfrag(cstate); in gen_portrangeop()
5569 b1 = gen_portrangeatom(cstate, 0, (bpf_int32)port1, (bpf_int32)port2); in gen_portrangeop()
5573 b1 = gen_portrangeatom(cstate, 2, (bpf_int32)port1, (bpf_int32)port2); in gen_portrangeop()
5578 tmp = gen_portrangeatom(cstate, 0, (bpf_int32)port1, (bpf_int32)port2); in gen_portrangeop()
5579 b1 = gen_portrangeatom(cstate, 2, (bpf_int32)port1, (bpf_int32)port2); in gen_portrangeop()
5584 tmp = gen_portrangeatom(cstate, 0, (bpf_int32)port1, (bpf_int32)port2); in gen_portrangeop()
5585 b1 = gen_portrangeatom(cstate, 2, (bpf_int32)port1, (bpf_int32)port2); in gen_portrangeop()
5598 gen_portrange(compiler_state_t *cstate, int port1, int port2, int ip_proto, in gen_portrange() argument
5604 b0 = gen_linktype(cstate, ETHERTYPE_IP); in gen_portrange()
5610 b1 = gen_portrangeop(cstate, port1, port2, ip_proto, dir); in gen_portrange()
5614 tmp = gen_portrangeop(cstate, port1, port2, IPPROTO_TCP, dir); in gen_portrange()
5615 b1 = gen_portrangeop(cstate, port1, port2, IPPROTO_UDP, dir); in gen_portrange()
5617 tmp = gen_portrangeop(cstate, port1, port2, IPPROTO_SCTP, dir); in gen_portrange()
5629 gen_portrangeatom6(compiler_state_t *cstate, int off, bpf_int32 v1, in gen_portrangeatom6() argument
5645 b1 = gen_cmp_ge(cstate, OR_TRAN_IPV6, off, BPF_H, v1); in gen_portrangeatom6()
5646 b2 = gen_cmp_le(cstate, OR_TRAN_IPV6, off, BPF_H, v2); in gen_portrangeatom6()
5654 gen_portrangeop6(compiler_state_t *cstate, int port1, int port2, int proto, in gen_portrangeop6() argument
5661 b0 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, (bpf_int32)proto); in gen_portrangeop6()
5665 b1 = gen_portrangeatom6(cstate, 0, (bpf_int32)port1, (bpf_int32)port2); in gen_portrangeop6()
5669 b1 = gen_portrangeatom6(cstate, 2, (bpf_int32)port1, (bpf_int32)port2); in gen_portrangeop6()
5674 tmp = gen_portrangeatom6(cstate, 0, (bpf_int32)port1, (bpf_int32)port2); in gen_portrangeop6()
5675 b1 = gen_portrangeatom6(cstate, 2, (bpf_int32)port1, (bpf_int32)port2); in gen_portrangeop6()
5680 tmp = gen_portrangeatom6(cstate, 0, (bpf_int32)port1, (bpf_int32)port2); in gen_portrangeop6()
5681 b1 = gen_portrangeatom6(cstate, 2, (bpf_int32)port1, (bpf_int32)port2); in gen_portrangeop6()
5694 gen_portrange6(compiler_state_t *cstate, int port1, int port2, int ip_proto, in gen_portrange6() argument
5700 b0 = gen_linktype(cstate, ETHERTYPE_IPV6); in gen_portrange6()
5706 b1 = gen_portrangeop6(cstate, port1, port2, ip_proto, dir); in gen_portrange6()
5710 tmp = gen_portrangeop6(cstate, port1, port2, IPPROTO_TCP, dir); in gen_portrange6()
5711 b1 = gen_portrangeop6(cstate, port1, port2, IPPROTO_UDP, dir); in gen_portrange6()
5713 tmp = gen_portrangeop6(cstate, port1, port2, IPPROTO_SCTP, dir); in gen_portrange6()
5725 lookup_proto(compiler_state_t *cstate, const char *name, int proto) in lookup_proto() argument
5736 bpf_error(cstate, "unknown ip proto '%s'", name); in lookup_proto()
5745 bpf_error(cstate, "unknown ether proto '%s'", name); in lookup_proto()
5757 bpf_error(cstate, "unknown osi proto '%s'", name); in lookup_proto()
5776 gen_protochain(compiler_state_t *cstate, int v, int proto, int dir) in gen_protochain() argument
5779 return gen_proto(cstate, v, proto, dir); in gen_protochain()
5786 int reg2 = alloc_reg(cstate); in gen_protochain()
5796 b0 = gen_protochain(cstate, v, Q_IP, dir); in gen_protochain()
5797 b = gen_protochain(cstate, v, Q_IPV6, dir); in gen_protochain()
5801 bpf_error(cstate, "bad protocol applied for 'protochain'"); in gen_protochain()
5816 if (cstate->off_linkpl.is_variable) in gen_protochain()
5817 bpf_error(cstate, "'protochain' not supported with variable length headers"); in gen_protochain()
5819 cstate->no_optimize = 1; /* this code is not compatible with optimizer yet */ in gen_protochain()
5827 s[i] = new_stmt(cstate, 0); /*dummy*/ in gen_protochain()
5832 b0 = gen_linktype(cstate, ETHERTYPE_IP); in gen_protochain()
5835 s[i] = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_B); in gen_protochain()
5836 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 9; in gen_protochain()
5839 s[i] = new_stmt(cstate, BPF_LDX|BPF_MSH|BPF_B); in gen_protochain()
5840 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_protochain()
5845 b0 = gen_linktype(cstate, ETHERTYPE_IPV6); in gen_protochain()
5848 s[i] = new_stmt(cstate, BPF_LD|BPF_ABS|BPF_B); in gen_protochain()
5849 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 6; in gen_protochain()
5852 s[i] = new_stmt(cstate, BPF_LDX|BPF_IMM); in gen_protochain()
5858 bpf_error(cstate, "unsupported proto to gen_protochain"); in gen_protochain()
5864 s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
5875 s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
5888 s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
5895 s[i - 1]->s.jf = s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
5901 s[i - 1]->s.jf = s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
5907 s[i - 1]->s.jf = s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
5924 s[i] = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_protochain()
5925 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_protochain()
5928 s[i] = new_stmt(cstate, BPF_ST); in gen_protochain()
5932 s[i] = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_protochain()
5933 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 1; in gen_protochain()
5936 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_protochain()
5940 s[i] = new_stmt(cstate, BPF_ALU|BPF_MUL|BPF_K); in gen_protochain()
5944 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X); in gen_protochain()
5948 s[i] = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_protochain()
5951 s[i] = new_stmt(cstate, BPF_LD|BPF_MEM); in gen_protochain()
5956 s[i] = new_stmt(cstate, BPF_JMP|BPF_JA); in gen_protochain()
5966 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_protochain()
5975 s[i] = new_stmt(cstate, BPF_JMP|BPF_JEQ|BPF_K); in gen_protochain()
5990 s[i - 1]->s.jt = s[i] = new_stmt(cstate, BPF_MISC|BPF_TXA); in gen_protochain()
5993 s[i] = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_protochain()
5994 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_protochain()
5997 s[i] = new_stmt(cstate, BPF_ST); in gen_protochain()
6001 s[i - 1]->s.jt = s[i] = new_stmt(cstate, BPF_MISC|BPF_TXA); in gen_protochain()
6004 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_protochain()
6008 s[i] = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_protochain()
6011 s[i] = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_protochain()
6012 s[i]->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_protochain()
6015 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_protochain()
6019 s[i] = new_stmt(cstate, BPF_ALU|BPF_MUL|BPF_K); in gen_protochain()
6023 s[i] = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_protochain()
6026 s[i] = new_stmt(cstate, BPF_LD|BPF_MEM); in gen_protochain()
6031 s[i] = new_stmt(cstate, BPF_JMP|BPF_JA); in gen_protochain()
6037 s[i] = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_protochain()
6055 b = new_block(cstate, JMP(BPF_JEQ)); in gen_protochain()
6059 free_reg(cstate, reg2); in gen_protochain()
6067 gen_check_802_11_data_frame(compiler_state_t *cstate) in gen_check_802_11_data_frame() argument
6076 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_check_802_11_data_frame()
6077 b0 = new_block(cstate, JMP(BPF_JSET)); in gen_check_802_11_data_frame()
6081 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_check_802_11_data_frame()
6082 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_check_802_11_data_frame()
6102 gen_proto(compiler_state_t *cstate, int v, int proto, int dir) in gen_proto() argument
6110 bpf_error(cstate, "direction applied to 'proto'"); in gen_proto()
6114 b0 = gen_proto(cstate, v, Q_IP, dir); in gen_proto()
6115 b1 = gen_proto(cstate, v, Q_IPV6, dir); in gen_proto()
6135 b0 = gen_linktype(cstate, ETHERTYPE_IP); in gen_proto()
6137 b1 = gen_cmp(cstate, OR_LINKPL, 9, BPF_B, (bpf_int32)v); in gen_proto()
6139 b1 = gen_protochain(cstate, v, Q_IP); in gen_proto()
6145 switch (cstate->linktype) { in gen_proto()
6166 return gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | v); in gen_proto()
6175 b0 = gen_linktype(cstate, LLCSAP_ISONS<<8 | LLCSAP_ISONS); in gen_proto()
6177 b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 1, BPF_B, (long)v); in gen_proto()
6182 b0 = gen_linktype(cstate, LLCSAP_ISONS); in gen_proto()
6183 b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 0, BPF_B, (long)v); in gen_proto()
6189 b0 = gen_proto(cstate, ISO10589_ISIS, Q_ISO, Q_DEFAULT); in gen_proto()
6194 b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 4, BPF_B, (long)v); in gen_proto()
6199 bpf_error(cstate, "arp does not encapsulate another protocol"); in gen_proto()
6203 bpf_error(cstate, "rarp does not encapsulate another protocol"); in gen_proto()
6207 bpf_error(cstate, "atalk encapsulation is not specifiable"); in gen_proto()
6211 bpf_error(cstate, "decnet encapsulation is not specifiable"); in gen_proto()
6215 bpf_error(cstate, "sca does not encapsulate another protocol"); in gen_proto()
6219 bpf_error(cstate, "lat does not encapsulate another protocol"); in gen_proto()
6223 bpf_error(cstate, "moprc does not encapsulate another protocol"); in gen_proto()
6227 bpf_error(cstate, "mopdl does not encapsulate another protocol"); in gen_proto()
6231 return gen_linktype(cstate, v); in gen_proto()
6234 bpf_error(cstate, "'udp proto' is bogus"); in gen_proto()
6238 bpf_error(cstate, "'tcp proto' is bogus"); in gen_proto()
6242 bpf_error(cstate, "'sctp proto' is bogus"); in gen_proto()
6246 bpf_error(cstate, "'icmp proto' is bogus"); in gen_proto()
6250 bpf_error(cstate, "'igmp proto' is bogus"); in gen_proto()
6254 bpf_error(cstate, "'igrp proto' is bogus"); in gen_proto()
6258 bpf_error(cstate, "'pim proto' is bogus"); in gen_proto()
6262 bpf_error(cstate, "'vrrp proto' is bogus"); in gen_proto()
6266 bpf_error(cstate, "'carp proto' is bogus"); in gen_proto()
6270 b0 = gen_linktype(cstate, ETHERTYPE_IPV6); in gen_proto()
6276 b2 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, IPPROTO_FRAGMENT); in gen_proto()
6277 b1 = gen_cmp(cstate, OR_LINKPL, 40, BPF_B, (bpf_int32)v); in gen_proto()
6279 b2 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, (bpf_int32)v); in gen_proto()
6282 b1 = gen_protochain(cstate, v, Q_IPV6); in gen_proto()
6288 bpf_error(cstate, "'icmp6 proto' is bogus"); in gen_proto()
6291 bpf_error(cstate, "'ah proto' is bogus"); in gen_proto()
6294 bpf_error(cstate, "'ah proto' is bogus"); in gen_proto()
6297 bpf_error(cstate, "'stp proto' is bogus"); in gen_proto()
6300 bpf_error(cstate, "'ipx proto' is bogus"); in gen_proto()
6303 bpf_error(cstate, "'netbeui proto' is bogus"); in gen_proto()
6306 bpf_error(cstate, "'radio proto' is bogus"); in gen_proto()
6316 gen_scode(compiler_state_t *cstate, const char *name, struct qual q) in gen_scode() argument
6339 bpf_error(cstate, "unknown network '%s'", name); in gen_scode()
6346 return gen_host(cstate, addr, mask, proto, dir, q.addr); in gen_scode()
6351 switch (cstate->linktype) { in gen_scode()
6358 bpf_error(cstate, in gen_scode()
6360 tmp = gen_prevlinkhdr_check(cstate); in gen_scode()
6361 b = gen_ehostop(cstate, eaddr, dir); in gen_scode()
6370 bpf_error(cstate, in gen_scode()
6372 b = gen_fhostop(cstate, eaddr, dir); in gen_scode()
6379 bpf_error(cstate, in gen_scode()
6381 b = gen_thostop(cstate, eaddr, dir); in gen_scode()
6392 bpf_error(cstate, in gen_scode()
6394 b = gen_wlanhostop(cstate, eaddr, dir); in gen_scode()
6401 bpf_error(cstate, in gen_scode()
6403 b = gen_ipfchostop(cstate, eaddr, dir); in gen_scode()
6408 …bpf_error(cstate, "only ethernet/FDDI/token ring/802.11/ATM LANE/Fibre Channel supports link-level… in gen_scode()
6414 bpf_error(cstate, "unknown decnet host name '%s'\n", name); in gen_scode()
6416 bpf_error(cstate, "decnet name support not included, '%s' cannot be translated\n", in gen_scode()
6424 return (gen_host(cstate, dn_addr, 0, proto, dir, q.addr)); in gen_scode()
6431 bpf_error(cstate, "unknown host '%s'", name); in gen_scode()
6432 cstate->ai = res; in gen_scode()
6438 if (cstate->off_linktype.constant_part == OFFSET_NOT_SET && in gen_scode()
6455 tmp = gen_host(cstate, ntohl(sin4->sin_addr.s_addr), in gen_scode()
6465 tmp = gen_host6(cstate, &sin6->sin6_addr, in gen_scode()
6476 cstate->ai = NULL; in gen_scode()
6479 bpf_error(cstate, "unknown host '%s'%s", name, in gen_scode()
6490 bpf_error(cstate, "illegal qualifier of 'port'"); in gen_scode()
6492 bpf_error(cstate, "unknown port '%s'", name); in gen_scode()
6495 bpf_error(cstate, "port '%s' is tcp", name); in gen_scode()
6497 bpf_error(cstate, "port '%s' is sctp", name); in gen_scode()
6504 bpf_error(cstate, "port '%s' is udp", name); in gen_scode()
6507 bpf_error(cstate, "port '%s' is sctp", name); in gen_scode()
6514 bpf_error(cstate, "port '%s' is udp", name); in gen_scode()
6517 bpf_error(cstate, "port '%s' is tcp", name); in gen_scode()
6523 bpf_error(cstate, "illegal port number %d < 0", port); in gen_scode()
6525 bpf_error(cstate, "illegal port number %d > 65535", port); in gen_scode()
6526 b = gen_port(cstate, port, real_proto, dir); in gen_scode()
6527 gen_or(gen_port6(cstate, port, real_proto, dir), b); in gen_scode()
6533 bpf_error(cstate, "illegal qualifier of 'portrange'"); in gen_scode()
6535 bpf_error(cstate, "unknown port in range '%s'", name); in gen_scode()
6538 bpf_error(cstate, "port in range '%s' is tcp", name); in gen_scode()
6540 bpf_error(cstate, "port in range '%s' is sctp", name); in gen_scode()
6547 bpf_error(cstate, "port in range '%s' is udp", name); in gen_scode()
6549 bpf_error(cstate, "port in range '%s' is sctp", name); in gen_scode()
6556 bpf_error(cstate, "port in range '%s' is udp", name); in gen_scode()
6558 bpf_error(cstate, "port in range '%s' is tcp", name); in gen_scode()
6564 bpf_error(cstate, "illegal port number %d < 0", port1); in gen_scode()
6566 bpf_error(cstate, "illegal port number %d > 65535", port1); in gen_scode()
6568 bpf_error(cstate, "illegal port number %d < 0", port2); in gen_scode()
6570 bpf_error(cstate, "illegal port number %d > 65535", port2); in gen_scode()
6572 b = gen_portrange(cstate, port1, port2, real_proto, dir); in gen_scode()
6573 gen_or(gen_portrange6(cstate, port1, port2, real_proto, dir), b); in gen_scode()
6580 bpf_error(cstate, "unknown ether host: %s", name); in gen_scode()
6583 cstate->ai = res; in gen_scode()
6585 bpf_error(cstate, "unknown host '%s'", name); in gen_scode()
6586 b = gen_gateway(cstate, eaddr, res, proto, dir); in gen_scode()
6587 cstate->ai = NULL; in gen_scode()
6590 bpf_error(cstate, "unknown host '%s'", name); in gen_scode()
6593 bpf_error(cstate, "'gateway' not supported in this configuration"); in gen_scode()
6597 real_proto = lookup_proto(cstate, name, proto); in gen_scode()
6599 return gen_proto(cstate, real_proto, proto, dir); in gen_scode()
6601 bpf_error(cstate, "unknown protocol: %s", name); in gen_scode()
6604 real_proto = lookup_proto(cstate, name, proto); in gen_scode()
6606 return gen_protochain(cstate, real_proto, proto, dir); in gen_scode()
6608 bpf_error(cstate, "unknown protocol: %s", name); in gen_scode()
6611 syntax(cstate); in gen_scode()
6619 gen_mcode(compiler_state_t *cstate, const char *s1, const char *s2, in gen_mcode() argument
6634 bpf_error(cstate, "non-network bits set in \"%s mask %s\"", in gen_mcode()
6639 bpf_error(cstate, "mask length must be <= 32"); in gen_mcode()
6649 bpf_error(cstate, "non-network bits set in \"%s/%d\"", in gen_mcode()
6656 return gen_host(cstate, n, m, q.proto, q.dir, q.addr); in gen_mcode()
6659 bpf_error(cstate, "Mask syntax for networks only"); in gen_mcode()
6666 gen_ncode(compiler_state_t *cstate, const char *s, bpf_u_int32 v, struct qual q) in gen_ncode() argument
6678 bpf_error(cstate, "malformed decnet address '%s'", s); in gen_ncode()
6688 return gen_host(cstate, v, 0, proto, dir, q.addr); in gen_ncode()
6690 bpf_error(cstate, "illegal link layer address"); in gen_ncode()
6704 return gen_host(cstate, v, mask, proto, dir, q.addr); in gen_ncode()
6717 bpf_error(cstate, "illegal qualifier of 'port'"); in gen_ncode()
6720 bpf_error(cstate, "illegal port number %u > 65535", v); in gen_ncode()
6724 b = gen_port(cstate, (int)v, proto, dir); in gen_ncode()
6725 gen_or(gen_port6(cstate, (int)v, proto, dir), b); in gen_ncode()
6739 bpf_error(cstate, "illegal qualifier of 'portrange'"); in gen_ncode()
6742 bpf_error(cstate, "illegal port number %u > 65535", v); in gen_ncode()
6746 b = gen_portrange(cstate, (int)v, (int)v, proto, dir); in gen_ncode()
6747 gen_or(gen_portrange6(cstate, (int)v, (int)v, proto, dir), b); in gen_ncode()
6752 bpf_error(cstate, "'gateway' requires a name"); in gen_ncode()
6756 return gen_proto(cstate, (int)v, proto, dir); in gen_ncode()
6759 return gen_protochain(cstate, (int)v, proto, dir); in gen_ncode()
6762 syntax(cstate); in gen_ncode()
6774 gen_mcode6(compiler_state_t *cstate, const char *s1, const char *s2, in gen_mcode6() argument
6784 bpf_error(cstate, "no mask %s supported", s2); in gen_mcode6()
6788 bpf_error(cstate, "invalid ip6 address %s", s1); in gen_mcode6()
6789 cstate->ai = res; in gen_mcode6()
6791 bpf_error(cstate, "%s resolved to multiple address", s1); in gen_mcode6()
6795 bpf_error(cstate, "mask length must be <= %u", (unsigned int)(sizeof(mask) * 8)); in gen_mcode6()
6807 bpf_error(cstate, "non-network bits set in \"%s/%d\"", s1, masklen); in gen_mcode6()
6815 bpf_error(cstate, "Mask syntax for networks only"); in gen_mcode6()
6819 b = gen_host6(cstate, addr, &mask, q.proto, q.dir, q.addr); in gen_mcode6()
6820 cstate->ai = NULL; in gen_mcode6()
6825 bpf_error(cstate, "invalid qualifier against IPv6 address"); in gen_mcode6()
6832 gen_ecode(compiler_state_t *cstate, const u_char *eaddr, struct qual q) in gen_ecode() argument
6837 switch (cstate->linktype) { in gen_ecode()
6841 tmp = gen_prevlinkhdr_check(cstate); in gen_ecode()
6842 b = gen_ehostop(cstate, eaddr, (int)q.dir); in gen_ecode()
6847 return gen_fhostop(cstate, eaddr, (int)q.dir); in gen_ecode()
6849 return gen_thostop(cstate, eaddr, (int)q.dir); in gen_ecode()
6855 return gen_wlanhostop(cstate, eaddr, (int)q.dir); in gen_ecode()
6857 return gen_ipfchostop(cstate, eaddr, (int)q.dir); in gen_ecode()
6859 …bpf_error(cstate, "ethernet addresses supported only on ethernet/FDDI/token ring/802.11/ATM LANE/F… in gen_ecode()
6863 bpf_error(cstate, "ethernet address used in non-ether expression"); in gen_ecode()
6880 xfer_to_x(compiler_state_t *cstate, struct arth *a) in xfer_to_x() argument
6884 s = new_stmt(cstate, BPF_LDX|BPF_MEM); in xfer_to_x()
6890 xfer_to_a(compiler_state_t *cstate, struct arth *a) in xfer_to_a() argument
6894 s = new_stmt(cstate, BPF_LD|BPF_MEM); in xfer_to_a()
6907 gen_load(compiler_state_t *cstate, int proto, struct arth *inst, int size) in gen_load() argument
6911 int regno = alloc_reg(cstate); in gen_load()
6913 free_reg(cstate, inst->regno); in gen_load()
6917 bpf_error(cstate, "data size must be 1, 2, or 4"); in gen_load()
6933 bpf_error(cstate, "unsupported index operation"); in gen_load()
6941 if (cstate->linktype != DLT_IEEE802_11_RADIO_AVS && in gen_load()
6942 cstate->linktype != DLT_IEEE802_11_RADIO && in gen_load()
6943 cstate->linktype != DLT_PRISM_HEADER) in gen_load()
6944 bpf_error(cstate, "radio information not present in capture"); in gen_load()
6950 s = xfer_to_x(cstate, inst); in gen_load()
6955 tmp = new_stmt(cstate, BPF_LD|BPF_IND|size); in gen_load()
6972 s = gen_abs_offset_varpart(cstate, &cstate->off_linkhdr); in gen_load()
6984 sappend(s, xfer_to_a(cstate, inst)); in gen_load()
6985 sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X)); in gen_load()
6986 sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX)); in gen_load()
6988 s = xfer_to_x(cstate, inst); in gen_load()
6997 tmp = new_stmt(cstate, BPF_LD|BPF_IND|size); in gen_load()
6998 tmp->s.k = cstate->off_linkhdr.constant_part; in gen_load()
7019 s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl); in gen_load()
7031 sappend(s, xfer_to_a(cstate, inst)); in gen_load()
7032 sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X)); in gen_load()
7033 sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX)); in gen_load()
7035 s = xfer_to_x(cstate, inst); in gen_load()
7044 tmp = new_stmt(cstate, BPF_LD|BPF_IND|size); in gen_load()
7045 tmp->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_load()
7053 b = gen_proto_abbrev(cstate, proto); in gen_load()
7082 s = gen_loadx_iphdrlen(cstate); in gen_load()
7098 sappend(s, xfer_to_a(cstate, inst)); in gen_load()
7099 sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X)); in gen_load()
7100 sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX)); in gen_load()
7101 sappend(s, tmp = new_stmt(cstate, BPF_LD|BPF_IND|size)); in gen_load()
7102 tmp->s.k = cstate->off_linkpl.constant_part + cstate->off_nl; in gen_load()
7111 gen_and(gen_proto_abbrev(cstate, proto), b = gen_ipfrag(cstate)); in gen_load()
7114 gen_and(gen_proto_abbrev(cstate, Q_IP), b); in gen_load()
7122 b = gen_proto_abbrev(cstate, Q_IPV6); in gen_load()
7131 b = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, 58); in gen_load()
7138 s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl); in gen_load()
7149 sappend(s, xfer_to_a(cstate, inst)); in gen_load()
7150 sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X)); in gen_load()
7151 sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX)); in gen_load()
7153 s = xfer_to_x(cstate, inst); in gen_load()
7163 tmp = new_stmt(cstate, BPF_LD|BPF_IND|size); in gen_load()
7164 tmp->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 40; in gen_load()
7172 s = new_stmt(cstate, BPF_ST); in gen_load()
7180 gen_relation(compiler_state_t *cstate, int code, struct arth *a0, in gen_relation() argument
7186 s0 = xfer_to_x(cstate, a1); in gen_relation()
7187 s1 = xfer_to_a(cstate, a0); in gen_relation()
7189 s2 = new_stmt(cstate, BPF_ALU|BPF_SUB|BPF_X); in gen_relation()
7190 b = new_block(cstate, JMP(code)); in gen_relation()
7194 b = new_block(cstate, BPF_JMP|code|BPF_X); in gen_relation()
7204 free_reg(cstate, a0->regno); in gen_relation()
7205 free_reg(cstate, a1->regno); in gen_relation()
7224 gen_loadlen(compiler_state_t *cstate) in gen_loadlen() argument
7226 int regno = alloc_reg(cstate); in gen_loadlen()
7227 struct arth *a = (struct arth *)newchunk(cstate, sizeof(*a)); in gen_loadlen()
7230 s = new_stmt(cstate, BPF_LD|BPF_LEN); in gen_loadlen()
7231 s->next = new_stmt(cstate, BPF_ST); in gen_loadlen()
7240 gen_loadi(compiler_state_t *cstate, int val) in gen_loadi() argument
7246 a = (struct arth *)newchunk(cstate, sizeof(*a)); in gen_loadi()
7248 reg = alloc_reg(cstate); in gen_loadi()
7250 s = new_stmt(cstate, BPF_LD|BPF_IMM); in gen_loadi()
7252 s->next = new_stmt(cstate, BPF_ST); in gen_loadi()
7261 gen_neg(compiler_state_t *cstate, struct arth *a) in gen_neg() argument
7265 s = xfer_to_a(cstate, a); in gen_neg()
7267 s = new_stmt(cstate, BPF_ALU|BPF_NEG); in gen_neg()
7270 s = new_stmt(cstate, BPF_ST); in gen_neg()
7278 gen_arth(compiler_state_t *cstate, int code, struct arth *a0, in gen_arth() argument
7289 bpf_error(cstate, "division by zero"); in gen_arth()
7292 bpf_error(cstate, "modulus by zero"); in gen_arth()
7294 s0 = xfer_to_x(cstate, a1); in gen_arth()
7295 s1 = xfer_to_a(cstate, a0); in gen_arth()
7296 s2 = new_stmt(cstate, BPF_ALU|BPF_X|code); in gen_arth()
7303 free_reg(cstate, a0->regno); in gen_arth()
7304 free_reg(cstate, a1->regno); in gen_arth()
7306 s0 = new_stmt(cstate, BPF_ST); in gen_arth()
7307 a0->regno = s0->s.k = alloc_reg(cstate); in gen_arth()
7317 init_regs(compiler_state_t *cstate) in init_regs() argument
7319 cstate->curreg = 0; in init_regs()
7320 memset(cstate->regused, 0, sizeof cstate->regused); in init_regs()
7327 alloc_reg(compiler_state_t *cstate) in alloc_reg() argument
7332 if (cstate->regused[cstate->curreg]) in alloc_reg()
7333 cstate->curreg = (cstate->curreg + 1) % BPF_MEMWORDS; in alloc_reg()
7335 cstate->regused[cstate->curreg] = 1; in alloc_reg()
7336 return cstate->curreg; in alloc_reg()
7339 bpf_error(cstate, "too many registers needed to evaluate expression"); in alloc_reg()
7348 free_reg(compiler_state_t *cstate, int n) in free_reg() argument
7350 cstate->regused[n] = 0; in free_reg()
7354 gen_len(compiler_state_t *cstate, int jmp, int n) in gen_len() argument
7359 s = new_stmt(cstate, BPF_LD|BPF_LEN); in gen_len()
7360 b = new_block(cstate, JMP(jmp)); in gen_len()
7368 gen_greater(compiler_state_t *cstate, int n) in gen_greater() argument
7370 return gen_len(cstate, BPF_JGE, n); in gen_greater()
7377 gen_less(compiler_state_t *cstate, int n) in gen_less() argument
7381 b = gen_len(cstate, BPF_JGT, n); in gen_less()
7398 gen_byteop(compiler_state_t *cstate, int op, int idx, int val) in gen_byteop() argument
7408 return gen_cmp(cstate, OR_LINKHDR, (u_int)idx, BPF_B, (bpf_int32)val); in gen_byteop()
7411 b = gen_cmp_lt(cstate, OR_LINKHDR, (u_int)idx, BPF_B, (bpf_int32)val); in gen_byteop()
7415 b = gen_cmp_gt(cstate, OR_LINKHDR, (u_int)idx, BPF_B, (bpf_int32)val); in gen_byteop()
7419 s = new_stmt(cstate, BPF_ALU|BPF_OR|BPF_K); in gen_byteop()
7423 s = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K); in gen_byteop()
7427 b = new_block(cstate, JMP(BPF_JEQ)); in gen_byteop()
7437 gen_broadcast(compiler_state_t *cstate, int proto) in gen_broadcast() argument
7447 switch (cstate->linktype) { in gen_broadcast()
7450 return gen_ahostop(cstate, abroadcast, Q_DST); in gen_broadcast()
7454 b1 = gen_prevlinkhdr_check(cstate); in gen_broadcast()
7455 b0 = gen_ehostop(cstate, ebroadcast, Q_DST); in gen_broadcast()
7460 return gen_fhostop(cstate, ebroadcast, Q_DST); in gen_broadcast()
7462 return gen_thostop(cstate, ebroadcast, Q_DST); in gen_broadcast()
7468 return gen_wlanhostop(cstate, ebroadcast, Q_DST); in gen_broadcast()
7470 return gen_ipfchostop(cstate, ebroadcast, Q_DST); in gen_broadcast()
7472 bpf_error(cstate, "not a broadcast link"); in gen_broadcast()
7482 if (cstate->netmask == PCAP_NETMASK_UNKNOWN) in gen_broadcast()
7483 bpf_error(cstate, "netmask not known, so 'ip broadcast' not supported"); in gen_broadcast()
7484 b0 = gen_linktype(cstate, ETHERTYPE_IP); in gen_broadcast()
7485 hostmask = ~cstate->netmask; in gen_broadcast()
7486 b1 = gen_mcmp(cstate, OR_LINKPL, 16, BPF_W, (bpf_int32)0, hostmask); in gen_broadcast()
7487 b2 = gen_mcmp(cstate, OR_LINKPL, 16, BPF_W, in gen_broadcast()
7493 bpf_error(cstate, "only link-layer/IP broadcast filters supported"); in gen_broadcast()
7502 gen_mac_multicast(compiler_state_t *cstate, int offset) in gen_mac_multicast() argument
7508 s = gen_load_a(cstate, OR_LINKHDR, offset, BPF_B); in gen_mac_multicast()
7509 b0 = new_block(cstate, JMP(BPF_JSET)); in gen_mac_multicast()
7516 gen_multicast(compiler_state_t *cstate, int proto) in gen_multicast() argument
7525 switch (cstate->linktype) { in gen_multicast()
7529 return gen_ahostop(cstate, abroadcast, Q_DST); in gen_multicast()
7533 b1 = gen_prevlinkhdr_check(cstate); in gen_multicast()
7535 b0 = gen_mac_multicast(cstate, 0); in gen_multicast()
7546 return gen_mac_multicast(cstate, 1); in gen_multicast()
7549 return gen_mac_multicast(cstate, 2); in gen_multicast()
7576 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_multicast()
7577 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_multicast()
7584 b0 = gen_mac_multicast(cstate, 16); in gen_multicast()
7591 s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B); in gen_multicast()
7592 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_multicast()
7600 b1 = gen_mac_multicast(cstate, 4); in gen_multicast()
7613 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_multicast()
7614 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_multicast()
7628 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_multicast()
7629 b2 = new_block(cstate, JMP(BPF_JSET)); in gen_multicast()
7637 b1 = gen_mac_multicast(cstate, 4); in gen_multicast()
7655 s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B); in gen_multicast()
7656 b1 = new_block(cstate, JMP(BPF_JSET)); in gen_multicast()
7668 b0 = gen_mac_multicast(cstate, 2); in gen_multicast()
7677 b0 = gen_linktype(cstate, ETHERTYPE_IP); in gen_multicast()
7678 b1 = gen_cmp_ge(cstate, OR_LINKPL, 16, BPF_B, (bpf_int32)224); in gen_multicast()
7683 b0 = gen_linktype(cstate, ETHERTYPE_IPV6); in gen_multicast()
7684 b1 = gen_cmp(cstate, OR_LINKPL, 24, BPF_B, (bpf_int32)255); in gen_multicast()
7688 …bpf_error(cstate, "link-layer multicast filters supported only on ethernet/FDDI/token ring/ARCNET/… in gen_multicast()
7702 gen_inbound(compiler_state_t *cstate, int dir) in gen_inbound() argument
7709 switch (cstate->linktype) { in gen_inbound()
7711 b0 = gen_relation(cstate, BPF_JEQ, in gen_inbound()
7712 gen_load(cstate, Q_LINK, gen_loadi(cstate, 0), 1), in gen_inbound()
7713 gen_loadi(cstate, 0), in gen_inbound()
7720 b0 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, IPNET_OUTBOUND); in gen_inbound()
7723 b0 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, IPNET_INBOUND); in gen_inbound()
7729 b0 = gen_cmp(cstate, OR_LINKHDR, 0, BPF_H, LINUX_SLL_OUTGOING); in gen_inbound()
7738 b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, dir), BPF_B, in gen_inbound()
7746 b0 = gen_cmp(cstate, OR_LINKHDR, 0, BPF_B, PPP_PPPD_OUT); in gen_inbound()
7749 b0 = gen_cmp(cstate, OR_LINKHDR, 0, BPF_B, PPP_PPPD_IN); in gen_inbound()
7780 b0 = gen_mcmp(cstate, OR_LINKHDR, 3, BPF_B, 0, 0x01); in gen_inbound()
7783 b0 = gen_mcmp(cstate, OR_LINKHDR, 3, BPF_B, 1, 0x01); in gen_inbound()
7810 if (cstate->bpf_pcap->rfile != NULL) { in gen_inbound()
7812 bpf_error(cstate, "inbound/outbound not supported on linktype %d when reading savefiles", in gen_inbound()
7813 cstate->linktype); in gen_inbound()
7818 b0 = gen_cmp(cstate, OR_LINKHDR, SKF_AD_OFF + SKF_AD_PKTTYPE, BPF_H, in gen_inbound()
7825 bpf_error(cstate, "inbound/outbound not supported on linktype %d", in gen_inbound()
7826 cstate->linktype); in gen_inbound()
7836 gen_pf_ifname(compiler_state_t *cstate, const char *ifname) in gen_pf_ifname() argument
7841 if (cstate->linktype != DLT_PFLOG) { in gen_pf_ifname()
7842 bpf_error(cstate, "ifname supported only on PF linktype"); in gen_pf_ifname()
7848 bpf_error(cstate, "ifname interface names can only be %d characters", in gen_pf_ifname()
7852 b0 = gen_bcmp(cstate, OR_LINKHDR, off, strlen(ifname), (const u_char *)ifname); in gen_pf_ifname()
7858 gen_pf_ruleset(compiler_state_t *cstate, char *ruleset) in gen_pf_ruleset() argument
7862 if (cstate->linktype != DLT_PFLOG) { in gen_pf_ruleset()
7863 bpf_error(cstate, "ruleset supported only on PF linktype"); in gen_pf_ruleset()
7868 bpf_error(cstate, "ruleset names can only be %ld characters", in gen_pf_ruleset()
7873 b0 = gen_bcmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, ruleset), in gen_pf_ruleset()
7880 gen_pf_rnr(compiler_state_t *cstate, int rnr) in gen_pf_rnr() argument
7884 if (cstate->linktype != DLT_PFLOG) { in gen_pf_rnr()
7885 bpf_error(cstate, "rnr supported only on PF linktype"); in gen_pf_rnr()
7889 b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, rulenr), BPF_W, in gen_pf_rnr()
7896 gen_pf_srnr(compiler_state_t *cstate, int srnr) in gen_pf_srnr() argument
7900 if (cstate->linktype != DLT_PFLOG) { in gen_pf_srnr()
7901 bpf_error(cstate, "srnr supported only on PF linktype"); in gen_pf_srnr()
7905 b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, subrulenr), BPF_W, in gen_pf_srnr()
7912 gen_pf_reason(compiler_state_t *cstate, int reason) in gen_pf_reason() argument
7916 if (cstate->linktype != DLT_PFLOG) { in gen_pf_reason()
7917 bpf_error(cstate, "reason supported only on PF linktype"); in gen_pf_reason()
7921 b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, reason), BPF_B, in gen_pf_reason()
7928 gen_pf_action(compiler_state_t *cstate, int action) in gen_pf_action() argument
7932 if (cstate->linktype != DLT_PFLOG) { in gen_pf_action()
7933 bpf_error(cstate, "action supported only on PF linktype"); in gen_pf_action()
7937 b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, action), BPF_B, in gen_pf_action()
7943 gen_pf_ifname(compiler_state_t *cstate, const char *ifname _U_) in gen_pf_ifname() argument
7945 bpf_error(cstate, "libpcap was compiled without pf support"); in gen_pf_ifname()
7950 gen_pf_ruleset(compiler_state_t *cstate, char *ruleset _U_) in gen_pf_ruleset() argument
7952 bpf_error(cstate, "libpcap was compiled on a machine without pf support"); in gen_pf_ruleset()
7957 gen_pf_rnr(compiler_state_t *cstate, int rnr _U_) in gen_pf_rnr() argument
7959 bpf_error(cstate, "libpcap was compiled on a machine without pf support"); in gen_pf_rnr()
7964 gen_pf_srnr(compiler_state_t *cstate, int srnr _U_) in gen_pf_srnr() argument
7966 bpf_error(cstate, "libpcap was compiled on a machine without pf support"); in gen_pf_srnr()
7971 gen_pf_reason(compiler_state_t *cstate, int reason _U_) in gen_pf_reason() argument
7973 bpf_error(cstate, "libpcap was compiled on a machine without pf support"); in gen_pf_reason()
7978 gen_pf_action(compiler_state_t *cstate, int action _U_) in gen_pf_action() argument
7980 bpf_error(cstate, "libpcap was compiled on a machine without pf support"); in gen_pf_action()
7987 gen_p80211_type(compiler_state_t *cstate, int type, int mask) in gen_p80211_type() argument
7991 switch (cstate->linktype) { in gen_p80211_type()
7997 b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, (bpf_int32)type, in gen_p80211_type()
8002 bpf_error(cstate, "802.11 link-layer types supported only on 802.11"); in gen_p80211_type()
8010 gen_p80211_fcdir(compiler_state_t *cstate, int fcdir) in gen_p80211_fcdir() argument
8014 switch (cstate->linktype) { in gen_p80211_fcdir()
8023 bpf_error(cstate, "frame direction supported only with 802.11 headers"); in gen_p80211_fcdir()
8027 b0 = gen_mcmp(cstate, OR_LINKHDR, 1, BPF_B, (bpf_int32)fcdir, in gen_p80211_fcdir()
8034 gen_acode(compiler_state_t *cstate, const u_char *eaddr, struct qual q) in gen_acode() argument
8036 switch (cstate->linktype) { in gen_acode()
8042 return (gen_ahostop(cstate, eaddr, (int)q.dir)); in gen_acode()
8044 bpf_error(cstate, "ARCnet address used in non-arc expression"); in gen_acode()
8050 bpf_error(cstate, "aid supported only on ARCnet"); in gen_acode()
8056 gen_ahostop(compiler_state_t *cstate, const u_char *eaddr, int dir) in gen_ahostop() argument
8063 return gen_bcmp(cstate, OR_LINKHDR, 0, 1, eaddr); in gen_ahostop()
8066 return gen_bcmp(cstate, OR_LINKHDR, 1, 1, eaddr); in gen_ahostop()
8069 b0 = gen_ahostop(cstate, eaddr, Q_SRC); in gen_ahostop()
8070 b1 = gen_ahostop(cstate, eaddr, Q_DST); in gen_ahostop()
8076 b0 = gen_ahostop(cstate, eaddr, Q_SRC); in gen_ahostop()
8077 b1 = gen_ahostop(cstate, eaddr, Q_DST); in gen_ahostop()
8082 bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11"); in gen_ahostop()
8086 bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11"); in gen_ahostop()
8090 bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11"); in gen_ahostop()
8094 bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11"); in gen_ahostop()
8098 bpf_error(cstate, "'ra' is only supported on 802.11"); in gen_ahostop()
8102 bpf_error(cstate, "'ta' is only supported on 802.11"); in gen_ahostop()
8110 gen_vlan_tpid_test(compiler_state_t *cstate) in gen_vlan_tpid_test() argument
8115 b0 = gen_linktype(cstate, ETHERTYPE_8021Q); in gen_vlan_tpid_test()
8116 b1 = gen_linktype(cstate, ETHERTYPE_8021AD); in gen_vlan_tpid_test()
8119 b1 = gen_linktype(cstate, ETHERTYPE_8021QINQ); in gen_vlan_tpid_test()
8126 gen_vlan_vid_test(compiler_state_t *cstate, int vlan_num) in gen_vlan_vid_test() argument
8128 return gen_mcmp(cstate, OR_LINKPL, 0, BPF_H, (bpf_int32)vlan_num, 0x0fff); in gen_vlan_vid_test()
8132 gen_vlan_no_bpf_extensions(compiler_state_t *cstate, int vlan_num) in gen_vlan_no_bpf_extensions() argument
8136 b0 = gen_vlan_tpid_test(cstate); in gen_vlan_no_bpf_extensions()
8139 b1 = gen_vlan_vid_test(cstate, vlan_num); in gen_vlan_no_bpf_extensions()
8148 cstate->off_linkpl.constant_part += 4; in gen_vlan_no_bpf_extensions()
8149 cstate->off_linktype.constant_part += 4; in gen_vlan_no_bpf_extensions()
8157 gen_vlan_vloffset_add(compiler_state_t *cstate, bpf_abs_offset *off, int v, struct slist *s) in gen_vlan_vloffset_add() argument
8164 off->reg = alloc_reg(cstate); in gen_vlan_vloffset_add()
8166 s2 = new_stmt(cstate, BPF_LD|BPF_MEM); in gen_vlan_vloffset_add()
8169 s2 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_IMM); in gen_vlan_vloffset_add()
8172 s2 = new_stmt(cstate, BPF_ST); in gen_vlan_vloffset_add()
8182 gen_vlan_patch_tpid_test(compiler_state_t *cstate, struct block *b_tpid) in gen_vlan_patch_tpid_test() argument
8188 cstate->is_vlan_vloffset = 1; in gen_vlan_patch_tpid_test()
8189 gen_vlan_vloffset_add(cstate, &cstate->off_linkpl, 4, &s); in gen_vlan_patch_tpid_test()
8190 gen_vlan_vloffset_add(cstate, &cstate->off_linktype, 4, &s); in gen_vlan_patch_tpid_test()
8202 gen_vlan_patch_vid_test(compiler_state_t *cstate, struct block *b_vid) in gen_vlan_patch_vid_test() argument
8207 s = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_vlan_patch_vid_test()
8211 sjeq = new_stmt(cstate, JMP(BPF_JEQ)); in gen_vlan_patch_vid_test()
8216 s2 = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_vlan_patch_vid_test()
8225 s2 = new_stmt(cstate, JMP(BPF_JA)); in gen_vlan_patch_vid_test()
8243 gen_vlan_bpf_extensions(compiler_state_t *cstate, int vlan_num) in gen_vlan_bpf_extensions() argument
8250 s = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS); in gen_vlan_bpf_extensions()
8253 b0 = new_block(cstate, JMP(BPF_JEQ)); in gen_vlan_bpf_extensions()
8267 b_tpid = gen_vlan_tpid_test(cstate); in gen_vlan_bpf_extensions()
8269 b_vid = gen_vlan_vid_test(cstate, vlan_num); in gen_vlan_bpf_extensions()
8271 gen_vlan_patch_tpid_test(cstate, b_tpid); in gen_vlan_bpf_extensions()
8276 gen_vlan_patch_vid_test(cstate, b_vid); in gen_vlan_bpf_extensions()
8289 gen_vlan(compiler_state_t *cstate, int vlan_num) in gen_vlan() argument
8294 if (cstate->label_stack_depth > 0) in gen_vlan()
8295 bpf_error(cstate, "no VLAN match after MPLS"); in gen_vlan()
8328 switch (cstate->linktype) { in gen_vlan()
8336 if (cstate->vlan_stack_depth == 0 && !cstate->off_linkhdr.is_variable && in gen_vlan()
8337 cstate->off_linkhdr.constant_part == in gen_vlan()
8338 cstate->off_outermostlinkhdr.constant_part) { in gen_vlan()
8342 if (cstate->bpf_pcap->bpf_codegen_flags & BPF_SPECIAL_VLAN_HANDLING) in gen_vlan()
8343 b0 = gen_vlan_bpf_extensions(cstate, vlan_num); in gen_vlan()
8345 b0 = gen_vlan_no_bpf_extensions(cstate, vlan_num); in gen_vlan()
8348 b0 = gen_vlan_no_bpf_extensions(cstate, vlan_num); in gen_vlan()
8355 b0 = gen_vlan_no_bpf_extensions(cstate, vlan_num); in gen_vlan()
8359 bpf_error(cstate, "no VLAN support for data link type %d", in gen_vlan()
8360 cstate->linktype); in gen_vlan()
8364 cstate->vlan_stack_depth++; in gen_vlan()
8373 gen_mpls(compiler_state_t *cstate, int label_num) in gen_mpls() argument
8377 if (cstate->label_stack_depth > 0) { in gen_mpls()
8379 b0 = gen_mcmp(cstate, OR_PREVMPLSHDR, 2, BPF_B, 0, 0x01); in gen_mpls()
8385 switch (cstate->linktype) { in gen_mpls()
8391 b0 = gen_linktype(cstate, ETHERTYPE_MPLS); in gen_mpls()
8395 b0 = gen_linktype(cstate, PPP_MPLS_UCAST); in gen_mpls()
8403 bpf_error(cstate, "no MPLS support for data link type %d", in gen_mpls()
8404 cstate->linktype); in gen_mpls()
8413 b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_W, (bpf_int32)label_num, in gen_mpls()
8433 cstate->off_nl_nosnap += 4; in gen_mpls()
8434 cstate->off_nl += 4; in gen_mpls()
8435 cstate->label_stack_depth++; in gen_mpls()
8443 gen_pppoed(compiler_state_t *cstate) in gen_pppoed() argument
8446 return gen_linktype(cstate, (bpf_int32)ETHERTYPE_PPPOED); in gen_pppoed()
8450 gen_pppoes(compiler_state_t *cstate, int sess_num) in gen_pppoes() argument
8457 b0 = gen_linktype(cstate, (bpf_int32)ETHERTYPE_PPPOES); in gen_pppoes()
8461 b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_W, in gen_pppoes()
8506 PUSH_LINKHDR(cstate, DLT_PPP, cstate->off_linkpl.is_variable, in gen_pppoes()
8507 cstate->off_linkpl.constant_part + cstate->off_nl + 6, /* 6 bytes past the PPPoE header */ in gen_pppoes()
8508 cstate->off_linkpl.reg); in gen_pppoes()
8510 cstate->off_linktype = cstate->off_linkhdr; in gen_pppoes()
8511 cstate->off_linkpl.constant_part = cstate->off_linkhdr.constant_part + 2; in gen_pppoes()
8513 cstate->off_nl = 0; in gen_pppoes()
8514 cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ in gen_pppoes()
8522 gen_geneve_check(compiler_state_t *cstate, in gen_geneve_check() argument
8528 b0 = gen_portfn(cstate, GENEVE_PORT, IPPROTO_UDP, Q_DST); in gen_geneve_check()
8533 b1 = gen_mcmp(cstate, offrel, 8, BPF_B, (bpf_int32)0, 0xc0); in gen_geneve_check()
8539 b1 = gen_mcmp(cstate, offrel, 12, BPF_W, (bpf_int32)vni, in gen_geneve_check()
8554 gen_geneve4(compiler_state_t *cstate, int vni) in gen_geneve4() argument
8559 b0 = gen_geneve_check(cstate, gen_port, OR_TRAN_IPV4, vni); in gen_geneve4()
8562 s = gen_loadx_iphdrlen(cstate); in gen_geneve4()
8564 s1 = new_stmt(cstate, BPF_MISC|BPF_TXA); in gen_geneve4()
8570 b1 = new_block(cstate, BPF_JMP|BPF_JEQ|BPF_X); in gen_geneve4()
8580 gen_geneve6(compiler_state_t *cstate, int vni) in gen_geneve6() argument
8585 b0 = gen_geneve_check(cstate, gen_port6, OR_TRAN_IPV6, vni); in gen_geneve6()
8589 s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl); in gen_geneve6()
8591 s1 = new_stmt(cstate, BPF_LD|BPF_IMM); in gen_geneve6()
8595 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X); in gen_geneve6()
8599 s = new_stmt(cstate, BPF_LD|BPF_IMM); in gen_geneve6()
8606 s1 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_geneve6()
8609 b1 = new_block(cstate, BPF_JMP|BPF_JEQ|BPF_X); in gen_geneve6()
8623 gen_geneve_offsets(compiler_state_t *cstate) in gen_geneve_offsets() argument
8632 s = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_geneve_offsets()
8633 s->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 8; in gen_geneve_offsets()
8636 s1 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_geneve_offsets()
8641 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_geneve_offsets()
8645 cstate->off_linktype.reg = alloc_reg(cstate); in gen_geneve_offsets()
8646 cstate->off_linktype.is_variable = 1; in gen_geneve_offsets()
8647 cstate->off_linktype.constant_part = 0; in gen_geneve_offsets()
8649 s1 = new_stmt(cstate, BPF_ST); in gen_geneve_offsets()
8650 s1->s.k = cstate->off_linktype.reg; in gen_geneve_offsets()
8656 s1 = new_stmt(cstate, BPF_LD|BPF_IND|BPF_B); in gen_geneve_offsets()
8660 s1 = new_stmt(cstate, BPF_ALU|BPF_AND|BPF_K); in gen_geneve_offsets()
8664 s1 = new_stmt(cstate, BPF_ALU|BPF_MUL|BPF_K); in gen_geneve_offsets()
8669 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_geneve_offsets()
8674 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X); in gen_geneve_offsets()
8686 PUSH_LINKHDR(cstate, DLT_EN10MB, 1, 0, alloc_reg(cstate)); in gen_geneve_offsets()
8688 s1 = new_stmt(cstate, BPF_ST); in gen_geneve_offsets()
8689 s1->s.k = cstate->off_linkhdr.reg; in gen_geneve_offsets()
8698 cstate->no_optimize = 1; in gen_geneve_offsets()
8701 s1 = new_stmt(cstate, BPF_LD|BPF_IND|BPF_H); in gen_geneve_offsets()
8706 s1 = new_stmt(cstate, BPF_LDX|BPF_MEM); in gen_geneve_offsets()
8707 s1->s.k = cstate->off_linkhdr.reg; in gen_geneve_offsets()
8713 s_proto = new_stmt(cstate, JMP(BPF_JEQ)); in gen_geneve_offsets()
8717 s1 = new_stmt(cstate, BPF_MISC|BPF_TXA); in gen_geneve_offsets()
8723 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_geneve_offsets()
8727 s1 = new_stmt(cstate, BPF_ST); in gen_geneve_offsets()
8728 s1->s.k = cstate->off_linktype.reg; in gen_geneve_offsets()
8733 s1 = new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_K); in gen_geneve_offsets()
8738 s1 = new_stmt(cstate, BPF_MISC|BPF_TAX); in gen_geneve_offsets()
8742 cstate->off_linkpl.reg = alloc_reg(cstate); in gen_geneve_offsets()
8743 cstate->off_linkpl.is_variable = 1; in gen_geneve_offsets()
8744 cstate->off_linkpl.constant_part = 0; in gen_geneve_offsets()
8746 s1 = new_stmt(cstate, BPF_STX); in gen_geneve_offsets()
8747 s1->s.k = cstate->off_linkpl.reg; in gen_geneve_offsets()
8751 cstate->off_nl = 0; in gen_geneve_offsets()
8758 gen_geneve(compiler_state_t *cstate, int vni) in gen_geneve() argument
8763 b0 = gen_geneve4(cstate, vni); in gen_geneve()
8764 b1 = gen_geneve6(cstate, vni); in gen_geneve()
8772 s = gen_geneve_offsets(cstate); in gen_geneve()
8774 b1 = gen_true(cstate); in gen_geneve()
8780 cstate->is_geneve = 1; in gen_geneve()
8788 gen_geneve_ll_check(compiler_state_t *cstate) in gen_geneve_ll_check() argument
8799 s = new_stmt(cstate, BPF_LD|BPF_MEM); in gen_geneve_ll_check()
8800 s->s.k = cstate->off_linkhdr.reg; in gen_geneve_ll_check()
8802 s1 = new_stmt(cstate, BPF_LDX|BPF_MEM); in gen_geneve_ll_check()
8803 s1->s.k = cstate->off_linkpl.reg; in gen_geneve_ll_check()
8806 b0 = new_block(cstate, BPF_JMP|BPF_JEQ|BPF_X); in gen_geneve_ll_check()
8815 gen_atmfield_code(compiler_state_t *cstate, int atmfield, bpf_int32 jvalue, in gen_atmfield_code() argument
8823 if (!cstate->is_atm) in gen_atmfield_code()
8824 bpf_error(cstate, "'vpi' supported only on raw ATM"); in gen_atmfield_code()
8825 if (cstate->off_vpi == OFFSET_NOT_SET) in gen_atmfield_code()
8827 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_vpi, BPF_B, 0xffffffff, jtype, in gen_atmfield_code()
8832 if (!cstate->is_atm) in gen_atmfield_code()
8833 bpf_error(cstate, "'vci' supported only on raw ATM"); in gen_atmfield_code()
8834 if (cstate->off_vci == OFFSET_NOT_SET) in gen_atmfield_code()
8836 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_vci, BPF_H, 0xffffffff, jtype, in gen_atmfield_code()
8841 if (cstate->off_proto == OFFSET_NOT_SET) in gen_atmfield_code()
8843 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_proto, BPF_B, 0x0f, jtype, in gen_atmfield_code()
8848 if (cstate->off_payload == OFFSET_NOT_SET) in gen_atmfield_code()
8850 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_payload + MSG_TYPE_POS, BPF_B, in gen_atmfield_code()
8855 if (!cstate->is_atm) in gen_atmfield_code()
8856 bpf_error(cstate, "'callref' supported only on raw ATM"); in gen_atmfield_code()
8857 if (cstate->off_proto == OFFSET_NOT_SET) in gen_atmfield_code()
8859 b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_proto, BPF_B, 0xffffffff, in gen_atmfield_code()
8870 gen_atmtype_abbrev(compiler_state_t *cstate, int type) in gen_atmtype_abbrev() argument
8878 if (!cstate->is_atm) in gen_atmtype_abbrev()
8879 bpf_error(cstate, "'metac' supported only on raw ATM"); in gen_atmtype_abbrev()
8880 b0 = gen_atmfield_code(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmtype_abbrev()
8881 b1 = gen_atmfield_code(cstate, A_VCI, 1, BPF_JEQ, 0); in gen_atmtype_abbrev()
8887 if (!cstate->is_atm) in gen_atmtype_abbrev()
8888 bpf_error(cstate, "'bcc' supported only on raw ATM"); in gen_atmtype_abbrev()
8889 b0 = gen_atmfield_code(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmtype_abbrev()
8890 b1 = gen_atmfield_code(cstate, A_VCI, 2, BPF_JEQ, 0); in gen_atmtype_abbrev()
8896 if (!cstate->is_atm) in gen_atmtype_abbrev()
8897 bpf_error(cstate, "'oam4sc' supported only on raw ATM"); in gen_atmtype_abbrev()
8898 b0 = gen_atmfield_code(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmtype_abbrev()
8899 b1 = gen_atmfield_code(cstate, A_VCI, 3, BPF_JEQ, 0); in gen_atmtype_abbrev()
8905 if (!cstate->is_atm) in gen_atmtype_abbrev()
8906 bpf_error(cstate, "'oam4ec' supported only on raw ATM"); in gen_atmtype_abbrev()
8907 b0 = gen_atmfield_code(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmtype_abbrev()
8908 b1 = gen_atmfield_code(cstate, A_VCI, 4, BPF_JEQ, 0); in gen_atmtype_abbrev()
8914 if (!cstate->is_atm) in gen_atmtype_abbrev()
8915 bpf_error(cstate, "'sc' supported only on raw ATM"); in gen_atmtype_abbrev()
8916 b0 = gen_atmfield_code(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmtype_abbrev()
8917 b1 = gen_atmfield_code(cstate, A_VCI, 5, BPF_JEQ, 0); in gen_atmtype_abbrev()
8923 if (!cstate->is_atm) in gen_atmtype_abbrev()
8924 bpf_error(cstate, "'ilmic' supported only on raw ATM"); in gen_atmtype_abbrev()
8925 b0 = gen_atmfield_code(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmtype_abbrev()
8926 b1 = gen_atmfield_code(cstate, A_VCI, 16, BPF_JEQ, 0); in gen_atmtype_abbrev()
8932 if (!cstate->is_atm) in gen_atmtype_abbrev()
8933 bpf_error(cstate, "'lane' supported only on raw ATM"); in gen_atmtype_abbrev()
8934 b1 = gen_atmfield_code(cstate, A_PROTOTYPE, PT_LANE, BPF_JEQ, 0); in gen_atmtype_abbrev()
8944 PUSH_LINKHDR(cstate, DLT_EN10MB, 0, in gen_atmtype_abbrev()
8945 cstate->off_payload + 2, /* Ethernet header */ in gen_atmtype_abbrev()
8947 cstate->off_linktype.constant_part = cstate->off_linkhdr.constant_part + 12; in gen_atmtype_abbrev()
8948 cstate->off_linkpl.constant_part = cstate->off_linkhdr.constant_part + 14; /* Ethernet */ in gen_atmtype_abbrev()
8949 cstate->off_nl = 0; /* Ethernet II */ in gen_atmtype_abbrev()
8950 cstate->off_nl_nosnap = 3; /* 802.3+802.2 */ in gen_atmtype_abbrev()
8955 if (!cstate->is_atm) in gen_atmtype_abbrev()
8956 bpf_error(cstate, "'llc' supported only on raw ATM"); in gen_atmtype_abbrev()
8957 b1 = gen_atmfield_code(cstate, A_PROTOTYPE, PT_LLC, BPF_JEQ, 0); in gen_atmtype_abbrev()
8958 cstate->linktype = cstate->prevlinktype; in gen_atmtype_abbrev()
8975 gen_mtp2type_abbrev(compiler_state_t *cstate, int type) in gen_mtp2type_abbrev() argument
8982 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
8983 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
8984 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
8985 bpf_error(cstate, "'fisu' supported only on MTP2"); in gen_mtp2type_abbrev()
8987 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B, 0x3f, BPF_JEQ, 0, 0); in gen_mtp2type_abbrev()
8991 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
8992 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
8993 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
8994 bpf_error(cstate, "'lssu' supported only on MTP2"); in gen_mtp2type_abbrev()
8995 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B, 0x3f, BPF_JGT, 1, 2); in gen_mtp2type_abbrev()
8996 b1 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B, 0x3f, BPF_JGT, 0, 0); in gen_mtp2type_abbrev()
9001 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
9002 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
9003 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
9004 bpf_error(cstate, "'msu' supported only on MTP2"); in gen_mtp2type_abbrev()
9005 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B, 0x3f, BPF_JGT, 0, 2); in gen_mtp2type_abbrev()
9009 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
9010 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
9011 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
9012 bpf_error(cstate, "'hfisu' supported only on MTP2_HSL"); in gen_mtp2type_abbrev()
9014 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H, 0xff80, BPF_JEQ, 0, 0); in gen_mtp2type_abbrev()
9018 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
9019 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
9020 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
9021 bpf_error(cstate, "'hlssu' supported only on MTP2_HSL"); in gen_mtp2type_abbrev()
9022 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H, 0xff80, BPF_JGT, 1, 0x0100); in gen_mtp2type_abbrev()
9023 b1 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H, 0xff80, BPF_JGT, 0, 0); in gen_mtp2type_abbrev()
9028 if ( (cstate->linktype != DLT_MTP2) && in gen_mtp2type_abbrev()
9029 (cstate->linktype != DLT_ERF) && in gen_mtp2type_abbrev()
9030 (cstate->linktype != DLT_MTP2_WITH_PHDR) ) in gen_mtp2type_abbrev()
9031 bpf_error(cstate, "'hmsu' supported only on MTP2_HSL"); in gen_mtp2type_abbrev()
9032 b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H, 0xff80, BPF_JGT, 0, 0x0100); in gen_mtp2type_abbrev()
9042 gen_mtp3field_code(compiler_state_t *cstate, int mtp3field, bpf_u_int32 jvalue, in gen_mtp3field_code() argument
9047 u_int newoff_sio = cstate->off_sio; in gen_mtp3field_code()
9048 u_int newoff_opc = cstate->off_opc; in gen_mtp3field_code()
9049 u_int newoff_dpc = cstate->off_dpc; in gen_mtp3field_code()
9050 u_int newoff_sls = cstate->off_sls; in gen_mtp3field_code()
9059 if (cstate->off_sio == OFFSET_NOT_SET) in gen_mtp3field_code()
9060 bpf_error(cstate, "'sio' supported only on SS7"); in gen_mtp3field_code()
9063 bpf_error(cstate, "sio value %u too big; max value = 255", in gen_mtp3field_code()
9065 b0 = gen_ncmp(cstate, OR_PACKET, newoff_sio, BPF_B, 0xffffffff, in gen_mtp3field_code()
9072 if (cstate->off_opc == OFFSET_NOT_SET) in gen_mtp3field_code()
9073 bpf_error(cstate, "'opc' supported only on SS7"); in gen_mtp3field_code()
9076 bpf_error(cstate, "opc value %u too big; max value = 16383", in gen_mtp3field_code()
9087 b0 = gen_ncmp(cstate, OR_PACKET, newoff_opc, BPF_W, 0x00c0ff0f, in gen_mtp3field_code()
9096 if (cstate->off_dpc == OFFSET_NOT_SET) in gen_mtp3field_code()
9097 bpf_error(cstate, "'dpc' supported only on SS7"); in gen_mtp3field_code()
9100 bpf_error(cstate, "dpc value %u too big; max value = 16383", in gen_mtp3field_code()
9109 b0 = gen_ncmp(cstate, OR_PACKET, newoff_dpc, BPF_W, 0xff3f0000, in gen_mtp3field_code()
9116 if (cstate->off_sls == OFFSET_NOT_SET) in gen_mtp3field_code()
9117 bpf_error(cstate, "'sls' supported only on SS7"); in gen_mtp3field_code()
9120 bpf_error(cstate, "sls value %u too big; max value = 15", in gen_mtp3field_code()
9125 b0 = gen_ncmp(cstate, OR_PACKET, newoff_sls, BPF_B, 0xf0, in gen_mtp3field_code()
9136 gen_msg_abbrev(compiler_state_t *cstate, int type) in gen_msg_abbrev() argument
9147 b1 = gen_atmfield_code(cstate, A_MSGTYPE, SETUP, BPF_JEQ, 0); in gen_msg_abbrev()
9151 b1 = gen_atmfield_code(cstate, A_MSGTYPE, CALL_PROCEED, BPF_JEQ, 0); in gen_msg_abbrev()
9155 b1 = gen_atmfield_code(cstate, A_MSGTYPE, CONNECT, BPF_JEQ, 0); in gen_msg_abbrev()
9159 b1 = gen_atmfield_code(cstate, A_MSGTYPE, CONNECT_ACK, BPF_JEQ, 0); in gen_msg_abbrev()
9163 b1 = gen_atmfield_code(cstate, A_MSGTYPE, RELEASE, BPF_JEQ, 0); in gen_msg_abbrev()
9167 b1 = gen_atmfield_code(cstate, A_MSGTYPE, RELEASE_DONE, BPF_JEQ, 0); in gen_msg_abbrev()
9177 gen_atmmulti_abbrev(compiler_state_t *cstate, int type) in gen_atmmulti_abbrev() argument
9184 if (!cstate->is_atm) in gen_atmmulti_abbrev()
9185 bpf_error(cstate, "'oam' supported only on raw ATM"); in gen_atmmulti_abbrev()
9186 b1 = gen_atmmulti_abbrev(cstate, A_OAMF4); in gen_atmmulti_abbrev()
9190 if (!cstate->is_atm) in gen_atmmulti_abbrev()
9191 bpf_error(cstate, "'oamf4' supported only on raw ATM"); in gen_atmmulti_abbrev()
9193 b0 = gen_atmfield_code(cstate, A_VCI, 3, BPF_JEQ, 0); in gen_atmmulti_abbrev()
9194 b1 = gen_atmfield_code(cstate, A_VCI, 4, BPF_JEQ, 0); in gen_atmmulti_abbrev()
9196 b0 = gen_atmfield_code(cstate, A_VPI, 0, BPF_JEQ, 0); in gen_atmmulti_abbrev()
9205 if (!cstate->is_atm) in gen_atmmulti_abbrev()
9206 bpf_error(cstate, "'connectmsg' supported only on raw ATM"); in gen_atmmulti_abbrev()
9207 b0 = gen_msg_abbrev(cstate, A_SETUP); in gen_atmmulti_abbrev()
9208 b1 = gen_msg_abbrev(cstate, A_CALLPROCEED); in gen_atmmulti_abbrev()
9210 b0 = gen_msg_abbrev(cstate, A_CONNECT); in gen_atmmulti_abbrev()
9212 b0 = gen_msg_abbrev(cstate, A_CONNECTACK); in gen_atmmulti_abbrev()
9214 b0 = gen_msg_abbrev(cstate, A_RELEASE); in gen_atmmulti_abbrev()
9216 b0 = gen_msg_abbrev(cstate, A_RELEASE_DONE); in gen_atmmulti_abbrev()
9218 b0 = gen_atmtype_abbrev(cstate, A_SC); in gen_atmmulti_abbrev()
9223 if (!cstate->is_atm) in gen_atmmulti_abbrev()
9224 bpf_error(cstate, "'metaconnect' supported only on raw ATM"); in gen_atmmulti_abbrev()
9225 b0 = gen_msg_abbrev(cstate, A_SETUP); in gen_atmmulti_abbrev()
9226 b1 = gen_msg_abbrev(cstate, A_CALLPROCEED); in gen_atmmulti_abbrev()
9228 b0 = gen_msg_abbrev(cstate, A_CONNECT); in gen_atmmulti_abbrev()
9230 b0 = gen_msg_abbrev(cstate, A_RELEASE); in gen_atmmulti_abbrev()
9232 b0 = gen_msg_abbrev(cstate, A_RELEASE_DONE); in gen_atmmulti_abbrev()
9234 b0 = gen_atmtype_abbrev(cstate, A_METAC); in gen_atmmulti_abbrev()