77 lines
2.1 KiB
C
77 lines
2.1 KiB
C
/*
|
|
*
|
|
* 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;
|
|
}
|