X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=src%2Fscript.c;h=ffb39f3f5726470513e8f0004f12bd7007048b61;hb=3fb3c327d889a8c5e0370259c4c6360c7d3106cb;hp=4eec04dceba3b4fc193c0f7a1492ccb7fc2821cd;hpb=6bc31b22abc26b9ee31b789d56a8e2a07aa4c569;p=odhcp6c.git diff --git a/src/script.c b/src/script.c index 4eec04d..ffb39f3 100644 --- a/src/script.c +++ b/src/script.c @@ -1,5 +1,5 @@ /** - * Copyright (C) 2012 Steven Barth + * Copyright (C) 2012-2013 Steven Barth * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License v2 as published by @@ -128,12 +128,17 @@ static void bin_to_env(uint8_t *opts, size_t len) } } +enum entry_type { + ENTRY_ADDRESS, + ENTRY_HOST, + ENTRY_ROUTE, + ENTRY_PREFIX +}; -static void entry_to_env(const char *name, const void *data, size_t len, bool host) +static void entry_to_env(const char *name, const void *data, size_t len, enum entry_type type) { size_t buf_len = strlen(name); const struct odhcp6c_entry *e = data; - const struct in6_addr any = IN6ADDR_ANY_INIT; char *buf = realloc(NULL, buf_len + 2 + (len / sizeof(*e)) * 144); memcpy(buf, name, buf_len); buf[buf_len++] = '='; @@ -141,16 +146,27 @@ static void entry_to_env(const char *name, const void *data, size_t len, bool ho for (size_t i = 0; i < len / sizeof(*e); ++i) { inet_ntop(AF_INET6, &e[i].target, &buf[buf_len], INET6_ADDRSTRLEN); buf_len += strlen(&buf[buf_len]); - if (!host) { + if (type != ENTRY_HOST) { buf_len += snprintf(&buf[buf_len], 6, "/%hhu", e[i].length); - if (!IN6_ARE_ADDR_EQUAL(&any, &e[i].router)) { - buf[buf_len++] = '@'; + if (type == ENTRY_ROUTE) { + buf[buf_len++] = ','; + if (!IN6_IS_ADDR_UNSPECIFIED(&e[i].router)) { + inet_ntop(AF_INET6, &e[i].router, &buf[buf_len], INET6_ADDRSTRLEN); + buf_len += strlen(&buf[buf_len]); + } + buf_len += snprintf(&buf[buf_len], 24, ",%u", e[i].valid); + buf_len += snprintf(&buf[buf_len], 12, ",%u", e[i].priority); + } else { + buf_len += snprintf(&buf[buf_len], 24, ",%u,%u", e[i].preferred, e[i].valid); + } + + if (type == ENTRY_PREFIX && e[i].priority) { + // priority and router are abused for prefix exclusion + buf[buf_len++] = ','; inet_ntop(AF_INET6, &e[i].router, &buf[buf_len], INET6_ADDRSTRLEN); buf_len += strlen(&buf[buf_len]); + buf_len += snprintf(&buf[buf_len], 24, "/%u", e[i].priority); } - buf_len += snprintf(&buf[buf_len], 24, ",%u,%u", e[i].preferred, e[i].valid); - if (e[i].priority) - buf_len += snprintf(&buf[buf_len], 12, ",%u", e[i].priority); } buf[buf_len++] = ' '; } @@ -162,7 +178,6 @@ static void entry_to_env(const char *name, const void *data, size_t len, bool ho void script_call(const char *status) { - syslog(LOG_WARNING, "State for %s changed to %s", argv[1], status); size_t dns_len, search_len, custom_len, sntp_ip_len, sntp_dns_len; size_t sip_ip_len, sip_fqdn_len; @@ -190,11 +205,11 @@ 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); bin_to_env(custom, custom_len); - entry_to_env("PREFIXES", prefix, prefix_len, false); - entry_to_env("ADDRESSES", address, address_len, false); - entry_to_env("RA_ADDRESSES", ra_pref, ra_pref_len, false); - entry_to_env("RA_ROUTES", ra_route, ra_route_len, false); - entry_to_env("RA_DNS", ra_dns, ra_dns_len, true); + entry_to_env("PREFIXES", prefix, prefix_len, ENTRY_PREFIX); + entry_to_env("ADDRESSES", address, address_len, ENTRY_ADDRESS); + entry_to_env("RA_ADDRESSES", ra_pref, ra_pref_len, ENTRY_ADDRESS); + entry_to_env("RA_ROUTES", ra_route, ra_route_len, ENTRY_ROUTE); + entry_to_env("RA_DNS", ra_dns, ra_dns_len, ENTRY_HOST); argv[2] = (char*)status; execv(argv[0], argv);