You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ma...@apache.org on 2019/04/17 07:04:01 UTC
[trafficserver] branch quic-latest updated: Print destination
addresses and ports of received packets
This is an automated email from the ASF dual-hosted git repository.
maskit pushed a commit to branch quic-latest
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/quic-latest by this push:
new 897f692 Print destination addresses and ports of received packets
897f692 is described below
commit 897f6922c304e15c9eea31d7b52c0b986b0f5fd7
Author: Masakazu Kitajo <ma...@apache.org>
AuthorDate: Wed Apr 17 16:03:24 2019 +0900
Print destination addresses and ports of received packets
---
iocore/net/P_UDPPacket.h | 6 ++--
iocore/net/QUICPacketHandler.cc | 24 ++++++++-----
iocore/net/UnixUDPNet.cc | 80 +++++++++++++++++++++++++++++++++++++++--
3 files changed, 96 insertions(+), 14 deletions(-)
diff --git a/iocore/net/P_UDPPacket.h b/iocore/net/P_UDPPacket.h
index 80426ca..d6747de 100644
--- a/iocore/net/P_UDPPacket.h
+++ b/iocore/net/P_UDPPacket.h
@@ -226,7 +226,7 @@ new_UDPPacket(ink_hrtime when, Ptr<IOBufferBlock> buf)
}
TS_INLINE UDPPacket *
-new_incoming_UDPPacket(struct sockaddr *from, char *buf, int len)
+new_incoming_UDPPacket(struct sockaddr *from, struct sockaddr *to, char *buf, int len)
{
UDPPacketInternal *p = udpPacketAllocator.alloc();
@@ -234,6 +234,7 @@ new_incoming_UDPPacket(struct sockaddr *from, char *buf, int len)
p->in_heap = 0;
p->delivery_time = 0;
ats_ip_copy(&p->from, from);
+ ats_ip_copy(&p->to, to);
IOBufferBlock *body = new_IOBufferBlock();
body->alloc(iobuffer_size_to_index(len));
@@ -245,7 +246,7 @@ new_incoming_UDPPacket(struct sockaddr *from, char *buf, int len)
}
TS_INLINE UDPPacket *
-new_incoming_UDPPacket(struct sockaddr *from, Ptr<IOBufferBlock> &block)
+new_incoming_UDPPacket(struct sockaddr *from, struct sockaddr *to, Ptr<IOBufferBlock> &block)
{
UDPPacketInternal *p = udpPacketAllocator.alloc();
@@ -253,6 +254,7 @@ new_incoming_UDPPacket(struct sockaddr *from, Ptr<IOBufferBlock> &block)
p->in_heap = 0;
p->delivery_time = 0;
ats_ip_copy(&p->from, from);
+ ats_ip_copy(&p->to, to);
p->chain = block;
return p;
diff --git a/iocore/net/QUICPacketHandler.cc b/iocore/net/QUICPacketHandler.cc
index f75e395..611023c 100644
--- a/iocore/net/QUICPacketHandler.cc
+++ b/iocore/net/QUICPacketHandler.cc
@@ -230,9 +230,11 @@ QUICPacketHandlerIn::_recv_packet(int event, UDPPacket *udp_packet)
}
if (is_debug_tag_set(debug_tag)) {
- ip_port_text_buffer ipb;
- QUICDebugDS(scid, dcid, "recv LH packet from %s size=%" PRId64, ats_ip_nptop(&udp_packet->from.sa, ipb, sizeof(ipb)),
- udp_packet->getPktLength());
+ ip_port_text_buffer ipb_from;
+ ip_port_text_buffer ipb_to;
+ QUICDebugDS(scid, dcid, "recv LH packet from %s to %s size=%" PRId64,
+ ats_ip_nptop(&udp_packet->from.sa, ipb_from, sizeof(ipb_from)),
+ ats_ip_nptop(&udp_packet->to.sa, ipb_to, sizeof(ipb_to)), udp_packet->getPktLength());
}
QUICVersion v;
@@ -271,9 +273,11 @@ QUICPacketHandlerIn::_recv_packet(int event, UDPPacket *udp_packet)
} else {
// TODO: lookup DCID by 5-tuple when ATS omits SCID
if (is_debug_tag_set(debug_tag)) {
- ip_port_text_buffer ipb;
- QUICDebugDS(scid, dcid, "recv SH packet from %s size=%" PRId64, ats_ip_nptop(&udp_packet->from.sa, ipb, sizeof(ipb)),
- udp_packet->getPktLength());
+ ip_port_text_buffer ipb_from;
+ ip_port_text_buffer ipb_to;
+ QUICDebugDS(scid, dcid, "recv SH packet from %s to %s size=%" PRId64,
+ ats_ip_nptop(&udp_packet->from.sa, ipb_from, sizeof(ipb_from)),
+ ats_ip_nptop(&udp_packet->to.sa, ipb_to, sizeof(ipb_to)), udp_packet->getPktLength());
}
}
@@ -471,9 +475,11 @@ QUICPacketHandlerOut::_recv_packet(int event, UDPPacket *udp_packet)
IOBufferBlock *block = udp_packet->getIOBlockChain();
const uint8_t *buf = reinterpret_cast<uint8_t *>(block->buf());
- ip_port_text_buffer ipb;
- QUICDebugQC(this->_vc, "recv %s packet from %s size=%" PRId64, (QUICInvariants::is_long_header(buf) ? "LH" : "SH"),
- ats_ip_nptop(&udp_packet->from.sa, ipb, sizeof(ipb)), udp_packet->getPktLength());
+ ip_port_text_buffer ipb_from;
+ ip_port_text_buffer ipb_to;
+ QUICDebugQC(this->_vc, "recv %s packet from %s to %s size=%" PRId64, (QUICInvariants::is_long_header(buf) ? "LH" : "SH"),
+ ats_ip_nptop(&udp_packet->from.sa, ipb_from, sizeof(ipb_from)),
+ ats_ip_nptop(&udp_packet->to.sa, ipb_to, sizeof(ipb_to)), udp_packet->getPktLength());
}
this->_vc->handle_received_packet(udp_packet);
diff --git a/iocore/net/UnixUDPNet.cc b/iocore/net/UnixUDPNet.cc
index 49a6d52..fb4cfc4 100644
--- a/iocore/net/UnixUDPNet.cc
+++ b/iocore/net/UnixUDPNet.cc
@@ -29,6 +29,11 @@
****************************************************************************/
+#if defined(darwin)
+/* This is for IPV6_PKTINFO and IPV6_RECVPKTINFO */
+#define __APPLE_USE_RFC_3542
+#endif
+
#include "P_Net.h"
#include "P_UDPNet.h"
@@ -164,12 +169,15 @@ UDPNetProcessorInternal::udp_read_from_net(UDPNetHandler *nh, UDPConnection *xuc
// build struct msghdr
sockaddr_in6 fromaddr;
+ sockaddr_in6 toaddr;
+ int toaddr_len = sizeof(toaddr);
+ char *cbuf[1024];
msg.msg_name = &fromaddr;
msg.msg_namelen = sizeof(fromaddr);
msg.msg_iov = tiovec;
msg.msg_iovlen = niov;
- msg.msg_control = nullptr;
- msg.msg_controllen = 0;
+ msg.msg_control = cbuf;
+ msg.msg_controllen = sizeof(cbuf);
// receive data by recvmsg
r = socketManager.recvmsg(uc->getFd(), &msg, 0);
@@ -199,8 +207,38 @@ UDPNetProcessorInternal::udp_read_from_net(UDPNetHandler *nh, UDPConnection *xuc
}
}
+ safe_getsockname(xuc->getFd(), reinterpret_cast<struct sockaddr *>(&toaddr), &toaddr_len);
+ for (auto cmsg = CMSG_FIRSTHDR(&msg); cmsg != nullptr; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
+ switch (cmsg->cmsg_type) {
+#ifdef IP_PKTINFO
+ case IP_PKTINFO:
+ if (cmsg->cmsg_level == IPPROTO_IP) {
+ struct in_pktinfo *pktinfo = reinterpret_cast<struct in_pktinfo *>(CMSG_DATA(cmsg));
+ reinterpret_cast<sockaddr_in *>(&toaddr)->sin_addr.s_addr = pktinfo->ipi_addr.s_addr;
+ }
+ break;
+#endif
+#ifdef IP_RECVDSTADDR
+ case IP_RECVDSTADDR:
+ if (cmsg->cmsg_level == IPPROTO_IP) {
+ struct in_addr *addr = reinterpret_cast<struct in_addr *>(CMSG_DATA(cmsg));
+ reinterpret_cast<sockaddr_in *>(&toaddr)->sin_addr.s_addr = addr->s_addr;
+ }
+ break;
+#endif
+#if defined(IPV6_PKTINFO) || defined(IPV6_RECVPKTINFO)
+ case IPV6_PKTINFO: // IPV6_RECVPKTINFO uses IPV6_PKTINFO too
+ if (cmsg->cmsg_level == IPPROTO_IPV6) {
+ struct in6_pktinfo *pktinfo = reinterpret_cast<struct in6_pktinfo *>(CMSG_DATA(cmsg));
+ memcpy(toaddr.sin6_addr.s6_addr, &pktinfo->ipi6_addr, 16);
+ }
+ break;
+#endif
+ }
+ }
+
// create packet
- UDPPacket *p = new_incoming_UDPPacket(ats_ip_sa_cast(&fromaddr), chain);
+ UDPPacket *p = new_incoming_UDPPacket(ats_ip_sa_cast(&fromaddr), ats_ip_sa_cast(&toaddr), chain);
p->setConnection(uc);
// queue onto the UDPConnection
uc->inQueue.push((UDPPacketInternal *)p);
@@ -630,6 +668,24 @@ UDPNetProcessor::CreateUDPSocket(int *resfd, sockaddr const *remote_addr, Action
}
}
+ if (opt.ip_family == AF_INET) {
+ int enable = 1;
+#ifdef IP_PKTINFO
+ safe_setsockopt(fd, IPPROTO_IP, IP_PKTINFO, reinterpret_cast<char *>(&enable), sizeof(enable));
+#endif
+#ifdef IP_RECVDSTADDR
+ safe_setsockopt(fd, IPPROTO_IP, IP_RECVDSTADDR, reinterpret_cast<char *>(&enable), sizeof(enable));
+#endif
+ } else if (opt.ip_family == AF_INET6) {
+ int enable = 1;
+#ifdef IPV6_PKTINFO
+ safe_setsockopt(fd, IPPROTO_IPV6, IPV6_PKTINFO, reinterpret_cast<char *>(&enable), sizeof(enable));
+#endif
+#ifdef IPV6_RECVPKTINFO
+ safe_setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, reinterpret_cast<char *>(&enable), sizeof(enable));
+#endif
+ }
+
if (local_addr.port() || !is_any_address) {
if (-1 == socketManager.ink_bind(fd, &local_addr.sa, ats_ip_size(&local_addr.sa))) {
char buff[INET6_ADDRPORTSTRLEN];
@@ -685,6 +741,24 @@ UDPNetProcessor::UDPBind(Continuation *cont, sockaddr const *addr, int send_bufs
goto Lerror;
}
+ if (addr->sa_family == AF_INET) {
+ int enable = 1;
+#ifdef IP_PKTINFO
+ safe_setsockopt(fd, IPPROTO_IP, IP_PKTINFO, reinterpret_cast<char *>(&enable), sizeof(enable));
+#endif
+#ifdef IP_RECVDSTADDR
+ safe_setsockopt(fd, IPPROTO_IP, IP_RECVDSTADDR, reinterpret_cast<char *>(&enable), sizeof(enable));
+#endif
+ } else if (addr->sa_family == AF_INET6) {
+ int enable = 1;
+#ifdef IPV6_PKTINFO
+ safe_setsockopt(fd, IPPROTO_IPV6, IPV6_PKTINFO, reinterpret_cast<char *>(&enable), sizeof(enable));
+#endif
+#ifdef IPV6_RECVPKTINFO
+ safe_setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, reinterpret_cast<char *>(&enable), sizeof(enable));
+#endif
+ }
+
// If this is a class D address (i.e. multicast address), use REUSEADDR.
if (ats_is_ip_multicast(addr)) {
int enable_reuseaddr = 1;