Send connman mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        https://lists.01.org/mailman/listinfo/connman
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of connman digest..."


Today's Topics:

   1. [PATCH v0 0/9] Add initial WireGuard support (Daniel Wagner)
   2. [PATCH v0 1/9] include: Remove unused definition (Daniel Wagner)
   3. [PATCH v0 3/9] build: Test for libmnl independent of nftables
      (Daniel Wagner)
   4. [PATCH v0 4/9] vpn: Add WireGuard plugin placeholder
      (Daniel Wagner)
   5. [PATCH v0 2/9] shared: Remove netlink code (Daniel Wagner)


----------------------------------------------------------------------

Message: 1
Date: Fri, 19 Jul 2019 13:21:29 +0200
From: Daniel Wagner <[email protected]>
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Subject: [PATCH v0 0/9] Add initial WireGuard support
Message-ID: <[email protected]>

Add WireGuard support to the VPN daemon. It's a minimalistic approach,
meaning not all features are yet supported. The option parser is for
sure not ready yet.

The main feature of WireGuard is the builtin roaming support. This
doesn't work yet. We need to teach ConnMan to handle
this. Unfortunatly, it is not straight forward. The main issue is
getting the routing table updated when a new transport comes up. I
have a dirty patch which teaches ConnMan not to tear down the
WireGuard tunnel when the transport goes away but as I said it is
useless until the routing table is updated correctly.

Daniel Wagner (9):
  include: Remove unused definition
  shared: Remove netlink code
  build: Test for libmnl independent of nftables
  vpn: Add WireGuard plugin placeholder
  shared: Add Generic Netlink helpers for libmnl
  vpn: Add embeddable WireGuard library
  vpn: Introduce VPN_FLAG_NO_DAEMON
  vpn: Add WireGuard support
  doc: Document WireGuard VPN plugin

 Makefile.am                |  13 +-
 Makefile.plugins           |  25 +
 configure.ac               |  23 +-
 doc/vpn-config-format.txt  |  22 +
 include/provider.h         |   2 -
 src/shared/mnlg.c          | 325 ++++++++++++
 src/shared/mnlg.h          |  27 +
 src/shared/netlink.c       | 666 -------------------------
 src/shared/netlink.h       |  53 --
 tools/netlink-test.c       | 123 -----
 vpn/plugins/libwireguard.c | 998 +++++++++++++++++++++++++++++++++++++
 vpn/plugins/vpn.c          |  51 +-
 vpn/plugins/vpn.h          |   3 +-
 vpn/plugins/wireguard.c    | 371 ++++++++++++++
 vpn/plugins/wireguard.h    | 103 ++++
 15 files changed, 1944 insertions(+), 861 deletions(-)
 create mode 100644 src/shared/mnlg.c
 create mode 100644 src/shared/mnlg.h
 delete mode 100644 src/shared/netlink.c
 delete mode 100644 src/shared/netlink.h
 delete mode 100644 tools/netlink-test.c
 create mode 100644 vpn/plugins/libwireguard.c
 create mode 100644 vpn/plugins/wireguard.c
 create mode 100644 vpn/plugins/wireguard.h

-- 
2.20.1


------------------------------

Message: 2
Date: Fri, 19 Jul 2019 13:21:30 +0200
From: Daniel Wagner <[email protected]>
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Subject: [PATCH v0 1/9] include: Remove unused definition
Message-ID: <[email protected]>

---
 include/provider.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/include/provider.h b/include/provider.h
index aa563edffc04..b58566532fc7 100644
--- a/include/provider.h
+++ b/include/provider.h
@@ -113,8 +113,6 @@ int connman_provider_set_nameservers(struct 
connman_provider *provider,
                                        char * const *nameservers);
 void connman_provider_set_autoconnect(struct connman_provider *provider,
                                                                bool flag);
-int connman_provider_append_route(struct connman_provider *provider,
-                                       const char *key, const char *value);
 
 const char *connman_provider_get_driver_name(struct connman_provider 
*provider);
 const char *connman_provider_get_save_group(struct connman_provider *provider);
-- 
2.20.1


------------------------------

Message: 3
Date: Fri, 19 Jul 2019 13:21:32 +0200
From: Daniel Wagner <[email protected]>
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Subject: [PATCH v0 3/9] build: Test for libmnl independent of nftables
Message-ID: <[email protected]>

Instead searching for libmnl and nftables in one test, split into two
seperate tests. We need libmnl for WireGuard too.
---
 Makefile.am  |  6 +++---
 configure.ac | 13 +++++++++++--
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 50ccbf856c71..5971ca9b8c91 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -158,7 +158,7 @@ endif
 
 if NFTABLES
 src_connmand_SOURCES += src/firewall-nftables.c
-src_connmand_LDADD +=  @NFTABLES_LIBS@
+src_connmand_LDADD += @NFTABLES_LIBS@ @LIBMNL_LIBS@
 endif
 
 if VPN
@@ -286,8 +286,8 @@ src_connmand_CFLAGS += @XTABLES_CFLAGS@
 endif
 
 if NFTABLES
-AM_CFLAGS += @NFTABLES_CFLAGS@
-src_connmand_CFLAGS += @NFTABLES_CFLAGS@
+AM_CFLAGS += @NFTABLES_CFLAGS@ @LIBMNL_CFLAGS@
+src_connmand_CFLAGS += @NFTABLES_CFLAGS@ @LIBMNL_CFLAGS@
 endif
 
 EXTRA_DIST += vpn/vpn-dbus.conf vpn/vpn-polkit.conf
diff --git a/configure.ac b/configure.ac
index ee49a22c4ec8..69e9f538d70c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -287,10 +287,19 @@ if (test "${firewall_type}" = "iptables"); then
 fi
 AM_CONDITIONAL(XTABLES, test "${found_iptables}" != "no")
 
+found_libmnl="no"
+if (test "${firewall_type}" = "nftables"); then
+       PKG_CHECK_MODULES(LIBMNL, [libmnl >= 1.0.0], [found_libmnl="yes"],
+               AC_MSG_ERROR([libmnl >= 1.0.0 not found]))
+       AC_SUBST(LIBMNL_CFLAGS)
+       AC_SUBST(LIBMNL_LIBS)
+fi
+AM_CONDITIONAL(LIBMNL, test "${found_libmnl}" != "no")
+
 found_nftables="no"
 if (test "${firewall_type}" = "nftables"); then
-       PKG_CHECK_MODULES(NFTABLES, [libnftnl >= 1.0.4 libmnl >= 1.0.0], 
[found_nftables="yes"],
-               AC_MSG_ERROR([libnftnl >= 1.0.4 or libmnl >= 1.0.0 not found]))
+       PKG_CHECK_MODULES(NFTABLES, [libnftnl >= 1.0.4], [found_nftables="yes"],
+               AC_MSG_ERROR([libnftnl >= 1.0.4]))
        AC_SUBST(NFTABLES_CFLAGS)
        AC_SUBST(NFTABLES_LIBS)
 fi
-- 
2.20.1


------------------------------

Message: 4
Date: Fri, 19 Jul 2019 13:21:33 +0200
From: Daniel Wagner <[email protected]>
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Subject: [PATCH v0 4/9] vpn: Add WireGuard plugin placeholder
Message-ID: <[email protected]>

Add an empty new plugin for WireGuard support.
---
 Makefile.plugins        | 18 +++++++++++++++++
 configure.ac            |  9 ++++++++-
 vpn/plugins/wireguard.c | 44 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+), 1 deletion(-)
 create mode 100644 vpn/plugins/wireguard.c

diff --git a/Makefile.plugins b/Makefile.plugins
index 14f2a782ae4e..3d4e32f08810 100644
--- a/Makefile.plugins
+++ b/Makefile.plugins
@@ -62,6 +62,24 @@ if VPN
 builtin_modules += vpn
 builtin_sources += plugins/vpn.c
 
+if WIREGUARD
+builtin_vpn_source = vpn/plugins/vpn.c vpn/plugins/vpn.h
+if WIREGUARD_BUILTIN
+builtin_vpn_modules += wireguard
+builtin_vpn_sources += vpn/plugins/wireguard.c
+builtin_vpn_cflags += -DWIREGUARD=\"@WIREGUARD@\"
+else
+vpn_plugin_LTLIBRARIES += vpn/plugins/wireguard.la
+vpn_plugin_objects += $(plugins_wireguard_la_OBJECTS)
+vpn_plugins_wireguard_la_SOURCES = vpn/plugins/wireguard.c
+vpn_plugins_wireguard_la_CFLAGS = $(plugin_cflags) \
+                                       -DWIREGUARD=\"@WIREGUARD@\" \
+                                       -DVPN_STATEDIR=\""$(vpn_statedir)"\" \
+                                       -DSCRIPTDIR=\""$(build_scriptdir)"\"
+vpn_plugins_wireguard_la_LDFLAGS = $(plugin_ldflags)
+endif
+endif
+
 if OPENCONNECT
 builtin_vpn_source = vpn/plugins/vpn.c vpn/plugins/vpn.h
 if OPENCONNECT_BUILTIN
diff --git a/configure.ac b/configure.ac
index 69e9f538d70c..537ba5f4007f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -342,6 +342,12 @@ AC_ARG_ENABLE(ethernet, 
AC_HELP_STRING([--disable-ethernet],
                                        [enable_ethernet=${enableval}])
 AM_CONDITIONAL(ETHERNET, test "${enable_ethernet}" != "no")
 
+AC_ARG_ENABLE(wireguard, AC_HELP_STRING([--disable-wireguard],
+                               [disable Wireguard support]),
+                                       [enable_wireguard=${enableval}])
+AM_CONDITIONAL(WIREGUARD, test "${enable_wireguard}" != "no")
+AM_CONDITIONAL(WIREGUARD_BUILTIN, test "${enable_wireguard}" = "builtin")
+
 AC_ARG_ENABLE(gadget, AC_HELP_STRING([--disable-gadget],
                                [disable USB Gadget support]),
                                        [enable_gadget=${enableval}])
@@ -453,7 +459,8 @@ AM_CONDITIONAL(VPN, test "${enable_openconnect}" != "no" -o 
\
                        "${enable_openvpn}" != "no" -o \
                        "${enable_vpnc}" != "no" -o \
                        "${enable_l2tp}" != "no" -o \
-                       "${enable_pptp}" != "no")
+                       "${enable_pptp}" != "no" -o \
+                       "${enable_wireguard}" != "no")
 
 AC_MSG_CHECKING(which DNS backend to use)
 AC_ARG_WITH(dns-backend, AC_HELP_STRING([--with-dns-backend=TYPE],
diff --git a/vpn/plugins/wireguard.c b/vpn/plugins/wireguard.c
new file mode 100644
index 000000000000..5056bd9776b8
--- /dev/null
+++ b/vpn/plugins/wireguard.c
@@ -0,0 +1,44 @@
+/*
+ *  ConnMan VPN daemon
+ *
+ *  Copyright (C) 2019  Daniel Wagner. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; 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 <glib.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/plugin.h>
+#include <connman/task.h>
+#include <connman/dbus.h>
+#include <connman/vpn-dbus.h>
+
+#include "vpn.h"
+
+static int wg_init(void)
+{
+       return 0;
+}
+
+static void wg_exit(void)
+{
+}
+
+CONNMAN_PLUGIN_DEFINE(wireguard, "WireGuard VPN plugin", VERSION,
+       CONNMAN_PLUGIN_PRIORITY_DEFAULT, wg_init, wg_exit)
-- 
2.20.1


------------------------------

Message: 5
Date: Fri, 19 Jul 2019 13:21:31 +0200
From: Daniel Wagner <[email protected]>
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Subject: [PATCH v0 2/9] shared: Remove netlink code
Message-ID: <[email protected]>

Remove the copy of ELL's netlink implemention. The only user was NFACCT
which also has been removed a while ago ddf176a0ce21 ("nfacct: Remove
support for NFACCT").
---
 Makefile.am          |   7 +-
 src/shared/netlink.c | 666 -------------------------------------------
 src/shared/netlink.h |  53 ----
 tools/netlink-test.c | 123 --------
 4 files changed, 1 insertion(+), 848 deletions(-)
 delete mode 100644 src/shared/netlink.c
 delete mode 100644 src/shared/netlink.h
 delete mode 100644 tools/netlink-test.c

diff --git a/Makefile.am b/Makefile.am
index 77f5d8a817a4..50ccbf856c71 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -55,7 +55,6 @@ stats_sources = src/nostats.c
 endif
 
 shared_sources = src/shared/util.h src/shared/util.c \
-               src/shared/netlink.h src/shared/netlink.c \
                src/shared/arp.h src/shared/arp.c
 
 if DATAFILES
@@ -340,7 +339,7 @@ noinst_PROGRAMS += tools/supplicant-test \
                        tools/tap-test tools/wpad-test \
                        tools/stats-tool tools/private-network-test \
                        tools/session-test \
-                       tools/dnsproxy-test tools/netlink-test
+                       tools/dnsproxy-test
 
 tools_supplicant_test_SOURCES = tools/supplicant-test.c \
                        tools/supplicant-dbus.h tools/supplicant-dbus.c \
@@ -413,10 +412,6 @@ endif
 tools_dnsproxy_test_SOURCES = tools/dnsproxy-test.c
 tools_dnsproxy_test_LDADD = @GLIB_LIBS@
 
-tools_netlink_test_SOURCES = src/shared/util.c src/shared/netlink.c \
-               tools/netlink-test.c
-tools_netlink_test_LDADD = @GLIB_LIBS@
-
 endif
 
 test_scripts = test/get-state test/list-services \
diff --git a/src/shared/netlink.c b/src/shared/netlink.c
deleted file mode 100644
index b32ab854b1ad..000000000000
--- a/src/shared/netlink.c
+++ /dev/null
@@ -1,666 +0,0 @@
-/*
- *
- *  Connection Manager
- *
- *  Copyright (C) 2011-2012  Intel Corporation. All rights reserved.
- *  Copyright (C) 2013-2014  BMW Car IT GmbH.
- *
- *  This program is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License version 2.1 as published by the Free Software Foundation.
- *
- *  This program 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 program; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- */
-
-/*
- * This file is a copy from ELL which has been ported to use GLib's
- * data structures.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <string.h>
-#include <unistd.h>
-#include <sys/socket.h>
-#include <linux/netlink.h>
-
-#include <gdbus.h>
-
-#include "src/shared/util.h"
-#include "src/shared/netlink.h"
-
-#ifndef SOL_NETLINK
-#define SOL_NETLINK 270
-#endif
-
-struct command {
-       unsigned int id;
-       uint32_t seq;
-       uint32_t len;
-       netlink_command_func_t handler;
-       netlink_destroy_func_t destroy;
-       void *user_data;
-};
-
-struct notify {
-       uint32_t group;
-       netlink_notify_func_t handler;
-       netlink_destroy_func_t destroy;
-       void *user_data;
-};
-
-struct netlink_info {
-       uint32_t pid;
-       GIOChannel *channel;
-       uint32_t next_seq;
-       GQueue *command_queue;
-       GHashTable *command_pending;
-       GHashTable *command_lookup;
-       unsigned int next_command_id;
-       GHashTable *notify_groups;
-       GHashTable *notify_lookup;
-       unsigned int next_notify_id;
-       netlink_debug_func_t debug_handler;
-       netlink_destroy_func_t debug_destroy;
-       void *debug_data;
-};
-
-
-static void destroy_command(struct command *command)
-{
-       if (command->destroy)
-               command->destroy(command->user_data);
-
-       g_free(command);
-}
-
-static void destroy_notify(struct notify *notify)
-{
-       if (notify->destroy)
-               notify->destroy(notify->user_data);
-
-       g_free(notify);
-}
-
-static gboolean can_write_data(GIOChannel *chan,
-                               GIOCondition cond, gpointer user_data)
-{
-       struct netlink_info *netlink = user_data;
-       struct command *command;
-       struct sockaddr_nl addr;
-       const void *data;
-       ssize_t written;
-       int sk;
-
-       command = g_queue_pop_head(netlink->command_queue);
-       if (!command)
-               return FALSE;
-
-       sk = g_io_channel_unix_get_fd(chan);
-
-       memset(&addr, 0, sizeof(addr));
-       addr.nl_family = AF_NETLINK;
-       addr.nl_pid = 0;
-
-       data = ((void *) command) + NLMSG_ALIGN(sizeof(struct command));
-
-       written = sendto(sk, data, command->len, 0,
-                               (struct sockaddr *) &addr, sizeof(addr));
-       if (written < 0 || (uint32_t) written != command->len) {
-               g_hash_table_remove(netlink->command_lookup,
-                                       GUINT_TO_POINTER(command->id));
-               destroy_command(command);
-               return FALSE;
-       }
-
-       util_hexdump('<', data, command->len,
-                               netlink->debug_handler, netlink->debug_data);
-
-       g_hash_table_replace(netlink->command_pending,
-                               GUINT_TO_POINTER(command->seq), command);
-
-       return g_queue_get_length(netlink->command_queue) > 0;
-}
-
-static void do_notify(gpointer key, gpointer value, gpointer user_data)
-{
-       struct nlmsghdr *nlmsg = user_data;
-       struct notify *notify = value;
-
-       if (notify->handler) {
-               notify->handler(nlmsg->nlmsg_type, NLMSG_DATA(nlmsg),
-                       nlmsg->nlmsg_len - NLMSG_HDRLEN, notify->user_data);
-       }
-}
-
-static void process_broadcast(struct netlink_info *netlink, uint32_t group,
-                                               struct nlmsghdr *nlmsg)
-{
-       GHashTable *notify_list;
-
-       notify_list = g_hash_table_lookup(netlink->notify_groups,
-                                              GUINT_TO_POINTER(group));
-       if (!notify_list)
-               return;
-
-       g_hash_table_foreach(notify_list, do_notify, nlmsg);
-}
-
-static void process_message(struct netlink_info *netlink,
-                               struct nlmsghdr *nlmsg)
-{
-       const void *data = nlmsg;
-       struct command *command;
-
-       command = g_hash_table_lookup(netlink->command_pending,
-                                       GUINT_TO_POINTER(nlmsg->nlmsg_seq));
-       if (!command)
-               return;
-
-       g_hash_table_remove(netlink->command_pending,
-                                       GUINT_TO_POINTER(nlmsg->nlmsg_seq));
-
-       if (!command->handler)
-               goto done;
-
-       if (nlmsg->nlmsg_type < NLMSG_MIN_TYPE) {
-               const struct nlmsgerr *err;
-
-               switch (nlmsg->nlmsg_type) {
-               case NLMSG_ERROR:
-                       err = data + NLMSG_HDRLEN;
-
-                       command->handler(-err->error, 0, NULL, 0,
-                                                       command->user_data);
-                       break;
-               }
-       } else {
-               command->handler(0, nlmsg->nlmsg_type, data + NLMSG_HDRLEN,
-                                       nlmsg->nlmsg_len - NLMSG_HDRLEN,
-                                       command->user_data);
-       }
-
-done:
-       g_hash_table_remove(netlink->command_lookup,
-                               GUINT_TO_POINTER(command->id));
-
-       destroy_command(command);
-}
-
-static void process_multi(struct netlink_info *netlink, struct nlmsghdr *nlmsg)
-{
-       const void *data = nlmsg;
-       struct command *command;
-
-       command = g_hash_table_lookup(netlink->command_pending,
-                                       GUINT_TO_POINTER(nlmsg->nlmsg_seq));
-       if (!command)
-               return;
-
-       if (!command->handler)
-               goto done;
-
-       if (nlmsg->nlmsg_type < NLMSG_MIN_TYPE) {
-               const struct nlmsgerr *err;
-
-               switch (nlmsg->nlmsg_type) {
-               case NLMSG_DONE:
-               case NLMSG_ERROR:
-                       err = data + NLMSG_HDRLEN;
-
-                       command->handler(-err->error, 0, NULL, 0,
-                                                       command->user_data);
-                       break;
-               }
-       } else {
-               command->handler(0, nlmsg->nlmsg_type, data + NLMSG_HDRLEN,
-                                       nlmsg->nlmsg_len - NLMSG_HDRLEN,
-                                       command->user_data);
-               return;
-       }
-
-done:
-       g_hash_table_remove(netlink->command_pending,
-                       GUINT_TO_POINTER(nlmsg->nlmsg_seq));
-
-       g_hash_table_remove(netlink->command_lookup,
-                       GUINT_TO_POINTER(command->id));
-
-       destroy_command(command);
-}
-
-static gboolean can_read_data(GIOChannel *chan,
-                               GIOCondition cond, gpointer data)
-{
-       struct netlink_info *netlink = data;
-       struct cmsghdr *cmsg;
-       struct msghdr msg;
-       struct iovec iov;
-       struct nlmsghdr *nlmsg;
-       unsigned char buffer[4096];
-       unsigned char control[32];
-       uint32_t group = 0;
-       ssize_t len;
-       int sk;
-
-       sk = g_io_channel_unix_get_fd(chan);
-
-       iov.iov_base = buffer;
-       iov.iov_len = sizeof(buffer);
-
-       memset(&msg, 0, sizeof(msg));
-       msg.msg_iov = &iov;
-       msg.msg_iovlen = 1;
-       msg.msg_control = control;
-       msg.msg_controllen = sizeof(control);
-
-       len = recvmsg(sk, &msg, 0);
-       if (len < 0)
-               return FALSE;
-
-       util_hexdump('>', buffer, len, netlink->debug_handler,
-                       netlink->debug_data);
-
-       for (cmsg = CMSG_FIRSTHDR(&msg); cmsg;
-                                       cmsg = CMSG_NXTHDR(&msg, cmsg)) {
-               struct nl_pktinfo *pktinfo;
-
-               if (cmsg->cmsg_level != SOL_NETLINK)
-                       continue;
-
-               if (cmsg->cmsg_type != NETLINK_PKTINFO)
-                       continue;
-
-               pktinfo = (void *) CMSG_DATA(cmsg);
-
-               group = pktinfo->group;
-       }
-
-       for (nlmsg = iov.iov_base; NLMSG_OK(nlmsg, (uint32_t) len);
-                                       nlmsg = NLMSG_NEXT(nlmsg, len)) {
-               if (group > 0 && nlmsg->nlmsg_seq == 0) {
-                       process_broadcast(netlink, group, nlmsg);
-                       continue;
-               }
-
-               if (nlmsg->nlmsg_pid != netlink->pid)
-                       continue;
-
-               if (nlmsg->nlmsg_flags & NLM_F_MULTI)
-                       process_multi(netlink, nlmsg);
-               else
-                       process_message(netlink, nlmsg);
-       }
-
-       return TRUE;
-}
-
-static gboolean netlink_event(GIOChannel *chan,
-                               GIOCondition cond, gpointer data)
-{
-       if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR))
-               return FALSE;
-
-       return TRUE;
-}
-
-static int create_netlink_socket(int protocol, uint32_t *pid)
-{
-       struct sockaddr_nl addr;
-       socklen_t addrlen = sizeof(addr);
-       int sk, pktinfo = 1;
-
-       sk = socket(PF_NETLINK, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK,
-                                                               protocol);
-       if (sk < 0)
-               return -1;
-
-       memset(&addr, 0, sizeof(addr));
-       addr.nl_family = AF_NETLINK;
-
-       if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
-               close(sk);
-               return -1;
-       }
-
-       if (getsockname(sk, (struct sockaddr *) &addr, &addrlen) < 0) {
-               close(sk);
-               return -1;
-       }
-
-       if (setsockopt(sk, SOL_NETLINK, NETLINK_PKTINFO,
-                                       &pktinfo, sizeof(pktinfo)) < 0) {
-               close(sk);
-               return -1;
-       }
-
-       if (pid)
-               *pid = addr.nl_pid;
-
-       return sk;
-}
-
-struct netlink_info *netlink_new(int protocol)
-{
-       struct netlink_info *netlink;
-       int sk;
-
-       netlink = g_try_new0(struct netlink_info, 1);
-       if (!netlink)
-               return NULL;
-
-       netlink->next_seq = 1;
-       netlink->next_command_id = 1;
-       netlink->next_notify_id = 1;
-
-       sk = create_netlink_socket(protocol, &netlink->pid);
-       if (sk < 0) {
-               g_free(netlink);
-               return NULL;
-       }
-
-       netlink->channel = g_io_channel_unix_new(sk);
-       g_io_channel_set_close_on_unref(netlink->channel, TRUE);
-
-       g_io_channel_set_encoding(netlink->channel, NULL, NULL);
-       g_io_channel_set_buffered(netlink->channel, FALSE);
-
-       g_io_add_watch(netlink->channel, G_IO_IN, can_read_data, netlink);
-       g_io_add_watch(netlink->channel, G_IO_NVAL | G_IO_HUP | G_IO_ERR,
-                       netlink_event, netlink);
-
-       netlink->command_queue = g_queue_new();
-       netlink->command_pending = g_hash_table_new(g_direct_hash,
-                                                       g_direct_equal);
-       netlink->command_lookup = g_hash_table_new(g_direct_hash,
-                                                       g_direct_equal);
-
-       netlink->notify_groups = g_hash_table_new(g_direct_hash,
-                                                       g_direct_equal);
-       netlink->notify_lookup = g_hash_table_new(g_direct_hash,
-                                                       g_direct_equal);
-
-       return netlink;
-}
-
-static gboolean cleanup_notify(gpointer key, gpointer value, gpointer 
user_data)
-{
-       struct notify *notify = value;
-
-       destroy_notify(notify);
-
-       return TRUE;
-
-}
-
-static gboolean cleanup_notify_group(gpointer key, gpointer value,
-                                       gpointer user_data)
-{
-       GHashTable *notify_list = value;
-
-       g_hash_table_foreach_remove(notify_list, cleanup_notify, user_data);
-       g_hash_table_destroy(notify_list);
-
-       return TRUE;
-}
-
-static gboolean cleanup_command(gpointer key, gpointer value,
-                                       gpointer user_data)
-{
-       struct command *command = value;
-
-       destroy_command(command);
-
-       return TRUE;
-}
-
-void netlink_destroy(struct netlink_info *netlink)
-{
-       g_hash_table_destroy(netlink->notify_lookup);
-
-       g_hash_table_foreach_remove(netlink->notify_groups,
-                               cleanup_notify_group, NULL);
-       g_hash_table_destroy(netlink->notify_groups);
-
-       g_queue_free(netlink->command_queue);
-
-       g_hash_table_destroy(netlink->command_pending);
-
-       g_hash_table_foreach_remove(netlink->command_lookup,
-                               cleanup_command, NULL);
-       g_hash_table_destroy(netlink->command_lookup);
-
-       g_io_channel_shutdown(netlink->channel, TRUE, NULL);
-       g_io_channel_unref(netlink->channel);
-
-       g_free(netlink);
-}
-
-unsigned int netlink_send(struct netlink_info *netlink,
-                       uint16_t type, uint16_t flags, const void *data,
-                       uint32_t len, netlink_command_func_t function,
-                       void *user_data, netlink_destroy_func_t destroy)
-{
-       struct command *command;
-       struct nlmsghdr *nlmsg;
-       size_t size;
-
-       if (!netlink)
-               return 0;
-
-       if (!netlink->command_queue ||
-                       !netlink->command_pending ||
-                       !netlink->command_lookup)
-               return 0;
-
-       size = NLMSG_ALIGN(sizeof(struct command)) +
-                                       NLMSG_HDRLEN + NLMSG_ALIGN(len);
-
-       command = g_try_malloc0(size);
-       if (!command)
-               return 0;
-
-       command->handler = function;
-       command->destroy = destroy;
-       command->user_data = user_data;
-
-       command->id = netlink->next_command_id;
-
-       g_hash_table_replace(netlink->command_lookup,
-                               GUINT_TO_POINTER(command->id), command);
-
-       command->seq = netlink->next_seq++;
-       command->len = NLMSG_HDRLEN + NLMSG_ALIGN(len);
-
-       nlmsg = ((void *) command) + NLMSG_ALIGN(sizeof(struct command));
-
-       nlmsg->nlmsg_len = command->len;
-       nlmsg->nlmsg_type = type;
-       nlmsg->nlmsg_flags = NLM_F_REQUEST | flags;
-       nlmsg->nlmsg_seq = command->seq;
-       nlmsg->nlmsg_pid = netlink->pid;
-
-       if (data && len > 0)
-               memcpy(((void *) nlmsg) + NLMSG_HDRLEN, data, len);
-
-       g_queue_push_tail(netlink->command_queue, command);
-
-       netlink->next_command_id++;
-
-       /* Arm IOChannel to call can_write_data in case it is not armed yet. */
-       if (g_queue_get_length(netlink->command_queue) == 1)
-               g_io_add_watch(netlink->channel, G_IO_OUT, can_write_data,
-                               netlink);
-
-       return command->id;
-}
-
-bool netlink_cancel(struct netlink_info *netlink, unsigned int id)
-{
-       struct command *command;
-
-       if (!netlink || id == 0)
-               return false;
-
-       if (!netlink->command_queue ||
-                       !netlink->command_pending ||
-                       !netlink->command_lookup)
-               return false;
-
-       command = g_hash_table_lookup(netlink->command_lookup,
-                                       GUINT_TO_POINTER(id));
-       if (!command)
-               return false;
-
-       g_hash_table_remove(netlink->command_lookup, GUINT_TO_POINTER(id));
-
-       if (!g_queue_remove(netlink->command_queue, command)) {
-               g_hash_table_remove(netlink->command_pending,
-                                       GUINT_TO_POINTER(command->seq));
-       }
-
-       destroy_command(command);
-
-       return true;
-}
-
-static bool add_membership(struct netlink_info *netlink, uint32_t group)
-{
-       int sk, value = group;
-
-       sk = g_io_channel_unix_get_fd(netlink->channel);
-
-       if (setsockopt(sk, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP,
-                                               &value, sizeof(value)) < 0)
-               return false;
-
-       return true;
-}
-
-static bool drop_membership(struct netlink_info *netlink, uint32_t group)
-{
-       int sk, value = group;
-
-       sk = g_io_channel_unix_get_fd(netlink->channel);
-
-       if (setsockopt(sk, SOL_NETLINK, NETLINK_DROP_MEMBERSHIP,
-                                               &value, sizeof(value)) < 0)
-               return false;
-
-       return true;
-}
-
-unsigned int netlink_register(struct netlink_info *netlink,
-                       uint32_t group, netlink_notify_func_t function,
-                       void *user_data, netlink_destroy_func_t destroy)
-{
-       GHashTable *notify_list;
-       struct notify *notify;
-       unsigned int id;
-
-       if (!netlink)
-               return 0;
-
-       if (!netlink->notify_groups || !netlink->notify_lookup)
-               return 0;
-
-       notify_list = g_hash_table_lookup(netlink->notify_groups,
-                                               GUINT_TO_POINTER(group));
-       if (!notify_list) {
-               notify_list = g_hash_table_new(g_direct_hash, g_direct_equal);
-               if (!notify_list)
-                       return 0;
-
-               g_hash_table_replace(netlink->notify_groups,
-                                       GUINT_TO_POINTER(group), notify_list);
-       }
-
-       notify = g_new(struct notify, 1);
-
-       notify->group = group;
-       notify->handler = function;
-       notify->destroy = destroy;
-       notify->user_data = user_data;
-
-       id = netlink->next_notify_id;
-
-       g_hash_table_replace(netlink->notify_lookup,
-                               GUINT_TO_POINTER(id), notify_list);
-       g_hash_table_replace(notify_list, GUINT_TO_POINTER(id), notify);
-
-       if (g_hash_table_size(notify_list) == 1) {
-               if (add_membership(netlink, notify->group) == false)
-                       goto remove_notify;
-       }
-
-       netlink->next_notify_id++;
-
-       return id;
-
-remove_notify:
-       g_hash_table_remove(notify_list, GUINT_TO_POINTER(id));
-       g_hash_table_remove(netlink->notify_lookup, GUINT_TO_POINTER(id));
-       g_free(notify);
-
-       return 0;
-}
-
-bool netlink_unregister(struct netlink_info *netlink, unsigned int id)
-{
-       GHashTable *notify_list;
-       struct notify *notify;
-
-       if (!netlink || id == 0)
-               return false;
-
-       if (!netlink->notify_groups || !netlink->notify_lookup)
-               return false;
-
-       notify_list = g_hash_table_lookup(netlink->notify_lookup,
-                                               GUINT_TO_POINTER(id));
-
-       if (!notify_list)
-               return false;
-
-       g_hash_table_remove(netlink->notify_lookup, GUINT_TO_POINTER(id));
-
-       notify = g_hash_table_lookup(notify_list, GUINT_TO_POINTER(id));
-       if (!notify)
-               return false;
-
-       g_hash_table_remove(notify_list, GUINT_TO_POINTER(id));
-
-       if (g_hash_table_size(notify_list) == 0)
-               drop_membership(netlink, notify->group);
-
-       destroy_notify(notify);
-
-       return true;
-}
-
-bool netlink_set_debug(struct netlink_info *netlink,
-                       netlink_debug_func_t function,
-                       void *user_data, netlink_destroy_func_t destroy)
-{
-       if (!netlink)
-               return false;
-
-       if (netlink->debug_destroy)
-               netlink->debug_destroy(netlink->debug_data);
-
-       netlink->debug_handler = function;
-       netlink->debug_destroy = destroy;
-       netlink->debug_data = user_data;
-
-       return true;
-}
diff --git a/src/shared/netlink.h b/src/shared/netlink.h
deleted file mode 100644
index 62bb3e012bc5..000000000000
--- a/src/shared/netlink.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- *
- *  Connection Manager
- *
- *  Copyright (C) 2011-2012  Intel Corporation. All rights reserved.
- *  Copyright (C) 2013  BMW Car IT GbmH.
- *
- *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License version 2.1 as published by the Free Software Foundation.
- *
- *  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
- *
- */
-
-#include <stdint.h>
-#include <stdbool.h>
-
-typedef void (*netlink_debug_func_t) (const char *str, void *user_data);
-typedef void (*netlink_command_func_t) (unsigned int error,
-                                               uint16_t type, const void *data,
-                                               uint32_t len, void *user_data);
-typedef void (*netlink_notify_func_t) (uint16_t type, const void *data,
-                                               uint32_t len, void *user_data);
-typedef void (*netlink_destroy_func_t) (void *user_data);
-
-struct netlink_info;
-
-struct netlink_info *netlink_new(int protocol);
-void netlink_destroy(struct netlink_info *netlink);
-
-unsigned int netlink_send(struct netlink_info *netlink,
-                       uint16_t type, uint16_t flags, const void *data,
-                       uint32_t len, netlink_command_func_t function,
-                       void *user_data, netlink_destroy_func_t destroy);
-bool netlink_cancel(struct netlink_info *netlink, unsigned int id);
-
-unsigned int netlink_register(struct netlink_info *netlink,
-                       uint32_t group, netlink_notify_func_t function,
-                       void *user_data, netlink_destroy_func_t destroy);
-bool netlink_unregister(struct netlink_info *netlink, unsigned int id);
-
-bool netlink_set_debug(struct netlink_info *netlink,
-                       netlink_debug_func_t function,
-                       void *user_data, netlink_destroy_func_t destroy);
diff --git a/tools/netlink-test.c b/tools/netlink-test.c
deleted file mode 100644
index 221e3490eae3..000000000000
--- a/tools/netlink-test.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- *
- *  Connection Manager
- *
- *  Copyright (C) 2013-2014  BMW Car IT GmbH.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License version 2 as
- *  published by the Free Software Foundation.
- *
- *  This program 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 General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; 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/netlink.h>
-#include <linux/rtnetlink.h>
-#include <linux/genetlink.h>
-#include <linux/netfilter/nfnetlink.h>
-#include <net/if.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <inttypes.h>
-#include <errno.h>
-
-#include <glib.h>
-
-#include "../src/shared/netlink.h"
-
-#define NFGEN_DATA(nlh) ((void *)((char *)(nlh) +                      \
-                               NLMSG_ALIGN(sizeof(struct nfgenmsg))))
-#define NLA_DATA(nla)  ((void *)((char*)(nla) + NLA_HDRLEN))
-#define NLA_OK(nla,len) ((len) >= (int)sizeof(struct nlattr) &&                
\
-                               (nla)->nla_len >= sizeof(struct nlattr) && \
-                               (nla)->nla_len <= (len))
-#define NLA_NEXT(nla,attrlen) ((attrlen) -= NLA_ALIGN((nla)->nla_len), \
-                               (struct nlattr*)(((char*)(nla)) +       \
-                                               NLA_ALIGN((nla)->nla_len)))
-
-static GMainLoop *mainloop;
-
-static void do_debug(const char *str, void *user_data)
-{
-       const char *prefix = user_data;
-
-       printf("%s%s\n", prefix, str);
-}
-
-static void getlink_callback(unsigned int error, uint16_t type, const void 
*data,
-                                               uint32_t len, void *user_data)
-{
-       const struct ifinfomsg *ifi = data;
-       struct rtattr *rta;
-       int bytes;
-       char ifname[IF_NAMESIZE];
-       uint32_t index, flags;
-
-       g_assert_cmpuint(error, ==, 0);
-
-       bytes = len - NLMSG_ALIGN(sizeof(struct ifinfomsg));
-
-       memset(ifname, 0, sizeof(ifname));
-
-       index = ifi->ifi_index;
-       flags = ifi->ifi_flags;
-
-       for (rta = IFLA_RTA(ifi); RTA_OK(rta, bytes);
-                                       rta = RTA_NEXT(rta, bytes)) {
-               switch (rta->rta_type) {
-               case IFLA_IFNAME:
-                       if (RTA_PAYLOAD(rta) <= IF_NAMESIZE)
-                               strcpy(ifname, RTA_DATA(rta));
-                       break;
-               }
-       }
-
-       printf("index=%d flags=0x%08x name=%s\n", index, flags, ifname);
-
-       g_main_loop_quit(mainloop);
-}
-
-static void test_case_1(void)
-{
-       struct netlink_info *netlink;
-       struct ifinfomsg msg;
-
-       netlink = netlink_new(NETLINK_ROUTE);
-
-       printf("\n");
-       netlink_set_debug(netlink, do_debug, "[NETLINK] ", NULL);
-
-       memset(&msg, 0, sizeof(msg));
-
-       netlink_send(netlink, RTM_GETLINK, NLM_F_DUMP, &msg, sizeof(msg),
-                                               getlink_callback, NULL, NULL);
-
-       mainloop = g_main_loop_new(NULL, FALSE);
-       g_main_loop_run(mainloop);
-       g_main_loop_unref(mainloop);
-
-       netlink_destroy(netlink);
-}
-
-int main(int argc, char *argv[])
-{
-       g_test_init(&argc, &argv, NULL);
-
-       g_test_add_func("/netlink/Test case 1", test_case_1);
-
-       return g_test_run();
-}
-- 
2.20.1


------------------------------

Subject: Digest Footer

_______________________________________________
connman mailing list
[email protected]
https://lists.01.org/mailman/listinfo/connman


------------------------------

End of connman Digest, Vol 45, Issue 11
***************************************

Reply via email to