Skip to content

Commit 7a4023b

Browse files
committed
src: rename ra_pio prefix to addr
We're storing the full interface address instead of the prefix, so renaming it from prefix to address should make the code more clear. Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
1 parent 03c1468 commit 7a4023b

File tree

4 files changed

+31
-28
lines changed

4 files changed

+31
-28
lines changed

src/odhcpd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ struct dnr_options {
346346

347347
// RA PIO - RFC9096
348348
struct ra_pio {
349-
struct in6_addr prefix;
349+
struct in6_addr addr;
350350
uint8_t length;
351351
time_t lifetime;
352352
};

src/router.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ inline static int router_compare_pio_addr(const struct ra_pio *pio, const struct
454454
{
455455
uint8_t cmp_len = max(64, max(pio->length, addr->prefix_len));
456456

457-
return odhcpd_bmemcmp(&pio->prefix, &addr->addr.in6, cmp_len);
457+
return odhcpd_bmemcmp(&pio->addr, &addr->addr.in6, cmp_len);
458458
}
459459

460460
static struct ra_pio *router_find_ra_pio(struct interface *iface,
@@ -478,20 +478,20 @@ static void router_add_ra_pio(struct interface *iface,
478478

479479
pio = router_find_ra_pio(iface, addr);
480480
if (pio) {
481-
if (memcmp(&pio->prefix, &addr->addr.in6, sizeof(struct in6_addr)) != 0 ||
481+
if (memcmp(&pio->addr, &addr->addr.in6, sizeof(struct in6_addr)) != 0 ||
482482
pio->length != addr->prefix_len)
483483
{
484484
char new_ipv6_str[INET6_ADDRSTRLEN];
485485

486486
iface->pio_update = true;
487487
warn("rfc9096: %s: changed %s/%u -> %s/%u",
488488
iface->ifname,
489-
inet_ntop(AF_INET6, &pio->prefix, ipv6_str, sizeof(ipv6_str)),
489+
inet_ntop(AF_INET6, &pio->addr, ipv6_str, sizeof(ipv6_str)),
490490
pio->length,
491491
inet_ntop(AF_INET6, &addr->addr.in6, new_ipv6_str, sizeof(new_ipv6_str)),
492492
addr->prefix_len);
493493

494-
memcpy(&pio->prefix, &addr->addr.in6, sizeof(struct in6_addr));
494+
memcpy(&pio->addr, &addr->addr.in6, sizeof(struct in6_addr));
495495
pio->length = addr->prefix_len;
496496
}
497497

@@ -501,7 +501,7 @@ static void router_add_ra_pio(struct interface *iface,
501501
iface->pio_update = true;
502502
warn("rfc9096: %s: renew %s/%u",
503503
iface->ifname,
504-
inet_ntop(AF_INET6, &pio->prefix, ipv6_str, sizeof(ipv6_str)),
504+
inet_ntop(AF_INET6, &pio->addr, ipv6_str, sizeof(ipv6_str)),
505505
pio->length);
506506
}
507507

@@ -516,14 +516,14 @@ static void router_add_ra_pio(struct interface *iface,
516516
pio = &iface->pios[iface->pio_cnt];
517517
iface->pio_cnt++;
518518

519-
memcpy(&pio->prefix, &addr->addr.in6, sizeof(struct in6_addr));
519+
memcpy(&pio->addr, &addr->addr.in6, sizeof(struct in6_addr));
520520
pio->length = addr->prefix_len;
521521
pio->lifetime = 0;
522522

523523
iface->pio_update = true;
524524
info("rfc9096: %s: add %s/%u",
525525
iface->ifname,
526-
inet_ntop(AF_INET6, &pio->prefix, ipv6_str, sizeof(ipv6_str)),
526+
inet_ntop(AF_INET6, &pio->addr, ipv6_str, sizeof(ipv6_str)),
527527
pio->length);
528528
}
529529

@@ -540,10 +540,10 @@ static void router_clear_duplicated_ra_pio(struct interface *iface)
540540
struct ra_pio *pio_b = &iface->pios[j];
541541

542542
if (pio_a->length == pio_b->length &&
543-
!memcmp(&pio_a->prefix, &pio_b->prefix, sizeof(struct in6_addr))) {
543+
!memcmp(&pio_a->addr, &pio_b->addr, sizeof(struct in6_addr))) {
544544
warn("rfc9096: %s: clear duplicated %s/%u",
545545
iface->ifname,
546-
inet_ntop(AF_INET6, &pio_a->prefix, ipv6_str, sizeof(ipv6_str)),
546+
inet_ntop(AF_INET6, &pio_a->addr, ipv6_str, sizeof(ipv6_str)),
547547
pio_a->length);
548548

549549
iface->pios[j] = iface->pios[iface->pio_cnt - 1];
@@ -574,7 +574,7 @@ static void router_clear_expired_ra_pio(time_t now,
574574
if (ra_pio_expired(cur_pio, now)) {
575575
info("rfc9096: %s: clear expired %s/%u",
576576
iface->ifname,
577-
inet_ntop(AF_INET6, &cur_pio->prefix, ipv6_str, sizeof(ipv6_str)),
577+
inet_ntop(AF_INET6, &cur_pio->addr, ipv6_str, sizeof(ipv6_str)),
578578
cur_pio->length);
579579

580580
iface->pios[i] = iface->pios[iface->pio_cnt - 1];
@@ -610,7 +610,7 @@ static void router_stale_ra_pio(struct interface *iface,
610610
iface->pio_update = true;
611611
warn("rfc9096: %s: stale %s/%u",
612612
iface->ifname,
613-
inet_ntop(AF_INET6, &pio->prefix, ipv6_str, sizeof(ipv6_str)),
613+
inet_ntop(AF_INET6, &pio->addr, ipv6_str, sizeof(ipv6_str)),
614614
pio->length);
615615
}
616616

@@ -725,7 +725,7 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr
725725
if (!pio_found) {
726726
struct odhcpd_ipaddr *addr = &addrs[total_addr_cnt];
727727

728-
memcpy(&addr->addr.in6, &cur_pio->prefix, sizeof(addr->addr.in6));
728+
memcpy(&addr->addr.in6, &cur_pio->addr, sizeof(addr->addr.in6));
729729
addr->prefix_len = cur_pio->length;
730730
addr->preferred_lt = 0;
731731
addr->valid_lt = (uint32_t) (now + ND_VALID_LIMIT);

src/statefiles.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ static void statefiles_finish_tmp_file(int dirfd, FILE **fpp, const char *prefix
108108
renameat(dirfd, ODHCPD_TMP_FILE, dirfd, filename);
109109
}
110110

111+
#define JSON_ADDRESS "address"
111112
#define JSON_LENGTH "length"
112113
#define JSON_PREFIX "prefix"
113114
#define JSON_SLAAC "slaac"
@@ -218,8 +219,8 @@ void statefiles_read_prefix_information(struct interface *iface)
218219
iface->pios = new_pios;
219220
iface->pio_cnt = 0;
220221
for (size_t i = 0; i < pio_cnt; i++) {
221-
json_object *cur_pio_json, *length_json, *prefix_json;
222-
const char *pio_str;
222+
json_object *cur_pio_json, *length_json, *addr_json;
223+
const char *pio_addr;
223224
time_t pio_lt = 0;
224225
struct ra_pio *pio;
225226
uint8_t pio_len;
@@ -235,20 +236,22 @@ void statefiles_read_prefix_information(struct interface *iface)
235236
if (!length_json)
236237
continue;
237238

238-
prefix_json = json_object_object_get(cur_pio_json, JSON_PREFIX);
239-
if (!prefix_json)
239+
addr_json = json_object_object_get(cur_pio_json, JSON_ADDRESS);
240+
if (!addr_json)
241+
addr_json = json_object_object_get(cur_pio_json, JSON_PREFIX);
242+
if (!addr_json)
240243
continue;
241244

242245
pio_len = (uint8_t) json_object_get_uint64(length_json);
243-
pio_str = json_object_get_string(prefix_json);
246+
pio_addr = json_object_get_string(addr_json);
244247
pio = &iface->pios[iface->pio_cnt];
245248

246-
inet_pton(AF_INET6, pio_str, &pio->prefix);
249+
inet_pton(AF_INET6, pio_addr, &pio->addr);
247250
pio->length = pio_len;
248251
pio->lifetime = pio_lt;
249252
info("rfc9096: %s: load %s/%u (%u)",
250253
iface->ifname,
251-
pio_str,
254+
pio_addr,
252255
pio_len,
253256
ra_pio_lifetime(pio, now));
254257

@@ -299,7 +302,7 @@ void statefiles_write_prefix_information(struct interface *iface)
299302
json_object_object_add(json, JSON_SLAAC, slaac_json);
300303

301304
for (size_t i = 0; i < iface->pio_cnt; i++) {
302-
struct json_object *cur_pio_json, *len_json, *pfx_json;
305+
struct json_object *cur_pio_json, *len_json, *addr_json;
303306
const struct ra_pio *cur_pio = &iface->pios[i];
304307

305308
if (ra_pio_expired(cur_pio, now))
@@ -309,22 +312,22 @@ void statefiles_write_prefix_information(struct interface *iface)
309312
if (!cur_pio_json)
310313
continue;
311314

312-
inet_ntop(AF_INET6, &cur_pio->prefix, ipv6_str, sizeof(ipv6_str));
315+
inet_ntop(AF_INET6, &cur_pio->addr, ipv6_str, sizeof(ipv6_str));
313316

314-
pfx_json = json_object_new_string(ipv6_str);
315-
if (!pfx_json) {
317+
addr_json = json_object_new_string(ipv6_str);
318+
if (!addr_json) {
316319
json_object_put(cur_pio_json);
317320
continue;
318321
}
319322

320323
len_json = json_object_new_uint64(cur_pio->length);
321324
if (!len_json) {
322325
json_object_put(cur_pio_json);
323-
json_object_put(pfx_json);
326+
json_object_put(addr_json);
324327
continue;
325328
}
326329

327-
json_object_object_add(cur_pio_json, JSON_PREFIX, pfx_json);
330+
json_object_object_add(cur_pio_json, JSON_ADDRESS, addr_json);
328331
json_object_object_add(cur_pio_json, JSON_LENGTH, len_json);
329332

330333
if (cur_pio->lifetime) {

src/ubus.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,11 @@ static int handle_ra_pio(_o_unused struct ubus_context *ctx, _o_unused struct ub
213213
pio_lt = ra_pio_lifetime(cur_pio, now);
214214
pio_stale = ra_pio_stale(cur_pio);
215215

216-
inet_ntop(AF_INET6, &cur_pio->prefix, ipv6_str, sizeof(ipv6_str));
216+
inet_ntop(AF_INET6, &cur_pio->addr, ipv6_str, sizeof(ipv6_str));
217217

218218
if (pio_lt)
219219
blobmsg_add_u32(&b, "lifetime", pio_lt);
220-
blobmsg_add_string(&b, "prefix", ipv6_str);
220+
blobmsg_add_string(&b, "address", ipv6_str);
221221
blobmsg_add_u16(&b, "length", cur_pio->length);
222222
blobmsg_add_u8(&b, "stale", pio_stale);
223223

0 commit comments

Comments
 (0)