Let kernel interfaces decide how to enable UDP decapsulation of ESP packets.
This commit is contained in:
@@ -108,12 +108,6 @@ METHOD(kernel_ipsec_t, del_policy, status_t,
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
METHOD(kernel_ipsec_t, bypass_socket, bool,
|
||||
private_load_tester_ipsec_t *this, int fd, int family)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(kernel_ipsec_t, destroy, void,
|
||||
private_load_tester_ipsec_t *this)
|
||||
{
|
||||
@@ -141,7 +135,8 @@ load_tester_ipsec_t *load_tester_ipsec_create()
|
||||
.query_policy = _query_policy,
|
||||
.del_policy = _del_policy,
|
||||
.flush_policies = (void*)return_failed,
|
||||
.bypass_socket = _bypass_socket,
|
||||
.bypass_socket = (void*)return_true,
|
||||
.enable_udp_decap = (void*)return_true,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -40,9 +40,6 @@
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <net/if.h>
|
||||
#ifdef __APPLE__
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
#include <hydra.h>
|
||||
#include <daemon.h>
|
||||
@@ -54,15 +51,6 @@
|
||||
/* length of non-esp marker */
|
||||
#define MARKER_LEN sizeof(u_int32_t)
|
||||
|
||||
/* from linux/udp.h */
|
||||
#ifndef UDP_ENCAP
|
||||
#define UDP_ENCAP 100
|
||||
#endif /*UDP_ENCAP*/
|
||||
|
||||
#ifndef UDP_ENCAP_ESPINUDP
|
||||
#define UDP_ENCAP_ESPINUDP 2
|
||||
#endif /*UDP_ENCAP_ESPINUDP*/
|
||||
|
||||
/* these are not defined on some platforms */
|
||||
#ifndef SOL_IP
|
||||
#define SOL_IP IPPROTO_IP
|
||||
@@ -70,9 +58,6 @@
|
||||
#ifndef SOL_IPV6
|
||||
#define SOL_IPV6 IPPROTO_IPV6
|
||||
#endif
|
||||
#ifndef SOL_UDP
|
||||
#define SOL_UDP IPPROTO_UDP
|
||||
#endif
|
||||
|
||||
/* IPV6_RECVPKTINFO is defined in RFC 3542 which obsoletes RFC 2292 that
|
||||
* previously defined IPV6_PKTINFO */
|
||||
@@ -513,17 +498,14 @@ static int open_socket(private_socket_default_socket_t *this,
|
||||
DBG1(DBG_NET, "installing IKE bypass policy failed");
|
||||
}
|
||||
|
||||
#ifndef __APPLE__
|
||||
/* enable UDP decapsulation globally, only for one socket needed */
|
||||
if (family == AF_INET && port == CHARON_NATT_PORT &&
|
||||
!hydra->kernel_interface->enable_udp_decap(hydra->kernel_interface,
|
||||
skt, family, port))
|
||||
{
|
||||
/* enable UDP decapsulation globally, only for one socket needed */
|
||||
int type = UDP_ENCAP_ESPINUDP;
|
||||
if (family == AF_INET && port == CHARON_NATT_PORT &&
|
||||
setsockopt(skt, SOL_UDP, UDP_ENCAP, &type, sizeof(type)) < 0)
|
||||
{
|
||||
DBG1(DBG_NET, "unable to set UDP_ENCAP: %s", strerror(errno));
|
||||
}
|
||||
DBG1(DBG_NET, "enabling UDP decapsulation failed");
|
||||
}
|
||||
#endif
|
||||
|
||||
return skt;
|
||||
}
|
||||
|
||||
@@ -568,18 +550,6 @@ socket_default_socket_t *socket_default_socket_create()
|
||||
"%s.max_packet", MAX_PACKET, charon->name),
|
||||
);
|
||||
|
||||
#ifdef __APPLE__
|
||||
{
|
||||
int natt_port = CHARON_NATT_PORT;
|
||||
if (sysctlbyname("net.inet.ipsec.esp_port", NULL, NULL, &natt_port,
|
||||
sizeof(natt_port)) != 0)
|
||||
{
|
||||
DBG1(DBG_NET, "could not set net.inet.ipsec.esp_port to %d: %s",
|
||||
natt_port, strerror(errno));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
this->ipv4 = open_socket(this, AF_INET, CHARON_UDP_PORT);
|
||||
if (this->ipv4 == 0)
|
||||
{
|
||||
|
||||
@@ -48,15 +48,6 @@
|
||||
/* length of non-esp marker */
|
||||
#define MARKER_LEN sizeof(u_int32_t)
|
||||
|
||||
/* from linux/udp.h */
|
||||
#ifndef UDP_ENCAP
|
||||
#define UDP_ENCAP 100
|
||||
#endif /*UDP_ENCAP*/
|
||||
|
||||
#ifndef UDP_ENCAP_ESPINUDP
|
||||
#define UDP_ENCAP_ESPINUDP 2
|
||||
#endif /*UDP_ENCAP_ESPINUDP*/
|
||||
|
||||
/* these are not defined on some platforms */
|
||||
#ifndef SOL_IP
|
||||
#define SOL_IP IPPROTO_IP
|
||||
@@ -64,9 +55,6 @@
|
||||
#ifndef SOL_IPV6
|
||||
#define SOL_IPV6 IPPROTO_IPV6
|
||||
#endif
|
||||
#ifndef SOL_UDP
|
||||
#define SOL_UDP IPPROTO_UDP
|
||||
#endif
|
||||
|
||||
/* IPV6_RECVPKTINFO is defined in RFC 3542 which obsoletes RFC 2292 that
|
||||
* previously defined IPV6_PKTINFO */
|
||||
@@ -352,7 +340,7 @@ METHOD(socket_t, receiver, status_t,
|
||||
static int open_socket(private_socket_dynamic_socket_t *this,
|
||||
int family, u_int16_t port)
|
||||
{
|
||||
int on = TRUE, type = UDP_ENCAP_ESPINUDP;
|
||||
int on = TRUE;
|
||||
struct sockaddr_storage addr;
|
||||
socklen_t addrlen;
|
||||
u_int sol, pktinfo = 0;
|
||||
@@ -424,10 +412,12 @@ static int open_socket(private_socket_dynamic_socket_t *this,
|
||||
}
|
||||
|
||||
/* enable UDP decapsulation on each socket */
|
||||
if (setsockopt(fd, SOL_UDP, UDP_ENCAP, &type, sizeof(type)) < 0)
|
||||
if (!hydra->kernel_interface->enable_udp_decap(hydra->kernel_interface,
|
||||
fd, family, port))
|
||||
{
|
||||
DBG1(DBG_NET, "unable to set UDP_ENCAP: %s", strerror(errno));
|
||||
DBG1(DBG_NET, "enabling UDP decapsulation failed");
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,15 +55,6 @@
|
||||
#define IKE_VERSION_OFFSET 17
|
||||
#define IKE_LENGTH_OFFSET 24
|
||||
|
||||
/* from linux/udp.h */
|
||||
#ifndef UDP_ENCAP
|
||||
#define UDP_ENCAP 100
|
||||
#endif /*UDP_ENCAP*/
|
||||
|
||||
#ifndef UDP_ENCAP_ESPINUDP
|
||||
#define UDP_ENCAP_ESPINUDP 2
|
||||
#endif /*UDP_ENCAP_ESPINUDP*/
|
||||
|
||||
/* needed for older kernel headers */
|
||||
#ifndef IPV6_2292PKTINFO
|
||||
#define IPV6_2292PKTINFO 2
|
||||
@@ -412,7 +403,6 @@ static int open_send_socket(private_socket_raw_socket_t *this,
|
||||
int family, u_int16_t port)
|
||||
{
|
||||
int on = TRUE;
|
||||
int type = UDP_ENCAP_ESPINUDP;
|
||||
struct sockaddr_storage addr;
|
||||
int skt;
|
||||
|
||||
@@ -463,22 +453,20 @@ static int open_send_socket(private_socket_raw_socket_t *this,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (family == AF_INET)
|
||||
{
|
||||
/* enable UDP decapsulation globally, only for one socket needed */
|
||||
if (setsockopt(skt, SOL_UDP, UDP_ENCAP, &type, sizeof(type)) < 0)
|
||||
{
|
||||
DBG1(DBG_NET, "unable to set UDP_ENCAP: %s; NAT-T may fail",
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
if (!hydra->kernel_interface->bypass_socket(hydra->kernel_interface,
|
||||
skt, family))
|
||||
{
|
||||
DBG1(DBG_NET, "installing bypass policy on send socket failed");
|
||||
}
|
||||
|
||||
/* enable UDP decapsulation globally, only for one socket needed */
|
||||
if (family == AF_INET && port == CHARON_NATT_PORT &&
|
||||
!hydra->kernel_interface->enable_udp_decap(hydra->kernel_interface,
|
||||
skt, family, port))
|
||||
{
|
||||
DBG1(DBG_NET, "enabling UDP decapsulation failed");
|
||||
}
|
||||
|
||||
return skt;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user