]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Remove count_netmask_bits(), convert users to use netmask_to_netbits2()
authorGert Doering <gert@greenie.muc.de>
Sat, 27 Dec 2014 20:59:43 +0000 (21:59 +0100)
committerGert Doering <gert@greenie.muc.de>
Sun, 8 Mar 2015 19:18:25 +0000 (20:18 +0100)
The previous Linux/iproute2 code converted binary netmasks to string
representation (print_in_addr_t()), just to immediately scanf() it back
to binary to count bits.  netmask_to_netbits2() directly works on the
in_addr_t.

Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: Steffan Karger <steffan.karger@fox-it.com>
Message-Id: <1419713983-16272-1-git-send-email-gert@greenie.muc.de>
URL: http://article.gmane.org/gmane.network.openvpn.devel/9360

src/openvpn/misc.c
src/openvpn/misc.h
src/openvpn/route.c
src/openvpn/route.h
src/openvpn/tun.c

index 61bc523dda0907a8af2576a1f4c8da20fab10170..5627cb9eaec4b4b423ebbc6e32a460a2e97566fa 100644 (file)
@@ -827,32 +827,6 @@ setenv_str_i (struct env_set *es, const char *name, const char *value, const int
   gc_free (&gc);
 }
 
-/*
- * taken from busybox networking/ifupdown.c
- */
-unsigned int
-count_bits(unsigned int a)
-{
-  unsigned int result;
-  result = (a & 0x55) + ((a >> 1) & 0x55);
-  result = (result & 0x33) + ((result >> 2) & 0x33);
-  return((result & 0x0F) + ((result >> 4) & 0x0F));
-}
-
-int
-count_netmask_bits(const char *dotted_quad)
-{
-  unsigned int result, a, b, c, d;
-  /* Found a netmask...  Check if it is dotted quad */
-  if (sscanf(dotted_quad, "%u.%u.%u.%u", &a, &b, &c, &d) != 4)
-    return -1;
-  result = count_bits(a);
-  result += count_bits(b);
-  result += count_bits(c);
-  result += count_bits(d);
-  return ((int)result);
-}
-
 /* return true if filename can be opened for read */
 bool
 test_file (const char *filename)
index 41748bd8324a6025f419b3440e05831de0f9e4cd..5fe085e916e6d3a6aad9eae3e0578d95b0bd7df4 100644 (file)
@@ -166,10 +166,6 @@ const char **make_env_array (const struct env_set *es,
 const char **make_arg_array (const char *first, const char *parms, struct gc_arena *gc);
 const char **make_extended_arg_array (char **p, struct gc_arena *gc);
 
-/* convert netmasks for iproute2 */
-int count_netmask_bits(const char *);
-unsigned int count_bits(unsigned int );
-
 /* an analogue to the random() function, but use OpenSSL functions if available */
 #ifdef ENABLE_CRYPTO
 long int get_random(void);
index 7ec482b9ce9a31553fdc95baa930c07abdba906a..a349ac9808cbf2eb6e21f8b4a45cfe33e08c00b4 100644 (file)
@@ -1288,7 +1288,7 @@ add_route (struct route_ipv4 *r,
   argv_printf (&argv, "%s route add %s/%d",
              iproute_path,
              network,
-             count_netmask_bits(netmask));
+              netmask_to_netbits2(r->netmask));
 
   if (r->flags & RT_METRIC_DEFINED)
     argv_printf_cat (&argv, "metric %d", r->metric);
@@ -1765,7 +1765,7 @@ delete_route (struct route_ipv4 *r,
   argv_printf (&argv, "%s route del %s/%d",
              iproute_path,
              network,
-             count_netmask_bits(netmask));
+              netmask_to_netbits2(r->netmask));
 #else
   argv_printf (&argv, "%s del -net %s netmask %s",
               ROUTE_PATH,
index f3c01501e2515367c07576e9b4ca04fc36c2e939..3cec08dfb35dfa215fabb1963e73e87b966751fd 100644 (file)
@@ -305,6 +305,7 @@ static inline bool test_routes (const struct route_list *rl, const struct tuntap
 #endif
 
 bool netmask_to_netbits (const in_addr_t network, const in_addr_t netmask, int *netbits);
+int netmask_to_netbits2 (in_addr_t netmask);
 
 static inline in_addr_t
 netbits_to_netmask (const int netbits)
index e92edc2f6f114ed7ce42e56fa94081da89acf08f..11a6d714cd1dcb64c9df1f55cc8493a7a6e7e7a3 100644 (file)
@@ -722,7 +722,7 @@ do_ifconfig (struct tuntap *tt,
                                  iproute_path,
                                  actual,
                                  ifconfig_local,
-                                 count_netmask_bits(ifconfig_remote_netmask),
+                                 netmask_to_netbits2(tt->remote_netmask),
                                  ifconfig_broadcast
                                  );
                  argv_msg (M_INFO, &argv);
@@ -1819,7 +1819,7 @@ close_tun (struct tuntap *tt)
                        iproute_path,
                        tt->actual_name,
                        print_in_addr_t (tt->local, 0, &gc),
-                       count_netmask_bits(print_in_addr_t (tt->remote_netmask, 0, &gc))
+                       netmask_to_netbits2(tt->remote_netmask)
                        );
              }
 #else