OpenVPN
proto.h File Reference
#include "common.h"
#include "buffer.h"
Include dependency graph for proto.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  openvpn_ethhdr
struct  openvpn_8021qhdr
struct  openvpn_iphdr
struct  openvpn_ipv6hdr
struct  openvpn_icmp6hdr
struct  openvpn_udphdr
struct  openvpn_tcphdr
struct  ip_tcp_udp_hdr

Macros

#define DEV_TYPE_UNDEF   0
#define DEV_TYPE_TUN   2 /* point-to-point IP tunnel */
#define DEV_TYPE_TAP   3 /* ethernet (802.3) tunnel */
#define TOP_UNDEF   0
#define TOP_NET30   1
#define TOP_P2P   2
#define TOP_SUBNET   3
#define OPENVPN_ETH_ALEN   6 /* ethernet address length */
#define OPENVPN_ETH_P_IPV4   0x0800 /* IPv4 protocol */
#define OPENVPN_ETH_P_IPV6   0x86DD /* IPv6 protocol */
#define OPENVPN_ETH_P_ARP   0x0806 /* ARP protocol */
#define OPENVPN_ETH_P_8021Q   0x8100 /* 802.1Q protocol */
#define OPENVPN_8021Q_MASK_PCP   htons(0xE000) /* mask PCP out of pcp_cfi_vid */
#define OPENVPN_8021Q_MASK_CFI   htons(0x1000) /* mask CFI out of pcp_cfi_vid */
#define OPENVPN_8021Q_MASK_VID   htons(0x0FFF) /* mask VID out of pcp_cfi_vid */
#define SIZE_ETH_TO_8021Q_HDR   (sizeof(struct openvpn_8021qhdr) - sizeof(struct openvpn_ethhdr))
#define OPENVPN_IN6_ARE_ADDR_EQUAL(a, b)
 Version of IN6_ARE_ADDR_EQUAL that is guaranteed to work for unaligned access.
#define OPENVPN_IPH_GET_VER(v)
#define OPENVPN_IPH_GET_LEN(v)
#define OPENVPN_IP_OFFMASK   0x1fff
#define OPENVPN_IPPROTO_IGMP   2 /* IGMP protocol */
#define OPENVPN_IPPROTO_TCP   6 /* TCP protocol */
#define OPENVPN_IPPROTO_UDP   17 /* UDP protocol */
#define OPENVPN_IPPROTO_ICMPV6   58 /* ICMPV6 protocol */
#define OPENVPN_ICMP6_DESTINATION_UNREACHABLE   1
#define OPENVPN_ND_ROUTER_SOLICIT   133
#define OPENVPN_ND_ROUTER_ADVERT   134
#define OPENVPN_ND_NEIGHBOR_SOLICIT   135
#define OPENVPN_ND_NEIGHBOR_ADVERT   136
#define OPENVPN_ND_INVERSE_SOLICIT   141
#define OPENVPN_ND_INVERSE_ADVERT   142
#define OPENVPN_ICMP6_DU_NOROUTE   0
#define OPENVPN_ICMP6_DU_COMMUNICATION_PROHIBTED   1
#define OPENVPN_TCPH_GET_DOFF(d)
#define OPENVPN_TCPH_FIN_MASK   (1 << 0)
#define OPENVPN_TCPH_SYN_MASK   (1 << 1)
#define OPENVPN_TCPH_RST_MASK   (1 << 2)
#define OPENVPN_TCPH_PSH_MASK   (1 << 3)
#define OPENVPN_TCPH_ACK_MASK   (1 << 4)
#define OPENVPN_TCPH_URG_MASK   (1 << 5)
#define OPENVPN_TCPH_ECE_MASK   (1 << 6)
#define OPENVPN_TCPH_CWR_MASK   (1 << 7)
#define OPENVPN_TCPOPT_EOL   0
#define OPENVPN_TCPOPT_NOP   1
#define OPENVPN_TCPOPT_MAXSEG   2
#define OPENVPN_TCPOLEN_MAXSEG   4
#define ADJUST_CHECKSUM(acc, cksum)
#define ADD_CHECKSUM_32(acc, u32)
#define SUB_CHECKSUM_32(acc, u32)
#define OPENVPN_8021Q_MIN_VID   1
#define OPENVPN_8021Q_MAX_VID   4094

Functions

static int get_tun_ip_ver (int tunnel_type, const struct buffer *buf, int *ip_hdr_offset)
bool is_ipv4 (int tunnel_type, struct buffer *buf)
bool is_ipv6 (int tunnel_type, struct buffer *buf)
uint16_t ip_checksum (const sa_family_t af, const uint8_t *payload, const int len_payload, const uint8_t *src_addr, const uint8_t *dest_addr, const int proto)
 Calculates an IP or IPv6 checksum with a pseudo header as required by TCP, UDP and ICMPv6.

Macro Definition Documentation

◆ ADD_CHECKSUM_32

#define ADD_CHECKSUM_32 ( acc,
u32 )
Value:
{ \
acc += (int32_t)((u32) & 0xffff); \
acc += (int32_t)((u32) >> 16); \
}

Definition at line 234 of file proto.h.

Referenced by client_nat_transform().

◆ ADJUST_CHECKSUM

#define ADJUST_CHECKSUM ( acc,
cksum )
Value:
{ \
int32_t _acc = acc; \
_acc += (cksum); \
if (_acc < 0) \
{ \
_acc = -_acc; \
_acc = (_acc >> 16) + (_acc & 0xffff); \
_acc += _acc >> 16; \
(cksum) = (uint16_t)~_acc; \
} \
else \
{ \
_acc = (_acc >> 16) + (_acc & 0xffff); \
_acc += _acc >> 16; \
(cksum) = (uint16_t)_acc; \
} \
}

Definition at line 215 of file proto.h.

Referenced by client_nat_transform(), and mss_fixup_dowork().

◆ DEV_TYPE_TAP

◆ DEV_TYPE_TUN

◆ DEV_TYPE_UNDEF

#define DEV_TYPE_UNDEF   0

Definition at line 34 of file proto.h.

Referenced by dev_type_enum(), is_tun_type_set(), multi_init(), and options_postprocess_verify_ce().

◆ OPENVPN_8021Q_MASK_CFI

#define OPENVPN_8021Q_MASK_CFI   htons(0x1000) /* mask CFI out of pcp_cfi_vid */

Definition at line 72 of file proto.h.

◆ OPENVPN_8021Q_MASK_PCP

#define OPENVPN_8021Q_MASK_PCP   htons(0xE000) /* mask PCP out of pcp_cfi_vid */

Definition at line 71 of file proto.h.

◆ OPENVPN_8021Q_MASK_VID

#define OPENVPN_8021Q_MASK_VID   htons(0x0FFF) /* mask VID out of pcp_cfi_vid */

Definition at line 73 of file proto.h.

Referenced by vlanhdr_get_vid(), and vlanhdr_set_vid().

◆ OPENVPN_8021Q_MAX_VID

#define OPENVPN_8021Q_MAX_VID   4094

Definition at line 317 of file proto.h.

Referenced by add_option().

◆ OPENVPN_8021Q_MIN_VID

#define OPENVPN_8021Q_MIN_VID   1

Definition at line 316 of file proto.h.

Referenced by add_option().

◆ OPENVPN_ETH_ALEN

#define OPENVPN_ETH_ALEN   6 /* ethernet address length */

Definition at line 52 of file proto.h.

Referenced by ipv6_send_icmp_unreachable(), and mroute_copy_ether_to_addr().

◆ OPENVPN_ETH_P_8021Q

#define OPENVPN_ETH_P_8021Q   0x8100 /* 802.1Q protocol */

Definition at line 61 of file proto.h.

Referenced by is_ipv_X(), vlan_decapsulate(), vlan_encapsulate(), and vlan_is_tagged().

◆ OPENVPN_ETH_P_ARP

#define OPENVPN_ETH_P_ARP   0x0806 /* ARP protocol */

Definition at line 60 of file proto.h.

◆ OPENVPN_ETH_P_IPV4

#define OPENVPN_ETH_P_IPV4   0x0800 /* IPv4 protocol */

Definition at line 58 of file proto.h.

Referenced by get_tun_ip_ver(), and is_ipv_X().

◆ OPENVPN_ETH_P_IPV6

#define OPENVPN_ETH_P_IPV6   0x86DD /* IPv6 protocol */

Definition at line 59 of file proto.h.

Referenced by get_tun_ip_ver(), ipv6_send_icmp_unreachable(), and is_ipv_X().

◆ OPENVPN_ICMP6_DESTINATION_UNREACHABLE

#define OPENVPN_ICMP6_DESTINATION_UNREACHABLE   1

Definition at line 136 of file proto.h.

Referenced by ipv6_send_icmp_unreachable().

◆ OPENVPN_ICMP6_DU_COMMUNICATION_PROHIBTED

#define OPENVPN_ICMP6_DU_COMMUNICATION_PROHIBTED   1

Definition at line 145 of file proto.h.

◆ OPENVPN_ICMP6_DU_NOROUTE

#define OPENVPN_ICMP6_DU_NOROUTE   0

Definition at line 144 of file proto.h.

Referenced by ipv6_send_icmp_unreachable().

◆ OPENVPN_IN6_ARE_ADDR_EQUAL

#define OPENVPN_IN6_ARE_ADDR_EQUAL ( a,
b )
Value:
(memcmp(a, b, sizeof(struct in6_addr)) == 0)

Version of IN6_ARE_ADDR_EQUAL that is guaranteed to work for unaligned access.

E.g. Linux uses 32bit compares which are not safe if the struct is unaligned.

Definition at line 87 of file proto.h.

Referenced by drop_if_recursive_routing().

◆ OPENVPN_IP_OFFMASK

#define OPENVPN_IP_OFFMASK   0x1fff

Definition at line 99 of file proto.h.

Referenced by mss_fixup_ipv4().

◆ OPENVPN_IPH_GET_LEN

#define OPENVPN_IPH_GET_LEN ( v)
Value:
(((v) & 0x0F) << 2)

Definition at line 92 of file proto.h.

Referenced by drop_if_recursive_routing(), and mss_fixup_ipv4().

◆ OPENVPN_IPH_GET_VER

#define OPENVPN_IPH_GET_VER ( v)
Value:
(((v) >> 4) & 0x0F)

Definition at line 91 of file proto.h.

Referenced by get_tun_ip_ver(), is_ip_packet_valid(), is_ipv_X(), and mroute_extract_addr_ip().

◆ OPENVPN_IPPROTO_ICMPV6

#define OPENVPN_IPPROTO_ICMPV6   58 /* ICMPV6 protocol */

Definition at line 107 of file proto.h.

Referenced by ipv6_send_icmp_unreachable().

◆ OPENVPN_IPPROTO_IGMP

#define OPENVPN_IPPROTO_IGMP   2 /* IGMP protocol */

Definition at line 104 of file proto.h.

Referenced by mroute_extract_addr_ip().

◆ OPENVPN_IPPROTO_TCP

#define OPENVPN_IPPROTO_TCP   6 /* TCP protocol */

◆ OPENVPN_IPPROTO_UDP

#define OPENVPN_IPPROTO_UDP   17 /* UDP protocol */

◆ OPENVPN_ND_INVERSE_ADVERT

#define OPENVPN_ND_INVERSE_ADVERT   142

Definition at line 142 of file proto.h.

◆ OPENVPN_ND_INVERSE_SOLICIT

#define OPENVPN_ND_INVERSE_SOLICIT   141

Definition at line 141 of file proto.h.

◆ OPENVPN_ND_NEIGHBOR_ADVERT

#define OPENVPN_ND_NEIGHBOR_ADVERT   136

Definition at line 140 of file proto.h.

◆ OPENVPN_ND_NEIGHBOR_SOLICIT

#define OPENVPN_ND_NEIGHBOR_SOLICIT   135

Definition at line 139 of file proto.h.

◆ OPENVPN_ND_ROUTER_ADVERT

#define OPENVPN_ND_ROUTER_ADVERT   134

Definition at line 138 of file proto.h.

◆ OPENVPN_ND_ROUTER_SOLICIT

#define OPENVPN_ND_ROUTER_SOLICIT   133

Definition at line 137 of file proto.h.

◆ OPENVPN_TCPH_ACK_MASK

#define OPENVPN_TCPH_ACK_MASK   (1 << 4)

Definition at line 179 of file proto.h.

◆ OPENVPN_TCPH_CWR_MASK

#define OPENVPN_TCPH_CWR_MASK   (1 << 7)

Definition at line 182 of file proto.h.

◆ OPENVPN_TCPH_ECE_MASK

#define OPENVPN_TCPH_ECE_MASK   (1 << 6)

Definition at line 181 of file proto.h.

◆ OPENVPN_TCPH_FIN_MASK

#define OPENVPN_TCPH_FIN_MASK   (1 << 0)

Definition at line 175 of file proto.h.

◆ OPENVPN_TCPH_GET_DOFF

#define OPENVPN_TCPH_GET_DOFF ( d)
Value:
(((d) & 0xF0) >> 2)

Definition at line 172 of file proto.h.

Referenced by mss_fixup_dowork().

◆ OPENVPN_TCPH_PSH_MASK

#define OPENVPN_TCPH_PSH_MASK   (1 << 3)

Definition at line 178 of file proto.h.

◆ OPENVPN_TCPH_RST_MASK

#define OPENVPN_TCPH_RST_MASK   (1 << 2)

Definition at line 177 of file proto.h.

◆ OPENVPN_TCPH_SYN_MASK

#define OPENVPN_TCPH_SYN_MASK   (1 << 1)

Definition at line 176 of file proto.h.

Referenced by mss_fixup_ipv4(), and mss_fixup_ipv6().

◆ OPENVPN_TCPH_URG_MASK

#define OPENVPN_TCPH_URG_MASK   (1 << 5)

Definition at line 180 of file proto.h.

◆ OPENVPN_TCPOLEN_MAXSEG

#define OPENVPN_TCPOLEN_MAXSEG   4

Definition at line 193 of file proto.h.

Referenced by mss_fixup_dowork().

◆ OPENVPN_TCPOPT_EOL

#define OPENVPN_TCPOPT_EOL   0

Definition at line 190 of file proto.h.

Referenced by mss_fixup_dowork().

◆ OPENVPN_TCPOPT_MAXSEG

#define OPENVPN_TCPOPT_MAXSEG   2

Definition at line 192 of file proto.h.

Referenced by mss_fixup_dowork().

◆ OPENVPN_TCPOPT_NOP

#define OPENVPN_TCPOPT_NOP   1

Definition at line 191 of file proto.h.

Referenced by mss_fixup_dowork().

◆ SIZE_ETH_TO_8021Q_HDR

#define SIZE_ETH_TO_8021Q_HDR   (sizeof(struct openvpn_8021qhdr) - sizeof(struct openvpn_ethhdr))

Definition at line 82 of file proto.h.

Referenced by vlan_decapsulate(), and vlan_encapsulate().

◆ SUB_CHECKSUM_32

#define SUB_CHECKSUM_32 ( acc,
u32 )
Value:
{ \
acc -= (int32_t)((u32) & 0xffff); \
acc -= (int32_t)((u32) >> 16); \
}

Definition at line 240 of file proto.h.

Referenced by client_nat_transform().

◆ TOP_NET30

◆ TOP_P2P

#define TOP_P2P   2

◆ TOP_SUBNET

◆ TOP_UNDEF

#define TOP_UNDEF   0

Function Documentation

◆ get_tun_ip_ver()

int get_tun_ip_ver ( int tunnel_type,
const struct buffer * buf,
int * ip_hdr_offset )
inlinestatic

◆ ip_checksum()

uint16_t ip_checksum ( const sa_family_t af,
const uint8_t * payload,
const int len_payload,
const uint8_t * src_addr,
const uint8_t * dest_addr,
const int proto )

Calculates an IP or IPv6 checksum with a pseudo header as required by TCP, UDP and ICMPv6.

Parameters
af- Address family for which the checksum is calculated AF_INET or AF_INET6
payload- the TCP, ICMPv6 or UDP packet
len_payload- length of payload
src_addr- Source address of the packet
dest_addr- Destination address of the packet
protonext - header or IP protocol of the packet
Returns
The calculated checksum in host order

Definition at line 119 of file proto.c.

Referenced by dhcp_extract_router_msg(), and ipv6_send_icmp_unreachable().

◆ is_ipv4()

bool is_ipv4 ( int tunnel_type,
struct buffer * buf )

Definition at line 107 of file proto.c.

References is_ipv_X().

Referenced by process_ip_header().

◆ is_ipv6()

bool is_ipv6 ( int tunnel_type,
struct buffer * buf )

Definition at line 112 of file proto.c.

References is_ipv_X().

Referenced by ipv6_send_icmp_unreachable(), and process_ip_header().