diff options
author | Jukka Rissanen <jukka.rissanen@linux.intel.com> | 2012-01-05 13:38:11 +0200 |
---|---|---|
committer | Daniel Wagner <daniel.wagner@bmw-carit.de> | 2012-01-05 13:17:26 +0100 |
commit | 8aa986762c7774844e6199b8fa2514d639df2500 (patch) | |
tree | 2a5be3b4ac85ced613e8e65cc3a4a0468aacaebb /gdhcp | |
parent | 3fd016f68a3d021d89fa7a1be1fa712e27e4913b (diff) | |
download | connman-8aa986762c7774844e6199b8fa2514d639df2500.tar.gz connman-8aa986762c7774844e6199b8fa2514d639df2500.tar.bz2 connman-8aa986762c7774844e6199b8fa2514d639df2500.zip |
dhcpv6: Renew message implemented.
Diffstat (limited to 'gdhcp')
-rw-r--r-- | gdhcp/client.c | 46 | ||||
-rw-r--r-- | gdhcp/gdhcp.h | 5 |
2 files changed, 49 insertions, 2 deletions
diff --git a/gdhcp/client.c b/gdhcp/client.c index a8fedb1f..a1f03097 100644 --- a/gdhcp/client.c +++ b/gdhcp/client.c @@ -72,6 +72,7 @@ typedef enum _dhcp_client_state { INFORMATION_REQ, SOLICITATION, REQUEST, + RENEW, } ClientState; struct _GDHCPClient { @@ -120,6 +121,8 @@ struct _GDHCPClient { gpointer advertise_data; GDHCPClientEventFunc request_cb; gpointer request_data; + GDHCPClientEventFunc renew_cb; + gpointer renew_data; char *last_address; unsigned char *duid; int duid_len; @@ -130,6 +133,7 @@ struct _GDHCPClient { uint32_t T1, T2; struct in6_addr ia_na; struct in6_addr ia_ta; + time_t last_renew; }; static inline void debug(GDHCPClient *client, const char *format, ...) @@ -618,7 +622,7 @@ void g_dhcpv6_client_create_iaid(GDHCPClient *dhcp_client, int index, } int g_dhcpv6_client_get_timeouts(GDHCPClient *dhcp_client, - uint32_t *T1, uint32_t *T2) + uint32_t *T1, uint32_t *T2, time_t *last_renew) { if (dhcp_client == NULL || dhcp_client->type == G_DHCP_IPV4) return -EINVAL; @@ -629,6 +633,9 @@ int g_dhcpv6_client_get_timeouts(GDHCPClient *dhcp_client, if (T2 != NULL) *T2 = dhcp_client->T2; + if (last_renew != NULL) + *last_renew = dhcp_client->last_renew; + return 0; } @@ -787,6 +794,11 @@ static int send_dhcpv6_request(GDHCPClient *dhcp_client) return send_dhcpv6_msg(dhcp_client, DHCPV6_REQUEST, "request"); } +static int send_dhcpv6_renew(GDHCPClient *dhcp_client) +{ + return send_dhcpv6_msg(dhcp_client, DHCPV6_RENEW, "renew"); +} + static int send_information_req(GDHCPClient *dhcp_client) { return send_dhcpv6_msg(dhcp_client, DHCPV6_INFORMATION_REQ, @@ -858,6 +870,7 @@ GDHCPClient *g_dhcp_client_new(GDHCPType type, dhcp_client->require_list = NULL; dhcp_client->duid = NULL; dhcp_client->duid_len = 0; + dhcp_client->last_renew = time(0); *error = G_DHCP_CLIENT_ERROR_NONE; @@ -1966,6 +1979,7 @@ static gboolean listener_event(GIOChannel *channel, GIOCondition condition, break; case INFORMATION_REQ: case REQUEST: + case RENEW: if (dhcp_client->type != G_DHCP_IPV6) return TRUE; @@ -2007,6 +2021,11 @@ static gboolean listener_event(GIOChannel *channel, GIOCondition condition, dhcp_client->request_data); return TRUE; } + if (dhcp_client->renew_cb != NULL) { + dhcp_client->renew_cb(dhcp_client, + dhcp_client->renew_data); + return TRUE; + } break; default: break; @@ -2130,6 +2149,16 @@ int g_dhcp_client_start(GDHCPClient *dhcp_client, const char *last_address) return re; } send_dhcpv6_request(dhcp_client); + + } else if (dhcp_client->renew_cb) { + dhcp_client->state = RENEW; + re = switch_listening_mode(dhcp_client, L3); + if (re != 0) { + switch_listening_mode(dhcp_client, L_NONE); + dhcp_client->state = 0; + return re; + } + send_dhcpv6_renew(dhcp_client); } return 0; @@ -2268,6 +2297,12 @@ void g_dhcp_client_register_event(GDHCPClient *dhcp_client, dhcp_client->request_cb = func; dhcp_client->request_data = data; return; + case G_DHCP_CLIENT_EVENT_RENEW: + if (dhcp_client->type == G_DHCP_IPV4) + return; + dhcp_client->renew_cb = func; + dhcp_client->renew_data = data; + return; } } @@ -2306,6 +2341,7 @@ char *g_dhcp_client_get_netmask(GDHCPClient *dhcp_client) case INFORMATION_REQ: case SOLICITATION: case REQUEST: + case RENEW: break; } return NULL; @@ -2402,6 +2438,14 @@ void g_dhcpv6_client_set_send(GDHCPClient *dhcp_client, } } +void g_dhcpv6_client_reset_renew(GDHCPClient *dhcp_client) +{ + if (dhcp_client == NULL || dhcp_client->type == G_DHCP_IPV4) + return; + + dhcp_client->last_renew = time(0); +} + uint16_t g_dhcpv6_client_get_status(GDHCPClient *dhcp_client) { if (dhcp_client == NULL || dhcp_client->type == G_DHCP_IPV4) diff --git a/gdhcp/gdhcp.h b/gdhcp/gdhcp.h index 22a28a54..3982e3ef 100644 --- a/gdhcp/gdhcp.h +++ b/gdhcp/gdhcp.h @@ -56,6 +56,7 @@ typedef enum { G_DHCP_CLIENT_EVENT_SOLICITATION, G_DHCP_CLIENT_EVENT_ADVERTISE, G_DHCP_CLIENT_EVENT_REQUEST, + G_DHCP_CLIENT_EVENT_RENEW, } GDHCPClientEvent; typedef enum { @@ -141,10 +142,12 @@ int g_dhcpv6_client_set_oro(GDHCPClient *dhcp_client, int args, ...); void g_dhcpv6_client_create_iaid(GDHCPClient *dhcp_client, int index, unsigned char *iaid); int g_dhcpv6_client_get_timeouts(GDHCPClient *dhcp_client, - uint32_t *T1, uint32_t *T2); + uint32_t *T1, uint32_t *T2, + time_t *last_renew); uint32_t g_dhcpv6_client_get_iaid(GDHCPClient *dhcp_client); int g_dhcpv6_client_set_ia(GDHCPClient *dhcp_client, int index, int code, uint32_t *T1, uint32_t *T2, gboolean add_iaaddr); +void g_dhcpv6_client_reset_renew(GDHCPClient *dhcp_client); /* DHCP Server */ typedef enum { |