]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
cleanup: avoid using ~0 - netmask
authorAlon Bar-Lev <alon.barlev@gmail.com>
Thu, 29 Mar 2012 09:16:41 +0000 (11:16 +0200)
committerDavid Sommerseth <davids@redhat.com>
Mon, 2 Apr 2012 09:54:09 +0000 (11:54 +0200)
Use IPV4_NETMASK_HOST constant.

Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Signed-off-by: David Sommerseth <davids@redhat.com>
src/openvpn/basic.h
src/openvpn/mroute.c
src/openvpn/pf.c
src/openvpn/route.c
src/openvpn/route.h
src/openvpn/tun.c

index 88539e240b950b36803f45e612cdace3c61849c6..7c13e2219ba7b3f47cc6a3f9076b2963601efef5 100644 (file)
@@ -46,4 +46,6 @@
 /* clear an object */
 #define CLEAR(x) memset(&(x), 0, sizeof(x))
 
+#define IPV4_NETMASK_HOST 0xffffffffU
+
 #endif
index 5b5357115f671481932eeabdbb2b980ad0fe42b9..aecb7027a80459acb93330c757b7d89395c59711 100644 (file)
@@ -342,7 +342,7 @@ mroute_addr_mask_host_bits (struct mroute_addr *ma)
          if ( bits_to_clear >= 8 )
            { ma->addr[byte--] = 0; bits_to_clear -= 8; }
          else
-           { ma->addr[byte--] &= (~0 << bits_to_clear); bits_to_clear = 0; }
+           { ma->addr[byte--] &= (IPV4_NETMASK_HOST << bits_to_clear); bits_to_clear = 0; }
         }
       ASSERT( bits_to_clear == 0 );
     }
index 7ed1e70880f82fcf788fca0ee9c1ad93fa4d0ade..3c468019c8a1b9dceab68f81cc52c25bb9b21e41 100644 (file)
@@ -125,7 +125,7 @@ add_subnet (const char *line, const char *prefix, const int line_num, struct pf_
     {
       /* match special "unknown" tag for addresses unrecognized by mroute */
       network.s_addr = htonl(0);
-      netmask = ~0;
+      netmask = IPV4_NETMASK_HOST;
     }
 
   {
index dda71c9c6873b551a7e199e790d97f3f7b3a0155..f681a58c97b8bcf106563433a72b7ec92a74f8cf 100644 (file)
@@ -268,7 +268,7 @@ init_route (struct route *r,
            const struct route_option *ro,
            const struct route_list *rl)
 {
-  const in_addr_t default_netmask = ~0;
+  const in_addr_t default_netmask = IPV4_NETMASK_HOST;
   bool status;
 
   CLEAR (*r);
@@ -797,7 +797,7 @@ add_bypass_routes (struct route_bypass *rb,
     {
       if (rb->bypass[i])
        add_route3 (rb->bypass[i],
-                   ~0,
+                   IPV4_NETMASK_HOST,
                    gateway,
                    tt,
                    flags | ROUTE_REF_GW,
@@ -819,7 +819,7 @@ del_bypass_routes (struct route_bypass *rb,
     {
       if (rb->bypass[i])
        del_route3 (rb->bypass[i],
-                   ~0,
+                   IPV4_NETMASK_HOST,
                    gateway,
                    tt,
                    flags | ROUTE_REF_GW,
@@ -870,7 +870,7 @@ redirect_default_route_to_vpn (struct route_list *rl, const struct tuntap *tt, u
               * adding this special /32 route */
              if (rl->spec.remote_host != IPV4_INVALID_ADDR) {
                add_route3 (rl->spec.remote_host,
-                           ~0,
+                           IPV4_NETMASK_HOST,
                            rl->rgi.gateway.addr,
                            tt,
                            flags | ROUTE_REF_GW,
@@ -944,7 +944,7 @@ undo_redirect_default_route_to_vpn (struct route_list *rl, const struct tuntap *
       if (rl->iflags & RL_DID_LOCAL)
        {
          del_route3 (rl->spec.remote_host,
-                     ~0,
+                     IPV4_NETMASK_HOST,
                      rl->rgi.gateway.addr,
                      tt,
                      flags | ROUTE_REF_GW,
@@ -3125,7 +3125,7 @@ netmask_to_netbits (const in_addr_t network, const in_addr_t netmask, int *netbi
 static void
 add_host_route_if_nonlocal (struct route_bypass *rb, const in_addr_t addr)
 {
-  if (test_local_addr(addr, NULL) == TLA_NONLOCAL && addr != 0 && addr != ~0)
+  if (test_local_addr(addr, NULL) == TLA_NONLOCAL && addr != 0 && addr != IPV4_NETMASK_HOST)
     add_bypass_address (rb, addr);
 }
 
index 25ecaeefa51d1e24c5923cbe7d9942c913d3ccd4..c0f5f574a16bcb5ac031af8e278bf31a46e0b749 100644 (file)
@@ -317,7 +317,7 @@ netbits_to_netmask (const int netbits)
   const int addrlen = sizeof (in_addr_t) * 8;
   in_addr_t mask = 0;
   if (netbits > 0 && netbits <= addrlen)
-    mask = ~0 << (addrlen-netbits);
+    mask = IPV4_NETMASK_HOST << (addrlen-netbits);
   return mask;
 }
 
index e6a7bc8083f483540c823647b3c38e76e5e18ad6..21778a20826c14ab02c900884ed6270012c945d0 100644 (file)
@@ -489,7 +489,7 @@ init_tun (const char *dev,       /* --dev option */
          if (tt->type == DEV_TYPE_TAP || (tt->type == DEV_TYPE_TUN && tt->topology == TOP_SUBNET))
            check_subnet_conflict (tt->local, tt->remote_netmask, "TUN/TAP adapter");
          else if (tt->type == DEV_TYPE_TUN)
-           check_subnet_conflict (tt->local, ~0, "TUN/TAP adapter");
+           check_subnet_conflict (tt->local, IPV4_NETMASK_HOST, "TUN/TAP adapter");
        }
 
       /*