Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 3919
b: refs/heads/master
c: f835e47
h: refs/heads/master
i:
  3917: e7455d7
  3915: d121a2d
  3911: bee961b
  3903: b691cd9
v: v3
  • Loading branch information
Robert Olsson authored and David S. Miller committed Jun 28, 2005
1 parent 14dbde6 commit 6b1bc62
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 2f85a42964dd43fed3a339701db046bee5a8b903
refs/heads/master: f835e471b557c45d2e5701ea5215f6e739b4eb39
56 changes: 39 additions & 17 deletions trunk/net/ipv4/fib_trie.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
* 2 of the License, or (at your option) any later version.
*/

#define VERSION "0.323"
#define VERSION "0.324"

#include <linux/config.h>
#include <asm/uaccess.h>
Expand Down Expand Up @@ -341,8 +341,10 @@ static struct leaf *leaf_new(void)
static struct leaf_info *leaf_info_new(int plen)
{
struct leaf_info *li = kmalloc(sizeof(struct leaf_info), GFP_KERNEL);
li->plen = plen;
INIT_LIST_HEAD(&li->falh);
if(li) {
li->plen = plen;
INIT_LIST_HEAD(&li->falh);
}
return li;
}

Expand Down Expand Up @@ -879,8 +881,8 @@ static struct node *trie_rebalance(struct trie *t, struct tnode *tn)
return (struct node*) tn;
}

static struct list_head *
fib_insert_node(struct trie *t, u32 key, int plen)
static struct list_head *
fib_insert_node(struct trie *t, int *err, u32 key, int plen)
{
int pos, newpos;
struct tnode *tp = NULL, *tn = NULL;
Expand Down Expand Up @@ -940,7 +942,6 @@ fib_insert_node(struct trie *t, u32 key, int plen)
if(tp && IS_LEAF(tp))
BUG();

t->revision++;

/* Case 1: n is a leaf. Compare prefixes */

Expand All @@ -949,8 +950,10 @@ fib_insert_node(struct trie *t, u32 key, int plen)

li = leaf_info_new(plen);

if(! li)
BUG();
if(! li) {
*err = -ENOMEM;
goto err;
}

fa_head = &li->falh;
insert_leaf_info(&l->list, li);
Expand All @@ -959,14 +962,19 @@ fib_insert_node(struct trie *t, u32 key, int plen)
t->size++;
l = leaf_new();

if(! l)
BUG();
if(! l) {
*err = -ENOMEM;
goto err;
}

l->key = key;
li = leaf_info_new(plen);

if(! li)
BUG();
if(! li) {
tnode_free((struct tnode *) l);
*err = -ENOMEM;
goto err;
}

fa_head = &li->falh;
insert_leaf_info(&l->list, li);
Expand Down Expand Up @@ -1003,9 +1011,14 @@ fib_insert_node(struct trie *t, u32 key, int plen)
newpos = 0;
tn = tnode_new(key, newpos, 1); /* First tnode */
}
if(!tn)
trie_bug("tnode_pfx_new failed");

if(!tn) {
free_leaf_info(li);
tnode_free((struct tnode *) l);
*err = -ENOMEM;
goto err;
}

NODE_SET_PARENT(tn, tp);

missbit=tkey_extract_bits(key, newpos, 1);
Expand All @@ -1027,7 +1040,9 @@ fib_insert_node(struct trie *t, u32 key, int plen)
}
/* Rebalance the trie */
t->trie = trie_rebalance(t, tp);
done:;
done:
t->revision++;
err:;
return fa_head;
}

Expand Down Expand Up @@ -1156,8 +1171,12 @@ fn_trie_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
* Insert new entry to the list.
*/

if(!fa_head)
fa_head = fib_insert_node(t, key, plen);
if(!fa_head) {
fa_head = fib_insert_node(t, &err, key, plen);
err = 0;
if(err)
goto out_free_new_fa;
}

write_lock_bh(&fib_lock);

Expand All @@ -1170,6 +1189,9 @@ fn_trie_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
rtmsg_fib(RTM_NEWROUTE, htonl(key), new_fa, plen, tb->tb_id, nlhdr, req);
succeeded:
return 0;

out_free_new_fa:
kmem_cache_free(fn_alias_kmem, new_fa);
out:
fib_release_info(fi);
err:;
Expand Down

0 comments on commit 6b1bc62

Please sign in to comment.