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/03/20 07:49:09 UTC

[trafficserver] branch quic-latest updated: Add five_tuple() to QUICConnection interface

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 976e1ec  Add five_tuple() to QUICConnection interface
976e1ec is described below

commit 976e1ecf82f82659d5145435ffc1cb6ebe52544a
Author: Masakazu Kitajo <ma...@apache.org>
AuthorDate: Tue Mar 20 16:08:24 2018 +0900

    Add five_tuple() to QUICConnection interface
---
 iocore/net/P_QUICNetVConnection.h     |  2 ++
 iocore/net/QUICNetVConnection.cc      |  7 +++++++
 iocore/net/quic/Mock.h                |  6 ++++++
 iocore/net/quic/QUICConnection.h      |  1 +
 iocore/net/quic/QUICConnectionTable.h | 13 ------------
 iocore/net/quic/QUICStatelessRetry.cc |  7 ++-----
 iocore/net/quic/QUICTypes.cc          | 37 +++++++++++++++++++++++++++++++++++
 iocore/net/quic/QUICTypes.h           | 18 +++++++++++++++++
 8 files changed, 73 insertions(+), 18 deletions(-)

diff --git a/iocore/net/P_QUICNetVConnection.h b/iocore/net/P_QUICNetVConnection.h
index 03a1c42..0cca49d 100644
--- a/iocore/net/P_QUICNetVConnection.h
+++ b/iocore/net/P_QUICNetVConnection.h
@@ -181,6 +181,7 @@ public:
   // QUICConnection
   QUICConnectionId original_connection_id() override;
   QUICConnectionId connection_id() override;
+  const QUICFiveTuple five_tuple() override;
   uint32_t maximum_quic_packet_size() override;
   uint32_t minimum_quic_packet_size() override;
   uint32_t maximum_stream_frame_data_size() override;
@@ -226,6 +227,7 @@ private:
 
   QUICConnectionId _original_quic_connection_id;
   QUICConnectionId _quic_connection_id;
+  QUICFiveTuple _five_tuple;
 
   AltConnectionInfo _alt_quic_connection_ids[3];
   int8_t _alt_quic_connection_id_seq_num = 0;
diff --git a/iocore/net/QUICNetVConnection.cc b/iocore/net/QUICNetVConnection.cc
index c647e93..32b45a2 100644
--- a/iocore/net/QUICNetVConnection.cc
+++ b/iocore/net/QUICNetVConnection.cc
@@ -175,6 +175,7 @@ QUICNetVConnection::startEvent(int event, Event *e)
 void
 QUICNetVConnection::start(SSL_CTX *ssl_ctx)
 {
+  this->_five_tuple.update(this->local_addr, this->remote_addr, SOCK_DGRAM);
   // Version 0x00000001 uses stream 0 for cryptographic handshake with TLS 1.3, but newer version may not
   if (this->direction() == NET_VCONNECTION_IN) {
     QUICConfig::scoped_config params;
@@ -289,6 +290,12 @@ QUICNetVConnection::connection_id()
   return this->_quic_connection_id;
 }
 
+const QUICFiveTuple
+QUICNetVConnection::five_tuple()
+{
+  return this->_five_tuple;
+}
+
 uint32_t
 QUICNetVConnection::pmtu()
 {
diff --git a/iocore/net/quic/Mock.h b/iocore/net/quic/Mock.h
index 2362561..6c61438 100644
--- a/iocore/net/quic/Mock.h
+++ b/iocore/net/quic/Mock.h
@@ -157,6 +157,12 @@ public:
     return 0;
   }
 
+  const QUICFiveTuple
+  five_tuple() override
+  {
+    return QUICFiveTuple();
+  }
+
   uint32_t
   transmit_packet(QUICPacketUPtr packet) override
   {
diff --git a/iocore/net/quic/QUICConnection.h b/iocore/net/quic/QUICConnection.h
index afcade0..8ab7b67 100644
--- a/iocore/net/quic/QUICConnection.h
+++ b/iocore/net/quic/QUICConnection.h
@@ -39,6 +39,7 @@ class QUICConnection : public QUICPacketTransmitter, public QUICFrameTransmitter
 public:
   virtual QUICConnectionId original_connection_id() = 0;
   virtual QUICConnectionId connection_id()          = 0;
+  virtual const QUICFiveTuple five_tuple()          = 0;
 
   /*
    * Retruns the maximum packet size at the time called
diff --git a/iocore/net/quic/QUICConnectionTable.h b/iocore/net/quic/QUICConnectionTable.h
index 0ead233..2a4fefd 100644
--- a/iocore/net/quic/QUICConnectionTable.h
+++ b/iocore/net/quic/QUICConnectionTable.h
@@ -27,19 +27,6 @@
 #include "QUICConnection.h"
 #include "ts/MT_hashtable.h"
 
-class QUICFiveTuple
-{
-public:
-  QUICFiveTuple(IpEndpoint src, IpEndpoint dst, int protocol)
-  {
-    // FIXME Generate a hash code
-    this->_hash_code = src.port() + dst.port() + protocol;
-  }
-
-private:
-  uint64_t _hash_code = 0;
-};
-
 class QUICConnectionTable
 {
 public:
diff --git a/iocore/net/quic/QUICStatelessRetry.cc b/iocore/net/quic/QUICStatelessRetry.cc
index 700b8c7..2776537 100644
--- a/iocore/net/quic/QUICStatelessRetry.cc
+++ b/iocore/net/quic/QUICStatelessRetry.cc
@@ -45,14 +45,11 @@ QUICStatelessRetry::init()
 int
 QUICStatelessRetry::generate_cookie(SSL *ssl, unsigned char *cookie, size_t *cookie_len)
 {
-  // Call UnixNetVConnection::get_remote_addr() safely
-  // TODO: add APIs to getting client addr in QUICConnection
-  QUICConnection *qc      = static_cast<QUICConnection *>(SSL_get_ex_data(ssl, QUIC::ssl_quic_qc_index));
-  QUICNetVConnection *qvc = dynamic_cast<QUICNetVConnection *>(qc);
+  QUICConnection *qc = static_cast<QUICConnection *>(SSL_get_ex_data(ssl, QUIC::ssl_quic_qc_index));
 
   uint8_t key[INET6_ADDRPORTSTRLEN] = {0};
   size_t key_len                    = INET6_ADDRPORTSTRLEN;
-  ats_ip_nptop(qvc->get_remote_addr(), reinterpret_cast<char *>(key), key_len);
+  ats_ip_nptop(qc->five_tuple().source(), reinterpret_cast<char *>(key), key_len);
 
   unsigned int dst_len = 0;
   HMAC(EVP_sha1(), stateless_cookie_secret, STATELESS_COOKIE_SECRET_LENGTH, key, key_len, cookie, &dst_len);
diff --git a/iocore/net/quic/QUICTypes.cc b/iocore/net/quic/QUICTypes.cc
index 077e26d..c4064b5 100644
--- a/iocore/net/quic/QUICTypes.cc
+++ b/iocore/net/quic/QUICTypes.cc
@@ -175,3 +175,40 @@ QUICError::code()
 {
   return static_cast<uint16_t>(this->trans_error_code);
 }
+
+//
+// QUICFiveTuple
+//
+QUICFiveTuple::QUICFiveTuple(IpEndpoint src, IpEndpoint dst, int protocol) : _source(src), _destination(dst), _protocol(protocol)
+{
+  // FIXME Generate a hash code
+  this->_hash_code = src.port() + dst.port() + protocol;
+}
+void
+QUICFiveTuple::update(IpEndpoint src, IpEndpoint dst, int protocol)
+{
+  this->_source      = src;
+  this->_destination = dst;
+  this->_protocol    = protocol;
+
+  // FIXME Generate a hash code
+  this->_hash_code = src.port() + dst.port() + protocol;
+}
+
+IpEndpoint
+QUICFiveTuple::source() const
+{
+  return this->_source;
+}
+
+IpEndpoint
+QUICFiveTuple::destination() const
+{
+  return this->_destination;
+}
+
+int
+QUICFiveTuple::protocol() const
+{
+  return this->_protocol;
+}
diff --git a/iocore/net/quic/QUICTypes.h b/iocore/net/quic/QUICTypes.h
index 2b4814d..6f77ad1 100644
--- a/iocore/net/quic/QUICTypes.h
+++ b/iocore/net/quic/QUICTypes.h
@@ -31,6 +31,7 @@
 #include <cstdint>
 #include "ts/INK_MD5.h"
 #include "ts/ink_memory.h"
+#include "ts/ink_inet.h"
 
 // These magical defines should be removed when we implement seriously
 #define MAGIC_NUMBER_0 0
@@ -254,6 +255,23 @@ enum class QUICStreamType : uint8_t {
   HANDSHAKE,
 };
 
+class QUICFiveTuple
+{
+public:
+  QUICFiveTuple(){};
+  QUICFiveTuple(IpEndpoint src, IpEndpoint dst, int protocol);
+  void update(IpEndpoint src, IpEndpoint dst, int protocol);
+  IpEndpoint source() const;
+  IpEndpoint destination() const;
+  int protocol() const;
+
+private:
+  IpEndpoint _source;
+  IpEndpoint _destination;
+  int _protocol;
+  uint64_t _hash_code = 0;
+};
+
 class QUICTypeUtil
 {
 public:

-- 
To stop receiving notification emails like this one, please contact
maskit@apache.org.