Changeset e2aebe7


Ignore:
Timestamp:
05/29/06 11:27:11 (15 years ago)
Author:
Perry Lorier <perry@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
f208f92
Parents:
ad96d00
Message:

Change the API for filters to

trace_create_filter
trace_apply_filter
trace_destroy_filter

Also, cleanup bitfield issues with msvc/gcc

Location:
lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • lib/dagformat.h

    rbf66333 re2aebe7  
    4646/** Flags */
    4747typedef struct flags {
    48         uint8_t   iface:2;
    49         uint8_t   vlen:1;
    50         uint8_t   trunc:1;
    51         uint8_t   rxerror:1;
    52         uint8_t   dserror:1;
    53         uint8_t  pad:2;
     48        LT_BITFIELD8  iface:2;          /**< Interface (direction) */
     49        LT_BITFIELD8  vlen:1;   
     50        LT_BITFIELD8  trunc:1;          /**< Trunacted */
     51        LT_BITFIELD8  rxerror:1;        /**< RX Error in this packet/before
     52                                          * this packet
     53                                          */
     54        LT_BITFIELD8  dserror:1;        /**< Data stream error */
     55        LT_BITFIELD8  pad:2;            /**< Unused */
    5456} PACKED flags_t;
    5557
  • lib/format_helper.c

    r64444f9 re2aebe7  
    140140        /* TODO: finalise packet */
    141141        *packet = *trace->event.packet;
    142         trace_destroy_packet(&trace->event.packet);
     142        trace_destroy_packet(trace->event.packet);
     143        trace->event.packet = NULL;
    143144
    144145        event.type = TRACE_EVENT_PACKET;
  • lib/libtrace.h.in

    r01459e4 re2aebe7  
    6969    typedef unsigned    __int32 uint32_t;
    7070    typedef unsigned    __int64 uint64_t;
    71         #ifdef BUILDING_DLL
    72                 #define DLLEXPORT __declspec(dllexport)
    73         #else
    74                 #define DLLEXPORT __declspec(dllimport)
    75         #endif
     71    #ifdef BUILDING_DLL
     72        #define DLLEXPORT __declspec(dllexport)
     73    #else
     74        #define DLLEXPORT __declspec(dllimport)
     75    #endif
     76    #define DLLLOCAL
     77    /* Windows pads bitfields out to to the size of their parent type
     78     * however gcc warns that this doesn't meet with the iso C specification
     79     * so produces warnings for this behaviour.  sigh.
     80     */
     81    #define LT_BITFIELD8        uint8_t
     82    #define LT_BITFIELD16       uint16_t
     83    #define LT_BITFIELD32       uint32_t
     84    #define LT_BITFIELD32       uint64_t
     85#else
     86    #ifdef HAVE_GCCVISIBILITYPATCH
     87        #define DLLEXPORT __attribute__ (visibility("default"))
     88        #define DLLLOCAL __attribute__ (visibility("hidden"))
     89    #else
     90        #define DLLEXPORT
    7691        #define DLLLOCAL
    77 #else
    78         #ifdef HAVE_GCCVISIBILITYPATCH
    79                 #define DLLEXPORT __attribute__ (visibility("default"))
    80                 #define DLLLOCAL __attribute__ (visibility("hidden"))
    81         #else
    82                 #define DLLEXPORT
    83                 #define DLLLOCAL
    84         #endif
     92    #endif
     93    /* GCC warns if the bitfield type is not "unsigned int", however windows
     94     * generates incorrect code for this (see above), so we define these
     95     * macros.  How Hidious.  So much for C's portability.
     96     */
     97    #define LT_BITFIELD8        unsigned int
     98    #define LT_BITFIELD16       unsigned int
     99    #define LT_BITFIELD32       unsigned int
     100    #define LT_BITFIELD32       unsigned int
    85101#endif
    86102
     
    217233       TRACE_TYPE_POS,
    218234       TRACE_TYPE_80211_PRISM = 12,
    219        TRACE_TYPE_DUCK,                 /**< Pseudo link layer for DUCK packets */
     235       TRACE_TYPE_DUCK                  /**< Pseudo link layer for DUCK packets */
    220236     } libtrace_linktype_t;
    221237
     
    246262{
    247263#if BYTE_ORDER == LITTLE_ENDIAN
    248     uint8_t ip_hl:4;            /**< Header Length */
    249     uint8_t ip_v:4;             /**< Version */
     264    LT_BITFIELD8 ip_hl:4;               /**< Header Length */
     265    LT_BITFIELD8 ip_v:4;                /**< Version */
    250266#elif BYTE_ORDER == BIG_ENDIAN
    251     uint8_t ip_v:4;             /**< Version */
    252     uint8_t ip_hl:4;            /**< Header Length */
     267    LT_BITFIELD8 ip_v:4;                /**< Version */
     268    LT_BITFIELD8 ip_hl:4;               /**< Header Length */
    253269#else
    254270#   error "Adjust your <bits/endian.h> defines"
     
    258274    int16_t  ip_id;                     /**< Identification */
    259275#if BYTE_ORDER == LITTLE_ENDIAN
    260     uint16_t ip_off:12;         /**< Fragment Offset */
    261     uint16_t ip_mf:1;           /**< More Fragments Flag */
    262     uint16_t ip_df:1;           /**< Dont Fragment Flag */
    263     uint16_t ip_rf:1;           /**< Reserved Fragment Flag */
     276    LT_BITFIELD16 ip_off:12;            /**< Fragment Offset */
     277    LT_BITFIELD16 ip_mf:1;              /**< More Fragments Flag */
     278    LT_BITFIELD16 ip_df:1;              /**< Dont Fragment Flag */
     279    LT_BITFIELD16 ip_rf:1;              /**< Reserved Fragment Flag */
    264280#elif BYTE_ORDER == BIG_ENDIAN
    265     uint16_t ip_rf:1;           /**< Fragment Offset */
    266     uint16_t ip_df:1;           /**< More Fragments Flag */
    267     uint16_t ip_mf:1;           /**< Dont Fragment Flag */
    268     uint16_t ip_off:12;         /**< Reserved Fragment Flag */
     281    LT_BITFIELD16 ip_rf:1;              /**< Fragment Offset */
     282    LT_BITFIELD16 ip_df:1;              /**< More Fragments Flag */
     283    LT_BITFIELD16 ip_mf:1;              /**< Dont Fragment Flag */
     284    LT_BITFIELD16 ip_off:12;            /**< Reserved Fragment Flag */
    269285#else
    270286#   error "Adjust your <bits/endian.h> defines"
     
    303319    uint32_t ack_seq;           /**< Acknowledgement Number */
    304320#  if BYTE_ORDER == LITTLE_ENDIAN
    305     uint8_t res1:4;     /**< Reserved bits */
    306     uint8_t doff:4;     /**< Data Offset */     
    307     uint8_t fin:1;              /**< FIN */
    308     uint8_t syn:1;              /**< SYN flag */
    309     uint8_t rst:1;              /**< RST flag */
    310     uint8_t psh:1;              /**< PuSH flag */
    311     uint8_t ack:1;              /**< ACK flag */
    312     uint8_t urg:1;              /**< URG flag */
    313     uint8_t res2:2;     /**< Reserved */
     321    LT_BITFIELD8 res1:4;        /**< Reserved bits */
     322    LT_BITFIELD8 doff:4;        /**< Data Offset */     
     323    LT_BITFIELD8 fin:1;         /**< FIN */
     324    LT_BITFIELD8 syn:1;         /**< SYN flag */
     325    LT_BITFIELD8 rst:1;         /**< RST flag */
     326    LT_BITFIELD8 psh:1;         /**< PuSH flag */
     327    LT_BITFIELD8 ack:1;         /**< ACK flag */
     328    LT_BITFIELD8 urg:1;         /**< URG flag */
     329    LT_BITFIELD8 res2:2;        /**< Reserved */
    314330#  elif BYTE_ORDER == BIG_ENDIAN
    315     uint8_t doff:4;     /**< Data offset */
    316     uint8_t res1:4;     /**< Reserved bits */
    317     uint8_t res2:2;     /**< Reserved */
    318     uint8_t urg:1;              /**< URG flag */
    319     uint8_t ack:1;              /**< ACK flag */
    320     uint8_t psh:1;              /**< PuSH flag */
    321     uint8_t rst:1;              /**< RST flag */
    322     uint8_t syn:1;              /**< SYN flag */
    323     uint8_t fin:1;              /**< FIN flag */
     331    LT_BITFIELD8 doff:4;        /**< Data offset */
     332    LT_BITFIELD8 res1:4;        /**< Reserved bits */
     333    LT_BITFIELD8 res2:2;        /**< Reserved */
     334    LT_BITFIELD8 urg:1;         /**< URG flag */
     335    LT_BITFIELD8 ack:1;         /**< ACK flag */
     336    LT_BITFIELD8 psh:1;         /**< PuSH flag */
     337    LT_BITFIELD8 rst:1;         /**< RST flag */
     338    LT_BITFIELD8 syn:1;         /**< SYN flag */
     339    LT_BITFIELD8 fin:1;         /**< FIN flag */
    324340#  else
    325341#   error "Adjust your <bits/endian.h> defines"
     
    368384  uint8_t control;
    369385/* SNAP */
    370   uint32_t oui:24;              /**< Organisationally Unique Identifier (scope)*/
     386  LT_BITFIELD32 oui:24;         /**< Organisationally Unique Identifier (scope)*/
    371387  uint16_t type;                /**< Protocol within OUI */
    372388} PACKED libtrace_llcsnap_t;
     
    383399typedef struct libtrace_8021q
    384400{
    385   uint16_t vlan_pri:3;   /**< VLAN User Priority */
    386   uint16_t vlan_cfi:1;   /**< VLAN Format Indicator,
     401  LT_BITFIELD16 vlan_pri:3;      /**< VLAN User Priority */
     402  LT_BITFIELD16 vlan_cfi:1;      /**< VLAN Format Indicator,
    387403                                   * 0 for ethernet, 1 for token ring */
    388   uint16_t vlan_id:12;   /**< VLAN Id */
     404  LT_BITFIELD16 vlan_id:12;      /**< VLAN Id */
    389405  uint16_t vlan_ether_type;      /**< VLAN Sub-packet Type ID Field
    390406                                   * (next-header)*/
     
    394410typedef struct libtrace_atm_cell
    395411{
    396   uint32_t gfc:4;               /**< Generic Flow Control */
    397   uint32_t vpi:8;               /**< Virtual Path Identifier */
    398   uint32_t vci:8;               /**< Virtual Channel Identifier */
    399   uint32_t pt:3;                /**< Payload Type */
    400   uint32_t clp:1;               /**< Cell Loss Priority */
    401   uint32_t hec:8;               /**< Header Error Control */
     412  LT_BITFIELD32 gfc:4;          /**< Generic Flow Control */
     413  LT_BITFIELD32 vpi:8;          /**< Virtual Path Identifier */
     414  LT_BITFIELD32 vci:8;          /**< Virtual Channel Identifier */
     415  LT_BITFIELD32 pt:3;           /**< Payload Type */
     416  LT_BITFIELD32 clp:1;          /**< Cell Loss Priority */
     417  LT_BITFIELD32 hec:8;          /**< Header Error Control */
    402418} PACKED libtrace_atm_cell_t;
    403419
     
    411427/** 802.11 header */
    412428typedef struct libtrace_80211_t {
    413         uint16_t      protocol:2;
    414         uint16_t      type:2;
    415         uint16_t      subtype:4;
    416         uint16_t      to_ds:1;          /**< Packet to Distribution Service */
    417         uint16_t      from_ds:1;        /**< Packet from Distribution Service */
    418         uint16_t      more_frag:1;      /**< Packet has more fragments */
    419         uint16_t      retry:1;          /**< Packet is a retry */
    420         uint16_t      power:1;
    421         uint16_t      more_data:1;
    422         uint16_t      wep:1;
    423         uint16_t      order:1;
     429        LT_BITFIELD32      protocol:2;
     430        LT_BITFIELD32      type:2;
     431        LT_BITFIELD32      subtype:4;
     432        LT_BITFIELD32      to_ds:1;             /**< Packet to Distribution Service */
     433        LT_BITFIELD32      from_ds:1;   /**< Packet from Distribution Service */
     434        LT_BITFIELD32      more_frag:1; /**< Packet has more fragments */
     435        LT_BITFIELD32      retry:1;             /**< Packet is a retry */
     436        LT_BITFIELD32      power:1;
     437        LT_BITFIELD32      more_data:1;
     438        LT_BITFIELD32      wep:1;
     439        LT_BITFIELD32      order:1;
    424440        uint16_t     duration;
    425441        uint8_t      mac1[6];
     
    658674 * sideeffect: sets packet to NULL
    659675 */
    660 DLLEXPORT void trace_destroy_packet(libtrace_packet_t **packet);
     676DLLEXPORT void trace_destroy_packet(libtrace_packet_t *packet);
    661677
    662678
     
    777793                uint32_t *remaining);
    778794
     795DLLEXPORT void *trace_get_payload_from_link(void *link,
     796                libtrace_linktype_t linktype,
     797                uint16_t *type, uint32_t *remaining)
     798
    779799/** Gets a pointer to the payload given a pointer to a tcp header
    780800 * @param tcp           The tcp Header
     
    11081128 */
    11091129DLLEXPORT SIMPLE_FUNCTION
    1110 libtrace_filter_t *trace_bpf_setfilter(const char *filterstring);
     1130libtrace_filter_t *trace_create_filter(const char *filterstring);
    11111131
    11121132/** apply a BPF filter
    11131133 * @param filter        the filter opaque pointer
    11141134 * @param packet        the packet opaque pointer
    1115  * @return 1 if the filter matches, 0 if it doesn't.
     1135 * @return >0 if the filter matches, 0 if it doesn't, -1 on error.
    11161136 * @note Due to the way BPF filters are built, the filter is not actually
    1117  * compiled until the first time trace_bpf_filter is called. If your filter is
    1118  * incorrect, it will generate an error message and assert, exiting the
     1137 * compiled until the first time trace_create_filter is called. If your filter
     1138 * is incorrect, it will generate an error message and assert, exiting the
    11191139 * program. This behaviour may change to more graceful handling of this error
    11201140 * in the future.
    11211141 */
    1122 DLLEXPORT int trace_bpf_filter(libtrace_filter_t *filter,
     1142DLLEXPORT int trace_apply_filter(libtrace_filter_t *filter,
    11231143                const libtrace_packet_t *packet);
    11241144
     
    11271147 * Deallocate all the resources associated with a BPF filter
    11281148 */
    1129 DLLEXPORT void trace_destroy_bpf(libtrace_filter_t *filter);
     1149DLLEXPORT void trace_destroy_filter(libtrace_filter_t *filter);
    11301150/*@}*/
    11311151
  • lib/trace.c

    rcd7eec7 re2aebe7  
    215215void rt_constructor();
    216216void wag_constructor();
     217void duck_constructor();
    217218
    218219/* call all the constructors if they haven't yet all been called */
     
    630631 * sideeffect: sets packet to NULL
    631632 */
    632 DLLEXPORT void trace_destroy_packet(libtrace_packet_t **packet) {
    633         if ((*packet)->buf_control == TRACE_CTRL_PACKET) {
    634                 free((*packet)->buffer);
    635         }
    636         free((*packet));
    637         *packet = NULL;
     633DLLEXPORT void trace_destroy_packet(libtrace_packet_t *packet) {
     634        if (packet->buf_control == TRACE_CTRL_PACKET) {
     635                free(packet->buffer);
     636        }
     637        packet->buf_control='\0'; /* an "bad" value to force an assert
     638                                   * if this packet is ever reused
     639                                   */
     640        free(packet);
    638641}       
    639642
     
    667670                                 * packet
    668671                                 */
    669                                 if (!trace_bpf_filter(libtrace->filter,packet)){
     672                                if (!trace_apply_filter(libtrace->filter,packet)){
    670673                                        continue;
    671674                                }
     
    916919 * @author Daniel Lawson
    917920 */
    918 DLLEXPORT libtrace_filter_t *trace_bpf_setfilter(const char *filterstring) {
     921DLLEXPORT libtrace_filter_t *trace_create_filter(const char *filterstring) {
    919922#if HAVE_BPF
    920923        libtrace_filter_t *filter = (libtrace_filter_t*)
     
    929932}
    930933
    931 DLLEXPORT void trace_destroy_bpf(libtrace_filter_t *filter)
     934DLLEXPORT void trace_destroy_filter(libtrace_filter_t *filter)
    932935{
    933936#if HAVE_BPF
     
    996999}
    9971000
    998 DLLEXPORT int trace_bpf_filter(libtrace_filter_t *filter,
     1001DLLEXPORT int trace_apply_filter(libtrace_filter_t *filter,
    9991002                        const libtrace_packet_t *packet) {
    10001003#if HAVE_BPF
Note: See TracChangeset for help on using the changeset viewer.