0
0
mirror of https://github.com/openwrt/packages.git synced 2025-02-12 01:10:54 +00:00
Andre Heider c23789a576 rpcd-mod-wireguard: add new package
The rpcd wireguard plugin provides essential functions similar to the `wg`
tool.

It uses the embeddable-wg-library [0], which describes itself as:
"This is a mini single-file library, meant to be embedded directly into the
source code of your program. Copy wireguard.c and wireguard.h into your
project. They should build with any C89 compiler. There are no dependencies
except libc"

The plugin does exactly that and therefor inherits the LGPL license.

At this point it provides the following functions:

'wireguard'
    "status":{}
    "genkey":{}
    "genpsk":{}
    "pubkey":{"private":"String"}

Examples:

$ ubus call wireguard status
{
        "wg0": {
                "ifindex": 12,
                "public_key": "<base64 encoded public key>",
                "listen_port": 1234,
                "peers": {
                        "<base64 encoded public peer key>": {
                                "allowed_ips": [
                                        "192.168.1.123/32"
                                ],
                                "last_handshake": 0,
                                "rx_bytes": 0,
                                "tx_bytes": 0
                        },
                        "<another base64 encoded public peer key>": {
                                "endpoint": "<ip:port>",
                                "allowed_ips": [
                                        "192.168.1.124/32"
                                ],
                                "last_handshake": 1676287619,
                                "rx_bytes": 8731604,
                                "tx_bytes": 88333652
                        }
                }
        }
}

$ ubus call wireguard genpsk
{
        "preshared": "EKQJ3XI/6xLoifAoGb5bNA39De1tiwZ3x7h8OS2zKkE="
}

$ ubus call wireguard genkey
{
        "private": "IFyGkfXlO+WO8DMO3cqhaDZ8rBfioP5pVnAoQlEpXnI=",
        "public": "uF2O6/ZXZjKnUnxBnldElBYIXfpyvvtUnZfKP+BSBSI="
}

$ ubus call wireguard pubkey '{"private":"IFyGkfXlO+WO8DMO3cqhaDZ8rBfioP5pVnAoQlEpXnI="}'
{
        "public": "uF2O6/ZXZjKnUnxBnldElBYIXfpyvvtUnZfKP+BSBSI="
}

Size comparison:
52436 /usr/bin/wg
18544 /usr/lib/rpcd/wireguard.so

[0] https://git.zx2c4.com/wireguard-tools/tree/contrib/embeddable-wg-library

Signed-off-by: Andre Heider <a.heider@gmail.com>
2023-08-25 10:18:26 +02:00

32 lines
710 B
Makefile

include $(TOPDIR)/rules.mk
PKG_NAME:=rpcd-mod-wireguard
PKG_RELEASE=1
PKG_LICENSE:=LGPL-2.1+
PKG_BUILD_FLAGS:=gc-sections
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/cmake.mk
define Package/rpcd-mod-wireguard
SECTION:=libs
CATEGORY:=Libraries
TITLE:=WireGuard rpcd module
DEPENDS:=+rpcd +kmod-wireguard
MAINTAINER:=Andre Heider <a.heider@gmail.com>
endef
define Package/rpcd-mod-wireguard/install
$(INSTALL_DIR) $(1)/usr/lib/rpcd
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/lib/rpcd/wireguard.so \
$(1)/usr/lib/rpcd/
endef
define Package/rpcd-mod-wireguard/postinst
#!/bin/sh
[ -n "$$IPKG_INSTROOT" ] || /etc/init.d/rpcd reload
endef
$(eval $(call BuildPackage,rpcd-mod-wireguard))