2 * Copyright (c) 2011 Nicira, Inc.
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>
26 #include <sys/socket.h>
31 #include "command-line.h"
34 #define ADD_ALL_VLANS_CMD 10
35 #define DEL_ALL_VLANS_CMD 11
37 static void usage(void);
38 static void parse_options(int argc
, char *argv
[]);
41 main(int argc
, char *argv
[])
43 struct vlan_ioctl_args vlan_args
;
44 const char *netdev
, *setting
;
47 set_program_name(argv
[0]);
49 parse_options(argc
, argv
);
50 if (argc
- optind
!= 2) {
51 ovs_fatal(0, "exactly two non-option arguments are required "
52 "(use --help for help)");
55 memset(&vlan_args
, 0, sizeof vlan_args
);
58 setting
= argv
[optind
+ 1];
59 if (!strcmp(setting
, "on")) {
60 vlan_args
.cmd
= ADD_ALL_VLANS_CMD
;
61 } else if (!strcmp(setting
, "off")) {
62 vlan_args
.cmd
= DEL_ALL_VLANS_CMD
;
64 ovs_fatal(0, "second command line argument must be \"on\" or \"off\" "
65 "(not \"%s\")", setting
);
68 /* Get network device name. */
69 netdev
= argv
[optind
];
70 if (strlen(netdev
) >= IFNAMSIZ
) {
71 ovs_fatal(0, "%s: network device name too long", netdev
);
73 strcpy(vlan_args
.device1
, netdev
);
75 /* Execute operation. */
76 fd
= socket(AF_INET
, SOCK_STREAM
, 0);
78 ovs_fatal(errno
, "socket creation failed");
80 if (ioctl(fd
, SIOCSIFVLAN
, &vlan_args
) < 0) {
81 if (errno
== ENOPKG
) {
82 ovs_fatal(0, "operation failed (8021q module not loaded)");
83 } else if (errno
== EOPNOTSUPP
) {
84 ovs_fatal(0, "operation failed (kernel does not support the "
85 "VLAN bug workaround)");
87 ovs_fatal(errno
, "operation failed");
99 %s, for enabling or disabling the kernel VLAN bug workaround\n\
100 usage: %s NETDEV SETTING\n\
101 where NETDEV is a network device (e.g. \"eth0\")\n\
102 and SETTING is \"on\" to enable the workaround or \"off\" to disable it.\n\
105 -h, --help Print this helpful information\n\
106 -V, --version Display version information\n",
107 program_name
, program_name
);
112 parse_options(int argc
, char *argv
[])
114 static const struct option long_options
[] = {
115 {"help", no_argument
, NULL
, 'h'},
116 {"version", no_argument
, NULL
, 'V'},
119 char *short_options
= ovs_cmdl_long_options_to_short_options(long_options
);
124 option
= getopt_long(argc
, argv
, "+t:hVe", long_options
, NULL
);
134 ovs_print_version(0, 0);