From 8a04d5f675b4c72c86fffc1a476da07ca212610b Mon Sep 17 00:00:00 2001 From: "Anand H. Krishnan" Date: Mon, 13 Apr 2015 19:54:10 +0530 Subject: [PATCH] Fix ipv6 route table base calculation Wrong pointer math made ipv6 route table base to overlap with ipv4 route table, resulting in unpredictable tables and memory corruption. Change-Id: Ia31a555cf3abb108af31c1ee74c4cd7384570de6 Closes-BUG: #1439654 --- dp-core/vr_ip_mtrie.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/dp-core/vr_ip_mtrie.c b/dp-core/vr_ip_mtrie.c index 27d728001..9ea216a6e 100644 --- a/dp-core/vr_ip_mtrie.c +++ b/dp-core/vr_ip_mtrie.c @@ -1054,8 +1054,7 @@ mtrie_algo_deinit(struct vr_rtable *rtable, struct rtable_fspec *fs, bool soft_r static int mtrie_stats_init(struct vr_rtable *rtable) { - int ret = 0; - unsigned int i; + int ret = 0, i; unsigned int stats_memory; stats_memory = sizeof(void *) * rtable->algo_max_vrfs; @@ -1132,9 +1131,11 @@ mtrie_algo_init(struct vr_rtable *rtable, struct rtable_fspec *fs) vr_inet_route_lookup = mtrie_lookup; vr_inet_vrf_stats = mtrie_stats; /* local cache */ - vn_rtable[0] = (struct ip_mtrie **)rtable->algo_data; // V4 table - vn_rtable[1] = (struct ip_mtrie **)((char*)rtable->algo_data - + fs->rtb_max_vrfs); // V6 table + /* ipv4 table */ + vn_rtable[0] = (struct ip_mtrie **)rtable->algo_data; + /* ipv6 table */ + vn_rtable[1] = (struct ip_mtrie **)((unsigned char **)rtable->algo_data + + fs->rtb_max_vrfs); mtrie_ip_bkt_info_init(ip4_bkt_info, IP4_PREFIX_LEN); mtrie_ip_bkt_info_init(ip6_bkt_info, IP6_PREFIX_LEN);