From d0a72d948e70eac20228005908250534eeb9d671 Mon Sep 17 00:00:00 2001 From: melifaro Date: Tue, 13 Mar 2012 11:08:40 +0000 Subject: [PATCH] Use rt_numfibs variable instead of compile-time RT_NUMFIBS. Reviewed by: glebius (previous version) Approved by: kib(mentor), ae(mentor) --- sys/modules/netgraph/netflow/Makefile | 2 -- sys/netgraph/netflow/netflow.c | 2 +- sys/netgraph/netflow/ng_netflow.c | 12 ++++++++++-- sys/netgraph/netflow/ng_netflow.h | 3 ++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/sys/modules/netgraph/netflow/Makefile b/sys/modules/netgraph/netflow/Makefile index 8330268f8747..fb38b241e5cc 100644 --- a/sys/modules/netgraph/netflow/Makefile +++ b/sys/modules/netgraph/netflow/Makefile @@ -17,8 +17,6 @@ opt_inet6.h: echo "#define INET6 1" > ${.TARGET} .endif -opt_route.h: - echo "#define ROUTETABLES RT_MAXFIBS" > ${.TARGET} .endif .include diff --git a/sys/netgraph/netflow/netflow.c b/sys/netgraph/netflow/netflow.c index 8ec5629af613..c3443e599e18 100644 --- a/sys/netgraph/netflow/netflow.c +++ b/sys/netgraph/netflow/netflow.c @@ -630,7 +630,7 @@ ng_netflow_cache_flush(priv_p priv) free(priv->hash6, M_NETFLOW_HASH); #endif - for (i = 0; i < RT_NUMFIBS; i++) { + for (i = 0; i < priv->maxfibs; i++) { if ((fe = priv_to_fib(priv, i)) == NULL) continue; diff --git a/sys/netgraph/netflow/ng_netflow.c b/sys/netgraph/netflow/ng_netflow.c index 64adc28a4618..727136283b86 100644 --- a/sys/netgraph/netflow/ng_netflow.c +++ b/sys/netgraph/netflow/ng_netflow.c @@ -225,6 +225,11 @@ ng_netflow_constructor(node_p node) /* Initialize private data */ priv = malloc(sizeof(*priv), M_NETGRAPH, M_WAITOK | M_ZERO); + /* Initialize fib data */ + priv->maxfibs = rt_numfibs; + priv->fib_data = malloc(sizeof(fib_export_p) * priv->maxfibs, + M_NETGRAPH, M_WAITOK | M_ZERO); + /* Make node and its data point at each other */ NG_NODE_SET_PRIVATE(node, priv); priv->node = node; @@ -901,8 +906,10 @@ loopend: /* Check packet FIB */ fib = M_GETFIB(m); - if (fib >= RT_NUMFIBS) { - CTR2(KTR_NET, "ng_netflow_rcvdata(): packet fib %d is out of range of available fibs: 0 .. %d", fib, RT_NUMFIBS); + if (fib >= priv->maxfibs) { + CTR2(KTR_NET, "ng_netflow_rcvdata(): packet fib %d is out of " + "range of available fibs: 0 .. %d", + fib, priv->maxfibs); goto bypass; } @@ -973,6 +980,7 @@ ng_netflow_rmnode(node_p node) NG_NODE_SET_PRIVATE(node, NULL); NG_NODE_UNREF(priv->node); + free(priv->fib_data, M_NETGRAPH); free(priv, M_NETGRAPH); return (0); diff --git a/sys/netgraph/netflow/ng_netflow.h b/sys/netgraph/netflow/ng_netflow.h index ed11f35e9cc8..bab04c77976d 100644 --- a/sys/netgraph/netflow/ng_netflow.h +++ b/sys/netgraph/netflow/ng_netflow.h @@ -413,7 +413,8 @@ struct netflow { struct flow_hash_entry *hash6; #endif /* Multiple FIB support */ - fib_export_p fib_data[RT_NUMFIBS]; /* array of pointers to fib-specific data */ + fib_export_p *fib_data; /* array of pointers to per-fib data */ + uint16_t maxfibs; /* number of allocated fibs */ /* * RFC 3954 clause 7.3