new mavl is working now

FossilOrigin-Name: 65a4eefffea57509c0d7fd573e53b15bf4a730ce297b7db182aaac796ea92448
bsdmakefiles
7u83@mail.ru 5 years ago
parent e4d65ef470
commit 4171d208d0
  1. 6
      ac.project
  2. 4
      actube.workspace
  3. 25
      libcw.project
  4. 712
      src/ac/ac_main.c
  5. 147
      src/ac/conf.c
  6. 4
      src/ac/dataman.c
  7. 1
      src/ac/wtplist.c
  8. 8
      src/ac/wtpman.c
  9. 12
      src/cw/aciplist.c
  10. 4
      src/cw/aciplist.h
  11. 4
      src/cw/acpriolist.c
  12. 10
      src/cw/action.c
  13. 13
      src/cw/conn_process_packet.c
  14. 121
      src/cw/connlist.c
  15. 2
      src/cw/cw.h
  16. 2
      src/cw/cw_in_ac_name_with_priority.c
  17. 7
      src/cw/cw_in_generic.c
  18. 13
      src/cw/cw_kvstore_mavl_delete.c
  19. 26
      src/cw/cw_kvt_add.c
  20. 6
      src/cw/cw_kvt_mavlcmp.c
  21. 15
      src/cw/cw_kvt_mavldel.c
  22. 2
      src/cw/cw_process_element.c
  23. 8
      src/cw/cw_read_descriptor_subelems.c
  24. 26
      src/cw/cw_read_wtp_descriptor.c
  25. 12
      src/cw/cw_read_wtp_descriptor_7.c
  26. 5
      src/cw/cw_strdup.c
  27. 0
      src/cw/cw_strnelem.c
  28. 50
      src/cw/cw_type_bstr16.c
  29. 22
      src/cw/cw_type_byte.c
  30. 22
      src/cw/cw_type_dword.c
  31. 22
      src/cw/cw_type_word.c
  32. 48
      src/cw/cw_types.h
  33. 6
      src/cw/cw_types_del_null.c
  34. 4
      src/cw/dbg.c
  35. 4
      src/cw/intavltree.c
  36. 4
      src/cw/item.c
  37. 15
      src/cw/kvstore.h
  38. 70
      src/cw/kvt.h
  39. 198
      src/cw/mavl.h
  40. 214
      src/cw/mavl_add.c
  41. 9
      src/cw/mavl_add_kv_byte.c
  42. 7
      src/cw/mavl_add_ptr.c
  43. 17
      src/cw/mavl_add_strdup.c
  44. 5
      src/cw/mavl_cmp_dword.c
  45. 5
      src/cw/mavl_cmp_kv.c
  46. 6
      src/cw/mavl_cmp_str.c
  47. 6
      src/cw/mavl_cmpstr.c
  48. 15
      src/cw/mavl_create.c
  49. 2
      src/cw/mavl_create_conststr.c
  50. 22
      src/cw/mavl_del.c
  51. 2
      src/cw/mavl_foreach.c
  52. 2
      src/cw/mavl_foreach_lr.c
  53. 7
      src/cw/mavl_free_bin.c
  54. 7
      src/cw/mavl_free_str.c
  55. 5
      src/cw/mavl_freeptr.c
  56. 6
      src/cw/mavl_get.c
  57. 2
      src/cw/mavl_get_node.c
  58. 8
      src/cw/mavl_get_ptr.c
  59. 8
      src/cw/mavl_merge.c
  60. 31
      src/cw/mavl_replace.c
  61. 10
      src/cw/mavliter_get.c
  62. 15
      src/cw/mavliter_get_ptr.c
  63. 11
      src/cw/mavliter_init.c
  64. 56
      src/cw/mavliter_next.c
  65. 3
      src/cw/mavliter_seek.c
  66. 10
      src/cw/mavliter_seek_set.c
  67. 10
      src/cw/mbag.c
  68. 33
      src/cw/md5sum.c
  69. 2
      src/cw/mlist.h
  70. 18
      src/cw/mod.c
  71. 2
      src/cw/mod.h
  72. 2
      src/cw/msget.h
  73. 126
      src/cw/msgset.c
  74. 4
      src/cw/stravltree.c
  75. 4
      src/cw/strheap.c
  76. 4
      src/mod/capwap/capwap_actions_ac.c
  77. 8
      src/mod/capwap/capwap_in_wtp_board_data.c
  78. 2
      src/mod/capwap/mod_capwap.h
  79. 4
      src/mod/cisco/cisco_actions_ac.c

@ -25,6 +25,8 @@
</VirtualDirectory>
<Description/>
<Dependencies/>
<Dependencies Name="Debug"/>
<Dependencies Name="Release"/>
<Settings Type="Executable">
<GlobalSettings>
<Compiler Options="" C_Options="" Assembler="">
@ -43,7 +45,7 @@
<ResourceCompiler Options="" Required="no"/>
<General OutputFile="" IntermediateDirectory="./" Command="$(WorkspacePath)/src/ac/actube" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(WorkspacePath)/src/ac/" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
<![CDATA[]]>
<![CDATA[LD_LIBRARY_PATH=../../lib]]>
</Environment>
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="no">
<DebuggerSearchPaths/>
@ -112,6 +114,4 @@
</Completion>
</Configuration>
</Settings>
<Dependencies Name="Debug"/>
<Dependencies Name="Release"/>
</CodeLite_Project>

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<CodeLite_Workspace Name="actube" Database="">
<Project Name="ac" Path="ac.project" Active="No"/>
<Project Name="ac" Path="ac.project" Active="Yes"/>
<Project Name="wtp" Path="wtp.project" Active="No"/>
<Project Name="mod_cipwap" Path="mod_cipwap.project" Active="No"/>
<Project Name="mod_capwap" Path="mod_capwap.project" Active="No"/>
<Project Name="mod_cisco" Path="mod_cisco.project" Active="No"/>
<Project Name="libcw" Path="libcw.project" Active="Yes"/>
<Project Name="libcw" Path="libcw.project" Active="No"/>
<Project Name="mod_capwap80211" Path="mod_capwap80211.project" Active="No"/>
<Project Name="mod_fortinet" Path="mod_fortinet.project" Active="No"/>
<BuildMatrix>

@ -224,7 +224,6 @@
<File Name="src/cw/fragman.c"/>
<File Name="src/cw/lwmsg.h"/>
<File Name="src/cw/cw_check_missing_mand.c"/>
<File Name="src/cw/cw_strnelem.c"/>
<File Name="src/cw/format_dot11_fc.c"/>
<File Name="src/cw/wtpinfo_lwreadelem_wtp_descriptor.c"/>
<File Name="src/cw/dbg_strings.c"/>
@ -289,8 +288,6 @@
<File Name="src/cw/capwap_strings_state.c"/>
<File Name="src/cw/cw_out_radio_info.c"/>
<File Name="src/cw/capwap_items.c"/>
<File Name="src/cw/message_set.c"/>
<File Name="src/cw/message_set.h"/>
<File Name="src/mod/cisco/mod_cisco.h"/>
<File Name="src/cw/cw_filename.c"/>
<File Name="src/cw/mdata.h"/>
@ -298,33 +295,33 @@
<File Name="src/cw/mdata_elem_new.c"/>
<File Name="src/cw/cw_type_byte.c"/>
<File Name="src/cw/cw_type_word.c"/>
<File Name="src/cw/cw_types.h"/>
<File Name="src/cw/cw_type_dword.c"/>
<File Name="src/cw/mavl_cmp_dword.c"/>
<File Name="src/cw/mavl_free_bin.c"/>
<File Name="src/cw/debug.h"/>
<File Name="src/cw/debug.c"/>
<File Name="src/cw/mavl_get_ptr.c"/>
<File Name="src/cw/mavl_add_strdup.c"/>
<File Name="src/cw/mavl_cmp_str.c"/>
<File Name="src/cw/mavliter_init.c"/>
<File Name="src/cw/mavl_add_ptr.c"/>
<File Name="src/cw/cw_format_dump.c"/>
<File Name="src/cw/cw_format_pkt_hdr.c"/>
<File Name="src/cw/mavl_cmp_kv.c"/>
<File Name="src/cw/mavl_add_kv_byte.c"/>
<File Name="src/cw/cw_types_mavl_delete.c"/>
<File Name="src/cw/cw_format_scan_hex_bytes.c"/>
<File Name="src/cw/cw_dbg_elem.c"/>
<File Name="src/cw/cw_kvstore_mavl_delete.c"/>
<File Name="src/cw/cw_format_version.c"/>
<File Name="src/cw/cw_strdup.c"/>
<File Name="src/cw/kvstore.h"/>
<File Name="src/cw/cw_kvstore_add.c"/>
<File Name="src/cw/cw_types_del_null.c"/>
<File Name="src/cw/cw_type_bstr16.c"/>
<File Name="src/cw/cw_process_element.c"/>
<File Name="src/cw/cw_result_is_ok.c"/>
<File Name="src/cw/mavliter_get.c"/>
<File Name="src/cw/kvt.h"/>
<File Name="src/cw/cw_kvt_mavlcmp.c"/>
<File Name="src/cw/cw_kvt_mavldel.c"/>
<File Name="src/cw/mavliter_get_ptr.c"/>
<File Name="src/cw/mavl_cmpstr.c"/>
<File Name="src/cw/mavl_freeptr.c"/>
<File Name="src/cw/msgset.c"/>
<File Name="src/cw/msget.h"/>
<File Name="src/cw/mavl_replace.c"/>
<File Name="src/cw/cw_kvt_add.c"/>
</VirtualDirectory>
</VirtualDirectory>
<Description/>

@ -52,208 +52,367 @@
int ac_run();
static void *alive_thread(void *data)
static void *alive_thread (void *data)
{
/* Ping the database every 5 seconds */
while (1) {
sleep(5);
sleep (5);
db_ping();
}
}
#include <getopt.h>
static int parse_args(int argc, char *argv[])
static int parse_args (int argc, char *argv[])
{
// int getopt_ret;
int option_index;
static struct option long_options[] = {
{"version", optional_argument, NULL, 'v'},
{0, 0, 0, 0}
};
int o;
while ((o = getopt_long(argc, argv, "v", long_options, &option_index)) != -1) {
while ( (o = getopt_long (argc, argv, "v", long_options, &option_index)) != -1) {
switch (o) {
case 0:
break;
case 'v':
printf("AC-Tube 0.01, %s\n", SYS_ARCH);
exit(0);
printf ("AC-Tube 0.01, %s\n", SYS_ARCH);
exit (0);
}
}
return 0;
}
#include "cw/mod.h"
extern struct cw_Mod * cw_get_mod_ac(const char *name);
extern struct cw_Mod * cw_get_mod_ac (const char *name);
#include "cw/mlist.h"
extern void test_sets();
#include "cw/file.h"
#include "cw/cw_types.h"
#include "cw/kvt.h"
int main(int argc, char *argv[])
struct mykv {
int key;
int value;
};
int mycmp (void *e1, void *e2)
{
/* mavl_t kv;
mavliter_t kviter;
uint8_t bytes[] = { 99,4,5,7 };
struct mykv * k1 = e1;
struct mykv * k2 = e2;
//printf("My CMP: %d and %d\n", k1->key, k2->key);
kv = cw_types_mavl_create();
//mavl_cmp_kv,cw_type_delete);
mavldata_t data, *result;
if (k1->key > k2->key)
return 1;
if (k1->key < k2->key)
return -1;
return 0;
}
data.kv.key="wtp_board_data";
result = cw_type_byte.get(&data,bytes,1);
mavl_add(kv,result);
void mavl_walk (struct mavlnode * node)
{
struct mykv * kv;
data.kv.key="wtp_next_data";
result = cw_type_byte.get(&data,bytes+1,1);
mavl_add(kv,result);
mavliter_init(&kviter,kv);
mavliter_foreach(&kviter){
char value[500];
mavldata_t * data;
data = mavliter_get(&kviter);
struct cw_Type * type = data->kv.priv;
type->to_str(data,value,0);
printf("Got %s (%s): %s\n",data->kv.key,type->name, value);
if (!node) {
printf ("\n");
return;
}
kv = mavlnode_dataptr (node);
printf ("KV %d\n", kv->key);
printf ("go left:");
mavl_walk (node->left);
printf ("go right:");
mavl_walk (node->right);
}
mavl_destroy(kv);
exit(0);
*/
int stcmp (const void * sa1, const void *sa2)
{
const char **s1 = sa1;
const char **s2 = sa2;
int rc;
rc = strcmp (*s1, *s2);
printf ("CMP %s, %s = %d\n", *s1, *s2, rc);
return rc;
}
/* cw_log_init();
cw_log(LOG_ERROR,"Hello Debug World222");
exit(0);
*/
/*
char * dump_data = "Eine kleine Mickey Maus zog sich mal die Hosen\
aus, zog sie wieder an, und du bist dran. Dran bist du noch lange nicht\
musst erst sagen, wie alt du bist.";
int main (int argc, char *argv[])
{
mavl_t tree;
int i;
mavliter_t it;
char * result = cw_format_dump(dump_data,strlen(dump_data),NULL);
printf("Dump Result:\n%s\n", result);
exit(0);
*/
/*tree = mavl_create_ptr( (int(*)(const void*,const void*))strcmp,free);
*/
/* char data[100];
mavl_t im;
mavldata_t * val, * val2,itt, itt2, * result, search ;
mavliter_t myit;
/*
tree = mavl_create_ptr(mycmp,NULL);
im = mavl_create(mavl_cmp_dword,NULL);
itt.dword = 7;
itt2.dword = 7;
struct mykv * mdata;
val = mavl_add(im,&itt);
val2 = mavl_add(im,&itt2);
mdata = malloc(sizeof(struct mykv));
mdata->key=14;
mdata->value=15;
mavl_add_ptr(tree, mdata);
search.dword = 7;
result = mavl_get(im,&search);
printf("Result: (%p, %p) (%p, %p) (%p, %p)\n",val, &itt, val2, &itt2, result, &search);
mdata = malloc(sizeof(struct mykv));
mdata->key=16;
mdata->value=17;
mavl_add_ptr(tree, mdata);
mdata = malloc(sizeof(struct mykv));
mdata->key=12;
mdata->value=13;
mavl_add_ptr(tree, mdata);
mavliter_init(&it,tree);
mavliter_foreach(&it){
mdata = mavliter_get_ptr(&it);
printf("MAVLIT: %d %d\n",mdata->key,mdata->value);
struct mykv search;
search.key=mdata->key;
mdata = mavl_get_ptr(tree,&search);
printf("Search T: %d %d\n",mdata->key,mdata->value);
}
exit(0);
*/
/*
if (tree==NULL)
return 0;
exit(0);
tree = mavl_create_str();
mavl_add_str(tree,cw_strdup("7u83"));
mavl_add_str(tree,cw_strdup("Herre"));
mavl_add_str(tree,cw_strdup("Tube"));
mavl_add_str(tree,cw_strdup("Tobias"));
printf("Count: %d\n", mavl_get_count(tree));
mavliter_init(&it,tree);
for (itt.dword=100; itt.dword>0; itt.dword--){
printf("Copunting: %d\n",itt.dword);
mavl_add(im,&itt);
mavliter_foreach(&it){
printf("iterWert %s\n",mavliter_get_str(&it));
}
*/
/*
tree = mavl_create (mycmp, NULL, sizeof (struct mykv));
struct mykv nwert;
int result;
struct mykv * mr;
nwert.key = 7;
nwert.value = 777;
mr = mavl_add_exists (tree, &nwert, &result);
printf ("7Result %d: %d %d\n", result, mr->key, mr->value);
for (i = 0; i < 10; i++) {
//cw_rand(&nwert.key,sizeof(nwert.key));
// printf("Addwert: %u\n",nwert.key);
// printf("add %u\n", i);
nwert.key = 9 - i;
nwert.value = 100 + i;
result=0;
mr = mavl_add_exists (tree, &nwert, &result);
printf ("Result %d: %d %d\n", result, mr->key, mr->value);
}
mavliter_init(&myit,im);
mavliter_foreach(&myit){
union mavldata * result;
result = mavliter_get(&myit);
printf("Got Value %d\n",result->dword);
mavliter_init (&it, tree);
mavliter_foreach (&it) {
struct mykv *kv;
kv = mavliter_get (&it);
printf ("iterWert %u\n", kv->key);
}
mavl_destroy(im);
exit (0);
*/
/* mavl_t kv;
mavliter_t kviter;
uint8_t bytes[] = { 99,4,5,7 };
kv = cw_types_mavl_create();
//mavl_cmp_kv,cw_type_delete);
mavldata_t data, *result;
data.kv.key="wtp_board_data";
result = cw_type_byte.get(&data,bytes,1);
mavl_add(kv,result);
data.kv.key="wtp_next_data";
result = cw_type_byte.get(&data,bytes+1,1);
mavl_add(kv,result);
mavliter_init(&kviter,kv);
mavliter_foreach(&kviter){
char value[500];
mavldata_t * data;
data = mavliter_get(&kviter);
struct cw_Type * type = data->kv.priv;
type->to_str(data,value,0);
printf("Got %s (%s): %s\n",data->kv.key,type->name, value);
}
mavl_destroy(kv);
exit(0);
*/
/* cw_log_init();
cw_log(LOG_ERROR,"Hello Debug World222");
exit(0);
*/
/*
char * dump_data = "Eine kleine Mickey Maus zog sich mal die Hosen\
aus, zog sie wieder an, und du bist dran. Dran bist du noch lange nicht\
musst erst sagen, wie alt du bist.";
char * result = cw_format_dump(dump_data,strlen(dump_data),NULL);
printf("Dump Result:\n%s\n", result);
exit(0);
*/
/* char data[100];
mavl_t im;
mavldata_t * val, * val2,itt, itt2, * result, search ;
mavliter_t myit;
im = mavl_create(mavl_cmp_dword,NULL);
itt.dword = 7;
itt2.dword = 7;
val = mavl_add(im,&itt);
val2 = mavl_add(im,&itt2);
search.dword = 7;
result = mavl_get(im,&search);
printf("Result: (%p, %p) (%p, %p) (%p, %p)\n",val, &itt, val2, &itt2, result, &search);
exit(0);
for (itt.dword=100; itt.dword>0; itt.dword--){
printf("Copunting: %d\n",itt.dword);
mavl_add(im,&itt);
}
mavliter_init(&myit,im);
mavliter_foreach(&myit){
union mavldata * result;
result = mavliter_get(&myit);
printf("Got Value %d\n",result->dword);
}
mavl_destroy(im);
*/
int rc = 0;
/* parse arguments */
parse_args(argc, argv);
parse_args (argc, argv);
cw_log_name = "AC-Tube";
if (!read_config("ac.conf"))
if (!read_config ("ac.conf"))
return 1;
/* Show debug options if there are any set */
if (cw_dbg_opt_level)
cw_log(LOG_INFO, "Debug Options: %08X", cw_dbg_opt_level);
cw_log (LOG_INFO, "Debug Options: %08X", cw_dbg_opt_level);
/* XXX Hard coded debug settigns, set it by config in the future */
cw_dbg_opt_display = DBG_DISP_ASC_DMP | DBG_DISP_COLORS;
/* Warn, if the "secret" debugging feature for
/* Warn, if the "secret" debugging feature for
developers is turned on ;) */
// DBGX("Attention! %s", "DBG X is ON!");
// cw_mod_set_mod_path("../../lib/actube");
//cw_mod_load("capwap");
/* Initialize the database */
if (!db_init())
goto errX;
/* Start the database */
if (!db_start())
goto errX;
db_ping();
/* Start a database "pinger thread", which inserts
every xx seconds a timestamp into the DB */
pthread_t alth;
pthread_create(&alth, NULL, alive_thread, NULL);
pthread_create (&alth, NULL, alive_thread, NULL);
/* Init DTLS library */
dtls_init();
ac_global_init();
if (!socklist_init())
goto errX;
if (!wtplist_init())
goto errX;
if (!dataman_list_init())
goto errX;
cw_log(LOG_INFO, "Starting AC-Tube, Name=%s, ID=%s", conf_acname, conf_acid);
cw_log (LOG_INFO, "Starting AC-Tube, Name=%s, ID=%s", conf_acname, conf_acid);
rc = ac_run();
errX:
errX:
/* XXX There is more cleanup to do */
wtplist_destroy();
socklist_destroy();
@ -266,297 +425,315 @@ int main(int argc, char *argv[])
void process_ctrl_packet(int index, struct sockaddr *addr, uint8_t * buffer, int len);
void process_ctrl_packet (int index, struct sockaddr *addr, uint8_t * buffer, int len);
void process_cw_data_packet(int index, struct sockaddr *addr, uint8_t * buffer, int len);
void process_cw_data_packet (int index, struct sockaddr *addr, uint8_t * buffer, int len);
int ac_run()
{
if (!conf_listen_addrs_len) {
cw_log(LOG_ERR, "Fatal error: No listen addresses found.");
cw_log (LOG_ERR, "Fatal error: No listen addresses found.");
return 1;
}
/* it is important to create the unicast sockets first,
* because when we create the mcast an bcast sockets next
/* it is important to create the unicast sockets first,
* because when we create the mcast an bcast sockets next
* we will look for already created sockets to find a
* good unicast reply socket */
int i;
for (i = 0; i < conf_listen_addrs_len; i++) {
char addr[100];
char port[50];
int proto;
conf_parse_listen_addr(conf_listen_addrs[i], addr, port, &proto);
conf_parse_listen_addr (conf_listen_addrs[i], addr, port, &proto);
//struct sockaddr sa;
socklist_add_unicast(addr, port,proto);
socklist_add_unicast (addr, port, proto);
//#ifdef WITH_LWAPP
// if (conf_lwapp)
// socklist_add_unicast(conf_listen_addrs[i], conf_lw_control_port,
// AC_PROTO_LWAPP);
//#endif
}
if (socklist_len == 0) {
cw_log(LOG_ERR, "Fatal error: Could not setup any listen socket");
cw_log (LOG_ERR, "Fatal error: Could not setup any listen socket");
return 1;
}
/* create multicast sockets */
for (i = 0; i < conf_mcast_groups_len; i++) {
socklist_add_multicast(conf_mcast_groups[i], conf_control_port,
AC_PROTO_CAPWAP);
socklist_add_multicast (conf_mcast_groups[i], conf_control_port,
AC_PROTO_CAPWAP);
#ifdef WITH_LWAPP
if (conf_lwapp)
socklist_add_multicast(conf_mcast_groups[i], conf_lw_control_port,
AC_PROTO_LWAPP);
socklist_add_multicast (conf_mcast_groups[i], conf_lw_control_port,
AC_PROTO_LWAPP);
#endif
}
/* broadcast socket ipv4 only */
for (i = 0; i < conf_bcast_addrs_len; i++) {
char addr[50],port[50];
char addr[50], port[50];
int proto;
conf_parse_listen_addr(conf_bcast_addrs[i], addr, port, &proto);
socklist_add_broadcast(addr,port,proto);
conf_parse_listen_addr (conf_bcast_addrs[i], addr, port, &proto);
socklist_add_broadcast (addr, port, proto);
#ifdef WITH_LWAPP
// printf("Adding %d\n",socklist_len);
if (conf_lwapp)
socklist_add_broadcast(conf_bcast_addrs[i], conf_lw_control_port,
AC_PROTO_LWAPP);
socklist_add_broadcast (conf_bcast_addrs[i], conf_lw_control_port,
AC_PROTO_LWAPP);
// printf ("SI %d, PROTO: %d\n",socklist_len-1,socklist[socklist_len-1].ac_proto);
#endif
}
//get_acinfo();
while (1) {
/* prepare fdset */
fd_set fset;
int max = 0;
FD_ZERO(&fset);
FD_ZERO (&fset);
for (i = 0; i < socklist_len; i++) {
FD_SET(socklist[i].sockfd, &fset);
FD_SET (socklist[i].sockfd, &fset);
if (socklist[i].sockfd > max)
max = socklist[i].sockfd;
if (socklist[i].data_sockfd) {
FD_SET(socklist[i].data_sockfd,&fset);
FD_SET (socklist[i].data_sockfd, &fset);
if (socklist[i].sockfd > max)
max = socklist[i].sockfd;
}
}
/* wait for an event */
int n;
while ((n = select(max + 1, &fset, NULL, NULL, NULL)) < 0) {
while ( (n = select (max + 1, &fset, NULL, NULL, NULL)) < 0) {
if (errno != EINTR)
return n;
}
/* process the received packet */
for (i = 0; i < socklist_len; i++) {
uint8_t buffer[4096];
struct sockaddr_storage srcaddr;
socklen_t srcaddrlen;
if (FD_ISSET(socklist[i].data_sockfd, &fset)){
int len = sock_receive(socklist[i].data_sockfd,
buffer, sizeof(buffer),
0,
(struct sockaddr *) &srcaddr,
&srcaddrlen);
process_cw_data_packet(i, (struct sockaddr *) &srcaddr, buffer, len);
if (FD_ISSET (socklist[i].data_sockfd, &fset)) {
int len = sock_receive (socklist[i].data_sockfd,
buffer, sizeof (buffer),
0,
(struct sockaddr *) &srcaddr,
&srcaddrlen);
process_cw_data_packet (i, (struct sockaddr *) &srcaddr, buffer, len);
}
if (FD_ISSET(socklist[i].sockfd, &fset)){
int len = sock_receive(socklist[i].sockfd,
buffer, sizeof(buffer),
0,
(struct sockaddr *) &srcaddr,
&srcaddrlen);
process_ctrl_packet(i, (struct sockaddr *) &srcaddr, buffer, len);
if (FD_ISSET (socklist[i].sockfd, &fset)) {
int len = sock_receive (socklist[i].sockfd,
buffer, sizeof (buffer),
0,
(struct sockaddr *) &srcaddr,
&srcaddrlen);
process_ctrl_packet (i, (struct sockaddr *) &srcaddr, buffer, len);
}
}
}
return 0;
}
void process_cw_data_packet(int index, struct sockaddr *addr, uint8_t * buffer, int len)
void process_cw_data_packet (int index, struct sockaddr *addr, uint8_t * buffer, int len)
{
char sock_buf[SOCK_ADDR_BUFSIZE];
cw_dbg(DBG_X, "There is a data packet now");
cw_dbg (DBG_X, "There is a data packet now");
dataman_list_lock();
cw_dbg(DBG_X, "Dataman list locked, now getting");
struct dataman * dm = dataman_list_get(socklist[index].data_sockfd,addr);
cw_dbg(DBG_X, "Dataman list locked, now gotted");
cw_dbg(DBG_INFO,"Packet for dataman %s,%d",sock_addr2str_p(addr,sock_buf),socklist[index].data_sockfd);
cw_dbg (DBG_X, "Dataman list locked, now getting");
struct dataman * dm = dataman_list_get (socklist[index].data_sockfd, addr);
cw_dbg (DBG_X, "Dataman list locked, now gotted");
cw_dbg (DBG_INFO, "Packet for dataman %s,%d", sock_addr2str_p (addr, sock_buf), socklist[index].data_sockfd);
if (!dm) {
cw_dbg(DBG_INFO,"No dataman %s,%d",sock_addr2str_p(addr,sock_buf),socklist[index].data_sockfd);
dm = dataman_create(socklist[index].data_sockfd,addr);
if (!dm){
cw_log(LOG_ERR,"Can't create dataman for packet from %s",sock_addr2str_p(addr,sock_buf));
cw_dbg (DBG_INFO, "No dataman %s,%d", sock_addr2str_p (addr, sock_buf), socklist[index].data_sockfd);
dm = dataman_create (socklist[index].data_sockfd, addr);
if (!dm) {
cw_log (LOG_ERR, "Can't create dataman for packet from %s", sock_addr2str_p (addr, sock_buf));
return;
}
dataman_list_add(dm);
dataman_start(dm);
dataman_list_add (dm);
dataman_start (dm);
}
dataman_list_unlock();
dataman_add_packet(dm,buffer,len);
dataman_add_packet (dm, buffer, len);
return;
exit(0);
printf("Data packet received len = %d\n",len);
exit(0);
struct wtpman *wtpman = wtplist_get(addr);
if (!wtpman){
cw_dbg(DBG_PKT_ERR,"Discarding packet on data channel from %s - No wtpman found.",sock_addr2str(addr,sock_buf));
exit (0);
printf ("Data packet received len = %d\n", len);
exit (0);
struct wtpman *wtpman = wtplist_get (addr);
if (!wtpman) {
cw_dbg (DBG_PKT_ERR, "Discarding packet on data channel from %s - No wtpman found.", sock_addr2str (addr, sock_buf));
return;
}
wtpman_addpacket(wtpman, buffer, len);
wtpman_addpacket (wtpman, buffer, len);
}
void process_cw_ctrl_packet(int index, struct sockaddr *addr, uint8_t * buffer, int len)
void process_cw_ctrl_packet (int index, struct sockaddr *addr, uint8_t * buffer, int len)
{
char sock_buf[SOCK_ADDR_BUFSIZE];
/* first of all check preamble */
int preamble = cw_get_hdr_preamble(buffer);
int preamble = cw_get_hdr_preamble (buffer);
if (preamble != CAPWAP_PACKET_PREAMBLE && preamble != CAPWAP_DTLS_PACKET_PREAMBLE) {
cw_dbg(DBG_PKT_ERR,
"Discarding packet from %s, wrong preamble, preamble = 0x%01X",
sock_addr2str(addr,sock_buf), preamble);
cw_dbg (DBG_PKT_ERR,
"Discarding packet from %s, wrong preamble, preamble = 0x%01X",
sock_addr2str (addr, sock_buf), preamble);
return;
}
wtplist_lock();
struct wtpman *wtpman = wtplist_get(addr);
struct wtpman *wtpman = wtplist_get (addr);
if (!wtpman) {
wtpman = wtpman_create(index, addr);
wtpman = wtpman_create (index, addr);
if (!wtpman) {
cw_log(LOG_ERR, "Error creating wtpman: %s", strerror(errno));
cw_log (LOG_ERR, "Error creating wtpman: %s", strerror (errno));
wtplist_unlock();
return;
}
if (!wtplist_add(wtpman)) {
cw_log(LOG_ERR, "Error adding wtpman: Too many wtp connections");
wtpman_destroy(wtpman);
if (!wtplist_add (wtpman)) {
cw_log (LOG_ERR, "Error adding wtpman: Too many wtp connections");
wtpman_destroy (wtpman);
wtplist_unlock();
return;
};
wtpman_start(wtpman, preamble & 0xf);
wtpman_start (wtpman, preamble & 0xf);
}
wtpman_addpacket(wtpman, buffer, len);
wtpman_addpacket (wtpman, buffer, len);
wtplist_unlock();
}
void process_lw_ctrl_packet(int index, struct sockaddr *addr, uint8_t * buffer, int len)
void process_lw_ctrl_packet (int index, struct sockaddr *addr, uint8_t * buffer, int len)
{
//int sock = socklist[index].reply_sockfd;
uint8_t *m = buffer + 6;
uint32_t val = ntohl(*((uint32_t *) (m)));
printf("VAL: %08X\n", val);
uint32_t val = ntohl (* ( (uint32_t *) (m)));
printf ("VAL: %08X\n", val);
/* first of all check preamble */
int version = LWTH_GET_VERSION(m);
int version = LWTH_GET_VERSION (m);
if (version != LW_VERSION) {
// cw_log_debug1("Discarding LWAPP packet, wrong verson");
return;
}
int l = LWTH_GET_LENGTH(m);
printf("LEN = %d\n", l);
int l = LWTH_GET_LENGTH (m);
printf ("LEN = %d\n", l);
if (l + 12 != len) {
// cw_log_debug1("Discarding LWAPP packet, wrong length");
return;
}
wtplist_lock();
struct wtpman *wtpman = wtplist_get(addr);
struct wtpman *wtpman = wtplist_get (addr);
if (!wtpman) {
wtpman = wtpman_create(index, addr);
wtpman = wtpman_create (index, addr);
if (!wtpman) {
cw_log(LOG_ERR, "Error creating wtpman: %s", strerror(errno));
cw_log (LOG_ERR, "Error creating wtpman: %s", strerror (errno));
wtplist_unlock();
return;
}
if (!wtplist_add(wtpman)) {
cw_log(LOG_ERR, "Error adding wtpman: Too many wtp connections");
wtpman_destroy(wtpman);
if (!wtplist_add (wtpman)) {
cw_log (LOG_ERR, "Error adding wtpman: Too many wtp connections");
wtpman_destroy (wtpman);
wtplist_unlock();
return;
};
//wtpman_lw_start(wtpman);
}
//wtpman_lw_addpacket(wtpman,buffer,len);
wtplist_unlock();
}
@ -565,14 +742,15 @@ void process_lw_ctrl_packet(int index, struct sockaddr *addr, uint8_t * buffer,
void process_ctrl_packet(int index, struct sockaddr *addr, uint8_t * buffer, int len)
void process_ctrl_packet (int index, struct sockaddr *addr, uint8_t * buffer, int len)
{
switch (socklist[index].ac_proto) {
case AC_PROTO_CAPWAP:
process_cw_ctrl_packet(index, addr, buffer, len);
process_cw_ctrl_packet (index, addr, buffer, len);
return;
case AC_PROTO_LWAPP:
process_lw_ctrl_packet(index, addr, buffer, len);
process_lw_ctrl_packet (index, addr, buffer, len);
return;
}
}

@ -38,7 +38,6 @@ uint8_t conf_macaddress_len = 0;
long conf_strict_capwap = 1;
long conf_strict_headers = 0;
//char *conf_capwap_mode_str = NULL;
int conf_capwap_mode = CW_MODE_CAPWAP;
@ -79,8 +78,6 @@ char *conf_sslkeypass = NULL;
char *conf_sslcipher = NULL;
char *conf_dtls_psk = NULL;
//char * conf_ac_hardware_version=NULL;
//char * conf_ac_software_version=NULL;
int conf_security = 0;
long conf_vendor_id = CONF_DEFAULT_VENDOR_ID;
@ -92,11 +89,6 @@ bstr_t conf_cisco_hardware_version = NULL;
bstr_t conf_cisco_software_version = NULL;
//int conf_hardware_version_len=0;
//int conf_software_version_len=0;
int conf_use_loopback = 0;
long conf_debug_level = -1;
@ -140,7 +132,9 @@ static int init_acname()
static int init_acid()
{
int i;
char *s;
if (conf_acid != NULL)
return 1;
@ -165,11 +159,11 @@ static int init_acid()
return 0;
};
int i;
conf_acid = malloc(2 * conf_macaddress_len + 1);
char *s = conf_acid;
s = conf_acid;
for (i = 0; i < conf_macaddress_len; i++) {
s += sprintf(s, "%02X", conf_macaddress[i]);
@ -178,10 +172,13 @@ static int init_acid()
}
static int init_dtls()
{
if (conf_dtls_psk != NULL) {
// conf_security=CW_SECURITY_FLAGS_S;
/*
// conf_security=CW_SECURITY_FLAGS_S;
*/
}
return 1;
@ -260,17 +257,21 @@ static int init_control_port()
static int init_listen_addrs()
{
struct ifaddrs *ifap, *ifa;
int rc;
int ctr;
if (conf_listen_addrs != 0)
return 1;
struct ifaddrs *ifap, *ifa;
int rc = getifaddrs(&ifap);
rc = getifaddrs(&ifap);
if (rc == -1)
return 0;
/* count the addresses */
int ctr = 0;
ctr = 0;
for (ifa = ifap; ifa != 0; ifa = ifa->ifa_next) {
if (!ifa->ifa_addr)
continue;
@ -307,8 +308,7 @@ static int init_listen_addrs()
if (ifa->ifa_addr->sa_family == AF_INET && conf_ipv4) {
sock_addrtostr(ifa->ifa_addr, str, 100,0);
// printf("The converter has %s\n",str);
// *strchr(str, ':') = 0;
conf_listen_addrs[ctr] =
(char *) cw_setstr((uint8_t **) & conf_listen_addrs[ctr],
(uint8_t *) str, strlen(str));
@ -346,6 +346,7 @@ static char *conf_default_mcast_groups_ipv4[] = {
#ifdef WITH_IPV6
static char *conf_default_mcast_groups_ipv6[] = {
"ff01:0:0:0:0:0:0:18c",
/* "ff01:0:0:0:0:0:0:18c",
"ff02:0:0:0:0:0:0:18c%em0",
"ff03:0:0:0:0:0:0:18c",
@ -356,11 +357,8 @@ static char *conf_default_mcast_groups_ipv6[] = {
};
#endif
//#include "avltree"
//#include "cw/stravltree.h"
/*
static int add_bcast_addr(void *priv, void *addr)
{
printf("Callback Called\n");
@ -374,12 +372,17 @@ static int add_bcast_addr(void *priv, void *addr)
conf_bcast_addrs_len++;
return 1;
}
*/
/*
* Initialize broadcast addresses (ipv4 only)
*/
int init_bcast_addrs()
{
int rc;
char str[100];
struct ifaddrs *ifa0, *ifa;
mavl_t t;
mavliter_t it;
@ -389,17 +392,17 @@ int init_bcast_addrs()
if (!conf_ipv4)
return 1;
t = mavl_create(mavl_cmp_str,mavl_free_str);
if (!t)
t = mavl_create_str();
if (t==NULL)
return 0;
/* add the default broadast address */
mavl_add_strdup(t, "255.255.255.255");
mavl_add_str(t, cw_strdup("255.255.255.255"));
/* add all other local broadcast addresses */
struct ifaddrs *ifa0, *ifa;
int rc = getifaddrs(&ifa0);
rc = getifaddrs(&ifa0);
if (rc == -1)
return 0;
@ -421,24 +424,22 @@ int init_bcast_addrs()
if (sa->sa_family != AF_INET)
continue;
char str[100];
if (ifa->ifa_broadaddr) {
sock_addrtostr(ifa->ifa_broadaddr, str, 100,1);
*strchr(str, ':') = 0;
mavl_add_strdup(t, str);
mavl_add_str(t, cw_strdup(str));
}
}
conf_bcast_addrs = malloc(t->count * sizeof(char *));
//mavl_foreach_asc(t, add_bcast_addr, 0);
mavliter_init(&it,t);
mavliter_foreach(&it){
union mavldata * d;
d = mavliter_get(&it);
conf_bcast_addrs[conf_bcast_addrs_len] = strdup(d->str);
char * d;
d = mavliter_get_str(&it);
conf_bcast_addrs[conf_bcast_addrs_len] = cw_strdup(d);
if (conf_bcast_addrs[conf_bcast_addrs_len] != 0)
conf_bcast_addrs_len++;
@ -454,19 +455,23 @@ int init_bcast_addrs()
int init_mcast_groups()
{
if (conf_mcast_groups)
return 1;
int ctr;
int i;
int n = 0;
int n4 = 0, n6 = 0;
if (conf_mcast_groups)
return 1;
if (conf_ipv4) {
n4 = sizeof(conf_default_mcast_groups_ipv4) / sizeof(char *);
}
#ifdef WITH_IPV6
if (conf_ipv6) {
n6 = sizeof(conf_default_mcast_groups_ipv6) / sizeof(char *);
}
#endif
n = n4 + n6;
if (n == 0)
return 1;
@ -476,8 +481,8 @@ int init_mcast_groups()
return 0;
memset(conf_mcast_groups, 0, n * sizeof(char *));
int ctr = 0;
int i;
ctr = 0;
for (i = 0; i < n4; i++) {
uint8_t *g = (uint8_t *) conf_default_mcast_groups_ipv4[i];
conf_mcast_groups[ctr] =
@ -546,8 +551,8 @@ static int conf_read_dbg_level(cfg_t * cfg)
for (i = 0; i < n; i++) {
char *str = cfg_getnstr(cfg, name, i);
//int u = cw_log_str2dbglevel(str);
int b = cw_strlist_get_id(cw_dbg_strings, str); //cw_log_str2dbglevel(str);
int b = cw_strlist_get_id(cw_dbg_strings, str);
cw_dbg_set_level(b, 1);
@ -555,34 +560,9 @@ static int conf_read_dbg_level(cfg_t * cfg)
return 1;
}
struct cw_Mod ** conf_mods; //[10];
struct cw_Mod ** conf_mods;
char *conf_mods_dir = NULL;
static int init_mods()
{
/* conf_mods[0]=modload_ac("cisco");
conf_mods[1]=modload_ac("fortinet");
// conf_mods[2]=modload_ac("zyxel");
conf_mods[2]=modload_ac("cipwap");
conf_mods[3]=modload_ac("capwap");