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 #include <vnet/tunnel/tunnel.h>
23 static_always_inline void
24 tunnel_encap_fixup_4o4 (tunnel_encap_decap_flags_t flags,
25 const ip4_header_t * inner, ip4_header_t * outer)
27 if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
28 ip4_header_set_dscp (outer, ip4_header_get_dscp (inner));
29 if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN)
30 ip4_header_set_ecn (outer, ip4_header_get_ecn (inner));
31 if ((flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DF) &&
32 ip4_header_get_df (inner))
33 ip4_header_set_df (outer);
36 static_always_inline void
37 tunnel_encap_fixup_6o4 (tunnel_encap_decap_flags_t flags,
38 const ip6_header_t * inner, ip4_header_t * outer)
40 if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
41 ip4_header_set_dscp (outer, ip6_dscp_network_order (inner));
42 if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN)
43 ip4_header_set_ecn (outer, ip6_ecn_network_order ((inner)));
46 static_always_inline void
47 tunnel_encap_fixup_6o6 (tunnel_encap_decap_flags_t flags,
48 const ip6_header_t * inner, ip6_header_t * outer)
50 if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
51 ip6_set_dscp_network_order (outer, ip6_dscp_network_order (inner));
52 if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN)
53 ip6_set_ecn_network_order (outer, ip6_ecn_network_order (inner));
56 static_always_inline void
57 tunnel_encap_fixup_4o6 (tunnel_encap_decap_flags_t flags,
58 const ip4_header_t * inner, ip6_header_t * outer)
60 if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
61 ip6_set_dscp_network_order (outer, ip4_header_get_dscp (inner));
62 if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN)
63 ip6_set_ecn_network_order (outer, ip4_header_get_ecn (inner));
66 static_always_inline void
67 tunnel_decap_fixup_4o6 (tunnel_encap_decap_flags_t flags,
68 ip4_header_t * inner, const ip6_header_t * outer)
70 if (flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN)
71 ip4_header_set_ecn_w_chksum (inner, ip6_ecn_network_order (outer));
74 static_always_inline void
75 tunnel_decap_fixup_6o6 (tunnel_encap_decap_flags_t flags,
76 ip6_header_t * inner, const ip6_header_t * outer)
78 if (flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN)
79 ip6_set_ecn_network_order (inner, ip6_ecn_network_order (outer));
82 static_always_inline void
83 tunnel_decap_fixup_6o4 (tunnel_encap_decap_flags_t flags,
84 ip6_header_t * inner, const ip4_header_t * outer)
86 if (flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN)
87 ip6_set_ecn_network_order (inner, ip4_header_get_ecn (outer));
90 static_always_inline void
91 tunnel_decap_fixup_4o4 (tunnel_encap_decap_flags_t flags,
92 ip4_header_t * inner, const ip4_header_t * outer)
94 if (flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN)
95 ip4_header_set_ecn_w_chksum (inner, ip4_header_get_ecn (outer));
101 * fd.io coding-style-patch-verification: ON
104 * eval: (c-set-style "gnu")