-static struct mbuf *
- rt_msg1(int, struct rt_addrinfo *);
-static int rt_msg2(int, struct rt_addrinfo *, caddr_t, struct walkarg *);
-static int rt_xaddrs(caddr_t, caddr_t, struct rt_addrinfo *);
-static int sysctl_dumpentry(struct radix_node *rn, void *vw);
-static int sysctl_iflist(int af, struct walkarg *w);
-static int sysctl_iflist2(int af, struct walkarg *w);
-static int route_output(struct mbuf *, struct socket *);
-static void rt_setmetrics(u_long, struct rt_metrics *, struct rt_metrics *);
-static void rt_setif(struct rtentry *, struct sockaddr *, struct sockaddr *,
- struct sockaddr *, unsigned int);
-
-#define SIN(sa) ((struct sockaddr_in *)(size_t)(sa))
-
-/* Sleazy use of local variables throughout file, warning!!!! */
-#define dst info.rti_info[RTAX_DST]
-#define gate info.rti_info[RTAX_GATEWAY]
-#define netmask info.rti_info[RTAX_NETMASK]
-#define genmask info.rti_info[RTAX_GENMASK]
-#define ifpaddr info.rti_info[RTAX_IFP]
-#define ifaaddr info.rti_info[RTAX_IFA]
-#define brdaddr info.rti_info[RTAX_BRD]
+static void route_dinit(struct domain *);
+static int rts_abort(struct socket *);
+static int rts_attach(struct socket *, int, struct proc *);
+static int rts_bind(struct socket *, struct sockaddr *, struct proc *);
+static int rts_connect(struct socket *, struct sockaddr *, struct proc *);
+static int rts_detach(struct socket *);
+static int rts_disconnect(struct socket *);
+static int rts_peeraddr(struct socket *, struct sockaddr **);
+static int rts_send(struct socket *, int, struct mbuf *, struct sockaddr *,
+ struct mbuf *, struct proc *);
+static int rts_shutdown(struct socket *);
+static int rts_sockaddr(struct socket *, struct sockaddr **);
+
+static int route_output(struct mbuf *, struct socket *);
+static int rt_setmetrics(u_int32_t, struct rt_metrics *, struct rtentry *);
+static void rt_getmetrics(struct rtentry *, struct rt_metrics *);
+static void rt_setif(struct rtentry *, struct sockaddr *, struct sockaddr *,
+ struct sockaddr *, unsigned int);
+static int rt_xaddrs(caddr_t, caddr_t, struct rt_addrinfo *);
+static struct mbuf *rt_msg1(int, struct rt_addrinfo *);
+static int rt_msg2(int, struct rt_addrinfo *, caddr_t, struct walkarg *,
+ kauth_cred_t *);
+static int sysctl_dumpentry(struct radix_node *rn, void *vw);
+static int sysctl_dumpentry_ext(struct radix_node *rn, void *vw);
+static int sysctl_iflist(int af, struct walkarg *w);
+static int sysctl_iflist2(int af, struct walkarg *w);
+static int sysctl_rtstat(struct sysctl_req *);
+static int sysctl_rttrash(struct sysctl_req *);
+static int sysctl_rtsock SYSCTL_HANDLER_ARGS;
+
+SYSCTL_NODE(_net, PF_ROUTE, routetable, CTLFLAG_RD | CTLFLAG_LOCKED,
+ sysctl_rtsock, "");
+
+SYSCTL_NODE(_net, OID_AUTO, route, CTLFLAG_RW | CTLFLAG_LOCKED, 0, "routing");
+
+/* Align x to 1024 (only power of 2) assuming x is positive */
+#define ALIGN_BYTES(x) do { \
+ x = P2ALIGN(x, 1024); \
+} while(0)
+
+#define ROUNDUP32(a) \
+ ((a) > 0 ? (1 + (((a) - 1) | (sizeof (uint32_t) - 1))) : \
+ sizeof (uint32_t))
+
+#define ADVANCE32(x, n) \
+ (x += ROUNDUP32((n)->sa_len))
+
+#define RT_HAS_IFADDR(rt) \
+ ((rt)->rt_ifa != NULL && (rt)->rt_ifa->ifa_addr != NULL)