Lines Matching refs:xp
1880 static void copy_templates(struct xfrm_policy *xp, struct xfrm_user_tmpl *ut, in copy_templates() argument
1885 xp->xfrm_nr = nr; in copy_templates()
1887 struct xfrm_tmpl *t = &xp->xfrm_vec[i]; in copy_templates()
2014 static void copy_from_user_policy(struct xfrm_policy *xp, struct xfrm_userpolicy_info *p) in copy_from_user_policy() argument
2016 xp->priority = p->priority; in copy_from_user_policy()
2017 xp->index = p->index; in copy_from_user_policy()
2018 memcpy(&xp->selector, &p->sel, sizeof(xp->selector)); in copy_from_user_policy()
2019 memcpy(&xp->lft, &p->lft, sizeof(xp->lft)); in copy_from_user_policy()
2020 xp->action = p->action; in copy_from_user_policy()
2021 xp->flags = p->flags; in copy_from_user_policy()
2022 xp->family = p->sel.family; in copy_from_user_policy()
2026 static void copy_to_user_policy(struct xfrm_policy *xp, struct xfrm_userpolicy_info *p, int dir) in copy_to_user_policy() argument
2029 memcpy(&p->sel, &xp->selector, sizeof(p->sel)); in copy_to_user_policy()
2030 memcpy(&p->lft, &xp->lft, sizeof(p->lft)); in copy_to_user_policy()
2031 memcpy(&p->curlft, &xp->curlft, sizeof(p->curlft)); in copy_to_user_policy()
2032 p->priority = xp->priority; in copy_to_user_policy()
2033 p->index = xp->index; in copy_to_user_policy()
2034 p->sel.family = xp->family; in copy_to_user_policy()
2036 p->action = xp->action; in copy_to_user_policy()
2037 p->flags = xp->flags; in copy_to_user_policy()
2047 struct xfrm_policy *xp = xfrm_policy_alloc(net, GFP_KERNEL); in xfrm_policy_construct() local
2050 if (!xp) { in xfrm_policy_construct()
2055 copy_from_user_policy(xp, p); in xfrm_policy_construct()
2057 err = copy_from_user_policy_type(&xp->type, attrs, extack); in xfrm_policy_construct()
2061 if (!(err = copy_from_user_tmpl(xp, attrs, p->dir, extack))) in xfrm_policy_construct()
2062 err = copy_from_user_sec_ctx(xp, attrs); in xfrm_policy_construct()
2066 xfrm_mark_get(attrs, &xp->mark); in xfrm_policy_construct()
2069 xp->if_id = nla_get_u32(attrs[XFRMA_IF_ID]); in xfrm_policy_construct()
2073 err = xfrm_dev_policy_add(net, xp, in xfrm_policy_construct()
2080 return xp; in xfrm_policy_construct()
2083 xp->walk.dead = 1; in xfrm_policy_construct()
2084 xfrm_policy_destroy(xp); in xfrm_policy_construct()
2094 struct xfrm_policy *xp; in xfrm_add_policy() local
2106 xp = xfrm_policy_construct(net, p, attrs, &err, extack); in xfrm_add_policy()
2107 if (!xp) in xfrm_add_policy()
2115 err = xfrm_policy_insert(p->dir, xp, excl); in xfrm_add_policy()
2116 xfrm_audit_policy_add(xp, err ? 0 : 1, true); in xfrm_add_policy()
2119 xfrm_dev_policy_delete(xp); in xfrm_add_policy()
2120 xfrm_dev_policy_free(xp); in xfrm_add_policy()
2121 security_xfrm_policy_free(xp->security); in xfrm_add_policy()
2122 kfree(xp); in xfrm_add_policy()
2129 km_policy_notify(xp, p->dir, &c); in xfrm_add_policy()
2131 xfrm_pol_put(xp); in xfrm_add_policy()
2136 static int copy_to_user_tmpl(struct xfrm_policy *xp, struct sk_buff *skb) in copy_to_user_tmpl() argument
2141 if (xp->xfrm_nr == 0) in copy_to_user_tmpl()
2144 if (xp->xfrm_nr > XFRM_MAX_DEPTH) in copy_to_user_tmpl()
2147 for (i = 0; i < xp->xfrm_nr; i++) { in copy_to_user_tmpl()
2149 struct xfrm_tmpl *kp = &xp->xfrm_vec[i]; in copy_to_user_tmpl()
2165 sizeof(struct xfrm_user_tmpl) * xp->xfrm_nr, vec); in copy_to_user_tmpl()
2176 static inline int copy_to_user_sec_ctx(struct xfrm_policy *xp, struct sk_buff *skb) in copy_to_user_sec_ctx() argument
2178 if (xp->security) in copy_to_user_sec_ctx()
2179 return copy_sec_ctx(xp->security, skb); in copy_to_user_sec_ctx()
2210 static int dump_one_policy(struct xfrm_policy *xp, int dir, int count, void *ptr) in dump_one_policy() argument
2226 copy_to_user_policy(xp, p, dir); in dump_one_policy()
2227 err = copy_to_user_tmpl(xp, skb); in dump_one_policy()
2229 err = copy_to_user_sec_ctx(xp, skb); in dump_one_policy()
2231 err = copy_to_user_policy_type(xp->type, skb); in dump_one_policy()
2233 err = xfrm_mark_put(skb, &xp->mark); in dump_one_policy()
2235 err = xfrm_if_id_put(skb, xp->if_id); in dump_one_policy()
2236 if (!err && xp->xdo.dev) in dump_one_policy()
2237 err = copy_user_offload(&xp->xdo, skb); in dump_one_policy()
2294 struct xfrm_policy *xp, in xfrm_policy_netlink() argument
2310 err = dump_one_policy(xp, dir, 0, &info); in xfrm_policy_netlink()
2413 struct xfrm_policy *xp; in xfrm_get_policy() local
2439 xp = xfrm_policy_byid(net, &m, if_id, type, p->dir, in xfrm_get_policy()
2457 xp = xfrm_policy_bysel_ctx(net, &m, if_id, type, p->dir, in xfrm_get_policy()
2461 if (xp == NULL) in xfrm_get_policy()
2467 resp_skb = xfrm_policy_netlink(skb, xp, p->dir, nlh->nlmsg_seq); in xfrm_get_policy()
2475 xfrm_audit_policy_delete(xp, err ? 0 : 1, true); in xfrm_get_policy()
2484 km_policy_notify(xp, p->dir, &c); in xfrm_get_policy()
2488 xfrm_pol_put(xp); in xfrm_get_policy()
2735 struct xfrm_policy *xp; in xfrm_add_pol_expire() local
2757 xp = xfrm_policy_byid(net, &m, if_id, type, p->dir, p->index, in xfrm_add_pol_expire()
2775 xp = xfrm_policy_bysel_ctx(net, &m, if_id, type, p->dir, in xfrm_add_pol_expire()
2779 if (xp == NULL) in xfrm_add_pol_expire()
2782 if (unlikely(xp->walk.dead)) in xfrm_add_pol_expire()
2787 xfrm_policy_delete(xp, p->dir); in xfrm_add_pol_expire()
2788 xfrm_audit_policy_delete(xp, 1, true); in xfrm_add_pol_expire()
2790 km_policy_expired(xp, p->dir, up->hard, nlh->nlmsg_pid); in xfrm_add_pol_expire()
2793 xfrm_pol_put(xp); in xfrm_add_pol_expire()
2840 struct xfrm_policy *xp; in xfrm_add_acquire() local
2863 xp = xfrm_policy_construct(net, &ua->policy, attrs, &err, extack); in xfrm_add_acquire()
2864 if (!xp) in xfrm_add_acquire()
2870 xp->mark.m = x->mark.m = mark.m; in xfrm_add_acquire()
2871 xp->mark.v = x->mark.v = mark.v; in xfrm_add_acquire()
2874 for (i = 0; i < xp->xfrm_nr; i++, ut++) { in xfrm_add_acquire()
2875 struct xfrm_tmpl *t = &xp->xfrm_vec[i]; in xfrm_add_acquire()
2883 err = km_query(x, t, xp); in xfrm_add_acquire()
2888 kfree(xp); in xfrm_add_acquire()
3584 struct xfrm_policy *xp) in xfrm_acquire_msgsize() argument
3587 + nla_total_size(sizeof(struct xfrm_user_tmpl) * xp->xfrm_nr) in xfrm_acquire_msgsize()
3594 struct xfrm_tmpl *xt, struct xfrm_policy *xp) in build_acquire() argument
3609 copy_to_user_policy(xp, &ua->policy, XFRM_POLICY_OUT); in build_acquire()
3615 err = copy_to_user_tmpl(xp, skb); in build_acquire()
3619 err = copy_to_user_policy_type(xp->type, skb); in build_acquire()
3621 err = xfrm_mark_put(skb, &xp->mark); in build_acquire()
3623 err = xfrm_if_id_put(skb, xp->if_id); in build_acquire()
3624 if (!err && xp->xdo.dev) in build_acquire()
3625 err = copy_user_offload(&xp->xdo, skb); in build_acquire()
3636 struct xfrm_policy *xp) in xfrm_send_acquire() argument
3642 skb = nlmsg_new(xfrm_acquire_msgsize(x, xp), GFP_ATOMIC); in xfrm_send_acquire()
3646 err = build_acquire(skb, x, xt, xp); in xfrm_send_acquire()
3661 struct xfrm_policy *xp; in xfrm_compile_policy() local
3697 xp = xfrm_policy_alloc(net, GFP_ATOMIC); in xfrm_compile_policy()
3698 if (xp == NULL) { in xfrm_compile_policy()
3703 copy_from_user_policy(xp, p); in xfrm_compile_policy()
3704 xp->type = XFRM_POLICY_TYPE_MAIN; in xfrm_compile_policy()
3705 copy_templates(xp, ut, nr); in xfrm_compile_policy()
3709 return xp; in xfrm_compile_policy()
3712 static inline unsigned int xfrm_polexpire_msgsize(struct xfrm_policy *xp) in xfrm_polexpire_msgsize() argument
3715 + nla_total_size(sizeof(struct xfrm_user_tmpl) * xp->xfrm_nr) in xfrm_polexpire_msgsize()
3716 + nla_total_size(xfrm_user_sec_ctx_size(xp->security)) in xfrm_polexpire_msgsize()
3721 static int build_polexpire(struct sk_buff *skb, struct xfrm_policy *xp, in build_polexpire() argument
3734 copy_to_user_policy(xp, &upe->pol, dir); in build_polexpire()
3735 err = copy_to_user_tmpl(xp, skb); in build_polexpire()
3737 err = copy_to_user_sec_ctx(xp, skb); in build_polexpire()
3739 err = copy_to_user_policy_type(xp->type, skb); in build_polexpire()
3741 err = xfrm_mark_put(skb, &xp->mark); in build_polexpire()
3743 err = xfrm_if_id_put(skb, xp->if_id); in build_polexpire()
3744 if (!err && xp->xdo.dev) in build_polexpire()
3745 err = copy_user_offload(&xp->xdo, skb); in build_polexpire()
3756 static int xfrm_exp_policy_notify(struct xfrm_policy *xp, int dir, const struct km_event *c) in xfrm_exp_policy_notify() argument
3758 struct net *net = xp_net(xp); in xfrm_exp_policy_notify()
3762 skb = nlmsg_new(xfrm_polexpire_msgsize(xp), GFP_ATOMIC); in xfrm_exp_policy_notify()
3766 err = build_polexpire(skb, xp, dir, c); in xfrm_exp_policy_notify()
3772 static int xfrm_notify_policy(struct xfrm_policy *xp, int dir, const struct km_event *c) in xfrm_notify_policy() argument
3774 unsigned int len = nla_total_size(sizeof(struct xfrm_user_tmpl) * xp->xfrm_nr); in xfrm_notify_policy()
3775 struct net *net = xp_net(xp); in xfrm_notify_policy()
3809 id->index = xp->index; in xfrm_notify_policy()
3811 memcpy(&id->sel, &xp->selector, sizeof(id->sel)); in xfrm_notify_policy()
3821 copy_to_user_policy(xp, p, dir); in xfrm_notify_policy()
3822 err = copy_to_user_tmpl(xp, skb); in xfrm_notify_policy()
3824 err = copy_to_user_policy_type(xp->type, skb); in xfrm_notify_policy()
3826 err = xfrm_mark_put(skb, &xp->mark); in xfrm_notify_policy()
3828 err = xfrm_if_id_put(skb, xp->if_id); in xfrm_notify_policy()
3829 if (!err && xp->xdo.dev) in xfrm_notify_policy()
3830 err = copy_user_offload(&xp->xdo, skb); in xfrm_notify_policy()
3871 static int xfrm_send_policy_notify(struct xfrm_policy *xp, int dir, const struct km_event *c) in xfrm_send_policy_notify() argument
3878 return xfrm_notify_policy(xp, dir, c); in xfrm_send_policy_notify()
3882 return xfrm_exp_policy_notify(xp, dir, c); in xfrm_send_policy_notify()