summaryrefslogtreecommitdiffstats
path: root/tinyNET/src/dhcp6
diff options
context:
space:
mode:
Diffstat (limited to 'tinyNET/src/dhcp6')
-rwxr-xr-xtinyNET/src/dhcp6/tnet_dhcp6.c364
-rwxr-xr-xtinyNET/src/dhcp6/tnet_dhcp6.h35
-rwxr-xr-xtinyNET/src/dhcp6/tnet_dhcp6_duid.c307
-rwxr-xr-xtinyNET/src/dhcp6/tnet_dhcp6_duid.h131
-rwxr-xr-xtinyNET/src/dhcp6/tnet_dhcp6_message.c130
-rwxr-xr-xtinyNET/src/dhcp6/tnet_dhcp6_message.h152
-rwxr-xr-xtinyNET/src/dhcp6/tnet_dhcp6_option.c377
-rwxr-xr-xtinyNET/src/dhcp6/tnet_dhcp6_option.h209
8 files changed, 835 insertions, 870 deletions
diff --git a/tinyNET/src/dhcp6/tnet_dhcp6.c b/tinyNET/src/dhcp6/tnet_dhcp6.c
index 8e2fdb7..94bf8cc 100755
--- a/tinyNET/src/dhcp6/tnet_dhcp6.c
+++ b/tinyNET/src/dhcp6/tnet_dhcp6.c
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -43,145 +43,144 @@
tnet_dhcp6_ctx_t* tnet_dhcp6_ctx_create()
{
- return tsk_object_new(tnet_dhcp6_ctx_def_t);
+ return tsk_object_new(tnet_dhcp6_ctx_def_t);
}
/**@ingroup tnet_dhcp6_group
*/
tnet_dhcp6_reply_t* tnet_dhcp6_send_request(const tnet_dhcp6_ctx_t* ctx, tnet_dhcp6_request_t* request)
{
- tsk_buffer_t *output;
- tnet_dhcp6_reply_t* reply = 0;
- int ret;
- struct timeval tv;
- fd_set set;
- uint64_t timeout = 0;
- tsk_list_item_t *item;
- const tnet_interface_t *iface;
- tnet_ip_t bestsource;
-
- tnet_socket_t *localsocket6 = 0;
- struct sockaddr_storage server;
-
- if(!ctx || !request){
- goto bail;
- }
-
- if((ret = tnet_getbestsource(TNET_DHCP6_All_DHCP_Relay_Agents_and_Servers, ctx->server_port, tnet_socket_type_udp_ipv6, &bestsource))){
- TSK_DEBUG_WARN("Failed to get best source for [%s]:%u.", TNET_DHCP6_All_DHCP_Relay_Agents_and_Servers, ctx->server_port);
- //fe80::21b:63ff:fea9:c14e%4
- localsocket6 = tnet_socket_create(TNET_SOCKET_HOST_ANY, ctx->port_client, tnet_socket_type_udp_ipv6);
- }
- else{
- localsocket6 = tnet_socket_create(bestsource, ctx->port_client, tnet_socket_type_udp_ipv6);
- }
-
- /* Check local socket. */
- if(!TNET_SOCKET_IS_VALID(localsocket6)){
- TSK_DEBUG_ERROR("Failed to create/bind DHCPv6 client socket.");
- goto bail;
- }
-
- /* Always wait for 200ms before retransmission */
- tv.tv_sec = 0;
- tv.tv_usec = (200 * 1000);
-
- if(tnet_sockaddr_init(TNET_DHCP6_All_DHCP_Relay_Agents_and_Servers, ctx->server_port, tnet_socket_type_udp_ipv6, &server)){
- TNET_PRINT_LAST_ERROR("Failed to initialize the DHCPv6 server address.");
- goto bail;
- }
-
- /* Set timeout */
- timeout = tsk_time_epoch() + ctx->timeout;
-
- do
- {
- tsk_list_foreach(item, ctx->interfaces){
- iface = item->data;
-
- /* Set FD */
- FD_ZERO(&set);
- FD_SET(localsocket6->fd, &set);
-
- ///* ciaddr */
- //if(request->type == dhcp_type_inform){
- // struct sockaddr_storage ss;
- // if(!tnet_get_sockaddr(localsocket4->fd, &ss)){
- // uint32_t addr = tnet_htonl_2(&((struct sockaddr_in*)&ss)->sin_addr);
- // memcpy(&request->ciaddr, &addr, 4);
- // }
- //}
-
- ///* chaddr */
- //memset(request->chaddr, 0, sizeof(request->chaddr));
- //request->hlen = iface->mac_address_length > sizeof(request->chaddr) ? sizeof(request->chaddr) : iface->mac_address_length;
- //memcpy(request->chaddr, iface->mac_address, request->hlen);
-
- /* Serialize and send to the server. */
- if(!(output = tnet_dhcp6_message_serialize(ctx, request))){
- TSK_DEBUG_ERROR("Failed to serialize the DHCPv6 message.");
- goto next_iface;
- }
- /* Send the request to the DHCP server */
- if((ret =tnet_sockfd_sendto(localsocket6->fd, (const struct sockaddr*)&server, output->data, output->size))<0){
- TNET_PRINT_LAST_ERROR("Failed to send DHCPv6 request.");
-
- tsk_thread_sleep(150); // wait 150ms before trying the next iface.
- goto next_iface;
- }
- /* wait for response */
- if((ret = select(localsocket6->fd+1, &set, NULL, NULL, &tv))<0){ /* Error */
- TNET_PRINT_LAST_ERROR("select have failed.");
- tsk_thread_sleep(150); // wait 150ms before trying the next iface.
- goto next_iface;
- }
- else if(ret == 0){ /* timeout ==> do nothing */
- }
- else{ /* there is data to read. */
- unsigned int len = 0;
- void* data = 0;
-
- /* Check how how many bytes are pending */
- if((ret = tnet_ioctlt(localsocket6->fd, FIONREAD, &len))<0){
- goto next_iface;
- }
-
- /* Receive pending data */
- data = tsk_calloc(len, sizeof(uint8_t));
- if((ret = tnet_sockfd_recv(localsocket6->fd, data, len, 0))<0){
- TSK_FREE(data);
-
- TNET_PRINT_LAST_ERROR("Failed to receive DHCP dgrams.");
- goto next_iface;
- }
-
- /* Parse the incoming response. */
- reply = tnet_dhcp6_message_deserialize(ctx, data, (tsk_size_t)ret);
- TSK_FREE(data);
-
- if(reply)
- { /* response successfuly parsed */
- if(request->transaction_id != reply->transaction_id)
- { /* Not same transaction id ==> continue*/
- TSK_OBJECT_SAFE_FREE(reply);
- }
- }
- }
-
- next_iface:
- TSK_OBJECT_SAFE_FREE(output);
- if(reply){
- goto bail;
- }
- }
- break;//FIXME
- }
- while(timeout > tsk_time_epoch());
+ tsk_buffer_t *output;
+ tnet_dhcp6_reply_t* reply = 0;
+ int ret;
+ struct timeval tv;
+ fd_set set;
+ uint64_t timeout = 0;
+ tsk_list_item_t *item;
+ const tnet_interface_t *iface;
+ tnet_ip_t bestsource;
+
+ tnet_socket_t *localsocket6 = 0;
+ struct sockaddr_storage server;
+
+ if(!ctx || !request) {
+ goto bail;
+ }
+
+ if((ret = tnet_getbestsource(TNET_DHCP6_All_DHCP_Relay_Agents_and_Servers, ctx->server_port, tnet_socket_type_udp_ipv6, &bestsource))) {
+ TSK_DEBUG_WARN("Failed to get best source for [%s]:%u.", TNET_DHCP6_All_DHCP_Relay_Agents_and_Servers, ctx->server_port);
+ //fe80::21b:63ff:fea9:c14e%4
+ localsocket6 = tnet_socket_create(TNET_SOCKET_HOST_ANY, ctx->port_client, tnet_socket_type_udp_ipv6);
+ }
+ else {
+ localsocket6 = tnet_socket_create(bestsource, ctx->port_client, tnet_socket_type_udp_ipv6);
+ }
+
+ /* Check local socket. */
+ if(!TNET_SOCKET_IS_VALID(localsocket6)) {
+ TSK_DEBUG_ERROR("Failed to create/bind DHCPv6 client socket.");
+ goto bail;
+ }
+
+ /* Always wait for 200ms before retransmission */
+ tv.tv_sec = 0;
+ tv.tv_usec = (200 * 1000);
+
+ if(tnet_sockaddr_init(TNET_DHCP6_All_DHCP_Relay_Agents_and_Servers, ctx->server_port, tnet_socket_type_udp_ipv6, &server)) {
+ TNET_PRINT_LAST_ERROR("Failed to initialize the DHCPv6 server address.");
+ goto bail;
+ }
+
+ /* Set timeout */
+ timeout = tsk_time_epoch() + ctx->timeout;
+
+ do {
+ tsk_list_foreach(item, ctx->interfaces) {
+ iface = item->data;
+
+ /* Set FD */
+ FD_ZERO(&set);
+ FD_SET(localsocket6->fd, &set);
+
+ ///* ciaddr */
+ //if(request->type == dhcp_type_inform){
+ // struct sockaddr_storage ss;
+ // if(!tnet_get_sockaddr(localsocket4->fd, &ss)){
+ // uint32_t addr = tnet_htonl_2(&((struct sockaddr_in*)&ss)->sin_addr);
+ // memcpy(&request->ciaddr, &addr, 4);
+ // }
+ //}
+
+ ///* chaddr */
+ //memset(request->chaddr, 0, sizeof(request->chaddr));
+ //request->hlen = iface->mac_address_length > sizeof(request->chaddr) ? sizeof(request->chaddr) : iface->mac_address_length;
+ //memcpy(request->chaddr, iface->mac_address, request->hlen);
+
+ /* Serialize and send to the server. */
+ if(!(output = tnet_dhcp6_message_serialize(ctx, request))) {
+ TSK_DEBUG_ERROR("Failed to serialize the DHCPv6 message.");
+ goto next_iface;
+ }
+ /* Send the request to the DHCP server */
+ if((ret =tnet_sockfd_sendto(localsocket6->fd, (const struct sockaddr*)&server, output->data, output->size))<0) {
+ TNET_PRINT_LAST_ERROR("Failed to send DHCPv6 request.");
+
+ tsk_thread_sleep(150); // wait 150ms before trying the next iface.
+ goto next_iface;
+ }
+ /* wait for response */
+ if((ret = select(localsocket6->fd+1, &set, NULL, NULL, &tv))<0) { /* Error */
+ TNET_PRINT_LAST_ERROR("select have failed.");
+ tsk_thread_sleep(150); // wait 150ms before trying the next iface.
+ goto next_iface;
+ }
+ else if(ret == 0) { /* timeout ==> do nothing */
+ }
+ else { /* there is data to read. */
+ unsigned int len = 0;
+ void* data = 0;
+
+ /* Check how how many bytes are pending */
+ if((ret = tnet_ioctlt(localsocket6->fd, FIONREAD, &len))<0) {
+ goto next_iface;
+ }
+
+ /* Receive pending data */
+ data = tsk_calloc(len, sizeof(uint8_t));
+ if((ret = tnet_sockfd_recv(localsocket6->fd, data, len, 0))<0) {
+ TSK_FREE(data);
+
+ TNET_PRINT_LAST_ERROR("Failed to receive DHCP dgrams.");
+ goto next_iface;
+ }
+
+ /* Parse the incoming response. */
+ reply = tnet_dhcp6_message_deserialize(ctx, data, (tsk_size_t)ret);
+ TSK_FREE(data);
+
+ if(reply) {
+ /* response successfuly parsed */
+ if(request->transaction_id != reply->transaction_id) {
+ /* Not same transaction id ==> continue*/
+ TSK_OBJECT_SAFE_FREE(reply);
+ }
+ }
+ }
+
+next_iface:
+ TSK_OBJECT_SAFE_FREE(output);
+ if(reply) {
+ goto bail;
+ }
+ }
+ break;//FIXME
+ }
+ while(timeout > tsk_time_epoch());
bail:
- TSK_OBJECT_SAFE_FREE(localsocket6);
+ TSK_OBJECT_SAFE_FREE(localsocket6);
- return reply;
+ return reply;
}
@@ -193,28 +192,28 @@ bail:
*/
tnet_dhcp6_reply_t* tnet_dhcp6_requestinfo(const tnet_dhcp6_ctx_t* ctx, const tnet_dhcp6_option_orequest_t *orequest)
{
- tnet_dhcp6_reply_t* reply = 0;
- tnet_dhcp6_request_t* request = tnet_dhcp6_request_create(dhcp6_type_information_request);
- tnet_dhcp6_option_t* option = 0;
+ tnet_dhcp6_reply_t* reply = 0;
+ tnet_dhcp6_request_t* request = tnet_dhcp6_request_create(dhcp6_type_information_request);
+ tnet_dhcp6_option_t* option = 0;
- if(!ctx || !orequest || !request){
- goto bail;
- }
+ if(!ctx || !orequest || !request) {
+ goto bail;
+ }
- if((option = tnet_dhcp6_option_create(dhcp6_code_oro, orequest, sizeof(*orequest)))){
- tsk_list_push_back_data(request->options, (void**)&option);
- }
+ if((option = tnet_dhcp6_option_create(dhcp6_code_oro, orequest, sizeof(*orequest)))) {
+ tsk_list_push_back_data(request->options, (void**)&option);
+ }
- /* Vendor class */
- {
-
- }
+ /* Vendor class */
+ {
- reply = tnet_dhcp6_send_request(ctx, request);
+ }
+
+ reply = tnet_dhcp6_send_request(ctx, request);
bail:
- return reply;
+ return reply;
}
@@ -226,44 +225,43 @@ bail:
//
static tsk_object_t* tnet_dhcp6_ctx_ctor(tsk_object_t * self, va_list * app)
{
- tnet_dhcp6_ctx_t *ctx = self;
- if(ctx){
- ctx->pen = TNET_IANA_PEN;
- ctx->vendor_class_data = tsk_strdup(TNET_DHCP6_VENDOR_CLASS_DATA_DEFAULT);
-
- ctx->port_client = TNET_DHCP6_CLIENT_PORT;
- ctx->server_port = TNET_DHCP6_SERVER_PORT;
- ctx->interfaces = tnet_get_interfaces();
-
- ctx->timeout = 0xffff; /* FIXME */
-
- if(!ctx->interfaces || TSK_LIST_IS_EMPTY(ctx->interfaces)){
- TSK_DEBUG_ERROR("Failed to retrieve network interfaces.");
- }
-
- tsk_safeobj_init(ctx);
- }
- return self;
-}
+ tnet_dhcp6_ctx_t *ctx = self;
+ if(ctx) {
+ ctx->pen = TNET_IANA_PEN;
+ ctx->vendor_class_data = tsk_strdup(TNET_DHCP6_VENDOR_CLASS_DATA_DEFAULT);
+
+ ctx->port_client = TNET_DHCP6_CLIENT_PORT;
+ ctx->server_port = TNET_DHCP6_SERVER_PORT;
+ ctx->interfaces = tnet_get_interfaces();
-static tsk_object_t* tnet_dhcp6_ctx_dtor(tsk_object_t * self)
-{
- tnet_dhcp6_ctx_t *ctx = self;
- if(ctx){
- tsk_safeobj_deinit(ctx);
-
- TSK_FREE(ctx->vendor_class_data);
-
- TSK_OBJECT_SAFE_FREE(ctx->interfaces);
- }
- return self;
+ ctx->timeout = 0xffff; /* FIXME */
+
+ if(!ctx->interfaces || TSK_LIST_IS_EMPTY(ctx->interfaces)) {
+ TSK_DEBUG_ERROR("Failed to retrieve network interfaces.");
+ }
+
+ tsk_safeobj_init(ctx);
+ }
+ return self;
}
-static const tsk_object_def_t tnet_dhcp6_ctx_def_s =
+static tsk_object_t* tnet_dhcp6_ctx_dtor(tsk_object_t * self)
{
- sizeof(tnet_dhcp6_ctx_t),
- tnet_dhcp6_ctx_ctor,
- tnet_dhcp6_ctx_dtor,
- tsk_null,
+ tnet_dhcp6_ctx_t *ctx = self;
+ if(ctx) {
+ tsk_safeobj_deinit(ctx);
+
+ TSK_FREE(ctx->vendor_class_data);
+
+ TSK_OBJECT_SAFE_FREE(ctx->interfaces);
+ }
+ return self;
+}
+
+static const tsk_object_def_t tnet_dhcp6_ctx_def_s = {
+ sizeof(tnet_dhcp6_ctx_t),
+ tnet_dhcp6_ctx_ctor,
+ tnet_dhcp6_ctx_dtor,
+ tsk_null,
};
const tsk_object_def_t *tnet_dhcp6_ctx_def_t = &tnet_dhcp6_ctx_def_s;
diff --git a/tinyNET/src/dhcp6/tnet_dhcp6.h b/tinyNET/src/dhcp6/tnet_dhcp6.h
index 156f5a9..fa556f8 100755
--- a/tinyNET/src/dhcp6/tnet_dhcp6.h
+++ b/tinyNET/src/dhcp6/tnet_dhcp6.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -61,7 +61,7 @@ TNET_BEGIN_DECLS
#define TNET_DHCP6_All_DHCP_Servers "FF05::1:3"
/*== RFC 3315 - 5.5. Transmission and Retransmission Parameters
- * This section presents a table of values used to describe the message
+ * This section presents a table of values used to describe the message
* transmission behavior of clients and servers.
*/
#define TNET_DHCP6_RT_SOL_MAX_DELAY 1 /**< 1 sec Max delay of first Solicit */
@@ -100,20 +100,19 @@ TNET_BEGIN_DECLS
/**@ingroup tnet_dhcpv_group
* DHCPv6 context.
*/
-typedef struct tnet_dhcp6_ctx_s
-{
- TSK_DECLARE_OBJECT;
-
- uint16_t pen; /**< Private Enterprise Number assigned by the IANA. Default= @ref TNET_IANA_PEN.*/
- char* vendor_class_data;
-
- uint64_t timeout;
-
- tnet_port_t port_client; /**< Local port to bind to for incloming DHCPv6 messages. Default: 546 */
- tnet_port_t server_port; /**< Destination port for outgoing DHCPv6 messages. Default: 547 */
- tnet_interfaces_L_t *interfaces;
-
- TSK_DECLARE_SAFEOBJ;
+typedef struct tnet_dhcp6_ctx_s {
+ TSK_DECLARE_OBJECT;
+
+ uint16_t pen; /**< Private Enterprise Number assigned by the IANA. Default= @ref TNET_IANA_PEN.*/
+ char* vendor_class_data;
+
+ uint64_t timeout;
+
+ tnet_port_t port_client; /**< Local port to bind to for incloming DHCPv6 messages. Default: 546 */
+ tnet_port_t server_port; /**< Destination port for outgoing DHCPv6 messages. Default: 547 */
+ tnet_interfaces_L_t *interfaces;
+
+ TSK_DECLARE_SAFEOBJ;
}
tnet_dhcp6_ctx_t;
diff --git a/tinyNET/src/dhcp6/tnet_dhcp6_duid.c b/tinyNET/src/dhcp6/tnet_dhcp6_duid.c
index 38f2a52..3bec2f4 100755
--- a/tinyNET/src/dhcp6/tnet_dhcp6_duid.c
+++ b/tinyNET/src/dhcp6/tnet_dhcp6_duid.c
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -38,101 +38,97 @@ int tnet_dhcp6_duid_ll_serialize(const tnet_dhcp6_duid_ll_t* self, tsk_buffer_t
tnet_dhcp6_duid_llt_t* tnet_dhcp6_duid_llt_create(const void* payload, tsk_size_t payload_size)
{
- return tsk_object_new(tnet_dhcp6_duid_llt_def_t, payload, payload_size);
+ return tsk_object_new(tnet_dhcp6_duid_llt_def_t, payload, payload_size);
}
tnet_dhcp6_duid_en_t* tnet_dhcp6_duid_en_create(const void* payload, tsk_size_t payload_size)
{
- return tsk_object_new(tnet_dhcp6_duid_en_def_t, payload, payload_size);
+ return tsk_object_new(tnet_dhcp6_duid_en_def_t, payload, payload_size);
}
tnet_dhcp6_duid_ll_t* tnet_dhcp6_duid_ll_create(const void* payload, tsk_size_t payload_size)
{
- return tsk_object_new(tnet_dhcp6_duid_ll_def_t, payload, payload_size);
+ return tsk_object_new(tnet_dhcp6_duid_ll_def_t, payload, payload_size);
}
int tnet_dhcp6_duid_init(tnet_dhcp6_duid_t *self, tnet_dhcp6_duid_type_t type)
{
- if(self){
- if(!self->initialized){
- self->type = type;
- self->initialized = tsk_true;
- return 0;
- }
- return -2;
- }
- return -1;
+ if(self) {
+ if(!self->initialized) {
+ self->type = type;
+ self->initialized = tsk_true;
+ return 0;
+ }
+ return -2;
+ }
+ return -1;
}
int tnet_dhcp6_duid_deinit(tnet_dhcp6_duid_t *self)
{
- if(self){
- if(self->initialized){
- self->initialized = tsk_true;
- return 0;
- }
- return -2;
- }
- return -1;
+ if(self) {
+ if(self->initialized) {
+ self->initialized = tsk_true;
+ return 0;
+ }
+ return -2;
+ }
+ return -1;
}
tnet_dhcp6_duid_t* tnet_dhcp6_duid_deserialize(const void* data, tsk_size_t size)
{
- tnet_dhcp6_duid_t *duid = 0;
- uint8_t* dataPtr = ((uint8_t*)data);
- //uint8_t* dataEnd = (dataPtr+size);
+ tnet_dhcp6_duid_t *duid = 0;
+ uint8_t* dataPtr = ((uint8_t*)data);
+ //uint8_t* dataEnd = (dataPtr+size);
- tnet_dhcp6_duid_type_t type;
- //uint8_t len = 0;
+ tnet_dhcp6_duid_type_t type;
+ //uint8_t len = 0;
- /* Check validity */
- if(!dataPtr || size<2/*Type*/){
- goto bail;
- }
+ /* Check validity */
+ if(!dataPtr || size<2/*Type*/) {
+ goto bail;
+ }
- type = (tnet_dhcp6_duid_type_t) tnet_ntohs_2(dataPtr);
- dataPtr += 2;
+ type = (tnet_dhcp6_duid_type_t) tnet_ntohs_2(dataPtr);
+ dataPtr += 2;
bail:
- return duid;
+ return duid;
}
int tnet_dhcp6_duid_serialize(const tnet_dhcp6_duid_t* self, tsk_buffer_t *output)
{
- int ret = -1;
-
- if(!self || !output){
- return ret;
- }
-
- switch(self->type){
- case dhcp6_duid_linklayer_plus_time:
- {
- ret = tnet_dhcp6_duid_llt_serialize(TNET_DHCP6_DUID_LLT(self), output);
- break;
- }
-
- case dhcp6_duid_Vendor_assigned_id:
- {
- ret = tnet_dhcp6_duid_en_serialize(TNET_DHCP6_DUID_EN(self), output);
- break;
- }
-
- case dhcp6_duid_linklayer:
- {
- ret = tnet_dhcp6_duid_ll_serialize(TNET_DHCP6_DUID_LL(self), output);
- break;
- }
-
- default:
- {
- ret = -2;
- goto bail;
- }
- }
+ int ret = -1;
+
+ if(!self || !output) {
+ return ret;
+ }
+
+ switch(self->type) {
+ case dhcp6_duid_linklayer_plus_time: {
+ ret = tnet_dhcp6_duid_llt_serialize(TNET_DHCP6_DUID_LLT(self), output);
+ break;
+ }
+
+ case dhcp6_duid_Vendor_assigned_id: {
+ ret = tnet_dhcp6_duid_en_serialize(TNET_DHCP6_DUID_EN(self), output);
+ break;
+ }
+
+ case dhcp6_duid_linklayer: {
+ ret = tnet_dhcp6_duid_ll_serialize(TNET_DHCP6_DUID_LL(self), output);
+ break;
+ }
+
+ default: {
+ ret = -2;
+ goto bail;
+ }
+ }
bail:
- return ret;
+ return ret;
}
/*=======================================================================================
@@ -141,7 +137,7 @@ bail:
int tnet_dhcp6_duid_llt_serialize(const tnet_dhcp6_duid_llt_t* self, tsk_buffer_t *output)
{
- return -1;
+ return -1;
}
//
@@ -149,39 +145,38 @@ int tnet_dhcp6_duid_llt_serialize(const tnet_dhcp6_duid_llt_t* self, tsk_buffer_
//
static tsk_object_t* tnet_dhcp6_duid_llt_ctor(tsk_object_t * self, va_list * app)
{
- tnet_dhcp6_duid_llt_t *duid = self;
- if(duid){
- const void* payload = va_arg(*app, const void*);
- tsk_size_t payload_size = va_arg(*app, tsk_size_t);
-
- /* init base */
- tnet_dhcp6_duid_init(TNET_DHCP6_DUID(duid), dhcp6_duid_linklayer_plus_time);
-
- if(payload && payload_size){
- /* DESERIALIZATION */
- }
- }
- return self;
+ tnet_dhcp6_duid_llt_t *duid = self;
+ if(duid) {
+ const void* payload = va_arg(*app, const void*);
+ tsk_size_t payload_size = va_arg(*app, tsk_size_t);
+
+ /* init base */
+ tnet_dhcp6_duid_init(TNET_DHCP6_DUID(duid), dhcp6_duid_linklayer_plus_time);
+
+ if(payload && payload_size) {
+ /* DESERIALIZATION */
+ }
+ }
+ return self;
}
-static tsk_object_t* tnet_dhcp6_duid_llt_dtor(tsk_object_t * self)
-{
- tnet_dhcp6_duid_llt_t *duid = self;
- if(duid){
- /* deinit base */
- tnet_dhcp6_duid_deinit(TNET_DHCP6_DUID(duid));
-
- TSK_OBJECT_SAFE_FREE(duid->address);
- }
- return self;
+static tsk_object_t* tnet_dhcp6_duid_llt_dtor(tsk_object_t * self)
+{
+ tnet_dhcp6_duid_llt_t *duid = self;
+ if(duid) {
+ /* deinit base */
+ tnet_dhcp6_duid_deinit(TNET_DHCP6_DUID(duid));
+
+ TSK_OBJECT_SAFE_FREE(duid->address);
+ }
+ return self;
}
-static const tsk_object_def_t tnet_dhcp6_duid_llt_def_s =
-{
- sizeof(tnet_dhcp6_duid_llt_t),
- tnet_dhcp6_duid_llt_ctor,
- tnet_dhcp6_duid_llt_dtor,
- tsk_null,
+static const tsk_object_def_t tnet_dhcp6_duid_llt_def_s = {
+ sizeof(tnet_dhcp6_duid_llt_t),
+ tnet_dhcp6_duid_llt_ctor,
+ tnet_dhcp6_duid_llt_dtor,
+ tsk_null,
};
const tsk_object_def_t *tnet_dhcp6_duid_llt_def_t = &tnet_dhcp6_duid_llt_def_s;
@@ -192,7 +187,7 @@ const tsk_object_def_t *tnet_dhcp6_duid_llt_def_t = &tnet_dhcp6_duid_llt_def_s;
int tnet_dhcp6_duid_en_serialize(const tnet_dhcp6_duid_en_t* self, tsk_buffer_t *output)
{
- return -1;
+ return -1;
}
//
@@ -200,39 +195,38 @@ int tnet_dhcp6_duid_en_serialize(const tnet_dhcp6_duid_en_t* self, tsk_buffer_t
//
static tsk_object_t* tnet_dhcp6_duid_en_ctor(tsk_object_t * self, va_list * app)
{
- tnet_dhcp6_duid_en_t *duid = self;
- if(duid){
- const void* payload = va_arg(*app, const void*);
- tsk_size_t payload_size = va_arg(*app, tsk_size_t);
-
- /* init base */
- tnet_dhcp6_duid_init(TNET_DHCP6_DUID(duid), dhcp6_duid_Vendor_assigned_id);
-
- if(payload && payload_size){
- /* DESERIALIZATION */
- }
- }
- return self;
+ tnet_dhcp6_duid_en_t *duid = self;
+ if(duid) {
+ const void* payload = va_arg(*app, const void*);
+ tsk_size_t payload_size = va_arg(*app, tsk_size_t);
+
+ /* init base */
+ tnet_dhcp6_duid_init(TNET_DHCP6_DUID(duid), dhcp6_duid_Vendor_assigned_id);
+
+ if(payload && payload_size) {
+ /* DESERIALIZATION */
+ }
+ }
+ return self;
}
-static tsk_object_t* tnet_dhcp6_duid_en_dtor(tsk_object_t * self)
-{
- tnet_dhcp6_duid_en_t *duid = self;
- if(duid){
- /* deinit base */
- tnet_dhcp6_duid_deinit(TNET_DHCP6_DUID(duid));
-
- TSK_OBJECT_SAFE_FREE(duid->indentifier);
- }
- return self;
+static tsk_object_t* tnet_dhcp6_duid_en_dtor(tsk_object_t * self)
+{
+ tnet_dhcp6_duid_en_t *duid = self;
+ if(duid) {
+ /* deinit base */
+ tnet_dhcp6_duid_deinit(TNET_DHCP6_DUID(duid));
+
+ TSK_OBJECT_SAFE_FREE(duid->indentifier);
+ }
+ return self;
}
-static const tsk_object_def_t tnet_dhcp6_duid_en_def_s =
-{
- sizeof(tnet_dhcp6_duid_en_t),
- tnet_dhcp6_duid_en_ctor,
- tnet_dhcp6_duid_en_dtor,
- tsk_null,
+static const tsk_object_def_t tnet_dhcp6_duid_en_def_s = {
+ sizeof(tnet_dhcp6_duid_en_t),
+ tnet_dhcp6_duid_en_ctor,
+ tnet_dhcp6_duid_en_dtor,
+ tsk_null,
};
const tsk_object_def_t *tnet_dhcp6_duid_en_def_t = &tnet_dhcp6_duid_en_def_s;
@@ -243,7 +237,7 @@ const tsk_object_def_t *tnet_dhcp6_duid_en_def_t = &tnet_dhcp6_duid_en_def_s;
int tnet_dhcp6_duid_ll_serialize(const tnet_dhcp6_duid_ll_t* self, tsk_buffer_t *output)
{
- return -1;
+ return -1;
}
//
@@ -251,38 +245,37 @@ int tnet_dhcp6_duid_ll_serialize(const tnet_dhcp6_duid_ll_t* self, tsk_buffer_t
//
static tsk_object_t* tnet_dhcp6_duid_ll_ctor(tsk_object_t * self, va_list * app)
{
- tnet_dhcp6_duid_ll_t *duid = self;
- if(duid){
- const void* payload = va_arg(*app, const void*);
- tsk_size_t payload_size = va_arg(*app, tsk_size_t);
-
- /* init base */
- tnet_dhcp6_duid_init(TNET_DHCP6_DUID(duid), dhcp6_duid_linklayer);
-
- if(payload && payload_size){
- /* DESERIALIZATION */
- }
- }
- return self;
+ tnet_dhcp6_duid_ll_t *duid = self;
+ if(duid) {
+ const void* payload = va_arg(*app, const void*);
+ tsk_size_t payload_size = va_arg(*app, tsk_size_t);
+
+ /* init base */
+ tnet_dhcp6_duid_init(TNET_DHCP6_DUID(duid), dhcp6_duid_linklayer);
+
+ if(payload && payload_size) {
+ /* DESERIALIZATION */
+ }
+ }
+ return self;
}
-static tsk_object_t* tnet_dhcp6_duid_ll_dtor(tsk_object_t * self)
-{
- tnet_dhcp6_duid_ll_t *duid = self;
- if(duid){
- /* deinit base */
- tnet_dhcp6_duid_deinit(TNET_DHCP6_DUID(duid));
-
- TSK_OBJECT_SAFE_FREE(duid->address);
- }
- return self;
+static tsk_object_t* tnet_dhcp6_duid_ll_dtor(tsk_object_t * self)
+{
+ tnet_dhcp6_duid_ll_t *duid = self;
+ if(duid) {
+ /* deinit base */
+ tnet_dhcp6_duid_deinit(TNET_DHCP6_DUID(duid));
+
+ TSK_OBJECT_SAFE_FREE(duid->address);
+ }
+ return self;
}
-static const tsk_object_def_t tnet_dhcp6_duid_ll_def_s =
-{
- sizeof(tnet_dhcp6_duid_ll_t),
- tnet_dhcp6_duid_ll_ctor,
- tnet_dhcp6_duid_ll_dtor,
- tsk_null,
+static const tsk_object_def_t tnet_dhcp6_duid_ll_def_s = {
+ sizeof(tnet_dhcp6_duid_ll_t),
+ tnet_dhcp6_duid_ll_ctor,
+ tnet_dhcp6_duid_ll_dtor,
+ tsk_null,
};
const tsk_object_def_t *tnet_dhcp6_duid_ll_def_t = &tnet_dhcp6_duid_ll_def_s;
diff --git a/tinyNET/src/dhcp6/tnet_dhcp6_duid.h b/tinyNET/src/dhcp6/tnet_dhcp6_duid.h
index 34383fa..94c2b32 100755
--- a/tinyNET/src/dhcp6/tnet_dhcp6_duid.h
+++ b/tinyNET/src/dhcp6/tnet_dhcp6_duid.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -44,23 +44,21 @@ TNET_BEGIN_DECLS
/** List of DHCPv6 DUIDs types as per RFC 3315 subclause 9.1.
*/
-typedef enum tnet_dhcp6_duid_type_e
-{
- dhcp6_duid_linklayer_plus_time = 1, /**< Link-layer address plus time. */
- dhcp6_duid_Vendor_assigned_id = 2, /**< Vendor-assigned unique ID based on Enterprise Number. */
- dhcp6_duid_linklayer = 3, /**< Link-layer address. */
+typedef enum tnet_dhcp6_duid_type_e {
+ dhcp6_duid_linklayer_plus_time = 1, /**< Link-layer address plus time. */
+ dhcp6_duid_Vendor_assigned_id = 2, /**< Vendor-assigned unique ID based on Enterprise Number. */
+ dhcp6_duid_linklayer = 3, /**< Link-layer address. */
}
tnet_dhcp6_duid_type_t;
/** DHCP Unique Identifier (DUID) base class (subclause 9).
*/
-typedef struct tnet_dhcp6_duid_s
-{
- TSK_DECLARE_OBJECT;
-
- tsk_bool_t initialized;
+typedef struct tnet_dhcp6_duid_s {
+ TSK_DECLARE_OBJECT;
+
+ tsk_bool_t initialized;
- tnet_dhcp6_duid_type_t type; /* DUID type. 2-bytes value. */
+ tnet_dhcp6_duid_type_t type; /* DUID type. 2-bytes value. */
}
tnet_dhcp6_duid_t;
@@ -80,29 +78,28 @@ int tnet_dhcp6_duid_serialize(const tnet_dhcp6_duid_t* self, tsk_buffer_t *outpu
/** DUID Based on Link-layer Address Plus Time [DUID-LLT]
*/
-typedef struct tnet_dhcp6_duid_llt_s
-{
- TNET_DECLARE_DHCP6_DUID;
- /*
- 0 1 2 3
- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | 1 | hardware type (16 bits) |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | time (32 bits) |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- . .
- . link-layer address (variable length) .
- . .
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- */
- /* The hardware type code as maintained by IANA. */
- tnet_hardware_type_t htype;
- /* The time value is the time that the DUID is generated represented in seconds
- since midnight (UTC), January 1, 2000, modulo 2^32. */
- uint32_t time;
- /* The link-layer address. */
- tsk_buffer_t *address;
+typedef struct tnet_dhcp6_duid_llt_s {
+ TNET_DECLARE_DHCP6_DUID;
+ /*
+ 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | 1 | hardware type (16 bits) |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | time (32 bits) |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ . .
+ . link-layer address (variable length) .
+ . .
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+ /* The hardware type code as maintained by IANA. */
+ tnet_hardware_type_t htype;
+ /* The time value is the time that the DUID is generated represented in seconds
+ since midnight (UTC), January 1, 2000, modulo 2^32. */
+ uint32_t time;
+ /* The link-layer address. */
+ tsk_buffer_t *address;
}
tnet_dhcp6_duid_llt_t;
@@ -113,27 +110,26 @@ tnet_dhcp6_duid_llt_t;
/** DUID Assigned by Vendor Based on Enterprise Number [DUID-EN]
*/
-typedef struct tnet_dhcp6_duid_en_s
-{
- TNET_DECLARE_DHCP6_DUID;
- /*
- 0 1 2 3
- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | 2 | enterprise-number |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | enterprise-number (contd) | |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- . identifier .
- . (variable length) .
- . .
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- */
- /* Tthe vendor's registered Private Enterprise Number as maintained by IANA.
- For more information: http://www.iana.org/assignments/enterprise-numbers. */
- uint32_t en;
- /* The link-layer address. */
- tsk_buffer_t *indentifier;
+typedef struct tnet_dhcp6_duid_en_s {
+ TNET_DECLARE_DHCP6_DUID;
+ /*
+ 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | 2 | enterprise-number |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | enterprise-number (contd) | |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
+ . identifier .
+ . (variable length) .
+ . .
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+ /* Tthe vendor's registered Private Enterprise Number as maintained by IANA.
+ For more information: http://www.iana.org/assignments/enterprise-numbers. */
+ uint32_t en;
+ /* The link-layer address. */
+ tsk_buffer_t *indentifier;
}
tnet_dhcp6_duid_en_t;
@@ -143,11 +139,10 @@ tnet_dhcp6_duid_en_t;
/** DUID Based on Link-layer Address [DUID-LL]
*/
-typedef struct tnet_dhcp6_duid_ll_s
-{
- TNET_DECLARE_DHCP6_DUID;
- /*
- 0 1 2 3
+typedef struct tnet_dhcp6_duid_ll_s {
+ TNET_DECLARE_DHCP6_DUID;
+ /*
+ 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 3 | hardware type (16 bits) |
@@ -156,11 +151,11 @@ typedef struct tnet_dhcp6_duid_ll_s
. link-layer address (variable length) .
. .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- */
- /* The hardware type code as maintained by IANA. */
- tnet_hardware_type_t htype;
- /* The link-layer address. */
- tsk_buffer_t *address;
+ */
+ /* The hardware type code as maintained by IANA. */
+ tnet_hardware_type_t htype;
+ /* The link-layer address. */
+ tsk_buffer_t *address;
}
tnet_dhcp6_duid_ll_t;
diff --git a/tinyNET/src/dhcp6/tnet_dhcp6_message.c b/tinyNET/src/dhcp6/tnet_dhcp6_message.c
index 4691714..9979335 100755
--- a/tinyNET/src/dhcp6/tnet_dhcp6_message.c
+++ b/tinyNET/src/dhcp6/tnet_dhcp6_message.c
@@ -32,65 +32,64 @@
tnet_dhcp6_message_t* tnet_dhcp6_message_create(tnet_dhcp6_message_type_t type)
{
- return tsk_object_new(tnet_dhcp6_message_def_t, type);
+ return tsk_object_new(tnet_dhcp6_message_def_t, type);
}
tnet_dhcp6_request_t* tnet_dhcp6_request_create(tnet_dhcp6_message_type_t type)
{
- return tnet_dhcp6_message_create(type);
+ return tnet_dhcp6_message_create(type);
}
tsk_buffer_t* tnet_dhcp6_message_serialize(const tnet_dhcp6_ctx_t *ctx, const tnet_dhcp6_message_t *self)
{
- tsk_buffer_t* output = 0;
- //uint8_t _1byte;
- uint16_t _2bytes;
- uint32_t _4bytes;
-
- /* Check message validity */
- if (!self){
- goto bail;
- }
-
- output = tsk_buffer_create_null();
-
- /*== msg-type + transaction-id */
- _4bytes = (((uint32_t)(self->type)) << 24) | (self->transaction_id & 0xFFFFFF);
- _4bytes = tnet_ntohl(_4bytes);
- tsk_buffer_append(output, &(_4bytes), 4);
-
- /*== Vendor class
- */
- {
- _2bytes = tnet_htons(dhcp6_code_vendor_class);
- tsk_buffer_append(output, &(_2bytes), 2);
- _2bytes = tnet_htons((unsigned short)(4 + tsk_strlen(ctx->vendor_class_data)));
- tsk_buffer_append(output, &(_2bytes), 2);
- _4bytes = tnet_ntohl(ctx->pen);
- tsk_buffer_append(output, &(_4bytes), 4);
- tsk_buffer_append(output, ctx->vendor_class_data, tsk_strlen(ctx->vendor_class_data));
- }
-
- /*== DHCP Options
- */
- {
- tsk_list_item_t *item;
- tnet_dhcp6_option_t* option;
- tsk_list_foreach(item, self->options)
- {
- option = (tnet_dhcp6_option_t*)item->data;
- if (tnet_dhcp6_option_serialize(option, output)){
- TSK_DEBUG_WARN("Failed to serialize DHCPv6 OPTION (%u)", option->code);
- }
- }
- }
+ tsk_buffer_t* output = 0;
+ //uint8_t _1byte;
+ uint16_t _2bytes;
+ uint32_t _4bytes;
+
+ /* Check message validity */
+ if (!self) {
+ goto bail;
+ }
+
+ output = tsk_buffer_create_null();
+
+ /*== msg-type + transaction-id */
+ _4bytes = (((uint32_t)(self->type)) << 24) | (self->transaction_id & 0xFFFFFF);
+ _4bytes = tnet_ntohl(_4bytes);
+ tsk_buffer_append(output, &(_4bytes), 4);
+
+ /*== Vendor class
+ */
+ {
+ _2bytes = tnet_htons(dhcp6_code_vendor_class);
+ tsk_buffer_append(output, &(_2bytes), 2);
+ _2bytes = tnet_htons((unsigned short)(4 + tsk_strlen(ctx->vendor_class_data)));
+ tsk_buffer_append(output, &(_2bytes), 2);
+ _4bytes = tnet_ntohl(ctx->pen);
+ tsk_buffer_append(output, &(_4bytes), 4);
+ tsk_buffer_append(output, ctx->vendor_class_data, tsk_strlen(ctx->vendor_class_data));
+ }
+
+ /*== DHCP Options
+ */
+ {
+ tsk_list_item_t *item;
+ tnet_dhcp6_option_t* option;
+ tsk_list_foreach(item, self->options) {
+ option = (tnet_dhcp6_option_t*)item->data;
+ if (tnet_dhcp6_option_serialize(option, output)) {
+ TSK_DEBUG_WARN("Failed to serialize DHCPv6 OPTION (%u)", option->code);
+ }
+ }
+ }
bail:
- return output;
+ return output;
}
tnet_dhcp6_message_t* tnet_dhcp6_message_deserialize(const tnet_dhcp6_ctx_t *ctx, const uint8_t *data, tsk_size_t size)
{
- return 0;
+ return 0;
}
@@ -100,32 +99,31 @@ tnet_dhcp6_message_t* tnet_dhcp6_message_deserialize(const tnet_dhcp6_ctx_t *ctx
//
static tsk_object_t* tnet_dhcp6_message_ctor(tsk_object_t * self, va_list * app)
{
- tnet_dhcp6_message_t *message = self;
- if (message){
- static uint16_t __dhcp6message_unique_tid = 0;//(uint32_t)tsk_time_epoch();
-
- message->type = va_arg(*app, tnet_dhcp6_message_type_t);
- message->transaction_id = ++__dhcp6message_unique_tid;
- message->options = tsk_list_create();
- }
- return self;
+ tnet_dhcp6_message_t *message = self;
+ if (message) {
+ static uint16_t __dhcp6message_unique_tid = 0;//(uint32_t)tsk_time_epoch();
+
+ message->type = va_arg(*app, tnet_dhcp6_message_type_t);
+ message->transaction_id = ++__dhcp6message_unique_tid;
+ message->options = tsk_list_create();
+ }
+ return self;
}
static tsk_object_t* tnet_dhcp6_message_dtor(tsk_object_t * self)
{
- tnet_dhcp6_message_t *message = self;
- if (message){
- TSK_OBJECT_SAFE_FREE(message->options);
- }
- return self;
+ tnet_dhcp6_message_t *message = self;
+ if (message) {
+ TSK_OBJECT_SAFE_FREE(message->options);
+ }
+ return self;
}
-static const tsk_object_def_t tnet_dhcp6_message_def_s =
-{
- sizeof(tnet_dhcp6_message_t),
- tnet_dhcp6_message_ctor,
- tnet_dhcp6_message_dtor,
- tsk_null,
+static const tsk_object_def_t tnet_dhcp6_message_def_s = {
+ sizeof(tnet_dhcp6_message_t),
+ tnet_dhcp6_message_ctor,
+ tnet_dhcp6_message_dtor,
+ tsk_null,
};
const tsk_object_def_t *tnet_dhcp6_message_def_t = &tnet_dhcp6_message_def_s;
diff --git a/tinyNET/src/dhcp6/tnet_dhcp6_message.h b/tinyNET/src/dhcp6/tnet_dhcp6_message.h
index dc5d9d2..3dfd6c6 100755
--- a/tinyNET/src/dhcp6/tnet_dhcp6_message.h
+++ b/tinyNET/src/dhcp6/tnet_dhcp6_message.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -42,86 +42,84 @@ struct tnet_dhcp6_ctx_s;
/** List of all supported DHCPv6 messages.
* For more info: RFC 3315 - 5.3. DHCP Message Types
*/
-typedef enum tnet_dhcp6_message_type_e
-{
- /* A client sends a Solicit message to locate servers. */
- dhcp6_type_solicit = 1,
- /* A server sends an Advertise message to indicate that it is available for DHCP service, in
- response to a Solicit message received from a client. */
- dhcp6_type_advertise = 2,
- /* A client sends a Request message to request configuration parameters, including IP
- addresses, from a specific server. */
- dhcp6_type_request = 3,
- /* A client sends a Confirm message to any available server to determine whether the
- addresses it was assigned are still appropriate to the link to which the client is connected. */
- dhcp6_type_confirm = 4,
- /* A client sends a Renew message to the server that originally provided the client's addresses
- and configuration parameters to extend the lifetimes on the addresses assigned to the
- client and to update other configurationparameters. */
- dhcp6_type_renew = 5,
- /* A client sends a Rebind message to any available server to extend the lifetimes on the
- addresses assigned to the client and to update other configuration parameters; this message is
- sent after a client receives no response to a Renew message.*/
- dhcp6_type_rebind = 6,
- /* A server sends a Reply message containing assigned addresses and configuration parameters
- in response to a Solicit, Request, Renew, Rebind message received from a client. A
- server sends a Reply message containing configuration parameters in response to an
- Information-request message. A server sends a Reply message in response to a Confirm message
- confirming or denying that the addresses assigned to the client are appropriate to the
- link to which the client is connected. A server sends a Reply message to acknowledge
- receipt of a Release or Decline message.*/
- dhcp6_type_reply = 7,
- /* A client sends a Release message to the server that assigned addresses to the client to
- indicate that the client will no longer use one or more of the assigned addresses.*/
- dhcp6_type_release = 8,
- /* A client sends a Decline message to a server to indicate that the client has determined that
- one or more addresses assigned by the server are already in use on the link to which the
- client is connected.*/
- dhcp6_type_decline = 9,
- /*A server sends a Reconfigure message to a client to inform the client that the server has
- new or updated configuration parameters, and that the client is to initiate a Renew/Reply
- or Information-request/Reply transaction with the server in order to receive the updatedinformation. */
- dhcp6_type_reconfigure = 10,
- /* A client sends an Information-request message to a server to request configuration
- parameters without the assignment of any IP addresses to the client.*/
- dhcp6_type_information_request = 11,
- /* A relay agent sends a Relay-forward message to relay messages to servers, either directly
- or through another relay agent. The received message, either a client message or a
- Relay-forward message from another relay agent, is encapsulated in an option in the Relay-forward message.*/
- dhcp6_type_relay_forw = 12,
- /* A server sends a Relay-reply message to a relay agent containing a message that the relay
- agent delivers to a client. The Relay-reply message may be relayed by other relay agents
- for delivery to the destination relay agent.
- The server encapsulates the client message as an option in the Relay-reply message, which the
- relay agent extracts and relays to the client.*/
- dhcp6_type_relay_repl = 13,
+typedef enum tnet_dhcp6_message_type_e {
+ /* A client sends a Solicit message to locate servers. */
+ dhcp6_type_solicit = 1,
+ /* A server sends an Advertise message to indicate that it is available for DHCP service, in
+ response to a Solicit message received from a client. */
+ dhcp6_type_advertise = 2,
+ /* A client sends a Request message to request configuration parameters, including IP
+ addresses, from a specific server. */
+ dhcp6_type_request = 3,
+ /* A client sends a Confirm message to any available server to determine whether the
+ addresses it was assigned are still appropriate to the link to which the client is connected. */
+ dhcp6_type_confirm = 4,
+ /* A client sends a Renew message to the server that originally provided the client's addresses
+ and configuration parameters to extend the lifetimes on the addresses assigned to the
+ client and to update other configurationparameters. */
+ dhcp6_type_renew = 5,
+ /* A client sends a Rebind message to any available server to extend the lifetimes on the
+ addresses assigned to the client and to update other configuration parameters; this message is
+ sent after a client receives no response to a Renew message.*/
+ dhcp6_type_rebind = 6,
+ /* A server sends a Reply message containing assigned addresses and configuration parameters
+ in response to a Solicit, Request, Renew, Rebind message received from a client. A
+ server sends a Reply message containing configuration parameters in response to an
+ Information-request message. A server sends a Reply message in response to a Confirm message
+ confirming or denying that the addresses assigned to the client are appropriate to the
+ link to which the client is connected. A server sends a Reply message to acknowledge
+ receipt of a Release or Decline message.*/
+ dhcp6_type_reply = 7,
+ /* A client sends a Release message to the server that assigned addresses to the client to
+ indicate that the client will no longer use one or more of the assigned addresses.*/
+ dhcp6_type_release = 8,
+ /* A client sends a Decline message to a server to indicate that the client has determined that
+ one or more addresses assigned by the server are already in use on the link to which the
+ client is connected.*/
+ dhcp6_type_decline = 9,
+ /*A server sends a Reconfigure message to a client to inform the client that the server has
+ new or updated configuration parameters, and that the client is to initiate a Renew/Reply
+ or Information-request/Reply transaction with the server in order to receive the updatedinformation. */
+ dhcp6_type_reconfigure = 10,
+ /* A client sends an Information-request message to a server to request configuration
+ parameters without the assignment of any IP addresses to the client.*/
+ dhcp6_type_information_request = 11,
+ /* A relay agent sends a Relay-forward message to relay messages to servers, either directly
+ or through another relay agent. The received message, either a client message or a
+ Relay-forward message from another relay agent, is encapsulated in an option in the Relay-forward message.*/
+ dhcp6_type_relay_forw = 12,
+ /* A server sends a Relay-reply message to a relay agent containing a message that the relay
+ agent delivers to a client. The Relay-reply message may be relayed by other relay agents
+ for delivery to the destination relay agent.
+ The server encapsulates the client message as an option in the Relay-reply message, which the
+ relay agent extracts and relays to the client.*/
+ dhcp6_type_relay_repl = 13,
}
tnet_dhcp6_message_type_t;
/** DHCPv6 message (common fields) as per RFC 3315 subclause 6.
*/
-typedef struct tnet_dhcp6_message_s
-{
- TSK_DECLARE_OBJECT;
- /*
- 0 1 2 3
- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | msg-type | transaction-id |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | |
- . options .
- . (variable) .
- | |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- */
- /* Identifies the DHCP message type. 1-byte value. */
- tnet_dhcp6_message_type_t type;
- /* The transaction ID for this message exchange. 3-bytes value. */
- uint32_t transaction_id;
- /* Options carried in this message. */
- tnet_dhcp6_options_L_t *options;
+typedef struct tnet_dhcp6_message_s {
+ TSK_DECLARE_OBJECT;
+ /*
+ 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | msg-type | transaction-id |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | |
+ . options .
+ . (variable) .
+ | |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+ /* Identifies the DHCP message type. 1-byte value. */
+ tnet_dhcp6_message_type_t type;
+ /* The transaction ID for this message exchange. 3-bytes value. */
+ uint32_t transaction_id;
+ /* Options carried in this message. */
+ tnet_dhcp6_options_L_t *options;
}
tnet_dhcp6_message_t;
diff --git a/tinyNET/src/dhcp6/tnet_dhcp6_option.c b/tinyNET/src/dhcp6/tnet_dhcp6_option.c
index 91ec16a..58107c6 100755
--- a/tinyNET/src/dhcp6/tnet_dhcp6_option.c
+++ b/tinyNET/src/dhcp6/tnet_dhcp6_option.c
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -37,125 +37,120 @@
tnet_dhcp6_option_t* tnet_dhcp6_option_create(tnet_dhcp6_option_code_t code, const void* payload, tsk_size_t payload_size)
{
- return tsk_object_new(tnet_dhcp6_option_def_t, code, payload, payload_size);
+ return tsk_object_new(tnet_dhcp6_option_def_t, code, payload, payload_size);
}
tnet_dhcp6_option_identifier_t* tnet_dhcp6_option_indentifer_create(tnet_dhcp6_option_code_t code, const void* payload, tsk_size_t payload_size)
{
- return tsk_object_new(tnet_dhcp6_option_identifier_def_t, code, payload, payload_size);
+ return tsk_object_new(tnet_dhcp6_option_identifier_def_t, code, payload, payload_size);
}
tnet_dhcp6_option_identifier_t* tnet_dhcp6_option_clientid_create(const void* payload, tsk_size_t payload_size)
{
- return tnet_dhcp6_option_indentifer_create(dhcp6_code_clientid, payload, payload_size);
+ return tnet_dhcp6_option_indentifer_create(dhcp6_code_clientid, payload, payload_size);
}
tnet_dhcp6_option_identifier_t* tnet_dhcp6_option_serverid_create(const void* payload, tsk_size_t payload_size)
{
- return tnet_dhcp6_option_indentifer_create(dhcp6_code_serverid, payload, payload_size);
+ return tnet_dhcp6_option_indentifer_create(dhcp6_code_serverid, payload, payload_size);
}
tnet_dhcp6_option_orequest_t* tnet_dhcp6_option_orequest_create(const void* payload, tsk_size_t payload_size)
{
- return tsk_object_new(tnet_dhcp6_option_orequest_def_t, payload, payload_size);
+ return tsk_object_new(tnet_dhcp6_option_orequest_def_t, payload, payload_size);
}
tnet_dhcp6_option_orequest_t* tnet_dhcp6_option_orequest_create_null()
{
- return tnet_dhcp6_option_orequest_create(tsk_null, 0);
+ return tnet_dhcp6_option_orequest_create(tsk_null, 0);
}
tnet_dhcp6_option_vendorclass_t* tnet_dhcp6_option_vendorclass_create(const void* payload, tsk_size_t payload_size)
{
- return tsk_object_new(tnet_dhcp6_option_vendorclass_def_t, payload, payload_size);
+ return tsk_object_new(tnet_dhcp6_option_vendorclass_def_t, payload, payload_size);
}
tnet_dhcp6_option_vendorclass_t* tnet_dhcp6_option_vendorclass_create_null()
{
- return tnet_dhcp6_option_vendorclass_create(tsk_null, 0);
+ return tnet_dhcp6_option_vendorclass_create(tsk_null, 0);
}
tnet_dhcp6_option_t* tnet_dhcp6_option_deserialize(const void* data, tsk_size_t size)
{
- tnet_dhcp6_option_t *option = 0;
- uint8_t* dataPtr = ((uint8_t*)data);
- //uint8_t* dataEnd = (dataPtr+size);
-
- tnet_dhcp6_option_code_t code;
- uint16_t len;
-
- /* Check validity */
- if(!dataPtr || size<4/*Code Len*/){
- goto bail;
- }
-
- code = (tnet_dhcp6_option_code_t) tnet_ntohs_2(dataPtr);
- dataPtr += 2;
-
- len = tnet_ntohs_2(dataPtr);
- dataPtr += 2;
-
- switch(code){
- case dhcp6_code_clientid:
- case dhcp6_code_serverid:
- {
- break;
- }
-
- default:
- {
- break;
- }
- }
+ tnet_dhcp6_option_t *option = 0;
+ uint8_t* dataPtr = ((uint8_t*)data);
+ //uint8_t* dataEnd = (dataPtr+size);
+
+ tnet_dhcp6_option_code_t code;
+ uint16_t len;
+
+ /* Check validity */
+ if(!dataPtr || size<4/*Code Len*/) {
+ goto bail;
+ }
+
+ code = (tnet_dhcp6_option_code_t) tnet_ntohs_2(dataPtr);
+ dataPtr += 2;
+
+ len = tnet_ntohs_2(dataPtr);
+ dataPtr += 2;
+
+ switch(code) {
+ case dhcp6_code_clientid:
+ case dhcp6_code_serverid: {
+ break;
+ }
+
+ default: {
+ break;
+ }
+ }
bail:
- return option;
+ return option;
}
int tnet_dhcp6_option_serialize(const tnet_dhcp6_option_t* self, tsk_buffer_t *output)
{
- uint16_t _2bytes;
- int ret = -1;
-
- if(!self || !output){
- goto bail;
- }
-
- /*== Code */
- _2bytes = tnet_htons(self->code);
- tsk_buffer_append(output, &(_2bytes), 2);
-
- switch(self->code){
- case dhcp6_code_clientid:
- case dhcp6_code_serverid:
- {
- break;
- }
-
- case dhcp6_code_oro:
- default:
- {
- if(self->data)
- {
- const tnet_dhcp6_option_orequest_t* opt = (const tnet_dhcp6_option_orequest_t*)self->data;
- if(opt->codes){
- /* option-len */
- _2bytes = tnet_htons((unsigned short)opt->codes->size);
- tsk_buffer_append(output, &(_2bytes), 2);
- /* option-data */
- ret = tsk_buffer_append(output, opt->codes->data, opt->codes->size);
- }
-
- }
- break;
- }
- }
+ uint16_t _2bytes;
+ int ret = -1;
+
+ if(!self || !output) {
+ goto bail;
+ }
+
+ /*== Code */
+ _2bytes = tnet_htons(self->code);
+ tsk_buffer_append(output, &(_2bytes), 2);
+
+ switch(self->code) {
+ case dhcp6_code_clientid:
+ case dhcp6_code_serverid: {
+ break;
+ }
+
+ case dhcp6_code_oro:
+ default: {
+ if(self->data) {
+ const tnet_dhcp6_option_orequest_t* opt = (const tnet_dhcp6_option_orequest_t*)self->data;
+ if(opt->codes) {
+ /* option-len */
+ _2bytes = tnet_htons((unsigned short)opt->codes->size);
+ tsk_buffer_append(output, &(_2bytes), 2);
+ /* option-data */
+ ret = tsk_buffer_append(output, opt->codes->data, opt->codes->size);
+ }
+
+ }
+ break;
+ }
+ }
bail:
- return ret;
+ return ret;
}
int tnet_dhcp6_option_serializeex(tnet_dhcp6_option_code_t code, uint8_t length, const void* value, tsk_buffer_t *output)
{
- return -1;
+ return -1;
}
//
@@ -163,43 +158,42 @@ int tnet_dhcp6_option_serializeex(tnet_dhcp6_option_code_t code, uint8_t length,
//
static tsk_object_t* tnet_dhcp6_option_ctor(tsk_object_t * self, va_list * app)
{
- tnet_dhcp6_option_t *option = self;
- if(option){
- tnet_dhcp6_option_code_t code = va_arg(*app, tnet_dhcp6_option_code_t);
- const void* payload = va_arg(*app, const void*);
- tsk_size_t payload_size = va_arg(*app, tsk_size_t);
-
- option->code = code;
- if(payload && payload_size){
- if((option->data = (tnet_dhcp6_option_data_t*)tsk_calloc(payload_size, sizeof(uint8_t)))){
- memcpy(option->data, payload, payload_size);
- option->len = (uint16_t)payload_size;
- }
- }
- }
- return self;
+ tnet_dhcp6_option_t *option = self;
+ if(option) {
+ tnet_dhcp6_option_code_t code = va_arg(*app, tnet_dhcp6_option_code_t);
+ const void* payload = va_arg(*app, const void*);
+ tsk_size_t payload_size = va_arg(*app, tsk_size_t);
+
+ option->code = code;
+ if(payload && payload_size) {
+ if((option->data = (tnet_dhcp6_option_data_t*)tsk_calloc(payload_size, sizeof(uint8_t)))) {
+ memcpy(option->data, payload, payload_size);
+ option->len = (uint16_t)payload_size;
+ }
+ }
+ }
+ return self;
}
-static tsk_object_t* tnet_dhcp6_option_dtor(tsk_object_t * self)
-{
- tnet_dhcp6_option_t *option = self;
- if(option){
- TSK_OBJECT_SAFE_FREE(option->data);
- }
- return self;
+static tsk_object_t* tnet_dhcp6_option_dtor(tsk_object_t * self)
+{
+ tnet_dhcp6_option_t *option = self;
+ if(option) {
+ TSK_OBJECT_SAFE_FREE(option->data);
+ }
+ return self;
}
-static const tsk_object_def_t tnet_dhcp6_option_def_s =
-{
- sizeof(tnet_dhcp6_option_t),
- tnet_dhcp6_option_ctor,
- tnet_dhcp6_option_dtor,
- tsk_null,
+static const tsk_object_def_t tnet_dhcp6_option_def_s = {
+ sizeof(tnet_dhcp6_option_t),
+ tnet_dhcp6_option_ctor,
+ tnet_dhcp6_option_dtor,
+ tsk_null,
};
const tsk_object_def_t *tnet_dhcp6_option_def_t = &tnet_dhcp6_option_def_s;
/*======================================================================================
-* RFC 3315 -
+* RFC 3315 -
22.2. Client Identifier Option
22.3. Server Identifier Option
*=======================================================================================*/
@@ -208,34 +202,33 @@ const tsk_object_def_t *tnet_dhcp6_option_def_t = &tnet_dhcp6_option_def_s;
//
static tsk_object_t* tnet_dhcp6_option_identifier_ctor(tsk_object_t * self, va_list * app)
{
- tnet_dhcp6_option_identifier_t *option = self;
- if(option){
- //tnet_dhcp6_option_code_t code = va_arg(*app, tnet_dhcp6_option_code_t);
- const void* payload = va_arg(*app, const void*);
- tsk_size_t payload_size = va_arg(*app, tsk_size_t);
-
- if(payload && payload_size){
- /* DESERIALIZATION */
- }
- }
- return self;
+ tnet_dhcp6_option_identifier_t *option = self;
+ if(option) {
+ //tnet_dhcp6_option_code_t code = va_arg(*app, tnet_dhcp6_option_code_t);
+ const void* payload = va_arg(*app, const void*);
+ tsk_size_t payload_size = va_arg(*app, tsk_size_t);
+
+ if(payload && payload_size) {
+ /* DESERIALIZATION */
+ }
+ }
+ return self;
}
-static tsk_object_t* tnet_dhcp6_option_identifier_dtor(tsk_object_t * self)
-{
- tnet_dhcp6_option_identifier_t *option = self;
- if(option){
- TSK_OBJECT_SAFE_FREE(option->duid);
- }
- return self;
+static tsk_object_t* tnet_dhcp6_option_identifier_dtor(tsk_object_t * self)
+{
+ tnet_dhcp6_option_identifier_t *option = self;
+ if(option) {
+ TSK_OBJECT_SAFE_FREE(option->duid);
+ }
+ return self;
}
-static const tsk_object_def_t tnet_dhcp6_option_identifier_def_s =
-{
- sizeof(tnet_dhcp6_option_identifier_t),
- tnet_dhcp6_option_identifier_ctor,
- tnet_dhcp6_option_identifier_dtor,
- tsk_null,
+static const tsk_object_def_t tnet_dhcp6_option_identifier_def_s = {
+ sizeof(tnet_dhcp6_option_identifier_t),
+ tnet_dhcp6_option_identifier_ctor,
+ tnet_dhcp6_option_identifier_dtor,
+ tsk_null,
};
const tsk_object_def_t *tnet_dhcp6_option_identifier_def_t = &tnet_dhcp6_option_identifier_def_s;
@@ -245,20 +238,20 @@ const tsk_object_def_t *tnet_dhcp6_option_identifier_def_t = &tnet_dhcp6_option_
int tnet_dhcp6_option_orequest_add_code(tnet_dhcp6_option_orequest_t* self, uint16_t code)
{
- uint16_t _2bytes;
- int ret = -1;
- if(self){
- if(!self->codes){
- if(!(self->codes = tsk_buffer_create_null())){
- return -3;
- }
- }
- _2bytes = tnet_ntohs(code);
- if(!(ret = tsk_buffer_append(self->codes, &_2bytes, 2))){
- TNET_DHCP6_OPTION(self)->len += 2;
- }
- }
- return ret;
+ uint16_t _2bytes;
+ int ret = -1;
+ if(self) {
+ if(!self->codes) {
+ if(!(self->codes = tsk_buffer_create_null())) {
+ return -3;
+ }
+ }
+ _2bytes = tnet_ntohs(code);
+ if(!(ret = tsk_buffer_append(self->codes, &_2bytes, 2))) {
+ TNET_DHCP6_OPTION(self)->len += 2;
+ }
+ }
+ return ret;
}
//
@@ -266,33 +259,32 @@ int tnet_dhcp6_option_orequest_add_code(tnet_dhcp6_option_orequest_t* self, uint
//
static tsk_object_t* tnet_dhcp6_option_orequest_ctor(tsk_object_t * self, va_list * app)
{
- tnet_dhcp6_option_orequest_t *option = self;
- if(option){
- const void* payload = va_arg(*app, const void*);
- tsk_size_t payload_size = va_arg(*app, tsk_size_t);
-
- if(payload && payload_size)
- { /* DESERIALIZATION */
- }
- }
- return self;
+ tnet_dhcp6_option_orequest_t *option = self;
+ if(option) {
+ const void* payload = va_arg(*app, const void*);
+ tsk_size_t payload_size = va_arg(*app, tsk_size_t);
+
+ if(payload && payload_size) {
+ /* DESERIALIZATION */
+ }
+ }
+ return self;
}
-static tsk_object_t* tnet_dhcp6_option_orequest_dtor(tsk_object_t * self)
-{
- tnet_dhcp6_option_orequest_t *option = self;
- if(option){
- TSK_OBJECT_SAFE_FREE(option->codes);
- }
- return self;
+static tsk_object_t* tnet_dhcp6_option_orequest_dtor(tsk_object_t * self)
+{
+ tnet_dhcp6_option_orequest_t *option = self;
+ if(option) {
+ TSK_OBJECT_SAFE_FREE(option->codes);
+ }
+ return self;
}
-static const tsk_object_def_t tnet_dhcp6_option_orequest_def_s =
-{
- sizeof(tnet_dhcp6_option_orequest_t),
- tnet_dhcp6_option_orequest_ctor,
- tnet_dhcp6_option_orequest_dtor,
- tsk_null,
+static const tsk_object_def_t tnet_dhcp6_option_orequest_def_s = {
+ sizeof(tnet_dhcp6_option_orequest_t),
+ tnet_dhcp6_option_orequest_ctor,
+ tnet_dhcp6_option_orequest_dtor,
+ tsk_null,
};
const tsk_object_def_t *tnet_dhcp6_option_orequest_def_t = &tnet_dhcp6_option_orequest_def_s;
@@ -305,32 +297,31 @@ const tsk_object_def_t *tnet_dhcp6_option_orequest_def_t = &tnet_dhcp6_option_or
//
static tsk_object_t* tnet_dhcp6_option_vendorclass_ctor(tsk_object_t * self, va_list * app)
{
- tnet_dhcp6_option_vendorclass_t *option = self;
- if(option){
- const void* payload = va_arg(*app, const void*);
- tsk_size_t payload_size = va_arg(*app, tsk_size_t);
-
- if(payload && payload_size){
- /* DESERIALIZATION */
- }
- }
- return self;
+ tnet_dhcp6_option_vendorclass_t *option = self;
+ if(option) {
+ const void* payload = va_arg(*app, const void*);
+ tsk_size_t payload_size = va_arg(*app, tsk_size_t);
+
+ if(payload && payload_size) {
+ /* DESERIALIZATION */
+ }
+ }
+ return self;
}
-static tsk_object_t* tnet_dhcp6_option_vendorclass_dtor(tsk_object_t * self)
-{
- tnet_dhcp6_option_vendorclass_t *option = self;
- if(option){
- TSK_OBJECT_SAFE_FREE(option->vendor_class_data);
- }
- return self;
+static tsk_object_t* tnet_dhcp6_option_vendorclass_dtor(tsk_object_t * self)
+{
+ tnet_dhcp6_option_vendorclass_t *option = self;
+ if(option) {
+ TSK_OBJECT_SAFE_FREE(option->vendor_class_data);
+ }
+ return self;
}
-static const tsk_object_def_t tnet_dhcp6_option_vendorclass_def_s =
-{
- sizeof(tnet_dhcp6_option_vendorclass_t),
- tnet_dhcp6_option_vendorclass_ctor,
- tnet_dhcp6_option_vendorclass_dtor,
- tsk_null,
+static const tsk_object_def_t tnet_dhcp6_option_vendorclass_def_s = {
+ sizeof(tnet_dhcp6_option_vendorclass_t),
+ tnet_dhcp6_option_vendorclass_ctor,
+ tnet_dhcp6_option_vendorclass_dtor,
+ tsk_null,
};
const tsk_object_def_t *tnet_dhcp6_option_vendorclass_def_t = &tnet_dhcp6_option_vendorclass_def_s;
diff --git a/tinyNET/src/dhcp6/tnet_dhcp6_option.h b/tinyNET/src/dhcp6/tnet_dhcp6_option.h
index 71241b9..56ec83e 100755
--- a/tinyNET/src/dhcp6/tnet_dhcp6_option.h
+++ b/tinyNET/src/dhcp6/tnet_dhcp6_option.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -42,47 +42,45 @@ TNET_BEGIN_DECLS
#define TNET_DHCP6_OPTION(self) ((tnet_dhcp6_option_t*)(self))
/** List of DHCPv6 option as registered by IANA (RFC 3315 subcaluse 24.3)*/
-typedef enum tnet_dhcp6_option_code_e
-{
- dhcp6_code_clientid = 1, /**< Client Identifier Option. */
- dhcp6_code_serverid = 2, /**< Server Identifier Option. */
- dhcp6_code_ia_na = 3, /**< Identity Association for Non-temporary Addresses Option. */
- dhcp6_code_ia_ta = 4, /**< Identity Association for Temporary Addresses Option. */
- dhcp6_code_iaaddr = 5, /**< IA Address Option. */
- dhcp6_code_oro = 6, /**< Option Request Option. */
- dhcp6_code_preference = 7, /**< Preference Option. */
- dhcp6_code_elapsed_time = 8, /**< Elapsed Time Option. */
- dhcp6_code_relay_msg = 9, /**< Relay Message Option. */
- dhcp6_code_auth = 11, /**< Authentication Option. */
- dhcp6_code_unicast = 12, /**< Server Unicast Option. */
- dhcp6_code_status_code = 13, /**< Status Code Option. */
- dhcp6_code_rapid_commit = 14, /**< Rapid Commit Option. */
- dhcp6_code_user_class = 15, /**< User Class Option. */
- dhcp6_code_vendor_class = 16, /**< Vendor Class Option. */
- dhcp6_code_vendor_opts = 17, /**< Vendor-specific Information Option. */
- dhcp6_code_interface_id = 18, /**< Interface-Id Option. */
- dhcp6_code_reconf_msg = 19, /**< Reconfigure Message Option. */
- dhcp6_code_reconf_accept = 20, /**< Reconfigure Accept Option. */
+typedef enum tnet_dhcp6_option_code_e {
+ dhcp6_code_clientid = 1, /**< Client Identifier Option. */
+ dhcp6_code_serverid = 2, /**< Server Identifier Option. */
+ dhcp6_code_ia_na = 3, /**< Identity Association for Non-temporary Addresses Option. */
+ dhcp6_code_ia_ta = 4, /**< Identity Association for Temporary Addresses Option. */
+ dhcp6_code_iaaddr = 5, /**< IA Address Option. */
+ dhcp6_code_oro = 6, /**< Option Request Option. */
+ dhcp6_code_preference = 7, /**< Preference Option. */
+ dhcp6_code_elapsed_time = 8, /**< Elapsed Time Option. */
+ dhcp6_code_relay_msg = 9, /**< Relay Message Option. */
+ dhcp6_code_auth = 11, /**< Authentication Option. */
+ dhcp6_code_unicast = 12, /**< Server Unicast Option. */
+ dhcp6_code_status_code = 13, /**< Status Code Option. */
+ dhcp6_code_rapid_commit = 14, /**< Rapid Commit Option. */
+ dhcp6_code_user_class = 15, /**< User Class Option. */
+ dhcp6_code_vendor_class = 16, /**< Vendor Class Option. */
+ dhcp6_code_vendor_opts = 17, /**< Vendor-specific Information Option. */
+ dhcp6_code_interface_id = 18, /**< Interface-Id Option. */
+ dhcp6_code_reconf_msg = 19, /**< Reconfigure Message Option. */
+ dhcp6_code_reconf_accept = 20, /**< Reconfigure Accept Option. */
}
tnet_dhcp6_option_code_t;
/** List of DHCPv6 status codes as registered by IANA (RFC 3315 subclause 24.4) */
-typedef enum tnet_dhcp6_statuscode_e
-{
- /* Success */
- dhcp6_statuscode_Success = 0,
- /* Failure, reason unspecified; this status code is sent by either a client
- or a server to indicate a failure not explicitly specified in this document (RFC 3315). */
- dhcp6_statuscode_UnspecFail = 1,
- /* Server has no addresses available to assign to the IA(s). */
- dhcp6_statuscode_NoAddrsAvail = 2,
- /* Client record (binding) unavailable. */
- dhcp6_statuscode_NoBinding = 3,
- /* The prefix for the address is not appropriate for the link to which the client is attached. */
- dhcp6_statuscode_NotOnLink = 4,
- /* Sent by a server to a client to force the client to send messages to the server.
- using the All_DHCP_Relay_Agents_and_Servers address.*/
- dhcp6_statuscode_UseMulticast = 5
+typedef enum tnet_dhcp6_statuscode_e {
+ /* Success */
+ dhcp6_statuscode_Success = 0,
+ /* Failure, reason unspecified; this status code is sent by either a client
+ or a server to indicate a failure not explicitly specified in this document (RFC 3315). */
+ dhcp6_statuscode_UnspecFail = 1,
+ /* Server has no addresses available to assign to the IA(s). */
+ dhcp6_statuscode_NoAddrsAvail = 2,
+ /* Client record (binding) unavailable. */
+ dhcp6_statuscode_NoBinding = 3,
+ /* The prefix for the address is not appropriate for the link to which the client is attached. */
+ dhcp6_statuscode_NotOnLink = 4,
+ /* Sent by a server to a client to force the client to send messages to the server.
+ using the All_DHCP_Relay_Agents_and_Servers address.*/
+ dhcp6_statuscode_UseMulticast = 5
}
tnet_dhcp6_statuscode_t;
@@ -93,34 +91,32 @@ tnet_dhcp6_statuscode_t;
/**@ingroup tnet_dhcpv_group
* DHCPv6 option-data.
*/
-typedef struct tnet_dhcp6_option_data_s
-{
- TSK_DECLARE_OBJECT;
+typedef struct tnet_dhcp6_option_data_s {
+ TSK_DECLARE_OBJECT;
}
tnet_dhcp6_option_data_t;
#define TNET_DECLARE_DHCP6_OPTION_DATA tnet_dhcp6_option_data_t dhcp6_option_data
-typedef struct tnet_dhcp6_option_s
-{
- TSK_DECLARE_OBJECT;
-
- /* RFC 3315 - 22.1. Format of DHCP Options
- 0 1 2 3
- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | option-code(2) | option-len(2) |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | option-data |
- | (option-len octets) |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- */
-
- /* An unsigned integer identifying the specific option type carried in this option.*/
- tnet_dhcp6_option_code_t code;
- /* Option length. Same as tsk_strlen(data buffer)*/
- uint16_t len;
- /* opton-data */
- tnet_dhcp6_option_data_t *data;
+typedef struct tnet_dhcp6_option_s {
+ TSK_DECLARE_OBJECT;
+
+ /* RFC 3315 - 22.1. Format of DHCP Options
+ 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | option-code(2) | option-len(2) |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | option-data |
+ | (option-len octets) |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+
+ /* An unsigned integer identifying the specific option type carried in this option.*/
+ tnet_dhcp6_option_code_t code;
+ /* Option length. Same as tsk_strlen(data buffer)*/
+ uint16_t len;
+ /* opton-data */
+ tnet_dhcp6_option_data_t *data;
}
tnet_dhcp6_option_t;
@@ -136,29 +132,28 @@ int tnet_dhcp6_option_serializeex(tnet_dhcp6_option_code_t code, uint8_t length,
/*======================================================================================
-* RFC 3315 -
+* RFC 3315 -
22.2. Client Identifier Option
22.3. Server Identifier Option
*=======================================================================================*/
/** DHCPv6 Client /server Identifier Option (subclause 22.2 and 22.3).
*/
-typedef struct tnet_dhcp6_option_identifier_s
-{
- TNET_DECLARE_DHCP6_OPTION_DATA;
- /*
- 0 1 2 3
- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | OPTION_XXXXXXID | option-len |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- . .
- . DUID .
- . (variable length) .
- . .
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- OPTION_XXXXXXID = OPTION_CLIENTID or OPTION_SERVERID
- */
- tnet_dhcp6_duid_t *duid;
+typedef struct tnet_dhcp6_option_identifier_s {
+ TNET_DECLARE_DHCP6_OPTION_DATA;
+ /*
+ 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | OPTION_XXXXXXID | option-len |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ . .
+ . DUID .
+ . (variable length) .
+ . .
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ OPTION_XXXXXXID = OPTION_CLIENTID or OPTION_SERVERID
+ */
+ tnet_dhcp6_duid_t *duid;
}
tnet_dhcp6_option_identifier_t;
typedef tnet_dhcp6_option_identifier_t tnet_dhcp6_option_clientid_t;
@@ -175,21 +170,20 @@ typedef tnet_dhcp6_option_identifier_t tnet_dhcp6_option_serverid_t;
/** DHCPv6 Option Request Option (subclause 22.7).
*/
-typedef struct tnet_dhcp6_option_orequest_s
-{
- TNET_DECLARE_DHCP6_OPTION_DATA;
- /*
- 0 1 2 3
- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | OPTION_ORO | option-len |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | requested-option-code-1 | requested-option-code-2 |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | ... |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- */
- tsk_buffer_t* codes;
+typedef struct tnet_dhcp6_option_orequest_s {
+ TNET_DECLARE_DHCP6_OPTION_DATA;
+ /*
+ 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | OPTION_ORO | option-len |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | requested-option-code-1 | requested-option-code-2 |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | ... |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+ tsk_buffer_t* codes;
}
tnet_dhcp6_option_orequest_t;
@@ -201,11 +195,10 @@ TINYNET_API int tnet_dhcp6_option_orequest_add_code(tnet_dhcp6_option_orequest_t
/** DHCPv6 Vendor Class Option (subclause 22.16).
*/
-typedef struct tnet_dhcp6_option_vendorclass_s
-{
- TNET_DECLARE_DHCP6_OPTION_DATA;
- /*
- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+typedef struct tnet_dhcp6_option_vendorclass_s {
+ TNET_DECLARE_DHCP6_OPTION_DATA;
+ /*
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| OPTION_VENDOR_CLASS | option-len |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -215,14 +208,14 @@ typedef struct tnet_dhcp6_option_vendorclass_s
. vendor-class-data .
. . . . .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- */
- uint32_t enterprise_number;
- /*
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...-+-+-+-+-+-+-+
+ */
+ uint32_t enterprise_number;
+ /*
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...-+-+-+-+-+-+-+
| vendor-class-len | opaque-data |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...-+-+-+-+-+-+-+
- */
- tsk_buffer_t* vendor_class_data;
+ */
+ tsk_buffer_t* vendor_class_data;
}
tnet_dhcp6_option_vendorclass_t;
OpenPOWER on IntegriCloud