vwifi: add package
authorJo-Philipp Wich <jo@mein.io>
Fri, 21 Jun 2024 11:03:38 +0000 (13:03 +0200)
committerJo-Philipp Wich <jo@mein.io>
Fri, 21 Jun 2024 12:00:36 +0000 (14:00 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
package/network/utils/vwifi/Makefile [new file with mode: 0644]
package/network/utils/vwifi/files/vwifi.init [new file with mode: 0755]
package/network/utils/vwifi/patches/100-compile-fixes.patch [new file with mode: 0644]

diff --git a/package/network/utils/vwifi/Makefile b/package/network/utils/vwifi/Makefile
new file mode 100644 (file)
index 0000000..e28bf19
--- /dev/null
@@ -0,0 +1,65 @@
+#
+# Copyright (C) 2012 Jo-Philipp Wich <jo@mein.io>
+#
+# This is free software, licensed under the Apache 2 license.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=vwifi
+PKG_RELEASE:=1
+
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_URL:=https://github.com/Raizo62/vwifi.git
+PKG_SOURCE_DATE:=2023-12-31
+PKG_SOURCE_VERSION:=e0019422225aa11fcc5e435ccda39f3486f590ed
+PKG_MIRROR_HASH:=880259f7fd0b105cee1dae693602d904c7daed08dc45aaca38a93a29b0a839d1
+PKG_MAINTAINER:=Jo-Philipp Wich <jo@mein.io>
+
+PKG_LICENSE:=LGPL-3.0-only
+PKG_LICENSE_FILES:=LICENSE.md
+
+include $(INCLUDE_DIR)/package.mk
+
+
+define Package/vwifi
+  SECTION:=utils
+  CATEGORY:=Utilities
+  TITLE:=Wi-Fi protocol simulation
+  DEPENDS:=+libstdcpp +libnl-tiny +kmod-virtio-vsockets
+endef
+
+define Package/vwifi/description
+  Simulate Wi-Fi (802.11) between Linux Virtual Machines.
+
+  The vwifi utilities can be used in Hypervisors such as GNS3, QEMU,
+  VirtualBox, VMware, Hyper-V etc. to simulate 802.11 traffic between
+  different virtual machines.
+
+  The utilities use the mac80211_hwsim driver to provide simulated
+  virtual wireless devices to Linux systems and transport the 802.11
+  frames via TCP connections across different machines.
+endef
+
+
+MAKE_VARS += \
+       NETLINK_FLAGS="-I$(STAGING_DIR)/usr/include/libnl-tiny -DNL_AUTO_PORT=0 -Dnl_send_auto=nl_send_auto_complete" \
+       NETLINK_LIBS="-lnl-tiny"
+
+define Build/Configure
+       $(INSTALL_DIR) $(PKG_BUILD_DIR)/src/netlink/route
+       touch $(PKG_BUILD_DIR)/src/netlink/route/link.h
+endef
+
+define Package/vwifi/install
+       $(INSTALL_DIR) $(1)/usr/sbin
+       $(INSTALL_BIN) $(PKG_BUILD_DIR)/vwifi-add-interfaces $(1)/usr/sbin/vwifi-add-interfaces
+       $(INSTALL_BIN) $(PKG_BUILD_DIR)/vwifi-client $(1)/usr/sbin/vwifi-client
+       $(INSTALL_BIN) $(PKG_BUILD_DIR)/vwifi-ctrl $(1)/usr/sbin/vwifi-ctrl
+       $(INSTALL_BIN) $(PKG_BUILD_DIR)/vwifi-server $(1)/usr/sbin/vwifi-server
+
+       $(INSTALL_DIR) $(1)/etc/init.d
+       $(INSTALL_BIN) ./files/vwifi.init $(1)/etc/init.d/vwifi
+endef
+
+$(eval $(call BuildPackage,vwifi))
diff --git a/package/network/utils/vwifi/files/vwifi.init b/package/network/utils/vwifi/files/vwifi.init
new file mode 100755 (executable)
index 0000000..e3a4676
--- /dev/null
@@ -0,0 +1,69 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2024 Jo-Philipp Wich
+
+START=90
+
+USE_PROCD=1
+
+VWIFI_CLIENT_BIN="/usr/sbin/vwifi-client"
+
+delete_iface() {
+       local cfg=$1
+       local radio=$2
+       local device
+
+       config_get device "$cfg" device
+
+       [ "$device" != "$radio" ] || {
+               uci delete "wireless.$cfg"
+       }
+}
+
+delete_device() {
+       local cfg=$1
+       local path
+
+       config_get path "$cfg" path
+
+       case "$path" in virtual/mac80211_hwsim/*)
+               config_foreach delete_iface wifi-iface "$cfg"
+               uci delete "wireless.$cfg"
+       ;; esac
+}
+
+fixup_config() {
+       . /lib/functions.sh
+
+       config_load wireless
+       config_foreach delete_device wifi-device
+
+       [ -z "$(uci changes wireless)" ] || uci commit wireless
+}
+
+fixup_hwsim() {
+       local num_radios=$(cat /sys/module/mac80211_hwsim/parameters/radios 2>/dev/null)
+
+       [ -n "$num_radios" ] || {
+               echo "vwifi-client: mac80211_hwsim module is not loaded, aborting!" >&2
+               exit 1
+       }
+
+       [ $num_radios = 0 ] || {
+               echo "vwifi-client: reloading mac80211_hwsim module without default radios" >&2
+               rmmod mac80211_hwsim
+               insmod mac80211_hwsim radios=0
+
+               fixup_config
+       }
+}
+
+start_service() {
+       fixup_hwsim
+
+       procd_open_instance
+       procd_set_param respawn
+       procd_set_param stdout 1
+       procd_set_param stderr 1
+       procd_set_param command $VWIFI_CLIENT_BIN
+       procd_close_instance
+}
diff --git a/package/network/utils/vwifi/patches/100-compile-fixes.patch b/package/network/utils/vwifi/patches/100-compile-fixes.patch
new file mode 100644 (file)
index 0000000..7bb43dc
--- /dev/null
@@ -0,0 +1,43 @@
+--- a/Makefile
++++ b/Makefile
+@@ -24,9 +24,9 @@ MODE+= -O3 -s -Wall -Wextra -pedantic #
+ EDITOR        ?=      geany
+ NETLINK_FLAGS_PATH := /usr/include/libnl3
+-NETLINK_FLAGS := -I $(NETLINK_FLAGS_PATH)
++NETLINK_FLAGS ?= -I $(NETLINK_FLAGS_PATH)
+ NETLINK_LIBS_PATH := .
+-NETLINK_LIBS := -L $(NETLINK_LIBS_PATH) -lnl-genl-3 -lnl-3
++NETLINK_LIBS ?= -L $(NETLINK_LIBS_PATH) -lnl-genl-3 -lnl-3
+ THREAD_LIBS := -lpthread
+--- a/src/cmonwirelessdevice.cc
++++ b/src/cmonwirelessdevice.cc
+@@ -20,7 +20,6 @@
+ #include <netlink/genl/genl.h>
+ #include <netlink/genl/ctrl.h>
+ #include <netlink/genl/family.h>
+-#include <netlink/route/link.h>
+ #include <linux/nl80211.h>
+@@ -207,7 +206,7 @@ void MonitorWirelessDevice::recv_inet_ev
+       char buf[IFLIST_REPLY_BUFFER];
+       struct iovec iov = { buf, sizeof(buf) };
+       struct sockaddr_nl snl;
+-      struct msghdr msg = { (void *)&snl, sizeof(snl), &iov, 1, NULL, 0, 0 };
++      struct msghdr msg = { (void *)&snl, sizeof(snl), &iov, 1, 0, 0, 0 };
+       struct nlmsghdr *nlmsgheader;
+       /* read the waiting message */
+--- a/src/ckernelwifi.cc
++++ b/src/ckernelwifi.cc
+@@ -5,7 +5,6 @@
+ #include <netlink/genl/genl.h>
+ #include <netlink/genl/ctrl.h>
+ #include <netlink/genl/family.h>
+-#include <netlink/route/link.h>
+ #include <net/if_arp.h>
+ #include <linux/nl80211.h>