Commit Graph

40 Commits

Author SHA1 Message Date
Thomas Huth 8c6d468210 ipv6: Fix gcc9 warnings
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>
2019-10-22 14:35:36 +11:00
Thomas Huth eeed8a10a8 libnet: Fix the check of the argument lengths of the "ping" command
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>
2019-08-27 12:00:36 +10:00
Thomas Huth 273d9ce14b libnet: Correctly re-initialize the "ip_version" variable each time
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>
2019-04-10 16:03:00 +10:00
Thomas Huth 2317427ce7 lib/libnet/pxelinux: Fix two off-by-one bugs in the pxelinux.cfg parser
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>
2018-06-07 16:44:25 +10:00
Thomas Huth 1eb8d7ec2d lib/libnet/pxelinux: Make the size handling for pxelinux_load_cfg more logical
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>
2018-06-07 16:43:00 +10:00
Thomas Huth 64c526a602 libnet: Support UUID-based pxelinux.cfg file names
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>
2018-05-29 19:08:14 +10:00
Thomas Huth 9976594366 libnet: Add support for DHCPv4 options 209 and 210
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>
2018-05-29 19:06:59 +10:00
Thomas Huth 08e22e4019 libnet: Wire up pxelinux.cfg network booting
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>
2018-05-29 19:06:45 +10:00
Thomas Huth 696e2036f4 libnet: Add functions for downloading and parsing pxelinux.cfg files
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>
2018-05-29 19:06:31 +10:00
Thomas Huth 382ae44433 libnet: Put code for determing TFTP error strings into a separate function
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>
2018-05-29 19:06:18 +10:00
Thomas Huth b08529db70 libnet: Pass ip_version via struct filename_ip
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>
2018-05-29 19:05:11 +10:00
Thomas Huth 4c2af4e48f libnet: Get rid of unused huge_load and block_size parameters
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>
2018-05-25 14:55:50 +10:00
Thomas Huth 4183816dcc libnet: Get rid of unnecessary (char *) casts
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>
2018-05-14 19:56:07 +10:00
Nikunj A Dadhania 3beb9c32d4 netboot: Create bootp-response when bootp is used
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>
2017-09-26 17:54:00 +10:00
Nikunj A Dadhania 6f4ed1c01c libnet/ipv6: assign times_asked value directly
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>
2017-09-26 12:42:05 +10:00
Thomas Huth 834113a1c6 libnet: Move parse_tftp_args to tftp.c
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>
2017-07-10 12:21:09 +10:00
Thomas Huth 64215f41aa libnet: Make the code compilable with -Wformat-security
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>
2017-07-07 16:40:58 +10:00
Thomas Huth 14df554937 libnet: Move the external declaration of send_ip to ethernet.h
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>
2017-07-07 16:40:53 +10:00
Thomas Huth 5d34a1b6c5 libnet/netload: Three more minor clean-ups
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>
2017-06-30 15:30:37 +10:00
Thomas Huth c633b135c0 libnet/tftp: Allow loading to address 0
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>
2017-06-30 15:30:32 +10:00
Thomas Huth d2d31be1b5 libnet: Refactor some code of netload() into a separate function
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>
2017-06-28 13:14:11 +10:00
Thomas Huth 140c3f39db libnet: Rework error message printing
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>
2017-06-28 13:14:03 +10:00
Thomas Huth 2f5f252995 libnet: Remove remainders of netsave code
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>
2017-06-28 13:13:57 +10:00
Murilo Opsfelder Araujo db35f1b8a2 lib/Makefile: Pass FLAG to make in SUBDIRS target
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>
2017-06-28 13:13:38 +10:00
Thomas Huth d5997edcbc libnet: Cosmetical clean-up
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>
2017-06-15 16:11:32 +10:00
Thomas Huth 8c41240bc4 libnet: Allocate ICMPv6 packet space on the heap, not on the stack
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>
2017-06-15 16:11:32 +10:00
Thomas Huth 87404ee220 libnet: Simplify the net-load arguments passing
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>
2016-10-17 11:02:16 +11:00
Thomas Huth f7eb3a5728 libnet: Simplify the Forth-to-C wrapper of ping()
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>
2016-10-17 11:02:16 +11:00
Thomas Huth 725e9d28b7 Do not link libnet to net-snk anymore, and remove net-snk from board-qemu
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>
2016-10-17 11:02:16 +11:00
Thomas Huth a8750987ca Add a Forth-to-C wrapper for the ping command, too
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>
2016-10-17 11:02:15 +11:00
Thomas Huth a225adc3a1 Link libnet code to Paflof and add a wrapper for netboot()
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>
2016-10-17 11:02:15 +11:00
Thomas Huth 3cca9577f7 libnet: Make netapps.h includable from .code files
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>
2016-10-10 17:30:54 +11:00
Thomas Huth dc2eba87c1 libnet: Remove unused prototypes from netapps.h
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>
2016-10-10 17:30:54 +11:00
Thomas Huth 9e34542c0f libnet: Fix the printout of the ping command
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>
2016-10-10 17:30:54 +11:00
Thomas Huth 265ee13712 libnet: Make sure to close sockets when we're done
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>
2016-10-10 17:30:54 +11:00
Thomas Huth 91d86c568e paflof: Provide get_timer() and set_timer() helper functions
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>
2016-09-14 17:50:40 +10:00
Thomas Huth 2174d9b883 libnet: Re-initialize global variables at the beginning of tftp()
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>
2016-08-16 18:47:49 +10:00
Thomas Huth 2435442ede net: Remove remainders of the MTFTP code
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>
2016-06-27 12:31:06 +10:00
Thomas Huth e7ac2e5f65 net: Move also files from clients/net-snk/app/netapps/ to lib/libnet/
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>
2016-06-27 12:31:06 +10:00
Thomas Huth 3c1fe653f5 net: Move files from clients/net-snk/app/netlib/ to lib/libnet/
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>
2016-06-27 12:31:06 +10:00