2020-07-18 10:24:53 +00:00
|
|
|
/*
|
|
|
|
* libifupdown/interface.h
|
|
|
|
* Purpose: interface management
|
|
|
|
*
|
|
|
|
* Copyright (c) 2020 Ariadne Conill <ariadne@dereferenced.org>
|
2020-09-25 00:15:16 +00:00
|
|
|
* Copyright (c) 2020 Maximilian Wilhelm <max@sdn.clinic>
|
2020-07-18 10:24:53 +00:00
|
|
|
*
|
|
|
|
* 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_INTERFACE_H__GUARD
|
|
|
|
#define LIBIFUPDOWN_INTERFACE_H__GUARD
|
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "libifupdown/dict.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Addresses are stored in a buffer with netmask and type.
|
|
|
|
*/
|
|
|
|
struct lif_address {
|
|
|
|
unsigned char addr_buf[sizeof(struct in6_addr)];
|
|
|
|
size_t netmask;
|
|
|
|
int domain;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern bool lif_address_parse(struct lif_address *address, const char *presentation);
|
|
|
|
extern bool lif_address_unparse(const struct lif_address *address, char *buf, size_t buflen, bool with_netmask);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interfaces are contained in a dictionary, with the interfaces mapped by
|
|
|
|
* interface name to their `struct lif_interface`.
|
|
|
|
*
|
|
|
|
* Interfaces are simply upserted as needed. This allows for `auto eth0`
|
|
|
|
* to create a placeholder `struct lif_interface` with auto set to true.
|
|
|
|
*
|
|
|
|
* Configuration variables are simply stored in a `struct lif_dict`, which
|
|
|
|
* can act as a multidict.
|
|
|
|
*/
|
|
|
|
struct lif_interface {
|
|
|
|
char *ifname;
|
|
|
|
|
|
|
|
bool is_auto;
|
2020-07-24 10:37:14 +00:00
|
|
|
bool is_bridge;
|
|
|
|
bool is_bond;
|
2020-09-23 17:29:01 +00:00
|
|
|
bool is_template;
|
2020-09-25 14:23:51 +00:00
|
|
|
bool is_pending;
|
2020-07-18 10:24:53 +00:00
|
|
|
|
2020-09-25 00:15:16 +00:00
|
|
|
bool has_config_error; /* error found in interface configuration */
|
|
|
|
|
2020-07-18 10:24:53 +00:00
|
|
|
struct lif_dict vars;
|
2020-07-24 09:42:34 +00:00
|
|
|
|
2020-09-09 23:13:11 +00:00
|
|
|
size_t refcount; /* > 0 if up, else 0 */
|
|
|
|
size_t rdepends_count; /* > 0 if any reverse dependency */
|
2020-07-18 10:24:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define LIF_INTERFACE_COLLECTION_FOREACH(iter, collection) \
|
|
|
|
LIF_DICT_FOREACH((iter), (collection))
|
|
|
|
|
|
|
|
#define LIF_INTERFACE_COLLECTION_FOREACH_SAFE(iter, iter_next, collection) \
|
|
|
|
LIF_DICT_FOREACH_SAFE((iter), (iter_next), (collection))
|
|
|
|
|
|
|
|
extern void lif_interface_init(struct lif_interface *interface, const char *ifname);
|
|
|
|
extern bool lif_interface_address_add(struct lif_interface *interface, const char *address);
|
|
|
|
extern void lif_interface_address_delete(struct lif_interface *interface, const char *address);
|
|
|
|
extern void lif_interface_fini(struct lif_interface *interface);
|
2020-08-20 09:08:29 +00:00
|
|
|
extern void lif_interface_use_executor(struct lif_interface *interface, const char *executor);
|
2020-07-18 10:24:53 +00:00
|
|
|
|
|
|
|
extern void lif_interface_collection_init(struct lif_dict *collection);
|
|
|
|
extern void lif_interface_collection_fini(struct lif_dict *collection);
|
|
|
|
extern struct lif_interface *lif_interface_collection_find(struct lif_dict *collection, const char *ifname);
|
|
|
|
extern struct lif_interface *lif_interface_collection_upsert(struct lif_dict *collection, struct lif_interface *interface);
|
2020-09-25 00:15:16 +00:00
|
|
|
extern bool lif_interface_collection_inherit(struct lif_interface *interface, struct lif_interface *parent);
|
2020-07-18 10:24:53 +00:00
|
|
|
extern void lif_interface_collection_delete(struct lif_dict *collection, struct lif_interface *interface);
|
|
|
|
|
|
|
|
#endif
|