Changeset 73dd29f


Ignore:
Timestamp:
04/02/07 21:44:53 (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:
11f2df7
Parents:
02bd77e
Message:

Sooo, pcap has two types of DLT's "pure" DLT's that are platform dependant,
and "linktype" DLT's that are portable and are what are written to pcap files.

Instead of fudging the two concepts together so much, attempt to disintangle
this mess without exposing too much of the god awful mess to the end user.

Location:
lib
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • lib/format_bpf.c

    r5361eae r73dd29f  
    6161        unsigned int buffersize;
    6262        int remaining;
    63         unsigned int dlt;
     63        unsigned int linktype;
    6464};
    6565
     
    151151
    152152        if (ioctl(FORMATIN(libtrace)->fd, BIOCGDLT,
    153                          &FORMATIN(libtrace)->dlt) == -1) {
     153                         &FORMATIN(libtrace)->linktype) == -1) {
    154154                trace_set_err(libtrace,errno,"Failed to retrieve link type");
    155155                close(FORMATIN(libtrace)->fd);
     
    278278
    279279        /* Find the payload */
    280         /* TODO: Pcap deals with a padded FDDI dlt here */
     280        /* TODO: Pcap deals with a padded FDDI linktype here */
    281281        packet->payload=FORMATIN(libtrace)->bufptr+BPFHDR(packet)->bh_hdrlen;
    282282
     
    293293
    294294static libtrace_linktype_t bpf_get_link_type(const libtrace_packet_t *packet) {
    295         return pcap_dlt_to_libtrace(FORMATIN(packet->trace)->dlt);
     295        return pcap_linktype_to_libtrace(FORMATIN(packet->trace)->linktype);
    296296}
    297297
  • lib/format_pcap.c

    rf0c639b r73dd29f  
    264264        assert(libtrace->format_data);
    265265        linktype = pcap_datalink(DATA(libtrace)->input.pcap);
    266         packet->type = pcap_dlt_to_rt(linktype);
     266        packet->type = pcap_linktype_to_rt(linktype);
    267267
    268268        packet->buf_control = TRACE_CTRL_PACKET;
     
    314314         * pop off the top header until it can be converted
    315315         */
    316         while (libtrace_to_pcap_dlt(trace_get_link_type(packet))==~0U) {
     316        while (libtrace_to_pcap_linktype(trace_get_link_type(packet))==~0U) {
    317317                if (!demote_packet(packet)) {
    318318                        trace_set_err_out(libtrace,
     
    323323        }
    324324
     325
    325326        if (!OUTPUT.trace.pcap) {
    326                 OUTPUT.trace.pcap = pcap_open_dead(
    327                         libtrace_to_pcap_dlt(trace_get_link_type(packet)),
    328                         65536);
     327                int linktype=libtrace_to_pcap_dlt(trace_get_link_type(packet));
     328                OUTPUT.trace.pcap = pcap_open_dead(linktype,65536);
    329329                if (!OUTPUT.trace.pcap) {
    330                         trace_set_err_out(libtrace,TRACE_ERR_INIT_FAILED,"Failed to open dead trace: %s\n",
     330                        trace_set_err_out(libtrace,TRACE_ERR_INIT_FAILED,
     331                                        "Failed to open dead trace: %s\n",
    331332                                        pcap_geterr(OUTPUT.trace.pcap));
    332333                }
     
    409410
    410411static libtrace_linktype_t pcap_get_link_type(const libtrace_packet_t *packet) {
    411         /* pcap doesn't store dlt in the framing header so we need
     412        /* pcap doesn't store linktype in the framing header so we need
    412413         * rt to do it for us
    413414         */
    414         int linktype = rt_to_pcap_dlt(packet->type);
    415         return pcap_dlt_to_libtrace(linktype);
     415        int linktype = rt_to_pcap_linktype(packet->type);
     416        return pcap_linktype_to_libtrace(linktype);
    416417}
    417418
     
    511512        struct pcap_pkthdr *pcapptr = 0;
    512513        pcapptr = (struct pcap_pkthdr *)packet->header;
    513         if (packet->type==pcap_dlt_to_rt(TRACE_DLT_EN10MB))
     514        if (packet->type==pcap_linktype_to_rt(TRACE_DLT_EN10MB))
    514515                return pcapptr->len+4; /* Include the missing FCS */
    515         else if (packet->type==pcap_dlt_to_rt(TRACE_DLT_IEEE802_11_RADIO)) {
     516        else if (packet->type==pcap_linktype_to_rt(TRACE_DLT_IEEE802_11_RADIO)) {
    516517                /* If the packet is Radiotap and the flags field indicates
    517518                 * that the FCS is not included in the 802.11 frame, then
    518519                 * we need to add 4 to the wire-length to account for it.
    519520                 */
    520                 uint16_t flags;
    521                 trace_get_wireless_flags(trace_get_link(packet), trace_get_link_type(packet), &flags);
     521                uint8_t flags;
     522                trace_get_wireless_flags(trace_get_link(packet),
     523                                trace_get_link_type(packet), &flags);
    522524                if ((flags & TRACE_RADIOTAP_F_FCS) == 0)
    523525                        return pcapptr->len + 4;
  • lib/format_pcapfile.c

    rf0c639b r73dd29f  
    212212        assert(libtrace->format_data);
    213213
    214         packet->type = pcap_dlt_to_rt(swapl(libtrace,
     214        packet->type = pcap_linktype_to_rt(swapl(libtrace,
    215215                                DATA(libtrace)->header.network));
    216216
     
    268268         * pop off the top header until it can be converted
    269269         */
    270         while (libtrace_to_pcap_dlt(trace_get_link_type(packet))==~0U) {
     270        while (libtrace_to_pcap_linktype(trace_get_link_type(packet))==~0U) {
    271271                if (!demote_packet(packet)) {
    272272                        trace_set_err_out(out,
     
    297297                pcaphdr.snaplen = 65536;
    298298                pcaphdr.network =
    299                         libtrace_to_pcap_dlt(trace_get_link_type(packet));
     299                        libtrace_to_pcap_linktype(trace_get_link_type(packet));
    300300
    301301                libtrace_io_write(DATAOUT(out)->file, &pcaphdr, sizeof(pcaphdr));
     
    338338{
    339339#if 0
    340         return pcap_dlt_to_libtrace(
     340        return pcap_linktype_to_libtrace(
    341341                        swapl(packet->trace,
    342342                                DATA(packet->trace)->header.network
     
    344344                        );
    345345#endif
    346         return pcap_dlt_to_libtrace(rt_to_pcap_dlt(packet->type));
     346        return pcap_linktype_to_libtrace(rt_to_pcap_linktype(packet->type));
    347347}
    348348
     
    429429        libtrace_pcapfile_pkt_hdr_t *pcapptr
    430430                = (libtrace_pcapfile_pkt_hdr_t *)packet->header;
    431         if (packet->type==pcap_dlt_to_rt(TRACE_DLT_EN10MB))
     431        if (packet->type==pcap_linktype_to_rt(TRACE_DLT_EN10MB))
    432432                /* Include the missing FCS */
    433433                return swapl(packet->trace,pcapptr->wirelen)+4;
    434         else if (packet->type==pcap_dlt_to_rt(TRACE_DLT_IEEE802_11_RADIO)) {
     434        else if (packet->type==pcap_linktype_to_rt(TRACE_DLT_IEEE802_11_RADIO)) {
    435435                /* If the packet is Radiotap and the flags field indicates
    436436                 * that the FCS is not included in the 802.11 frame, then
  • lib/libtrace.h.in

    r3ec29a9 r73dd29f  
    203203};
    204204
    205 /** Enumeration of DLT types supported by libtrace
    206  * These aren't actually DLTs, but LINKTYPE_'s, so becareful when modifying
    207  * this.
    208  */
     205/** Enumeration of DLT supported by libtrace
     206 */
    209207typedef enum {
    210208        TRACE_DLT_NULL = 0,
     
    212210        TRACE_DLT_PPP = 9,
    213211        TRACE_DLT_ATM_RFC1483 = 11,
    214         TRACE_DLT_RAW = 101,
     212        /* Sigh. This is handled in files with LINKTYPE's */
     213#ifdef __OpenBSD__
     214        TRACE_DLT_RAW = 14,     
     215#else
     216        TRACE_DLT_RAW = 12,
     217#endif
     218        TRACE_DLT_LINKTYPE_RAW = 101,
    215219        TRACE_DLT_IEEE802_11 = 105,
    216220        TRACE_DLT_LINUX_SLL = 113,
  • lib/libtrace_int.h

    re01a738 r73dd29f  
    361361void register_format(struct libtrace_format_t *format);
    362362
    363 libtrace_linktype_t pcap_dlt_to_libtrace(libtrace_dlt_t dlt);
    364 libtrace_dlt_t libtrace_to_pcap_dlt(libtrace_linktype_t type);
    365 libtrace_rt_types_t pcap_dlt_to_rt(libtrace_dlt_t dlt);
    366 libtrace_dlt_t rt_to_pcap_dlt(libtrace_rt_types_t rt_type);
     363libtrace_linktype_t pcap_linktype_to_libtrace(libtrace_linktype_t linktype);
     364libtrace_linktype_t libtrace_to_pcap_linktype(libtrace_linktype_t type);
     365libtrace_linktype_t libtrace_to_pcap_dlt(libtrace_linktype_t type);
     366libtrace_rt_types_t pcap_linktype_to_rt(libtrace_linktype_t linktype);
     367libtrace_linktype_t rt_to_pcap_linktype(libtrace_rt_types_t rt_type);
    367368libtrace_linktype_t erf_type_to_libtrace(uint8_t erf);
    368369uint8_t libtrace_to_erf_type(libtrace_linktype_t linktype);
  • lib/linktypes.c

    rbe22b51 r73dd29f  
    3232 */
    3333
    34 libtrace_linktype_t pcap_dlt_to_libtrace(libtrace_dlt_t dlt)
    35 {
    36         switch(dlt) {
    37                 case TRACE_DLT_RAW: return TRACE_TYPE_NONE;
     34libtrace_linktype_t pcap_linktype_to_libtrace(libtrace_dlt_t linktype)
     35{
     36        switch(linktype) {
     37                case TRACE_DLT_RAW:
     38                case TRACE_DLT_LINKTYPE_RAW: return TRACE_TYPE_NONE;
    3839                case TRACE_DLT_EN10MB: return TRACE_TYPE_ETH;
    3940                case TRACE_DLT_IEEE802_11: return TRACE_TYPE_80211;
     
    5354}
    5455
    55 
    56 libtrace_dlt_t libtrace_to_pcap_dlt(libtrace_linktype_t type)
     56libtrace_linktype_t libtrace_to_pcap_dlt(libtrace_linktype_t type)
    5757{
    5858        /* If pcap doesn't have a DLT, you can either ask pcap to register
     
    6161         */
    6262        switch(type) {
    63                 case TRACE_TYPE_NONE: return TRACE_DLT_RAW;
     63                case TRACE_TYPE_NONE: return TRACE_DLT_RAW; 
    6464                case TRACE_TYPE_ETH: return TRACE_DLT_EN10MB;
    6565                case TRACE_TYPE_80211: return TRACE_DLT_IEEE802_11;
     
    9393}
    9494
    95 libtrace_rt_types_t pcap_dlt_to_rt(libtrace_dlt_t dlt)
    96 {
    97         /* For pcap the rt type is just the dlt + a fixed value */
    98         return dlt + TRACE_RT_DATA_DLT;
    99 }
    100 
    101 libtrace_dlt_t rt_to_pcap_dlt(libtrace_rt_types_t rt_type)
     95libtrace_linktype_t libtrace_to_pcap_linktype(libtrace_linktype_t type)
     96{
     97        return pcap_dlt_to_pcap_linktype(libtrace_to_pcap_dlt(type));
     98}
     99
     100static libtrace_dlt_t pcap_dlt_to_pcap_linktype(libtrace_dlt_t linktype)
     101{
     102        switch (linktype) {
     103                case TRACE_DLT_RAW: return TRACE_DLT_LINKTYPE_RAW;
     104                default:
     105                                    return linktype;
     106        }
     107}
     108
     109libtrace_rt_types_t pcap_linktype_to_rt(libtrace_dlt_t linktype)
     110{
     111        /* For pcap the rt type is just the linktype + a fixed value */
     112        return pcap_dlt_to_pcap_linktype(linktype) + TRACE_RT_DATA_DLT;
     113}
     114
     115libtrace_linktype_t rt_to_pcap_linktype(libtrace_rt_types_t rt_type)
    102116{
    103117        assert(rt_type >= TRACE_RT_DATA_DLT);
     
    173187                libtrace_sll_header_t *hdr;
    174188
    175                 if (pcap_dlt_to_libtrace(rt_to_pcap_dlt(packet->type))
     189                if (pcap_linktype_to_libtrace(rt_to_pcap_linktype(packet->type))
    176190                        == TRACE_TYPE_LINUX_SLL) {
    177191                        /* This is already been promoted, so ignore it */
     
    192206                hdr->pkttype=TRACE_SLL_OUTGOING;
    193207
    194                 switch(pcap_dlt_to_libtrace(rt_to_pcap_dlt(packet->type))) {
     208                switch(pcap_linktype_to_libtrace(rt_to_pcap_linktype(packet->type))) {
    195209                        case TRACE_TYPE_NONE:
    196210                                trace_get_payload_from_link(
     
    226240                packet->header=tmpbuffer;
    227241                packet->payload=tmpbuffer+trace_get_framing_length(packet);
    228                 packet->type=pcap_dlt_to_rt(TRACE_DLT_LINUX_SLL);
     242                packet->type=pcap_linktype_to_rt(TRACE_DLT_LINUX_SLL);
    229243                ((struct libtrace_pcapfile_pkt_hdr_t*) packet->header)->caplen+=
    230244                        sizeof(libtrace_sll_header_t);
     
    277291                        packet->header=tmp;
    278292                        packet->payload=tmp+sizeof(libtrace_pcapfile_pkt_hdr_t);
    279                         packet->type=pcap_dlt_to_rt(TRACE_DLT_ATM_RFC1483);
     293                        packet->type=pcap_linktype_to_rt(TRACE_DLT_ATM_RFC1483);
    280294                       
    281295                        if (trace == NULL) {
     
    291305                                        ->hatype)) {
    292306                                case ARPHRD_PPP:
    293                                         packet->type=pcap_dlt_to_rt(TRACE_DLT_RAW);
     307                                        packet->type=pcap_linktype_to_rt(TRACE_DLT_RAW);
    294308                                        break;
    295309                                case ARPHRD_ETHER:
    296                                         packet->type=pcap_dlt_to_rt(TRACE_DLT_EN10MB);
     310                                        packet->type=pcap_linktype_to_rt(TRACE_DLT_EN10MB);
    297311                                        break;
    298312                                default:
  • lib/trace.c

    re01a738 r73dd29f  
    14901490        memcpy(packet->header,&hdr,sizeof(hdr));
    14911491        memcpy(packet->payload,data,(size_t)len);
    1492         packet->type=pcap_dlt_to_rt(libtrace_to_pcap_dlt(linktype));
    1493 }
     1492        packet->type=pcap_linktype_to_rt(libtrace_to_pcap_linktype(linktype));
     1493}
Note: See TracChangeset for help on using the changeset viewer.