cleanup: remove libnl dependency from nm-ip4-config/nm-ip6-config
This commit is contained in:
@@ -29,11 +29,6 @@
|
|||||||
#include "nm-setting-ip4-config.h"
|
#include "nm-setting-ip4-config.h"
|
||||||
#include "nm-platform.h"
|
#include "nm-platform.h"
|
||||||
#include "nm-utils.h"
|
#include "nm-utils.h"
|
||||||
|
|
||||||
#include <netlink/route/addr.h>
|
|
||||||
#include <netlink/utils.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
|
|
||||||
#include "nm-ip4-config-glue.h"
|
#include "nm-ip4-config-glue.h"
|
||||||
#include "nm-dbus-glib-types.h"
|
#include "nm-dbus-glib-types.h"
|
||||||
|
|
||||||
@@ -78,20 +73,6 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static struct nl_addr *
|
|
||||||
nm_utils_ip4_addr_to_nl_addr (guint32 ip4_addr)
|
|
||||||
{
|
|
||||||
struct nl_addr * nla = NULL;
|
|
||||||
|
|
||||||
if (!(nla = nl_addr_alloc (sizeof (in_addr_t))))
|
|
||||||
return NULL;
|
|
||||||
nl_addr_set_family (nla, AF_INET);
|
|
||||||
nl_addr_set_binary_addr (nla, &ip4_addr, sizeof (guint32));
|
|
||||||
|
|
||||||
return nla;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NMIP4Config *
|
NMIP4Config *
|
||||||
nm_ip4_config_new (void)
|
nm_ip4_config_new (void)
|
||||||
{
|
{
|
||||||
@@ -631,95 +612,6 @@ nm_ip4_config_get_nis_domain (NMIP4Config *config)
|
|||||||
return NM_IP4_CONFIG_GET_PRIVATE (config)->nis_domain;
|
return NM_IP4_CONFIG_GET_PRIVATE (config)->nis_domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* libnl convenience/conversion functions */
|
|
||||||
|
|
||||||
static int ip4_addr_to_rtnl_local (guint32 ip4_address, struct rtnl_addr *addr)
|
|
||||||
{
|
|
||||||
struct nl_addr * local = NULL;
|
|
||||||
int err = 0;
|
|
||||||
|
|
||||||
g_return_val_if_fail (addr != NULL, -1);
|
|
||||||
|
|
||||||
local = nm_utils_ip4_addr_to_nl_addr (ip4_address);
|
|
||||||
err = rtnl_addr_set_local (addr, local);
|
|
||||||
nl_addr_put (local);
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ip4_addr_to_rtnl_peer (guint32 ip4_address, struct rtnl_addr *addr)
|
|
||||||
{
|
|
||||||
struct nl_addr * peer = NULL;
|
|
||||||
int err = 0;
|
|
||||||
|
|
||||||
g_return_val_if_fail (addr != NULL, -1);
|
|
||||||
|
|
||||||
peer = nm_utils_ip4_addr_to_nl_addr (ip4_address);
|
|
||||||
err = rtnl_addr_set_peer (addr, peer);
|
|
||||||
nl_addr_put (peer);
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ip4_addr_to_rtnl_broadcast (guint32 ip4_broadcast, struct rtnl_addr *addr)
|
|
||||||
{
|
|
||||||
struct nl_addr * local = NULL;
|
|
||||||
int err = 0;
|
|
||||||
|
|
||||||
g_return_val_if_fail (addr != NULL, -1);
|
|
||||||
|
|
||||||
local = nm_utils_ip4_addr_to_nl_addr (ip4_broadcast);
|
|
||||||
err = rtnl_addr_set_broadcast (addr, local);
|
|
||||||
nl_addr_put (local);
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct rtnl_addr *
|
|
||||||
nm_ip4_config_to_rtnl_addr (NMIP4Config *config, guint32 i, guint32 flags)
|
|
||||||
{
|
|
||||||
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
||||||
NMIP4Address *config_addr;
|
|
||||||
struct rtnl_addr *addr;
|
|
||||||
gboolean success = TRUE;
|
|
||||||
|
|
||||||
g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
|
|
||||||
|
|
||||||
config_addr = nm_ip4_config_get_address (config, i);
|
|
||||||
g_return_val_if_fail (config_addr != NULL, NULL);
|
|
||||||
|
|
||||||
if (!(addr = rtnl_addr_alloc()))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (flags & NM_RTNL_ADDR_ADDR)
|
|
||||||
success = (ip4_addr_to_rtnl_local (nm_ip4_address_get_address (config_addr), addr) >= 0);
|
|
||||||
|
|
||||||
if (flags & NM_RTNL_ADDR_PTP_ADDR)
|
|
||||||
success = (ip4_addr_to_rtnl_peer (priv->ptp_address, addr) >= 0);
|
|
||||||
|
|
||||||
if (flags & NM_RTNL_ADDR_PREFIX)
|
|
||||||
rtnl_addr_set_prefixlen (addr, nm_ip4_address_get_prefix (config_addr));
|
|
||||||
|
|
||||||
if (flags & NM_RTNL_ADDR_BROADCAST) {
|
|
||||||
guint32 hostmask, network, bcast, netmask;
|
|
||||||
|
|
||||||
netmask = nm_utils_ip4_prefix_to_netmask (nm_ip4_address_get_prefix (config_addr));
|
|
||||||
network = ntohl (nm_ip4_address_get_address (config_addr)) & ntohl (netmask);
|
|
||||||
hostmask = ~ntohl (netmask);
|
|
||||||
bcast = htonl (network | hostmask);
|
|
||||||
|
|
||||||
success = (ip4_addr_to_rtnl_broadcast (bcast, addr) >= 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!success) {
|
|
||||||
rtnl_addr_put (addr);
|
|
||||||
addr = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
addr_slist_compare (GSList *a, GSList *b)
|
addr_slist_compare (GSList *a, GSList *b)
|
||||||
{
|
{
|
||||||
|
@@ -111,19 +111,6 @@ void nm_ip4_config_reset_nis_servers (NMIP4Config *config);
|
|||||||
void nm_ip4_config_set_nis_domain (NMIP4Config *config, const char *domain);
|
void nm_ip4_config_set_nis_domain (NMIP4Config *config, const char *domain);
|
||||||
const char * nm_ip4_config_get_nis_domain (NMIP4Config *config);
|
const char * nm_ip4_config_get_nis_domain (NMIP4Config *config);
|
||||||
|
|
||||||
|
|
||||||
/* Flags for nm_ip4_config_to_rtnl_addr() */
|
|
||||||
#define NM_RTNL_ADDR_NONE 0x0000
|
|
||||||
#define NM_RTNL_ADDR_ADDR 0x0001
|
|
||||||
#define NM_RTNL_ADDR_PTP_ADDR 0x0002
|
|
||||||
#define NM_RTNL_ADDR_PREFIX 0x0004
|
|
||||||
#define NM_RTNL_ADDR_BROADCAST 0x0008
|
|
||||||
|
|
||||||
#define NM_RTNL_ADDR_DEFAULT (NM_RTNL_ADDR_ADDR | NM_RTNL_ADDR_PREFIX | NM_RTNL_ADDR_BROADCAST)
|
|
||||||
#define NM_RTNL_ADDR_PTP_DEFAULT (NM_RTNL_ADDR_ADDR | NM_RTNL_ADDR_PREFIX | NM_RTNL_ADDR_PTP_ADDR)
|
|
||||||
|
|
||||||
struct rtnl_addr *nm_ip4_config_to_rtnl_addr (NMIP4Config *config, guint32 i, guint32 flags);
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
NM_IP4_COMPARE_FLAG_NONE = 0x00000000, /* match nothing, kinda pointless */
|
NM_IP4_COMPARE_FLAG_NONE = 0x00000000, /* match nothing, kinda pointless */
|
||||||
NM_IP4_COMPARE_FLAG_ADDRESSES = 0x00000001,
|
NM_IP4_COMPARE_FLAG_ADDRESSES = 0x00000001,
|
||||||
|
@@ -29,11 +29,6 @@
|
|||||||
#include "nm-setting-ip6-config.h"
|
#include "nm-setting-ip6-config.h"
|
||||||
#include "nm-platform.h"
|
#include "nm-platform.h"
|
||||||
#include "nm-utils.h"
|
#include "nm-utils.h"
|
||||||
|
|
||||||
#include <netlink/route/addr.h>
|
|
||||||
#include <netlink/utils.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
|
|
||||||
#include "nm-ip6-config-glue.h"
|
#include "nm-ip6-config-glue.h"
|
||||||
#include "nm-dbus-glib-types.h"
|
#include "nm-dbus-glib-types.h"
|
||||||
|
|
||||||
@@ -73,22 +68,6 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static struct nl_addr *
|
|
||||||
nm_utils_ip6_addr_to_nl_addr (const struct in6_addr *ip6_addr, guint prefix)
|
|
||||||
{
|
|
||||||
struct nl_addr * nla = NULL;
|
|
||||||
|
|
||||||
if (!(nla = nl_addr_alloc (sizeof (struct in6_addr))))
|
|
||||||
return NULL;
|
|
||||||
nl_addr_set_family (nla, AF_INET6);
|
|
||||||
nl_addr_set_binary_addr (nla, (struct in6_addr *)ip6_addr, sizeof (struct in6_addr));
|
|
||||||
if (prefix)
|
|
||||||
nl_addr_set_prefixlen (nla, prefix);
|
|
||||||
|
|
||||||
return nla;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NMIP6Config *
|
NMIP6Config *
|
||||||
nm_ip6_config_new (void)
|
nm_ip6_config_new (void)
|
||||||
{
|
{
|
||||||
@@ -506,74 +485,6 @@ nm_ip6_config_set_never_default (NMIP6Config *config, gboolean never_default)
|
|||||||
NM_IP6_CONFIG_GET_PRIVATE (config)->never_default = never_default;
|
NM_IP6_CONFIG_GET_PRIVATE (config)->never_default = never_default;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* libnl convenience/conversion functions */
|
|
||||||
|
|
||||||
static int ip6_addr_to_rtnl_local (const struct in6_addr *ip6_address,
|
|
||||||
struct rtnl_addr *addr,
|
|
||||||
guint prefix)
|
|
||||||
{
|
|
||||||
struct nl_addr * local = NULL;
|
|
||||||
int err = 0;
|
|
||||||
|
|
||||||
g_return_val_if_fail (addr != NULL, -1);
|
|
||||||
|
|
||||||
local = nm_utils_ip6_addr_to_nl_addr (ip6_address, prefix);
|
|
||||||
err = rtnl_addr_set_local (addr, local);
|
|
||||||
nl_addr_put (local);
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ip6_addr_to_rtnl_peer (const struct in6_addr *ip6_address, struct rtnl_addr *addr)
|
|
||||||
{
|
|
||||||
struct nl_addr * peer = NULL;
|
|
||||||
int err = 0;
|
|
||||||
|
|
||||||
g_return_val_if_fail (addr != NULL, -1);
|
|
||||||
|
|
||||||
peer = nm_utils_ip6_addr_to_nl_addr (ip6_address, 0);
|
|
||||||
err = rtnl_addr_set_peer (addr, peer);
|
|
||||||
nl_addr_put (peer);
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct rtnl_addr *
|
|
||||||
nm_ip6_config_to_rtnl_addr (NMIP6Config *config, guint32 i, guint32 flags)
|
|
||||||
{
|
|
||||||
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config);
|
|
||||||
NMIP6Address *config_addr;
|
|
||||||
struct rtnl_addr *addr;
|
|
||||||
gboolean success = TRUE;
|
|
||||||
|
|
||||||
g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL);
|
|
||||||
|
|
||||||
config_addr = nm_ip6_config_get_address (config, i);
|
|
||||||
g_return_val_if_fail (config_addr != NULL, NULL);
|
|
||||||
|
|
||||||
if (!(addr = rtnl_addr_alloc()))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (flags & NM_RTNL_ADDR_ADDR) {
|
|
||||||
success = (ip6_addr_to_rtnl_local (nm_ip6_address_get_address (config_addr),
|
|
||||||
addr,
|
|
||||||
nm_ip6_address_get_prefix (config_addr)) >= 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & NM_RTNL_ADDR_PTP_ADDR)
|
|
||||||
success = (ip6_addr_to_rtnl_peer (&priv->ptp_address, addr) >= 0);
|
|
||||||
|
|
||||||
if (flags & NM_RTNL_ADDR_PREFIX)
|
|
||||||
rtnl_addr_set_prefixlen (addr, nm_ip6_address_get_prefix (config_addr));
|
|
||||||
|
|
||||||
if (!success) {
|
|
||||||
rtnl_addr_put (addr);
|
|
||||||
addr = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
addr_slist_compare (GSList *a, GSList *b)
|
addr_slist_compare (GSList *a, GSList *b)
|
||||||
{
|
{
|
||||||
|
@@ -95,18 +95,6 @@ void nm_ip6_config_set_mss (NMIP6Config *config, guint32 ms
|
|||||||
gboolean nm_ip6_config_get_never_default (NMIP6Config *config);
|
gboolean nm_ip6_config_get_never_default (NMIP6Config *config);
|
||||||
void nm_ip6_config_set_never_default (NMIP6Config *config, gboolean never_default);
|
void nm_ip6_config_set_never_default (NMIP6Config *config, gboolean never_default);
|
||||||
|
|
||||||
/* Flags for nm_ip6_config_to_rtnl_addr() */
|
|
||||||
#define NM_RTNL_ADDR_NONE 0x0000
|
|
||||||
#define NM_RTNL_ADDR_ADDR 0x0001
|
|
||||||
#define NM_RTNL_ADDR_PTP_ADDR 0x0002
|
|
||||||
#define NM_RTNL_ADDR_PREFIX 0x0004
|
|
||||||
#define NM_RTNL_ADDR_BROADCAST 0x0008
|
|
||||||
|
|
||||||
#define NM_RTNL_ADDR_DEFAULT (NM_RTNL_ADDR_ADDR | NM_RTNL_ADDR_PREFIX | NM_RTNL_ADDR_BROADCAST)
|
|
||||||
#define NM_RTNL_ADDR_PTP_DEFAULT (NM_RTNL_ADDR_ADDR | NM_RTNL_ADDR_PREFIX | NM_RTNL_ADDR_PTP_ADDR)
|
|
||||||
|
|
||||||
struct rtnl_addr *nm_ip6_config_to_rtnl_addr (NMIP6Config *config, guint32 i, guint32 flags);
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
NM_IP6_COMPARE_FLAG_NONE = 0x00000000, /* match nothing, kinda pointless */
|
NM_IP6_COMPARE_FLAG_NONE = 0x00000000, /* match nothing, kinda pointless */
|
||||||
NM_IP6_COMPARE_FLAG_ADDRESSES = 0x00000001,
|
NM_IP6_COMPARE_FLAG_ADDRESSES = 0x00000001,
|
||||||
|
Reference in New Issue
Block a user