Centralize the ROUNDUP and ADVANCE macro in a header file, give them an

RT_ prefix and use them appropriately, instead of making copies. Make
pppd use the RT_ROUNDUP macro; fixes proxyarp setting on 64 bit hosts.

XXX: All this should be pulled up to 5.0
This commit is contained in:
christos 2009-04-02 21:02:06 +00:00
parent bbb900dedf
commit af069eb3c7
5 changed files with 23 additions and 29 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: route.c,v 1.116 2009/03/24 16:36:52 roy Exp $ */
/* $NetBSD: route.c,v 1.117 2009/04/02 21:02:06 christos Exp $ */
/*-
* Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@ -93,7 +93,7 @@
#include "opt_route.h"
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.116 2009/03/24 16:36:52 roy Exp $");
__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.117 2009/04/02 21:02:06 christos Exp $");
#include <sys/param.h>
#include <sys/sysctl.h>
@ -608,8 +608,6 @@ ifa_ifwithroute(int flags, const struct sockaddr *dst,
return ifa;
}
#define ROUNDUP(a) (a>0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
int
rtrequest(int req, const struct sockaddr *dst, const struct sockaddr *gateway,
const struct sockaddr *netmask, int flags, struct rtentry **ret_nrt)

View File

@ -1,4 +1,4 @@
/* $NetBSD: route.h,v 1.72 2009/01/11 02:45:54 christos Exp $ */
/* $NetBSD: route.h,v 1.73 2009/04/02 21:02:06 christos Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -257,6 +257,10 @@ struct rt_msghdr {
#define RTAX_BRD 7 /* for NEWADDR, broadcast or p-p dest addr */
#define RTAX_MAX 8 /* size of array to allocate */
#define RT_ROUNDUP(a) \
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
#define RT_ADVANCE(x, n) (x += RT_ROUNDUP((n)->sa_len))
struct rt_addrinfo {
int rti_addrs;
const struct sockaddr *rti_info[RTAX_MAX];

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtsock.c,v 1.124 2009/03/11 09:26:27 roy Exp $ */
/* $NetBSD: rtsock.c,v 1.125 2009/04/02 21:02:06 christos Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.124 2009/03/11 09:26:27 roy Exp $");
__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.125 2009/04/02 21:02:06 christos Exp $");
#include "opt_inet.h"
#ifdef _KERNEL_OPT
@ -515,10 +515,6 @@ rt_setmetrics(u_long which, const struct rt_metrics *in, struct nrt_metrics *out
#undef metric
}
#define ROUNDUP(a) \
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
static int
rt_xaddrs(u_char rtmtype, const char *cp, const char *cplim,
struct rt_addrinfo *rtinfo)
@ -530,7 +526,7 @@ rt_xaddrs(u_char rtmtype, const char *cp, const char *cplim,
if ((rtinfo->rti_addrs & (1 << i)) == 0)
continue;
rtinfo->rti_info[i] = sa = (const struct sockaddr *)cp;
ADVANCE(cp, sa);
RT_ADVANCE(cp, sa);
}
/*
@ -546,7 +542,7 @@ rt_xaddrs(u_char rtmtype, const char *cp, const char *cplim,
/* Check for bad data length. */
if (cp != cplim) {
if (i == RTAX_NETMASK + 1 && sa != NULL &&
cp - ROUNDUP(sa->sa_len) + sa->sa_len == cplim)
cp - RT_ROUNDUP(sa->sa_len) + sa->sa_len == cplim)
/*
* The last sockaddr was info.rti_info[RTAX_NETMASK].
* We accept this for now for the sake of old
@ -626,7 +622,7 @@ rt_msg1(int type, struct rt_addrinfo *rtinfo, void *data, int datalen)
if ((sa = rtinfo->rti_info[i]) == NULL)
continue;
rtinfo->rti_addrs |= (1 << i);
dlen = ROUNDUP(sa->sa_len);
dlen = RT_ROUNDUP(sa->sa_len);
m_copyback(m, len, dlen, sa);
len += dlen;
}
@ -695,7 +691,7 @@ again:
if ((sa = rtinfo->rti_info[i]) == NULL)
continue;
rtinfo->rti_addrs |= (1 << i);
dlen = ROUNDUP(sa->sa_len);
dlen = RT_ROUNDUP(sa->sa_len);
if (cp) {
(void)memcpy(cp, sa, (size_t)dlen);
cp += dlen;

View File

@ -1,4 +1,4 @@
/* $NetBSD: arp.c,v 1.47 2008/07/21 13:36:57 lukem Exp $ */
/* $NetBSD: arp.c,v 1.48 2009/04/02 21:02:06 christos Exp $ */
/*
* Copyright (c) 1984, 1993
@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1984, 1993\
#if 0
static char sccsid[] = "@(#)arp.c 8.3 (Berkeley) 4/28/95";
#else
__RCSID("$NetBSD: arp.c,v 1.47 2008/07/21 13:36:57 lukem Exp $");
__RCSID("$NetBSD: arp.c,v 1.48 2009/04/02 21:02:06 christos Exp $");
#endif
#endif /* not lint */
@ -50,10 +50,6 @@ __RCSID("$NetBSD: arp.c,v 1.47 2008/07/21 13:36:57 lukem Exp $");
* arp - display, set, and delete arp table entries
*/
/* Roundup the same way rt_xaddrs does */
#define ROUNDUP(a) \
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
#include <sys/param.h>
#include <sys/file.h>
#include <sys/socket.h>
@ -285,7 +281,7 @@ tryagain:
return (1);
}
sina = (struct sockaddr_inarp *)(void *)(rtm + 1);
sdl = (struct sockaddr_dl *)(void *)(ROUNDUP(sina->sin_len) +
sdl = (struct sockaddr_dl *)(void *)(RT_ROUNDUP(sina->sin_len) +
(char *)(void *)sina);
if (sina->sin_addr.s_addr == sin_m.sin_addr.s_addr) {
if (is_llinfo(sdl, rtm->rtm_flags))
@ -379,7 +375,7 @@ tryagain:
return (1);
}
sina = (struct sockaddr_inarp *)(void *)(rtm + 1);
sdl = (struct sockaddr_dl *)(void *)(ROUNDUP(sina->sin_len) +
sdl = (struct sockaddr_dl *)(void *)(RT_ROUNDUP(sina->sin_len) +
(char *)(void *)sina);
if (sina->sin_addr.s_addr == sin_m.sin_addr.s_addr &&
is_llinfo(sdl, rtm->rtm_flags))
@ -439,7 +435,7 @@ dump(uint32_t addr)
rtm = (struct rt_msghdr *)(void *)next;
sina = (struct sockaddr_inarp *)(void *)(rtm + 1);
sdl = (struct sockaddr_dl *)(void *)
(ROUNDUP(sina->sin_len) + (char *)(void *)sina);
(RT_ROUNDUP(sina->sin_len) + (char *)(void *)sina);
if (addr) {
if (addr != sina->sin_addr.s_addr)
continue;
@ -471,7 +467,7 @@ dump(uint32_t addr)
(void)printf(" published (proxy only)");
if (rtm->rtm_addrs & RTA_NETMASK) {
sina = (struct sockaddr_inarp *)(void *)
(ROUNDUP(sdl->sdl_len) + (char *)(void *)sdl);
(RT_ROUNDUP(sdl->sdl_len) + (char *)(void *)sdl);
if (sina->sin_addr.s_addr == 0xffffffff)
(void)printf(" published");
if (sina->sin_len != 8)
@ -626,7 +622,7 @@ rtmsg(int cmd)
if (rtm->rtm_addrs & (w)) { \
(void)memcpy(cp, &s, \
(size_t)((struct sockaddr *)(void *)&s)->sa_len); \
cp += ROUNDUP(((struct sockaddr *)(void *)&s)->sa_len); \
RT_ADVANCE(cp, ((struct sockaddr *)(void *)&s)); \
}
NEXTADDR(RTA_DST, sin_m);

View File

@ -1,4 +1,4 @@
/* $NetBSD: sys-bsd.c,v 1.58 2008/10/25 22:12:20 christos Exp $ */
/* $NetBSD: sys-bsd.c,v 1.59 2009/04/02 21:02:06 christos Exp $ */
/*
* sys-bsd.c - System-dependent procedures for setting up
@ -79,7 +79,7 @@
#if 0
#define RCSID "Id: sys-bsd.c,v 1.47 2000/04/13 12:04:23 paulus Exp "
#else
__RCSID("$NetBSD: sys-bsd.c,v 1.58 2008/10/25 22:12:20 christos Exp $");
__RCSID("$NetBSD: sys-bsd.c,v 1.59 2009/04/02 21:02:06 christos Exp $");
#endif
#endif
@ -1615,7 +1615,7 @@ sifproxyarp(int unit, u_int32_t hisaddr)
arpmsg.dst.sin_other = SIN_PROXY;
arpmsg.hdr.rtm_msglen = (char *) &arpmsg.hwa - (char *) &arpmsg
+ arpmsg.hwa.sdl_len;
+ RT_ROUNDUP(arpmsg.hwa.sdl_len);
if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) {
error("Couldn't add proxy arp entry: %m");
close(routes);