8 #include <linux/if_vlan.h>
9 #include <linux/sockios.h>
11 #include <sys/socket.h>
12 #include <sys/types.h>
17 int vconfig_main(int argc, char** argv) {
19 struct vlan_ioctl_args if_request;
24 unsigned int skb_priority;
25 unsigned short vlan_qos;
26 unsigned int nm_type = VLAN_NAME_TYPE_PLUS_VID;
28 char* conf_file_name = "/proc/net/vlan/config";
30 memset(&if_request, 0, sizeof(struct vlan_ioctl_args));
32 if ((argc < 3) || (argc > 5)) {
33 error_msg_and_die("Expecting argc to be 3-5, inclusive. Was: %d\n",argc);
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;
42 else if (strcasecmp(argv[2], "VLAN_PLUS_VID_NO_PAD") == 0) {
43 nm_type = VLAN_NAME_TYPE_PLUS_VID_NO_PAD;
45 else if (strcasecmp(argv[2], "DEV_PLUS_VID") == 0) {
46 nm_type = VLAN_NAME_TYPE_RAW_PLUS_VID;
48 else if (strcasecmp(argv[2], "DEV_PLUS_VID_NO_PAD") == 0) {
49 nm_type = VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD;
52 error_msg_and_die("Invalid name type.\n");
54 if_request.u.name_type = nm_type;
58 if (strlen(if_name) > 15) {
59 error_msg_and_die("ERROR: if_name must be 15 characters or less.\n");
61 strcpy(if_request.device1, if_name);
66 if_request.u.VID = vid;
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;
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");
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");
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));
98 printf("Added VLAN with VID == %u to IF -:%s:-\n", vid, if_name);
100 error_msg("WARNING: VLAN 1 does not work with many switches,\nconsider another number if you have problems.\n");
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));
111 printf("Removed VLAN -:%s:-\n", if_name);
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));
121 printf("Set egress mapping on device -:%s:- "
122 "Should be visible in /proc/net/vlan/%s\n",
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));
133 printf("Set ingress mapping on device -:%s:- "
134 "Should be visible in /proc/net/vlan/%s\n",
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));
145 printf("Set flag on device -:%s:- "
146 "Should be visible in /proc/net/vlan/%s\n",
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",
157 printf("Set name-type for VLAN subsystem."
158 " Should be visible in /proc/net/vlan/config\n");
162 error_msg_and_die("Unknown command -:%s:-\n", cmd);