static void reuseport_free_rcu(struct rcu_head *head) { struct sock_reuseport *reuse; reuse = container_of(head, struct sock_reuseport, rcu); if (reuse->prog) bpf_prog_destroy(reuse->prog); kfree(reuse); }
static void tcf_bpf_cleanup(struct tc_action *act, int bind) { const struct tcf_bpf *prog = act->priv; if (tcf_bpf_is_ebpf(prog)) bpf_prog_put(prog->filter); else bpf_prog_destroy(prog->filter); }
static void tcf_bpf_cfg_cleanup(const struct tcf_bpf_cfg *cfg) { if (cfg->is_ebpf) bpf_prog_put(cfg->filter); else bpf_prog_destroy(cfg->filter); kfree(cfg->bpf_ops); kfree(cfg->bpf_name); }
static void bpf_mt_destroy_v1(const struct xt_mtdtor_param *par) { const struct xt_bpf_info_v1 *info = par->matchinfo; bpf_prog_destroy(info->filter); }
static int tcf_bpf_init(struct net *net, struct nlattr *nla, struct nlattr *est, struct tc_action *act, int replace, int bind) { struct nlattr *tb[TCA_ACT_BPF_MAX + 1]; struct tc_act_bpf *parm; struct tcf_bpf *prog; struct tcf_bpf_cfg cfg; bool is_bpf, is_ebpf; int ret; if (!nla) return -EINVAL; ret = nla_parse_nested(tb, TCA_ACT_BPF_MAX, nla, act_bpf_policy); if (ret < 0) return ret; is_bpf = tb[TCA_ACT_BPF_OPS_LEN] && tb[TCA_ACT_BPF_OPS]; is_ebpf = tb[TCA_ACT_BPF_FD]; if ((!is_bpf && !is_ebpf) || (is_bpf && is_ebpf) || !tb[TCA_ACT_BPF_PARMS]) return -EINVAL; parm = nla_data(tb[TCA_ACT_BPF_PARMS]); memset(&cfg, 0, sizeof(cfg)); ret = is_bpf ? tcf_bpf_init_from_ops(tb, &cfg) : tcf_bpf_init_from_efd(tb, &cfg); if (ret < 0) return ret; if (!tcf_hash_check(parm->index, act, bind)) { ret = tcf_hash_create(parm->index, est, act, sizeof(*prog), bind); if (ret < 0) goto destroy_fp; ret = ACT_P_CREATED; } else { /* Don't override defaults. */ if (bind) goto destroy_fp; tcf_hash_release(act, bind); if (!replace) { ret = -EEXIST; goto destroy_fp; } } prog = to_bpf(act); spin_lock_bh(&prog->tcf_lock); prog->bpf_ops = cfg.bpf_ops; prog->bpf_name = cfg.bpf_name; if (cfg.bpf_num_ops) prog->bpf_num_ops = cfg.bpf_num_ops; if (cfg.bpf_fd) prog->bpf_fd = cfg.bpf_fd; prog->tcf_action = parm->action; prog->filter = cfg.filter; spin_unlock_bh(&prog->tcf_lock); if (ret == ACT_P_CREATED) tcf_hash_insert(act); return ret; destroy_fp: if (is_ebpf) bpf_prog_put(cfg.filter); else bpf_prog_destroy(cfg.filter); kfree(cfg.bpf_ops); kfree(cfg.bpf_name); return ret; }