diff options
Diffstat (limited to 'networking/vconfig.c')
-rw-r--r-- | networking/vconfig.c | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/networking/vconfig.c b/networking/vconfig.c index 3bd9c3040..d58c375f7 100644 --- a/networking/vconfig.c +++ b/networking/vconfig.c | |||
@@ -1,3 +1,27 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * vconfig implementation for busybox | ||
4 | * | ||
5 | * Copyright (C) 2001 Manuel Novoa III <mjn3@codepoet.org> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | /* BB_AUDIT SUSv3 N/A */ | ||
24 | |||
1 | #include <stdlib.h> | 25 | #include <stdlib.h> |
2 | #include <unistd.h> | 26 | #include <unistd.h> |
3 | #include <fcntl.h> | 27 | #include <fcntl.h> |
@@ -11,29 +35,14 @@ | |||
11 | #define VLAN_GROUP_ARRAY_LEN 4096 | 35 | #define VLAN_GROUP_ARRAY_LEN 4096 |
12 | #define SIOCSIFVLAN 0x8983 /* Set 802.1Q VLAN options */ | 36 | #define SIOCSIFVLAN 0x8983 /* Set 802.1Q VLAN options */ |
13 | 37 | ||
14 | /* This is rather specialized in that we're passing a 'char **' in | ||
15 | * order to avoid the pointer dereference multiple times in the | ||
16 | * actual calls below. */ | ||
17 | static unsigned long xstrtoul10(char **str, unsigned long max_val) | ||
18 | { | ||
19 | char *endptr; | ||
20 | unsigned long r; | ||
21 | |||
22 | r = strtoul(str[2], &endptr, 10); | ||
23 | if ((r > max_val) || (*endptr != 0)) { | ||
24 | show_usage(); | ||
25 | } | ||
26 | return r; | ||
27 | } | ||
28 | |||
29 | /* On entry, table points to the length of the current string plus | 38 | /* On entry, table points to the length of the current string plus |
30 | * nul terminator plus data lenght for the subsequent entry. The | 39 | * nul terminator plus data length for the subsequent entry. The |
31 | * return value is the last data entry for the matching string. */ | 40 | * return value is the last data entry for the matching string. */ |
32 | static const char *xfind_str(const char *table, const char *str) | 41 | static const char *xfind_str(const char *table, const char *str) |
33 | { | 42 | { |
34 | while (strcasecmp(str, table+1) != 0) { | 43 | while (strcasecmp(str, table+1) != 0) { |
35 | if (!*(table += table[0])) { | 44 | if (!*(table += table[0])) { |
36 | show_usage(); | 45 | bb_show_usage(); |
37 | } | 46 | } |
38 | } | 47 | } |
39 | return table - 1; | 48 | return table - 1; |
@@ -89,12 +98,12 @@ int vconfig_main(int argc, char **argv) | |||
89 | int fd; | 98 | int fd; |
90 | 99 | ||
91 | if (argc < 3) { | 100 | if (argc < 3) { |
92 | show_usage(); | 101 | bb_show_usage(); |
93 | } | 102 | } |
94 | 103 | ||
95 | /* Don't bother closing the filedes. It will be closed on cleanup. */ | 104 | /* Don't bother closing the filedes. It will be closed on cleanup. */ |
96 | if (open(conf_file_name, O_RDONLY) < 0) { /* Is 802.1q is present? */ | 105 | if (open(conf_file_name, O_RDONLY) < 0) { /* Is 802.1q is present? */ |
97 | perror_msg_and_die("open %s", conf_file_name); | 106 | bb_perror_msg_and_die("open %s", conf_file_name); |
98 | } | 107 | } |
99 | 108 | ||
100 | memset(&ifr, 0, sizeof(struct vlan_ioctl_args)); | 109 | memset(&ifr, 0, sizeof(struct vlan_ioctl_args)); |
@@ -103,16 +112,17 @@ int vconfig_main(int argc, char **argv) | |||
103 | p = xfind_str(cmds+2, *argv); | 112 | p = xfind_str(cmds+2, *argv); |
104 | ifr.cmd = *p; | 113 | ifr.cmd = *p; |
105 | if (argc != p[-1]) { | 114 | if (argc != p[-1]) { |
106 | show_usage(); | 115 | bb_show_usage(); |
107 | } | 116 | } |
108 | 117 | ||
109 | if (ifr.cmd == SET_VLAN_NAME_TYPE_CMD) { /* set_name_type */ | 118 | if (ifr.cmd == SET_VLAN_NAME_TYPE_CMD) { /* set_name_type */ |
110 | ifr.u.name_type = *xfind_str(name_types+1, argv[1]); | 119 | ifr.u.name_type = *xfind_str(name_types+1, argv[1]); |
111 | } else { | 120 | } else { |
112 | if (strlen(argv[1]) >= IF_NAMESIZE) { | 121 | if (strlen(argv[1]) >= IF_NAMESIZE) { |
113 | error_msg_and_die("if_name >= %d chars\n", IF_NAMESIZE); | 122 | bb_error_msg_and_die("if_name >= %d chars\n", IF_NAMESIZE); |
114 | } | 123 | } |
115 | strcpy(ifr.device1, argv[1]); | 124 | strcpy(ifr.device1, argv[1]); |
125 | p = argv[2]; | ||
116 | 126 | ||
117 | /* I suppose one could try to combine some of the function calls below, | 127 | /* I suppose one could try to combine some of the function calls below, |
118 | * 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 |
@@ -120,19 +130,19 @@ int vconfig_main(int argc, char **argv) | |||
120 | * 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 |
121 | * more of a pain. */ | 131 | * more of a pain. */ |
122 | if (ifr.cmd == SET_VLAN_FLAG_CMD) { /* set_flag */ | 132 | if (ifr.cmd == SET_VLAN_FLAG_CMD) { /* set_flag */ |
123 | ifr.u.flag = xstrtoul10(argv, 1); | 133 | ifr.u.flag = bb_xgetularg10_bnd(p, 0, 1); |
124 | } else if (ifr.cmd == ADD_VLAN_CMD) { /* add */ | 134 | } else if (ifr.cmd == ADD_VLAN_CMD) { /* add */ |
125 | ifr.u.VID = xstrtoul10(argv, VLAN_GROUP_ARRAY_LEN-1); | 135 | ifr.u.VID = bb_xgetularg10_bnd(p, 0, VLAN_GROUP_ARRAY_LEN-1); |
126 | } else if (ifr.cmd != DEL_VLAN_CMD) { /* set_{egress|ingress}_map */ | 136 | } else if (ifr.cmd != DEL_VLAN_CMD) { /* set_{egress|ingress}_map */ |
127 | ifr.u.skb_priority = xstrtoul10(argv, ULONG_MAX); | 137 | ifr.u.skb_priority = bb_xgetularg10_bnd(p, 0, ULONG_MAX); |
128 | ifr.vlan_qos = xstrtoul10(argv+1, 7); | 138 | ifr.vlan_qos = bb_xgetularg10_bnd(argv[3], 0, 7); |
129 | } | 139 | } |
130 | } | 140 | } |
131 | 141 | ||
132 | if (((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) | 142 | if (((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) |
133 | || (ioctl(fd, SIOCSIFVLAN, &ifr) < 0) | 143 | || (ioctl(fd, SIOCSIFVLAN, &ifr) < 0) |
134 | ) { | 144 | ) { |
135 | perror_msg_and_die("socket or ioctl error for %s", *argv); | 145 | bb_perror_msg_and_die("socket or ioctl error for %s", *argv); |
136 | } | 146 | } |
137 | 147 | ||
138 | return 0; | 148 | return 0; |