From 22d9d9a28fe32b6de5a5d92d42f450cd69352486 Mon Sep 17 00:00:00 2001
From: Laine Stump <laine@laine.org>
Date: Tue, 18 Jun 2013 12:42:41 -0400
Subject: [PATCH] network: increase max number of routes

This fixes the problem reported in:

   https://bugzilla.redhat.com/show_bug.cgi?id=972690

When checking for a collision of a new libvirt network's subnet with
any existing routes, we read all of /proc/net/route into memory, then
parse all the entries. The function that we use to read this file
requires a "maximum length" parameter, which had previously been set
to 64*1024. As each line in /proc/net/route is 128 bytes, this would
allow for a maximum of 512 entries in the routing table.

This patch increases that number to 128 * 100000, which allows for
100,000 routing table entries. This means that it's possible that 12MB
would be allocated, but that would only happen if there really were
100,000 route table entries on the system, it's only held for a very
short time.

Since there is no method of specifying and unlimited max (and that
would create a potential denial of service anyway) hopefully this
limit is large enough to accomodate everyone.

(cherry picked from commit 2bdf548f5f0f709c9dec8ba1872e4fcaf8c25fbf)
---
 src/network/bridge_driver.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 777024fbbb..24d545e2f9 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -2300,7 +2300,8 @@ networkCheckRouteCollision(virNetworkObjPtr network)
 {
     int ret = 0, len;
     char *cur, *buf = NULL;
-    enum {MAX_ROUTE_SIZE = 1024*64};
+    /* allow for up to 100000 routes (each line is 128 bytes) */
+    enum {MAX_ROUTE_SIZE = 128*100000};
 
     /* Read whole routing table into memory */
     if ((len = virFileReadAll(PROC_NET_ROUTE, MAX_ROUTE_SIZE, &buf)) < 0)
-- 
GitLab