summaryrefslogtreecommitdiffstats
path: root/net/net.c
Commit message (Collapse)AuthorAgeFilesLines
* net: icmp: don't overrun buffer on sendAhmad Fatoum2024-04-051-2/+2
| | | | | | | | | | | | len is the size of the ICMP echo request and the ICMP echo response will have the exact same size, but the code erroneously, copied ETHER_HDR_SIZE bytes worth of extra data beyond the buffer and sent that out. Fix this by using the correct length. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240404184001.1532897-6-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: icmp: properly set IP TTL and fragement fieldsAhmad Fatoum2024-04-051-1/+2
| | | | | | | | | | | | | | | | | We shouldn't keep using the TTL value of the ICMP echo request, as we are sending a fresh packet, therefore restore it to the maximum value. While at it, also fix the frag_off field: A fragment offset of 0 on its own doesn't mean that there's no fragmentation, but that this is the first fragment. Writing 0x4000 there sets the "Don't fragment" bit, which we are already setting for all other IP communication and should be setting here as well. Suggested-by: Jan Lübbe <j.luebbe@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240404184001.1532897-5-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: icmp: don't blindly trust driver supplied frame sizeAhmad Fatoum2024-04-051-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The barebox network stack calls ping_reply() to handle ICMP echo requests. The function copies destination addresses to source addresses, fixes up some fields, recalculates checksums and then sends back the ICMP echo response. There are two checksums involved: The IP checksum over the IP header and the ICMP header spanning the ICMP payload, which extends to the end of packet. The number of bytes that the ICMP checksum should be computed for was being calculated as total_size_reported_by_nic - iphdr_size - ethhdr_size. This is wrong as it assumes that the IP payload extends until the end of packet. There are multiple reasons this may not be the case: - The packet is smaller than the minimum and is thus padded. - The sender adds trailing bytes after the IP payload for no reason. - The network driver reports a wrong size, because it doesn't correctly handle extra bytes added by hardware checksum offloading. The last one affects the barebox cpsw and smsc95xx drivers, which will be fixed up in follow-up commits. The proper solution is to use the same length for the payload and for its checksum. Do this by using the new ip_verify_size(), which will take care to fix up the size discrepancy. This issue was found by trying to ping a Raspberry Pi 3b running barebox sitting behind a router employing conntrack, which apparently discarded the ping responses due to the wrong ICMP checksum. These issues did not occur without such a router in-beween, because the ping command itself doesn't bother to verify the checksum. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240404184001.1532897-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: ip: don't blindly trust driver supplied frame sizeAhmad Fatoum2024-04-051-3/+40
| | | | | | | | | | | | | | | | | | | | | We currently assume that the size reported by the network driver reflects the number of bytes actually transmitted over the wire, but this is apparently not always the case, at least for the barebox cpsw and smc95xx drivers. These don't handle hardware checksum offloading correctly and thus pass extraneous checksum bytes inserted by the hardware to the network stack as if these were part of the transmitted frame. These drivers will be fixed in follow-up commits, but on the off-chance more drivers are affected, let's use the size reported in the IP header when doing IP packet processing. As the old size is needed to dump the packet in net_bad_packet(), this is moved inside the new function. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240404184001.1532897-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: free packets with net_free_packetAhmad Fatoum2024-04-051-4/+4
| | | | | | | | | | While ultimately the same (net_free_packet == dma_free == free), this will not necessarily be always the case, so let's use the dedicated net_free_packet function to free the packets. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240404184001.1532897-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: retire global NetRxPackets arraysAhmad Fatoum2024-03-131-3/+0
| | | | | | | | | Now that no in-tree user of NetRxPackets remain, no one will miss this remnant of simpler times. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240313110704.1095554-8-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: add net_alloc_packets helperAhmad Fatoum2024-03-131-3/+24
| | | | | | | | | | | We have a number of drivers that call net_alloc_packet in a loop and will gain some more in the quest to drop NetRxPackets. Let's provide a helper that can be used for this and a function to free the packets as well. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240313110704.1095554-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* eth: replace ethaddr_to_string() with %pMSascha Hauer2024-02-051-6/+2
| | | | | | | | Now that we can print MAC addresses using the %pM format specifier we can get rid of ethaddr_to_string(). Do this treewide. Link: https://lore.barebox.org/20240202151147.226876-2-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: add generic MAC address derivation from machine IDAhmad Fatoum2023-11-221-2/+47
| | | | | | | | | | | | | | | Especially during development, devices often lack a MAC address. While a MAC address can be easily added to the environment: nv dev.eth0.ethaddr="aa:bb:cc:dd:ee:ff" It's easily lost when flashing complete new images, e.g. from CI. Make the development experience neater by deriving a stable MAC address if possible. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20231122094747.340825-3-uwe@kleine-koenig.org Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net.c: Don't forget about the first fragment.Christian Melki2023-07-281-1/+6
| | | | | | | | | | | | | | | | | | | | It's possible to request very large messages using the current code base. F.ex. UDP datagrams with the tftp client. The tftp servers will happily reply with fragmented IP frames. All these frame parts need to be dropped as BB currently doesn't do fragment reassembly. The current check was for fragment offsets only (0x1fff). But the first frame has fragment offset 0 and would slip through this check. That could result in a seemingly OK frame for the tftp client, but with broken data. Add check for the MF (More Fragments) flag. Should cover the first packet too. Signed-off-by: Christian Melki <christian.melki@t2data.com> Link: https://lore.barebox.org/20230704175535.1183448-1-christian.melki@t2data.com Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: ifup: have ifup -a1 stop at first DHCP-set global.net.serverAhmad Fatoum2023-02-031-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | The normal use case for ifup -a is to get *some* interface working and not really wait for all interfaces to come up and then timeout waiting for those without link up to never get a DHCP lease. When using automounts with a previously empty $global.net.server, we know this to be the case, because the first DHCP interface will set the variable and all remaining ones won't affect this. Therefore, let's add a ifup -a1 option, which would stop after $global.net.server was set via DHCP. This is a special case of a possible future ifup -ar, which would check after each ifup if $global.net.server was either newly set or became resolvable, but that would be a bigger change, so we skip that for now. Times after eth_open_all has brought up CPU Ethernet and 4 DSA ports: barebox$ time ifup -a time: 10002ms barebox$ time ifup -a1 time: 1072ms Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230130072057.34349-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: ping: propagate failureAhmad Fatoum2022-09-121-1/+1
| | | | | | | | We populate ret, but don't do anything with it. Pass it along instead. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220905095557.596891-32-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* add ethlog commandOleksij Rempel2022-04-191-0/+3
| | | | | | | | | | It is kind of tcpdump or tshark for barebox. Instead of starting application it will let barebox dump everything to the console by still allowing to use other application. Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Link: https://lore.barebox.org/20220413082205.429509-15-o.rempel@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: add RX preprocessor supportOleksij Rempel2022-04-141-0/+11
| | | | | | | | | Add callback for optional rx_preprocessor. This is needed to add DSA switch support and demultiplex traffic received from different switch ports. Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Link: https://lore.barebox.org/20220413082205.429509-2-o.rempel@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Removed Unreachable code: net/net.c: net_handle_arp()Neeraj Pal2021-05-121-2/+0
| | | | | | Signed-off-by: Neeraj Pal <neerajpal09@gmail.com> Link: https://lore.barebox.org/20210508193654.81389-1-neerajpal09@gmail.com Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: Replace license and copyright boilerplate by SPDX identfiersUwe Kleine-König2020-11-021-17/+7
| | | | | | | | | Converts the files that licensecheck can determine to be licensed under GPL-2.0-only or GPL-2.0-or-later and also convert the copyright statements to SPDX. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* magicvar: Replace BAREBOX_MAGICVAR_NAMED with BAREBOX_MAGICVARSascha Hauer2020-10-021-3/+3
| | | | | | | | BAREBOX_MAGICVAR now generates a unique identifier automatically, so we can convert users of BAREBOX_MAGICVAR_NAMED to the simpler BAREBOX_MAGICVAR macro. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: reply to ping requestsSascha Hauer2020-08-191-2/+44
| | | | | | | Now that we have the network receive function running in a poller we can reasonably well answer to ping requests. Implement this feature. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: Call net_poll() in a pollerSascha Hauer2020-08-191-0/+50
| | | | | | | | | | | | | | | This adds calling of net_poll() in a poller. With this we can react to incoming packets like ping requests or fastboot requests. We could change to call net_poll() from a poller exclusively, but this would significantly slow down USB network controllers. As described in the patch these take a long time in the packet receive path. To work around this we keep the networking users call net_poll() at a high rate when they are waiting for incoming packets and only every 10ms we call net_poll() from a poller to get incoming traffic when no networking protocol is actively calling net_poll(). Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: remove references to CREDITSUwe Kleine-König2020-04-271-3/+0
| | | | | | | | The CREDITS file was removed from barebox in 2015 by commit 6570288f2d97 ("Remove the CREDITS file"). Remove references to it from several files. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: Allow hostnames for global.net.serverSascha Hauer2019-01-041-5/+14
| | | | | | | Additional to IPv4 addresses add support for global.net.server being a hostname. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: dns: return error codesSascha Hauer2018-11-291-1/+3
| | | | | | | | | | | | | | The resolv() function used to return the IP address. When net_udp_new() fails we return an error code though which the callers of resolv() take as an IP address. This is wrong of course and we could return 0 in this case. Instead we return an error code and pass the resolved IP as a pointer which allows us to return proper error codes. This patch also adds error messages and error returns to the various callers of resolv() which used to just continue with a zero IP and let the user figure out what went wrong. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: Do not route traffic to interfaces that are not upAndrey Smirnov2018-08-221-1/+1
| | | | | | | | | | | | | | | | | | | | | In the case when: - Board has multiple network interfaces - Two ore more of those interfaces are statically configured to be on the same network - Only one of those interfaces is up and it is preceeded (as far as for_each_netdev is concerned) by interface in the same network that isn't net_route() will choose "non-up" device as a route for traffic resulting in no network connectivity. Change the routing logic to also consider if interface is "up", so that only such interfaces would be considered for sending network traffic out. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: use dev_warn() when no MAC address is setVivien Didelot2018-05-221-1/+1
| | | | | | | | | | | | | | | | | | | When a SoC such as VF610 has no addresses programmed for both its interfaces, the "No MAC address set" warning can be confusing: booting 'net' WARNING: net: warning: No MAC address set. Using random address a2:e8:be:79:72:01 WARNING: net: warning: No MAC address set. Using random address aa:d5:d7:10:c0:42 This patch uses dev_warn() instead and removes the redundant "warning": booting 'net' WARNING: eth0: No MAC address set. Using random address a2:e8:be:79:72:01 WARNING: eth1: No MAC address set. Using random address 4e:be:c4:bc:ce:36 Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Acked-by: Sam Ravnborg <sam@ravnborg.org>
* net: Pick network device based on IP settingsSascha Hauer2017-12-141-2/+28
| | | | | | | | | The IP/netmask/gateway settings contain all informations needed to pick the correct network device. This patch adds support for that and makes specifying the "current" network interface using the ethact command unnecessary. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: dhcp: Allow to specify network deviceSascha Hauer2017-12-141-9/+3
| | | | | | | | | Instead of allowing to DHCP only on the "current" network device, allow to specify the desired network device. This is a first step to get rid of the concept of a "current" network device. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: allow udp connections on specified network deviceSascha Hauer2017-12-011-12/+20
| | | | | | | | This allows the DHCP code to configure specific network devices so that DHCP no longer depends on any "current" network device. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: Use a single gatewaySascha Hauer2017-12-011-4/+9
| | | | | | | | | | | | | | There is not much point in having a network device specific gateway. If barebox really is part of such a complicated network in which it needs multiple gateways, then we probably need a real routing table. Until this happens, a single gateway should be enough. This introduces global.net.gateway which holds the gateway ip. The previously used device specific <ethx>.gateway variables still exist, but are only aliases for the single gateway. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: dhcp: Do not overwrite serverip if it is validSascha Hauer2017-12-011-0/+8
| | | | | | | | | | | | | Some DHCP servers provide the wrong serverip in which case it is desired to specify it manually and won't let the dhcp command overwrite it. This has previously been done by setting the serverip again to the desired value after dhcp has been executed. With this patch we do not overwrite it in the first place if it is valid already. This is necessary when the serverip is not set via /env/network/eth* but via nv.net.server. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: introduce global.net.serverSascha Hauer2017-12-011-6/+5
| | | | | | | | | | | | The server to use is independent of the network device, there is not much point to make the server specific to a network device. This introduces global.net.server as the serverip which is used as standard NFS/tftp server. The previously used eth device specific parameters still exist, but are only aliases for the global single variable. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: Add functions to get/set nameserver and domainnameSascha Hauer2017-12-011-0/+24
| | | | | | | | | It's more convenient to have getter/setter functions for variables rather than using the detour around global vars which use string matching and all kinds of overhead in the background. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: Make domainname and nameserver globalvarsSascha Hauer2017-12-011-15/+10
| | | | | | | | | Register domainname and nameserver as globalvars rather than attaching them to a dedicated net device. the global device already exists and already contains much of the barebox configuration, so no need to add an extra device for network config. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: Add and use IP_BROADCASTSascha Hauer2017-12-011-3/+3
| | | | | | | Rather than using the hardcoded value 0xffffffff in several places add a define for the broadcast IP. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: use pr_* functions for messagesSascha Hauer2017-12-011-12/+14
| | | | | | | | Use pr_* functions in the networking code rather than printf() and debug(). Also Add a "net: " prefix to messages to give them some more context. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: use dev_add_param_stringSascha Hauer2017-04-111-2/+9
| | | | | | | dev_add_param_string allows to pass a priv * so that the device_d * argument is not needed and can be removed later. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* convert users to %pI4Sascha Hauer2016-09-221-2/+2
| | | | | | | Convert users of ip_to_string() and print_IPaddr() to %pI4 and remove the now unused functions. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: Pass network device to net_answer_arp()Sascha Hauer2016-07-141-3/+2
| | | | | | | | | The caller already has the correct network device, so pass it to net_answer_arp() rather than using eth_get_current() there. This is a step towards making a global current network device unnecessary. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: fix 'new blank line at EOF' formatting errorAntony Pavlov2015-07-021-1/+0
| | | | | Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: Move library functions to net/lib.cSascha Hauer2015-07-021-78/+0
| | | | | | | Some network related functions are also needed when networking is disabled. Move these to a separate file which is always compiled. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: eth: Do not rely on CONFIG_PARAMETER to be enabledSascha Hauer2015-06-261-1/+1
| | | | | | | | | register_preset_mac_address only works when CONFIG_PARAMETER is enabled because otherwise dev_set_param is a no-op. Add a function to set the MAC address explicitly without the need of CONFIG_PARAMETER and use it where appropriate. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/net'Sascha Hauer2014-06-041-11/+10
|\ | | | | | | | | Conflicts: drivers/net/dm9k.c
| * net: Allow to use multiple network interfaces at onceSascha Hauer2014-05-151-10/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In barebox network packets always go out at the current ethernet device and are expected to be received from the current interface. This has some side effects. When for example an NFS is mounted when one interface is active and the interface is changed afterwards the NFS packets leave the new interface, but the NFS server won't be reachable there. Instead of changing the whole network traffic to the current ethernet interface we now initialize a network connection with the current network interface, but then the connection will continue to use that interface even when the current interface is changed. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * net: Pass eth_device to net_receiveSascha Hauer2014-05-151-1/+1
| | | | | | | | | | | | | | So that barebox has the information which interface a packet came from. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | net: show enetaddr in lowercaseHolger Schurig2014-06-021-1/+1
|/ | | | | | | | | "ifconfig" and "ip" from normal Linux userspace shows ethernet addresses normally in lowercase. And the %pM format specifier in Linux does that, too. Conform to this custom formatting. Signed-off-by: Holger Schurig <holgerschurig@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: Fix error return value for string_to_ethaddrSascha Hauer2014-01-201-2/+2
| | | | | | Return a proper error code instead of -1 which would be -EPERM. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* barebox: remove double semicolonsAlexander Aring2013-11-181-1/+1
| | | | | Signed-off-by: Alexander Aring <alex.aring@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: fix checksum verificationBaruch Siach2013-08-121-1/+1
| | | | | | | | | Checksum calculation on data including its own checksum (as is the case with IP headers) should give 0xffff before bit flipping. Current code works well for the correct checksum case, but fails to identify errors. Signed-off-by: Baruch Siach <baruch@tkos.co.il> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: store ethernet device parameters in deviceSascha Hauer2013-04-111-48/+32
| | | | | | | | Rather than storing the parameters globally and trying to keep them in sync with the device parameters, store the parameters in the ethernet device directly. Also, update to dev_add_param_ip(). Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mem: add the swab (swap bytes) option to memory_display()Antony Pavlov2012-11-261-1/+1
| | | | | Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/remove-fsf-address'Sascha Hauer2012-10-031-3/+0
|\ | | | | | | | | | | Conflicts: drivers/net/miidev.c include/miidev.h