extern u32 ip_set_range_to_cidr(u32 from, u32 to, u8 *cidr);
 
+#define ip_set_mask_from_to(from, to, cidr)    \
+do {                                           \
+       from &= ip_set_hostmask(cidr);          \
+       to = from | ~ip_set_hostmask(cidr);     \
+} while (0)
+
 #endif /*_PFXLEN_H */
 
 
                if (cidr > 32)
                        return -IPSET_ERR_INVALID_CIDR;
-               ip &= ip_set_hostmask(cidr);
-               ip_to = ip | ~ip_set_hostmask(cidr);
+               ip_set_mask_from_to(ip, ip_to, cidr);
        } else
                ip_to = ip;
 
 
                if (cidr >= 32)
                        return -IPSET_ERR_INVALID_CIDR;
-               first_ip &= ip_set_hostmask(cidr);
-               last_ip = first_ip | ~ip_set_hostmask(cidr);
+               ip_set_mask_from_to(first_ip, last_ip, cidr);
        } else
                return -IPSET_ERR_PROTOCOL;
 
 
 
                if (cidr >= 32)
                        return -IPSET_ERR_INVALID_CIDR;
-               last_ip = first_ip | ~ip_set_hostmask(cidr);
+               ip_set_mask_from_to(first_ip, last_ip, cidr);
        } else
                return -IPSET_ERR_PROTOCOL;
 
 
 
                if (cidr > 32)
                        return -IPSET_ERR_INVALID_CIDR;
-               ip &= ip_set_hostmask(cidr);
-               ip_to = ip | ~ip_set_hostmask(cidr);
+               ip_set_mask_from_to(ip, ip_to, cidr);
        } else
                ip_to = ip;
 
 
 
                if (cidr > 32)
                        return -IPSET_ERR_INVALID_CIDR;
-               ip &= ip_set_hostmask(cidr);
-               ip_to = ip | ~ip_set_hostmask(cidr);
+               ip_set_mask_from_to(ip, ip_to, cidr);
        } else
                ip_to = ip;
 
 
 
                if (cidr > 32)
                        return -IPSET_ERR_INVALID_CIDR;
-               ip &= ip_set_hostmask(cidr);
-               ip_to = ip | ~ip_set_hostmask(cidr);
+               ip_set_mask_from_to(ip, ip_to, cidr);
        } else
                ip_to = ip;
 
 
 
                if (cidr > 32)
                        return -IPSET_ERR_INVALID_CIDR;
-               ip &= ip_set_hostmask(cidr);
-               ip_to = ip | ~ip_set_hostmask(cidr);
+               ip_set_mask_from_to(ip, ip_to, cidr);
        }
 
        port_to = port = ntohs(data.port);
                if (ip2_from + UINT_MAX == ip2_to)
                        return -IPSET_ERR_HASH_RANGE;
        } else {
-               ip2_from &= ip_set_hostmask(data.cidr);
-               ip2_to = ip2_from | ~ip_set_hostmask(data.cidr);
+               ip_set_mask_from_to(ip2_from, ip2_to, data.cidr);
        }
 
        if (retried)
 
                if (ip + UINT_MAX == ip_to)
                        return -IPSET_ERR_HASH_RANGE;
        } else {
-               ip &= ip_set_hostmask(data.cidr);
-               ip_to = ip | ~ip_set_hostmask(data.cidr);
+               ip_set_mask_from_to(ip, ip_to, data.cidr);
        }
 
        if (retried)