Now that ICMP pass-through from socket-to-tap and TTL/hop limit based
outgoing flow separation is in place, it is easy to support UDP based
traceroute functionality in direction tap-to-socket.
We fix that in this commit.
Signed-off-by: Jon Maloy
---
v2: Using ancillary data instead of setsockopt to transfer outgoing
TTL.
---
udp.c | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/udp.c b/udp.c
index 8a2c593..7361ffa 100644
--- a/udp.c
+++ b/udp.c
@@ -861,6 +861,7 @@ int udp_tap_handler(const struct ctx *c, uint8_t pif,
uint8_t ttl, const struct pool *p, int idx,
const struct timespec *now)
{
+ char ancillary[CMSG_SPACE(sizeof(int))];
const struct flowside *toside;
struct mmsghdr mm[UIO_MAXIOV];
union sockaddr_inany to_sa;
@@ -868,6 +869,8 @@ int udp_tap_handler(const struct ctx *c, uint8_t pif,
const struct udphdr *uh;
struct udp_flow *uflow;
int i, s, count = 0;
+ char *control = NULL;
+ int control_len = 0;
flow_sidx_t tosidx;
in_port_t src, dst;
uint8_t topif;
@@ -914,6 +917,22 @@ int udp_tap_handler(const struct ctx *c, uint8_t pif,
pif_sockaddr(c, &to_sa, &sl, topif, &toside->eaddr, toside->eport);
+ if (ttl != DEFAULT_TTL) {
+ struct cmsghdr *cmsg = (void *) ancillary;
+
+ if (af == AF_INET) {
+ cmsg->cmsg_level = IPPROTO_IP;
+ cmsg->cmsg_type = IP_TTL;
+ } else {
+ cmsg->cmsg_level = IPPROTO_IPV6;
+ cmsg->cmsg_type = IPV6_HOPLIMIT;
+ }
+ cmsg->cmsg_len = CMSG_LEN(sizeof(int));
+ *((int *) CMSG_DATA(cmsg)) = ttl;
+ control = ancillary;
+ control_len = sizeof(ancillary);
+ }
+
for (i = 0; i < (int)p->count - idx; i++) {
struct udphdr *uh_send;
size_t len;
@@ -936,8 +955,8 @@ int udp_tap_handler(const struct ctx *c, uint8_t pif,
mm[i].msg_hdr.msg_iovlen = 0;
}
- mm[i].msg_hdr.msg_control = NULL;
- mm[i].msg_hdr.msg_controllen = 0;
+ mm[i].msg_hdr.msg_control = control;
+ mm[i].msg_hdr.msg_controllen = control_len;
mm[i].msg_hdr.msg_flags = 0;
count++;
--
2.48.1