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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <vnet/tcp/tcp_packet.h>
17 #include <vnet/ip/ip4_packet.h>
20 mss_clamping (u16 mss_clamping, tcp_header_t * tcp, ip_csum_t * sum)
23 u8 opt_len, opts_len, kind;
26 if (!(mss_clamping && tcp_syn (tcp)))
29 opts_len = (tcp_doff (tcp) << 2) - sizeof (tcp_header_t);
30 data = (u8 *) (tcp + 1);
31 for (; opts_len > 0; opts_len -= opt_len, data += opt_len)
35 if (kind == TCP_OPTION_EOL)
37 else if (kind == TCP_OPTION_NOOP)
48 if (opt_len < 2 || opt_len > opts_len)
52 if (kind == TCP_OPTION_MSS)
54 mss = *(u16 *) (data + 2);
55 if (clib_net_to_host_u16 (mss) > mss_clamping)
57 u16 mss_value_net = clib_host_to_net_u16(mss_clamping);
59 ip_csum_update (*sum, mss, mss_value_net, ip4_header_t,
61 clib_memcpy_fast (data + 2, &mss_value_net, 2);