mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
extend netmode
This commit is contained in:
parent
af98fc8da9
commit
ab2e164c6a
4 changed files with 195 additions and 21 deletions
|
|
@ -17,6 +17,8 @@ l3_mcast_config() {
|
|||
l3_network_config() {
|
||||
logger -s -p user.info -t "netmode" "Generating L3 network configuration"
|
||||
|
||||
wandev="$(uci -q get network.WAN.ifname)"
|
||||
|
||||
# Configure L3 Network Mode
|
||||
uci -q set network.lan=interface
|
||||
uci -q set network.lan.device='br-lan'
|
||||
|
|
@ -36,11 +38,32 @@ l3_network_config() {
|
|||
uci -q delete network.wan.disabled
|
||||
uci -q delete network.wan.username
|
||||
uci -q delete network.wan.password
|
||||
uci -q delete network.wan.ipaddr
|
||||
uci -q delete network.wan.gateway
|
||||
uci -q delete network.wan.netmask
|
||||
|
||||
uci -q set network.wan6=interface
|
||||
uci -q set network.wan6.proto='dhcpv6'
|
||||
uci -q delete network.wan6.disabled
|
||||
|
||||
if [ -n "$wandev" -a -n "$NETMODE_vlanid" -a $NETMODE_vlanid -gt 0 ]; then
|
||||
uci -q set network.vlan_${NETMODE_vlanid}=device
|
||||
uci -q set network.vlan_${NETMODE_vlanid}.type="8021q"
|
||||
uci -q set network.vlan_${NETMODE_vlanid}.name="$wandev.$NETMODE_vlanid"
|
||||
uci -q set network.vlan_${NETMODE_vlanid}.ifname="$wandev"
|
||||
uci -q set network.vlan_${NETMODE_vlanid}.vid=$NETMODE_vlanid
|
||||
|
||||
uci -q set network.wan.device="$wandev.$NETMODE_vlanid"
|
||||
fi
|
||||
|
||||
uci -q delete network.wan.dns
|
||||
if [ -n "$NETMODE_dns_servers" ]; then
|
||||
dns_servers="$(echo $NETMODE_dns_servers | tr ',' ' ')"
|
||||
for server in $dns_servers; do
|
||||
uci -q add_list network.wan.dns=$server
|
||||
done
|
||||
fi
|
||||
|
||||
uci -q delete network.br_lan.ports
|
||||
uci -q set network.br_lan.bridge_empty='1'
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ l3_mcast_config() {
|
|||
l3_network_pppoe_config() {
|
||||
logger -s -p user.info -t "netmode" "Generating L3 network configuration"
|
||||
|
||||
wandev="$(uci -q get network.WAN.ifname)"
|
||||
|
||||
# Configure L3 Network Mode
|
||||
uci -q set network.lan=interface
|
||||
uci -q set network.lan.device='br-lan'
|
||||
|
|
@ -36,9 +38,30 @@ l3_network_pppoe_config() {
|
|||
uci -q set network.wan.username="$NETMODE_username"
|
||||
uci -q set network.wan.password="$NETMODE_password"
|
||||
uci -q delete network.wan.disabled
|
||||
uci -q delete network.wan.ipaddr
|
||||
uci -q delete network.wan.gateway
|
||||
uci -q delete network.wan.netmask
|
||||
|
||||
uci -q set network.wan6.disabled='1'
|
||||
|
||||
if [ -n "$wandev" -a -n "$NETMODE_vlanid" -a $NETMODE_vlanid -gt 0 ]; then
|
||||
uci -q set network.vlan_${NETMODE_vlanid}=device
|
||||
uci -q set network.vlan_${NETMODE_vlanid}.type="8021q"
|
||||
uci -q set network.vlan_${NETMODE_vlanid}.name="$wandev.$NETMODE_vlanid"
|
||||
uci -q set network.vlan_${NETMODE_vlanid}.ifname="$wandev"
|
||||
uci -q set network.vlan_${NETMODE_vlanid}.vid=$NETMODE_vlanid
|
||||
|
||||
uci -q set network.wan.device="$wandev.$NETMODE_vlanid"
|
||||
fi
|
||||
|
||||
uci -q delete network.wan.dns
|
||||
if [ -n "$NETMODE_dns_servers" ]; then
|
||||
dns_servers="$(echo $NETMODE_dns_servers | tr ',' ' ')"
|
||||
for server in $dns_servers; do
|
||||
uci -q add_list network.wan.dns=$server
|
||||
done
|
||||
fi
|
||||
|
||||
uci -q delete network.br_lan.ports
|
||||
uci -q set network.br_lan.bridge_empty='1'
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,128 @@
|
|||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
source "/etc/device_info"
|
||||
|
||||
l3_mcast_config() {
|
||||
# configure L3 mcast config
|
||||
logger -s -p user.info -t "netmode" "Generating L3 mcast configuration"
|
||||
|
||||
rm -f /etc/config/mcast
|
||||
sh /rom/etc/uci-defaults/61-mcast_config_generate
|
||||
uci -q commit mcast
|
||||
}
|
||||
|
||||
l3_network_config() {
|
||||
logger -s -p user.info -t "netmode" "Generating L3 network configuration"
|
||||
|
||||
wandev="$(uci -q get network.WAN.ifname)"
|
||||
|
||||
# Configure L3 Network Mode
|
||||
uci -q set network.lan=interface
|
||||
uci -q set network.lan.device='br-lan'
|
||||
uci -q set network.lan.proto='static'
|
||||
uci -q set network.lan.ipaddr='192.168.1.1'
|
||||
uci -q set network.lan.netmask='255.255.255.0'
|
||||
uci -q set network.lan.ip6assign='60'
|
||||
uci -q delete network.lan.vendorid
|
||||
uci -q delete network.lan.clientid
|
||||
uci -q delete network.lan.reqopts
|
||||
uci -q delete network.lan.sendopts
|
||||
|
||||
uci -q delete network.lan6
|
||||
|
||||
uci -q set network.wan=interface
|
||||
uci -q set network.wan.device="$wandev"
|
||||
uci -q set network.wan.proto='static'
|
||||
uci -q set network.wan.ipaddr="$NETMODE_ipaddr"
|
||||
uci -q set network.wan.gateway="$NETMODE_gateway"
|
||||
uci -q set network.wan.netmask="$NETMODE_netmask"
|
||||
uci -q delete network.wan.disabled
|
||||
uci -q delete network.wan.username
|
||||
uci -q delete network.wan.password
|
||||
|
||||
uci -q set network.wan6.disabled='1'
|
||||
|
||||
uci -q delete network.wan.dns
|
||||
if [ -n "$NETMODE_dns_servers" ]; then
|
||||
dns_servers="$(echo $NETMODE_dns_servers | tr ',' ' ')"
|
||||
for server in $dns_servers; do
|
||||
uci -q add_list network.wan.dns=$server
|
||||
done
|
||||
fi
|
||||
|
||||
uci -q delete network.wan.dns
|
||||
if [ -n "$NETMODE_dns_servers" ]; then
|
||||
IFS=',' read -ra ADDRS <<< "$NETMODE_dns_servers"
|
||||
for ip in "${ADDRS[@]}"; do
|
||||
uci -q add_list network.wan.dns=$ip
|
||||
done
|
||||
fi
|
||||
|
||||
uci -q delete network.br_lan.ports
|
||||
uci -q set network.br_lan.bridge_empty='1'
|
||||
|
||||
add_port_to_br_lan() {
|
||||
port="$1"
|
||||
[ -n "$port" -a -d /sys/class/net/$port ] || continue
|
||||
uci add_list network.br_lan.ports="$port"
|
||||
}
|
||||
|
||||
if [ -f /etc/board.json ]; then
|
||||
json_load_file /etc/board.json
|
||||
json_select network
|
||||
json_select lan
|
||||
if json_is_a ports array; then
|
||||
json_for_each_item add_port_to_br_lan ports
|
||||
else
|
||||
json_get_var device device
|
||||
[ -n "$device" ] && uci add_list network.br_lan.ports="$device"
|
||||
fi
|
||||
json_select ..
|
||||
json_select wan 2>/dev/null
|
||||
json_get_var device device
|
||||
if [ -n "$device" ]; then
|
||||
uci -q set network.wan.device="$device"
|
||||
uci -q set network.wan6.device="$device"
|
||||
fi
|
||||
json_cleanup
|
||||
fi
|
||||
|
||||
uci -q commit network
|
||||
|
||||
# Enable DHCP Server
|
||||
uci -q set dhcp.lan.ignore=0
|
||||
uci -q set dhcp.wan.ignore=1
|
||||
uci -q commit dhcp
|
||||
/etc/init.d/odhcpd enable
|
||||
|
||||
# Enable SSDPD
|
||||
uci -q set ssdpd.ssdp.enabled="1"
|
||||
uci -q commit ssdpd
|
||||
|
||||
# Update CWMP Agent WAN Interface
|
||||
uci -q set cwmp.cpe.default_wan_interface="wan"
|
||||
uci -q commit cwmp
|
||||
|
||||
# Update gateway WAN Interface
|
||||
uci -q set gateway.global.wan_interface="wan"
|
||||
uci -q commit gateway
|
||||
|
||||
# Enable firewall
|
||||
uci -q set firewall.globals.enabled="1"
|
||||
uci -q commit firewall
|
||||
}
|
||||
|
||||
l3_network_config
|
||||
l3_mcast_config
|
||||
|
||||
# If device is already boot-up, assume netmode changed during runtime
|
||||
if [ -f /var/run/boot_complete ]; then
|
||||
/etc/init.d/odhcpd restart 2>/dev/null
|
||||
for config in network dhcp ssdpd cwmp gateway firewall mcast; do
|
||||
ubus call uci commit "{\"config\":\"$config\"}"
|
||||
sleep 1
|
||||
done
|
||||
fi
|
||||
|
|
@ -3,17 +3,17 @@
|
|||
"supported_modes": [
|
||||
{
|
||||
"name": "routed-dhcp",
|
||||
"description": "WAN with DHCP proto (Layer 3)",
|
||||
"description": "DHCP",
|
||||
"supported_args": [
|
||||
{
|
||||
"name": "vlan",
|
||||
"description": "Optional VLAN ID",
|
||||
"name": "vlanid",
|
||||
"description": "VLAN ID",
|
||||
"required": false,
|
||||
"type": "integer"
|
||||
},
|
||||
{
|
||||
"name": "dns-servers",
|
||||
"description": "Optional DNS servers, comma separated",
|
||||
"name": "dns_servers",
|
||||
"description": "DNS Servers, comma separated",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
}
|
||||
|
|
@ -21,31 +21,31 @@
|
|||
},
|
||||
{
|
||||
"name": "routed-pppoe",
|
||||
"description": "WAN with PPPoE (Layer 3)",
|
||||
"description": "PPPoE",
|
||||
"supported_args": [
|
||||
{
|
||||
"name": "username",
|
||||
"description": "PPPoE username",
|
||||
"description": "PPPoE Username",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"#value": "TestUser"
|
||||
},
|
||||
{
|
||||
"name": "password",
|
||||
"description": "PPPoE password",
|
||||
"description": "PPPoE Password",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"#value": "TestPassword"
|
||||
},
|
||||
{
|
||||
"name": "vlan",
|
||||
"description": "Optional VLAN ID",
|
||||
"name": "vlanid",
|
||||
"description": "VLAN ID",
|
||||
"required": false,
|
||||
"type": "integer"
|
||||
},
|
||||
{
|
||||
"name": "dns-servers",
|
||||
"description": "Optional DNS servers, comma separated",
|
||||
"name": "dns_servers",
|
||||
"description": "DNS Servers, comma separated",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
}
|
||||
|
|
@ -53,38 +53,38 @@
|
|||
},
|
||||
{
|
||||
"name": "routed-static",
|
||||
"description": "WAN with static IP configuration (Layer 3)",
|
||||
"description": "Static",
|
||||
"supported_args": [
|
||||
{
|
||||
"name": "ip-address",
|
||||
"description": "Static IP address",
|
||||
"name": "ipaddr",
|
||||
"description": "IP Address",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"#value": "93.21.0.104"
|
||||
},
|
||||
{
|
||||
"name": "netmask",
|
||||
"description": "Subnet mask",
|
||||
"description": "Subnet Mask",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"#value": "255.255.255.0"
|
||||
},
|
||||
{
|
||||
"name": "gateway",
|
||||
"description": "Default gateway",
|
||||
"description": "Default Gateway",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"#value": "93.21.0.1"
|
||||
},
|
||||
{
|
||||
"name": "vlan",
|
||||
"description": "Optional VLAN ID",
|
||||
"name": "vlanid",
|
||||
"description": "VLAN ID",
|
||||
"required": false,
|
||||
"type": "integer"
|
||||
},
|
||||
{
|
||||
"name": "dns-servers",
|
||||
"description": "Optional DNS servers, comma separated",
|
||||
"name": "dns_servers",
|
||||
"description": "DNS servers, comma separated",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue