Skip to content

Commit

Permalink
fix: Idempotency wrapper for callers
Browse files Browse the repository at this point in the history
Example for a caller assuming idempotency: uhcp (-> `gnrc_netif_ipv6_add_prefix` -> `NETOPT_IPV6_IID`)
  • Loading branch information
xnumad committed Sep 20, 2024
1 parent 6cbd58d commit 3af0785
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sys/net/gnrc/netif/gnrc_netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ int gnrc_netif_get_from_netdev(gnrc_netif_t *netif, gnrc_netapi_opt_t *opt)
assert(opt->data_len == sizeof(netopt_ipv6_rfc7217_iid_data));
netopt_ipv6_rfc7217_iid_data *data =
(netopt_ipv6_rfc7217_iid_data *) opt->data;
res = ipv6_get_rfc7217_iid(
res = ipv6_get_rfc7217_iid_idempotent(
data->iid, netif, data->pfx, data->dad_ctr);
break;
#endif
Expand Down
24 changes: 24 additions & 0 deletions sys/net/gnrc/network_layer/ipv6/nib/_nib-slaac.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,30 @@ int ipv6_get_rfc7217_iid(eui64_t *iid, gnrc_netif_t *netif, const ipv6_addr_t *p

return 0;
}

inline int ipv6_get_rfc7217_iid_idempotent(eui64_t *iid, gnrc_netif_t *netif, const ipv6_addr_t *pfx,

Check warning on line 220 in sys/net/gnrc/network_layer/ipv6/nib/_nib-slaac.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
uint8_t *dad_ctr) {
int idx;
if ((idx = gnrc_netif_ipv6_addr_pfx_idx(netif, pfx, SLAAC_PREFIX_LENGTH)) >= 0) {
/* if the prefix is already known,
* do not cause generation of a potentially different
* stable privacy address (keyword DAD_Counter).
* refer to https://datatracker.ietf.org/doc/html/rfc4862#section-5.5.3 d)
* */
DEBUG("nib: Not calling IDGEN, prefix already known.\n");

//write out params
//- dad_ctr
*dad_ctr = gnrc_netif_ipv6_addr_gen_retries(netif, idx);
//- iid
ipv6_addr_t *addr = &netif->ipv6.addrs[idx];
memcpy(iid, &addr->u64[1], sizeof(*iid));

return 1;
}

return ipv6_get_rfc7217_iid(iid, netif, pfx,dad_ctr);

Check warning on line 241 in sys/net/gnrc/network_layer/ipv6/nib/_nib-slaac.c

View workflow job for this annotation

GitHub Actions / static-tests

comma should be followed by whitespace
}
#endif

#if IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_SLAAC)
Expand Down
7 changes: 7 additions & 0 deletions sys/net/gnrc/network_layer/ipv6/nib/_nib-slaac.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ bool _stable_privacy_should_retry_idgen(uint8_t *dad_ctr, const char *reason);
*/
int ipv6_get_rfc7217_iid(eui64_t *iid, gnrc_netif_t *netif, const ipv6_addr_t *pfx,
uint8_t *dad_ctr);

/**
* @brief @ref ipv6_get_rfc7217_iid for those callers which assume idempotency.
* @return 1 if ignored for idempotency, else @ref ipv6_get_rfc7217_iid
*/
int ipv6_get_rfc7217_iid_idempotent(eui64_t *iid, gnrc_netif_t *netif, const ipv6_addr_t *pfx,
uint8_t *dad_ctr);
#endif

#if IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_SLAAC) || defined(DOXYGEN)
Expand Down

0 comments on commit 3af0785

Please sign in to comment.