#include "sd-radv.h"
-#include "macro.h"
#include "alloc-util.h"
#include "dns-domain.h"
#include "ether-addr-util.h"
#include "fd-util.h"
#include "icmp6-util.h"
#include "in-addr-util.h"
+#include "io-util.h"
+#include "macro.h"
#include "radv-internal.h"
+#include "random-util.h"
#include "socket-util.h"
#include "string-util.h"
#include "strv.h"
#include "util.h"
-#include "random-util.h"
_public_ int sd_radv_new(sd_radv **ret) {
_cleanup_(sd_radv_unrefp) sd_radv *ra = NULL;
adv.nd_ra_curhoplimit = ra->hop_limit;
adv.nd_ra_flags_reserved = ra->flags;
adv.nd_ra_router_lifetime = htobe16(router_lifetime);
- iov[msg.msg_iovlen].iov_base = &adv;
- iov[msg.msg_iovlen].iov_len = sizeof(adv);
- msg.msg_iovlen++;
+ iov[msg.msg_iovlen++] = IOVEC_MAKE(&adv, sizeof(adv));
/* 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 (!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);
- msg.msg_iovlen++;
+ iov[msg.msg_iovlen++] = IOVEC_MAKE(&opt_mac, sizeof(opt_mac));
}
if (ra->mtu) {
opt_mtu.nd_opt_mtu_mtu = htobe32(ra->mtu);
- iov[msg.msg_iovlen].iov_base = &opt_mtu;
- iov[msg.msg_iovlen].iov_len = sizeof(opt_mtu);
- msg.msg_iovlen++;
+ iov[msg.msg_iovlen++] = IOVEC_MAKE(&opt_mtu, sizeof(opt_mtu));
}
LIST_FOREACH(prefix, p, ra->prefixes) {
else
p->opt.preferred_lifetime = htobe32((p->preferred_until - time_now) / USEC_PER_SEC);
}
- iov[msg.msg_iovlen].iov_base = &p->opt;
- iov[msg.msg_iovlen].iov_len = sizeof(p->opt);
- msg.msg_iovlen++;
+ iov[msg.msg_iovlen++] = IOVEC_MAKE(&p->opt, sizeof(p->opt));
}
- if (ra->rdnss) {
- iov[msg.msg_iovlen].iov_base = ra->rdnss;
- iov[msg.msg_iovlen].iov_len = ra->rdnss->length * 8;
- msg.msg_iovlen++;
- }
+ if (ra->rdnss)
+ iov[msg.msg_iovlen++] = IOVEC_MAKE(ra->rdnss, ra->rdnss->length * 8);
- if (ra->dnssl) {
- iov[msg.msg_iovlen].iov_base = ra->dnssl;
- iov[msg.msg_iovlen].iov_len = ra->dnssl->length * 8;
- msg.msg_iovlen++;
- }
+ if (ra->dnssl)
+ iov[msg.msg_iovlen++] = IOVEC_MAKE(ra->dnssl, ra->dnssl->length * 8);
if (sendmsg(ra->fd, &msg, 0) < 0)
return -errno;
if (!p)
return -EINVAL;
+ /* Refuse prefixes that don't have a prefix set */
+ if (IN6_IS_ADDR_UNSPECIFIED(&p->opt.in6_addr))
+ return -ENOEXEC;
+
LIST_FOREACH(prefix, cur, ra->prefixes) {
r = in_addr_prefix_intersect(AF_INET6,
}
_public_ int sd_radv_prefix_new(sd_radv_prefix **ret) {
- _cleanup_(sd_radv_prefix_unrefp) sd_radv_prefix *p = NULL;
+ sd_radv_prefix *p;
assert_return(ret, -EINVAL);
- p = new0(sd_radv_prefix, 1);
+ p = new(sd_radv_prefix, 1);
if (!p)
return -ENOMEM;
- p->n_ref = 1;
-
- p->opt.type = ND_OPT_PREFIX_INFORMATION;
- p->opt.length = (sizeof(p->opt) - 1) /8 + 1;
-
- p->opt.prefixlen = 64;
+ *p = (sd_radv_prefix) {
+ .n_ref = 1,
- /* RFC 4861, Section 6.2.1 */
- SET_FLAG(p->opt.flags, ND_OPT_PI_FLAG_ONLINK, true);
- SET_FLAG(p->opt.flags, ND_OPT_PI_FLAG_AUTO, true);
- p->opt.preferred_lifetime = htobe32(604800);
- p->opt.valid_lifetime = htobe32(2592000);
+ .opt.type = ND_OPT_PREFIX_INFORMATION,
+ .opt.length = (sizeof(p->opt) - 1)/8 + 1,
+ .opt.prefixlen = 64,
- LIST_INIT(prefix, p);
+ /* RFC 4861, Section 6.2.1 */
+ .opt.flags = ND_OPT_PI_FLAG_ONLINK|ND_OPT_PI_FLAG_AUTO,
- *ret = TAKE_PTR(p);
+ .opt.preferred_lifetime = htobe32(604800),
+ .opt.valid_lifetime = htobe32(2592000),
+ };
+ *ret = p;
return 0;
}