diff options
-rw-r--r-- | networking/vconfig.c | 96 |
1 files changed, 41 insertions, 55 deletions
diff --git a/networking/vconfig.c b/networking/vconfig.c index ac8b96d8c..924b2f009 100644 --- a/networking/vconfig.c +++ b/networking/vconfig.c | |||
@@ -13,12 +13,12 @@ | |||
13 | //usage: "COMMAND [OPTIONS]" | 13 | //usage: "COMMAND [OPTIONS]" |
14 | //usage:#define vconfig_full_usage "\n\n" | 14 | //usage:#define vconfig_full_usage "\n\n" |
15 | //usage: "Create and remove virtual ethernet devices\n" | 15 | //usage: "Create and remove virtual ethernet devices\n" |
16 | //usage: "\n add [interface-name] [vlan_id]" | 16 | //usage: "\n add IFACE VLAN_ID" |
17 | //usage: "\n rem [vlan-name]" | 17 | //usage: "\n rem VLAN_NAME" |
18 | //usage: "\n set_flag [interface-name] [flag-num] [0 | 1]" | 18 | //usage: "\n set_flag IFACE 0|1 VLAN_QOS" |
19 | //usage: "\n set_egress_map [vlan-name] [skb_priority] [vlan_qos]" | 19 | //usage: "\n set_egress_map VLAN_NAME SKB_PRIO VLAN_QOS" |
20 | //usage: "\n set_ingress_map [vlan-name] [skb_priority] [vlan_qos]" | 20 | //usage: "\n set_ingress_map VLAN_NAME SKB_PRIO VLAN_QOS" |
21 | //usage: "\n set_name_type [name-type]" | 21 | //usage: "\n set_name_type NAME_TYPE" |
22 | 22 | ||
23 | #include "libbb.h" | 23 | #include "libbb.h" |
24 | #include <net/if.h> | 24 | #include <net/if.h> |
@@ -66,54 +66,38 @@ struct vlan_ioctl_args { | |||
66 | * The return value is the last data entry for the matching string. */ | 66 | * The return value is the last data entry for the matching string. */ |
67 | static const char *xfind_str(const char *table, const char *str) | 67 | static const char *xfind_str(const char *table, const char *str) |
68 | { | 68 | { |
69 | while (strcasecmp(str, table+1) != 0) { | 69 | while (strcasecmp(str, table + 1) != 0) { |
70 | table += table[0]; | 70 | if (!table[0]) |
71 | if (!*table) { | ||
72 | bb_show_usage(); | 71 | bb_show_usage(); |
73 | } | 72 | table += table[0]; |
74 | } | 73 | } |
75 | return table - 1; | 74 | return table - 1; |
76 | } | 75 | } |
77 | 76 | ||
78 | static const char cmds[] ALIGN1 = { | 77 | static const char cmds[] ALIGN1 = { |
79 | 4, ADD_VLAN_CMD, 7, | 78 | 4, ADD_VLAN_CMD, 7, |
80 | 'a', 'd', 'd', 0, | 79 | 'a','d','d',0, |
81 | 3, DEL_VLAN_CMD, 7, | 80 | 3, DEL_VLAN_CMD, 7, |
82 | 'r', 'e', 'm', 0, | 81 | 'r','e','m',0, |
83 | 3, SET_VLAN_NAME_TYPE_CMD, 17, | 82 | 3, SET_VLAN_NAME_TYPE_CMD, 17, |
84 | 's', 'e', 't', '_', | 83 | 's','e','t','_','n','a','m','e','_','t','y','p','e',0, |
85 | 'n', 'a', 'm', 'e', '_', | ||
86 | 't', 'y', 'p', 'e', 0, | ||
87 | 5, SET_VLAN_FLAG_CMD, 12, | 84 | 5, SET_VLAN_FLAG_CMD, 12, |
88 | 's', 'e', 't', '_', | 85 | 's','e','t','_','f','l','a','g',0, |
89 | 'f', 'l', 'a', 'g', 0, | ||
90 | 5, SET_VLAN_EGRESS_PRIORITY_CMD, 18, | 86 | 5, SET_VLAN_EGRESS_PRIORITY_CMD, 18, |
91 | 's', 'e', 't', '_', | 87 | 's','e','t','_','e','g','r','e','s','s','_','m','a','p',0, |
92 | 'e', 'g', 'r', 'e', 's', 's', '_', | 88 | 5, SET_VLAN_INGRESS_PRIORITY_CMD, 0, |
93 | 'm', 'a', 'p', 0, | 89 | 's','e','t','_','i','n','g','r','e','s','s','_','m','a','p',0, |
94 | 5, SET_VLAN_INGRESS_PRIORITY_CMD, 16, | ||
95 | 's', 'e', 't', '_', | ||
96 | 'i', 'n', 'g', 'r', 'e', 's', 's', '_', | ||
97 | 'm', 'a', 'p', 0, | ||
98 | }; | 90 | }; |
99 | 91 | ||
100 | static const char name_types[] ALIGN1 = { | 92 | static const char name_types[] ALIGN1 = { |
101 | VLAN_NAME_TYPE_PLUS_VID, 16, | 93 | VLAN_NAME_TYPE_PLUS_VID, 16, |
102 | 'V', 'L', 'A', 'N', | 94 | 'V','L','A','N','_','P','L','U','S','_','V','I','D',0, |
103 | '_', 'P', 'L', 'U', 'S', '_', 'V', 'I', 'D', | ||
104 | 0, | ||
105 | VLAN_NAME_TYPE_PLUS_VID_NO_PAD, 22, | 95 | VLAN_NAME_TYPE_PLUS_VID_NO_PAD, 22, |
106 | 'V', 'L', 'A', 'N', | 96 | 'V','L','A','N','_','P','L','U','S','_','V','I','D','_','N','O','_','P','A','D',0, |
107 | '_', 'P', 'L', 'U', 'S', '_', 'V', 'I', 'D', | ||
108 | '_', 'N', 'O', '_', 'P', 'A', 'D', 0, | ||
109 | VLAN_NAME_TYPE_RAW_PLUS_VID, 15, | 97 | VLAN_NAME_TYPE_RAW_PLUS_VID, 15, |
110 | 'D', 'E', 'V', | 98 | 'D','E','V','_','P','L','U','S','_','V','I','D',0, |
111 | '_', 'P', 'L', 'U', 'S', '_', 'V', 'I', 'D', | 99 | VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD, 0, |
112 | 0, | 100 | 'D','E','V','_','P','L','U','S','_','V','I','D','_','N','O','_','P','A','D',0, |
113 | VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD, 20, | ||
114 | 'D', 'E', 'V', | ||
115 | '_', 'P', 'L', 'U', 'S', '_', 'V', 'I', 'D', | ||
116 | '_', 'N', 'O', '_', 'P', 'A', 'D', 0, | ||
117 | }; | 101 | }; |
118 | 102 | ||
119 | int vconfig_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 103 | int vconfig_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
@@ -123,21 +107,19 @@ int vconfig_main(int argc, char **argv) | |||
123 | const char *p; | 107 | const char *p; |
124 | int fd; | 108 | int fd; |
125 | 109 | ||
126 | if (argc < 3) { | ||
127 | bb_show_usage(); | ||
128 | } | ||
129 | |||
130 | memset(&ifr, 0, sizeof(ifr)); | 110 | memset(&ifr, 0, sizeof(ifr)); |
131 | 111 | ||
132 | ++argv; | 112 | ++argv; |
133 | p = xfind_str(cmds+2, *argv); | 113 | if (!argv[0]) |
114 | bb_show_usage(); | ||
115 | p = xfind_str(cmds + 2, argv[0]); | ||
134 | ifr.cmd = *p; | 116 | ifr.cmd = *p; |
135 | if (argc != p[-1]) { | 117 | if (argc != p[-1]) |
136 | bb_show_usage(); | 118 | bb_show_usage(); |
137 | } | ||
138 | 119 | ||
139 | if (ifr.cmd == SET_VLAN_NAME_TYPE_CMD) { /* set_name_type */ | 120 | if (ifr.cmd == SET_VLAN_NAME_TYPE_CMD) { |
140 | ifr.u.name_type = *xfind_str(name_types+1, argv[1]); | 121 | /* set_name_type */ |
122 | ifr.u.name_type = *xfind_str(name_types + 1, argv[1]); | ||
141 | } else { | 123 | } else { |
142 | strncpy_IFNAMSIZ(ifr.device1, argv[1]); | 124 | strncpy_IFNAMSIZ(ifr.device1, argv[1]); |
143 | p = argv[2]; | 125 | p = argv[2]; |
@@ -146,22 +128,26 @@ int vconfig_main(int argc, char **argv) | |||
146 | * since ifr.u.flag, ifr.u.VID, and ifr.u.skb_priority are all same-sized | 128 | * since ifr.u.flag, ifr.u.VID, and ifr.u.skb_priority are all same-sized |
147 | * (unsigned) int members of a unions. But because of the range checking, | 129 | * (unsigned) int members of a unions. But because of the range checking, |
148 | * doing so wouldn't save that much space and would also make maintainence | 130 | * doing so wouldn't save that much space and would also make maintainence |
149 | * more of a pain. */ | 131 | * more of a pain. |
150 | if (ifr.cmd == SET_VLAN_FLAG_CMD) { /* set_flag */ | 132 | */ |
151 | ifr.u.flag = xatoul_range(p, 0, 1); | 133 | if (ifr.cmd == SET_VLAN_FLAG_CMD) { |
134 | /* set_flag */ | ||
135 | ifr.u.flag = xatou_range(p, 0, 1); | ||
152 | /* DM: in order to set reorder header, qos must be set */ | 136 | /* DM: in order to set reorder header, qos must be set */ |
153 | ifr.vlan_qos = xatoul_range(argv[3], 0, 7); | 137 | ifr.vlan_qos = xatou_range(argv[3], 0, 7); |
154 | } else if (ifr.cmd == ADD_VLAN_CMD) { /* add */ | 138 | } else if (ifr.cmd == ADD_VLAN_CMD) { |
155 | ifr.u.VID = xatoul_range(p, 0, VLAN_GROUP_ARRAY_LEN-1); | 139 | /* add */ |
156 | } else if (ifr.cmd != DEL_VLAN_CMD) { /* set_{egress|ingress}_map */ | 140 | ifr.u.VID = xatou_range(p, 0, VLAN_GROUP_ARRAY_LEN - 1); |
141 | } else if (ifr.cmd != DEL_VLAN_CMD) { | ||
142 | /* set_{egress|ingress}_map */ | ||
157 | ifr.u.skb_priority = xatou(p); | 143 | ifr.u.skb_priority = xatou(p); |
158 | ifr.vlan_qos = xatoul_range(argv[3], 0, 7); | 144 | ifr.vlan_qos = xatou_range(argv[3], 0, 7); |
159 | } | 145 | } |
160 | } | 146 | } |
161 | 147 | ||
162 | fd = xsocket(AF_INET, SOCK_STREAM, 0); | 148 | fd = xsocket(AF_INET, SOCK_STREAM, 0); |
163 | ioctl_or_perror_and_die(fd, SIOCSIFVLAN, &ifr, | 149 | ioctl_or_perror_and_die(fd, SIOCSIFVLAN, &ifr, |
164 | "ioctl error for %s", *argv); | 150 | "ioctl error for %s", argv[0]); |
165 | 151 | ||
166 | return 0; | 152 | return 0; |
167 | } | 153 | } |