aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/transport/gnunet-helper-transport-wlan-dummy.c195
-rw-r--r--src/transport/gnunet-helper-transport-wlan.c43
-rw-r--r--src/transport/plugin_transport_wlan.c20
3 files changed, 162 insertions, 96 deletions
diff --git a/src/transport/gnunet-helper-transport-wlan-dummy.c b/src/transport/gnunet-helper-transport-wlan-dummy.c
index 476b403a5..dddd51cb7 100644
--- a/src/transport/gnunet-helper-transport-wlan-dummy.c
+++ b/src/transport/gnunet-helper-transport-wlan-dummy.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2010 Christian Grothoff (and other contributing authors) 3 (C) 2010, 2012 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -27,22 +27,60 @@
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "plugin_transport_wlan.h" 28#include "plugin_transport_wlan.h"
29 29
30#define FIFO_FILE1 "/tmp/test-transport/api-wlan-p1/WLAN_FIFO_in" 30/**
31#define FIFO_FILE2 "/tmp/test-transport/api-wlan-p1/WLAN_FIFO_out" 31 * Name of the fifo to use for IPC with the other dummy process.
32 */
33#define FIFO_FILE1 "/tmp/test-transport/api-wlan-p1/WLAN_FIFO_in"
34
35/**
36 * Name of the fifo to use for IPC with the other dummy process.
37 */
38#define FIFO_FILE2 "/tmp/test-transport/api-wlan-p1/WLAN_FIFO_out"
32 39
40/**
41 * Maximum size of a message allowed in either direction
42 * (used for our receive and sent buffers).
43 */
33#define MAXLINE 4096 44#define MAXLINE 4096
34 45
35struct sendbuf 46
47/**
48 * IO buffer used for buffering data in transit.
49 */
50struct SendBuffer
36{ 51{
37 unsigned int pos; 52
38 unsigned int size; 53 /**
54 * How many bytes that were stored in 'buf' did we already write to the
55 * destination? Always smaller than 'size'.
56 */
57 size_t pos;
58
59 /**
60 * How many bytes of data are stored in 'buf' for transmission right now?
61 * Data always starts at offset 0 and extends to 'size'.
62 */
63 size_t size;
64
65 /**
66 * Buffered data; twice the maximum allowed message size as we add some
67 * headers.
68 */
39 char buf[MAXLINE * 2]; 69 char buf[MAXLINE * 2];
40}; 70};
41 71
42static int first;
43 72
73/**
74 * Flag set to 1 if we are to terminate, otherwise 0.
75 */
44static int closeprog; 76static int closeprog;
45 77
78
79/**
80 * We're being killed, clean up.
81 *
82 * @param sig killing signal
83 */
46static void 84static void
47sigfunc (int sig) 85sigfunc (int sig)
48{ 86{
@@ -53,7 +91,8 @@ sigfunc (int sig)
53 91
54 92
55/** 93/**
56 * function to create GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL message for plugin 94 * Create control message for plugin
95 *
57 * @param buffer pointer to buffer for the message 96 * @param buffer pointer to buffer for the message
58 * @param mac pointer to the mac address 97 * @param mac pointer to the mac address
59 * @return number of bytes written 98 * @return number of bytes written
@@ -67,16 +106,23 @@ send_mac_to_plugin (char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac)
67 memcpy (&macmsg.mac, (char *) mac, sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)); 106 memcpy (&macmsg.mac, (char *) mac, sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
68 macmsg.hdr.size = htons (sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)); 107 macmsg.hdr.size = htons (sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage));
69 macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); 108 macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
70
71 memcpy (buffer, &macmsg, sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)); 109 memcpy (buffer, &macmsg, sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage));
72 return sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage); 110 return sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage);
73} 111}
74 112
75 113
114/**
115 * We got a message from the FIFO, check it, convert the message
116 * type to the output forward and copy it to the buffer for stdout.
117 *
118 * @param cls the 'struct SendBuffer' to copy the converted message to
119 * @param client unused
120 * @param hdr inbound message from the FIFO
121 */
76static void 122static void
77stdin_send (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) 123stdin_send (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
78{ 124{
79 struct sendbuf *write_pout = cls; 125 struct SendBuffer *write_pout = cls;
80 const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *in; 126 const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *in;
81 size_t payload_size; 127 size_t payload_size;
82 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage newheader; 128 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage newheader;
@@ -87,15 +133,13 @@ stdin_send (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
87 if ( (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) || 133 if ( (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) ||
88 (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) > sendsize) ) 134 (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) > sendsize) )
89 { 135 {
90 fprintf (stderr, "Received malformed message\n", 136 fprintf (stderr, "Received malformed message\n");
91 (unsigned int) sendsize,
92 (unsigned int) ntohs (hdr->type));
93 exit (1); 137 exit (1);
94 } 138 }
95 payload_size = sendsize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage); 139 payload_size = sendsize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage);
96 if ((payload_size + sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + write_pout->size) > MAXLINE * 2) 140 if ((payload_size + sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + write_pout->size) > MAXLINE * 2)
97 { 141 {
98 fprintf (stderr, "Packet too big for buffer\n"); 142 FPRINTF (stderr, "%s", "Packet too big for buffer\n");
99 exit (1); 143 exit (1);
100 } 144 }
101 memset (&newheader, 0, sizeof (newheader)); 145 memset (&newheader, 0, sizeof (newheader));
@@ -113,24 +157,37 @@ stdin_send (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
113} 157}
114 158
115 159
160/**
161 * We read a full message from stdin. Copy it to our send buffer.
162 *
163 * @param cls the 'struct SendBuffer' to copy to
164 * @param client unused
165 * @param hdr the message we received to copy to the buffer
166 */
116static void 167static void
117file_in_send (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) 168file_in_send (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
118{ 169{
119 struct sendbuf *write_std = cls; 170 struct SendBuffer *write_std = cls;
120 uint16_t sendsize; 171 uint16_t sendsize;
121 172
122 sendsize = ntohs (hdr->size); 173 sendsize = ntohs (hdr->size);
123 if ((sendsize + write_std->size) > MAXLINE * 2) 174 if ((sendsize + write_std->size) > MAXLINE * 2)
124 { 175 {
125 fprintf (stderr, "Function file_in_send: Packet too big for buffer\n"); 176 FPRINTF (stderr, "%s", "Packet too big for buffer\n");
126 exit (1); 177 exit (1);
127 } 178 }
128
129 memcpy (write_std->buf + write_std->size, hdr, sendsize); 179 memcpy (write_std->buf + write_std->size, hdr, sendsize);
130 write_std->size += sendsize; 180 write_std->size += sendsize;
131} 181}
132 182
133 183
184/**
185 * Main function of a program that pretends to be a WLAN card.
186 *
187 * @param argc should be 2
188 * @param argv either '1' or '2', depending on which of the two cards this dummy is to emulate
189 * @return 1 on error, 0 if terminated normally via signal
190 */
134int 191int
135main (int argc, char *argv[]) 192main (int argc, char *argv[])
136{ 193{
@@ -141,105 +198,98 @@ main (int argc, char *argv[])
141 int fdpin; 198 int fdpin;
142 int fdpout; 199 int fdpout;
143 char readbuf[MAXLINE]; 200 char readbuf[MAXLINE];
144 int readsize = 0; 201 int readsize;
145 struct sendbuf write_std; 202 struct SendBuffer write_std;
146 struct sendbuf write_pout; 203 struct SendBuffer write_pout;
147 int ret = 0; 204 int ret;
148 int maxfd = 0; 205 int maxfd;
149 fd_set rfds; 206 fd_set rfds;
150 fd_set wfds; 207 fd_set wfds;
151 struct timeval tv; 208 struct timeval tv;
152 int retval; 209 int retval;
153 struct GNUNET_SERVER_MessageStreamTokenizer *stdin_mst; 210 struct GNUNET_SERVER_MessageStreamTokenizer *stdin_mst = NULL;
154 struct GNUNET_SERVER_MessageStreamTokenizer *file_in_mst; 211 struct GNUNET_SERVER_MessageStreamTokenizer *file_in_mst = NULL;
155 struct GNUNET_TRANSPORT_WLAN_MacAddress macaddr; 212 struct GNUNET_TRANSPORT_WLAN_MacAddress macaddr;
213 int first;
156 214
157 if (2 != argc) 215 if ( (2 != argc) ||
216 ((0 != strcmp (argv[1], "1")) && (0 != strcmp (argv[1], "2"))) )
158 { 217 {
159 fprintf (stderr, 218 FPRINTF (stderr,
160 "This program must be started with the operating mode (1 or 2) as the only argument.\n"); 219 "%s",
220 "This program must be started with the operating mode (1 or 2) as the only argument.\n");
161 return 1; 221 return 1;
162 } 222 }
163 if ((0 != strstr (argv[1], "1")) && (0 != strstr (argv[1], "2")))
164 return 1;
165 223
166 //make the fifos if needed 224 /* make the fifos if needed */
167 if (0 != stat (FIFO_FILE1, &st)) 225 if (0 != stat (FIFO_FILE1, &st))
168 { 226 {
169 if (0 == stat (FIFO_FILE2, &st)) 227 if (0 == stat (FIFO_FILE2, &st))
170 { 228 {
171 fprintf (stderr, "FIFO_FILE2 exists, but FIFO_FILE1 not\n"); 229 FPRINTF (stderr, "%s", "FIFO_FILE2 exists, but FIFO_FILE1 not\n");
172 exit (1); 230 exit (1);
173 } 231 }
174 umask (0); 232 umask (0);
175 erg = mkfifo (FIFO_FILE1, 0666); 233 erg = mkfifo (FIFO_FILE1, 0666);
176 if (0 != erg) 234 if (0 != erg)
177 { 235 {
178 fprintf (stderr, "Error in mkfifo(%s): %s\n", FIFO_FILE1, 236 FPRINTF (stderr, "Error in mkfifo(%s): %s\n", FIFO_FILE1,
179 strerror (errno)); 237 strerror (errno));
180 //exit(1);
181 } 238 }
182 erg = mkfifo (FIFO_FILE2, 0666); 239 erg = mkfifo (FIFO_FILE2, 0666);
183 if (0 != erg) 240 if (0 != erg)
184 { 241 {
185 fprintf (stderr, "Error in mkfifo(%s): %s\n", FIFO_FILE2, 242 FPRINTF (stderr, "Error in mkfifo(%s): %s\n", FIFO_FILE2,
186 strerror (errno)); 243 strerror (errno));
187 //exit(1);
188 } 244 }
189
190 } 245 }
191 else 246 else
192 { 247 {
193 if (0 != stat (FIFO_FILE2, &st)) 248 if (0 != stat (FIFO_FILE2, &st))
194 { 249 {
195 fprintf (stderr, "FIFO_FILE1 exists, but FIFO_FILE2 not\n"); 250 FPRINTF (stderr, "%s", "FIFO_FILE1 exists, but FIFO_FILE2 not\n");
196 exit (1); 251 exit (1);
197 } 252 }
198 } 253 }
199 254
200 if (strstr (argv[1], "1")) 255 if (0 != strcmp (argv[1], "1"))
201 { 256 {
202 //fprintf(stderr, "First\n");
203 first = 1; 257 first = 1;
204 fpin = fopen (FIFO_FILE1, "r"); 258 fpin = fopen (FIFO_FILE1, "r");
205 if (NULL == fpin) 259 if (NULL == fpin)
206 { 260 {
207 fprintf (stderr, "fopen of read FIFO_FILE1\n"); 261 FPRINTF (stderr, "fopen of read FIFO_FILE1 failed: %s\n", STRERROR (errno));
208 goto end; 262 goto end;
209 } 263 }
210 fpout = fopen (FIFO_FILE2, "w"); 264 fpout = fopen (FIFO_FILE2, "w");
211 if (NULL == fpout) 265 if (NULL == fpout)
212 { 266 {
213 fprintf (stderr, "fopen of write FIFO_FILE2\n"); 267 FPRINTF (stderr, "fopen of write FIFO_FILE2 failed: %s\n", STRERROR (errno));
214 goto end; 268 goto end;
215 } 269 }
216
217 } 270 }
218 else 271 else
219 { 272 {
220 first = 0; 273 first = 0;
221 //fprintf(stderr, "Second\n");
222 fpout = fopen (FIFO_FILE1, "w"); 274 fpout = fopen (FIFO_FILE1, "w");
223 if (NULL == fpout) 275 if (NULL == fpout)
224 { 276 {
225 fprintf (stderr, "fopen of write FIFO_FILE1\n"); 277 FPRINTF (stderr, "fopen of write FIFO_FILE1 failed: %s\n", STRERROR (errno));
226 goto end; 278 goto end;
227 } 279 }
228 fpin = fopen (FIFO_FILE2, "r"); 280 fpin = fopen (FIFO_FILE2, "r");
229 if (NULL == fpin) 281 if (NULL == fpin)
230 { 282 {
231 fprintf (stderr, "fopen of read FIFO_FILE2\n"); 283 FPRINTF (stderr, "fopen of read FIFO_FILE2 failed: %s\n", STRERROR (errno));
232 goto end; 284 goto end;
233 } 285 }
234
235 } 286 }
236 287
237 fdpin = fileno (fpin); 288 fdpin = fileno (fpin);
238 GNUNET_assert (fpin >= 0); 289 GNUNET_assert (fpin >= 0);
239
240 if (fdpin >= FD_SETSIZE) 290 if (fdpin >= FD_SETSIZE)
241 { 291 {
242 fprintf (stderr, "File fdpin number too large (%d > %u)\n", fdpin, 292 FPRINTF (stderr, "File fdpin number too large (%d > %u)\n", fdpin,
243 (unsigned int) FD_SETSIZE); 293 (unsigned int) FD_SETSIZE);
244 goto end; 294 goto end;
245 } 295 }
@@ -249,10 +299,9 @@ main (int argc, char *argv[])
249 299
250 if (fdpout >= FD_SETSIZE) 300 if (fdpout >= FD_SETSIZE)
251 { 301 {
252 fprintf (stderr, "File fdpout number too large (%d > %u)\n", fdpout, 302 FPRINTF (stderr, "File fdpout number too large (%d > %u)\n", fdpout,
253 (unsigned int) FD_SETSIZE); 303 (unsigned int) FD_SETSIZE);
254 goto end; 304 goto end;
255
256 } 305 }
257 306
258 signal (SIGINT, &sigfunc); 307 signal (SIGINT, &sigfunc);
@@ -265,7 +314,7 @@ main (int argc, char *argv[])
265 stdin_mst = GNUNET_SERVER_mst_create (&stdin_send, &write_pout); 314 stdin_mst = GNUNET_SERVER_mst_create (&stdin_send, &write_pout);
266 file_in_mst = GNUNET_SERVER_mst_create (&file_in_send, &write_std); 315 file_in_mst = GNUNET_SERVER_mst_create (&file_in_send, &write_std);
267 316
268 //Send random mac address 317 /* Send 'random' mac address */
269 macaddr.mac[0] = 0x13; 318 macaddr.mac[0] = 0x13;
270 macaddr.mac[1] = 0x22; 319 macaddr.mac[1] = 0x22;
271 macaddr.mac[2] = 0x33; 320 macaddr.mac[2] = 0x33;
@@ -277,12 +326,12 @@ main (int argc, char *argv[])
277 while (0 == closeprog) 326 while (0 == closeprog)
278 { 327 {
279 maxfd = -1; 328 maxfd = -1;
280 //set timeout
281 tv.tv_sec = 5; 329 tv.tv_sec = 5;
282 tv.tv_usec = 0; 330 tv.tv_usec = 0;
283 331
284 FD_ZERO (&rfds); 332 FD_ZERO (&rfds);
285 // if output queue is empty 333 FD_ZERO (&wfds);
334 /* if output queue is empty, read */
286 if (0 == write_pout.size) 335 if (0 == write_pout.size)
287 { 336 {
288 FD_SET (STDIN_FILENO, &rfds); 337 FD_SET (STDIN_FILENO, &rfds);
@@ -293,8 +342,8 @@ main (int argc, char *argv[])
293 FD_SET (fdpin, &rfds); 342 FD_SET (fdpin, &rfds);
294 maxfd = MAX (fdpin, maxfd); 343 maxfd = MAX (fdpin, maxfd);
295 } 344 }
296 FD_ZERO (&wfds); 345
297 // if there is something to write 346 /* if there is something to write, try to write */
298 if (0 < write_std.size) 347 if (0 < write_std.size)
299 { 348 {
300 FD_SET (STDOUT_FILENO, &wfds); 349 FD_SET (STDOUT_FILENO, &wfds);
@@ -311,7 +360,7 @@ main (int argc, char *argv[])
311 continue; 360 continue;
312 if (0 > retval) 361 if (0 > retval)
313 { 362 {
314 fprintf (stderr, "select failed: %s\n", strerror (errno)); 363 FPRINTF (stderr, "select failed: %s\n", STRERROR (errno));
315 closeprog = 1; 364 closeprog = 1;
316 break; 365 break;
317 } 366 }
@@ -324,14 +373,14 @@ main (int argc, char *argv[])
324 if (0 > ret) 373 if (0 > ret)
325 { 374 {
326 closeprog = 1; 375 closeprog = 1;
327 fprintf (stderr, "Write ERROR to STDOUT_FILENO: %s\n", 376 FPRINTF (stderr, "Write ERROR to STDOUT_FILENO: %s\n",
328 strerror (errno)); 377 STRERROR (errno));
329 break; 378 break;
330 } 379 }
331 else 380 else
332 { 381 {
333 write_std.pos += ret; 382 write_std.pos += ret;
334 // check if finished 383 /* check if finished writing */
335 if (write_std.pos == write_std.size) 384 if (write_std.pos == write_std.size)
336 { 385 {
337 write_std.pos = 0; 386 write_std.pos = 0;
@@ -349,12 +398,12 @@ main (int argc, char *argv[])
349 if (0 > ret) 398 if (0 > ret)
350 { 399 {
351 closeprog = 1; 400 closeprog = 1;
352 fprintf (stderr, "Write ERROR to fdpout: %s\n", strerror (errno)); 401 FPRINTF (stderr, "Write ERROR to fdpout failed: %s\n", STRERROR (errno));
353 } 402 }
354 else 403 else
355 { 404 {
356 write_pout.pos += ret; 405 write_pout.pos += ret;
357 // check if finished 406 /* check if finished writing */
358 if (write_pout.pos == write_pout.size) 407 if (write_pout.pos == write_pout.size)
359 { 408 {
360 write_pout.pos = 0; 409 write_pout.pos = 0;
@@ -370,8 +419,8 @@ main (int argc, char *argv[])
370 if (0 > readsize) 419 if (0 > readsize)
371 { 420 {
372 closeprog = 1; 421 closeprog = 1;
373 fprintf (stderr, "Error reading from STDIN_FILENO: %s\n", 422 FPRINTF (stderr, "Error reading from STDIN_FILENO: %s\n",
374 strerror (errno)); 423 STRERROR (errno));
375 } 424 }
376 else if (0 < readsize) 425 else if (0 < readsize)
377 { 426 {
@@ -381,7 +430,7 @@ main (int argc, char *argv[])
381 } 430 }
382 else 431 else
383 { 432 {
384 //eof 433 /* eof */
385 closeprog = 1; 434 closeprog = 1;
386 } 435 }
387 } 436 }
@@ -392,7 +441,7 @@ main (int argc, char *argv[])
392 if (0 > readsize) 441 if (0 > readsize)
393 { 442 {
394 closeprog = 1; 443 closeprog = 1;
395 fprintf (stderr, "Error reading from fdpin: %s\n", strerror (errno)); 444 FPRINTF (stderr, "Error reading from fdpin: %s\n", STRERROR (errno));
396 break; 445 break;
397 } 446 }
398 else if (0 < readsize) 447 else if (0 < readsize)
@@ -402,20 +451,22 @@ main (int argc, char *argv[])
402 } 451 }
403 else 452 else
404 { 453 {
405 //eof 454 /* eof */
406 closeprog = 1; 455 closeprog = 1;
407 } 456 }
408 } 457 }
409 } 458 }
410 459
411 //clean up
412 GNUNET_SERVER_mst_destroy (stdin_mst);
413 GNUNET_SERVER_mst_destroy (file_in_mst);
414
415end: 460end:
416 if (fpout != NULL) 461 /* clean up */
462 if (NULL != stdin_mst)
463 GNUNET_SERVER_mst_destroy (stdin_mst);
464 if (NULL != file_in_mst)
465 GNUNET_SERVER_mst_destroy (file_in_mst);
466
467 if (NULL != fpout)
417 fclose (fpout); 468 fclose (fpout);
418 if (fpin != NULL) 469 if (NULL != fpin)
419 fclose (fpin); 470 fclose (fpin);
420 if (1 == first) 471 if (1 == first)
421 { 472 {
diff --git a/src/transport/gnunet-helper-transport-wlan.c b/src/transport/gnunet-helper-transport-wlan.c
index 2d68c3655..363925cad 100644
--- a/src/transport/gnunet-helper-transport-wlan.c
+++ b/src/transport/gnunet-helper-transport-wlan.c
@@ -30,18 +30,39 @@
30 * interface. It will force traffic to be in 'ad-hoc' mode, use the 30 * interface. It will force traffic to be in 'ad-hoc' mode, use the
31 * proper MAC address of the WLAN interface and use a GNUnet-specific 31 * proper MAC address of the WLAN interface and use a GNUnet-specific
32 * SSID (and a GNUnet-specific SNAP header). It only takes a single 32 * SSID (and a GNUnet-specific SNAP header). It only takes a single
33 * argument, which is the name of the interface to use. Since it uses 33 * argument, which is the name of the WLAN interface to use. The
34 * RAW sockets, it must be installed SUID or run as 'root'. In order 34 * program detects if the interface is not a WLAN interface and exits
35 * to keep the security risk of the resulting SUID binary minimal, the 35 * with an error in that case.
36 * program ONLY opens the RAW socket with root privileges, then drops
37 * them and only then starts to process command line arguments. The
38 * code also does not link against any shared libraries (except libc)
39 * and is strictly minimal (except for checking for errors). The
40 * following list of people have reviewed this code and considered it
41 * safe since the last modification (if you reviewed it, please have
42 * your name added to the list):
43 * 36 *
44 * - Christian Grothoff (Mar 16th 2012) 37 * Once initialized, the program will first send a 'struct
38 * GNUNET_TRANSPORT_WLAN_HelperControlMessage' to 'stdout'. That
39 * message contains the MAC address of the WLAN interface. It will
40 * then read messages from the WLAN interface and send them together
41 * with performance information as 'struct
42 * GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage' messages to 'stdout'.
43 * Furthermore, it will read a stream of messages from 'stdin' that
44 * have the format from 'struct
45 * GNUNET_TRANSPORT_WLAN_RadiotapSendMessage'. Those messages will
46 * then be sent via the WLAN interface; however, the sender MAC
47 * address will be forced to be the correct address from our WLAN
48 * card. If 'stdin' closes, receiving from the WLAN interface will
49 * continue. If 'stdout' causes a SIGPIPE, the process dies from the
50 * signal. Errors cause an error message to be reported to 'stderr',
51 * in most cases the process also exits (with status code '1'). The
52 * program never terminates normally; it is safe to kill the
53 * process with SIGTERM or SIGKILL at any time.
54 *
55 * Since it uses RAW sockets, the binary must be installed SUID or run
56 * as 'root'. In order to keep the security risk of the resulting
57 * SUID binary minimal, the program ONLY opens the RAW socket with
58 * root privileges, then drops them and only then starts to process
59 * command line arguments. The code also does not link against any
60 * shared libraries (except libc) and is strictly minimal (except for
61 * checking for errors). The following list of people have reviewed
62 * this code and considered it safe since the last modification (if
63 * you reviewed it, please have your name added to the list):
64 *
65 * - Christian Grothoff (Apr 3rd 2012)
45 */ 66 */
46 67
47/*- 68/*-
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c
index 13f414f30..a3d90b598 100644
--- a/src/transport/plugin_transport_wlan.c
+++ b/src/transport/plugin_transport_wlan.c
@@ -1003,12 +1003,13 @@ set_next_beacon_time (struct Plugin *const plugin)
1003 } 1003 }
1004} 1004}
1005 1005
1006
1006/** 1007/**
1007 * Function to set the timer for the next timeout of the fragment queue 1008 * Function to set the timer for the next timeout of the fragment queue
1008 * @param plugin the handle to the plugin struct 1009 * @param plugin the handle to the plugin struct
1009 */ 1010 */
1010static void 1011static void
1011set_next_send (struct Plugin *const plugin) 1012set_next_send (struct Plugin *plugin)
1012{ 1013{
1013 struct GNUNET_TIME_Relative next_send; 1014 struct GNUNET_TIME_Relative next_send;
1014 1015
@@ -1185,7 +1186,6 @@ free_fragment_message (struct Plugin *plugin, struct FragmentMessage *fm)
1185 } 1186 }
1186 fmq = fmq_next; 1187 fmq = fmq_next;
1187 } 1188 }
1188
1189 session->mac->fragment_messages_out_count--; 1189 session->mac->fragment_messages_out_count--;
1190 session->fragment_messages_out_count--; 1190 session->fragment_messages_out_count--;
1191 plugin->pending_Fragment_Messages--; 1191 plugin->pending_Fragment_Messages--;
@@ -1766,10 +1766,8 @@ fragmentmessage_timeout (void *cls,
1766 1766
1767 GNUNET_assert (fm != NULL); 1767 GNUNET_assert (fm != NULL);
1768 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1768 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1769 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) 1769 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1770 { 1770 return;
1771 return;
1772 }
1773 free_fragment_message (fm->session->mac->plugin, fm); 1771 free_fragment_message (fm->session->mac->plugin, fm);
1774} 1772}
1775 1773
@@ -1908,7 +1906,6 @@ do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1908 struct FragmentMessage_queue *fmq; 1906 struct FragmentMessage_queue *fmq;
1909 ssize_t bytes; 1907 ssize_t bytes;
1910 1908
1911
1912 GNUNET_assert (plugin != NULL); 1909 GNUNET_assert (plugin != NULL);
1913 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK; 1910 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
1914 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1911 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
@@ -1926,8 +1923,7 @@ do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1926 } 1923 }
1927 if (NULL == plugin->sending_messages_head) 1924 if (NULL == plugin->sending_messages_head)
1928 { 1925 {
1929 /* do_transmit did nothing, should not happen */ 1926 /* nothing to do right now, check when to go again */
1930 GNUNET_break (0);
1931 set_next_send (plugin); 1927 set_next_send (plugin);
1932 return; 1928 return;
1933 } 1929 }
@@ -2241,10 +2237,8 @@ free_session (struct Plugin *plugin, struct Sessionqueue *queue,
2241 while (fm != NULL) 2237 while (fm != NULL)
2242 { 2238 {
2243 fmnext = fm->next; 2239 fmnext = fm->next;
2244 if (fm->session == queue->content) 2240 if (fm->session == queue->content)
2245 { 2241 free_fragment_message (plugin, fm);
2246 free_fragment_message (plugin, fm);
2247 }
2248 fm = fmnext; 2242 fm = fmnext;
2249 } 2243 }
2250 2244