Report status cleaner.
static void
update_online(DHCPCD_CONNECTION *con, bool showif)
{
- bool ison, iscarrier, isstop;
+ bool ison, iscarrier;
char *msg, *msgs, *tmp;
- DHCPCD_IF *ifs, *i, *j;
+ DHCPCD_IF *ifs, *i;
ison = iscarrier = false;
msgs = NULL;
ifs = dhcpcd_interfaces(con);
for (i = ifs; i; i = i->next) {
- if (showif)
- g_message("%s: %s", i->ifname, i->reason);
- if (strcmp(i->reason, "RELEASE") == 0 ||
- strcmp(i->reason, "STOP") == 0)
- continue;
- if (strcmp(i->type, "ipv4") != 0) {
- isstop = false;
- for (j = ifs; j; j = j->next)
- if (strcmp(j->ifname, i->ifname) == 0 &&
- strcmp(j->type, "ipv4") == 0)
- {
- if (strcmp(j->reason, "STOP") == 0)
- isstop = true;
- break;
- }
- if (isstop)
- continue;
- }
if (i->up)
ison = iscarrier = true;
if (!iscarrier && g_strcmp0(i->reason, "CARRIER") == 0)
iscarrier = true;
msg = dhcpcd_if_message(i);
if (msg) {
+ if (showif)
+ g_message("%s", msg);
if (msgs) {
tmp = g_strconcat(msgs, "\n", msg, NULL);
g_free(msgs);
g_free(msg);
msgs = tmp;
} else
- msgs = msg;
- }
+ msgs = msg;
+ } else if (showif)
+ g_message("%s: %s", i->ifname, i->reason);
}
if (online != ison || carrier != iscarrier) {
char *msg;
const char *icon;
- g_message("%s: %s", i->ifname, i->reason);
+ g_message("interface event: %s: %s", i->ifname, i->reason);
update_online(con, false);
/* We should ignore renew and stop so we don't annoy the user */
return;
msg = dhcpcd_if_message(i);
- if (i->up)
- icon = "network-transmit-receive";
- //else
- // icon = "network-transmit";
- if (!i->up)
- icon = "network-offline";
- notify(_("Network event"), msg, icon);
- g_free(msg);
+ if (msg) {
+ g_message("%s", msg);
+ if (i->up)
+ icon = "network-transmit-receive";
+ //else
+ // icon = "network-transmit";
+ if (!i->up)
+ icon = "network-offline";
+ notify(_("Network event"), msg, icon);
+ g_free(msg);
+ }
}
static void
#define IN_LIBDHCPCD
#include "libdhcpcd.h"
+static const char *dhcpcd_types[] = { "link", "ipv4", "ra", "dhcp6", NULL };
+
static const char *
dhcpcd_message_get_string(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))
p = order;
n = nl = NULL;
+ /* Remove all instances on carrier drop */
+ if (strcmp(i->reason, "NOCARRIER") == 0 ||
+ strcmp(i->reason, "DEPARTED") == 0 ||
+ strcmp(i->reason, "STOPPED") == 0)
+ {
+ l = NULL;
+ for (e = con->interfaces; e; e = n) {
+ n = e->next;
+ if (strcmp(e->ifname, i->ifname) == 0) {
+ if (strcmp(e->type, i->type) == 0)
+ l = nl = e;
+ else {
+ if (l)
+ l->next = e->next;
+ else
+ con->interfaces = e->next;
+ free(e);
+ }
+ } else
+ l = e;
+ }
+ }
+
+ /* Find our pointer */
+ if (nl == NULL) {
+ l = NULL;
+ for (e = con->interfaces; e; e = e->next) {
+ if (strcmp(e->ifname, i->ifname) == 0 &&
+ strcmp(e->type, i->type) == 0)
+ {
+ nl = e;
+ break;
+ }
+ l = e;
+ }
+ }
+ if (nl) {
+ /* Preserve the pointer for wireless history */
+ n = nl->next;
+ memcpy(nl, i, sizeof(*i));
+ nl->next = n;
+ free(i);
+ i = nl;
+ } else {
+ /* Append it then */
+ if (l)
+ l->next = i;
+ else
+ con->interfaces = i;
+ i->next = NULL;
+ }
+
+ /* Sort! */
+ n = nl = NULL;
while ((o = strsep(&p, " ")) != NULL) {
- for (ti = 0; ti < 2; ti++) {
+ for (ti = 0; dhcpcd_types[ti]; ti++) {
l = NULL;
for (e = con->interfaces; e; e = e->next) {
if (strcmp(e->ifname, o) == 0 &&
- strcmp(e->type, types[ti]) == 0)
+ strcmp(e->type, dhcpcd_types[ti]) == 0)
break;
l = e;
}
- if (e == NULL) {
- if (strcmp(i->ifname, o) != 0 ||
- strcmp(i->type, types[ti]) == 0)
- continue;
- e = i;
- } else {
- if (l != NULL)
- l->next = e->next;
- else
- con->interfaces = e->next;
- 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;
- }
- e->next = NULL;
- }
+ if (e == NULL)
+ continue;
+ if (l)
+ l->next = e->next;
+ else
+ con->interfaces = e->next;
+ e->next = NULL;
if (nl == NULL)
n = nl = e;
else {
nl->next = e;
- nl = nl->next;
+ nl = e;
}
}
}
-
- if (nl != NULL)
- nl->next = con->interfaces;
+ /* Free any stragglers */
+ while (con->interfaces) {
+ e = con->interfaces->next;
+ free(con->interfaces);
+ con->interfaces = e;
+ }
con->interfaces = n;
if (con->event)
{
if (con->wi_scanresults) {
str = dhcpcd_message_get_string(msg);
- ifp = dhcpcd_if_find(con, str, "ipv4");
+ ifp = dhcpcd_if_find(con, str, "link");
if (ifp)
con->wi_scanresults(con, ifp, con->signal_data);
}
DBusMessageIter args, dict, entry;
DHCPCD_IF *i, *l;
int errors;
+ char *stopif;
if (con->interfaces != NULL)
return con->interfaces;
l = NULL;
errors = con->errors;
dbus_message_iter_recurse(&args, &dict);
+ stopif = NULL;
for (;
dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY;
dbus_message_iter_next(&dict))
i = dhcpcd_if_new(con, &entry, NULL);
if (i == NULL)
break;
+ if (stopif && strcmp(stopif, i->ifname) == 0) {
+ free(i);
+ continue;
+ }
+ if (strcmp(i->reason, "NOCARRIER") == 0 ||
+ strcmp(i->reason, "DEPARTED") == 0 ||
+ strcmp(i->reason, "STOPPED") == 0)
+ stopif = i->ifname;
if (l == NULL)
con->interfaces = i;
else
}
if (con->wi_scanresults) {
for (i = dhcpcd_interfaces(con); i; i = i->next)
- if (i->wireless && strcmp(i->type, "ipv4") == 0)
+ if (i->wireless && strcmp(i->type, "link") == 0)
con->wi_scanresults(con, i, data);
}
}
} else
reason = _("Cable unplugged");
showip = false;
- } else if (strcmp(i->reason, "FAIL") == 0)
+ } else if (strcmp(i->reason, "UNKNOWN") == 0)
+ reason = _("Unknown link state");
+ else if (strcmp(i->reason, "FAIL") == 0)
reason = _("Automatic configuration not possible");
else if (strcmp(i->reason, "3RDPARTY") == 0)
reason = _("Waiting for 3rd Party configuration");
if (showssid)
p += snprintf(p, len - (size_t)(p - msg), " %s", i->ssid);
if (i->ip.s_addr != 0 && showip) {
- p += snprintf(p, len - (size_t)(p - msg), " %s", inet_ntoa(i->ip));
+ p += snprintf(p, len - (size_t)(p - msg), " %s",
+ inet_ntoa(i->ip));
if (i->cidr != 0)
snprintf(p, len - (size_t)(p - msg), "/%d", i->cidr);
} else if (!IN6_IS_ADDR_UNSPECIFIED(&i->ip6) && showip) {
p += snprintf(p, len - (size_t)(p - msg), " %s",
inet_ntop(AF_INET6, &i->prefix, buf, INET6_ADDRSTRLEN));
if (i->prefix_len != 0)
- snprintf(p, len - (size_t)(p - msg), "/%d", i->prefix_len);
+ snprintf(p, len - (size_t)(p - msg),
+ "/%d", i->prefix_len);
}
return msg;
}