Commit 79b8b7f4 authored by Thomas Graf's avatar Thomas Graf Committed by David S. Miller

[XFRM] netlink: Use nlmsg_put() instead of NLMSG_PUT()

Signed-off-by: default avatarThomas Graf <tgraf@suug.ch>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6168b96c
...@@ -588,10 +588,10 @@ static int dump_one_state(struct xfrm_state *x, int count, void *ptr) ...@@ -588,10 +588,10 @@ static int dump_one_state(struct xfrm_state *x, int count, void *ptr)
if (sp->this_idx < sp->start_idx) if (sp->this_idx < sp->start_idx)
goto out; goto out;
nlh = NLMSG_PUT(skb, NETLINK_CB(in_skb).pid, nlh = nlmsg_put(skb, NETLINK_CB(in_skb).pid, sp->nlmsg_seq,
sp->nlmsg_seq, XFRM_MSG_NEWSA, sizeof(*p), sp->nlmsg_flags);
XFRM_MSG_NEWSA, sizeof(*p)); if (nlh == NULL)
nlh->nlmsg_flags = sp->nlmsg_flags; return -EMSGSIZE;
p = NLMSG_DATA(nlh); p = NLMSG_DATA(nlh);
copy_to_user_state(x, p); copy_to_user_state(x, p);
...@@ -633,7 +633,6 @@ static int dump_one_state(struct xfrm_state *x, int count, void *ptr) ...@@ -633,7 +633,6 @@ static int dump_one_state(struct xfrm_state *x, int count, void *ptr)
sp->this_idx++; sp->this_idx++;
return 0; return 0;
nlmsg_failure:
rtattr_failure: rtattr_failure:
nlmsg_trim(skb, b); nlmsg_trim(skb, b);
return -1; return -1;
...@@ -1276,11 +1275,11 @@ static int dump_one_policy(struct xfrm_policy *xp, int dir, int count, void *ptr ...@@ -1276,11 +1275,11 @@ static int dump_one_policy(struct xfrm_policy *xp, int dir, int count, void *ptr
if (sp->this_idx < sp->start_idx) if (sp->this_idx < sp->start_idx)
goto out; goto out;
nlh = NLMSG_PUT(skb, NETLINK_CB(in_skb).pid, nlh = nlmsg_put(skb, NETLINK_CB(in_skb).pid, sp->nlmsg_seq,
sp->nlmsg_seq, XFRM_MSG_NEWPOLICY, sizeof(*p), sp->nlmsg_flags);
XFRM_MSG_NEWPOLICY, sizeof(*p)); if (nlh == NULL)
return -EMSGSIZE;
p = NLMSG_DATA(nlh); p = NLMSG_DATA(nlh);
nlh->nlmsg_flags = sp->nlmsg_flags;
copy_to_user_policy(xp, p, dir); copy_to_user_policy(xp, p, dir);
if (copy_to_user_tmpl(xp, skb) < 0) if (copy_to_user_tmpl(xp, skb) < 0)
...@@ -1449,9 +1448,10 @@ static int build_aevent(struct sk_buff *skb, struct xfrm_state *x, struct km_eve ...@@ -1449,9 +1448,10 @@ static int build_aevent(struct sk_buff *skb, struct xfrm_state *x, struct km_eve
struct xfrm_lifetime_cur ltime; struct xfrm_lifetime_cur ltime;
unsigned char *b = skb_tail_pointer(skb); unsigned char *b = skb_tail_pointer(skb);
nlh = NLMSG_PUT(skb, c->pid, c->seq, XFRM_MSG_NEWAE, sizeof(*id)); nlh = nlmsg_put(skb, c->pid, c->seq, XFRM_MSG_NEWAE, sizeof(*id), 0);
if (nlh == NULL)
return -EMSGSIZE;
id = NLMSG_DATA(nlh); id = NLMSG_DATA(nlh);
nlh->nlmsg_flags = 0;
memcpy(&id->sa_id.daddr, &x->id.daddr,sizeof(x->id.daddr)); memcpy(&id->sa_id.daddr, &x->id.daddr,sizeof(x->id.daddr));
id->sa_id.spi = x->id.spi; id->sa_id.spi = x->id.spi;
...@@ -1483,7 +1483,6 @@ static int build_aevent(struct sk_buff *skb, struct xfrm_state *x, struct km_eve ...@@ -1483,7 +1483,6 @@ static int build_aevent(struct sk_buff *skb, struct xfrm_state *x, struct km_eve
return skb->len; return skb->len;
rtattr_failure: rtattr_failure:
nlmsg_failure:
nlmsg_trim(skb, b); nlmsg_trim(skb, b);
return -1; return -1;
} }
...@@ -1866,9 +1865,10 @@ static int build_migrate(struct sk_buff *skb, struct xfrm_migrate *m, ...@@ -1866,9 +1865,10 @@ static int build_migrate(struct sk_buff *skb, struct xfrm_migrate *m,
unsigned char *b = skb_tail_pointer(skb); unsigned char *b = skb_tail_pointer(skb);
int i; int i;
nlh = NLMSG_PUT(skb, 0, 0, XFRM_MSG_MIGRATE, sizeof(*pol_id)); nlh = nlmsg_put(skb, 0, 0, XFRM_MSG_MIGRATE, sizeof(*pol_id), 0);
if (nlh == NULL)
return -EMSGSIZE;
pol_id = NLMSG_DATA(nlh); pol_id = NLMSG_DATA(nlh);
nlh->nlmsg_flags = 0;
/* copy data from selector, dir, and type to the pol_id */ /* copy data from selector, dir, and type to the pol_id */
memset(pol_id, 0, sizeof(*pol_id)); memset(pol_id, 0, sizeof(*pol_id));
...@@ -2045,20 +2045,16 @@ static int build_expire(struct sk_buff *skb, struct xfrm_state *x, struct km_eve ...@@ -2045,20 +2045,16 @@ static int build_expire(struct sk_buff *skb, struct xfrm_state *x, struct km_eve
struct nlmsghdr *nlh; struct nlmsghdr *nlh;
unsigned char *b = skb_tail_pointer(skb); unsigned char *b = skb_tail_pointer(skb);
nlh = NLMSG_PUT(skb, c->pid, 0, XFRM_MSG_EXPIRE, nlh = nlmsg_put(skb, c->pid, 0, XFRM_MSG_EXPIRE, sizeof(*ue), 0);
sizeof(*ue)); if (nlh == NULL)
return -EMSGSIZE;
ue = NLMSG_DATA(nlh); ue = NLMSG_DATA(nlh);
nlh->nlmsg_flags = 0;
copy_to_user_state(x, &ue->state); copy_to_user_state(x, &ue->state);
ue->hard = (c->data.hard != 0) ? 1 : 0; ue->hard = (c->data.hard != 0) ? 1 : 0;
nlh->nlmsg_len = skb_tail_pointer(skb) - b; nlh->nlmsg_len = skb_tail_pointer(skb) - b;
return skb->len; return skb->len;
nlmsg_failure:
nlmsg_trim(skb, b);
return -1;
} }
static int xfrm_exp_state_notify(struct xfrm_state *x, struct km_event *c) static int xfrm_exp_state_notify(struct xfrm_state *x, struct km_event *c)
...@@ -2108,9 +2104,11 @@ static int xfrm_notify_sa_flush(struct km_event *c) ...@@ -2108,9 +2104,11 @@ static int xfrm_notify_sa_flush(struct km_event *c)
return -ENOMEM; return -ENOMEM;
b = skb->tail; b = skb->tail;
nlh = NLMSG_PUT(skb, c->pid, c->seq, nlh = nlmsg_put(skb, c->pid, c->seq, XFRM_MSG_FLUSHSA, sizeof(*p), 0);
XFRM_MSG_FLUSHSA, sizeof(*p)); if (nlh == NULL) {
nlh->nlmsg_flags = 0; kfree_skb(skb);
return -EMSGSIZE;
}
p = NLMSG_DATA(nlh); p = NLMSG_DATA(nlh);
p->proto = c->data.proto; p->proto = c->data.proto;
...@@ -2119,10 +2117,6 @@ static int xfrm_notify_sa_flush(struct km_event *c) ...@@ -2119,10 +2117,6 @@ static int xfrm_notify_sa_flush(struct km_event *c)
NETLINK_CB(skb).dst_group = XFRMNLGRP_SA; NETLINK_CB(skb).dst_group = XFRMNLGRP_SA;
return netlink_broadcast(xfrm_nl, skb, 0, XFRMNLGRP_SA, GFP_ATOMIC); return netlink_broadcast(xfrm_nl, skb, 0, XFRMNLGRP_SA, GFP_ATOMIC);
nlmsg_failure:
kfree_skb(skb);
return -1;
} }
static inline int xfrm_sa_len(struct xfrm_state *x) static inline int xfrm_sa_len(struct xfrm_state *x)
...@@ -2162,8 +2156,9 @@ static int xfrm_notify_sa(struct xfrm_state *x, struct km_event *c) ...@@ -2162,8 +2156,9 @@ static int xfrm_notify_sa(struct xfrm_state *x, struct km_event *c)
return -ENOMEM; return -ENOMEM;
b = skb->tail; b = skb->tail;
nlh = NLMSG_PUT(skb, c->pid, c->seq, c->event, headlen); nlh = nlmsg_put(skb, c->pid, c->seq, c->event, headlen, 0);
nlh->nlmsg_flags = 0; if (nlh == NULL)
goto nlmsg_failure;
p = NLMSG_DATA(nlh); p = NLMSG_DATA(nlh);
if (c->event == XFRM_MSG_DELSA) { if (c->event == XFRM_MSG_DELSA) {
...@@ -2233,10 +2228,10 @@ static int build_acquire(struct sk_buff *skb, struct xfrm_state *x, ...@@ -2233,10 +2228,10 @@ static int build_acquire(struct sk_buff *skb, struct xfrm_state *x,
unsigned char *b = skb_tail_pointer(skb); unsigned char *b = skb_tail_pointer(skb);
__u32 seq = xfrm_get_acqseq(); __u32 seq = xfrm_get_acqseq();
nlh = NLMSG_PUT(skb, 0, 0, XFRM_MSG_ACQUIRE, nlh = nlmsg_put(skb, 0, 0, XFRM_MSG_ACQUIRE, sizeof(*ua), 0);
sizeof(*ua)); if (nlh == NULL)
return -EMSGSIZE;
ua = NLMSG_DATA(nlh); ua = NLMSG_DATA(nlh);
nlh->nlmsg_flags = 0;
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));
...@@ -2352,9 +2347,10 @@ static int build_polexpire(struct sk_buff *skb, struct xfrm_policy *xp, ...@@ -2352,9 +2347,10 @@ static int build_polexpire(struct sk_buff *skb, struct xfrm_policy *xp,
int hard = c->data.hard; int hard = c->data.hard;
unsigned char *b = skb_tail_pointer(skb); unsigned char *b = skb_tail_pointer(skb);
nlh = NLMSG_PUT(skb, c->pid, 0, XFRM_MSG_POLEXPIRE, sizeof(*upe)); nlh = nlmsg_put(skb, c->pid, 0, XFRM_MSG_POLEXPIRE, sizeof(*upe), 0);
if (nlh == NULL)
return -EMSGSIZE;
upe = NLMSG_DATA(nlh); upe = NLMSG_DATA(nlh);
nlh->nlmsg_flags = 0;
copy_to_user_policy(xp, &upe->pol, dir); copy_to_user_policy(xp, &upe->pol, dir);
if (copy_to_user_tmpl(xp, skb) < 0) if (copy_to_user_tmpl(xp, skb) < 0)
...@@ -2420,7 +2416,9 @@ static int xfrm_notify_policy(struct xfrm_policy *xp, int dir, struct km_event * ...@@ -2420,7 +2416,9 @@ static int xfrm_notify_policy(struct xfrm_policy *xp, int dir, struct km_event *
return -ENOMEM; return -ENOMEM;
b = skb->tail; b = skb->tail;
nlh = NLMSG_PUT(skb, c->pid, c->seq, c->event, headlen); nlh = nlmsg_put(skb, c->pid, c->seq, c->event, headlen, 0);
if (nlh == NULL)
goto nlmsg_failure;
p = NLMSG_DATA(nlh); p = NLMSG_DATA(nlh);
if (c->event == XFRM_MSG_DELPOLICY) { if (c->event == XFRM_MSG_DELPOLICY) {
...@@ -2435,8 +2433,6 @@ static int xfrm_notify_policy(struct xfrm_policy *xp, int dir, struct km_event * ...@@ -2435,8 +2433,6 @@ static int xfrm_notify_policy(struct xfrm_policy *xp, int dir, struct km_event *
p = RTA_DATA(__RTA_PUT(skb, XFRMA_POLICY, sizeof(*p))); p = RTA_DATA(__RTA_PUT(skb, XFRMA_POLICY, sizeof(*p)));
} }
nlh->nlmsg_flags = 0;
copy_to_user_policy(xp, p, dir); copy_to_user_policy(xp, p, dir);
if (copy_to_user_tmpl(xp, skb) < 0) if (copy_to_user_tmpl(xp, skb) < 0)
goto nlmsg_failure; goto nlmsg_failure;
...@@ -2471,8 +2467,9 @@ static int xfrm_notify_policy_flush(struct km_event *c) ...@@ -2471,8 +2467,9 @@ static int xfrm_notify_policy_flush(struct km_event *c)
b = skb->tail; b = skb->tail;
nlh = NLMSG_PUT(skb, c->pid, c->seq, XFRM_MSG_FLUSHPOLICY, 0); nlh = nlmsg_put(skb, c->pid, c->seq, XFRM_MSG_FLUSHPOLICY, 0, 0);
nlh->nlmsg_flags = 0; if (nlh == NULL)
goto nlmsg_failure;
if (copy_to_user_policy_type(c->data.type, skb) < 0) if (copy_to_user_policy_type(c->data.type, skb) < 0)
goto nlmsg_failure; goto nlmsg_failure;
...@@ -2513,9 +2510,10 @@ static int build_report(struct sk_buff *skb, u8 proto, ...@@ -2513,9 +2510,10 @@ static int build_report(struct sk_buff *skb, u8 proto,
struct nlmsghdr *nlh; struct nlmsghdr *nlh;
unsigned char *b = skb_tail_pointer(skb); unsigned char *b = skb_tail_pointer(skb);
nlh = NLMSG_PUT(skb, 0, 0, XFRM_MSG_REPORT, sizeof(*ur)); nlh = nlmsg_put(skb, 0, 0, XFRM_MSG_REPORT, sizeof(*ur), 0);
if (nlh == NULL)
return -EMSGSIZE;
ur = NLMSG_DATA(nlh); ur = NLMSG_DATA(nlh);
nlh->nlmsg_flags = 0;
ur->proto = proto; ur->proto = proto;
memcpy(&ur->sel, sel, sizeof(ur->sel)); memcpy(&ur->sel, sel, sizeof(ur->sel));
...@@ -2526,7 +2524,6 @@ static int build_report(struct sk_buff *skb, u8 proto, ...@@ -2526,7 +2524,6 @@ static int build_report(struct sk_buff *skb, u8 proto,
nlh->nlmsg_len = skb_tail_pointer(skb) - b; nlh->nlmsg_len = skb_tail_pointer(skb) - b;
return skb->len; return skb->len;
nlmsg_failure:
rtattr_failure: rtattr_failure:
nlmsg_trim(skb, b); nlmsg_trim(skb, b);
return -1; return -1;
......
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