Config: Handle multiple address or dns in config file

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Aurélien Chabot 2018-03-05 23:47:07 +11:00 committed by Jason A. Donenfeld
parent 44698bb000
commit 74eae55c87

View File

@ -90,9 +90,9 @@ public class Interface extends BaseObservable implements Parcelable {
public void parse(final String line) {
final Attribute key = Attribute.match(line);
if (key == Attribute.ADDRESS)
setAddress(key.parse(line));
addAddress(key.parse(line));
else if (key == Attribute.DNS)
setDns(key.parse(line));
addDns(key.parse(line));
else if (key == Attribute.LISTEN_PORT)
setListenPort(key.parse(line));
else if (key == Attribute.MTU)
@ -103,6 +103,13 @@ public class Interface extends BaseObservable implements Parcelable {
throw new IllegalArgumentException(line);
}
public void addAddress(String address) {
if (address != null && address.isEmpty())
address = null;
setAddress((this.address == null) ? address
: this.address + ", " + address);
}
public void setAddress(String address) {
if (address != null && address.isEmpty())
address = null;
@ -110,6 +117,13 @@ public class Interface extends BaseObservable implements Parcelable {
notifyPropertyChanged(BR.address);
}
public void addDns(String dns) {
if (dns != null && dns.isEmpty())
dns = null;
setDns((this.dns == null) ? dns
: this.dns + ", " + dns);
}
public void setDns(String dns) {
if (dns != null && dns.isEmpty())
dns = null;