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)