FD.io VPP  v21.01.1
Vector Packet Processing
nat_inlines.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef __included_lib_nat_inlines_h__
17 #define __included_lib_nat_inlines_h__
18 
19 #include <vnet/tcp/tcp_packet.h>
20 #include <vnet/ip/ip4_packet.h>
21 
22 static inline void
24 {
25  u32 v;
26 
27  v = clib_net_to_host_u32 (a->as_u32) + 1;
28  a->as_u32 = clib_host_to_net_u32 (v);
29 }
30 
31 always_inline void
33 {
34  u8 *data;
35  u8 opt_len, opts_len, kind;
36  u16 mss;
37 
38  if (!(mss_clamping && tcp_syn (tcp)))
39  return;
40 
41  opts_len = (tcp_doff (tcp) << 2) - sizeof (tcp_header_t);
42  data = (u8 *) (tcp + 1);
43  for (; opts_len > 0; opts_len -= opt_len, data += opt_len)
44  {
45  kind = data[0];
46 
47  if (kind == TCP_OPTION_EOL)
48  break;
49  else if (kind == TCP_OPTION_NOOP)
50  {
51  opt_len = 1;
52  continue;
53  }
54  else
55  {
56  if (opts_len < 2)
57  return;
58  opt_len = data[1];
59 
60  if (opt_len < 2 || opt_len > opts_len)
61  return;
62  }
63 
64  if (kind == TCP_OPTION_MSS)
65  {
66  mss = *(u16 *) (data + 2);
67  if (clib_net_to_host_u16 (mss) > mss_clamping)
68  {
69  u16 mss_value_net = clib_host_to_net_u16 (mss_clamping);
70  *sum =
71  ip_csum_update (*sum, mss, mss_value_net, ip4_header_t,
72  length);
73  clib_memcpy_fast (data + 2, &mss_value_net, 2);
74  }
75  return;
76  }
77  }
78 }
79 
80 #endif /* __included_lib_nat_inlines_h__ */
81 
82 /*
83  * fd.io coding-style-patch-verification: ON
84  *
85  * Local Variables:
86  * eval: (c-set-style "gnu")
87  * End:
88  */
End of options.
Definition: tcp_packet.h:104
a
Definition: bitmap.h:544
#define clib_memcpy_fast(a, b, c)
Definition: string.h:81
#define tcp_doff(_th)
Definition: tcp_packet.h:78
uword ip_csum_t
Definition: ip_packet.h:246
No operation.
Definition: tcp_packet.h:105
struct _tcp_header tcp_header_t
unsigned char u8
Definition: types.h:56
u8 data[128]
Definition: ipsec_types.api:90
Limit MSS.
Definition: tcp_packet.h:106
unsigned int u32
Definition: types.h:88
unsigned short u16
Definition: types.h:57
static void mss_clamping(u16 mss_clamping, tcp_header_t *tcp, ip_csum_t *sum)
Definition: nat_inlines.h:32
#define always_inline
Definition: ipsec.h:28
static void increment_v4_address(ip4_address_t *a)
Definition: nat_inlines.h:23
#define tcp_syn(_th)
Definition: tcp_packet.h:80
char const int length
Definition: cJSON.h:163
#define ip_csum_update(sum, old, new, type, field)
Definition: ip_packet.h:296