From patchwork Fri Apr 8 04:48:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brenden Blanco X-Patchwork-Id: 607827 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3qh6Rw5HHvz9t5h for ; Fri, 8 Apr 2016 14:49:00 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=plumgrid-com.20150623.gappssmtp.com header.i=@plumgrid-com.20150623.gappssmtp.com header.b=XNwY2VKi; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755802AbcDHEs6 (ORCPT ); Fri, 8 Apr 2016 00:48:58 -0400 Received: from mail-pf0-f177.google.com ([209.85.192.177]:34368 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754861AbcDHEs5 (ORCPT ); Fri, 8 Apr 2016 00:48:57 -0400 Received: by mail-pf0-f177.google.com with SMTP id c20so69090758pfc.1 for ; Thu, 07 Apr 2016 21:48:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=plumgrid-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9JJSN/nUo5QooktNiiT644sC5BH4QVSA0gSteQ2nXmU=; b=XNwY2VKiOzFen3jNs8Xs6EoGlABIJvuk0Ou7euLK8VfB26ieQW+gkAl7eJWTgWcChj f2G3FROkBPxPphynMoLTWW2+In+1nqFvFALCjXPzZIOOOLDH8vIc/yf0JME7UAo6uxx/ WLyK3p/OaSHnnMpBrkHYKq/z7XMe04fz1J8kDa09/dLjSVJLhZmAgsHURwn213iy93pi mxobA7TAb8eBOux9uue2PyvDmVHF+yAiff2ECeh/bYWYOYDAp6R/+zeOoujQcM68CjZN VFoBRLcRHNlTDMPrIVa/n16xRnSolyvQN+Jy5d1xLyP5ExLrZiNslyPlq4C/Sf0MFJT7 FPrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9JJSN/nUo5QooktNiiT644sC5BH4QVSA0gSteQ2nXmU=; b=R7F6XWAcrpUfjyEYF2RgdlFbD6BVE62G4fg9fWIgmhZnEWZcd7bRFuNSo/t/A+shNm HJADvp5DertS1S/FZdNEJjRzYLLCZMfsYrs302fltfHqvb7yziUSpA/iH0l+TJ4a8nHH e/zCUfopEenewnDIYDPbGwTsZttXv+a+dvpP4NivkCLT/R9g+BoMr5qcl/HIshxqV54v cTqIs7DqirPqXcSlc8VBzAY/46EyJIXHpf1bpsAtMIWUP//q2VyePG0gCs8ZTWrt4yiJ z0iwjCdIIXTnATEdlGswpnP8lWi3F20yQXOnNk1QLs3pMZXHIM2wPFvT35ZlRS01+2a2 /s8w== X-Gm-Message-State: AD7BkJL8n95Ec4VKzeBtrWLMYkrROiCl5Yl9pF36A+TczphOb5F527S/REdEaWbwDI2TcTFp X-Received: by 10.98.7.24 with SMTP id b24mr9700389pfd.125.1460090936326; Thu, 07 Apr 2016 21:48:56 -0700 (PDT) Received: from iovisor-test1.plumgrid.com ([12.97.19.201]) by smtp.gmail.com with ESMTPSA id r88sm15523595pfi.9.2016.04.07.21.48.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Apr 2016 21:48:55 -0700 (PDT) From: Brenden Blanco To: davem@davemloft.net Cc: Brenden Blanco , 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 2/5] net: add ndo to set bpf prog in adapter rx Date: Thu, 7 Apr 2016 21:48:47 -0700 Message-Id: <1460090930-11219-2-git-send-email-bblanco@plumgrid.com> X-Mailer: git-send-email 2.8.0 In-Reply-To: <1460090930-11219-1-git-send-email-bblanco@plumgrid.com> References: <1460090930-11219-1-git-send-email-bblanco@plumgrid.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add two new set/get netdev ops for drivers implementing the BPF_PROG_TYPE_PHYS_DEV filter. Signed-off-by: Brenden Blanco --- include/linux/netdevice.h | 13 +++++++++++++ net/core/dev.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index cb4e508..3acf732 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -61,6 +61,7 @@ struct wireless_dev; /* 802.15.4 specific */ struct wpan_dev; struct mpls_dev; +struct bpf_prog; void netdev_set_default_ethtool_ops(struct net_device *dev, const struct ethtool_ops *ops); @@ -1102,6 +1103,14 @@ struct tc_to_netdev { * appropriate rx headroom value allows avoiding skb head copy on * forward. Setting a negative value resets the rx headroom to the * default value. + * int (*ndo_bpf_set)(struct net_device *dev, struct bpf_prog *prog); + * This function is used to set or clear a bpf program used in the + * earliest stages of packet rx. The prog will have been loaded as + * BPF_PROG_TYPE_PHYS_DEV. The callee is responsible for calling + * bpf_prog_put on any old progs that are stored, but not on the passed + * in prog. + * bool (*ndo_bpf_get)(struct net_device *dev); + * This function is used to check if a bpf program is set on the device. * */ struct net_device_ops { @@ -1292,6 +1301,9 @@ struct net_device_ops { struct sk_buff *skb); void (*ndo_set_rx_headroom)(struct net_device *dev, int needed_headroom); + int (*ndo_bpf_set)(struct net_device *dev, + struct bpf_prog *prog); + bool (*ndo_bpf_get)(struct net_device *dev); }; /** @@ -3251,6 +3263,7 @@ int dev_get_phys_port_id(struct net_device *dev, int dev_get_phys_port_name(struct net_device *dev, char *name, size_t len); int dev_change_proto_down(struct net_device *dev, bool proto_down); +int dev_change_bpf_fd(struct net_device *dev, int fd); struct sk_buff *validate_xmit_skb_list(struct sk_buff *skb, struct net_device *dev); struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev, struct netdev_queue *txq, int *ret); diff --git a/net/core/dev.c b/net/core/dev.c index 273f10d..7cf749c 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -94,6 +94,7 @@ #include #include #include +#include #include #include #include @@ -6483,6 +6484,43 @@ int dev_change_proto_down(struct net_device *dev, bool proto_down) EXPORT_SYMBOL(dev_change_proto_down); /** + * dev_change_bpf_fd - set or clear a bpf program for a device + * @dev: device + * @fd: new program fd or negative value to clear + * + * Set or clear a bpf program for a device + */ +int dev_change_bpf_fd(struct net_device *dev, int fd) +{ + const struct net_device_ops *ops = dev->netdev_ops; + struct bpf_prog *prog = NULL; + int err; + + if (!ops->ndo_bpf_set) + return -EOPNOTSUPP; + if (!netif_device_present(dev)) + return -ENODEV; + + if (fd >= 0) { + prog = bpf_prog_get(fd); + if (IS_ERR(prog)) + return PTR_ERR(prog); + + if (prog->type != BPF_PROG_TYPE_PHYS_DEV) { + bpf_prog_put(prog); + return -EINVAL; + } + } + + err = ops->ndo_bpf_set(dev, prog); + if (err < 0 && prog) + bpf_prog_put(prog); + + return err; +} +EXPORT_SYMBOL(dev_change_bpf_fd); + +/** * dev_new_index - allocate an ifindex * @net: the applicable net namespace *