Module Name: src Committed By: roy Date: Mon Mar 23 18:33:17 UTC 2015
Modified Files: src/sbin/route: route.8 route.c rtutil.c show.c src/share/man/man4: route.4 src/sys/net: route.h src/sys/netinet: if_arp.c ip_flow.c ip_output.c src/sys/netinet6: ip6_flow.c src/usr.bin/netstat: netstat.1 Log Message: Add RTF_BROADCAST to mark routes used for the broadcast address when they are created on the fly. This makes it clear what the route is for and allows an optimisation in ip_output() by avoiding a call to in_broadcast() because most of the time we do talk to a host. It also avoids a needless allocation for the storage of llinfo_arp and thus vanishes from arp(8) - it showed as incomplete anyway so this is a nice side effect. Guard against this and routes marked with RTF_BLACKHOLE in ip_fastforward(). While here, guard against routes marked with RTF_BLACKHOLE in ip6_fastforward(). RTF_BROADCAST is IPv4 only, so don't bother checking that here. To generate a diff of this commit: cvs rdiff -u -r1.54 -r1.55 src/sbin/route/route.8 cvs rdiff -u -r1.150 -r1.151 src/sbin/route/route.c cvs rdiff -u -r1.5 -r1.6 src/sbin/route/rtutil.c cvs rdiff -u -r1.47 -r1.48 src/sbin/route/show.c cvs rdiff -u -r1.24 -r1.25 src/share/man/man4/route.4 cvs rdiff -u -r1.87 -r1.88 src/sys/net/route.h cvs rdiff -u -r1.161 -r1.162 src/sys/netinet/if_arp.c cvs rdiff -u -r1.65 -r1.66 src/sys/netinet/ip_flow.c cvs rdiff -u -r1.233 -r1.234 src/sys/netinet/ip_output.c cvs rdiff -u -r1.23 -r1.24 src/sys/netinet6/ip6_flow.c cvs rdiff -u -r1.71 -r1.72 src/usr.bin/netstat/netstat.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sbin/route/route.8 diff -u src/sbin/route/route.8:1.54 src/sbin/route/route.8:1.55 --- src/sbin/route/route.8:1.54 Thu Feb 26 09:56:11 2015 +++ src/sbin/route/route.8 Mon Mar 23 18:33:17 2015 @@ -1,4 +1,4 @@ -.\" $NetBSD: route.8,v 1.54 2015/02/26 09:56:11 roy Exp $ +.\" $NetBSD: route.8,v 1.55 2015/03/23 18:33:17 roy Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)route.8 8.4 (Berkeley) 6/1/94 .\" -.Dd February 26, 2015 +.Dd March 19, 2015 .Dt ROUTE 8 .Os .Sh NAME @@ -295,6 +295,7 @@ by indicating the following correspondin .It Li 1 Ta -proto1 Ta " RTF_PROTO1" Ta set protocol specific flag #1 .It Li 2 Ta -proto2 Ta " RTF_PROTO2" Ta set protocol specific flag #2 .It Li B Ta -blackhole Ta " RTF_BLACKHOLE" Ta discard pkts (during updates) +.It Li b Ta "" Ta " RTF_BROADCAST" Ta Route represents a broadcast address .It Li " " Ta -noblackhole Ta ~RTF_BLACKHOLE Ta clear blackhole flag .It Li C Ta -cloning Ta " RTF_CLONING" Ta generates a new route on use .It Li " " Ta -nocloning Ta ~RTF_CLONING Ta stop generating new routes on use Index: src/sbin/route/route.c diff -u src/sbin/route/route.c:1.150 src/sbin/route/route.c:1.151 --- src/sbin/route/route.c:1.150 Thu Feb 26 09:56:11 2015 +++ src/sbin/route/route.c Mon Mar 23 18:33:17 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: route.c,v 1.150 2015/02/26 09:56:11 roy Exp $ */ +/* $NetBSD: route.c,v 1.151 2015/03/23 18:33:17 roy Exp $ */ /* * Copyright (c) 1983, 1989, 1991, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 19 #if 0 static char sccsid[] = "@(#)route.c 8.6 (Berkeley) 4/28/95"; #else -__RCSID("$NetBSD: route.c,v 1.150 2015/02/26 09:56:11 roy Exp $"); +__RCSID("$NetBSD: route.c,v 1.151 2015/03/23 18:33:17 roy Exp $"); #endif #endif /* not lint */ @@ -1292,7 +1292,7 @@ const char * const msgtypes[] = { const char metricnames[] = "\011pksent\010rttvar\7rtt\6ssthresh\5sendpipe\4recvpipe\3expire\2hopcount\1mtu"; const char routeflags[] = -"\1UP\2GATEWAY\3HOST\4REJECT\5DYNAMIC\6MODIFIED\7DONE\010MASK_PRESENT\011CLONING\012XRESOLVE\013LLINFO\014STATIC\015BLACKHOLE\016CLONED\017PROTO2\020PROTO1\023LOCAL"; +"\1UP\2GATEWAY\3HOST\4REJECT\5DYNAMIC\6MODIFIED\7DONE\010MASK_PRESENT\011CLONING\012XRESOLVE\013LLINFO\014STATIC\015BLACKHOLE\016CLONED\017PROTO2\020PROTO1\023LOCAL\024BROADCAST"; const char ifnetflags[] = "\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5PTP\6NOTRAILERS\7RUNNING\010NOARP\011PPROMISC\012ALLMULTI\013OACTIVE\014SIMPLEX\015LINK0\016LINK1\017LINK2\020MULTICAST"; const char addrnames[] = Index: src/sbin/route/rtutil.c diff -u src/sbin/route/rtutil.c:1.5 src/sbin/route/rtutil.c:1.6 --- src/sbin/route/rtutil.c:1.5 Thu Feb 26 09:56:11 2015 +++ src/sbin/route/rtutil.c Mon Mar 23 18:33:17 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: rtutil.c,v 1.5 2015/02/26 09:56:11 roy Exp $ */ +/* $NetBSD: rtutil.c,v 1.6 2015/03/23 18:33:17 roy Exp $ */ /* $OpenBSD: show.c,v 1.1 2006/05/27 19:16:37 claudio Exp $ */ /* @@ -93,6 +93,7 @@ static const struct bits bits[] = { /* { RTF_JUMBO, 'J' }, */ { RTF_ANNOUNCE, 'p' }, { RTF_LOCAL, 'l'}, + { RTF_BROADCAST, 'b'}, { 0, 0 } }; Index: src/sbin/route/show.c diff -u src/sbin/route/show.c:1.47 src/sbin/route/show.c:1.48 --- src/sbin/route/show.c:1.47 Thu Feb 26 09:56:11 2015 +++ src/sbin/route/show.c Mon Mar 23 18:33:17 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: show.c,v 1.47 2015/02/26 09:56:11 roy Exp $ */ +/* $NetBSD: show.c,v 1.48 2015/03/23 18:33:17 roy 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.47 2015/02/26 09:56:11 roy Exp $"); +__RCSID("$NetBSD: show.c,v 1.48 2015/03/23 18:33:17 roy Exp $"); #endif #endif /* not lint */ @@ -137,7 +137,7 @@ show(int argc, char *const *argv, int fl { int af, rflags; static int interesting = RTF_UP | RTF_GATEWAY | RTF_HOST | - RTF_REJECT | RTF_LLINFO | RTF_LOCAL; + RTF_REJECT | RTF_LLINFO | RTF_LOCAL | RTF_BROADCAST; parse_show_opts(argc, argv, &af, &rflags, NULL, true); p_rttables(af, flags, rflags, interesting); Index: src/share/man/man4/route.4 diff -u src/share/man/man4/route.4:1.24 src/share/man/man4/route.4:1.25 --- src/share/man/man4/route.4:1.24 Thu Feb 26 09:58:39 2015 +++ src/share/man/man4/route.4 Mon Mar 23 18:33:17 2015 @@ -1,4 +1,4 @@ -.\" $NetBSD: route.4,v 1.24 2015/02/26 09:58:39 roy Exp $ +.\" $NetBSD: route.4,v 1.25 2015/03/23 18:33:17 roy Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)route.4 8.6 (Berkeley) 4/19/94 .\" -.Dd February 26, 2015 +.Dd March 19, 2015 .Dt ROUTE 4 .Os .Sh NAME @@ -311,6 +311,7 @@ Flags include the values: #define RTF_SRC 0x10000 /* route has fixed source address */ #define RTF_ANNOUNCE 0x20000 /* announce new ARP or NDP entry */ #define RTF_LOCAL 0x40000 /* route represents a local address */ +#define RTF_BROADCAST 0x80000 /* route represents a bcast address */ .Ed .Pp Specifiers for metric values in rmx_locks and rtm_inits are: Index: src/sys/net/route.h diff -u src/sys/net/route.h:1.87 src/sys/net/route.h:1.88 --- src/sys/net/route.h:1.87 Thu Feb 26 09:54:46 2015 +++ src/sys/net/route.h Mon Mar 23 18:33:17 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: route.h,v 1.87 2015/02/26 09:54:46 roy Exp $ */ +/* $NetBSD: route.h,v 1.88 2015/03/23 18:33:17 roy Exp $ */ /* * Copyright (c) 1980, 1986, 1993 @@ -156,6 +156,7 @@ struct ortentry { #define RTF_SRC 0x10000 /* route has fixed source address */ #define RTF_ANNOUNCE 0x20000 /* announce new ARP or NDP entry */ #define RTF_LOCAL 0x40000 /* route represents a local address */ +#define RTF_BROADCAST 0x80000 /* route represents a bcast address */ /* * Routing statistics. Index: src/sys/netinet/if_arp.c diff -u src/sys/netinet/if_arp.c:1.161 src/sys/netinet/if_arp.c:1.162 --- src/sys/netinet/if_arp.c:1.161 Thu Feb 26 09:54:46 2015 +++ src/sys/netinet/if_arp.c Mon Mar 23 18:33:17 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: if_arp.c,v 1.161 2015/02/26 09:54:46 roy Exp $ */ +/* $NetBSD: if_arp.c,v 1.162 2015/03/23 18:33:17 roy 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.161 2015/02/26 09:54:46 roy Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.162 2015/03/23 18:33:17 roy Exp $"); #include "opt_ddb.h" #include "opt_inet.h" @@ -613,10 +613,24 @@ arp_rtrequest(int req, struct rtentry *r log(LOG_DEBUG, "arp_rtrequest: bad gateway value\n"); break; } + satosdl(gate)->sdl_type = ifp->if_type; satosdl(gate)->sdl_index = ifp->if_index; if (la != NULL) break; /* This happens on a route change */ + + /* If the route is for a broadcast address mark it as such. + * This way we can avoid an expensive call to in_broadcast() + * in ip_output() most of the time (because the route passed + * to ip_output() is almost always a host route). */ + if (rt->rt_flags & RTF_HOST && + !(rt->rt_flags & RTF_BROADCAST) && + in_broadcast(satocsin(rt_getkey(rt))->sin_addr, rt->rt_ifp)) + rt->rt_flags |= RTF_BROADCAST; + /* There is little point in resolving the broadcast address */ + if (rt->rt_flags & RTF_BROADCAST) + break; + /* * Case 2: This route may come from cloning, or a manual route * add with a LL address. Index: src/sys/netinet/ip_flow.c diff -u src/sys/netinet/ip_flow.c:1.65 src/sys/netinet/ip_flow.c:1.66 --- src/sys/netinet/ip_flow.c:1.65 Sat Oct 18 08:33:29 2014 +++ src/sys/netinet/ip_flow.c Mon Mar 23 18:33:17 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: ip_flow.c,v 1.65 2014/10/18 08:33:29 snj Exp $ */ +/* $NetBSD: ip_flow.c,v 1.66 2015/03/23 18:33:17 roy Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ip_flow.c,v 1.65 2014/10/18 08:33:29 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip_flow.c,v 1.66 2015/03/23 18:33:17 roy Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -234,7 +234,8 @@ ipflow_fastforward(struct mbuf *m) * Route and interface still up? */ if ((rt = rtcache_validate(&ipf->ipf_ro)) == NULL || - (rt->rt_ifp->if_flags & IFF_UP) == 0) + (rt->rt_ifp->if_flags & IFF_UP) == 0 || + (rt->rt_flags & (RTF_BLACKHOLE | RTF_BROADCAST)) != 0) return 0; /* Index: src/sys/netinet/ip_output.c diff -u src/sys/netinet/ip_output.c:1.233 src/sys/netinet/ip_output.c:1.234 --- src/sys/netinet/ip_output.c:1.233 Wed Nov 26 10:18:37 2014 +++ src/sys/netinet/ip_output.c Mon Mar 23 18:33:17 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: ip_output.c,v 1.233 2014/11/26 10:18:37 ozaki-r Exp $ */ +/* $NetBSD: ip_output.c,v 1.234 2015/03/23 18:33:17 roy Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -91,7 +91,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.233 2014/11/26 10:18:37 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.234 2015/03/23 18:33:17 roy Exp $"); #include "opt_inet.h" #include "opt_ipsec.h" @@ -163,6 +163,7 @@ ip_output(struct mbuf *m0, ...) struct route iproute; const struct sockaddr_in *dst; struct in_ifaddr *ia; + int isbroadcast; struct mbuf *opt; struct route *ro; int flags, sw_csum; @@ -257,12 +258,14 @@ ip_output(struct mbuf *m0, ...) ifp = ia->ia_ifp; mtu = ifp->if_mtu; ip->ip_ttl = 1; + isbroadcast = in_broadcast(dst->sin_addr, ifp); } else if ((IN_MULTICAST(ip->ip_dst.s_addr) || ip->ip_dst.s_addr == INADDR_BROADCAST) && imo != NULL && imo->imo_multicast_ifp != NULL) { ifp = imo->imo_multicast_ifp; mtu = ifp->if_mtu; IFP_TO_IA(ifp, ia); + isbroadcast = 0; } else { if (rt == NULL) rt = rtcache_init(ro); @@ -278,6 +281,10 @@ ip_output(struct mbuf *m0, ...) rt->rt_use++; if (rt->rt_flags & RTF_GATEWAY) dst = satosin(rt->rt_gateway); + if (rt->rt_flags & RTF_HOST) + isbroadcast = rt->rt_flags & RTF_BROADCAST; + else + isbroadcast = in_broadcast(dst->sin_addr, ifp); } rtmtu_nolock = rt && (rt->rt_rmx.rmx_locks & RTV_MTU) == 0; @@ -412,7 +419,7 @@ ip_output(struct mbuf *m0, ...) * Look for broadcast address and and verify user is allowed to * send such a packet. */ - if (in_broadcast(dst->sin_addr, ifp)) { + if (isbroadcast) { if ((ifp->if_flags & IFF_BROADCAST) == 0) { error = EADDRNOTAVAIL; goto bad; Index: src/sys/netinet6/ip6_flow.c diff -u src/sys/netinet6/ip6_flow.c:1.23 src/sys/netinet6/ip6_flow.c:1.24 --- src/sys/netinet6/ip6_flow.c:1.23 Tue May 20 20:23:56 2014 +++ src/sys/netinet6/ip6_flow.c Mon Mar 23 18:33:17 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: ip6_flow.c,v 1.23 2014/05/20 20:23:56 bouyer Exp $ */ +/* $NetBSD: ip6_flow.c,v 1.24 2015/03/23 18:33:17 roy Exp $ */ /*- * Copyright (c) 2007 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ip6_flow.c,v 1.23 2014/05/20 20:23:56 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip6_flow.c,v 1.24 2015/03/23 18:33:17 roy Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -275,10 +275,9 @@ ip6flow_fastforward(struct mbuf **mp) * Route and interface still up? */ if ((rt = rtcache_validate(&ip6f->ip6f_ro)) == NULL || - (rt->rt_ifp->if_flags & IFF_UP) == 0) { - /* Route or interface is down */ + (rt->rt_ifp->if_flags & IFF_UP) == 0 || + (rt->rt_flags & RTF_BLACKHOLE) != 0) return 0; - } /* * Packet size greater than MTU? Index: src/usr.bin/netstat/netstat.1 diff -u src/usr.bin/netstat/netstat.1:1.71 src/usr.bin/netstat/netstat.1:1.72 --- src/usr.bin/netstat/netstat.1:1.71 Thu Feb 26 09:58:12 2015 +++ src/usr.bin/netstat/netstat.1 Mon Mar 23 18:33:17 2015 @@ -1,4 +1,4 @@ -.\" $NetBSD: netstat.1,v 1.71 2015/02/26 09:58:12 roy Exp $ +.\" $NetBSD: netstat.1,v 1.72 2015/03/23 18:33:17 roy Exp $ .\" .\" Copyright (c) 1983, 1990, 1992, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)netstat.1 8.8 (Berkeley) 4/18/94 .\" -.Dd February 26, 2015 +.Dd March 19, 2015 .Dt NETSTAT 1 .Os .Sh NAME @@ -372,6 +372,7 @@ The mapping between letters and flags is .It 1 RTF_PROTO1 Protocol specific routing flag #1 .It 2 RTF_PROTO2 Protocol specific routing flag #2 .It B RTF_BLACKHOLE Just discard pkts (during updates) +.It b RTF_BROADCAST Route represents a broadcast address .It C RTF_CLONING Generate new routes on use .It c RTF_CLONED Cloned routes (generated from RTF_CLONING) .It D RTF_DYNAMIC Created dynamically (by redirect)