FD.io VPP  v21.01.1
Vector Packet Processing
tunnel_dp.h
Go to the documentation of this file.
1 /*
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 
21 #include <vnet/tunnel/tunnel.h>
22 
25  const ip4_header_t * inner, ip4_header_t * outer)
26 {
27  if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
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 
38  const ip4_header_t * inner,
39  ip4_header_t * outer)
40 {
41  if (flags & (TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP |
42  TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN))
43  {
44  ip_csum_t sum = outer->checksum;
45  u8 tos = outer->tos;
46 
47  if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
49  if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN)
50  ip4_header_set_ecn (outer, ip4_header_get_ecn (inner));
51 
52  sum =
53  ip_csum_update (outer->checksum, tos, outer->tos, ip4_header_t, tos);
54  outer->checksum = ip_csum_fold (sum);
55  }
56  if ((flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DF) &&
57  ip4_header_get_df (inner))
58  {
59  ip_csum_t sum = outer->checksum;
60  u16 tos = outer->flags_and_fragment_offset;
61 
62  ip4_header_set_df (outer);
63 
64  sum =
65  ip_csum_update (outer->checksum, tos, outer->tos, ip4_header_t,
66  flags_and_fragment_offset);
67  outer->checksum = ip_csum_fold (sum);
68  }
69 }
70 
73  const ip6_header_t * inner, ip4_header_t * outer)
74 {
75  if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
77  if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN)
78  ip4_header_set_ecn (outer, ip6_ecn_network_order ((inner)));
79 }
80 
83  const ip6_header_t * inner,
84  ip4_header_t * outer)
85 {
86  if (flags & (TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP |
87  TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN))
88  {
89  ip_csum_t sum = outer->checksum;
90  u8 tos = outer->tos;
91 
92  if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
94  if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN)
95  ip4_header_set_ecn (outer, ip6_ecn_network_order ((inner)));
96 
97  sum =
98  ip_csum_update (outer->checksum, tos, outer->tos, ip4_header_t, tos);
99  outer->checksum = ip_csum_fold (sum);
100  }
101 }
102 
105  const ip6_header_t * inner, ip6_header_t * outer)
106 {
107  if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
109  if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN)
111 }
112 
115  const ip4_header_t * inner, ip6_header_t * outer)
116 {
117  if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
119  if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN)
121 }
122 
125  ip4_header_t * inner, const ip6_header_t * outer)
126 {
127  if (flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN)
129 }
130 
133  ip6_header_t * inner, const ip6_header_t * outer)
134 {
135  if (flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN)
137 }
138 
141  ip6_header_t * inner, const ip4_header_t * outer)
142 {
143  if (flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN)
145 }
146 
149  ip4_header_t * inner, const ip4_header_t * outer)
150 {
151  if (flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN)
153 }
154 
155 #endif
156 
157 /*
158  * fd.io coding-style-patch-verification: ON
159  *
160  * Local Variables:
161  * eval: (c-set-style "gnu")
162  * End:
163  */
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105
static ip_dscp_t ip4_header_get_dscp(const ip4_header_t *ip4)
Definition: ip4_packet.h:351
static void ip4_header_set_ecn_w_chksum(ip4_header_t *ip4, ip_ecn_t ecn)
Definition: ip4_packet.h:339
uword ip_csum_t
Definition: ip_packet.h:246
static void ip4_header_set_dscp(ip4_header_t *ip4, ip_dscp_t dscp)
Definition: ip4_packet.h:320
u16 flags_and_fragment_offset
Definition: ip4_packet.h:106
static_always_inline ip_ecn_t ip6_ecn_network_order(const ip6_header_t *ip6)
Definition: ip6_packet.h:339
unsigned char u8
Definition: types.h:56
#define static_always_inline
Definition: clib.h:109
static_always_inline void tunnel_decap_fixup_6o6(tunnel_encap_decap_flags_t flags, ip6_header_t *inner, const ip6_header_t *outer)
Definition: tunnel_dp.h:132
static_always_inline void tunnel_encap_fixup_6o6(tunnel_encap_decap_flags_t flags, const ip6_header_t *inner, ip6_header_t *outer)
Definition: tunnel_dp.h:104
static_always_inline void tunnel_decap_fixup_4o4(tunnel_encap_decap_flags_t flags, ip4_header_t *inner, const ip4_header_t *outer)
Definition: tunnel_dp.h:148
static_always_inline void tunnel_encap_fixup_4o6(tunnel_encap_decap_flags_t flags, const ip4_header_t *inner, ip6_header_t *outer)
Definition: tunnel_dp.h:114
static void ip4_header_set_ecn(ip4_header_t *ip4, ip_ecn_t ecn)
Definition: ip4_packet.h:332
static void ip4_header_set_df(ip4_header_t *ip4)
Definition: ip4_packet.h:363
unsigned short u16
Definition: types.h:57
enum tunnel_encap_decap_flags_t_ tunnel_encap_decap_flags_t
static_always_inline void ip6_set_dscp_network_order(ip6_header_t *ip6, ip_dscp_t dscp)
Definition: ip6_packet.h:356
static_always_inline ip_dscp_t ip6_dscp_network_order(const ip6_header_t *ip6)
Definition: ip6_packet.h:332
static_always_inline void ip6_set_ecn_network_order(ip6_header_t *ip6, ip_ecn_t ecn)
Definition: ip6_packet.h:366
static_always_inline void tunnel_encap_fixup_4o4(tunnel_encap_decap_flags_t flags, const ip4_header_t *inner, ip4_header_t *outer)
Definition: tunnel_dp.h:24
static_always_inline void tunnel_decap_fixup_4o6(tunnel_encap_decap_flags_t flags, ip4_header_t *inner, const ip6_header_t *outer)
Definition: tunnel_dp.h:124
static_always_inline void tunnel_decap_fixup_6o4(tunnel_encap_decap_flags_t flags, ip6_header_t *inner, const ip4_header_t *outer)
Definition: tunnel_dp.h:140
ip_dscp_t tos
Definition: ip4_packet.h:96
static u8 ip4_header_get_df(const ip4_header_t *ip4)
Definition: ip4_packet.h:377
static_always_inline void tunnel_encap_fixup_6o4(tunnel_encap_decap_flags_t flags, const ip6_header_t *inner, ip4_header_t *outer)
Definition: tunnel_dp.h:72
#define ip_csum_update(sum, old, new, type, field)
Definition: ip_packet.h:296
static ip_ecn_t ip4_header_get_ecn(const ip4_header_t *ip4)
Definition: ip4_packet.h:357
static_always_inline void tunnel_encap_fixup_6o4_w_chksum(tunnel_encap_decap_flags_t flags, const ip6_header_t *inner, ip4_header_t *outer)
Definition: tunnel_dp.h:82
static_always_inline void tunnel_encap_fixup_4o4_w_chksum(tunnel_encap_decap_flags_t flags, const ip4_header_t *inner, ip4_header_t *outer)
Definition: tunnel_dp.h:37
static u16 ip_csum_fold(ip_csum_t c)
Definition: ip_packet.h:302