mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-29 16:10:11 +01:00
rdisc: move public fields from NMRDisc to NMRDiscPrivate
As they are initialized from the constructor of the subclass, the have to be construct-only GObject properties, which brings some overhead.
This commit is contained in:
parent
322299617f
commit
c9c00ec5c6
6 changed files with 133 additions and 40 deletions
|
|
@ -359,7 +359,7 @@ gboolean nm_utils_get_ipv6_interface_identifier (NMLinkType link_type,
|
|||
guint dev_id,
|
||||
NMUtilsIPv6IfaceId *out_iid);
|
||||
|
||||
typedef enum {
|
||||
typedef enum { /*< skip >*/
|
||||
NM_UTILS_STABLE_TYPE_UUID = 0,
|
||||
NM_UTILS_STABLE_TYPE_STABLE_ID = 1,
|
||||
} NMUtilsStableType;
|
||||
|
|
|
|||
|
|
@ -344,10 +344,13 @@ nm_fake_rdisc_emit_new_ras (NMFakeRDisc *self)
|
|||
NMRDisc *
|
||||
nm_fake_rdisc_new (int ifindex, const char *ifname)
|
||||
{
|
||||
NMRDisc *rdisc = g_object_new (NM_TYPE_FAKE_RDISC, NULL);
|
||||
NMRDisc *rdisc;
|
||||
|
||||
rdisc = g_object_new (NM_TYPE_FAKE_RDISC,
|
||||
NM_RDISC_IFINDEX, ifindex,
|
||||
NM_RDISC_IFNAME, ifname,
|
||||
NULL);
|
||||
|
||||
rdisc->ifindex = ifindex;
|
||||
rdisc->ifname = g_strdup (ifname);
|
||||
rdisc->max_addresses = NM_RDISC_MAX_ADDRESSES_DEFAULT;
|
||||
rdisc->rtr_solicitations = NM_RDISC_RTR_SOLICITATIONS_DEFAULT;
|
||||
rdisc->rtr_solicitation_interval = NM_RDISC_RTR_SOLICITATION_INTERVAL_DEFAULT;
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ send_rs (NMRDisc *rdisc, GError **error)
|
|||
"cannot create router solicitation");
|
||||
return FALSE;
|
||||
}
|
||||
ndp_msg_ifindex_set (msg, rdisc->ifindex);
|
||||
ndp_msg_ifindex_set (msg, nm_rdisc_get_ifindex (rdisc));
|
||||
|
||||
errsv = ndp_msg_send (priv->ndp, msg);
|
||||
ndp_msg_destroy (msg);
|
||||
|
|
@ -332,7 +332,7 @@ start (NMRDisc *rdisc)
|
|||
/* Flush any pending messages to avoid using obsolete information */
|
||||
event_ready (priv->event_channel, 0, rdisc);
|
||||
|
||||
ndp_msgrcv_handler_register (priv->ndp, receive_ra, NDP_MSG_RA, rdisc->ifindex, rdisc);
|
||||
ndp_msgrcv_handler_register (priv->ndp, receive_ra, NDP_MSG_RA, nm_rdisc_get_ifindex (rdisc), rdisc);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
@ -372,14 +372,13 @@ nm_lndp_rdisc_new (NMPlatform *platform,
|
|||
|
||||
rdisc = g_object_new (NM_TYPE_LNDP_RDISC,
|
||||
NM_RDISC_PLATFORM, platform,
|
||||
NM_RDISC_STABLE_TYPE, (int) stable_type,
|
||||
NM_RDISC_IFINDEX, ifindex,
|
||||
NM_RDISC_IFNAME, ifname,
|
||||
NM_RDISC_NETWORK_ID, network_id,
|
||||
NM_RDISC_ADDR_GEN_MODE, (int) addr_gen_mode,
|
||||
NULL);
|
||||
|
||||
rdisc->ifindex = ifindex;
|
||||
rdisc->ifname = g_strdup (ifname);
|
||||
rdisc->stable_type = stable_type;
|
||||
rdisc->network_id = g_strdup (network_id);
|
||||
rdisc->addr_gen_mode = addr_gen_mode;
|
||||
|
||||
rdisc->max_addresses = ipv6_sysctl_get (platform, ifname, "max_addresses",
|
||||
NM_RDISC_MAX_ADDRESSES_DEFAULT);
|
||||
rdisc->rtr_solicitations = ipv6_sysctl_get (platform, ifname, "router_solicitations",
|
||||
|
|
@ -405,14 +404,14 @@ nm_lndp_rdisc_new (NMPlatform *platform,
|
|||
static void
|
||||
dispose (GObject *object)
|
||||
{
|
||||
NMLndpRDisc *rdisc = NM_LNDP_RDISC (object);
|
||||
NMLndpRDiscPrivate *priv = NM_LNDP_RDISC_GET_PRIVATE (rdisc);
|
||||
NMRDisc *rdisc = (NMRDisc *) object;
|
||||
NMLndpRDiscPrivate *priv = NM_LNDP_RDISC_GET_PRIVATE ((NMLndpRDisc *) rdisc);
|
||||
|
||||
nm_clear_g_source (&priv->event_id);
|
||||
g_clear_pointer (&priv->event_channel, g_io_channel_unref);
|
||||
|
||||
if (priv->ndp) {
|
||||
ndp_msgrcv_handler_unregister (priv->ndp, receive_ra, NDP_MSG_RA, NM_RDISC (rdisc)->ifindex, rdisc);
|
||||
ndp_msgrcv_handler_unregister (priv->ndp, receive_ra, NDP_MSG_RA, nm_rdisc_get_ifindex (rdisc), rdisc);
|
||||
ndp_close (priv->ndp);
|
||||
priv->ndp = NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,19 +44,20 @@ gboolean nm_rdisc_add_dns_domain (NMRDisc *rdisc, const NMRDiscDNSDoma
|
|||
const NMLogDomain __domain = (domain); \
|
||||
\
|
||||
if (nm_logging_enabled (__level, __domain)) { \
|
||||
NMRDisc *const __self = (self); \
|
||||
char __prefix[64]; \
|
||||
const char *__p_prefix = _NMLOG_PREFIX_NAME; \
|
||||
const NMRDisc *const __self = (self); \
|
||||
\
|
||||
if (__self) { \
|
||||
g_snprintf (__prefix, sizeof (__prefix), "%s[%p,%s%s%s]", \
|
||||
_NMLOG_PREFIX_NAME, __self, \
|
||||
NM_PRINT_FMT_QUOTE_STRING (__self->ifname)); \
|
||||
__p_prefix = __prefix; \
|
||||
} \
|
||||
_nm_log (__level, __domain, 0, \
|
||||
"%s: " _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \
|
||||
__p_prefix _NM_UTILS_MACRO_REST (__VA_ARGS__)); \
|
||||
(__self \
|
||||
? ({ \
|
||||
const char *__ifname = nm_rdisc_get_ifname (__self); \
|
||||
nm_sprintf_buf (__prefix, "%s[%p,%s%s%s]", \
|
||||
_NMLOG_PREFIX_NAME, __self, \
|
||||
NM_PRINT_FMT_QUOTE_STRING (__ifname)); \
|
||||
}) \
|
||||
: _NMLOG_PREFIX_NAME) \
|
||||
_NM_UTILS_MACRO_REST (__VA_ARGS__)); \
|
||||
} \
|
||||
} G_STMT_END
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,12 @@ struct _NMRDiscPrivate {
|
|||
guint timeout_id; /* prefix/dns/etc lifetime timeout */
|
||||
char *last_send_rs_error;
|
||||
|
||||
int ifindex;
|
||||
char *ifname;
|
||||
char *network_id;
|
||||
NMSettingIP6ConfigAddrGenMode addr_gen_mode;
|
||||
NMUtilsStableType stable_type;
|
||||
|
||||
NMPlatform *platform;
|
||||
NMPNetns *netns;
|
||||
};
|
||||
|
|
@ -53,6 +59,11 @@ typedef struct _NMRDiscPrivate NMRDiscPrivate;
|
|||
|
||||
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
|
||||
PROP_PLATFORM,
|
||||
PROP_IFINDEX,
|
||||
PROP_IFNAME,
|
||||
PROP_STABLE_TYPE,
|
||||
PROP_NETWORK_ID,
|
||||
PROP_ADDR_GEN_MODE,
|
||||
);
|
||||
|
||||
enum {
|
||||
|
|
@ -106,7 +117,25 @@ nm_rdisc_netns_push (NMRDisc *self, NMPNetns **netns)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
int
|
||||
nm_rdisc_get_ifindex (NMRDisc *self)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_RDISC (self), 0);
|
||||
|
||||
return NM_RDISC_GET_PRIVATE (self)->ifindex;
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_rdisc_get_ifname (NMRDisc *self)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_RDISC (self), NULL);
|
||||
|
||||
return NM_RDISC_GET_PRIVATE (self)->ifname;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
gboolean
|
||||
nm_rdisc_add_gateway (NMRDisc *rdisc, const NMRDiscGateway *new)
|
||||
|
|
@ -158,13 +187,17 @@ nm_rdisc_add_gateway (NMRDisc *rdisc, const NMRDiscGateway *new)
|
|||
static gboolean
|
||||
complete_address (NMRDisc *rdisc, NMRDiscAddress *addr)
|
||||
{
|
||||
NMRDiscPrivate *priv;
|
||||
GError *error = NULL;
|
||||
|
||||
if (rdisc->addr_gen_mode == NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY) {
|
||||
if (!nm_utils_ipv6_addr_set_stable_privacy (rdisc->stable_type,
|
||||
g_return_val_if_fail (NM_IS_RDISC (rdisc), FALSE);
|
||||
|
||||
priv = NM_RDISC_GET_PRIVATE (rdisc);
|
||||
if (priv->addr_gen_mode == NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY) {
|
||||
if (!nm_utils_ipv6_addr_set_stable_privacy (priv->stable_type,
|
||||
&addr->address,
|
||||
rdisc->ifname,
|
||||
rdisc->network_id,
|
||||
priv->ifname,
|
||||
priv->network_id,
|
||||
addr->dad_counter++,
|
||||
&error)) {
|
||||
_LOGW ("complete-address: failed to generate an stable-privacy address: %s",
|
||||
|
|
@ -351,12 +384,15 @@ nm_rdisc_add_dns_domain (NMRDisc *rdisc, const NMRDiscDNSDomain *new)
|
|||
gboolean
|
||||
nm_rdisc_set_iid (NMRDisc *rdisc, const NMUtilsIPv6IfaceId iid)
|
||||
{
|
||||
NMRDiscPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (NM_IS_RDISC (rdisc), FALSE);
|
||||
|
||||
if (rdisc->iid.id != iid.id) {
|
||||
rdisc->iid = iid;
|
||||
|
||||
if (rdisc->addr_gen_mode == NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY)
|
||||
priv = NM_RDISC_GET_PRIVATE (rdisc);
|
||||
if (priv->addr_gen_mode == NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY)
|
||||
return FALSE;
|
||||
|
||||
if (rdisc->addresses->len) {
|
||||
|
|
@ -450,7 +486,7 @@ nm_rdisc_start (NMRDisc *rdisc)
|
|||
|
||||
g_assert (klass->start);
|
||||
|
||||
_LOGD ("starting router discovery: %d", rdisc->ifindex);
|
||||
_LOGD ("starting router discovery: %d", priv->ifindex);
|
||||
|
||||
if (!nm_rdisc_netns_push (rdisc, &netns))
|
||||
return;
|
||||
|
|
@ -756,6 +792,28 @@ set_property (GObject *object, guint prop_id,
|
|||
|
||||
g_return_if_fail (!priv->netns || priv->netns == nmp_netns_get_current ());
|
||||
break;
|
||||
case PROP_IFINDEX:
|
||||
/* construct-only */
|
||||
priv->ifindex = g_value_get_int (value);
|
||||
g_return_if_fail (priv->ifindex > 0);
|
||||
break;
|
||||
case PROP_IFNAME:
|
||||
/* construct-only */
|
||||
priv->ifname = g_value_dup_string (value);
|
||||
g_return_if_fail (priv->ifname && priv->ifname[0]);
|
||||
break;
|
||||
case PROP_STABLE_TYPE:
|
||||
/* construct-only */
|
||||
priv->stable_type = g_value_get_int (value);
|
||||
break;
|
||||
case PROP_NETWORK_ID:
|
||||
/* construct-only */
|
||||
priv->network_id = g_value_dup_string (value);
|
||||
break;
|
||||
case PROP_ADDR_GEN_MODE:
|
||||
/* construct-only */
|
||||
priv->addr_gen_mode = g_value_get_int (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
|
|
@ -805,8 +863,9 @@ finalize (GObject *object)
|
|||
NMRDisc *rdisc = NM_RDISC (object);
|
||||
NMRDiscPrivate *priv = NM_RDISC_GET_PRIVATE (rdisc);
|
||||
|
||||
g_free (rdisc->ifname);
|
||||
g_free (rdisc->network_id);
|
||||
g_free (priv->ifname);
|
||||
g_free (priv->network_id);
|
||||
|
||||
g_array_unref (rdisc->gateways);
|
||||
g_array_unref (rdisc->addresses);
|
||||
g_array_unref (rdisc->routes);
|
||||
|
|
@ -837,6 +896,36 @@ nm_rdisc_class_init (NMRDiscClass *klass)
|
|||
G_PARAM_WRITABLE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
obj_properties[PROP_IFINDEX] =
|
||||
g_param_spec_int (NM_RDISC_IFINDEX, "", "",
|
||||
0, G_MAXINT, 0,
|
||||
G_PARAM_WRITABLE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
obj_properties[PROP_IFNAME] =
|
||||
g_param_spec_string (NM_RDISC_IFNAME, "", "",
|
||||
NULL,
|
||||
G_PARAM_WRITABLE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
obj_properties[PROP_STABLE_TYPE] =
|
||||
g_param_spec_int (NM_RDISC_STABLE_TYPE, "", "",
|
||||
NM_UTILS_STABLE_TYPE_UUID, NM_UTILS_STABLE_TYPE_STABLE_ID, NM_UTILS_STABLE_TYPE_UUID,
|
||||
G_PARAM_WRITABLE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
obj_properties[PROP_NETWORK_ID] =
|
||||
g_param_spec_string (NM_RDISC_NETWORK_ID, "", "",
|
||||
NULL,
|
||||
G_PARAM_WRITABLE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
obj_properties[PROP_ADDR_GEN_MODE] =
|
||||
g_param_spec_int (NM_RDISC_ADDR_GEN_MODE, "", "",
|
||||
NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64, NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY, NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64,
|
||||
G_PARAM_WRITABLE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
|
||||
|
||||
signals[CONFIG_CHANGED] =
|
||||
|
|
|
|||
|
|
@ -35,6 +35,11 @@
|
|||
#define NM_RDISC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_RDISC, NMRDiscClass))
|
||||
|
||||
#define NM_RDISC_PLATFORM "platform"
|
||||
#define NM_RDISC_IFINDEX "ifindex"
|
||||
#define NM_RDISC_IFNAME "ifname"
|
||||
#define NM_RDISC_NETWORK_ID "network-id"
|
||||
#define NM_RDISC_ADDR_GEN_MODE "addr-gen-mode"
|
||||
#define NM_RDISC_STABLE_TYPE "stable-type"
|
||||
#define NM_RDISC_CONFIG_CHANGED "config-changed"
|
||||
#define NM_RDISC_RA_TIMEOUT "ra-timeout"
|
||||
|
||||
|
|
@ -107,7 +112,6 @@ struct _NMRDiscPrivate;
|
|||
|
||||
/**
|
||||
* NMRDisc:
|
||||
* @ifindex: Interface index
|
||||
*
|
||||
* Interface-specific structure that handles incoming router advertisements,
|
||||
* caches advertised items and removes them when they are obsolete.
|
||||
|
|
@ -117,12 +121,6 @@ typedef struct {
|
|||
|
||||
struct _NMRDiscPrivate *_priv;
|
||||
|
||||
NMUtilsStableType stable_type;
|
||||
|
||||
int ifindex;
|
||||
char *ifname;
|
||||
char *network_id;
|
||||
NMSettingIP6ConfigAddrGenMode addr_gen_mode;
|
||||
NMUtilsIPv6IfaceId iid;
|
||||
gint32 max_addresses;
|
||||
gint32 rtr_solicitations;
|
||||
|
|
@ -150,6 +148,9 @@ typedef struct {
|
|||
|
||||
GType nm_rdisc_get_type (void);
|
||||
|
||||
int nm_rdisc_get_ifindex (NMRDisc *self);
|
||||
const char *nm_rdisc_get_ifname (NMRDisc *self);
|
||||
|
||||
gboolean nm_rdisc_set_iid (NMRDisc *rdisc, const NMUtilsIPv6IfaceId iid);
|
||||
void nm_rdisc_start (NMRDisc *rdisc);
|
||||
void nm_rdisc_dad_failed (NMRDisc *rdisc, struct in6_addr *address);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue