Changeset 1482

Show
Ignore:
Timestamp:
07/08/06 15:34:13 (3 years ago)
Author:
aturner
Message:

first pass at adding split by mac
refs #1

Location:
trunk/src
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/Makefile.am

    r1480 r1482  
    6262tcpprep_LDADD = ./common/libcommon.a \ 
    6363                  $(LIBSTRL) @LNETLIB@ @LPCAPLIB@ $(LIBOPTS_LDADD) 
    64 tcpprep_SOURCES = tcpprep_opts.c tcpprep.c tree.c 
     64tcpprep_SOURCES = tcpprep_opts.c tcpprep.c tree.c mac.c 
    6565tcpprep_OBJECTS: tcpprep_opts.h 
    6666tcpprep_opts.h: tcpprep_opts.c 
  • trunk/src/mac.c

    r1462 r1482  
    1 /* $Id:$ */ 
     1/* $Id$ */ 
    22/* Copyright 2004-2005 Aaron Turner  
    33 * All rights reserved. 
     
    108108} 
    109109 
     110/* 
     111 * Figures out if a MAC is listed in a comma delimited 
     112 * string of MAC addresses. 
     113 * returns CACHE_PRIMARY if listed 
     114 * returns CACHE_SECONDARY if not listed 
     115 */ 
     116int 
     117macinstring(const char *macstring, const u_char *mac) 
     118{ 
     119    char *tok, *tempstr, *ourstring; 
     120    u_char *tempmac; 
     121    int len = 6, ret = CACHE_SECONDARY; 
     122     
     123    ourstring = safe_strdup(macstring); 
     124     
     125    tempstr = strtok_r(ourstring, ",", &tok); 
     126    if (strlen(tempstr)) { 
     127       mac2hex(tempstr, tempmac, len); 
     128       if (memcmp(mac, tempmac, len) == 0) { 
     129           ret = CACHE_PRIMARY; 
     130           goto EXIT_MACINSTRING; 
     131       } 
     132    } else { 
     133        goto EXIT_MACINSTRING; 
     134    } 
     135 
     136    while ((tempstr = strtok_r(NULL, ",", &tok)) != NULL) { 
     137       mac2hex(tempstr, tempmac, len); 
     138       if (memcmp(mac, tempmac, len) == 0) { 
     139           ret = CACHE_PRIMARY; 
     140           goto EXIT_MACINSTRING; 
     141       } 
     142    } 
     143 
     144EXIT_MACINSTRING: 
     145    free(ourstring); 
     146    return ret; 
     147} 
    110148 
    111149/* 
  • trunk/src/mac.h

    r1462 r1482  
    1 /* $Id:$ */ 
     1/* $Id$ */ 
    22/* Copyright 2004 Aaron Turner  
    33 * All rights reserved. 
     
    3535void mac2hex(const char *mac, u_char *dst, int len); 
    3636int dualmac2hex(const char *dualmac, u_char *first, u_char *second, int len); 
     37int macinstring(const char *macstring, const u_char *mac); 
    3738 
    3839#endif /* __MAC_H__ */ 
  • trunk/src/tcpprep.c

    r1481 r1482  
    6262#include "lib/sll.h" 
    6363#include "lib/strlcpy.h" 
     64#include "mac.h" 
    6465 
    6566/* 
     
    121122        errx(1, "Error opening file: %s", errbuf); 
    122123 
    123     switch((int)options.pcap) { 
     124    /* make sure we support the DLT type */ 
     125    switch(pcap_datalink(options.pcap)) { 
    124126        case DLT_EN10MB: 
    125127        case DLT_LINUX_SLL: 
     
    129131        default: 
    130132            errx(1, "Unsupported pcap DLT type: 0x%x", pcap_datalink(options.pcap)); 
     133    } 
     134 
     135    /* Can only split based on MAC address for ethernet */ 
     136    if ((pcap_datalink(options.pcap) != DLT_EN10MB) && 
     137        (options.mode == MAC_MODE)) { 
     138        err(1, "MAC mode splitting is only supported by DLT_EN10MB packet captures."); 
    131139    } 
    132140 
     
    285293{ 
    286294    ip_hdr_t *ip_hdr = NULL; 
     295    eth_hdr_t *eth_hdr = NULL; 
    287296    struct pcap_pkthdr pkthdr; 
    288297    const u_char *pktdata = NULL; 
     
    316325            } 
    317326        } 
     327         
     328        eth_hdr = (eth_hdr_t *)pktdata; 
    318329 
    319330        /* get the IP header (if any) */ 
     
    354365            cache_result = add_cache(&options.cachedata, SEND, 
    355366                      check_ip_cidr(options.cidrdata, ip_hdr->ip_src.s_addr)); 
     367            break; 
     368        case MAC_MODE: 
     369            dbg(2, "processing mac mode..."); 
     370            cache_result = add_cache(&options.cachedata, SEND, 
     371                macinstring(options.maclist, (u_char *)eth_hdr->ether_shost)); 
    356372            break; 
    357373        case AUTO_MODE: 
  • trunk/src/tcpprep.h

    r1462 r1482  
    5252    tcpr_cache_t *cachedata; 
    5353    tcpr_cidr_t *cidrdata; 
    54  
     54    char *maclist; 
    5555    tcpr_xX_t xX; 
    5656    tcpr_bpf_t bpf; 
  • trunk/src/tcpprep_opts.def

    r1481 r1482  
    7676    flags-cant  = port; 
    7777    flags-cant  = regex; 
     78        flags-cant      = mac; 
    7879    flag-code   = <<- EOAuto 
    7980     
     
    137138    flags-cant  = port; 
    138139    flags-cant  = regex; 
     140        flags-cant      = mac; 
    139141    flag-code   = <<- EOCidr 
    140142   
     
    162164    flags-cant  = port; 
    163165    flags-cant  = cidr; 
     166        flags-cant      = mac; 
    164167    flag-code   = <<- EORegex 
    165168     
     
    185188    value       = p; 
    186189    descrip     = "Port-split mode"; 
     190        max                     = 1; 
    187191    flags-cant  = auto; 
    188192    flags-cant  = regex; 
    189193    flags-cant  = cidr; 
     194        flags-cant      = mac; 
    190195    flag-code   = <<- EOPort 
    191196     
     
    197202or server based upon the destination port of the header. 
    198203EOText; 
     204}; 
     205 
     206flag = { 
     207        name            = mac; 
     208        value           = e; 
     209        arg-type        = string; 
     210        max                     = 1; 
     211        descrip         = "Source MAC split mode"; 
     212        flags-cant      = auto; 
     213        flags-cant      = regex; 
     214        flags-cant      = cidr; 
     215        flags-cant      = port; 
     216        flag-code       = <<- EOMac 
     217         
     218        options.mode = MAC_MODE; 
     219        options.maclist = safe_strdup(OPT_ARG(MAC)); 
     220         
     221 
     222EOMac; 
     223        doc                     = <<- EOText 
     224Specify a list of MAC addresses to match against the source MAC 
     225of each packet.  Packets matching one of the values are classified 
     226as servers.      
     227EOText; 
     228         
    199229}; 
    200230