virnetlink.h 3.4 KB
Newer Older
E
Eric Blake 已提交
1
/*
2
 * Copyright (C) 2010-2013 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
16
 * License along with this library.  If not, see
O
Osier Yang 已提交
17
 * <http://www.gnu.org/licenses/>.
E
Eric Blake 已提交
18 19
 */

20 21 22
#ifndef __VIR_NETLINK_H__
# define __VIR_NETLINK_H__

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

# if defined(__linux__) && defined(HAVE_LIBNL)
27

28 29
/* Work around a bug where older libnl-1 headers expected older gcc
 * semantics of 'extern inline' that conflict with C99 semantics.  */
30 31 32
#  ifdef HAVE_LIBNL1
#   define inline
#  endif
33
#  include <netlink/msg.h>
34 35 36
#  ifdef HAVE_LIBNL1
#   undef inline
#  endif
37 38 39 40

# else

struct nl_msg;
41
struct sockaddr_nl;
42
struct nlattr;
43
struct nlmsghdr;
44 45 46

# endif /* __linux__ */

47 48 49
int virNetlinkStartup(void);
void virNetlinkShutdown(void);

50
int virNetlinkCommand(struct nl_msg *nl_msg,
51
                      struct nlmsghdr **resp, unsigned int *respbuflen,
52 53
                      uint32_t src_pid, uint32_t dst_pid,
                      unsigned int protocol, unsigned int groups);
54

55 56 57 58 59
typedef void (*virNetlinkEventHandleCallback)(struct nlmsghdr *,
                                              unsigned int length,
                                              struct sockaddr_nl *peer,
                                              bool *handled,
                                              void *opaque);
60

61 62 63
typedef void (*virNetlinkEventRemoveCallback)(int watch,
                                              const virMacAddr *macaddr,
                                              void *opaque);
64 65 66 67

/**
 * stopNetlinkEventServer: stop the monitor to receive netlink messages for libvirtd
 */
68
int virNetlinkEventServiceStop(unsigned int protocol);
69

70 71 72 73 74
/**
 * stopNetlinkEventServerAll: stop all the monitors to receive netlink messages for libvirtd
 */
int virNetlinkEventServiceStopAll(void);

75 76 77
/**
 * startNetlinkEventServer: start a monitor to receive netlink messages for libvirtd
 */
78
int virNetlinkEventServiceStart(unsigned int protocol, unsigned int groups);
79 80 81 82

/**
 * virNetlinkEventServiceIsRunning: returns if the netlink event service is running.
 */
83
bool virNetlinkEventServiceIsRunning(unsigned int protocol);
84

85 86 87
/**
 * virNetlinkEventServiceLocalPid: returns nl_pid used to bind() netlink socket
 */
88
int virNetlinkEventServiceLocalPid(unsigned int protocol);
89

90 91 92 93 94
/**
 * virNetlinkEventAddClient: register a callback for handling of netlink messages
 */
int virNetlinkEventAddClient(virNetlinkEventHandleCallback handleCB,
                             virNetlinkEventRemoveCallback removeCB,
95
                             void *opaque, const virMacAddr *macaddr,
96
                             unsigned int protocol);
97 98 99 100

/**
 * virNetlinkEventRemoveClient: unregister a callback from a netlink monitor
 */
101
int virNetlinkEventRemoveClient(int watch, const virMacAddr *macaddr,
102
                                unsigned int protocol);
103

104
#endif /* __VIR_NETLINK_H__ */