--- fwsync/driver/fwsync.c 2022/06/22 13:01:55 1.1.1.1 +++ fwsync/driver/fwsync.c 2022/07/05 21:50:36 1.4 @@ -8,12 +8,44 @@ static intptr_t fwsync_wchan; +static int +fwsync_add_state_4(const struct fws_proto *pkt) +{ + DTRACE(); + + return 0; +} + +static int +fwsync_add_state_6(const struct fws_proto *pkt) +{ + DTRACE(); + + return 0; +} + +static int +fwsync_add_state(const struct fws_proto *pkt) +{ + DTRACE(); + + if (pkt->fws_addrtype == 4) + fwsync_add_state_4(pkt); + else if (pkt->fws_addrtype == 6) + fwsync_add_state_6(pkt); + else + return EINVAL; + + return 0; +} + static void fwsync_edge_proc(void *arg) { - int e, rcvflg; + int e, rcvflg = 0; struct uio uio; struct mbuf *m = NULL; + struct fws_proto *pkt; DTRACE(); @@ -34,8 +66,27 @@ fwsync_edge_proc(void *arg) tsleep(&fwsync_wchan, 0, "edge_handler", hz); continue; } + pkt = mtod(m, struct fws_proto*); + if (m_length(m, NULL) != sizeof(struct fws_proto)) { + printf("FWSync packet length=%d isn't match expected %lu\n", + m_length(m, NULL), sizeof(struct fws_proto)); + continue; + } - printf("%u...-> %s\n", m->m_len, m->m_data); + switch (pkt->fws_version) { + case FWS_PKTVER_STATE: + fwsync_add_state(pkt); + break; + case FWS_PKTVER_ALIAS_OUT: + break; + case FWS_PKTVER_ALIAS_IN: + break; + default: + printf("FWSync packet was discarded due to wrong version\n"); + continue; + } + + printf("%u...-> %s version=%c\n", m->m_len, m->m_data, pkt->fws_version); } fws_ctx.config &= ~CTX_EDGE_ONLINE; @@ -285,8 +336,6 @@ fwsync_start(struct ip_fw_chain *ch, ip_fw3_opheader * fws_ctx.config |= CTX_COLLECTOR_2_ONLINE; } - /* at last but not at least, activate config status of started sync service */ - fws_cfg.cfg.on |= *n; return 0; } @@ -328,7 +377,5 @@ fwsync_stop(struct ip_fw_chain *ch, ip_fw3_opheader *o ipfw_unregister_alias_hook(); } - /* at last but not at least, stop sync service */ - fws_cfg.cfg.on &= ~*n; return 0; }