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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
15 #ifndef included_nat_proto_h__
16 #define included_nat_proto_h__
18 #include <vnet/ip/ip.h>
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")
28 #define _(N, i, n, s) NAT_PROTOCOL_##N = i,
33 always_inline nat_protocol_t
34 ip_proto_to_nat_proto (ip_protocol_t ip_proto)
36 static const nat_protocol_t lookup_table[256] = {
37 [IP_PROTOCOL_TCP] = NAT_PROTOCOL_TCP,
38 [IP_PROTOCOL_UDP] = NAT_PROTOCOL_UDP,
39 [IP_PROTOCOL_ICMP] = NAT_PROTOCOL_ICMP,
40 [IP_PROTOCOL_ICMP6] = NAT_PROTOCOL_ICMP,
43 return lookup_table[ip_proto];
46 static_always_inline ip_protocol_t
47 nat_proto_to_ip_proto (nat_protocol_t nat_proto)
49 ASSERT (nat_proto <= NAT_PROTOCOL_ICMP);
51 static const u8 lookup_table[256] = {
52 [NAT_PROTOCOL_OTHER] = ~0,
53 [NAT_PROTOCOL_TCP] = IP_PROTOCOL_TCP,
54 [NAT_PROTOCOL_UDP] = IP_PROTOCOL_UDP,
55 [NAT_PROTOCOL_ICMP] = IP_PROTOCOL_ICMP,
58 ASSERT (NAT_PROTOCOL_OTHER == nat_proto || NAT_PROTOCOL_TCP == nat_proto ||
59 NAT_PROTOCOL_UDP == nat_proto || NAT_PROTOCOL_ICMP == nat_proto);
61 return lookup_table[nat_proto];
64 u8 *format_nat_protocol (u8 *s, va_list *args);
66 uword unformat_nat_protocol (unformat_input_t *input, va_list *args);
68 #endif /* included_nat_proto_h__ */
70 * fd.io coding-style-patch-verification: ON
73 * eval: (c-set-style "gnu")