Module Name: src Committed By: ozaki-r Date: Tue Mar 6 07:27:55 UTC 2018
Modified Files: src/sys/net: if_llatbl.c if_llatbl.h src/sys/netinet: in.c src/sys/netinet6: in6.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/sys/net/if_llatbl.c cvs rdiff -u -r1.13 -r1.14 src/sys/net/if_llatbl.h cvs rdiff -u -r1.222 -r1.223 src/sys/netinet/in.c cvs rdiff -u -r1.263 -r1.264 src/sys/netinet6/in6.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/net/if_llatbl.c diff -u src/sys/net/if_llatbl.c:1.25 src/sys/net/if_llatbl.c:1.26 --- src/sys/net/if_llatbl.c:1.25 Tue Mar 6 07:25:27 2018 +++ src/sys/net/if_llatbl.c Tue Mar 6 07:27:55 2018 @@ -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 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__ Index: src/sys/net/if_llatbl.h diff -u src/sys/net/if_llatbl.h:1.13 src/sys/net/if_llatbl.h:1.14 --- src/sys/net/if_llatbl.h:1.13 Fri Nov 10 07:24:28 2017 +++ src/sys/net/if_llatbl.h Tue Mar 6 07:27:55 2018 @@ -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 *); Index: src/sys/netinet/in.c diff -u src/sys/netinet/in.c:1.222 src/sys/netinet/in.c:1.223 --- src/sys/netinet/in.c:1.222 Tue Mar 6 07:25:27 2018 +++ src/sys/netinet/in.c Tue Mar 6 07:27:55 2018 @@ -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, #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 *l 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_i * 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); + 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->base); + return lle; } #define IN_ARE_MASKED_ADDR_EQUAL(d, a, m) ( \ Index: src/sys/netinet6/in6.c diff -u src/sys/netinet6/in6.c:1.263 src/sys/netinet6/in6.c:1.264 --- src/sys/netinet6/in6.c:1.263 Tue Mar 6 07:25:27 2018 +++ src/sys/netinet6/in6.c Tue Mar 6 07:27:55 2018 @@ -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_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