Improved mod detection, also for bindings. detections are cached.
FossilOrigin-Name: bb2a4cd9c18aded4fa028aa8d385c811d7550a37ddaf3da17f90399315abf637
This commit is contained in:
parent
43401093ea
commit
be07b0aa0a
@ -195,7 +195,6 @@ DTLSOBJS+=dtls_bio.o
|
||||
|
||||
CONNOBJS= conn_create.o \
|
||||
conn_process_packet.o \
|
||||
conn_process_packet2.o \
|
||||
conn_q_add_packet.o \
|
||||
conn_q_get_packet.o \
|
||||
conn_q_recv_packet.o \
|
||||
@ -261,7 +260,8 @@ CWACTION=action.o \
|
||||
radio.o \
|
||||
cw_out_radio_info.o \
|
||||
capwap_items.o \
|
||||
item.o
|
||||
item.o \
|
||||
mod.o
|
||||
|
||||
# cw_process_msg.o \
|
||||
# item_strings.o \
|
||||
|
@ -117,7 +117,7 @@ struct cw_itemdef capwap_itemdefs[] = {
|
||||
|
||||
|
||||
|
||||
{CW_ITEM_AP_MODE_AND_TYPE,CW_ITEM_NONE,MBAG_WORD},
|
||||
//{CW_ITEM_AP_MODE_AND_TYPE,CW_ITEM_NONE,MBAG_WORD},
|
||||
|
||||
/* Board Data */
|
||||
{CW_ITEM_WTP_BOARD_DATA,CW_ITEM_NONE,MBAG_MBAG},
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "sock.h"
|
||||
|
||||
#include "stravltree.h"
|
||||
#include "mod.h"
|
||||
|
||||
|
||||
int conn_send_msg(struct conn *conn, uint8_t * rawmsg);
|
||||
@ -152,6 +153,78 @@ static int check_len(struct conn *conn, struct cw_action_in *a, uint8_t * data,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static struct mod_ac * detect_mod(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
int elems_len, struct sockaddr *from, int mode)
|
||||
{
|
||||
if (conn->mods) {
|
||||
struct mod_ac **mods = (struct mod_ac **) conn->mods;
|
||||
int i;
|
||||
for (i = 0; mods[i]; i++) {
|
||||
if (mods[i]->detect) {
|
||||
if (mods[i]->
|
||||
detect(conn, rawmsg, len, elems_len, from, mode)) {
|
||||
return mods[i];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return MOD_NULL;
|
||||
}
|
||||
|
||||
static struct cw_actiondef * load_mods(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
int elems_len, struct sockaddr *from)
|
||||
{
|
||||
|
||||
struct mod_ac * cmod = detect_mod(conn, rawmsg, len, elems_len, from, MOD_DETECT_CAPWAP);
|
||||
if (cmod == MOD_NULL) {
|
||||
cw_dbg(DBG_MSG_ERR, "Cant't find mod to handle connection from %s , discarding message",
|
||||
sock_addr2str_p(from));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct mod_ac * bmod = detect_mod(conn, rawmsg, len, elems_len, from, MOD_DETECT_BINDINGS);
|
||||
|
||||
cw_dbg(DBG_INFO,"Mods deteced: %s,%s",cmod->name,bmod->name);
|
||||
|
||||
struct cw_actiondef * ad = mod_cache_add(cmod,bmod);
|
||||
|
||||
return ad;
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
if (bindins_mod) {
|
||||
cw_dbg(DBG_INFO, "Using mod '%s' to handle CAWPAP for %s", mod->name,
|
||||
sock_addr2str_p(from));
|
||||
conn->detected=1;
|
||||
}
|
||||
else{
|
||||
// errno = EAGAIN;
|
||||
// return -1;
|
||||
}
|
||||
|
||||
|
||||
mod = detect_mod(conn, rawmsg, len, elems_len, from, MOD_DETECT_BINDINGS);
|
||||
if (mod) {
|
||||
cw_dbg(DBG_INFO, "Using bindings '%s' to handle %s", mod->name,
|
||||
sock_addr2str_p(from));
|
||||
conn->detected=1;
|
||||
}
|
||||
else{
|
||||
cw_dbg(DBG_MSG_ERR, "Cant't detect bindings ... for %s",
|
||||
sock_addr2str_p(from));
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
struct sockaddr *from)
|
||||
@ -198,30 +271,14 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
|
||||
|
||||
if (!conn->detected) {
|
||||
if (conn->mods) {
|
||||
struct mod_ac **mods = (struct mod_ac **) conn->mods;
|
||||
int i;
|
||||
for (i = 0; mods[i]; i++) {
|
||||
if (mods[i]->detect) {
|
||||
if (mods[i]->detect(conn, rawmsg, len, elems_len, from)) {
|
||||
cw_dbg(DBG_INFO,
|
||||
"Using mod '%s' to handle connection from %s",
|
||||
mods[i]->name,
|
||||
sock_addr2str(from));
|
||||
break;
|
||||
//struct mod_ac *mod;
|
||||
struct cw_actiondef * ad = load_mods(conn, rawmsg, len, elems_len, from);
|
||||
if (!ad) {
|
||||
cw_log(LOG_ERR,"Eror");
|
||||
errno=EAGAIN;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!conn->detected) {
|
||||
|
||||
cw_dbg(DBG_MSG_ERR, "Cant't detect capwap, discarding message from %s",
|
||||
sock_addr2str(from));
|
||||
// errno = EAGAIN;
|
||||
// return -1;
|
||||
conn->actions = ad;
|
||||
|
||||
}
|
||||
|
||||
@ -284,7 +341,7 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
/* Create an avltree to catch the found mandatory elements */
|
||||
conn->mand = stravltree_create();
|
||||
|
||||
int unrecognized=0;
|
||||
int unrecognized = 0;
|
||||
|
||||
/* iterate through message elements */
|
||||
cw_foreach_elem(elem, elems_ptr, elems_len) {
|
||||
@ -307,7 +364,7 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!check_len(conn,af,cw_get_elem_data(elem), elem_len,from)){
|
||||
if (!check_len(conn, af, cw_get_elem_data(elem), elem_len, from)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -336,8 +393,9 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
}
|
||||
|
||||
|
||||
if (unrecognized){
|
||||
cw_dbg(DBG_RFC,"Message has %d unrecognized message elements.",unrecognized);
|
||||
if (unrecognized) {
|
||||
cw_dbg(DBG_RFC, "Message has %d unrecognized message elements.",
|
||||
unrecognized);
|
||||
if (!result_code) {
|
||||
result_code = CW_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT;
|
||||
}
|
||||
|
87
src/cw/mod.c
Normal file
87
src/cw/mod.c
Normal file
@ -0,0 +1,87 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "action.h"
|
||||
#include "mavl.h"
|
||||
#include "dbg.h"
|
||||
|
||||
struct cache_item
|
||||
{
|
||||
const char *capwap;
|
||||
const char *bindings;
|
||||
struct cw_actiondef actions;
|
||||
|
||||
};
|
||||
|
||||
static struct mavl * cache = NULL;
|
||||
|
||||
static int mod_null_register_actions(struct cw_actiondef *def)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
struct mod_ac mod_null={
|
||||
.name="none",
|
||||
.register_actions=mod_null_register_actions
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
int cmp(const void *p1, const void *p2)
|
||||
{
|
||||
struct cache_item * c1 = (struct cache_item *)p1;
|
||||
struct cache_item * c2 = (struct cache_item *)p2;
|
||||
|
||||
int r;
|
||||
r = strcmp(c1->capwap,c2->capwap);
|
||||
if (r!=0)
|
||||
return r;
|
||||
|
||||
return strcmp(c1->bindings,c2->bindings);
|
||||
|
||||
}
|
||||
|
||||
struct cw_actiondef * mod_cache_get(const char *capwap, const char *bindings)
|
||||
{
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct cw_actiondef * mod_cache_add(struct mod_ac *c, struct mod_ac *b)
|
||||
{
|
||||
if (!cache){
|
||||
cache = mavl_create(cmp,NULL);
|
||||
if (!cache)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct cache_item s;
|
||||
s.capwap=c->name;
|
||||
s.bindings=b->name;
|
||||
|
||||
struct cache_item * i = mavl_get(cache,&s);
|
||||
if (i){
|
||||
cw_dbg(DBG_INFO,"Using cached actions for %s,%s",c->name,b->name);
|
||||
return &(i->actions);
|
||||
}
|
||||
|
||||
|
||||
i = malloc(sizeof(struct cache_item));
|
||||
if (!i)
|
||||
return NULL;
|
||||
|
||||
cw_dbg(DBG_INFO,"Loading actions for %s,%s",c->name,b->name);
|
||||
memset (i,0,sizeof(struct cache_item));
|
||||
if (c){
|
||||
i->capwap=c->name;
|
||||
c->register_actions(&(i->actions));
|
||||
}
|
||||
if (b){
|
||||
i->bindings=b->name;
|
||||
b->register_actions(&(i->actions));
|
||||
}
|
||||
|
||||
mavl_add(cache,i);
|
||||
|
||||
return &(i->actions);
|
||||
|
||||
}
|
25
src/cw/mod.h
25
src/cw/mod.h
@ -28,23 +28,30 @@
|
||||
|
||||
struct cw_actiondef;
|
||||
|
||||
struct mod_ac
|
||||
{
|
||||
#define MOD_MAXMODS 8
|
||||
|
||||
enum {
|
||||
MOD_DETECT_CAPWAP,
|
||||
MOD_DETECT_BINDINGS
|
||||
};
|
||||
|
||||
struct mod_ac {
|
||||
/** Name of the mod */
|
||||
const char *name;
|
||||
/** Initializion method */
|
||||
int (*init)();
|
||||
int (*init) ();
|
||||
/** Detect capwap
|
||||
This function ifter receiving and disassembling a complete
|
||||
This function is called after receiving and disassembling a complete
|
||||
CAPWAP message. Either on Discovery Request or Join Request
|
||||
**/
|
||||
int (*detect)(struct conn *conn,const uint8_t *rawmsg, int rawlen,int elems_len, struct sockaddr *from);
|
||||
int (*detect) (struct conn * conn, const uint8_t * rawmsg, int rawlen,
|
||||
int elems_len, struct sockaddr * from, int mode);
|
||||
|
||||
/** used for private data */
|
||||
void *data;
|
||||
|
||||
/** Register actions */
|
||||
int (*register_actions)(struct cw_actiondef *def);
|
||||
int (*register_actions) (struct cw_actiondef * def);
|
||||
};
|
||||
|
||||
|
||||
@ -55,5 +62,11 @@ struct mod_ac
|
||||
#define mod_wtp mod_ac
|
||||
|
||||
|
||||
extern struct mod_ac mod_null;
|
||||
|
||||
#define MOD_NULL (&mod_null)
|
||||
|
||||
struct cw_actiondef * mod_cache_add(struct mod_ac *c, struct mod_ac *b);
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -296,6 +296,18 @@ static cw_action_in_t actions_in[] = {
|
||||
}
|
||||
,
|
||||
|
||||
{
|
||||
.capwap_state = CW_STATE_CONFIGURE,
|
||||
.msg_id = CW_MSG_CONFIGURATION_STATUS_REQUEST,
|
||||
.elem_id = CW_ELEM_RADIO_ADMINISTRATIVE_STATE,
|
||||
.item_id = CW_ITEM_RADIO_ADMINISTRATIVE_STATE,
|
||||
.start = cw_in_radio_administrative_state,
|
||||
.mand = 1
|
||||
|
||||
}
|
||||
,
|
||||
|
||||
|
||||
|
||||
|
||||
/* End of list */
|
||||
|
@ -325,7 +325,7 @@ static cw_action_out_t actions_out[] = {
|
||||
}
|
||||
,
|
||||
/* Radio Admin State - Config Status Request */
|
||||
/* {
|
||||
{
|
||||
.msg_id = CW_MSG_CONFIGURATION_STATUS_REQUEST,
|
||||
.item_id = CW_ITEM_RADIO_ADMINISTRATIVE_STATE,
|
||||
.out = cw_out_radio_administrative_states,
|
||||
@ -333,7 +333,7 @@ static cw_action_out_t actions_out[] = {
|
||||
.mand = 1
|
||||
}
|
||||
,
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -17,30 +17,30 @@ extern int capwap_register_actions_ac(struct cw_actiondef *def);
|
||||
|
||||
static int init()
|
||||
{
|
||||
cw_dbg(DBG_INFO,"Initialiazing mod_capwap ...");
|
||||
int rc = capwap_register_actions_ac(&actions);
|
||||
cw_dbg(DBG_INFO,"Initialized mod capwap with %d actions",rc);
|
||||
cw_dbg(DBG_INFO, "Initialiazing mod_capwap ...");
|
||||
// int rc = capwap_register_actions_ac(&actions);
|
||||
// cw_dbg(DBG_INFO, "Initialized mod capwap with %d actions", rc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int detect(struct conn *conn,const uint8_t *rawmsg, int rawlen,int elems_len,struct sockaddr *from)
|
||||
static int detect(struct conn *conn, const uint8_t * rawmsg, int rawlen, int elems_len,
|
||||
struct sockaddr *from, int mode)
|
||||
{
|
||||
cw_log(LOG_INFO,"Detecting ...");
|
||||
conn->detected=1;
|
||||
conn->actions=&actions;
|
||||
if (mode != MOD_DETECT_CAPWAP)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static struct mod_ac capwap_ac = {
|
||||
.name ="capwap",
|
||||
.name = "capwap",
|
||||
.init = init,
|
||||
.detect = detect,
|
||||
.register_actions = capwap_register_actions_ac
|
||||
|
||||
};
|
||||
|
||||
struct mod_ac * mod_capwap_ac(){
|
||||
struct mod_ac *mod_capwap_ac()
|
||||
{
|
||||
return &capwap_ac;
|
||||
};
|
||||
|
||||
|
@ -17,30 +17,33 @@ extern int capwap_register_actions_wtp(struct cw_actiondef *def);
|
||||
|
||||
static int init()
|
||||
{
|
||||
cw_dbg(DBG_INFO,"Initialiazing mod_capwap ...");
|
||||
cw_dbg(DBG_INFO, "Initialiazing mod_capwap ...");
|
||||
int rc = capwap_register_actions_wtp(&actions);
|
||||
cw_dbg(DBG_INFO,"Initialized mod capwap with %d actions",rc);
|
||||
cw_dbg(DBG_INFO, "Initialized mod capwap with %d actions", rc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int detect(struct conn *conn,const uint8_t *rawmsg, int rawlen,int elems_len,struct sockaddr *from)
|
||||
static int detect(struct conn *conn, const uint8_t * rawmsg, int rawlen, int elems_len,
|
||||
struct sockaddr *from, int mode)
|
||||
{
|
||||
cw_log(LOG_INFO,"Detecting ...");
|
||||
conn->detected=1;
|
||||
conn->actions=&actions;
|
||||
if (mode != MOD_DETECT_CAPWAP)
|
||||
return 0;
|
||||
|
||||
cw_log(LOG_INFO, "Detecting ...");
|
||||
conn->detected = 1;
|
||||
conn->actions = &actions;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static struct mod_wtp capwap_wtp = {
|
||||
.name ="capwap",
|
||||
.name = "capwap",
|
||||
.init = init,
|
||||
.detect = detect,
|
||||
.register_actions = capwap_register_actions_wtp
|
||||
|
||||
};
|
||||
|
||||
struct mod_wtp * mod_capwap_wtp(){
|
||||
struct mod_wtp *mod_capwap_wtp()
|
||||
{
|
||||
return &capwap_wtp;
|
||||
};
|
||||
|
||||
|
@ -12,8 +12,9 @@ int cipwap_init()
|
||||
}
|
||||
|
||||
|
||||
static int detect(struct conn *conn,const uint8_t *rawmsg, int rawlen,int elems_len, struct sockaddr *from)
|
||||
static int detect(struct conn *conn,const uint8_t *rawmsg, int rawlen,int elems_len, struct sockaddr *from, int mode)
|
||||
{
|
||||
|
||||
cw_log(LOG_INFO,"Detecting ...");
|
||||
return 0;
|
||||
}
|
||||
|
@ -19,22 +19,26 @@ extern int cisco_register_actions_ac(struct cw_actiondef *def);
|
||||
|
||||
static int init()
|
||||
{
|
||||
cw_dbg(DBG_INFO,"Initialiazing mod_cisco ...");
|
||||
struct mod_ac * cmod = modload_ac("capwap");
|
||||
cw_dbg(DBG_INFO, "Initialiazing mod_cisco ...");
|
||||
struct mod_ac *cmod = modload_ac("capwap");
|
||||
cmod->register_actions(&actions);
|
||||
if (!cmod ){
|
||||
cw_log(LOG_ERR,"Can't initzialize mod_cisco, failed to load bas mod mod_capwap");
|
||||
if (!cmod) {
|
||||
cw_log(LOG_ERR,
|
||||
"Can't initzialize mod_cisco, failed to load base mod mod_capwap");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int rc = cisco_register_actions_ac(&actions);
|
||||
cw_dbg(DBG_INFO,"Initialized mod cisco with %d actions",rc);
|
||||
cw_dbg(DBG_INFO, "Initialized mod cisco with %d actions", rc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int detect(struct conn *conn,const uint8_t *rawmsg, int rawlen,int elems_len,struct sockaddr *from)
|
||||
static int detect(struct conn *conn, const uint8_t * rawmsg, int rawlen, int elems_len,
|
||||
struct sockaddr *from, int mode)
|
||||
{
|
||||
if (mode != MOD_DETECT_CAPWAP)
|
||||
return 0;
|
||||
|
||||
int offset = cw_get_hdr_msg_offset(rawmsg);
|
||||
const uint8_t *msg_ptr = rawmsg + offset;
|
||||
@ -47,11 +51,10 @@ static int detect(struct conn *conn,const uint8_t *rawmsg, int rawlen,int elems_
|
||||
* specific payload Cisco identifier */
|
||||
cw_foreach_elem(elem, elems_ptr, elems_len) {
|
||||
int id = cw_get_elem_id(elem);
|
||||
if (id==CW_ELEM_VENDOR_SPECIFIC_PAYLOAD){
|
||||
if (id == CW_ELEM_VENDOR_SPECIFIC_PAYLOAD) {
|
||||
uint32_t vendor_id = cw_get_dword(cw_get_elem_data(elem));
|
||||
if (vendor_id==CW_VENDOR_ID_CISCO){
|
||||
conn->detected=1;
|
||||
conn->actions=&actions;
|
||||
if (vendor_id == CW_VENDOR_ID_CISCO) {
|
||||
conn->actions = &actions;
|
||||
return 1;
|
||||
|
||||
}
|
||||
@ -64,13 +67,13 @@ static int detect(struct conn *conn,const uint8_t *rawmsg, int rawlen,int elems_
|
||||
}
|
||||
|
||||
static struct mod_ac capwap_ac = {
|
||||
.name ="cisco",
|
||||
.name = "cisco",
|
||||
.init = init,
|
||||
.detect = detect
|
||||
|
||||
.detect = detect,
|
||||
.register_actions = cisco_register_actions_ac
|
||||
};
|
||||
|
||||
struct mod_ac * mod_cisco_ac(){
|
||||
struct mod_ac *mod_cisco_ac()
|
||||
{
|
||||
return &capwap_ac;
|
||||
};
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "cw/conn.h"
|
||||
#include "cw/log.h"
|
||||
#include "cw/mbag.h"
|
||||
#include "cw/capwap_items.h"
|
||||
|
||||
#include "wtp_interface.h"
|
||||
#include "cfg.h"
|
||||
@ -14,9 +15,11 @@ int configure()
|
||||
|
||||
mbag_del_all(conn->incomming);
|
||||
|
||||
int rc = cw_send_request(conn, CW_MSG_CONFIGURATION_STATUS_REQUEST);
|
||||
printf("Putting AC NAME\n");
|
||||
mbag_set_str(conn->local,CW_ITEM_AC_NAME,"abc");
|
||||
|
||||
printf("Configure RC: %d\n",rc);
|
||||
|
||||
int rc = cw_send_request(conn, CW_MSG_CONFIGURATION_STATUS_REQUEST);
|
||||
|
||||
if (!cw_rcok(rc)) {
|
||||
if (rc > 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user