netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] samples: bpf: make the use of xdp samples consistent
@ 2019-06-24 11:20 Daniel T. Lee
  2019-06-24 18:24 ` Toke Høiland-Jørgensen
  2019-06-24 23:25 ` Song Liu
  0 siblings, 2 replies; 4+ messages in thread
From: Daniel T. Lee @ 2019-06-24 11:20 UTC (permalink / raw)
  To: Daniel Borkmann, Alexei Starovoitov; +Cc: netdev

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>
---
 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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] samples: bpf: make the use of xdp samples consistent
  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
  1 sibling, 1 reply; 4+ messages in thread
From: Toke Høiland-Jørgensen @ 2019-06-24 18:24 UTC (permalink / raw)
  To: Daniel T. Lee, Daniel Borkmann, Alexei Starovoitov; +Cc: netdev

"Daniel T. Lee" <danieltimlee@gmail.com> writes:

> 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.)

The xdp_redirect and xdp_redirect_map also only accept ifindexes, not
interface names. Care to fix those while you're at it? :)

-Toke

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] samples: bpf: make the use of xdp samples consistent
  2019-06-24 18:24 ` Toke Høiland-Jørgensen
@ 2019-06-24 22:48   ` Daniel T. Lee
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel T. Lee @ 2019-06-24 22:48 UTC (permalink / raw)
  To: Toke Høiland-Jørgensen
  Cc: Daniel Borkmann, Alexei Starovoitov, netdev

Will do right away! :)

On Tue, Jun 25, 2019 at 3:24 AM Toke Høiland-Jørgensen <toke@redhat.com> wrote:
>
> "Daniel T. Lee" <danieltimlee@gmail.com> writes:
>
> > 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.)
>
> The xdp_redirect and xdp_redirect_map also only accept ifindexes, not
> interface names. Care to fix those while you're at it? :)
>
> -Toke

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] samples: bpf: make the use of xdp samples consistent
  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 23:25 ` Song Liu
  1 sibling, 0 replies; 4+ messages in thread
From: Song Liu @ 2019-06-24 23:25 UTC (permalink / raw)
  To: Daniel T. Lee; +Cc: Daniel Borkmann, Alexei Starovoitov, Networking

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
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-06-24 23:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).