bpf: allocate opcode table in struct bpf_cfg_in
struct bpf_cfg_in already carries a pointer to sock_filter ops. It's currently set to a local variable in bpf_parse_opt_tbl(), shared between parsing and loading stages. Move the array entirely to struct bpf_cfg_in, this will allow us to split parsing and loading. Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com> Acked-by: Daniel Borkmann <daniel@iogearbox.net>
This commit is contained in:
parent
f20ff2f195
commit
51be754690
|
|
@ -72,7 +72,7 @@ struct bpf_cfg_in {
|
||||||
enum bpf_mode mode;
|
enum bpf_mode mode;
|
||||||
int argc;
|
int argc;
|
||||||
char **argv;
|
char **argv;
|
||||||
struct sock_filter *ops;
|
struct sock_filter opcodes[BPF_MAXINSNS];
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ALU ops on registers, bpf_add|sub|...: dst_reg += src_reg */
|
/* ALU ops on registers, bpf_add|sub|...: dst_reg += src_reg */
|
||||||
|
|
|
||||||
|
|
@ -894,7 +894,7 @@ static int bpf_parse(struct bpf_cfg_in *cfg, const bool *opt_tbl)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfg->mode == CBPF_BYTECODE || cfg->mode == CBPF_FILE)
|
if (cfg->mode == CBPF_BYTECODE || cfg->mode == CBPF_FILE)
|
||||||
ret = bpf_ops_parse(argc, argv, cfg->ops,
|
ret = bpf_ops_parse(argc, argv, cfg->opcodes,
|
||||||
cfg->mode == CBPF_FILE);
|
cfg->mode == CBPF_FILE);
|
||||||
else if (cfg->mode == EBPF_OBJECT)
|
else if (cfg->mode == EBPF_OBJECT)
|
||||||
ret = bpf_obj_open(file, cfg->type, section, verbose);
|
ret = bpf_obj_open(file, cfg->type, section, verbose);
|
||||||
|
|
@ -916,18 +916,15 @@ static int bpf_parse_opt_tbl(struct bpf_cfg_in *cfg,
|
||||||
const struct bpf_cfg_ops *ops, void *nl,
|
const struct bpf_cfg_ops *ops, void *nl,
|
||||||
const bool *opt_tbl)
|
const bool *opt_tbl)
|
||||||
{
|
{
|
||||||
struct sock_filter opcodes[BPF_MAXINSNS];
|
|
||||||
char annotation[256];
|
char annotation[256];
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
cfg->ops = opcodes;
|
|
||||||
ret = bpf_parse(cfg, opt_tbl);
|
ret = bpf_parse(cfg, opt_tbl);
|
||||||
cfg->ops = NULL;
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if (cfg->mode == CBPF_BYTECODE || cfg->mode == CBPF_FILE)
|
if (cfg->mode == CBPF_BYTECODE || cfg->mode == CBPF_FILE)
|
||||||
ops->cbpf_cb(nl, opcodes, ret);
|
ops->cbpf_cb(nl, cfg->opcodes, ret);
|
||||||
if (cfg->mode == EBPF_OBJECT || cfg->mode == EBPF_PINNED) {
|
if (cfg->mode == EBPF_OBJECT || cfg->mode == EBPF_PINNED) {
|
||||||
snprintf(annotation, sizeof(annotation), "%s:[%s]",
|
snprintf(annotation, sizeof(annotation), "%s:[%s]",
|
||||||
basename(cfg->object), cfg->mode == EBPF_PINNED ?
|
basename(cfg->object), cfg->mode == EBPF_PINNED ?
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue