gl-mt3000: update patchs

Signed-off-by: Jianhui Zhao <jianhui.zhao@gl-inet.com>
This commit is contained in:
Jianhui Zhao 2022-07-08 16:27:09 +08:00
parent e0074b2a2e
commit 78ff2c913c
3 changed files with 272 additions and 177 deletions

View File

@ -1,7 +1,7 @@
repo: https://github.com/openwrt/openwrt.git
branch: v21.02.3
git_clone_dir: openwrt-21.02.3/
openwrt_root_dir: openwrt-21.02.3/
git_clone_dir: mt7981/
openwrt_root_dir: mt7981/
revision: 42a15ca378e1bc52f125f894d748c31ce3c52903
patch_folders:

View File

@ -1,166 +1,186 @@
Index: linux-5.4.188/drivers/net/wireguard/Makefile
===================================================================
--- linux-5.4.188.orig/drivers/net/wireguard/Makefile
+++ linux-5.4.188/drivers/net/wireguard/Makefile
@@ -14,4 +14,5 @@ wireguard-y += allowedips.o
wireguard-y += ratelimiter.o
wireguard-y += cookie.o
wireguard-y += netlink.o
+wireguard-y += hotplug.o
obj-$(CONFIG_WIREGUARD) := wireguard.o
Index: linux-5.4.188/drivers/net/wireguard/hotplug.c
===================================================================
From 916a1e5f3f467b96962ad78ab989df2ed3406c30 Mon Sep 17 00:00:00 2001
From: Jianhui Zhao <jianhui.zhao@gl-inet.com>
Date: Thu, 7 Jul 2022 15:18:12 +0800
Subject: [PATCH] wireguard: support hotplug for gl
Signed-off-by: Jianhui Zhao <jianhui.zhao@gl-inet.com>
---
.../950-wireguard-support-hotplug.patch | 166 ++++++++++++++++++
1 file changed, 166 insertions(+)
create mode 100644 target/linux/generic/hack-5.4/950-wireguard-support-hotplug.patch
diff --git a/target/linux/generic/hack-5.4/950-wireguard-support-hotplug.patch b/target/linux/generic/hack-5.4/950-wireguard-support-hotplug.patch
new file mode 100644
index 0000000000..740b300e5b
--- /dev/null
+++ linux-5.4.188/drivers/net/wireguard/hotplug.c
@@ -0,0 +1,82 @@
+#include <linux/workqueue.h>
+#include <linux/netlink.h>
+#include <linux/kobject.h>
+#include <linux/skbuff.h>
+#include <linux/if.h>
+
+#define SUBSYSTEM_NAME "wireguard"
+
+#define EVENT_BUF_SIZE 2048
+
+struct wg_event {
+ struct work_struct work;
+ char ifname[IFNAMSIZ];
+ const char *action;
+};
+
+
+/* -------------------------------------------------------------------------*/
+static int bh_event_add_var(struct sk_buff *skb, int argv,
+ const char *format, ...)
+{
+ static char buf[128];
+ char *s;
+ va_list args;
+ int len;
+
+ if (argv)
+ return 0;
+
+ va_start(args, format);
+ len = vsnprintf(buf, sizeof(buf), format, args);
+ va_end(args);
+
+ if (len >= sizeof(buf)) {
+ //WARN(1, "buffer size too small\n");
+ return -ENOMEM;
+ }
+
+ s = skb_put(skb, len + 1);
+ strcpy(s, buf);
+
+ return 0;
+}
+
+static void hotplug_work(struct work_struct *work)
+{
+ struct wg_event *event = container_of(work, struct wg_event, work);
+ struct sk_buff *skb;
+
+ skb = alloc_skb(EVENT_BUF_SIZE, GFP_KERNEL);
+ if (!skb)
+ goto out_free_event;
+
+ bh_event_add_var(skb, 0, "SUBSYSTEM=%s", SUBSYSTEM_NAME);
+ bh_event_add_var(skb, 0, "ACTION=%s", event->action);
+ bh_event_add_var(skb, 0, "ifname=%s", event->ifname);
+
+ NETLINK_CB(skb).dst_group = 1;
+ broadcast_uevent(skb, 0, 1, GFP_KERNEL);
+
+out_free_event:
+ kfree(event);
+}
+
+void wireguard_hotplug(const char *ifname, const char *action)
+{
+ struct wg_event *event;
+
+ if (!strcmp(ifname, "wgserver"))
+ return;
+
+ event = kzalloc(sizeof(struct wg_event), GFP_ATOMIC);
+ if (!event)
+ return;
+
+ memcpy(event->ifname, ifname, IFNAMSIZ);
+
+ event->action = action;
+
+ INIT_WORK(&event->work, hotplug_work);
+ schedule_work(&event->work);
+}
Index: linux-5.4.188/drivers/net/wireguard/hotplug.h
===================================================================
--- /dev/null
+++ linux-5.4.188/drivers/net/wireguard/hotplug.h
@@ -0,0 +1,13 @@
+#ifndef __HOTPLUG_H__
+#define __HOTPLUG_H__
+
+#define REKEY_GIVEUP_EVENT "REKEY-GIVEUP"
+#define REKEY_TIMEOUT_EVENT "REKEY-TIMEOUT"
+#define KEYPAIR_CREATED_EVENT "KEYPAIR-CREATED"
+
+extern void wireguard_hotplug(const char *ifname, const char *action);
+extern void wg_hotplug_init(void);
+extern void wg_hotplug_free(void);
+
+#endif
+
Index: linux-5.4.188/drivers/net/wireguard/noise.c
===================================================================
--- linux-5.4.188.orig/drivers/net/wireguard/noise.c
+++ linux-5.4.188/drivers/net/wireguard/noise.c
@@ -9,6 +9,7 @@
#include "messages.h"
#include "queueing.h"
#include "peerlookup.h"
+#include "hotplug.h"
#include <linux/rcupdate.h>
#include <linux/slab.h>
@@ -817,6 +818,8 @@ bool wg_noise_handshake_begin_session(st
ret = wg_index_hashtable_replace(
handshake->entry.peer->device->index_hashtable,
&handshake->entry, &new_keypair->entry);
+
+ wireguard_hotplug(handshake->entry.peer->device->dev->name, KEYPAIR_CREATED_EVENT);
} else {
kzfree(new_keypair);
}
Index: linux-5.4.188/drivers/net/wireguard/timers.c
===================================================================
--- linux-5.4.188.orig/drivers/net/wireguard/timers.c
+++ linux-5.4.188/drivers/net/wireguard/timers.c
@@ -8,6 +8,7 @@
#include "peer.h"
#include "queueing.h"
#include "socket.h"
+#include "hotplug.h"
/*
* - Timer for retransmitting the handshake if we don't hear back after
@@ -60,6 +61,8 @@ static void wg_expired_retransmit_handsh
if (!timer_pending(&peer->timer_zero_key_material))
mod_peer_timer(peer, &peer->timer_zero_key_material,
jiffies + REJECT_AFTER_TIME * 3 * HZ);
+
+ wireguard_hotplug(peer->device->dev->name, REKEY_GIVEUP_EVENT);
} else {
++peer->timer_handshake_attempts;
pr_debug("%s: Handshake for peer %llu (%pISpfsc) did not complete after %d seconds, retrying (try %d)\n",
@@ -73,6 +76,8 @@ static void wg_expired_retransmit_handsh
wg_socket_clear_peer_endpoint_src(peer);
wg_packet_send_queued_handshake_initiation(peer, true);
+
+ wireguard_hotplug(peer->device->dev->name, REKEY_TIMEOUT_EVENT);
}
}
+++ b/target/linux/generic/hack-5.4/950-wireguard-support-hotplug.patch
@@ -0,0 +1,166 @@
+Index: linux-5.4.188/drivers/net/wireguard/Makefile
+===================================================================
+--- linux-5.4.188.orig/drivers/net/wireguard/Makefile
++++ linux-5.4.188/drivers/net/wireguard/Makefile
+@@ -14,4 +14,5 @@ wireguard-y += allowedips.o
+ wireguard-y += ratelimiter.o
+ wireguard-y += cookie.o
+ wireguard-y += netlink.o
++wireguard-y += hotplug.o
+ obj-$(CONFIG_WIREGUARD) := wireguard.o
+Index: linux-5.4.188/drivers/net/wireguard/hotplug.c
+===================================================================
+--- /dev/null
++++ linux-5.4.188/drivers/net/wireguard/hotplug.c
+@@ -0,0 +1,82 @@
++#include <linux/workqueue.h>
++#include <linux/netlink.h>
++#include <linux/kobject.h>
++#include <linux/skbuff.h>
++#include <linux/if.h>
++
++#define SUBSYSTEM_NAME "wireguard"
++
++#define EVENT_BUF_SIZE 2048
++
++struct wg_event {
++ struct work_struct work;
++ char ifname[IFNAMSIZ];
++ const char *action;
++};
++
++
++/* -------------------------------------------------------------------------*/
++static int bh_event_add_var(struct sk_buff *skb, int argv,
++ const char *format, ...)
++{
++ static char buf[128];
++ char *s;
++ va_list args;
++ int len;
++
++ if (argv)
++ return 0;
++
++ va_start(args, format);
++ len = vsnprintf(buf, sizeof(buf), format, args);
++ va_end(args);
++
++ if (len >= sizeof(buf)) {
++ //WARN(1, "buffer size too small\n");
++ return -ENOMEM;
++ }
++
++ s = skb_put(skb, len + 1);
++ strcpy(s, buf);
++
++ return 0;
++}
++
++static void hotplug_work(struct work_struct *work)
++{
++ struct wg_event *event = container_of(work, struct wg_event, work);
++ struct sk_buff *skb;
++
++ skb = alloc_skb(EVENT_BUF_SIZE, GFP_KERNEL);
++ if (!skb)
++ goto out_free_event;
++
++ bh_event_add_var(skb, 0, "SUBSYSTEM=%s", SUBSYSTEM_NAME);
++ bh_event_add_var(skb, 0, "ACTION=%s", event->action);
++ bh_event_add_var(skb, 0, "ifname=%s", event->ifname);
++
++ NETLINK_CB(skb).dst_group = 1;
++ broadcast_uevent(skb, 0, 1, GFP_KERNEL);
++
++out_free_event:
++ kfree(event);
++}
++
++void wireguard_hotplug(const char *ifname, const char *action)
++{
++ struct wg_event *event;
++
++ if (!strcmp(ifname, "wgserver"))
++ return;
++
++ event = kzalloc(sizeof(struct wg_event), GFP_ATOMIC);
++ if (!event)
++ return;
++
++ memcpy(event->ifname, ifname, IFNAMSIZ);
++
++ event->action = action;
++
++ INIT_WORK(&event->work, hotplug_work);
++ schedule_work(&event->work);
++}
+Index: linux-5.4.188/drivers/net/wireguard/hotplug.h
+===================================================================
+--- /dev/null
++++ linux-5.4.188/drivers/net/wireguard/hotplug.h
+@@ -0,0 +1,13 @@
++#ifndef __HOTPLUG_H__
++#define __HOTPLUG_H__
++
++#define REKEY_GIVEUP_EVENT "REKEY-GIVEUP"
++#define REKEY_TIMEOUT_EVENT "REKEY-TIMEOUT"
++#define KEYPAIR_CREATED_EVENT "KEYPAIR-CREATED"
++
++extern void wireguard_hotplug(const char *ifname, const char *action);
++extern void wg_hotplug_init(void);
++extern void wg_hotplug_free(void);
++
++#endif
++
+Index: linux-5.4.188/drivers/net/wireguard/noise.c
+===================================================================
+--- linux-5.4.188.orig/drivers/net/wireguard/noise.c
++++ linux-5.4.188/drivers/net/wireguard/noise.c
+@@ -9,6 +9,7 @@
+ #include "messages.h"
+ #include "queueing.h"
+ #include "peerlookup.h"
++#include "hotplug.h"
+
+ #include <linux/rcupdate.h>
+ #include <linux/slab.h>
+@@ -817,6 +818,8 @@ bool wg_noise_handshake_begin_session(st
+ ret = wg_index_hashtable_replace(
+ handshake->entry.peer->device->index_hashtable,
+ &handshake->entry, &new_keypair->entry);
++
++ wireguard_hotplug(handshake->entry.peer->device->dev->name, KEYPAIR_CREATED_EVENT);
+ } else {
+ kzfree(new_keypair);
+ }
+Index: linux-5.4.188/drivers/net/wireguard/timers.c
+===================================================================
+--- linux-5.4.188.orig/drivers/net/wireguard/timers.c
++++ linux-5.4.188/drivers/net/wireguard/timers.c
+@@ -8,6 +8,7 @@
+ #include "peer.h"
+ #include "queueing.h"
+ #include "socket.h"
++#include "hotplug.h"
+
+ /*
+ * - Timer for retransmitting the handshake if we don't hear back after
+@@ -60,6 +61,8 @@ static void wg_expired_retransmit_handsh
+ if (!timer_pending(&peer->timer_zero_key_material))
+ mod_peer_timer(peer, &peer->timer_zero_key_material,
+ jiffies + REJECT_AFTER_TIME * 3 * HZ);
++
++ wireguard_hotplug(peer->device->dev->name, REKEY_GIVEUP_EVENT);
+ } else {
+ ++peer->timer_handshake_attempts;
+ pr_debug("%s: Handshake for peer %llu (%pISpfsc) did not complete after %d seconds, retrying (try %d)\n",
+@@ -73,6 +76,8 @@ static void wg_expired_retransmit_handsh
+ wg_socket_clear_peer_endpoint_src(peer);
+
+ wg_packet_send_queued_handshake_initiation(peer, true);
++
++ wireguard_hotplug(peer->device->dev->name, REKEY_TIMEOUT_EVENT);
+ }
+ }
+
--
2.25.1

View File

@ -1,4 +1,4 @@
From b8c31ea7a79397802eca863bbfda1a9cca176f60 Mon Sep 17 00:00:00 2001
From 9e780b505183e3f754666adddd77b8084ca7b45b Mon Sep 17 00:00:00 2001
From: Jianhui Zhao <jianhui.zhao@gl-inet.com>
Date: Fri, 1 Jul 2022 11:27:42 +0800
Subject: [PATCH] iwinfo: support mtk private wifi driver
@ -6,9 +6,9 @@ Subject: [PATCH] iwinfo: support mtk private wifi driver
Signed-off-by: Jianhui Zhao <jianhui.zhao@gl-inet.com>
---
package/network/utils/iwinfo/Makefile | 2 +-
.../iwinfo/patches/0100-support-mtk.patch | 42 +++
package/network/utils/iwinfo/src/iwinfo_mtk.c | 294 ++++++++++++++++++
3 files changed, 337 insertions(+), 1 deletion(-)
.../iwinfo/patches/0100-support-mtk.patch | 112 +++++++
package/network/utils/iwinfo/src/iwinfo_mtk.c | 299 ++++++++++++++++++
3 files changed, 412 insertions(+), 1 deletion(-)
create mode 100644 package/network/utils/iwinfo/patches/0100-support-mtk.patch
create mode 100644 package/network/utils/iwinfo/src/iwinfo_mtk.c
@ -27,10 +27,10 @@ index 815c477988..4fa21e7dee 100644
define Build/InstallDev
diff --git a/package/network/utils/iwinfo/patches/0100-support-mtk.patch b/package/network/utils/iwinfo/patches/0100-support-mtk.patch
new file mode 100644
index 0000000000..67e7a639d5
index 0000000000..4c5ebc014c
--- /dev/null
+++ b/package/network/utils/iwinfo/patches/0100-support-mtk.patch
@@ -0,0 +1,42 @@
@@ -0,0 +1,112 @@
+Index: libiwinfo-2021-04-30-c45f0b58/Makefile
+===================================================================
+--- libiwinfo-2021-04-30-c45f0b58.orig/Makefile
@ -73,12 +73,82 @@ index 0000000000..67e7a639d5
+ &wext_ops,
+ };
+
+Index: libiwinfo-2021-04-30-c45f0b58/include/iwinfo/lua.h
+===================================================================
+--- libiwinfo-2021-04-30-c45f0b58.orig/include/iwinfo/lua.h
++++ libiwinfo-2021-04-30-c45f0b58/include/iwinfo/lua.h
+@@ -41,6 +41,9 @@
+ #define IWINFO_NL80211_META "iwinfo.nl80211"
+ #endif
+
++#ifdef USE_MTK
++#define IWINFO_MTK_META "iwinfo.mtk"
++#endif
+
+ #define LUA_REG(type,op) \
+ { #op, iwinfo_L_##type##_##op }
+Index: libiwinfo-2021-04-30-c45f0b58/iwinfo_lua.c
+===================================================================
+--- libiwinfo-2021-04-30-c45f0b58.orig/iwinfo_lua.c
++++ libiwinfo-2021-04-30-c45f0b58/iwinfo_lua.c
+@@ -769,6 +769,15 @@ LUA_WRAP_STRUCT_OP(nl80211,mbssid_suppor
+ LUA_WRAP_STRUCT_OP(nl80211,hardware_id)
+ #endif
+
++#ifdef USE_MTK
++LUA_WRAP_INT_OP(mtk,channel)
++LUA_WRAP_STRING_OP(mtk,ssid)
++LUA_WRAP_STRING_OP(mtk,bssid)
++LUA_WRAP_STRING_OP(mtk,phyname)
++LUA_WRAP_STRUCT_OP(mtk,mode)
++LUA_WRAP_STRUCT_OP(mtk,assoclist)
++#endif
++
+ /* Wext */
+ LUA_WRAP_INT_OP(wext,channel)
+ LUA_WRAP_INT_OP(wext,frequency)
+@@ -896,6 +905,19 @@ static const luaL_reg R_nl80211[] = {
+ };
+ #endif
+
++#ifdef USE_MTK
++/* NL80211 table */
++static const luaL_reg R_mtk[] = {
++ LUA_REG(mtk,channel),
++ LUA_REG(mtk,mode),
++ LUA_REG(mtk,ssid),
++ LUA_REG(mtk,bssid),
++ LUA_REG(mtk,assoclist),
++ LUA_REG(mtk,phyname),
++ { NULL, NULL }
++};
++#endif
++
+ /* Wext table */
+ static const luaL_reg R_wext[] = {
+ LUA_REG(wext,channel),
+@@ -965,6 +987,15 @@ LUALIB_API int luaopen_iwinfo(lua_State
+ lua_setfield(L, -2, "nl80211");
+ #endif
+
++#ifdef USE_MTK
++ luaL_newmetatable(L, IWINFO_MTK_META);
++ luaL_register(L, NULL, R_common);
++ luaL_register(L, NULL, R_mtk);
++ lua_pushvalue(L, -1);
++ lua_setfield(L, -2, "__index");
++ lua_setfield(L, -2, "mtk");
++#endif
++
+ luaL_newmetatable(L, IWINFO_WEXT_META);
+ luaL_register(L, NULL, R_common);
+ luaL_register(L, NULL, R_wext);
diff --git a/package/network/utils/iwinfo/src/iwinfo_mtk.c b/package/network/utils/iwinfo/src/iwinfo_mtk.c
new file mode 100644
index 0000000000..5bc89f0c63
index 0000000000..55f9d28e0c
--- /dev/null
+++ b/package/network/utils/iwinfo/src/iwinfo_mtk.c
@@ -0,0 +1,294 @@
@@ -0,0 +1,299 @@
+#include "iwinfo.h"
+#include "iwinfo_wext.h"
+
@ -304,8 +374,13 @@ index 0000000000..5bc89f0c63
+
+static int mtk_get_phyname(const char *ifname, char *buf)
+{
+ /* No suitable api in wext */
+ strcpy(buf, ifname);
+ if (strstr(ifname, "ra"))
+ strcpy(buf, "ra0");
+ else if (strstr(ifname, "rax"))
+ strcpy(buf, "rax0");
+ else
+ return -1;
+
+ return 0;
+}
+