summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/vconfig.c96
1 files changed, 41 insertions, 55 deletions
diff --git a/networking/vconfig.c b/networking/vconfig.c
index ac8b96d..924b2f0 100644
--- a/networking/vconfig.c
+++ b/networking/vconfig.c
@@ -13,12 +13,12 @@
//usage: "COMMAND [OPTIONS]"
//usage:#define vconfig_full_usage "\n\n"
//usage: "Create and remove virtual ethernet devices\n"
-//usage: "\n add [interface-name] [vlan_id]"
-//usage: "\n rem [vlan-name]"
-//usage: "\n set_flag [interface-name] [flag-num] [0 | 1]"
-//usage: "\n set_egress_map [vlan-name] [skb_priority] [vlan_qos]"
-//usage: "\n set_ingress_map [vlan-name] [skb_priority] [vlan_qos]"
-//usage: "\n set_name_type [name-type]"
+//usage: "\n add IFACE VLAN_ID"
+//usage: "\n rem VLAN_NAME"
+//usage: "\n set_flag IFACE 0|1 VLAN_QOS"
+//usage: "\n set_egress_map VLAN_NAME SKB_PRIO VLAN_QOS"
+//usage: "\n set_ingress_map VLAN_NAME SKB_PRIO VLAN_QOS"
+//usage: "\n set_name_type NAME_TYPE"
#include "libbb.h"
#include <net/if.h>
@@ -66,54 +66,38 @@ struct vlan_ioctl_args {
* The return value is the last data entry for the matching string. */
static const char *xfind_str(const char *table, const char *str)
{
- while (strcasecmp(str, table+1) != 0) {
- table += table[0];
- if (!*table) {
+ while (strcasecmp(str, table + 1) != 0) {
+ if (!table[0])
bb_show_usage();
- }
+ table += table[0];
}
return table - 1;
}
static const char cmds[] ALIGN1 = {
4, ADD_VLAN_CMD, 7,
- 'a', 'd', 'd', 0,
+ 'a','d','d',0,
3, DEL_VLAN_CMD, 7,
- 'r', 'e', 'm', 0,
+ 'r','e','m',0,
3, SET_VLAN_NAME_TYPE_CMD, 17,
- 's', 'e', 't', '_',
- 'n', 'a', 'm', 'e', '_',
- 't', 'y', 'p', 'e', 0,
+ 's','e','t','_','n','a','m','e','_','t','y','p','e',0,
5, SET_VLAN_FLAG_CMD, 12,
- 's', 'e', 't', '_',
- 'f', 'l', 'a', 'g', 0,
+ 's','e','t','_','f','l','a','g',0,
5, SET_VLAN_EGRESS_PRIORITY_CMD, 18,
- 's', 'e', 't', '_',
- 'e', 'g', 'r', 'e', 's', 's', '_',
- 'm', 'a', 'p', 0,
- 5, SET_VLAN_INGRESS_PRIORITY_CMD, 16,
- 's', 'e', 't', '_',
- 'i', 'n', 'g', 'r', 'e', 's', 's', '_',
- 'm', 'a', 'p', 0,
+ 's','e','t','_','e','g','r','e','s','s','_','m','a','p',0,
+ 5, SET_VLAN_INGRESS_PRIORITY_CMD, 0,
+ 's','e','t','_','i','n','g','r','e','s','s','_','m','a','p',0,
};
static const char name_types[] ALIGN1 = {
VLAN_NAME_TYPE_PLUS_VID, 16,
- 'V', 'L', 'A', 'N',
- '_', 'P', 'L', 'U', 'S', '_', 'V', 'I', 'D',
- 0,
+ 'V','L','A','N','_','P','L','U','S','_','V','I','D',0,
VLAN_NAME_TYPE_PLUS_VID_NO_PAD, 22,
- 'V', 'L', 'A', 'N',
- '_', 'P', 'L', 'U', 'S', '_', 'V', 'I', 'D',
- '_', 'N', 'O', '_', 'P', 'A', 'D', 0,
+ 'V','L','A','N','_','P','L','U','S','_','V','I','D','_','N','O','_','P','A','D',0,
VLAN_NAME_TYPE_RAW_PLUS_VID, 15,
- 'D', 'E', 'V',
- '_', 'P', 'L', 'U', 'S', '_', 'V', 'I', 'D',
- 0,
- VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD, 20,
- 'D', 'E', 'V',
- '_', 'P', 'L', 'U', 'S', '_', 'V', 'I', 'D',
- '_', 'N', 'O', '_', 'P', 'A', 'D', 0,
+ 'D','E','V','_','P','L','U','S','_','V','I','D',0,
+ VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD, 0,
+ 'D','E','V','_','P','L','U','S','_','V','I','D','_','N','O','_','P','A','D',0,
};
int vconfig_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -123,21 +107,19 @@ int vconfig_main(int argc, char **argv)
const char *p;
int fd;
- if (argc < 3) {
- bb_show_usage();
- }
-
memset(&ifr, 0, sizeof(ifr));
++argv;
- p = xfind_str(cmds+2, *argv);
+ if (!argv[0])
+ bb_show_usage();
+ p = xfind_str(cmds + 2, argv[0]);
ifr.cmd = *p;
- if (argc != p[-1]) {
+ if (argc != p[-1])
bb_show_usage();
- }
- if (ifr.cmd == SET_VLAN_NAME_TYPE_CMD) { /* set_name_type */
- ifr.u.name_type = *xfind_str(name_types+1, argv[1]);
+ if (ifr.cmd == SET_VLAN_NAME_TYPE_CMD) {
+ /* set_name_type */
+ ifr.u.name_type = *xfind_str(name_types + 1, argv[1]);
} else {
strncpy_IFNAMSIZ(ifr.device1, argv[1]);
p = argv[2];
@@ -146,22 +128,26 @@ int vconfig_main(int argc, char **argv)
* since ifr.u.flag, ifr.u.VID, and ifr.u.skb_priority are all same-sized
* (unsigned) int members of a unions. But because of the range checking,
* doing so wouldn't save that much space and would also make maintainence
- * more of a pain. */
- if (ifr.cmd == SET_VLAN_FLAG_CMD) { /* set_flag */
- ifr.u.flag = xatoul_range(p, 0, 1);
+ * more of a pain.
+ */
+ if (ifr.cmd == SET_VLAN_FLAG_CMD) {
+ /* set_flag */
+ ifr.u.flag = xatou_range(p, 0, 1);
/* DM: in order to set reorder header, qos must be set */
- ifr.vlan_qos = xatoul_range(argv[3], 0, 7);
- } else if (ifr.cmd == ADD_VLAN_CMD) { /* add */
- ifr.u.VID = xatoul_range(p, 0, VLAN_GROUP_ARRAY_LEN-1);
- } else if (ifr.cmd != DEL_VLAN_CMD) { /* set_{egress|ingress}_map */
+ ifr.vlan_qos = xatou_range(argv[3], 0, 7);
+ } else if (ifr.cmd == ADD_VLAN_CMD) {
+ /* add */
+ ifr.u.VID = xatou_range(p, 0, VLAN_GROUP_ARRAY_LEN - 1);
+ } else if (ifr.cmd != DEL_VLAN_CMD) {
+ /* set_{egress|ingress}_map */
ifr.u.skb_priority = xatou(p);
- ifr.vlan_qos = xatoul_range(argv[3], 0, 7);
+ ifr.vlan_qos = xatou_range(argv[3], 0, 7);
}
}
fd = xsocket(AF_INET, SOCK_STREAM, 0);
ioctl_or_perror_and_die(fd, SIOCSIFVLAN, &ifr,
- "ioctl error for %s", *argv);
+ "ioctl error for %s", argv[0]);
return 0;
}