Mercurial > hg > toybox
annotate toys/other/vconfig.c @ 1261:9e105bab92e5 draft
Revert lots of half-finished local debris I didn't mean to check in with Isaac's roadmap update.
Mercurial's "import" command is still broken, committing local tree changes to files that weren't even touched by the patch because the hg developers inisist, when I point out how stupid it is, that they meant to do that. (hg record can do hunks, but import can't even track _files_.)
author | Rob Landley <rob@landley.net> |
---|---|
date | Wed, 16 Apr 2014 08:54:19 -0500 |
parents | 6ca31490f581 |
children | 160ea67a200d |
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 | 3 * Copyright 2012 Sandeep Sharma <sandeep.jack2756@gmail.com> |
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 | 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 |
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
|
16 add [interface-name] [vlan_id] |
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
|
17 rem [vlan-name] |
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
|
18 set_flag [interface-name] [flag-num] [0 | 1] |
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
|
19 set_egress_map [vlan-name] [skb_priority] [vlan_qos] |
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
|
20 set_ingress_map [vlan-name] [skb_priority] [vlan_qos] |
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
|
21 set_name_type [name-type] |
683
8d7fbb4c2205
Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff
changeset
|
22 |
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
|
23 Create and remove virtual ethernet devices |
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 | 29 |
1106
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
30 static long strtorange(char *str, long min, long max) |
683
8d7fbb4c2205
Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff
changeset
|
31 { |
1103 | 32 char *end = 0; |
33 long val = strtol(str, &end, 10); | |
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
|
34 |
1103 | 35 if (end && *end && end != str && val >= min && val <= max) return val; |
36 | |
1106
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
37 perror_exit("%s not %ld-%ld\n", str, min, max); |
683
8d7fbb4c2205
Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff
changeset
|
38 } |
1103 | 39 |
683
8d7fbb4c2205
Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff
changeset
|
40 void vconfig_main(void) |
8d7fbb4c2205
Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff
changeset
|
41 { |
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
|
42 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
|
43 char *cmd; |
1106
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
44 int fd; |
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
45 |
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
46 fd = xsocket(AF_INET, SOCK_STREAM, 0); |
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
47 memset(&request, 0, sizeof(struct vlan_ioctl_args)); |
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
48 cmd = toys.optargs[0]; |
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 if (!strcmp(cmd, "set_name_type")) { |
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
51 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
|
52 "DEV_PLUS_VID_NO_PAD"}; |
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
53 int i, j = sizeof(types)/sizeof(*types); |
683
8d7fbb4c2205
Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff
changeset
|
54 |
1106
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
55 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
|
56 if (i == j) { |
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
57 for (i=0; i<j; i++) puts(types[i]); |
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
58 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
|
59 } |
1106
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
60 |
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
61 request.u.name_type = i; |
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
62 request.cmd = SET_VLAN_NAME_TYPE_CMD; |
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
63 xioctl(fd, SIOCSIFVLAN, &request); |
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
64 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
|
65 } |
683
8d7fbb4c2205
Add vconfig.c - Creates virtual ethernet devices.
Kyungwan Han <asura321@gmail.com>
parents:
diff
changeset
|
66 |
1106
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
67 // 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
|
68 xstrncpy(request.device1, toys.optargs[1], 16); |
1106
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
69 |
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
70 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
|
71 request.cmd = ADD_VLAN_CMD; |
1106
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
72 if (toys.optargs[2]) request.u.VID = strtorange(toys.optargs[2], 0, 4094); |
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
73 if (request.u.VID == 1) |
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
74 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
|
75 } 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
|
76 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
|
77 request.cmd = SET_VLAN_FLAG_CMD; |
1106
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
78 if (toys.optargs[2]) request.u.flag = strtorange(toys.optargs[2], 0, 1); |
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
79 if (toys.optargs[3]) request.vlan_qos = strtorange(toys.optargs[3], 0, 7); |
1103 | 80 } 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
|
81 request.cmd = SET_VLAN_EGRESS_PRIORITY_CMD; |
1106
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
82 if (toys.optargs[2]) |
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
83 request.u.skb_priority = strtorange(toys.optargs[2], 0, INT_MAX); |
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
84 if (toys.optargs[3]) request.vlan_qos = strtorange(toys.optargs[3], 0, 7); |
1103 | 85 } 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
|
86 request.cmd = SET_VLAN_INGRESS_PRIORITY_CMD; |
1106
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
87 if (toys.optargs[2]) |
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
88 request.u.skb_priority = strtorange(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
|
89 //To set flag we must have to set vlan_qos |
1106
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
90 if (toys.optargs[3]) request.vlan_qos = strtorange(toys.optargs[3], 0, 7); |
1103 | 91 } 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
|
92 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
|
93 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
|
94 } |
1106
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
95 |
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
96 xioctl(fd, SIOCSIFVLAN, &request); |
30a210bae3e9
Sceond cleanup pass on vconfig
Rob Landley <rob@landley.net>
parents:
1104
diff
changeset
|
97 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
|
98 } |