diff options
-rw-r--r-- | include/network.h | 6 | ||||
-rw-r--r-- | src/network.c | 5 | ||||
-rw-r--r-- | src/sync-ftfw.c | 36 | ||||
-rw-r--r-- | src/sync-mode.c | 2 |
4 files changed, 43 insertions, 6 deletions
diff --git a/include/network.h b/include/network.h index f9756db..40bb2b2 100644 --- a/include/network.h +++ b/include/network.h @@ -29,6 +29,7 @@ int nethdr_align(int len); int nethdr_size(int len); void nethdr_set(struct nethdr *net, int type); void nethdr_set_ack(struct nethdr *net); +void nethdr_set_ctl(struct nethdr *net); #define NETHDR_DATA(x) \ (struct netattr *)(((char *)x) + NETHDR_SIZ) @@ -102,7 +103,6 @@ ssize_t mcast_buffered_pending_netmsg(struct mcast_sock *m); #define IS_NACK(x) (x->type == NET_T_CTL && x->flags & NET_F_NACK) #define IS_RESYNC(x) (x->type == NET_T_CTL && x->flags & NET_F_RESYNC) #define IS_ALIVE(x) (x->type == NET_T_CTL && x->flags & NET_F_ALIVE) -#define IS_CTL(x) IS_ACK(x) || IS_NACK(x) || IS_RESYNC(x) || IS_ALIVE(x) #define IS_HELLO(x) (x->flags & NET_F_HELLO) #define IS_HELLO_BACK(x)(x->flags & NET_F_HELLO_BACK) @@ -110,7 +110,7 @@ ssize_t mcast_buffered_pending_netmsg(struct mcast_sock *m); ({ \ x->len = ntohs(x->len); \ x->seq = ntohl(x->seq); \ - if (IS_CTL(x)) { \ + if (IS_ACK(x) || IS_NACK(x) || IS_RESYNC(x)) { \ struct nethdr_ack *__ack = (struct nethdr_ack *) x; \ __ack->from = ntohl(__ack->from); \ __ack->to = ntohl(__ack->to); \ @@ -119,7 +119,7 @@ ssize_t mcast_buffered_pending_netmsg(struct mcast_sock *m); #define HDR_HOST2NETWORK(x) \ ({ \ - if (IS_CTL(x)) { \ + if (IS_ACK(x) || IS_NACK(x) || IS_RESYNC(x)) { \ struct nethdr_ack *__ack = (struct nethdr_ack *) x; \ __ack->from = htonl(__ack->from); \ __ack->to = htonl(__ack->to); \ diff --git a/src/network.c b/src/network.c index 98df5ea..090dec8 100644 --- a/src/network.c +++ b/src/network.c @@ -61,6 +61,11 @@ void nethdr_set_ack(struct nethdr *net) __nethdr_set(net, NETHDR_ACK_SIZ, NET_T_CTL); } +void nethdr_set_ctl(struct nethdr *net) +{ + __nethdr_set(net, NETHDR_SIZ, NET_T_CTL); +} + static size_t tx_buflenmax; static size_t tx_buflen = 0; static char *tx_buf; diff --git a/src/sync-ftfw.c b/src/sync-ftfw.c index 014cebd..4758710 100644 --- a/src/sync-ftfw.c +++ b/src/sync-ftfw.c @@ -121,6 +121,31 @@ static void tx_queue_add_ctlmsg(uint32_t flags, uint32_t from, uint32_t to) write_evfd(STATE_SYNC(evfd)); } +static void tx_queue_add_ctlmsg2(uint32_t flags) +{ + struct nethdr ctl = { + .type = NET_T_CTL, + .flags = flags, + }; + + switch(hello_state) { + case HELLO_INIT: + hello_state = HELLO_SAY; + /* fall through */ + case HELLO_SAY: + ctl.flags |= NET_F_HELLO; + break; + } + + if (say_hello_back) { + ctl.flags |= NET_F_HELLO_BACK; + say_hello_back = 0; + } + + queue_add(tx_queue, &ctl, NETHDR_SIZ); + write_evfd(STATE_SYNC(evfd)); +} + /* this function is called from the alarm framework */ static void do_alive_alarm(struct alarm_block *a, void *data) { @@ -131,7 +156,7 @@ static void do_alive_alarm(struct alarm_block *a, void *data) STATE_SYNC(last_seq_recv)); ack_from_set = 0; } else - tx_queue_add_ctlmsg(NET_F_ALIVE, 0, 0); + tx_queue_add_ctlmsg2(NET_F_ALIVE); } static int ftfw_init(void) @@ -491,7 +516,14 @@ static int tx_queue_xmit(void *data1, const void *data2) { struct nethdr *net = data1; - nethdr_set_ack(net); + if (IS_ACK(net) || IS_NACK(net) || IS_RESYNC(net)) { + nethdr_set_ack(net); + } else if (IS_ALIVE(net)) { + nethdr_set_ctl(net); + } else { + dlog(LOG_ERR, "sending unknown control message?"); + return 0; + } HDR_HOST2NETWORK(net); dp("tx_queue sq: %u fl:%u len:%u\n", diff --git a/src/sync-mode.c b/src/sync-mode.c index d5355a7..b2b78ad 100644 --- a/src/sync-mode.c +++ b/src/sync-mode.c @@ -131,7 +131,7 @@ static void mcast_handler(void) break; } - if (IS_CTL(net)) { + if (IS_ACK(net) || IS_NACK(net) || IS_RESYNC(net)) { if (remain < NETHDR_ACK_SIZ) { STATE(malformed)++; dlog(LOG_WARNING, "no room for ctl message"); |