patch-2.3.15 linux/net/ipv4/fib_rules.c

Next file: linux/net/ipv4/fib_semantics.c
Previous file: linux/net/ipv4/fib_hash.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.14/linux/net/ipv4/fib_rules.c linux/net/ipv4/fib_rules.c
@@ -5,7 +5,7 @@
  *
  *		IPv4 Forwarding Information Base: policy rules.
  *
- * Version:	$Id: fib_rules.c,v 1.11 1999/06/09 10:10:47 davem Exp $
+ * Version:	$Id: fib_rules.c,v 1.13 1999/08/20 11:05:05 davem Exp $
  *
  * Authors:	Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
  *
@@ -52,6 +52,7 @@
 struct fib_rule
 {
 	struct fib_rule *r_next;
+	atomic_t	r_clntref;
 	u32		r_preference;
 	unsigned char	r_table;
 	unsigned char	r_action;
@@ -72,11 +73,12 @@
 	__u32		r_tclassid;
 #endif
 	char		r_ifname[IFNAMSIZ];
+	int		r_dead;
 };
 
-static struct fib_rule default_rule = { NULL, 0x7FFF, RT_TABLE_DEFAULT, RTN_UNICAST, };
-static struct fib_rule main_rule = { &default_rule, 0x7FFE, RT_TABLE_MAIN, RTN_UNICAST, };
-static struct fib_rule local_rule = { &main_rule, 0, RT_TABLE_LOCAL, RTN_UNICAST, };
+static struct fib_rule default_rule = { NULL, ATOMIC_INIT(2), 0x7FFF, RT_TABLE_DEFAULT, RTN_UNICAST, };
+static struct fib_rule main_rule = { &default_rule, ATOMIC_INIT(2), 0x7FFE, RT_TABLE_MAIN, RTN_UNICAST, };
+static struct fib_rule local_rule = { &main_rule, ATOMIC_INIT(2), 0, RT_TABLE_LOCAL, RTN_UNICAST, };
 
 static struct fib_rule *fib_rules = &local_rule;
 static rwlock_t fib_rules_lock = RW_LOCK_UNLOCKED;
@@ -107,9 +109,9 @@
 
 			write_lock_bh(&fib_rules_lock);
 			*rp = r->r_next;
+			r->r_dead = 1;
 			write_unlock_bh(&fib_rules_lock);
-			if (r != &default_rule && r != &main_rule)
-				kfree(r);
+			fib_rule_put(r);
 			err = 0;
 			break;
 		}
@@ -129,6 +131,15 @@
 	return NULL;
 }
 
+void fib_rule_put(struct fib_rule *r)
+{
+	if (atomic_dec_and_test(&r->r_clntref)) {
+		if (r->r_dead)
+			kfree(r);
+		else
+			printk("Freeing alive rule %p\n", r);
+	}
+}
 
 int inet_rtm_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
 {
@@ -183,7 +194,7 @@
 		memcpy(new_r->r_ifname, RTA_DATA(rta[RTA_IIF-1]), IFNAMSIZ);
 		new_r->r_ifname[IFNAMSIZ-1] = 0;
 		new_r->r_ifindex = -1;
-		dev = dev_get(new_r->r_ifname);
+		dev = __dev_get_by_name(new_r->r_ifname);
 		if (dev)
 			new_r->r_ifindex = dev->ifindex;
 	}
@@ -209,6 +220,7 @@
 	}
 
 	new_r->r_next = r;
+	atomic_inc(&new_r->r_clntref);
 	write_lock_bh(&fib_rules_lock);
 	*rp = new_r;
 	write_unlock_bh(&fib_rules_lock);
@@ -322,8 +334,9 @@
 			continue;
 		err = tb->tb_lookup(tb, key, res);
 		if (err == 0) {
-FRprintk("ok\n");
 			res->r = policy;
+			if (policy)
+				atomic_inc(&policy->r_clntref);
 			read_unlock(&fib_rules_lock);
 			return 0;
 		}

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)