diff options
| -rw-r--r-- | conf.c | 7 | ||||
| -rw-r--r-- | fwd.c | 10 | ||||
| -rw-r--r-- | fwd.h | 2 |
3 files changed, 12 insertions, 7 deletions
@@ -2250,7 +2250,12 @@ void conf_handler(struct ctx *c, uint32_t events) " ", ""); } - fwd_listen_switch(c); + if (fwd_listen_switch(c) < 0) { + err("Error switching to new forwarding rules"); + /* Switch back to old rules (still in c->fwd_pending) */ + if (fwd_listen_switch(c) < 0) + err("Couldn't restore old forwarding rules"); + } } if (events & EPOLLHUP) { @@ -536,8 +536,10 @@ int fwd_listen_init(const struct ctx *c) /** * fwd_listen_switch() - Switch from current to pending rules table * @c: Execution context + * + * Return: 0 on success, -1 on failure */ -void fwd_listen_switch(struct ctx *c) +int fwd_listen_switch(struct ctx *c) { struct fwd_table *tmp[PIF_NUM_TYPES]; unsigned i; @@ -549,9 +551,8 @@ void fwd_listen_switch(struct ctx *c) if (!fwd) continue; - debug("Flushing %u old %s rules", fwd->count, pif_name(i)); + debug("Flushing %u %s rules", fwd->count, pif_name(i)); fwd_listen_close(fwd); - fwd->count = fwd->sock_count = 0; } /* Swap active and pending tables */ @@ -563,8 +564,7 @@ void fwd_listen_switch(struct ctx *c) memcpy((void *)c->fwd_pending, &tmp, sizeof(c->fwd_pending)); /* Start listening on the new tables */ - if (fwd_listen_init(c) < 0) - err("Error switching to new forwarding rules"); + return fwd_listen_init(c); } /* See enum in kernel's include/net/tcp_states.h */ @@ -61,7 +61,7 @@ int fwd_listen_sync(const struct ctx *c, uint8_t pif, const struct fwd_scan *tcp, const struct fwd_scan *udp); void fwd_listen_close(const struct fwd_table *fwd); int fwd_listen_init(const struct ctx *c); -void fwd_listen_switch(struct ctx *c); +int fwd_listen_switch(struct ctx *c); bool nat_inbound(const struct ctx *c, const union inany_addr *addr, union inany_addr *translated); |
