From 4e3fb1666d7fe5b0c2973b842d065c1c7f9b8fbe Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Wed, 17 May 2023 16:37:15 +0200 Subject: [PATCH] stun: clang-format for coherent indentation and coding style --- src/modules/stun/config.c | 12 +- src/modules/stun/config.h | 3 +- src/modules/stun/kam_stun.c | 595 ++++++++++++++++++------------------ src/modules/stun/kam_stun.h | 150 ++++----- src/modules/stun/stun_mod.c | 35 ++- 5 files changed, 401 insertions(+), 394 deletions(-) diff --git a/src/modules/stun/config.c b/src/modules/stun/config.c index 358e63a99c3..6f127e14b39 100644 --- a/src/modules/stun/config.c +++ b/src/modules/stun/config.c @@ -29,15 +29,13 @@ #include "config.h" struct cfg_group_stun default_stun_cfg = { - 0, /* Read only variable to mark if stun is enabled */ - }; + 0, /* Read only variable to mark if stun is enabled */ +}; void *stun_cfg = &default_stun_cfg; cfg_def_t stun_cfg_def[] = { - { "stun_enabled", CFG_VAR_INT | CFG_ATOMIC | CFG_READONLY, - 0, 0, 0, 0, - "If set to one (true) STUN is enabled." }, + {"stun_enabled", CFG_VAR_INT | CFG_ATOMIC | CFG_READONLY, 0, 0, 0, 0, + "If set to one (true) STUN is enabled."}, - {0, 0, 0, 0, 0, 0} -}; + {0, 0, 0, 0, 0, 0}}; diff --git a/src/modules/stun/config.h b/src/modules/stun/config.h index d7d715c1cac..5c976ce6a7c 100644 --- a/src/modules/stun/config.h +++ b/src/modules/stun/config.h @@ -31,7 +31,8 @@ #include "../../core/cfg/cfg.h" -struct cfg_group_stun { +struct cfg_group_stun +{ int stun_active; }; diff --git a/src/modules/stun/kam_stun.c b/src/modules/stun/kam_stun.c index 0ddbb00ed1c..09b71d0a3a8 100644 --- a/src/modules/stun/kam_stun.c +++ b/src/modules/stun/kam_stun.c @@ -39,34 +39,27 @@ * Declaration of functions * * **************************************************************************** */ -static int stun_parse_header(struct stun_msg* req, USHORT_T* error_code); -static int stun_parse_body( - struct stun_msg* req, - struct stun_unknown_att** unknown, - USHORT_T* error_code); -static void stun_delete_unknown_attrs(struct stun_unknown_att* unknown); -static struct stun_unknown_att* stun_alloc_unknown_attr(USHORT_T type); -static int stun_add_address_attr(struct stun_msg* res, - UINT_T af, - USHORT_T port, - UINT_T* ip_addr, - USHORT_T type, - int do_xor); -static int add_unknown_attr(struct stun_msg* res, struct stun_unknown_att* unknown); -static int add_error_code(struct stun_msg* res, USHORT_T error_code); -static int copy_str_to_buffer(struct stun_msg* res, const char* data, UINT_T pad); -static int reallock_buffer(struct stun_buffer* buffer, UINT_T len); -static int buf_copy(struct stun_buffer* msg, void* source, UINT_T len); -static void clean_memory(struct stun_msg* req, - struct stun_msg* res, struct stun_unknown_att* unknown); -static int stun_create_response( - struct stun_msg* req, - struct stun_msg* res, - struct receive_info* ri, - struct stun_unknown_att* unknown, - UINT_T error_code); -static int stun_add_common_text_attr(struct stun_msg* res, USHORT_T type, char* value, - USHORT_T pad); +static int stun_parse_header(struct stun_msg *req, USHORT_T *error_code); +static int stun_parse_body(struct stun_msg *req, + struct stun_unknown_att **unknown, USHORT_T *error_code); +static void stun_delete_unknown_attrs(struct stun_unknown_att *unknown); +static struct stun_unknown_att *stun_alloc_unknown_attr(USHORT_T type); +static int stun_add_address_attr(struct stun_msg *res, UINT_T af, USHORT_T port, + UINT_T *ip_addr, USHORT_T type, int do_xor); +static int add_unknown_attr( + struct stun_msg *res, struct stun_unknown_att *unknown); +static int add_error_code(struct stun_msg *res, USHORT_T error_code); +static int copy_str_to_buffer( + struct stun_msg *res, const char *data, UINT_T pad); +static int reallock_buffer(struct stun_buffer *buffer, UINT_T len); +static int buf_copy(struct stun_buffer *msg, void *source, UINT_T len); +static void clean_memory(struct stun_msg *req, struct stun_msg *res, + struct stun_unknown_att *unknown); +static int stun_create_response(struct stun_msg *req, struct stun_msg *res, + struct receive_info *ri, struct stun_unknown_att *unknown, + UINT_T error_code); +static int stun_add_common_text_attr( + struct stun_msg *res, USHORT_T type, char *value, USHORT_T pad); /* @@ -74,7 +67,7 @@ static int stun_add_common_text_attr(struct stun_msg* res, USHORT_T type, char* * Definition of functions * * **************************************************************************** */ - + /* * process_stun_msg(): * buf - incoming message @@ -90,57 +83,56 @@ static int stun_add_common_text_attr(struct stun_msg* res, USHORT_T type, char* * of memory * */ -int process_stun_msg(char* buf, unsigned len, struct receive_info* ri) +int process_stun_msg(char *buf, unsigned len, struct receive_info *ri) { - struct stun_msg msg_req; - struct stun_msg msg_res; - struct dest_info dst; - struct stun_unknown_att* unknown; - USHORT_T error_code; - + struct stun_msg msg_req; + struct stun_msg msg_res; + struct dest_info dst; + struct stun_unknown_att *unknown; + USHORT_T error_code; + memset(&msg_req, 0, sizeof(msg_req)); memset(&msg_res, 0, sizeof(msg_res)); - + msg_req.msg.buf.s = buf; - msg_req.msg.buf.len = len; + msg_req.msg.buf.len = len; unknown = NULL; error_code = RESPONSE_OK; - - if (stun_parse_header(&msg_req, &error_code) != 0) { + + if(stun_parse_header(&msg_req, &error_code) != 0) { goto error; } - - if (error_code == RESPONSE_OK) { - if (stun_parse_body(&msg_req, &unknown, &error_code) != 0) { + + if(error_code == RESPONSE_OK) { + if(stun_parse_body(&msg_req, &unknown, &error_code) != 0) { goto error; } } - - if (stun_create_response(&msg_req, &msg_res, ri, - unknown, error_code) != 0) { + + if(stun_create_response(&msg_req, &msg_res, ri, unknown, error_code) != 0) { goto error; } - + init_dst_from_rcv(&dst, ri); -#ifdef EXTRA_DEBUG +#ifdef EXTRA_DEBUG struct ip_addr ip; su2ip_addr(&ip, &dst.to); - LOG(L_DBG, "DEBUG: process_stun_msg: decoded request from (%s:%d)\n", ip_addr2a(&ip), - su_getport(&dst.to)); + LOG(L_DBG, "DEBUG: process_stun_msg: decoded request from (%s:%d)\n", + ip_addr2a(&ip), su_getport(&dst.to)); #endif - + /* send STUN response */ - if (msg_send(&dst, msg_res.msg.buf.s, msg_res.msg.buf.len) != 0) { + if(msg_send(&dst, msg_res.msg.buf.s, msg_res.msg.buf.len) != 0) { goto error; } - + #ifdef EXTRA_DEBUG LOG(L_DBG, "DEBUG: process_stun_msg: send response\n"); #endif clean_memory(&msg_req, &msg_res, unknown); return 0; - + error: #ifdef EXTRA_DEBUG LOG(L_DBG, "DEBUG: process_stun_msg: failed to decode request\n"); @@ -161,11 +153,11 @@ int process_stun_msg(char* buf, unsigned len, struct receive_info* ri) * of memory */ -static int stun_parse_header(struct stun_msg* req, USHORT_T* error_code) +static int stun_parse_header(struct stun_msg *req, USHORT_T *error_code) { - - if (sizeof(req->hdr) > req->msg.buf.len) { - if(req->msg.buf.len==4 && *((int*)req->msg.buf.s)==0) { + + if(sizeof(req->hdr) > req->msg.buf.len) { + if(req->msg.buf.len == 4 && *((int *)req->msg.buf.s) == 0) { /* likely the UDP ping 0000 */ return FATAL_ERROR; } @@ -176,20 +168,22 @@ static int stun_parse_header(struct stun_msg* req, USHORT_T* error_code) */ return FATAL_ERROR; } - + memcpy(&req->hdr, req->msg.buf.s, sizeof(struct stun_hdr)); req->hdr.type = ntohs(req->hdr.type); - - /* the SER supports only Binding Request right now */ - if (req->hdr.type != BINDING_REQUEST) { - LOG(L_INFO, "INFO: stun_parse_header: unsupported type of STUN message: %x\n", - req->hdr.type); + + /* the SER supports only Binding Request right now */ + if(req->hdr.type != BINDING_REQUEST) { + LOG(L_INFO, + "INFO: stun_parse_header: unsupported type of STUN message: " + "%x\n", + req->hdr.type); /* resending of same message is not welcome */ *error_code = GLOBAL_FAILURE_ERR; } - + req->hdr.len = ntohs(req->hdr.len); - + /* check if there is correct magic cookie */ req->old = (req->hdr.id.magic_cookie == htonl(MAGIC_COOKIE)) ? 0 : 1; @@ -210,66 +204,66 @@ static int stun_parse_header(struct stun_msg* req, USHORT_T* error_code) * -1 if there is some environment error such as insufficiency * of memory */ -static int stun_parse_body( - struct stun_msg* req, - struct stun_unknown_att** unknown, - USHORT_T* error_code) +static int stun_parse_body(struct stun_msg *req, + struct stun_unknown_att **unknown, USHORT_T *error_code) { int not_parsed; struct stun_attr attr; USHORT_T attr_size; UINT_T padded_len; - struct stun_unknown_att* tmp_unknown; - struct stun_unknown_att* body; - char* buf; - + struct stun_unknown_att *tmp_unknown; + struct stun_unknown_att *body; + char *buf; + attr_size = sizeof(struct stun_attr); buf = &req->msg.buf.s[sizeof(struct stun_hdr)]; - + /* * Mark the body length as unparsed. */ not_parsed = req->msg.buf.len - sizeof(struct stun_hdr); - - if (not_parsed != req->hdr.len) { + + if(not_parsed != req->hdr.len) { #ifdef EXTRA_DEBUG LOG(L_DBG, "DEBUG: stun_parse_body: body too short to be valid\n"); #endif *error_code = BAD_REQUEST_ERR; - return 0; + return 0; } - + tmp_unknown = *unknown; body = NULL; - - while (not_parsed > 0 && *error_code == RESPONSE_OK) { + + while(not_parsed > 0 && *error_code == RESPONSE_OK) { memset(&attr, 0, attr_size); - + /* check if there are 4 bytes for attribute type and its value */ - if (not_parsed < 4) { + if(not_parsed < 4) { #ifdef EXTRA_DEBUG - LOG(L_DBG, "DEBUG: stun_parse_body: attribute header short to be valid\n"); + LOG(L_DBG, "DEBUG: stun_parse_body: attribute header short to be " + "valid\n"); #endif *error_code = BAD_REQUEST_ERR; continue; } - + memcpy(&attr, buf, attr_size); - + buf += attr_size; not_parsed -= attr_size; - + /* check if there is enought unparsed space for attribute's value */ - if (not_parsed < ntohs(attr.len)) { + if(not_parsed < ntohs(attr.len)) { #ifdef EXTRA_DEBUG - LOG(L_DBG, "DEBUG: stun_parse_body: remaining message is shorter than attribute length\n"); + LOG(L_DBG, "DEBUG: stun_parse_body: remaining message is shorter " + "than attribute length\n"); #endif *error_code = BAD_REQUEST_ERR; continue; } - + /* check if the attribute is known to the server */ - switch (ntohs(attr.type)) { + switch(ntohs(attr.type)) { case REALM_ATTR: case NONCE_ATTR: case MAPPED_ADDRESS_ATTR: @@ -277,7 +271,7 @@ static int stun_parse_body( case ALTERNATE_SERVER_ATTR: case RESPONSE_ADDRESS_ATTR: case SOURCE_ADDRESS_ATTR: - case REFLECTED_FROM_ATTR: + case REFLECTED_FROM_ATTR: case CHANGE_REQUEST_ATTR: case CHANGED_ADDRESS_ATTR: padded_len = ntohs(attr.len); @@ -285,7 +279,7 @@ static int stun_parse_body( LOG(L_DBG, "DEBUG: stun_parse_body: known attributes\n"); #endif break; - + /* following attributes must be padded to 4 bytes */ case USERNAME_ATTR: case ERROR_CODE_ATTR: @@ -300,48 +294,56 @@ static int stun_parse_body( /* MESSAGE_INTEGRITY must be padded to sixty four bytes*/ case MESSAGE_INTEGRITY_ATTR: #ifdef EXTRA_DEBUG - LOG(L_DBG, "DEBUG: stun_parse_body: message integrity attribute found\n"); + LOG(L_DBG, "DEBUG: stun_parse_body: message integrity " + "attribute found\n"); #endif padded_len = PADDED_TO_SIXTYFOUR(ntohs(attr.len)); break; - + case FINGERPRINT_ATTR: #ifdef EXTRA_DEBUG - LOG(L_DBG, "DEBUG: stun_parse_body: fingerprint attribute found\n"); + LOG(L_DBG, "DEBUG: stun_parse_body: fingerprint attribute " + "found\n"); #endif padded_len = SHA_DIGEST_LENGTH; - if (not_parsed > SHA_DIGEST_LENGTH) { + if(not_parsed > SHA_DIGEST_LENGTH) { #ifdef EXTRA_DEBUG - LOG(L_DBG, "DEBUG: stun_parse_body: fingerprint is not the last attribute\n"); + LOG(L_DBG, "DEBUG: stun_parse_body: fingerprint is not the " + "last attribute\n"); #endif /* fingerprint must be last parameter in request */ *error_code = BAD_REQUEST_ERR; continue; } break; - + default: /* * the attribute is uknnown to the server * let see if it's necessary to generate error response */ #ifdef EXTRA_DEBUG - LOG(L_DBG, "DEBUG: low endian: attr - 0x%x const - 0x%x\n", ntohs(attr.type), MANDATORY_ATTR); - LOG(L_DBG, "DEBUG: big endian: attr - 0x%x const - 0x%x\n", attr.type, htons(MANDATORY_ATTR)); + LOG(L_DBG, "DEBUG: low endian: attr - 0x%x const - 0x%x\n", + ntohs(attr.type), MANDATORY_ATTR); + LOG(L_DBG, "DEBUG: big endian: attr - 0x%x const - 0x%x\n", + attr.type, htons(MANDATORY_ATTR)); #endif - if (ntohs(attr.type) <= MANDATORY_ATTR) { + if(ntohs(attr.type) <= MANDATORY_ATTR) { #ifdef EXTRA_DEBUG - LOG(L_DBG, "DEBUG: stun_parse_body: mandatory unknown attribute found - 0x%x\n", ntohs(attr.type)); -#endif + LOG(L_DBG, + "DEBUG: stun_parse_body: mandatory unknown " + "attribute found - 0x%x\n", + ntohs(attr.type)); +#endif tmp_unknown = stun_alloc_unknown_attr(attr.type); - if (tmp_unknown == NULL) { + if(tmp_unknown == NULL) { return FATAL_ERROR; } - if (*unknown == NULL) { + if(*unknown == NULL) { *unknown = body = tmp_unknown; } else { - if(body==NULL) { + if(body == NULL) { body = *unknown; } body->next = tmp_unknown; @@ -349,32 +351,35 @@ static int stun_parse_body( } } #ifdef EXTRA_DEBUG - else { - LOG(L_DBG, "DEBUG: stun_parse_body: optional unknown attribute found - 0x%x\n", ntohs(attr.type)); - } + else { + LOG(L_DBG, + "DEBUG: stun_parse_body: optional unknown " + "attribute found - 0x%x\n", + ntohs(attr.type)); + } #endif padded_len = ntohs(attr.len); break; } - + /* check if there is enough unparsed space for the padded attribute (the padded length might be greater than the attribute length) */ - if (not_parsed < padded_len) { + if(not_parsed < padded_len) { break; } buf += padded_len; not_parsed -= padded_len; - } /* while */ - + } /* while */ + /* * The unknown attribute error code must set after parsing of whole body * because it's necessary to obtain all of unknown attributes! */ - if (*error_code == RESPONSE_OK && *unknown != NULL) { + if(*error_code == RESPONSE_OK && *unknown != NULL) { *error_code = UNKNOWN_ATTRIBUTE_ERR; - } - + } + return 0; } @@ -395,41 +400,38 @@ static int stun_parse_body( * of memory */ -static int stun_create_response( - struct stun_msg* req, - struct stun_msg* res, - struct receive_info* ri, - struct stun_unknown_att* unknown, - UINT_T error_code) +static int stun_create_response(struct stun_msg *req, struct stun_msg *res, + struct receive_info *ri, struct stun_unknown_att *unknown, + UINT_T error_code) { /* * Alloc some space for response. * Optimalization? - maybe it would be better to use biggish static array. */ - res->msg.buf.s = (char *) pkg_malloc(sizeof(char)*STUN_MSG_LEN); - if (res->msg.buf.s == NULL) { + res->msg.buf.s = (char *)pkg_malloc(sizeof(char) * STUN_MSG_LEN); + if(res->msg.buf.s == NULL) { PKG_MEM_ERROR; return FATAL_ERROR; } - - memset(res->msg.buf.s, 0, sizeof(char)*STUN_MSG_LEN); + + memset(res->msg.buf.s, 0, sizeof(char) * STUN_MSG_LEN); res->msg.buf.len = 0; res->msg.empty = STUN_MSG_LEN; - + /* use magic cookie and transaction ID from request */ memcpy(&res->hdr.id, &req->hdr.id, sizeof(struct transaction_id)); - /* the correct body length will be added ASAP it will be known */ + /* the correct body length will be added ASAP it will be known */ res->hdr.len = htons(0); - - if (error_code == RESPONSE_OK) { + + if(error_code == RESPONSE_OK) { #ifdef EXTRA_DEBUG LOG(L_DBG, "DEBUG: stun_create_response: creating normal response\n"); #endif res->hdr.type = htons(BINDING_RESPONSE); - + /* copy header into msg buffer */ - if (buf_copy(&res->msg, (void *) &res->hdr, - sizeof(struct stun_hdr)) != 0) { + if(buf_copy(&res->msg, (void *)&res->hdr, sizeof(struct stun_hdr)) + != 0) { #ifdef EXTRA_DEBUG LOG(L_DBG, "DEBUG: stun_create_response: failed to copy buffer\n"); #endif @@ -440,75 +442,80 @@ static int stun_create_response( * If the SER received message in old format, then the body will * contain MAPPED-ADDRESS attribute instead of XOR-MAPPED-ADDRESS * attribute. - */ - if (req->old == 0) { - if (stun_add_address_attr(res, ri->src_ip.af, ri->src_port, - ri->src_ip.u.addr32, XOR_MAPPED_ADDRESS_ATTR, - XOR) != 0) { + */ + if(req->old == 0) { + if(stun_add_address_attr(res, ri->src_ip.af, ri->src_port, + ri->src_ip.u.addr32, XOR_MAPPED_ADDRESS_ATTR, XOR) + != 0) { #ifdef EXTRA_DEBUG - LOG(L_DBG, "DEBUG: stun_create_response: failed to add address\n"); + LOG(L_DBG, + "DEBUG: stun_create_response: failed to add address\n"); #endif return FATAL_ERROR; } - } - else { - if (stun_add_address_attr(res, ri->src_ip.af, ri->src_port, - ri->src_ip.u.addr32, MAPPED_ADDRESS_ATTR, !XOR) != 0) { + } else { + if(stun_add_address_attr(res, ri->src_ip.af, ri->src_port, + ri->src_ip.u.addr32, MAPPED_ADDRESS_ATTR, !XOR) + != 0) { #ifdef EXTRA_DEBUG - LOG(L_DBG, "DEBUG: stun_create_response: failed to add address\n"); + LOG(L_DBG, + "DEBUG: stun_create_response: failed to add address\n"); #endif return FATAL_ERROR; } } - } - else { + } else { #ifdef EXTRA_DEBUG LOG(L_DBG, "DEBUG: stun_create_response: creating error response\n"); #endif res->hdr.type = htons(BINDING_ERROR_RESPONSE); - - if (buf_copy(&res->msg, (void *) &res->hdr, - sizeof(struct stun_hdr)) != 0) { + + if(buf_copy(&res->msg, (void *)&res->hdr, sizeof(struct stun_hdr)) + != 0) { #ifdef EXTRA_DEBUG LOG(L_DBG, "DEBUG: stun_create_response: failed to copy buffer\n"); #endif return FATAL_ERROR; } - - if (add_error_code(res, error_code) != 0) { + + if(add_error_code(res, error_code) != 0) { #ifdef EXTRA_DEBUG - LOG(L_DBG, "DEBUG: stun_create_response: failed to add error code\n"); + LOG(L_DBG, + "DEBUG: stun_create_response: failed to add error code\n"); #endif return FATAL_ERROR; } - - if (unknown != NULL) { - if (add_unknown_attr(res, unknown) != 0) { + + if(unknown != NULL) { + if(add_unknown_attr(res, unknown) != 0) { #ifdef EXTRA_DEBUG - LOG(L_DBG, "DEBUG: stun_create_response: failed to add unknown attribute\n"); + LOG(L_DBG, "DEBUG: stun_create_response: failed to add unknown " + "attribute\n"); #endif return FATAL_ERROR; } - } + } } - - if (req->old == 0) { + + if(req->old == 0) { /* * add optional information about server; attribute SOFTWARE is part of * rfc5389.txt * */ - if (stun_add_common_text_attr(res, SOFTWARE_ATTR, SERVER_HDR, PAD4)!=0) { + if(stun_add_common_text_attr(res, SOFTWARE_ATTR, SERVER_HDR, PAD4) + != 0) { #ifdef EXTRA_DEBUG - LOG(L_DBG, "DEBUG: stun_create_response: failed to add common text attribute\n"); + LOG(L_DBG, "DEBUG: stun_create_response: failed to add common text " + "attribute\n"); #endif return FATAL_ERROR; } - } - + } + res->hdr.len = htons(res->msg.buf.len - sizeof(struct stun_hdr)); - memcpy(&res->msg.buf.s[sizeof(USHORT_T)], (void *) &res->hdr.len, - sizeof(USHORT_T)); - + memcpy(&res->msg.buf.s[sizeof(USHORT_T)], (void *)&res->hdr.len, + sizeof(USHORT_T)); + return 0; } @@ -525,54 +532,56 @@ static int stun_create_response( * of memory * */ -static int add_unknown_attr(struct stun_msg* res, struct stun_unknown_att* unknown) +static int add_unknown_attr( + struct stun_msg *res, struct stun_unknown_att *unknown) { struct stun_attr attr; - struct stun_unknown_att* tmp_unknown; - UINT_T counter; - USHORT_T orig_len; + struct stun_unknown_att *tmp_unknown; + UINT_T counter; + USHORT_T orig_len; counter = 0; orig_len = res->msg.buf.len; tmp_unknown = unknown; - + attr.type = htons(UNKNOWN_ATTRIBUTES_ATTR); attr.len = htons(0); - - if (buf_copy(&res->msg, (void *) &attr, sizeof(struct stun_attr)) != 0) { + + if(buf_copy(&res->msg, (void *)&attr, sizeof(struct stun_attr)) != 0) { #ifdef EXTRA_DEBUG LOG(L_DBG, "DEBUG: add_unknown_attr: failed to copy buffer\n"); #endif return FATAL_ERROR; } - - while (tmp_unknown != NULL) { - if (buf_copy(&res->msg, (void *)&tmp_unknown->type, - sizeof(USHORT_T)) != 0) { + + while(tmp_unknown != NULL) { + if(buf_copy(&res->msg, (void *)&tmp_unknown->type, sizeof(USHORT_T)) + != 0) { #ifdef EXTRA_DEBUG - LOG(L_DBG, "DEBUG: add_unknown_attr: failed to copy unknown attribute\n"); + LOG(L_DBG, "DEBUG: add_unknown_attr: failed to copy unknown " + "attribute\n"); #endif return FATAL_ERROR; } tmp_unknown = tmp_unknown->next; ++counter; } - + attr.len = htons(res->msg.buf.len - orig_len); memcpy(&res->msg.buf.s[orig_len], (void *)&attr, sizeof(struct stun_attr)); - + /* check if there is an odd number of unknown attributes and if yes, * repeat one of them because of padding to 32 */ - if (counter/2 != 0 && unknown != NULL) { - if (buf_copy(&res->msg, (void *)&unknown->type, sizeof(USHORT_T))!=0) { + if(counter / 2 != 0 && unknown != NULL) { + if(buf_copy(&res->msg, (void *)&unknown->type, sizeof(USHORT_T)) != 0) { #ifdef EXTRA_DEBUG LOG(L_DBG, "DEBUG: add_unknown_attr: failed to padd\n"); #endif return FATAL_ERROR; } - } - + } + return 0; } @@ -588,20 +597,20 @@ static int add_unknown_attr(struct stun_msg* res, struct stun_unknown_att* unkno * -1 if there is some environment error such as insufficiency * of memory */ -static int add_error_code(struct stun_msg* res, USHORT_T error_code) +static int add_error_code(struct stun_msg *res, USHORT_T error_code) { struct stun_attr attr; - USHORT_T orig_len; - USHORT_T two_bytes; - int text_pad; - char err[2]; - + USHORT_T orig_len; + USHORT_T two_bytes; + int text_pad; + char err[2]; + orig_len = res->msg.buf.len; text_pad = 0; - + /* the type and length will be copied as last one because of unknown length*/ - if (res->msg.buf.len < sizeof(struct stun_attr)) { - if (reallock_buffer(&res->msg, sizeof(struct stun_attr)) != 0) { + if(res->msg.buf.len < sizeof(struct stun_attr)) { + if(reallock_buffer(&res->msg, sizeof(struct stun_attr)) != 0) { #ifdef EXTRA_DEBUG LOG(L_DBG, "DEBUG: add_error_code: failed to reallocate buffer\n"); #endif @@ -610,71 +619,71 @@ static int add_error_code(struct stun_msg* res, USHORT_T error_code) } res->msg.buf.len += sizeof(struct stun_attr); res->msg.empty -= sizeof(struct stun_attr); - + /* first two bytes are empty */ two_bytes = 0x0000; - - if (buf_copy(&res->msg, (void *) &two_bytes, sizeof(USHORT_T)) != 0) { + + if(buf_copy(&res->msg, (void *)&two_bytes, sizeof(USHORT_T)) != 0) { #ifdef EXTRA_DEBUG LOG(L_DBG, "DEBUG: add_error_code: failed to copy buffer\n"); #endif return FATAL_ERROR; } - + err[0] = error_code / 100; err[1] = error_code % 100; - if (buf_copy(&res->msg, (void *) err, sizeof(UCHAR_T)*2) != 0) { + if(buf_copy(&res->msg, (void *)err, sizeof(UCHAR_T) * 2) != 0) { return FATAL_ERROR; } - - switch (error_code) { + + switch(error_code) { case TRY_ALTERNATE_ERR: - text_pad = copy_str_to_buffer(res, TRY_ALTERNATE_TXT, PAD4); + text_pad = copy_str_to_buffer(res, TRY_ALTERNATE_TXT, PAD4); break; case BAD_REQUEST_ERR: - text_pad = copy_str_to_buffer(res, BAD_REQUEST_TXT, PAD4); + text_pad = copy_str_to_buffer(res, BAD_REQUEST_TXT, PAD4); break; case UNAUTHORIZED_ERR: - text_pad = copy_str_to_buffer(res, UNAUTHORIZED_TXT, PAD4); + text_pad = copy_str_to_buffer(res, UNAUTHORIZED_TXT, PAD4); break; case UNKNOWN_ATTRIBUTE_ERR: text_pad = copy_str_to_buffer(res, UNKNOWN_ATTRIBUTE_TXT, PAD4); break; case STALE_CREDENTIALS_ERR: - text_pad = copy_str_to_buffer(res, STALE_CREDENTIALS_TXT, PAD4); + text_pad = copy_str_to_buffer(res, STALE_CREDENTIALS_TXT, PAD4); break; case INTEGRITY_CHECK_ERR: - text_pad = copy_str_to_buffer(res, INTEGRITY_CHECK_TXT, PAD4); + text_pad = copy_str_to_buffer(res, INTEGRITY_CHECK_TXT, PAD4); break; case MISSING_USERNAME_ERR: - text_pad = copy_str_to_buffer(res, MISSING_USERNAME_TXT, PAD4); + text_pad = copy_str_to_buffer(res, MISSING_USERNAME_TXT, PAD4); break; case USE_TLS_ERR: - text_pad = copy_str_to_buffer(res, USE_TLS_TXT, PAD4); + text_pad = copy_str_to_buffer(res, USE_TLS_TXT, PAD4); break; case MISSING_REALM_ERR: - text_pad = copy_str_to_buffer(res, MISSING_REALM_TXT, PAD4); + text_pad = copy_str_to_buffer(res, MISSING_REALM_TXT, PAD4); break; case MISSING_NONCE_ERR: - text_pad = copy_str_to_buffer(res, MISSING_NONCE_TXT, PAD4); + text_pad = copy_str_to_buffer(res, MISSING_NONCE_TXT, PAD4); break; case UNKNOWN_USERNAME_ERR: - text_pad = copy_str_to_buffer(res, UNKNOWN_USERNAME_TXT, PAD4); + text_pad = copy_str_to_buffer(res, UNKNOWN_USERNAME_TXT, PAD4); break; case STALE_NONCE_ERR: text_pad = copy_str_to_buffer(res, STALE_NONCE_TXT, PAD4); break; case SERVER_ERROR_ERR: - text_pad = copy_str_to_buffer(res, SERVER_ERROR_TXT, PAD4); + text_pad = copy_str_to_buffer(res, SERVER_ERROR_TXT, PAD4); break; case GLOBAL_FAILURE_ERR: - text_pad = copy_str_to_buffer(res, GLOBAL_FAILURE_TXT, PAD4); + text_pad = copy_str_to_buffer(res, GLOBAL_FAILURE_TXT, PAD4); break; default: LOG(L_ERR, "ERROR: STUN: Unknown error code.\n"); break; } - if (text_pad < 0) { + if(text_pad < 0) { #ifdef EXTRA_DEBUG LOG(L_DBG, "DEBUG: add_error_code: text_pad is negative\n"); #endif @@ -682,10 +691,10 @@ static int add_error_code(struct stun_msg* res, USHORT_T error_code) } attr.type = htons(ERROR_CODE_ATTR); /* count length of "value" field -> without type and lehgth field */ - attr.len = htons(res->msg.buf.len - orig_len - - text_pad - sizeof(struct stun_attr)); + attr.len = htons( + res->msg.buf.len - orig_len - text_pad - sizeof(struct stun_attr)); memcpy(&res->msg.buf.s[orig_len], (void *)&attr, sizeof(struct stun_attr)); - + return 0; error: @@ -706,34 +715,35 @@ static int add_error_code(struct stun_msg* res, USHORT_T error_code) * -1 if there is some environment error such as insufficiency * of memory */ -static int copy_str_to_buffer(struct stun_msg* res, const char* data, UINT_T pad) +static int copy_str_to_buffer( + struct stun_msg *res, const char *data, UINT_T pad) { - USHORT_T pad_len; - UINT_T data_len; - UCHAR_T empty[pad]; - + USHORT_T pad_len; + UINT_T data_len; + UCHAR_T empty[pad]; + data_len = strlen(data); memset(&empty, 0, pad); - - pad_len = (pad - data_len%pad) % pad; - - if (buf_copy(&res->msg, (void *) data, sizeof(UCHAR_T)*data_len) != 0) { + + pad_len = (pad - data_len % pad) % pad; + + if(buf_copy(&res->msg, (void *)data, sizeof(UCHAR_T) * data_len) != 0) { #ifdef EXTRA_DEBUG LOG(L_DBG, "DEBUG: copy_str_to_buffer: failed to copy buffer\n"); #endif return FATAL_ERROR; } - - if (pad_len != 0) { - if (buf_copy(&res->msg, &empty, pad_len) != 0) { + + if(pad_len != 0) { + if(buf_copy(&res->msg, &empty, pad_len) != 0) { #ifdef EXTRA_DEBUG LOG(L_DBG, "DEBUG: copy_str_to_buffer: failed to pad\n"); #endif return FATAL_ERROR; - } + } } - return pad_len; + return pad_len; } /* @@ -753,52 +763,49 @@ static int copy_str_to_buffer(struct stun_msg* res, const char* data, UINT_T pad * -1 if there is some environment error such as insufficiency * of memory */ -static int stun_add_address_attr(struct stun_msg* res, - UINT_T af, - USHORT_T port, - UINT_T* ip_addr, - USHORT_T type, - int do_xor) +static int stun_add_address_attr(struct stun_msg *res, UINT_T af, USHORT_T port, + UINT_T *ip_addr, USHORT_T type, int do_xor) { struct stun_attr attr; - int ip_struct_len; - UINT_T id[IP_ADDR]; + int ip_struct_len; + UINT_T id[IP_ADDR]; int i; - + ip_struct_len = 0; attr.type = htons(type); res->ip_addr.port = htons((do_xor) ? (port ^ MAGIC_COOKIE_2B) : port); switch(af) { case AF_INET: - ip_struct_len = sizeof(struct stun_ip_addr) - 3*sizeof(UINT_T); + ip_struct_len = sizeof(struct stun_ip_addr) - 3 * sizeof(UINT_T); res->ip_addr.family = htons(IPV4_FAMILY); memcpy(res->ip_addr.ip, ip_addr, IPV4_LEN); - res->ip_addr.ip[0] = (do_xor) ? - res->ip_addr.ip[0] ^ htonl(MAGIC_COOKIE) : res->ip_addr.ip[0]; + res->ip_addr.ip[0] = + (do_xor) ? res->ip_addr.ip[0] ^ htonl(MAGIC_COOKIE) + : res->ip_addr.ip[0]; break; case AF_INET6: ip_struct_len = sizeof(struct stun_ip_addr); res->ip_addr.family = htons(IPV6_FAMILY); memcpy(&res->ip_addr.ip, ip_addr, IPV6_LEN); memcpy(id, &res->hdr.id, sizeof(struct transaction_id)); - for (i=0; iip_addr.ip[i] = (do_xor) ? - res->ip_addr.ip[i] ^ id[i] : res->ip_addr.ip[i]; + for(i = 0; i < IP_ADDR; i++) { + res->ip_addr.ip[i] = (do_xor) ? res->ip_addr.ip[i] ^ id[i] + : res->ip_addr.ip[i]; } break; default: break; } - + attr.len = htons(ip_struct_len); - - /* copy type and attribute's length */ - if (buf_copy(&res->msg, (void *) &attr, sizeof(struct stun_attr)) != 0) { + + /* copy type and attribute's length */ + if(buf_copy(&res->msg, (void *)&attr, sizeof(struct stun_attr)) != 0) { return FATAL_ERROR; } - + /* copy family, port and IP */ - if (buf_copy(&res->msg, (void *) &res->ip_addr, ip_struct_len) != 0) { + if(buf_copy(&res->msg, (void *)&res->ip_addr, ip_struct_len) != 0) { return FATAL_ERROR; } @@ -816,19 +823,20 @@ static int stun_add_address_attr(struct stun_msg* res, * NULL if there is some environment error such as insufficiency * of memory */ -static struct stun_unknown_att* stun_alloc_unknown_attr(USHORT_T type) +static struct stun_unknown_att *stun_alloc_unknown_attr(USHORT_T type) { - struct stun_unknown_att* attr; + struct stun_unknown_att *attr; - attr = (struct stun_unknown_att *) pkg_malloc(sizeof(struct stun_unknown_att)); - if (attr == NULL) { + attr = (struct stun_unknown_att *)pkg_malloc( + sizeof(struct stun_unknown_att)); + if(attr == NULL) { PKG_MEM_ERROR; return NULL; } - + attr->type = type; attr->next = NULL; - + return attr; } @@ -840,18 +848,18 @@ static struct stun_unknown_att* stun_alloc_unknown_attr(USHORT_T type) * * Return value: none */ -static void stun_delete_unknown_attrs(struct stun_unknown_att* unknown) +static void stun_delete_unknown_attrs(struct stun_unknown_att *unknown) { - struct stun_unknown_att* tmp_unknown; - - if (unknown == NULL) { + struct stun_unknown_att *tmp_unknown; + + if(unknown == NULL) { return; } - + while(unknown->next) { tmp_unknown = unknown->next; unknown->next = tmp_unknown->next; - pkg_free(tmp_unknown); + pkg_free(tmp_unknown); } pkg_free(unknown); } @@ -868,18 +876,18 @@ static void stun_delete_unknown_attrs(struct stun_unknown_att* unknown) * -1 if there is some environment error such as insufficiency * of memory */ -static int buf_copy(struct stun_buffer* msg, void* source, UINT_T len) +static int buf_copy(struct stun_buffer *msg, void *source, UINT_T len) { - if (msg->empty < len) { - if (reallock_buffer(msg, len) != 0) { + if(msg->empty < len) { + if(reallock_buffer(msg, len) != 0) { return FATAL_ERROR; } } - + memcpy(&msg->buf.s[msg->buf.len], source, len); msg->buf.len += len; msg->empty -= len; - + return 0; } @@ -896,20 +904,20 @@ static int buf_copy(struct stun_buffer* msg, void* source, UINT_T len) * -1 if there is some environment error such as insufficiency * of memory */ -static int reallock_buffer(struct stun_buffer* buffer, UINT_T len) +static int reallock_buffer(struct stun_buffer *buffer, UINT_T len) { - char* tmp_buf; - UINT_T new_len; - - new_len = (STUN_MSG_LEN < len) ? STUN_MSG_LEN+len : STUN_MSG_LEN; - - tmp_buf = (char *) pkg_realloc(buffer->buf.s, - buffer->buf.len + buffer->empty + new_len); - if (tmp_buf == 0) { + char *tmp_buf; + UINT_T new_len; + + new_len = (STUN_MSG_LEN < len) ? STUN_MSG_LEN + len : STUN_MSG_LEN; + + tmp_buf = (char *)pkg_realloc( + buffer->buf.s, buffer->buf.len + buffer->empty + new_len); + if(tmp_buf == 0) { LOG(L_ERR, "ERROR: STUN: out of memory\n"); return FATAL_ERROR; } - + buffer->buf.s = tmp_buf; buffer->empty += new_len; @@ -925,10 +933,10 @@ static int reallock_buffer(struct stun_buffer* buffer, UINT_T len) * * Return value: none */ -static void clean_memory(struct stun_msg* req, - struct stun_msg* res, struct stun_unknown_att* unknown) +static void clean_memory(struct stun_msg *req, struct stun_msg *res, + struct stun_unknown_att *unknown) { - if (res->msg.buf.s != NULL) { + if(res->msg.buf.s != NULL) { pkg_free(res->msg.buf.s); } stun_delete_unknown_attrs(unknown); @@ -948,29 +956,26 @@ static void clean_memory(struct stun_msg* req, * -1 if there is some environment error such as insufficiency * of memory */ -static int stun_add_common_text_attr(struct stun_msg* res, - USHORT_T type, - char* value, - USHORT_T pad) +static int stun_add_common_text_attr( + struct stun_msg *res, USHORT_T type, char *value, USHORT_T pad) { struct stun_attr attr; - - if (value == NULL) { + + if(value == NULL) { LOG(L_INFO, "INFO: stun_add_common_text_attr: value is NULL\n"); return 0; } - + attr.type = htons(type); attr.len = htons(strlen(value)); - - if (buf_copy(&res->msg, (void *) &attr, sizeof(struct stun_attr)) != 0) { + + if(buf_copy(&res->msg, (void *)&attr, sizeof(struct stun_attr)) != 0) { return FATAL_ERROR; } - - if (copy_str_to_buffer(res, value, pad) < 0) { + + if(copy_str_to_buffer(res, value, pad) < 0) { return FATAL_ERROR; } - + return 0; - } diff --git a/src/modules/stun/kam_stun.h b/src/modules/stun/kam_stun.h index 3d113bb365d..e03ffb51426 100644 --- a/src/modules/stun/kam_stun.h +++ b/src/modules/stun/kam_stun.h @@ -35,116 +35,120 @@ #include "../../core/stun.h" /* STUN message types supported by Kamailio */ -#define BINDING_REQUEST 0x0001 -#define BINDING_RESPONSE 0x0101 -#define BINDING_ERROR_RESPONSE 0x0111 +#define BINDING_REQUEST 0x0001 +#define BINDING_RESPONSE 0x0101 +#define BINDING_ERROR_RESPONSE 0x0111 /* common STUN attributes */ -#define MAPPED_ADDRESS_ATTR 0x0001 -#define USERNAME_ATTR 0x0006 -#define MESSAGE_INTEGRITY_ATTR 0x0008 -#define ERROR_CODE_ATTR 0x0009 -#define UNKNOWN_ATTRIBUTES_ATTR 0x000A +#define MAPPED_ADDRESS_ATTR 0x0001 +#define USERNAME_ATTR 0x0006 +#define MESSAGE_INTEGRITY_ATTR 0x0008 +#define ERROR_CODE_ATTR 0x0009 +#define UNKNOWN_ATTRIBUTES_ATTR 0x000A /* STUN attributes defined by rfc5389 */ -#define REALM_ATTR 0x0014 -#define NONCE_ATTR 0x0015 -#define XOR_MAPPED_ADDRESS_ATTR 0x0020 -#define FINGERPRINT_ATTR 0x8028 -#define SOFTWARE_ATTR 0x8022 -#define ALTERNATE_SERVER_ATTR 0x8023 +#define REALM_ATTR 0x0014 +#define NONCE_ATTR 0x0015 +#define XOR_MAPPED_ADDRESS_ATTR 0x0020 +#define FINGERPRINT_ATTR 0x8028 +#define SOFTWARE_ATTR 0x8022 +#define ALTERNATE_SERVER_ATTR 0x8023 /* STUN attributes defined by rfc3489 */ -#define RESPONSE_ADDRESS_ATTR 0x0002 -#define CHANGE_REQUEST_ATTR 0x0003 -#define SOURCE_ADDRESS_ATTR 0x0004 -#define CHANGED_ADDRESS_ATTR 0x0005 -#define REFLECTED_FROM_ATTR 0x000b +#define RESPONSE_ADDRESS_ATTR 0x0002 +#define CHANGE_REQUEST_ATTR 0x0003 +#define SOURCE_ADDRESS_ATTR 0x0004 +#define CHANGED_ADDRESS_ATTR 0x0005 +#define REFLECTED_FROM_ATTR 0x000b /* STUN error codes supported by Kamailio */ -#define RESPONSE_OK 200 -#define TRY_ALTERNATE_ERR 300 -#define BAD_REQUEST_ERR 400 -#define UNAUTHORIZED_ERR 401 -#define UNKNOWN_ATTRIBUTE_ERR 420 -#define STALE_CREDENTIALS_ERR 430 -#define INTEGRITY_CHECK_ERR 431 -#define MISSING_USERNAME_ERR 432 -#define USE_TLS_ERR 433 -#define MISSING_REALM_ERR 434 -#define MISSING_NONCE_ERR 435 -#define UNKNOWN_USERNAME_ERR 436 -#define STALE_NONCE_ERR 438 -#define SERVER_ERROR_ERR 500 -#define GLOBAL_FAILURE_ERR 600 - -#define TRY_ALTERNATE_TXT "Try Alternate" -#define BAD_REQUEST_TXT "Bad Request" -#define UNAUTHORIZED_TXT "Unauthorized" -#define UNKNOWN_ATTRIBUTE_TXT "Unknown Attribute" -#define STALE_CREDENTIALS_TXT "Stale Credentials" -#define INTEGRITY_CHECK_TXT "Integrity Check Failure" -#define MISSING_USERNAME_TXT "Missing Username" -#define USE_TLS_TXT "Use TLS" -#define MISSING_REALM_TXT "Missing Realm" -#define MISSING_NONCE_TXT "Missing Nonce" -#define UNKNOWN_USERNAME_TXT "Unknown Username" -#define STALE_NONCE_TXT "Stale Nonce" -#define SERVER_ERROR_TXT "Server Error" -#define GLOBAL_FAILURE_TXT "Global Failure" +#define RESPONSE_OK 200 +#define TRY_ALTERNATE_ERR 300 +#define BAD_REQUEST_ERR 400 +#define UNAUTHORIZED_ERR 401 +#define UNKNOWN_ATTRIBUTE_ERR 420 +#define STALE_CREDENTIALS_ERR 430 +#define INTEGRITY_CHECK_ERR 431 +#define MISSING_USERNAME_ERR 432 +#define USE_TLS_ERR 433 +#define MISSING_REALM_ERR 434 +#define MISSING_NONCE_ERR 435 +#define UNKNOWN_USERNAME_ERR 436 +#define STALE_NONCE_ERR 438 +#define SERVER_ERROR_ERR 500 +#define GLOBAL_FAILURE_ERR 600 + +#define TRY_ALTERNATE_TXT "Try Alternate" +#define BAD_REQUEST_TXT "Bad Request" +#define UNAUTHORIZED_TXT "Unauthorized" +#define UNKNOWN_ATTRIBUTE_TXT "Unknown Attribute" +#define STALE_CREDENTIALS_TXT "Stale Credentials" +#define INTEGRITY_CHECK_TXT "Integrity Check Failure" +#define MISSING_USERNAME_TXT "Missing Username" +#define USE_TLS_TXT "Use TLS" +#define MISSING_REALM_TXT "Missing Realm" +#define MISSING_NONCE_TXT "Missing Nonce" +#define UNKNOWN_USERNAME_TXT "Unknown Username" +#define STALE_NONCE_TXT "Stale Nonce" +#define SERVER_ERROR_TXT "Server Error" +#define GLOBAL_FAILURE_TXT "Global Failure" /* other stuff */ -#define MAGIC_COOKIE_2B 0x2112 /* because of XOR for port */ -#define MANDATORY_ATTR 0x7fff -#define PAD4 4 -#define PAD64 64 -#define STUN_MSG_LEN 516 -#define IPV4_LEN 4 -#define IPV6_LEN 16 -#define IPV4_FAMILY 0x0001 -#define IPV6_FAMILY 0x0002 -#define FATAL_ERROR -1 -#define IP_ADDR 4 -#define XOR 1 +#define MAGIC_COOKIE_2B 0x2112 /* because of XOR for port */ +#define MANDATORY_ATTR 0x7fff +#define PAD4 4 +#define PAD64 64 +#define STUN_MSG_LEN 516 +#define IPV4_LEN 4 +#define IPV6_LEN 16 +#define IPV4_FAMILY 0x0001 +#define IPV6_FAMILY 0x0002 +#define FATAL_ERROR -1 +#define IP_ADDR 4 +#define XOR 1 #ifndef SHA_DIGEST_LENGTH -#define SHA_DIGEST_LENGTH 20 +#define SHA_DIGEST_LENGTH 20 #endif /** padd len to a multiple of sz. * sz must be a power of the form 2^k (e.g. 2, 4, 8, 16 ...) */ -#define PADD_TO(len, sz) (((len) + (sz)-1) & (~((sz) - 1))) +#define PADD_TO(len, sz) (((len) + (sz)-1) & (~((sz)-1))) -#define PADDED_TO_FOUR(len) PADD_TO(len, 4) +#define PADDED_TO_FOUR(len) PADD_TO(len, 4) #define PADDED_TO_SIXTYFOUR(len) PADD_TO(len, 64) -struct stun_ip_addr { +struct stun_ip_addr +{ USHORT_T family; /* 0x01: IPv4; 0x02: IPv6 */ USHORT_T port; UINT_T ip[IP_ADDR]; }; -struct stun_buffer { +struct stun_buffer +{ str buf; - USHORT_T empty; /* number of free bytes in buf before it'll be necessary + USHORT_T empty; /* number of free bytes in buf before it'll be necessary to realloc the buf */ }; -struct stun_unknown_att { +struct stun_unknown_att +{ USHORT_T type; - struct stun_unknown_att* next; + struct stun_unknown_att *next; }; -struct stun_msg { +struct stun_msg +{ struct stun_hdr hdr; struct stun_ip_addr ip_addr; /* XOR values for rfc3489bis, normal values for rfc3489 */ struct stun_buffer msg; UCHAR_T old; /* true: the format of message is in accordance with - rfc3489 */ + rfc3489 */ }; -int process_stun_msg(char* buf, unsigned len, struct receive_info* ri); +int process_stun_msg(char *buf, unsigned len, struct receive_info *ri); -#endif /* _kam_stun_h */ +#endif /* _kam_stun_h */ diff --git a/src/modules/stun/stun_mod.c b/src/modules/stun/stun_mod.c index ff976d2f6b4..f347f9117c7 100644 --- a/src/modules/stun/stun_mod.c +++ b/src/modules/stun/stun_mod.c @@ -37,32 +37,31 @@ static int mod_init(void); static int stun_msg_receive(sr_event_param_t *evp); struct module_exports exports = { - "stun", /* module name */ - DEFAULT_DLFLAGS, /* dlopen flags */ - 0, /* exported functions */ - 0, /* exported parameters */ - 0, /* exported RPC functions */ - 0, /* exported pseudo-variables */ - 0, /* response function */ - mod_init, /* module initialization function */ - 0, /* per-child initialization function */ - 0 /* destroy function */ + "stun", /* module name */ + DEFAULT_DLFLAGS, /* dlopen flags */ + 0, /* exported functions */ + 0, /* exported parameters */ + 0, /* exported RPC functions */ + 0, /* exported pseudo-variables */ + 0, /* response function */ + mod_init, /* module initialization function */ + 0, /* per-child initialization function */ + 0 /* destroy function */ }; static int mod_init(void) { - if (sr_event_register_cb(SREV_STUN_IN, stun_msg_receive) != 0) - { + if(sr_event_register_cb(SREV_STUN_IN, stun_msg_receive) != 0) { LM_ERR("registering STUN receive call-back\n"); return -1; } - if (cfg_declare("stun", stun_cfg_def, &default_stun_cfg, - cfg_sizeof(stun), &stun_cfg)) { - LM_ERR("declaring config framework variable\n"); - return -1; - } - default_stun_cfg.stun_active = 1; + if(cfg_declare("stun", stun_cfg_def, &default_stun_cfg, cfg_sizeof(stun), + &stun_cfg)) { + LM_ERR("declaring config framework variable\n"); + return -1; + } + default_stun_cfg.stun_active = 1; return 0; }