From: Gregor Riepl Date: Thu, 5 Aug 2010 13:52:07 +0000 (+0200) Subject: Added empty network setup scripts X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=228fe0f0315910df2b6ca06f7f3eb976e54ad808;p=mtetherd Added empty network setup scripts Implemented launching of such --- diff --git a/Makefile b/Makefile index 0284e89..35a3d6d 100644 --- a/Makefile +++ b/Makefile @@ -8,12 +8,12 @@ IMAGE_DIR = $(PREFIX)/share/pixmaps ETC_DIR = /etc CC = gcc CFLAGS = -Wall -O2 -g -D_GNU_SOURCE -DIMAGE_DIR=\"$(IMAGE_DIR)\" -DSBIN_DIR=\"$(SBIN_DIR)\" -INCLUDES = $(shell pkg-config --cflags dbus-1 libhildondesktop-1 hal) +INCLUDES = $(shell pkg-config --cflags dbus-1 libhildondesktop-1 hal glib-2.0 gtk+-2.0) LDFLAGS = LIBS_DBUS = $(shell pkg-config --libs dbus-1) LIBS_HILDON = $(shell pkg-config --libs libhildondesktop-1 hal glib-2.0 gtk+-2.0) -all: mtetherd mtetherd-plugin.so +all: mtetherd-plugin.so mtetherd: mtetherd.o device.o $(CC) $(LDFLAGS) $(LIBS_DBUS) -o $@ $^ @@ -26,25 +26,26 @@ mtetherd-plugin.so: plugin.o hal.o net.o util.o clean: rm -f *.o mtetherd mtetherd-plugin.so -install: mtetherd mtetherd-plugin.so - install -m 755 -D mtetherd $(DESTDIR)/$(SBIN_DIR)/mtetherd - install -m 644 -D event.d-mtetherd $(DESTDIR)/$(ETC_DIR)/event.d/mtetherd +install: mtetherd-plugin.so install -m 644 -D README $(DESTDIR)/$(DOC_DIR)/README install -m 644 -D mtetherd-plugin.desktop $(DESTDIR)/$(HILDON_DESKTOP_DIR)/mtetherd-plugin.desktop install -m 755 -D mtetherd-plugin.so $(DESTDIR)/$(HILDON_PLUGIN_DIR)/mtetherd-plugin.so install -m 755 -D mtetherd-usbnet-enable.sh $(DESTDIR)/$(SBIN_DIR)/mtetherd-usbnet-enable.sh install -m 755 -D mtetherd-usbnet-disable.sh $(DESTDIR)/$(SBIN_DIR)/mtetherd-usbnet-disable.sh + install -m 755 -D mtetherd-net-setup.sh $(DESTDIR)/$(SBIN_DIR)/mtetherd-net-setup.sh + install -m 755 -D mtetherd-net-shutdown.sh $(DESTDIR)/$(SBIN_DIR)/mtetherd-net-shutdown.sh install -m 644 -D mtetherd.sudoers $(DESTDIR)/$(ETC_DIR)/sudoers.d/mtetherd.sudoers install -m 644 -D mtetherd-net-icon.png $(DESTDIR)/$(IMAGE_DIR)/mtetherd-net-icon.png uninstall: - rm -f $(DESTDIR)/$(SBIN_DIR)/mtetherd rm -f $(DESTDIR)/$(ETC_DIR)/event.d/mtetherd rm -rf $(DESTDIR)/$(PREFIX)/share/doc/mtetherd rm -f $(DESTDIR)/$(HILDON_DESKTOP_DIR)/mtetherd-plugin.desktop rm -f $(DESTDIR)/$(HILDON_PLUGIN_DIR)/mtetherd-plugin.so rm -f $(DESTDIR)/$(SBIN_DIR)/mtetherd-usbnet-enable.sh rm -f $(DESTDIR)/$(SBIN_DIR)/mtetherd-usbnet-disable.sh + rm -f $(DESTDIR)/$(SBIN_DIR)/mtetherd-net-setup.sh + rm -f $(DESTDIR)/$(SBIN_DIR)/mtetherd-net-shutdown.sh rm -f $(DESTDIR)/$(ETC_DIR)/sudoers.d/mtetherd.sudoers rm -f $(DESTDIR)/$(IMAGE_DIR)/mtetherd-net-icon.png diff --git a/mtetherd-net-setup.sh b/mtetherd-net-setup.sh new file mode 100755 index 0000000..e69de29 diff --git a/mtetherd-net-shutdown.sh b/mtetherd-net-shutdown.sh new file mode 100755 index 0000000..e69de29 diff --git a/net.c b/net.c index af1953b..788aff6 100644 --- a/net.c +++ b/net.c @@ -150,6 +150,50 @@ const gchar *mtetherd_device_get_interface(MTetherDDevice *self) { return NULL; } +gchar *mtetherd_device_get_addr(MTetherDDevice *self) { + if (self && self->priv) { + guchar a = self->priv->addr & 0xff; + guchar b = (self->priv->addr >> 8) & 0xff; + guchar c = (self->priv->addr >> 16) & 0xff; + guchar d = (self->priv->addr >> 24) & 0xff; + return g_strdup_printf("%u.%u.%u.%u", a, b, c, d); + } + return NULL; +} + +gchar *mtetherd_device_get_netmask(MTetherDDevice *self) { + if (self && self->priv) { + guchar a = self->priv->netmask & 0xff; + guchar b = (self->priv->netmask >> 8) & 0xff; + guchar c = (self->priv->netmask >> 16) & 0xff; + guchar d = (self->priv->netmask >> 24) & 0xff; + return g_strdup_printf("%u.%u.%u.%u", a, b, c, d); + } + return NULL; +} + +gchar *mtetherd_device_get_dhcp_start(MTetherDDevice *self) { + if (self && self->priv) { + guchar a = self->priv->dhcp_start & 0xff; + guchar b = (self->priv->dhcp_start >> 8) & 0xff; + guchar c = (self->priv->dhcp_start >> 16) & 0xff; + guchar d = (self->priv->dhcp_start >> 24) & 0xff; + return g_strdup_printf("%u.%u.%u.%u", a, b, c, d); + } + return NULL; +} + +gchar *mtetherd_device_get_dhcp_end(MTetherDDevice *self) { + if (self && self->priv) { + guchar a = self->priv->dhcp_end & 0xff; + guchar b = (self->priv->dhcp_end >> 8) & 0xff; + guchar c = (self->priv->dhcp_end >> 16) & 0xff; + guchar d = (self->priv->dhcp_end >> 24) & 0xff; + return g_strdup_printf("%u.%u.%u.%u", a, b, c, d); + } + return NULL; +} + static gint mtetherd_device_list_find_index(gpointer *array, const gchar *udi) { guint i; for (i = 0; i < MAX_DEVICES; i++) { diff --git a/net.h b/net.h index 2507143..f3caf02 100644 --- a/net.h +++ b/net.h @@ -60,6 +60,18 @@ MTetherDDevice *mtetherd_device_new(const gchar *interface, const gchar *udi); void mtetherd_device_set_index(MTetherDDevice *self, guint index); // Returns the interface name const gchar *mtetherd_device_get_interface(MTetherDDevice *self); +// Returns the host address +// Free when done +gchar *mtetherd_device_get_addr(MTetherDDevice *self); +// Returns the netmask +// Free when done +gchar *mtetherd_device_get_netmask(MTetherDDevice *self); +// Returns the DHCP range start address +// Free when done +gchar *mtetherd_device_get_dhcp_start(MTetherDDevice *self); +// Returns the DHCP range end address +// Free when done +gchar *mtetherd_device_get_dhcp_end(MTetherDDevice *self); // Device list functions // The list is constrained to 64 entries diff --git a/plugin.c b/plugin.c index 2fb47d6..a0b4d5f 100644 --- a/plugin.c +++ b/plugin.c @@ -53,7 +53,6 @@ struct _MTetherDStatusPluginPrivate { #define SBIN_DIR "/usr/sbin" #endif -static const char *USBNET_MODULE = "g_ether"; // The UDI contains the MAC address and is thus unsuitable for // loaded status checking, so we just use the interface name static const char *USBNET_INTERFACE = "usb0"; @@ -166,9 +165,6 @@ static void mtetherd_status_plugin_init(MTetherDStatusPlugin *plugin) { plugin->priv->usb_plugged = FALSE; } - // Unnecessary, we scan the network device name instead - //plugin->priv->usbnet_loaded = mtetherd_scan_modules(USBNET_MODULE); - // Update the button status mtetherd_status_plugin_usb_plugged_show(plugin); @@ -179,15 +175,27 @@ void mtetherd_status_plugin_device_added(MTetherDStatusPlugin *plugin, MTetherDD if (plugin && plugin->priv) { const gchar *interface = mtetherd_device_get_interface(device); if (mtetherd_device_ok(interface)) { - if (!mtetherd_device_list_add(plugin->priv->devices, device)) { - g_warning("Error adding network interface to list: Maximum number of devices exceeded"); - } else { + if (mtetherd_device_list_add(plugin->priv->devices, device)) { if (g_strcmp0(USBNET_INTERFACE, interface) == 0) { plugin->priv->usbnet_state = MTETHERD_STATUS_PLUGIN_USB_NET_ENABLED; mtetherd_status_plugin_enable_button_set_text(plugin); } hildon_banner_show_informationf(GTK_WIDGET(plugin), NULL, "Starting network on %s", interface); - // TODO: Launch network setup script + g_debug("Launching " SBIN_DIR "/mtetherd-net-setup.sh"); + gchar *addr = mtetherd_device_get_addr(device); + gchar *netmask = mtetherd_device_get_netmask(device); + gchar *dhcp_start = mtetherd_device_get_dhcp_start(device); + gchar *dhcp_end = mtetherd_device_get_dhcp_end(device); + const char *command[] = { "/usr/bin/sudo", SBIN_DIR "/mtetherd-net-setup.sh", interface, addr, netmask, dhcp_start, dhcp_end, NULL }; + if (!mtetherd_launch_script(command)) { + g_warning("Error launching USB networking setup script"); + } + g_free(addr); + g_free(netmask); + g_free(dhcp_start); + g_free(dhcp_end); + } else { + g_warning("Error adding network interface to list: Maximum number of devices exceeded"); } } } @@ -203,7 +211,11 @@ void mtetherd_status_plugin_device_removed(MTetherDStatusPlugin *plugin, const g mtetherd_status_plugin_enable_button_set_text(plugin); } hildon_banner_show_informationf(GTK_WIDGET(plugin), NULL, "Shutting down network on %s", interface); - // TODO: Launch network teardown script + g_debug("Launching " SBIN_DIR "/mtetherd-net-shutdown.sh"); + const char *command[] = { "/usr/bin/sudo", SBIN_DIR "/mtetherd-net-shutdown.sh", interface, NULL }; + if (!mtetherd_launch_script(command)) { + g_warning("Error launching USB networking shutdown script"); + } } if (!mtetherd_device_list_remove(plugin->priv->devices, udi)) { g_warning("Error removing network interface from list: Not found"); diff --git a/util.h b/util.h index 8295c66..138a33a 100644 --- a/util.h +++ b/util.h @@ -23,7 +23,7 @@ #include -// Opens /proc/modules and scans for g_ether +// Opens /proc/modules and scans for module // Returns TRUE if found, FALSE if not gboolean mtetherd_scan_modules(const char *module); // Launch an external script in the background