[BACK]Return to domain.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / sys

File: [cvs.NetBSD.org] / src / sys / sys / domain.h (download)

Revision 1.24, Sat Dec 9 05:33:09 2006 UTC (17 years, 4 months ago) by dyoung
Branch: MAIN
CVS Tags: yamt-splraiseipl-base5, yamt-splraiseipl-base4, yamt-splraiseipl-base3, thorpej-atomic-base, thorpej-atomic, reinoud-bufcleanup, post-newlock2-merge, newlock2-nbase, newlock2-base, ad-audiomp-base, ad-audiomp
Branch point for: yamt-idlelwp, vmlocking, mjf-ufs-trans
Changes since 1.23: +5 -1 lines

Here are various changes designed to protect against bad IPv4
routing caused by stale route caches (struct route).  Route caches
are sprinkled throughout PCBs, the IP fast-forwarding table, and
IP tunnel interfaces (gre, gif, stf).

Stale IPv6 and ISO route caches will be treated by separate patches.

Thank you to Christoph Badura for suggesting the general approach
to invalidating route caches that I take here.

Here are the details:

Add hooks to struct domain for tracking and for invalidating each
domain's route caches: dom_rtcache, dom_rtflush, and dom_rtflushall.

Introduce helper subroutines, rtflush(ro) for invalidating a route
cache, rtflushall(family) for invalidating all route caches in a
routing domain, and rtcache(ro) for notifying the domain of a new
cached route.

Chain together all IPv4 route caches where ro_rt != NULL.  Provide
in_rtcache() for adding a route to the chain.  Provide in_rtflush()
and in_rtflushall() for invalidating IPv4 route caches.  In
in_rtflush(), set ro_rt to NULL, and remove the route from the
chain.  In in_rtflushall(), walk the chain and remove every route
cache.

In rtrequest1(), call rtflushall() to invalidate route caches when
a route is added.

In gif(4), discard the workaround for stale caches that involves
expiring them every so often.

Replace the pattern 'RTFREE(ro->ro_rt); ro->ro_rt = NULL;' with a
call to rtflush(ro).

Update ipflow_fastforward() and all other users of route caches so
that they expect a cached route, ro->ro_rt, to turn to NULL.

Take care when moving a 'struct route' to rtflush() the source and
to rtcache() the destination.

In domain initializers, use .dom_xxx tags.

KNF here and there.

/*	$NetBSD: domain.h,v 1.24 2006/12/09 05:33:09 dyoung Exp $	*/

/*
 * Copyright (c) 1982, 1986, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)domain.h	8.1 (Berkeley) 6/2/93
 */

#ifndef _SYS_DOMAIN_H_
#define _SYS_DOMAIN_H_

/*
 * Structure per communications domain.
 */
#include <sys/mbuf.h>

/*
 * Forward structure declarations for function prototypes [sic].
 */
struct	lwp;
struct	mbuf;
struct	ifnet;
struct	ifqueue;
struct	route;

struct	domain {
	int	dom_family;		/* AF_xxx */
	const char *dom_name;
	void	(*dom_init)		/* initialize domain data structures */
			(void);
	int	(*dom_externalize)	/* externalize access rights */
			(struct mbuf *, struct lwp *);
	void	(*dom_dispose)		/* dispose of internalized rights */
			(struct mbuf *);
	const struct protosw *dom_protosw, *dom_protoswNPROTOSW;
	int	(*dom_rtattach)		/* initialize routing table */
			(void **, int);
	int	dom_rtoffset;		/* an arg to rtattach, in bits */
	int	dom_maxrtkey;		/* for routing layer */
	void	*(*dom_ifattach)	/* attach af-dependent data on ifnet */
			(struct ifnet *);
	void	(*dom_ifdetach)		/* detach af-dependent data on ifnet */
			(struct ifnet *, void *);
	struct ifqueue *dom_ifqueues[2]; /* ifqueue for domain */
	STAILQ_ENTRY(domain) dom_link;
	struct	mowner dom_mowner;
	void	(*dom_rtcache)(struct route *);
	void	(*dom_rtflush)(struct route *);
	void	(*dom_rtflushall)(void);
};

STAILQ_HEAD(domainhead,domain);

#ifdef _KERNEL
#define	DOMAIN_DEFINE(name)	\
	extern struct domain name; \
	__link_set_add_data(domains, name)

#define	DOMAIN_FOREACH(dom)	STAILQ_FOREACH(dom, &domains, dom_link)
extern struct domainhead domains;
void domain_attach(struct domain *);
void domaininit(void);
#endif

#endif /* !_SYS_DOMAIN_H_ */