Annotation of embedtools/src/dwds.c, revision 1.1.2.7
1.1.2.1 misho 1: #include "global.h"
2: #include "dwds.h"
3:
4:
1.1.2.4 misho 5: sl_config cfg;
6: int Verbose, Kill, nif;
7: char **ifs, szConfig[MAXPATHLEN] = DWDS_CONFIG;
1.1.2.2 misho 8: extern char compiled[], compiledby[], compilehost[];
9:
10:
11: static void
12: Usage()
13: {
1.1.2.3 misho 14: printf( "-= dWDS =- WiFi dynamic WDS service managment for VAP\n"
1.1.2.2 misho 15: "=== %s === %s@%s ===\n\n"
1.1.2.3 misho 16: " Syntax: dwds [options] <interface|any> [interface [...]]\n"
1.1.2.2 misho 17: "\n"
18: "\t-v\t\tVerbose ...\n"
19: "\t-f\t\tForeground, not demonize process ...\n"
20: "\t-c <config>\tConfig file [default=/etc/dwds.conf]\n"
21: "\n", compiled, compiledby, compilehost);
22: }
23:
1.1.2.4 misho 24: static void
25: sigHandler(int sig)
26: {
27: int stat;
28: const u_char *v;
29: char szStr[STRSIZ];
30:
31: switch (sig) {
32: case SIGHUP:
33: UnloadConfig(&cfg);
34: if (LoadConfig(szConfig, &cfg)) {
35: printf("Error:: can`t load config %s ...\n", szConfig);
36: Kill++;
37: } else {
38: closelog();
39:
40: cfg_LoadAttribute(&cfg, CFG("dwds"), CFG("name"), CFG(szStr), STRSIZ, DWDS_NAME);
41: openlog(szStr, LOG_PID | LOG_CONS, LOG_DAEMON);
42: v = cfg_GetAttribute(&cfg, CFG("dwds"), CFG("syslog_upto"));
43: setlogmask(v ? strtol((char*) v, NULL, 0) : 0);
44: }
45: break;
46: case SIGTERM:
47: Kill++;
48: break;
49: case SIGCHLD:
50: while (waitpid(-1, &stat, WNOHANG) > 0);
51: break;
52: }
53: }
54:
55: static int
1.1.2.6 misho 56: RtMsg(struct dwds_if *wds, struct rt_msghdr *msg, size_t len)
1.1.2.4 misho 57: {
58: return 0;
59: }
60:
1.1.2.2 misho 61: // ---------------------------------------------------------------
62:
1.1.2.1 misho 63: int
64: main(int argc, char **argv)
65: {
1.1.2.4 misho 66: char ch, szStr[STRSIZ], fg = 0;
67: const u_char *v, msg[2048];
68: int s;
69: struct sigaction sa;
70: size_t len;
1.1.2.6 misho 71: struct dwds_if *wds = NULL;
1.1.2.2 misho 72:
1.1.2.3 misho 73: while ((ch = getopt(argc, argv, "hvfc:")) != -1)
74: switch (ch) {
75: case 'v':
76: Verbose++;
77: break;
78: case 'f':
79: fg = 1;
80: break;
81: case 'c':
82: strlcpy(szConfig, optarg, MAXPATHLEN);
83: break;
84: case 'h':
85: default:
86: Usage();
87: return 1;
88: }
89: argc -= optind;
90: argv += optind;
91: if (!argc) {
92: printf("Error:: not specified interface for use ...\n");
93: Usage();
94: return 1;
1.1.2.4 misho 95: } else {
96: nif = argc;
97: ifs = argv;
98: }
99: if (LoadConfig(szConfig, &cfg)) {
100: printf("Error:: can`t load config %s ...\n", szConfig);
101: return 1;
102: }
103:
1.1.2.7 ! misho 104: if (!fg)
1.1.2.4 misho 105: switch (fork()) {
106: case -1:
107: printf("Error:: when fork() #%d - %s\n", errno, strerror(errno));
108: UnloadConfig(&cfg);
109: return 2;
110: case 0 :
111: VERB(1) printf("Going to shadow land ...\n");
112:
113: setsid();
114:
115: memset(&sa, 0, sizeof sa);
116: sa.sa_handler = sigHandler;
117: sigemptyset(&sa.sa_mask);
118: sigaction(SIGHUP, &sa, NULL);
119: sigaction(SIGTERM, &sa, NULL);
120: sigaction(SIGCHLD, &sa, NULL);
121: break;
122: default:
123: goto end;
124: }
125:
126: cfg_LoadAttribute(&cfg, CFG("dwds"), CFG("name"), CFG(szStr), STRSIZ, DWDS_NAME);
127: openlog(szStr, LOG_PID | LOG_CONS, LOG_DAEMON);
128: v = cfg_GetAttribute(&cfg, CFG("dwds"), CFG("syslog_upto"));
129: setlogmask(v ? strtol((char*) v, NULL, 0) : 0);
130:
131: s = socket(PF_ROUTE, SOCK_RAW, 0);
132: if (s == -1) {
133: syslog(LOG_ERR, "Error:: socket() #%d - %s\n", errno, strerror(errno));
134: goto end;
135: }
136:
1.1.2.7 ! misho 137: if (!(wds = wifi_buildWDS(s, ifs, nif))) {
! 138: syslog(LOG_ERR, "Error:: Go to dead ...\n");
1.1.2.6 misho 139: goto end;
1.1.2.7 ! misho 140: }
1.1.2.6 misho 141:
1.1.2.4 misho 142: while (!Kill) {
143: len = read(s, (void*) msg, sizeof msg);
144: if (len == -1) {
145: syslog(LOG_ERR, "Error:: read() #%d - %s\n", errno, strerror(errno));
146: Kill++;
147: } else
1.1.2.6 misho 148: RtMsg(wds, (struct rt_msghdr*) msg, len);
1.1.2.3 misho 149: }
150:
1.1.2.4 misho 151: close(s);
152: end:
153: closelog();
154: UnloadConfig(&cfg);
1.1.2.1 misho 155: return 0;
156: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>