Changeset 1949

Show
Ignore:
Timestamp:
01/14/08 10:09:06 (12 months ago)
Author:
aturner
Message:

more fragroute clean up. need to figure out how to parse fragroute rules.
refs #42

Location:
trunk/src
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/fragroute/Makefile.am

    r1942 r1949  
    99libfragroute_a_CFLAGS = -I.. -I../.. @LDNETINC@ 
    1010 
    11 libfragroute_a_LIBS = @LDNETLIB@ 
     11# libfragroute_a_LIBS = @LDNETLIB@ 
    1212 
    1313noinst_HEADERS = bget.h mod.h pkt.h randutil.h fragroute.h argv.h \ 
  • trunk/src/fragroute/fragroute.h

    r1941 r1949  
    44#ifndef __FRAGROUTE_H__ 
    55#define __FRAGROUTE_H__ 
     6 
     7#define FRAGROUTE_ERRBUF_LEN 1024 
    68 
    79/* Fragroute context. */ 
     
    1921//      route_t         *route; 
    2022//      tun_t           *tun; 
    21     char        errbuf[1024]; 
     23    char        errbuf[FRAGROUTE_ERRBUF_LEN]; 
    2224        struct pktq *pktq; /* packet chain */     
    2325}; 
  • trunk/src/fragroute/mod.c

    r1942 r1949  
    8686        TAILQ_INIT(&rules); 
    8787         
     88        /* open the config/script file */ 
    8889        if ((fp = fopen(script, "r")) == NULL) { 
    8990                sprintf(errbuf, "couldn't open %s", script); 
    9091                return (-1); 
    9192        } 
     93         
     94        /* read the file, one line at a time... */ 
    9295        for (i = 1; fgets(buf, sizeof(buf), fp) != NULL; i++) { 
     96             
     97            /* skip comments & blank lines */ 
    9398                if (*buf == '#' || *buf == '\r' || *buf == '\n') 
    9499                        continue; 
    95100                 
     101                /* parse the line into an array */ 
    96102                if ((argc = argv_create(buf, MAX_ARGS, argv)) < 1) { 
    97103                        sprintf(errbuf, "couldn't parse arguments (line %d)", i); 
     
    99105                        break; 
    100106                } 
     107                 
     108                /* check first keyword against modules */ 
    101109                for (m = mods; *m != NULL; m++) { 
    102110                        if (strcasecmp((*m)->name, argv[0]) == 0) 
    103111                                break; 
    104112                } 
     113                 
     114                /* do we have a match? */ 
    105115                if (*m == NULL) { 
    106116                        sprintf(errbuf, "unknown directive '%s' (line %d)", argv[0], i); 
     
    108118                        break; 
    109119                } 
     120                 
     121                /* allocate memory for our rule */ 
    110122                if ((rule = calloc(1, sizeof(*rule))) == NULL) { 
    111123                        sprintf(errbuf, "calloc"); 
     
    115127                rule->mod = *m; 
    116128 
     129        /* pass the remaining args to the rule */ 
    117130                if (rule->mod->open != NULL && 
    118131                    (rule->data = rule->mod->open(argc, argv)) == NULL) { 
     
    122135                        break; 
    123136                } 
     137                /* append the rule to the rule list */ 
    124138                TAILQ_INSERT_TAIL(&rules, rule, next); 
    125139        } 
     140         
     141        /* close the file */ 
    126142        fclose(fp); 
    127143 
     
    133149                } 
    134150                buf[strlen(buf) - 4] = '\0'; 
    135                 warnx("%s", buf); 
     151                sprintf(errbuf, "%s", buf); 
     152        ret = -1; 
    136153        } 
    137154        return (ret); 
  • trunk/src/tcprewrite_opts.def

    r1945 r1949  
    172172flag = { 
    173173    ifdef       = ENABLE_FRAGROUTE; 
    174     name        = frag; 
     174    name        = fragroute; 
    175175    arg-type    = string; 
    176176    max         = 1; 
     
    180180engine.  See the fragroute(8) man page for more details.  Important: 
    181181tcprewrite does not support the delay, echo or print commands.     
     182EOText; 
     183}; 
     184 
     185 
     186flag = { 
     187    ifdef       = ENABLE_FRAGROUTE; 
     188    name        = fragdir; 
     189    arg-type    = string; 
     190    max         = 1; 
     191    descrip     = "Which flows to apply fragroute to"; 
     192    doc         = <<- EOText 
     193Apply the fragroute engine to packets going c2s, s2c or both. 
    182194EOText; 
    183195};