-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.c
193 lines (170 loc) · 5.17 KB
/
debug.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
* Copyright (C) 2009-2012 B.A.T.M.A.N. contributors:
*
* Marek Lindner <lindner_marek@yahoo.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA
*
*/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <dirent.h>
#include "main.h"
#include "debug.h"
#include "debugfs.h"
#include "functions.h"
void originators_usage(void)
{
printf("Usage: batctl [options] originators \n");
printf("options:\n");
printf(" \t -h print this help\n");
printf(" \t -n don't replace mac addresses with bat-host names\n");
printf(" \t -w [interval] watch mode - refresh the originator table continuously\n");
printf(" \t -t timeout interval - don't print originators not seen for x.y seconds \n");
}
void trans_local_usage(void)
{
printf("Usage: batctl [options] translocal \n");
printf("options:\n");
printf(" \t -h print this help\n");
printf(" \t -n don't replace mac addresses with bat-host names\n");
printf(" \t -w [interval] watch mode - refresh the local translation table continuously\n");
}
void trans_global_usage(void)
{
printf("Usage: batctl [options] transglobal \n");
printf("options:\n");
printf(" \t -h print this help\n");
printf(" \t -n don't replace mac addresses with bat-host names\n");
printf(" \t -w [interval] watch mode - refresh the global translation table continuously\n");
}
void softif_neigh_usage(void)
{
printf("Usage: batctl [options] softif_neigh \n");
printf("options:\n");
printf(" \t -h print this help\n");
printf(" \t -n don't replace mac addresses with bat-host names\n");
printf(" \t -w [interval] watch mode - refresh the soft-interface neighbor table continuously\n");
}
void gateways_usage(void)
{
printf("Usage: batctl [options] gateways \n");
printf("options:\n");
printf(" \t -h print this help\n");
printf(" \t -n don't replace mac addresses with bat-host names\n");
printf(" \t -w [interval] watch mode - refresh the gateway server list continuously\n");
}
int handle_debug_table(char *mesh_iface, int argc, char **argv,
char *file_path, void table_usage(void))
{
int optchar, read_opt = USE_BAT_HOSTS;
char full_path[MAX_PATH+1];
char *debugfs_mnt;
float orig_timeout;
float watch_interval = 1;
opterr = 0;
while ((optchar = getopt(argc, argv, "hnw:t:")) != -1) {
switch (optchar) {
case 'h':
table_usage();
return EXIT_SUCCESS;
case 'n':
read_opt &= ~USE_BAT_HOSTS;
break;
case 'w':
read_opt |= CLR_CONT_READ;
if (optarg[0] == '-') {
optind--;
break;
}
if (!sscanf(optarg, "%f", &watch_interval)) {
printf("Error - provided argument of -w is not a number\n");
return EXIT_FAILURE;
}
break;
case 't':
if (table_usage != originators_usage) {
table_usage();
return EXIT_FAILURE;
}
read_opt |= NO_OLD_ORIGS;
if (!sscanf(optarg, "%f", &orig_timeout)) {
printf("Error - provided argument of -t is not a number\n");
return EXIT_FAILURE;
}
break;
case '?':
if (optopt == 't')
printf("Error - argument -t needs a number\n");
else if (optopt == 'w') {
read_opt |= CLR_CONT_READ;
break;
}
else
printf("Error - unrecognised option -%c\n", optopt);
return EXIT_FAILURE;
default:
table_usage();
return EXIT_FAILURE;
}
}
debugfs_mnt = debugfs_mount(NULL);
if (!debugfs_mnt) {
printf("Error - can't mount or find debugfs\n");
return EXIT_FAILURE;
}
debugfs_make_path(DEBUG_BATIF_PATH_FMT "/", mesh_iface, full_path, sizeof(full_path));
return read_file(full_path, file_path, read_opt, orig_timeout, watch_interval);
}
static void log_usage(void)
{
printf("Usage: batctl [options] log \n");
printf("options:\n");
printf(" \t -h print this help\n");
printf(" \t -n don't replace mac addresses with bat-host names\n");
}
int log_print(char *mesh_iface, int argc, char **argv)
{
int optchar, res, read_opt = USE_BAT_HOSTS | LOG_MODE;
char full_path[MAX_PATH+1];
char *debugfs_mnt;
while ((optchar = getopt(argc, argv, "hn")) != -1) {
switch (optchar) {
case 'h':
log_usage();
return EXIT_SUCCESS;
case 'n':
read_opt &= ~USE_BAT_HOSTS;
break;
default:
log_usage();
return EXIT_FAILURE;
}
}
debugfs_mnt = debugfs_mount(NULL);
if (!debugfs_mnt) {
printf("Error - can't mount or find debugfs\n");
return EXIT_FAILURE;
}
debugfs_make_path(DEBUG_BATIF_PATH_FMT "/", mesh_iface, full_path, sizeof(full_path));
res = read_file(full_path, DEBUG_LOG, read_opt, 0, 0);
if ((res != EXIT_SUCCESS) && (errno == ENOENT))
printf("To read the debug log you need to compile the module with debugging enabled (see the README)\n");
return res;
}