Skip to content

Instantly share code, notes, and snippets.

@oskar456
Created July 5, 2022 11:42
Show Gist options
  • Save oskar456/5183dee566416101727331bda30dd816 to your computer and use it in GitHub Desktop.
Save oskar456/5183dee566416101727331bda30dd816 to your computer and use it in GitHub Desktop.
A quick and dirty patch to add Pref64 RA option to odhcpd (RFC 8781)
diff --git a/src/router.c b/src/router.c
index 541c023..9ad79d4 100644
--- a/src/router.c
+++ b/src/router.c
@@ -390,6 +390,7 @@ enum {
IOV_RA_ROUTES,
IOV_RA_DNS,
IOV_RA_SEARCH,
+ IOV_RA_PREF64,
IOV_RA_ADV_INTERVAL,
IOV_RA_TOTAL,
};
@@ -427,6 +428,13 @@ struct nd_opt_route_info {
uint32_t addr[4];
};
+struct nd_opt_pref64_info {
+ uint8_t type;
+ uint8_t len;
+ uint16_t lifetime;
+ uint32_t addr[3];
+};
+
/* Router Advert server mode */
static int send_router_advert(struct interface *iface, const struct in6_addr *from)
{
@@ -437,10 +445,11 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr
struct nd_opt_dns_server *dns = NULL;
struct nd_opt_search_list *search = NULL;
struct nd_opt_route_info *routes = NULL;
+ struct nd_opt_pref64_info *pref64 = NULL;
struct nd_opt_adv_interval adv_interval;
struct iovec iov[IOV_RA_TOTAL];
struct sockaddr_in6 dest;
- size_t dns_sz = 0, search_sz = 0, pfxs_cnt = 0, routes_cnt = 0;
+ size_t dns_sz = 0, search_sz = 0, pfxs_cnt = 0, routes_cnt = 0, pref64_sz = 0;
ssize_t addr_cnt = 0;
uint32_t minvalid = UINT32_MAX, maxival, lifetime;
int msecs, mtu = iface->ra_mtu, hlim = iface->ra_hoplimit;
@@ -657,6 +666,17 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr
iov[IOV_RA_SEARCH].iov_base = (char *)search;
iov[IOV_RA_SEARCH].iov_len = search_sz;
+ if (1) {
+ pref64_sz = sizeof(*pref64);
+ pref64 = alloca(pref64_sz);
+ memset(pref64, 0, pref64_sz);
+ pref64->type = 38;
+ pref64->len = 2;
+ pref64->lifetime = htons(0xfff8 & (lifetime < UINT16_MAX ? lifetime : UINT16_MAX));
+ pref64->addr[0] = htonl(0x0064ff9b);
+ }
+ iov[IOV_RA_PREF64].iov_base = (char *)pref64;
+ iov[IOV_RA_PREF64].iov_len = pref64_sz;
/*
* RFC7084 § 4.3 :
* L-3: An IPv6 CE router MUST advertise itself as a router for the
--
2.35.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment