aboutsummaryrefslogtreecommitdiff
path: root/lib/libnet
AgeCommit message (Collapse)AuthorFilesLines
2023-02-28Fix typos in the lib/libnet folderThomas Huth9-28/+28
Found with the "codespell" utility. Signed-off-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2023-02-28lib/libnet/ipv6: Silence compiler warning from ClangThomas Huth1-3/+2
When compiling the libnet code with Clang (e.g. for the s390-ccw bios), it complains with the following warning: ipv6.c:447:18: warning: variable length array folded to constant array as an extension [-Wgnu-folding-constant] unsigned short raw[ip6size]; ^ The warning is completely harmless, of course. Anyway let's rewrite the code a little bit to make the compiler silent again. Signed-off-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2021-02-12libnet: Compile with -WextraAlexey Kardashevskiy4-9/+10
-Wextra enables a bunch of rather useful checks which this fixes. This also fixes unused parameters warning by passing meaningful value and doing sanity checks. Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> --- Changes: v2: * updated commit log about using AF_INET/etc * replaced cast to int with size_t in pxelinux_load_cfg * added (alen == 0) in ping()
2019-10-22ipv6: Fix gcc9 warningsThomas Huth5-57/+49
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-08-27libnet: Fix the check of the argument lengths of the "ping" commandThomas Huth1-1/+1
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-04-10libnet: Correctly re-initialize the "ip_version" variable each timeThomas Huth1-1/+3
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>
2018-06-07lib/libnet/pxelinux: Fix two off-by-one bugs in the pxelinux.cfg parserThomas Huth1-5/+6
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-07lib/libnet/pxelinux: Make the size handling for pxelinux_load_cfg more logicalThomas Huth1-6/+8
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-05-29libnet: Support UUID-based pxelinux.cfg file namesThomas Huth3-5/+31
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-29libnet: Add support for DHCPv4 options 209 and 210Thomas Huth5-20/+88
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-29libnet: Wire up pxelinux.cfg network bootingThomas Huth1-2/+82
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-29libnet: Add functions for downloading and parsing pxelinux.cfg filesThomas Huth3-1/+246
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-29libnet: Put code for determing TFTP error strings into a separate functionThomas Huth3-73/+109
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-29libnet: Pass ip_version via struct filename_ipThomas Huth3-12/+13
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-25libnet: Get rid of unused huge_load and block_size parametersThomas Huth5-23/+10
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-14libnet: Get rid of unnecessary (char *) castsThomas Huth6-33/+35
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>
2017-09-26netboot: Create bootp-response when bootp is usedNikunj A Dadhania3-17/+51
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-26libnet/ipv6: assign times_asked value directlyNikunj A Dadhania1-1/+1
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-07-10libnet: Move parse_tftp_args to tftp.cThomas Huth2-106/+104
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-07libnet: Make the code compilable with -Wformat-securityThomas Huth1-1/+1
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-07libnet: Move the external declaration of send_ip to ethernet.hThomas Huth3-4/+3
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-06-30libnet/netload: Three more minor clean-upsThomas Huth1-12/+13
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-30libnet/tftp: Allow loading to address 0Thomas Huth1-5/+6
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-28libnet: Refactor some code of netload() into a separate functionThomas Huth1-83/+94
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-28libnet: Rework error message printingThomas Huth1-82/+44
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-28libnet: Remove remainders of netsave codeThomas Huth2-3/+0
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-28lib/Makefile: Pass FLAG to make in SUBDIRS targetMurilo Opsfelder Araujo1-1/+1
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-15libnet: Cosmetical clean-upThomas Huth3-14/+11
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-15libnet: Allocate ICMPv6 packet space on the heap, not on the stackThomas Huth1-4/+26
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>
2016-10-17libnet: Simplify the net-load arguments passingThomas Huth3-24/+23
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-17libnet: Simplify the Forth-to-C wrapper of ping()Thomas Huth3-22/+15
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-17Do not link libnet to net-snk anymore, and remove net-snk from board-qemuThomas Huth2-3/+2
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-17Add a Forth-to-C wrapper for the ping command, tooThomas Huth2-0/+18
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-17Link libnet code to Paflof and add a wrapper for netboot()Thomas Huth2-0/+21
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-10libnet: Make netapps.h includable from .code filesThomas Huth3-9/+12
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-10libnet: Remove unused prototypes from netapps.hThomas Huth1-3/+0
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-10libnet: Fix the printout of the ping commandThomas Huth1-3/+1
Commit 7e31382cca5fb988b ("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-10libnet: Make sure to close sockets when we're doneThomas Huth2-0/+10
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-09-14paflof: Provide get_timer() and set_timer() helper functionsThomas Huth1-0/+6
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-08-16libnet: Re-initialize global variables at the beginning of tftp()Thomas Huth1-15/+23
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-06-27net: Remove remainders of the MTFTP codeThomas Huth3-49/+1
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-27net: Move also files from clients/net-snk/app/netapps/ to lib/libnet/Thomas Huth6-1/+1305
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-27net: Move files from clients/net-snk/app/netlib/ to lib/libnet/Thomas Huth24-0/+6130
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>