22c22
< * $FreeBSD: head/contrib/libpcap/gencode.c 235426 2012-05-14 05:12:56Z delphij $
---
> * $FreeBSD: head/contrib/libpcap/gencode.c 241231 2012-10-05 18:42:50Z delphij $
88a89,93
> #if defined(PF_PACKET) && defined(SO_ATTACH_FILTER)
> #include <linux/types.h>
> #include <linux/if_packet.h>
> #include <linux/filter.h>
> #endif
423c428
< int len;
---
> u_int len;
1398d1402
< #ifdef DLT_PFSYNC
1405d1408
< #endif
3361d3363
< #ifdef DLT_PFSYNC
3364d3365
< #endif
5823a5825,5829
> #ifdef INET6
> #ifndef CHASE_CHAIN
> struct block *b2;
> #endif
> #endif
5992c5998,6006
< b1 = gen_cmp(OR_NET, 6, BPF_B, (bpf_int32)v);
---
> /*
> * Also check for a fragment header before the final
> * header.
> */
> b2 = gen_cmp(OR_NET, 6, BPF_B, IPPROTO_FRAGMENT);
> b1 = gen_cmp(OR_NET, 40, BPF_B, (bpf_int32)v);
> gen_and(b2, b1);
> b2 = gen_cmp(OR_NET, 6, BPF_B, (bpf_int32)v);
> gen_or(b2, b1);
7473,7475c7487,7493
< * generate command for inbound/outbound. It's here so we can
< * make it link-type specific. 'dir' = 0 implies "inbound",
< * = 1 implies "outbound".
---
> * Filter on inbound (dir == 0) or outbound (dir == 1) traffic.
> * Outbound traffic is sent by this machine, while inbound traffic is
> * sent by a remote machine (and may include packets destined for a
> * unicast or multicast link-layer address we are not subscribing to).
> * These are the same definitions implemented by pcap_setdirection().
> * Capturing only unicast traffic destined for this host is probably
> * better accomplished using a higher-layer filter.
7505,7521c7523,7527
< if (dir) {
< /*
< * Match packets sent by this machine.
< */
< b0 = gen_cmp(OR_LINK, 0, BPF_H, LINUX_SLL_OUTGOING);
< } else {
< /*
< * Match packets sent to this machine.
< * (No broadcast or multicast packets, or
< * packets sent to some other machine and
< * received promiscuously.)
< *
< * XXX - packets sent to other machines probably
< * shouldn't be matched, but what about broadcast
< * or multicast packets we received?
< */
< b0 = gen_cmp(OR_LINK, 0, BPF_H, LINUX_SLL_HOST);
---
> /* match outgoing packets */
> b0 = gen_cmp(OR_LINK, 0, BPF_H, LINUX_SLL_OUTGOING);
> if (!dir) {
> /* to filter on inbound traffic, invert the match */
> gen_not(b0);
7576a7583,7609
> /*
> * If we have packet meta-data indicating a direction,
> * check it, otherwise give up as this link-layer type
> * has nothing in the packet data.
> */
> #if defined(PF_PACKET) && defined(SO_ATTACH_FILTER)
> /*
> * We infer that this is Linux with PF_PACKET support.
> * If this is a *live* capture, we can look at
> * special meta-data in the filter expression;
> * if it's a savefile, we can't.
> */
> if (bpf_pcap->sf.rfile != NULL) {
> /* We have a FILE *, so this is a savefile */
> bpf_error("inbound/outbound not supported on linktype %d when reading savefiles",
> linktype);
> b0 = NULL;
> /* NOTREACHED */
> }
> /* match outgoing packets */
> b0 = gen_cmp(OR_LINK, SKF_AD_OFF + SKF_AD_PKTTYPE, BPF_H,
> PACKET_OUTGOING);
> if (!dir) {
> /* to filter on inbound traffic, invert the match */
> gen_not(b0);
> }
> #else /* defined(PF_PACKET) && defined(SO_ATTACH_FILTER) */
7580a7614
> #endif /* defined(PF_PACKET) && defined(SO_ATTACH_FILTER) */
< * $FreeBSD: head/contrib/libpcap/gencode.c 235426 2012-05-14 05:12:56Z delphij $
---
> * $FreeBSD: head/contrib/libpcap/gencode.c 241231 2012-10-05 18:42:50Z delphij $
88a89,93
> #if defined(PF_PACKET) && defined(SO_ATTACH_FILTER)
> #include <linux/types.h>
> #include <linux/if_packet.h>
> #include <linux/filter.h>
> #endif
423c428
< int len;
---
> u_int len;
1398d1402
< #ifdef DLT_PFSYNC
1405d1408
< #endif
3361d3363
< #ifdef DLT_PFSYNC
3364d3365
< #endif
5823a5825,5829
> #ifdef INET6
> #ifndef CHASE_CHAIN
> struct block *b2;
> #endif
> #endif
5992c5998,6006
< b1 = gen_cmp(OR_NET, 6, BPF_B, (bpf_int32)v);
---
> /*
> * Also check for a fragment header before the final
> * header.
> */
> b2 = gen_cmp(OR_NET, 6, BPF_B, IPPROTO_FRAGMENT);
> b1 = gen_cmp(OR_NET, 40, BPF_B, (bpf_int32)v);
> gen_and(b2, b1);
> b2 = gen_cmp(OR_NET, 6, BPF_B, (bpf_int32)v);
> gen_or(b2, b1);
7473,7475c7487,7493
< * generate command for inbound/outbound. It's here so we can
< * make it link-type specific. 'dir' = 0 implies "inbound",
< * = 1 implies "outbound".
---
> * Filter on inbound (dir == 0) or outbound (dir == 1) traffic.
> * Outbound traffic is sent by this machine, while inbound traffic is
> * sent by a remote machine (and may include packets destined for a
> * unicast or multicast link-layer address we are not subscribing to).
> * These are the same definitions implemented by pcap_setdirection().
> * Capturing only unicast traffic destined for this host is probably
> * better accomplished using a higher-layer filter.
7505,7521c7523,7527
< if (dir) {
< /*
< * Match packets sent by this machine.
< */
< b0 = gen_cmp(OR_LINK, 0, BPF_H, LINUX_SLL_OUTGOING);
< } else {
< /*
< * Match packets sent to this machine.
< * (No broadcast or multicast packets, or
< * packets sent to some other machine and
< * received promiscuously.)
< *
< * XXX - packets sent to other machines probably
< * shouldn't be matched, but what about broadcast
< * or multicast packets we received?
< */
< b0 = gen_cmp(OR_LINK, 0, BPF_H, LINUX_SLL_HOST);
---
> /* match outgoing packets */
> b0 = gen_cmp(OR_LINK, 0, BPF_H, LINUX_SLL_OUTGOING);
> if (!dir) {
> /* to filter on inbound traffic, invert the match */
> gen_not(b0);
7576a7583,7609
> /*
> * If we have packet meta-data indicating a direction,
> * check it, otherwise give up as this link-layer type
> * has nothing in the packet data.
> */
> #if defined(PF_PACKET) && defined(SO_ATTACH_FILTER)
> /*
> * We infer that this is Linux with PF_PACKET support.
> * If this is a *live* capture, we can look at
> * special meta-data in the filter expression;
> * if it's a savefile, we can't.
> */
> if (bpf_pcap->sf.rfile != NULL) {
> /* We have a FILE *, so this is a savefile */
> bpf_error("inbound/outbound not supported on linktype %d when reading savefiles",
> linktype);
> b0 = NULL;
> /* NOTREACHED */
> }
> /* match outgoing packets */
> b0 = gen_cmp(OR_LINK, SKF_AD_OFF + SKF_AD_PKTTYPE, BPF_H,
> PACKET_OUTGOING);
> if (!dir) {
> /* to filter on inbound traffic, invert the match */
> gen_not(b0);
> }
> #else /* defined(PF_PACKET) && defined(SO_ATTACH_FILTER) */
7580a7614
> #endif /* defined(PF_PACKET) && defined(SO_ATTACH_FILTER) */