From f31a37f79d1f33d4d0d6a18f3768bfee27e8b6cc Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Thu, 31 Jan 2008 21:38:58 -0800 Subject: [PATCH] fix problem caused by rtnl_send checks Some usages of rtnl_send could cause errors (ie flush requests) others do a listen afterwards. Signed-off-by: Stephen Hemminger --- include/libnetlink.h | 2 +- ip/ipaddress.c | 2 +- ip/ipneigh.c | 2 +- ip/iproute.c | 2 +- ip/xfrm_policy.c | 2 +- ip/xfrm_state.c | 2 +- lib/libnetlink.c | 19 +++++++------------ 7 files changed, 13 insertions(+), 18 deletions(-) diff --git a/include/libnetlink.h b/include/libnetlink.h index b67c5a5ea..0e0246829 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -34,7 +34,7 @@ extern int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer, rtnl_filter_t junk, void *jarg); extern int rtnl_send(struct rtnl_handle *rth, const char *buf, int); - +extern int rtnl_send_check(struct rtnl_handle *rth, const char *buf, int); extern int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32 data); extern int addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data, int alen); diff --git a/ip/ipaddress.c b/ip/ipaddress.c index 6dc61eba9..0a34ace21 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -316,7 +316,7 @@ int print_linkinfo(const struct sockaddr_nl *who, static int flush_update(void) { - if (rtnl_send(&rth, filter.flushb, filter.flushp) < 0) { + if (rtnl_send_check(&rth, filter.flushb, filter.flushp) < 0) { perror("Failed to send flush request"); return -1; } diff --git a/ip/ipneigh.c b/ip/ipneigh.c index b40de5b43..03a176056 100644 --- a/ip/ipneigh.c +++ b/ip/ipneigh.c @@ -87,7 +87,7 @@ int nud_state_a2n(unsigned *state, char *arg) static int flush_update(void) { - if (rtnl_send(&rth, filter.flushb, filter.flushp) < 0) { + if (rtnl_send_check(&rth, filter.flushb, filter.flushp) < 0) { perror("Failed to send flush request"); return -1; } diff --git a/ip/iproute.c b/ip/iproute.c index 685cb85fe..2a8f3f839 100644 --- a/ip/iproute.c +++ b/ip/iproute.c @@ -112,7 +112,7 @@ static struct static int flush_update(void) { - if (rtnl_send(&rth, filter.flushb, filter.flushp) < 0) { + if (rtnl_send_check(&rth, filter.flushb, filter.flushp) < 0) { perror("Failed to send flush request"); return -1; } diff --git a/ip/xfrm_policy.c b/ip/xfrm_policy.c index b5e5c3fee..11116e5fe 100644 --- a/ip/xfrm_policy.c +++ b/ip/xfrm_policy.c @@ -783,7 +783,7 @@ static int xfrm_policy_list_or_deleteall(int argc, char **argv, int deleteall) break; } - if (rtnl_send(&rth, xb.buf, xb.offset) < 0) { + if (rtnl_send_check(&rth, xb.buf, xb.offset) < 0) { perror("Failed to send delete-all request"); exit(1); } diff --git a/ip/xfrm_state.c b/ip/xfrm_state.c index f51e8b660..0e2120336 100644 --- a/ip/xfrm_state.c +++ b/ip/xfrm_state.c @@ -906,7 +906,7 @@ static int xfrm_state_list_or_deleteall(int argc, char **argv, int deleteall) break; } - if (rtnl_send(&rth, xb.buf, xb.offset) < 0) { + if (rtnl_send_check(&rth, xb.buf, xb.offset) < 0) { perror("Failed to send delete-all request\n"); exit(1); } diff --git a/lib/libnetlink.c b/lib/libnetlink.c index a4e91cf7c..5ae64f7ea 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -94,10 +94,6 @@ int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type) struct nlmsghdr nlh; struct rtgenmsg g; } req; - struct sockaddr_nl nladdr; - - memset(&nladdr, 0, sizeof(nladdr)); - nladdr.nl_family = AF_NETLINK; memset(&req, 0, sizeof(req)); req.nlh.nlmsg_len = sizeof(req); @@ -107,22 +103,21 @@ int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type) req.nlh.nlmsg_seq = rth->dump = ++rth->seq; req.g.rtgen_family = family; - return sendto(rth->fd, (void*)&req, sizeof(req), 0, - (struct sockaddr*)&nladdr, sizeof(nladdr)); + return send(rth->fd, (void*)&req, sizeof(req), 0); } int rtnl_send(struct rtnl_handle *rth, const char *buf, int len) { - struct sockaddr_nl nladdr; + return send(rth->fd, buf, len, 0); +} + +int rtnl_send_check(struct rtnl_handle *rth, const char *buf, int len) +{ struct nlmsghdr *h; int status; char resp[1024]; - memset(&nladdr, 0, sizeof(nladdr)); - nladdr.nl_family = AF_NETLINK; - - status = sendto(rth->fd, buf, len, 0, - (struct sockaddr*)&nladdr, sizeof(nladdr)); + status = send(rth->fd, buf, len, 0); if (status < 0) return status; -- 2.47.2