Re: [tcng] tcc->tc comments

Linux Advanced Routing and Traffic Control

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



raptor wrote:
> is there a way so that I can write something like that :

Hmm, looks like a good use for pragmas with tc output ;-)
After applying the attached quick and dirty patch, this

htb (pragma "#the_outer_qdisc") {
    class (rate 10kbps,ceil 20kbps,pragma "#the_first_class") {
        fifo(pragma "#the_inner_qdisc");
    }
} 

yields this:

# the_outer_qdisc
tc qdisc add dev eth0 handle 1:0 root htb
# the_first_class
tc class add dev eth0 parent 1:0 classid 1:1 htb rate 1250bps ceil 2500bps
# the_inner_qdisc
tc qdisc add dev eth0 handle 2:0 parent 1:1 pfifo

Note that you can't include spaces in pragams, but all other
non-blank characters are fine.

> And similar thing for filters/classifiers ?!

Works there too, but only if using "on". When using "if", tcc
may transform the expression quite heavily, and there's no way
for associating output items with input items (in the general
case).

But a better way to do all this is to use tcc's location map
to extract the comments directly from the source, as demonstrated
by the Perl script in the second attachment. 

Input example:

/* this is the comment
   for HTB */
htb {
    // another comment, this
    // time for a class
    class (rate 10kbps,ceil 20kbps) {
        // last but not least, a comment for the FIFO
        fifo;
    }
}

Not that, when invoking com.pl, the name of the input file
must be the last command-line argument.

- Werner

-- 
  _________________________________________________________________________
 / Werner Almesberger, Buenos Aires, Argentina         wa@almesberger.net /
/_http://www.almesberger.net/____________________________________________/
--- tc.c.orig	Thu Sep 26 17:32:47 2002
+++ tc.c	Thu Sep 26 17:37:52 2002
@@ -237,6 +237,18 @@
 
 void tc_pragma(const PARAM *params)
 {
-    if (prm_present(params,&prm_pragma))
-	yywarn("\"pragma\" parameter ignored by \"tc\" target");
+    const DATA_LIST *pragma;
+
+    if (!prm_present(params,&prm_pragma)) return;
+    for (pragma = prm_data(params,&prm_pragma).u.list; pragma;
+      pragma = pragma->next) {
+	const char *s;
+
+	s = pragma->ref->u.string;
+	if (*s != '#') {
+	    yywarn("\"pragma\" parameter ignored by \"tc\" target");
+	    return;
+	}
+	printf("# %s\n",s+1);
+    }
 }
#!/usr/bin/perl

sub emit
{
    return unless $in =~ /\n$_[0] /s;
    ($s = "\n$`") =~ s/\n\d+ /\n/gs;
    return unless
      $s =~ m#/\*\s*(([^*]|\*[^/])*)\*/[^\n]*$|//\s*(([^\n]*\n\s*//)*[^\n]*)$#s;
    ($s = defined $1 ? $1 : $3) =~ s/\n\s*/\n# /sg;
    $s =~ s#\s*//\s*# #;
    print "# $s\n" || die "stdout: $!";
}

open(FILE,$ARGV[$#ARGV]) || die "$ARGV[$#ARGV]: $!";
while (<FILE>) {
    $in .= "$. $_";
}
close FILE;
print "out: $in\n";
open(PIPE,"tcc -l $$.out ".join(" ",@ARGV)."|") || die "tcc: $!";
@out = <PIPE>;
close PIPE;
exit $? if $?;
open(FILE,"$$.out") || die "$$.out: $!";
for (<FILE>) {
    $q{$1} = $2 if /^qdisc [^:]+:(\S+) .* (\d+)$/;
    $c{$1} = $2 if /^class [^:]+:(\S+) .* (\d+)$/;
}
close FILE;
unlink "$$.out" || warn "unlink $$.out: $!";
for (@out) {
    &emit($q{$1}) if /^tc qdisc .* handle (\d+):0/;
    &emit($c{$1}) if /^tc class .* classid (\d+:\d+)/;
    print $_ || die "stdout: $!";
}

[Index of Archives]     [LARTC Home Page]     [Netfilter]     [Netfilter Development]     [Network Development]     [Bugtraq]     [GCC Help]     [Yosemite News]     [Linux Kernel]     [Fedora Users]
  Powered by Linux