diff options
Diffstat (limited to 'udp.c')
| -rw-r--r-- | udp.c | 28 |
1 files changed, 19 insertions, 9 deletions
@@ -705,13 +705,13 @@ static int udp_sock_errs(const struct ctx *c, int s, flow_sidx_t sidx, n_err += rc; if (rc < 0) - return -1; /* error reading error, unrecoverable */ + goto fail; /* error reading error, unrecoverable */ errlen = sizeof(err); if (getsockopt(s, SOL_SOCKET, SO_ERROR, &err, &errlen) < 0 || errlen != sizeof(err)) { flow_perror_ratelimit(uflow, now, "Error reading SO_ERROR"); - return -1; /* error reading error, unrecoverable */ + goto fail; /* error reading error, unrecoverable */ } if (err) { @@ -724,10 +724,16 @@ static int udp_sock_errs(const struct ctx *c, int s, flow_sidx_t sidx, /* EPOLLERR, but no errors to clear !? */ flow_err_ratelimit(uflow, now, "EPOLLERR event without reported errors"); - return -1; /* no way to clear, unrecoverable */ + goto fail; /* no way to clear, unrecoverable */ } return n_err; + +fail: + err_ratelimit(now, +"UDP: Unrecoverable error on listening socket: (%s port %hu)", + pif_name(pif), port); + return -1; } /** @@ -856,12 +862,13 @@ static void udp_buf_sock_to_tap(const struct ctx *c, int s, int n, * udp_sock_fwd() - Forward datagrams from a possibly unconnected socket * @c: Execution context * @s: Socket to forward from + * @errors: There are socket errors (EPOLLERR) to be flushed * @rule_hint: Forwarding rule to use, or -1 if unknown * @frompif: Interface to which @s belongs * @port: Our (local) port number of @s * @now: Current timestamp */ -void udp_sock_fwd(const struct ctx *c, int s, int rule_hint, +void udp_sock_fwd(const struct ctx *c, int s, bool errors, int rule_hint, uint8_t frompif, in_port_t port, const struct timespec *now) { union sockaddr_inany src; @@ -876,14 +883,14 @@ void udp_sock_fwd(const struct ctx *c, int s, int rule_hint, if (rc < 0) { trace("Error peeking at socket address: %s", strerror_(-rc)); + /* Clear errors & carry on */ if (udp_sock_errs(c, s, FLOW_SIDX_NONE, frompif, port, now) < 0) { - err_ratelimit(now, -"UDP: Unrecoverable error on listening socket: (%s port %hu)", - pif_name(frompif), port); - /* FIXME: what now? close/re-open socket? */ + ; /* FIXME: what now? close/re-open socket? */ } + errors = false; + continue; } @@ -918,6 +925,9 @@ void udp_sock_fwd(const struct ctx *c, int s, int rule_hint, debug_perror("Failed to discard datagram"); } } + + if (errors) + udp_sock_errs(c, s, FLOW_SIDX_NONE, frompif, port, now); } /** @@ -932,7 +942,7 @@ void udp_listen_sock_handler(const struct ctx *c, const struct timespec *now) { if (events & (EPOLLERR | EPOLLIN)) { - udp_sock_fwd(c, ref.fd, ref.listen.rule, + udp_sock_fwd(c, ref.fd, events & EPOLLERR, ref.listen.rule, ref.listen.pif, ref.listen.port, now); } } |
