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=-8.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 A2E5FC43613 for ; Mon, 24 Jun 2019 11:20:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 75A11212F5 for ; Mon, 24 Jun 2019 11:20:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EXGG2msI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729312AbfFXLU2 (ORCPT ); Mon, 24 Jun 2019 07:20:28 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:39811 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728515AbfFXLU2 (ORCPT ); Mon, 24 Jun 2019 07:20:28 -0400 Received: by mail-pl1-f194.google.com with SMTP id b7so6716646pls.6 for ; Mon, 24 Jun 2019 04:20:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=SqDLjsemqHZVkEqvzObvOVSVuW+KkPPB4CHniC6UqgU=; b=EXGG2msIfL0qlSDzv/JcBU8rILD7Plk5GrxLieXHbzkF0PfXoW0vnCuMA/uoGx2NsK WUo0cdaC5QRszQ5KZ5whD7850a3YU2rdOx1IxKHzvl8h6VAVSQgVO1zyyaMJD+rc4gPR lbsrLUUR+7AaEIHKLjZJAVGC1PG66p549niP6Ym2OablhtMljOx+wm81KdKh2KEKmDq1 vPYJIqYVrJMHzF/JOQ5DcoyIIbpUG4q5mNkZdegJmCly1vDnubNLv2rzZFl339TgappQ 0Whau0n011wT+LXMqu91X8JeYqfD8bTNW42YXvgQWUkGpwoXlrU3a+wQndap675dmqzh 4q+A== 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; bh=SqDLjsemqHZVkEqvzObvOVSVuW+KkPPB4CHniC6UqgU=; b=reD/eJWOAPBXOv7TnR/SacO3gmrvKvAaeSqsuOJmwgBbzwB0TOhQN0xBndjvviJvEj OQa81l6loBarRbW/09jLUELJqEjGzXNq1tLiLdq8Dx143Tzw8Z36uet4sujK6x9GM3Al hzk3gwfJyCeYKygc6SQ3i4FYSwle5z6JEFQ1+Xdxzbr6/Gh69HuPALagZ4AZi5DKLq7G /4+jOik7NYGfYN8QErbRz1G9VVg+35sOJtJpz1PzhCjlus1PDL6RZSpkHgDgIYHvCKFM yqnp2NfIbPWxjfW25HaeOxTPup4Ie042+14OUb8Xcp2KvQ+DcP/Tzl5RKrAqxULpxEMG FFBw== X-Gm-Message-State: APjAAAVpCyQhkE4cifNpim5HKaItTNFsqi4XdMKHAaRLrq5Nk2G6bd5P xcshBlsd/j0AW/5UGu+0dg== X-Google-Smtp-Source: APXvYqx0rEC6X8lgS4ioxfTM2Whe+i5YwTHEaHve7kP3GE/ViD8WtazHPlpnBNBjZ/qSR9FyrSTMhg== X-Received: by 2002:a17:902:2bcb:: with SMTP id l69mr40533004plb.155.1561375227529; Mon, 24 Jun 2019 04:20:27 -0700 (PDT) Received: from localhost.localdomain ([111.118.56.180]) by smtp.gmail.com with ESMTPSA id a13sm10035085pgl.84.2019.06.24.04.20.25 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 24 Jun 2019 04:20:26 -0700 (PDT) From: "Daniel T. Lee" To: Daniel Borkmann , Alexei Starovoitov Cc: netdev@vger.kernel.org Subject: [PATCH] samples: bpf: make the use of xdp samples consistent Date: Mon, 24 Jun 2019 20:20:09 +0900 Message-Id: <20190624112009.20048-1-danieltimlee@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Currently, each xdp samples are inconsistent in the use. Most of the samples fetch the interface with it's name. (ex. xdp1, xdp2skb, xdp_redirect, xdp_sample_pkts, etc.) But only xdp_adjst_tail and xdp_tx_iptunnel fetch the interface with ifindex by command argument. This commit enables those two samples to fetch interface with it's name without changing the original index interface fetching. ( fetching in the same way as xdp_sample_pkts_user.c does.) Signed-off-by: Daniel T. Lee --- samples/bpf/xdp_adjust_tail_user.c | 12 ++++++++++-- samples/bpf/xdp_tx_iptunnel_user.c | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/samples/bpf/xdp_adjust_tail_user.c b/samples/bpf/xdp_adjust_tail_user.c index 586ff751aba9..a3596b617c4c 100644 --- a/samples/bpf/xdp_adjust_tail_user.c +++ b/samples/bpf/xdp_adjust_tail_user.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -69,7 +70,7 @@ static void usage(const char *cmd) printf("Start a XDP prog which send ICMP \"packet too big\" \n" "messages if ingress packet is bigger then MAX_SIZE bytes\n"); printf("Usage: %s [...]\n", cmd); - printf(" -i Interface Index\n"); + printf(" -i Interface\n"); printf(" -T Default: 0 (forever)\n"); printf(" -S use skb-mode\n"); printf(" -N enforce native mode\n"); @@ -102,7 +103,9 @@ int main(int argc, char **argv) switch (opt) { case 'i': - ifindex = atoi(optarg); + ifindex = if_nametoindex(optarg); + if (!ifindex) + ifindex = atoi(optarg); break; case 'T': kill_after_s = atoi(optarg); @@ -136,6 +139,11 @@ int main(int argc, char **argv) return 1; } + if (!ifindex) { + fprintf(stderr, "Invalid ifname\n"); + return 1; + } + snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); prog_load_attr.file = filename; diff --git a/samples/bpf/xdp_tx_iptunnel_user.c b/samples/bpf/xdp_tx_iptunnel_user.c index 394896430712..dfb68582e243 100644 --- a/samples/bpf/xdp_tx_iptunnel_user.c +++ b/samples/bpf/xdp_tx_iptunnel_user.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -83,7 +84,7 @@ static void usage(const char *cmd) "in an IPv4/v6 header and XDP_TX it out. The dst \n" "is used to select packets to encapsulate\n\n"); printf("Usage: %s [...]\n", cmd); - printf(" -i Interface Index\n"); + printf(" -i Interface\n"); printf(" -a IPv4 or IPv6\n"); printf(" -p A port range (e.g. 433-444) is also allowed\n"); printf(" -s Used in the IPTunnel header\n"); @@ -181,7 +182,9 @@ int main(int argc, char **argv) switch (opt) { case 'i': - ifindex = atoi(optarg); + ifindex = if_nametoindex(optarg); + if (!ifindex) + ifindex = atoi(optarg); break; case 'a': vip.family = parse_ipstr(optarg, vip.daddr.v6); @@ -253,6 +256,11 @@ int main(int argc, char **argv) return 1; } + if (!ifindex) { + fprintf(stderr, "Invalid ifname\n"); + return 1; + } + snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); prog_load_attr.file = filename; -- 2.17.1