All of lore.kernel.org
 help / color / mirror / Atom feed
* Single socket with TX_RING and RX_RING
@ 2013-05-15 12:53 Ricardo Tubío
  2013-05-15 13:20 ` Daniel Borkmann
  2013-05-15 22:44 ` Phil Sutter
  0 siblings, 2 replies; 16+ messages in thread
From: Ricardo Tubío @ 2013-05-15 12:53 UTC (permalink / raw)
  To: netdev

Once I tell kernel to export the TX_RING through setsockopt() (see code
below) I always get an error (EBUSY) if i try to tell kernel to export the
RX_RING with the same socket descriptor. Therefore, I have to open an
additional socket for the RX_RING and I require of two sockets when I though
that I would only require of one socket for both TX and RX using mmap()ed
memory.

Do I need both sockets or am I doing something wrong?

Code: 

/* init_ring; type = {PACKET_TX_RING, PACKET_RX_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 )
	{
		log_sys_error("Setting socket options for this ring");
	}

	// 2) 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);
	
}

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2013-05-22 19:36 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.