datapath: Silence RCU lockdep checks from flow lookup.

Flow lookup can happen either in packet processing context or userspace
context but it was annotated as requiring RCU read lock to be held. This
also allows OVS mutex to be held without causing warnings.

Reported-by: Justin Pettit <jpettit@nicira.com>
Signed-off-by: Jesse Gross <jesse@nicira.com>
Reviewed-by: Thomas Graf <tgraf@redhat.com>
lib/util: Rename ctz() as ctz32().

ctz() returns 32 for zero input, and we already have ctz64(),
so it makes sense to rename ctz() as ctz32().

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
lib/util: Add clz32() and clz64().

Count leading zeroes using builtin if available.

Make log_2_floor() use raw_clz() and inline log_2_floor() and
log_2_ceil().

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
tests/ofproto-dpif.at: Avoid testing with incomplete TCP packets.

Use nw_proto values that generate less "expected but not present”
debug logging due to parsing errors for netdev-dummy/receive.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
ofproto: Add OF1.4 elements to enum ofp_table_config

Add elements to enum ofp_table_config for table mod bits
defined in OpenFlow1.4.

Also tidy up the indentation of existing elements.

Signed-off-by: Simon Horman <horms@verge.net.au>
Co-authored-by: Ben Pfaff <blp@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
datapath: Add backport for genlmsg_new_unicast().

genlmsg_new_unicast() will be proposed upstream to support memory
mapped Netlink but on existing kernels it just uses genlmsg_new().

Signed-off-by: Jesse Gross <jesse@nicira.com>
datapath: Enable memory mapped Netlink i/o

Use memory mapped Netlink i/o for all unicast openvswitch
communication if a ring has been set up.

Benchmark
  * pktgen -> ovs internal port
  * 5M pkts, 5M flows
  * 4 threads, 8 cores

Before:
Result: OK: 67418743(c67108212+d310530) usec, 5000000 (9000byte,0frags)
  74163pps 5339Mb/sec (5339736000bps) errors: 0
	+   2.98%     ovs-vswitchd  [k] copy_user_generic_string
	+   2.49%     ovs-vswitchd  [k] memcpy
	+   1.84%       kpktgend_2  [k] memcpy
	+   1.81%       kpktgend_1  [k] memcpy
	+   1.81%       kpktgend_3  [k] memcpy
	+   1.78%       kpktgend_0  [k] memcpy

After:
Result: OK: 24229690(c24127165+d102524) usec, 5000000 (9000byte,0frags)
  206358pps 14857Mb/sec (14857776000bps) errors: 0
	+   2.80%     ovs-vswitchd  [k] memcpy
	+   1.31%       kpktgend_2  [k] memcpy
	+   1.23%       kpktgend_0  [k] memcpy
	+   1.09%       kpktgend_1  [k] memcpy
	+   1.04%       kpktgend_3  [k] memcpy
	+   0.96%     ovs-vswitchd  [k] copy_user_generic_string

Signed-off-by: Thomas Graf <tgraf@suug.ch>
Reviewed-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: Jesse Gross <jesse@nicira.com>
ofp-util: Break ofputil_encode_packet_in() into multiple functions.

This form makes it obvious that an OpenFlow 1.1 implementation is missing.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Reviewed-by: Simon Horman <horms@verge.net.au>
ofp-util: Implement OpenFlow 1.1 packet-in message.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Reviewed-by: Simon Horman <horms@verge.net.au>
lib: refactor match_format() output functions

Refactor to remove some duplicated logic in match_format()
implemenation and make the output more uniform.

Signed-off-by: Andy Zhou <azhou@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
fedora package: include python byte compiled files

Include byte compiled files to speed up the execution,
to avoid spurious SELinux AVC denials and also to make
rpm happy when checking for unpackaged files:

RPM build errors:
    Installed (but unpackaged) file(s) found:
   /usr/share/openvswitch/python/argparse.pyc
   /usr/share/openvswitch/python/argparse.pyo
   /usr/share/openvswitch/python/ovs/__init__.pyc
   [...]

Package guideline reference:
https://fedoraproject.org/wiki/Packaging:Python?rd=Packaging/Python#Files_to_include

Signed-off-by: Flavio Leitner <fbl@redhat.com>
Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
lib/meta-flow: remove unused function

Remove mf_random_value() which does not have any user now.

Signed-off-by: Andy Zhou <azhou@nicira.com>
Add check for -latomic

Later versions of gcc on some architectures push atomic functions
out into a separate atomic library; add a check to see when this
is required and add it to LIBS if need be.

Specifically the problem was observed on GCC 4.8.2 on powerpc
architecture for Ubuntu 14.04:

https://launchpadlibrarian.net/155235096/buildlog_ubuntu-trusty-powerpc.openvswitch_2.0.0-0ubuntu1_FAILEDTOBUILD.txt.gz

Signed-off-by: James Page <james.page@ubuntu.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
m4: Remove assignment of otherwise unused variable RESOLVER_LIBS.

Found by inspection.

Signed-off-by: Ben Pfaff <blp@nicira.com>
bridge: Improve iface_set_ofport() style.

This should behave the same as before but the code reads more naturally to
me this way.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
datapath: Fix compat skb_get_rxhash()

Add missing return statement.

Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
Acked-by: Jesse Gross <jesse@nicira.com>
datapath: Improve compat rxhash functionality.

Following patch improves rxhash calculation, It is taken from
upstream Linux kernel code.
From kernel 3.8, skb_get_rxhash() can handle hardware generated
l4-rxhash. Therefore compat skb_get_rxhash() is not used on
kernel 3.8 or new.

Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
Reviewed-by: Thomas Graf <tgraf@redhat.com>
Acked-by: Jesse Gross <jesse@nicira.com>
datapath: Add compile time check for rxhash

Some distribution kernel has backported skb->rxhash (e.g. RHEL)
Following patch allows use precalculated rxhash.

Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
Reviewed-by: Thomas Graf <tgraf@redhat.com>
Acked-by: Jesse Gross <jesse@nicira.com>
datapath: lisp: Use skb rxhash for source port.

Rather than using complete flow hash, we can use skb->rxhash for
calculating source port. Similar calculation is done by vxlan.

Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
Acked-by: Jesse Gross <jesse@nicira.com>
datapath: Use percpu allocator for flow-stats.

Use percpu allocator for stats due to objection to stats array.
But percpu allocator is not designed for high churn allocation/
deallcation. so we need to avoid allocating percpu flow for
short lived flows. One cheaper way to detect flow is by checking
if 5-tuple used in RSS are masked or not. if any one of them is
masked, flow is likely shared across CPU where percpu stat
should be more scalable. And that flow should be relatively
long lived flow.

Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
Acked-by: Jesse Gross <jesse@nicira.com>