GCC 9 introduced some new compiler warnings that occur when taking the
address of a packed struct, e.g.:
lib/libnet/icmpv6.c:173:21: warning: taking address of packed member of
‘struct ip6hdr’ may result in an unaligned pointer value [-Waddress-of-packed-member]
173 | rtr = find_router (&(ip6h->src));
| ^~~~~~~~~~~~
Since these warnings are mainly about the ip6_addr_t values that are
embedded in these packed structs, and ip6_addr_t is reasonable small
(just 128 bit), let's fix it by passing around the IPv6 addresses by
value instead of pointer, which looks a little bit nicer anyway.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
The current if-condition can never be true.
Buglink: https://bugs.launchpad.net/qemu/+bug/1840646
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
I recently noticed that if you start QEMU with two NICs, and only
want to boot from the second NIC, SLOF only tries to get an IP
address via DHCPv6 instead of trying both, DHCPv4 and DHCPv6. For
example:
$ qemu-system-ppc64 -nic hubport,hubid=1 \
-nic user,model=virtio,tftp=/.../tftp,bootfile=zImage.pseries
[...]
Trying to load: from: /vdevice/l-lan@71000002 ...
Initializing NIC
Reading MAC address from device: 52:54:00:12:34:56
Requesting information via DHCP: 007
Aborted
E3001 (net) Could not get IP address
Trying to load: from: /pci@800000020000000/ethernet@0 ...
Initializing NIC
Reading MAC address from device: 52:54:00:12:34:57
Requesting information via DHCPv6: done
Using IPv6 address: fec0::5254:ff:fe12:3457
The problem is that we never re-initialize the "ip_version" variable
anymore, so once it has been set to 6, it stays at 6 for the second
network boot attempt, too. Thus reset the variable to 4 at the beginning
of the netload() function.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
There are two small bugs in the pxelinux.cfg parser:
1. If the file does not end with a '\n', the code set 'eol = cfg + cfgsize'
and later wrote a NUL character to *eol, i.e. it wrote the NUL character
beyond the end of the buffer. We've got to use 'eol = cfg + cfgsize - 1'
instead.
2. The code always replaced the last byte of the buffer with a NUL character
to get a proper termination. If the config file ends with a required character
(e.g. the last line is a KERNEL or INITRD line and the file does not have
a '\n' at the end), the last character got lost. Move the obligation for the
terminating NUL character to the caller instead so that we can be sure to
have a proper terminated buffer in pxelinux_parse_cfg() without the need to
blindly overwrite the last character here.
Reviewed-by: Greg Kurz <groug@kaod.org>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
The pxelinux_load_cfg() function always tried to load one byte less than
its parameter said (so that we've got space for a terminating NUL-character
later). This is not very intuitive, let's better ask for one byte less
when we call the function. While we're at it, add a sanity check that
the function really did not load more bytes than requested.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Retrieve the UUID from the device tree and pass it to the pxelinux.cfg
function, so that we can look there for UUID-based file names, too.
Signed-off-by: Thomas Huth <thuth@redhat.com>
[aik: removed trailing space]
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
There are two dedicated DHCP options for loading PXELINUX config files,
option 209 (config file name) and 210 (path prefix). We should support
them, too, in case some users want to configure their boot flow this way.
See RFC 5071 and the following URL for more details:
https://www.syslinux.org/wiki/index.php?title=PXELINUX#DHCP_options
Unlike most other strings in libnet, I've chosen to not use fixed-size
arrays for these two strings, but to allocate the memory via malloc here.
We always have to make sure not to overflow the stack in Paflof, so
adding 2 * 256 byte arrays to struct filename_ip sounded just too
dangerous to me.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
In case the normal network loading failed, try to load a pxelinux.cfg
config file. If that succeeds, load the kernel and initrd with the
information that could be found in this file.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Booting a kernel via pxelinux.cfg files is common on x86 and also with
ppc64 bootloaders like petitboot, so it would be nice to support this
in SLOF, too. This patch adds functions for downloading and parsing
such pxelinux.cfg files. See this URL for more details on pxelinux.cfg:
https://www.syslinux.org/wiki/index.php?title=PXELINUX
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
This way we can easily re-use the rc --> string translation in later
patches.
Reviewed-by: Greg Kurz <groug@kaod.org>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
When we will support loading of pxelinux.cfg files later, we have to call
the tftp load function multiple times from different places. To avoid that
we've also got to pass around the ip_version information via function para-
meters to all spots, let's rather put it into struct filename_ip instead
since we've got this struct filename_ip info available everywhere already.
While we're at it, also drop the __attribute__((packed)) from the struct.
The struct is only used internally, without exchanging it with the outside
world, so the attribute is certainly not necessary here.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
The blocksize is hard-coded to 1428 bytes in obp-tftp.fs, so instead of
hardcoding this in the Forth code, we could also move this into tftp.c
directly instead. A similar condition exists with the huge-tftp-load
parameter. While this non-standard variable could still be changed in the
obp-tftp package, it does not make much sense to set it to zero since you
only lose the possibility to do huge TFTP loads with index wrap-around in
that case.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
For some strange reasons, the libnet code is using int8_t arrays for
strings in a couple of places where it really does not make any sense.
Therefor a lot of "(char *)" casts are needed when the code is using
the string functions from the libc. Let's change the strings to use
"char" instead of "int8_t" so we can get rid of a lot of these casts.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
According to TFTP Booting extension, after the success of BOOTP, BOOTREPLY
packet should be copied to bootp-response property under "/chosen"
While in current case, even when DHCP was used, bootp-response was being set. So
set bootp-response when BOOTP is used and dhcp-response for DHCP
Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
times_asked value remains same as the structure is zeroed, but it makes more
sense to do that directly instead of adding with previous value.
Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
To be able to re-use the libnet code in other projects (where
the rather Open Firmware specific netload.c can not be used),
the function parse_tftp_args() must be moved to another file.
The function is related to TFTP, and its prototype is already
declared in tftp.h, so the code should reside in tftp.c.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
When compiling the libnet code with the -Wformat-security compiler
flag, there is a warning in tftp.c that printf is used without
format argument. It's not a real problem here, but let's make
the code ready for this compiler flag anyway and add a proper
format string here, too.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
When compiling SLOF with the -Wredundant-decls compiler flag,
there is currently a warning in the libnet code since the send_ip
pointer is currently declared twice, one time in ipv4.h and
one time in ipv6.h. To avoid this warning, let's move the
declaration to IP-version independent ethernet.h instead.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
The error code in netload_error() could be longer than 4 characters,
so we should rather use the calculated string length here instead.
The tftp_err variable is only used in tftp_load() so it can be moved
there.
And the icmp_err_str variable only points to constant strings, so it
should be marked with "const".
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
It's theoretically possible to load a file to address 0, too, so
we should use a different marker than NULL to check for a valid
buffer.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
netload() is a huge function, it's easy to lose track here. So
let's refactor the TFTP-related loading and error printing code
into a separate function instead.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
There is a repetive pattern of code in netload.c to print out
error message: snprintf(buf, ...) + bootmsg_error() + write_mm_log().
The code can be simplified / shortened quite a bit by consolidating
this pattern in a helper function.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
The code does not exist in the repository, so it does not make
sense to keep the prototypes and the Forth wrapper around.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Some applications, e.g. https://maas.io/, trust on the dhcp code 93
option to reply the correct pxelinux.0 file according to client
architecture.
Today, dhcp.c is compiled without DHCPARCH, which causes it not to
send client architecture in the dhcp request, i.e. dhcpd server can
reply a pxelinux.0 binary that is not intended for client
architecture.
This patch makes sure client architecture is sent in the dhcp request.
Signed-off-by: Murilo Opsfelder Araujo <muriloo@linux.vnet.ibm.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Replace indentation spaces with tabs, remove superfluous prototype
(ip6addr_add() is declared in ipv6.h already) and fix the old-style
declaration of ip6_create_prefix_info(). No functional changes done.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
While doing IPv6 network booting in SLOF, I recently ran into
"ERROR: stack overflow in engine()!" messages. Looks like the
huge ether_packet arrays that are created on the stack in icmpv6.c
can cause these stack overflows. Fix this issue by allocating
the ether_packets from the heap instead (the functions should
not be timing critical, so the additional overhead should not
be an issue here).
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
There is no need anymore to pass most of the arguments as
strings, we can use integers and pointers now instead.
While we're at it, change the maximum TFTP packet block size
in obp-tftp.fs from 1432 to 1428, since this is the correct
value (with 1432, there might be problems with networking
over VLANs). The code in tftp.c forces this value to 1428
anyway (see the MAX_BLOCKSIZE constant there), so this change
is just cosmetical, and should not change the behavior of
the TFTP loading process.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Now that we do not link libnet against net-snk anymore, we can
change the prototype of ping() and thus simplify the "net-ping"
Forth-to-C wrapper. There is no need to convert the parameters
to a temporary argv[] array anymore.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Since libnet is now linked to Paflof directly, we do not have to
link it into net-snk anymore. So for board-qemu, we can now even
exclude net-snk completely from the build (for board-js2x, it is
still required for the biosemu, so we can not erase the net-snk
folder completely yet).
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Now that we link libnet to Paflof, we can call the ping
function there directly instead of using the one from
net-snk. We add a similar Forth-to-C wrapper like it has
already been done for netboot() - simplification and clean-up
will be done in a later patch once we do not link against
net-snk anymore.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Now that all necessary functions are provided by Paflof, too,
we can finally link the libnet code to this binary. To be able
to call the netboot() function from the Forth code now, we also
add a wrapper that takes the parameter string from the obp-tftp
package and converts it to an argv array that is expected by
the netboot() function.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Unfortunately netapps.h currently can't be included from .code
Forth-to-C wrapper files - it includes tftp.h which in turn
includes ipv6.h, and that header contains some constructs which
can't be used in .code files. So let's make netapps.h independent
from tftp.h and add some "extern" keywords like it is done with
the other header files already that are included from .code files.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
These functions do not exist anymore, thus their prototypes
can be removed nowadays.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Commit 7e31382cca ("Improve printed text when booting
via network") moved the "Requesting information via DHCP..."
printf statement from the netboot() function into the dhcp()
function. However, it did not take into account that the
ping() function should be changed in the same way, so with
ping, the message is currently printed out twice. So let's
re-arrange the printout of ping() now accordingly.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
If libnet is linked to the net-snk, it does not matter since the
whole stack is completely reloaded each time. But if we are
linking libnet to Paflof, we've got to make sure to properly
release the resources that we've allocated before, since the
code and data stays in memory.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
They are needed for libnet, too. This implementation uses
SLOF_GetTimer() instead of using the decrementer like it is
done in the net-snk functions.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
When we will link the TFTP code to paflof instead of net-snk later,
the executable won't be reloaded each time we want to do an TFTP
transfer, so we got to make sure to initialize global variables
properly instead of relying on the ELF loader to do this job.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
The separate mtftp.h and mtftp.c files (for doing multicast TFTP)
never really got included into the SLOF repository, so it does
not make sense to keep the "#ifdef USE_MTFTP" code snippets around.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
These files should go into libnet, too, so we can later link
them to paflof instead of net-snk.
Note: A "make distclean" is required after applying this patch
to make sure that the dependencies for the moved files are
properly re-generated.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
When we want to link the network stack to other parts of the
firmware later (paflof), we've got to turn it into a proper
library first.
Note: Make sure to run "make distclean" after this patch, so that
the dependencies for the moved files get rebuilt properly.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>