--- fwsync/driver/fwsync_workers.c 2022/08/11 21:59:05 1.10 +++ fwsync/driver/fwsync_workers.c 2022/08/13 18:44:02 1.13 @@ -31,8 +31,22 @@ fwsync_add_state(const struct fws_proto *pkt) int fwsync_add_alias(const struct fws_proto *pkt) { + struct fws_sndpkt *p; + DTRACE(); + if (!pkt || pkt->fws_addrtype == 1) + return 0; /* skip ethernet packet */ + + p = malloc(sizeof(struct fws_sndpkt), M_FWSYNC, M_NOWAIT | M_ZERO); + if (!p) { + return ENOMEM; + } else + memcpy(&p->sp_proto, pkt, sizeof(struct fws_proto)); + + mtx_lock(&fws_mtx_n); + TAILQ_INSERT_TAIL(&fwsync_natpkt, p, sp_next); + mtx_unlock(&fws_mtx_n); return 0; } @@ -254,6 +268,34 @@ fwsync_state_sync(const void *arg, const void *extdata ipfw_dyn_install_sync_state(&fid, rule, pkt->sp_proto.fws_ruleid, pkt->sp_proto.fws_rulenum, pkt->sp_proto.fws_kidx, pkt->sp_proto.fws_cmdtype); + + free(pkt, M_FWSYNC); + return 0; +} + +int +fwsync_alias_sync(const void *arg, const void *extdata) +{ + struct fws_sndpkt *pkt; + + DTRACE(); + + mtx_lock(&fws_mtx_n); + pkt = TAILQ_FIRST(&fwsync_natpkt); + if (pkt) + TAILQ_REMOVE(&fwsync_natpkt, pkt, sp_next); + mtx_unlock(&fws_mtx_n); + + if (!pkt) /* update queue is empty */ + return 0; + + if (!(fws_cfg.cfg.on & CFG_SYNC_EDGE)) { + free(pkt, M_FWSYNC); + return EAGAIN; + } + + // TODO: xxx + printf("%s: pkt=%p\n", __func__, pkt); free(pkt, M_FWSYNC); return 0;