Home | History | Annotate | Line # | Download | only in netinet
ip_flow.c revision 1.34.4.1
      1  1.34.4.1      yamt /*	$NetBSD: ip_flow.c,v 1.34.4.1 2006/10/22 06:07:28 yamt Exp $	*/
      2       1.1      matt 
      3       1.1      matt /*-
      4       1.1      matt  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5       1.1      matt  * All rights reserved.
      6       1.1      matt  *
      7       1.1      matt  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1      matt  * by the 3am Software Foundry ("3am").  It was developed by Matt Thomas.
      9       1.1      matt  *
     10       1.1      matt  * Redistribution and use in source and binary forms, with or without
     11       1.1      matt  * modification, are permitted provided that the following conditions
     12       1.1      matt  * are met:
     13       1.1      matt  * 1. Redistributions of source code must retain the above copyright
     14       1.1      matt  *    notice, this list of conditions and the following disclaimer.
     15       1.1      matt  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1      matt  *    notice, this list of conditions and the following disclaimer in the
     17       1.1      matt  *    documentation and/or other materials provided with the distribution.
     18       1.1      matt  * 3. All advertising materials mentioning features or use of this software
     19       1.1      matt  *    must display the following acknowledgement:
     20       1.1      matt  *	This product includes software developed by the NetBSD
     21       1.1      matt  *	Foundation, Inc. and its contributors.
     22       1.1      matt  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.1      matt  *    contributors may be used to endorse or promote products derived
     24       1.1      matt  *    from this software without specific prior written permission.
     25       1.1      matt  *
     26       1.1      matt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.1      matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.1      matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.1      matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.1      matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.1      matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.1      matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.1      matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.1      matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.1      matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.1      matt  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1      matt  */
     38      1.22     lukem 
     39      1.22     lukem #include <sys/cdefs.h>
     40  1.34.4.1      yamt __KERNEL_RCSID(0, "$NetBSD: ip_flow.c,v 1.34.4.1 2006/10/22 06:07:28 yamt Exp $");
     41       1.1      matt 
     42       1.1      matt #include <sys/param.h>
     43       1.1      matt #include <sys/systm.h>
     44       1.1      matt #include <sys/malloc.h>
     45       1.1      matt #include <sys/mbuf.h>
     46       1.1      matt #include <sys/domain.h>
     47       1.1      matt #include <sys/protosw.h>
     48       1.1      matt #include <sys/socket.h>
     49       1.1      matt #include <sys/socketvar.h>
     50       1.1      matt #include <sys/errno.h>
     51       1.1      matt #include <sys/time.h>
     52       1.1      matt #include <sys/kernel.h>
     53       1.7   thorpej #include <sys/pool.h>
     54       1.1      matt #include <sys/sysctl.h>
     55       1.1      matt 
     56       1.1      matt #include <net/if.h>
     57       1.1      matt #include <net/if_dl.h>
     58       1.1      matt #include <net/route.h>
     59       1.1      matt #include <net/pfil.h>
     60       1.1      matt 
     61       1.1      matt #include <netinet/in.h>
     62       1.1      matt #include <netinet/in_systm.h>
     63       1.1      matt #include <netinet/ip.h>
     64       1.1      matt #include <netinet/in_pcb.h>
     65       1.1      matt #include <netinet/in_var.h>
     66       1.1      matt #include <netinet/ip_var.h>
     67       1.1      matt 
     68      1.28    simonb POOL_INIT(ipflow_pool, sizeof(struct ipflow), 0, 0, 0, "ipflowpl", NULL);
     69       1.7   thorpej 
     70       1.5   thorpej LIST_HEAD(ipflowhead, ipflow);
     71       1.5   thorpej 
     72       1.1      matt #define	IPFLOW_TIMER		(5 * PR_SLOWHZ)
     73       1.1      matt #define	IPFLOW_HASHSIZE		(1 << IPFLOW_HASHBITS)
     74       1.5   thorpej 
     75       1.5   thorpej static struct ipflowhead ipflowtable[IPFLOW_HASHSIZE];
     76       1.5   thorpej static struct ipflowhead ipflowlist;
     77       1.1      matt static int ipflow_inuse;
     78       1.5   thorpej 
     79       1.5   thorpej #define	IPFLOW_INSERT(bucket, ipf) \
     80       1.5   thorpej do { \
     81       1.5   thorpej 	LIST_INSERT_HEAD((bucket), (ipf), ipf_hash); \
     82       1.5   thorpej 	LIST_INSERT_HEAD(&ipflowlist, (ipf), ipf_list); \
     83      1.26     perry } while (/*CONSTCOND*/ 0)
     84       1.5   thorpej 
     85       1.5   thorpej #define	IPFLOW_REMOVE(ipf) \
     86       1.5   thorpej do { \
     87       1.5   thorpej 	LIST_REMOVE((ipf), ipf_hash); \
     88       1.5   thorpej 	LIST_REMOVE((ipf), ipf_list); \
     89      1.26     perry } while (/*CONSTCOND*/ 0)
     90       1.5   thorpej 
     91       1.3      matt #ifndef IPFLOW_MAX
     92       1.1      matt #define	IPFLOW_MAX		256
     93       1.3      matt #endif
     94       1.3      matt int ip_maxflows = IPFLOW_MAX;
     95       1.1      matt 
     96       1.1      matt static unsigned
     97      1.29     perry ipflow_hash(struct in_addr dst,	struct in_addr src, unsigned tos)
     98       1.1      matt {
     99       1.1      matt 	unsigned hash = tos;
    100       1.1      matt 	int idx;
    101       1.1      matt 	for (idx = 0; idx < 32; idx += IPFLOW_HASHBITS)
    102       1.1      matt 		hash += (dst.s_addr >> (32 - idx)) + (src.s_addr >> idx);
    103       1.1      matt 	return hash & (IPFLOW_HASHSIZE-1);
    104       1.1      matt }
    105       1.1      matt 
    106       1.1      matt static struct ipflow *
    107      1.29     perry ipflow_lookup(const struct ip *ip)
    108       1.1      matt {
    109       1.1      matt 	unsigned hash;
    110       1.1      matt 	struct ipflow *ipf;
    111       1.1      matt 
    112       1.1      matt 	hash = ipflow_hash(ip->ip_dst, ip->ip_src, ip->ip_tos);
    113       1.1      matt 
    114      1.30  christos 	LIST_FOREACH(ipf, &ipflowtable[hash], ipf_hash) {
    115       1.1      matt 		if (ip->ip_dst.s_addr == ipf->ipf_dst.s_addr
    116       1.1      matt 		    && ip->ip_src.s_addr == ipf->ipf_src.s_addr
    117       1.1      matt 		    && ip->ip_tos == ipf->ipf_tos)
    118       1.1      matt 			break;
    119       1.1      matt 	}
    120       1.1      matt 	return ipf;
    121       1.1      matt }
    122       1.1      matt 
    123       1.7   thorpej void
    124      1.29     perry ipflow_init(void)
    125       1.7   thorpej {
    126       1.7   thorpej 	int i;
    127       1.7   thorpej 
    128       1.7   thorpej 	LIST_INIT(&ipflowlist);
    129       1.7   thorpej 	for (i = 0; i < IPFLOW_HASHSIZE; i++)
    130       1.7   thorpej 		LIST_INIT(&ipflowtable[i]);
    131       1.7   thorpej }
    132       1.7   thorpej 
    133       1.1      matt int
    134      1.29     perry ipflow_fastforward(struct mbuf *m)
    135       1.1      matt {
    136      1.25   thorpej 	struct ip *ip, ip_store;
    137       1.1      matt 	struct ipflow *ipf;
    138       1.1      matt 	struct rtentry *rt;
    139      1.16   thorpej 	struct sockaddr *dst;
    140       1.1      matt 	int error;
    141       1.6  sommerfe 	int iplen;
    142       1.1      matt 
    143       1.1      matt 	/*
    144       1.1      matt 	 * Are we forwarding packets?  Big enough for an IP packet?
    145       1.1      matt 	 */
    146       1.3      matt 	if (!ipforwarding || ipflow_inuse == 0 || m->m_len < sizeof(struct ip))
    147       1.1      matt 		return 0;
    148      1.14  sommerfe 
    149      1.14  sommerfe 	/*
    150      1.19       wiz 	 * Was packet received as a link-level multicast or broadcast?
    151      1.14  sommerfe 	 * If so, don't try to fast forward..
    152      1.14  sommerfe 	 */
    153      1.14  sommerfe 	if ((m->m_flags & (M_BCAST|M_MCAST)) != 0)
    154      1.14  sommerfe 		return 0;
    155      1.24    itojun 
    156       1.1      matt 	/*
    157       1.1      matt 	 * IP header with no option and valid version and length
    158       1.1      matt 	 */
    159      1.25   thorpej 	if (IP_HDR_ALIGNED_P(mtod(m, caddr_t)))
    160      1.25   thorpej 		ip = mtod(m, struct ip *);
    161      1.25   thorpej 	else {
    162      1.25   thorpej 		memcpy(&ip_store, mtod(m, caddr_t), sizeof(ip_store));
    163      1.25   thorpej 		ip = &ip_store;
    164      1.25   thorpej 	}
    165       1.6  sommerfe 	iplen = ntohs(ip->ip_len);
    166       1.5   thorpej 	if (ip->ip_v != IPVERSION || ip->ip_hl != (sizeof(struct ip) >> 2) ||
    167      1.13     proff 	    iplen < sizeof(struct ip) || iplen > m->m_pkthdr.len)
    168       1.1      matt 		return 0;
    169       1.1      matt 	/*
    170       1.1      matt 	 * Find a flow.
    171       1.1      matt 	 */
    172       1.1      matt 	if ((ipf = ipflow_lookup(ip)) == NULL)
    173       1.1      matt 		return 0;
    174       1.1      matt 
    175       1.1      matt 	/*
    176      1.18   thorpej 	 * Verify the IP header checksum.
    177       1.2   thorpej 	 */
    178      1.18   thorpej 	switch (m->m_pkthdr.csum_flags &
    179      1.20   thorpej 		((m->m_pkthdr.rcvif->if_csum_flags_rx & M_CSUM_IPv4) |
    180      1.18   thorpej 		 M_CSUM_IPv4_BAD)) {
    181      1.18   thorpej 	case M_CSUM_IPv4|M_CSUM_IPv4_BAD:
    182      1.18   thorpej 		return (0);
    183      1.18   thorpej 
    184      1.18   thorpej 	case M_CSUM_IPv4:
    185      1.18   thorpej 		/* Checksum was okay. */
    186      1.18   thorpej 		break;
    187      1.18   thorpej 
    188      1.18   thorpej 	default:
    189      1.18   thorpej 		/* Must compute it ourselves. */
    190      1.18   thorpej 		if (in_cksum(m, sizeof(struct ip)) != 0)
    191      1.18   thorpej 			return (0);
    192      1.18   thorpej 		break;
    193      1.18   thorpej 	}
    194       1.2   thorpej 
    195       1.2   thorpej 	/*
    196       1.1      matt 	 * Route and interface still up?
    197       1.1      matt 	 */
    198       1.1      matt 	rt = ipf->ipf_ro.ro_rt;
    199       1.5   thorpej 	if ((rt->rt_flags & RTF_UP) == 0 ||
    200       1.5   thorpej 	    (rt->rt_ifp->if_flags & IFF_UP) == 0)
    201       1.1      matt 		return 0;
    202       1.1      matt 
    203       1.1      matt 	/*
    204       1.1      matt 	 * Packet size OK?  TTL?
    205       1.1      matt 	 */
    206       1.1      matt 	if (m->m_pkthdr.len > rt->rt_ifp->if_mtu || ip->ip_ttl <= IPTTLDEC)
    207       1.1      matt 		return 0;
    208       1.1      matt 
    209       1.1      matt 	/*
    210      1.18   thorpej 	 * Clear any in-bound checksum flags for this packet.
    211      1.18   thorpej 	 */
    212      1.18   thorpej 	m->m_pkthdr.csum_flags = 0;
    213      1.18   thorpej 
    214      1.18   thorpej 	/*
    215       1.1      matt 	 * Everything checks out and so we can forward this packet.
    216       1.1      matt 	 * Modify the TTL and incrementally change the checksum.
    217      1.24    itojun 	 *
    218       1.9   mycroft 	 * This method of adding the checksum works on either endian CPU.
    219       1.9   mycroft 	 * If htons() is inlined, all the arithmetic is folded; otherwise
    220      1.32     perry 	 * the htons()s are combined by CSE due to the const attribute.
    221      1.18   thorpej 	 *
    222      1.18   thorpej 	 * Don't bother using HW checksumming here -- the incremental
    223      1.18   thorpej 	 * update is pretty fast.
    224       1.1      matt 	 */
    225       1.1      matt 	ip->ip_ttl -= IPTTLDEC;
    226      1.12     itohy 	if (ip->ip_sum >= (u_int16_t) ~htons(IPTTLDEC << 8))
    227      1.11   mycroft 		ip->ip_sum -= ~htons(IPTTLDEC << 8);
    228       1.8   mycroft 	else
    229       1.2   thorpej 		ip->ip_sum += htons(IPTTLDEC << 8);
    230      1.25   thorpej 
    231      1.25   thorpej 	/*
    232      1.25   thorpej 	 * Done modifying the header; copy it back, if necessary.
    233      1.25   thorpej 	 */
    234      1.25   thorpej 	if (IP_HDR_ALIGNED_P(mtod(m, caddr_t)) == 0)
    235      1.25   thorpej 		memcpy(mtod(m, caddr_t), &ip_store, sizeof(ip_store));
    236       1.6  sommerfe 
    237       1.6  sommerfe 	/*
    238      1.24    itojun 	 * Trim the packet in case it's too long..
    239       1.6  sommerfe 	 */
    240       1.6  sommerfe 	if (m->m_pkthdr.len > iplen) {
    241       1.6  sommerfe 		if (m->m_len == m->m_pkthdr.len) {
    242       1.6  sommerfe 			m->m_len = iplen;
    243       1.6  sommerfe 			m->m_pkthdr.len = iplen;
    244       1.6  sommerfe 		} else
    245       1.6  sommerfe 			m_adj(m, iplen - m->m_pkthdr.len);
    246       1.2   thorpej 	}
    247       1.1      matt 
    248       1.1      matt 	/*
    249       1.1      matt 	 * Send the packet on it's way.  All we can get back is ENOBUFS
    250       1.1      matt 	 */
    251       1.1      matt 	ipf->ipf_uses++;
    252       1.5   thorpej 	PRT_SLOW_ARM(ipf->ipf_timer, IPFLOW_TIMER);
    253      1.16   thorpej 
    254      1.16   thorpej 	if (rt->rt_flags & RTF_GATEWAY)
    255      1.16   thorpej 		dst = rt->rt_gateway;
    256      1.16   thorpej 	else
    257      1.16   thorpej 		dst = &ipf->ipf_ro.ro_dst;
    258      1.16   thorpej 
    259      1.16   thorpej 	if ((error = (*rt->rt_ifp->if_output)(rt->rt_ifp, m, dst, rt)) != 0) {
    260       1.1      matt 		if (error == ENOBUFS)
    261       1.1      matt 			ipf->ipf_dropped++;
    262       1.1      matt 		else
    263       1.1      matt 			ipf->ipf_errors++;
    264       1.1      matt 	}
    265       1.1      matt 	return 1;
    266       1.1      matt }
    267       1.1      matt 
    268       1.1      matt static void
    270       1.1      matt ipflow_addstats(struct ipflow *ipf)
    271       1.1      matt {
    272       1.1      matt 	ipf->ipf_ro.ro_rt->rt_use += ipf->ipf_uses;
    273      1.34  liamjfoy 	ipstat.ips_cantforward += ipf->ipf_errors + ipf->ipf_dropped;
    274       1.1      matt 	ipstat.ips_total += ipf->ipf_uses;
    275       1.1      matt 	ipstat.ips_forward += ipf->ipf_uses;
    276       1.1      matt 	ipstat.ips_fastforward += ipf->ipf_uses;
    277       1.1      matt }
    278       1.1      matt 
    279      1.29     perry static void
    280       1.1      matt ipflow_free(struct ipflow *ipf)
    281       1.1      matt {
    282       1.1      matt 	int s;
    283       1.1      matt 	/*
    284       1.1      matt 	 * Remove the flow from the hash table (at elevated IPL).
    285       1.1      matt 	 * Once it's off the list, we can deal with it at normal
    286       1.1      matt 	 * network IPL.
    287      1.17   thorpej 	 */
    288       1.5   thorpej 	s = splnet();
    289       1.1      matt 	IPFLOW_REMOVE(ipf);
    290       1.1      matt 	splx(s);
    291       1.1      matt 	ipflow_addstats(ipf);
    292       1.1      matt 	RTFREE(ipf->ipf_ro.ro_rt);
    293  1.34.4.1      yamt 	ipflow_inuse--;
    294       1.7   thorpej 	s = splnet();
    295  1.34.4.1      yamt 	pool_put(&ipflow_pool, ipf);
    296       1.1      matt 	splx(s);
    297       1.1      matt }
    298       1.3      matt 
    299      1.29     perry struct ipflow *
    300       1.1      matt ipflow_reap(int just_one)
    301       1.3      matt {
    302       1.3      matt 	while (just_one || ipflow_inuse > ip_maxflows) {
    303       1.3      matt 		struct ipflow *ipf, *maybe_ipf = NULL;
    304       1.3      matt 		int s;
    305       1.5   thorpej 
    306       1.5   thorpej 		ipf = LIST_FIRST(&ipflowlist);
    307       1.5   thorpej 		while (ipf != NULL) {
    308       1.5   thorpej 			/*
    309       1.5   thorpej 			 * If this no longer points to a valid route
    310       1.5   thorpej 			 * reclaim it.
    311       1.5   thorpej 			 */
    312       1.5   thorpej 			if ((ipf->ipf_ro.ro_rt->rt_flags & RTF_UP) == 0)
    313       1.5   thorpej 				goto done;
    314       1.5   thorpej 			/*
    315       1.5   thorpej 			 * choose the one that's been least recently
    316       1.5   thorpej 			 * used or has had the least uses in the
    317       1.5   thorpej 			 * last 1.5 intervals.
    318       1.5   thorpej 			 */
    319       1.5   thorpej 			if (maybe_ipf == NULL ||
    320       1.5   thorpej 			    ipf->ipf_timer < maybe_ipf->ipf_timer ||
    321       1.5   thorpej 			    (ipf->ipf_timer == maybe_ipf->ipf_timer &&
    322       1.5   thorpej 			     ipf->ipf_last_uses + ipf->ipf_uses <
    323       1.5   thorpej 			         maybe_ipf->ipf_last_uses +
    324       1.5   thorpej 			         maybe_ipf->ipf_uses))
    325       1.5   thorpej 				maybe_ipf = ipf;
    326       1.1      matt 			ipf = LIST_NEXT(ipf, ipf_list);
    327       1.3      matt 		}
    328       1.3      matt 		ipf = maybe_ipf;
    329       1.3      matt 	    done:
    330       1.3      matt 		/*
    331       1.3      matt 		 * Remove the entry from the flow table.
    332      1.17   thorpej 		 */
    333       1.5   thorpej 		s = splnet();
    334       1.3      matt 		IPFLOW_REMOVE(ipf);
    335       1.3      matt 		splx(s);
    336       1.3      matt 		ipflow_addstats(ipf);
    337       1.3      matt 		RTFREE(ipf->ipf_ro.ro_rt);
    338       1.3      matt 		if (just_one)
    339       1.7   thorpej 			return ipf;
    340       1.3      matt 		pool_put(&ipflow_pool, ipf);
    341       1.1      matt 		ipflow_inuse--;
    342       1.3      matt 	}
    343       1.1      matt 	return NULL;
    344       1.1      matt }
    345       1.1      matt 
    346      1.29     perry void
    347       1.1      matt ipflow_slowtimo(void)
    348       1.5   thorpej {
    349       1.2   thorpej 	struct ipflow *ipf, *next_ipf;
    350      1.30  christos 
    351       1.5   thorpej 	for (ipf = LIST_FIRST(&ipflowlist); ipf != NULL; ipf = next_ipf) {
    352       1.5   thorpej 		next_ipf = LIST_NEXT(ipf, ipf_list);
    353       1.5   thorpej 		if (PRT_SLOW_ISEXPIRED(ipf->ipf_timer)) {
    354       1.5   thorpej 			ipflow_free(ipf);
    355       1.5   thorpej 		} else {
    356       1.5   thorpej 			ipf->ipf_last_uses = ipf->ipf_uses;
    357      1.34  liamjfoy 			ipf->ipf_ro.ro_rt->rt_use += ipf->ipf_uses;
    358       1.5   thorpej 			ipstat.ips_total += ipf->ipf_uses;
    359       1.5   thorpej 			ipstat.ips_forward += ipf->ipf_uses;
    360       1.5   thorpej 			ipstat.ips_fastforward += ipf->ipf_uses;
    361       1.1      matt 			ipf->ipf_uses = 0;
    362       1.1      matt 		}
    363       1.1      matt 	}
    364       1.1      matt }
    365       1.1      matt 
    366      1.29     perry void
    367       1.1      matt ipflow_create(const struct route *ro, struct mbuf *m)
    368       1.1      matt {
    369       1.1      matt 	const struct ip *const ip = mtod(m, struct ip *);
    370       1.1      matt 	struct ipflow *ipf;
    371       1.1      matt 	unsigned hash;
    372       1.1      matt 	int s;
    373       1.1      matt 
    374       1.1      matt 	/*
    375       1.1      matt 	 * Don't create cache entries for ICMP messages.
    376       1.3      matt 	 */
    377       1.1      matt 	if (ip_maxflows == 0 || ip->ip_p == IPPROTO_ICMP)
    378       1.1      matt 		return;
    379       1.1      matt 	/*
    380       1.1      matt 	 * See if an existing flow struct exists.  If so remove it from it's
    381       1.1      matt 	 * list and free the old route.  If not, try to malloc a new one
    382       1.1      matt 	 * (if we aren't at our limit).
    383       1.1      matt 	 */
    384       1.1      matt 	ipf = ipflow_lookup(ip);
    385       1.3      matt 	if (ipf == NULL) {
    386       1.3      matt 		if (ipflow_inuse >= ip_maxflows) {
    387       1.1      matt 			ipf = ipflow_reap(1);
    388  1.34.4.1      yamt 		} else {
    389       1.7   thorpej 			s = splnet();
    390  1.34.4.1      yamt 			ipf = pool_get(&ipflow_pool, PR_NOWAIT);
    391       1.1      matt 			splx(s);
    392       1.1      matt 			if (ipf == NULL)
    393       1.1      matt 				return;
    394       1.1      matt 			ipflow_inuse++;
    395       1.1      matt 		}
    396       1.1      matt 		bzero((caddr_t) ipf, sizeof(*ipf));
    397      1.17   thorpej 	} else {
    398       1.5   thorpej 		s = splnet();
    399       1.1      matt 		IPFLOW_REMOVE(ipf);
    400       1.1      matt 		splx(s);
    401       1.1      matt 		ipflow_addstats(ipf);
    402       1.1      matt 		RTFREE(ipf->ipf_ro.ro_rt);
    403       1.1      matt 		ipf->ipf_uses = ipf->ipf_last_uses = 0;
    404       1.1      matt 		ipf->ipf_errors = ipf->ipf_dropped = 0;
    405       1.1      matt 	}
    406       1.1      matt 
    407       1.1      matt 	/*
    408       1.1      matt 	 * Fill in the updated information.
    409       1.1      matt 	 */
    410       1.1      matt 	ipf->ipf_ro = *ro;
    411       1.1      matt 	ro->ro_rt->rt_refcnt++;
    412       1.1      matt 	ipf->ipf_dst = ip->ip_dst;
    413       1.1      matt 	ipf->ipf_src = ip->ip_src;
    414       1.5   thorpej 	ipf->ipf_tos = ip->ip_tos;
    415      1.33    kardel 	PRT_SLOW_ARM(ipf->ipf_timer, IPFLOW_TIMER);
    416       1.1      matt 	ipf->ipf_start = time_uptime;
    417       1.1      matt 	/*
    418       1.1      matt 	 * Insert into the approriate bucket of the flow table.
    419       1.1      matt 	 */
    420      1.17   thorpej 	hash = ipflow_hash(ip->ip_dst, ip->ip_src, ip->ip_tos);
    421       1.5   thorpej 	s = splnet();
    422      1.27       scw 	IPFLOW_INSERT(&ipflowtable[hash], ipf);
    423      1.27       scw 	splx(s);
    424      1.27       scw }
    425      1.27       scw 
    426      1.29     perry void
    427      1.27       scw ipflow_invalidate_all(void)
    428      1.27       scw {
    429      1.27       scw 	struct ipflow *ipf, *next_ipf;
    430      1.27       scw 	int s;
    431      1.27       scw 
    432      1.27       scw 	s = splnet();
    433      1.27       scw 	for (ipf = LIST_FIRST(&ipflowlist); ipf != NULL; ipf = next_ipf) {
    434      1.27       scw 		next_ipf = LIST_NEXT(ipf, ipf_list);
    435      1.27       scw 		ipflow_free(ipf);
    436       1.1      matt 	}
    437       1.1      matt 	splx(s);
    438                     }
    439