X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/de355530ae67247cbd0da700edb3a2a1dae884c2..c910b4d9d2451126ae3917b931cd4390c11e1d52:/bsd/net/route.h diff --git a/bsd/net/route.h b/bsd/net/route.h index cd5060001..cfc95a6aa 100644 --- a/bsd/net/route.h +++ b/bsd/net/route.h @@ -1,23 +1,29 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2008 Apple Inc. All rights reserved. * - * @APPLE_LICENSE_HEADER_START@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * - * The contents of this file constitute Original Code as defined in and - * are subject to the Apple Public Source License Version 1.1 (the - * "License"). You may not use this file except in compliance with the - * License. Please obtain a copy of the License at - * http://www.apple.com/publicsource and read it before using this file. + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. * - * This Original Code and all software distributed under the License are - * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License. + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. * - * @APPLE_LICENSE_HEADER_END@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ /* * Copyright (c) 1980, 1986, 1993 @@ -58,6 +64,8 @@ #ifndef _NET_ROUTE_H_ #define _NET_ROUTE_H_ #include +#include +#include /* * Kernel resident routing tables. @@ -71,46 +79,47 @@ * to a routing entry. These are often held by protocols * in their control blocks, e.g. inpcb. */ -#if !defined(KERNEL) || defined(__APPLE_API_PRIVATE) +#ifdef PRIVATE +struct rtentry; struct route { struct rtentry *ro_rt; struct sockaddr ro_dst; - u_long reserved[2]; /* for future use if needed */ + u_int32_t ro_flags; /* route flags (see below) */ + u_int32_t reserved; /* for future use if needed */ }; + +#define ROF_SRCIF_SELECTED 0x1 /* source interface was selected */ + #else struct route; -#endif +#endif /* PRIVATE */ /* * These numbers are used by reliable protocols for determining * retransmission behavior and are included in the routing structure. */ struct rt_metrics { - u_long rmx_locks; /* Kernel must leave these values alone */ - u_long rmx_mtu; /* MTU for this path */ - u_long rmx_hopcount; /* max hops expected */ - u_long rmx_expire; /* lifetime for route, e.g. redirect */ - u_long rmx_recvpipe; /* inbound delay-bandwidth product */ - u_long rmx_sendpipe; /* outbound delay-bandwidth product */ - u_long rmx_ssthresh; /* outbound gateway buffer limit */ - u_long rmx_rtt; /* estimated round trip time */ - u_long rmx_rttvar; /* estimated rtt variance */ - u_long rmx_pksent; /* packets sent using this route */ - u_long rmx_filler[4]; /* will be used for T/TCP later */ + u_int32_t rmx_locks; /* Kernel must leave these values alone */ + u_int32_t rmx_mtu; /* MTU for this path */ + u_int32_t rmx_hopcount; /* max hops expected */ + int32_t rmx_expire; /* lifetime for route, e.g. redirect */ + u_int32_t rmx_recvpipe; /* inbound delay-bandwidth product */ + u_int32_t rmx_sendpipe; /* outbound delay-bandwidth product */ + u_int32_t rmx_ssthresh; /* outbound gateway buffer limit */ + u_int32_t rmx_rtt; /* estimated round trip time */ + u_int32_t rmx_rttvar; /* estimated rtt variance */ + u_int32_t rmx_pksent; /* packets sent using this route */ + u_int32_t rmx_filler[4]; /* will be used for T/TCP later */ }; /* * rmx_rtt and rmx_rttvar are stored as microseconds; - * RTTTOPRHZ(rtt) converts to a value suitable for use - * by a protocol slowtimo counter. */ #define RTM_RTTUNIT 1000000 /* units for rtt, rttvar, as units per sec */ -#define RTTTOPRHZ(r) ((r) / (RTM_RTTUNIT / PR_SLOWHZ)) /* * XXX kernel function pointer `rt_output' is visible to applications. */ -struct mbuf; /* * We distinguish between routes to hosts and routes to networks, @@ -120,10 +129,10 @@ struct mbuf; * gateways are marked so that the output routines know to address the * gateway rather than the ultimate destination. */ +#ifdef PRIVATE #ifndef RNF_NORMAL #include #endif -#ifdef __APPLE_API_UNSTABLE struct rtentry { struct radix_node rt_nodes[2]; /* tree glue, and other values */ #define rt_key(r) ((struct sockaddr *)((r)->rt_nodes->rn_key)) @@ -138,14 +147,15 @@ struct rtentry { caddr_t rt_llinfo; /* pointer to link level info cache */ struct rt_metrics rt_rmx; /* metrics used by rx'ing protocols */ struct rtentry *rt_gwroute; /* implied entry for gatewayed routes */ - int (*rt_output) __P((struct ifnet *, struct mbuf *, - struct sockaddr *, struct rtentry *)); + int (*rt_output)(struct ifnet *, struct mbuf *, + struct sockaddr *, struct rtentry *); /* output routine for this (rt,if) */ - struct rtentry *rt_parent; /* cloning parent of this route */ - void *rt_filler2; /* more filler */ + struct rtentry *rt_parent; /* cloning parent of this route */ + u_long generation_id; /* route generation id */ }; -#endif /* __APPLE_API_UNSTABLE */ +#endif /* PRIVATE */ +#ifdef __APPLE_API_OBSOLETE /* * Following structure necessary for 4.3 compatibility; * We should eventually move it to a compat file. @@ -159,8 +169,11 @@ struct ortentry { u_long rt_use; /* raw # packets forwarded */ struct ifnet *rt_ifp; /* the answer: interface to use */ }; +#endif /* __APPLE_API_OBSOLETE */ +#ifdef PRIVATE #define rt_use rt_rmx.rmx_pksent +#endif /* PRIVATE */ #define RTF_UP 0x1 /* route usable */ #define RTF_GATEWAY 0x2 /* destination is a gateway */ @@ -181,12 +194,13 @@ struct ortentry { #define RTF_PRCLONING 0x10000 /* protocol requires cloning */ #define RTF_WASCLONED 0x20000 /* route generated through cloning */ #define RTF_PROTO3 0x40000 /* protocol specific routing flag */ -/* 0x80000 unused */ + /* 0x80000 unused */ #define RTF_PINNED 0x100000 /* future use */ -#define RTF_LOCAL 0x200000 /* route represents a local address */ +#define RTF_LOCAL 0x200000 /* route represents a local address */ #define RTF_BROADCAST 0x400000 /* route represents a bcast address */ #define RTF_MULTICAST 0x800000 /* route represents a mcast address */ - /* 0x1000000 and up unassigned */ +#define RTF_IFSCOPE 0x1000000 /* has valid interface scope */ + /* 0x2000000 and up unassigned */ /* * Routing statistics. @@ -198,24 +212,41 @@ struct rtstat { short rts_unreach; /* lookups which failed */ short rts_wildcard; /* lookups satisfied by a wildcard */ }; + /* * Structures for routing messages. */ struct rt_msghdr { - u_short rtm_msglen; /* to skip over non-understood messages */ - u_char rtm_version; /* future binary compatibility */ - u_char rtm_type; /* message type */ - u_short rtm_index; /* index for associated ifp */ - int rtm_flags; /* flags, incl. kern & message, e.g. DONE */ - int rtm_addrs; /* bitmask identifying sockaddrs in msg */ - pid_t rtm_pid; /* identify sender */ - int rtm_seq; /* for sender to identify action */ - int rtm_errno; /* why failed */ - int rtm_use; /* from rtentry */ - u_long rtm_inits; /* which metrics we are initializing */ - struct rt_metrics rtm_rmx; /* metrics themselves */ + u_short rtm_msglen; /* to skip over non-understood messages */ + u_char rtm_version; /* future binary compatibility */ + u_char rtm_type; /* message type */ + u_short rtm_index; /* index for associated ifp */ + int rtm_flags; /* flags, incl. kern & message, e.g. DONE */ + int rtm_addrs; /* bitmask identifying sockaddrs in msg */ + pid_t rtm_pid; /* identify sender */ + int rtm_seq; /* for sender to identify action */ + int rtm_errno; /* why failed */ + int rtm_use; /* from rtentry */ + u_int32_t rtm_inits; /* which metrics we are initializing */ + struct rt_metrics rtm_rmx; /* metrics themselves */ +}; + +struct rt_msghdr2 { + u_short rtm_msglen; /* to skip over non-understood messages */ + u_char rtm_version; /* future binary compatibility */ + u_char rtm_type; /* message type */ + u_short rtm_index; /* index for associated ifp */ + int rtm_flags; /* flags, incl. kern & message, e.g. DONE */ + int rtm_addrs; /* bitmask identifying sockaddrs in msg */ + int32_t rtm_refcnt; /* reference count */ + int rtm_parentflags; /* flags of the parent route */ + int rtm_reserved; /* reserved field set to 0 */ + int rtm_use; /* from rtentry */ + u_int32_t rtm_inits; /* which metrics we are initializing */ + struct rt_metrics rtm_rmx; /* metrics themselves */ }; + #define RTM_VERSION 5 /* Up the ante and ignore older versions */ /* @@ -237,6 +268,12 @@ struct rt_msghdr { #define RTM_IFINFO 0xe /* iface going up/down etc. */ #define RTM_NEWMADDR 0xf /* mcast group membership being added to if */ #define RTM_DELMADDR 0x10 /* mcast group membership being deleted */ +#ifdef PRIVATE +#define RTM_GET_SILENT 0x11 +#endif PRIVATE +#define RTM_IFINFO2 0x12 /* */ +#define RTM_NEWMADDR2 0x13 /* */ +#define RTM_GET2 0x14 /* */ /* * Bitmask values for rtm_inits and rmx_locks. @@ -289,53 +326,64 @@ struct route_cb { int any_count; }; -#ifdef KERNEL -#ifndef __APPLE__ -#define RTFREE(rt) \ - do { \ - if ((rt)->rt_refcnt <= 1) \ - rtfree(rt); \ - else \ - (rt)->rt_refcnt--; \ - } while (0) -#else -#define RTFREE(rt) rtfree(rt) -#endif +#ifdef KERNEL_PRIVATE +/* + * For scoped routing; a zero interface scope value means nil/no scope. + */ +#define IFSCOPE_NONE 0 -#ifdef __APPLE_API_PRIVATE +#define RTFREE(rt) rtfree(rt) extern struct route_cb route_cb; extern struct radix_node_head *rt_tables[AF_MAX+1]; struct ifmultiaddr; struct proc; -void route_init __P((void)); -void rt_ifmsg __P((struct ifnet *)); -void rt_missmsg __P((int, struct rt_addrinfo *, int, int)); -void rt_newaddrmsg __P((int, struct ifaddr *, int, struct rtentry *)); -void rt_newmaddrmsg __P((int, struct ifmultiaddr *)); -int rt_setgate __P((struct rtentry *, - struct sockaddr *, struct sockaddr *)); -void rtalloc __P((struct route *)); -void rtalloc_ign __P((struct route *, u_long)); -struct rtentry * - rtalloc1 __P((struct sockaddr *, int, u_long)); -void rtfree __P((struct rtentry *)); -void rtref __P((struct rtentry *)); +__private_extern__ int rttrash; + +extern void route_init(void) __attribute__((section("__TEXT, initcode"))); +extern void rt_ifmsg(struct ifnet *); +extern void rt_missmsg(int, struct rt_addrinfo *, int, int); +extern void rt_newaddrmsg(int, struct ifaddr *, int, struct rtentry *); +extern void rt_newmaddrmsg(int, struct ifmultiaddr *); +extern int rt_setgate(struct rtentry *, struct sockaddr *, struct sockaddr *); +extern void set_primary_ifscope(unsigned int); +extern unsigned int get_primary_ifscope(void); +extern boolean_t rt_inet_default(struct rtentry *, struct sockaddr *); +extern struct rtentry *rt_lookup(boolean_t, struct sockaddr *, + struct sockaddr *, struct radix_node_head *, unsigned int); +extern void rtalloc(struct route *); +extern void rtalloc_ign(struct route *, u_long); +extern void rtalloc_ign_locked(struct route *, u_long); +extern void rtalloc_scoped_ign_locked(struct route *, u_long, unsigned int); +extern struct rtentry *rtalloc1(struct sockaddr *, int, u_long); +extern struct rtentry *rtalloc1_locked(struct sockaddr *, int, u_long); +extern struct rtentry *rtalloc1_scoped_locked(struct sockaddr *, int, + u_long, unsigned int); +extern void rtfree(struct rtentry *); +extern void rtfree_locked(struct rtentry *); +extern void rtref(struct rtentry *); /* * rtunref will decrement the refcount, rtfree will decrement and free if * the refcount has reached zero and the route is not up. * Unless you have good reason to do otherwise, use rtfree. */ -void rtunref __P((struct rtentry *)); -void rtsetifa __P((struct rtentry *, struct ifaddr *)); -int rtinit __P((struct ifaddr *, int, int)); -int rtioctl __P((int, caddr_t, struct proc *)); -void rtredirect __P((struct sockaddr *, struct sockaddr *, - struct sockaddr *, int, struct sockaddr *, struct rtentry **)); -int rtrequest __P((int, struct sockaddr *, - struct sockaddr *, struct sockaddr *, int, struct rtentry **)); -#endif /* __APPLE_API_PRIVATE */ -#endif +extern void rtunref(struct rtentry *); +extern void rtsetifa(struct rtentry *, struct ifaddr *); +extern int rtinit(struct ifaddr *, int, int); +extern int rtinit_locked(struct ifaddr *, int, int); +extern int rtioctl(int, caddr_t, struct proc *); +extern void rtredirect(struct ifnet *, struct sockaddr *, struct sockaddr *, + struct sockaddr *, int, struct sockaddr *, struct rtentry **); +extern int rtrequest(int, struct sockaddr *, + struct sockaddr *, struct sockaddr *, int, struct rtentry **); +extern int rtrequest_locked(int, struct sockaddr *, + struct sockaddr *, struct sockaddr *, int, struct rtentry **); +extern int rtrequest_scoped_locked(int, struct sockaddr *, struct sockaddr *, + struct sockaddr *, int, struct rtentry **, unsigned int); +extern struct rtentry *rte_alloc(void); +extern void rte_free(struct rtentry *); +extern unsigned int sa_get_ifscope(struct sockaddr *); +#endif KERNEL_PRIVATE #endif