Allow daemon mode
This commit is contained in:
parent
7b6bd52f48
commit
99b6373cd7
@ -3,6 +3,8 @@
|
|||||||
version = "1.0";
|
version = "1.0";
|
||||||
|
|
||||||
application: {
|
application: {
|
||||||
|
standalone = false;
|
||||||
|
|
||||||
name = "ac 1";
|
name = "ac 1";
|
||||||
|
|
||||||
binding = [
|
binding = [
|
||||||
@ -51,8 +53,8 @@ application: {
|
|||||||
|
|
||||||
presharedkey: {
|
presharedkey: {
|
||||||
hint = "esempio";
|
hint = "esempio";
|
||||||
identity = "prova";
|
identity = "prova";
|
||||||
pskkey = "123456";
|
pskkey = "123456";
|
||||||
};
|
};
|
||||||
|
|
||||||
x509: {
|
x509: {
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
version = "1.0";
|
version = "1.0";
|
||||||
|
|
||||||
application: {
|
application: {
|
||||||
|
standalone = false;
|
||||||
|
|
||||||
name = "wtp 1";
|
name = "wtp 1";
|
||||||
|
|
||||||
location = "Ufficio";
|
location = "Ufficio";
|
||||||
@ -79,7 +81,7 @@ application: {
|
|||||||
network: {
|
network: {
|
||||||
#binding = "eth1";
|
#binding = "eth1";
|
||||||
mtu = 1500;
|
mtu = 1500;
|
||||||
#port = 10000;
|
|
||||||
transport = "udp";
|
transport = "udp";
|
||||||
|
|
||||||
ipv4 = true;
|
ipv4 = true;
|
||||||
@ -88,7 +90,7 @@ application: {
|
|||||||
};
|
};
|
||||||
|
|
||||||
acdiscovery: {
|
acdiscovery: {
|
||||||
search = false;
|
search = true;
|
||||||
host = [
|
host = [
|
||||||
"127.0.0.1"
|
"127.0.0.1"
|
||||||
];
|
];
|
||||||
|
16
src/ac/ac.c
16
src/ac/ac.c
@ -16,6 +16,9 @@ static char g_configurationfile[260] = AC_DEFAULT_CONFIGURATION_FILE;
|
|||||||
|
|
||||||
/* Alloc AC */
|
/* Alloc AC */
|
||||||
static int ac_init(void) {
|
static int ac_init(void) {
|
||||||
|
/* */
|
||||||
|
g_ac.standalone = 1;
|
||||||
|
|
||||||
/* Network */
|
/* Network */
|
||||||
capwap_network_init(&g_ac.net);
|
capwap_network_init(&g_ac.net);
|
||||||
g_ac.mtu = CAPWAP_MTU_DEFAULT;
|
g_ac.mtu = CAPWAP_MTU_DEFAULT;
|
||||||
@ -158,6 +161,11 @@ static int ac_parsing_configuration_1_0(config_t* config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Set running mode */
|
||||||
|
if (config_lookup_bool(config, "application.standalone", &configInt) == CONFIG_TRUE) {
|
||||||
|
g_ac.standalone = ((configInt != 0) ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
/* Set name of AC */
|
/* Set name of AC */
|
||||||
if (config_lookup_string(config, "application.name", &configString) == CONFIG_TRUE) {
|
if (config_lookup_string(config, "application.name", &configString) == CONFIG_TRUE) {
|
||||||
if (strlen(configString) > CAPWAP_ACNAME_MAXLENGTH) {
|
if (strlen(configString) > CAPWAP_ACNAME_MAXLENGTH) {
|
||||||
@ -690,6 +698,14 @@ int main(int argc, char** argv) {
|
|||||||
if (value < 0) {
|
if (value < 0) {
|
||||||
result = AC_ERROR_LOAD_CONFIGURATION;
|
result = AC_ERROR_LOAD_CONFIGURATION;
|
||||||
} else if (value > 0) {
|
} else if (value > 0) {
|
||||||
|
if (!g_ac.standalone) {
|
||||||
|
capwap_daemon();
|
||||||
|
|
||||||
|
/* Console logging is disabled in daemon mode */
|
||||||
|
capwap_logging_disable_console();
|
||||||
|
capwap_logging_info("Running AC in daemon mode");
|
||||||
|
}
|
||||||
|
|
||||||
/* Complete configuration AC */
|
/* Complete configuration AC */
|
||||||
result = ac_configure();
|
result = ac_configure();
|
||||||
if (result == CAPWAP_SUCCESSFUL) {
|
if (result == CAPWAP_SUCCESSFUL) {
|
||||||
|
@ -83,6 +83,7 @@ struct ac_data_session_handshake {
|
|||||||
|
|
||||||
/* AC */
|
/* AC */
|
||||||
struct ac_t {
|
struct ac_t {
|
||||||
|
int standalone;
|
||||||
int running;
|
int running;
|
||||||
|
|
||||||
/* */
|
/* */
|
||||||
|
@ -160,3 +160,41 @@ void* capwap_clone(void* buffer, int buffersize) {
|
|||||||
|
|
||||||
return memcpy(bufferclone, buffer, buffersize);
|
return memcpy(bufferclone, buffer, buffersize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
void capwap_daemon(void) {
|
||||||
|
int fd;
|
||||||
|
pid_t pid;
|
||||||
|
|
||||||
|
/* Fork off the parent process */
|
||||||
|
pid = fork();
|
||||||
|
if (pid < 0) {
|
||||||
|
capwap_exit(CAPWAP_DAEMON_ERROR);
|
||||||
|
} else if (pid > 0) {
|
||||||
|
capwap_exit(CAPWAP_SUCCESSFUL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Change the file mode mask */
|
||||||
|
umask(0);
|
||||||
|
|
||||||
|
/* Create a new SID for the child process */
|
||||||
|
if (setsid() < 0) {
|
||||||
|
capwap_exit(CAPWAP_DAEMON_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Change the current working directory */
|
||||||
|
if ((chdir("/")) < 0) {
|
||||||
|
capwap_exit(CAPWAP_DAEMON_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Redirect the standard file descriptors to /dev/null */
|
||||||
|
fd = open("/dev/null", 0);
|
||||||
|
if (fd == -1) {
|
||||||
|
capwap_exit(CAPWAP_DAEMON_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
dup2(fd, STDIN_FILENO);
|
||||||
|
dup2(fd, STDOUT_FILENO);
|
||||||
|
dup2(fd, STDERR_FILENO);
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
@ -12,9 +12,12 @@
|
|||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
@ -92,6 +95,9 @@ void capwap_killall_timeout(struct timeout_control* timeout);
|
|||||||
int capwap_is_enable_timeout(struct timeout_control* timeout, unsigned long index);
|
int capwap_is_enable_timeout(struct timeout_control* timeout, unsigned long index);
|
||||||
int capwap_is_timeout(struct timeout_control* timeout, unsigned long index);
|
int capwap_is_timeout(struct timeout_control* timeout, unsigned long index);
|
||||||
|
|
||||||
|
/* */
|
||||||
|
void capwap_daemon(void);
|
||||||
|
|
||||||
/* */
|
/* */
|
||||||
#define capwap_outofmemory() capwap_logging_fatal("Out of memory %s(%d)", __FILE__, __LINE__); \
|
#define capwap_outofmemory() capwap_logging_fatal("Out of memory %s(%d)", __FILE__, __LINE__); \
|
||||||
capwap_exit(CAPWAP_OUT_OF_MEMORY);
|
capwap_exit(CAPWAP_OUT_OF_MEMORY);
|
||||||
|
@ -6,5 +6,6 @@
|
|||||||
#define CAPWAP_OUT_OF_MEMORY -2
|
#define CAPWAP_OUT_OF_MEMORY -2
|
||||||
#define CAPWAP_REQUEST_ROOT -3
|
#define CAPWAP_REQUEST_ROOT -3
|
||||||
#define CAPWAP_CRYPT_ERROR -4
|
#define CAPWAP_CRYPT_ERROR -4
|
||||||
|
#define CAPWAP_DAEMON_ERROR -5
|
||||||
|
|
||||||
#endif /* __CAPWAP_ERROR_HEADER__*/
|
#endif /* __CAPWAP_ERROR_HEADER__*/
|
||||||
|
@ -81,6 +81,20 @@ void capwap_logging_enable_console(int error) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
void capwap_logging_disable_console(void) {
|
||||||
|
#ifdef CAPWAP_MULTITHREADING_ENABLE
|
||||||
|
capwap_lock_enter(&l_loglock);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
loggingoutputstdout = 0;
|
||||||
|
loggingoutputstderr = 0;
|
||||||
|
|
||||||
|
#ifdef CAPWAP_MULTITHREADING_ENABLE
|
||||||
|
capwap_lock_exit(&l_loglock);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/* */
|
/* */
|
||||||
#ifdef ENABLE_LOGGING
|
#ifdef ENABLE_LOGGING
|
||||||
void capwap_logging_printf(int level, const char* format, ...) {
|
void capwap_logging_printf(int level, const char* format, ...) {
|
||||||
|
@ -19,6 +19,7 @@ void capwap_logging_verboselevel(unsigned int level);
|
|||||||
/* */
|
/* */
|
||||||
void capwap_logging_disable_allinterface();
|
void capwap_logging_disable_allinterface();
|
||||||
void capwap_logging_enable_console(int error);
|
void capwap_logging_enable_console(int error);
|
||||||
|
void capwap_logging_disable_console(void);
|
||||||
|
|
||||||
/* */
|
/* */
|
||||||
#ifdef ENABLE_LOGGING
|
#ifdef ENABLE_LOGGING
|
||||||
|
@ -24,6 +24,9 @@ static int wtp_init(void) {
|
|||||||
/* Init WTP with default value */
|
/* Init WTP with default value */
|
||||||
memset(&g_wtp, 0, sizeof(struct wtp_t));
|
memset(&g_wtp, 0, sizeof(struct wtp_t));
|
||||||
|
|
||||||
|
/* Standard running mode is standalone */
|
||||||
|
g_wtp.standalone = 1;
|
||||||
|
|
||||||
/* Standard name */
|
/* Standard name */
|
||||||
g_wtp.name.name = (uint8_t*)capwap_duplicate_string(WTP_STANDARD_NAME);
|
g_wtp.name.name = (uint8_t*)capwap_duplicate_string(WTP_STANDARD_NAME);
|
||||||
g_wtp.location.value = (uint8_t*)capwap_duplicate_string(WTP_STANDARD_LOCATION);
|
g_wtp.location.value = (uint8_t*)capwap_duplicate_string(WTP_STANDARD_LOCATION);
|
||||||
@ -237,6 +240,11 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Set running mode */
|
||||||
|
if (config_lookup_bool(config, "application.standalone", &configInt) == CONFIG_TRUE) {
|
||||||
|
g_wtp.standalone = ((configInt != 0) ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
/* Set name of WTP */
|
/* Set name of WTP */
|
||||||
if (config_lookup_string(config, "application.name", &configString) == CONFIG_TRUE) {
|
if (config_lookup_string(config, "application.name", &configString) == CONFIG_TRUE) {
|
||||||
if (strlen(configString) > CAPWAP_WTPNAME_MAXLENGTH) {
|
if (strlen(configString) > CAPWAP_WTPNAME_MAXLENGTH) {
|
||||||
@ -1014,7 +1022,7 @@ int main(int argc, char** argv) {
|
|||||||
result = CAPWAP_CRYPT_ERROR;
|
result = CAPWAP_CRYPT_ERROR;
|
||||||
capwap_logging_fatal("Error to init crypt engine");
|
capwap_logging_fatal("Error to init crypt engine");
|
||||||
} else {
|
} else {
|
||||||
/* Alloc a WTP */
|
/* Init WTP */
|
||||||
if (!wtp_init()) {
|
if (!wtp_init()) {
|
||||||
result = WTP_ERROR_SYSTEM_FAILER;
|
result = WTP_ERROR_SYSTEM_FAILER;
|
||||||
capwap_logging_fatal("Error to init WTP engine");
|
capwap_logging_fatal("Error to init WTP engine");
|
||||||
@ -1025,6 +1033,14 @@ int main(int argc, char** argv) {
|
|||||||
result = WTP_ERROR_LOAD_CONFIGURATION;
|
result = WTP_ERROR_LOAD_CONFIGURATION;
|
||||||
capwap_logging_fatal("Error to load configuration");
|
capwap_logging_fatal("Error to load configuration");
|
||||||
} else if (value > 0) {
|
} else if (value > 0) {
|
||||||
|
if (!g_wtp.standalone) {
|
||||||
|
capwap_daemon();
|
||||||
|
|
||||||
|
/* Console logging is disabled in daemon mode */
|
||||||
|
capwap_logging_disable_console();
|
||||||
|
capwap_logging_info("Running WTP in daemon mode");
|
||||||
|
}
|
||||||
|
|
||||||
capwap_logging_info("Startup WTP");
|
capwap_logging_info("Startup WTP");
|
||||||
|
|
||||||
/* Start WTP */
|
/* Start WTP */
|
||||||
|
@ -73,6 +73,7 @@ struct wtp_state {
|
|||||||
|
|
||||||
/* WTP */
|
/* WTP */
|
||||||
struct wtp_t {
|
struct wtp_t {
|
||||||
|
int standalone;
|
||||||
int running;
|
int running;
|
||||||
|
|
||||||
struct wtp_state dfa;
|
struct wtp_state dfa;
|
||||||
|
Loading…
Reference in New Issue
Block a user