]> git.proxmox.com Git - mirror_ifupdown2.git/commitdiff
addons: batman_adv: Add support to set B.A.T.M.A.N. advanced routing_algo
authorMaximilian Wilhelm <max@sdn.clinic>
Sat, 25 May 2019 12:16:30 +0000 (14:16 +0200)
committerMaximilian Wilhelm <max@sdn.clinic>
Sat, 25 May 2019 12:16:30 +0000 (14:16 +0200)
  Add a new attribute for B.A.T.M.A.N. advanced interfaces to control the
  B.A.T.M.A.N. advanced routing algorithm to be used when setting up new
  interfaces. As the routing algorithm must be set before an interface is
  created, it needs special handling and can't be implemented as a common
  attribute. D'oh.

Signed-off-by: Maximilian Wilhelm <max@sdn.clinic>
Tested-by: Annika Wickert <aw@awlnx.space>
ifupdown2/addons/batman_adv.py

index 293d1c34b8dc67f2838f50c962926f676bba3b95..23ec0e121ec2562c6a70288bea3c0d84fbfed46e 100644 (file)
@@ -77,6 +77,13 @@ class batman_adv (moduleBase):
                 'required' : False,
                 'batman-attr' : True,
             },
                 'required' : False,
                 'batman-attr' : True,
             },
+
+           'batman-routing-algo' : {
+                'help' : 'B.A.T.M.A.N. routing algo',
+                'validvals' : [ 'BATMAN_IV', 'BATMAN_V' ],
+                'required' : False,
+                'batman-attr' : False,
+            },
         }
     }
 
         }
     }
 
@@ -131,12 +138,17 @@ class batman_adv (moduleBase):
         return None
 
 
         return None
 
 
-    def _read_current_batman_attr (self, ifaceobj, attr):
-        if attr not in self._batman_attrs:
-            raise ValueError ("_read_current_batman_attr: Invalid or unsupported B.A.T.M.A.N. adv. attribute: %s" % attr)
+    def _read_current_batman_attr (self, ifaceobj, attr, dont_map = False):
+       # 'routing_algo' needs special handling, D'oh.
+        if dont_map:
+            attr_file_path = "/sys/class/net/%s/mesh/%s" % (ifaceobj.name, attr)
+        else:
+            if attr not in self._batman_attrs:
+                raise ValueError ("_read_current_batman_attr: Invalid or unsupported B.A.T.M.A.N. adv. attribute: %s" % attr)
+
+            attr_file_name = self._batman_attrs[attr]['filename']
+            attr_file_path = "/sys/class/net/%s/mesh/%s" % (ifaceobj.name, attr_file_name)
 
 
-        attr_file_name = self._batman_attrs[attr]['filename']
-        attr_file_path = "/sys/class/net/%s/mesh/%s" % (ifaceobj.name, attr_file_name)
         try:
             return self.read_file_oneline(attr_file_path)
         except IOError as i:
         try:
             return self.read_file_oneline(attr_file_path)
         except IOError as i:
@@ -169,6 +181,18 @@ class batman_adv (moduleBase):
         except Exception as e:
             raise Exception ("_batctl_if: %s" % e)
 
         except Exception as e:
             raise Exception ("_batctl_if: %s" % e)
 
+    def _set_routing_algo (self, routing_algo):
+        if routing_algo not in ['BATMAN_IV', 'BATMAN_V']:
+            raise Exception ("_set_routing_algo() called with invalid \"routing_algo\" value: %s" % routing_algo)
+
+        try:
+            self.logger.debug ("Running batctl ra %s" % routing_algo)
+            batctl_output = subprocess.check_output (["batctl", "ra", routing_algo], stderr = subprocess.STDOUT)
+        except subprocess.CalledProcessError as c:
+            raise Exception ("Command \"batctl ra %s\" failed: %s" % (routing_algo, c.output))
+        except Exception as e:
+            raise Exception ("_set_routing_algo: %s" % e)
+
 
     def _find_member_ifaces (self, ifaceobj, ignore = True):
         members = []
 
     def _find_member_ifaces (self, ifaceobj, ignore = True):
         members = []
@@ -213,6 +237,11 @@ class batman_adv (moduleBase):
         if len (batman_ifaces) == 0:
             raise Exception ("None of the configured batman interfaces are available!")
 
         if len (batman_ifaces) == 0:
             raise Exception ("None of the configured batman interfaces are available!")
 
+        routing_algo = ifaceobj.get_attr_value_first ('batman-routing-algo')
+        if routing_algo:
+            self._set_routing_algo (routing_algo)
+
+
         if_ignore_re = self._get_batman_ifaces_ignore_regex (ifaceobj)
         # Is the batman main interface already present?
         if self.ipcmd.link_exists (ifaceobj.name):
         if_ignore_re = self._get_batman_ifaces_ignore_regex (ifaceobj)
         # Is the batman main interface already present?
         if self.ipcmd.link_exists (ifaceobj.name):
@@ -303,6 +332,16 @@ class batman_adv (moduleBase):
 
             ifaceobjcurr.update_config_with_status ('batman-%s' % attr, value_curr, value_ok)
 
 
             ifaceobjcurr.update_config_with_status ('batman-%s' % attr, value_curr, value_ok)
 
+        routing_algo = ifaceobj.get_attr_value_first ('batman-routing-algo')
+        if routing_algo:
+            value_curr = self._read_current_batman_attr (ifaceobj, "routing_algo", dont_map = True)
+
+            value_ok = 0
+            if routing_algo != value_curr:
+                value_ok = 1
+
+            ifaceobjcurr.update_config_with_status ('batman-routing-algo', value_curr, value_ok)
+
 
     def _query_running (self, ifaceobjrunning):
         if not self.ipcmd.link_exists (ifaceobjrunning.name):
 
     def _query_running (self, ifaceobjrunning):
         if not self.ipcmd.link_exists (ifaceobjrunning.name):