[pkg-fso-commits] [SCM] FSO frameworkd Debian packaging branch, master, updated. milestone4-368-g700ab82

Michael 'Mickey' Lauer mickey at vanille-media.de
Mon Feb 2 18:51:48 UTC 2009


The following commit has been merged in the master branch:
commit ed797b0a4f3af5018a17eebd56c0cdf7db9257eb
Author: Michael 'Mickey' Lauer <mickey at vanille-media.de>
Date:   Tue Dec 30 18:38:35 2008 +0100

    kobject: parse a bit more of netlink

diff --git a/framework/patterns/kobject.py b/framework/patterns/kobject.py
index c6e3132..13bfa5b 100644
--- a/framework/patterns/kobject.py
+++ b/framework/patterns/kobject.py
@@ -12,6 +12,8 @@ Module: services
 
 __version__ = "0.1.0"
 
+SYS_CLASS_NET = "/sys/class/net"
+
 import netlink
 
 import gobject
@@ -25,6 +27,16 @@ except AttributeError:
 import logging
 logger = logging.getLogger( "frameworkd.services" )
 
+def indexToInterface( index ):
+    for iface in os.listdir( "/sys/class/net" ):
+        ifindex = int( open( "%s/%s/ifindex" % ( SYS_CLASS_NET, iface ), "r" ).read().strip() )
+        if ifindex == index:
+            return iface
+    raise IndexError( "index not found" )
+
+def ipv4Address( data ):
+    return ".".join( str(ord(octet)) for octet in data )
+
 #----------------------------------------------------------------------------#
 class KObjectDispatcher( object ):
 #----------------------------------------------------------------------------#
@@ -164,9 +176,19 @@ class KObjectDispatcher( object ):
         print "len=%d, type=%d, flags=%d, seq=%d, pid=%d" %( msglen, msg_type, flags, seq, pid )
 
         if msg_type == netlink.RTM_NEWROUTE:
-            print "addroute"
+            if msglen == 44:
+                route = "0.0.0.0"
+            else:
+                route = ipv4Address( data[40:44] )
+            iface = indexToInterface( ord( data[-4] ) )
+            print "addroute=%s; iface=%s;" % ( route, iface )
         elif msg_type == netlink.RTM_DELROUTE:
-            print "delroute"
+            if msglen == 44:
+                route = "0.0.0.0"
+            else:
+                route = ipv4Address( data[40:44] )
+            iface = indexToInterface( ord( data[-4] ) )
+            print "delroute=%s; iface=%s" % ( route, iface )
         elif msg_type == netlink.RTM_NEWLINK:
             iface = data[36:36+8].strip()
             print "addlink; iface=%s" % iface
@@ -193,6 +215,8 @@ class KObjectDispatcher( object ):
 #----------------------------------------------------------------------------#
 if __name__ == "__main__":
 #----------------------------------------------------------------------------#
+    logging.basicConfig()
+
     def class_callback( *args, **kwargs ):
         print "class callback", args, kwargs
 

-- 
FSO frameworkd Debian packaging



More information about the pkg-fso-commits mailing list