65 size_t header_size = 0;
106 overhead += extra_tun;
118#if defined(ENABLE_FRAGMENT)
173 overhead += 64 / 8 + 64 / 8;
186 return payload + overhead;
200#ifdef ENABLE_FRAGMENT
215#define MTUDISC_NOT_SUPPORTED_MSG "--mtu-disc is not supported on this OS"
224#if defined(IP_MTU_DISCOVER)
229 msg(
M_ERR,
"Error setting IP_MTU_DISCOVER type=%d on TCP/UDP socket",
mtu_type);
234#if defined(IPV6_MTU_DISCOVER)
239 msg(
M_ERR,
"Error setting IPV6_MTU_DISCOVER type=%d on TCP6/UDP6 socket",
255#if defined(IP_PMTUDISC_DONT) && defined(IP_PMTUDISC_WANT) && defined(IP_PMTUDISC_DO)
260 if (!
strcmp(name,
"maybe"))
268 msg(
M_FATAL,
"invalid --mtu-disc type: '%s' -- valid types are 'yes', 'maybe', or 'no'", name);
275#if EXTENDED_SOCKET_ERROR_CAPABILITY
284format_extended_socket_error(
int fd,
int *mtu,
struct gc_arena *
gc)
287 struct probehdr rcvbuf;
290 struct cmsghdr *cmsg;
291 struct sock_extended_err *e;
292 struct sockaddr_storage addr;
300 memset(&rcvbuf, -1,
sizeof(rcvbuf));
301 iov.iov_base = &rcvbuf;
302 iov.iov_len =
sizeof(rcvbuf);
304 msg.msg_namelen =
sizeof(addr);
309 msg.msg_controllen = 256;
325 e = (
struct sock_extended_err *)CMSG_DATA(cmsg);
329 buf_printf(&out,
"CMSG=%d|", cmsg->cmsg_type);
332 else if (cmsg->cmsg_level == IPPROTO_IPV6)
334 if (cmsg->cmsg_type == IPV6_RECVERR)
336 e = (
struct sock_extended_err *)CMSG_DATA(cmsg);
340 buf_printf(&out,
"CMSG=%d|", cmsg->cmsg_type);
357 buf_printf(&out,
"EMSGSIZE Path-MTU=%d|", e->ee_info);
393set_sock_extended_error_passing(
int sd,
sa_family_t proto_af)
399 if (setsockopt(sd,
SOL_IP, IP_RECVERR, (
void *)&on,
sizeof(on)) != 0)
402 "Note: enable extended error passing on TCP/UDP socket failed (IP_RECVERR)");
407 if (proto_af == AF_INET6
408 && setsockopt(sd, IPPROTO_IPV6, IPV6_RECVERR, (
void *)&on,
sizeof(on)) != 0)
411 "Note: enable extended error passing on TCP/UDP socket failed (IPV6_RECVERR)");
bool buf_printf(struct buffer *buf, const char *format,...)
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
struct buffer alloc_buf(size_t size)
void buf_rmtail(struct buffer *buf, uint8_t remove)
static bool buf_safe(const struct buffer *buf, size_t len)
static void gc_free(struct gc_arena *a)
#define buf_init(buf, offset)
static struct gc_arena gc_new(void)
#define COMP_ALG_LZ4
LZ4 algorithm.
#define COMP_ALG_STUB
support compression command byte and framing without actual compression
#define COMP_ALG_LZO
LZO algorithm.
unsigned int calculate_crypto_overhead(const struct key_type *kt, unsigned int pkt_id_size, bool occ)
Calculate the maximum overhead that our encryption has on a packet.
void init_key_type(struct key_type *kt, const char *ciphername, const char *authname, bool tls_mode, bool warn)
Initialize a key_type structure with.
Data Channel Cryptography Module.
bool cipher_kt_mode_cbc(const char *ciphername)
Check if the supplied cipher is a supported CBC mode cipher.
bool cipher_kt_mode_ofb_cfb(const char *ciphername)
Check if the supplied cipher is a supported OFB or CFB mode cipher.
void frame_print(const struct frame *frame, int level, const char *prefix)
size_t frame_calculate_payload_size(const struct frame *frame, const struct options *options, const struct key_type *kt)
Calculates the size of the payload according to tun-mtu and tap overhead.
#define MTUDISC_NOT_SUPPORTED_MSG
int translate_mtu_discover_type_name(const char *name)
size_t frame_calculate_protocol_header_size(const struct key_type *kt, const struct options *options, bool occ)
Calculates the size of the OpenVPN protocol header.
unsigned int calc_packet_id_size_dc(const struct options *options, const struct key_type *kt)
Return the size of the packet ID size that is currently in use by cipher and options for the data cha...
void alloc_buf_sock_tun(struct buffer *buf, const struct frame *frame)
size_t calc_options_string_link_mtu(const struct options *o, const struct frame *frame)
Calculate the link-mtu to advertise to our peer.
void set_mtu_discover_type(socket_descriptor_t sd, int mtu_type, sa_family_t proto_af)
size_t frame_calculate_payload_overhead(size_t extra_tun, const struct options *options, const struct key_type *kt)
Calculates the size of the payload overhead according to tun-mtu and tap overhead.
static int packet_id_size(bool long_form)
static bool proto_is_udp(int proto)
Returns if the protocol being used is UDP.
static bool proto_is_tcp(int proto)
returns if the proto is a TCP variant (tcp-server, tcp-client or tcp)
Wrapper structure for dynamically allocated memory.
uint8_t * data
Pointer to the allocated memory.
int len
Length in bytes of the actual content within the allocated memory.
const char * socks_proxy_server
Packet geometry parameters.
int tun_mtu
the (user) configured tun-mtu.
int payload_size
the maximum size that a payload that our buffers can hold from either tun device or network link.
int tun_max_mtu
the maximum tun-mtu size the buffers are are sized for.
int extra_tun
Maximum number of bytes in excess of the tun/tap MTU that might be read from or written to the virtua...
int headroom
the headroom in the buffer, this is choosen to allow all potential header to be added before the pack...
uint16_t mss_fix
The actual MSS value that should be written to the payload packets.
int max_fragment_size
The maximum size of a fragment.
int tailroom
the tailroom in the buffer.
Garbage collection arena used to keep track of dynamically allocated memory.
const char * cipher
const name of the cipher
struct compress_options comp
struct connection_entry ce
const char * shared_secret_file
unsigned short sa_family_t
SOCKET socket_descriptor_t