diff options
author | nickcooper-zhangtonghao <nickcooper-zhangtonghao@opencloud.tech> | 2016-10-03 01:57:37 -0700 |
---|---|---|
committer | Gurucharan Shetty <guru@ovn.org> | 2016-10-03 14:11:40 -0700 |
commit | e2bfcad6cbb0e7f47e91f68b14307d213d11823a (patch) | |
tree | 53e825721909614bb7324a4c5649d4303f1e734a /lib | |
parent | ab187e7e309874d46fdcdb9f539fb0387988600c (diff) | |
download | openvswitch-e2bfcad6cbb0e7f47e91f68b14307d213d11823a.tar.gz |
ovn-nbctl: Add LB commands.
This patch provides the command line to create a load balancer.
You can create a load balancer independently and add it to multiple
switches or routers. A single load balancer can have multiple vips.
Add a name column for the load balancer. With --add-duplicate,
the command really creates a new load balancer with a duplicate name.
This name has no special meaning or purpose other than to provide
convenience for human interaction with the ovn-nb database.
This patch also provides the unit tests and the documentation.
Signed-off-by: nickcooper-zhangtonghao <nickcooper-zhangtonghao@opencloud.tech>
Signed-off-by: Gurucharan Shetty <guru@ovn.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/packets.c | 18 | ||||
-rw-r--r-- | lib/packets.h | 10 |
2 files changed, 28 insertions, 0 deletions
diff --git a/lib/packets.c b/lib/packets.c index e4c29d509..11bb587e5 100644 --- a/lib/packets.c +++ b/lib/packets.c @@ -427,6 +427,24 @@ ip_parse(const char *s, ovs_be32 *ip) return inet_pton(AF_INET, s, ip) == 1; } +/* Parses string 's', which must be an IP address with a port number + * with ":" as a separator (e.g.: 192.168.1.2:80). + * Stores the IP address into '*ip' and port number to '*port'. */ +char * OVS_WARN_UNUSED_RESULT +ip_parse_port(const char *s, ovs_be32 *ip, ovs_be16 *port) +{ + int n = 0; + if (!ovs_scan_len(s, &n, IP_PORT_SCAN_FMT, + IP_PORT_SCAN_ARGS(ip, port))) { + return xasprintf("%s: invalid IP address or port number", s); + } + + if (s[n]) { + return xasprintf("%s: invalid IP address or port number", s); + } + return NULL; +} + /* Parses string 's', which must be an IP address with an optional netmask or * CIDR prefix length. Stores the IP address into '*ip', netmask into '*mask', * (255.255.255.255, if 's' lacks a netmask), and number of scanned characters diff --git a/lib/packets.h b/lib/packets.h index dcfcd04b2..21bd35c09 100644 --- a/lib/packets.h +++ b/lib/packets.h @@ -537,6 +537,14 @@ mpls_lse_to_bos(ovs_be32 mpls_lse) &((uint8_t *) ip)[2], \ &((uint8_t *) ip)[3] +#define IP_PORT_SCAN_FMT "%"SCNu8".%"SCNu8".%"SCNu8".%"SCNu8":%"SCNu16 +#define IP_PORT_SCAN_ARGS(ip, port) \ + ((void) (ovs_be32) *(ip), &((uint8_t *) ip)[0]), \ + &((uint8_t *) ip)[1], \ + &((uint8_t *) ip)[2], \ + &((uint8_t *) ip)[3], \ + ((void) (ovs_be16) *(port), (uint16_t *) port) + /* Returns true if 'netmask' is a CIDR netmask, that is, if it consists of N * high-order 1-bits and 32-N low-order 0-bits. */ static inline bool @@ -558,6 +566,8 @@ ip_is_local_multicast(ovs_be32 ip) int ip_count_cidr_bits(ovs_be32 netmask); void ip_format_masked(ovs_be32 ip, ovs_be32 mask, struct ds *); bool ip_parse(const char *s, ovs_be32 *ip); +char *ip_parse_port(const char *s, ovs_be32 *ip, ovs_be16 *port) + OVS_WARN_UNUSED_RESULT; char *ip_parse_masked(const char *s, ovs_be32 *ip, ovs_be32 *mask) OVS_WARN_UNUSED_RESULT; char *ip_parse_cidr(const char *s, ovs_be32 *ip, unsigned int *plen) |