From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,FROM_EXCESS_BASE64, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A305BC282F6 for ; Mon, 21 Jan 2019 08:46:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 460EB20861 for ; Mon, 21 Jan 2019 08:46:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ATuVygLi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729451AbfAUIq6 (ORCPT ); Mon, 21 Jan 2019 03:46:58 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:39369 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727993AbfAUIq5 (ORCPT ); Mon, 21 Jan 2019 03:46:57 -0500 Received: by mail-lj1-f196.google.com with SMTP id t9-v6so16787723ljh.6 for ; Mon, 21 Jan 2019 00:46:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8GktFzsI3eOKU3efYKNjqwwxKUe8cAzOFOLSSy0fnK4=; b=ATuVygLiuTmde3RLOGM9kHoNUEqV5kwMobXjYP0gaAkbzTVrNCoEax9G37a8j8mh1k ec8AqR64x2D+8gB7xleSRFMGq6KsXiGdlbPe/xJd1W1dW2pN1CgBRb7fJA87/g90yAJx ykgyVHRmTEvlFHmSCf0j2YET0meMsuxLsOkpy4F6Nw5rdSL2wbXFREslMh4I0ZrX+7AL Ai6WOhGPFyoKB4UNlPWuhvaxD6ky4a4M/YTMH5nZ7aBmjMGZGcEUJAwPkNgtsnuUQ+sW X53vUkDXA0SX0g6HYLh3qjsVOJGqzHGDBCZJB5Fud1MWvJ/pIUMwerUIq1ZM8CyghsXw zwUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8GktFzsI3eOKU3efYKNjqwwxKUe8cAzOFOLSSy0fnK4=; b=KHRnLtngn3YcKfmTfVvZQCXmjXxKE2ZBXPJdPC55KKV520VONthStgPD0z0PyygosW owVJcguJ9MRTXquBzanapNsuHsDLJgOurXYZKFSFRDPQaCylItGhZ6TrLBxcseJ+wXoT gMS6ex/2dzc6ZX3xEp/uqkufapXPkx79+Nnf8+p4VtZh8RoMwh1PPj85Rs7nzQjyr17W fkwugg2NHss+Y+yr/fwNEzvjFZ09G6wEu4M6RaaHKr131YvifI7WbpvegOCpYnWgrQRP bYS4lJRUywLXeLuDupuxYPjsrsw4k9Afuqt/xLqIxnBOZ1E+DimO0M+BMaPGfmiDYHAY o6Mg== X-Gm-Message-State: AJcUukc9jMBajuJsBkCVrX9JN83ZbFS0W0e144v4qn5KIXWnu4/sjtpk XAWFGuz2Od4nHYRgaTTILho= X-Google-Smtp-Source: ALg8bN6wDyt5DdXPX/217izdh2g0O6bA1fOYXqfiOuS6EGpk7E47IAVXsLYUkmWTV82w1j1P9JkcGg== X-Received: by 2002:a2e:9059:: with SMTP id n25-v6mr17469965ljg.155.1548060414555; Mon, 21 Jan 2019 00:46:54 -0800 (PST) Received: from maciek-lenovo (host-185-93-94-63.ip-point.pl. [185.93.94.63]) by smtp.gmail.com with ESMTPSA id u24sm2138876lfi.24.2019.01.21.00.46.53 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 21 Jan 2019 00:46:54 -0800 (PST) Date: Mon, 21 Jan 2019 09:46:50 +0100 From: Maciej =?UTF-8?B?RmlqYcWCa293c2tp?= To: Jesper Dangaard Brouer Cc: Daniel Borkmann , =?UTF-8?B?QmrDtnJuIFTDtnBl?= =?UTF-8?B?bA==?= , Alexei Starovoitov , Jakub Kicinski , Jean Hsiao , netdev Subject: Re: [PATCH bpf-next 6/6] samples: bpf: Check the prog id before exiting Message-ID: <20190121094650.77df960a@maciek-lenovo> In-Reply-To: <20190117123650.646ccecb@redhat.com> References: <20190117010115.18234-1-maciejromanfijalkowski@gmail.com> <20190117010115.18234-7-maciejromanfijalkowski@gmail.com> <20190117123650.646ccecb@redhat.com> X-Mailer: Claws Mail 3.9.3 (GTK+ 2.24.23; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Dnia 2019-01-17, o godz. 12:36:50 Jesper Dangaard Brouer napisa=C5=82(a): > On Thu, 17 Jan 2019 02:01:15 +0100 > Maciej Fijalkowski wrote: >=20 > > Check the program id within the signal handler on polling xdp samples > > that were previously converted to libbpf usage. Avoid the situation of > > unloading the program that was not attached by sample that is exiting. >=20 > I love that you are doing this work! QA have already hit these kind of > issues, and I've had to deal with figuring out why certain combination > of QA testing was failing. >=20 Glad to hear that! This actually also came from our validation engineers, s= o it seems this is a common issue. I have also seen some old email threads where= you were mentioning this problem. > Bj=C3=B8rn and I are working on hashing out XDP programs per RXQ see[1]. = I > do think that this API: > bpf_get_link_xdp_id(ifindex, &curr_prog_id, xdp_flags); >=20 > Will be will be compatible with our proposed semantic[1], as this reads > the "global-prog" (and later if match unloads the "global-prog"). > > [1] > https://github.com/xdp-project/xdp-project/blob/master/areas/core/xdp_per= _rxq01.org#interface-semantics >=20 > > Signed-off-by: Maciej Fijalkowski > > Reviewed-by: Jakub Kicinski > > --- > > samples/bpf/xdp1_user.c | 19 +++++++++++++++- > > samples/bpf/xdp_adjust_tail_user.c | 25 +++++++++++++++++---- > > samples/bpf/xdp_redirect_map_user.c | 37 ++++++++++++++++++++++++++++-= -- > > samples/bpf/xdp_redirect_user.c | 38 +++++++++++++++++++++++++++++= --- > > samples/bpf/xdp_router_ipv4_user.c | 43 > > ++++++++++++++++++++++--------------- samples/bpf/xdp_rxq_info_user.c = | > > 28 +++++++++++++++++++----- samples/bpf/xdp_sample_pkts_user.c | 29 > > ++++++++++++++++++++----- samples/bpf/xdp_tx_iptunnel_user.c | 23 > > +++++++++++++++++--- samples/bpf/xdpsock_user.c | 18 > > +++++++++++++++- 9 files changed, 218 insertions(+), 42 deletions(-) > >=20 > > diff --git a/samples/bpf/xdp1_user.c b/samples/bpf/xdp1_user.c > > index 505bce207165..3acc0e1d589a 100644 > > --- a/samples/bpf/xdp1_user.c > > +++ b/samples/bpf/xdp1_user.c > > @@ -23,10 +23,17 @@ > > =20 > > static int ifindex; > > static __u32 xdp_flags =3D XDP_FLAGS_UPDATE_IF_NOEXIST; > > +static __u32 prog_id; > > =20 > > static void int_exit(int sig) > > { > > - bpf_set_link_xdp_fd(ifindex, -1, xdp_flags); > > + __u32 curr_prog_id; > > + > > + bpf_get_link_xdp_id(ifindex, &curr_prog_id, xdp_flags); > > + if (prog_id =3D=3D curr_prog_id) > > + bpf_set_link_xdp_fd(ifindex, -1, xdp_flags); > > + else > > + printf("program on interface changed, not removing\n"); > > exit(0); > > } > > =20 > > @@ -74,11 +81,14 @@ int main(int argc, char **argv) > > struct bpf_prog_load_attr prog_load_attr =3D { > > .prog_type =3D BPF_PROG_TYPE_XDP, > > }; > > + struct bpf_prog_info info =3D {}; > > + __u32 info_len =3D sizeof(info); > > const char *optstr =3D "FSN"; > > int prog_fd, map_fd, opt; > > struct bpf_object *obj; > > struct bpf_map *map; > > char filename[256]; > > + int err; > > =20 > > while ((opt =3D getopt(argc, argv, optstr)) !=3D -1) { > > switch (opt) { > > @@ -139,6 +149,13 @@ int main(int argc, char **argv) > > return 1; > > } > > =20 > > + err =3D bpf_obj_get_info_by_fd(prog_fd, &info, &info_len); > > + if (err) { > > + printf("can't get prog info - %s\n", strerror(errno)); > > + return err; > > + } > > + prog_id =3D info.id; > > + > > poll_stats(map_fd, 2); > > =20 > > return 0; > > diff --git a/samples/bpf/xdp_adjust_tail_user.c > > b/samples/bpf/xdp_adjust_tail_user.c index 049bddf7778b..01fc700d6a0c 1= 00644 > > --- a/samples/bpf/xdp_adjust_tail_user.c > > +++ b/samples/bpf/xdp_adjust_tail_user.c > > @@ -25,11 +25,19 @@ > > =20 > > static int ifindex =3D -1; > > static __u32 xdp_flags =3D XDP_FLAGS_UPDATE_IF_NOEXIST; > > +static __u32 prog_id; > > =20 > > static void int_exit(int sig) > > { > > - if (ifindex > -1) > > - bpf_set_link_xdp_fd(ifindex, -1, xdp_flags); > > + __u32 curr_prog_id; > > + > > + if (ifindex > -1) { > > + bpf_get_link_xdp_id(ifindex, &curr_prog_id, xdp_flags); > > + if (prog_id =3D=3D curr_prog_id) > > + bpf_set_link_xdp_fd(ifindex, -1, xdp_flags); > > + else > > + printf("program on interface changed, not > > removing\n"); > > + } > > exit(0); > > } > > =20 > > @@ -72,11 +80,14 @@ int main(int argc, char **argv) > > }; > > unsigned char opt_flags[256] =3D {}; > > const char *optstr =3D "i:T:SNFh"; > > + struct bpf_prog_info info =3D {}; > > + __u32 info_len =3D sizeof(info); > > unsigned int kill_after_s =3D 0; > > int i, prog_fd, map_fd, opt; > > struct bpf_object *obj; > > struct bpf_map *map; > > char filename[256]; > > + int err; > > =20 > > for (i =3D 0; i < strlen(optstr); i++) > > if (optstr[i] !=3D 'h' && 'a' <=3D optstr[i] && optstr[i] <=3D > > 'z') @@ -146,9 +157,15 @@ int main(int argc, char **argv) > > return 1; > > } > > =20 > > - poll_stats(map_fd, kill_after_s); > > + err =3D bpf_obj_get_info_by_fd(prog_fd, &info, &info_len); > > + if (err) { > > + printf("can't get prog info - %s\n", strerror(errno)); > > + return 1; > > + } > > + prog_id =3D info.id; > > =20 > > - bpf_set_link_xdp_fd(ifindex, -1, xdp_flags); > > + poll_stats(map_fd, kill_after_s); > > + int_exit(0); > > =20 > > return 0; > > } > > diff --git a/samples/bpf/xdp_redirect_map_user.c > > b/samples/bpf/xdp_redirect_map_user.c index 470e1a7e8810..cae7b9cead74 > > 100644 --- a/samples/bpf/xdp_redirect_map_user.c > > +++ b/samples/bpf/xdp_redirect_map_user.c > > @@ -29,15 +29,29 @@ > > static int ifindex_in; > > static int ifindex_out; > > static bool ifindex_out_xdp_dummy_attached =3D true; > > +static __u32 prog_id; > > +static __u32 dummy_prog_id; > > =20 > > static __u32 xdp_flags =3D XDP_FLAGS_UPDATE_IF_NOEXIST; > > static int rxcnt_map_fd; > > =20 > > static void int_exit(int sig) > > { > > - bpf_set_link_xdp_fd(ifindex_in, -1, xdp_flags); > > - if (ifindex_out_xdp_dummy_attached) > > - bpf_set_link_xdp_fd(ifindex_out, -1, xdp_flags); > > + __u32 curr_prog_id; > > + > > + bpf_get_link_xdp_id(ifindex_in, &curr_prog_id, xdp_flags); > > + if (prog_id =3D=3D curr_prog_id) > > + bpf_set_link_xdp_fd(ifindex_in, -1, xdp_flags); > > + else > > + printf("program on iface IN changed, not removing\n"); > > + > > + if (ifindex_out_xdp_dummy_attached) { > > + bpf_get_link_xdp_id(ifindex_out, &curr_prog_id, xdp_flags); > > + if (dummy_prog_id =3D=3D curr_prog_id) > > + bpf_set_link_xdp_fd(ifindex_out, -1, xdp_flags); > > + else > > + printf("program on iface OUT changed, not > > removing\n"); > > + } > > exit(0); > > } > > =20 > > @@ -82,6 +96,8 @@ int main(int argc, char **argv) > > .prog_type =3D BPF_PROG_TYPE_XDP, > > }; > > struct bpf_program *prog, *dummy_prog; > > + struct bpf_prog_info info =3D {}; > > + __u32 info_len =3D sizeof(info); > > int prog_fd, dummy_prog_fd; > > const char *optstr =3D "FSN"; > > struct bpf_object *obj; > > @@ -153,6 +169,13 @@ int main(int argc, char **argv) > > return 1; > > } > > =20 > > + ret =3D bpf_obj_get_info_by_fd(prog_fd, &info, &info_len); > > + if (ret) { > > + printf("can't get prog info - %s\n", strerror(errno)); > > + return ret; > > + } > > + prog_id =3D info.id; > > + > > /* Loading dummy XDP prog on out-device */ > > if (bpf_set_link_xdp_fd(ifindex_out, dummy_prog_fd, > > (xdp_flags | XDP_FLAGS_UPDATE_IF_NOEXIST)) < > > 0) { @@ -160,6 +183,14 @@ int main(int argc, char **argv) > > ifindex_out_xdp_dummy_attached =3D false; > > } > > =20 > > + memset(&info, 0, sizeof(info)); > > + ret =3D bpf_obj_get_info_by_fd(dummy_prog_fd, &info, &info_len); > > + if (ret) { > > + printf("can't get prog info - %s\n", strerror(errno)); > > + return ret; > > + } > > + dummy_prog_id =3D info.id; > > + > > signal(SIGINT, int_exit); > > signal(SIGTERM, int_exit); > > =20 > > diff --git a/samples/bpf/xdp_redirect_user.c > > b/samples/bpf/xdp_redirect_user.c index be6058cda97c..230b1e5e7f61 1006= 44 > > --- a/samples/bpf/xdp_redirect_user.c > > +++ b/samples/bpf/xdp_redirect_user.c > > @@ -29,15 +29,30 @@ > > static int ifindex_in; > > static int ifindex_out; > > static bool ifindex_out_xdp_dummy_attached =3D true; > > +static __u32 prog_id; > > +static __u32 dummy_prog_id; > > =20 > > static __u32 xdp_flags =3D XDP_FLAGS_UPDATE_IF_NOEXIST; > > static int rxcnt_map_fd; > > =20 > > static void int_exit(int sig) > > { > > - bpf_set_link_xdp_fd(ifindex_in, -1, xdp_flags); > > - if (ifindex_out_xdp_dummy_attached) > > - bpf_set_link_xdp_fd(ifindex_out, -1, xdp_flags); > > + __u32 curr_prog_id; > > + > > + bpf_get_link_xdp_id(ifindex_in, &curr_prog_id, xdp_flags); > > + if (prog_id =3D=3D curr_prog_id) > > + bpf_set_link_xdp_fd(ifindex_in, -1, xdp_flags); > > + else > > + printf("program on iface IN changed, not removing\n"); > > + > > + if (ifindex_out_xdp_dummy_attached) { > > + bpf_get_link_xdp_id(ifindex_out, &curr_prog_id, > > + xdp_flags); > > + if (dummy_prog_id =3D=3D curr_prog_id) > > + bpf_set_link_xdp_fd(ifindex_out, -1, xdp_flags); > > + else > > + printf("program on iface OUT changed, not > > removing\n"); > > + } > > exit(0); > > } > > =20 > > @@ -84,6 +99,8 @@ int main(int argc, char **argv) > > }; > > struct bpf_program *prog, *dummy_prog; > > int prog_fd, tx_port_map_fd, opt; > > + struct bpf_prog_info info =3D {}; > > + __u32 info_len =3D sizeof(info); > > const char *optstr =3D "FSN"; > > struct bpf_object *obj; > > char filename[256]; > > @@ -154,6 +171,13 @@ int main(int argc, char **argv) > > return 1; > > } > > =20 > > + ret =3D bpf_obj_get_info_by_fd(prog_fd, &info, &info_len); > > + if (ret) { > > + printf("can't get prog info - %s\n", strerror(errno)); > > + return ret; > > + } > > + prog_id =3D info.id; > > + > > /* Loading dummy XDP prog on out-device */ > > if (bpf_set_link_xdp_fd(ifindex_out, dummy_prog_fd, > > (xdp_flags | XDP_FLAGS_UPDATE_IF_NOEXIST)) < > > 0) { @@ -161,6 +185,14 @@ int main(int argc, char **argv) > > ifindex_out_xdp_dummy_attached =3D false; > > } > > =20 > > + memset(&info, 0, sizeof(info)); > > + ret =3D bpf_obj_get_info_by_fd(prog_fd, &info, &info_len); > > + if (ret) { > > + printf("can't get prog info - %s\n", strerror(errno)); > > + return ret; > > + } > > + dummy_prog_id =3D info.id; > > + > > signal(SIGINT, int_exit); > > signal(SIGTERM, int_exit); > > =20 > > diff --git a/samples/bpf/xdp_router_ipv4_user.c > > b/samples/bpf/xdp_router_ipv4_user.c index 208d6a996478..3991bd42b20c 1= 00644 > > --- a/samples/bpf/xdp_router_ipv4_user.c > > +++ b/samples/bpf/xdp_router_ipv4_user.c > > @@ -30,7 +30,8 @@ > > =20 > > int sock, sock_arp, flags =3D XDP_FLAGS_UPDATE_IF_NOEXIST; > > static int total_ifindex; > > -int *ifindex_list; > > +static int *ifindex_list; > > +static __u32 *prog_id_list; > > char buf[8192]; > > static int lpm_map_fd; > > static int rxcnt_map_fd; > > @@ -41,23 +42,26 @@ static int tx_port_map_fd; > > static int get_route_table(int rtm_family); > > static void int_exit(int sig) > > { > > + __u32 prog_id; > > int i =3D 0; > > =20 > > - for (i =3D 0; i < total_ifindex; i++) > > - bpf_set_link_xdp_fd(ifindex_list[i], -1, flags); > > + for (i =3D 0; i < total_ifindex; i++) { > > + bpf_get_link_xdp_id(ifindex_list[i], &prog_id, flags); > > + if (prog_id_list[i] =3D=3D prog_id) > > + bpf_set_link_xdp_fd(ifindex_list[i], -1, flags); > > + else > > + printf("program on iface %d changed, not > > removing\n", > > + ifindex_list[i]); > > + } > > exit(0); > > } > > =20 > > static void close_and_exit(int sig) > > { > > - int i =3D 0; > > - > > close(sock); > > close(sock_arp); > > =20 > > - for (i =3D 0; i < total_ifindex; i++) > > - bpf_set_link_xdp_fd(ifindex_list[i], -1, flags); > > - exit(0); > > + int_exit(0); > > } > > =20 > > /* Get the mac address of the interface given interface name */ > > @@ -186,13 +190,8 @@ static void read_route(struct nlmsghdr *nh, int nl= l) > > route.iface_name =3D alloca(sizeof(char *) * IFNAMSIZ); > > route.iface_name =3D if_indextoname(route.iface, > > route.iface_name); route.mac =3D getmac(route.iface_name); > > - if (route.mac =3D=3D -1) { > > - int i =3D 0; > > - > > - for (i =3D 0; i < total_ifindex; i++) > > - bpf_set_link_xdp_fd(ifindex_list[i], -1, > > flags); > > - exit(0); > > - } > > + if (route.mac =3D=3D -1) > > + int_exit(0); > > assert(bpf_map_update_elem(tx_port_map_fd, > > &route.iface, &route.iface, 0) > > =3D=3D 0); if (rtm_family =3D=3D AF_INET) { > > @@ -625,12 +624,14 @@ int main(int ac, char **argv) > > struct bpf_prog_load_attr prog_load_attr =3D { > > .prog_type =3D BPF_PROG_TYPE_XDP, > > }; > > + struct bpf_prog_info info =3D {}; > > + __u32 info_len =3D sizeof(info); > > const char *optstr =3D "SF"; > > struct bpf_object *obj; > > char filename[256]; > > char **ifname_list; > > int prog_fd, opt; > > - int i =3D 1; > > + int err, i =3D 1; > > =20 > > snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); > > prog_load_attr.file =3D filename; > > @@ -687,7 +688,7 @@ int main(int ac, char **argv) > > return 1; > > } > > =20 > > - ifindex_list =3D (int *)malloc(total_ifindex * sizeof(int *)); > > + ifindex_list =3D (int *)calloc(total_ifindex, sizeof(int *)); > > for (i =3D 0; i < total_ifindex; i++) { > > ifindex_list[i] =3D if_nametoindex(ifname_list[i]); > > if (!ifindex_list[i]) { > > @@ -696,6 +697,7 @@ int main(int ac, char **argv) > > return 1; > > } > > } > > + prog_id_list =3D (__u32 *)calloc(total_ifindex, sizeof(__u32 *)); > > for (i =3D 0; i < total_ifindex; i++) { > > if (bpf_set_link_xdp_fd(ifindex_list[i], prog_fd, flags) < > > 0) { printf("link set xdp fd failed\n"); > > @@ -706,6 +708,13 @@ int main(int ac, char **argv) > > =20 > > return 1; > > } > > + err =3D bpf_obj_get_info_by_fd(prog_fd, &info, &info_len); > > + if (err) { > > + printf("can't get prog info - %s\n", > > strerror(errno)); > > + return err; > > + } > > + prog_id_list[i] =3D info.id; > > + memset(&info, 0, sizeof(info)); > > printf("Attached to %d\n", ifindex_list[i]); > > } > > signal(SIGINT, int_exit); > > diff --git a/samples/bpf/xdp_rxq_info_user.c > > b/samples/bpf/xdp_rxq_info_user.c index e7a98c2a440f..7602a54eeba6 1006= 44 > > --- a/samples/bpf/xdp_rxq_info_user.c > > +++ b/samples/bpf/xdp_rxq_info_user.c > > @@ -29,6 +29,7 @@ static const char *__doc__ =3D " XDP RX-queue info ex= tract > > example\n\n" static int ifindex =3D -1; > > static char ifname_buf[IF_NAMESIZE]; > > static char *ifname; > > +static __u32 prog_id; > > =20 > > static __u32 xdp_flags =3D XDP_FLAGS_UPDATE_IF_NOEXIST; > > =20 > > @@ -58,11 +59,19 @@ static const struct option long_options[] =3D { > > =20 > > static void int_exit(int sig) > > { > > - fprintf(stderr, > > - "Interrupted: Removing XDP program on ifindex:%d > > device:%s\n", > > - ifindex, ifname); > > - if (ifindex > -1) > > - bpf_set_link_xdp_fd(ifindex, -1, xdp_flags); > > + __u32 curr_prog_id; > > + > > + if (ifindex > -1) { > > + bpf_get_link_xdp_id(ifindex, &curr_prog_id, xdp_flags); > > + if (prog_id =3D=3D curr_prog_id) { > > + fprintf(stderr, > > + "Interrupted: Removing XDP program on > > ifindex:%d device:%s\n", > > + ifindex, ifname); > > + bpf_set_link_xdp_fd(ifindex, -1, xdp_flags); > > + } else { > > + printf("program on interface changed, not > > removing\n"); > > + } > > + } > > exit(EXIT_OK); > > } > > =20 > > @@ -447,6 +456,8 @@ int main(int argc, char **argv) > > struct bpf_prog_load_attr prog_load_attr =3D { > > .prog_type =3D BPF_PROG_TYPE_XDP, > > }; > > + struct bpf_prog_info info =3D {}; > > + __u32 info_len =3D sizeof(info); > > int prog_fd, map_fd, opt, err; > > bool use_separators =3D true; > > struct config cfg =3D { 0 }; > > @@ -580,6 +591,13 @@ int main(int argc, char **argv) > > return EXIT_FAIL_XDP; > > } > > =20 > > + err =3D bpf_obj_get_info_by_fd(prog_fd, &info, &info_len); > > + if (err) { > > + printf("can't get prog info - %s\n", strerror(errno)); > > + return err; > > + } > > + prog_id =3D info.id; > > + > > stats_poll(interval, action, cfg_options); > > return EXIT_OK; > > } > > diff --git a/samples/bpf/xdp_sample_pkts_user.c > > b/samples/bpf/xdp_sample_pkts_user.c index 362ad35b524d..dcf78fbc371e 1= 00644 > > --- a/samples/bpf/xdp_sample_pkts_user.c > > +++ b/samples/bpf/xdp_sample_pkts_user.c > > @@ -24,25 +24,44 @@ static int pmu_fds[MAX_CPUS], if_idx; > > static struct perf_event_mmap_page *headers[MAX_CPUS]; > > static char *if_name; > > static __u32 xdp_flags =3D XDP_FLAGS_UPDATE_IF_NOEXIST; > > +static __u32 prog_id; > > =20 > > static int do_attach(int idx, int fd, const char *name) > > { > > + struct bpf_prog_info info =3D {}; > > + __u32 info_len =3D sizeof(info); > > int err; > > =20 > > err =3D bpf_set_link_xdp_fd(idx, fd, xdp_flags); > > - if (err < 0) > > + if (err < 0) { > > printf("ERROR: failed to attach program to %s\n", name); > > + return err; > > + } > > + > > + err =3D bpf_obj_get_info_by_fd(fd, &info, &info_len); > > + if (err) { > > + printf("can't get prog info - %s\n", strerror(errno)); > > + return err; > > + } > > + prog_id =3D info.id; > > =20 > > return err; > > } > > =20 > > static int do_detach(int idx, const char *name) > > { > > - int err; > > + __u32 curr_prog_id; > > + int err =3D 0; > > =20 > > - err =3D bpf_set_link_xdp_fd(idx, -1, 0); > > - if (err < 0) > > - printf("ERROR: failed to detach program from %s\n", name); > > + bpf_get_link_xdp_id(idx, &curr_prog_id, 0); > > + > > + if (prog_id =3D=3D curr_prog_id) { > > + err =3D bpf_set_link_xdp_fd(idx, -1, 0); > > + if (err < 0) > > + printf("ERROR: failed to detach prog from %s\n", > > name); > > + } else { > > + printf("program on interface changed, not removing\n"); > > + } > > =20 > > return err; > > } > > diff --git a/samples/bpf/xdp_tx_iptunnel_user.c > > b/samples/bpf/xdp_tx_iptunnel_user.c index e3de60930d27..4c1b9b14aa79 1= 00644 > > --- a/samples/bpf/xdp_tx_iptunnel_user.c > > +++ b/samples/bpf/xdp_tx_iptunnel_user.c > > @@ -27,11 +27,19 @@ > > static int ifindex =3D -1; > > static __u32 xdp_flags =3D XDP_FLAGS_UPDATE_IF_NOEXIST; > > static int rxcnt_map_fd; > > +static __u32 prog_id; > > =20 > > static void int_exit(int sig) > > { > > - if (ifindex > -1) > > - bpf_set_link_xdp_fd(ifindex, -1, xdp_flags); > > + __u32 curr_prog_id; > > + > > + if (ifindex > -1) { > > + bpf_get_link_xdp_id(ifindex, &curr_prog_id, xdp_flags); > > + if (prog_id =3D=3D curr_prog_id) > > + bpf_set_link_xdp_fd(ifindex, -1, xdp_flags); > > + else > > + printf("program on interface changed, not > > removing\n"); > > + } > > exit(0); > > } > > =20 > > @@ -148,13 +156,15 @@ int main(int argc, char **argv) > > int min_port =3D 0, max_port =3D 0, vip2tnl_map_fd; > > const char *optstr =3D "i:a:p:s:d:m:T:P:FSNh"; > > unsigned char opt_flags[256] =3D {}; > > + struct bpf_prog_info info =3D {}; > > + __u32 info_len =3D sizeof(info); > > unsigned int kill_after_s =3D 0; > > struct iptnl_info tnl =3D {}; > > struct bpf_object *obj; > > struct vip vip =3D {}; > > char filename[256]; > > int opt, prog_fd; > > - int i; > > + int i, err; > > =20 > > tnl.family =3D AF_UNSPEC; > > vip.protocol =3D IPPROTO_TCP; > > @@ -276,6 +286,13 @@ int main(int argc, char **argv) > > return 1; > > } > > =20 > > + err =3D bpf_obj_get_info_by_fd(prog_fd, &info, &info_len); > > + if (err) { > > + printf("can't get prog info - %s\n", strerror(errno)); > > + return err; > > + } > > + prog_id =3D info.id; > > + > > poll_stats(kill_after_s); > > =20 > > bpf_set_link_xdp_fd(ifindex, -1, xdp_flags); > > diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c > > index 188723784768..d7fb74d9a223 100644 > > --- a/samples/bpf/xdpsock_user.c > > +++ b/samples/bpf/xdpsock_user.c > > @@ -76,6 +76,7 @@ static int opt_poll; > > static int opt_shared_packet_buffer; > > static int opt_interval =3D 1; > > static u32 opt_xdp_bind_flags; > > +static __u32 prog_id; > > =20 > > struct xdp_umem_uqueue { > > u32 cached_prod; > > @@ -631,9 +632,15 @@ static void *poller(void *arg) > > =20 > > static void int_exit(int sig) > > { > > + __u32 curr_prog_id; > > + > > (void)sig; > > dump_stats(); > > - bpf_set_link_xdp_fd(opt_ifindex, -1, opt_xdp_flags); > > + bpf_get_link_xdp_id(opt_ifindex, &curr_prog_id, opt_xdp_flags); > > + if (prog_id =3D=3D curr_prog_id) > > + bpf_set_link_xdp_fd(opt_ifindex, -1, opt_xdp_flags); > > + else > > + printf("program on interface changed, not removing\n"); > > exit(EXIT_SUCCESS); > > } > > =20 > > @@ -907,6 +914,8 @@ int main(int argc, char **argv) > > .prog_type =3D BPF_PROG_TYPE_XDP, > > }; > > int prog_fd, qidconf_map, xsks_map; > > + struct bpf_prog_info info =3D {}; > > + __u32 info_len =3D sizeof(info); > > struct bpf_object *obj; > > char xdp_filename[256]; > > struct bpf_map *map; > > @@ -953,6 +962,13 @@ int main(int argc, char **argv) > > exit(EXIT_FAILURE); > > } > > =20 > > + ret =3D bpf_obj_get_info_by_fd(prog_fd, &info, &info_len); > > + if (ret) { > > + printf("can't get prog info - %s\n", strerror(errno)); > > + return 1; > > + } > > + prog_id =3D info.id; > > + > > ret =3D bpf_map_update_elem(qidconf_map, &key, &opt_queue, 0); > > if (ret) { > > fprintf(stderr, "ERROR: bpf_map_update_elem qidconf\n"); >=20 >=20 >=20