Use RT_ROUNDUP() and friends from sys/route.h instead of homegrown

variants.
This commit is contained in:
martin 2011-02-04 14:31:23 +00:00
parent 1b0c8eddf4
commit 82fe9809af
5 changed files with 15 additions and 40 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: show.c,v 1.42 2010/12/13 17:39:47 pooka Exp $ */
/* $NetBSD: show.c,v 1.43 2011/02/04 14:31:23 martin Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "from: @(#)route.c 8.3 (Berkeley) 3/9/94";
#else
__RCSID("$NetBSD: show.c,v 1.42 2010/12/13 17:39:47 pooka Exp $");
__RCSID("$NetBSD: show.c,v 1.43 2011/02/04 14:31:23 martin Exp $");
#endif
#endif /* not lint */
@ -65,9 +65,6 @@ __RCSID("$NetBSD: show.c,v 1.42 2010/12/13 17:39:47 pooka Exp $");
#include "extern.h"
#include "prog_ops.h"
#define ROUNDUP(a) \
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
/*
* Definitions for showing gateway flags.
@ -290,14 +287,14 @@ p_rtentry(struct rt_msghdr *rtm)
else {
/* skip to gateway */
nm = (struct sockaddr *)
(ROUNDUP(sa->sa_len) + (char *)sa);
(RT_ROUNDUP(sa->sa_len) + (char *)sa);
/* skip over gateway to netmask */
nm = (struct sockaddr *)
(ROUNDUP(nm->sa_len) + (char *)nm);
(RT_ROUNDUP(nm->sa_len) + (char *)nm);
}
p_sockaddr(sa, nm, rtm->rtm_flags, WID_DST(af));
sa = (struct sockaddr *)(ROUNDUP(sa->sa_len) + (char *)sa);
sa = (struct sockaddr *)(RT_ROUNDUP(sa->sa_len) + (char *)sa);
p_sockaddr(sa, NULL, 0, WID_GW(af));
}
p_flags(rtm->rtm_flags & interesting);

View File

@ -1,4 +1,4 @@
/* $NetBSD: if.c,v 1.70 2010/12/13 21:15:30 pooka Exp $ */
/* $NetBSD: if.c,v 1.71 2011/02/04 14:31:23 martin Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "from: @(#)if.c 8.2 (Berkeley) 2/21/94";
#else
__RCSID("$NetBSD: if.c,v 1.70 2010/12/13 21:15:30 pooka Exp $");
__RCSID("$NetBSD: if.c,v 1.71 2011/02/04 14:31:23 martin Exp $");
#endif
#endif /* not lint */
@ -948,13 +948,6 @@ catchalarm(signo)
signalled = true;
}
#define ROUNDUP(a, size) \
(((a) & ((size)-1)) ? (1 + ((a) | ((size)-1))) : (a))
#define NEXT_SA(ap) (ap) = (struct sockaddr *) \
((caddr_t)(ap) + ((ap)->sa_len ? ROUNDUP((ap)->sa_len,\
sizeof(u_long)) : sizeof(u_long)))
static void
get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info)
{
@ -963,9 +956,8 @@ get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info)
for (i = 0; i < RTAX_MAX; i++) {
if (addrs & (1 << i)) {
rti_info[i] = sa;
NEXT_SA(sa);
/* sa = (struct sockaddr *)((char *)(sa) +
roundup(sa->sa_len, sizeof(long))); */
sa = (struct sockaddr *)((char *)(sa) +
RT_ROUNDUP(sa->sa_len));
} else
rti_info[i] = NULL;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: route.c,v 1.76 2011/02/01 01:39:21 matt Exp $ */
/* $NetBSD: route.c,v 1.77 2011/02/04 14:31:23 martin Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "from: @(#)route.c 8.3 (Berkeley) 3/9/94";
#else
__RCSID("$NetBSD: route.c,v 1.76 2011/02/01 01:39:21 matt Exp $");
__RCSID("$NetBSD: route.c,v 1.77 2011/02/04 14:31:23 martin Exp $");
#endif
#endif /* not lint */
@ -70,11 +70,6 @@ __RCSID("$NetBSD: route.c,v 1.76 2011/02/01 01:39:21 matt Exp $");
#define kget(p, d) (kread((u_long)(p), (char *)&(d), sizeof (d)))
/* alignment constraint for routing socket */
#define ROUNDUP(a) \
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
/*
* XXX we put all of the sockaddr types in here to force the alignment
* to be correct.

View File

@ -1,4 +1,4 @@
/* $NetBSD: show.c,v 1.12 2011/02/01 01:39:21 matt Exp $ */
/* $NetBSD: show.c,v 1.13 2011/02/04 14:31:23 martin Exp $ */
/* $OpenBSD: show.c,v 1.1 2006/05/27 19:16:37 claudio Exp $ */
/*
@ -63,10 +63,6 @@ char *any_ntoa(const struct sockaddr *);
char *link_print(struct sockaddr *);
char *mpls_ntoa(const struct sockaddr *);
#define ROUNDUP(a) \
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
#define PFKEYV2_CHUNK sizeof(u_int64_t)
/*
@ -229,7 +225,7 @@ get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info)
if (addrs & (1 << i)) {
rti_info[i] = sa;
sa = (struct sockaddr *)((char *)(sa) +
ROUNDUP(sa->sa_len));
RT_ROUNDUP(sa->sa_len));
} else
rti_info[i] = NULL;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: ifwatchd.c,v 1.24 2009/04/15 08:33:04 lukem Exp $ */
/* $NetBSD: ifwatchd.c,v 1.25 2011/02/04 14:31:23 martin Exp $ */
/*-
* Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@ -84,11 +84,6 @@ static int check_is_connected(const char * ifname, int def_retvalue);
#define if_is_not_connected(X) 1
#endif
/* stolen from /sbin/route */
#define ROUNDUP(a) \
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
/* global variables */
static int verbose = 0, quiet = 0;
static int inhibit_initial = 0;
@ -317,7 +312,7 @@ check_addrs(char *cp, int addrs, enum event ev)
ifa = sa;
else if (i == RTA_BRD)
brd = sa;
ADVANCE(cp, sa);
RT_ADVANCE(cp, sa);
}
if (ifa != NULL) {
ifname = if_indextoname(ifndx, ifname_buf);