X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=src%2Fscript.c;h=389dc3708b05c1bb97d1597dfa4c67ef4502a937;hb=e3aa092cc84fc6eff6051c6ae306c085b50271ab;hp=44ce80e8683d67ad5e42834fcd88e914c863e2e8;hpb=fd9801a99fa0d3eea8aad5d19c5c8db8cb779a82;p=odhcp6c.git diff --git a/src/script.c b/src/script.c index 44ce80e..389dc37 100644 --- a/src/script.c +++ b/src/script.c @@ -238,6 +238,9 @@ static void s46_to_env(enum odhcp6c_state state, const uint8_t *data, size_t len fputc('=', fp); #ifdef EXT_S46 + const char *type = (state == STATE_S46_MAPE) ? "map-e" : + (state == STATE_S46_MAPT) ? "map-t" : "lw4o6"; + uint8_t *odata; uint16_t otype, olen; dhcpv6_for_each_option(data, &data[len], otype, olen, odata) { @@ -246,12 +249,18 @@ static void s46_to_env(enum odhcp6c_state state, const uint8_t *data, size_t len struct dhcpv6_s46_v4v6bind *bind = (struct dhcpv6_s46_v4v6bind*)odata; if (state != STATE_S46_LW && otype == DHCPV6_OPT_S46_RULE && - olen >= sizeof(struct dhcpv6_s46_rule) && olen >= - sizeof(struct dhcpv6_s46_rule) + rule->prefix6_len) { + olen >= sizeof(struct dhcpv6_s46_rule)) { char buf4[INET_ADDRSTRLEN]; char buf6[INET6_ADDRSTRLEN]; struct in6_addr in6 = IN6ADDR_ANY_INIT; - memcpy(&in6, rule->ipv6_prefix, rule->prefix6_len); + + size_t prefix6len = rule->prefix6_len; + prefix6len = (prefix6len % 8 == 0) ? prefix6len / 8 : prefix6len / 8 + 1; + + if (olen < sizeof(struct dhcpv6_s46_rule) + prefix6len) + continue; + + memcpy(&in6, rule->ipv6_prefix, prefix6len); inet_ntop(AF_INET, &rule->ipv4_prefix, buf4, sizeof(buf4)); inet_ntop(AF_INET6, &in6, buf6, sizeof(buf6)); @@ -259,11 +268,11 @@ static void s46_to_env(enum odhcp6c_state state, const uint8_t *data, size_t len if (rule->flags & 1) fputs("fmr,", fp); - fprintf(fp, "ealen=%d,prefix4len=%d,prefix6len=%d,ipv4prefix=%s,ipv6prefix=%s,", - rule->ea_len, rule->prefix4_len, rule->prefix6_len, buf4, buf6); + fprintf(fp, "type=%s,ealen=%d,prefix4len=%d,prefix6len=%d,ipv4prefix=%s,ipv6prefix=%s,", + type, rule->ea_len, rule->prefix4_len, rule->prefix6_len, buf4, buf6); - s46_to_env_portparams(&rule->ipv6_prefix[rule->prefix6_len], - olen - sizeof(*rule) - rule->prefix6_len, fp); + s46_to_env_portparams(&rule->ipv6_prefix[prefix6len], + olen - sizeof(*rule) - prefix6len, fp); dhcpv6_for_each_option(data, &data[len], otype, olen, odata) { if (state != STATE_S46_MAPT && otype == DHCPV6_OPT_S46_BR && @@ -271,30 +280,42 @@ static void s46_to_env(enum odhcp6c_state state, const uint8_t *data, size_t len inet_ntop(AF_INET6, odata, buf6, sizeof(buf6)); fprintf(fp, "br=%s,", buf6); } else if (state == STATE_S46_MAPT && otype == DHCPV6_OPT_S46_DMR && - olen >= sizeof(struct dhcpv6_s46_dmr) && olen >= - sizeof(struct dhcpv6_s46_dmr) + dmr->dmr_prefix6_len) { + olen >= sizeof(struct dhcpv6_s46_dmr)) { + dmr = (struct dhcpv6_s46_dmr*)odata; memset(&in6, 0, sizeof(in6)); - memcpy(&in6, dmr->dmr_ipv6_prefix, dmr->dmr_prefix6_len); + size_t prefix6len = dmr->dmr_prefix6_len; + prefix6len = (prefix6len % 8 == 0) ? prefix6len / 8 : prefix6len / 8 + 1; + + if (olen < sizeof(struct dhcpv6_s46_dmr) + prefix6len) + continue; + + memcpy(&in6, dmr->dmr_ipv6_prefix, prefix6len); inet_ntop(AF_INET6, &in6, buf6, sizeof(buf6)); fprintf(fp, "dmr=%s/%d,", buf6, dmr->dmr_prefix6_len); } } } else if (state == STATE_S46_LW && otype == DHCPV6_OPT_S46_V4V6BIND && - olen >= sizeof(struct dhcpv6_s46_v4v6bind) && olen >= - sizeof(struct dhcpv6_s46_v4v6bind) + bind->bindprefix6_len) { + olen >= sizeof(struct dhcpv6_s46_v4v6bind)) { char buf4[INET_ADDRSTRLEN]; char buf6[INET6_ADDRSTRLEN]; struct in6_addr in6 = IN6ADDR_ANY_INIT; - memcpy(&in6, bind->bind_ipv6_prefix, bind->bindprefix6_len); + + size_t prefix6len = bind->bindprefix6_len; + prefix6len = (prefix6len % 8 == 0) ? prefix6len / 8 : prefix6len / 8 + 1; + + if (olen < sizeof(struct dhcpv6_s46_v4v6bind) + prefix6len) + continue; + + memcpy(&in6, bind->bind_ipv6_prefix, prefix6len); inet_ntop(AF_INET, &bind->ipv4_address, buf4, sizeof(buf4)); inet_ntop(AF_INET6, &in6, buf6, sizeof(buf6)); - fprintf(fp, "ipv4address=%s,prefix6len=%d,ipv6prefix=%s,", - buf4, bind->bindprefix6_len, buf6); + fprintf(fp, "type=%s,ipv4address=%s,prefix6len=%d,ipv6prefix=%s,", + type, buf4, bind->bindprefix6_len, buf6); - s46_to_env_portparams(&bind->bind_ipv6_prefix[bind->bindprefix6_len], - olen - sizeof(*bind) - bind->bindprefix6_len, fp); + s46_to_env_portparams(&bind->bind_ipv6_prefix[prefix6len], + olen - sizeof(*bind) - prefix6len, fp); dhcpv6_for_each_option(data, &data[len], otype, olen, odata) { if (otype == DHCPV6_OPT_S46_BR && olen == sizeof(struct in6_addr)) { @@ -338,7 +359,7 @@ void script_call(const char *status) { size_t dns_len, search_len, custom_len, sntp_ip_len, ntp_ip_len, ntp_dns_len; size_t sip_ip_len, sip_fqdn_len, aftr_name_len, cer_len; - size_t s46_mapt_len, s46_mape_len, s46_lw_len; + size_t s46_mapt_len, s46_mape_len, s46_lw_len, passthru_len; odhcp6c_expire(); if (delayed_call) { @@ -359,6 +380,7 @@ void script_call(const char *status) uint8_t *s46_mapt = odhcp6c_get_state(STATE_S46_MAPT, &s46_mapt_len); uint8_t *s46_mape = odhcp6c_get_state(STATE_S46_MAPE, &s46_mape_len); uint8_t *s46_lw = odhcp6c_get_state(STATE_S46_LW, &s46_lw_len); + uint8_t *passthru = odhcp6c_get_state(STATE_PASSTHRU, &passthru_len); size_t prefix_len, address_len, ra_pref_len, ra_route_len, ra_dns_len; uint8_t *prefix = odhcp6c_get_state(STATE_IA_PD, &prefix_len); @@ -389,6 +411,11 @@ void script_call(const char *status) entry_to_env("RA_ROUTES", ra_route, ra_route_len, ENTRY_ROUTE); entry_to_env("RA_DNS", ra_dns, ra_dns_len, ENTRY_HOST); + char *buf = malloc(10 + passthru_len * 2); + strncpy(buf, "PASSTHRU=", 10); + script_hexlify(&buf[9], passthru, passthru_len); + putenv(buf); + argv[2] = (char*)status; execv(argv[0], argv); _exit(128);