add core state management
This commit is contained in:
parent
6606432600
commit
d4e1997486
3 changed files with 78 additions and 2 deletions
48
libifupdown/state.c
Normal file
48
libifupdown/state.c
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* libifupdown/state.h
|
||||
* Purpose: state management
|
||||
*
|
||||
* Copyright (c) 2020 Ariadne Conill <ariadne@dereferenced.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* This software is provided 'as is' and without any warranty, express or
|
||||
* implied. In no event shall the authors be liable for any damages arising
|
||||
* from the use of this software.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "libifupdown/state.h"
|
||||
|
||||
void
|
||||
lif_state_upsert(struct lif_dict *state, const char *ifname, struct lif_interface *iface)
|
||||
{
|
||||
lif_dict_add(state, ifname, strdup(iface->ifname));
|
||||
}
|
||||
|
||||
void
|
||||
lif_state_delete(struct lif_dict *state, const char *ifname)
|
||||
{
|
||||
struct lif_dict_entry *entry = lif_dict_find(state, ifname);
|
||||
|
||||
if (entry == NULL)
|
||||
return;
|
||||
|
||||
free(entry->data);
|
||||
lif_dict_delete_entry(state, entry);
|
||||
}
|
||||
|
||||
void
|
||||
lif_state_write(const struct lif_dict *state, FILE *f)
|
||||
{
|
||||
struct lif_node *iter;
|
||||
|
||||
LIF_DICT_FOREACH(iter, state)
|
||||
{
|
||||
struct lif_dict_entry *entry = iter->data;
|
||||
|
||||
fprintf(f, "%s=%s\n", entry->key, (const char *) entry->data);
|
||||
}
|
||||
}
|
||||
26
libifupdown/state.h
Normal file
26
libifupdown/state.h
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* libifupdown/state.h
|
||||
* Purpose: state management
|
||||
*
|
||||
* Copyright (c) 2020 Ariadne Conill <ariadne@dereferenced.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* This software is provided 'as is' and without any warranty, express or
|
||||
* implied. In no event shall the authors be liable for any damages arising
|
||||
* from the use of this software.
|
||||
*/
|
||||
|
||||
#ifndef LIBIFUPDOWN_STATE_H__GUARD
|
||||
#define LIBIFUPDOWN_STATE_H__GUARD
|
||||
|
||||
#include <stdio.h>
|
||||
#include "libifupdown/interface.h"
|
||||
|
||||
extern void lif_state_upsert(struct lif_dict *state, const char *ifname, struct lif_interface *iface);
|
||||
extern void lif_state_delete(struct lif_dict *state, const char *ifname);
|
||||
extern void lif_state_write(const struct lif_dict *state, FILE *f);
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue