netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira <pablo@eurodev.net>
To: netdev@oss.sgi.com
Cc: "David S. Miller" <davem@redhat.com>
Subject: [NETLINK] introduce netlink bucket
Date: Tue, 02 Nov 2004 22:41:44 +0100	[thread overview]
Message-ID: <4187FF18.5050608@eurodev.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 170 bytes --]

Hi Davem,

This patch introduces the netlink bucket struct, it joins three arrays 
into an array of netlink bucket.

Signed-off-by: Pablo Neira Ayuso <pablo@eurodev.net>

[-- Attachment #2: x --]
[-- Type: text/plain, Size: 3937 bytes --]

===== net/netlink/af_netlink.c 1.57 vs edited =====
--- 1.57/net/netlink/af_netlink.c	2004-10-20 07:10:40 +02:00
+++ edited/net/netlink/af_netlink.c	2004-10-30 19:37:26 +02:00
@@ -69,13 +69,15 @@
 
 #define nlk_sk(__sk) ((struct netlink_opt *)(__sk)->sk_protinfo)
 
-static struct hlist_head nl_table[MAX_LINKS];
 static DECLARE_WAIT_QUEUE_HEAD(nl_table_wait);
-static unsigned nl_nonroot[MAX_LINKS];
 
+static struct netlink_bucket {
+	struct hlist_head nl_table;
+	unsigned nl_nonroot;
 #ifdef NL_EMULATE_DEV
-static struct socket *netlink_kernel[MAX_LINKS];
+	struct socket *netlink_kernel;
 #endif
+} nl_bucket[MAX_LINKS];
 
 static int netlink_dump(struct sock *sk);
 static void netlink_destroy_callback(struct netlink_callback *cb);
@@ -164,7 +166,7 @@
 	struct hlist_node *node;
 
 	read_lock(&nl_table_lock);
-	sk_for_each(sk, node, &nl_table[protocol]) {
+	sk_for_each(sk, node, &nl_bucket[protocol].nl_table) {
 		if (nlk_sk(sk)->pid == pid) {
 			sock_hold(sk);
 			goto found;
@@ -185,7 +187,7 @@
 	struct hlist_node *node;
 
 	netlink_table_grab();
-	sk_for_each(osk, node, &nl_table[sk->sk_protocol]) {
+	sk_for_each(osk, node, &nl_bucket[sk->sk_protocol].nl_table) {
 		if (nlk_sk(osk)->pid == pid)
 			break;
 	}
@@ -193,7 +195,7 @@
 		err = -EBUSY;
 		if (nlk_sk(sk)->pid == 0) {
 			nlk_sk(sk)->pid = pid;
-			sk_add_node(sk, &nl_table[sk->sk_protocol]);
+			sk_add_node(sk, &nl_bucket[sk->sk_protocol].nl_table);
 			err = 0;
 		}
 	}
@@ -297,7 +299,7 @@
 
 retry:
 	netlink_table_grab();
-	sk_for_each(osk, node, &nl_table[sk->sk_protocol]) {
+	sk_for_each(osk, node, &nl_bucket[sk->sk_protocol].nl_table) {
 		if (nlk_sk(osk)->pid == pid) {
 			/* Bind collision, search negative pid values. */
 			if (pid > 0)
@@ -318,7 +320,7 @@
 
 static inline int netlink_capable(struct socket *sock, unsigned flag) 
 { 
-	return (nl_nonroot[sock->sk->sk_protocol] & flag) ||
+	return (nl_bucket[sock->sk->sk_protocol].nl_nonroot & flag) ||
 	       capable(CAP_NET_ADMIN);
 } 
 
@@ -615,7 +617,7 @@
 
 	netlink_lock_table();
 
-	sk_for_each(sk, node, &nl_table[protocol]) {
+	sk_for_each(sk, node, &nl_bucket[protocol].nl_table) {
 		struct netlink_opt *nlk = nlk_sk(sk);
 
 		if (ssk == sk)
@@ -675,7 +677,7 @@
 	int protocol = ssk->sk_protocol;
 
 	read_lock(&nl_table_lock);
-	sk_for_each(sk, node, &nl_table[protocol]) {
+	sk_for_each(sk, node, &nl_bucket[protocol].nl_table) {
 		struct netlink_opt *nlk = nlk_sk(sk);
 		if (ssk == sk)
 			continue;
@@ -883,7 +885,7 @@
 void netlink_set_nonroot(int protocol, unsigned flags)
 { 
 	if ((unsigned)protocol < MAX_LINKS) 
-		nl_nonroot[protocol] = flags;
+		nl_bucket[protocol].nl_nonroot = flags;
 } 
 
 static void netlink_destroy_callback(struct netlink_callback *cb)
@@ -1034,7 +1036,7 @@
 		return -ENOBUFS;
 	nlk_sk(sk)->handler = function;
 	write_lock_bh(&nl_emu_lock);
-	netlink_kernel[unit] = sk->sk_socket;
+	nl_bucket[unit].netlink_kernel = sk->sk_socket;
 	write_unlock_bh(&nl_emu_lock);
 	return 0;
 }
@@ -1044,8 +1046,8 @@
 	struct socket *sock;
 
 	write_lock_bh(&nl_emu_lock);
-	sock = netlink_kernel[unit];
-	netlink_kernel[unit] = NULL;
+	sock = nl_bucket[unit].netlink_kernel;
+	nl_bucket[unit].netlink_kernel = NULL;
 	write_unlock_bh(&nl_emu_lock);
 
 	sock_release(sock);
@@ -1056,7 +1058,7 @@
 	struct socket *sock;
 
 	read_lock(&nl_emu_lock);
-	sock = netlink_kernel[unit];
+	sock = nl_bucket[unit].netlink_kernel;
 	if (sock) {
 		struct sock *sk = sock->sk;
 		memset(skb->cb, 0, sizeof(skb->cb));
@@ -1083,7 +1085,7 @@
 	loff_t off = 0;
 
 	for (i=0; i<MAX_LINKS; i++) {
-		sk_for_each(s, node, &nl_table[i]) {
+		sk_for_each(s, node, &nl_bucket[i].nl_table) {
 			if (off == pos) {
 				seq->private = (void *) i;
 				return s;
@@ -1114,7 +1116,7 @@
 		long i = (long)seq->private;
 
 		while (++i < MAX_LINKS) {
-			s = sk_head(&nl_table[i]);
+			s = sk_head(&nl_bucket[i].nl_table);
 			if (s) {
 				seq->private = (void *) i;
 				break;

             reply	other threads:[~2004-11-02 21:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-02 21:41 Pablo Neira [this message]
2004-11-02 22:16 ` [NETLINK] introduce netlink bucket Herbert Xu
2004-11-02 22:22   ` Pablo Neira
2004-11-02 22:16     ` David S. Miller
2004-11-03 23:48 ` David S. Miller
2004-11-21 22:24   ` Pablo Neira

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=4187FF18.5050608@eurodev.net \
    --to=pablo@eurodev.net \
    --cc=davem@redhat.com \
    --cc=netdev@oss.sgi.com \
    /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).