2016-06-13 21:01:27 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007-2016 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2019-06-18 16:12:48 +00:00
|
|
|
#pragma once
|
2016-06-13 21:01:27 +00:00
|
|
|
|
2019-06-18 16:12:48 +00:00
|
|
|
#include "virsocketaddr.h"
|
|
|
|
#include "virautoclean.h"
|
2016-06-13 21:01:27 +00:00
|
|
|
|
2017-03-06 17:39:48 +00:00
|
|
|
typedef struct _virNetDevIPAddr virNetDevIPAddr;
|
|
|
|
typedef virNetDevIPAddr *virNetDevIPAddrPtr;
|
|
|
|
struct _virNetDevIPAddr {
|
2016-04-04 21:00:03 +00:00
|
|
|
virSocketAddr address; /* ipv4 or ipv6 address */
|
|
|
|
virSocketAddr peer; /* ipv4 or ipv6 address of peer */
|
|
|
|
unsigned int prefix; /* number of 1 bits in the netmask */
|
2017-03-06 17:39:48 +00:00
|
|
|
};
|
2016-06-14 17:40:04 +00:00
|
|
|
|
2017-03-06 17:39:48 +00:00
|
|
|
typedef struct _virNetDevIPRoute virNetDevIPRoute;
|
|
|
|
typedef virNetDevIPRoute *virNetDevIPRoutePtr;
|
|
|
|
struct _virNetDevIPRoute {
|
2016-06-14 17:40:04 +00:00
|
|
|
char *family; /* ipv4 or ipv6 - default is ipv4 */
|
|
|
|
virSocketAddr address; /* Routed Network IP address */
|
|
|
|
|
|
|
|
/* One or the other of the following two will be used for a given
|
|
|
|
* Network address, but never both. The parser guarantees this.
|
|
|
|
* The virSocketAddrGetIPPrefix() can be used to get a
|
|
|
|
* valid prefix.
|
|
|
|
*/
|
|
|
|
virSocketAddr netmask; /* ipv4 - either netmask or prefix specified */
|
|
|
|
unsigned int prefix; /* ipv6 - only prefix allowed */
|
|
|
|
bool has_prefix; /* prefix= was specified */
|
|
|
|
unsigned int metric; /* value for metric (defaults to 1) */
|
|
|
|
bool has_metric; /* metric= was specified */
|
|
|
|
virSocketAddr gateway; /* gateway IP address for ip-route */
|
2017-03-06 17:39:48 +00:00
|
|
|
};
|
2016-06-14 17:40:04 +00:00
|
|
|
|
2016-06-06 19:19:23 +00:00
|
|
|
/* A full set of all IP config info for a network device */
|
2017-03-06 17:39:48 +00:00
|
|
|
typedef struct _virNetDevIPInfo virNetDevIPInfo;
|
|
|
|
typedef virNetDevIPInfo *virNetDevIPInfoPtr;
|
|
|
|
struct _virNetDevIPInfo {
|
2016-06-06 19:19:23 +00:00
|
|
|
size_t nips;
|
|
|
|
virNetDevIPAddrPtr *ips;
|
|
|
|
size_t nroutes;
|
|
|
|
virNetDevIPRoutePtr *routes;
|
2017-03-06 17:39:48 +00:00
|
|
|
};
|
2016-06-06 19:19:23 +00:00
|
|
|
|
2016-06-13 21:01:27 +00:00
|
|
|
/* manipulating/querying the netdev */
|
|
|
|
int virNetDevIPAddrAdd(const char *ifname,
|
|
|
|
virSocketAddr *addr,
|
|
|
|
virSocketAddr *peer,
|
|
|
|
unsigned int prefix)
|
2017-07-12 10:07:17 +00:00
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NOINLINE;
|
2016-06-13 21:01:27 +00:00
|
|
|
int virNetDevIPRouteAdd(const char *ifname,
|
|
|
|
virSocketAddrPtr addr,
|
|
|
|
unsigned int prefix,
|
|
|
|
virSocketAddrPtr gateway,
|
|
|
|
unsigned int metric)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4)
|
|
|
|
ATTRIBUTE_RETURN_CHECK;
|
|
|
|
int virNetDevIPAddrDel(const char *ifname,
|
|
|
|
virSocketAddr *addr,
|
|
|
|
unsigned int prefix)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
|
|
|
|
int virNetDevIPAddrGet(const char *ifname, virSocketAddrPtr addr)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
|
|
|
|
int virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, size_t count)
|
|
|
|
ATTRIBUTE_NONNULL(1);
|
2017-03-03 13:14:51 +00:00
|
|
|
bool virNetDevIPCheckIPv6Forwarding(void);
|
2018-07-28 18:01:26 +00:00
|
|
|
void virNetDevIPAddrFree(virNetDevIPAddrPtr ip);
|
2016-06-13 21:01:27 +00:00
|
|
|
|
2016-06-14 17:40:04 +00:00
|
|
|
/* virNetDevIPRoute object */
|
|
|
|
void virNetDevIPRouteFree(virNetDevIPRoutePtr def);
|
|
|
|
virSocketAddrPtr virNetDevIPRouteGetAddress(virNetDevIPRoutePtr def);
|
|
|
|
int virNetDevIPRouteGetPrefix(virNetDevIPRoutePtr def);
|
|
|
|
unsigned int virNetDevIPRouteGetMetric(virNetDevIPRoutePtr def);
|
|
|
|
virSocketAddrPtr virNetDevIPRouteGetGateway(virNetDevIPRoutePtr def);
|
|
|
|
|
2016-06-06 19:19:23 +00:00
|
|
|
/* virNetDevIPInfo object */
|
|
|
|
void virNetDevIPInfoClear(virNetDevIPInfoPtr ip);
|
2016-06-16 16:22:07 +00:00
|
|
|
int virNetDevIPInfoAddToDev(const char *ifname,
|
|
|
|
virNetDevIPInfo const *ipInfo);
|
2016-06-06 19:19:23 +00:00
|
|
|
|
2019-02-07 17:18:52 +00:00
|
|
|
VIR_DEFINE_AUTOPTR_FUNC(virNetDevIPAddr, virNetDevIPAddrFree);
|
|
|
|
VIR_DEFINE_AUTOPTR_FUNC(virNetDevIPRoute, virNetDevIPRouteFree);
|