Skip to contentSkip to conversation

Adding dsmark qdisc fails

LARTC Tero Saarni 4 participants 6 messages Mar 20, 2005 – Jan 6, 2006

lore
Share & tools
lore
#0 lore raw

I'm trying to configure dsmark qdisc on 2.6.11.4 user mode linux and tc from iproute2-2.6.11-050314.

I think I have some mismatch in my setup since adding dsmark qdisc fails *unless* I specify "set_tc_index" argument which I believe should be optional:

# tc qdisc add dev eth1 handle 1:0 root dsmark indices 8
RTNETLINK answers: Invalid argument
Mar 20 13:00:50 user user.debug kernel: dsmark_init(sch a0bb3ae0,[qdisc 
a0bb3b60],opt 00000000)

here the log shows that opt is null, sch_dsmark checks for that and bails out. However running tc with "set_tc_index" goes ok:

# tc qdisc add dev eth1 handle 1:0 root dsmark indices 8 set_tc_index
Mar 20 13:01:12 user user.debug kernel: dsmark_init(sch a0bb3060,[qdisc 
a0bb30e0],opt a038e9d0)
Mar 20 13:01:12 user user.debug kernel: dsmark_init: qdisc a0bb30e0
# tc qdisc show dev eth1
qdisc dsmark 1: indices 0x0008 set_tc_index

but then changing the class fails:

# tc class change dev eth1 classid 1:1 dsmark mask 0x0 value 0xb8
RTNETLINK answers: Invalid argument
Mar 20 13:02:28 user user.debug kernel: dsmark_get(sch a0bb3060,[qdisc 
a0bb30e0],classid 10001)
Mar 20 13:02:28 user user.debug kernel: dsmark_change(sch a0bb3060,[qdisc 
a0bb30e0],classid 10001,parent 0),arg 0x2

Any ideas where I've gone wrong?

--
Tero

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

_______________________________________________
LARTC mailing list
[email protected]
http://mailman.ds9a.nl/cgi-bin/mailman/listinfo/lartc

#1 lore raw
Quoted 24 lines · Tero Saarni

I'm trying to configure dsmark qdisc on 2.6.11.4 user mode linux and tc from iproute2-2.6.11-050314.

I think I have some mismatch in my setup since adding dsmark qdisc fails *unless* I specify "set_tc_index" argument which I believe should be optional:

# tc qdisc add dev eth1 handle 1:0 root dsmark indices 8
RTNETLINK answers: Invalid argument
Mar 20 13:00:50 user user.debug kernel: dsmark_init(sch a0bb3ae0,[qdisc a0bb3b60],opt 00000000)

here the log shows that opt is null, sch_dsmark checks for that and bails out. However running tc with "set_tc_index" goes ok:

# tc qdisc add dev eth1 handle 1:0 root dsmark indices 8 set_tc_index
Mar 20 13:01:12 user user.debug kernel: dsmark_init(sch a0bb3060,[qdisc a0bb30e0],opt a038e9d0)
Mar 20 13:01:12 user user.debug kernel: dsmark_init: qdisc a0bb30e0
# tc qdisc show dev eth1
qdisc dsmark 1: indices 0x0008 set_tc_index

but then changing the class fails:

Quoted 7 lines
# tc class change dev eth1 classid 1:1 dsmark mask 0x0 value 0xb8
RTNETLINK answers: Invalid argument
Mar 20 13:02:28 user user.debug kernel: dsmark_get(sch a0bb3060,[qdisc a0bb30e0],classid 10001)
Mar 20 13:02:28 user user.debug kernel: dsmark_change(sch a0bb3060,[qdisc a0bb30e0],classid 10001,parent 0),arg 0x2

Any ideas where I've gone wrong?

It is caused by this patch, the transformation to use NLMSG_TAIL is
not equivalent (it calculates the size of the aligned message). This
makes parsing the attributes in rtnetlink_rcv_msg() fail. I haven't checked what the exact problem is, Thomas, can you have a look at this please?

Regards
Patrick

# This is a BitKeeper generated diff -Nru style patch. #
# ChangeSet

#   2005/01/18 02:24:18+01:00 [email protected] 
#   Transform rta_len calculations for nested TLVs to use NLMSG_TAIL
#   macro to simply code a lot.
# 
# tc/q_tbf.c
#   2005/01/18 02:24:18+01:00 [email protected] +2 -2
#   Use NLMSG_TAIL
# 
# tc/q_red.c
#   2005/01/18 02:24:18+01:00 [email protected] +2 -3
#   Use NLMSG_TAIL
# 
# tc/q_netem.c
#   2005/01/18 02:24:18+01:00 [email protected] +2 -2
#   Use NLMSG_TAIL
# 
# tc/q_htb.c
#   2005/01/18 02:24:18+01:00 [email protected] +4 -4
#   Use NLMSG_TAIL
# 
# tc/q_hfsc.c
#   2005/01/18 02:24:18+01:00 [email protected] +2 -2
#   Use NLMSG_TAIL
# 
# tc/q_gred.c
#   2005/01/18 02:24:18+01:00 [email protected] +4 -6
#   Use NLMSG_TAIL
# 
# tc/q_dsmark.c
#   2005/01/18 02:24:18+01:00 [email protected] +4 -4
#   Use NLMSG_TAIL
# 
# tc/q_cbq.c
#   2005/01/18 02:24:18+01:00 [email protected] +4 -4
#   Use NLMSG_TAIL
# 
# tc/q_atm.c
#   2005/01/18 02:24:18+01:00 [email protected] +2 -2
#   Use NLMSG_TAIL
# 
# tc/m_police.c
#   2005/01/18 02:24:18+01:00 [email protected] +2 -2
#   Use NLMSG_TAIL
# 
# tc/m_pedit.c
#   2005/01/18 02:24:18+01:00 [email protected] +2 -3
#   Use NLMSG_TAIL
# 
# tc/m_mirred.c
#   2005/01/18 02:24:18+01:00 [email protected] +2 -3
#   Use NLMSG_TAIL
# 
# tc/m_ipt.c
#   2005/01/18 02:24:18+01:00 [email protected] +2 -3
#   Use NLMSG_TAIL
# 
# tc/m_gact.c
#   2005/01/18 02:24:18+01:00 [email protected] +2 -3
#   Use NLMSG_TAIL
# 
# tc/m_action.c
#   2005/01/18 02:24:18+01:00 [email protected] +17 -30
#   Use NLMSG_TAIL
# 
# tc/f_u32.c
#   2005/01/18 02:24:18+01:00 [email protected] +2 -2
#   Use NLMSG_TAIL
# 
# tc/f_tcindex.c
#   2005/01/18 02:24:18+01:00 [email protected] +2 -2
#   Use NLMSG_TAIL
# 
# tc/f_rsvp.c
#   2005/01/18 02:24:18+01:00 [email protected] +2 -2
#   Use NLMSG_TAIL
# 
# tc/f_route.c
#   2005/01/18 02:24:18+01:00 [email protected] +2 -2
#   Use NLMSG_TAIL
# 
# tc/f_fw.c
#   2005/01/18 02:24:18+01:00 [email protected] +2 -2
#   Use NLMSG_TAIL
# 
# include/libnetlink.h
#   2005/01/18 02:24:18+01:00 [email protected] +3 -0
#   Add NLMSG_TAIL macro pointing to the tail of a netlink message
# 
diff -Nru a/include/libnetlink.h b/include/libnetlink.h
--- a/include/libnetlink.h	2005-03-20 15:54:37 +01:00
+++ b/include/libnetlink.h	2005-03-20 15:54:37 +01:00
@@ -46,5 +46,8 @@
 extern int rtnl_from_file(FILE *, rtnl_filter_t handler,
 		       void *jarg);

+#define NLMSG_TAIL(nmsg) \
+ ((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
+
#endif /* __LIBNETLINK_H__ */

tc/f_fw.c +2 -2
diff -Nru a/tc/f_fw.c b/tc/f_fw.c
@@ -50,7 +50,7 @@
 	if (argc == 0)
 		return 0;
 
-	tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
+	tail = NLMSG_TAIL(n);
 	addattr_l(n, 4096, TCA_OPTIONS, NULL, 0);
 
 	while (argc > 0) {
@@ -98,7 +98,7 @@
 		}
 		argc--; argv++;
 	}
-	tail->rta_len = (((void*)n)+n->nlmsg_len) - (void*)tail;
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
tc/f_route.c +2 -2
diff -Nru a/tc/f_route.c b/tc/f_route.c
@@ -54,7 +54,7 @@
 	if (argc == 0)
 		return 0;
 
-	tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
+	tail = NLMSG_TAIL(n);
 	addattr_l(n, 4096, TCA_OPTIONS, NULL, 0);
 
 	while (argc > 0) {
@@ -125,7 +125,7 @@
 		}
 		argc--; argv++;
 	}
-	tail->rta_len = (((void*)n)+n->nlmsg_len) - (void*)tail;
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	if (order) {
 		fh &= ~0x7F00;
 		fh |= (order<<8)&0x7F00;
tc/f_rsvp.c +2 -2
diff -Nru a/tc/f_rsvp.c b/tc/f_rsvp.c
@@ -189,7 +189,7 @@
 	if (argc == 0)
 		return 0;
 
-	tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
+	tail = NLMSG_TAIL(n);
 	addattr_l(n, 4096, TCA_OPTIONS, NULL, 0);
 
 	while (argc > 0) {
@@ -282,7 +282,7 @@
 
 	if (pinfo_ok)
 		addattr_l(n, 4096, TCA_RSVP_PINFO, &pinfo, sizeof(pinfo));
-	tail->rta_len = (((void*)n)+n->nlmsg_len) - (void*)tail;
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
tc/f_tcindex.c +2 -2
diff -Nru a/tc/f_tcindex.c b/tc/f_tcindex.c
@@ -43,7 +43,7 @@
 		}
 	}
 	if (!argc) return 0;
-	tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
+	tail = NLMSG_TAIL(n);
 	addattr_l(n,4096,TCA_OPTIONS,NULL,0);
 	while (argc) {
 		if (!strcmp(*argv,"hash")) {
@@ -117,7 +117,7 @@
 		argc--;
 		argv++;
 	}
-	tail->rta_len = (((void*)n)+n->nlmsg_len) - (void*)tail;
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
tc/f_u32.c +2 -2
diff -Nru a/tc/f_u32.c b/tc/f_u32.c
@@ -794,7 +794,7 @@
 	if (argc == 0)
 		return 0;
 
-	tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
+	tail = NLMSG_TAIL(n);
 	addattr_l(n, MAX_MSG, TCA_OPTIONS, NULL, 0);
 
 	while (argc > 0) {
@@ -943,7 +943,7 @@
 		addattr_l(n, MAX_MSG, TCA_U32_HASH, &htid, 4);
 	if (sel_ok)
 		addattr_l(n, MAX_MSG, TCA_U32_SEL, &sel, sizeof(sel.sel)+sel.sel.nkeys*sizeof(struct tc_u32_key));
-	tail->rta_len = (((void*)n)+n->nlmsg_len) - (void*)tail;
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
tc/m_action.c +17 -30

111 lines not on this page · raw message

tc/m_gact.c +2 -3
diff -Nru a/tc/m_gact.c b/tc/m_gact.c
@@ -177,7 +177,7 @@
 	if (!ok)
 		return -1;
 
-	tail = (struct rtattr *) (((void *) n) + NLMSG_ALIGN(n->nlmsg_len));
+	tail = NLMSG_TAIL(n);
 	addattr_l(n, MAX_MSG, tca_id, NULL, 0);
 	addattr_l(n, MAX_MSG, TCA_GACT_PARMS, &p, sizeof (p));
 #ifdef CONFIG_GACT_PROB
@@ -185,8 +185,7 @@
 		addattr_l(n, MAX_MSG, TCA_GACT_PROB, &pp, sizeof (pp));
 	}
 #endif
-	tail->rta_len =
-	    (((void *) n) + NLMSG_ALIGN(n->nlmsg_len)) - (void *) tail;
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 
 	*argc_p = argc;
 	*argv_p = argv;
tc/m_ipt.c +2 -3
diff -Nru a/tc/m_ipt.c b/tc/m_ipt.c
@@ -547,7 +547,7 @@
 		}
 	}
 
-	tail = (struct rtattr *) (((void *) n) + NLMSG_ALIGN(n->nlmsg_len));
+	tail = NLMSG_TAIL(n);
 	addattr_l(n, MAX_MSG, tca_id, NULL, 0);
 	fprintf(stdout, "tablename: %s hook: %s\n ", tname, ipthooks[hook]);
 	fprintf(stdout, "\ttarget: ");
@@ -569,8 +569,7 @@
 	addattr_l(n, MAX_MSG, TCA_IPT_INDEX, &index, 4);
 	if (m)
 		addattr_l(n, MAX_MSG, TCA_IPT_TARG, m->t, m->t->u.target_size);
-	tail->rta_len =
-	    (((void *) n) + NLMSG_ALIGN(n->nlmsg_len)) - (void *) tail;
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 
 	argc -= optind;
 	argv += optind;
tc/m_mirred.c +2 -3
diff -Nru a/tc/m_mirred.c b/tc/m_mirred.c
@@ -201,11 +201,10 @@
 	if (mirred_d)
 		fprintf(stdout, "Action %d device %s ifindex %d\n",p.action, d,p.ifindex);
 
-	tail = (struct rtattr *) (((void *) n) + NLMSG_ALIGN(n->nlmsg_len));
+	tail = NLMSG_TAIL(n);
 	addattr_l(n, MAX_MSG, tca_id, NULL, 0);
 	addattr_l(n, MAX_MSG, TCA_MIRRED_PARMS, &p, sizeof (p));
-	tail->rta_len =
-	    (((void *) n) + NLMSG_ALIGN(n->nlmsg_len)) - (void *) tail;
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 
 	*argc_p = argc;
 	*argv_p = argv;
tc/m_pedit.c +2 -3
diff -Nru a/tc/m_pedit.c b/tc/m_pedit.c
@@ -534,11 +534,10 @@
 		}
 	}
 
-	tail = (struct rtattr *) (((void *) n) + NLMSG_ALIGN(n->nlmsg_len));
+	tail = NLMSG_TAIL(n);
 	addattr_l(n, MAX_MSG, tca_id, NULL, 0);
 	addattr_l(n, MAX_MSG, TCA_PEDIT_PARMS,&sel, sizeof(sel.sel)+sel.sel.nkeys*sizeof(struct tc_pedit_key));
-	tail->rta_len =
-	    (((void *) n) + NLMSG_ALIGN(n->nlmsg_len)) - (void *) tail;
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 
 	*argc_p = argc;
 	*argv_p = argv;
tc/m_police.c +2 -2
diff -Nru a/tc/m_police.c b/tc/m_police.c
@@ -282,7 +282,7 @@
 		p.peakrate.mpu = mpu;
 	}
 
-	tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
+	tail = NLMSG_TAIL(n);
 	addattr_l(n, MAX_MSG, tca_id, NULL, 0);
 	addattr_l(n, MAX_MSG, TCA_POLICE_TBF, &p, sizeof(p));
 	if (p.rate.rate)
@@ -294,7 +294,7 @@
 	if (presult)
 		addattr32(n, MAX_MSG, TCA_POLICE_RESULT, presult);
 
-	tail->rta_len = (((void*)n)+NLMSG_ALIGN(n->nlmsg_len)) - (void*)tail;
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	res = 0;
 
 	*argc_p = argc;
tc/q_atm.c +2 -2
diff -Nru a/tc/q_atm.c b/tc/q_atm.c
@@ -179,12 +179,12 @@
 			perror("ioctl ATMARP_MKIP");
 			return -1;
 		}
-	tail = (struct rtattr *) (((void *) n)+NLMSG_ALIGN(n->nlmsg_len));
+	tail = NLMSG_TAIL(n);
 	addattr_l(n,1024,TCA_OPTIONS,NULL,0);
 	addattr_l(n,1024,TCA_ATM_FD,&s,sizeof(s));
 	if (excess) addattr_l(n,1024,TCA_ATM_EXCESS,&excess,sizeof(excess));
 	if (hdr_len != -1) addattr_l(n,1024,TCA_ATM_HDR,hdr,hdr_len);
-	tail->rta_len = (((void *) n)+NLMSG_ALIGN(n->nlmsg_len))-(void *) tail;
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
tc/q_cbq.c +4 -4
diff -Nru a/tc/q_cbq.c b/tc/q_cbq.c
@@ -151,7 +151,7 @@
 	lss.change = TCF_CBQ_LSS_MAXIDLE|TCF_CBQ_LSS_EWMA|TCF_CBQ_LSS_AVPKT;
 	lss.avpkt = avpkt;
 
-	tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
+	tail = NLMSG_TAIL(n);
 	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	addattr_l(n, 1024, TCA_CBQ_RATE, &r, sizeof(r));
 	addattr_l(n, 1024, TCA_CBQ_LSSOPT, &lss, sizeof(lss));
@@ -162,7 +162,7 @@
 			printf("%u ", rtab[i]);
 		printf("\n");
 	}
-	tail->rta_len = (((void*)n)+NLMSG_ALIGN(n->nlmsg_len)) - (void*)tail;
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
@@ -385,7 +385,7 @@
 		lss.change |= TCF_CBQ_LSS_EWMA;
 	}
 
-	tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
+	tail = NLMSG_TAIL(n);
 	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	if (lss.change) {
 		lss.change |= TCF_CBQ_LSS_FLAGS;
@@ -405,7 +405,7 @@
 			printf("\n");
 		}
 	}
-	tail->rta_len = (((void*)n)+NLMSG_ALIGN(n->nlmsg_len)) - (void*)tail;
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
tc/q_dsmark.c +4 -4
diff -Nru a/tc/q_dsmark.c b/tc/q_dsmark.c
@@ -71,7 +71,7 @@
 		explain();
 		return -1;
 	}
-	tail = (struct rtattr *) (((void *) n)+NLMSG_ALIGN(n->nlmsg_len));
+	tail = NLMSG_TAIL(n);
 	addattr_l(n,1024,TCA_OPTIONS,NULL,0);
 	addattr_l(n,1024,TCA_DSMARK_INDICES,&ind,sizeof(ind));
 	if (dflt != -1) {
@@ -80,7 +80,7 @@
 	    addattr_l(n,1024,TCA_DSMARK_DEFAULT_INDEX,&tmp,sizeof(tmp));
 	}
 	if (set_tc_index) addattr_l(n,1024,TCA_DSMARK_SET_TC_INDEX,NULL,0);
-	tail->rta_len = (((void *) n)+n->nlmsg_len)-(void *) tail;
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
@@ -98,7 +98,7 @@
 	__u8 tmp;
 	char *end;
 
-	tail = (struct rtattr *) (((void *) n)+NLMSG_ALIGN(n->nlmsg_len));
+	tail = NLMSG_TAIL(n);
 	addattr_l(n,1024,TCA_OPTIONS,NULL,0);
 	while (argc > 0) {
 		if (!strcmp(*argv,"mask")) {
@@ -126,7 +126,7 @@
 		argc--;
 		argv++;
 	}
-	tail->rta_len = (((void *) n)+n->nlmsg_len)-(void *) tail;
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
tc/q_gred.c +4 -6
diff -Nru a/tc/q_gred.c b/tc/q_gred.c
@@ -106,11 +106,10 @@
 }
 DPRINTF("TC_GRED: sending DPs=%d default=%d\n",opt.DPs,opt.def_DP);
 	n->nlmsg_flags|=NLM_F_CREATE;
-	tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
-
+	tail = NLMSG_TAIL(n);
 	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	addattr_l(n, 1024, TCA_GRED_DPS, &opt, sizeof(struct tc_gred_sopt));
-	tail->rta_len = (((void*)n)+NLMSG_ALIGN(n->nlmsg_len)) - (void*)tail;
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 return 0;
 }
 /*
@@ -252,12 +251,11 @@
 	}
 	opt.Scell_log = wlog;
 
-	tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
-
+	tail = NLMSG_TAIL(n);
 	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	addattr_l(n, 1024, TCA_GRED_PARMS, &opt, sizeof(opt));
 	addattr_l(n, 1024, TCA_GRED_STAB, sbuf, 256);
-	tail->rta_len = (((void*)n)+NLMSG_ALIGN(n->nlmsg_len)) - (void*)tail;
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
tc/q_hfsc.c +2 -2
diff -Nru a/tc/q_hfsc.c b/tc/q_hfsc.c
@@ -205,7 +205,7 @@
 		return -1;
 	}
 
-	tail = (struct rtattr*)(((void*)n) + NLMSG_ALIGN(n->nlmsg_len));
+	tail = NLMSG_TAIL(n);
 
 	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	if (rsc_ok)
@@ -215,7 +215,7 @@
 	if (usc_ok)
 		addattr_l(n, 1024, TCA_HFSC_USC, &usc, sizeof(usc));
 
-	tail->rta_len = (((void*)n) + NLMSG_ALIGN(n->nlmsg_len)) - (void*)tail;
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
tc/q_htb.c +4 -4
diff -Nru a/tc/q_htb.c b/tc/q_htb.c
@@ -93,10 +93,10 @@
 		}
 		argc--; argv++;
 	}
-	tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
+	tail = NLMSG_TAIL(n);
 	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	addattr_l(n, 2024, TCA_HTB_INIT, &opt, NLMSG_ALIGN(sizeof(opt)));
-	tail->rta_len = (((void*)n)+NLMSG_ALIGN(n->nlmsg_len)) - (void*)tail;
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
@@ -224,12 +224,12 @@
 	opt.cbuffer = tc_calc_xmittime(opt.ceil.rate, cbuffer);
 	opt.ceil.cell_log = ccell_log;
 
-	tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
+	tail = NLMSG_TAIL(n);
 	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	addattr_l(n, 2024, TCA_HTB_PARMS, &opt, sizeof(opt));
 	addattr_l(n, 3024, TCA_HTB_RTAB, rtab, 1024);
 	addattr_l(n, 4024, TCA_HTB_CTAB, ctab, 1024);
-	tail->rta_len = (((void*)n)+NLMSG_ALIGN(n->nlmsg_len)) - (void*)tail;
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
tc/q_netem.c +2 -2
diff -Nru a/tc/q_netem.c b/tc/q_netem.c
@@ -213,7 +213,7 @@
 		argc--; argv++;
 	}
 
-	tail = (struct rtattr*)(((void*)n) + NLMSG_ALIGN(n->nlmsg_len));
+	tail = NLMSG_TAIL(n);
 
 	addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
 	addattr_l(n, 1024, TCA_NETEM_CORR, &cor, sizeof(cor));
@@ -222,7 +222,7 @@
 		addattr_l(n, 32768, TCA_NETEM_DELAY_DIST,
 			  dist_data, dist_size*sizeof(dist_data[0]));
 	}
-	tail->rta_len = (((void*)n)+NLMSG_ALIGN(n->nlmsg_len)) - (void*)tail;
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
tc/q_red.c +2 -3
diff -Nru a/tc/q_red.c b/tc/q_red.c
@@ -149,12 +149,11 @@
 #endif
 	}
 
-	tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
-
+	tail = NLMSG_TAIL(n);
 	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	addattr_l(n, 1024, TCA_RED_PARMS, &opt, sizeof(opt));
 	addattr_l(n, 1024, TCA_RED_STAB, sbuf, 256);
-	tail->rta_len = (((void*)n)+NLMSG_ALIGN(n->nlmsg_len)) - (void*)tail;
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
tc/q_tbf.c +2 -2
diff -Nru a/tc/q_tbf.c b/tc/q_tbf.c
@@ -187,13 +187,13 @@
 		opt.peakrate.mpu = mpu;
 	}
 
-	tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
+	tail = NLMSG_TAIL(n);
 	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	addattr_l(n, 2024, TCA_TBF_PARMS, &opt, sizeof(opt));
 	addattr_l(n, 3024, TCA_TBF_RTAB, rtab, 1024);
 	if (opt.peakrate.rate)
 		addattr_l(n, 4096, TCA_TBF_PTAB, ptab, 1024);
-	tail->rta_len = (((void*)n)+NLMSG_ALIGN(n->nlmsg_len)) - (void*)tail;
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 

_______________________________________________
LARTC mailing list
[email protected]
http://mailman.ds9a.nl/cgi-bin/mailman/listinfo/lartc

#2 lore raw
In reply to Tero Saarni

* Patrick McHardy <[email protected]> 2005-03-20 16:15

Quoted 10 lines
Quoted 5 lines
# tc qdisc add dev eth1 handle 1:0 root dsmark indices 8
RTNETLINK answers: Invalid argument
Mar 20 13:00:50 user user.debug kernel: dsmark_init(sch a0bb3ae0,[qdisc 
a0bb3b60],opt 00000000)

It is caused by this patch, the transformation to use NLMSG_TAIL is not equivalent (it calculates the size of the aligned message). This makes parsing the attributes in rtnetlink_rcv_msg() fail. I haven't checked what the exact problem is, Thomas, can you have a look at this please?

My patch is right but discovered a quite more serious bug in the generic routing attribute handling. nlmsg_len is not aligned to RTA_ALIGNTO if the data length of the attribute did not have this alignment itself. The fact that the addition of the next attribute fixed this bug automatically by issueing NLMSG_ALIGN(nlmsg_len) + len put a good shadow around it and made it only a problem when the last attribute added was not properly aligned. Patch attached, alternatively one can clone bk://kernel.bkbits.net/tgraf/iproute2-tgr and als get the new fancy multipath bits installed. ;->

# This is a BitKeeper generated diff -Nru style patch. #
# ChangeSet

#   2005/03/20 17:19:39+01:00 [email protected] 
#   Fix netlink message alignment when the last routing attribute added
#   has a data length not aligned to RTA_ALIGNTO.
# 
# lib/libnetlink.c
#   2005/03/20 17:19:38+01:00 [email protected] +4 -4
#   Fix netlink message alignment when the last routing attribute added
#   has a data length not aligned to RTA_ALIGNTO.
# 
diff -Nru a/lib/libnetlink.c b/lib/libnetlink.c
--- a/lib/libnetlink.c	2005-03-20 17:19:53 +01:00
+++ b/lib/libnetlink.c	2005-03-20 17:19:53 +01:00
@@ -491,7 +491,7 @@
 	int len = RTA_LENGTH(alen);
 	struct rtattr *rta;

- if (NLMSG_ALIGN(n->nlmsg_len) + len > maxlen) {
+ if (NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len) > maxlen) {
fprintf(stderr, "addattr_l ERROR: message exceeded bound of %d\n",maxlen); return -1;
}
@@ -499,7 +499,7 @@
rta->rta_type = type;
rta->rta_len = len;
memcpy(RTA_DATA(rta), data, alen);
- n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + len;
+ n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len);
return 0;
}

@@ -539,7 +539,7 @@
struct rtattr *subrta;
int len = RTA_LENGTH(alen);

- if (RTA_ALIGN(rta->rta_len) + len > maxlen) {
+ if (RTA_ALIGN(rta->rta_len) + RTA_ALIGN(len) > maxlen) {
fprintf(stderr,"rta_addattr_l: Error! max allowed bound %d exceeded\n",maxlen); return -1;
}
@@ -547,7 +547,7 @@
subrta->rta_type = type;
subrta->rta_len = len;
memcpy(RTA_DATA(subrta), data, alen);
- rta->rta_len = NLMSG_ALIGN(rta->rta_len) + len;
+ rta->rta_len = NLMSG_ALIGN(rta->rta_len) + RTA_ALIGN(len);
return 0;
}

_______________________________________________
LARTC mailing list
[email protected]
http://mailman.ds9a.nl/cgi-bin/mailman/listinfo/lartc

#3 lore raw
In reply to Tero Saarni
Quoted 10 lines

From: Thomas Graf <[email protected]>
My patch is right but discovered a quite more serious bug in the generic routing attribute handling. nlmsg_len is not aligned to RTA_ALIGNTO if the data length of the attribute did not have this alignment itself. The fact that the addition of the next attribute fixed this bug automatically by issueing NLMSG_ALIGN(nlmsg_len) + len put a good shadow around it and made it only a problem when the last attribute added was not properly aligned. Patch attached, alternatively one can clone bk://kernel.bkbits.net/tgraf/iproute2-tgr and als get the new fancy multipath bits installed. ;->

Thanks!
That fixed it.

--
Tero

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now!
http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/

_______________________________________________
LARTC mailing list
[email protected]
http://mailman.ds9a.nl/cgi-bin/mailman/listinfo/lartc

#4 lore raw
In reply to Tero Saarni

I 'm having a problem identical to one encountered on this list awhile
back:

Quoted 7 lines

I'm trying to configure dsmark qdisc on 2.6.11.4 user mode linux and tc from iproute2-2.6.11-050314.

I think I have some mismatch in my setup since adding dsmark qdisc fails *unless* I specify "set_tc_index" argument which I believe should

Quoted 6 lines

be optional:

# tc qdisc add dev eth1 handle 1:0 root dsmark indices 8 
RTNETLINK answers: Invalid argument 
Mar 20 13:00:50 user user.debug kernel: dsmark_init(sch a0bb3ae0,[qdisc

a0bb3b60],opt 00000000)

Quoted 7 lines

here the log shows that opt is null, sch_dsmark checks for that and bails out. However running tc with "set_tc_index" goes ok:

# tc qdisc add dev eth1 handle 1:0 root dsmark indices 8 set_tc_index 
Mar 20 13:01:12 user user.debug kernel: dsmark_init(sch a0bb3060,[qdisc

a0bb30e0],opt a038e9d0)

Quoted 7 lines
Mar 20 13:01:12 user user.debug kernel: dsmark_init: qdisc a0bb30e0 
# tc qdisc show dev eth1 
qdisc dsmark 1: indices 0x0008 set_tc_index 
Quoted 6 lines

but then changing the class fails:

# tc class change dev eth1 classid 1:1 dsmark mask 0x0 value 0xb8 
RTNETLINK answers: Invalid argument 
Mar 20 13:02:28 user user.debug kernel: dsmark_get(sch a0bb3060,[qdisc

a0bb30e0],classid 10001)

Quoted 1 line
Mar 20 13:02:28 user user.debug kernel: dsmark_change(sch

a0bb3060,[qdisc a0bb30e0],classid 10001,parent 0),arg 0x2

Quoted 7 lines

Any ideas where I've gone wrong?

Signature · 1 line
Tero 

I've applied the patch to my iproute2 that was suggested as a solution, as well as upgrading to the latest version
(http://developer.osdl.org/dev/iproute2/download/iproute2-2.6.14-051107.
tar.gz
<http://developer.osdl.org/dev/iproute2/download/iproute2-2.6.14-051107.
tar.gz> ) of iproute2 which includes the patch, but always get the following errors:

# tc qdisc add dev eth1 handle 1:0 root dsmark indices 64 RTNETLINK answers: Invalid argument

Changing that to:

# tc qdisc add dev eth1 handle 1:0 root dsmark indices 64 set_tc_index

Works, but following that with produces the same error:

# tc class change dev eth1 classid 1:1 dsmark mask 0x3 value 0x88 RTNETLINK answers: Invalid argument

Is this an iproute2 bug, or user error?

I'm using iproute2 on FC4 2.6.14-1.1653

TIY

Keith Mitchell
CTO
Productivity Associates, Inc.
5625 Ruffin Rd STE 220
San Diego, CA 92123
858-495-3528 (Direct)
858-495-3540 (Fax)

#5 lore raw
In reply to Tero Saarni

K never mind, i'm a dork.

* Edit iproute2/Config to enable Diffserv support:
TC_CONFIG_DIFFSERV=y

________________________________

From: [email protected] [mailto:[email protected]] On Behalf Of Keith Mitchell
Sent: Thursday, January 05, 2006 1:35 PM
To: [email protected]
Subject: [LARTC] Adding dsmark qdisc fails

I 'm having a problem identical to one encountered on this list awhile
back:

Quoted 7 lines

I'm trying to configure dsmark qdisc on 2.6.11.4 user mode linux and tc from iproute2-2.6.11-050314.

I think I have some mismatch in my setup since adding dsmark qdisc fails *unless* I specify "set_tc_index" argument which I believe should

Quoted 6 lines

be optional:

# tc qdisc add dev eth1 handle 1:0 root dsmark indices 8 
RTNETLINK answers: Invalid argument 
Mar 20 13:00:50 user user.debug kernel: dsmark_init(sch a0bb3ae0,[qdisc

a0bb3b60],opt 00000000)

Quoted 7 lines

here the log shows that opt is null, sch_dsmark checks for that and bails out. However running tc with "set_tc_index" goes ok:

# tc qdisc add dev eth1 handle 1:0 root dsmark indices 8 set_tc_index 
Mar 20 13:01:12 user user.debug kernel: dsmark_init(sch a0bb3060,[qdisc

a0bb30e0],opt a038e9d0)

Quoted 7 lines
Mar 20 13:01:12 user user.debug kernel: dsmark_init: qdisc a0bb30e0 
# tc qdisc show dev eth1 
qdisc dsmark 1: indices 0x0008 set_tc_index 
Quoted 6 lines

but then changing the class fails:

# tc class change dev eth1 classid 1:1 dsmark mask 0x0 value 0xb8 
RTNETLINK answers: Invalid argument 
Mar 20 13:02:28 user user.debug kernel: dsmark_get(sch a0bb3060,[qdisc

a0bb30e0],classid 10001)

Quoted 1 line
Mar 20 13:02:28 user user.debug kernel: dsmark_change(sch

a0bb3060,[qdisc a0bb30e0],classid 10001,parent 0),arg 0x2

Quoted 7 lines

Any ideas where I've gone wrong?

Signature · 1 line
Tero 

I've applied the patch to my iproute2 that was suggested as a solution, as well as upgrading to the latest version
(http://developer.osdl.org/dev/iproute2/download/iproute2-2.6.14-051107.
tar.gz
<http://developer.osdl.org/dev/iproute2/download/iproute2-2.6.14-051107.
tar.gz> ) of iproute2 which includes the patch, but always get the following errors:

# tc qdisc add dev eth1 handle 1:0 root dsmark indices 64 RTNETLINK answers: Invalid argument

Changing that to:

# tc qdisc add dev eth1 handle 1:0 root dsmark indices 64 set_tc_index

Works, but following that with produces the same error:

# tc class change dev eth1 classid 1:1 dsmark mask 0x3 value 0x88 RTNETLINK answers: Invalid argument

Is this an iproute2 bug, or user error?

I'm using iproute2 on FC4 2.6.14-1.1653

TIY

Keith Mitchell
CTO
Productivity Associates, Inc.
5625 Ruffin Rd STE 220
San Diego, CA 92123
858-495-3528 (Direct)
858-495-3540 (Fax)

_______________________________________________
LARTC mailing list
[email protected]
http://mailman.ds9a.nl/cgi-bin/mailman/listinfo/lartc