From aeb7c37224051811553c898b2a784944f26276b0 Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Mon, 13 May 2013 17:17:07 +0200 Subject: [PATCH] Export AFTR-IP as well and update README --- README | 3 +++ src/script.c | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/README b/README index 3dd5289..a6fa298 100644 --- a/README +++ b/README @@ -28,6 +28,7 @@ especially routers. It compiles to only about 30 KB (-Os -s). f) SIP Options g) Information-Refresh Options h) SOL_MAX_RT default to 3600 + i) DS-Lite AFTR-Name Option 4. Support for requesting and parsing Router Advertisements a) parsing of prefixes, routes, MTU and RDNSS options @@ -75,3 +76,5 @@ Environment: * RA_ROUTES A space-separated list of routes from the RA Format:
/,gateway,valid,metric * RA_DNS A space-separated list of recursive DNS servers from the RA +* AFTR The DS-Lite AFTR domain name +* AFTR_IP The DS-Lite AFTR resolved IPv6 address diff --git a/src/script.c b/src/script.c index b9bf0aa..9d88daf 100644 --- a/src/script.c +++ b/src/script.c @@ -13,6 +13,7 @@ */ #include +#include #include #include #include @@ -115,6 +116,29 @@ static void fqdn_to_env(const char *name, const uint8_t *fqdn, size_t len) } +static void fqdn_to_ip_env(const char *name, const uint8_t *fqdn, size_t len) +{ + size_t buf_len = strlen(name); + char *buf = realloc(NULL, INET6_ADDRSTRLEN + buf_len + 3); + memcpy(buf, name, buf_len); + buf[buf_len++] = '='; + + char namebuf[256]; + if (dn_expand(fqdn, fqdn + len, fqdn, namebuf, sizeof(namebuf)) <= 0) + return; + + struct addrinfo hints = {.ai_family = AF_INET6}, *r; + if (getaddrinfo(namebuf, NULL, &hints, &r)) + return; + + struct sockaddr_in6 *sin6 = (struct sockaddr_in6*)r->ai_addr; + inet_ntop(AF_INET6, &sin6->sin6_addr, &buf[buf_len], INET6_ADDRSTRLEN); + + freeaddrinfo(r); + putenv(buf); +} + + static void bin_to_env(uint8_t *opts, size_t len) { uint8_t *oend = opts + len, *odata; @@ -230,6 +254,7 @@ void script_call(const char *status) fqdn_to_env("SNTP_FQDN", sntp_dns, sntp_dns_len); fqdn_to_env("SIP_DOMAIN", sip_fqdn, sip_fqdn_len); fqdn_to_env("AFTR", aftr_name, aftr_name_len); + fqdn_to_ip_env("AFTR_IP", aftr_name, aftr_name_len); bin_to_env(custom, custom_len); entry_to_env("PREFIXES", prefix, prefix_len, ENTRY_PREFIX); entry_to_env("ADDRESSES", address, address_len, ENTRY_ADDRESS); -- 2.25.1