All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net-proc: expose the tos values in /proc/net/[tcp|udp]
@ 2011-09-29 19:22 ` Muraliraja Muniraju
  0 siblings, 0 replies; 6+ messages in thread
From: Muraliraja Muniraju @ 2011-09-29 19:22 UTC (permalink / raw)
  To: David S. Miller",
	Alexey Kuznetsov, James Morris, Hideaki YOSHIFUJI,
	Patrick McHardy
  Cc: netdev, linux-kernel, Murali Raja

From: Murali Raja <muralira@google.com>

This patch exports the tos values from the inet_sock struct
for tcp and udp into the /proc/net/tcp or /proc/net/udp respectively.
This will not pickup per packet tos changes but it will address most
of the cases. This is mainly useful as it would decrease reliance on
tcpdump and also people without root access will be able to read
the values.

Signed-off-by: Murali Raja <muralira@google.com>
---
 net/ipv4/tcp_ipv4.c |    7 +++++--
 net/ipv4/udp.c      |    5 +++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index dd3fad9..b036184 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -2416,6 +2416,7 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
 	__u16 destp = ntohs(inet->inet_dport);
 	__u16 srcp = ntohs(inet->inet_sport);
 	int rx_queue;
+	unsigned int tos;
 
 	if (icsk->icsk_pending == ICSK_TIME_RETRANS) {
 		timer_active	= 1;
@@ -2439,8 +2440,10 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
 		 */
 		rx_queue = max_t(int, tp->rcv_nxt - tp->copied_seq, 0);
 
+	tos = inet->tos;
+
 	seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
-			"%08X %5d %8d %lu %d %pK %lu %lu %u %u %d%n",
+			"%08X %5d %8d %lu %d %pK %lu %lu %u %u %d %u%n",
 		i, src, srcp, dest, destp, sk->sk_state,
 		tp->write_seq - tp->snd_una,
 		rx_queue,
@@ -2455,7 +2458,7 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
 		jiffies_to_clock_t(icsk->icsk_ack.ato),
 		(icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
 		tp->snd_cwnd,
-		tcp_in_initial_slowstart(tp) ? -1 : tp->snd_ssthresh,
+		tcp_in_initial_slowstart(tp) ? -1 : tp->snd_ssthresh, tos,
 		len);
 }
 
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index ebaa96b..588786e 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -2092,15 +2092,16 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
 	__be32 src  = inet->inet_rcv_saddr;
 	__u16 destp	  = ntohs(inet->inet_dport);
 	__u16 srcp	  = ntohs(inet->inet_sport);
+	unsigned int tos = inet->tos;
 
 	seq_printf(f, "%5d: %08X:%04X %08X:%04X"
-		" %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %pK %d%n",
+		" %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %pK %d %d%n",
 		bucket, src, srcp, dest, destp, sp->sk_state,
 		sk_wmem_alloc_get(sp),
 		sk_rmem_alloc_get(sp),
 		0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
 		atomic_read(&sp->sk_refcnt), sp,
-		atomic_read(&sp->sk_drops), len);
+		atomic_read(&sp->sk_drops), tos, len);
 }
 
 int udp4_seq_show(struct seq_file *seq, void *v)
-- 
1.7.3.1


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

* [PATCH] net-proc: expose the tos values in /proc/net/[tcp|udp]
@ 2011-09-29 19:22 ` Muraliraja Muniraju
  0 siblings, 0 replies; 6+ messages in thread
From: Muraliraja Muniraju @ 2011-09-29 19:22 UTC (permalink / raw)
  To: David S. Miller",
	Alexey Kuznetsov, James Morris, Hideaki YOSHIFUJI,
	Patrick McHardy
  Cc: netdev, linux-kernel, Murali Raja

From: Murali Raja <muralira@google.com>

This patch exports the tos values from the inet_sock struct
for tcp and udp into the /proc/net/tcp or /proc/net/udp respectively.
This will not pickup per packet tos changes but it will address most
of the cases. This is mainly useful as it would decrease reliance on
tcpdump and also people without root access will be able to read
the values.

Signed-off-by: Murali Raja <muralira@google.com>
---
 net/ipv4/tcp_ipv4.c |    7 +++++--
 net/ipv4/udp.c      |    5 +++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index dd3fad9..b036184 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -2416,6 +2416,7 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
 	__u16 destp = ntohs(inet->inet_dport);
 	__u16 srcp = ntohs(inet->inet_sport);
 	int rx_queue;
+	unsigned int tos;
 
 	if (icsk->icsk_pending == ICSK_TIME_RETRANS) {
 		timer_active	= 1;
@@ -2439,8 +2440,10 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
 		 */
 		rx_queue = max_t(int, tp->rcv_nxt - tp->copied_seq, 0);
 
+	tos = inet->tos;
+
 	seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
-			"%08X %5d %8d %lu %d %pK %lu %lu %u %u %d%n",
+			"%08X %5d %8d %lu %d %pK %lu %lu %u %u %d %u%n",
 		i, src, srcp, dest, destp, sk->sk_state,
 		tp->write_seq - tp->snd_una,
 		rx_queue,
@@ -2455,7 +2458,7 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
 		jiffies_to_clock_t(icsk->icsk_ack.ato),
 		(icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
 		tp->snd_cwnd,
-		tcp_in_initial_slowstart(tp) ? -1 : tp->snd_ssthresh,
+		tcp_in_initial_slowstart(tp) ? -1 : tp->snd_ssthresh, tos,
 		len);
 }
 
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index ebaa96b..588786e 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -2092,15 +2092,16 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
 	__be32 src  = inet->inet_rcv_saddr;
 	__u16 destp	  = ntohs(inet->inet_dport);
 	__u16 srcp	  = ntohs(inet->inet_sport);
+	unsigned int tos = inet->tos;
 
 	seq_printf(f, "%5d: %08X:%04X %08X:%04X"
-		" %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %pK %d%n",
+		" %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %pK %d %d%n",
 		bucket, src, srcp, dest, destp, sp->sk_state,
 		sk_wmem_alloc_get(sp),
 		sk_rmem_alloc_get(sp),
 		0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
 		atomic_read(&sp->sk_refcnt), sp,
-		atomic_read(&sp->sk_drops), len);
+		atomic_read(&sp->sk_drops), tos, len);
 }
 
 int udp4_seq_show(struct seq_file *seq, void *v)
-- 
1.7.3.1

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

* Re: [PATCH] net-proc: expose the tos values in /proc/net/[tcp|udp]
  2011-09-29 19:22 ` Muraliraja Muniraju
  (?)
@ 2011-09-29 19:32 ` David Miller
  2011-10-04 17:38   ` MuraliRaja Muniraju
  -1 siblings, 1 reply; 6+ messages in thread
From: David Miller @ 2011-09-29 19:32 UTC (permalink / raw)
  To: muralira; +Cc: kuznet, jmorris, yoshfuji, kaber, netdev, linux-kernel

From: Muraliraja Muniraju <muralira@google.com>
Date: Thu, 29 Sep 2011 12:22:42 -0700

> From: Murali Raja <muralira@google.com>
> 
> This patch exports the tos values from the inet_sock struct
> for tcp and udp into the /proc/net/tcp or /proc/net/udp respectively.
> This will not pickup per packet tos changes but it will address most
> of the cases. This is mainly useful as it would decrease reliance on
> tcpdump and also people without root access will be able to read
> the values.
> 
> Signed-off-by: Murali Raja <muralira@google.com>

You cannot change the layout of these files, they are parsed by userland
problems and therefore have a fixed API.

Netlink based socket dumping provides a proper, backwards compatible,
way to extend what is reported, so please consider adding your changes
there.

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

* Re: [PATCH] net-proc: expose the tos values in /proc/net/[tcp|udp]
  2011-09-29 19:32 ` David Miller
@ 2011-10-04 17:38   ` MuraliRaja Muniraju
  2011-10-05  9:34     ` Eric Dumazet
  0 siblings, 1 reply; 6+ messages in thread
From: MuraliRaja Muniraju @ 2011-10-04 17:38 UTC (permalink / raw)
  To: David Miller; +Cc: kuznet, jmorris, yoshfuji, kaber, netdev, linux-kernel

I shall make the changes by exposing the tos values via the
netlink as suggested. I had a doubt is I have to modify the
inet_diag_sockid or export it via a new option. I am considering
that adding into inet_diag_sockid is better because the latter is a
bit of a over kill for a single value to be exposed and it also seems
to be logical fit.
Can you let me know your thoughts on this.

Thanks,
Murali

On Thu, Sep 29, 2011 at 12:32 PM, David Miller <davem@davemloft.net> wrote:
> From: Muraliraja Muniraju <muralira@google.com>
> Date: Thu, 29 Sep 2011 12:22:42 -0700
>
>> From: Murali Raja <muralira@google.com>
>>
>> This patch exports the tos values from the inet_sock struct
>> for tcp and udp into the /proc/net/tcp or /proc/net/udp respectively.
>> This will not pickup per packet tos changes but it will address most
>> of the cases. This is mainly useful as it would decrease reliance on
>> tcpdump and also people without root access will be able to read
>> the values.
>>
>> Signed-off-by: Murali Raja <muralira@google.com>
>
> You cannot change the layout of these files, they are parsed by userland
> problems and therefore have a fixed API.
>
> Netlink based socket dumping provides a proper, backwards compatible,
> way to extend what is reported, so please consider adding your changes
> there.
>



-- 
Thanks,
Murali

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

* Re: [PATCH] net-proc: expose the tos values in /proc/net/[tcp|udp]
  2011-10-04 17:38   ` MuraliRaja Muniraju
@ 2011-10-05  9:34     ` Eric Dumazet
  2011-10-05 14:09       ` MuraliRaja Muniraju
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Dumazet @ 2011-10-05  9:34 UTC (permalink / raw)
  To: MuraliRaja Muniraju
  Cc: David Miller, kuznet, jmorris, yoshfuji, kaber, netdev, linux-kernel

Le mardi 04 octobre 2011 à 10:38 -0700, MuraliRaja Muniraju a écrit :
> I shall make the changes by exposing the tos values via the
> netlink as suggested. I had a doubt is I have to modify the
> inet_diag_sockid or export it via a new option. I am considering
> that adding into inet_diag_sockid is better because the latter is a
> bit of a over kill for a single value to be exposed and it also seems
> to be logical fit.
> Can you let me know your thoughts on this.

I believe you could add one "u32 tos" to struct tcp_info

[ It wont solve the UDP case, since "ss -u" still dumps /proc/net/udp
and /proc/net/udp6 ]

Following patch should handle tcp/dccp ipv4/ipv6

diff --git a/include/linux/tcp.h b/include/linux/tcp.h
index 7f59ee9..eec6f3b 100644
--- a/include/linux/tcp.h
+++ b/include/linux/tcp.h
@@ -167,6 +167,7 @@ struct tcp_info {
 	__u32	tcpi_rcv_space;
 
 	__u32	tcpi_total_retrans;
+	__u32	tos;
 };
 
 /* for TCP_MD5SIG socket option */
diff --git a/net/dccp/diag.c b/net/dccp/diag.c
index b21f261..70d9498 100644
--- a/net/dccp/diag.c
+++ b/net/dccp/diag.c
@@ -37,6 +37,7 @@ static void dccp_get_info(struct sock *sk, struct tcp_info *info)
 
 	if (dp->dccps_hc_tx_ccid != NULL)
 		ccid_hc_tx_get_info(dp->dccps_hc_tx_ccid, sk, info);
+	info->tos = inet_sk(sk)->tos;
 }
 
 static void dccp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 4c0da24..b24c3d8 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -2493,6 +2493,7 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info)
 	info->tcpi_rcv_space = tp->rcvq_space.space;
 
 	info->tcpi_total_retrans = tp->total_retrans;
+	info->tos = inet_sk(sk)->tos;
 }
 EXPORT_SYMBOL_GPL(tcp_get_info);
 



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

* Re: [PATCH] net-proc: expose the tos values in /proc/net/[tcp|udp]
  2011-10-05  9:34     ` Eric Dumazet
@ 2011-10-05 14:09       ` MuraliRaja Muniraju
  0 siblings, 0 replies; 6+ messages in thread
From: MuraliRaja Muniraju @ 2011-10-05 14:09 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David Miller, kuznet, jmorris, yoshfuji, kaber, netdev, linux-kernel

Hi Eric,
     I am trying one more approach of adding a new attribute to the
inet_diag extension to expose the tos values. Hence with this approach
tcp tos problem would be solved. When  udp would also be supported via
netlink and will be using inet_diag, it would be just be publishing
the tos values in the new extension added. Can you let me know your
thoughts on the following patch.

--- a/include/linux/inet_diag.h
+++ b/include/linux/inet_diag.h
@@ -97,9 +97,10 @@ enum {
        INET_DIAG_INFO,
        INET_DIAG_VEGASINFO,
        INET_DIAG_CONG,
+       INET_DIAG_TOS,
 };

-#define INET_DIAG_MAX INET_DIAG_CONG
+#define INET_DIAG_MAX INET_DIAG_TOS


 /* INET_DIAG_MEM */
@@ -120,6 +121,13 @@ struct tcpvegas_info {
        __u32   tcpv_minrtt;
 };

+/* INET_DIAG_TOS */
+
+struct inet_diag_tos {
+       __u8    idiag_tos;
+       __u8    idiag_reserved[3];
+};
+
 #ifdef __KERNEL__
 struct sock;
 struct inet_hashinfo;
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index e5fa2dd..abdd606 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -82,6 +82,7 @@ static int inet_csk_diag_fill(struct sock *sk,
        struct nlmsghdr  *nlh;
        void *info = NULL;
        struct inet_diag_meminfo  *minfo = NULL;
+       struct inet_diag_tos *tos = NULL;
        unsigned char    *b = skb_tail_pointer(skb);
        const struct inet_diag_handler *handler;

@@ -108,6 +109,9 @@ static int inet_csk_diag_fill(struct sock *sk,
                       icsk->icsk_ca_ops->name);
        }

+       if (ext & (1 << (INET_DIAG_TOS - 1)))
+               tos = INET_DIAG_PUT(skb, INET_DIAG_TOS, sizeof(*tos));
+
        r->idiag_family = sk->sk_family;
        r->idiag_state = sk->sk_state;
        r->idiag_timer = 0;
@@ -169,6 +173,9 @@ static int inet_csk_diag_fill(struct sock *sk,
            icsk->icsk_ca_ops && icsk->icsk_ca_ops->get_info)
                icsk->icsk_ca_ops->get_info(sk, ext, skb);

+       if (tos)
+               tos->idiag_tos = inet->tos;
+
        nlh->nlmsg_len = skb_tail_pointer(skb) - b;
        return skb->len;


Thanks,
Murali

On Wed, Oct 5, 2011 at 2:34 AM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> Le mardi 04 octobre 2011 à 10:38 -0700, MuraliRaja Muniraju a écrit :
>> I shall make the changes by exposing the tos values via the
>> netlink as suggested. I had a doubt is I have to modify the
>> inet_diag_sockid or export it via a new option. I am considering
>> that adding into inet_diag_sockid is better because the latter is a
>> bit of a over kill for a single value to be exposed and it also seems
>> to be logical fit.
>> Can you let me know your thoughts on this.
>
> I believe you could add one "u32 tos" to struct tcp_info
>
> [ It wont solve the UDP case, since "ss -u" still dumps /proc/net/udp
> and /proc/net/udp6 ]
>
> Following patch should handle tcp/dccp ipv4/ipv6
>
> diff --git a/include/linux/tcp.h b/include/linux/tcp.h
> index 7f59ee9..eec6f3b 100644
> --- a/include/linux/tcp.h
> +++ b/include/linux/tcp.h
> @@ -167,6 +167,7 @@ struct tcp_info {
>        __u32   tcpi_rcv_space;
>
>        __u32   tcpi_total_retrans;
> +       __u32   tos;
>  };
>
>  /* for TCP_MD5SIG socket option */
> diff --git a/net/dccp/diag.c b/net/dccp/diag.c
> index b21f261..70d9498 100644
> --- a/net/dccp/diag.c
> +++ b/net/dccp/diag.c
> @@ -37,6 +37,7 @@ static void dccp_get_info(struct sock *sk, struct tcp_info *info)
>
>        if (dp->dccps_hc_tx_ccid != NULL)
>                ccid_hc_tx_get_info(dp->dccps_hc_tx_ccid, sk, info);
> +       info->tos = inet_sk(sk)->tos;
>  }
>
>  static void dccp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index 4c0da24..b24c3d8 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -2493,6 +2493,7 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info)
>        info->tcpi_rcv_space = tp->rcvq_space.space;
>
>        info->tcpi_total_retrans = tp->total_retrans;
> +       info->tos = inet_sk(sk)->tos;
>  }
>  EXPORT_SYMBOL_GPL(tcp_get_info);
>
>
>
>



-- 
Thanks,
Murali

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

end of thread, other threads:[~2011-10-05 14:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-29 19:22 [PATCH] net-proc: expose the tos values in /proc/net/[tcp|udp] Muraliraja Muniraju
2011-09-29 19:22 ` Muraliraja Muniraju
2011-09-29 19:32 ` David Miller
2011-10-04 17:38   ` MuraliRaja Muniraju
2011-10-05  9:34     ` Eric Dumazet
2011-10-05 14:09       ` MuraliRaja Muniraju

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.