summaryrefslogtreecommitdiffstats
path: root/sys/netinet/ip_dummynet.c
diff options
context:
space:
mode:
authorluigi <luigi@FreeBSD.org>1999-05-04 07:30:08 +0000
committerluigi <luigi@FreeBSD.org>1999-05-04 07:30:08 +0000
commit61851a14d7f0271bacc976afef8762bdfa4b29d7 (patch)
treeb94fe5db74091e9e76883be5594c3f6426b3e96c /sys/netinet/ip_dummynet.c
parentcd4564cee7f2a60d615773daaa303999bd220569 (diff)
downloadFreeBSD-src-61851a14d7f0271bacc976afef8762bdfa4b29d7.zip
FreeBSD-src-61851a14d7f0271bacc976afef8762bdfa4b29d7.tar.gz
assorted dummynet cleanup:
+ plug an mbuf leak when dummynet used with bridging + make prototype of dummynet_io consistent with usage + code cleanup so that now bandwidth regulation is precise to the bit/s and not to (8*HZ) bit/s as before.
Diffstat (limited to 'sys/netinet/ip_dummynet.c')
-rw-r--r--sys/netinet/ip_dummynet.c58
1 files changed, 34 insertions, 24 deletions
diff --git a/sys/netinet/ip_dummynet.c b/sys/netinet/ip_dummynet.c
index 26c92a5..024998c 100644
--- a/sys/netinet/ip_dummynet.c
+++ b/sys/netinet/ip_dummynet.c
@@ -10,7 +10,7 @@
*
* This software is provided ``AS IS'' without any warranties of any kind.
*
- * $Id: ip_dummynet.c,v 1.11 1999/04/17 11:09:08 peter Exp $
+ * $Id: ip_dummynet.c,v 1.12 1999/04/20 13:32:04 peter Exp $
*/
/*
@@ -153,9 +153,11 @@ dn_move(struct dn_pipe *pipe, int immediate)
* such that the pkt would go out before the next tick.
*/
if (pipe->bandwidth) {
- if (pipe->numbytes < len)
+ int len_scaled = len*8*hz ;
+ /* numbytes is in bit/sec, scaled 8*hz ... */
+ if (pipe->numbytes < len_scaled)
break;
- pipe->numbytes -= len;
+ pipe->numbytes -= len_scaled;
}
pipe->r_len--; /* elements in queue */
pipe->r_len_bytes -= len ;
@@ -217,7 +219,7 @@ dn_move(struct dn_pipe *pipe, int immediate)
struct rtentry *tmp_rt = pkt->ro.ro_rt ;
(void)ip_output((struct mbuf *)pkt, (struct mbuf *)pkt->ifp,
- &(pkt->ro), pkt->dn_hlen, NULL);
+ &(pkt->ro), pkt->dn_dst, NULL);
rt_unref (tmp_rt) ;
}
break ;
@@ -225,8 +227,13 @@ dn_move(struct dn_pipe *pipe, int immediate)
ip_input((struct mbuf *)pkt) ;
break ;
#ifdef BRIDGE
- case DN_TO_BDG_FWD :
- bdg_forward((struct mbuf **)&pkt, pkt->ifp);
+ case DN_TO_BDG_FWD : {
+ struct mbuf *m = (struct mbuf *)pkt ;
+
+ bdg_forward(&m, pkt->ifp);
+ if (m)
+ m_freem(m);
+ }
break ;
#endif
default:
@@ -278,7 +285,8 @@ dummynet(void * __unused unused)
*/
int
dummynet_io(int pipe_nr, int dir,
- struct mbuf *m, struct ifnet *ifp, struct route *ro, int hlen,
+ struct mbuf *m, struct ifnet *ifp, struct route *ro,
+ struct sockaddr_in *dst,
struct ip_fw_chain *rule)
{
struct dn_pkt *pkt;
@@ -334,11 +342,21 @@ dummynet_io(int pipe_nr, int dir,
pkt->ifp = ifp;
if (dir == DN_TO_IP_OUT) {
- pkt->ro = *ro; /* XXX copied! */
+ /*
+ * we need to copy *ro because for icmp pkts (and maybe others)
+ * the caller passed a pointer into the stack.
+ */
+ pkt->ro = *ro;
if (ro->ro_rt)
ro->ro_rt->rt_refcnt++ ; /* XXX */
+ /*
+ * and again, dst might be a pointer into *ro...
+ */
+ if (dst == &ro->ro_dst) /* dst points into ro */
+ dst = &(pkt->ro.ro_dst) ;
+
+ pkt->dn_dst = dst;
}
- pkt->dn_hlen = hlen;
if (pipe->r.head == NULL)
pipe->r.head = pkt;
else
@@ -470,11 +488,10 @@ ip_dn_ctl(struct sockopt *sopt)
struct dn_pipe *q = (struct dn_pipe *)bp ;
bcopy(p, bp, sizeof( *p ) );
- /*
- * return bw and delay in bits/s and ms, respectively
- */
- q->bandwidth *= (8*hz) ;
- q->delay = (q->delay * 1000) / hz ;
+ /*
+ * return bw and delay in bits/s and ms, respectively
+ */
+ q->delay = (q->delay * 1000) / hz ;
bp += sizeof( *p ) ;
}
error = sooptcopyout(sopt, buf, size);
@@ -491,25 +508,19 @@ ip_dn_ctl(struct sockopt *sopt)
/*
* The config program passes parameters as follows:
* bandwidth = bits/second (0 = no limits);
- * must be translated in bytes/tick.
* delay = ms
* must be translated in ticks.
* queue_size = slots (0 = no limit)
* queue_size_bytes = bytes (0 = no limit)
* only one can be set, must be bound-checked
*/
- if ( p->bandwidth > 0 ) {
- p->bandwidth = p->bandwidth / 8 / hz ;
- if (p->bandwidth == 0) /* too little does not make sense! */
- p->bandwidth = 10 ;
- }
p->delay = ( p->delay * hz ) / 1000 ;
if (p->queue_size == 0 && p->queue_size_bytes == 0)
- p->queue_size = 100 ;
+ p->queue_size = 50 ;
if (p->queue_size != 0 ) /* buffers are prevailing */
p->queue_size_bytes = 0 ;
if (p->queue_size > 100)
- p->queue_size = 100 ;
+ p->queue_size = 50 ;
if (p->queue_size_bytes > 1024*1024)
p->queue_size_bytes = 1024*1024 ;
#if 0
@@ -591,8 +602,7 @@ ip_dn_ctl(struct sockopt *sopt)
static void
ip_dn_init(void)
{
- printf("DUMMYNET initialized (990326) -- size dn_pkt %d\n",
- sizeof(struct dn_pkt));
+ printf("DUMMYNET initialized (990504)\n");
all_pipes = NULL ;
ip_dn_ctl_ptr = ip_dn_ctl;
}
OpenPOWER on IntegriCloud