Deleted Added
sdiff udiff text old ( 75110 ) new ( 98533 )
full compact
1/*#define CHASE_CHAIN*/
2/*
3 * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998
4 * The Regents of the University of California. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that: (1) source code distributions
8 * retain the above copyright notice and this paragraph in its entirety, (2)

--- 5 unchanged lines hidden (view full) ---

14 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
15 * the University nor the names of its contributors may be used to endorse
16 * or promote products derived from this software without specific prior
17 * written permission.
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 *
22 * $FreeBSD: head/contrib/libpcap/gencode.c 75110 2001-04-03 04:32:48Z fenner $
23 */
24#ifndef lint
25static const char rcsid[] =
26 "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.140.2.1 2001/01/14 06:48:35 guy Exp $ (LBL)";
27#endif
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#include <sys/types.h>
34#include <sys/socket.h>

--- 13 unchanged lines hidden (view full) ---

48#include <memory.h>
49#include <setjmp.h>
50#include <stdarg.h>
51
52#include "pcap-int.h"
53
54#include "ethertype.h"
55#include "nlpid.h"
56#include "gencode.h"
57#include "ppp.h"
58#include "sll.h"
59#include <pcap-namedb.h>
60#ifdef INET6
61#include <netdb.h>
62#include <sys/socket.h>
63#endif /*INET6*/
64
65#define LLC_SNAP_LSAP 0xaa
66#define LLC_ISO_LSAP 0xfe
67
68#undef ETHERMTU
69#define ETHERMTU 1500
70
71#ifdef HAVE_OS_PROTO_H
72#include "os-proto.h"
73#endif
74
75#define JMP(c) ((c)|BPF_JMP|BPF_K)
76
77/* Locals */
78static jmp_buf top_ctx;
79static pcap_t *bpf_pcap;
80
81/* XXX */
82#ifdef PCAP_FDDIPAD
83int pcap_fddipad = PCAP_FDDIPAD;
84#else
85int pcap_fddipad;
86#endif
87
88/* VARARGS */

--- 52 unchanged lines hidden (view full) ---

141static inline struct block *gen_true(void);
142static inline struct block *gen_false(void);
143static struct block *gen_linktype(int);
144static struct block *gen_snap(bpf_u_int32, bpf_u_int32, u_int);
145static struct block *gen_hostop(bpf_u_int32, bpf_u_int32, int, int, u_int, u_int);
146#ifdef INET6
147static struct block *gen_hostop6(struct in6_addr *, struct in6_addr *, int, int, u_int, u_int);
148#endif
149static struct block *gen_ehostop(const u_char *, int);
150static struct block *gen_fhostop(const u_char *, int);
151static struct block *gen_thostop(const u_char *, int);
152static struct block *gen_dnhostop(bpf_u_int32, int, u_int);
153static struct block *gen_host(bpf_u_int32, bpf_u_int32, int, int);
154#ifdef INET6
155static struct block *gen_host6(struct in6_addr *, struct in6_addr *, int, int);
156#endif

--- 388 unchanged lines hidden (view full) ---

545static int linktype;
546
547static void
548init_linktype(type)
549 int type;
550{
551 linktype = type;
552
553 switch (type) {
554
555 case DLT_EN10MB:
556 off_linktype = 12;
557 off_nl = 14;
558 return;
559
560 case DLT_SLIP:
561 /*
562 * SLIP doesn't have a link level type. The 16 byte

--- 12 unchanged lines hidden (view full) ---

575
576 case DLT_NULL:
577 case DLT_LOOP:
578 off_linktype = 0;
579 off_nl = 4;
580 return;
581
582 case DLT_PPP:
583 case DLT_C_HDLC:
584 case DLT_PPP_SERIAL:
585 off_linktype = 2;
586 off_nl = 4;
587 return;
588
589 case DLT_PPP_BSDOS:
590 off_linktype = 5;
591 off_nl = 24;
592 return;
593
594 case DLT_FDDI:
595 /*
596 * FDDI doesn't really have a link-level type field.
597 * We assume that SSAP = SNAP is being used and pick
598 * out the encapsulated Ethernet type.
599 *
600 * XXX - should we generate code to check for SNAP?
601 */
602 off_linktype = 19;
603#ifdef PCAP_FDDIPAD
604 off_linktype += pcap_fddipad;
605#endif
606 off_nl = 21;
607#ifdef PCAP_FDDIPAD
608 off_nl += pcap_fddipad;
609#endif
610 return;
611
612 case DLT_IEEE802:
613 /*
614 * Token Ring doesn't really have a link-level type field.
615 * We assume that SSAP = SNAP is being used and pick
616 * out the encapsulated Ethernet type.
617 *
618 * XXX - should we generate code to check for SNAP?
619 *
620 * XXX - the header is actually variable-length.
621 * Some various Linux patched versions gave 38
622 * as "off_linktype" and 40 as "off_nl"; however,
623 * if a token ring packet has *no* routing
624 * information, i.e. is not source-routed, the correct
625 * values are 20 and 22, as they are in the vanilla code.
626 *
627 * A packet is source-routed iff the uppermost bit
628 * of the first byte of the source address, at an
629 * offset of 8, has the uppermost bit set. If the
630 * packet is source-routed, the total number of bytes
631 * of routing information is 2 plus bits 0x1F00 of
632 * the 16-bit value at an offset of 14 (shifted right
633 * 8 - figure out which byte that is).
634 */
635 off_linktype = 20;
636 off_nl = 22;
637 return;
638
639 case DLT_ATM_RFC1483:
640 /*
641 * assume routed, non-ISO PDUs
642 * (i.e., LLC = 0xAA-AA-03, OUT = 0x00-00-00)
643 */
644 off_linktype = 6;
645 off_nl = 8;
646 return;

--- 7 unchanged lines hidden (view full) ---

654 off_linktype = 6;
655 off_nl = 8;
656 return;
657
658 case DLT_LINUX_SLL: /* fake header for Linux cooked socket */
659 off_linktype = 14;
660 off_nl = 16;
661 return;
662 }
663 bpf_error("unknown data link type %d", linktype);
664 /* NOTREACHED */
665}
666
667static struct block *
668gen_uncond(rsense)
669 int rsense;

--- 30 unchanged lines hidden (view full) ---

700((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))
701
702static struct block *
703gen_linktype(proto)
704 register int proto;
705{
706 struct block *b0, *b1;
707
708 /* If we're not using encapsulation, we're done */
709 if (off_linktype == -1)
710 return gen_true();
711
712 switch (linktype) {
713
714 case DLT_EN10MB:
715 /*
716 * XXX - handle other LLC-encapsulated protocols here
717 * (IPX, OSI)?
718 */
719 switch (proto) {
720
721 case LLC_ISO_LSAP:
722 /*
723 * OSI protocols always use 802.2 encapsulation.
724 */
725 b0 = gen_cmp_gt(off_linktype, BPF_H, ETHERMTU);
726 gen_not(b0);
727 b1 = gen_cmp(off_linktype + 2, BPF_H, (bpf_int32)
728 ((LLC_ISO_LSAP << 8) | LLC_ISO_LSAP));
729 gen_and(b0, b1);
730 return b1;
731
732 case ETHERTYPE_ATALK:
733 case ETHERTYPE_AARP:
734 /*
735 * EtherTalk (AppleTalk protocols on Ethernet link
736 * layer) may use 802.2 encapsulation.
737 */
738
739 /*

--- 25 unchanged lines hidden (view full) ---

765 * Check for Ethernet encapsulation (Ethertalk
766 * phase 1?); we just check for the Ethernet
767 * protocol type.
768 */
769 b0 = gen_cmp(off_linktype, BPF_H, (bpf_int32)proto);
770
771 gen_or(b0, b1);
772 return b1;
773 }
774 break;
775
776 case DLT_SLIP:
777 return gen_false();
778
779 case DLT_PPP:
780 case DLT_PPP_SERIAL:
781 /*
782 * We use Ethernet protocol types inside libpcap;
783 * map them to the corresponding PPP protocol types.
784 */
785 switch (proto) {
786
787 case ETHERTYPE_IP:
788 proto = PPP_IP; /* XXX was 0x21 */

--- 12 unchanged lines hidden (view full) ---

801 case ETHERTYPE_ATALK:
802 proto = PPP_APPLE;
803 break;
804
805 case ETHERTYPE_NS:
806 proto = PPP_NS;
807 break;
808
809 case LLC_ISO_LSAP:
810 proto = PPP_OSI;
811 break;
812 }
813 break;
814
815 case DLT_PPP_BSDOS:
816 /*
817 * We use Ethernet protocol types inside libpcap;
818 * map them to the corresponding PPP protocol types.
819 */

--- 21 unchanged lines hidden (view full) ---

841 case ETHERTYPE_ATALK:
842 proto = PPP_APPLE;
843 break;
844
845 case ETHERTYPE_NS:
846 proto = PPP_NS;
847 break;
848
849 case LLC_ISO_LSAP:
850 proto = PPP_OSI;
851 break;
852 }
853 break;
854
855 case DLT_NULL:
856 case DLT_LOOP:
857 /*
858 * For DLT_NULL, the link-layer header is a 32-bit
859 * word containing an AF_ value in *host* byte order.

--- 48 unchanged lines hidden (view full) ---

908 * generate code to compare against the result.
909 */
910 if (bpf_pcap->sf.rfile != NULL &&
911 bpf_pcap->sf.swapped)
912 proto = SWAPLONG(proto);
913 proto = htonl(proto);
914 }
915 return (gen_cmp(0, BPF_W, (bpf_int32)proto));
916 }
917 return gen_cmp(off_linktype, BPF_H, (bpf_int32)proto);
918}
919
920/*
921 * Check for an LLC SNAP packet with a given organization code and
922 * protocol type; we check the entire contents of the 802.2 LLC and
923 * snap headers, checking for DSAP and SSAP of SNAP and a control
924 * field of 0x03 in the LLC header, and for the specified organization
925 * code and protocol type in the SNAP header.
926 */
927static struct block *
928gen_snap(orgcode, ptype, offset)
929 bpf_u_int32 orgcode;
930 bpf_u_int32 ptype;
931 u_int offset;
932{
933 u_char snapblock[8];
934
935 snapblock[0] = LLC_SNAP_LSAP; /* DSAP = SNAP */
936 snapblock[1] = LLC_SNAP_LSAP; /* SSAP = SNAP */
937 snapblock[2] = 0x03; /* control = UI */
938 snapblock[3] = (orgcode >> 16); /* upper 8 bits of organization code */
939 snapblock[4] = (orgcode >> 8); /* middle 8 bits of organization code */
940 snapblock[5] = (orgcode >> 0); /* lower 8 bits of organization code */
941 snapblock[6] = (ptype >> 8); /* upper 8 bits of protocol type */
942 snapblock[7] = (ptype >> 0); /* lower 8 bits of protocol type */
943 return gen_bcmp(offset, 8, snapblock);
944}

--- 323 unchanged lines hidden (view full) ---

1268
1269 case Q_ARP:
1270 return gen_hostop(addr, mask, dir, ETHERTYPE_ARP,
1271 off_nl + 14, off_nl + 24);
1272
1273 case Q_TCP:
1274 bpf_error("'tcp' modifier applied to host");
1275
1276 case Q_UDP:
1277 bpf_error("'udp' modifier applied to host");
1278
1279 case Q_ICMP:
1280 bpf_error("'icmp' modifier applied to host");
1281
1282 case Q_IGMP:
1283 bpf_error("'igmp' modifier applied to host");
1284
1285 case Q_IGRP:
1286 bpf_error("'igrp' modifier applied to host");
1287
1288 case Q_PIM:
1289 bpf_error("'pim' modifier applied to host");
1290
1291 case Q_ATALK:
1292 bpf_error("ATALK host filtering not implemented");
1293
1294 case Q_AARP:
1295 bpf_error("AARP host filtering not implemented");
1296
1297 case Q_DECNET:
1298 return gen_dnhostop(addr, dir, off_nl);

--- 31 unchanged lines hidden (view full) ---

1330 bpf_error("'esis' modifier applied to host");
1331
1332 case Q_ISIS:
1333 bpf_error("'isis' modifier applied to host");
1334
1335 case Q_CLNP:
1336 bpf_error("'clnp' modifier applied to host");
1337
1338 default:
1339 abort();
1340 }
1341 /* NOTREACHED */
1342}
1343
1344#ifdef INET6
1345static struct block *

--- 12 unchanged lines hidden (view full) ---

1358 bpf_error("'ip' modifier applied to ip6 host");
1359
1360 case Q_RARP:
1361 bpf_error("'rarp' modifier applied to ip6 host");
1362
1363 case Q_ARP:
1364 bpf_error("'arp' modifier applied to ip6 host");
1365
1366 case Q_TCP:
1367 bpf_error("'tcp' modifier applied to host");
1368
1369 case Q_UDP:
1370 bpf_error("'udp' modifier applied to host");
1371
1372 case Q_ICMP:
1373 bpf_error("'icmp' modifier applied to host");
1374
1375 case Q_IGMP:
1376 bpf_error("'igmp' modifier applied to host");
1377
1378 case Q_IGRP:
1379 bpf_error("'igrp' modifier applied to host");
1380
1381 case Q_PIM:
1382 bpf_error("'pim' modifier applied to host");
1383
1384 case Q_ATALK:
1385 bpf_error("ATALK host filtering not implemented");
1386
1387 case Q_AARP:
1388 bpf_error("AARP host filtering not implemented");
1389
1390 case Q_DECNET:
1391 bpf_error("'decnet' modifier applied to ip6 host");

--- 30 unchanged lines hidden (view full) ---

1422 bpf_error("'esis' modifier applied to host");
1423
1424 case Q_ISIS:
1425 bpf_error("'isis' modifier applied to host");
1426
1427 case Q_CLNP:
1428 bpf_error("'clnp' modifier applied to host");
1429
1430 default:
1431 abort();
1432 }
1433 /* NOTREACHED */
1434}
1435#endif /*INET6*/
1436
1437#ifndef INET6

--- 45 unchanged lines hidden (view full) ---

1483{
1484#ifdef INET6
1485 struct block *b0;
1486#endif
1487 struct block *b1;
1488
1489 switch (proto) {
1490
1491 case Q_TCP:
1492 b1 = gen_proto(IPPROTO_TCP, Q_IP, Q_DEFAULT);
1493#ifdef INET6
1494 b0 = gen_proto(IPPROTO_TCP, Q_IPV6, Q_DEFAULT);
1495 gen_or(b0, b1);
1496#endif
1497 break;
1498

--- 31 unchanged lines hidden (view full) ---

1530 case Q_PIM:
1531 b1 = gen_proto(IPPROTO_PIM, Q_IP, Q_DEFAULT);
1532#ifdef INET6
1533 b0 = gen_proto(IPPROTO_PIM, Q_IPV6, Q_DEFAULT);
1534 gen_or(b0, b1);
1535#endif
1536 break;
1537
1538 case Q_IP:
1539 b1 = gen_linktype(ETHERTYPE_IP);
1540 break;
1541
1542 case Q_ARP:
1543 b1 = gen_linktype(ETHERTYPE_ARP);
1544 break;
1545

--- 63 unchanged lines hidden (view full) ---

1609 b1 = gen_proto(IPPROTO_ESP, Q_IP, Q_DEFAULT);
1610#ifdef INET6
1611 b0 = gen_proto(IPPROTO_ESP, Q_IPV6, Q_DEFAULT);
1612 gen_or(b0, b1);
1613#endif
1614 break;
1615
1616 case Q_ISO:
1617 b1 = gen_linktype(LLC_ISO_LSAP);
1618 break;
1619
1620 case Q_ESIS:
1621 b1 = gen_proto(ISO9542_ESIS, Q_ISO, Q_DEFAULT);
1622 break;
1623
1624 case Q_ISIS:
1625 b1 = gen_proto(ISO10589_ISIS, Q_ISO, Q_DEFAULT);
1626 break;
1627
1628 case Q_CLNP:
1629 b1 = gen_proto(ISO8473_CLNP, Q_ISO, Q_DEFAULT);
1630 break;
1631
1632 default:
1633 abort();
1634 }
1635 return b1;
1636}
1637
1638static struct block *
1639gen_ipfrag()

--- 93 unchanged lines hidden (view full) ---

1733 struct block *b0, *b1, *tmp;
1734
1735 /* ether proto ip */
1736 b0 = gen_linktype(ETHERTYPE_IP);
1737
1738 switch (ip_proto) {
1739 case IPPROTO_UDP:
1740 case IPPROTO_TCP:
1741 b1 = gen_portop(port, ip_proto, dir);
1742 break;
1743
1744 case PROTO_UNDEF:
1745 tmp = gen_portop(port, IPPROTO_TCP, dir);
1746 b1 = gen_portop(port, IPPROTO_UDP, dir);
1747 gen_or(tmp, b1);
1748 break;
1749
1750 default:
1751 abort();
1752 }
1753 gen_and(b0, b1);
1754 return b1;
1755}

--- 47 unchanged lines hidden (view full) ---

1803 struct block *b0, *b1, *tmp;
1804
1805 /* ether proto ip */
1806 b0 = gen_linktype(ETHERTYPE_IPV6);
1807
1808 switch (ip_proto) {
1809 case IPPROTO_UDP:
1810 case IPPROTO_TCP:
1811 b1 = gen_portop6(port, ip_proto, dir);
1812 break;
1813
1814 case PROTO_UNDEF:
1815 tmp = gen_portop6(port, IPPROTO_TCP, dir);
1816 b1 = gen_portop6(port, IPPROTO_UDP, dir);
1817 gen_or(tmp, b1);
1818 break;
1819
1820 default:
1821 abort();
1822 }
1823 gen_and(b0, b1);
1824 return b1;
1825}

--- 5 unchanged lines hidden (view full) ---

1831 register int proto;
1832{
1833 register int v;
1834
1835 switch (proto) {
1836
1837 case Q_DEFAULT:
1838 case Q_IP:
1839 v = pcap_nametoproto(name);
1840 if (v == PROTO_UNDEF)
1841 bpf_error("unknown ip proto '%s'", name);
1842 break;
1843
1844 case Q_LINK:
1845 /* XXX should look up h/w protocol type based on linktype */
1846 v = pcap_nametoeproto(name);

--- 348 unchanged lines hidden (view full) ---

2195 b1 = gen_cmp(off_nl + 9, BPF_B, (bpf_int32)v);
2196#else
2197 b1 = gen_protochain(v, Q_IP);
2198#endif
2199 gen_and(b0, b1);
2200 return b1;
2201
2202 case Q_ISO:
2203 b0 = gen_linktype(LLC_ISO_LSAP);
2204 b1 = gen_cmp(off_nl + 3, BPF_B, (long)v);
2205 gen_and(b0, b1);
2206 return b1;
2207
2208 case Q_ARP:
2209 bpf_error("arp does not encapsulate another protocol");
2210 /* NOTREACHED */
2211

--- 31 unchanged lines hidden (view full) ---

2243 case Q_UDP:
2244 bpf_error("'udp proto' is bogus");
2245 /* NOTREACHED */
2246
2247 case Q_TCP:
2248 bpf_error("'tcp proto' is bogus");
2249 /* NOTREACHED */
2250
2251 case Q_ICMP:
2252 bpf_error("'icmp proto' is bogus");
2253 /* NOTREACHED */
2254
2255 case Q_IGMP:
2256 bpf_error("'igmp proto' is bogus");
2257 /* NOTREACHED */
2258
2259 case Q_IGRP:
2260 bpf_error("'igrp proto' is bogus");
2261 /* NOTREACHED */
2262
2263 case Q_PIM:
2264 bpf_error("'pim proto' is bogus");
2265 /* NOTREACHED */
2266
2267#ifdef INET6
2268 case Q_IPV6:
2269 b0 = gen_linktype(ETHERTYPE_IPV6);
2270#ifndef CHASE_CHAIN
2271 b1 = gen_cmp(off_nl + 6, BPF_B, (bpf_int32)v);
2272#else
2273 b1 = gen_protochain(v, Q_IPV6);
2274#endif

--- 5 unchanged lines hidden (view full) ---

2280#endif /* INET6 */
2281
2282 case Q_AH:
2283 bpf_error("'ah proto' is bogus");
2284
2285 case Q_ESP:
2286 bpf_error("'ah proto' is bogus");
2287
2288 default:
2289 abort();
2290 /* NOTREACHED */
2291 }
2292 /* NOTREACHED */
2293}
2294
2295struct block *

--- 37 unchanged lines hidden (view full) ---

2333 if (proto == Q_LINK) {
2334 switch (linktype) {
2335
2336 case DLT_EN10MB:
2337 eaddr = pcap_ether_hostton(name);
2338 if (eaddr == NULL)
2339 bpf_error(
2340 "unknown ether host '%s'", name);
2341 return gen_ehostop(eaddr, dir);
2342
2343 case DLT_FDDI:
2344 eaddr = pcap_ether_hostton(name);
2345 if (eaddr == NULL)
2346 bpf_error(
2347 "unknown FDDI host '%s'", name);
2348 return gen_fhostop(eaddr, dir);
2349
2350 case DLT_IEEE802:
2351 eaddr = pcap_ether_hostton(name);
2352 if (eaddr == NULL)
2353 bpf_error(
2354 "unknown token ring host '%s'", name);
2355 return gen_thostop(eaddr, dir);
2356
2357 default:
2358 bpf_error(
2359 "only ethernet/FDDI/token ring supports link-level host name");
2360 break;
2361 }
2362 } else if (proto == Q_DECNET) {
2363 unsigned short dn_addr = __pcap_nametodnaddr(name);

--- 44 unchanged lines hidden (view full) ---

2408 if (tproto6 == Q_IP)
2409 continue;
2410
2411 sin6 = (struct sockaddr_in6 *)
2412 res->ai_addr;
2413 tmp = gen_host6(&sin6->sin6_addr,
2414 &mask128, tproto6, dir);
2415 break;
2416 }
2417 if (b)
2418 gen_or(b, tmp);
2419 b = tmp;
2420 }
2421 freeaddrinfo(res0);
2422 if (b == NULL) {
2423 bpf_error("unknown host '%s'%s", name,
2424 (proto == Q_DEFAULT)
2425 ? ""
2426 : " for specified address family");
2427 }
2428 return b;
2429#endif /*INET6*/
2430 }
2431
2432 case Q_PORT:
2433 if (proto != Q_DEFAULT && proto != Q_UDP && proto != Q_TCP)
2434 bpf_error("illegal qualifier of 'port'");
2435 if (pcap_nametoport(name, &port, &real_proto) == 0)
2436 bpf_error("unknown port '%s'", name);
2437 if (proto == Q_UDP) {
2438 if (real_proto == IPPROTO_TCP)
2439 bpf_error("port '%s' is tcp", name);
2440 else
2441 /* override PROTO_UNDEF */
2442 real_proto = IPPROTO_UDP;
2443 }
2444 if (proto == Q_TCP) {
2445 if (real_proto == IPPROTO_UDP)
2446 bpf_error("port '%s' is udp", name);
2447 else
2448 /* override PROTO_UNDEF */
2449 real_proto = IPPROTO_TCP;
2450 }
2451#ifndef INET6
2452 return gen_port(port, real_proto, dir);
2453#else
2454 {
2455 struct block *b;
2456 b = gen_port(port, real_proto, dir);
2457 gen_or(gen_port6(port, real_proto, dir), b);
2458 return b;

--- 4 unchanged lines hidden (view full) ---

2463#ifndef INET6
2464 eaddr = pcap_ether_hostton(name);
2465 if (eaddr == NULL)
2466 bpf_error("unknown ether host: %s", name);
2467
2468 alist = pcap_nametoaddr(name);
2469 if (alist == NULL || *alist == NULL)
2470 bpf_error("unknown host '%s'", name);
2471 return gen_gateway(eaddr, alist, proto, dir);
2472#else
2473 bpf_error("'gateway' not supported in this configuration");
2474#endif /*INET6*/
2475
2476 case Q_PROTO:
2477 real_proto = lookup_proto(name, proto);
2478 if (real_proto >= 0)
2479 return gen_proto(real_proto, proto, dir);

--- 100 unchanged lines hidden (view full) ---

2580 return gen_host(v, mask, proto, dir);
2581 }
2582
2583 case Q_PORT:
2584 if (proto == Q_UDP)
2585 proto = IPPROTO_UDP;
2586 else if (proto == Q_TCP)
2587 proto = IPPROTO_TCP;
2588 else if (proto == Q_DEFAULT)
2589 proto = PROTO_UNDEF;
2590 else
2591 bpf_error("illegal qualifier of 'port'");
2592
2593#ifndef INET6
2594 return gen_port((int)v, proto, dir);
2595#else

--- 46 unchanged lines hidden (view full) ---

2642 if (!res)
2643 bpf_error("invalid ip6 address %s", s1);
2644 if (res->ai_next)
2645 bpf_error("%s resolved to multiple address", s1);
2646 addr = &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr;
2647
2648 if (sizeof(mask) * 8 < masklen)
2649 bpf_error("mask length must be <= %u", (unsigned int)(sizeof(mask) * 8));
2650 memset(&mask, 0xff, masklen / 8);
2651 if (masklen % 8) {
2652 mask.s6_addr[masklen / 8] =
2653 (0xff << (8 - masklen % 8)) & 0xff;
2654 }
2655
2656 a = (u_int32_t *)addr;
2657 m = (u_int32_t *)&mask;

--- 134 unchanged lines hidden (view full) ---

2792 sappend(index->s, s);
2793
2794 b = gen_proto_abbrev(proto);
2795 if (index->b)
2796 gen_and(index->b, b);
2797 index->b = b;
2798 break;
2799
2800 case Q_TCP:
2801 case Q_UDP:
2802 case Q_ICMP:
2803 case Q_IGMP:
2804 case Q_IGRP:
2805 case Q_PIM:
2806 s = new_stmt(BPF_LDX|BPF_MSH|BPF_B);
2807 s->s.k = off_nl;
2808 sappend(s, xfer_to_a(index));
2809 sappend(s, new_stmt(BPF_ALU|BPF_ADD|BPF_X));
2810 sappend(s, new_stmt(BPF_MISC|BPF_TAX));
2811 sappend(s, tmp = new_stmt(BPF_LD|BPF_IND|size));
2812 tmp->s.k = off_nl;
2813 sappend(index->s, s);

--- 258 unchanged lines hidden (view full) ---

3072 s->s.k = val;
3073 b = new_block(JMP(BPF_JEQ));
3074 b->stmts = s;
3075 gen_not(b);
3076
3077 return b;
3078}
3079
3080struct block *
3081gen_broadcast(proto)
3082 int proto;
3083{
3084 bpf_u_int32 hostmask;
3085 struct block *b0, *b1, *b2;
3086 static u_char ebroadcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
3087
3088 switch (proto) {
3089
3090 case Q_DEFAULT:
3091 case Q_LINK:
3092 if (linktype == DLT_EN10MB)
3093 return gen_ehostop(ebroadcast, Q_DST);
3094 if (linktype == DLT_FDDI)
3095 return gen_fhostop(ebroadcast, Q_DST);
3096 if (linktype == DLT_IEEE802)
3097 return gen_thostop(ebroadcast, Q_DST);
3098 bpf_error("not a broadcast link");
3099 break;

--- 17 unchanged lines hidden (view full) ---

3117{
3118 register struct block *b0, *b1;
3119 register struct slist *s;
3120
3121 switch (proto) {
3122
3123 case Q_DEFAULT:
3124 case Q_LINK:
3125 if (linktype == DLT_EN10MB) {
3126 /* ether[0] & 1 != 0 */
3127 s = new_stmt(BPF_LD|BPF_B|BPF_ABS);
3128 s->s.k = 0;
3129 b0 = new_block(JMP(BPF_JSET));
3130 b0->s.k = 1;
3131 b0->stmts = s;
3132 return b0;

--- 61 unchanged lines hidden (view full) ---

3194 bpf_error("inbound/outbound not supported on linktype %d\n",
3195 linktype);
3196 b0 = NULL;
3197 /* NOTREACHED */
3198 }
3199 return (b0);
3200}
3201
3202/*
3203 * support IEEE 802.1Q VLAN trunk over ethernet
3204 */
3205struct block *
3206gen_vlan(vlan_num)
3207 int vlan_num;
3208{
3209 static u_int orig_linktype = -1, orig_nl = -1;
3210 struct block *b0;
3211
3212 /*
3213 * Change the offsets to point to the type and data fields within
3214 * the VLAN packet. This is somewhat of a kludge.
3215 */
3216 if (orig_nl == (u_int)-1) {
3217 orig_linktype = off_linktype; /* save original values */

--- 30 unchanged lines hidden ---