static void trigger_rtnl(int index, void *user_data) { struct connman_rtnl *rtnl = user_data; if (rtnl->newlink) { unsigned short type = __connman_ipconfig_get_type_from_index(index); unsigned int flags = __connman_ipconfig_get_flags_from_index(index); rtnl->newlink(type, index, flags, 0); } if (rtnl->newgateway) { const char *gateway = __connman_ipconfig_get_gateway_from_index(index); if (gateway != NULL) rtnl->newgateway(index, gateway); } }
/* * DUID should not change over time so save it to file. * See RFC 3315 chapter 9 for details. */ static int set_duid(struct connman_service *service, struct connman_network *network, GDHCPClient *dhcp_client, int index) { GKeyFile *keyfile; const char *ident; char *hex_duid; unsigned char *duid; int duid_len; ident = __connman_service_get_ident(service); keyfile = connman_storage_load_service(ident); if (keyfile == NULL) return -EINVAL; hex_duid = g_key_file_get_string(keyfile, ident, "IPv6.DHCP.DUID", NULL); if (hex_duid != NULL) { unsigned int i, j = 0, hex; size_t hex_duid_len = strlen(hex_duid); duid = g_try_malloc0(hex_duid_len / 2); if (duid == NULL) { g_key_file_free(keyfile); g_free(hex_duid); return -ENOMEM; } for (i = 0; i < hex_duid_len; i += 2) { sscanf(hex_duid + i, "%02x", &hex); duid[j++] = hex; } duid_len = hex_duid_len / 2; } else { int ret; int type = __connman_ipconfig_get_type_from_index(index); ret = g_dhcpv6_create_duid(G_DHCPV6_DUID_LLT, index, type, &duid, &duid_len); if (ret < 0) { g_key_file_free(keyfile); return ret; } hex_duid = convert_to_hex(duid, duid_len); if (hex_duid == NULL) { g_key_file_free(keyfile); return -ENOMEM; } g_key_file_set_string(keyfile, ident, "IPv6.DHCP.DUID", hex_duid); __connman_storage_save_service(keyfile, ident); } g_free(hex_duid); g_key_file_free(keyfile); g_dhcpv6_client_set_duid(dhcp_client, duid, duid_len); return 0; }