nat: dslite plugin separation
[vpp.git] / src / plugins / nat / lib / inlines.h
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 The NAT44 inline functions
17  */
18 #ifndef included_nat_inlines_h__
19 #define included_nat_inlines_h__
20
21 static_always_inline u32
22 ip_proto_to_nat_proto (u8 ip_proto)
23 {
24   u32 nat_proto = ~0;
25
26   nat_proto = (ip_proto == IP_PROTOCOL_UDP) ? NAT_PROTOCOL_UDP : nat_proto;
27   nat_proto = (ip_proto == IP_PROTOCOL_TCP) ? NAT_PROTOCOL_TCP : nat_proto;
28   nat_proto = (ip_proto == IP_PROTOCOL_ICMP) ? NAT_PROTOCOL_ICMP : nat_proto;
29   nat_proto = (ip_proto == IP_PROTOCOL_ICMP6) ? NAT_PROTOCOL_ICMP : nat_proto;
30
31   return nat_proto;
32 }
33
34 static_always_inline u8
35 nat_proto_to_ip_proto (nat_protocol_t nat_proto)
36 {
37   u8 ip_proto = ~0;
38
39   ip_proto = (nat_proto == NAT_PROTOCOL_UDP) ? IP_PROTOCOL_UDP : ip_proto;
40   ip_proto = (nat_proto == NAT_PROTOCOL_TCP) ? IP_PROTOCOL_TCP : ip_proto;
41   ip_proto = (nat_proto == NAT_PROTOCOL_ICMP) ? IP_PROTOCOL_ICMP : ip_proto;
42
43   return ip_proto;
44 }
45
46 static_always_inline u8
47 icmp_type_is_error_message (u8 icmp_type)
48 {
49   switch (icmp_type)
50     {
51     case ICMP4_destination_unreachable:
52     case ICMP4_time_exceeded:
53     case ICMP4_parameter_problem:
54     case ICMP4_source_quench:
55     case ICMP4_redirect:
56     case ICMP4_alternate_host_address:
57       return 1;
58     }
59   return 0;
60 }
61
62 #endif /* included_nat_inlines_h__ */
63 /*
64  * fd.io coding-style-patch-verification: ON
65  *
66  * Local Variables:
67  * eval: (c-set-style "gnu")
68  * End:
69  */