Commit e624b193 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

More tweaks to netlink debugging code.

parent b31d4850
...@@ -145,8 +145,6 @@ netlink_socket(struct netlink *nl, uint32_t groups) ...@@ -145,8 +145,6 @@ netlink_socket(struct netlink *nl, uint32_t groups)
static int static int
netlink_read(int (*filter)(struct nlmsghdr *, void *data), void *data) netlink_read(int (*filter)(struct nlmsghdr *, void *data), void *data)
{ {
int err;
struct sockaddr_nl nladdr; struct sockaddr_nl nladdr;
struct msghdr msg; struct msghdr msg;
struct iovec iov; struct iovec iov;
...@@ -198,7 +196,7 @@ netlink_read(int (*filter)(struct nlmsghdr *, void *data), void *data) ...@@ -198,7 +196,7 @@ netlink_read(int (*filter)(struct nlmsghdr *, void *data), void *data)
for(nh = (struct nlmsghdr *)buf; for(nh = (struct nlmsghdr *)buf;
NLMSG_OK(nh, len); NLMSG_OK(nh, len);
nh = NLMSG_NEXT(nh, len)) { nh = NLMSG_NEXT(nh, len)) {
debugf("nh %d %s", i, debugf("%d %s", i,
(nh->nlmsg_flags & NLM_F_MULTI) ? "(multi) " : ""); (nh->nlmsg_flags & NLM_F_MULTI) ? "(multi) " : "");
i++; i++;
if(nh->nlmsg_pid != nl_command.sockaddr.nl_pid || if(nh->nlmsg_pid != nl_command.sockaddr.nl_pid ||
...@@ -206,8 +204,8 @@ netlink_read(int (*filter)(struct nlmsghdr *, void *data), void *data) ...@@ -206,8 +204,8 @@ netlink_read(int (*filter)(struct nlmsghdr *, void *data), void *data)
debugf("(wrong seqno/pid), "); debugf("(wrong seqno/pid), ");
continue; continue;
} else if(nh->nlmsg_type == NLMSG_DONE) { } else if(nh->nlmsg_type == NLMSG_DONE) {
debugf("done\n"); debugf("(done)\n");
return 0; goto done;
} else if(nh->nlmsg_type == NLMSG_ERROR) { } else if(nh->nlmsg_type == NLMSG_ERROR) {
struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(nh); struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(nh);
if(err->error == 0) { if(err->error == 0) {
...@@ -236,6 +234,7 @@ netlink_read(int (*filter)(struct nlmsghdr *, void *data), void *data) ...@@ -236,6 +234,7 @@ netlink_read(int (*filter)(struct nlmsghdr *, void *data), void *data)
} }
} }
done:
return 0; return 0;
} }
...@@ -340,7 +339,7 @@ netlink_listen(int (*monitor)(struct nlmsghdr *nh, void *data), void *data) { ...@@ -340,7 +339,7 @@ netlink_listen(int (*monitor)(struct nlmsghdr *nh, void *data), void *data) {
struct sockaddr_nl nladdr; struct sockaddr_nl nladdr;
struct iovec iov; struct iovec iov;
struct nlmsghdr *nh; struct nlmsghdr *nh;
int len, i; int len;
int interesting = 0; int interesting = 0;
static char buf[8192]; static char buf[8192];
...@@ -362,46 +361,36 @@ netlink_listen(int (*monitor)(struct nlmsghdr *nh, void *data), void *data) { ...@@ -362,46 +361,36 @@ netlink_listen(int (*monitor)(struct nlmsghdr *nh, void *data), void *data) {
iov.iov_base = buf; iov.iov_base = buf;
iov.iov_len = sizeof(buf); iov.iov_len = sizeof(buf);
// TODO non block ??
len = recvmsg(nl_listen.sock, &msg, 0); len = recvmsg(nl_listen.sock, &msg, 0);
debugf("netlink_listen: recvmsg\n");
if(len < 0) { if(len < 0) {
if(errno == EINTR) if(errno == EINTR)
return 0; return 0;
perror("OVERRUN"); perror("recvmsg(netlink)");
return -1; return -1;
} }
if(len == 0) { if(len == 0) {
fprintf(stderr, "netlink_listen: EOF on netlink\n"); fprintf(stderr, "recvmsg(netlink): EOF\n");
return -1; return -1;
} }
if(msg.msg_namelen != nl_listen.socklen) { if(msg.msg_namelen != nl_listen.socklen) {
fprintf(stderr, "netlink_listen: sender address length == %d\n", fprintf(stderr,
"netlink_listen: unexpected sender address length (%d)\n",
msg.msg_namelen); msg.msg_namelen);
return -1; return -1;
} }
for(nh = (struct nlmsghdr *)buf, i = 1; NLMSG_OK(nh, len); for(nh = (struct nlmsghdr *)buf;
nh = NLMSG_NEXT(nh, len), i++) { NLMSG_OK(nh, len);
nh = NLMSG_NEXT(nh, len)) {
debugf("netlink_listen: nh: %d (multi : %s) : ", i,
(nh->nlmsg_flags & NLM_F_MULTI) ? "yes" : "no");
if(nh->nlmsg_type == NLMSG_DONE) { if(nh->nlmsg_type == NLMSG_DONE) {
debugf("netlink_listen: DONE\n");
continue; continue;
} } else if(nh->nlmsg_type == NLMSG_ERROR) {
if(nh->nlmsg_type == NLMSG_ERROR) {
debugf("netlink_listen: ERROR\n");
continue; continue;
} }
/* Ignore les messages venant de babel */
if(nh->nlmsg_pid == nl_command.sockaddr.nl_pid) if(nh->nlmsg_pid == nl_command.sockaddr.nl_pid)
continue; continue;
...@@ -410,10 +399,10 @@ netlink_listen(int (*monitor)(struct nlmsghdr *nh, void *data), void *data) { ...@@ -410,10 +399,10 @@ netlink_listen(int (*monitor)(struct nlmsghdr *nh, void *data), void *data) {
if(err < 0) return err; if(err < 0) return err;
interesting = interesting || err; interesting = interesting || err;
} }
} }
if(msg.msg_flags & MSG_TRUNC) { if(msg.msg_flags & MSG_TRUNC) {
fprintf(stderr, "netlink_listen: Message truncated\n"); fprintf(stderr, "Netlink message truncated\n");
} }
return interesting; return interesting;
} }
......
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