summaryrefslogtreecommitdiff
path: root/src/l2_packet/l2_packet_linux.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/l2_packet/l2_packet_linux.c')
-rw-r--r--src/l2_packet/l2_packet_linux.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/l2_packet/l2_packet_linux.c b/src/l2_packet/l2_packet_linux.c
index a7a300e568e6d..291c9dd263a6e 100644
--- a/src/l2_packet/l2_packet_linux.c
+++ b/src/l2_packet/l2_packet_linux.c
@@ -84,6 +84,26 @@ static const struct sock_fprog ndisc_sock_filter = {
.filter = ndisc_sock_filter_insns,
};
+/* drop packet if skb->pkt_type is PACKET_OTHERHOST (0x03). Generated by:
+ * $ bpfc - <<EOF
+ * > ldb #type
+ * > jeq #0x03, drop
+ * > pass: ret #-1
+ * > drop: ret #0
+ * > EOF
+ */
+static struct sock_filter pkt_type_filter_insns[] = {
+ { 0x30, 0, 0, 0xfffff004 },
+ { 0x15, 1, 0, 0x00000003 },
+ { 0x6, 0, 0, 0xffffffff },
+ { 0x6, 0, 0, 0x00000000 },
+};
+
+static const struct sock_fprog pkt_type_sock_filter = {
+ .len = ARRAY_SIZE(pkt_type_filter_insns),
+ .filter = pkt_type_filter_insns,
+};
+
int l2_packet_get_own_addr(struct l2_packet_data *l2, u8 *addr)
{
@@ -96,6 +116,9 @@ int l2_packet_send(struct l2_packet_data *l2, const u8 *dst_addr, u16 proto,
const u8 *buf, size_t len)
{
int ret;
+
+ if (TEST_FAIL())
+ return -1;
if (l2 == NULL)
return -1;
if (l2->l2_hdr) {
@@ -458,6 +481,9 @@ int l2_packet_set_packet_filter(struct l2_packet_data *l2,
{
const struct sock_fprog *sock_filter;
+ if (TEST_FAIL())
+ return -1;
+
switch (type) {
case L2_PACKET_FILTER_DHCP:
sock_filter = &dhcp_sock_filter;
@@ -465,6 +491,9 @@ int l2_packet_set_packet_filter(struct l2_packet_data *l2,
case L2_PACKET_FILTER_NDISC:
sock_filter = &ndisc_sock_filter;
break;
+ case L2_PACKET_FILTER_PKTTYPE:
+ sock_filter = &pkt_type_sock_filter;
+ break;
default:
return -1;
}