diff --git a/libifupdown/lifecycle.c b/libifupdown/lifecycle.c index fd030f1..33c6308 100644 --- a/libifupdown/lifecycle.c +++ b/libifupdown/lifecycle.c @@ -13,6 +13,7 @@ * from the use of this software. */ +#include #include #include "libifupdown/environment.h" @@ -183,6 +184,49 @@ lif_lifecycle_run_phase(const struct lif_execute_opts *opts, struct lif_interfac else lif_environment_push(&envp, "MODE", "stop"); + struct lif_node *iter; + bool did_address = false, did_gateway = false; + + LIF_DICT_FOREACH(iter, &iface->vars) + { + struct lif_dict_entry *entry = iter->data; + + if (!strcmp(entry->key, "address")) + { + if (did_address) + continue; + + struct lif_address *addr = entry->data; + char addrbuf[4096]; + + if (!lif_address_unparse(addr, addrbuf, sizeof addrbuf, true)) + continue; + + lif_environment_push(&envp, "IF_ADDRESS", addrbuf); + did_address = true; + + continue; + } + else if (!strcmp(entry->key, "gateway")) + { + if (did_gateway) + continue; + + did_gateway = true; + } + + char envkey[4096] = "IF_"; + strlcat(envkey, entry->key, sizeof envkey); + char *ep = envkey + 2; + + while (*ep++) + { + *ep = toupper(*ep); + } + + lif_environment_push(&envp, envkey, (const char *) entry->data); + } + if (!strcmp(phase, "pre-up")) { if (!handle_pre_up(opts, iface, lifname))