2014-07-11 22:12:11 +02:00
|
|
|
/*
|
|
|
|
This file is part of actube.
|
|
|
|
|
|
|
|
actube is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
libcapwap is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
#include <stdio.h>
|
2015-03-30 07:56:42 +02:00
|
|
|
#include <stdlib.h>
|
2015-10-18 10:14:33 +02:00
|
|
|
#include <unistd.h>
|
2014-07-11 22:12:11 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdint.h>
|
2018-03-17 12:32:40 +01:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
#include "actube.h"
|
|
|
|
#include "wtplist.h"
|
2016-03-03 20:46:20 +01:00
|
|
|
#include "cw/dtls.h"
|
|
|
|
#include "cw/log.h"
|
|
|
|
#include "cw/dbg.h"
|
|
|
|
#include "cw/sock.h"
|
2015-10-18 10:14:33 +02:00
|
|
|
#include "conf.h"
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
#include "socklist.h"
|
|
|
|
|
2014-08-25 22:38:52 +02:00
|
|
|
#include "db.h"
|
2018-03-17 18:01:17 +01:00
|
|
|
|
|
|
|
|
2016-03-03 20:46:20 +01:00
|
|
|
#include "cw/capwap_crypto.h"
|
2018-03-17 18:01:17 +01:00
|
|
|
|
2015-04-29 12:22:28 +02:00
|
|
|
|
2015-03-30 07:56:42 +02:00
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
#include "ac.h"
|
2016-03-03 20:46:20 +01:00
|
|
|
#include "cw/format.h"
|
2015-03-30 07:56:42 +02:00
|
|
|
|
2016-04-10 16:04:58 +02:00
|
|
|
|
|
|
|
#include "dataman.h"
|
|
|
|
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
int ac_run();
|
|
|
|
|
2015-04-29 12:22:28 +02:00
|
|
|
|
2018-03-11 00:56:41 +01:00
|
|
|
static void *alive_thread (void *data)
|
2014-08-25 22:38:52 +02:00
|
|
|
{
|
2015-04-29 12:22:28 +02:00
|
|
|
/* Ping the database every 5 seconds */
|
2015-10-18 10:14:33 +02:00
|
|
|
while (1) {
|
2018-03-11 00:56:41 +01:00
|
|
|
sleep (5);
|
2014-08-25 22:38:52 +02:00
|
|
|
db_ping();
|
|
|
|
}
|
2018-04-02 21:00:37 +02:00
|
|
|
return NULL;
|
2014-08-25 22:38:52 +02:00
|
|
|
}
|
|
|
|
|
2016-03-27 04:46:30 +02:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
#include <getopt.h>
|
2018-03-17 12:32:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct bootcfg {
|
|
|
|
const char * cfgfilename;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int parse_args (int argc, char *argv[], struct bootcfg * bootcfg)
|
2015-04-07 07:42:36 +02:00
|
|
|
{
|
2018-03-17 12:32:40 +01:00
|
|
|
int c;
|
|
|
|
opterr = 1;
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2018-03-17 12:32:40 +01:00
|
|
|
bootcfg->cfgfilename = "config.ktv";
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2018-03-17 12:32:40 +01:00
|
|
|
while ( (c = getopt (argc, argv, "vc:d:p:")) != -1) {
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case 'c':
|
|
|
|
bootcfg->cfgfilename = optarg;
|
2015-10-18 10:14:33 +02:00
|
|
|
break;
|
|
|
|
case 'v':
|
2018-03-17 12:32:40 +01:00
|
|
|
printf("AC-Tube version 0.0.1, %s\n", SYS_ARCH);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
break;
|
|
|
|
case 'd':{
|
|
|
|
int b = cw_strlist_get_id(cw_dbg_strings, optarg);
|
|
|
|
if (b==-1){
|
|
|
|
fprintf(stderr,"Invalid debug option: %s\n",optarg);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
cw_dbg_set_level(b, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'p':
|
|
|
|
cw_mod_set_path(optarg);
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
default:
|
|
|
|
case 'h':
|
|
|
|
printf("%s: -vcmh\n",argv[0]);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
break;
|
2015-10-18 10:14:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2015-05-01 12:50:28 +02:00
|
|
|
}
|
|
|
|
|
2016-02-22 09:18:35 +01:00
|
|
|
|
2018-03-17 12:32:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-03 20:46:20 +01:00
|
|
|
#include "cw/mod.h"
|
2018-03-11 00:56:41 +01:00
|
|
|
extern struct cw_Mod * cw_get_mod_ac (const char *name);
|
2016-02-22 09:18:35 +01:00
|
|
|
|
2016-03-03 20:46:20 +01:00
|
|
|
#include "cw/mlist.h"
|
2016-02-28 13:41:45 +01:00
|
|
|
|
|
|
|
|
2018-02-24 00:30:44 +01:00
|
|
|
extern void test_sets();
|
2018-02-26 12:21:50 +01:00
|
|
|
#include "cw/file.h"
|
2018-03-12 11:22:06 +01:00
|
|
|
#include "cw/ktv.h"
|
2018-02-24 00:30:44 +01:00
|
|
|
|
2018-03-03 08:15:19 +01:00
|
|
|
|
2018-03-11 00:56:41 +01:00
|
|
|
struct mykv {
|
|
|
|
int key;
|
|
|
|
int value;
|
|
|
|
};
|
|
|
|
|
|
|
|
int mycmp (void *e1, void *e2)
|
2015-10-18 10:14:33 +02:00
|
|
|
{
|
2018-03-11 00:56:41 +01:00
|
|
|
struct mykv * k1 = e1;
|
|
|
|
struct mykv * k2 = e2;
|
2018-03-05 20:39:15 +01:00
|
|
|
|
2018-03-26 15:11:57 +02:00
|
|
|
/*//printf("My CMP: %d and %d\n", k1->key, k2->key);
|
|
|
|
*/
|
2018-03-11 00:56:41 +01:00
|
|
|
if (k1->key > k2->key)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (k1->key < k2->key)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-03-05 20:39:15 +01:00
|
|
|
|
2018-03-11 00:56:41 +01:00
|
|
|
void mavl_walk (struct mavlnode * node)
|
|
|
|
{
|
|
|
|
struct mykv * kv;
|
2018-03-05 20:39:15 +01:00
|
|
|
|
2018-03-11 00:56:41 +01:00
|
|
|
if (!node) {
|
|
|
|
printf ("\n");
|
|
|
|
return;
|
2018-03-05 20:39:15 +01:00
|
|
|
}
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
kv = mavlnode_dataptr (node);
|
|
|
|
printf ("KV %d\n", kv->key);
|
|
|
|
|
|
|
|
printf ("go left:");
|
|
|
|
mavl_walk (node->left);
|
|
|
|
printf ("go right:");
|
|
|
|
mavl_walk (node->right);
|
|
|
|
|
|
|
|
}
|
2018-03-05 20:39:15 +01:00
|
|
|
|
2018-04-02 18:19:28 +02:00
|
|
|
/*
|
2018-03-11 00:56:41 +01:00
|
|
|
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;
|
|
|
|
}
|
2018-04-02 18:19:28 +02:00
|
|
|
*/
|
2018-04-02 21:00:37 +02:00
|
|
|
/*
|
2018-04-02 18:19:28 +02:00
|
|
|
static int ibcmp(const void *v1, const void *v2)
|
|
|
|
{
|
|
|
|
int *i1,*i2;
|
|
|
|
i1=v1;i2=v2;
|
|
|
|
|
|
|
|
return *i1-*i2;
|
|
|
|
}
|
2018-04-02 21:00:37 +02:00
|
|
|
*/
|
2018-03-17 12:32:40 +01:00
|
|
|
|
2018-04-02 21:00:37 +02:00
|
|
|
#include "discovery_cache.h"
|
2018-04-02 18:19:28 +02:00
|
|
|
void tester1()
|
|
|
|
{
|
2018-04-02 21:00:37 +02:00
|
|
|
struct cw_DiscoveryCache * cache;
|
|
|
|
struct sockaddr_storage addr;
|
|
|
|
int rc;
|
|
|
|
const char *c,*b;
|
2018-04-02 18:19:28 +02:00
|
|
|
|
2018-04-02 21:00:37 +02:00
|
|
|
cache = discovery_cache_create(1);
|
2018-04-02 18:19:28 +02:00
|
|
|
|
2018-04-02 21:00:37 +02:00
|
|
|
sock_strtoaddr("192.168.0.12:1234",(struct sockaddr*)&addr);
|
|
|
|
discovery_cache_add(cache,(struct sockaddr*)&addr,"Nase","Loeffel");
|
2018-04-02 18:19:28 +02:00
|
|
|
|
2018-04-02 21:00:37 +02:00
|
|
|
sock_strtoaddr("192.168.0.13:1234",(struct sockaddr*)&addr);
|
|
|
|
discovery_cache_add(cache,(struct sockaddr*)&addr,"Nase","Loeffel");
|
2018-03-17 12:32:40 +01:00
|
|
|
|
2018-04-02 21:00:37 +02:00
|
|
|
|
|
|
|
rc = discovery_cache_get(cache,(struct sockaddr*)&addr,&c,&b);
|
|
|
|
|
|
|
|
if (rc) {
|
|
|
|
printf("RC: %d, %s %s\n",rc,c,b);
|
|
|
|
}
|
2018-04-02 18:19:28 +02:00
|
|
|
}
|
2018-03-17 12:32:40 +01:00
|
|
|
|
|
|
|
|
2018-03-11 00:56:41 +01:00
|
|
|
int main (int argc, char *argv[])
|
|
|
|
{
|
2018-03-17 12:32:40 +01:00
|
|
|
int rc = 0;
|
|
|
|
struct bootcfg bootcfg;
|
|
|
|
FILE * file;
|
|
|
|
mavl_t types_tree, global_cfg;
|
|
|
|
const cw_Type_t **ti;
|
2018-05-02 11:03:05 +02:00
|
|
|
|
2018-03-12 11:22:06 +01:00
|
|
|
|
2018-03-17 12:32:40 +01:00
|
|
|
/* parse arguments */
|
|
|
|
parse_args (argc, argv, &bootcfg);
|
|
|
|
|
|
|
|
/* open config file */
|
|
|
|
file = fopen(bootcfg.cfgfilename,"r");
|
|
|
|
if (file == NULL){
|
|
|
|
cw_log(LOG_ERR,"Cant open config file '%s': %s",
|
|
|
|
bootcfg.cfgfilename, strerror(errno));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create types tree with default types */
|
|
|
|
types_tree = cw_ktv_create_types_tree();
|
|
|
|
for (ti=CW_KTV_STD_TYPES;*ti;ti++){
|
|
|
|
mavl_add_ptr(types_tree,*ti);
|
2018-03-12 11:22:06 +01:00
|
|
|
}
|
2018-03-04 16:59:20 +01:00
|
|
|
|
2018-03-17 12:32:40 +01:00
|
|
|
global_cfg = cw_ktv_create();
|
|
|
|
if (global_cfg == NULL){
|
|
|
|
cw_log(LOG_ERR,"Can't create local_cfg: %s",strerror(errno));
|
|
|
|
exit(EXIT_FAILURE);
|
2018-03-11 10:34:20 +01:00
|
|
|
}
|
|
|
|
|
2018-03-17 12:32:40 +01:00
|
|
|
cw_ktv_read_file(file,global_cfg,types_tree);
|
|
|
|
|
|
|
|
fclose(file);
|
|
|
|
|
|
|
|
|
2018-03-21 18:50:07 +01:00
|
|
|
actube_global_cfg = global_cfg;
|
2018-03-17 12:32:40 +01:00
|
|
|
|
2018-04-03 07:35:55 +02:00
|
|
|
/* cw_dbg_opt_level=0xffffffff;*/
|
2018-03-21 20:01:36 +01:00
|
|
|
cw_dbg(DBG_INFO,"Hello world");
|
2018-03-17 12:32:40 +01:00
|
|
|
|
|
|
|
|
2018-03-21 20:01:36 +01:00
|
|
|
cw_dbg_ktv_dump(global_cfg,DBG_INFO,NULL,"CFG:",NULL);
|
2018-03-24 07:56:05 +01:00
|
|
|
|
|
|
|
/* int idx;
|
|
|
|
idx = cw_ktv_idx_get(global_cfg,"capwap-control-ip-address/address",0,CW_TYPE_IPADDRESS);
|
|
|
|
printf("IDX: %d\n");
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
*/
|
2015-10-18 10:14:33 +02:00
|
|
|
cw_log_name = "AC-Tube";
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
if (!read_config ("ac.conf"))
|
2018-02-18 21:46:45 +01:00
|
|
|
return 1;
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2018-05-02 11:03:05 +02:00
|
|
|
start_shell();
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-29 12:22:28 +02:00
|
|
|
/* Show debug options if there are any set */
|
2015-10-18 10:14:33 +02:00
|
|
|
if (cw_dbg_opt_level)
|
2018-03-11 00:56:41 +01:00
|
|
|
cw_log (LOG_INFO, "Debug Options: %08X", cw_dbg_opt_level);
|
|
|
|
|
2015-04-29 12:42:04 +02:00
|
|
|
/* XXX Hard coded debug settigns, set it by config in the future */
|
2015-10-18 10:14:33 +02:00
|
|
|
cw_dbg_opt_display = DBG_DISP_ASC_DMP | DBG_DISP_COLORS;
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
/* Warn, if the "secret" debugging feature for
|
2015-10-18 10:14:33 +02:00
|
|
|
developers is turned on ;) */
|
2018-03-26 15:11:57 +02:00
|
|
|
|
|
|
|
/*
|
2018-03-05 10:19:54 +01:00
|
|
|
// DBGX("Attention! %s", "DBG X is ON!");
|
2015-04-29 12:42:04 +02:00
|
|
|
|
2018-02-26 14:26:17 +01:00
|
|
|
// cw_mod_set_mod_path("../../lib/actube");
|
2018-03-03 08:15:19 +01:00
|
|
|
//cw_mod_load("capwap");
|
2018-03-26 15:11:57 +02:00
|
|
|
*/
|
2018-03-21 18:50:07 +01:00
|
|
|
|
|
|
|
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-29 12:22:28 +02:00
|
|
|
/* Initialize the database */
|
2015-10-18 10:14:33 +02:00
|
|
|
if (!db_init())
|
2015-04-29 12:22:28 +02:00
|
|
|
goto errX;
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
/* Start the database */
|
2015-04-29 12:22:28 +02:00
|
|
|
if (!db_start())
|
|
|
|
goto errX;
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2015-04-29 12:22:28 +02:00
|
|
|
db_ping();
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
|
2015-04-29 12:22:28 +02:00
|
|
|
/* Start a database "pinger thread", which inserts
|
|
|
|
every xx seconds a timestamp into the DB */
|
|
|
|
pthread_t alth;
|
2018-03-11 00:56:41 +01:00
|
|
|
pthread_create (&alth, NULL, alive_thread, NULL);
|
|
|
|
|
2015-04-29 12:42:04 +02:00
|
|
|
/* Init DTLS library */
|
|
|
|
dtls_init();
|
2018-04-02 21:00:37 +02:00
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
ac_global_init();
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
if (!socklist_init())
|
|
|
|
goto errX;
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
if (!wtplist_init())
|
|
|
|
goto errX;
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2016-04-10 16:04:58 +02:00
|
|
|
if (!dataman_list_init())
|
|
|
|
goto errX;
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
cw_log (LOG_INFO, "Starting AC-Tube, Name=%s, ID=%s", conf_acname, conf_acid);
|
2015-04-05 02:07:59 +02:00
|
|
|
rc = ac_run();
|
2018-03-11 00:56:41 +01:00
|
|
|
errX:
|
2015-04-29 19:23:52 +02:00
|
|
|
/* XXX There is more cleanup to do */
|
2014-07-11 22:12:11 +02:00
|
|
|
wtplist_destroy();
|
|
|
|
socklist_destroy();
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-11 00:56:41 +01:00
|
|
|
void process_ctrl_packet (int index, struct sockaddr *addr, uint8_t * buffer, int len);
|
2014-07-26 20:29:30 +02:00
|
|
|
|
2018-03-11 00:56:41 +01:00
|
|
|
void process_cw_data_packet (int index, struct sockaddr *addr, uint8_t * buffer, int len);
|
2014-07-26 20:29:30 +02:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
int ac_run()
|
|
|
|
{
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
if (!conf_listen_addrs_len) {
|
2018-03-11 00:56:41 +01:00
|
|
|
cw_log (LOG_ERR, "Fatal error: No listen addresses found.");
|
2014-07-11 22:12:11 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* it is important to create the unicast sockets first,
|
|
|
|
* because when we create the mcast an bcast sockets next
|
2014-07-11 22:12:11 +02:00
|
|
|
* we will look for already created sockets to find a
|
|
|
|
* good unicast reply socket */
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
int i;
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
for (i = 0; i < conf_listen_addrs_len; i++) {
|
2016-02-17 16:16:39 +01:00
|
|
|
char addr[100];
|
|
|
|
char port[50];
|
|
|
|
int proto;
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
conf_parse_listen_addr (conf_listen_addrs[i], addr, port, &proto);
|
|
|
|
|
|
|
|
socklist_add_unicast (addr, port, proto);
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
if (socklist_len == 0) {
|
2018-03-11 00:56:41 +01:00
|
|
|
cw_log (LOG_ERR, "Fatal error: Could not setup any listen socket");
|
2014-07-11 22:12:11 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
/* create multicast sockets */
|
2015-10-18 10:14:33 +02:00
|
|
|
for (i = 0; i < conf_mcast_groups_len; i++) {
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
socklist_add_multicast (conf_mcast_groups[i], conf_control_port,
|
|
|
|
AC_PROTO_CAPWAP);
|
2014-07-26 20:29:30 +02:00
|
|
|
#ifdef WITH_LWAPP
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
if (conf_lwapp)
|
2018-03-11 00:56:41 +01:00
|
|
|
socklist_add_multicast (conf_mcast_groups[i], conf_lw_control_port,
|
|
|
|
AC_PROTO_LWAPP);
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
#endif
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2016-02-16 08:13:34 +01:00
|
|
|
/* broadcast socket ipv4 only */
|
2015-10-18 10:14:33 +02:00
|
|
|
for (i = 0; i < conf_bcast_addrs_len; i++) {
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
char addr[50], port[50];
|
2016-02-17 20:25:19 +01:00
|
|
|
int proto;
|
2018-03-11 00:56:41 +01:00
|
|
|
conf_parse_listen_addr (conf_bcast_addrs[i], addr, port, &proto);
|
|
|
|
|
|
|
|
socklist_add_broadcast (addr, port, proto);
|
2014-07-26 20:29:30 +02:00
|
|
|
#ifdef WITH_LWAPP
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
// printf("Adding %d\n",socklist_len);
|
|
|
|
if (conf_lwapp)
|
2018-03-11 00:56:41 +01:00
|
|
|
socklist_add_broadcast (conf_bcast_addrs[i], conf_lw_control_port,
|
|
|
|
AC_PROTO_LWAPP);
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
// printf ("SI %d, PROTO: %d\n",socklist_len-1,socklist[socklist_len-1].ac_proto);
|
|
|
|
#endif
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-26 15:11:57 +02:00
|
|
|
/*//get_acinfo();*/
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
while (1) {
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
/* prepare fdset */
|
|
|
|
fd_set fset;
|
|
|
|
int max = 0;
|
2018-03-11 00:56:41 +01:00
|
|
|
FD_ZERO (&fset);
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
for (i = 0; i < socklist_len; i++) {
|
2018-03-11 00:56:41 +01:00
|
|
|
FD_SET (socklist[i].sockfd, &fset);
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
if (socklist[i].sockfd > max)
|
|
|
|
max = socklist[i].sockfd;
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2016-03-20 15:48:13 +01:00
|
|
|
if (socklist[i].data_sockfd) {
|
2018-03-11 00:56:41 +01:00
|
|
|
FD_SET (socklist[i].data_sockfd, &fset);
|
|
|
|
|
2016-03-20 15:48:13 +01:00
|
|
|
if (socklist[i].sockfd > max)
|
|
|
|
max = socklist[i].sockfd;
|
|
|
|
}
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
/* wait for an event */
|
|
|
|
int n;
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
while ( (n = select (max + 1, &fset, NULL, NULL, NULL)) < 0) {
|
2015-10-18 10:14:33 +02:00
|
|
|
if (errno != EINTR)
|
2014-07-11 22:12:11 +02:00
|
|
|
return n;
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
}
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
/* process the received packet */
|
2015-10-18 10:14:33 +02:00
|
|
|
for (i = 0; i < socklist_len; i++) {
|
2014-07-11 22:12:11 +02:00
|
|
|
uint8_t buffer[4096];
|
2016-03-20 15:48:13 +01:00
|
|
|
struct sockaddr_storage srcaddr;
|
|
|
|
socklen_t srcaddrlen;
|
|
|
|
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
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);
|
2016-03-20 15:48:13 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
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);
|
2016-03-20 15:48:13 +01:00
|
|
|
}
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-11 00:56:41 +01:00
|
|
|
void process_cw_data_packet (int index, struct sockaddr *addr, uint8_t * buffer, int len)
|
2016-03-20 15:48:13 +01:00
|
|
|
{
|
2018-03-05 12:23:16 +01:00
|
|
|
char sock_buf[SOCK_ADDR_BUFSIZE];
|
2018-03-11 00:56:41 +01:00
|
|
|
cw_dbg (DBG_X, "There is a data packet now");
|
|
|
|
|
2016-04-10 16:04:58 +02:00
|
|
|
dataman_list_lock();
|
2018-03-11 00:56:41 +01:00
|
|
|
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);
|
|
|
|
|
2016-04-10 16:04:58 +02:00
|
|
|
if (!dm) {
|
2018-03-11 00:56:41 +01:00
|
|
|
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));
|
2016-04-10 16:04:58 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
dataman_list_add (dm);
|
|
|
|
|
|
|
|
dataman_start (dm);
|
|
|
|
|
|
|
|
|
2016-04-10 16:04:58 +02:00
|
|
|
}
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2016-04-10 16:04:58 +02:00
|
|
|
dataman_list_unlock();
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
dataman_add_packet (dm, buffer, len);
|
|
|
|
|
2016-04-10 16:04:58 +02:00
|
|
|
return;
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
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));
|
2016-04-10 16:04:58 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
wtpman_addpacket (wtpman, buffer, len);
|
2016-03-20 15:48:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-11 00:56:41 +01:00
|
|
|
void process_cw_ctrl_packet (int index, struct sockaddr *addr, uint8_t * buffer, int len)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2018-03-05 12:23:16 +01:00
|
|
|
char sock_buf[SOCK_ADDR_BUFSIZE];
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
/* first of all check preamble */
|
2018-03-11 00:56:41 +01:00
|
|
|
int preamble = cw_get_hdr_preamble (buffer);
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
if (preamble != CAPWAP_PACKET_PREAMBLE && preamble != CAPWAP_DTLS_PACKET_PREAMBLE) {
|
2018-03-11 00:56:41 +01:00
|
|
|
cw_dbg (DBG_PKT_ERR,
|
|
|
|
"Discarding packet from %s, wrong preamble, preamble = 0x%01X",
|
|
|
|
sock_addr2str (addr, sock_buf), preamble);
|
2014-07-11 22:12:11 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
wtplist_lock();
|
2018-03-11 00:56:41 +01:00
|
|
|
struct wtpman *wtpman = wtplist_get (addr);
|
2018-04-02 01:39:08 +02:00
|
|
|
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
if (!wtpman) {
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2018-04-02 21:00:37 +02:00
|
|
|
wtpman = wtpman_create (index, addr, preamble & 0xf);
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
if (!wtpman) {
|
2018-03-11 00:56:41 +01:00
|
|
|
cw_log (LOG_ERR, "Error creating wtpman: %s", strerror (errno));
|
2014-07-11 22:12:11 +02:00
|
|
|
wtplist_unlock();
|
|
|
|
return;
|
|
|
|
}
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
if (!wtplist_add (wtpman)) {
|
|
|
|
cw_log (LOG_ERR, "Error adding wtpman: Too many wtp connections");
|
|
|
|
wtpman_destroy (wtpman);
|
2014-07-11 22:12:11 +02:00
|
|
|
wtplist_unlock();
|
|
|
|
return;
|
|
|
|
};
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
wtpman_start (wtpman, preamble & 0xf);
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
wtpman_addpacket (wtpman, buffer, len);
|
2014-07-11 22:12:11 +02:00
|
|
|
wtplist_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-02 21:00:37 +02:00
|
|
|
/*
|
2018-03-11 00:56:41 +01:00
|
|
|
void process_lw_ctrl_packet (int index, struct sockaddr *addr, uint8_t * buffer, int len)
|
2014-07-26 20:29:30 +02:00
|
|
|
{
|
2018-04-02 21:00:37 +02:00
|
|
|
//int sock = socklist[index].reply_sockfd;
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
uint8_t *m = buffer + 6;
|
2018-03-11 00:56:41 +01:00
|
|
|
uint32_t val = ntohl (* ( (uint32_t *) (m)));
|
|
|
|
|
|
|
|
|
|
|
|
printf ("VAL: %08X\n", val);
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-04-02 21:00:37 +02:00
|
|
|
// first of all check preamble
|
2018-03-11 00:56:41 +01:00
|
|
|
int version = LWTH_GET_VERSION (m);
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
if (version != LW_VERSION) {
|
2018-04-02 21:00:37 +02:00
|
|
|
// cw_log_debug1("Discarding LWAPP packet, wrong verson");
|
2014-07-26 20:29:30 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
int l = LWTH_GET_LENGTH (m);
|
|
|
|
printf ("LEN = %d\n", l);
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
if (l + 12 != len) {
|
2018-04-02 21:00:37 +02:00
|
|
|
// cw_log_debug1("Discarding LWAPP packet, wrong length");
|
2014-07-26 20:29:30 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2014-07-26 20:29:30 +02:00
|
|
|
wtplist_lock();
|
2018-03-11 00:56:41 +01:00
|
|
|
struct wtpman *wtpman = wtplist_get (addr);
|
2018-04-02 01:39:08 +02:00
|
|
|
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
if (!wtpman) {
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
wtpman = wtpman_create (index, addr);
|
2018-04-02 01:39:08 +02:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
if (!wtpman) {
|
2018-03-11 00:56:41 +01:00
|
|
|
cw_log (LOG_ERR, "Error creating wtpman: %s", strerror (errno));
|
2014-07-26 20:29:30 +02:00
|
|
|
wtplist_unlock();
|
|
|
|
return;
|
|
|
|
}
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
if (!wtplist_add (wtpman)) {
|
|
|
|
cw_log (LOG_ERR, "Error adding wtpman: Too many wtp connections");
|
|
|
|
wtpman_destroy (wtpman);
|
2014-07-26 20:29:30 +02:00
|
|
|
wtplist_unlock();
|
|
|
|
return;
|
|
|
|
};
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2018-04-02 21:00:37 +02:00
|
|
|
//wtpman_lw_start(wtpman);
|
2014-07-26 20:29:30 +02:00
|
|
|
}
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2018-04-02 21:00:37 +02:00
|
|
|
//wtpman_lw_addpacket(wtpman,buffer,len);
|
2014-07-26 20:29:30 +02:00
|
|
|
wtplist_unlock();
|
|
|
|
}
|
|
|
|
|
2018-04-02 21:00:37 +02:00
|
|
|
*/
|
2014-07-26 20:29:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-11 00:56:41 +01:00
|
|
|
void process_ctrl_packet (int index, struct sockaddr *addr, uint8_t * buffer, int len)
|
2014-07-26 20:29:30 +02:00
|
|
|
{
|
2015-10-18 10:14:33 +02:00
|
|
|
switch (socklist[index].ac_proto) {
|
2014-07-26 20:29:30 +02:00
|
|
|
case AC_PROTO_CAPWAP:
|
2018-03-11 00:56:41 +01:00
|
|
|
process_cw_ctrl_packet (index, addr, buffer, len);
|
2014-07-26 20:29:30 +02:00
|
|
|
return;
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2018-04-02 21:00:37 +02:00
|
|
|
/*case AC_PROTO_LWAPP:
|
2018-03-11 00:56:41 +01:00
|
|
|
process_lw_ctrl_packet (index, addr, buffer, len);
|
2018-04-02 21:00:37 +02:00
|
|
|
return;*/
|
2014-07-26 20:29:30 +02:00
|
|
|
}
|
|
|
|
}
|