LCOV - code coverage report
Current view: top level - plugins/nat/lib - nat_proto.h (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 6 6 100.0 %
Date: 2023-10-26 01:39:38 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2021 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_nat_proto_h__
      16             : #define included_nat_proto_h__
      17             : 
      18             : #include <vnet/ip/ip.h>
      19             : 
      20             : #define foreach_nat_protocol                                                  \
      21             :   _ (OTHER, 0, other, "other")                                                \
      22             :   _ (UDP, 1, udp, "udp")                                                      \
      23             :   _ (TCP, 2, tcp, "tcp")                                                      \
      24             :   _ (ICMP, 3, icmp, "icmp")
      25             : 
      26             : typedef enum
      27             : {
      28             : #define _(N, i, n, s) NAT_PROTOCOL_##N = i,
      29             :   foreach_nat_protocol
      30             : #undef _
      31             :     NAT_N_PROTOCOLS
      32             : } nat_protocol_t;
      33             : 
      34             : always_inline nat_protocol_t
      35       22005 : ip_proto_to_nat_proto (ip_protocol_t ip_proto)
      36             : {
      37             :   static const nat_protocol_t lookup_table[256] = {
      38             :     [IP_PROTOCOL_TCP] = NAT_PROTOCOL_TCP,
      39             :     [IP_PROTOCOL_UDP] = NAT_PROTOCOL_UDP,
      40             :     [IP_PROTOCOL_ICMP] = NAT_PROTOCOL_ICMP,
      41             :     [IP_PROTOCOL_ICMP6] = NAT_PROTOCOL_ICMP,
      42             :   };
      43             : 
      44       22005 :   return lookup_table[ip_proto];
      45             : }
      46             : 
      47             : static_always_inline ip_protocol_t
      48       21031 : nat_proto_to_ip_proto (nat_protocol_t nat_proto)
      49             : {
      50       21031 :   ASSERT (nat_proto <= NAT_PROTOCOL_ICMP);
      51             : 
      52             :   static const u8 lookup_table[256] = {
      53             :     [NAT_PROTOCOL_OTHER] = ~0,
      54             :     [NAT_PROTOCOL_TCP] = IP_PROTOCOL_TCP,
      55             :     [NAT_PROTOCOL_UDP] = IP_PROTOCOL_UDP,
      56             :     [NAT_PROTOCOL_ICMP] = IP_PROTOCOL_ICMP,
      57             :   };
      58             : 
      59       21031 :   ASSERT (NAT_PROTOCOL_OTHER == nat_proto || NAT_PROTOCOL_TCP == nat_proto ||
      60             :           NAT_PROTOCOL_UDP == nat_proto || NAT_PROTOCOL_ICMP == nat_proto);
      61             : 
      62       21031 :   return lookup_table[nat_proto];
      63             : }
      64             : 
      65             : u8 *format_nat_protocol (u8 *s, va_list *args);
      66             : 
      67             : uword unformat_nat_protocol (unformat_input_t *input, va_list *args);
      68             : 
      69             : #endif /* included_nat_proto_h__ */
      70             : /*
      71             :  * fd.io coding-style-patch-verification: ON
      72             :  *
      73             :  * Local Variables:
      74             :  * eval: (c-set-style "gnu")
      75             :  * End:
      76             :  */

Generated by: LCOV version 1.14