Annotation of embedtools/src/dwds.c, revision 1.1.2.8
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.8 ! misho 56: RtMsg(struct dwds_if **wds, struct rt_msghdr *msg, size_t len)
1.1.2.4 misho 57: {
1.1.2.8 ! misho 58: struct if_announcemsghdr *ifan;
! 59: const u_char *v;
! 60: struct ether_addr bssid;
! 61:
! 62: assert(wds);
! 63: assert(msg);
! 64:
! 65: if (msg->rtm_version != RTM_VERSION) {
! 66: syslog(LOG_ERR, "Error:: routing message version %d not understood!\n", msg->rtm_version);
! 67: return -1;
! 68: }
! 69:
! 70: switch (msg->rtm_type) {
! 71: case RTM_IFANNOUNCE:
! 72: ifan = (struct if_announcemsghdr*) msg;
! 73: switch (ifan->ifan_what) {
! 74: case IFAN_ARRIVAL:
! 75: VERB(1) syslog(LOG_INFO, "RTM_IFANNOUNCE: if# %d, what: arrival\n",
! 76: ifan->ifan_index);
! 77: break;
! 78: case IFAN_DEPARTURE:
! 79: VERB(1) syslog(LOG_INFO, "RTM_IFANNOUNCE: if# %d, what: departure\n",
! 80: ifan->ifan_index);
! 81: wifi_destroyWDS(ifan->ifan_name, wds);
! 82: break;
! 83: }
! 84: break;
! 85: case RTM_IEEE80211:
! 86: #define V(type) ((struct type *)(&ifan[1]))
! 87: ifan = (struct if_announcemsghdr*) msg;
! 88: switch (ifan->ifan_what) {
! 89: case RTM_IEEE80211_DISASSOC:
! 90: v = cfg_GetAttribute(&cfg, CFG("dwds"), CFG("discover_on_join"));
! 91: if (!v || !strtol((char*) v, NULL, 0))
! 92: break;
! 93: /* fall thru ... */
! 94: case RTM_IEEE80211_LEAVE:
! 95: break;
! 96:
! 97: case RTM_IEEE80211_JOIN:
! 98: case RTM_IEEE80211_REJOIN:
! 99: case RTM_IEEE80211_ASSOC:
! 100: case RTM_IEEE80211_REASSOC:
! 101: v = cfg_GetAttribute(&cfg, CFG("dwds"), CFG("discover_on_join"));
! 102: if (!v || !strtol((char*) v, NULL, 0))
! 103: break;
! 104: /* fall thru ... */
! 105: case RTM_IEEE80211_WDS:
! 106: break;
! 107: }
! 108: #undef V
! 109: break;
! 110: }
! 111:
1.1.2.4 misho 112: return 0;
113: }
114:
1.1.2.2 misho 115: // ---------------------------------------------------------------
116:
1.1.2.1 misho 117: int
118: main(int argc, char **argv)
119: {
1.1.2.4 misho 120: char ch, szStr[STRSIZ], fg = 0;
121: const u_char *v, msg[2048];
122: int s;
123: struct sigaction sa;
124: size_t len;
1.1.2.6 misho 125: struct dwds_if *wds = NULL;
1.1.2.2 misho 126:
1.1.2.3 misho 127: while ((ch = getopt(argc, argv, "hvfc:")) != -1)
128: switch (ch) {
129: case 'v':
130: Verbose++;
131: break;
132: case 'f':
133: fg = 1;
134: break;
135: case 'c':
136: strlcpy(szConfig, optarg, MAXPATHLEN);
137: break;
138: case 'h':
139: default:
140: Usage();
141: return 1;
142: }
143: argc -= optind;
144: argv += optind;
145: if (!argc) {
146: printf("Error:: not specified interface for use ...\n");
147: Usage();
148: return 1;
1.1.2.4 misho 149: } else {
150: nif = argc;
151: ifs = argv;
152: }
153: if (LoadConfig(szConfig, &cfg)) {
154: printf("Error:: can`t load config %s ...\n", szConfig);
155: return 1;
156: }
157:
1.1.2.7 misho 158: if (!fg)
1.1.2.4 misho 159: switch (fork()) {
160: case -1:
161: printf("Error:: when fork() #%d - %s\n", errno, strerror(errno));
162: UnloadConfig(&cfg);
163: return 2;
164: case 0 :
165: VERB(1) printf("Going to shadow land ...\n");
166:
167: setsid();
168:
169: memset(&sa, 0, sizeof sa);
170: sa.sa_handler = sigHandler;
171: sigemptyset(&sa.sa_mask);
172: sigaction(SIGHUP, &sa, NULL);
173: sigaction(SIGTERM, &sa, NULL);
174: sigaction(SIGCHLD, &sa, NULL);
175: break;
176: default:
177: goto end;
178: }
179:
180: cfg_LoadAttribute(&cfg, CFG("dwds"), CFG("name"), CFG(szStr), STRSIZ, DWDS_NAME);
181: openlog(szStr, LOG_PID | LOG_CONS, LOG_DAEMON);
182: v = cfg_GetAttribute(&cfg, CFG("dwds"), CFG("syslog_upto"));
183: setlogmask(v ? strtol((char*) v, NULL, 0) : 0);
184:
185: s = socket(PF_ROUTE, SOCK_RAW, 0);
186: if (s == -1) {
187: syslog(LOG_ERR, "Error:: socket() #%d - %s\n", errno, strerror(errno));
188: goto end;
189: }
190:
1.1.2.7 misho 191: if (!(wds = wifi_buildWDS(s, ifs, nif))) {
192: syslog(LOG_ERR, "Error:: Go to dead ...\n");
1.1.2.6 misho 193: goto end;
1.1.2.7 misho 194: }
1.1.2.6 misho 195:
1.1.2.4 misho 196: while (!Kill) {
197: len = read(s, (void*) msg, sizeof msg);
198: if (len == -1) {
199: syslog(LOG_ERR, "Error:: read() #%d - %s\n", errno, strerror(errno));
200: Kill++;
201: } else
1.1.2.8 ! misho 202: RtMsg(&wds, (struct rt_msghdr*) msg, len);
1.1.2.3 misho 203: }
204:
1.1.2.4 misho 205: close(s);
206: end:
207: closelog();
208: UnloadConfig(&cfg);
1.1.2.1 misho 209: return 0;
210: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>