@@ -1405,21 +1405,39 @@ uint64_t ptls_decode_quicint(const uint8_t **src, const uint8_t *end);
14051405 ptls_decode_assert_block_close((src), end); \
14061406 } while (0)
14071407
1408+ typedef struct st_ptls_log_getsni_t {
1409+ const char * (* cb )(void * arg );
1410+ void * arg ;
1411+ } ptls_log_getsni_t ;
1412+
1413+ /**
1414+ * Creates a lazy callback object for obtaining SNI. The object is used to delay materialization of SNI to only when it is needed.
1415+ */
1416+ #define PTLS_LOG_DEFINE_GETSNI (suffix , type , body ) \
1417+ static inline const char *ptls_log_getsni_cb_##suffix(void *_arg) \
1418+ { \
1419+ type arg = (type)_arg; \
1420+ body \
1421+ } \
1422+ static inline ptls_log_getsni_t ptls_log_getsni_##suffix(type arg) \
1423+ { \
1424+ return (ptls_log_getsni_t){ptls_log_getsni_cb_##suffix, arg}; \
1425+ }
1426+
14081427#if PTLS_HAVE_LOG
1409- #define PTLS_LOG__DO_LOG (module , name , conn_state , get_sni , get_sni_arg , add_time , block ) \
1428+ #define PTLS_LOG__DO_LOG (module , name , conn_state , get_sni , add_time , block ) \
14101429 do { \
14111430 int ptlslog_include_appdata = 0; \
14121431 do { \
14131432 ptls_log__do_write_start(&logpoint, (add_time)); \
14141433 do { \
14151434 block \
14161435 } while (0); \
1417- ptlslog_include_appdata = \
1418- ptls_log__do_write_end(&logpoint, (conn_state), (get_sni), (get_sni_arg), ptlslog_include_appdata); \
1436+ ptlslog_include_appdata = ptls_log__do_write_end(&logpoint, (conn_state), (get_sni), ptlslog_include_appdata); \
14191437 } while (PTLS_UNLIKELY(ptlslog_include_appdata)); \
14201438 } while (0)
14211439#else
1422- #define PTLS_LOG__DO_LOG (module , name , conn_state , get_sni , get_sni_arg , add_time , block ) /* don't generate code */
1440+ #define PTLS_LOG__DO_LOG (module , name , conn_state , get_sni , add_time , block ) /* don't generate code */
14231441#endif
14241442
14251443#define PTLS_LOG_DEFINE_POINT (_module , _name , _var ) \
@@ -1430,7 +1448,7 @@ uint64_t ptls_decode_quicint(const uint8_t **src, const uint8_t *end);
14301448 PTLS_LOG_DEFINE_POINT(module, name, logpoint); \
14311449 if (PTLS_LIKELY(ptls_log_point_maybe_active(&logpoint) == 0)) \
14321450 break; \
1433- PTLS_LOG__DO_LOG(module, name, NULL, NULL, NULL, 1, {block}); \
1451+ PTLS_LOG__DO_LOG(module, name, NULL, (ptls_log_getsni_t){ NULL}, 1, {block}); \
14341452 } while (0)
14351453
14361454#define PTLS_LOG_CONN (name , tls , block ) \
@@ -1441,10 +1459,10 @@ uint64_t ptls_decode_quicint(const uint8_t **src, const uint8_t *end);
14411459 break; \
14421460 ptls_t *_tls = (tls); \
14431461 ptls_log_conn_state_t *conn_state = ptls_get_log_state(_tls); \
1444- active &= ptls_log_conn_maybe_active(conn_state, (const char *(*)(void *))ptls_get_server_name, _tls); \
1462+ active &= ptls_log_conn_maybe_active(conn_state, ptls_log_getsni_ptls(_tls)); \
14451463 if (PTLS_LIKELY(active == 0)) \
14461464 break; \
1447- PTLS_LOG__DO_LOG(picotls, name, conn_state, (const char *(*)(void *))ptls_get_server_name, _tls, 1, { \
1465+ PTLS_LOG__DO_LOG(picotls, name, conn_state, ptls_log_getsni_ptls(_tls), 1, { \
14481466 PTLS_LOG_ELEMENT_PTR(tls, _tls); \
14491467 do { \
14501468 block \
@@ -1571,7 +1589,7 @@ static uint32_t ptls_log_point_maybe_active(struct st_ptls_log_point_t *point);
15711589/**
15721590 * returns a bitmap indicating the loggers active for given connection
15731591 */
1574- static uint32_t ptls_log_conn_maybe_active (ptls_log_conn_state_t * conn , const char * ( * get_sni )( void * ), void * get_sni_arg );
1592+ static uint32_t ptls_log_conn_maybe_active (ptls_log_conn_state_t * conn , ptls_log_getsni_t getsni );
15751593
15761594/**
15771595 * Returns the number of log events that were unable to be emitted.
@@ -1588,8 +1606,7 @@ size_t ptls_log_num_lost(void);
15881606int ptls_log_add_fd (int fd , float sample_ratio , const char * points , const char * snis , const char * addresses , int appdata );
15891607
15901608void ptls_log__recalc_point (int caller_locked , struct st_ptls_log_point_t * point );
1591- void ptls_log__recalc_conn (int caller_locked , struct st_ptls_log_conn_state_t * conn , const char * (* get_sni )(void * ),
1592- void * get_sni_arg );
1609+ void ptls_log__recalc_conn (int caller_locked , struct st_ptls_log_conn_state_t * conn , ptls_log_getsni_t getsni );
15931610void ptls_log__do_push_element_safestr (const char * prefix , size_t prefix_len , const char * s , size_t l );
15941611void ptls_log__do_push_element_unsafestr (const char * prefix , size_t prefix_len , const char * s , size_t l );
15951612void ptls_log__do_push_element_hexdump (const char * prefix , size_t prefix_len , const void * s , size_t l );
@@ -1603,8 +1620,8 @@ void ptls_log__do_push_appdata_element_unsafestr(int includes_appdata, const cha
16031620void ptls_log__do_push_appdata_element_hexdump (int includes_appdata , const char * prefix , size_t prefix_len , const void * s ,
16041621 size_t l );
16051622void ptls_log__do_write_start (struct st_ptls_log_point_t * point , int add_time );
1606- int ptls_log__do_write_end (struct st_ptls_log_point_t * point , struct st_ptls_log_conn_state_t * conn , const char * ( * get_sni )( void * ) ,
1607- void * get_sni_arg , int includes_appdata );
1623+ int ptls_log__do_write_end (struct st_ptls_log_point_t * point , struct st_ptls_log_conn_state_t * conn , ptls_log_getsni_t getsni ,
1624+ int includes_appdata );
16081625
16091626/**
16101627 * create a client object to handle new TLS connection
@@ -1963,6 +1980,8 @@ extern ptls_get_time_t ptls_get_time;
19631980 */
19641981static void ptls_hash_clone_memcpy (void * dst , const void * src , size_t size );
19651982
1983+ PTLS_LOG_DEFINE_GETSNI (ptls , ptls_t * , { return ptls_get_server_name (arg ); })
1984+
19661985/* inline functions */
19671986
19681987inline uint32_t ptls_log_point_maybe_active (struct st_ptls_log_point_t * point )
@@ -1981,11 +2000,11 @@ inline void ptls_log_recalc_conn_state(ptls_log_conn_state_t *state)
19812000 state -> state .generation = 0 ;
19822001}
19832002
1984- inline uint32_t ptls_log_conn_maybe_active (ptls_log_conn_state_t * conn , const char * ( * get_sni )( void * ), void * get_sni_arg )
2003+ inline uint32_t ptls_log_conn_maybe_active (ptls_log_conn_state_t * conn , ptls_log_getsni_t getsni )
19852004{
19862005#if PTLS_HAVE_LOG
19872006 if (PTLS_UNLIKELY (conn -> state .generation != ptls_log ._generation ))
1988- ptls_log__recalc_conn (0 , conn , get_sni , get_sni_arg );
2007+ ptls_log__recalc_conn (0 , conn , getsni );
19892008 return conn -> state .active_conns ;
19902009#else
19912010 return 0 ;
0 commit comments