xref: /csrg-svn/sys/netiso/clnp_timer.c (revision 63222)
149267Sbostic /*-
2*63222Sbostic  * Copyright (c) 1991, 1993
3*63222Sbostic  *	The Regents of the University of California.  All rights reserved.
449267Sbostic  *
549267Sbostic  * %sccs.include.redist.c%
649267Sbostic  *
7*63222Sbostic  *	@(#)clnp_timer.c	8.1 (Berkeley) 06/10/93
849267Sbostic  */
949267Sbostic 
1036376Ssklower /***********************************************************
1136376Ssklower 		Copyright IBM Corporation 1987
1236376Ssklower 
1336376Ssklower                       All Rights Reserved
1436376Ssklower 
1536376Ssklower Permission to use, copy, modify, and distribute this software and its
1636376Ssklower documentation for any purpose and without fee is hereby granted,
1736376Ssklower provided that the above copyright notice appear in all copies and that
1836376Ssklower both that copyright notice and this permission notice appear in
1936376Ssklower supporting documentation, and that the name of IBM not be
2036376Ssklower used in advertising or publicity pertaining to distribution of the
2136376Ssklower software without specific, written prior permission.
2236376Ssklower 
2336376Ssklower IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
2436376Ssklower ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
2536376Ssklower IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
2636376Ssklower ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
2736376Ssklower WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
2836376Ssklower ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
2936376Ssklower SOFTWARE.
3036376Ssklower 
3136376Ssklower ******************************************************************/
3236376Ssklower 
3336376Ssklower /*
3436376Ssklower  * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
3536376Ssklower  */
3636376Ssklower /* $Header: clnp_timer.c,v 4.2 88/06/29 14:59:05 hagens Exp $ */
3736376Ssklower /* $Source: /usr/argo/sys/netiso/RCS/clnp_timer.c,v $ */
3836376Ssklower 
3956533Sbostic #include <sys/param.h>
4056533Sbostic #include <sys/mbuf.h>
4156533Sbostic #include <sys/domain.h>
4256533Sbostic #include <sys/protosw.h>
4356533Sbostic #include <sys/socket.h>
4456533Sbostic #include <sys/socketvar.h>
4556533Sbostic #include <sys/errno.h>
4636376Ssklower 
4756533Sbostic #include <net/if.h>
4856533Sbostic #include <net/route.h>
4936376Ssklower 
5056533Sbostic #include <netiso/iso.h>
5156533Sbostic #include <netiso/clnp.h>
5256533Sbostic #include <netiso/clnp_stat.h>
5356533Sbostic #include <netiso/argo_debug.h>
5436376Ssklower 
5536376Ssklower extern struct clnp_fragl *clnp_frags;
5636376Ssklower 
5736376Ssklower /*
5836376Ssklower  * FUNCTION:		clnp_freefrags
5936376Ssklower  *
6036376Ssklower  * PURPOSE:			Free the resources associated with a fragment
6136376Ssklower  *
6236376Ssklower  * RETURNS:			pointer to next fragment in list of fragments
6336376Ssklower  *
6436376Ssklower  * SIDE EFFECTS:
6536376Ssklower  *
6636376Ssklower  * NOTES:
6736376Ssklower  *			TODO: send ER back to source
6836376Ssklower  */
6936376Ssklower struct clnp_fragl *
clnp_freefrags(cfh)7036376Ssklower clnp_freefrags(cfh)
7136376Ssklower register struct clnp_fragl	*cfh;	/* fragment header to delete */
7236376Ssklower {
7336376Ssklower 	struct clnp_fragl	*next = cfh->cfl_next;
7436376Ssklower 	struct clnp_frag	*cf;
7536376Ssklower 
7636376Ssklower 	/* free any frags hanging around */
7736376Ssklower 	cf = cfh->cfl_frags;
7836376Ssklower 	while (cf != NULL) {
7936376Ssklower 		struct clnp_frag	*cf_next = cf->cfr_next;
8039195Ssklower 		INCSTAT(cns_fragdropped);
8136376Ssklower 		m_freem(cf->cfr_data);
8236376Ssklower 		cf = cf_next;
8336376Ssklower 	}
8436376Ssklower 
8536376Ssklower 	/* free the copy of the header */
8639195Ssklower 	INCSTAT(cns_fragdropped);
8736376Ssklower 	m_freem(cfh->cfl_orighdr);
8836376Ssklower 
8936376Ssklower 	if (clnp_frags == cfh) {
9036376Ssklower 		clnp_frags = cfh->cfl_next;
9136376Ssklower 	} else {
9236376Ssklower 		struct clnp_fragl	*scan;
9336376Ssklower 
9436376Ssklower 		for (scan = clnp_frags; scan != NULL; scan = scan->cfl_next) {
9536376Ssklower 			if (scan->cfl_next == cfh) {
9636376Ssklower 				scan->cfl_next = cfh->cfl_next;
9736376Ssklower 				break;
9836376Ssklower 			}
9936376Ssklower 		}
10036376Ssklower 	}
10136376Ssklower 
10236376Ssklower 	/* free the fragment header */
10336376Ssklower 	m_freem(dtom(cfh));
10436376Ssklower 
10536376Ssklower 	return(next);
10636376Ssklower }
10736376Ssklower 
10836376Ssklower /*
10936376Ssklower  * FUNCTION:		clnp_slowtimo
11036376Ssklower  *
11136376Ssklower  * PURPOSE:			clnp timer processing; if the ttl expires on a
11236376Ssklower  *					packet on the reassembly queue, discard it.
11336376Ssklower  *
11436376Ssklower  * RETURNS:			none
11536376Ssklower  *
11636376Ssklower  * SIDE EFFECTS:
11736376Ssklower  *
11836376Ssklower  * NOTES:
11936376Ssklower  */
clnp_slowtimo()12036376Ssklower clnp_slowtimo()
12136376Ssklower {
12236376Ssklower 	register struct clnp_fragl	*cfh = clnp_frags;
12336376Ssklower 	int s = splnet();
12436376Ssklower 
12536376Ssklower 	while (cfh != NULL) {
12636376Ssklower 		if (--cfh->cfl_ttl == 0) {
12736376Ssklower 			cfh = clnp_freefrags(cfh);
12839195Ssklower 			INCSTAT(cns_fragtimeout);
12936376Ssklower 		} else {
13036376Ssklower 			cfh = cfh->cfl_next;
13136376Ssklower 		}
13236376Ssklower 	}
13336376Ssklower 	splx(s);
13436376Ssklower }
13536376Ssklower 
13636376Ssklower /*
13736376Ssklower  * FUNCTION:		clnp_drain
13836376Ssklower  *
13936376Ssklower  * PURPOSE:			drain off all datagram fragments
14036376Ssklower  *
14136376Ssklower  * RETURNS:			none
14236376Ssklower  *
14336376Ssklower  * SIDE EFFECTS:
14436376Ssklower  *
14536376Ssklower  * NOTES:
14636376Ssklower  *	TODO: should send back ER
14736376Ssklower  */
clnp_drain()14836376Ssklower clnp_drain()
14936376Ssklower {
15036376Ssklower 	register struct clnp_fragl	*cfh = clnp_frags;
15136376Ssklower 
15236376Ssklower 	while (cfh != NULL)
15336376Ssklower 		cfh = clnp_freefrags(cfh);
15436376Ssklower }
155