From: "Ricardo Tubío" <rtpardavila@gmail.com>
To: netdev@vger.kernel.org
Subject: Re: Single socket with TX_RING and RX_RING
Date: Thu, 16 May 2013 11:01:17 +0000 (UTC) [thread overview]
Message-ID: <loom.20130516T125157-378@post.gmane.org> (raw)
In-Reply-To: 20130516104541.GB18282@orbit.nwl.cc
Phil Sutter <phil <at> nwl.cc> writes:
> So you do not call init_ring() twice as one may imply when reading your
> first mail? Please provide a complete code sample.
>
Yes, I call it twice. The problem is that if I call it twice with the same
socket_fd, the second time I call it I get the EBUSY error from kernel. I
have to use two different sockets (two different socket_fd's, therefore) in
order to workaround this issue.
The code I use for calling "init_ring" is the one below. If in function
"init_rings", instead of using two different sockets (rx_socket_fd and
tx_socket_fd), I use a single socket, I get the EBUSY error from kernel.
Hope this clarifies, Cardo.
>>>>>>>>>>>>>>>>> FULL CODE EXAMPLE
/* init_rings */
int init_rings(ll_socket_t *ll_socket)
{
// 1) initialize rx ring
if ( ( ll_socket->rx_ring_buffer
= init_ring(ll_socket->rx_socket_fd, PACKET_RX_RING) ) == NULL )
{
handle_app_error("Could not set initialize RX ring.");
}
// 2) initialize tx ring
if ( ( ll_socket->tx_ring_buffer
= init_ring(ll_socket->tx_socket_fd, PACKET_TX_RING) ) == NULL )
{
handle_app_error("Could not set initialize TX ring.");
}
// 3) set destination address for both kernel rings
if ( set_sockaddr_ll(ll_socket) < 0 )
{
handle_app_error("Could not set sockaddr_ll for TX/RX rings.");
}
return(EX_OK);
}
/* init_ring */
void *init_ring(const int socket_fd, const int type)
{
void *ring = NULL;
int ring_access_flags = PROT_READ | PROT_WRITE;
tpacket_req_t *p = init_tpacket_req(FRAMES_PER_RING);
int ring_len = ( p->tp_block_size ) * ( p->tp_block_nr );
if ( setsockopt(socket_fd, SOL_PACKET, type, p, LEN__TPACKET_REQ) < 0 )
{
handle_sys_error("Setting socket options for this ring");
}
// 3) open ring
if ( ( ring = mmap(NULL, ring_len, ring_access_flags, MAP_SHARED,
socket_fd, 0) ) == NULL )
{
log_sys_error("mmap()ing error");
}
return(ring);
}
/* init_tpacket_req */
tpacket_req_t *init_tpacket_req(const int frames_per_ring)
{
tpacket_req_t *t = new_tpacket_req();
t->tp_block_size = frames_per_ring * getpagesize();
t->tp_block_nr = 1;
t->tp_frame_size = getpagesize();
t->tp_frame_nr = frames_per_ring;
return(t);
}
>>>>>>>>>>>>>>>>>
next prev parent reply other threads:[~2013-05-16 11:01 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-15 12:53 Single socket with TX_RING and RX_RING Ricardo Tubío
2013-05-15 13:20 ` Daniel Borkmann
2013-05-15 13:32 ` Ricardo Tubío
2013-05-15 14:47 ` Daniel Borkmann
2013-05-15 14:52 ` Daniel Borkmann
2013-05-15 14:58 ` Ricardo Tubío
2013-05-15 15:04 ` Daniel Borkmann
2013-05-20 20:50 ` Paul Chavent
2013-05-15 22:44 ` Phil Sutter
2013-05-16 9:18 ` Ricardo Tubío
2013-05-16 10:45 ` Phil Sutter
2013-05-16 11:01 ` Ricardo Tubío [this message]
2013-05-16 11:14 ` Daniel Borkmann
2013-05-16 11:52 ` Phil Sutter
2013-05-20 20:54 ` Paul Chavent
2013-05-22 19:36 ` Ricardo Tubío
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=loom.20130516T125157-378@post.gmane.org \
--to=rtpardavila@gmail.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).