From: Brenden Blanco <bblanco@plumgrid.com>
To: davem@davemloft.net
Cc: Brenden Blanco <bblanco@plumgrid.com>,
netdev@vger.kernel.org, tom@herbertland.com,
alexei.starovoitov@gmail.com, ogerlitz@mellanox.com,
daniel@iogearbox.net, brouer@redhat.com, eric.dumazet@gmail.com,
ecree@solarflare.com, john.fastabend@gmail.com, tgraf@suug.ch,
johannes@sipsolutions.net, eranlinuxmellanox@gmail.com,
lorenzo@google.com
Subject: [RFC PATCH v2 3/5] rtnl: add option for setting link bpf prog
Date: Thu, 7 Apr 2016 21:48:48 -0700 [thread overview]
Message-ID: <1460090930-11219-3-git-send-email-bblanco@plumgrid.com> (raw)
In-Reply-To: <1460090930-11219-1-git-send-email-bblanco@plumgrid.com>
Sets the bpf program represented by fd as an early filter in the rx path
of the netdev. The fd must have been created as BPF_PROG_TYPE_PHYS_DEV.
Providing a negative value as fd clears the program. Getting the fd back
via rtnl is not possible, therefore reading of this value merely
provides a bool whether the program is valid on the link or not.
Signed-off-by: Brenden Blanco <bblanco@plumgrid.com>
---
include/uapi/linux/if_link.h | 1 +
net/core/rtnetlink.c | 12 ++++++++++++
2 files changed, 13 insertions(+)
diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index 9427f17..ccad234 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -155,6 +155,7 @@ enum {
IFLA_PROTO_DOWN,
IFLA_GSO_MAX_SEGS,
IFLA_GSO_MAX_SIZE,
+ IFLA_BPF_FD,
__IFLA_MAX
};
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index a75f7e9..96579ce 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -910,6 +910,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
+ nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_PORT_ID */
+ nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_SWITCH_ID */
+ nla_total_size(IFNAMSIZ) /* IFLA_PHYS_PORT_NAME */
+ + nla_total_size(4) /* IFLA_BPF_FD */
+ nla_total_size(1); /* IFLA_PROTO_DOWN */
}
@@ -1242,6 +1243,9 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
nla_put_u32(skb, IFLA_CARRIER_CHANGES,
atomic_read(&dev->carrier_changes)) ||
+ (dev->netdev_ops->ndo_bpf_get &&
+ nla_put_s32(skb, IFLA_BPF_FD,
+ dev->netdev_ops->ndo_bpf_get(dev))) ||
nla_put_u8(skb, IFLA_PROTO_DOWN, dev->proto_down))
goto nla_put_failure;
@@ -1375,6 +1379,7 @@ static const struct nla_policy ifla_policy[IFLA_MAX+1] = {
[IFLA_PHYS_SWITCH_ID] = { .type = NLA_BINARY, .len = MAX_PHYS_ITEM_ID_LEN },
[IFLA_LINK_NETNSID] = { .type = NLA_S32 },
[IFLA_PROTO_DOWN] = { .type = NLA_U8 },
+ [IFLA_BPF_FD] = { .type = NLA_S32 },
};
static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {
@@ -2029,6 +2034,13 @@ static int do_setlink(const struct sk_buff *skb,
status |= DO_SETLINK_NOTIFY;
}
+ if (tb[IFLA_BPF_FD]) {
+ err = dev_change_bpf_fd(dev, nla_get_s32(tb[IFLA_BPF_FD]));
+ if (err)
+ goto errout;
+ status |= DO_SETLINK_NOTIFY;
+ }
+
errout:
if (status & DO_SETLINK_MODIFIED) {
if (status & DO_SETLINK_NOTIFY)
--
2.8.0
next prev parent reply other threads:[~2016-04-08 4:48 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-08 4:48 [RFC PATCH v2 1/5] bpf: add PHYS_DEV prog type for early driver filter Brenden Blanco
2016-04-08 4:48 ` [RFC PATCH v2 2/5] net: add ndo to set bpf prog in adapter rx Brenden Blanco
2016-04-08 9:38 ` Jesper Dangaard Brouer
2016-04-08 16:39 ` Brenden Blanco
2016-04-08 4:48 ` Brenden Blanco [this message]
2016-04-08 4:48 ` [RFC PATCH v2 4/5] mlx4: add support for fast rx drop bpf program Brenden Blanco
2016-04-08 11:41 ` Jesper Dangaard Brouer
2016-04-08 17:04 ` Brenden Blanco
2016-04-08 4:48 ` [RFC PATCH v2 5/5] Add sample for adding simple drop program to link Brenden Blanco
2016-04-09 14:48 ` Jamal Hadi Salim
2016-04-09 16:43 ` Brenden Blanco
2016-04-09 17:27 ` Jamal Hadi Salim
2016-04-10 18:38 ` Brenden Blanco
2016-04-13 10:40 ` Jamal Hadi Salim
2016-04-08 10:36 ` [RFC PATCH v2 1/5] bpf: add PHYS_DEV prog type for early driver filter Jesper Dangaard Brouer
2016-04-08 11:09 ` Daniel Borkmann
2016-04-08 16:48 ` Brenden Blanco
2016-04-08 12:33 ` Jesper Dangaard Brouer
2016-04-08 17:02 ` Brenden Blanco
2016-04-08 19:05 ` Jesper Dangaard Brouer
2016-04-08 17:26 ` Alexei Starovoitov
2016-04-08 20:08 ` Jesper Dangaard Brouer
2016-04-08 21:34 ` Alexei Starovoitov
2016-04-09 11:29 ` Tom Herbert
2016-04-09 15:29 ` Jamal Hadi Salim
2016-04-09 17:26 ` Alexei Starovoitov
2016-04-10 7:55 ` Thomas Graf
2016-04-10 16:53 ` Tom Herbert
2016-04-10 18:09 ` Jamal Hadi Salim
2016-04-10 13:07 ` Jamal Hadi Salim
2016-04-09 11:17 ` Tom Herbert
2016-04-09 12:27 ` Jesper Dangaard Brouer
2016-04-09 13:17 ` Tom Herbert
2016-04-09 17:00 ` Alexei Starovoitov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1460090930-11219-3-git-send-email-bblanco@plumgrid.com \
--to=bblanco@plumgrid.com \
--cc=alexei.starovoitov@gmail.com \
--cc=brouer@redhat.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=ecree@solarflare.com \
--cc=eranlinuxmellanox@gmail.com \
--cc=eric.dumazet@gmail.com \
--cc=johannes@sipsolutions.net \
--cc=john.fastabend@gmail.com \
--cc=lorenzo@google.com \
--cc=netdev@vger.kernel.org \
--cc=ogerlitz@mellanox.com \
--cc=tgraf@suug.ch \
--cc=tom@herbertland.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).