]> The Tcpdump Group git mirrors - libpcap/blob - pcap-dag.c
ae37b10c21494e5832306977b4d2fb48e0c2cf33
[libpcap] / pcap-dag.c
1 /*
2 * pcap-dag.c: Packet capture interface for Emulex EndaceDAG cards.
3 *
4 * The functionality of this code attempts to mimic that of pcap-linux as much
5 * as possible. This code is compiled in several different ways depending on
6 * whether DAG_ONLY and HAVE_DAG_API are defined. If HAVE_DAG_API is not
7 * defined it should not get compiled in, otherwise if DAG_ONLY is defined then
8 * the 'dag_' function calls are renamed to 'pcap_' equivalents. If DAG_ONLY
9 * is not defined then nothing is altered - the dag_ functions will be
10 * called as required from their pcap-linux/bpf equivalents.
11 *
12 * Authors: Richard Littin, Sean Irvine ({richard,sean}@reeltwo.com)
13 * Modifications: Jesper Peterson
14 * Koryn Grant
15 * Stephen Donnelly <stephen.donnelly@emulex.com>
16 */
17
18 #ifdef HAVE_CONFIG_H
19 #include <config.h>
20 #endif
21
22 #include <sys/param.h> /* optionally get BSD define */
23
24 #include <stdlib.h>
25 #include <string.h>
26 #include <errno.h>
27
28 #include "pcap-int.h"
29
30 #include <ctype.h>
31 #include <netinet/in.h>
32 #include <sys/mman.h>
33 #include <sys/socket.h>
34 #include <sys/types.h>
35 #include <unistd.h>
36
37 struct mbuf; /* Squelch compiler warnings on some platforms for */
38 struct rtentry; /* declarations in <net/if.h> */
39 #include <net/if.h>
40
41 #include "dagnew.h"
42 #include "dagapi.h"
43 #include "dagpci.h"
44
45 #include "pcap-dag.h"
46
47 /*
48 * DAG devices have names beginning with "dag", followed by a number
49 * from 0 to DAG_MAX_BOARDS, then optionally a colon and a stream number
50 * from 0 to DAG_STREAM_MAX.
51 */
52 #ifndef DAG_MAX_BOARDS
53 #define DAG_MAX_BOARDS 32
54 #endif
55
56
57 #ifndef ERF_TYPE_AAL5
58 #define ERF_TYPE_AAL5 4
59 #endif
60
61 #ifndef ERF_TYPE_MC_HDLC
62 #define ERF_TYPE_MC_HDLC 5
63 #endif
64
65 #ifndef ERF_TYPE_MC_RAW
66 #define ERF_TYPE_MC_RAW 6
67 #endif
68
69 #ifndef ERF_TYPE_MC_ATM
70 #define ERF_TYPE_MC_ATM 7
71 #endif
72
73 #ifndef ERF_TYPE_MC_RAW_CHANNEL
74 #define ERF_TYPE_MC_RAW_CHANNEL 8
75 #endif
76
77 #ifndef ERF_TYPE_MC_AAL5
78 #define ERF_TYPE_MC_AAL5 9
79 #endif
80
81 #ifndef ERF_TYPE_COLOR_HDLC_POS
82 #define ERF_TYPE_COLOR_HDLC_POS 10
83 #endif
84
85 #ifndef ERF_TYPE_COLOR_ETH
86 #define ERF_TYPE_COLOR_ETH 11
87 #endif
88
89 #ifndef ERF_TYPE_MC_AAL2
90 #define ERF_TYPE_MC_AAL2 12
91 #endif
92
93 #ifndef ERF_TYPE_IP_COUNTER
94 #define ERF_TYPE_IP_COUNTER 13
95 #endif
96
97 #ifndef ERF_TYPE_TCP_FLOW_COUNTER
98 #define ERF_TYPE_TCP_FLOW_COUNTER 14
99 #endif
100
101 #ifndef ERF_TYPE_DSM_COLOR_HDLC_POS
102 #define ERF_TYPE_DSM_COLOR_HDLC_POS 15
103 #endif
104
105 #ifndef ERF_TYPE_DSM_COLOR_ETH
106 #define ERF_TYPE_DSM_COLOR_ETH 16
107 #endif
108
109 #ifndef ERF_TYPE_COLOR_MC_HDLC_POS
110 #define ERF_TYPE_COLOR_MC_HDLC_POS 17
111 #endif
112
113 #ifndef ERF_TYPE_AAL2
114 #define ERF_TYPE_AAL2 18
115 #endif
116
117 #ifndef ERF_TYPE_COLOR_HASH_POS
118 #define ERF_TYPE_COLOR_HASH_POS 19
119 #endif
120
121 #ifndef ERF_TYPE_COLOR_HASH_ETH
122 #define ERF_TYPE_COLOR_HASH_ETH 20
123 #endif
124
125 #ifndef ERF_TYPE_INFINIBAND
126 #define ERF_TYPE_INFINIBAND 21
127 #endif
128
129 #ifndef ERF_TYPE_IPV4
130 #define ERF_TYPE_IPV4 22
131 #endif
132
133 #ifndef ERF_TYPE_IPV6
134 #define ERF_TYPE_IPV6 23
135 #endif
136
137 #ifndef ERF_TYPE_RAW_LINK
138 #define ERF_TYPE_RAW_LINK 24
139 #endif
140
141 #ifndef ERF_TYPE_INFINIBAND_LINK
142 #define ERF_TYPE_INFINIBAND_LINK 25
143 #endif
144
145 #ifndef ERF_TYPE_META
146 #define ERF_TYPE_META 27
147 #endif
148
149 #ifndef ERF_TYPE_PAD
150 #define ERF_TYPE_PAD 48
151 #endif
152
153 #define ATM_CELL_SIZE 52
154 #define ATM_HDR_SIZE 4
155
156 /*
157 * A header containing additional MTP information.
158 */
159 #define MTP2_SENT_OFFSET 0 /* 1 byte */
160 #define MTP2_ANNEX_A_USED_OFFSET 1 /* 1 byte */
161 #define MTP2_LINK_NUMBER_OFFSET 2 /* 2 bytes */
162 #define MTP2_HDR_LEN 4 /* length of the header */
163
164 #define MTP2_ANNEX_A_NOT_USED 0
165 #define MTP2_ANNEX_A_USED 1
166 #define MTP2_ANNEX_A_USED_UNKNOWN 2
167
168 /* SunATM pseudo header */
169 struct sunatm_hdr {
170 unsigned char flags; /* destination and traffic type */
171 unsigned char vpi; /* VPI */
172 unsigned short vci; /* VCI */
173 };
174
175 /*
176 * Private data for capturing on DAG devices.
177 */
178 struct pcap_dag {
179 struct pcap_stat stat;
180 u_char *dag_mem_bottom; /* DAG card current memory bottom pointer */
181 u_char *dag_mem_top; /* DAG card current memory top pointer */
182 int dag_fcs_bits; /* Number of checksum bits from link layer */
183 int dag_flags; /* Flags */
184 int dag_stream; /* DAG stream number */
185 int dag_timeout; /* timeout specified to pcap_open_live.
186 * Same as in linux above, introduce
187 * generally? */
188 struct timeval required_select_timeout;
189 /* Timeout caller must use in event loops */
190 };
191
192 typedef struct pcap_dag_node {
193 struct pcap_dag_node *next;
194 pcap_t *p;
195 pid_t pid;
196 } pcap_dag_node_t;
197
198 static pcap_dag_node_t *pcap_dags = NULL;
199 static int atexit_handler_installed = 0;
200 static const unsigned short endian_test_word = 0x0100;
201
202 #define IS_BIGENDIAN() (*((unsigned char *)&endian_test_word))
203
204 #define MAX_DAG_PACKET 65536
205
206 static unsigned char TempPkt[MAX_DAG_PACKET];
207
208 #ifndef HAVE_DAG_LARGE_STREAMS_API
209 #define dag_attach_stream64(a, b, c, d) dag_attach_stream(a, b, c, d)
210 #define dag_get_stream_poll64(a, b, c, d, e) dag_get_stream_poll(a, b, c, d, e)
211 #define dag_set_stream_poll64(a, b, c, d, e) dag_set_stream_poll(a, b, c, d, e)
212 #define dag_size_t uint32_t
213 #endif
214
215 static int dag_setfilter(pcap_t *p, struct bpf_program *fp);
216 static int dag_stats(pcap_t *p, struct pcap_stat *ps);
217 static int dag_set_datalink(pcap_t *p, int dlt);
218 static int dag_get_datalink(pcap_t *p);
219 static int dag_setnonblock(pcap_t *p, int nonblock);
220
221 static void
222 delete_pcap_dag(pcap_t *p)
223 {
224 pcap_dag_node_t *curr = NULL, *prev = NULL;
225
226 for (prev = NULL, curr = pcap_dags; curr != NULL && curr->p != p; prev = curr, curr = curr->next) {
227 /* empty */
228 }
229
230 if (curr != NULL && curr->p == p) {
231 if (prev != NULL) {
232 prev->next = curr->next;
233 } else {
234 pcap_dags = curr->next;
235 }
236 }
237 }
238
239 /*
240 * Performs a graceful shutdown of the DAG card, frees dynamic memory held
241 * in the pcap_t structure, and closes the file descriptor for the DAG card.
242 */
243
244 static void
245 dag_platform_cleanup(pcap_t *p)
246 {
247 struct pcap_dag *pd = p->priv;
248
249 if(dag_stop_stream(p->fd, pd->dag_stream) < 0)
250 fprintf(stderr,"dag_stop_stream: %s\n", strerror(errno));
251
252 if(dag_detach_stream(p->fd, pd->dag_stream) < 0)
253 fprintf(stderr,"dag_detach_stream: %s\n", strerror(errno));
254
255 if(p->fd != -1) {
256 if(dag_close(p->fd) < 0)
257 fprintf(stderr,"dag_close: %s\n", strerror(errno));
258 p->fd = -1;
259 }
260 delete_pcap_dag(p);
261 pcap_cleanup_live_common(p);
262 /* Note: don't need to call close(p->fd) here as dag_close(p->fd) does this. */
263 }
264
265 static void
266 atexit_handler(void)
267 {
268 while (pcap_dags != NULL) {
269 if (pcap_dags->pid == getpid()) {
270 if (pcap_dags->p != NULL)
271 dag_platform_cleanup(pcap_dags->p);
272 } else {
273 delete_pcap_dag(pcap_dags->p);
274 }
275 }
276 }
277
278 static int
279 new_pcap_dag(pcap_t *p)
280 {
281 pcap_dag_node_t *node = NULL;
282
283 if ((node = malloc(sizeof(pcap_dag_node_t))) == NULL) {
284 return -1;
285 }
286
287 if (!atexit_handler_installed) {
288 atexit(atexit_handler);
289 atexit_handler_installed = 1;
290 }
291
292 node->next = pcap_dags;
293 node->p = p;
294 node->pid = getpid();
295
296 pcap_dags = node;
297
298 return 0;
299 }
300
301 static unsigned int
302 dag_erf_ext_header_count(uint8_t * erf, size_t len)
303 {
304 uint32_t hdr_num = 0;
305 uint8_t hdr_type;
306
307 /* basic sanity checks */
308 if ( erf == NULL )
309 return 0;
310 if ( len < 16 )
311 return 0;
312
313 /* check if we have any extension headers */
314 if ( (erf[8] & 0x80) == 0x00 )
315 return 0;
316
317 /* loop over the extension headers */
318 do {
319
320 /* sanity check we have enough bytes */
321 if ( len < (24 + (hdr_num * 8)) )
322 return hdr_num;
323
324 /* get the header type */
325 hdr_type = erf[(16 + (hdr_num * 8))];
326 hdr_num++;
327
328 } while ( hdr_type & 0x80 );
329
330 return hdr_num;
331 }
332
333 /*
334 * Read at most max_packets from the capture stream and call the callback
335 * for each of them. Returns the number of packets handled, -1 if an
336 * error occured, or -2 if we were told to break out of the loop.
337 */
338 static int
339 dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
340 {
341 struct pcap_dag *pd = p->priv;
342 unsigned int processed = 0;
343 unsigned int nonblocking = pd->dag_flags & DAGF_NONBLOCK;
344 unsigned int num_ext_hdr = 0;
345 unsigned int ticks_per_second;
346
347 /* Get the next bufferful of packets (if necessary). */
348 while (pd->dag_mem_top - pd->dag_mem_bottom < dag_record_size) {
349
350 /*
351 * Has "pcap_breakloop()" been called?
352 */
353 if (p->break_loop) {
354 /*
355 * Yes - clear the flag that indicates that
356 * it has, and return -2 to indicate that
357 * we were told to break out of the loop.
358 */
359 p->break_loop = 0;
360 return -2;
361 }
362
363 /* dag_advance_stream() will block (unless nonblock is called)
364 * until 64kB of data has accumulated.
365 * If to_ms is set, it will timeout before 64kB has accumulated.
366 * We wait for 64kB because processing a few packets at a time
367 * can cause problems at high packet rates (>200kpps) due
368 * to inefficiencies.
369 * This does mean if to_ms is not specified the capture may 'hang'
370 * for long periods if the data rate is extremely slow (<64kB/sec)
371 * If non-block is specified it will return immediately. The user
372 * is then responsible for efficiency.
373 */
374 if ( NULL == (pd->dag_mem_top = dag_advance_stream(p->fd, pd->dag_stream, &(pd->dag_mem_bottom))) ) {
375 return -1;
376 }
377
378 if (nonblocking && (pd->dag_mem_top - pd->dag_mem_bottom < dag_record_size))
379 {
380 /* Pcap is configured to process only available packets, and there aren't any, return immediately. */
381 return 0;
382 }
383
384 if(!nonblocking &&
385 pd->dag_timeout &&
386 (pd->dag_mem_top - pd->dag_mem_bottom < dag_record_size))
387 {
388 /* Blocking mode, but timeout set and no data has arrived, return anyway.*/
389 return 0;
390 }
391
392 }
393
394 /* Process the packets. */
395 while (pd->dag_mem_top - pd->dag_mem_bottom >= dag_record_size) {
396
397 unsigned short packet_len = 0;
398 int caplen = 0;
399 struct pcap_pkthdr pcap_header;
400
401 dag_record_t *header = (dag_record_t *)(pd->dag_mem_bottom);
402
403 u_char *dp = ((u_char *)header); /* + dag_record_size; */
404 unsigned short rlen;
405
406 /*
407 * Has "pcap_breakloop()" been called?
408 */
409 if (p->break_loop) {
410 /*
411 * Yes - clear the flag that indicates that
412 * it has, and return -2 to indicate that
413 * we were told to break out of the loop.
414 */
415 p->break_loop = 0;
416 return -2;
417 }
418
419 rlen = ntohs(header->rlen);
420 if (rlen < dag_record_size)
421 {
422 strncpy(p->errbuf, "dag_read: record too small", PCAP_ERRBUF_SIZE);
423 return -1;
424 }
425 pd->dag_mem_bottom += rlen;
426
427 /* Count lost packets. */
428 switch((header->type & 0x7f)) {
429 /* in these types the color value overwrites the lctr */
430 case ERF_TYPE_COLOR_HDLC_POS:
431 case ERF_TYPE_COLOR_ETH:
432 case ERF_TYPE_DSM_COLOR_HDLC_POS:
433 case ERF_TYPE_DSM_COLOR_ETH:
434 case ERF_TYPE_COLOR_MC_HDLC_POS:
435 case ERF_TYPE_COLOR_HASH_ETH:
436 case ERF_TYPE_COLOR_HASH_POS:
437 break;
438
439 default:
440 if (header->lctr) {
441 if (pd->stat.ps_drop > (UINT_MAX - ntohs(header->lctr))) {
442 pd->stat.ps_drop = UINT_MAX;
443 } else {
444 pd->stat.ps_drop += ntohs(header->lctr);
445 }
446 }
447 }
448
449 if ((header->type & 0x7f) == ERF_TYPE_PAD) {
450 continue;
451 }
452
453 num_ext_hdr = dag_erf_ext_header_count(dp, rlen);
454
455 /* ERF encapsulation */
456 /* The Extensible Record Format is not dropped for this kind of encapsulation,
457 * and will be handled as a pseudo header by the decoding application.
458 * The information carried in the ERF header and in the optional subheader (if present)
459 * could be merged with the libpcap information, to offer a better decoding.
460 * The packet length is
461 * o the length of the packet on the link (header->wlen),
462 * o plus the length of the ERF header (dag_record_size), as the length of the
463 * pseudo header will be adjusted during the decoding,
464 * o plus the length of the optional subheader (if present).
465 *
466 * The capture length is header.rlen and the byte stuffing for alignment will be dropped
467 * if the capture length is greater than the packet length.
468 */
469 if (p->linktype == DLT_ERF) {
470 packet_len = ntohs(header->wlen) + dag_record_size;
471 caplen = rlen;
472 switch ((header->type & 0x7f)) {
473 case ERF_TYPE_MC_AAL5:
474 case ERF_TYPE_MC_ATM:
475 case ERF_TYPE_MC_HDLC:
476 case ERF_TYPE_MC_RAW_CHANNEL:
477 case ERF_TYPE_MC_RAW:
478 case ERF_TYPE_MC_AAL2:
479 case ERF_TYPE_COLOR_MC_HDLC_POS:
480 packet_len += 4; /* MC header */
481 break;
482
483 case ERF_TYPE_COLOR_HASH_ETH:
484 case ERF_TYPE_DSM_COLOR_ETH:
485 case ERF_TYPE_COLOR_ETH:
486 case ERF_TYPE_ETH:
487 packet_len += 2; /* ETH header */
488 break;
489 } /* switch type */
490
491 /* Include ERF extension headers */
492 packet_len += (8 * num_ext_hdr);
493
494 if (caplen > packet_len) {
495 caplen = packet_len;
496 }
497 } else {
498 /* Other kind of encapsulation according to the header Type */
499
500 /* Skip over generic ERF header */
501 dp += dag_record_size;
502 /* Skip over extension headers */
503 dp += 8 * num_ext_hdr;
504
505 switch((header->type & 0x7f)) {
506 case ERF_TYPE_ATM:
507 case ERF_TYPE_AAL5:
508 if ((header->type & 0x7f) == ERF_TYPE_AAL5) {
509 packet_len = ntohs(header->wlen);
510 caplen = rlen - dag_record_size;
511 }
512 case ERF_TYPE_MC_ATM:
513 if ((header->type & 0x7f) == ERF_TYPE_MC_ATM) {
514 caplen = packet_len = ATM_CELL_SIZE;
515 dp+=4;
516 }
517 case ERF_TYPE_MC_AAL5:
518 if ((header->type & 0x7f) == ERF_TYPE_MC_AAL5) {
519 packet_len = ntohs(header->wlen);
520 caplen = rlen - dag_record_size - 4;
521 dp+=4;
522 }
523 /* Skip over extension headers */
524 caplen -= (8 * num_ext_hdr);
525
526 if ((header->type & 0x7f) == ERF_TYPE_ATM) {
527 caplen = packet_len = ATM_CELL_SIZE;
528 }
529 if (p->linktype == DLT_SUNATM) {
530 struct sunatm_hdr *sunatm = (struct sunatm_hdr *)dp;
531 unsigned long rawatm;
532
533 rawatm = ntohl(*((unsigned long *)dp));
534 sunatm->vci = htons((rawatm >> 4) & 0xffff);
535 sunatm->vpi = (rawatm >> 20) & 0x00ff;
536 sunatm->flags = ((header->flags.iface & 1) ? 0x80 : 0x00) |
537 ((sunatm->vpi == 0 && sunatm->vci == htons(5)) ? 6 :
538 ((sunatm->vpi == 0 && sunatm->vci == htons(16)) ? 5 :
539 ((dp[ATM_HDR_SIZE] == 0xaa &&
540 dp[ATM_HDR_SIZE+1] == 0xaa &&
541 dp[ATM_HDR_SIZE+2] == 0x03) ? 2 : 1)));
542
543 } else if (p->linktype == DLT_ATM_RFC1483) {
544 packet_len -= ATM_HDR_SIZE;
545 caplen -= ATM_HDR_SIZE;
546 dp += ATM_HDR_SIZE;
547 } else
548 continue;
549 break;
550
551 case ERF_TYPE_COLOR_HASH_ETH:
552 case ERF_TYPE_DSM_COLOR_ETH:
553 case ERF_TYPE_COLOR_ETH:
554 case ERF_TYPE_ETH:
555 if ((p->linktype != DLT_EN10MB) &&
556 (p->linktype != DLT_DOCSIS))
557 continue;
558 packet_len = ntohs(header->wlen);
559 packet_len -= (pd->dag_fcs_bits >> 3);
560 caplen = rlen - dag_record_size - 2;
561 /* Skip over extension headers */
562 caplen -= (8 * num_ext_hdr);
563 if (caplen > packet_len) {
564 caplen = packet_len;
565 }
566 dp += 2;
567 break;
568
569 case ERF_TYPE_COLOR_HASH_POS:
570 case ERF_TYPE_DSM_COLOR_HDLC_POS:
571 case ERF_TYPE_COLOR_HDLC_POS:
572 case ERF_TYPE_HDLC_POS:
573 if ((p->linktype != DLT_CHDLC) &&
574 (p->linktype != DLT_PPP_SERIAL) &&
575 (p->linktype != DLT_FRELAY))
576 continue;
577 packet_len = ntohs(header->wlen);
578 packet_len -= (pd->dag_fcs_bits >> 3);
579 caplen = rlen - dag_record_size;
580 /* Skip over extension headers */
581 caplen -= (8 * num_ext_hdr);
582 if (caplen > packet_len) {
583 caplen = packet_len;
584 }
585 break;
586
587 case ERF_TYPE_COLOR_MC_HDLC_POS:
588 case ERF_TYPE_MC_HDLC:
589 if ((p->linktype != DLT_CHDLC) &&
590 (p->linktype != DLT_PPP_SERIAL) &&
591 (p->linktype != DLT_FRELAY) &&
592 (p->linktype != DLT_MTP2) &&
593 (p->linktype != DLT_MTP2_WITH_PHDR) &&
594 (p->linktype != DLT_LAPD))
595 continue;
596 packet_len = ntohs(header->wlen);
597 packet_len -= (pd->dag_fcs_bits >> 3);
598 caplen = rlen - dag_record_size - 4;
599 /* Skip over extension headers */
600 caplen -= (8 * num_ext_hdr);
601 if (caplen > packet_len) {
602 caplen = packet_len;
603 }
604 /* jump the MC_HDLC_HEADER */
605 dp += 4;
606 #ifdef DLT_MTP2_WITH_PHDR
607 if (p->linktype == DLT_MTP2_WITH_PHDR) {
608 /* Add the MTP2 Pseudo Header */
609 caplen += MTP2_HDR_LEN;
610 packet_len += MTP2_HDR_LEN;
611
612 TempPkt[MTP2_SENT_OFFSET] = 0;
613 TempPkt[MTP2_ANNEX_A_USED_OFFSET] = MTP2_ANNEX_A_USED_UNKNOWN;
614 *(TempPkt+MTP2_LINK_NUMBER_OFFSET) = ((header->rec.mc_hdlc.mc_header>>16)&0x01);
615 *(TempPkt+MTP2_LINK_NUMBER_OFFSET+1) = ((header->rec.mc_hdlc.mc_header>>24)&0xff);
616 memcpy(TempPkt+MTP2_HDR_LEN, dp, caplen);
617 dp = TempPkt;
618 }
619 #endif
620 break;
621
622 case ERF_TYPE_IPV4:
623 if ((p->linktype != DLT_RAW) &&
624 (p->linktype != DLT_IPV4))
625 continue;
626 packet_len = ntohs(header->wlen);
627 caplen = rlen - dag_record_size;
628 /* Skip over extension headers */
629 caplen -= (8 * num_ext_hdr);
630 if (caplen > packet_len) {
631 caplen = packet_len;
632 }
633 break;
634
635 case ERF_TYPE_IPV6:
636 if ((p->linktype != DLT_RAW) &&
637 (p->linktype != DLT_IPV6))
638 continue;
639 packet_len = ntohs(header->wlen);
640 caplen = rlen - dag_record_size;
641 /* Skip over extension headers */
642 caplen -= (8 * num_ext_hdr);
643 if (caplen > packet_len) {
644 caplen = packet_len;
645 }
646 break;
647
648 /* These types have no matching 'native' DLT, but can be used with DLT_ERF above */
649 case ERF_TYPE_MC_RAW:
650 case ERF_TYPE_MC_RAW_CHANNEL:
651 case ERF_TYPE_IP_COUNTER:
652 case ERF_TYPE_TCP_FLOW_COUNTER:
653 case ERF_TYPE_INFINIBAND:
654 case ERF_TYPE_RAW_LINK:
655 case ERF_TYPE_INFINIBAND_LINK:
656 default:
657 /* Unhandled ERF type.
658 * Ignore rather than generating error
659 */
660 continue;
661 } /* switch type */
662
663 } /* ERF encapsulation */
664
665 if (caplen > p->snapshot)
666 caplen = p->snapshot;
667
668 /* Run the packet filter if there is one. */
669 if ((p->fcode.bf_insns == NULL) || bpf_filter(p->fcode.bf_insns, dp, packet_len, caplen)) {
670
671 /* convert between timestamp formats */
672 register unsigned long long ts;
673
674 if (IS_BIGENDIAN()) {
675 ts = SWAPLL(header->ts);
676 } else {
677 ts = header->ts;
678 }
679
680 switch (p->opt.tstamp_precision) {
681 case PCAP_TSTAMP_PRECISION_NANO:
682 ticks_per_second = 1000000000;
683 break;
684 case PCAP_TSTAMP_PRECISION_MICRO:
685 default:
686 ticks_per_second = 1000000;
687 break;
688
689 }
690 pcap_header.ts.tv_sec = ts >> 32;
691 ts = (ts & 0xffffffffULL) * ticks_per_second;
692 ts += 0x80000000; /* rounding */
693 pcap_header.ts.tv_usec = ts >> 32;
694 if (pcap_header.ts.tv_usec >= ticks_per_second) {
695 pcap_header.ts.tv_usec -= ticks_per_second;
696 pcap_header.ts.tv_sec++;
697 }
698
699 /* Fill in our own header data */
700 pcap_header.caplen = caplen;
701 pcap_header.len = packet_len;
702
703 /* Count the packet. */
704 pd->stat.ps_recv++;
705
706 /* Call the user supplied callback function */
707 callback(user, &pcap_header, dp);
708
709 /* Only count packets that pass the filter, for consistency with standard Linux behaviour. */
710 processed++;
711 if (processed == cnt && !PACKET_COUNT_IS_UNLIMITED(cnt))
712 {
713 /* Reached the user-specified limit. */
714 return cnt;
715 }
716 }
717 }
718
719 return processed;
720 }
721
722 static int
723 dag_inject(pcap_t *p, const void *buf _U_, size_t size _U_)
724 {
725 strlcpy(p->errbuf, "Sending packets isn't supported on DAG cards",
726 PCAP_ERRBUF_SIZE);
727 return (-1);
728 }
729
730 /*
731 * Get a handle for a live capture from the given DAG device. Passing a NULL
732 * device will result in a failure. The promisc flag is ignored because DAG
733 * cards are always promiscuous. The to_ms parameter is used in setting the
734 * API polling parameters.
735 *
736 * snaplen is now also ignored, until we get per-stream slen support. Set
737 * slen with approprite DAG tool BEFORE pcap_activate().
738 *
739 * See also pcap(3).
740 */
741 static int dag_activate(pcap_t* p)
742 {
743 struct pcap_dag *pd = p->priv;
744 char *s;
745 int n;
746 daginf_t* daginf;
747 char * newDev = NULL;
748 char * device = p->opt.device;
749 dag_size_t mindata;
750 struct timeval maxwait;
751 struct timeval poll;
752
753 if (device == NULL) {
754 pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "device is NULL");
755 return -1;
756 }
757
758 /* Initialize some components of the pcap structure. */
759 newDev = (char *)malloc(strlen(device) + 16);
760 if (newDev == NULL) {
761 pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
762 errno, "Can't allocate string for device name");
763 goto fail;
764 }
765
766 /* Parse input name to get dag device and stream number if provided */
767 if (dag_parse_name(device, newDev, strlen(device) + 16, &pd->dag_stream) < 0) {
768 pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
769 errno, "dag_parse_name");
770 goto fail;
771 }
772 device = newDev;
773
774 if (pd->dag_stream%2) {
775 pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "dag_parse_name: tx (even numbered) streams not supported for capture");
776 goto fail;
777 }
778
779 /* setup device parameters */
780 if((p->fd = dag_open((char *)device)) < 0) {
781 pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
782 errno, "dag_open %s", device);
783 goto fail;
784 }
785
786 /* Open requested stream. Can fail if already locked or on error */
787 if (dag_attach_stream64(p->fd, pd->dag_stream, 0, 0) < 0) {
788 pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
789 errno, "dag_attach_stream");
790 goto failclose;
791 }
792
793 /* Set up default poll parameters for stream
794 * Can be overridden by pcap_set_nonblock()
795 */
796 if (dag_get_stream_poll64(p->fd, pd->dag_stream,
797 &mindata, &maxwait, &poll) < 0) {
798 pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
799 errno, "dag_get_stream_poll");
800 goto faildetach;
801 }
802
803 /* Use the poll time as the required select timeout for callers
804 * who are using select()/etc. in an event loop waiting for
805 * packets to arrive.
806 */
807 pd->required_select_timeout = poll;
808 p->required_select_timeout = &pd->required_select_timeout;
809
810 /*
811 * Turn a negative snapshot value (invalid), a snapshot value of
812 * 0 (unspecified), or a value bigger than the normal maximum
813 * value, into the maximum allowed value.
814 *
815 * If some application really *needs* a bigger snapshot
816 * length, we should just increase MAXIMUM_SNAPLEN.
817 */
818 if (p->snapshot <= 0 || p->snapshot > MAXIMUM_SNAPLEN)
819 p->snapshot = MAXIMUM_SNAPLEN;
820
821 if (p->opt.immediate) {
822 /* Call callback immediately.
823 * XXX - is this the right way to p this?
824 */
825 mindata = 0;
826 } else {
827 /* Amount of data to collect in Bytes before calling callbacks.
828 * Important for efficiency, but can introduce latency
829 * at low packet rates if to_ms not set!
830 */
831 mindata = 65536;
832 }
833
834 /* Obey opt.timeout (was to_ms) if supplied. This is a good idea!
835 * Recommend 10-100ms. Calls will time out even if no data arrived.
836 */
837 maxwait.tv_sec = p->opt.timeout/1000;
838 maxwait.tv_usec = (p->opt.timeout%1000) * 1000;
839
840 if (dag_set_stream_poll64(p->fd, pd->dag_stream,
841 mindata, &maxwait, &poll) < 0) {
842 pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
843 errno, "dag_set_stream_poll");
844 goto faildetach;
845 }
846
847 /* XXX Not calling dag_configure() to set slen; this is unsafe in
848 * multi-stream environments as the gpp config is global.
849 * Once the firmware provides 'per-stream slen' this can be supported
850 * again via the Config API without side-effects */
851 #if 0
852 /* set the card snap length to the specified snaplen parameter */
853 /* This is a really bad idea, as different cards have different
854 * valid slen ranges. Should fix in Config API. */
855 if (p->snapshot == 0 || p->snapshot > MAX_DAG_SNAPLEN) {
856 p->snapshot = MAX_DAG_SNAPLEN;
857 } else if (snaplen < MIN_DAG_SNAPLEN) {
858 p->snapshot = MIN_DAG_SNAPLEN;
859 }
860 /* snap len has to be a multiple of 4 */
861 #endif
862
863 if(dag_start_stream(p->fd, pd->dag_stream) < 0) {
864 pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
865 errno, "dag_start_stream %s", device);
866 goto faildetach;
867 }
868
869 /*
870 * Important! You have to ensure bottom is properly
871 * initialized to zero on startup, it won't give you
872 * a compiler warning if you make this mistake!
873 */
874 pd->dag_mem_bottom = 0;
875 pd->dag_mem_top = 0;
876
877 /*
878 * Find out how many FCS bits we should strip.
879 * First, query the card to see if it strips the FCS.
880 */
881 daginf = dag_info(p->fd);
882 if ((0x4200 == daginf->device_code) || (0x4230 == daginf->device_code)) {
883 /* DAG 4.2S and 4.23S already strip the FCS. Stripping the final word again truncates the packet. */
884 pd->dag_fcs_bits = 0;
885
886 /* Note that no FCS will be supplied. */
887 p->linktype_ext = LT_FCS_DATALINK_EXT(0);
888 } else {
889 /*
890 * Start out assuming it's 32 bits.
891 */
892 pd->dag_fcs_bits = 32;
893
894 /* Allow an environment variable to override. */
895 if ((s = getenv("ERF_FCS_BITS")) != NULL) {
896 if ((n = atoi(s)) == 0 || n == 16 || n == 32) {
897 pd->dag_fcs_bits = n;
898 } else {
899 pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
900 "pcap_activate %s: bad ERF_FCS_BITS value (%d) in environment", device, n);
901 goto failstop;
902 }
903 }
904
905 /*
906 * Did the user request that they not be stripped?
907 */
908 if ((s = getenv("ERF_DONT_STRIP_FCS")) != NULL) {
909 /* Yes. Note the number of bytes that will be
910 supplied. */
911 p->linktype_ext = LT_FCS_DATALINK_EXT(pd->dag_fcs_bits/16);
912
913 /* And don't strip them. */
914 pd->dag_fcs_bits = 0;
915 }
916 }
917
918 pd->dag_timeout = p->opt.timeout;
919
920 p->linktype = -1;
921 if (dag_get_datalink(p) < 0)
922 goto failstop;
923
924 p->bufsize = 0;
925
926 if (new_pcap_dag(p) < 0) {
927 pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
928 errno, "new_pcap_dag %s", device);
929 goto failstop;
930 }
931
932 /*
933 * "select()" and "poll()" don't work on DAG device descriptors.
934 */
935 p->selectable_fd = -1;
936
937 if (newDev != NULL) {
938 free((char *)newDev);
939 }
940
941 p->read_op = dag_read;
942 p->inject_op = dag_inject;
943 p->setfilter_op = dag_setfilter;
944 p->setdirection_op = NULL; /* Not implemented.*/
945 p->set_datalink_op = dag_set_datalink;
946 p->getnonblock_op = pcap_getnonblock_fd;
947 p->setnonblock_op = dag_setnonblock;
948 p->stats_op = dag_stats;
949 p->cleanup_op = dag_platform_cleanup;
950 pd->stat.ps_drop = 0;
951 pd->stat.ps_recv = 0;
952 pd->stat.ps_ifdrop = 0;
953 return 0;
954
955 failstop:
956 if (dag_stop_stream(p->fd, pd->dag_stream) < 0) {
957 fprintf(stderr,"dag_stop_stream: %s\n", strerror(errno));
958 }
959
960 faildetach:
961 if (dag_detach_stream(p->fd, pd->dag_stream) < 0)
962 fprintf(stderr,"dag_detach_stream: %s\n", strerror(errno));
963
964 failclose:
965 if (dag_close(p->fd) < 0)
966 fprintf(stderr,"dag_close: %s\n", strerror(errno));
967 delete_pcap_dag(p);
968
969 fail:
970 pcap_cleanup_live_common(p);
971 if (newDev != NULL) {
972 free((char *)newDev);
973 }
974
975 return PCAP_ERROR;
976 }
977
978 pcap_t *dag_create(const char *device, char *ebuf, int *is_ours)
979 {
980 const char *cp;
981 char *cpend;
982 long devnum;
983 pcap_t *p;
984 long stream = 0;
985
986 /* Does this look like a DAG device? */
987 cp = strrchr(device, '/');
988 if (cp == NULL)
989 cp = device;
990 /* Does it begin with "dag"? */
991 if (strncmp(cp, "dag", 3) != 0) {
992 /* Nope, doesn't begin with "dag" */
993 *is_ours = 0;
994 return NULL;
995 }
996 /* Yes - is "dag" followed by a number from 0 to DAG_MAX_BOARDS-1 */
997 cp += 3;
998 devnum = strtol(cp, &cpend, 10);
999 if (*cpend == ':') {
1000 /* Followed by a stream number. */
1001 stream = strtol(++cpend, &cpend, 10);
1002 }
1003
1004 if (cpend == cp || *cpend != '\0') {
1005 /* Not followed by a number. */
1006 *is_ours = 0;
1007 return NULL;
1008 }
1009
1010 if (devnum < 0 || devnum >= DAG_MAX_BOARDS) {
1011 /* Followed by a non-valid number. */
1012 *is_ours = 0;
1013 return NULL;
1014 }
1015
1016 if (stream <0 || stream >= DAG_STREAM_MAX) {
1017 /* Followed by a non-valid stream number. */
1018 *is_ours = 0;
1019 return NULL;
1020 }
1021
1022 /* OK, it's probably ours. */
1023 *is_ours = 1;
1024
1025 p = pcap_create_common(ebuf, sizeof (struct pcap_dag));
1026 if (p == NULL)
1027 return NULL;
1028
1029 p->activate_op = dag_activate;
1030
1031 /*
1032 * We claim that we support microsecond and nanosecond time
1033 * stamps.
1034 *
1035 * XXX Our native precision is 2^-32s, but libpcap doesn't support
1036 * power of two precisions yet. We can convert to either MICRO or NANO.
1037 */
1038 p->tstamp_precision_count = 2;
1039 p->tstamp_precision_list = malloc(2 * sizeof(u_int));
1040 if (p->tstamp_precision_list == NULL) {
1041 pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
1042 errno, "malloc");
1043 pcap_close(p);
1044 return NULL;
1045 }
1046 p->tstamp_precision_list[0] = PCAP_TSTAMP_PRECISION_MICRO;
1047 p->tstamp_precision_list[1] = PCAP_TSTAMP_PRECISION_NANO;
1048 return p;
1049 }
1050
1051 static int
1052 dag_stats(pcap_t *p, struct pcap_stat *ps) {
1053 struct pcap_dag *pd = p->priv;
1054
1055 /* This needs to be filled out correctly. Hopefully a dagapi call will
1056 provide all necessary information.
1057 */
1058 /*pd->stat.ps_recv = 0;*/
1059 /*pd->stat.ps_drop = 0;*/
1060
1061 *ps = pd->stat;
1062
1063 return 0;
1064 }
1065
1066 /*
1067 * Add all DAG devices.
1068 */
1069 int
1070 dag_findalldevs(pcap_if_list_t *devlistp, char *errbuf)
1071 {
1072 char name[12]; /* XXX - pick a size */
1073 int ret = 0;
1074 int c;
1075 char dagname[DAGNAME_BUFSIZE];
1076 int dagstream;
1077 int dagfd;
1078 dag_card_inf_t *inf;
1079 char *description;
1080 int stream, rxstreams;
1081
1082 /* Try all the DAGs 0-DAG_MAX_BOARDS */
1083 for (c = 0; c < DAG_MAX_BOARDS; c++) {
1084 pcap_snprintf(name, 12, "dag%d", c);
1085 if (-1 == dag_parse_name(name, dagname, DAGNAME_BUFSIZE, &dagstream))
1086 {
1087 (void) pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE,
1088 "dag: device name %s can't be parsed", name);
1089 return -1;
1090 }
1091 if ( (dagfd = dag_open(dagname)) >= 0 ) {
1092 description = NULL;
1093 if ((inf = dag_pciinfo(dagfd)))
1094 description = dag_device_name(inf->device_code, 1);
1095 if (add_dev(devlistp, name, 0, description, errbuf) == NULL) {
1096 /*
1097 * Failure.
1098 */
1099 ret = -1;
1100 }
1101 rxstreams = dag_rx_get_stream_count(dagfd);
1102 for(stream=0;stream<DAG_STREAM_MAX;stream+=2) {
1103 if (0 == dag_attach_stream(dagfd, stream, 0, 0)) {
1104 dag_detach_stream(dagfd, stream);
1105
1106 pcap_snprintf(name, 10, "dag%d:%d", c, stream);
1107 if (add_dev(devlistp, name, 0, description, errbuf) == NULL) {
1108 /*
1109 * Failure.
1110 */
1111 ret = -1;
1112 }
1113
1114 rxstreams--;
1115 if(rxstreams <= 0) {
1116 break;
1117 }
1118 }
1119 }
1120 dag_close(dagfd);
1121 }
1122
1123 }
1124 return (ret);
1125 }
1126
1127 /*
1128 * Installs the given bpf filter program in the given pcap structure. There is
1129 * no attempt to store the filter in kernel memory as that is not supported
1130 * with DAG cards.
1131 */
1132 static int
1133 dag_setfilter(pcap_t *p, struct bpf_program *fp)
1134 {
1135 if (!p)
1136 return -1;
1137 if (!fp) {
1138 strncpy(p->errbuf, "setfilter: No filter specified",
1139 sizeof(p->errbuf));
1140 return -1;
1141 }
1142
1143 /* Make our private copy of the filter */
1144
1145 if (install_bpf_program(p, fp) < 0)
1146 return -1;
1147
1148 return (0);
1149 }
1150
1151 static int
1152 dag_set_datalink(pcap_t *p, int dlt)
1153 {
1154 p->linktype = dlt;
1155
1156 return (0);
1157 }
1158
1159 static int
1160 dag_setnonblock(pcap_t *p, int nonblock)
1161 {
1162 struct pcap_dag *pd = p->priv;
1163 dag_size_t mindata;
1164 struct timeval maxwait;
1165 struct timeval poll;
1166
1167 /*
1168 * Set non-blocking mode on the FD.
1169 * XXX - is that necessary? If not, don't bother calling it,
1170 * and have a "dag_getnonblock()" function that looks at
1171 * "pd->dag_flags".
1172 */
1173 if (pcap_setnonblock_fd(p, nonblock) < 0)
1174 return (-1);
1175
1176 if (dag_get_stream_poll64(p->fd, pd->dag_stream,
1177 &mindata, &maxwait, &poll) < 0) {
1178 pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
1179 errno, "dag_get_stream_poll");
1180 return -1;
1181 }
1182
1183 /* Amount of data to collect in Bytes before calling callbacks.
1184 * Important for efficiency, but can introduce latency
1185 * at low packet rates if to_ms not set!
1186 */
1187 if(nonblock)
1188 mindata = 0;
1189 else
1190 mindata = 65536;
1191
1192 if (dag_set_stream_poll64(p->fd, pd->dag_stream,
1193 mindata, &maxwait, &poll) < 0) {
1194 pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
1195 errno, "dag_set_stream_poll");
1196 return -1;
1197 }
1198
1199 if (nonblock) {
1200 pd->dag_flags |= DAGF_NONBLOCK;
1201 } else {
1202 pd->dag_flags &= ~DAGF_NONBLOCK;
1203 }
1204 return (0);
1205 }
1206
1207 static int
1208 dag_get_datalink(pcap_t *p)
1209 {
1210 struct pcap_dag *pd = p->priv;
1211 int index=0, dlt_index=0;
1212 uint8_t types[255];
1213
1214 memset(types, 0, 255);
1215
1216 if (p->dlt_list == NULL && (p->dlt_list = malloc(255*sizeof(*(p->dlt_list)))) == NULL) {
1217 pcap_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
1218 errno, "malloc");
1219 return (-1);
1220 }
1221
1222 p->linktype = 0;
1223
1224 #ifdef HAVE_DAG_GET_STREAM_ERF_TYPES
1225 /* Get list of possible ERF types for this card */
1226 if (dag_get_stream_erf_types(p->fd, pd->dag_stream, types, 255) < 0) {
1227 pcap_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
1228 errno, "dag_get_stream_erf_types");
1229 return (-1);
1230 }
1231
1232 while (types[index]) {
1233
1234 #elif defined HAVE_DAG_GET_ERF_TYPES
1235 /* Get list of possible ERF types for this card */
1236 if (dag_get_erf_types(p->fd, types, 255) < 0) {
1237 pcap_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
1238 errno, "dag_get_erf_types");
1239 return (-1);
1240 }
1241
1242 while (types[index]) {
1243 #else
1244 /* Check the type through a dagapi call. */
1245 types[index] = dag_linktype(p->fd);
1246
1247 {
1248 #endif
1249 switch((types[index] & 0x7f)) {
1250
1251 case ERF_TYPE_HDLC_POS:
1252 case ERF_TYPE_COLOR_HDLC_POS:
1253 case ERF_TYPE_DSM_COLOR_HDLC_POS:
1254 case ERF_TYPE_COLOR_HASH_POS:
1255
1256 if (p->dlt_list != NULL) {
1257 p->dlt_list[dlt_index++] = DLT_CHDLC;
1258 p->dlt_list[dlt_index++] = DLT_PPP_SERIAL;
1259 p->dlt_list[dlt_index++] = DLT_FRELAY;
1260 }
1261 if(!p->linktype)
1262 p->linktype = DLT_CHDLC;
1263 break;
1264
1265 case ERF_TYPE_ETH:
1266 case ERF_TYPE_COLOR_ETH:
1267 case ERF_TYPE_DSM_COLOR_ETH:
1268 case ERF_TYPE_COLOR_HASH_ETH:
1269 /*
1270 * This is (presumably) a real Ethernet capture; give it a
1271 * link-layer-type list with DLT_EN10MB and DLT_DOCSIS, so
1272 * that an application can let you choose it, in case you're
1273 * capturing DOCSIS traffic that a Cisco Cable Modem
1274 * Termination System is putting out onto an Ethernet (it
1275 * doesn't put an Ethernet header onto the wire, it puts raw
1276 * DOCSIS frames out on the wire inside the low-level
1277 * Ethernet framing).
1278 */
1279 if (p->dlt_list != NULL) {
1280 p->dlt_list[dlt_index++] = DLT_EN10MB;
1281 p->dlt_list[dlt_index++] = DLT_DOCSIS;
1282 }
1283 if(!p->linktype)
1284 p->linktype = DLT_EN10MB;
1285 break;
1286
1287 case ERF_TYPE_ATM:
1288 case ERF_TYPE_AAL5:
1289 case ERF_TYPE_MC_ATM:
1290 case ERF_TYPE_MC_AAL5:
1291 if (p->dlt_list != NULL) {
1292 p->dlt_list[dlt_index++] = DLT_ATM_RFC1483;
1293 p->dlt_list[dlt_index++] = DLT_SUNATM;
1294 }
1295 if(!p->linktype)
1296 p->linktype = DLT_ATM_RFC1483;
1297 break;
1298
1299 case ERF_TYPE_COLOR_MC_HDLC_POS:
1300 case ERF_TYPE_MC_HDLC:
1301 if (p->dlt_list != NULL) {
1302 p->dlt_list[dlt_index++] = DLT_CHDLC;
1303 p->dlt_list[dlt_index++] = DLT_PPP_SERIAL;
1304 p->dlt_list[dlt_index++] = DLT_FRELAY;
1305 p->dlt_list[dlt_index++] = DLT_MTP2;
1306 p->dlt_list[dlt_index++] = DLT_MTP2_WITH_PHDR;
1307 p->dlt_list[dlt_index++] = DLT_LAPD;
1308 }
1309 if(!p->linktype)
1310 p->linktype = DLT_CHDLC;
1311 break;
1312
1313 case ERF_TYPE_IPV4:
1314 if (p->dlt_list != NULL) {
1315 p->dlt_list[dlt_index++] = DLT_RAW;
1316 p->dlt_list[dlt_index++] = DLT_IPV4;
1317 }
1318 if(!p->linktype)
1319 p->linktype = DLT_RAW;
1320 break;
1321
1322 case ERF_TYPE_IPV6:
1323 if (p->dlt_list != NULL) {
1324 p->dlt_list[dlt_index++] = DLT_RAW;
1325 p->dlt_list[dlt_index++] = DLT_IPV6;
1326 }
1327 if(!p->linktype)
1328 p->linktype = DLT_RAW;
1329 break;
1330
1331 case ERF_TYPE_LEGACY:
1332 case ERF_TYPE_MC_RAW:
1333 case ERF_TYPE_MC_RAW_CHANNEL:
1334 case ERF_TYPE_IP_COUNTER:
1335 case ERF_TYPE_TCP_FLOW_COUNTER:
1336 case ERF_TYPE_INFINIBAND:
1337 case ERF_TYPE_RAW_LINK:
1338 case ERF_TYPE_INFINIBAND_LINK:
1339 case ERF_TYPE_META:
1340 default:
1341 /* Libpcap cannot deal with these types yet */
1342 /* Add no 'native' DLTs, but still covered by DLT_ERF */
1343 break;
1344
1345 } /* switch */
1346 index++;
1347 }
1348
1349 p->dlt_list[dlt_index++] = DLT_ERF;
1350
1351 p->dlt_count = dlt_index;
1352
1353 if(!p->linktype)
1354 p->linktype = DLT_ERF;
1355
1356 return p->linktype;
1357 }
1358
1359 #ifdef DAG_ONLY
1360 /*
1361 * This libpcap build supports only DAG cards, not regular network
1362 * interfaces.
1363 */
1364
1365 /*
1366 * There are no regular interfaces, just DAG interfaces.
1367 */
1368 int
1369 pcap_platform_finddevs(pcap_if_list_t *devlistp _U_, char *errbuf)
1370 {
1371 return (0);
1372 }
1373
1374 /*
1375 * Attempts to open a regular interface fail.
1376 */
1377 pcap_t *
1378 pcap_create_interface(const char *device, char *errbuf)
1379 {
1380 pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE,
1381 "This version of libpcap only supports DAG cards");
1382 return NULL;
1383 }
1384
1385 /*
1386 * Libpcap version string.
1387 */
1388 const char *
1389 pcap_lib_version(void)
1390 {
1391 return (PCAP_VERSION_STRING " (DAG-only)");
1392 }
1393 #endif