diff options
| author | Roy Marples <roy@marples.name> | 2008-05-22 13:59:33 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2008-05-22 13:59:33 +0000 |
| commit | bed0c5d411bfa910a7adc19613575de27bddf0bd (patch) | |
| tree | 4041fb2851421741e676106c5466805d4bc9173b /bpf-filter.h | |
| parent | b604c3de5b04d1a5e0e68e5f2e54aae731e91d62 (diff) | |
| download | dhcpcd-bed0c5d411bfa910a7adc19613575de27bddf0bd.tar.xz | |
Use constant BPF structures and defines to alter the data instead of functions. Smaller code :)
Diffstat (limited to 'bpf-filter.h')
| -rw-r--r-- | bpf-filter.h | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/bpf-filter.h b/bpf-filter.h index 59118039..16930dd0 100644 --- a/bpf-filter.h +++ b/bpf-filter.h @@ -24,53 +24,60 @@ * SUCH DAMAGE. */ -/* Credit where credit is due :) - * The below BPF filter is taken from ISC DHCP */ -static struct bpf_insn dhcp_bpf_filter [] = { +#ifndef BPF_ETHCOOK +# define BPF_ETHCOOK 0 +#endif +#ifndef BPF_WHOLEPACKET +# define BPF_WHOLEPACKET ~0U +#endif + +static const struct bpf_insn const dhcp_bpf_filter [] = { +#ifndef BPF_SKIPTYPE /* Make sure this is an IP packet... */ - BPF_STMT (BPF_LD + BPF_H + BPF_ABS, 12), - BPF_JUMP (BPF_JMP + BPF_JEQ + BPF_K, ETHERTYPE_IP, 0, 8), + BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 12), + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ETHERTYPE_IP, 0, 8), +#endif /* Make sure it's a UDP packet... */ - BPF_STMT (BPF_LD + BPF_B + BPF_ABS, 23), - BPF_JUMP (BPF_JMP + BPF_JEQ + BPF_K, IPPROTO_UDP, 0, 6), + BPF_STMT(BPF_LD + BPF_B + BPF_ABS, 23 + BPF_ETHCOOK), + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, IPPROTO_UDP, 0, 6), /* Make sure this isn't a fragment... */ - BPF_STMT (BPF_LD + BPF_H + BPF_ABS, 20), - BPF_JUMP (BPF_JMP + BPF_JSET + BPF_K, 0x1fff, 4, 0), + BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 20 + BPF_ETHCOOK), + BPF_JUMP(BPF_JMP + BPF_JSET + BPF_K, 0x1fff, 4, 0), /* Get the IP header length... */ - BPF_STMT (BPF_LDX + BPF_B + BPF_MSH, 14), + BPF_STMT(BPF_LDX + BPF_B + BPF_MSH, 14 + BPF_ETHCOOK), /* Make sure it's to the right port... */ - BPF_STMT (BPF_LD + BPF_H + BPF_IND, 16), - BPF_JUMP (BPF_JMP + BPF_JEQ + BPF_K, DHCP_CLIENT_PORT, 0, 1), + BPF_STMT(BPF_LD + BPF_H + BPF_IND, 16 + BPF_ETHCOOK), + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, DHCP_CLIENT_PORT, 0, 1), /* If we passed all the tests, ask for the whole packet. */ - BPF_STMT (BPF_RET + BPF_K, ~0U), + BPF_STMT(BPF_RET + BPF_K, BPF_WHOLEPACKET), /* Otherwise, drop it. */ - BPF_STMT (BPF_RET + BPF_K, 0), + BPF_STMT(BPF_RET + BPF_K, 0), }; static const size_t dhcp_bpf_filter_len = sizeof(dhcp_bpf_filter) / sizeof(dhcp_bpf_filter[0]); - -/* This, however, is mine */ -static struct bpf_insn arp_bpf_filter [] = { +static const struct bpf_insn const arp_bpf_filter [] = { +#ifndef BPF_SKIPTYPE /* Make sure this is an ARP packet... */ - BPF_STMT (BPF_LD + BPF_H + BPF_ABS, 12), - BPF_JUMP (BPF_JMP + BPF_JEQ + BPF_K, ETHERTYPE_ARP, 0, 3), + BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 12), + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ETHERTYPE_ARP, 0, 3), +#endif /* Make sure this is an ARP REPLY... */ - BPF_STMT (BPF_LD + BPF_H + BPF_ABS, 20), - BPF_JUMP (BPF_JMP + BPF_JEQ + BPF_K, ARPOP_REPLY, 0, 1), + BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 20 + BPF_ETHCOOK), + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ARPOP_REPLY, 0, 1), /* If we passed all the tests, ask for the whole packet. */ - BPF_STMT (BPF_RET + BPF_K, ~0U), + BPF_STMT(BPF_RET + BPF_K, BPF_WHOLEPACKET), /* Otherwise, drop it. */ - BPF_STMT (BPF_RET + BPF_K, 0), + BPF_STMT(BPF_RET + BPF_K, 0), }; static const size_t arp_bpf_filter_len = sizeof(arp_bpf_filter) / sizeof(arp_bpf_filter[0]); |
