kernel-netlink: Pass protocol specific enum names to socket constructor
authorMartin Willi <martin@revosec.ch>
Thu, 10 Jul 2014 12:21:20 +0000 (14:21 +0200)
committerMartin Willi <martin@revosec.ch>
Wed, 24 Sep 2014 09:19:59 +0000 (11:19 +0200)
This avoid the hard dependency on enum names, and makes kernel_netlink_shared
independent of kernel_netlink_ipsec.

src/libhydra/plugins/kernel_netlink/kernel_netlink_ipsec.c
src/libhydra/plugins/kernel_netlink/kernel_netlink_net.c
src/libhydra/plugins/kernel_netlink/kernel_netlink_shared.c
src/libhydra/plugins/kernel_netlink/kernel_netlink_shared.h

index cd94168..dfd71f3 100644 (file)
@@ -2711,7 +2711,7 @@ kernel_netlink_ipsec_t *kernel_netlink_ipsec_create()
                fclose(f);
        }
 
-       this->socket_xfrm = netlink_socket_create(NETLINK_XFRM);
+       this->socket_xfrm = netlink_socket_create(NETLINK_XFRM, xfrm_msg_names);
        if (!this->socket_xfrm)
        {
                destroy(this);
index 3d5538c..e8d146c 100644 (file)
@@ -2469,7 +2469,7 @@ kernel_netlink_net_t *kernel_netlink_net_create()
                                .destroy = _destroy,
                        },
                },
-               .socket = netlink_socket_create(NETLINK_ROUTE),
+               .socket = netlink_socket_create(NETLINK_ROUTE, NULL),
                .rt_exclude = linked_list_create(),
                .routes = hashtable_create((hashtable_hash_t)route_entry_hash,
                                                                   (hashtable_equals_t)route_entry_equals, 16),
index 74466e2..b4cece7 100644 (file)
@@ -46,14 +46,14 @@ struct private_netlink_socket_t {
        int seq;
 
        /**
-        * netlink socket protocol
+        * netlink socket
         */
-       int protocol;
+       int socket;
 
        /**
-        * netlink socket
+        * Enum names for Netlink messages
         */
-       int socket;
+       enum_name_t *names;
 };
 
 /**
@@ -83,10 +83,10 @@ METHOD(netlink_socket_t, netlink_send, status_t,
        addr.nl_pid = 0;
        addr.nl_groups = 0;
 
-       if (this->protocol == NETLINK_XFRM)
+       if (this->names)
        {
                DBG3(DBG_KNL, "sending %N: %b",
-                        xfrm_msg_names, in->nlmsg_type, in, in->nlmsg_len);
+                        this->names, in->nlmsg_type, in, in->nlmsg_len);
        }
        while (TRUE)
        {
@@ -230,7 +230,7 @@ METHOD(netlink_socket_t, destroy, void,
 /**
  * Described in header.
  */
-netlink_socket_t *netlink_socket_create(int protocol)
+netlink_socket_t *netlink_socket_create(int protocol, enum_name_t *names)
 {
        private_netlink_socket_t *this;
        struct sockaddr_nl addr = {
@@ -246,7 +246,7 @@ netlink_socket_t *netlink_socket_create(int protocol)
                .seq = 200,
                .mutex = mutex_create(MUTEX_TYPE_DEFAULT),
                .socket = socket(AF_NETLINK, SOCK_RAW, protocol),
-               .protocol = protocol,
+               .names = names,
        );
 
        if (this->socket == -1)
index 1a03a89..069f746 100644 (file)
@@ -64,9 +64,10 @@ struct netlink_socket_t {
 /**
  * Create a netlink_socket_t object.
  *
- * @param      protocol        protocol type (e.g. NETLINK_XFRM or NETLINK_ROUTE)
+ * @param protocol     protocol type (e.g. NETLINK_XFRM or NETLINK_ROUTE)
+ * @param names                optional enum names for Netlink messages
  */
-netlink_socket_t *netlink_socket_create(int protocol);
+netlink_socket_t *netlink_socket_create(int protocol, enum_name_t *names);
 
 /**
  * Creates an rtattr and adds it to the given netlink message.