|
version 1.2, 2022/06/29 19:44:58
|
version 1.6, 2022/07/15 09:19:25
|
|
Line 5
|
Line 5
|
| #include "fwsync.h" |
#include "fwsync.h" |
| |
|
| |
|
| |
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; |
| |
} |
| |
|
| |
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; |
| |
} |
| |
|
| |
int |
| |
fwsync_add_alias(const struct fws_proto *pkt) |
| |
{ |
| |
DTRACE(); |
| |
|
| |
return 0; |
| |
} |
| |
|
| |
|
| void |
void |
| fwsync_sndpkt_state(void *context, int pending) | fwsync_sndpkt_handler(void *context, int pending) |
| { |
{ |
| struct fws_sndpkt *pkt; |
struct fws_sndpkt *pkt; |
| struct mbuf *m2, *m; |
struct mbuf *m2, *m; |
|
Line 19 fwsync_sndpkt_state(void *context, int pending)
|
Line 59 fwsync_sndpkt_state(void *context, int pending)
|
| do { |
do { |
| mtx_lock(&fws_mtx_c); |
mtx_lock(&fws_mtx_c); |
| pkt = TAILQ_FIRST(&fwsync_sndpkt); |
pkt = TAILQ_FIRST(&fwsync_sndpkt); |
| TAILQ_REMOVE(&fwsync_sndpkt, pkt, sp_next); | if (pkt) |
| | TAILQ_REMOVE(&fwsync_sndpkt, pkt, sp_next); |
| mtx_unlock(&fws_mtx_c); |
mtx_unlock(&fws_mtx_c); |
| |
|
| if (!(fws_cfg.cfg.on & CFG_SYNC_COLLECTOR)) | if (!pkt) /* sending queue is empty */ |
| | break; |
| | |
| | if (!(fws_cfg.cfg.on & CFG_SYNC_COLLECTOR)) { |
| | free(pkt, M_FWSYNC); |
| continue; |
continue; |
| |
} |
| |
|
| m = m_gethdr(M_NOWAIT, MT_DATA); |
m = m_gethdr(M_NOWAIT, MT_DATA); |
| if (!m) | if (!m) { |
| | free(pkt, M_FWSYNC); |
| continue; |
continue; |
| |
} |
| |
|
| memcpy(mtod(m, struct fws_proto *), &pkt->sp_proto, sizeof pkt->sp_proto); |
memcpy(mtod(m, struct fws_proto *), &pkt->sp_proto, sizeof pkt->sp_proto); |
| m->m_len = sizeof pkt->sp_proto; |
m->m_len = sizeof pkt->sp_proto; |
|
Line 62 fwsync_sndpkt_state(void *context, int pending)
|
Line 110 fwsync_sndpkt_state(void *context, int pending)
|
| } |
} |
| out: |
out: |
| m_freem(m); |
m_freem(m); |
| |
free(pkt, M_FWSYNC); |
| } while (--pending); |
} while (--pending); |
| } |
} |
| |
|
| int |
int |
| fwsync_state_handler(void *arg) | fwsync_state_handler(const void *arg) |
| { |
{ |
| struct ipfw_flow_id *pkt = arg; | const struct ipfw_flow_id *pkt = arg; |
| struct fws_proto *spkt; |
struct fws_proto *spkt; |
| struct fws_sndpkt *p; |
struct fws_sndpkt *p; |
| |
|
| DTRACE(); |
DTRACE(); |
| |
|
| if (pkt->addr_type == 1) | if (!pkt || pkt->addr_type == 1) |
| return 0; /* skip ethernet packet */ |
return 0; /* skip ethernet packet */ |
| |
|
| mtx_lock(&fws_mtx_c); |
mtx_lock(&fws_mtx_c); |
| |
|
| p = malloc(sizeof(struct fws_proto), M_FWSYNC, M_NOWAIT | M_ZERO); | p = malloc(sizeof(struct fws_sndpkt), M_FWSYNC, M_NOWAIT | M_ZERO); |
| if (!p) { |
if (!p) { |
| mtx_unlock(&fws_mtx_c); |
mtx_unlock(&fws_mtx_c); |
| return 0; |
return 0; |
|
Line 119 fwsync_state_handler(void *arg)
|
Line 168 fwsync_state_handler(void *arg)
|
| } |
} |
| |
|
| int |
int |
| fwsync_alias_handler(void *arg) | fwsync_alias_handler(const void *arg) |
| { |
{ |
| |
const struct alias_link *lnk = arg; |
| |
struct fws_proto *spkt; |
| |
struct fws_sndpkt *p; |
| |
|
| DTRACE(); |
DTRACE(); |
| |
|
| |
if (!lnk || lnk->link_type >= IPPROTO_MAX) |
| |
return 0; |
| |
|
| |
mtx_lock(&fws_mtx_c); |
| |
|
| |
p = malloc(sizeof(struct fws_sndpkt), M_FWSYNC, M_NOWAIT | M_ZERO); |
| |
if (!p) { |
| |
mtx_unlock(&fws_mtx_c); |
| |
return 0; |
| |
} else |
| |
spkt = &p->sp_proto; |
| |
|
| |
spkt->fws_version = FWS_PKTVER_ALIAS; |
| |
spkt->fws_proto = lnk->link_type; |
| |
spkt->fws_addrtype = 4; |
| |
spkt->fws_sport = lnk->src_port; |
| |
spkt->fws_dport = lnk->dst_port; |
| |
spkt->fws_aport = lnk->alias_port; |
| |
spkt->fws_pport = lnk->proxy_port; |
| |
spkt->fws_saddr.s_addr = lnk->src_addr.s_addr; |
| |
spkt->fws_daddr.s_addr = lnk->dst_addr.s_addr; |
| |
spkt->fws_aaddr.s_addr = lnk->alias_addr.s_addr; |
| |
spkt->fws_paddr.s_addr = lnk->proxy_addr.s_addr; |
| |
|
| |
TAILQ_INSERT_TAIL(&fwsync_sndpkt, p, sp_next); |
| |
|
| |
mtx_unlock(&fws_mtx_c); |
| |
|
| |
taskqueue_enqueue(fws_tq, &fws_sndpkt_task); |
| return 0; |
return 0; |
| } |
} |