busybox/networking/vconfig.c
Denis Vlasenko fb79a2e2cf xioctl and friends by Tito <farmatito@tiscali.it>
function                                             old     new   delta
do_iptunnel                                          203     977    +774
process_dev                                         5328    5494    +166
ioctl_or_perror                                        -      54     +54
ioctl_or_perror_and_die                                -      51     +51
ioctl_alt_func                                         -      49     +49
bb_ioctl_or_warn                                       -      47     +47
do_add_ioctl                                         102     145     +43
bb_xioctl                                              -      39     +39
print_value_on_off                                     -      31     +31
get_lcm                                              105     123     +18
arp_main                                            2155    2167     +12
..................
zcip_main                                           1576    1566     -10
setlogcons_main                                       92      82     -10
dumpkmap_main                                        263     253     -10
do_get_ioctl                                          85      75     -10
setkeycodes_main                                     165     154     -11
write_table                                          244     232     -12
vconfig_main                                         318     306     -12
do_del_ioctl                                          93      81     -12
set_address                                           75      62     -13
maybe_set_utc                                         30      16     -14
loadfont_main                                        495     479     -16
slattach_main                                        712     695     -17
do_loadfont                                          191     174     -17
do_iplink                                           1155    1136     -19
getty_main                                          2583    2562     -21
fbset_main                                          2058    2035     -23
do_time                                              588     565     -23
xioctl                                                25       -     -25
read_rtc                                             186     160     -26
parse_conf                                          1299    1270     -29
udhcp_read_interface                                 269     239     -30
bb_ioctl                                              45       -     -45
bb_ioctl_alt                                          70       -     -70
bb_ioctl_on_off                                       78       -     -78
.rodata                                           129370  129018    -352
do_show                                              799       -    -799
------------------------------------------------------------------------------
(add/remove: 6/5 grow/shrink: 13/49 up/down: 1316/-1864)     Total: -548 bytes
   text	   data	    bss	    dec	    hex	filename
 675352	   2740	  13968	 692060	  a8f5c	busybox_old
 674804	   2740	  13968	 691512	  a8d38	busybox_unstripped
2007-07-14 22:07:14 +00:00

165 lines
4.4 KiB
C

/* vi: set sw=4 ts=4: */
/*
* vconfig implementation for busybox
*
* Copyright (C) 2001 Manuel Novoa III <mjn3@codepoet.org>
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
/* BB_AUDIT SUSv3 N/A */
#include "libbb.h"
#include <net/if.h>
/* Stuff from linux/if_vlan.h, kernel version 2.4.23 */
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, /* Name will look like: vlan0005 */
VLAN_NAME_TYPE_RAW_PLUS_VID, /* name will look like: eth1.0005 */
VLAN_NAME_TYPE_PLUS_VID_NO_PAD, /* Name will look like: vlan5 */
VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD, /* Name will look like: eth0.5 */
VLAN_NAME_TYPE_HIGHEST
};
struct vlan_ioctl_args {
int cmd; /* Should be one of the vlan_ioctl_cmds enum above. */
char device1[24];
union {
char device2[24];
int VID;
unsigned int skb_priority;
unsigned int name_type;
unsigned int bind_type;
unsigned int flag; /* Matches vlan_dev_info flags */
} u;
short vlan_qos;
};
#define VLAN_GROUP_ARRAY_LEN 4096
#define SIOCSIFVLAN 0x8983 /* Set 802.1Q VLAN options */
/* On entry, table points to the length of the current string plus
* nul terminator plus data length for the subsequent entry. The
* return value is the last data entry for the matching string. */
static const char *xfind_str(const char *table, const char *str)
{
while (strcasecmp(str, table+1) != 0) {
if (!*(table += table[0])) {
bb_show_usage();
}
}
return table - 1;
}
static const char cmds[] = {
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, 16,
's', 'e', 't', '_',
'i', 'n', 'g', 'r', 'e', 's', 's', '_',
'm', 'a', 'p', 0,
};
static const char name_types[] = {
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, 20,
'D', 'E', 'V',
'_', 'P', 'L', 'U', 'S', '_', 'V', 'I', 'D',
'_', 'N', 'O', '_', 'P', 'A', 'D', 0,
};
static const char conf_file_name[] = "/proc/net/vlan/config";
int vconfig_main(int argc, char **argv);
int vconfig_main(int argc, char **argv)
{
struct vlan_ioctl_args ifr;
const char *p;
int fd;
if (argc < 3) {
bb_show_usage();
}
/* Don't bother closing the filedes. It will be closed on cleanup. */
/* Will die if 802.1q is not present */
xopen(conf_file_name, O_RDONLY);
memset(&ifr, 0, sizeof(struct vlan_ioctl_args));
++argv;
p = xfind_str(cmds+2, *argv);
ifr.cmd = *p;
if (argc != p[-1]) {
bb_show_usage();
}
if (ifr.cmd == SET_VLAN_NAME_TYPE_CMD) { /* set_name_type */
ifr.u.name_type = *xfind_str(name_types+1, argv[1]);
} else {
if (strlen(argv[1]) >= IF_NAMESIZE) {
bb_error_msg_and_die("if_name >= %d chars", IF_NAMESIZE);
}
strcpy(ifr.device1, argv[1]);
p = argv[2];
/* I suppose one could try to combine some of the function calls below,
* since ifr.u.flag, ifr.u.VID, and ifr.u.skb_priority are all same-sized
* (unsigned) int members of a unions. But because of the range checking,
* doing so wouldn't save that much space and would also make maintainence
* more of a pain. */
if (ifr.cmd == SET_VLAN_FLAG_CMD) { /* set_flag */
ifr.u.flag = xatoul_range(p, 0, 1);
/* DM: in order to set reorder header, qos must be set */
ifr.vlan_qos = xatoul_range(argv[3], 0, 7);
} else if (ifr.cmd == ADD_VLAN_CMD) { /* add */
ifr.u.VID = xatoul_range(p, 0, VLAN_GROUP_ARRAY_LEN-1);
} else if (ifr.cmd != DEL_VLAN_CMD) { /* set_{egress|ingress}_map */
ifr.u.skb_priority = xatou(p);
ifr.vlan_qos = xatoul_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);
return 0;
}