Add a new AF/PF_ROUTE which is 64-bit clean which makes the routing socket

interface (and its associated sysctls) act identically for both 32 and 64 bit
programs.  The old unclean one remains for backward compatibility.
This commit is contained in:
matt 2011-02-01 01:39:19 +00:00
parent 597d48fbe7
commit 4d5d6d9aa5
17 changed files with 535 additions and 327 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: route.c,v 1.127 2010/12/13 17:39:47 pooka Exp $ */
/* $NetBSD: route.c,v 1.128 2011/02/01 01:39:19 matt Exp $ */
/*
* Copyright (c) 1983, 1989, 1991, 1993
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1989, 1991, 1993\
#if 0
static char sccsid[] = "@(#)route.c 8.6 (Berkeley) 4/28/95";
#else
__RCSID("$NetBSD: route.c,v 1.127 2010/12/13 17:39:47 pooka Exp $");
__RCSID("$NetBSD: route.c,v 1.128 2011/02/01 01:39:19 matt Exp $");
#endif
#endif /* not lint */
@ -91,6 +91,7 @@ union sockunion {
struct sockaddr_iso siso;
struct sockaddr_mpls smpls;
#endif /* SMALL */
struct sockaddr_storage sstorage;
};
typedef union sockunion *sup;
@ -131,7 +132,7 @@ int forcehost, forcenet, doflush, nflag, af, qflag, tflag, Sflag;
int iflag, verbose, aflen = sizeof(struct sockaddr_in), rtag;
int locking, lockrest, debugonly, shortoutput;
struct rt_metrics rt_metrics;
u_int32_t rtm_inits;
int rtm_inits;
short ns_nullh[] = {0,0,0};
short ns_bh[] = {-1,-1,-1};
@ -152,9 +153,6 @@ usage(const char *cp)
#define PRIETHER "02x:%02x:%02x:%02x:%02x:%02x"
#define PRIETHER_ARGS(__enaddr) (__enaddr)[0], (__enaddr)[1], (__enaddr)[2], \
(__enaddr)[3], (__enaddr)[4], (__enaddr)[5]
#define ROUNDUP(a) \
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
int
main(int argc, char * const *argv)
@ -327,7 +325,7 @@ flushroutes(int argc, char * const argv[], int doall)
else {
(void)printf("%-20.20s ",
routename(sa, NULL, rtm->rtm_flags));
sa = (struct sockaddr *)(ROUNDUP(sa->sa_len) +
sa = (struct sockaddr *)(RT_ROUNDUP(sa->sa_len) +
(char *)sa);
(void)printf("%-20.20s ",
routename(sa, NULL, RTF_HOST));
@ -766,10 +764,11 @@ static void
set_metric(const char *value, int key)
{
int flag = 0;
u_long noval, *valp = &noval;
uint64_t noval, *valp = &noval;
switch (key) {
#define caseof(x, y, z) case x: valp = &rt_metrics.z; flag = y; break
#define caseof(x, y, z) \
case x: valp = (uint64_t *)&rt_metrics.z; flag = y; break
caseof(K_MTU, RTV_MTU, rmx_mtu);
caseof(K_HOPCOUNT, RTV_HOPCOUNT, rmx_hopcount);
caseof(K_EXPIRE, RTV_EXPIRE, rmx_expire);
@ -1479,7 +1478,7 @@ rtmsg(int cmd, int flags, struct sou *soup)
#define NEXTADDR(w, u) \
if (rtm_addrs & (w)) {\
l = ROUNDUP(u.sa.sa_len); memmove(cp, &(u), l); cp += l;\
l = RT_ROUNDUP(u.sa.sa_len); memmove(cp, &(u), l); cp += l;\
if (verbose && ! shortoutput) sodump(&(u),#u);\
}
@ -1600,30 +1599,26 @@ mask_addr(struct sou *soup)
#endif /* SMALL */
}
const char *msgtypes[] = {
"",
"RTM_ADD: Add Route",
"RTM_DELETE: Delete Route",
"RTM_CHANGE: Change Metrics or flags",
"RTM_GET: Report Metrics",
"RTM_LOSING: Kernel Suspects Partitioning",
"RTM_REDIRECT: Told to use different route",
"RTM_MISS: Lookup failed on this address",
"RTM_LOCK: fix specified metrics",
"RTM_OLDADD: caused by SIOCADDRT",
"RTM_OLDDEL: caused by SIOCDELRT",
"RTM_RESOLVE: Route created by cloning",
"RTM_NEWADDR: address being added to iface",
"RTM_DELADDR: address being removed from iface",
"RTM_OOIFINFO: iface status change (pre-1.5)",
"RTM_OIFINFO: iface status change (pre-6.0)",
"RTM_IFANNOUNCE: iface arrival/departure",
"RTM_IEEE80211: IEEE80211 wireless event",
"",
"",
"RTM_IFINFO: iface status change",
"RTM_CHGADDR: address being changed on iface",
0,
const char * const msgtypes[] = {
[RTM_ADD] = "RTM_ADD: Add Route",
[RTM_DELETE] = "RTM_DELETE: Delete Route",
[RTM_CHANGE] = "RTM_CHANGE: Change Metrics or flags",
[RTM_GET] = "RTM_GET: Report Metrics",
[RTM_LOSING] = "RTM_LOSING: Kernel Suspects Partitioning",
[RTM_REDIRECT] = "RTM_REDIRECT: Told to use different route",
[RTM_MISS] = "RTM_MISS: Lookup failed on this address",
[RTM_LOCK] = "RTM_LOCK: fix specified metrics",
[RTM_OLDADD] = "RTM_OLDADD: caused by SIOCADDRT",
[RTM_OLDDEL] = "RTM_OLDDEL: caused by SIOCDELRT",
[RTM_RESOLVE] = "RTM_RESOLVE: Route created by cloning",
[RTM_NEWADDR] = "RTM_NEWADDR: address being added to iface",
[RTM_DELADDR] = "RTM_DELADDR: address being removed from iface",
[RTM_OOIFINFO] = "RTM_OOIFINFO: iface status change (pre-1.5)",
[RTM_OIFINFO] = "RTM_OIFINFO: iface status change (pre-64bit time)",
[RTM_IFANNOUNCE] = "RTM_IFANNOUNCE: iface arrival/departure",
[RTM_IEEE80211] = "RTM_IEEE80211: IEEE80211 wireless event",
[RTM_IFINFO] = "RTM_IFINFO: iface status change",
[RTM_CHGADDR] = "RTM_CHGADDR: address being changed on iface",
};
const char metricnames[] =
@ -1805,9 +1800,10 @@ print_getmsg(struct rt_msghdr *rtm, int msglen, struct sou *soup)
char *cp;
int i;
if (! shortoutput)
if (! shortoutput) {
(void)printf(" route to: %s\n",
routename(&soup->so_dst.sa, NULL, RTF_HOST));
}
if (rtm->rtm_version != RTM_VERSION) {
warnx("routing message version %d not understood",
rtm->rtm_version);
@ -1849,7 +1845,7 @@ print_getmsg(struct rt_msghdr *rtm, int msglen, struct sou *soup)
mpls = sa;
break;
}
ADVANCE(cp, sa);
RT_ADVANCE(cp, sa);
}
if (dst && mask)
mask->sa_family = dst->sa_family; /* XXX */
@ -1903,16 +1899,16 @@ print_getmsg(struct rt_msghdr *rtm, int msglen, struct sou *soup)
if (! shortoutput) {
(void)printf("\n%s\n", "\
recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire");
printf("%8ld%c ", rtm->rtm_rmx.rmx_recvpipe, lock(RPIPE));
printf("%8ld%c ", rtm->rtm_rmx.rmx_sendpipe, lock(SPIPE));
printf("%8ld%c ", rtm->rtm_rmx.rmx_ssthresh, lock(SSTHRESH));
printf("%8ld%c ", msec(rtm->rtm_rmx.rmx_rtt), lock(RTT));
printf("%8ld%c ", msec(rtm->rtm_rmx.rmx_rttvar), lock(RTTVAR));
printf("%8ld%c ", rtm->rtm_rmx.rmx_hopcount, lock(HOPCOUNT));
printf("%8ld%c ", rtm->rtm_rmx.rmx_mtu, lock(MTU));
printf("%8"PRId64"%c ", rtm->rtm_rmx.rmx_recvpipe, lock(RPIPE));
printf("%8"PRId64"%c ", rtm->rtm_rmx.rmx_sendpipe, lock(SPIPE));
printf("%8"PRId64"%c ", rtm->rtm_rmx.rmx_ssthresh, lock(SSTHRESH));
printf("%8"PRId64"%c ", msec(rtm->rtm_rmx.rmx_rtt), lock(RTT));
printf("%8"PRId64"%c ", msec(rtm->rtm_rmx.rmx_rttvar), lock(RTTVAR));
printf("%8"PRId64"%c ", rtm->rtm_rmx.rmx_hopcount, lock(HOPCOUNT));
printf("%8"PRId64"%c ", rtm->rtm_rmx.rmx_mtu, lock(MTU));
if (rtm->rtm_rmx.rmx_expire)
rtm->rtm_rmx.rmx_expire -= time(0);
printf("%8ld%c\n", rtm->rtm_rmx.rmx_expire, lock(EXPIRE));
printf("%8"PRId64"%c\n", rtm->rtm_rmx.rmx_expire, lock(EXPIRE));
}
#undef lock
#undef msec
@ -1953,7 +1949,7 @@ extract_addrs(const char *cp, int addrs, const struct sockaddr *sa[], int *nmfp)
if ((i == RTAX_DST || i == RTAX_IFA) &&
nmf == -1)
nmf = sa[i]->sa_family;
ADVANCE(cp, sa[i]);
RT_ADVANCE(cp, sa[i]);
} else
sa[i] = NULL;
}
@ -1996,8 +1992,10 @@ bprintf(FILE *fp, int b, const char *f)
int gotsome = 0;
const uint8_t *s = (const uint8_t *)f;
if (b == 0)
if (b == 0) {
fputs("none", fp);
return;
}
while ((i = *s++) != 0) {
if (b & (1 << (i-1))) {
if (gotsome == 0)

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtsock_14.c,v 1.2 2009/01/11 02:45:47 christos Exp $ */
/* $NetBSD: rtsock_14.c,v 1.3 2011/02/01 01:39:19 matt Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: rtsock_14.c,v 1.2 2009/01/11 02:45:47 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: rtsock_14.c,v 1.3 2011/02/01 01:39:19 matt Exp $");
#include "opt_inet.h"
@ -86,16 +86,17 @@ __KERNEL_RCSID(0, "$NetBSD: rtsock_14.c,v 1.2 2009/01/11 02:45:47 christos Exp $
#include <machine/stdarg.h>
#include <compat/net/if.h>
#include <compat/net/route.h>
void
compat_14_rt_ifmsg(struct ifnet *ifp, struct if_msghdr *ifm)
compat_14_rt_oifmsg(struct ifnet *ifp)
{
struct if_msghdr14 oifm;
struct mbuf *m;
struct rt_addrinfo info;
struct timeval tv;
if (route_cb.any_count == 0)
if (compat_50_route_info.ri_cb.any_count == 0)
return;
(void)memset(&info, 0, sizeof(info));
(void)memset(&oifm, 0, sizeof(oifm));
@ -121,10 +122,10 @@ compat_14_rt_ifmsg(struct ifnet *ifp, struct if_msghdr *ifm)
TIMESPEC_TO_TIMEVAL(&tv, &ifp->if_data.ifi_lastchange);
timeval_to_timeval50(&tv, &oifm.ifm_data.ifi_lastchange);
oifm.ifm_addrs = 0;
m = rt_msg1(RTM_OOIFINFO, &info, (void *)&oifm, sizeof(oifm));
m = compat_50_rt_msg1(RTM_OOIFINFO, &info, (void *)&oifm, sizeof(oifm));
if (m == NULL)
return;
route_enqueue(m, 0);
compat_50_route_enqueue(m, 0);
}
int

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtsock_50.c,v 1.2 2009/01/11 02:45:47 christos Exp $ */
/* $NetBSD: rtsock_50.c,v 1.3 2011/02/01 01:39:19 matt Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -61,40 +61,27 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: rtsock_50.c,v 1.2 2009/01/11 02:45:47 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: rtsock_50.c,v 1.3 2011/02/01 01:39:19 matt Exp $");
#include "opt_inet.h"
#include "opt_compat_netbsd.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/mbuf.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/domain.h>
#include <sys/protosw.h>
#include <sys/sysctl.h>
#include <sys/kauth.h>
#ifdef RTSOCK_DEBUG
#include <netinet/in.h>
#endif /* RTSOCK_DEBUG */
#if defined(COMPAT_14) && !defined(COMPAT_50)
#define COMPAT_50 1 /* 1.4 needs 5.0 */
#endif
#include <net/if.h>
#include <net/route.h>
#include <net/raw_cb.h>
#if defined(COMPAT_50)
#define COMPAT_RTSOCK
#include <machine/stdarg.h>
#include <compat/net/if.h>
#include <net/rtsock.c>
void
compat_50_rt_ifmsg(struct ifnet *ifp, struct if_msghdr *ifm)
compat_50_rt_oifmsg(struct ifnet *ifp)
{
struct if_msghdr50 oifm;
struct mbuf *m;
struct rt_addrinfo info;
if (route_cb.any_count == 0)
if (COMPATNAME(route_info).ri_cb.any_count == 0)
return;
(void)memset(&info, 0, sizeof(info));
(void)memset(&oifm, 0, sizeof(oifm));
@ -120,10 +107,10 @@ compat_50_rt_ifmsg(struct ifnet *ifp, struct if_msghdr *ifm)
TIMESPEC_TO_TIMEVAL(&oifm.ifm_data.ifi_lastchange,
&ifp->if_data.ifi_lastchange);
oifm.ifm_addrs = 0;
m = rt_msg1(RTM_OIFINFO, &info, (void *)&oifm, sizeof(oifm));
m = COMPATNAME(rt_msg1)(RTM_OIFINFO, &info, (void *)&oifm, sizeof(oifm));
if (m == NULL)
return;
route_enqueue(m, 0);
COMPATNAME(route_enqueue)(m, 0);
}
int
@ -162,3 +149,5 @@ compat_50_iflist(struct ifnet *ifp, struct rt_walkarg *w,
w->w_where = (char *)w->w_where + len;
return 0;
}
#endif /* COMPAT_50 */

View File

@ -1,4 +1,4 @@
/* $NetBSD: if.h,v 1.2 2009/01/11 03:03:07 christos Exp $ */
/* $NetBSD: if.h,v 1.3 2011/02/01 01:39:20 matt Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@ -107,7 +107,7 @@ struct if_msghdr14 {
struct if_data14 ifm_data; /* statistics and other data about if */
};
void compat_14_rt_ifmsg(struct ifnet *, struct if_msghdr *);
void compat_14_rt_oifmsg(struct ifnet *);
int compat_14_iflist(struct ifnet *, struct rt_walkarg *, struct rt_addrinfo *,
size_t);
@ -153,8 +153,34 @@ struct if_msghdr50 {
struct if_data50 ifm_data;/* statistics and other data about if */
};
void compat_50_rt_ifmsg(struct ifnet *, struct if_msghdr *);
void compat_50_rt_oifmsg(struct ifnet *);
int compat_50_iflist(struct ifnet *, struct rt_walkarg *, struct rt_addrinfo *,
size_t);
/*
* Message format for use in obtaining information about interface addresses
* from sysctl and the routing socket.
*/
struct ifa_msghdr50 {
u_short ifam_msglen; /* to skip over non-understood messages */
u_char ifam_version; /* future binary compatibility */
u_char ifam_type; /* message type */
int ifam_addrs; /* like rtm_addrs */
int ifam_flags; /* value of ifa_flags */
u_short ifam_index; /* index for associated ifp */
int ifam_metric; /* value of ifa_metric */
};
/*
* Message format announcing the arrival or departure of a network interface.
*/
struct if_announcemsghdr50 {
u_short ifan_msglen; /* to skip over non-understood messages */
u_char ifan_version; /* future binary compatibility */
u_char ifan_type; /* message type */
u_short ifan_index; /* index for associated ifp */
char ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */
u_short ifan_what; /* what type of announcement */
};
#endif /* _COMPAT_NET_IF_H_ */

98
sys/compat/net/route.h Normal file
View File

@ -0,0 +1,98 @@
/* $NetBSD: route.h,v 1.1 2011/02/01 01:39:20 matt Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)route.h 8.5 (Berkeley) 2/8/95
*/
#ifndef _COMPAT_NET_ROUTE_H_
#define _COMPAT_NET_ROUTE_H_
#include <sys/queue.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <net/if.h>
#if !(defined(_KERNEL) || defined(_STANDALONE))
#include <stdbool.h>
#endif
/*
* These numbers are used by reliable protocols for determining
* retransmission behavior and are included in the routing structure.
*/
struct rt_metrics50 {
u_long rmx_locks; /* Kernel must leave these values alone */
u_long rmx_mtu; /* MTU for this path */
u_long rmx_hopcount; /* max hops expected */
u_long rmx_expire; /* lifetime for route, e.g. redirect */
u_long rmx_recvpipe; /* inbound delay-bandwidth product */
u_long rmx_sendpipe; /* outbound delay-bandwidth product */
u_long rmx_ssthresh; /* outbound gateway buffer limit */
u_long rmx_rtt; /* estimated round trip time */
u_long rmx_rttvar; /* estimated rtt variance */
u_long rmx_pksent; /* packets sent using this route */
};
/*
* Structures for routing messages.
*/
struct rt_msghdr50 {
u_short rtm_msglen; /* to skip over non-understood messages */
u_char rtm_version; /* future binary compatibility */
u_char rtm_type; /* message type */
u_short rtm_index; /* index for associated ifp */
int rtm_flags; /* flags, incl. kern & message, e.g. DONE */
int rtm_addrs; /* bitmask identifying sockaddrs in msg */
pid_t rtm_pid; /* identify sender */
int rtm_seq; /* for sender to identify action */
int rtm_errno; /* why failed */
int rtm_use; /* from rtentry */
u_long rtm_inits; /* which metrics we are initializing */
struct rt_metrics50 rtm_rmx; /* metrics themselves */
};
#ifdef _KERNEL
extern struct route_info compat_50_route_info;
void compat_50_route_enqueue(struct mbuf *, int);
void compat_50_rt_ifannouncemsg(struct ifnet *, int);
void compat_50_rt_ieee80211msg(struct ifnet *, int, void *, size_t);
void compat_50_rt_ifmsg(struct ifnet *);
void compat_50_rt_missmsg(int, const struct rt_addrinfo *, int, int);
struct mbuf *
compat_50_rt_msg1(int, struct rt_addrinfo *, void *, int);
void compat_50_rt_newaddrmsg(int, struct ifaddr *, int, struct rtentry *);
#endif
#define RTM_OVERSION 3 /* Up the ante and ignore older versions */
#define RT_OROUNDUP(a) RT_ROUNDUP2((a), sizeof(long))
#define RT_OADVANCE(x, n) (x += RT_OROUNDUP((n)->sa_len))
#endif /* !_COMPAT_NET_ROUTE_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: uipc_socket.c,v 1.202 2011/01/17 07:13:32 uebayasi Exp $ */
/* $NetBSD: uipc_socket.c,v 1.203 2011/02/01 01:39:20 matt Exp $ */
/*-
* Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@ -63,7 +63,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.202 2011/01/17 07:13:32 uebayasi Exp $");
__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.203 2011/02/01 01:39:20 matt Exp $");
#include "opt_compat_netbsd.h"
#include "opt_sock_counters.h"
@ -463,9 +463,10 @@ socket_listener_cb(kauth_cred_t cred, kauth_action_t action, void *cookie,
case KAUTH_REQ_NETWORK_SOCKET_OPEN:
/* We allow "raw" routing/bluetooth sockets to anyone. */
if ((u_long)arg1 == PF_ROUTE || (u_long)arg1 == PF_BLUETOOTH)
if ((u_long)arg1 == PF_ROUTE || (u_long)arg1 == PF_OROUTE
|| (u_long)arg1 == PF_BLUETOOTH) {
result = KAUTH_RESULT_ALLOW;
else {
} else {
/* Privileged, let secmodel handle this. */
if ((u_long)arg2 == SOCK_RAW)
break;

View File

@ -1,4 +1,4 @@
/* $NetBSD: if.h,v 1.149 2011/01/18 20:33:45 rmind Exp $ */
/* $NetBSD: if.h,v 1.150 2011/02/01 01:39:20 matt Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@ -471,17 +471,25 @@ struct ifaddr {
#define IFA_ROUTE RTF_UP /* (0x01) route installed */
/*
* Message format for use in obtaining information about interfaces
* from sysctl and the routing socket.
* Message format for use in obtaining information about interfaces from
* sysctl and the routing socket. We need to force 64-bit alignment if we
* aren't using compatiblity definitons.
*/
#if !defined(_KERNEL) || !defined(COMPAT_RTSOCK)
#define __align64 __aligned(sizeof(uint64_t))
#else
#define __align64
#endif
struct if_msghdr {
u_short ifm_msglen; /* to skip over non-understood messages */
u_short ifm_msglen __align64;
/* to skip over non-understood messages */
u_char ifm_version; /* future binary compatibility */
u_char ifm_type; /* message type */
int ifm_addrs; /* like rtm_addrs */
int ifm_flags; /* value of if_flags */
u_short ifm_index; /* index for associated ifp */
struct if_data ifm_data;/* statistics and other data about if */
struct if_data ifm_data __align64;
/* statistics and other data about if */
};
/*
@ -489,20 +497,22 @@ struct if_msghdr {
* from sysctl and the routing socket.
*/
struct ifa_msghdr {
u_short ifam_msglen; /* to skip over non-understood messages */
u_short ifam_msglen __align64;
/* to skip over non-understood messages */
u_char ifam_version; /* future binary compatibility */
u_char ifam_type; /* message type */
int ifam_addrs; /* like rtm_addrs */
int ifam_flags; /* value of ifa_flags */
u_short ifam_index; /* index for associated ifp */
int ifam_metric; /* value of ifa_metric */
u_short ifam_index; /* index for associated ifp */
};
/*
* Message format announcing the arrival or departure of a network interface.
*/
struct if_announcemsghdr {
u_short ifan_msglen; /* to skip over non-understood messages */
u_short ifan_msglen __align64;
/* to skip over non-understood messages */
u_char ifan_version; /* future binary compatibility */
u_char ifan_type; /* message type */
u_short ifan_index; /* index for associated ifp */
@ -513,6 +523,8 @@ struct if_announcemsghdr {
#define IFAN_ARRIVAL 0 /* interface arrival */
#define IFAN_DEPARTURE 1 /* interface departure */
#undef __align64
/*
* Interface request structure used for socket
* ioctl's. All interface ioctl's must have parameter

View File

@ -1,4 +1,4 @@
/* $NetBSD: route.c,v 1.123 2010/06/26 14:24:28 kefren Exp $ */
/* $NetBSD: route.c,v 1.124 2011/02/01 01:39:20 matt 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.123 2010/06/26 14:24:28 kefren Exp $");
__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.124 2011/02/01 01:39:20 matt Exp $");
#include <sys/param.h>
#include <sys/sysctl.h>
@ -124,7 +124,6 @@ __KERNEL_RCSID(0, "$NetBSD: route.c,v 1.123 2010/06/26 14:24:28 kefren Exp $");
#define rtcache_debug() 0
#endif /* RTFLUSH_DEBUG */
struct route_cb route_cb;
struct rtstat rtstat;
struct radix_node_head *rt_tables[AF_MAX+1];
@ -283,7 +282,7 @@ route_listener_cb(kauth_cred_t cred, kauth_action_t action, void *cookie,
}
void
route_init(void)
rt_init(void)
{
#ifdef RTFLUSH_DEBUG
@ -295,7 +294,6 @@ route_init(void)
pool_init(&rttimer_pool, sizeof(struct rttimer), 0, 0, 0, "rttmrpl",
NULL, IPL_SOFTNET);
rt_init();
rn_init(); /* initialize all zeroes, all ones, mask table */
rtable_init((void **)rt_tables);

View File

@ -1,4 +1,4 @@
/* $NetBSD: route.h,v 1.77 2011/01/26 00:58:36 dyoung Exp $ */
/* $NetBSD: route.h,v 1.78 2011/02/01 01:39:20 matt Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -67,27 +67,14 @@ struct route {
* retransmission behavior and are included in the routing structure.
*/
struct rt_metrics {
u_long rmx_locks; /* Kernel must leave these values alone */
u_long rmx_mtu; /* MTU for this path */
u_long rmx_hopcount; /* max hops expected */
u_long rmx_expire; /* lifetime for route, e.g. redirect */
u_long rmx_recvpipe; /* inbound delay-bandwidth product */
u_long rmx_sendpipe; /* outbound delay-bandwidth product */
u_long rmx_ssthresh; /* outbound gateway buffer limit */
u_long rmx_rtt; /* estimated round trip time */
u_long rmx_rttvar; /* estimated rtt variance */
u_long rmx_pksent; /* packets sent using this route */
};
struct nrt_metrics {
u_long rmx_locks; /* Kernel must leave these values alone */
u_long rmx_mtu; /* MTU for this path */
u_long rmx_hopcount; /* max hops expected */
u_long rmx_recvpipe; /* inbound delay-bandwidth product */
u_long rmx_sendpipe; /* outbound delay-bandwidth product */
u_long rmx_ssthresh; /* outbound gateway buffer limit */
u_long rmx_rtt; /* estimated round trip time */
u_long rmx_rttvar; /* estimated rtt variance */
uint64_t rmx_locks; /* Kernel must leave these values alone */
uint64_t rmx_mtu; /* MTU for this path */
uint64_t rmx_hopcount; /* max hops expected */
uint64_t rmx_recvpipe; /* inbound delay-bandwidth product */
uint64_t rmx_sendpipe; /* outbound delay-bandwidth product */
uint64_t rmx_ssthresh; /* outbound gateway buffer limit */
uint64_t rmx_rtt; /* estimated round trip time */
uint64_t rmx_rttvar; /* estimated rtt variance */
time_t rmx_expire; /* lifetime for route, e.g. redirect */
time_t rmx_pksent; /* packets sent using this route */
};
@ -117,12 +104,12 @@ struct rtentry {
struct sockaddr *rt_gateway; /* value */
int rt_flags; /* up/down?, host/net */
int rt_refcnt; /* # held references */
u_long rt_use; /* raw # packets forwarded */
uint64_t rt_use; /* raw # packets forwarded */
struct ifnet *rt_ifp; /* the answer: interface to use */
struct ifaddr *rt_ifa; /* the answer: interface to use */
uint32_t rt_ifa_seqno;
void * rt_llinfo; /* pointer to link level info cache */
struct nrt_metrics rt_rmx; /* metrics used by rx'ing protocols */
struct rt_metrics rt_rmx; /* metrics used by rx'ing protocols */
struct rtentry *rt_gwroute; /* implied entry for gatewayed routes */
LIST_HEAD(, rttimer) rt_timer; /* queue of timeouts for misc funcs */
struct rtentry *rt_parent; /* parent of cloned route */
@ -179,11 +166,26 @@ struct rtstat {
uint64_t rts_unreach; /* lookups which failed */
uint64_t rts_wildcard; /* lookups satisfied by a wildcard */
};
/*
* Structures for routing messages.
* Structures for routing messages. By forcing the first member to be aligned
* at a 64-bit boundary, we also force the size to be a multiple of 64-bits.
*/
#if !defined(_KERNEL) || !defined(COMPAT_RTSOCK)
/*
* If we aren't being compiled for backwards compatiblity, enforce 64-bit
* alignment so any routing message is the same regardless if the kernel
* is an ILP32 or LP64 kernel.
*/
#define __align64 __aligned(sizeof(uint64_t))
#else
#define __align64
#endif
struct rt_msghdr {
u_short rtm_msglen; /* to skip over non-understood messages */
u_short rtm_msglen __align64;
/* to skip over non-understood messages */
u_char rtm_version; /* future binary compatibility */
u_char rtm_type; /* message type */
u_short rtm_index; /* index for associated ifp */
@ -193,11 +195,14 @@ struct rt_msghdr {
int rtm_seq; /* for sender to identify action */
int rtm_errno; /* why failed */
int rtm_use; /* from rtentry */
u_long rtm_inits; /* which metrics we are initializing */
struct rt_metrics rtm_rmx; /* metrics themselves */
int rtm_inits; /* which metrics we are initializing */
struct rt_metrics rtm_rmx __align64;
/* metrics themselves */
};
#define RTM_VERSION 3 /* Up the ante and ignore older versions */
#undef __align64
#define RTM_VERSION 4 /* Up the ante and ignore older versions */
#define RTM_ADD 0x1 /* Add Route */
#define RTM_DELETE 0x2 /* Delete Route */
@ -213,7 +218,7 @@ struct rt_msghdr {
#define RTM_NEWADDR 0xc /* address being added to iface */
#define RTM_DELADDR 0xd /* address being removed from iface */
#define RTM_OOIFINFO 0xe /* Old (pre-1.5) RTM_IFINFO message */
#define RTM_OIFINFO 0xf /* Old (pre-6.0) RTM_IFINFO message */
#define RTM_OIFINFO 0xf /* Old (pre-64bit time) RTM_IFINFO message */
#define RTM_IFANNOUNCE 0x10 /* iface arrival/departure */
#define RTM_IEEE80211 0x11 /* IEEE80211 wireless event */
#define RTM_SETGATE 0x12 /* set prototype gateway for clones
@ -261,9 +266,9 @@ struct rt_msghdr {
#define RTAX_TAG 8 /* route tag */
#define RTAX_MAX 9 /* 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))
#define RT_ROUNDUP2(a, n) ((a) > 0 ? (1 + (((a) - 1) | ((n) - 1))) : (n))
#define RT_ROUNDUP(a) RT_ROUNDUP2((a), sizeof(uint64_t))
#define RT_ADVANCE(x, n) (x += RT_ROUNDUP((n)->sa_len))
struct rt_addrinfo {
int rti_addrs;
@ -271,14 +276,11 @@ struct rt_addrinfo {
int rti_flags;
struct ifaddr *rti_ifa;
struct ifnet *rti_ifp;
struct rt_msghdr *rti_rtm;
};
struct route_cb {
int ip_count;
int ip6_count;
int ipx_count;
int ns_count;
int iso_count;
int mpls_count;
int any_count;
@ -309,10 +311,6 @@ struct rttimer_queue {
#ifdef _KERNEL
extern struct sockaddr route_dst;
extern struct sockaddr route_src;
extern struct sockproto route_proto;
struct rt_walkarg {
int w_op;
int w_arg;
@ -334,28 +332,37 @@ struct rtwalk {
int (*rw_f)(struct rtentry *, void *);
void *rw_v;
};
extern struct route_cb route_cb;
/*
* Global data specific to the routing socket.
*/
struct route_info {
struct sockaddr ri_dst;
struct sockaddr ri_src;
struct route_cb ri_cb;
int ri_maxqlen;
struct ifqueue ri_intrq;
void *ri_sih;
};
extern struct route_info route_info;
extern struct rtstat rtstat;
extern struct radix_node_head *rt_tables[AF_MAX+1];
struct socket;
struct dom_rtlist;
void route_init(void);
int route_output(struct mbuf *, ...);
int route_usrreq(struct socket *,
int, struct mbuf *, struct mbuf *, struct mbuf *, struct lwp *);
void rt_init(void);
void rt_ifannouncemsg(struct ifnet *, int);
void rt_ieee80211msg(struct ifnet *, int, void *, size_t);
void rt_ifmsg(struct ifnet *);
void rt_maskedcopy(const struct sockaddr *,
struct sockaddr *, const struct sockaddr *);
void rt_missmsg(int, struct rt_addrinfo *, int, int);
void rt_missmsg(int, const struct rt_addrinfo *, int, int);
struct mbuf *rt_msg1(int, struct rt_addrinfo *, void *, int);
void rt_newaddrmsg(int, struct ifaddr *, int, struct rtentry *);
void rt_maskedcopy(const struct sockaddr *,
struct sockaddr *, const struct sockaddr *);
int rt_setgate(struct rtentry *, const struct sockaddr *);
void rt_setmetrics(u_long, const struct rt_metrics *, struct nrt_metrics *);
int rt_timer_add(struct rtentry *,
void(*)(struct rtentry *, struct rttimer *),
struct rttimer_queue *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtsock.c,v 1.132 2010/12/25 20:37:44 christos Exp $ */
/* $NetBSD: rtsock.c,v 1.133 2011/02/01 01:39:20 matt Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -61,11 +61,11 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.132 2010/12/25 20:37:44 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.133 2011/02/01 01:39:20 matt Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
#include "opt_mpls.h"
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
#endif
@ -92,23 +92,64 @@ __KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.132 2010/12/25 20:37:44 christos Exp $"
#if defined(COMPAT_14) || defined(COMPAT_50)
#include <compat/net/if.h>
#include <compat/net/route.h>
#endif
#ifdef COMPAT_RTSOCK
#define RTM_XVERSION RTM_OVERSION
#define RT_XADVANCE(a,b) RT_OADVANCE(a,b)
#define RT_XROUNDUP(n) RT_OROUNDUP(n)
#define PF_XROUTE PF_OROUTE
#define rt_xmsghdr rt_msghdr50
#define if_xmsghdr if_msghdr /* if_msghdr50 is for RTM_OIFINFO */
#define ifa_xmsghdr ifa_msghdr50
#define if_xannouncemsghdr if_announcemsghdr50
#define COMPATNAME(x) compat_50_ ## x
#define DOMAINNAME "oroute"
CTASSERT(sizeof(struct ifa_xmsghdr) == 20);
DOMAIN_DEFINE(compat_50_routedomain); /* forward declare and add to link set */
#else
#define RTM_XVERSION RTM_VERSION
#define RT_XADVANCE(a,b) RT_ADVANCE(a,b)
#define RT_XROUNDUP(n) RT_ROUNDUP(n)
#define PF_XROUTE PF_ROUTE
#define rt_xmsghdr rt_msghdr
#define if_xmsghdr if_msghdr
#define ifa_xmsghdr ifa_msghdr
#define if_xannouncemsghdr if_announcemsghdr
#define COMPATNAME(x) x
#define DOMAINNAME "route"
CTASSERT(sizeof(struct ifa_xmsghdr) == 24);
#ifdef COMPAT_50
#define COMPATCALL(name, args) compat_50_ ## name args
#endif
DOMAIN_DEFINE(routedomain); /* forward declare and add to link set */
#undef COMPAT_50
#undef COMPAT_14
#endif
#ifndef COMPATCALL
#define COMPATCALL(name, args) do { } while (/*CONSTCOND*/ 0)
#endif
#include <machine/stdarg.h>
DOMAIN_DEFINE(routedomain); /* forward declare and add to link set */
struct route_info COMPATNAME(route_info) = {
.ri_dst = { .sa_len = 2, .sa_family = PF_XROUTE, },
.ri_src = { .sa_len = 2, .sa_family = PF_XROUTE, },
.ri_maxqlen = IFQ_MAXLEN,
};
struct sockaddr route_dst = { .sa_len = 2, .sa_family = PF_ROUTE, };
struct sockaddr route_src = { .sa_len = 2, .sa_family = PF_ROUTE, };
int route_maxqlen = IFQ_MAXLEN;
static struct ifqueue route_intrq;
static void *route_sih;
static void COMPATNAME(route_init)(void);
static int COMPATNAME(route_output)(struct mbuf *, ...);
static int COMPATNAME(route_usrreq)(struct socket *,
int, struct mbuf *, struct mbuf *, struct mbuf *, struct lwp *);
static int rt_msg2(int, struct rt_addrinfo *, void *, struct rt_walkarg *, int *);
static int rt_xaddrs(u_char, const char *, const char *, struct rt_addrinfo *);
static struct mbuf *rt_makeifannouncemsg(struct ifnet *, int, int,
struct rt_addrinfo *);
static void rt_setmetrics(int, const struct rt_xmsghdr *, struct rtentry *);
static void rtm_setmetrics(const struct rtentry *, struct rt_xmsghdr *);
static void sysctl_net_route_setup(struct sysctllog **);
static int sysctl_dumpentry(struct rtentry *, void *);
static int sysctl_iflist(int, struct rt_walkarg *, int);
@ -118,49 +159,31 @@ static void rt_adjustcount(int, int);
static void
rt_adjustcount(int af, int cnt)
{
route_cb.any_count += cnt;
struct route_cb * const cb = &COMPATNAME(route_info).ri_cb;
cb->any_count += cnt;
switch (af) {
case AF_INET:
route_cb.ip_count += cnt;
cb->ip_count += cnt;
return;
#ifdef INET6
case AF_INET6:
route_cb.ip6_count += cnt;
cb->ip6_count += cnt;
return;
#endif
case AF_IPX:
route_cb.ipx_count += cnt;
return;
case AF_ISO:
route_cb.iso_count += cnt;
cb->iso_count += cnt;
return;
case AF_MPLS:
route_cb.mpls_count += cnt;
return;
case AF_NS:
route_cb.ns_count += cnt;
cb->mpls_count += cnt;
return;
}
}
static void
cvtmetrics(struct rt_metrics *ortm, const struct nrt_metrics *rtm)
{
ortm->rmx_locks = rtm->rmx_locks;
ortm->rmx_mtu = rtm->rmx_mtu;
ortm->rmx_hopcount = rtm->rmx_hopcount;
ortm->rmx_expire = rtm->rmx_expire;
ortm->rmx_recvpipe = rtm->rmx_recvpipe;
ortm->rmx_sendpipe = rtm->rmx_sendpipe;
ortm->rmx_ssthresh = rtm->rmx_ssthresh;
ortm->rmx_rtt = rtm->rmx_rtt;
ortm->rmx_rttvar = rtm->rmx_rttvar;
ortm->rmx_pksent = rtm->rmx_pksent;
}
/*ARGSUSED*/
int
route_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
COMPATNAME(route_usrreq)(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
struct mbuf *control, struct lwp *l)
{
int error = 0;
@ -197,8 +220,8 @@ route_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
return error;
}
rt_adjustcount(rp->rcb_proto.sp_protocol, 1);
rp->rcb_laddr = &route_src;
rp->rcb_faddr = &route_dst;
rp->rcb_laddr = &COMPATNAME(route_info).ri_src;
rp->rcb_faddr = &COMPATNAME(route_info).ri_dst;
soisconnected(so);
so->so_options |= SO_USELOOPBACK;
}
@ -221,11 +244,11 @@ intern_netmask(const struct sockaddr *mask)
/*ARGSUSED*/
int
route_output(struct mbuf *m, ...)
COMPATNAME(route_output)(struct mbuf *m, ...)
{
struct sockproto proto = { .sp_family = PF_ROUTE, };
struct rt_msghdr *rtm = NULL;
struct rt_msghdr *old_rtm = NULL;
struct sockproto proto = { .sp_family = PF_XROUTE, };
struct rt_xmsghdr *rtm = NULL;
struct rt_xmsghdr *old_rtm = NULL;
struct rtentry *rt = NULL;
struct rtentry *saved_nrt = NULL;
struct rt_addrinfo info;
@ -245,20 +268,20 @@ route_output(struct mbuf *m, ...)
(m = m_pullup(m, sizeof(int32_t))) == NULL))
return ENOBUFS;
if ((m->m_flags & M_PKTHDR) == 0)
panic("route_output");
panic("%s", __func__);
len = m->m_pkthdr.len;
if (len < sizeof(*rtm) ||
len != mtod(m, struct rt_msghdr *)->rtm_msglen) {
len != mtod(m, struct rt_xmsghdr *)->rtm_msglen) {
info.rti_info[RTAX_DST] = NULL;
senderr(EINVAL);
}
R_Malloc(rtm, struct rt_msghdr *, len);
R_Malloc(rtm, struct rt_xmsghdr *, len);
if (rtm == NULL) {
info.rti_info[RTAX_DST] = NULL;
senderr(ENOBUFS);
}
m_copydata(m, 0, len, rtm);
if (rtm->rtm_version != RTM_VERSION) {
if (rtm->rtm_version != RTM_XVERSION) {
info.rti_info[RTAX_DST] = NULL;
senderr(EPROTONOSUPPORT);
}
@ -266,8 +289,9 @@ route_output(struct mbuf *m, ...)
memset(&info, 0, sizeof(info));
info.rti_addrs = rtm->rtm_addrs;
if (rt_xaddrs(rtm->rtm_type, (const char *)(rtm + 1), len + (char *)rtm,
&info))
&info)) {
senderr(EINVAL);
}
info.rti_flags = rtm->rtm_flags;
#ifdef RTSOCK_DEBUG
if (info.rti_info[RTAX_DST]->sa_family == AF_INET) {
@ -277,11 +301,13 @@ route_output(struct mbuf *m, ...)
}
#endif /* RTSOCK_DEBUG */
if (info.rti_info[RTAX_DST] == NULL ||
(info.rti_info[RTAX_DST]->sa_family >= AF_MAX))
(info.rti_info[RTAX_DST]->sa_family >= AF_MAX)) {
senderr(EINVAL);
}
if (info.rti_info[RTAX_GATEWAY] != NULL &&
(info.rti_info[RTAX_GATEWAY]->sa_family >= AF_MAX))
(info.rti_info[RTAX_GATEWAY]->sa_family >= AF_MAX)) {
senderr(EINVAL);
}
/*
* Verify that the caller has the appropriate privilege; RTM_GET
@ -294,12 +320,12 @@ route_output(struct mbuf *m, ...)
switch (rtm->rtm_type) {
case RTM_ADD:
if (info.rti_info[RTAX_GATEWAY] == NULL)
if (info.rti_info[RTAX_GATEWAY] == NULL) {
senderr(EINVAL);
}
error = rtrequest1(rtm->rtm_type, &info, &saved_nrt);
if (error == 0 && saved_nrt) {
rt_setmetrics(rtm->rtm_inits,
&rtm->rtm_rmx, &saved_nrt->rt_rmx);
rt_setmetrics(rtm->rtm_inits, rtm, saved_nrt);
saved_nrt->rt_refcnt--;
}
break;
@ -388,14 +414,14 @@ route_output(struct mbuf *m, ...)
(void)rt_msg2(rtm->rtm_type, &info, NULL, NULL, &len);
if (len > rtm->rtm_msglen) {
old_rtm = rtm;
R_Malloc(rtm, struct rt_msghdr *, len);
R_Malloc(rtm, struct rt_xmsghdr *, len);
if (rtm == NULL)
senderr(ENOBUFS);
(void)memcpy(rtm, old_rtm, old_rtm->rtm_msglen);
}
(void)rt_msg2(rtm->rtm_type, &info, rtm, NULL, 0);
rtm->rtm_flags = rt->rt_flags;
cvtmetrics(&rtm->rtm_rmx, &rt->rt_rmx);
rtm_setmetrics(rt, rtm);
rtm->rtm_addrs = info.rti_addrs;
break;
@ -446,8 +472,7 @@ route_output(struct mbuf *m, ...)
}
if (ifp && rt->rt_ifp != ifp)
rt->rt_ifp = ifp;
rt_setmetrics(rtm->rtm_inits, &rtm->rtm_rmx,
&rt->rt_rmx);
rt_setmetrics(rtm->rtm_inits, rtm, rt);
if (rt->rt_ifa && rt->rt_ifa->ifa_rtrequest)
rt->rt_ifa->ifa_rtrequest(RTM_ADD, rt, &info);
/*FALLTHROUGH*/
@ -486,7 +511,7 @@ flush:
* Check to see if we don't want our own messages.
*/
if ((so->so_options & SO_USELOOPBACK) == 0) {
if (route_cb.any_count <= 1) {
if (COMPATNAME(route_info).ri_cb.any_count <= 1) {
if (rtm)
Free(rtm);
m_freem(m);
@ -509,17 +534,18 @@ flush:
if (family)
proto.sp_protocol = family;
if (m)
raw_input(m, &proto, &route_src, &route_dst);
raw_input(m, &proto, &COMPATNAME(route_info).ri_src,
&COMPATNAME(route_info).ri_dst);
if (rp)
rp->rcb_proto.sp_family = PF_ROUTE;
rp->rcb_proto.sp_family = PF_XROUTE;
}
return error;
}
void
rt_setmetrics(u_long which, const struct rt_metrics *in, struct nrt_metrics *out)
static void
rt_setmetrics(int which, const struct rt_xmsghdr *in, struct rtentry *out)
{
#define metric(f, e) if (which & (f)) out->e = in->e;
#define metric(f, e) if (which & (f)) out->rt_rmx.e = in->rtm_rmx.e;
metric(RTV_RPIPE, rmx_recvpipe);
metric(RTV_SPIPE, rmx_sendpipe);
metric(RTV_SSTHRESH, rmx_ssthresh);
@ -527,11 +553,25 @@ rt_setmetrics(u_long which, const struct rt_metrics *in, struct nrt_metrics *out
metric(RTV_RTTVAR, rmx_rttvar);
metric(RTV_HOPCOUNT, rmx_hopcount);
metric(RTV_MTU, rmx_mtu);
/* XXX time_t: Will not work after February 2145 (u_long time) */
metric(RTV_EXPIRE, rmx_expire);
#undef metric
}
static void
rtm_setmetrics(const struct rtentry *in, struct rt_xmsghdr *out)
{
#define metric(e) out->rtm_rmx.e = in->rt_rmx.e;
metric(rmx_recvpipe);
metric(rmx_sendpipe);
metric(rmx_ssthresh);
metric(rmx_rtt);
metric(rmx_rttvar);
metric(rmx_hopcount);
metric(rmx_mtu);
metric(rmx_expire);
#undef metric
}
static int
rt_xaddrs(u_char rtmtype, const char *cp, const char *cplim,
struct rt_addrinfo *rtinfo)
@ -543,7 +583,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;
RT_ADVANCE(cp, sa);
RT_XADVANCE(cp, sa);
}
/*
@ -559,7 +599,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 - RT_ROUNDUP(sa->sa_len) + sa->sa_len == cplim)
cp - RT_XROUNDUP(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
@ -575,11 +615,18 @@ rt_xaddrs(u_char rtmtype, const char *cp, const char *cplim,
static int
rt_getlen(int type)
{
#ifndef COMPAT_RTSOCK
CTASSERT(__alignof(struct ifa_msghdr) >= sizeof(uint64_t));
CTASSERT(__alignof(struct if_msghdr) >= sizeof(uint64_t));
CTASSERT(__alignof(struct if_announcemsghdr) >= sizeof(uint64_t));
CTASSERT(__alignof(struct rt_msghdr) >= sizeof(uint64_t));
#endif
switch (type) {
case RTM_DELADDR:
case RTM_NEWADDR:
case RTM_CHGADDR:
return sizeof(struct ifa_msghdr);
return sizeof(struct ifa_xmsghdr);
case RTM_OOIFINFO:
#ifdef COMPAT_14
@ -601,22 +648,22 @@ rt_getlen(int type)
#endif
case RTM_IFINFO:
return sizeof(struct if_msghdr);
return sizeof(struct if_xmsghdr);
case RTM_IFANNOUNCE:
case RTM_IEEE80211:
return sizeof(struct if_announcemsghdr);
return sizeof(struct if_xannouncemsghdr);
default:
return sizeof(struct rt_msghdr);
return sizeof(struct rt_xmsghdr);
}
}
struct mbuf *
rt_msg1(int type, struct rt_addrinfo *rtinfo, void *data, int datalen)
COMPATNAME(rt_msg1)(int type, struct rt_addrinfo *rtinfo, void *data, int datalen)
{
struct rt_msghdr *rtm;
struct rt_xmsghdr *rtm;
struct mbuf *m;
int i;
const struct sockaddr *sa;
@ -625,12 +672,12 @@ rt_msg1(int type, struct rt_addrinfo *rtinfo, void *data, int datalen)
m = m_gethdr(M_DONTWAIT, MT_DATA);
if (m == NULL)
return m;
MCLAIM(m, &routedomain.dom_mowner);
MCLAIM(m, &COMPATNAME(routedomain).dom_mowner);
if ((len = rt_getlen(type)) == -1)
goto out;
if (len > MHLEN + MLEN)
panic("rt_msg1: message too long");
panic("%s: message too long", __func__);
else if (len > MHLEN) {
m->m_next = m_get(M_DONTWAIT, MT_DATA);
if (m->m_next == NULL)
@ -646,19 +693,23 @@ rt_msg1(int type, struct rt_addrinfo *rtinfo, void *data, int datalen)
m_copyback(m, 0, datalen, data);
if (len > datalen)
(void)memset(mtod(m, char *) + datalen, 0, len - datalen);
rtm = mtod(m, struct rt_msghdr *);
rtm = mtod(m, struct rt_xmsghdr *);
for (i = 0; i < RTAX_MAX; i++) {
if ((sa = rtinfo->rti_info[i]) == NULL)
continue;
rtinfo->rti_addrs |= (1 << i);
dlen = RT_ROUNDUP(sa->sa_len);
m_copyback(m, len, dlen, sa);
dlen = RT_XROUNDUP(sa->sa_len);
m_copyback(m, len, sa->sa_len, sa);
if (dlen != sa->sa_len) {
m_copyback(m, len + sa->sa_len,
dlen - sa->sa_len, "\0\0\0\0\0\0");
}
len += dlen;
}
if (m->m_pkthdr.len != len)
goto out;
rtm->rtm_msglen = len;
rtm->rtm_version = RTM_VERSION;
rtm->rtm_version = RTM_XVERSION;
rtm->rtm_type = type;
return m;
out:
@ -700,7 +751,7 @@ again:
if ((sa = rtinfo->rti_info[i]) == NULL)
continue;
rtinfo->rti_addrs |= (1 << i);
dlen = RT_ROUNDUP(sa->sa_len);
dlen = RT_XROUNDUP(sa->sa_len);
if (cp) {
(void)memcpy(cp, sa, (size_t)dlen);
cp += dlen;
@ -732,9 +783,9 @@ again:
}
}
if (cp) {
struct rt_msghdr *rtm = (struct rt_msghdr *)cp0;
struct rt_xmsghdr *rtm = (struct rt_xmsghdr *)cp0;
rtm->rtm_version = RTM_VERSION;
rtm->rtm_version = RTM_XVERSION;
rtm->rtm_type = type;
rtm->rtm_msglen = len;
}
@ -750,22 +801,25 @@ again:
* destination.
*/
void
rt_missmsg(int type, struct rt_addrinfo *rtinfo, int flags, int error)
COMPATNAME(rt_missmsg)(int type, const struct rt_addrinfo *rtinfo, int flags,
int error)
{
struct rt_msghdr rtm;
struct rt_xmsghdr rtm;
struct mbuf *m;
const struct sockaddr *sa = rtinfo->rti_info[RTAX_DST];
struct rt_addrinfo info = *rtinfo;
if (route_cb.any_count == 0)
COMPATCALL(rt_missmsg, (type, rtinfo, flags, error));
if (COMPATNAME(route_info).ri_cb.any_count == 0)
return;
memset(&rtm, 0, sizeof(rtm));
rtm.rtm_flags = RTF_DONE | flags;
rtm.rtm_errno = error;
m = rt_msg1(type, rtinfo, &rtm, sizeof(rtm));
m = COMPATNAME(rt_msg1)(type, &info, &rtm, sizeof(rtm));
if (m == NULL)
return;
mtod(m, struct rt_msghdr *)->rtm_addrs = rtinfo->rti_addrs;
route_enqueue(m, sa ? sa->sa_family : 0);
mtod(m, struct rt_xmsghdr *)->rtm_addrs = info.rti_addrs;
COMPATNAME(route_enqueue)(m, sa ? sa->sa_family : 0);
}
/*
@ -773,13 +827,14 @@ rt_missmsg(int type, struct rt_addrinfo *rtinfo, int flags, int error)
* socket indicating that the status of a network interface has changed.
*/
void
rt_ifmsg(struct ifnet *ifp)
COMPATNAME(rt_ifmsg)(struct ifnet *ifp)
{
struct if_msghdr ifm;
struct if_xmsghdr ifm;
struct mbuf *m;
struct rt_addrinfo info;
if (route_cb.any_count == 0)
COMPATCALL(rt_ifmsg, (ifp));
if (COMPATNAME(route_info).ri_cb.any_count == 0)
return;
(void)memset(&info, 0, sizeof(info));
(void)memset(&ifm, 0, sizeof(ifm));
@ -787,15 +842,15 @@ rt_ifmsg(struct ifnet *ifp)
ifm.ifm_flags = ifp->if_flags;
ifm.ifm_data = ifp->if_data;
ifm.ifm_addrs = 0;
m = rt_msg1(RTM_IFINFO, &info, &ifm, sizeof(ifm));
m = COMPATNAME(rt_msg1)(RTM_IFINFO, &info, &ifm, sizeof(ifm));
if (m == NULL)
return;
route_enqueue(m, 0);
COMPATNAME(route_enqueue)(m, 0);
#ifdef COMPAT_14
compat_14_rt_ifmsg(ifp, &ifm);
compat_14_rt_oifmsg(ifp);
#endif
#ifdef COMPAT_50
compat_50_rt_ifmsg(ifp, &ifm);
compat_50_rt_oifmsg(ifp);
#endif
}
@ -809,7 +864,8 @@ rt_ifmsg(struct ifnet *ifp)
* copies of it.
*/
void
rt_newaddrmsg(int cmd, struct ifaddr *ifa, int error, struct rtentry *rt)
COMPATNAME(rt_newaddrmsg)(int cmd, struct ifaddr *ifa, int error,
struct rtentry *rt)
{
#define cmdpass(__cmd, __pass) (((__cmd) << 2) | (__pass))
struct rt_addrinfo info;
@ -817,11 +873,12 @@ rt_newaddrmsg(int cmd, struct ifaddr *ifa, int error, struct rtentry *rt)
int pass;
struct mbuf *m;
struct ifnet *ifp = ifa->ifa_ifp;
struct rt_msghdr rtm;
struct ifa_msghdr ifam;
struct rt_xmsghdr rtm;
struct ifa_xmsghdr ifam;
int ncmd;
if (route_cb.any_count == 0)
COMPATCALL(rt_newaddrmsg, (cmd, ifa, error, rt));
if (COMPATNAME(route_info).ri_cb.any_count == 0)
return;
for (pass = 1; pass < 3; pass++) {
memset(&info, 0, sizeof(info));
@ -847,10 +904,10 @@ rt_newaddrmsg(int cmd, struct ifaddr *ifa, int error, struct rtentry *rt)
ifam.ifam_index = ifp->if_index;
ifam.ifam_metric = ifa->ifa_metric;
ifam.ifam_flags = ifa->ifa_flags;
m = rt_msg1(ncmd, &info, &ifam, sizeof(ifam));
m = COMPATNAME(rt_msg1)(ncmd, &info, &ifam, sizeof(ifam));
if (m == NULL)
continue;
mtod(m, struct ifa_msghdr *)->ifam_addrs =
mtod(m, struct ifa_xmsghdr *)->ifam_addrs =
info.rti_addrs;
break;
case cmdpass(RTM_ADD, 2):
@ -865,10 +922,10 @@ rt_newaddrmsg(int cmd, struct ifaddr *ifa, int error, struct rtentry *rt)
rtm.rtm_index = ifp->if_index;
rtm.rtm_flags |= rt->rt_flags;
rtm.rtm_errno = error;
m = rt_msg1(cmd, &info, &rtm, sizeof(rtm));
m = COMPATNAME(rt_msg1)(cmd, &info, &rtm, sizeof(rtm));
if (m == NULL)
continue;
mtod(m, struct rt_msghdr *)->rtm_addrs = info.rti_addrs;
mtod(m, struct rt_xmsghdr *)->rtm_addrs = info.rti_addrs;
break;
default:
continue;
@ -877,7 +934,7 @@ rt_newaddrmsg(int cmd, struct ifaddr *ifa, int error, struct rtentry *rt)
if (m == NULL)
panic("%s: called with wrong command", __func__);
#endif
route_enqueue(m, sa ? sa->sa_family : 0);
COMPATNAME(route_enqueue)(m, sa ? sa->sa_family : 0);
}
#undef cmdpass
}
@ -886,14 +943,14 @@ static struct mbuf *
rt_makeifannouncemsg(struct ifnet *ifp, int type, int what,
struct rt_addrinfo *info)
{
struct if_announcemsghdr ifan;
struct if_xannouncemsghdr ifan;
memset(info, 0, sizeof(*info));
memset(&ifan, 0, sizeof(ifan));
ifan.ifan_index = ifp->if_index;
strlcpy(ifan.ifan_name, ifp->if_xname, sizeof(ifan.ifan_name));
ifan.ifan_what = what;
return rt_msg1(type, info, &ifan, sizeof(ifan));
return COMPATNAME(rt_msg1)(type, info, &ifan, sizeof(ifan));
}
/*
@ -901,17 +958,18 @@ rt_makeifannouncemsg(struct ifnet *ifp, int type, int what,
* network interface arrival and departure.
*/
void
rt_ifannouncemsg(struct ifnet *ifp, int what)
COMPATNAME(rt_ifannouncemsg)(struct ifnet *ifp, int what)
{
struct mbuf *m;
struct rt_addrinfo info;
if (route_cb.any_count == 0)
COMPATCALL(rt_ifannouncemsg, (ifp, what));
if (COMPATNAME(route_info).ri_cb.any_count == 0)
return;
m = rt_makeifannouncemsg(ifp, RTM_IFANNOUNCE, what, &info);
if (m == NULL)
return;
route_enqueue(m, 0);
COMPATNAME(route_enqueue)(m, 0);
}
/*
@ -920,12 +978,14 @@ rt_ifannouncemsg(struct ifnet *ifp, int what)
* XXX we piggyback on the RTM_IFANNOUNCE msg format in a clumsy way.
*/
void
rt_ieee80211msg(struct ifnet *ifp, int what, void *data, size_t data_len)
COMPATNAME(rt_ieee80211msg)(struct ifnet *ifp, int what, void *data,
size_t data_len)
{
struct mbuf *m;
struct rt_addrinfo info;
if (route_cb.any_count == 0)
COMPATCALL(rt_ieee80211msg, (ifp, what, data, data_len));
if (COMPATNAME(route_info).ri_cb.any_count == 0)
return;
m = rt_makeifannouncemsg(ifp, RTM_IEEE80211, what, &info);
if (m == NULL)
@ -952,8 +1012,8 @@ rt_ieee80211msg(struct ifnet *ifp, int what, void *data, size_t data_len)
}
if (m->m_flags & M_PKTHDR)
m->m_pkthdr.len += data_len;
mtod(m, struct if_announcemsghdr *)->ifan_msglen += data_len;
route_enqueue(m, 0);
mtod(m, struct if_xannouncemsghdr *)->ifan_msglen += data_len;
COMPATNAME(route_enqueue)(m, 0);
}
/*
@ -987,11 +1047,11 @@ sysctl_dumpentry(struct rtentry *rt, void *v)
if ((error = rt_msg2(RTM_GET, &info, 0, w, &size)))
return error;
if (w->w_where && w->w_tmem && w->w_needed <= 0) {
struct rt_msghdr *rtm = (struct rt_msghdr *)w->w_tmem;
struct rt_xmsghdr *rtm = (struct rt_xmsghdr *)w->w_tmem;
rtm->rtm_flags = rt->rt_flags;
rtm->rtm_use = rt->rt_use;
cvtmetrics(&rtm->rtm_rmx, &rt->rt_rmx);
rtm_setmetrics(rt, rtm);
KASSERT(rt->rt_ifp != NULL);
rtm->rtm_index = rt->rt_ifp->if_index;
rtm->rtm_errno = rtm->rtm_pid = rtm->rtm_seq = 0;
@ -1042,9 +1102,9 @@ sysctl_iflist(int af, struct rt_walkarg *w, int type)
if (w->w_where && w->w_tmem && w->w_needed <= 0) {
switch (type) {
case NET_RT_IFLIST: {
struct if_msghdr *ifm;
struct if_xmsghdr *ifm;
ifm = (struct if_msghdr *)w->w_tmem;
ifm = (struct if_xmsghdr *)w->w_tmem;
ifm->ifm_index = ifp->if_index;
ifm->ifm_flags = ifp->if_flags;
ifm->ifm_data = ifp->if_data;
@ -1083,9 +1143,9 @@ sysctl_iflist(int af, struct rt_walkarg *w, int type)
if ((error = rt_msg2(RTM_NEWADDR, &info, 0, w, &len)))
return error;
if (w->w_where && w->w_tmem && w->w_needed <= 0) {
struct ifa_msghdr *ifam;
struct ifa_xmsghdr *ifam;
ifam = (struct ifa_msghdr *)w->w_tmem;
ifam = (struct ifa_xmsghdr *)w->w_tmem;
ifam->ifam_index = ifa->ifa_ifp->if_index;
ifam->ifam_flags = ifa->ifa_flags;
ifam->ifam_metric = ifa->ifa_metric;
@ -1157,9 +1217,9 @@ again:
error = sysctl_iflist(af, &w, w.w_op);
break;
#endif
case NET_RT_IFLIST:
error = sysctl_iflist(af, &w, w.w_op);
break;
}
splx(s);
@ -1184,22 +1244,23 @@ again:
* Routing message software interrupt routine
*/
static void
route_intr(void *cookie)
COMPATNAME(route_intr)(void *cookie)
{
struct sockproto proto = { .sp_family = PF_ROUTE, };
struct sockproto proto = { .sp_family = PF_XROUTE, };
struct route_info * const ri = &COMPATNAME(route_info);
struct mbuf *m;
int s;
mutex_enter(softnet_lock);
KERNEL_LOCK(1, NULL);
while (!IF_IS_EMPTY(&route_intrq)) {
while (!IF_IS_EMPTY(&ri->ri_intrq)) {
s = splnet();
IF_DEQUEUE(&route_intrq, m);
IF_DEQUEUE(&ri->ri_intrq, m);
splx(s);
if (m == NULL)
break;
proto.sp_protocol = M_GETCTX(m, uintptr_t);
raw_input(m, &proto, &route_src, &route_dst);
raw_input(m, &proto, &ri->ri_src, &ri->ri_dst);
}
KERNEL_UNLOCK_ONE(NULL);
mutex_exit(softnet_lock);
@ -1209,59 +1270,69 @@ route_intr(void *cookie)
* Enqueue a message to the software interrupt routine.
*/
void
route_enqueue(struct mbuf *m, int family)
COMPATNAME(route_enqueue)(struct mbuf *m, int family)
{
struct route_info * const ri = &COMPATNAME(route_info);
int s, wasempty;
s = splnet();
if (IF_QFULL(&route_intrq)) {
IF_DROP(&route_intrq);
if (IF_QFULL(&ri->ri_intrq)) {
IF_DROP(&ri->ri_intrq);
m_freem(m);
} else {
wasempty = IF_IS_EMPTY(&route_intrq);
wasempty = IF_IS_EMPTY(&ri->ri_intrq);
M_SETCTX(m, (uintptr_t)family);
IF_ENQUEUE(&route_intrq, m);
IF_ENQUEUE(&ri->ri_intrq, m);
if (wasempty)
softint_schedule(route_sih);
softint_schedule(ri->ri_sih);
}
splx(s);
}
void
rt_init(void)
static void
COMPATNAME(route_init)(void)
{
struct route_info * const ri = &COMPATNAME(route_info);
#ifndef COMPAT_RTSOCK
rt_init();
#endif
sysctl_net_route_setup(NULL);
route_intrq.ifq_maxlen = route_maxqlen;
route_sih = softint_establish(SOFTINT_NET | SOFTINT_MPSAFE,
route_intr, NULL);
ri->ri_intrq.ifq_maxlen = ri->ri_maxqlen;
ri->ri_sih = softint_establish(SOFTINT_NET | SOFTINT_MPSAFE,
COMPATNAME(route_intr), NULL);
}
/*
* Definitions of protocols supported in the ROUTE domain.
*/
PR_WRAP_USRREQ(route_usrreq)
#define route_usrreq route_usrreq_wrapper
#ifndef COMPAT_RTSOCK
PR_WRAP_USRREQ(route_usrreq);
#else
PR_WRAP_USRREQ(compat_50_route_usrreq);
#endif
const struct protosw routesw[] = {
static const struct protosw COMPATNAME(route_protosw)[] = {
{
.pr_type = SOCK_RAW,
.pr_domain = &routedomain,
.pr_domain = &COMPATNAME(routedomain),
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = raw_input,
.pr_output = route_output,
.pr_output = COMPATNAME(route_output),
.pr_ctlinput = raw_ctlinput,
.pr_usrreq = route_usrreq,
.pr_usrreq = COMPATNAME(route_usrreq_wrapper),
.pr_init = raw_init,
},
};
struct domain routedomain = {
.dom_family = PF_ROUTE,
.dom_name = "route",
.dom_init = route_init,
.dom_protosw = routesw,
.dom_protoswNPROTOSW = &routesw[__arraycount(routesw)],
struct domain COMPATNAME(routedomain) = {
.dom_family = PF_XROUTE,
.dom_name = DOMAINNAME,
.dom_init = COMPATNAME(route_init),
.dom_protosw = COMPATNAME(route_protosw),
.dom_protoswNPROTOSW =
&COMPATNAME(route_protosw)[__arraycount(COMPATNAME(route_protosw))],
};
static void
@ -1277,16 +1348,18 @@ sysctl_net_route_setup(struct sysctllog **clog)
sysctl_createv(clog, 0, NULL, &rnode,
CTLFLAG_PERMANENT,
CTLTYPE_NODE, "route",
CTLTYPE_NODE, DOMAINNAME,
SYSCTL_DESCR("PF_ROUTE information"),
NULL, 0, NULL, 0,
CTL_NET, PF_ROUTE, CTL_EOL);
CTL_NET, PF_XROUTE, CTL_EOL);
sysctl_createv(clog, 0, NULL, NULL,
CTLFLAG_PERMANENT,
CTLTYPE_NODE, "rtable",
SYSCTL_DESCR("Routing table information"),
sysctl_rtable, 0, NULL, 0,
CTL_NET, PF_ROUTE, 0 /* any protocol */, CTL_EOL);
CTL_NET, PF_XROUTE, 0 /* any protocol */, CTL_EOL);
sysctl_createv(clog, 0, &rnode, NULL,
CTLFLAG_PERMANENT,
CTLTYPE_STRUCT, "stats",

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_arp.c,v 1.149 2009/11/20 02:14:57 christos Exp $ */
/* $NetBSD: if_arp.c,v 1.150 2011/02/01 01:39:21 matt Exp $ */
/*-
* Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@ -68,7 +68,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.149 2009/11/20 02:14:57 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.150 2011/02/01 01:39:21 matt Exp $");
#include "opt_ddb.h"
#include "opt_inet.h"
@ -1555,9 +1555,9 @@ db_show_rtentry(struct rtentry *rt, void *w)
{
db_printf("rtentry=%p", rt);
db_printf(" flags=0x%x refcnt=%d use=%ld expire=%lld\n",
db_printf(" flags=0x%x refcnt=%d use=%"PRId64" expire=%"PRId64"\n",
rt->rt_flags, rt->rt_refcnt,
rt->rt_use, (long long)rt->rt_expire);
rt->rt_use, (uint64_t)rt->rt_expire);
db_printf(" key="); db_print_sa(rt_getkey(rt));
db_printf(" mask="); db_print_sa(rt_mask(rt));

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile.rumpnet,v 1.10 2010/01/19 22:08:18 pooka Exp $
# $NetBSD: Makefile.rumpnet,v 1.11 2011/02/01 01:39:21 matt Exp $
#
.include "${RUMPTOP}/Makefile.rump"
@ -21,8 +21,8 @@ SRCS+= sys_socket.c uipc_accf.c uipc_domain.c uipc_mbuf.c uipc_mbuf2.c \
# radix trie support
SRCS+= radix.c
# compat
SRCS+= rtsock_50.c
# compat (nothing for now)
SRCS+=
# bpf stubs, required for all kernels
SRCS+= bpf_stub.c

View File

@ -1,4 +1,4 @@
/* $NetBSD: net_stub.c,v 1.11 2010/12/08 20:20:52 pooka Exp $ */
/* $NetBSD: net_stub.c,v 1.12 2011/02/01 01:39:21 matt Exp $ */
/*
* Copyright (c) 2008 Antti Kantee. All Rights Reserved.
@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: net_stub.c,v 1.11 2010/12/08 20:20:52 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: net_stub.c,v 1.12 2011/02/01 01:39:21 matt Exp $");
#include <sys/param.h>
#include <sys/protosw.h>
@ -53,7 +53,7 @@ __weak_alias(ifunit,__rumpnet_stub);
__weak_alias(ifreq_setaddr,__rumpnet_stub);
__weak_alias(rt_msg1,__rumpnet_stub);
__weak_alias(route_enqueue,__rumpnet_stub);
__weak_alias(route_cb,__rumpnet_stub);
__weak_alias(route_info,__rumpnet_stub);
/*
* Weak symbols so that we can optionally leave components out.

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.10 2010/12/08 18:06:43 pooka Exp $
# $NetBSD: Makefile,v 1.11 2011/02/01 01:39:21 matt Exp $
#
.PATH: ${.CURDIR}/../../../../net ${.CURDIR}/../../../../compat/common
@ -6,7 +6,7 @@
LIB= rumpnet_net
# iffy stuff
SRCS= if.c if_loop.c route.c rtsock.c raw_usrreq.c \
SRCS= if.c if_loop.c route.c rtsock.c rtsock_50.c raw_usrreq.c \
raw_cb.c if_media.c link_proto.c net_stats.c if_ethersubr.c
SRCS+= if_43.c uipc_syscalls_50.c
SRCS+= component.c

View File

@ -1,4 +1,4 @@
/* $NetBSD: socket.h,v 1.98 2010/06/26 14:24:27 kefren Exp $ */
/* $NetBSD: socket.h,v 1.99 2011/02/01 01:39:21 matt Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -184,7 +184,7 @@ struct accept_filter_arg {
#define AF_LAT 14 /* LAT */
#define AF_HYLINK 15 /* NSC Hyperchannel */
#define AF_APPLETALK 16 /* Apple Talk */
#define AF_ROUTE 17 /* Internal Routing Protocol */
#define AF_OROUTE 17 /* Internal Routing Protocol */
#define AF_LINK 18 /* Link layer interface */
#if defined(_NETBSD_SOURCE)
#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */
@ -211,7 +211,8 @@ struct accept_filter_arg {
#define AF_BLUETOOTH 31 /* Bluetooth: HCI, SCO, L2CAP, RFCOMM */
#define AF_IEEE80211 32 /* IEEE80211 */
#define AF_MPLS 33 /* MultiProtocol Label Switching */
#define AF_MAX 34
#define AF_ROUTE 34 /* Internal Routing Protocol */
#define AF_MAX 35
/*
* Structure used by kernel to store most
@ -279,7 +280,7 @@ struct sockaddr_storage {
#define PF_LAT AF_LAT
#define PF_HYLINK AF_HYLINK
#define PF_APPLETALK AF_APPLETALK
#define PF_ROUTE AF_ROUTE
#define PF_OROUTE AF_OROUTE
#define PF_LINK AF_LINK
#if defined(_NETBSD_SOURCE)
#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
@ -301,6 +302,7 @@ struct sockaddr_storage {
#endif
#define PF_BLUETOOTH AF_BLUETOOTH
#define PF_MPLS AF_MPLS
#define PF_ROUTE AF_ROUTE
#define PF_MAX AF_MAX
@ -365,7 +367,7 @@ struct sockcred {
{ "lat", CTLTYPE_NODE }, \
{ "hylink", CTLTYPE_NODE }, \
{ "appletalk", CTLTYPE_NODE }, \
{ "route", CTLTYPE_NODE }, \
{ "oroute", CTLTYPE_NODE }, \
{ "link_layer", CTLTYPE_NODE }, \
{ "xtp", CTLTYPE_NODE }, \
{ "coip", CTLTYPE_NODE }, \
@ -378,6 +380,9 @@ struct sockcred {
{ "natm", CTLTYPE_NODE }, \
{ "arp", CTLTYPE_NODE }, \
{ "key", CTLTYPE_NODE }, \
{ "ieee80211", CTLTYPE_NODE }, \
{ "mlps", CTLTYPE_NODE }, \
{ "route", CTLTYPE_NODE }, \
}
struct kinfo_pcb {

View File

@ -1,4 +1,4 @@
/* $NetBSD: route.c,v 1.75 2010/06/27 06:52:38 kefren Exp $ */
/* $NetBSD: route.c,v 1.76 2011/02/01 01:39:21 matt 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.75 2010/06/27 06:52:38 kefren Exp $");
__RCSID("$NetBSD: route.c,v 1.76 2011/02/01 01:39:21 matt Exp $");
#endif
#endif /* not lint */
@ -267,9 +267,9 @@ p_krtentry(rt)
p_addr(addr, mask, rt->rt_flags);
p_gwaddr(kgetsa(rt->rt_gateway), kgetsa(rt->rt_gateway)->sa_family);
p_flags(rt->rt_flags, "%-6.6s ");
printf("%6d %8lu ", rt->rt_refcnt, rt->rt_use);
printf("%6d %8"PRIu64" ", rt->rt_refcnt, rt->rt_use);
if (rt->rt_rmx.rmx_mtu)
printf("%6lu", rt->rt_rmx.rmx_mtu);
printf("%6"PRIu64, rt->rt_rmx.rmx_mtu);
else
printf("%6s", "-");
putchar((rt->rt_rmx.rmx_locks & RTV_MTU) ? 'L' : ' ');
@ -298,23 +298,23 @@ p_krtentry(rt)
}
putchar('\n');
if (vflag) {
printf("\texpire %10lld%c recvpipe %10ld%c "
"sendpipe %10ld%c\n",
(long long)rt->rt_rmx.rmx_expire,
printf("\texpire %10"PRId64"%c recvpipe %10"PRIu64"%c "
"sendpipe %10"PRIu64"%c\n",
(int64_t)rt->rt_rmx.rmx_expire,
(rt->rt_rmx.rmx_locks & RTV_EXPIRE) ? 'L' : ' ',
rt->rt_rmx.rmx_recvpipe,
(rt->rt_rmx.rmx_locks & RTV_RPIPE) ? 'L' : ' ',
rt->rt_rmx.rmx_sendpipe,
(rt->rt_rmx.rmx_locks & RTV_SPIPE) ? 'L' : ' ');
printf("\tssthresh %10lu%c rtt %10ld%c "
"rttvar %10ld%c\n",
printf("\tssthresh %10"PRIu64"%c rtt %10"PRIu64"%c "
"rttvar %10"PRIu64"%c\n",
rt->rt_rmx.rmx_ssthresh,
(rt->rt_rmx.rmx_locks & RTV_SSTHRESH) ? 'L' : ' ',
rt->rt_rmx.rmx_rtt,
(rt->rt_rmx.rmx_locks & RTV_RTT) ? 'L' : ' ',
rt->rt_rmx.rmx_rttvar,
(rt->rt_rmx.rmx_locks & RTV_RTTVAR) ? 'L' : ' ');
printf("\thopcount %10lu%c\n",
printf("\thopcount %10"PRIu64"%c\n",
rt->rt_rmx.rmx_hopcount,
(rt->rt_rmx.rmx_locks & RTV_HOPCOUNT) ? 'L' : ' ');
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: show.c,v 1.11 2010/12/13 21:15:30 pooka Exp $ */
/* $NetBSD: show.c,v 1.12 2011/02/01 01:39:21 matt Exp $ */
/* $OpenBSD: show.c,v 1.1 2006/05/27 19:16:37 claudio Exp $ */
/*
@ -263,13 +263,13 @@ p_rtentry(struct rt_msghdr *rtm)
WID_GW(sa->sa_family));
p_flags(rtm->rtm_flags, "%-6.6s ");
#if 0 /* XXX-elad */
printf("%6d %8ld ", (int)rtm->rtm_rmx.rmx_refcnt,
printf("%6d %8"PRId64" ", (int)rtm->rtm_rmx.rmx_refcnt,
rtm->rtm_rmx.rmx_pksent);
#else
printf("%6s %8s ", "-", "-");
#endif
if (rtm->rtm_rmx.rmx_mtu)
printf("%6ld", rtm->rtm_rmx.rmx_mtu);
printf("%6"PRId64, rtm->rtm_rmx.rmx_mtu);
else
printf("%6s", "-");
putchar((rtm->rtm_rmx.rmx_locks & RTV_MTU) ? 'L' : ' ');