From 127bad2fb5bde4723d10acd922974e54450f0ee6 Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Thu, 10 May 2018 20:40:51 +0000 Subject: [PATCH] More work on data packets FossilOrigin-Name: bbc6d184bd9c0a39fbcd90c30acea864ee63114bed3392fc827138e04ad2fd4c --- src/ac/dataman.c | 7 ++++--- src/ac/shell.c | 4 ++++ src/ac/wtplist.c | 7 +++++-- src/ac/wtplist.h | 2 +- src/cw/conn.h | 3 ++- src/cw/connlist.c | 8 +++++++- src/mod/capwap/capwap_actions_ac.c | 8 ++++++++ src/mod/cisco/cisco_actions_ac.c | 16 ++++++++++++++-- 8 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/ac/dataman.c b/src/ac/dataman.c index 22b07aff..d01dc2e6 100644 --- a/src/ac/dataman.c +++ b/src/ac/dataman.c @@ -105,14 +105,15 @@ int dataman_process_keep_alive(struct netconn *nc, uint8_t *rawmsg, int len) cw_foreach_elem(elem, elems_ptr, elems_len) { if (cw_get_elem_id(elem) == CAPWAP_ELEM_SESSION_ID){ - uint8_t sessid[16]; + uint8_t sessid[64]; memset(sessid,0,16); int sessid_len = cw_get_elem_len(elem); printf("Sess id len = %d\n",sessid_len); - memcpy(sessid,cw_get_elem_data(elem),sessid_len); + ((uint16_t*)sessid)[0]=sessid_len; + memcpy(bstr16_data(sessid),cw_get_elem_data(elem),sessid_len); struct wtpman * wtpman = wtplist_get_by_session_id(sessid); if (wtpman){ @@ -123,7 +124,7 @@ int dataman_process_keep_alive(struct netconn *nc, uint8_t *rawmsg, int len) uint8_t * dl = cw_init_data_keep_alive_msg(buffer,NULL); uint8_t * d=dl+2; - int l = cw_put_elem_session_id(d,sessid,sessid_len); + int l = cw_put_elem_session_id(d,bstr16_data(sessid),sessid_len); cw_put_word(dl,l); int total_len = dl-buffer + l+2; diff --git a/src/ac/shell.c b/src/ac/shell.c index d9c29b9e..91789c57 100644 --- a/src/ac/shell.c +++ b/src/ac/shell.c @@ -16,6 +16,10 @@ #include "wtplist.h" + + + + void show_cfg (FILE *out, mavl_t ktv) { char value[500]; diff --git a/src/ac/wtplist.c b/src/ac/wtplist.c index 2481bcb4..246d4cb0 100644 --- a/src/ac/wtplist.c +++ b/src/ac/wtplist.c @@ -78,14 +78,17 @@ struct wtpman * wtplist_get(const struct sockaddr * addr) } -struct wtpman * wtplist_get_by_session_id(uint8_t *session_id) +struct wtpman * wtplist_get_by_session_id(bstr16_t *session_id) { struct conn search; struct conn * conn; - memcpy (search.session_id, session_id,16); + search.session_id = session_id; + /*memcpy (search.session_id, session_id,16);*/ conn = connlist_get_by_session_id(connlist,&search); + if (conn == NULL) + return NULL; return conn->data; } diff --git a/src/ac/wtplist.h b/src/ac/wtplist.h index c5373a1c..c6d950d3 100644 --- a/src/ac/wtplist.h +++ b/src/ac/wtplist.h @@ -13,7 +13,7 @@ extern struct wtpman * wtplist_add(struct wtpman * wtpman); extern void wtplist_remove(struct wtpman * wtpman); extern void wtplist_lock(); extern void wtplist_unlock(); -extern struct wtpman * wtplist_get_by_session_id(uint8_t *session_id); +extern struct wtpman * wtplist_get_by_session_id(bstr16_t *session_id); struct connlist * wtplist_get_connlist(void); #endif diff --git a/src/cw/conn.h b/src/cw/conn.h index c2f455a9..f62aa9f1 100644 --- a/src/cw/conn.h +++ b/src/cw/conn.h @@ -92,7 +92,8 @@ struct conn { mbag_t config_upd; */ - uint8_t session_id[16]; +/* uint8_t session_id[16];*/ + bstr16_t session_id; int role; diff --git a/src/cw/connlist.c b/src/cw/connlist.c index 2e425a3b..ed7a2516 100644 --- a/src/cw/connlist.c +++ b/src/cw/connlist.c @@ -57,7 +57,13 @@ static int cmp_by_session_id ( const void *d1, const void *d2 ) { struct conn * c1 = *( void ** ) d1; struct conn * c2 = *( void ** ) d2; - return memcmp ( c1->session_id, c2->session_id, 16 ); + int len1,len2; + len1 = bstr16_len(c1->session_id); + len2 = bstr16_len(c2->session_id); + + if (len1 != len2 ) + return len1-len2; + return memcmp ( bstr16_data(c1->session_id), bstr16_data(c2->session_id), len1 ); } /** diff --git a/src/mod/capwap/capwap_actions_ac.c b/src/mod/capwap/capwap_actions_ac.c index f5a3b96b..1d68b5c1 100644 --- a/src/mod/capwap/capwap_actions_ac.c +++ b/src/mod/capwap/capwap_actions_ac.c @@ -727,6 +727,14 @@ static struct cw_MsgDef messages[] = { static int postprocess_join_request(struct conn *conn) { + cw_KTV_t * result; + + result = cw_ktv_get(conn->remote_cfg,"session-id",CW_TYPE_BSTR16); + if (result != NULL){ + conn->session_id = result->val.ptr; + connlist_add_by_session_id(conn->connlist,conn); + } + return 1; } diff --git a/src/mod/cisco/cisco_actions_ac.c b/src/mod/cisco/cisco_actions_ac.c index ada2b335..40aff965 100644 --- a/src/mod/cisco/cisco_actions_ac.c +++ b/src/mod/cisco/cisco_actions_ac.c @@ -1745,10 +1745,19 @@ static cw_StateMachineState_t statemachine_states[]={ }; - +static int (*postprocess_join_request_parent)(struct conn * conn); struct cw_MsgSet * cisco_register_msg_set(struct cw_MsgSet * set, int mode){ - if (mode != CW_MOD_MODE_CAPWAP) + + struct cw_MsgData * md; + + if (mode != CW_MOD_MODE_CAPWAP) return NULL; + + md = cw_msgset_get_msgdata(set,CAPWAP_MSG_JOIN_REQUEST); + if (md != NULL){ + postprocess_join_request_parent = md->postprocess; + } + cw_msgset_add(set,messages, handlers73); cw_msgset_add_states(set,statemachine_states); return set; @@ -1791,6 +1800,9 @@ static int postprocess_discovery(struct conn *conn) static int postprocess_join_request(struct conn *conn) { + if (postprocess_join_request_parent!=NULL){ + postprocess_join_request_parent(conn); + } postprocess_discovery(conn); return 1; }