2 * tunnel_dp.h: data-plane functions tunnels.
4 * Copyright (c) 2019 Cisco and/or its affiliates.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #ifndef __TUNNEL_DP_H__
19 #define __TUNNEL_DP_H__
21 static_always_inline void
22 tunnel_encap_fixup_4o4 (tunnel_encap_decap_flags_t flags,
23 const ip4_header_t * inner, ip4_header_t * outer)
25 if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
26 ip4_header_set_dscp (outer, ip4_header_get_dscp (inner));
27 if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN)
28 ip4_header_set_ecn (outer, ip4_header_get_ecn (inner));
29 if ((flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DF) &&
30 ip4_header_get_df (inner))
31 ip4_header_set_df (outer);
34 static_always_inline void
35 tunnel_encap_fixup_6o4 (tunnel_encap_decap_flags_t flags,
36 const ip6_header_t * inner, ip4_header_t * outer)
38 if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
39 ip4_header_set_dscp (outer, ip6_dscp_network_order (inner));
40 if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN)
41 ip4_header_set_ecn (outer, ip6_ecn_network_order ((inner)));
44 static_always_inline void
45 tunnel_encap_fixup_6o6 (tunnel_encap_decap_flags_t flags,
46 const ip6_header_t * inner, ip6_header_t * outer)
48 if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
49 ip6_set_dscp_network_order (outer, ip6_dscp_network_order (inner));
50 if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN)
51 ip6_set_ecn_network_order (outer, ip6_ecn_network_order (inner));
54 static_always_inline void
55 tunnel_encap_fixup_4o6 (tunnel_encap_decap_flags_t flags,
56 const ip4_header_t * inner, ip6_header_t * outer)
58 if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
59 ip6_set_dscp_network_order (outer, ip4_header_get_dscp (inner));
60 if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN)
61 ip6_set_ecn_network_order (outer, ip4_header_get_ecn (inner));
64 static_always_inline void
65 tunnel_decap_fixup_4o6 (tunnel_encap_decap_flags_t flags,
66 ip4_header_t * inner, const ip6_header_t * outer)
68 if (flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN)
69 ip4_header_set_ecn_w_chksum (inner, ip6_ecn_network_order (outer));
72 static_always_inline void
73 tunnel_decap_fixup_6o6 (tunnel_encap_decap_flags_t flags,
74 ip6_header_t * inner, const ip6_header_t * outer)
76 if (flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN)
77 ip6_set_ecn_network_order (inner, ip6_ecn_network_order (outer));
80 static_always_inline void
81 tunnel_decap_fixup_6o4 (tunnel_encap_decap_flags_t flags,
82 ip6_header_t * inner, const ip4_header_t * outer)
84 if (flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN)
85 ip6_set_ecn_network_order (inner, ip4_header_get_ecn (outer));
88 static_always_inline void
89 tunnel_decap_fixup_4o4 (tunnel_encap_decap_flags_t flags,
90 ip4_header_t * inner, const ip4_header_t * outer)
92 if (flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN)
93 ip4_header_set_ecn_w_chksum (inner, ip4_header_get_ecn (outer));
99 * fd.io coding-style-patch-verification: ON
102 * eval: (c-set-style "gnu")