Anyway, I started to use connman which works quite well, except that it seems it never calls the preup / postup functions from /etc/conf.d/net
And there doesn't seem to be anyway to install this kind of callback with connman, unless I missed something.
So, are these functions limited to openrc only, or is there another way ? (maybe by using something else, like network manager ?).
EDIT : well I found a solution, maybe it could be usefull for some others :
I just installed the examples from the connman package, and took inspiration from the monitor-services python script.
It can be modified to run the functions from /etc/conf.d/net when an event occured.
I am not totally sure I took the right status to launch preup and predown, but I was more interested by postup anyway. It should work though.
Here is the modified script, I placed it in /usr/bin/connman-monitor-services :
Code: Select all
#!/usr/bin/python2
import gobject
import dbus
import dbus.mainloop.glib
import os
global iface
iface = {}
def extract_values(values):
val = "{"
for key in values.keys():
val += " " + key + "="
if key in ["Servers", "Excludes"]:
val += extract_list(values[key])
else:
val += str(values[key])
val += " }"
return val
def extract_list(list):
val = "["
for i in list:
val += " " + str(i)
val += " ]"
return val
def property_changed(name, value, path):
service = path[path.rfind("/") + 1:]
if name in ["Services"]:
val = "["
for i in value:
val = val + " " + i[i.rfind("/") + 1:]
val = val + " ]"
elif name in ["IPv4", "IPv4.Configuration",
"IPv6", "IPv6.Configuration",
"Proxy", "Proxy.Configuration", "Ethernet", "Provider"]:
val = extract_values(value)
elif name in ["Nameservers", "Nameservers.Configuration",
"Domains", "Domains.Configuration",
"Timeservers", "Timeservers.Configuration", "Security"]:
val = extract_list(value)
elif name in ["Strength", "Priority"]:
val = int(value)
else:
val = str(value)
if name == "Ethernet":
iface[service] = value["Interface"]
print "[%s] %s = %s" % (service, name, val)
if name == "State":
action = ""
if value == "idle":
action = "postdown"
elif value == "disconnect":
action = "predown"
elif value == "configuration":
action = "preup"
elif value == "online":
action = "postup"
if service and action and iface.get(service):
print "*** launch net ",iface[service]," ",action
os.system(". /etc/conf.d/net; export IFACE=%s; %s %s" % (iface[service],action,iface[service]))
def services_changed(services, removed):
for i in services:
service = i[0][i[0].rfind("/") + 1:]
print "[%s] changed" % (service)
for n in i[1].keys():
property_changed(n, i[1][n], i[0])
for i in removed:
service = i[i.rfind("/") + 1:]
print "[%s] removed" % (service)
def technology_added(path, properties):
technology = path[path.rfind("/") + 1:]
print "[%s] added" % (technology)
for n in properties.keys():
property_changed(n, properties[n], technology)
def technology_removed(path):
technology = path[path.rfind("/") + 1:]
print "[%s] removed" % (technology)
if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
bus.add_signal_receiver(property_changed,
bus_name="net.connman",
dbus_interface="net.connman.Manager",
signal_name="PropertyChanged",
path_keyword="path")
bus.add_signal_receiver(services_changed,
bus_name="net.connman",
dbus_interface="net.connman.Manager",
signal_name="ServicesChanged")
bus.add_signal_receiver(property_changed,
bus_name="net.connman",
dbus_interface="net.connman.Service",
signal_name="PropertyChanged",
path_keyword="path")
bus.add_signal_receiver(technology_added,
bus_name="net.connman",
dbus_interface="net.connman.Manager",
signal_name="TechnologyAdded")
bus.add_signal_receiver(technology_removed,
bus_name="net.connman",
dbus_interface="net.connman.Manager",
signal_name="TechnologyRemoved")
bus.add_signal_receiver(property_changed,
bus_name="net.connman",
dbus_interface="net.connman.Technology",
signal_name="PropertyChanged",
path_keyword="path")
mainloop = gobject.MainLoop()
mainloop.run()
And then just launch this with connman, I took the solution to modify /etc/init.d/connman and add it to the default runlevel (otherwise connman is launched by dbus apparently).
Here is the modified script :
Code: Select all
#!/sbin/runscript
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Purpose License v2
# $Header: /var/cvsroot/gentoo-x86/net-misc/connman/files/connman.initd2,v 1.1 2013/03/14 12:51:31 chainsaw Exp $
depend() {
need dbus
provide net
}
start() {
ebegin "Starting Connection Manager"
start-stop-daemon --start --quiet --exec /usr/sbin/connmand -- ${CONNMAN_OPTS}
start-stop-daemon --start -b -m -p /var/run/connman-monitor-services --quiet --exec /usr/bin/connman-monitor-services
eend $?
}
stop() {
ebegin "Stopping Connection Manager"
start-stop-daemon --stop --quiet --exec /usr/sbin/connmand
start-stop-daemon --stop -p /var/run/connman-monitor-services --quiet --exec /usr/bin/connman-monitor-services
eend $?
}
# vim: set ft=gentoo-init-d ts=3 sw=3 et:

