Re: [OpenWrt-Devel] [PATCH] netifd: proto-dhcp: handle alias interfaces

2018-09-15 Thread Jo-Philipp Wich
Hi,

the functionality seems arbitrary and overly specific to your use case,
also the option name "alias" does not really explain the effects of
setting this option.

IMHO you rather should write/ship a custom /etc/hotplug.d/iface/ script
which deals with downing the fallback alias interface when the main one
successfully sets up.

~ Jo

___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH] netifd: proto-dhcp: handle alias interfaces

2018-09-04 Thread Yury Shvedov
The alias interfaces for interfaces with proto dhcp are very useful for
specialised builds with proto dhcp on lan by default but with backup static
addresses.

The default way has one shortage. It left backup address configured on
interface with address configured by odchp. This can lead to network
overlapping (when dhcp server configured on the same subnet with alias
interface) and to the addresses duplication inside broadcast domain
(when more then one board with same firmware running in subnet).

This patch introduces new option to dhcp proto. Just add

option alias ''

to the interface configuration and it will automatically downs alias
interfaces you specified upon dhcp address receiving.

Signed-off-by: Yury Shvedov 
---
 .../config/netifd/files/lib/netifd/dhcp.script| 11 ++-
 .../config/netifd/files/lib/netifd/proto/dhcp.sh  | 11 +--
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/package/network/config/netifd/files/lib/netifd/dhcp.script 
b/package/network/config/netifd/files/lib/netifd/dhcp.script
index 00604f40e7..8055b472ff 100755
--- a/package/network/config/netifd/files/lib/netifd/dhcp.script
+++ b/package/network/config/netifd/files/lib/netifd/dhcp.script
@@ -14,6 +14,11 @@ set_classless_routes() {
 }
 
 setup_interface () {
+   local i
+   for i in $ALIAS; do
+   ubus call network.interface."$i" down '{}'
+   done
+
proto_init_update "*" 1
proto_add_ipv4_address "$ip" "${subnet:-255.255.255.0}"
# TODO: apply $broadcast
@@ -21,7 +26,6 @@ setup_interface () {
local ip_net
eval "$(ipcalc.sh "$ip/$mask")";ip_net="$NETWORK"
 
-   local i
for i in $router; do
local gw_net
eval "$(ipcalc.sh "$i/$mask")";gw_net="$NETWORK"
@@ -93,6 +97,11 @@ setup_interface () {
 deconfig_interface() {
proto_init_update "*" 0
proto_send_update "$INTERFACE"
+
+   local i
+   for i in $ALIAS; do
+   ubus call network.interface."$i" up '{}'
+   done
 }
 
 case "$1" in
diff --git a/package/network/config/netifd/files/lib/netifd/proto/dhcp.sh 
b/package/network/config/netifd/files/lib/netifd/proto/dhcp.sh
index a2b0ccedbf..15edab13bc 100755
--- a/package/network/config/netifd/files/lib/netifd/proto/dhcp.sh
+++ b/package/network/config/netifd/files/lib/netifd/proto/dhcp.sh
@@ -25,6 +25,7 @@ proto_dhcp_init_config() {
proto_config_add_string mtu6rd
proto_config_add_string customroutes
proto_config_add_boolean classlessroute
+   proto_config_add_string 'alias'
 }
 
 proto_dhcp_add_sendopts() {
@@ -35,8 +36,8 @@ proto_dhcp_setup() {
local config="$1"
local iface="$2"
 
-   local ipaddr hostname clientid vendorid broadcast release reqopts 
defaultreqopts iface6rd sendopts delegate zone6rd zone mtu6rd customroutes 
classlessroute
-   json_get_vars ipaddr hostname clientid vendorid broadcast release 
reqopts defaultreqopts iface6rd delegate zone6rd zone mtu6rd customroutes 
classlessroute
+   local ipaddr hostname clientid vendorid broadcast release reqopts 
defaultreqopts iface6rd sendopts delegate zone6rd zone mtu6rd customroutes 
classlessroute alias
+   json_get_vars ipaddr hostname clientid vendorid broadcast release 
reqopts defaultreqopts iface6rd delegate zone6rd zone mtu6rd customroutes 
classlessroute alias
 
local opt dhcpopts
for opt in $reqopts; do
@@ -60,6 +61,12 @@ proto_dhcp_setup() {
# Request classless route option (see RFC 3442) by default
[ "$classlessroute" = "0" ] || append dhcpopts "-O 121"
 
+   proto_export "ALIAS=$alias"
+   local i
+   for i in $alias; do
+   ubus call network.interface."$i" up '{}'
+   done
+
proto_export "INTERFACE=$config"
proto_run_command "$config" udhcpc \
-p /var/run/udhcpc-$iface.pid \
-- 
2.18.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel