svn commit: r204201 - in user/luigi/ipfw3-head: sbin/ipfw sys/netinet sys/netinet/ipfw

Luigi Rizzo luigi at FreeBSD.org
Mon Feb 22 15:49:17 UTC 2010


Author: luigi
Date: Mon Feb 22 15:49:16 2010
New Revision: 204201
URL: http://svn.freebsd.org/changeset/base/204201

Log:
  updates to profile handling

Modified:
  user/luigi/ipfw3-head/sbin/ipfw/dummynet.c
  user/luigi/ipfw3-head/sys/netinet/ip_dummynet.h
  user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dn_glue.c
  user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dn_io.c
  user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c

Modified: user/luigi/ipfw3-head/sbin/ipfw/dummynet.c
==============================================================================
--- user/luigi/ipfw3-head/sbin/ipfw/dummynet.c	Mon Feb 22 15:35:31 2010	(r204200)
+++ user/luigi/ipfw3-head/sbin/ipfw/dummynet.c	Mon Feb 22 15:49:16 2010	(r204201)
@@ -511,7 +511,7 @@ static void
 read_bandwidth(char *arg, int *bandwidth, char *if_name, int namelen)
 {
 	if (*bandwidth != -1)
-		warn("duplicate token, override bandwidth value!");
+		warnx("duplicate token, override bandwidth value!");
 
 	if (arg[0] >= 'a' && arg[0] <= 'z') {
 		if (!if_name) {
@@ -592,8 +592,7 @@ load_extra_delays(const char *filename, 
 	struct point    points[ED_MAX_SAMPLES_NO];
 	int     points_no = 0;
 
-	if (link == NULL)
-		return; /*XXX error */
+	/* XXX link never NULL? */
 	p->link_nr = link->link_nr;
 
 	profile_name[0] = '\0';
@@ -637,7 +636,7 @@ load_extra_delays(const char *filename, 
 		    do_points = 0;
 		} else if (!strcasecmp(name, ED_TOK_BW)) {
 		    char buf[IFNAMSIZ];
-		    read_bandwidth(arg, &p->bandwidth, buf, sizeof(buf));
+		    read_bandwidth(arg, &link->bandwidth, buf, sizeof(buf));
 		} else if (!strcasecmp(name, ED_TOK_LOSS)) {
 		    if (loss != -1.0)
 			errx(ED_EFMT("duplicated token: %s"), name);
@@ -1101,9 +1100,9 @@ end_mask:
 			NEED((!pf), "profile already set");
 			NEED(p, "profile");
 		    {
-			pf = o_next(&buf, sizeof(*pf), DN_PROFILE);
 			NEED1("extra delay needs the file name\n");
-			load_extra_delays(av[0], pf, p);
+			pf = o_next(&buf, sizeof(*pf), DN_PROFILE);
+			load_extra_delays(av[0], pf, p); //XXX can't fail?
 			--ac; ++av;
 		    }
 			break;
@@ -1198,9 +1197,6 @@ end_mask:
 		 * correct. But on the other hand, why do we want RED with
 		 * WF2Q+ ?
 		 */
-		/* XXX MPD TODO do it in kernel space when attaching the
-		 *              flowset to scheduler?
-		 */
 #if 0
 		if (p.bandwidth==0) /* this is a WF2Q+ queue */
 			s = 0;
@@ -1226,13 +1222,6 @@ end_mask:
 	    }
 	}
 
-#if 0	/* XXX profile ? */
-	if (p.samples_no <= 0) {
-		struct dn_profile *prof;
-		prof = o_next(&o, sizeof(*prof), DN_PROFILE);
-		i = do_cmd(IP_DUMMYNET_CONFIGURE, prof, sizeof *prof);
-	} else
-#endif
 	i = do_cmd(IP_DUMMYNET3, base, (char *)buf - (char *)base);
 
 	if (i)

Modified: user/luigi/ipfw3-head/sys/netinet/ip_dummynet.h
==============================================================================
--- user/luigi/ipfw3-head/sys/netinet/ip_dummynet.h	Mon Feb 22 15:35:31 2010	(r204200)
+++ user/luigi/ipfw3-head/sys/netinet/ip_dummynet.h	Mon Feb 22 15:49:16 2010	(r204201)
@@ -204,7 +204,7 @@ struct dn_profile {
 	char		name[ED_MAX_NAME_LEN];
 	int		link_nr;
 	int		loss_level;
-	int		bandwidth;	// XXX maybe not needed ?
+	int		bandwidth;	// XXX use link bandwidth?
 	int		samples_no;	/* actual length of samples[] */
 	int samples[ED_MAX_SAMPLES_NO]; /* may be shorter */
 };

Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dn_glue.c
==============================================================================
--- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dn_glue.c	Mon Feb 22 15:35:31 2010	(r204200)
+++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dn_glue.c	Mon Feb 22 15:49:16 2010	(r204201)
@@ -417,11 +417,8 @@ dn_compat_config_pipe(struct dn_sch *sch
 	p->bandwidth = p7->bandwidth;
 	p->delay = p7->delay;
 	if (!is7) {
-		/* FreeBSD 8 has burst and profile */
+		/* FreeBSD 8 has burst  */
 		p->burst = p8->burst;
-		if (p8->samples > 0)
-			/*XXX TODO */
-			;
 	}
 
 	/* fill the fifo flowset */
@@ -448,12 +445,11 @@ dn_compat_config_profile(struct dn_profi
 {
 	struct dn_pipe8 *p8 = (struct dn_pipe8 *)v;
 
-	/* XXX NOT TESTED YET */
 	p8->samples = &(((struct dn_pipe_max8 *)p8)->samples[0]);
 	
 	pf->link_nr = p->link_nr;
 	pf->loss_level = p8->loss_level;
-	pf->bandwidth = p->bandwidth;
+// 	pf->bandwidth = p->bandwidth; //XXX bandwidth redundant?
 	pf->samples_no = p8->samples_no;
 	strncpy(pf->name, p8->name,sizeof(pf->name));
 	bcopy(p8->samples, pf->samples, sizeof(pf->samples));
@@ -605,7 +601,7 @@ dn_c_copy_pipe(struct dn_schk *s, struct
 			pipe8->loss_level = pf->loss_level;
 			pipe8->samples_no = pf->samples_no;
 		}
-		pipe8->burst = l->burst / 8 / hz;
+		pipe8->burst = div64(l->burst , 8 * hz);
 	}
 
 	fs->flow_mask = s->sch.sched_mask;

Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dn_io.c
==============================================================================
--- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dn_io.c	Mon Feb 22 15:35:31 2010	(r204200)
+++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dn_io.c	Mon Feb 22 15:49:16 2010	(r204201)
@@ -255,7 +255,7 @@ red_drops (struct dn_queue *q, int len)
 		 * XXX check wraps...
 		 */
 		if (q->avg) {
-			u_int t = (dn_cfg.curr_time - q->q_time) / fs->lookup_step;
+			u_int t = div64((dn_cfg.curr_time - q->q_time), fs->lookup_step);
 
 			q->avg = (t < fs->lookup_depth) ?
 			    SCALE_MUL(q->avg, fs->w_q_lookup[t]) : 0;
@@ -293,7 +293,7 @@ red_drops (struct dn_queue *q, int len)
 	}
 
 	if (fs->fs.flags & DN_QSIZE_BYTES)
-		p_b = (p_b * len) / fs->max_pkt_size;
+		p_b = div64((p_b * len) , fs->max_pkt_size);
 	if (++q->count == 0)
 		q->random = random() & 0xffff;
 	else {
@@ -556,7 +556,7 @@ dummynet_send(struct mbuf *m)
 	struct mbuf *n;
 
 	for (; m != NULL; m = n) {
-		struct ifnet *ifp;
+		struct ifnet *ifp = NULL;	/* gcc 3.4.6 complains */
         	struct m_tag *tag;
 		int dst;
 

Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c
==============================================================================
--- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c	Mon Feb 22 15:35:31 2010	(r204200)
+++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c	Mon Feb 22 15:49:16 2010	(r204201)
@@ -746,6 +746,10 @@ schk_delete_cb(void *obj, void *arg)
 		dn_ht_scan(s->siht, si_destroy, NULL);
 	else if (s->siht)
 		si_destroy(s->siht, NULL);
+	if (s->profile) {
+		free(s->profile, M_DUMMYNET);
+		s->profile = NULL;
+	}
 	s->siht = NULL;
 	if (s->fp->destroy)
 		s->fp->destroy(s);
@@ -984,8 +988,8 @@ config_red(struct dn_fsk *fs)
 	s = (i <= 0) ? 0 :
 		hz * dn_cfg.red_avg_pkt_size * 8 * SCALE(1) / i;
 
-	idle = (s * 3) / fs->w_q; /* s, fs->w_q scaled; idle not scaled */
-	fs->lookup_step = idle / dn_cfg.red_lookup_depth;
+	idle = div64((s * 3) , fs->w_q); /* s, fs->w_q scaled; idle not scaled */
+	fs->lookup_step = div64(idle , dn_cfg.red_lookup_depth);
 	/* fs->lookup_step not scaled, */
 	if (!fs->lookup_step)
 		fs->lookup_step = 1;
@@ -1170,6 +1174,11 @@ config_link(struct dn_link *p, struct dn
 		D("sched %d not found", i);
 		return EINVAL;
 	    }
+	    /* remove profile if exists */
+	    if (s->profile) {
+		free(s->profile, M_DUMMYNET);
+		s->profile = NULL;
+	    }
 	    /* copy all parameters */
 	    s->link.oid = p->oid;
 	    s->link.link_nr = i;
@@ -1281,6 +1290,7 @@ config_sched(struct dn_sch *_nsch, struc
 	struct schk_new_arg a; /* argument for schk_new */
 	int i;
 	struct dn_link p;	/* copy of oldlink */
+	struct dn_profile *pf;	/* copy of old link profile */
 	/* Used to preserv mask parameter */
 	struct ipfw_flow_id new_mask;
 	int new_buckets = 0;
@@ -1301,6 +1311,11 @@ config_sched(struct dn_sch *_nsch, struc
 			1, dn_cfg.max_hash_size, "sched buckets");
 	/* XXX other sanity checks */
 	bzero(&p, sizeof(p));
+	pf = malloc(sizeof(struct dn_profile), M_DUMMYNET, M_NOWAIT | M_ZERO);
+	if (pf == NULL) {
+		D("Error allocating profile");
+		return ENOMEM;
+	}
 
 	pipe_cmd = a.sch->flags & DN_PIPE_CMD;
 	a.sch->flags &= ~DN_PIPE_CMD; //XXX do it even if is not set?
@@ -1360,8 +1375,13 @@ again: /* run twice, for wfq and fifo */
 		return ENOMEM;
 	}
 	/* restore existing link if any */
-	if (p.link_nr)
+	if (p.link_nr) {
 		s->link = p;
+		if (pf->link_nr == p.link_nr) /* Restore profile */
+			s->profile = pf;
+		else
+			s->profile = NULL; /* XXX maybe not needed */
+	}
 	p.link_nr = 0;
 	if (s->fp == NULL) {
 		DX(2, "sched %d new type %s", i, a.fp->name);
@@ -1376,6 +1396,8 @@ again: /* run twice, for wfq and fifo */
 		if (s->link.link_nr == 0)
 			D("XXX WARNING link 0 for sched %d", i);
 		p = s->link;	/* preserve link */
+		if (s->profile) /* preserve profile */
+			bcopy(s->profile, pf, sizeof(struct dn_profile));
 		/* remove from the hash */
 		dn_ht_find(dn_cfg.schedhash, i, DNHT_REMOVE, NULL);
 		/* Detach flowsets, preserve queues. */


More information about the svn-src-user mailing list