mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2025-01-03 10:32:33 +01:00
rtnlutil: Introduce rtnl utility
The rtnl utility will encapsulate a collection of functions for rtnl ops.
This commit is contained in:
parent
b0ef0a79a8
commit
5104e6752f
@ -204,6 +204,7 @@ src_iwd_SOURCES = src/main.c linux/nl80211.h src/iwd.h src/missing.h \
|
||||
src/manager.c \
|
||||
src/erp.h src/erp.c \
|
||||
src/fils.h src/fils.c \
|
||||
src/rtnutil.h src/rtnlutil.c \
|
||||
$(eap_sources) \
|
||||
$(builtin_sources)
|
||||
src_iwd_LDADD = $(ell_ldadd) -ldl
|
||||
|
76
src/rtnlutil.c
Normal file
76
src/rtnlutil.c
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
*
|
||||
* Wireless daemon for Linux
|
||||
*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
|
||||
#include <ell/ell.h>
|
||||
|
||||
#include "src/rtnlutil.h"
|
||||
|
||||
static size_t rta_add_u8(void *rta_buf, unsigned short type, uint8_t value)
|
||||
{
|
||||
struct rtattr *rta = rta_buf;
|
||||
|
||||
rta->rta_len = RTA_LENGTH(sizeof(uint8_t));
|
||||
rta->rta_type = type;
|
||||
*((uint8_t *) RTA_DATA(rta)) = value;
|
||||
|
||||
return RTA_SPACE(sizeof(uint8_t));
|
||||
}
|
||||
|
||||
uint32_t rtnl_set_linkmode_and_operstate(struct l_netlink *rtnl, int ifindex,
|
||||
uint8_t linkmode, uint8_t operstate,
|
||||
l_netlink_command_func_t cb,
|
||||
void *user_data,
|
||||
l_netlink_destroy_func_t destroy)
|
||||
{
|
||||
struct ifinfomsg *rtmmsg;
|
||||
void *rta_buf;
|
||||
size_t bufsize;
|
||||
uint32_t id;
|
||||
|
||||
bufsize = NLMSG_ALIGN(sizeof(struct ifinfomsg)) +
|
||||
RTA_SPACE(sizeof(uint8_t)) + RTA_SPACE(sizeof(uint8_t));
|
||||
|
||||
rtmmsg = l_malloc(bufsize);
|
||||
memset(rtmmsg, 0, bufsize);
|
||||
|
||||
rtmmsg->ifi_family = AF_UNSPEC;
|
||||
rtmmsg->ifi_index = ifindex;
|
||||
|
||||
rta_buf = (void *) rtmmsg + NLMSG_ALIGN(sizeof(struct ifinfomsg));
|
||||
|
||||
rta_buf += rta_add_u8(rta_buf, IFLA_LINKMODE, linkmode);
|
||||
rta_buf += rta_add_u8(rta_buf, IFLA_OPERSTATE, operstate);
|
||||
|
||||
id = l_netlink_send(rtnl, RTM_SETLINK, 0, rtmmsg,
|
||||
rta_buf - (void *) rtmmsg,
|
||||
cb, user_data, destroy);
|
||||
l_free(rtmmsg);
|
||||
|
||||
return id;
|
||||
}
|
27
src/rtnlutil.h
Normal file
27
src/rtnlutil.h
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
*
|
||||
* Wireless daemon for Linux
|
||||
*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
uint32_t rtnl_set_linkmode_and_operstate(struct l_netlink *rtnl, int ifindex,
|
||||
uint8_t linkmode, uint8_t operstate,
|
||||
l_netlink_command_func_t cb,
|
||||
void *user_data,
|
||||
l_netlink_destroy_func_t destroy);
|
Loading…
Reference in New Issue
Block a user