not using %m printf handler, as late errno interpration over bus may be problematic
This commit is contained in:
@@ -1426,7 +1426,7 @@ static void stroke_process(private_stroke_interface_t *this, int strokefd)
|
|||||||
bytes_read = recv(strokefd, msg, msg_length, 0);
|
bytes_read = recv(strokefd, msg, msg_length, 0);
|
||||||
if (bytes_read != msg_length)
|
if (bytes_read != msg_length)
|
||||||
{
|
{
|
||||||
DBG1(DBG_CFG, "reading stroke message failed: %m");
|
DBG1(DBG_CFG, "reading stroke message failed: %s", strerror(errno));
|
||||||
close(strokefd);
|
close(strokefd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1434,7 +1434,7 @@ static void stroke_process(private_stroke_interface_t *this, int strokefd)
|
|||||||
out = fdopen(dup(strokefd), "w");
|
out = fdopen(dup(strokefd), "w");
|
||||||
if (out == NULL)
|
if (out == NULL)
|
||||||
{
|
{
|
||||||
DBG1(DBG_CFG, "opening stroke output channel failed: %m");
|
DBG1(DBG_CFG, "opening stroke output channel failed: %s", strerror(errno));
|
||||||
close(strokefd);
|
close(strokefd);
|
||||||
free(msg);
|
free(msg);
|
||||||
return;
|
return;
|
||||||
@@ -1520,7 +1520,7 @@ static void stroke_receive(private_stroke_interface_t *this)
|
|||||||
|
|
||||||
if (strokefd < 0)
|
if (strokefd < 0)
|
||||||
{
|
{
|
||||||
DBG1(DBG_CFG, "accepting stroke connection failed: %m");
|
DBG1(DBG_CFG, "accepting stroke connection failed: %s", strerror(errno));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
stroke_process(this, strokefd);
|
stroke_process(this, strokefd);
|
||||||
@@ -1571,7 +1571,7 @@ stroke_t *stroke_create(local_backend_t *backend)
|
|||||||
old = umask(~S_IRWXU);
|
old = umask(~S_IRWXU);
|
||||||
if (bind(this->socket, (struct sockaddr *)&socket_addr, sizeof(socket_addr)) < 0)
|
if (bind(this->socket, (struct sockaddr *)&socket_addr, sizeof(socket_addr)) < 0)
|
||||||
{
|
{
|
||||||
DBG1(DBG_CFG, "could not bind stroke socket: %m");
|
DBG1(DBG_CFG, "could not bind stroke socket: %s", strerror(errno));
|
||||||
close(this->socket);
|
close(this->socket);
|
||||||
free(this);
|
free(this);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -1580,7 +1580,7 @@ stroke_t *stroke_create(local_backend_t *backend)
|
|||||||
|
|
||||||
if (listen(this->socket, 0) < 0)
|
if (listen(this->socket, 0) < 0)
|
||||||
{
|
{
|
||||||
DBG1(DBG_CFG, "could not listen on stroke socket: %m");
|
DBG1(DBG_CFG, "could not listen on stroke socket: %s", strerror(errno));
|
||||||
close(this->socket);
|
close(this->socket);
|
||||||
unlink(socket_addr.sun_path);
|
unlink(socket_addr.sun_path);
|
||||||
free(this);
|
free(this);
|
||||||
|
|||||||
@@ -571,7 +571,7 @@ static status_t netlink_send(int socket, struct nlmsghdr *in,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&mutex);
|
pthread_mutex_unlock(&mutex);
|
||||||
DBG1(DBG_KNL, "error sending to netlink socket: %m");
|
DBG1(DBG_KNL, "error sending to netlink socket: %s", strerror(errno));
|
||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -601,7 +601,7 @@ static status_t netlink_send(int socket, struct nlmsghdr *in,
|
|||||||
/* interrupted, try again */
|
/* interrupted, try again */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
DBG1(DBG_IKE, "error reading from netlink socket: %m");
|
DBG1(DBG_IKE, "error reading from netlink socket: %s", strerror(errno));
|
||||||
pthread_mutex_unlock(&mutex);
|
pthread_mutex_unlock(&mutex);
|
||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-13
@@ -176,7 +176,7 @@ static status_t receiver(private_socket_t *this, packet_t **packet)
|
|||||||
bytes_read = recv(this->recv4, buffer, MAX_PACKET, 0);
|
bytes_read = recv(this->recv4, buffer, MAX_PACKET, 0);
|
||||||
if (bytes_read < 0)
|
if (bytes_read < 0)
|
||||||
{
|
{
|
||||||
DBG1(DBG_NET, "error reading from IPv4 socket: %m");
|
DBG1(DBG_NET, "error reading from IPv4 socket: %s", strerror(errno));
|
||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
DBG3(DBG_NET, "received IPv4 packet %b", buffer, bytes_read);
|
DBG3(DBG_NET, "received IPv4 packet %b", buffer, bytes_read);
|
||||||
@@ -238,7 +238,7 @@ static status_t receiver(private_socket_t *this, packet_t **packet)
|
|||||||
bytes_read = recvmsg(this->recv6, &msg, 0);
|
bytes_read = recvmsg(this->recv6, &msg, 0);
|
||||||
if (bytes_read < 0)
|
if (bytes_read < 0)
|
||||||
{
|
{
|
||||||
DBG1(DBG_NET, "error reading from IPv6 socket: %m");
|
DBG1(DBG_NET, "error reading from IPv6 socket: %s", strerror(errno));
|
||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
DBG3(DBG_NET, "received IPv6 packet %b", buffer, bytes_read);
|
DBG3(DBG_NET, "received IPv6 packet %b", buffer, bytes_read);
|
||||||
@@ -428,7 +428,7 @@ status_t sender(private_socket_t *this, packet_t *packet)
|
|||||||
|
|
||||||
if (bytes_sent != data.len)
|
if (bytes_sent != data.len)
|
||||||
{
|
{
|
||||||
DBG1(DBG_NET, "error writing to socket: %m");
|
DBG1(DBG_NET, "error writing to socket: %s", strerror(errno));
|
||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
@@ -477,13 +477,14 @@ static int open_send_socket(private_socket_t *this, int family, u_int16_t port)
|
|||||||
skt = socket(family, SOCK_DGRAM, IPPROTO_UDP);
|
skt = socket(family, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
if (skt < 0)
|
if (skt < 0)
|
||||||
{
|
{
|
||||||
DBG1(DBG_NET, "could not open send socket: %m");
|
DBG1(DBG_NET, "could not open send socket: %s", strerror(errno));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setsockopt(skt, SOL_SOCKET, SO_REUSEADDR, (void*)&on, sizeof(on)) < 0)
|
if (setsockopt(skt, SOL_SOCKET, SO_REUSEADDR, (void*)&on, sizeof(on)) < 0)
|
||||||
{
|
{
|
||||||
DBG1(DBG_NET, "unable to set SO_REUSEADDR on send socket: %m");
|
DBG1(DBG_NET, "unable to set SO_REUSEADDR on send socket: %s",
|
||||||
|
strerror(errno));
|
||||||
close(skt);
|
close(skt);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -497,7 +498,8 @@ static int open_send_socket(private_socket_t *this, int family, u_int16_t port)
|
|||||||
|
|
||||||
if (setsockopt(skt, sol, ipsec_policy, &policy, sizeof(policy)) < 0)
|
if (setsockopt(skt, sol, ipsec_policy, &policy, sizeof(policy)) < 0)
|
||||||
{
|
{
|
||||||
DBG1(DBG_NET, "unable to set IPSEC_POLICY on send socket: %m");
|
DBG1(DBG_NET, "unable to set IPSEC_POLICY on send socket: %s",
|
||||||
|
strerror(errno));
|
||||||
close(skt);
|
close(skt);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -507,7 +509,8 @@ static int open_send_socket(private_socket_t *this, int family, u_int16_t port)
|
|||||||
policy.sadb_x_policy_dir = IPSEC_DIR_INBOUND;
|
policy.sadb_x_policy_dir = IPSEC_DIR_INBOUND;
|
||||||
if (setsockopt(skt, sol, ipsec_policy, &policy, sizeof(policy)) < 0)
|
if (setsockopt(skt, sol, ipsec_policy, &policy, sizeof(policy)) < 0)
|
||||||
{
|
{
|
||||||
DBG1(DBG_NET, "unable to set IPSEC_POLICY on send socket: %m");
|
DBG1(DBG_NET, "unable to set IPSEC_POLICY on send socket: %s",
|
||||||
|
strerror(errno));
|
||||||
close(skt);
|
close(skt);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -515,7 +518,8 @@ static int open_send_socket(private_socket_t *this, int family, u_int16_t port)
|
|||||||
/* bind the send socket */
|
/* bind the send socket */
|
||||||
if (bind(skt, (struct sockaddr *)&addr, sizeof(addr)) < 0)
|
if (bind(skt, (struct sockaddr *)&addr, sizeof(addr)) < 0)
|
||||||
{
|
{
|
||||||
DBG1(DBG_NET, "unable to bind send socket: %m");
|
DBG1(DBG_NET, "unable to bind send socket: %s",
|
||||||
|
strerror(errno));
|
||||||
close(skt);
|
close(skt);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -525,7 +529,8 @@ static int open_send_socket(private_socket_t *this, int family, u_int16_t port)
|
|||||||
/* enable UDP decapsulation globally, only for one socket needed */
|
/* enable UDP decapsulation globally, only for one socket needed */
|
||||||
if (setsockopt(skt, SOL_UDP, UDP_ENCAP, &type, sizeof(type)) < 0)
|
if (setsockopt(skt, SOL_UDP, UDP_ENCAP, &type, sizeof(type)) < 0)
|
||||||
{
|
{
|
||||||
DBG1(DBG_NET, "unable to set UDP_ENCAP: %m; NAT-T may fail");
|
DBG1(DBG_NET, "unable to set UDP_ENCAP: %s; NAT-T may fail",
|
||||||
|
strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -606,14 +611,15 @@ static int open_recv_socket(private_socket_t *this, int family)
|
|||||||
skt = socket(family, SOCK_RAW, IPPROTO_UDP);
|
skt = socket(family, SOCK_RAW, IPPROTO_UDP);
|
||||||
if (skt < 0)
|
if (skt < 0)
|
||||||
{
|
{
|
||||||
DBG1(DBG_NET, "unable to create raw socket: %m");
|
DBG1(DBG_NET, "unable to create raw socket: %s", strerror(errno));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setsockopt(skt, SOL_SOCKET, SO_ATTACH_FILTER,
|
if (setsockopt(skt, SOL_SOCKET, SO_ATTACH_FILTER,
|
||||||
&ikev2_filter, sizeof(ikev2_filter)) < 0)
|
&ikev2_filter, sizeof(ikev2_filter)) < 0)
|
||||||
{
|
{
|
||||||
DBG1(DBG_NET, "unable to attach IKEv2 filter to raw socket: %m");
|
DBG1(DBG_NET, "unable to attach IKEv2 filter to raw socket: %s",
|
||||||
|
strerror(errno));
|
||||||
close(skt);
|
close(skt);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -623,7 +629,8 @@ static int open_recv_socket(private_socket_t *this, int family)
|
|||||||
* 2 or 50 depending on kernel header version */
|
* 2 or 50 depending on kernel header version */
|
||||||
setsockopt(skt, sol, IPV6_2292PKTINFO, &on, sizeof(on)) < 0)
|
setsockopt(skt, sol, IPV6_2292PKTINFO, &on, sizeof(on)) < 0)
|
||||||
{
|
{
|
||||||
DBG1(DBG_NET, "unable to set IPV6_PKTINFO on raw socket: %m");
|
DBG1(DBG_NET, "unable to set IPV6_PKTINFO on raw socket: %s",
|
||||||
|
strerror(errno));
|
||||||
close(skt);
|
close(skt);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -637,7 +644,8 @@ static int open_recv_socket(private_socket_t *this, int family)
|
|||||||
|
|
||||||
if (setsockopt(skt, sol, ipsec_policy, &policy, sizeof(policy)) < 0)
|
if (setsockopt(skt, sol, ipsec_policy, &policy, sizeof(policy)) < 0)
|
||||||
{
|
{
|
||||||
DBG1(DBG_NET, "unable to set IPSEC_POLICY on raw socket: %m");
|
DBG1(DBG_NET, "unable to set IPSEC_POLICY on raw socket: %s",
|
||||||
|
strerror(errno));
|
||||||
close(skt);
|
close(skt);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-7
@@ -26,6 +26,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <printf.h>
|
#include <printf.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include "ike_sa.h"
|
#include "ike_sa.h"
|
||||||
|
|
||||||
@@ -1711,7 +1712,8 @@ static void remove_dns_servers(private_ike_sa_t *this)
|
|||||||
file = fopen(RESOLV_CONF, "r");
|
file = fopen(RESOLV_CONF, "r");
|
||||||
if (file == NULL || stat(RESOLV_CONF, &stats) != 0)
|
if (file == NULL || stat(RESOLV_CONF, &stats) != 0)
|
||||||
{
|
{
|
||||||
DBG1(DBG_IKE, "unable to open DNS configuration file %s: %m", RESOLV_CONF);
|
DBG1(DBG_IKE, "unable to open DNS configuration file %s: %s",
|
||||||
|
RESOLV_CONF, strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1719,7 +1721,7 @@ static void remove_dns_servers(private_ike_sa_t *this)
|
|||||||
|
|
||||||
if (fread(contents.ptr, 1, contents.len, file) != contents.len)
|
if (fread(contents.ptr, 1, contents.len, file) != contents.len)
|
||||||
{
|
{
|
||||||
DBG1(DBG_IKE, "unable to read DNS configuration file: %m");
|
DBG1(DBG_IKE, "unable to read DNS configuration file: %s", strerror(errno));
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1728,7 +1730,8 @@ static void remove_dns_servers(private_ike_sa_t *this)
|
|||||||
file = fopen(RESOLV_CONF, "w");
|
file = fopen(RESOLV_CONF, "w");
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
{
|
{
|
||||||
DBG1(DBG_IKE, "unable to open DNS configuration file %s: %m", RESOLV_CONF);
|
DBG1(DBG_IKE, "unable to open DNS configuration file %s: %s",
|
||||||
|
RESOLV_CONF, strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1784,7 +1787,8 @@ static void add_dns_server(private_ike_sa_t *this, host_t *dns)
|
|||||||
file = fopen(RESOLV_CONF, "a+");
|
file = fopen(RESOLV_CONF, "a+");
|
||||||
if (file == NULL || stat(RESOLV_CONF, &stats) != 0)
|
if (file == NULL || stat(RESOLV_CONF, &stats) != 0)
|
||||||
{
|
{
|
||||||
DBG1(DBG_IKE, "unable to open DNS configuration file %s: %m", RESOLV_CONF);
|
DBG1(DBG_IKE, "unable to open DNS configuration file %s: %s",
|
||||||
|
RESOLV_CONF, strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1792,7 +1796,7 @@ static void add_dns_server(private_ike_sa_t *this, host_t *dns)
|
|||||||
|
|
||||||
if (fread(contents.ptr, 1, contents.len, file) != contents.len)
|
if (fread(contents.ptr, 1, contents.len, file) != contents.len)
|
||||||
{
|
{
|
||||||
DBG1(DBG_IKE, "unable to read DNS configuration file: %m");
|
DBG1(DBG_IKE, "unable to read DNS configuration file: %s", strerror(errno));
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1801,14 +1805,15 @@ static void add_dns_server(private_ike_sa_t *this, host_t *dns)
|
|||||||
file = fopen(RESOLV_CONF, "w");
|
file = fopen(RESOLV_CONF, "w");
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
{
|
{
|
||||||
DBG1(DBG_IKE, "unable to open DNS configuration file %s: %m", RESOLV_CONF);
|
DBG1(DBG_IKE, "unable to open DNS configuration file %s: %s",
|
||||||
|
RESOLV_CONF, strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fprintf(file, "nameserver %H # added by strongSwan, assigned by %D\n",
|
if (fprintf(file, "nameserver %H # added by strongSwan, assigned by %D\n",
|
||||||
dns, this->other_id) < 0)
|
dns, this->other_id) < 0)
|
||||||
{
|
{
|
||||||
DBG1(DBG_IKE, "unable to write DNS configuration: %m");
|
DBG1(DBG_IKE, "unable to write DNS configuration: %s", strerror(errno));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user