Work with a seperate interface for Router Advertisements
authorRoy Marples <roy@marples.name>
Thu, 2 Feb 2012 18:24:51 +0000 (18:24 +0000)
committerRoy Marples <roy@marples.name>
Thu, 2 Feb 2012 18:24:51 +0000 (18:24 +0000)
Makefile
src/dhcpcd-gtk/Makefile
src/dhcpcd-gtk/main.c
src/dhcpcd-gtk/menu.c
src/dhcpcd-gtk/prefs.c
src/libdhcpcd/dispatch.c
src/libdhcpcd/libdhcpcd.h
src/libdhcpcd/main.c
src/libdhcpcd/misc.c

index d378ef6edcfa7ca26c2d22f1755ed3691296d2bc..7cd4953fad4988403c76eb437532de971b7483fc 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
 PROG=          dhcpcd-ui
-VERSION=       0.5.2
+VERSION=       0.6.0
 
 .PHONY:                icons
 
index 56e16ea2f8a2eebd19c2a4c5528746b2abf2584f..95b2fdce5a86ca55d7fdfefa48d7b30d512a057b 100644 (file)
@@ -15,5 +15,7 @@ CPPFLAGS+=    ${NOTIFY} -I${TOPDIR}
 CFLAGS+=       ${GTK_CFLAGS}
 LDADD+=                ${LIB_DHCPCD} ${GTK_LIBS}
 
+.PHONY: dhcpcd-gtk
+
 include ../libdhcpcd/Makefile.inc
 include ${MKDIR}/prog.mk
index 295bfb1a87dd70c08ffb9f080666c7ba8ad6b249..0da2030e98a0b308ed93c605634557226d8175a8 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * dhcpcd-gtk
- * Copyright 2009-2011 Roy Marples <roy@marples.name>
+ * Copyright 2009-2012 Roy Marples <roy@marples.name>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -134,7 +134,7 @@ update_online(DHCPCD_CONNECTION *con, bool showif)
                if (strcmp(i->reason, "RELEASE") == 0 ||
                    strcmp(i->reason, "STOP") == 0)
                        continue;
-               if (dhcpcd_if_up(i))
+               if (i->up)
                        ison = iscarrier = true;
                if (!iscarrier && g_strcmp0(i->reason, "CARRIER") == 0)
                        iscarrier = true;
@@ -241,11 +241,11 @@ event_cb(DHCPCD_CONNECTION *con, DHCPCD_IF *i, _unused void *data)
                return;
 
        msg = dhcpcd_if_message(i);
-       if (dhcpcd_if_up(i))
+       if (i->up)
                icon = "network-transmit-receive";
-       else
-               icon = "network-transmit";
-       if (dhcpcd_if_down(i))
+       //else
+       //      icon = "network-transmit";
+       if (!i->up)
                icon = "network-offline";
        notify(_("Network event"), msg, icon);
        g_free(msg);
@@ -264,6 +264,13 @@ status_cb(DHCPCD_CONNECTION *con, const char *status, _unused void *data)
        if (g_strcmp0(status, "down") == 0) {
                msg = N_(last ?
                    "Connection to dhcpcd lost" : "dhcpcd not running");
+               if (ani_timer != 0) {
+                       g_source_remove(ani_timer);
+                       ani_timer = 0;
+                       ani_counter = 0;
+               }
+               gtk_status_icon_set_from_icon_name(status_icon,
+                   "network-offline");
                gtk_status_icon_set_tooltip(status_icon, msg);
                notify(_("No network"), msg, "network-offline");
                dhcpcd_prefs_abort();
@@ -382,7 +389,7 @@ add_watch_cb(DHCPCD_CONNECTION *con, const struct pollfd *fd,
        
        gio = g_io_channel_unix_new(fd->fd);
        if (gio == NULL) {
-               g_error(_("Error creating new GIO Channel\n"));
+               g_warning(_("Error creating new GIO Channel\n"));
                return;
        }
        flags = 0;
@@ -396,7 +403,7 @@ add_watch_cb(DHCPCD_CONNECTION *con, const struct pollfd *fd,
                flags |= G_IO_HUP;
        if ((eventid = g_io_add_watch(gio, flags, gio_callback, con)) == 0) {
                g_io_channel_unref(gio);
-               g_error(_("Error creating watch\n"));
+               g_warning(_("Error creating watch\n"));
                return;
        }
        w = g_malloc(sizeof(*w));
@@ -452,8 +459,10 @@ main(int argc, char *argv[])
 
        dhcpcd_set_watch_functions(con, add_watch_cb, delete_watch_cb, NULL);
        dhcpcd_set_signal_functions(con, event_cb, status_cb, scan_cb, NULL);
-       if (dhcpcd_error(con))
-               g_error("libdhcpcd: %s", dhcpcd_error(con));
+       if (dhcpcd_error(con)) {
+               g_critical("libdhcpcd: %s", dhcpcd_error(con));
+               exit(EXIT_FAILURE);
+       }
 
        menu_init(status_icon, con);
 
index 0d2818823bf3ec65642852187bbbc0a1cf298bd1..7898b4706e830abdae9e4e69c999ee6d8d9c1b85 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * dhcpcd-gtk
- * Copyright 2009-2010 Roy Marples <roy@marples.name>
+ * Copyright 2009-2012 Roy Marples <roy@marples.name>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -27,7 +27,7 @@
 #include "config.h"
 #include "dhcpcd-gtk.h"
 
-static const char *copyright = "Copyright (c) 2009-2010 Roy Marples";
+static const char *copyright = "Copyright (c) 2009-2012 Roy Marples";
 static const char *authors[] = { "Roy Marples <roy@marples.name>", NULL };
 
 static void
index 5c38e86c1e38983280d2bd06d28d0e76c2515629..af9e400c5c296b661028bf7f6eee413ff9e867e0 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * dhcpcd-gtk
- * Copyright 2009-2010 Roy Marples <roy@marples.name>
+ * Copyright 2009-2012 Roy Marples <roy@marples.name>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -174,7 +174,8 @@ list_interfaces(DHCPCD_CONNECTION *con)
 
        list = NULL;
        for (i = dhcpcd_interfaces(con); i; i = i->next)
-               list = g_slist_append(list, i->ifname);
+               if (strcmp(i->type, "ipv4") == 0)
+                       list = g_slist_append(list, i->ifname);
        return list;
 }
 
@@ -295,7 +296,7 @@ names_on_change(_unused GtkWidget *widget, gpointer data)
        if (block && name) {
                config = dhcpcd_config_load(con, block, name);
                if (config == NULL && dhcpcd_error(con))
-                       g_error("libdhcpcd: %s\n", dhcpcd_error(con));
+                       g_error("libdhcpcd: %s", dhcpcd_error(con));
        } else
                config = NULL;
        show_config(config);
index c36f29712fc03945b82f866f6b23dffbf111b315..4e3bf9f31ccf1aff315792d2b905ad79135a0a72 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * libdhcpcd
- * Copyright 2009 Roy Marples <roy@marples.name>
+ * Copyright 2009-2012 Roy Marples <roy@marples.name>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -51,6 +51,8 @@ dhcpcd_handle_event(DHCPCD_CONNECTION *con, DHCPCD_MESSAGE *msg)
        DBusMessageIter args;
        DHCPCD_IF *i, *e, *l, *n, *nl;
        char *order, *o, *p;
+       static const char *types[] = { "ipv4", "ra", NULL };
+       int ti;
 
        if (!dbus_message_iter_init(msg, &args))
                return;
@@ -60,38 +62,48 @@ dhcpcd_handle_event(DHCPCD_CONNECTION *con, DHCPCD_MESSAGE *msg)
                return;
        p = order;
        n = nl = NULL;
+
        while ((o = strsep(&p, " ")) != NULL) {
-               l = NULL;
-               for (e = con->interfaces; e; e = e->next) {
-                       if (strcmp(e->ifname, o) == 0)
-                               break;
-                       l = e;
-               }
-               if (e == NULL) {
-                       e = i;
-               } else {
-                       if (l != NULL)
-                               l->next = e->next;
-                       else
-                               con->interfaces = e->next;
-                       e->next = NULL;
-               }
-               if (e != i && strcmp(e->ifname, i->ifname) == 0) {
-                       /* Preserve the pointer */
-                       memcpy(e, i, sizeof(*e));
-                       free(i);
-                       i = e;
-               }
-               if (nl == NULL)
-                       n = nl = e;
-               else {
-                       nl->next = e;
-                       nl = nl->next;
+               for (ti = 0; ti < 2; ti++) {
+                       l = NULL;
+                       for (e = con->interfaces; e; e = e->next) {
+                               if (strcmp(e->ifname, o) == 0 &&
+                                   strcmp(e->type, types[ti]) == 0)
+                                       break;
+                               l = e;
+                       }
+                       if (e == NULL) {
+                               e = i;
+                       } else {
+                               if (l != NULL)
+                                       l->next = e->next;
+                               else
+                                       con->interfaces = e->next;
+                               e->next = NULL;
+                               if (i != NULL &&
+                                   strcmp(e->ifname, i->ifname) == 0 &&
+                                   strcmp(e->type, i->type) == 0)
+                               {
+                                       /* Preserve the pointer for
+                                        * our wireless history */
+                                       memcpy(e, i, sizeof(*e));
+                                       free(i);
+                                       i = e;
+                               }
+                       }
+                       if (nl == NULL)
+                               n = nl = e;
+                       else {
+                               nl->next = e;
+                               nl = nl->next;
+                       }
                }
        }
+
        if (nl != NULL)
                nl->next = con->interfaces;
        con->interfaces = n;
+
        if (con->event)
                con->event(con, i, con->signal_data);
 }
@@ -101,6 +113,7 @@ dhcpcd_dispatch_message(DHCPCD_CONNECTION *con, DHCPCD_MESSAGE *msg)
 {
        bool handled;
        const char *str;
+       DHCPCD_IF *ifp;
 
        if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
                return false;
@@ -122,8 +135,9 @@ dhcpcd_dispatch_message(DHCPCD_CONNECTION *con, DHCPCD_MESSAGE *msg)
        {
                if (con->wi_scanresults) {
                        str = dhcpcd_message_get_string(msg);
-                       con->wi_scanresults(con, dhcpcd_if_find(con, str),
-                           con->signal_data);
+                       ifp = dhcpcd_if_find(con, str, "ipv4");
+                       if (ifp)
+                               con->wi_scanresults(con, ifp, con->signal_data);
                }
        } else if (dbus_message_is_signal(msg, DHCPCD_SERVICE, "Event"))
                dhcpcd_handle_event(con, msg);
index 2555dde6d12c2136024dd570beb8a0af7974147c..939f40670d4421c135c622bb9fdcec3b37c60840 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * libdhcpcd
- * Copyright 2009 Roy Marples <roy@marples.name>
+ * Copyright 2009-2012 Roy Marples <roy@marples.name>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -36,6 +36,7 @@
 #define IF_SSIDSIZE 33
 #define IF_BSSIDSIZE 64
 #define FLAGSIZE 64
+#define TYPESIZE 8
 #define REASONSIZE 16
 
 typedef struct dhcpcd_wi_avs {
@@ -57,9 +58,13 @@ typedef struct dhcpcd_wi_scan {
 typedef struct dhcpcd_if {
        struct dhcpcd_if *next;
        char ifname[IF_NAMESIZE];
+       char type[TYPESIZE];
        unsigned int flags;
+       bool up;
        char reason[REASONSIZE];
        struct in_addr ip;
+       struct in6_addr prefix;
+       int prefix_len;
        unsigned char cidr;
        bool wireless;
        char ssid[IF_SSIDSIZE];
@@ -143,11 +148,9 @@ const char * dhcpcd_status(DHCPCD_CONNECTION *);
 bool dhcpcd_command(DHCPCD_CONNECTION *, const char *, const char *, char **);
 void dhcpcd_dispatch(int);
 DHCPCD_IF * dhcpcd_interfaces(DHCPCD_CONNECTION *);
-DHCPCD_IF * dhcpcd_if_find(DHCPCD_CONNECTION *, const char *);
+DHCPCD_IF * dhcpcd_if_find(DHCPCD_CONNECTION *, const char *, const char *);
 DHCPCD_CONNECTION * dhcpcd_if_connection(DHCPCD_IF *);
 
-bool dhcpcd_if_up(const DHCPCD_IF *);
-bool dhcpcd_if_down(const DHCPCD_IF *);
 char * dhcpcd_if_message(const DHCPCD_IF *);
 
 DHCPCD_WI_SCAN * dhcpcd_wi_scans(DHCPCD_CONNECTION *, DHCPCD_IF *);
index ff338e7372b7bd7b4be98a88125445096cb120bc..fe5b31869506fe15ccd17950681698f9ff52dd70 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * libdhcpcd
- * Copyright 2009 Roy Marples <roy@marples.name>
+ * Copyright 2009-2012 Roy Marples <roy@marples.name>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -24,6 +24,7 @@
  * SUCH DAMAGE.
  */
 
+#include <arpa/inet.h>
 #include <errno.h>
 #include <poll.h>
 #include <stdbool.h>
@@ -425,17 +426,25 @@ dhcpcd_if_new(DHCPCD_CONNECTION *con, DBusMessageIter *array, char **order)
                        if (!dhcpcd_iter_get(con, &var, DBUS_TYPE_STRING, &s))
                                break;
                        strlcpy(i->ifname, s, sizeof(i->ifname));
+               } else if (strcmp(s, "Type") == 0) {
+                       if (!dhcpcd_iter_get(con, &var, DBUS_TYPE_STRING, &s))
+                               break;
+                       strlcpy(i->type, s, sizeof(i->type));
                } else if (strcmp(s, "Flags") == 0) {
                        if (!dhcpcd_iter_get(con, &var, DBUS_TYPE_UINT32, &u32))
                                break;
                        i->flags = u32;
+               } else if (strcmp(s, "Up") == 0) {
+                       /* b is an int as DBus booleans want more space than
+                        * a C99 boolean */
+                       if (!dhcpcd_iter_get(con, &var, DBUS_TYPE_BOOLEAN, &b))
+                               break;
+                       i->up = b;
                } else if (strcmp(s, "Reason") == 0) {
                        if (!dhcpcd_iter_get(con, &var, DBUS_TYPE_STRING, &s))
                                break;
                        strlcpy(i->reason, s, sizeof(i->reason));
                } else if (strcmp(s, "Wireless") == 0) {
-                       /* b is an int as DBus booleans want more space than
-                        * a C99 boolean */
                        if (!dhcpcd_iter_get(con, &var, DBUS_TYPE_BOOLEAN, &b))
                                break;
                        i->wireless = b;
@@ -449,7 +458,15 @@ dhcpcd_if_new(DHCPCD_CONNECTION *con, DBusMessageIter *array, char **order)
                        i->ip.s_addr = u32;
                } else if (strcmp(s, "SubnetCIDR") == 0)
                        dbus_message_iter_get_basic(&var, &i->cidr);
-               else if (order != NULL && strcmp(s, "InterfaceOrder") == 0)
+               else if (strcmp(s, "RA_Prefix") == 0) {
+                       if (!dhcpcd_iter_get(con, &var, DBUS_TYPE_STRING, &s))
+                               break;
+                       inet_pton(AF_INET6, s, &i->prefix.s6_addr);
+               } else if (strcmp(s, "RA_PrefixLen") == 0) {
+                       if (!dhcpcd_iter_get(con, &var, DBUS_TYPE_BYTE, &b))
+                               break;
+                       i->prefix_len = b;
+               } else if (order != NULL && strcmp(s, "InterfaceOrder") == 0)
                        if (!dhcpcd_iter_get(con, &var, DBUS_TYPE_STRING, order))
                                break;
        }
@@ -514,14 +531,15 @@ dhcpcd_interfaces(DHCPCD_CONNECTION *con)
 }
 
 DHCPCD_IF *
-dhcpcd_if_find(DHCPCD_CONNECTION *con, const char *ifname)
+dhcpcd_if_find(DHCPCD_CONNECTION *con, const char *ifname, const char *type)
 {
        DHCPCD_IF *i;
 
        if (con->interfaces == NULL)
                dhcpcd_interfaces(con);
        for (i = con->interfaces; i; i = i ->next)
-               if (strcmp(i->ifname, ifname) == 0)
+               if (strcmp(i->ifname, ifname) == 0 &&
+                   strcmp(i->type, type) == 0)
                        return i;
        return NULL;
 }
@@ -572,7 +590,7 @@ dhcpcd_set_signal_functions(DHCPCD_CONNECTION *con,
        }
        if (con->wi_scanresults) {
                for (i = dhcpcd_interfaces(con); i; i = i->next)
-                       if (i->wireless)
+                       if (i->wireless && strcmp(i->type, "ipv4") == 0)
                                con->wi_scanresults(con, i, data);
        }
 }
index fbeb2e1ebfcc7fb68de0f208b0c0eb5e2b5131c2..99ec553fe9ed94ab5c43e189207e32f4f73b06f6 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * libdhcpcd
- * Copyright 2009 Roy Marples <roy@marples.name>
+ * Copyright 2009-2012 Roy Marples <roy@marples.name>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 #define _ gettext
 
-static const char *const dhcpcd_up_reasons[] = {
-       "BOUND",
-       "RENEW",
-       "REBIND",
-       "REBOOT",
-       "IPV4LL",
-       "INFORM",
-       "STATIC",
-       "TIMEOUT",
-       "ROUTERADVERT",
-       NULL
-};
-
-static const char *const dhcpcd_down_reasons[] = {
-       "EXPIRE",
-       "FAIL",
-       "NAK",
-       "NOCARRIER",
-       "STOP",
-       NULL
-};
-
-bool
-dhcpcd_if_up(const DHCPCD_IF *i)
-{
-       const char *const *r;
-
-       for (r = dhcpcd_up_reasons; *r; r++)
-               if (strcmp(*r, i->reason) == 0)
-                       return true;
-       return false;
-}
-
-bool
-dhcpcd_if_down(const DHCPCD_IF *i)
-{
-       const char *const *r;
-
-       for (r = dhcpcd_down_reasons; *r; r++)
-               if (strcmp(*r, i->reason) == 0)
-                       return true;
-       return false;
-}
-
 char *
 dhcpcd_if_message(const DHCPCD_IF *i)
 {
@@ -88,12 +44,11 @@ dhcpcd_if_message(const DHCPCD_IF *i)
        const char *reason = NULL;
        size_t len;
        bool showip, showssid;
+       char buf[INET6_ADDRSTRLEN];
     
        showip = true;
        showssid = false;
-       if (dhcpcd_if_up(i))
-               reason = _("Acquired address");
-       else if (strcmp(i->reason, "EXPIRE") == 0)
+       if (strcmp(i->reason, "EXPIRE") == 0)
                reason = _("Expired");
        else if (strcmp(i->reason, "CARRIER") == 0) {
                if (i->wireless) {
@@ -118,8 +73,14 @@ dhcpcd_if_message(const DHCPCD_IF *i)
        else if (strcmp(i->reason, "3RDPARTY") == 0)
                reason = _("Waiting for 3rd Party configuration");
 
-       if (reason == NULL)
-               reason = i->reason;
+       if (reason == NULL) {
+               if (i->up)
+                       reason = _("Configured");
+               else if (strcmp(i->type, "ra") == 0)
+                       reason = "Expired RA";
+               else
+                       reason = i->reason;
+       }
        
        len = strlen(i->ifname) + 3;
        len += strlen(reason) + 1;
@@ -127,6 +88,10 @@ dhcpcd_if_message(const DHCPCD_IF *i)
                len += 16; /* 000. * 4 */
                if (i->cidr != 0)
                        len += 3; /* /32 */
+       } else if (!IN6_IS_ADDR_UNSPECIFIED(&i->prefix)) {
+               len += INET6_ADDRSTRLEN;
+               if (i->prefix_len != 0)
+                       len += 4;
        }
        if (showssid)
                len += strlen(i->ssid) + 1;
@@ -138,6 +103,11 @@ dhcpcd_if_message(const DHCPCD_IF *i)
                p += snprintf(p, len - (p - msg), " %s", inet_ntoa(i->ip));
                if (i->cidr != 0)
                        snprintf(p, len - (p - msg), "/%d", i->cidr);
+       } else if (!IN6_IS_ADDR_UNSPECIFIED(&i->prefix) && showip) {
+               p += snprintf(p, len - (p - msg), " %s",
+                   inet_ntop(AF_INET6, &i->prefix, buf, INET6_ADDRSTRLEN));
+               if (i->prefix_len != 0)
+                       snprintf(p, len - (p - msg), "/%d", i->prefix_len);
        }
        return msg;
 }