From e7320a61a6707904f30fb33914b07218d4dadb3b Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Thu, 10 Dec 2020 15:16:05 -0800 Subject: [PATCH] daemon: revert wlan mac learning change, due to undesired default behavior, there may be some cases where this behavior is desired, so the option to enable a promiscuous mode has been added and will be present in core-pygui --- daemon/core/location/mobility.py | 16 ++++++++++++++++ daemon/core/nodes/netclient.py | 7 ++++--- daemon/core/nodes/network.py | 6 +++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/daemon/core/location/mobility.py b/daemon/core/location/mobility.py index c3b97e7c..95516ce8 100644 --- a/daemon/core/location/mobility.py +++ b/daemon/core/location/mobility.py @@ -31,6 +31,9 @@ from core.nodes.network import WlanNode if TYPE_CHECKING: from core.emulator.session import Session +LEARNING_DISABLED: int = 0 +LEARNING_ENABLED: int = 30000 + def get_mobility_node(session: "Session", node_id: int) -> Union[WlanNode, EmaneNet]: try: @@ -259,6 +262,12 @@ class BasicRangeModel(WirelessModel): Configuration( _id="error", _type=ConfigDataTypes.STRING, default="0", label="loss (%)" ), + Configuration( + _id="promiscuous", + _type=ConfigDataTypes.BOOL, + default="0", + label="promiscuous mode", + ), ] @classmethod @@ -282,6 +291,7 @@ class BasicRangeModel(WirelessModel): self.delay: Optional[int] = None self.loss: Optional[float] = None self.jitter: Optional[int] = None + self.promiscuous: bool = False def _get_config(self, current_value: int, config: Dict[str, str], name: str) -> int: """ @@ -444,6 +454,12 @@ class BasicRangeModel(WirelessModel): self.delay = self._get_config(self.delay, config, "delay") self.loss = self._get_config(self.loss, config, "error") self.jitter = self._get_config(self.jitter, config, "jitter") + promiscuous = config["promiscuous"] == "1" + if self.promiscuous and not promiscuous: + self.wlan.net_client.set_mac_learning(self.wlan.brname, LEARNING_ENABLED) + elif not self.promiscuous and promiscuous: + self.wlan.net_client.set_mac_learning(self.wlan.brname, LEARNING_DISABLED) + self.promiscuous = promiscuous self.setlinkparams() def create_link_data( diff --git a/daemon/core/nodes/netclient.py b/daemon/core/nodes/netclient.py index 68fbef98..729550b6 100644 --- a/daemon/core/nodes/netclient.py +++ b/daemon/core/nodes/netclient.py @@ -286,14 +286,15 @@ class LinuxNetClient: return True return False - def disable_mac_learning(self, name: str) -> None: + def set_mac_learning(self, name: str, value: int) -> None: """ - Disable mac learning for a Linux bridge. + Set mac learning for a Linux bridge. :param name: bridge name + :param value: ageing time value :return: nothing """ - self.run(f"{IP} link set {name} type bridge ageing_time 0") + self.run(f"{IP} link set {name} type bridge ageing_time {value}") class OvsNetClient(LinuxNetClient): diff --git a/daemon/core/nodes/network.py b/daemon/core/nodes/network.py index aef4b04b..cb3aca79 100644 --- a/daemon/core/nodes/network.py +++ b/daemon/core/nodes/network.py @@ -32,7 +32,8 @@ if TYPE_CHECKING: WirelessModelType = Type[WirelessModel] -ebtables_lock = threading.Lock() +LEARNING_DISABLED: int = 0 +ebtables_lock: threading.Lock = threading.Lock() class EbtablesQueue: @@ -946,7 +947,7 @@ class HubNode(CoreNetwork): :return: nothing """ super().startup() - self.net_client.disable_mac_learning(self.brname) + self.net_client.set_mac_learning(self.brname, LEARNING_DISABLED) class WlanNode(CoreNetwork): @@ -989,7 +990,6 @@ class WlanNode(CoreNetwork): :return: nothing """ super().startup() - self.net_client.disable_mac_learning(self.brname) ebq.ebchange(self) def attach(self, iface: CoreInterface) -> None: