Go to the documentation of this file.
26 #elif defined(_MSC_VER)
77 size_t header_size = 0;
119 overhead += extra_tun;
121 #if defined(USE_COMP)
131 #if defined(ENABLE_FRAGMENT)
179 unsigned int overhead = 0;
187 overhead += 64/8 + 64/8;
200 return payload + overhead;
216 #ifdef ENABLE_FRAGMENT
231 #define MTUDISC_NOT_SUPPORTED_MSG "--mtu-disc is not supported on this OS"
240 #if defined(IP_MTU_DISCOVER)
242 if (setsockopt(sd, IPPROTO_IP, IP_MTU_DISCOVER,
243 (
void *) &mtu_type,
sizeof(mtu_type)))
245 msg(
M_ERR,
"Error setting IP_MTU_DISCOVER type=%d on TCP/UDP socket",
251 #if defined(IPV6_MTU_DISCOVER)
253 if (setsockopt(sd, IPPROTO_IPV6, IPV6_MTU_DISCOVER,
254 (
void *) &mtu_type,
sizeof(mtu_type)))
256 msg(
M_ERR,
"Error setting IPV6_MTU_DISCOVER type=%d on TCP6/UDP6 socket",
272 #if defined(IP_PMTUDISC_DONT) && defined(IP_PMTUDISC_WANT) && defined(IP_PMTUDISC_DO)
273 if (!strcmp(name,
"yes"))
275 return IP_PMTUDISC_DO;
277 if (!strcmp(name,
"maybe"))
279 return IP_PMTUDISC_WANT;
281 if (!strcmp(name,
"no"))
283 return IP_PMTUDISC_DONT;
286 "invalid --mtu-disc type: '%s' -- valid types are 'yes', 'maybe', or 'no'",
294 #if EXTENDED_SOCKET_ERROR_CAPABILITY
303 format_extended_socket_error(
int fd,
int *mtu,
struct gc_arena *gc)
306 struct probehdr rcvbuf;
309 struct cmsghdr *cmsg;
310 struct sock_extended_err *e;
311 struct sockaddr_storage addr;
313 char *cbuf = (
char *)
gc_malloc(256,
false, gc);
319 memset(&rcvbuf, -1,
sizeof(rcvbuf));
320 iov.iov_base = &rcvbuf;
321 iov.iov_len =
sizeof(rcvbuf);
322 msg.msg_name = (uint8_t *) &addr;
323 msg.msg_namelen =
sizeof(addr);
327 msg.msg_control = cbuf;
328 msg.msg_controllen = 256;
330 res = recvmsg(fd, &
msg, MSG_ERRQUEUE);
338 for (cmsg = CMSG_FIRSTHDR(&
msg); cmsg; cmsg = CMSG_NXTHDR(&
msg, cmsg))
340 if (cmsg->cmsg_level ==
SOL_IP)
342 if (cmsg->cmsg_type == IP_RECVERR)
344 e = (
struct sock_extended_err *) CMSG_DATA(cmsg);
348 buf_printf(&out,
"CMSG=%d|", cmsg->cmsg_type);
351 else if (cmsg->cmsg_level == IPPROTO_IPV6)
353 if (cmsg->cmsg_type == IPV6_RECVERR)
355 e = (
struct sock_extended_err *) CMSG_DATA(cmsg);
359 buf_printf(&out,
"CMSG=%d|", cmsg->cmsg_type);
376 buf_printf(&out,
"EMSGSIZE Path-MTU=%d|", e->ee_info);
412 set_sock_extended_error_passing(
int sd,
sa_family_t proto_af)
418 if (setsockopt(sd,
SOL_IP, IP_RECVERR, (
void *) &on,
sizeof(on)) != 0)
421 "Note: enable extended error passing on TCP/UDP socket failed (IP_RECVERR)");
426 if (proto_af == AF_INET6
427 && setsockopt(sd, IPPROTO_IPV6, IPV6_RECVERR, (
void *) &on,
sizeof(on)) != 0)
430 "Note: enable extended error passing on TCP/UDP socket failed (IPV6_RECVERR)");
static bool buf_safe(const struct buffer *buf, size_t len)
unsigned int mss_fix
The actual MSS value that should be written to the payload packets.
void buf_rmtail(struct buffer *buf, uint8_t remove)
static struct gc_arena gc_new(void)
int len
Length in bytes of the actual content within the allocated memory.
void frame_print(const struct frame *frame, int level, const char *prefix)
const char * socks_proxy_server
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 buf_init(buf, offset)
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.
const char * shared_secret_file
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
int tailroom
the tailroom in the buffer.
struct connection_entry ce
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.
Packet geometry parameters.
int translate_mtu_discover_type_name(const char *name)
unsigned short sa_family_t
int extra_tun
Maximum number of bytes in excess of the tun/tap MTU that might be read from or written to the virtua...
struct compress_options comp
int payload_size
the maximum size that a payload that our buffers can hold from either tun device or network link.
size_t calc_options_string_link_mtu(const struct options *o, const struct frame *frame)
Calculate the link-mtu to advertise to our peer.
Wrapper structure for dynamically allocated memory.
static bool proto_is_udp(int proto)
Returns if the protocol being used is UDP.
#define MTUDISC_NOT_SUPPORTED_MSG
int max_fragment_size
The maximum size of a fragment.
bool cipher_kt_mode_ofb_cfb(const char *ciphername)
Check if the supplied cipher is a supported OFB or CFB mode cipher.
Garbage collection arena used to keep track of dynamically allocated memory.
void alloc_buf_sock_tun(struct buffer *buf, const struct frame *frame)
const char * cipher
const name of the cipher
SOCKET socket_descriptor_t
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
void set_mtu_discover_type(socket_descriptor_t sd, int mtu_type, sa_family_t proto_af)
static int packet_id_size(bool long_form)
static void gc_free(struct gc_arena *a)
int tun_max_mtu
the maximum tun-mtu size the buffers are are sized for.
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...
bool cipher_kt_mode_cbc(const char *ciphername)
Check if the supplied cipher is a supported CBC mode cipher.
static bool proto_is_tcp(int proto)
returns if the proto is a TCP variant (tcp-server, tcp-client or tcp)
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.
struct buffer alloc_buf(size_t size)
int tun_mtu
the (user) configured tun-mtu.
bool buf_printf(struct buffer *buf, const char *format,...)
int headroom
the headroom in the buffer, this is choosen to allow all potential header to be added before the pack...
uint8_t * data
Pointer to the allocated memory.