mirror of
https://github.com/sheumann/hush.git
synced 2025-01-03 00:31:16 +00:00
*: s/IF_NAMESIZE/IFNAMSIZ/, regularize its use a bit.
function old new delta strncpy_IFNAMSIZ - 13 +13 set_slave_mtu 39 37 -2 set_slave_hwaddr 52 50 -2 set_master_hwaddr 52 50 -2 set_if_flags 40 38 -2 get_if_settings 101 98 -3 ifenslave_main 1680 1661 -19 vconfig_main 306 280 -26 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/7 up/down: 13/-56) Total: -43 bytes
This commit is contained in:
parent
0a1446275d
commit
01eaee9309
@ -576,7 +576,7 @@ config NAMEIF
|
|||||||
Renamed interfaces MUST be in the down state.
|
Renamed interfaces MUST be in the down state.
|
||||||
It is possible to use a file (default: /etc/mactab)
|
It is possible to use a file (default: /etc/mactab)
|
||||||
with list of new interface names and MACs.
|
with list of new interface names and MACs.
|
||||||
Maximum interface name length: IF_NAMESIZE = 16
|
Maximum interface name length: IFNAMSIZ = 16
|
||||||
File fields are separated by space or tab.
|
File fields are separated by space or tab.
|
||||||
File format:
|
File format:
|
||||||
# Comment
|
# Comment
|
||||||
|
@ -137,7 +137,7 @@ int brctl_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
|||||||
|
|
||||||
if (!if_indextoname(bridx[i], brname))
|
if (!if_indextoname(bridx[i], brname))
|
||||||
bb_perror_msg_and_die("can't get bridge name for index %d", i);
|
bb_perror_msg_and_die("can't get bridge name for index %d", i);
|
||||||
safe_strncpy(ifr.ifr_name, brname, IFNAMSIZ);
|
strncpy(ifr.ifr_name, brname, IFNAMSIZ);
|
||||||
|
|
||||||
arm_ioctl(args, BRCTL_GET_BRIDGE_INFO,
|
arm_ioctl(args, BRCTL_GET_BRIDGE_INFO,
|
||||||
(unsigned long) &bi, 0);
|
(unsigned long) &bi, 0);
|
||||||
@ -191,7 +191,7 @@ int brctl_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
|||||||
if (!*argv) /* all but 'addif/delif' need at least two arguments */
|
if (!*argv) /* all but 'addif/delif' need at least two arguments */
|
||||||
bb_show_usage();
|
bb_show_usage();
|
||||||
|
|
||||||
safe_strncpy(ifr.ifr_name, br, IFNAMSIZ);
|
strncpy(ifr.ifr_name, br, IFNAMSIZ);
|
||||||
if (key == ARG_addif || key == ARG_delif) { /* addif or delif */
|
if (key == ARG_addif || key == ARG_delif) { /* addif or delif */
|
||||||
brif = *argv;
|
brif = *argv;
|
||||||
ifr.ifr_ifindex = if_nametoindex(brif);
|
ifr.ifr_ifindex = if_nametoindex(brif);
|
||||||
|
@ -315,7 +315,7 @@ int ifconfig_main(int argc, char **argv)
|
|||||||
sockfd = xsocket(AF_INET, SOCK_DGRAM, 0);
|
sockfd = xsocket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
|
||||||
/* get interface name */
|
/* get interface name */
|
||||||
safe_strncpy(ifr.ifr_name, *argv, IFNAMSIZ);
|
strncpy(ifr.ifr_name, *argv, IFNAMSIZ);
|
||||||
|
|
||||||
/* Process the remaining arguments. */
|
/* Process the remaining arguments. */
|
||||||
while (*++argv != (char *) NULL) {
|
while (*++argv != (char *) NULL) {
|
||||||
|
@ -148,6 +148,10 @@ static void change_active(char *master_ifname, char *slave_ifname);
|
|||||||
static int enslave(char *master_ifname, char *slave_ifname);
|
static int enslave(char *master_ifname, char *slave_ifname);
|
||||||
static int release(char *master_ifname, char *slave_ifname);
|
static int release(char *master_ifname, char *slave_ifname);
|
||||||
|
|
||||||
|
static void strncpy_IFNAMSIZ(char *dst, const char *src)
|
||||||
|
{
|
||||||
|
strncpy(dst, src, IFNAMSIZ);
|
||||||
|
}
|
||||||
|
|
||||||
int ifenslave_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
int ifenslave_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||||
int ifenslave_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
int ifenslave_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||||
@ -302,7 +306,7 @@ static void get_drv_info(char *master_ifname)
|
|||||||
struct ethtool_drvinfo info;
|
struct ethtool_drvinfo info;
|
||||||
|
|
||||||
memset(&ifr, 0, sizeof(ifr));
|
memset(&ifr, 0, sizeof(ifr));
|
||||||
strncpy(ifr.ifr_name, master_ifname, IFNAMSIZ);
|
strncpy_IFNAMSIZ(ifr.ifr_name, master_ifname);
|
||||||
ifr.ifr_data = (caddr_t)&info;
|
ifr.ifr_data = (caddr_t)&info;
|
||||||
|
|
||||||
info.cmd = ETHTOOL_GDRVINFO;
|
info.cmd = ETHTOOL_GDRVINFO;
|
||||||
@ -332,8 +336,8 @@ static void change_active(char *master_ifname, char *slave_ifname)
|
|||||||
slave_ifname);
|
slave_ifname);
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(ifr.ifr_name, master_ifname, IFNAMSIZ);
|
strncpy_IFNAMSIZ(ifr.ifr_name, master_ifname);
|
||||||
strncpy(ifr.ifr_slave, slave_ifname, IFNAMSIZ);
|
strncpy_IFNAMSIZ(ifr.ifr_slave, slave_ifname);
|
||||||
if (ioctl(skfd, SIOCBONDCHANGEACTIVE, &ifr) < 0
|
if (ioctl(skfd, SIOCBONDCHANGEACTIVE, &ifr) < 0
|
||||||
&& ioctl(skfd, BOND_CHANGE_ACTIVE_OLD, &ifr) < 0
|
&& ioctl(skfd, BOND_CHANGE_ACTIVE_OLD, &ifr) < 0
|
||||||
) {
|
) {
|
||||||
@ -448,8 +452,8 @@ static int enslave(char *master_ifname, char *slave_ifname)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Do the real thing */
|
/* Do the real thing */
|
||||||
strncpy(ifr.ifr_name, master_ifname, IFNAMSIZ);
|
strncpy_IFNAMSIZ(ifr.ifr_name, master_ifname);
|
||||||
strncpy(ifr.ifr_slave, slave_ifname, IFNAMSIZ);
|
strncpy_IFNAMSIZ(ifr.ifr_slave, slave_ifname);
|
||||||
if (ioctl(skfd, SIOCBONDENSLAVE, &ifr) < 0
|
if (ioctl(skfd, SIOCBONDENSLAVE, &ifr) < 0
|
||||||
&& ioctl(skfd, BOND_ENSLAVE_OLD, &ifr) < 0
|
&& ioctl(skfd, BOND_ENSLAVE_OLD, &ifr) < 0
|
||||||
) {
|
) {
|
||||||
@ -484,8 +488,8 @@ static int release(char *master_ifname, char *slave_ifname)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(ifr.ifr_name, master_ifname, IFNAMSIZ);
|
strncpy_IFNAMSIZ(ifr.ifr_name, master_ifname);
|
||||||
strncpy(ifr.ifr_slave, slave_ifname, IFNAMSIZ);
|
strncpy_IFNAMSIZ(ifr.ifr_slave, slave_ifname);
|
||||||
if (ioctl(skfd, SIOCBONDRELEASE, &ifr) < 0
|
if (ioctl(skfd, SIOCBONDRELEASE, &ifr) < 0
|
||||||
&& ioctl(skfd, BOND_RELEASE_OLD, &ifr) < 0
|
&& ioctl(skfd, BOND_RELEASE_OLD, &ifr) < 0
|
||||||
) {
|
) {
|
||||||
@ -508,11 +512,11 @@ static int get_if_settings(char *ifname, struct dev_data *dd)
|
|||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
strncpy(dd->mtu.ifr_name, ifname, IFNAMSIZ);
|
strncpy_IFNAMSIZ(dd->mtu.ifr_name, ifname);
|
||||||
res = ioctl(skfd, SIOCGIFMTU, &dd->mtu);
|
res = ioctl(skfd, SIOCGIFMTU, &dd->mtu);
|
||||||
strncpy(dd->flags.ifr_name, ifname, IFNAMSIZ);
|
strncpy_IFNAMSIZ(dd->flags.ifr_name, ifname);
|
||||||
res |= ioctl(skfd, SIOCGIFFLAGS, &dd->flags);
|
res |= ioctl(skfd, SIOCGIFFLAGS, &dd->flags);
|
||||||
strncpy(dd->hwaddr.ifr_name, ifname, IFNAMSIZ);
|
strncpy_IFNAMSIZ(dd->hwaddr.ifr_name, ifname);
|
||||||
res |= ioctl(skfd, SIOCGIFHWADDR, &dd->hwaddr);
|
res |= ioctl(skfd, SIOCGIFHWADDR, &dd->hwaddr);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
@ -520,7 +524,7 @@ static int get_if_settings(char *ifname, struct dev_data *dd)
|
|||||||
|
|
||||||
static int get_slave_flags(char *slave_ifname)
|
static int get_slave_flags(char *slave_ifname)
|
||||||
{
|
{
|
||||||
strncpy(slave.flags.ifr_name, slave_ifname, IFNAMSIZ);
|
strncpy_IFNAMSIZ(slave.flags.ifr_name, slave_ifname);
|
||||||
return ioctl(skfd, SIOCGIFFLAGS, &slave.flags);
|
return ioctl(skfd, SIOCGIFFLAGS, &slave.flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -528,7 +532,7 @@ static int set_master_hwaddr(char *master_ifname, struct sockaddr *hwaddr)
|
|||||||
{
|
{
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
|
|
||||||
strncpy(ifr.ifr_name, master_ifname, IFNAMSIZ);
|
strncpy_IFNAMSIZ(ifr.ifr_name, master_ifname);
|
||||||
memcpy(&(ifr.ifr_hwaddr), hwaddr, sizeof(struct sockaddr));
|
memcpy(&(ifr.ifr_hwaddr), hwaddr, sizeof(struct sockaddr));
|
||||||
return ioctl(skfd, SIOCSIFHWADDR, &ifr);
|
return ioctl(skfd, SIOCSIFHWADDR, &ifr);
|
||||||
}
|
}
|
||||||
@ -537,7 +541,7 @@ static int set_slave_hwaddr(char *slave_ifname, struct sockaddr *hwaddr)
|
|||||||
{
|
{
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
|
|
||||||
strncpy(ifr.ifr_name, slave_ifname, IFNAMSIZ);
|
strncpy_IFNAMSIZ(ifr.ifr_name, slave_ifname);
|
||||||
memcpy(&(ifr.ifr_hwaddr), hwaddr, sizeof(struct sockaddr));
|
memcpy(&(ifr.ifr_hwaddr), hwaddr, sizeof(struct sockaddr));
|
||||||
return ioctl(skfd, SIOCSIFHWADDR, &ifr);
|
return ioctl(skfd, SIOCSIFHWADDR, &ifr);
|
||||||
}
|
}
|
||||||
@ -547,7 +551,7 @@ static int set_slave_mtu(char *slave_ifname, int mtu)
|
|||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
|
|
||||||
ifr.ifr_mtu = mtu;
|
ifr.ifr_mtu = mtu;
|
||||||
strncpy(ifr.ifr_name, slave_ifname, IFNAMSIZ);
|
strncpy_IFNAMSIZ(ifr.ifr_name, slave_ifname);
|
||||||
return ioctl(skfd, SIOCSIFMTU, &ifr);
|
return ioctl(skfd, SIOCSIFMTU, &ifr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -556,7 +560,7 @@ static int set_if_flags(char *ifname, short flags)
|
|||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
|
|
||||||
ifr.ifr_flags = flags;
|
ifr.ifr_flags = flags;
|
||||||
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
|
strncpy_IFNAMSIZ(ifr.ifr_name, ifname);
|
||||||
return ioctl(skfd, SIOCSIFFLAGS, &ifr);
|
return ioctl(skfd, SIOCSIFFLAGS, &ifr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -580,7 +584,7 @@ static int clear_if_addr(char *ifname)
|
|||||||
{
|
{
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
|
|
||||||
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
|
strncpy_IFNAMSIZ(ifr.ifr_name, ifname);
|
||||||
ifr.ifr_addr.sa_family = AF_INET;
|
ifr.ifr_addr.sa_family = AF_INET;
|
||||||
memset(ifr.ifr_addr.sa_data, 0, sizeof(ifr.ifr_addr.sa_data));
|
memset(ifr.ifr_addr.sa_data, 0, sizeof(ifr.ifr_addr.sa_data));
|
||||||
return ioctl(skfd, SIOCSIFADDR, &ifr);
|
return ioctl(skfd, SIOCSIFADDR, &ifr);
|
||||||
@ -603,7 +607,7 @@ static int set_if_addr(char *master_ifname, char *slave_ifname)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(ifra); i++) {
|
for (i = 0; i < ARRAY_SIZE(ifra); i++) {
|
||||||
strncpy(ifr.ifr_name, master_ifname, IFNAMSIZ);
|
strncpy_IFNAMSIZ(ifr.ifr_name, master_ifname);
|
||||||
res = ioctl(skfd, ifra[i].g_ioctl, &ifr);
|
res = ioctl(skfd, ifra[i].g_ioctl, &ifr);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
ifr.ifr_addr.sa_family = AF_INET;
|
ifr.ifr_addr.sa_family = AF_INET;
|
||||||
@ -611,7 +615,7 @@ static int set_if_addr(char *master_ifname, char *slave_ifname)
|
|||||||
sizeof(ifr.ifr_addr.sa_data));
|
sizeof(ifr.ifr_addr.sa_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(ifr.ifr_name, slave_ifname, IFNAMSIZ);
|
strncpy_IFNAMSIZ(ifr.ifr_name, slave_ifname);
|
||||||
res = ioctl(skfd, ifra[i].s_ioctl, &ifr);
|
res = ioctl(skfd, ifra[i].s_ioctl, &ifr);
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return res;
|
return res;
|
||||||
|
@ -388,7 +388,7 @@ static struct interface *add_interface(char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
new = xzalloc(sizeof(*new));
|
new = xzalloc(sizeof(*new));
|
||||||
safe_strncpy(new->name, name, IFNAMSIZ);
|
strncpy(new->name, name, IFNAMSIZ);
|
||||||
nextp = ife ? &ife->next : &int_list;
|
nextp = ife ? &ife->next : &int_list;
|
||||||
new->prev = ife;
|
new->prev = ife;
|
||||||
new->next = *nextp;
|
new->next = *nextp;
|
||||||
|
@ -16,16 +16,11 @@
|
|||||||
#include <netinet/ether.h>
|
#include <netinet/ether.h>
|
||||||
#include <linux/sockios.h>
|
#include <linux/sockios.h>
|
||||||
|
|
||||||
/* Older versions of net/if.h do not appear to define IF_NAMESIZE. */
|
#ifndef IFNAMSIZ
|
||||||
#ifndef IF_NAMESIZE
|
#define IFNAMSIZ 16
|
||||||
# ifdef IFNAMSIZ
|
|
||||||
# define IF_NAMESIZE IFNAMSIZ
|
|
||||||
# else
|
|
||||||
# define IF_NAMESIZE 16
|
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* take from linux/sockios.h */
|
/* Taken from linux/sockios.h */
|
||||||
#define SIOCSIFNAME 0x8923 /* set interface name */
|
#define SIOCSIFNAME 0x8923 /* set interface name */
|
||||||
|
|
||||||
/* Octets in one Ethernet addr, from <linux/if_ether.h> */
|
/* Octets in one Ethernet addr, from <linux/if_ether.h> */
|
||||||
@ -111,7 +106,7 @@ static void nameif_parse_selector(ethtable_t *ch, char *selector)
|
|||||||
static void prepend_new_eth_table(ethtable_t **clist, char *ifname, char *selector)
|
static void prepend_new_eth_table(ethtable_t **clist, char *ifname, char *selector)
|
||||||
{
|
{
|
||||||
ethtable_t *ch;
|
ethtable_t *ch;
|
||||||
if (strlen(ifname) >= IF_NAMESIZE)
|
if (strlen(ifname) >= IFNAMSIZ)
|
||||||
bb_error_msg_and_die("interface name '%s' too long", ifname);
|
bb_error_msg_and_die("interface name '%s' too long", ifname);
|
||||||
ch = xzalloc(sizeof(*ch));
|
ch = xzalloc(sizeof(*ch));
|
||||||
ch->ifname = xstrdup(ifname);
|
ch->ifname = xstrdup(ifname);
|
||||||
|
@ -133,10 +133,7 @@ int vconfig_main(int argc, char **argv)
|
|||||||
if (ifr.cmd == SET_VLAN_NAME_TYPE_CMD) { /* set_name_type */
|
if (ifr.cmd == SET_VLAN_NAME_TYPE_CMD) { /* set_name_type */
|
||||||
ifr.u.name_type = *xfind_str(name_types+1, argv[1]);
|
ifr.u.name_type = *xfind_str(name_types+1, argv[1]);
|
||||||
} else {
|
} else {
|
||||||
if (strlen(argv[1]) >= IF_NAMESIZE) {
|
strncpy(ifr.device1, argv[1], IFNAMSIZ);
|
||||||
bb_error_msg_and_die("if_name >= %d chars", IF_NAMESIZE);
|
|
||||||
}
|
|
||||||
strcpy(ifr.device1, argv[1]);
|
|
||||||
p = argv[2];
|
p = argv[2];
|
||||||
|
|
||||||
/* I suppose one could try to combine some of the function calls below,
|
/* I suppose one could try to combine some of the function calls below,
|
||||||
|
Loading…
Reference in New Issue
Block a user