diff mbox series

[v2] Allow colon in PXE bootfile URLs

Message ID 20220122151636.11887-1-lylejfranklin@gmail.com
State Changes Requested
Delegated to: Ramon Fried
Headers show
Series [v2] Allow colon in PXE bootfile URLs | expand

Commit Message

Lyle Franklin Jan. 22, 2022, 3:16 p.m. UTC
- U-boot's PXE flow supports prefixing your bootfile name with an
  IP address to fetch from a server other than the DHCP server,
  e.g. `hostIPaddr:bootfilename`:
  https://github.com/u-boot/u-boot/commit/a93907c43f847f076dd0e34ee3b69b5e8e6d0d29
- However, this breaks bootfile paths which contain a colon, e.g.
  `f0:ad:4e:10:1b:87/7/pxelinux.cfg/default`
- This patch checks whether the `hostIPaddr` prefix is a valid
  IP address before overriding the serverIP otherwise the whole
  bootfile path is preserved

Signed-off-by: Lyle Franklin <lylejfranklin@gmail.com>
---
 net/net.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Ramon Fried April 10, 2022, 5:30 a.m. UTC | #1
On Sat, Jan 22, 2022 at 5:16 PM Lyle Franklin <lylejfranklin@gmail.com> wrote:
>
> - U-boot's PXE flow supports prefixing your bootfile name with an
>   IP address to fetch from a server other than the DHCP server,
>   e.g. `hostIPaddr:bootfilename`:
>   https://github.com/u-boot/u-boot/commit/a93907c43f847f076dd0e34ee3b69b5e8e6d0d29
> - However, this breaks bootfile paths which contain a colon, e.g.
>   `f0:ad:4e:10:1b:87/7/pxelinux.cfg/default`
> - This patch checks whether the `hostIPaddr` prefix is a valid
>   IP address before overriding the serverIP otherwise the whole
>   bootfile path is preserved
>
> Signed-off-by: Lyle Franklin <lylejfranklin@gmail.com>
> ---
>  net/net.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/net/net.c b/net/net.c
> index 072a82d8f9..57ed77795a 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -1538,14 +1538,18 @@ int is_serverip_in_cmd(void)
>  int net_parse_bootfile(struct in_addr *ipaddr, char *filename, int max_len)
>  {
>         char *colon;
> +       struct in_addr ip;
>
>         if (net_boot_file_name[0] == '\0')
>                 return 0;
>
>         colon = strchr(net_boot_file_name, ':');
>         if (colon) {
> -               if (ipaddr)
> -                       *ipaddr = string_to_ip(net_boot_file_name);
> +               ip = string_to_ip(net_boot_file_name);
> +               if (ipaddr && ip.s_addr)
> +                       *ipaddr = ip;
> +       }
> +       if (ip.s_addr) {
>                 strncpy(filename, colon + 1, max_len);
>         } else {
>                 strncpy(filename, net_boot_file_name, max_len);
> --
> 2.31.1
>
Applied to u-boot-net/next
Thanks,
Ramon
diff mbox series

Patch

diff --git a/net/net.c b/net/net.c
index 072a82d8f9..57ed77795a 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1538,14 +1538,18 @@  int is_serverip_in_cmd(void)
 int net_parse_bootfile(struct in_addr *ipaddr, char *filename, int max_len)
 {
 	char *colon;
+	struct in_addr ip;
 
 	if (net_boot_file_name[0] == '\0')
 		return 0;
 
 	colon = strchr(net_boot_file_name, ':');
 	if (colon) {
-		if (ipaddr)
-			*ipaddr = string_to_ip(net_boot_file_name);
+		ip = string_to_ip(net_boot_file_name);
+		if (ipaddr && ip.s_addr)
+			*ipaddr = ip;
+	}
+	if (ip.s_addr) {
 		strncpy(filename, colon + 1, max_len);
 	} else {
 		strncpy(filename, net_boot_file_name, max_len);