diff --git a/include/re_udp.h b/include/re_udp.h index 4f12e5546..cb7d043d6 100644 --- a/include/re_udp.h +++ b/include/re_udp.h @@ -58,4 +58,6 @@ int udp_register_helper(struct udp_helper **uhp, struct udp_sock *us, void *arg); int udp_send_helper(struct udp_sock *us, const struct sa *dst, struct mbuf *mb, struct udp_helper *uh); +void udp_recv_helper(struct udp_sock *us, const struct sa *src, + struct mbuf *mb, struct udp_helper *uh); struct udp_helper *udp_helper_find(const struct udp_sock *us, int layer); diff --git a/src/udp/udp.c b/src/udp/udp.c index 45a6326b2..73d7abce3 100644 --- a/src/udp/udp.c +++ b/src/udp/udp.c @@ -868,6 +868,36 @@ int udp_send_helper(struct udp_sock *us, const struct sa *dst, } +void udp_recv_helper(struct udp_sock *us, const struct sa *src, + struct mbuf *mb, struct udp_helper *uhx) +{ + struct sa hsrc; + struct le *le; + + if (!us || !src || !mb || !uhx) + return; + + le = uhx->le.next; + while (le) { + struct udp_helper *uh = le->data; + bool hdld; + + le = le->next; + + if (src != &hsrc) { + sa_cpy(&hsrc, src); + src = &hsrc; + } + + hdld = uh->recvh(&hsrc, mb, uh->arg); + if (hdld) + return; + } + + us->rh(src, mb, us->arg); +} + + /** * Find a UDP-helper on a UDP socket *