diff mbox

[net-next,5/5] sock_diag: notify when filter change

Message ID 1366727277-19522-6-git-send-email-nicolas.dichtel@6wind.com
State Superseded, archived
Delegated to: David Miller
Headers show

Commit Message

Nicolas Dichtel April 23, 2013, 2:27 p.m. UTC
Filter is advertised in packet diag messages, hence we may update the status
when a filter is updated.

Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
 net/core/filter.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Cong Wang April 24, 2013, 8:05 a.m. UTC | #1
On Tue, 23 Apr 2013 at 14:27 GMT, Nicolas Dichtel <nicolas.dichtel@6wind.com> wrote:
> @@ -773,6 +775,7 @@ int sk_detach_filter(struct sock *sk)
>  		RCU_INIT_POINTER(sk->sk_filter, NULL);
>  		sk_filter_uncharge(sk, filter);
>  		ret = 0;
> +		sock_diag_notify(sk, 1);

Should be sock_diag_notify(sk, 0)?

BTW, use 'true' and 'false' instead of '1' and '0'.

--
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
Nicolas Dichtel April 24, 2013, 8:13 a.m. UTC | #2
Le 24/04/2013 10:05, Cong Wang a écrit :
> On Tue, 23 Apr 2013 at 14:27 GMT, Nicolas Dichtel <nicolas.dichtel@6wind.com> wrote:
>> @@ -773,6 +775,7 @@ int sk_detach_filter(struct sock *sk)
>>   		RCU_INIT_POINTER(sk->sk_filter, NULL);
>>   		sk_filter_uncharge(sk, filter);
>>   		ret = 0;
>> +		sock_diag_notify(sk, 1);
>
> Should be sock_diag_notify(sk, 0)?
No, the filter is removed but the socket is still alive.
0 means that the socket is destroyed.

>
> BTW, use 'true' and 'false' instead of '1' and '0'.
Will do.
--
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
Nicolas Dichtel April 24, 2013, 3:52 p.m. UTC | #3
The goal of this patchset is to be able to monitor packet sockets.
The two first patches add new attributes for packet_diag subsystem, so that all
information exported via the /proc/net/packet are also exported via netlink.
The third patch allows the user to get details about filter attached to a packet
socket.
Then, the two last one enable sockets monitoring. A netlink message is sent each
time a packet socket is created, deleted or when the filter information are
updated.

As usual, the patch against iproute2 will be sent once the patches are included
and net-next merged. I can send it on demand.
With this serie, the tools ss can monitor packet sockets activity.

v2: add sock_diag_notify_del() to avoid confusion of the meaning of the second
    arg of __sock_diag_notify()
    enhance commitlog of patch 3/5

 include/linux/sock_diag.h        |  6 ++++
 include/uapi/linux/packet_diag.h |  5 +++
 include/uapi/linux/sock_diag.h   | 13 +++++++-
 net/core/filter.c                |  3 ++
 net/core/sock_diag.c             | 68 ++++++++++++++++++++++++++++++++++++++++
 net/packet/af_packet.c           |  4 +++
 net/packet/diag.c                | 49 +++++++++++++++++++++++++----
 7 files changed, 141 insertions(+), 7 deletions(-)

Comments are welcome.

Regards,
Nicolas
--
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
diff mbox

Patch

diff --git a/net/core/filter.c b/net/core/filter.c
index dad2a17..8b08c7a 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -40,6 +40,7 @@ 
 #include <linux/ratelimit.h>
 #include <linux/seccomp.h>
 #include <linux/if_vlan.h>
+#include <linux/sock_diag.h>
 
 /* No hurry in this branch
  *
@@ -755,6 +756,7 @@  int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
 
 	if (old_fp)
 		sk_filter_uncharge(sk, old_fp);
+	sock_diag_notify(sk, 1);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(sk_attach_filter);
@@ -773,6 +775,7 @@  int sk_detach_filter(struct sock *sk)
 		RCU_INIT_POINTER(sk->sk_filter, NULL);
 		sk_filter_uncharge(sk, filter);
 		ret = 0;
+		sock_diag_notify(sk, 1);
 	}
 	return ret;
 }