epoc32/include/stdapis/net/route.h
branchSymbian2
changeset 2 2fe1408b6811
child 4 837f303aceeb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/net/route.h	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,345 @@
     1.4 +/*-
     1.5 + * © Portions copyright (c) 2007 Symbian Software Ltd. All rights reserved.
     1.6 + * Copyright (c) 1980, 1986, 1993
     1.7 + *	The Regents of the University of California.  All rights reserved.
     1.8 + * Redistribution and use in source and binary forms, with or without
     1.9 + * modification, are permitted provided that the following conditions
    1.10 + * are met:
    1.11 + * 1. Redistributions of source code must retain the above copyright
    1.12 + *    notice, this list of conditions and the following disclaimer.
    1.13 + * 2. Redistributions in binary form must reproduce the above copyright
    1.14 + *    notice, this list of conditions and the following disclaimer in the
    1.15 + *    documentation and/or other materials provided with the distribution.
    1.16 + * 4. Neither the name of the University nor the names of its contributors
    1.17 + *    may be used to endorse or promote products derived from this software
    1.18 + *    without specific prior written permission.
    1.19 + *
    1.20 + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    1.21 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.22 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.23 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    1.24 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    1.25 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    1.26 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    1.27 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    1.28 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    1.29 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    1.30 + * SUCH DAMAGE.
    1.31 + *
    1.32 + *	@(#)route.h	8.4 (Berkeley) 1/9/95
    1.33 + * $FreeBSD: src/sys/net/route.h,v 1.63 2005/01/07 01:45:35 imp Exp $
    1.34 + */
    1.35 +
    1.36 +#ifndef _NET_ROUTE_H_
    1.37 +#define _NET_ROUTE_H_
    1.38 +
    1.39 +#ifndef __SYMBIAN32__
    1.40 +/*
    1.41 + * Kernel resident routing tables.
    1.42 + *
    1.43 + * The routing tables are initialized when interface addresses
    1.44 + * are set by making entries for all directly connected interfaces.
    1.45 + */
    1.46 +
    1.47 +/*
    1.48 + * A route consists of a destination address and a reference
    1.49 + * to a routing entry.  These are often held by protocols
    1.50 + * in their control blocks, e.g. inpcb.
    1.51 + */
    1.52 +struct route {
    1.53 +	struct	rtentry *ro_rt;
    1.54 +	struct	sockaddr ro_dst;
    1.55 +};
    1.56 +#endif //__SYMBIAN32__
    1.57 +/*
    1.58 + * These numbers are used by reliable protocols for determining
    1.59 + * retransmission behavior and are included in the routing structure.
    1.60 + */
    1.61 +struct rt_metrics_lite {
    1.62 +	u_long	rmx_mtu;	/* MTU for this path */
    1.63 +	u_long	rmx_expire;	/* lifetime for route, e.g. redirect */
    1.64 +	u_long	rmx_pksent;	/* packets sent using this route */
    1.65 +};
    1.66 +
    1.67 +struct rt_metrics {
    1.68 +	u_long	rmx_locks;	/* Kernel must leave these values alone */
    1.69 +	u_long	rmx_mtu;	/* MTU for this path */
    1.70 +	u_long	rmx_hopcount;	/* max hops expected */
    1.71 +	u_long	rmx_expire;	/* lifetime for route, e.g. redirect */
    1.72 +	u_long	rmx_recvpipe;	/* inbound delay-bandwidth product */
    1.73 +	u_long	rmx_sendpipe;	/* outbound delay-bandwidth product */
    1.74 +	u_long	rmx_ssthresh;	/* outbound gateway buffer limit */
    1.75 +	u_long	rmx_rtt;	/* estimated round trip time */
    1.76 +	u_long	rmx_rttvar;	/* estimated rtt variance */
    1.77 +	u_long	rmx_pksent;	/* packets sent using this route */
    1.78 +	u_long	rmx_filler[4];	/* will be used for T/TCP later */
    1.79 +};
    1.80 +
    1.81 +/*
    1.82 + * rmx_rtt and rmx_rttvar are stored as microseconds;
    1.83 + * RTTTOPRHZ(rtt) converts to a value suitable for use
    1.84 + * by a protocol slowtimo counter.
    1.85 + */
    1.86 +#define	RTM_RTTUNIT	1000000	/* units for rtt, rttvar, as units per sec */
    1.87 +#define	RTTTOPRHZ(r)	((r) / (RTM_RTTUNIT / PR_SLOWHZ))
    1.88 +
    1.89 +/*
    1.90 + * XXX kernel function pointer `rt_output' is visible to applications.
    1.91 + */
    1.92 +struct mbuf;
    1.93 +
    1.94 +/*
    1.95 + * We distinguish between routes to hosts and routes to networks,
    1.96 + * preferring the former if available.  For each route we infer
    1.97 + * the interface to use from the gateway address supplied when
    1.98 + * the route was entered.  Routes that forward packets through
    1.99 + * gateways are marked so that the output routines know to address the
   1.100 + * gateway rather than the ultimate destination.
   1.101 + */
   1.102 +#ifndef RNF_NORMAL
   1.103 +#include <net/radix.h>
   1.104 +#endif
   1.105 +struct rtentry {
   1.106 +	struct	radix_node rt_nodes[2];	/* tree glue, and other values */
   1.107 +	/*
   1.108 +	 * XXX struct rtentry must begin with a struct radix_node (or two!)
   1.109 +	 * because the code does some casts of a 'struct radix_node *'
   1.110 +	 * to a 'struct rtentry *'
   1.111 +	 */
   1.112 +#define	rt_key(r)	(*((struct sockaddr **)(&(r)->rt_nodes->rn_key)))
   1.113 +#define	rt_mask(r)	(*((struct sockaddr **)(&(r)->rt_nodes->rn_mask)))
   1.114 +#ifndef __SYMBIAN32__	 
   1.115 +	struct	sockaddr *rt_gateway;	/* value */
   1.116 +#endif //__SYMBIAN32__	 
   1.117 +	u_long	rt_flags;		/* up/down?, host/net */
   1.118 +	struct	ifnet *rt_ifp;		/* the answer: interface to use */
   1.119 +	struct	ifaddr *rt_ifa;		/* the answer: interface address to use */
   1.120 +	struct	rt_metrics_lite rt_rmx;	/* metrics used by rx'ing protocols */
   1.121 +	long	rt_refcnt;		/* # held references */
   1.122 +#ifndef __SYMBIAN32__
   1.123 +	struct	sockaddr *rt_genmask;	/* for generation of cloned routes */
   1.124 +#endif	
   1.125 +	caddr_t	rt_llinfo;		/* pointer to link level info cache */
   1.126 +	struct	rtentry *rt_gwroute;	/* implied entry for gatewayed routes */
   1.127 +	struct	rtentry *rt_parent; 	/* cloning parent of this route */
   1.128 +#ifdef _KERNEL
   1.129 +	/* XXX ugly, user apps use this definition but don't have a mtx def */
   1.130 +	struct	mtx rt_mtx;		/* mutex for routing entry */
   1.131 +#endif
   1.132 +
   1.133 +/*to be compatible with linux */
   1.134 +#ifdef __SYMBIAN32__
   1.135 +    struct sockaddr rt_gateway;     /* Gateway addr (RTF_GATEWAY).  */
   1.136 +    char *rt_dev;           /* Forcing the device at add.  */		    
   1.137 +	struct sockaddr rt_genmask;     /* Target network mask (IP).  */    
   1.138 +	short int rt_metric;        /* +1 for binary compatibility!  */    
   1.139 +    struct sockaddr rt_dst;     /* Target address.  */
   1.140 +#endif //__SYMBIAN32__  
   1.141 +};
   1.142 +
   1.143 +#define	RTF_UP		0x1		/* route usable */
   1.144 +#define	RTF_GATEWAY	0x2		/* destination is a gateway */
   1.145 +#define	RTF_HOST	0x4		/* host entry (net otherwise) */
   1.146 +#define	RTF_DYNAMIC	0x10		/* created dynamically (by redirect) */
   1.147 +#define RTF_STATIC	0x800		/* manually added */
   1.148 +
   1.149 +#ifndef __SYMBIAN32__
   1.150 +/*
   1.151 + * Following structure necessary for 4.3 compatibility;
   1.152 + * We should eventually move it to a compat file.
   1.153 + */
   1.154 +struct ortentry {
   1.155 +	u_long	rt_hash;		/* to speed lookups */
   1.156 +	struct	sockaddr rt_dst;	/* key */
   1.157 +	struct	sockaddr rt_gateway;	/* value */
   1.158 +	short	rt_flags;		/* up/down?, host/net */
   1.159 +	short	rt_refcnt;		/* # held references */
   1.160 +	u_long	rt_use;			/* raw # packets forwarded */
   1.161 +	struct	ifnet *rt_ifp;		/* the answer: interface to use */
   1.162 +};
   1.163 +
   1.164 +#define rt_use rt_rmx.rmx_pksent
   1.165 +
   1.166 +#define	RTF_UP		0x1		/* route usable */
   1.167 +#define	RTF_GATEWAY	0x2		/* destination is a gateway */
   1.168 +#define	RTF_HOST	0x4		/* host entry (net otherwise) */
   1.169 +#define	RTF_REJECT	0x8		/* host or net unreachable */
   1.170 +#define	RTF_DYNAMIC	0x10		/* created dynamically (by redirect) */
   1.171 +#define	RTF_MODIFIED	0x20		/* modified dynamically (by redirect) */
   1.172 +#define RTF_DONE	0x40		/* message confirmed */
   1.173 +/*			0x80		   unused, was RTF_DELCLONE */
   1.174 +#define RTF_CLONING	0x100		/* generate new routes on use */
   1.175 +#define RTF_XRESOLVE	0x200		/* external daemon resolves name */
   1.176 +#define RTF_LLINFO	0x400		/* generated by link layer (e.g. ARP) */
   1.177 +#define RTF_STATIC	0x800		/* manually added */
   1.178 +#define RTF_BLACKHOLE	0x1000		/* just discard pkts (during updates) */
   1.179 +#define RTF_PROTO2	0x4000		/* protocol specific routing flag */
   1.180 +#define RTF_PROTO1	0x8000		/* protocol specific routing flag */
   1.181 +
   1.182 +/* XXX: temporary to stay API/ABI compatible with userland */
   1.183 +#ifndef _KERNEL
   1.184 +#define RTF_PRCLONING	0x10000		/* unused, for compatibility */
   1.185 +#endif
   1.186 +
   1.187 +#define RTF_WASCLONED	0x20000		/* route generated through cloning */
   1.188 +#define RTF_PROTO3	0x40000		/* protocol specific routing flag */
   1.189 +/*			0x80000		   unused */
   1.190 +#define RTF_PINNED	0x100000	/* future use */
   1.191 +#define	RTF_LOCAL	0x200000 	/* route represents a local address */
   1.192 +#define	RTF_BROADCAST	0x400000	/* route represents a bcast address */
   1.193 +#define	RTF_MULTICAST	0x800000	/* route represents a mcast address */
   1.194 +					/* 0x1000000 and up unassigned */
   1.195 +
   1.196 +/*
   1.197 + * Routing statistics.
   1.198 + */
   1.199 +struct	rtstat {
   1.200 +	short	rts_badredirect;	/* bogus redirect calls */
   1.201 +	short	rts_dynamic;		/* routes created by redirects */
   1.202 +	short	rts_newgateway;		/* routes modified by redirects */
   1.203 +	short	rts_unreach;		/* lookups which failed */
   1.204 +	short	rts_wildcard;		/* lookups satisfied by a wildcard */
   1.205 +};
   1.206 +/*
   1.207 + * Structures for routing messages.
   1.208 + */
   1.209 +struct rt_msghdr {
   1.210 +	u_short	rtm_msglen;	/* to skip over non-understood messages */
   1.211 +	u_char	rtm_version;	/* future binary compatibility */
   1.212 +	u_char	rtm_type;	/* message type */
   1.213 +	u_short	rtm_index;	/* index for associated ifp */
   1.214 +	int	rtm_flags;	/* flags, incl. kern & message, e.g. DONE */
   1.215 +	int	rtm_addrs;	/* bitmask identifying sockaddrs in msg */
   1.216 +	pid_t	rtm_pid;	/* identify sender */
   1.217 +	int	rtm_seq;	/* for sender to identify action */
   1.218 +	int	rtm_errno;	/* why failed */
   1.219 +	int	rtm_use;	/* from rtentry */
   1.220 +	u_long	rtm_inits;	/* which metrics we are initializing */
   1.221 +	struct	rt_metrics rtm_rmx; /* metrics themselves */
   1.222 +};
   1.223 +
   1.224 +#define RTM_VERSION	5	/* Up the ante and ignore older versions */
   1.225 +
   1.226 +/*
   1.227 + * Message types.
   1.228 + */
   1.229 +#define RTM_ADD		0x1	/* Add Route */
   1.230 +#define RTM_DELETE	0x2	/* Delete Route */
   1.231 +#define RTM_CHANGE	0x3	/* Change Metrics or flags */
   1.232 +#define RTM_GET		0x4	/* Report Metrics */
   1.233 +#define RTM_LOSING	0x5	/* Kernel Suspects Partitioning */
   1.234 +#define RTM_REDIRECT	0x6	/* Told to use different route */
   1.235 +#define RTM_MISS	0x7	/* Lookup failed on this address */
   1.236 +#define RTM_LOCK	0x8	/* fix specified metrics */
   1.237 +#define RTM_OLDADD	0x9	/* caused by SIOCADDRT */
   1.238 +#define RTM_OLDDEL	0xa	/* caused by SIOCDELRT */
   1.239 +#define RTM_RESOLVE	0xb	/* req to resolve dst to LL addr */
   1.240 +#define RTM_NEWADDR	0xc	/* address being added to iface */
   1.241 +#define RTM_DELADDR	0xd	/* address being removed from iface */
   1.242 +#define RTM_IFINFO	0xe	/* iface going up/down etc. */
   1.243 +#define	RTM_NEWMADDR	0xf	/* mcast group membership being added to if */
   1.244 +#define	RTM_DELMADDR	0x10	/* mcast group membership being deleted */
   1.245 +#define	RTM_IFANNOUNCE	0x11	/* iface arrival/departure */
   1.246 +#define	RTM_IEEE80211	0x12	/* IEEE80211 wireless event */
   1.247 +
   1.248 +/*
   1.249 + * Bitmask values for rtm_inits and rmx_locks.
   1.250 + */
   1.251 +#define RTV_MTU		0x1	/* init or lock _mtu */
   1.252 +#define RTV_HOPCOUNT	0x2	/* init or lock _hopcount */
   1.253 +#define RTV_EXPIRE	0x4	/* init or lock _expire */
   1.254 +#define RTV_RPIPE	0x8	/* init or lock _recvpipe */
   1.255 +#define RTV_SPIPE	0x10	/* init or lock _sendpipe */
   1.256 +#define RTV_SSTHRESH	0x20	/* init or lock _ssthresh */
   1.257 +#define RTV_RTT		0x40	/* init or lock _rtt */
   1.258 +#define RTV_RTTVAR	0x80	/* init or lock _rttvar */
   1.259 +
   1.260 +/*
   1.261 + * Bitmask values for rtm_addrs.
   1.262 + */
   1.263 +#define RTA_DST		0x1	/* destination sockaddr present */
   1.264 +#define RTA_GATEWAY	0x2	/* gateway sockaddr present */
   1.265 +#define RTA_NETMASK	0x4	/* netmask sockaddr present */
   1.266 +#define RTA_GENMASK	0x8	/* cloning mask sockaddr present */
   1.267 +#define RTA_IFP		0x10	/* interface name sockaddr present */
   1.268 +#define RTA_IFA		0x20	/* interface addr sockaddr present */
   1.269 +#define RTA_AUTHOR	0x40	/* sockaddr for author of redirect */
   1.270 +#define RTA_BRD		0x80	/* for NEWADDR, broadcast or p-p dest addr */
   1.271 +
   1.272 +/*
   1.273 + * Index offsets for sockaddr array for alternate internal encoding.
   1.274 + */
   1.275 +#define RTAX_DST	0	/* destination sockaddr present */
   1.276 +#define RTAX_GATEWAY	1	/* gateway sockaddr present */
   1.277 +#define RTAX_NETMASK	2	/* netmask sockaddr present */
   1.278 +#define RTAX_GENMASK	3	/* cloning mask sockaddr present */
   1.279 +#define RTAX_IFP	4	/* interface name sockaddr present */
   1.280 +#define RTAX_IFA	5	/* interface addr sockaddr present */
   1.281 +#define RTAX_AUTHOR	6	/* sockaddr for author of redirect */
   1.282 +#define RTAX_BRD	7	/* for NEWADDR, broadcast or p-p dest addr */
   1.283 +#define RTAX_MAX	8	/* size of array to allocate */
   1.284 +
   1.285 +struct rt_addrinfo {
   1.286 +	int	rti_addrs;
   1.287 +	struct	sockaddr *rti_info[RTAX_MAX];
   1.288 +	int	rti_flags;
   1.289 +	struct	ifaddr *rti_ifa;
   1.290 +	struct	ifnet *rti_ifp;
   1.291 +};
   1.292 +
   1.293 +/*
   1.294 + * This macro returns the size of a struct sockaddr when passed
   1.295 + * through a routing socket. Basically we round up sa_len to
   1.296 + * a multiple of sizeof(long), with a minimum of sizeof(long).
   1.297 + * The check for a NULL pointer is just a convenience, probably never used.
   1.298 + * The case sa_len == 0 should only apply to empty structures.
   1.299 + */
   1.300 +#define SA_SIZE(sa)						\
   1.301 +    (  (!(sa) || ((struct sockaddr *)(sa))->sa_len == 0) ?	\
   1.302 +	sizeof(long)		:				\
   1.303 +	1 + ( (((struct sockaddr *)(sa))->sa_len - 1) | (sizeof(long) - 1) ) )
   1.304 +
   1.305 +#ifdef _KERNEL
   1.306 +
   1.307 +#define	RT_LOCK_INIT(_rt) \
   1.308 +	mtx_init(&(_rt)->rt_mtx, "rtentry", NULL, MTX_DEF | MTX_DUPOK)
   1.309 +#define	RT_LOCK(_rt)		mtx_lock(&(_rt)->rt_mtx)
   1.310 +#define	RT_UNLOCK(_rt)		mtx_unlock(&(_rt)->rt_mtx)
   1.311 +#define	RT_LOCK_DESTROY(_rt)	mtx_destroy(&(_rt)->rt_mtx)
   1.312 +#define	RT_LOCK_ASSERT(_rt)	mtx_assert(&(_rt)->rt_mtx, MA_OWNED)
   1.313 +
   1.314 +#define	RT_ADDREF(_rt)	do {					\
   1.315 +	RT_LOCK_ASSERT(_rt);					\
   1.316 +	KASSERT((_rt)->rt_refcnt >= 0,				\
   1.317 +		("negative refcnt %ld", (_rt)->rt_refcnt));	\
   1.318 +	(_rt)->rt_refcnt++;					\
   1.319 +} while (0);
   1.320 +#define	RT_REMREF(_rt)	do {					\
   1.321 +	RT_LOCK_ASSERT(_rt);					\
   1.322 +	KASSERT((_rt)->rt_refcnt > 0,				\
   1.323 +		("bogus refcnt %ld", (_rt)->rt_refcnt));	\
   1.324 +	(_rt)->rt_refcnt--;					\
   1.325 +} while (0);
   1.326 +
   1.327 +#define	RTFREE_LOCKED(_rt) do {					\
   1.328 +		if ((_rt)->rt_refcnt <= 1)			\
   1.329 +			rtfree(_rt);				\
   1.330 +		else {						\
   1.331 +			RT_REMREF(_rt);				\
   1.332 +			RT_UNLOCK(_rt);				\
   1.333 +		}						\
   1.334 +		/* guard against invalid refs */		\
   1.335 +		_rt = 0;					\
   1.336 +	} while (0)
   1.337 +#define	RTFREE(_rt) do {					\
   1.338 +		RT_LOCK(_rt);					\
   1.339 +		RTFREE_LOCKED(_rt);				\
   1.340 +	} while (0)
   1.341 +
   1.342 +extern struct radix_node_head *rt_tables[AF_MAX+1];
   1.343 +
   1.344 +struct ifmultiaddr;
   1.345 +
   1.346 +#endif
   1.347 +#endif //__SYMBIAN32__
   1.348 +#endif