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 2018/01/15 07:59:02 UTC

[trafficserver] branch quic-latest updated (56fa13f -> e2dc349)

This is an automated email from the ASF dual-hosted git repository.

masaori pushed a change to branch quic-latest
in repository https://gitbox.apache.org/repos/asf/trafficserver.git.


    from 56fa13f  Switch to draining state on idle timeout
     new dbb740f  Fix condition of ssl extention context on adding Transport Parameters
     new e2dc349  Divide QUICPacketHandler into QUICPacketHandlerIn (incoming conn) and QUICPacketHandlerOut (outgoing conn)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 iocore/net/P_QUICNetVConnection.h          |   2 +-
 iocore/net/P_QUICPacketHandler.h           |  57 +++++++--
 iocore/net/QUICNetProcessor.cc             |  15 +--
 iocore/net/QUICPacketHandler.cc            | 184 ++++++++++++++++++++---------
 iocore/net/quic/QUICTransportParameters.cc |   2 +-
 5 files changed, 185 insertions(+), 75 deletions(-)

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].

[trafficserver] 01/02: Fix condition of ssl extention context on adding Transport Parameters

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

masaori pushed a commit to branch quic-latest
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit dbb740f141d97b882ca8e9512586a41fecc7b231
Author: Masaori Koshiba <ma...@apache.org>
AuthorDate: Mon Jan 15 16:56:04 2018 +0900

    Fix condition of ssl extention context on adding Transport Parameters
---
 iocore/net/quic/QUICTransportParameters.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/iocore/net/quic/QUICTransportParameters.cc b/iocore/net/quic/QUICTransportParameters.cc
index 4a511b2..c3c25c4 100644
--- a/iocore/net/quic/QUICTransportParameters.cc
+++ b/iocore/net/quic/QUICTransportParameters.cc
@@ -547,7 +547,7 @@ QUICTransportParametersHandler::add(SSL *s, unsigned int ext_type, unsigned int
 {
   QUICHandshake *hs = static_cast<QUICHandshake *>(SSL_get_ex_data(s, QUIC::ssl_quic_hs_index));
   *out              = reinterpret_cast<const unsigned char *>(ats_malloc(TRANSPORT_PARAMETERS_MAXIMUM_SIZE));
-  bool with_version = (context == SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS);
+  bool with_version = (context != SSL_EXT_TLS1_3_NEW_SESSION_TICKET);
   hs->local_transport_parameters(with_version)->store(const_cast<uint8_t *>(*out), reinterpret_cast<uint16_t *>(outlen));
 
   return 1;

-- 
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.

[trafficserver] 02/02: Divide QUICPacketHandler into QUICPacketHandlerIn (incoming conn) and QUICPacketHandlerOut (outgoing conn)

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

masaori pushed a commit to branch quic-latest
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit e2dc349fc37276fbd166028cc3000cd92e4d1194
Author: Masaori Koshiba <ma...@apache.org>
AuthorDate: Mon Jan 15 16:58:42 2018 +0900

    Divide QUICPacketHandler into QUICPacketHandlerIn (incoming conn) and QUICPacketHandlerOut (outgoing conn)
---
 iocore/net/P_QUICNetVConnection.h |   2 +-
 iocore/net/P_QUICPacketHandler.h  |  57 ++++++++++--
 iocore/net/QUICNetProcessor.cc    |  15 ++--
 iocore/net/QUICPacketHandler.cc   | 184 ++++++++++++++++++++++++++------------
 4 files changed, 184 insertions(+), 74 deletions(-)

diff --git a/iocore/net/P_QUICNetVConnection.h b/iocore/net/P_QUICNetVConnection.h
index e67fc37..a040ca2 100644
--- a/iocore/net/P_QUICNetVConnection.h
+++ b/iocore/net/P_QUICNetVConnection.h
@@ -87,7 +87,7 @@ typedef enum {
 //
 //////////////////////////////////////////////////////////////////
 
-struct QUICPacketHandler;
+class QUICPacketHandler;
 class QUICLossDetector;
 
 class SSLNextProtocolSet;
diff --git a/iocore/net/P_QUICPacketHandler.h b/iocore/net/P_QUICPacketHandler.h
index 564dbba..2205a80 100644
--- a/iocore/net/P_QUICPacketHandler.h
+++ b/iocore/net/P_QUICPacketHandler.h
@@ -31,24 +31,65 @@
 class QUICNetVConnection;
 class QUICPacket;
 
-struct QUICPacketHandler : public NetAccept {
+class QUICPacketHandler
+{
 public:
-  QUICPacketHandler(const NetProcessor::AcceptOptions &opt, SSL_CTX *);
-  virtual ~QUICPacketHandler();
+  virtual void send_packet(const QUICPacket &packet, QUICNetVConnection *vc)        = 0;
+  virtual void registerAltConnectionId(QUICConnectionId id, QUICNetVConnection *vc) = 0;
 
+protected:
+  static void _send_packet(Continuation *c, const QUICPacket &packet, UDPConnection *udp_con, IpEndpoint &addr, uint32_t pmtu);
+  static bool _read_connection_id(QUICConnectionId &cid, IOBufferBlock *block);
+
+  virtual void _recv_packet(int event, UDPPacket *udpPacket) = 0;
+};
+
+/*
+ * @class QUICPacketHanderIn
+ * @brief QUIC Packet Handler for incoming connections
+ */
+class QUICPacketHandlerIn : public NetAccept, public QUICPacketHandler
+{
+public:
+  QUICPacketHandlerIn(const NetProcessor::AcceptOptions &opt, SSL_CTX *);
+  ~QUICPacketHandlerIn();
+
+  // NetAccept
   virtual NetProcessor *getNetProcessor() const override;
   virtual NetAccept *clone() const override;
   virtual int acceptEvent(int event, void *e) override;
   void init_accept(EThread *t) override;
-  void send_packet(const QUICPacket &packet, QUICNetVConnection *vc);
-  void send_packet(const QUICPacket &packet, UDPConnection *udp_con, IpEndpoint &addr, uint32_t pmtu);
 
-  void registerAltConnectionId(QUICConnectionId id, QUICNetVConnection *vc);
+  // QUICPacketHandler
+  virtual void send_packet(const QUICPacket &packet, QUICNetVConnection *vc) override;
+  virtual void registerAltConnectionId(QUICConnectionId id, QUICNetVConnection *vc) override;
 
 private:
-  void _recv_packet(int event, UDPPacket *udpPacket);
-  bool _read_connection_id(QUICConnectionId &cid, IOBufferBlock *block);
+  void _recv_packet(int event, UDPPacket *udp_packet) override;
 
   Map<int64_t, QUICNetVConnection *> _connections;
   SSL_CTX *_ssl_ctx;
 };
+
+/*
+ * @class QUICPacketHanderOut
+ * @brief QUIC Packet Handler for outgoing connections
+ */
+class QUICPacketHandlerOut : public Continuation, public QUICPacketHandler
+{
+public:
+  QUICPacketHandlerOut();
+  ~QUICPacketHandlerOut(){};
+
+  void init(QUICNetVConnection *vc);
+  int event_handler(int event, Event *data);
+
+  // QUICPacketHandler
+  virtual void send_packet(const QUICPacket &packet, QUICNetVConnection *vc) override;
+  virtual void registerAltConnectionId(QUICConnectionId id, QUICNetVConnection *vc) override;
+
+private:
+  void _recv_packet(int event, UDPPacket *udp_packet) override;
+
+  QUICNetVConnection *_vc = nullptr;
+};
diff --git a/iocore/net/QUICNetProcessor.cc b/iocore/net/QUICNetProcessor.cc
index 01a4462..ff6bcf2 100644
--- a/iocore/net/QUICNetProcessor.cc
+++ b/iocore/net/QUICNetProcessor.cc
@@ -20,14 +20,14 @@
  */
 
 #include "ts/ink_config.h"
+#include "ts/I_Layout.h"
 
 #include "P_Net.h"
-#include "ts/I_Layout.h"
 #include "I_RecHttp.h"
+
 #include "QUICGlobals.h"
 #include "QUICConfig.h"
 #include "QUICTransportParameters.h"
-// #include "P_QUICUtils.h"
 
 //
 // Global Data
@@ -89,7 +89,7 @@ QUICNetProcessor::start(int, size_t stacksize)
 NetAccept *
 QUICNetProcessor::createNetAccept(const NetProcessor::AcceptOptions &opt)
 {
-  return (NetAccept *)new QUICPacketHandler(opt, this->_ssl_ctx);
+  return (NetAccept *)new QUICPacketHandlerIn(opt, this->_ssl_ctx);
 }
 
 NetVConnection *
@@ -138,13 +138,7 @@ QUICNetProcessor::connect_re(Continuation *cont, sockaddr const *remote_addr, Ne
   UnixUDPConnection *con = new UnixUDPConnection(fd);
   Debug("quic_ps", "con=%p fd=%d", con, fd);
 
-  AcceptOptions const accept_opt;
-  // FIXME: create QUICPacketHandler for Client (origin server side)
-  QUICPacketHandler *packet_handler = new QUICPacketHandler(accept_opt, this->_ssl_ctx);
-  packet_handler->init_accept(t);
-  packet_handler->action_  = new NetAcceptAction();
-  *packet_handler->action_ = cont;
-
+  QUICPacketHandlerOut *packet_handler = new QUICPacketHandlerOut();
   con->setBinding(reinterpret_cast<sockaddr const *>(&local_addr));
   con->bindToThread(packet_handler);
 
@@ -162,6 +156,7 @@ QUICNetProcessor::connect_re(Continuation *cont, sockaddr const *remote_addr, Ne
   cid.randomize();
   QUICNetVConnection *vc = static_cast<QUICNetVConnection *>(this->allocate_vc(t));
   vc->init(cid, con, packet_handler);
+  packet_handler->init(vc);
 
   if (opt) {
     vc->options = *opt;
diff --git a/iocore/net/QUICPacketHandler.cc b/iocore/net/QUICPacketHandler.cc
index e07dec5..12e3cc4 100644
--- a/iocore/net/QUICPacketHandler.cc
+++ b/iocore/net/QUICPacketHandler.cc
@@ -27,32 +27,78 @@
 #include "QUICDebugNames.h"
 #include "QUICEvents.h"
 
-QUICPacketHandler::QUICPacketHandler(const NetProcessor::AcceptOptions &opt, SSL_CTX *ctx) : NetAccept(opt), _ssl_ctx(ctx)
+//
+// QUICPacketHandler
+//
+void
+QUICPacketHandler::_send_packet(Continuation *c, const QUICPacket &packet, UDPConnection *udp_con, IpEndpoint &addr, uint32_t pmtu)
+{
+  size_t udp_len;
+  Ptr<IOBufferBlock> udp_payload(new_IOBufferBlock());
+  udp_payload->alloc(iobuffer_size_to_index(pmtu));
+  packet.store(reinterpret_cast<uint8_t *>(udp_payload->end()), &udp_len);
+  udp_payload->fill(udp_len);
+
+  UDPPacket *udp_packet = new_UDPPacket(addr, 0, udp_payload);
+
+  // NOTE: p will be enqueued to udpOutQueue of UDPNetHandler
+  ip_port_text_buffer ipb;
+  Debug("quic_sec", "[%" PRIx64 "] send %s packet to %s, size=%" PRId64, static_cast<uint64_t>(packet.connection_id()),
+        QUICDebugNames::packet_type(packet.type()), ats_ip_nptop(&udp_packet->to.sa, ipb, sizeof(ipb)), udp_packet->getPktLength());
+
+  udp_con->send(c, udp_packet);
+}
+
+// TODO: Integrate with QUICPacketHeader::connection_id()
+bool
+QUICPacketHandler::_read_connection_id(QUICConnectionId &cid, IOBufferBlock *block)
+{
+  const uint8_t *buf       = reinterpret_cast<const uint8_t *>(block->buf());
+  const uint8_t cid_offset = 1;
+  const uint8_t cid_len    = 8;
+
+  if (QUICTypeUtil::has_long_header(buf)) {
+    cid = QUICTypeUtil::read_QUICConnectionId(buf + cid_offset, cid_len);
+  } else {
+    if (QUICTypeUtil::has_connection_id(buf)) {
+      cid = QUICTypeUtil::read_QUICConnectionId(buf + cid_offset, cid_len);
+    } else {
+      return false;
+    }
+  }
+
+  return true;
+}
+
+//
+// QUICPacketHandlerIn
+//
+QUICPacketHandlerIn::QUICPacketHandlerIn(const NetProcessor::AcceptOptions &opt, SSL_CTX *ctx) : NetAccept(opt), _ssl_ctx(ctx)
 {
   this->mutex = new_ProxyMutex();
 }
 
-QUICPacketHandler::~QUICPacketHandler()
+QUICPacketHandlerIn::~QUICPacketHandlerIn()
 {
 }
 
 NetProcessor *
-QUICPacketHandler::getNetProcessor() const
+QUICPacketHandlerIn::getNetProcessor() const
 {
   return &quic_NetProcessor;
 }
 
 NetAccept *
-QUICPacketHandler::clone() const
+QUICPacketHandlerIn::clone() const
 {
   NetAccept *na;
-  na  = new QUICPacketHandler(opt, this->_ssl_ctx);
+  na  = new QUICPacketHandlerIn(opt, this->_ssl_ctx);
   *na = *this;
   return na;
 }
 
 int
-QUICPacketHandler::acceptEvent(int event, void *data)
+QUICPacketHandlerIn::acceptEvent(int event, void *data)
 {
   // NetVConnection *netvc;
   ink_release_assert(event == NET_EVENT_DATAGRAM_OPEN || event == NET_EVENT_DATAGRAM_READ_READY ||
@@ -84,43 +130,22 @@ QUICPacketHandler::acceptEvent(int event, void *data)
 }
 
 void
-QUICPacketHandler::init_accept(EThread *t = nullptr)
+QUICPacketHandlerIn::init_accept(EThread *t = nullptr)
 {
-  SET_HANDLER(&QUICPacketHandler::acceptEvent);
-}
-
-// TODO: Integrate with QUICPacketHeader::connection_id()
-bool
-QUICPacketHandler::_read_connection_id(QUICConnectionId &cid, IOBufferBlock *block)
-{
-  const uint8_t *buf       = reinterpret_cast<const uint8_t *>(block->buf());
-  const uint8_t cid_offset = 1;
-  const uint8_t cid_len    = 8;
-
-  if (QUICTypeUtil::has_long_header(buf)) {
-    cid = QUICTypeUtil::read_QUICConnectionId(buf + cid_offset, cid_len);
-  } else {
-    if (QUICTypeUtil::has_connection_id(buf)) {
-      cid = QUICTypeUtil::read_QUICConnectionId(buf + cid_offset, cid_len);
-    } else {
-      return false;
-    }
-  }
-
-  return true;
+  SET_HANDLER(&QUICPacketHandlerIn::acceptEvent);
 }
 
 void
-QUICPacketHandler::_recv_packet(int event, UDPPacket *udpPacket)
+QUICPacketHandlerIn::_recv_packet(int event, UDPPacket *udp_packet)
 {
-  IOBufferBlock *block = udpPacket->getIOBlockChain();
+  IOBufferBlock *block = udp_packet->getIOBlockChain();
 
   QUICConnectionId cid;
   bool res = this->_read_connection_id(cid, block);
 
   ip_port_text_buffer ipb;
   Debug("quic_sec", "[%" PRIx64 "] received packet from %s, size=%" PRId64, static_cast<uint64_t>(cid),
-        ats_ip_nptop(&udpPacket->from.sa, ipb, sizeof(ipb)), udpPacket->getPktLength());
+        ats_ip_nptop(&udp_packet->from.sa, ipb, sizeof(ipb)), udp_packet->getPktLength());
 
   QUICNetVConnection *vc = nullptr;
   if (res) {
@@ -132,7 +157,7 @@ QUICPacketHandler::_recv_packet(int event, UDPPacket *udpPacket)
 
   if (!vc) {
     Connection con;
-    con.setRemote(&udpPacket->from.sa);
+    con.setRemote(&udp_packet->from.sa);
 
     // Send stateless reset if the packet is not a initial packet
     if (!QUICTypeUtil::has_long_header(reinterpret_cast<const uint8_t *>(block->buf()))) {
@@ -142,14 +167,14 @@ QUICPacketHandler::_recv_packet(int event, UDPPacket *udpPacket)
         token.generate(cid, params->server_id());
       }
       auto packet = QUICPacketFactory::create_stateless_reset_packet(cid, token);
-      this->send_packet(*packet, udpPacket->getConnection(), con.addr, 1200);
+      this->_send_packet(this, *packet, udp_packet->getConnection(), con.addr, 1200);
       return;
     }
 
     // Create a new NetVConnection
-    vc =
-      static_cast<QUICNetVConnection *>(getNetProcessor()->allocate_vc(((UnixUDPConnection *)udpPacket->getConnection())->ethread));
-    vc->init(cid, udpPacket->getConnection(), this);
+    vc = static_cast<QUICNetVConnection *>(
+      getNetProcessor()->allocate_vc(((UnixUDPConnection *)udp_packet->getConnection())->ethread));
+    vc->init(cid, udp_packet->getConnection(), this);
     vc->id = net_next_connection_number();
     vc->con.move(con);
     vc->submit_time = Thread::get_hrtime();
@@ -160,7 +185,7 @@ QUICPacketHandler::_recv_packet(int event, UDPPacket *udpPacket)
     vc->read.triggered = 1;
     vc->start(this->_ssl_ctx);
     vc->options.ip_proto  = NetVCOptions::USE_UDP;
-    vc->options.ip_family = udpPacket->from.sa.sa_family;
+    vc->options.ip_family = udp_packet->from.sa.sa_family;
 
     this->_connections.put(cid, vc);
     this->action_->continuation->handleEvent(NET_EVENT_ACCEPT, vc);
@@ -172,14 +197,14 @@ QUICPacketHandler::_recv_packet(int event, UDPPacket *udpPacket)
     // QUICNetVConnections are going to be freed by QUICNetHandler
     // vc->free(vc->thread);
   } else {
-    vc->push_packet(udpPacket);
+    vc->push_packet(udp_packet);
     eventProcessor.schedule_imm(vc, ET_CALL, QUIC_EVENT_PACKET_READ_READY, nullptr);
   }
 }
 
 // TODO: Should be called via eventProcessor?
 void
-QUICPacketHandler::send_packet(const QUICPacket &packet, QUICNetVConnection *vc)
+QUICPacketHandlerIn::send_packet(const QUICPacket &packet, QUICNetVConnection *vc)
 {
   // TODO: remove a connection which is created by Client Initial
   //       or update key to new one
@@ -187,30 +212,79 @@ QUICPacketHandler::send_packet(const QUICPacket &packet, QUICNetVConnection *vc)
     this->_connections.put(packet.connection_id(), vc);
   }
 
-  this->send_packet(packet, vc->get_udp_con(), vc->con.addr, vc->pmtu());
+  this->_send_packet(this, packet, vc->get_udp_con(), vc->con.addr, vc->pmtu());
 }
 
 void
-QUICPacketHandler::send_packet(const QUICPacket &packet, UDPConnection *udp_con, IpEndpoint &addr, uint32_t pmtu)
+QUICPacketHandlerIn::registerAltConnectionId(QUICConnectionId id, QUICNetVConnection *vc)
 {
-  size_t udp_len;
-  Ptr<IOBufferBlock> udp_payload(new_IOBufferBlock());
-  udp_payload->alloc(iobuffer_size_to_index(pmtu));
-  packet.store(reinterpret_cast<uint8_t *>(udp_payload->end()), &udp_len);
-  udp_payload->fill(udp_len);
+  this->_connections.put(id, vc);
+}
 
-  UDPPacket *udpPkt = new_UDPPacket(addr, 0, udp_payload);
+//
+// QUICPacketHandlerOut
+//
+QUICPacketHandlerOut::QUICPacketHandlerOut() : Continuation(new_ProxyMutex())
+{
+  SET_HANDLER(&QUICPacketHandlerOut::event_handler);
+}
 
-  // NOTE: p will be enqueued to udpOutQueue of UDPNetHandler
-  ip_port_text_buffer ipb;
-  Debug("quic_sec", "[%" PRIx64 "] send %s packet to %s, size=%" PRId64, static_cast<uint64_t>(packet.connection_id()),
-        QUICDebugNames::packet_type(packet.type()), ats_ip_nptop(&udpPkt->to.sa, ipb, sizeof(ipb)), udpPkt->getPktLength());
+void
+QUICPacketHandlerOut::init(QUICNetVConnection *vc)
+{
+  this->_vc = vc;
+}
 
-  udp_con->send(this, udpPkt);
+int
+QUICPacketHandlerOut::event_handler(int event, Event *data)
+{
+  switch (event) {
+  case NET_EVENT_DATAGRAM_OPEN: {
+    // Nothing to do.
+    return EVENT_CONT;
+  }
+  case NET_EVENT_DATAGRAM_READ_READY: {
+    Queue<UDPPacket> *queue = (Queue<UDPPacket> *)data;
+    UDPPacket *packet_r;
+    while ((packet_r = queue->dequeue())) {
+      this->_recv_packet(event, packet_r);
+    }
+    return EVENT_CONT;
+  }
+  default:
+    Debug("quic_ph", "Unknown Event (%d)", event);
+
+    break;
+  }
+
+  return EVENT_DONE;
 }
 
 void
-QUICPacketHandler::registerAltConnectionId(QUICConnectionId id, QUICNetVConnection *vc)
+QUICPacketHandlerOut::send_packet(const QUICPacket &packet, QUICNetVConnection *vc)
 {
-  this->_connections.put(id, vc);
+  this->_send_packet(this, packet, vc->get_udp_con(), vc->con.addr, vc->pmtu());
+}
+
+void
+QUICPacketHandlerOut::registerAltConnectionId(QUICConnectionId id, QUICNetVConnection *vc)
+{
+  // do nothing
+  ink_assert(false);
+}
+
+void
+QUICPacketHandlerOut::_recv_packet(int event, UDPPacket *udp_packet)
+{
+  IOBufferBlock *block = udp_packet->getIOBlockChain();
+
+  QUICConnectionId cid;
+  this->_read_connection_id(cid, block);
+
+  ip_port_text_buffer ipb;
+  Debug("quic_sec", "[%" PRIx64 "] received packet from %s, size=%" PRId64, static_cast<uint64_t>(cid),
+        ats_ip_nptop(&udp_packet->from.sa, ipb, sizeof(ipb)), udp_packet->getPktLength());
+
+  this->_vc->push_packet(udp_packet);
+  eventProcessor.schedule_imm(this->_vc, ET_CALL, QUIC_EVENT_PACKET_READ_READY, nullptr);
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.