aboutsummaryrefslogtreecommitdiff
path: root/lib/netlink-socket.c
AgeCommit message (Collapse)Author
2013-09-27Remove unused variables and functions.Jarno Rajahalme
Found by Clang. Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
2013-09-06datapath: Cleanup netlink compat code.Pravin B Shelar
Patch removes genl, netlink, rtnl compat code and dpif-linux fallback-id compat code. Signed-off-by: Pravin B Shelar <pshelar@nicira.com> Acked-by: Jesse Gross <jesse@nicira.com>
2013-08-20Use "error-checking" mutexes in place of other kinds wherever possible.Ben Pfaff
We've seen a number of deadlocks in the tree since thread safety was introduced. So far, all of these are self-deadlocks, that is, a single thread acquiring a lock and then attempting to re-acquire the same lock recursively. When this has happened, the process simply hung, and it was somewhat difficult to find the cause. POSIX "error-checking" mutexes check for this specific problem (and others). This commit switches from other types of mutexes to error-checking mutexes everywhere that we can, that is, everywhere that we're not using recursive mutexes. This ought to help find problems more quickly in the future. There might be performance advantages to other kinds of mutexes in some cases. However, the existing mutex type choices were just guesses, so I'd rather go for easy detection of errors until we know that other mutex types actually perform better in specific cases. Also, I did a quick microbenchmark of glibc mutex types on my host and found that the error checking mutexes weren't any slower than the other types, at least when the mutex is uncontended. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
2013-07-30clang: Add annotations for thread safety check.Ethan Jackson
This commit adds annotations for thread safety check. And the check can be conducted by using -Wthread-safety flag in clang. Co-authored-by: Alex Wang <alexw@nicira.com> Signed-off-by: Alex Wang <alexw@nicira.com> Signed-off-by: Ethan Jackson <ethan@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-07-18netlink-socket: Make thread-safe.Ben Pfaff
The uses of vlog in this module are not thread-safe, because vlog itself is not yet thread-safe. Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-07-18netlink-socket: Simplify use of transactions and dumps.Ben Pfaff
This disentangles "struct nl_dump" from "struct nl_sock", clearing the way to make the use of either one thread-safe in an obviously correct manner. Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-07-15stress: Remove essentially unused library.Ben Pfaff
The "stress" library was introduced years ago. We intended at the time to start using it to provoke errors in testing, to make sure that Open vSwitch was resilient against those errors. The intention was good, but there were few actual implementations of stress options, and the testing never materialized. Rather than adapt the stress library for thread safety, this seems like a good opportunity to remove it, so this commit does so. Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-06-28Replace all uses of strerror() by ovs_strerror(), for thread safety.Ben Pfaff
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-04-29netlink-socket: Use xmalloc() instead of malloc().Ben Pfaff
This was the only obvious use of bare malloc() in the tree, other than in the implementation of wrapper functions. Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-04-29netlink-socket: Minor style fix.Ben Pfaff
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-04-11netlink-socket: Don't bother logging SO_RCVBUFFORCE failureAnsis Atteka
This patch fixes tests when they are run with "fakeroot debian/rules binary" command. The problem was that under fakeroot setsockopt() call could still return EPERM and lead to a warning message being logged. Signed-off-by: Ansis Atteka <aatteka@nicira.com>
2013-02-01netlink-socket: Don't bother logging SO_RCVBUFFORCE failure as non-root.Ben Pfaff
Some Open vSwitch utilities can do useful work when they are not run as root. Without this commit, these utilities will log a warning on failure to use the SO_RCVBUFFORCE socket option if they open any Netlink sockets. This will always happen, it does not report anything unexpected or fixable as non-root, and sometimes it makes users wonder if something is wrong, so there is no benefit to logging it. This commit drops it in that case. Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-01-16Replace most uses of assert by ovs_assert.Ben Pfaff
This is a straight search-and-replace, except that I also removed #include <assert.h> from each file where there were no assert calls left. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
2012-08-03util: New macro CONST_CAST.Ben Pfaff
Casts are sometimes necessary. One common reason that they are necessary is for discarding a "const" qualifier. However, this can impede maintenance: if the type of the expression being cast changes, then the presence of the cast can hide a necessary change in the code that does the cast. Using CONST_CAST, instead of a bare cast, makes these changes visible. Inspired by my own work elsewhere: http://git.savannah.gnu.org/cgit/pspp.git/tree/src/libpspp/cast.h#n80 Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-07-05ovs-brcompatd: Fix sending replies to kernel requests.Ben Pfaff
Commit 7d7447 (netlink: Postpone choosing sequence numbers until send time.) broke ovs-brcompatd because it prevented userspace replies to kernel requests from using the correct sequence numbers. This commit fixes it. Atzm Watanabe found the root cause and provided an alternative patch to avoid the problem. Reported-by: André Ruß <andre.russ@hybris.com> Reported-by: Atzm Watanabe <atzm@stratosphere.co.jp> Tested-by: Atzm Watanabe <atzm@stratosphere.co.jp> Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-05-02Global replace of Nicira Networks.Raju Subramanian
Replaced all instances of Nicira Networks(, Inc) to Nicira, Inc. Feature #10593 Signed-off-by: Raju Subramanian <rsubramanian@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-04-18netlink-socket: Make caller provide message receive buffers.Ben Pfaff
Typically an nl_sock client can stack-allocate the buffer for receiving a Netlink message, which provides a performance boost. Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-04-18netlink: Postpone choosing sequence numbers until send time.Ben Pfaff
Choosing sequence numbers at time of creating a packet means that nl_sock_transact_multiple() has to search for the sequence number of a reply, because the sequence numbers of the requests aren't necessarily sequential. This commit makes it possible to avoid the search, by deferring choice of sequence numbers until the time that we send the packets. It doesn't actually modify nl_sock_transact_multiple(), which will happen in a later commit. Previously, I was concerned about a theoretical race condition described in a comment in the old versino of this code: This implementation uses sequence numbers that are unique process-wide, to avoid a hypothetical race: send request, close socket, open new socket that reuses the old socket's PID value, send request on new socket, receive reply from kernel to old socket but with same PID and sequence number. (This race could be avoided other ways, e.g. by preventing PIDs from being quickly reused). However, I no longer believe that this can be a real problem, because Netlink operates synchronously. The reply to a request will always arrive before the socket can be closed and a new socket opened with the old socket's PID. Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-04-18netlink-socket: Avoid forcing a reply for final message in a transaction.Ben Pfaff
Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-03-15netlink-socket: Increase Netlink socket receive buffer size.Ben Pfaff
Open vSwitch userspace can set up flows at a high rate, but it is somewhat "bursty" in opportunities to set up flows, by which I mean that OVS sets up a batch of flows, then goes off and does some other work for a while, then sets up another batch of flows, and so on. The result is that, if a large number of packets that need flow setups come in all at once, then some of them can overflow the relatively small kernel-to-user buffers. This commit increases the kernel-to-user buffers from the default of approximately 120 kB each to 1 MB each. In one somewhat synthetic test case that I ran based on an "hping3" that generated a load of about 20,000 new flows per second (including both requests and replies), this reduced the packets dropped at the kernel-to-user interface from about 30% to none. I expect that it will similarly improve packet loss in workloads where flow arrival is not easily predictable. (This has little effect on workloads generated by "ovs-benchmark rate" because that benchmark is effectively "self-clocking", that is, a new flow is triggered only by a reply to a request made earlier, which means that the number of buffered packets at any given has a known, constant upper limit.) Bug #10210. Signed-off-by: Ben Pfaff <blp@nicira.com>
2011-11-28netlink-socket: Let the kernel choose Netlink pids for us.Ben Pfaff
The Netlink code in the Linux kernel has been willing to choose unique Netlink pids for userspace sockets since at least 2.4.36 and probably earlier. There's no value in choosing them ourselves. This simplifies the code and eliminates the possibility of exhausting our supply of Netlink PIDs.
2011-11-28dpif-linux: Use poll() internally in dpif_linux_recv().Ben Pfaff
Using poll() internally in dpif_linux_recv(), instead of relying on the results of the main loop poll() call, brings netperf CRR performance back within 1% of par versus the code base before the poll_fd_woke() optimizations were introduced. It also increases the ovs-benchmark results by about 5% versus that baseline, too. My theory is that this is because the main loop takes long enough that a significant number of packets can arrive during the main loop itself, so this reduces the time before OVS gets to those packets.
2011-11-28Revert "poll-loop: Enable checking whether a FD caused a wakeup."Ben Pfaff
This reverts commit 1e276d1a10539a8cd97d2ad63c073a9a43f0f1ef. The poll_fd_woke() and nl_sock_woke() function added in that commit are no longer used, so there is no reason to keep them in the tree.
2011-10-14netlink-socket: New function nl_sock_transact_multiple().Ben Pfaff
This will be used in an upcoming commit.
2011-10-11netlink: New macros NL_NESTED_FOR_EACH, NL_NESTED_FOR_EACH_UNSAFE.Ben Pfaff
Upcoming commits will introduce more users.
2011-09-23poll-loop: Enable checking whether a FD caused a wakeup.Jesse Gross
Each time we run through the poll loop, we check all file descriptors that we were waiting on to see if there is data available. However, this requires a system call and poll already provides information on which FDs caused the wakeup so it is inefficient as the number of active FDs grows. This provides a way to check whether a given FD has data.
2011-09-23netlink: Expose method to get Netlink pid of a socket.Jesse Gross
In the future, the kernel will use unicast messages instead of multicast to send upcalls. As a result, we need to be able to tell it where to direct the traffic. This adds a function to expose the Netlink pid of a socket so it can be included in messages to the kernel.
2011-09-22netlink-socket: Async notifications are incompatible with other operations.Ben Pfaff
A Netlink socket that receives asynchronous notifications (e.g. from a multicast group) cannot be used for transactions or dumps, because those operations would discard asynchronous messages that arrive while waiting for replies. This commit documents this issue in a comment on nl_sock_join_mcgroup(). It also removes an internal attempt to avoid mixing multicast reception with other operations. The attempt was incomplete, because it only handled dumps even though ordinary transactions are also problematic. It seems better to remove it than to fix it because, first, all of the existing users in OVS already separate multicast reception from other operations and, second, an upcoming commit will start using unicast Netlink for asynchronous notifications, which has the same issues but doesn't use nl_sock_join_mcgroup().
2011-09-21netlink-socket: Fix typo in comment.Ben Pfaff
2011-09-16dpif-linux: Handle nl_lookup_genl_mcgroup() failures.Ethan Jackson
The nl_lookup_genl_mcgroup() function can fail on older kernels which do not support the required netlink interface. Before this patch, dpif-linux would refuse to create a datapath when this happened. With this patch, it attempts to use a workaround. If the workaround fails it simply disables the affected features without completely disabling the dpif.
2011-09-09netlink-socket: Avoid use-after-free in nl_lookup_genl_mcgroup().Ben Pfaff
Commit e408762f "netlink-socket: New function nl_lookup_genl_mcgroup()" modified do_lookup_genl_family() to return the Netlink attributes to the caller, but it still freed the Netlink message itself, which meant that the attributes pointed into freed memory. This commit fixes the problem. This commit is not a minimal fix. It refactors do_lookup_genl_family(), changing the return value from "negative errno value or positive genl family id" to the more common "zero or positive errno value". Found by valgrind.
2011-09-01netlink-socket: New function nl_lookup_genl_mcgroup().Ethan Jackson
2011-07-27netlink-socket: Reduce nl_sock_recv() from 2 (or more) system calls to 1.Ben Pfaff
Until now, each attempt to receive a message from a Netlink socket has taken at least two system calls, one to check the size of the message to be received and a second one to delete the message from the socket buffer. This commit switches to a new strategy that requires only one system call per message received. In my testing this increases the maximum flow setups per second by a little over 10%.
2011-07-27netlink-socket: Remove unused nl_sock_sendv() function.Ben Pfaff
This function hasn't been used for ages.
2011-01-27netlink-socket: Log Generic Netlink family names.Ben Pfaff
The ids for Generic Netlink family names aren't very helpful because they can vary from machine to machine and even from one boot to the next. So this change logs their names too. This only affects logging at DBG level. Reviewed by Ethan Jackson <ethan@nicira.com>.
2011-01-27netlink-socket: Consistently log sequence numbers in hexadecimal.Ben Pfaff
nlmsghdr_to_string() wrote sequence numbers in hex, but nl_sock_transact() wrote them in decimal. This consistently switches to hexadecimal. Reviewed by Ethan Jackson <ethan@nicira.com>.
2011-01-27netlink-socket: Make dumping and doing transactions on same nl_sock safe.Ben Pfaff
It's not safe to use a single Netlink fd to do multiple operations in an synchronous way. Some of the limitations are fundamental; for example, the kernel only supports a single "dump" operation at a time. Others are limitations imposed by the OVS coding style; for example, our Netlink library is not callback based, so nothing can be done about incoming messages that can't be handled immediately. Regardless, in OVS multicast groups, transactions, and dumps cannot coexist on a single nl_sock. This is only mildly irritating at the moment, but it will become much worse later on, when dpif-linux shifts to using Netlink dumps for listing various kinds of datapath entities. When that happens, a dump will be in progress in situations where the dpif-linux client might want to do other operations. For example, it is reasonable for the client to list flows and, in the middle, look up information on vports mentioned in those flows. It might be possible to simply ban and avoid such nested operations--I have not even audited the source tree to find out whether we do anything like that already--but that seems like an unnecessary cramp on our coding style. Furthermore, it's difficult to explain and justify without understanding the implementation. This patch takes another approach, by improving the Netlink socket library to avoid artificial constraints. When an operation, or a dump, or joining a multicast group would cause a problem, this patch makes the library transparently create a separate Netlink socket. This solves the problem without putting any onerous restrictions on use. This commit also slightly simplifies netdev_vport_reset_names(). It had been written to destroy the dump object before the Netlink socket that it used, but this is no longer necessary and doing it in the opposite order saved a few lines of code. Reviewed by Ethan Jackson <ethan@nicira.com>.
2011-01-27netlink-socket: Slightly improve logging of Generic Netlink messages.Ben Pfaff
This makes the stream of requests and replies very slightly easier to understand. Reviewed by Justin Pettit.
2011-01-27netlink-socket: New function for draining the receive buffer.Ben Pfaff
This will be used in an upcoming patch. Reviewed by Justin Pettit.
2011-01-27netlink-socket: Add functions for joining and leaving multicast groups.Ben Pfaff
When this library was originally implemented, support for Linux 2.4 was important. The Netlink implementation in Linux only added support for joining and leaving multicast groups after a socket is bound as of Linux 2.6.14, so the library did not support it either. But the current version of Open vSwitch targets Linux 2.6.18 and over, so it's fine to add this support now, and this commit does so. This will be used more extensively in upcoming commits. Reviewed by Justin Pettit.
2010-12-10netlink: Split into generic and Linux-specific parts.Ben Pfaff
The parts of the netlink module that are related to sockets are Linux-specific, since only Linux has AF_NETLINK sockets. The rest can be built anywhere. This commit breaks them into two modules, and builds the generic one on all platforms. Acked-by: Jesse Gross <jesse@nicira.com>