virnetlink.h 2.5 KB
Newer Older
E
Eric Blake 已提交
1
/*
2
 * Copyright (C) 2010-2012 Red Hat, Inc.
3
 * Copyright (C) 2010-2012 IBM Corporation
E
Eric Blake 已提交
4 5 6 7 8 9 10 11 12 13 14 15
 *
 * 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
O
Osier Yang 已提交
16 17
 * License along with this library;  If not, see
 * <http://www.gnu.org/licenses/>.
E
Eric Blake 已提交
18 19
 */

20 21 22
#ifndef __VIR_NETLINK_H__
# define __VIR_NETLINK_H__

23
# include "config.h"
24
# include "internal.h"
25
# include "virmacaddr.h"
26 27

# if defined(__linux__) && defined(HAVE_LIBNL)
28 29 30 31 32 33

#  include <netlink/msg.h>

# else

struct nl_msg;
34
struct sockaddr_nl;
35
struct nlattr;
36 37 38

# endif /* __linux__ */

39 40 41
int virNetlinkStartup(void);
void virNetlinkShutdown(void);

42 43
int virNetlinkCommand(struct nl_msg *nl_msg,
                      unsigned char **respbuf, unsigned int *respbuflen,
44
                      uint32_t src_port, uint32_t dst_port);
45

46 47
typedef void (*virNetlinkEventHandleCallback)(unsigned char *msg, int length, struct sockaddr_nl *peer, bool *handled, void *opaque);

48
typedef void (*virNetlinkEventRemoveCallback)(int watch, const virMacAddrPtr macaddr, void *opaque);
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

/**
 * stopNetlinkEventServer: stop the monitor to receive netlink messages for libvirtd
 */
int virNetlinkEventServiceStop(void);

/**
 * startNetlinkEventServer: start a monitor to receive netlink messages for libvirtd
 */
int virNetlinkEventServiceStart(void);

/**
 * virNetlinkEventServiceIsRunning: returns if the netlink event service is running.
 */
bool virNetlinkEventServiceIsRunning(void);

65 66 67 68 69
/**
 * virNetlinkEventServiceLocalPid: returns nl_pid used to bind() netlink socket
 */
int virNetlinkEventServiceLocalPid(void);

70 71 72 73 74
/**
 * virNetlinkEventAddClient: register a callback for handling of netlink messages
 */
int virNetlinkEventAddClient(virNetlinkEventHandleCallback handleCB,
                             virNetlinkEventRemoveCallback removeCB,
75
                             void *opaque, const virMacAddrPtr macaddr);
76 77 78 79

/**
 * virNetlinkEventRemoveClient: unregister a callback from a netlink monitor
 */
80
int virNetlinkEventRemoveClient(int watch, const virMacAddrPtr macaddr);
81

82
#endif /* __VIR_NETLINK_H__ */