+/* Given the IP netmask 'netmask', returns the number of bits of the IP address
+ * that it specifies, that is, the number of 1-bits in 'netmask'. 'netmask'
+ * must be a CIDR netmask (see ip_is_cidr()). */
+int
+ip_count_cidr_bits(ovs_be32 netmask)
+{
+ assert(ip_is_cidr(netmask));
+ return 32 - ctz(ntohl(netmask));
+}
+
+void
+ip_format_masked(ovs_be32 ip, ovs_be32 mask, struct ds *s)
+{
+ ds_put_format(s, IP_FMT, IP_ARGS(&ip));
+ if (mask != htonl(UINT32_MAX)) {
+ if (ip_is_cidr(mask)) {
+ ds_put_format(s, "/%d", ip_count_cidr_bits(mask));
+ } else {
+ ds_put_format(s, "/"IP_FMT, IP_ARGS(&mask));
+ }
+ }
+}
+
+