* [PATCH iproute2 -next] f_bpf: allow for optional classid and add flags
@ 2015-09-25 10:32 Daniel Borkmann
2015-09-25 14:58 ` Alexei Starovoitov
2015-10-12 16:42 ` Stephen Hemminger
0 siblings, 2 replies; 3+ messages in thread
From: Daniel Borkmann @ 2015-09-25 10:32 UTC (permalink / raw)
To: stephen; +Cc: ast, netdev, Daniel Borkmann
When having optional classid, most minimal command can be sth
like:
tc filter add dev foo parent X: bpf obj prog.o
Therefore, adapt the code so that a next argument will not be
enforced as the case currently.
Also, minor cleanup on the classid, where we should rather
have used addattr32(), and add flags for exec configuration,
for example (using short notation):
tc filter add dev foo parent X: bpf da obj prog.o
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
---
include/utils.h | 1 +
tc/f_bpf.c | 43 ++++++++++++++++++++++++++++++-------------
2 files changed, 31 insertions(+), 13 deletions(-)
diff --git a/include/utils.h b/include/utils.h
index f77edeb..668d159 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -47,6 +47,7 @@ void incomplete_command(void) __attribute__((noreturn));
#define NEXT_ARG() do { argv++; if (--argc <= 0) incomplete_command(); } while(0)
#define NEXT_ARG_OK() (argc - 1 > 0)
+#define NEXT_ARG_FWD() do { argv++; argc--; } while(0)
#define PREV_ARG() do { argv--; argc++; } while(0)
typedef struct
diff --git a/tc/f_bpf.c b/tc/f_bpf.c
index 490dc6b..ac77af5 100644
--- a/tc/f_bpf.c
+++ b/tc/f_bpf.c
@@ -41,7 +41,7 @@ static void explain(void)
fprintf(stderr, "\n");
fprintf(stderr, "eBPF use case:\n");
fprintf(stderr, " object-file FILE [ section CLS_NAME ] [ export UDS_FILE ]");
- fprintf(stderr, " [ verbose ]\n");
+ fprintf(stderr, " [ verbose ] [ direct-action ]\n");
fprintf(stderr, "\n");
fprintf(stderr, "Common remaining options:\n");
fprintf(stderr, " [ action ACTION_SPEC ]\n");
@@ -69,6 +69,7 @@ static int bpf_parse_opt(struct filter_util *qu, char *handle,
struct tcmsg *t = NLMSG_DATA(n);
const char *bpf_uds_name = NULL;
const char *bpf_sec_name = NULL;
+ unsigned int bpf_flags = 0;
char *bpf_obj = NULL;
struct rtattr *tail;
bool seen_run = false;
@@ -124,25 +125,28 @@ opt_bpf:
if (ebpf) {
bpf_uds_name = getenv(BPF_ENV_UDS);
bpf_obj = *argv;
- NEXT_ARG();
- if (strcmp(*argv, "section") == 0 ||
- strcmp(*argv, "sec") == 0) {
+ NEXT_ARG_FWD();
+
+ if (argc > 0 &&
+ (strcmp(*argv, "section") == 0 ||
+ strcmp(*argv, "sec") == 0)) {
NEXT_ARG();
bpf_sec_name = *argv;
- NEXT_ARG();
+ NEXT_ARG_FWD();
}
- if (!bpf_uds_name &&
+ if (argc > 0 && !bpf_uds_name &&
(strcmp(*argv, "export") == 0 ||
strcmp(*argv, "exp") == 0)) {
NEXT_ARG();
bpf_uds_name = *argv;
- NEXT_ARG();
+ NEXT_ARG_FWD();
}
- if (strcmp(*argv, "verbose") == 0 ||
- strcmp(*argv, "verb") == 0) {
+ if (argc > 0 &&
+ (strcmp(*argv, "verbose") == 0 ||
+ strcmp(*argv, "verb") == 0)) {
bpf_verbose = true;
- NEXT_ARG();
+ NEXT_ARG_FWD();
}
PREV_ARG();
@@ -182,7 +186,10 @@ opt_bpf:
fprintf(stderr, "Illegal \"classid\"\n");
return -1;
}
- addattr_l(n, MAX_MSG, TCA_BPF_CLASSID, &handle, 4);
+ addattr32(n, MAX_MSG, TCA_BPF_CLASSID, handle);
+ } else if (matches(*argv, "direct-action") == 0 ||
+ matches(*argv, "da") == 0) {
+ bpf_flags |= TCA_BPF_FLAG_ACT_DIRECT;
} else if (matches(*argv, "action") == 0) {
NEXT_ARG();
if (parse_action(&argc, &argv, TCA_BPF_ACT, n)) {
@@ -208,10 +215,13 @@ opt_bpf:
explain();
return -1;
}
- argc--;
- argv++;
+
+ NEXT_ARG_FWD();
}
+ if (bpf_obj && bpf_flags)
+ addattr32(n, MAX_MSG, TCA_BPF_FLAGS, bpf_flags);
+
tail->rta_len = (((void *)n) + n->nlmsg_len) - (void *)tail;
if (bpf_uds_name)
@@ -244,6 +254,13 @@ static int bpf_print_opt(struct filter_util *qu, FILE *f,
else if (tb[TCA_BPF_FD])
fprintf(f, "pfd %u ", rta_getattr_u32(tb[TCA_BPF_FD]));
+ if (tb[TCA_BPF_FLAGS]) {
+ unsigned int flags = rta_getattr_u32(tb[TCA_BPF_FLAGS]);
+
+ if (flags & TCA_BPF_FLAG_ACT_DIRECT)
+ fprintf(f, "direct-action ");
+ }
+
if (tb[TCA_BPF_OPS] && tb[TCA_BPF_OPS_LEN]) {
bpf_print_ops(f, tb[TCA_BPF_OPS],
rta_getattr_u16(tb[TCA_BPF_OPS_LEN]));
--
1.9.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH iproute2 -next] f_bpf: allow for optional classid and add flags
2015-09-25 10:32 [PATCH iproute2 -next] f_bpf: allow for optional classid and add flags Daniel Borkmann
@ 2015-09-25 14:58 ` Alexei Starovoitov
2015-10-12 16:42 ` Stephen Hemminger
1 sibling, 0 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2015-09-25 14:58 UTC (permalink / raw)
To: Daniel Borkmann, stephen; +Cc: netdev
On 9/25/15 3:32 AM, Daniel Borkmann wrote:
> When having optional classid, most minimal command can be sth
> like:
>
> tc filter add dev foo parent X: bpf obj prog.o
>
> Therefore, adapt the code so that a next argument will not be
> enforced as the case currently.
>
> Also, minor cleanup on the classid, where we should rather
> have used addattr32(), and add flags for exec configuration,
> for example (using short notation):
>
> tc filter add dev foo parent X: bpf da obj prog.o
>
> Signed-off-by: Daniel Borkmann<daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@plumgrid.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH iproute2 -next] f_bpf: allow for optional classid and add flags
2015-09-25 10:32 [PATCH iproute2 -next] f_bpf: allow for optional classid and add flags Daniel Borkmann
2015-09-25 14:58 ` Alexei Starovoitov
@ 2015-10-12 16:42 ` Stephen Hemminger
1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2015-10-12 16:42 UTC (permalink / raw)
To: Daniel Borkmann; +Cc: ast, netdev
On Fri, 25 Sep 2015 12:32:41 +0200
Daniel Borkmann <daniel@iogearbox.net> wrote:
> When having optional classid, most minimal command can be sth
> like:
>
> tc filter add dev foo parent X: bpf obj prog.o
>
> Therefore, adapt the code so that a next argument will not be
> enforced as the case currently.
>
> Also, minor cleanup on the classid, where we should rather
> have used addattr32(), and add flags for exec configuration,
> for example (using short notation):
>
> tc filter add dev foo parent X: bpf da obj prog.o
>
> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Applied to net-next branch of iproute2
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-10-12 16:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-25 10:32 [PATCH iproute2 -next] f_bpf: allow for optional classid and add flags Daniel Borkmann
2015-09-25 14:58 ` Alexei Starovoitov
2015-10-12 16:42 ` Stephen Hemminger
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).