Track link address and MTU settings
authorMarcel Holtmann <marcel@holtmann.org>
Sun, 20 Dec 2009 07:00:52 +0000 (23:00 -0800)
committerMarcel Holtmann <marcel@holtmann.org>
Sun, 20 Dec 2009 07:00:52 +0000 (23:00 -0800)
src/connman.h
src/ipconfig.c
src/rtnl.c
src/service.c

index f030785..889cc6d 100644 (file)
@@ -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);
index c2dd555..1298a78 100644 (file)
@@ -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)
 {
index 455a259..195f210 100644 (file)
@@ -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));
 
index b9ed4e4..ffec472 100644 (file)
@@ -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)