netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Song Liu <liu.song.a23@gmail.com>
To: "Daniel T. Lee" <danieltimlee@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>,
	Alexei Starovoitov <ast@kernel.org>,
	Networking <netdev@vger.kernel.org>
Subject: Re: [PATCH] samples: bpf: make the use of xdp samples consistent
Date: Mon, 24 Jun 2019 16:25:37 -0700	[thread overview]
Message-ID: <CAPhsuW5_KJXBcYr3AYa78Gw4Lx4TX73ri3-6wx8kEiX=ENoAVA@mail.gmail.com> (raw)
In-Reply-To: <20190624112009.20048-1-danieltimlee@gmail.com>

On Mon, Jun 24, 2019 at 6:57 AM Daniel T. Lee <danieltimlee@gmail.com> wrote:
>
> 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.
> (<ifname|ifindex> fetching in the same way as xdp_sample_pkts_user.c does.)
>
> Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>

From patchworks, I assume you will send v2.

Please also CC bpf@vger.kernel.org in v2.

Thanks,
Song

> ---
>  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 <stdio.h>
>  #include <stdlib.h>
>  #include <string.h>
> +#include <net/if.h>
>  #include <sys/resource.h>
>  #include <arpa/inet.h>
>  #include <netinet/ether.h>
> @@ -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 <ifindex> Interface Index\n");
> +       printf("    -i <ifname|ifindex> Interface\n");
>         printf("    -T <stop-after-X-seconds> 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 <stdio.h>
>  #include <stdlib.h>
>  #include <string.h>
> +#include <net/if.h>
>  #include <sys/resource.h>
>  #include <arpa/inet.h>
>  #include <netinet/ether.h>
> @@ -83,7 +84,7 @@ static void usage(const char *cmd)
>                "in an IPv4/v6 header and XDP_TX it out.  The dst <VIP:PORT>\n"
>                "is used to select packets to encapsulate\n\n");
>         printf("Usage: %s [...]\n", cmd);
> -       printf("    -i <ifindex> Interface Index\n");
> +       printf("    -i <ifname|ifindex> Interface\n");
>         printf("    -a <vip-service-address> IPv4 or IPv6\n");
>         printf("    -p <vip-service-port> A port range (e.g. 433-444) is also allowed\n");
>         printf("    -s <source-ip> 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
>

      parent reply	other threads:[~2019-06-24 23:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-24 11:20 [PATCH] samples: bpf: make the use of xdp samples consistent Daniel T. Lee
2019-06-24 18:24 ` Toke Høiland-Jørgensen
2019-06-24 22:48   ` Daniel T. Lee
2019-06-24 23:25 ` Song Liu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPhsuW5_KJXBcYr3AYa78Gw4Lx4TX73ri3-6wx8kEiX=ENoAVA@mail.gmail.com' \
    --to=liu.song.a23@gmail.com \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=danieltimlee@gmail.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).