Deleted Added
full compact
gencode.c (75110) gencode.c (98533)
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 *
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 $
22 * $FreeBSD: head/contrib/libpcap/gencode.c 98533 2002-06-21 01:38:14Z fenner $
23 */
24#ifndef lint
25static const char rcsid[] =
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)";
26 "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.160 2001/11/30 07:25:48 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"
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 "llc.h"
56#include "gencode.h"
57#include "ppp.h"
58#include "sll.h"
57#include "gencode.h"
58#include "ppp.h"
59#include "sll.h"
60#include "arcnet.h"
59#include <pcap-namedb.h>
60#ifdef INET6
61#include <netdb.h>
62#include <sys/socket.h>
63#endif /*INET6*/
64
61#include <pcap-namedb.h>
62#ifdef INET6
63#include <netdb.h>
64#include <sys/socket.h>
65#endif /*INET6*/
66
65#define LLC_SNAP_LSAP 0xaa
66#define LLC_ISO_LSAP 0xfe
67
68#undef ETHERMTU
69#define ETHERMTU 1500
70
67#undef ETHERMTU
68#define ETHERMTU 1500
69
70#ifndef IPPROTO_SCTP
71#define IPPROTO_SCTP 132
72#endif
73
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
74#ifdef HAVE_OS_PROTO_H
75#include "os-proto.h"
76#endif
77
78#define JMP(c) ((c)|BPF_JMP|BPF_K)
79
80/* Locals */
81static jmp_buf top_ctx;
82static pcap_t *bpf_pcap;
83
84/* Hack for updating VLAN offsets. */
85static u_int orig_linktype = -1, orig_nl = -1;
86
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
87/* XXX */
88#ifdef PCAP_FDDIPAD
89int pcap_fddipad = PCAP_FDDIPAD;
90#else
91int pcap_fddipad;
92#endif
93
94/* VARARGS */

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

147static inline struct block *gen_true(void);
148static inline struct block *gen_false(void);
149static struct block *gen_linktype(int);
150static struct block *gen_snap(bpf_u_int32, bpf_u_int32, u_int);
151static struct block *gen_hostop(bpf_u_int32, bpf_u_int32, int, int, u_int, u_int);
152#ifdef INET6
153static struct block *gen_hostop6(struct in6_addr *, struct in6_addr *, int, int, u_int, u_int);
154#endif
155static struct block *gen_ahostop(const u_char *, int);
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
156static struct block *gen_ehostop(const u_char *, int);
157static struct block *gen_fhostop(const u_char *, int);
158static struct block *gen_thostop(const u_char *, int);
159static struct block *gen_dnhostop(bpf_u_int32, int, u_int);
160static struct block *gen_host(bpf_u_int32, bpf_u_int32, int, int);
161#ifdef INET6
162static struct block *gen_host6(struct in6_addr *, struct in6_addr *, int, int);
163#endif

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

552static int linktype;
553
554static void
555init_linktype(type)
556 int type;
557{
558 linktype = type;
559
560 orig_linktype = -1;
561 orig_nl = -1;
562
553 switch (type) {
554
563 switch (type) {
564
565 case DLT_ARCNET:
566 off_linktype = 2;
567 off_nl = 6; /* XXX in reality, variable! */
568 return;
569
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:
570 case DLT_EN10MB:
571 off_linktype = 12;
572 off_nl = 14;
573 return;
574
575 case DLT_SLIP:
576 /*
577 * SLIP doesn't have a link level type. The 16 byte

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

590
591 case DLT_NULL:
592 case DLT_LOOP:
593 off_linktype = 0;
594 off_nl = 4;
595 return;
596
597 case DLT_PPP:
583 case DLT_C_HDLC:
584 case DLT_PPP_SERIAL:
598 case DLT_C_HDLC: /* BSD/OS Cisco HDLC */
599 case DLT_PPP_SERIAL: /* NetBSD sync/async serial PPP */
585 off_linktype = 2;
586 off_nl = 4;
587 return;
588
600 off_linktype = 2;
601 off_nl = 4;
602 return;
603
604 case DLT_PPP_ETHER:
605 /*
606 * This does no include the Ethernet header, and
607 * only covers session state.
608 */
609 off_linktype = 6;
610 off_nl = 8;
611 return;
612
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.
613 case DLT_PPP_BSDOS:
614 off_linktype = 5;
615 off_nl = 24;
616 return;
617
618 case DLT_FDDI:
619 /*
620 * 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.
621 * We set "off_linktype" to the offset of the LLC header.
599 *
622 *
623 * To check for Ethernet types, we assume that SSAP = SNAP
624 * is being used and pick out the encapsulated Ethernet type.
600 * XXX - should we generate code to check for SNAP?
601 */
625 * XXX - should we generate code to check for SNAP?
626 */
602 off_linktype = 19;
627 off_linktype = 13;
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.
628#ifdef PCAP_FDDIPAD
629 off_linktype += pcap_fddipad;
630#endif
631 off_nl = 21;
632#ifdef PCAP_FDDIPAD
633 off_nl += pcap_fddipad;
634#endif
635 return;
636
637 case DLT_IEEE802:
638 /*
639 * 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.
640 * We set "off_linktype" to the offset of the LLC header.
617 *
641 *
642 * To check for Ethernet types, we assume that SSAP = SNAP
643 * is being used and pick out the encapsulated Ethernet type.
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 */
644 * XXX - should we generate code to check for SNAP?
645 *
646 * XXX - the header is actually variable-length.
647 * Some various Linux patched versions gave 38
648 * as "off_linktype" and 40 as "off_nl"; however,
649 * if a token ring packet has *no* routing
650 * information, i.e. is not source-routed, the correct
651 * values are 20 and 22, as they are in the vanilla code.
652 *
653 * A packet is source-routed iff the uppermost bit
654 * of the first byte of the source address, at an
655 * offset of 8, has the uppermost bit set. If the
656 * packet is source-routed, the total number of bytes
657 * of routing information is 2 plus bits 0x1F00 of
658 * the 16-bit value at an offset of 14 (shifted right
659 * 8 - figure out which byte that is).
660 */
635 off_linktype = 20;
661 off_linktype = 14;
636 off_nl = 22;
637 return;
638
662 off_nl = 22;
663 return;
664
665 case DLT_IEEE802_11:
666 /*
667 * 802.11 doesn't really have a link-level type field.
668 * We set "off_linktype" to the offset of the LLC header.
669 *
670 * To check for Ethernet types, we assume that SSAP = SNAP
671 * is being used and pick out the encapsulated Ethernet type.
672 * XXX - should we generate code to check for SNAP?
673 *
674 * XXX - the header is actually variable-length. We
675 * assume a 24-byte link-layer header, as appears in
676 * data frames in networks with no bridges.
677 */
678 off_linktype = 24;
679 off_nl = 30;
680 return;
681
682 case DLT_PRISM_HEADER:
683 /*
684 * Same as 802.11, but with an additional header before
685 * the 802.11 header, containing a bunch of additional
686 * information including radio-level information.
687 *
688 * The header is 144 bytes long.
689 *
690 * XXX - same variable-length header problem; at least
691 * the Prism header is fixed-length.
692 */
693 off_linktype = 144+24;
694 off_nl = 144+30;
695 return;
696
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;
697 case DLT_ATM_RFC1483:
698 /*
699 * assume routed, non-ISO PDUs
700 * (i.e., LLC = 0xAA-AA-03, OUT = 0x00-00-00)
701 */
702 off_linktype = 6;
703 off_nl = 8;
704 return;

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

712 off_linktype = 6;
713 off_nl = 8;
714 return;
715
716 case DLT_LINUX_SLL: /* fake header for Linux cooked socket */
717 off_linktype = 14;
718 off_nl = 16;
719 return;
720
721 case DLT_LTALK:
722 /*
723 * LocalTalk does have a 1-byte type field in the LLAP header,
724 * but really it just indicates whether there is a "short" or
725 * "long" DDP packet following.
726 */
727 off_linktype = -1;
728 off_nl = 0;
729 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
730 }
731 bpf_error("unknown data link type %d", linktype);
732 /* NOTREACHED */
733}
734
735static struct block *
736gen_uncond(rsense)
737 int rsense;

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

768((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))
769
770static struct block *
771gen_linktype(proto)
772 register int proto;
773{
774 struct block *b0, *b1;
775
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:
776 switch (linktype) {
777
778 case DLT_EN10MB:
715 /*
716 * XXX - handle other LLC-encapsulated protocols here
717 * (IPX, OSI)?
718 */
719 switch (proto) {
720
779 switch (proto) {
780
721 case LLC_ISO_LSAP:
781 case LLCSAP_ISONS:
722 /*
723 * OSI protocols always use 802.2 encapsulation.
782 /*
783 * OSI protocols always use 802.2 encapsulation.
784 * XXX - should we check both the DSAP and the
785 * SSAP, like this, or should we check just the
786 * DSAP?
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)
787 */
788 b0 = gen_cmp_gt(off_linktype, BPF_H, ETHERMTU);
789 gen_not(b0);
790 b1 = gen_cmp(off_linktype + 2, BPF_H, (bpf_int32)
728 ((LLC_ISO_LSAP << 8) | LLC_ISO_LSAP));
791 ((LLCSAP_ISONS << 8) | LLCSAP_ISONS));
729 gen_and(b0, b1);
730 return b1;
731
792 gen_and(b0, b1);
793 return b1;
794
795 case LLCSAP_NETBEUI:
796 /*
797 * NetBEUI always uses 802.2 encapsulation.
798 * XXX - should we check both the DSAP and the
799 * SSAP, like this, or should we check just the
800 * DSAP?
801 */
802 b0 = gen_cmp_gt(off_linktype, BPF_H, ETHERMTU);
803 gen_not(b0);
804 b1 = gen_cmp(off_linktype + 2, BPF_H, (bpf_int32)
805 ((LLCSAP_NETBEUI << 8) | LLCSAP_NETBEUI));
806 gen_and(b0, b1);
807 return b1;
808
809 case LLCSAP_IPX:
810 /*
811 * Check for;
812 *
813 * Ethernet_II frames, which are Ethernet
814 * frames with a frame type of ETHERTYPE_IPX;
815 *
816 * Ethernet_802.3 frames, which are 802.3
817 * frames (i.e., the type/length field is
818 * a length field, <= ETHERMTU, rather than
819 * a type field) with the first two bytes
820 * after the Ethernet/802.3 header being
821 * 0xFFFF;
822 *
823 * Ethernet_802.2 frames, which are 802.3
824 * frames with an 802.2 LLC header and
825 * with the IPX LSAP as the DSAP in the LLC
826 * header;
827 *
828 * Ethernet_SNAP frames, which are 802.3
829 * frames with an LLC header and a SNAP
830 * header and with an OUI of 0x000000
831 * (encapsulated Ethernet) and a protocol
832 * ID of ETHERTYPE_IPX in the SNAP header.
833 *
834 * XXX - should we generate the same code both
835 * for tests for LLCSAP_IPX and for ETHERTYPE_IPX?
836 */
837
838 /*
839 * This generates code to check both for the
840 * IPX LSAP (Ethernet_802.2) and for Ethernet_802.3.
841 */
842 b0 = gen_cmp(off_linktype + 2, BPF_B,
843 (bpf_int32)LLCSAP_IPX);
844 b1 = gen_cmp(off_linktype + 2, BPF_H,
845 (bpf_int32)0xFFFF);
846 gen_or(b0, b1);
847
848 /*
849 * Now we add code to check for SNAP frames with
850 * ETHERTYPE_IPX, i.e. Ethernet_SNAP.
851 */
852 b0 = gen_snap(0x000000, ETHERTYPE_IPX, 14);
853 gen_or(b0, b1);
854
855 /*
856 * Now we generate code to check for 802.3
857 * frames in general.
858 */
859 b0 = gen_cmp_gt(off_linktype, BPF_H, ETHERMTU);
860 gen_not(b0);
861
862 /*
863 * Now add the check for 802.3 frames before the
864 * check for Ethernet_802.2 and Ethernet_802.3,
865 * as those checks should only be done on 802.3
866 * frames, not on Ethernet frames.
867 */
868 gen_and(b0, b1);
869
870 /*
871 * Now add the check for Ethernet_II frames, and
872 * do that before checking for the other frame
873 * types.
874 */
875 b0 = gen_cmp(off_linktype, BPF_H,
876 (bpf_int32)ETHERTYPE_IPX);
877 gen_or(b0, b1);
878 return b1;
879
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;
880 case ETHERTYPE_ATALK:
881 case ETHERTYPE_AARP:
882 /*
883 * EtherTalk (AppleTalk protocols on Ethernet link
884 * layer) may use 802.2 encapsulation.
885 */
886
887 /*

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

913 * Check for Ethernet encapsulation (Ethertalk
914 * phase 1?); we just check for the Ethernet
915 * protocol type.
916 */
917 b0 = gen_cmp(off_linktype, BPF_H, (bpf_int32)proto);
918
919 gen_or(b0, b1);
920 return b1;
921
922 default:
923 if (proto <= ETHERMTU) {
924 /*
925 * This is an LLC SAP value, so the frames
926 * that match would be 802.2 frames.
927 * Check that the frame is an 802.2 frame
928 * (i.e., that the length/type field is
929 * a length field, <= ETHERMTU) and
930 * then check the DSAP.
931 */
932 b0 = gen_cmp_gt(off_linktype, BPF_H, ETHERMTU);
933 gen_not(b0);
934 b1 = gen_cmp(off_linktype + 2, BPF_B,
935 (bpf_int32)proto);
936 gen_and(b0, b1);
937 return b1;
938 } else {
939 /*
940 * This is an Ethernet type, so compare
941 * the length/type field with it (if
942 * the frame is an 802.2 frame, the length
943 * field will be <= ETHERMTU, and, as
944 * "proto" is > ETHERMTU, this test
945 * will fail and the frame won't match,
946 * which is what we want).
947 */
948 return gen_cmp(off_linktype, BPF_H,
949 (bpf_int32)proto);
950 }
773 }
774 break;
775
951 }
952 break;
953
954 case DLT_IEEE802_11:
955 case DLT_PRISM_HEADER:
956 case DLT_FDDI:
957 case DLT_IEEE802:
958 case DLT_ATM_RFC1483:
959 case DLT_ATM_CLIP:
960 /*
961 * XXX - handle token-ring variable-length header.
962 */
963 switch (proto) {
964
965 case LLCSAP_ISONS:
966 return gen_cmp(off_linktype, BPF_H, (long)
967 ((LLCSAP_ISONS << 8) | LLCSAP_ISONS));
968
969 case LLCSAP_NETBEUI:
970 return gen_cmp(off_linktype, BPF_H, (long)
971 ((LLCSAP_NETBEUI << 8) | LLCSAP_NETBEUI));
972
973 case LLCSAP_IPX:
974 /*
975 * XXX - are there ever SNAP frames for IPX on
976 * non-Ethernet 802.x networks?
977 */
978 return gen_cmp(off_linktype, BPF_B,
979 (bpf_int32)LLCSAP_IPX);
980
981 case ETHERTYPE_ATALK:
982 /*
983 * 802.2-encapsulated ETHERTYPE_ATALK packets are
984 * SNAP packets with an organization code of
985 * 0x080007 (Apple, for Appletalk) and a protocol
986 * type of ETHERTYPE_ATALK (Appletalk).
987 *
988 * XXX - check for an organization code of
989 * encapsulated Ethernet as well?
990 */
991 return gen_snap(0x080007, ETHERTYPE_ATALK,
992 off_linktype);
993 break;
994
995 default:
996 /*
997 * XXX - we don't have to check for IPX 802.3
998 * here, but should we check for the IPX Ethertype?
999 */
1000 if (proto <= ETHERMTU) {
1001 /*
1002 * This is an LLC SAP value, so check
1003 * the DSAP.
1004 */
1005 return gen_cmp(off_linktype, BPF_B,
1006 (bpf_int32)proto);
1007 } else {
1008 /*
1009 * This is an Ethernet type; we assume
1010 * that it's unlikely that it'll
1011 * appear in the right place at random,
1012 * and therefore check only the
1013 * location that would hold the Ethernet
1014 * type in a SNAP frame with an organization
1015 * code of 0x000000 (encapsulated Ethernet).
1016 *
1017 * XXX - if we were to check for the SNAP DSAP
1018 * and LSAP, as per XXX, and were also to check
1019 * for an organization code of 0x000000
1020 * (encapsulated Ethernet), we'd do
1021 *
1022 * return gen_snap(0x000000, proto,
1023 * off_linktype);
1024 *
1025 * here; for now, we don't, as per the above.
1026 * I don't know whether it's worth the
1027 * extra CPU time to do the right check
1028 * or not.
1029 */
1030 return gen_cmp(off_linktype+6, BPF_H,
1031 (bpf_int32)proto);
1032 }
1033 }
1034 break;
1035
1036 case DLT_LINUX_SLL:
1037 switch (proto) {
1038
1039 case LLCSAP_ISONS:
1040 /*
1041 * OSI protocols always use 802.2 encapsulation.
1042 * XXX - should we check both the DSAP and the
1043 * LSAP, like this, or should we check just the
1044 * DSAP?
1045 */
1046 b0 = gen_cmp(off_linktype, BPF_H, LINUX_SLL_P_802_2);
1047 b1 = gen_cmp(off_linktype + 2, BPF_H, (bpf_int32)
1048 ((LLCSAP_ISONS << 8) | LLCSAP_ISONS));
1049 gen_and(b0, b1);
1050 return b1;
1051
1052 case LLCSAP_NETBEUI:
1053 /*
1054 * NetBEUI always uses 802.2 encapsulation.
1055 * XXX - should we check both the DSAP and the
1056 * LSAP, like this, or should we check just the
1057 * DSAP?
1058 */
1059 b0 = gen_cmp(off_linktype, BPF_H, LINUX_SLL_P_802_2);
1060 b1 = gen_cmp(off_linktype + 2, BPF_H, (bpf_int32)
1061 ((LLCSAP_NETBEUI << 8) | LLCSAP_NETBEUI));
1062 gen_and(b0, b1);
1063 return b1;
1064
1065 case LLCSAP_IPX:
1066 /*
1067 * Ethernet_II frames, which are Ethernet
1068 * frames with a frame type of ETHERTYPE_IPX;
1069 *
1070 * Ethernet_802.3 frames, which have a frame
1071 * type of LINUX_SLL_P_802_3;
1072 *
1073 * Ethernet_802.2 frames, which are 802.3
1074 * frames with an 802.2 LLC header (i.e, have
1075 * a frame type of LINUX_SLL_P_802_2) and
1076 * with the IPX LSAP as the DSAP in the LLC
1077 * header;
1078 *
1079 * Ethernet_SNAP frames, which are 802.3
1080 * frames with an LLC header and a SNAP
1081 * header and with an OUI of 0x000000
1082 * (encapsulated Ethernet) and a protocol
1083 * ID of ETHERTYPE_IPX in the SNAP header.
1084 *
1085 * First, do the checks on LINUX_SLL_P_802_2
1086 * frames; generate the check for either
1087 * Ethernet_802.2 or Ethernet_SNAP frames, and
1088 * then put a check for LINUX_SLL_P_802_2 frames
1089 * before it.
1090 */
1091 b0 = gen_cmp(off_linktype + 2, BPF_B,
1092 (bpf_int32)LLCSAP_IPX);
1093 b1 = gen_snap(0x000000, ETHERTYPE_IPX,
1094 off_linktype + 2);
1095 gen_or(b0, b1);
1096 b0 = gen_cmp(off_linktype, BPF_H, LINUX_SLL_P_802_2);
1097 gen_and(b0, b1);
1098
1099 /*
1100 * Now check for 802.3 frames and OR that with
1101 * the previous test.
1102 */
1103 b0 = gen_cmp(off_linktype, BPF_H, LINUX_SLL_P_802_3);
1104 gen_or(b0, b1);
1105
1106 /*
1107 * Now add the check for Ethernet_II frames, and
1108 * do that before checking for the other frame
1109 * types.
1110 */
1111 b0 = gen_cmp(off_linktype, BPF_H,
1112 (bpf_int32)ETHERTYPE_IPX);
1113 gen_or(b0, b1);
1114 return b1;
1115
1116 case ETHERTYPE_ATALK:
1117 case ETHERTYPE_AARP:
1118 /*
1119 * EtherTalk (AppleTalk protocols on Ethernet link
1120 * layer) may use 802.2 encapsulation.
1121 */
1122
1123 /*
1124 * Check for 802.2 encapsulation (EtherTalk phase 2?);
1125 * we check for the 802.2 protocol type in the
1126 * "Ethernet type" field.
1127 */
1128 b0 = gen_cmp(off_linktype, BPF_H, LINUX_SLL_P_802_2);
1129
1130 /*
1131 * 802.2-encapsulated ETHERTYPE_ATALK packets are
1132 * SNAP packets with an organization code of
1133 * 0x080007 (Apple, for Appletalk) and a protocol
1134 * type of ETHERTYPE_ATALK (Appletalk).
1135 *
1136 * 802.2-encapsulated ETHERTYPE_AARP packets are
1137 * SNAP packets with an organization code of
1138 * 0x000000 (encapsulated Ethernet) and a protocol
1139 * type of ETHERTYPE_AARP (Appletalk ARP).
1140 */
1141 if (proto == ETHERTYPE_ATALK)
1142 b1 = gen_snap(0x080007, ETHERTYPE_ATALK,
1143 off_linktype + 2);
1144 else /* proto == ETHERTYPE_AARP */
1145 b1 = gen_snap(0x000000, ETHERTYPE_AARP,
1146 off_linktype + 2);
1147 gen_and(b0, b1);
1148
1149 /*
1150 * Check for Ethernet encapsulation (Ethertalk
1151 * phase 1?); we just check for the Ethernet
1152 * protocol type.
1153 */
1154 b0 = gen_cmp(off_linktype, BPF_H, (bpf_int32)proto);
1155
1156 gen_or(b0, b1);
1157 return b1;
1158
1159 default:
1160 if (proto <= ETHERMTU) {
1161 /*
1162 * This is an LLC SAP value, so the frames
1163 * that match would be 802.2 frames.
1164 * Check for the 802.2 protocol type
1165 * in the "Ethernet type" field, and
1166 * then check the DSAP.
1167 */
1168 b0 = gen_cmp(off_linktype, BPF_H,
1169 LINUX_SLL_P_802_2);
1170 b1 = gen_cmp(off_linktype + 2, BPF_B,
1171 (bpf_int32)proto);
1172 gen_and(b0, b1);
1173 return b1;
1174 } else {
1175 /*
1176 * This is an Ethernet type, so compare
1177 * the length/type field with it (if
1178 * the frame is an 802.2 frame, the length
1179 * field will be <= ETHERMTU, and, as
1180 * "proto" is > ETHERMTU, this test
1181 * will fail and the frame won't match,
1182 * which is what we want).
1183 */
1184 return gen_cmp(off_linktype, BPF_H,
1185 (bpf_int32)proto);
1186 }
1187 }
1188 break;
1189
776 case DLT_SLIP:
1190 case DLT_SLIP:
777 return gen_false();
1191 case DLT_SLIP_BSDOS:
1192 case DLT_RAW:
1193 /*
1194 * These types don't provide any type field; packets
1195 * are always IP.
1196 *
1197 * XXX - for IPv4, check for a version number of 4, and,
1198 * for IPv6, check for a version number of 6?
1199 */
1200 switch (proto) {
778
1201
1202 case ETHERTYPE_IP:
1203#ifdef INET6
1204 case ETHERTYPE_IPV6:
1205#endif
1206 return gen_true(); /* always true */
1207
1208 default:
1209 return gen_false(); /* always false */
1210 }
1211 break;
1212
779 case DLT_PPP:
780 case DLT_PPP_SERIAL:
1213 case DLT_PPP:
1214 case DLT_PPP_SERIAL:
1215 case DLT_PPP_ETHER:
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
1216 /*
1217 * We use Ethernet protocol types inside libpcap;
1218 * map them to the corresponding PPP protocol types.
1219 */
1220 switch (proto) {
1221
1222 case ETHERTYPE_IP:
1223 proto = PPP_IP; /* XXX was 0x21 */

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

1236 case ETHERTYPE_ATALK:
1237 proto = PPP_APPLE;
1238 break;
1239
1240 case ETHERTYPE_NS:
1241 proto = PPP_NS;
1242 break;
1243
809 case LLC_ISO_LSAP:
1244 case LLCSAP_ISONS:
810 proto = PPP_OSI;
811 break;
1245 proto = PPP_OSI;
1246 break;
1247
1248 case LLCSAP_8021D:
1249 /*
1250 * I'm assuming the "Bridging PDU"s that go
1251 * over PPP are Spanning Tree Protocol
1252 * Bridging PDUs.
1253 */
1254 proto = PPP_BRPDU;
1255 break;
1256
1257 case LLCSAP_IPX:
1258 proto = PPP_IPX;
1259 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
1260 }
1261 break;
1262
1263 case DLT_PPP_BSDOS:
1264 /*
1265 * We use Ethernet protocol types inside libpcap;
1266 * map them to the corresponding PPP protocol types.
1267 */

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

1289 case ETHERTYPE_ATALK:
1290 proto = PPP_APPLE;
1291 break;
1292
1293 case ETHERTYPE_NS:
1294 proto = PPP_NS;
1295 break;
1296
849 case LLC_ISO_LSAP:
1297 case LLCSAP_ISONS:
850 proto = PPP_OSI;
851 break;
1298 proto = PPP_OSI;
1299 break;
1300
1301 case LLCSAP_8021D:
1302 /*
1303 * I'm assuming the "Bridging PDU"s that go
1304 * over PPP are Spanning Tree Protocol
1305 * Bridging PDUs.
1306 */
1307 proto = PPP_BRPDU;
1308 break;
1309
1310 case LLCSAP_IPX:
1311 proto = PPP_IPX;
1312 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));
1313 }
1314 break;
1315
1316 case DLT_NULL:
1317 case DLT_LOOP:
1318 /*
1319 * For DLT_NULL, the link-layer header is a 32-bit
1320 * word containing an AF_ value in *host* byte order.

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

1369 * generate code to compare against the result.
1370 */
1371 if (bpf_pcap->sf.rfile != NULL &&
1372 bpf_pcap->sf.swapped)
1373 proto = SWAPLONG(proto);
1374 proto = htonl(proto);
1375 }
1376 return (gen_cmp(0, BPF_W, (bpf_int32)proto));
1377
1378 case DLT_ARCNET:
1379 /*
1380 * XXX should we check for first fragment if the protocol
1381 * uses PHDS?
1382 */
1383 switch(proto) {
1384 default:
1385 return gen_false();
1386#ifdef INET6
1387 case ETHERTYPE_IPV6:
1388 return(gen_cmp(2, BPF_B,
1389 (bpf_int32)htonl(ARCTYPE_INET6)));
1390#endif /* INET6 */
1391 case ETHERTYPE_IP:
1392 b0 = gen_cmp(2, BPF_B, (bpf_int32)htonl(ARCTYPE_IP));
1393 b1 = gen_cmp(2, BPF_B,
1394 (bpf_int32)htonl(ARCTYPE_IP_OLD));
1395 gen_or(b0, b1);
1396 return(b1);
1397 case ETHERTYPE_ARP:
1398 b0 = gen_cmp(2, BPF_B, (bpf_int32)htonl(ARCTYPE_ARP));
1399 b1 = gen_cmp(2, BPF_B,
1400 (bpf_int32)htonl(ARCTYPE_ARP_OLD));
1401 gen_or(b0, b1);
1402 return(b1);
1403 case ETHERTYPE_REVARP:
1404 return(gen_cmp(2, BPF_B,
1405 (bpf_int32)htonl(ARCTYPE_REVARP)));
1406 case ETHERTYPE_ATALK:
1407 return(gen_cmp(2, BPF_B,
1408 (bpf_int32)htonl(ARCTYPE_ATALK)));
1409 }
1410 break;
1411
1412 case DLT_LTALK:
1413 switch (proto) {
1414 case ETHERTYPE_ATALK:
1415 return gen_true();
1416 default:
1417 return gen_false();
1418 }
1419 break;
916 }
1420 }
1421
1422 /*
1423 * All the types that have no encapsulation should either be
1424 * handled as DLT_SLIP, DLT_SLIP_BSDOS, and DLT_RAW are, if
1425 * all packets are IP packets, or should be handled in some
1426 * special case, if none of them are (if some are and some
1427 * aren't, the lack of encapsulation is a problem, as we'd
1428 * have to find some other way of determining the packet type).
1429 *
1430 * Therefore, if "off_linktype" is -1, there's an error.
1431 */
1432 if (off_linktype == -1)
1433 abort();
1434
1435 /*
1436 * Any type not handled above should always have an Ethernet
1437 * type at an offset of "off_linktype". (PPP is partially
1438 * handled above - the protocol type is mapped from the
1439 * Ethernet and LLC types we use internally to the corresponding
1440 * PPP type - but the PPP type is always specified by a value
1441 * at "off_linktype", so we don't have to do the code generation
1442 * above.)
1443 */
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
1444 return gen_cmp(off_linktype, BPF_H, (bpf_int32)proto);
1445}
1446
1447/*
1448 * Check for an LLC SNAP packet with a given organization code and
1449 * protocol type; we check the entire contents of the 802.2 LLC and
1450 * snap headers, checking for DSAP and SSAP of SNAP and a control
1451 * field of 0x03 in the LLC header, and for the specified organization
1452 * code and protocol type in the SNAP header.
1453 */
1454static struct block *
1455gen_snap(orgcode, ptype, offset)
1456 bpf_u_int32 orgcode;
1457 bpf_u_int32 ptype;
1458 u_int offset;
1459{
1460 u_char snapblock[8];
1461
935 snapblock[0] = LLC_SNAP_LSAP; /* DSAP = SNAP */
936 snapblock[1] = LLC_SNAP_LSAP; /* SSAP = SNAP */
1462 snapblock[0] = LLCSAP_SNAP; /* DSAP = SNAP */
1463 snapblock[1] = LLCSAP_SNAP; /* 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
1464 snapblock[2] = 0x03; /* control = UI */
1465 snapblock[3] = (orgcode >> 16); /* upper 8 bits of organization code */
1466 snapblock[4] = (orgcode >> 8); /* middle 8 bits of organization code */
1467 snapblock[5] = (orgcode >> 0); /* lower 8 bits of organization code */
1468 snapblock[6] = (ptype >> 8); /* upper 8 bits of protocol type */
1469 snapblock[7] = (ptype >> 0); /* lower 8 bits of protocol type */
1470 return gen_bcmp(offset, 8, snapblock);
1471}

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

1795
1796 case Q_ARP:
1797 return gen_hostop(addr, mask, dir, ETHERTYPE_ARP,
1798 off_nl + 14, off_nl + 24);
1799
1800 case Q_TCP:
1801 bpf_error("'tcp' modifier applied to host");
1802
1803 case Q_SCTP:
1804 bpf_error("'sctp' modifier applied to host");
1805
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
1806 case Q_UDP:
1807 bpf_error("'udp' modifier applied to host");
1808
1809 case Q_ICMP:
1810 bpf_error("'icmp' modifier applied to host");
1811
1812 case Q_IGMP:
1813 bpf_error("'igmp' modifier applied to host");
1814
1815 case Q_IGRP:
1816 bpf_error("'igrp' modifier applied to host");
1817
1818 case Q_PIM:
1819 bpf_error("'pim' modifier applied to host");
1820
1821 case Q_VRRP:
1822 bpf_error("'vrrp' modifier applied to host");
1823
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
1824 case Q_ATALK:
1825 bpf_error("ATALK host filtering not implemented");
1826
1827 case Q_AARP:
1828 bpf_error("AARP host filtering not implemented");
1829
1830 case Q_DECNET:
1831 return gen_dnhostop(addr, dir, off_nl);

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

1863 bpf_error("'esis' modifier applied to host");
1864
1865 case Q_ISIS:
1866 bpf_error("'isis' modifier applied to host");
1867
1868 case Q_CLNP:
1869 bpf_error("'clnp' modifier applied to host");
1870
1871 case Q_STP:
1872 bpf_error("'stp' modifier applied to host");
1873
1874 case Q_IPX:
1875 bpf_error("IPX host filtering not implemented");
1876
1877 case Q_NETBEUI:
1878 bpf_error("'netbeui' modifier applied to host");
1879
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
1880 default:
1881 abort();
1882 }
1883 /* NOTREACHED */
1884}
1885
1886#ifdef INET6
1887static struct block *

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

1900 bpf_error("'ip' modifier applied to ip6 host");
1901
1902 case Q_RARP:
1903 bpf_error("'rarp' modifier applied to ip6 host");
1904
1905 case Q_ARP:
1906 bpf_error("'arp' modifier applied to ip6 host");
1907
1908 case Q_SCTP:
1909 bpf_error("'sctp' modifier applied to host");
1910
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
1911 case Q_TCP:
1912 bpf_error("'tcp' modifier applied to host");
1913
1914 case Q_UDP:
1915 bpf_error("'udp' modifier applied to host");
1916
1917 case Q_ICMP:
1918 bpf_error("'icmp' modifier applied to host");
1919
1920 case Q_IGMP:
1921 bpf_error("'igmp' modifier applied to host");
1922
1923 case Q_IGRP:
1924 bpf_error("'igrp' modifier applied to host");
1925
1926 case Q_PIM:
1927 bpf_error("'pim' modifier applied to host");
1928
1929 case Q_VRRP:
1930 bpf_error("'vrrp' modifier applied to host");
1931
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
1932 case Q_ATALK:
1933 bpf_error("ATALK host filtering not implemented");
1934
1935 case Q_AARP:
1936 bpf_error("AARP host filtering not implemented");
1937
1938 case Q_DECNET:
1939 bpf_error("'decnet' modifier applied to ip6 host");

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

1970 bpf_error("'esis' modifier applied to host");
1971
1972 case Q_ISIS:
1973 bpf_error("'isis' modifier applied to host");
1974
1975 case Q_CLNP:
1976 bpf_error("'clnp' modifier applied to host");
1977
1978 case Q_STP:
1979 bpf_error("'stp' modifier applied to host");
1980
1981 case Q_IPX:
1982 bpf_error("IPX host filtering not implemented");
1983
1984 case Q_NETBEUI:
1985 bpf_error("'netbeui' modifier applied to host");
1986
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
1987 default:
1988 abort();
1989 }
1990 /* NOTREACHED */
1991}
1992#endif /*INET6*/
1993
1994#ifndef INET6

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

2040{
2041#ifdef INET6
2042 struct block *b0;
2043#endif
2044 struct block *b1;
2045
2046 switch (proto) {
2047
2048 case Q_SCTP:
2049 b1 = gen_proto(IPPROTO_SCTP, Q_IP, Q_DEFAULT);
2050#ifdef INET6
2051 b0 = gen_proto(IPPROTO_SCTP, Q_IPV6, Q_DEFAULT);
2052 gen_or(b0, b1);
2053#endif
2054 break;
2055
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
2056 case Q_TCP:
2057 b1 = gen_proto(IPPROTO_TCP, Q_IP, Q_DEFAULT);
2058#ifdef INET6
2059 b0 = gen_proto(IPPROTO_TCP, Q_IPV6, Q_DEFAULT);
2060 gen_or(b0, b1);
2061#endif
2062 break;
2063

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

2095 case Q_PIM:
2096 b1 = gen_proto(IPPROTO_PIM, Q_IP, Q_DEFAULT);
2097#ifdef INET6
2098 b0 = gen_proto(IPPROTO_PIM, Q_IPV6, Q_DEFAULT);
2099 gen_or(b0, b1);
2100#endif
2101 break;
2102
2103#ifndef IPPROTO_VRRP
2104#define IPPROTO_VRRP 112
2105#endif
2106
2107 case Q_VRRP:
2108 b1 = gen_proto(IPPROTO_VRRP, Q_IP, Q_DEFAULT);
2109 break;
2110
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:
2111 case Q_IP:
2112 b1 = gen_linktype(ETHERTYPE_IP);
2113 break;
2114
2115 case Q_ARP:
2116 b1 = gen_linktype(ETHERTYPE_ARP);
2117 break;
2118

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

2182 b1 = gen_proto(IPPROTO_ESP, Q_IP, Q_DEFAULT);
2183#ifdef INET6
2184 b0 = gen_proto(IPPROTO_ESP, Q_IPV6, Q_DEFAULT);
2185 gen_or(b0, b1);
2186#endif
2187 break;
2188
2189 case Q_ISO:
1617 b1 = gen_linktype(LLC_ISO_LSAP);
2190 b1 = gen_linktype(LLCSAP_ISONS);
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
2191 break;
2192
2193 case Q_ESIS:
2194 b1 = gen_proto(ISO9542_ESIS, Q_ISO, Q_DEFAULT);
2195 break;
2196
2197 case Q_ISIS:
2198 b1 = gen_proto(ISO10589_ISIS, Q_ISO, Q_DEFAULT);
2199 break;
2200
2201 case Q_CLNP:
2202 b1 = gen_proto(ISO8473_CLNP, Q_ISO, Q_DEFAULT);
2203 break;
2204
2205 case Q_STP:
2206 b1 = gen_linktype(LLCSAP_8021D);
2207 break;
2208
2209 case Q_IPX:
2210 b1 = gen_linktype(LLCSAP_IPX);
2211 break;
2212
2213 case Q_NETBEUI:
2214 b1 = gen_linktype(LLCSAP_NETBEUI);
2215 break;
2216
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:
2217 default:
2218 abort();
2219 }
2220 return b1;
2221}
2222
2223static struct block *
2224gen_ipfrag()

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

2318 struct block *b0, *b1, *tmp;
2319
2320 /* ether proto ip */
2321 b0 = gen_linktype(ETHERTYPE_IP);
2322
2323 switch (ip_proto) {
2324 case IPPROTO_UDP:
2325 case IPPROTO_TCP:
2326 case IPPROTO_SCTP:
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);
2327 b1 = gen_portop(port, ip_proto, dir);
2328 break;
2329
2330 case PROTO_UNDEF:
2331 tmp = gen_portop(port, IPPROTO_TCP, dir);
2332 b1 = gen_portop(port, IPPROTO_UDP, dir);
2333 gen_or(tmp, b1);
2334 tmp = gen_portop(port, IPPROTO_SCTP, dir);
2335 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:
2336 break;
2337
2338 default:
2339 abort();
2340 }
2341 gen_and(b0, b1);
2342 return b1;
2343}

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

2391 struct block *b0, *b1, *tmp;
2392
2393 /* ether proto ip */
2394 b0 = gen_linktype(ETHERTYPE_IPV6);
2395
2396 switch (ip_proto) {
2397 case IPPROTO_UDP:
2398 case IPPROTO_TCP:
2399 case IPPROTO_SCTP:
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);
2400 b1 = gen_portop6(port, ip_proto, dir);
2401 break;
2402
2403 case PROTO_UNDEF:
2404 tmp = gen_portop6(port, IPPROTO_TCP, dir);
2405 b1 = gen_portop6(port, IPPROTO_UDP, dir);
2406 gen_or(tmp, b1);
2407 tmp = gen_portop6(port, IPPROTO_SCTP, dir);
2408 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:
2409 break;
2410
2411 default:
2412 abort();
2413 }
2414 gen_and(b0, b1);
2415 return b1;
2416}

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

2422 register int proto;
2423{
2424 register int v;
2425
2426 switch (proto) {
2427
2428 case Q_DEFAULT:
2429 case Q_IP:
2430 case Q_IPV6:
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:
2431 v = pcap_nametoproto(name);
2432 if (v == PROTO_UNDEF)
2433 bpf_error("unknown ip proto '%s'", name);
2434 break;
2435
2436 case Q_LINK:
2437 /* XXX should look up h/w protocol type based on linktype */
2438 v = pcap_nametoeproto(name);

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

2787 b1 = gen_cmp(off_nl + 9, BPF_B, (bpf_int32)v);
2788#else
2789 b1 = gen_protochain(v, Q_IP);
2790#endif
2791 gen_and(b0, b1);
2792 return b1;
2793
2794 case Q_ISO:
2203 b0 = gen_linktype(LLC_ISO_LSAP);
2795 b0 = gen_linktype(LLCSAP_ISONS);
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
2796 b1 = gen_cmp(off_nl + 3, BPF_B, (long)v);
2797 gen_and(b0, b1);
2798 return b1;
2799
2800 case Q_ARP:
2801 bpf_error("arp does not encapsulate another protocol");
2802 /* NOTREACHED */
2803

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

2835 case Q_UDP:
2836 bpf_error("'udp proto' is bogus");
2837 /* NOTREACHED */
2838
2839 case Q_TCP:
2840 bpf_error("'tcp proto' is bogus");
2841 /* NOTREACHED */
2842
2843 case Q_SCTP:
2844 bpf_error("'sctp proto' is bogus");
2845 /* NOTREACHED */
2846
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
2847 case Q_ICMP:
2848 bpf_error("'icmp proto' is bogus");
2849 /* NOTREACHED */
2850
2851 case Q_IGMP:
2852 bpf_error("'igmp proto' is bogus");
2853 /* NOTREACHED */
2854
2855 case Q_IGRP:
2856 bpf_error("'igrp proto' is bogus");
2857 /* NOTREACHED */
2858
2859 case Q_PIM:
2860 bpf_error("'pim proto' is bogus");
2861 /* NOTREACHED */
2862
2863 case Q_VRRP:
2864 bpf_error("'vrrp proto' is bogus");
2865 /* NOTREACHED */
2866
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
2867#ifdef INET6
2868 case Q_IPV6:
2869 b0 = gen_linktype(ETHERTYPE_IPV6);
2870#ifndef CHASE_CHAIN
2871 b1 = gen_cmp(off_nl + 6, BPF_B, (bpf_int32)v);
2872#else
2873 b1 = gen_protochain(v, Q_IPV6);
2874#endif

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

2880#endif /* INET6 */
2881
2882 case Q_AH:
2883 bpf_error("'ah proto' is bogus");
2884
2885 case Q_ESP:
2886 bpf_error("'ah proto' is bogus");
2887
2888 case Q_STP:
2889 bpf_error("'stp proto' is bogus");
2890
2891 case Q_IPX:
2892 bpf_error("'ipx proto' is bogus");
2893
2894 case Q_NETBEUI:
2895 bpf_error("'netbeui proto' is bogus");
2896
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);
2897 default:
2898 abort();
2899 /* NOTREACHED */
2900 }
2901 /* NOTREACHED */
2902}
2903
2904struct block *

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

2942 if (proto == Q_LINK) {
2943 switch (linktype) {
2944
2945 case DLT_EN10MB:
2946 eaddr = pcap_ether_hostton(name);
2947 if (eaddr == NULL)
2948 bpf_error(
2949 "unknown ether host '%s'", name);
2341 return gen_ehostop(eaddr, dir);
2950 b = gen_ehostop(eaddr, dir);
2951 free(eaddr);
2952 return b;
2342
2343 case DLT_FDDI:
2344 eaddr = pcap_ether_hostton(name);
2345 if (eaddr == NULL)
2346 bpf_error(
2347 "unknown FDDI host '%s'", name);
2953
2954 case DLT_FDDI:
2955 eaddr = pcap_ether_hostton(name);
2956 if (eaddr == NULL)
2957 bpf_error(
2958 "unknown FDDI host '%s'", name);
2348 return gen_fhostop(eaddr, dir);
2959 b = gen_fhostop(eaddr, dir);
2960 free(eaddr);
2961 return b;
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);
2962
2963 case DLT_IEEE802:
2964 eaddr = pcap_ether_hostton(name);
2965 if (eaddr == NULL)
2966 bpf_error(
2967 "unknown token ring host '%s'", name);
2355 return gen_thostop(eaddr, dir);
2968 b = gen_thostop(eaddr, dir);
2969 free(eaddr);
2970 return b;
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;
2971
2972 default:
2973 bpf_error(
2974 "only ethernet/FDDI/token ring supports link-level host name");
2975 break;
2976 }
2977 } else if (proto == Q_DECNET) {
2978 unsigned short dn_addr = __pcap_nametodnaddr(name);

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

3023 if (tproto6 == Q_IP)
3024 continue;
3025
3026 sin6 = (struct sockaddr_in6 *)
3027 res->ai_addr;
3028 tmp = gen_host6(&sin6->sin6_addr,
3029 &mask128, tproto6, dir);
3030 break;
3031 default:
3032 continue;
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:
3033 }
3034 if (b)
3035 gen_or(b, tmp);
3036 b = tmp;
3037 }
3038 freeaddrinfo(res0);
3039 if (b == NULL) {
3040 bpf_error("unknown host '%s'%s", name,
3041 (proto == Q_DEFAULT)
3042 ? ""
3043 : " for specified address family");
3044 }
3045 return b;
3046#endif /*INET6*/
3047 }
3048
3049 case Q_PORT:
2433 if (proto != Q_DEFAULT && proto != Q_UDP && proto != Q_TCP)
3050 if (proto != Q_DEFAULT &&
3051 proto != Q_UDP && proto != Q_TCP && proto != Q_SCTP)
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);
3052 bpf_error("illegal qualifier of 'port'");
3053 if (pcap_nametoport(name, &port, &real_proto) == 0)
3054 bpf_error("unknown port '%s'", name);
3055 if (proto == Q_UDP) {
3056 if (real_proto == IPPROTO_TCP)
3057 bpf_error("port '%s' is tcp", name);
3058 else if (real_proto == IPPROTO_SCTP)
3059 bpf_error("port '%s' is sctp", 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);
3060 else
3061 /* override PROTO_UNDEF */
3062 real_proto = IPPROTO_UDP;
3063 }
3064 if (proto == Q_TCP) {
3065 if (real_proto == IPPROTO_UDP)
3066 bpf_error("port '%s' is udp", name);
3067
3068 else if (real_proto == IPPROTO_SCTP)
3069 bpf_error("port '%s' is sctp", name);
2447 else
2448 /* override PROTO_UNDEF */
2449 real_proto = IPPROTO_TCP;
2450 }
3070 else
3071 /* override PROTO_UNDEF */
3072 real_proto = IPPROTO_TCP;
3073 }
3074 if (proto == Q_SCTP) {
3075 if (real_proto == IPPROTO_UDP)
3076 bpf_error("port '%s' is udp", name);
3077
3078 else if (real_proto == IPPROTO_TCP)
3079 bpf_error("port '%s' is tcp", name);
3080 else
3081 /* override PROTO_UNDEF */
3082 real_proto = IPPROTO_SCTP;
3083 }
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);
3084#ifndef INET6
3085 return gen_port(port, real_proto, dir);
3086#else
3087 {
3088 struct block *b;
3089 b = gen_port(port, real_proto, dir);
3090 gen_or(gen_port6(port, real_proto, dir), b);
3091 return b;

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

3096#ifndef INET6
3097 eaddr = pcap_ether_hostton(name);
3098 if (eaddr == NULL)
3099 bpf_error("unknown ether host: %s", name);
3100
3101 alist = pcap_nametoaddr(name);
3102 if (alist == NULL || *alist == NULL)
3103 bpf_error("unknown host '%s'", name);
2471 return gen_gateway(eaddr, alist, proto, dir);
3104 b = gen_gateway(eaddr, alist, proto, dir);
3105 free(eaddr);
3106 return b;
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;
3107#else
3108 bpf_error("'gateway' not supported in this configuration");
3109#endif /*INET6*/
3110
3111 case Q_PROTO:
3112 real_proto = lookup_proto(name, proto);
3113 if (real_proto >= 0)
3114 return gen_proto(real_proto, proto, dir);

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

3215 return gen_host(v, mask, proto, dir);
3216 }
3217
3218 case Q_PORT:
3219 if (proto == Q_UDP)
3220 proto = IPPROTO_UDP;
3221 else if (proto == Q_TCP)
3222 proto = IPPROTO_TCP;
3223 else if (proto == Q_SCTP)
3224 proto = IPPROTO_SCTP;
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));
3225 else if (proto == Q_DEFAULT)
3226 proto = PROTO_UNDEF;
3227 else
3228 bpf_error("illegal qualifier of 'port'");
3229
3230#ifndef INET6
3231 return gen_port((int)v, proto, dir);
3232#else

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

3279 if (!res)
3280 bpf_error("invalid ip6 address %s", s1);
3281 if (res->ai_next)
3282 bpf_error("%s resolved to multiple address", s1);
3283 addr = &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr;
3284
3285 if (sizeof(mask) * 8 < masklen)
3286 bpf_error("mask length must be <= %u", (unsigned int)(sizeof(mask) * 8));
3287 memset(&mask, 0, sizeof(mask));
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
3288 memset(&mask, 0xff, masklen / 8);
3289 if (masklen % 8) {
3290 mask.s6_addr[masklen / 8] =
3291 (0xff << (8 - masklen % 8)) & 0xff;
3292 }
3293
3294 a = (u_int32_t *)addr;
3295 m = (u_int32_t *)&mask;

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

3430 sappend(index->s, s);
3431
3432 b = gen_proto_abbrev(proto);
3433 if (index->b)
3434 gen_and(index->b, b);
3435 index->b = b;
3436 break;
3437
3438 case Q_SCTP:
2800 case Q_TCP:
2801 case Q_UDP:
2802 case Q_ICMP:
2803 case Q_IGMP:
2804 case Q_IGRP:
2805 case Q_PIM:
3439 case Q_TCP:
3440 case Q_UDP:
3441 case Q_ICMP:
3442 case Q_IGMP:
3443 case Q_IGRP:
3444 case Q_PIM:
3445 case Q_VRRP:
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
3446 s = new_stmt(BPF_LDX|BPF_MSH|BPF_B);
3447 s->s.k = off_nl;
3448 sappend(s, xfer_to_a(index));
3449 sappend(s, new_stmt(BPF_ALU|BPF_ADD|BPF_X));
3450 sappend(s, new_stmt(BPF_MISC|BPF_TAX));
3451 sappend(s, tmp = new_stmt(BPF_LD|BPF_IND|size));
3452 tmp->s.k = off_nl;
3453 sappend(index->s, s);

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

3712 s->s.k = val;
3713 b = new_block(JMP(BPF_JEQ));
3714 b->stmts = s;
3715 gen_not(b);
3716
3717 return b;
3718}
3719
3720static u_char abroadcast[] = { 0x0 };
3721
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:
3722struct block *
3723gen_broadcast(proto)
3724 int proto;
3725{
3726 bpf_u_int32 hostmask;
3727 struct block *b0, *b1, *b2;
3728 static u_char ebroadcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
3729
3730 switch (proto) {
3731
3732 case Q_DEFAULT:
3733 case Q_LINK:
3734 if (linktype == DLT_ARCNET)
3735 return gen_ahostop(abroadcast, Q_DST);
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:
3736 if (linktype == DLT_EN10MB)
3737 return gen_ehostop(ebroadcast, Q_DST);
3738 if (linktype == DLT_FDDI)
3739 return gen_fhostop(ebroadcast, Q_DST);
3740 if (linktype == DLT_IEEE802)
3741 return gen_thostop(ebroadcast, Q_DST);
3742 bpf_error("not a broadcast link");
3743 break;

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

3761{
3762 register struct block *b0, *b1;
3763 register struct slist *s;
3764
3765 switch (proto) {
3766
3767 case Q_DEFAULT:
3768 case Q_LINK:
3769 if (linktype == DLT_ARCNET)
3770 /* all ARCnet multicasts use the same address */
3771 return gen_ahostop(abroadcast, Q_DST);
3772
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
3773 if (linktype == DLT_EN10MB) {
3774 /* ether[0] & 1 != 0 */
3775 s = new_stmt(BPF_LD|BPF_B|BPF_ABS);
3776 s->s.k = 0;
3777 b0 = new_block(JMP(BPF_JSET));
3778 b0->s.k = 1;
3779 b0->stmts = s;
3780 return b0;

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

3842 bpf_error("inbound/outbound not supported on linktype %d\n",
3843 linktype);
3844 b0 = NULL;
3845 /* NOTREACHED */
3846 }
3847 return (b0);
3848}
3849
3850struct block *
3851gen_acode(eaddr, q)
3852 register const u_char *eaddr;
3853 struct qual q;
3854{
3855 if ((q.addr == Q_HOST || q.addr == Q_DEFAULT) && q.proto == Q_LINK) {
3856 if (linktype == DLT_ARCNET)
3857 return gen_ahostop(eaddr, (int)q.dir);
3858 }
3859 bpf_error("ARCnet address used in non-arc expression");
3860 /* NOTREACHED */
3861}
3862
3863static struct block *
3864gen_ahostop(eaddr, dir)
3865 register const u_char *eaddr;
3866 register int dir;
3867{
3868 register struct block *b0, *b1;
3869
3870 switch (dir) {
3871 /* src comes first, different from Ethernet */
3872 case Q_SRC:
3873 return gen_bcmp(0, 1, eaddr);
3874
3875 case Q_DST:
3876 return gen_bcmp(1, 1, eaddr);
3877
3878 case Q_AND:
3879 b0 = gen_ahostop(eaddr, Q_SRC);
3880 b1 = gen_ahostop(eaddr, Q_DST);
3881 gen_and(b0, b1);
3882 return b1;
3883
3884 case Q_DEFAULT:
3885 case Q_OR:
3886 b0 = gen_ahostop(eaddr, Q_SRC);
3887 b1 = gen_ahostop(eaddr, Q_DST);
3888 gen_or(b0, b1);
3889 return b1;
3890 }
3891 abort();
3892 /* NOTREACHED */
3893}
3894
3202/*
3203 * support IEEE 802.1Q VLAN trunk over ethernet
3204 */
3205struct block *
3206gen_vlan(vlan_num)
3207 int vlan_num;
3208{
3895/*
3896 * support IEEE 802.1Q VLAN trunk over ethernet
3897 */
3898struct block *
3899gen_vlan(vlan_num)
3900 int vlan_num;
3901{
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 ---
3902 struct block *b0;
3903
3904 /*
3905 * Change the offsets to point to the type and data fields within
3906 * the VLAN packet. This is somewhat of a kludge.
3907 */
3908 if (orig_nl == (u_int)-1) {
3909 orig_linktype = off_linktype; /* save original values */

--- 30 unchanged lines hidden ---