Commit 7c4d1c43 authored by Herbert Xu's avatar Herbert Xu Committed by Hideaki Yoshifuji

[XFRM] Set port/proto in acquire messages.

Also append policy spec to acquire message.
parent 31e6d03a
...@@ -203,6 +203,7 @@ struct xfrm_userpolicy_id { ...@@ -203,6 +203,7 @@ struct xfrm_userpolicy_id {
struct xfrm_user_acquire { struct xfrm_user_acquire {
struct xfrm_id id; struct xfrm_id id;
xfrm_address_t saddr; xfrm_address_t saddr;
struct xfrm_selector sel;
struct xfrm_userpolicy_info policy; struct xfrm_userpolicy_info policy;
__u32 aalgos; __u32 aalgos;
__u32 ealgos; __u32 ealgos;
......
...@@ -560,7 +560,7 @@ static void copy_templates(struct xfrm_policy *xp, struct xfrm_user_tmpl *ut, ...@@ -560,7 +560,7 @@ static void copy_templates(struct xfrm_policy *xp, struct xfrm_user_tmpl *ut,
} }
} }
static int copy_user_tmpl(struct xfrm_policy *pol, struct rtattr **xfrma) static int copy_from_user_tmpl(struct xfrm_policy *pol, struct rtattr **xfrma)
{ {
struct rtattr *rt = xfrma[XFRMA_TMPL-1]; struct rtattr *rt = xfrma[XFRMA_TMPL-1];
struct xfrm_user_tmpl *utmpl; struct xfrm_user_tmpl *utmpl;
...@@ -616,7 +616,7 @@ static struct xfrm_policy *xfrm_policy_construct(struct xfrm_userpolicy_info *p, ...@@ -616,7 +616,7 @@ static struct xfrm_policy *xfrm_policy_construct(struct xfrm_userpolicy_info *p,
} }
copy_from_user_policy(xp, p); copy_from_user_policy(xp, p);
err = copy_user_tmpl(xp, xfrma); err = copy_from_user_tmpl(xp, xfrma);
if (err) { if (err) {
*errp = err; *errp = err;
kfree(xp); kfree(xp);
...@@ -653,30 +653,14 @@ static int xfrm_add_policy(struct sk_buff *skb, struct nlmsghdr *nlh, void **xfr ...@@ -653,30 +653,14 @@ static int xfrm_add_policy(struct sk_buff *skb, struct nlmsghdr *nlh, void **xfr
return 0; return 0;
} }
static int dump_one_policy(struct xfrm_policy *xp, int dir, int count, void *ptr) static int copy_to_user_tmpl(struct xfrm_policy *xp, struct sk_buff *skb)
{ {
struct xfrm_dump_info *sp = ptr;
struct xfrm_userpolicy_info *p;
struct sk_buff *in_skb = sp->in_skb;
struct sk_buff *skb = sp->out_skb;
struct nlmsghdr *nlh;
unsigned char *b = skb->tail;
if (sp->this_idx < sp->start_idx)
goto out;
nlh = NLMSG_PUT(skb, NETLINK_CB(in_skb).pid,
sp->nlmsg_seq,
XFRM_MSG_NEWPOLICY, sizeof(*p));
p = NLMSG_DATA(nlh);
nlh->nlmsg_flags = 0;
copy_to_user_policy(xp, p, dir);
if (xp->xfrm_nr) {
struct xfrm_user_tmpl vec[XFRM_MAX_DEPTH]; struct xfrm_user_tmpl vec[XFRM_MAX_DEPTH];
int i; int i;
if (xp->xfrm_nr == 0)
return 0;
for (i = 0; i < xp->xfrm_nr; i++) { for (i = 0; i < xp->xfrm_nr; i++) {
struct xfrm_user_tmpl *up = &vec[i]; struct xfrm_user_tmpl *up = &vec[i];
struct xfrm_tmpl *kp = &xp->xfrm_vec[i]; struct xfrm_tmpl *kp = &xp->xfrm_vec[i];
...@@ -694,7 +678,34 @@ static int dump_one_policy(struct xfrm_policy *xp, int dir, int count, void *ptr ...@@ -694,7 +678,34 @@ static int dump_one_policy(struct xfrm_policy *xp, int dir, int count, void *ptr
RTA_PUT(skb, XFRMA_TMPL, RTA_PUT(skb, XFRMA_TMPL,
(sizeof(struct xfrm_user_tmpl) * xp->xfrm_nr), (sizeof(struct xfrm_user_tmpl) * xp->xfrm_nr),
vec); vec);
}
return 0;
rtattr_failure:
return -1;
}
static int dump_one_policy(struct xfrm_policy *xp, int dir, int count, void *ptr)
{
struct xfrm_dump_info *sp = ptr;
struct xfrm_userpolicy_info *p;
struct sk_buff *in_skb = sp->in_skb;
struct sk_buff *skb = sp->out_skb;
struct nlmsghdr *nlh;
unsigned char *b = skb->tail;
if (sp->this_idx < sp->start_idx)
goto out;
nlh = NLMSG_PUT(skb, NETLINK_CB(in_skb).pid,
sp->nlmsg_seq,
XFRM_MSG_NEWPOLICY, sizeof(*p));
p = NLMSG_DATA(nlh);
nlh->nlmsg_flags = 0;
copy_to_user_policy(xp, p, dir);
if (copy_to_user_tmpl(xp, skb) < 0)
goto nlmsg_failure;
nlh->nlmsg_len = skb->tail - b; nlh->nlmsg_len = skb->tail - b;
out: out:
...@@ -702,7 +713,6 @@ static int dump_one_policy(struct xfrm_policy *xp, int dir, int count, void *ptr ...@@ -702,7 +713,6 @@ static int dump_one_policy(struct xfrm_policy *xp, int dir, int count, void *ptr
return 0; return 0;
nlmsg_failure: nlmsg_failure:
rtattr_failure:
skb_trim(skb, b - skb->data); skb_trim(skb, b - skb->data);
return -1; return -1;
} }
...@@ -1011,12 +1021,16 @@ static int build_acquire(struct sk_buff *skb, struct xfrm_state *x, ...@@ -1011,12 +1021,16 @@ static int build_acquire(struct sk_buff *skb, struct xfrm_state *x,
memcpy(&ua->id, &x->id, sizeof(ua->id)); memcpy(&ua->id, &x->id, sizeof(ua->id));
memcpy(&ua->saddr, &x->props.saddr, sizeof(ua->saddr)); memcpy(&ua->saddr, &x->props.saddr, sizeof(ua->saddr));
memcpy(&ua->sel, &x->sel, sizeof(ua->sel));
copy_to_user_policy(xp, &ua->policy, dir); copy_to_user_policy(xp, &ua->policy, dir);
ua->aalgos = xt->aalgos; ua->aalgos = xt->aalgos;
ua->ealgos = xt->ealgos; ua->ealgos = xt->ealgos;
ua->calgos = xt->calgos; ua->calgos = xt->calgos;
ua->seq = x->km.seq = seq; ua->seq = x->km.seq = seq;
if (copy_to_user_tmpl(xp, skb) < 0)
goto nlmsg_failure;
nlh->nlmsg_len = skb->tail - b; nlh->nlmsg_len = skb->tail - b;
return skb->len; return skb->len;
...@@ -1029,8 +1043,12 @@ static int xfrm_send_acquire(struct xfrm_state *x, struct xfrm_tmpl *xt, ...@@ -1029,8 +1043,12 @@ static int xfrm_send_acquire(struct xfrm_state *x, struct xfrm_tmpl *xt,
struct xfrm_policy *xp, int dir) struct xfrm_policy *xp, int dir)
{ {
struct sk_buff *skb; struct sk_buff *skb;
size_t len;
skb = alloc_skb(sizeof(struct xfrm_user_acquire) + 16, GFP_ATOMIC); len = RTA_LENGTH(sizeof(struct xfrm_user_tmpl) * xp->xfrm_nr);
len = RTA_ALIGN(len);
len += NLMSG_ALIGN(NLMSG_LENGTH(sizeof(struct xfrm_user_acquire)));
skb = alloc_skb(len, GFP_ATOMIC);
if (skb == NULL) if (skb == NULL)
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment