[RFC][PATCH 0/3] net: per skb control messages

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Octavian Purdila
Date: Wednesday, July 23, 2008 - 3:01 pm

Hi everybody,

These patches are a follow up on two previous [rfc] threads: 
- new sk_buff member: hwstamp [1]
- support for IEEE 1588 [2]

[1] http://www.spinics.net/lists/netdev/msg68804.html
[2] http://www.spinics.net/lists/netdev/msg67799.html

The idea is to associate control messages with skbs - for both 
out-going and in-going traffic. 

The RX case seems pretty straight forward.  

For the TX case, I am queueing an empty (or a clone of the original)
skb (with control messages attached) to the error queue of the socket
the TX skb belongs to.

To make an idea about how would this be used from userspace, I've
added a simple userspace demo for getting TX hardware timestamps.

I still ended up adding a new skb member but since this is a bit more
generic maybe it can offset the cost?

Thanks,
tavi
---
#include <stdlib.h>
#include <string.h>
#include <error.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/poll.h>
#include <sys/uio.h>
#include <netinet/in.h>

typedef unsigned long long __u64;
typedef unsigned long long __u32;

#define SOL_SKB 275

#include "include/linux/skb_cmsg.h"

struct cmsg_tx_tstamp  {
	struct cmsghdr hdr;
	struct skb_tx_tstamp stt __attribute__ ((packed));
};


int main()
{
	char buffer[100];
	struct iovec iovec = {
		.iov_base = buffer,
		.iov_len = sizeof(buffer)
	};
	struct cmsg_tx_tstamp ctt = {
		.hdr = {
			.cmsg_len = sizeof(ctt),
			.cmsg_level = SOL_SKB,
			.cmsg_type = SKB_TX_GET_TSTAMP
		},
		.stt = {
			.cookie = 0x0bad0badbeefbeefULL,
		}
	};
	struct sockaddr_in daddr = {
		.sin_family = AF_INET,
		.sin_port = 8888,
		.sin_addr = { htonl(0x01010101) }
	};
	struct msghdr msg = {
		.msg_iov = &iovec,
		.msg_iovlen = 1,
		.msg_control = &ctt,
		.msg_controllen = sizeof(ctt),
		.msg_name = &daddr,
		.msg_namelen = sizeof(daddr)
	};
	int s=socket(PF_INET, SOCK_DGRAM, 0);
	struct pollfd pollfd = {
		.fd = s,
		.events = POLLERR,
	};

	printf("%d %d %d %llx %llx\n", ctt.hdr.cmsg_len, ctt.hdr.cmsg_level,
	       ctt.hdr.cmsg_type, ctt.stt.cookie, ctt.stt.tstamp);

	if (sendmsg(s, &msg, 0) < 0)
		perror("sendmsg");

	poll(&pollfd, 1, -1);

	if (recvmsg(s, &msg, MSG_ERRQUEUE) < 0)
		perror("recvmsg");

	return printf("%d %d %d %llx %llx\n", ctt.hdr.cmsg_len,
		      ctt.hdr.cmsg_level, ctt.hdr.cmsg_type, ctt.stt.tstamp,
		      ctt.stt.cookie);
}
---
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[RFC][PATCH 0/3] net: per skb control messages, Octavian Purdila, (Wed Jul 23, 3:01 pm)
[RFC][PATCH 1/3] net: per skb control messages, Octavian Purdila, (Wed Jul 23, 3:01 pm)
[RFC][PATCH 2/3] ip: support for SOL_SKB control messages ..., Octavian Purdila, (Wed Jul 23, 3:01 pm)
[RFC][PATCH 3/3] net: add SKB_SOL control messages, Octavian Purdila, (Wed Jul 23, 3:01 pm)
Re: [RFC][PATCH 1/3] net: per skb control messages, Herbert Xu, (Thu Jul 24, 5:46 am)
Re: [RFC][PATCH 1/3] net: per skb control messages, Octavian Purdila, (Thu Jul 24, 6:34 am)
Re: [RFC][PATCH 1/3] net: per skb control messages, Herbert Xu, (Thu Jul 24, 8:01 am)
Re: [RFC][PATCH 1/3] net: per skb control messages, Octavian Purdila, (Thu Jul 24, 9:22 am)
Re: [RFC][PATCH 1/3] net: per skb control messages, David Miller, (Thu Jul 24, 1:28 pm)
Re: [RFC][PATCH 1/3] net: per skb control messages, Octavian Purdila, (Thu Jul 24, 2:49 pm)
Re: [RFC][PATCH 1/3] net: per skb control messages, David Miller, (Thu Jul 24, 2:56 pm)
Re: [RFC][PATCH 1/3] net: per skb control messages, Stephen Hemminger, (Thu Jul 24, 2:58 pm)
Re: [RFC][PATCH 1/3] net: per skb control messages, Octavian Purdila, (Thu Jul 24, 3:12 pm)
Re: [RFC][PATCH 1/3] net: per skb control messages, David Miller, (Thu Jul 24, 3:17 pm)
Re: [RFC][PATCH 1/3] net: per skb control messages, Octavian Purdila, (Thu Jul 24, 3:35 pm)
Re: [RFC][PATCH 1/3] net: per skb control messages, Stephen Hemminger, (Thu Jul 24, 4:05 pm)
Re: [RFC][PATCH 1/3] net: per skb control messages, Octavian Purdila, (Thu Jul 24, 4:14 pm)
Re: [RFC][PATCH 1/3] net: per skb control messages, David Miller, (Thu Jul 24, 4:18 pm)
Re: [RFC][PATCH 1/3] net: per skb control messages, Octavian Purdila, (Thu Jul 24, 4:26 pm)