dpif-linux: Avoid segfault on netdev_get_stats() without kernel module.
authorBen Pfaff <blp@nicira.com>
Fri, 8 Apr 2011 23:37:22 +0000 (16:37 -0700)
committerBen Pfaff <blp@nicira.com>
Mon, 11 Apr 2011 17:46:32 +0000 (10:46 -0700)
netdev_linux_get_stats() calls into netdev_vport_get_stats(), which in
turn attempts a transaction on genl_sock.  If the kernel module isn't
loaded, then genl_sock won't be there, and in any case there's nothing that
guarantees that it's been initialized yet.

This fixes the problem by ensuring that dpif_linux was initialized properly
before attempting a transaction on genl_sock.

Reported-by: Aaron Rosen <arosen@clemson.edu>
lib/dpif-linux.c

index 10ddd511c41dd45ef86df22c1ffd7082f258d08f..a7823b886a9f1fb00a84cb85ddd077ee3bdbfc56 100644 (file)
@@ -1282,6 +1282,15 @@ dpif_linux_vport_transact(const struct dpif_linux_vport *request,
 
     assert((reply != NULL) == (bufp != NULL));
 
+    error = dpif_linux_init();
+    if (error) {
+        if (reply) {
+            *bufp = NULL;
+            dpif_linux_vport_init(reply);
+        }
+        return error;
+    }
+
     request_buf = ofpbuf_new(1024);
     dpif_linux_vport_to_ofpbuf(request, request_buf);
     error = nl_sock_transact(genl_sock, request_buf, bufp);