OpenVPN 3 Core Library
Loading...
Searching...
No Matches
tcp.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12#pragma once
13
16
17namespace openvpn {
18
19#pragma pack(push)
20#pragma pack(1)
21
23{
24 static unsigned int length(const std::uint8_t doff_res)
25 {
26 return ((doff_res) & 0xF0) >> 2;
27 }
28
29 std::uint16_t source;
30 std::uint16_t dest;
31 std::uint32_t seq;
32 std::uint32_t ack_seq;
33 std::uint8_t doff_res;
34 std::uint8_t flags;
35 std::uint16_t window;
36 std::uint16_t check;
37 std::uint16_t urgent_p;
38
39 // helper enum to parse options in TCP header
40 enum
41 {
46 };
47
48 enum
49 {
50 FLAG_SYN = 1 << 1
51 };
52};
53
54#pragma pack(pop)
55
56/*
57 * The following routine is used to update an
58 * internet checksum. "acc" is a 32-bit
59 * accumulation of all the changes to the
60 * checksum (adding in old 16-bit words and
61 * subtracting out new words), and "cksum"
62 * is the checksum value to be updated.
63 */
64inline void tcp_adjust_checksum(int acc, std::uint16_t &cksum)
65{
66 int _acc = acc;
67 _acc += cksum;
68 if (_acc < 0)
69 {
70 _acc = -_acc;
71 _acc = (_acc >> 16) + (_acc & 0xffff);
72 _acc += _acc >> 16;
73 cksum = (uint16_t)~_acc;
74 }
75 else
76 {
77 _acc = (_acc >> 16) + (_acc & 0xffff);
78 _acc += _acc >> 16;
79 cksum = (uint16_t)_acc;
80 }
81}
82} // namespace openvpn
Support deferred server-side state creation when client connects.
Definition ovpncli.cpp:95
void tcp_adjust_checksum(int acc, std::uint16_t &cksum)
Definition tcp.hpp:64
std::uint16_t window
Definition tcp.hpp:35
std::uint16_t dest
Definition tcp.hpp:30
std::uint32_t ack_seq
Definition tcp.hpp:32
std::uint16_t source
Definition tcp.hpp:29
std::uint16_t check
Definition tcp.hpp:36
static unsigned int length(const std::uint8_t doff_res)
Definition tcp.hpp:24
std::uint16_t urgent_p
Definition tcp.hpp:37
std::uint8_t flags
Definition tcp.hpp:34
std::uint32_t seq
Definition tcp.hpp:31
std::uint8_t doff_res
Definition tcp.hpp:33