[ovs-dev] [PATCH ovn 1/2] ovn-northd.c: Move struct v46_ip and related functions to utils.
Numan Siddique
numans at ovn.org
Fri Feb 14 11:02:34 UTC 2020
On Mon, Feb 10, 2020 at 12:31 PM Han Zhou <hzhou at ovn.org> wrote:
>
> The struct and functions will be reused by other modules.
>
> Signed-off-by: Han Zhou <hzhou at ovn.org>
Acked-by: Numan Siddique <numans at ovn.org>
Thanks
Numan
> ---
> lib/ovn-util.c | 28 ++++++++++++++++++++++++++++
> lib/ovn-util.h | 12 ++++++++++++
> northd/ovn-northd.c | 37 -------------------------------------
> 3 files changed, 40 insertions(+), 37 deletions(-)
>
> diff --git a/lib/ovn-util.c b/lib/ovn-util.c
> index ba643c5..df18fda 100644
> --- a/lib/ovn-util.c
> +++ b/lib/ovn-util.c
> @@ -521,3 +521,31 @@ ovn_chassis_redirect_name(const char *port_name)
> {
> return xasprintf("cr-%s", port_name);
> }
> +
> +bool
> +ip46_parse_cidr(const char *str, struct v46_ip *prefix, unsigned int *plen)
> +{
> + memset(prefix, 0, sizeof *prefix);
> +
> + char *error = ip_parse_cidr(str, &prefix->ipv4, plen);
> + if (!error) {
> + prefix->family = AF_INET;
> + return true;
> + }
> + free(error);
> + error = ipv6_parse_cidr(str, &prefix->ipv6, plen);
> + if (!error) {
> + prefix->family = AF_INET6;
> + return true;
> + }
> + free(error);
> + return false;
> +}
> +
> +bool
> +ip46_equals(const struct v46_ip *addr1, const struct v46_ip *addr2)
> +{
> + return (addr1->family == addr2->family &&
> + (addr1->family == AF_INET ? addr1->ipv4 == addr2->ipv4 :
> + IN6_ARE_ADDR_EQUAL(&addr1->ipv6, &addr2->ipv6)));
> +}
> diff --git a/lib/ovn-util.h b/lib/ovn-util.h
> index d0a2645..4ece077 100644
> --- a/lib/ovn-util.h
> +++ b/lib/ovn-util.h
> @@ -105,4 +105,16 @@ uint32_t ovn_allocate_tnlid(struct hmap *set, const char *name, uint32_t min,
> uint32_t max, uint32_t *hint);
>
> char *ovn_chassis_redirect_name(const char *port_name);
> +
> +/* An IPv4 or IPv6 address */
> +struct v46_ip {
> + int family;
> + union {
> + ovs_be32 ipv4;
> + struct in6_addr ipv6;
> + };
> +};
> +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);
> #endif
> diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
> index 815c727..8a4e63c 100644
> --- a/northd/ovn-northd.c
> +++ b/northd/ovn-northd.c
> @@ -72,15 +72,6 @@ struct northd_state {
> bool paused;
> };
>
> -/* An IPv4 or IPv6 address */
> -struct v46_ip {
> - int family;
> - union {
> - ovs_be32 ipv4;
> - struct in6_addr ipv6;
> - };
> -};
> -
> static const char *ovnnb_db;
> static const char *ovnsb_db;
> static const char *unixctl_path;
> @@ -6927,34 +6918,6 @@ build_routing_policy_flow(struct hmap *lflows, struct ovn_datapath *od,
> ds_destroy(&actions);
> }
>
> -static bool
> -ip46_parse_cidr(const char *str, struct v46_ip *prefix, unsigned int *plen)
> -{
> - memset(prefix, 0, sizeof *prefix);
> -
> - char *error = ip_parse_cidr(str, &prefix->ipv4, plen);
> - if (!error) {
> - prefix->family = AF_INET;
> - return true;
> - }
> - free(error);
> - error = ipv6_parse_cidr(str, &prefix->ipv6, plen);
> - if (!error) {
> - prefix->family = AF_INET6;
> - return true;
> - }
> - free(error);
> - return false;
> -}
> -
> -static bool
> -ip46_equals(const struct v46_ip *addr1, const struct v46_ip *addr2)
> -{
> - return (addr1->family == addr2->family &&
> - (addr1->family == AF_INET ? addr1->ipv4 == addr2->ipv4 :
> - IN6_ARE_ADDR_EQUAL(&addr1->ipv6, &addr2->ipv6)));
> -}
> -
> struct parsed_route {
> struct ovs_list list_node;
> struct v46_ip prefix;
> --
> 2.1.0
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>
More information about the dev
mailing list