Browse Source

firewall: mark an IP as handled in /qubes-firewall_handled/[ip] after
each handling iteration

Actually a counter is increased after each handling iteration.
This is useful for user applications to remain up to date with the
changes implemented by the Qubes firewall.

3hhh 2 years ago
parent
commit
78de37da92
1 changed files with 15 additions and 0 deletions
  1. 15 0
      qubesagent/firewall.py

+ 15 - 0
qubesagent/firewall.py

@@ -143,6 +143,19 @@ class FirewallWorker(object):
         for host, hostaddrs in dns.items():
             self.qdb.write('/dns/{}/{}'.format(source, host), str(hostaddrs))
 
+    def update_handled(self, addr):
+        """
+        Update the QubesDB count of how often the given address was handled.
+        User applications may watch these paths for count increases to remain
+        up to date with QubesDB changes.
+        """
+        cnt = self.qdb.read('/qubes-firewall_handled/{}'.format(addr))
+        try:
+            cnt = int(cnt)
+        except (TypeError, ValueError):
+            cnt = 0
+        self.qdb.write('/qubes-firewall_handled/{}'.format(addr), str(cnt+1))
+
     def list_targets(self):
         return set(t.split('/')[2] for t in self.qdb.list('/qubes-firewall/'))
 
@@ -179,6 +192,8 @@ class FirewallWorker(object):
                 self.log_error(
                     'Failed to block traffic for {}'.format(addr))
 
+        self.update_handled(addr)
+
     @staticmethod
     def dns_addresses(family=None):
         with open('/etc/resolv.conf') as resolv: