timeval: Initialize 'unix_epoch' for Windows correctly.

Till now, we were initializing 'unix_epoch' through time_init().
But if there was a call directly to xgettimeofday(), we would
miss the initialization causing overflows. This commit fixes it
by pre-calculating the value and assigning it globally.

Also add-in a missing return statement.

Reported-by: Alessandro Pilotti <apilotti@cloudbasesolutions.com>
Reported-by: Linda Sun <lsun@vmware.com>
Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
daemon: restart child process if it died before signaling its readiness

The child process (the one being monitored) could die before it was able
to call fork_notify_startup() function.  If such situation arises, then
parent process (the one monitoring child process) would also terminate
with a fatal log message:

...|EMER|fork child died before signaling startup (killed (...))

This patch changes that behavior by always restarting child process
if it was able to start up at least once in the past.  However, if
child was not able to start up even once, then the monitor process
would still terminate, because that would most likely indicate a
persistent programming or system error.

To reproduce use following script:

while : ; do kill -SIGSEGV `cat /var/run/openvswitch/ovs-vswitchd.pid`; done

Signed-Off-By: Ansis Atteka <aatteka@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
VMware-BZ: 1273550
datapath/flow_netlink: Fix NDP flow mask validation

match_validate() enforce that a mask matching on NDP attributes has also an
exact match on ICMPv6 type.
The ICMPv6 type, which is 8-bit wide, is stored in the 'tp.src' field of
'struct sw_flow_key', which is 16-bit wide.
Therefore, an exact match on ICMPv6 type should only check the first 8 bits.

This commit fixes a bug that prevented flows with an exact match on NDP field
from being installed

Signed-off-by: Daniele Di Proietto <ddiproietto@vmware.com>
Acked-by: Pravin B Shelar <pshelar@nicira.com>
Modify and add headers needed for compile

Add headers structures, typedefs and defines needed to compile the files
lib/dpif-linux.c, lib/dpif.c, lib/netdev-linux.c, lib/netdev.c,
lib/netlink-socket.c, lib/netlink.c and lib/vlandev.c.

Signed-off-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com>
netlink-protocol: Remove definition of struct sockaddr_nl.

This struct is used only in netlink-socket.c, which is only used on Linux,
which in turn gets the definition from <linux/netlink.h>.  On Windows the
definition actually causes a small amount of trouble because Windows does
not define sa_family_t (despite POSIX), so it's better to remove it.

Even if other platforms adopt Netlink, I have no reason to believe that
they will use the same sockaddr format as Linux.

CC: Saurabh Shah <ssaurabh@vmware.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Gurucharan Shetty <gshetty@nicira.com>
datapath: add skb_clone NULL check in the recirc action.

Refactoring recirc action implementation.

The main change is to fix a bug where the NULL check after skb clone()
call is missing.  The fix is to return -ENOMEM whenever skb_clone()
failed to create a clone.

Also rearranged adjacent code to improve readability.

Reported-by: Pravin B Shelar <pshelar@nicira.com>
Signed-off-by: Andy Zhou <azhou@nicira.com>
Acked-by: Pravin B Shelar <pshelar@nicira.com>
datapath: add skb_clone NULL check for the sampling action.

Fix a bug where skb_clone() NULL check is missing in sample action
implementation.

Signed-off-by: Andy Zhou <azhou@nicira.com>
Acked-by: Pravin B Shelar <pshelar@nicira.com>
datapath: refactor do_output() to move skb_clone NULL check out of fast path

skb_clone() NULL check is implemented in do_output(), as past of the
common (fast) path. Refactoring so that NULL check is done in the
slow path, immediately after skb_clone() is called.

Besides optimization, this change also improves code readability by
making the skb_clone() NULL check consistent within OVS datapath
module.

Signed-off-by: Andy Zhou <azhou@nicira.com>
Acked-by: Pravin B Shelar <pshelar@nicira.com>
Add to changes lib/netlink.h

Add NETLINK defines for MSVC compiling

Signed-off-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com>
Changes to lib/automake.mk

Add the NETLINK and DPIF objects to the openvswitch archive for windows.

Signed-off-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com>
Ignore epoll specific functions in case of MSVC

Bypass epoll_ctl, epoll_create and epoll_wait functions on MSVC.

Signed-off-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com>
Initialize dpif_linux_class for MSVC as well

Do not bypass dpif_linux_class for the creation of dpif_class when compiling
with MSVC. This will allow the code behind dpif-linux interface to run.

Signed-off-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com>
Initialize linux netdev class for MSVC as well

Do not bypass the register of the netdev_linux_class, netdev_internal_class,
netdev_tap_class and netdev_vport_tunnel_register when compiling
with MSVC. This will allow the code behind netdev-linux interface to run.

Signed-off-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com>
Remove netlink padding for MSVC

Change the defines NLMSG_ALIGNTO and NLA_ALIGNTO defines to 0.

Change the macros NLA_ALIGN and NLMSG_ALIGN to SIZE.

Signed-off-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com>
Initialize vlandev_linux_class for MSVC as well

Change the vlandev_get_class to vlandev_linux_class instead of
vlandev_stub_class when compiling with MSVC.

This will allow the code behind dpifnetdev-linuxlinux interface to run.

Signed-off-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com>
Ignore aligned cast and drains on MSVC

Bypass ALIGNED_CAST on CMSG_DATA when compiling on MSVC. Ignore the code
behind netdev_linux_rxq_drain as well.

Signed-off-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com>
Allow compile when compiling with MSVC

Ignore HAVE_NETLINK macro when compiling with MSVC this will allow the
inclusion of the netlink-socket.h.

Signed-off-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com>
Ignore padding when compiling with MSVC

Change the size of the padding to 0 in the function nl_msg_put_uninit.

Signed-off-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com>
Changes needed for netlink-socket.c

Adding CreateFile, WriteFile, ReadFile and CloseHandle instead of linux
counterparts when compiling netlink-socket.c with MSVC. Also add socket pid
generation function that will later on will be needed in the kernel
extension.

Signed-off-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com>
Add new headers to noinst_HEADERS

Add the newly created headers in include/windows/* to
include/windows/automake.mk.

Signed-off-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com>