tools/hotplug: Fixes to vif-nat
cover tools/hotplug: Fixes to vif-nat
This patch series fixes issues around the vif-nat script when setting up the vif interface and dhcp server in dom0.
It has been validated and used in Yocto and meta-arm-autonomy
Diego Sueiro (3):
tools/hotplug: Fix hostname setting in vif-nat tools/hotplug: Fix dhcpd symlink removal in vif-nat tools/hotplug: Extend dhcpd conf, init and arg files search
tools/hotplug/Linux/vif-nat | 14 ++++++++------ tools/hotplug/Linux/xen-network-common.sh | 6 +++--- 2 files changed, 11 insertions(+), 9 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/3 tools/hotplug: Fix hostname setting in vif-nat
Setting the hostname is failing because the "$XENBUS_PATH/domain" doesn't exist anymore. To fix this we set it to dom$domid
--- tools/hotplug/Linux/vif-nat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/hotplug/Linux/vif-nat +1 -1
@@ -85,7 +85,7 @@ router_ip=$(routing_ip "$ip") # Split the given IP/bits pair. vif_ip=`echo ${ip} | awk -F/ '{print $1}'` -hostname=$(xenstore_read "$XENBUS_PATH/domain" | tr -- '_.:/+' '-----') +hostname=dom$domid if [ "$vifid" != "1" ] then hostname="$hostname-$vifid"
Signature · 1 line
2.7.4
Re: [PATCH 1/3] tools/hotplug: Fix hostname setting in vif-nat
Quoted 8 lines · Diego Sueiro
Setting the hostname is failing because the "$XENBUS_PATH/domain" doesn't exist anymore. To fix this we set it to dom$domid
Signed-off-by Diego Sueiro <[email protected]>
Quoted 21 lines
---
tools/hotplug/Linux/vif-nat| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)tools/hotplug/Linux/vif-nat +0
-0@@ -85,7 +85,7 @@ router_ip=$(routing_ip "$ip") # Split the given IP/bits pair.vif_ip=
echo ${ip} | awk -F/ '{print $1}'tools/hotplug/Linux/vif-nat +1
-1-hostname=$(xenstore_read "$XENBUS_PATH/domain" | tr -- '_.:/+' '-----') +hostname=dom$domidif [ "$vifid" != "1" ]
then
hostname="$hostname-$vifid"Signature · 1 line
2.7.4
Wei Liu
Acked-byRe: [PATCH 1/3] tools/hotplug: Fix hostname setting in vif-nat
Quoted 10 lines · Bertrand Marquis
Quoted 8 lines · Diego Sueiro
Setting the hostname is failing because the "$XENBUS_PATH/domain" doesn't exist anymore. To fix this we set it to dom$domid
Signed-off-by Diego Sueiro <[email protected]>Reviewed-by Bertrand Marquis <[email protected]>
PATCH 2/3 tools/hotplug: Fix dhcpd symlink removal in vif-nat
In reply to Diego SueiroCopy temp files used to add/remove dhcpd configurations to avoid replacing potential symlinks.
--- tools/hotplug/Linux/vif-nat | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
tools/hotplug/Linux/vif-nat +7 -5
@@ -99,7 +99,8 @@ dhcparg_remove_entry() then rm "$tmpfile" else - mv "$tmpfile" "$dhcpd_arg_file" + cp "$tmpfile" "$dhcpd_arg_file" + rm "$tmpfile" fi }
@@ -109,11 +110,11 @@ dhcparg_add_entry() local tmpfile=$(mktemp) # handle Red Hat, SUSE, and Debian styles, with or without quotes sed -e 's/^DHCPDARGS="*\([^"]*\)"*/DHCPDARGS="\1'"${dev} "'"/' \ - "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file" + "$dhcpd_arg_file" >"$tmpfile" && cp "$tmpfile" "$dhcpd_arg_file" sed -e 's/^DHCPD_INTERFACE="*\([^"]*\)"*/DHCPD_INTERFACE="\1'"${dev} "'"/' \ - "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file" + "$dhcpd_arg_file" >"$tmpfile" && cp "$tmpfile" "$dhcpd_arg_file" sed -e 's/^INTERFACES="*\([^"]*\)"*/INTERFACES="\1'"${dev} "'"/' \ - "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file" + "$dhcpd_arg_file" >"$tmpfile" && cp "$tmpfile" "$dhcpd_arg_file" rm -f "$tmpfile" }
@@ -125,7 +126,8 @@ dhcp_remove_entry() then rm "$tmpfile" else - mv "$tmpfile" "$dhcpd_conf_file" + cp "$tmpfile" "$dhcpd_conf_file" + rm "$tmpfile" fi dhcparg_remove_entry }
Signature · 1 line
2.7.4
Re: [PATCH 2/3] tools/hotplug: Fix dhcpd symlink removal in vif-nat
Quoted 8 lines · Diego Sueiro
Copy temp files used to add/remove dhcpd configurations to avoid replacing potential symlinks.
Signed-off-by Diego Sueiro <[email protected]>
Quoted 47 lines
---
tools/hotplug/Linux/vif-nat| 12 +++++++-----1 file changed, 7 insertions(+), 5 deletions(-)tools/hotplug/Linux/vif-nat +7
-5@@ -99,7 +99,8 @@ dhcparg_remove_entry() then rm "$tmpfile" else - mv "$tmpfile" "$dhcpd_arg_file" + cp "$tmpfile" "$dhcpd_arg_file" + rm "$tmpfile" fi }@@ -109,11 +110,11 @@ dhcparg_add_entry() local tmpfile=$(mktemp) # handle Red Hat, SUSE, and Debian styles, with or without quotes sed -e 's/^DHCPDARGS="*\([^"]*\)"*/DHCPDARGS="\1'"${dev} "'"/' \ - "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file" + "$dhcpd_arg_file" >"$tmpfile" && cp "$tmpfile" "$dhcpd_arg_file" sed -e 's/^DHCPD_INTERFACE="*\([^"]*\)"*/DHCPD_INTERFACE="\1'"${dev} "'"/' \ - "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file" + "$dhcpd_arg_file" >"$tmpfile" && cp "$tmpfile" "$dhcpd_arg_file" sed -e 's/^INTERFACES="*\([^"]*\)"*/INTERFACES="\1'"${dev} "'"/' \ - "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file" + "$dhcpd_arg_file" >"$tmpfile" && cp "$tmpfile" "$dhcpd_arg_file" rm -f "$tmpfile" }@@ -125,7 +126,8 @@ dhcp_remove_entry() then rm "$tmpfile" else - mv "$tmpfile" "$dhcpd_conf_file" + cp "$tmpfile" "$dhcpd_conf_file" + rm "$tmpfile" fi dhcparg_remove_entry }Signature · 1 line
2.7.4
Re: [PATCH 2/3] tools/hotplug: Fix dhcpd symlink removal in vif-nat
In reply to Diego SueiroQuoted 3 lines · Diego Sueiro
Copy temp files used to add/remove dhcpd configurations to avoid replacing potential symlinks.
Can you clarify the issue you saw a bit?
Which one of the parameter is a symlink (I assume the latter) and what problem you see with replacing the symlinks?
Quoted 10 lines
Signed-off-by Diego Sueiro <[email protected]>--- tools/hotplug/Linux/vif-nat | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)tools/hotplug/Linux/vif-nat +0
-0
tools/hotplug/Linux/vif-nat dhcparg_remove_entry() · line 104
Quoted 7 lines
tools/hotplug/Linux/vif-nat +2
-1@@ -99,7 +99,8 @@ dhcparg_remove_entry() then rm "$tmpfile" else - mv "$tmpfile" "$dhcpd_arg_file" + cp "$tmpfile" "$dhcpd_arg_file" + rm "$tmpfile" fi
You could've simplified the code a bit here and below now that both branches issue the same rm command.
But don't resend just yet. Please help me understand your issue first.
Wei.
Quoted 30 lines
tools/hotplug/Linux/vif-nat +5
-4}@@ -109,11 +110,11 @@ dhcparg_add_entry() local tmpfile=$(mktemp) # handle Red Hat, SUSE, and Debian styles, with or without quotes sed -e 's/^DHCPDARGS="*\([^"]*\)"*/DHCPDARGS="\1'"${dev} "'"/' \ - "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file" + "$dhcpd_arg_file" >"$tmpfile" && cp "$tmpfile" "$dhcpd_arg_file" sed -e 's/^DHCPD_INTERFACE="*\([^"]*\)"*/DHCPD_INTERFACE="\1'"${dev} "'"/' \ - "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file" + "$dhcpd_arg_file" >"$tmpfile" && cp "$tmpfile" "$dhcpd_arg_file" sed -e 's/^INTERFACES="*\([^"]*\)"*/INTERFACES="\1'"${dev} "'"/' \ - "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file" + "$dhcpd_arg_file" >"$tmpfile" && cp "$tmpfile" "$dhcpd_arg_file" rm -f "$tmpfile" }@@ -125,7 +126,8 @@ dhcp_remove_entry() then rm "$tmpfile" else - mv "$tmpfile" "$dhcpd_conf_file" + cp "$tmpfile" "$dhcpd_conf_file" + rm "$tmpfile" fi dhcparg_remove_entry }Signature · 1 line
2.7.4
Re: [PATCH 2/3] tools/hotplug: Fix dhcpd symlink removal in vif-nat
Hi Wei,
Quoted 11 lines · Wei Liu
Quoted 3 lines · Diego Sueiro
Copy temp files used to add/remove dhcpd configurations to avoid replacing potential symlinks.
Can you clarify the issue you saw a bit?
Which one of the parameter is a symlink (I assume the latter) and what problem you see with replacing the symlinks?
Maybe i can explain here.
If you have this:/etc/dhcp.conf -> dhcp.conf.real
mv will create a new file dhcp.conf where cp will actually modify dhcp.conf.real instead of replacing the symlink with a real file.
This prevents some mistakes where the user will actually continue to modify dhcp.conf.real where it would not be the one used anymore.
Bertrand
Quoted 55 lines
Quoted 11 lines
Signed-off-by Diego Sueiro <[email protected]>---
tools/hotplug/Linux/vif-nat| 12 +++++++-----1 file changed, 7 insertions(+), 5 deletions(-)tools/hotplug/Linux/vif-nat +0
-0tools/hotplug/Linux/vif-nat dhcparg_remove_entry() · line 104
Quoted 7 lines
tools/hotplug/Linux/vif-nat +2
-1@@ -99,7 +99,8 @@ dhcparg_remove_entry() then rm "$tmpfile" else - mv "$tmpfile" "$dhcpd_arg_file" + cp "$tmpfile" "$dhcpd_arg_file" + rm "$tmpfile" fiYou could've simplified the code a bit here and below now that both branches issue the same rm command.
But don't resend just yet. Please help me understand your issue first.
Wei.
Quoted 29 lines
tools/hotplug/Linux/vif-nat +5
-4}@@ -109,11 +110,11 @@ dhcparg_add_entry() local tmpfile=$(mktemp) # handle Red Hat, SUSE, and Debian styles, with or without quotes sed -e 's/^DHCPDARGS="*\([^"]*\)"*/DHCPDARGS="\1'"${dev} "'"/' \ - "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file" + "$dhcpd_arg_file" >"$tmpfile" && cp "$tmpfile" "$dhcpd_arg_file" sed -e 's/^DHCPD_INTERFACE="*\([^"]*\)"*/DHCPD_INTERFACE="\1'"${dev} "'"/' \ - "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file" + "$dhcpd_arg_file" >"$tmpfile" && cp "$tmpfile" "$dhcpd_arg_file" sed -e 's/^INTERFACES="*\([^"]*\)"*/INTERFACES="\1'"${dev} "'"/' \ - "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file" + "$dhcpd_arg_file" >"$tmpfile" && cp "$tmpfile" "$dhcpd_arg_file" rm -f "$tmpfile" }@@ -125,7 +126,8 @@ dhcp_remove_entry() then rm "$tmpfile" else - mv "$tmpfile" "$dhcpd_conf_file" + cp "$tmpfile" "$dhcpd_conf_file" + rm "$tmpfile" fi dhcparg_remove_entry }Signature · 1 line
2.7.4
Re: [PATCH 2/3] tools/hotplug: Fix dhcpd symlink removal in vif-nat
Quoted 16 lines · Bertrand Marquis
Hi Wei,
Quoted 11 lines · Wei Liu
Quoted 3 lines · Diego Sueiro
Copy temp files used to add/remove dhcpd configurations to avoid replacing potential symlinks.
Can you clarify the issue you saw a bit?
Which one of the parameter is a symlink (I assume the latter) and what problem you see with replacing the symlinks?
Maybe i can explain here.
Quoted 8 lines
If you have this:
/etc/dhcp.conf-> dhcp.conf.realmv will create a new file dhcp.conf where cp will actually modify dhcp.conf.real instead of replacing the symlink with a real file.
This prevents some mistakes where the user will actually continue to modify dhcp.conf.real where it would not be the one used anymore.
OK. Now I understand the use case. Thanks.
I think you explanation should be part of the commit message.
Diego, can you please incorporate Bertrand's explanation and deal with my comment below?
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
---
tools/hotplug/Linux/vif-nat| 12 +++++++-----1 file changed, 7 insertions(+), 5 deletions(-)
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
tools/hotplug/Linux/vif-nat +0
-0@@ -99,7 +99,8 @@ dhcparg_remove_entry() then rm "$tmpfile"Quoted 8 lines
tools/hotplug/Linux/vif-nat dhcparg_remove_entry() · line 104
Quoted 5 lines
tools/hotplug/Linux/vif-nat +2
-1else - mv "$tmpfile" "$dhcpd_arg_file" + cp "$tmpfile" "$dhcpd_arg_file" + rm "$tmpfile" fiYou could've simplified the code a bit here and below now that both branches issue the same rm command.
Wei.
RE: [PATCH 2/3] tools/hotplug: Fix dhcpd symlink removal in vif-nat
Quoted 35 lines
-----Original Message-----
From: Wei Liu <[email protected]>
Sent: 07 September 2020 16:10
To: Bertrand Marquis <[email protected]>
Cc: Wei Liu <[email protected]>; Diego Sueiro <[email protected]>; xen- [email protected]; nd <[email protected]>; Ian Jackson <[email protected]>
Subject: Re: [PATCH 2/3]tools/hotplug: Fix dhcpd symlink removal in vif-natQuoted 16 lines · Bertrand Marquis
Hi Wei,
Quoted 11 lines · Wei Liu
Quoted 3 lines · Diego Sueiro
Copy temp files used to add/remove dhcpd configurations to avoid replacing potential symlinks.
Can you clarify the issue you saw a bit?
Which one of the parameter is a symlink (I assume the latter) and what problem you see with replacing the symlinks?
Maybe i can explain here.
Quoted 8 lines
If you have this:
/etc/dhcp.conf-> dhcp.conf.realmv will create a new file dhcp.conf where cp will actually modify dhcp.conf.real instead of replacing the symlink with a real file.
This prevents some mistakes where the user will actually continue to modify dhcp.conf.real where it would not be the one used anymore.
Quoted 7 lines
OK. Now I understand the use case. Thanks.
I think you explanation should be part of the commit message.
Diego, can you please incorporate Bertrand's explanation and deal with my comment below?
Done and v2 sent to the mailing list. Thanks for your review.
--
Diego Sueiro
Quoted 21 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
---
tools/hotplug/Linux/vif-nat| 12 +++++++-----1 file changed, 7 insertions(+), 5 deletions(-)Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
(quoted diff) +0
-0b/tools/hotplug/Linux/vif-nat index 2614435..1ab80ed 100644
tools/hotplug/Linux/vif-nat +0
-0@@ -99,7 +99,8 @@ dhcparg_remove_entry() then rm "$tmpfile"Quoted 8 lines
tools/hotplug/Linux/vif-nat dhcparg_remove_entry() · line 104
Quoted 5 lines
tools/hotplug/Linux/vif-nat +2
-1else - mv "$tmpfile" "$dhcpd_arg_file" + cp "$tmpfile" "$dhcpd_arg_file" + rm "$tmpfile" fiYou could've simplified the code a bit here and below now that both branches issue the same rm command.
Wei.
PATCH 3/3 tools/hotplug: Extend dhcpd conf, init and arg files search
In reply to Diego SueiroNewer versions of the ISC dhcp server expect the dhcpd.conf file to be located at /etc/dhcp directory.
Also, some distributions and Yocto based ones have these installation paths by default: /etc/init.d/{isc-dhcp-server,dhcp-server} and /etc/default/dhcp-server.
--- tools/hotplug/Linux/xen-network-common.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/hotplug/Linux/xen-network-common.sh +3 -3
@@ -64,18 +64,18 @@ first_file() find_dhcpd_conf_file() { - first_file -f /etc/dhcp3/dhcpd.conf /etc/dhcpd.conf + first_file -f /etc/dhcp/dhcpd.conf /etc/dhcp3/dhcpd.conf /etc/dhcpd.conf } find_dhcpd_init_file() { - first_file -x /etc/init.d/{dhcp3-server,dhcp,dhcpd} + first_file -x /etc/init.d/{isc-dhcp-server,dhcp-server,dhcp3-server,dhcp,dhcpd} } find_dhcpd_arg_file() { - first_file -f /etc/sysconfig/dhcpd /etc/defaults/dhcp /etc/default/dhcp3-server + first_file -f /etc/sysconfig/dhcpd /etc/defaults/dhcp /etc/default/dhcp-server /etc/default/dhcp3-server } # configure interfaces which act as pure bridge ports:
Signature · 1 line
2.7.4
Re: [PATCH 3/3] tools/hotplug: Extend dhcpd conf, init and arg files search
Quoted 12 lines · Diego Sueiro
Newer versions of the ISC dhcp server expect the dhcpd.conf file to be located at
/etc/dhcpdirectory.Also, some distributions and Yocto based ones have these installation paths by default:
/etc/init.d/{isc-dhcp-server,dhcp-server}and/etc/default/dhcp-server.Signed-off-by Diego Sueiro <[email protected]>
Quoted 34 lines
---
tools/hotplug/Linux/xen-network-common.sh| 6 +++---1 file changed, 3 insertions(+), 3 deletions(-)tools/hotplug/Linux/xen-network-common.sh +3
-3@@ -64,18 +64,18 @@ first_file() find_dhcpd_conf_file() { - first_file -f /etc/dhcp3/dhcpd.conf /etc/dhcpd.conf + first_file -f /etc/dhcp/dhcpd.conf /etc/dhcp3/dhcpd.conf /etc/dhcpd.conf } find_dhcpd_init_file() { - first_file -x /etc/init.d/{dhcp3-server,dhcp,dhcpd} + first_file -x /etc/init.d/{isc-dhcp-server,dhcp-server,dhcp3-server,dhcp,dhcpd} } find_dhcpd_arg_file() { - first_file -f /etc/sysconfig/dhcpd /etc/defaults/dhcp /etc/default/dhcp3-server + first_file -f /etc/sysconfig/dhcpd /etc/defaults/dhcp /etc/default/dhcp-server /etc/default/dhcp3-server } # configure interfaces which act as pure bridge ports:Signature · 1 line
2.7.4
Re: [PATCH 3/3] tools/hotplug: Extend dhcpd conf, init and arg files search
In reply to Diego SueiroQuoted 8 lines · Diego Sueiro
Newer versions of the ISC dhcp server expect the dhcpd.conf file to be located at
/etc/dhcpdirectory.Also, some distributions and Yocto based ones have these installation paths by default:
/etc/init.d/{isc-dhcp-server,dhcp-server}and/etc/default/dhcp-server.Signed-off-by Diego Sueiro <[email protected]>
Hi,
A gentle ping to have a review/ack on this serie :-)
(Adding some people in CC)
Bertrand
Quoted 20 lines · Diego Sueiro
This patch series fixes issues around the vif-nat script when setting up the vif interface and dhcp server in dom0.
It has been validated and used in Yocto and meta-arm-autonomy
Diego Sueiro (3):
tools/hotplug: Fix hostname setting in vif-nattools/hotplug: Fix dhcpd symlink removal in vif-nattools/hotplug: Extend dhcpd conf, init and arg files search
tools/hotplug/Linux/vif-nat| 14 ++++++++------tools/hotplug/Linux/xen-network-common.sh| 6 +++---2 files changed, 11 insertions(+), 9 deletions(-)Signature · 1 line
2.7.4