Go to the documentation of this file.
68 size_t header_size = 0;
110 overhead += extra_tun;
112 #if defined(USE_COMP)
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)
233 if (setsockopt(sd, IPPROTO_IP, IP_MTU_DISCOVER,
234 (
void *) &mtu_type,
sizeof(mtu_type)))
236 msg(
M_ERR,
"Error setting IP_MTU_DISCOVER type=%d on TCP/UDP socket",
242 #if defined(IPV6_MTU_DISCOVER)
244 if (setsockopt(sd, IPPROTO_IPV6, IPV6_MTU_DISCOVER,
245 (
void *) &mtu_type,
sizeof(mtu_type)))
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)
264 if (!strcmp(name,
"yes"))
266 return IP_PMTUDISC_DO;
268 if (!strcmp(name,
"maybe"))
270 return IP_PMTUDISC_WANT;
272 if (!strcmp(name,
"no"))
274 return IP_PMTUDISC_DONT;
277 "invalid --mtu-disc type: '%s' -- valid types are 'yes', 'maybe', or 'no'",
285 #if EXTENDED_SOCKET_ERROR_CAPABILITY
294 format_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;
304 char *cbuf = (
char *)
gc_malloc(256,
false, gc);
310 memset(&rcvbuf, -1,
sizeof(rcvbuf));
311 iov.iov_base = &rcvbuf;
312 iov.iov_len =
sizeof(rcvbuf);
313 msg.msg_name = (uint8_t *) &addr;
314 msg.msg_namelen =
sizeof(addr);
318 msg.msg_control = cbuf;
319 msg.msg_controllen = 256;
321 res = recvmsg(fd, &
msg, MSG_ERRQUEUE);
329 for (cmsg = CMSG_FIRSTHDR(&
msg); cmsg; cmsg = CMSG_NXTHDR(&
msg, cmsg))
331 if (cmsg->cmsg_level ==
SOL_IP)
333 if (cmsg->cmsg_type == IP_RECVERR)
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);
403 set_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)");
static bool buf_safe(const struct buffer *buf, size_t len)
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
uint16_t mss_fix
The actual MSS value that should be written to the payload packets.
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.