Copy DLT_SLIP direction constants from tcpdump and use those to generate
the instructions. Rename gen_inbound() to gen_inbound_outbound(),
rename "dir" to "outbound", replace three if-blocks with a single
statement each. Fixup indentation.
#define ISO10747_IDRP 0x85
#endif
#define ISO10747_IDRP 0x85
#endif
+// Same as in tcpdump/print-sl.c.
+#define SLIPDIR_IN 0
+#define SLIPDIR_OUT 1
#ifdef HAVE_OS_PROTO_H
#include "os-proto.h"
#ifdef HAVE_OS_PROTO_H
#include "os-proto.h"
- * Filter on inbound (dir == 0) or outbound (dir == 1) traffic.
+ * Filter on inbound (outbound == 0) or outbound (outbound == 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).
* 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).
* better accomplished using a higher-layer filter.
*/
struct block *
* better accomplished using a higher-layer filter.
*/
struct block *
-gen_inbound(compiler_state_t *cstate, int dir)
+gen_inbound_outbound(compiler_state_t *cstate, const int outbound)
{
register struct block *b0;
{
register struct block *b0;
b0 = gen_relation_internal(cstate, BPF_JEQ,
gen_load_internal(cstate, Q_LINK, gen_loadi_internal(cstate, 0), 1),
gen_loadi_internal(cstate, 0),
b0 = gen_relation_internal(cstate, BPF_JEQ,
gen_load_internal(cstate, Q_LINK, gen_loadi_internal(cstate, 0), 1),
gen_loadi_internal(cstate, 0),
+ outbound ? SLIPDIR_OUT : SLIPDIR_IN);
- if (dir) {
- /* match outgoing packets */
- b0 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, IPNET_OUTBOUND);
- } else {
- /* match incoming packets */
- b0 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, IPNET_INBOUND);
- }
+ b0 = gen_cmp(cstate, OR_LINKHDR, 2, BPF_H,
+ outbound ? IPNET_OUTBOUND : IPNET_INBOUND);
break;
case DLT_LINUX_SLL:
/* match outgoing packets */
b0 = gen_cmp(cstate, OR_LINKHDR, 0, BPF_H, LINUX_SLL_OUTGOING);
break;
case DLT_LINUX_SLL:
/* match outgoing packets */
b0 = gen_cmp(cstate, OR_LINKHDR, 0, BPF_H, LINUX_SLL_OUTGOING);
/* to filter on inbound traffic, invert the match */
gen_not(b0);
}
/* to filter on inbound traffic, invert the match */
gen_not(b0);
}
case DLT_LINUX_SLL2:
/* match outgoing packets */
b0 = gen_cmp(cstate, OR_LINKHDR, 10, BPF_B, LINUX_SLL_OUTGOING);
case DLT_LINUX_SLL2:
/* match outgoing packets */
b0 = gen_cmp(cstate, OR_LINKHDR, 10, BPF_B, LINUX_SLL_OUTGOING);
/* to filter on inbound traffic, invert the match */
gen_not(b0);
}
/* to filter on inbound traffic, invert the match */
gen_not(b0);
}
case DLT_PFLOG:
b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, dir), BPF_B,
case DLT_PFLOG:
b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, dir), BPF_B,
- ((dir == 0) ? PF_IN : PF_OUT));
+ outbound ? PF_OUT : PF_IN);
break;
case DLT_PPP_PPPD:
break;
case DLT_PPP_PPPD:
- if (dir) {
- /* match outgoing packets */
- b0 = gen_cmp(cstate, OR_LINKHDR, 0, BPF_B, PPP_PPPD_OUT);
- } else {
- /* match incoming packets */
- b0 = gen_cmp(cstate, OR_LINKHDR, 0, BPF_B, PPP_PPPD_IN);
- }
+ b0 = gen_cmp(cstate, OR_LINKHDR, 0, BPF_B, outbound ? PPP_PPPD_OUT : PPP_PPPD_IN);
- case DLT_JUNIPER_MFR:
- case DLT_JUNIPER_MLFR:
- case DLT_JUNIPER_MLPPP:
+ case DLT_JUNIPER_MFR:
+ case DLT_JUNIPER_MLFR:
+ case DLT_JUNIPER_MLPPP:
case DLT_JUNIPER_ATM1:
case DLT_JUNIPER_ATM2:
case DLT_JUNIPER_PPPOE:
case DLT_JUNIPER_PPPOE_ATM:
case DLT_JUNIPER_ATM1:
case DLT_JUNIPER_ATM2:
case DLT_JUNIPER_PPPOE:
case DLT_JUNIPER_PPPOE_ATM:
- case DLT_JUNIPER_GGSN:
- case DLT_JUNIPER_ES:
- case DLT_JUNIPER_MONITOR:
- case DLT_JUNIPER_SERVICES:
- case DLT_JUNIPER_ETHER:
- case DLT_JUNIPER_PPP:
- case DLT_JUNIPER_FRELAY:
- case DLT_JUNIPER_CHDLC:
- case DLT_JUNIPER_VP:
- case DLT_JUNIPER_ST:
- case DLT_JUNIPER_ISM:
- case DLT_JUNIPER_VS:
- case DLT_JUNIPER_SRX_E2E:
- case DLT_JUNIPER_FIBRECHANNEL:
+ case DLT_JUNIPER_GGSN:
+ case DLT_JUNIPER_ES:
+ case DLT_JUNIPER_MONITOR:
+ case DLT_JUNIPER_SERVICES:
+ case DLT_JUNIPER_ETHER:
+ case DLT_JUNIPER_PPP:
+ case DLT_JUNIPER_FRELAY:
+ case DLT_JUNIPER_CHDLC:
+ case DLT_JUNIPER_VP:
+ case DLT_JUNIPER_ST:
+ case DLT_JUNIPER_ISM:
+ case DLT_JUNIPER_VS:
+ case DLT_JUNIPER_SRX_E2E:
+ case DLT_JUNIPER_FIBRECHANNEL:
case DLT_JUNIPER_ATM_CEMIC:
case DLT_JUNIPER_ATM_CEMIC:
/* juniper flags (including direction) are stored
* the byte after the 3-byte magic number */
/* juniper flags (including direction) are stored
* the byte after the 3-byte magic number */
- if (dir) {
- /* match outgoing packets */
- b0 = gen_mcmp(cstate, OR_LINKHDR, 3, BPF_B, 0, 0x01);
- } else {
- /* match incoming packets */
- b0 = gen_mcmp(cstate, OR_LINKHDR, 3, BPF_B, 1, 0x01);
- }
+ b0 = gen_mcmp(cstate, OR_LINKHDR, 3, BPF_B, outbound ? 0 : 1, 0x01);
/* match outgoing packets */
b0 = gen_cmp(cstate, OR_LINKHDR, SKF_AD_OFF + SKF_AD_PKTTYPE, BPF_H,
PACKET_OUTGOING);
/* match outgoing packets */
b0 = gen_cmp(cstate, OR_LINKHDR, SKF_AD_OFF + SKF_AD_PKTTYPE, BPF_H,
PACKET_OUTGOING);
/* to filter on inbound traffic, invert the match */
gen_not(b0);
}
/* to filter on inbound traffic, invert the match */
gen_not(b0);
}
struct block *gen_broadcast(compiler_state_t *, int);
struct block *gen_multicast(compiler_state_t *, int);
struct block *gen_ifindex(compiler_state_t *, int);
struct block *gen_broadcast(compiler_state_t *, int);
struct block *gen_multicast(compiler_state_t *, int);
struct block *gen_ifindex(compiler_state_t *, int);
-struct block *gen_inbound(compiler_state_t *, int);
+struct block *gen_inbound_outbound(compiler_state_t *, int);
struct block *gen_llc(compiler_state_t *);
struct block *gen_llc_i(compiler_state_t *);
struct block *gen_llc(compiler_state_t *);
struct block *gen_llc_i(compiler_state_t *);
| LESS NUM { CHECK_PTR_VAL(($$ = gen_less(cstate, $2))); }
| GREATER NUM { CHECK_PTR_VAL(($$ = gen_greater(cstate, $2))); }
| CBYTE NUM byteop NUM { CHECK_PTR_VAL(($$ = gen_byteop(cstate, $3, $2, $4))); }
| LESS NUM { CHECK_PTR_VAL(($$ = gen_less(cstate, $2))); }
| GREATER NUM { CHECK_PTR_VAL(($$ = gen_greater(cstate, $2))); }
| CBYTE NUM byteop NUM { CHECK_PTR_VAL(($$ = gen_byteop(cstate, $3, $2, $4))); }
- | INBOUND { CHECK_PTR_VAL(($$ = gen_inbound(cstate, 0))); }
- | OUTBOUND { CHECK_PTR_VAL(($$ = gen_inbound(cstate, 1))); }
+ | INBOUND { CHECK_PTR_VAL(($$ = gen_inbound_outbound(cstate, 0))); }
+ | OUTBOUND { CHECK_PTR_VAL(($$ = gen_inbound_outbound(cstate, 1))); }
| IFINDEX NUM { CHECK_PTR_VAL(($$ = gen_ifindex(cstate, $2))); }
| VLAN pnum { CHECK_PTR_VAL(($$ = gen_vlan(cstate, $2, 1))); }
| VLAN { CHECK_PTR_VAL(($$ = gen_vlan(cstate, 0, 0))); }
| IFINDEX NUM { CHECK_PTR_VAL(($$ = gen_ifindex(cstate, $2))); }
| VLAN pnum { CHECK_PTR_VAL(($$ = gen_vlan(cstate, $2, 1))); }
| VLAN { CHECK_PTR_VAL(($$ = gen_vlan(cstate, 0, 0))); }