ofproto-dpif: Fix a vlan-splinter megaflow bug

When vlan-splinter is enabled, ovs receives non-vlan flows from the
kernel vlan ports, vlan tag is then added to the incoming flow before
xlating, so that they look like those received from a trunk port.

In case megaflow is enabled, xlating may set vlan masks during rule
processing as usual. If those vlan masks were serialized and downloaded
to the kernel (this bug), those mega flows will be rejected due to
unexpected vlan mask encapsulation, since the original kernel flows do
not have vlan tags. This bug does not break connectivity, but impacts
performance since all traffic received on vlan splinter ports will now
be handled by vswitchd, as no datapath flows can be successfully
installed.

This fix is to make sure no vlan mask encapsulation is generated for
the datapath flow if its in_port was re-written by vlan-splinter
receiving logic.

Bug #22567

Signed-off-by: Andy Zhou <azhou@nicira.com>
Fix !HAVE_NETLINK build

Fix a regression introduced by commit 4b97b70d
("ofproto-dpif: Enable NXAST_SAMPLE only if the datapath supports it.")

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: Ben Pfaff <blp@nicira.com>
datapath: Use kmem_cache_free() instead of kfree()

memory allocated by kmem_cache_alloc() should be freed using
kmem_cache_free(), not kfree().

Fixes: e298e5057006 ('openvswitch: Per cpu flow stats.')
Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
Signed-off-by: Jesse Gross <jesse@nicira.com>
ofproto-dpif-upcall: Slightly simplify udpif_upcall_handler().

Signed-off-by: Ben Pfaff <blp@nicira.com>
netdev-dummy: Remove unused member 'listening' from struct netdev_dummy.

Signed-off-by: Ben Pfaff <blp@nicira.com>
netdev-dummy: Make netdev_rx_wait() wakeups work cross-thread for dummies.

Until now, netdev_dummy_rx_wait() has only checked whether the receive
queue for the dummy device is currently empty.  This has worked OK because
in practice packets were queued to dummy devices only from the same thread
that attempted to receive them.  An upcoming commit will use different
threads for these purposes, so this commit switches to a notification
method that works cross-thread.

Signed-off-by: Ben Pfaff <blp@nicira.com>
dpif: Remove unused 'get_max_ports' from provider interface.

Nothing ever called this function.

Signed-off-by: Ben Pfaff <blp@nicira.com>
dpif-netdev: Use new "ovsthread_counter" to track dp statistics.

ovsthread_counter is an abstract interface that could be implemented
different ways.  The initial implementation is simple but less than
optimally efficient.

Signed-off-by: Ben Pfaff <blp@nicira.com>
dpif-netdev: Use hmap instead of list+array for tracking ports.

The goal is to make it easy to divide the ports into groups for handling
by threads.  It seems easy enough to do that by hash value, and a little
harder otherwise.

This commit has the side effect of raising the maximum number of ports from
256 to UINT32_MAX-1.  That is why some tests need to be updated:
previously, internally generated port names like "ovs_vxlan_4341" were
ignored because 4341 is bigger than the previous limit of 256.

Signed-off-by: Ben Pfaff <blp@nicira.com>
dpif-netdev: Remove max_mtu tracking.

Normally all the ports have the same mtu anyhow, so there is little
advantage in keeping track of the maximum mtu on a per-bridge basis.  In
upcoming commits, tracking mtu will require more locking and present
even less advantage (because the packet buffer will become per-thread, so
that reallocating once per thread becomes essentially a null cost).

Signed-off-by: Ben Pfaff <blp@nicira.com>
ovs-atomic: New functions atomic_flag_init(), atomic_flag_destroy().

Standard C11 doesn't need these functions because it is able to require
implementations not to need them.  But we can't construct a portable
implementation that does not need them in every case, so this commit adds
them.

These functions are only needed for atomic_flag objects that are
dynamically allocated (because statically allocated objects can use
ATOMIC_FLAG_INIT).  So far there aren't any of those, but an upcoming
commit will introduce one.

Signed-off-by: Ben Pfaff <blp@nicira.com>
ovs-atomic: Add atomic_destroy() and use everywhere it is needed.

C11 is able to require that atomics don't need to be destroyed, but some
of the OVS implementations do.

Signed-off-by: Ben Pfaff <blp@nicira.com>
ovs-atomic: Introduce a new 'struct ovs_refcount'.

This is a thin wrapper around an atomic_uint.  It is useful anyhow because
each ovs_refcount_ref() or ovs_refcount_unref() call saves a few lines of
code.

This commit also changes all the potential direct users over to use the new
data structure.

Signed-off-by: Ben Pfaff <blp@nicira.com>
dpif-netdev: Take advantage of ovs_refcount for dp_netdev.

By making "destroyed" own a reference, we can treat dp_netdev's ref_cnt
like any other in Open vSwitch.

Signed-off-by: Ben Pfaff <blp@nicira.com>
dpif-netdev: Break actions out into new struct dp_netdev_actions.

This is analogous to the split between rule and rule_actions in
ofproto.  As there, it will allow retaining a reference to a rule's
actions, while processing them, without having to retain a reference
to the rule itself.

Signed-off-by: Ben Pfaff <blp@nicira.com>
dpif-netdev: Introduce new mutex to protect queues.

This is a first step in making thread safety more granular in dpif-netdev,
to allow for multithreaded forwarding.

Signed-off-by: Ben Pfaff <blp@nicira.com>
dpif-netdev: Make thread-safety much more granular.

This will allow for parallelism in multithreaded forwarding in an upcoming
commit.

Signed-off-by: Ben Pfaff <blp@nicira.com>
dpif-netdev: Use separate threads for forwarding.

For now, we use exactly two threads.  Presumably at some point we will want
to make this configurable.

Signed-off-by: Ben Pfaff <blp@nicira.com>