mirror of
https://git.kernel.org/pub/scm/network/iproute2/iproute2.git
synced 2024-11-16 14:35:34 +08:00
4bd624467b
This work follows upon commit 6256f8c9e4
("tc, bpf: finalize eBPF
support for cls and act front-end") and takes up the idea proposed by
Hannes Frederic Sowa to spawn a shell (or any other command) that holds
generated eBPF map file descriptors.
File descriptors, based on their id, are being fetched from the same
unix domain socket as demonstrated in the bpf_agent, the shell spawned
via execvpe(2) and the map fds passed over the environment, and thus
are made available to applications in the fashion of std{in,out,err}
for read/write access, for example in case of iproute2's examples/bpf/:
# env | grep BPF
BPF_NUM_MAPS=3
BPF_MAP1=6 <- BPF_MAP_ID_QUEUE (id 1)
BPF_MAP0=5 <- BPF_MAP_ID_PROTO (id 0)
BPF_MAP2=7 <- BPF_MAP_ID_DROPS (id 2)
# ls -la /proc/self/fd
[...]
lrwx------. 1 root root 64 Apr 14 16:46 0 -> /dev/pts/4
lrwx------. 1 root root 64 Apr 14 16:46 1 -> /dev/pts/4
lrwx------. 1 root root 64 Apr 14 16:46 2 -> /dev/pts/4
[...]
lrwx------. 1 root root 64 Apr 14 16:46 5 -> anon_inode:bpf-map
lrwx------. 1 root root 64 Apr 14 16:46 6 -> anon_inode:bpf-map
lrwx------. 1 root root 64 Apr 14 16:46 7 -> anon_inode:bpf-map
The advantage (as opposed to the direct/native usage) is that now the
shell is map fd owner and applications can terminate and easily reattach
to descriptors w/o any kernel changes. Moreover, multiple applications
can easily read/write eBPF maps simultaneously.
To further allow users for experimenting with that, next step is to add
a small helper that can get along with simple data types, so that also
shell scripts can make use of bpf syscall, f.e to read/write into maps.
Generally, this allows for prepopulating maps, or any runtime altering
which could influence eBPF program behaviour (f.e. different run-time
classifications, skb modifications, ...), dumping of statistics, etc.
Reference: http://thread.gmane.org/gmane.linux.network/357471/focus=357860
Suggested-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Acked-by: Alexei Starovoitov <ast@plumgrid.com>
111 lines
4.0 KiB
C
111 lines
4.0 KiB
C
#ifndef _TC_UTIL_H_
|
|
#define _TC_UTIL_H_ 1
|
|
|
|
#define MAX_MSG 16384
|
|
#include <linux/pkt_sched.h>
|
|
#include <linux/pkt_cls.h>
|
|
#include <linux/gen_stats.h>
|
|
#include "tc_core.h"
|
|
|
|
/* This is the deprecated multiqueue interface */
|
|
#ifndef TCA_PRIO_MAX
|
|
enum
|
|
{
|
|
TCA_PRIO_UNSPEC,
|
|
TCA_PRIO_MQ,
|
|
__TCA_PRIO_MAX
|
|
};
|
|
|
|
#define TCA_PRIO_MAX (__TCA_PRIO_MAX - 1)
|
|
#endif
|
|
|
|
struct qdisc_util {
|
|
struct qdisc_util *next;
|
|
const char *id;
|
|
int (*parse_qopt)(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n);
|
|
int (*print_qopt)(struct qdisc_util *qu, FILE *f, struct rtattr *opt);
|
|
int (*print_xstats)(struct qdisc_util *qu, FILE *f, struct rtattr *xstats);
|
|
|
|
int (*parse_copt)(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n);
|
|
int (*print_copt)(struct qdisc_util *qu, FILE *f, struct rtattr *opt);
|
|
};
|
|
|
|
extern __u16 f_proto;
|
|
struct filter_util {
|
|
struct filter_util *next;
|
|
char id[16];
|
|
int (*parse_fopt)(struct filter_util *qu, char *fhandle, int argc,
|
|
char **argv, struct nlmsghdr *n);
|
|
int (*print_fopt)(struct filter_util *qu, FILE *f, struct rtattr *opt, __u32 fhandle);
|
|
};
|
|
|
|
struct action_util {
|
|
struct action_util *next;
|
|
char id[16];
|
|
int (*parse_aopt)(struct action_util *a, int *argc, char ***argv,
|
|
int code, struct nlmsghdr *n);
|
|
int (*print_aopt)(struct action_util *au, FILE *f, struct rtattr *opt);
|
|
int (*print_xstats)(struct action_util *au, FILE *f, struct rtattr *xstats);
|
|
};
|
|
|
|
struct exec_util {
|
|
struct exec_util *next;
|
|
char id[16];
|
|
int (*parse_eopt)(struct exec_util *eu, int argc, char **argv);
|
|
};
|
|
|
|
extern const char *get_tc_lib(void);
|
|
|
|
extern struct qdisc_util *get_qdisc_kind(const char *str);
|
|
extern struct filter_util *get_filter_kind(const char *str);
|
|
|
|
extern int get_qdisc_handle(__u32 *h, const char *str);
|
|
extern int get_rate(unsigned *rate, const char *str);
|
|
extern int get_rate64(__u64 *rate, const char *str);
|
|
extern int get_size(unsigned *size, const char *str);
|
|
extern int get_size_and_cell(unsigned *size, int *cell_log, char *str);
|
|
extern int get_time(unsigned *time, const char *str);
|
|
extern int get_linklayer(unsigned *val, const char *arg);
|
|
|
|
extern void print_rate(char *buf, int len, __u64 rate);
|
|
extern void print_size(char *buf, int len, __u32 size);
|
|
extern void print_qdisc_handle(char *buf, int len, __u32 h);
|
|
extern void print_time(char *buf, int len, __u32 time);
|
|
extern void print_linklayer(char *buf, int len, unsigned linklayer);
|
|
|
|
extern char * sprint_rate(__u64 rate, char *buf);
|
|
extern char * sprint_size(__u32 size, char *buf);
|
|
extern char * sprint_qdisc_handle(__u32 h, char *buf);
|
|
extern char * sprint_tc_classid(__u32 h, char *buf);
|
|
extern char * sprint_time(__u32 time, char *buf);
|
|
extern char * sprint_ticks(__u32 ticks, char *buf);
|
|
extern char * sprint_linklayer(unsigned linklayer, char *buf);
|
|
|
|
extern void print_tcstats_attr(FILE *fp, struct rtattr *tb[], char *prefix, struct rtattr **xstats);
|
|
extern void print_tcstats2_attr(FILE *fp, struct rtattr *rta, char *prefix, struct rtattr **xstats);
|
|
|
|
extern int get_tc_classid(__u32 *h, const char *str);
|
|
extern int print_tc_classid(char *buf, int len, __u32 h);
|
|
extern char * sprint_tc_classid(__u32 h, char *buf);
|
|
|
|
extern int tc_print_police(FILE *f, struct rtattr *tb);
|
|
extern int parse_police(int *, char ***, int, struct nlmsghdr *);
|
|
|
|
extern char *action_n2a(int action, char *buf, int len);
|
|
extern int action_a2n(char *arg, int *result);
|
|
extern int act_parse_police(struct action_util *a,int *, char ***, int, struct nlmsghdr *);
|
|
extern int print_police(struct action_util *a, FILE *f,
|
|
struct rtattr *tb);
|
|
extern int police_print_xstats(struct action_util *a,FILE *f,
|
|
struct rtattr *tb);
|
|
extern int tc_print_action(FILE *f, const struct rtattr *tb);
|
|
extern int tc_print_ipt(FILE *f, const struct rtattr *tb);
|
|
extern int parse_action(int *, char ***, int, struct nlmsghdr *);
|
|
extern void print_tm(FILE *f, const struct tcf_t *tm);
|
|
extern int prio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt);
|
|
|
|
extern int cls_names_init(char *path);
|
|
extern void cls_names_uninit(void);
|
|
|
|
#endif
|