From c5a72405b65b08a6f5fc8d94c886749922e4caad Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 6 Jul 2016 11:28:35 +0200 Subject: rdisc: hide NMLndpRDisc struct and embed private data --- src/rdisc/nm-lndp-rdisc.c | 58 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 16 deletions(-) (limited to 'src/rdisc/nm-lndp-rdisc.c') diff --git a/src/rdisc/nm-lndp-rdisc.c b/src/rdisc/nm-lndp-rdisc.c index 47e41c9655..6f8105c559 100644 --- a/src/rdisc/nm-lndp-rdisc.c +++ b/src/rdisc/nm-lndp-rdisc.c @@ -20,21 +20,23 @@ #include "nm-default.h" +#include "nm-lndp-rdisc.h" + #include #include /* stdarg.h included because of a bug in ndp.h */ #include #include -#include "nm-lndp-rdisc.h" #include "nm-rdisc-private.h" - #include "NetworkManagerUtils.h" #include "nm-platform.h" #include "nmp-netns.h" #define _NMLOG_PREFIX_NAME "rdisc-lndp" +/*****************************************************************************/ + typedef struct { struct ndp *ndp; @@ -43,16 +45,40 @@ typedef struct { guint ra_timeout_id; /* first RA timeout */ } NMLndpRDiscPrivate; -#define NM_LNDP_RDISC_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_LNDP_RDISC, NMLndpRDiscPrivate)) +/*****************************************************************************/ + +struct _NMLndpRDisc { + NMRDisc parent; + NMLndpRDiscPrivate _priv; +}; + +struct _NMLndpRDiscClass { + NMRDiscClass parent; +}; + +/*****************************************************************************/ G_DEFINE_TYPE (NMLndpRDisc, nm_lndp_rdisc, NM_TYPE_RDISC) -/******************************************************************/ +#define NM_LNDP_RDISC_GET_PRIVATE(self) \ + ({ \ + /* preserve the const-ness of self. Unfortunately, that + * way, @self cannot be a void pointer */ \ + typeof (self) _self = (self); \ + \ + /* Get compiler error if variable is of wrong type */ \ + _nm_unused const NMLndpRDisc *_self2 = (_self); \ + \ + nm_assert (NM_IS_LNDP_RDISC (_self)); \ + &_self->_priv; \ + }) + +/*****************************************************************************/ static gboolean send_rs (NMRDisc *rdisc, GError **error) { - NMLndpRDiscPrivate *priv = NM_LNDP_RDISC_GET_PRIVATE (rdisc); + NMLndpRDiscPrivate *priv = NM_LNDP_RDISC_GET_PRIVATE ((NMLndpRDisc *) rdisc); struct ndp_msg *msg; int errsv; @@ -283,7 +309,7 @@ static gboolean event_ready (GIOChannel *source, GIOCondition condition, NMRDisc *rdisc) { nm_auto_pop_netns NMPNetns *netns = NULL; - NMLndpRDiscPrivate *priv = NM_LNDP_RDISC_GET_PRIVATE (rdisc); + NMLndpRDiscPrivate *priv = NM_LNDP_RDISC_GET_PRIVATE ((NMLndpRDisc *) rdisc); _LOGD ("processing libndp events"); @@ -297,7 +323,7 @@ event_ready (GIOChannel *source, GIOCondition condition, NMRDisc *rdisc) static void start (NMRDisc *rdisc) { - NMLndpRDiscPrivate *priv = NM_LNDP_RDISC_GET_PRIVATE (rdisc); + NMLndpRDiscPrivate *priv = NM_LNDP_RDISC_GET_PRIVATE ((NMLndpRDisc *) rdisc); int fd = ndp_get_eventfd (priv->ndp); priv->event_channel = g_io_channel_unix_new (fd); @@ -309,7 +335,7 @@ start (NMRDisc *rdisc) ndp_msgrcv_handler_register (priv->ndp, receive_ra, NDP_MSG_RA, rdisc->ifindex, rdisc); } -/******************************************************************/ +/*****************************************************************************/ static inline gint32 ipv6_sysctl_get (NMPlatform *platform, const char *ifname, const char *property, gint32 defval) @@ -317,6 +343,13 @@ ipv6_sysctl_get (NMPlatform *platform, const char *ifname, const char *property, return nm_platform_sysctl_get_int32 (platform, nm_utils_ip6_property_path (ifname, property), defval); } +/*****************************************************************************/ + +static void +nm_lndp_rdisc_init (NMLndpRDisc *lndp_rdisc) +{ +} + NMRDisc * nm_lndp_rdisc_new (NMPlatform *platform, int ifindex, @@ -354,7 +387,7 @@ nm_lndp_rdisc_new (NMPlatform *platform, rdisc->rtr_solicitation_interval = ipv6_sysctl_get (platform, ifname, "router_solicitation_interval", NM_RDISC_RTR_SOLICITATION_INTERVAL_DEFAULT); - priv = NM_LNDP_RDISC_GET_PRIVATE (rdisc); + priv = NM_LNDP_RDISC_GET_PRIVATE ((NMLndpRDisc *) rdisc); errsv = ndp_open (&priv->ndp); @@ -369,11 +402,6 @@ nm_lndp_rdisc_new (NMPlatform *platform, return rdisc; } -static void -nm_lndp_rdisc_init (NMLndpRDisc *lndp_rdisc) -{ -} - static void dispose (GObject *object) { @@ -398,8 +426,6 @@ nm_lndp_rdisc_class_init (NMLndpRDiscClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); NMRDiscClass *rdisc_class = NM_RDISC_CLASS (klass); - g_type_class_add_private (klass, sizeof (NMLndpRDiscPrivate)); - object_class->dispose = dispose; rdisc_class->start = start; rdisc_class->send_rs = send_rs; -- cgit v1.2.3