Changeset 1841

Show
Ignore:
Timestamp:
04/25/07 20:43:14 (21 months ago)
Author:
aturner
Message:

add support for returning src/dst mac addresses for each plugin
refs #166

Location:
trunk/src/tcpedit
Files:
21 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/tcpedit/plugins/dlt_en10mb/en10mb.c

    r1829 r1841  
    1 /* $Id:$ */ 
     1/* $Id$ */ 
    22 
    33/* 
     
    9191    plugin->plugin_get_layer3 = dlt_en10mb_get_layer3; 
    9292    plugin->plugin_merge_layer3 = dlt_en10mb_merge_layer3; 
    93  
     93    plugin->plugin_get_mac = dlt_en10mb_get_mac; 
     94     
    9495    /* add it to the available plugin list */ 
    9596    return tcpedit_dlt_addplugin(ctx, plugin); 
     
    342343     
    343344    int newl2len; 
    344     u_char tmpbuff[MAXPACKET]; 
    345345 
    346346    assert(ctx); 
     
    567567} 
    568568 
     569/* 
     570 * return a static pointer to the source/destination MAC address 
     571 * return NULL on error/address doesn't exist 
     572 */     
     573u_char * 
     574dlt_en10mb_get_mac(tcpeditdlt_t *ctx, tcpeditdlt_mac_type_t mac, const u_char *packet, const int pktlen) 
     575{ 
     576    assert(ctx); 
     577    assert(packet); 
     578    assert(pktlen); 
     579 
     580    /* FIXME: return a ptr to the source or dest mac address. */ 
     581    switch(mac) { 
     582    case SRC_MAC: 
     583        memcpy(ctx->srcmac, &packet[6], ETHER_ADDR_LEN); 
     584        return(ctx->srcmac); 
     585        break; 
     586         
     587    case DST_MAC: 
     588        memcpy(ctx->dstmac, packet, ETHER_ADDR_LEN); 
     589        return(ctx->dstmac); 
     590        break; 
     591         
     592    default: 
     593        errx(1, "Invalid tcpeditdlt_mac_type_t: %d", mac); 
     594    } 
     595    return(NULL); 
     596} 
     597 
    569598/*  
    570599 * return the length of the L2 header of the current packet 
  • trunk/src/tcpedit/plugins/dlt_en10mb/en10mb.h

    r1830 r1841  
    1 /* $Id:$ */ 
     1/* $Id$ */ 
    22 
    33/* 
     
    4747u_char *dlt_en10mb_merge_layer3(tcpeditdlt_t *ctx, u_char *packet, const int pktlen, u_char *l3data); 
    4848int dlt_en10mb_l2len(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen); 
    49  
     49u_char *dlt_en10mb_get_mac(tcpeditdlt_t *ctx, tcpeditdlt_mac_type_t mac, const u_char *packet, const int pktlen); 
    5050 
    5151tcpeditdlt_l2addr_type_t dlt_en10mb_l2addr_type(void); 
  • trunk/src/tcpedit/plugins/dlt_hdlc/hdlc.c

    r1830 r1841  
    1 /* $Id:$ */ 
     1/* $Id$ */ 
    22 
    33/* 
     
    8989    plugin->plugin_get_layer3 = dlt_hdlc_get_layer3; 
    9090    plugin->plugin_merge_layer3 = dlt_hdlc_merge_layer3; 
    91  
     91    plugin->plugin_get_mac = dlt_hdlc_get_mac; 
     92     
    9293    /* add it to the available plugin list */ 
    9394    return tcpedit_dlt_addplugin(ctx, plugin); 
     
    354355} 
    355356 
     357/* 
     358 * return a static pointer to the source/destination MAC address 
     359 * return NULL on error/address doesn't exist 
     360 */     
     361u_char * 
     362dlt_hdlc_get_mac(tcpeditdlt_t *ctx, tcpeditdlt_mac_type_t mac, const u_char *packet, const int pktlen) 
     363{ 
     364    assert(ctx); 
     365    assert(packet); 
     366    assert(pktlen); 
     367 
     368    /* FIXME: return a ptr to the source or dest mac address. */ 
     369    switch(mac) { 
     370    case SRC_MAC: 
     371        return(NULL); 
     372        break; 
     373         
     374    case DST_MAC: 
     375        memcpy(ctx->dstmac, packet, 2); 
     376        return(ctx->dstmac); 
     377        break; 
     378         
     379    default: 
     380        errx(1, "Invalid tcpeditdlt_mac_type_t: %d", mac); 
     381    } 
     382    return(NULL); 
     383} 
    356384 
    357385tcpeditdlt_l2addr_type_t  
  • trunk/src/tcpedit/plugins/dlt_hdlc/hdlc.h

    r1830 r1841  
    1 /* $Id:$ */ 
     1/* $Id$ */ 
    22 
    33/* 
     
    4848tcpeditdlt_l2addr_type_t dlt_hdlc_l2addr_type(void); 
    4949int dlt_hdlc_l2len(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen); 
     50u_char *dlt_hdlc_get_mac(tcpeditdlt_t *ctx, tcpeditdlt_mac_type_t mac, const u_char *packet, const int pktlen); 
    5051 
    5152/* 
    52  * FIXME: structure to hold any data parsed from the packet by the decoder. 
     53 * structure to hold any data parsed from the packet by the decoder. 
    5354 * Example: Ethernet VLAN tag info 
    5455 */ 
  • trunk/src/tcpedit/plugins/dlt_ieee80211/ieee80211.c

    r1840 r1841  
    4848 */ 
    4949static char dlt_name[] = "ieee80211"; 
    50 static char dlt_prefix[] = "ieee802_11"; 
     50__attribute__((unused)) static char dlt_prefix[] = "ieee802_11"; 
    5151static u_int16_t dlt_value = DLT_IEEE802_11; 
    5252 
     
    9595    plugin->plugin_get_layer3 = dlt_ieee80211_get_layer3; 
    9696    plugin->plugin_merge_layer3 = dlt_ieee80211_merge_layer3; 
     97    plugin->plugin_get_mac = dlt_ieee80211_get_mac; 
    9798 
    9899    /* add it to the available plugin list */ 
     
    220221 */ 
    221222int  
    222 dlt_ieee80211_encode(tcpeditdlt_t *ctx, u_char **packet_ex, int pktlen, tcpr_dir_t dir) 
     223dlt_ieee80211_encode(tcpeditdlt_t *ctx, u_char **packet_ex, int pktlen, __attribute__((unused)) tcpr_dir_t dir) 
    223224{ 
    224225    u_char *packet; 
    225226    assert(ctx); 
    226227    assert(packet_ex); 
     228    assert(pktlen); 
    227229     
    228230    packet = *packet_ex; 
     
    341343} 
    342344 
     345/* 
     346 * return a static pointer to the source/destination MAC address 
     347 * return NULL on error/address doesn't exist 
     348 */     
     349u_char * 
     350dlt_ieee80211_get_mac(tcpeditdlt_t *ctx, tcpeditdlt_mac_type_t mac, const u_char *packet, const int pktlen) 
     351{ 
     352    assert(ctx); 
     353    assert(packet); 
     354    assert(pktlen); 
     355    char *macaddr; 
     356     
     357    switch(mac) { 
     358    case SRC_MAC: 
     359        macaddr = ieee80211_get_src(packet); 
     360        memcpy(ctx->srcmac, macaddr, ETHER_ADDR_LEN); 
     361        return(ctx->srcmac); 
     362        break; 
     363         
     364    case DST_MAC: 
     365        macaddr = ieee80211_get_dst(packet); 
     366        memcpy(ctx->dstmac, macaddr, ETHER_ADDR_LEN); 
     367        return(ctx->dstmac); 
     368        break; 
     369         
     370    default: 
     371        errx(1, "Invalid tcpeditdlt_mac_type_t: %d", mac); 
     372    } 
     373    return(NULL); 
     374} 
     375 
    343376 
    344377tcpeditdlt_l2addr_type_t  
  • trunk/src/tcpedit/plugins/dlt_ieee80211/ieee80211.h

    r1838 r1841  
    4848tcpeditdlt_l2addr_type_t dlt_ieee80211_l2addr_type(void); 
    4949int dlt_ieee80211_l2len(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen); 
     50u_char *dlt_ieee80211_get_mac(tcpeditdlt_t *ctx, tcpeditdlt_mac_type_t mac, const u_char *packet, const int pktlen); 
    5051 
    5152/* 802.11 packet header w/ 3 addresses (non-WDS) */ 
  • trunk/src/tcpedit/plugins/dlt_linuxsll/linuxsll.c

    r1830 r1841  
    1 /* $Id:$ */ 
     1/* $Id$ */ 
    22 
    33/* 
     
    9090    plugin->plugin_get_layer3 = dlt_linuxsll_get_layer3; 
    9191    plugin->plugin_merge_layer3 = dlt_linuxsll_merge_layer3; 
    92  
     92    plugin->plugin_get_mac = dlt_linuxsll_get_mac; 
     93     
    9394    /* add it to the available plugin list */ 
    9495    return tcpedit_dlt_addplugin(ctx, plugin); 
     
    291292} 
    292293 
     294/* 
     295 * return a static pointer to the source/destination MAC address 
     296 * return NULL on error/address doesn't exist 
     297 */     
     298u_char * 
     299dlt_linuxsll_get_mac(tcpeditdlt_t *ctx, tcpeditdlt_mac_type_t mac, const u_char *packet, const int pktlen) 
     300{ 
     301    assert(ctx); 
     302    assert(packet); 
     303    assert(pktlen); 
     304 
     305    /* FIXME: return a ptr to the source or dest mac address. */ 
     306    switch(mac) { 
     307    case SRC_MAC: 
     308        memcpy(ctx->srcmac, &packet[6], 8); /* linuxssl defines the src mac field to be 8 bytes, not 6 */ 
     309        return(ctx->srcmac); 
     310        break; 
     311         
     312    case DST_MAC: 
     313        return(NULL); 
     314        break; 
     315         
     316    default: 
     317        errx(1, "Invalid tcpeditdlt_mac_type_t: %d", mac); 
     318    } 
     319    return(NULL); 
     320} 
    293321 
    294322tcpeditdlt_l2addr_type_t  
  • trunk/src/tcpedit/plugins/dlt_linuxsll/linuxsll.h

    r1830 r1841  
    1 /* $Id:$ */ 
     1/* $Id$ */ 
    22 
    33/* 
     
    4848tcpeditdlt_l2addr_type_t dlt_linuxsll_l2addr_type(void); 
    4949int dlt_linuxsll_l2len(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen); 
     50u_char *dlt_linuxsll_get_mac(tcpeditdlt_t *ctx, tcpeditdlt_mac_type_t mac, const u_char *packet, const int pktlen); 
    5051 
    5152/* 
    52  * FIXME: structure to hold any data parsed from the packet by the decoder. 
     53 * structure to hold any data parsed from the packet by the decoder. 
    5354 * Example: Ethernet VLAN tag info 
    5455 */ 
  • trunk/src/tcpedit/plugins/dlt_loop/loop.c

    r1830 r1841  
    1 /* $Id:$ */ 
     1/* $Id$ */ 
    22 
    33/* 
     
    7373    plugin = tcpedit_dlt_newplugin(); 
    7474 
    75     /* FIXME: set what we provide & require */ 
     75    /* set what we provide & require */ 
    7676    plugin->provides += PLUGIN_MASK_PROTO; 
    7777    plugin->requires += 0; 
     
    9494    plugin->plugin_get_layer3 = dlt_null_get_layer3; 
    9595    plugin->plugin_merge_layer3 = dlt_null_merge_layer3; 
    96  
     96    plugin->plugin_get_mac = dlt_null_get_mac; 
     97     
    9798    /* add it to the available plugin list */ 
    9899    return tcpedit_dlt_addplugin(ctx, plugin); 
  • trunk/src/tcpedit/plugins/dlt_null/null.c

    r1830 r1841  
    1 /* $Id:$ */ 
     1/* $Id$ */ 
    22 
    33/* 
     
    313313} 
    314314 
     315/* 
     316 * return a static pointer to the source/destination MAC address 
     317 * return NULL on error/address doesn't exist 
     318 */     
     319u_char * 
     320dlt_null_get_mac(tcpeditdlt_t *ctx, __attribute__((unused)) tcpeditdlt_mac_type_t mac, const u_char *packet, const int pktlen) 
     321{ 
     322    assert(ctx); 
     323    assert(packet); 
     324    assert(pktlen); 
     325 
     326    return(NULL); 
     327 
     328} 
    315329 
    316330tcpeditdlt_l2addr_type_t  
  • trunk/src/tcpedit/plugins/dlt_null/null.h

    r1830 r1841  
    1 /* $Id:$ */ 
     1/* $Id$ */ 
    22 
    33/* 
     
    4848tcpeditdlt_l2addr_type_t dlt_null_l2addr_type(void); 
    4949int dlt_null_l2len(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen); 
     50u_char *dlt_null_get_mac(tcpeditdlt_t *ctx, tcpeditdlt_mac_type_t mac, const u_char *packet, const int pktlen); 
    5051 
    5152/* 
    52  * FIXME: structure to hold any data parsed from the packet by the decoder. 
     53 * structure to hold any data parsed from the packet by the decoder. 
    5354 * Example: Ethernet VLAN tag info 
    5455 */ 
  • trunk/src/tcpedit/plugins/dlt_plugins-int.h

    r1802 r1841  
    7575typedef enum tcpeditdlt_l2addr_type_e tcpeditdlt_l2addr_type_t; 
    7676 
     77/* src or dst mac */ 
     78enum tcpeditdlt_mac_type_e { 
     79    SRC_MAC, 
     80    DST_MAC 
     81}; 
     82typedef enum tcpeditdlt_mac_type_e tcpeditdlt_mac_type_t; 
     83 
     84/* MAC address buffer length */ 
     85#define MAX_MAC_LEN 10 
     86 
    7787/*  
    7888 * Each plugin must fill this out so that we know what function 
     
    92102    int (*plugin_proto)(tcpeditdlt_t *, const u_char *, const int); 
    93103    int (*plugin_l2len)(tcpeditdlt_t *, const u_char *, const int); 
    94     u_char *(*plugin_get_layer3)(tcpeditdlt_t *, u_char *, const int); 
     104    u_char *(*plugin_get_layer3)(tcpeditdlt_t *,  u_char *, const int); 
    95105    u_char *(*plugin_merge_layer3)(tcpeditdlt_t *, u_char *, const int, u_char *); 
    96106    tcpeditdlt_l2addr_type_t (*plugin_l2addr_type)(void); 
     107    u_char *(*plugin_get_mac)(tcpeditdlt_t *, tcpeditdlt_mac_type_t, const u_char *, const int); 
    97108    void *config; /* user configuration data for the encoder */ 
    98109     
     
    132143    u_int16_t proto;                        /* layer 3 proto type?? */ 
    133144    void *decoded_extra;                    /* any extra L2 data from decoder like VLAN tags */ 
     145    u_char srcmac[MAX_MAC_LEN];             /* buffers to store the src & dst MAC */ 
     146    u_char dstmac[MAX_MAC_LEN]; 
    134147}; 
    135148 
  • trunk/src/tcpedit/plugins/dlt_plugins.h

    r1757 r1841  
    6060 * process the given packet, by calling decode & encode 
    6161 */ 
    62 int tcpedit_dlt_process(tcpeditdlt_t *ctx, u_char *packet,  
    63     int pktlen, tcpr_dir_t direction); 
     62int tcpedit_dlt_process(tcpeditdlt_t *ctx, u_char *packet, int pktlen, tcpr_dir_t direction); 
    6463 
    6564/* 
     
    7978 
    8079 
    81  
    8280int tcpedit_dlt_src(tcpeditdlt_t *ctx); 
    8381int tcpedit_dlt_dst(tcpeditdlt_t *ctx); 
  • trunk/src/tcpedit/plugins/dlt_raw/raw.c

    r1830 r1841  
    1 /* $Id:$ */ 
     1/* $Id$ */ 
    22 
    33/* 
     
    9393    plugin->plugin_get_layer3 = dlt_raw_get_layer3; 
    9494    plugin->plugin_merge_layer3 = dlt_raw_merge_layer3; 
    95  
     95    plugin->plugin_get_mac = dlt_raw_get_mac; 
     96     
    9697    /* add it to the available plugin list */ 
    9798    return tcpedit_dlt_addplugin(ctx, plugin); 
     
    293294} 
    294295 
     296/* 
     297 * return a static pointer to the source/destination MAC address 
     298 * return NULL on error/address doesn't exist 
     299 */     
     300u_char * 
     301dlt_raw_get_mac(tcpeditdlt_t *ctx, __attribute__((unused)) tcpeditdlt_mac_type_t mac, const u_char *packet, const int pktlen) 
     302{ 
     303    assert(ctx); 
     304    assert(packet); 
     305    assert(pktlen); 
     306 
     307    return(NULL); 
     308} 
    295309 
    296310tcpeditdlt_l2addr_type_t  
  • trunk/src/tcpedit/plugins/dlt_raw/raw.h

    r1830 r1841  
    1 /* $Id:$ */ 
     1/* $Id$ */ 
    22 
    33/* 
     
    4848tcpeditdlt_l2addr_type_t dlt_raw_l2addr_type(void); 
    4949int dlt_raw_l2len(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen); 
     50u_char *dlt_raw_get_mac(tcpeditdlt_t *ctx, tcpeditdlt_mac_type_t mac, const u_char *packet, const int pktlen); 
    5051 
    5152/* 
    52  * FIXME: structure to hold any data parsed from the packet by the decoder. 
     53 * structure to hold any data parsed from the packet by the decoder. 
    5354 * Example: Ethernet VLAN tag info 
    5455 */ 
  • trunk/src/tcpedit/plugins/dlt_template/plugin.c

    r1830 r1841  
    1 /* $Id:$ */ 
     1/* $Id$ */ 
    22 
    33/* 
     
    7474    plugin->dlt = dlt_value; 
    7575 
     76    /* offset to src/dst mac's.  must be >= 0 for a valid value or -1 for non-existent */ 
     77    plugin->srcmac_offset = -1; 
     78    plugin->dstmac_offset = -1; 
     79 
     80 
    7681    /* set the prefix name of our plugin.  This is also used as the prefix for our options */ 
    7782    plugin->name = safe_strdup(dlt_name); 
     
    9196    plugin->plugin_get_layer3 = dlt_%{plugin}_get_layer3; 
    9297    plugin->plugin_merge_layer3 = dlt_%{plugin}_merge_layer3; 
     98    plugin->plugin_get_mac = dlt_%{plugin}_get_mac; 
    9399 
    94100    /* add it to the available plugin list */ 
     
    277283} 
    278284 
     285/* 
     286 * return a static pointer to the source/destination MAC address 
     287 * return NULL on error/address doesn't exist 
     288 */     
     289u_char * 
     290dlt_%{plugin}_get_mac(tcpeditdlt_t *ctx, tcpeditdlt_mac_type_t mac, const u_char *packet, const int pktlen) 
     291{ 
     292    assert(ctx); 
     293    assert(packet); 
     294    assert(pktlen); 
     295 
     296    /* FIXME: return a ptr to the source or dest mac address. */ 
     297    switch(mac) { 
     298    case SRC_MAC: 
     299        memcpy(ctx->srcmac, packet, length); 
     300        return(ctx->srcmac); 
     301        break; 
     302         
     303    case DST_MAC: 
     304        memcpy(ctx->dstmac, packet, length); 
     305        return(ctx->dstmac); 
     306        break; 
     307         
     308    default: 
     309        errx(1, "Invalid tcpeditdlt_mac_type_t: %d", mac); 
     310    } 
     311} 
     312 
     313 
    279314/*  
    280315 * return the length of the L2 header of the current packet 
  • trunk/src/tcpedit/plugins/dlt_template/plugin.h

    r1830 r1841  
    1 /* $Id:$ */ 
     1/* $Id$ */ 
    22 
    33/* 
     
    4848tcpeditdlt_l2addr_type_t dlt_%{plugin}_l2addr_type(void); 
    4949int dlt_%{plugin}_l2len(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen); 
     50u_char *dlt_%{plugin}_get_mac(tcpeditdlt_t *ctx, tcpeditdlt_mac_type_t mac, const u_char *packet, const int pktlen); 
    5051 
    5152/* 
  • trunk/src/tcpedit/plugins/dlt_user/user.c

    r1830 r1841  
    1 /* $Id:$ */ 
     1/* $Id$ */ 
    22 
    33/* 
     
    8989    plugin->plugin_get_layer3 = dlt_user_get_layer3; 
    9090    plugin->plugin_merge_layer3 = dlt_user_merge_layer3; 
    91  
     91    plugin->plugin_get_mac = dlt_user_get_mac; 
     92     
    9293    /* add it to the available plugin list */ 
    9394    return tcpedit_dlt_addplugin(ctx, plugin); 
     
    340341} 
    341342 
     343/* 
     344 * return a static pointer to the source/destination MAC address 
     345 * return NULL on error/address doesn't exist 
     346 */     
     347u_char * 
     348dlt_user_get_mac(tcpeditdlt_t *ctx, __attribute__((unused)) tcpeditdlt_mac_type_t mac, const u_char *packet, const int pktlen) 
     349{ 
     350    assert(ctx); 
     351    assert(packet); 
     352    assert(pktlen); 
     353 
     354    /* we don't know the format of USER DLT, hence always return NULL */ 
     355    return(NULL); 
     356} 
    342357 
    343358tcpeditdlt_l2addr_type_t  
  • trunk/src/tcpedit/plugins/dlt_user/user.h

    r1830 r1841  
    1 /* $Id:$ */ 
     1/* $Id$ */ 
    22 
    33/* 
     
    4848tcpeditdlt_l2addr_type_t dlt_user_l2addr_type(void); 
    4949int dlt_user_l2len(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen); 
     50u_char *dlt_user_get_mac(tcpeditdlt_t *ctx, tcpeditdlt_mac_type_t mac, const u_char *packet, const int pktlen); 
    5051 
    5152/* extra function called directly by tcpedit_dlt_output_dlt() */ 
  • trunk/src/tcpedit/tcpedit.c

    r1836 r1841  
    396396 
    397397 
    398 u_char * 
     398const u_char * 
    399399tcpedit_l3data(tcpedit_t *tcpedit, tcpedit_coder_t code, u_char *packet, const int pktlen) 
    400400{ 
     
    409409 
    410410int  
     411tcpedit_l2len(tcpedit_t *tcpedit, tcpedit_coder_t code, u_char *packet, const int pktlen) 
     412{ 
     413    int result = 0; 
     414    if (code == BEFORE_PROCESS) { 
     415        result = tcpedit_dlt_l2len(tcpedit->dlt_ctx, tcpedit->dlt_ctx->decoder->dlt, packet, pktlen); 
     416    } else { 
     417        result = tcpedit_dlt_l2len(tcpedit->dlt_ctx, tcpedit->dlt_ctx->encoder->dlt, packet, pktlen); 
     418    } 
     419    return result; 
     420} 
     421 
     422int  
    411423tcpedit_l3proto(tcpedit_t *tcpedit, tcpedit_coder_t code, const u_char *packet, const int pktlen) 
    412424{ 
     
    420432} 
    421433