summaryrefslogtreecommitdiffstats
path: root/src/peer.h
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-03-02 19:41:17 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-03-02 19:41:17 +0100
commit3a4964f5e8c07943474036e594698b313a73d502 (patch)
tree232984b71eed3d874feb179b78272b8d7b69d4fd /src/peer.h
parent0f2e170ea6edee4df0f90a3821d5c054db6bd6b7 (diff)
downloadfastd-3a4964f5e8c07943474036e594698b313a73d502.tar
fastd-3a4964f5e8c07943474036e594698b313a73d502.zip
Allow floating peers
Diffstat (limited to 'src/peer.h')
-rw-r--r--src/peer.h36
1 files changed, 33 insertions, 3 deletions
diff --git a/src/peer.h b/src/peer.h
index e89155e..cd3d1d9 100644
--- a/src/peer.h
+++ b/src/peer.h
@@ -34,10 +34,40 @@
const fastd_eth_addr* fastd_get_source_address(const fastd_context *ctx, fastd_buffer buffer);
const fastd_eth_addr* fastd_get_dest_address(const fastd_context *ctx, fastd_buffer buffer);
-fastd_peer* fastd_peer_init(fastd_context *ctx, fastd_peer_config *conf);
-void fastd_peer_free(fastd_context *ctx, fastd_peer *peer);
+fastd_peer* fastd_peer_add(fastd_context *ctx, fastd_peer_config *conf);
+fastd_peer* fastd_peer_add_temp(fastd_context *ctx, in_addr_t address, in_port_t port);
+fastd_peer* fastd_peer_merge(fastd_context *ctx, fastd_peer *perm_peer, fastd_peer *temp_peer);
+void fastd_peer_delete(fastd_context *ctx, fastd_peer *peer);
-static inline int fastd_eth_addr_is_unicast(const fastd_eth_addr *addr) {
+
+static inline bool fastd_peer_is_floating(fastd_peer *peer) {
+ return (peer->config && !peer->config->address);
+}
+
+static inline bool fastd_peer_is_temporary(fastd_peer *peer) {
+ return (peer->state == STATE_TEMP || peer->state == STATE_TEMP_ESTABLISHED);
+}
+
+static inline bool fastd_peer_is_established(fastd_peer *peer) {
+ return (peer->state == STATE_ESTABLISHED || peer->state == STATE_TEMP_ESTABLISHED);
+}
+
+static inline void fastd_peer_set_established(fastd_context *ctx, fastd_peer *peer) {
+ switch(peer->state) {
+ case STATE_WAIT:
+ peer->state = STATE_ESTABLISHED;
+ break;
+
+ case STATE_TEMP:
+ peer->state = STATE_TEMP_ESTABLISHED;
+ break;
+
+ default:
+ pr_warn(ctx, "tried to set an already established connection to established");
+ }
+}
+
+static inline bool fastd_eth_addr_is_unicast(const fastd_eth_addr *addr) {
return ((addr->data[0] & 1) == 0);
}