More work on CW VM code ..
FossilOrigin-Name: 3b0cb324535527b32d0e938b03151c75f6100ca2059fc121e2c4d350a8caf8a4
This commit is contained in:
123
src/wtp/join.c
123
src/wtp/join.c
@ -12,6 +12,8 @@
|
||||
#include "capwap/cw_log.h"
|
||||
#include "capwap/sock.h"
|
||||
#include "capwap/dtls.h"
|
||||
#include "capwap/aciplist.h"
|
||||
#include "capwap/capwap_items.h"
|
||||
|
||||
/*
|
||||
#define acinfo_log acinfo_log_
|
||||
@ -88,8 +90,129 @@ acinfo.result_code=99;
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
int run_join_d(struct sockaddr *sa)
|
||||
{
|
||||
struct conn *conn = get_conn();
|
||||
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));
|
||||
return -1;
|
||||
}
|
||||
sock_set_recvtimeout(sockfd,1);
|
||||
|
||||
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));
|
||||
close(sockfd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
conn->sock=sockfd;
|
||||
sock_copyaddr(&conn->addr,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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
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));
|
||||
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
//
|
||||
// conn_send_msg(conn, conn->req_buffer);
|
||||
|
||||
int rc = cw_send_request(conn,CW_MSG_JOIN_REQUEST);
|
||||
|
||||
if (rc >=0 ) {
|
||||
cw_dbg(DBG_ELEM,"Join Result: %d - %s",rc,cw_strresult(rc));
|
||||
|
||||
}
|
||||
if (rc != 0 && rc != 2) {
|
||||
cw_log(LOG_ERR,"Join to %s was not successful.",sock_addr2str(&conn->addr));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int join()
|
||||
{
|
||||
struct conn * conn = get_conn();
|
||||
cw_aciplist_t iplist = cw_itemstore_get_avltree(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);
|
||||
|
||||
cw_dbg(DBG_ELEM,"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;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
int join(struct sockaddr *sa)
|
||||
{
|
||||
int sockfd;
|
||||
|
Reference in New Issue
Block a user