aboutsummaryrefslogtreecommitdiff
path: root/lib/netdev-linux.c
AgeCommit message (Collapse)Author
2013-09-07netdev: update IFF_LOOPBACK flag for linux and bsd devicesAlexandru Copot
Signed-off-by: Alexandru Copot <alex.mihai.c@gmail.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-08-27netdev: Fix deadlock when netdev_dump_queues() callback calls into netdev.Ben Pfaff
We have a call chain like this: iface_configure_qos() calls netdev_dump_queues(), which calls netdev_linux_dump_queues(), which calls back through 'cb' to qos_unixctl_show_cb(), which calls netdev_delete_queue(), which calls netdev_linux_delete_queue(). Both netdev_dump_queues() and netdev_linux_delete_queue() take the same mutex in the same netdev, which deadlocks. This commit fixes the problem by getting rid of the callback. netdev_linux_dump_queue_stats() would benefit from the same treatment but it's less urgent because I don't see any callbacks from that function that call back into a netdev function. Bug #19319. Reported-by: Scott Hendricks <shendricks@vmware.com> Signed-off-by: Ben Pfaff <blp@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-08-16netdev-linux: Fix self-deadlocks in traffic control code.Ben Pfaff
htb_parse_qdisc_details__(), which is called with the netdev mutex, called netdev_get_mtu(), which tried to reacquire the mutex and thus deadlocked. This commit fixes the problem and similar problems in htb_parse_class_details__() and hfsc_parse_qdisc_details__(). Bug #19180. Reported-by: Dhaval Badiani <dbadiani@vmware.com> Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Andy Zhou <azhou@nicira.com>
2013-08-10netdev-linux: Avoid deadlock in netdev_linux_update_flags() for taps.Ben Pfaff
netdev_linux_set_etheraddr() would attempt to recursively acquire netdev->mutex via netdev_linux_update_flags() for tap devices. Reported-by: ZhengLingyun <konghuarukhr@163.com> Tested-by: ZhengLingyun <konghuarukhr@163.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-08-10netdev-linux: Fix netdev leak in corner case.Ben Pfaff
Reported-by: Alex Wang <alexw@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-08-09netdev: Make netdev access thread-safe.Ben Pfaff
Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Andy Zhou <azhou@nicira.com>
2013-08-09netdev-linux: Use dedicated netlink notification socket.Ben Pfaff
The rtnetlink_link asynchronous netlink notifications seem somewhat troublesome in a threaded environment. It seems more straightforward to have netdev-linux fend for itself. Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-08-09netdev: Adopt four-step alloc/construct/destruct/dealloc lifecycle.Ben Pfaff
This is the same lifecycle used in the ofproto provider interface. Compared to the previous netdev provider interface, it has the advantage that the netdev top layer can control when any given netdev becomes visible to the outside world. Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-08-09netdev-linux, netdev-bsd: Make access to AF_INET socket thread-safe.Ben Pfaff
The only uses of 'af_inet_sock', in both drivers, were ioctls, so it seemed like a good abstraction to write a function that just does such an ioctl, and to factor out shared code into socket-util. Signed-off-by: Ben Pfaff <blp@nicira.com> CC: Ed Maste <emaste@freebsd.org>
2013-08-07netdev: Make netdev_from_name() take a reference to its returned netdev.Ben Pfaff
This API change is necessary for thread safety, to be added in an upcoming commit. Otherwise, the client would not be able to safely use the returned netdev because it could already have been destroyed. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Andy Zhou <azhou@nicira.com>
2013-08-07netdev: Make netdev_get_devices() take a reference to each netdev.Ben Pfaff
This API change is necessary for thread safety, to be added in an upcoming commit. Otherwise, the client would not be able to actually use any of the returned netdevs because they could already have been destroyed. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Andy Zhou <azhou@nicira.com>
2013-08-07netdev-linux: Move variable declaration inward in netdev_linux_cache_cb().Ben Pfaff
Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Andy Zhou <azhou@nicira.com>
2013-08-07netdev-linux: Remove useless member 'peer', which was always zero.Ben Pfaff
Always, correct a comment on netdev_linux_get_features(). Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Andy Zhou <azhou@nicira.com>
2013-08-07netdev-linux: Remove unused struct netdev_linux member.Ben Pfaff
Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Andy Zhou <azhou@nicira.com>
2013-08-07netdev-linux: Remove pointless layers of indirection for tap devices.Ben Pfaff
Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Andy Zhou <azhou@nicira.com>
2013-08-02netdev: Minor formatting improvements.Ben Pfaff
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-08-02netdev-linux: Don't assume 'struct netdev' has offset 0.Ben Pfaff
The data items returned by netdev_get_devices() are "struct netdev *"s. The code fixed up by this commit used them as "struct netdev_linux *", which happens to work because struct netdev happens to be at offset 0 in each struct but it's better to do a proper cast in case someday struct netdev gets moved to a nonzero offset. Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-08-02netdev-linux: Initialize change_seq for tap devices too.Ben Pfaff
change_seq is supposed to always be nonzero but tap devices got this wrong. Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-08-02netdev-linux: Fix fd leak on error path.Ben Pfaff
Found by inspection. Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-07-26Implement OpenFlow 1.3 queue stats duration feature.Ben Pfaff
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-07-23clang: Fix the alignment warning.Alex Wang
This commit fixes the warning issued by 'clang' when pointer is casted to one with greater alignment. Signed-off-by: Alex Wang <alexw@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-07-23netdev-linux: Work on thread safety.Ben Pfaff
Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Andy Zhou <azhou@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-18netdev-linux: avoid negative value cast to non-negative in comparisonZhengLingyun
I am using a userspace OVS, there is a constant ERR message in log: "dpif_netdev|ERR|error receiving data from ovs-netdev: Message too long" Check the code and find there is a comparison between ssize_t and size_t type in netdev_rx_linux_recv(). It makes the negative "retval" greater than the "size". Change the sequence of comparison to avoid negative return value cast to a positive and become greater then a non-negative value. Signed-off-by: ZhengLingyun <konghuarukhr@163.com> 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-06-13lib/netdev-linux.c: Prevent receiving of sent packetsMurphy McCauley
Commit 796223f5 (netdev: Add new "struct netdev_rx" for capturing packets from a netdev) refactored send and receive into separate netdevs. As a result, send and receive now use different socket descriptors (except for tap interfaces which are treated specially). An unintended side effect was that all sent packets are looped back and received, which had previously been avoided as the kernel specifically prevents this from happening on a single socket descriptor. To resolve the situation, a socket filter is added to the receive socket so that it only accepts inbound packets. Simon Horman co-discovered and initially reported this issue. Signed-off-by: Murphy McCauley <murphy.mccauley@gmail.com> Signed-off-by: Ben Pfaff <blp@nicira.com> Tested-by: Simon Horman <horms@verge.net.au> Reviewed-by: Simon Horman <horms@verge.net.au>
2013-05-13netdev-linux: Skip NETDEV_UP test in netdev_linux_set_etheraddr() for taps.Ben Pfaff
netdev_turn_flags_off() does nothing if the flags that one turns off are already off. Reported-by: Ethan Jackson <ethan@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
2013-05-10netdev: Get rid of netdev_dev.Ben Pfaff
The distinction between struct netdev_dev and struct netdev has always been confusing. Now that previous commits have eliminated all interesting state from struct netdev, this commit deletes it and renames struct netdev_dev to take its place. Now the situation makes much more sense and I won't have to continue making embarrassed explanations in the future. Good riddance. Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-05-10Rename superclass members to 'up'.Ben Pfaff
Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
2013-05-10netdev: Add new "struct netdev_rx" for capturing packets from a netdev.Ben Pfaff
Separating packet capture from "struct netdev" means that there is no remaining per-"struct netdev" state, which will allow us to get rid of "struct netdev_dev" (by renaming it "struct netdev"). Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
2013-05-10netdev: Factor restoring flags into new "struct netdev_saved_flags".Ben Pfaff
This gets rid of the only per-instance data in "struct netdev", which will make it possible to merge "struct netdev_dev" into "struct netdev" in a later commit. Ed Maste wrote the netdev-bsd changes in this commit. Signed-off-by: Ben Pfaff <blp@nicira.com> Co-authored-by: Ed Maste <emaste@freebsd.org> Signed-off-by: Ed Maste <emaste@freebsd.org> Tested-by: Ed Maste <emaste@freebsd.org>
2013-05-03netdev-linux: Mark more static data as "const".Ben Pfaff
This makes this code more obviously thread-safe. Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-02-28netdev-linux: Fix netdev_linux_send() return value in corner case.Ben Pfaff
A negative 'sock' means there was an error but netdev_linux_send() returns a positive errno value on error. Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-02-01netdev-linux: Check return value of set_nonblocking().Ben Pfaff
It's unlikely to fail but checking it can't hurt. Found by Coverity. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
2013-01-28netdev-vport: Build on all platforms.Ethan Jackson
This patch removes the final bit of linux specific code which prevents building netdev-vport everywhere. With this, other platforms automatically get access to patch ports, and (if their datapath supports it), flow based tunneling. Signed-off-by: Ethan Jackson <ethan@nicira.com>
2013-01-25linux: Increase accuracy of ingress_policing_rate at low ratesThomas Graf
The current method of calculating the ingress policer rate can lead to inaccuracy if ingress_policing_rate is set to a smallish values because the rate is divided by 8 first which causes rounding errors. Signed-off-by: Thomas Graf <tgraf@redhat.com> 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>
2013-01-15netdev: Parse and make available tunnel configuration.Ethan Jackson
Future patches will need to know the details of a netdev's tunnel configuration from outside the netdev library. Signed-off-by: Ethan Jackson <ethan@nicira.com>
2013-01-03netdev: Rename get_drv_info() to get_status().Ethan Jackson
get_status() is a much more intuitive name since "status" is what the database column is called. Signed-off-by: Ethan Jackson <ethan@nicira.com>
2012-12-26netdev-vport: Remove set_stats() implementation.Ethan Jackson
The only user of netdev_set_stats() is bonding (for updating the fake interface). This interface is never a vport, so it seems quite a bit cleaner to keep the relevant code in the netdev-linux library where it's needed, instead of in netdev-vport, where it adds needless complexity. Signed-off-by: Ethan Jackson <ethan@nicira.com>
2012-12-12packets: Change IP_ARGS interface to take an ovs_be32 instead of a pointer.Ben Pfaff
An ovs_be32 is a more obvious way to represent an IP address than a pointer to one. It is also more type-safe, especially since "sparse" is able to check that the argument is in network byte order. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
2012-12-07netdev-linux: Use underlying tap device on netdev_linux_listen().Justin Pettit
Commit acf608 (ofproto-dpif: Use a single underlying datapath across multiple bridges.) broke connectivity to userspace datapath devices. The code assumed the first caller to open a tap device with netdev_linux_open() wanted to write to it. This commit moves that logic to when netdev_linux_listen() is called. Thanks to Ben Pfaff for helping debug the issue. Signed-off-by: Justin Pettit <jpettit@nicira.com> Reported-by: Simon Horman <horms@verge.net.au> Tested-by: Simon Horman <horms@verge.net.au>
2012-11-16netdev-linux: Don't log vport warnings when kernel datapath not loaded.Justin Pettit
The *_get_stats functions call get_stats_via_vport(), which tries to get information about ports attached to the kernel datapath. When a pure userspace switch is used (eg, the OVS kernel module isn't loaded), ports are not attached to a kernel datapath, so warnings get logged. This commit handles that case and doesn't log a warning. However, if the kernel datapath is loaded, ports attached to a userspace datapath will still log a warning. Signed-off-by: Justin Pettit <jpettit@nicira.com>
2012-11-16netdev-linux: "Down" tap devices before setting hw addr.Justin Pettit
On Linux, it is not possible to set the mac address on "up" tap interfaces. This commit temporarily "down"s the interface so the address can be set for the netdev_linux_set_etheraddr() call. Signed-off-by: Justin Pettit <jpettit@nicira.com>
2012-11-03ofproto: Report 0 Mbps when speed not available instead of 100 Mbps.Ben Pfaff
When a link is down, or when a link has no speed because it is not a physical interface, Open vSwitch previously reported that its rate is 100 Mbps as a default. This is counterintuitive, however, so this commit changes Open vSwitch behavior to report 0 Mbps when a link is down or its speed is otherwise unavailable. Bug #13388. Reported-by: Hiroshi Tanaka <htanaka@nicira.com> Signed-off-by: Ben Pfaff <blp@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-06-21netdev-linux: Break ethtool coverage counter into "get" and "set" versions.Ben Pfaff
Reads and writes have difference performance implications so it's better to separate them. Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-06-14lib: New data structure - smap.Ethan Jackson
A smap is a string to string hash map. It has a cleaner interface than shash's which were traditionally used for the same purpose. This patch implements the data structure, and changes netdev and its providers to use it. Signed-off-by: Ethan Jackson <ethan@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>