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"
|
2016-06-13 21:01:27 +00:00
|
|
|
|
2017-03-06 17:39:48 +00:00
|
|
|
typedef struct _virNetDevIPAddr virNetDevIPAddr;
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
struct _virNetDevIPInfo {
|
2016-06-06 19:19:23 +00:00
|
|
|
size_t nips;
|
2021-03-11 07:16:13 +00:00
|
|
|
virNetDevIPAddr **ips;
|
2016-06-06 19:19:23 +00:00
|
|
|
size_t nroutes;
|
2021-03-11 07:16:13 +00:00
|
|
|
virNetDevIPRoute **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)
|
2019-10-15 11:24:34 +00:00
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT G_GNUC_NO_INLINE;
|
2016-06-13 21:01:27 +00:00
|
|
|
int virNetDevIPRouteAdd(const char *ifname,
|
2021-03-11 07:16:13 +00:00
|
|
|
virSocketAddr *addr,
|
2016-06-13 21:01:27 +00:00
|
|
|
unsigned int prefix,
|
2021-03-11 07:16:13 +00:00
|
|
|
virSocketAddr *gateway,
|
2016-06-13 21:01:27 +00:00
|
|
|
unsigned int metric)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4)
|
2019-10-14 12:25:14 +00:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT;
|
2016-06-13 21:01:27 +00:00
|
|
|
int virNetDevIPAddrDel(const char *ifname,
|
|
|
|
virSocketAddr *addr,
|
|
|
|
unsigned int prefix)
|
2019-10-14 12:25:14 +00:00
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
|
2021-03-11 07:16:13 +00:00
|
|
|
int virNetDevIPAddrGet(const char *ifname, virSocketAddr *addr)
|
2019-10-14 12:25:14 +00:00
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
|
2017-03-03 13:14:51 +00:00
|
|
|
bool virNetDevIPCheckIPv6Forwarding(void);
|
2021-03-11 07:16:13 +00:00
|
|
|
void virNetDevIPAddrFree(virNetDevIPAddr *ip);
|
2016-06-13 21:01:27 +00:00
|
|
|
|
2016-06-14 17:40:04 +00:00
|
|
|
/* virNetDevIPRoute object */
|
2021-03-11 07:16:13 +00:00
|
|
|
void virNetDevIPRouteFree(virNetDevIPRoute *def);
|
|
|
|
virSocketAddr *virNetDevIPRouteGetAddress(virNetDevIPRoute *def);
|
|
|
|
int virNetDevIPRouteGetPrefix(virNetDevIPRoute *def);
|
|
|
|
unsigned int virNetDevIPRouteGetMetric(virNetDevIPRoute *def);
|
|
|
|
virSocketAddr *virNetDevIPRouteGetGateway(virNetDevIPRoute *def);
|
2016-06-14 17:40:04 +00:00
|
|
|
|
2016-06-06 19:19:23 +00:00
|
|
|
/* virNetDevIPInfo object */
|
2021-03-11 07:16:13 +00:00
|
|
|
void virNetDevIPInfoClear(virNetDevIPInfo *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-10-15 12:47:50 +00:00
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetDevIPAddr, virNetDevIPAddrFree);
|
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetDevIPRoute, virNetDevIPRouteFree);
|