From dd7b4f46a52c4f9b2d0f3c48f111e024827567e7 Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Sat, 5 Mar 2016 07:51:52 +0000 Subject: [PATCH] Checks for psk and cert files New indentation. FossilOrigin-Name: dc933bcd1f09da544d06ef1c35bb4693a74c896999f90a3897c9c5fcb8816e9b --- src/wtp/join.c | 139 ++++++++++++++++++++++++++++++------------------- 1 file changed, 84 insertions(+), 55 deletions(-) diff --git a/src/wtp/join.c b/src/wtp/join.c index 3f13e256..188edd5e 100644 --- a/src/wtp/join.c +++ b/src/wtp/join.c @@ -97,58 +97,71 @@ acinfo.result_code=99; int run_join_d(struct sockaddr *sa) { struct conn *conn = get_conn(); - conn->capwap_state=CW_STATE_JOIN; + conn->capwap_state = CW_STATE_JOIN; int sockfd; int rc; - sockfd = socket(AF_INET,SOCK_DGRAM,0); - if (sockfd==-1){ - cw_log(LOG_ERR,"Can't create socket: %s\n",strerror(errno)); + sockfd = socket(AF_INET, SOCK_DGRAM, 0); + if (sockfd == -1) { + cw_log(LOG_ERR, "Can't create socket: %s\n", strerror(errno)); return -1; } - sock_set_recvtimeout(sockfd,1); + sock_set_recvtimeout(sockfd, 1); - rc = connect(sockfd,(struct sockaddr*)sa,sock_addrlen((struct sockaddr*)sa)); + rc = connect(sockfd, (struct sockaddr *) sa, + sock_addrlen((struct sockaddr *) sa)); - if (rc<0){ - cw_log(LOG_ERR,"Can't connect to %s: %s\n",sock_addr2str(sa),strerror(errno)); + if (rc < 0) { + cw_log(LOG_ERR, "Can't connect to %s: %s\n", sock_addr2str(sa), + strerror(errno)); close(sockfd); return -1; } - conn->sock=sockfd; - sock_copyaddr(&conn->addr,sa); + conn->sock = sockfd; + sock_copyaddr(&conn->addr, sa); - cw_dbg (DBG_DTLS,"Establishing DTLS session with %s",sock_addr2str(sa)); + cw_dbg(DBG_DTLS, "Establishing DTLS session with %s", sock_addr2str(sa)); - if (conf_dtls_psk){ - conn->dtls_psk=conf_dtls_psk; - conn->dtls_psk_len=strlen(conn->dtls_psk); - conn->dtls_cipher=conf_dtls_cipher; + int dtls_conf_ok=0; + + if (conf_dtls_psk) { + conn->dtls_psk = conf_dtls_psk; + conn->dtls_psk_len = strlen(conn->dtls_psk); + conn->dtls_cipher = conf_dtls_cipher; + dtls_conf_ok=1; } - if (conf_sslkeyfilename && conf_sslcertfilename){ + if (conf_sslkeyfilename && conf_sslcertfilename) { conn->dtls_key_file = conf_sslkeyfilename; conn->dtls_cert_file = conf_sslcertfilename; conn->dtls_key_pass = conf_sslkeypass; - conn->dtls_cipher=conf_dtls_cipher; - + conn->dtls_cipher = conf_dtls_cipher; + dtls_conf_ok=1; } - - - rc = dtls_connect(conn); - if (rc!=1){ - dtls_shutdown(conn); - cw_log(LOG_ERR,"Can't establish DTLS connection to %s", sock_addr2str(sa)); + if (!dtls_conf_ok){ + cw_log(LOG_ERR,"Can't establish DTLS connection with %s, neither psk nor cert set in config", + sock_addr2str(sa)); close(sockfd); return 0; } - cw_dbg (DBG_DTLS,"DTLS Connection successful established with %s",sock_addr2str(sa)); + rc = dtls_connect(conn); + if (rc != 1) { + dtls_shutdown(conn); + cw_log(LOG_ERR, "Can't establish DTLS connection to %s", + sock_addr2str(sa)); + close(sockfd); + return 0; + } + + + cw_dbg(DBG_DTLS, "DTLS Connection successful established with %s", + sock_addr2str(sa)); @@ -156,31 +169,35 @@ int run_join_d(struct sockaddr *sa) } -int run_join(struct conn * conn) +int run_join(struct conn *conn) { -// cw_init_request(conn, CW_MSG_JOIN_REQUEST); -// if ( cw_put_msg(conn, conn->req_buffer) == -1 ) -// return 0; +// cw_init_request(conn, CW_MSG_JOIN_REQUEST); +// if ( cw_put_msg(conn, conn->req_buffer) == -1 ) +// return 0; // -// conn_send_msg(conn, conn->req_buffer); +// conn_send_msg(conn, conn->req_buffer); - int rc = cw_send_request(conn,CW_MSG_JOIN_REQUEST); - if (!cw_rcok(rc) ) { - if (rc>0 ){ - cw_log(LOG_ERR,"Can't Join AC at %s, AC said: %d - %s.", - sock_addr2str(&conn->addr),rc,cw_strerror(rc)); - } - else{ - cw_log(LOG_ERR,"Can't Join AC at %s: %d - %s.", - sock_addr2str(&conn->addr),errno,cw_strerror(rc)); + int rc = cw_send_request(conn, CW_MSG_JOIN_REQUEST); + + + + if (!cw_rcok(rc)) { + if (rc > 0) { + cw_log(LOG_ERR, "Can't Join AC at %s, AC said: %d - %s.", + sock_addr2str(&conn->addr), rc, cw_strerror(rc)); + + } else { + cw_log(LOG_ERR, "Can't Join AC at %s: %d - %s.", + sock_addr2str(&conn->addr), errno, cw_strerror(rc)); } return 0; } - cw_dbg(DBG_ELEM,"Joined AC at %s, Join Result: %d - %s",sock_addr2str(&conn->addr),rc,cw_strresult(rc)); + cw_dbg(DBG_ELEM, "Joined AC at %s, Join Result: %d - %s", + sock_addr2str(&conn->addr), rc, cw_strresult(rc)); return 1; } @@ -189,34 +206,46 @@ int run_join(struct conn * conn) int join() { - struct conn * conn = get_conn(); + struct conn *conn = get_conn(); - cw_aciplist_t iplist = mbag_get_mavl(conn->local,CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST); - if (!iplist){ - cw_log(LOG_ERR,"No IPs to join controller."); + printf("Join\n"); + + cw_aciplist_t iplist = + mbag_get_mavl(conn->local, CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST); + if (!iplist) { + cw_log(LOG_ERR, "No IPs to join controller."); return 0; } - DEFINE_AVLITER(ii,iplist); - avliter_foreach(&ii){ - cw_acip_t * ip = avliter_get(&ii); + if (!mavl_get_count(iplist)){ + cw_log(LOG_ERR, "No IPs to join controller. IP list is empty."); + return 0; + } - cw_dbg(DBG_INFO,"Going to join CAWAP controller on %s",sock_addr2str(&ip->ip)); - int rc = run_join_d((struct sockaddr*)&ip->ip); - if (!rc) + DEFINE_AVLITER(ii, iplist); + avliter_foreach(&ii) { + + cw_acip_t *ip = avliter_get(&ii); + + cw_dbg(DBG_INFO, "Going to join CAWAP controller on %s", + sock_addr2str(&ip->ip)); + + int rc = run_join_d((struct sockaddr *) &ip->ip); + if (!rc) continue; rc = run_join(conn); - if (rc){ - conn->capwap_state=CW_STATE_CONFIGURE; + if (rc) { + conn->capwap_state = CW_STATE_CONFIGURE; return 1; } - - + + } + printf("Nudel\n"); + return 0; } -