@@ -589,6 +589,45 @@ ip46_equals(const struct v46_ip *addr1, const struct v46_ip *addr2)
IN6_ARE_ADDR_EQUAL(&addr1->ipv6, &addr2->ipv6)));
}
+/* The caller must free the returned string. */
+char *
+normalize_ipv4_prefix(ovs_be32 ipv4, unsigned int plen)
+{
+ ovs_be32 network = ipv4 & be32_prefix_mask(plen);
+ if (plen == 32) {
+ return xasprintf(IP_FMT, IP_ARGS(network));
+ } else {
+ return xasprintf(IP_FMT "/%d", IP_ARGS(network), plen);
+ }
+}
+
+/* The caller must free the returned string. */
+char *
+normalize_ipv6_prefix(struct in6_addr ipv6, unsigned int plen)
+{
+ char network_s[INET6_ADDRSTRLEN];
+
+ struct in6_addr mask = ipv6_create_mask(plen);
+ struct in6_addr network = ipv6_addr_bitand(&ipv6, &mask);
+
+ inet_ntop(AF_INET6, &network, network_s, INET6_ADDRSTRLEN);
+ if (plen == 128) {
+ return xasprintf("%s", network_s);
+ } else {
+ return xasprintf("%s/%d", network_s, plen);
+ }
+}
+
+char *
+normalize_v46_prefix(const struct v46_ip *prefix, unsigned int plen)
+{
+ if (prefix->family == AF_INET) {
+ return normalize_ipv4_prefix(prefix->ipv4, plen);
+ } else {
+ return normalize_ipv6_prefix(prefix->ipv6, plen);
+ }
+}
+
char *
str_tolower(const char *orig)
{
@@ -144,6 +144,10 @@ bool ip46_parse_cidr(const char *str, struct v46_ip *prefix,
unsigned int *plen);
bool ip46_equals(const struct v46_ip *addr1, const struct v46_ip *addr2);
+char *normalize_ipv4_prefix(ovs_be32 ipv4, unsigned int plen);
+char *normalize_ipv6_prefix(struct in6_addr ipv6, unsigned int plen);
+char *normalize_v46_prefix(const struct v46_ip *prefix, unsigned int plen);
+
/* Returns a lowercase copy of orig.
* Caller must free the returned string.
*/
@@ -3482,35 +3482,6 @@ nbctl_dhcp_options_list(struct ctl_context *ctx)
free(nodes);
}
-/* The caller must free the returned string. */
-static char *
-normalize_ipv4_prefix(ovs_be32 ipv4, unsigned int plen)
-{
- ovs_be32 network = ipv4 & be32_prefix_mask(plen);
- if (plen == 32) {
- return xasprintf(IP_FMT, IP_ARGS(network));
- } else {
- return xasprintf(IP_FMT"/%d", IP_ARGS(network), plen);
- }
-}
-
-/* The caller must free the returned string. */
-static char *
-normalize_ipv6_prefix(struct in6_addr ipv6, unsigned int plen)
-{
- char network_s[INET6_ADDRSTRLEN];
-
- struct in6_addr mask = ipv6_create_mask(plen);
- struct in6_addr network = ipv6_addr_bitand(&ipv6, &mask);
-
- inet_ntop(AF_INET6, &network, network_s, INET6_ADDRSTRLEN);
- if (plen == 128) {
- return xasprintf("%s", network_s);
- } else {
- return xasprintf("%s/%d", network_s, plen);
- }
-}
-
static char *
normalize_ipv4_prefix_str(const char *orig_prefix)
{
This moves a couple of existing IP address normalization routines from ovn-nbctl.c to ovn-util.c. It also adds a new normalization function for a v46_address. This new function is not used in this commit but will be used in a future commit in this series. Signed-off-by: Mark Michelson <mmichels@redhat.com> --- lib/ovn-util.c | 39 +++++++++++++++++++++++++++++++++++++++ lib/ovn-util.h | 4 ++++ utilities/ovn-nbctl.c | 29 ----------------------------- 3 files changed, 43 insertions(+), 29 deletions(-)