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 <stephen.hemminger@vyatta.com>
This commit is contained in:
Stephen Hemminger 2008-01-31 21:38:58 -08:00
parent 42169181b8
commit f31a37f79d
7 changed files with 13 additions and 18 deletions

View File

@ -34,7 +34,7 @@ extern int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
rtnl_filter_t junk, rtnl_filter_t junk,
void *jarg); void *jarg);
extern int rtnl_send(struct rtnl_handle *rth, const char *buf, int); 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 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); extern int addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data, int alen);

View File

@ -316,7 +316,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
static int flush_update(void) 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"); perror("Failed to send flush request");
return -1; return -1;
} }

View File

@ -87,7 +87,7 @@ int nud_state_a2n(unsigned *state, char *arg)
static int flush_update(void) 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"); perror("Failed to send flush request");
return -1; return -1;
} }

View File

@ -112,7 +112,7 @@ static struct
static int flush_update(void) 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"); perror("Failed to send flush request");
return -1; return -1;
} }

View File

@ -783,7 +783,7 @@ static int xfrm_policy_list_or_deleteall(int argc, char **argv, int deleteall)
break; 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"); perror("Failed to send delete-all request");
exit(1); exit(1);
} }

View File

@ -906,7 +906,7 @@ static int xfrm_state_list_or_deleteall(int argc, char **argv, int deleteall)
break; 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"); perror("Failed to send delete-all request\n");
exit(1); exit(1);
} }

View File

@ -94,10 +94,6 @@ int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type)
struct nlmsghdr nlh; struct nlmsghdr nlh;
struct rtgenmsg g; struct rtgenmsg g;
} req; } req;
struct sockaddr_nl nladdr;
memset(&nladdr, 0, sizeof(nladdr));
nladdr.nl_family = AF_NETLINK;
memset(&req, 0, sizeof(req)); memset(&req, 0, sizeof(req));
req.nlh.nlmsg_len = 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.nlh.nlmsg_seq = rth->dump = ++rth->seq;
req.g.rtgen_family = family; req.g.rtgen_family = family;
return sendto(rth->fd, (void*)&req, sizeof(req), 0, return send(rth->fd, (void*)&req, sizeof(req), 0);
(struct sockaddr*)&nladdr, sizeof(nladdr));
} }
int rtnl_send(struct rtnl_handle *rth, const char *buf, int len) 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; struct nlmsghdr *h;
int status; int status;
char resp[1024]; char resp[1024];
memset(&nladdr, 0, sizeof(nladdr)); status = send(rth->fd, buf, len, 0);
nladdr.nl_family = AF_NETLINK;
status = sendto(rth->fd, buf, len, 0,
(struct sockaddr*)&nladdr, sizeof(nladdr));
if (status < 0) if (status < 0)
return status; return status;