From 4e3703660e5cc805bfd9decb4f11205f237548be Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Fri, 1 Apr 2016 00:22:18 +0200 Subject: [PATCH] MT#16239 Avoid duplicate IP records (shared_ip/shared_v6ip/advertised_ip) Configuring the identical shared IP once again shouldn't cause duplicate IP records, since e.g. nginx receives two "listen" lines with the same IP and fails hard then. New behaviour with this change is to avoid duplicates: | root@spce:~# ngcp-network --verbose --set-interface=eth0 --shared-ip=1.2.3.4 | [...] | adding IP entry shared_ip: 1.2.3.4 | [...] | root@spce:~# ngcp-network --verbose --set-interface=eth0 --shared-ip=1.2.3.4 | [...] | not setting shared_ip to 1.2.3.4 to avoid duplicates | [...] Change-Id: Iee3ff1e7a27bc3298128835468e1e888c327d13d --- sbin/ngcp-network | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sbin/ngcp-network b/sbin/ngcp-network index cf9e2a57..3868b077 100755 --- a/sbin/ngcp-network +++ b/sbin/ngcp-network @@ -267,11 +267,16 @@ sub set_interface { delete $yaml->[0]->{hosts}->{$host}->{$iface}->{$k}; } else { - logger("$k: $settings->{$k}"); if($k eq 'shared_ip' || $k eq 'shared_v6ip' || $k eq 'advertised_ip') { - push @{ $yaml->[0]->{hosts}->{$host}->{$iface}->{$k} }, $settings->{$k}; + if (my ($matched) = grep { $_ eq $settings->{$k} } @{ $yaml->[0]->{hosts}->{$host}->{$iface}->{$k} }) { + logger("not setting $k to $matched to avoid duplicates"); + } else { + logger("adding IP entry $k: $settings->{$k}"); + push @{ $yaml->[0]->{hosts}->{$host}->{$iface}->{$k} }, $settings->{$k} + } } else { + logger("adding entry $k: $settings->{$k}"); $yaml->[0]->{hosts}->{$host}->{$iface}->{$k} = $settings->{$k}; } }