From patchwork Mon Feb 28 01:58:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Ahern X-Patchwork-Id: 12762277 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BBA6C433EF for ; Mon, 28 Feb 2022 01:58:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232371AbiB1B7W (ORCPT ); Sun, 27 Feb 2022 20:59:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231145AbiB1B7V (ORCPT ); Sun, 27 Feb 2022 20:59:21 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5461F3DA6C for ; Sun, 27 Feb 2022 17:58:44 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E341160A1C for ; Mon, 28 Feb 2022 01:58:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8016C340F4; Mon, 28 Feb 2022 01:58:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646013523; bh=cnMDROwtdnWKeHZKno1E44nU7eeC80jeDaNRA4Q9EXg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D9whhtQK9czwduCKJxQeQ4+d0fubi4vNQaQCVwJEyhLgO1DKArgWuX6cJYkfsmtg+ 8jbBGSgVZDaHlWEzWB0/mkxHhp4tlcjmefpLoD5LSXo5GxVMYkPfVYh1N0k79T/5Of YO3DGBOGYAK5X3AHavqjc9xPeZUr+2lzLEjLr75QwGRKsHvLx8j0eg6+ArttUEN/xt uKYDvWeo2KXcdiQWMyxsW9OaCAN+xEX9dgx24CsoM/2dwveha6p40mCajBDtGHHuHr lXsd7R4bZ5Iag1R1n9cV1ERQabovQjVMh5arG2wPi1jsvfeoFC2MwNoe/HD1gPJ8qR xQULocTgzvi5A== From: David Ahern To: netdev@vger.kernel.org Cc: stephen@networkplumber.org, David Ahern Subject: [PATCH iproute2-next 1/3] bpf_glue: Remove use of bpf_load_program from libbpf Date: Sun, 27 Feb 2022 18:58:38 -0700 Message-Id: <20220228015840.1413-2-dsahern@kernel.org> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20220228015840.1413-1-dsahern@kernel.org> References: <20220228015840.1413-1-dsahern@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com bpf_load_program is deprecated starting in v0.7. The preferred bpf_prog_load requires bpf_prog_load_opts from v0.6. This creates an ugly scenario for iproute2 to work across libbpf versions from v0.1 and up. Since bpf_program_load is only used to load the builtin vrf program, just remove the libbpf call and use the legacy code. Signed-off-by: David Ahern --- lib/bpf_glue.c | 12 ------------ lib/bpf_legacy.c | 7 +++++++ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/bpf_glue.c b/lib/bpf_glue.c index 70d001840f7b..cc3015487c68 100644 --- a/lib/bpf_glue.c +++ b/lib/bpf_glue.c @@ -11,18 +11,6 @@ #include #endif -int bpf_program_load(enum bpf_prog_type type, const struct bpf_insn *insns, - size_t size_insns, const char *license, char *log, - size_t size_log) -{ -#ifdef HAVE_LIBBPF - return bpf_load_program(type, insns, size_insns / sizeof(struct bpf_insn), - license, 0, log, size_log); -#else - return bpf_prog_load_dev(type, insns, size_insns, license, 0, log, size_log); -#endif -} - int bpf_program_attach(int prog_fd, int target_fd, enum bpf_attach_type type) { #ifdef HAVE_LIBBPF diff --git a/lib/bpf_legacy.c b/lib/bpf_legacy.c index 6e3891c9f1f1..3779ae90cc1c 100644 --- a/lib/bpf_legacy.c +++ b/lib/bpf_legacy.c @@ -1126,6 +1126,13 @@ int bpf_prog_load_dev(enum bpf_prog_type type, const struct bpf_insn *insns, return bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); } +int bpf_program_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; From patchwork Mon Feb 28 01:58:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Ahern X-Patchwork-Id: 12762278 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B493C433F5 for ; Mon, 28 Feb 2022 01:58:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232374AbiB1B70 (ORCPT ); Sun, 27 Feb 2022 20:59:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231145AbiB1B7Y (ORCPT ); Sun, 27 Feb 2022 20:59:24 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 132613DA77 for ; Sun, 27 Feb 2022 17:58:46 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7DC90B80D0A for ; Mon, 28 Feb 2022 01:58:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 941FCC340E9; Mon, 28 Feb 2022 01:58:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646013524; bh=pDu/xGTxLrBpe9yl4L0UDPiW0y3OjiKwno869CjuVHA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E3hgmOovCLMXq9Xdbi1G/w6z7lP4w4CAFxrrQGsLfAwZNXi2i/xFfNh6p3R7DpxpY muKaxMPi31RmiH6dHWy15leYlyqMqT+RXmAJwZAlSJz/mNkL9XM/xduPpe3sqjk7oU CVJoE1OmRSswz5folZCOIwN06iFZ9FHvMW2WkZnGyRH/7bG3UY80rUVvstf5qjSHYY Cuola4V6HcVs6WHZp1lPWnXRpdgTM4zJyg23ygCLx1GnP4CQ6fRhhw95N7LwNas2La kD+Xlv1H39Pzvorp25z4baIv3HKozz5FrzRxaqIakX62CfF/z8e2BxBAPSZoUyz/0p 2X5zqB4Jgrm4A== From: David Ahern To: netdev@vger.kernel.org Cc: stephen@networkplumber.org, David Ahern Subject: [PATCH iproute2-next 2/3] bpf: Export bpf syscall wrapper Date: Sun, 27 Feb 2022 18:58:39 -0700 Message-Id: <20220228015840.1413-3-dsahern@kernel.org> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20220228015840.1413-1-dsahern@kernel.org> References: <20220228015840.1413-1-dsahern@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com Move bpf syscall wrapper to bpf_glue to make it available to libbpf based functions. Signed-off-by: David Ahern --- include/bpf_util.h | 2 ++ lib/bpf_glue.c | 13 +++++++++++++ lib/bpf_legacy.c | 12 ------------ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/include/bpf_util.h b/include/bpf_util.h index 53acc4106de8..abb9627556ef 100644 --- a/include/bpf_util.h +++ b/include/bpf_util.h @@ -287,6 +287,8 @@ int bpf_program_attach(int prog_fd, int target_fd, enum bpf_attach_type type); int bpf_dump_prog_info(FILE *f, uint32_t id); +int bpf(int cmd, union bpf_attr *attr, unsigned int size); + #ifdef HAVE_ELF int bpf_send_map_fds(const char *path, const char *obj); int bpf_recv_map_fds(const char *path, int *fds, struct bpf_map_aux *aux, diff --git a/lib/bpf_glue.c b/lib/bpf_glue.c index cc3015487c68..c1cf351b7359 100644 --- a/lib/bpf_glue.c +++ b/lib/bpf_glue.c @@ -4,13 +4,26 @@ * Authors: Hangbin Liu * */ +#include #include +#include #include "bpf_util.h" #ifdef HAVE_LIBBPF #include #endif +int bpf(int cmd, union bpf_attr *attr, unsigned int size) +{ +#ifdef __NR_bpf + return syscall(__NR_bpf, cmd, attr, size); +#else + fprintf(stderr, "No bpf syscall, kernel headers too old?\n"); + errno = ENOSYS; + return -1; +#endif +} + int bpf_program_attach(int prog_fd, int target_fd, enum bpf_attach_type type) { #ifdef HAVE_LIBBPF diff --git a/lib/bpf_legacy.c b/lib/bpf_legacy.c index 3779ae90cc1c..9bf7c1c493b4 100644 --- a/lib/bpf_legacy.c +++ b/lib/bpf_legacy.c @@ -33,7 +33,6 @@ #include #include #include -#include #include #include @@ -134,17 +133,6 @@ static inline __u64 bpf_ptr_to_u64(const void *ptr) return (__u64)(unsigned long)ptr; } -static int bpf(int cmd, union bpf_attr *attr, unsigned int size) -{ -#ifdef __NR_bpf - return syscall(__NR_bpf, cmd, attr, size); -#else - fprintf(stderr, "No bpf syscall, kernel headers too old?\n"); - errno = ENOSYS; - return -1; -#endif -} - static int bpf_map_update(int fd, const void *key, const void *value, uint64_t flags) { From patchwork Mon Feb 28 01:58:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Ahern X-Patchwork-Id: 12762279 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 499E4C433FE for ; Mon, 28 Feb 2022 01:58:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232380AbiB1B70 (ORCPT ); Sun, 27 Feb 2022 20:59:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232372AbiB1B7Z (ORCPT ); Sun, 27 Feb 2022 20:59:25 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53E083DDC5 for ; Sun, 27 Feb 2022 17:58:47 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0772FB80D2F for ; Mon, 28 Feb 2022 01:58:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40CC3C340F2; Mon, 28 Feb 2022 01:58:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646013524; bh=abYtWFuf72qUSIeg07hgF7NhwfA4icl5i5Y5YaX9eN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gw71suKC8glj573lom/CoHsB1DHTR43Igd+7ZuvYy0HI0Oi7n8yyOjy+klwzqmB44 Ksqks6ci82Zy9Y+a2tIDVtzUrhSLylndWNr5DedLVOWh4rdUfPQHffh10sYOX4Xo+U P7QberbtRgGBY63HrF2GFeFaSiRVHpg8iFBEwSR/PY4Ls7iIjK4NnHCRWd9E2OSg7y HP/0XEO9Htt1q1L7NzxJ+KulV7jfT9y7FjLjMALVnTUltw8VQu4oWI+XeBj8NRWbGq ARY0F8EX3ifQ8rukDrGGaeKJqzI/aJ6lGl5f0f1ivDnchBPKn4SALXLLpylWm9Ci4O YUeyifoxBfGWQ== From: David Ahern To: netdev@vger.kernel.org Cc: stephen@networkplumber.org, David Ahern Subject: [PATCH iproute2-next 3/3] bpf: Remove use of bpf_create_map_xattr Date: Sun, 27 Feb 2022 18:58:40 -0700 Message-Id: <20220228015840.1413-4-dsahern@kernel.org> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20220228015840.1413-1-dsahern@kernel.org> References: <20220228015840.1413-1-dsahern@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com bpf_create_map_xattr is deprecated in v0.7 in favor of bpf_map_create. bpf_map_create and its bpf_map_create_opts are not available across the range of v0.1 and up versions of libbpf, so change create_map to use the bpf syscall directly. Signed-off-by: David Ahern --- lib/bpf_libbpf.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/bpf_libbpf.c b/lib/bpf_libbpf.c index 921716aec8c6..f4f98caa1e58 100644 --- a/lib/bpf_libbpf.c +++ b/lib/bpf_libbpf.c @@ -54,18 +54,18 @@ static const char *get_bpf_program__section_name(const struct bpf_program *prog) static int create_map(const char *name, struct bpf_elf_map *map, __u32 ifindex, int inner_fd) { - struct bpf_create_map_attr map_attr = {}; - - map_attr.name = name; - map_attr.map_type = map->type; - map_attr.map_flags = map->flags; - map_attr.key_size = map->size_key; - map_attr.value_size = map->size_value; - map_attr.max_entries = map->max_elem; - map_attr.map_ifindex = ifindex; - map_attr.inner_map_fd = inner_fd; - - return bpf_create_map_xattr(&map_attr); + union bpf_attr attr = {}; + + attr.map_type = map->type; + strlcpy(attr.map_name, name, sizeof(attr.map_name)); + attr.map_flags = map->flags; + attr.key_size = map->size_key; + attr.value_size = map->size_value; + attr.max_entries = map->max_elem; + attr.map_ifindex = ifindex; + attr.inner_map_fd = inner_fd; + + return bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); } static int create_map_in_map(struct bpf_object *obj, struct bpf_map *map,