2 * Copyright (c) 2011 Nicira Networks.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <linux/if_vlan.h>
22 #include <linux/sockios.h>
25 #include <sys/ioctl.h>
30 #include "command-line.h"
33 #define ADD_ALL_VLANS_CMD 10
34 #define DEL_ALL_VLANS_CMD 11
36 static void usage(void);
37 static void parse_options(int argc, char *argv[]);
40 main(int argc, char *argv[])
42 struct vlan_ioctl_args vlan_args;
43 const char *netdev, *setting;
46 set_program_name(argv[0]);
48 parse_options(argc, argv);
49 if (argc - optind != 2) {
50 ovs_fatal(0, "exactly two non-option arguments are required "
51 "(use --help for help)");
54 memset(&vlan_args, 0, sizeof vlan_args);
57 setting = argv[optind + 1];
58 if (!strcmp(setting, "on")) {
59 vlan_args.cmd = ADD_ALL_VLANS_CMD;
60 } else if (!strcmp(setting, "off")) {
61 vlan_args.cmd = DEL_ALL_VLANS_CMD;
63 ovs_fatal(0, "second command line argument must be \"on\" or \"off\" "
64 "(not \"%s\")", setting);
67 /* Get network device name. */
68 netdev = argv[optind];
69 if (strlen(netdev) >= IFNAMSIZ) {
70 ovs_fatal(0, "%s: network device name too long", netdev);
72 strcpy(vlan_args.device1, netdev);
74 /* Execute operation. */
75 fd = socket(AF_INET, SOCK_STREAM, 0);
77 ovs_fatal(errno, "socket creation failed");
79 if (ioctl(fd, SIOCSIFVLAN, &vlan_args) < 0) {
80 if (errno == ENOPKG) {
81 ovs_fatal(0, "operation failed (8021q module not loaded)");
82 } else if (errno == EOPNOTSUPP) {
83 ovs_fatal(0, "operation failed (kernel does not support the "
84 "VLAN bug workaround)");
86 ovs_fatal(errno, "operation failed");
98 %s, for enabling or disabling the kernel VLAN bug workaround\n\
99 usage: %s NETDEV SETTING\n\
100 where NETDEV is a network device (e.g. \"eth0\")\n\
101 and SETTING is \"on\" to enable the workaround or \"off\" to disable it.\n\
104 -h, --help Print this helpful information\n\
105 -V, --version Display version information\n",
106 program_name, program_name);
111 parse_options(int argc, char *argv[])
113 static const struct option long_options[] = {
114 {"help", no_argument, NULL, 'h'},
115 {"version", no_argument, NULL, 'V'},
118 char *short_options = long_options_to_short_options(long_options);
123 option = getopt_long(argc, argv, "+t:hVe", long_options, NULL);
133 OVS_PRINT_VERSION(0, 0);