mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-03 07:33:50 +00:00
commit 09778e09 switched from using ioctl(SIOCBRDELBR) for bridge device deletion to using a netlink RTM_DELLINK message, which is the more modern way to delete a bridge (and also doesn't require the bridge to be ~IFF_UP to succeed). However, although older kernels (e.g. 2.6.32, in RHEL6/CentOS6) support deleting *some* link types with RTM_NEWLINK, they don't support deleting bridges, and there is no compile-time way to figure this out. This patch moves the body of the SIOCBRDELBR version of virNetDevBridgeDelete() into a static function, calls the new function from the original, and also calls the new function from the RTM_DELLINK version if the RTM_DELLINK message generates an EOPNOTSUPP error. Since RTM_DELLINK is done from the subordinate function virNetlinkDelLink, which is also called for other purposes (deleting a macvtap interface), a function pointer called "fallback" has been added to the arglist of virNetlinkDelLink() - if that arg != NULL, the provided function will be called when (and only when) RTM_DELLINK fails with EOPNOTSUPP. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1252780 (part 2)
111 lines
3.6 KiB
C
111 lines
3.6 KiB
C
/*
|
|
* 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/>.
|
|
*/
|
|
|
|
#ifndef __VIR_NETLINK_H__
|
|
# define __VIR_NETLINK_H__
|
|
|
|
# include "internal.h"
|
|
# include "virmacaddr.h"
|
|
|
|
# if defined(__linux__) && defined(HAVE_LIBNL)
|
|
|
|
/* Work around a bug where older libnl-1 headers expected older gcc
|
|
* semantics of 'extern inline' that conflict with C99 semantics. */
|
|
# ifdef HAVE_LIBNL1
|
|
# define inline
|
|
# endif
|
|
# include <netlink/msg.h>
|
|
# ifdef HAVE_LIBNL1
|
|
# undef inline
|
|
# endif
|
|
|
|
# else
|
|
|
|
struct nl_msg;
|
|
struct sockaddr_nl;
|
|
struct nlattr;
|
|
struct nlmsghdr;
|
|
|
|
# endif /* __linux__ */
|
|
|
|
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 (*virNetlinkDelLinkFallback)(const char *ifname);
|
|
|
|
int virNetlinkDelLink(const char *ifname, virNetlinkDelLinkFallback fallback);
|
|
|
|
int virNetlinkGetErrorCode(struct nlmsghdr *resp, unsigned int recvbuflen);
|
|
|
|
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);
|
|
|
|
#endif /* __VIR_NETLINK_H__ */
|