History log of /netbsd-current/sbin/route/route.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.169 10-Apr-2022 andvar

fix various typos in comments and output/log messages.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base phil-wifi-20200421 phil-wifi-20200411 phil-wifi-20200406
# 1.168 02-Apr-2020 christos

Add a prog_setsockopt (thanks kre@)


# 1.167 14-Mar-2020 roy

route: Enable receive error reporting on the routing socket


Revision tags: is-mlppp-base
# 1.166 22-Feb-2020 kamil

Avoid undefined behavior

route.c:1523:20, left shift of 1073741824 by 1 places cannot be represented
in type 'int'


# 1.165 22-Jan-2020 roy

route: address flags are more useful than interface flags for address msgs


# 1.164 22-Jan-2020 roy

route: Decode the correct flags for interface address messages


Revision tags: phil-wifi-20191119
# 1.163 02-Sep-2019 roy

route(8): Show addres for RTM_LOSING

While here, add /* FALLTHROUGH */.


# 1.162 31-Aug-2019 roy

route(8): show addrs for RTM_MISS


# 1.161 22-Aug-2019 roy

route(8): print RTM_CHANGE messages

XXX Pullup -9


Revision tags: netbsd-9-base phil-wifi-20190609 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906
# 1.160 14-Aug-2018 roy

branches: 1.160.2;
Resolve every route(4) message type before printing anything more about it
other than the type and length.

This solves the issue where RTM_ONEWADDR is received and it tries to
parse route information from it.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330
# 1.159 23-Mar-2018 roy

branches: 1.159.2;
Handle the routing socket overflowing gracefully.


Revision tags: pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.158 13-Dec-2017 christos

branches: 1.158.2;
Use the definitions from the standard header files and replace homebrew
snprintb with the libutil one.


# 1.157 13-Dec-2017 uwe

Fix typo in flag name. We should probably just use IFFBITS string
that <net/if.h> defines.

PR bin/52815


Revision tags: perseant-stdc-iso10646-base
# 1.156 16-Jun-2017 ozaki-r

Support -c <count> option for route monitor

route command exits if it receives <count> routing messages where
<count> is a value specified by -c.

The option is useful to get only particular message(s) in a test script.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320
# 1.155 17-Mar-2017 roy

branches: 1.155.4;
Report the PID for the process changing the address.


Revision tags: bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.154 04-Apr-2016 ozaki-r

branches: 1.154.2; 1.154.4;
Separate nexthop caches from the routing table

By this change, nexthop caches (IP-MAC address pair) are not stored
in the routing table anymore. Instead nexthop caches are stored in
each network interface; we already have lltable/llentry data structure
for this purpose. This change also obsoletes the concept of cloning/cloned
routes. Cloned routes no longer exist while cloning routes still exist
with renamed to connected routes.

Noticeable changes are:
- Nexthop caches aren't listed in route show/netstat -r
- sysctl(NET_RT_DUMP) doesn't return them
- If RTF_LLDATA is specified, it returns nexthop caches
- Several definitions of routing flags and messages are removed
- RTF_CLONING, RTF_XRESOLVE, RTF_LLINFO, RTF_CLONED and RTM_RESOLVE
- RTF_CONNECTED is added
- It has the same value of RTF_CLONING for backward compatibility
- route's -xresolve, -[no]cloned and -llinfo options are removed
- -[no]cloning remains because it seems there are users
- -[no]connected is introduced and recommended
to be used instead of -[no]cloning
- route show/netstat -r drops some flags
- 'L' and 'c' are not seen anymore
- 'C' now indicates a connected route
- Gateway value of a route of an interface address is now not
a L2 address but "link#N" like a connected (cloning) route
- Proxy ARP: "arp -s ... pub" doesn't create a route

You can know details of behavior changes by seeing diffs under tests/.

Proposed on tech-net and tech-kern:
http://mail-index.netbsd.org/tech-net/2016/03/11/msg005701.html


# 1.153 23-Jan-2016 christos

no need for <sys/mbuf.h>


# 1.152 17-Jan-2016 christos

PR/50671: David Binderman: fix memory leak.


# 1.151 23-Mar-2015 roy

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.


# 1.150 26-Feb-2015 roy

Teach route(8) about RTF_LOCAL.


# 1.149 20-Dec-2014 prlw1

MKINET6=no build fixes

http://mail-index.netbsd.org/tech-net/2014/12/13/msg004898.html


# 1.148 17-Dec-2014 roy

Note that RTM_CHANGE can also change the gateway


# 1.147 12-Nov-2014 christos

PR/47704: Takahiro HAYASHI: Add -L flag


# 1.146 07-Nov-2014 christos

Now that the code can support tags and verbose route printing, enable them.
Also document previously undocumented flags.


# 1.145 06-Nov-2014 christos

Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.144 19-Oct-2013 christos

branches: 1.144.4;
use correct function


# 1.143 19-Oct-2013 christos

use symbolic flags


# 1.142 19-Oct-2013 christos

use scopeid functions


# 1.141 18-Oct-2013 christos

avoid pointer gymnastics


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.140 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.139 04-Oct-2012 uwe

Fix fallout from 1.129 that converted sou::so_foo from unions to
pointers but missed (char *)&soup->so_foo => (char *)soup->so_foo in
mask_addr(). It worked by luck - unless it didn't: due to pointer
numerology on amd64 route add -net ClassC without explicit /24 prefix
length specification would result into /16 destination instead of /24.


# 1.138 08-Aug-2012 christos

branches: 1.138.2;
remove useless rump headers.


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.137 17-Mar-2012 christos

PR/42179: Christoph Badura: Be a little friendlier about missing args.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.136 26-Dec-2011 christos

branches: 1.136.2;
Off by one and clarity improvement from Christian Biere


# 1.135 24-Dec-2011 christos

PR/45661: Henning Petersen: Overlapping buffer in route.c.


# 1.134 11-Nov-2011 gdt

Move RTF_ANNOUNCE flag so that it no longer conflicts with RTF_PROTO2.

RTF_ANNOUNCE was defined as RTF_PROTO2. The flag is used to indicated
that host should act as a proxy for a link level arp or ndp request.
(If RTF_PROTO2 is used as an experimental flag (as advertised),
various problems can occur.)

This commit provides a first-class definition with its own bit for
RTF_ANNOUNCE, removes the old aliasing definitions, and adds support
for the new RTF_ANNOUNCE flag to netstat(8) and route(8).,

Also, remove unused RTF_ flags that collide with RTF_PROTO1:
netinet/icmp6.h defined RTF_PROBEMTU as RTF_PROTO1
netinet/if_inarp.h defined RTF_USETRAILERS as RTF_PROTO1
(Neither of these flags are used anywhere. Both have been removed
to reduce chances of collision with RTF_PROTO1.)

Figuring this out and the diff are the work of Beverly Schwartz of
BBN.

(Passed release build, boot in VM, with no apparently related atf
failures.)

Approved for Public Release, Distribution Unlimited
This material is based upon work supported by the Defense Advanced
Research Projects Agency and Space and Naval Warfare Systems Center,
Pacific, under Contract No. N66001-09-C-2073.


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.133 07-Oct-2011 joerg

branches: 1.133.2;
Simplify.


# 1.132 29-Aug-2011 joerg

Use __dead


# 1.131 01-Jul-2011 joerg

Fix memset usage.


# 1.130 22-Jun-2011 kefren

don't compile tag functions if SMALL is defined. Should fix the build


# 1.129 21-Jun-2011 kefren

Alloc dynamically sockunions in sou.
Teach route(8) about multiple tags. E.G.: -tag 100,20,33
XXX: needs documentation


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.128 01-Feb-2011 matt

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.


Revision tags: matt-mips64-premerge-20101231
# 1.127 13-Dec-2010 pooka

branches: 1.127.2;
Convert from RUMP_ACTION to RUMPPRG.


# 1.126 12-Nov-2010 roy

Support the new RTM_IFINFO and RTM_CHGADDR messages.


# 1.125 05-Nov-2010 pooka

adapt to new rumpclient_init() signature


# 1.124 04-Nov-2010 pooka

#ifdef variable correctly


# 1.123 04-Nov-2010 pooka

be consistent in what to leave outside of SMALL


# 1.122 04-Nov-2010 pooka

Support RUMP_ACTION to compile a rump kernel client.


# 1.121 26-Jun-2010 kefren

add MPLS clue - mpls and tag keywords


# 1.120 12-May-2010 christos

PR/40455: Mihai Chelaru: Add noreject noblackhole options


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base mjf-devfs2-base
# 1.119 28-Dec-2008 christos

parse unsigned long with strtoul not atoi


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3
# 1.118 10-Sep-2008 dyoung

branches: 1.118.6;
Get the socket addresses for dst/gateway/netmask/interface/ifaddr
out of the global namespace.


# 1.117 10-Sep-2008 dyoung

Don't cast a sockunion * to sockaddr *. Instead, reference the
sockaddr inside of the sockunion.


# 1.116 10-Sep-2008 dyoung

Delete superfluous casts to void *.


# 1.115 10-Sep-2008 dyoung

Constify.


# 1.114 10-Sep-2008 dyoung

Constify.


# 1.113 10-Sep-2008 dyoung

Constify.

For clarity's sake, do not assign a new value to inet_makenetandmask()'s
argument, `inet'.


# 1.112 09-Sep-2008 dyoung

Extract subroutine extract_addrs() for reuse, later.

Replace the anonymous constant, 0, with AF_UNSPEC.


# 1.111 09-Sep-2008 dyoung

Constify.


# 1.110 09-Sep-2008 dyoung

Shorten a staircase. Remove superfluous parentheses from return
statements. Constify.


# 1.109 09-Sep-2008 dyoung

Use a union and sizeof() to avoid a cast and an anonymous constant
buffer length, respectively.


# 1.108 09-Sep-2008 dyoung

Use bool.


Revision tags: wrstuden-revivesa-base-2
# 1.107 20-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking cube-autoconf-base mjf-devfs-base matt-armv6-base matt-mips64-base hpcarm-cleanup-base
# 1.106 18-Feb-2007 hubertf

branches: 1.106.12; 1.106.16;
TSEL() is const char* now


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base netbsd-4-base
# 1.105 11-Nov-2006 apb

Fix a bug that caused 0.0.0.0/0 to be treated like 0.0.0.0/32.

foo << 32 is undefined per section 6.5.7 of the C99 standard
if foo is (or is promoted to) a 32-bit type.


# 1.104 23-Sep-2006 dyoung

Let us qualify 'route flush' and 'route show' commands with -llinfo
and -host flags, which is useful for displaying/flushing ARP entries:

# route -n show -inet -llinfo -host
Routing table

Internet:
Destination Gateway Flags
169.254.1.119 link#1 UH
169.254.230.110 00:02:6f:21:e6:6e UH
# route -n flush -inet -llinfo -host
169.254.1.119 done
169.254.230.110 0.2.6f.21.e6.6e done
169.254.237.70 done
# route -n show -inet -llinfo -host
Routing table
#

This will help me address bin/11079, "dhclient may require arp and sed".

Extract common code from flushroutes() and show(), creating
parse_show_opts().

While I'm here, make small cosmetic changes to flushroutes().


# 1.103 23-Sep-2006 dyoung

Move the #ifndef SMALL code together.


# 1.102 23-Sep-2006 dyoung

Use the symbol AF_UNSPEC instead of 0 as appropriate.


# 1.101 23-Sep-2006 dyoung

Remove dead code.


# 1.100 26-Aug-2006 matt

Remove XNS and CCITT/X25 bits.


Revision tags: abandoned-netbsd-4-base
# 1.99 06-Aug-2006 dyoung

KNF err(3), errx(3) usage, indentation, braces.


# 1.98 06-Aug-2006 dyoung

Add route keywords -nocloned, -nocloning.


# 1.97 29-Jan-2006 wiz

Use default option order (AaBbCc...).


# 1.96 26-Jan-2006 is

Print the INET netmask if it is non-contiguous.


# 1.95 25-Jan-2006 christos

PR/32632: Yves-Emmanuel JUTARD: Improvment suggestion in 'route' display.
Add a new -S flag that prints a space for missing flags.


# 1.94 25-Jan-2006 christos

PR/32629: Yves-Emmanuel JUTARD: Type errors in sbin/route/route.c, another
u_char/char conflict.


# 1.93 31-Aug-2005 ginsbach

Add full IPv6 syntax support when route is built with -DSMALL and -DINET6.
Fixes PR/23937. Adapted from supplied patch.


# 1.92 30-Aug-2005 ginsbach

Clean up some minor nits:
+ style (KNF).
. don't cast NULL
. white space clean up
+ use consistent format for error messages.
+ plug memory leaks and avoid malloc(0).
+ verbose message should display even when routing table is empty
(flushroutes).


# 1.91 15-Aug-2005 ginsbach

Make sure that a netmask socket address value prints appropriately when the
family is unset. Either the destination or interface address socket address
family value is used. This change prevents the following sort of output:

RTM_NEWADDR: address being added to iface: len 60, metric 0, flags:<UP>
sockaddrs: <NETMASK,IFA,BRD>
(0) 00.00.ff.00.00 127.0.0.1 127.0.0.1

With this change the last line becomes:

255.0.0.0 127.0.0.1 127.0.0.1

Also make sure that when using a generated inet netmask the address family
is set. With this change a generated netmask will print appropriately
when using the verbose (-v) option.


# 1.90 12-Aug-2005 ginsbach

Make sure the get command always exits non-zero on error. This makes things
like the following work as expected.

#!/bin/sh

if ! route -sn get default >/dev/null 2>&1; then
echo default gateway not set
exit 1
fi
echo default gateway set

Handle routing socket write(2) errors when they occur. This produces
better diagnostics by allowing for handling of the special route errno
values ESRCH, EBUSY, and ENOBUFS even with the quiet (-q) option or
when doing a get command.


# 1.89 12-Aug-2005 ginsbach

Trim the local domain name in routename() for INET6 lookups; similar to
INET lookups.


# 1.88 10-Aug-2005 he

Make this build for __GNUC__ <= 2 (i.e. for vax). The cast to
caddr_t removes a const qualifier. Instead, cast the first element
of the subtraction to "struct sockaddr *" to work around the problem.


# 1.87 09-Aug-2005 ginsbach

Accept protocol flags, i.e. -inet, -inet6, with the show command.
[From OpenBSD via DragonFly BSD]


# 1.86 09-Aug-2005 ginsbach

Fix the default case in sodump(). Printing the address of the "which"
string isn't really that useful. Instead print the string and the value
of sa_family.


# 1.85 09-Aug-2005 ginsbach

More style nits (KNF); casts and sizeof's are not followed by a space.


# 1.84 20-Jul-2005 ginsbach

switch is not a function, so add a space; sort switch elements
alphabetically (KNF).


# 1.83 15-Jul-2005 ginsbach

* Exit non-zero error code when flushroute() fails operating on the
routing socket, e.g. running route flush as non-root.

* When quiet (-q) don't append error string to a non-existent
diagnostic output (stdout). The error diagnostic is still written
to stderr. [from FreeBSD]

* Use warn(3) in place of perror(3).


# 1.82 26-Jun-2005 christos

const poisoning.


# 1.81 25-Jun-2005 dyoung

Teach route(8) to print the messages generated by net80211.


# 1.80 19-May-2005 ginsbach

Convert prefixlen() to ANSI function declaration. Missed by earlier
conversion.


# 1.79 19-May-2005 ginsbach

Due to a limitation in inet_addr(3) it was not possible to specify a
netmask value of 0xffffffff (INADDR_NONE). Fix by using inet_aton(3).
Note it was possible to specify the same mask as the dotted quad
255.255.255.255 because of a later call to gethostbyname(3).
[From FreeBSD]


# 1.78 13-May-2005 ginsbach

Fix botched prior commit. Additional debugging error messages mistakenly
committed.


# 1.77 12-May-2005 ginsbach

* Honor -net when using CIDR (net/mask) notation. This differs
from the default CIDR (host/mask) interpretation. As discussed on
tech-net.

* Use errx() in place of fprintf() and exit(). Make the error message
formats consistent.


# 1.76 10-May-2005 ginsbach

Fix macro NEXTADDR so that the names, like so_dst, are printed
rather than u. The preprocessor doesn't do replacement within
strings, so the # string creation operator must be used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.75 05-Feb-2005 xtraeme

Kill __P(), use ANSI function declarations.


# 1.74 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


# 1.73 15-May-2004 itojun

bump buffer size for any_ntoa(), for huge sa_len


# 1.72 15-May-2004 itojun

2-byte read overrun for unknown sockaddr. from openbsd
XXX out[64], is it safe? what if sa_len > 23?


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.71 05-Jan-2004 jmmv

Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.


# 1.70 01-Oct-2003 itojun

print prefixlen on -show


# 1.69 16-Sep-2003 cube

Remove a comment that referred to a non-committed part of the patch I
submitted for bin/17613. Ok'd by mrg@.


# 1.68 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.


# 1.67 19-Jul-2003 jrf

This is an updated submitted patch originally written by Jim Rees
and sent in by Greg Hudson as seen in PR misc/3227. Basically what it
does is adds a flushall option which deletes all but localhost routes.
This is done by andoring in a flag called doall (1 means do all routes
including gateway, 0 means do a regular flush). I have seen some
platforms that do this. I tested it out on ipv4 only, it works as
advertised. Commit was approved by christos@.


# 1.66 11-Jun-2003 christos

PR/21856: Robert Elz: Changes to route(8) to allow /n instead of -prefixlen
for INET6


# 1.65 03-Jun-2003 itojun

permit foo/bar notation, like "route add 10.0.0.0/8 127.0.0.1".
originally by provos


# 1.64 17-May-2003 itojun

strlcpy [a few mistakes found]


# 1.63 21-Apr-2003 jrf

This addresses PR 17613 when certain methods of adding routes would
muck up the routing tables. The patch was submitted by Quentin Garnier
<netbsd@quatriemek.com> and tweaked a little after it was reviewed
by Christos Zoulas <christos@netbsd.org>. Final change/commit approved
by Christos.


# 1.62 03-Apr-2003 jrf

Made a note in the code about the -d and -d options brought up in
PR 18674. Thanks to Chris Jones for pointing it out.


Revision tags: fvdl_fs64_base
# 1.61 18-Oct-2002 itojun

correct prefixlen handling for IPv4.


# 1.60 18-Oct-2002 itojun

Make prefixlen check to make sure its argument is present before deref
from openbsd


# 1.59 20-Jul-2002 grant

sweep of errx/warnx, remove unnecessary trailing \n


# 1.58 10-Jun-2002 itojun

permit DNS names to address portion. they will be considered as RTF_HOST
if specified as destination (as there's no getnetbyname in IPv6).


# 1.57 05-Jun-2002 itojun

if we're unsure about prefixlen, don't say "128".


# 1.56 05-Jun-2002 itojun

more correct ion to RTF_HOST handling.


# 1.55 04-Jun-2002 itojun

do not have -prefixlen 128 on RTF_HOST.
From: Dawid Szymanski <dawszy@arhea.net>


Revision tags: netbsd-1-6-base
# 1.54 20-May-2002 itojun

branches: 1.54.2;
raise RTF_HOST if destination is a host (/128). from ume


# 1.53 21-Feb-2002 christos

PR/15672: Love: route monitor missing info


# 1.52 15-Nov-2001 christos

Make route exit with a non-zero error code when operations to the routing
socket fails. eg, running route add 1.2.3.4 5.6.7.8 as non root.


# 1.51 02-Nov-2001 lukem

fix -Wshadow warnings


# 1.50 24-Oct-2001 atatat

Provide a short output format for the get command that only prints the
address corresponding to RTA_GATEWAY, or nothing if it doesn't exist.
Modify the exit value of route depending on this, so that one can do
stuff like:

#!/bin/sh
gw=`route -sn get default 2>/dev/null`
if [ -z "$gw" ]; then
echo no default route
exit 1
fi
ping -w1 -c1 $gw >/dev/null 2>&1
if ! route -sn get $gw >/dev/null; then
echo default gateway not responding
exit 1
fi
echo default gateway is at $gw


# 1.49 24-Oct-2001 atatat

Print a R on reject routes to indicate that they're not normal routes,
and check netmask (or prefix) length as well as the destination
address when determining if a route is a "default" or not. This means
that the output from 'route show' will no longer say:

Internet6:
Destination Gateway Flags
default localhost UG
default localhost UG

but instead

Internet6:
Destination Gateway Flags
::/104 localhost UGR
::/96 localhost UGR

which makes much more sense.


# 1.48 20-Jul-2001 itojun

off-by-one error in -prefixlen arg validation (do not permit 129 on IPv6)


# 1.47 20-Jul-2001 itojun

make prefixlen work on IPv4 too


# 1.46 16-Jul-2001 bad

The way pmsg_addrs() is used requires that it always prints a newline and
flushes stdout before returning.

Previously the decoded output for a message was stuck in stdio buffers until
the next arrived.


# 1.45 19-Feb-2001 cgd

convert to use getprogname()


# 1.44 04-Feb-2001 christos

remove nested externs.


# 1.43 27-Jan-2001 itojun

support -cloned command line flag.
i don't think anyone ever going to use it.


# 1.42 27-Jan-2001 itojun

mark cloned routes with RTF_CLONED. present it with netstat -r by "c".

let static routes overwrite cloned routes, as cloned routes can come back again
if necessary. behavior same as freebsd/bsdi, code partially from bsdi42.
(NRL rt->rt_parent was not added)
should fix PR 11916 and maybe some other PRs with ARP behavior.

recompilation of usr.sbin/route6d is suggested.


# 1.41 27-Jan-2001 itojun

support RTF_BLACKHOLE.

XXX route show is total duplicate of netstat -r, we need to either remove
route show, or share the same source code, otherwise maintenance cost
bites (and is biting) us


# 1.40 27-Jan-2001 itojun

remove use of uninitialized route (struct ortentry).
it seems that the bug was born during 4.3reno -> 4.4Lite1 transition.


# 1.39 10-Oct-2000 itojun

on "route monitor", print RTM_IFANNOUNCE, RTM_IFINFO (new #), and others.


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.38 04-May-2000 sommerfeld

branches: 1.38.4;
Allow INET6 to be used with SMALL without undefined symbols


# 1.37 20-Apr-2000 itojun

use scoped notation for link-local multicast too.


# 1.36 20-Apr-2000 itojun

support extended scoped address notation (fe80::1%de0).
it hides implementation detail (embedded ifid) from the users.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.35 03-Dec-1999 itojun

don't make "-prefixlen 64" a default in -inet6 case. the past behavior
was not compatible with past practice ("route get" did not work right).

sync with recent KAME.


Revision tags: comdex-fall-1999-base
# 1.34 01-Nov-1999 sommerfeld

Display local address associated with route (if any) in "route get".


# 1.33 03-Sep-1999 itojun

branches: 1.33.2;
fix alignment issue in routing socket data, on 64bit arch (i.e. alpha).
sockaddrs are packed with ROUNDUP() in sys/net/rtsock.c so userland
programs needs to follow that.

PR: 8179


# 1.32 06-Jul-1999 mjacob

Incorrect integration. ctime takes a time_t value, not a long.


# 1.31 02-Jul-1999 itojun

IPv6-ready route command (-inet6 and -prefixlen are added)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.30 23-Oct-1998 lukem

branches: 1.30.2;
* implement -f; flush all routes before executing command
* reset af to 0 in flushroutes() and newroute()
* cleanup -DSMALL:
- `flush' and AF_APPLETALK is supported (the latter had partial support)
- AF_NS, AF_ISO, and AF_CCITT are not supported at all (rather than being
- partially unsupported).


# 1.29 26-Jul-1998 mycroft

const poisoning.


# 1.28 01-Apr-1998 kleink

Need <time.h> for time() prototype.


# 1.27 05-Feb-1998 ross

64-bit sweep, "route -v show" was spinning forever.


# 1.26 16-Nov-1997 christos

Use {warn,err}{,x}(3) instead of printf's


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 01-Oct-1997 enami

Don't declare optind.


# 1.24 16-Sep-1997 lukem

resolve conflicts from lite-2 import


# 1.23 15-Sep-1997 lukem

* cleanup for WARNS=1
* use .Nm correctly
* deprecate register
* getopt returns -1 not EOF


# 1.22 02-Sep-1997 thorpej

Fix uninitialized pointer botch when attempting to flush an already
empty routing table. From Matthias Scheler <tron@lyssa.owl.de>, in
PR #4074.


# 1.21 27-Apr-1997 thorpej

Don't SEGV if a qualifier is passed without an argument. From
Geoff Wing <mason@primenet.com.au>, fixes PR #2700.


# 1.20 21-Apr-1997 mrg

KNF. be safe with buffers.


# 1.19 03-Apr-1997 christos

- Add netatalk bits
- Add prototypes
- Fix printf formats


# 1.18 22-Feb-1997 carrel

Remove uid checks since the kernel now handles this and route(1) is no
longer setuid.
Document the "Permission denied" msg in the man page since this is
_slightly_ less clear than route(1)'s old error msg.


# 1.17 15-Nov-1996 gwr

As discussed some time ago, add a "show" sub-command.
Also allow compilation with -DSMALL to ommit support for
non-essential protocols (i.e. when built into a ramdisk).
Use a less hack-ish way to generate keywords.[ch] and just
check in the result (helps ../../distrib/utils/x_route).


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.16 15-Apr-1996 cgd

check returns of inet_addr() and inet_network() against INADDR_NONE,
not -1, per the manual page. on 64-bit systems like the alpha, -1 will
never equal (unsigned long)INADDR_NONE.


# 1.15 07-Jan-1996 pk

Produce less output on -q as promised by the man page (John Hawkinson; PR#998).


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.14 20-Apr-1995 mycroft

Interface-specific routes can be static.


# 1.13 20-Apr-1995 mycroft

Implement the document `-llinfo' flag.


# 1.12 18-Apr-1995 mycroft

Remove extra `break;'.


# 1.11 18-Mar-1995 cgd

convert to new RCS Id conventions; reduce my headache


# 1.10 24-Dec-1994 cgd

kill some extraneous equal signs.


# 1.9 23-Sep-1994 mycroft

Remove some more uses of obsolete functions.


# 1.8 23-Sep-1994 mycroft

Eliminate uses of some obsolete functions.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.7 13-May-1994 mycroft

Clean up import.


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 25-Apr-1993 mycroft

Compile X.25, OSI, and NS code.


# 1.4 18-Apr-1993 mycroft

Cleanup for GCC 2.


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.3 23-Mar-1993 cgd

changed "Id" to "Header" for rcsids


# 1.2 22-Mar-1993 cgd

added rcs ids to all files


# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
Initial revision


# 1.168 02-Apr-2020 christos

Add a prog_setsockopt (thanks kre@)


# 1.167 14-Mar-2020 roy

route: Enable receive error reporting on the routing socket


# 1.166 22-Feb-2020 kamil

Avoid undefined behavior

route.c:1523:20, left shift of 1073741824 by 1 places cannot be represented
in type 'int'


# 1.165 22-Jan-2020 roy

route: address flags are more useful than interface flags for address msgs


# 1.164 22-Jan-2020 roy

route: Decode the correct flags for interface address messages


Revision tags: phil-wifi-20191119
# 1.163 02-Sep-2019 roy

route(8): Show addres for RTM_LOSING

While here, add /* FALLTHROUGH */.


# 1.162 31-Aug-2019 roy

route(8): show addrs for RTM_MISS


# 1.161 22-Aug-2019 roy

route(8): print RTM_CHANGE messages

XXX Pullup -9


Revision tags: netbsd-9-base phil-wifi-20190609 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906
# 1.160 14-Aug-2018 roy

branches: 1.160.2;
Resolve every route(4) message type before printing anything more about it
other than the type and length.

This solves the issue where RTM_ONEWADDR is received and it tries to
parse route information from it.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330
# 1.159 23-Mar-2018 roy

branches: 1.159.2;
Handle the routing socket overflowing gracefully.


Revision tags: pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.158 13-Dec-2017 christos

branches: 1.158.2;
Use the definitions from the standard header files and replace homebrew
snprintb with the libutil one.


# 1.157 13-Dec-2017 uwe

Fix typo in flag name. We should probably just use IFFBITS string
that <net/if.h> defines.

PR bin/52815


Revision tags: perseant-stdc-iso10646-base
# 1.156 16-Jun-2017 ozaki-r

Support -c <count> option for route monitor

route command exits if it receives <count> routing messages where
<count> is a value specified by -c.

The option is useful to get only particular message(s) in a test script.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320
# 1.155 17-Mar-2017 roy

branches: 1.155.4;
Report the PID for the process changing the address.


Revision tags: bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.154 04-Apr-2016 ozaki-r

branches: 1.154.2; 1.154.4;
Separate nexthop caches from the routing table

By this change, nexthop caches (IP-MAC address pair) are not stored
in the routing table anymore. Instead nexthop caches are stored in
each network interface; we already have lltable/llentry data structure
for this purpose. This change also obsoletes the concept of cloning/cloned
routes. Cloned routes no longer exist while cloning routes still exist
with renamed to connected routes.

Noticeable changes are:
- Nexthop caches aren't listed in route show/netstat -r
- sysctl(NET_RT_DUMP) doesn't return them
- If RTF_LLDATA is specified, it returns nexthop caches
- Several definitions of routing flags and messages are removed
- RTF_CLONING, RTF_XRESOLVE, RTF_LLINFO, RTF_CLONED and RTM_RESOLVE
- RTF_CONNECTED is added
- It has the same value of RTF_CLONING for backward compatibility
- route's -xresolve, -[no]cloned and -llinfo options are removed
- -[no]cloning remains because it seems there are users
- -[no]connected is introduced and recommended
to be used instead of -[no]cloning
- route show/netstat -r drops some flags
- 'L' and 'c' are not seen anymore
- 'C' now indicates a connected route
- Gateway value of a route of an interface address is now not
a L2 address but "link#N" like a connected (cloning) route
- Proxy ARP: "arp -s ... pub" doesn't create a route

You can know details of behavior changes by seeing diffs under tests/.

Proposed on tech-net and tech-kern:
http://mail-index.netbsd.org/tech-net/2016/03/11/msg005701.html


# 1.153 23-Jan-2016 christos

no need for <sys/mbuf.h>


# 1.152 17-Jan-2016 christos

PR/50671: David Binderman: fix memory leak.


# 1.151 23-Mar-2015 roy

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.


# 1.150 26-Feb-2015 roy

Teach route(8) about RTF_LOCAL.


# 1.149 20-Dec-2014 prlw1

MKINET6=no build fixes

http://mail-index.netbsd.org/tech-net/2014/12/13/msg004898.html


# 1.148 17-Dec-2014 roy

Note that RTM_CHANGE can also change the gateway


# 1.147 12-Nov-2014 christos

PR/47704: Takahiro HAYASHI: Add -L flag


# 1.146 07-Nov-2014 christos

Now that the code can support tags and verbose route printing, enable them.
Also document previously undocumented flags.


# 1.145 06-Nov-2014 christos

Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.144 19-Oct-2013 christos

branches: 1.144.4;
use correct function


# 1.143 19-Oct-2013 christos

use symbolic flags


# 1.142 19-Oct-2013 christos

use scopeid functions


# 1.141 18-Oct-2013 christos

avoid pointer gymnastics


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.140 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.139 04-Oct-2012 uwe

Fix fallout from 1.129 that converted sou::so_foo from unions to
pointers but missed (char *)&soup->so_foo => (char *)soup->so_foo in
mask_addr(). It worked by luck - unless it didn't: due to pointer
numerology on amd64 route add -net ClassC without explicit /24 prefix
length specification would result into /16 destination instead of /24.


# 1.138 08-Aug-2012 christos

branches: 1.138.2;
remove useless rump headers.


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.137 17-Mar-2012 christos

PR/42179: Christoph Badura: Be a little friendlier about missing args.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.136 26-Dec-2011 christos

branches: 1.136.2;
Off by one and clarity improvement from Christian Biere


# 1.135 24-Dec-2011 christos

PR/45661: Henning Petersen: Overlapping buffer in route.c.


# 1.134 11-Nov-2011 gdt

Move RTF_ANNOUNCE flag so that it no longer conflicts with RTF_PROTO2.

RTF_ANNOUNCE was defined as RTF_PROTO2. The flag is used to indicated
that host should act as a proxy for a link level arp or ndp request.
(If RTF_PROTO2 is used as an experimental flag (as advertised),
various problems can occur.)

This commit provides a first-class definition with its own bit for
RTF_ANNOUNCE, removes the old aliasing definitions, and adds support
for the new RTF_ANNOUNCE flag to netstat(8) and route(8).,

Also, remove unused RTF_ flags that collide with RTF_PROTO1:
netinet/icmp6.h defined RTF_PROBEMTU as RTF_PROTO1
netinet/if_inarp.h defined RTF_USETRAILERS as RTF_PROTO1
(Neither of these flags are used anywhere. Both have been removed
to reduce chances of collision with RTF_PROTO1.)

Figuring this out and the diff are the work of Beverly Schwartz of
BBN.

(Passed release build, boot in VM, with no apparently related atf
failures.)

Approved for Public Release, Distribution Unlimited
This material is based upon work supported by the Defense Advanced
Research Projects Agency and Space and Naval Warfare Systems Center,
Pacific, under Contract No. N66001-09-C-2073.


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.133 07-Oct-2011 joerg

branches: 1.133.2;
Simplify.


# 1.132 29-Aug-2011 joerg

Use __dead


# 1.131 01-Jul-2011 joerg

Fix memset usage.


# 1.130 22-Jun-2011 kefren

don't compile tag functions if SMALL is defined. Should fix the build


# 1.129 21-Jun-2011 kefren

Alloc dynamically sockunions in sou.
Teach route(8) about multiple tags. E.G.: -tag 100,20,33
XXX: needs documentation


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.128 01-Feb-2011 matt

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.


Revision tags: matt-mips64-premerge-20101231
# 1.127 13-Dec-2010 pooka

branches: 1.127.2;
Convert from RUMP_ACTION to RUMPPRG.


# 1.126 12-Nov-2010 roy

Support the new RTM_IFINFO and RTM_CHGADDR messages.


# 1.125 05-Nov-2010 pooka

adapt to new rumpclient_init() signature


# 1.124 04-Nov-2010 pooka

#ifdef variable correctly


# 1.123 04-Nov-2010 pooka

be consistent in what to leave outside of SMALL


# 1.122 04-Nov-2010 pooka

Support RUMP_ACTION to compile a rump kernel client.


# 1.121 26-Jun-2010 kefren

add MPLS clue - mpls and tag keywords


# 1.120 12-May-2010 christos

PR/40455: Mihai Chelaru: Add noreject noblackhole options


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base mjf-devfs2-base
# 1.119 28-Dec-2008 christos

parse unsigned long with strtoul not atoi


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3
# 1.118 10-Sep-2008 dyoung

branches: 1.118.6;
Get the socket addresses for dst/gateway/netmask/interface/ifaddr
out of the global namespace.


# 1.117 10-Sep-2008 dyoung

Don't cast a sockunion * to sockaddr *. Instead, reference the
sockaddr inside of the sockunion.


# 1.116 10-Sep-2008 dyoung

Delete superfluous casts to void *.


# 1.115 10-Sep-2008 dyoung

Constify.


# 1.114 10-Sep-2008 dyoung

Constify.


# 1.113 10-Sep-2008 dyoung

Constify.

For clarity's sake, do not assign a new value to inet_makenetandmask()'s
argument, `inet'.


# 1.112 09-Sep-2008 dyoung

Extract subroutine extract_addrs() for reuse, later.

Replace the anonymous constant, 0, with AF_UNSPEC.


# 1.111 09-Sep-2008 dyoung

Constify.


# 1.110 09-Sep-2008 dyoung

Shorten a staircase. Remove superfluous parentheses from return
statements. Constify.


# 1.109 09-Sep-2008 dyoung

Use a union and sizeof() to avoid a cast and an anonymous constant
buffer length, respectively.


# 1.108 09-Sep-2008 dyoung

Use bool.


Revision tags: wrstuden-revivesa-base-2
# 1.107 20-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking cube-autoconf-base mjf-devfs-base matt-armv6-base matt-mips64-base hpcarm-cleanup-base
# 1.106 18-Feb-2007 hubertf

branches: 1.106.12; 1.106.16;
TSEL() is const char* now


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base netbsd-4-base
# 1.105 11-Nov-2006 apb

Fix a bug that caused 0.0.0.0/0 to be treated like 0.0.0.0/32.

foo << 32 is undefined per section 6.5.7 of the C99 standard
if foo is (or is promoted to) a 32-bit type.


# 1.104 23-Sep-2006 dyoung

Let us qualify 'route flush' and 'route show' commands with -llinfo
and -host flags, which is useful for displaying/flushing ARP entries:

# route -n show -inet -llinfo -host
Routing table

Internet:
Destination Gateway Flags
169.254.1.119 link#1 UH
169.254.230.110 00:02:6f:21:e6:6e UH
# route -n flush -inet -llinfo -host
169.254.1.119 done
169.254.230.110 0.2.6f.21.e6.6e done
169.254.237.70 done
# route -n show -inet -llinfo -host
Routing table
#

This will help me address bin/11079, "dhclient may require arp and sed".

Extract common code from flushroutes() and show(), creating
parse_show_opts().

While I'm here, make small cosmetic changes to flushroutes().


# 1.103 23-Sep-2006 dyoung

Move the #ifndef SMALL code together.


# 1.102 23-Sep-2006 dyoung

Use the symbol AF_UNSPEC instead of 0 as appropriate.


# 1.101 23-Sep-2006 dyoung

Remove dead code.


# 1.100 26-Aug-2006 matt

Remove XNS and CCITT/X25 bits.


Revision tags: abandoned-netbsd-4-base
# 1.99 06-Aug-2006 dyoung

KNF err(3), errx(3) usage, indentation, braces.


# 1.98 06-Aug-2006 dyoung

Add route keywords -nocloned, -nocloning.


# 1.97 29-Jan-2006 wiz

Use default option order (AaBbCc...).


# 1.96 26-Jan-2006 is

Print the INET netmask if it is non-contiguous.


# 1.95 25-Jan-2006 christos

PR/32632: Yves-Emmanuel JUTARD: Improvment suggestion in 'route' display.
Add a new -S flag that prints a space for missing flags.


# 1.94 25-Jan-2006 christos

PR/32629: Yves-Emmanuel JUTARD: Type errors in sbin/route/route.c, another
u_char/char conflict.


# 1.93 31-Aug-2005 ginsbach

Add full IPv6 syntax support when route is built with -DSMALL and -DINET6.
Fixes PR/23937. Adapted from supplied patch.


# 1.92 30-Aug-2005 ginsbach

Clean up some minor nits:
+ style (KNF).
. don't cast NULL
. white space clean up
+ use consistent format for error messages.
+ plug memory leaks and avoid malloc(0).
+ verbose message should display even when routing table is empty
(flushroutes).


# 1.91 15-Aug-2005 ginsbach

Make sure that a netmask socket address value prints appropriately when the
family is unset. Either the destination or interface address socket address
family value is used. This change prevents the following sort of output:

RTM_NEWADDR: address being added to iface: len 60, metric 0, flags:<UP>
sockaddrs: <NETMASK,IFA,BRD>
(0) 00.00.ff.00.00 127.0.0.1 127.0.0.1

With this change the last line becomes:

255.0.0.0 127.0.0.1 127.0.0.1

Also make sure that when using a generated inet netmask the address family
is set. With this change a generated netmask will print appropriately
when using the verbose (-v) option.


# 1.90 12-Aug-2005 ginsbach

Make sure the get command always exits non-zero on error. This makes things
like the following work as expected.

#!/bin/sh

if ! route -sn get default >/dev/null 2>&1; then
echo default gateway not set
exit 1
fi
echo default gateway set

Handle routing socket write(2) errors when they occur. This produces
better diagnostics by allowing for handling of the special route errno
values ESRCH, EBUSY, and ENOBUFS even with the quiet (-q) option or
when doing a get command.


# 1.89 12-Aug-2005 ginsbach

Trim the local domain name in routename() for INET6 lookups; similar to
INET lookups.


# 1.88 10-Aug-2005 he

Make this build for __GNUC__ <= 2 (i.e. for vax). The cast to
caddr_t removes a const qualifier. Instead, cast the first element
of the subtraction to "struct sockaddr *" to work around the problem.


# 1.87 09-Aug-2005 ginsbach

Accept protocol flags, i.e. -inet, -inet6, with the show command.
[From OpenBSD via DragonFly BSD]


# 1.86 09-Aug-2005 ginsbach

Fix the default case in sodump(). Printing the address of the "which"
string isn't really that useful. Instead print the string and the value
of sa_family.


# 1.85 09-Aug-2005 ginsbach

More style nits (KNF); casts and sizeof's are not followed by a space.


# 1.84 20-Jul-2005 ginsbach

switch is not a function, so add a space; sort switch elements
alphabetically (KNF).


# 1.83 15-Jul-2005 ginsbach

* Exit non-zero error code when flushroute() fails operating on the
routing socket, e.g. running route flush as non-root.

* When quiet (-q) don't append error string to a non-existent
diagnostic output (stdout). The error diagnostic is still written
to stderr. [from FreeBSD]

* Use warn(3) in place of perror(3).


# 1.82 26-Jun-2005 christos

const poisoning.


# 1.81 25-Jun-2005 dyoung

Teach route(8) to print the messages generated by net80211.


# 1.80 19-May-2005 ginsbach

Convert prefixlen() to ANSI function declaration. Missed by earlier
conversion.


# 1.79 19-May-2005 ginsbach

Due to a limitation in inet_addr(3) it was not possible to specify a
netmask value of 0xffffffff (INADDR_NONE). Fix by using inet_aton(3).
Note it was possible to specify the same mask as the dotted quad
255.255.255.255 because of a later call to gethostbyname(3).
[From FreeBSD]


# 1.78 13-May-2005 ginsbach

Fix botched prior commit. Additional debugging error messages mistakenly
committed.


# 1.77 12-May-2005 ginsbach

* Honor -net when using CIDR (net/mask) notation. This differs
from the default CIDR (host/mask) interpretation. As discussed on
tech-net.

* Use errx() in place of fprintf() and exit(). Make the error message
formats consistent.


# 1.76 10-May-2005 ginsbach

Fix macro NEXTADDR so that the names, like so_dst, are printed
rather than u. The preprocessor doesn't do replacement within
strings, so the # string creation operator must be used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.75 05-Feb-2005 xtraeme

Kill __P(), use ANSI function declarations.


# 1.74 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


# 1.73 15-May-2004 itojun

bump buffer size for any_ntoa(), for huge sa_len


# 1.72 15-May-2004 itojun

2-byte read overrun for unknown sockaddr. from openbsd
XXX out[64], is it safe? what if sa_len > 23?


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.71 05-Jan-2004 jmmv

Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.


# 1.70 01-Oct-2003 itojun

print prefixlen on -show


# 1.69 16-Sep-2003 cube

Remove a comment that referred to a non-committed part of the patch I
submitted for bin/17613. Ok'd by mrg@.


# 1.68 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.


# 1.67 19-Jul-2003 jrf

This is an updated submitted patch originally written by Jim Rees
and sent in by Greg Hudson as seen in PR misc/3227. Basically what it
does is adds a flushall option which deletes all but localhost routes.
This is done by andoring in a flag called doall (1 means do all routes
including gateway, 0 means do a regular flush). I have seen some
platforms that do this. I tested it out on ipv4 only, it works as
advertised. Commit was approved by christos@.


# 1.66 11-Jun-2003 christos

PR/21856: Robert Elz: Changes to route(8) to allow /n instead of -prefixlen
for INET6


# 1.65 03-Jun-2003 itojun

permit foo/bar notation, like "route add 10.0.0.0/8 127.0.0.1".
originally by provos


# 1.64 17-May-2003 itojun

strlcpy [a few mistakes found]


# 1.63 21-Apr-2003 jrf

This addresses PR 17613 when certain methods of adding routes would
muck up the routing tables. The patch was submitted by Quentin Garnier
<netbsd@quatriemek.com> and tweaked a little after it was reviewed
by Christos Zoulas <christos@netbsd.org>. Final change/commit approved
by Christos.


# 1.62 03-Apr-2003 jrf

Made a note in the code about the -d and -d options brought up in
PR 18674. Thanks to Chris Jones for pointing it out.


Revision tags: fvdl_fs64_base
# 1.61 18-Oct-2002 itojun

correct prefixlen handling for IPv4.


# 1.60 18-Oct-2002 itojun

Make prefixlen check to make sure its argument is present before deref
from openbsd


# 1.59 20-Jul-2002 grant

sweep of errx/warnx, remove unnecessary trailing \n


# 1.58 10-Jun-2002 itojun

permit DNS names to address portion. they will be considered as RTF_HOST
if specified as destination (as there's no getnetbyname in IPv6).


# 1.57 05-Jun-2002 itojun

if we're unsure about prefixlen, don't say "128".


# 1.56 05-Jun-2002 itojun

more correct ion to RTF_HOST handling.


# 1.55 04-Jun-2002 itojun

do not have -prefixlen 128 on RTF_HOST.
From: Dawid Szymanski <dawszy@arhea.net>


Revision tags: netbsd-1-6-base
# 1.54 20-May-2002 itojun

branches: 1.54.2;
raise RTF_HOST if destination is a host (/128). from ume


# 1.53 21-Feb-2002 christos

PR/15672: Love: route monitor missing info


# 1.52 15-Nov-2001 christos

Make route exit with a non-zero error code when operations to the routing
socket fails. eg, running route add 1.2.3.4 5.6.7.8 as non root.


# 1.51 02-Nov-2001 lukem

fix -Wshadow warnings


# 1.50 24-Oct-2001 atatat

Provide a short output format for the get command that only prints the
address corresponding to RTA_GATEWAY, or nothing if it doesn't exist.
Modify the exit value of route depending on this, so that one can do
stuff like:

#!/bin/sh
gw=`route -sn get default 2>/dev/null`
if [ -z "$gw" ]; then
echo no default route
exit 1
fi
ping -w1 -c1 $gw >/dev/null 2>&1
if ! route -sn get $gw >/dev/null; then
echo default gateway not responding
exit 1
fi
echo default gateway is at $gw


# 1.49 24-Oct-2001 atatat

Print a R on reject routes to indicate that they're not normal routes,
and check netmask (or prefix) length as well as the destination
address when determining if a route is a "default" or not. This means
that the output from 'route show' will no longer say:

Internet6:
Destination Gateway Flags
default localhost UG
default localhost UG

but instead

Internet6:
Destination Gateway Flags
::/104 localhost UGR
::/96 localhost UGR

which makes much more sense.


# 1.48 20-Jul-2001 itojun

off-by-one error in -prefixlen arg validation (do not permit 129 on IPv6)


# 1.47 20-Jul-2001 itojun

make prefixlen work on IPv4 too


# 1.46 16-Jul-2001 bad

The way pmsg_addrs() is used requires that it always prints a newline and
flushes stdout before returning.

Previously the decoded output for a message was stuck in stdio buffers until
the next arrived.


# 1.45 19-Feb-2001 cgd

convert to use getprogname()


# 1.44 04-Feb-2001 christos

remove nested externs.


# 1.43 27-Jan-2001 itojun

support -cloned command line flag.
i don't think anyone ever going to use it.


# 1.42 27-Jan-2001 itojun

mark cloned routes with RTF_CLONED. present it with netstat -r by "c".

let static routes overwrite cloned routes, as cloned routes can come back again
if necessary. behavior same as freebsd/bsdi, code partially from bsdi42.
(NRL rt->rt_parent was not added)
should fix PR 11916 and maybe some other PRs with ARP behavior.

recompilation of usr.sbin/route6d is suggested.


# 1.41 27-Jan-2001 itojun

support RTF_BLACKHOLE.

XXX route show is total duplicate of netstat -r, we need to either remove
route show, or share the same source code, otherwise maintenance cost
bites (and is biting) us


# 1.40 27-Jan-2001 itojun

remove use of uninitialized route (struct ortentry).
it seems that the bug was born during 4.3reno -> 4.4Lite1 transition.


# 1.39 10-Oct-2000 itojun

on "route monitor", print RTM_IFANNOUNCE, RTM_IFINFO (new #), and others.


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.38 04-May-2000 sommerfeld

branches: 1.38.4;
Allow INET6 to be used with SMALL without undefined symbols


# 1.37 20-Apr-2000 itojun

use scoped notation for link-local multicast too.


# 1.36 20-Apr-2000 itojun

support extended scoped address notation (fe80::1%de0).
it hides implementation detail (embedded ifid) from the users.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.35 03-Dec-1999 itojun

don't make "-prefixlen 64" a default in -inet6 case. the past behavior
was not compatible with past practice ("route get" did not work right).

sync with recent KAME.


Revision tags: comdex-fall-1999-base
# 1.34 01-Nov-1999 sommerfeld

Display local address associated with route (if any) in "route get".


# 1.33 03-Sep-1999 itojun

branches: 1.33.2;
fix alignment issue in routing socket data, on 64bit arch (i.e. alpha).
sockaddrs are packed with ROUNDUP() in sys/net/rtsock.c so userland
programs needs to follow that.

PR: 8179


# 1.32 06-Jul-1999 mjacob

Incorrect integration. ctime takes a time_t value, not a long.


# 1.31 02-Jul-1999 itojun

IPv6-ready route command (-inet6 and -prefixlen are added)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.30 23-Oct-1998 lukem

branches: 1.30.2;
* implement -f; flush all routes before executing command
* reset af to 0 in flushroutes() and newroute()
* cleanup -DSMALL:
- `flush' and AF_APPLETALK is supported (the latter had partial support)
- AF_NS, AF_ISO, and AF_CCITT are not supported at all (rather than being
- partially unsupported).


# 1.29 26-Jul-1998 mycroft

const poisoning.


# 1.28 01-Apr-1998 kleink

Need <time.h> for time() prototype.


# 1.27 05-Feb-1998 ross

64-bit sweep, "route -v show" was spinning forever.


# 1.26 16-Nov-1997 christos

Use {warn,err}{,x}(3) instead of printf's


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 01-Oct-1997 enami

Don't declare optind.


# 1.24 16-Sep-1997 lukem

resolve conflicts from lite-2 import


# 1.23 15-Sep-1997 lukem

* cleanup for WARNS=1
* use .Nm correctly
* deprecate register
* getopt returns -1 not EOF


# 1.22 02-Sep-1997 thorpej

Fix uninitialized pointer botch when attempting to flush an already
empty routing table. From Matthias Scheler <tron@lyssa.owl.de>, in
PR #4074.


# 1.21 27-Apr-1997 thorpej

Don't SEGV if a qualifier is passed without an argument. From
Geoff Wing <mason@primenet.com.au>, fixes PR #2700.


# 1.20 21-Apr-1997 mrg

KNF. be safe with buffers.


# 1.19 03-Apr-1997 christos

- Add netatalk bits
- Add prototypes
- Fix printf formats


# 1.18 22-Feb-1997 carrel

Remove uid checks since the kernel now handles this and route(1) is no
longer setuid.
Document the "Permission denied" msg in the man page since this is
_slightly_ less clear than route(1)'s old error msg.


# 1.17 15-Nov-1996 gwr

As discussed some time ago, add a "show" sub-command.
Also allow compilation with -DSMALL to ommit support for
non-essential protocols (i.e. when built into a ramdisk).
Use a less hack-ish way to generate keywords.[ch] and just
check in the result (helps ../../distrib/utils/x_route).


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.16 15-Apr-1996 cgd

check returns of inet_addr() and inet_network() against INADDR_NONE,
not -1, per the manual page. on 64-bit systems like the alpha, -1 will
never equal (unsigned long)INADDR_NONE.


# 1.15 07-Jan-1996 pk

Produce less output on -q as promised by the man page (John Hawkinson; PR#998).


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.14 20-Apr-1995 mycroft

Interface-specific routes can be static.


# 1.13 20-Apr-1995 mycroft

Implement the document `-llinfo' flag.


# 1.12 18-Apr-1995 mycroft

Remove extra `break;'.


# 1.11 18-Mar-1995 cgd

convert to new RCS Id conventions; reduce my headache


# 1.10 24-Dec-1994 cgd

kill some extraneous equal signs.


# 1.9 23-Sep-1994 mycroft

Remove some more uses of obsolete functions.


# 1.8 23-Sep-1994 mycroft

Eliminate uses of some obsolete functions.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.7 13-May-1994 mycroft

Clean up import.


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 25-Apr-1993 mycroft

Compile X.25, OSI, and NS code.


# 1.4 18-Apr-1993 mycroft

Cleanup for GCC 2.


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.3 23-Mar-1993 cgd

changed "Id" to "Header" for rcsids


# 1.2 22-Mar-1993 cgd

added rcs ids to all files


# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
Initial revision


# 1.167 14-Mar-2020 roy

route: Enable receive error reporting on the routing socket


# 1.166 22-Feb-2020 kamil

Avoid undefined behavior

route.c:1523:20, left shift of 1073741824 by 1 places cannot be represented
in type 'int'


# 1.165 22-Jan-2020 roy

route: address flags are more useful than interface flags for address msgs


# 1.164 22-Jan-2020 roy

route: Decode the correct flags for interface address messages


Revision tags: phil-wifi-20191119
# 1.163 02-Sep-2019 roy

route(8): Show addres for RTM_LOSING

While here, add /* FALLTHROUGH */.


# 1.162 31-Aug-2019 roy

route(8): show addrs for RTM_MISS


# 1.161 22-Aug-2019 roy

route(8): print RTM_CHANGE messages

XXX Pullup -9


Revision tags: netbsd-9-base phil-wifi-20190609 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906
# 1.160 14-Aug-2018 roy

branches: 1.160.2;
Resolve every route(4) message type before printing anything more about it
other than the type and length.

This solves the issue where RTM_ONEWADDR is received and it tries to
parse route information from it.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330
# 1.159 23-Mar-2018 roy

branches: 1.159.2;
Handle the routing socket overflowing gracefully.


Revision tags: pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.158 13-Dec-2017 christos

branches: 1.158.2;
Use the definitions from the standard header files and replace homebrew
snprintb with the libutil one.


# 1.157 13-Dec-2017 uwe

Fix typo in flag name. We should probably just use IFFBITS string
that <net/if.h> defines.

PR bin/52815


Revision tags: perseant-stdc-iso10646-base
# 1.156 16-Jun-2017 ozaki-r

Support -c <count> option for route monitor

route command exits if it receives <count> routing messages where
<count> is a value specified by -c.

The option is useful to get only particular message(s) in a test script.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320
# 1.155 17-Mar-2017 roy

branches: 1.155.4;
Report the PID for the process changing the address.


Revision tags: bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.154 04-Apr-2016 ozaki-r

branches: 1.154.2; 1.154.4;
Separate nexthop caches from the routing table

By this change, nexthop caches (IP-MAC address pair) are not stored
in the routing table anymore. Instead nexthop caches are stored in
each network interface; we already have lltable/llentry data structure
for this purpose. This change also obsoletes the concept of cloning/cloned
routes. Cloned routes no longer exist while cloning routes still exist
with renamed to connected routes.

Noticeable changes are:
- Nexthop caches aren't listed in route show/netstat -r
- sysctl(NET_RT_DUMP) doesn't return them
- If RTF_LLDATA is specified, it returns nexthop caches
- Several definitions of routing flags and messages are removed
- RTF_CLONING, RTF_XRESOLVE, RTF_LLINFO, RTF_CLONED and RTM_RESOLVE
- RTF_CONNECTED is added
- It has the same value of RTF_CLONING for backward compatibility
- route's -xresolve, -[no]cloned and -llinfo options are removed
- -[no]cloning remains because it seems there are users
- -[no]connected is introduced and recommended
to be used instead of -[no]cloning
- route show/netstat -r drops some flags
- 'L' and 'c' are not seen anymore
- 'C' now indicates a connected route
- Gateway value of a route of an interface address is now not
a L2 address but "link#N" like a connected (cloning) route
- Proxy ARP: "arp -s ... pub" doesn't create a route

You can know details of behavior changes by seeing diffs under tests/.

Proposed on tech-net and tech-kern:
http://mail-index.netbsd.org/tech-net/2016/03/11/msg005701.html


# 1.153 23-Jan-2016 christos

no need for <sys/mbuf.h>


# 1.152 17-Jan-2016 christos

PR/50671: David Binderman: fix memory leak.


# 1.151 23-Mar-2015 roy

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.


# 1.150 26-Feb-2015 roy

Teach route(8) about RTF_LOCAL.


# 1.149 20-Dec-2014 prlw1

MKINET6=no build fixes

http://mail-index.netbsd.org/tech-net/2014/12/13/msg004898.html


# 1.148 17-Dec-2014 roy

Note that RTM_CHANGE can also change the gateway


# 1.147 12-Nov-2014 christos

PR/47704: Takahiro HAYASHI: Add -L flag


# 1.146 07-Nov-2014 christos

Now that the code can support tags and verbose route printing, enable them.
Also document previously undocumented flags.


# 1.145 06-Nov-2014 christos

Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.144 19-Oct-2013 christos

branches: 1.144.4;
use correct function


# 1.143 19-Oct-2013 christos

use symbolic flags


# 1.142 19-Oct-2013 christos

use scopeid functions


# 1.141 18-Oct-2013 christos

avoid pointer gymnastics


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.140 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.139 04-Oct-2012 uwe

Fix fallout from 1.129 that converted sou::so_foo from unions to
pointers but missed (char *)&soup->so_foo => (char *)soup->so_foo in
mask_addr(). It worked by luck - unless it didn't: due to pointer
numerology on amd64 route add -net ClassC without explicit /24 prefix
length specification would result into /16 destination instead of /24.


# 1.138 08-Aug-2012 christos

branches: 1.138.2;
remove useless rump headers.


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.137 17-Mar-2012 christos

PR/42179: Christoph Badura: Be a little friendlier about missing args.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.136 26-Dec-2011 christos

branches: 1.136.2;
Off by one and clarity improvement from Christian Biere


# 1.135 24-Dec-2011 christos

PR/45661: Henning Petersen: Overlapping buffer in route.c.


# 1.134 11-Nov-2011 gdt

Move RTF_ANNOUNCE flag so that it no longer conflicts with RTF_PROTO2.

RTF_ANNOUNCE was defined as RTF_PROTO2. The flag is used to indicated
that host should act as a proxy for a link level arp or ndp request.
(If RTF_PROTO2 is used as an experimental flag (as advertised),
various problems can occur.)

This commit provides a first-class definition with its own bit for
RTF_ANNOUNCE, removes the old aliasing definitions, and adds support
for the new RTF_ANNOUNCE flag to netstat(8) and route(8).,

Also, remove unused RTF_ flags that collide with RTF_PROTO1:
netinet/icmp6.h defined RTF_PROBEMTU as RTF_PROTO1
netinet/if_inarp.h defined RTF_USETRAILERS as RTF_PROTO1
(Neither of these flags are used anywhere. Both have been removed
to reduce chances of collision with RTF_PROTO1.)

Figuring this out and the diff are the work of Beverly Schwartz of
BBN.

(Passed release build, boot in VM, with no apparently related atf
failures.)

Approved for Public Release, Distribution Unlimited
This material is based upon work supported by the Defense Advanced
Research Projects Agency and Space and Naval Warfare Systems Center,
Pacific, under Contract No. N66001-09-C-2073.


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.133 07-Oct-2011 joerg

branches: 1.133.2;
Simplify.


# 1.132 29-Aug-2011 joerg

Use __dead


# 1.131 01-Jul-2011 joerg

Fix memset usage.


# 1.130 22-Jun-2011 kefren

don't compile tag functions if SMALL is defined. Should fix the build


# 1.129 21-Jun-2011 kefren

Alloc dynamically sockunions in sou.
Teach route(8) about multiple tags. E.G.: -tag 100,20,33
XXX: needs documentation


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.128 01-Feb-2011 matt

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.


Revision tags: matt-mips64-premerge-20101231
# 1.127 13-Dec-2010 pooka

branches: 1.127.2;
Convert from RUMP_ACTION to RUMPPRG.


# 1.126 12-Nov-2010 roy

Support the new RTM_IFINFO and RTM_CHGADDR messages.


# 1.125 05-Nov-2010 pooka

adapt to new rumpclient_init() signature


# 1.124 04-Nov-2010 pooka

#ifdef variable correctly


# 1.123 04-Nov-2010 pooka

be consistent in what to leave outside of SMALL


# 1.122 04-Nov-2010 pooka

Support RUMP_ACTION to compile a rump kernel client.


# 1.121 26-Jun-2010 kefren

add MPLS clue - mpls and tag keywords


# 1.120 12-May-2010 christos

PR/40455: Mihai Chelaru: Add noreject noblackhole options


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base mjf-devfs2-base
# 1.119 28-Dec-2008 christos

parse unsigned long with strtoul not atoi


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3
# 1.118 10-Sep-2008 dyoung

branches: 1.118.6;
Get the socket addresses for dst/gateway/netmask/interface/ifaddr
out of the global namespace.


# 1.117 10-Sep-2008 dyoung

Don't cast a sockunion * to sockaddr *. Instead, reference the
sockaddr inside of the sockunion.


# 1.116 10-Sep-2008 dyoung

Delete superfluous casts to void *.


# 1.115 10-Sep-2008 dyoung

Constify.


# 1.114 10-Sep-2008 dyoung

Constify.


# 1.113 10-Sep-2008 dyoung

Constify.

For clarity's sake, do not assign a new value to inet_makenetandmask()'s
argument, `inet'.


# 1.112 09-Sep-2008 dyoung

Extract subroutine extract_addrs() for reuse, later.

Replace the anonymous constant, 0, with AF_UNSPEC.


# 1.111 09-Sep-2008 dyoung

Constify.


# 1.110 09-Sep-2008 dyoung

Shorten a staircase. Remove superfluous parentheses from return
statements. Constify.


# 1.109 09-Sep-2008 dyoung

Use a union and sizeof() to avoid a cast and an anonymous constant
buffer length, respectively.


# 1.108 09-Sep-2008 dyoung

Use bool.


Revision tags: wrstuden-revivesa-base-2
# 1.107 20-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking cube-autoconf-base mjf-devfs-base matt-armv6-base matt-mips64-base hpcarm-cleanup-base
# 1.106 18-Feb-2007 hubertf

branches: 1.106.12; 1.106.16;
TSEL() is const char* now


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base netbsd-4-base
# 1.105 11-Nov-2006 apb

Fix a bug that caused 0.0.0.0/0 to be treated like 0.0.0.0/32.

foo << 32 is undefined per section 6.5.7 of the C99 standard
if foo is (or is promoted to) a 32-bit type.


# 1.104 23-Sep-2006 dyoung

Let us qualify 'route flush' and 'route show' commands with -llinfo
and -host flags, which is useful for displaying/flushing ARP entries:

# route -n show -inet -llinfo -host
Routing table

Internet:
Destination Gateway Flags
169.254.1.119 link#1 UH
169.254.230.110 00:02:6f:21:e6:6e UH
# route -n flush -inet -llinfo -host
169.254.1.119 done
169.254.230.110 0.2.6f.21.e6.6e done
169.254.237.70 done
# route -n show -inet -llinfo -host
Routing table
#

This will help me address bin/11079, "dhclient may require arp and sed".

Extract common code from flushroutes() and show(), creating
parse_show_opts().

While I'm here, make small cosmetic changes to flushroutes().


# 1.103 23-Sep-2006 dyoung

Move the #ifndef SMALL code together.


# 1.102 23-Sep-2006 dyoung

Use the symbol AF_UNSPEC instead of 0 as appropriate.


# 1.101 23-Sep-2006 dyoung

Remove dead code.


# 1.100 26-Aug-2006 matt

Remove XNS and CCITT/X25 bits.


Revision tags: abandoned-netbsd-4-base
# 1.99 06-Aug-2006 dyoung

KNF err(3), errx(3) usage, indentation, braces.


# 1.98 06-Aug-2006 dyoung

Add route keywords -nocloned, -nocloning.


# 1.97 29-Jan-2006 wiz

Use default option order (AaBbCc...).


# 1.96 26-Jan-2006 is

Print the INET netmask if it is non-contiguous.


# 1.95 25-Jan-2006 christos

PR/32632: Yves-Emmanuel JUTARD: Improvment suggestion in 'route' display.
Add a new -S flag that prints a space for missing flags.


# 1.94 25-Jan-2006 christos

PR/32629: Yves-Emmanuel JUTARD: Type errors in sbin/route/route.c, another
u_char/char conflict.


# 1.93 31-Aug-2005 ginsbach

Add full IPv6 syntax support when route is built with -DSMALL and -DINET6.
Fixes PR/23937. Adapted from supplied patch.


# 1.92 30-Aug-2005 ginsbach

Clean up some minor nits:
+ style (KNF).
. don't cast NULL
. white space clean up
+ use consistent format for error messages.
+ plug memory leaks and avoid malloc(0).
+ verbose message should display even when routing table is empty
(flushroutes).


# 1.91 15-Aug-2005 ginsbach

Make sure that a netmask socket address value prints appropriately when the
family is unset. Either the destination or interface address socket address
family value is used. This change prevents the following sort of output:

RTM_NEWADDR: address being added to iface: len 60, metric 0, flags:<UP>
sockaddrs: <NETMASK,IFA,BRD>
(0) 00.00.ff.00.00 127.0.0.1 127.0.0.1

With this change the last line becomes:

255.0.0.0 127.0.0.1 127.0.0.1

Also make sure that when using a generated inet netmask the address family
is set. With this change a generated netmask will print appropriately
when using the verbose (-v) option.


# 1.90 12-Aug-2005 ginsbach

Make sure the get command always exits non-zero on error. This makes things
like the following work as expected.

#!/bin/sh

if ! route -sn get default >/dev/null 2>&1; then
echo default gateway not set
exit 1
fi
echo default gateway set

Handle routing socket write(2) errors when they occur. This produces
better diagnostics by allowing for handling of the special route errno
values ESRCH, EBUSY, and ENOBUFS even with the quiet (-q) option or
when doing a get command.


# 1.89 12-Aug-2005 ginsbach

Trim the local domain name in routename() for INET6 lookups; similar to
INET lookups.


# 1.88 10-Aug-2005 he

Make this build for __GNUC__ <= 2 (i.e. for vax). The cast to
caddr_t removes a const qualifier. Instead, cast the first element
of the subtraction to "struct sockaddr *" to work around the problem.


# 1.87 09-Aug-2005 ginsbach

Accept protocol flags, i.e. -inet, -inet6, with the show command.
[From OpenBSD via DragonFly BSD]


# 1.86 09-Aug-2005 ginsbach

Fix the default case in sodump(). Printing the address of the "which"
string isn't really that useful. Instead print the string and the value
of sa_family.


# 1.85 09-Aug-2005 ginsbach

More style nits (KNF); casts and sizeof's are not followed by a space.


# 1.84 20-Jul-2005 ginsbach

switch is not a function, so add a space; sort switch elements
alphabetically (KNF).


# 1.83 15-Jul-2005 ginsbach

* Exit non-zero error code when flushroute() fails operating on the
routing socket, e.g. running route flush as non-root.

* When quiet (-q) don't append error string to a non-existent
diagnostic output (stdout). The error diagnostic is still written
to stderr. [from FreeBSD]

* Use warn(3) in place of perror(3).


# 1.82 26-Jun-2005 christos

const poisoning.


# 1.81 25-Jun-2005 dyoung

Teach route(8) to print the messages generated by net80211.


# 1.80 19-May-2005 ginsbach

Convert prefixlen() to ANSI function declaration. Missed by earlier
conversion.


# 1.79 19-May-2005 ginsbach

Due to a limitation in inet_addr(3) it was not possible to specify a
netmask value of 0xffffffff (INADDR_NONE). Fix by using inet_aton(3).
Note it was possible to specify the same mask as the dotted quad
255.255.255.255 because of a later call to gethostbyname(3).
[From FreeBSD]


# 1.78 13-May-2005 ginsbach

Fix botched prior commit. Additional debugging error messages mistakenly
committed.


# 1.77 12-May-2005 ginsbach

* Honor -net when using CIDR (net/mask) notation. This differs
from the default CIDR (host/mask) interpretation. As discussed on
tech-net.

* Use errx() in place of fprintf() and exit(). Make the error message
formats consistent.


# 1.76 10-May-2005 ginsbach

Fix macro NEXTADDR so that the names, like so_dst, are printed
rather than u. The preprocessor doesn't do replacement within
strings, so the # string creation operator must be used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.75 05-Feb-2005 xtraeme

Kill __P(), use ANSI function declarations.


# 1.74 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


# 1.73 15-May-2004 itojun

bump buffer size for any_ntoa(), for huge sa_len


# 1.72 15-May-2004 itojun

2-byte read overrun for unknown sockaddr. from openbsd
XXX out[64], is it safe? what if sa_len > 23?


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.71 05-Jan-2004 jmmv

Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.


# 1.70 01-Oct-2003 itojun

print prefixlen on -show


# 1.69 16-Sep-2003 cube

Remove a comment that referred to a non-committed part of the patch I
submitted for bin/17613. Ok'd by mrg@.


# 1.68 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.


# 1.67 19-Jul-2003 jrf

This is an updated submitted patch originally written by Jim Rees
and sent in by Greg Hudson as seen in PR misc/3227. Basically what it
does is adds a flushall option which deletes all but localhost routes.
This is done by andoring in a flag called doall (1 means do all routes
including gateway, 0 means do a regular flush). I have seen some
platforms that do this. I tested it out on ipv4 only, it works as
advertised. Commit was approved by christos@.


# 1.66 11-Jun-2003 christos

PR/21856: Robert Elz: Changes to route(8) to allow /n instead of -prefixlen
for INET6


# 1.65 03-Jun-2003 itojun

permit foo/bar notation, like "route add 10.0.0.0/8 127.0.0.1".
originally by provos


# 1.64 17-May-2003 itojun

strlcpy [a few mistakes found]


# 1.63 21-Apr-2003 jrf

This addresses PR 17613 when certain methods of adding routes would
muck up the routing tables. The patch was submitted by Quentin Garnier
<netbsd@quatriemek.com> and tweaked a little after it was reviewed
by Christos Zoulas <christos@netbsd.org>. Final change/commit approved
by Christos.


# 1.62 03-Apr-2003 jrf

Made a note in the code about the -d and -d options brought up in
PR 18674. Thanks to Chris Jones for pointing it out.


Revision tags: fvdl_fs64_base
# 1.61 18-Oct-2002 itojun

correct prefixlen handling for IPv4.


# 1.60 18-Oct-2002 itojun

Make prefixlen check to make sure its argument is present before deref
from openbsd


# 1.59 20-Jul-2002 grant

sweep of errx/warnx, remove unnecessary trailing \n


# 1.58 10-Jun-2002 itojun

permit DNS names to address portion. they will be considered as RTF_HOST
if specified as destination (as there's no getnetbyname in IPv6).


# 1.57 05-Jun-2002 itojun

if we're unsure about prefixlen, don't say "128".


# 1.56 05-Jun-2002 itojun

more correct ion to RTF_HOST handling.


# 1.55 04-Jun-2002 itojun

do not have -prefixlen 128 on RTF_HOST.
From: Dawid Szymanski <dawszy@arhea.net>


Revision tags: netbsd-1-6-base
# 1.54 20-May-2002 itojun

branches: 1.54.2;
raise RTF_HOST if destination is a host (/128). from ume


# 1.53 21-Feb-2002 christos

PR/15672: Love: route monitor missing info


# 1.52 15-Nov-2001 christos

Make route exit with a non-zero error code when operations to the routing
socket fails. eg, running route add 1.2.3.4 5.6.7.8 as non root.


# 1.51 02-Nov-2001 lukem

fix -Wshadow warnings


# 1.50 24-Oct-2001 atatat

Provide a short output format for the get command that only prints the
address corresponding to RTA_GATEWAY, or nothing if it doesn't exist.
Modify the exit value of route depending on this, so that one can do
stuff like:

#!/bin/sh
gw=`route -sn get default 2>/dev/null`
if [ -z "$gw" ]; then
echo no default route
exit 1
fi
ping -w1 -c1 $gw >/dev/null 2>&1
if ! route -sn get $gw >/dev/null; then
echo default gateway not responding
exit 1
fi
echo default gateway is at $gw


# 1.49 24-Oct-2001 atatat

Print a R on reject routes to indicate that they're not normal routes,
and check netmask (or prefix) length as well as the destination
address when determining if a route is a "default" or not. This means
that the output from 'route show' will no longer say:

Internet6:
Destination Gateway Flags
default localhost UG
default localhost UG

but instead

Internet6:
Destination Gateway Flags
::/104 localhost UGR
::/96 localhost UGR

which makes much more sense.


# 1.48 20-Jul-2001 itojun

off-by-one error in -prefixlen arg validation (do not permit 129 on IPv6)


# 1.47 20-Jul-2001 itojun

make prefixlen work on IPv4 too


# 1.46 16-Jul-2001 bad

The way pmsg_addrs() is used requires that it always prints a newline and
flushes stdout before returning.

Previously the decoded output for a message was stuck in stdio buffers until
the next arrived.


# 1.45 19-Feb-2001 cgd

convert to use getprogname()


# 1.44 04-Feb-2001 christos

remove nested externs.


# 1.43 27-Jan-2001 itojun

support -cloned command line flag.
i don't think anyone ever going to use it.


# 1.42 27-Jan-2001 itojun

mark cloned routes with RTF_CLONED. present it with netstat -r by "c".

let static routes overwrite cloned routes, as cloned routes can come back again
if necessary. behavior same as freebsd/bsdi, code partially from bsdi42.
(NRL rt->rt_parent was not added)
should fix PR 11916 and maybe some other PRs with ARP behavior.

recompilation of usr.sbin/route6d is suggested.


# 1.41 27-Jan-2001 itojun

support RTF_BLACKHOLE.

XXX route show is total duplicate of netstat -r, we need to either remove
route show, or share the same source code, otherwise maintenance cost
bites (and is biting) us


# 1.40 27-Jan-2001 itojun

remove use of uninitialized route (struct ortentry).
it seems that the bug was born during 4.3reno -> 4.4Lite1 transition.


# 1.39 10-Oct-2000 itojun

on "route monitor", print RTM_IFANNOUNCE, RTM_IFINFO (new #), and others.


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.38 04-May-2000 sommerfeld

branches: 1.38.4;
Allow INET6 to be used with SMALL without undefined symbols


# 1.37 20-Apr-2000 itojun

use scoped notation for link-local multicast too.


# 1.36 20-Apr-2000 itojun

support extended scoped address notation (fe80::1%de0).
it hides implementation detail (embedded ifid) from the users.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.35 03-Dec-1999 itojun

don't make "-prefixlen 64" a default in -inet6 case. the past behavior
was not compatible with past practice ("route get" did not work right).

sync with recent KAME.


Revision tags: comdex-fall-1999-base
# 1.34 01-Nov-1999 sommerfeld

Display local address associated with route (if any) in "route get".


# 1.33 03-Sep-1999 itojun

branches: 1.33.2;
fix alignment issue in routing socket data, on 64bit arch (i.e. alpha).
sockaddrs are packed with ROUNDUP() in sys/net/rtsock.c so userland
programs needs to follow that.

PR: 8179


# 1.32 06-Jul-1999 mjacob

Incorrect integration. ctime takes a time_t value, not a long.


# 1.31 02-Jul-1999 itojun

IPv6-ready route command (-inet6 and -prefixlen are added)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.30 23-Oct-1998 lukem

branches: 1.30.2;
* implement -f; flush all routes before executing command
* reset af to 0 in flushroutes() and newroute()
* cleanup -DSMALL:
- `flush' and AF_APPLETALK is supported (the latter had partial support)
- AF_NS, AF_ISO, and AF_CCITT are not supported at all (rather than being
- partially unsupported).


# 1.29 26-Jul-1998 mycroft

const poisoning.


# 1.28 01-Apr-1998 kleink

Need <time.h> for time() prototype.


# 1.27 05-Feb-1998 ross

64-bit sweep, "route -v show" was spinning forever.


# 1.26 16-Nov-1997 christos

Use {warn,err}{,x}(3) instead of printf's


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 01-Oct-1997 enami

Don't declare optind.


# 1.24 16-Sep-1997 lukem

resolve conflicts from lite-2 import


# 1.23 15-Sep-1997 lukem

* cleanup for WARNS=1
* use .Nm correctly
* deprecate register
* getopt returns -1 not EOF


# 1.22 02-Sep-1997 thorpej

Fix uninitialized pointer botch when attempting to flush an already
empty routing table. From Matthias Scheler <tron@lyssa.owl.de>, in
PR #4074.


# 1.21 27-Apr-1997 thorpej

Don't SEGV if a qualifier is passed without an argument. From
Geoff Wing <mason@primenet.com.au>, fixes PR #2700.


# 1.20 21-Apr-1997 mrg

KNF. be safe with buffers.


# 1.19 03-Apr-1997 christos

- Add netatalk bits
- Add prototypes
- Fix printf formats


# 1.18 22-Feb-1997 carrel

Remove uid checks since the kernel now handles this and route(1) is no
longer setuid.
Document the "Permission denied" msg in the man page since this is
_slightly_ less clear than route(1)'s old error msg.


# 1.17 15-Nov-1996 gwr

As discussed some time ago, add a "show" sub-command.
Also allow compilation with -DSMALL to ommit support for
non-essential protocols (i.e. when built into a ramdisk).
Use a less hack-ish way to generate keywords.[ch] and just
check in the result (helps ../../distrib/utils/x_route).


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.16 15-Apr-1996 cgd

check returns of inet_addr() and inet_network() against INADDR_NONE,
not -1, per the manual page. on 64-bit systems like the alpha, -1 will
never equal (unsigned long)INADDR_NONE.


# 1.15 07-Jan-1996 pk

Produce less output on -q as promised by the man page (John Hawkinson; PR#998).


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.14 20-Apr-1995 mycroft

Interface-specific routes can be static.


# 1.13 20-Apr-1995 mycroft

Implement the document `-llinfo' flag.


# 1.12 18-Apr-1995 mycroft

Remove extra `break;'.


# 1.11 18-Mar-1995 cgd

convert to new RCS Id conventions; reduce my headache


# 1.10 24-Dec-1994 cgd

kill some extraneous equal signs.


# 1.9 23-Sep-1994 mycroft

Remove some more uses of obsolete functions.


# 1.8 23-Sep-1994 mycroft

Eliminate uses of some obsolete functions.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.7 13-May-1994 mycroft

Clean up import.


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 25-Apr-1993 mycroft

Compile X.25, OSI, and NS code.


# 1.4 18-Apr-1993 mycroft

Cleanup for GCC 2.


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.3 23-Mar-1993 cgd

changed "Id" to "Header" for rcsids


# 1.2 22-Mar-1993 cgd

added rcs ids to all files


# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
Initial revision


# 1.166 22-Feb-2020 kamil

Avoid undefined behavior

route.c:1523:20, left shift of 1073741824 by 1 places cannot be represented
in type 'int'


# 1.165 22-Jan-2020 roy

route: address flags are more useful than interface flags for address msgs


# 1.164 22-Jan-2020 roy

route: Decode the correct flags for interface address messages


Revision tags: phil-wifi-20191119
# 1.163 02-Sep-2019 roy

route(8): Show addres for RTM_LOSING

While here, add /* FALLTHROUGH */.


# 1.162 31-Aug-2019 roy

route(8): show addrs for RTM_MISS


# 1.161 22-Aug-2019 roy

route(8): print RTM_CHANGE messages

XXX Pullup -9


Revision tags: netbsd-9-base phil-wifi-20190609 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906
# 1.160 14-Aug-2018 roy

branches: 1.160.2;
Resolve every route(4) message type before printing anything more about it
other than the type and length.

This solves the issue where RTM_ONEWADDR is received and it tries to
parse route information from it.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330
# 1.159 23-Mar-2018 roy

branches: 1.159.2;
Handle the routing socket overflowing gracefully.


Revision tags: pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.158 13-Dec-2017 christos

branches: 1.158.2;
Use the definitions from the standard header files and replace homebrew
snprintb with the libutil one.


# 1.157 13-Dec-2017 uwe

Fix typo in flag name. We should probably just use IFFBITS string
that <net/if.h> defines.

PR bin/52815


Revision tags: perseant-stdc-iso10646-base
# 1.156 16-Jun-2017 ozaki-r

Support -c <count> option for route monitor

route command exits if it receives <count> routing messages where
<count> is a value specified by -c.

The option is useful to get only particular message(s) in a test script.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320
# 1.155 17-Mar-2017 roy

branches: 1.155.4;
Report the PID for the process changing the address.


Revision tags: bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.154 04-Apr-2016 ozaki-r

branches: 1.154.2; 1.154.4;
Separate nexthop caches from the routing table

By this change, nexthop caches (IP-MAC address pair) are not stored
in the routing table anymore. Instead nexthop caches are stored in
each network interface; we already have lltable/llentry data structure
for this purpose. This change also obsoletes the concept of cloning/cloned
routes. Cloned routes no longer exist while cloning routes still exist
with renamed to connected routes.

Noticeable changes are:
- Nexthop caches aren't listed in route show/netstat -r
- sysctl(NET_RT_DUMP) doesn't return them
- If RTF_LLDATA is specified, it returns nexthop caches
- Several definitions of routing flags and messages are removed
- RTF_CLONING, RTF_XRESOLVE, RTF_LLINFO, RTF_CLONED and RTM_RESOLVE
- RTF_CONNECTED is added
- It has the same value of RTF_CLONING for backward compatibility
- route's -xresolve, -[no]cloned and -llinfo options are removed
- -[no]cloning remains because it seems there are users
- -[no]connected is introduced and recommended
to be used instead of -[no]cloning
- route show/netstat -r drops some flags
- 'L' and 'c' are not seen anymore
- 'C' now indicates a connected route
- Gateway value of a route of an interface address is now not
a L2 address but "link#N" like a connected (cloning) route
- Proxy ARP: "arp -s ... pub" doesn't create a route

You can know details of behavior changes by seeing diffs under tests/.

Proposed on tech-net and tech-kern:
http://mail-index.netbsd.org/tech-net/2016/03/11/msg005701.html


# 1.153 23-Jan-2016 christos

no need for <sys/mbuf.h>


# 1.152 17-Jan-2016 christos

PR/50671: David Binderman: fix memory leak.


# 1.151 23-Mar-2015 roy

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.


# 1.150 26-Feb-2015 roy

Teach route(8) about RTF_LOCAL.


# 1.149 20-Dec-2014 prlw1

MKINET6=no build fixes

http://mail-index.netbsd.org/tech-net/2014/12/13/msg004898.html


# 1.148 17-Dec-2014 roy

Note that RTM_CHANGE can also change the gateway


# 1.147 12-Nov-2014 christos

PR/47704: Takahiro HAYASHI: Add -L flag


# 1.146 07-Nov-2014 christos

Now that the code can support tags and verbose route printing, enable them.
Also document previously undocumented flags.


# 1.145 06-Nov-2014 christos

Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.144 19-Oct-2013 christos

branches: 1.144.4;
use correct function


# 1.143 19-Oct-2013 christos

use symbolic flags


# 1.142 19-Oct-2013 christos

use scopeid functions


# 1.141 18-Oct-2013 christos

avoid pointer gymnastics


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.140 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.139 04-Oct-2012 uwe

Fix fallout from 1.129 that converted sou::so_foo from unions to
pointers but missed (char *)&soup->so_foo => (char *)soup->so_foo in
mask_addr(). It worked by luck - unless it didn't: due to pointer
numerology on amd64 route add -net ClassC without explicit /24 prefix
length specification would result into /16 destination instead of /24.


# 1.138 08-Aug-2012 christos

branches: 1.138.2;
remove useless rump headers.


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.137 17-Mar-2012 christos

PR/42179: Christoph Badura: Be a little friendlier about missing args.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.136 26-Dec-2011 christos

branches: 1.136.2;
Off by one and clarity improvement from Christian Biere


# 1.135 24-Dec-2011 christos

PR/45661: Henning Petersen: Overlapping buffer in route.c.


# 1.134 11-Nov-2011 gdt

Move RTF_ANNOUNCE flag so that it no longer conflicts with RTF_PROTO2.

RTF_ANNOUNCE was defined as RTF_PROTO2. The flag is used to indicated
that host should act as a proxy for a link level arp or ndp request.
(If RTF_PROTO2 is used as an experimental flag (as advertised),
various problems can occur.)

This commit provides a first-class definition with its own bit for
RTF_ANNOUNCE, removes the old aliasing definitions, and adds support
for the new RTF_ANNOUNCE flag to netstat(8) and route(8).,

Also, remove unused RTF_ flags that collide with RTF_PROTO1:
netinet/icmp6.h defined RTF_PROBEMTU as RTF_PROTO1
netinet/if_inarp.h defined RTF_USETRAILERS as RTF_PROTO1
(Neither of these flags are used anywhere. Both have been removed
to reduce chances of collision with RTF_PROTO1.)

Figuring this out and the diff are the work of Beverly Schwartz of
BBN.

(Passed release build, boot in VM, with no apparently related atf
failures.)

Approved for Public Release, Distribution Unlimited
This material is based upon work supported by the Defense Advanced
Research Projects Agency and Space and Naval Warfare Systems Center,
Pacific, under Contract No. N66001-09-C-2073.


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.133 07-Oct-2011 joerg

branches: 1.133.2;
Simplify.


# 1.132 29-Aug-2011 joerg

Use __dead


# 1.131 01-Jul-2011 joerg

Fix memset usage.


# 1.130 22-Jun-2011 kefren

don't compile tag functions if SMALL is defined. Should fix the build


# 1.129 21-Jun-2011 kefren

Alloc dynamically sockunions in sou.
Teach route(8) about multiple tags. E.G.: -tag 100,20,33
XXX: needs documentation


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.128 01-Feb-2011 matt

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.


Revision tags: matt-mips64-premerge-20101231
# 1.127 13-Dec-2010 pooka

branches: 1.127.2;
Convert from RUMP_ACTION to RUMPPRG.


# 1.126 12-Nov-2010 roy

Support the new RTM_IFINFO and RTM_CHGADDR messages.


# 1.125 05-Nov-2010 pooka

adapt to new rumpclient_init() signature


# 1.124 04-Nov-2010 pooka

#ifdef variable correctly


# 1.123 04-Nov-2010 pooka

be consistent in what to leave outside of SMALL


# 1.122 04-Nov-2010 pooka

Support RUMP_ACTION to compile a rump kernel client.


# 1.121 26-Jun-2010 kefren

add MPLS clue - mpls and tag keywords


# 1.120 12-May-2010 christos

PR/40455: Mihai Chelaru: Add noreject noblackhole options


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base mjf-devfs2-base
# 1.119 28-Dec-2008 christos

parse unsigned long with strtoul not atoi


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3
# 1.118 10-Sep-2008 dyoung

branches: 1.118.6;
Get the socket addresses for dst/gateway/netmask/interface/ifaddr
out of the global namespace.


# 1.117 10-Sep-2008 dyoung

Don't cast a sockunion * to sockaddr *. Instead, reference the
sockaddr inside of the sockunion.


# 1.116 10-Sep-2008 dyoung

Delete superfluous casts to void *.


# 1.115 10-Sep-2008 dyoung

Constify.


# 1.114 10-Sep-2008 dyoung

Constify.


# 1.113 10-Sep-2008 dyoung

Constify.

For clarity's sake, do not assign a new value to inet_makenetandmask()'s
argument, `inet'.


# 1.112 09-Sep-2008 dyoung

Extract subroutine extract_addrs() for reuse, later.

Replace the anonymous constant, 0, with AF_UNSPEC.


# 1.111 09-Sep-2008 dyoung

Constify.


# 1.110 09-Sep-2008 dyoung

Shorten a staircase. Remove superfluous parentheses from return
statements. Constify.


# 1.109 09-Sep-2008 dyoung

Use a union and sizeof() to avoid a cast and an anonymous constant
buffer length, respectively.


# 1.108 09-Sep-2008 dyoung

Use bool.


Revision tags: wrstuden-revivesa-base-2
# 1.107 20-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking cube-autoconf-base mjf-devfs-base matt-armv6-base matt-mips64-base hpcarm-cleanup-base
# 1.106 18-Feb-2007 hubertf

branches: 1.106.12; 1.106.16;
TSEL() is const char* now


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base netbsd-4-base
# 1.105 11-Nov-2006 apb

Fix a bug that caused 0.0.0.0/0 to be treated like 0.0.0.0/32.

foo << 32 is undefined per section 6.5.7 of the C99 standard
if foo is (or is promoted to) a 32-bit type.


# 1.104 23-Sep-2006 dyoung

Let us qualify 'route flush' and 'route show' commands with -llinfo
and -host flags, which is useful for displaying/flushing ARP entries:

# route -n show -inet -llinfo -host
Routing table

Internet:
Destination Gateway Flags
169.254.1.119 link#1 UH
169.254.230.110 00:02:6f:21:e6:6e UH
# route -n flush -inet -llinfo -host
169.254.1.119 done
169.254.230.110 0.2.6f.21.e6.6e done
169.254.237.70 done
# route -n show -inet -llinfo -host
Routing table
#

This will help me address bin/11079, "dhclient may require arp and sed".

Extract common code from flushroutes() and show(), creating
parse_show_opts().

While I'm here, make small cosmetic changes to flushroutes().


# 1.103 23-Sep-2006 dyoung

Move the #ifndef SMALL code together.


# 1.102 23-Sep-2006 dyoung

Use the symbol AF_UNSPEC instead of 0 as appropriate.


# 1.101 23-Sep-2006 dyoung

Remove dead code.


# 1.100 26-Aug-2006 matt

Remove XNS and CCITT/X25 bits.


Revision tags: abandoned-netbsd-4-base
# 1.99 06-Aug-2006 dyoung

KNF err(3), errx(3) usage, indentation, braces.


# 1.98 06-Aug-2006 dyoung

Add route keywords -nocloned, -nocloning.


# 1.97 29-Jan-2006 wiz

Use default option order (AaBbCc...).


# 1.96 26-Jan-2006 is

Print the INET netmask if it is non-contiguous.


# 1.95 25-Jan-2006 christos

PR/32632: Yves-Emmanuel JUTARD: Improvment suggestion in 'route' display.
Add a new -S flag that prints a space for missing flags.


# 1.94 25-Jan-2006 christos

PR/32629: Yves-Emmanuel JUTARD: Type errors in sbin/route/route.c, another
u_char/char conflict.


# 1.93 31-Aug-2005 ginsbach

Add full IPv6 syntax support when route is built with -DSMALL and -DINET6.
Fixes PR/23937. Adapted from supplied patch.


# 1.92 30-Aug-2005 ginsbach

Clean up some minor nits:
+ style (KNF).
. don't cast NULL
. white space clean up
+ use consistent format for error messages.
+ plug memory leaks and avoid malloc(0).
+ verbose message should display even when routing table is empty
(flushroutes).


# 1.91 15-Aug-2005 ginsbach

Make sure that a netmask socket address value prints appropriately when the
family is unset. Either the destination or interface address socket address
family value is used. This change prevents the following sort of output:

RTM_NEWADDR: address being added to iface: len 60, metric 0, flags:<UP>
sockaddrs: <NETMASK,IFA,BRD>
(0) 00.00.ff.00.00 127.0.0.1 127.0.0.1

With this change the last line becomes:

255.0.0.0 127.0.0.1 127.0.0.1

Also make sure that when using a generated inet netmask the address family
is set. With this change a generated netmask will print appropriately
when using the verbose (-v) option.


# 1.90 12-Aug-2005 ginsbach

Make sure the get command always exits non-zero on error. This makes things
like the following work as expected.

#!/bin/sh

if ! route -sn get default >/dev/null 2>&1; then
echo default gateway not set
exit 1
fi
echo default gateway set

Handle routing socket write(2) errors when they occur. This produces
better diagnostics by allowing for handling of the special route errno
values ESRCH, EBUSY, and ENOBUFS even with the quiet (-q) option or
when doing a get command.


# 1.89 12-Aug-2005 ginsbach

Trim the local domain name in routename() for INET6 lookups; similar to
INET lookups.


# 1.88 10-Aug-2005 he

Make this build for __GNUC__ <= 2 (i.e. for vax). The cast to
caddr_t removes a const qualifier. Instead, cast the first element
of the subtraction to "struct sockaddr *" to work around the problem.


# 1.87 09-Aug-2005 ginsbach

Accept protocol flags, i.e. -inet, -inet6, with the show command.
[From OpenBSD via DragonFly BSD]


# 1.86 09-Aug-2005 ginsbach

Fix the default case in sodump(). Printing the address of the "which"
string isn't really that useful. Instead print the string and the value
of sa_family.


# 1.85 09-Aug-2005 ginsbach

More style nits (KNF); casts and sizeof's are not followed by a space.


# 1.84 20-Jul-2005 ginsbach

switch is not a function, so add a space; sort switch elements
alphabetically (KNF).


# 1.83 15-Jul-2005 ginsbach

* Exit non-zero error code when flushroute() fails operating on the
routing socket, e.g. running route flush as non-root.

* When quiet (-q) don't append error string to a non-existent
diagnostic output (stdout). The error diagnostic is still written
to stderr. [from FreeBSD]

* Use warn(3) in place of perror(3).


# 1.82 26-Jun-2005 christos

const poisoning.


# 1.81 25-Jun-2005 dyoung

Teach route(8) to print the messages generated by net80211.


# 1.80 19-May-2005 ginsbach

Convert prefixlen() to ANSI function declaration. Missed by earlier
conversion.


# 1.79 19-May-2005 ginsbach

Due to a limitation in inet_addr(3) it was not possible to specify a
netmask value of 0xffffffff (INADDR_NONE). Fix by using inet_aton(3).
Note it was possible to specify the same mask as the dotted quad
255.255.255.255 because of a later call to gethostbyname(3).
[From FreeBSD]


# 1.78 13-May-2005 ginsbach

Fix botched prior commit. Additional debugging error messages mistakenly
committed.


# 1.77 12-May-2005 ginsbach

* Honor -net when using CIDR (net/mask) notation. This differs
from the default CIDR (host/mask) interpretation. As discussed on
tech-net.

* Use errx() in place of fprintf() and exit(). Make the error message
formats consistent.


# 1.76 10-May-2005 ginsbach

Fix macro NEXTADDR so that the names, like so_dst, are printed
rather than u. The preprocessor doesn't do replacement within
strings, so the # string creation operator must be used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.75 05-Feb-2005 xtraeme

Kill __P(), use ANSI function declarations.


# 1.74 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


# 1.73 15-May-2004 itojun

bump buffer size for any_ntoa(), for huge sa_len


# 1.72 15-May-2004 itojun

2-byte read overrun for unknown sockaddr. from openbsd
XXX out[64], is it safe? what if sa_len > 23?


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.71 05-Jan-2004 jmmv

Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.


# 1.70 01-Oct-2003 itojun

print prefixlen on -show


# 1.69 16-Sep-2003 cube

Remove a comment that referred to a non-committed part of the patch I
submitted for bin/17613. Ok'd by mrg@.


# 1.68 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.


# 1.67 19-Jul-2003 jrf

This is an updated submitted patch originally written by Jim Rees
and sent in by Greg Hudson as seen in PR misc/3227. Basically what it
does is adds a flushall option which deletes all but localhost routes.
This is done by andoring in a flag called doall (1 means do all routes
including gateway, 0 means do a regular flush). I have seen some
platforms that do this. I tested it out on ipv4 only, it works as
advertised. Commit was approved by christos@.


# 1.66 11-Jun-2003 christos

PR/21856: Robert Elz: Changes to route(8) to allow /n instead of -prefixlen
for INET6


# 1.65 03-Jun-2003 itojun

permit foo/bar notation, like "route add 10.0.0.0/8 127.0.0.1".
originally by provos


# 1.64 17-May-2003 itojun

strlcpy [a few mistakes found]


# 1.63 21-Apr-2003 jrf

This addresses PR 17613 when certain methods of adding routes would
muck up the routing tables. The patch was submitted by Quentin Garnier
<netbsd@quatriemek.com> and tweaked a little after it was reviewed
by Christos Zoulas <christos@netbsd.org>. Final change/commit approved
by Christos.


# 1.62 03-Apr-2003 jrf

Made a note in the code about the -d and -d options brought up in
PR 18674. Thanks to Chris Jones for pointing it out.


Revision tags: fvdl_fs64_base
# 1.61 18-Oct-2002 itojun

correct prefixlen handling for IPv4.


# 1.60 18-Oct-2002 itojun

Make prefixlen check to make sure its argument is present before deref
from openbsd


# 1.59 20-Jul-2002 grant

sweep of errx/warnx, remove unnecessary trailing \n


# 1.58 10-Jun-2002 itojun

permit DNS names to address portion. they will be considered as RTF_HOST
if specified as destination (as there's no getnetbyname in IPv6).


# 1.57 05-Jun-2002 itojun

if we're unsure about prefixlen, don't say "128".


# 1.56 05-Jun-2002 itojun

more correct ion to RTF_HOST handling.


# 1.55 04-Jun-2002 itojun

do not have -prefixlen 128 on RTF_HOST.
From: Dawid Szymanski <dawszy@arhea.net>


Revision tags: netbsd-1-6-base
# 1.54 20-May-2002 itojun

branches: 1.54.2;
raise RTF_HOST if destination is a host (/128). from ume


# 1.53 21-Feb-2002 christos

PR/15672: Love: route monitor missing info


# 1.52 15-Nov-2001 christos

Make route exit with a non-zero error code when operations to the routing
socket fails. eg, running route add 1.2.3.4 5.6.7.8 as non root.


# 1.51 02-Nov-2001 lukem

fix -Wshadow warnings


# 1.50 24-Oct-2001 atatat

Provide a short output format for the get command that only prints the
address corresponding to RTA_GATEWAY, or nothing if it doesn't exist.
Modify the exit value of route depending on this, so that one can do
stuff like:

#!/bin/sh
gw=`route -sn get default 2>/dev/null`
if [ -z "$gw" ]; then
echo no default route
exit 1
fi
ping -w1 -c1 $gw >/dev/null 2>&1
if ! route -sn get $gw >/dev/null; then
echo default gateway not responding
exit 1
fi
echo default gateway is at $gw


# 1.49 24-Oct-2001 atatat

Print a R on reject routes to indicate that they're not normal routes,
and check netmask (or prefix) length as well as the destination
address when determining if a route is a "default" or not. This means
that the output from 'route show' will no longer say:

Internet6:
Destination Gateway Flags
default localhost UG
default localhost UG

but instead

Internet6:
Destination Gateway Flags
::/104 localhost UGR
::/96 localhost UGR

which makes much more sense.


# 1.48 20-Jul-2001 itojun

off-by-one error in -prefixlen arg validation (do not permit 129 on IPv6)


# 1.47 20-Jul-2001 itojun

make prefixlen work on IPv4 too


# 1.46 16-Jul-2001 bad

The way pmsg_addrs() is used requires that it always prints a newline and
flushes stdout before returning.

Previously the decoded output for a message was stuck in stdio buffers until
the next arrived.


# 1.45 19-Feb-2001 cgd

convert to use getprogname()


# 1.44 04-Feb-2001 christos

remove nested externs.


# 1.43 27-Jan-2001 itojun

support -cloned command line flag.
i don't think anyone ever going to use it.


# 1.42 27-Jan-2001 itojun

mark cloned routes with RTF_CLONED. present it with netstat -r by "c".

let static routes overwrite cloned routes, as cloned routes can come back again
if necessary. behavior same as freebsd/bsdi, code partially from bsdi42.
(NRL rt->rt_parent was not added)
should fix PR 11916 and maybe some other PRs with ARP behavior.

recompilation of usr.sbin/route6d is suggested.


# 1.41 27-Jan-2001 itojun

support RTF_BLACKHOLE.

XXX route show is total duplicate of netstat -r, we need to either remove
route show, or share the same source code, otherwise maintenance cost
bites (and is biting) us


# 1.40 27-Jan-2001 itojun

remove use of uninitialized route (struct ortentry).
it seems that the bug was born during 4.3reno -> 4.4Lite1 transition.


# 1.39 10-Oct-2000 itojun

on "route monitor", print RTM_IFANNOUNCE, RTM_IFINFO (new #), and others.


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.38 04-May-2000 sommerfeld

branches: 1.38.4;
Allow INET6 to be used with SMALL without undefined symbols


# 1.37 20-Apr-2000 itojun

use scoped notation for link-local multicast too.


# 1.36 20-Apr-2000 itojun

support extended scoped address notation (fe80::1%de0).
it hides implementation detail (embedded ifid) from the users.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.35 03-Dec-1999 itojun

don't make "-prefixlen 64" a default in -inet6 case. the past behavior
was not compatible with past practice ("route get" did not work right).

sync with recent KAME.


Revision tags: comdex-fall-1999-base
# 1.34 01-Nov-1999 sommerfeld

Display local address associated with route (if any) in "route get".


# 1.33 03-Sep-1999 itojun

branches: 1.33.2;
fix alignment issue in routing socket data, on 64bit arch (i.e. alpha).
sockaddrs are packed with ROUNDUP() in sys/net/rtsock.c so userland
programs needs to follow that.

PR: 8179


# 1.32 06-Jul-1999 mjacob

Incorrect integration. ctime takes a time_t value, not a long.


# 1.31 02-Jul-1999 itojun

IPv6-ready route command (-inet6 and -prefixlen are added)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.30 23-Oct-1998 lukem

branches: 1.30.2;
* implement -f; flush all routes before executing command
* reset af to 0 in flushroutes() and newroute()
* cleanup -DSMALL:
- `flush' and AF_APPLETALK is supported (the latter had partial support)
- AF_NS, AF_ISO, and AF_CCITT are not supported at all (rather than being
- partially unsupported).


# 1.29 26-Jul-1998 mycroft

const poisoning.


# 1.28 01-Apr-1998 kleink

Need <time.h> for time() prototype.


# 1.27 05-Feb-1998 ross

64-bit sweep, "route -v show" was spinning forever.


# 1.26 16-Nov-1997 christos

Use {warn,err}{,x}(3) instead of printf's


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 01-Oct-1997 enami

Don't declare optind.


# 1.24 16-Sep-1997 lukem

resolve conflicts from lite-2 import


# 1.23 15-Sep-1997 lukem

* cleanup for WARNS=1
* use .Nm correctly
* deprecate register
* getopt returns -1 not EOF


# 1.22 02-Sep-1997 thorpej

Fix uninitialized pointer botch when attempting to flush an already
empty routing table. From Matthias Scheler <tron@lyssa.owl.de>, in
PR #4074.


# 1.21 27-Apr-1997 thorpej

Don't SEGV if a qualifier is passed without an argument. From
Geoff Wing <mason@primenet.com.au>, fixes PR #2700.


# 1.20 21-Apr-1997 mrg

KNF. be safe with buffers.


# 1.19 03-Apr-1997 christos

- Add netatalk bits
- Add prototypes
- Fix printf formats


# 1.18 22-Feb-1997 carrel

Remove uid checks since the kernel now handles this and route(1) is no
longer setuid.
Document the "Permission denied" msg in the man page since this is
_slightly_ less clear than route(1)'s old error msg.


# 1.17 15-Nov-1996 gwr

As discussed some time ago, add a "show" sub-command.
Also allow compilation with -DSMALL to ommit support for
non-essential protocols (i.e. when built into a ramdisk).
Use a less hack-ish way to generate keywords.[ch] and just
check in the result (helps ../../distrib/utils/x_route).


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.16 15-Apr-1996 cgd

check returns of inet_addr() and inet_network() against INADDR_NONE,
not -1, per the manual page. on 64-bit systems like the alpha, -1 will
never equal (unsigned long)INADDR_NONE.


# 1.15 07-Jan-1996 pk

Produce less output on -q as promised by the man page (John Hawkinson; PR#998).


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.14 20-Apr-1995 mycroft

Interface-specific routes can be static.


# 1.13 20-Apr-1995 mycroft

Implement the document `-llinfo' flag.


# 1.12 18-Apr-1995 mycroft

Remove extra `break;'.


# 1.11 18-Mar-1995 cgd

convert to new RCS Id conventions; reduce my headache


# 1.10 24-Dec-1994 cgd

kill some extraneous equal signs.


# 1.9 23-Sep-1994 mycroft

Remove some more uses of obsolete functions.


# 1.8 23-Sep-1994 mycroft

Eliminate uses of some obsolete functions.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.7 13-May-1994 mycroft

Clean up import.


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 25-Apr-1993 mycroft

Compile X.25, OSI, and NS code.


# 1.4 18-Apr-1993 mycroft

Cleanup for GCC 2.


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.3 23-Mar-1993 cgd

changed "Id" to "Header" for rcsids


# 1.2 22-Mar-1993 cgd

added rcs ids to all files


# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
Initial revision


# 1.165 22-Jan-2020 roy

route: address flags are more useful than interface flags for address msgs


# 1.164 22-Jan-2020 roy

route: Decode the correct flags for interface address messages


Revision tags: phil-wifi-20191119
# 1.163 02-Sep-2019 roy

route(8): Show addres for RTM_LOSING

While here, add /* FALLTHROUGH */.


# 1.162 31-Aug-2019 roy

route(8): show addrs for RTM_MISS


# 1.161 22-Aug-2019 roy

route(8): print RTM_CHANGE messages

XXX Pullup -9


Revision tags: netbsd-9-base phil-wifi-20190609 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906
# 1.160 14-Aug-2018 roy

branches: 1.160.2;
Resolve every route(4) message type before printing anything more about it
other than the type and length.

This solves the issue where RTM_ONEWADDR is received and it tries to
parse route information from it.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330
# 1.159 23-Mar-2018 roy

branches: 1.159.2;
Handle the routing socket overflowing gracefully.


Revision tags: pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.158 13-Dec-2017 christos

branches: 1.158.2;
Use the definitions from the standard header files and replace homebrew
snprintb with the libutil one.


# 1.157 13-Dec-2017 uwe

Fix typo in flag name. We should probably just use IFFBITS string
that <net/if.h> defines.

PR bin/52815


Revision tags: perseant-stdc-iso10646-base
# 1.156 16-Jun-2017 ozaki-r

Support -c <count> option for route monitor

route command exits if it receives <count> routing messages where
<count> is a value specified by -c.

The option is useful to get only particular message(s) in a test script.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320
# 1.155 17-Mar-2017 roy

branches: 1.155.4;
Report the PID for the process changing the address.


Revision tags: bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.154 04-Apr-2016 ozaki-r

branches: 1.154.2; 1.154.4;
Separate nexthop caches from the routing table

By this change, nexthop caches (IP-MAC address pair) are not stored
in the routing table anymore. Instead nexthop caches are stored in
each network interface; we already have lltable/llentry data structure
for this purpose. This change also obsoletes the concept of cloning/cloned
routes. Cloned routes no longer exist while cloning routes still exist
with renamed to connected routes.

Noticeable changes are:
- Nexthop caches aren't listed in route show/netstat -r
- sysctl(NET_RT_DUMP) doesn't return them
- If RTF_LLDATA is specified, it returns nexthop caches
- Several definitions of routing flags and messages are removed
- RTF_CLONING, RTF_XRESOLVE, RTF_LLINFO, RTF_CLONED and RTM_RESOLVE
- RTF_CONNECTED is added
- It has the same value of RTF_CLONING for backward compatibility
- route's -xresolve, -[no]cloned and -llinfo options are removed
- -[no]cloning remains because it seems there are users
- -[no]connected is introduced and recommended
to be used instead of -[no]cloning
- route show/netstat -r drops some flags
- 'L' and 'c' are not seen anymore
- 'C' now indicates a connected route
- Gateway value of a route of an interface address is now not
a L2 address but "link#N" like a connected (cloning) route
- Proxy ARP: "arp -s ... pub" doesn't create a route

You can know details of behavior changes by seeing diffs under tests/.

Proposed on tech-net and tech-kern:
http://mail-index.netbsd.org/tech-net/2016/03/11/msg005701.html


# 1.153 23-Jan-2016 christos

no need for <sys/mbuf.h>


# 1.152 17-Jan-2016 christos

PR/50671: David Binderman: fix memory leak.


# 1.151 23-Mar-2015 roy

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.


# 1.150 26-Feb-2015 roy

Teach route(8) about RTF_LOCAL.


# 1.149 20-Dec-2014 prlw1

MKINET6=no build fixes

http://mail-index.netbsd.org/tech-net/2014/12/13/msg004898.html


# 1.148 17-Dec-2014 roy

Note that RTM_CHANGE can also change the gateway


# 1.147 12-Nov-2014 christos

PR/47704: Takahiro HAYASHI: Add -L flag


# 1.146 07-Nov-2014 christos

Now that the code can support tags and verbose route printing, enable them.
Also document previously undocumented flags.


# 1.145 06-Nov-2014 christos

Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.144 19-Oct-2013 christos

branches: 1.144.4;
use correct function


# 1.143 19-Oct-2013 christos

use symbolic flags


# 1.142 19-Oct-2013 christos

use scopeid functions


# 1.141 18-Oct-2013 christos

avoid pointer gymnastics


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.140 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.139 04-Oct-2012 uwe

Fix fallout from 1.129 that converted sou::so_foo from unions to
pointers but missed (char *)&soup->so_foo => (char *)soup->so_foo in
mask_addr(). It worked by luck - unless it didn't: due to pointer
numerology on amd64 route add -net ClassC without explicit /24 prefix
length specification would result into /16 destination instead of /24.


# 1.138 08-Aug-2012 christos

branches: 1.138.2;
remove useless rump headers.


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.137 17-Mar-2012 christos

PR/42179: Christoph Badura: Be a little friendlier about missing args.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.136 26-Dec-2011 christos

branches: 1.136.2;
Off by one and clarity improvement from Christian Biere


# 1.135 24-Dec-2011 christos

PR/45661: Henning Petersen: Overlapping buffer in route.c.


# 1.134 11-Nov-2011 gdt

Move RTF_ANNOUNCE flag so that it no longer conflicts with RTF_PROTO2.

RTF_ANNOUNCE was defined as RTF_PROTO2. The flag is used to indicated
that host should act as a proxy for a link level arp or ndp request.
(If RTF_PROTO2 is used as an experimental flag (as advertised),
various problems can occur.)

This commit provides a first-class definition with its own bit for
RTF_ANNOUNCE, removes the old aliasing definitions, and adds support
for the new RTF_ANNOUNCE flag to netstat(8) and route(8).,

Also, remove unused RTF_ flags that collide with RTF_PROTO1:
netinet/icmp6.h defined RTF_PROBEMTU as RTF_PROTO1
netinet/if_inarp.h defined RTF_USETRAILERS as RTF_PROTO1
(Neither of these flags are used anywhere. Both have been removed
to reduce chances of collision with RTF_PROTO1.)

Figuring this out and the diff are the work of Beverly Schwartz of
BBN.

(Passed release build, boot in VM, with no apparently related atf
failures.)

Approved for Public Release, Distribution Unlimited
This material is based upon work supported by the Defense Advanced
Research Projects Agency and Space and Naval Warfare Systems Center,
Pacific, under Contract No. N66001-09-C-2073.


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.133 07-Oct-2011 joerg

branches: 1.133.2;
Simplify.


# 1.132 29-Aug-2011 joerg

Use __dead


# 1.131 01-Jul-2011 joerg

Fix memset usage.


# 1.130 22-Jun-2011 kefren

don't compile tag functions if SMALL is defined. Should fix the build


# 1.129 21-Jun-2011 kefren

Alloc dynamically sockunions in sou.
Teach route(8) about multiple tags. E.G.: -tag 100,20,33
XXX: needs documentation


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.128 01-Feb-2011 matt

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.


Revision tags: matt-mips64-premerge-20101231
# 1.127 13-Dec-2010 pooka

branches: 1.127.2;
Convert from RUMP_ACTION to RUMPPRG.


# 1.126 12-Nov-2010 roy

Support the new RTM_IFINFO and RTM_CHGADDR messages.


# 1.125 05-Nov-2010 pooka

adapt to new rumpclient_init() signature


# 1.124 04-Nov-2010 pooka

#ifdef variable correctly


# 1.123 04-Nov-2010 pooka

be consistent in what to leave outside of SMALL


# 1.122 04-Nov-2010 pooka

Support RUMP_ACTION to compile a rump kernel client.


# 1.121 26-Jun-2010 kefren

add MPLS clue - mpls and tag keywords


# 1.120 12-May-2010 christos

PR/40455: Mihai Chelaru: Add noreject noblackhole options


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base mjf-devfs2-base
# 1.119 28-Dec-2008 christos

parse unsigned long with strtoul not atoi


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3
# 1.118 10-Sep-2008 dyoung

branches: 1.118.6;
Get the socket addresses for dst/gateway/netmask/interface/ifaddr
out of the global namespace.


# 1.117 10-Sep-2008 dyoung

Don't cast a sockunion * to sockaddr *. Instead, reference the
sockaddr inside of the sockunion.


# 1.116 10-Sep-2008 dyoung

Delete superfluous casts to void *.


# 1.115 10-Sep-2008 dyoung

Constify.


# 1.114 10-Sep-2008 dyoung

Constify.


# 1.113 10-Sep-2008 dyoung

Constify.

For clarity's sake, do not assign a new value to inet_makenetandmask()'s
argument, `inet'.


# 1.112 09-Sep-2008 dyoung

Extract subroutine extract_addrs() for reuse, later.

Replace the anonymous constant, 0, with AF_UNSPEC.


# 1.111 09-Sep-2008 dyoung

Constify.


# 1.110 09-Sep-2008 dyoung

Shorten a staircase. Remove superfluous parentheses from return
statements. Constify.


# 1.109 09-Sep-2008 dyoung

Use a union and sizeof() to avoid a cast and an anonymous constant
buffer length, respectively.


# 1.108 09-Sep-2008 dyoung

Use bool.


Revision tags: wrstuden-revivesa-base-2
# 1.107 20-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking cube-autoconf-base mjf-devfs-base matt-armv6-base matt-mips64-base hpcarm-cleanup-base
# 1.106 18-Feb-2007 hubertf

branches: 1.106.12; 1.106.16;
TSEL() is const char* now


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base netbsd-4-base
# 1.105 11-Nov-2006 apb

Fix a bug that caused 0.0.0.0/0 to be treated like 0.0.0.0/32.

foo << 32 is undefined per section 6.5.7 of the C99 standard
if foo is (or is promoted to) a 32-bit type.


# 1.104 23-Sep-2006 dyoung

Let us qualify 'route flush' and 'route show' commands with -llinfo
and -host flags, which is useful for displaying/flushing ARP entries:

# route -n show -inet -llinfo -host
Routing table

Internet:
Destination Gateway Flags
169.254.1.119 link#1 UH
169.254.230.110 00:02:6f:21:e6:6e UH
# route -n flush -inet -llinfo -host
169.254.1.119 done
169.254.230.110 0.2.6f.21.e6.6e done
169.254.237.70 done
# route -n show -inet -llinfo -host
Routing table
#

This will help me address bin/11079, "dhclient may require arp and sed".

Extract common code from flushroutes() and show(), creating
parse_show_opts().

While I'm here, make small cosmetic changes to flushroutes().


# 1.103 23-Sep-2006 dyoung

Move the #ifndef SMALL code together.


# 1.102 23-Sep-2006 dyoung

Use the symbol AF_UNSPEC instead of 0 as appropriate.


# 1.101 23-Sep-2006 dyoung

Remove dead code.


# 1.100 26-Aug-2006 matt

Remove XNS and CCITT/X25 bits.


Revision tags: abandoned-netbsd-4-base
# 1.99 06-Aug-2006 dyoung

KNF err(3), errx(3) usage, indentation, braces.


# 1.98 06-Aug-2006 dyoung

Add route keywords -nocloned, -nocloning.


# 1.97 29-Jan-2006 wiz

Use default option order (AaBbCc...).


# 1.96 26-Jan-2006 is

Print the INET netmask if it is non-contiguous.


# 1.95 25-Jan-2006 christos

PR/32632: Yves-Emmanuel JUTARD: Improvment suggestion in 'route' display.
Add a new -S flag that prints a space for missing flags.


# 1.94 25-Jan-2006 christos

PR/32629: Yves-Emmanuel JUTARD: Type errors in sbin/route/route.c, another
u_char/char conflict.


# 1.93 31-Aug-2005 ginsbach

Add full IPv6 syntax support when route is built with -DSMALL and -DINET6.
Fixes PR/23937. Adapted from supplied patch.


# 1.92 30-Aug-2005 ginsbach

Clean up some minor nits:
+ style (KNF).
. don't cast NULL
. white space clean up
+ use consistent format for error messages.
+ plug memory leaks and avoid malloc(0).
+ verbose message should display even when routing table is empty
(flushroutes).


# 1.91 15-Aug-2005 ginsbach

Make sure that a netmask socket address value prints appropriately when the
family is unset. Either the destination or interface address socket address
family value is used. This change prevents the following sort of output:

RTM_NEWADDR: address being added to iface: len 60, metric 0, flags:<UP>
sockaddrs: <NETMASK,IFA,BRD>
(0) 00.00.ff.00.00 127.0.0.1 127.0.0.1

With this change the last line becomes:

255.0.0.0 127.0.0.1 127.0.0.1

Also make sure that when using a generated inet netmask the address family
is set. With this change a generated netmask will print appropriately
when using the verbose (-v) option.


# 1.90 12-Aug-2005 ginsbach

Make sure the get command always exits non-zero on error. This makes things
like the following work as expected.

#!/bin/sh

if ! route -sn get default >/dev/null 2>&1; then
echo default gateway not set
exit 1
fi
echo default gateway set

Handle routing socket write(2) errors when they occur. This produces
better diagnostics by allowing for handling of the special route errno
values ESRCH, EBUSY, and ENOBUFS even with the quiet (-q) option or
when doing a get command.


# 1.89 12-Aug-2005 ginsbach

Trim the local domain name in routename() for INET6 lookups; similar to
INET lookups.


# 1.88 10-Aug-2005 he

Make this build for __GNUC__ <= 2 (i.e. for vax). The cast to
caddr_t removes a const qualifier. Instead, cast the first element
of the subtraction to "struct sockaddr *" to work around the problem.


# 1.87 09-Aug-2005 ginsbach

Accept protocol flags, i.e. -inet, -inet6, with the show command.
[From OpenBSD via DragonFly BSD]


# 1.86 09-Aug-2005 ginsbach

Fix the default case in sodump(). Printing the address of the "which"
string isn't really that useful. Instead print the string and the value
of sa_family.


# 1.85 09-Aug-2005 ginsbach

More style nits (KNF); casts and sizeof's are not followed by a space.


# 1.84 20-Jul-2005 ginsbach

switch is not a function, so add a space; sort switch elements
alphabetically (KNF).


# 1.83 15-Jul-2005 ginsbach

* Exit non-zero error code when flushroute() fails operating on the
routing socket, e.g. running route flush as non-root.

* When quiet (-q) don't append error string to a non-existent
diagnostic output (stdout). The error diagnostic is still written
to stderr. [from FreeBSD]

* Use warn(3) in place of perror(3).


# 1.82 26-Jun-2005 christos

const poisoning.


# 1.81 25-Jun-2005 dyoung

Teach route(8) to print the messages generated by net80211.


# 1.80 19-May-2005 ginsbach

Convert prefixlen() to ANSI function declaration. Missed by earlier
conversion.


# 1.79 19-May-2005 ginsbach

Due to a limitation in inet_addr(3) it was not possible to specify a
netmask value of 0xffffffff (INADDR_NONE). Fix by using inet_aton(3).
Note it was possible to specify the same mask as the dotted quad
255.255.255.255 because of a later call to gethostbyname(3).
[From FreeBSD]


# 1.78 13-May-2005 ginsbach

Fix botched prior commit. Additional debugging error messages mistakenly
committed.


# 1.77 12-May-2005 ginsbach

* Honor -net when using CIDR (net/mask) notation. This differs
from the default CIDR (host/mask) interpretation. As discussed on
tech-net.

* Use errx() in place of fprintf() and exit(). Make the error message
formats consistent.


# 1.76 10-May-2005 ginsbach

Fix macro NEXTADDR so that the names, like so_dst, are printed
rather than u. The preprocessor doesn't do replacement within
strings, so the # string creation operator must be used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.75 05-Feb-2005 xtraeme

Kill __P(), use ANSI function declarations.


# 1.74 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


# 1.73 15-May-2004 itojun

bump buffer size for any_ntoa(), for huge sa_len


# 1.72 15-May-2004 itojun

2-byte read overrun for unknown sockaddr. from openbsd
XXX out[64], is it safe? what if sa_len > 23?


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.71 05-Jan-2004 jmmv

Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.


# 1.70 01-Oct-2003 itojun

print prefixlen on -show


# 1.69 16-Sep-2003 cube

Remove a comment that referred to a non-committed part of the patch I
submitted for bin/17613. Ok'd by mrg@.


# 1.68 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.


# 1.67 19-Jul-2003 jrf

This is an updated submitted patch originally written by Jim Rees
and sent in by Greg Hudson as seen in PR misc/3227. Basically what it
does is adds a flushall option which deletes all but localhost routes.
This is done by andoring in a flag called doall (1 means do all routes
including gateway, 0 means do a regular flush). I have seen some
platforms that do this. I tested it out on ipv4 only, it works as
advertised. Commit was approved by christos@.


# 1.66 11-Jun-2003 christos

PR/21856: Robert Elz: Changes to route(8) to allow /n instead of -prefixlen
for INET6


# 1.65 03-Jun-2003 itojun

permit foo/bar notation, like "route add 10.0.0.0/8 127.0.0.1".
originally by provos


# 1.64 17-May-2003 itojun

strlcpy [a few mistakes found]


# 1.63 21-Apr-2003 jrf

This addresses PR 17613 when certain methods of adding routes would
muck up the routing tables. The patch was submitted by Quentin Garnier
<netbsd@quatriemek.com> and tweaked a little after it was reviewed
by Christos Zoulas <christos@netbsd.org>. Final change/commit approved
by Christos.


# 1.62 03-Apr-2003 jrf

Made a note in the code about the -d and -d options brought up in
PR 18674. Thanks to Chris Jones for pointing it out.


Revision tags: fvdl_fs64_base
# 1.61 18-Oct-2002 itojun

correct prefixlen handling for IPv4.


# 1.60 18-Oct-2002 itojun

Make prefixlen check to make sure its argument is present before deref
from openbsd


# 1.59 20-Jul-2002 grant

sweep of errx/warnx, remove unnecessary trailing \n


# 1.58 10-Jun-2002 itojun

permit DNS names to address portion. they will be considered as RTF_HOST
if specified as destination (as there's no getnetbyname in IPv6).


# 1.57 05-Jun-2002 itojun

if we're unsure about prefixlen, don't say "128".


# 1.56 05-Jun-2002 itojun

more correct ion to RTF_HOST handling.


# 1.55 04-Jun-2002 itojun

do not have -prefixlen 128 on RTF_HOST.
From: Dawid Szymanski <dawszy@arhea.net>


Revision tags: netbsd-1-6-base
# 1.54 20-May-2002 itojun

branches: 1.54.2;
raise RTF_HOST if destination is a host (/128). from ume


# 1.53 21-Feb-2002 christos

PR/15672: Love: route monitor missing info


# 1.52 15-Nov-2001 christos

Make route exit with a non-zero error code when operations to the routing
socket fails. eg, running route add 1.2.3.4 5.6.7.8 as non root.


# 1.51 02-Nov-2001 lukem

fix -Wshadow warnings


# 1.50 24-Oct-2001 atatat

Provide a short output format for the get command that only prints the
address corresponding to RTA_GATEWAY, or nothing if it doesn't exist.
Modify the exit value of route depending on this, so that one can do
stuff like:

#!/bin/sh
gw=`route -sn get default 2>/dev/null`
if [ -z "$gw" ]; then
echo no default route
exit 1
fi
ping -w1 -c1 $gw >/dev/null 2>&1
if ! route -sn get $gw >/dev/null; then
echo default gateway not responding
exit 1
fi
echo default gateway is at $gw


# 1.49 24-Oct-2001 atatat

Print a R on reject routes to indicate that they're not normal routes,
and check netmask (or prefix) length as well as the destination
address when determining if a route is a "default" or not. This means
that the output from 'route show' will no longer say:

Internet6:
Destination Gateway Flags
default localhost UG
default localhost UG

but instead

Internet6:
Destination Gateway Flags
::/104 localhost UGR
::/96 localhost UGR

which makes much more sense.


# 1.48 20-Jul-2001 itojun

off-by-one error in -prefixlen arg validation (do not permit 129 on IPv6)


# 1.47 20-Jul-2001 itojun

make prefixlen work on IPv4 too


# 1.46 16-Jul-2001 bad

The way pmsg_addrs() is used requires that it always prints a newline and
flushes stdout before returning.

Previously the decoded output for a message was stuck in stdio buffers until
the next arrived.


# 1.45 19-Feb-2001 cgd

convert to use getprogname()


# 1.44 04-Feb-2001 christos

remove nested externs.


# 1.43 27-Jan-2001 itojun

support -cloned command line flag.
i don't think anyone ever going to use it.


# 1.42 27-Jan-2001 itojun

mark cloned routes with RTF_CLONED. present it with netstat -r by "c".

let static routes overwrite cloned routes, as cloned routes can come back again
if necessary. behavior same as freebsd/bsdi, code partially from bsdi42.
(NRL rt->rt_parent was not added)
should fix PR 11916 and maybe some other PRs with ARP behavior.

recompilation of usr.sbin/route6d is suggested.


# 1.41 27-Jan-2001 itojun

support RTF_BLACKHOLE.

XXX route show is total duplicate of netstat -r, we need to either remove
route show, or share the same source code, otherwise maintenance cost
bites (and is biting) us


# 1.40 27-Jan-2001 itojun

remove use of uninitialized route (struct ortentry).
it seems that the bug was born during 4.3reno -> 4.4Lite1 transition.


# 1.39 10-Oct-2000 itojun

on "route monitor", print RTM_IFANNOUNCE, RTM_IFINFO (new #), and others.


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.38 04-May-2000 sommerfeld

branches: 1.38.4;
Allow INET6 to be used with SMALL without undefined symbols


# 1.37 20-Apr-2000 itojun

use scoped notation for link-local multicast too.


# 1.36 20-Apr-2000 itojun

support extended scoped address notation (fe80::1%de0).
it hides implementation detail (embedded ifid) from the users.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.35 03-Dec-1999 itojun

don't make "-prefixlen 64" a default in -inet6 case. the past behavior
was not compatible with past practice ("route get" did not work right).

sync with recent KAME.


Revision tags: comdex-fall-1999-base
# 1.34 01-Nov-1999 sommerfeld

Display local address associated with route (if any) in "route get".


# 1.33 03-Sep-1999 itojun

branches: 1.33.2;
fix alignment issue in routing socket data, on 64bit arch (i.e. alpha).
sockaddrs are packed with ROUNDUP() in sys/net/rtsock.c so userland
programs needs to follow that.

PR: 8179


# 1.32 06-Jul-1999 mjacob

Incorrect integration. ctime takes a time_t value, not a long.


# 1.31 02-Jul-1999 itojun

IPv6-ready route command (-inet6 and -prefixlen are added)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.30 23-Oct-1998 lukem

branches: 1.30.2;
* implement -f; flush all routes before executing command
* reset af to 0 in flushroutes() and newroute()
* cleanup -DSMALL:
- `flush' and AF_APPLETALK is supported (the latter had partial support)
- AF_NS, AF_ISO, and AF_CCITT are not supported at all (rather than being
- partially unsupported).


# 1.29 26-Jul-1998 mycroft

const poisoning.


# 1.28 01-Apr-1998 kleink

Need <time.h> for time() prototype.


# 1.27 05-Feb-1998 ross

64-bit sweep, "route -v show" was spinning forever.


# 1.26 16-Nov-1997 christos

Use {warn,err}{,x}(3) instead of printf's


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 01-Oct-1997 enami

Don't declare optind.


# 1.24 16-Sep-1997 lukem

resolve conflicts from lite-2 import


# 1.23 15-Sep-1997 lukem

* cleanup for WARNS=1
* use .Nm correctly
* deprecate register
* getopt returns -1 not EOF


# 1.22 02-Sep-1997 thorpej

Fix uninitialized pointer botch when attempting to flush an already
empty routing table. From Matthias Scheler <tron@lyssa.owl.de>, in
PR #4074.


# 1.21 27-Apr-1997 thorpej

Don't SEGV if a qualifier is passed without an argument. From
Geoff Wing <mason@primenet.com.au>, fixes PR #2700.


# 1.20 21-Apr-1997 mrg

KNF. be safe with buffers.


# 1.19 03-Apr-1997 christos

- Add netatalk bits
- Add prototypes
- Fix printf formats


# 1.18 22-Feb-1997 carrel

Remove uid checks since the kernel now handles this and route(1) is no
longer setuid.
Document the "Permission denied" msg in the man page since this is
_slightly_ less clear than route(1)'s old error msg.


# 1.17 15-Nov-1996 gwr

As discussed some time ago, add a "show" sub-command.
Also allow compilation with -DSMALL to ommit support for
non-essential protocols (i.e. when built into a ramdisk).
Use a less hack-ish way to generate keywords.[ch] and just
check in the result (helps ../../distrib/utils/x_route).


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.16 15-Apr-1996 cgd

check returns of inet_addr() and inet_network() against INADDR_NONE,
not -1, per the manual page. on 64-bit systems like the alpha, -1 will
never equal (unsigned long)INADDR_NONE.


# 1.15 07-Jan-1996 pk

Produce less output on -q as promised by the man page (John Hawkinson; PR#998).


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.14 20-Apr-1995 mycroft

Interface-specific routes can be static.


# 1.13 20-Apr-1995 mycroft

Implement the document `-llinfo' flag.


# 1.12 18-Apr-1995 mycroft

Remove extra `break;'.


# 1.11 18-Mar-1995 cgd

convert to new RCS Id conventions; reduce my headache


# 1.10 24-Dec-1994 cgd

kill some extraneous equal signs.


# 1.9 23-Sep-1994 mycroft

Remove some more uses of obsolete functions.


# 1.8 23-Sep-1994 mycroft

Eliminate uses of some obsolete functions.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.7 13-May-1994 mycroft

Clean up import.


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 25-Apr-1993 mycroft

Compile X.25, OSI, and NS code.


# 1.4 18-Apr-1993 mycroft

Cleanup for GCC 2.


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.3 23-Mar-1993 cgd

changed "Id" to "Header" for rcsids


# 1.2 22-Mar-1993 cgd

added rcs ids to all files


# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
Initial revision


# 1.163 02-Sep-2019 roy

route(8): Show addres for RTM_LOSING

While here, add /* FALLTHROUGH */.


# 1.162 31-Aug-2019 roy

route(8): show addrs for RTM_MISS


# 1.161 22-Aug-2019 roy

route(8): print RTM_CHANGE messages

XXX Pullup -9


Revision tags: netbsd-9-base phil-wifi-20190609 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906
# 1.160 14-Aug-2018 roy

branches: 1.160.2;
Resolve every route(4) message type before printing anything more about it
other than the type and length.

This solves the issue where RTM_ONEWADDR is received and it tries to
parse route information from it.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330
# 1.159 23-Mar-2018 roy

branches: 1.159.2;
Handle the routing socket overflowing gracefully.


Revision tags: pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.158 13-Dec-2017 christos

branches: 1.158.2;
Use the definitions from the standard header files and replace homebrew
snprintb with the libutil one.


# 1.157 13-Dec-2017 uwe

Fix typo in flag name. We should probably just use IFFBITS string
that <net/if.h> defines.

PR bin/52815


Revision tags: perseant-stdc-iso10646-base
# 1.156 16-Jun-2017 ozaki-r

Support -c <count> option for route monitor

route command exits if it receives <count> routing messages where
<count> is a value specified by -c.

The option is useful to get only particular message(s) in a test script.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320
# 1.155 17-Mar-2017 roy

branches: 1.155.4;
Report the PID for the process changing the address.


Revision tags: bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.154 04-Apr-2016 ozaki-r

branches: 1.154.2; 1.154.4;
Separate nexthop caches from the routing table

By this change, nexthop caches (IP-MAC address pair) are not stored
in the routing table anymore. Instead nexthop caches are stored in
each network interface; we already have lltable/llentry data structure
for this purpose. This change also obsoletes the concept of cloning/cloned
routes. Cloned routes no longer exist while cloning routes still exist
with renamed to connected routes.

Noticeable changes are:
- Nexthop caches aren't listed in route show/netstat -r
- sysctl(NET_RT_DUMP) doesn't return them
- If RTF_LLDATA is specified, it returns nexthop caches
- Several definitions of routing flags and messages are removed
- RTF_CLONING, RTF_XRESOLVE, RTF_LLINFO, RTF_CLONED and RTM_RESOLVE
- RTF_CONNECTED is added
- It has the same value of RTF_CLONING for backward compatibility
- route's -xresolve, -[no]cloned and -llinfo options are removed
- -[no]cloning remains because it seems there are users
- -[no]connected is introduced and recommended
to be used instead of -[no]cloning
- route show/netstat -r drops some flags
- 'L' and 'c' are not seen anymore
- 'C' now indicates a connected route
- Gateway value of a route of an interface address is now not
a L2 address but "link#N" like a connected (cloning) route
- Proxy ARP: "arp -s ... pub" doesn't create a route

You can know details of behavior changes by seeing diffs under tests/.

Proposed on tech-net and tech-kern:
http://mail-index.netbsd.org/tech-net/2016/03/11/msg005701.html


# 1.153 23-Jan-2016 christos

no need for <sys/mbuf.h>


# 1.152 17-Jan-2016 christos

PR/50671: David Binderman: fix memory leak.


# 1.151 23-Mar-2015 roy

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.


# 1.150 26-Feb-2015 roy

Teach route(8) about RTF_LOCAL.


# 1.149 20-Dec-2014 prlw1

MKINET6=no build fixes

http://mail-index.netbsd.org/tech-net/2014/12/13/msg004898.html


# 1.148 17-Dec-2014 roy

Note that RTM_CHANGE can also change the gateway


# 1.147 12-Nov-2014 christos

PR/47704: Takahiro HAYASHI: Add -L flag


# 1.146 07-Nov-2014 christos

Now that the code can support tags and verbose route printing, enable them.
Also document previously undocumented flags.


# 1.145 06-Nov-2014 christos

Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.144 19-Oct-2013 christos

branches: 1.144.4;
use correct function


# 1.143 19-Oct-2013 christos

use symbolic flags


# 1.142 19-Oct-2013 christos

use scopeid functions


# 1.141 18-Oct-2013 christos

avoid pointer gymnastics


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.140 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.139 04-Oct-2012 uwe

Fix fallout from 1.129 that converted sou::so_foo from unions to
pointers but missed (char *)&soup->so_foo => (char *)soup->so_foo in
mask_addr(). It worked by luck - unless it didn't: due to pointer
numerology on amd64 route add -net ClassC without explicit /24 prefix
length specification would result into /16 destination instead of /24.


# 1.138 08-Aug-2012 christos

branches: 1.138.2;
remove useless rump headers.


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.137 17-Mar-2012 christos

PR/42179: Christoph Badura: Be a little friendlier about missing args.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.136 26-Dec-2011 christos

branches: 1.136.2;
Off by one and clarity improvement from Christian Biere


# 1.135 24-Dec-2011 christos

PR/45661: Henning Petersen: Overlapping buffer in route.c.


# 1.134 11-Nov-2011 gdt

Move RTF_ANNOUNCE flag so that it no longer conflicts with RTF_PROTO2.

RTF_ANNOUNCE was defined as RTF_PROTO2. The flag is used to indicated
that host should act as a proxy for a link level arp or ndp request.
(If RTF_PROTO2 is used as an experimental flag (as advertised),
various problems can occur.)

This commit provides a first-class definition with its own bit for
RTF_ANNOUNCE, removes the old aliasing definitions, and adds support
for the new RTF_ANNOUNCE flag to netstat(8) and route(8).,

Also, remove unused RTF_ flags that collide with RTF_PROTO1:
netinet/icmp6.h defined RTF_PROBEMTU as RTF_PROTO1
netinet/if_inarp.h defined RTF_USETRAILERS as RTF_PROTO1
(Neither of these flags are used anywhere. Both have been removed
to reduce chances of collision with RTF_PROTO1.)

Figuring this out and the diff are the work of Beverly Schwartz of
BBN.

(Passed release build, boot in VM, with no apparently related atf
failures.)

Approved for Public Release, Distribution Unlimited
This material is based upon work supported by the Defense Advanced
Research Projects Agency and Space and Naval Warfare Systems Center,
Pacific, under Contract No. N66001-09-C-2073.


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.133 07-Oct-2011 joerg

branches: 1.133.2;
Simplify.


# 1.132 29-Aug-2011 joerg

Use __dead


# 1.131 01-Jul-2011 joerg

Fix memset usage.


# 1.130 22-Jun-2011 kefren

don't compile tag functions if SMALL is defined. Should fix the build


# 1.129 21-Jun-2011 kefren

Alloc dynamically sockunions in sou.
Teach route(8) about multiple tags. E.G.: -tag 100,20,33
XXX: needs documentation


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.128 01-Feb-2011 matt

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.


Revision tags: matt-mips64-premerge-20101231
# 1.127 13-Dec-2010 pooka

branches: 1.127.2;
Convert from RUMP_ACTION to RUMPPRG.


# 1.126 12-Nov-2010 roy

Support the new RTM_IFINFO and RTM_CHGADDR messages.


# 1.125 05-Nov-2010 pooka

adapt to new rumpclient_init() signature


# 1.124 04-Nov-2010 pooka

#ifdef variable correctly


# 1.123 04-Nov-2010 pooka

be consistent in what to leave outside of SMALL


# 1.122 04-Nov-2010 pooka

Support RUMP_ACTION to compile a rump kernel client.


# 1.121 26-Jun-2010 kefren

add MPLS clue - mpls and tag keywords


# 1.120 12-May-2010 christos

PR/40455: Mihai Chelaru: Add noreject noblackhole options


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base mjf-devfs2-base
# 1.119 28-Dec-2008 christos

parse unsigned long with strtoul not atoi


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3
# 1.118 10-Sep-2008 dyoung

branches: 1.118.6;
Get the socket addresses for dst/gateway/netmask/interface/ifaddr
out of the global namespace.


# 1.117 10-Sep-2008 dyoung

Don't cast a sockunion * to sockaddr *. Instead, reference the
sockaddr inside of the sockunion.


# 1.116 10-Sep-2008 dyoung

Delete superfluous casts to void *.


# 1.115 10-Sep-2008 dyoung

Constify.


# 1.114 10-Sep-2008 dyoung

Constify.


# 1.113 10-Sep-2008 dyoung

Constify.

For clarity's sake, do not assign a new value to inet_makenetandmask()'s
argument, `inet'.


# 1.112 09-Sep-2008 dyoung

Extract subroutine extract_addrs() for reuse, later.

Replace the anonymous constant, 0, with AF_UNSPEC.


# 1.111 09-Sep-2008 dyoung

Constify.


# 1.110 09-Sep-2008 dyoung

Shorten a staircase. Remove superfluous parentheses from return
statements. Constify.


# 1.109 09-Sep-2008 dyoung

Use a union and sizeof() to avoid a cast and an anonymous constant
buffer length, respectively.


# 1.108 09-Sep-2008 dyoung

Use bool.


Revision tags: wrstuden-revivesa-base-2
# 1.107 20-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking cube-autoconf-base mjf-devfs-base matt-armv6-base matt-mips64-base hpcarm-cleanup-base
# 1.106 18-Feb-2007 hubertf

branches: 1.106.12; 1.106.16;
TSEL() is const char* now


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base netbsd-4-base
# 1.105 11-Nov-2006 apb

Fix a bug that caused 0.0.0.0/0 to be treated like 0.0.0.0/32.

foo << 32 is undefined per section 6.5.7 of the C99 standard
if foo is (or is promoted to) a 32-bit type.


# 1.104 23-Sep-2006 dyoung

Let us qualify 'route flush' and 'route show' commands with -llinfo
and -host flags, which is useful for displaying/flushing ARP entries:

# route -n show -inet -llinfo -host
Routing table

Internet:
Destination Gateway Flags
169.254.1.119 link#1 UH
169.254.230.110 00:02:6f:21:e6:6e UH
# route -n flush -inet -llinfo -host
169.254.1.119 done
169.254.230.110 0.2.6f.21.e6.6e done
169.254.237.70 done
# route -n show -inet -llinfo -host
Routing table
#

This will help me address bin/11079, "dhclient may require arp and sed".

Extract common code from flushroutes() and show(), creating
parse_show_opts().

While I'm here, make small cosmetic changes to flushroutes().


# 1.103 23-Sep-2006 dyoung

Move the #ifndef SMALL code together.


# 1.102 23-Sep-2006 dyoung

Use the symbol AF_UNSPEC instead of 0 as appropriate.


# 1.101 23-Sep-2006 dyoung

Remove dead code.


# 1.100 26-Aug-2006 matt

Remove XNS and CCITT/X25 bits.


Revision tags: abandoned-netbsd-4-base
# 1.99 06-Aug-2006 dyoung

KNF err(3), errx(3) usage, indentation, braces.


# 1.98 06-Aug-2006 dyoung

Add route keywords -nocloned, -nocloning.


# 1.97 29-Jan-2006 wiz

Use default option order (AaBbCc...).


# 1.96 26-Jan-2006 is

Print the INET netmask if it is non-contiguous.


# 1.95 25-Jan-2006 christos

PR/32632: Yves-Emmanuel JUTARD: Improvment suggestion in 'route' display.
Add a new -S flag that prints a space for missing flags.


# 1.94 25-Jan-2006 christos

PR/32629: Yves-Emmanuel JUTARD: Type errors in sbin/route/route.c, another
u_char/char conflict.


# 1.93 31-Aug-2005 ginsbach

Add full IPv6 syntax support when route is built with -DSMALL and -DINET6.
Fixes PR/23937. Adapted from supplied patch.


# 1.92 30-Aug-2005 ginsbach

Clean up some minor nits:
+ style (KNF).
. don't cast NULL
. white space clean up
+ use consistent format for error messages.
+ plug memory leaks and avoid malloc(0).
+ verbose message should display even when routing table is empty
(flushroutes).


# 1.91 15-Aug-2005 ginsbach

Make sure that a netmask socket address value prints appropriately when the
family is unset. Either the destination or interface address socket address
family value is used. This change prevents the following sort of output:

RTM_NEWADDR: address being added to iface: len 60, metric 0, flags:<UP>
sockaddrs: <NETMASK,IFA,BRD>
(0) 00.00.ff.00.00 127.0.0.1 127.0.0.1

With this change the last line becomes:

255.0.0.0 127.0.0.1 127.0.0.1

Also make sure that when using a generated inet netmask the address family
is set. With this change a generated netmask will print appropriately
when using the verbose (-v) option.


# 1.90 12-Aug-2005 ginsbach

Make sure the get command always exits non-zero on error. This makes things
like the following work as expected.

#!/bin/sh

if ! route -sn get default >/dev/null 2>&1; then
echo default gateway not set
exit 1
fi
echo default gateway set

Handle routing socket write(2) errors when they occur. This produces
better diagnostics by allowing for handling of the special route errno
values ESRCH, EBUSY, and ENOBUFS even with the quiet (-q) option or
when doing a get command.


# 1.89 12-Aug-2005 ginsbach

Trim the local domain name in routename() for INET6 lookups; similar to
INET lookups.


# 1.88 10-Aug-2005 he

Make this build for __GNUC__ <= 2 (i.e. for vax). The cast to
caddr_t removes a const qualifier. Instead, cast the first element
of the subtraction to "struct sockaddr *" to work around the problem.


# 1.87 09-Aug-2005 ginsbach

Accept protocol flags, i.e. -inet, -inet6, with the show command.
[From OpenBSD via DragonFly BSD]


# 1.86 09-Aug-2005 ginsbach

Fix the default case in sodump(). Printing the address of the "which"
string isn't really that useful. Instead print the string and the value
of sa_family.


# 1.85 09-Aug-2005 ginsbach

More style nits (KNF); casts and sizeof's are not followed by a space.


# 1.84 20-Jul-2005 ginsbach

switch is not a function, so add a space; sort switch elements
alphabetically (KNF).


# 1.83 15-Jul-2005 ginsbach

* Exit non-zero error code when flushroute() fails operating on the
routing socket, e.g. running route flush as non-root.

* When quiet (-q) don't append error string to a non-existent
diagnostic output (stdout). The error diagnostic is still written
to stderr. [from FreeBSD]

* Use warn(3) in place of perror(3).


# 1.82 26-Jun-2005 christos

const poisoning.


# 1.81 25-Jun-2005 dyoung

Teach route(8) to print the messages generated by net80211.


# 1.80 19-May-2005 ginsbach

Convert prefixlen() to ANSI function declaration. Missed by earlier
conversion.


# 1.79 19-May-2005 ginsbach

Due to a limitation in inet_addr(3) it was not possible to specify a
netmask value of 0xffffffff (INADDR_NONE). Fix by using inet_aton(3).
Note it was possible to specify the same mask as the dotted quad
255.255.255.255 because of a later call to gethostbyname(3).
[From FreeBSD]


# 1.78 13-May-2005 ginsbach

Fix botched prior commit. Additional debugging error messages mistakenly
committed.


# 1.77 12-May-2005 ginsbach

* Honor -net when using CIDR (net/mask) notation. This differs
from the default CIDR (host/mask) interpretation. As discussed on
tech-net.

* Use errx() in place of fprintf() and exit(). Make the error message
formats consistent.


# 1.76 10-May-2005 ginsbach

Fix macro NEXTADDR so that the names, like so_dst, are printed
rather than u. The preprocessor doesn't do replacement within
strings, so the # string creation operator must be used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.75 05-Feb-2005 xtraeme

Kill __P(), use ANSI function declarations.


# 1.74 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


# 1.73 15-May-2004 itojun

bump buffer size for any_ntoa(), for huge sa_len


# 1.72 15-May-2004 itojun

2-byte read overrun for unknown sockaddr. from openbsd
XXX out[64], is it safe? what if sa_len > 23?


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.71 05-Jan-2004 jmmv

Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.


# 1.70 01-Oct-2003 itojun

print prefixlen on -show


# 1.69 16-Sep-2003 cube

Remove a comment that referred to a non-committed part of the patch I
submitted for bin/17613. Ok'd by mrg@.


# 1.68 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.


# 1.67 19-Jul-2003 jrf

This is an updated submitted patch originally written by Jim Rees
and sent in by Greg Hudson as seen in PR misc/3227. Basically what it
does is adds a flushall option which deletes all but localhost routes.
This is done by andoring in a flag called doall (1 means do all routes
including gateway, 0 means do a regular flush). I have seen some
platforms that do this. I tested it out on ipv4 only, it works as
advertised. Commit was approved by christos@.


# 1.66 11-Jun-2003 christos

PR/21856: Robert Elz: Changes to route(8) to allow /n instead of -prefixlen
for INET6


# 1.65 03-Jun-2003 itojun

permit foo/bar notation, like "route add 10.0.0.0/8 127.0.0.1".
originally by provos


# 1.64 17-May-2003 itojun

strlcpy [a few mistakes found]


# 1.63 21-Apr-2003 jrf

This addresses PR 17613 when certain methods of adding routes would
muck up the routing tables. The patch was submitted by Quentin Garnier
<netbsd@quatriemek.com> and tweaked a little after it was reviewed
by Christos Zoulas <christos@netbsd.org>. Final change/commit approved
by Christos.


# 1.62 03-Apr-2003 jrf

Made a note in the code about the -d and -d options brought up in
PR 18674. Thanks to Chris Jones for pointing it out.


Revision tags: fvdl_fs64_base
# 1.61 18-Oct-2002 itojun

correct prefixlen handling for IPv4.


# 1.60 18-Oct-2002 itojun

Make prefixlen check to make sure its argument is present before deref
from openbsd


# 1.59 20-Jul-2002 grant

sweep of errx/warnx, remove unnecessary trailing \n


# 1.58 10-Jun-2002 itojun

permit DNS names to address portion. they will be considered as RTF_HOST
if specified as destination (as there's no getnetbyname in IPv6).


# 1.57 05-Jun-2002 itojun

if we're unsure about prefixlen, don't say "128".


# 1.56 05-Jun-2002 itojun

more correct ion to RTF_HOST handling.


# 1.55 04-Jun-2002 itojun

do not have -prefixlen 128 on RTF_HOST.
From: Dawid Szymanski <dawszy@arhea.net>


Revision tags: netbsd-1-6-base
# 1.54 20-May-2002 itojun

branches: 1.54.2;
raise RTF_HOST if destination is a host (/128). from ume


# 1.53 21-Feb-2002 christos

PR/15672: Love: route monitor missing info


# 1.52 15-Nov-2001 christos

Make route exit with a non-zero error code when operations to the routing
socket fails. eg, running route add 1.2.3.4 5.6.7.8 as non root.


# 1.51 02-Nov-2001 lukem

fix -Wshadow warnings


# 1.50 24-Oct-2001 atatat

Provide a short output format for the get command that only prints the
address corresponding to RTA_GATEWAY, or nothing if it doesn't exist.
Modify the exit value of route depending on this, so that one can do
stuff like:

#!/bin/sh
gw=`route -sn get default 2>/dev/null`
if [ -z "$gw" ]; then
echo no default route
exit 1
fi
ping -w1 -c1 $gw >/dev/null 2>&1
if ! route -sn get $gw >/dev/null; then
echo default gateway not responding
exit 1
fi
echo default gateway is at $gw


# 1.49 24-Oct-2001 atatat

Print a R on reject routes to indicate that they're not normal routes,
and check netmask (or prefix) length as well as the destination
address when determining if a route is a "default" or not. This means
that the output from 'route show' will no longer say:

Internet6:
Destination Gateway Flags
default localhost UG
default localhost UG

but instead

Internet6:
Destination Gateway Flags
::/104 localhost UGR
::/96 localhost UGR

which makes much more sense.


# 1.48 20-Jul-2001 itojun

off-by-one error in -prefixlen arg validation (do not permit 129 on IPv6)


# 1.47 20-Jul-2001 itojun

make prefixlen work on IPv4 too


# 1.46 16-Jul-2001 bad

The way pmsg_addrs() is used requires that it always prints a newline and
flushes stdout before returning.

Previously the decoded output for a message was stuck in stdio buffers until
the next arrived.


# 1.45 19-Feb-2001 cgd

convert to use getprogname()


# 1.44 04-Feb-2001 christos

remove nested externs.


# 1.43 27-Jan-2001 itojun

support -cloned command line flag.
i don't think anyone ever going to use it.


# 1.42 27-Jan-2001 itojun

mark cloned routes with RTF_CLONED. present it with netstat -r by "c".

let static routes overwrite cloned routes, as cloned routes can come back again
if necessary. behavior same as freebsd/bsdi, code partially from bsdi42.
(NRL rt->rt_parent was not added)
should fix PR 11916 and maybe some other PRs with ARP behavior.

recompilation of usr.sbin/route6d is suggested.


# 1.41 27-Jan-2001 itojun

support RTF_BLACKHOLE.

XXX route show is total duplicate of netstat -r, we need to either remove
route show, or share the same source code, otherwise maintenance cost
bites (and is biting) us


# 1.40 27-Jan-2001 itojun

remove use of uninitialized route (struct ortentry).
it seems that the bug was born during 4.3reno -> 4.4Lite1 transition.


# 1.39 10-Oct-2000 itojun

on "route monitor", print RTM_IFANNOUNCE, RTM_IFINFO (new #), and others.


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.38 04-May-2000 sommerfeld

branches: 1.38.4;
Allow INET6 to be used with SMALL without undefined symbols


# 1.37 20-Apr-2000 itojun

use scoped notation for link-local multicast too.


# 1.36 20-Apr-2000 itojun

support extended scoped address notation (fe80::1%de0).
it hides implementation detail (embedded ifid) from the users.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.35 03-Dec-1999 itojun

don't make "-prefixlen 64" a default in -inet6 case. the past behavior
was not compatible with past practice ("route get" did not work right).

sync with recent KAME.


Revision tags: comdex-fall-1999-base
# 1.34 01-Nov-1999 sommerfeld

Display local address associated with route (if any) in "route get".


# 1.33 03-Sep-1999 itojun

branches: 1.33.2;
fix alignment issue in routing socket data, on 64bit arch (i.e. alpha).
sockaddrs are packed with ROUNDUP() in sys/net/rtsock.c so userland
programs needs to follow that.

PR: 8179


# 1.32 06-Jul-1999 mjacob

Incorrect integration. ctime takes a time_t value, not a long.


# 1.31 02-Jul-1999 itojun

IPv6-ready route command (-inet6 and -prefixlen are added)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.30 23-Oct-1998 lukem

branches: 1.30.2;
* implement -f; flush all routes before executing command
* reset af to 0 in flushroutes() and newroute()
* cleanup -DSMALL:
- `flush' and AF_APPLETALK is supported (the latter had partial support)
- AF_NS, AF_ISO, and AF_CCITT are not supported at all (rather than being
- partially unsupported).


# 1.29 26-Jul-1998 mycroft

const poisoning.


# 1.28 01-Apr-1998 kleink

Need <time.h> for time() prototype.


# 1.27 05-Feb-1998 ross

64-bit sweep, "route -v show" was spinning forever.


# 1.26 16-Nov-1997 christos

Use {warn,err}{,x}(3) instead of printf's


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 01-Oct-1997 enami

Don't declare optind.


# 1.24 16-Sep-1997 lukem

resolve conflicts from lite-2 import


# 1.23 15-Sep-1997 lukem

* cleanup for WARNS=1
* use .Nm correctly
* deprecate register
* getopt returns -1 not EOF


# 1.22 02-Sep-1997 thorpej

Fix uninitialized pointer botch when attempting to flush an already
empty routing table. From Matthias Scheler <tron@lyssa.owl.de>, in
PR #4074.


# 1.21 27-Apr-1997 thorpej

Don't SEGV if a qualifier is passed without an argument. From
Geoff Wing <mason@primenet.com.au>, fixes PR #2700.


# 1.20 21-Apr-1997 mrg

KNF. be safe with buffers.


# 1.19 03-Apr-1997 christos

- Add netatalk bits
- Add prototypes
- Fix printf formats


# 1.18 22-Feb-1997 carrel

Remove uid checks since the kernel now handles this and route(1) is no
longer setuid.
Document the "Permission denied" msg in the man page since this is
_slightly_ less clear than route(1)'s old error msg.


# 1.17 15-Nov-1996 gwr

As discussed some time ago, add a "show" sub-command.
Also allow compilation with -DSMALL to ommit support for
non-essential protocols (i.e. when built into a ramdisk).
Use a less hack-ish way to generate keywords.[ch] and just
check in the result (helps ../../distrib/utils/x_route).


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.16 15-Apr-1996 cgd

check returns of inet_addr() and inet_network() against INADDR_NONE,
not -1, per the manual page. on 64-bit systems like the alpha, -1 will
never equal (unsigned long)INADDR_NONE.


# 1.15 07-Jan-1996 pk

Produce less output on -q as promised by the man page (John Hawkinson; PR#998).


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.14 20-Apr-1995 mycroft

Interface-specific routes can be static.


# 1.13 20-Apr-1995 mycroft

Implement the document `-llinfo' flag.


# 1.12 18-Apr-1995 mycroft

Remove extra `break;'.


# 1.11 18-Mar-1995 cgd

convert to new RCS Id conventions; reduce my headache


# 1.10 24-Dec-1994 cgd

kill some extraneous equal signs.


# 1.9 23-Sep-1994 mycroft

Remove some more uses of obsolete functions.


# 1.8 23-Sep-1994 mycroft

Eliminate uses of some obsolete functions.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.7 13-May-1994 mycroft

Clean up import.


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 25-Apr-1993 mycroft

Compile X.25, OSI, and NS code.


# 1.4 18-Apr-1993 mycroft

Cleanup for GCC 2.


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.3 23-Mar-1993 cgd

changed "Id" to "Header" for rcsids


# 1.2 22-Mar-1993 cgd

added rcs ids to all files


# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
Initial revision


# 1.162 31-Aug-2019 roy

route(8): show addrs for RTM_MISS


# 1.161 22-Aug-2019 roy

route(8): print RTM_CHANGE messages

XXX Pullup -9


Revision tags: netbsd-9-base phil-wifi-20190609 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906
# 1.160 14-Aug-2018 roy

branches: 1.160.2;
Resolve every route(4) message type before printing anything more about it
other than the type and length.

This solves the issue where RTM_ONEWADDR is received and it tries to
parse route information from it.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330
# 1.159 23-Mar-2018 roy

branches: 1.159.2;
Handle the routing socket overflowing gracefully.


Revision tags: pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.158 13-Dec-2017 christos

branches: 1.158.2;
Use the definitions from the standard header files and replace homebrew
snprintb with the libutil one.


# 1.157 13-Dec-2017 uwe

Fix typo in flag name. We should probably just use IFFBITS string
that <net/if.h> defines.

PR bin/52815


Revision tags: perseant-stdc-iso10646-base
# 1.156 16-Jun-2017 ozaki-r

Support -c <count> option for route monitor

route command exits if it receives <count> routing messages where
<count> is a value specified by -c.

The option is useful to get only particular message(s) in a test script.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320
# 1.155 17-Mar-2017 roy

branches: 1.155.4;
Report the PID for the process changing the address.


Revision tags: bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.154 04-Apr-2016 ozaki-r

branches: 1.154.2; 1.154.4;
Separate nexthop caches from the routing table

By this change, nexthop caches (IP-MAC address pair) are not stored
in the routing table anymore. Instead nexthop caches are stored in
each network interface; we already have lltable/llentry data structure
for this purpose. This change also obsoletes the concept of cloning/cloned
routes. Cloned routes no longer exist while cloning routes still exist
with renamed to connected routes.

Noticeable changes are:
- Nexthop caches aren't listed in route show/netstat -r
- sysctl(NET_RT_DUMP) doesn't return them
- If RTF_LLDATA is specified, it returns nexthop caches
- Several definitions of routing flags and messages are removed
- RTF_CLONING, RTF_XRESOLVE, RTF_LLINFO, RTF_CLONED and RTM_RESOLVE
- RTF_CONNECTED is added
- It has the same value of RTF_CLONING for backward compatibility
- route's -xresolve, -[no]cloned and -llinfo options are removed
- -[no]cloning remains because it seems there are users
- -[no]connected is introduced and recommended
to be used instead of -[no]cloning
- route show/netstat -r drops some flags
- 'L' and 'c' are not seen anymore
- 'C' now indicates a connected route
- Gateway value of a route of an interface address is now not
a L2 address but "link#N" like a connected (cloning) route
- Proxy ARP: "arp -s ... pub" doesn't create a route

You can know details of behavior changes by seeing diffs under tests/.

Proposed on tech-net and tech-kern:
http://mail-index.netbsd.org/tech-net/2016/03/11/msg005701.html


# 1.153 23-Jan-2016 christos

no need for <sys/mbuf.h>


# 1.152 17-Jan-2016 christos

PR/50671: David Binderman: fix memory leak.


# 1.151 23-Mar-2015 roy

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.


# 1.150 26-Feb-2015 roy

Teach route(8) about RTF_LOCAL.


# 1.149 20-Dec-2014 prlw1

MKINET6=no build fixes

http://mail-index.netbsd.org/tech-net/2014/12/13/msg004898.html


# 1.148 17-Dec-2014 roy

Note that RTM_CHANGE can also change the gateway


# 1.147 12-Nov-2014 christos

PR/47704: Takahiro HAYASHI: Add -L flag


# 1.146 07-Nov-2014 christos

Now that the code can support tags and verbose route printing, enable them.
Also document previously undocumented flags.


# 1.145 06-Nov-2014 christos

Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.144 19-Oct-2013 christos

branches: 1.144.4;
use correct function


# 1.143 19-Oct-2013 christos

use symbolic flags


# 1.142 19-Oct-2013 christos

use scopeid functions


# 1.141 18-Oct-2013 christos

avoid pointer gymnastics


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.140 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.139 04-Oct-2012 uwe

Fix fallout from 1.129 that converted sou::so_foo from unions to
pointers but missed (char *)&soup->so_foo => (char *)soup->so_foo in
mask_addr(). It worked by luck - unless it didn't: due to pointer
numerology on amd64 route add -net ClassC without explicit /24 prefix
length specification would result into /16 destination instead of /24.


# 1.138 08-Aug-2012 christos

branches: 1.138.2;
remove useless rump headers.


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.137 17-Mar-2012 christos

PR/42179: Christoph Badura: Be a little friendlier about missing args.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.136 26-Dec-2011 christos

branches: 1.136.2;
Off by one and clarity improvement from Christian Biere


# 1.135 24-Dec-2011 christos

PR/45661: Henning Petersen: Overlapping buffer in route.c.


# 1.134 11-Nov-2011 gdt

Move RTF_ANNOUNCE flag so that it no longer conflicts with RTF_PROTO2.

RTF_ANNOUNCE was defined as RTF_PROTO2. The flag is used to indicated
that host should act as a proxy for a link level arp or ndp request.
(If RTF_PROTO2 is used as an experimental flag (as advertised),
various problems can occur.)

This commit provides a first-class definition with its own bit for
RTF_ANNOUNCE, removes the old aliasing definitions, and adds support
for the new RTF_ANNOUNCE flag to netstat(8) and route(8).,

Also, remove unused RTF_ flags that collide with RTF_PROTO1:
netinet/icmp6.h defined RTF_PROBEMTU as RTF_PROTO1
netinet/if_inarp.h defined RTF_USETRAILERS as RTF_PROTO1
(Neither of these flags are used anywhere. Both have been removed
to reduce chances of collision with RTF_PROTO1.)

Figuring this out and the diff are the work of Beverly Schwartz of
BBN.

(Passed release build, boot in VM, with no apparently related atf
failures.)

Approved for Public Release, Distribution Unlimited
This material is based upon work supported by the Defense Advanced
Research Projects Agency and Space and Naval Warfare Systems Center,
Pacific, under Contract No. N66001-09-C-2073.


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.133 07-Oct-2011 joerg

branches: 1.133.2;
Simplify.


# 1.132 29-Aug-2011 joerg

Use __dead


# 1.131 01-Jul-2011 joerg

Fix memset usage.


# 1.130 22-Jun-2011 kefren

don't compile tag functions if SMALL is defined. Should fix the build


# 1.129 21-Jun-2011 kefren

Alloc dynamically sockunions in sou.
Teach route(8) about multiple tags. E.G.: -tag 100,20,33
XXX: needs documentation


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.128 01-Feb-2011 matt

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.


Revision tags: matt-mips64-premerge-20101231
# 1.127 13-Dec-2010 pooka

branches: 1.127.2;
Convert from RUMP_ACTION to RUMPPRG.


# 1.126 12-Nov-2010 roy

Support the new RTM_IFINFO and RTM_CHGADDR messages.


# 1.125 05-Nov-2010 pooka

adapt to new rumpclient_init() signature


# 1.124 04-Nov-2010 pooka

#ifdef variable correctly


# 1.123 04-Nov-2010 pooka

be consistent in what to leave outside of SMALL


# 1.122 04-Nov-2010 pooka

Support RUMP_ACTION to compile a rump kernel client.


# 1.121 26-Jun-2010 kefren

add MPLS clue - mpls and tag keywords


# 1.120 12-May-2010 christos

PR/40455: Mihai Chelaru: Add noreject noblackhole options


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base mjf-devfs2-base
# 1.119 28-Dec-2008 christos

parse unsigned long with strtoul not atoi


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3
# 1.118 10-Sep-2008 dyoung

branches: 1.118.6;
Get the socket addresses for dst/gateway/netmask/interface/ifaddr
out of the global namespace.


# 1.117 10-Sep-2008 dyoung

Don't cast a sockunion * to sockaddr *. Instead, reference the
sockaddr inside of the sockunion.


# 1.116 10-Sep-2008 dyoung

Delete superfluous casts to void *.


# 1.115 10-Sep-2008 dyoung

Constify.


# 1.114 10-Sep-2008 dyoung

Constify.


# 1.113 10-Sep-2008 dyoung

Constify.

For clarity's sake, do not assign a new value to inet_makenetandmask()'s
argument, `inet'.


# 1.112 09-Sep-2008 dyoung

Extract subroutine extract_addrs() for reuse, later.

Replace the anonymous constant, 0, with AF_UNSPEC.


# 1.111 09-Sep-2008 dyoung

Constify.


# 1.110 09-Sep-2008 dyoung

Shorten a staircase. Remove superfluous parentheses from return
statements. Constify.


# 1.109 09-Sep-2008 dyoung

Use a union and sizeof() to avoid a cast and an anonymous constant
buffer length, respectively.


# 1.108 09-Sep-2008 dyoung

Use bool.


Revision tags: wrstuden-revivesa-base-2
# 1.107 20-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking cube-autoconf-base mjf-devfs-base matt-armv6-base matt-mips64-base hpcarm-cleanup-base
# 1.106 18-Feb-2007 hubertf

branches: 1.106.12; 1.106.16;
TSEL() is const char* now


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base netbsd-4-base
# 1.105 11-Nov-2006 apb

Fix a bug that caused 0.0.0.0/0 to be treated like 0.0.0.0/32.

foo << 32 is undefined per section 6.5.7 of the C99 standard
if foo is (or is promoted to) a 32-bit type.


# 1.104 23-Sep-2006 dyoung

Let us qualify 'route flush' and 'route show' commands with -llinfo
and -host flags, which is useful for displaying/flushing ARP entries:

# route -n show -inet -llinfo -host
Routing table

Internet:
Destination Gateway Flags
169.254.1.119 link#1 UH
169.254.230.110 00:02:6f:21:e6:6e UH
# route -n flush -inet -llinfo -host
169.254.1.119 done
169.254.230.110 0.2.6f.21.e6.6e done
169.254.237.70 done
# route -n show -inet -llinfo -host
Routing table
#

This will help me address bin/11079, "dhclient may require arp and sed".

Extract common code from flushroutes() and show(), creating
parse_show_opts().

While I'm here, make small cosmetic changes to flushroutes().


# 1.103 23-Sep-2006 dyoung

Move the #ifndef SMALL code together.


# 1.102 23-Sep-2006 dyoung

Use the symbol AF_UNSPEC instead of 0 as appropriate.


# 1.101 23-Sep-2006 dyoung

Remove dead code.


# 1.100 26-Aug-2006 matt

Remove XNS and CCITT/X25 bits.


Revision tags: abandoned-netbsd-4-base
# 1.99 06-Aug-2006 dyoung

KNF err(3), errx(3) usage, indentation, braces.


# 1.98 06-Aug-2006 dyoung

Add route keywords -nocloned, -nocloning.


# 1.97 29-Jan-2006 wiz

Use default option order (AaBbCc...).


# 1.96 26-Jan-2006 is

Print the INET netmask if it is non-contiguous.


# 1.95 25-Jan-2006 christos

PR/32632: Yves-Emmanuel JUTARD: Improvment suggestion in 'route' display.
Add a new -S flag that prints a space for missing flags.


# 1.94 25-Jan-2006 christos

PR/32629: Yves-Emmanuel JUTARD: Type errors in sbin/route/route.c, another
u_char/char conflict.


# 1.93 31-Aug-2005 ginsbach

Add full IPv6 syntax support when route is built with -DSMALL and -DINET6.
Fixes PR/23937. Adapted from supplied patch.


# 1.92 30-Aug-2005 ginsbach

Clean up some minor nits:
+ style (KNF).
. don't cast NULL
. white space clean up
+ use consistent format for error messages.
+ plug memory leaks and avoid malloc(0).
+ verbose message should display even when routing table is empty
(flushroutes).


# 1.91 15-Aug-2005 ginsbach

Make sure that a netmask socket address value prints appropriately when the
family is unset. Either the destination or interface address socket address
family value is used. This change prevents the following sort of output:

RTM_NEWADDR: address being added to iface: len 60, metric 0, flags:<UP>
sockaddrs: <NETMASK,IFA,BRD>
(0) 00.00.ff.00.00 127.0.0.1 127.0.0.1

With this change the last line becomes:

255.0.0.0 127.0.0.1 127.0.0.1

Also make sure that when using a generated inet netmask the address family
is set. With this change a generated netmask will print appropriately
when using the verbose (-v) option.


# 1.90 12-Aug-2005 ginsbach

Make sure the get command always exits non-zero on error. This makes things
like the following work as expected.

#!/bin/sh

if ! route -sn get default >/dev/null 2>&1; then
echo default gateway not set
exit 1
fi
echo default gateway set

Handle routing socket write(2) errors when they occur. This produces
better diagnostics by allowing for handling of the special route errno
values ESRCH, EBUSY, and ENOBUFS even with the quiet (-q) option or
when doing a get command.


# 1.89 12-Aug-2005 ginsbach

Trim the local domain name in routename() for INET6 lookups; similar to
INET lookups.


# 1.88 10-Aug-2005 he

Make this build for __GNUC__ <= 2 (i.e. for vax). The cast to
caddr_t removes a const qualifier. Instead, cast the first element
of the subtraction to "struct sockaddr *" to work around the problem.


# 1.87 09-Aug-2005 ginsbach

Accept protocol flags, i.e. -inet, -inet6, with the show command.
[From OpenBSD via DragonFly BSD]


# 1.86 09-Aug-2005 ginsbach

Fix the default case in sodump(). Printing the address of the "which"
string isn't really that useful. Instead print the string and the value
of sa_family.


# 1.85 09-Aug-2005 ginsbach

More style nits (KNF); casts and sizeof's are not followed by a space.


# 1.84 20-Jul-2005 ginsbach

switch is not a function, so add a space; sort switch elements
alphabetically (KNF).


# 1.83 15-Jul-2005 ginsbach

* Exit non-zero error code when flushroute() fails operating on the
routing socket, e.g. running route flush as non-root.

* When quiet (-q) don't append error string to a non-existent
diagnostic output (stdout). The error diagnostic is still written
to stderr. [from FreeBSD]

* Use warn(3) in place of perror(3).


# 1.82 26-Jun-2005 christos

const poisoning.


# 1.81 25-Jun-2005 dyoung

Teach route(8) to print the messages generated by net80211.


# 1.80 19-May-2005 ginsbach

Convert prefixlen() to ANSI function declaration. Missed by earlier
conversion.


# 1.79 19-May-2005 ginsbach

Due to a limitation in inet_addr(3) it was not possible to specify a
netmask value of 0xffffffff (INADDR_NONE). Fix by using inet_aton(3).
Note it was possible to specify the same mask as the dotted quad
255.255.255.255 because of a later call to gethostbyname(3).
[From FreeBSD]


# 1.78 13-May-2005 ginsbach

Fix botched prior commit. Additional debugging error messages mistakenly
committed.


# 1.77 12-May-2005 ginsbach

* Honor -net when using CIDR (net/mask) notation. This differs
from the default CIDR (host/mask) interpretation. As discussed on
tech-net.

* Use errx() in place of fprintf() and exit(). Make the error message
formats consistent.


# 1.76 10-May-2005 ginsbach

Fix macro NEXTADDR so that the names, like so_dst, are printed
rather than u. The preprocessor doesn't do replacement within
strings, so the # string creation operator must be used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.75 05-Feb-2005 xtraeme

Kill __P(), use ANSI function declarations.


# 1.74 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


# 1.73 15-May-2004 itojun

bump buffer size for any_ntoa(), for huge sa_len


# 1.72 15-May-2004 itojun

2-byte read overrun for unknown sockaddr. from openbsd
XXX out[64], is it safe? what if sa_len > 23?


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.71 05-Jan-2004 jmmv

Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.


# 1.70 01-Oct-2003 itojun

print prefixlen on -show


# 1.69 16-Sep-2003 cube

Remove a comment that referred to a non-committed part of the patch I
submitted for bin/17613. Ok'd by mrg@.


# 1.68 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.


# 1.67 19-Jul-2003 jrf

This is an updated submitted patch originally written by Jim Rees
and sent in by Greg Hudson as seen in PR misc/3227. Basically what it
does is adds a flushall option which deletes all but localhost routes.
This is done by andoring in a flag called doall (1 means do all routes
including gateway, 0 means do a regular flush). I have seen some
platforms that do this. I tested it out on ipv4 only, it works as
advertised. Commit was approved by christos@.


# 1.66 11-Jun-2003 christos

PR/21856: Robert Elz: Changes to route(8) to allow /n instead of -prefixlen
for INET6


# 1.65 03-Jun-2003 itojun

permit foo/bar notation, like "route add 10.0.0.0/8 127.0.0.1".
originally by provos


# 1.64 17-May-2003 itojun

strlcpy [a few mistakes found]


# 1.63 21-Apr-2003 jrf

This addresses PR 17613 when certain methods of adding routes would
muck up the routing tables. The patch was submitted by Quentin Garnier
<netbsd@quatriemek.com> and tweaked a little after it was reviewed
by Christos Zoulas <christos@netbsd.org>. Final change/commit approved
by Christos.


# 1.62 03-Apr-2003 jrf

Made a note in the code about the -d and -d options brought up in
PR 18674. Thanks to Chris Jones for pointing it out.


Revision tags: fvdl_fs64_base
# 1.61 18-Oct-2002 itojun

correct prefixlen handling for IPv4.


# 1.60 18-Oct-2002 itojun

Make prefixlen check to make sure its argument is present before deref
from openbsd


# 1.59 20-Jul-2002 grant

sweep of errx/warnx, remove unnecessary trailing \n


# 1.58 10-Jun-2002 itojun

permit DNS names to address portion. they will be considered as RTF_HOST
if specified as destination (as there's no getnetbyname in IPv6).


# 1.57 05-Jun-2002 itojun

if we're unsure about prefixlen, don't say "128".


# 1.56 05-Jun-2002 itojun

more correct ion to RTF_HOST handling.


# 1.55 04-Jun-2002 itojun

do not have -prefixlen 128 on RTF_HOST.
From: Dawid Szymanski <dawszy@arhea.net>


Revision tags: netbsd-1-6-base
# 1.54 20-May-2002 itojun

branches: 1.54.2;
raise RTF_HOST if destination is a host (/128). from ume


# 1.53 21-Feb-2002 christos

PR/15672: Love: route monitor missing info


# 1.52 15-Nov-2001 christos

Make route exit with a non-zero error code when operations to the routing
socket fails. eg, running route add 1.2.3.4 5.6.7.8 as non root.


# 1.51 02-Nov-2001 lukem

fix -Wshadow warnings


# 1.50 24-Oct-2001 atatat

Provide a short output format for the get command that only prints the
address corresponding to RTA_GATEWAY, or nothing if it doesn't exist.
Modify the exit value of route depending on this, so that one can do
stuff like:

#!/bin/sh
gw=`route -sn get default 2>/dev/null`
if [ -z "$gw" ]; then
echo no default route
exit 1
fi
ping -w1 -c1 $gw >/dev/null 2>&1
if ! route -sn get $gw >/dev/null; then
echo default gateway not responding
exit 1
fi
echo default gateway is at $gw


# 1.49 24-Oct-2001 atatat

Print a R on reject routes to indicate that they're not normal routes,
and check netmask (or prefix) length as well as the destination
address when determining if a route is a "default" or not. This means
that the output from 'route show' will no longer say:

Internet6:
Destination Gateway Flags
default localhost UG
default localhost UG

but instead

Internet6:
Destination Gateway Flags
::/104 localhost UGR
::/96 localhost UGR

which makes much more sense.


# 1.48 20-Jul-2001 itojun

off-by-one error in -prefixlen arg validation (do not permit 129 on IPv6)


# 1.47 20-Jul-2001 itojun

make prefixlen work on IPv4 too


# 1.46 16-Jul-2001 bad

The way pmsg_addrs() is used requires that it always prints a newline and
flushes stdout before returning.

Previously the decoded output for a message was stuck in stdio buffers until
the next arrived.


# 1.45 19-Feb-2001 cgd

convert to use getprogname()


# 1.44 04-Feb-2001 christos

remove nested externs.


# 1.43 27-Jan-2001 itojun

support -cloned command line flag.
i don't think anyone ever going to use it.


# 1.42 27-Jan-2001 itojun

mark cloned routes with RTF_CLONED. present it with netstat -r by "c".

let static routes overwrite cloned routes, as cloned routes can come back again
if necessary. behavior same as freebsd/bsdi, code partially from bsdi42.
(NRL rt->rt_parent was not added)
should fix PR 11916 and maybe some other PRs with ARP behavior.

recompilation of usr.sbin/route6d is suggested.


# 1.41 27-Jan-2001 itojun

support RTF_BLACKHOLE.

XXX route show is total duplicate of netstat -r, we need to either remove
route show, or share the same source code, otherwise maintenance cost
bites (and is biting) us


# 1.40 27-Jan-2001 itojun

remove use of uninitialized route (struct ortentry).
it seems that the bug was born during 4.3reno -> 4.4Lite1 transition.


# 1.39 10-Oct-2000 itojun

on "route monitor", print RTM_IFANNOUNCE, RTM_IFINFO (new #), and others.


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.38 04-May-2000 sommerfeld

branches: 1.38.4;
Allow INET6 to be used with SMALL without undefined symbols


# 1.37 20-Apr-2000 itojun

use scoped notation for link-local multicast too.


# 1.36 20-Apr-2000 itojun

support extended scoped address notation (fe80::1%de0).
it hides implementation detail (embedded ifid) from the users.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.35 03-Dec-1999 itojun

don't make "-prefixlen 64" a default in -inet6 case. the past behavior
was not compatible with past practice ("route get" did not work right).

sync with recent KAME.


Revision tags: comdex-fall-1999-base
# 1.34 01-Nov-1999 sommerfeld

Display local address associated with route (if any) in "route get".


# 1.33 03-Sep-1999 itojun

branches: 1.33.2;
fix alignment issue in routing socket data, on 64bit arch (i.e. alpha).
sockaddrs are packed with ROUNDUP() in sys/net/rtsock.c so userland
programs needs to follow that.

PR: 8179


# 1.32 06-Jul-1999 mjacob

Incorrect integration. ctime takes a time_t value, not a long.


# 1.31 02-Jul-1999 itojun

IPv6-ready route command (-inet6 and -prefixlen are added)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.30 23-Oct-1998 lukem

branches: 1.30.2;
* implement -f; flush all routes before executing command
* reset af to 0 in flushroutes() and newroute()
* cleanup -DSMALL:
- `flush' and AF_APPLETALK is supported (the latter had partial support)
- AF_NS, AF_ISO, and AF_CCITT are not supported at all (rather than being
- partially unsupported).


# 1.29 26-Jul-1998 mycroft

const poisoning.


# 1.28 01-Apr-1998 kleink

Need <time.h> for time() prototype.


# 1.27 05-Feb-1998 ross

64-bit sweep, "route -v show" was spinning forever.


# 1.26 16-Nov-1997 christos

Use {warn,err}{,x}(3) instead of printf's


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 01-Oct-1997 enami

Don't declare optind.


# 1.24 16-Sep-1997 lukem

resolve conflicts from lite-2 import


# 1.23 15-Sep-1997 lukem

* cleanup for WARNS=1
* use .Nm correctly
* deprecate register
* getopt returns -1 not EOF


# 1.22 02-Sep-1997 thorpej

Fix uninitialized pointer botch when attempting to flush an already
empty routing table. From Matthias Scheler <tron@lyssa.owl.de>, in
PR #4074.


# 1.21 27-Apr-1997 thorpej

Don't SEGV if a qualifier is passed without an argument. From
Geoff Wing <mason@primenet.com.au>, fixes PR #2700.


# 1.20 21-Apr-1997 mrg

KNF. be safe with buffers.


# 1.19 03-Apr-1997 christos

- Add netatalk bits
- Add prototypes
- Fix printf formats


# 1.18 22-Feb-1997 carrel

Remove uid checks since the kernel now handles this and route(1) is no
longer setuid.
Document the "Permission denied" msg in the man page since this is
_slightly_ less clear than route(1)'s old error msg.


# 1.17 15-Nov-1996 gwr

As discussed some time ago, add a "show" sub-command.
Also allow compilation with -DSMALL to ommit support for
non-essential protocols (i.e. when built into a ramdisk).
Use a less hack-ish way to generate keywords.[ch] and just
check in the result (helps ../../distrib/utils/x_route).


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.16 15-Apr-1996 cgd

check returns of inet_addr() and inet_network() against INADDR_NONE,
not -1, per the manual page. on 64-bit systems like the alpha, -1 will
never equal (unsigned long)INADDR_NONE.


# 1.15 07-Jan-1996 pk

Produce less output on -q as promised by the man page (John Hawkinson; PR#998).


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.14 20-Apr-1995 mycroft

Interface-specific routes can be static.


# 1.13 20-Apr-1995 mycroft

Implement the document `-llinfo' flag.


# 1.12 18-Apr-1995 mycroft

Remove extra `break;'.


# 1.11 18-Mar-1995 cgd

convert to new RCS Id conventions; reduce my headache


# 1.10 24-Dec-1994 cgd

kill some extraneous equal signs.


# 1.9 23-Sep-1994 mycroft

Remove some more uses of obsolete functions.


# 1.8 23-Sep-1994 mycroft

Eliminate uses of some obsolete functions.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.7 13-May-1994 mycroft

Clean up import.


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 25-Apr-1993 mycroft

Compile X.25, OSI, and NS code.


# 1.4 18-Apr-1993 mycroft

Cleanup for GCC 2.


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.3 23-Mar-1993 cgd

changed "Id" to "Header" for rcsids


# 1.2 22-Mar-1993 cgd

added rcs ids to all files


# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
Initial revision


# 1.161 22-Aug-2019 roy

route(8): print RTM_CHANGE messages

XXX Pullup -9


Revision tags: netbsd-9-base phil-wifi-20190609 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906
# 1.160 14-Aug-2018 roy

Resolve every route(4) message type before printing anything more about it
other than the type and length.

This solves the issue where RTM_ONEWADDR is received and it tries to
parse route information from it.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330
# 1.159 23-Mar-2018 roy

branches: 1.159.2;
Handle the routing socket overflowing gracefully.


Revision tags: pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.158 13-Dec-2017 christos

branches: 1.158.2;
Use the definitions from the standard header files and replace homebrew
snprintb with the libutil one.


# 1.157 13-Dec-2017 uwe

Fix typo in flag name. We should probably just use IFFBITS string
that <net/if.h> defines.

PR bin/52815


Revision tags: perseant-stdc-iso10646-base
# 1.156 16-Jun-2017 ozaki-r

Support -c <count> option for route monitor

route command exits if it receives <count> routing messages where
<count> is a value specified by -c.

The option is useful to get only particular message(s) in a test script.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320
# 1.155 17-Mar-2017 roy

branches: 1.155.4;
Report the PID for the process changing the address.


Revision tags: bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.154 04-Apr-2016 ozaki-r

branches: 1.154.2; 1.154.4;
Separate nexthop caches from the routing table

By this change, nexthop caches (IP-MAC address pair) are not stored
in the routing table anymore. Instead nexthop caches are stored in
each network interface; we already have lltable/llentry data structure
for this purpose. This change also obsoletes the concept of cloning/cloned
routes. Cloned routes no longer exist while cloning routes still exist
with renamed to connected routes.

Noticeable changes are:
- Nexthop caches aren't listed in route show/netstat -r
- sysctl(NET_RT_DUMP) doesn't return them
- If RTF_LLDATA is specified, it returns nexthop caches
- Several definitions of routing flags and messages are removed
- RTF_CLONING, RTF_XRESOLVE, RTF_LLINFO, RTF_CLONED and RTM_RESOLVE
- RTF_CONNECTED is added
- It has the same value of RTF_CLONING for backward compatibility
- route's -xresolve, -[no]cloned and -llinfo options are removed
- -[no]cloning remains because it seems there are users
- -[no]connected is introduced and recommended
to be used instead of -[no]cloning
- route show/netstat -r drops some flags
- 'L' and 'c' are not seen anymore
- 'C' now indicates a connected route
- Gateway value of a route of an interface address is now not
a L2 address but "link#N" like a connected (cloning) route
- Proxy ARP: "arp -s ... pub" doesn't create a route

You can know details of behavior changes by seeing diffs under tests/.

Proposed on tech-net and tech-kern:
http://mail-index.netbsd.org/tech-net/2016/03/11/msg005701.html


# 1.153 23-Jan-2016 christos

no need for <sys/mbuf.h>


# 1.152 17-Jan-2016 christos

PR/50671: David Binderman: fix memory leak.


# 1.151 23-Mar-2015 roy

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.


# 1.150 26-Feb-2015 roy

Teach route(8) about RTF_LOCAL.


# 1.149 20-Dec-2014 prlw1

MKINET6=no build fixes

http://mail-index.netbsd.org/tech-net/2014/12/13/msg004898.html


# 1.148 17-Dec-2014 roy

Note that RTM_CHANGE can also change the gateway


# 1.147 12-Nov-2014 christos

PR/47704: Takahiro HAYASHI: Add -L flag


# 1.146 07-Nov-2014 christos

Now that the code can support tags and verbose route printing, enable them.
Also document previously undocumented flags.


# 1.145 06-Nov-2014 christos

Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.144 19-Oct-2013 christos

branches: 1.144.4;
use correct function


# 1.143 19-Oct-2013 christos

use symbolic flags


# 1.142 19-Oct-2013 christos

use scopeid functions


# 1.141 18-Oct-2013 christos

avoid pointer gymnastics


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.140 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.139 04-Oct-2012 uwe

Fix fallout from 1.129 that converted sou::so_foo from unions to
pointers but missed (char *)&soup->so_foo => (char *)soup->so_foo in
mask_addr(). It worked by luck - unless it didn't: due to pointer
numerology on amd64 route add -net ClassC without explicit /24 prefix
length specification would result into /16 destination instead of /24.


# 1.138 08-Aug-2012 christos

branches: 1.138.2;
remove useless rump headers.


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.137 17-Mar-2012 christos

PR/42179: Christoph Badura: Be a little friendlier about missing args.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.136 26-Dec-2011 christos

branches: 1.136.2;
Off by one and clarity improvement from Christian Biere


# 1.135 24-Dec-2011 christos

PR/45661: Henning Petersen: Overlapping buffer in route.c.


# 1.134 11-Nov-2011 gdt

Move RTF_ANNOUNCE flag so that it no longer conflicts with RTF_PROTO2.

RTF_ANNOUNCE was defined as RTF_PROTO2. The flag is used to indicated
that host should act as a proxy for a link level arp or ndp request.
(If RTF_PROTO2 is used as an experimental flag (as advertised),
various problems can occur.)

This commit provides a first-class definition with its own bit for
RTF_ANNOUNCE, removes the old aliasing definitions, and adds support
for the new RTF_ANNOUNCE flag to netstat(8) and route(8).,

Also, remove unused RTF_ flags that collide with RTF_PROTO1:
netinet/icmp6.h defined RTF_PROBEMTU as RTF_PROTO1
netinet/if_inarp.h defined RTF_USETRAILERS as RTF_PROTO1
(Neither of these flags are used anywhere. Both have been removed
to reduce chances of collision with RTF_PROTO1.)

Figuring this out and the diff are the work of Beverly Schwartz of
BBN.

(Passed release build, boot in VM, with no apparently related atf
failures.)

Approved for Public Release, Distribution Unlimited
This material is based upon work supported by the Defense Advanced
Research Projects Agency and Space and Naval Warfare Systems Center,
Pacific, under Contract No. N66001-09-C-2073.


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.133 07-Oct-2011 joerg

branches: 1.133.2;
Simplify.


# 1.132 29-Aug-2011 joerg

Use __dead


# 1.131 01-Jul-2011 joerg

Fix memset usage.


# 1.130 22-Jun-2011 kefren

don't compile tag functions if SMALL is defined. Should fix the build


# 1.129 21-Jun-2011 kefren

Alloc dynamically sockunions in sou.
Teach route(8) about multiple tags. E.G.: -tag 100,20,33
XXX: needs documentation


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.128 01-Feb-2011 matt

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.


Revision tags: matt-mips64-premerge-20101231
# 1.127 13-Dec-2010 pooka

branches: 1.127.2;
Convert from RUMP_ACTION to RUMPPRG.


# 1.126 12-Nov-2010 roy

Support the new RTM_IFINFO and RTM_CHGADDR messages.


# 1.125 05-Nov-2010 pooka

adapt to new rumpclient_init() signature


# 1.124 04-Nov-2010 pooka

#ifdef variable correctly


# 1.123 04-Nov-2010 pooka

be consistent in what to leave outside of SMALL


# 1.122 04-Nov-2010 pooka

Support RUMP_ACTION to compile a rump kernel client.


# 1.121 26-Jun-2010 kefren

add MPLS clue - mpls and tag keywords


# 1.120 12-May-2010 christos

PR/40455: Mihai Chelaru: Add noreject noblackhole options


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base mjf-devfs2-base
# 1.119 28-Dec-2008 christos

parse unsigned long with strtoul not atoi


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3
# 1.118 10-Sep-2008 dyoung

branches: 1.118.6;
Get the socket addresses for dst/gateway/netmask/interface/ifaddr
out of the global namespace.


# 1.117 10-Sep-2008 dyoung

Don't cast a sockunion * to sockaddr *. Instead, reference the
sockaddr inside of the sockunion.


# 1.116 10-Sep-2008 dyoung

Delete superfluous casts to void *.


# 1.115 10-Sep-2008 dyoung

Constify.


# 1.114 10-Sep-2008 dyoung

Constify.


# 1.113 10-Sep-2008 dyoung

Constify.

For clarity's sake, do not assign a new value to inet_makenetandmask()'s
argument, `inet'.


# 1.112 09-Sep-2008 dyoung

Extract subroutine extract_addrs() for reuse, later.

Replace the anonymous constant, 0, with AF_UNSPEC.


# 1.111 09-Sep-2008 dyoung

Constify.


# 1.110 09-Sep-2008 dyoung

Shorten a staircase. Remove superfluous parentheses from return
statements. Constify.


# 1.109 09-Sep-2008 dyoung

Use a union and sizeof() to avoid a cast and an anonymous constant
buffer length, respectively.


# 1.108 09-Sep-2008 dyoung

Use bool.


Revision tags: wrstuden-revivesa-base-2
# 1.107 20-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking cube-autoconf-base mjf-devfs-base matt-armv6-base matt-mips64-base hpcarm-cleanup-base
# 1.106 18-Feb-2007 hubertf

branches: 1.106.12; 1.106.16;
TSEL() is const char* now


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base netbsd-4-base
# 1.105 11-Nov-2006 apb

Fix a bug that caused 0.0.0.0/0 to be treated like 0.0.0.0/32.

foo << 32 is undefined per section 6.5.7 of the C99 standard
if foo is (or is promoted to) a 32-bit type.


# 1.104 23-Sep-2006 dyoung

Let us qualify 'route flush' and 'route show' commands with -llinfo
and -host flags, which is useful for displaying/flushing ARP entries:

# route -n show -inet -llinfo -host
Routing table

Internet:
Destination Gateway Flags
169.254.1.119 link#1 UH
169.254.230.110 00:02:6f:21:e6:6e UH
# route -n flush -inet -llinfo -host
169.254.1.119 done
169.254.230.110 0.2.6f.21.e6.6e done
169.254.237.70 done
# route -n show -inet -llinfo -host
Routing table
#

This will help me address bin/11079, "dhclient may require arp and sed".

Extract common code from flushroutes() and show(), creating
parse_show_opts().

While I'm here, make small cosmetic changes to flushroutes().


# 1.103 23-Sep-2006 dyoung

Move the #ifndef SMALL code together.


# 1.102 23-Sep-2006 dyoung

Use the symbol AF_UNSPEC instead of 0 as appropriate.


# 1.101 23-Sep-2006 dyoung

Remove dead code.


# 1.100 26-Aug-2006 matt

Remove XNS and CCITT/X25 bits.


Revision tags: abandoned-netbsd-4-base
# 1.99 06-Aug-2006 dyoung

KNF err(3), errx(3) usage, indentation, braces.


# 1.98 06-Aug-2006 dyoung

Add route keywords -nocloned, -nocloning.


# 1.97 29-Jan-2006 wiz

Use default option order (AaBbCc...).


# 1.96 26-Jan-2006 is

Print the INET netmask if it is non-contiguous.


# 1.95 25-Jan-2006 christos

PR/32632: Yves-Emmanuel JUTARD: Improvment suggestion in 'route' display.
Add a new -S flag that prints a space for missing flags.


# 1.94 25-Jan-2006 christos

PR/32629: Yves-Emmanuel JUTARD: Type errors in sbin/route/route.c, another
u_char/char conflict.


# 1.93 31-Aug-2005 ginsbach

Add full IPv6 syntax support when route is built with -DSMALL and -DINET6.
Fixes PR/23937. Adapted from supplied patch.


# 1.92 30-Aug-2005 ginsbach

Clean up some minor nits:
+ style (KNF).
. don't cast NULL
. white space clean up
+ use consistent format for error messages.
+ plug memory leaks and avoid malloc(0).
+ verbose message should display even when routing table is empty
(flushroutes).


# 1.91 15-Aug-2005 ginsbach

Make sure that a netmask socket address value prints appropriately when the
family is unset. Either the destination or interface address socket address
family value is used. This change prevents the following sort of output:

RTM_NEWADDR: address being added to iface: len 60, metric 0, flags:<UP>
sockaddrs: <NETMASK,IFA,BRD>
(0) 00.00.ff.00.00 127.0.0.1 127.0.0.1

With this change the last line becomes:

255.0.0.0 127.0.0.1 127.0.0.1

Also make sure that when using a generated inet netmask the address family
is set. With this change a generated netmask will print appropriately
when using the verbose (-v) option.


# 1.90 12-Aug-2005 ginsbach

Make sure the get command always exits non-zero on error. This makes things
like the following work as expected.

#!/bin/sh

if ! route -sn get default >/dev/null 2>&1; then
echo default gateway not set
exit 1
fi
echo default gateway set

Handle routing socket write(2) errors when they occur. This produces
better diagnostics by allowing for handling of the special route errno
values ESRCH, EBUSY, and ENOBUFS even with the quiet (-q) option or
when doing a get command.


# 1.89 12-Aug-2005 ginsbach

Trim the local domain name in routename() for INET6 lookups; similar to
INET lookups.


# 1.88 10-Aug-2005 he

Make this build for __GNUC__ <= 2 (i.e. for vax). The cast to
caddr_t removes a const qualifier. Instead, cast the first element
of the subtraction to "struct sockaddr *" to work around the problem.


# 1.87 09-Aug-2005 ginsbach

Accept protocol flags, i.e. -inet, -inet6, with the show command.
[From OpenBSD via DragonFly BSD]


# 1.86 09-Aug-2005 ginsbach

Fix the default case in sodump(). Printing the address of the "which"
string isn't really that useful. Instead print the string and the value
of sa_family.


# 1.85 09-Aug-2005 ginsbach

More style nits (KNF); casts and sizeof's are not followed by a space.


# 1.84 20-Jul-2005 ginsbach

switch is not a function, so add a space; sort switch elements
alphabetically (KNF).


# 1.83 15-Jul-2005 ginsbach

* Exit non-zero error code when flushroute() fails operating on the
routing socket, e.g. running route flush as non-root.

* When quiet (-q) don't append error string to a non-existent
diagnostic output (stdout). The error diagnostic is still written
to stderr. [from FreeBSD]

* Use warn(3) in place of perror(3).


# 1.82 26-Jun-2005 christos

const poisoning.


# 1.81 25-Jun-2005 dyoung

Teach route(8) to print the messages generated by net80211.


# 1.80 19-May-2005 ginsbach

Convert prefixlen() to ANSI function declaration. Missed by earlier
conversion.


# 1.79 19-May-2005 ginsbach

Due to a limitation in inet_addr(3) it was not possible to specify a
netmask value of 0xffffffff (INADDR_NONE). Fix by using inet_aton(3).
Note it was possible to specify the same mask as the dotted quad
255.255.255.255 because of a later call to gethostbyname(3).
[From FreeBSD]


# 1.78 13-May-2005 ginsbach

Fix botched prior commit. Additional debugging error messages mistakenly
committed.


# 1.77 12-May-2005 ginsbach

* Honor -net when using CIDR (net/mask) notation. This differs
from the default CIDR (host/mask) interpretation. As discussed on
tech-net.

* Use errx() in place of fprintf() and exit(). Make the error message
formats consistent.


# 1.76 10-May-2005 ginsbach

Fix macro NEXTADDR so that the names, like so_dst, are printed
rather than u. The preprocessor doesn't do replacement within
strings, so the # string creation operator must be used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.75 05-Feb-2005 xtraeme

Kill __P(), use ANSI function declarations.


# 1.74 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


# 1.73 15-May-2004 itojun

bump buffer size for any_ntoa(), for huge sa_len


# 1.72 15-May-2004 itojun

2-byte read overrun for unknown sockaddr. from openbsd
XXX out[64], is it safe? what if sa_len > 23?


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.71 05-Jan-2004 jmmv

Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.


# 1.70 01-Oct-2003 itojun

print prefixlen on -show


# 1.69 16-Sep-2003 cube

Remove a comment that referred to a non-committed part of the patch I
submitted for bin/17613. Ok'd by mrg@.


# 1.68 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.


# 1.67 19-Jul-2003 jrf

This is an updated submitted patch originally written by Jim Rees
and sent in by Greg Hudson as seen in PR misc/3227. Basically what it
does is adds a flushall option which deletes all but localhost routes.
This is done by andoring in a flag called doall (1 means do all routes
including gateway, 0 means do a regular flush). I have seen some
platforms that do this. I tested it out on ipv4 only, it works as
advertised. Commit was approved by christos@.


# 1.66 11-Jun-2003 christos

PR/21856: Robert Elz: Changes to route(8) to allow /n instead of -prefixlen
for INET6


# 1.65 03-Jun-2003 itojun

permit foo/bar notation, like "route add 10.0.0.0/8 127.0.0.1".
originally by provos


# 1.64 17-May-2003 itojun

strlcpy [a few mistakes found]


# 1.63 21-Apr-2003 jrf

This addresses PR 17613 when certain methods of adding routes would
muck up the routing tables. The patch was submitted by Quentin Garnier
<netbsd@quatriemek.com> and tweaked a little after it was reviewed
by Christos Zoulas <christos@netbsd.org>. Final change/commit approved
by Christos.


# 1.62 03-Apr-2003 jrf

Made a note in the code about the -d and -d options brought up in
PR 18674. Thanks to Chris Jones for pointing it out.


Revision tags: fvdl_fs64_base
# 1.61 18-Oct-2002 itojun

correct prefixlen handling for IPv4.


# 1.60 18-Oct-2002 itojun

Make prefixlen check to make sure its argument is present before deref
from openbsd


# 1.59 20-Jul-2002 grant

sweep of errx/warnx, remove unnecessary trailing \n


# 1.58 10-Jun-2002 itojun

permit DNS names to address portion. they will be considered as RTF_HOST
if specified as destination (as there's no getnetbyname in IPv6).


# 1.57 05-Jun-2002 itojun

if we're unsure about prefixlen, don't say "128".


# 1.56 05-Jun-2002 itojun

more correct ion to RTF_HOST handling.


# 1.55 04-Jun-2002 itojun

do not have -prefixlen 128 on RTF_HOST.
From: Dawid Szymanski <dawszy@arhea.net>


Revision tags: netbsd-1-6-base
# 1.54 20-May-2002 itojun

branches: 1.54.2;
raise RTF_HOST if destination is a host (/128). from ume


# 1.53 21-Feb-2002 christos

PR/15672: Love: route monitor missing info


# 1.52 15-Nov-2001 christos

Make route exit with a non-zero error code when operations to the routing
socket fails. eg, running route add 1.2.3.4 5.6.7.8 as non root.


# 1.51 02-Nov-2001 lukem

fix -Wshadow warnings


# 1.50 24-Oct-2001 atatat

Provide a short output format for the get command that only prints the
address corresponding to RTA_GATEWAY, or nothing if it doesn't exist.
Modify the exit value of route depending on this, so that one can do
stuff like:

#!/bin/sh
gw=`route -sn get default 2>/dev/null`
if [ -z "$gw" ]; then
echo no default route
exit 1
fi
ping -w1 -c1 $gw >/dev/null 2>&1
if ! route -sn get $gw >/dev/null; then
echo default gateway not responding
exit 1
fi
echo default gateway is at $gw


# 1.49 24-Oct-2001 atatat

Print a R on reject routes to indicate that they're not normal routes,
and check netmask (or prefix) length as well as the destination
address when determining if a route is a "default" or not. This means
that the output from 'route show' will no longer say:

Internet6:
Destination Gateway Flags
default localhost UG
default localhost UG

but instead

Internet6:
Destination Gateway Flags
::/104 localhost UGR
::/96 localhost UGR

which makes much more sense.


# 1.48 20-Jul-2001 itojun

off-by-one error in -prefixlen arg validation (do not permit 129 on IPv6)


# 1.47 20-Jul-2001 itojun

make prefixlen work on IPv4 too


# 1.46 16-Jul-2001 bad

The way pmsg_addrs() is used requires that it always prints a newline and
flushes stdout before returning.

Previously the decoded output for a message was stuck in stdio buffers until
the next arrived.


# 1.45 19-Feb-2001 cgd

convert to use getprogname()


# 1.44 04-Feb-2001 christos

remove nested externs.


# 1.43 27-Jan-2001 itojun

support -cloned command line flag.
i don't think anyone ever going to use it.


# 1.42 27-Jan-2001 itojun

mark cloned routes with RTF_CLONED. present it with netstat -r by "c".

let static routes overwrite cloned routes, as cloned routes can come back again
if necessary. behavior same as freebsd/bsdi, code partially from bsdi42.
(NRL rt->rt_parent was not added)
should fix PR 11916 and maybe some other PRs with ARP behavior.

recompilation of usr.sbin/route6d is suggested.


# 1.41 27-Jan-2001 itojun

support RTF_BLACKHOLE.

XXX route show is total duplicate of netstat -r, we need to either remove
route show, or share the same source code, otherwise maintenance cost
bites (and is biting) us


# 1.40 27-Jan-2001 itojun

remove use of uninitialized route (struct ortentry).
it seems that the bug was born during 4.3reno -> 4.4Lite1 transition.


# 1.39 10-Oct-2000 itojun

on "route monitor", print RTM_IFANNOUNCE, RTM_IFINFO (new #), and others.


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.38 04-May-2000 sommerfeld

branches: 1.38.4;
Allow INET6 to be used with SMALL without undefined symbols


# 1.37 20-Apr-2000 itojun

use scoped notation for link-local multicast too.


# 1.36 20-Apr-2000 itojun

support extended scoped address notation (fe80::1%de0).
it hides implementation detail (embedded ifid) from the users.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.35 03-Dec-1999 itojun

don't make "-prefixlen 64" a default in -inet6 case. the past behavior
was not compatible with past practice ("route get" did not work right).

sync with recent KAME.


Revision tags: comdex-fall-1999-base
# 1.34 01-Nov-1999 sommerfeld

Display local address associated with route (if any) in "route get".


# 1.33 03-Sep-1999 itojun

branches: 1.33.2;
fix alignment issue in routing socket data, on 64bit arch (i.e. alpha).
sockaddrs are packed with ROUNDUP() in sys/net/rtsock.c so userland
programs needs to follow that.

PR: 8179


# 1.32 06-Jul-1999 mjacob

Incorrect integration. ctime takes a time_t value, not a long.


# 1.31 02-Jul-1999 itojun

IPv6-ready route command (-inet6 and -prefixlen are added)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.30 23-Oct-1998 lukem

branches: 1.30.2;
* implement -f; flush all routes before executing command
* reset af to 0 in flushroutes() and newroute()
* cleanup -DSMALL:
- `flush' and AF_APPLETALK is supported (the latter had partial support)
- AF_NS, AF_ISO, and AF_CCITT are not supported at all (rather than being
- partially unsupported).


# 1.29 26-Jul-1998 mycroft

const poisoning.


# 1.28 01-Apr-1998 kleink

Need <time.h> for time() prototype.


# 1.27 05-Feb-1998 ross

64-bit sweep, "route -v show" was spinning forever.


# 1.26 16-Nov-1997 christos

Use {warn,err}{,x}(3) instead of printf's


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 01-Oct-1997 enami

Don't declare optind.


# 1.24 16-Sep-1997 lukem

resolve conflicts from lite-2 import


# 1.23 15-Sep-1997 lukem

* cleanup for WARNS=1
* use .Nm correctly
* deprecate register
* getopt returns -1 not EOF


# 1.22 02-Sep-1997 thorpej

Fix uninitialized pointer botch when attempting to flush an already
empty routing table. From Matthias Scheler <tron@lyssa.owl.de>, in
PR #4074.


# 1.21 27-Apr-1997 thorpej

Don't SEGV if a qualifier is passed without an argument. From
Geoff Wing <mason@primenet.com.au>, fixes PR #2700.


# 1.20 21-Apr-1997 mrg

KNF. be safe with buffers.


# 1.19 03-Apr-1997 christos

- Add netatalk bits
- Add prototypes
- Fix printf formats


# 1.18 22-Feb-1997 carrel

Remove uid checks since the kernel now handles this and route(1) is no
longer setuid.
Document the "Permission denied" msg in the man page since this is
_slightly_ less clear than route(1)'s old error msg.


# 1.17 15-Nov-1996 gwr

As discussed some time ago, add a "show" sub-command.
Also allow compilation with -DSMALL to ommit support for
non-essential protocols (i.e. when built into a ramdisk).
Use a less hack-ish way to generate keywords.[ch] and just
check in the result (helps ../../distrib/utils/x_route).


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.16 15-Apr-1996 cgd

check returns of inet_addr() and inet_network() against INADDR_NONE,
not -1, per the manual page. on 64-bit systems like the alpha, -1 will
never equal (unsigned long)INADDR_NONE.


# 1.15 07-Jan-1996 pk

Produce less output on -q as promised by the man page (John Hawkinson; PR#998).


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.14 20-Apr-1995 mycroft

Interface-specific routes can be static.


# 1.13 20-Apr-1995 mycroft

Implement the document `-llinfo' flag.


# 1.12 18-Apr-1995 mycroft

Remove extra `break;'.


# 1.11 18-Mar-1995 cgd

convert to new RCS Id conventions; reduce my headache


# 1.10 24-Dec-1994 cgd

kill some extraneous equal signs.


# 1.9 23-Sep-1994 mycroft

Remove some more uses of obsolete functions.


# 1.8 23-Sep-1994 mycroft

Eliminate uses of some obsolete functions.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.7 13-May-1994 mycroft

Clean up import.


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 25-Apr-1993 mycroft

Compile X.25, OSI, and NS code.


# 1.4 18-Apr-1993 mycroft

Cleanup for GCC 2.


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.3 23-Mar-1993 cgd

changed "Id" to "Header" for rcsids


# 1.2 22-Mar-1993 cgd

added rcs ids to all files


# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
Initial revision


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906
# 1.160 14-Aug-2018 roy

Resolve every route(4) message type before printing anything more about it
other than the type and length.

This solves the issue where RTM_ONEWADDR is received and it tries to
parse route information from it.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330
# 1.159 23-Mar-2018 roy

Handle the routing socket overflowing gracefully.


Revision tags: pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.158 13-Dec-2017 christos

branches: 1.158.2;
Use the definitions from the standard header files and replace homebrew
snprintb with the libutil one.


# 1.157 13-Dec-2017 uwe

Fix typo in flag name. We should probably just use IFFBITS string
that <net/if.h> defines.

PR bin/52815


Revision tags: perseant-stdc-iso10646-base
# 1.156 16-Jun-2017 ozaki-r

Support -c <count> option for route monitor

route command exits if it receives <count> routing messages where
<count> is a value specified by -c.

The option is useful to get only particular message(s) in a test script.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320
# 1.155 17-Mar-2017 roy

branches: 1.155.4;
Report the PID for the process changing the address.


Revision tags: bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.154 04-Apr-2016 ozaki-r

branches: 1.154.2; 1.154.4;
Separate nexthop caches from the routing table

By this change, nexthop caches (IP-MAC address pair) are not stored
in the routing table anymore. Instead nexthop caches are stored in
each network interface; we already have lltable/llentry data structure
for this purpose. This change also obsoletes the concept of cloning/cloned
routes. Cloned routes no longer exist while cloning routes still exist
with renamed to connected routes.

Noticeable changes are:
- Nexthop caches aren't listed in route show/netstat -r
- sysctl(NET_RT_DUMP) doesn't return them
- If RTF_LLDATA is specified, it returns nexthop caches
- Several definitions of routing flags and messages are removed
- RTF_CLONING, RTF_XRESOLVE, RTF_LLINFO, RTF_CLONED and RTM_RESOLVE
- RTF_CONNECTED is added
- It has the same value of RTF_CLONING for backward compatibility
- route's -xresolve, -[no]cloned and -llinfo options are removed
- -[no]cloning remains because it seems there are users
- -[no]connected is introduced and recommended
to be used instead of -[no]cloning
- route show/netstat -r drops some flags
- 'L' and 'c' are not seen anymore
- 'C' now indicates a connected route
- Gateway value of a route of an interface address is now not
a L2 address but "link#N" like a connected (cloning) route
- Proxy ARP: "arp -s ... pub" doesn't create a route

You can know details of behavior changes by seeing diffs under tests/.

Proposed on tech-net and tech-kern:
http://mail-index.netbsd.org/tech-net/2016/03/11/msg005701.html


# 1.153 23-Jan-2016 christos

no need for <sys/mbuf.h>


# 1.152 17-Jan-2016 christos

PR/50671: David Binderman: fix memory leak.


# 1.151 23-Mar-2015 roy

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.


# 1.150 26-Feb-2015 roy

Teach route(8) about RTF_LOCAL.


# 1.149 20-Dec-2014 prlw1

MKINET6=no build fixes

http://mail-index.netbsd.org/tech-net/2014/12/13/msg004898.html


# 1.148 17-Dec-2014 roy

Note that RTM_CHANGE can also change the gateway


# 1.147 12-Nov-2014 christos

PR/47704: Takahiro HAYASHI: Add -L flag


# 1.146 07-Nov-2014 christos

Now that the code can support tags and verbose route printing, enable them.
Also document previously undocumented flags.


# 1.145 06-Nov-2014 christos

Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.144 19-Oct-2013 christos

branches: 1.144.4;
use correct function


# 1.143 19-Oct-2013 christos

use symbolic flags


# 1.142 19-Oct-2013 christos

use scopeid functions


# 1.141 18-Oct-2013 christos

avoid pointer gymnastics


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.140 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.139 04-Oct-2012 uwe

Fix fallout from 1.129 that converted sou::so_foo from unions to
pointers but missed (char *)&soup->so_foo => (char *)soup->so_foo in
mask_addr(). It worked by luck - unless it didn't: due to pointer
numerology on amd64 route add -net ClassC without explicit /24 prefix
length specification would result into /16 destination instead of /24.


# 1.138 08-Aug-2012 christos

branches: 1.138.2;
remove useless rump headers.


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.137 17-Mar-2012 christos

PR/42179: Christoph Badura: Be a little friendlier about missing args.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.136 26-Dec-2011 christos

branches: 1.136.2;
Off by one and clarity improvement from Christian Biere


# 1.135 24-Dec-2011 christos

PR/45661: Henning Petersen: Overlapping buffer in route.c.


# 1.134 11-Nov-2011 gdt

Move RTF_ANNOUNCE flag so that it no longer conflicts with RTF_PROTO2.

RTF_ANNOUNCE was defined as RTF_PROTO2. The flag is used to indicated
that host should act as a proxy for a link level arp or ndp request.
(If RTF_PROTO2 is used as an experimental flag (as advertised),
various problems can occur.)

This commit provides a first-class definition with its own bit for
RTF_ANNOUNCE, removes the old aliasing definitions, and adds support
for the new RTF_ANNOUNCE flag to netstat(8) and route(8).,

Also, remove unused RTF_ flags that collide with RTF_PROTO1:
netinet/icmp6.h defined RTF_PROBEMTU as RTF_PROTO1
netinet/if_inarp.h defined RTF_USETRAILERS as RTF_PROTO1
(Neither of these flags are used anywhere. Both have been removed
to reduce chances of collision with RTF_PROTO1.)

Figuring this out and the diff are the work of Beverly Schwartz of
BBN.

(Passed release build, boot in VM, with no apparently related atf
failures.)

Approved for Public Release, Distribution Unlimited
This material is based upon work supported by the Defense Advanced
Research Projects Agency and Space and Naval Warfare Systems Center,
Pacific, under Contract No. N66001-09-C-2073.


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.133 07-Oct-2011 joerg

branches: 1.133.2;
Simplify.


# 1.132 29-Aug-2011 joerg

Use __dead


# 1.131 01-Jul-2011 joerg

Fix memset usage.


# 1.130 22-Jun-2011 kefren

don't compile tag functions if SMALL is defined. Should fix the build


# 1.129 21-Jun-2011 kefren

Alloc dynamically sockunions in sou.
Teach route(8) about multiple tags. E.G.: -tag 100,20,33
XXX: needs documentation


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.128 01-Feb-2011 matt

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.


Revision tags: matt-mips64-premerge-20101231
# 1.127 13-Dec-2010 pooka

branches: 1.127.2;
Convert from RUMP_ACTION to RUMPPRG.


# 1.126 12-Nov-2010 roy

Support the new RTM_IFINFO and RTM_CHGADDR messages.


# 1.125 05-Nov-2010 pooka

adapt to new rumpclient_init() signature


# 1.124 04-Nov-2010 pooka

#ifdef variable correctly


# 1.123 04-Nov-2010 pooka

be consistent in what to leave outside of SMALL


# 1.122 04-Nov-2010 pooka

Support RUMP_ACTION to compile a rump kernel client.


# 1.121 26-Jun-2010 kefren

add MPLS clue - mpls and tag keywords


# 1.120 12-May-2010 christos

PR/40455: Mihai Chelaru: Add noreject noblackhole options


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base mjf-devfs2-base
# 1.119 28-Dec-2008 christos

parse unsigned long with strtoul not atoi


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3
# 1.118 10-Sep-2008 dyoung

branches: 1.118.6;
Get the socket addresses for dst/gateway/netmask/interface/ifaddr
out of the global namespace.


# 1.117 10-Sep-2008 dyoung

Don't cast a sockunion * to sockaddr *. Instead, reference the
sockaddr inside of the sockunion.


# 1.116 10-Sep-2008 dyoung

Delete superfluous casts to void *.


# 1.115 10-Sep-2008 dyoung

Constify.


# 1.114 10-Sep-2008 dyoung

Constify.


# 1.113 10-Sep-2008 dyoung

Constify.

For clarity's sake, do not assign a new value to inet_makenetandmask()'s
argument, `inet'.


# 1.112 09-Sep-2008 dyoung

Extract subroutine extract_addrs() for reuse, later.

Replace the anonymous constant, 0, with AF_UNSPEC.


# 1.111 09-Sep-2008 dyoung

Constify.


# 1.110 09-Sep-2008 dyoung

Shorten a staircase. Remove superfluous parentheses from return
statements. Constify.


# 1.109 09-Sep-2008 dyoung

Use a union and sizeof() to avoid a cast and an anonymous constant
buffer length, respectively.


# 1.108 09-Sep-2008 dyoung

Use bool.


Revision tags: wrstuden-revivesa-base-2
# 1.107 20-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking cube-autoconf-base mjf-devfs-base matt-armv6-base matt-mips64-base hpcarm-cleanup-base
# 1.106 18-Feb-2007 hubertf

branches: 1.106.12; 1.106.16;
TSEL() is const char* now


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base netbsd-4-base
# 1.105 11-Nov-2006 apb

Fix a bug that caused 0.0.0.0/0 to be treated like 0.0.0.0/32.

foo << 32 is undefined per section 6.5.7 of the C99 standard
if foo is (or is promoted to) a 32-bit type.


# 1.104 23-Sep-2006 dyoung

Let us qualify 'route flush' and 'route show' commands with -llinfo
and -host flags, which is useful for displaying/flushing ARP entries:

# route -n show -inet -llinfo -host
Routing table

Internet:
Destination Gateway Flags
169.254.1.119 link#1 UH
169.254.230.110 00:02:6f:21:e6:6e UH
# route -n flush -inet -llinfo -host
169.254.1.119 done
169.254.230.110 0.2.6f.21.e6.6e done
169.254.237.70 done
# route -n show -inet -llinfo -host
Routing table
#

This will help me address bin/11079, "dhclient may require arp and sed".

Extract common code from flushroutes() and show(), creating
parse_show_opts().

While I'm here, make small cosmetic changes to flushroutes().


# 1.103 23-Sep-2006 dyoung

Move the #ifndef SMALL code together.


# 1.102 23-Sep-2006 dyoung

Use the symbol AF_UNSPEC instead of 0 as appropriate.


# 1.101 23-Sep-2006 dyoung

Remove dead code.


# 1.100 26-Aug-2006 matt

Remove XNS and CCITT/X25 bits.


Revision tags: abandoned-netbsd-4-base
# 1.99 06-Aug-2006 dyoung

KNF err(3), errx(3) usage, indentation, braces.


# 1.98 06-Aug-2006 dyoung

Add route keywords -nocloned, -nocloning.


# 1.97 29-Jan-2006 wiz

Use default option order (AaBbCc...).


# 1.96 26-Jan-2006 is

Print the INET netmask if it is non-contiguous.


# 1.95 25-Jan-2006 christos

PR/32632: Yves-Emmanuel JUTARD: Improvment suggestion in 'route' display.
Add a new -S flag that prints a space for missing flags.


# 1.94 25-Jan-2006 christos

PR/32629: Yves-Emmanuel JUTARD: Type errors in sbin/route/route.c, another
u_char/char conflict.


# 1.93 31-Aug-2005 ginsbach

Add full IPv6 syntax support when route is built with -DSMALL and -DINET6.
Fixes PR/23937. Adapted from supplied patch.


# 1.92 30-Aug-2005 ginsbach

Clean up some minor nits:
+ style (KNF).
. don't cast NULL
. white space clean up
+ use consistent format for error messages.
+ plug memory leaks and avoid malloc(0).
+ verbose message should display even when routing table is empty
(flushroutes).


# 1.91 15-Aug-2005 ginsbach

Make sure that a netmask socket address value prints appropriately when the
family is unset. Either the destination or interface address socket address
family value is used. This change prevents the following sort of output:

RTM_NEWADDR: address being added to iface: len 60, metric 0, flags:<UP>
sockaddrs: <NETMASK,IFA,BRD>
(0) 00.00.ff.00.00 127.0.0.1 127.0.0.1

With this change the last line becomes:

255.0.0.0 127.0.0.1 127.0.0.1

Also make sure that when using a generated inet netmask the address family
is set. With this change a generated netmask will print appropriately
when using the verbose (-v) option.


# 1.90 12-Aug-2005 ginsbach

Make sure the get command always exits non-zero on error. This makes things
like the following work as expected.

#!/bin/sh

if ! route -sn get default >/dev/null 2>&1; then
echo default gateway not set
exit 1
fi
echo default gateway set

Handle routing socket write(2) errors when they occur. This produces
better diagnostics by allowing for handling of the special route errno
values ESRCH, EBUSY, and ENOBUFS even with the quiet (-q) option or
when doing a get command.


# 1.89 12-Aug-2005 ginsbach

Trim the local domain name in routename() for INET6 lookups; similar to
INET lookups.


# 1.88 10-Aug-2005 he

Make this build for __GNUC__ <= 2 (i.e. for vax). The cast to
caddr_t removes a const qualifier. Instead, cast the first element
of the subtraction to "struct sockaddr *" to work around the problem.


# 1.87 09-Aug-2005 ginsbach

Accept protocol flags, i.e. -inet, -inet6, with the show command.
[From OpenBSD via DragonFly BSD]


# 1.86 09-Aug-2005 ginsbach

Fix the default case in sodump(). Printing the address of the "which"
string isn't really that useful. Instead print the string and the value
of sa_family.


# 1.85 09-Aug-2005 ginsbach

More style nits (KNF); casts and sizeof's are not followed by a space.


# 1.84 20-Jul-2005 ginsbach

switch is not a function, so add a space; sort switch elements
alphabetically (KNF).


# 1.83 15-Jul-2005 ginsbach

* Exit non-zero error code when flushroute() fails operating on the
routing socket, e.g. running route flush as non-root.

* When quiet (-q) don't append error string to a non-existent
diagnostic output (stdout). The error diagnostic is still written
to stderr. [from FreeBSD]

* Use warn(3) in place of perror(3).


# 1.82 26-Jun-2005 christos

const poisoning.


# 1.81 25-Jun-2005 dyoung

Teach route(8) to print the messages generated by net80211.


# 1.80 19-May-2005 ginsbach

Convert prefixlen() to ANSI function declaration. Missed by earlier
conversion.


# 1.79 19-May-2005 ginsbach

Due to a limitation in inet_addr(3) it was not possible to specify a
netmask value of 0xffffffff (INADDR_NONE). Fix by using inet_aton(3).
Note it was possible to specify the same mask as the dotted quad
255.255.255.255 because of a later call to gethostbyname(3).
[From FreeBSD]


# 1.78 13-May-2005 ginsbach

Fix botched prior commit. Additional debugging error messages mistakenly
committed.


# 1.77 12-May-2005 ginsbach

* Honor -net when using CIDR (net/mask) notation. This differs
from the default CIDR (host/mask) interpretation. As discussed on
tech-net.

* Use errx() in place of fprintf() and exit(). Make the error message
formats consistent.


# 1.76 10-May-2005 ginsbach

Fix macro NEXTADDR so that the names, like so_dst, are printed
rather than u. The preprocessor doesn't do replacement within
strings, so the # string creation operator must be used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.75 05-Feb-2005 xtraeme

Kill __P(), use ANSI function declarations.


# 1.74 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


# 1.73 15-May-2004 itojun

bump buffer size for any_ntoa(), for huge sa_len


# 1.72 15-May-2004 itojun

2-byte read overrun for unknown sockaddr. from openbsd
XXX out[64], is it safe? what if sa_len > 23?


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.71 05-Jan-2004 jmmv

Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.


# 1.70 01-Oct-2003 itojun

print prefixlen on -show


# 1.69 16-Sep-2003 cube

Remove a comment that referred to a non-committed part of the patch I
submitted for bin/17613. Ok'd by mrg@.


# 1.68 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.


# 1.67 19-Jul-2003 jrf

This is an updated submitted patch originally written by Jim Rees
and sent in by Greg Hudson as seen in PR misc/3227. Basically what it
does is adds a flushall option which deletes all but localhost routes.
This is done by andoring in a flag called doall (1 means do all routes
including gateway, 0 means do a regular flush). I have seen some
platforms that do this. I tested it out on ipv4 only, it works as
advertised. Commit was approved by christos@.


# 1.66 11-Jun-2003 christos

PR/21856: Robert Elz: Changes to route(8) to allow /n instead of -prefixlen
for INET6


# 1.65 03-Jun-2003 itojun

permit foo/bar notation, like "route add 10.0.0.0/8 127.0.0.1".
originally by provos


# 1.64 17-May-2003 itojun

strlcpy [a few mistakes found]


# 1.63 21-Apr-2003 jrf

This addresses PR 17613 when certain methods of adding routes would
muck up the routing tables. The patch was submitted by Quentin Garnier
<netbsd@quatriemek.com> and tweaked a little after it was reviewed
by Christos Zoulas <christos@netbsd.org>. Final change/commit approved
by Christos.


# 1.62 03-Apr-2003 jrf

Made a note in the code about the -d and -d options brought up in
PR 18674. Thanks to Chris Jones for pointing it out.


Revision tags: fvdl_fs64_base
# 1.61 18-Oct-2002 itojun

correct prefixlen handling for IPv4.


# 1.60 18-Oct-2002 itojun

Make prefixlen check to make sure its argument is present before deref
from openbsd


# 1.59 20-Jul-2002 grant

sweep of errx/warnx, remove unnecessary trailing \n


# 1.58 10-Jun-2002 itojun

permit DNS names to address portion. they will be considered as RTF_HOST
if specified as destination (as there's no getnetbyname in IPv6).


# 1.57 05-Jun-2002 itojun

if we're unsure about prefixlen, don't say "128".


# 1.56 05-Jun-2002 itojun

more correct ion to RTF_HOST handling.


# 1.55 04-Jun-2002 itojun

do not have -prefixlen 128 on RTF_HOST.
From: Dawid Szymanski <dawszy@arhea.net>


Revision tags: netbsd-1-6-base
# 1.54 20-May-2002 itojun

branches: 1.54.2;
raise RTF_HOST if destination is a host (/128). from ume


# 1.53 21-Feb-2002 christos

PR/15672: Love: route monitor missing info


# 1.52 15-Nov-2001 christos

Make route exit with a non-zero error code when operations to the routing
socket fails. eg, running route add 1.2.3.4 5.6.7.8 as non root.


# 1.51 02-Nov-2001 lukem

fix -Wshadow warnings


# 1.50 24-Oct-2001 atatat

Provide a short output format for the get command that only prints the
address corresponding to RTA_GATEWAY, or nothing if it doesn't exist.
Modify the exit value of route depending on this, so that one can do
stuff like:

#!/bin/sh
gw=`route -sn get default 2>/dev/null`
if [ -z "$gw" ]; then
echo no default route
exit 1
fi
ping -w1 -c1 $gw >/dev/null 2>&1
if ! route -sn get $gw >/dev/null; then
echo default gateway not responding
exit 1
fi
echo default gateway is at $gw


# 1.49 24-Oct-2001 atatat

Print a R on reject routes to indicate that they're not normal routes,
and check netmask (or prefix) length as well as the destination
address when determining if a route is a "default" or not. This means
that the output from 'route show' will no longer say:

Internet6:
Destination Gateway Flags
default localhost UG
default localhost UG

but instead

Internet6:
Destination Gateway Flags
::/104 localhost UGR
::/96 localhost UGR

which makes much more sense.


# 1.48 20-Jul-2001 itojun

off-by-one error in -prefixlen arg validation (do not permit 129 on IPv6)


# 1.47 20-Jul-2001 itojun

make prefixlen work on IPv4 too


# 1.46 16-Jul-2001 bad

The way pmsg_addrs() is used requires that it always prints a newline and
flushes stdout before returning.

Previously the decoded output for a message was stuck in stdio buffers until
the next arrived.


# 1.45 19-Feb-2001 cgd

convert to use getprogname()


# 1.44 04-Feb-2001 christos

remove nested externs.


# 1.43 27-Jan-2001 itojun

support -cloned command line flag.
i don't think anyone ever going to use it.


# 1.42 27-Jan-2001 itojun

mark cloned routes with RTF_CLONED. present it with netstat -r by "c".

let static routes overwrite cloned routes, as cloned routes can come back again
if necessary. behavior same as freebsd/bsdi, code partially from bsdi42.
(NRL rt->rt_parent was not added)
should fix PR 11916 and maybe some other PRs with ARP behavior.

recompilation of usr.sbin/route6d is suggested.


# 1.41 27-Jan-2001 itojun

support RTF_BLACKHOLE.

XXX route show is total duplicate of netstat -r, we need to either remove
route show, or share the same source code, otherwise maintenance cost
bites (and is biting) us


# 1.40 27-Jan-2001 itojun

remove use of uninitialized route (struct ortentry).
it seems that the bug was born during 4.3reno -> 4.4Lite1 transition.


# 1.39 10-Oct-2000 itojun

on "route monitor", print RTM_IFANNOUNCE, RTM_IFINFO (new #), and others.


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.38 04-May-2000 sommerfeld

branches: 1.38.4;
Allow INET6 to be used with SMALL without undefined symbols


# 1.37 20-Apr-2000 itojun

use scoped notation for link-local multicast too.


# 1.36 20-Apr-2000 itojun

support extended scoped address notation (fe80::1%de0).
it hides implementation detail (embedded ifid) from the users.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.35 03-Dec-1999 itojun

don't make "-prefixlen 64" a default in -inet6 case. the past behavior
was not compatible with past practice ("route get" did not work right).

sync with recent KAME.


Revision tags: comdex-fall-1999-base
# 1.34 01-Nov-1999 sommerfeld

Display local address associated with route (if any) in "route get".


# 1.33 03-Sep-1999 itojun

branches: 1.33.2;
fix alignment issue in routing socket data, on 64bit arch (i.e. alpha).
sockaddrs are packed with ROUNDUP() in sys/net/rtsock.c so userland
programs needs to follow that.

PR: 8179


# 1.32 06-Jul-1999 mjacob

Incorrect integration. ctime takes a time_t value, not a long.


# 1.31 02-Jul-1999 itojun

IPv6-ready route command (-inet6 and -prefixlen are added)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.30 23-Oct-1998 lukem

branches: 1.30.2;
* implement -f; flush all routes before executing command
* reset af to 0 in flushroutes() and newroute()
* cleanup -DSMALL:
- `flush' and AF_APPLETALK is supported (the latter had partial support)
- AF_NS, AF_ISO, and AF_CCITT are not supported at all (rather than being
- partially unsupported).


# 1.29 26-Jul-1998 mycroft

const poisoning.


# 1.28 01-Apr-1998 kleink

Need <time.h> for time() prototype.


# 1.27 05-Feb-1998 ross

64-bit sweep, "route -v show" was spinning forever.


# 1.26 16-Nov-1997 christos

Use {warn,err}{,x}(3) instead of printf's


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 01-Oct-1997 enami

Don't declare optind.


# 1.24 16-Sep-1997 lukem

resolve conflicts from lite-2 import


# 1.23 15-Sep-1997 lukem

* cleanup for WARNS=1
* use .Nm correctly
* deprecate register
* getopt returns -1 not EOF


# 1.22 02-Sep-1997 thorpej

Fix uninitialized pointer botch when attempting to flush an already
empty routing table. From Matthias Scheler <tron@lyssa.owl.de>, in
PR #4074.


# 1.21 27-Apr-1997 thorpej

Don't SEGV if a qualifier is passed without an argument. From
Geoff Wing <mason@primenet.com.au>, fixes PR #2700.


# 1.20 21-Apr-1997 mrg

KNF. be safe with buffers.


# 1.19 03-Apr-1997 christos

- Add netatalk bits
- Add prototypes
- Fix printf formats


# 1.18 22-Feb-1997 carrel

Remove uid checks since the kernel now handles this and route(1) is no
longer setuid.
Document the "Permission denied" msg in the man page since this is
_slightly_ less clear than route(1)'s old error msg.


# 1.17 15-Nov-1996 gwr

As discussed some time ago, add a "show" sub-command.
Also allow compilation with -DSMALL to ommit support for
non-essential protocols (i.e. when built into a ramdisk).
Use a less hack-ish way to generate keywords.[ch] and just
check in the result (helps ../../distrib/utils/x_route).


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.16 15-Apr-1996 cgd

check returns of inet_addr() and inet_network() against INADDR_NONE,
not -1, per the manual page. on 64-bit systems like the alpha, -1 will
never equal (unsigned long)INADDR_NONE.


# 1.15 07-Jan-1996 pk

Produce less output on -q as promised by the man page (John Hawkinson; PR#998).


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.14 20-Apr-1995 mycroft

Interface-specific routes can be static.


# 1.13 20-Apr-1995 mycroft

Implement the document `-llinfo' flag.


# 1.12 18-Apr-1995 mycroft

Remove extra `break;'.


# 1.11 18-Mar-1995 cgd

convert to new RCS Id conventions; reduce my headache


# 1.10 24-Dec-1994 cgd

kill some extraneous equal signs.


# 1.9 23-Sep-1994 mycroft

Remove some more uses of obsolete functions.


# 1.8 23-Sep-1994 mycroft

Eliminate uses of some obsolete functions.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.7 13-May-1994 mycroft

Clean up import.


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 25-Apr-1993 mycroft

Compile X.25, OSI, and NS code.


# 1.4 18-Apr-1993 mycroft

Cleanup for GCC 2.


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.3 23-Mar-1993 cgd

changed "Id" to "Header" for rcsids


# 1.2 22-Mar-1993 cgd

added rcs ids to all files


# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
Initial revision


# 1.158 13-Dec-2017 christos

Use the definitions from the standard header files and replace homebrew
snprintb with the libutil one.


# 1.157 13-Dec-2017 uwe

Fix typo in flag name. We should probably just use IFFBITS string
that <net/if.h> defines.

PR bin/52815


Revision tags: perseant-stdc-iso10646-base
# 1.156 16-Jun-2017 ozaki-r

Support -c <count> option for route monitor

route command exits if it receives <count> routing messages where
<count> is a value specified by -c.

The option is useful to get only particular message(s) in a test script.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320
# 1.155 17-Mar-2017 roy

branches: 1.155.4;
Report the PID for the process changing the address.


Revision tags: bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.154 04-Apr-2016 ozaki-r

branches: 1.154.2; 1.154.4;
Separate nexthop caches from the routing table

By this change, nexthop caches (IP-MAC address pair) are not stored
in the routing table anymore. Instead nexthop caches are stored in
each network interface; we already have lltable/llentry data structure
for this purpose. This change also obsoletes the concept of cloning/cloned
routes. Cloned routes no longer exist while cloning routes still exist
with renamed to connected routes.

Noticeable changes are:
- Nexthop caches aren't listed in route show/netstat -r
- sysctl(NET_RT_DUMP) doesn't return them
- If RTF_LLDATA is specified, it returns nexthop caches
- Several definitions of routing flags and messages are removed
- RTF_CLONING, RTF_XRESOLVE, RTF_LLINFO, RTF_CLONED and RTM_RESOLVE
- RTF_CONNECTED is added
- It has the same value of RTF_CLONING for backward compatibility
- route's -xresolve, -[no]cloned and -llinfo options are removed
- -[no]cloning remains because it seems there are users
- -[no]connected is introduced and recommended
to be used instead of -[no]cloning
- route show/netstat -r drops some flags
- 'L' and 'c' are not seen anymore
- 'C' now indicates a connected route
- Gateway value of a route of an interface address is now not
a L2 address but "link#N" like a connected (cloning) route
- Proxy ARP: "arp -s ... pub" doesn't create a route

You can know details of behavior changes by seeing diffs under tests/.

Proposed on tech-net and tech-kern:
http://mail-index.netbsd.org/tech-net/2016/03/11/msg005701.html


# 1.153 23-Jan-2016 christos

no need for <sys/mbuf.h>


# 1.152 17-Jan-2016 christos

PR/50671: David Binderman: fix memory leak.


# 1.151 23-Mar-2015 roy

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.


# 1.150 26-Feb-2015 roy

Teach route(8) about RTF_LOCAL.


# 1.149 20-Dec-2014 prlw1

MKINET6=no build fixes

http://mail-index.netbsd.org/tech-net/2014/12/13/msg004898.html


# 1.148 17-Dec-2014 roy

Note that RTM_CHANGE can also change the gateway


# 1.147 12-Nov-2014 christos

PR/47704: Takahiro HAYASHI: Add -L flag


# 1.146 07-Nov-2014 christos

Now that the code can support tags and verbose route printing, enable them.
Also document previously undocumented flags.


# 1.145 06-Nov-2014 christos

Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.144 19-Oct-2013 christos

branches: 1.144.4;
use correct function


# 1.143 19-Oct-2013 christos

use symbolic flags


# 1.142 19-Oct-2013 christos

use scopeid functions


# 1.141 18-Oct-2013 christos

avoid pointer gymnastics


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.140 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.139 04-Oct-2012 uwe

Fix fallout from 1.129 that converted sou::so_foo from unions to
pointers but missed (char *)&soup->so_foo => (char *)soup->so_foo in
mask_addr(). It worked by luck - unless it didn't: due to pointer
numerology on amd64 route add -net ClassC without explicit /24 prefix
length specification would result into /16 destination instead of /24.


# 1.138 08-Aug-2012 christos

branches: 1.138.2;
remove useless rump headers.


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.137 17-Mar-2012 christos

PR/42179: Christoph Badura: Be a little friendlier about missing args.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.136 26-Dec-2011 christos

branches: 1.136.2;
Off by one and clarity improvement from Christian Biere


# 1.135 24-Dec-2011 christos

PR/45661: Henning Petersen: Overlapping buffer in route.c.


# 1.134 11-Nov-2011 gdt

Move RTF_ANNOUNCE flag so that it no longer conflicts with RTF_PROTO2.

RTF_ANNOUNCE was defined as RTF_PROTO2. The flag is used to indicated
that host should act as a proxy for a link level arp or ndp request.
(If RTF_PROTO2 is used as an experimental flag (as advertised),
various problems can occur.)

This commit provides a first-class definition with its own bit for
RTF_ANNOUNCE, removes the old aliasing definitions, and adds support
for the new RTF_ANNOUNCE flag to netstat(8) and route(8).,

Also, remove unused RTF_ flags that collide with RTF_PROTO1:
netinet/icmp6.h defined RTF_PROBEMTU as RTF_PROTO1
netinet/if_inarp.h defined RTF_USETRAILERS as RTF_PROTO1
(Neither of these flags are used anywhere. Both have been removed
to reduce chances of collision with RTF_PROTO1.)

Figuring this out and the diff are the work of Beverly Schwartz of
BBN.

(Passed release build, boot in VM, with no apparently related atf
failures.)

Approved for Public Release, Distribution Unlimited
This material is based upon work supported by the Defense Advanced
Research Projects Agency and Space and Naval Warfare Systems Center,
Pacific, under Contract No. N66001-09-C-2073.


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.133 07-Oct-2011 joerg

branches: 1.133.2;
Simplify.


# 1.132 29-Aug-2011 joerg

Use __dead


# 1.131 01-Jul-2011 joerg

Fix memset usage.


# 1.130 22-Jun-2011 kefren

don't compile tag functions if SMALL is defined. Should fix the build


# 1.129 21-Jun-2011 kefren

Alloc dynamically sockunions in sou.
Teach route(8) about multiple tags. E.G.: -tag 100,20,33
XXX: needs documentation


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.128 01-Feb-2011 matt

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.


Revision tags: matt-mips64-premerge-20101231
# 1.127 13-Dec-2010 pooka

branches: 1.127.2;
Convert from RUMP_ACTION to RUMPPRG.


# 1.126 12-Nov-2010 roy

Support the new RTM_IFINFO and RTM_CHGADDR messages.


# 1.125 05-Nov-2010 pooka

adapt to new rumpclient_init() signature


# 1.124 04-Nov-2010 pooka

#ifdef variable correctly


# 1.123 04-Nov-2010 pooka

be consistent in what to leave outside of SMALL


# 1.122 04-Nov-2010 pooka

Support RUMP_ACTION to compile a rump kernel client.


# 1.121 26-Jun-2010 kefren

add MPLS clue - mpls and tag keywords


# 1.120 12-May-2010 christos

PR/40455: Mihai Chelaru: Add noreject noblackhole options


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base mjf-devfs2-base
# 1.119 28-Dec-2008 christos

parse unsigned long with strtoul not atoi


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3
# 1.118 10-Sep-2008 dyoung

branches: 1.118.6;
Get the socket addresses for dst/gateway/netmask/interface/ifaddr
out of the global namespace.


# 1.117 10-Sep-2008 dyoung

Don't cast a sockunion * to sockaddr *. Instead, reference the
sockaddr inside of the sockunion.


# 1.116 10-Sep-2008 dyoung

Delete superfluous casts to void *.


# 1.115 10-Sep-2008 dyoung

Constify.


# 1.114 10-Sep-2008 dyoung

Constify.


# 1.113 10-Sep-2008 dyoung

Constify.

For clarity's sake, do not assign a new value to inet_makenetandmask()'s
argument, `inet'.


# 1.112 09-Sep-2008 dyoung

Extract subroutine extract_addrs() for reuse, later.

Replace the anonymous constant, 0, with AF_UNSPEC.


# 1.111 09-Sep-2008 dyoung

Constify.


# 1.110 09-Sep-2008 dyoung

Shorten a staircase. Remove superfluous parentheses from return
statements. Constify.


# 1.109 09-Sep-2008 dyoung

Use a union and sizeof() to avoid a cast and an anonymous constant
buffer length, respectively.


# 1.108 09-Sep-2008 dyoung

Use bool.


Revision tags: wrstuden-revivesa-base-2
# 1.107 20-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking cube-autoconf-base mjf-devfs-base matt-armv6-base matt-mips64-base hpcarm-cleanup-base
# 1.106 18-Feb-2007 hubertf

branches: 1.106.12; 1.106.16;
TSEL() is const char* now


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base netbsd-4-base
# 1.105 11-Nov-2006 apb

Fix a bug that caused 0.0.0.0/0 to be treated like 0.0.0.0/32.

foo << 32 is undefined per section 6.5.7 of the C99 standard
if foo is (or is promoted to) a 32-bit type.


# 1.104 23-Sep-2006 dyoung

Let us qualify 'route flush' and 'route show' commands with -llinfo
and -host flags, which is useful for displaying/flushing ARP entries:

# route -n show -inet -llinfo -host
Routing table

Internet:
Destination Gateway Flags
169.254.1.119 link#1 UH
169.254.230.110 00:02:6f:21:e6:6e UH
# route -n flush -inet -llinfo -host
169.254.1.119 done
169.254.230.110 0.2.6f.21.e6.6e done
169.254.237.70 done
# route -n show -inet -llinfo -host
Routing table
#

This will help me address bin/11079, "dhclient may require arp and sed".

Extract common code from flushroutes() and show(), creating
parse_show_opts().

While I'm here, make small cosmetic changes to flushroutes().


# 1.103 23-Sep-2006 dyoung

Move the #ifndef SMALL code together.


# 1.102 23-Sep-2006 dyoung

Use the symbol AF_UNSPEC instead of 0 as appropriate.


# 1.101 23-Sep-2006 dyoung

Remove dead code.


# 1.100 26-Aug-2006 matt

Remove XNS and CCITT/X25 bits.


Revision tags: abandoned-netbsd-4-base
# 1.99 06-Aug-2006 dyoung

KNF err(3), errx(3) usage, indentation, braces.


# 1.98 06-Aug-2006 dyoung

Add route keywords -nocloned, -nocloning.


# 1.97 29-Jan-2006 wiz

Use default option order (AaBbCc...).


# 1.96 26-Jan-2006 is

Print the INET netmask if it is non-contiguous.


# 1.95 25-Jan-2006 christos

PR/32632: Yves-Emmanuel JUTARD: Improvment suggestion in 'route' display.
Add a new -S flag that prints a space for missing flags.


# 1.94 25-Jan-2006 christos

PR/32629: Yves-Emmanuel JUTARD: Type errors in sbin/route/route.c, another
u_char/char conflict.


# 1.93 31-Aug-2005 ginsbach

Add full IPv6 syntax support when route is built with -DSMALL and -DINET6.
Fixes PR/23937. Adapted from supplied patch.


# 1.92 30-Aug-2005 ginsbach

Clean up some minor nits:
+ style (KNF).
. don't cast NULL
. white space clean up
+ use consistent format for error messages.
+ plug memory leaks and avoid malloc(0).
+ verbose message should display even when routing table is empty
(flushroutes).


# 1.91 15-Aug-2005 ginsbach

Make sure that a netmask socket address value prints appropriately when the
family is unset. Either the destination or interface address socket address
family value is used. This change prevents the following sort of output:

RTM_NEWADDR: address being added to iface: len 60, metric 0, flags:<UP>
sockaddrs: <NETMASK,IFA,BRD>
(0) 00.00.ff.00.00 127.0.0.1 127.0.0.1

With this change the last line becomes:

255.0.0.0 127.0.0.1 127.0.0.1

Also make sure that when using a generated inet netmask the address family
is set. With this change a generated netmask will print appropriately
when using the verbose (-v) option.


# 1.90 12-Aug-2005 ginsbach

Make sure the get command always exits non-zero on error. This makes things
like the following work as expected.

#!/bin/sh

if ! route -sn get default >/dev/null 2>&1; then
echo default gateway not set
exit 1
fi
echo default gateway set

Handle routing socket write(2) errors when they occur. This produces
better diagnostics by allowing for handling of the special route errno
values ESRCH, EBUSY, and ENOBUFS even with the quiet (-q) option or
when doing a get command.


# 1.89 12-Aug-2005 ginsbach

Trim the local domain name in routename() for INET6 lookups; similar to
INET lookups.


# 1.88 10-Aug-2005 he

Make this build for __GNUC__ <= 2 (i.e. for vax). The cast to
caddr_t removes a const qualifier. Instead, cast the first element
of the subtraction to "struct sockaddr *" to work around the problem.


# 1.87 09-Aug-2005 ginsbach

Accept protocol flags, i.e. -inet, -inet6, with the show command.
[From OpenBSD via DragonFly BSD]


# 1.86 09-Aug-2005 ginsbach

Fix the default case in sodump(). Printing the address of the "which"
string isn't really that useful. Instead print the string and the value
of sa_family.


# 1.85 09-Aug-2005 ginsbach

More style nits (KNF); casts and sizeof's are not followed by a space.


# 1.84 20-Jul-2005 ginsbach

switch is not a function, so add a space; sort switch elements
alphabetically (KNF).


# 1.83 15-Jul-2005 ginsbach

* Exit non-zero error code when flushroute() fails operating on the
routing socket, e.g. running route flush as non-root.

* When quiet (-q) don't append error string to a non-existent
diagnostic output (stdout). The error diagnostic is still written
to stderr. [from FreeBSD]

* Use warn(3) in place of perror(3).


# 1.82 26-Jun-2005 christos

const poisoning.


# 1.81 25-Jun-2005 dyoung

Teach route(8) to print the messages generated by net80211.


# 1.80 19-May-2005 ginsbach

Convert prefixlen() to ANSI function declaration. Missed by earlier
conversion.


# 1.79 19-May-2005 ginsbach

Due to a limitation in inet_addr(3) it was not possible to specify a
netmask value of 0xffffffff (INADDR_NONE). Fix by using inet_aton(3).
Note it was possible to specify the same mask as the dotted quad
255.255.255.255 because of a later call to gethostbyname(3).
[From FreeBSD]


# 1.78 13-May-2005 ginsbach

Fix botched prior commit. Additional debugging error messages mistakenly
committed.


# 1.77 12-May-2005 ginsbach

* Honor -net when using CIDR (net/mask) notation. This differs
from the default CIDR (host/mask) interpretation. As discussed on
tech-net.

* Use errx() in place of fprintf() and exit(). Make the error message
formats consistent.


# 1.76 10-May-2005 ginsbach

Fix macro NEXTADDR so that the names, like so_dst, are printed
rather than u. The preprocessor doesn't do replacement within
strings, so the # string creation operator must be used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.75 05-Feb-2005 xtraeme

Kill __P(), use ANSI function declarations.


# 1.74 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


# 1.73 15-May-2004 itojun

bump buffer size for any_ntoa(), for huge sa_len


# 1.72 15-May-2004 itojun

2-byte read overrun for unknown sockaddr. from openbsd
XXX out[64], is it safe? what if sa_len > 23?


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.71 05-Jan-2004 jmmv

Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.


# 1.70 01-Oct-2003 itojun

print prefixlen on -show


# 1.69 16-Sep-2003 cube

Remove a comment that referred to a non-committed part of the patch I
submitted for bin/17613. Ok'd by mrg@.


# 1.68 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.


# 1.67 19-Jul-2003 jrf

This is an updated submitted patch originally written by Jim Rees
and sent in by Greg Hudson as seen in PR misc/3227. Basically what it
does is adds a flushall option which deletes all but localhost routes.
This is done by andoring in a flag called doall (1 means do all routes
including gateway, 0 means do a regular flush). I have seen some
platforms that do this. I tested it out on ipv4 only, it works as
advertised. Commit was approved by christos@.


# 1.66 11-Jun-2003 christos

PR/21856: Robert Elz: Changes to route(8) to allow /n instead of -prefixlen
for INET6


# 1.65 03-Jun-2003 itojun

permit foo/bar notation, like "route add 10.0.0.0/8 127.0.0.1".
originally by provos


# 1.64 17-May-2003 itojun

strlcpy [a few mistakes found]


# 1.63 21-Apr-2003 jrf

This addresses PR 17613 when certain methods of adding routes would
muck up the routing tables. The patch was submitted by Quentin Garnier
<netbsd@quatriemek.com> and tweaked a little after it was reviewed
by Christos Zoulas <christos@netbsd.org>. Final change/commit approved
by Christos.


# 1.62 03-Apr-2003 jrf

Made a note in the code about the -d and -d options brought up in
PR 18674. Thanks to Chris Jones for pointing it out.


Revision tags: fvdl_fs64_base
# 1.61 18-Oct-2002 itojun

correct prefixlen handling for IPv4.


# 1.60 18-Oct-2002 itojun

Make prefixlen check to make sure its argument is present before deref
from openbsd


# 1.59 20-Jul-2002 grant

sweep of errx/warnx, remove unnecessary trailing \n


# 1.58 10-Jun-2002 itojun

permit DNS names to address portion. they will be considered as RTF_HOST
if specified as destination (as there's no getnetbyname in IPv6).


# 1.57 05-Jun-2002 itojun

if we're unsure about prefixlen, don't say "128".


# 1.56 05-Jun-2002 itojun

more correct ion to RTF_HOST handling.


# 1.55 04-Jun-2002 itojun

do not have -prefixlen 128 on RTF_HOST.
From: Dawid Szymanski <dawszy@arhea.net>


Revision tags: netbsd-1-6-base
# 1.54 20-May-2002 itojun

branches: 1.54.2;
raise RTF_HOST if destination is a host (/128). from ume


# 1.53 21-Feb-2002 christos

PR/15672: Love: route monitor missing info


# 1.52 15-Nov-2001 christos

Make route exit with a non-zero error code when operations to the routing
socket fails. eg, running route add 1.2.3.4 5.6.7.8 as non root.


# 1.51 02-Nov-2001 lukem

fix -Wshadow warnings


# 1.50 24-Oct-2001 atatat

Provide a short output format for the get command that only prints the
address corresponding to RTA_GATEWAY, or nothing if it doesn't exist.
Modify the exit value of route depending on this, so that one can do
stuff like:

#!/bin/sh
gw=`route -sn get default 2>/dev/null`
if [ -z "$gw" ]; then
echo no default route
exit 1
fi
ping -w1 -c1 $gw >/dev/null 2>&1
if ! route -sn get $gw >/dev/null; then
echo default gateway not responding
exit 1
fi
echo default gateway is at $gw


# 1.49 24-Oct-2001 atatat

Print a R on reject routes to indicate that they're not normal routes,
and check netmask (or prefix) length as well as the destination
address when determining if a route is a "default" or not. This means
that the output from 'route show' will no longer say:

Internet6:
Destination Gateway Flags
default localhost UG
default localhost UG

but instead

Internet6:
Destination Gateway Flags
::/104 localhost UGR
::/96 localhost UGR

which makes much more sense.


# 1.48 20-Jul-2001 itojun

off-by-one error in -prefixlen arg validation (do not permit 129 on IPv6)


# 1.47 20-Jul-2001 itojun

make prefixlen work on IPv4 too


# 1.46 16-Jul-2001 bad

The way pmsg_addrs() is used requires that it always prints a newline and
flushes stdout before returning.

Previously the decoded output for a message was stuck in stdio buffers until
the next arrived.


# 1.45 19-Feb-2001 cgd

convert to use getprogname()


# 1.44 04-Feb-2001 christos

remove nested externs.


# 1.43 27-Jan-2001 itojun

support -cloned command line flag.
i don't think anyone ever going to use it.


# 1.42 27-Jan-2001 itojun

mark cloned routes with RTF_CLONED. present it with netstat -r by "c".

let static routes overwrite cloned routes, as cloned routes can come back again
if necessary. behavior same as freebsd/bsdi, code partially from bsdi42.
(NRL rt->rt_parent was not added)
should fix PR 11916 and maybe some other PRs with ARP behavior.

recompilation of usr.sbin/route6d is suggested.


# 1.41 27-Jan-2001 itojun

support RTF_BLACKHOLE.

XXX route show is total duplicate of netstat -r, we need to either remove
route show, or share the same source code, otherwise maintenance cost
bites (and is biting) us


# 1.40 27-Jan-2001 itojun

remove use of uninitialized route (struct ortentry).
it seems that the bug was born during 4.3reno -> 4.4Lite1 transition.


# 1.39 10-Oct-2000 itojun

on "route monitor", print RTM_IFANNOUNCE, RTM_IFINFO (new #), and others.


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.38 04-May-2000 sommerfeld

branches: 1.38.4;
Allow INET6 to be used with SMALL without undefined symbols


# 1.37 20-Apr-2000 itojun

use scoped notation for link-local multicast too.


# 1.36 20-Apr-2000 itojun

support extended scoped address notation (fe80::1%de0).
it hides implementation detail (embedded ifid) from the users.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.35 03-Dec-1999 itojun

don't make "-prefixlen 64" a default in -inet6 case. the past behavior
was not compatible with past practice ("route get" did not work right).

sync with recent KAME.


Revision tags: comdex-fall-1999-base
# 1.34 01-Nov-1999 sommerfeld

Display local address associated with route (if any) in "route get".


# 1.33 03-Sep-1999 itojun

branches: 1.33.2;
fix alignment issue in routing socket data, on 64bit arch (i.e. alpha).
sockaddrs are packed with ROUNDUP() in sys/net/rtsock.c so userland
programs needs to follow that.

PR: 8179


# 1.32 06-Jul-1999 mjacob

Incorrect integration. ctime takes a time_t value, not a long.


# 1.31 02-Jul-1999 itojun

IPv6-ready route command (-inet6 and -prefixlen are added)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.30 23-Oct-1998 lukem

branches: 1.30.2;
* implement -f; flush all routes before executing command
* reset af to 0 in flushroutes() and newroute()
* cleanup -DSMALL:
- `flush' and AF_APPLETALK is supported (the latter had partial support)
- AF_NS, AF_ISO, and AF_CCITT are not supported at all (rather than being
- partially unsupported).


# 1.29 26-Jul-1998 mycroft

const poisoning.


# 1.28 01-Apr-1998 kleink

Need <time.h> for time() prototype.


# 1.27 05-Feb-1998 ross

64-bit sweep, "route -v show" was spinning forever.


# 1.26 16-Nov-1997 christos

Use {warn,err}{,x}(3) instead of printf's


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 01-Oct-1997 enami

Don't declare optind.


# 1.24 16-Sep-1997 lukem

resolve conflicts from lite-2 import


# 1.23 15-Sep-1997 lukem

* cleanup for WARNS=1
* use .Nm correctly
* deprecate register
* getopt returns -1 not EOF


# 1.22 02-Sep-1997 thorpej

Fix uninitialized pointer botch when attempting to flush an already
empty routing table. From Matthias Scheler <tron@lyssa.owl.de>, in
PR #4074.


# 1.21 27-Apr-1997 thorpej

Don't SEGV if a qualifier is passed without an argument. From
Geoff Wing <mason@primenet.com.au>, fixes PR #2700.


# 1.20 21-Apr-1997 mrg

KNF. be safe with buffers.


# 1.19 03-Apr-1997 christos

- Add netatalk bits
- Add prototypes
- Fix printf formats


# 1.18 22-Feb-1997 carrel

Remove uid checks since the kernel now handles this and route(1) is no
longer setuid.
Document the "Permission denied" msg in the man page since this is
_slightly_ less clear than route(1)'s old error msg.


# 1.17 15-Nov-1996 gwr

As discussed some time ago, add a "show" sub-command.
Also allow compilation with -DSMALL to ommit support for
non-essential protocols (i.e. when built into a ramdisk).
Use a less hack-ish way to generate keywords.[ch] and just
check in the result (helps ../../distrib/utils/x_route).


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.16 15-Apr-1996 cgd

check returns of inet_addr() and inet_network() against INADDR_NONE,
not -1, per the manual page. on 64-bit systems like the alpha, -1 will
never equal (unsigned long)INADDR_NONE.


# 1.15 07-Jan-1996 pk

Produce less output on -q as promised by the man page (John Hawkinson; PR#998).


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.14 20-Apr-1995 mycroft

Interface-specific routes can be static.


# 1.13 20-Apr-1995 mycroft

Implement the document `-llinfo' flag.


# 1.12 18-Apr-1995 mycroft

Remove extra `break;'.


# 1.11 18-Mar-1995 cgd

convert to new RCS Id conventions; reduce my headache


# 1.10 24-Dec-1994 cgd

kill some extraneous equal signs.


# 1.9 23-Sep-1994 mycroft

Remove some more uses of obsolete functions.


# 1.8 23-Sep-1994 mycroft

Eliminate uses of some obsolete functions.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.7 13-May-1994 mycroft

Clean up import.


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 25-Apr-1993 mycroft

Compile X.25, OSI, and NS code.


# 1.4 18-Apr-1993 mycroft

Cleanup for GCC 2.


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.3 23-Mar-1993 cgd

changed "Id" to "Header" for rcsids


# 1.2 22-Mar-1993 cgd

added rcs ids to all files


# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
Initial revision


# 1.156 16-Jun-2017 ozaki-r

Support -c <count> option for route monitor

route command exits if it receives <count> routing messages where
<count> is a value specified by -c.

The option is useful to get only particular message(s) in a test script.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320
# 1.155 17-Mar-2017 roy

Report the PID for the process changing the address.


Revision tags: bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.154 04-Apr-2016 ozaki-r

branches: 1.154.2; 1.154.4;
Separate nexthop caches from the routing table

By this change, nexthop caches (IP-MAC address pair) are not stored
in the routing table anymore. Instead nexthop caches are stored in
each network interface; we already have lltable/llentry data structure
for this purpose. This change also obsoletes the concept of cloning/cloned
routes. Cloned routes no longer exist while cloning routes still exist
with renamed to connected routes.

Noticeable changes are:
- Nexthop caches aren't listed in route show/netstat -r
- sysctl(NET_RT_DUMP) doesn't return them
- If RTF_LLDATA is specified, it returns nexthop caches
- Several definitions of routing flags and messages are removed
- RTF_CLONING, RTF_XRESOLVE, RTF_LLINFO, RTF_CLONED and RTM_RESOLVE
- RTF_CONNECTED is added
- It has the same value of RTF_CLONING for backward compatibility
- route's -xresolve, -[no]cloned and -llinfo options are removed
- -[no]cloning remains because it seems there are users
- -[no]connected is introduced and recommended
to be used instead of -[no]cloning
- route show/netstat -r drops some flags
- 'L' and 'c' are not seen anymore
- 'C' now indicates a connected route
- Gateway value of a route of an interface address is now not
a L2 address but "link#N" like a connected (cloning) route
- Proxy ARP: "arp -s ... pub" doesn't create a route

You can know details of behavior changes by seeing diffs under tests/.

Proposed on tech-net and tech-kern:
http://mail-index.netbsd.org/tech-net/2016/03/11/msg005701.html


# 1.153 23-Jan-2016 christos

no need for <sys/mbuf.h>


# 1.152 17-Jan-2016 christos

PR/50671: David Binderman: fix memory leak.


# 1.151 23-Mar-2015 roy

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.


# 1.150 26-Feb-2015 roy

Teach route(8) about RTF_LOCAL.


# 1.149 20-Dec-2014 prlw1

MKINET6=no build fixes

http://mail-index.netbsd.org/tech-net/2014/12/13/msg004898.html


# 1.148 17-Dec-2014 roy

Note that RTM_CHANGE can also change the gateway


# 1.147 12-Nov-2014 christos

PR/47704: Takahiro HAYASHI: Add -L flag


# 1.146 07-Nov-2014 christos

Now that the code can support tags and verbose route printing, enable them.
Also document previously undocumented flags.


# 1.145 06-Nov-2014 christos

Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.144 19-Oct-2013 christos

branches: 1.144.4;
use correct function


# 1.143 19-Oct-2013 christos

use symbolic flags


# 1.142 19-Oct-2013 christos

use scopeid functions


# 1.141 18-Oct-2013 christos

avoid pointer gymnastics


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.140 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.139 04-Oct-2012 uwe

Fix fallout from 1.129 that converted sou::so_foo from unions to
pointers but missed (char *)&soup->so_foo => (char *)soup->so_foo in
mask_addr(). It worked by luck - unless it didn't: due to pointer
numerology on amd64 route add -net ClassC without explicit /24 prefix
length specification would result into /16 destination instead of /24.


# 1.138 08-Aug-2012 christos

branches: 1.138.2;
remove useless rump headers.


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.137 17-Mar-2012 christos

PR/42179: Christoph Badura: Be a little friendlier about missing args.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.136 26-Dec-2011 christos

branches: 1.136.2;
Off by one and clarity improvement from Christian Biere


# 1.135 24-Dec-2011 christos

PR/45661: Henning Petersen: Overlapping buffer in route.c.


# 1.134 11-Nov-2011 gdt

Move RTF_ANNOUNCE flag so that it no longer conflicts with RTF_PROTO2.

RTF_ANNOUNCE was defined as RTF_PROTO2. The flag is used to indicated
that host should act as a proxy for a link level arp or ndp request.
(If RTF_PROTO2 is used as an experimental flag (as advertised),
various problems can occur.)

This commit provides a first-class definition with its own bit for
RTF_ANNOUNCE, removes the old aliasing definitions, and adds support
for the new RTF_ANNOUNCE flag to netstat(8) and route(8).,

Also, remove unused RTF_ flags that collide with RTF_PROTO1:
netinet/icmp6.h defined RTF_PROBEMTU as RTF_PROTO1
netinet/if_inarp.h defined RTF_USETRAILERS as RTF_PROTO1
(Neither of these flags are used anywhere. Both have been removed
to reduce chances of collision with RTF_PROTO1.)

Figuring this out and the diff are the work of Beverly Schwartz of
BBN.

(Passed release build, boot in VM, with no apparently related atf
failures.)

Approved for Public Release, Distribution Unlimited
This material is based upon work supported by the Defense Advanced
Research Projects Agency and Space and Naval Warfare Systems Center,
Pacific, under Contract No. N66001-09-C-2073.


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.133 07-Oct-2011 joerg

branches: 1.133.2;
Simplify.


# 1.132 29-Aug-2011 joerg

Use __dead


# 1.131 01-Jul-2011 joerg

Fix memset usage.


# 1.130 22-Jun-2011 kefren

don't compile tag functions if SMALL is defined. Should fix the build


# 1.129 21-Jun-2011 kefren

Alloc dynamically sockunions in sou.
Teach route(8) about multiple tags. E.G.: -tag 100,20,33
XXX: needs documentation


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.128 01-Feb-2011 matt

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.


Revision tags: matt-mips64-premerge-20101231
# 1.127 13-Dec-2010 pooka

branches: 1.127.2;
Convert from RUMP_ACTION to RUMPPRG.


# 1.126 12-Nov-2010 roy

Support the new RTM_IFINFO and RTM_CHGADDR messages.


# 1.125 05-Nov-2010 pooka

adapt to new rumpclient_init() signature


# 1.124 04-Nov-2010 pooka

#ifdef variable correctly


# 1.123 04-Nov-2010 pooka

be consistent in what to leave outside of SMALL


# 1.122 04-Nov-2010 pooka

Support RUMP_ACTION to compile a rump kernel client.


# 1.121 26-Jun-2010 kefren

add MPLS clue - mpls and tag keywords


# 1.120 12-May-2010 christos

PR/40455: Mihai Chelaru: Add noreject noblackhole options


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base mjf-devfs2-base
# 1.119 28-Dec-2008 christos

parse unsigned long with strtoul not atoi


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3
# 1.118 10-Sep-2008 dyoung

branches: 1.118.6;
Get the socket addresses for dst/gateway/netmask/interface/ifaddr
out of the global namespace.


# 1.117 10-Sep-2008 dyoung

Don't cast a sockunion * to sockaddr *. Instead, reference the
sockaddr inside of the sockunion.


# 1.116 10-Sep-2008 dyoung

Delete superfluous casts to void *.


# 1.115 10-Sep-2008 dyoung

Constify.


# 1.114 10-Sep-2008 dyoung

Constify.


# 1.113 10-Sep-2008 dyoung

Constify.

For clarity's sake, do not assign a new value to inet_makenetandmask()'s
argument, `inet'.


# 1.112 09-Sep-2008 dyoung

Extract subroutine extract_addrs() for reuse, later.

Replace the anonymous constant, 0, with AF_UNSPEC.


# 1.111 09-Sep-2008 dyoung

Constify.


# 1.110 09-Sep-2008 dyoung

Shorten a staircase. Remove superfluous parentheses from return
statements. Constify.


# 1.109 09-Sep-2008 dyoung

Use a union and sizeof() to avoid a cast and an anonymous constant
buffer length, respectively.


# 1.108 09-Sep-2008 dyoung

Use bool.


Revision tags: wrstuden-revivesa-base-2
# 1.107 20-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking cube-autoconf-base mjf-devfs-base matt-armv6-base matt-mips64-base hpcarm-cleanup-base
# 1.106 18-Feb-2007 hubertf

branches: 1.106.12; 1.106.16;
TSEL() is const char* now


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base netbsd-4-base
# 1.105 11-Nov-2006 apb

Fix a bug that caused 0.0.0.0/0 to be treated like 0.0.0.0/32.

foo << 32 is undefined per section 6.5.7 of the C99 standard
if foo is (or is promoted to) a 32-bit type.


# 1.104 23-Sep-2006 dyoung

Let us qualify 'route flush' and 'route show' commands with -llinfo
and -host flags, which is useful for displaying/flushing ARP entries:

# route -n show -inet -llinfo -host
Routing table

Internet:
Destination Gateway Flags
169.254.1.119 link#1 UH
169.254.230.110 00:02:6f:21:e6:6e UH
# route -n flush -inet -llinfo -host
169.254.1.119 done
169.254.230.110 0.2.6f.21.e6.6e done
169.254.237.70 done
# route -n show -inet -llinfo -host
Routing table
#

This will help me address bin/11079, "dhclient may require arp and sed".

Extract common code from flushroutes() and show(), creating
parse_show_opts().

While I'm here, make small cosmetic changes to flushroutes().


# 1.103 23-Sep-2006 dyoung

Move the #ifndef SMALL code together.


# 1.102 23-Sep-2006 dyoung

Use the symbol AF_UNSPEC instead of 0 as appropriate.


# 1.101 23-Sep-2006 dyoung

Remove dead code.


# 1.100 26-Aug-2006 matt

Remove XNS and CCITT/X25 bits.


Revision tags: abandoned-netbsd-4-base
# 1.99 06-Aug-2006 dyoung

KNF err(3), errx(3) usage, indentation, braces.


# 1.98 06-Aug-2006 dyoung

Add route keywords -nocloned, -nocloning.


# 1.97 29-Jan-2006 wiz

Use default option order (AaBbCc...).


# 1.96 26-Jan-2006 is

Print the INET netmask if it is non-contiguous.


# 1.95 25-Jan-2006 christos

PR/32632: Yves-Emmanuel JUTARD: Improvment suggestion in 'route' display.
Add a new -S flag that prints a space for missing flags.


# 1.94 25-Jan-2006 christos

PR/32629: Yves-Emmanuel JUTARD: Type errors in sbin/route/route.c, another
u_char/char conflict.


# 1.93 31-Aug-2005 ginsbach

Add full IPv6 syntax support when route is built with -DSMALL and -DINET6.
Fixes PR/23937. Adapted from supplied patch.


# 1.92 30-Aug-2005 ginsbach

Clean up some minor nits:
+ style (KNF).
. don't cast NULL
. white space clean up
+ use consistent format for error messages.
+ plug memory leaks and avoid malloc(0).
+ verbose message should display even when routing table is empty
(flushroutes).


# 1.91 15-Aug-2005 ginsbach

Make sure that a netmask socket address value prints appropriately when the
family is unset. Either the destination or interface address socket address
family value is used. This change prevents the following sort of output:

RTM_NEWADDR: address being added to iface: len 60, metric 0, flags:<UP>
sockaddrs: <NETMASK,IFA,BRD>
(0) 00.00.ff.00.00 127.0.0.1 127.0.0.1

With this change the last line becomes:

255.0.0.0 127.0.0.1 127.0.0.1

Also make sure that when using a generated inet netmask the address family
is set. With this change a generated netmask will print appropriately
when using the verbose (-v) option.


# 1.90 12-Aug-2005 ginsbach

Make sure the get command always exits non-zero on error. This makes things
like the following work as expected.

#!/bin/sh

if ! route -sn get default >/dev/null 2>&1; then
echo default gateway not set
exit 1
fi
echo default gateway set

Handle routing socket write(2) errors when they occur. This produces
better diagnostics by allowing for handling of the special route errno
values ESRCH, EBUSY, and ENOBUFS even with the quiet (-q) option or
when doing a get command.


# 1.89 12-Aug-2005 ginsbach

Trim the local domain name in routename() for INET6 lookups; similar to
INET lookups.


# 1.88 10-Aug-2005 he

Make this build for __GNUC__ <= 2 (i.e. for vax). The cast to
caddr_t removes a const qualifier. Instead, cast the first element
of the subtraction to "struct sockaddr *" to work around the problem.


# 1.87 09-Aug-2005 ginsbach

Accept protocol flags, i.e. -inet, -inet6, with the show command.
[From OpenBSD via DragonFly BSD]


# 1.86 09-Aug-2005 ginsbach

Fix the default case in sodump(). Printing the address of the "which"
string isn't really that useful. Instead print the string and the value
of sa_family.


# 1.85 09-Aug-2005 ginsbach

More style nits (KNF); casts and sizeof's are not followed by a space.


# 1.84 20-Jul-2005 ginsbach

switch is not a function, so add a space; sort switch elements
alphabetically (KNF).


# 1.83 15-Jul-2005 ginsbach

* Exit non-zero error code when flushroute() fails operating on the
routing socket, e.g. running route flush as non-root.

* When quiet (-q) don't append error string to a non-existent
diagnostic output (stdout). The error diagnostic is still written
to stderr. [from FreeBSD]

* Use warn(3) in place of perror(3).


# 1.82 26-Jun-2005 christos

const poisoning.


# 1.81 25-Jun-2005 dyoung

Teach route(8) to print the messages generated by net80211.


# 1.80 19-May-2005 ginsbach

Convert prefixlen() to ANSI function declaration. Missed by earlier
conversion.


# 1.79 19-May-2005 ginsbach

Due to a limitation in inet_addr(3) it was not possible to specify a
netmask value of 0xffffffff (INADDR_NONE). Fix by using inet_aton(3).
Note it was possible to specify the same mask as the dotted quad
255.255.255.255 because of a later call to gethostbyname(3).
[From FreeBSD]


# 1.78 13-May-2005 ginsbach

Fix botched prior commit. Additional debugging error messages mistakenly
committed.


# 1.77 12-May-2005 ginsbach

* Honor -net when using CIDR (net/mask) notation. This differs
from the default CIDR (host/mask) interpretation. As discussed on
tech-net.

* Use errx() in place of fprintf() and exit(). Make the error message
formats consistent.


# 1.76 10-May-2005 ginsbach

Fix macro NEXTADDR so that the names, like so_dst, are printed
rather than u. The preprocessor doesn't do replacement within
strings, so the # string creation operator must be used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.75 05-Feb-2005 xtraeme

Kill __P(), use ANSI function declarations.


# 1.74 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


# 1.73 15-May-2004 itojun

bump buffer size for any_ntoa(), for huge sa_len


# 1.72 15-May-2004 itojun

2-byte read overrun for unknown sockaddr. from openbsd
XXX out[64], is it safe? what if sa_len > 23?


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.71 05-Jan-2004 jmmv

Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.


# 1.70 01-Oct-2003 itojun

print prefixlen on -show


# 1.69 16-Sep-2003 cube

Remove a comment that referred to a non-committed part of the patch I
submitted for bin/17613. Ok'd by mrg@.


# 1.68 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.


# 1.67 19-Jul-2003 jrf

This is an updated submitted patch originally written by Jim Rees
and sent in by Greg Hudson as seen in PR misc/3227. Basically what it
does is adds a flushall option which deletes all but localhost routes.
This is done by andoring in a flag called doall (1 means do all routes
including gateway, 0 means do a regular flush). I have seen some
platforms that do this. I tested it out on ipv4 only, it works as
advertised. Commit was approved by christos@.


# 1.66 11-Jun-2003 christos

PR/21856: Robert Elz: Changes to route(8) to allow /n instead of -prefixlen
for INET6


# 1.65 03-Jun-2003 itojun

permit foo/bar notation, like "route add 10.0.0.0/8 127.0.0.1".
originally by provos


# 1.64 17-May-2003 itojun

strlcpy [a few mistakes found]


# 1.63 21-Apr-2003 jrf

This addresses PR 17613 when certain methods of adding routes would
muck up the routing tables. The patch was submitted by Quentin Garnier
<netbsd@quatriemek.com> and tweaked a little after it was reviewed
by Christos Zoulas <christos@netbsd.org>. Final change/commit approved
by Christos.


# 1.62 03-Apr-2003 jrf

Made a note in the code about the -d and -d options brought up in
PR 18674. Thanks to Chris Jones for pointing it out.


Revision tags: fvdl_fs64_base
# 1.61 18-Oct-2002 itojun

correct prefixlen handling for IPv4.


# 1.60 18-Oct-2002 itojun

Make prefixlen check to make sure its argument is present before deref
from openbsd


# 1.59 20-Jul-2002 grant

sweep of errx/warnx, remove unnecessary trailing \n


# 1.58 10-Jun-2002 itojun

permit DNS names to address portion. they will be considered as RTF_HOST
if specified as destination (as there's no getnetbyname in IPv6).


# 1.57 05-Jun-2002 itojun

if we're unsure about prefixlen, don't say "128".


# 1.56 05-Jun-2002 itojun

more correct ion to RTF_HOST handling.


# 1.55 04-Jun-2002 itojun

do not have -prefixlen 128 on RTF_HOST.
From: Dawid Szymanski <dawszy@arhea.net>


Revision tags: netbsd-1-6-base
# 1.54 20-May-2002 itojun

branches: 1.54.2;
raise RTF_HOST if destination is a host (/128). from ume


# 1.53 21-Feb-2002 christos

PR/15672: Love: route monitor missing info


# 1.52 15-Nov-2001 christos

Make route exit with a non-zero error code when operations to the routing
socket fails. eg, running route add 1.2.3.4 5.6.7.8 as non root.


# 1.51 02-Nov-2001 lukem

fix -Wshadow warnings


# 1.50 24-Oct-2001 atatat

Provide a short output format for the get command that only prints the
address corresponding to RTA_GATEWAY, or nothing if it doesn't exist.
Modify the exit value of route depending on this, so that one can do
stuff like:

#!/bin/sh
gw=`route -sn get default 2>/dev/null`
if [ -z "$gw" ]; then
echo no default route
exit 1
fi
ping -w1 -c1 $gw >/dev/null 2>&1
if ! route -sn get $gw >/dev/null; then
echo default gateway not responding
exit 1
fi
echo default gateway is at $gw


# 1.49 24-Oct-2001 atatat

Print a R on reject routes to indicate that they're not normal routes,
and check netmask (or prefix) length as well as the destination
address when determining if a route is a "default" or not. This means
that the output from 'route show' will no longer say:

Internet6:
Destination Gateway Flags
default localhost UG
default localhost UG

but instead

Internet6:
Destination Gateway Flags
::/104 localhost UGR
::/96 localhost UGR

which makes much more sense.


# 1.48 20-Jul-2001 itojun

off-by-one error in -prefixlen arg validation (do not permit 129 on IPv6)


# 1.47 20-Jul-2001 itojun

make prefixlen work on IPv4 too


# 1.46 16-Jul-2001 bad

The way pmsg_addrs() is used requires that it always prints a newline and
flushes stdout before returning.

Previously the decoded output for a message was stuck in stdio buffers until
the next arrived.


# 1.45 19-Feb-2001 cgd

convert to use getprogname()


# 1.44 04-Feb-2001 christos

remove nested externs.


# 1.43 27-Jan-2001 itojun

support -cloned command line flag.
i don't think anyone ever going to use it.


# 1.42 27-Jan-2001 itojun

mark cloned routes with RTF_CLONED. present it with netstat -r by "c".

let static routes overwrite cloned routes, as cloned routes can come back again
if necessary. behavior same as freebsd/bsdi, code partially from bsdi42.
(NRL rt->rt_parent was not added)
should fix PR 11916 and maybe some other PRs with ARP behavior.

recompilation of usr.sbin/route6d is suggested.


# 1.41 27-Jan-2001 itojun

support RTF_BLACKHOLE.

XXX route show is total duplicate of netstat -r, we need to either remove
route show, or share the same source code, otherwise maintenance cost
bites (and is biting) us


# 1.40 27-Jan-2001 itojun

remove use of uninitialized route (struct ortentry).
it seems that the bug was born during 4.3reno -> 4.4Lite1 transition.


# 1.39 10-Oct-2000 itojun

on "route monitor", print RTM_IFANNOUNCE, RTM_IFINFO (new #), and others.


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.38 04-May-2000 sommerfeld

branches: 1.38.4;
Allow INET6 to be used with SMALL without undefined symbols


# 1.37 20-Apr-2000 itojun

use scoped notation for link-local multicast too.


# 1.36 20-Apr-2000 itojun

support extended scoped address notation (fe80::1%de0).
it hides implementation detail (embedded ifid) from the users.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.35 03-Dec-1999 itojun

don't make "-prefixlen 64" a default in -inet6 case. the past behavior
was not compatible with past practice ("route get" did not work right).

sync with recent KAME.


Revision tags: comdex-fall-1999-base
# 1.34 01-Nov-1999 sommerfeld

Display local address associated with route (if any) in "route get".


# 1.33 03-Sep-1999 itojun

branches: 1.33.2;
fix alignment issue in routing socket data, on 64bit arch (i.e. alpha).
sockaddrs are packed with ROUNDUP() in sys/net/rtsock.c so userland
programs needs to follow that.

PR: 8179


# 1.32 06-Jul-1999 mjacob

Incorrect integration. ctime takes a time_t value, not a long.


# 1.31 02-Jul-1999 itojun

IPv6-ready route command (-inet6 and -prefixlen are added)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.30 23-Oct-1998 lukem

branches: 1.30.2;
* implement -f; flush all routes before executing command
* reset af to 0 in flushroutes() and newroute()
* cleanup -DSMALL:
- `flush' and AF_APPLETALK is supported (the latter had partial support)
- AF_NS, AF_ISO, and AF_CCITT are not supported at all (rather than being
- partially unsupported).


# 1.29 26-Jul-1998 mycroft

const poisoning.


# 1.28 01-Apr-1998 kleink

Need <time.h> for time() prototype.


# 1.27 05-Feb-1998 ross

64-bit sweep, "route -v show" was spinning forever.


# 1.26 16-Nov-1997 christos

Use {warn,err}{,x}(3) instead of printf's


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 01-Oct-1997 enami

Don't declare optind.


# 1.24 16-Sep-1997 lukem

resolve conflicts from lite-2 import


# 1.23 15-Sep-1997 lukem

* cleanup for WARNS=1
* use .Nm correctly
* deprecate register
* getopt returns -1 not EOF


# 1.22 02-Sep-1997 thorpej

Fix uninitialized pointer botch when attempting to flush an already
empty routing table. From Matthias Scheler <tron@lyssa.owl.de>, in
PR #4074.


# 1.21 27-Apr-1997 thorpej

Don't SEGV if a qualifier is passed without an argument. From
Geoff Wing <mason@primenet.com.au>, fixes PR #2700.


# 1.20 21-Apr-1997 mrg

KNF. be safe with buffers.


# 1.19 03-Apr-1997 christos

- Add netatalk bits
- Add prototypes
- Fix printf formats


# 1.18 22-Feb-1997 carrel

Remove uid checks since the kernel now handles this and route(1) is no
longer setuid.
Document the "Permission denied" msg in the man page since this is
_slightly_ less clear than route(1)'s old error msg.


# 1.17 15-Nov-1996 gwr

As discussed some time ago, add a "show" sub-command.
Also allow compilation with -DSMALL to ommit support for
non-essential protocols (i.e. when built into a ramdisk).
Use a less hack-ish way to generate keywords.[ch] and just
check in the result (helps ../../distrib/utils/x_route).


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.16 15-Apr-1996 cgd

check returns of inet_addr() and inet_network() against INADDR_NONE,
not -1, per the manual page. on 64-bit systems like the alpha, -1 will
never equal (unsigned long)INADDR_NONE.


# 1.15 07-Jan-1996 pk

Produce less output on -q as promised by the man page (John Hawkinson; PR#998).


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.14 20-Apr-1995 mycroft

Interface-specific routes can be static.


# 1.13 20-Apr-1995 mycroft

Implement the document `-llinfo' flag.


# 1.12 18-Apr-1995 mycroft

Remove extra `break;'.


# 1.11 18-Mar-1995 cgd

convert to new RCS Id conventions; reduce my headache


# 1.10 24-Dec-1994 cgd

kill some extraneous equal signs.


# 1.9 23-Sep-1994 mycroft

Remove some more uses of obsolete functions.


# 1.8 23-Sep-1994 mycroft

Eliminate uses of some obsolete functions.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.7 13-May-1994 mycroft

Clean up import.


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 25-Apr-1993 mycroft

Compile X.25, OSI, and NS code.


# 1.4 18-Apr-1993 mycroft

Cleanup for GCC 2.


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.3 23-Mar-1993 cgd

changed "Id" to "Header" for rcsids


# 1.2 22-Mar-1993 cgd

added rcs ids to all files


# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
Initial revision


Revision tags: prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320
# 1.155 17-Mar-2017 roy

Report the PID for the process changing the address.


Revision tags: bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.154 04-Apr-2016 ozaki-r

branches: 1.154.2; 1.154.4;
Separate nexthop caches from the routing table

By this change, nexthop caches (IP-MAC address pair) are not stored
in the routing table anymore. Instead nexthop caches are stored in
each network interface; we already have lltable/llentry data structure
for this purpose. This change also obsoletes the concept of cloning/cloned
routes. Cloned routes no longer exist while cloning routes still exist
with renamed to connected routes.

Noticeable changes are:
- Nexthop caches aren't listed in route show/netstat -r
- sysctl(NET_RT_DUMP) doesn't return them
- If RTF_LLDATA is specified, it returns nexthop caches
- Several definitions of routing flags and messages are removed
- RTF_CLONING, RTF_XRESOLVE, RTF_LLINFO, RTF_CLONED and RTM_RESOLVE
- RTF_CONNECTED is added
- It has the same value of RTF_CLONING for backward compatibility
- route's -xresolve, -[no]cloned and -llinfo options are removed
- -[no]cloning remains because it seems there are users
- -[no]connected is introduced and recommended
to be used instead of -[no]cloning
- route show/netstat -r drops some flags
- 'L' and 'c' are not seen anymore
- 'C' now indicates a connected route
- Gateway value of a route of an interface address is now not
a L2 address but "link#N" like a connected (cloning) route
- Proxy ARP: "arp -s ... pub" doesn't create a route

You can know details of behavior changes by seeing diffs under tests/.

Proposed on tech-net and tech-kern:
http://mail-index.netbsd.org/tech-net/2016/03/11/msg005701.html


# 1.153 23-Jan-2016 christos

no need for <sys/mbuf.h>


# 1.152 17-Jan-2016 christos

PR/50671: David Binderman: fix memory leak.


# 1.151 23-Mar-2015 roy

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.


# 1.150 26-Feb-2015 roy

Teach route(8) about RTF_LOCAL.


# 1.149 20-Dec-2014 prlw1

MKINET6=no build fixes

http://mail-index.netbsd.org/tech-net/2014/12/13/msg004898.html


# 1.148 17-Dec-2014 roy

Note that RTM_CHANGE can also change the gateway


# 1.147 12-Nov-2014 christos

PR/47704: Takahiro HAYASHI: Add -L flag


# 1.146 07-Nov-2014 christos

Now that the code can support tags and verbose route printing, enable them.
Also document previously undocumented flags.


# 1.145 06-Nov-2014 christos

Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.144 19-Oct-2013 christos

branches: 1.144.4;
use correct function


# 1.143 19-Oct-2013 christos

use symbolic flags


# 1.142 19-Oct-2013 christos

use scopeid functions


# 1.141 18-Oct-2013 christos

avoid pointer gymnastics


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.140 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.139 04-Oct-2012 uwe

Fix fallout from 1.129 that converted sou::so_foo from unions to
pointers but missed (char *)&soup->so_foo => (char *)soup->so_foo in
mask_addr(). It worked by luck - unless it didn't: due to pointer
numerology on amd64 route add -net ClassC without explicit /24 prefix
length specification would result into /16 destination instead of /24.


# 1.138 08-Aug-2012 christos

branches: 1.138.2;
remove useless rump headers.


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.137 17-Mar-2012 christos

PR/42179: Christoph Badura: Be a little friendlier about missing args.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.136 26-Dec-2011 christos

branches: 1.136.2;
Off by one and clarity improvement from Christian Biere


# 1.135 24-Dec-2011 christos

PR/45661: Henning Petersen: Overlapping buffer in route.c.


# 1.134 11-Nov-2011 gdt

Move RTF_ANNOUNCE flag so that it no longer conflicts with RTF_PROTO2.

RTF_ANNOUNCE was defined as RTF_PROTO2. The flag is used to indicated
that host should act as a proxy for a link level arp or ndp request.
(If RTF_PROTO2 is used as an experimental flag (as advertised),
various problems can occur.)

This commit provides a first-class definition with its own bit for
RTF_ANNOUNCE, removes the old aliasing definitions, and adds support
for the new RTF_ANNOUNCE flag to netstat(8) and route(8).,

Also, remove unused RTF_ flags that collide with RTF_PROTO1:
netinet/icmp6.h defined RTF_PROBEMTU as RTF_PROTO1
netinet/if_inarp.h defined RTF_USETRAILERS as RTF_PROTO1
(Neither of these flags are used anywhere. Both have been removed
to reduce chances of collision with RTF_PROTO1.)

Figuring this out and the diff are the work of Beverly Schwartz of
BBN.

(Passed release build, boot in VM, with no apparently related atf
failures.)

Approved for Public Release, Distribution Unlimited
This material is based upon work supported by the Defense Advanced
Research Projects Agency and Space and Naval Warfare Systems Center,
Pacific, under Contract No. N66001-09-C-2073.


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.133 07-Oct-2011 joerg

branches: 1.133.2;
Simplify.


# 1.132 29-Aug-2011 joerg

Use __dead


# 1.131 01-Jul-2011 joerg

Fix memset usage.


# 1.130 22-Jun-2011 kefren

don't compile tag functions if SMALL is defined. Should fix the build


# 1.129 21-Jun-2011 kefren

Alloc dynamically sockunions in sou.
Teach route(8) about multiple tags. E.G.: -tag 100,20,33
XXX: needs documentation


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.128 01-Feb-2011 matt

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.


Revision tags: matt-mips64-premerge-20101231
# 1.127 13-Dec-2010 pooka

branches: 1.127.2;
Convert from RUMP_ACTION to RUMPPRG.


# 1.126 12-Nov-2010 roy

Support the new RTM_IFINFO and RTM_CHGADDR messages.


# 1.125 05-Nov-2010 pooka

adapt to new rumpclient_init() signature


# 1.124 04-Nov-2010 pooka

#ifdef variable correctly


# 1.123 04-Nov-2010 pooka

be consistent in what to leave outside of SMALL


# 1.122 04-Nov-2010 pooka

Support RUMP_ACTION to compile a rump kernel client.


# 1.121 26-Jun-2010 kefren

add MPLS clue - mpls and tag keywords


# 1.120 12-May-2010 christos

PR/40455: Mihai Chelaru: Add noreject noblackhole options


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base mjf-devfs2-base
# 1.119 28-Dec-2008 christos

parse unsigned long with strtoul not atoi


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3
# 1.118 10-Sep-2008 dyoung

branches: 1.118.6;
Get the socket addresses for dst/gateway/netmask/interface/ifaddr
out of the global namespace.


# 1.117 10-Sep-2008 dyoung

Don't cast a sockunion * to sockaddr *. Instead, reference the
sockaddr inside of the sockunion.


# 1.116 10-Sep-2008 dyoung

Delete superfluous casts to void *.


# 1.115 10-Sep-2008 dyoung

Constify.


# 1.114 10-Sep-2008 dyoung

Constify.


# 1.113 10-Sep-2008 dyoung

Constify.

For clarity's sake, do not assign a new value to inet_makenetandmask()'s
argument, `inet'.


# 1.112 09-Sep-2008 dyoung

Extract subroutine extract_addrs() for reuse, later.

Replace the anonymous constant, 0, with AF_UNSPEC.


# 1.111 09-Sep-2008 dyoung

Constify.


# 1.110 09-Sep-2008 dyoung

Shorten a staircase. Remove superfluous parentheses from return
statements. Constify.


# 1.109 09-Sep-2008 dyoung

Use a union and sizeof() to avoid a cast and an anonymous constant
buffer length, respectively.


# 1.108 09-Sep-2008 dyoung

Use bool.


Revision tags: wrstuden-revivesa-base-2
# 1.107 20-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking cube-autoconf-base mjf-devfs-base matt-armv6-base matt-mips64-base hpcarm-cleanup-base
# 1.106 18-Feb-2007 hubertf

branches: 1.106.12; 1.106.16;
TSEL() is const char* now


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base netbsd-4-base
# 1.105 11-Nov-2006 apb

Fix a bug that caused 0.0.0.0/0 to be treated like 0.0.0.0/32.

foo << 32 is undefined per section 6.5.7 of the C99 standard
if foo is (or is promoted to) a 32-bit type.


# 1.104 23-Sep-2006 dyoung

Let us qualify 'route flush' and 'route show' commands with -llinfo
and -host flags, which is useful for displaying/flushing ARP entries:

# route -n show -inet -llinfo -host
Routing table

Internet:
Destination Gateway Flags
169.254.1.119 link#1 UH
169.254.230.110 00:02:6f:21:e6:6e UH
# route -n flush -inet -llinfo -host
169.254.1.119 done
169.254.230.110 0.2.6f.21.e6.6e done
169.254.237.70 done
# route -n show -inet -llinfo -host
Routing table
#

This will help me address bin/11079, "dhclient may require arp and sed".

Extract common code from flushroutes() and show(), creating
parse_show_opts().

While I'm here, make small cosmetic changes to flushroutes().


# 1.103 23-Sep-2006 dyoung

Move the #ifndef SMALL code together.


# 1.102 23-Sep-2006 dyoung

Use the symbol AF_UNSPEC instead of 0 as appropriate.


# 1.101 23-Sep-2006 dyoung

Remove dead code.


# 1.100 26-Aug-2006 matt

Remove XNS and CCITT/X25 bits.


Revision tags: abandoned-netbsd-4-base
# 1.99 06-Aug-2006 dyoung

KNF err(3), errx(3) usage, indentation, braces.


# 1.98 06-Aug-2006 dyoung

Add route keywords -nocloned, -nocloning.


# 1.97 29-Jan-2006 wiz

Use default option order (AaBbCc...).


# 1.96 26-Jan-2006 is

Print the INET netmask if it is non-contiguous.


# 1.95 25-Jan-2006 christos

PR/32632: Yves-Emmanuel JUTARD: Improvment suggestion in 'route' display.
Add a new -S flag that prints a space for missing flags.


# 1.94 25-Jan-2006 christos

PR/32629: Yves-Emmanuel JUTARD: Type errors in sbin/route/route.c, another
u_char/char conflict.


# 1.93 31-Aug-2005 ginsbach

Add full IPv6 syntax support when route is built with -DSMALL and -DINET6.
Fixes PR/23937. Adapted from supplied patch.


# 1.92 30-Aug-2005 ginsbach

Clean up some minor nits:
+ style (KNF).
. don't cast NULL
. white space clean up
+ use consistent format for error messages.
+ plug memory leaks and avoid malloc(0).
+ verbose message should display even when routing table is empty
(flushroutes).


# 1.91 15-Aug-2005 ginsbach

Make sure that a netmask socket address value prints appropriately when the
family is unset. Either the destination or interface address socket address
family value is used. This change prevents the following sort of output:

RTM_NEWADDR: address being added to iface: len 60, metric 0, flags:<UP>
sockaddrs: <NETMASK,IFA,BRD>
(0) 00.00.ff.00.00 127.0.0.1 127.0.0.1

With this change the last line becomes:

255.0.0.0 127.0.0.1 127.0.0.1

Also make sure that when using a generated inet netmask the address family
is set. With this change a generated netmask will print appropriately
when using the verbose (-v) option.


# 1.90 12-Aug-2005 ginsbach

Make sure the get command always exits non-zero on error. This makes things
like the following work as expected.

#!/bin/sh

if ! route -sn get default >/dev/null 2>&1; then
echo default gateway not set
exit 1
fi
echo default gateway set

Handle routing socket write(2) errors when they occur. This produces
better diagnostics by allowing for handling of the special route errno
values ESRCH, EBUSY, and ENOBUFS even with the quiet (-q) option or
when doing a get command.


# 1.89 12-Aug-2005 ginsbach

Trim the local domain name in routename() for INET6 lookups; similar to
INET lookups.


# 1.88 10-Aug-2005 he

Make this build for __GNUC__ <= 2 (i.e. for vax). The cast to
caddr_t removes a const qualifier. Instead, cast the first element
of the subtraction to "struct sockaddr *" to work around the problem.


# 1.87 09-Aug-2005 ginsbach

Accept protocol flags, i.e. -inet, -inet6, with the show command.
[From OpenBSD via DragonFly BSD]


# 1.86 09-Aug-2005 ginsbach

Fix the default case in sodump(). Printing the address of the "which"
string isn't really that useful. Instead print the string and the value
of sa_family.


# 1.85 09-Aug-2005 ginsbach

More style nits (KNF); casts and sizeof's are not followed by a space.


# 1.84 20-Jul-2005 ginsbach

switch is not a function, so add a space; sort switch elements
alphabetically (KNF).


# 1.83 15-Jul-2005 ginsbach

* Exit non-zero error code when flushroute() fails operating on the
routing socket, e.g. running route flush as non-root.

* When quiet (-q) don't append error string to a non-existent
diagnostic output (stdout). The error diagnostic is still written
to stderr. [from FreeBSD]

* Use warn(3) in place of perror(3).


# 1.82 26-Jun-2005 christos

const poisoning.


# 1.81 25-Jun-2005 dyoung

Teach route(8) to print the messages generated by net80211.


# 1.80 19-May-2005 ginsbach

Convert prefixlen() to ANSI function declaration. Missed by earlier
conversion.


# 1.79 19-May-2005 ginsbach

Due to a limitation in inet_addr(3) it was not possible to specify a
netmask value of 0xffffffff (INADDR_NONE). Fix by using inet_aton(3).
Note it was possible to specify the same mask as the dotted quad
255.255.255.255 because of a later call to gethostbyname(3).
[From FreeBSD]


# 1.78 13-May-2005 ginsbach

Fix botched prior commit. Additional debugging error messages mistakenly
committed.


# 1.77 12-May-2005 ginsbach

* Honor -net when using CIDR (net/mask) notation. This differs
from the default CIDR (host/mask) interpretation. As discussed on
tech-net.

* Use errx() in place of fprintf() and exit(). Make the error message
formats consistent.


# 1.76 10-May-2005 ginsbach

Fix macro NEXTADDR so that the names, like so_dst, are printed
rather than u. The preprocessor doesn't do replacement within
strings, so the # string creation operator must be used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.75 05-Feb-2005 xtraeme

Kill __P(), use ANSI function declarations.


# 1.74 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


# 1.73 15-May-2004 itojun

bump buffer size for any_ntoa(), for huge sa_len


# 1.72 15-May-2004 itojun

2-byte read overrun for unknown sockaddr. from openbsd
XXX out[64], is it safe? what if sa_len > 23?


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.71 05-Jan-2004 jmmv

Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.


# 1.70 01-Oct-2003 itojun

print prefixlen on -show


# 1.69 16-Sep-2003 cube

Remove a comment that referred to a non-committed part of the patch I
submitted for bin/17613. Ok'd by mrg@.


# 1.68 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.


# 1.67 19-Jul-2003 jrf

This is an updated submitted patch originally written by Jim Rees
and sent in by Greg Hudson as seen in PR misc/3227. Basically what it
does is adds a flushall option which deletes all but localhost routes.
This is done by andoring in a flag called doall (1 means do all routes
including gateway, 0 means do a regular flush). I have seen some
platforms that do this. I tested it out on ipv4 only, it works as
advertised. Commit was approved by christos@.


# 1.66 11-Jun-2003 christos

PR/21856: Robert Elz: Changes to route(8) to allow /n instead of -prefixlen
for INET6


# 1.65 03-Jun-2003 itojun

permit foo/bar notation, like "route add 10.0.0.0/8 127.0.0.1".
originally by provos


# 1.64 17-May-2003 itojun

strlcpy [a few mistakes found]


# 1.63 21-Apr-2003 jrf

This addresses PR 17613 when certain methods of adding routes would
muck up the routing tables. The patch was submitted by Quentin Garnier
<netbsd@quatriemek.com> and tweaked a little after it was reviewed
by Christos Zoulas <christos@netbsd.org>. Final change/commit approved
by Christos.


# 1.62 03-Apr-2003 jrf

Made a note in the code about the -d and -d options brought up in
PR 18674. Thanks to Chris Jones for pointing it out.


Revision tags: fvdl_fs64_base
# 1.61 18-Oct-2002 itojun

correct prefixlen handling for IPv4.


# 1.60 18-Oct-2002 itojun

Make prefixlen check to make sure its argument is present before deref
from openbsd


# 1.59 20-Jul-2002 grant

sweep of errx/warnx, remove unnecessary trailing \n


# 1.58 10-Jun-2002 itojun

permit DNS names to address portion. they will be considered as RTF_HOST
if specified as destination (as there's no getnetbyname in IPv6).


# 1.57 05-Jun-2002 itojun

if we're unsure about prefixlen, don't say "128".


# 1.56 05-Jun-2002 itojun

more correct ion to RTF_HOST handling.


# 1.55 04-Jun-2002 itojun

do not have -prefixlen 128 on RTF_HOST.
From: Dawid Szymanski <dawszy@arhea.net>


Revision tags: netbsd-1-6-base
# 1.54 20-May-2002 itojun

branches: 1.54.2;
raise RTF_HOST if destination is a host (/128). from ume


# 1.53 21-Feb-2002 christos

PR/15672: Love: route monitor missing info


# 1.52 15-Nov-2001 christos

Make route exit with a non-zero error code when operations to the routing
socket fails. eg, running route add 1.2.3.4 5.6.7.8 as non root.


# 1.51 02-Nov-2001 lukem

fix -Wshadow warnings


# 1.50 24-Oct-2001 atatat

Provide a short output format for the get command that only prints the
address corresponding to RTA_GATEWAY, or nothing if it doesn't exist.
Modify the exit value of route depending on this, so that one can do
stuff like:

#!/bin/sh
gw=`route -sn get default 2>/dev/null`
if [ -z "$gw" ]; then
echo no default route
exit 1
fi
ping -w1 -c1 $gw >/dev/null 2>&1
if ! route -sn get $gw >/dev/null; then
echo default gateway not responding
exit 1
fi
echo default gateway is at $gw


# 1.49 24-Oct-2001 atatat

Print a R on reject routes to indicate that they're not normal routes,
and check netmask (or prefix) length as well as the destination
address when determining if a route is a "default" or not. This means
that the output from 'route show' will no longer say:

Internet6:
Destination Gateway Flags
default localhost UG
default localhost UG

but instead

Internet6:
Destination Gateway Flags
::/104 localhost UGR
::/96 localhost UGR

which makes much more sense.


# 1.48 20-Jul-2001 itojun

off-by-one error in -prefixlen arg validation (do not permit 129 on IPv6)


# 1.47 20-Jul-2001 itojun

make prefixlen work on IPv4 too


# 1.46 16-Jul-2001 bad

The way pmsg_addrs() is used requires that it always prints a newline and
flushes stdout before returning.

Previously the decoded output for a message was stuck in stdio buffers until
the next arrived.


# 1.45 19-Feb-2001 cgd

convert to use getprogname()


# 1.44 04-Feb-2001 christos

remove nested externs.


# 1.43 27-Jan-2001 itojun

support -cloned command line flag.
i don't think anyone ever going to use it.


# 1.42 27-Jan-2001 itojun

mark cloned routes with RTF_CLONED. present it with netstat -r by "c".

let static routes overwrite cloned routes, as cloned routes can come back again
if necessary. behavior same as freebsd/bsdi, code partially from bsdi42.
(NRL rt->rt_parent was not added)
should fix PR 11916 and maybe some other PRs with ARP behavior.

recompilation of usr.sbin/route6d is suggested.


# 1.41 27-Jan-2001 itojun

support RTF_BLACKHOLE.

XXX route show is total duplicate of netstat -r, we need to either remove
route show, or share the same source code, otherwise maintenance cost
bites (and is biting) us


# 1.40 27-Jan-2001 itojun

remove use of uninitialized route (struct ortentry).
it seems that the bug was born during 4.3reno -> 4.4Lite1 transition.


# 1.39 10-Oct-2000 itojun

on "route monitor", print RTM_IFANNOUNCE, RTM_IFINFO (new #), and others.


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.38 04-May-2000 sommerfeld

branches: 1.38.4;
Allow INET6 to be used with SMALL without undefined symbols


# 1.37 20-Apr-2000 itojun

use scoped notation for link-local multicast too.


# 1.36 20-Apr-2000 itojun

support extended scoped address notation (fe80::1%de0).
it hides implementation detail (embedded ifid) from the users.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.35 03-Dec-1999 itojun

don't make "-prefixlen 64" a default in -inet6 case. the past behavior
was not compatible with past practice ("route get" did not work right).

sync with recent KAME.


Revision tags: comdex-fall-1999-base
# 1.34 01-Nov-1999 sommerfeld

Display local address associated with route (if any) in "route get".


# 1.33 03-Sep-1999 itojun

branches: 1.33.2;
fix alignment issue in routing socket data, on 64bit arch (i.e. alpha).
sockaddrs are packed with ROUNDUP() in sys/net/rtsock.c so userland
programs needs to follow that.

PR: 8179


# 1.32 06-Jul-1999 mjacob

Incorrect integration. ctime takes a time_t value, not a long.


# 1.31 02-Jul-1999 itojun

IPv6-ready route command (-inet6 and -prefixlen are added)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.30 23-Oct-1998 lukem

branches: 1.30.2;
* implement -f; flush all routes before executing command
* reset af to 0 in flushroutes() and newroute()
* cleanup -DSMALL:
- `flush' and AF_APPLETALK is supported (the latter had partial support)
- AF_NS, AF_ISO, and AF_CCITT are not supported at all (rather than being
- partially unsupported).


# 1.29 26-Jul-1998 mycroft

const poisoning.


# 1.28 01-Apr-1998 kleink

Need <time.h> for time() prototype.


# 1.27 05-Feb-1998 ross

64-bit sweep, "route -v show" was spinning forever.


# 1.26 16-Nov-1997 christos

Use {warn,err}{,x}(3) instead of printf's


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 01-Oct-1997 enami

Don't declare optind.


# 1.24 16-Sep-1997 lukem

resolve conflicts from lite-2 import


# 1.23 15-Sep-1997 lukem

* cleanup for WARNS=1
* use .Nm correctly
* deprecate register
* getopt returns -1 not EOF


# 1.22 02-Sep-1997 thorpej

Fix uninitialized pointer botch when attempting to flush an already
empty routing table. From Matthias Scheler <tron@lyssa.owl.de>, in
PR #4074.


# 1.21 27-Apr-1997 thorpej

Don't SEGV if a qualifier is passed without an argument. From
Geoff Wing <mason@primenet.com.au>, fixes PR #2700.


# 1.20 21-Apr-1997 mrg

KNF. be safe with buffers.


# 1.19 03-Apr-1997 christos

- Add netatalk bits
- Add prototypes
- Fix printf formats


# 1.18 22-Feb-1997 carrel

Remove uid checks since the kernel now handles this and route(1) is no
longer setuid.
Document the "Permission denied" msg in the man page since this is
_slightly_ less clear than route(1)'s old error msg.


# 1.17 15-Nov-1996 gwr

As discussed some time ago, add a "show" sub-command.
Also allow compilation with -DSMALL to ommit support for
non-essential protocols (i.e. when built into a ramdisk).
Use a less hack-ish way to generate keywords.[ch] and just
check in the result (helps ../../distrib/utils/x_route).


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.16 15-Apr-1996 cgd

check returns of inet_addr() and inet_network() against INADDR_NONE,
not -1, per the manual page. on 64-bit systems like the alpha, -1 will
never equal (unsigned long)INADDR_NONE.


# 1.15 07-Jan-1996 pk

Produce less output on -q as promised by the man page (John Hawkinson; PR#998).


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.14 20-Apr-1995 mycroft

Interface-specific routes can be static.


# 1.13 20-Apr-1995 mycroft

Implement the document `-llinfo' flag.


# 1.12 18-Apr-1995 mycroft

Remove extra `break;'.


# 1.11 18-Mar-1995 cgd

convert to new RCS Id conventions; reduce my headache


# 1.10 24-Dec-1994 cgd

kill some extraneous equal signs.


# 1.9 23-Sep-1994 mycroft

Remove some more uses of obsolete functions.


# 1.8 23-Sep-1994 mycroft

Eliminate uses of some obsolete functions.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.7 13-May-1994 mycroft

Clean up import.


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 25-Apr-1993 mycroft

Compile X.25, OSI, and NS code.


# 1.4 18-Apr-1993 mycroft

Cleanup for GCC 2.


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.3 23-Mar-1993 cgd

changed "Id" to "Header" for rcsids


# 1.2 22-Mar-1993 cgd

added rcs ids to all files


# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
Initial revision


Revision tags: pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.154 04-Apr-2016 ozaki-r

Separate nexthop caches from the routing table

By this change, nexthop caches (IP-MAC address pair) are not stored
in the routing table anymore. Instead nexthop caches are stored in
each network interface; we already have lltable/llentry data structure
for this purpose. This change also obsoletes the concept of cloning/cloned
routes. Cloned routes no longer exist while cloning routes still exist
with renamed to connected routes.

Noticeable changes are:
- Nexthop caches aren't listed in route show/netstat -r
- sysctl(NET_RT_DUMP) doesn't return them
- If RTF_LLDATA is specified, it returns nexthop caches
- Several definitions of routing flags and messages are removed
- RTF_CLONING, RTF_XRESOLVE, RTF_LLINFO, RTF_CLONED and RTM_RESOLVE
- RTF_CONNECTED is added
- It has the same value of RTF_CLONING for backward compatibility
- route's -xresolve, -[no]cloned and -llinfo options are removed
- -[no]cloning remains because it seems there are users
- -[no]connected is introduced and recommended
to be used instead of -[no]cloning
- route show/netstat -r drops some flags
- 'L' and 'c' are not seen anymore
- 'C' now indicates a connected route
- Gateway value of a route of an interface address is now not
a L2 address but "link#N" like a connected (cloning) route
- Proxy ARP: "arp -s ... pub" doesn't create a route

You can know details of behavior changes by seeing diffs under tests/.

Proposed on tech-net and tech-kern:
http://mail-index.netbsd.org/tech-net/2016/03/11/msg005701.html


# 1.153 23-Jan-2016 christos

no need for <sys/mbuf.h>


# 1.152 17-Jan-2016 christos

PR/50671: David Binderman: fix memory leak.


# 1.151 23-Mar-2015 roy

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.


# 1.150 26-Feb-2015 roy

Teach route(8) about RTF_LOCAL.


# 1.149 20-Dec-2014 prlw1

MKINET6=no build fixes

http://mail-index.netbsd.org/tech-net/2014/12/13/msg004898.html


# 1.148 17-Dec-2014 roy

Note that RTM_CHANGE can also change the gateway


# 1.147 12-Nov-2014 christos

PR/47704: Takahiro HAYASHI: Add -L flag


# 1.146 07-Nov-2014 christos

Now that the code can support tags and verbose route printing, enable them.
Also document previously undocumented flags.


# 1.145 06-Nov-2014 christos

Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.144 19-Oct-2013 christos

branches: 1.144.4;
use correct function


# 1.143 19-Oct-2013 christos

use symbolic flags


# 1.142 19-Oct-2013 christos

use scopeid functions


# 1.141 18-Oct-2013 christos

avoid pointer gymnastics


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.140 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.139 04-Oct-2012 uwe

Fix fallout from 1.129 that converted sou::so_foo from unions to
pointers but missed (char *)&soup->so_foo => (char *)soup->so_foo in
mask_addr(). It worked by luck - unless it didn't: due to pointer
numerology on amd64 route add -net ClassC without explicit /24 prefix
length specification would result into /16 destination instead of /24.


# 1.138 08-Aug-2012 christos

branches: 1.138.2;
remove useless rump headers.


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.137 17-Mar-2012 christos

PR/42179: Christoph Badura: Be a little friendlier about missing args.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.136 26-Dec-2011 christos

branches: 1.136.2;
Off by one and clarity improvement from Christian Biere


# 1.135 24-Dec-2011 christos

PR/45661: Henning Petersen: Overlapping buffer in route.c.


# 1.134 11-Nov-2011 gdt

Move RTF_ANNOUNCE flag so that it no longer conflicts with RTF_PROTO2.

RTF_ANNOUNCE was defined as RTF_PROTO2. The flag is used to indicated
that host should act as a proxy for a link level arp or ndp request.
(If RTF_PROTO2 is used as an experimental flag (as advertised),
various problems can occur.)

This commit provides a first-class definition with its own bit for
RTF_ANNOUNCE, removes the old aliasing definitions, and adds support
for the new RTF_ANNOUNCE flag to netstat(8) and route(8).,

Also, remove unused RTF_ flags that collide with RTF_PROTO1:
netinet/icmp6.h defined RTF_PROBEMTU as RTF_PROTO1
netinet/if_inarp.h defined RTF_USETRAILERS as RTF_PROTO1
(Neither of these flags are used anywhere. Both have been removed
to reduce chances of collision with RTF_PROTO1.)

Figuring this out and the diff are the work of Beverly Schwartz of
BBN.

(Passed release build, boot in VM, with no apparently related atf
failures.)

Approved for Public Release, Distribution Unlimited
This material is based upon work supported by the Defense Advanced
Research Projects Agency and Space and Naval Warfare Systems Center,
Pacific, under Contract No. N66001-09-C-2073.


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.133 07-Oct-2011 joerg

branches: 1.133.2;
Simplify.


# 1.132 29-Aug-2011 joerg

Use __dead


# 1.131 01-Jul-2011 joerg

Fix memset usage.


# 1.130 22-Jun-2011 kefren

don't compile tag functions if SMALL is defined. Should fix the build


# 1.129 21-Jun-2011 kefren

Alloc dynamically sockunions in sou.
Teach route(8) about multiple tags. E.G.: -tag 100,20,33
XXX: needs documentation


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.128 01-Feb-2011 matt

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.


Revision tags: matt-mips64-premerge-20101231
# 1.127 13-Dec-2010 pooka

branches: 1.127.2;
Convert from RUMP_ACTION to RUMPPRG.


# 1.126 12-Nov-2010 roy

Support the new RTM_IFINFO and RTM_CHGADDR messages.


# 1.125 05-Nov-2010 pooka

adapt to new rumpclient_init() signature


# 1.124 04-Nov-2010 pooka

#ifdef variable correctly


# 1.123 04-Nov-2010 pooka

be consistent in what to leave outside of SMALL


# 1.122 04-Nov-2010 pooka

Support RUMP_ACTION to compile a rump kernel client.


# 1.121 26-Jun-2010 kefren

add MPLS clue - mpls and tag keywords


# 1.120 12-May-2010 christos

PR/40455: Mihai Chelaru: Add noreject noblackhole options


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base mjf-devfs2-base
# 1.119 28-Dec-2008 christos

parse unsigned long with strtoul not atoi


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3
# 1.118 10-Sep-2008 dyoung

branches: 1.118.6;
Get the socket addresses for dst/gateway/netmask/interface/ifaddr
out of the global namespace.


# 1.117 10-Sep-2008 dyoung

Don't cast a sockunion * to sockaddr *. Instead, reference the
sockaddr inside of the sockunion.


# 1.116 10-Sep-2008 dyoung

Delete superfluous casts to void *.


# 1.115 10-Sep-2008 dyoung

Constify.


# 1.114 10-Sep-2008 dyoung

Constify.


# 1.113 10-Sep-2008 dyoung

Constify.

For clarity's sake, do not assign a new value to inet_makenetandmask()'s
argument, `inet'.


# 1.112 09-Sep-2008 dyoung

Extract subroutine extract_addrs() for reuse, later.

Replace the anonymous constant, 0, with AF_UNSPEC.


# 1.111 09-Sep-2008 dyoung

Constify.


# 1.110 09-Sep-2008 dyoung

Shorten a staircase. Remove superfluous parentheses from return
statements. Constify.


# 1.109 09-Sep-2008 dyoung

Use a union and sizeof() to avoid a cast and an anonymous constant
buffer length, respectively.


# 1.108 09-Sep-2008 dyoung

Use bool.


Revision tags: wrstuden-revivesa-base-2
# 1.107 20-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking cube-autoconf-base mjf-devfs-base matt-armv6-base matt-mips64-base hpcarm-cleanup-base
# 1.106 18-Feb-2007 hubertf

branches: 1.106.12; 1.106.16;
TSEL() is const char* now


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base netbsd-4-base
# 1.105 11-Nov-2006 apb

Fix a bug that caused 0.0.0.0/0 to be treated like 0.0.0.0/32.

foo << 32 is undefined per section 6.5.7 of the C99 standard
if foo is (or is promoted to) a 32-bit type.


# 1.104 23-Sep-2006 dyoung

Let us qualify 'route flush' and 'route show' commands with -llinfo
and -host flags, which is useful for displaying/flushing ARP entries:

# route -n show -inet -llinfo -host
Routing table

Internet:
Destination Gateway Flags
169.254.1.119 link#1 UH
169.254.230.110 00:02:6f:21:e6:6e UH
# route -n flush -inet -llinfo -host
169.254.1.119 done
169.254.230.110 0.2.6f.21.e6.6e done
169.254.237.70 done
# route -n show -inet -llinfo -host
Routing table
#

This will help me address bin/11079, "dhclient may require arp and sed".

Extract common code from flushroutes() and show(), creating
parse_show_opts().

While I'm here, make small cosmetic changes to flushroutes().


# 1.103 23-Sep-2006 dyoung

Move the #ifndef SMALL code together.


# 1.102 23-Sep-2006 dyoung

Use the symbol AF_UNSPEC instead of 0 as appropriate.


# 1.101 23-Sep-2006 dyoung

Remove dead code.


# 1.100 26-Aug-2006 matt

Remove XNS and CCITT/X25 bits.


Revision tags: abandoned-netbsd-4-base
# 1.99 06-Aug-2006 dyoung

KNF err(3), errx(3) usage, indentation, braces.


# 1.98 06-Aug-2006 dyoung

Add route keywords -nocloned, -nocloning.


# 1.97 29-Jan-2006 wiz

Use default option order (AaBbCc...).


# 1.96 26-Jan-2006 is

Print the INET netmask if it is non-contiguous.


# 1.95 25-Jan-2006 christos

PR/32632: Yves-Emmanuel JUTARD: Improvment suggestion in 'route' display.
Add a new -S flag that prints a space for missing flags.


# 1.94 25-Jan-2006 christos

PR/32629: Yves-Emmanuel JUTARD: Type errors in sbin/route/route.c, another
u_char/char conflict.


# 1.93 31-Aug-2005 ginsbach

Add full IPv6 syntax support when route is built with -DSMALL and -DINET6.
Fixes PR/23937. Adapted from supplied patch.


# 1.92 30-Aug-2005 ginsbach

Clean up some minor nits:
+ style (KNF).
. don't cast NULL
. white space clean up
+ use consistent format for error messages.
+ plug memory leaks and avoid malloc(0).
+ verbose message should display even when routing table is empty
(flushroutes).


# 1.91 15-Aug-2005 ginsbach

Make sure that a netmask socket address value prints appropriately when the
family is unset. Either the destination or interface address socket address
family value is used. This change prevents the following sort of output:

RTM_NEWADDR: address being added to iface: len 60, metric 0, flags:<UP>
sockaddrs: <NETMASK,IFA,BRD>
(0) 00.00.ff.00.00 127.0.0.1 127.0.0.1

With this change the last line becomes:

255.0.0.0 127.0.0.1 127.0.0.1

Also make sure that when using a generated inet netmask the address family
is set. With this change a generated netmask will print appropriately
when using the verbose (-v) option.


# 1.90 12-Aug-2005 ginsbach

Make sure the get command always exits non-zero on error. This makes things
like the following work as expected.

#!/bin/sh

if ! route -sn get default >/dev/null 2>&1; then
echo default gateway not set
exit 1
fi
echo default gateway set

Handle routing socket write(2) errors when they occur. This produces
better diagnostics by allowing for handling of the special route errno
values ESRCH, EBUSY, and ENOBUFS even with the quiet (-q) option or
when doing a get command.


# 1.89 12-Aug-2005 ginsbach

Trim the local domain name in routename() for INET6 lookups; similar to
INET lookups.


# 1.88 10-Aug-2005 he

Make this build for __GNUC__ <= 2 (i.e. for vax). The cast to
caddr_t removes a const qualifier. Instead, cast the first element
of the subtraction to "struct sockaddr *" to work around the problem.


# 1.87 09-Aug-2005 ginsbach

Accept protocol flags, i.e. -inet, -inet6, with the show command.
[From OpenBSD via DragonFly BSD]


# 1.86 09-Aug-2005 ginsbach

Fix the default case in sodump(). Printing the address of the "which"
string isn't really that useful. Instead print the string and the value
of sa_family.


# 1.85 09-Aug-2005 ginsbach

More style nits (KNF); casts and sizeof's are not followed by a space.


# 1.84 20-Jul-2005 ginsbach

switch is not a function, so add a space; sort switch elements
alphabetically (KNF).


# 1.83 15-Jul-2005 ginsbach

* Exit non-zero error code when flushroute() fails operating on the
routing socket, e.g. running route flush as non-root.

* When quiet (-q) don't append error string to a non-existent
diagnostic output (stdout). The error diagnostic is still written
to stderr. [from FreeBSD]

* Use warn(3) in place of perror(3).


# 1.82 26-Jun-2005 christos

const poisoning.


# 1.81 25-Jun-2005 dyoung

Teach route(8) to print the messages generated by net80211.


# 1.80 19-May-2005 ginsbach

Convert prefixlen() to ANSI function declaration. Missed by earlier
conversion.


# 1.79 19-May-2005 ginsbach

Due to a limitation in inet_addr(3) it was not possible to specify a
netmask value of 0xffffffff (INADDR_NONE). Fix by using inet_aton(3).
Note it was possible to specify the same mask as the dotted quad
255.255.255.255 because of a later call to gethostbyname(3).
[From FreeBSD]


# 1.78 13-May-2005 ginsbach

Fix botched prior commit. Additional debugging error messages mistakenly
committed.


# 1.77 12-May-2005 ginsbach

* Honor -net when using CIDR (net/mask) notation. This differs
from the default CIDR (host/mask) interpretation. As discussed on
tech-net.

* Use errx() in place of fprintf() and exit(). Make the error message
formats consistent.


# 1.76 10-May-2005 ginsbach

Fix macro NEXTADDR so that the names, like so_dst, are printed
rather than u. The preprocessor doesn't do replacement within
strings, so the # string creation operator must be used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.75 05-Feb-2005 xtraeme

Kill __P(), use ANSI function declarations.


# 1.74 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


# 1.73 15-May-2004 itojun

bump buffer size for any_ntoa(), for huge sa_len


# 1.72 15-May-2004 itojun

2-byte read overrun for unknown sockaddr. from openbsd
XXX out[64], is it safe? what if sa_len > 23?


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.71 05-Jan-2004 jmmv

Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.


# 1.70 01-Oct-2003 itojun

print prefixlen on -show


# 1.69 16-Sep-2003 cube

Remove a comment that referred to a non-committed part of the patch I
submitted for bin/17613. Ok'd by mrg@.


# 1.68 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.


# 1.67 19-Jul-2003 jrf

This is an updated submitted patch originally written by Jim Rees
and sent in by Greg Hudson as seen in PR misc/3227. Basically what it
does is adds a flushall option which deletes all but localhost routes.
This is done by andoring in a flag called doall (1 means do all routes
including gateway, 0 means do a regular flush). I have seen some
platforms that do this. I tested it out on ipv4 only, it works as
advertised. Commit was approved by christos@.


# 1.66 11-Jun-2003 christos

PR/21856: Robert Elz: Changes to route(8) to allow /n instead of -prefixlen
for INET6


# 1.65 03-Jun-2003 itojun

permit foo/bar notation, like "route add 10.0.0.0/8 127.0.0.1".
originally by provos


# 1.64 17-May-2003 itojun

strlcpy [a few mistakes found]


# 1.63 21-Apr-2003 jrf

This addresses PR 17613 when certain methods of adding routes would
muck up the routing tables. The patch was submitted by Quentin Garnier
<netbsd@quatriemek.com> and tweaked a little after it was reviewed
by Christos Zoulas <christos@netbsd.org>. Final change/commit approved
by Christos.


# 1.62 03-Apr-2003 jrf

Made a note in the code about the -d and -d options brought up in
PR 18674. Thanks to Chris Jones for pointing it out.


Revision tags: fvdl_fs64_base
# 1.61 18-Oct-2002 itojun

correct prefixlen handling for IPv4.


# 1.60 18-Oct-2002 itojun

Make prefixlen check to make sure its argument is present before deref
from openbsd


# 1.59 20-Jul-2002 grant

sweep of errx/warnx, remove unnecessary trailing \n


# 1.58 10-Jun-2002 itojun

permit DNS names to address portion. they will be considered as RTF_HOST
if specified as destination (as there's no getnetbyname in IPv6).


# 1.57 05-Jun-2002 itojun

if we're unsure about prefixlen, don't say "128".


# 1.56 05-Jun-2002 itojun

more correct ion to RTF_HOST handling.


# 1.55 04-Jun-2002 itojun

do not have -prefixlen 128 on RTF_HOST.
From: Dawid Szymanski <dawszy@arhea.net>


Revision tags: netbsd-1-6-base
# 1.54 20-May-2002 itojun

branches: 1.54.2;
raise RTF_HOST if destination is a host (/128). from ume


# 1.53 21-Feb-2002 christos

PR/15672: Love: route monitor missing info


# 1.52 15-Nov-2001 christos

Make route exit with a non-zero error code when operations to the routing
socket fails. eg, running route add 1.2.3.4 5.6.7.8 as non root.


# 1.51 02-Nov-2001 lukem

fix -Wshadow warnings


# 1.50 24-Oct-2001 atatat

Provide a short output format for the get command that only prints the
address corresponding to RTA_GATEWAY, or nothing if it doesn't exist.
Modify the exit value of route depending on this, so that one can do
stuff like:

#!/bin/sh
gw=`route -sn get default 2>/dev/null`
if [ -z "$gw" ]; then
echo no default route
exit 1
fi
ping -w1 -c1 $gw >/dev/null 2>&1
if ! route -sn get $gw >/dev/null; then
echo default gateway not responding
exit 1
fi
echo default gateway is at $gw


# 1.49 24-Oct-2001 atatat

Print a R on reject routes to indicate that they're not normal routes,
and check netmask (or prefix) length as well as the destination
address when determining if a route is a "default" or not. This means
that the output from 'route show' will no longer say:

Internet6:
Destination Gateway Flags
default localhost UG
default localhost UG

but instead

Internet6:
Destination Gateway Flags
::/104 localhost UGR
::/96 localhost UGR

which makes much more sense.


# 1.48 20-Jul-2001 itojun

off-by-one error in -prefixlen arg validation (do not permit 129 on IPv6)


# 1.47 20-Jul-2001 itojun

make prefixlen work on IPv4 too


# 1.46 16-Jul-2001 bad

The way pmsg_addrs() is used requires that it always prints a newline and
flushes stdout before returning.

Previously the decoded output for a message was stuck in stdio buffers until
the next arrived.


# 1.45 19-Feb-2001 cgd

convert to use getprogname()


# 1.44 04-Feb-2001 christos

remove nested externs.


# 1.43 27-Jan-2001 itojun

support -cloned command line flag.
i don't think anyone ever going to use it.


# 1.42 27-Jan-2001 itojun

mark cloned routes with RTF_CLONED. present it with netstat -r by "c".

let static routes overwrite cloned routes, as cloned routes can come back again
if necessary. behavior same as freebsd/bsdi, code partially from bsdi42.
(NRL rt->rt_parent was not added)
should fix PR 11916 and maybe some other PRs with ARP behavior.

recompilation of usr.sbin/route6d is suggested.


# 1.41 27-Jan-2001 itojun

support RTF_BLACKHOLE.

XXX route show is total duplicate of netstat -r, we need to either remove
route show, or share the same source code, otherwise maintenance cost
bites (and is biting) us


# 1.40 27-Jan-2001 itojun

remove use of uninitialized route (struct ortentry).
it seems that the bug was born during 4.3reno -> 4.4Lite1 transition.


# 1.39 10-Oct-2000 itojun

on "route monitor", print RTM_IFANNOUNCE, RTM_IFINFO (new #), and others.


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.38 04-May-2000 sommerfeld

branches: 1.38.4;
Allow INET6 to be used with SMALL without undefined symbols


# 1.37 20-Apr-2000 itojun

use scoped notation for link-local multicast too.


# 1.36 20-Apr-2000 itojun

support extended scoped address notation (fe80::1%de0).
it hides implementation detail (embedded ifid) from the users.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.35 03-Dec-1999 itojun

don't make "-prefixlen 64" a default in -inet6 case. the past behavior
was not compatible with past practice ("route get" did not work right).

sync with recent KAME.


Revision tags: comdex-fall-1999-base
# 1.34 01-Nov-1999 sommerfeld

Display local address associated with route (if any) in "route get".


# 1.33 03-Sep-1999 itojun

branches: 1.33.2;
fix alignment issue in routing socket data, on 64bit arch (i.e. alpha).
sockaddrs are packed with ROUNDUP() in sys/net/rtsock.c so userland
programs needs to follow that.

PR: 8179


# 1.32 06-Jul-1999 mjacob

Incorrect integration. ctime takes a time_t value, not a long.


# 1.31 02-Jul-1999 itojun

IPv6-ready route command (-inet6 and -prefixlen are added)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.30 23-Oct-1998 lukem

branches: 1.30.2;
* implement -f; flush all routes before executing command
* reset af to 0 in flushroutes() and newroute()
* cleanup -DSMALL:
- `flush' and AF_APPLETALK is supported (the latter had partial support)
- AF_NS, AF_ISO, and AF_CCITT are not supported at all (rather than being
- partially unsupported).


# 1.29 26-Jul-1998 mycroft

const poisoning.


# 1.28 01-Apr-1998 kleink

Need <time.h> for time() prototype.


# 1.27 05-Feb-1998 ross

64-bit sweep, "route -v show" was spinning forever.


# 1.26 16-Nov-1997 christos

Use {warn,err}{,x}(3) instead of printf's


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 01-Oct-1997 enami

Don't declare optind.


# 1.24 16-Sep-1997 lukem

resolve conflicts from lite-2 import


# 1.23 15-Sep-1997 lukem

* cleanup for WARNS=1
* use .Nm correctly
* deprecate register
* getopt returns -1 not EOF


# 1.22 02-Sep-1997 thorpej

Fix uninitialized pointer botch when attempting to flush an already
empty routing table. From Matthias Scheler <tron@lyssa.owl.de>, in
PR #4074.


# 1.21 27-Apr-1997 thorpej

Don't SEGV if a qualifier is passed without an argument. From
Geoff Wing <mason@primenet.com.au>, fixes PR #2700.


# 1.20 21-Apr-1997 mrg

KNF. be safe with buffers.


# 1.19 03-Apr-1997 christos

- Add netatalk bits
- Add prototypes
- Fix printf formats


# 1.18 22-Feb-1997 carrel

Remove uid checks since the kernel now handles this and route(1) is no
longer setuid.
Document the "Permission denied" msg in the man page since this is
_slightly_ less clear than route(1)'s old error msg.


# 1.17 15-Nov-1996 gwr

As discussed some time ago, add a "show" sub-command.
Also allow compilation with -DSMALL to ommit support for
non-essential protocols (i.e. when built into a ramdisk).
Use a less hack-ish way to generate keywords.[ch] and just
check in the result (helps ../../distrib/utils/x_route).


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.16 15-Apr-1996 cgd

check returns of inet_addr() and inet_network() against INADDR_NONE,
not -1, per the manual page. on 64-bit systems like the alpha, -1 will
never equal (unsigned long)INADDR_NONE.


# 1.15 07-Jan-1996 pk

Produce less output on -q as promised by the man page (John Hawkinson; PR#998).


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.14 20-Apr-1995 mycroft

Interface-specific routes can be static.


# 1.13 20-Apr-1995 mycroft

Implement the document `-llinfo' flag.


# 1.12 18-Apr-1995 mycroft

Remove extra `break;'.


# 1.11 18-Mar-1995 cgd

convert to new RCS Id conventions; reduce my headache


# 1.10 24-Dec-1994 cgd

kill some extraneous equal signs.


# 1.9 23-Sep-1994 mycroft

Remove some more uses of obsolete functions.


# 1.8 23-Sep-1994 mycroft

Eliminate uses of some obsolete functions.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.7 13-May-1994 mycroft

Clean up import.


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 25-Apr-1993 mycroft

Compile X.25, OSI, and NS code.


# 1.4 18-Apr-1993 mycroft

Cleanup for GCC 2.


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.3 23-Mar-1993 cgd

changed "Id" to "Header" for rcsids


# 1.2 22-Mar-1993 cgd

added rcs ids to all files


# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
Initial revision