patch-2.1.14 linux/net/ipv6/ndisc.c

Next file: linux/net/ipv6/raw.c
Previous file: linux/net/ipv6/ipv6_route.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.13/linux/net/ipv6/ndisc.c linux/net/ipv6/ndisc.c
@@ -18,8 +18,9 @@
  *	Changes:
  *
  *	Lars Fenneberg			:	fixed MTU setting on receipt
- *						of an RA. 
+ *						of an RA.
  *
+ *	Janos Farkas			:	kmalloc failure checks
  */
 
 /*
@@ -580,6 +581,7 @@
 	if (skb == NULL)
 	{
 		printk(KERN_DEBUG "send_na: alloc skb failed\n");
+		return;
 	}
 
 	skb->free=1;
@@ -737,6 +739,7 @@
 	if (skb == NULL)
 	{
 		printk(KERN_DEBUG "send_ns: alloc skb failed\n");
+		return;
 	}
 
 	skb->free=1;
@@ -1296,29 +1299,40 @@
 	{
 		printk(KERN_DEBUG "ndisc_rdisc: new default router\n");
 
-		rt = (struct rt6_info *)kmalloc(sizeof(struct rt6_info),
-						GFP_ATOMIC);
-
-		neigh = ndisc_retrieve_neigh(skb->dev, &skb->ipv6_hdr->saddr);
-
-		if (neigh == NULL)
+		rt = (struct rt6_info *) kmalloc(sizeof(struct rt6_info),
+						 GFP_ATOMIC);
+		if (rt)
 		{
-			neigh = ndisc_new_neigh(skb->dev,
-						&skb->ipv6_hdr->saddr);
-		}
+			neigh = ndisc_retrieve_neigh(skb->dev,
+						     &skb->ipv6_hdr->saddr);
 
-		atomic_inc(&neigh->refcnt);
-		neigh->flags |= NCF_ROUTER;
+			if (neigh == NULL)
+			{
+				neigh = ndisc_new_neigh(skb->dev,
+							&skb->ipv6_hdr->saddr);
+			}
 
-		memset(rt, 0, sizeof(struct rt6_info));
+			if (neigh)
+			{
+				atomic_inc(&neigh->refcnt);
+				neigh->flags |= NCF_ROUTER;
+				
+				memset(rt, 0, sizeof(struct rt6_info));
 
-		ipv6_addr_copy(&rt->rt_dst, &skb->ipv6_hdr->saddr);
-		rt->rt_metric = 1;
-		rt->rt_flags = RTF_GATEWAY | RTF_DYNAMIC;
-		rt->rt_dev = skb->dev;
-		rt->rt_nexthop = neigh;
+				ipv6_addr_copy(&rt->rt_dst,
+					       &skb->ipv6_hdr->saddr);
+				rt->rt_metric = 1;
+				rt->rt_flags = RTF_GATEWAY | RTF_DYNAMIC;
+				rt->rt_dev = skb->dev;
+				rt->rt_nexthop = neigh;
 
-		ndisc_add_dflt_router(rt);
+				ndisc_add_dflt_router(rt);
+			}
+			else
+			{
+				kfree(rt);
+			}
+		}
 	}
 
 	if (rt)

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov