1 /*****************************************************************************
2 Copyright (c) 2006 EMC Corporation.
3 Copyright (c) 2011 Factor-SPE
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2 of the License, or (at your option)
10 This program is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc., 59
17 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 The full GNU General Public License is included in this distribution in the
22 Authors: Srinivas Aji <Aji_Srinivas@emc.com>
23 Authors: Vitalii Demianets <dvitasgs@gmail.com>
25 ******************************************************************************/
27 /* #define MISC_TEST_FUNCS */
36 #include <sys/types.h>
37 #include <libubox/uloop.h>
39 #include "bridge_ctl.h"
40 #include "netif_utils.h"
45 #include "bridge_track.h"
49 #define APP_NAME "ustpd"
51 static int print_to_syslog
= 1;
52 int log_level
= LOG_LEVEL_DEFAULT
;
55 int main(int argc
, char *argv
[])
59 while((c
= getopt(argc
, argv
, "sv:")) != -1) {
67 l
= strtoul(optarg
, &end
, 0);
68 if(*optarg
== 0 || *end
!= 0 || l
> LOG_LEVEL_MAX
) {
69 ERROR("Invalid loglevel %s", optarg
);
81 openlog(APP_NAME
, LOG_PID
, LOG_DAEMON
);
85 TST(worker_init() == 0, -1);
86 TST(packet_sock_init() == 0, -1);
87 TST(netsock_init() == 0, -1);
88 TST(init_bridge_ops() == 0, -1);
100 /*********************** Logging *********************/
105 static void vDprintf(int level
, const char *fmt
, va_list ap
)
107 if(level
> log_level
)
117 local_tm
= localtime(&clock
);
118 int l
= strftime(logbuf
, sizeof(logbuf
) - 1, "%F %T ", local_tm
);
119 vsnprintf(logbuf
+ l
, sizeof(logbuf
) - l
- 1, fmt
, ap
);
120 printf("%s\n", logbuf
);
125 vsyslog((level
<= LOG_LEVEL_INFO
) ? LOG_INFO
: LOG_DEBUG
, fmt
, ap
);
129 void Dprintf(int level
, const char *fmt
, ...)
133 vDprintf(level
, fmt
, ap
);