]> git.decadent.org.uk Git - odhcp6c.git/blobdiff - src/script.c
Add support for DHCPv6 option passthru
[odhcp6c.git] / src / script.c
index 6caaffd7f19e67ed149e0cb9551690c475e2c130..389dc3708b05c1bb97d1597dfa4c67ef4502a937 100644 (file)
@@ -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) {
@@ -265,8 +268,8 @@ 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[prefix6len],
                                        olen - sizeof(*rule) - prefix6len, fp);
@@ -278,6 +281,7 @@ static void s46_to_env(enum odhcp6c_state state, const uint8_t *data, size_t len
                                        fprintf(fp, "br=%s,", buf6);
                                } else if (state == STATE_S46_MAPT && otype == DHCPV6_OPT_S46_DMR &&
                                                olen >= sizeof(struct dhcpv6_s46_dmr)) {
+                                       dmr = (struct dhcpv6_s46_dmr*)odata;
                                        memset(&in6, 0, sizeof(in6));
                                        size_t prefix6len = dmr->dmr_prefix6_len;
                                        prefix6len = (prefix6len % 8 == 0) ? prefix6len / 8 : prefix6len / 8 + 1;
@@ -307,8 +311,8 @@ static void s46_to_env(enum odhcp6c_state state, const uint8_t *data, size_t len
                        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[prefix6len],
                                        olen - sizeof(*bind) - prefix6len, fp);
@@ -355,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) {
@@ -376,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);
@@ -406,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);