libnetlink: break up dump function
Indentation is deep here. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
This commit is contained in:
parent
1949f82cdf
commit
892a25e286
|
|
@ -261,6 +261,48 @@ int rtnl_dump_request_n(struct rtnl_handle *rth, struct nlmsghdr *n)
|
||||||
return sendmsg(rth->fd, &msg, 0);
|
return sendmsg(rth->fd, &msg, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int rtnl_dump_done(const struct rtnl_handle *rth,
|
||||||
|
struct nlmsghdr *h)
|
||||||
|
{
|
||||||
|
int len = *(int *)NLMSG_DATA(h);
|
||||||
|
|
||||||
|
if (rth->proto == NETLINK_SOCK_DIAG) {
|
||||||
|
if (h->nlmsg_len < NLMSG_LENGTH(sizeof(int))) {
|
||||||
|
fprintf(stderr, "DONE truncated\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (len < 0) {
|
||||||
|
errno = -len;
|
||||||
|
if (errno == ENOENT || errno == EOPNOTSUPP)
|
||||||
|
return -1;
|
||||||
|
perror("RTNETLINK answers");
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void rtnl_dump_error(const struct rtnl_handle *rth,
|
||||||
|
struct nlmsghdr *h)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) {
|
||||||
|
fprintf(stderr, "ERROR truncated\n");
|
||||||
|
} else {
|
||||||
|
const struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(h);
|
||||||
|
|
||||||
|
errno = -err->error;
|
||||||
|
if (rth->proto == NETLINK_SOCK_DIAG &&
|
||||||
|
(errno == ENOENT ||
|
||||||
|
errno == EOPNOTSUPP))
|
||||||
|
return;
|
||||||
|
|
||||||
|
perror("RTNETLINK answers");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int rtnl_dump_filter_l(struct rtnl_handle *rth,
|
int rtnl_dump_filter_l(struct rtnl_handle *rth,
|
||||||
const struct rtnl_dump_filter_arg *arg)
|
const struct rtnl_dump_filter_arg *arg)
|
||||||
{
|
{
|
||||||
|
|
@ -320,40 +362,16 @@ int rtnl_dump_filter_l(struct rtnl_handle *rth,
|
||||||
dump_intr = 1;
|
dump_intr = 1;
|
||||||
|
|
||||||
if (h->nlmsg_type == NLMSG_DONE) {
|
if (h->nlmsg_type == NLMSG_DONE) {
|
||||||
if (rth->proto == NETLINK_SOCK_DIAG) {
|
err = rtnl_dump_done(rth, h);
|
||||||
if (h->nlmsg_len < NLMSG_LENGTH(sizeof(int))) {
|
if (err < 0)
|
||||||
fprintf(stderr, "DONE truncated\n");
|
return -1;
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
int len = *(int *)NLMSG_DATA(h);
|
|
||||||
if (len < 0) {
|
|
||||||
errno = -len;
|
|
||||||
if (errno == ENOENT ||
|
|
||||||
errno == EOPNOTSUPP)
|
|
||||||
return -1;
|
|
||||||
perror("RTNETLINK answers");
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
found_done = 1;
|
found_done = 1;
|
||||||
break; /* process next filter */
|
break; /* process next filter */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (h->nlmsg_type == NLMSG_ERROR) {
|
if (h->nlmsg_type == NLMSG_ERROR) {
|
||||||
struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(h);
|
rtnl_dump_error(rth, h);
|
||||||
|
|
||||||
if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) {
|
|
||||||
fprintf(stderr,
|
|
||||||
"ERROR truncated\n");
|
|
||||||
} else {
|
|
||||||
errno = -err->error;
|
|
||||||
if (rth->proto == NETLINK_SOCK_DIAG &&
|
|
||||||
(errno == ENOENT ||
|
|
||||||
errno == EOPNOTSUPP))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
perror("RTNETLINK answers");
|
|
||||||
}
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue