http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/P_OCSPStapling.h ---------------------------------------------------------------------- diff --git a/iocore/net/P_OCSPStapling.h b/iocore/net/P_OCSPStapling.h index 5d414e8..077529c 100644 --- a/iocore/net/P_OCSPStapling.h +++ b/iocore/net/P_OCSPStapling.h @@ -27,10 +27,10 @@ #ifdef sk_OPENSSL_STRING_pop #ifdef SSL_CTX_set_tlsext_status_cb #define HAVE_OPENSSL_OCSP_STAPLING 1 - void ssl_stapling_ex_init(); - bool ssl_stapling_init_cert(SSL_CTX *ctx, const char *certfile); - void ocsp_update(); - int ssl_callback_ocsp_stapling(SSL *); +void ssl_stapling_ex_init(); +bool ssl_stapling_init_cert(SSL_CTX *ctx, const char *certfile); +void ocsp_update(); +int ssl_callback_ocsp_stapling(SSL *); #endif /* SSL_CTX_set_tlsext_status_cb */ #endif /* sk_OPENSSL_STRING_pop */
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/P_SSLCertLookup.h ---------------------------------------------------------------------- diff --git a/iocore/net/P_SSLCertLookup.h b/iocore/net/P_SSLCertLookup.h index 23fad46..a6c3629 100644 --- a/iocore/net/P_SSLCertLookup.h +++ b/iocore/net/P_SSLCertLookup.h @@ -30,15 +30,13 @@ struct SSLConfigParams; struct SSLContextStorage; -struct ssl_ticket_key_t -{ +struct ssl_ticket_key_t { unsigned char key_name[16]; unsigned char hmac_secret[16]; unsigned char aes_key[16]; }; -struct ssl_ticket_key_block -{ +struct ssl_ticket_key_block { unsigned num_keys; ssl_ticket_key_t keys[]; }; @@ -54,57 +52,57 @@ struct ssl_ticket_key_block there is exactly one place we can find all the @c SSL_CTX instances exactly once. */ -struct SSLCertContext -{ +struct SSLCertContext { /** Special things to do instead of use a context. In general an option will be associated with a @c NULL context because the context is not used. */ enum Option { - OPT_NONE, ///< Nothing special. Implies valid context. + OPT_NONE, ///< Nothing special. Implies valid context. OPT_TUNNEL ///< Just tunnel, don't terminate. }; SSLCertContext() : ctx(0), opt(OPT_NONE), keyblock(NULL) {} - explicit SSLCertContext(SSL_CTX* c) : ctx(c), opt(OPT_NONE), keyblock(NULL) {} - SSLCertContext(SSL_CTX* c, Option o) : ctx(c), opt(o), keyblock(NULL) {} - SSLCertContext(SSL_CTX* c, Option o, ssl_ticket_key_block *kb) : ctx(c), opt(o), keyblock(kb) {} + explicit SSLCertContext(SSL_CTX *c) : ctx(c), opt(OPT_NONE), keyblock(NULL) {} + SSLCertContext(SSL_CTX *c, Option o) : ctx(c), opt(o), keyblock(NULL) {} + SSLCertContext(SSL_CTX *c, Option o, ssl_ticket_key_block *kb) : ctx(c), opt(o), keyblock(kb) {} - SSL_CTX* ctx; ///< openSSL context. - Option opt; ///< Special handling option. + SSL_CTX *ctx; ///< openSSL context. + Option opt; ///< Special handling option. ssl_ticket_key_block *keyblock; ///< session keys associated with this address - }; -struct SSLCertLookup : public ConfigInfo -{ - SSLContextStorage * ssl_storage; - SSL_CTX * ssl_default; - bool is_valid; +struct SSLCertLookup : public ConfigInfo { + SSLContextStorage *ssl_storage; + SSL_CTX *ssl_default; + bool is_valid; int insert(const char *name, SSLCertContext const &cc); - int insert(const IpEndpoint& address, SSLCertContext const &cc); + int insert(const IpEndpoint &address, SSLCertContext const &cc); /** Find certificate context by IP address. The IP addresses are taken from the socket @a s. Exact matches have priority, then wildcards. The destination address is preferred to the source address. @return @c A pointer to the matched context, @c NULL if no match is found. */ - SSLCertContext* find(const IpEndpoint& address) const; + SSLCertContext *find(const IpEndpoint &address) const; /** Find certificate context by name (FQDN). Exact matches have priority, then wildcards. Only destination based matches are checked. @return @c A pointer to the matched context, @c NULL if no match is found. */ - SSLCertContext* find(char const* name) const; - + SSLCertContext *find(char const *name) const; // Return the last-resort default TLS context if there is no name or address match. - SSL_CTX * defaultContext() const { return ssl_default; } + SSL_CTX * + defaultContext() const + { + return ssl_default; + } unsigned count() const; - SSLCertContext * get(unsigned i) const; + SSLCertContext *get(unsigned i) const; SSLCertLookup(); virtual ~SSLCertLookup(); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/P_SSLConfig.h ---------------------------------------------------------------------- diff --git a/iocore/net/P_SSLConfig.h b/iocore/net/P_SSLConfig.h index cda2dcb..549aa28 100644 --- a/iocore/net/P_SSLConfig.h +++ b/iocore/net/P_SSLConfig.h @@ -47,10 +47,8 @@ struct SSLCertLookup; typedef void (*init_ssl_ctx_func)(void *, bool); -struct SSLConfigParams : public ConfigInfo -{ - enum SSL_SESSION_CACHE_MODE - { +struct SSLConfigParams : public ConfigInfo { + enum SSL_SESSION_CACHE_MODE { SSL_SESSION_CACHE_MODE_OFF = 0, SSL_SESSION_CACHE_MODE_SERVER_OPENSSL_IMPL = 1, SSL_SESSION_CACHE_MODE_SERVER_ATS_IMPL = 2 @@ -59,40 +57,40 @@ struct SSLConfigParams : public ConfigInfo SSLConfigParams(); virtual ~SSLConfigParams(); - char * serverCertPathOnly; - char * serverCertChainFilename; - char * serverKeyPathOnly; - char * serverCACertFilename; - char * serverCACertPath; - char * configFilePath; - char * dhparamsFile; - char * cipherSuite; - char * client_cipherSuite; - int clientCertLevel; - int verify_depth; - int ssl_session_cache; // SSL_SESSION_CACHE_MODE - int ssl_session_cache_size; - int ssl_session_cache_num_buckets; - int ssl_session_cache_skip_on_contention; - int ssl_session_cache_timeout; - int ssl_session_cache_auto_clear; - - char * clientCertPath; - char * clientKeyPath; - char * clientCACertFilename; - char * clientCACertPath; - int clientVerify; - int client_verify_depth; - long ssl_ctx_options; - long ssl_client_ctx_protocols; + char *serverCertPathOnly; + char *serverCertChainFilename; + char *serverKeyPathOnly; + char *serverCACertFilename; + char *serverCACertPath; + char *configFilePath; + char *dhparamsFile; + char *cipherSuite; + char *client_cipherSuite; + int clientCertLevel; + int verify_depth; + int ssl_session_cache; // SSL_SESSION_CACHE_MODE + int ssl_session_cache_size; + int ssl_session_cache_num_buckets; + int ssl_session_cache_skip_on_contention; + int ssl_session_cache_timeout; + int ssl_session_cache_auto_clear; + + char *clientCertPath; + char *clientKeyPath; + char *clientCACertFilename; + char *clientCACertPath; + int clientVerify; + int client_verify_depth; + long ssl_ctx_options; + long ssl_client_ctx_protocols; static int ssl_maxrecord; static bool ssl_allow_client_renegotiation; static bool ssl_ocsp_enabled; - static int ssl_ocsp_cache_timeout; - static int ssl_ocsp_request_timeout; - static int ssl_ocsp_update_period; + static int ssl_ocsp_cache_timeout; + static int ssl_ocsp_request_timeout; + static int ssl_ocsp_update_period; static size_t session_cache_number_buckets; static size_t session_cache_max_bucket_size; @@ -110,12 +108,11 @@ struct SSLConfigParams : public ConfigInfo // ///////////////////////////////////////////////////////////// -struct SSLConfig -{ +struct SSLConfig { static void startup(); static void reconfigure(); - static SSLConfigParams * acquire(); - static void release(SSLConfigParams * params); + static SSLConfigParams *acquire(); + static void release(SSLConfigParams *params); typedef ConfigProcessor::scoped_config<SSLConfig, SSLConfigParams> scoped_config; @@ -123,12 +120,11 @@ private: static int configid; }; -struct SSLCertificateConfig -{ +struct SSLCertificateConfig { static bool startup(); static bool reconfigure(); - static SSLCertLookup * acquire(); - static void release(SSLCertLookup * params); + static SSLCertLookup *acquire(); + static void release(SSLCertLookup *params); typedef ConfigProcessor::scoped_config<SSLCertificateConfig, SSLCertLookup> scoped_config; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/P_SSLNetAccept.h ---------------------------------------------------------------------- diff --git a/iocore/net/P_SSLNetAccept.h b/iocore/net/P_SSLNetAccept.h index d50d7ea..1ed4280 100644 --- a/iocore/net/P_SSLNetAccept.h +++ b/iocore/net/P_SSLNetAccept.h @@ -36,7 +36,7 @@ ****************************************************************************/ -#if !defined (_SSLNetAccept_h_) +#if !defined(_SSLNetAccept_h_) #define _SSLNetAccept_h_ #include "libts.h" @@ -50,18 +50,14 @@ class UnixNetVConnection; // NetAccept // Handles accepting connections. // -struct SSLNetAccept: public NetAccept -{ - virtual NetProcessor * getNetProcessor() const; +struct SSLNetAccept : public NetAccept { + virtual NetProcessor *getNetProcessor() const; virtual EventType getEtype() const; virtual void init_accept_per_thread(); virtual NetAccept *clone() const; - SSLNetAccept() - { }; - - virtual ~SSLNetAccept() - { }; + SSLNetAccept(){}; + virtual ~SSLNetAccept(){}; }; #endif http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/P_SSLNetProcessor.h ---------------------------------------------------------------------- diff --git a/iocore/net/P_SSLNetProcessor.h b/iocore/net/P_SSLNetProcessor.h index 2ff93d6..ec008dd 100644 --- a/iocore/net/P_SSLNetProcessor.h +++ b/iocore/net/P_SSLNetProcessor.h @@ -45,15 +45,17 @@ struct NetAccept; // class SSLNetProcessor // ////////////////////////////////////////////////////////////////// -struct SSLNetProcessor : public UnixNetProcessor -{ +struct SSLNetProcessor : public UnixNetProcessor { public: - virtual int start(int no_of_ssl_threads, size_t stacksize); void cleanup(void); - SSL_CTX *getClientSSL_CTX(void) const { return client_ctx; } + SSL_CTX * + getClientSSL_CTX(void) const + { + return client_ctx; + } SSLNetProcessor(); virtual ~SSLNetProcessor(); @@ -70,12 +72,12 @@ public: // to be upgraded to ET_SSL for SSLNetProcessor. virtual void upgradeEtype(EventType &etype); - virtual NetAccept * createNetAccept(); - virtual NetVConnection * allocate_vc(EThread *t); + virtual NetAccept *createNetAccept(); + virtual NetVConnection *allocate_vc(EThread *t); private: SSLNetProcessor(const SSLNetProcessor &); - SSLNetProcessor & operator =(const SSLNetProcessor &); + SSLNetProcessor &operator=(const SSLNetProcessor &); }; extern SSLNetProcessor ssl_NetProcessor; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/P_SSLNetVConnection.h ---------------------------------------------------------------------- diff --git a/iocore/net/P_SSLNetVConnection.h b/iocore/net/P_SSLNetVConnection.h index c32ecd5..f458bb7 100644 --- a/iocore/net/P_SSLNetVConnection.h +++ b/iocore/net/P_SSLNetVConnection.h @@ -29,7 +29,7 @@ ****************************************************************************/ -#if !defined (_SSLNetVConnection_h_) +#if !defined(_SSLNetVConnection_h_) #define _SSLNetVConnection_h_ #include "libts.h" @@ -60,10 +60,10 @@ // (another 20-60 bytes on average, depending on the negotiated ciphersuite [2]). // All in all: 1500 - 40 (IP) - 20 (TCP) - 40 (TCP options) - TLS overhead (60-100) // For larger records, the size is determined by TLS protocol record size -#define SSL_DEF_TLS_RECORD_SIZE 1300 // 1500 - 40 (IP) - 20 (TCP) - 40 (TCP options) - TLS overhead (60-100) -#define SSL_MAX_TLS_RECORD_SIZE 16383 // 2^14 - 1 -#define SSL_DEF_TLS_RECORD_BYTE_THRESHOLD 1000000 -#define SSL_DEF_TLS_RECORD_MSEC_THRESHOLD 1000 +#define SSL_DEF_TLS_RECORD_SIZE 1300 // 1500 - 40 (IP) - 20 (TCP) - 40 (TCP options) - TLS overhead (60-100) +#define SSL_MAX_TLS_RECORD_SIZE 16383 // 2^14 - 1 +#define SSL_DEF_TLS_RECORD_BYTE_THRESHOLD 1000000 +#define SSL_DEF_TLS_RECORD_MSEC_THRESHOLD 1000 class SSLNextProtocolSet; struct SSLCertLookup; @@ -75,37 +75,43 @@ struct SSLCertLookup; // A VConnection for a network socket. // ////////////////////////////////////////////////////////////////// -class SSLNetVConnection:public UnixNetVConnection +class SSLNetVConnection : public UnixNetVConnection { typedef UnixNetVConnection super; ///< Parent type. public: virtual int sslStartHandShake(int event, int &err); - virtual void free(EThread * t); - virtual void enableRead() + virtual void free(EThread *t); + virtual void + enableRead() { read.enabled = 1; write.enabled = 1; }; - virtual bool getSSLHandShakeComplete() + virtual bool + getSSLHandShakeComplete() { return sslHandShakeComplete; }; - void setSSLHandShakeComplete(bool state) + void + setSSLHandShakeComplete(bool state) { sslHandShakeComplete = state; }; - virtual bool getSSLClientConnection() + virtual bool + getSSLClientConnection() { return sslClientConnection; }; - virtual void setSSLClientConnection(bool state) + virtual void + setSSLClientConnection(bool state) { sslClientConnection = state; }; int sslServerHandShakeEvent(int &err); int sslClientHandShakeEvent(int &err); - virtual void net_read_io(NetHandler * nh, EThread * lthread); - virtual int64_t load_buffer_and_write(int64_t towrite, int64_t &wattempted, int64_t &total_written, MIOBufferAccessor & buf, int &needs); + virtual void net_read_io(NetHandler *nh, EThread *lthread); + virtual int64_t load_buffer_and_write(int64_t towrite, int64_t &wattempted, int64_t &total_written, MIOBufferAccessor &buf, + int &needs); void registerNextProtocolSet(const SSLNextProtocolSet *); //////////////////////////////////////////////////////////// @@ -114,36 +120,43 @@ public: // The constructor is public just to avoid compile errors.// //////////////////////////////////////////////////////////// SSLNetVConnection(); - virtual ~SSLNetVConnection() { } + virtual ~SSLNetVConnection() {} SSL *ssl; ink_hrtime sslHandshakeBeginTime; ink_hrtime sslLastWriteTime; - int64_t sslTotalBytesSent; + int64_t sslTotalBytesSent; - static int advertise_next_protocol(SSL * ssl, const unsigned char ** out, unsigned * outlen, void *); - static int select_next_protocol(SSL * ssl, const unsigned char ** out, unsigned char * outlen, const unsigned char * in, unsigned inlen, void *); + static int advertise_next_protocol(SSL *ssl, const unsigned char **out, unsigned *outlen, void *); + static int select_next_protocol(SSL *ssl, const unsigned char **out, unsigned char *outlen, const unsigned char *in, + unsigned inlen, void *); - Continuation * endpoint() const { + Continuation * + endpoint() const + { return npnEndpoint; } - bool getSSLClientRenegotiationAbort() const + bool + getSSLClientRenegotiationAbort() const { return sslClientRenegotiationAbort; }; - void setSSLClientRenegotiationAbort(bool state) + void + setSSLClientRenegotiationAbort(bool state) { sslClientRenegotiationAbort = state; }; - bool getTransparentPassThrough() const + bool + getTransparentPassThrough() const { return transparentPassThrough; }; - void setTransparentPassThrough(bool val) + void + setTransparentPassThrough(bool val) { transparentPassThrough = val; }; @@ -152,22 +165,26 @@ public: using super::reenable; /// Reenable the VC after a pre-accept or SNI hook is called. - virtual void reenable(NetHandler* nh); + virtual void reenable(NetHandler *nh); /// Set the SSL context. /// @note This must be called after the SSL endpoint has been created. - virtual bool sslContextSet(void* ctx); + virtual bool sslContextSet(void *ctx); /// Set by asynchronous hooks to request a specific operation. TSSslVConnOp hookOpRequested; int64_t read_raw_data(); - void initialize_handshake_buffers() { + void + initialize_handshake_buffers() + { this->handShakeBuffer = new_MIOBuffer(); this->handShakeReader = this->handShakeBuffer->alloc_reader(); this->handShakeHolder = this->handShakeReader->clone(); this->handShakeBioStored = 0; } - void free_handshake_buffers() { + void + free_handshake_buffers() + { if (this->handShakeReader) { this->handShakeReader->dealloc(); } @@ -187,13 +204,11 @@ public: // Returns true if we have already called at // least some of the hooks - bool calledHooks(TSHttpHookID /* eventId */) { - return (this->sslHandshakeHookState != HANDSHAKE_HOOKS_PRE); - } + bool calledHooks(TSHttpHookID /* eventId */) { return (this->sslHandshakeHookState != HANDSHAKE_HOOKS_PRE); } private: SSLNetVConnection(const SSLNetVConnection &); - SSLNetVConnection & operator =(const SSLNetVConnection &); + SSLNetVConnection &operator=(const SSLNetVConnection &); bool sslHandShakeComplete; bool sslClientConnection; @@ -207,14 +222,14 @@ private: /// The current hook. /// @note For @C SSL_HOOKS_INVOKE, this is the hook to invoke. - class APIHook* curHook; + class APIHook *curHook; enum { - SSL_HOOKS_INIT, ///< Initial state, no hooks called yet. - SSL_HOOKS_INVOKE, ///< Waiting to invoke hook. - SSL_HOOKS_ACTIVE, ///< Hook invoked, waiting for it to complete. + SSL_HOOKS_INIT, ///< Initial state, no hooks called yet. + SSL_HOOKS_INVOKE, ///< Waiting to invoke hook. + SSL_HOOKS_ACTIVE, ///< Hook invoked, waiting for it to complete. SSL_HOOKS_CONTINUE, ///< All hooks have been called and completed - SSL_HOOKS_DONE ///< All hooks have been called and completed + SSL_HOOKS_DONE ///< All hooks have been called and completed } sslPreAcceptHookState; enum SSLHandshakeHookState { @@ -225,11 +240,11 @@ private: HANDSHAKE_HOOKS_DONE } sslHandshakeHookState; - const SSLNextProtocolSet * npnSet; - Continuation * npnEndpoint; + const SSLNextProtocolSet *npnSet; + Continuation *npnEndpoint; }; -typedef int (SSLNetVConnection::*SSLNetVConnHandler) (int, void *); +typedef int (SSLNetVConnection::*SSLNetVConnHandler)(int, void *); extern ClassAllocator<SSLNetVConnection> sslNetVCAllocator; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/P_SSLNextProtocolAccept.h ---------------------------------------------------------------------- diff --git a/iocore/net/P_SSLNextProtocolAccept.h b/iocore/net/P_SSLNextProtocolAccept.h index 800d881..51968ce 100644 --- a/iocore/net/P_SSLNextProtocolAccept.h +++ b/iocore/net/P_SSLNextProtocolAccept.h @@ -31,36 +31,36 @@ #include "P_SSLNextProtocolSet.h" #include "I_IOBuffer.h" -class SSLNextProtocolAccept: public SessionAccept +class SSLNextProtocolAccept : public SessionAccept { public: SSLNextProtocolAccept(Continuation *, bool); ~SSLNextProtocolAccept(); - void accept(NetVConnection *, MIOBuffer *, IOBufferReader*); + void accept(NetVConnection *, MIOBuffer *, IOBufferReader *); // Register handler as an endpoint for the specified protocol. Neither // handler nor protocol are copied, so the caller must guarantee their // lifetime is at least as long as that of the acceptor. - bool registerEndpoint(const char * protocol, Continuation * handler); + bool registerEndpoint(const char *protocol, Continuation *handler); // Unregister the handler. Returns false if this protocol is not registered // or if it is not registered for the specified handler. - bool unregisterEndpoint(const char * protocol, Continuation * handler); + bool unregisterEndpoint(const char *protocol, Continuation *handler); SLINK(SSLNextProtocolAccept, link); private: - int mainEvent(int event, void * netvc); - SSLNextProtocolAccept(const SSLNextProtocolAccept &); // disabled - SSLNextProtocolAccept& operator =(const SSLNextProtocolAccept&); // disabled + int mainEvent(int event, void *netvc); + SSLNextProtocolAccept(const SSLNextProtocolAccept &); // disabled + SSLNextProtocolAccept &operator=(const SSLNextProtocolAccept &); // disabled - MIOBuffer * buffer; // XXX do we really need this? - Continuation * endpoint; + MIOBuffer *buffer; // XXX do we really need this? + Continuation *endpoint; SSLNextProtocolSet protoset; bool transparent_passthrough; -friend struct SSLNextProtocolTrampoline; + friend struct SSLNextProtocolTrampoline; }; #endif /* P_SSLNextProtocolAccept_H_ */ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/P_SSLNextProtocolSet.h ---------------------------------------------------------------------- diff --git a/iocore/net/P_SSLNextProtocolSet.h b/iocore/net/P_SSLNextProtocolSet.h index 729038a..fd38c15 100644 --- a/iocore/net/P_SSLNextProtocolSet.h +++ b/iocore/net/P_SSLNextProtocolSet.h @@ -37,29 +37,28 @@ public: bool registerEndpoint(const char *, Continuation *); bool unregisterEndpoint(const char *, Continuation *); - bool advertiseProtocols(const unsigned char ** out, unsigned * len) const; + bool advertiseProtocols(const unsigned char **out, unsigned *len) const; - Continuation * findEndpoint(const unsigned char *, unsigned) const; + Continuation *findEndpoint(const unsigned char *, unsigned) const; - struct NextProtocolEndpoint - { + struct NextProtocolEndpoint { // NOTE: the protocol and endpoint are NOT copied. The caller is // responsible for ensuring their lifetime. - NextProtocolEndpoint(const char * protocol, Continuation * endpoint); + NextProtocolEndpoint(const char *protocol, Continuation *endpoint); ~NextProtocolEndpoint(); - const char * protocol; - Continuation * endpoint; + const char *protocol; + Continuation *endpoint; LINK(NextProtocolEndpoint, link); typedef DLL<NextProtocolEndpoint> list_type; }; private: - SSLNextProtocolSet(const SSLNextProtocolSet&); // disabled - SSLNextProtocolSet& operator=(const SSLNextProtocolSet&); // disabled + SSLNextProtocolSet(const SSLNextProtocolSet &); // disabled + SSLNextProtocolSet &operator=(const SSLNextProtocolSet &); // disabled - mutable unsigned char * npn; + mutable unsigned char *npn; mutable size_t npnsz; NextProtocolEndpoint::list_type endpoints; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/P_SSLUtils.h ---------------------------------------------------------------------- diff --git a/iocore/net/P_SSLUtils.h b/iocore/net/P_SSLUtils.h index 6d7697c..bd7aa89 100644 --- a/iocore/net/P_SSLUtils.h +++ b/iocore/net/P_SSLUtils.h @@ -40,8 +40,7 @@ struct RecRawStatBlock; typedef int ssl_error_t; -enum SSL_Stats -{ +enum SSL_Stats { ssl_origin_server_expired_cert_stat, ssl_user_agent_expired_cert_stat, ssl_origin_server_revoked_cert_stat, @@ -69,7 +68,7 @@ enum SSL_Stats ssl_total_tickets_created_stat, ssl_total_tickets_verified_stat, ssl_total_tickets_verified_old_key_stat, // verified with old key. - ssl_total_ticket_keys_renewed_stat, // number of keys renewed. + ssl_total_ticket_keys_renewed_stat, // number of keys renewed. ssl_total_tickets_not_found_stat, ssl_total_tickets_renewed_stat, ssl_total_dyn_def_tls_record_count, @@ -100,21 +99,21 @@ enum SSL_Stats extern RecRawStatBlock *ssl_rsb; /* Stats should only be accessed using these macros */ -#define SSL_INCREMENT_DYN_STAT(x) RecIncrRawStat(ssl_rsb, NULL, (int) x, 1) -#define SSL_DECREMENT_DYN_STAT(x) RecIncrRawStat(ssl_rsb, NULL, (int) x, -1) -#define SSL_SET_COUNT_DYN_STAT(x,count) RecSetRawStatCount(ssl_rsb, x, count) -#define SSL_INCREMENT_DYN_STAT_EX(x, y) RecIncrRawStat(ssl_rsb, NULL, (int) x, y) -#define SSL_CLEAR_DYN_STAT(x) \ - do { \ - RecSetRawStatSum(ssl_rsb, (x), 0); \ +#define SSL_INCREMENT_DYN_STAT(x) RecIncrRawStat(ssl_rsb, NULL, (int)x, 1) +#define SSL_DECREMENT_DYN_STAT(x) RecIncrRawStat(ssl_rsb, NULL, (int)x, -1) +#define SSL_SET_COUNT_DYN_STAT(x, count) RecSetRawStatCount(ssl_rsb, x, count) +#define SSL_INCREMENT_DYN_STAT_EX(x, y) RecIncrRawStat(ssl_rsb, NULL, (int)x, y) +#define SSL_CLEAR_DYN_STAT(x) \ + do { \ + RecSetRawStatSum(ssl_rsb, (x), 0); \ RecSetRawStatCount(ssl_rsb, (x), 0); \ } while (0) // Create a default SSL server context. -SSL_CTX * SSLDefaultServerContext(); +SSL_CTX *SSLDefaultServerContext(); // Create and initialize a SSL client context. -SSL_CTX * SSLInitClientContext(const SSLConfigParams * param); +SSL_CTX *SSLInitClientContext(const SSLConfigParams *param); // Initialize the SSL library. void SSLInitializeLibrary(); @@ -123,55 +122,83 @@ void SSLInitializeLibrary(); void SSLInitializeStatistics(); // Release SSL_CTX and the associated data -void SSLReleaseContext(SSL_CTX* ctx); +void SSLReleaseContext(SSL_CTX *ctx); // Wrapper functions to SSL I/O routines -ssl_error_t SSLWriteBuffer(SSL * ssl, const void * buf, int64_t nbytes, int64_t& nwritten); -ssl_error_t SSLReadBuffer(SSL * ssl, void * buf, int64_t nbytes, int64_t& nread); +ssl_error_t SSLWriteBuffer(SSL *ssl, const void *buf, int64_t nbytes, int64_t &nwritten); +ssl_error_t SSLReadBuffer(SSL *ssl, void *buf, int64_t nbytes, int64_t &nread); ssl_error_t SSLAccept(SSL *ssl); -ssl_error_t SSLConnect(SSL * ssl); +ssl_error_t SSLConnect(SSL *ssl); // Log an SSL error. #define SSLError(fmt, ...) SSLDiagnostic(DiagsMakeLocation(), false, NULL, fmt, ##__VA_ARGS__) -#define SSLErrorVC(vc,fmt, ...) SSLDiagnostic(DiagsMakeLocation(), false, (vc), fmt, ##__VA_ARGS__) +#define SSLErrorVC(vc, fmt, ...) SSLDiagnostic(DiagsMakeLocation(), false, (vc), fmt, ##__VA_ARGS__) // Log a SSL diagnostic using the "ssl" diagnostic tag. #define SSLDebug(fmt, ...) SSLDiagnostic(DiagsMakeLocation(), true, NULL, fmt, ##__VA_ARGS__) #define SSLDebugVC(vc, fmt, ...) SSLDiagnostic(DiagsMakeLocation(), true, (vc), fmt, ##__VA_ARGS__) #define SSL_CLR_ERR_INCR_DYN_STAT(vc, x, fmt, ...) \ - do { \ - SSLDebugVC((vc), fmt, ##__VA_ARGS__); \ - RecIncrRawStat(ssl_rsb, NULL, (int) x, 1); \ + do { \ + SSLDebugVC((vc), fmt, ##__VA_ARGS__); \ + RecIncrRawStat(ssl_rsb, NULL, (int)x, 1); \ } while (0) -void SSLDiagnostic(const SrcLoc& loc, bool debug, SSLNetVConnection * vc, const char * fmt, ...) TS_PRINTFLIKE(4, 5); +void SSLDiagnostic(const SrcLoc &loc, bool debug, SSLNetVConnection *vc, const char *fmt, ...) TS_PRINTFLIKE(4, 5); // Return a static string name for a SSL_ERROR constant. -const char * SSLErrorName(int ssl_error); +const char *SSLErrorName(int ssl_error); // Log a SSL network buffer. -void SSLDebugBufferPrint(const char * tag, const char * buffer, unsigned buflen, const char * message); +void SSLDebugBufferPrint(const char *tag, const char *buffer, unsigned buflen, const char *message); // Load the SSL certificate configuration. -bool SSLParseCertificateConfiguration(const SSLConfigParams * params, SSLCertLookup * lookup); +bool SSLParseCertificateConfiguration(const SSLConfigParams *params, SSLCertLookup *lookup); -namespace ssl { namespace detail { +namespace ssl +{ +namespace detail +{ struct SCOPED_X509_TRAITS { - typedef X509* value_type; - static value_type initValue() { return NULL; } - static bool isValid(value_type x) { return x != NULL; } - static void destroy(value_type x) { X509_free(x); } + typedef X509 *value_type; + static value_type + initValue() + { + return NULL; + } + static bool + isValid(value_type x) + { + return x != NULL; + } + static void + destroy(value_type x) + { + X509_free(x); + } }; struct SCOPED_BIO_TRAITS { - typedef BIO* value_type; - static value_type initValue() { return NULL; } - static bool isValid(value_type x) { return x != NULL; } - static void destroy(value_type x) { BIO_free(x); } + typedef BIO *value_type; + static value_type + initValue() + { + return NULL; + } + static bool + isValid(value_type x) + { + return x != NULL; + } + static void + destroy(value_type x) + { + BIO_free(x); + } }; -/* namespace ssl */ } /* namespace detail */ } +/* namespace ssl */ } /* namespace detail */ +} -typedef ats_scoped_resource<ssl::detail::SCOPED_X509_TRAITS> scoped_X509; -typedef ats_scoped_resource<ssl::detail::SCOPED_BIO_TRAITS> scoped_BIO; +typedef ats_scoped_resource<ssl::detail::SCOPED_X509_TRAITS> scoped_X509; +typedef ats_scoped_resource<ssl::detail::SCOPED_BIO_TRAITS> scoped_BIO; #endif /* __P_SSLUTILS_H__ */ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/P_Socks.h ---------------------------------------------------------------------- diff --git a/iocore/net/P_Socks.h b/iocore/net/P_Socks.h index c7ad37c..aa9cacf 100644 --- a/iocore/net/P_Socks.h +++ b/iocore/net/P_Socks.h @@ -31,17 +31,15 @@ #include <ts/IpMap.h> #endif -enum -{ - //types of events for Socks auth handlers +enum { + // types of events for Socks auth handlers SOCKS_AUTH_OPEN, SOCKS_AUTH_WRITE_COMPLETE, SOCKS_AUTH_READ_COMPLETE, SOCKS_AUTH_FILL_WRITE_BUF }; -struct socks_conf_struct -{ +struct socks_conf_struct { int socks_needed; int server_connect_timeout; int socks_timeout; @@ -52,7 +50,7 @@ struct socks_conf_struct int per_server_connection_attempts; int connection_attempts; - //the following ports are used by SocksProxy + // the following ports are used by SocksProxy int accept_enabled; int accept_port; unsigned short http_port; @@ -65,13 +63,14 @@ struct socks_conf_struct IpEndpoint server_addr; #endif - socks_conf_struct():socks_needed(0), server_connect_timeout(0), socks_timeout(100), default_version(5), - user_name_n_passwd(NULL), user_name_n_passwd_len(0), - per_server_connection_attempts(1), connection_attempts(0), accept_enabled(0), accept_port(0), http_port(1080) + socks_conf_struct() + : socks_needed(0), server_connect_timeout(0), socks_timeout(100), default_version(5), user_name_n_passwd(NULL), + user_name_n_passwd_len(0), per_server_connection_attempts(1), connection_attempts(0), accept_enabled(0), accept_port(0), + http_port(1080) { -# if !defined(SOCKS_WITH_TS) +#if !defined(SOCKS_WITH_TS) memset(&server_addr, 0, sizeof(server_addr)); -# endif +#endif } }; @@ -79,20 +78,20 @@ extern struct socks_conf_struct *g_socks_conf_stuff; void start_SocksProxy(int port); -int loadSocksAuthInfo(int fd, socks_conf_struct * socks_stuff); +int loadSocksAuthInfo(int fd, socks_conf_struct *socks_stuff); // umm.. the following typedef should take _its own_ type as one of the args // not possible with C // Right now just use a generic fn ptr and hide casting in an inline fn. -typedef int (*SocksAuthHandler) (int event, unsigned char *buf, void (**h_ptr) (void)); +typedef int (*SocksAuthHandler)(int event, unsigned char *buf, void (**h_ptr)(void)); TS_INLINE int -invokeSocksAuthHandler(SocksAuthHandler & h, int arg1, unsigned char *arg2) +invokeSocksAuthHandler(SocksAuthHandler &h, int arg1, unsigned char *arg2) { - return (h) (arg1, arg2, (void (**)(void)) (&h)); + return (h)(arg1, arg2, (void (**)(void))(&h)); } -void loadSocksConfiguration(socks_conf_struct * socks_conf_stuff); +void loadSocksConfiguration(socks_conf_struct *socks_conf_stuff); int socks5BasicAuthHandler(int event, unsigned char *p, void (**)(void)); int socks5PasswdAuthHandler(int event, unsigned char *p, void (**)(void)); int socks5ServerAuthHandler(int event, unsigned char *p, void (**)(void)); @@ -100,10 +99,7 @@ int socks5ServerAuthHandler(int event, unsigned char *p, void (**)(void)); class UnixNetVConnection; typedef UnixNetVConnection SocksNetVC; -struct SocksEntry:public Continuation -{ - - +struct SocksEntry : public Continuation { MIOBuffer *buf; IOBufferReader *reader; @@ -127,28 +123,28 @@ struct SocksEntry:public Continuation unsigned char socks_cmd; #ifdef SOCKS_WITH_TS - //socks server selection: + // socks server selection: ParentConfigParams *server_params; - HttpRequestData req_data; //We dont use any http specific fields. + HttpRequestData req_data; // We dont use any http specific fields. ParentResult server_result; #endif int startEvent(int event, void *data); int mainEvent(int event, void *data); void findServer(); - void init(ProxyMutex * m, SocksNetVC * netvc, unsigned char socks_support, unsigned char ver); + void init(ProxyMutex *m, SocksNetVC *netvc, unsigned char socks_support, unsigned char ver); void free(); - SocksEntry():Continuation(NULL), netVConnection(0), - nattempts(0), - lerrno(0), timeout(0), version(5), write_done(false), auth_handler(NULL), socks_cmd(NORMAL_SOCKS) + SocksEntry() + : Continuation(NULL), netVConnection(0), nattempts(0), lerrno(0), timeout(0), version(5), write_done(false), auth_handler(NULL), + socks_cmd(NORMAL_SOCKS) { memset(&target_addr, 0, sizeof(target_addr)); memset(&server_addr, 0, sizeof(server_addr)); } }; -typedef int (SocksEntry::*SocksEntryHandler) (int, void *); +typedef int (SocksEntry::*SocksEntryHandler)(int, void *); extern ClassAllocator<SocksEntry> socksAllocator; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/P_UDPConnection.h ---------------------------------------------------------------------- diff --git a/iocore/net/P_UDPConnection.h b/iocore/net/P_UDPConnection.h index 7cc7c33..bac1a83 100644 --- a/iocore/net/P_UDPConnection.h +++ b/iocore/net/P_UDPConnection.h @@ -34,16 +34,15 @@ #include "I_UDPNet.h" -class UDPConnectionInternal:public UDPConnection +class UDPConnectionInternal : public UDPConnection { - public: UDPConnectionInternal(); - virtual ~ UDPConnectionInternal(); + virtual ~UDPConnectionInternal(); Continuation *continuation; - int recvActive; // interested in receiving - int refcount; // public for assertion + int recvActive; // interested in receiving + int refcount; // public for assertion SOCKET fd; IpEndpoint binding; @@ -84,13 +83,13 @@ UDPConnectionInternal::~UDPConnectionInternal() TS_INLINE SOCKET UDPConnection::getFd() { - return ((UDPConnectionInternal *) this)->fd; + return ((UDPConnectionInternal *)this)->fd; } TS_INLINE void -UDPConnection::setBinding(struct sockaddr const* s) +UDPConnection::setBinding(struct sockaddr const *s) { - UDPConnectionInternal *p = (UDPConnectionInternal *) this; + UDPConnectionInternal *p = (UDPConnectionInternal *)this; ats_ip_copy(&p->binding, s); p->binding_valid = 1; } @@ -98,7 +97,7 @@ UDPConnection::setBinding(struct sockaddr const* s) TS_INLINE int UDPConnection::getBinding(struct sockaddr *s) { - UDPConnectionInternal *p = (UDPConnectionInternal *) this; + UDPConnectionInternal *p = (UDPConnectionInternal *)this; ats_ip_copy(s, &p->binding); return p->binding_valid; } @@ -106,31 +105,31 @@ UDPConnection::getBinding(struct sockaddr *s) TS_INLINE void UDPConnection::destroy() { - ((UDPConnectionInternal *) this)->tobedestroyed = 1; + ((UDPConnectionInternal *)this)->tobedestroyed = 1; } TS_INLINE int UDPConnection::shouldDestroy() { - return ((UDPConnectionInternal *) this)->tobedestroyed; + return ((UDPConnectionInternal *)this)->tobedestroyed; } TS_INLINE void UDPConnection::AddRef() { - ink_atomic_increment(&((UDPConnectionInternal *) this)->refcount, 1); + ink_atomic_increment(&((UDPConnectionInternal *)this)->refcount, 1); } TS_INLINE int UDPConnection::GetRefCount() { - return ((UDPConnectionInternal *) this)->refcount; + return ((UDPConnectionInternal *)this)->refcount; } TS_INLINE int UDPConnection::GetSendGenerationNumber() { - return ((UDPConnectionInternal *) this)->sendGenerationNum; + return ((UDPConnectionInternal *)this)->sendGenerationNum; } TS_INLINE int @@ -142,7 +141,7 @@ UDPConnection::getPortNum(void) TS_INLINE int64_t UDPConnection::cancel(void) { - UDPConnectionInternal *p = (UDPConnectionInternal *) this; + UDPConnectionInternal *p = (UDPConnectionInternal *)this; p->sendGenerationNum++; p->lastPktStartTime = p->lastSentPktStartTime; @@ -152,16 +151,16 @@ UDPConnection::cancel(void) TS_INLINE void UDPConnection::SetLastSentPktTSSeqNum(int64_t sentSeqNum) { - ((UDPConnectionInternal *) this)->lastSentPktTSSeqNum = sentSeqNum; + ((UDPConnectionInternal *)this)->lastSentPktTSSeqNum = sentSeqNum; } TS_INLINE void -UDPConnection::setContinuation(Continuation * c) +UDPConnection::setContinuation(Continuation *c) { // it is not safe to switch among continuations that don't share locks ink_assert(mutex == NULL || c->mutex == mutex); mutex = c->mutex; - ((UDPConnectionInternal *) this)->continuation = c; + ((UDPConnectionInternal *)this)->continuation = c; } #endif //__P_UDPCONNECTION_H_ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/P_UDPIOEvent.h ---------------------------------------------------------------------- diff --git a/iocore/net/P_UDPIOEvent.h b/iocore/net/P_UDPIOEvent.h index bc5511d..4daddae 100644 --- a/iocore/net/P_UDPIOEvent.h +++ b/iocore/net/P_UDPIOEvent.h @@ -26,67 +26,73 @@ // ugly -- just encapsulate the I/O result so that it can be passed // back to the caller via continuation handler. -class UDPIOEvent:public Event +class UDPIOEvent : public Event { public: - UDPIOEvent():fd(-1), err(0), m(0), handle(0), b(0), bytesTransferred(0) - { - }; - ~UDPIOEvent() { - }; - void setInfo(int fd_, IOBufferBlock * b_, int bytesTransferred_, int errno_) + UDPIOEvent() : fd(-1), err(0), m(0), handle(0), b(0), bytesTransferred(0){}; + ~UDPIOEvent(){}; + void + setInfo(int fd_, IOBufferBlock *b_, int bytesTransferred_, int errno_) { fd = fd_; b = b_; bytesTransferred = bytesTransferred_; err = errno_; }; - void setInfo(int fd_, struct msghdr *m_, int bytesTransferred_, int errno_) + void + setInfo(int fd_, struct msghdr *m_, int bytesTransferred_, int errno_) { fd = fd_; m = m_; bytesTransferred = bytesTransferred_; err = errno_; }; - void setHandle(void *v) + void + setHandle(void *v) { handle = v; } - void *getHandle() + void * + getHandle() { return handle; } void free(); - int getBytesTransferred() + int + getBytesTransferred() { return bytesTransferred; } - IOBufferBlock *getIOBufferBlock() + IOBufferBlock * + getIOBufferBlock() { return b; } - int getError() + int + getError() { return err; } - Continuation *getContinuation() + Continuation * + getContinuation() { return continuation; } - static void free(UDPIOEvent * e); + static void free(UDPIOEvent *e); + private: - void *operator new(size_t size); // undefined + void *operator new(size_t size); // undefined int fd; - int err; // error code + int err; // error code struct msghdr *m; - void *handle; // some extra data for the client handler - Ptr<IOBufferBlock> b; // holds buffer that I/O will go to - int bytesTransferred; // actual bytes transferred + void *handle; // some extra data for the client handler + Ptr<IOBufferBlock> b; // holds buffer that I/O will go to + int bytesTransferred; // actual bytes transferred }; extern ClassAllocator<UDPIOEvent> UDPIOEventAllocator; TS_INLINE void -UDPIOEvent::free(UDPIOEvent * e) +UDPIOEvent::free(UDPIOEvent *e) { e->b = NULL; e->mutex = NULL; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/P_UDPNet.h ---------------------------------------------------------------------- diff --git a/iocore/net/P_UDPNet.h b/iocore/net/P_UDPNet.h index d159e1a..fab6b71 100644 --- a/iocore/net/P_UDPNet.h +++ b/iocore/net/P_UDPNet.h @@ -36,7 +36,7 @@ extern EventType ET_UDP; #include "I_UDPNet.h" #include "P_UDPPacket.h" -//added by YTS Team, yamsat +// added by YTS Team, yamsat static inline PollCont *get_UDPPollCont(EThread *); #include "P_UnixUDPConnection.h" @@ -44,11 +44,10 @@ static inline PollCont *get_UDPPollCont(EThread *); struct UDPNetHandler; -struct UDPNetProcessorInternal : public UDPNetProcessor -{ +struct UDPNetProcessorInternal : public UDPNetProcessor { virtual int start(int n_udp_threads, size_t stacksize); - void udp_read_from_net(UDPNetHandler * nh, UDPConnection * uc); - int udp_callback(UDPNetHandler * nh, UDPConnection * uc, EThread * thread); + void udp_read_from_net(UDPNetHandler *nh, UDPConnection *uc); + int udp_callback(UDPNetHandler *nh, UDPConnection *uc, EThread *thread); off_t pollCont_offset; off_t udpNetHandler_offset; @@ -57,7 +56,6 @@ struct UDPNetProcessorInternal : public UDPNetProcessor extern UDPNetProcessorInternal udpNetInternal; - // 20 ms slots; 2048 slots => 40 sec. into the future #define SLOT_TIME_MSEC 20 #define SLOT_TIME HRTIME_MSECONDS(SLOT_TIME_MSEC) @@ -65,16 +63,14 @@ extern UDPNetProcessorInternal udpNetInternal; class PacketQueue { - public: - PacketQueue() - : nPackets(0), now_slot(0) - { - lastPullLongTermQ = 0; - init(); - } +public: + PacketQueue() : nPackets(0), now_slot(0) + { + lastPullLongTermQ = 0; + init(); + } - virtual ~ PacketQueue() - { } + virtual ~PacketQueue() {} int nPackets; ink_hrtime lastPullLongTermQ; @@ -83,7 +79,8 @@ class PacketQueue ink_hrtime delivery_time[N_SLOTS]; int now_slot; - void init(void) + void + init(void) { now_slot = 0; ink_hrtime now = ink_get_hrtime_internal(); @@ -96,7 +93,8 @@ class PacketQueue } } - void addPacket(UDPPacketInternal * e, ink_hrtime now = 0) + void + addPacket(UDPPacketInternal *e, ink_hrtime now = 0) { int before = 0; int slot; @@ -133,14 +131,14 @@ class PacketQueue slot = (s + now_slot) % N_SLOTS; // so that slot+1 is still "in future". - ink_assert((before || delivery_time[slot] <= e->delivery_time) && - (delivery_time[(slot + 1) % N_SLOTS] >= e->delivery_time)); + ink_assert((before || delivery_time[slot] <= e->delivery_time) && (delivery_time[(slot + 1) % N_SLOTS] >= e->delivery_time)); e->in_the_priority_queue = 1; e->in_heap = slot; bucket[slot].enqueue(e); } - UDPPacketInternal *firstPacket(ink_hrtime t) + UDPPacketInternal * + firstPacket(ink_hrtime t) { if (t > delivery_time[now_slot]) { return bucket[now_slot].head; @@ -149,25 +147,29 @@ class PacketQueue } } - UDPPacketInternal *getFirstPacket() + UDPPacketInternal * + getFirstPacket() { nPackets--; return dequeue_ready(0); } - int size() + int + size() { ink_assert(nPackets >= 0); return nPackets; } - bool IsCancelledPacket(UDPPacketInternal * p) + bool + IsCancelledPacket(UDPPacketInternal *p) { // discard packets that'll never get sent... return ((p->conn->shouldDestroy()) || (p->conn->GetSendGenerationNumber() != p->reqGenerationNum)); } - void FreeCancelledPackets(int numSlots) + void + FreeCancelledPackets(int numSlots) { UDPPacketInternal *p; Queue<UDPPacketInternal> tempQ; @@ -189,7 +191,8 @@ class PacketQueue } } - void advanceNow(ink_hrtime t) + void + advanceNow(ink_hrtime t) { int s = now_slot; int prev; @@ -223,13 +226,14 @@ class PacketQueue } if (s != now_slot) - Debug("udpnet-service", "Advancing by (%d slots): behind by %" PRId64 " ms", - s - now_slot, ink_hrtime_to_msec(t - delivery_time[now_slot])); + Debug("udpnet-service", "Advancing by (%d slots): behind by %" PRId64 " ms", s - now_slot, + ink_hrtime_to_msec(t - delivery_time[now_slot])); now_slot = s; } - private: - void remove(UDPPacketInternal * e) +private: + void + remove(UDPPacketInternal *e) { nPackets--; ink_assert(e->in_the_priority_queue); @@ -237,10 +241,11 @@ class PacketQueue bucket[e->in_heap].remove(e); } - public: - UDPPacketInternal *dequeue_ready(ink_hrtime t) +public: + UDPPacketInternal * + dequeue_ready(ink_hrtime t) { - (void) t; + (void)t; UDPPacketInternal *e = bucket[now_slot].dequeue(); if (e) { ink_assert(e->in_the_priority_queue); @@ -250,12 +255,14 @@ class PacketQueue return e; } - void check_ready(ink_hrtime now) + void + check_ready(ink_hrtime now) { - (void) now; + (void)now; } - ink_hrtime earliest_timeout() + ink_hrtime + earliest_timeout() { int s = now_slot; for (int i = 0; i < N_SLOTS; i++) { @@ -267,9 +274,11 @@ class PacketQueue return HRTIME_FOREVER; } - private: - void kill_cancelled_events() - { } +private: + void + kill_cancelled_events() + { + } }; @@ -288,20 +297,19 @@ public: void service(UDPNetHandler *); void SendPackets(); - void SendUDPPacket(UDPPacketInternal * p, int32_t pktLen); + void SendUDPPacket(UDPPacketInternal *p, int32_t pktLen); // Interface exported to the outside world - void send(UDPPacket * p); + void send(UDPPacket *p); UDPQueue(); ~UDPQueue(); }; -void initialize_thread_for_udp_net(EThread * thread); +void initialize_thread_for_udp_net(EThread *thread); -struct UDPNetHandler: public Continuation -{ +struct UDPNetHandler : public Continuation { public: // to be polled for read Que(UnixUDPConnection, polling_link) udp_polling; @@ -319,21 +327,21 @@ public: ink_hrtime nextCheck; ink_hrtime lastCheck; - int startNetEvent(int event, Event * data); - int mainNetEvent(int event, Event * data); + int startNetEvent(int event, Event *data); + int mainNetEvent(int event, Event *data); UDPNetHandler(); }; struct PollCont; static inline PollCont * -get_UDPPollCont(EThread * t) +get_UDPPollCont(EThread *t) { return (PollCont *)ETHREAD_GET_PTR(t, udpNetInternal.pollCont_offset); } static inline UDPNetHandler * -get_UDPNetHandler(EThread * t) +get_UDPNetHandler(EThread *t) { return (UDPNetHandler *)ETHREAD_GET_PTR(t, udpNetInternal.udpNetHandler_offset); } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/P_UDPPacket.h ---------------------------------------------------------------------- diff --git a/iocore/net/P_UDPPacket.h b/iocore/net/P_UDPPacket.h index f56e0b9..d926eef 100644 --- a/iocore/net/P_UDPPacket.h +++ b/iocore/net/P_UDPPacket.h @@ -34,27 +34,26 @@ #include "I_UDPNet.h" -class UDPPacketInternal:public UDPPacket +class UDPPacketInternal : public UDPPacket { - public: UDPPacketInternal(); - virtual ~ UDPPacketInternal(); + virtual ~UDPPacketInternal(); - void append_block_internal(IOBufferBlock * block); + void append_block_internal(IOBufferBlock *block); virtual void free(); - SLINK(UDPPacketInternal, alink); // atomic link + SLINK(UDPPacketInternal, alink); // atomic link // packet scheduling stuff: keep it a doubly linked list uint64_t pktLength; int reqGenerationNum; - ink_hrtime delivery_time; // when to deliver packet + ink_hrtime delivery_time; // when to deliver packet Ptr<IOBufferBlock> chain; - Continuation *cont; // callback on error - UDPConnectionInternal *conn; // connection where packet should be sent to. + Continuation *cont; // callback on error + UDPConnectionInternal *conn; // connection where packet should be sent to. int in_the_priority_queue; int in_heap; @@ -64,8 +63,7 @@ inkcoreapi extern ClassAllocator<UDPPacketInternal> udpPacketAllocator; TS_INLINE UDPPacketInternal::UDPPacketInternal() - : pktLength(0), reqGenerationNum(0), delivery_time(0), cont(NULL), - conn(NULL), in_the_priority_queue(0), in_heap(0) + : pktLength(0), reqGenerationNum(0), delivery_time(0), cont(NULL), conn(NULL), in_the_priority_queue(0), in_heap(0) { memset(&from, '\0', sizeof(from)); memset(&to, '\0', sizeof(to)); @@ -88,12 +86,12 @@ UDPPacketInternal::free() } TS_INLINE void -UDPPacket::append_block(IOBufferBlock * block) +UDPPacket::append_block(IOBufferBlock *block) { - UDPPacketInternal *p = (UDPPacketInternal *) this; + UDPPacketInternal *p = (UDPPacketInternal *)this; if (block) { - if (p->chain) { // append to end + if (p->chain) { // append to end IOBufferBlock *last = p->chain; while (last->next != NULL) { last = last->next; @@ -108,7 +106,7 @@ UDPPacket::append_block(IOBufferBlock * block) TS_INLINE int64_t UDPPacket::getPktLength() { - UDPPacketInternal *p = (UDPPacketInternal *) this; + UDPPacketInternal *p = (UDPPacketInternal *)this; IOBufferBlock *b; p->pktLength = 0; @@ -123,17 +121,17 @@ UDPPacket::getPktLength() TS_INLINE void UDPPacket::free() { - ((UDPPacketInternal *) this)->free(); + ((UDPPacketInternal *)this)->free(); } TS_INLINE void -UDPPacket::setContinuation(Continuation * c) +UDPPacket::setContinuation(Continuation *c) { - ((UDPPacketInternal *) this)->cont = c; + ((UDPPacketInternal *)this)->cont = c; } TS_INLINE void -UDPPacket::setConnection(UDPConnection * c) +UDPPacket::setConnection(UDPConnection *c) { /*Code reviewed by Case Larsen. Previously, we just had ink_assert(!conn). This prevents tunneling of packets @@ -142,7 +140,7 @@ UDPPacket::setConnection(UDPConnection * c) assert will prevent that. The "if" clause enables correct handling of the connection ref. counts in such a scenario. */ - UDPConnectionInternal *&conn = ((UDPPacketInternal *) this)->conn; + UDPConnectionInternal *&conn = ((UDPPacketInternal *)this)->conn; if (conn) { if (conn == c) @@ -150,24 +148,24 @@ UDPPacket::setConnection(UDPConnection * c) conn->Release(); conn = NULL; } - conn = (UDPConnectionInternal *) c; + conn = (UDPConnectionInternal *)c; conn->AddRef(); } TS_INLINE IOBufferBlock * UDPPacket::getIOBlockChain(void) { - return ((UDPPacketInternal *) this)->chain; + return ((UDPPacketInternal *)this)->chain; } TS_INLINE UDPConnection * UDPPacket::getConnection(void) { - return ((UDPPacketInternal *) this)->conn; + return ((UDPPacketInternal *)this)->conn; } TS_INLINE UDPPacket * -new_UDPPacket(struct sockaddr const* to, ink_hrtime when, char *buf, int len) +new_UDPPacket(struct sockaddr const *to, ink_hrtime when, char *buf, int len) { UDPPacketInternal *p = udpPacketAllocator.alloc(); @@ -188,9 +186,9 @@ new_UDPPacket(struct sockaddr const* to, ink_hrtime when, char *buf, int len) } TS_INLINE UDPPacket * -new_UDPPacket(struct sockaddr const* to, ink_hrtime when, IOBufferBlock * buf, int len) +new_UDPPacket(struct sockaddr const *to, ink_hrtime when, IOBufferBlock *buf, int len) { - (void) len; + (void)len; UDPPacketInternal *p = udpPacketAllocator.alloc(); IOBufferBlock *body; @@ -208,7 +206,7 @@ new_UDPPacket(struct sockaddr const* to, ink_hrtime when, IOBufferBlock * buf, i } TS_INLINE UDPPacket * -new_UDPPacket(struct sockaddr const* to, ink_hrtime when, Ptr<IOBufferBlock> buf) +new_UDPPacket(struct sockaddr const *to, ink_hrtime when, Ptr<IOBufferBlock> buf) { UDPPacketInternal *p = udpPacketAllocator.alloc(); @@ -228,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, char *buf, int len) { UDPPacketInternal *p = udpPacketAllocator.alloc(); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/P_UnixCompletionUtil.h ---------------------------------------------------------------------- diff --git a/iocore/net/P_UnixCompletionUtil.h b/iocore/net/P_UnixCompletionUtil.h index 4a7f547..e9e6235 100644 --- a/iocore/net/P_UnixCompletionUtil.h +++ b/iocore/net/P_UnixCompletionUtil.h @@ -35,70 +35,70 @@ completionUtil::create() return u; } TS_INLINE void -completionUtil::destroy(Event * e) +completionUtil::destroy(Event *e) { ink_assert(e != NULL); - UDPIOEvent *u = (UDPIOEvent *) e; + UDPIOEvent *u = (UDPIOEvent *)e; UDPIOEvent::free(u); } TS_INLINE void -completionUtil::setThread(Event * e, EThread * t) +completionUtil::setThread(Event *e, EThread *t) { - UDPIOEvent *u = (UDPIOEvent *) e; + UDPIOEvent *u = (UDPIOEvent *)e; u->ethread = t; } TS_INLINE void -completionUtil::setContinuation(Event * e, Continuation * c) +completionUtil::setContinuation(Event *e, Continuation *c) { - UDPIOEvent *u = (UDPIOEvent *) e; - *(Action *) u = c; + UDPIOEvent *u = (UDPIOEvent *)e; + *(Action *)u = c; } TS_INLINE void * -completionUtil::getHandle(Event * e) +completionUtil::getHandle(Event *e) { - UDPIOEvent *u = (UDPIOEvent *) e; + UDPIOEvent *u = (UDPIOEvent *)e; return u->getHandle(); } TS_INLINE void -completionUtil::setHandle(Event * e, void *handle) +completionUtil::setHandle(Event *e, void *handle) { - UDPIOEvent *u = (UDPIOEvent *) e; + UDPIOEvent *u = (UDPIOEvent *)e; u->setHandle(handle); } TS_INLINE void -completionUtil::setInfo(Event * e, int fd, IOBufferBlock * buf, int actual, int errno_) +completionUtil::setInfo(Event *e, int fd, IOBufferBlock *buf, int actual, int errno_) { - UDPIOEvent *u = (UDPIOEvent *) e; + UDPIOEvent *u = (UDPIOEvent *)e; u->setInfo(fd, buf, actual, errno_); } TS_INLINE void -completionUtil::setInfo(Event * e, int fd, struct msghdr *msg, int actual, int errno_) +completionUtil::setInfo(Event *e, int fd, struct msghdr *msg, int actual, int errno_) { - UDPIOEvent *u = (UDPIOEvent *) e; + UDPIOEvent *u = (UDPIOEvent *)e; u->setInfo(fd, msg, actual, errno_); } TS_INLINE int -completionUtil::getBytesTransferred(Event * e) +completionUtil::getBytesTransferred(Event *e) { - UDPIOEvent *u = (UDPIOEvent *) e; + UDPIOEvent *u = (UDPIOEvent *)e; return u->getBytesTransferred(); } TS_INLINE IOBufferBlock * -completionUtil::getIOBufferBlock(Event * e) +completionUtil::getIOBufferBlock(Event *e) { - UDPIOEvent *u = (UDPIOEvent *) e; + UDPIOEvent *u = (UDPIOEvent *)e; return u->getIOBufferBlock(); } TS_INLINE Continuation * -completionUtil::getContinuation(Event * e) +completionUtil::getContinuation(Event *e) { - UDPIOEvent *u = (UDPIOEvent *) e; + UDPIOEvent *u = (UDPIOEvent *)e; return u->getContinuation(); } TS_INLINE int -completionUtil::getError(Event * e) +completionUtil::getError(Event *e) { - UDPIOEvent *u = (UDPIOEvent *) e; + UDPIOEvent *u = (UDPIOEvent *)e; return u->getError(); } #endif http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/P_UnixNet.h ---------------------------------------------------------------------- diff --git a/iocore/net/P_UnixNet.h b/iocore/net/P_UnixNet.h index 7b8228a..3b06428 100644 --- a/iocore/net/P_UnixNet.h +++ b/iocore/net/P_UnixNet.h @@ -26,27 +26,27 @@ #include "libts.h" -#define USE_EDGE_TRIGGER_EPOLL 1 +#define USE_EDGE_TRIGGER_EPOLL 1 #define USE_EDGE_TRIGGER_KQUEUE 1 -#define USE_EDGE_TRIGGER_PORT 1 +#define USE_EDGE_TRIGGER_PORT 1 -#define EVENTIO_NETACCEPT 1 -#define EVENTIO_READWRITE_VC 2 -#define EVENTIO_DNS_CONNECTION 3 -#define EVENTIO_UDP_CONNECTION 4 -#define EVENTIO_ASYNC_SIGNAL 5 +#define EVENTIO_NETACCEPT 1 +#define EVENTIO_READWRITE_VC 2 +#define EVENTIO_DNS_CONNECTION 3 +#define EVENTIO_UDP_CONNECTION 4 +#define EVENTIO_ASYNC_SIGNAL 5 #if TS_USE_EPOLL #ifdef USE_EDGE_TRIGGER_EPOLL #define USE_EDGE_TRIGGER 1 -#define EVENTIO_READ (EPOLLIN|EPOLLET) -#define EVENTIO_WRITE (EPOLLOUT|EPOLLET) +#define EVENTIO_READ (EPOLLIN | EPOLLET) +#define EVENTIO_WRITE (EPOLLOUT | EPOLLET) #else #define EVENTIO_READ EPOLLIN #define EVENTIO_WRITE EPOLLOUT #endif -#define EVENTIO_ERROR (EPOLLERR|EPOLLPRI|EPOLLHUP) +#define EVENTIO_ERROR (EPOLLERR | EPOLLPRI | EPOLLHUP) #endif #if TS_USE_KQUEUE @@ -58,15 +58,15 @@ #endif #define EVENTIO_READ INK_EVP_IN #define EVENTIO_WRITE INK_EVP_OUT -#define EVENTIO_ERROR (0x010|0x002|0x020) // ERR PRI HUP +#define EVENTIO_ERROR (0x010 | 0x002 | 0x020) // ERR PRI HUP #endif #if TS_USE_PORT #ifdef USE_EDGE_TRIGGER_PORT #define USE_EDGE_TRIGGER 1 #endif -#define EVENTIO_READ POLLIN +#define EVENTIO_READ POLLIN #define EVENTIO_WRITE POLLOUT -#define EVENTIO_ERROR (POLLERR|POLLPRI|POLLHUP) +#define EVENTIO_ERROR (POLLERR | POLLPRI | POLLHUP) #endif struct PollDescriptor; @@ -76,16 +76,14 @@ class UnixNetVConnection; class UnixUDPConnection; struct DNSConnection; struct NetAccept; -struct EventIO -{ +struct EventIO { int fd; #if TS_USE_KQUEUE || TS_USE_EPOLL && !defined(USE_EDGE_TRIGGER) || TS_USE_PORT int events; #endif EventLoop event_loop; int type; - union - { + union { Continuation *c; UnixNetVConnection *vc; DNSConnection *dnscon; @@ -104,7 +102,8 @@ struct EventIO int refresh(int events); int stop(); int close(); - EventIO() { + EventIO() + { type = 0; data.c = 0; } @@ -119,7 +118,7 @@ struct EventIO class UnixNetVConnection; class NetHandler; -typedef int (NetHandler::*NetContHandler) (int, void *); +typedef int (NetHandler::*NetContHandler)(int, void *); typedef unsigned int uint32; extern ink_hrtime last_throttle_warning; @@ -139,40 +138,39 @@ extern int http_accept_port_number; // Design notes are in Memo.NetDesign // -#define THROTTLE_FD_HEADROOM (128 + 64) // CACHE_DB_FDS + 64 +#define THROTTLE_FD_HEADROOM (128 + 64) // CACHE_DB_FDS + 64 -#define TRANSIENT_ACCEPT_ERROR_MESSAGE_EVERY HRTIME_HOURS(24) -#define NET_RETRY_DELAY HRTIME_MSECONDS(10) +#define TRANSIENT_ACCEPT_ERROR_MESSAGE_EVERY HRTIME_HOURS(24) +#define NET_RETRY_DELAY HRTIME_MSECONDS(10) // also the 'throttle connect headroom' -#define THROTTLE_AT_ONCE 5 -#define EMERGENCY_THROTTLE 16 -#define HYPER_EMERGENCY_THROTTLE 6 +#define THROTTLE_AT_ONCE 5 +#define EMERGENCY_THROTTLE 16 +#define HYPER_EMERGENCY_THROTTLE 6 -#define NET_THROTTLE_ACCEPT_HEADROOM 1.1 // 10% -#define NET_THROTTLE_CONNECT_HEADROOM 1.0 // 0% -#define NET_THROTTLE_MESSAGE_EVERY HRTIME_MINUTES(10) -#define NET_PERIOD -HRTIME_MSECONDS(5) -#define ACCEPT_PERIOD -HRTIME_MSECONDS(4) -#define NET_THROTTLE_DELAY 50 /* mseconds */ +#define NET_THROTTLE_ACCEPT_HEADROOM 1.1 // 10% +#define NET_THROTTLE_CONNECT_HEADROOM 1.0 // 0% +#define NET_THROTTLE_MESSAGE_EVERY HRTIME_MINUTES(10) +#define NET_PERIOD -HRTIME_MSECONDS(5) +#define ACCEPT_PERIOD -HRTIME_MSECONDS(4) +#define NET_THROTTLE_DELAY 50 /* mseconds */ -#define PRINT_IP(x) ((uint8_t*)&(x))[0],((uint8_t*)&(x))[1], ((uint8_t*)&(x))[2],((uint8_t*)&(x))[3] +#define PRINT_IP(x) ((uint8_t *)&(x))[0], ((uint8_t *)&(x))[1], ((uint8_t *)&(x))[2], ((uint8_t *)&(x))[3] // function prototype needed for SSLUnixNetVConnection unsigned int net_next_connection_number(); -struct PollCont:public Continuation -{ +struct PollCont : public Continuation { NetHandler *net_handler; PollDescriptor *pollDescriptor; PollDescriptor *nextPollDescriptor; int poll_timeout; - PollCont(ProxyMutex * m, int pt = net_config_poll_timeout); - PollCont(ProxyMutex * m, NetHandler * nh, int pt = net_config_poll_timeout); + PollCont(ProxyMutex *m, int pt = net_config_poll_timeout); + PollCont(ProxyMutex *m, NetHandler *nh, int pt = net_config_poll_timeout); ~PollCont(); - int pollEvent(int event, Event * e); + int pollEvent(int event, Event *e); }; @@ -182,7 +180,7 @@ struct PollCont:public Continuation // A NetHandler handles the Network IO operations. It maintains // lists of operations at multiples of it's periodicity. // -class NetHandler:public Continuation +class NetHandler : public Continuation { public: Event *trigger_event; @@ -198,48 +196,49 @@ public: time_t sec; int cycles; - int startNetEvent(int event, Event * data); - int mainNetEvent(int event, Event * data); - int mainNetEventExt(int event, Event * data); + int startNetEvent(int event, Event *data); + int mainNetEvent(int event, Event *data); + int mainNetEventExt(int event, Event *data); void process_enabled_list(NetHandler *); NetHandler(); }; static inline NetHandler * -get_NetHandler(EThread * t) +get_NetHandler(EThread *t) { - return (NetHandler *) ETHREAD_GET_PTR(t, unix_netProcessor.netHandler_offset); + return (NetHandler *)ETHREAD_GET_PTR(t, unix_netProcessor.netHandler_offset); } static inline PollCont * -get_PollCont(EThread * t) +get_PollCont(EThread *t) { - return (PollCont *) ETHREAD_GET_PTR(t, unix_netProcessor.pollCont_offset); + return (PollCont *)ETHREAD_GET_PTR(t, unix_netProcessor.pollCont_offset); } static inline PollDescriptor * -get_PollDescriptor(EThread * t) +get_PollDescriptor(EThread *t) { PollCont *p = get_PollCont(t); return p->pollDescriptor; } -enum ThrottleType -{ ACCEPT, CONNECT }; +enum ThrottleType { + ACCEPT, + CONNECT, +}; TS_INLINE int net_connections_to_throttle(ThrottleType t) { - double headroom = t == ACCEPT ? NET_THROTTLE_ACCEPT_HEADROOM : NET_THROTTLE_CONNECT_HEADROOM; int64_t sval = 0; NET_READ_GLOBAL_DYN_SUM(net_connections_currently_open_stat, sval); - int currently_open = (int) sval; + int currently_open = (int)sval; // deal with race if we got to multiple net threads if (currently_open < 0) currently_open = 0; - return (int) (currently_open * headroom); + return (int)(currently_open * headroom); } TS_INLINE void @@ -279,7 +278,6 @@ check_throttle_warning() if (t - last_throttle_warning > NET_THROTTLE_MESSAGE_EVERY) { last_throttle_warning = t; RecSignalWarning(REC_SIGNAL_SYSTEM_ERROR, "too many connections, throttling"); - } } @@ -295,7 +293,7 @@ check_throttle_warning() // will recover. // TS_INLINE int -check_emergency_throttle(Connection & con) +check_emergency_throttle(Connection &con) { int fd = con.fd; int emergency = fds_limit - EMERGENCY_THROTTLE; @@ -315,10 +313,10 @@ check_emergency_throttle(Connection & con) TS_INLINE int change_net_connections_throttle(const char *token, RecDataT data_type, RecData value, void *data) { - (void) token; - (void) data_type; - (void) value; - (void) data; + (void)token; + (void)data_type; + (void)value; + (void)data; int throttle = fds_limit - THROTTLE_FD_HEADROOM; if (fds_throttle < 0) net_connections_throttle = throttle; @@ -340,8 +338,8 @@ accept_error_seriousness(int res) switch (res) { case -EAGAIN: case -ECONNABORTED: - case -ECONNRESET: // for Linux - case -EPIPE: // also for Linux + case -ECONNRESET: // for Linux + case -EPIPE: // also for Linux return 1; case -EMFILE: case -ENOMEM: @@ -389,7 +387,7 @@ check_transient_accept_error(int res) // Disable a UnixNetVConnection // static inline void -read_disable(NetHandler * nh, UnixNetVConnection * vc) +read_disable(NetHandler *nh, UnixNetVConnection *vc) { #ifdef INACTIVITY_TIMEOUT if (vc->inactivity_timeout) { @@ -410,7 +408,7 @@ read_disable(NetHandler * nh, UnixNetVConnection * vc) } static inline void -write_disable(NetHandler * nh, UnixNetVConnection * vc) +write_disable(NetHandler *nh, UnixNetVConnection *vc) { #ifdef INACTIVITY_TIMEOUT if (vc->inactivity_timeout) { @@ -430,34 +428,53 @@ write_disable(NetHandler * nh, UnixNetVConnection * vc) vc->ep.modify(-EVENTIO_WRITE); } -TS_INLINE int EventIO::start(EventLoop l, DNSConnection *vc, int events) { +TS_INLINE int +EventIO::start(EventLoop l, DNSConnection *vc, int events) +{ type = EVENTIO_DNS_CONNECTION; - return start(l, vc->fd, (Continuation*)vc, events); + return start(l, vc->fd, (Continuation *)vc, events); } -TS_INLINE int EventIO::start(EventLoop l, NetAccept *vc, int events) { +TS_INLINE int +EventIO::start(EventLoop l, NetAccept *vc, int events) +{ type = EVENTIO_NETACCEPT; - return start(l, vc->server.fd, (Continuation*)vc, events); + return start(l, vc->server.fd, (Continuation *)vc, events); } -TS_INLINE int EventIO::start(EventLoop l, UnixNetVConnection *vc, int events) { +TS_INLINE int +EventIO::start(EventLoop l, UnixNetVConnection *vc, int events) +{ type = EVENTIO_READWRITE_VC; - return start(l, vc->con.fd, (Continuation*)vc, events); + return start(l, vc->con.fd, (Continuation *)vc, events); } -TS_INLINE int EventIO::start(EventLoop l, UnixUDPConnection *vc, int events) { +TS_INLINE int +EventIO::start(EventLoop l, UnixUDPConnection *vc, int events) +{ type = EVENTIO_UDP_CONNECTION; - return start(l, vc->fd, (Continuation*)vc, events); + return start(l, vc->fd, (Continuation *)vc, events); } -TS_INLINE int EventIO::close() { +TS_INLINE int +EventIO::close() +{ stop(); switch (type) { - default: ink_assert(!"case"); - case EVENTIO_DNS_CONNECTION: return data.dnscon->close(); break; - case EVENTIO_NETACCEPT: return data.na->server.close(); break; - case EVENTIO_READWRITE_VC: return data.vc->con.close(); break; + default: + ink_assert(!"case"); + case EVENTIO_DNS_CONNECTION: + return data.dnscon->close(); + break; + case EVENTIO_NETACCEPT: + return data.na->server.close(); + break; + case EVENTIO_READWRITE_VC: + return data.vc->con.close(); + break; } return -1; } -TS_INLINE int EventIO::start(EventLoop l, int afd, Continuation *c, int e) { +TS_INLINE int +EventIO::start(EventLoop l, int afd, Continuation *c, int e) +{ data.c = c; fd = afd; event_loop = l; @@ -476,20 +493,23 @@ TS_INLINE int EventIO::start(EventLoop l, int afd, Continuation *c, int e) { struct kevent ev[2]; int n = 0; if (e & EVENTIO_READ) - EV_SET(&ev[n++], fd, EVFILT_READ, EV_ADD|INK_EV_EDGE_TRIGGER, 0, 0, this); + EV_SET(&ev[n++], fd, EVFILT_READ, EV_ADD | INK_EV_EDGE_TRIGGER, 0, 0, this); if (e & EVENTIO_WRITE) - EV_SET(&ev[n++], fd, EVFILT_WRITE, EV_ADD|INK_EV_EDGE_TRIGGER, 0, 0, this); + EV_SET(&ev[n++], fd, EVFILT_WRITE, EV_ADD | INK_EV_EDGE_TRIGGER, 0, 0, this); return kevent(l->kqueue_fd, &ev[0], n, NULL, 0, NULL); #endif #if TS_USE_PORT events = e; int retval = port_associate(event_loop->port_fd, PORT_SOURCE_FD, fd, events, this); - Debug("iocore_eventio", "[EventIO::start] e(%d), events(%d), %d[%s]=port_associate(%d,%d,%d,%d,%p)", e, events, retval, retval<0? strerror(errno) : "ok", event_loop->port_fd, PORT_SOURCE_FD, fd, events, this); + Debug("iocore_eventio", "[EventIO::start] e(%d), events(%d), %d[%s]=port_associate(%d,%d,%d,%d,%p)", e, events, retval, + retval < 0 ? strerror(errno) : "ok", event_loop->port_fd, PORT_SOURCE_FD, fd, events, this); return retval; #endif } -TS_INLINE int EventIO::modify(int e) { +TS_INLINE int +EventIO::modify(int e) +{ ink_assert(event_loop); #if TS_USE_EPOLL && !defined(USE_EDGE_TRIGGER) struct epoll_event ev; @@ -522,9 +542,9 @@ TS_INLINE int EventIO::modify(int e) { } else { ee |= e; if (e & EVENTIO_READ) - EV_SET(&ev[n++], fd, EVFILT_READ, EV_ADD|INK_EV_EDGE_TRIGGER, 0, 0, this); + EV_SET(&ev[n++], fd, EVFILT_READ, EV_ADD | INK_EV_EDGE_TRIGGER, 0, 0, this); if (e & EVENTIO_WRITE) - EV_SET(&ev[n++], fd, EVFILT_WRITE, EV_ADD|INK_EV_EDGE_TRIGGER, 0, 0, this); + EV_SET(&ev[n++], fd, EVFILT_WRITE, EV_ADD | INK_EV_EDGE_TRIGGER, 0, 0, this); } events = ee; if (n) @@ -555,7 +575,8 @@ TS_INLINE int EventIO::modify(int e) { if (n && ne && event_loop) { events = ne; int retval = port_associate(event_loop->port_fd, PORT_SOURCE_FD, fd, events, this); - Debug("iocore_eventio", "[EventIO::modify] e(%d), ne(%d), events(%d), %d[%s]=port_associate(%d,%d,%d,%d,%p)", e, ne, events, retval, retval<0? strerror(errno) : "ok", event_loop->port_fd, PORT_SOURCE_FD, fd, events, this); + Debug("iocore_eventio", "[EventIO::modify] e(%d), ne(%d), events(%d), %d[%s]=port_associate(%d,%d,%d,%d,%p)", e, ne, events, + retval, retval < 0 ? strerror(errno) : "ok", event_loop->port_fd, PORT_SOURCE_FD, fd, events, this); return retval; } return 0; @@ -565,16 +586,18 @@ TS_INLINE int EventIO::modify(int e) { #endif } -TS_INLINE int EventIO::refresh(int e) { +TS_INLINE int +EventIO::refresh(int e) +{ ink_assert(event_loop); #if TS_USE_KQUEUE && defined(USE_EDGE_TRIGGER) e = e & events; struct kevent ev[2]; int n = 0; if (e & EVENTIO_READ) - EV_SET(&ev[n++], fd, EVFILT_READ, EV_ADD|INK_EV_EDGE_TRIGGER, 0, 0, this); + EV_SET(&ev[n++], fd, EVFILT_READ, EV_ADD | INK_EV_EDGE_TRIGGER, 0, 0, this); if (e & EVENTIO_WRITE) - EV_SET(&ev[n++], fd, EVFILT_WRITE, EV_ADD|INK_EV_EDGE_TRIGGER, 0, 0, this); + EV_SET(&ev[n++], fd, EVFILT_WRITE, EV_ADD | INK_EV_EDGE_TRIGGER, 0, 0, this); if (n) return kevent(event_loop->kqueue_fd, &ev[0], n, NULL, 0, NULL); else @@ -592,8 +615,8 @@ TS_INLINE int EventIO::refresh(int e) { if (n && ne && event_loop) { events = ne; int retval = port_associate(event_loop->port_fd, PORT_SOURCE_FD, fd, events, this); - Debug("iocore_eventio", "[EventIO::refresh] e(%d), ne(%d), events(%d), %d[%s]=port_associate(%d,%d,%d,%d,%p)", - e, ne, events, retval, retval<0? strerror(errno) : "ok", event_loop->port_fd, PORT_SOURCE_FD, fd, events, this); + Debug("iocore_eventio", "[EventIO::refresh] e(%d), ne(%d), events(%d), %d[%s]=port_associate(%d,%d,%d,%d,%p)", e, ne, events, + retval, retval < 0 ? strerror(errno) : "ok", event_loop->port_fd, PORT_SOURCE_FD, fd, events, this); return retval; } } @@ -605,7 +628,9 @@ TS_INLINE int EventIO::refresh(int e) { } -TS_INLINE int EventIO::stop() { +TS_INLINE int +EventIO::stop() +{ if (event_loop) { int retval = 0; #if TS_USE_EPOLL @@ -616,7 +641,8 @@ TS_INLINE int EventIO::stop() { #endif #if TS_USE_PORT retval = port_dissociate(event_loop->port_fd, PORT_SOURCE_FD, fd); - Debug("iocore_eventio", "[EventIO::stop] %d[%s]=port_dissociate(%d,%d,%d)", retval, retval<0? strerror(errno) : "ok", event_loop->port_fd, PORT_SOURCE_FD, fd); + Debug("iocore_eventio", "[EventIO::stop] %d[%s]=port_dissociate(%d,%d,%d)", retval, retval < 0 ? strerror(errno) : "ok", + event_loop->port_fd, PORT_SOURCE_FD, fd); #endif event_loop = NULL; return retval; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/P_UnixNetProcessor.h ---------------------------------------------------------------------- diff --git a/iocore/net/P_UnixNetProcessor.h b/iocore/net/P_UnixNetProcessor.h index 47994c1..d28bc76 100644 --- a/iocore/net/P_UnixNetProcessor.h +++ b/iocore/net/P_UnixNetProcessor.h @@ -33,33 +33,19 @@ class UnixNetVConnection; // class UnixNetProcessor // ////////////////////////////////////////////////////////////////// -struct UnixNetProcessor:public NetProcessor -{ +struct UnixNetProcessor : public NetProcessor { public: - virtual Action *accept_internal ( - Continuation * cont, - int fd, - AcceptOptions const &opt - ); - - Action *connect_re_internal( - Continuation * cont, - sockaddr const* target, - NetVCOptions * options = NULL - ); - Action *connect( - Continuation * cont, - UnixNetVConnection ** vc, - sockaddr const* target, - NetVCOptions * opt = NULL - ); + virtual Action *accept_internal(Continuation *cont, int fd, AcceptOptions const &opt); + + Action *connect_re_internal(Continuation *cont, sockaddr const *target, NetVCOptions *options = NULL); + Action *connect(Continuation *cont, UnixNetVConnection **vc, sockaddr const *target, NetVCOptions *opt = NULL); // Virtual function allows etype to be upgraded to ET_SSL for SSLNetProcessor. Does // nothing for NetProcessor - virtual void upgradeEtype(EventType & /* etype ATS_UNUSED */) { }; + virtual void upgradeEtype(EventType & /* etype ATS_UNUSED */){}; virtual NetAccept *createNetAccept(); - virtual NetVConnection * allocate_vc(EThread *t); + virtual NetVConnection *allocate_vc(EThread *t); virtual int start(int number_of_net_threads, size_t stacksize); @@ -77,11 +63,8 @@ public: TS_INLINE Action * -NetProcessor::connect_re( - Continuation * cont, - sockaddr const* addr, - NetVCOptions * opts -) { +NetProcessor::connect_re(Continuation *cont, sockaddr const *addr, NetVCOptions *opts) +{ return static_cast<UnixNetProcessor *>(this)->connect_re_internal(cont, addr, opts); } @@ -92,7 +75,7 @@ extern UnixNetProcessor unix_netProcessor; // This function should be called for all threads created to // accept such events by the EventProcesor. // -extern void initialize_thread_for_net(EThread * thread); +extern void initialize_thread_for_net(EThread *thread); //#include "UnixNet.h" #endif http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/P_UnixNetState.h ---------------------------------------------------------------------- diff --git a/iocore/net/P_UnixNetState.h b/iocore/net/P_UnixNetState.h index 5c1d443..efffe8f 100644 --- a/iocore/net/P_UnixNetState.h +++ b/iocore/net/P_UnixNetState.h @@ -37,7 +37,7 @@ ****************************************************************************/ -#if !defined (_UnixNetState_h_) +#if !defined(_UnixNetState_h_) #define _UnixNetState_h_ #include "List.h" @@ -46,8 +46,7 @@ class Event; class UnixNetVConnection; -struct NetState -{ +struct NetState { volatile int enabled; VIO vio; Link<UnixNetVConnection> ready_link; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/P_UnixNetVConnection.h ---------------------------------------------------------------------- diff --git a/iocore/net/P_UnixNetVConnection.h b/iocore/net/P_UnixNetVConnection.h index eb16e02..c8ce1eb 100644 --- a/iocore/net/P_UnixNetVConnection.h +++ b/iocore/net/P_UnixNetVConnection.h @@ -70,8 +70,8 @@ NetVCOptions::reset() } TS_INLINE void -NetVCOptions::set_sock_param(int _recv_bufsize, int _send_bufsize, unsigned long _opt_flags, - unsigned long _packet_mark, unsigned long _packet_tos) +NetVCOptions::set_sock_param(int _recv_bufsize, int _send_bufsize, unsigned long _opt_flags, unsigned long _packet_mark, + unsigned long _packet_tos) { socket_recv_bufsize = _recv_bufsize; socket_send_bufsize = _send_bufsize; @@ -80,8 +80,7 @@ NetVCOptions::set_sock_param(int _recv_bufsize, int _send_bufsize, unsigned long packet_tos = _packet_tos; } -struct OOB_callback:public Continuation -{ +struct OOB_callback : public Continuation { char *data; int length; Event *trigger; @@ -89,19 +88,18 @@ struct OOB_callback:public Continuation Continuation *server_cont; int retry_OOB_send(int, Event *); - OOB_callback(ProxyMutex *m, NetVConnection *vc, Continuation *cont, - char *buf, int len):Continuation(m), data(buf), length(len), trigger(0) + OOB_callback(ProxyMutex *m, NetVConnection *vc, Continuation *cont, char *buf, int len) + : Continuation(m), data(buf), length(len), trigger(0) { - server_vc = (UnixNetVConnection *) vc; + server_vc = (UnixNetVConnection *)vc; server_cont = cont; SET_HANDLER(&OOB_callback::retry_OOB_send); } }; -class UnixNetVConnection:public NetVConnection +class UnixNetVConnection : public NetVConnection { public: - virtual VIO *do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf); virtual VIO *do_io_write(Continuation *c, int64_t nbytes, IOBufferReader *buf, bool owner = false); @@ -110,11 +108,27 @@ public: virtual Action *send_OOB(Continuation *cont, char *buf, int len); virtual void cancel_OOB(); - virtual void setSSLHandshakeWantsRead(bool /* flag */) { return; } - virtual bool getSSLHandshakeWantsRead() { return false; } - virtual void setSSLHandshakeWantsWrite(bool /* flag */) { return; } + virtual void + setSSLHandshakeWantsRead(bool /* flag */) + { + return; + } + virtual bool + getSSLHandshakeWantsRead() + { + return false; + } + virtual void + setSSLHandshakeWantsWrite(bool /* flag */) + { + return; + } - virtual bool getSSLHandshakeWantsWrite() { return false; } + virtual bool + getSSLHandshakeWantsWrite() + { + return false; + } virtual void do_io_close(int lerrno = -1); virtual void do_io_shutdown(ShutdownHowTo_t howto); @@ -144,7 +158,7 @@ public: virtual SOCKET get_socket(); - virtual ~ UnixNetVConnection(); + virtual ~UnixNetVConnection(); ///////////////////////////////////////////////////////////////// // instances of UnixNetVConnection should be allocated // @@ -155,10 +169,9 @@ public: private: UnixNetVConnection(const NetVConnection &); - UnixNetVConnection & operator =(const NetVConnection &); + UnixNetVConnection &operator=(const NetVConnection &); public: - ///////////////////////// // UNIX implementation // ///////////////////////// @@ -169,24 +182,31 @@ public: // these are not part of the pure virtual interface. They were // added to reduce the amount of duplicate code in classes inherited // from NetVConnection (SSL). - virtual int sslStartHandShake(int event, int &err) { - (void) event; - (void) err; + virtual int + sslStartHandShake(int event, int &err) + { + (void)event; + (void)err; return EVENT_ERROR; } - virtual bool getSSLHandShakeComplete() { + virtual bool + getSSLHandShakeComplete() + { return (true); } - virtual bool getSSLClientConnection() + virtual bool + getSSLClientConnection() { return (false); } - virtual void setSSLClientConnection(bool state) + virtual void + setSSLClientConnection(bool state) { - (void) state; + (void)state; } virtual void net_read_io(NetHandler *nh, EThread *lthread); - virtual int64_t load_buffer_and_write(int64_t towrite, int64_t &wattempted, int64_t &total_written, MIOBufferAccessor & buf, int &needs); + virtual int64_t load_buffer_and_write(int64_t towrite, int64_t &wattempted, int64_t &total_written, MIOBufferAccessor &buf, + int &needs); void readDisable(NetHandler *nh); void readSignalError(NetHandler *nh, int err); int readSignalDone(int event, NetHandler *nh); @@ -222,15 +242,13 @@ public: // amc - what is this for? Why not use remote_addr or con.addr? IpEndpoint server_addr; /// Server address and port. - union - { + union { unsigned int flags; -#define NET_VC_SHUTDOWN_READ 1 +#define NET_VC_SHUTDOWN_READ 1 #define NET_VC_SHUTDOWN_WRITE 2 - struct - { - unsigned int got_local_addr:1; - unsigned int shutdown:2; + struct { + unsigned int got_local_addr : 1; + unsigned int shutdown : 2; } f; }; @@ -254,12 +272,12 @@ public: virtual int set_tcp_init_cwnd(int init_cwnd); virtual void apply_options(); - friend void write_to_net_io(NetHandler*, UnixNetVConnection*, EThread*); + friend void write_to_net_io(NetHandler *, UnixNetVConnection *, EThread *); }; extern ClassAllocator<UnixNetVConnection> netVCAllocator; -typedef int (UnixNetVConnection::*NetVConnHandler) (int, void *); +typedef int (UnixNetVConnection::*NetVConnHandler)(int, void *); TS_INLINE void @@ -385,17 +403,20 @@ UnixNetVConnection::set_tcp_init_cwnd(int init_cwnd) #endif } -TS_INLINE UnixNetVConnection::~UnixNetVConnection() { } +TS_INLINE UnixNetVConnection::~UnixNetVConnection() +{ +} TS_INLINE SOCKET -UnixNetVConnection::get_socket() { +UnixNetVConnection::get_socket() +{ return con.fd; } // declarations for local use (within the net module) -void close_UnixNetVConnection(UnixNetVConnection * vc, EThread * t); -void write_to_net(NetHandler * nh, UnixNetVConnection * vc, EThread * thread); -void write_to_net_io(NetHandler * nh, UnixNetVConnection * vc, EThread * thread); +void close_UnixNetVConnection(UnixNetVConnection *vc, EThread *t); +void write_to_net(NetHandler *nh, UnixNetVConnection *vc, EThread *thread); +void write_to_net_io(NetHandler *nh, UnixNetVConnection *vc, EThread *thread); #endif http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/P_UnixPollDescriptor.h ---------------------------------------------------------------------- diff --git a/iocore/net/P_UnixPollDescriptor.h b/iocore/net/P_UnixPollDescriptor.h index af3d9e7..88b8f38 100644 --- a/iocore/net/P_UnixPollDescriptor.h +++ b/iocore/net/P_UnixPollDescriptor.h @@ -34,23 +34,22 @@ #if TS_USE_KQUEUE #include <sys/event.h> -#define INK_EVP_IN 0x001 -#define INK_EVP_PRI 0x002 -#define INK_EVP_OUT 0x004 -#define INK_EVP_ERR 0x010 -#define INK_EVP_HUP 0x020 +#define INK_EVP_IN 0x001 +#define INK_EVP_PRI 0x002 +#define INK_EVP_OUT 0x004 +#define INK_EVP_ERR 0x010 +#define INK_EVP_HUP 0x020 #endif #define POLL_DESCRIPTOR_SIZE 32768 typedef struct pollfd Pollfd; -struct PollDescriptor -{ - int result; // result of poll +struct PollDescriptor { + int result; // result of poll #if TS_USE_EPOLL int epoll_fd; - int nfds; // actual number + int nfds; // actual number Pollfd pfd[POLL_DESCRIPTOR_SIZE]; struct epoll_event ePoll_Triggered_Events[POLL_DESCRIPTOR_SIZE]; #endif @@ -63,26 +62,26 @@ struct PollDescriptor #if TS_USE_EPOLL #define get_ev_port(a) ((a)->epoll_fd) -#define get_ev_events(a,x) ((a)->ePoll_Triggered_Events[(x)].events) -#define get_ev_data(a,x) ((a)->ePoll_Triggered_Events[(x)].data.ptr) -#define ev_next_event(a,x) +#define get_ev_events(a, x) ((a)->ePoll_Triggered_Events[(x)].events) +#define get_ev_data(a, x) ((a)->ePoll_Triggered_Events[(x)].data.ptr) +#define ev_next_event(a, x) #endif #if TS_USE_KQUEUE struct kevent kq_Triggered_Events[POLL_DESCRIPTOR_SIZE]; - /* we define these here as numbers, because for kqueue mapping them to a combination of - * filters / flags is hard to do. */ +/* we define these here as numbers, because for kqueue mapping them to a combination of +*filters / flags is hard to do. */ #define get_ev_port(a) ((a)->kqueue_fd) -#define get_ev_events(a,x) ((a)->kq_event_convert((a)->kq_Triggered_Events[(x)].filter, (a)->kq_Triggered_Events[(x)].flags)) -#define get_ev_data(a,x) ((a)->kq_Triggered_Events[(x)].udata) - int kq_event_convert(int16_t event, uint16_t flags) +#define get_ev_events(a, x) ((a)->kq_event_convert((a)->kq_Triggered_Events[(x)].filter, (a)->kq_Triggered_Events[(x)].flags)) +#define get_ev_data(a, x) ((a)->kq_Triggered_Events[(x)].udata) + int + kq_event_convert(int16_t event, uint16_t flags) { int r = 0; if (event == EVFILT_READ) { r |= INK_EVP_IN; - } - else if (event == EVFILT_WRITE) { + } else if (event == EVFILT_WRITE) { r |= INK_EVP_OUT; } @@ -91,19 +90,20 @@ struct PollDescriptor } return r; } -#define ev_next_event(a,x) +#define ev_next_event(a, x) #endif #if TS_USE_PORT port_event_t Port_Triggered_Events[POLL_DESCRIPTOR_SIZE]; #define get_ev_port(a) ((a)->port_fd) -#define get_ev_events(a,x) ((a)->Port_Triggered_Events[(x)].portev_events) -#define get_ev_data(a,x) ((a)->Port_Triggered_Events[(x)].portev_user) -#define get_ev_odata(a,x) ((a)->Port_Triggered_Events[(x)].portev_object) -#define ev_next_event(a,x) +#define get_ev_events(a, x) ((a)->Port_Triggered_Events[(x)].portev_events) +#define get_ev_data(a, x) ((a)->Port_Triggered_Events[(x)].portev_user) +#define get_ev_odata(a, x) ((a)->Port_Triggered_Events[(x)].portev_object) +#define ev_next_event(a, x) #endif - Pollfd *alloc() + Pollfd * + alloc() { #if TS_USE_EPOLL // XXX : We need restrict max size based on definition. @@ -115,7 +115,8 @@ struct PollDescriptor return 0; #endif } - PollDescriptor *init() + PollDescriptor * + init() { result = 0; #if TS_USE_EPOLL @@ -134,9 +135,7 @@ struct PollDescriptor #endif return this; } - PollDescriptor() { - init(); - } + PollDescriptor() { init(); } }; #endif http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/P_UnixUDPConnection.h ---------------------------------------------------------------------- diff --git a/iocore/net/P_UnixUDPConnection.h b/iocore/net/P_UnixUDPConnection.h index 1ea5598..9f6a079 100644 --- a/iocore/net/P_UnixUDPConnection.h +++ b/iocore/net/P_UnixUDPConnection.h @@ -34,11 +34,11 @@ #include "P_UDPConnection.h" #include "P_UDPPacket.h" -class UnixUDPConnection:public UDPConnectionInternal +class UnixUDPConnection : public UDPConnectionInternal { public: void init(int the_fd); - void setEthread(EThread * e); + void setEthread(EThread *e); void errorAndDie(int e); int callbackHandler(int event, void *data); @@ -53,22 +53,19 @@ public: EventIO ep; UnixUDPConnection(int the_fd); - virtual ~ UnixUDPConnection(); + virtual ~UnixUDPConnection(); + private: int m_errno; - virtual void UDPConnection_is_abstract() {}; + virtual void UDPConnection_is_abstract(){}; }; TS_INLINE -UnixUDPConnection::UnixUDPConnection(int the_fd) - : onCallbackQueue(0) - , callbackAction(NULL) - , ethread(NULL) - , m_errno(0) +UnixUDPConnection::UnixUDPConnection(int the_fd) : onCallbackQueue(0), callbackAction(NULL), ethread(NULL), m_errno(0) { fd = the_fd; UDPPacketInternal p; - ink_atomiclist_init(&inQueue, "Incoming UDP Packet queue", (char *) &p.alink.next - (char *) &p); + ink_atomiclist_init(&inQueue, "Incoming UDP Packet queue", (char *)&p.alink.next - (char *)&p); SET_HANDLER(&UnixUDPConnection::callbackHandler); } @@ -82,12 +79,12 @@ UnixUDPConnection::init(int the_fd) m_errno = 0; UDPPacketInternal p; - ink_atomiclist_init(&inQueue, "Incoming UDP Packet queue", (char *) &p.alink.next - (char *) &p); + ink_atomiclist_init(&inQueue, "Incoming UDP Packet queue", (char *)&p.alink.next - (char *)&p); SET_HANDLER(&UnixUDPConnection::callbackHandler); } TS_INLINE void -UnixUDPConnection::setEthread(EThread * e) +UnixUDPConnection::setEthread(EThread *e) { ethread = e; } @@ -99,9 +96,9 @@ UnixUDPConnection::errorAndDie(int e) } TS_INLINE Action * -UDPConnection::recv(Continuation * c) +UDPConnection::recv(Continuation *c) { - UnixUDPConnection *p = (UnixUDPConnection *) this; + UnixUDPConnection *p = (UnixUDPConnection *)this; // register callback interest. p->continuation = c; ink_assert(c != NULL);
