2011-06-22 21:42:51 +00:00
|
|
|
/*
|
2013-05-31 17:52:51 +00:00
|
|
|
* Copyright (C) 2010-2013 Red Hat, Inc.
|
2012-02-03 14:13:19 +00:00
|
|
|
* Copyright (C) 2010-2012 IBM Corporation
|
2011-06-22 21:42:51 +00:00
|
|
|
*
|
|
|
|
* 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
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2011-06-22 21:42:51 +00:00
|
|
|
*/
|
|
|
|
|
2011-06-22 18:17:36 +00:00
|
|
|
#ifndef __VIR_NETLINK_H__
|
|
|
|
# define __VIR_NETLINK_H__
|
|
|
|
|
2012-02-22 13:17:13 +00:00
|
|
|
# include "internal.h"
|
2012-07-17 12:07:59 +00:00
|
|
|
# include "virmacaddr.h"
|
2011-06-23 15:54:11 +00:00
|
|
|
|
|
|
|
# if defined(__linux__) && defined(HAVE_LIBNL)
|
2011-06-22 18:17:36 +00:00
|
|
|
|
build: work with older libnl1 headers
Ubuntu 10.04 shipped with out-of-the-box libnl1 headers, which
assumed the old gcc semantics of 'extern inline' as a C89 extension:
the function will _always_ be inline if it is used, and that
it may be declared extern inline in headers without a definition,
as long as the definition occurs before any use. But when C99
added 'extern inline' as a mandatory feature of the language, with
slightly different semantics than gcc (the function MUST have
external linkage, and the inline definition MUST be present
alongside any declaration, where the compiler can then choose
which of the two versions to use), this rendered the use of
'inline' in libnl's header obsolete. Most distros already solved
this by removing 'inline' (the resulting 'extern' is correct,
regardless of gcc semantics), and libnl-3 does not have the
problem (where it has switched to 'static inline' instead, again
with the definition present, and again, our hack will result in
plain 'static' with no ill effects). But for the case of building
out of the box, we hack around the broken Ubuntu header.
* src/util/virnetlink.h: Work around libnl issue.
2012-08-27 21:00:59 +00:00
|
|
|
/* Work around a bug where older libnl-1 headers expected older gcc
|
|
|
|
* semantics of 'extern inline' that conflict with C99 semantics. */
|
2012-08-28 10:01:50 +00:00
|
|
|
# ifdef HAVE_LIBNL1
|
|
|
|
# define inline
|
|
|
|
# endif
|
2011-06-22 18:17:36 +00:00
|
|
|
# include <netlink/msg.h>
|
2012-08-28 10:01:50 +00:00
|
|
|
# ifdef HAVE_LIBNL1
|
|
|
|
# undef inline
|
|
|
|
# endif
|
2011-06-22 18:17:36 +00:00
|
|
|
|
|
|
|
# else
|
|
|
|
|
|
|
|
struct nl_msg;
|
2012-02-22 13:17:13 +00:00
|
|
|
struct sockaddr_nl;
|
2012-03-06 01:12:34 +00:00
|
|
|
struct nlattr;
|
2013-04-03 13:09:19 +00:00
|
|
|
struct nlmsghdr;
|
2011-06-22 18:17:36 +00:00
|
|
|
|
|
|
|
# endif /* __linux__ */
|
|
|
|
|
2012-05-03 14:39:04 +00:00
|
|
|
int virNetlinkStartup(void);
|
|
|
|
void virNetlinkShutdown(void);
|
|
|
|
|
2012-02-03 14:13:19 +00:00
|
|
|
int virNetlinkCommand(struct nl_msg *nl_msg,
|
2013-04-03 13:09:19 +00:00
|
|
|
struct nlmsghdr **resp, unsigned int *respbuflen,
|
2012-08-22 04:10:23 +00:00
|
|
|
uint32_t src_pid, uint32_t dst_pid,
|
|
|
|
unsigned int protocol, unsigned int groups);
|
2011-06-22 18:17:36 +00:00
|
|
|
|
2013-04-03 13:09:19 +00:00
|
|
|
typedef void (*virNetlinkEventHandleCallback)(struct nlmsghdr *,
|
|
|
|
unsigned int length,
|
|
|
|
struct sockaddr_nl *peer,
|
|
|
|
bool *handled,
|
|
|
|
void *opaque);
|
2012-02-22 13:17:13 +00:00
|
|
|
|
2012-07-17 12:07:59 +00:00
|
|
|
typedef void (*virNetlinkEventRemoveCallback)(int watch, const virMacAddrPtr macaddr, void *opaque);
|
2012-02-22 13:17:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* stopNetlinkEventServer: stop the monitor to receive netlink messages for libvirtd
|
|
|
|
*/
|
2012-08-22 04:10:23 +00:00
|
|
|
int virNetlinkEventServiceStop(unsigned int protocol);
|
2012-02-22 13:17:13 +00:00
|
|
|
|
2012-08-22 04:10:24 +00:00
|
|
|
/**
|
|
|
|
* stopNetlinkEventServerAll: stop all the monitors to receive netlink messages for libvirtd
|
|
|
|
*/
|
|
|
|
int virNetlinkEventServiceStopAll(void);
|
|
|
|
|
2012-02-22 13:17:13 +00:00
|
|
|
/**
|
|
|
|
* startNetlinkEventServer: start a monitor to receive netlink messages for libvirtd
|
|
|
|
*/
|
2012-08-22 04:10:23 +00:00
|
|
|
int virNetlinkEventServiceStart(unsigned int protocol, unsigned int groups);
|
2012-02-22 13:17:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* virNetlinkEventServiceIsRunning: returns if the netlink event service is running.
|
|
|
|
*/
|
2012-08-22 04:10:23 +00:00
|
|
|
bool virNetlinkEventServiceIsRunning(unsigned int protocol);
|
2012-02-22 13:17:13 +00:00
|
|
|
|
2012-05-04 17:19:51 +00:00
|
|
|
/**
|
|
|
|
* virNetlinkEventServiceLocalPid: returns nl_pid used to bind() netlink socket
|
|
|
|
*/
|
2012-08-22 04:10:23 +00:00
|
|
|
int virNetlinkEventServiceLocalPid(unsigned int protocol);
|
2012-05-04 17:19:51 +00:00
|
|
|
|
2012-02-22 13:17:13 +00:00
|
|
|
/**
|
|
|
|
* virNetlinkEventAddClient: register a callback for handling of netlink messages
|
|
|
|
*/
|
|
|
|
int virNetlinkEventAddClient(virNetlinkEventHandleCallback handleCB,
|
|
|
|
virNetlinkEventRemoveCallback removeCB,
|
2012-08-22 04:10:23 +00:00
|
|
|
void *opaque, const virMacAddrPtr macaddr,
|
|
|
|
unsigned int protocol);
|
2012-02-22 13:17:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* virNetlinkEventRemoveClient: unregister a callback from a netlink monitor
|
|
|
|
*/
|
2012-08-22 04:10:23 +00:00
|
|
|
int virNetlinkEventRemoveClient(int watch, const virMacAddrPtr macaddr,
|
|
|
|
unsigned int protocol);
|
2012-02-22 13:17:13 +00:00
|
|
|
|
2011-06-22 18:17:36 +00:00
|
|
|
#endif /* __VIR_NETLINK_H__ */
|