Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/networking/vconfig.c
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/networking/vconfig.c
r2725 r3232 9 9 10 10 /* BB_AUDIT SUSv3 N/A */ 11 12 //usage:#define vconfig_trivial_usage 13 //usage: "COMMAND [OPTIONS]" 14 //usage:#define vconfig_full_usage "\n\n" 15 //usage: "Create and remove virtual ethernet devices\n" 16 //usage: "\n add IFACE VLAN_ID" 17 //usage: "\n rem VLAN_NAME" 18 //usage: "\n set_flag IFACE 0|1 VLAN_QOS" 19 //usage: "\n set_egress_map VLAN_NAME SKB_PRIO VLAN_QOS" 20 //usage: "\n set_ingress_map VLAN_NAME SKB_PRIO VLAN_QOS" 21 //usage: "\n set_name_type NAME_TYPE" 11 22 12 23 #include "libbb.h" … … 56 67 static const char *xfind_str(const char *table, const char *str) 57 68 { 58 while (strcasecmp(str, table+1) != 0) { 69 while (strcasecmp(str, table + 1) != 0) { 70 if (!table[0]) 71 bb_show_usage(); 59 72 table += table[0]; 60 if (!*table) {61 bb_show_usage();62 }63 73 } 64 74 return table - 1; … … 67 77 static const char cmds[] ALIGN1 = { 68 78 4, ADD_VLAN_CMD, 7, 69 'a', 'd', 'd',0,79 'a','d','d',0, 70 80 3, DEL_VLAN_CMD, 7, 71 'r', 'e', 'm',0,81 'r','e','m',0, 72 82 3, SET_VLAN_NAME_TYPE_CMD, 17, 73 's', 'e', 't', '_', 74 'n', 'a', 'm', 'e', '_', 75 't', 'y', 'p', 'e', 0, 83 's','e','t','_','n','a','m','e','_','t','y','p','e',0, 76 84 5, SET_VLAN_FLAG_CMD, 12, 77 's', 'e', 't', '_', 78 'f', 'l', 'a', 'g', 0, 85 's','e','t','_','f','l','a','g',0, 79 86 5, SET_VLAN_EGRESS_PRIORITY_CMD, 18, 80 's', 'e', 't', '_', 81 'e', 'g', 'r', 'e', 's', 's', '_', 82 'm', 'a', 'p', 0, 83 5, SET_VLAN_INGRESS_PRIORITY_CMD, 16, 84 's', 'e', 't', '_', 85 'i', 'n', 'g', 'r', 'e', 's', 's', '_', 86 'm', 'a', 'p', 0, 87 's','e','t','_','e','g','r','e','s','s','_','m','a','p',0, 88 5, SET_VLAN_INGRESS_PRIORITY_CMD, 0, 89 's','e','t','_','i','n','g','r','e','s','s','_','m','a','p',0, 87 90 }; 88 91 89 92 static const char name_types[] ALIGN1 = { 90 93 VLAN_NAME_TYPE_PLUS_VID, 16, 91 'V', 'L', 'A', 'N', 92 '_', 'P', 'L', 'U', 'S', '_', 'V', 'I', 'D', 93 0, 94 'V','L','A','N','_','P','L','U','S','_','V','I','D',0, 94 95 VLAN_NAME_TYPE_PLUS_VID_NO_PAD, 22, 95 'V', 'L', 'A', 'N', 96 '_', 'P', 'L', 'U', 'S', '_', 'V', 'I', 'D', 97 '_', 'N', 'O', '_', 'P', 'A', 'D', 0, 96 'V','L','A','N','_','P','L','U','S','_','V','I','D','_','N','O','_','P','A','D',0, 98 97 VLAN_NAME_TYPE_RAW_PLUS_VID, 15, 99 'D', 'E', 'V', 100 '_', 'P', 'L', 'U', 'S', '_', 'V', 'I', 'D', 101 0, 102 VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD, 20, 103 'D', 'E', 'V', 104 '_', 'P', 'L', 'U', 'S', '_', 'V', 'I', 'D', 105 '_', 'N', 'O', '_', 'P', 'A', 'D', 0, 98 'D','E','V','_','P','L','U','S','_','V','I','D',0, 99 VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD, 0, 100 'D','E','V','_','P','L','U','S','_','V','I','D','_','N','O','_','P','A','D',0, 106 101 }; 107 108 static const char conf_file_name[] ALIGN1 = "/proc/net/vlan/config";109 102 110 103 int vconfig_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; … … 115 108 int fd; 116 109 117 if (argc < 3) {118 bb_show_usage();119 }120 121 /* Don't bother closing the filedes. It will be closed on cleanup. */122 /* Will die if 802.1q is not present */123 xopen(conf_file_name, O_RDONLY);124 125 110 memset(&ifr, 0, sizeof(ifr)); 126 111 127 112 ++argv; 128 p = xfind_str(cmds+2, *argv); 113 if (!argv[0]) 114 bb_show_usage(); 115 p = xfind_str(cmds + 2, argv[0]); 129 116 ifr.cmd = *p; 130 if (argc != p[-1]) {117 if (argc != p[-1]) 131 118 bb_show_usage(); 132 }133 119 134 if (ifr.cmd == SET_VLAN_NAME_TYPE_CMD) { /* set_name_type */ 135 ifr.u.name_type = *xfind_str(name_types+1, argv[1]); 120 if (ifr.cmd == SET_VLAN_NAME_TYPE_CMD) { 121 /* set_name_type */ 122 ifr.u.name_type = *xfind_str(name_types + 1, argv[1]); 136 123 } else { 137 124 strncpy_IFNAMSIZ(ifr.device1, argv[1]); … … 142 129 * (unsigned) int members of a unions. But because of the range checking, 143 130 * doing so wouldn't save that much space and would also make maintainence 144 * more of a pain. */ 145 if (ifr.cmd == SET_VLAN_FLAG_CMD) { /* set_flag */ 146 ifr.u.flag = xatoul_range(p, 0, 1); 131 * more of a pain. 132 */ 133 if (ifr.cmd == SET_VLAN_FLAG_CMD) { 134 /* set_flag */ 135 ifr.u.flag = xatou_range(p, 0, 1); 147 136 /* DM: in order to set reorder header, qos must be set */ 148 ifr.vlan_qos = xatoul_range(argv[3], 0, 7); 149 } else if (ifr.cmd == ADD_VLAN_CMD) { /* add */ 150 ifr.u.VID = xatoul_range(p, 0, VLAN_GROUP_ARRAY_LEN-1); 151 } else if (ifr.cmd != DEL_VLAN_CMD) { /* set_{egress|ingress}_map */ 137 ifr.vlan_qos = xatou_range(argv[3], 0, 7); 138 } else if (ifr.cmd == ADD_VLAN_CMD) { 139 /* add */ 140 ifr.u.VID = xatou_range(p, 0, VLAN_GROUP_ARRAY_LEN - 1); 141 } else if (ifr.cmd != DEL_VLAN_CMD) { 142 /* set_{egress|ingress}_map */ 152 143 ifr.u.skb_priority = xatou(p); 153 ifr.vlan_qos = xatou l_range(argv[3], 0, 7);144 ifr.vlan_qos = xatou_range(argv[3], 0, 7); 154 145 } 155 146 } … … 157 148 fd = xsocket(AF_INET, SOCK_STREAM, 0); 158 149 ioctl_or_perror_and_die(fd, SIOCSIFVLAN, &ifr, 159 "ioctl error for %s", *argv);150 "ioctl error for %s", argv[0]); 160 151 161 152 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.