virnetlink.h 2.6 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 16 17 18 19
 *
 * 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 */

20 21 22
#ifndef __VIR_NETLINK_H__
# define __VIR_NETLINK_H__

23
# include "config.h"
24
# include "internal.h"
25

E
Eric Blake 已提交
26 27
# include <stdint.h>

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

#  include <netlink/msg.h>

# else

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

# endif /* __linux__ */

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

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

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
typedef void (*virNetlinkEventHandleCallback)(unsigned char *msg, int length, struct sockaddr_nl *peer, bool *handled, void *opaque);

typedef void (*virNetlinkEventRemoveCallback)(int watch, const unsigned char *macaddr, void *opaque);

/**
 * 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);

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

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

/**
 * virNetlinkEventRemoveClient: unregister a callback from a netlink monitor
 */
int virNetlinkEventRemoveClient(int watch, const unsigned char *macaddr);

83
#endif /* __VIR_NETLINK_H__ */