1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
/*
* Copyright (C) 2010-2013, 2015 Red Hat, Inc.
* Copyright (C) 2010-2012 IBM Corporation
*
* 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, see
* <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "internal.h"
#include "virmacaddr.h"
#if defined(WITH_LIBNL)
# include <netlink/msg.h>
typedef struct nl_msg virNetlinkMsg;
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetlinkMsg, nlmsg_free);
#else
struct nl_msg;
struct sockaddr_nl;
struct nlattr;
struct nlmsghdr;
#endif /* WITH_LIBNL */
int virNetlinkStartup(void);
void virNetlinkShutdown(void);
int virNetlinkCommand(struct nl_msg *nl_msg,
struct nlmsghdr **resp, unsigned int *respbuflen,
uint32_t src_pid, uint32_t dst_pid,
unsigned int protocol, unsigned int groups);
typedef int (*virNetlinkDumpCallback)(struct nlmsghdr *resp,
void *data);
int virNetlinkDumpCommand(struct nl_msg *nl_msg,
virNetlinkDumpCallback callback,
uint32_t src_pid, uint32_t dst_pid,
unsigned int protocol, unsigned int groups,
void *opaque);
typedef struct _virNetlinkNewLinkData virNetlinkNewLinkData;
typedef virNetlinkNewLinkData *virNetlinkNewLinkDataPtr;
struct _virNetlinkNewLinkData {
const int *ifindex; /* The index for the 'link' device */
const virMacAddr *mac; /* The MAC address of the device */
const uint32_t *macvlan_mode; /* The mode of macvlan */
const char *veth_peer; /* The peer name for veth */
};
int virNetlinkNewLink(const char *ifname,
const char *type,
virNetlinkNewLinkDataPtr data,
int *error);
typedef int (*virNetlinkTalkFallback)(const char *ifname);
int virNetlinkDelLink(const char *ifname, virNetlinkTalkFallback fallback);
int virNetlinkGetErrorCode(struct nlmsghdr *resp, unsigned int recvbuflen);
int virNetlinkDumpLink(const char *ifname, int ifindex,
void **nlData, struct nlattr **tb,
uint32_t src_pid, uint32_t dst_pid)
G_GNUC_WARN_UNUSED_RESULT;
int
virNetlinkGetNeighbor(void **nlData, uint32_t src_pid, uint32_t dst_pid);
typedef void (*virNetlinkEventHandleCallback)(struct nlmsghdr *,
unsigned int length,
struct sockaddr_nl *peer,
bool *handled,
void *opaque);
typedef void (*virNetlinkEventRemoveCallback)(int watch,
const virMacAddr *macaddr,
void *opaque);
/**
* stopNetlinkEventServer: stop the monitor to receive netlink messages for libvirtd
*/
int virNetlinkEventServiceStop(unsigned int protocol);
/**
* stopNetlinkEventServerAll: stop all the monitors to receive netlink messages for libvirtd
*/
int virNetlinkEventServiceStopAll(void);
/**
* startNetlinkEventServer: start a monitor to receive netlink messages for libvirtd
*/
int virNetlinkEventServiceStart(unsigned int protocol, unsigned int groups);
/**
* virNetlinkEventServiceIsRunning: returns if the netlink event service is running.
*/
bool virNetlinkEventServiceIsRunning(unsigned int protocol);
/**
* virNetlinkEventServiceLocalPid: returns nl_pid used to bind() netlink socket
*/
int virNetlinkEventServiceLocalPid(unsigned int protocol);
/**
* virNetlinkEventAddClient: register a callback for handling of netlink messages
*/
int virNetlinkEventAddClient(virNetlinkEventHandleCallback handleCB,
virNetlinkEventRemoveCallback removeCB,
void *opaque, const virMacAddr *macaddr,
unsigned int protocol);
/**
* virNetlinkEventRemoveClient: unregister a callback from a netlink monitor
*/
int virNetlinkEventRemoveClient(int watch, const virMacAddr *macaddr,
unsigned int protocol);
|