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;