Browse Source

[cmdline] Add the "ipstat" command

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 years ago
parent
commit
f22c19f3fb
5 changed files with 150 additions and 0 deletions
  1. 3
    0
      src/config/config.c
  2. 1
    0
      src/config/general.h
  3. 70
    0
      src/hci/commands/ipstat_cmd.c
  4. 14
    0
      src/include/usr/ipstat.h
  5. 62
    0
      src/usr/ipstat.c

+ 3
- 0
src/config/config.c View File

@@ -287,6 +287,9 @@ REQUIRE_OBJECT ( ping_cmd );
287 287
 #ifdef CONSOLE_CMD
288 288
 REQUIRE_OBJECT ( console_cmd );
289 289
 #endif
290
+#ifdef IPSTAT_CMD
291
+REQUIRE_OBJECT ( ipstat_cmd );
292
+#endif
290 293
 
291 294
 /*
292 295
  * Drag in miscellaneous objects

+ 1
- 0
src/config/general.h View File

@@ -137,6 +137,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
137 137
 //#define NEIGHBOUR_CMD		/* Neighbour management commands */
138 138
 //#define PING_CMD		/* Ping command */
139 139
 //#define CONSOLE_CMD		/* Console command */
140
+//#define IPSTAT_CMD		/* IP statistics commands */
140 141
 
141 142
 /*
142 143
  * ROM-specific options

+ 70
- 0
src/hci/commands/ipstat_cmd.c View File

@@ -0,0 +1,70 @@
1
+/*
2
+ * Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17
+ * 02110-1301, USA.
18
+ */
19
+
20
+FILE_LICENCE ( GPL2_OR_LATER );
21
+
22
+#include <stdio.h>
23
+#include <getopt.h>
24
+#include <ipxe/command.h>
25
+#include <ipxe/parseopt.h>
26
+#include <usr/ipstat.h>
27
+
28
+/** @file
29
+ *
30
+ * IP statistics commands
31
+ *
32
+ */
33
+
34
+/** "ipstat" options */
35
+struct ipstat_options {};
36
+
37
+/** "ipstat" option list */
38
+static struct option_descriptor ipstat_opts[] = {};
39
+
40
+/** "ipstat" command descriptor */
41
+static struct command_descriptor ipstat_cmd =
42
+	COMMAND_DESC ( struct ipstat_options, ipstat_opts, 0, 0, NULL );
43
+
44
+/**
45
+ * The "ipstat" command
46
+ *
47
+ * @v argc		Argument count
48
+ * @v argv		Argument list
49
+ * @ret rc		Return status code
50
+ */
51
+static int ipstat_exec ( int argc, char **argv ) {
52
+	struct ipstat_options opts;
53
+	int rc;
54
+
55
+	/* Parse options */
56
+	if ( ( rc = parse_options ( argc, argv, &ipstat_cmd, &opts ) ) != 0 )
57
+		return rc;
58
+
59
+	ipstat();
60
+
61
+	return 0;
62
+}
63
+
64
+/** Routing table management commands */
65
+struct command ipstat_commands[] __command = {
66
+	{
67
+		.name = "ipstat",
68
+		.exec = ipstat_exec,
69
+	},
70
+};

+ 14
- 0
src/include/usr/ipstat.h View File

@@ -0,0 +1,14 @@
1
+#ifndef _USR_IPSTAT_H
2
+#define _USR_IPSTAT_H
3
+
4
+/** @file
5
+ *
6
+ * IP statistics
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER );
11
+
12
+extern void ipstat ( void );
13
+
14
+#endif /* _USR_IPSTAT_H */

+ 62
- 0
src/usr/ipstat.c View File

@@ -0,0 +1,62 @@
1
+/*
2
+ * Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17
+ * 02110-1301, USA.
18
+ */
19
+
20
+FILE_LICENCE ( GPL2_OR_LATER );
21
+
22
+#include <stdio.h>
23
+#include <ipxe/ipstat.h>
24
+#include <usr/ipstat.h>
25
+
26
+/** @file
27
+ *
28
+ * IP statistics
29
+ *
30
+ */
31
+
32
+/**
33
+ * Print IP statistics
34
+ *
35
+ */
36
+void ipstat ( void ) {
37
+	struct ip_statistics_family *family;
38
+	struct ip_statistics *stats;
39
+
40
+	for_each_table_entry ( family, IP_STATISTICS_FAMILIES ) {
41
+		stats = family->stats;
42
+		printf ( "IP version %d:\n", family->version );
43
+		printf ( "  InReceives:%ld InMcastPkts:%ld InBcastPkts:%ld "
44
+			 "InOctets:%ld\n", stats->in_receives,
45
+			 stats->in_mcast_pkts, stats->in_bcast_pkts,
46
+			 stats->in_octets );
47
+		printf ( "  InHdrErrors:%ld InAddrErrors:%ld "
48
+			 "InUnknownProtos:%ld InTruncatedPkts:%ld\n",
49
+			 stats->in_hdr_errors, stats->in_addr_errors,
50
+			 stats->in_unknown_protos, stats->in_truncated_pkts );
51
+		printf ( "  ReasmReqds:%ld ReasmOKs:%ld ReasmFails:%ld\n",
52
+			 stats->reasm_reqds, stats->reasm_oks,
53
+			 stats->reasm_fails );
54
+		printf ( "  InDelivers:%ld OutRequests:%ld OutNoRoutes:%ld\n",
55
+			 stats->in_delivers, stats->out_requests,
56
+			 stats->out_no_routes );
57
+		printf ( "  OutTransmits:%ld OutMcastPkts:%ld OutBcastPkts:%ld "
58
+			 "OutOctets:%ld\n", stats->out_transmits,
59
+			 stats->out_mcast_pkts, stats->out_bcast_pkts,
60
+			 stats->out_octets );
61
+	}
62
+}

Loading…
Cancel
Save