kernel-netlink: Pass protocol specific enum names to socket constructor

This avoid the hard dependency on enum names, and makes kernel_netlink_shared
independent of kernel_netlink_ipsec.
This commit is contained in:
Martin Willi 2014-07-10 14:21:20 +02:00
parent 5957e76b38
commit c94e93a7ab
4 changed files with 14 additions and 13 deletions

View 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);

View 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),

View File

@ -45,15 +45,15 @@ struct private_netlink_socket_t {
*/
int seq;
/**
* netlink socket protocol
*/
int protocol;
/**
* netlink socket
*/
int socket;
/**
* Enum names for Netlink messages
*/
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)

View File

@ -65,8 +65,9 @@ struct netlink_socket_t {
* Create a netlink_socket_t object.
*
* @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.