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,
34 always_inline nat_protocol_t
35 ip_proto_to_nat_proto (ip_protocol_t ip_proto)
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,
44 return lookup_table[ip_proto];
47 static_always_inline ip_protocol_t
48 nat_proto_to_ip_proto (nat_protocol_t nat_proto)
50 ASSERT (nat_proto <= NAT_PROTOCOL_ICMP);
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,
59 ASSERT (NAT_PROTOCOL_OTHER == nat_proto || NAT_PROTOCOL_TCP == nat_proto ||
60 NAT_PROTOCOL_UDP == nat_proto || NAT_PROTOCOL_ICMP == nat_proto);
62 return lookup_table[nat_proto];
65 u8 *format_nat_protocol (u8 *s, va_list *args);
67 uword unformat_nat_protocol (unformat_input_t *input, va_list *args);
69 #endif /* included_nat_proto_h__ */
71 * fd.io coding-style-patch-verification: ON
74 * eval: (c-set-style "gnu")