Hack to build macvtap support for SLES11 >= SP2

SLES11 linux-kernel-headers does not support macvtap, even though the
kernel does provide such support.  See the following bug and
research@suse.de thread for more information

https://bugzilla.novell.com/show_bug.cgi?id=770103
https://mailman.suse.de/mailman/private/research/2012-July/001535.html


Index: libvirt-1.0.5.4/configure.ac
===================================================================
--- libvirt-1.0.5.4.orig/configure.ac
+++ libvirt-1.0.5.4/configure.ac
@@ -2248,15 +2248,7 @@ AC_ARG_WITH([macvtap],
 
 AC_MSG_CHECKING([whether to compile with macvtap support])
 if test "$with_macvtap" != "no" ; then
-    AC_TRY_COMPILE([ #include <sys/socket.h>
-                     #include <linux/rtnetlink.h> ],
-                   [ int x = MACVLAN_MODE_BRIDGE;
-                     int y = IFLA_VF_MAX; ],
-                   [ with_macvtap=yes ],
-                   [ if test "$with_macvtap" = "yes" ; then
-                         AC_MSG_ERROR([Installed linux headers don't show support for macvtap device.])
-                     fi
-                     with_macvtap=no ])
+    with_macvtap=yes
     if test "$with_macvtap" = "yes" ; then
         val=1
     else
@@ -2295,14 +2287,7 @@ if test "$with_macvtap" != "yes"; then
 fi
 if test "$with_virtualport" != "no"; then
     AC_MSG_CHECKING([whether to compile with virtual port support])
-    AC_TRY_COMPILE([ #include <sys/socket.h>
-                     #include <linux/rtnetlink.h> ],
-                     [ int x = IFLA_PORT_MAX; ],
-                     [ with_virtualport=yes ],
-                     [ if test "$with_virtualport" = "yes" ; then
-                         AC_MSG_ERROR([Installed linux headers don't show support for virtual port support.])
-                       fi
-                       with_virtualport=no ])
+    with_virtualport=yes
     if test "$with_virtualport" = "yes"; then
         val=1
     else
Index: libvirt-1.0.5.4/src/util/virnetdevmacvlan.c
===================================================================
--- libvirt-1.0.5.4.orig/src/util/virnetdevmacvlan.c
+++ libvirt-1.0.5.4/src/util/virnetdevmacvlan.c
@@ -52,10 +52,11 @@ VIR_ENUM_IMPL(virNetDevMacVLanMode, VIR_
 # include <linux/if.h>
 # include <linux/if_tun.h>
 
-/* Older kernels lacked this enum value.  */
-# if !HAVE_DECL_MACVLAN_MODE_PASSTHRU
-#  define MACVLAN_MODE_PASSTHRU 8
-# endif
+/* SLES11 linux-kernel-headers package does not contain an ip_link.h with
+   macvtap support.  The SP2+ kernels support it though, so add the
+   ip_link.h additions to a local header as a build hack
+*/
+# include "viriflink.h"
 
 # include "viralloc.h"
 # include "virlog.h"
Index: libvirt-1.0.5.4/src/util/viriflink.h
===================================================================
--- /dev/null
+++ libvirt-1.0.5.4/src/util/viriflink.h
@@ -0,0 +1,166 @@
+/*
+ * viriflink.h: SLES11 hack to workaround no macvtap support in
+ *              linux-kernel-headers package.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef __VIRIFLINK_H__
+# define __VIRIFLINK_H__
+
+# define IFLA_NUM_VF 21		/* Number of VFs if device is SR-IOV PF */
+# define IFLA_VFINFO_LIST 22
+# define IFLA_STATS64 23
+# define IFLA_VF_PORTS 24
+# define IFLA_PORT_SELF 25
+
+
+# ifdef IFLA_MAX
+#  undef IFLA_MAX
+#  define IFLA_MAX 25
+# endif
+
+/* MACVLAN section */
+enum {
+	IFLA_MACVLAN_UNSPEC,
+	IFLA_MACVLAN_MODE,
+	__IFLA_MACVLAN_MAX,
+};
+
+# define IFLA_MACVLAN_MAX (__IFLA_MACVLAN_MAX - 1)
+
+enum macvlan_mode {
+	MACVLAN_MODE_PRIVATE = 1, /* don't talk to other macvlans */
+	MACVLAN_MODE_VEPA    = 2, /* talk to other ports through ext bridge */
+	MACVLAN_MODE_BRIDGE  = 4, /* talk to bridge ports directly */
+	MACVLAN_MODE_PASSTHRU = 8,/* take over the underlying device */
+};
+
+/* SR-IOV virtual function management section */
+
+enum {
+	IFLA_VF_INFO_UNSPEC,
+	IFLA_VF_INFO,
+	__IFLA_VF_INFO_MAX,
+};
+
+# define IFLA_VF_INFO_MAX (__IFLA_VF_INFO_MAX - 1)
+
+enum {
+	IFLA_VF_UNSPEC,
+	IFLA_VF_MAC,		/* Hardware queue specific attributes */
+	IFLA_VF_VLAN,
+	IFLA_VF_TX_RATE,	/* TX Bandwidth Allocation */
+	IFLA_VF_SPOOFCHK,	/* Spoof Checking on/off switch */
+	__IFLA_VF_MAX,
+};
+
+# define IFLA_VF_MAX (__IFLA_VF_MAX - 1)
+
+struct ifla_vf_mac {
+	__u32 vf;
+	__u8 mac[32]; /* MAX_ADDR_LEN */
+};
+
+struct ifla_vf_vlan {
+	__u32 vf;
+	__u32 vlan; /* 0 - 4095, 0 disables VLAN filter */
+	__u32 qos;
+};
+
+struct ifla_vf_tx_rate {
+	__u32 vf;
+	__u32 rate; /* Max TX bandwidth in Mbps, 0 disables throttling */
+};
+
+struct ifla_vf_spoofchk {
+	__u32 vf;
+	__u32 setting;
+};
+
+/* VF ports management section
+ *
+ *	Nested layout of set/get msg is:
+ *
+ *		[IFLA_NUM_VF]
+ *		[IFLA_VF_PORTS]
+ *			[IFLA_VF_PORT]
+ *				[IFLA_PORT_*], ...
+ *			[IFLA_VF_PORT]
+ *				[IFLA_PORT_*], ...
+ *			...
+ *		[IFLA_PORT_SELF]
+ *			[IFLA_PORT_*], ...
+ */
+
+enum {
+	IFLA_VF_PORT_UNSPEC,
+	IFLA_VF_PORT,			/* nest */
+	__IFLA_VF_PORT_MAX,
+};
+
+# define IFLA_VF_PORT_MAX (__IFLA_VF_PORT_MAX - 1)
+
+enum {
+	IFLA_PORT_UNSPEC,
+	IFLA_PORT_VF,			/* __u32 */
+	IFLA_PORT_PROFILE,		/* string */
+	IFLA_PORT_VSI_TYPE,		/* 802.1Qbg (pre-)standard VDP */
+	IFLA_PORT_INSTANCE_UUID,	/* binary UUID */
+	IFLA_PORT_HOST_UUID,		/* binary UUID */
+	IFLA_PORT_REQUEST,		/* __u8 */
+	IFLA_PORT_RESPONSE,		/* __u16, output only */
+	__IFLA_PORT_MAX,
+};
+
+# define IFLA_PORT_MAX (__IFLA_PORT_MAX - 1)
+
+# define PORT_PROFILE_MAX	40
+# define PORT_UUID_MAX		16
+# define PORT_SELF_VF		-1
+
+enum {
+	PORT_REQUEST_PREASSOCIATE = 0,
+	PORT_REQUEST_PREASSOCIATE_RR,
+	PORT_REQUEST_ASSOCIATE,
+	PORT_REQUEST_DISASSOCIATE,
+};
+
+enum {
+	PORT_VDP_RESPONSE_SUCCESS = 0,
+	PORT_VDP_RESPONSE_INVALID_FORMAT,
+	PORT_VDP_RESPONSE_INSUFFICIENT_RESOURCES,
+	PORT_VDP_RESPONSE_UNUSED_VTID,
+	PORT_VDP_RESPONSE_VTID_VIOLATION,
+	PORT_VDP_RESPONSE_VTID_VERSION_VIOALTION,
+	PORT_VDP_RESPONSE_OUT_OF_SYNC,
+	/* 0x08-0xFF reserved for future VDP use */
+	PORT_PROFILE_RESPONSE_SUCCESS = 0x100,
+	PORT_PROFILE_RESPONSE_INPROGRESS,
+	PORT_PROFILE_RESPONSE_INVALID,
+	PORT_PROFILE_RESPONSE_BADSTATE,
+	PORT_PROFILE_RESPONSE_INSUFFICIENT_RESOURCES,
+	PORT_PROFILE_RESPONSE_ERROR,
+};
+
+struct ifla_port_vsi {
+	__u8 vsi_mgr_id;
+	__u8 vsi_type_id[3];
+	__u8 vsi_type_version;
+	__u8 pad[3];
+};
+
+#endif
Index: libvirt-1.0.5.4/src/util/virnetdevvportprofile.c
===================================================================
--- libvirt-1.0.5.4.orig/src/util/virnetdevvportprofile.c
+++ libvirt-1.0.5.4/src/util/virnetdevvportprofile.c
@@ -51,6 +51,12 @@ VIR_ENUM_IMPL(virNetDevVPortProfileOp, V
 # include <linux/if.h>
 # include <linux/if_tun.h>
 
+/* SLES11 linux-kernel-headers package does not contain an ip_link.h with
+   macvtap support.  The SP2+ kernels support it though, so add the
+   ip_link.h additions to a local header as a build hack
+*/
+# include "viriflink.h"
+
 # include "virnetlink.h"
 # include "virfile.h"
 # include "virlog.h"
