lifecycle: implement support for IF_ env vars based on triples
This commit is contained in:
parent
a19a8e2ccc
commit
1824d05bd5
1 changed files with 44 additions and 0 deletions
|
@ -13,6 +13,7 @@
|
|||
* from the use of this software.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
#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))
|
||||
|
|
Loading…
Reference in a new issue