summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorozaki-r <ozaki-r@NetBSD.org>2018-03-06 07:27:55 +0000
committerozaki-r <ozaki-r@NetBSD.org>2018-03-06 07:27:55 +0000
commit189cfbc96fa2dcb47b5f0e57a9400a886ae7489c (patch)
tree1b4bb456a58231454ba8371526e5d2141a9b2725
parent39d7ee4d3c5f654bfdd179ab64dc54fd17d7673b (diff)
Use pool(9) for llentry allocations
llentry is easy to be leaked and pool suits for it because pool is usable to detect leaks. Also sweep unnecessary wrappers for llentry, in_llentry and in6_llentry.
-rw-r--r--sys/net/if_llatbl.c24
-rw-r--r--sys/net/if_llatbl.h5
-rw-r--r--sys/netinet/in.c30
-rw-r--r--sys/netinet6/in6.c26
4 files changed, 51 insertions, 34 deletions
diff --git a/sys/net/if_llatbl.c b/sys/net/if_llatbl.c
index 57f6b49ffa1..7fc7d19602d 100644
--- a/sys/net/if_llatbl.c
+++ b/sys/net/if_llatbl.c
@@ -1,4 +1,4 @@
-/* $NetBSD: if_llatbl.c,v 1.25 2018/03/06 07:25:27 ozaki-r Exp $ */
+/* $NetBSD: if_llatbl.c,v 1.26 2018/03/06 07:27:55 ozaki-r Exp $ */
/*
* Copyright (c) 2004 Luigi Rizzo, Alessandro Cerri. All rights reserved.
* Copyright (c) 2004-2008 Qing Li. All rights reserved.
@@ -67,6 +67,7 @@
static SLIST_HEAD(, lltable) lltables;
krwlock_t lltable_rwlock;
+static struct pool llentry_pool;
static void lltable_unlink(struct lltable *llt);
static void llentries_unlink(struct lltable *llt, struct llentries *head);
@@ -335,6 +336,24 @@ lltable_drop_entry_queue(struct llentry *lle)
return (pkts_dropped);
}
+struct llentry *
+llentry_pool_get(int flags)
+{
+ struct llentry *lle;
+
+ lle = pool_get(&llentry_pool, flags);
+ if (lle != NULL)
+ memset(lle, 0, sizeof(*lle));
+ return lle;
+}
+
+void
+llentry_pool_put(struct llentry *lle)
+{
+
+ pool_put(&llentry_pool, lle);
+}
+
/*
* Deletes an address from the address table.
* This function is called by the timer functions
@@ -747,6 +766,9 @@ lltableinit(void)
SLIST_INIT(&lltables);
rw_init(&lltable_rwlock);
+
+ pool_init(&llentry_pool, sizeof(struct llentry), 0, 0, 0, "llentrypl",
+ NULL, IPL_SOFTNET);
}
#ifdef __FreeBSD__
diff --git a/sys/net/if_llatbl.h b/sys/net/if_llatbl.h
index e53c2c75abd..4c5d13e986c 100644
--- a/sys/net/if_llatbl.h
+++ b/sys/net/if_llatbl.h
@@ -1,4 +1,4 @@
-/* $NetBSD: if_llatbl.h,v 1.13 2017/11/10 07:24:28 ozaki-r Exp $ */
+/* $NetBSD: if_llatbl.h,v 1.14 2018/03/06 07:27:55 ozaki-r Exp $ */
/*
* Copyright (c) 2004 Luigi Rizzo, Alessandro Cerri. All rights reserved.
* Copyright (c) 2004-2008 Qing Li. All rights reserved.
@@ -266,6 +266,9 @@ size_t llentry_free(struct llentry *);
struct llentry *llentry_alloc(struct ifnet *, struct lltable *,
struct sockaddr_storage *);
+struct llentry *llentry_pool_get(int);
+void llentry_pool_put(struct llentry *);
+
/* helper functions */
size_t lltable_drop_entry_queue(struct llentry *);
diff --git a/sys/netinet/in.c b/sys/netinet/in.c
index fb58da77926..b2753865062 100644
--- a/sys/netinet/in.c
+++ b/sys/netinet/in.c
@@ -1,4 +1,4 @@
-/* $NetBSD: in.c,v 1.222 2018/03/06 07:25:27 ozaki-r Exp $ */
+/* $NetBSD: in.c,v 1.223 2018/03/06 07:27:55 ozaki-r Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.222 2018/03/06 07:25:27 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.223 2018/03/06 07:27:55 ozaki-r Exp $");
#include "arp.h"
@@ -1918,10 +1918,6 @@ in_tunnel_validate(const struct ip *ip, struct in_addr src, struct in_addr dst)
#if NARP > 0
-struct in_llentry {
- struct llentry base;
-};
-
#define IN_LLTBL_DEFAULT_HSIZE 32
#define IN_LLTBL_HASH(k, h) \
(((((((k >> 8) ^ k) >> 8) ^ k) >> 8) ^ k) & ((h) - 1))
@@ -1939,15 +1935,15 @@ in_lltable_destroy_lle(struct llentry *lle)
LLE_WUNLOCK(lle);
LLE_LOCK_DESTROY(lle);
- kmem_intr_free(lle, sizeof(*lle));
+ llentry_pool_put(lle);
}
static struct llentry *
in_lltable_new(struct in_addr addr4, u_int flags)
{
- struct in_llentry *lle;
+ struct llentry *lle;
- lle = kmem_intr_zalloc(sizeof(*lle), KM_NOSLEEP);
+ lle = llentry_pool_get(PR_NOWAIT);
if (lle == NULL) /* NB: caller generates msg */
return NULL;
@@ -1955,14 +1951,14 @@ in_lltable_new(struct in_addr addr4, u_int flags)
* For IPv4 this will trigger "arpresolve" to generate
* an ARP request.
*/
- lle->base.la_expire = time_uptime; /* mark expired */
- lle->base.r_l3addr.addr4 = addr4;
- lle->base.lle_refcnt = 1;
- lle->base.lle_free = in_lltable_destroy_lle;
- LLE_LOCK_INIT(&lle->base);
- callout_init(&lle->base.la_timer, CALLOUT_MPSAFE);
-
- return (&lle->base);
+ lle->la_expire = time_uptime; /* mark expired */
+ lle->r_l3addr.addr4 = addr4;
+ lle->lle_refcnt = 1;
+ lle->lle_free = in_lltable_destroy_lle;
+ LLE_LOCK_INIT(lle);
+ callout_init(&lle->la_timer, CALLOUT_MPSAFE);
+
+ return lle;
}
#define IN_ARE_MASKED_ADDR_EQUAL(d, a, m) ( \
diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c
index d7a1ff27752..96aa0e7b0e5 100644
--- a/sys/netinet6/in6.c
+++ b/sys/netinet6/in6.c
@@ -1,4 +1,4 @@
-/* $NetBSD: in6.c,v 1.263 2018/03/06 07:25:27 ozaki-r Exp $ */
+/* $NetBSD: in6.c,v 1.264 2018/03/06 07:27:55 ozaki-r Exp $ */
/* $KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $ */
/*
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.263 2018/03/06 07:25:27 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.264 2018/03/06 07:27:55 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -2386,10 +2386,6 @@ in6_if2idlen(struct ifnet *ifp)
}
}
-struct in6_llentry {
- struct llentry base;
-};
-
#define IN6_LLTBL_DEFAULT_HSIZE 32
#define IN6_LLTBL_HASH(k, h) \
(((((((k >> 8) ^ k) >> 8) ^ k) >> 8) ^ k) & ((h) - 1))
@@ -2407,25 +2403,25 @@ in6_lltable_destroy_lle(struct llentry *lle)
LLE_WUNLOCK(lle);
LLE_LOCK_DESTROY(lle);
- kmem_intr_free(lle, sizeof(struct in6_llentry));
+ llentry_pool_put(lle);
}
static struct llentry *
in6_lltable_new(const struct in6_addr *addr6, u_int flags)
{
- struct in6_llentry *lle;
+ struct llentry *lle;
- lle = kmem_intr_zalloc(sizeof(struct in6_llentry), KM_NOSLEEP);
+ lle = llentry_pool_get(PR_NOWAIT);
if (lle == NULL) /* NB: caller generates msg */
return NULL;
- lle->base.r_l3addr.addr6 = *addr6;
- lle->base.lle_refcnt = 1;
- lle->base.lle_free = in6_lltable_destroy_lle;
- LLE_LOCK_INIT(&lle->base);
- callout_init(&lle->base.lle_timer, CALLOUT_MPSAFE);
+ lle->r_l3addr.addr6 = *addr6;
+ lle->lle_refcnt = 1;
+ lle->lle_free = in6_lltable_destroy_lle;
+ LLE_LOCK_INIT(lle);
+ callout_init(&lle->lle_timer, CALLOUT_MPSAFE);
- return &lle->base;
+ return lle;
}
static int