Changeset 52656ed for lib/format_dag25.c


Ignore:
Timestamp:
09/04/07 16:50:19 (14 years ago)
Author:
Shane Alcock <salcock@…>
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:
5798dc6
Parents:
2cf30f6
Message:
  • Updated autotools to detect DAG 3.X drivers. The new detection method will also catch DAG 2.5, but this is not a problem because the API is the same so DAG 2.5 and DAG 3 can use the same code within libtrace.
  • Changed format_dag25.c to manage the dag stream manually, similar to format_dag24.c.
  • Libtrace programs using DAG 2.5 and greater should now detach the DAG stream properly, provided they are exited cleanly.
  • The snaplen can now be configured for DAG 2.5 and DAG 3.0 inputs
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_dag25.c

    r708f9ae r52656ed  
    7575        int fd;
    7676        unsigned int dagstream;
     77        int stream_attached;
     78        uint8_t *bottom;
     79        uint8_t *top;
    7780};
    7881
     
    105108        DUCK.last_pkt = 0;
    106109        DUCK.dummy_duck = NULL;
    107 
     110        FORMAT_DATA->stream_attached = 0;
     111       
    108112        return 0;
    109113}
     
    111115static int dag_config_input(libtrace_t *libtrace, trace_option_t option,
    112116                                void *data) {
    113         switch(option) {
     117        char conf_str[4096];
     118        switch(option) {
    114119                case TRACE_OPTION_META_FREQ:
    115120                        DUCK.duck_freq = *(int *)data;
    116121                        return 0;
    117122                case TRACE_OPTION_SNAPLEN:
    118                         /* Surely we can set this?? Fall through for now*/
    119                         return -1;
     123                        snprintf(conf_str, 4096, "varlen slen=%i", *(int *)data);
     124                        if (dag_configure(FORMAT_DATA->fd, conf_str) != 0) {
     125                                trace_set_err(libtrace, errno, "Failed to configure snaplen on DAG card: %s", libtrace->uridata);
     126                                return -1;
     127                        }
     128                        return 0;
    120129                case TRACE_OPTION_PROMISC:
    121130                        /* DAG already operates in a promisc fashion */
     
    152161                return -1;
    153162        }
     163        FORMAT_DATA->stream_attached = 1;
    154164        /* We don't want the dag card to do any sleeping */
    155165        dag_set_stream_poll(FORMAT_DATA->fd,
     
    158168       
    159169        /* Should probably flush the memory hole now */
     170       
    160171        do {
    161172                top = dag_advance_stream(FORMAT_DATA->fd,
     
    164175                assert(top && bottom);
    165176                diff = top - bottom;
     177                bottom -= diff;
    166178        } while (diff != 0);
    167179
     
    180192                return -1;
    181193        }
    182 
     194        FORMAT_DATA->stream_attached = 0;
    183195        return 0;
    184196}
    185197
    186198static int dag_fin_input(libtrace_t *libtrace) {
     199        if (FORMAT_DATA->stream_attached)
     200                dag_pause_input(libtrace);
     201        dag_close(FORMAT_DATA->fd);
    187202        if (DUCK.dummy_duck)
    188203                trace_destroy_dead(DUCK.dummy_duck);
     
    193208static int dag_get_duckinfo(libtrace_t *libtrace,
    194209                                libtrace_packet_t *packet) {
    195         daginf_t lt_dag_inf;
    196 
    197210        if (packet->buf_control == TRACE_CTRL_EXTERNAL ||
    198211                        !packet->buffer) {
     
    224237}
    225238
    226 dag_record_t *dag_get_record(libtrace_t *libtrace) {
     239static int dag_available(libtrace_t *libtrace) {
     240        uint32_t diff = FORMAT_DATA->top - FORMAT_DATA->bottom;
     241        if (diff >= dag_record_size)
     242                return diff;
     243        FORMAT_DATA->top = dag_advance_stream(FORMAT_DATA->fd,
     244                        FORMAT_DATA->dagstream,
     245                        &(FORMAT_DATA->bottom));
     246        if (FORMAT_DATA->top == NULL) {
     247                trace_set_err(libtrace, errno, "dag_advance_stream failed!");
     248                return -1;
     249        }
     250        diff = FORMAT_DATA->top - FORMAT_DATA->bottom;
     251        return diff;
     252}
     253
     254static dag_record_t *dag_get_record(libtrace_t *libtrace) {
    227255        dag_record_t *erfptr = NULL;
    228256        uint16_t size;
    229         erfptr = (dag_record_t *) dag_rx_stream_next_record(FORMAT_DATA->fd,
    230                         FORMAT_DATA->dagstream);
     257        erfptr = (dag_record_t *)FORMAT_DATA->bottom;
    231258        if (!erfptr)
    232259                return NULL;
    233260        size = ntohs(erfptr->rlen);
    234261        assert( size >= dag_record_size );
     262        /* Make certain we have the full packet available */
     263        if (size > (FORMAT_DATA->top - FORMAT_DATA->bottom))
     264                return NULL;
     265        FORMAT_DATA->bottom += size;
    235266        return erfptr;
    236267}
    237268
    238 void dag_form_packet(dag_record_t *erfptr, libtrace_packet_t *packet) {
     269static void dag_form_packet(dag_record_t *erfptr, libtrace_packet_t *packet) {
    239270        packet->buffer = erfptr;
    240271        packet->header = erfptr;
     
    257288        struct timeval tv;
    258289        dag_record_t *erfptr = NULL;
    259 
     290        int numbytes = 0;
     291       
    260292        if (DUCK.last_pkt - DUCK.last_duck > DUCK.duck_freq &&
    261293                        DUCK.duck_freq != 0) {
     
    276308
    277309        do {
     310                numbytes = dag_available(libtrace);
     311                if (numbytes < 0)
     312                        return numbytes;
     313                if (numbytes < dag_record_size)
     314                        /* Block until we see a packet */
     315                        continue;
    278316                erfptr = dag_get_record(libtrace);
    279317        } while (erfptr == NULL);
Note: See TracChangeset for help on using the changeset viewer.