NetworkManager/src/core/nm-l3-ipv4ll.h
Thomas Haller ac1a9e03e4
all: move "src/" directory to "src/core/"
Currently "src/" mostly contains the source code of the daemon.
I say mostly, because that is not true, there are also the device,
settings, wwan, ppp plugins, the initrd generator, the pppd and dhcp
helper, and probably more.

Also we have source code under libnm-core/, libnm/, clients/, and
shared/ directories. That is all confusing.

We should have one "src" directory, that contains subdirectories. Those
subdirectories should contain individual parts (libraries or
applications), that possibly have dependencies on other subdirectories.
There should be a flat hierarchy of directories under src/, which
contains individual modules.

As the name "src/" is already taken, that prevents any sensible
restructuring of the code.

As a first step, move "src/" to "src/core/". This gives space to
reorganize the code better by moving individual components into "src/".

For inspiration, look at systemd's "src/" directory.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/743
2021-02-04 09:45:55 +01:00

118 lines
3.8 KiB
C

/* SPDX-License-Identifier: LGPL-2.1-or-later */
#ifndef __NM_L3_IPV4LL_H__
#define __NM_L3_IPV4LL_H__
#include "nm-l3cfg.h"
/*****************************************************************************/
typedef enum _nm_packed {
NM_L3_IPV4LL_STATE_UNKNOWN,
NM_L3_IPV4LL_STATE_DISABLED,
NM_L3_IPV4LL_STATE_WAIT_FOR_LINK,
NM_L3_IPV4LL_STATE_EXTERNAL,
NM_L3_IPV4LL_STATE_PROBING,
NM_L3_IPV4LL_STATE_READY,
NM_L3_IPV4LL_STATE_DEFENDING,
} NML3IPv4LLState;
const char *nm_l3_ipv4ll_state_to_string(NML3IPv4LLState val, char *buf, gsize len);
static inline gboolean
nm_l3_ipv4ll_state_is_good(NML3IPv4LLState state)
{
switch (state) {
case NM_L3_IPV4LL_STATE_UNKNOWN:
case NM_L3_IPV4LL_STATE_DISABLED:
case NM_L3_IPV4LL_STATE_WAIT_FOR_LINK:
case NM_L3_IPV4LL_STATE_PROBING:
return FALSE;
case NM_L3_IPV4LL_STATE_EXTERNAL:
case NM_L3_IPV4LL_STATE_READY:
case NM_L3_IPV4LL_STATE_DEFENDING:
return TRUE;
}
return nm_assert_unreachable_val(FALSE);
}
/*****************************************************************************/
typedef struct _NML3IPv4LL NML3IPv4LL;
static inline gboolean
NM_IS_L3_IPV4LL(const NML3IPv4LL *self)
{
nm_assert(!self
|| (NM_IS_L3CFG(*((NML3Cfg **) self))
&& (*((int *) (((char *) self) + sizeof(gpointer)))) > 0));
return !!self;
}
NML3IPv4LL *nm_l3_ipv4ll_new(NML3Cfg *self);
NML3IPv4LL *nm_l3_ipv4ll_ref(NML3IPv4LL *self);
void nm_l3_ipv4ll_unref(NML3IPv4LL *self);
NM_AUTO_DEFINE_FCN0(NML3IPv4LL *, _nm_auto_unref_l3ipv4ll, nm_l3_ipv4ll_unref);
#define nm_auto_unref_l3ipv4ll nm_auto(_nm_auto_unref_l3ipv4ll)
/*****************************************************************************/
NML3Cfg *nm_l3_ipv4ll_get_l3cfg(NML3IPv4LL *self);
int nm_l3_ipv4ll_get_ifindex(NML3IPv4LL *self);
NMPlatform *nm_l3_ipv4ll_get_platform(NML3IPv4LL *self);
/*****************************************************************************/
/* By default, NML3IPv4LL is disabled. You also need to register (enable) it.
* The intent of this API is that multiple users can enable/register their own
* settings, and NML3IPv4LL will mediate the different requests.
*
* Also, by setting timeout_msec to zero, NML3IPv4LL is disabled again (zero
* wins over all timeouts). This is useful if you do DHCP and IPv4LL on the
* same interface. You possibly want to disable IPv4LL if you have a valid
* DHCP lease. By registering a timeout_msec to zero, you can disable IPv4LL.
*
* Also, a registration keeps the NML3IPv4LL instance alive (it also takes
* a reference). */
typedef struct _NML3IPv4LLRegistration NML3IPv4LLRegistration;
NML3IPv4LLRegistration *nm_l3_ipv4ll_register_new(NML3IPv4LL *self, guint timeout_msec);
NML3IPv4LLRegistration *nm_l3_ipv4ll_register_update(NML3IPv4LLRegistration *reg,
guint timeout_msec);
NML3IPv4LLRegistration *nm_l3_ipv4ll_register_remove(NML3IPv4LLRegistration *reg);
NM_AUTO_DEFINE_FCN0(NML3IPv4LLRegistration *,
_nm_auto_remove_l3ipv4ll_registration,
nm_l3_ipv4ll_register_remove);
#define nm_auto_remove_l3ipv4ll_registration nm_auto(_nm_auto_remove_l3ipv4ll_registration)
static inline NML3IPv4LL *
nm_l3_ipv4ll_register_get_instance(NML3IPv4LLRegistration *reg)
{
NML3IPv4LL *ipv4ll;
if (!reg)
return NULL;
ipv4ll = *((NML3IPv4LL **) reg);
nm_assert(NM_IS_L3_IPV4LL(ipv4ll));
return ipv4ll;
}
/*****************************************************************************/
NML3IPv4LLState nm_l3_ipv4ll_get_state(NML3IPv4LL *self);
gboolean nm_l3_ipv4ll_is_timed_out(NML3IPv4LL *self);
in_addr_t nm_l3_ipv4ll_get_addr(NML3IPv4LL *self);
const NML3ConfigData *nm_l3_ipv4ll_get_l3cd(NML3IPv4LL *self);
#endif /* __NM_L3_IPV4LL_H__ */