Fast u32 hashing filter generator

Download

prefixtree.c

Description

A small C program that generates very fast u32 hashing filters given a random set of prefixes and destination class ids as input. The resulting filters can be appended to a file containing the htb class definitions to create a complete tc input file.

The program generates a tree of u32 hash tables. The root table contains entries for the first byte in the IPv4 address. Each entry contains hash tables for the second byte, whose entries in turn contain hash tables for the third and so on. Only entries used in the prefixes supplied are generated.

This way, regardless of the IP address, classifying a packet into a class needs a fixed number of operations (the maximum tree depth is 4). At constant traffic levels, increasing the number of prefixes will only increase the used memory. CPU usage should remain fairly the same.

Compile/run instructions


root@br1 [/home/vcalinus]# gcc -o prefixtree prefixtree.c

root@br1 [/home/vcalinus]# ./prefixtree
IPv4 u32 hash filter generator - (C) 2006 Calin Velea
Syntax: prefixtree {prefix.in} {u32filters.out} {interface} {src/dst} [batch]

Arguments

  • {prefix.in} – input file. Contains the list of prefixes and the associated class ids in the following format:

<prefix> <classid>

….


  • {u32filters.out} – output file. Contains the generated u32 hash filters

  • {interface} – interface where the shaping takes place (tc filter add dev {interface} )

  • {src/dst} – indicates whether we are shaping upload or download (affects src/dst and hash offsets in tc statements)
  • [batch] – if specified, will generate an output file acceptable for tc -b

Typical usage example


tc.main.src – base tc file

qdisc add dev eth0 root handle 1: htb default 99 r2q 1
class add dev eth0 parent 1: classid 1:1 htb rate 400000kbit ceil 400000kbit quantum 1536

#default
class add dev eth0 parent 1:1 classid 1:99 htb rate 100kbit ceil 100kbit
qdisc add dev eth0 parent 1:99 handle 99: sfq quantum 1520 perturb 10
# cust1 – class 1:101
class add dev eth0 parent 1:1 classid 1:101 htb rate 10120kbit ceil 10120kbit quantum 1536
qdisc add dev eth0 parent 1:101 handle 101: sfq quantum 1520 perturb 10

# cust2 – class 1:102
class add dev eth0 parent 1:1 classid 1:102 htb rate 20096kbit ceil 20096kbit quantum 1536
qdisc add dev eth0 parent 1:102 handle 102: sfq quantum 1520 perturb 10

# cust3 – class 1:1af
class add dev eth0 parent 1:1 classid 1:1af htb rate 20096kbit ceil 20096kbit quantum 1536
qdisc add dev eth0 parent 1:1af handle 1af: sfq quantum 1520 perturb 10


prefixes.in – input file for prefixtree

68.91.0.0/20     1:101
195.28.184.0/29  1:102
89.165.145.5/32  1:1af


Run it:

root@br1 [/home/vcalinus]# ./prefixtree prefixes.in u32filters.out eth0 src batch
lines parsed: 3
total hashtables: 8

Output file:

root@br1 [/home/vcalinus]# cat u32filters.out

##### Generated with prefixtree v1.0 #####

filter add dev eth0 parent 1:0 prio 5 protocol ip u32
filter add dev eth0 parent 1:0 prio 5 handle 10: protocol ip u32 divisor 256
filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 800:: match ip src 0.0.0.0/0 hashkey mask 0xff000000 at 12 link 10:

## entries for 68.0.0.0/8

filter add dev eth0 parent 1:0 prio 5 handle 11: protocol ip u32 divisor 256
filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 10:44:  match ip src 0.0.0.0/0 hashkey mask 0xff0000 at 12 link 11:

## entries for 68.91.0.0/16

     filter add dev eth0 parent 1:0 prio 5 handle 12: protocol ip u32 divisor 256
     filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 11:5b:  match ip src 0.0.0.0/0 hashkey mask 0xff00 at 12 link 12:

         filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 12:0:  match ip src 0.0.0.0/0 flowid 1:101
         filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 12:1:  match ip src 0.0.0.0/0 flowid 1:101
         filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 12:2:  match ip src 0.0.0.0/0 flowid 1:101
         filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 12:3:  match ip src 0.0.0.0/0 flowid 1:101
         filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 12:4:  match ip src 0.0.0.0/0 flowid 1:101
         filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 12:5:  match ip src 0.0.0.0/0 flowid 1:101
         filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 12:6:  match ip src 0.0.0.0/0 flowid 1:101
         filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 12:7:  match ip src 0.0.0.0/0 flowid 1:101
         filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 12:8:  match ip src 0.0.0.0/0 flowid 1:101
         filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 12:9:  match ip src 0.0.0.0/0 flowid 1:101
         filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 12:a:  match ip src 0.0.0.0/0 flowid 1:101
         filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 12:b:  match ip src 0.0.0.0/0 flowid 1:101
         filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 12:c:  match ip src 0.0.0.0/0 flowid 1:101
         filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 12:d:  match ip src 0.0.0.0/0 flowid 1:101
         filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 12:e:  match ip src 0.0.0.0/0 flowid 1:101
         filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 12:f:  match ip src 0.0.0.0/0 flowid 1:101

## entries for 89.0.0.0/8

filter add dev eth0 parent 1:0 prio 5 handle 16: protocol ip u32 divisor 256
filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 10:59:  match ip src 0.0.0.0/0 hashkey mask 0xff0000 at 12 link 16:

## entries for 89.165.0.0/16

     filter add dev eth0 parent 1:0 prio 5 handle 17: protocol ip u32 divisor 256
     filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 16:a5:  match ip src 0.0.0.0/0 hashkey mask 0xff00 at 12 link 17:

## entries for 89.165.145.0/24

         filter add dev eth0 parent 1:0 prio 5 handle 18: protocol ip u32 divisor 256
         filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 17:91:  match ip src 0.0.0.0/0 hashkey mask 0xff at 12 link 18:

               filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 18:5:  match ip src 0.0.0.0/0 flowid 1:1af

## entries for 195.0.0.0/8

filter add dev eth0 parent 1:0 prio 5 handle 13: protocol ip u32 divisor 256
filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 10:c3:  match ip src 0.0.0.0/0 hashkey mask 0xff0000 at 12 link 13:

## entries for 195.28.0.0/16

     filter add dev eth0 parent 1:0 prio 5 handle 14: protocol ip u32 divisor 256
     filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 13:1c:  match ip src 0.0.0.0/0 hashkey mask 0xff00 at 12 link 14:

## entries for 195.28.184.0/24

         filter add dev eth0 parent 1:0 prio 5 handle 15: protocol ip u32 divisor 256
         filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 14:b8:  match ip src 0.0.0.0/0 hashkey mask 0xff at 12 link 15:

               filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 15:0:  match ip src 0.0.0.0/0 flowid 1:102
               filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 15:1:  match ip src 0.0.0.0/0 flowid 1:102
               filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 15:2:  match ip src 0.0.0.0/0 flowid 1:102
               filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 15:3:  match ip src 0.0.0.0/0 flowid 1:102
               filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 15:4:  match ip src 0.0.0.0/0 flowid 1:102
               filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 15:5:  match ip src 0.0.0.0/0 flowid 1:102
               filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 15:6:  match ip src 0.0.0.0/0 flowid 1:102
               filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 15:7:  match ip src 0.0.0.0/0 flowid 1:102

root@br1 [/home/vcalinus]#

Finishing up

Put classes and filters together:

cat u32filters.out >> tc.main.src

Apply everything:

tc –b < tc.main.src

Repeat the steps above using dst when running prefixtree to shape the download.


Optimizing existing tc files

Suppose you have a tc file which is not using hashing. Classification is done only based on src/dst prefix match (no port or other specific u32 matches are used). You could easily optimize it by separating the classes and filters part, constructing an input file for prefixtree then joining it back with the classes part. You need to write a script to parse the files and extract the prefixes and class ids (from the tc statements).

grep –v "tc filter add" unoptimized_tc.in > classes.out

grep "tc filter add" unoptimized_tc.in > unoptimized_filters.out

./generate_prefixtree_input classes.out unoptimized_filters.out prefixes.in

./prefixtree prefixes.in optimized_filters.out $iface src batch

cat optimized_filters_out >> classes.out

mv classes.out optimized_tc.in

tc –b < optimized_tc.in

Test Results

Real-world testing has shown troughputs of 1300Mbps / 250.000 pps (aggregated in+out)  for a 2.6.20 linux shaping bridge on a quad-core Xeon X3210 (2.13GHz, 8M  L2 cache), 2GBs of RAM using Intel PCI Express Gigabit NICs.  At this traffic level, CPU utilization averages varied between 25 – 50 % for every core.  Almost 8.000 prefixes of various lengths were being shaped, with a roughly equal number of htb classes.

5000 series Xeons with 12MB of L2 cache, running at 3GHz or more should come close to 6-700.000 pps peak performance, saturating several gigabit interfaces.

18 comments to Fast u32 hashing filter generator

  • Sefirah

    Thank you very much.
    (multumesc frumos)

  • Hello!
    Great job. BUt a have a quaestion. Why is there only 0.0.0.0/0 in the result?
    HOw it can be work if there is only 0.0.0.0/0 in the filters?
    Can you explain, please?
    Thank you!

  • If you look carefully at the generated filters, you will see that the lookup is based
    only on the hash table indices (ht xx:y:). After the hastable selections, you hit the last rule
    (the one with flowid). At that point, the src/destination IP range is already decided, and
    match ip src/dst 0.0.0.0/0 is only there because tc filter needs a match on something – you
    can’t write something like
    filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 15:7: flowid 1:102
    becaus tc will complain there is no match.

    The 0.0.0.0/0 match on the intermediate ht selections has the same meaning.

  • Paul

    Why bother with the hash tables. Why not match ip src 89.165.145.0/24 ?

  • If you have 100 customers, each with one /24 and don’t use hash tables, in the worst
    case tc will do 100 lookups to find the destination classid. With this solution, you are
    doing only 4 lookups regardles of the number of customer subnets.

  • todor.lazarov

    Very good.

    And what happens if we have to add one class 1:5 which is a high priority and subject to all in this table.

    example:

    match u8 0×05 0x0f at 0 match u16 0×0000 0xff80 at 2 match ip protocol 6 0xff match u8 0×10 0xff at 33 flowid 1:5

  • Filters with a lower prio parameter should be evaluated first. It should be possible to have both regular filters with a lower prio (evaluated
    first) then hash-based filters with a higher prio.

  • todor.lazarov

    tc filter add dev imq0 protocol ip parent 1:0 prio 5 u32 ht 15:15: match ip src 0.0.0.0/0 hashkey mask 0xff at 12 link 37:
    tc filter add dev imq0 protocol ip parent 1:0 prio 5 u32 ht 37:87: match ip protocol 1 0xff flowid 1:5
    tc filter add dev imq0 protocol ip parent 1:0 prio 5 u32 ht 37:87: match ip protocol 6 0xff match u8 0×05 0x0f at 0 match u16 0×0000
    0xffc0 at 2 match u8 0×10 0xff at 33 flowid 1:6
    tc filter add dev imq0 protocol ip parent 1:0 prio 5 u32 ht 37:87: match ip tos 0×20 0xff flowid 1:474
    tc filter add dev imq0 protocol ip parent 1:0 prio 5 u32 ht 37:87: match ip src 0.0.0.0/0 flowid 1:475
    tc filter add dev imq0 parent 1:0 prio 5 handle 17: protocol ip u32 divisor 256
    tc filter add dev imq0 protocol ip parent 1:0 prio 5 u32 ht 15:66: match ip src 0.0.0.0/0 hashkey mask 0xff at 12 link 17:
    tc filter add dev imq0 protocol ip parent 1:0 prio 5 u32 ht 17:64: match ip protocol 1 0xff flowid 1:5
    tc filter add dev imq0 protocol ip parent 1:0 prio 5 u32 ht 17:64: match ip protocol 6 0xff match u8 0×05 0x0f at 0 match u16 0×0000
    0xffc0 at 2 match u8 0×10 0xff at 33 flowid 1:6
    tc filter add dev imq0 protocol ip parent 1:0 prio 5 u32 ht 17:64: match ip tos 0×20 0xff flowid 1:256
    tc filter add dev imq0 protocol ip parent 1:0 prio 5 u32 ht 17:64: match ip src 0.0.0.0/0 flowid 1:257
    tc filter add dev imq0 protocol ip parent 1:0 prio 5 u32 ht 17:65: match ip protocol 1 0xff flowid 1:5
    tc filter add dev imq0 protocol ip parent 1:0 prio 5 u32 ht 17:65: match ip protocol 6 0xff match u8 0×05 0x0f at 0 match u16 0×0000
    0xffc0 at 2 match u8 0×10 0xff at 33 flowid 1:6
    tc filter add dev imq0 protocol ip parent 1:0 prio 5 u32 ht 17:65: match ip tos 0×20 0xff flowid 1:256
    tc filter add dev imq0 protocol ip parent 1:0 prio 5 u32 ht 17:65: match ip src 0.0.0.0/0 flowid 1:257

    is it possible to do so as 1:5 and 1:6 classes are in one line and depend on all

  • Se poate ca prefixes.in se fie exportate direct din BPG? Cum se face asta? Iar eth0 este interfata spre clienti sau spre WAN?

  • prefixes.in sunt de obicei ip-urile dezagregate ale clientilor, care nu stau in BGP in mod normal. Se pot exporta prefixe
    din bgp cu “vtysh -c sh ip bgp” si parsa output-ul cu un script daca totusi e cazul

    In exemplul de pe site, eth0 e interfata de upload (WAN).

  • how should the program generate_prefixtree_input from the example optimizing existing tc files. look like?
    Thank you for your help.

  • Supposing unoptimized_filter_in looks like:

    filter add dev eth1.61 parent 1: protocol ip prio 2 u32 match ip src 195.28.184.204/30 flowid 1:14
    filter add dev eth1.61 parent 1: protocol ip prio 2 u32 match ip src 195.189.208.0/24 flowid 1:14

    prefixtree.in will look like:

    195.28.184.204/30 1:14
    195.189.208.0/24 1:14

    generate_prefixtree_inpute should parse the filters and extract the prefixes and associated classes to generate an input for prefixtree

  • Tom

    Can it be used for multiple WAN/LAN or have to generate separate input files? I’m testing this solution.

  • You can use it with the same input file and different command line arguments (interface name and src/dst). However, unless you use IMQ to
    aggregate trafic from multiple interfaces into one interface for shaping, using multiple WAN interfaces will give users separate limits
    over each interface instead of aggregated limits.

  • Thanks very much for this program. I did not actually use it for my application, but the concepts you have demonstrated and explained helped me a great deal to develop my own hash filter generator in bash.

  • Remy Mudingay

    Hi Calin,

    thanks for writing the code and sharing it. I needed this for an application I was writing which is almost completed. A colleague of mine has modified it by adding the possibility of specifying the parent instead of the implicit ’1:0′ parent class. I hope others will find it as useful.

    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include

    #define VERSION “iphash 0.9″

    int nodes = 0;
    int dir = 0;
    int lines = 0;
    int batch = 0;
    char intf[255];

    #define DIR_UPLOAD 1
    #define DIR_DOWNLOAD 2

    #define TC_H_MAJ_MASK (0xFFFF0000U)
    #define TC_H_MIN_MASK (0x0000FFFFU)
    #define TC_H_MAJ(h) ((h)&TC_H_MAJ_MASK)
    #define TC_H_MIN(h) ((h)&TC_H_MIN_MASK)
    #define TC_H_MAKE(maj,min) (((maj)&TC_H_MAJ_MASK)|((min)&TC_H_MIN_MASK))

    typedef struct node {

    struct node *children[256];

    unsigned char leafquad[256];
    __u32 leafclass[256];

    int tableid;

    unsigned int match_network;
    int match_mask;
    __u32 classid;

    unsigned char index;
    unsigned char subnum;
    unsigned char childnum;

    int netmask;
    char leaf;
    } *pNode;

    int get_tc_classid (__u32 *h, const char *str)
    {
    __u32 maj, min;
    char *p;

    maj = strtoul(str, &p, 16);
    if (p == str) {
    maj = 0;
    if (*p != ‘:’)
    return -1;
    }
    if (*p == ‘:’) {
    if (maj >= (1<<16))
    return -1;
    maj <= (1<tableid = tableid;
    tmp->match_network = net;
    tmp->match_mask = mask;
    tmp->leaf = 1;
    tmp->classid = classid;
    tmp->netmask = netmask;
    tmp->index = index;

    return tmp;
    }

    void addNode(pNode root, unsigned char b1, unsigned char b2, unsigned char b3, unsigned char b4,
    int mask, int classid)
    {
    static int tableindex = 11;
    int size, i;

    pNode current = root;

    if(mask <= 8) {
    size = 1 << (8 – mask);
    for (i = b1; i leafquad[i] = 1;
    current->leafclass[i] = classid;
    current->subnum++;
    }
    current->leaf = 1;
    return;
    }

    //Level 1
    if(current->children[b1] != NULL)
    current = current->children[b1];
    else {
    int net = (b1 <children[b1] = nodeAlloc(b1, tableindex++, net, 0x00ff0000, classid, 8);
    current->childnum++;
    current->leaf = 0;
    current = current->children[b1];
    }

    if(mask > 8 && mask <= 16) {
    size = 1 << (16 – mask);
    for (i = b2; i leafquad[i] = 1;
    current->leafclass[i] = classid;
    current->subnum++;
    }
    current->leaf = 1;
    return;
    }

    //Level 2
    if(current->children[b2] != NULL)
    current = current->children[b2];
    else {
    int net = (b1 << 24) | (b2 <children[b2] = nodeAlloc(b2, tableindex++, net, 0x0000ff00, classid, 16);
    current->childnum++;
    current->leaf = 0;
    current = current->children[b2];
    }

    if(mask > 16 && mask <= 24) {
    size = 1 << (24 – mask);
    for (i = b3; i leafquad[i] = 1;
    current->leafclass[i] = classid;
    current->subnum++;
    }
    current->leaf = 1;
    return;
    }

    //Level 3
    if(current->children[b3] != NULL)
    current = current->children[b3];
    else {
    int net = (b1 << 24) | (b2 << 16) | (b3 <children[b3] = nodeAlloc (b3, tableindex++, net, 0x000000ff, classid, 24);
    current->childnum++;
    current->leaf = 0;
    current = current->children[b3];
    }

    size = 1 << (32 – mask);
    for (i = b4; i leafquad[i] = 1;
    current->leafclass[i] = classid;
    current->subnum++;
    }
    current->leaf = 1;
    }

    int readTree(pNode root, FILE *in)
    {
    char linebuf[254];
    int b1,b2,b3,b4,m;
    __u32 classid;
    int ret;
    char strclass[256];
    int linecnt = 0;

    bzero(root->children, 256 * sizeof(struct node*));
    root->tableid = 10;
    root->leaf = 0;
    root->match_mask = 0xff000000;
    root->match_network = 0;

    while( fgets(linebuf, 200, in) != NULL) {
    ret = sscanf (linebuf, “%d.%d.%d.%d/%d %s”, &b1, &b2, &b3, &b4, &m, strclass);
    if(ret != 6)
    printf(“Parse error at line %d: %s”, linecnt, linebuf);
    else if ( get_tc_classid (&classid, strclass) < 0 )
    printf ("Invalid classid at line %d: %s", linecnt, linebuf);
    else addNode (root, b1, b2, b3, b4, m, classid);
    linecnt++;
    }

    lines = linecnt;

    return 0;
    }

    void printTree(pNode root)
    {
    int i,j;
    static int level = 0;

    level++;

    for(i = 0;i children[i]) {
    for(j = 0;j children[i]->leaf) {
    printf(“%d —>”,i);
    for(j=0;jchildren[i]->leafquad[j]) printf(” |.%d [%d]“, j, root->children[i]->leafclass[j]);
    printf(” end\n”);
    }
    else printf (“%d \n”,i);

    printTree(root->children[i]);
    }

    level–;
    }

    void writeTree(pNode root, FILE *out)
    {
    int i,j;
    static int level = 0;
    struct in_addr addr;

    level++;

    if(root->childnum == 0) {

    for(i = 0;i leafquad[i]) {
    for(j=0;jtableid,i, (dir == 1) ? “src” : “dst”,
    TC_H_MAJ(root->leafclass[i])>>16, TC_H_MIN(root->leafclass[i]) );
    }

    } else {

    for(i = 0;i children[i]) {
    addr.s_addr = ntohl(root->children[i]->match_network);
    for (j = 0;j children[i]->netmask);
    for (j = 0;j children[i]->tableid);
    for (j = 0;j tableid,i,
    (dir == 1) ? “src” : “dst”, root->children[i]->match_mask,
    (dir == 1) ? 12 : 16, root->children[i]->tableid);

    writeTree(root->children[i], out);
    }

    if(root->subnum > 0) {
    for(i = 0;i leafquad[i]) {
    for(j = 0;j tableid, i, (dir == 1) ? “src” : “dst”,
    TC_H_MAJ(root->leafclass[i])>>16, TC_H_MIN(root->leafclass[i]) );
    }
    }
    }

    level–;
    }

    void writeFilters(pNode root, FILE *out)
    {

    fprintf(out, “##### Generated with %s #####\n\n”, VERSION);

    fprintf(out, “%sfilter add dev %s parent 1:0 prio 5 protocol ip u32\n”, batch ? “”:”tc ” ,intf);
    fprintf(out, “%sfilter add dev %s parent 1:0 prio 5 handle 10: protocol ip u32 divisor 256\n”, batch ? “”:”tc “, intf);

    fprintf(out, “%sfilter add dev %s protocol ip parent 1:0 prio 5 u32 ht 800:: ” \
    “match ip %s 0.0.0.0/0 hashkey mask 0xff000000 at %d link 10: \n\n”, batch ? “”:”tc “, intf,
    (dir == 1) ? “src” : “dst”, (dir == 1) ? 12 : 16 );

    writeTree(root, out);
    }

    int main (int argc, char **argv)
    {
    FILE *in, *out;

    struct node root;
    bzero(&root, sizeof(struct node));

    if(argc < 5) {
    printf("IPv4 u32 hash filter generator \n\n");
    printf("Syntax: hashtable_gen {prefix.in} {u32filters.out} {interface} {src/dst} [batch]\n\n");
    return 1;
    }

    if (argc == 6)
    if(!strcmp(argv[5], "batch"))
    batch = 1;

    if(!strcmp(argv[4], "src"))
    dir = DIR_UPLOAD;
    else if(!strcmp(argv[4], "dst"))
    dir = DIR_DOWNLOAD;
    else {
    printf("Specify src or dst on the command line!\n");
    return 1;
    }

    strncpy(intf, argv[3], 255);

    in = fopen(argv[1],"r");
    out = fopen(argv[2],"w");

    if(in == NULL) {
    printf("Error opening: %s !\n", argv[1]);
    return 1;
    }

    if(out == NULL) {
    printf("Error opening: %s !\n", argv[2]);
    return 1;
    }

    readTree (&root, in);
    writeFilters (&root, out);

    printf("lines parsed: %d\n", lines);
    printf("total hashtables: %d\n", nodes);

    return 0;
    }

  • Dyr

    Would be somebody so kind to explain, what should I do, if I have 3 ip pools /16 (10.52.0.0/16, 10.53.0.0/16 and 10.54.0.0/16) with /29 per customer so that I want to shape these customers? Something like that or there is even more optimized way?
    ##### Generated with prefixtree v1.0 #####

    filter add dev eth0 parent 1:0 prio 5 protocol ip u32
    filter add dev eth0 parent 1:0 prio 5 handle 10: protocol ip u32 divisor 256
    filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 800:: match ip src 0.0.0.0/0 hashkey mask 0xff000000 at 12 link 10:

    ## entries for 10.0.0.0/8

    filter add dev eth0 parent 1:0 prio 5 handle 11: protocol ip u32 divisor 256
    filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 10:a: match ip src 0.0.0.0/0 hashkey mask 0xff0000 at 12 link 11:

    filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 11:34: match ip src 0.0.0.0/0 flowid 1:34
    filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 11:35: match ip src 0.0.0.0/0 flowid 1:35
    filter add dev eth0 protocol ip parent 1:0 prio 5 u32 ht 11:36: match ip src 0.0.0.0/0 flowid 1:36

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>