Skip to content

Commit 8ccab94

Browse files
committed
Merge branch 'configurable-arptable' into load-tester
Conflicts: src/firewall.c
2 parents c07628d + 367acdc commit 8ccab94

22 files changed

+1060
-1057
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ WiFiDog 1.2.1:
1212
* Enhance safe_malloc to always zero memory (#155)
1313
* Fix segfault related pstr_t's buffer (#149)
1414
* Add open the firewall if no auth servers can be reached (optional, #90)
15+
* Add configurable ARP table location (-a switch). Useful for mock ARP tables during
16+
load tests (#166)
1517
* Various other fixes and minor improvements, see
1618
https://github.com/wifidog/wifidog-gateway/compare/1.2.0...1.2.1
1719

src/auth.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@
4848
#include "client_list.h"
4949
#include "util.h"
5050

51-
/* Defined in clientlist.c */
52-
extern pthread_mutex_t client_list_mutex;
53-
54-
/* Defined in util.c */
55-
extern long served_this_session;
5651

5752
/** Launches a thread that periodically checks if any of the connections has timed out
5853
@param arg Must contain a pointer to a string containing the IP adress of the client to check to check

src/centralserver.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@
5252

5353
#include "simple_http.h"
5454

55-
extern pthread_mutex_t config_mutex;
56-
5755
/** Initiates a transaction with the auth server, either to authenticate or to
5856
* update the traffic counters at the server
5957
@param authresponse Returns the information given by the central server

src/client_list.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* vim: set et sw=4 ts=4 sts=4 : */
12
/********************************************************************\
23
* This program is free software; you can redistribute it and/or *
34
* modify it under the terms of the GNU General Public License as *
@@ -18,9 +19,6 @@
1819
* *
1920
\********************************************************************/
2021

21-
/*
22-
* $Id$
23-
*/
2422
/** @file client_list.c
2523
@brief Client List Functions
2624
@author Copyright (C) 2004 Alexandre Carmel-Veillex <[email protected]>
@@ -44,15 +42,14 @@
4442
#include "conf.h"
4543
#include "client_list.h"
4644

47-
/** Global mutex to protect access to the client list */
48-
extern pthread_mutex_t client_list_mutex;
49-
pthread_mutex_t client_list_mutex = PTHREAD_MUTEX_INITIALIZER;
50-
5145
/** @internal
5246
* Holds a pointer to the first element of the list
5347
*/
5448
static t_client *firstclient = NULL;
5549

50+
/** Global mutex to protect access to the client list */
51+
pthread_mutex_t client_list_mutex = PTHREAD_MUTEX_INITIALIZER;
52+
5653
/** Get a new client struct, not added to the list yet
5754
* @return Pointer to newly created client object not on the list yet.
5855
*/

src/client_list.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* vim: set et sw=4 ts=4 sts=4 : */
12
/********************************************************************\
23
* This program is free software; you can redistribute it and/or *
34
* modify it under the terms of the GNU General Public License as *
@@ -27,6 +28,9 @@
2728
#ifndef _CLIENT_LIST_H_
2829
#define _CLIENT_LIST_H_
2930

31+
/** Global mutex to protect access to the client list */
32+
extern pthread_mutex_t client_list_mutex;
33+
3034
/** Counters struct for a client's bandwidth usage (in bytes)
3135
*/
3236
typedef struct _t_counters {

src/commandline.c

Lines changed: 116 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* vim: set et sw=4 ts=4 sts=4 : */
12
/********************************************************************\
23
* This program is free software; you can redistribute it and/or *
34
* modify it under the terms of the GNU General Public License as *
@@ -18,7 +19,6 @@
1819
* *
1920
\********************************************************************/
2021

21-
/* $Id$ */
2222
/** @file commandline.c
2323
@brief Command line argument handling
2424
@author Copyright (C) 2004 Philippe April <[email protected]>
@@ -33,28 +33,23 @@
3333
#include "debug.h"
3434
#include "safe.h"
3535
#include "conf.h"
36+
#include "commandline.h"
3637

3738
#include "../config.h"
3839

3940
/*
4041
* Holds an argv that could be passed to exec*() if we restart ourselves
4142
*/
42-
/* Declare variable */
43-
extern char ** restartargv;
44-
/* Define variable */
4543
char ** restartargv = NULL;
4644

47-
static void usage(void);
48-
49-
void parse_commandline(int argc, char **argv);
50-
51-
/*
45+
/**
5246
* A flag to denote whether we were restarted via a parent wifidog, or started normally
5347
* 0 means normally, otherwise it will be populated by the PID of the parent
5448
*/
55-
extern pid_t restart_orig_pid;
5649
pid_t restart_orig_pid = 0;
5750

51+
static void usage(void);
52+
5853
/** @internal
5954
* @brief Print usage
6055
*
@@ -73,115 +68,125 @@ usage(void)
7368
fprintf(stdout, " -w <path> Wdctl socket path\n");
7469
fprintf(stdout, " -h Print usage\n");
7570
fprintf(stdout, " -v Print version information\n");
76-
fprintf(stdout, " -x pid Used internally by WiFiDog when re-starting itself *DO NOT ISSUE THIS SWITCH MANUAlLY*\n");
71+
fprintf(stdout,
72+
" -x pid Used internally by WiFiDog when re-starting itself *DO NOT ISSUE THIS SWITCH MANUAlLY*\n");
7773
fprintf(stdout, " -i <path> Internal socket path used when re-starting self\n");
7874
fprintf(stdout, "\n");
7975
}
8076

8177
/** Uses getopt() to parse the command line and set configuration values
8278
* also populates restartargv
8379
*/
84-
void parse_commandline(int argc, char **argv) {
85-
int c;
86-
int skiponrestart;
87-
int i;
80+
void
81+
parse_commandline(int argc, char **argv)
82+
{
83+
int c;
84+
int skiponrestart;
85+
int i;
8886

8987
s_config *config = config_get_config();
9088

91-
//MAGIC 3: Our own -x, the pid, and NULL :
92-
restartargv = safe_malloc((size_t) (argc + 3) * sizeof(char*));
93-
i=0;
94-
restartargv[i++] = safe_strdup(argv[0]);
95-
96-
while (-1 != (c = getopt(argc, argv, "c:hfd:sw:vx:i:"))) {
97-
98-
skiponrestart = 0;
99-
100-
switch(c) {
101-
102-
case 'h':
103-
usage();
104-
exit(1);
105-
break;
106-
107-
case 'c':
108-
if (optarg) {
109-
strncpy(config->configfile, optarg, sizeof(config->configfile));
110-
}
111-
break;
112-
113-
case 'w':
114-
if (optarg) {
115-
free(config->wdctl_sock);
116-
config->wdctl_sock = safe_strdup(optarg);
117-
}
118-
break;
119-
120-
case 'f':
121-
skiponrestart = 1;
122-
config->daemon = 0;
123-
break;
124-
125-
case 'd':
126-
if (optarg) {
127-
config->debuglevel = atoi(optarg);
128-
}
129-
break;
130-
131-
case 's':
132-
config->log_syslog = 1;
133-
break;
134-
135-
case 'v':
136-
fprintf(stdout, "This is WiFiDog version " VERSION "\n");
137-
exit(1);
138-
break;
139-
140-
case 'x':
141-
skiponrestart = 1;
142-
if (optarg) {
143-
restart_orig_pid = atoi(optarg);
144-
}
145-
else {
146-
fprintf(stdout, "The expected PID to the -x switch was not supplied!");
147-
exit(1);
148-
}
149-
break;
150-
151-
case 'i':
152-
if (optarg) {
153-
free(config->internal_sock);
154-
config->internal_sock = safe_strdup(optarg);
155-
}
156-
break;
157-
158-
default:
159-
usage();
160-
exit(1);
161-
break;
162-
163-
}
164-
165-
if (!skiponrestart) {
166-
/* Add it to restartargv */
167-
safe_asprintf(&(restartargv[i++]), "-%c", c);
168-
if (optarg) {
169-
restartargv[i++] = safe_strdup(optarg);
170-
}
171-
}
172-
173-
}
174-
175-
/* Finally, we should add the -x, pid and NULL to restartargv
176-
* HOWEVER we cannot do it here, since this is called before we fork to background
177-
* so we'll leave this job to gateway.c after forking is completed
178-
* so that the correct PID is assigned
179-
*
180-
* We add 3 nulls, and the first 2 will be overridden later
181-
*/
182-
restartargv[i++] = NULL;
183-
restartargv[i++] = NULL;
184-
restartargv[i++] = NULL;
185-
89+
//MAGIC 3: Our own -x, the pid, and NULL :
90+
restartargv = safe_malloc((size_t) (argc + 3) * sizeof(char *));
91+
i = 0;
92+
restartargv[i++] = safe_strdup(argv[0]);
93+
94+
while (-1 != (c = getopt(argc, argv, "c:hfd:sw:vx:i:a:"))) {
95+
96+
skiponrestart = 0;
97+
98+
switch (c) {
99+
100+
case 'h':
101+
usage();
102+
exit(1);
103+
break;
104+
105+
case 'c':
106+
if (optarg) {
107+
free(config->configfile);
108+
config->configfile = safe_strdup(optarg);
109+
}
110+
break;
111+
112+
case 'w':
113+
if (optarg) {
114+
free(config->wdctl_sock);
115+
config->wdctl_sock = safe_strdup(optarg);
116+
}
117+
break;
118+
119+
case 'f':
120+
skiponrestart = 1;
121+
config->daemon = 0;
122+
break;
123+
124+
case 'd':
125+
if (optarg) {
126+
config->debuglevel = atoi(optarg);
127+
}
128+
break;
129+
130+
case 's':
131+
config->log_syslog = 1;
132+
break;
133+
134+
case 'v':
135+
fprintf(stdout, "This is WiFiDog version " VERSION "\n");
136+
exit(1);
137+
break;
138+
139+
case 'x':
140+
skiponrestart = 1;
141+
if (optarg) {
142+
restart_orig_pid = atoi(optarg);
143+
} else {
144+
fprintf(stdout, "The expected PID to the -x switch was not supplied!");
145+
exit(1);
146+
}
147+
break;
148+
149+
case 'i':
150+
if (optarg) {
151+
free(config->internal_sock);
152+
config->internal_sock = safe_strdup(optarg);
153+
}
154+
break;
155+
156+
case 'a':
157+
if (optarg) {
158+
free(config->arp_table_path);
159+
config->arp_table_path = safe_strdup(optarg);
160+
} else {
161+
fprintf(stdout, "You must supply the path to the ARP table with -a!");
162+
exit(1);
163+
}
164+
break;
165+
default:
166+
usage();
167+
exit(1);
168+
break;
169+
170+
}
171+
172+
if (!skiponrestart) {
173+
/* Add it to restartargv */
174+
safe_asprintf(&(restartargv[i++]), "-%c", c);
175+
if (optarg) {
176+
restartargv[i++] = safe_strdup(optarg);
177+
}
178+
}
179+
180+
}
181+
182+
/* Finally, we should add the -x, pid and NULL to restartargv
183+
* HOWEVER we cannot do it here, since this is called before we fork to background
184+
* so we'll leave this job to gateway.c after forking is completed
185+
* so that the correct PID is assigned
186+
*
187+
* We add 3 nulls, and the first 2 will be overridden later
188+
*/
189+
restartargv[i++] = NULL;
190+
restartargv[i++] = NULL;
191+
restartargv[i++] = NULL;
186192
}
187-

src/commandline.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* vim: set et sw=4 ts=4 sts=4 : */
12
/********************************************************************\
23
* This program is free software; you can redistribute it and/or *
34
* modify it under the terms of the GNU General Public License as *
@@ -27,7 +28,18 @@
2728
#ifndef _COMMANDLINE_H_
2829
#define _COMMANDLINE_H_
2930

31+
/*
32+
* Holds an argv that could be passed to exec*() if we restart ourselves
33+
*/
34+
extern char **restartargv;
35+
36+
/**
37+
* A flag to denote whether we were restarted via a parent wifidog, or started normally
38+
* 0 means normally, otherwise it will be populated by the PID of the parent
39+
*/
40+
extern pid_t restart_orig_pid;
41+
3042
/** @brief Parses the command line and set the config accordingly */
31-
void parse_commandline(int, char**);
43+
void parse_commandline(int, char **);
3244

33-
#endif /* _COMMANDLINE_H_ */
45+
#endif /* _COMMANDLINE_H_ */

0 commit comments

Comments
 (0)