Network Events Connector
Subsystems (4)
PATCH 1/1 Network Events Connector
This patch adds a connector which reports networking's events to userspace. It's sending events when a sock has its sk_state changed to :
- LISTEN or CLOSE for DCCP and TCP
- BIND or CLOSE for UDP.
With this notification, a userspace tool can ask the user if he want to let the local firewall open for the corresponding sport or not, and if so open the firewall for the application which get the corresponding sport.
For people behind a firewall (non-running in the user box) we can have a authentification between the user box, which have set the port to state TCP_LISTEN for example, and the firewall, in a such way that the firewall's router will forward incoming packet for this port to the user box.
It will avoid adding specific rules to the user's firewall-script, and let the firewall be more interactive for users.
--- drivers/connector/Kconfig | 8 ++ drivers/connector/Makefile | 1 drivers/connector/cn_net.c | 161 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/cn_net.h | 64 +++++++++++++++++ include/linux/connector.h | 4 + net/dccp/proto.c | 6 +- net/ipv4/af_inet.c | 6 ++ net/ipv4/tcp.c | 5 + net/ipv4/udp.c | 2 + 9 files changed, 254 insertions(+), 3 deletions(-)
drivers/connector/Kconfig +8 -0
@@ -18,4 +18,12 @@ config PROC_EVENTS Provide a connector that reports process events to userspace. Send events such as fork, exec, id change (uid, gid, suid, etc), and exit. +config NET_EVENTS + boolean "Report network events to userspace" + depends on CONNECTOR=y + default y + ---help--- + Provide a connector that reports networking's events to userspace. + Send events such as DCCP/TCP listen/close and UDP bind/close. + endmenu
drivers/connector/Makefile +1 -0
@@ -1,4 +1,5 @@ obj-$(CONFIG_CONNECTOR) += cn.o obj-$(CONFIG_PROC_EVENTS) += cn_proc.o +obj-$(CONFIG_NET_EVENTS) += cn_net.o cn-y += cn_queue.o connector.o
drivers/connector/cn_net.c new file +161 -0
161 lines not on this page · raw message
include/linux/cn_net.h new file +64 -0
64 lines not on this page · raw message
include/linux/connector.h +3 -1
@@ -36,9 +36,11 @@ #define CN_IDX_CIFS 0x2#define CN_VAL_CIFS 0x1#define CN_W1_IDX 0x3/* w1 communication */ #define CN_W1_VAL 0x1 +#define CN_IDX_NET 0x4 +#define CN_VAL_NET 0x1 -#define CN_NETLINK_USERS 4 +#define CN_NETLINK_USERS 5/* * Maximum connector's message size.
net/dccp/proto.c +5 -1
@@ -21,6 +21,7 @@ #include <linux/if_arp.h>#include <linux/init.h> #include <linux/random.h> #include <net/checksum.h> +#include <linux/cn_net.h> #include <net/inet_sock.h> #include <net/sock.h>
@@ -794,6 +795,7 @@ int inet_dccp_listen(struct socket *sock } sk->sk_max_ack_backlog = backlog; err =0 ; +cn_net_event (sk,NET_EVENT_DCCP_LISTEN ); out:release_sock (sk);
@@ -906,8 +908,10 @@ #if 0#endif } -if (sk->sk_state ==DCCP_CLOSED ) +if (sk->sk_state ==DCCP_CLOSED ) { +cn_net_event (sk,NET_EVENT_DCCP_CLOSE );inet_csk_destroy_sock (sk); + }/* Otherwise, socket is reprieved until protocol close. */
net/ipv4/af_inet.c +6 -0
@@ -114,6 +114,7 @@ #include <net/xfrm.h>#ifdef CONFIG_IP_MROUTE #include <linux/mroute.h> #endif +#include <linux/cn_net.h> DEFINE_SNMP_STAT(struct linux_mib, net_statistics) __read_mostly;
@@ -210,6 +211,7 @@ int inet_listen(struct socket *sock, int } sk->sk_max_ack_backlog = backlog; err =0 ; +cn_net_event (sk,NET_EVENT_TCP_LISTEN ); out:release_sock (sk);
@@ -468,6 +470,10 @@ int inet_bind(struct socket *sock, struc inet->dport =0 ;sk_dst_reset (sk); err =0 ; + +if (sk->sk_protocol ==IPPROTO_UDP ) +cn_net_event (sk,NET_EVENT_UDP_BIND ); + out_release_sock:release_sock (sk); out:
net/ipv4/tcp.c +4 -1
@@ -258,6 +258,7 @@ #include <linux/random.h>#include <linux/bootmem.h> #include <linux/cache.h> #include <linux/err.h> +#include <linux/cn_net.h> #include <net/icmp.h> #include <net/tcp.h>
@@ -1684,8 +1685,10 @@ adjudge_to_death: } } -if (sk->sk_state ==TCP_CLOSE ) +if (sk->sk_state ==TCP_CLOSE ) { +cn_net_event (sk,NET_EVENT_TCP_CLOSE );inet_csk_destroy_sock (sk); + }/* Otherwise, socket is reprieved until protocol close. */ out:
net/ipv4/udp.c +2 -0
@@ -108,6 +108,7 @@ #include <net/route.h>#include <net/inet_common.h> #include <net/checksum.h> #include <net/xfrm.h> +#include <linux/cn_net.h> /* * Snmp MIB for the UDP layer
@@ -912,6 +913,7 @@ int udp_disconnect(struct sock *sk, intstatic void udp_close (struct sock *sk,long timeout) { +cn_net_event (sk,NET_EVENT_UDP_CLOSE );sk_common_release (sk); }
Quoted 16 lines · Samir Bellabes
This patch adds a connector which reports networking's events to userspace. It's sending events when a sock has its
sk_statechanged to :
- LISTEN or CLOSE for DCCP and TCP
- BIND or CLOSE for UDP.With this notification, a userspace tool can ask the user if he want to let the local firewall open for the corresponding sport or not, and if so open the firewall for the application which get the corresponding sport.
For people behind a firewall (non-running in the user box) we can have a authentification between the user box, which have set the port to state
TCP_LISTENfor example, and the firewall, in a such way that the firewall's router will forward incoming packet for this port to the user box.
Quoted 4 lines
It will avoid adding specific rules to the user's firewall-script, and let the firewall be more interactive for users.
Signed-off-by Samir Bellabes <[email protected]>
Interesting... Mybe it even prints the name of the application which is trying to change port state?
I have couple of comments about structures you use, otherwise it looks good, although I do not know if it is ok or not ok to include it into mainline tree.
Quoted 1 line
From one point of view it is small and interesting piece of code, from other
point it is not clear if such functionality is needed...
Btw, you could also create netlink/connector based firewall rules update, I think people with hundreds of rules in one table will bless you after that.
Quoted 17 lines
include/linux/cn_net.h new file +17
-0+#ifndef CN_NET_H +#define CN_NET_H + +#include <linux/time.h> +#include <linux/ipv6.h> + +/* + * Userspace sends this enum to register with the kernel that it is listening + * for events on the connector. + */ +enum cn_net_status { + CN_NET_LISTEN = 1, + CN_NET_IGNORE = 2 +}; + +struct net_event { + enum event {
include/linux/cn_net.h line 39
Quoted 10 lines
include/linux/cn_net.h new file +10
-0+NET_EVENT_NONE =0x00000000 , +NET_EVENT_TCP_LISTEN =0x00000001 , +NET_EVENT_TCP_CLOSE =0x00000002 , +NET_EVENT_UDP_BIND =0x00000004 , +NET_EVENT_UDP_CLOSE =0x00000008 , +NET_EVENT_DCCP_LISTEN =0x00000010 , +NET_EVENT_DCCP_CLOSE =0x00000020 , + NET_EVENT_MAX = 0x80000000 + } event; +struct timespec timestamp;
Doesn't this monster have different size in 64 and 32 bit environments?
include/linux/cn_net.h line 49
Quoted 10 lines
include/linux/cn_net.h new file +10
-0+ union { + struct { + __u32 err; + } ack; + + struct { + unsigned int family; + union { + struct in6_addr ipv6; + unsigned long ipv4;
Please no longs in code which is supposed to be used simultaneously in 32 and 64 bit environments.
Quoted 5 lines
include/linux/cn_net.h new file +5
-0+ } saddr; +unsigned int sport; + } data; + } net_event_data; +};
Signature · 1 line
Evgeniy Polyakov
Quoted 17 lines · Evgeniy Polyakov
Quoted 16 lines · Samir Bellabes
This patch adds a connector which reports networking's events to userspace. It's sending events when a sock has its
sk_statechanged to :
- LISTEN or CLOSE for DCCP and TCP
- BIND or CLOSE for UDP.With this notification, a userspace tool can ask the user if he want to let the local firewall open for the corresponding sport or not, and if so open the firewall for the application which get the corresponding sport.
For people behind a firewall (non-running in the user box) we can have a authentification between the user box, which have set the port to state
TCP_LISTENfor example, and the firewall, in a such way that the firewall's router will forward incoming packet for this port to the user box.
Quoted 7 lines
Quoted 4 lines
It will avoid adding specific rules to the user's firewall-script, and let the firewall be more interactive for users.
Signed-off-by Samir Bellabes <[email protected]>Interesting... Mybe it even prints the name of the application which is trying to change port state?
Yes, of course, the name of the application is a part of the 'trusted system'. But i think we can look for the application which gets the inode corresponding to the sock in userspace, using the /proc/<pid> files.
Whithout this, we have to lookup all the process in kernel, in order to find the one which old the sock. It's time consumming, even if the kind of event involved (listening/close port) doesn't occur so often. But if you think the kernel can do that, it's not a problem, i have code to do that.
In fact the '$PATH/apps' is the complete info we need. With it, we can ask the user, and we can check with the 'distro' tools (urpmi, apt-get, smart) if the '$PATH/apps' really belongs to the distro and should be trust.
I'm working also in a option on this, in order to avoid some 'false positive', because some ports don't need to be 'open' in the firewall, using conntrack.
As a example, you can take ftp's client, which will own a listening port when it will received data from server, but the ip/nf_conntrack_ftp will do the jobs for us, in order to let the data coming in.
This current patch will send the information that the ftp's client is listening on a port (and a userspace tool will ask the user about what to do with this) but the ip_conntrack as already did the job.
Quoted 5 lines
I have couple of comments about structures you use, otherwise it looks good, although I do not know if it is ok or not ok to include it into mainline tree.
From one point of view it is small and interesting piece of code, from other point it is not clear if such functionality is needed...
ok.
Quoted 3 lines
Btw, you could also create netlink/connector based firewall rules update, I think people with hundreds of rules in one table will bless you after that.
This is the real goal, using ipset - http://ipset.netfilter.org/
With this we can easily create a uniq rule for iptables, and then add/remove port from the 'set' involve.
Quoted 22 lines
Quoted 22 lines
include/linux/cn_net.h new file +22
-0+#ifndef CN_NET_H +#define CN_NET_H + +#include <linux/time.h> +#include <linux/ipv6.h> + +/* + * Userspace sends this enum to register with the kernel that it is listening + * for events on the connector. + */ +enum cn_net_status { + CN_NET_LISTEN = 1, + CN_NET_IGNORE = 2 +}; + +struct net_event { + enum event { + NET_EVENT_NONE = 0x00000000, + NET_EVENT_TCP_LISTEN = 0x00000001, + NET_EVENT_TCP_CLOSE = 0x00000002, + NET_EVENT_UDP_BIND = 0x00000004, + NET_EVENT_UDP_CLOSE = 0x00000008,
Quoted 8 lines
include/linux/cn_net.h line 39
Quoted 5 lines
include/linux/cn_net.h new file +5
-0+NET_EVENT_DCCP_LISTEN =0x00000010 , +NET_EVENT_DCCP_CLOSE =0x00000020 , + NET_EVENT_MAX = 0x80000000 + } event; +struct timespec timestamp;Doesn't this monster have different size in 64 and 32 bit environments?
I see.
Quoted 5 lines
Quoted 5 lines
include/linux/cn_net.h new file +5
-0+union { +struct { +__u32 err; + } ack; +
Quoted 8 lines
include/linux/cn_net.h line 49
Quoted 5 lines
include/linux/cn_net.h new file +5
-0+struct { +unsigned int family; +union { +struct in6_addr ipv6; +unsigned long ipv4;Please no longs in code which is supposed to be used simultaneously in 32 and 64 bit environments.
Of course.
Thanks for you comments, i will send a new patch later today. regars.
Quoted 27 lines · Samir Bellabes
Quoted 17 lines · Evgeniy Polyakov
Quoted 16 lines · Samir Bellabes
This patch adds a connector which reports networking's events to userspace. It's sending events when a sock has its
sk_statechanged to :
- LISTEN or CLOSE for DCCP and TCP
- BIND or CLOSE for UDP.With this notification, a userspace tool can ask the user if he want to let the local firewall open for the corresponding sport or not, and if so open the firewall for the application which get the corresponding sport.
For people behind a firewall (non-running in the user box) we can have a authentification between the user box, which have set the port to state
TCP_LISTENfor example, and the firewall, in a such way that the firewall's router will forward incoming packet for this port to the user box.Quoted 7 lines
Quoted 4 lines
It will avoid adding specific rules to the user's firewall-script, and let the firewall be more interactive for users.
Signed-off-by Samir Bellabes <[email protected]>Interesting... Mybe it even prints the name of the application which is trying to change port state?
Quoted 9 lines
Yes, of course, the name of the application is a part of the 'trusted system'. But i think we can look for the application which gets the inode corresponding to the sock in userspace, using the /proc/<pid> files.
Whithout this, we have to lookup all the process in kernel, in order to find the one which old the sock. It's time consumming, even if the kind of event involved (listening/close port) doesn't occur so often. But if you think the kernel can do that, it's not a problem, i have code to do that.
It is much better to do it in userspace - look into /proc/$pid/.
I recall I saw such feature in Windows :)
You can also extend your module to be more generic and send all (or just requested in config) state changes for all protocols (or those checked in config).
Quoted 23 lines
In fact the '$PATH/apps' is the complete info we need. With it, we can ask the user, and we can check with the 'distro' tools (urpmi, apt-get, smart) if the '$PATH/apps' really belongs to the distro and should be trust.
I'm working also in a option on this, in order to avoid some 'false positive', because some ports don't need to be 'open' in the firewall, using conntrack.
As a example, you can take ftp's client, which will own a listening port when it will received data from server, but the ip/nf_conntrack_ftp will do the jobs for us, in order to let the data coming in.
This current patch will send the information that the ftp's client is listening on a port (and a userspace tool will ask the user about what to do with this) but theip_conntrackas already did the job.Quoted 5 lines
I have couple of comments about structures you use, otherwise it looks good, although I do not know if it is ok or not ok to include it into mainline tree.
From one point of view it is small and interesting piece of code, from other point it is not clear if such functionality is needed...ok.
Quoted 7 lines
Quoted 3 lines
Btw, you could also create netlink/connector based firewall rules update, I think people with hundreds of rules in one table will bless you after that.
This is the real goal, using ipset - http://ipset.netfilter.org/
With this we can easily create a uniq rule for iptables, and then add/remove port from the 'set' involve.
It is not the same as create and update existing rules. I think hipac project uses feature of fast rules update. It is quite major break for existing iptables, but it should be eventually done...
Signature · 1 line
Evgeniy Polyakov
Quoted 7 lines · Evgeniy Polyakov
Quoted 3 lines · Samir Bellabes
Quoted 1 line · Evgeniy Polyakov
On Mon, Oct 02, 2006 at 08:11:06AM +0200, Samir Bellabes ([email protected]) wrote:
You can also extend your module to be more generic and send all (or just requested in config) state changes for all protocols (or those checked in config).
Ok, so the next step now is to target all state changes for all protocols, *but* send only the states asked dynamically from the userspace, using the userspace-to-kernel's way of the netlink. What do you think about that ?
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Btw, you could also create netlink/connector based firewall rules update, I think people with hundreds of rules in one table will bless you after that.
Quoted 8 lines
Quoted 3 lines
This is the real goal, using ipset - http://ipset.netfilter.org/
With this we can easily create a uniq rule for iptables, and then add/remove port from the 'set' involve.It is not the same as create and update existing rules. I think hipac project uses feature of fast rules update. It is quite major break for existing iptables, but it should be eventually done...
Ok now i understand clearly your point.
But we are a bit far from the initial idea, even if it could be really good to do that. First, let's code the initial idea.
Quoted 8 lines · Samir Bellabes
Quoted 3 lines
You can also extend your module to be more generic and send all (or just requested in config) state changes for all protocols (or those checked in config).
Ok, so the next step now is to target all state changes for all protocols, *but* send only the states asked dynamically from the userspace, using the userspace-to-kernel's way of the netlink. What do you think about that ?
That sounds good, but as David mentioned, if there are other good possibilities to do so, there is no need to reinvent new one (although sometimes it is much better to reinvent the wheel, if existing one is square).
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Btw, you could also create netlink/connector based firewall rules update, I think people with hundreds of rules in one table will bless you after that.
This is the real goal, using ipset - http://ipset.netfilter.org/
With this we can easily create a uniq rule for iptables, and then add/remove port from the 'set' involve.
Quoted 8 lines
Quoted 4 lines
It is not the same as create and update existing rules. I think hipac project uses feature of fast rules update. It is quite major break for existing iptables, but it should be eventually done...
Ok now i understand clearly your point.
But we are a bit far from the initial idea, even if it could be really good to do that. First, let's code the initial idea.
Agree.
Signature · 1 line
Evgeniy Polyakov
David Miller
maintainerFrom: Samir Bellabes <[email protected]>
Date: Mon, 02 Oct 2006 08:11:06 +0200
Quoted 8 lines
This patch adds a connector which reports networking's events to userspace. It's sending events when a sock has its
sk_statechanged to :
- LISTEN or CLOSE for DCCP and TCP
- BIND or CLOSE for UDP.With this notification, a userspace tool can ask the user if he want to let the local firewall open for the corresponding sport or not, and if so open the firewall for the application which get the corresponding sport.
You can do this with the security layer, netfilter's ULOG, or even the netfilter connection tracking netlink sockets.
That's 3 facilities by which you can accomplish this, and if none of them are perfect, add the small modifications you need to one of them to make them usable for your task.
It makes no sense to add new facilities just for this.
Quoted 8 lines · David Miller
From: Samir Bellabes <[email protected]>
Date: Mon, 02 Oct 2006 08:11:06 +0200Quoted 5 lines
This patch adds a connector which reports networking's events to userspace. It's sending events when a sock has its
sk_statechanged to :
- LISTEN or CLOSE for DCCP and TCP
- BIND or CLOSE for UDP.
Quoted 8 lines
You can do this with the security layer, netfilter's ULOG, or even the netfilter connection tracking netlink sockets.
That's 3 facilities by which you can accomplish this, and if none of them are perfect, add the small modifications you need to one of them to make them usable for your task.
It makes no sense to add new facilities just for this.
I see, i will look futher the netfilter conntrack netlink sockets in order to merge my code into it.
thanks for comments.