Blame src/nm-l3-ipv4ll.h

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