On Tue, Jun 24, 2003 at 07:54:45PM -0700, David S. Miller wrote: > > Herbert, please make this requested enhancement to your > acquire->sel patch, and I will apply it. Here you go. -- Debian GNU/Linux 3.0 is out! ( http://www.debian.org/ ) Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Index: kernel-source-2.5/include/linux/xfrm.h =================================================================== RCS file: /home/gondolin/herbert/src/CVS/debian/kernel-source-2.5/include/linux/xfrm.h,v retrieving revision 1.1.1.6 diff -u -r1.1.1.6 xfrm.h --- kernel-source-2.5/include/linux/xfrm.h 17 Jun 2003 04:19:42 -0000 1.1.1.6 +++ kernel-source-2.5/include/linux/xfrm.h 24 Jun 2003 08:55:39 -0000 @@ -201,6 +203,7 @@ struct xfrm_user_acquire { struct xfrm_id id; xfrm_address_t saddr; + struct xfrm_selector sel; struct xfrm_userpolicy_info policy; __u32 aalgos; __u32 ealgos; Index: kernel-source-2.5/net/xfrm/xfrm_user.c =================================================================== RCS file: /home/gondolin/herbert/src/CVS/debian/kernel-source-2.5/net/xfrm/xfrm_user.c,v retrieving revision 1.5 diff -u -r1.5 xfrm_user.c --- kernel-source-2.5/net/xfrm/xfrm_user.c 20 Jun 2003 11:49:08 -0000 1.5 +++ kernel-source-2.5/net/xfrm/xfrm_user.c 25 Jun 2003 09:18:19 -0000 @@ -563,7 +560,7 @@ } } -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 xfrm_user_tmpl *utmpl; @@ -619,7 +616,7 @@ } copy_from_user_policy(xp, p); - err = copy_user_tmpl(xp, xfrma); + err = copy_from_user_tmpl(xp, xfrma); if (err) { *errp = err; kfree(xp); @@ -656,6 +653,38 @@ return 0; } +static int copy_to_user_tmpl(struct xfrm_policy *xp, struct sk_buff *skb) +{ + struct xfrm_user_tmpl vec[XFRM_MAX_DEPTH]; + int i; + + if (xp->xfrm_nr == 0) + return 0; + + for (i = 0; i < xp->xfrm_nr; i++) { + struct xfrm_user_tmpl *up = &vec[i]; + struct xfrm_tmpl *kp = &xp->xfrm_vec[i]; + + memcpy(&up->id, &kp->id, sizeof(up->id)); + memcpy(&up->saddr, &kp->saddr, sizeof(up->saddr)); + up->reqid = kp->reqid; + up->mode = kp->mode; + up->share = kp->share; + up->optional = kp->optional; + up->aalgos = kp->aalgos; + up->ealgos = kp->ealgos; + up->calgos = kp->calgos; + } + RTA_PUT(skb, XFRMA_TMPL, + (sizeof(struct xfrm_user_tmpl) * xp->xfrm_nr), + 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; @@ -675,29 +704,8 @@ nlh->nlmsg_flags = 0; copy_to_user_policy(xp, p, dir); - - if (xp->xfrm_nr) { - struct xfrm_user_tmpl vec[XFRM_MAX_DEPTH]; - int i; - - for (i = 0; i < xp->xfrm_nr; i++) { - struct xfrm_user_tmpl *up = &vec[i]; - struct xfrm_tmpl *kp = &xp->xfrm_vec[i]; - - memcpy(&up->id, &kp->id, sizeof(up->id)); - memcpy(&up->saddr, &kp->saddr, sizeof(up->saddr)); - up->reqid = kp->reqid; - up->mode = kp->mode; - up->share = kp->share; - up->optional = kp->optional; - up->aalgos = kp->aalgos; - up->ealgos = kp->ealgos; - up->calgos = kp->calgos; - } - RTA_PUT(skb, XFRMA_TMPL, - (sizeof(struct xfrm_user_tmpl) * xp->xfrm_nr), - vec); - } + if (copy_to_user_tmpl(xp, skb) < 0) + goto nlmsg_failure; nlh->nlmsg_len = skb->tail - b; out: @@ -705,7 +713,6 @@ return 0; nlmsg_failure: -rtattr_failure: skb_trim(skb, b - skb->data); return -1; } @@ -1012,12 +1021,16 @@ memcpy(&ua->id, &x->id, sizeof(ua->id)); 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); ua->aalgos = xt->aalgos; ua->ealgos = xt->ealgos; ua->calgos = xt->calgos; ua->seq = x->km.seq = seq; + if (copy_to_user_tmpl(xp, skb) < 0) + goto nlmsg_failure; + nlh->nlmsg_len = skb->tail - b; return skb->len; @@ -1031,7 +1044,7 @@ { struct sk_buff *skb; - skb = alloc_skb(sizeof(struct xfrm_user_acquire) + 16, GFP_ATOMIC); + skb = alloc_skb(NLMSG_GOODSIZE, GFP_ATOMIC); if (skb == NULL) return -ENOMEM;