netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Unai Uribarri <unai.uribarri@optenet.com>
To: Stephen Hemminger <shemminger@linux-foundation.org>
Cc: "David S. Miller" <davem@davemloft.net>,
	Evgeniy Polyakov <johnpol@2ka.mipt.ru>,
	netdev@vger.kernel.org
Subject: Re: [RFC] af_packet: allow disabling timestamps
Date: Thu, 27 Sep 2007 16:34:30 +0200	[thread overview]
Message-ID: <1190903670.6487.170.camel@localhost.localdomain> (raw)
In-Reply-To: <20070913124253.60da52f2@oldman>

This small modification to Stephen's patch timestamps the skb when
needed, so the timestamp can be reused by other af_packet sockets.

Signed-off-by: Unai Uribarri <unai.uribarri@optenet.com>

--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -259,7 +259,8 @@ static void sock_disable_timestamp(struct sock *sk)
 {
 	if (sock_flag(sk, SOCK_TIMESTAMP)) {
 		sock_reset_flag(sk, SOCK_TIMESTAMP);
-		net_disable_timestamp();
+		if (sk->sk_family != PF_PACKET)
+			net_disable_timestamp();
 	}
 }
 
@@ -1655,7 +1656,8 @@ void sock_enable_timestamp(struct sock *sk)
 {
 	if (!sock_flag(sk, SOCK_TIMESTAMP)) {
 		sock_set_flag(sk, SOCK_TIMESTAMP);
-		net_enable_timestamp();
+		if (sk->sk_family != PF_PACKET)
+			net_enable_timestamp();
 	}
 }
 EXPORT_SYMBOL(sock_enable_timestamp);
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -570,7 +570,6 @@ static int tpacket_rcv(struct sk_buff *skb, struct
net_device *dev, struct packe
 	unsigned long status = TP_STATUS_LOSING|TP_STATUS_USER;
 	unsigned short macoff, netoff;
 	struct sk_buff *copy_skb = NULL;
-	struct timeval tv;
 
 	if (dev->nd_net != &init_net)
 		goto drop;
@@ -648,12 +647,18 @@ static int tpacket_rcv(struct sk_buff *skb, struct
net_device *dev, struct packe
 	h->tp_snaplen = snaplen;
 	h->tp_mac = macoff;
 	h->tp_net = netoff;
-	if (skb->tstamp.tv64)
+
+	if (sock_flag(sk, SOCK_TIMESTAMP)) {
+		struct timeval tv;
+		if (skb->tstamp.tv64 == 0)
+			__net_timestamp(skb);
 		tv = ktime_to_timeval(skb->tstamp);
-	else
-		do_gettimeofday(&tv);
-	h->tp_sec = tv.tv_sec;
-	h->tp_usec = tv.tv_usec;
+		h->tp_sec = tv.tv_sec;
+		h->tp_usec = tv.tv_usec;
+	} else {
+		h->tp_sec = 0;
+		h->tp_usec = 0;
+	}
 
 	sll = (struct sockaddr_ll*)((u8*)h + TPACKET_ALIGN(sizeof(*h)));
 	sll->sll_halen = dev_parse_header(skb, sll->sll_addr);
@@ -1004,6 +1009,7 @@ static int packet_create(struct net *net, struct
socket *sock, int protocol)
 		sock->ops = &packet_ops_spkt;
 
 	sock_init_data(sock, sk);
+	sock_set_flag(sk, SOCK_TIMESTAMP);
 
 	po = pkt_sk(sk);
 	sk->sk_family = PF_PACKET;



On jue, 2007-09-13 at 12:42 +0200, Stephen Hemminger wrote:
> Currently, af_packet does not allow disabling timestamps. This patch changes
> that but doesn't force global timestamps on.
> 
> This shows up in bugzilla as:
> 	http://bugzilla.kernel.org/show_bug.cgi?id=4809
> 
> Patch against net-2.6.24 tree.
> 
> Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
> 
> --- a/net/core/sock.c	2007-09-12 15:08:43.000000000 +0200
> +++ b/net/core/sock.c	2007-09-13 12:10:19.000000000 +0200
> @@ -259,7 +259,8 @@ static void sock_disable_timestamp(struc
>  {
>  	if (sock_flag(sk, SOCK_TIMESTAMP)) {
>  		sock_reset_flag(sk, SOCK_TIMESTAMP);
> -		net_disable_timestamp();
> +		if (sk->sk_family != PF_PACKET)
> +			net_disable_timestamp();
>  	}
>  }
>  
> @@ -1645,7 +1646,8 @@ void sock_enable_timestamp(struct sock *
>  {
>  	if (!sock_flag(sk, SOCK_TIMESTAMP)) {
>  		sock_set_flag(sk, SOCK_TIMESTAMP);
> -		net_enable_timestamp();
> +		if (sk->sk_family != PF_PACKET)
> +			net_enable_timestamp();
>  	}
>  }
>  EXPORT_SYMBOL(sock_enable_timestamp);
> --- a/net/packet/af_packet.c	2007-09-12 17:07:00.000000000 +0200
> +++ b/net/packet/af_packet.c	2007-09-13 12:09:10.000000000 +0200
> @@ -572,7 +572,6 @@ static int tpacket_rcv(struct sk_buff *s
>  	unsigned long status = TP_STATUS_LOSING|TP_STATUS_USER;
>  	unsigned short macoff, netoff;
>  	struct sk_buff *copy_skb = NULL;
> -	struct timeval tv;
>  
>  	if (dev->nd_net != &init_net)
>  		goto drop;
> @@ -650,12 +649,19 @@ static int tpacket_rcv(struct sk_buff *s
>  	h->tp_snaplen = snaplen;
>  	h->tp_mac = macoff;
>  	h->tp_net = netoff;
> -	if (skb->tstamp.tv64)
> -		tv = ktime_to_timeval(skb->tstamp);
> -	else
> -		do_gettimeofday(&tv);
> -	h->tp_sec = tv.tv_sec;
> -	h->tp_usec = tv.tv_usec;
> +
> +	if (sock_flag(sk, SOCK_TIMESTAMP)) {
> +		struct timeval tv;
> +		if (skb->tstamp.tv64)
> +			tv = ktime_to_timeval(skb->tstamp);
> +		else
> +			do_gettimeofday(&tv);
> +		h->tp_sec = tv.tv_sec;
> +		h->tp_usec = tv.tv_usec;
> +	} else {
> +		h->tp_sec = 0;
> +		h->tp_usec = 0;
> +	}
>  
>  	sll = (struct sockaddr_ll*)((u8*)h + TPACKET_ALIGN(sizeof(*h)));
>  	sll->sll_halen = 0;
> @@ -1014,6 +1020,7 @@ static int packet_create(struct net *net
>  		sock->ops = &packet_ops_spkt;
>  
>  	sock_init_data(sock, sk);
> +	sock_set_flag(sk, SOCK_TIMESTAMP);
>  
>  	po = pkt_sk(sk);
>  	sk->sk_family = PF_PACKET;
> -
> 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
> 





      parent reply	other threads:[~2007-09-27 14:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-09 14:21 [PATCH 1/1] af_packet: don't enable timestamps in mmap'ed sockets Unai Uribarri
2007-08-09 14:33 ` Evgeniy Polyakov
2007-08-09 18:13   ` Unai Uribarri
2007-08-09 18:18     ` Evgeniy Polyakov
2007-08-09 18:44       ` Unai Uribarri
2007-08-10  8:34         ` Evgeniy Polyakov
2007-08-10 11:55           ` Unai Uribarri
2007-08-10 12:14             ` Evgeniy Polyakov
2007-08-09 18:50       ` Unai Uribarri
2007-09-13 10:42         ` [RFC] af_packet: allow disabling timestamps Stephen Hemminger
2007-09-13 12:24           ` Eric Dumazet
2007-09-14 10:26             ` Stephen Hemminger
2007-09-19  9:07               ` Evgeniy Polyakov
2007-09-27 14:08               ` Unai Uribarri
2007-09-27 14:34           ` Unai Uribarri [this message]

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=1190903670.6487.170.camel@localhost.localdomain \
    --to=unai.uribarri@optenet.com \
    --cc=davem@davemloft.net \
    --cc=johnpol@2ka.mipt.ru \
    --cc=netdev@vger.kernel.org \
    --cc=shemminger@linux-foundation.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).