commit 5104e6752fdc2883463d815559f800cf2ad65095
parent b0ef0a79a8e63744281297cf7cbd65f65bad587d
Author: Tim Kourt <tim.a.kourt@linux.intel.com>
Date: Mon, 6 May 2019 11:17:52 -0700
rtnlutil: Introduce rtnl utility
The rtnl utility will encapsulate a collection of functions for rtnl ops.
Diffstat:
3 files changed, 104 insertions(+), 0 deletions(-)
diff --git a/Makefile.am b/Makefile.am
@@ -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
diff --git a/src/rtnlutil.c b/src/rtnlutil.c
@@ -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;
+}
diff --git a/src/rtnlutil.h b/src/rtnlutil.h
@@ -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);