blob: 3e3a81307f1a6ea04603e8c22ae95fe029a46b6f [file] [log] [blame]
Neale Rannse5b94dd2019-12-31 05:13:14 +00001/*
2 * tunnel_dp.h: data-plane functions tunnels.
3 *
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:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 */
17
18#ifndef __TUNNEL_DP_H__
19#define __TUNNEL_DP_H__
20
21static_always_inline void
22tunnel_encap_fixup_4o4 (tunnel_encap_decap_flags_t flags,
23 const ip4_header_t * inner, ip4_header_t * outer)
24{
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);
32}
33
34static_always_inline void
35tunnel_encap_fixup_6o4 (tunnel_encap_decap_flags_t flags,
36 const ip6_header_t * inner, ip4_header_t * outer)
37{
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)));
42}
43
44static_always_inline void
45tunnel_encap_fixup_6o6 (tunnel_encap_decap_flags_t flags,
46 const ip6_header_t * inner, ip6_header_t * outer)
47{
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));
52}
53
54static_always_inline void
55tunnel_encap_fixup_4o6 (tunnel_encap_decap_flags_t flags,
56 const ip4_header_t * inner, ip6_header_t * outer)
57{
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));
62}
63
64static_always_inline void
65tunnel_decap_fixup_4o6 (tunnel_encap_decap_flags_t flags,
66 ip4_header_t * inner, const ip6_header_t * outer)
67{
68 if (flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN)
69 ip4_header_set_ecn_w_chksum (inner, ip6_ecn_network_order (outer));
70}
71
72static_always_inline void
73tunnel_decap_fixup_6o6 (tunnel_encap_decap_flags_t flags,
74 ip6_header_t * inner, const ip6_header_t * outer)
75{
76 if (flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN)
77 ip6_set_ecn_network_order (inner, ip6_ecn_network_order (outer));
78}
79
80static_always_inline void
81tunnel_decap_fixup_6o4 (tunnel_encap_decap_flags_t flags,
82 ip6_header_t * inner, const ip4_header_t * outer)
83{
84 if (flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN)
85 ip6_set_ecn_network_order (inner, ip4_header_get_ecn (outer));
86}
87
88static_always_inline void
89tunnel_decap_fixup_4o4 (tunnel_encap_decap_flags_t flags,
90 ip4_header_t * inner, const ip4_header_t * outer)
91{
92 if (flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN)
93 ip4_header_set_ecn_w_chksum (inner, ip4_header_get_ecn (outer));
94}
95
96#endif
97
98/*
99 * fd.io coding-style-patch-verification: ON
100 *
101 * Local Variables:
102 * eval: (c-set-style "gnu")
103 * End:
104 */