From 390f88e5cbdbe4125548b4845fac6559e730a16c Mon Sep 17 00:00:00 2001
From: Matthieu Imbert <matthieu.imbert@inria.fr>
Date: Thu, 9 Apr 2020 15:29:12 +0200
Subject: [PATCH] [gen] shorten ipv6 format when possible

---
 lib/refrepo/input_loader.rb | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/lib/refrepo/input_loader.rb b/lib/refrepo/input_loader.rb
index c2bb8c33ded..840d5a3ca60 100644
--- a/lib/refrepo/input_loader.rb
+++ b/lib/refrepo/input_loader.rb
@@ -124,8 +124,12 @@ def add_ipv6(h)
             ip6 = '2001:660:4406:'
             ip6 += '%x' % h['ipv6']['site-indexes'][site_uid]
             ip6 += '00:'
-            ip6 += '%x:' % ((ip4.split('.')[2].to_i & 0b1111) + 1)
-            ip6 += '%x::' % idx
+            ip6 += '%x' % ((ip4.split('.')[2].to_i & 0b1111) + 1)
+            if idx > 0
+              ip6 += ':%x::' % idx
+            else
+              ip6 += '::'
+            end
             ip6 += '%x' % (ip4.split('.')[3].to_i)
             nah['ip6'] = ip6
           end
@@ -157,8 +161,12 @@ def add_kavlan_ipv6s(h)
               ip6 = '2001:660:4406:'
               ip6 += '%x' % h['ipv6']['site-indexes'][site_uid]
               ip6 += '%x:' % (kvl_id + 0x80)
-              ip6 += '%x:' % ((ip4.split('.')[2].to_i & 0b1111) + 1)
-              ip6 += '%x::' % idx
+              ip6 += '%x' % ((ip4.split('.')[2].to_i & 0b1111) + 1)
+              if idx > 0
+                ip6 += ':%x::' % idx
+              else
+                ip6 += '::'
+              end
               ip6 += '%x' % (ip4.split('.')[3].to_i)
               hn['kavlan6'][iface][kvl_id] = ip6
             end
-- 
GitLab