summaryrefslogtreecommitdiff
path: root/src/n-acd.h
blob: 97276cfca8b16c6f761391b79368adea3fb155cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#pragma once

/*
 * IPv4 Address Conflict Detection
 *
 * This is the public header of the n-acd library, implementing IPv4 Address
 * Conflict Detection as described in RFC-5227. This header defines the public
 * API and all entry points of n-acd.
 */

#ifdef __cplusplus
extern "C" {
#endif

#include <netinet/in.h>
#include <stdbool.h>

enum {
        _N_ACD_E_SUCCESS,

        N_ACD_E_DONE,
        N_ACD_E_STOPPED,
        N_ACD_E_PREEMPTED,

        N_ACD_E_INVALID_ARGUMENT,
        N_ACD_E_BUSY,
};

typedef struct NAcd NAcd;

typedef struct NAcdConfig {
        int ifindex;
        unsigned int transport;
        const uint8_t *mac;
        size_t n_mac;
        struct in_addr ip;
        uint64_t timeout_msec;
} NAcdConfig;

typedef struct NAcdEvent {
        unsigned int event;
        union {
                struct {
                } ready, down;
                struct {
                        uint16_t operation;
                        uint8_t *sender;
                        size_t n_sender;
                        struct in_addr target;
                } used, defended, conflict;
        };
} NAcdEvent;

enum {
        N_ACD_TRANSPORT_ETHERNET,
        _N_ACD_TRANSPORT_N,
};

enum {
        N_ACD_EVENT_READY,
        N_ACD_EVENT_USED,
        N_ACD_EVENT_DEFENDED,
        N_ACD_EVENT_CONFLICT,
        N_ACD_EVENT_DOWN,
        _N_ACD_EVENT_N,
};

enum {
        N_ACD_DEFEND_NEVER,
        N_ACD_DEFEND_ONCE,
        N_ACD_DEFEND_ALWAYS,
        _N_ACD_DEFEND_N,
};

int n_acd_new(NAcd **acdp);
NAcd *n_acd_free(NAcd *acd);

void n_acd_get_fd(NAcd *acd, int *fdp);

int n_acd_dispatch(NAcd *acd);
int n_acd_pop_event(NAcd *acd, NAcdEvent **eventp);
int n_acd_announce(NAcd *acd, unsigned int defend);

int n_acd_start(NAcd *acd, NAcdConfig *config);
void n_acd_stop(NAcd *acd);

static inline void n_acd_freep(NAcd **acd) {
        if (*acd)
                n_acd_free(*acd);
}

#ifdef __cplusplus
}
#endif