Module Name:    src
Committed By:   ozaki-r
Date:           Mon Oct  5 08:17:32 UTC 2015

Modified Files:
        src/sys/netinet: if_arp.c

Log Message:
Fix arplookup logic

It should first lookup and then create an entry if not found (and if
creation is requested).


To generate a diff of this commit:
cvs rdiff -u -r1.181 -r1.182 src/sys/netinet/if_arp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netinet/if_arp.c
diff -u src/sys/netinet/if_arp.c:1.181 src/sys/netinet/if_arp.c:1.182
--- src/sys/netinet/if_arp.c:1.181	Fri Sep 11 10:33:32 2015
+++ src/sys/netinet/if_arp.c	Mon Oct  5 08:17:31 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.c,v 1.181 2015/09/11 10:33:32 roy Exp $	*/
+/*	$NetBSD: if_arp.c,v 1.182 2015/10/05 08:17:31 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.181 2015/09/11 10:33:32 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.182 2015/10/05 08:17:31 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1471,14 +1471,14 @@ arplookup(struct ifnet *ifp, struct mbuf
 		struct llentry *la;
 		int flags = wlock ? LLE_EXCLUSIVE : 0;
 
-		if (create) {
+		IF_AFDATA_RLOCK(ifp);
+		la = lla_lookup(LLTABLE(ifp), flags, rt_getkey(rt));
+		IF_AFDATA_RUNLOCK(ifp);
+
+		if (la == NULL && create) {
 			IF_AFDATA_WLOCK(ifp);
 			la = lla_create(LLTABLE(ifp), flags, rt_getkey(rt));
 			IF_AFDATA_WUNLOCK(ifp);
-		} else {
-			IF_AFDATA_RLOCK(ifp);
-			la = lla_lookup(LLTABLE(ifp), flags, rt_getkey(rt));
-			IF_AFDATA_RUNLOCK(ifp);
 		}
 
 		return la;

Reply via email to