[ovs-dev,RFC] OVN: add the possibility to configure a static IPv4 addr/IPv6 prefix and dynamic MAC
diff mbox series

Message ID 2d0f02a51e139fcc577441ff819a9db627291a67.1550683351.git.lorenzo.bianconi@redhat.com
State RFC
Headers show
Series
  • [ovs-dev,RFC] OVN: add the possibility to configure a static IPv4 addr/IPv6 prefix and dynamic MAC
Related show

Commit Message

Lorenzo Bianconi Feb. 20, 2019, 5:28 p.m. UTC
Add the possibility to configure a static IPv4 address and IPv6 prefix
and get MAC address dynamically allocated. This can be done using the
following commands:

$ovn-nbctl ls-add sw0
$ovn-nbctl set Logical-Switch sw0 other_config:subnet=192.168.0.0/24
$ovn-nbctl set Logical-switch sw0 other_config:ipv6_prefix=2001::0
$ovn-nbctl lsp-add sw0 lsp0 -- lsp-set-addresses lsp0 "dynamic 192.168.0.1 2001::1"

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
---
 ovn/lib/ovn-util.c      |  4 ++++
 ovn/northd/ovn-northd.c | 17 ++++++++++++-----
 2 files changed, 16 insertions(+), 5 deletions(-)

Comments

Ben Pfaff Feb. 22, 2019, 10:07 p.m. UTC | #1
On Wed, Feb 20, 2019 at 06:28:42PM +0100, Lorenzo Bianconi wrote:
> Add the possibility to configure a static IPv4 address and IPv6 prefix
> and get MAC address dynamically allocated. This can be done using the
> following commands:
> 
> $ovn-nbctl ls-add sw0
> $ovn-nbctl set Logical-Switch sw0 other_config:subnet=192.168.0.0/24
> $ovn-nbctl set Logical-switch sw0 other_config:ipv6_prefix=2001::0
> $ovn-nbctl lsp-add sw0 lsp0 -- lsp-set-addresses lsp0 "dynamic 192.168.0.1 2001::1"
> 
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>

I think this is OK.  It needs a documentation update and a NEWS item
though.

Patch
diff mbox series

diff --git a/ovn/lib/ovn-util.c b/ovn/lib/ovn-util.c
index aa03919bb..147f11ca0 100644
--- a/ovn/lib/ovn-util.c
+++ b/ovn/lib/ovn-util.c
@@ -80,6 +80,7 @@  add_ipv6_netaddr(struct lport_addresses *laddrs, struct in6_addr addr,
 bool
 is_dynamic_lsp_address(const char *address)
 {
+    char ipv6_s[IPV6_SCAN_LEN + 1];
     struct eth_addr ea;
     ovs_be32 ip;
     int n;
@@ -87,6 +88,9 @@  is_dynamic_lsp_address(const char *address)
             || (ovs_scan(address, "dynamic "IP_SCAN_FMT"%n",
                          IP_SCAN_ARGS(&ip), &n)
                          && address[n] == '\0')
+            || (ovs_scan(address, "dynamic "IP_SCAN_FMT" "IPV6_SCAN_FMT"%n",
+                         IP_SCAN_ARGS(&ip), ipv6_s, &n)
+                         && address[n] == '\0')
             || (ovs_scan(address, ETH_ADDR_SCAN_FMT" dynamic%n",
                          ETH_ADDR_SCAN_ARGS(ea), &n) && address[n] == '\0'));
 }
diff --git a/ovn/northd/ovn-northd.c b/ovn/northd/ovn-northd.c
index 2b7a3634e..f3d6716bf 100644
--- a/ovn/northd/ovn-northd.c
+++ b/ovn/northd/ovn-northd.c
@@ -1166,13 +1166,16 @@  dynamic_ip4_changed(const char *lsp_addrs,
          */
         return DYNAMIC;
     } else {
+        char ipv6_s[IPV6_SCAN_LEN + 1];
         ovs_be32 new_ip;
         int n = 0;
 
-        if (ovs_scan(lsp_addrs, "dynamic "IP_SCAN_FMT"%n",
+        if ((ovs_scan(lsp_addrs, "dynamic "IP_SCAN_FMT"%n",
                      IP_SCAN_ARGS(&new_ip), &n)
-            && lsp_addrs[n] == '\0') {
-
+             && lsp_addrs[n] == '\0') ||
+            (ovs_scan(lsp_addrs, "dynamic "IP_SCAN_FMT" "IPV6_SCAN_FMT"%n",
+                      IP_SCAN_ARGS(&new_ip), ipv6_s, &n)
+             && lsp_addrs[n] == '\0')) {
             index = ntohl(new_ip) - ipam->start_ipv4;
             if (ntohl(new_ip) < ipam->start_ipv4 ||
                 index > ipam->total_ipv4s ||
@@ -1278,6 +1281,7 @@  static void
 set_dynamic_updates(const char *addrspec,
                     struct dynamic_address_update *update)
 {
+    char ipv6_s[IPV6_SCAN_LEN + 1];
     struct eth_addr mac;
     ovs_be32 ip;
     int n = 0;
@@ -1290,9 +1294,12 @@  set_dynamic_updates(const char *addrspec,
         update->mac = DYNAMIC;
     }
 
-    if (ovs_scan(addrspec, "dynamic "IP_SCAN_FMT"%n",
+    if ((ovs_scan(addrspec, "dynamic "IP_SCAN_FMT"%n",
                  IP_SCAN_ARGS(&ip), &n)
-        && addrspec[n] == '\0') {
+         && addrspec[n] == '\0') ||
+        (ovs_scan(addrspec, "dynamic "IP_SCAN_FMT" "IPV6_SCAN_FMT"%n",
+                  IP_SCAN_ARGS(&ip), ipv6_s, &n)
+         && addrspec[n] == '\0')) {
         update->ipv4 = STATIC;
         update->static_ip = ip;
     } else if (update->op->od->ipam_info.allocated_ipv4s) {