/*
- * Copyright (c) 2008-2011 Apple Inc. All rights reserved.
+ * Copyright (c) 2008-2017 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
u_short u_data[128];
} sa_u;
-static void ntreestuff __P((void));
static void np_rtentry __P((struct rt_msghdr2 *));
static void p_sockaddr __P((struct sockaddr *, struct sockaddr *, int, int));
static void p_flags __P((int, char *));
static uint32_t forgemask __P((uint32_t));
static void domask __P((char *, uint32_t, uint32_t));
-/*
- * Print routing tables.
- */
-void
-routepr(uint32_t rtree)
-{
- printf("Routing tables\n");
-
- if (dflag == 0) {
- ntreestuff();
- } else {
- if (rtree == 0) {
- printf("rt_tables: symbol not in namelist\n");
- return;
- }
- }
- }
-
/*
* Print address family header before a section of the routing table.
*/
#ifndef INET6
#define WID_DST(af) 18 /* width of destination column */
#define WID_GW(af) 18 /* width of gateway column */
+#define WID_RT_IFA(af) 18 /* width of source column */
#define WID_IF(af) 7 /* width of netif column */
#else
#define WID_DST(af) \
((af) == AF_INET6 ? (lflag ? 39 : (nflag ? 39: 18)) : 18)
#define WID_GW(af) \
((af) == AF_INET6 ? (lflag ? 31 : (nflag ? 31 : 18)) : 18)
+#define WID_RT_IFA(af) \
+ ((af) == AF_INET6 ? (lflag ? 39 : (nflag ? 39 : 18)) : 18)
#define WID_IF(af) ((af) == AF_INET6 ? 8 : 7)
#endif /*INET6*/
void
pr_rthdr(int af)
{
-
- if (Aflag)
- printf("%-8.8s ","Address");
- if (af == AF_INET || lflag)
- if (lflag)
- printf("%-*.*s %-*.*s %-10.10s %6.6s %8.8s %6.6s %*.*s %6s\n",
+ if (lflag) {
+ if (lflag > 2)
+ printf("%-*.*s %-*.*s %-*.*s %-10.10s %6.6s %8.8s %6.6s %*.*s %6s "
+ "%10s %10s %8s %8s %8s\n",
WID_DST(af), WID_DST(af), "Destination",
WID_GW(af), WID_GW(af), "Gateway",
+ WID_RT_IFA(af), WID_RT_IFA(af), "RT_IFA",
"Flags", "Refs", "Use", "Mtu",
- WID_IF(af), WID_IF(af), "Netif", "Expire");
+ WID_IF(af), WID_IF(af), "Netif", "Expire",
+ "rtt(ms)", "rttvar(ms)", "recvpipe", "sendpipe", "ssthresh");
+ else if (lflag > 1)
+ printf("%-*.*s %-*.*s %-*.*s %-10.10s %6.6s %8.8s %6.6s %*.*s %6s "
+ "%10s %10s\n",
+ WID_DST(af), WID_DST(af), "Destination",
+ WID_GW(af), WID_GW(af), "Gateway",
+ WID_RT_IFA(af), WID_RT_IFA(af), "RT_IFA",
+ "Flags", "Refs", "Use", "Mtu",
+ WID_IF(af), WID_IF(af), "Netif", "Expire",
+ "rtt(ms)", "rttvar(ms)");
else
- printf("%-*.*s %-*.*s %-10.10s %6.6s %8.8s %*.*s %6s\n",
+ printf("%-*.*s %-*.*s %-*.*s %-10.10s %6.6s %8.8s %6.6s %*.*s %6s\n",
WID_DST(af), WID_DST(af), "Destination",
WID_GW(af), WID_GW(af), "Gateway",
- "Flags", "Refs", "Use",
+ WID_RT_IFA(af), WID_RT_IFA(af), "RT_IFA",
+ "Flags", "Refs", "Use", "Mtu",
WID_IF(af), WID_IF(af), "Netif", "Expire");
- else
- printf("%-*.*s %-*.*s %-10.10s %8.8s %6s\n",
+ } else {
+ printf("%-*.*s %-*.*s %-10.10s %*.*s %6s\n",
WID_DST(af), WID_DST(af), "Destination",
WID_GW(af), WID_GW(af), "Gateway",
- "Flags", "Netif", "Expire");
+ "Flags", WID_IF(af), WID_IF(af), "Netif", "Expire");
+ }
}
-static void
-ntreestuff(void)
+/*
+ * Print routing tables.
+ */
+void
+routepr(void)
{
size_t needed;
int mib[6];
char *buf, *next, *lim;
struct rt_msghdr2 *rtm;
+ printf("Routing tables\n");
+
mib[0] = CTL_NET;
mib[1] = PF_ROUTE;
mib[2] = 0;
return;
}
+ if (lflag > 1 && zflag != 0 && rtm->rtm_rmx.rmx_rtt == 0 && rtm->rtm_rmx.rmx_rttvar == 0)
+ return;
fam = sa->sa_family;
if (af != AF_UNSPEC && af != fam)
return;
p_sockaddr(rti_info[RTAX_GATEWAY], NULL, RTF_HOST,
WID_GW(addr.u_sa.sa_family));
+
+ if (lflag && (rtm->rtm_addrs & RTA_IFA)) {
+ p_sockaddr(rti_info[RTAX_IFA], NULL, RTF_HOST,
+ WID_RT_IFA(addr.u_sa.sa_family));
+ }
p_flags(rtm->rtm_flags, "%-10.10s ");
- if (addr.u_sa.sa_family == AF_INET || lflag) {
+ if (lflag) {
printf("%6u %8u ", rtm->rtm_refcnt, (unsigned int)rtm->rtm_use);
- if (lflag) {
- if (rtm->rtm_rmx.rmx_mtu != 0)
- printf("%6u ", rtm->rtm_rmx.rmx_mtu);
- else
- printf("%6s ", "");
- }
+ if (rtm->rtm_rmx.rmx_mtu != 0)
+ printf("%6u ", rtm->rtm_rmx.rmx_mtu);
+ else
+ printf("%6s ", "");
}
+
if (rtm->rtm_index != lastindex) {
if_indextoname(rtm->rtm_index, ifname);
lastindex = rtm->rtm_index;
if ((expire_time =
rtm->rtm_rmx.rmx_expire - time((time_t *)0)) > 0)
printf(" %6d", (int)expire_time);
+ else
+ printf(" %6s", "!");
+ } else {
+ printf(" %6s", "");
+ }
+ if (lflag > 1) {
+ if (rtm->rtm_rmx.rmx_rtt != 0)
+ printf(" %6u.%03u", rtm->rtm_rmx.rmx_rtt / 1000,
+ rtm->rtm_rmx.rmx_rtt % 1000);
+ else
+ printf(" %10s", "");
+ if (rtm->rtm_rmx.rmx_rttvar != 0)
+ printf(" %6u.%03u", rtm->rtm_rmx.rmx_rttvar / 1000,
+ rtm->rtm_rmx.rmx_rttvar % 1000);
+ else
+ printf(" %10s", "");
+ if (lflag > 2) {
+ if (rtm->rtm_rmx.rmx_recvpipe != 0)
+ printf(" %8u", rtm->rtm_rmx.rmx_recvpipe);
+ else
+ printf(" %8s", "");
+ if (rtm->rtm_rmx.rmx_sendpipe != 0)
+ printf(" %8u", rtm->rtm_rmx.rmx_sendpipe);
+ else
+ printf(" %8s", "");
+ if (rtm->rtm_rmx.rmx_ssthresh != 0)
+ printf(" %8u", rtm->rtm_rmx.rmx_ssthresh);
+ else
+ printf(" %8s", "");
+ }
}
putchar('\n');
}
}
}
if (cp) {
- strncpy(line, cp, sizeof(line) - 1);
- line[sizeof(line) - 1] = '\0';
+ strlcpy(line, cp, sizeof(line));
} else {
#define C(x) ((x) & 0xff)
in = ntohl(in);
}
}
if (cp)
- strncpy(line, cp, sizeof(line) - 1);
+ strlcpy(line, cp, sizeof(line));
else {
switch (dmask) {
case IN_CLASSA_NET:
p(rts_newgateway, "\t%u new gateway%s due to redirects\n");
p(rts_unreach, "\t%u destination%s found unreachable\n");
p(rts_wildcard, "\t%u use%s of a wildcard route\n");
+ p(rts_badrtgwroute, "\t%u lookup%s returned indirect "
+ "routes pointing to indirect gateway route\n");
#undef p
if (rttrash || sflag <= 1)