[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:46 UTC 2009


The following commit has been merged in the master branch:
commit 42bda5dbf045f49d3d658f346629f173b595a361
Author: Michael 'Mickey' Lauer <mickey at vanille-media.de>
Date:   Thu Dec 25 22:49:10 2008 +0100

    add netlink constants

diff --git a/framework/netlink.py b/framework/netlink.py
new file mode 100644
index 0000000..39046f0
--- /dev/null
+++ b/framework/netlink.py
@@ -0,0 +1,101 @@
+#!/usr/bin/env python
+"""
+freesmartphone.org Framework Daemon
+
+(C) 2008 Michael 'Mickey' Lauer <mlauer at vanille-media.de>
+(C) 2008 Openmoko, Inc.
+GPLv2 or later
+
+Package: framework
+Module: netlink
+"""
+
+# RTnetlink multicast groups
+RTNLGRP_NONE = 0x0
+RTNLGRP_LINK = 0x1
+RTNLGRP_NOTIFY = 0x2
+RTNLGRP_NEIGH = 0x4
+RTNLGRP_TC = 0x8
+RTNLGRP_IPV4_IFADDR = 0x10
+RTNLGRP_IPV4_MROUTE = 0x20
+RTNLGRP_IPV4_ROUTE = 0x40
+RTNLGRP_IPV4_RULE = 0x80
+RTNLGRP_IPV6_IFADDR = 0x100
+RTNLGRP_IPV6_MROUTE = 0x200
+RTNLGRP_IPV6_ROUTE = 0x400
+RTNLGRP_IPV6_IFINFO = 0x800
+RTNLGRP_DECnet_IFADDR = 0x1000
+RTNLGRP_NOP2 = 0x2000
+RTNLGRP_DECnet_ROUTE = 0x4000
+RTNLGRP_DECnet_RULE = 0x8000
+RTNLGRP_NOP4 = 0x10000
+RTNLGRP_IPV6_PREFIX = 0x20000
+RTNLGRP_IPV6_RULE = 0x40000
+
+# flags
+RTNLM_F_REQUEST = 1
+RTNLM_F_MULTI = 2
+RTNLM_F_ACK = 4
+RTNLM_F_ECHO = 8
+
+# types (message types)
+RTM_NOOP  = 1
+RTM_ERROR = 2
+RTM_DONE  = 3
+RTM_OVERRUN   = 4
+RTM_MIN_TYPE  = 0x10
+
+# Message Types
+RTM_NEWLINK     = 16
+RTM_DELLINK     = 17
+RTM_GETLINK     = 18
+RTM_SETLINK     = 19
+
+RTM_NEWADDR     = 20
+RTM_DELADDR     = 21
+RTM_GETADDR     = 22
+
+RTM_NEWROUTE    = 24
+RTM_DELROUTE    = 25
+RTM_GETROUTE    = 26
+
+RTM_NEWNEIGH    = 28
+RTM_DELNEIGH    = 29
+RTM_GETNEIGH    = 30
+
+RTM_NEWRULE     = 32
+RTM_DELRULE     = 33
+RTM_GETRULE     = 34
+
+RTM_NEWQDISC    = 36
+RTM_DELQDISC    = 37
+RTM_GETQDISC    = 38
+
+RTM_NEWTCLASS   = 40
+RTM_DELTCLASS   = 41
+RTM_GETTCLASS   = 42
+
+RTM_NEWTFILTER  = 44
+RTM_DELTFILTER  = 45
+RTM_GETTFILTER  = 46
+
+RTM_NEWACTION   = 48
+RTM_DELACTION   = 49
+RTM_GETACTION   = 50
+
+RTM_NEWPREFIX   = 52
+
+RTM_GETMULTICAST = 58
+
+RTM_GETANYCAST  = 62
+
+RTM_NEWNEIGHTBL = 64
+RTM_GETNEIGHTBL = 66
+RTM_SETNEIGHTBL = 67
+
+RTM_NEWNDUSEROPT = 68
+
+RTM_NEWADDRLABEL = 72
+RTM_DELADDRLABEL = 73
+RTM_GETADDRLABEL = 74
+
diff --git a/framework/services.py b/framework/services.py
index 40b90d2..c6e3132 100644
--- a/framework/services.py
+++ b/framework/services.py
@@ -12,9 +12,11 @@ Module: services
 
 __version__ = "0.1.0"
 
+import netlink
+
 import gobject
 
-import os, time, sys, socket, fcntl
+import os, time, sys, socket, fcntl, struct
 try:
     socket.NETLINK_KOBJECT_UEVENT
 except AttributeError:
@@ -70,14 +72,13 @@ class KObjectDispatcher( object ):
             self._watchU = gobject.io_add_watch( self._socketU.fileno(), gobject.IO_IN, self._onActivityU )
 
         try:
-            self._socketR.bind( ( os.getpid(), 1 ) )
+            self._socketR.bind( ( os.getpid(), netlink.RTNLGRP_LINK | netlink.RTNLGRP_IPV4_ROUTE ) )
         except socket.error, e:
             logger.error( "Could not bind to netlink, kobject notifications will not work." )
         else:
             logger.info( "Successfully bound to netlink route." )
             self._watchR = gobject.io_add_watch( self._socketR.fileno(), gobject.IO_IN, self._onActivityR )
 
-
     def __del__( self ):
         """
         Deregister
@@ -155,17 +156,33 @@ class KObjectDispatcher( object ):
         Run through callbacks and call, if applicable
         """
         data = os.read( source, 512 )
+
         print "MSG='%s'" % repr(data)
         logger.debug( "Received route notification: %s" % repr(data) )
 
-        msgtype = data[24] # 03 iface down, 02 iface up
-        iface = data[36:36+8].strip()
+        msglen, msg_type, flags, seq, pid = struct.unpack( "IHHII", data[:16] )
+        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"
+        elif msg_type == netlink.RTM_DELROUTE:
+            print "delroute"
+        elif msg_type == netlink.RTM_NEWLINK:
+            iface = data[36:36+8].strip()
+            print "addlink; iface=%s" % iface
+        elif msg_type == netlink.RTM_DELLINK:
+            iface = data[36:36+8].strip()
+            print "dellink; iface=%s" % iface
+        else:
+            print "undecoded RTM type %d" % msg_type
+
+        #msgtype = data[24] # 03 iface down, 02 iface up
         #parts = data.split( '\0' )
         #action, path = parts[0].split( '@' )
         #properties = {}
         #if len( parts ) > 1:
             #properties = dict( [ x.split('=') for x in parts if '=' in x ] )
-        ##print "action='%s', path='%s', properties='%s'" % ( action, path, properties
+        #print "action='%s', path='%s', properties='%s'" % ( action, path, properties
         #for match, rules in self._matches.iteritems():
             ##print "checking %s startswith %s" % ( parts[0], match )
             #if parts[0].startswith( match ):

-- 
FSO frameworkd Debian packaging



More information about the pkg-fso-commits mailing list