sockadd2str is c90 compliant
FossilOrigin-Name: 6336ae782e53db768fb7edb6b784c2c2abed4f45b0b1da98a24ac34f7360187f
This commit is contained in:
parent
aa8932b770
commit
fdbfe8af32
@ -1,11 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CodeLite_Workspace Name="actube" Database="">
|
||||
<Project Name="ac" Path="ac.project" Active="No"/>
|
||||
<Project Name="ac" Path="ac.project" Active="Yes"/>
|
||||
<Project Name="wtp" Path="wtp.project" Active="No"/>
|
||||
<Project Name="mod_cipwap" Path="mod_cipwap.project" Active="No"/>
|
||||
<Project Name="mod_capwap" Path="mod_capwap.project" Active="No"/>
|
||||
<Project Name="mod_cisco" Path="mod_cisco.project" Active="No"/>
|
||||
<Project Name="libcw" Path="libcw.project" Active="Yes"/>
|
||||
<Project Name="libcw" Path="libcw.project" Active="No"/>
|
||||
<Project Name="mod_capwap80211" Path="mod_capwap80211.project" Active="No"/>
|
||||
<Project Name="mod_fortinet" Path="mod_fortinet.project" Active="No"/>
|
||||
<BuildMatrix>
|
||||
|
@ -365,6 +365,7 @@ int ac_run()
|
||||
|
||||
void process_cw_data_packet(int index, struct sockaddr *addr, uint8_t * buffer, int len)
|
||||
{
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
cw_dbg(DBG_X, "There is a data packet now");
|
||||
|
||||
dataman_list_lock();
|
||||
@ -372,12 +373,12 @@ void process_cw_data_packet(int index, struct sockaddr *addr, uint8_t * buffer,
|
||||
struct dataman * dm = dataman_list_get(socklist[index].data_sockfd,addr);
|
||||
cw_dbg(DBG_X, "Dataman list locked, now gotted");
|
||||
|
||||
cw_dbg(DBG_INFO,"Packet for dataman %s,%d",sock_addr2str_p(addr),socklist[index].data_sockfd);
|
||||
cw_dbg(DBG_INFO,"Packet for dataman %s,%d",sock_addr2str_p(addr,sock_buf),socklist[index].data_sockfd);
|
||||
if (!dm) {
|
||||
cw_dbg(DBG_INFO,"No dataman %s,%d",sock_addr2str_p(addr),socklist[index].data_sockfd);
|
||||
cw_dbg(DBG_INFO,"No dataman %s,%d",sock_addr2str_p(addr,sock_buf),socklist[index].data_sockfd);
|
||||
dm = dataman_create(socklist[index].data_sockfd,addr);
|
||||
if (!dm){
|
||||
cw_log(LOG_ERR,"Can't create dataman for packet from %s",sock_addr2str_p(addr));
|
||||
cw_log(LOG_ERR,"Can't create dataman for packet from %s",sock_addr2str_p(addr,sock_buf));
|
||||
return;
|
||||
}
|
||||
dataman_list_add(dm);
|
||||
@ -401,7 +402,7 @@ void process_cw_data_packet(int index, struct sockaddr *addr, uint8_t * buffer,
|
||||
exit(0);
|
||||
struct wtpman *wtpman = wtplist_get(addr);
|
||||
if (!wtpman){
|
||||
cw_dbg(DBG_PKT_ERR,"Discarding packet on data channel from %s - No wtpman found.",sock_addr2str(addr));
|
||||
cw_dbg(DBG_PKT_ERR,"Discarding packet on data channel from %s - No wtpman found.",sock_addr2str(addr,sock_buf));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -412,7 +413,7 @@ void process_cw_data_packet(int index, struct sockaddr *addr, uint8_t * buffer,
|
||||
|
||||
void process_cw_ctrl_packet(int index, struct sockaddr *addr, uint8_t * buffer, int len)
|
||||
{
|
||||
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
|
||||
/* first of all check preamble */
|
||||
int preamble = cw_get_hdr_preamble(buffer);
|
||||
@ -420,7 +421,7 @@ void process_cw_ctrl_packet(int index, struct sockaddr *addr, uint8_t * buffer,
|
||||
if (preamble != CAPWAP_PACKET_PREAMBLE && preamble != CAPWAP_DTLS_PACKET_PREAMBLE) {
|
||||
cw_dbg(DBG_PKT_ERR,
|
||||
"Discarding packet from %s, wrong preamble, preamble = 0x%01X",
|
||||
sock_addr2str(addr), preamble);
|
||||
sock_addr2str(addr,sock_buf), preamble);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -332,7 +332,7 @@ static int socklist_check_size()
|
||||
|
||||
int socklist_add_unicast(const char *addr, const char *port, int ac_proto)
|
||||
{
|
||||
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
|
||||
if (!socklist_check_size())
|
||||
return 0;
|
||||
@ -402,7 +402,7 @@ int socklist_add_unicast(const char *addr, const char *port, int ac_proto)
|
||||
sock_addrlen(res->ai_addr));
|
||||
cw_log(LOG_INFO,
|
||||
"Bound to: %s:%s (%i) on interface %s, netmask %s", addr,
|
||||
port, sockfd, ifname, sock_addr2str(&netmask));
|
||||
port, sockfd, ifname, sock_addr2str(&netmask,sock_buf));
|
||||
} else {
|
||||
cw_log(LOG_INFO, "Bound to: [%s]:%s (%i) on interface %s", addr,
|
||||
port, sockfd, ifname);
|
||||
|
@ -45,6 +45,7 @@
|
||||
|
||||
static void reset_echointerval_timer(struct wtpman *wtpman)
|
||||
{
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
uint16_t ct = mbag_get_word(wtpman->conn->local, CW_ITEM_CAPWAP_TIMERS,
|
||||
CW_MAX_DISCOVERY_INTERVAL << 8 |
|
||||
CAPWAP_ECHO_INTERVAL);
|
||||
@ -52,7 +53,7 @@ static void reset_echointerval_timer(struct wtpman *wtpman)
|
||||
/* start echinterval timer and put 2 seconds for "safety" on it */
|
||||
|
||||
wtpman->echointerval_timer = cw_timer_start(2+ (ct & 0xff));
|
||||
db_ping_wtp(sock_addr2str_p(&wtpman->conn->addr), conf_acname);
|
||||
db_ping_wtp(sock_addr2str_p(&wtpman->conn->addr,sock_buf), conf_acname);
|
||||
// cw_dbg(DBG_X, "Starting capwap timer: %d", wtpman->echointerval_timer);
|
||||
|
||||
}
|
||||
@ -130,6 +131,7 @@ int xprocess_message(struct conn *conn, uint8_t * rawmsg, int rawlen,
|
||||
|
||||
static int wtpman_establish_dtls(void *arg)
|
||||
{
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
struct wtpman *wtpman = (struct wtpman *) arg;
|
||||
|
||||
/* setup cipher */
|
||||
@ -165,18 +167,19 @@ static int wtpman_establish_dtls(void *arg)
|
||||
/* try to accept the connection */
|
||||
if (!dtls_accept(wtpman->conn)) {
|
||||
cw_dbg(DBG_DTLS, "Error establishing DTLS session with %s",
|
||||
sock_addr2str_p(&wtpman->conn->addr));
|
||||
sock_addr2str_p(&wtpman->conn->addr,sock_buf));
|
||||
return 0;
|
||||
}
|
||||
|
||||
cw_dbg(DBG_DTLS, "DTLS session established with %s, cipher=%s",
|
||||
sock_addr2str_p(&wtpman->conn->addr), dtls_get_cipher(wtpman->conn));
|
||||
sock_addr2str_p(&wtpman->conn->addr,sock_buf), dtls_get_cipher(wtpman->conn));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int wtpman_join(void *arg, time_t timer)
|
||||
{
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
struct wtpman *wtpman = (struct wtpman *) arg;
|
||||
struct conn *conn = wtpman->conn;
|
||||
|
||||
@ -195,7 +198,7 @@ static int wtpman_join(void *arg, time_t timer)
|
||||
// wtpman->conn->itemstore = mbag_create();
|
||||
|
||||
|
||||
cw_dbg(DBG_INFO, "Join State - %s", sock_addr2str(&conn->addr));
|
||||
cw_dbg(DBG_INFO, "Join State - %s", sock_addr2str(&conn->addr,sock_buf));
|
||||
|
||||
int rc;
|
||||
while (!cw_timer_timeout(timer) && wtpman->conn->capwap_state == CAPWAP_STATE_JOIN) {
|
||||
@ -214,7 +217,7 @@ static int wtpman_join(void *arg, time_t timer)
|
||||
|
||||
if (wtpman->conn->capwap_state == CAPWAP_STATE_JOIN) {
|
||||
cw_dbg(DBG_MSG_ERR, "No join request from %s after %d seconds, WTP died.",
|
||||
sock_addr2str(&wtpman->conn->addr), wtpman->conn->wait_dtls);
|
||||
sock_addr2str(&wtpman->conn->addr,sock_buf), wtpman->conn->wait_dtls);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -227,6 +230,7 @@ static int wtpman_join(void *arg, time_t timer)
|
||||
|
||||
static void wtpman_image_data(struct wtpman *wtpman)
|
||||
{
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
struct conn *conn = wtpman->conn;
|
||||
|
||||
/* Image upload */
|
||||
@ -234,15 +238,15 @@ static void wtpman_image_data(struct wtpman *wtpman)
|
||||
if (!filename) {
|
||||
cw_log(LOG_ERR,
|
||||
"Can't send image to %s. No Image Filename Item found.",
|
||||
sock_addr2str(&conn->addr));
|
||||
sock_addr2str(&conn->addr,sock_buf));
|
||||
return;
|
||||
}
|
||||
cw_dbg(DBG_INFO, "Sending image file '%s' to '%s'.", filename,
|
||||
sock_addr2str(&conn->addr));
|
||||
sock_addr2str(&conn->addr,sock_buf));
|
||||
FILE *infile = fopen(filename, "rb");
|
||||
if (infile == NULL) {
|
||||
cw_log(LOG_ERR, "Can't open image %s: %s",
|
||||
sock_addr2str(&conn->addr), strerror(errno));
|
||||
sock_addr2str(&conn->addr,sock_buf), strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -263,10 +267,10 @@ static void wtpman_image_data(struct wtpman *wtpman)
|
||||
|
||||
if (rc) {
|
||||
cw_log(LOG_ERR, "Error sending image to %s: %s",
|
||||
sock_addr2str(&conn->addr), cw_strrc(rc));
|
||||
sock_addr2str(&conn->addr,sock_buf), cw_strrc(rc));
|
||||
} else {
|
||||
cw_dbg(DBG_INFO, "Image '%s' sucessful sent to %s in %0.1f seconds.",
|
||||
filename, sock_addr2str(&conn->addr), cw_clock_stop(&clk));
|
||||
filename, sock_addr2str(&conn->addr,sock_buf), cw_clock_stop(&clk));
|
||||
conn->capwap_state = CW_STATE_NONE;
|
||||
}
|
||||
|
||||
@ -424,7 +428,8 @@ void radio_to_sql(struct conn *conn, char *wtp_id, int rid, mbag_t radio)
|
||||
|
||||
void radios_to_sql(struct conn *conn)
|
||||
{
|
||||
char *wtp_id = sock_addr2str(&conn->addr);
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
char *wtp_id = sock_addr2str(&conn->addr,sock_buf);
|
||||
MAVLITER_DEFINE(it, conn->radios);
|
||||
mavliter_foreach(&it) {
|
||||
struct mbag_item * i = mavliter_get(&it);
|
||||
@ -475,7 +480,7 @@ static int msg_end_handler(struct conn *conn, struct cw_action_in *a, uint8_t *
|
||||
|
||||
static void wtpman_run(void *arg)
|
||||
{
|
||||
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
|
||||
struct wtpman *wtpman = (struct wtpman *) arg;
|
||||
|
||||
@ -514,7 +519,7 @@ static void wtpman_run(void *arg)
|
||||
|
||||
|
||||
cw_dbg(DBG_INFO, "WTP from %s has joined with session id: %s",
|
||||
sock_addr2str_p(&conn->addr),
|
||||
sock_addr2str_p(&conn->addr,sock_buf),
|
||||
format_bin2hex(conn->session_id,16));
|
||||
|
||||
|
||||
@ -579,7 +584,7 @@ static void wtpman_run(void *arg)
|
||||
if (cw_timer_timeout(wtpman->echointerval_timer)) {
|
||||
|
||||
cw_dbg(DBG_INFO, "Lost connection to WTP:%s",
|
||||
sock_addr2str_p(&conn->addr));
|
||||
sock_addr2str_p(&conn->addr,sock_buf));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -592,13 +597,13 @@ static void wtpman_run(void *arg)
|
||||
|
||||
|
||||
mavl_conststr_t r;
|
||||
r = db_get_update_tasks(conn, sock_addr2str(&conn->addr));
|
||||
r = db_get_update_tasks(conn, sock_addr2str(&conn->addr,sock_buf));
|
||||
if (r) {
|
||||
|
||||
if (!conn->outgoing->count)
|
||||
continue;
|
||||
|
||||
cw_dbg(DBG_INFO, "Updating WTP %s",sock_addr2str(&conn->addr));
|
||||
cw_dbg(DBG_INFO, "Updating WTP %s",sock_addr2str(&conn->addr,sock_buf));
|
||||
|
||||
rc = cw_send_request(conn, CAPWAP_MSG_CONFIGURATION_UPDATE_REQUEST);
|
||||
mavl_merge(conn->config, conn->outgoing);
|
||||
@ -609,13 +614,13 @@ static void wtpman_run(void *arg)
|
||||
mavl_destroy(r);
|
||||
}
|
||||
|
||||
r = db_get_radio_tasks(conn, sock_addr2str(&conn->addr));
|
||||
r = db_get_radio_tasks(conn, sock_addr2str(&conn->addr,sock_buf));
|
||||
if (r) {
|
||||
|
||||
if (!conn->radios_upd->count)
|
||||
continue;
|
||||
|
||||
cw_dbg(DBG_INFO, "Updating Radios for %s",sock_addr2str(&conn->addr));
|
||||
cw_dbg(DBG_INFO, "Updating Radios for %s",sock_addr2str(&conn->addr,sock_buf));
|
||||
rc = cw_send_request(conn, CAPWAP_MSG_CONFIGURATION_UPDATE_REQUEST);
|
||||
|
||||
|
||||
@ -642,7 +647,7 @@ static void wtpman_run(void *arg)
|
||||
|
||||
}
|
||||
|
||||
db_ping_wtp(sock_addr2str_p(&conn->addr), "");
|
||||
db_ping_wtp(sock_addr2str_p(&conn->addr,sock_buf), "");
|
||||
wtpman_remove(wtpman);
|
||||
return;
|
||||
}
|
||||
@ -650,7 +655,7 @@ static void wtpman_run(void *arg)
|
||||
|
||||
static void wtpman_run_dtls(void *arg)
|
||||
{
|
||||
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
struct wtpman *wtpman = (struct wtpman *) arg;
|
||||
|
||||
|
||||
@ -658,7 +663,7 @@ static void wtpman_run_dtls(void *arg)
|
||||
/* reject connections to our multi- or broadcast sockets */
|
||||
if (socklist[wtpman->socklistindex].type != SOCKLIST_UNICAST_SOCKET) {
|
||||
cw_dbg(DBG_DTLS, "Dropping connection from %s to non-unicast socket.",
|
||||
sock_addr2str_p(&wtpman->conn->addr));
|
||||
sock_addr2str_p(&wtpman->conn->addr,sock_buf));
|
||||
wtpman_remove(wtpman);
|
||||
return;
|
||||
}
|
||||
@ -686,6 +691,7 @@ void wtpman_destroy(struct wtpman *wtpman)
|
||||
|
||||
struct wtpman *wtpman_create(int socklistindex, struct sockaddr *srcaddr)
|
||||
{
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
struct wtpman *wtpman;
|
||||
wtpman = malloc(sizeof(struct wtpman));
|
||||
if (!wtpman)
|
||||
@ -701,7 +707,7 @@ struct wtpman *wtpman_create(int socklistindex, struct sockaddr *srcaddr)
|
||||
|
||||
if (replyfd == -1) {
|
||||
cw_log(LOG_ERR, "Can't find reply socket for request from %s",
|
||||
sock_addr2str(srcaddr));
|
||||
sock_addr2str(srcaddr,sock_buf));
|
||||
free(wtpman);
|
||||
return NULL;
|
||||
}
|
||||
@ -717,7 +723,7 @@ struct wtpman *wtpman_create(int socklistindex, struct sockaddr *srcaddr)
|
||||
getsockname(sockfd, &dbgaddr, &dbgaddrl);
|
||||
|
||||
cw_dbg(DBG_INFO, "Creating wtpman on socket %d, %s:%d", sockfd,
|
||||
sock_addr2str(&dbgaddr), sock_getport(&dbgaddr));
|
||||
sock_addr2str(&dbgaddr,sock_buf), sock_getport(&dbgaddr));
|
||||
|
||||
//extern int conn_process_packet2(struct conn *conn, uint8_t * packet, int len,
|
||||
// struct sockaddr *from);
|
||||
|
@ -181,13 +181,14 @@ static int check_len(struct conn *conn, struct cw_action_in *a, uint8_t * data,
|
||||
static struct cw_MsgSet *load_msg_set(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
int elems_len, struct sockaddr *from)
|
||||
{
|
||||
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
|
||||
struct cw_Mod *cmod =
|
||||
cw_mod_detect(conn, rawmsg, len, elems_len, from, CW_MOD_MODE_CAPWAP);
|
||||
if (cmod == MOD_NULL) {
|
||||
cw_dbg(DBG_MSG_ERR,
|
||||
"Can't find mod to handle connection from %s, discarding message",
|
||||
sock_addr2str_p(from));
|
||||
sock_addr2str_p(from,sock_buf));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -219,6 +220,7 @@ int cw_in_check_generic(struct conn *conn, struct cw_action_in *a, uint8_t * dat
|
||||
static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
struct sockaddr *from)
|
||||
{
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
struct cw_action_in as, *af, *afm;
|
||||
|
||||
int offset = cw_get_hdr_msg_offset(rawmsg);
|
||||
@ -236,7 +238,7 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
if (conn->strict_hdr) {
|
||||
cw_dbg(DBG_MSG_ERR,
|
||||
"Discarding message from %s, msgelems len=%d, payload len=%d, (Strict CAPWAP) ",
|
||||
sock_addr2str(&conn->addr), elems_len, payloadlen - 8);
|
||||
sock_addr2str(&conn->addr,sock_buf), elems_len, payloadlen - 8);
|
||||
errno = EAGAIN;
|
||||
return -1;
|
||||
}
|
||||
@ -245,7 +247,7 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
if (elems_len < payloadlen - 8) {
|
||||
cw_dbg(DBG_RFC,
|
||||
"Packet from from %s has %d bytes of extra data, ignoring.",
|
||||
sock_addr2str(&conn->addr), payloadlen - 8 - elems_len);
|
||||
sock_addr2str(&conn->addr,sock_buf), payloadlen - 8 - elems_len);
|
||||
elems_len = len - 8;
|
||||
}
|
||||
|
||||
@ -253,7 +255,7 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
|
||||
cw_dbg(DBG_RFC,
|
||||
"Packet from from %s has msgelems len of %d bytes, but has only %d bytes of data, truncating.",
|
||||
sock_addr2str(&conn->addr), elems_len, payloadlen - 8);
|
||||
sock_addr2str(&conn->addr, sock_buf), elems_len, payloadlen - 8);
|
||||
elems_len = payloadlen - 8;
|
||||
}
|
||||
}
|
||||
@ -487,7 +489,7 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
int process_message(struct conn *conn, uint8_t * rawmsg, int rawlen,
|
||||
struct sockaddr *from)
|
||||
{
|
||||
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
|
||||
uint8_t *msgptr = rawmsg + cw_get_hdr_msg_offset(rawmsg);
|
||||
|
||||
@ -517,7 +519,7 @@ int process_message(struct conn *conn, uint8_t * rawmsg, int rawlen,
|
||||
if (sd != 0) {
|
||||
cw_dbg(DBG_MSG_ERR,
|
||||
"Discarding message from %s, old seqnum, seqnum = %d, last seqnum=%d",
|
||||
sock_addr2str(&conn->addr), s2, s1);
|
||||
sock_addr2str(&conn->addr,sock_buf), s2, s1);
|
||||
errno = EAGAIN;
|
||||
return -1;
|
||||
}
|
||||
@ -528,7 +530,7 @@ int process_message(struct conn *conn, uint8_t * rawmsg, int rawlen,
|
||||
|
||||
cw_dbg(DBG_MSG_ERR,
|
||||
"Retransmitted request message from %s detected, seqnum=%d, type=%d",
|
||||
sock_addr2str(&conn->addr), s2, type);
|
||||
sock_addr2str(&conn->addr,sock_buf), s2, type);
|
||||
|
||||
|
||||
if (cw_get_hdr_msg_type(conn->resp_buffer) - 1 != type) {
|
||||
@ -540,7 +542,7 @@ int process_message(struct conn *conn, uint8_t * rawmsg, int rawlen,
|
||||
}
|
||||
|
||||
cw_dbg(DBG_MSG_ERR, "Retransmitting response message to %s, seqnum=%d",
|
||||
sock_addr2str(&conn->addr), s2);
|
||||
sock_addr2str(&conn->addr, sock_buf), s2);
|
||||
|
||||
// XXX untested
|
||||
conn_send_msg(conn, conn->resp_buffer);
|
||||
@ -558,13 +560,13 @@ int process_message(struct conn *conn, uint8_t * rawmsg, int rawlen,
|
||||
int conn_process_packet2(struct conn *conn, uint8_t * packet, int len,
|
||||
struct sockaddr *from)
|
||||
{
|
||||
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
|
||||
if (len < 8) {
|
||||
/* packet too short */
|
||||
cw_dbg(DBG_PKT_ERR,
|
||||
"Discarding packet from %s, packet too short, len=%d, at least 8 expected.",
|
||||
sock_addr2str(&conn->addr), len);
|
||||
sock_addr2str(&conn->addr, sock_buf), len);
|
||||
errno = EAGAIN;
|
||||
return -1;
|
||||
}
|
||||
@ -575,7 +577,7 @@ int conn_process_packet2(struct conn *conn, uint8_t * packet, int len,
|
||||
/* wrong version */
|
||||
cw_dbg(DBG_PKT_ERR,
|
||||
"Discarding packet from %s, wrong version, version=%d, version %d expected.",
|
||||
sock_addr2str(&conn->addr), (preamble & 0xf0) >> 4,
|
||||
sock_addr2str(&conn->addr,sock_buf), (preamble & 0xf0) >> 4,
|
||||
CAPWAP_VERSION);
|
||||
errno = EAGAIN;
|
||||
return -1;
|
||||
@ -585,7 +587,7 @@ int conn_process_packet2(struct conn *conn, uint8_t * packet, int len,
|
||||
/* Encrypted data, this shuold never happen here */
|
||||
cw_dbg(DBG_PKT_ERR,
|
||||
"Discarding packet from %s, encrypted data after decryption ...",
|
||||
sock_addr2str(&conn->addr));
|
||||
sock_addr2str(&conn->addr,sock_buf));
|
||||
errno = EAGAIN;
|
||||
return -1;
|
||||
}
|
||||
@ -599,7 +601,7 @@ int conn_process_packet2(struct conn *conn, uint8_t * packet, int len,
|
||||
/* Eleminate messages with wrong header size */
|
||||
cw_dbg(DBG_PKT_ERR,
|
||||
"Discarding packet from %s, header length (%d) greater than packet len (%d).",
|
||||
sock_addr2str(&conn->addr), offs, len);
|
||||
sock_addr2str(&conn->addr,sock_buf), offs, len);
|
||||
errno = EAGAIN;
|
||||
return -1;
|
||||
}
|
||||
@ -611,7 +613,7 @@ int conn_process_packet2(struct conn *conn, uint8_t * packet, int len,
|
||||
/* wrong rmac size */
|
||||
cw_dbg(DBG_PKT_ERR,
|
||||
"Discarding packet from %s, wrong R-MAC size, size=%d",
|
||||
sock_addr2str(&conn->addr), *(packet + 8));
|
||||
sock_addr2str(&conn->addr,sock_buf), *(packet + 8));
|
||||
errno = EAGAIN;
|
||||
return -1;
|
||||
}
|
||||
|
@ -27,6 +27,7 @@
|
||||
|
||||
void conn_q_add_packet(struct conn * conn,uint8_t *packet,int len)
|
||||
{
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
int qwpos = conn->qwpos;
|
||||
if (qwpos==conn->qsize)
|
||||
qwpos=0;
|
||||
@ -34,7 +35,7 @@ void conn_q_add_packet(struct conn * conn,uint8_t *packet,int len)
|
||||
if (conn->qrpos==qwpos){
|
||||
/* no buffers, discard packet */
|
||||
cw_dbg(DBG_PKT_ERR, "Discarding packet from %s, no queue buffers left",
|
||||
sock_addr2str(&conn->addr));
|
||||
sock_addr2str(&conn->addr,sock_buf));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -31,9 +31,10 @@
|
||||
|
||||
int conn_send_data_packet(struct conn * conn, const uint8_t * buffer, int len)
|
||||
{
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
int n;
|
||||
|
||||
cw_dbg(DBG_X,"Sending data packet to %s\n",sock_addr2str_p(&conn->data_addr));
|
||||
cw_dbg(DBG_X,"Sending data packet to %s\n",sock_addr2str_p(&conn->data_addr,sock_buf));
|
||||
|
||||
while((n=sendto( conn->data_sock, buffer, len, 0,
|
||||
(struct sockaddr*)&conn->data_addr,
|
||||
|
@ -16,7 +16,8 @@ void cw_get_wtp_name(struct conn *conn,struct sockaddr *addr)
|
||||
|
||||
int cw_set_capwap_mode(struct conn *conn,int mode)
|
||||
{
|
||||
cw_dbg(DBG_INFO,"Setting CAPWAP mode to %d for %s",mode,sock_addr2str(&conn->addr));
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
cw_dbg(DBG_INFO,"Setting CAPWAP mode to %d for %s",mode,sock_addr2str(&conn->addr,sock_buf));
|
||||
conn->capwap_mode_out=mode;
|
||||
return 1;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
int cw_in_check_disc_req(struct conn *conn, struct cw_action_in *a, uint8_t * data,
|
||||
int len,struct sockaddr *from)
|
||||
{
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
|
||||
cw_action_in_t *mlist[120];
|
||||
int n = cw_check_missing_mand(mlist, conn, a);
|
||||
@ -23,7 +24,7 @@ int cw_in_check_disc_req(struct conn *conn, struct cw_action_in *a, uint8_t * da
|
||||
mode send no discovery response */
|
||||
cw_dbg(DBG_MSG_ERR,
|
||||
"Ignoring Discovery Request from %s - missing mandatory elements.",
|
||||
sock_addr2str(from));
|
||||
sock_addr2str(from,sock_buf));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
17
src/cw/dbg.c
17
src/cw/dbg.c
@ -217,21 +217,24 @@ void cw_dbg_missing_mand(int level, struct conn *conn, cw_action_in_t ** ml, int
|
||||
int cw_format_pkt_hdr(char *dst, int level, struct conn *conn, uint8_t * packet, int len,
|
||||
struct sockaddr *from)
|
||||
{
|
||||
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
|
||||
char *s = dst;
|
||||
switch (level) {
|
||||
case DBG_PKT_IN:
|
||||
if (cw_get_hdr_flag_f(packet)) {
|
||||
s += sprintf(s, "Fragment from %s",
|
||||
sock_addr2str_p(from));
|
||||
sock_addr2str_p(from,sock_buf));
|
||||
} else {
|
||||
s += sprintf(s, "From %s", sock_addr2str_p(from));
|
||||
s += sprintf(s, "From %s", sock_addr2str_p(from,sock_buf));
|
||||
}
|
||||
break;
|
||||
case DBG_PKT_OUT:
|
||||
if (cw_get_hdr_flag_f(packet)) {
|
||||
s += sprintf(s, "Fragment to %s", sock_addr2str(from));
|
||||
s += sprintf(s, "Fragment to %s", sock_addr2str(from,sock_buf));
|
||||
} else {
|
||||
s += sprintf(s, "To %s", sock_addr2str(from));
|
||||
s += sprintf(s, "To %s", sock_addr2str(from,sock_buf));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -477,7 +480,7 @@ void cw_dbg_msg(int level, struct conn *conn, uint8_t * packet, int len,
|
||||
{
|
||||
if (!cw_dbg_is_level(level))
|
||||
return;
|
||||
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
char buf[1024];
|
||||
char *s = buf;
|
||||
|
||||
@ -501,9 +504,9 @@ void cw_dbg_msg(int level, struct conn *conn, uint8_t * packet, int len,
|
||||
|
||||
s += sprintf(s, "%s Message (type=%d) ", msname /*cw_strmsg(msg_id)*/, msg_id);
|
||||
if (level == DBG_MSG_IN)
|
||||
s += sprintf(s, "from %s ", sock_addr2str(from));
|
||||
s += sprintf(s, "from %s ", sock_addr2str(from,sock_buf));
|
||||
else
|
||||
s += sprintf(s, "to %s ", sock_addr2str(from));
|
||||
s += sprintf(s, "to %s ", sock_addr2str(from,sock_buf));
|
||||
|
||||
s += sprintf(s, ", Seqnum: %d ElemLen: %d", cw_get_msg_seqnum(msgptr),
|
||||
cw_get_msg_elems_len(msgptr));
|
||||
|
@ -27,6 +27,7 @@
|
||||
|
||||
#include "conn.h"
|
||||
|
||||
|
||||
#ifndef CW_LOG_DUMP_ROW_LEN
|
||||
#define CW_LOG_DUMP_ROW_LEN 32
|
||||
#endif
|
||||
@ -35,6 +36,7 @@
|
||||
#define CW_LOG_DUMP_ROW_TAB_LEN 8
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
*@defgroup DBG DBG
|
||||
*@{
|
||||
|
@ -37,13 +37,14 @@
|
||||
|
||||
int dtls_gnutls_accept(struct conn *conn)
|
||||
{
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
struct dtls_gnutls_data *d;
|
||||
|
||||
gnutls_datum_t cookie_key;
|
||||
|
||||
gnutls_key_generate(&cookie_key, GNUTLS_COOKIE_KEY_SIZE);
|
||||
cw_dbg(DBG_DTLS, "Session cookie for %s generated: %s",
|
||||
sock_addr2str(&conn->addr), sock_hwaddr2idstr((uint8_t *) (&cookie_key),
|
||||
sock_addr2str(&conn->addr,sock_buf), sock_hwaddr2idstr((uint8_t *) (&cookie_key),
|
||||
sizeof(cookie_key)));
|
||||
|
||||
gnutls_dtls_prestate_st prestate;
|
||||
@ -94,7 +95,7 @@ int dtls_gnutls_accept(struct conn *conn)
|
||||
}
|
||||
|
||||
|
||||
cw_dbg(DBG_DTLS, "Cookie verified! Starting handshake with %s ...",sock_addr2str(&conn->addr));
|
||||
cw_dbg(DBG_DTLS, "Cookie verified! Starting handshake with %s ...",sock_addr2str(&conn->addr,sock_buf));
|
||||
|
||||
|
||||
|
||||
@ -113,12 +114,12 @@ int dtls_gnutls_accept(struct conn *conn)
|
||||
|
||||
|
||||
if ( rc < 0 ) {
|
||||
cw_log(LOG_ERR, "Error in handshake with %s: %s",sock_addr2str(&conn->addr), gnutls_strerror(rc));
|
||||
cw_log(LOG_ERR, "Error in handshake with %s: %s",sock_addr2str(&conn->addr,sock_buf), gnutls_strerror(rc));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
cw_dbg(DBG_DTLS,"Handshake with %s successful.",sock_addr2str(&conn->addr));
|
||||
cw_dbg(DBG_DTLS,"Handshake with %s successful.",sock_addr2str(&conn->addr,sock_buf));
|
||||
|
||||
conn->dtls_data=d;
|
||||
conn->read = dtls_gnutls_read;
|
||||
|
@ -38,6 +38,7 @@
|
||||
*/
|
||||
int dtls_gnutls_connect(struct conn *conn)
|
||||
{
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
struct dtls_gnutls_data *d;
|
||||
d = dtls_gnutls_data_create(conn,
|
||||
GNUTLS_CLIENT | GNUTLS_DATAGRAM | GNUTLS_NONBLOCK);
|
||||
@ -63,12 +64,12 @@ int dtls_gnutls_connect(struct conn *conn)
|
||||
|
||||
if (rc < 0) {
|
||||
cw_log(LOG_ERR, "DTLS (gnutls) Can't connect to %s: %s",
|
||||
sock_addr2str(&conn->addr), gnutls_strerror(rc));
|
||||
sock_addr2str(&conn->addr,sock_buf), gnutls_strerror(rc));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
cw_dbg(DBG_DTLS, "Handshake with %s successful", sock_addr2str(&conn->addr));
|
||||
cw_dbg(DBG_DTLS, "Handshake with %s successful", sock_addr2str(&conn->addr,sock_buf));
|
||||
|
||||
conn->dtls_data = d;
|
||||
conn->read = dtls_gnutls_read;
|
||||
|
@ -531,6 +531,7 @@ int dtls_openssl_shutdown(struct conn *conn)
|
||||
|
||||
int dtls_openssl_generate_cookie(SSL *ssl, unsigned char *cookie, unsigned int *cookie_len)
|
||||
{
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
|
||||
BIO * b = SSL_get_rbio(ssl);
|
||||
struct conn * conn = b->ptr;
|
||||
@ -539,7 +540,7 @@ int dtls_openssl_generate_cookie(SSL *ssl, unsigned char *cookie, unsigned int *
|
||||
|
||||
/* we "missuse" sockaddr2str to convert our cookie to a hex str */
|
||||
cw_dbg(DBG_DTLS,"DTLS session cookie for %s generated: %s",
|
||||
sock_addr2str(&conn->addr), sock_hwaddr2idstr(conn->dtls_cookie,sizeof(conn->dtls_cookie)));
|
||||
sock_addr2str(&conn->addr,sock_buf), sock_hwaddr2idstr(conn->dtls_cookie,sizeof(conn->dtls_cookie)));
|
||||
|
||||
memcpy(cookie,conn->dtls_cookie,sizeof(conn->dtls_cookie));
|
||||
*cookie_len=sizeof(conn->dtls_cookie);
|
||||
@ -552,11 +553,12 @@ int dtls_openssl_generate_cookie(SSL *ssl, unsigned char *cookie, unsigned int *
|
||||
|
||||
int dtls_openssl_verify_cookie(SSL *ssl, unsigned char *cookie, unsigned int len)
|
||||
{
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
BIO * b = SSL_get_rbio(ssl);
|
||||
struct conn * conn = b->ptr;
|
||||
|
||||
cw_dbg(DBG_DTLS,"Verifying DTLS cookie from %s: %s",
|
||||
sock_addr2str(&conn->addr),sock_hwaddr2idstr(conn->dtls_cookie,len));
|
||||
sock_addr2str(&conn->addr,sock_buf),sock_hwaddr2idstr(conn->dtls_cookie,len));
|
||||
|
||||
if (len != sizeof(conn->dtls_cookie)){
|
||||
return 0;
|
||||
|
@ -26,6 +26,8 @@
|
||||
|
||||
int dtls_openssl_accept(struct conn *conn)
|
||||
{
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
|
||||
if (!conn->dtls_data)
|
||||
conn->dtls_data =
|
||||
dtls_openssl_data_create(conn, DTLSv1_server_method(),
|
||||
@ -49,6 +51,6 @@ int dtls_openssl_accept(struct conn *conn)
|
||||
return 0;
|
||||
}
|
||||
cw_log(LOG_ERR, "DTLS Error: Timeout while establishing session with %s.",
|
||||
sock_addr2str(&conn->addr));
|
||||
sock_addr2str(&conn->addr, sock_buf));
|
||||
return 0;
|
||||
}
|
||||
|
@ -124,6 +124,7 @@ int netconn_q_recv_packet_peek(struct netconn *nc, uint8_t * buffer, int len)
|
||||
|
||||
void netconn_q_add_packet(struct netconn * nc,uint8_t *packet,int len)
|
||||
{
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
int qwpos = nc->qwpos;
|
||||
if (qwpos==nc->qsize)
|
||||
qwpos=0;
|
||||
@ -131,7 +132,7 @@ void netconn_q_add_packet(struct netconn * nc,uint8_t *packet,int len)
|
||||
if (nc->qrpos==qwpos){
|
||||
/* no buffers, discard packet */
|
||||
cw_dbg(DBG_PKT_ERR, "Discarding packet from %s, no queue buffers left",
|
||||
sock_addr2str(&nc->addr));
|
||||
sock_addr2str(&nc->addr,sock_buf));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -236,13 +237,14 @@ int netconn_send_capwap_msg(struct netconn * nc, uint8_t *rawmsg, int msglen)
|
||||
int netconn_process_packet(struct netconn *nc, uint8_t * packet, int len,
|
||||
struct sockaddr *from)
|
||||
{
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
|
||||
cw_dbg_pkt_nc(DBG_PKT_IN, nc, packet, len, from);
|
||||
if (len < 8) {
|
||||
/* packet too short */
|
||||
cw_dbg(DBG_PKT_ERR,
|
||||
"Discarding packet from %s, packet too short, len=%d, at least 8 expected.",
|
||||
sock_addr2str(&nc->addr), len);
|
||||
sock_addr2str(&nc->addr,sock_buf), len);
|
||||
errno = EAGAIN;
|
||||
return -1;
|
||||
}
|
||||
@ -253,7 +255,7 @@ int netconn_process_packet(struct netconn *nc, uint8_t * packet, int len,
|
||||
/* wrong version */
|
||||
cw_dbg(DBG_PKT_ERR,
|
||||
"Discarding packet from %s, wrong version, version=%d, version %d expected.",
|
||||
sock_addr2str(&nc->addr), (preamble & 0xf0) >> 4,
|
||||
sock_addr2str(&nc->addr,sock_buf), (preamble & 0xf0) >> 4,
|
||||
CAPWAP_VERSION);
|
||||
errno = EAGAIN;
|
||||
return -1;
|
||||
@ -263,7 +265,7 @@ int netconn_process_packet(struct netconn *nc, uint8_t * packet, int len,
|
||||
/* Encrypted data, this shuold never happen here */
|
||||
cw_dbg(DBG_PKT_ERR,
|
||||
"Discarding packet from %s, encrypted data after decryption ...",
|
||||
sock_addr2str(&nc->addr));
|
||||
sock_addr2str(&nc->addr,sock_buf));
|
||||
errno = EAGAIN;
|
||||
return -1;
|
||||
}
|
||||
@ -277,7 +279,7 @@ int netconn_process_packet(struct netconn *nc, uint8_t * packet, int len,
|
||||
/* Eleminate messages with wrong header size */
|
||||
cw_dbg(DBG_PKT_ERR,
|
||||
"Discarding packet from %s, header length (%d) greater than packet len (%d).",
|
||||
sock_addr2str(&nc->addr), offs, len);
|
||||
sock_addr2str(&nc->addr,sock_buf), offs, len);
|
||||
errno = EAGAIN;
|
||||
return -1;
|
||||
}
|
||||
@ -289,7 +291,7 @@ int netconn_process_packet(struct netconn *nc, uint8_t * packet, int len,
|
||||
/* wrong rmac size */
|
||||
cw_dbg(DBG_PKT_ERR,
|
||||
"Discarding packet from %s, wrong R-MAC size, size=%d",
|
||||
sock_addr2str(&nc->addr), *(packet + 8));
|
||||
sock_addr2str(&nc->addr,sock_buf), *(packet + 8));
|
||||
errno = EAGAIN;
|
||||
return -1;
|
||||
}
|
||||
|
@ -124,6 +124,7 @@ int conn_send_data_msg(struct conn * conn, uint8_t *rawmsg,int len)
|
||||
|
||||
int cw_send_request(struct conn *conn,int msg_id)
|
||||
{
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
cw_init_request(conn, msg_id);
|
||||
if ( cw_put_msg(conn, conn->req_buffer) == -1 ){
|
||||
errno=ENOMSG;
|
||||
@ -157,7 +158,7 @@ int cw_send_request(struct conn *conn,int msg_id)
|
||||
}
|
||||
|
||||
if ( rc <0 && errno != EAGAIN) {
|
||||
cw_log(LOG_ERR,"Can't read from %s: %s",sock_addr2str(&conn->addr),strerror(errno));
|
||||
cw_log(LOG_ERR,"Can't read from %s: %s",sock_addr2str(&conn->addr,sock_buf),strerror(errno));
|
||||
}
|
||||
if ( rc <0 && errno == EAGAIN) {
|
||||
errno=ETIMEDOUT;
|
||||
|
@ -84,6 +84,9 @@ extern int sock_getifinfo(const struct sockaddr *addr, char *ifname,
|
||||
|
||||
char *sock_addrtostr(const struct sockaddr *sa, char *s, size_t maxlen, int addport);
|
||||
|
||||
#define SOCK_ADDR_BUFSIZE 64
|
||||
|
||||
#define SOCK_ADDR_BUF_DEFINE char __sock_buf__[SOCK_ADDR_BUFSIZE]
|
||||
|
||||
/**
|
||||
* Convert a sockaddr structure to a human readable string
|
||||
@ -100,13 +103,13 @@ char *sock_addrtostr(const struct sockaddr *sa, char *s, size_t maxlen, int addp
|
||||
sprintf("Adress: %s",sock_addr2str(&sa));
|
||||
\endcode
|
||||
*/
|
||||
#define sock_addr2str(s) ( sock_addrtostr( (struct sockaddr*)s, (char[64]){0}, 64, 0 ) )
|
||||
#define sock_addr2str(s,buf) ( sock_addrtostr( (struct sockaddr*)s, buf , SOCK_ADDR_BUFSIZE, 0 ) )
|
||||
|
||||
/**
|
||||
* Same as #sock_addr2str, but also the port number is appended to the result
|
||||
* @see #sock_addr2str
|
||||
*/
|
||||
#define sock_addr2str_p(s) ( sock_addrtostr( (struct sockaddr*)s, (char[64]){0}, 64,1 ) )
|
||||
#define sock_addr2str_p(s,buf) ( sock_addrtostr( (struct sockaddr*)s, buf, SOCK_ADDR_BUFSIZE, 1 ) )
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user