From 9cd4a78effcfe6089bd23808d9d3120d898b4a7a Mon Sep 17 00:00:00 2001 From: Monika-Research Date: Fri, 10 Nov 2023 16:24:11 +0400 Subject: [PATCH 1/4] Include comms.setting support for MPTCP Make BRIDGE as radio specific config from global config Signed-off-by: Monika-Research --- .../src/nats/scripts/cli_settings_request.py | 8 ++++++- .../src/nats/src/comms_settings.py | 22 ++++++++++++++----- .../src/nats/src/validation.py | 11 ++++++++++ 3 files changed, 34 insertions(+), 7 deletions(-) mode change 100644 => 100755 modules/sc-mesh-secure-deployment/src/nats/src/validation.py diff --git a/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_settings_request.py b/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_settings_request.py index 30cf29d5b..749eb7617 100644 --- a/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_settings_request.py +++ b/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_settings_request.py @@ -19,6 +19,7 @@ async def main(): "frequency": "2412", "frequency_mcc": "2412", # multiradio not supporting "routing": "batman-adv", + "mptcp": "disable", "priority": "long_range", "ip": "10.20.15.3", "subnet": "255.255.255.0", @@ -26,6 +27,7 @@ async def main(): "mode": "mesh", # ap+mesh_scc, mesh, halow "mesh_vif": "wlp2s0", "batman_iface": "bat0", + "bridge": "br-lan bat0 eth1 lan1 eth0 usb0", }, { "radio_index": "1", @@ -36,6 +38,7 @@ async def main(): "frequency": "5220", "frequency_mcc": "2412", # multiradio not supporting "routing": "batman-adv", + "mptcp": "disable", "priority": "long_range", "ip": "10.20.15.3", "subnet": "255.255.255.0", @@ -43,6 +46,7 @@ async def main(): "mode": "mesh", # ap+mesh_scc, mesh, halow "mesh_vif": "wlp3s0", # this needs to be correct "batman_iface": "bat0", + "bridge": "br-lan bat0 eth1 lan1 eth0 usb0", }, { "radio_index": "2", @@ -53,6 +57,7 @@ async def main(): "frequency": "5190", "frequency_mcc": "2412", # multiradio not supporting "routing": "batman-adv", + "mptcp": "disable", "priority": "long_range", "ip": "10.20.15.3", "subnet": "255.255.255.0", @@ -60,9 +65,10 @@ async def main(): "mode": "halow", # ap+mesh_scc, mesh, halow "mesh_vif": "halow1", "batman_iface": "bat0", + "bridge": "br-lan bat0 eth1 lan1 eth0 usb0", }, ], - "bridge": "br-lan bat0 eth1 lan1 eth0 usb0" + } cmd = json.dumps(cmd_dict) diff --git a/modules/sc-mesh-secure-deployment/src/nats/src/comms_settings.py b/modules/sc-mesh-secure-deployment/src/nats/src/comms_settings.py index 0f73375e3..c9a37a8da 100644 --- a/modules/sc-mesh-secure-deployment/src/nats/src/comms_settings.py +++ b/modules/sc-mesh-secure-deployment/src/nats/src/comms_settings.py @@ -40,9 +40,10 @@ def __init__(self, comms_status: [cs.CommsStatus, ...], logger): self.priority = [] self.role: str = "" self.mesh_vif = [] + self.mptcp = [] # self.phy = [] self.batman_iface = [] - self.bridge: str = "" + self.bridge = [] self.msversion: str = "" self.delay: str = "" # delay for channel change self.comms_status = comms_status @@ -110,6 +111,10 @@ def validate_mesh_settings(self, index: int) -> (str, str): return "FAIL", "Invalid mesh vif" self.logger.debug("validate mesh settings mesh vif ok") + if validation.validate_mptcp(self.mptcp[index]) is False: + return "FAIL", "Invalid mptcp value" + self.logger.debug("validate mesh settings mptcp ok") + # if validation.validate_phy(self.phy[index]) is False: # return "FAIL", "Invalid phy" # self.logger.debug("validate mesh settings phy ok") @@ -138,8 +143,10 @@ def __clean_all_settings(self) -> None: self.routing: [str, ...] = [] self.priority: [str, ...] = [] self.mesh_vif: [str, ...] = [] + self.mptcp: [str, ...] = [] # self.phy = [] self.batman_iface: [str, ...] = [] + self.bridge: [str, ...] = [] def handle_mesh_settings_channel_change( self, msg: str, path="/opt", file="mesh_stored.conf" @@ -235,10 +242,10 @@ def handle_mesh_settings( self.routing.append(quote(str(parameters["routing"]))) self.priority.append(quote(str(parameters["priority"]))) self.mesh_vif.append(quote(str(parameters["mesh_vif"]))) + self.mptcp.append(quote(str(parameters["mptcp"]))) # self.phy.append(quote(str(parameters["phy"]))) self.batman_iface.append(quote(str(parameters["batman_iface"]))) - - self.bridge = quote(str(parameters_set["bridge"])) + self.bridge.append(str(parameters["bridge"])) for index in self.radio_index: self.logger.debug("Mesh settings validation index: %s", str(index)) @@ -329,11 +336,12 @@ def __save_settings(self, path: str, file: str, index: int) -> (str, str): mesh_conf.write( f"id{str(index)}_MESH_VIF={quote(self.mesh_vif[index])}\n" ) + mesh_conf.write(f"id{str(index)}_MPTCP={quote(self.mptcp[index])}\n") # mesh_conf.write(f"id{str(index)}_PHY={quote(self.phy[index])}\n") mesh_conf.write( f"id{str(index)}_BATMAN_IFACE={quote(self.batman_iface[index])}\n" ) - mesh_conf.write(f"BRIDGE={self.bridge}\n") + mesh_conf.write(f"id{str(index)}_BRIDGE={quote(self.bridge[index])}\n") except: self.comms_status[index].mesh_cfg_status = comms.STATUS.mesh_cfg_not_stored @@ -379,17 +387,19 @@ def __read_configs(self, mesh_conf_lines) -> None: self.priority.append(match[1]) elif name == "MESH_VIF": self.mesh_vif.append(match[1]) + elif name == "MPTCP": + self.mptcp.append(match[1]) # elif name == "PHY": # self.phy.append(match[1]) elif name == "BATMAN_IFACE": self.batman_iface.append(match[1]) + elif name == "BRIDGE": + self.bridge.append(match[1]) else: self.logger.error("unknown config parameter: %s", name) else: # global config without index if match[0] == "MSVERSION": self.msversion = match[1] - elif match[0] == "BRIDGE": - self.bridge = match[1] elif match[0] == "ROLE": self.role = match[1] else: diff --git a/modules/sc-mesh-secure-deployment/src/nats/src/validation.py b/modules/sc-mesh-secure-deployment/src/nats/src/validation.py old mode 100644 new mode 100755 index 5a1bded71..2afdedc69 --- a/modules/sc-mesh-secure-deployment/src/nats/src/validation.py +++ b/modules/sc-mesh-secure-deployment/src/nats/src/validation.py @@ -284,5 +284,16 @@ def validate_batman_iface(batman_iface: str) -> bool: if "bat" in batman_iface and int(batman_iface.replace("bat", "")) >= 0: return True return False + except (ValueError, TypeError, AttributeError): + return False +def validate_mptcp(mptcp: str) -> bool: + """ + Validates a given mptcp. + Returns True if the mptcp is valid, False otherwise. + """ + try: + if mptcp in ("enable", "disable"): + return True + return False except (ValueError, TypeError, AttributeError): return False \ No newline at end of file From 7e67ef403e446c86df76b7ca7cdb63f42994f560 Mon Sep 17 00:00:00 2001 From: Monika-Research Date: Fri, 10 Nov 2023 17:27:24 +0400 Subject: [PATCH 2/4] Handling new parameter MPTCP Updating radio pararmeters in MPTCP configuration Support for multiple batman instances (bridged/non-bridged) Signed-off-by: Monika-Research --- common/scripts/mesh-11s_nats.sh | 114 +++++++++++++++++++------------- common/scripts/mesh-helper.sh | 2 +- 2 files changed, 70 insertions(+), 46 deletions(-) diff --git a/common/scripts/mesh-11s_nats.sh b/common/scripts/mesh-11s_nats.sh index dc09aaca8..6ef11be2e 100755 --- a/common/scripts/mesh-11s_nats.sh +++ b/common/scripts/mesh-11s_nats.sh @@ -74,9 +74,11 @@ fix_iface_mac_addresses() { ifconfig "$batman_iface" down ifconfig "$batman_iface" hw ether "$batif_mac" ifconfig "$batman_iface" up - ifconfig "$bridge_name" down - ifconfig "$bridge_name" hw ether "$eth0_mac" - ifconfig "$bridge_name" up + if [[ -n $bridge_name ]]; then + ifconfig "$bridge_name" down + ifconfig "$bridge_name" hw ether "$eth0_mac" + ifconfig "$bridge_name" up + fi } calculate_network_address() { @@ -228,7 +230,7 @@ EOF sleep 1 if [ "$routing_algo" == "batman-adv" ]; then - batctl if add "$wifidev" + batctl meshif $batman_iface if add "$wifidev" echo "$batman_iface up.." ifconfig "$batman_iface" up echo "$batman_iface ip address.." @@ -237,6 +239,21 @@ EOF ifconfig "$batman_iface" mtu 1460 echo ifconfig "$batman_iface" + if [[ -n $bridge_name ]]; then + add_network_intf_to_bridge "$bridge_name" "$bridge_interfaces" + ifconfig "$bridge_name" "$bridge_ip" netmask "$nmask" + ifconfig "$bridge_name" up + echo + ifconfig "$bridge_name" + # Add forwarding rules from AP to "$batman_iface" interface + iptables -P FORWARD ACCEPT + route del -net "$network" gw 0.0.0.0 netmask "$nmask" dev "$bridge_name" + route add -net "$network" gw "$bridge_ip" netmask "$nmask" dev "$bridge_name" + iptables -A FORWARD --in-interface "$_mesh_vif" -j ACCEPT + iptables --table nat -A POSTROUTING --out-interface "$bridge_ip" -j MASQUERADE + sleep 5 + fi + fix_iface_mac_addresses elif [ "$routing_algo" == "olsr" ]; then ifconfig "$wifidev" "$ipaddr" netmask "$nmask" @@ -244,13 +261,6 @@ EOF (olsrd -i "$wifidev" -d 0)& fi - add_network_intf_to_bridge "$bridge_name" "$bridge_interfaces" - ifconfig "$bridge_name" "$bridge_ip" netmask "$nmask" - ifconfig "$bridge_name" up - echo - ifconfig "$bridge_name" - fix_iface_mac_addresses - if [ "$routing_algo" == "batman-adv" ]; then sleep 3 # for visualisation @@ -262,15 +272,6 @@ EOF fi fi - # Add forwarding rules from AP to "$batman_iface" interface - iptables -P FORWARD ACCEPT - route del -net "$network" gw 0.0.0.0 netmask "$nmask" dev "$bridge_name" - route add -net "$network" gw "$bridge_ip" netmask "$nmask" dev "$bridge_name" - iptables -A FORWARD --in-interface "$_mesh_vif" -j ACCEPT - iptables --table nat -A POSTROUTING --out-interface "$bridge_ip" -j MASQUERADE - - sleep 5 - # Radio parameters echo "set radio parameters" # /usr/local/bin/cli_app set txpwr fixed 23 @@ -343,7 +344,7 @@ EOF ip link set "$wifidev" up if [ "$routing_algo" == "batman-adv" ]; then - batctl if add "$wifidev" + batctl meshif $batman_iface if add "$wifidev" echo "$batman_iface up.." ifconfig "$batman_iface" up echo "$batman_iface ip address.." @@ -352,7 +353,21 @@ EOF ifconfig "$batman_iface" mtu 1460 echo ifconfig "$batman_iface" - + if [[ -n $bridge_name ]]; then + add_network_intf_to_bridge "$bridge_name" "$bridge_interfaces" + ifconfig "$bridge_name" "$bridge_ip" netmask "$nmask" + ifconfig "$bridge_name" up + echo + ifconfig "$bridge_name" + # Add forwarding rules from AP to "$batman_iface" interface + iptables -P FORWARD ACCEPT + route del -net "$network" gw 0.0.0.0 netmask "$nmask" dev "$bridge_name" + route add -net "$network" gw "$bridge_ip" netmask "$nmask" dev "$bridge_name" + iptables -A FORWARD --in-interface "$_mesh_vif" -j ACCEPT + iptables --table nat -A POSTROUTING --out-interface "$bridge_ip" -j MASQUERADE + sleep 5 + fi + fix_iface_mac_addresses elif [ "$routing_algo" == "olsr" ]; then ifconfig "$wifidev" "$ipaddr" netmask "$nmask" # Enable debug level as necessary @@ -362,13 +377,6 @@ EOF # Radio parameters iw dev "$wifidev" set txpower limit "$txpwr"00 - add_network_intf_to_bridge "$bridge_name" "$bridge_interfaces" - ifconfig "$bridge_name" "$bridge_ip" netmask "$nmask" - ifconfig "$bridge_name" up - echo - ifconfig "$bridge_name" - fix_iface_mac_addresses - if [ "$routing_algo" == "batman-adv" ]; then sleep 3 # for visualisation @@ -379,14 +387,6 @@ EOF echo "batadv-vis started." fi fi - - # Add forwarding rules from AP to "$batman_iface" interface - iptables -P FORWARD ACCEPT - route del -net "$network" gw 0.0.0.0 netmask "$nmask" dev "$bridge_name" - route add -net "$network" gw "$bridge_ip" netmask "$nmask" dev "$bridge_name" - iptables -A FORWARD --in-interface "$batman_iface" -j ACCEPT - iptables --table nat -A POSTROUTING --out-interface "$bridge_ip" -j MASQUERADE - wpa_supplicant -i "$wifidev" -c /var/run/wpa_supplicant-11s_"$INDEX".conf -D nl80211 -C /var/run/wpa_supplicant_"$INDEX"/ -f /tmp/wpa_supplicant_11s_"$INDEX".log ;; "ap+mesh_mcc") @@ -557,10 +557,6 @@ main () { # id0_PRIORITY=long_range # BRIDGE="br-mesh eth1 eth0 lan1" # ROLE=drone - generate_lan_bridge_ip - # to get bridge_ip warning free - bridge_ip=$bridge_ip - find_ethernet_port # to get eth_port warning free eth_port=$eth_port @@ -616,6 +612,14 @@ main () { _batman_iface="${INDEX}_BATMAN_IFACE" batman_iface="${!_batman_iface}" + _mptcp="${INDEX}_MPTCP" + mptcp="${!_mptcp}" + echo "MPTCP: $mptcp" + + _bridge="${INDEX}_BRIDGE" + bridge="${!_bridge}" + echo "BRIDGE: $bridge" + # shellcheck disable=SC2153 # shellcheck disable=SC2034 # this is for the future use @@ -630,8 +634,8 @@ main () { fi # e.g. BRIDGE=br-mesh eth0 eth1 lan1 - bridge_name=$(echo "$BRIDGE" | cut -d' ' -f1) - bridge_interfaces=$(echo "$BRIDGE" | cut -d' ' -f2-) + bridge_name=$(echo "$bridge" | cut -d' ' -f1) + bridge_interfaces=$(echo "$bridge" | cut -d' ' -f2-) if brctl show "$bridge_name" &>/dev/null; then echo "Bridge $bridge_name already exists." @@ -640,9 +644,29 @@ main () { brctl addbr "$bridge_name" 2>/dev/null echo "Bridge $bridge_name created." fi - - calculate_network_address "$bridge_ip" "$nmask" + if [[ -n "$bridge_name" ]]; then + generate_lan_bridge_ip + # to get bridge_ip warning free + bridge_ip=$bridge_ip + calculate_network_address "$bridge_ip" "$nmask" + fi + if [ $mptcp == "enable" ]; then + echo "MPTCP enabled" + if ! [ -f /var/run/mptcp.conf ]; then + echo "SUBFLOWS=0" > /var/run/mptcp.conf + fi + if [[ -n $bridge_name ]]; then + source /var/run/mptcp.conf + echo "BRIDGE_IFACE=${bridge_name}" >> /var/run/mptcp.conf + else + source /opt/mptcp.conf + sed -i "s/$SUBFLOWS/$((SUBFLOWS + 1))/" /var/run/mptcp.conf + source /var/run/mptcp.conf + echo "INTERFACE_${SUBFLOWS}=${batman_iface}" >> /var/run/mptcp.conf + fi + fi mode_execute "$mode" + } main "$@" diff --git a/common/scripts/mesh-helper.sh b/common/scripts/mesh-helper.sh index ec1c49447..bbb779136 100644 --- a/common/scripts/mesh-helper.sh +++ b/common/scripts/mesh-helper.sh @@ -46,7 +46,7 @@ EOF generate_lan_bridge_ip() { local mesh_if_mac - bridge_name=$(echo "$BRIDGE" | cut -d' ' -f1) + bridge_name=$(echo "$bridge" | cut -d' ' -f1) mesh_if_mac=$(cat /sys/class/net/"$id0_MESH_VIF"/address) if [ -z "$mesh_if_mac" ]; then From bacddb51791cf52e1fe881bc1bd644cd7ecd9100 Mon Sep 17 00:00:00 2001 From: Monika-Research Date: Fri, 10 Nov 2023 16:24:11 +0400 Subject: [PATCH 3/4] Include comms.setting support for MPTCP Make BRIDGE as radio specific config from global config Signed-off-by: Monika-Research --- .../src/nats/scripts/cli_settings_request.py | 19 +++++++++++++++++++ .../src/nats/src/comms_settings.py | 18 +++++++++--------- .../src/nats/src/validation.py | 1 + 3 files changed, 29 insertions(+), 9 deletions(-) mode change 100644 => 100755 modules/sc-mesh-secure-deployment/src/nats/src/validation.py diff --git a/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_settings_request.py b/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_settings_request.py index 3b240a1b3..d3895f7af 100644 --- a/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_settings_request.py +++ b/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_settings_request.py @@ -20,7 +20,11 @@ async def main(): "frequency": "2412", "frequency_mcc": "2412", # multiradio not supporting "routing": "batman-adv", +<<<<<<< HEAD "mptcp": "disable", # MPTCP support feature flag, enable/disable +======= + "mptcp": "disable", +>>>>>>> Include comms.setting support for MPTCP "priority": "long_range", "ip": "10.20.15.3", "subnet": "255.255.255.0", @@ -28,6 +32,7 @@ async def main(): "mode": "mesh", # ap+mesh_scc, mesh, halow "mesh_vif": "wlp2s0", "batman_iface": "bat0", + "bridge": "br-lan bat0 eth1 lan1 eth0 usb0", }, { "radio_index": "1", @@ -38,7 +43,11 @@ async def main(): "frequency": "5220", "frequency_mcc": "2412", # multiradio not supporting "routing": "batman-adv", +<<<<<<< HEAD "mptcp": "disable", # MPTCP support feature flag, enable/disable +======= + "mptcp": "disable", +>>>>>>> Include comms.setting support for MPTCP "priority": "long_range", "ip": "10.20.15.3", "subnet": "255.255.255.0", @@ -46,6 +55,7 @@ async def main(): "mode": "mesh", # ap+mesh_scc, mesh, halow "mesh_vif": "wlp3s0", # this needs to be correct "batman_iface": "bat0", + "bridge": "br-lan bat0 eth1 lan1 eth0 usb0", }, { "radio_index": "2", @@ -56,7 +66,11 @@ async def main(): "frequency": "5190", "frequency_mcc": "2412", # multiradio not supporting "routing": "batman-adv", +<<<<<<< HEAD "mptcp": "disable", # MPTCP support feature flag, enable/disable +======= + "mptcp": "disable", +>>>>>>> Include comms.setting support for MPTCP "priority": "long_range", "ip": "10.20.15.3", "subnet": "255.255.255.0", @@ -64,9 +78,14 @@ async def main(): "mode": "halow", # ap+mesh_scc, mesh, halow "mesh_vif": "halow1", "batman_iface": "bat0", + "bridge": "br-lan bat0 eth1 lan1 eth0 usb0", }, ], +<<<<<<< HEAD "bridge": "br-lan bat0 eth1 lan1 eth0 usb0", +======= + +>>>>>>> Include comms.setting support for MPTCP } cmd = json.dumps(cmd_dict) diff --git a/modules/sc-mesh-secure-deployment/src/nats/src/comms_settings.py b/modules/sc-mesh-secure-deployment/src/nats/src/comms_settings.py index bb09884bd..1aaa4a066 100644 --- a/modules/sc-mesh-secure-deployment/src/nats/src/comms_settings.py +++ b/modules/sc-mesh-secure-deployment/src/nats/src/comms_settings.py @@ -39,11 +39,11 @@ def __init__(self, comms_status: [cs.CommsStatus, ...], logger): self.routing: [str, ...] = [] self.priority: [str, ...] = [] self.role: str = "" - self.mesh_vif: [str, ...] = [] - self.mptcp: [str, ...] = [] + self.mesh_vif = [] + self.mptcp = [] # self.phy = [] - self.batman_iface: [str, ...] = [] - self.bridge: str = "" + self.batman_iface = [] + self.bridge = [] self.msversion: str = "" self.delay: str = "" # delay for channel change self.comms_status = comms_status @@ -146,6 +146,7 @@ def __clean_all_settings(self) -> None: self.mptcp: [str, ...] = [] # self.phy = [] self.batman_iface: [str, ...] = [] + self.bridge: [str, ...] = [] def handle_mesh_settings_channel_change( self, msg: str, path="/opt", file="mesh_stored.conf" @@ -244,8 +245,7 @@ def handle_mesh_settings( self.mptcp.append(quote(str(parameters["mptcp"]))) # self.phy.append(quote(str(parameters["phy"]))) self.batman_iface.append(quote(str(parameters["batman_iface"]))) - - self.bridge = quote(str(parameters_set["bridge"])) + self.bridge.append(str(parameters["bridge"])) for index in self.radio_index: self.logger.debug("Mesh settings validation index: %s", str(index)) @@ -341,7 +341,7 @@ def __save_settings(self, path: str, file: str, index: int) -> (str, str): mesh_conf.write( f"id{str(index)}_BATMAN_IFACE={quote(self.batman_iface[index])}\n" ) - mesh_conf.write(f"BRIDGE={self.bridge}\n") + mesh_conf.write(f"id{str(index)}_BRIDGE={quote(self.bridge[index])}\n") except: self.comms_status[index].mesh_cfg_status = comms.STATUS.mesh_cfg_not_stored @@ -393,13 +393,13 @@ def __read_configs(self, mesh_conf_lines) -> None: # self.phy.append(match[1]) elif name == "BATMAN_IFACE": self.batman_iface.append(match[1]) + elif name == "BRIDGE": + self.bridge.append(match[1]) else: self.logger.error("unknown config parameter: %s", name) else: # global config without index if match[0] == "MSVERSION": self.msversion = match[1] - elif match[0] == "BRIDGE": - self.bridge = match[1] elif match[0] == "ROLE": self.role = match[1] else: diff --git a/modules/sc-mesh-secure-deployment/src/nats/src/validation.py b/modules/sc-mesh-secure-deployment/src/nats/src/validation.py old mode 100644 new mode 100755 index eb6481f48..ea10eb2a3 --- a/modules/sc-mesh-secure-deployment/src/nats/src/validation.py +++ b/modules/sc-mesh-secure-deployment/src/nats/src/validation.py @@ -297,3 +297,4 @@ def validate_mptcp(mptcp: str) -> bool: return False except (ValueError, TypeError, AttributeError): return False + From 86aa679a6e2bc2b09ecc8170043f0d25183a9e4a Mon Sep 17 00:00:00 2001 From: Monika-Research Date: Fri, 10 Nov 2023 17:27:24 +0400 Subject: [PATCH 4/4] Handling new parameter MPTCP Updating radio pararmeters in MPTCP configuration Support for multiple batman instances (bridged/non-bridged) Signed-off-by: Monika-Research --- common/scripts/mesh-11s_nats.sh | 109 +++++++++++++++++++------------- common/scripts/mesh-helper.sh | 2 +- 2 files changed, 65 insertions(+), 46 deletions(-) diff --git a/common/scripts/mesh-11s_nats.sh b/common/scripts/mesh-11s_nats.sh index acfc12b30..66535b2fc 100755 --- a/common/scripts/mesh-11s_nats.sh +++ b/common/scripts/mesh-11s_nats.sh @@ -74,9 +74,11 @@ fix_iface_mac_addresses() { ifconfig "$batman_iface" down ifconfig "$batman_iface" hw ether "$batif_mac" ifconfig "$batman_iface" up - ifconfig "$bridge_name" down - ifconfig "$bridge_name" hw ether "$eth0_mac" - ifconfig "$bridge_name" up + if [[ -n $bridge_name ]]; then + ifconfig "$bridge_name" down + ifconfig "$bridge_name" hw ether "$eth0_mac" + ifconfig "$bridge_name" up + fi } calculate_network_address() { @@ -234,7 +236,7 @@ EOF sleep 1 if [ "$routing_algo" == "batman-adv" ]; then - batctl if add "$wifidev" + batctl meshif $batman_iface if add "$wifidev" echo "$batman_iface up.." ifconfig "$batman_iface" up echo "$batman_iface ip address.." @@ -243,6 +245,21 @@ EOF ifconfig "$batman_iface" mtu 1460 echo ifconfig "$batman_iface" + if [[ -n $bridge_name ]]; then + add_network_intf_to_bridge "$bridge_name" "$bridge_interfaces" + ifconfig "$bridge_name" "$bridge_ip" netmask "$nmask" + ifconfig "$bridge_name" up + echo + ifconfig "$bridge_name" + # Add forwarding rules from AP to "$batman_iface" interface + iptables -P FORWARD ACCEPT + route del -net "$network" gw 0.0.0.0 netmask "$nmask" dev "$bridge_name" + route add -net "$network" gw "$bridge_ip" netmask "$nmask" dev "$bridge_name" + iptables -A FORWARD --in-interface "$_mesh_vif" -j ACCEPT + iptables --table nat -A POSTROUTING --out-interface "$bridge_ip" -j MASQUERADE + sleep 5 + fi + fix_iface_mac_addresses elif [ "$routing_algo" == "olsr" ]; then ifconfig "$wifidev" "$ipaddr" netmask "$nmask" @@ -250,13 +267,6 @@ EOF (olsrd -i "$wifidev" -d 0)& fi - add_network_intf_to_bridge "$bridge_name" "$bridge_interfaces" - ifconfig "$bridge_name" "$bridge_ip" netmask "$nmask" - ifconfig "$bridge_name" up - echo - ifconfig "$bridge_name" - fix_iface_mac_addresses - if [ "$routing_algo" == "batman-adv" ]; then sleep 3 # for visualisation @@ -268,15 +278,6 @@ EOF fi fi - # Add forwarding rules from AP to "$batman_iface" interface - iptables -P FORWARD ACCEPT - route del -net "$network" gw 0.0.0.0 netmask "$nmask" dev "$bridge_name" - route add -net "$network" gw "$bridge_ip" netmask "$nmask" dev "$bridge_name" - iptables -A FORWARD --in-interface "$_mesh_vif" -j ACCEPT - iptables --table nat -A POSTROUTING --out-interface "$bridge_ip" -j MASQUERADE - - sleep 5 - # Radio parameters echo "set radio parameters" # /usr/local/bin/cli_app set txpwr fixed 23 @@ -349,7 +350,7 @@ EOF ip link set "$wifidev" up if [ "$routing_algo" == "batman-adv" ]; then - batctl if add "$wifidev" + batctl meshif $batman_iface if add "$wifidev" echo "$batman_iface up.." ifconfig "$batman_iface" up echo "$batman_iface ip address.." @@ -358,7 +359,21 @@ EOF ifconfig "$batman_iface" mtu 1460 echo ifconfig "$batman_iface" - + if [[ -n $bridge_name ]]; then + add_network_intf_to_bridge "$bridge_name" "$bridge_interfaces" + ifconfig "$bridge_name" "$bridge_ip" netmask "$nmask" + ifconfig "$bridge_name" up + echo + ifconfig "$bridge_name" + # Add forwarding rules from AP to "$batman_iface" interface + iptables -P FORWARD ACCEPT + route del -net "$network" gw 0.0.0.0 netmask "$nmask" dev "$bridge_name" + route add -net "$network" gw "$bridge_ip" netmask "$nmask" dev "$bridge_name" + iptables -A FORWARD --in-interface "$_mesh_vif" -j ACCEPT + iptables --table nat -A POSTROUTING --out-interface "$bridge_ip" -j MASQUERADE + sleep 5 + fi + fix_iface_mac_addresses elif [ "$routing_algo" == "olsr" ]; then ifconfig "$wifidev" "$ipaddr" netmask "$nmask" # Enable debug level as necessary @@ -368,13 +383,6 @@ EOF # Radio parameters iw dev "$wifidev" set txpower limit "$txpwr"00 - add_network_intf_to_bridge "$bridge_name" "$bridge_interfaces" - ifconfig "$bridge_name" "$bridge_ip" netmask "$nmask" - ifconfig "$bridge_name" up - echo - ifconfig "$bridge_name" - fix_iface_mac_addresses - if [ "$routing_algo" == "batman-adv" ]; then sleep 3 # for visualisation @@ -385,14 +393,6 @@ EOF echo "batadv-vis started." fi fi - - # Add forwarding rules from AP to "$batman_iface" interface - iptables -P FORWARD ACCEPT - route del -net "$network" gw 0.0.0.0 netmask "$nmask" dev "$bridge_name" - route add -net "$network" gw "$bridge_ip" netmask "$nmask" dev "$bridge_name" - iptables -A FORWARD --in-interface "$batman_iface" -j ACCEPT - iptables --table nat -A POSTROUTING --out-interface "$bridge_ip" -j MASQUERADE - wpa_supplicant -i "$wifidev" -c /var/run/wpa_supplicant-11s_"$INDEX".conf -D nl80211 -C /var/run/wpa_supplicant_"$INDEX"/ -f /tmp/wpa_supplicant_11s_"$INDEX".log ;; "ap+mesh_mcc") @@ -563,10 +563,6 @@ main () { # id0_PRIORITY=long_range # BRIDGE="br-mesh eth1 eth0 lan1" # ROLE=drone - generate_lan_bridge_ip - # to get bridge_ip warning free - bridge_ip=$bridge_ip - find_ethernet_port # to get eth_port warning free eth_port=$eth_port @@ -625,6 +621,9 @@ main () { _mptcp="${INDEX}_MPTCP" mptcp="${!_mptcp}" # enable disable + _bridge="${INDEX}_BRIDGE" + bridge="${!_bridge}" + # shellcheck disable=SC2153 # shellcheck disable=SC2034 # this is for the future use @@ -639,8 +638,8 @@ main () { fi # e.g. BRIDGE=br-mesh eth0 eth1 lan1 - bridge_name=$(echo "$BRIDGE" | cut -d' ' -f1) - bridge_interfaces=$(echo "$BRIDGE" | cut -d' ' -f2-) + bridge_name=$(echo "$bridge" | cut -d' ' -f1) + bridge_interfaces=$(echo "$bridge" | cut -d' ' -f2-) if brctl show "$bridge_name" &>/dev/null; then echo "Bridge $bridge_name already exists." @@ -649,9 +648,29 @@ main () { brctl addbr "$bridge_name" 2>/dev/null echo "Bridge $bridge_name created." fi - - calculate_network_address "$bridge_ip" "$nmask" + if [[ -n "$bridge_name" ]]; then + generate_lan_bridge_ip + # to get bridge_ip warning free + bridge_ip=$bridge_ip + calculate_network_address "$bridge_ip" "$nmask" + fi + if [ $mptcp == "enable" ]; then + echo "MPTCP enabled" + if ! [ -f /var/run/mptcp.conf ]; then + echo "SUBFLOWS=0" > /var/run/mptcp.conf + fi + if [[ -n $bridge_name ]]; then + source /var/run/mptcp.conf + echo "BRIDGE_IFACE=${bridge_name}" >> /var/run/mptcp.conf + else + source /opt/mptcp.conf + sed -i "s/$SUBFLOWS/$((SUBFLOWS + 1))/" /var/run/mptcp.conf + source /var/run/mptcp.conf + echo "INTERFACE_${SUBFLOWS}=${batman_iface}" >> /var/run/mptcp.conf + fi + fi mode_execute "$mode" + } main "$@" diff --git a/common/scripts/mesh-helper.sh b/common/scripts/mesh-helper.sh index ec1c49447..bbb779136 100644 --- a/common/scripts/mesh-helper.sh +++ b/common/scripts/mesh-helper.sh @@ -46,7 +46,7 @@ EOF generate_lan_bridge_ip() { local mesh_if_mac - bridge_name=$(echo "$BRIDGE" | cut -d' ' -f1) + bridge_name=$(echo "$bridge" | cut -d' ' -f1) mesh_if_mac=$(cat /sys/class/net/"$id0_MESH_VIF"/address) if [ -z "$mesh_if_mac" ]; then