Add get_endpoint in transport vft
[vpp.git] / src / vnet / session / transport.c
1 /*
2  * Copyright (c) 2017-2019 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #include <vnet/session/transport.h>
17 #include <vnet/session/session.h>
18 #include <vnet/fib/fib.h>
19
20 /**
21  * Per-type vector of transport protocol virtual function tables
22  */
23 transport_proto_vft_t *tp_vfts;
24
25 /*
26  * Port allocator seed
27  */
28 static u32 port_allocator_seed;
29
30 /*
31  * Local endpoints table
32  */
33 static transport_endpoint_table_t local_endpoints_table;
34
35 /*
36  * Pool of local endpoints
37  */
38 static transport_endpoint_t *local_endpoints;
39
40 /*
41  * Local endpoints pool lock
42  */
43 static clib_spinlock_t local_endpoints_lock;
44
45 /*
46  * Period used by transport pacers. Initialized by session layer
47  */
48 static double transport_pacer_period;
49
50 #define TRANSPORT_PACER_MIN_MSS         1460
51 #define TRANSPORT_PACER_MIN_BURST       TRANSPORT_PACER_MIN_MSS
52 #define TRANSPORT_PACER_MAX_BURST       (32 * TRANSPORT_PACER_MIN_MSS)
53
54 u8 *
55 format_transport_proto (u8 * s, va_list * args)
56 {
57   u32 transport_proto = va_arg (*args, u32);
58   switch (transport_proto)
59     {
60     case TRANSPORT_PROTO_TCP:
61       s = format (s, "TCP");
62       break;
63     case TRANSPORT_PROTO_UDP:
64       s = format (s, "UDP");
65       break;
66     case TRANSPORT_PROTO_SCTP:
67       s = format (s, "SCTP");
68       break;
69     case TRANSPORT_PROTO_UDPC:
70       s = format (s, "UDPC");
71       break;
72     case TRANSPORT_PROTO_QUIC:
73       s = format (s, "QUIC");
74       break;
75     }
76   return s;
77 }
78
79 u8 *
80 format_transport_proto_short (u8 * s, va_list * args)
81 {
82   u32 transport_proto = va_arg (*args, u32);
83   switch (transport_proto)
84     {
85     case TRANSPORT_PROTO_TCP:
86       s = format (s, "T");
87       break;
88     case TRANSPORT_PROTO_UDP:
89       s = format (s, "U");
90       break;
91     case TRANSPORT_PROTO_SCTP:
92       s = format (s, "S");
93       break;
94     case TRANSPORT_PROTO_UDPC:
95       s = format (s, "U");
96       break;
97     case TRANSPORT_PROTO_QUIC:
98       s = format (s, "Q");
99       break;
100     }
101   return s;
102 }
103
104 u8 *
105 format_transport_connection (u8 * s, va_list * args)
106 {
107   u32 transport_proto = va_arg (*args, u32);
108   u32 conn_index = va_arg (*args, u32);
109   u32 thread_index = va_arg (*args, u32);
110   u32 verbose = va_arg (*args, u32);
111   transport_proto_vft_t *tp_vft;
112   transport_connection_t *tc;
113   u32 indent;
114
115   tp_vft = transport_protocol_get_vft (transport_proto);
116   if (!tp_vft)
117     return s;
118
119   s = format (s, "%U", tp_vft->format_connection, conn_index, thread_index,
120               verbose);
121   tc = tp_vft->get_connection (conn_index, thread_index);
122   if (tc && transport_connection_is_tx_paced (tc) && verbose > 1)
123     {
124       indent = format_get_indent (s) + 1;
125       s = format (s, "%Upacer: %U\n", format_white_space, indent,
126                   format_transport_pacer, &tc->pacer);
127     }
128   return s;
129 }
130
131 u8 *
132 format_transport_listen_connection (u8 * s, va_list * args)
133 {
134   u32 transport_proto = va_arg (*args, u32);
135   transport_proto_vft_t *tp_vft;
136
137   tp_vft = transport_protocol_get_vft (transport_proto);
138   if (!tp_vft)
139     return s;
140
141   s = (tp_vft->format_listener) (s, args);
142   return s;
143 }
144
145 u8 *
146 format_transport_half_open_connection (u8 * s, va_list * args)
147 {
148   u32 transport_proto = va_arg (*args, u32);
149   u32 listen_index = va_arg (*args, u32);
150   transport_proto_vft_t *tp_vft;
151
152   tp_vft = transport_protocol_get_vft (transport_proto);
153   if (!tp_vft)
154     return s;
155
156   s = format (s, "%U", tp_vft->format_half_open, listen_index);
157   return s;
158 }
159
160 uword
161 unformat_transport_proto (unformat_input_t * input, va_list * args)
162 {
163   u32 *proto = va_arg (*args, u32 *);
164   if (unformat (input, "tcp"))
165     *proto = TRANSPORT_PROTO_TCP;
166   else if (unformat (input, "TCP"))
167     *proto = TRANSPORT_PROTO_TCP;
168   else if (unformat (input, "udpc"))
169     *proto = TRANSPORT_PROTO_UDPC;
170   else if (unformat (input, "UDPC"))
171     *proto = TRANSPORT_PROTO_UDPC;
172   else if (unformat (input, "udp"))
173     *proto = TRANSPORT_PROTO_UDP;
174   else if (unformat (input, "UDP"))
175     *proto = TRANSPORT_PROTO_UDP;
176   else if (unformat (input, "sctp"))
177     *proto = TRANSPORT_PROTO_SCTP;
178   else if (unformat (input, "SCTP"))
179     *proto = TRANSPORT_PROTO_SCTP;
180   else if (unformat (input, "tls"))
181     *proto = TRANSPORT_PROTO_TLS;
182   else if (unformat (input, "TLS"))
183     *proto = TRANSPORT_PROTO_TLS;
184   else if (unformat (input, "quic"))
185     *proto = TRANSPORT_PROTO_QUIC;
186   else if (unformat (input, "QUIC"))
187     *proto = TRANSPORT_PROTO_QUIC;
188   else
189     return 0;
190   return 1;
191 }
192
193 u32
194 transport_endpoint_lookup (transport_endpoint_table_t * ht, u8 proto,
195                            ip46_address_t * ip, u16 port)
196 {
197   clib_bihash_kv_24_8_t kv;
198   int rv;
199
200   kv.key[0] = ip->as_u64[0];
201   kv.key[1] = ip->as_u64[1];
202   kv.key[2] = (u64) port << 8 | (u64) proto;
203
204   rv = clib_bihash_search_inline_24_8 (ht, &kv);
205   if (rv == 0)
206     return kv.value;
207
208   return ENDPOINT_INVALID_INDEX;
209 }
210
211 void
212 transport_endpoint_table_add (transport_endpoint_table_t * ht, u8 proto,
213                               transport_endpoint_t * te, u32 value)
214 {
215   clib_bihash_kv_24_8_t kv;
216
217   kv.key[0] = te->ip.as_u64[0];
218   kv.key[1] = te->ip.as_u64[1];
219   kv.key[2] = (u64) te->port << 8 | (u64) proto;
220   kv.value = value;
221
222   clib_bihash_add_del_24_8 (ht, &kv, 1);
223 }
224
225 void
226 transport_endpoint_table_del (transport_endpoint_table_t * ht, u8 proto,
227                               transport_endpoint_t * te)
228 {
229   clib_bihash_kv_24_8_t kv;
230
231   kv.key[0] = te->ip.as_u64[0];
232   kv.key[1] = te->ip.as_u64[1];
233   kv.key[2] = (u64) te->port << 8 | (u64) proto;
234
235   clib_bihash_add_del_24_8 (ht, &kv, 0);
236 }
237
238 /**
239  * Register transport virtual function table.
240  *
241  * @param transport_proto - transport protocol type (i.e., TCP, UDP ..)
242  * @param vft - virtual function table for transport proto
243  * @param fib_proto - network layer protocol
244  * @param output_node - output node index that session layer will hand off
245  *                      buffers to, for requested fib proto
246  */
247 void
248 transport_register_protocol (transport_proto_t transport_proto,
249                              const transport_proto_vft_t * vft,
250                              fib_protocol_t fib_proto, u32 output_node)
251 {
252   u8 is_ip4 = fib_proto == FIB_PROTOCOL_IP4;
253
254   vec_validate (tp_vfts, transport_proto);
255   tp_vfts[transport_proto] = *vft;
256
257   session_register_transport (transport_proto, vft, is_ip4, output_node);
258 }
259
260 /**
261  * Get transport virtual function table
262  *
263  * @param type - session type (not protocol type)
264  */
265 transport_proto_vft_t *
266 transport_protocol_get_vft (transport_proto_t transport_proto)
267 {
268   if (transport_proto >= vec_len (tp_vfts))
269     return 0;
270   return &tp_vfts[transport_proto];
271 }
272
273 transport_service_type_t
274 transport_protocol_service_type (transport_proto_t tp)
275 {
276   return tp_vfts[tp].service_type;
277 }
278
279 transport_tx_fn_type_t
280 transport_protocol_tx_fn_type (transport_proto_t tp)
281 {
282   return tp_vfts[tp].tx_type;
283 }
284
285 void
286 transport_cleanup (transport_proto_t tp, u32 conn_index, u8 thread_index)
287 {
288   tp_vfts[tp].cleanup (conn_index, thread_index);
289 }
290
291 int
292 transport_connect (transport_proto_t tp, transport_endpoint_cfg_t * tep)
293 {
294   return tp_vfts[tp].connect (tep);
295 }
296
297 void
298 transport_close (transport_proto_t tp, u32 conn_index, u8 thread_index)
299 {
300   tp_vfts[tp].close (conn_index, thread_index);
301 }
302
303 u32
304 transport_start_listen (transport_proto_t tp, u32 session_index,
305                         transport_endpoint_t * tep)
306 {
307   return tp_vfts[tp].start_listen (session_index, tep);
308 }
309
310 u32
311 transport_stop_listen (transport_proto_t tp, u32 conn_index)
312 {
313   return tp_vfts[tp].stop_listen (conn_index);
314 }
315
316 u8
317 transport_protocol_is_cl (transport_proto_t tp)
318 {
319   return (tp_vfts[tp].service_type == TRANSPORT_SERVICE_CL);
320 }
321
322 always_inline void
323 default_get_transport_endpoint (transport_connection_t * tc,
324                                 ip46_address_t * ip, u16 * port, u8 * is_ip4,
325                                 u8 is_lcl)
326 {
327   if (is_lcl)
328     {
329       *port = tc->lcl_port;
330       *is_ip4 = tc->is_ip4;
331       clib_memcpy_fast (ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
332     }
333   else
334     {
335       *port = tc->rmt_port;
336       *is_ip4 = tc->is_ip4;
337       clib_memcpy_fast (ip, &tc->rmt_ip, sizeof (tc->rmt_ip));
338     }
339 }
340
341 void
342 transport_get_endpoint (transport_proto_t tp, u32 conn_index,
343                         u32 thread_index, ip46_address_t * ip, u16 * port,
344                         u8 * is_ip4, u8 is_lcl)
345 {
346   if (tp_vfts[tp].get_transport_endpoint)
347     tp_vfts[tp].get_transport_endpoint (conn_index, thread_index, ip, port,
348                                         is_ip4, is_lcl);
349   else
350     {
351       transport_connection_t *tc;
352       tc = transport_get_connection (tp, conn_index, thread_index);
353       default_get_transport_endpoint (tc, ip, port, is_ip4, is_lcl);
354     }
355 }
356
357 void
358 transport_get_listener_endpoint (transport_proto_t tp, u32 conn_index,
359                                  ip46_address_t * ip, u16 * port, u8 * is_ip4,
360                                  u8 is_lcl)
361 {
362   if (tp_vfts[tp].get_transport_listener_endpoint)
363     tp_vfts[tp].get_transport_listener_endpoint (conn_index, ip, port, is_ip4,
364                                                  is_lcl);
365   else
366     {
367       transport_connection_t *tc;
368       tc = transport_get_listener (tp, conn_index);
369       default_get_transport_endpoint (tc, ip, port, is_ip4, is_lcl);
370     }
371 }
372
373 #define PORT_MASK ((1 << 16)- 1)
374
375 void
376 transport_endpoint_del (u32 tepi)
377 {
378   clib_spinlock_lock_if_init (&local_endpoints_lock);
379   pool_put_index (local_endpoints, tepi);
380   clib_spinlock_unlock_if_init (&local_endpoints_lock);
381 }
382
383 always_inline transport_endpoint_t *
384 transport_endpoint_new (void)
385 {
386   transport_endpoint_t *tep;
387   pool_get_zero (local_endpoints, tep);
388   return tep;
389 }
390
391 void
392 transport_endpoint_cleanup (u8 proto, ip46_address_t * lcl_ip, u16 port)
393 {
394   u32 tepi;
395   transport_endpoint_t *tep;
396
397   /* Cleanup local endpoint if this was an active connect */
398   tepi = transport_endpoint_lookup (&local_endpoints_table, proto, lcl_ip,
399                                     clib_net_to_host_u16 (port));
400   if (tepi != ENDPOINT_INVALID_INDEX)
401     {
402       tep = pool_elt_at_index (local_endpoints, tepi);
403       transport_endpoint_table_del (&local_endpoints_table, proto, tep);
404       transport_endpoint_del (tepi);
405     }
406 }
407
408 static void
409 transport_endpoint_mark_used (u8 proto, ip46_address_t * ip, u16 port)
410 {
411   transport_endpoint_t *tep;
412   clib_spinlock_lock_if_init (&local_endpoints_lock);
413   tep = transport_endpoint_new ();
414   clib_memcpy_fast (&tep->ip, ip, sizeof (*ip));
415   tep->port = port;
416   transport_endpoint_table_add (&local_endpoints_table, proto, tep,
417                                 tep - local_endpoints);
418   clib_spinlock_unlock_if_init (&local_endpoints_lock);
419 }
420
421 /**
422  * Allocate local port and add if successful add entry to local endpoint
423  * table to mark the pair as used.
424  */
425 int
426 transport_alloc_local_port (u8 proto, ip46_address_t * ip)
427 {
428   u16 min = 1024, max = 65535;  /* XXX configurable ? */
429   int tries, limit;
430   u32 tei;
431
432   limit = max - min;
433
434   /* Only support active opens from thread 0 */
435   ASSERT (vlib_get_thread_index () == 0);
436
437   /* Search for first free slot */
438   for (tries = 0; tries < limit; tries++)
439     {
440       u16 port = 0;
441
442       /* Find a port in the specified range */
443       while (1)
444         {
445           port = random_u32 (&port_allocator_seed) & PORT_MASK;
446           if (PREDICT_TRUE (port >= min && port < max))
447             break;
448         }
449
450       /* Look it up. If not found, we're done */
451       tei = transport_endpoint_lookup (&local_endpoints_table, proto, ip,
452                                        port);
453       if (tei == ENDPOINT_INVALID_INDEX)
454         {
455           transport_endpoint_mark_used (proto, ip, port);
456           return port;
457         }
458     }
459   return -1;
460 }
461
462 static clib_error_t *
463 transport_get_interface_ip (u32 sw_if_index, u8 is_ip4, ip46_address_t * addr)
464 {
465   if (is_ip4)
466     {
467       ip4_address_t *ip4;
468       ip4 = ip_interface_get_first_ip (sw_if_index, 1);
469       if (!ip4)
470         return clib_error_return (0, "no routable ip4 address on %U",
471                                   format_vnet_sw_if_index_name,
472                                   vnet_get_main (), sw_if_index);
473       addr->ip4.as_u32 = ip4->as_u32;
474     }
475   else
476     {
477       ip6_address_t *ip6;
478       ip6 = ip_interface_get_first_ip (sw_if_index, 0);
479       if (ip6 == 0)
480         return clib_error_return (0, "no routable ip6 addresses on %U",
481                                   format_vnet_sw_if_index_name,
482                                   vnet_get_main (), sw_if_index);
483       clib_memcpy_fast (&addr->ip6, ip6, sizeof (*ip6));
484     }
485   return 0;
486 }
487
488 static clib_error_t *
489 transport_find_local_ip_for_remote (u32 sw_if_index,
490                                     transport_endpoint_t * rmt,
491                                     ip46_address_t * lcl_addr)
492 {
493   fib_node_index_t fei;
494   fib_prefix_t prefix;
495
496   if (sw_if_index == ENDPOINT_INVALID_INDEX)
497     {
498       /* Find a FIB path to the destination */
499       clib_memcpy_fast (&prefix.fp_addr, &rmt->ip, sizeof (rmt->ip));
500       prefix.fp_proto = rmt->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
501       prefix.fp_len = rmt->is_ip4 ? 32 : 128;
502
503       ASSERT (rmt->fib_index != ENDPOINT_INVALID_INDEX);
504       fei = fib_table_lookup (rmt->fib_index, &prefix);
505
506       /* Couldn't find route to destination. Bail out. */
507       if (fei == FIB_NODE_INDEX_INVALID)
508         return clib_error_return (0, "no route to %U", format_ip46_address,
509                                   &rmt->ip, (rmt->is_ip4 == 0) + 1);
510
511       sw_if_index = fib_entry_get_resolving_interface (fei);
512       if (sw_if_index == ENDPOINT_INVALID_INDEX)
513         return clib_error_return (0, "no resolving interface for %U",
514                                   format_ip46_address, &rmt->ip,
515                                   (rmt->is_ip4 == 0) + 1);
516     }
517
518   clib_memset (lcl_addr, 0, sizeof (*lcl_addr));
519   return transport_get_interface_ip (sw_if_index, rmt->is_ip4, lcl_addr);
520 }
521
522 int
523 transport_alloc_local_endpoint (u8 proto, transport_endpoint_cfg_t * rmt_cfg,
524                                 ip46_address_t * lcl_addr, u16 * lcl_port)
525 {
526   transport_endpoint_t *rmt = (transport_endpoint_t *) rmt_cfg;
527   clib_error_t *error;
528   int port;
529   u32 tei;
530
531   /*
532    * Find the local address
533    */
534   if (ip_is_zero (&rmt_cfg->peer.ip, rmt_cfg->peer.is_ip4))
535     {
536       error = transport_find_local_ip_for_remote (rmt_cfg->peer.sw_if_index,
537                                                   rmt, lcl_addr);
538       if (error)
539         {
540           clib_error_report (error);
541           return -1;
542         }
543     }
544   else
545     {
546       /* Assume session layer vetted this address */
547       clib_memcpy_fast (lcl_addr, &rmt_cfg->peer.ip,
548                         sizeof (rmt_cfg->peer.ip));
549     }
550
551   /*
552    * Allocate source port
553    */
554   if (rmt_cfg->peer.port == 0)
555     {
556       port = transport_alloc_local_port (proto, lcl_addr);
557       if (port < 1)
558         {
559           clib_warning ("Failed to allocate src port");
560           return -1;
561         }
562       *lcl_port = port;
563     }
564   else
565     {
566       port = clib_net_to_host_u16 (rmt_cfg->peer.port);
567       tei = transport_endpoint_lookup (&local_endpoints_table, proto,
568                                        lcl_addr, port);
569       if (tei != ENDPOINT_INVALID_INDEX)
570         return -1;
571
572       transport_endpoint_mark_used (proto, lcl_addr, port);
573       *lcl_port = port;
574     }
575
576   return 0;
577 }
578
579 #define SPACER_CPU_TICKS_PER_PERIOD_SHIFT 10
580 #define SPACER_CPU_TICKS_PER_PERIOD (1 << SPACER_CPU_TICKS_PER_PERIOD_SHIFT)
581
582 u8 *
583 format_transport_pacer (u8 * s, va_list * args)
584 {
585   spacer_t *pacer = va_arg (*args, spacer_t *);
586
587   s = format (s, "bucket %u max_burst %u tokens/period %.3f last_update %x",
588               pacer->bucket, pacer->max_burst_size, pacer->tokens_per_period,
589               pacer->last_update);
590   return s;
591 }
592
593 static inline u32
594 spacer_max_burst (spacer_t * pacer, u64 norm_time_now)
595 {
596   u64 n_periods = norm_time_now - pacer->last_update;
597   u64 inc;
598
599   if (n_periods > 0 && (inc = n_periods * pacer->tokens_per_period) > 10)
600     {
601       pacer->last_update = norm_time_now;
602       pacer->bucket += inc;
603     }
604
605   return clib_min (pacer->bucket, TRANSPORT_PACER_MAX_BURST);
606 }
607
608 static inline void
609 spacer_update_bucket (spacer_t * pacer, u32 bytes)
610 {
611   ASSERT (pacer->bucket >= bytes);
612   pacer->bucket -= bytes;
613 }
614
615 static inline void
616 spacer_set_pace_rate (spacer_t * pacer, u64 rate_bytes_per_sec)
617 {
618   ASSERT (rate_bytes_per_sec != 0);
619   pacer->tokens_per_period = rate_bytes_per_sec / transport_pacer_period;
620 }
621
622 void
623 transport_connection_tx_pacer_reset (transport_connection_t * tc,
624                                      u32 rate_bytes_per_sec,
625                                      u32 start_bucket, u64 time_now)
626 {
627   spacer_t *pacer = &tc->pacer;
628   spacer_set_pace_rate (&tc->pacer, rate_bytes_per_sec);
629   pacer->last_update = time_now >> SPACER_CPU_TICKS_PER_PERIOD_SHIFT;
630   pacer->bucket = start_bucket;
631 }
632
633 void
634 transport_connection_tx_pacer_init (transport_connection_t * tc,
635                                     u32 rate_bytes_per_sec,
636                                     u32 initial_bucket)
637 {
638   vlib_main_t *vm = vlib_get_main ();
639   tc->flags |= TRANSPORT_CONNECTION_F_IS_TX_PACED;
640   transport_connection_tx_pacer_reset (tc, rate_bytes_per_sec,
641                                        initial_bucket,
642                                        vm->clib_time.last_cpu_time);
643 }
644
645 void
646 transport_connection_tx_pacer_update (transport_connection_t * tc,
647                                       u64 bytes_per_sec)
648 {
649   spacer_set_pace_rate (&tc->pacer, bytes_per_sec);
650 }
651
652 u32
653 transport_connection_tx_pacer_burst (transport_connection_t * tc,
654                                      u64 time_now)
655 {
656   time_now >>= SPACER_CPU_TICKS_PER_PERIOD_SHIFT;
657   return spacer_max_burst (&tc->pacer, time_now);
658 }
659
660 u32
661 transport_connection_snd_space (transport_connection_t * tc, u64 time_now,
662                                 u16 mss)
663 {
664   u32 snd_space, max_paced_burst;
665
666   snd_space = tp_vfts[tc->proto].send_space (tc);
667   if (transport_connection_is_tx_paced (tc))
668     {
669       time_now >>= SPACER_CPU_TICKS_PER_PERIOD_SHIFT;
670       max_paced_burst = spacer_max_burst (&tc->pacer, time_now);
671       max_paced_burst = (max_paced_burst < mss) ? 0 : max_paced_burst;
672       snd_space = clib_min (snd_space, max_paced_burst);
673       snd_space = snd_space - snd_space % mss;
674     }
675   return snd_space;
676 }
677
678 void
679 transport_connection_update_tx_stats (transport_connection_t * tc, u32 bytes)
680 {
681   tc->stats.tx_bytes += bytes;
682   if (transport_connection_is_tx_paced (tc))
683     spacer_update_bucket (&tc->pacer, bytes);
684 }
685
686 void
687 transport_connection_tx_pacer_update_bytes (transport_connection_t * tc,
688                                             u32 bytes)
689 {
690   spacer_update_bucket (&tc->pacer, bytes);
691 }
692
693 void
694 transport_init_tx_pacers_period (void)
695 {
696   f64 cpu_freq = os_cpu_clock_frequency ();
697   transport_pacer_period = cpu_freq / SPACER_CPU_TICKS_PER_PERIOD;
698 }
699
700 void
701 transport_update_time (f64 time_now, u8 thread_index)
702 {
703   transport_proto_vft_t *vft;
704   vec_foreach (vft, tp_vfts)
705   {
706     if (vft->update_time)
707       (vft->update_time) (time_now, thread_index);
708   }
709 }
710
711 void
712 transport_enable_disable (vlib_main_t * vm, u8 is_en)
713 {
714   transport_proto_vft_t *vft;
715   vec_foreach (vft, tp_vfts)
716   {
717     if (vft->enable)
718       (vft->enable) (vm, is_en);
719   }
720 }
721
722 void
723 transport_init (void)
724 {
725   vlib_thread_main_t *vtm = vlib_get_thread_main ();
726   session_main_t *smm = vnet_get_session_main ();
727   u32 num_threads;
728
729   if (smm->local_endpoints_table_buckets == 0)
730     smm->local_endpoints_table_buckets = 250000;
731   if (smm->local_endpoints_table_memory == 0)
732     smm->local_endpoints_table_memory = 512 << 20;
733
734   /* Initialize [port-allocator] random number seed */
735   port_allocator_seed = (u32) clib_cpu_time_now ();
736
737   clib_bihash_init_24_8 (&local_endpoints_table, "local endpoints table",
738                          smm->local_endpoints_table_buckets,
739                          smm->local_endpoints_table_memory);
740   num_threads = 1 /* main thread */  + vtm->n_threads;
741   if (num_threads > 1)
742     clib_spinlock_init (&local_endpoints_lock);
743 }
744
745 /*
746  * fd.io coding-style-patch-verification: ON
747  *
748  * Local Variables:
749  * eval: (c-set-style "gnu")
750  * End:
751  */