Working on mods.

FossilOrigin-Name: 5b47ebc4f08ac42b88471906357598a2155f3b7ae8eb0f4f843f6c05df155d46
This commit is contained in:
7u83@mail.ru 2016-02-23 18:38:10 +00:00
parent 82047233c0
commit 8b7f56ed38
17 changed files with 163 additions and 25 deletions

View File

@ -143,7 +143,18 @@ static int init_mods()
{
conf_mods[0]=cw_get_mod_ac("cipwap");
conf_mods[1]=NULL;
conf_mods[1]=cw_get_mod_ac("capwap");
conf_mods[2]=NULL;
int i;
for(i=0; conf_mods[i]; i++){
if (conf_mods[i]->init){
conf_mods[i]->init();
}
}
return 0;
}

View File

@ -189,6 +189,7 @@ DTLSOBJS+=dtls_bio.o
CONNOBJS= conn_create.o \
conn_process_packet.o \
conn_process_packet_x.o \
conn_q_add_packet.o \
conn_q_get_packet.o \
conn_q_recv_packet.o \
@ -291,6 +292,7 @@ CFLAGS += $(GNUTLS_CFLAGS) \
#SRCS = $(OBJS:.o=.c)
MODOBJS=$(wildcard ./mod/cipwap/$(ARCH)/*.o)
MODOBJS+=$(wildcard ./mod/capwap/$(ARCH)/*.o)
$(ARCH)/%.o:%.c
@mkdir -p $(ARCH)
@ -325,7 +327,6 @@ mod_cipwap:
$(MAKE) -C mod/cipwap
clean:
$(RM) $(ARCH)/*
# $(RM) $(OBJS)

View File

@ -19,7 +19,7 @@
/**
* @file
* @brief CAPWAP ACtions Header
* @defgroup ACTION CAPWAP/LWAP Actions
* @defgroup ACTION CAPWAP/LWAPP Actions
* @{
*/
#ifndef __ACTION_H

View File

@ -991,6 +991,10 @@ static inline int cw_rcok(int rc)
}
/**
*@defgroup CW CW
*@{
*/
static inline const char *cw_strelemp_(cw_strheap_t h, int msg_id)
{
@ -1000,6 +1004,8 @@ static inline const char *cw_strelemp_(cw_strheap_t h, int msg_id)
return cw_strheap_get(h, CW_STR_STOP);
}
/**@}*/
#define cw_strelemp(p,id) cw_strelemp_((p)->strelem,id)

View File

@ -173,12 +173,22 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
int i;
for (i=0; mods[i]; i++){
if (mods[i]->detect){
mods[i]->detect(conn,rawmsg,len,from);
if (mods[i]->detect(conn,rawmsg,len,from)){
cw_dbg(DBG_INFO,"Using mod '%s' to handle connection from %s",mods[i]->name,sock_addr2str(from));
break;
}
}
}
}
}
if (!conn->detected){
cw_dbg(DBG_INFO,"Cant't detect capwap, discarding message from %s",sock_addr2str(from));
errno=EAGAIN;
return -1;
}
/* prepare struct for search operation */

View File

@ -11,7 +11,7 @@ int static check_len(struct conn *conn, struct cw_action_in *a, uint8_t * data,
{
if (len < a->min_len) {
cw_dbg(DBG_ELEM_ERR,
"%d (%s) message element too short, lan=%d, min len=%d",
"%d (%s) message element too short, len=%d, min len=%d",
a->elem_id, cw_strelemp(conn->actions, a->elem_id), len,
a->min_len);
return 0;

View File

@ -59,4 +59,3 @@ char *cw_load_file(const char *filename, size_t * size)
fclose(infile);
return buf;
}

View File

@ -34,7 +34,6 @@
/**
* Debug strings
*/
struct cw_strlist_elem cw_dbg_strings[] = {
{ DBG_INFO, "info" },
{ DBG_PKT_IN, "pkt_in" },

View File

@ -1,7 +1,7 @@
/*!
\mainpage LIBCAWAP Documentation
\mainpage LIBCAPWAP Documentation
\section IBCAPWAPInstall Installing
\section LIBCAPWAPInstall Installing
To install libcapwap you need the following things:
A computer, a keyboard, some software and time.

View File

@ -27,16 +27,17 @@
/**
* Format bytes as hex string.
* @param dst destination buffer
* @param format format to use when writing a byte.
* @param delim delimiter
* @param src bytes to format
* @param len number of bytes to format
* @return the number character written to dst
* @param dst Destination buffer
* @param format Format to use, when writing a byte. Use the same format syntax as for printf,
* e.g. the string "%02X" would format a byte as upper case hexadeciaml string.
* @param delim Delimiter string. The given string is placed between bytes.
* @param src Bytes to format
* @param len Number of bytes to format
* @return the number of characters written to dst
*
* This function is used by macros like #cw_format_hexl, #cw_format_hex ... \n
* The size of the destination buffer must be at least x * len + strlen(delim) * (len-1) +1,
* where x is the number of characters a formatted hex byte needs (typically 2).
* where x is the number of characters. A formatted hex byte needs (typically 2).
*
*/
int cw_format_hex_bytes(char *dst, const char *format, const char *delim,

View File

@ -16,8 +16,12 @@
*/
/**
* @addtogroup Fragman
* @{
*/
/*
/**
* @file
* @brief This file implements a simple fragment management system for the capwap protocol.
*
@ -110,6 +114,14 @@ void fragman_free(frag_t * frags,struct frag * f)
}
*/
/**
* Add a fragment
* @pram frags Fragman object
* @param packet Pointer to data of the packet to add
* @param hlen Length of the header od the packet
* @param payloadlen Number of bytes in payload
* @return NULL if someting went wrong
*/
uint8_t * fragman_add(frag_t * frags, uint8_t *packet, int hlen, int payloadlen)
{
struct frag * f;
@ -200,3 +212,8 @@ void fragman_destroy(frag_t * frags)
free (frags);
}
/**
* @}
*/

View File

@ -17,6 +17,15 @@
*/
/**
*@defgroup Fragman FRAGMAN
*@breif Frgaman functions
*
* Detailed esription
*@{
*/
#ifndef __FRAGMAN_H
#define __FRAGMAN_H
@ -24,6 +33,7 @@
#include <time.h>
#ifndef FRAG_MAXSIZE
/** maximaum size of a fragment */
#define FRAG_MAXSIZE 65536+4
#endif
@ -61,5 +71,7 @@ extern void fragman_destroy(frag_t * frags);
extern void fragman_free(frag_t * frags,struct frag * f);
/**@}*/
#endif

View File

@ -50,7 +50,7 @@ struct mbag_typedef{
struct mbag_item * (*from_str)(const char *src);
};
/** The type for an mbag typedf */
/** The type for an mbag typedef */
typedef const struct mbag_typedef * mbagtype_t;
@ -59,24 +59,27 @@ typedef const struct mbag_typedef * mbagtype_t;
* The MBAG item
*/
struct mbag_item{
union {
uint32_t iid;
/**
* Key of this item
*
* This could be either a string (default) or an integer uint32_t value.
* If you whant to use with uint32_t keys, use the mbag_i_* functions, to
* create mbags.
*/
union {
uint32_t iid;
const char *id;
};
/** indicates if the key is dynamic oder static.
If dynamic, the id will be freed using free
if mbag_item is deleted */
/**
* Indicates if the key is dynamic oder static.
* If dynamic, the id will be freed using free,
* if mbag_item is deleted
*/
uint8_t dynid;
/** Type of this item */
const struct mbag_typedef * type;
/** Value of this item */
union {
/** Value of this item */
void *data;
uint8_t byte;
uint16_t word;

View File

@ -18,13 +18,17 @@ struct mod_ac
CAPWAP message. Either on Discovery Request or Join Request
**/
int (*detect)(struct conn *conn,const uint8_t *rawmsg, int rawlen,struct sockaddr *from);
/** used for private data */
void *data;
};
#include "mod/cipwap/mod_cipwap.h"
#include "mod/capwap/mod_capwap.h"
#define MODS_AC { mod_cipwap_ac,NULL }
#define MODS_AC { mod_capwap_ac,mod_cipwap_ac,NULL }
extern struct mod_ac * cw_get_mod_ac(const char *name);

View File

@ -0,0 +1,25 @@
include ../../../Macros.mak
include ../../../Config.mak
OBJS=\
mod_capwap_ac.o \
capwap_actions_ac.o
OBJS:=$(patsubst %.o,$(ARCH)/%.o,$(OBJS))
CFLAGS = -Wall -g -O0 -D_REENTRANT -DWITH_IPV6 -DWITH_RMAC_SUPPORT -I ../../../
SRCS = $(OBJS:.o=.c)
$(ARCH)/%.o:%.c
@mkdir -p $(ARCH)
@echo " CC "$<
@$(CC) -c $(CFLAGS) $< -o $@
all: $(OBJS)
clean:
rm -rf $(ARCH)

View File

@ -0,0 +1,6 @@
#ifndef __MOD_CAPWAP_H
#define __MOD_CAPWAP_H
struct mod_ac * mod_capwap_ac();
#endif

View File

@ -0,0 +1,44 @@
#include "capwap/mod.h"
#include "capwap/log.h"
#include "capwap/dbg.h"
#include "capwap/action.h"
#include "mod_capwap.h"
static struct cw_actiondef actions;
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);
return 0;
}
static int detect(struct conn *conn,const uint8_t *rawmsg, int rawlen,struct sockaddr *from)
{
cw_log(LOG_INFO,"Detecting ...");
conn->detected=1;
return 1;
}
static struct mod_ac capwap_ac = {
.name ="capwap",
.init = init,
.detect = detect
};
struct mod_ac * mod_capwap_ac(){
return &capwap_ac;
};