diff --git a/common/scripts/mesh-11s_nats.sh b/common/scripts/mesh-11s_nats.sh index acfc12b30..c7707f498 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 @@ -623,7 +619,10 @@ main () { batman_iface="${!_batman_iface}" _mptcp="${INDEX}_MPTCP" - mptcp="${!_mptcp}" # enable disable + mptcp="${!_mptcp}" + + _bridge="${INDEX}_BRIDGE" + bridge="${!_bridge}" # shellcheck disable=SC2153 # shellcheck disable=SC2034 @@ -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 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..b3a331de7 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 @@ -28,6 +28,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", @@ -46,6 +47,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", @@ -64,9 +66,9 @@ 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 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