]> git.proxmox.com Git - mirror_ovs.git/blob - utilities/ovs-dpctl.c
rhel: Add option to enable AF_XDP on rpm package.
[mirror_ovs.git] / utilities / ovs-dpctl.c
1 /*
2 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <config.h>
18 #include <sys/types.h>
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
21 #include <errno.h>
22 #include <getopt.h>
23 #include <inttypes.h>
24 #include <sys/socket.h>
25 #include <net/if.h>
26 #include <signal.h>
27 #include <stdarg.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <unistd.h>
31 #include <sys/stat.h>
32 #include <sys/time.h>
33
34 #include "command-line.h"
35 #include "compiler.h"
36 #include "dirs.h"
37 #include "dpctl.h"
38 #include "fatal-signal.h"
39 #include "odp-util.h"
40 #include "packets.h"
41 #include "timeval.h"
42 #include "util.h"
43 #include "openvswitch/vlog.h"
44
45 static struct dpctl_params dpctl_p;
46
47 OVS_NO_RETURN static void usage(void *userdata OVS_UNUSED);
48 static void parse_options(int argc, char *argv[]);
49
50 static void
51 dpctl_print(void *userdata OVS_UNUSED, bool error, const char *msg)
52 {
53 FILE *outfile = error ? stderr : stdout;
54 fputs(msg, outfile);
55 }
56
57 int
58 main(int argc, char *argv[])
59 {
60 int error;
61 set_program_name(argv[0]);
62 parse_options(argc, argv);
63 fatal_ignore_sigpipe();
64
65 dpctl_p.is_appctl = false;
66 dpctl_p.output = dpctl_print;
67 dpctl_p.usage = usage;
68
69 error = dpctl_run_command(argc - optind, (const char **) argv + optind,
70 &dpctl_p);
71 return error ? EXIT_FAILURE : EXIT_SUCCESS;
72 }
73
74 static void
75 parse_options(int argc, char *argv[])
76 {
77 enum {
78 OPT_CLEAR = UCHAR_MAX + 1,
79 OPT_MAY_CREATE,
80 OPT_READ_ONLY,
81 OPT_NAMES,
82 OPT_NO_NAMES,
83 VLOG_OPTION_ENUMS
84 };
85 static const struct option long_options[] = {
86 {"statistics", no_argument, NULL, 's'},
87 {"clear", no_argument, NULL, OPT_CLEAR},
88 {"may-create", no_argument, NULL, OPT_MAY_CREATE},
89 {"read-only", no_argument, NULL, OPT_READ_ONLY},
90 {"more", no_argument, NULL, 'm'},
91 {"names", no_argument, NULL, OPT_NAMES},
92 {"no-names", no_argument, NULL, OPT_NO_NAMES},
93 {"timeout", required_argument, NULL, 't'},
94 {"help", no_argument, NULL, 'h'},
95 {"option", no_argument, NULL, 'o'},
96 {"version", no_argument, NULL, 'V'},
97 VLOG_LONG_OPTIONS,
98 {NULL, 0, NULL, 0},
99 };
100 char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
101
102 bool set_names = false;
103 unsigned int timeout = 0;
104
105 for (;;) {
106 int c;
107
108 c = getopt_long(argc, argv, short_options, long_options, NULL);
109 if (c == -1) {
110 break;
111 }
112
113 switch (c) {
114 case 's':
115 dpctl_p.print_statistics = true;
116 break;
117
118 case OPT_CLEAR:
119 dpctl_p.zero_statistics = true;
120 break;
121
122 case OPT_MAY_CREATE:
123 dpctl_p.may_create = true;
124 break;
125
126 case OPT_READ_ONLY:
127 dpctl_p.read_only = true;
128 break;
129
130 case 'm':
131 dpctl_p.verbosity++;
132 break;
133
134 case OPT_NAMES:
135 dpctl_p.names = true;
136 set_names = true;
137 break;
138
139 case OPT_NO_NAMES:
140 dpctl_p.names = false;
141 set_names = true;
142 break;
143
144 case 't':
145 if (!str_to_uint(optarg, 10, &timeout) || !timeout) {
146 ovs_fatal(0, "value %s on -t or --timeout is invalid", optarg);
147 }
148 break;
149
150 case 'h':
151 usage(NULL);
152
153 case 'o':
154 ovs_cmdl_print_options(long_options);
155 exit(EXIT_SUCCESS);
156
157 case 'V':
158 ovs_print_version(0, 0);
159 exit(EXIT_SUCCESS);
160
161 VLOG_OPTION_HANDLERS
162
163 case '?':
164 exit(EXIT_FAILURE);
165
166 default:
167 abort();
168 }
169 }
170 free(short_options);
171
172 ctl_timeout_setup(timeout);
173
174 if (!set_names) {
175 dpctl_p.names = dpctl_p.verbosity > 0;
176 }
177 }
178
179 static void
180 usage(void *userdata OVS_UNUSED)
181 {
182 printf("%s: Open vSwitch datapath management utility\n"
183 "usage: %s [OPTIONS] COMMAND [ARG...]\n"
184 " add-dp DP [IFACE...] add new datapath DP (with IFACEs)\n"
185 " del-dp DP delete local datapath DP\n"
186 " add-if DP IFACE... add each IFACE as a port on DP\n"
187 " set-if DP IFACE... reconfigure each IFACE within DP\n"
188 " del-if DP IFACE... delete each IFACE from DP\n"
189 " dump-dps display names of all datapaths\n"
190 " show show basic info on all datapaths\n"
191 " show DP... show basic info on each DP\n"
192 " dump-flows [DP] display flows in DP\n"
193 " add-flow [DP] FLOW ACTIONS add FLOW with ACTIONS to DP\n"
194 " add-flows [DP] FILE add flows from FILE\n"
195 " mod-flow [DP] FLOW ACTIONS change FLOW actions to ACTIONS in DP\n"
196 " mod-flows [DP] FILE change flows from FILE\n"
197 " get-flow [DP] ufid:UFID fetch flow corresponding to UFID\n"
198 " del-flow [DP] FLOW delete FLOW from DP\n"
199 " del-flows [DP] [FILE] " \
200 "delete all or specified flows from DP\n"
201 " dump-conntrack [DP] [zone=ZONE] " \
202 "display conntrack entries for ZONE\n"
203 " flush-conntrack [DP] [zone=ZONE] [ct-tuple]" \
204 "delete matched conntrack entries in ZONE\n"
205 " ct-stats-show [DP] [zone=ZONE] [verbose] " \
206 "CT connections grouped by protocol\n"
207 " ct-bkts [DP] [gt=N] display connections per CT bucket\n"
208 "Each IFACE on add-dp, add-if, and set-if may be followed by\n"
209 "comma-separated options. See ovs-dpctl(8) for syntax, or the\n"
210 "Interface table in ovs-vswitchd.conf.db(5) for an options list.\n"
211 "For COMMAND dump-flows, add-flow, add-flows, mod-flow,\n"
212 "mod-flows, del-flow and del-flows, DP is optional if there is\n"
213 "only one datapath.\n",
214 program_name, program_name);
215 vlog_usage();
216 printf("\nOptions for show and mod-flow:\n"
217 " -s, --statistics print statistics for port or flow\n"
218 "\nOptions for dump-flows:\n"
219 " -m, --more increase verbosity of output\n"
220 " --names use port names in output\n"
221 "\nOptions for mod-flow:\n"
222 " --may-create create flow if it doesn't exist\n"
223 " --read-only do not run read/write commands\n"
224 " --clear reset existing stats to zero\n"
225 "\nOther options:\n"
226 " -t, --timeout=SECS give up after SECS seconds\n"
227 " -h, --help display this help message\n"
228 " -V, --version display version information\n");
229 exit(EXIT_SUCCESS);
230 }