about summary refs log tree commit diff
path: root/shared/n-acd/src/n-acd.h
diff options
context:
space:
mode:
Diffstat (limited to 'shared/n-acd/src/n-acd.h')
-rw-r--r--shared/n-acd/src/n-acd.h126
1 files changed, 89 insertions, 37 deletions
diff --git a/shared/n-acd/src/n-acd.h b/shared/n-acd/src/n-acd.h
index 75646243..74b0aacb 100644
--- a/shared/n-acd/src/n-acd.h
+++ b/shared/n-acd/src/n-acd.h
@@ -15,43 +15,22 @@ extern "C" {
 #include <netinet/in.h>
 #include <stdbool.h>
 
+typedef struct NAcd NAcd;
+typedef struct NAcdConfig NAcdConfig;
+typedef struct NAcdEvent NAcdEvent;
+typedef struct NAcdProbe NAcdProbe;
+typedef struct NAcdProbeConfig NAcdProbeConfig;
+
 #define N_ACD_TIMEOUT_RFC5227 (UINT64_C(9000))
 
 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;
+        _N_ACD_E_N,
+};
 
 enum {
         N_ACD_TRANSPORT_ETHERNET,
@@ -74,21 +53,94 @@ enum {
         _N_ACD_DEFEND_N,
 };
 
-int n_acd_new(NAcd **acdp);
-void n_acd_free(NAcd *acd);
+struct NAcdEvent {
+        unsigned int event;
+        union {
+                struct {
+                        NAcdProbe *probe;
+                } ready;
+                struct {
+                } down;
+                struct {
+                        NAcdProbe *probe;
+                        uint8_t *sender;
+                        size_t n_sender;
+                } used, defended, conflict;
+        };
+};
 
-void n_acd_get_fd(NAcd *acd, int *fdp);
+/* configs */
 
+int n_acd_config_new(NAcdConfig **configp);
+NAcdConfig *n_acd_config_free(NAcdConfig *config);
+
+void n_acd_config_set_ifindex(NAcdConfig *config, int ifindex);
+void n_acd_config_set_transport(NAcdConfig *config, unsigned int transport);
+void n_acd_config_set_mac(NAcdConfig *config, const uint8_t *mac, size_t n_mac);
+
+int n_acd_probe_config_new(NAcdProbeConfig **configp);
+NAcdProbeConfig *n_acd_probe_config_free(NAcdProbeConfig *config);
+
+void n_acd_probe_config_set_ip(NAcdProbeConfig *config, struct in_addr ip);
+void n_acd_probe_config_set_timeout(NAcdProbeConfig *config, uint64_t msecs);
+
+/* contexts */
+
+int n_acd_new(NAcd **acdp, NAcdConfig *config);
+NAcd *n_acd_ref(NAcd *acd);
+NAcd *n_acd_unref(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);
-int n_acd_stop(NAcd *acd);
+int n_acd_probe(NAcd *acd, NAcdProbe **probep, NAcdProbeConfig *config);
+
+/* probes */
+
+NAcdProbe *n_acd_probe_free(NAcdProbe *probe);
+
+void n_acd_probe_set_userdata(NAcdProbe *probe, void *userdata);
+void n_acd_probe_get_userdata(NAcdProbe *probe, void **userdatap);
+
+int n_acd_probe_announce(NAcdProbe *probe, unsigned int defend);
+
+/* inline helpers */
+
+static inline void n_acd_config_freep(NAcdConfig **config) {
+        if (*config)
+                n_acd_config_free(*config);
+}
+
+static inline void n_acd_config_freev(NAcdConfig *config) {
+        n_acd_config_free(config);
+}
+
+static inline void n_acd_probe_config_freep(NAcdProbeConfig **config) {
+        if (*config)
+                n_acd_probe_config_free(*config);
+}
+
+static inline void n_acd_probe_config_freev(NAcdProbeConfig *config) {
+        n_acd_probe_config_free(config);
+}
 
-static inline void n_acd_freep(NAcd **acd) {
+static inline void n_acd_unrefp(NAcd **acd) {
         if (*acd)
-                n_acd_free(*acd);
+                n_acd_unref(*acd);
+}
+
+static inline void n_acd_unrefv(NAcd *acd) {
+        n_acd_unref(acd);
+}
+
+static inline void n_acd_probe_freep(NAcdProbe **probe) {
+        if (*probe)
+                n_acd_probe_free(*probe);
+}
+
+static inline void n_acd_probe_freev(NAcdProbe *probe) {
+        n_acd_probe_free(probe);
 }
 
 #ifdef __cplusplus