kernel-netlink: Provide error information for Netlink sockets
authorTobias Brunner <tobias@strongswan.org>
Fri, 27 May 2016 11:43:41 +0000 (13:43 +0200)
committerTobias Brunner <tobias@strongswan.org>
Fri, 10 Jun 2016 08:34:09 +0000 (10:34 +0200)
 #1467.

src/libcharon/plugins/kernel_netlink/kernel_netlink_ipsec.c
src/libcharon/plugins/kernel_netlink/kernel_netlink_net.c
src/libcharon/plugins/kernel_netlink/kernel_netlink_shared.c

index d40264a..fbeff91 100644 (file)
@@ -1081,7 +1081,8 @@ static bool receive_events(private_kernel_netlink_ipsec_t *this, int fd,
                                /* no data ready, select again */
                                return TRUE;
                        default:
-                               DBG1(DBG_KNL, "unable to receive from xfrm event socket");
+                               DBG1(DBG_KNL, "unable to receive from XFRM event socket: %s "
+                                        "(%d)", strerror(errno), errno);
                                sleep(1);
                                return TRUE;
                }
@@ -1109,8 +1110,8 @@ static bool receive_events(private_kernel_netlink_ipsec_t *this, int fd,
                                process_mapping(this, hdr);
                                break;
                        default:
-                               DBG1(DBG_KNL, "received unknown event from xfrm event "
-                                                         "socket: %d", hdr->nlmsg_type);
+                               DBG1(DBG_KNL, "received unknown event from XFRM event "
+                                        "socket: %d", hdr->nlmsg_type);
                                break;
                }
                hdr = NLMSG_NEXT(hdr, len);
@@ -1678,8 +1679,7 @@ static void get_replay_state(private_kernel_netlink_ipsec_t *this,
                                {
                                        struct nlmsgerr *err = NLMSG_DATA(hdr);
                                        DBG1(DBG_KNL, "querying replay state from SAD entry "
-                                                                 "failed: %s (%d)", strerror(-err->error),
-                                                                 -err->error);
+                                                "failed: %s (%d)", strerror(-err->error), -err->error);
                                        break;
                                }
                                default:
@@ -2359,9 +2359,8 @@ static status_t add_policy_internal(private_kernel_netlink_ipsec_t *this,
                                                                                old->src_ip, old->if_name) != SUCCESS)
                                {
                                        DBG1(DBG_KNL, "error uninstalling route installed with "
-                                                                 "policy %R === %R %N", in->src_ts,
-                                                                  in->dst_ts, policy_dir_names,
-                                                                  policy->direction);
+                                                "policy %R === %R %N", in->src_ts, in->dst_ts,
+                                                policy_dir_names, policy->direction);
                                }
                                route_entry_destroy(old);
                                policy->route = NULL;
@@ -2787,15 +2786,15 @@ static bool add_socket_bypass(private_kernel_netlink_ipsec_t *this,
        policy.dir = XFRM_POLICY_OUT;
        if (setsockopt(fd, sol, ipsec_policy, &policy, sizeof(policy)) < 0)
        {
-               DBG1(DBG_KNL, "unable to set IPSEC_POLICY on socket: %s",
-                                          strerror(errno));
+               DBG1(DBG_KNL, "unable to set IPSEC_POLICY on socket: %s (%d)",
+                        strerror(errno), errno);
                return FALSE;
        }
        policy.dir = XFRM_POLICY_IN;
        if (setsockopt(fd, sol, ipsec_policy, &policy, sizeof(policy)) < 0)
        {
-               DBG1(DBG_KNL, "unable to set IPSEC_POLICY on socket: %s",
-                                          strerror(errno));
+               DBG1(DBG_KNL, "unable to set IPSEC_POLICY on socket: %s (%d)",
+                        strerror(errno), errno);
                return FALSE;
        }
        return TRUE;
@@ -3068,7 +3067,8 @@ kernel_netlink_ipsec_t *kernel_netlink_ipsec_create()
                this->socket_xfrm_events = socket(AF_NETLINK, SOCK_RAW, NETLINK_XFRM);
                if (this->socket_xfrm_events <= 0)
                {
-                       DBG1(DBG_KNL, "unable to create XFRM event socket");
+                       DBG1(DBG_KNL, "unable to create XFRM event socket: %s (%d)",
+                                strerror(errno), errno);
                        destroy(this);
                        return NULL;
                }
@@ -3076,7 +3076,8 @@ kernel_netlink_ipsec_t *kernel_netlink_ipsec_create()
                                                 XFRMNLGRP(MIGRATE) | XFRMNLGRP(MAPPING);
                if (bind(this->socket_xfrm_events, (struct sockaddr*)&addr, sizeof(addr)))
                {
-                       DBG1(DBG_KNL, "unable to bind XFRM event socket");
+                       DBG1(DBG_KNL, "unable to bind XFRM event socket: %s (%d)",
+                                strerror(errno), errno);
                        destroy(this);
                        return NULL;
                }
index 426ddde..bde0e77 100644 (file)
@@ -1297,7 +1297,8 @@ static bool receive_events(private_kernel_netlink_net_t *this, int fd,
                                /* no data ready, select again */
                                return TRUE;
                        default:
-                               DBG1(DBG_KNL, "unable to receive from rt event socket");
+                               DBG1(DBG_KNL, "unable to receive from RT event socket %s (%d)",
+                                        strerror(errno), errno);
                                sleep(1);
                                return TRUE;
                }
@@ -2644,7 +2645,8 @@ kernel_netlink_net_t *kernel_netlink_net_create()
                this->socket_events = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
                if (this->socket_events < 0)
                {
-                       DBG1(DBG_KNL, "unable to create RT event socket");
+                       DBG1(DBG_KNL, "unable to create RT event socket: %s (%d)",
+                                strerror(errno), errno);
                        destroy(this);
                        return NULL;
                }
@@ -2652,7 +2654,8 @@ kernel_netlink_net_t *kernel_netlink_net_create()
                                                 RTMGRP_IPV4_ROUTE | RTMGRP_IPV6_ROUTE | RTMGRP_LINK;
                if (bind(this->socket_events, (struct sockaddr*)&addr, sizeof(addr)))
                {
-                       DBG1(DBG_KNL, "unable to bind RT event socket");
+                       DBG1(DBG_KNL, "unable to bind RT event socket: %s (%d)",
+                                strerror(errno), errno);
                        destroy(this);
                        return NULL;
                }
index 0e49987..7165b65 100644 (file)
@@ -594,13 +594,15 @@ netlink_socket_t *netlink_socket_create(int protocol, enum_name_t *names,
        }
        if (this->socket == -1)
        {
-               DBG1(DBG_KNL, "unable to create netlink socket");
+               DBG1(DBG_KNL, "unable to create netlink socket: %s (%d)",
+                        strerror(errno), errno);
                destroy(this);
                return NULL;
        }
        if (bind(this->socket, (struct sockaddr*)&addr, sizeof(addr)))
        {
-               DBG1(DBG_KNL, "unable to bind netlink socket");
+               DBG1(DBG_KNL, "unable to bind netlink socket: %s (%d)",
+                        strerror(errno), errno);
                destroy(this);
                return NULL;
        }