root/trunk/batctl/main.c @ 1596

Revision 1596, 5.9 kB (checked in by marek, 6 months ago)

batctl: adding batctl bonding mode support

Signed-off-by: Marek Lindner <lindner_marek@…>

Line 
1/*
2 * Copyright (C) 2007-2009 B.A.T.M.A.N. contributors:
3 *
4 * Andreas Langer <a.langer@q-dsl.de>, Marek Lindner <lindner_marek@yahoo.de>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22
23
24#include <sys/types.h>
25#include <stdio.h>
26#include <stdint.h>
27#include <stdlib.h>
28#include <unistd.h>
29#include <string.h>
30
31#include "main.h"
32#include "proc.h"
33#include "sys.h"
34#include "ping.h"
35#include "traceroute.h"
36#include "tcpdump.h"
37#include "bisect.h"
38#include "vis.h"
39
40
41void print_usage(void) {
42        printf("Usage: batctl [options] commands \n");
43        printf("commands:\n");
44        printf(" \tinterface|if   [none|interface]  \tdisplay or modify the interface settings\n");
45        printf(" \toriginators|o                    \tdisplay the originator table\n");
46        printf(" \tinterval|it    [orig_interval]   \tdisplay or modify the originator interval in ms\n");
47        printf(" \tloglevel|ll    [level]           \tdisplay or modify the log level\n");
48        printf(" \tlog|l                            \tread the log produced by the kernel module\n");
49        printf(" \tgw_mode|gw     [mode]            \tdisplay or modify the gateway mode\n");
50        printf(" \tgw_srv_list|gwl                  \tdisplay the gateway server list\n");
51        printf(" \ttranslocal|tl                    \tdisplay the local translation table\n");
52        printf(" \ttransglobal|tg                   \tdisplay the global translation table\n");
53        printf(" \tvis_server|vs  [enable|disable]  \tdisplay or modify the status of the VIS server\n");
54        printf(" \tvis_data|vd    [dot|JSON]        \tdisplay the VIS data in dot or JSON format\n");
55        printf(" \taggregation|ag [0|1]             \tdisplay or modify the packet aggregation setting\n");
56        printf(" \tbonding|b      [0|1]             \tdisplay or modify the bonding mode setting\n");
57        printf("\n");
58        printf(" \tping|p         <destination>     \tping another batman adv host via layer 2\n");
59        printf(" \ttraceroute|tr  <destination>     \ttraceroute another batman adv host via layer 2\n");
60        printf(" \ttcpdump|td     <interface>       \ttcpdump layer 2 traffic on the given interface\n");
61        printf(" \tbisect         <file1> .. <fileN>\tanalyze given log files for routing stability\n");
62        printf("options:\n");
63        printf(" \t-h print this help (or 'batctl <command> -h' for the command specific help)\n");
64        printf(" \t-v print version\n");
65}
66
67int main(int argc, char **argv)
68{
69        int ret = EXIT_FAILURE;
70
71        if ((argc < 2) || (strcmp(argv[1], "-h") == 0)) {
72                print_usage();
73                exit(EXIT_FAILURE);
74        }
75
76        if (strcmp(argv[1], "-v") == 0) {
77                printf("batctl %s%s\n", SOURCE_VERSION, (strlen(REVISION_VERSION) > 3 ? REVISION_VERSION : ""));
78                exit(EXIT_SUCCESS);
79        }
80
81        /* TODO: remove this generic check here and move it into the individual functions */
82        /* check if user is root */
83        if ((strcmp(argv[1], "bisect") != 0) && ((getuid()) || (getgid()))) {
84                fprintf(stderr, "Error - you must be root to run '%s' !\n", argv[0]);
85                exit(EXIT_FAILURE);
86        }
87
88        if ((strcmp(argv[1], "ping") == 0) || (strcmp(argv[1], "p") == 0)) {
89
90                ret = ping(argc - 1, argv + 1);
91
92        } else if ((strcmp(argv[1], "traceroute") == 0) || (strcmp(argv[1], "tr") == 0)) {
93
94                ret = traceroute(argc - 1, argv + 1);
95
96        } else if ((strcmp(argv[1], "tcpdump") == 0) || (strcmp(argv[1], "td") == 0)) {
97
98                ret = tcpdump(argc - 1, argv + 1);
99
100        } else if ((strcmp(argv[1], "interface") == 0) || (strcmp(argv[1], "if") == 0)) {
101
102                ret = interface(argc - 1, argv + 1);
103
104        } else if ((strcmp(argv[1], "originators") == 0) || (strcmp(argv[1], "o") == 0)) {
105
106                ret = handle_sys_table(argc - 1, argv + 1, SYS_ORIGINATORS, originators_usage);
107
108        } else if ((strcmp(argv[1], "translocal") == 0) || (strcmp(argv[1], "tl") == 0)) {
109
110                ret = handle_sys_table(argc - 1, argv + 1, SYS_TRANSTABLE_LOCAL, trans_local_usage);
111
112        } else if ((strcmp(argv[1], "transglobal") == 0) || (strcmp(argv[1], "tg") == 0)) {
113
114                ret = handle_sys_table(argc - 1, argv + 1, SYS_TRANSTABLE_GLOBAL, trans_global_usage);
115
116        } else if ((strcmp(argv[1], "loglevel") == 0) || (strcmp(argv[1], "ll") == 0)) {
117
118                ret = handle_loglevel(argc - 1, argv + 1);
119
120        } else if ((strcmp(argv[1], "log") == 0) || (strcmp(argv[1], "l") == 0)) {
121
122                ret = log_print(argc - 1, argv + 1);
123
124        } else if ((strcmp(argv[1], "interval") == 0) || (strcmp(argv[1], "it") == 0)) {
125
126                ret = handle_proc_setting(argc - 1, argv + 1, PROC_ORIG_INTERVAL, orig_interval_usage);
127
128        } else if ((strcmp(argv[1], "vis_server") == 0) || (strcmp(argv[1], "vs") == 0)) {
129
130                ret = handle_proc_setting(argc - 1, argv + 1, PROC_VIS_SERVER, vis_server_usage);
131
132        } else if ((strcmp(argv[1], "vis_data") == 0) || (strcmp(argv[1], "vd") == 0)) {
133
134                ret = vis_data(argc - 1, argv + 1);
135
136        } else if ((strcmp(argv[1], "gw_mode") == 0) || (strcmp(argv[1], "gw") == 0)) {
137
138                ret = handle_proc_setting(argc - 1, argv + 1, PROC_GW_MODE, gw_mode_usage);
139
140        } else if ((strcmp(argv[1], "gw_srv_list") == 0) || (strcmp(argv[1], "gwl") == 0)) {
141
142                ret = handle_table(argc - 1, argv + 1, PROC_GW_SRV_LIST, gw_srv_list_usage);
143
144        } else if ((strcmp(argv[1], "aggregation") == 0) || (strcmp(argv[1], "ag") == 0)) {
145
146                ret = handle_sys_setting(argc - 1, argv + 1, SYS_AGGR, aggregation_usage);
147
148        } else if ((strcmp(argv[1], "bonding") == 0) || (strcmp(argv[1], "b") == 0)) {
149
150                ret = handle_sys_setting(argc - 1, argv + 1, SYS_BONDING, bonding_usage);
151
152        } else if ((strcmp(argv[1], "bisect") == 0)) {
153
154                ret = bisect(argc - 1, argv + 1);
155
156        } else {
157                print_usage();
158        }
159
160        return ret;
161}
Note: See TracBrowser for help on using the browser.