From patchwork Fri Nov 24 02:11:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 840931 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="eP0ZVSwg"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yjfqF4Qbhz9s9Y for ; Fri, 24 Nov 2017 13:12:57 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752227AbdKXCMW (ORCPT ); Thu, 23 Nov 2017 21:12:22 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:34142 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751869AbdKXCMT (ORCPT ); Thu, 23 Nov 2017 21:12:19 -0500 Received: by mail-pf0-f195.google.com with SMTP id k24so4422716pfb.1 for ; Thu, 23 Nov 2017 18:12:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JExNedzmT8b+TW4Kt9/kxJKRIwC+g4K1z+3pikW7R/c=; b=eP0ZVSwgHYQb/DKHqIdrwK8xigrf+IT1piOXOYDwowAnCCv4uU2nsrrAienhXXWmFi FC0zEMZlrftAnhKEeX8ME1UZ5SQowBwb2rsNKO1p++QSMdQxs1ji694UxrZchd/NVst8 PTi5OuW2mkKjM44Qd/mZyb1Akap63AGxwVWTVbeNE2T4KbVt5xIbKQe13q+yl+DdjuZx GRdc4KMjLUambssmpm2m0OLToX3RtGsYGyuWWzsyFY5EwN6MJwK2rZkO854rRLvmR/kQ IQhLugWtJq8lcn4DAGfYaJIcq5K7fbuvvU38jZ9SRQBo3mHibUgbDoaN1cjBFLNfOKMS IjqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JExNedzmT8b+TW4Kt9/kxJKRIwC+g4K1z+3pikW7R/c=; b=eQrRYUIFr6was7Rmo5oW95DWYvPAp3zT1ZwzGThCTf98oQUQrzPQzUXb1MaC13nS4h Ymf51CAn2PX2i2pbEsLwQY+gzbGcwMYpFOz75+DLHmWIXi391xHRiViJ4psy6kMpavrb Z0jb25DoaQnN9jQoMe5JFR/VPms6x+flA/18RRkfJY4e08amxURQWkb7JslMmiUhOWz0 6iXzFSxEMiFayl3hXzondEsrFzZqmypB/Mz98gCkYEpERP98PlsbtwZrhzg2wMKAuSK9 +H1UbmHMzfrcLe9U8U71oiaPZc9EZSqJTm+dj8Z22nvQU06FYDipOcMcNaIpNpj9rNKd 8o/w== X-Gm-Message-State: AJaThX6k9njPTeHbTyMOYI7sBf8eoYu0816/Xsk7hIbCJwV08TIYzA7H LkLXy4cRGlozZPJaqvtG2Q0mGeDY X-Google-Smtp-Source: AGs4zMbM39Wwi4pFhwJW8/sCoorh48IKkm9AUfSigW98eaCTwLotxQlh98o+0nyP0ZeLxgKgqVRvXQ== X-Received: by 10.98.238.12 with SMTP id e12mr24940702pfi.223.1511489538264; Thu, 23 Nov 2017 18:12:18 -0800 (PST) Received: from jkicinski-Precision-T1700.netronome.com ([75.53.12.129]) by smtp.gmail.com with ESMTPSA id q12sm29400889pgn.56.2017.11.23.18.12.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 23 Nov 2017 18:12:17 -0800 (PST) From: Jakub Kicinski To: netdev@vger.kernel.org Cc: oss-drivers@netronome.com, daniel@iogearbox.net, Jakub Kicinski Subject: [PATCH iproute2/master 01/11] bpf: pass program type in struct bpf_cfg_in Date: Thu, 23 Nov 2017 18:11:58 -0800 Message-Id: <20171124021208.13419-2-jakub.kicinski@netronome.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171124021208.13419-1-jakub.kicinski@netronome.com> References: <20171124021208.13419-1-jakub.kicinski@netronome.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Program type is needed both for parsing and loading of the program. Parsing may also induce the type based on signatures from __bpf_prog_meta. Instead of passing the type around keep it in struct bpf_cfg_in. Signed-off-by: Jakub Kicinski Reviewed-by: Quentin Monnet Acked-by: Daniel Borkmann --- include/bpf_util.h | 5 +++-- ip/iplink_xdp.c | 3 ++- ip/iproute_lwtunnel.c | 3 ++- lib/bpf.c | 38 +++++++++++++++++++------------------- tc/f_bpf.c | 3 ++- tc/m_bpf.c | 3 ++- 6 files changed, 30 insertions(+), 25 deletions(-) diff --git a/include/bpf_util.h b/include/bpf_util.h index e818221d70d9..0da4b85c979a 100644 --- a/include/bpf_util.h +++ b/include/bpf_util.h @@ -60,6 +60,7 @@ struct bpf_cfg_in { const char *object; const char *section; const char *uds; + enum bpf_prog_type type; int argc; char **argv; struct sock_filter *ops; @@ -244,8 +245,8 @@ struct bpf_cfg_in { .off = 0, \ .imm = 0 }) -int bpf_parse_common(enum bpf_prog_type type, struct bpf_cfg_in *cfg, - const struct bpf_cfg_ops *ops, void *nl); +int bpf_parse_common(struct bpf_cfg_in *cfg, const struct bpf_cfg_ops *ops, + void *nl); const char *bpf_prog_to_default_section(enum bpf_prog_type type); diff --git a/ip/iplink_xdp.c b/ip/iplink_xdp.c index 2d2953aa47a8..993e44d7878a 100644 --- a/ip/iplink_xdp.c +++ b/ip/iplink_xdp.c @@ -52,6 +52,7 @@ int xdp_parse(int *argc, char ***argv, struct iplink_req *req, bool generic, bool drv, bool offload) { struct bpf_cfg_in cfg = { + .type = BPF_PROG_TYPE_XDP, .argc = *argc, .argv = *argv, }; @@ -74,7 +75,7 @@ int xdp_parse(int *argc, char ***argv, struct iplink_req *req, bool generic, return xdp_delete(&xdp); } - if (bpf_parse_common(BPF_PROG_TYPE_XDP, &cfg, &bpf_cb_ops, &xdp)) + if (bpf_parse_common(&cfg, &bpf_cb_ops, &xdp)) return -1; *argc = cfg.argc; diff --git a/ip/iproute_lwtunnel.c b/ip/iproute_lwtunnel.c index 1c8adbe78ed2..9f0f647e261f 100644 --- a/ip/iproute_lwtunnel.c +++ b/ip/iproute_lwtunnel.c @@ -872,6 +872,7 @@ static int lwt_parse_bpf(struct rtattr *rta, size_t len, int attr, const enum bpf_prog_type bpf_type) { struct bpf_cfg_in cfg = { + .type = bpf_type, .argc = *argcp, .argv = *argvp, }; @@ -883,7 +884,7 @@ static int lwt_parse_bpf(struct rtattr *rta, size_t len, int err; nest = rta_nest(rta, len, attr); - err = bpf_parse_common(bpf_type, &cfg, &bpf_cb_ops, &x); + err = bpf_parse_common(&cfg, &bpf_cb_ops, &x); if (err < 0) { fprintf(stderr, "Failed to parse eBPF program: %s\n", strerror(-err)); diff --git a/lib/bpf.c b/lib/bpf.c index fdc28772fb71..5e65682b5ea4 100644 --- a/lib/bpf.c +++ b/lib/bpf.c @@ -813,8 +813,8 @@ enum bpf_mode { BPF_MODE_MAX, }; -static int bpf_parse(enum bpf_prog_type *type, enum bpf_mode *mode, - struct bpf_cfg_in *cfg, const bool *opt_tbl) +static int bpf_parse(enum bpf_mode *mode, struct bpf_cfg_in *cfg, + const bool *opt_tbl) { const char *file, *section, *uds_name; bool verbose = false; @@ -852,7 +852,7 @@ static int bpf_parse(enum bpf_prog_type *type, enum bpf_mode *mode, file = *argv; NEXT_ARG_FWD(); - if (*type == BPF_PROG_TYPE_UNSPEC) { + if (cfg->type == BPF_PROG_TYPE_UNSPEC) { if (argc > 0 && matches(*argv, "type") == 0) { NEXT_ARG(); for (i = 0; i < ARRAY_SIZE(__bpf_prog_meta); @@ -861,30 +861,30 @@ static int bpf_parse(enum bpf_prog_type *type, enum bpf_mode *mode, continue; if (!matches(*argv, __bpf_prog_meta[i].type)) { - *type = i; + cfg->type = i; break; } } - if (*type == BPF_PROG_TYPE_UNSPEC) { + if (cfg->type == BPF_PROG_TYPE_UNSPEC) { fprintf(stderr, "What type is \"%s\"?\n", *argv); return -1; } NEXT_ARG_FWD(); } else { - *type = BPF_PROG_TYPE_SCHED_CLS; + cfg->type = BPF_PROG_TYPE_SCHED_CLS; } } - section = bpf_prog_to_default_section(*type); + section = bpf_prog_to_default_section(cfg->type); if (argc > 0 && matches(*argv, "section") == 0) { NEXT_ARG(); section = *argv; NEXT_ARG_FWD(); } - if (__bpf_prog_meta[*type].may_uds_export) { + if (__bpf_prog_meta[cfg->type].may_uds_export) { uds_name = getenv(BPF_ENV_UDS); if (argc > 0 && !uds_name && matches(*argv, "export") == 0) { @@ -905,9 +905,9 @@ static int bpf_parse(enum bpf_prog_type *type, enum bpf_mode *mode, if (*mode == CBPF_BYTECODE || *mode == CBPF_FILE) ret = bpf_ops_parse(argc, argv, cfg->ops, *mode == CBPF_FILE); else if (*mode == EBPF_OBJECT) - ret = bpf_obj_open(file, *type, section, verbose); + ret = bpf_obj_open(file, cfg->type, section, verbose); else if (*mode == EBPF_PINNED) - ret = bpf_obj_pinned(file, *type); + ret = bpf_obj_pinned(file, cfg->type); else return -1; @@ -920,7 +920,7 @@ static int bpf_parse(enum bpf_prog_type *type, enum bpf_mode *mode, return ret; } -static int bpf_parse_opt_tbl(enum bpf_prog_type type, struct bpf_cfg_in *cfg, +static int bpf_parse_opt_tbl(struct bpf_cfg_in *cfg, const struct bpf_cfg_ops *ops, void *nl, const bool *opt_tbl) { @@ -930,7 +930,7 @@ static int bpf_parse_opt_tbl(enum bpf_prog_type type, struct bpf_cfg_in *cfg, int ret; cfg->ops = opcodes; - ret = bpf_parse(&type, &mode, cfg, opt_tbl); + ret = bpf_parse(&mode, cfg, opt_tbl); cfg->ops = NULL; if (ret < 0) return ret; @@ -947,8 +947,8 @@ static int bpf_parse_opt_tbl(enum bpf_prog_type type, struct bpf_cfg_in *cfg, return 0; } -int bpf_parse_common(enum bpf_prog_type type, struct bpf_cfg_in *cfg, - const struct bpf_cfg_ops *ops, void *nl) +int bpf_parse_common(struct bpf_cfg_in *cfg, const struct bpf_cfg_ops *ops, + void *nl) { bool opt_tbl[BPF_MODE_MAX] = {}; @@ -962,12 +962,11 @@ int bpf_parse_common(enum bpf_prog_type type, struct bpf_cfg_in *cfg, opt_tbl[EBPF_PINNED] = true; } - return bpf_parse_opt_tbl(type, cfg, ops, nl, opt_tbl); + return bpf_parse_opt_tbl(cfg, ops, nl, opt_tbl); } int bpf_graft_map(const char *map_path, uint32_t *key, int argc, char **argv) { - enum bpf_prog_type type = BPF_PROG_TYPE_UNSPEC; const bool opt_tbl[BPF_MODE_MAX] = { [EBPF_OBJECT] = true, [EBPF_PINNED] = true, @@ -978,6 +977,7 @@ int bpf_graft_map(const char *map_path, uint32_t *key, int argc, char **argv) .size_value = sizeof(int), }; struct bpf_cfg_in cfg = { + .type = BPF_PROG_TYPE_UNSPEC, .argc = argc, .argv = argv, }; @@ -986,7 +986,7 @@ int bpf_graft_map(const char *map_path, uint32_t *key, int argc, char **argv) enum bpf_mode mode; uint32_t map_key; - prog_fd = bpf_parse(&type, &mode, &cfg, opt_tbl); + prog_fd = bpf_parse(&mode, &cfg, opt_tbl); if (prog_fd < 0) return prog_fd; if (key) { @@ -1000,7 +1000,7 @@ int bpf_graft_map(const char *map_path, uint32_t *key, int argc, char **argv) } } - map_fd = bpf_obj_get(map_path, type); + map_fd = bpf_obj_get(map_path, cfg.type); if (map_fd < 0) { fprintf(stderr, "Couldn\'t retrieve pinned map \'%s\': %s\n", map_path, strerror(errno)); @@ -1010,7 +1010,7 @@ int bpf_graft_map(const char *map_path, uint32_t *key, int argc, char **argv) ret = bpf_map_selfcheck_pinned(map_fd, &test, &ext, offsetof(struct bpf_elf_map, max_elem), - type); + cfg.type); if (ret < 0) { fprintf(stderr, "Map \'%s\' self-check failed!\n", map_path); goto out_map; diff --git a/tc/f_bpf.c b/tc/f_bpf.c index 3f619d0dc738..a38ec2ab7786 100644 --- a/tc/f_bpf.c +++ b/tc/f_bpf.c @@ -103,10 +103,11 @@ static int bpf_parse_opt(struct filter_util *qu, char *handle, NEXT_ARG(); opt_bpf: seen_run = true; + cfg.type = bpf_type; cfg.argc = argc; cfg.argv = argv; - if (bpf_parse_common(bpf_type, &cfg, &bpf_cb_ops, n)) + if (bpf_parse_common(&cfg, &bpf_cb_ops, n)) return -1; argc = cfg.argc; diff --git a/tc/m_bpf.c b/tc/m_bpf.c index e3d0a2b11838..f2ce3892e4ed 100644 --- a/tc/m_bpf.c +++ b/tc/m_bpf.c @@ -98,10 +98,11 @@ static int bpf_parse_opt(struct action_util *a, int *ptr_argc, char ***ptr_argv, NEXT_ARG(); opt_bpf: seen_run = true; + cfg.type = bpf_type; cfg.argc = argc; cfg.argv = argv; - if (bpf_parse_common(bpf_type, &cfg, &bpf_cb_ops, n)) + if (bpf_parse_common(&cfg, &bpf_cb_ops, n)) return -1; argc = cfg.argc; From patchwork Fri Nov 24 02:11:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 840924 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="Qde9B/U2"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yjfpd1d5Cz9s9Y for ; Fri, 24 Nov 2017 13:12:25 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752271AbdKXCMX (ORCPT ); Thu, 23 Nov 2017 21:12:23 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:35366 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751575AbdKXCMU (ORCPT ); Thu, 23 Nov 2017 21:12:20 -0500 Received: by mail-pg0-f68.google.com with SMTP id l19so14675879pgo.2 for ; Thu, 23 Nov 2017 18:12:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UJaiGrIj4r58XyTtK/LcZnxS4pnL/ydZSpporXcD9nM=; b=Qde9B/U2c4M05RbJAFGOCt2oQqFzMx6m3oqooufGyHLdQgmwjDtxuvcVWtdUJNaSrm 24Lde1jfu3ctpsumgHrjNSkiT7Pazp1RiUiFyddAjlPNOmeLZmrE4doPKJyAdh0BC58Z j529kPY1xixPospjzDGKRiecjAhfdMKMA+/ekiSne7M11rdd8Iq8YGE7ruSFq9Q+M5WQ y20DOhc0WXY6+Amtg2ThOWWHogWPgdLchd9dwJDqTzQngb8XimceDsyo1uDAwO+ZoNoC a8kKvGSoanxG5Iceg/Yq7kuOpiu5kdH+3EwduNV/8ukewuL9xEhYhTjQvGUs9WxKQx12 fB6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UJaiGrIj4r58XyTtK/LcZnxS4pnL/ydZSpporXcD9nM=; b=pwyQ1EtzOXBs/7VX5YzusWN75/KdHx4WHaoI+OqhY7zcIJJVf4IgD1ePTaGH+BIkla hbJnTVTsA4OXNV/4C7tYEy4/zDrNCF8hBviMss4/9qwqn4xRH5suUwgwuOgtST+C1Bc2 G4cVW3Z13tPUC63vgGAsEiYAZww3yv+BPUexEoc+NcWRvgnRXIokzRTCnDEsMFhAFykt 0wXIUYOlxrLYGf85QCMRo+0MaDJC5oJdah/DuE7gD0jSmEJxId/Ie85Q16BRPdom3Rg4 MNKrfA6KM2oXdaX3MV+yB55CGdmHBIh1UrFFUjBnEVxshP01W3GBsNSVS/0O4qXUuoam flrQ== X-Gm-Message-State: AJaThX5oc+pgLOdHkZ1kVURh24Z0eeBa3c+XIk7bCvshFW/MqtLpGzCT McsZqNuI63B4ckbnbqkyGsCfdv7z X-Google-Smtp-Source: AGs4zMbwk7ZRw4bSdmBBd9MhY4wQEXrqioX4IV9Wvflejv4LXa95TaRw8P/eml5G/rkj+4kgimfATg== X-Received: by 10.99.116.30 with SMTP id p30mr26244256pgc.303.1511489539374; Thu, 23 Nov 2017 18:12:19 -0800 (PST) Received: from jkicinski-Precision-T1700.netronome.com ([75.53.12.129]) by smtp.gmail.com with ESMTPSA id q12sm29400889pgn.56.2017.11.23.18.12.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 23 Nov 2017 18:12:18 -0800 (PST) From: Jakub Kicinski To: netdev@vger.kernel.org Cc: oss-drivers@netronome.com, daniel@iogearbox.net, Jakub Kicinski Subject: [PATCH iproute2/master 02/11] bpf: keep parsed program mode in struct bpf_cfg_in Date: Thu, 23 Nov 2017 18:11:59 -0800 Message-Id: <20171124021208.13419-3-jakub.kicinski@netronome.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171124021208.13419-1-jakub.kicinski@netronome.com> References: <20171124021208.13419-1-jakub.kicinski@netronome.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org bpf_parse() will parse command line arguments to find out the program mode. This mode will later be needed at loading time. Instead of keeping it locally add it to struct bpf_cfg_in, this will allow splitting parsing and loading stages. enum bpf_mode has to be moved to the header file, because C doesn't allow forward declaration of enums. Signed-off-by: Jakub Kicinski Reviewed-by: Quentin Monnet Acked-by: Daniel Borkmann --- include/bpf_util.h | 9 +++++++++ lib/bpf.c | 42 ++++++++++++++++-------------------------- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/include/bpf_util.h b/include/bpf_util.h index 0da4b85c979a..a6f4eeb5fe01 100644 --- a/include/bpf_util.h +++ b/include/bpf_util.h @@ -56,11 +56,20 @@ struct bpf_cfg_ops { void (*ebpf_cb)(void *nl, int fd, const char *annotation); }; +enum bpf_mode { + CBPF_BYTECODE, + CBPF_FILE, + EBPF_OBJECT, + EBPF_PINNED, + BPF_MODE_MAX, +}; + struct bpf_cfg_in { const char *object; const char *section; const char *uds; enum bpf_prog_type type; + enum bpf_mode mode; int argc; char **argv; struct sock_filter *ops; diff --git a/lib/bpf.c b/lib/bpf.c index 5e65682b5ea4..33c92d6c8a69 100644 --- a/lib/bpf.c +++ b/lib/bpf.c @@ -805,16 +805,7 @@ static int bpf_obj_pinned(const char *pathname, enum bpf_prog_type type) return prog_fd; } -enum bpf_mode { - CBPF_BYTECODE, - CBPF_FILE, - EBPF_OBJECT, - EBPF_PINNED, - BPF_MODE_MAX, -}; - -static int bpf_parse(enum bpf_mode *mode, struct bpf_cfg_in *cfg, - const bool *opt_tbl) +static int bpf_parse(struct bpf_cfg_in *cfg, const bool *opt_tbl) { const char *file, *section, *uds_name; bool verbose = false; @@ -827,20 +818,20 @@ static int bpf_parse(enum bpf_mode *mode, struct bpf_cfg_in *cfg, if (opt_tbl[CBPF_BYTECODE] && (matches(*argv, "bytecode") == 0 || strcmp(*argv, "bc") == 0)) { - *mode = CBPF_BYTECODE; + cfg->mode = CBPF_BYTECODE; } else if (opt_tbl[CBPF_FILE] && (matches(*argv, "bytecode-file") == 0 || strcmp(*argv, "bcf") == 0)) { - *mode = CBPF_FILE; + cfg->mode = CBPF_FILE; } else if (opt_tbl[EBPF_OBJECT] && (matches(*argv, "object-file") == 0 || strcmp(*argv, "obj") == 0)) { - *mode = EBPF_OBJECT; + cfg->mode = EBPF_OBJECT; } else if (opt_tbl[EBPF_PINNED] && (matches(*argv, "object-pinned") == 0 || matches(*argv, "pinned") == 0 || matches(*argv, "fd") == 0)) { - *mode = EBPF_PINNED; + cfg->mode = EBPF_PINNED; } else { fprintf(stderr, "What mode is \"%s\"?\n", *argv); return -1; @@ -848,7 +839,7 @@ static int bpf_parse(enum bpf_mode *mode, struct bpf_cfg_in *cfg, NEXT_ARG(); file = section = uds_name = NULL; - if (*mode == EBPF_OBJECT || *mode == EBPF_PINNED) { + if (cfg->mode == EBPF_OBJECT || cfg->mode == EBPF_PINNED) { file = *argv; NEXT_ARG_FWD(); @@ -902,11 +893,12 @@ static int bpf_parse(enum bpf_mode *mode, struct bpf_cfg_in *cfg, PREV_ARG(); } - if (*mode == CBPF_BYTECODE || *mode == CBPF_FILE) - ret = bpf_ops_parse(argc, argv, cfg->ops, *mode == CBPF_FILE); - else if (*mode == EBPF_OBJECT) + if (cfg->mode == CBPF_BYTECODE || cfg->mode == CBPF_FILE) + ret = bpf_ops_parse(argc, argv, cfg->ops, + cfg->mode == CBPF_FILE); + else if (cfg->mode == EBPF_OBJECT) ret = bpf_obj_open(file, cfg->type, section, verbose); - else if (*mode == EBPF_PINNED) + else if (cfg->mode == EBPF_PINNED) ret = bpf_obj_pinned(file, cfg->type); else return -1; @@ -926,20 +918,19 @@ static int bpf_parse_opt_tbl(struct bpf_cfg_in *cfg, { struct sock_filter opcodes[BPF_MAXINSNS]; char annotation[256]; - enum bpf_mode mode; int ret; cfg->ops = opcodes; - ret = bpf_parse(&mode, cfg, opt_tbl); + ret = bpf_parse(cfg, opt_tbl); cfg->ops = NULL; if (ret < 0) return ret; - if (mode == CBPF_BYTECODE || mode == CBPF_FILE) + if (cfg->mode == CBPF_BYTECODE || cfg->mode == CBPF_FILE) ops->cbpf_cb(nl, opcodes, ret); - if (mode == EBPF_OBJECT || mode == EBPF_PINNED) { + if (cfg->mode == EBPF_OBJECT || cfg->mode == EBPF_PINNED) { snprintf(annotation, sizeof(annotation), "%s:[%s]", - basename(cfg->object), mode == EBPF_PINNED ? + basename(cfg->object), cfg->mode == EBPF_PINNED ? "*fsobj" : cfg->section); ops->ebpf_cb(nl, ret, annotation); } @@ -983,10 +974,9 @@ int bpf_graft_map(const char *map_path, uint32_t *key, int argc, char **argv) }; struct bpf_map_ext ext = {}; int ret, prog_fd, map_fd; - enum bpf_mode mode; uint32_t map_key; - prog_fd = bpf_parse(&mode, &cfg, opt_tbl); + prog_fd = bpf_parse(&cfg, opt_tbl); if (prog_fd < 0) return prog_fd; if (key) { From patchwork Fri Nov 24 02:12:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 840934 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="ZK5LmYTE"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yjfqV58jQz9s76 for ; Fri, 24 Nov 2017 13:13:10 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753003AbdKXCNJ (ORCPT ); Thu, 23 Nov 2017 21:13:09 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:39471 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751611AbdKXCMV (ORCPT ); Thu, 23 Nov 2017 21:12:21 -0500 Received: by mail-pg0-f68.google.com with SMTP id 70so14671059pgf.6 for ; Thu, 23 Nov 2017 18:12:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yPuzSv6i4/Li7yjOX0pgRIau2H/lsEJJRKRQAx57FFI=; b=ZK5LmYTEhJYZmDy9Um/kILutW5M3re2W2e9zQEqZaXooffZpFvUkEEiH9DnBJAqN0r VhWFZZVOCX7mSLrWQqrN6DlLwN7vVVJYL+iAHd88UV90oiTgMCxwGK6xbWkTgZiyGwtg Ke5gdprniv/G9dwje/hNl4Ln2AHRkG6Y8NDWsDdfaeThYhIahm346OJEWuwCYMKMzj9q i5zDta+3NOvZcJ+1/rCVuRgRAVIaTYBeKTZKDiqMOIopNbNILtdXihSEZ/Px3bCaDgFb tl+hvc4H9VAVvnePpmM+G7fy1yW0OIgB9yXX3aEyNoOV7/iwobZymnlyR6o5VLMM4SwO fiwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yPuzSv6i4/Li7yjOX0pgRIau2H/lsEJJRKRQAx57FFI=; b=DHFflckOCLZB2a/1neiTGT2spsmSW7K2VrA3/YKu/rWATo6kMJhQd+jXQruXcI5r8W wP7gMUsAhHmxNFE3JVbs3NIRK7GvSxD21bItAGyPIonoig8hQvwQycZDHe4xQTPGj58y EH05LaXLn/xpi5crsC8pYeE3basBp09lYBovHwfOBU2c/+pIuX9X9RBCWGmZHuI7TCZL aBKWAfmkQRnBhovMPIDxIDyNRtnpWvscnvoQg6Zku2eFgiT9vRVaGCYASLViZtl+et2P VzQ7NuPciDnGhqhWU7Js3tcQJXYQ3zMksQdgfukAoaphOdBC85is4gi3VOHxsTHmoB+d 6+gQ== X-Gm-Message-State: AJaThX4ZZuu6z82kSa5O45nsaXeyWgtj1bBhdaKt8k8z6l/oGjiuBP71 xR+JXpRCx50e6/y9H6+hpaLWrHUu X-Google-Smtp-Source: AGs4zMa/qIE0dzF3G90DsIj6Z2CY1KfB2cK/7ztROUmYy0Ckxwdi3nvlejsFjdZVe/PPeOxTmD1X9Q== X-Received: by 10.101.80.8 with SMTP id f8mr6127518pgo.24.1511489540321; Thu, 23 Nov 2017 18:12:20 -0800 (PST) Received: from jkicinski-Precision-T1700.netronome.com ([75.53.12.129]) by smtp.gmail.com with ESMTPSA id q12sm29400889pgn.56.2017.11.23.18.12.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 23 Nov 2017 18:12:19 -0800 (PST) From: Jakub Kicinski To: netdev@vger.kernel.org Cc: oss-drivers@netronome.com, daniel@iogearbox.net, Jakub Kicinski Subject: [PATCH iproute2/master 03/11] bpf: allocate opcode table in struct bpf_cfg_in Date: Thu, 23 Nov 2017 18:12:00 -0800 Message-Id: <20171124021208.13419-4-jakub.kicinski@netronome.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171124021208.13419-1-jakub.kicinski@netronome.com> References: <20171124021208.13419-1-jakub.kicinski@netronome.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org struct bpf_cfg_in already carries a pointer to sock_filter ops. It's currently set to a local variable in bpf_parse_opt_tbl(), shared between parsing and loading stages. Move the array entirely to struct bpf_cfg_in, this will allow us to split parsing and loading. Signed-off-by: Jakub Kicinski Reviewed-by: Quentin Monnet Acked-by: Daniel Borkmann --- include/bpf_util.h | 2 +- lib/bpf.c | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/include/bpf_util.h b/include/bpf_util.h index a6f4eeb5fe01..638721f6315a 100644 --- a/include/bpf_util.h +++ b/include/bpf_util.h @@ -72,7 +72,7 @@ struct bpf_cfg_in { enum bpf_mode mode; int argc; char **argv; - struct sock_filter *ops; + struct sock_filter opcodes[BPF_MAXINSNS]; }; /* ALU ops on registers, bpf_add|sub|...: dst_reg += src_reg */ diff --git a/lib/bpf.c b/lib/bpf.c index 33c92d6c8a69..7493595ab1d6 100644 --- a/lib/bpf.c +++ b/lib/bpf.c @@ -894,7 +894,7 @@ static int bpf_parse(struct bpf_cfg_in *cfg, const bool *opt_tbl) } if (cfg->mode == CBPF_BYTECODE || cfg->mode == CBPF_FILE) - ret = bpf_ops_parse(argc, argv, cfg->ops, + ret = bpf_ops_parse(argc, argv, cfg->opcodes, cfg->mode == CBPF_FILE); else if (cfg->mode == EBPF_OBJECT) ret = bpf_obj_open(file, cfg->type, section, verbose); @@ -916,18 +916,15 @@ static int bpf_parse_opt_tbl(struct bpf_cfg_in *cfg, const struct bpf_cfg_ops *ops, void *nl, const bool *opt_tbl) { - struct sock_filter opcodes[BPF_MAXINSNS]; char annotation[256]; int ret; - cfg->ops = opcodes; ret = bpf_parse(cfg, opt_tbl); - cfg->ops = NULL; if (ret < 0) return ret; if (cfg->mode == CBPF_BYTECODE || cfg->mode == CBPF_FILE) - ops->cbpf_cb(nl, opcodes, ret); + ops->cbpf_cb(nl, cfg->opcodes, ret); if (cfg->mode == EBPF_OBJECT || cfg->mode == EBPF_PINNED) { snprintf(annotation, sizeof(annotation), "%s:[%s]", basename(cfg->object), cfg->mode == EBPF_PINNED ? From patchwork Fri Nov 24 02:12:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 840932 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="gv+86xsk"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yjfqJ2ywGz9s76 for ; Fri, 24 Nov 2017 13:13:00 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752965AbdKXCM6 (ORCPT ); Thu, 23 Nov 2017 21:12:58 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:39376 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752163AbdKXCMW (ORCPT ); Thu, 23 Nov 2017 21:12:22 -0500 Received: by mail-pf0-f195.google.com with SMTP id l24so14175940pfj.6 for ; Thu, 23 Nov 2017 18:12:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bNLko7h8yNAL0P6wrNwO/I1axTH94HRLQML4Uv1A92Q=; b=gv+86xskF1nAtXfzNrwnpv2rc076m8SaXGEQmj3Km89tXsKpqr/zPQWM8nbCkraWfX JQx3+gnwBgN1R+VvWZK5IkcOvCXsJgz5Wn3SxcvZWYVesbEcbmFaNZTl6od+oPHvFZKo GNjJ3Di/xOknq3GCHWakhcqhhqpyOAmNI2e2K2JButk3y5xcnasHIjq335wQdYdRotEV 0rqj4VO6ynNNZXix2VzVAZ20dORM4FViRI1bw89Fqv6wNocNwIbb7cvX1EE5jv5/KozV zr1aPhRV5+TuLhpyB7z1MQW28CmrdsWJRif7cUm4xXWBugZbdrghqGbQQu3XMgvNgeHX 0YBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bNLko7h8yNAL0P6wrNwO/I1axTH94HRLQML4Uv1A92Q=; b=M3tWuNkQKbMFxMC856Zs2ZKfKEPvfZ5Vj6uTgTQVrKANcCJGdcGqghIenee15oZe2f /4YARB7StyOekkGXCvpC6cw8x+vUws2spyeq8N8EVtYFpqTNHvOXgfy4eLcbgBI1dQcA 71JDsa+Ztc6sHrrSZOb32O94+p8CdAyQgcG4TMFyt8/RP//UFWw2oyq8u8e0aJjuEXnM pk4uF9m5L/wBpZYyy495UpESNNKRosZlFfNLDMt9QaJCyecY0X+UEih0gXFEmKZZ6pw1 RzIJhizMejO5/nILCI78iLkleCkpx3teuFBYX1U5EvoL25pD38VA9bNNxRvSmloutzb2 06YA== X-Gm-Message-State: AJaThX500K5WkaWYe/hPXilHl6zMT0BEZDNN2JAg2PfBCWBj5QaYO6+F 2gp7qcKaXYnENCxm2ETtHtcdukgq X-Google-Smtp-Source: AGs4zMYHTBJOS3RCSx3ZecDc9DXDMcT3wpY/Jf6Ne/wJIS3DYsKzrvOaVhR2P6Bucz8qyBS1tXk/ug== X-Received: by 10.101.67.6 with SMTP id j6mr19454842pgq.278.1511489541077; Thu, 23 Nov 2017 18:12:21 -0800 (PST) Received: from jkicinski-Precision-T1700.netronome.com ([75.53.12.129]) by smtp.gmail.com with ESMTPSA id q12sm29400889pgn.56.2017.11.23.18.12.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 23 Nov 2017 18:12:20 -0800 (PST) From: Jakub Kicinski To: netdev@vger.kernel.org Cc: oss-drivers@netronome.com, daniel@iogearbox.net, Jakub Kicinski Subject: [PATCH iproute2/master 04/11] bpf: split parse from program loading Date: Thu, 23 Nov 2017 18:12:01 -0800 Message-Id: <20171124021208.13419-5-jakub.kicinski@netronome.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171124021208.13419-1-jakub.kicinski@netronome.com> References: <20171124021208.13419-1-jakub.kicinski@netronome.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Parsing command line is currently done together with potentially loading a new eBPF program. This makes it more difficult to provide additional parameters for loading (which may come after the eBPF program info on the command line). Split the two (only internally for now). Verbose parameter has to be saved in struct bpf_cfg_in to be carried between the stages. Signed-off-by: Jakub Kicinski Reviewed-by: Quentin Monnet Acked-by: Daniel Borkmann --- include/bpf_util.h | 5 +++++ lib/bpf.c | 49 +++++++++++++++++++++++++++++++++++++------------ 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/include/bpf_util.h b/include/bpf_util.h index 638721f6315a..8e39a2d489db 100644 --- a/include/bpf_util.h +++ b/include/bpf_util.h @@ -70,9 +70,14 @@ struct bpf_cfg_in { const char *uds; enum bpf_prog_type type; enum bpf_mode mode; + bool verbose; int argc; char **argv; struct sock_filter opcodes[BPF_MAXINSNS]; + union { + int n_opcodes; + int prog_fd; + }; }; /* ALU ops on registers, bpf_add|sub|...: dst_reg += src_reg */ diff --git a/lib/bpf.c b/lib/bpf.c index 7493595ab1d6..52f7c790065f 100644 --- a/lib/bpf.c +++ b/lib/bpf.c @@ -805,7 +805,7 @@ static int bpf_obj_pinned(const char *pathname, enum bpf_prog_type type) return prog_fd; } -static int bpf_parse(struct bpf_cfg_in *cfg, const bool *opt_tbl) +static int bpf_do_parse(struct bpf_cfg_in *cfg, const bool *opt_tbl) { const char *file, *section, *uds_name; bool verbose = false; @@ -893,25 +893,39 @@ static int bpf_parse(struct bpf_cfg_in *cfg, const bool *opt_tbl) PREV_ARG(); } - if (cfg->mode == CBPF_BYTECODE || cfg->mode == CBPF_FILE) + if (cfg->mode == CBPF_BYTECODE || cfg->mode == CBPF_FILE) { ret = bpf_ops_parse(argc, argv, cfg->opcodes, cfg->mode == CBPF_FILE); - else if (cfg->mode == EBPF_OBJECT) - ret = bpf_obj_open(file, cfg->type, section, verbose); - else if (cfg->mode == EBPF_PINNED) + cfg->n_opcodes = ret; + } else if (cfg->mode == EBPF_OBJECT) { + ret = 0; /* program will be loaded by load stage */ + } else if (cfg->mode == EBPF_PINNED) { ret = bpf_obj_pinned(file, cfg->type); - else + cfg->prog_fd = ret; + } else { return -1; + } cfg->object = file; cfg->section = section; cfg->uds = uds_name; cfg->argc = argc; cfg->argv = argv; + cfg->verbose = verbose; return ret; } +static int bpf_do_load(struct bpf_cfg_in *cfg) +{ + if (cfg->mode == EBPF_OBJECT) { + cfg->prog_fd = bpf_obj_open(cfg->object, cfg->type, + cfg->section, cfg->verbose); + return cfg->prog_fd; + } + return 0; +} + static int bpf_parse_opt_tbl(struct bpf_cfg_in *cfg, const struct bpf_cfg_ops *ops, void *nl, const bool *opt_tbl) @@ -919,17 +933,21 @@ static int bpf_parse_opt_tbl(struct bpf_cfg_in *cfg, char annotation[256]; int ret; - ret = bpf_parse(cfg, opt_tbl); + ret = bpf_do_parse(cfg, opt_tbl); + if (ret < 0) + return ret; + + ret = bpf_do_load(cfg); if (ret < 0) return ret; if (cfg->mode == CBPF_BYTECODE || cfg->mode == CBPF_FILE) - ops->cbpf_cb(nl, cfg->opcodes, ret); + ops->cbpf_cb(nl, cfg->opcodes, cfg->n_opcodes); if (cfg->mode == EBPF_OBJECT || cfg->mode == EBPF_PINNED) { snprintf(annotation, sizeof(annotation), "%s:[%s]", basename(cfg->object), cfg->mode == EBPF_PINNED ? "*fsobj" : cfg->section); - ops->ebpf_cb(nl, ret, annotation); + ops->ebpf_cb(nl, cfg->prog_fd, annotation); } return 0; @@ -973,9 +991,16 @@ int bpf_graft_map(const char *map_path, uint32_t *key, int argc, char **argv) int ret, prog_fd, map_fd; uint32_t map_key; - prog_fd = bpf_parse(&cfg, opt_tbl); - if (prog_fd < 0) - return prog_fd; + ret = bpf_do_parse(&cfg, opt_tbl); + if (ret < 0) + return ret; + + ret = bpf_do_load(&cfg); + if (ret < 0) + return ret; + + prog_fd = cfg.prog_fd; + if (key) { map_key = *key; } else { From patchwork Fri Nov 24 02:12:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 840933 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="kxBSG3rP"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yjfqN5gKLz9s9Y for ; Fri, 24 Nov 2017 13:13:04 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752936AbdKXCM5 (ORCPT ); Thu, 23 Nov 2017 21:12:57 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:44085 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751869AbdKXCMW (ORCPT ); Thu, 23 Nov 2017 21:12:22 -0500 Received: by mail-pg0-f68.google.com with SMTP id c123so14663420pga.11 for ; Thu, 23 Nov 2017 18:12:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UgsnJ0EG+SheVXXQCsB8RcreEPXTBD3SDVwW1uAsNow=; b=kxBSG3rPIq6udJHsm1EYCwe57sbkwJNWBPlAEwI6VwWf2/fxEo4fcwYaUJ+v6JByak tg5t/fiZKzZDozhXPHOAROHCIMeNs1XAOy5xTcChWV76rmWYTeWrNe3w1WTpK935vYDC 5k1rZdYzCADWWKsaSWdzRXyrhV2lGb/DX6RvmDOtEu8LUGTjpLW41CRavr8SoCxcQqvJ I5WzAgm+wUPkCyjY5nA3gwljctROymHSpEBA+PldJhmGEwevdI39hZU2rpWzpsTL/qWh L/0OJaPJeLl6gNgBkB4kq6pF8ss+MnC6dDJXdY601bcU+/TXsfDhBZpVET3Za7SKmGFL SLcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UgsnJ0EG+SheVXXQCsB8RcreEPXTBD3SDVwW1uAsNow=; b=UFEIhU7FRdUG4fMLxIRxUrYOx5+i5zahzWxd3454rQttolU0JaEKJd94KvOhxInO0t tsEuRynrkFypBHTLpBpd/SQKaGynZLuX3iIn3tg1zyi232KIIb9aL32JYmkVbZR4rNAy KIibNERBGO9TQ73hT2RjWve2lsdJ1ngSNDnJG32ztVH73G/MNL2cKi4Ewb4MLDyMilV0 3AmF6Ax0WfbWL5X10TTJa03XPKm+dvsirWWfft8N1KOJLejC42zLKoxDIld5Vt4tO+bt P4/UlIc8/ySG/mLbeTUh2QuJ4dcG7u2sTAFW80trxU2wL1MeW9BeybnyHk63Too4p073 PygQ== X-Gm-Message-State: AJaThX7q7eTgCoJrSixFU05K54vbVAIFp9v7FCDyb/EXjvxdmzMCprdu aWC/jZdkt0SQO1+5N4TVBqrGnqnk X-Google-Smtp-Source: AGs4zMYOacCSgmwFc4KOTqJdjLjnVHcFt9dgVZD25Ur9AfWF9b0Q0beEM9vS53UjXclJkAZG8ag1TQ== X-Received: by 10.101.97.75 with SMTP id o11mr4440130pgv.363.1511489542040; Thu, 23 Nov 2017 18:12:22 -0800 (PST) Received: from jkicinski-Precision-T1700.netronome.com ([75.53.12.129]) by smtp.gmail.com with ESMTPSA id q12sm29400889pgn.56.2017.11.23.18.12.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 23 Nov 2017 18:12:21 -0800 (PST) From: Jakub Kicinski To: netdev@vger.kernel.org Cc: oss-drivers@netronome.com, daniel@iogearbox.net, Jakub Kicinski Subject: [PATCH iproute2/master 05/11] bpf: rename bpf_parse_common() to bpf_parse_and_load_common() Date: Thu, 23 Nov 2017 18:12:02 -0800 Message-Id: <20171124021208.13419-6-jakub.kicinski@netronome.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171124021208.13419-1-jakub.kicinski@netronome.com> References: <20171124021208.13419-1-jakub.kicinski@netronome.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org bpf_parse_common() parses and loads the program. Rename it accordingly. Signed-off-by: Jakub Kicinski Reviewed-by: Quentin Monnet Acked-by: Daniel Borkmann --- include/bpf_util.h | 4 ++-- ip/iplink_xdp.c | 2 +- ip/iproute_lwtunnel.c | 2 +- lib/bpf.c | 4 ++-- tc/f_bpf.c | 2 +- tc/m_bpf.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/bpf_util.h b/include/bpf_util.h index 8e39a2d489db..da2dee8bb3aa 100644 --- a/include/bpf_util.h +++ b/include/bpf_util.h @@ -259,8 +259,8 @@ struct bpf_cfg_in { .off = 0, \ .imm = 0 }) -int bpf_parse_common(struct bpf_cfg_in *cfg, const struct bpf_cfg_ops *ops, - void *nl); +int bpf_parse_and_load_common(struct bpf_cfg_in *cfg, + const struct bpf_cfg_ops *ops, void *nl); const char *bpf_prog_to_default_section(enum bpf_prog_type type); diff --git a/ip/iplink_xdp.c b/ip/iplink_xdp.c index 993e44d7878a..edaec2a250e7 100644 --- a/ip/iplink_xdp.c +++ b/ip/iplink_xdp.c @@ -75,7 +75,7 @@ int xdp_parse(int *argc, char ***argv, struct iplink_req *req, bool generic, return xdp_delete(&xdp); } - if (bpf_parse_common(&cfg, &bpf_cb_ops, &xdp)) + if (bpf_parse_and_load_common(&cfg, &bpf_cb_ops, &xdp)) return -1; *argc = cfg.argc; diff --git a/ip/iproute_lwtunnel.c b/ip/iproute_lwtunnel.c index 9f0f647e261f..2280c7a7b192 100644 --- a/ip/iproute_lwtunnel.c +++ b/ip/iproute_lwtunnel.c @@ -884,7 +884,7 @@ static int lwt_parse_bpf(struct rtattr *rta, size_t len, int err; nest = rta_nest(rta, len, attr); - err = bpf_parse_common(&cfg, &bpf_cb_ops, &x); + err = bpf_parse_and_load_common(&cfg, &bpf_cb_ops, &x); if (err < 0) { fprintf(stderr, "Failed to parse eBPF program: %s\n", strerror(-err)); diff --git a/lib/bpf.c b/lib/bpf.c index 52f7c790065f..9a0867124fc4 100644 --- a/lib/bpf.c +++ b/lib/bpf.c @@ -953,8 +953,8 @@ static int bpf_parse_opt_tbl(struct bpf_cfg_in *cfg, return 0; } -int bpf_parse_common(struct bpf_cfg_in *cfg, const struct bpf_cfg_ops *ops, - void *nl) +int bpf_parse_and_load_common(struct bpf_cfg_in *cfg, + const struct bpf_cfg_ops *ops, void *nl) { bool opt_tbl[BPF_MODE_MAX] = {}; diff --git a/tc/f_bpf.c b/tc/f_bpf.c index a38ec2ab7786..21ba759c4b01 100644 --- a/tc/f_bpf.c +++ b/tc/f_bpf.c @@ -107,7 +107,7 @@ static int bpf_parse_opt(struct filter_util *qu, char *handle, cfg.argc = argc; cfg.argv = argv; - if (bpf_parse_common(&cfg, &bpf_cb_ops, n)) + if (bpf_parse_and_load_common(&cfg, &bpf_cb_ops, n)) return -1; argc = cfg.argc; diff --git a/tc/m_bpf.c b/tc/m_bpf.c index f2ce3892e4ed..e275afd01fb3 100644 --- a/tc/m_bpf.c +++ b/tc/m_bpf.c @@ -102,7 +102,7 @@ static int bpf_parse_opt(struct action_util *a, int *ptr_argc, char ***ptr_argv, cfg.argc = argc; cfg.argv = argv; - if (bpf_parse_common(&cfg, &bpf_cb_ops, n)) + if (bpf_parse_and_load_common(&cfg, &bpf_cb_ops, n)) return -1; argc = cfg.argc; From patchwork Fri Nov 24 02:12:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 840928 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="AVkqzVk3"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yjfpx07sxz9s9Y for ; Fri, 24 Nov 2017 13:12:41 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752362AbdKXCM0 (ORCPT ); Thu, 23 Nov 2017 21:12:26 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:38491 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751575AbdKXCMY (ORCPT ); Thu, 23 Nov 2017 21:12:24 -0500 Received: by mail-pf0-f194.google.com with SMTP id r62so14169035pfd.5 for ; Thu, 23 Nov 2017 18:12:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/QS0dWUknTDUZxOr1uPHcDfTCmra125VAKau65xSCqA=; b=AVkqzVk3CtwgWQDroeHKV5mG8M03UjN3bB17pb3JcH9huH8xqhZtgQMlPXEt+VKLvU /T6bb5/C4RUg4C0jOaMHrMuMlAMhhvdUZvbZL+6ZaP8pJUN6LCar78hDdm5A6boBRxiI I4jsQipiaxe6IhdKUhcHbLQlM3KYYZTWuJlBm4HqrZa1ANNngK85EDsAo6af2OJe2cY/ KdOA4lSAUb6EK20g5bEAEfictQhDiSx4HXOQpsfh/MhsP6cYWtF/tdSvGEkhXZ+iArmp zNFw/CJJ3tS0dLjZj+X0KAfM4zStZkZCVCKCmxyrm4Y0Re0lVEdUMl3E8xaLHFv0DQgv 0gsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/QS0dWUknTDUZxOr1uPHcDfTCmra125VAKau65xSCqA=; b=CFFacn8Lj0YyFNAt+52fvCVdrgRvHl2fjNCtmtD+a/nEnPFFKW+VurzeIfgKxdXYw9 Lj+nVjqn0r0dQzhQdj543kqYSQ2J5nmsbGTUQ/T/rPhif1TsYplXdNeSSTfN1Ijsf3cP EtfRbdzAbnlTjw0QzNYJgxFJH7XuEs3rWsHBRK4geEM7jiSTenIhHKbGVQDYwkEmqiMh 3XLPJQdJepy7o7e3g4OazpYjltZcwv6qRClHWD4lP9lJHoB/q40JBAKqGRBJeuuPJAG8 MZCzvBzBenbWiu6ZfcXW93OX2av46K4YSZTlHgAgYrbOVlAHHLkOz5r05e1BFabAJ78/ TJ1Q== X-Gm-Message-State: AJaThX4BFK6hAE1MGG2DSRZfo1ZofhjMIgb8LY7IjPsLcekSX+RAGkr1 wtjcHSCOT37VvMQJNCLwLihZZLGr X-Google-Smtp-Source: AGs4zMbYk2H1DjpwhHRvibQYjpD56NHwJ7RSgA1G0F0SPyButyr6N422rPbRTspaC8Ei3JX1lX0zOQ== X-Received: by 10.99.111.139 with SMTP id k133mr6396934pgc.332.1511489542882; Thu, 23 Nov 2017 18:12:22 -0800 (PST) Received: from jkicinski-Precision-T1700.netronome.com ([75.53.12.129]) by smtp.gmail.com with ESMTPSA id q12sm29400889pgn.56.2017.11.23.18.12.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 23 Nov 2017 18:12:22 -0800 (PST) From: Jakub Kicinski To: netdev@vger.kernel.org Cc: oss-drivers@netronome.com, daniel@iogearbox.net, Jakub Kicinski Subject: [PATCH iproute2/master 06/11] bpf: expose bpf_parse_common() and bpf_load_common() Date: Thu, 23 Nov 2017 18:12:03 -0800 Message-Id: <20171124021208.13419-7-jakub.kicinski@netronome.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171124021208.13419-1-jakub.kicinski@netronome.com> References: <20171124021208.13419-1-jakub.kicinski@netronome.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Expose bpf_parse_common() and bpf_load_common() functions for those users who may want to modify the parameters to load after parsing is done. Signed-off-by: Jakub Kicinski Reviewed-by: Quentin Monnet Acked-by: Daniel Borkmann --- include/bpf_util.h | 3 +++ lib/bpf.c | 26 ++++++++++++++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/include/bpf_util.h b/include/bpf_util.h index da2dee8bb3aa..f6371994252e 100644 --- a/include/bpf_util.h +++ b/include/bpf_util.h @@ -259,6 +259,9 @@ struct bpf_cfg_in { .off = 0, \ .imm = 0 }) +int bpf_parse_common(struct bpf_cfg_in *cfg, const struct bpf_cfg_ops *ops); +int bpf_load_common(struct bpf_cfg_in *cfg, const struct bpf_cfg_ops *ops, + void *nl); int bpf_parse_and_load_common(struct bpf_cfg_in *cfg, const struct bpf_cfg_ops *ops, void *nl); diff --git a/lib/bpf.c b/lib/bpf.c index 9a0867124fc4..f25f7016d10f 100644 --- a/lib/bpf.c +++ b/lib/bpf.c @@ -926,17 +926,12 @@ static int bpf_do_load(struct bpf_cfg_in *cfg) return 0; } -static int bpf_parse_opt_tbl(struct bpf_cfg_in *cfg, - const struct bpf_cfg_ops *ops, void *nl, - const bool *opt_tbl) +int bpf_load_common(struct bpf_cfg_in *cfg, const struct bpf_cfg_ops *ops, + void *nl) { char annotation[256]; int ret; - ret = bpf_do_parse(cfg, opt_tbl); - if (ret < 0) - return ret; - ret = bpf_do_load(cfg); if (ret < 0) return ret; @@ -953,8 +948,7 @@ static int bpf_parse_opt_tbl(struct bpf_cfg_in *cfg, return 0; } -int bpf_parse_and_load_common(struct bpf_cfg_in *cfg, - const struct bpf_cfg_ops *ops, void *nl) +int bpf_parse_common(struct bpf_cfg_in *cfg, const struct bpf_cfg_ops *ops) { bool opt_tbl[BPF_MODE_MAX] = {}; @@ -968,7 +962,19 @@ int bpf_parse_and_load_common(struct bpf_cfg_in *cfg, opt_tbl[EBPF_PINNED] = true; } - return bpf_parse_opt_tbl(cfg, ops, nl, opt_tbl); + return bpf_do_parse(cfg, opt_tbl); +} + +int bpf_parse_and_load_common(struct bpf_cfg_in *cfg, + const struct bpf_cfg_ops *ops, void *nl) +{ + int ret; + + ret = bpf_parse_common(cfg, ops); + if (ret < 0) + return ret; + + return bpf_load_common(cfg, ops, nl); } int bpf_graft_map(const char *map_path, uint32_t *key, int argc, char **argv) From patchwork Fri Nov 24 02:12:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 840925 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="izFvHQM0"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yjfpk0bPmz9s76 for ; Fri, 24 Nov 2017 13:12:30 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752420AbdKXCM1 (ORCPT ); Thu, 23 Nov 2017 21:12:27 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:36260 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751896AbdKXCMY (ORCPT ); Thu, 23 Nov 2017 21:12:24 -0500 Received: by mail-pf0-f196.google.com with SMTP id i15so14177844pfa.3 for ; Thu, 23 Nov 2017 18:12:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HtW2VeluHl5g6XG2M4b7mhKMI6OyNFY8Lh4HZQLe5QI=; b=izFvHQM0GGnbVBNKOXzoQ71Fj+Tvh8rFdZqpIJOemLYhfbONmT+2eBHmwrMmNeeEQR fxwoLoBDb4iQKDDEWBadpqpzSu417D575U7+Wx1aw3CRy4yY938aaUPhKj+7mtZmAmEm SkRrKQ6D+LUmPeCnD8rLfzxFwy18fJ6X4G+SDznzAyBCZpoJ496GM2qpMiJlb35pPWLI 0HHfgC+KOdgvISwiPn4uvbjpj2ZWHtoJ+LRdt6lxETcnrJg0o4wkkEwBiMNGPM+ERzUT dKUk4ON0Z9BsKEnY4lmkmHj7K+s70kUuxXDAKNt3LS1iRoBO1lJWt9lvyLzpDfBXb9qy ChAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=HtW2VeluHl5g6XG2M4b7mhKMI6OyNFY8Lh4HZQLe5QI=; b=CO7dbBFMbdScTlB6eFWCAKENH2ySPb9ol47IWAWZLdPELYOx4lBGemGYkO1u7f4XMM 6uT5++LfpP9YcaRTKGSzSrJCRwAw7r8Hgvwa/6C9/osppgmeqmyLUmF5meFONT3AirUi 3YpoeAEtnyjtJp6RV8Uk49Mp6B04HkLxFDgWuo6SAZTHGbYt2V4MAjZcjXgvLtN2BR/M T08/AXYCCz6HjJDPQxBYEkiu2Q3NO/7v8S/HwhIyyVDAUdZCTiOyD8Zn3QJj/rB9JpHk zOptebWPt0fz9qokPYwerFm0x0dMRTnm5Z67uN8EyfAGDOCye9hfbQ7b2CkQe4ng+6tE a4yw== X-Gm-Message-State: AJaThX5HLH8G9mhbWn2mIjwnWerfI6hUv4gcmc0hzRUymtV0hOVv7n6y k387eYEWNBzzgCGIVPbqdMs5iT4O X-Google-Smtp-Source: AGs4zMYPN36cMaqeXBaqpLRrQoZiFXOHjIg97uMi+tJG4toZjWhhUgSH+RCKMUmkoBooz9vsz6a0Hg== X-Received: by 10.99.95.20 with SMTP id t20mr25333196pgb.398.1511489543812; Thu, 23 Nov 2017 18:12:23 -0800 (PST) Received: from jkicinski-Precision-T1700.netronome.com ([75.53.12.129]) by smtp.gmail.com with ESMTPSA id q12sm29400889pgn.56.2017.11.23.18.12.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 23 Nov 2017 18:12:23 -0800 (PST) From: Jakub Kicinski To: netdev@vger.kernel.org Cc: oss-drivers@netronome.com, daniel@iogearbox.net, Jakub Kicinski Subject: [PATCH iproute2/master 07/11] bpf: allow loading programs for a specific ifindex Date: Thu, 23 Nov 2017 18:12:04 -0800 Message-Id: <20171124021208.13419-8-jakub.kicinski@netronome.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171124021208.13419-1-jakub.kicinski@netronome.com> References: <20171124021208.13419-1-jakub.kicinski@netronome.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org For BPF offload we need to specify the ifindex when program is loaded now. Extend the bpf common code to accommodate that. Signed-off-by: Jakub Kicinski Reviewed-by: Quentin Monnet Acked-by: Daniel Borkmann --- include/bpf_util.h | 1 + lib/bpf.c | 37 ++++++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/include/bpf_util.h b/include/bpf_util.h index f6371994252e..219beb40cd25 100644 --- a/include/bpf_util.h +++ b/include/bpf_util.h @@ -70,6 +70,7 @@ struct bpf_cfg_in { const char *uds; enum bpf_prog_type type; enum bpf_mode mode; + __u32 ifindex; bool verbose; int argc; char **argv; diff --git a/lib/bpf.c b/lib/bpf.c index f25f7016d10f..d32f1b808180 100644 --- a/lib/bpf.c +++ b/lib/bpf.c @@ -113,10 +113,10 @@ const char *bpf_prog_to_default_section(enum bpf_prog_type type) #ifdef HAVE_ELF static int bpf_obj_open(const char *path, enum bpf_prog_type type, - const char *sec, bool verbose); + const char *sec, __u32 ifindex, bool verbose); #else static int bpf_obj_open(const char *path, enum bpf_prog_type type, - const char *sec, bool verbose) + const char *sec, __u32 ifindex, bool verbose) { fprintf(stderr, "No ELF library support compiled in.\n"); errno = ENOSYS; @@ -920,7 +920,8 @@ static int bpf_do_load(struct bpf_cfg_in *cfg) { if (cfg->mode == EBPF_OBJECT) { cfg->prog_fd = bpf_obj_open(cfg->object, cfg->type, - cfg->section, cfg->verbose); + cfg->section, cfg->ifindex, + cfg->verbose); return cfg->prog_fd; } return 0; @@ -1065,9 +1066,10 @@ int bpf_prog_detach_fd(int target_fd, enum bpf_attach_type type) return bpf(BPF_PROG_DETACH, &attr, sizeof(attr)); } -int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns, - size_t size_insns, const char *license, char *log, - size_t size_log) +static int bpf_prog_load_dev(enum bpf_prog_type type, + const struct bpf_insn *insns, size_t size_insns, + const char *license, __u32 ifindex, + char *log, size_t size_log) { union bpf_attr attr = {}; @@ -1075,6 +1077,7 @@ int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns, attr.insns = bpf_ptr_to_u64(insns); attr.insn_cnt = size_insns / sizeof(struct bpf_insn); attr.license = bpf_ptr_to_u64(license); + attr.prog_ifindex = ifindex; if (size_log > 0) { attr.log_buf = bpf_ptr_to_u64(log); @@ -1085,6 +1088,14 @@ int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns, return bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); } +int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns, + size_t size_insns, const char *license, char *log, + size_t size_log) +{ + return bpf_prog_load_dev(type, insns, size_insns, license, 0, + log, size_log); +} + #ifdef HAVE_ELF struct bpf_elf_prog { enum bpf_prog_type type; @@ -1120,6 +1131,7 @@ struct bpf_elf_ctx { int sec_maps; char license[ELF_MAX_LICENSE_LEN]; enum bpf_prog_type type; + __u32 ifindex; bool verbose; struct bpf_elf_st stat; struct bpf_hash_entry *ht[256]; @@ -1492,8 +1504,9 @@ static int bpf_prog_attach(const char *section, int tries = 0, fd; retry: errno = 0; - fd = bpf_prog_load(prog->type, prog->insns, prog->size, - prog->license, ctx->log, ctx->log_size); + fd = bpf_prog_load_dev(prog->type, prog->insns, prog->size, + prog->license, ctx->ifindex, + ctx->log, ctx->log_size); if (fd < 0 || ctx->verbose) { /* The verifier log is pretty chatty, sometimes so chatty * on larger programs, that we could fail to dump everything @@ -2421,7 +2434,8 @@ static void bpf_get_cfg(struct bpf_elf_ctx *ctx) } static int bpf_elf_ctx_init(struct bpf_elf_ctx *ctx, const char *pathname, - enum bpf_prog_type type, bool verbose) + enum bpf_prog_type type, __u32 ifindex, + bool verbose) { int ret = -EINVAL; @@ -2433,6 +2447,7 @@ static int bpf_elf_ctx_init(struct bpf_elf_ctx *ctx, const char *pathname, bpf_get_cfg(ctx); ctx->verbose = verbose; ctx->type = type; + ctx->ifindex = ifindex; ctx->obj_fd = open(pathname, O_RDONLY); if (ctx->obj_fd < 0) @@ -2524,12 +2539,12 @@ static void bpf_elf_ctx_destroy(struct bpf_elf_ctx *ctx, bool failure) static struct bpf_elf_ctx __ctx; static int bpf_obj_open(const char *pathname, enum bpf_prog_type type, - const char *section, bool verbose) + const char *section, __u32 ifindex, bool verbose) { struct bpf_elf_ctx *ctx = &__ctx; int fd = 0, ret; - ret = bpf_elf_ctx_init(ctx, pathname, type, verbose); + ret = bpf_elf_ctx_init(ctx, pathname, type, ifindex, verbose); if (ret < 0) { fprintf(stderr, "Cannot initialize ELF context!\n"); return ret; From patchwork Fri Nov 24 02:12:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 840930 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="1MZH/bYA"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yjfq91d2Xz9s76 for ; Fri, 24 Nov 2017 13:12:53 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752824AbdKXCMv (ORCPT ); Thu, 23 Nov 2017 21:12:51 -0500 Received: from mail-pl0-f65.google.com ([209.85.160.65]:43837 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752283AbdKXCMZ (ORCPT ); Thu, 23 Nov 2017 21:12:25 -0500 Received: by mail-pl0-f65.google.com with SMTP id h3so3559643pln.10 for ; Thu, 23 Nov 2017 18:12:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6h2fjc48+r4ckGmsY4IRgBhCI2F1zquzjG7rYfsJ5fo=; b=1MZH/bYAf4WkfTnNU26VJt+IdSSVnyn0JMXjwtXZB5IyH8y+syctQQUgE9iiVeEPMa el9giOwD8GghceoV6EG55SuRhU4JP1YY+ou91BSSztG6jSZgJMQS304kiqyBXjWbrI7H JQuTu0zzg3TuiMILP9PocLSxPlBIPC92MvCVTWxzc8NcP6sQH9roTYHNZDDIBHGJfqD2 X54JFnP9t7PUDh4mDTBVARJ7q2HQfnUyHKHdsN3L4UkKnmTta38NmDvtJtw5ISaAJMUr I4gWO4Bj13WFjjIrVU6hBAgEo7TGsA7QLTzzw/l9oQUPuz6120z5kI6NxXPWZdDDB5n2 2MKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6h2fjc48+r4ckGmsY4IRgBhCI2F1zquzjG7rYfsJ5fo=; b=E0jbUJRZ7VZWFmUMPbvr3MiG/P58mtNUIszGRHOPBn2BHhwaFjwDu5K1uemYkfL83z V+78TqA2smusZ5qp4CAkT2OPiQismCNd053+A3m/ceemLwguRdy/wQmdif3pvePbzHUM h/MoaBDOPri16mvNEpXgrJr7d46u8kJLNP5QYatstuWldWa//FAPmqmykU7zefLpO6N9 /8Lee81qhcSFNSR5BJe5vGNA5Nr3dgsO1wX24L8y9ToJC9b0xY33FiImIig06NKf37NL 2rlw+SgqA8IOFgR4qdQwrl2gvaMa6lcRoOd4JJkHIvsfCrzaqnBejlZGmNTRLao+/ngW 08zg== X-Gm-Message-State: AJaThX5JlowhdSUUtuhaaVF1XWEypbcUZzl++rseB2z2bUsb2WJws1Af sBld/SqCI4lfZxyTym56C91lRxgI X-Google-Smtp-Source: AGs4zMZpb8hZ5zt399OH2YGZPLUqhvgiiXyhvdzKKPZ5OzcaPYXAwN6ZpYVKQAk621KSVJOaaUmYiA== X-Received: by 10.84.175.129 with SMTP id t1mr26713946plb.193.1511489544689; Thu, 23 Nov 2017 18:12:24 -0800 (PST) Received: from jkicinski-Precision-T1700.netronome.com ([75.53.12.129]) by smtp.gmail.com with ESMTPSA id q12sm29400889pgn.56.2017.11.23.18.12.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 23 Nov 2017 18:12:24 -0800 (PST) From: Jakub Kicinski To: netdev@vger.kernel.org Cc: oss-drivers@netronome.com, daniel@iogearbox.net, Jakub Kicinski Subject: [PATCH iproute2/master 08/11] {f, m}_bpf: don't allow specifying multiple bpf programs Date: Thu, 23 Nov 2017 18:12:05 -0800 Message-Id: <20171124021208.13419-9-jakub.kicinski@netronome.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171124021208.13419-1-jakub.kicinski@netronome.com> References: <20171124021208.13419-1-jakub.kicinski@netronome.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Both BPF filter and action will allow users to specify run multiple times, and only the last one will be considered by the kernel. Explicitly refuse such command lines. Signed-off-by: Jakub Kicinski Reviewed-by: Quentin Monnet Acked-by: Daniel Borkmann --- tc/f_bpf.c | 3 +++ tc/m_bpf.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/tc/f_bpf.c b/tc/f_bpf.c index 21ba759c4b01..f598784e8b08 100644 --- a/tc/f_bpf.c +++ b/tc/f_bpf.c @@ -101,6 +101,9 @@ static int bpf_parse_opt(struct filter_util *qu, char *handle, while (argc > 0) { if (matches(*argv, "run") == 0) { NEXT_ARG(); + + if (seen_run) + duparg("run", *argv); opt_bpf: seen_run = true; cfg.type = bpf_type; diff --git a/tc/m_bpf.c b/tc/m_bpf.c index e275afd01fb3..1c1f71cdb83f 100644 --- a/tc/m_bpf.c +++ b/tc/m_bpf.c @@ -96,6 +96,9 @@ static int bpf_parse_opt(struct action_util *a, int *ptr_argc, char ***ptr_argv, while (argc > 0) { if (matches(*argv, "run") == 0) { NEXT_ARG(); + + if (seen_run) + duparg("run", *argv); opt_bpf: seen_run = true; cfg.type = bpf_type; From patchwork Fri Nov 24 02:12:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 840929 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="fULkpRm4"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yjfpy2mWMz9s9Y for ; Fri, 24 Nov 2017 13:12:42 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752721AbdKXCMl (ORCPT ); Thu, 23 Nov 2017 21:12:41 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:38992 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752318AbdKXCM0 (ORCPT ); Thu, 23 Nov 2017 21:12:26 -0500 Received: by mail-pl0-f68.google.com with SMTP id l16so3564759pli.6 for ; Thu, 23 Nov 2017 18:12:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=J/dB0c/go0zazHlZxr0qVACNJlWtEcDR+IeFLi3HFPg=; b=fULkpRm4H2JABL10Gha4UwHYHW/htq9yXwNXx4wEn/4jzTYZnG6HZ43T5sxiwrhC2Z +JbOar/AgNq0XDYyoFKFLyuTAOPQ8pzIslSrv3dqezczV3YV3RUcbNhmJxmT+Vey9DEB 96rhYTTEulJ1BteT9O0l5bWJ/rvB+/8kfXyhJLctZL5N0/ZVSgvW3bso2awGkUMUIaOO EGVKHIJ7yerqTw5OI4wZhQ9wpgDMowLBYX33jFGQ33cAMEkEMDN2DFzPWycffeeoOMZ/ FIArnZ/YpYNYbWhEiPl9BsLx1zgeGySvLbvNIFrE5s7MxyDc3tbE26ehVHO02v2JGeuW 0joQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=J/dB0c/go0zazHlZxr0qVACNJlWtEcDR+IeFLi3HFPg=; b=TlpzZ+fDTk+Mw2u0QXSE+g/w//tK2GBz6e0deYB2t52qKxwNIHMB5jncRk+HodHZ9i oqLLelS4Xfqp/N4R0jETOZYx0ALsIOP3wUHLfg5dmwSyCtjsmhdNNx4cDNtKaaEprGDB YP3bmotrFnZtS7QAPZgy7UZd5ZBPvhuirRXL+O3mR1GKvpY7AI9P+QCK+rOgVRgkS2hB wZLNye1Obug7rg2e7rP51mqBMs40z9dIZgnNilbOpiLzmYcv0nrgr23ZKx9figP5G0me Ffenm+CVFnz2M0n1LP91qkXcwiftGk+3kc61f7oBLTNc6mI5LiBDncF77AQ6C2xdM2iw FzNQ== X-Gm-Message-State: AJaThX6AiYUQqykb1uh7d7jQiDpjb0oc6YYqHIUCFGok6QgZ92UW+RPB OWyNqYIhpnCVUviBR628RY77Shp9 X-Google-Smtp-Source: AGs4zMY/N6VnqGR3nr0GtMEIEUzgfY79y4odINSGEi47jtaj/28aLC15uopz3yOZ+MEVJ39CbgSg7A== X-Received: by 10.84.170.132 with SMTP id j4mr22602717plb.316.1511489545436; Thu, 23 Nov 2017 18:12:25 -0800 (PST) Received: from jkicinski-Precision-T1700.netronome.com ([75.53.12.129]) by smtp.gmail.com with ESMTPSA id q12sm29400889pgn.56.2017.11.23.18.12.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 23 Nov 2017 18:12:25 -0800 (PST) From: Jakub Kicinski To: netdev@vger.kernel.org Cc: oss-drivers@netronome.com, daniel@iogearbox.net, Jakub Kicinski Subject: [PATCH iproute2/master 09/11] tc_filter: resolve device name before parsing filter Date: Thu, 23 Nov 2017 18:12:06 -0800 Message-Id: <20171124021208.13419-10-jakub.kicinski@netronome.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171124021208.13419-1-jakub.kicinski@netronome.com> References: <20171124021208.13419-1-jakub.kicinski@netronome.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Move resolving device name into an ifindex before calling filter specific callbacks. This way if filters need the ifindex, they can read it from the request. Signed-off-by: Jakub Kicinski Reviewed-by: Quentin Monnet Acked-by: Daniel Borkmann --- tc/tc_filter.c | 50 ++++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/tc/tc_filter.c b/tc/tc_filter.c index d0c967a9633a..0a3f7e696af8 100644 --- a/tc/tc_filter.c +++ b/tc/tc_filter.c @@ -160,6 +160,16 @@ static int tc_filter_modify(int cmd, unsigned int flags, int argc, char **argv) if (k[0]) addattr_l(&req.n, sizeof(req), TCA_KIND, k, strlen(k)+1); + if (d[0]) { + ll_init_map(&rth); + + req.t.tcm_ifindex = ll_name_to_index(d); + if (req.t.tcm_ifindex == 0) { + fprintf(stderr, "Cannot find device \"%s\"\n", d); + return 1; + } + } + if (q) { if (q->parse_fopt(q, fhandle, argc, argv, &req.n)) return 1; @@ -182,17 +192,6 @@ static int tc_filter_modify(int cmd, unsigned int flags, int argc, char **argv) if (est.ewma_log) addattr_l(&req.n, sizeof(req), TCA_RATE, &est, sizeof(est)); - - if (d[0]) { - ll_init_map(&rth); - - req.t.tcm_ifindex = ll_name_to_index(d); - if (req.t.tcm_ifindex == 0) { - fprintf(stderr, "Cannot find device \"%s\"\n", d); - return 1; - } - } - if (rtnl_talk(&rth, &req.n, NULL) < 0) { fprintf(stderr, "We have an error talking to the kernel\n"); return 2; @@ -452,10 +451,23 @@ static int tc_filter_get(int cmd, unsigned int flags, int argc, char **argv) return -1; } + if (d[0]) { + ll_init_map(&rth); + + req.t.tcm_ifindex = ll_name_to_index(d); + if (req.t.tcm_ifindex == 0) { + fprintf(stderr, "Cannot find device \"%s\"\n", d); + return 1; + } + filter_ifindex = req.t.tcm_ifindex; + } else { + fprintf(stderr, "Must specify netdevice \"dev\"\n"); + return -1; + } + if (q->parse_fopt(q, fhandle, argc, argv, &req.n)) return 1; - if (!fhandle) { fprintf(stderr, "Must specify filter \"handle\"\n"); return -1; @@ -470,20 +482,6 @@ static int tc_filter_get(int cmd, unsigned int flags, int argc, char **argv) return -1; } - if (d[0]) { - ll_init_map(&rth); - - req.t.tcm_ifindex = ll_name_to_index(d); - if (req.t.tcm_ifindex == 0) { - fprintf(stderr, "Cannot find device \"%s\"\n", d); - return 1; - } - filter_ifindex = req.t.tcm_ifindex; - } else { - fprintf(stderr, "Must specify netdevice \"dev\"\n"); - return -1; - } - if (rtnl_talk(&rth, &req.n, &answer) < 0) { fprintf(stderr, "We have an error talking to the kernel\n"); return 2; From patchwork Fri Nov 24 02:12:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 840927 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="ruZDOX2J"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yjfps2mBvz9s9Y for ; Fri, 24 Nov 2017 13:12:37 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752631AbdKXCMf (ORCPT ); Thu, 23 Nov 2017 21:12:35 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:43839 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751575AbdKXCM0 (ORCPT ); Thu, 23 Nov 2017 21:12:26 -0500 Received: by mail-pl0-f68.google.com with SMTP id h3so3559678pln.10 for ; Thu, 23 Nov 2017 18:12:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gGga+IwyYqKeji9rwT9DsT3DjhrGmtOv1KcGftNerkM=; b=ruZDOX2JM3+N/CsASr2dhqjLpwb/V/F2+VUEPhoD0e+Q2PbM6LWYBiv4WkrsrfP/+5 kjTHGqcj9xRcrkoEtbHUGQliMJQvugT7I8E4jRrO1OmpDhKZYStaz3HbID4zIzOzS1dc DkJynlG5gHBDXRsjtSNo9DcZdJqvFtPKUfPQpaSHljirL3Nq7Y2PyfsLXp9fP/twbZeO n5l7LG1CDpR22sRUw0j6kaeRWqM8+5RvLQACrJVX/xj79WjPqBt8mr6MyKfnr+yulS2N 8wPxhwAIHUteW9heRsQTXmbmTrzE6K7Mbyg+dMb+2E11BrZ18QyQhm5ueyO9g5Rki4HS iqWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gGga+IwyYqKeji9rwT9DsT3DjhrGmtOv1KcGftNerkM=; b=R7WFelW9/CiO4Rrj6H2o3ObZn8nNQlRW0pIqFi3eU3IoYDBPtx1kwLpN2LnmHNVgMw 57wfiFm1qXZASwZLNbi05U7P2qRMQYE9+76OeRI53XUHbmKeu4Mog8LRSIyetOtNlTJr yIjGeAhJGLfEq0vowA/L3P/XUns3ZY5on+H2vn+Cndd9d0vLMTCL6MjKvpJ0kh1ZHvVw T43OWXI2Oc7eHzMeG7xSq/ZFKhMyAZKBSnXeqhULnpGQFnVeeEXHvZIHizFgj5Po2TSq 1ZZHI3gARMTFYTpS0TsvexdbYT75BTprIPGsn33liH1YS0HH3QpxslEiLVsd+opfGZCx Ptkw== X-Gm-Message-State: AJaThX7Li9JNmWcrSmgstB+Yu6mm0yCQts32I98ffcUexOsHkKw2/9lG /mTVNE0vSTujkPPLoywRmv+ivprm X-Google-Smtp-Source: AGs4zMY6xjYQgcjER3DTNseBjMh5Zxomz3ujVirNgc1keh9WyFeiwzIxFZkut38ybJKVQ14hKMA6xA== X-Received: by 10.159.229.10 with SMTP id s10mr27531995plq.386.1511489546198; Thu, 23 Nov 2017 18:12:26 -0800 (PST) Received: from jkicinski-Precision-T1700.netronome.com ([75.53.12.129]) by smtp.gmail.com with ESMTPSA id q12sm29400889pgn.56.2017.11.23.18.12.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 23 Nov 2017 18:12:25 -0800 (PST) From: Jakub Kicinski To: netdev@vger.kernel.org Cc: oss-drivers@netronome.com, daniel@iogearbox.net, Jakub Kicinski Subject: [PATCH iproute2/master 10/11] f_bpf: communicate ifindex for eBPF offload Date: Thu, 23 Nov 2017 18:12:07 -0800 Message-Id: <20171124021208.13419-11-jakub.kicinski@netronome.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171124021208.13419-1-jakub.kicinski@netronome.com> References: <20171124021208.13419-1-jakub.kicinski@netronome.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Split parsing and loading of the eBPF program and if skip_sw is set load the program for ifindex, to which the qdisc is attached. Note that the ifindex will be ignored for programs which are already loaded (e.g. when using pinned programs), but in that case we just trust the user knows what he's doing. Hopefully we will get extack soon in the driver to help debugging this case. Signed-off-by: Jakub Kicinski Reviewed-by: Quentin Monnet Acked-by: Daniel Borkmann --- tc/f_bpf.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tc/f_bpf.c b/tc/f_bpf.c index f598784e8b08..5906f8bb969d 100644 --- a/tc/f_bpf.c +++ b/tc/f_bpf.c @@ -82,6 +82,7 @@ static int bpf_parse_opt(struct filter_util *qu, char *handle, unsigned int bpf_flags = 0; struct bpf_cfg_in cfg = {}; bool seen_run = false; + bool skip_sw = false; struct rtattr *tail; int ret = 0; @@ -110,8 +111,11 @@ static int bpf_parse_opt(struct filter_util *qu, char *handle, cfg.argc = argc; cfg.argv = argv; - if (bpf_parse_and_load_common(&cfg, &bpf_cb_ops, n)) + if (bpf_parse_common(&cfg, &bpf_cb_ops) < 0) { + fprintf(stderr, + "Unable to parse bpf command line\n"); return -1; + } argc = cfg.argc; argv = cfg.argv; @@ -135,6 +139,7 @@ static int bpf_parse_opt(struct filter_util *qu, char *handle, bpf_gen_flags |= TCA_CLS_FLAGS_SKIP_HW; } else if (matches(*argv, "skip_sw") == 0) { bpf_gen_flags |= TCA_CLS_FLAGS_SKIP_SW; + skip_sw = true; } else if (matches(*argv, "action") == 0) { NEXT_ARG(); if (parse_action(&argc, &argv, TCA_BPF_ACT, n)) { @@ -164,6 +169,13 @@ static int bpf_parse_opt(struct filter_util *qu, char *handle, NEXT_ARG_FWD(); } + if (skip_sw) + cfg.ifindex = t->tcm_ifindex; + if (bpf_load_common(&cfg, &bpf_cb_ops, n) < 0) { + fprintf(stderr, "Unable to load program\n"); + return -1; + } + if (bpf_gen_flags) addattr32(n, MAX_MSG, TCA_BPF_FLAGS_GEN, bpf_gen_flags); if (bpf_flags) From patchwork Fri Nov 24 02:12:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 840926 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="QqY28m5t"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yjfpl4mx8z9s76 for ; Fri, 24 Nov 2017 13:12:31 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752582AbdKXCM3 (ORCPT ); Thu, 23 Nov 2017 21:12:29 -0500 Received: from mail-pl0-f65.google.com ([209.85.160.65]:37536 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752424AbdKXCM1 (ORCPT ); Thu, 23 Nov 2017 21:12:27 -0500 Received: by mail-pl0-f65.google.com with SMTP id 61so3569606plf.4 for ; Thu, 23 Nov 2017 18:12:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/BmtGayBtElnOyKo7NR/rZ6R6Pe/QMJ4TqEqV9FVFjk=; b=QqY28m5tzjm7I4I5/YBznjHYMgAAmsEIVSt+VH1S32tMluI7EgqvHAhIRW0/6boJFV eLtYtuJcAbNtXnMDnLTdr9J9cUVwpgd5V2n1wxZF37062o0dlEhEqmil+Ni7sVssvu/k PDGALItagVHQF1/48SR4jOD1Tnp46RGtSNmoyXhRr+3+Q4lD2Ae/hh4Kd6IXyKWspZ3T OL0NLhjZHh5ehrb/965a6JI2ZNW1zKpFvXEWnzqmj9avu/Rf0ODsB2hRrNEk6hO9bfNO nvW0Ky7pbdyZ066SI/BMxQhn5NcF8B3VtBzloXVkzEvQKzAUMLIUJB4w0yZtPyxX3diA 3mUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/BmtGayBtElnOyKo7NR/rZ6R6Pe/QMJ4TqEqV9FVFjk=; b=kViD1jwVKGSuCwdVmGFGtPxYgIkXJuQKHQIBdMKNVI12KPbB64Z55qbsnO1CMJ1/Vp JOHPVRx3CYvm4m1E3B0eMjplfOavlGpBqkhOyMTqvV6PZIAFiVY38BV4tdNyjlgH6dRk U0Cpxk+2FNAOG8LD7jf1FqXKgWHOHeVKK9G7nxk0su/qquJVI0wBM4xf9NwOYENLu5FX hZ+TRI4gAGsywvo9c2i+1fT4Rk9Kl0BYbuBlmtdxk1osQK7iqutRUceU86/ZJJxApcdZ J6fFYW0NK5nPYUShgDYYmSxpXyiZrUgSdGlQ4MwcvJwRXyXvACHw7SiAdNSJQlpL3QPA 8ZvQ== X-Gm-Message-State: AJaThX6YDiSvYY2ceRoUBJtzF08LhwFfyOFWq2xofxD/RjJhDICe9HsA yZRuzWBdi6oiIZcF+yYxCOXgmHbo X-Google-Smtp-Source: AGs4zMYQK5uFIuMervRrBBb7j6VeFXrFP1VNu06L1TBDMtIS/8XJcWW76FUaoUwHH8kkyn9o6WjeVg== X-Received: by 10.159.247.15 with SMTP id d15mr24423123pls.88.1511489547075; Thu, 23 Nov 2017 18:12:27 -0800 (PST) Received: from jkicinski-Precision-T1700.netronome.com ([75.53.12.129]) by smtp.gmail.com with ESMTPSA id q12sm29400889pgn.56.2017.11.23.18.12.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 23 Nov 2017 18:12:26 -0800 (PST) From: Jakub Kicinski To: netdev@vger.kernel.org Cc: oss-drivers@netronome.com, daniel@iogearbox.net, Jakub Kicinski Subject: [PATCH iproute2/master 11/11] iplink: communicate ifindex for xdp offload Date: Thu, 23 Nov 2017 18:12:08 -0800 Message-Id: <20171124021208.13419-12-jakub.kicinski@netronome.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171124021208.13419-1-jakub.kicinski@netronome.com> References: <20171124021208.13419-1-jakub.kicinski@netronome.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When xdpoffload option is used, communicate the ifindex down to the kernel to trigger device-specific load. Signed-off-by: Jakub Kicinski Reviewed-by: Quentin Monnet Acked-by: Daniel Borkmann --- ip/iplink.c | 4 ++-- ip/iplink_xdp.c | 10 ++++++++-- ip/xdp.h | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ip/iplink.c b/ip/iplink.c index 0360a0753d4a..4928f1d9489e 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -631,8 +631,8 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, bool offload = strcmp(*argv, "xdpoffload") == 0; NEXT_ARG(); - if (xdp_parse(&argc, &argv, req, generic, drv, - offload)) + if (xdp_parse(&argc, &argv, req, dev_index, + generic, drv, offload)) exit(-1); } else if (strcmp(*argv, "netns") == 0) { NEXT_ARG(); diff --git a/ip/iplink_xdp.c b/ip/iplink_xdp.c index edaec2a250e7..6eeb820af0c3 100644 --- a/ip/iplink_xdp.c +++ b/ip/iplink_xdp.c @@ -48,8 +48,8 @@ static int xdp_delete(struct xdp_req *xdp) return 0; } -int xdp_parse(int *argc, char ***argv, struct iplink_req *req, bool generic, - bool drv, bool offload) +int xdp_parse(int *argc, char ***argv, struct iplink_req *req, __u32 ifindex, + bool generic, bool drv, bool offload) { struct bpf_cfg_in cfg = { .type = BPF_PROG_TYPE_XDP, @@ -60,6 +60,12 @@ int xdp_parse(int *argc, char ***argv, struct iplink_req *req, bool generic, .req = req, }; + if (offload) { + if (!ifindex) + incomplete_command(); + cfg.ifindex = ifindex; + } + if (!force) xdp.flags |= XDP_FLAGS_UPDATE_IF_NOEXIST; if (generic) diff --git a/ip/xdp.h b/ip/xdp.h index 1efd591b087c..7400792bbeb7 100644 --- a/ip/xdp.h +++ b/ip/xdp.h @@ -3,8 +3,8 @@ #include "utils.h" -int xdp_parse(int *argc, char ***argv, struct iplink_req *req, bool generic, - bool drv, bool offload); +int xdp_parse(int *argc, char ***argv, struct iplink_req *req, __u32 ifindex, + bool generic, bool drv, bool offload); void xdp_dump(FILE *fp, struct rtattr *tb, bool link, bool details); #endif /* __XDP__ */