Merge branch 'master' of git+ssh://vda@busybox.net/var/lib/git/busybox

This commit is contained in:
Denys Vlasenko 2011-01-21 21:59:26 +01:00
commit e8f565c1ee
4 changed files with 69 additions and 56 deletions

View File

@ -131,18 +131,21 @@ static int network_ioctl(int request, void* data, const char *errmsg)
static smallint detect_link_mii(void) static smallint detect_link_mii(void)
{ {
struct ifreq ifreq; /* char buffer instead of bona-fide struct avoids aliasing warning */
struct mii_ioctl_data *mii = (void *)&ifreq.ifr_data; char buf[sizeof(struct ifreq)];
struct ifreq *const ifreq = (void *)buf;
set_ifreq_to_ifname(&ifreq); struct mii_ioctl_data *mii = (void *)&ifreq->ifr_data;
if (network_ioctl(SIOCGMIIPHY, &ifreq, "SIOCGMIIPHY") < 0) { set_ifreq_to_ifname(ifreq);
if (network_ioctl(SIOCGMIIPHY, ifreq, "SIOCGMIIPHY") < 0) {
return IFSTATUS_ERR; return IFSTATUS_ERR;
} }
mii->reg_num = 1; mii->reg_num = 1;
if (network_ioctl(SIOCGMIIREG, &ifreq, "SIOCGMIIREG") < 0) { if (network_ioctl(SIOCGMIIREG, ifreq, "SIOCGMIIREG") < 0) {
return IFSTATUS_ERR; return IFSTATUS_ERR;
} }
@ -151,18 +154,21 @@ static smallint detect_link_mii(void)
static smallint detect_link_priv(void) static smallint detect_link_priv(void)
{ {
struct ifreq ifreq; /* char buffer instead of bona-fide struct avoids aliasing warning */
struct mii_ioctl_data *mii = (void *)&ifreq.ifr_data; char buf[sizeof(struct ifreq)];
struct ifreq *const ifreq = (void *)buf;
set_ifreq_to_ifname(&ifreq); struct mii_ioctl_data *mii = (void *)&ifreq->ifr_data;
if (network_ioctl(SIOCDEVPRIVATE, &ifreq, "SIOCDEVPRIVATE") < 0) { set_ifreq_to_ifname(ifreq);
if (network_ioctl(SIOCDEVPRIVATE, ifreq, "SIOCDEVPRIVATE") < 0) {
return IFSTATUS_ERR; return IFSTATUS_ERR;
} }
mii->reg_num = 1; mii->reg_num = 1;
if (network_ioctl(SIOCDEVPRIVATE+1, &ifreq, "SIOCDEVPRIVATE+1") < 0) { if (network_ioctl(SIOCDEVPRIVATE+1, ifreq, "SIOCDEVPRIVATE+1") < 0) {
return IFSTATUS_ERR; return IFSTATUS_ERR;
} }

View File

@ -153,7 +153,10 @@ static int kw_lookup(const char *kwtbl, char ***pargs)
static NOINLINE void INET_setroute(int action, char **args) static NOINLINE void INET_setroute(int action, char **args)
{ {
struct rtentry rt; /* char buffer instead of bona-fide struct avoids aliasing warning */
char rt_buf[sizeof(struct rtentry)];
struct rtentry *const rt = (void *)rt_buf;
const char *netmask = NULL; const char *netmask = NULL;
int skfd, isnet, xflag; int skfd, isnet, xflag;
@ -166,7 +169,7 @@ static NOINLINE void INET_setroute(int action, char **args)
} }
/* Clean out the RTREQ structure. */ /* Clean out the RTREQ structure. */
memset(&rt, 0, sizeof(rt)); memset(rt, 0, sizeof(*rt));
{ {
const char *target = *args++; const char *target = *args++;
@ -178,17 +181,17 @@ static NOINLINE void INET_setroute(int action, char **args)
int prefix_len; int prefix_len;
prefix_len = xatoul_range(prefix+1, 0, 32); prefix_len = xatoul_range(prefix+1, 0, 32);
mask_in_addr(rt) = htonl( ~(0xffffffffUL >> prefix_len)); mask_in_addr(*rt) = htonl( ~(0xffffffffUL >> prefix_len));
*prefix = '\0'; *prefix = '\0';
#if HAVE_NEW_ADDRT #if HAVE_NEW_ADDRT
rt.rt_genmask.sa_family = AF_INET; rt->rt_genmask.sa_family = AF_INET;
#endif #endif
} else { } else {
/* Default netmask. */ /* Default netmask. */
netmask = "default"; netmask = "default";
} }
/* Prefer hostname lookup is -host flag (xflag==1) was given. */ /* Prefer hostname lookup is -host flag (xflag==1) was given. */
isnet = INET_resolve(target, (struct sockaddr_in *) &rt.rt_dst, isnet = INET_resolve(target, (struct sockaddr_in *) &rt->rt_dst,
(xflag & HOST_FLAG)); (xflag & HOST_FLAG));
if (isnet < 0) { if (isnet < 0) {
bb_error_msg_and_die("resolving %s", target); bb_error_msg_and_die("resolving %s", target);
@ -204,20 +207,20 @@ static NOINLINE void INET_setroute(int action, char **args)
} }
/* Fill in the other fields. */ /* Fill in the other fields. */
rt.rt_flags = ((isnet) ? RTF_UP : (RTF_UP | RTF_HOST)); rt->rt_flags = ((isnet) ? RTF_UP : (RTF_UP | RTF_HOST));
while (*args) { while (*args) {
int k = kw_lookup(tbl_ipvx, &args); int k = kw_lookup(tbl_ipvx, &args);
const char *args_m1 = args[-1]; const char *args_m1 = args[-1];
if (k & KW_IPVx_FLAG_ONLY) { if (k & KW_IPVx_FLAG_ONLY) {
rt.rt_flags |= flags_ipvx[k & 3]; rt->rt_flags |= flags_ipvx[k & 3];
continue; continue;
} }
#if HAVE_NEW_ADDRT #if HAVE_NEW_ADDRT
if (k == KW_IPVx_METRIC) { if (k == KW_IPVx_METRIC) {
rt.rt_metric = xatoul(args_m1) + 1; rt->rt_metric = xatoul(args_m1) + 1;
continue; continue;
} }
#endif #endif
@ -225,7 +228,7 @@ static NOINLINE void INET_setroute(int action, char **args)
if (k == KW_IPVx_NETMASK) { if (k == KW_IPVx_NETMASK) {
struct sockaddr mask; struct sockaddr mask;
if (mask_in_addr(rt)) { if (mask_in_addr(*rt)) {
bb_show_usage(); bb_show_usage();
} }
@ -234,18 +237,18 @@ static NOINLINE void INET_setroute(int action, char **args)
if (isnet < 0) { if (isnet < 0) {
bb_error_msg_and_die("resolving %s", netmask); bb_error_msg_and_die("resolving %s", netmask);
} }
rt.rt_genmask = full_mask(mask); rt->rt_genmask = full_mask(mask);
continue; continue;
} }
if (k == KW_IPVx_GATEWAY) { if (k == KW_IPVx_GATEWAY) {
if (rt.rt_flags & RTF_GATEWAY) { if (rt->rt_flags & RTF_GATEWAY) {
bb_show_usage(); bb_show_usage();
} }
isnet = INET_resolve(args_m1, isnet = INET_resolve(args_m1,
(struct sockaddr_in *) &rt.rt_gateway, 1); (struct sockaddr_in *) &rt->rt_gateway, 1);
rt.rt_flags |= RTF_GATEWAY; rt->rt_flags |= RTF_GATEWAY;
if (isnet) { if (isnet) {
if (isnet < 0) { if (isnet < 0) {
@ -257,24 +260,24 @@ static NOINLINE void INET_setroute(int action, char **args)
} }
if (k == KW_IPVx_MSS) { /* Check valid MSS bounds. */ if (k == KW_IPVx_MSS) { /* Check valid MSS bounds. */
rt.rt_flags |= RTF_MSS; rt->rt_flags |= RTF_MSS;
rt.rt_mss = xatoul_range(args_m1, 64, 32768); rt->rt_mss = xatoul_range(args_m1, 64, 32768);
continue; continue;
} }
if (k == KW_IPVx_WINDOW) { /* Check valid window bounds. */ if (k == KW_IPVx_WINDOW) { /* Check valid window bounds. */
rt.rt_flags |= RTF_WINDOW; rt->rt_flags |= RTF_WINDOW;
rt.rt_window = xatoul_range(args_m1, 128, INT_MAX); rt->rt_window = xatoul_range(args_m1, 128, INT_MAX);
continue; continue;
} }
#ifdef RTF_IRTT #ifdef RTF_IRTT
if (k == KW_IPVx_IRTT) { if (k == KW_IPVx_IRTT) {
rt.rt_flags |= RTF_IRTT; rt->rt_flags |= RTF_IRTT;
rt.rt_irtt = xatoul(args_m1); rt->rt_irtt = xatoul(args_m1);
rt.rt_irtt *= (sysconf(_SC_CLK_TCK) / 100); /* FIXME */ rt->rt_irtt *= (sysconf(_SC_CLK_TCK) / 100); /* FIXME */
#if 0 /* FIXME: do we need to check anything of this? */ #if 0 /* FIXME: do we need to check anything of this? */
if (rt.rt_irtt < 1 || rt.rt_irtt > (120 * HZ)) { if (rt->rt_irtt < 1 || rt->rt_irtt > (120 * HZ)) {
bb_error_msg_and_die("bad irtt"); bb_error_msg_and_die("bad irtt");
} }
#endif #endif
@ -284,9 +287,9 @@ static NOINLINE void INET_setroute(int action, char **args)
/* Device is special in that it can be the last arg specified /* Device is special in that it can be the last arg specified
* and doesn't requre the dev/device keyword in that case. */ * and doesn't requre the dev/device keyword in that case. */
if (!rt.rt_dev && ((k == KW_IPVx_DEVICE) || (!k && !*++args))) { if (!rt->rt_dev && ((k == KW_IPVx_DEVICE) || (!k && !*++args))) {
/* Don't use args_m1 here since args may have changed! */ /* Don't use args_m1 here since args may have changed! */
rt.rt_dev = args[-1]; rt->rt_dev = args[-1];
continue; continue;
} }
@ -295,41 +298,41 @@ static NOINLINE void INET_setroute(int action, char **args)
} }
#ifdef RTF_REJECT #ifdef RTF_REJECT
if ((rt.rt_flags & RTF_REJECT) && !rt.rt_dev) { if ((rt->rt_flags & RTF_REJECT) && !rt->rt_dev) {
rt.rt_dev = (char*)"lo"; rt->rt_dev = (char*)"lo";
} }
#endif #endif
/* sanity checks.. */ /* sanity checks.. */
if (mask_in_addr(rt)) { if (mask_in_addr(*rt)) {
uint32_t mask = mask_in_addr(rt); uint32_t mask = mask_in_addr(*rt);
mask = ~ntohl(mask); mask = ~ntohl(mask);
if ((rt.rt_flags & RTF_HOST) && mask != 0xffffffff) { if ((rt->rt_flags & RTF_HOST) && mask != 0xffffffff) {
bb_error_msg_and_die("netmask %.8x and host route conflict", bb_error_msg_and_die("netmask %.8x and host route conflict",
(unsigned int) mask); (unsigned int) mask);
} }
if (mask & (mask + 1)) { if (mask & (mask + 1)) {
bb_error_msg_and_die("bogus netmask %s", netmask); bb_error_msg_and_die("bogus netmask %s", netmask);
} }
mask = ((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr; mask = ((struct sockaddr_in *) &rt->rt_dst)->sin_addr.s_addr;
if (mask & ~(uint32_t)mask_in_addr(rt)) { if (mask & ~(uint32_t)mask_in_addr(*rt)) {
bb_error_msg_and_die("netmask and route address conflict"); bb_error_msg_and_die("netmask and route address conflict");
} }
} }
/* Fill out netmask if still unset */ /* Fill out netmask if still unset */
if ((action == RTACTION_ADD) && (rt.rt_flags & RTF_HOST)) { if ((action == RTACTION_ADD) && (rt->rt_flags & RTF_HOST)) {
mask_in_addr(rt) = 0xffffffff; mask_in_addr(*rt) = 0xffffffff;
} }
/* Create a socket to the INET kernel. */ /* Create a socket to the INET kernel. */
skfd = xsocket(AF_INET, SOCK_DGRAM, 0); skfd = xsocket(AF_INET, SOCK_DGRAM, 0);
if (action == RTACTION_ADD) if (action == RTACTION_ADD)
xioctl(skfd, SIOCADDRT, &rt); xioctl(skfd, SIOCADDRT, rt);
else else
xioctl(skfd, SIOCDELRT, &rt); xioctl(skfd, SIOCDELRT, rt);
if (ENABLE_FEATURE_CLEAN_UP) close(skfd); if (ENABLE_FEATURE_CLEAN_UP) close(skfd);
} }

View File

@ -751,7 +751,8 @@ print(int read_len, const struct sockaddr *from, const struct sockaddr *to)
} else } else
#endif #endif
{ {
read_len -= ((struct ip*)recv_pkt)->ip_hl << 2; struct ip *ip4packet = (struct ip*)recv_pkt;
read_len -= ip4packet->ip_hl << 2;
} }
printf(" %d bytes to %s", read_len, ina); printf(" %d bytes to %s", read_len, ina);
free(ina); free(ina);

View File

@ -36,42 +36,45 @@
int FAST_FUNC udhcp_read_interface(const char *interface, int *ifindex, uint32_t *nip, uint8_t *mac) int FAST_FUNC udhcp_read_interface(const char *interface, int *ifindex, uint32_t *nip, uint8_t *mac)
{ {
/* char buffer instead of bona-fide struct avoids aliasing warning */
char ifr_buf[sizeof(struct ifreq)];
struct ifreq *const ifr = (void *)ifr_buf;
int fd; int fd;
struct ifreq ifr;
struct sockaddr_in *our_ip; struct sockaddr_in *our_ip;
memset(&ifr, 0, sizeof(ifr)); memset(ifr, 0, sizeof(*ifr));
fd = xsocket(AF_INET, SOCK_RAW, IPPROTO_RAW); fd = xsocket(AF_INET, SOCK_RAW, IPPROTO_RAW);
ifr.ifr_addr.sa_family = AF_INET; ifr->ifr_addr.sa_family = AF_INET;
strncpy_IFNAMSIZ(ifr.ifr_name, interface); strncpy_IFNAMSIZ(ifr->ifr_name, interface);
if (nip) { if (nip) {
if (ioctl_or_perror(fd, SIOCGIFADDR, &ifr, if (ioctl_or_perror(fd, SIOCGIFADDR, ifr,
"is interface %s up and configured?", interface) "is interface %s up and configured?", interface)
) { ) {
close(fd); close(fd);
return -1; return -1;
} }
our_ip = (struct sockaddr_in *) &ifr.ifr_addr; our_ip = (struct sockaddr_in *) &ifr->ifr_addr;
*nip = our_ip->sin_addr.s_addr; *nip = our_ip->sin_addr.s_addr;
log1("IP %s", inet_ntoa(our_ip->sin_addr)); log1("IP %s", inet_ntoa(our_ip->sin_addr));
} }
if (ifindex) { if (ifindex) {
if (ioctl_or_warn(fd, SIOCGIFINDEX, &ifr) != 0) { if (ioctl_or_warn(fd, SIOCGIFINDEX, ifr) != 0) {
close(fd); close(fd);
return -1; return -1;
} }
log1("Adapter index %d", ifr.ifr_ifindex); log1("Adapter index %d", ifr->ifr_ifindex);
*ifindex = ifr.ifr_ifindex; *ifindex = ifr->ifr_ifindex;
} }
if (mac) { if (mac) {
if (ioctl_or_warn(fd, SIOCGIFHWADDR, &ifr) != 0) { if (ioctl_or_warn(fd, SIOCGIFHWADDR, ifr) != 0) {
close(fd); close(fd);
return -1; return -1;
} }
memcpy(mac, ifr.ifr_hwaddr.sa_data, 6); memcpy(mac, ifr->ifr_hwaddr.sa_data, 6);
log1("MAC %02x:%02x:%02x:%02x:%02x:%02x", log1("MAC %02x:%02x:%02x:%02x:%02x:%02x",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
} }