1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28#include "toys.h"
29#include <linux/if_vlan.h>
30#include <linux/sockios.h>
31
32void vconfig_main(void)
33{
34 struct vlan_ioctl_args request;
35 char *cmd;
36 int fd;
37
38 fd = xsocket(AF_INET, SOCK_STREAM, 0);
39 memset(&request, 0, sizeof(struct vlan_ioctl_args));
40 cmd = toys.optargs[0];
41
42 if (!strcmp(cmd, "set_name_type")) {
43 char *types[] = {"VLAN_PLUS_VID", "DEV_PLUS_VID", "VLAN_PLUS_VID_NO_PAD",
44 "DEV_PLUS_VID_NO_PAD"};
45 int i, j = sizeof(types)/sizeof(*types);
46
47 for (i=0; i<j; i++) if (!strcmp(toys.optargs[1], types[i])) break;
48 if (i == j) {
49 for (i=0; i<j; i++) puts(types[i]);
50 error_exit("%s: unknown '%s'", cmd, toys.optargs[1]);
51 }
52
53 request.u.name_type = i;
54 request.cmd = SET_VLAN_NAME_TYPE_CMD;
55 xioctl(fd, SIOCSIFVLAN, &request);
56 return;
57 }
58
59
60 xstrncpy(request.device1, toys.optargs[1], 16);
61
62 if (!strcmp(cmd, "add")) {
63 request.cmd = ADD_VLAN_CMD;
64 if (toys.optargs[2]) request.u.VID = atolx_range(toys.optargs[2], 0, 4094);
65 if (request.u.VID == 1)
66 xprintf("WARNING: VLAN 1 does not work with many switches.\n");
67 } else if (!strcmp(cmd, "rem")) request.cmd = DEL_VLAN_CMD;
68 else if (!strcmp(cmd, "set_flag")) {
69 request.cmd = SET_VLAN_FLAG_CMD;
70 if (toys.optargs[2]) request.u.flag = atolx_range(toys.optargs[2], 0, 1);
71 if (toys.optargs[3]) request.vlan_qos = atolx_range(toys.optargs[3], 0, 7);
72 } else if(strcmp(cmd, "set_egress_map") == 0) {
73 request.cmd = SET_VLAN_EGRESS_PRIORITY_CMD;
74 if (toys.optargs[2])
75 request.u.skb_priority = atolx_range(toys.optargs[2], 0, INT_MAX);
76 if (toys.optargs[3]) request.vlan_qos = atolx_range(toys.optargs[3], 0, 7);
77 } else if(strcmp(cmd, "set_ingress_map") == 0) {
78 request.cmd = SET_VLAN_INGRESS_PRIORITY_CMD;
79 if (toys.optargs[2])
80 request.u.skb_priority = atolx_range(toys.optargs[2], 0, INT_MAX);
81
82 if (toys.optargs[3]) request.vlan_qos = atolx_range(toys.optargs[3], 0, 7);
83 } else {
84 xclose(fd);
85 perror_exit("Unknown command %s", cmd);
86 }
87
88 xioctl(fd, SIOCSIFVLAN, &request);
89 xprintf("Successful %s on device %s\n", cmd, toys.optargs[1]);
90}
91