提交 f7ed6936 编写于 作者: S Stefan Berger

build: fix compilation on systems missing libnl and new includes

This patch fixes the compilation of netlink.c and interface.c on those
systems missing either libnl or that have an older linux/if_link.h
include file not supporting macvtap or VF_PORTS.

WITH_MACVTAP is '1' if newer include files were detected, '0' otherwise.

IFLA_PORT_MAX is defined in linux/if_link.h if yet more functionality is
supported.
上级 20991b93
...@@ -510,7 +510,7 @@ ifaceSetMacaddr(const char *ifname ATTRIBUTE_UNUSED, ...@@ -510,7 +510,7 @@ ifaceSetMacaddr(const char *ifname ATTRIBUTE_UNUSED,
* *
* Returns 0 on success, -1 on fatal error. * Returns 0 on success, -1 on fatal error.
*/ */
#if __linux__ #if defined(__linux__) && WITH_MACVTAP
int int
ifaceMacvtapLinkAdd(const char *type, ifaceMacvtapLinkAdd(const char *type,
const unsigned char *macaddress, int macaddrsize, const unsigned char *macaddress, int macaddrsize,
...@@ -649,8 +649,14 @@ ifaceMacvtapLinkAdd(const char *type ATTRIBUTE_UNUSED, ...@@ -649,8 +649,14 @@ ifaceMacvtapLinkAdd(const char *type ATTRIBUTE_UNUSED,
int *retry ATTRIBUTE_UNUSED) int *retry ATTRIBUTE_UNUSED)
{ {
ifaceError(VIR_ERR_INTERNAL_ERROR, "%s", ifaceError(VIR_ERR_INTERNAL_ERROR, "%s",
# if defined(__linux__) && !WITH_MACVTAP
_("ifaceMacvtapLinkAdd is not supported since the include "
"files were too old"));
# else
_("ifaceMacvtapLinkAdd is not supported on non-linux " _("ifaceMacvtapLinkAdd is not supported on non-linux "
"platforms")); "platforms"));
# endif
return -1; return -1;
} }
...@@ -666,7 +672,7 @@ ifaceMacvtapLinkAdd(const char *type ATTRIBUTE_UNUSED, ...@@ -666,7 +672,7 @@ ifaceMacvtapLinkAdd(const char *type ATTRIBUTE_UNUSED,
* *
* Returns 0 on success, -1 on fatal error. * Returns 0 on success, -1 on fatal error.
*/ */
#if __linux__ #if defined( __linux__) && WITH_MACVTAP
int int
ifaceLinkDel(const char *ifname) ifaceLinkDel(const char *ifname)
{ {
...@@ -751,14 +757,20 @@ int ...@@ -751,14 +757,20 @@ int
ifaceLinkDel(const char *ifname ATTRIBUTE_UNUSED) ifaceLinkDel(const char *ifname ATTRIBUTE_UNUSED)
{ {
ifaceError(VIR_ERR_INTERNAL_ERROR, "%s", ifaceError(VIR_ERR_INTERNAL_ERROR, "%s",
# if defined(__linux__) && !WITH_MACVTAP
_("ifaceLinkDel is not supported since the include files "
"were too old"));
# else
_("ifaceLinkDel is not supported on non-linux platforms")); _("ifaceLinkDel is not supported on non-linux platforms"));
# endif
return -1; return -1;
} }
#endif #endif
#if __linux__ #if defined(__linux__) && defined(IFLA_PORT_MAX)
static struct nla_policy ifla_policy[IFLA_MAX + 1] = static struct nla_policy ifla_policy[IFLA_MAX + 1] =
{ {
[IFLA_VF_PORTS] = { .type = NLA_NESTED }, [IFLA_VF_PORTS] = { .type = NLA_NESTED },
...@@ -894,8 +906,14 @@ ifaceMacvtapLinkDump(bool nltarget_kernel ATTRIBUTE_UNUSED, ...@@ -894,8 +906,14 @@ ifaceMacvtapLinkDump(bool nltarget_kernel ATTRIBUTE_UNUSED,
uint32_t (*getPidFunc)(void) ATTRIBUTE_UNUSED) uint32_t (*getPidFunc)(void) ATTRIBUTE_UNUSED)
{ {
ifaceError(VIR_ERR_INTERNAL_ERROR, "%s", ifaceError(VIR_ERR_INTERNAL_ERROR, "%s",
# if defined(__linux__) && !defined(IFLA_PORT_MAX)
_("ifaceMacvtapLinkDump is not supported since the include "
"files were too old"));
# else
_("ifaceMacvtapLinkDump is not supported on non-linux " _("ifaceMacvtapLinkDump is not supported on non-linux "
"platforms")); "platforms"));
# endif
return -1; return -1;
} }
...@@ -920,7 +938,7 @@ ifaceMacvtapLinkDump(bool nltarget_kernel ATTRIBUTE_UNUSED, ...@@ -920,7 +938,7 @@ ifaceMacvtapLinkDump(bool nltarget_kernel ATTRIBUTE_UNUSED,
* *
* Return 0 on success, != 0 otherwise * Return 0 on success, != 0 otherwise
*/ */
#if __linux__ #if defined(__linux__) && WITH_MACVTAP
int int
ifaceGetNthParent(int ifindex, const char *ifname, unsigned int nthParent, ifaceGetNthParent(int ifindex, const char *ifname, unsigned int nthParent,
int *parent_ifindex, char *parent_ifname, int *parent_ifindex, char *parent_ifname,
...@@ -981,7 +999,12 @@ ifaceGetNthParent(int ifindex ATTRIBUTE_UNUSED, ...@@ -981,7 +999,12 @@ ifaceGetNthParent(int ifindex ATTRIBUTE_UNUSED,
unsigned int *nth ATTRIBUTE_UNUSED) unsigned int *nth ATTRIBUTE_UNUSED)
{ {
ifaceError(VIR_ERR_INTERNAL_ERROR, "%s", ifaceError(VIR_ERR_INTERNAL_ERROR, "%s",
# if defined(__linux__) && !WITH_MACVTAP
_("ifaceGetNthParent is not supported since the include files "
"were too old"));
# else
_("ifaceGetNthParent is not supported on non-linux platforms")); _("ifaceGetNthParent is not supported on non-linux platforms"));
# endif
return -1; return -1;
} }
......
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
* Returns 0 on success, -1 on error. In case of error, no response * Returns 0 on success, -1 on error. In case of error, no response
* buffer will be returned. * buffer will be returned.
*/ */
#if __linux__ #if defined(__linux__) && defined(HAVE_LIBNL)
int nlComm(struct nl_msg *nl_msg, int nlComm(struct nl_msg *nl_msg,
unsigned char **respbuf, unsigned int *respbuflen, unsigned char **respbuf, unsigned int *respbuflen,
int nl_pid) int nl_pid)
...@@ -143,7 +143,11 @@ int nlComm(struct nl_msg *nl_msg ATTRIBUTE_UNUSED, ...@@ -143,7 +143,11 @@ int nlComm(struct nl_msg *nl_msg ATTRIBUTE_UNUSED,
int nl_pid ATTRIBUTE_UNUSED) int nl_pid ATTRIBUTE_UNUSED)
{ {
netlinkError(VIR_ERR_INTERNAL_ERROR, "%s", netlinkError(VIR_ERR_INTERNAL_ERROR, "%s",
# if defined(__linux__) && !defined(HAVE_LIBNL)
_("nlComm is not supported since libnl was not available"));
# else
_("nlComm is not supported on non-linux platforms")); _("nlComm is not supported on non-linux platforms"));
# endif
return -1; return -1;
} }
......
...@@ -20,7 +20,9 @@ ...@@ -20,7 +20,9 @@
#ifndef __VIR_NETLINK_H__ #ifndef __VIR_NETLINK_H__
# define __VIR_NETLINK_H__ # define __VIR_NETLINK_H__
# if __linux__ # include "config.h"
# if defined(__linux__) && defined(HAVE_LIBNL)
# include <netlink/msg.h> # include <netlink/msg.h>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册