Bryan O'Sullivan avatar Bryan O'Sullivan committed dc544a0

Latest round of changes from Steve Grubb.

Comments (0)

Files changed (1)

     skip,	/* skip the message */
     done,	/* all's well, no more processing */
     bail,	/* something's wrong, no more processing */
+    user,	/* packet came from someone naughty in user space */
 } todo;
 
 
 	}
 
 	do_log(LOG_ERR, "Netlink receive error: %m");
-	return skip;
+	return done;
     }
     else if (*status == 0) {
 	do_log(LOG_ERR, "Unexpected EOF on netlink");
     if (msg->msg_namelen != sizeof(struct sockaddr_nl)) {
 	do_log(LOG_ERR, "Unexpected sender address length: got %d, expected %d",
 	       msg->msg_namelen, sizeof(struct sockaddr_nl));
-	return bail;
+	return done;
     }
 
     if (((struct sockaddr_nl *) msg->msg_name)->nl_pid != 0) {
 	do_log(LOG_ERR, "Netlink packet came from pid %d, not from kernel",
 	       ((struct sockaddr_nl *) msg->msg_name)->nl_pid);
-	return skip;
+	return user;
     }
 
     return ok;
 }
 
 
+/*
+ * Return values:
+ *
+ * 0  - exit calling loop
+ * !0 - we have a valid event
+ */
 int
 netlink_listen(int fd, netlink_callback callback, void *arg)
 {
 	int status;
 	
 	switch (receive(fd, &msg, &status)) {
+	case user:
 	case done:
 	    return 1;
 	case bail:
 	case bail:
 	case done:
 	    return;
+	case user:
 	case skip:
 	    continue;
 	case ok:
         struct nlmsghdr *hdr = (struct nlmsghdr *) buf;
 
         while (NLMSG_OK(hdr, status)) {
-            int err;
-
             if (hdr->nlmsg_seq != dump) {
                 do_log(LOG_ERR, "Skipping junk");
                 goto skip_it;
             }
 
             if (callback) {
+		int err;
+
                 if ((err = callback(hdr, arg)) == -1) {
                     do_log(LOG_ERR, "Callback failed");
                     return;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.