test-vconn: Block in three cases where a race is visible on FreeBSD.

On FreeBSD, sometimes plain vconn_connect() or vconn_recv() reports EAGAIN
in these cases.

Reported-by: Ed Maste <emaste@freebsd.org>
Signed-off-by: Ben Pfaff <blp@nicira.com>
test-vconn: Also accept EPIPE for TCP connection failures.

Ed Maste reports that write() to a socket where the other side has closed
returns EPIPE on FreeBSD and ECONNRESET on Linux.

Reported-by: Ed Maste <emaste@freebsd.org>
Signed-off-by: Ben Pfaff <blp@nicira.com>
lockfile: Fix hang locking through a dangling symlink.

open() with O_CREAT|O_EXCL yields EEXIST if the file being opened is a
symlink.  lockfile_try_lock() interpreted that error code to mean that
some other process had created the lock file in the meantime, so it went
around its loop again, which found out the same thing, which led to a hang.

This commit fixes the problem by dropping O_EXCL.  I don't see any reason
that it's actually necessary.  That means that the loop itself is
unnecessary, so this commit drops that too.

Debian bug #681880.
CC: 681880@bugs.debian.org
Reported-by: Bastian Blank <waldi@debian.org>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Reviewed-by: Simon Horman <horms@verge.net.au>
ovsdb: Make "ovsdb-tool create" work through a dangling symlink.

open() with O_CREAT|O_EXCL yields EEXIST if the name passed in is a
symlink, but we would like "ovsdb-tool create /etc/openvswitch/conf.db" to
work if /etc/openvswitch/conf.db is a symlink to elsewhere in the file
system.  This commit fixes the problem.  It introduces a theoretical race,
but no one should be doing "ovsdb-tool create" in parallel anyhow; O_EXCL
is just an idiot check here, not required to be fail-safe.

Debian bug #681880.
CC: 681880@bugs.debian.org
Reported-by: Bastian Blank <waldi@debian.org>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Reviewed-by: Simon Horman <horms@verge.net.au>
Make the location of the database separately configurable.

The default is unchanged, /etc/openvswitch/conf.db.

This makes it possible to transition each Open vSwitch packaging from
/etc/openvswitch/conf.db to /var/lib/openvswitch/conf.db independently.

Signed-off-by: Ben Pfaff <blp@nicira.com>
tests: Slightly generalize utility function tests.

This will allow passing arguments in for an upcoming test.

Signed-off-by: Ben Pfaff <blp@nicira.com>
util: New function follow_symlinks().

It will acquire its first user in an upcoming commit.

Signed-off-by: Ben Pfaff <blp@nicira.com>
lockfile: Be more forgiving about lockfiles for symlinks.

As the database is being transitioned from /etc to /var, there is a symlink
from the old to the new location for the database and a symlink for its
lockfile.  This works OK, but it would be more user-friendly to still work
correctly in case the symlink for the lockfile isn't there (since its
existence is non-obvious), so this commit implements that behavior.

Signed-off-by: Ben Pfaff <blp@nicira.com>
ovsdb: Do not replace symlinks by regular files during compaction.

Signed-off-by: Ben Pfaff <blp@nicira.com>
flow: Fix wild pointer dereference in flow_compose().

The 'ip' variable in flow_compose() points to some memory allocated
in an ofpbuf.  The ofpbuf is modified without making the necessary
updates to the location of 'ip' causing a potential wild memory
access.

Found by inspection.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
Improving comment for OFP10_VLAN_NONE.

Signed-off-by: Mehak Mahajan <mmahajan@nicira.com>
Fix a typo in commit f973f2af2.

Signed-off-by: Mehak Mahajan <mmahajan@nicira.com>
Create .conf.db.~lock~ in same dir as DBDIR.

Commit f973f2af (Make the location of the database separately configurable.)
introduced the environment variable OVS_DBDIR which specifies the path for
the conf.db.  With this commit, .conf.db.~lock~ will also be created in the
DBDIR.

Signed-off-by: Mehak Mahajan <mmahajan@nicira.com>
Adding checksum to IP packets created by ovs for testing.

OVS provides a utility to create IP packets for the purpose of testing
using ovs-appctl netdev-dummy/receive.  These packets created by
flow_compose() earlier did not have the IP checksum in them.  With this
commit, the checksum with be added to these test IP packets.

Signed-off-by: Mehak Mahajan <mmahajan@nicira.com>
dirs: dbdir default must be based on sysconfdir.

Some in-tree and out-of-tree code sets the OVS_SYSCONFDIR environment
variable to control where /etc files go (mostly for test purposes).  When
the database directory (dbdir) was split off from the sysconfdir, the
configure-time default continued to be based on the sysconfdir, but
overriding the sysconfdir at runtime with OVS_SYSCONFDIR didn't have any
effect on the dbdir, which caused a visible change in behavior for code
that set the OVS_SYSCONFDIR environment variable.  This commit reverts that
change in behavior, by basing the dbdir on OVS_SYSCONFDIR if that
environment variable is set (but the OVS_DBDIR environment variable is
not).

Signed-off-by: Ben Pfaff <blp@nicira.com>
ofproto: Avoid sensitivity to hash order in flow monitor pause/resume test.

Signed-off-by: Ben Pfaff <blp@nicira.com>
flow: Correctly consider nw_frag_mask in some flow_wildcards_*() functions.

This probably means that some classifier functions based on the fragment
type of packets have never worked properly.

Signed-off-by: Ben Pfaff <blp@nicira.com>
flow: Remove superfluous casts.

Signed-off-by: Ben Pfaff <blp@nicira.com>
ofproto-dpif: Remove superfluous cast.

'packet' is already a struct ofpbuf *.

Signed-off-by: Ben Pfaff <blp@nicira.com>
test-sha1: Remove unneeded casts.

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