+ switch (type) {
+ case ARPHRD_ETHER:
+ case ARPHRD_LOOPBACK:
+ case ARPHRD_NONE:
+ __connman_ipconfig_dellink(index, &stats);
+ break;
+ }
+
+ g_hash_table_remove(interface_list, GINT_TO_POINTER(index));
+}
+
+static void extract_ipv4_addr(struct ifaddrmsg *msg, int bytes,
+ const char **label,
+ struct in_addr *local,
+ struct in_addr *address,
+ struct in_addr *broadcast)
+{
+ struct rtattr *attr;
+
+ for (attr = IFA_RTA(msg); RTA_OK(attr, bytes);
+ attr = RTA_NEXT(attr, bytes)) {
+ switch (attr->rta_type) {
+ case IFA_ADDRESS:
+ if (address != NULL)
+ *address = *((struct in_addr *) RTA_DATA(attr));
+ break;
+ case IFA_LOCAL:
+ if (local != NULL)
+ *local = *((struct in_addr *) RTA_DATA(attr));
+ break;
+ case IFA_BROADCAST:
+ if (broadcast != NULL)
+ *broadcast = *((struct in_addr *) RTA_DATA(attr));
+ break;
+ case IFA_LABEL:
+ if (label != NULL)
+ *label = RTA_DATA(attr);
+ break;
+ }
+ }
+}
+
+static void extract_ipv6_addr(struct ifaddrmsg *msg, int bytes,
+ struct in6_addr *addr,
+ struct in6_addr *local)
+{
+ struct rtattr *attr;
+
+ for (attr = IFA_RTA(msg); RTA_OK(attr, bytes);
+ attr = RTA_NEXT(attr, bytes)) {
+ switch (attr->rta_type) {
+ case IFA_ADDRESS:
+ if (addr != NULL)
+ *addr = *((struct in6_addr *) RTA_DATA(attr));
+ break;
+ case IFA_LOCAL:
+ if (local != NULL)
+ *local = *((struct in6_addr *) RTA_DATA(attr));
+ break;
+ }
+ }
+}
+
+static void process_newaddr(unsigned char family, unsigned char prefixlen,
+ int index, struct ifaddrmsg *msg, int bytes)
+{
+ const char *label = NULL;
+ void *src;
+ char ip_string[INET6_ADDRSTRLEN];
+
+ if (family == AF_INET) {
+ struct in_addr ipv4_addr = { INADDR_ANY };
+
+ extract_ipv4_addr(msg, bytes, &label, &ipv4_addr, NULL, NULL);
+ src = &ipv4_addr;
+ } else if (family == AF_INET6) {
+ struct in6_addr ipv6_address, ipv6_local;
+
+ extract_ipv6_addr(msg, bytes, &ipv6_address, &ipv6_local);
+ if (IN6_IS_ADDR_LINKLOCAL(&ipv6_address))
+ return;
+
+ src = &ipv6_address;
+ } else {
+ return;
+ }
+
+ if (inet_ntop(family, src, ip_string, INET6_ADDRSTRLEN) == NULL)
+ return;
+
+ __connman_ipconfig_newaddr(index, family, label,
+ prefixlen, ip_string);
+
+ if (family == AF_INET6) {
+ /*
+ * Re-create RDNSS configured servers if there are any
+ * for this interface. This is done because we might
+ * have now properly configured interface with proper
+ * autoconfigured address.
+ */
+ char *interface = connman_inet_ifname(index);
+
+ __connman_resolver_redo_servers(interface);
+
+ g_free(interface);
+ }
+}
+
+static void process_deladdr(unsigned char family, unsigned char prefixlen,
+ int index, struct ifaddrmsg *msg, int bytes)
+{
+ const char *label = NULL;
+ void *src;
+ char ip_string[INET6_ADDRSTRLEN];
+
+ if (family == AF_INET) {
+ struct in_addr ipv4_addr = { INADDR_ANY };
+
+ extract_ipv4_addr(msg, bytes, &label, &ipv4_addr, NULL, NULL);
+ src = &ipv4_addr;
+ } else if (family == AF_INET6) {
+ struct in6_addr ipv6_address, ipv6_local;
+
+ extract_ipv6_addr(msg, bytes, &ipv6_address, &ipv6_local);
+ if (IN6_IS_ADDR_LINKLOCAL(&ipv6_address))
+ return;
+
+ src = &ipv6_address;
+ } else {
+ return;
+ }
+
+ if (inet_ntop(family, src, ip_string, INET6_ADDRSTRLEN) == NULL)
+ return;
+
+ __connman_ipconfig_deladdr(index, family, label,
+ prefixlen, ip_string);
+}
+
+static void extract_ipv4_route(struct rtmsg *msg, int bytes, int *index,
+ struct in_addr *dst,
+ struct in_addr *gateway)
+{
+ struct rtattr *attr;
+
+ for (attr = RTM_RTA(msg); RTA_OK(attr, bytes);
+ attr = RTA_NEXT(attr, bytes)) {
+ switch (attr->rta_type) {
+ case RTA_DST:
+ if (dst != NULL)
+ *dst = *((struct in_addr *) RTA_DATA(attr));
+ break;
+ case RTA_GATEWAY:
+ if (gateway != NULL)
+ *gateway = *((struct in_addr *) RTA_DATA(attr));
+ break;
+ case RTA_OIF:
+ if (index != NULL)
+ *index = *((int *) RTA_DATA(attr));
+ break;
+ }
+ }
+}
+
+static void extract_ipv6_route(struct rtmsg *msg, int bytes, int *index,
+ struct in6_addr *dst,
+ struct in6_addr *gateway)
+{
+ struct rtattr *attr;
+
+ for (attr = RTM_RTA(msg); RTA_OK(attr, bytes);
+ attr = RTA_NEXT(attr, bytes)) {
+ switch (attr->rta_type) {
+ case RTA_DST:
+ if (dst != NULL)
+ *dst = *((struct in6_addr *) RTA_DATA(attr));
+ break;
+ case RTA_GATEWAY:
+ if (gateway != NULL)
+ *gateway =
+ *((struct in6_addr *) RTA_DATA(attr));
+ break;
+ case RTA_OIF:
+ if (index != NULL)
+ *index = *((int *) RTA_DATA(attr));
+ break;
+ }
+ }
+}
+
+static void process_newroute(unsigned char family, unsigned char scope,
+ struct rtmsg *msg, int bytes)
+{
+ GSList *list;
+ char dststr[INET6_ADDRSTRLEN], gatewaystr[INET6_ADDRSTRLEN];
+ int index = -1;
+
+ if (family == AF_INET) {
+ struct in_addr dst = { INADDR_ANY }, gateway = { INADDR_ANY };
+
+ extract_ipv4_route(msg, bytes, &index, &dst, &gateway);
+
+ inet_ntop(family, &dst, dststr, sizeof(dststr));
+ inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
+
+ __connman_ipconfig_newroute(index, family, scope, dststr,
+ gatewaystr);
+
+ /* skip host specific routes */
+ if (scope != RT_SCOPE_UNIVERSE &&
+ !(scope == RT_SCOPE_LINK && dst.s_addr == INADDR_ANY))
+ return;
+
+ if (dst.s_addr != INADDR_ANY)
+ return;
+
+ } else if (family == AF_INET6) {
+ struct in6_addr dst = IN6ADDR_ANY_INIT,
+ gateway = IN6ADDR_ANY_INIT;
+
+ extract_ipv6_route(msg, bytes, &index, &dst, &gateway);
+
+ inet_ntop(family, &dst, dststr, sizeof(dststr));
+ inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
+
+ __connman_ipconfig_newroute(index, family, scope, dststr,
+ gatewaystr);
+
+ /* skip host specific routes */
+ if (scope != RT_SCOPE_UNIVERSE &&
+ !(scope == RT_SCOPE_LINK &&
+ IN6_IS_ADDR_UNSPECIFIED(&dst)))
+ return;
+
+ if (!IN6_IS_ADDR_UNSPECIFIED(&dst))
+ return;
+ } else
+ return;
+
+ for (list = rtnl_list; list; list = list->next) {
+ struct connman_rtnl *rtnl = list->data;
+
+ if (rtnl->newgateway)
+ rtnl->newgateway(index, gatewaystr);
+ }