summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2019-04-18 16:56:34 +0100
committerRoy Marples <roy@marples.name>2019-04-18 16:56:34 +0100
commit1e78fa81dc3e06ffac539d051636c45d61394748 (patch)
tree9bc7447b06ce904f3d16c526d3f36c8829dce7c0
parent283f5c4e7c938e3628afa255cbd1eac231f34fbe (diff)
downloaddhcpcd-1e78fa81dc3e06ffac539d051636c45d61394748.tar.xz
BPF: Set flag indicate whether the packet was broadcast or not
-rw-r--r--src/bpf.c27
-rw-r--r--src/bpf.h1
2 files changed, 25 insertions, 3 deletions
diff --git a/src/bpf.c b/src/bpf.c
index c2c14dc8..81d3a1c6 100644
--- a/src/bpf.c
+++ b/src/bpf.c
@@ -84,7 +84,7 @@ size_t
bpf_frame_header_len(const struct interface *ifp)
{
- switch(ifp->family) {
+ switch (ifp->family) {
case ARPHRD_ETHER:
return sizeof(struct ether_header);
default:
@@ -92,6 +92,23 @@ bpf_frame_header_len(const struct interface *ifp)
}
}
+static const uint8_t etherbroadcastaddr[] =
+ { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+
+static int
+bpf_frame_bcast(const struct interface *ifp, const char *frame)
+{
+
+ switch (ifp->family) {
+ case ARPHRD_ETHER:
+ return memcmp(frame +
+ offsetof(struct ether_header, ether_dhost),
+ etherbroadcastaddr, sizeof(etherbroadcastaddr));
+ default:
+ return -1;
+ }
+}
+
#ifndef __linux__
/* Linux is a special snowflake for opening, attaching and reading BPF.
* See if-linux.c for the Linux specific BPF functions. */
@@ -227,8 +244,12 @@ bpf_read(struct interface *ifp, int fd, void *data, size_t len,
if (state->buffer_pos + packet.bh_caplen + packet.bh_hdrlen >
state->buffer_len)
goto next; /* Packet beyond buffer, drop. */
- payload = state->buffer + state->buffer_pos +
- packet.bh_hdrlen + fl;
+ payload = state->buffer + state->buffer_pos + packet.bh_hdrlen;
+ if (bpf_frame_bcast(ifp, payload) == 0)
+ *flags |= BPF_BCAST;
+ else
+ *flags &= ~BPF_BCAST;
+ payload += fl;
bytes = (ssize_t)packet.bh_caplen - fl;
if ((size_t)bytes > len)
bytes = (ssize_t)len;
diff --git a/src/bpf.h b/src/bpf.h
index 91ca16e2..f3ce5434 100644
--- a/src/bpf.h
+++ b/src/bpf.h
@@ -31,6 +31,7 @@
#define BPF_READING (1U << 0)
#define BPF_EOF (1U << 1)
#define BPF_PARTIALCSUM (1U << 2)
+#define BPF_BCAST (1U << 3)
#include "dhcpcd.h"