@@ -19,6 +19,8 @@ quic_quicly_main_t quic_quicly_main;
1919 * size of the pacer (10 packets) */
2020#define QUIC_QUICLY_SEND_PACKET_VEC_SIZE 10
2121
22+ #define QUIC_QUICLY_RCV_MAX_PACKETS 16
23+
2224VLIB_PLUGIN_REGISTER () = {
2325 .version = VPP_BUILD_VER ,
2426 .description = "Quicly QUIC Engine" ,
@@ -313,17 +315,18 @@ quic_quicly_addr_to_ip46_addr (quicly_address_t *quicly_addr,
313315static int
314316quic_quicly_send_packets (quic_ctx_t * ctx )
315317{
316- /* TODO: GET packetsp[], buf[], next_timeout OFF OF THE STACK!!! */
317- struct iovec packets [QUIC_QUICLY_SEND_PACKET_VEC_SIZE ];
318- uint64_t max_udp_payload_size = quic_quicly_get_quicly_ctx_from_ctx (ctx )
319- -> transport_params .max_udp_payload_size ;
320- uint8_t buf [QUIC_QUICLY_SEND_PACKET_VEC_SIZE * max_udp_payload_size ];
318+ quic_quicly_main_t * qqm = & quic_quicly_main ;
319+ struct iovec * packets = qqm -> tx_packets [ctx -> c_thread_index ];
321320 session_t * udp_session ;
322321 quicly_conn_t * conn ;
323322 size_t num_packets , i , max_packets ;
324323 u32 n_sent = 0 , buf_size ;
325324 int err = 0 ;
326325 quicly_address_t quicly_rmt_ip , quicly_lcl_ip ;
326+ u8 * buf = qqm -> tx_bufs [ctx -> c_thread_index ];
327+
328+ ASSERT (vec_len (buf ) >= (QUIC_QUICLY_SEND_PACKET_VEC_SIZE * QUIC_MAX_PACKET_SIZE ));
329+ ASSERT (vec_len (packets ) >= QUIC_QUICLY_SEND_PACKET_VEC_SIZE );
327330
328331 /* We have sctx, get qctx */
329332 if (quic_ctx_is_stream (ctx ))
@@ -354,7 +357,7 @@ quic_quicly_send_packets (quic_ctx_t *ctx)
354357 }
355358
356359 /* Shrink buf_size if we have less dgrams than QUIC_QUICLY_SEND_PACKET_VEC_SIZE */
357- buf_size = clib_min (sizeof (buf ), max_packets * max_udp_payload_size );
360+ buf_size = clib_min (vec_len (buf ), max_packets * QUIC_MAX_PACKET_SIZE );
358361
359362 /* If under memory pressure and chunks cannot be allocated try reschedule */
360363 if (svm_fifo_provision_chunks (udp_session -> tx_fifo , 0 , 0 , buf_size ))
@@ -1802,7 +1805,10 @@ quic_quicly_engine_init (quic_main_t *qm)
18021805 qqm -> session_cache .super .cb = quic_quicly_encrypt_ticket_cb ;
18031806 qqm -> qm = qm ;
18041807
1805- vec_validate (quic_quicly_main .next_cid , qm -> num_threads - 1 );
1808+ vec_validate (qqm -> next_cid , qm -> num_threads - 1 );
1809+ vec_validate (qqm -> rx_packets , qm -> num_threads - 1 );
1810+ vec_validate (qqm -> tx_packets , qm -> num_threads - 1 );
1811+ vec_validate (qqm -> tx_bufs , qm -> num_threads - 1 );
18061812 next_cid = qqm -> next_cid ;
18071813 clib_bihash_init_16_8 (& qqm -> connection_hash ,
18081814 "quic (quicly engine) connections" , 1024 , 4 << 20 );
@@ -1823,6 +1829,9 @@ quic_quicly_engine_init (quic_main_t *qm)
18231829 1e-3 /* timer period 1ms */ , ~0 );
18241830 tw -> last_run_time = vlib_time_now (vlib_get_main ());
18251831 next_cid [i ].thread_id = i ;
1832+ vec_validate (qqm -> rx_packets [i ], QUIC_QUICLY_RCV_MAX_PACKETS );
1833+ vec_validate (qqm -> tx_packets [i ], QUIC_QUICLY_SEND_PACKET_VEC_SIZE );
1834+ vec_validate (qqm -> tx_bufs [i ], QUIC_QUICLY_SEND_PACKET_VEC_SIZE * QUIC_MAX_PACKET_SIZE );
18261835 }
18271836}
18281837
@@ -1856,17 +1865,17 @@ static int
18561865quic_quicly_udp_session_rx_packets (session_t * udp_session )
18571866{
18581867 /* Read data from UDP rx_fifo and pass it to the quic_eng conn. */
1868+ quic_quicly_main_t * qqm = & quic_quicly_main ;
18591869 quic_ctx_t * ctx = NULL , * prev_ctx = NULL ;
18601870 svm_fifo_t * f = udp_session -> rx_fifo ;
18611871 u32 max_deq ;
18621872 u64 udp_session_handle = session_handle (udp_session );
18631873 int rv = 0 ;
18641874 clib_thread_index_t thread_index = vlib_get_thread_index ();
18651875 u32 cur_deq , fifo_offset , max_packets , i ;
1866- /* TODO: move packet buffer off of the stack and
1867- * allocate a vector of packet_ct_t.
1868- */
1869- quic_quicly_rx_packet_ctx_t packets_ctx [QUIC_RCV_MAX_PACKETS ];
1876+ quic_quicly_rx_packet_ctx_t * packet_ctx ;
1877+
1878+ ASSERT (vec_len (qqm -> rx_packets [udp_session -> thread_index ]) >= QUIC_QUICLY_RCV_MAX_PACKETS );
18701879
18711880 if (udp_session -> flags & SESSION_F_IS_MIGRATING )
18721881 {
@@ -1882,17 +1891,14 @@ quic_quicly_udp_session_rx_packets (session_t *udp_session)
18821891 }
18831892
18841893 fifo_offset = 0 ;
1885- max_packets = QUIC_RCV_MAX_PACKETS ;
1894+ max_packets = QUIC_QUICLY_RCV_MAX_PACKETS ;
18861895
1887- #if CLIB_DEBUG > 0
1888- clib_memset (packets_ctx , 0xfa ,
1889- QUIC_RCV_MAX_PACKETS * sizeof (quic_quicly_rx_packet_ctx_t ));
1890- #endif
18911896 for (i = 0 ; i < max_packets ; i ++ )
18921897 {
1893- packets_ctx [i ].thread_index = UINT32_MAX ;
1894- packets_ctx [i ].ctx_index = UINT32_MAX ;
1895- packets_ctx [i ].ptype = QUIC_PACKET_TYPE_DROP ;
1898+ packet_ctx = vec_elt_at_index (qqm -> rx_packets [udp_session -> thread_index ], i );
1899+ packet_ctx -> thread_index = UINT32_MAX ;
1900+ packet_ctx -> ctx_index = UINT32_MAX ;
1901+ packet_ctx -> ptype = QUIC_PACKET_TYPE_DROP ;
18961902
18971903 cur_deq = max_deq - fifo_offset ;
18981904
@@ -1908,11 +1914,10 @@ quic_quicly_udp_session_rx_packets (session_t *udp_session)
19081914 QUIC_ERR ("Fifo %d < header size in RX" , cur_deq );
19091915 break ;
19101916 }
1911- rv = quic_quicly_process_one_rx_packet (udp_session_handle , f ,
1912- fifo_offset , & packets_ctx [i ]);
1913- if (packets_ctx [i ].ptype != QUIC_PACKET_TYPE_MIGRATE )
1917+ rv = quic_quicly_process_one_rx_packet (udp_session_handle , f , fifo_offset , packet_ctx );
1918+ if (packet_ctx -> ptype != QUIC_PACKET_TYPE_MIGRATE )
19141919 {
1915- fifo_offset += SESSION_CONN_HDR_LEN + packets_ctx [ i ]. ph .data_length ;
1920+ fifo_offset += SESSION_CONN_HDR_LEN + packet_ctx -> ph .data_length ;
19161921 }
19171922 if (rv )
19181923 {
@@ -1923,43 +1928,41 @@ quic_quicly_udp_session_rx_packets (session_t *udp_session)
19231928
19241929 for (i = 0 ; i < max_packets ; i ++ )
19251930 {
1926- switch (packets_ctx [i ].ptype )
1931+ packet_ctx = vec_elt_at_index (qqm -> rx_packets [udp_session -> thread_index ], i );
1932+ switch (packet_ctx -> ptype )
19271933 {
19281934 case QUIC_PACKET_TYPE_RECEIVE :
1929- ctx =
1930- quic_quicly_get_quic_ctx (packets_ctx [i ].ctx_index , thread_index );
1935+ ctx = quic_quicly_get_quic_ctx (packet_ctx -> ctx_index , thread_index );
19311936 /* FIXME: Process return value and handle errors. */
1932- quic_quicly_receive_a_packet (ctx , & packets_ctx [ i ] );
1937+ quic_quicly_receive_a_packet (ctx , packet_ctx );
19331938 break ;
19341939 case QUIC_PACKET_TYPE_ACCEPT :
19351940 /* FIXME: Process return value and handle errors. */
1936- quic_quicly_accept_connection (& packets_ctx [ i ] );
1941+ quic_quicly_accept_connection (packet_ctx );
19371942 break ;
19381943 case QUIC_PACKET_TYPE_RESET :
19391944 /* FIXME: Process return value and handle errors. */
1940- quic_quicly_reset_connection (udp_session_handle , & packets_ctx [ i ] );
1945+ quic_quicly_reset_connection (udp_session_handle , packet_ctx );
19411946 break ;
19421947 }
19431948 }
19441949 ctx = prev_ctx = NULL ;
19451950 for (i = 0 ; i < max_packets ; i ++ )
19461951 {
1952+ packet_ctx = vec_elt_at_index (qqm -> rx_packets [udp_session -> thread_index ], i );
19471953 prev_ctx = ctx ;
1948- switch (packets_ctx [ i ]. ptype )
1954+ switch (packet_ctx -> ptype )
19491955 {
19501956 case QUIC_PACKET_TYPE_RECEIVE :
1951- ctx = quic_quicly_get_quic_ctx (packets_ctx [i ].ctx_index ,
1952- packets_ctx [i ].thread_index );
1957+ ctx = quic_quicly_get_quic_ctx (packet_ctx -> ctx_index , packet_ctx -> thread_index );
19531958 if (ctx -> conn_state <= QUIC_CONN_STATE_HANDSHAKE )
19541959 {
19551960 quic_quicly_check_quic_session_connected (ctx );
1956- ctx = quic_quicly_get_quic_ctx (packets_ctx [i ].ctx_index ,
1957- packets_ctx [i ].thread_index );
1961+ ctx = quic_quicly_get_quic_ctx (packet_ctx -> ctx_index , packet_ctx -> thread_index );
19581962 }
19591963 break ;
19601964 case QUIC_PACKET_TYPE_ACCEPT :
1961- ctx = quic_quicly_get_quic_ctx (packets_ctx [i ].ctx_index ,
1962- packets_ctx [i ].thread_index );
1965+ ctx = quic_quicly_get_quic_ctx (packet_ctx -> ctx_index , packet_ctx -> thread_index );
19631966 break ;
19641967 default :
19651968 continue ; /* this exits the for loop since other packet types are
0 commit comments