Skip to content

Commit

Permalink
UAPI changes for Amnezia kernel module
Browse files Browse the repository at this point in the history
  • Loading branch information
leninalive committed Nov 20, 2023
1 parent c9ff85e commit 0ef35ee
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 35 deletions.
11 changes: 10 additions & 1 deletion contrib/embeddable-wg-library/wireguard.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

/* wireguard.h netlink uapi: */

#define WG_GENL_NAME "wireguard"
#define WG_GENL_NAME "amnezia"
#define WG_GENL_VERSION 1

enum wg_cmd {
Expand All @@ -48,6 +48,15 @@ enum wgdevice_attribute {
WGDEVICE_A_LISTEN_PORT,
WGDEVICE_A_FWMARK,
WGDEVICE_A_PEERS,
WGDEVICE_A_JC,
WGDEVICE_A_JMIN,
WGDEVICE_A_JMAX,
WGDEVICE_A_S1,
WGDEVICE_A_S2,
WGDEVICE_A_H1,
WGDEVICE_A_H2,
WGDEVICE_A_H3,
WGDEVICE_A_H4,
__WGDEVICE_A_LAST
};

Expand Down
72 changes: 45 additions & 27 deletions src/ipc-linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,41 +459,59 @@ static int parse_device(const struct nlattr *attr, void *data)
break;
case WGDEVICE_A_PEERS:
return mnl_attr_parse_nested(attr, parse_peers, device);
case WGDEVICE_HAS_JC:
if (!mnl_attr_validate(attr, MNL_TYPE_U16))
device->junk_packet_count = mnl_attr_get_u16(attr);
case WGDEVICE_A_JC:
if (!mnl_attr_validate(attr, MNL_TYPE_U16)) {
device->junk_packet_count = mnl_attr_get_u16(attr);
device->flags |= WGDEVICE_HAS_JC;
}
break;
case WGDEVICE_HAS_JMIN:
if (!mnl_attr_validate(attr, MNL_TYPE_U16))
device->junk_packet_min_size = mnl_attr_get_u16(attr);
case WGDEVICE_A_JMIN:
if (!mnl_attr_validate(attr, MNL_TYPE_U16)) {
device->junk_packet_min_size = mnl_attr_get_u16(attr);
device->flags |= WGDEVICE_HAS_JMIN;
}
break;
case WGDEVICE_HAS_JMAX:
if (!mnl_attr_validate(attr, MNL_TYPE_U16))
device->junk_packet_max_size = mnl_attr_get_u16(attr);
case WGDEVICE_A_JMAX:
if (!mnl_attr_validate(attr, MNL_TYPE_U16)) {
device->junk_packet_max_size = mnl_attr_get_u16(attr);
device->flags |= WGDEVICE_HAS_JMAX;
}
break;
case WGDEVICE_HAS_S1:
if (!mnl_attr_validate(attr, MNL_TYPE_U16))
device->init_packet_junk_size = mnl_attr_get_u16(attr);
case WGDEVICE_A_S1:
if (!mnl_attr_validate(attr, MNL_TYPE_U16)) {
device->init_packet_junk_size = mnl_attr_get_u16(attr);
device->flags |= WGDEVICE_HAS_S1;
}
break;
case WGDEVICE_HAS_S2:
if (!mnl_attr_validate(attr, MNL_TYPE_U16))
device->response_packet_junk_size = mnl_attr_get_u16(attr);
case WGDEVICE_A_S2:
if (!mnl_attr_validate(attr, MNL_TYPE_U16)) {
device->response_packet_junk_size = mnl_attr_get_u16(attr);
device->flags |= WGDEVICE_HAS_S2;
}
break;
case WGDEVICE_HAS_H1:
if (!mnl_attr_validate(attr, MNL_TYPE_U32))
device->init_packet_magic_header = mnl_attr_get_u32(attr);
case WGDEVICE_A_H1:
if (!mnl_attr_validate(attr, MNL_TYPE_U32)) {
device->init_packet_magic_header = mnl_attr_get_u32(attr);
device->flags |= WGDEVICE_HAS_H1;
}
break;
case WGDEVICE_HAS_H2:
if (!mnl_attr_validate(attr, MNL_TYPE_U32))
device->response_packet_magic_header = mnl_attr_get_u32(attr);
case WGDEVICE_A_H2:
if (!mnl_attr_validate(attr, MNL_TYPE_U32)) {
device->response_packet_magic_header = mnl_attr_get_u32(attr);
device->flags |= WGDEVICE_HAS_H2;
}
break;
case WGDEVICE_HAS_H3:
if (!mnl_attr_validate(attr, MNL_TYPE_U32))
device->underload_packet_magic_header = mnl_attr_get_u32(attr);
case WGDEVICE_A_H3:
if (!mnl_attr_validate(attr, MNL_TYPE_U32)) {
device->underload_packet_magic_header = mnl_attr_get_u32(attr);
device->flags |= WGDEVICE_HAS_H3;
}
break;
case WGDEVICE_HAS_H4:
if (!mnl_attr_validate(attr, MNL_TYPE_U32))
device->transport_packet_magic_header = mnl_attr_get_u32(attr);
case WGDEVICE_A_H4:
if (!mnl_attr_validate(attr, MNL_TYPE_U32)) {
device->transport_packet_magic_header = mnl_attr_get_u32(attr);
device->flags |= WGDEVICE_HAS_H4;
}
break;
}

Expand Down
4 changes: 2 additions & 2 deletions src/uapi/linux/linux/wireguard.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) OR MIT */
/* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) OR MIT */
/*
* Copyright (C) 2015-2020 Jason A. Donenfeld <[email protected]>. All Rights Reserved.
*
Expand Down Expand Up @@ -131,7 +131,7 @@
#ifndef _WG_UAPI_WIREGUARD_H
#define _WG_UAPI_WIREGUARD_H

#define WG_GENL_NAME "wireguard"
#define WG_GENL_NAME "amnezia"
#define WG_GENL_VERSION 1

#define WG_KEY_LEN 32
Expand Down
10 changes: 5 additions & 5 deletions src/wg-quick/linux.bash
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ die() {
parse_options() {
local interface_section=0 line key value stripped v
CONFIG_FILE="$1"
[[ $CONFIG_FILE =~ ^[a-zA-Z0-9_=+.-]{1,15}$ ]] && CONFIG_FILE="/etc/wireguard/$CONFIG_FILE.conf"
[[ $CONFIG_FILE =~ ^[a-zA-Z0-9_=+.-]{1,15}$ ]] && CONFIG_FILE="/etc/amnezia/$CONFIG_FILE.conf"
[[ -e $CONFIG_FILE ]] || die "\`$CONFIG_FILE' does not exist"
[[ $CONFIG_FILE =~ (^|/)([a-zA-Z0-9_=+.-]{1,15})\.conf$ ]] || die "The config file must be a valid interface name, followed by .conf"
CONFIG_FILE="$(readlink -f "$CONFIG_FILE")"
Expand Down Expand Up @@ -87,10 +87,10 @@ auto_su() {

add_if() {
local ret
if ! cmd ip link add "$INTERFACE" type wireguard; then
if ! cmd ip link add "$INTERFACE" type amnezia; then
ret=$?
[[ -e /sys/module/wireguard ]] || ! command -v "${WG_QUICK_USERSPACE_IMPLEMENTATION:-wireguard-go}" >/dev/null && exit $ret
echo "[!] Missing WireGuard kernel module. Falling back to slow userspace implementation." >&2
[[ -e /sys/module/amnezia ]] || ! command -v "${WG_QUICK_USERSPACE_IMPLEMENTATION:-wireguard-go}" >/dev/null && exit $ret
echo "[!] Missing WireGuard (Amnezia VPN) kernel module. Falling back to slow userspace implementation." >&2
cmd "${WG_QUICK_USERSPACE_IMPLEMENTATION:-wireguard-go}" "$INTERFACE"
fi
}
Expand Down Expand Up @@ -302,7 +302,7 @@ cmd_usage() {
CONFIG_FILE is a configuration file, whose filename is the interface name
followed by \`.conf'. Otherwise, INTERFACE is an interface name, with
configuration found at /etc/wireguard/INTERFACE.conf. It is to be readable
configuration found at /etc/amnezia/INTERFACE.conf. It is to be readable
by wg(8)'s \`setconf' sub-command, with the exception of the following additions
to the [Interface] section, which are handled by $PROGRAM:
Expand Down

0 comments on commit 0ef35ee

Please sign in to comment.