From f1b6d58e816f842f0029ce0f3b68022a10b80b42 Mon Sep 17 00:00:00 2001 From: enami Date: Mon, 24 Jan 2005 04:46:49 +0000 Subject: [PATCH] To fix bad pointer dereference on start up when gif is used, - Allow rn_init() to be called multiple times, but do nothing except the first call. - Include opt_inet.h so that #ifdef INET works. - Call rn_init() from encap_init() explicitly rather than depending on the order of initialization. --- sys/net/radix.c | 21 +++++++++++++++------ sys/netinet/ip_encap.c | 5 +++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/sys/net/radix.c b/sys/net/radix.c index bdf1900c05a0..cfb50ba5daff 100644 --- a/sys/net/radix.c +++ b/sys/net/radix.c @@ -1,4 +1,4 @@ -/* $NetBSD: radix.c,v 1.26 2005/01/23 18:41:56 matt Exp $ */ +/* $NetBSD: radix.c,v 1.27 2005/01/24 04:46:49 enami Exp $ */ /* * Copyright (c) 1988, 1989, 1993 @@ -36,11 +36,13 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: radix.c,v 1.26 2005/01/23 18:41:56 matt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: radix.c,v 1.27 2005/01/24 04:46:49 enami Exp $"); #ifndef _NET_RADIX_H_ #include #ifdef _KERNEL +#include "opt_inet.h" + #include #include #define M_DONTWAIT M_NOWAIT @@ -943,11 +945,18 @@ rn_init() { char *cp, *cplim; #ifdef _KERNEL - struct domain *dom; + static int initialized; + __link_set_decl(domains, struct domain); + struct domain *const *dpp; - DOMAIN_FOREACH(dom) - if (dom->dom_maxrtkey > max_keylen) - max_keylen = dom->dom_maxrtkey; + if (initialized) + return; + initialized = 1; + + __link_set_foreach(dpp, domains) { + if ((*dpp)->dom_maxrtkey > max_keylen) + max_keylen = (*dpp)->dom_maxrtkey; + } #ifdef INET encap_setkeylen(); #endif diff --git a/sys/netinet/ip_encap.c b/sys/netinet/ip_encap.c index eb196749d206..22d5d50554a3 100644 --- a/sys/netinet/ip_encap.c +++ b/sys/netinet/ip_encap.c @@ -70,7 +70,7 @@ #define USE_RADIX #include -__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.20 2005/01/24 02:42:49 itojun Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.21 2005/01/24 04:46:49 enami Exp $"); #include "opt_mrouting.h" #include "opt_inet.h" @@ -192,8 +192,9 @@ encap_init() #ifdef USE_RADIX /* * initialize radix lookup table. - * max_keylen initialization should happen before the call to rn_init(). + * max_keylen initialization happen in the rn_init(). */ + rn_init(); rn_inithead((void *)&encap_head[0], sizeof(struct sockaddr_pack) << 3); #ifdef INET6 rn_inithead((void *)&encap_head[1], sizeof(struct sockaddr_pack) << 3);