Skip to content

Instantly share code, notes, and snippets.

@1-1-2
Last active April 11, 2024 14:53
Show Gist options
  • Save 1-1-2/335dbc8e138f39fb8fe6243d424fe476 to your computer and use it in GitHub Desktop.
Save 1-1-2/335dbc8e138f39fb8fe6243d424fe476 to your computer and use it in GitHub Desktop.
Experimental patches for JDCloud Router(s)
--- ./openwrt/target/linux/ramips/mt7621/base-files/etc/board.d/02_network 2023-12-15 22:05:46.668367604 +0800
+++ ./patch_test/02_network 2023-12-31 16:57:11.667111818 +0800
@@ -23,6 +23,7 @@
xiaomi,mi-router-3-pro|\
xiaomi,mi-router-ac2100|\
xiaomi,mi-router-cr6606|\
+ jdcloud,re-cp-02|\
xiaomi,mi-router-cr6608|\
xiaomi,mi-router-cr6609|\
xiaomi,redmi-router-ac2100|\
@@ -188,6 +189,11 @@
zbtlink,zbt-wg3526-32m)
label_mac=$(mtd_get_mac_binary factory 0x4)
;;
+ jdcloud,re-cp-02)
+ wan_mac=$(mtd_get_mac_binary factory 0x80f4)
+ lan_mac=$(mtd_get_mac_binary factory 0x80fa)
+ label_mac=$lan_mac
+ ;;
ampedwireless,ally-00x19k)
lan_mac=$(mtd_get_mac_ascii hwconfig HW.LAN.MAC.Address)
label_mac=$lan_mac
--- 02_network openwrt/blob/e6b72de70367044260a6077bba3a91da463feaab/target/linux/ramips/mt7621/base-files/etc/board.d/02_network
+++ 02_network
@@ -69,6 +69,7 @@
glinet,gl-mt1300|\
iptime,a3002mesh|\
jcg,q20|\
+ jdcloud,re-sp-01b|\
lenovo,newifi-d1|\
mikrotik,routerboard-m33g|\
mts,wg430223|\
@@ -322,6 +322,11 @@
;;
+ jdcloud,re-sp-01b)
+ lan_mac=$(mtd_get_mac_ascii config mac)
+ wan_mac=$(macaddr_add "$lan_mac" 1)
+ label_mac=$lan_mac
+ ;;
esac
[ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
--- mt7621.mk openwrt/blob/e6b72de70367044260a6077bba3a91da463feaab/target/linux/ramips/image/mt7621.mk
+++ mt7621.mk
@@ -157,6 +157,15 @@
IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
endef
+define Device/jdcloud_re-cp-02
+ $(Device/dsa-migration)
+ IMAGE_SIZE := 16192k
+ DEVICE_VENDOR := JDCloud
+ DEVICE_MODEL := Luban
+ DEVICE_PACKAGES := kmod-mt7915e kmod-mt7915-firmware kmod-sdhci-mt7620
+endef
+TARGET_DEVICES += jdcloud_re-cp-02
+
define Device/adslr_g7
$(Device/dsa-migration)
IMAGE_SIZE := 16064k
--- mt7621.mk openwrt/blob/e6b72de70367044260a6077bba3a91da463feaab/target/linux/ramips/image/mt7621.mk
+++ mt7621.mk
@@ -157,6 +157,15 @@
IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
endef
+define Device/jdcloud_re-sp-01b
+ $(Device/dsa-migration)
+ IMAGE_SIZE := 32448k
+ DEVICE_VENDOR := JDCloud
+ DEVICE_MODEL := RE-SP-01B
+ DEVICE_PACKAGES := kmod-mt7603 kmod-mt7615-firmware kmod-sdhci-mt7620 kmod-usb3
+endef
+TARGET_DEVICES += jdcloud_re-sp-01b
+
define Device/adslr_g7
$(Device/dsa-migration)
IMAGE_SIZE := 16064k
// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
// Ref: https://github.com/lyq1996/openwrt/blob/master-jdcloud-re-cp-02/target/linux/ramips/dts/mt7621_jdcloud_re-cp-02.dts
#include "mt7621.dtsi"
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
/ {
compatible = "jdcloud,re-cp-02", "mediatek,mt7621-soc";
model = "JDCloud RE-CP-02";
aliases {
led-boot = &led_red;
led-failsafe = &led_red;
led-running = &led_green;
led-upgrade = &led_blue;
label-mac-device = &gmac0;
};
chosen {
bootargs = "console=ttyS0,115200";
};
keys {
compatible = "gpio-keys";
reset {
label = "reset";
gpios = <&gpio 18 GPIO_ACTIVE_LOW>;
linux,code = <KEY_RESTART>;
};
wps {
label = "wps";
gpios = <&gpio 15 GPIO_ACTIVE_LOW>;
linux,code = <KEY_WPS_BUTTON>;
};
};
leds {
compatible = "gpio-leds";
led_red: red {
label = "red:sys";
gpios = <&gpio 6 GPIO_ACTIVE_LOW>;
panic-indicator;
};
led_green: green {
label = "green:sys";
gpios = <&gpio 8 GPIO_ACTIVE_LOW>;
};
led_blue: blue {
label = "blue:sys";
gpios = <&gpio 7 GPIO_ACTIVE_LOW>;
};
};
};
&sdhci {
status = "okay";
};
&spi0 {
status = "okay";
flash@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <10000000>;
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
partition@0 {
label = "u-boot";
reg = <0x00 0x20000>;
read-only;
};
factory: partition@20000 {
label = "factory";
reg = <0x20000 0x10000>;
read-only;
compatible = "nvmem-cells";
#address-cells = <1>;
#size-cells = <1>;
};
partition@30000 {
compatible = "denx,uimage";
label = "firmware";
reg = <0x30000 0xfd0000>;
};
};
};
};
&switch0 {
ports {
port@1 {
status = "okay";
label = "lan1";
};
port@2 {
status = "okay";
label = "lan2";
};
port@3 {
status = "okay";
label = "lan3";
};
port@4 {
status = "okay";
label = "wan";
mtd-mac-address = <&factory 0x80f4>;
};
};
};
&pcie {
status = "okay";
};
&pcie1 {
wifi@0,0 {
compatible = "mediatek,mt76";
reg = <0x0000 0 0 0 0>;
mediatek,mtd-eeprom = <&factory 0x0>;
};
};
&gmac0 {
mtd-mac-address = <&factory 0x80fa>;
};
&state_default {
gpio {
groups = "i2c";
function = "gpio";
};
};
// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
#include "mt7621.dtsi"
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
/ {
compatible = "jdcloud,re-sp-01b", "mediatek,mt7621-soc";
model = "JDCloud RE-SP-01B";
aliases {
led-boot = &led_red;
led-failsafe = &led_red;
led-running = &led_green;
led-upgrade = &led_blue;
};
chosen {
bootargs = "console=ttyS0,115200";
};
keys {
compatible = "gpio-keys";
reset {
label = "reset";
gpios = <&gpio 18 GPIO_ACTIVE_LOW>;
linux,code = <KEY_RESTART>;
};
};
leds {
compatible = "gpio-leds";
led_red: red {
label = "red:sys";
gpios = <&gpio 6 GPIO_ACTIVE_LOW>;
panic-indicator;
};
led_green: green {
label = "green:sys";
gpios = <&gpio 8 GPIO_ACTIVE_LOW>;
};
led_blue: blue {
label = "blue:sys";
gpios = <&gpio 12 GPIO_ACTIVE_LOW>;
};
};
};
&sdhci {
status = "okay";
};
&spi0 {
status = "okay";
flash@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <50000000>;
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
partition@0 {
label = "u-boot";
reg = <0x0 0x30000>;
read-only;
};
partition@30000 {
label = "config";
reg = <0x30000 0x10000>;
read-only;
};
factory: partition@40000 {
label = "factory";
reg = <0x40000 0x10000>;
read-only;
compatible = "nvmem-cells";
#address-cells = <1>;
#size-cells = <1>;
};
partition@50000 {
compatible = "denx,uimage";
label = "firmware";
reg = <0x50000 0x1fb0000>;
};
};
};
};
&switch0 {
ports {
port@0 {
status = "okay";
label = "wan";
};
port@1 {
status = "okay";
label = "lan1";
};
port@2 {
status = "okay";
label = "lan2";
};
};
};
&pcie {
status = "okay";
};
&pcie0 {
wifi@0,0 {
compatible = "mediatek,mt76";
reg = <0x0000 0 0 0 0>;
mediatek,mtd-eeprom = <&factory 0x0>;
};
};
&pcie1 {
wifi@0,0 {
compatible = "mediatek,mt76";
reg = <0x0000 0 0 0 0>;
mediatek,mtd-eeprom = <&factory 0x8000>;
ieee80211-freq-limit = <5000000 6000000>;
};
};
&state_default {
gpio {
groups = "uart2", "uart3", "wdt";
function = "gpio";
};
};
--- n2n.init.sh
+++ n2n.init_mod.sh
@@ -1,6 +1,9 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2008-2020 OpenWrt.org
# Copyright (C) 2022 ImmortalWrt.org
+# 20230106 mod by 1-1-2
+# 在有nftables的设备上好像不需要添加防火墙规则。。。
+# 所以都注释掉了
START=99
USE_PROCD=1
@@ -57,9 +60,13 @@
procd_set_param respawn
procd_close_instance
- iptables -I FORWARD -i "$tunname" -j ACCEPT -m comment --comment 'n2n edge eth'
- iptables -I FORWARD -o "$tunname" -j ACCEPT -m comment --comment 'n2n edge eth'
- [ "$masquerade" = "0" ] || iptables -t nat -I POSTROUTING -o "$tunname" -j MASQUERADE -m comment --comment 'n2n edge net'
+ # iptables -I FORWARD -i "$tunname" -j ACCEPT -m comment --comment 'n2n edge eth'
+ # nft add rule inet fw4 forward iifname "$tunname" accept comment 'n2n edge eth'
+ # iptables -I FORWARD -o "$tunname" -j ACCEPT -m comment --comment 'n2n edge eth'
+ # nft add rule inet fw4 forward oifname "$tunname" accept comment 'n2n edge eth'
+
+ # [ "$masquerade" = "0" ] || iptables -t nat -I POSTROUTING -o "$tunname" -j MASQUERADE -m comment --comment 'n2n edge net'
+ # [ "$masquerade" = "0" ] || nft add rule inet fw4 srcnat oif "$tunname" masquerade
;;
supernode)
local enabled
@@ -82,7 +89,8 @@
procd_set_param respawn
procd_close_instance
- iptables -I INPUT -p udp --dport $port -j ACCEPT -m comment --comment 'n2n supernode port'
+ # iptables -I INPUT -p udp --dport $port -j ACCEPT -m comment --comment 'n2n supernode port'
+ # nft add rule inet fw4 input udp dport "$port" accept comment 'n2n supernode port'
;;
route)
local enabled
@@ -110,15 +118,19 @@
config_get tunname "$cfg" 'tunname'
config_get_bool masquerade "$cfg" 'masquerade' '0'
- iptables -D FORWARD -i "$tunname" -j ACCEPT -m comment --comment 'n2n edge eth' 2>/dev/null
- iptables -D FORWARD -o "$tunname" -j ACCEPT -m comment --comment 'n2n edge eth' 2>/dev/null
- iptables -t nat -D POSTROUTING -o "$tunname" -j MASQUERADE -m comment --comment 'n2n edge net' 2>"/dev/null"
+ # iptables -D FORWARD -i "$tunname" -j ACCEPT -m comment --comment 'n2n edge eth' 2>/dev/null
+ # nft delete rule inet fw4 forward iif "$tunname" accept comment 'n2n edge eth'
+ # iptables -D FORWARD -o "$tunname" -j ACCEPT -m comment --comment 'n2n edge eth' 2>/dev/null
+ # nft delete rule inet fw4 forward oif "$tunname" accept comment 'n2n edge eth'
+ # iptables -t nat -D POSTROUTING -o "$tunname" -j MASQUERADE -m comment --comment 'n2n edge net' 2>"/dev/null"
+ # nft delete rule inet fw4 srcnat oif "$tunname" masquerade comment 'n2n edge net'
;;
supernode)
local port
config_get port "$cfg" 'port'
- iptables -D INPUT -p udp --dport "$port" -j ACCEPT -m comment --comment 'n2n supernode port' 2>"/dev/null"
+ # iptables -D INPUT -p udp --dport "$port" -j ACCEPT -m comment --comment 'n2n supernode port' 2>"/dev/null"
+ # nft delete rule inet fw4 input udp dport "$port" accept comment 'n2n supernode port'
;;
esac
}
Statement
For experimental use only. Illegal use is prohibited!
--- system.sh openwrt/blob/e6b72de70367044260a6077bba3a91da463feaab/package/base-files/files/lib/functions/system.sh
+++ system.sh
@@ -73,7 +73,7 @@
return
fi
- mac_dirty=$(strings "$part" | sed -n 's/^'"$key"'=//p')
+ mac_dirty=$(strings "$part" | sed -n 's/^'"$key"'=//p' | head -n1)
# "canonicalize" mac
[ -n "$mac_dirty" ] && macaddr_canonicalize "$mac_dirty"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment