123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- #include "libbb.h"
- #include <net/if.h>
- enum vlan_ioctl_cmds {
- ADD_VLAN_CMD,
- DEL_VLAN_CMD,
- SET_VLAN_INGRESS_PRIORITY_CMD,
- SET_VLAN_EGRESS_PRIORITY_CMD,
- GET_VLAN_INGRESS_PRIORITY_CMD,
- GET_VLAN_EGRESS_PRIORITY_CMD,
- SET_VLAN_NAME_TYPE_CMD,
- SET_VLAN_FLAG_CMD
- };
- enum vlan_name_types {
- VLAN_NAME_TYPE_PLUS_VID,
- VLAN_NAME_TYPE_RAW_PLUS_VID,
- VLAN_NAME_TYPE_PLUS_VID_NO_PAD,
- VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD,
- VLAN_NAME_TYPE_HIGHEST
- };
- struct vlan_ioctl_args {
- int cmd;
- char device1[24];
- union {
- char device2[24];
- int VID;
- unsigned int skb_priority;
- unsigned int name_type;
- unsigned int bind_type;
- unsigned int flag;
- } u;
- short vlan_qos;
- };
- #define VLAN_GROUP_ARRAY_LEN 4096
- #define SIOCSIFVLAN 0x8983
- static const char *xfind_str(const char *table, const char *str)
- {
- while (strcasecmp(str, table + 1) != 0) {
- if (!table[0])
- bb_show_usage();
- table += table[0];
- }
- return table - 1;
- }
- static const char cmds[] ALIGN1 = {
- 4, ADD_VLAN_CMD, 7,
- 'a','d','d',0,
- 3, DEL_VLAN_CMD, 7,
- 'r','e','m',0,
- 3, SET_VLAN_NAME_TYPE_CMD, 17,
- 's','e','t','_','n','a','m','e','_','t','y','p','e',0,
- 5, SET_VLAN_FLAG_CMD, 12,
- 's','e','t','_','f','l','a','g',0,
- 5, SET_VLAN_EGRESS_PRIORITY_CMD, 18,
- 's','e','t','_','e','g','r','e','s','s','_','m','a','p',0,
- 5, SET_VLAN_INGRESS_PRIORITY_CMD, 0,
- 's','e','t','_','i','n','g','r','e','s','s','_','m','a','p',0,
- };
- static const char name_types[] ALIGN1 = {
- VLAN_NAME_TYPE_PLUS_VID, 16,
- 'V','L','A','N','_','P','L','U','S','_','V','I','D',0,
- VLAN_NAME_TYPE_PLUS_VID_NO_PAD, 22,
- 'V','L','A','N','_','P','L','U','S','_','V','I','D','_','N','O','_','P','A','D',0,
- VLAN_NAME_TYPE_RAW_PLUS_VID, 15,
- 'D','E','V','_','P','L','U','S','_','V','I','D',0,
- VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD, 0,
- 'D','E','V','_','P','L','U','S','_','V','I','D','_','N','O','_','P','A','D',0,
- };
- int vconfig_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
- int vconfig_main(int argc, char **argv)
- {
- struct vlan_ioctl_args ifr;
- const char *p;
- int fd;
- memset(&ifr, 0, sizeof(ifr));
- ++argv;
- if (!argv[0])
- bb_show_usage();
- p = xfind_str(cmds + 2, argv[0]);
- ifr.cmd = *p;
- if (argc != p[-1])
- bb_show_usage();
- if (ifr.cmd == SET_VLAN_NAME_TYPE_CMD) {
-
- ifr.u.name_type = *xfind_str(name_types + 1, argv[1]);
- } else {
- strncpy_IFNAMSIZ(ifr.device1, argv[1]);
- p = argv[2];
-
- if (ifr.cmd == SET_VLAN_FLAG_CMD) {
-
- ifr.u.flag = xatou_range(p, 0, 1);
-
- ifr.vlan_qos = xatou_range(argv[3], 0, 7);
- } else if (ifr.cmd == ADD_VLAN_CMD) {
-
- ifr.u.VID = xatou_range(p, 0, VLAN_GROUP_ARRAY_LEN - 1);
- } else if (ifr.cmd != DEL_VLAN_CMD) {
-
- ifr.u.skb_priority = xatou(p);
- ifr.vlan_qos = xatou_range(argv[3], 0, 7);
- }
- }
- fd = xsocket(AF_INET, SOCK_STREAM, 0);
- ioctl_or_perror_and_die(fd, SIOCSIFVLAN, &ifr,
- "ioctl error for %s", argv[0]);
- return 0;
- }
|