FD.io VPP  v21.01.1
Vector Packet Processing
inlines.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 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 /**
16  * @brief Common NAT inline functions
17  */
18 #ifndef included_nat_inlines_h__
19 #define included_nat_inlines_h__
20 
21 #include <vnet/ip/icmp46_packet.h>
22 
25 {
26  static const nat_protocol_t lookup_table[256] = {
27  [IP_PROTOCOL_TCP] = NAT_PROTOCOL_TCP,
28  [IP_PROTOCOL_UDP] = NAT_PROTOCOL_UDP,
29  [IP_PROTOCOL_ICMP] = NAT_PROTOCOL_ICMP,
30  [IP_PROTOCOL_ICMP6] = NAT_PROTOCOL_ICMP,
31  };
32 
33  return lookup_table[ip_proto];
34 }
35 
38 {
39  ASSERT (nat_proto <= NAT_PROTOCOL_ICMP);
40 
41  static const u8 lookup_table[256] = {
42  [NAT_PROTOCOL_OTHER] = ~0,
43  [NAT_PROTOCOL_TCP] = IP_PROTOCOL_TCP,
44  [NAT_PROTOCOL_UDP] = IP_PROTOCOL_UDP,
45  [NAT_PROTOCOL_ICMP] = IP_PROTOCOL_ICMP,
46  };
47 
48  ASSERT (NAT_PROTOCOL_OTHER == nat_proto || NAT_PROTOCOL_TCP == nat_proto
49  || NAT_PROTOCOL_UDP == nat_proto || NAT_PROTOCOL_ICMP == nat_proto);
50 
51  return lookup_table[nat_proto];
52 }
53 
56 {
57  switch (icmp_type)
58  {
59  case ICMP4_destination_unreachable:
60  case ICMP4_time_exceeded:
61  case ICMP4_parameter_problem:
62  case ICMP4_source_quench:
63  case ICMP4_redirect:
64  case ICMP4_alternate_host_address:
65  return 1;
66  }
67  return 0;
68 }
69 
70 #endif /* included_nat_inlines_h__ */
71 /*
72  * fd.io coding-style-patch-verification: ON
73  *
74  * Local Variables:
75  * eval: (c-set-style "gnu")
76  * End:
77  */
ip_proto
Definition: ip_types.api:75
nat_protocol_t
Definition: lib.h:63
unsigned char u8
Definition: types.h:56
#define static_always_inline
Definition: clib.h:109
static nat_protocol_t ip_proto_to_nat_proto(u8 ip_proto)
Common NAT inline functions.
Definition: inlines.h:24
static_always_inline u8 icmp_type_is_error_message(u8 icmp_type)
Definition: inlines.h:55
#define always_inline
Definition: ipsec.h:28
#define ASSERT(truth)
static_always_inline u8 nat_proto_to_ip_proto(nat_protocol_t nat_proto)
Definition: inlines.h:37