From 94d8f5eb230b476d8bfb1524962e698d4317a734 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 19 Dec 2009 23:00:52 -0800 Subject: [PATCH] Track link address and MTU settings --- src/connman.h | 5 ++++- src/ipconfig.c | 30 +++++++++++++++++++++++++++++- src/rtnl.c | 43 ++++++++++++++++++++++++++++++------------- src/service.c | 7 +++---- 4 files changed, 66 insertions(+), 19 deletions(-) diff --git a/src/connman.h b/src/connman.h index f030785..889cc6d 100644 --- a/src/connman.h +++ b/src/connman.h @@ -104,7 +104,8 @@ int __connman_ipconfig_init(void); void __connman_ipconfig_cleanup(void); void __connman_ipconfig_newlink(int index, unsigned short type, - unsigned int flags); + unsigned int flags, const char *address, + unsigned short mtu); void __connman_ipconfig_dellink(int index); void __connman_ipconfig_newaddr(int index, const char *label, unsigned char prefixlen, const char *address); @@ -131,6 +132,8 @@ void __connman_ipconfig_append_ipv4(struct connman_ipconfig *ipconfig, DBusMessageIter *iter); int __connman_ipconfig_set_ipv4(struct connman_ipconfig *ipconfig, const char *key, DBusMessageIter *value); +int __connman_ipconfig_append_ethernet(struct connman_ipconfig *ipconfig, + DBusMessageIter *iter); int __connman_ipconfig_load(struct connman_ipconfig *ipconfig, GKeyFile *keyfile, const char *identifier, const char *prefix); diff --git a/src/ipconfig.c b/src/ipconfig.c index c2dd555..1298a78 100644 --- a/src/ipconfig.c +++ b/src/ipconfig.c @@ -45,6 +45,9 @@ struct connman_ipconfig { enum connman_ipconfig_method method; struct connman_ipaddress *address; + + char *eth; + uint16_t mtu; }; struct connman_ipdevice { @@ -285,7 +288,8 @@ static void __connman_ipconfig_lower_down(struct connman_ipdevice *ipdevice) } void __connman_ipconfig_newlink(int index, unsigned short type, - unsigned int flags) + unsigned int flags, const char *address, + unsigned short mtu) { struct connman_ipdevice *ipdevice; GList *list; @@ -375,6 +379,10 @@ update: if (index != ipconfig->index) continue; + g_free(ipconfig->eth); + ipconfig->eth = g_strdup(address); + ipconfig->mtu = mtu; + if (up == TRUE && ipconfig->ops->up) ipconfig->ops->up(ipconfig); if (lower_up == TRUE && ipconfig->ops->lower_up) @@ -691,6 +699,7 @@ void connman_ipconfig_unref(struct connman_ipconfig *ipconfig) } connman_ipaddress_free(ipconfig->address); + g_free(ipconfig->eth); g_free(ipconfig); } } @@ -929,6 +938,25 @@ int __connman_ipconfig_set_ipv4(struct connman_ipconfig *ipconfig, return 0; } +int __connman_ipconfig_append_ethernet(struct connman_ipconfig *ipconfig, + DBusMessageIter *iter) +{ + const char *method = "auto"; + + connman_dbus_dict_append_basic(iter, "Method", + DBUS_TYPE_STRING, &method); + + if (ipconfig->eth != NULL) + connman_dbus_dict_append_basic(iter, "Address", + DBUS_TYPE_STRING, &ipconfig->eth); + + if (ipconfig->mtu > 0) + connman_dbus_dict_append_basic(iter, "MTU", + DBUS_TYPE_UINT16, &ipconfig->mtu); + + return 0; +} + int __connman_ipconfig_load(struct connman_ipconfig *ipconfig, GKeyFile *keyfile, const char *identifier, const char *prefix) { diff --git a/src/rtnl.c b/src/rtnl.c index 455a259..195f210 100644 --- a/src/rtnl.c +++ b/src/rtnl.c @@ -240,7 +240,8 @@ static const char *operstate2str(unsigned char operstate) } static void extract_link(struct ifinfomsg *msg, int bytes, - const char **ifname, unsigned char *operstate) + const char **address, const char **ifname, + unsigned int *mtu, unsigned char *operstate) { struct rtnl_link_stats stats; struct rtattr *attr; @@ -248,15 +249,17 @@ static void extract_link(struct ifinfomsg *msg, int bytes, for (attr = IFLA_RTA(msg); RTA_OK(attr, bytes); attr = RTA_NEXT(attr, bytes)) { switch (attr->rta_type) { + case IFLA_ADDRESS: + if (address != NULL) + *address = RTA_DATA(attr); + break; case IFLA_IFNAME: if (ifname != NULL) *ifname = RTA_DATA(attr); break; - case IFLA_OPERSTATE: - if (operstate != NULL) - *operstate = *((unsigned char *) RTA_DATA(attr)); - break; - case IFLA_LINKMODE: + case IFLA_MTU: + if (mtu != NULL) + *mtu = *((unsigned int *) RTA_DATA(attr)); break; case IFLA_STATS: memcpy(&stats, RTA_DATA(attr), @@ -266,6 +269,12 @@ static void extract_link(struct ifinfomsg *msg, int bytes, connman_info("%s {TX} %d packets %d bytes", *ifname, stats.tx_packets, stats.tx_bytes); break; + case IFLA_OPERSTATE: + if (operstate != NULL) + *operstate = *((unsigned char *) RTA_DATA(attr)); + break; + case IFLA_LINKMODE: + break; } } } @@ -273,22 +282,28 @@ static void extract_link(struct ifinfomsg *msg, int bytes, static void process_newlink(unsigned short type, int index, unsigned flags, unsigned change, struct ifinfomsg *msg, int bytes) { - unsigned char operstate = 0xff; + const char *address = NULL; const char *ifname = NULL; + unsigned int mtu = 0; + unsigned char operstate = 0xff; GSList *list; + extract_link(msg, bytes, &address, &ifname, &mtu, &operstate); + switch (type) { case ARPHRD_ETHER: case ARPHRD_LOOPBACK: case ARPHRD_NONE: - __connman_ipconfig_newlink(index, type, flags); + __connman_ipconfig_newlink(index, type, flags, address, mtu); break; } - extract_link(msg, bytes, &ifname, &operstate); + if (address != NULL && strlen(address) > 0) + connman_info("%s {newlink} index %d address %s mtu %u", + ifname, index, address, mtu); if (operstate != 0xff) - connman_info("%s {newlink} index %d operstate %d <%s>", + connman_info("%s {newlink} index %d operstate %u <%s>", ifname, index, operstate, operstate2str(operstate)); @@ -316,14 +331,16 @@ static void process_newlink(unsigned short type, int index, unsigned flags, static void process_dellink(unsigned short type, int index, unsigned flags, unsigned change, struct ifinfomsg *msg, int bytes) { - unsigned char operstate = 0xff; + const char *address = NULL; const char *ifname = NULL; + unsigned int mtu = 0; + unsigned char operstate = 0xff; GSList *list; - extract_link(msg, bytes, &ifname, &operstate); + extract_link(msg, bytes, &address, &ifname, &mtu, &operstate); if (operstate != 0xff) - connman_info("%s {dellink} index %d operstate %d <%s>", + connman_info("%s {dellink} index %d operstate %u <%s>", ifname, index, operstate, operstate2str(operstate)); diff --git a/src/service.c b/src/service.c index b9ed4e4..ffec472 100644 --- a/src/service.c +++ b/src/service.c @@ -385,11 +385,10 @@ static void apn_changed(struct connman_service *service) static void append_ethernet(DBusMessageIter *iter, void *user_data) { - //struct connman_service *service = user_data; - const char *method = "auto"; + struct connman_service *service = user_data; - connman_dbus_dict_append_basic(iter, "Method", - DBUS_TYPE_STRING, &method); + if (service->ipconfig != NULL) + __connman_ipconfig_append_ethernet(service->ipconfig, iter); } static void append_ipv4(DBusMessageIter *iter, void *user_data) -- 2.7.4