chiark / gitweb /
server/admin.c (a_vformat): Fix uses of `va_arg' to dereference `ap'.
[tripe] / svc / conntrack.in
index f4b717bc2ec3a8a8e276fb100e0c359f95123df8..6ada45d73950e68f6ca1d1c4419c08c6718de579 100644 (file)
@@ -195,7 +195,7 @@ class Config (object):
 ### This will be a configuration file.
 CF = None
 
-def straddr(a): return S.inet_ntoa(pack('>L', a))
+def straddr(a): return a is None and '#<none>' or S.inet_ntoa(pack('>L', a))
 def strmask(m):
   for i in xrange(33):
     if m == 0xffffffff ^ ((1 << (32 - i)) - 1): return i
@@ -350,7 +350,14 @@ NM_PATH = '/org/freedesktop/NetworkManager'
 NM_IFACE = NM_NAME
 NMCA_IFACE = NM_NAME + '.Connection.Active'
 
-NM_STATE_CONNECTED = 3
+NM_STATE_CONNECTED = 3 #obsolete
+NM_STATE_CONNECTED_LOCAL = 50
+NM_STATE_CONNECTED_SITE = 60
+NM_STATE_CONNECTED_GLOBAL = 70
+NM_CONNSTATES = set([NM_STATE_CONNECTED,
+                     NM_STATE_CONNECTED_LOCAL,
+                     NM_STATE_CONNECTED_SITE,
+                     NM_STATE_CONNECTED_GLOBAL])
 
 class NetworkManagerMonitor (object):
   """
@@ -370,20 +377,19 @@ class NetworkManagerMonitor (object):
     try:
       nm = bus.get_object(NM_NAME, NM_PATH)
       state = nm.Get(NM_IFACE, 'State')
-      if state == NM_STATE_CONNECTED:
+      if state in NM_CONNSTATES:
         netupdown(True, ['nm', 'initially-connected'])
       else:
         netupdown(False, ['nm', 'initially-disconnected'])
     except D.DBusException:
       pass
-    bus.add_signal_receiver(me._nm_state, 'StateChanged', NM_IFACE,
-                            NM_NAME, NM_PATH)
-    bus.add_signal_receiver(me._nm_connchange,
-                            'PropertiesChanged', NMCA_IFACE,
-                            NM_NAME, None)
+    bus.add_signal_receiver(me._nm_state, 'StateChanged',
+                            NM_IFACE, NM_NAME, NM_PATH)
+    bus.add_signal_receiver(me._nm_connchange, 'PropertiesChanged',
+                            NMCA_IFACE, NM_NAME, None)
 
   def _nm_state(me, state):
-    if state == NM_STATE_CONNECTED:
+    if state in NM_CONNSTATES:
       netupdown(True, ['nm', 'connected'])
     else:
       netupdown(False, ['nm', 'disconnected'])
@@ -392,6 +398,38 @@ class NetworkManagerMonitor (object):
     if props.get('Default', False):
       netupdown(True, ['nm', 'default-connection-change'])
 
+##--------------------------------------------------------------------------
+### Connman monitor.
+
+CM_NAME = 'net.connman'
+CM_PATH = '/'
+CM_IFACE = 'net.connman.Manager'
+
+class ConnManMonitor (object):
+  """
+  Watch ConnMan signls for changes in network state.
+  """
+
+  ## Strategy.  Everything seems to be usefully encoded in the `State'
+  ## property.  If it's `offline', `idle' or `ready' then we don't expect a
+  ## network connection.  During handover from one network to another, the
+  ## property passes through `ready' to `online'.
+
+  def attach(me, bus):
+    try:
+      cm = bus.get_object(CM_NAME, CM_PATH)
+      props = cm.GetProperties(dbus_interface = CM_IFACE)
+      state = props['State']
+      netupdown(state == 'online', ['connman', 'initially-%s' % state])
+    except D.DBusException:
+      pass
+    bus.add_signal_receiver(me._cm_state, 'PropertyChanged',
+                            CM_IFACE, CM_NAME, CM_PATH)
+
+  def _cm_state(me, prop, value):
+    if prop != 'State': return
+    netupdown(value == 'online', ['connman', value])
+
 ###--------------------------------------------------------------------------
 ### Maemo monitor.
 
@@ -543,6 +581,7 @@ def init():
   T.Coroutine(kickpeers, name = 'kickpeers').switch()
   DBM = DBusMonitor()
   DBM.addmon(NetworkManagerMonitor())
+  DBM.addmon(ConnManMonitor())
   DBM.addmon(MaemoICdMonitor())
   G.timeout_add_seconds(30, lambda: (netupdown(True, ['interval-timer'])
                                      or True))