]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Put my code at the top and UNCONST filters in bpf.c
authorRoy Marples <roy@marples.name>
Thu, 22 May 2008 18:16:22 +0000 (18:16 +0000)
committerRoy Marples <roy@marples.name>
Thu, 22 May 2008 18:16:22 +0000 (18:16 +0000)
bpf-filter.h
bpf.c

index dbc3aaf7b11bf0acc3c4e0812a669bd53b16a6fc..adcc8bbb42609c60795d98b59976455366b43866 100644 (file)
@@ -1,3 +1,56 @@
+/*
+ * dhcpcd - DHCP client daemon
+ * Copyright 2006-2008 Roy Marples <roy@marples.name>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef BPF_ETHCOOK
+# define BPF_ETHCOOK 0
+#endif
+#ifndef BPF_WHOLEPACKET
+# define BPF_WHOLEPACKET ~0U
+#endif
+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),
+#endif
+
+       /* Make sure this is an ARP REPLY... */
+       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, BPF_WHOLEPACKET),
+
+       /* Otherwise, drop it. */
+       BPF_STMT(BPF_RET + BPF_K, 0),
+};
+static const size_t arp_bpf_filter_len =
+    sizeof(arp_bpf_filter) / sizeof(arp_bpf_filter[0]);
+
+
 /* dhcp_bpf_filter taken from bpf.c in dhcp-3.1.0
  *
  * Copyright (c) 2004,2007 by Internet Systems Consortium, Inc. ("ISC")
  *   http://www.isc.org/
  */
 
-/* #defines added by Roy Marples <roy@marples.name> so the same filter
- * easily works on Linux packet 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... */
@@ -62,51 +105,3 @@ static const struct bpf_insn const dhcp_bpf_filter [] = {
 };
 static const size_t dhcp_bpf_filter_len =
     sizeof(dhcp_bpf_filter) / sizeof(dhcp_bpf_filter[0]);
-
-
-
-/*
- * dhcpcd - DHCP client daemon
- * Copyright 2006-2008 Roy Marples <roy@marples.name>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-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),
-#endif
-
-       /* Make sure this is an ARP REPLY... */
-       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, BPF_WHOLEPACKET),
-
-       /* Otherwise, drop it. */
-       BPF_STMT(BPF_RET + BPF_K, 0),
-};
-static const size_t arp_bpf_filter_len =
-    sizeof(arp_bpf_filter) / sizeof(arp_bpf_filter[0]);
diff --git a/bpf.c b/bpf.c
index f22a6d110be306778d4457ee00f3dfee41326316..37a92f3d205f2581183d1754bb612c38d24a9131 100644 (file)
--- a/bpf.c
+++ b/bpf.c
@@ -107,10 +107,10 @@ open_socket(struct interface *iface, int protocol)
 
        /* Install the DHCP filter */
        if (protocol == ETHERTYPE_ARP) {
-               pf.bf_insns = arp_bpf_filter;
+               pf.bf_insns = UNCONST(arp_bpf_filter);
                pf.bf_len = arp_bpf_filter_len;
        } else {
-               pf.bf_insns = dhcp_bpf_filter;
+               pf.bf_insns = UNCONST(dhcp_bpf_filter);
                pf.bf_len = dhcp_bpf_filter_len;
        }
        if (ioctl(fd, BIOCSETF, &pf) == -1)