68 size_t header_size = 0;
110 overhead += extra_tun;
122#if defined(ENABLE_FRAGMENT)
178 overhead += 64/8 + 64/8;
191 return payload + overhead;
207#ifdef ENABLE_FRAGMENT
222#define MTUDISC_NOT_SUPPORTED_MSG "--mtu-disc is not supported on this OS"
231#if defined(IP_MTU_DISCOVER)
236 msg(
M_ERR,
"Error setting IP_MTU_DISCOVER type=%d on TCP/UDP socket",
242#if defined(IPV6_MTU_DISCOVER)
247 msg(
M_ERR,
"Error setting IPV6_MTU_DISCOVER type=%d on TCP6/UDP6 socket",
263#if defined(IP_PMTUDISC_DONT) && defined(IP_PMTUDISC_WANT) && defined(IP_PMTUDISC_DO)
268 if (!
strcmp(name,
"maybe"))
277 "invalid --mtu-disc type: '%s' -- valid types are 'yes', 'maybe', or 'no'",
285#if EXTENDED_SOCKET_ERROR_CAPABILITY
294format_extended_socket_error(
int fd,
int *mtu,
struct gc_arena *
gc)
297 struct probehdr rcvbuf;
300 struct cmsghdr *cmsg;
301 struct sock_extended_err *e;
302 struct sockaddr_storage addr;
310 memset(&rcvbuf, -1,
sizeof(rcvbuf));
311 iov.iov_base = &rcvbuf;
312 iov.iov_len =
sizeof(rcvbuf);
314 msg.msg_namelen =
sizeof(addr);
319 msg.msg_controllen = 256;
335 e = (
struct sock_extended_err *) CMSG_DATA(cmsg);
339 buf_printf(&out,
"CMSG=%d|", cmsg->cmsg_type);
342 else if (cmsg->cmsg_level == IPPROTO_IPV6)
344 if (cmsg->cmsg_type == IPV6_RECVERR)
346 e = (
struct sock_extended_err *) CMSG_DATA(cmsg);
350 buf_printf(&out,
"CMSG=%d|", cmsg->cmsg_type);
367 buf_printf(&out,
"EMSGSIZE Path-MTU=%d|", e->ee_info);
403set_sock_extended_error_passing(
int sd,
sa_family_t proto_af)
409 if (setsockopt(sd,
SOL_IP, IP_RECVERR, (
void *) &on,
sizeof(on)) != 0)
412 "Note: enable extended error passing on TCP/UDP socket failed (IP_RECVERR)");
417 if (proto_af == AF_INET6
418 && setsockopt(sd, IPPROTO_IPV6, IPV6_RECVERR, (
void *) &on,
sizeof(on)) != 0)
421 "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)
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