FD.io VPP  v21.06-3-gbb25fbf28
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 #include <vnet/mpls/mpls_lookup.h>
23 
26  const ip4_header_t * inner, ip4_header_t * outer)
27 {
28  if (PREDICT_FALSE (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP))
30  if (PREDICT_FALSE (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN))
31  ip4_header_set_ecn (outer, ip4_header_get_ecn (inner));
32  if (PREDICT_FALSE ((flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DF) &&
33  ip4_header_get_df (inner)))
34  ip4_header_set_df (outer);
35  if (PREDICT_FALSE (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_HOP_LIMIT))
36  ip4_header_set_ttl (outer, ip4_header_get_ttl (inner));
37 }
38 
41  const ip4_header_t * inner,
42  ip4_header_t * outer)
43 {
44  if (PREDICT_FALSE (flags & (TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP |
45  TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN)))
46  {
47  ip_csum_t sum = outer->checksum;
48  u8 tos = outer->tos;
49 
50  if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
52  if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN)
53  ip4_header_set_ecn (outer, ip4_header_get_ecn (inner));
54 
55  sum =
56  ip_csum_update (outer->checksum, tos, outer->tos, ip4_header_t, tos);
57  outer->checksum = ip_csum_fold (sum);
58  }
59  if (PREDICT_FALSE ((flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DF) &&
60  ip4_header_get_df (inner)))
61  {
62  ip_csum_t sum = outer->checksum;
63  u16 tos = outer->flags_and_fragment_offset;
64 
65  ip4_header_set_df (outer);
66 
67  sum =
68  ip_csum_update (outer->checksum, tos, outer->tos, ip4_header_t,
69  flags_and_fragment_offset);
70  outer->checksum = ip_csum_fold (sum);
71  }
72 }
73 
76  const mpls_unicast_header_t *inner,
77  ip4_header_t *outer)
78 {
79  if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
80  {
81  ip_csum_t sum = outer->checksum;
82  u8 tos = outer->tos;
83 
84  if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
85  ip4_header_set_dscp (outer,
87 
88  sum =
89  ip_csum_update (outer->checksum, tos, outer->tos, ip4_header_t, tos);
90  outer->checksum = ip_csum_fold (sum);
91  }
92 }
93 
96  const ip6_header_t * inner, ip4_header_t * outer)
97 {
98  if (PREDICT_FALSE (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP))
100  if (PREDICT_FALSE (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN))
101  ip4_header_set_ecn (outer, ip6_ecn_network_order ((inner)));
102  if (PREDICT_FALSE (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_HOP_LIMIT))
104 }
105 
108  const ip6_header_t * inner,
109  ip4_header_t * outer)
110 {
111  if (PREDICT_FALSE (flags & (TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP |
112  TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN)))
113  {
114  ip_csum_t sum = outer->checksum;
115  u8 tos = outer->tos;
116 
117  if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
119  if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN)
120  ip4_header_set_ecn (outer, ip6_ecn_network_order ((inner)));
121 
122  sum =
123  ip_csum_update (outer->checksum, tos, outer->tos, ip4_header_t, tos);
124  outer->checksum = ip_csum_fold (sum);
125  }
126 }
127 
130  const ip6_header_t * inner, ip6_header_t * outer)
131 {
132  if (PREDICT_FALSE (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP))
134  if (PREDICT_FALSE (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN))
136  if (PREDICT_FALSE (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_FLOW_LABEL))
139  if (PREDICT_FALSE (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_HOP_LIMIT))
142 }
143 
146  const vlib_buffer_t *b, const ip4_header_t *inner,
147  ip6_header_t *outer)
148 {
149  if (PREDICT_FALSE (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP))
151  if (PREDICT_FALSE (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN))
153  if (PREDICT_FALSE (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_HOP_LIMIT))
155  if (PREDICT_FALSE (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_FLOW_LABEL))
157  outer, (0 != vnet_buffer (b)->ip.flow_hash ?
158  vnet_buffer (b)->ip.flow_hash :
160 }
161 
164  const vlib_buffer_t *b,
165  const mpls_unicast_header_t *inner,
166  ip6_header_t *outer)
167 {
168  if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
171  if (PREDICT_FALSE (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_FLOW_LABEL))
173  outer, (0 != vnet_buffer (b)->ip.flow_hash ?
174  vnet_buffer (b)->ip.flow_hash :
176 }
177 
180  const mpls_unicast_header_t *inner,
181  ip4_header_t *outer)
182 {
183  if (flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
185 }
186 
189  ip4_header_t * inner, const ip6_header_t * outer)
190 {
191  if (PREDICT_FALSE (flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN))
193 }
194 
197  ip6_header_t * inner, const ip6_header_t * outer)
198 {
199  if (PREDICT_FALSE (flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN))
201 }
202 
205  ip6_header_t * inner, const ip4_header_t * outer)
206 {
207  if (PREDICT_FALSE (flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN))
209 }
210 
213  ip4_header_t * inner, const ip4_header_t * outer)
214 {
215  if (PREDICT_FALSE (flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN))
217 }
218 
221  mpls_unicast_header_t *inner,
222  const ip6_header_t *outer)
223 {
224 }
225 
228  mpls_unicast_header_t *inner,
229  const ip4_header_t *outer)
230 {
231 }
232 
233 #endif
234 
235 /*
236  * fd.io coding-style-patch-verification: ON
237  *
238  * Local Variables:
239  * eval: (c-set-style "gnu")
240  * End:
241  */
ip6_hop_limit_network_order
static_always_inline u32 ip6_hop_limit_network_order(const ip6_header_t *ip6)
Definition: ip6_packet.h:395
tunnel_encap_decap_flags_t
enum tunnel_encap_decap_flags_t_ tunnel_encap_decap_flags_t
tunnel_encap_fixup_mplso4
static_always_inline void tunnel_encap_fixup_mplso4(tunnel_encap_decap_flags_t flags, const mpls_unicast_header_t *inner, ip4_header_t *outer)
Definition: tunnel_dp.h:179
tunnel_decap_fixup_4o6
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:188
ip4_header_set_ecn_w_chksum
static void ip4_header_set_ecn_w_chksum(ip4_header_t *ip4, ip_ecn_t ecn)
Definition: ip4_packet.h:339
ip4_header_get_df
static u8 ip4_header_get_df(const ip4_header_t *ip4)
Definition: ip4_packet.h:389
ip6_flow_label_network_order
static_always_inline u32 ip6_flow_label_network_order(const ip6_header_t *ip6)
Definition: ip6_packet.h:377
tunnel.h
tunnel_encap_fixup_mplso6
static_always_inline void tunnel_encap_fixup_mplso6(tunnel_encap_decap_flags_t flags, const vlib_buffer_t *b, const mpls_unicast_header_t *inner, ip6_header_t *outer)
Definition: tunnel_dp.h:163
u16
unsigned short u16
Definition: types.h:57
tunnel_encap_fixup_mplso4_w_chksum
static_always_inline void tunnel_encap_fixup_mplso4_w_chksum(tunnel_encap_decap_flags_t flags, const mpls_unicast_header_t *inner, ip4_header_t *outer)
Definition: tunnel_dp.h:75
mpls_unicast_header_t
Definition: packet.h:28
tunnel_encap_fixup_6o4
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:95
ip6_set_dscp_network_order
static_always_inline void ip6_set_dscp_network_order(ip6_header_t *ip6, ip_dscp_t dscp)
Definition: ip6_packet.h:357
ip4_header_t
Definition: ip4_packet.h:87
ip4_header_t::tos
ip_dscp_t tos
Definition: ip4_packet.h:96
ip6_dscp_network_order
static_always_inline ip_dscp_t ip6_dscp_network_order(const ip6_header_t *ip6)
Definition: ip6_packet.h:333
ip4_header_set_df
static void ip4_header_set_df(ip4_header_t *ip4)
Definition: ip4_packet.h:375
tunnel_encap_fixup_6o6
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:129
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:437
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
tunnel_decap_fixup_6o4
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:204
static_always_inline
#define static_always_inline
Definition: clib.h:112
tunnel_encap_fixup_6o4_w_chksum
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:107
IP_FLOW_HASH_DEFAULT
#define IP_FLOW_HASH_DEFAULT
Default: 5-tuple + flowlabel without the "reverse" bit.
Definition: ip_flow_hash.h:22
ip4_header_set_ecn
static void ip4_header_set_ecn(ip4_header_t *ip4, ip_ecn_t ecn)
Definition: ip4_packet.h:332
ip4_header_set_dscp
static void ip4_header_set_dscp(ip4_header_t *ip4, ip_dscp_t dscp)
Definition: ip4_packet.h:320
vnet_mpls_uc_get_exp
static u32 vnet_mpls_uc_get_exp(mpls_label_t label_exp_s_ttl)
Definition: packet.h:110
mpls_compute_flow_hash
static u32 mpls_compute_flow_hash(const mpls_unicast_header_t *hdr, flow_hash_config_t flow_hash_config)
Definition: mpls_lookup.h:43
tunnel_encap_fixup_4o4
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:25
ip4_header_t::checksum
u16 checksum
Definition: ip4_packet.h:118
ip6_set_flow_label_network_order
static_always_inline void ip6_set_flow_label_network_order(ip6_header_t *ip6, u32 flow_label)
Definition: ip6_packet.h:385
mpls_lookup.h
tunnel_decap_fixup_6o6
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:196
ip4_header_get_dscp
static ip_dscp_t ip4_header_get_dscp(const ip4_header_t *ip4)
Definition: ip4_packet.h:351
tunnel_decap_fixup_mplso6
static_always_inline void tunnel_decap_fixup_mplso6(tunnel_encap_decap_flags_t flags, mpls_unicast_header_t *inner, const ip6_header_t *outer)
Definition: tunnel_dp.h:220
ip4_header_set_ttl
static void ip4_header_set_ttl(ip4_header_t *ip4, u8 ttl)
Definition: ip4_packet.h:369
ip6_set_ecn_network_order
static_always_inline void ip6_set_ecn_network_order(ip6_header_t *ip6, ip_ecn_t ecn)
Definition: ip6_packet.h:367
ip4_compute_flow_hash
static u32 ip4_compute_flow_hash(const ip4_header_t *ip, flow_hash_config_t flow_hash_config)
Definition: ip4_inlines.h:51
ip6_header_t
Definition: ip6_packet.h:294
ip4_header_t::flags_and_fragment_offset
u16 flags_and_fragment_offset
Definition: ip4_packet.h:106
mpls_unicast_header_t::label_exp_s_ttl
mpls_label_t label_exp_s_ttl
Definition: packet.h:33
ip_csum_update
#define ip_csum_update(sum, old, new, type, field)
Definition: ip_packet.h:295
ip4_header_get_ecn
static ip_ecn_t ip4_header_get_ecn(const ip4_header_t *ip4)
Definition: ip4_packet.h:357
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
u8
unsigned char u8
Definition: types.h:56
ip
vl_api_address_t ip
Definition: l2.api:558
ip_csum_t
uword ip_csum_t
Definition: ip_packet.h:245
ip6_ecn_network_order
static_always_inline ip_ecn_t ip6_ecn_network_order(const ip6_header_t *ip6)
Definition: ip6_packet.h:340
tunnel_decap_fixup_mplso4
static_always_inline void tunnel_decap_fixup_mplso4(tunnel_encap_decap_flags_t flags, mpls_unicast_header_t *inner, const ip4_header_t *outer)
Definition: tunnel_dp.h:227
tunnel_encap_fixup_4o4_w_chksum
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:40
tunnel_encap_fixup_4o6
static_always_inline void tunnel_encap_fixup_4o6(tunnel_encap_decap_flags_t flags, const vlib_buffer_t *b, const ip4_header_t *inner, ip6_header_t *outer)
Definition: tunnel_dp.h:145
ip_csum_fold
static u16 ip_csum_fold(ip_csum_t c)
Definition: ip_packet.h:301
ip6_set_hop_limit_network_order
static_always_inline void ip6_set_hop_limit_network_order(ip6_header_t *ip6, u8 hop_limit)
Definition: ip6_packet.h:401
ip4_header_get_ttl
static u8 ip4_header_get_ttl(const ip4_header_t *ip4)
Definition: ip4_packet.h:363
tunnel_decap_fixup_4o4
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:212
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105