LCOV - code coverage report
Current view: top level - vnet/udp - udp.h (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 15 28 53.6 %
Date: 2023-10-26 01:39:38 Functions: 6 7 85.7 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2017-2020 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             : #ifndef __included_udp_h__
      16             : #define __included_udp_h__
      17             : 
      18             : #include <vnet/vnet.h>
      19             : #include <vnet/udp/udp_inlines.h>
      20             : #include <vnet/udp/udp_local.h>
      21             : #include <vnet/udp/udp_packet.h>
      22             : #include <vnet/ip/ip4_packet.h>
      23             : #include <vnet/ip/format.h>
      24             : 
      25             : #include <vnet/ip/ip.h>
      26             : #include <vnet/session/transport.h>
      27             : 
      28             : #define UDP_NO_NODE_SET ((u16) ~0)
      29             : 
      30             : typedef enum
      31             : {
      32             : #define udp_error(f, n, s, d) UDP_ERROR_##f,
      33             : #include <vnet/udp/udp_error.def>
      34             : #undef udp_error
      35             :   UDP_N_ERROR,
      36             : } udp_error_t;
      37             : 
      38             : #define foreach_udp_connection_flag                                     \
      39             :   _(CONNECTED, "CONNECTED")   /**< connected mode */                       \
      40             :   _(OWNS_PORT, "OWNS_PORT")   /**< port belong to conn (UDPC) */   \
      41             :   _(CLOSING, "CLOSING")               /**< conn closed with data */                \
      42             :   _(LISTEN, "LISTEN")         /**< conn is listening */            \
      43             :   _(MIGRATED, "MIGRATED")     /**< cloned to another thread */     \
      44             : 
      45             : enum udp_conn_flags_bits
      46             : {
      47             : #define _(sym, str) UDP_CONN_F_BIT_##sym,
      48             :   foreach_udp_connection_flag
      49             : #undef _
      50             :   UDP_CONN_N_FLAGS
      51             : };
      52             : 
      53             : typedef enum udp_conn_flags_
      54             : {
      55             : #define _(sym, str) UDP_CONN_F_##sym = 1 << UDP_CONN_F_BIT_##sym,
      56             :   foreach_udp_connection_flag
      57             : #undef _
      58             : } udp_conn_flags_t;
      59             : 
      60             : #define foreach_udp_cfg_flag _ (NO_CSUM_OFFLOAD, "no-csum-offload")
      61             : 
      62             : typedef enum udp_cfg_flag_bits_
      63             : {
      64             : #define _(sym, str) UDP_CFG_F_##sym##_BIT,
      65             :   foreach_udp_cfg_flag
      66             : #undef _
      67             :     UDP_CFG_N_FLAG_BITS
      68             : } udp_cfg_flag_bits_e;
      69             : 
      70             : typedef enum udp_cfg_flag_
      71             : {
      72             : #define _(sym, str) UDP_CFG_F_##sym = 1 << UDP_CFG_F_##sym##_BIT,
      73             :   foreach_udp_cfg_flag
      74             : #undef _
      75             :     UDP_CFG_N_FLAGS
      76             : } __clib_packed udp_cfg_flags_t;
      77             : 
      78             : typedef struct
      79             : {
      80             :   /** Required for pool_get_aligned */
      81             :   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
      82             :   transport_connection_t connection;    /**< must be first */
      83             :   clib_spinlock_t rx_lock;              /**< rx fifo lock */
      84             :   u8 flags;                             /**< connection flags */
      85             :   udp_cfg_flags_t cfg_flags;            /**< configuration flags */
      86             :   u16 mss;                              /**< connection mss */
      87             :   u32 sw_if_index;                      /**< connection sw_if_index */
      88             :   u32 next_node_index;  /**< Can be used to control next node in output */
      89             :   u32 next_node_opaque; /**< Opaque to pass to next node */
      90             : } udp_connection_t;
      91             : 
      92             : #define udp_csum_offload(uc) (!((uc)->cfg_flags & UDP_CFG_F_NO_CSUM_OFFLOAD))
      93             : 
      94             : typedef struct
      95             : {
      96             :   /* Name (a c string). */
      97             :   char *name;
      98             : 
      99             :   /* Port number in host byte order. */
     100             :   udp_dst_port_t dst_port;
     101             : 
     102             :   /* Node which handles this type. */
     103             :   u32 node_index;
     104             : 
     105             :   /* Next index for this type. */
     106             :   u32 next_index;
     107             : 
     108             :   /* Parser for packet generator edits for this protocol */
     109             :   unformat_function_t *unformat_pg_edit;
     110             : } udp_dst_port_info_t;
     111             : 
     112             : typedef enum
     113             : {
     114             :   UDP_IP6 = 0,
     115             :   UDP_IP4,                      /* the code is full of is_ip4... */
     116             :   N_UDP_AF,
     117             : } udp_af_t;
     118             : 
     119             : typedef struct udp_worker_
     120             : {
     121             :   udp_connection_t *connections;
     122             :   u32 *pending_cleanups;
     123             : } udp_worker_t;
     124             : 
     125             : typedef struct
     126             : {
     127             :   udp_dst_port_info_t *dst_port_infos[N_UDP_AF];
     128             : 
     129             :   /* Hash tables mapping name/protocol to protocol info index. */
     130             :   uword *dst_port_info_by_name[N_UDP_AF];
     131             :   uword *dst_port_info_by_dst_port[N_UDP_AF];
     132             : 
     133             :   /* Sparse vector mapping udp dst_port in network byte order
     134             :      to next index. */
     135             :   u16 *next_by_dst_port4;
     136             :   u16 *next_by_dst_port6;
     137             :   u8 punt_unknown4;
     138             :   u8 punt_unknown6;
     139             : 
     140             :   /* Udp local to input arc index */
     141             :   u32 local_to_input_edge[N_UDP_AF];
     142             : 
     143             :   /*
     144             :    * UDP transport layer per-thread context
     145             :    */
     146             : 
     147             :   udp_worker_t *wrk;
     148             :   udp_connection_t *listener_pool;
     149             : 
     150             :   /* Refcounts for ports consumed by udp transports to handle
     151             :    * both passive and active opens using the same port */
     152             :   u16 *transport_ports_refcnt[N_UDP_AF];
     153             : 
     154             :   u16 default_mtu;
     155             :   u16 msg_id_base;
     156             :   u8 csum_offload;
     157             : 
     158             :   u8 icmp_send_unreachable_disabled;
     159             : } udp_main_t;
     160             : 
     161             : extern udp_main_t udp_main;
     162             : extern vlib_node_registration_t udp4_input_node;
     163             : extern vlib_node_registration_t udp6_input_node;
     164             : extern vlib_node_registration_t udp4_local_node;
     165             : extern vlib_node_registration_t udp6_local_node;
     166             : extern vlib_node_registration_t udp4_output_node;
     167             : extern vlib_node_registration_t udp6_output_node;
     168             : 
     169             : void udp_add_dst_port (udp_main_t * um, udp_dst_port_t dst_port,
     170             :                        char *dst_port_name, u8 is_ip4);
     171             : 
     172             : always_inline udp_worker_t *
     173      234508 : udp_worker_get (u32 thread_index)
     174             : {
     175      234508 :   return vec_elt_at_index (udp_main.wrk, thread_index);
     176             : }
     177             : 
     178             : always_inline udp_connection_t *
     179      234347 : udp_connection_get (u32 conn_index, u32 thread_index)
     180             : {
     181      234347 :   udp_worker_t *wrk = udp_worker_get (thread_index);
     182             : 
     183      234347 :   if (pool_is_free_index (wrk->connections, conn_index))
     184           0 :     return 0;
     185      234347 :   return pool_elt_at_index (wrk->connections, conn_index);
     186             : }
     187             : 
     188             : always_inline udp_connection_t *
     189          62 : udp_listener_get (u32 conn_index)
     190             : {
     191          62 :   return pool_elt_at_index (udp_main.listener_pool, conn_index);
     192             : }
     193             : 
     194             : always_inline udp_main_t *
     195         619 : vnet_get_udp_main ()
     196             : {
     197         619 :   return &udp_main;
     198             : }
     199             : 
     200             : always_inline udp_connection_t *
     201       94317 : udp_connection_from_transport (transport_connection_t * tc)
     202             : {
     203       94317 :   return ((udp_connection_t *) tc);
     204             : }
     205             : 
     206             : void udp_connection_free (udp_connection_t * uc);
     207             : udp_connection_t *udp_connection_alloc (u32 thread_index);
     208             : 
     209             : always_inline udp_connection_t *
     210           0 : udp_connection_clone_safe (u32 connection_index, u32 thread_index)
     211             : {
     212           0 :   u32 current_thread_index = vlib_get_thread_index (), new_index;
     213             :   udp_connection_t *old_c, *new_c;
     214             : 
     215           0 :   new_c = udp_connection_alloc (current_thread_index);
     216           0 :   new_index = new_c->c_c_index;
     217             :   /* Connection pool always realloced with barrier */
     218           0 :   old_c = udp_main.wrk[thread_index].connections + connection_index;
     219           0 :   clib_memcpy_fast (new_c, old_c, sizeof (*new_c));
     220           0 :   old_c->flags |= UDP_CONN_F_MIGRATED;
     221           0 :   new_c->c_thread_index = current_thread_index;
     222           0 :   new_c->c_c_index = new_index;
     223           0 :   new_c->c_fib_index = old_c->c_fib_index;
     224             :   /* Assume cloned sessions don't need lock */
     225           0 :   new_c->rx_lock = 0;
     226           0 :   return new_c;
     227             : }
     228             : 
     229             : always_inline udp_dst_port_info_t *
     230        1477 : udp_get_dst_port_info (udp_main_t * um, udp_dst_port_t dst_port, u8 is_ip4)
     231             : {
     232        1477 :   uword *p = hash_get (um->dst_port_info_by_dst_port[is_ip4], dst_port);
     233        1477 :   return p ? vec_elt_at_index (um->dst_port_infos[is_ip4], p[0]) : 0;
     234             : }
     235             : 
     236             : format_function_t format_udp_header;
     237             : format_function_t format_udp_rx_trace;
     238             : format_function_t format_udp_connection;
     239             : unformat_function_t unformat_udp_header;
     240             : unformat_function_t unformat_udp_port;
     241             : 
     242             : void udp_punt_unknown (vlib_main_t * vm, u8 is_ip4, u8 is_add);
     243             : 
     244             : /*
     245             :  * fd.io coding-style-patch-verification: ON
     246             :  *
     247             :  * Local Variables:
     248             :  * eval: (c-set-style "gnu")
     249             :  * End:
     250             :  */
     251             : 
     252             : #endif /* __included_udp_h__ */

Generated by: LCOV version 1.14