- Timestamp:
- 12/06/12 11:10:16 (10 years ago)
- 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:
- 90e8d92
- Parents:
- a464de7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_linux.c
rb4c3f61 r6ba84d9 77 77 */ 78 78 #define MAX_ORDER 10 79 static unsigned int max_order = MAX_ORDER;80 79 81 80 /* Cached page size, the page size shoudn't be changing */ … … 142 141 * support the format directly. 143 142 */ 143 144 144 145 #define PACKET_RX_RING 5 145 146 #define PACKET_VERSION 10 … … 152 153 #define TPACKET_ALIGNMENT 16 153 154 #define TPACKET_ALIGN(x) (((x)+TPACKET_ALIGNMENT-1)&~(TPACKET_ALIGNMENT-1)) 154 #define TPACKET 2_HDRLEN (TPACKET_ALIGN(sizeof(struct tpacket2_hdr)) + sizeof(struct sockaddr_ll))155 #define TPACKET_HDRLEN (TPACKET_ALIGN(sizeof(struct tpacket2_hdr)) + sizeof(struct sockaddr_ll)) 155 156 156 157 enum tpacket_versions { … … 205 206 /* The current frame number within the rx ring */ 206 207 int rxring_offset; 207 /* The format this trace is using linuxring or linuxnative*/208 /* The actual format being used - ring vs int */ 208 209 libtrace_rt_types_t format; 209 210 /* The current ring buffer layout */ 210 211 struct tpacket_req req; 212 /* Used to determine buffer size for the ring buffer */ 213 uint32_t max_order; 211 214 }; 212 215 … … 254 257 /* The format this trace is using linuxring or linuxnative */ 255 258 libtrace_rt_types_t format; 259 /* Used to determine buffer size for the ring buffer */ 260 uint32_t max_order; 256 261 }; 257 262 … … 259 264 #define GET_SOCKADDR_HDR(x) ((struct sockaddr_ll *) (((char *) (x))\ 260 265 + TPACKET_ALIGN(sizeof(struct tpacket2_hdr)))) 261 262 #define TPACKET_HDRLEN TPACKET2_HDRLEN263 266 264 267 #define FORMAT(x) ((struct linux_format_data_t*)(x)) … … 273 276 274 277 #ifdef HAVE_NETPACKET_PACKET_H 275 276 278 /* 277 279 * Try figure out the best sizes for the ring buffer. Ensure that: … … 286 288 * - Calculates based on max_order and buf_min 287 289 */ 288 static void calculate_buffers(struct tpacket_req * req, int fd, char * uri){ 290 static void calculate_buffers(struct tpacket_req * req, int fd, char * uri, 291 uint32_t max_order){ 289 292 290 293 struct ifreq ifr; 291 unsigned m tu= LIBTRACE_PACKET_BUFSIZE;294 unsigned max_frame = LIBTRACE_PACKET_BUFSIZE; 292 295 pagesize = getpagesize(); 293 296 297 strcpy(ifr.ifr_name, uri); 294 298 /* Don't bother trying to set frame size above mtu linux will drop 295 * these anyway 299 * these anyway. 300 * 301 * Remember, that our frame also has to include a TPACKET header! 296 302 */ 297 strcpy(ifr.ifr_name, uri);298 303 if (ioctl(fd, SIOCGIFMTU, (caddr_t) &ifr) >= 0) 299 m tu = ifr.ifr_mtu;300 if (mtu> LIBTRACE_PACKET_BUFSIZE)301 m tu= LIBTRACE_PACKET_BUFSIZE;304 max_frame = ifr.ifr_mtu + sizeof(struct tpacket2_hdr); 305 if (max_frame > LIBTRACE_PACKET_BUFSIZE) 306 max_frame = LIBTRACE_PACKET_BUFSIZE; 302 307 303 308 /* Calculate frame size */ 304 309 req->tp_frame_size = pagesize; 305 while(req->tp_frame_size < mtu && req->tp_frame_size < LIBTRACE_PACKET_BUFSIZE){ 310 while(req->tp_frame_size < max_frame && 311 req->tp_frame_size < LIBTRACE_PACKET_BUFSIZE){ 306 312 req->tp_frame_size <<= 1; 307 313 } … … 326 332 (req->tp_block_size / req->tp_frame_size); 327 333 328 /*printf("MaxO 0x%x BS 0x%x BN 0x%x FS 0x%x FN 0x%x\n", 334 /* 335 printf("MaxO 0x%x BS 0x%x BN 0x%x FS 0x%x FN 0x%x\n", 329 336 max_order, 330 337 req->tp_block_size, 331 338 req->tp_block_nr, 332 339 req->tp_frame_size, 333 req->tp_frame_nr);*/ 340 req->tp_frame_nr); 341 */ 334 342 335 343 /* In case we have some silly values*/ … … 519 527 int fd, 520 528 struct tpacket_req * req, 521 char ** ring_location){ 529 char ** ring_location, 530 uint32_t *max_order){ 522 531 socklen_t len; 523 532 int val; … … 547 556 */ 548 557 while(1) { 549 if ( max_order <= 0) {558 if (*max_order <= 0) { 550 559 return -1; 551 560 } 552 calculate_buffers(req, fd, uridata );561 calculate_buffers(req, fd, uridata, *max_order); 553 562 if (setsockopt(fd, 554 563 SOL_PACKET, … … 557 566 sizeof(struct tpacket_req)) == -1) { 558 567 if(errno == ENOMEM){ 559 max_order--;568 (*max_order)--; 560 569 } else { 561 570 return -1; … … 584 593 585 594 /* Make it a packetmmap */ 586 if(socket_to_packetmmap(libtrace->uridata, PACKET_RX_RING, FORMAT(libtrace->format_data)->fd, 587 &FORMAT(libtrace->format_data)->req, &FORMAT(libtrace->format_data)->rx_ring) != 0){ 595 if(socket_to_packetmmap(libtrace->uridata, PACKET_RX_RING, 596 FORMAT(libtrace->format_data)->fd, 597 &FORMAT(libtrace->format_data)->req, 598 &FORMAT(libtrace->format_data)->rx_ring, 599 &FORMAT(libtrace->format_data)->max_order) != 0){ 588 600 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, 589 601 "TPACKET2 not supported or ring buffer is too large"); … … 592 604 return -1; 593 605 } 594 606 595 607 return 0; 596 608 } … … 614 626 615 627 /* Make it a packetmmap */ 616 if(socket_to_packetmmap(libtrace->uridata, PACKET_TX_RING, DATAOUT(libtrace)->fd, 617 &DATAOUT(libtrace)->req, &DATAOUT(libtrace)->tx_ring) != 0){ 628 if(socket_to_packetmmap(libtrace->uridata, PACKET_TX_RING, 629 DATAOUT(libtrace)->fd, 630 &DATAOUT(libtrace)->req, 631 &DATAOUT(libtrace)->tx_ring, 632 &DATAOUT(libtrace)->max_order) != 0){ 618 633 trace_set_err_out(libtrace, TRACE_ERR_INIT_FAILED, 619 634 "TPACKET2 not supported or ring buffer is too large"); … … 834 849 TO_TP_HDR(packet->header)->tp_mac, 835 850 TO_TP_HDR(packet->header)->tp_net, 836 TPACKET 2_HDRLEN);851 TPACKET_HDRLEN); 837 852 packet->type = rt_type; 838 853 … … 1024 1039 if (ret < 0) { 1025 1040 if (errno != EINTR) 1026 trace_set_err(libtrace,errno,"poll()");1041 trace_set_err(libtrace,errno,"poll()"); 1027 1042 return -1; 1028 1043 } … … 1333 1348 { 1334 1349 /* 1335 * Need to make frame_length + capture_length = comp elete capture length1350 * Need to make frame_length + capture_length = complete capture length 1336 1351 * so include alligment whitespace. So reverse calculate from packet. 1337 1352 */ … … 1656 1671 1657 1672 void linuxnative_constructor(void) { 1673 /* TODO: once we're happy with ring:, it would be a good idea to 1674 * swap the order of these calls so that ring: is preferred over 1675 * int: if the user just gives an interface name as an input without 1676 * explicitly choosing a format. 1677 */ 1658 1678 register_format(&linuxnative); 1659 1679 register_format(&linuxring);
Note: See TracChangeset
for help on using the changeset viewer.