4 * uAnytun is a tiny implementation of SATP. Unlike Anytun which is a full
5 * featured implementation uAnytun has no support for multiple connections
6 * or synchronisation. It is a small single threaded implementation intended
7 * to act as a client on small platforms.
8 * The secure anycast tunneling protocol (satp) defines a protocol used
9 * for communication between any combination of unicast and anycast
10 * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel
11 * mode and allows tunneling of every ETHER TYPE protocol (e.g.
12 * ethernet, ip, arp ...). satp directly includes cryptography and
13 * message authentication based on the methodes used by SRTP. It is
14 * intended to deliver a generic, scaleable and secure solution for
15 * tunneling and relaying of packets of any protocol.
18 * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
20 * This file is part of uAnytun.
22 * uAnytun is free software: you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License version 3 as
24 * published by the Free Software Foundation.
26 * uAnytun is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with uAnytun. If not, see <http://www.gnu.org/licenses/>.
35 enum syslog_facility_enum { USER = LOG_USER, MAIL = LOG_MAIL,
36 DAEMON = LOG_DAEMON, AUTH = LOG_AUTH,
37 SYSLOG = LOG_SYSLOG, LPR = LOG_LPR,
38 NEWS = LOG_NEWS, UUCP = LOG_UUCP,
39 CRON = LOG_CRON, AUTHPRIV = LOG_AUTHPRIV,
40 FTP = LOG_FTP, LOCAL0 = LOG_LOCAL0,
41 LOCAL1 = LOG_LOCAL1, LOCAL2 = LOG_LOCAL2,
42 LOCAL3 = LOG_LOCAL3, LOCAL4 = LOG_LOCAL4,
43 LOCAL5 = LOG_LOCAL5, LOCAL6 = LOG_LOCAL6,
44 LOCAL7 = LOG_LOCAL7 };
45 typedef enum syslog_facility_enum syslog_facility_t;
47 struct log_target_syslog_param_struct {
49 syslog_facility_t facility_;
51 typedef struct log_target_syslog_param_struct log_target_syslog_param_t;
53 int log_target_syslog_init(log_target_t* self, const char* conf)
55 if(!self || (conf && conf[0] == 0))
58 self->param_ = malloc(sizeof(log_target_syslog_param_t));
63 const char* end = NULL;
65 logname = strdup("uanytun");
67 end = strchr(conf, ',');
69 size_t len = (size_t)(end - conf);
74 logname = malloc(len+1);
76 strncpy(logname, conf, len);
81 logname = strdup(conf);
88 ((log_target_syslog_param_t*)(self->param_))->logname_ = logname;
91 ((log_target_syslog_param_t*)(self->param_))->facility_ = DAEMON;
95 if(end[1] == 0 || end[1] == ',') {
101 const char* start = end + 1;
102 end = strchr(start, ',');
105 if(facilitynames[i].c_name == NULL) {
111 if(( end && !strncmp(start, facilitynames[i].c_name, (size_t)(end - start)) && facilitynames[i].c_name[(size_t)(end-start)] == 0) ||
112 (!end && !strcmp(start, facilitynames[i].c_name))) {
113 ((log_target_syslog_param_t*)(self->param_))->facility_ = facilitynames[i].c_val;
121 void log_target_syslog_open(log_target_t* self)
123 if(!self || !self->param_)
126 openlog(((log_target_syslog_param_t*)(self->param_))->logname_, LOG_PID, ((log_target_syslog_param_t*)(self->param_))->facility_);
130 void log_target_syslog_log(log_target_t* self, log_prio_t prio, const char* msg)
132 if(!self || !self->param_ || !self->opened_)
135 syslog((prio + 2) | ((log_target_syslog_param_t*)(self->param_))->facility_, "%s", msg);
138 void log_target_syslog_close(log_target_t* self)
144 void log_target_syslog_clear(log_target_t* self)
146 if(!self || !self->param_)
149 if(((log_target_syslog_param_t*)(self->param_))->logname_)
150 free(((log_target_syslog_param_t*)(self->param_))->logname_);
155 log_target_t* log_target_syslog_new()
157 log_target_t* tmp = malloc(sizeof(log_target_t));
161 tmp->type_ = TARGET_SYSLOG;
162 tmp->init = &log_target_syslog_init;
163 tmp->open = &log_target_syslog_open;
164 tmp->log = &log_target_syslog_log;
165 tmp->close = &log_target_syslog_close;
166 tmp->clear = &log_target_syslog_clear;
169 tmp->max_prio_ = NOTICE;
177 struct log_target_file_param_struct {
181 typedef struct log_target_file_param_struct log_target_file_param_t;
183 int log_target_file_init(log_target_t* self, const char* conf)
185 if(!self || (conf && conf[0] == 0))
188 self->param_ = malloc(sizeof(log_target_file_param_t));
194 logfilename = strdup("uanytun.log");
196 const char* end = strchr(conf, ',');
198 size_t len = (size_t)(end - conf);
203 logfilename = malloc(len+1);
205 strncpy(logfilename, conf, len);
206 logfilename[len] = 0;
210 logfilename = strdup(conf);
217 ((log_target_file_param_t*)(self->param_))->logfilename_ = logfilename;
218 ((log_target_file_param_t*)(self->param_))->file_ = NULL;
223 void log_target_file_open(log_target_t* self)
225 if(!self || !self->param_)
228 ((log_target_file_param_t*)(self->param_))->file_ = fopen(((log_target_file_param_t*)(self->param_))->logfilename_, "w");
229 if(((log_target_file_param_t*)(self->param_))->file_)
233 void log_target_file_log(log_target_t* self, log_prio_t prio, const char* msg)
235 if(!self || !self->param_ || !self->opened_)
238 fprintf(((log_target_file_param_t*)(self->param_))->file_, "%s-%s\n", log_prio_to_string(prio), msg);
239 fflush(((log_target_file_param_t*)(self->param_))->file_);
242 void log_target_file_close(log_target_t* self)
244 if(!self || !self->param_)
247 fclose(((log_target_file_param_t*)(self->param_))->file_);
251 void log_target_file_clear(log_target_t* self)
253 if(!self || !self->param_)
256 if(((log_target_file_param_t*)(self->param_))->logfilename_)
257 free(((log_target_file_param_t*)(self->param_))->logfilename_);
263 log_target_t* log_target_file_new()
265 log_target_t* tmp = malloc(sizeof(log_target_t));
269 tmp->type_ = TARGET_FILE;
270 tmp->init = &log_target_file_init;
271 tmp->open = &log_target_file_open;
272 tmp->log = &log_target_file_log;
273 tmp->close = &log_target_file_close;
274 tmp->clear = &log_target_file_clear;
277 tmp->max_prio_ = NOTICE;
285 void log_target_stdout_log(log_target_t* self, log_prio_t prio, const char* msg)
287 printf("%s-%s\n", log_prio_to_string(prio), msg);
290 log_target_t* log_target_stdout_new()
292 log_target_t* tmp = malloc(sizeof(log_target_t));
296 tmp->type_ = TARGET_STDOUT;
299 tmp->log = &log_target_stdout_log;
304 tmp->max_prio_ = NOTICE;
312 void log_target_stderr_log(log_target_t* self, log_prio_t prio, const char* msg)
314 fprintf(stderr, "%s-%s\n", log_prio_to_string(prio), msg);
317 log_target_t* log_target_stderr_new()
319 log_target_t* tmp = malloc(sizeof(log_target_t));
323 tmp->type_ = TARGET_STDERR;
326 tmp->log = &log_target_stderr_log;
331 tmp->max_prio_ = NOTICE;