annotate toys/other/vconfig.c @ 1776:7bf68329eb3b draft default tip

Repository switched to git at https://github.com/landley/toybox
author Rob Landley <rob@landley.net>
date Thu, 09 Apr 2015 02:28:32 -0500
parents fc1bb49e58a9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 683
diff changeset
1 /* vconfig.c - Creates virtual ethernet devices.
683
8d7fbb4c2205 Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff changeset
2 *
1103
bc09fa708d94 Cleanup vconfig.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
3 * Copyright 2012 Sandeep Sharma <sandeep.jack2756@gmail.com>
bc09fa708d94 Cleanup vconfig.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
4 * Copyright 2012 Kyungwan Han <asura321@gmail.com>
683
8d7fbb4c2205 Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff changeset
5 *
1103
bc09fa708d94 Cleanup vconfig.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
6 * No standard
683
8d7fbb4c2205 Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff changeset
7
8d7fbb4c2205 Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff changeset
8 USE_VCONFIG(NEWTOY(vconfig, "<2>4", TOYFLAG_NEEDROOT|TOYFLAG_SBIN))
8d7fbb4c2205 Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff changeset
9
8d7fbb4c2205 Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff changeset
10 config VCONFIG
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 683
diff changeset
11 bool "vconfig"
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 683
diff changeset
12 default y
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 683
diff changeset
13 help
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 683
diff changeset
14 usage: vconfig COMMAND [OPTIONS]
683
8d7fbb4c2205 Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff changeset
15
1333
fc1bb49e58a9 Help text should have a blank line after usage: lines, and a couple other whitespace tweaks.
Rob Landley <rob@landley.net>
parents: 1316
diff changeset
16 Create and remove virtual ethernet devices
683
8d7fbb4c2205 Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff changeset
17
1333
fc1bb49e58a9 Help text should have a blank line after usage: lines, and a couple other whitespace tweaks.
Rob Landley <rob@landley.net>
parents: 1316
diff changeset
18 add [interface-name] [vlan_id]
fc1bb49e58a9 Help text should have a blank line after usage: lines, and a couple other whitespace tweaks.
Rob Landley <rob@landley.net>
parents: 1316
diff changeset
19 rem [vlan-name]
fc1bb49e58a9 Help text should have a blank line after usage: lines, and a couple other whitespace tweaks.
Rob Landley <rob@landley.net>
parents: 1316
diff changeset
20 set_flag [interface-name] [flag-num] [0 | 1]
fc1bb49e58a9 Help text should have a blank line after usage: lines, and a couple other whitespace tweaks.
Rob Landley <rob@landley.net>
parents: 1316
diff changeset
21 set_egress_map [vlan-name] [skb_priority] [vlan_qos]
fc1bb49e58a9 Help text should have a blank line after usage: lines, and a couple other whitespace tweaks.
Rob Landley <rob@landley.net>
parents: 1316
diff changeset
22 set_ingress_map [vlan-name] [skb_priority] [vlan_qos]
fc1bb49e58a9 Help text should have a blank line after usage: lines, and a couple other whitespace tweaks.
Rob Landley <rob@landley.net>
parents: 1316
diff changeset
23 set_name_type [name-type]
683
8d7fbb4c2205 Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff changeset
24 */
8d7fbb4c2205 Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff changeset
25
8d7fbb4c2205 Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff changeset
26 #include "toys.h"
8d7fbb4c2205 Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff changeset
27 #include <linux/if_vlan.h>
8d7fbb4c2205 Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff changeset
28 #include <linux/sockios.h>
1103
bc09fa708d94 Cleanup vconfig.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
29
683
8d7fbb4c2205 Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff changeset
30 void vconfig_main(void)
8d7fbb4c2205 Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff changeset
31 {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 683
diff changeset
32 struct vlan_ioctl_args request;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 683
diff changeset
33 char *cmd;
1106
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
34 int fd;
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
35
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
36 fd = xsocket(AF_INET, SOCK_STREAM, 0);
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
37 memset(&request, 0, sizeof(struct vlan_ioctl_args));
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
38 cmd = toys.optargs[0];
683
8d7fbb4c2205 Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff changeset
39
1106
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
40 if (!strcmp(cmd, "set_name_type")) {
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
41 char *types[] = {"VLAN_PLUS_VID", "DEV_PLUS_VID", "VLAN_PLUS_VID_NO_PAD",
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
42 "DEV_PLUS_VID_NO_PAD"};
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
43 int i, j = sizeof(types)/sizeof(*types);
683
8d7fbb4c2205 Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff changeset
44
1106
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
45 for (i=0; i<j; i++) if (!strcmp(toys.optargs[1], types[i])) break;
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
46 if (i == j) {
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
47 for (i=0; i<j; i++) puts(types[i]);
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
48 error_exit("%s: unknown '%s'", cmd, toys.optargs[1]);
683
8d7fbb4c2205 Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff changeset
49 }
1106
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
50
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
51 request.u.name_type = i;
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
52 request.cmd = SET_VLAN_NAME_TYPE_CMD;
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
53 xioctl(fd, SIOCSIFVLAN, &request);
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
54 return;
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 683
diff changeset
55 }
683
8d7fbb4c2205 Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff changeset
56
1106
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
57 // Store interface name
1261
9e105bab92e5 Revert lots of half-finished local debris I didn't mean to check in with Isaac's roadmap update.
Rob Landley <rob@landley.net>
parents: 1251
diff changeset
58 xstrncpy(request.device1, toys.optargs[1], 16);
1106
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
59
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
60 if (!strcmp(cmd, "add")) {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 683
diff changeset
61 request.cmd = ADD_VLAN_CMD;
1316
160ea67a200d atolx_range() is already added into lib/lib.c, in vconfig.c atolx_range() can be used in place of locally defined strtorange() function.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents: 1261
diff changeset
62 if (toys.optargs[2]) request.u.VID = atolx_range(toys.optargs[2], 0, 4094);
1106
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
63 if (request.u.VID == 1)
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
64 xprintf("WARNING: VLAN 1 does not work with many switches.\n");
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
65 } else if (!strcmp(cmd, "rem")) request.cmd = DEL_VLAN_CMD;
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
66 else if (!strcmp(cmd, "set_flag")) {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 683
diff changeset
67 request.cmd = SET_VLAN_FLAG_CMD;
1316
160ea67a200d atolx_range() is already added into lib/lib.c, in vconfig.c atolx_range() can be used in place of locally defined strtorange() function.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents: 1261
diff changeset
68 if (toys.optargs[2]) request.u.flag = atolx_range(toys.optargs[2], 0, 1);
160ea67a200d atolx_range() is already added into lib/lib.c, in vconfig.c atolx_range() can be used in place of locally defined strtorange() function.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents: 1261
diff changeset
69 if (toys.optargs[3]) request.vlan_qos = atolx_range(toys.optargs[3], 0, 7);
1103
bc09fa708d94 Cleanup vconfig.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
70 } else if(strcmp(cmd, "set_egress_map") == 0) {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 683
diff changeset
71 request.cmd = SET_VLAN_EGRESS_PRIORITY_CMD;
1106
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
72 if (toys.optargs[2])
1316
160ea67a200d atolx_range() is already added into lib/lib.c, in vconfig.c atolx_range() can be used in place of locally defined strtorange() function.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents: 1261
diff changeset
73 request.u.skb_priority = atolx_range(toys.optargs[2], 0, INT_MAX);
160ea67a200d atolx_range() is already added into lib/lib.c, in vconfig.c atolx_range() can be used in place of locally defined strtorange() function.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents: 1261
diff changeset
74 if (toys.optargs[3]) request.vlan_qos = atolx_range(toys.optargs[3], 0, 7);
1103
bc09fa708d94 Cleanup vconfig.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
75 } else if(strcmp(cmd, "set_ingress_map") == 0) {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 683
diff changeset
76 request.cmd = SET_VLAN_INGRESS_PRIORITY_CMD;
1106
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
77 if (toys.optargs[2])
1316
160ea67a200d atolx_range() is already added into lib/lib.c, in vconfig.c atolx_range() can be used in place of locally defined strtorange() function.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents: 1261
diff changeset
78 request.u.skb_priority = atolx_range(toys.optargs[2], 0, INT_MAX);
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 683
diff changeset
79 //To set flag we must have to set vlan_qos
1316
160ea67a200d atolx_range() is already added into lib/lib.c, in vconfig.c atolx_range() can be used in place of locally defined strtorange() function.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents: 1261
diff changeset
80 if (toys.optargs[3]) request.vlan_qos = atolx_range(toys.optargs[3], 0, 7);
1103
bc09fa708d94 Cleanup vconfig.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
81 } else {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 683
diff changeset
82 xclose(fd);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 683
diff changeset
83 perror_exit("Unknown command %s", cmd);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 683
diff changeset
84 }
1106
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
85
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
86 xioctl(fd, SIOCSIFVLAN, &request);
30a210bae3e9 Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
87 xprintf("Successful %s on device %s\n", cmd, toys.optargs[1]);
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 683
diff changeset
88 }