diff options
Diffstat (limited to 'src/ndisc')
| -rw-r--r-- | src/ndisc/nm-fake-ndisc.c | 8 | ||||
| -rw-r--r-- | src/ndisc/nm-lndp-ndisc.c | 57 | ||||
| -rw-r--r-- | src/ndisc/nm-ndisc.c | 34 | ||||
| -rw-r--r-- | src/ndisc/tests/meson.build | 2 | ||||
| -rw-r--r-- | src/ndisc/tests/test-ndisc-fake.c | 12 |
5 files changed, 60 insertions, 53 deletions
diff --git a/src/ndisc/nm-fake-ndisc.c b/src/ndisc/nm-fake-ndisc.c index 020764d3..5f4594b9 100644 --- a/src/ndisc/nm-fake-ndisc.c +++ b/src/ndisc/nm-fake-ndisc.c @@ -62,7 +62,7 @@ struct _NMFakeRNDiscClass { G_DEFINE_TYPE (NMFakeNDisc, nm_fake_ndisc, NM_TYPE_NDISC) -#define NM_FAKE_NDISC_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMFakeNDisc, NM_IS_FAKE_NDISC) +#define NM_FAKE_NDISC_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMFakeNDisc, NM_IS_FAKE_NDISC, NMNDisc) /*****************************************************************************/ @@ -234,7 +234,7 @@ receive_ra (gpointer user_data) NMNDiscDataInternal *rdata = ndisc->rdata; FakeRa *ra = priv->ras->data; NMNDiscConfigMap changed = 0; - gint32 now = nm_utils_get_monotonic_timestamp_s (); + gint32 now = nm_utils_get_monotonic_timestamp_sec (); guint i; NMNDiscDHCPLevel dhcp_level; @@ -326,7 +326,7 @@ receive_ra (gpointer user_data) static void start (NMNDisc *ndisc) { - NMFakeNDiscPrivate *priv = NM_FAKE_NDISC_GET_PRIVATE ((NMFakeNDisc *) ndisc); + NMFakeNDiscPrivate *priv = NM_FAKE_NDISC_GET_PRIVATE (ndisc); FakeRa *ra; /* Queue up the first fake RA */ @@ -366,7 +366,7 @@ nm_fake_ndisc_new (int ifindex, const char *ifname) static void dispose (GObject *object) { - NMFakeNDiscPrivate *priv = NM_FAKE_NDISC_GET_PRIVATE ((NMFakeNDisc *) object); + NMFakeNDiscPrivate *priv = NM_FAKE_NDISC_GET_PRIVATE (object); nm_clear_g_source (&priv->receive_ra_id); diff --git a/src/ndisc/nm-lndp-ndisc.c b/src/ndisc/nm-lndp-ndisc.c index 6f2815ef..b10adc91 100644 --- a/src/ndisc/nm-lndp-ndisc.c +++ b/src/ndisc/nm-lndp-ndisc.c @@ -24,9 +24,7 @@ typedef struct { struct ndp *ndp; - - GIOChannel *event_channel; - guint event_id; + GSource *event_source; } NMLndpNDiscPrivate; /*****************************************************************************/ @@ -44,14 +42,14 @@ struct _NMLndpNDiscClass { G_DEFINE_TYPE (NMLndpNDisc, nm_lndp_ndisc, NM_TYPE_NDISC) -#define NM_LNDP_NDISC_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMLndpNDisc, NM_IS_LNDP_NDISC) +#define NM_LNDP_NDISC_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMLndpNDisc, NM_IS_LNDP_NDISC, NMNDisc) /*****************************************************************************/ static gboolean send_rs (NMNDisc *ndisc, GError **error) { - NMLndpNDiscPrivate *priv = NM_LNDP_NDISC_GET_PRIVATE ((NMLndpNDisc *) ndisc); + NMLndpNDiscPrivate *priv = NM_LNDP_NDISC_GET_PRIVATE (ndisc); struct ndp_msg *msg; int errsv; @@ -99,7 +97,7 @@ receive_ra (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data) NMNDiscConfigMap changed = 0; struct ndp_msgra *msgra = ndp_msgra (msg); struct in6_addr gateway_addr; - gint32 now = nm_utils_get_monotonic_timestamp_s (); + gint32 now = nm_utils_get_monotonic_timestamp_sec (); int offset; int hop_limit; guint32 val; @@ -231,7 +229,7 @@ receive_ra (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data) /* DNS information */ ndp_msg_opt_for_each_offset(offset, msg, NDP_MSG_OPT_RDNSS) { - static struct in6_addr *addr; + struct in6_addr *addr; int addr_index; ndp_msg_opt_rdnss_for_each_addr (addr, addr_index, msg, offset) { @@ -260,7 +258,7 @@ receive_ra (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data) NMNDiscDNSDomain dns_domain = { .domain = domain, .timestamp = now, - .lifetime = ndp_msg_opt_rdnss_lifetime (msg, offset), + .lifetime = ndp_msg_opt_dnssl_lifetime (msg, offset), }; /* Pad the lifetime somewhat to give a bit of slack in cases @@ -346,9 +344,9 @@ typedef struct { static gboolean send_ra (NMNDisc *ndisc, GError **error) { - NMLndpNDiscPrivate *priv = NM_LNDP_NDISC_GET_PRIVATE ((NMLndpNDisc *) ndisc); + NMLndpNDiscPrivate *priv = NM_LNDP_NDISC_GET_PRIVATE (ndisc); NMNDiscDataInternal *rdata = ndisc->rdata; - gint32 now = nm_utils_get_monotonic_timestamp_s (); + gint32 now = nm_utils_get_monotonic_timestamp_sec (); int errsv; struct in6_addr *addr; struct ndp_msg *msg; @@ -484,17 +482,19 @@ receive_rs (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data) } static gboolean -event_ready (GIOChannel *source, GIOCondition condition, NMNDisc *ndisc) +event_ready (int fd, + GIOCondition condition, + gpointer user_data) { - _nm_unused gs_unref_object NMNDisc *ndisc_keep_alive = g_object_ref (ndisc); + gs_unref_object NMNDisc *ndisc = g_object_ref (NM_NDISC (user_data)); nm_auto_pop_netns NMPNetns *netns = NULL; - NMLndpNDiscPrivate *priv = NM_LNDP_NDISC_GET_PRIVATE ((NMLndpNDisc *) ndisc); + NMLndpNDiscPrivate *priv = NM_LNDP_NDISC_GET_PRIVATE (ndisc); _LOGD ("processing libndp events"); if (!nm_ndisc_netns_push (ndisc, &netns)) { /* something is very wrong. Stop handling events. */ - priv->event_id = 0; + nm_clear_g_source_inst (&priv->event_source); return G_SOURCE_REMOVE; } @@ -505,17 +505,23 @@ event_ready (GIOChannel *source, GIOCondition condition, NMNDisc *ndisc) static void start (NMNDisc *ndisc) { - NMLndpNDiscPrivate *priv = NM_LNDP_NDISC_GET_PRIVATE ((NMLndpNDisc *) ndisc); - int fd = ndp_get_eventfd (priv->ndp); + NMLndpNDiscPrivate *priv = NM_LNDP_NDISC_GET_PRIVATE (ndisc); + int fd; + + g_return_if_fail (!priv->event_source); - g_return_if_fail (!priv->event_channel); - g_return_if_fail (!priv->event_id); + fd = ndp_get_eventfd (priv->ndp); - priv->event_channel = g_io_channel_unix_new (fd); - priv->event_id = g_io_add_watch (priv->event_channel, G_IO_IN, (GIOFunc) event_ready, ndisc); + priv->event_source = nm_g_unix_fd_source_new (fd, + G_IO_IN, + G_PRIORITY_DEFAULT, + event_ready, + ndisc, + NULL); + g_source_attach (priv->event_source, NULL); /* Flush any pending messages to avoid using obsolete information */ - event_ready (priv->event_channel, 0, ndisc); + event_ready (fd, 0, ndisc); switch (nm_ndisc_get_node_type (ndisc)) { case NM_NDISC_NODE_TYPE_HOST: @@ -592,7 +598,7 @@ nm_lndp_ndisc_new (NMPlatform *platform, 1, G_MAXINT32, NM_NDISC_ROUTER_SOLICITATION_INTERVAL_DEFAULT), NULL); - priv = NM_LNDP_NDISC_GET_PRIVATE ((NMLndpNDisc *) ndisc); + priv = NM_LNDP_NDISC_GET_PRIVATE (ndisc); errsv = ndp_open (&priv->ndp); @@ -610,11 +616,10 @@ nm_lndp_ndisc_new (NMPlatform *platform, static void dispose (GObject *object) { - NMNDisc *ndisc = (NMNDisc *) object; - NMLndpNDiscPrivate *priv = NM_LNDP_NDISC_GET_PRIVATE ((NMLndpNDisc *) ndisc); + NMNDisc *ndisc = NM_NDISC (object); + NMLndpNDiscPrivate *priv = NM_LNDP_NDISC_GET_PRIVATE (ndisc); - nm_clear_g_source (&priv->event_id); - g_clear_pointer (&priv->event_channel, g_io_channel_unref); + nm_clear_g_source_inst (&priv->event_source); if (priv->ndp) { switch (nm_ndisc_get_node_type (ndisc)) { diff --git a/src/ndisc/nm-ndisc.c b/src/ndisc/nm-ndisc.c index 0afca26b..5e556084 100644 --- a/src/ndisc/nm-ndisc.c +++ b/src/ndisc/nm-ndisc.c @@ -173,7 +173,7 @@ _get_exp (char *buf, gsize buf_size, gint64 now_ns, gint64 expiry_time) return "permanent"; l = g_snprintf (buf, buf_size, "%.4f", - ((double) ((expiry_time * NM_UTILS_NS_PER_SECOND) - now_ns)) / ((double) NM_UTILS_NS_PER_SECOND)); + ((double) ((expiry_time * NM_UTILS_NSEC_PER_SEC) - now_ns)) / ((double) NM_UTILS_NSEC_PER_SEC)); nm_assert (l < buf_size); return buf; } @@ -676,7 +676,7 @@ nm_ndisc_add_dns_domain (NMNDisc *ndisc, const NMNDiscDNSDomain *new) _different_message = g_strcmp0 (priv->last_error, error->message) != 0; \ _NMLOG (_different_message ? LOGL_WARN : LOGL_DEBUG, __VA_ARGS__); \ if (_different_message) { \ - g_clear_pointer (&priv->last_error, g_free); \ + nm_clear_g_free (&priv->last_error); \ priv->last_error = g_strdup (error->message); \ } \ } G_STMT_END @@ -697,13 +697,13 @@ send_rs_timeout (NMNDisc *ndisc) if (klass->send_rs (ndisc, &error)) { _LOGD ("router solicitation sent"); priv->solicitations_left--; - g_clear_pointer (&priv->last_error, g_free); + nm_clear_g_free (&priv->last_error); } else { _MAYBE_WARN ("failure sending router solicitation: %s", error->message); g_clear_error (&error); } - priv->last_rs = nm_utils_get_monotonic_timestamp_s (); + priv->last_rs = nm_utils_get_monotonic_timestamp_sec (); if (priv->solicitations_left > 0) { _LOGD ("scheduling router solicitation retry in %d seconds.", (int) priv->router_solicitation_interval); @@ -727,7 +727,7 @@ solicit_routers (NMNDisc *ndisc) if (priv->send_rs_id) return; - now = nm_utils_get_monotonic_timestamp_s (); + now = nm_utils_get_monotonic_timestamp_sec (); priv->solicitations_left = priv->router_solicitations; t = (((gint64) priv->last_rs) + priv->router_solicitation_interval) - now; @@ -748,10 +748,10 @@ announce_router (NMNDisc *ndisc) if (!nm_ndisc_netns_push (ndisc, &netns)) return G_SOURCE_REMOVE; - priv->last_ra = nm_utils_get_monotonic_timestamp_s (); + priv->last_ra = nm_utils_get_monotonic_timestamp_sec (); if (klass->send_ra (ndisc, &error)) { _LOGD ("router advertisement sent"); - g_clear_pointer (&priv->last_error, g_free); + nm_clear_g_free (&priv->last_error); } else { _MAYBE_WARN ("failure sending router advertisement: %s", error->message); g_clear_error (&error); @@ -788,7 +788,7 @@ announce_router_initial (NMNDisc *ndisc) priv->announcements_left = NM_NDISC_ROUTER_ADVERTISEMENTS_DEFAULT; /* Unschedule an unsolicited resend if we are allowed to send now. */ - if (G_LIKELY (nm_utils_get_monotonic_timestamp_s () - priv->last_ra > NM_NDISC_ROUTER_ADVERT_DELAY)) + if (G_LIKELY (nm_utils_get_monotonic_timestamp_sec () - priv->last_ra > NM_NDISC_ROUTER_ADVERT_DELAY)) nm_clear_g_source (&priv->send_ra_id); /* Schedule the initial send rather early. Clamp the delay by minimal @@ -807,7 +807,7 @@ announce_router_solicited (NMNDisc *ndisc) _LOGD ("will send an solicited router advertisement"); /* Unschedule an unsolicited resend if we are allowed to send now. */ - if (nm_utils_get_monotonic_timestamp_s () - priv->last_ra > NM_NDISC_ROUTER_ADVERT_DELAY) + if (nm_utils_get_monotonic_timestamp_sec () - priv->last_ra > NM_NDISC_ROUTER_ADVERT_DELAY) nm_clear_g_source (&priv->send_ra_id); if (!priv->send_ra_id) { @@ -965,7 +965,7 @@ nm_ndisc_dad_failed (NMNDisc *ndisc, const struct in6_addr *address, gboolean em if (IN6_ARE_ADDR_EQUAL (&item->address, address)) { char sbuf[NM_UTILS_INET_ADDRSTRLEN]; - _LOGD ("DAD failed for discovered address %s", nm_utils_inet6_ntop (address, sbuf)); + _LOGD ("DAD failed for discovered address %s", _nm_utils_inet6_ntop (address, sbuf)); changed = TRUE; if (!complete_address (ndisc, item)) { g_array_remove_index (rdata->addresses, i); @@ -1031,7 +1031,7 @@ _config_changed_log (NMNDisc *ndisc, NMNDiscConfigMap changed) if (!_LOGD_ENABLED ()) return; - now_ns = nm_utils_get_monotonic_timestamp_ns (); + now_ns = nm_utils_get_monotonic_timestamp_nsec (); priv = NM_NDISC_GET_PRIVATE (ndisc); rdata = &priv->rdata; @@ -1068,7 +1068,7 @@ _config_changed_log (NMNDisc *ndisc, NMNDiscConfigMap changed) inet_ntop (AF_INET6, &route->network, addrstr, sizeof (addrstr)); _LOGD (" route %s/%u via %s pref %s exp %s", addrstr, (guint) route->plen, - nm_utils_inet6_ntop (&route->gateway, sbuf), + _nm_utils_inet6_ntop (&route->gateway, sbuf), nm_icmpv6_router_pref_to_string (route->preference, str_pref, sizeof (str_pref)), get_exp (str_exp, now_ns, route)); } @@ -1245,7 +1245,7 @@ timeout_cb (gpointer user_data) NMNDisc *self = user_data; NM_NDISC_GET_PRIVATE (self)->timeout_id = 0; - check_timestamps (self, nm_utils_get_monotonic_timestamp_s (), 0); + check_timestamps (self, nm_utils_get_monotonic_timestamp_sec (), 0); return G_SOURCE_REMOVE; } @@ -1256,7 +1256,7 @@ nm_ndisc_ra_received (NMNDisc *ndisc, gint32 now, NMNDiscConfigMap changed) nm_clear_g_source (&priv->ra_timeout_id); nm_clear_g_source (&priv->send_rs_id); - g_clear_pointer (&priv->last_error, g_free); + nm_clear_g_free (&priv->last_error); check_timestamps (ndisc, now, changed); } @@ -1265,7 +1265,7 @@ nm_ndisc_rs_received (NMNDisc *ndisc) { NMNDiscPrivate *priv = NM_NDISC_GET_PRIVATE (ndisc); - g_clear_pointer (&priv->last_error, g_free); + nm_clear_g_free (&priv->last_error); announce_router_solicited (ndisc); } @@ -1370,7 +1370,7 @@ nm_ndisc_init (NMNDisc *ndisc) priv->rdata.public.hop_limit = 64; /* Start at very low number so that last_rs - router_solicitation_interval - * is much lower than nm_utils_get_monotonic_timestamp_s() at startup. + * is much lower than nm_utils_get_monotonic_timestamp_sec() at startup. */ priv->last_rs = G_MININT32; } @@ -1384,7 +1384,7 @@ dispose (GObject *object) nm_clear_g_source (&priv->ra_timeout_id); nm_clear_g_source (&priv->send_rs_id); nm_clear_g_source (&priv->send_ra_id); - g_clear_pointer (&priv->last_error, g_free); + nm_clear_g_free (&priv->last_error); nm_clear_g_source (&priv->timeout_id); diff --git a/src/ndisc/tests/meson.build b/src/ndisc/tests/meson.build index c81e24ad..349eebba 100644 --- a/src/ndisc/tests/meson.build +++ b/src/ndisc/tests/meson.build @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: LGPL-2.1+ + test_unit = 'test-ndisc-fake' exe = executable( diff --git a/src/ndisc/tests/test-ndisc-fake.c b/src/ndisc/tests/test-ndisc-fake.c index 8bdc053d..91fe9802 100644 --- a/src/ndisc/tests/test-ndisc-fake.c +++ b/src/ndisc/tests/test-ndisc-fake.c @@ -157,7 +157,7 @@ static void test_simple (void) { NMFakeNDisc *ndisc = ndisc_new (); - guint32 now = nm_utils_get_monotonic_timestamp_s (); + guint32 now = nm_utils_get_monotonic_timestamp_sec (); TestData data = { g_main_loop_new (NULL, FALSE), 0, 0, now }; guint id; @@ -239,7 +239,7 @@ static void test_everything (void) { NMFakeNDisc *ndisc = ndisc_new (); - guint32 now = nm_utils_get_monotonic_timestamp_s (); + guint32 now = nm_utils_get_monotonic_timestamp_sec (); TestData data = { g_main_loop_new (NULL, FALSE), 0, 0, now }; guint id; @@ -313,7 +313,7 @@ static void test_preference_order (void) { NMFakeNDisc *ndisc = ndisc_new (); - guint32 now = nm_utils_get_monotonic_timestamp_s (); + guint32 now = nm_utils_get_monotonic_timestamp_sec (); TestData data = { g_main_loop_new (NULL, FALSE), 0, 0, now }; guint id; @@ -386,7 +386,7 @@ static void test_preference_changed (void) { NMFakeNDisc *ndisc = ndisc_new (); - guint32 now = nm_utils_get_monotonic_timestamp_s (); + guint32 now = nm_utils_get_monotonic_timestamp_sec (); TestData data = { g_main_loop_new (NULL, FALSE), 0, 0, now }; guint id; @@ -440,7 +440,7 @@ success_timeout (TestData *data) static void test_dns_solicit_loop_rs_sent (NMFakeNDisc *ndisc, TestData *data) { - guint32 now = nm_utils_get_monotonic_timestamp_s (); + guint32 now = nm_utils_get_monotonic_timestamp_sec (); guint id; if (data->rs_counter > 0 && data->rs_counter < 6) { @@ -472,7 +472,7 @@ static void test_dns_solicit_loop (void) { NMFakeNDisc *ndisc = ndisc_new (); - guint32 now = nm_utils_get_monotonic_timestamp_s (); + guint32 now = nm_utils_get_monotonic_timestamp_sec (); TestData data = { g_main_loop_new (NULL, FALSE), 0, 0, now, 0 }; guint id; |