#include "macro.h"
#include "alloc-util.h"
#include "dns-domain.h"
+#include "ether-addr-util.h"
+#include "event-util.h"
#include "fd-util.h"
#include "icmp6-util.h"
#include "in-addr-util.h"
assert_return(ret, -EINVAL);
- ra = new0(sd_radv, 1);
+ ra = new(sd_radv, 1);
if (!ra)
return -ENOMEM;
- ra->n_ref = 1;
- ra->fd = -1;
-
- LIST_HEAD_INIT(ra->prefixes);
+ *ra = (sd_radv) {
+ .n_ref = 1,
+ .fd = -1,
+ };
*ret = TAKE_PTR(ra);
static void radv_reset(sd_radv *ra) {
assert(ra);
- ra->timeout_event_source =
- sd_event_source_unref(ra->timeout_event_source);
+ (void) event_source_disable(ra->timeout_event_source);
ra->recv_event_source =
sd_event_source_unref(ra->recv_event_source);
}
static sd_radv *radv_free(sd_radv *ra) {
- assert(ra);
+ if (!ra)
+ return NULL;
while (ra->prefixes) {
sd_radv_prefix *p = ra->prefixes;
free(ra->rdnss);
free(ra->dnssl);
+ ra->timeout_event_source = sd_event_source_unref(ra->timeout_event_source);
+
radv_reset(ra);
sd_radv_detach_event(ra);
DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_radv, sd_radv, radv_free);
-static int radv_send(sd_radv *ra, const struct in6_addr *dst,
- const uint32_t router_lifetime) {
- static const struct ether_addr mac_zero = {};
+static int radv_send(sd_radv *ra, const struct in6_addr *dst, uint32_t router_lifetime) {
sd_radv_prefix *p;
struct sockaddr_in6 dst_addr = {
.sin6_family = AF_INET6,
usec_t time_now;
int r;
+ assert(ra);
+
r = sd_event_now(ra->event, clock_boottime_or_monotonic(), &time_now);
if (r < 0)
return r;
- if (dst && !in_addr_is_null(AF_INET6, (union in_addr_union*) dst))
+ if (dst && !IN6_IS_ADDR_UNSPECIFIED(dst))
dst_addr.sin6_addr = *dst;
adv.nd_ra_type = ND_ROUTER_ADVERT;
/* MAC address is optional, either because the link does not use L2
addresses or load sharing is desired. See RFC 4861, Section 4.2 */
- if (memcmp(&mac_zero, &ra->mac_addr, sizeof(mac_zero))) {
+ if (!ether_addr_is_null(&ra->mac_addr)) {
opt_mac.slladdr = ra->mac_addr;
iov[msg.msg_iovlen].iov_base = &opt_mac;
iov[msg.msg_iovlen].iov_len = sizeof(opt_mac);
assert(ra);
assert(ra->event);
- ra->timeout_event_source = sd_event_source_unref(ra->timeout_event_source);
-
r = sd_event_now(ra->event, clock_boottime_or_monotonic(), &time_now);
if (r < 0)
goto fail;
format_timespan(time_string, FORMAT_TIMESPAN_MAX,
timeout, USEC_PER_SEC));
- r = sd_event_add_time(ra->event, &ra->timeout_event_source,
- clock_boottime_or_monotonic(),
- time_now + timeout, MSEC_PER_SEC,
- radv_timeout, ra);
- if (r < 0)
- goto fail;
-
- r = sd_event_source_set_priority(ra->timeout_event_source,
- ra->event_priority);
- if (r < 0)
- goto fail;
-
- r = sd_event_source_set_description(ra->timeout_event_source,
- "radv-timeout");
+ r = event_reset_time(ra->event, &ra->timeout_event_source,
+ clock_boottime_or_monotonic(),
+ time_now + timeout, MSEC_PER_SEC,
+ radv_timeout, ra,
+ ra->event_priority, "radv-timeout", true);
if (r < 0)
goto fail;
ra->ra_sent++;
+ return 0;
+
fail:
- if (r < 0)
- sd_radv_stop(ra);
+ sd_radv_stop(ra);
return 0;
}
if (ra->state != SD_RADV_STATE_IDLE)
return 0;
- r = sd_event_add_time(ra->event, &ra->timeout_event_source,
- clock_boottime_or_monotonic(), 0, 0,
- radv_timeout, ra);
+ r = event_reset_time(ra->event, &ra->timeout_event_source,
+ clock_boottime_or_monotonic(),
+ 0, 0,
+ radv_timeout, ra,
+ ra->event_priority, "radv-timeout", true);
if (r < 0)
goto fail;
- r = sd_event_source_set_priority(ra->timeout_event_source,
- ra->event_priority);
- if (r < 0)
- goto fail;
-
- (void) sd_event_source_set_description(ra->timeout_event_source,
- "radv-timeout");
-
r = icmp6_bind_router_advertisement(ra->ifindex);
if (r < 0)
goto fail;