aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/applets.h3
-rw-r--r--include/usage.h11
-rw-r--r--networking/Config.in6
-rw-r--r--networking/Makefile.in1
-rw-r--r--networking/vconfig.c166
5 files changed, 187 insertions, 0 deletions
diff --git a/include/applets.h b/include/applets.h
index 504f86a17..9e88f5044 100644
--- a/include/applets.h
+++ b/include/applets.h
@@ -598,6 +598,9 @@
598#ifdef CONFIG_UUENCODE 598#ifdef CONFIG_UUENCODE
599 APPLET(uuencode, uuencode_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) 599 APPLET(uuencode, uuencode_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
600#endif 600#endif
601#ifdef CONFIG_VCONFIG
602 APPLET(vconfig, vconfig_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
603#endif
601#ifdef CONFIG_VI 604#ifdef CONFIG_VI
602 APPLET(vi, vi_main, _BB_DIR_BIN, _BB_SUID_NEVER) 605 APPLET(vi, vi_main, _BB_DIR_BIN, _BB_SUID_NEVER)
603#endif 606#endif
diff --git a/include/usage.h b/include/usage.h
index 077306bdf..d2fb19372 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -2369,6 +2369,17 @@
2369 "$ uudecode busybox busybox > busybox.uu\n" \ 2369 "$ uudecode busybox busybox > busybox.uu\n" \
2370 "$\n" 2370 "$\n"
2371 2371
2372#define vconfig_trivial_usage \
2373 "COMMAND [OPTIONS] ..."
2374
2375#define vconfig_full_usage \
2376"Usage: add [interface-name] [vlan_id] \n" \
2377" rem [vlan-name] \n" \
2378" set_flag [interface-name] [flag-num] [0 | 1] \n" \
2379" set_egress_map [vlan-name] [skb_priority] [vlan_qos] \n" \
2380" set_ingress_map [vlan-name] [skb_priority] [vlan_qos] \n" \
2381" set_name_type [name-type] \n"
2382
2372#define vi_trivial_usage \ 2383#define vi_trivial_usage \
2373 "[OPTION] [FILE]..." 2384 "[OPTION] [FILE]..."
2374#define vi_full_usage \ 2385#define vi_full_usage \
diff --git a/networking/Config.in b/networking/Config.in
index ebefd600d..22676c085 100644
--- a/networking/Config.in
+++ b/networking/Config.in
@@ -376,6 +376,12 @@ config CONFIG_FEATURE_TRACEROUTE_SO_DEBUG
376 help 376 help
377 Please submit a patch to add help text for this item. 377 Please submit a patch to add help text for this item.
378 378
379config CONFIG_VCONFIG
380 bool "vconfig"
381 default n
382 help
383 Creates, removes, and configures VLAN interfaces
384
379config CONFIG_WGET 385config CONFIG_WGET
380 bool "wget" 386 bool "wget"
381 default n 387 default n
diff --git a/networking/Makefile.in b/networking/Makefile.in
index 144091abc..12fc8ddbd 100644
--- a/networking/Makefile.in
+++ b/networking/Makefile.in
@@ -47,6 +47,7 @@ NETWORKING-$(CONFIG_TELNET) += telnet.o
47NETWORKING-$(CONFIG_TELNETD) += telnetd.o 47NETWORKING-$(CONFIG_TELNETD) += telnetd.o
48NETWORKING-$(CONFIG_TFTP) += tftp.o 48NETWORKING-$(CONFIG_TFTP) += tftp.o
49NETWORKING-$(CONFIG_TRACEROUTE) += traceroute.o 49NETWORKING-$(CONFIG_TRACEROUTE) += traceroute.o
50NETWORKING-$(CONFIG_VCONFIG) += vconfig.o
50NETWORKING-$(CONFIG_WGET) += wget.o 51NETWORKING-$(CONFIG_WGET) += wget.o
51 52
52libraries-y+=$(NETWORKING_DIR)$(NETWORKING_AR) 53libraries-y+=$(NETWORKING_DIR)$(NETWORKING_AR)
diff --git a/networking/vconfig.c b/networking/vconfig.c
new file mode 100644
index 000000000..0ad759e69
--- /dev/null
+++ b/networking/vconfig.c
@@ -0,0 +1,166 @@
1#include <errno.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <unistd.h>
5#include <fcntl.h>
6#include <strings.h>
7#include <sys/ioctl.h>
8#include <linux/if_vlan.h>
9#include <linux/sockios.h>
10#include <string.h>
11#include <sys/socket.h>
12#include <sys/types.h>
13#include "busybox.h"
14
15
16
17int vconfig_main(int argc, char** argv) {
18 int fd;
19 struct vlan_ioctl_args if_request;
20
21 char* cmd = NULL;
22 char* if_name = NULL;
23 unsigned int vid = 0;
24 unsigned int skb_priority;
25 unsigned short vlan_qos;
26 unsigned int nm_type = VLAN_NAME_TYPE_PLUS_VID;
27
28 char* conf_file_name = "/proc/net/vlan/config";
29
30 memset(&if_request, 0, sizeof(struct vlan_ioctl_args));
31
32 if ((argc < 3) || (argc > 5)) {
33 error_msg_and_die("Expecting argc to be 3-5, inclusive. Was: %d\n",argc);
34 }
35 else {
36 cmd = argv[1];
37
38 if (strcasecmp(cmd, "set_name_type") == 0) {
39 if (strcasecmp(argv[2], "VLAN_PLUS_VID") == 0) {
40 nm_type = VLAN_NAME_TYPE_PLUS_VID;
41 }
42 else if (strcasecmp(argv[2], "VLAN_PLUS_VID_NO_PAD") == 0) {
43 nm_type = VLAN_NAME_TYPE_PLUS_VID_NO_PAD;
44 }
45 else if (strcasecmp(argv[2], "DEV_PLUS_VID") == 0) {
46 nm_type = VLAN_NAME_TYPE_RAW_PLUS_VID;
47 }
48 else if (strcasecmp(argv[2], "DEV_PLUS_VID_NO_PAD") == 0) {
49 nm_type = VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD;
50 }
51 else {
52 error_msg_and_die("Invalid name type.\n");
53 }
54 if_request.u.name_type = nm_type;
55 }
56 else {
57 if_name = argv[2];
58 if (strlen(if_name) > 15) {
59 error_msg_and_die("ERROR: if_name must be 15 characters or less.\n");
60 }
61 strcpy(if_request.device1, if_name);
62 }
63
64 if (argc == 4) {
65 vid = atoi(argv[3]);
66 if_request.u.VID = vid;
67 }
68
69 if (argc == 5) {
70 skb_priority = atoi(argv[3]);
71 vlan_qos = atoi(argv[4]);
72 if_request.u.skb_priority = skb_priority;
73 if_request.vlan_qos = vlan_qos;
74 }
75 }
76
77 // Open up the /proc/vlan/config
78 if ((fd = open(conf_file_name, O_RDONLY)) < 0) {
79 error_msg("WARNING: Could not open /proc/net/vlan/config. Maybe you need to load the 8021q module, or maybe you are not using PROCFS??\n");
80 }
81 else {
82 close(fd);
83 }
84
85 /* We use sockets now, instead of the file descriptor */
86 if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
87 error_msg_and_die("FATAL: Couldn't open a socket..go figure!\n");
88 }
89
90 /* add */
91 if (strcasecmp(cmd, "add") == 0) {
92 if_request.cmd = ADD_VLAN_CMD;
93 if (ioctl(fd, SIOCSIFVLAN, &if_request) < 0) {
94 error_msg("ERROR: trying to add VLAN #%u to IF -:%s:- error: %s\n",
95 vid, if_name, strerror(errno));
96 }
97 else {
98 printf("Added VLAN with VID == %u to IF -:%s:-\n", vid, if_name);
99 if (vid == 1) {
100 error_msg("WARNING: VLAN 1 does not work with many switches,\nconsider another number if you have problems.\n");
101 }
102 }
103 }//if
104 else if (strcasecmp(cmd, "rem") == 0) {
105 if_request.cmd = DEL_VLAN_CMD;
106 if (ioctl(fd, SIOCSIFVLAN, &if_request) < 0) {
107 error_msg("ERROR: trying to remove VLAN -:%s:- error: %s\n",
108 if_name, strerror(errno));
109 }
110 else {
111 printf("Removed VLAN -:%s:-\n", if_name);
112 }
113 }//if
114 else if (strcasecmp(cmd, "set_egress_map") == 0) {
115 if_request.cmd = SET_VLAN_EGRESS_PRIORITY_CMD;
116 if (ioctl(fd, SIOCSIFVLAN, &if_request) < 0) {
117 error_msg("ERROR: trying to set egress map on device -:%s:- error: %s\n",
118 if_name, strerror(errno));
119 }
120 else {
121 printf("Set egress mapping on device -:%s:- "
122 "Should be visible in /proc/net/vlan/%s\n",
123 if_name, if_name);
124 }
125 }
126 else if (strcasecmp(cmd, "set_ingress_map") == 0) {
127 if_request.cmd = SET_VLAN_INGRESS_PRIORITY_CMD;
128 if (ioctl(fd, SIOCSIFVLAN, &if_request) < 0) {
129 error_msg("ERROR: trying to set ingress map on device -:%s:- error: %s\n",
130 if_name, strerror(errno));
131 }
132 else {
133 printf("Set ingress mapping on device -:%s:- "
134 "Should be visible in /proc/net/vlan/%s\n",
135 if_name, if_name);
136 }
137 }
138 else if (strcasecmp(cmd, "set_flag") == 0) {
139 if_request.cmd = SET_VLAN_FLAG_CMD;
140 if (ioctl(fd, SIOCSIFVLAN, &if_request) < 0) {
141 error_msg("ERROR: trying to set flag on device -:%s:- error: %s\n",
142 if_name, strerror(errno));
143 }
144 else {
145 printf("Set flag on device -:%s:- "
146 "Should be visible in /proc/net/vlan/%s\n",
147 if_name, if_name);
148 }
149 }
150 else if (strcasecmp(cmd, "set_name_type") == 0) {
151 if_request.cmd = SET_VLAN_NAME_TYPE_CMD;
152 if (ioctl(fd, SIOCSIFVLAN, &if_request) < 0) {
153 error_msg("ERROR: trying to set name type for VLAN subsystem, error: %s\n",
154 strerror(errno));
155 }
156 else {
157 printf("Set name-type for VLAN subsystem."
158 " Should be visible in /proc/net/vlan/config\n");
159 }
160 }
161 else {
162 error_msg_and_die("Unknown command -:%s:-\n", cmd);
163 }
164
165 return 0;
166}/* main */