patch-2.4.1 linux/net/appletalk/aarp.c

Next file: linux/net/appletalk/ddp.c
Previous file: linux/mm/vmscan.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.0/linux/net/appletalk/aarp.c linux/net/appletalk/aarp.c
@@ -25,6 +25,7 @@
  *		Jaume Grau	-	flush caches on AARP_PROBE
  *		Rob Newberry	-	Added proxy AARP and AARP proc fs, 
  *					moved probing from DDP module.
+ *		Arnaldo C. Melo -	don't mangle rx packets
  *
  */
 
@@ -58,16 +59,12 @@
 #include <linux/init.h>
 #include <linux/proc_fs.h>
 
- 
 int sysctl_aarp_expiry_time = AARP_EXPIRY_TIME;
 int sysctl_aarp_tick_time = AARP_TICK_TIME;
 int sysctl_aarp_retransmit_limit = AARP_RETRANSMIT_LIMIT;
 int sysctl_aarp_resolve_time = AARP_RESOLVE_TIME;
 
-/*
- *	Lists of aarp entries
- */
- 
+/* Lists of aarp entries */
 struct aarp_entry {
 	/* These first two are only used for unresolved entries */
 	unsigned long last_sent;		/* Last time we xmitted the aarp request */
@@ -81,22 +78,16 @@
 	struct aarp_entry *next;		/* Next entry in chain */
 };
 
-/*
- *	Hashed list of resolved, unresolved and proxy entries
- */
-
+/* Hashed list of resolved, unresolved and proxy entries */
 static struct aarp_entry *resolved[AARP_HASH_SIZE];
 static struct aarp_entry *unresolved[AARP_HASH_SIZE];
 static struct aarp_entry *proxies[AARP_HASH_SIZE];
-static int unresolved_count = 0;
+static int unresolved_count;
 
 /* One lock protects it all. */
 static spinlock_t aarp_lock = SPIN_LOCK_UNLOCKED;
 
-/*
- *	Used to walk the list and purge/kick entries.
- */
- 
+/* Used to walk the list and purge/kick entries.  */
 static struct timer_list aarp_timer;
 
 /*
@@ -108,7 +99,7 @@
 {
 	struct sk_buff *skb;
 	
-	while ((skb=skb_dequeue(&a->packet_queue)) != NULL)
+	while ((skb = skb_dequeue(&a->packet_queue)) != NULL)
 		kfree_skb(skb);
 
 	kfree(a);
@@ -125,33 +116,29 @@
 	static char aarp_eth_multicast[ETH_ALEN] =
 		{ 0x09, 0x00, 0x07, 0xFF, 0xFF, 0xFF };
 	struct net_device *dev = a->dev;
-	int len = dev->hard_header_len + sizeof(struct elapaarp) + aarp_dl->header_length;
+	int len = dev->hard_header_len + sizeof(struct elapaarp) +
+		aarp_dl->header_length;
 	struct sk_buff *skb = alloc_skb(len, GFP_ATOMIC);
-	struct elapaarp *eah;
 	struct at_addr *sat = atalk_find_dev_addr(dev);
+	struct elapaarp *eah;
 	
-	if (skb == NULL)
+	if (!skb)
 		return;
 
-	if (sat == NULL) {
+	if (!sat) {
 		kfree_skb(skb);
 		return;
 	}
 	
-	/*
-	 *	Set up the buffer.
-	 */		
-
+	/* Set up the buffer */		
 	skb_reserve(skb, dev->hard_header_len + aarp_dl->header_length);
-	eah		=	(struct elapaarp *)skb_put(skb, sizeof(struct elapaarp));
+	eah		=	(struct elapaarp *)skb_put(skb,
+						sizeof(struct elapaarp));
 	skb->protocol   =       htons(ETH_P_ATALK);
 	skb->nh.raw     =       skb->h.raw = (void *) eah;
 	skb->dev	=	dev;
 	
-	/*
-	 *	Set up the ARP.
-	 */
-	 
+	/* Set up the ARP */
 	eah->hw_type	=	htons(AARP_HW_TYPE_ETHERNET);
 	eah->pa_type	=	htons(ETH_P_ATALK);
 	eah->hw_len	=	ETH_ALEN;	
@@ -170,52 +157,37 @@
 	eah->pa_dst_net	=	a->target_addr.s_net;
 	eah->pa_dst_node=	a->target_addr.s_node;
 	
-	/*
-	 *	Add ELAP headers and set target to the AARP multicast.
-	 */
-	 
+	/* Add ELAP headers and set target to the AARP multicast */
 	aarp_dl->datalink_header(aarp_dl, skb, aarp_eth_multicast);	
 
-	/*
-	 *	Send it.
-	 */	
-	
+	/* Send it */	
 	dev_queue_xmit(skb);
-	
-	/*
-	 *	Update the sending count
-	 */
-	 
+	/* Update the sending count */
 	a->xmit_count++;
 }
 
-/* This runs under aarp_lock and in softint context, so only
- * atomic memory allocations can be used.
- */
+/* This runs under aarp_lock and in softint context, so only atomic memory
+ * allocations can be used. */
 static void aarp_send_reply(struct net_device *dev, struct at_addr *us,
 			    struct at_addr *them, unsigned char *sha)
 {
-	int len = dev->hard_header_len + sizeof(struct elapaarp) + aarp_dl->header_length;
+	int len = dev->hard_header_len + sizeof(struct elapaarp) +
+			aarp_dl->header_length;
 	struct sk_buff *skb = alloc_skb(len, GFP_ATOMIC);
 	struct elapaarp *eah;
 	
-	if (skb == NULL)
+	if (!skb)
 		return;
 	
-	/*
-	 *	Set up the buffer.
-	 */		
-
+	/* Set up the buffer */
 	skb_reserve(skb, dev->hard_header_len + aarp_dl->header_length);
-	eah		=	(struct elapaarp *)skb_put(skb, sizeof(struct elapaarp));	 
+	eah		=	(struct elapaarp *)skb_put(skb,
+					sizeof(struct elapaarp));	 
 	skb->protocol   =       htons(ETH_P_ATALK);
 	skb->nh.raw     =       skb->h.raw = (void *) eah;
 	skb->dev	=	dev;
 	
-	/*
-	 *	Set up the ARP.
-	 */
-	 
+	/* Set up the ARP */
 	eah->hw_type	=	htons(AARP_HW_TYPE_ETHERNET);
 	eah->pa_type	=	htons(ETH_P_ATALK);
 	eah->hw_len	=	ETH_ALEN;	
@@ -228,7 +200,7 @@
 	eah->pa_src_net	=	us->s_net;
 	eah->pa_src_node=	us->s_node;
 	
-	if (sha == NULL)
+	if (!sha)
 		memset(eah->hw_dst, '\0', ETH_ALEN);
 	else
 		memcpy(eah->hw_dst, sha, ETH_ALEN);
@@ -237,47 +209,38 @@
 	eah->pa_dst_net	=	them->s_net;
 	eah->pa_dst_node=	them->s_node;
 	
-	/*
-	 *	Add ELAP headers and set target to the AARP multicast.
-	 */
-	 
+	/* Add ELAP headers and set target to the AARP multicast */
 	aarp_dl->datalink_header(aarp_dl, skb, sha);	
-
-	/*
-	 *	Send it.
-	 */	
+	/* Send it */	
 	dev_queue_xmit(skb);
 }
 
 /*
- *	Send probe frames. Called from aarp_probe_network and aarp_proxy_probe_network.
+ *	Send probe frames. Called from aarp_probe_network and
+ *	aarp_proxy_probe_network.
  */
 
 void aarp_send_probe(struct net_device *dev, struct at_addr *us)
 {
-	int len = dev->hard_header_len + sizeof(struct elapaarp) + aarp_dl->header_length;
+	int len = dev->hard_header_len + sizeof(struct elapaarp) +
+			aarp_dl->header_length;
 	struct sk_buff *skb = alloc_skb(len, GFP_ATOMIC);
-	struct elapaarp *eah;
 	static char aarp_eth_multicast[ETH_ALEN] =
 		{ 0x09, 0x00, 0x07, 0xFF, 0xFF, 0xFF };
+	struct elapaarp *eah;
 
-	if (skb == NULL)
+	if (!skb)
 		return;
 
-	/*
-	 *	Set up the buffer.
-	 */
-
+	/* Set up the buffer */
 	skb_reserve(skb, dev->hard_header_len + aarp_dl->header_length);
-	eah		=	(struct elapaarp *)skb_put(skb, sizeof(struct elapaarp));
+	eah		=	(struct elapaarp *)skb_put(skb,
+					sizeof(struct elapaarp));
 	skb->protocol   =       htons(ETH_P_ATALK);
 	skb->nh.raw     =       skb->h.raw = (void *) eah;
 	skb->dev	=	dev;
 
-	/*
-	 *	Set up the ARP.
-	 */
-
+	/* Set up the ARP */
 	eah->hw_type	=	htons(AARP_HW_TYPE_ETHERNET);
 	eah->pa_type	=	htons(ETH_P_ATALK);
 	eah->hw_len	=	ETH_ALEN;
@@ -296,15 +259,9 @@
 	eah->pa_dst_net	=	us->s_net;
 	eah->pa_dst_node=	us->s_node;
 
-	/*
-	 *	Add ELAP headers and set target to the AARP multicast.
-	 */
-
+	/* Add ELAP headers and set target to the AARP multicast */
 	aarp_dl->datalink_header(aarp_dl, skb, aarp_eth_multicast);
-
-	/*
-	 *	Send it.
-	 */
+	/* Send it */
 	dev_queue_xmit(skb);
 }
 	
@@ -318,16 +275,14 @@
 {
 	struct aarp_entry *t;
 
-	while ((*n) != NULL) {
+	while (*n)
 		/* Expired ? */
-		if(time_after(jiffies, (*n)->expires_at)) {
+		if (time_after(jiffies, (*n)->expires_at)) {
 			t = *n;
 			*n = (*n)->next;
 			__aarp_expire(t);
-		} else {
+		} else
 			n = &((*n)->next);
-		}
-	}
 }
 
 /*
@@ -340,10 +295,8 @@
 {
 	struct aarp_entry *t;
 
-	while ((*n) != NULL) {
-		/* Expired - if this will be the 11th transmit, we delete
-		 * instead.
-		 */
+	while (*n)
+		/* Expired: if this will be the 11th tx, we delete instead. */
 		if ((*n)->xmit_count >= sysctl_aarp_retransmit_limit) {
 			t = *n;
 			*n = (*n)->next;
@@ -352,7 +305,6 @@
 			__aarp_send_query(*n);
 			n = &((*n)->next);
 		}
-	}
 }
 
 /*
@@ -366,21 +318,16 @@
 {
 	struct aarp_entry *t;
 
-	while ((*n) != NULL) {
+	while (*n)
 		if ((*n)->dev == dev) {
 			t = *n;
 			*n = (*n)->next;
 			__aarp_expire(t);
-		} else {
+		} else
 			n = &((*n)->next);
-		}
-	}
 }
 		
-/*
- *	Handle the timer event 
- */
- 
+/* Handle the timer event */
 static void aarp_expire_timeout(unsigned long unused)
 {
 	int ct;
@@ -395,17 +342,14 @@
 	}
 
 	spin_unlock_bh(&aarp_lock);
-
 	mod_timer(&aarp_timer, jiffies + 
-		  (unresolved_count ? sysctl_aarp_tick_time:
+		  (unresolved_count ? sysctl_aarp_tick_time :
 		   sysctl_aarp_expiry_time));
 }
 
-/*
- *	Network device notifier chain handler.
- */
- 
-static int aarp_device_event(struct notifier_block *this, unsigned long event, void *ptr)
+/* Network device notifier chain handler. */
+static int aarp_device_event(struct notifier_block *this, unsigned long event,
+				void *ptr)
 {
 	int ct;
 
@@ -432,11 +376,8 @@
 {
 	struct aarp_entry *a = kmalloc(sizeof(struct aarp_entry), GFP_ATOMIC);
 
-	if (a == NULL)
-		return NULL;
-
-	skb_queue_head_init(&a->packet_queue);
-
+	if (a)
+		skb_queue_head_init(&a->packet_queue);
 	return a;
 }
 
@@ -464,10 +405,8 @@
 /* Called from the DDP code, and thus must be exported. */
 void aarp_proxy_remove(struct net_device *dev, struct at_addr *sa)
 {
+	int hash = sa->s_node % (AARP_HASH_SIZE - 1);
 	struct aarp_entry *a;
-	int hash;
-	
-	hash = 	sa->s_node % (AARP_HASH_SIZE-1);
 
 	spin_lock_bh(&aarp_lock);
 
@@ -479,23 +418,15 @@
 }
 
 /* This must run under aarp_lock. */
-static struct at_addr *__aarp_proxy_find(struct net_device *dev, struct at_addr *sa)
+static struct at_addr *__aarp_proxy_find(struct net_device *dev,
+					 struct at_addr *sa)
 {
-	struct at_addr *retval;
-	struct aarp_entry *a;
-	int hash;
-
-	hash = 	sa->s_node % (AARP_HASH_SIZE-1);
+	int hash = sa->s_node % (AARP_HASH_SIZE - 1);
+	struct aarp_entry *a = __aarp_find_entry(proxies[hash], dev, sa);
 
-	retval = NULL;
-	a = __aarp_find_entry(proxies[hash], dev, sa);
-	if (a != NULL)
-		retval = sa;
-
-	return retval;
+	return a ? sa : NULL;
 }
 
-	
 /*
  * Probe a Phase 1 device or a device that requires its Net:Node to
  * be set via an ioctl.
@@ -506,13 +437,13 @@
     struct sockaddr_at *sa = (struct sockaddr_at *)&atreq.ifr_addr;
 
     sa->sat_addr.s_node = iface->address.s_node;
-    sa->sat_addr.s_net  = ntohs(iface->address.s_net);
+    sa->sat_addr.s_net = ntohs(iface->address.s_net);
 
     /* We pass the Net:Node to the drivers/cards by a Device ioctl. */
     if (!(iface->dev->do_ioctl(iface->dev, &atreq, SIOCSIFADDR))) {
 	    (void)iface->dev->do_ioctl(iface->dev, &atreq, SIOCGIFADDR);
-	    if ((iface->address.s_net != htons(sa->sat_addr.s_net)) ||
-		(iface->address.s_node != sa->sat_addr.s_node))
+	    if (iface->address.s_net != htons(sa->sat_addr.s_net) ||
+		iface->address.s_node != sa->sat_addr.s_node)
 		    iface->status |= ATIF_PROBE_FAIL;
 
 	    iface->address.s_net  = htons(sa->sat_addr.s_net);
@@ -523,17 +454,16 @@
 
 void aarp_probe_network(struct atalk_iface *atif)
 {
-	if(atif->dev->type == ARPHRD_LOCALTLK || atif->dev->type == ARPHRD_PPP) {
+	if (atif->dev->type == ARPHRD_LOCALTLK ||
+	    atif->dev->type == ARPHRD_PPP) 
 		aarp_send_probe_phase1(atif);
-	} else {
+	else {
 		unsigned int count;
 
 		for (count = 0; count < AARP_RETRANSMIT_LIMIT; count++) {
 			aarp_send_probe(atif->dev, &atif->address);
 
-			/*
-			 * Defer 1/10th
-			 */
+			/* Defer 1/10th */
 			current->state = TASK_INTERRUPTIBLE;
 			schedule_timeout(HZ/10);
 							
@@ -545,9 +475,9 @@
 
 int aarp_proxy_probe_network(struct atalk_iface *atif, struct at_addr *sa)
 {
-	struct	aarp_entry	*entry;
+	int hash, retval = 1;
+	struct aarp_entry *entry;
 	unsigned int count;
-	int	hash, retval;
 	
 	/*
 	 * we don't currently support LocalTalk or PPP for proxy AARP;
@@ -564,7 +494,7 @@
 	 * we need this one to hang around even if it's in use
 	 */
 	entry = aarp_alloc();
-	if (entry == NULL)
+	if (!entry)
 		return -ENOMEM;
 	
 	entry->expires_at = -1;
@@ -582,56 +512,38 @@
 	for (count = 0; count < AARP_RETRANSMIT_LIMIT; count++) {
 		aarp_send_probe(atif->dev, sa);
 
-		/*
-		 * Defer 1/10th
-		 */
+		/* Defer 1/10th */
 		current->state = TASK_INTERRUPTIBLE;
-
 		spin_unlock_bh(&aarp_lock);
-
 		schedule_timeout(HZ/10);
-						
 		spin_lock_bh(&aarp_lock);
 
 		if (entry->status & ATIF_PROBE_FAIL)
 			break;
 	}
 	
-	retval = 1;
-
 	if (entry->status & ATIF_PROBE_FAIL) {
-		/* free the entry */
-		entry->expires_at = jiffies - 1;
-		
-		/* return network full */
-		retval = -EADDRINUSE;
-	} else {
-		/* clear the probing flag */
+		entry->expires_at = jiffies - 1; /* free the entry */
+		retval = -EADDRINUSE; /* return network full */
+	} else /* clear the probing flag */
 		entry->status &= ~ATIF_PROBE;
-	}
 
 	spin_unlock_bh(&aarp_lock);
-
 	return retval;
 }
 
-
-/*
- *	Send a DDP frame
- */
-int aarp_send_ddp(struct net_device *dev,struct sk_buff *skb, struct at_addr *sa, void *hwaddr)
+/* Send a DDP frame */
+int aarp_send_ddp(struct net_device *dev,struct sk_buff *skb,
+			struct at_addr *sa, void *hwaddr)
 {
-	static char ddp_eth_multicast[ETH_ALEN] = { 0x09, 0x00, 0x07, 0xFF, 0xFF, 0xFF };
+	static char ddp_eth_multicast[ETH_ALEN] =
+		{ 0x09, 0x00, 0x07, 0xFF, 0xFF, 0xFF };
 	int hash;
 	struct aarp_entry *a;
 	
 	skb->nh.raw = skb->data;
 	
-	/*
-	 *	Check for LocalTalk first
-	 */
-	 
-	 
+	/* Check for LocalTalk first */
 	if (dev->type == ARPHRD_LOCALTLK) {
 		struct at_addr *at = atalk_find_dev_addr(dev);
 		struct ddpehdr *ddp = (struct ddpehdr *)skb->data;
@@ -644,8 +556,8 @@
 		 *	(zero matches anything)
 		 */
 		 
-		if( ( ddp->deh_snet==0 || at->s_net==ddp->deh_snet) &&
-		    ( ddp->deh_dnet==0 || at->s_net==ddp->deh_dnet) ) {
+		if ((!ddp->deh_snet || at->s_net == ddp->deh_snet) &&
+		    (!ddp->deh_dnet || at->s_net == ddp->deh_dnet)) {
 			skb_pull(skb, sizeof(struct ddpehdr) - 4);
 
 			/*
@@ -665,104 +577,58 @@
 		skb->data[0] = sa->s_node;
 		skb->data[1] = at->s_node;
 		skb->data[2] = ft;
-		 
-		if (skb->sk)
-			skb->priority = skb->sk->priority;
 		skb->dev = dev;
-		dev_queue_xmit(skb);
-		return 1;
+		goto sendit;
 	}	
 
-	/*
-	 *	On a PPP link we neither compress nor aarp.
-	 */
+	/* On a PPP link we neither compress nor aarp.  */
 	if (dev->type == ARPHRD_PPP) {
 		skb->protocol = htons(ETH_P_PPPTALK);
-		if (skb->sk)
-			skb->priority = skb->sk->priority;
 		skb->dev = dev;
-		dev_queue_xmit(skb);
-		return 1;
+		goto sendit;
 	}
 	 
-	/*
-	 *	Non ELAP we cannot do.
-	 */
-
+	/* Non ELAP we cannot do. */
 	if (dev->type != ARPHRD_ETHER)
 		return -1;
 
 	skb->dev = dev;
 	skb->protocol = htons(ETH_P_ATALK);
-			
 	hash = sa->s_node % (AARP_HASH_SIZE - 1);
 	
-	/*
-	 *	Do we have a resolved entry ?
-	 */
-	 
+	/* Do we have a resolved entry? */
 	if (sa->s_node == ATADDR_BCAST) {
 		ddp_dl->datalink_header(ddp_dl, skb, ddp_eth_multicast);
-
-		if (skb->sk)
-			skb->priority = skb->sk->priority;
-		dev_queue_xmit(skb);
-		return 1;
+		goto sendit;
 	}
 
 	spin_lock_bh(&aarp_lock);
-
 	a = __aarp_find_entry(resolved[hash], dev, sa);
 
-	if (a != NULL) {
-		/*
-		 *	Return 1 and fill in the address
-		 */
-
+	if (a) { /* Return 1 and fill in the address */
 		a->expires_at = jiffies + (sysctl_aarp_expiry_time * 10);
 		ddp_dl->datalink_header(ddp_dl, skb, a->hwaddr);
-		if(skb->sk)
-			skb->priority = skb->sk->priority;
-		dev_queue_xmit(skb);
-
 		spin_unlock_bh(&aarp_lock);
-		return 1;
+		goto sendit;
 	}
 
-	/*
-	 *	Do we have an unresolved entry: This is the less common path
-	 */
-
+	/* Do we have an unresolved entry: This is the less common path */
 	a = __aarp_find_entry(unresolved[hash], dev, sa);
-	if (a != NULL) {
-		/*
-		 *	Queue onto the unresolved queue
-		 */
-
+	if (a) { /* Queue onto the unresolved queue */
 		skb_queue_tail(&a->packet_queue, skb);
-
 		spin_unlock_bh(&aarp_lock);
 		return 0;
 	}
 
-	/*
-	 *	Allocate a new entry
-	 */
-
+	/* Allocate a new entry */
 	a = aarp_alloc();
-	if (a == NULL) {
-		/*
-		 *	Whoops slipped... good job it's an unreliable 
-		 *	protocol 8)	
-		 */
+	if (!a) {
+		/* Whoops slipped... good job it's an unreliable protocol 8) */
 		spin_unlock_bh(&aarp_lock);
 		return -1;
 	}
 
-	/*
-	 *	Set up the queue
-	 */
-
+	/* Set up the queue */
 	skb_queue_tail(&a->packet_queue, skb);
 	a->expires_at = jiffies + sysctl_aarp_resolve_time;
 	a->dev = dev;
@@ -772,10 +638,7 @@
 	unresolved[hash] = a;
 	unresolved_count++;
 
-	/*
-	 *	Send an initial request for the address
-	 */
-
+	/* Send an initial request for the address */
 	__aarp_send_query(a);
 
 	/*
@@ -786,18 +649,16 @@
 	if (unresolved_count == 1)
 		mod_timer(&aarp_timer, jiffies + sysctl_aarp_tick_time);
 
-
-	/*
-	 *	Now finally, it is safe to drop the lock.
-	 */
-
+	/* Now finally, it is safe to drop the lock. */
 	spin_unlock_bh(&aarp_lock);
 
-	/*
-	 *	Tell the ddp layer we have taken over for this frame.
-	 */
-
+	/* Tell the ddp layer we have taken over for this frame. */
 	return 0;
+
+sendit: if (skb->sk)
+		skb->priority = skb->sk->priority;
+	dev_queue_xmit(skb);
+	return 1;
 }
 
 /*
@@ -806,170 +667,112 @@
  *
  *	Must run under aarp_lock.
  */
-static void __aarp_resolved(struct aarp_entry **list, struct aarp_entry *a, int hash)
+static void __aarp_resolved(struct aarp_entry **list, struct aarp_entry *a,
+				int hash)
 {
 	struct sk_buff *skb;
 
-	while (*list != NULL) {
+	while (*list)
 		if (*list == a) {
 			unresolved_count--;
-
 			*list = a->next;
 
-			/* 
-			 *	Move into the resolved list 
-			 */
-
+			/* Move into the resolved list */
 			a->next = resolved[hash];
 			resolved[hash] = a;
 
-			/*
-			 *	Kick frames off 
-			 */
-
+			/* Kick frames off */
 			while ((skb = skb_dequeue(&a->packet_queue)) != NULL) {
-				a->expires_at = jiffies + (sysctl_aarp_expiry_time*10);
+				a->expires_at = jiffies +
+						sysctl_aarp_expiry_time * 10;
 				ddp_dl->datalink_header(ddp_dl, skb, a->hwaddr);
 				if (skb->sk)
 					skb->priority = skb->sk->priority;
 				dev_queue_xmit(skb);
 			}
-		} else {
+		} else 
 			list = &((*list)->next);
-		}
-	}
 }
 
 /*
  *	This is called by the SNAP driver whenever we see an AARP SNAP
  *	frame. We currently only support Ethernet.
  */
-static int aarp_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt)
+static int aarp_rcv(struct sk_buff *skb, struct net_device *dev,
+			struct packet_type *pt)
 {
-	struct elapaarp *ea=(struct elapaarp *)skb->h.raw;
+	struct elapaarp *ea = (struct elapaarp *)skb->h.raw;
+	int hash, ret = 0;
+	__u16 function;
 	struct aarp_entry *a;
 	struct at_addr sa, *ma, da;
-	int hash;
 	struct atalk_iface *ifa;
 
-	/*
-	 *	We only do Ethernet SNAP AARP.
-	 */
-
-	if (dev->type != ARPHRD_ETHER) {
-		kfree_skb(skb);
-		return 0;
-	}
-
-	/*
-	 *	Frame size ok ?
-	 */
-
-	if (!skb_pull(skb, sizeof(*ea))) {
-		kfree_skb(skb);
-		return 0;
-	}
-
-	ea->function = ntohs(ea->function);
+	/* We only do Ethernet SNAP AARP. */
+	if (dev->type != ARPHRD_ETHER)
+		goto out0;
 
-	/*
-	 *	Sanity check fields.
-	 */
+	/* Frame size ok? */
+	if (!skb_pull(skb, sizeof(*ea)))
+		goto out0;
 
-	if (ea->function < AARP_REQUEST ||
-	    ea->function > AARP_PROBE ||
-	    ea->hw_len != ETH_ALEN ||
-	    ea->pa_len != AARP_PA_ALEN ||
-	    ea->pa_src_zero != 0 ||
-	    ea->pa_dst_zero != 0) {
-		kfree_skb(skb);
-		return 0;
-	}
+	function = ntohs(ea->function);
 
-	/*
-	 *	Looks good.
-	 */
+	/* Sanity check fields. */
+	if (function < AARP_REQUEST || function > AARP_PROBE ||
+	    ea->hw_len != ETH_ALEN || ea->pa_len != AARP_PA_ALEN ||
+	    ea->pa_src_zero || ea->pa_dst_zero)
+		goto out0;
 
+	/* Looks good. */
 	hash = ea->pa_src_node % (AARP_HASH_SIZE - 1);
 
-	/*
-	 *	Build an address.
-	 */
-
+	/* Build an address. */
 	sa.s_node = ea->pa_src_node;
 	sa.s_net = ea->pa_src_net;
 
-	/*
-	 *	Process the packet.
-	 *	Check for replies of me.
-	 */
-
+	/* Process the packet. Check for replies of me. */
 	ifa = atalk_find_dev(dev);
-	if (ifa == NULL) {
-		kfree_skb(skb);
-		return 1;
-	}
-
-	if (ifa->status & ATIF_PROBE) {
-		if (ifa->address.s_node == ea->pa_dst_node &&
-		    ifa->address.s_net == ea->pa_dst_net) {
-			/*
-			 *	Fail the probe (in use)
-			 */
+	if (!ifa)
+		goto out1;
 
-			ifa->status |= ATIF_PROBE_FAIL;
-			kfree_skb(skb);
-			return 1;
-		}
+	if (ifa->status & ATIF_PROBE &&
+	    ifa->address.s_node == ea->pa_dst_node &&
+	    ifa->address.s_net == ea->pa_dst_net) {
+		ifa->status |= ATIF_PROBE_FAIL; /* Fail the probe (in use) */
+		goto out1;
 	}
 
-	/*
-	 * Check for replies of proxy AARP entries
-	 */
-
+	/* Check for replies of proxy AARP entries */
 	da.s_node = ea->pa_dst_node;
 	da.s_net = ea->pa_dst_net;
 
 	spin_lock_bh(&aarp_lock);
-
 	a = __aarp_find_entry(proxies[hash], dev, &da);
 
-	if (a != NULL) {
-		if (a->status & ATIF_PROBE) {
-			a->status |= ATIF_PROBE_FAIL;
-
-			spin_unlock_bh(&aarp_lock);
-
-			/*
-			 * we do not respond to probe or request packets for
-			 * this address while we are probing this address
-			 */
-			kfree_skb(skb);
-
-			return 1;
-		}
+	if (a && a->status & ATIF_PROBE) {
+		a->status |= ATIF_PROBE_FAIL;
+		/*
+		 * we do not respond to probe or request packets for
+		 * this address while we are probing this address
+		 */
+		goto unlock;
 	}
 
-	switch (ea->function) {
+	switch (function) {
 		case AARP_REPLY:	
-			if (unresolved_count == 0)	/* Speed up */
+			if (!unresolved_count)	/* Speed up */
 				break;
 
-			/*
-			 *	Find the entry.
-			 */
-			 
-			if ((a = __aarp_find_entry(unresolved[hash],dev,&sa)) == NULL ||
-			    (dev != a->dev))
+			/* Find the entry.  */
+			a = __aarp_find_entry(unresolved[hash],dev,&sa);
+			if (!a || dev != a->dev)
 				break;
 
-			/*
-			 *	We can fill one in - this is good.
-			 */
-			 
+			/* We can fill one in - this is good. */
 			memcpy(a->hwaddr,ea->hw_src,ETH_ALEN);
 			__aarp_resolved(&unresolved[hash],a,hash);
-			if (unresolved_count == 0)
+			if (!unresolved_count)
 				mod_timer(&aarp_timer,
 					  jiffies + sysctl_aarp_expiry_time);
 			break;
@@ -977,49 +780,45 @@
 		case AARP_REQUEST:
 		case AARP_PROBE:
 			/*
-			 *	If it is my address set ma to my address and reply. We can treat probe and
-			 *	request the same. Probe simply means we shouldn't cache the querying host, 
-			 *	as in a probe they are proposing an address not using one.
+			 *	If it is my address set ma to my address and
+			 *	reply. We can treat probe and request the
+			 *	same. Probe simply means we shouldn't cache
+			 *	the querying host, as in a probe they are
+			 *	proposing an address not using one.
 			 *	
-			 *	Support for proxy-AARP added.  We check if the address is one
-			 *	of our proxies before we toss the packet out.
+			 *	Support for proxy-AARP added. We check if the
+			 *	address is one of our proxies before we toss
+			 *	the packet out.
 			 */
 			 
 			sa.s_node = ea->pa_dst_node;
 			sa.s_net = ea->pa_dst_net;
 
-			/*
-			 * See if we have a matching proxy.
-			 */
+			/* See if we have a matching proxy. */
 			ma = __aarp_proxy_find(dev, &sa);
-			if (!ma) {
+			if (!ma)
 				ma = &ifa->address;
-			} else {
-				/*
-				 * We need to make a copy of the entry.
-				 */
+			else { /* We need to make a copy of the entry. */
 				da.s_node = sa.s_node;
 				da.s_net = da.s_net;
 				ma = &da;
 			}
 
-			if (ea->function == AARP_PROBE) {
+			if (function == AARP_PROBE) {
 				/* A probe implies someone trying to get an
 				 * address. So as a precaution flush any
-				 * entries we have for this address.
-				 */
+				 * entries we have for this address. */
 				struct aarp_entry *a = __aarp_find_entry(
-						resolved[sa.s_node%(AARP_HASH_SIZE-1)],
-						skb->dev,
-						&sa);
+					resolved[sa.s_node%(AARP_HASH_SIZE-1)],
+					skb->dev, &sa);
 				/* Make it expire next tick - that avoids us
-				 * getting into a probe/flush/learn/probe/flush/learn
-				 * cycle during probing of a slow to respond host addr.
-				 */
-				if (a != NULL)
-				{
+				 * getting into a probe/flush/learn/probe/
+				 * flush/learn cycle during probing of a slow
+				 * to respond host addr. */
+				if (a) {
 					a->expires_at = jiffies - 1;
-					mod_timer(&aarp_timer, jiffies + sysctl_aarp_tick_time);
+					mod_timer(&aarp_timer, jiffies +
+							sysctl_aarp_tick_time);
 				}
 			}
 
@@ -1032,18 +831,16 @@
 			sa.s_node = ea->pa_src_node;
 			sa.s_net = ea->pa_src_net;
 			
-			/*
-			 *	aarp_my_address has found the address to use for us.
-			 */
-			 
+			/* aarp_my_address has found the address to use for us.
+			*/
 			aarp_send_reply(dev, ma, &sa, ea->hw_src);
 			break;
-	};
-
-	spin_unlock_bh(&aarp_lock);
+	}
 
-	kfree_skb(skb);
-	return 1;
+unlock:	spin_unlock_bh(&aarp_lock);
+out1:	ret = 1;
+out0:	kfree_skb(skb);
+	return ret;
 }
 
 static struct notifier_block aarp_notifier = {
@@ -1054,10 +851,10 @@
 
 static char aarp_snap_id[] = { 0x00, 0x00, 0x00, 0x80, 0xF3 };
 
-
 void __init aarp_proto_init(void)
 {
-	if ((aarp_dl = register_snap_client(aarp_snap_id, aarp_rcv)) == NULL)
+	aarp_dl = register_snap_client(aarp_snap_id, aarp_rcv);
+	if (!aarp_dl)
 		printk(KERN_CRIT "Unable to register AARP with SNAP.\n");
 	init_timer(&aarp_timer);
 	aarp_timer.function = aarp_expire_timeout;
@@ -1067,9 +864,7 @@
 	register_netdevice_notifier(&aarp_notifier);
 }
 
-/*
- * Remove the AARP entries associated with a device.
- */
+/* Remove the AARP entries associated with a device. */
 void aarp_device_down(struct net_device *dev)
 {
 	int ct;
@@ -1085,14 +880,12 @@
 	spin_unlock_bh(&aarp_lock);
 }
 
-/*
- * Called from proc fs
- */
+/* Called from proc fs */
 static int aarp_get_info(char *buffer, char **start, off_t offset, int length)
 {
 	/* we should dump all our AARP entries */
-	struct aarp_entry	*entry;
-	int			len, ct;
+	struct aarp_entry *entry;
+	int len, ct;
 
 	len = sprintf(buffer,
 		"%-10.10s  ""%-10.10s""%-18.18s""%12.12s""%12.12s"" xmit_count  status\n",
@@ -1171,25 +964,19 @@
 	}
 
 	spin_unlock_bh(&aarp_lock);
-
 	return len;
 }
 
 #ifdef MODULE
-/*
- * General module cleanup. Called from cleanup_module() in ddp.c.
- */
+/* General module cleanup. Called from cleanup_module() in ddp.c. */
 void aarp_cleanup_module(void)
 {
 	del_timer(&aarp_timer);
 	unregister_netdevice_notifier(&aarp_notifier);
 	unregister_snap_client(aarp_snap_id);
 }
-
 #endif  /* MODULE */
-
 #ifdef CONFIG_PROC_FS
-
 void aarp_register_proc_fs(void)
 {
 	proc_net_create("aarp", 0, aarp_get_info);
@@ -1199,7 +986,5 @@
 {
 	proc_net_remove("aarp");
 }
-
 #endif
-
 #endif  /* CONFIG_ATALK || CONFIG_ATALK_MODULE */

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