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 /lpf.c | |
| 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 'lpf.c')
| -rw-r--r-- | lpf.c | 29 |
1 files changed, 5 insertions, 24 deletions
@@ -38,6 +38,9 @@ # include <linux/filter.h> # include <netpacket/packet.h> # define bpf_insn sock_filter +# define BPF_SKIPTYPE +# define BPF_ETHCOOK -ETH_HLEN +# define BPF_WHOLEPACKET 65535 /* work around buggy LPF filters */ #endif #include <errno.h> @@ -64,27 +67,6 @@ static const uint8_t ipv4_bcast_addr[] = { 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff }; -void -setup_packet_filters(void) -{ -#ifdef __linux__ - /* We need to massage the filters for Linux cooked packets */ - dhcp_bpf_filter[1].jf = 0; /* skip the IP packet type check */ - dhcp_bpf_filter[2].k -= ETH_HLEN; - dhcp_bpf_filter[4].k -= ETH_HLEN; - dhcp_bpf_filter[6].k -= ETH_HLEN; - dhcp_bpf_filter[7].k -= ETH_HLEN; - - arp_bpf_filter[1].jf = 0; /* skip the IP packet type check */ - arp_bpf_filter[2].k -= ETH_HLEN; - - /* Some buggy Linux kernels do not work with ~0U. - * 65536 should be enough for anyone ;) */ - dhcp_bpf_filter[9].k = 65536; - arp_bpf_filter[5].k = 65536; -#endif -} - int open_socket(struct interface *iface, int protocol) { @@ -108,14 +90,13 @@ open_socket(struct interface *iface, int protocol) errno = ENOENT; goto eexit; } - /* Install the DHCP filter */ memset(&pf, 0, sizeof(pf)); if (protocol == ETHERTYPE_ARP) { - pf.filter = arp_bpf_filter; + pf.filter = UNCONST(arp_bpf_filter); pf.len = arp_bpf_filter_len; } else { - pf.filter = dhcp_bpf_filter; + pf.filter = UNCONST(dhcp_bpf_filter); pf.len = dhcp_bpf_filter_len; } if (setsockopt(s, SOL_SOCKET, SO_ATTACH_FILTER, &pf, sizeof(pf)) != 0) |
