From 27497b14d31f6442a57a47062b80f0d1e09de1e9 Mon Sep 17 00:00:00 2001 From: gl-dengxinfa Date: Thu, 29 Sep 2022 11:50:08 +0800 Subject: [PATCH] ramips: mt1300 v4.1.0 support --- ...0001-fix-scripts-feeds-support-setup.patch | 8 +- ...ix-gl-mt1300-adapts-to-glinet-SDK4.0.patch | 2 +- .../0005-fix-do-not-keep-config.patch | 24 ++ .../0006-fix-wireguard-support-hotplug.patch | 241 ++++++++++++++++++ profiles/glinet_mt1300.yml | 163 +++++++++++- 5 files changed, 432 insertions(+), 6 deletions(-) create mode 100644 patches-22.03.0/0005-fix-do-not-keep-config.patch create mode 100644 patches-22.03.0/0006-fix-wireguard-support-hotplug.patch diff --git a/patches-22.03.0/0001-fix-scripts-feeds-support-setup.patch b/patches-22.03.0/0001-fix-scripts-feeds-support-setup.patch index 88ab730..60560a2 100644 --- a/patches-22.03.0/0001-fix-scripts-feeds-support-setup.patch +++ b/patches-22.03.0/0001-fix-scripts-feeds-support-setup.patch @@ -32,10 +32,6 @@ index aee73e793f..4b68b5e930 100755 + + open(my $fd, ">>feeds.conf"); + -+ if ($opts{b}) { -+ printf $fd "src-include defaults feeds.conf.default\n"; -+ } -+ + while (my $entry = shift @ARGV) { + my ($type, $name, $src) = split /,/, $entry; + @@ -53,6 +49,10 @@ index aee73e793f..4b68b5e930 100755 + printf $fd "%s %s %s\n", $type, $name, $src; + } + ++ if ($opts{b}) { ++ printf $fd "src-include defaults feeds.conf.default\n"; ++ } ++ + return 0; +} + diff --git a/patches-22.03.0/0003-fix-gl-mt1300-adapts-to-glinet-SDK4.0.patch b/patches-22.03.0/0003-fix-gl-mt1300-adapts-to-glinet-SDK4.0.patch index a3a12e3..8cf882c 100644 --- a/patches-22.03.0/0003-fix-gl-mt1300-adapts-to-glinet-SDK4.0.patch +++ b/patches-22.03.0/0003-fix-gl-mt1300-adapts-to-glinet-SDK4.0.patch @@ -41,7 +41,7 @@ index 384da1bfa9..23c5be89c8 100644 + radio = "radio0"; + usb-port = "1-1"; + factory_data { -+ device_mac = "factory", "0x04"; ++ device_mac = "factory", "0x4000"; + device_ddns = "factory", "0x4010"; + device_sn_bak = "factory", "0x4020"; + device_sn = "factory", "0x4030"; diff --git a/patches-22.03.0/0005-fix-do-not-keep-config.patch b/patches-22.03.0/0005-fix-do-not-keep-config.patch new file mode 100644 index 0000000..1644c0a --- /dev/null +++ b/patches-22.03.0/0005-fix-do-not-keep-config.patch @@ -0,0 +1,24 @@ +From 0cc3433812dc4132876ae4edd930bec97bd6308c Mon Sep 17 00:00:00 2001 +From: gl-dengxinfa +Date: Wed, 28 Sep 2022 17:13:22 +0800 +Subject: [PATCH] fix: do not keep config + +--- + package/base-files/files/lib/preinit/80_mount_root | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/package/base-files/files/lib/preinit/80_mount_root b/package/base-files/files/lib/preinit/80_mount_root +index c3816c2cbf..62a1a4bf32 100644 +--- a/package/base-files/files/lib/preinit/80_mount_root ++++ b/package/base-files/files/lib/preinit/80_mount_root +@@ -17,6 +17,7 @@ missing_lines() { + do_mount_root() { + mount_root + boot_run_hook preinit_mount_root ++ return + [ -f /sysupgrade.tgz -o -f /tmp/sysupgrade.tar ] && { + echo "- config restore -" + cp /etc/passwd /etc/group /etc/shadow /tmp +-- +2.34.1 + diff --git a/patches-22.03.0/0006-fix-wireguard-support-hotplug.patch b/patches-22.03.0/0006-fix-wireguard-support-hotplug.patch new file mode 100644 index 0000000..159ec15 --- /dev/null +++ b/patches-22.03.0/0006-fix-wireguard-support-hotplug.patch @@ -0,0 +1,241 @@ +From 0d2f4bdd2bb401ec0635321bfa033703e869ea10 Mon Sep 17 00:00:00 2001 +From: gl-dengxinfa +Date: Thu, 29 Sep 2022 11:45:43 +0800 +Subject: [PATCH] fix: wireguard support hotplug + +--- + .../856-wireguard-support-hotplug.patch | 222 ++++++++++++++++++ + 1 file changed, 222 insertions(+) + create mode 100644 target/linux/ramips/patches-5.10/856-wireguard-support-hotplug.patch + +diff --git a/target/linux/ramips/patches-5.10/856-wireguard-support-hotplug.patch b/target/linux/ramips/patches-5.10/856-wireguard-support-hotplug.patch +new file mode 100644 +index 0000000000..0de25b62ec +--- /dev/null ++++ b/target/linux/ramips/patches-5.10/856-wireguard-support-hotplug.patch +@@ -0,0 +1,222 @@ ++--- a/drivers/net/wireguard/Makefile +++++ b/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 ++--- /dev/null +++++ b/drivers/net/wireguard/hotplug.c ++@@ -0,0 +1,124 @@ +++/* +++ * oui-tertf Hotplug driver +++ * +++ */ +++ +++#include +++#include +++#include +++#include +++ +++#include +++#include +++#include +++#include +++ +++#include +++ +++#define SUBSYSTEM_NAME "wireguard" +++ +++ +++#define BH_SKB_SIZE 2048 +++#define IFNAMSIZ 16 +++ +++struct work_struct wg_event_work; +++struct wg_event { +++ struct work_struct work; +++ char ifname[IFNAMSIZ]; +++ const char *action; +++}; +++struct wg_event *gl_wg_event; +++ +++static DEFINE_SPINLOCK(event_lock); +++ +++ +++/* -------------------------------------------------------------------------*/ +++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 wireguard_send_hotplug(struct work_struct *mywork) +++{ +++ struct wg_event * event; +++ struct sk_buff *skb; +++ char ifname[IFNAMSIZ]; +++ char *action; +++ +++ event = container_of(mywork, struct wg_event, work); +++ if (!event) +++ return; +++ skb = alloc_skb(BH_SKB_SIZE, GFP_KERNEL); +++ if (!skb) +++ return; +++ strcpy(ifname, event->ifname); +++ action = event->action; +++ +++ pr_info("wireguard-hotplug IFNAME=%s ACTION=%s\n", ifname, action); +++ +++ bh_event_add_var(skb, 0, "SUBSYSTEM=%s", SUBSYSTEM_NAME); +++ +++ spin_lock(&event_lock); +++ bh_event_add_var(skb, 0, "ACTION=%s", action); +++ bh_event_add_var(skb, 0, "ifname=%s", ifname); +++ spin_unlock(&event_lock); +++ +++ NETLINK_CB(skb).dst_group = 1; +++ broadcast_uevent(skb, 0, 1, GFP_KERNEL); +++} +++ +++void wireguard_hotplug(const char *ifname, const char *action) +++{ +++ if(gl_wg_event == NULL){ +++ return; +++ } +++ if (0 == strcmp(ifname,"wgserver")) +++ return; +++ +++ spin_lock(&event_lock); +++ memcpy(gl_wg_event->ifname, ifname, IFNAMSIZ); +++ gl_wg_event->action = action; +++ spin_unlock(&event_lock); +++ +++ schedule_work(&gl_wg_event->work); +++} +++ +++void wg_hotplug_init(void) +++{ +++ gl_wg_event = (struct wg_event *)kzalloc(sizeof(struct wg_event),GFP_KERNEL); +++ if(gl_wg_event == NULL){ +++ return; +++ } +++ gl_wg_event->work = wg_event_work; +++ INIT_WORK(&gl_wg_event->work, wireguard_send_hotplug); +++} +++ +++void wg_hotplug_free(void) +++{ +++ if(gl_wg_event){ +++ kfree(gl_wg_event); +++ } +++ return; +++} ++--- /dev/null +++++ b/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 +++ ++--- a/drivers/net/wireguard/main.c +++++ b/drivers/net/wireguard/main.c ++@@ -17,6 +17,8 @@ ++ #include ++ #include ++ +++#include "hotplug.h" +++ ++ static int __init mod_init(void) ++ { ++ int ret; ++@@ -44,6 +46,7 @@ static int __init mod_init(void) ++ ret = wg_genetlink_init(); ++ if (ret < 0) ++ goto err_netlink; +++ wg_hotplug_init(); ++ ++ pr_info("WireGuard " WIREGUARD_VERSION " loaded. See www.wireguard.com for information.\n"); ++ pr_info("Copyright (C) 2015-2019 Jason A. Donenfeld . All Rights Reserved.\n"); ++@@ -62,6 +65,7 @@ err_allowedips: ++ ++ static void __exit mod_exit(void) ++ { +++ wg_hotplug_free(); ++ wg_genetlink_uninit(); ++ wg_device_uninit(); ++ wg_peer_uninit(); ++--- a/drivers/net/wireguard/noise.c +++++ b/drivers/net/wireguard/noise.c ++@@ -9,6 +9,7 @@ ++ #include "messages.h" ++ #include "queueing.h" ++ #include "peerlookup.h" +++#include "hotplug.h" ++ ++ #include ++ #include ++@@ -850,6 +851,7 @@ 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 { ++ kfree_sensitive(new_keypair); ++ } ++--- a/drivers/net/wireguard/timers.c +++++ b/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,7 @@ 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 +75,7 @@ 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.34.1 + diff --git a/profiles/glinet_mt1300.yml b/profiles/glinet_mt1300.yml index 0ed23b4..b286f3b 100644 --- a/profiles/glinet_mt1300.yml +++ b/profiles/glinet_mt1300.yml @@ -6,5 +6,166 @@ feeds: branch: v4.1.0 - name: gl_feed_common uri: https://github.com/gl-inet/gl-feeds.git - revision: 1c390c8a9f58a5e0a89998555956c894c7a5ff1f + revision: 963d8afb636623832371dd0ea920d52afca75421 +packages: + - kmod-ipt-offload + - kmod-usb-storage + - kmod-usb-uhci + - kmod-usb2 + - kmod-usb-ohci + - kmod-gl-sdk4-hw-info + - kmod-gl-sdk4-tertf + - dnsmasq-full + - mwan3 + - iwinfo + - block-mount + - blkid + - ntfs-3g + - ntfs-3g-utils + - kmod-fs-ext4 + - kmod-fs-ntfs + - kmod-fs-vfat + - kmod-fs-exfat + - kmod-inet-diag + - iptables-mod-tproxy + - iptables-mod-filter + - i2c-tools + - tor:gl_feed_common + - smstools3:packages + - gl-oui-rpc + - gl-sdk4-luci + - gl-sdk4-rtty + - gl-sdk4-cable + - gl-sdk4-clients + - gl-sdk4-modem + - gl-sdk4-wifi + - gl-sdk4-switch-button + - gl-sdk4-netmode + - gl-sdk4-base-files + - gl-sdk4-tethering + - gl-sdk4-upgrade + - gl-sdk4-ovpn-client + - gl-sdk4-ovpn-server + - gl-sdk4-wg-client + - gl-sdk4-wg-server + - gl-sdk4-macclone + - gl-sdk4-ddns + - gl-sdk4-plugins + - gl-sdk4-firewall + - gl-sdk4-repeater + - gl-sdk4-dns + - gl-sdk4-system + - gl-sdk4-network + - gl-sdk4-acl + - gl-sdk4-mqtt + - gl-sdk4-cloud + - gl-sdk4-lan + - gl-sdk4-ipv6 + - gl-sdk4-upgrade + - gl-sdk4-vpn-policy + - gl-sdk4-logread + - gl-sdk4-qos + - gl-sdk4-cloud-batch-manage + - gl-sdk4-network-diag + - gl-sdk4-carrier-monitor + - gl-sdk4-init-portal + - gl-sdk4-s2s + - gl-sdk4-edgerouter + - gl-sdk4-mwan3 + - gl-sdk4-timer + - gl-sdk4-tor + - gl-sdk4-igmp + - gl-sdk4-ui-adminpw + - gl-sdk4-ui-advanced + - gl-sdk4-ui-bridge + - gl-sdk4-ui-btnsettings + - gl-sdk4-ui-clients + - gl-sdk4-ui-cloud + - gl-sdk4-ui-core + - gl-sdk4-ui-dnsview + - gl-sdk4-ui-dynamicdns + - gl-sdk4-ui-edgerouter + - gl-sdk4-ui-firewallview + - gl-sdk4-ui-home + - gl-sdk4-ui-igmp + - gl-sdk4-ui-internet + - gl-sdk4-ui-ipv6 + - gl-sdk4-ui-lanip + - gl-sdk4-ui-login + - gl-sdk4-ui-logview + - gl-sdk4-ui-macclone + - gl-sdk4-ui-modemmanage + - gl-sdk4-ui-multiwan + - gl-sdk4-ui-nasview + - gl-sdk4-ui-overview + - gl-sdk4-ui-ovpnclient + - gl-sdk4-ui-ovpnserver + - gl-sdk4-ui-plugins + - gl-sdk4-ui-process + - gl-sdk4-ui-reset + - gl-sdk4-ui-timedtask + - gl-sdk4-ui-timezone + - gl-sdk4-ui-torview + - gl-sdk4-ui-upgrade + - gl-sdk4-ui-vlan + - gl-sdk4-ui-vpndashboard + - gl-sdk4-ui-welcome + - gl-sdk4-ui-wgclient + - gl-sdk4-ui-wgserver + - gl-sdk4-ui-wireless + - gl-sdk4-ui-hwnat + - gl-sdk4-nas-utils + - gl-sdk4-nas-web + - gl-sdk4-exfat-utils + - gl-sdk4-webdav + - kmod-usb-storage-uas + - dosfstools + - e2fsprogs + - minidlna + +diffconfig: | + CONFIG_SIGNATURE_CHECK=n + CONFIG_PACKAGE_dnsmasq=n + CONFIG_PACKAGE_wpad-basic=n + CONFIG_PACKAGE_wpad=n + CONFIG_BUSYBOX_CUSTOM=y + CONFIG_BUSYBOX_CONFIG_FEATURE_FLOAT_SLEEP=y + CONFIG_NGINX_HTTP_CHARSET=n + CONFIG_NGINX_HTTP_GZIP=n + CONFIG_NGINX_HTTP_SSI=n + CONFIG_NGINX_HTTP_USERID=n + CONFIG_NGINX_HTTP_ACCESS=n + CONFIG_NGINX_HTTP_AUTH_BASIC=n + CONFIG_NGINX_HTTP_AUTOINDEX=n + CONFIG_NGINX_HTTP_GEO=n + CONFIG_NGINX_HTTP_MAP=n + CONFIG_NGINX_HTTP_SPLIT_CLIENTS=n + CONFIG_NGINX_HTTP_REFERER=n + CONFIG_NGINX_HTTP_REWRITE=n + CONFIG_NGINX_HTTP_FASTCGI=n + CONFIG_NGINX_HTTP_SCGI=n + CONFIG_NGINX_HTTP_MEMCACHED=n + CONFIG_NGINX_HTTP_LIMIT_CONN=n + CONFIG_NGINX_HTTP_LIMIT_REQ=n + CONFIG_NGINX_HTTP_EMPTY_GIF=n + CONFIG_NGINX_HTTP_BROWSER=n + CONFIG_NGINX_HTTP_UPSTREAM_HASH=n + CONFIG_NGINX_HTTP_UPSTREAM_IP_HASH=n + CONFIG_NGINX_HTTP_UPSTREAM_LEAST_CONN=n + CONFIG_NGINX_HTTP_UPSTREAM_KEEPALIVE=n + CONFIG_NGINX_HTTP_CACHE=n + CONFIG_NGINX_NAXSI=n + CONFIG_NGINX_HEADERS_MORE=n + CONFIG_LIBCURL_MBEDTLS=n + CONFIG_LIBCURL_OPENSSL=y + CONFIG_OPENSSL_OPTIMIZE_SPEED=y + CONFIG_LUCI_LANG_zh_Hans=y + CONFIG_PACKAGE_wpad-basic-wolfssl=n + CONFIG_BUSYBOX_CONFIG_ADDGROUP=y + CONFIG_BUSYBOX_CONFIG_FEATURE_ADDUSER_TO_GROUP=y + CONFIG_BUSYBOX_CONFIG_ADDUSER=y + CONFIG_BUSYBOX_CONFIG_CHPASSWD=y + CONFIG_BUSYBOX_CONFIG_DELUSER=y + CONFIG_BUSYBOX_CONFIG_DELGROUP=y + CONFIG_BUSYBOX_CONFIG_FEATURE_DEL_USER_FROM_GROUP=y