blob: a00a3b3e2224caf19944a68468679945ba5b052d [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
Neale Ranns4ec36c52020-03-31 09:21:29 -040021#include <vnet/tunnel/tunnel.h>
22
Neale Rannse5b94dd2019-12-31 05:13:14 +000023static_always_inline void
24tunnel_encap_fixup_4o4 (tunnel_encap_decap_flags_t flags,
25 const ip4_header_t * inner, ip4_header_t * outer)
26{
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);
34}
35
36static_always_inline void
37tunnel_encap_fixup_6o4 (tunnel_encap_decap_flags_t flags,
38 const ip6_header_t * inner, ip4_header_t * outer)
39{
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)));
44}
45
46static_always_inline void
47tunnel_encap_fixup_6o6 (tunnel_encap_decap_flags_t flags,
48 const ip6_header_t * inner, ip6_header_t * outer)
49{
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));
54}
55
56static_always_inline void
57tunnel_encap_fixup_4o6 (tunnel_encap_decap_flags_t flags,
58 const ip4_header_t * inner, ip6_header_t * outer)
59{
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));
64}
65
66static_always_inline void
67tunnel_decap_fixup_4o6 (tunnel_encap_decap_flags_t flags,
68 ip4_header_t * inner, const ip6_header_t * outer)
69{
70 if (flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN)
71 ip4_header_set_ecn_w_chksum (inner, ip6_ecn_network_order (outer));
72}
73
74static_always_inline void
75tunnel_decap_fixup_6o6 (tunnel_encap_decap_flags_t flags,
76 ip6_header_t * inner, const ip6_header_t * outer)
77{
78 if (flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN)
79 ip6_set_ecn_network_order (inner, ip6_ecn_network_order (outer));
80}
81
82static_always_inline void
83tunnel_decap_fixup_6o4 (tunnel_encap_decap_flags_t flags,
84 ip6_header_t * inner, const ip4_header_t * outer)
85{
86 if (flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN)
87 ip6_set_ecn_network_order (inner, ip4_header_get_ecn (outer));
88}
89
90static_always_inline void
91tunnel_decap_fixup_4o4 (tunnel_encap_decap_flags_t flags,
92 ip4_header_t * inner, const ip4_header_t * outer)
93{
94 if (flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN)
95 ip4_header_set_ecn_w_chksum (inner, ip4_header_get_ecn (outer));
96}
97
98#endif
99
100/*
101 * fd.io coding-style-patch-verification: ON
102 *
103 * Local Variables:
104 * eval: (c-set-style "gnu")
105 * End:
106 */