Release tizen_2.0_beta
[framework/connectivity/connman.git] / gdhcp / client.c
index 8ea75d6..29c30fa 100644 (file)
@@ -72,7 +72,7 @@ typedef enum _dhcp_client_state {
 } ClientState;
 
 struct _GDHCPClient {
-       gint ref_count;
+       int ref_count;
        GDHCPType type;
        ClientState state;
        int ifindex;
@@ -110,6 +110,9 @@ struct _GDHCPClient {
        GDHCPDebugFunc debug_func;
        gpointer debug_data;
        char *last_address;
+#if defined TIZEN_EXT
+       gboolean init_reboot;
+#endif
 };
 
 static inline void debug(GDHCPClient *client, const char *format, ...)
@@ -212,6 +215,9 @@ static int send_select(GDHCPClient *dhcp_client)
 
        dhcp_add_simple_option(&packet, DHCP_REQUESTED_IP,
                                        dhcp_client->requested_ip);
+#if defined TIZEN_EXT
+       if (dhcp_client->init_reboot != TRUE)
+#endif
        dhcp_add_simple_option(&packet, DHCP_SERVER_ID, dhcp_client->server_ip);
 
        add_request_options(dhcp_client, &packet);
@@ -361,7 +367,7 @@ static void get_interface_mac_address(int index, uint8_t *mac_address)
        struct ifreq ifr;
        int sk, err;
 
-       sk = socket(PF_INET, SOCK_DGRAM, 0);
+       sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
        if (sk < 0) {
                perror("Open socket error");
                return;
@@ -515,7 +521,7 @@ static int dhcp_l2_socket(int ifindex)
                .filter = (struct sock_filter *) filter_instr,
        };
 
-       fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP));
+       fd = socket(PF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC, htons(ETH_P_IP));
        if (fd < 0)
                return fd;
 
@@ -1197,6 +1203,9 @@ static gboolean listener_event(GIOChannel *channel, GIOCondition condition,
                        dhcp_client->timeout = 0;
 
                        dhcp_client->lease_seconds = get_lease(&packet);
+#if defined TIZEN_EXT
+                       debug(dhcp_client, "lease %d secs", dhcp_client->lease_seconds);
+#endif
 
                        get_request(dhcp_client, &packet);
 
@@ -1217,6 +1226,9 @@ static gboolean listener_event(GIOChannel *channel, GIOCondition condition,
                        if (dhcp_client->timeout > 0)
                                g_source_remove(dhcp_client->timeout);
 
+#if defined TIZEN_EXT
+                       g_dhcp_client_set_address_known(dhcp_client, FALSE);
+#endif
                        dhcp_client->timeout = g_timeout_add_seconds_full(
                                                        G_PRIORITY_HIGH, 3,
                                                        restart_dhcp_timeout,
@@ -1345,6 +1357,15 @@ int g_dhcp_client_start(GDHCPClient *dhcp_client, const char *last_address)
                        dhcp_client->last_address = g_strdup(last_address);
                }
        }
+#if defined TIZEN_EXT
+       if (dhcp_client->init_reboot == TRUE) {
+               dhcp_client->requested_ip = addr;
+
+               start_request(dhcp_client);
+
+               return 0;
+       }
+#endif
        send_discover(dhcp_client, addr);
 
        dhcp_client->timeout = g_timeout_add_seconds_full(G_PRIORITY_HIGH,
@@ -1506,7 +1527,7 @@ GDHCPClient *g_dhcp_client_ref(GDHCPClient *dhcp_client)
        if (dhcp_client == NULL)
                return NULL;
 
-       g_atomic_int_inc(&dhcp_client->ref_count);
+       __sync_fetch_and_add(&dhcp_client->ref_count, 1);
 
        return dhcp_client;
 }
@@ -1516,7 +1537,7 @@ void g_dhcp_client_unref(GDHCPClient *dhcp_client)
        if (dhcp_client == NULL)
                return;
 
-       if (g_atomic_int_dec_and_test(&dhcp_client->ref_count) == FALSE)
+       if (__sync_fetch_and_sub(&dhcp_client->ref_count, 1) != 1)
                return;
 
        g_dhcp_client_stop(dhcp_client);
@@ -1543,3 +1564,19 @@ void g_dhcp_client_set_debug(GDHCPClient *dhcp_client,
        dhcp_client->debug_func = func;
        dhcp_client->debug_data = user_data;
 }
+
+#if defined TIZEN_EXT
+void g_dhcp_client_set_address_known(GDHCPClient *dhcp_client, gboolean known)
+{
+       /* DHCPREQUEST during INIT-REBOOT state (rfc2131)
+        * 4.4.3 Initialization with known network address
+        * 4.3.2 DHCPREQUEST generated during INIT-REBOOT state
+        */
+       debug(dhcp_client, "known network address (%d)", known);
+
+       if (dhcp_client->init_reboot == known)
+               return;
+
+       dhcp_client->init_reboot = known;
+}
+#endif