summaryrefslogtreecommitdiffstats
path: root/include/net.h
Commit message (Collapse)AuthorAgeFilesLines
* net: retire global NetRxPackets arraysAhmad Fatoum2024-03-131-2/+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-0/+8
| | | | | | | | | | | 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-1/+0
| | | | | | | | 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: remove unused field from struct eth_deviceSascha Hauer2023-12-191-1/+0
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* include: net: align PKTSIZE to 64 bytesSteffen Trumtrar2023-12-051-2/+2
| | | | | | | | | | | PKTSIZE is used to allocate network packet storage. Make it fill a cache line so drivers using it don't accidentally flush adjacent packets. Suggested-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Link: https://lore.barebox.org/20231201-v2023-08-0-topic-macb-v4-3-b4f5d64de1ad@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: add generic MAC address derivation from machine IDAhmad Fatoum2023-11-221-0/+2
| | | | | | | | | | | | | | | 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: import Linux eth_addr_inc/dec/add helpersAhmad Fatoum2023-09-221-0/+71
| | | | | | | | | Linux has a number of helpers to do arithmetic on Ethernet addresses, which are useful for generating sequential MAC addresses. Import them. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230911155927.3786335-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Convert License Identifiers to SPDX 3.0 for files originating from LiMonRoland Hieber2023-08-071-1/+1
| | | | | | | | | | | | | | The respective U-Boot commit was ported to Barebox in commit 0b5d36d77b6022bd1f40 (2023-07-27, Sascha Hauer: "Add SPDX License identifier for files originating from LiMon"), but the U-Boot change was already made in 2014, and the SPDX specification was updated since then and deprecated the "GPL-2.0" identifier in favour of "GPL-2.0-only". Update the license identifiers to SPDX 3.0 specification, which we also use everywhere else in the Barebox code. Signed-off-by: Roland Hieber <rhi@pengutronix.de> Link: https://lore.barebox.org/20230804094650.2094025-1-rhi@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Add SPDX License identifier for files originating from LiMonSascha Hauer2023-07-281-7/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The header of some LiMon imported files reference a License file which does not exist in barebox. These files were originally licensed under GPLv2 as can be seen in this U-Boot commit: | commit 2ea9103924048637d28baf0f7b1dd410f6704c32 | Author: Wolfgang Denk <wd@denx.de> | Date: Tue Sep 30 10:44:01 2014 +0200 | | SPDX License cleanup for LiMon imported files | | A number of network related files were imported from the LiMon | project; these contain a somewhat unclear license statement: | | Copyright 1994 - 2000 Neil Russell. | (See License) | | I analyzed the source code of LiMon v1.4.2 which was used for this | import. It does not contain any "License" file, but the top level | directory contains a file "COPYING", which turns out to be GPL v2 | of June 1991. So it is legitimate to conclude that the LiMon derived | files are also to be released under GPLv2. Mark them as such. Based on this commit add the correct SPDX License identifier. While at it drop the reference to the non-existing License file and also remove the long unmaintained file history. Reported-by: Oliver Fendt <ofendt@googlemail.com> Link: https://lore.barebox.org/20230727101008.3350548-1-s.hauer@pengutronix.de 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-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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: ifup: have ifup -a poll for link up in parallelAhmad Fatoum2023-02-031-0/+3
| | | | | | | | | | | | | | | | | DHCP is usually fairly quick, but link up check timeout is 10 seconds, which adds up, especially on systems with bigger DSA switches. The workaround is to set ethX.mode=disabled for other ports, but let's improve the default a bit and have barebox poll link ups in parallel, so instead of (number_of_ports_wihout_link * 10s), we just wait 10s at most. For setups where this is a problem, users may revert to ifup in sequence by doing ifup -a -s. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230130072057.34349-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: dsa: add Realtek (rtl8365mb/rtl8366rb) switch supportAhmad Fatoum2023-01-231-1/+2
| | | | | | | | | This imports the Linux v6.1 state of the driver into barebox. This has been tested with the RTL8365MB in (bitbanged) SMI mode. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230116134501.2006391-10-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Rename struct device_d to deviceSascha Hauer2023-01-101-3/+3
| | | | | | | | | | | | | The '_d' suffix was originally introduced in case we want to import Linux struct device as a separate struct into barebox. Over time it became clear that this won't happen, instead barebox struct device_d is basically the same as Linux struct device. Rename the struct name accordingly to make porting Linux code easier. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20221214123512.189688-3-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: add promiscuous mode configuration supportOleksij Rempel2022-11-081-0/+3
| | | | | | | | | | This configuration is mostly needed for controllers attached to switches with different MAC address configurations or for debugging networking issues. Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Link: https://lore.barebox.org/20221108061009.4168735-1-o.rempel@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: Bring up all interfaces when going interactiveSascha Hauer2022-09-221-0/+3
| | | | | | | | | | | | | | So far we only bring up network interfaces when we actually need them. This means we could be idling in the shell for long and once the user decides to do networking he has to wait for the link to be established. We can do better: Before going interactive bring up all known network interfaces which makes the links established when the user needs them. To implement this we have to rework carrier checking a bit, because otherwise barebox would wait for the links to be established before continuing. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: Use dma_alloc to allocate net packetSascha Hauer2022-09-161-1/+2
| | | | | | | | | | | network packets are often DMAed by the network drivers, so allocate them with dma_alloc() rather than assuming that an arbitrarily chosen alignment is sufficient This fixes network transfers on a Rockchip RK3568 board which occasionally sent out packets with corrupt data. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* add ethlog commandOleksij Rempel2022-04-191-0/+11
| | | | | | | | | | 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 of_find_eth_device_by_node() functionOleksij Rempel2022-04-141-0/+1
| | | | | | | | | For DSA support we need to find MAC node by phandle from the switch port node. So, provide of_find_eth_device_by_node() to solve this task. Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Link: https://lore.barebox.org/20220413082205.429509-3-o.rempel@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: add RX preprocessor supportOleksij Rempel2022-04-141-0/+3
| | | | | | | | | 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>
* net: Add a slice to struct eth_deviceSascha Hauer2020-08-191-0/+10
| | | | | | Add ethernet code safe for being called from a poller. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: Add ifdown support and commandSascha Hauer2020-03-311-0/+4
| | | | | | | ifdown is the counterpart to ifup and disables one or all ethernet interfaces. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: Open ethernet devices explicitlySascha Hauer2020-03-311-1/+2
| | | | | | | | Open ethernet devices explicitly rather than implicitly when sending packets. This allows us to not only enable, but in the next step to also disable ethernet devices. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: dns: return error codesSascha Hauer2018-11-291-5/+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: Add linuxdevname propertySascha Hauer2017-12-151-0/+1
| | | | | | | | | | | | | | | | | When you have a static network environment but more than one network device on your machine it is necessary to provide the <device> parameter to the ip parameter at kernel cmd line. The device name assigned by Linux cannot in general be predicted as it depends on driver bind order. This patch introduces a new property linux.devname to eth devices. The value is added to bootargs per interface and can be changed in env/network/INTF Based on patch by Gavin Schenk <g.schenk@eckelmann.de>. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: Provide new way to configure network devicesSascha Hauer2017-12-141-0/+7
| | | | | | | | | | | | | | | | | | | This provides a new way to configure network interfaces based on nvvars. A network interface can now be configured with variables in the nv.dev.<ethname>.* namespace. There is a new network device parameter "mode" which specifies the mode used to obtain IP settings. The mode can be "dhcp", "static" or "disabled": nv.dev.eth0.mode=dhcp (ipaddr, netmask are ignored in this setting) nv.dev.eth0.mode=static nv.dev.eth0.ipaddr=192.168.0.17 nv.dev.eth0.netmask=255.255.0.0 nv.dev.eth0.mode=disabled Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: remove "current" network deviceSascha Hauer2017-12-141-2/+0
| | | | | | | Now that we can do routing we no longer need a "current" network device. Remove it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: Pick network device based on IP settingsSascha Hauer2017-12-141-0/+1
| | | | | | | | | 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-3/+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-0/+4
| | | | | | | | 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-1/+1
| | | | | | | | | | | | | | 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/+1
| | | | | | | | | | | | | 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-1/+0
| | | | | | | | | | | | 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/+4
| | | | | | | | | 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: Add and use IP_BROADCASTSascha Hauer2017-12-011-0/+2
| | | | | | | 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: add linux.bootarg parameter from ifup callEnrico Jorns2016-09-221-0/+1
| | | | | | | | | | | | | This sets a `ip=dhcp` or `ip=<clientip>:<serverip>:<gatewayip>:<netmaskip>::<iface>:` bootarg for the network device upon execution of 'ifup'. This is the only point where we can distinguish between a static ip and a dhcp-based network setup and thus set a valid bootarg options as it will be required for nfs boot, for example. Signed-off-by: Enrico Jorns <ejo@pengutronix.de> Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* convert users to %pI4Sascha Hauer2016-09-221-6/+0
| | | | | | | 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: eth: add name to struct eth_deviceSascha Hauer2016-07-141-0/+6
| | | | | | | | | Using dev_name often is not a good idea since it's a statically allocated string which gets overwritten by later calls to dev_name. Add a devname string to struct eth_device to have the name available for later use. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: introduce for_each_netdev iteratorSascha Hauer2016-07-141-0/+4
| | | | | | | | for_each_netdev is nicer to read. Also export the list of network devices since it will be used by code outside of net/eth.c in later patches. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: resolv: Make argument constSascha Hauer2015-12-141-2/+2
| | | | | | resolv() is not allowed to change the hostname argument, make it const. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: eth: Remove ethaddr_paramJan Remmet2015-11-201-1/+0
| | | | | | | | commit d00db554 introduce ethaddr_param. But it is not initialized, so devinfo fails to show the mac. Remove it and use edev->ethaddr. Signed-off-by: Jan Remmet <j.remmet@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net_udp_bind(): use uint16_t type for source portAntony Pavlov2015-07-201-1/+1
| | | | | Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: eth: Do not rely on CONFIG_PARAMETER to be enabledSascha Hauer2015-06-261-0/+2
| | | | | | | | | 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>
* net: Make set_ethaddr argument constSascha Hauer2015-06-261-1/+1
| | | | | | | The set_ethaddr callback should not modify the MAC address passed to it, so make it const. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net.h: add ETH_ALEN constant; fix whitespacesAntony Pavlov2014-07-021-3/+5
| | | | | Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: Allow to use multiple network interfaces at onceSascha Hauer2014-05-151-1/+2
| | | | | | | | | | | | | | | | 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: Add ifup supportSascha Hauer2014-03-071-0/+5
| | | | | | | | The defaultenv-2 has ifup support as a shell script. This patch replaces it with a command which is more robust, can be called from C and now can also bring up all configured interfaces. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: constify eth_get_byname argumentSascha Hauer2014-03-071-1/+1
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: new function net_read_uint64Uwe Kleine-König2014-02-101-0/+7
| | | | | | | | This is needed for nfs3 support as some types became bigger compared to nfs2. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* net: net_read_uint32: assert that only 32 bit are readUwe Kleine-König2014-02-101-4/+4
| | | | | | | | | | | | | | | On some architectures (e.g. alpha, amd64, arm64, ia64, s390x, mips64) sizeof(ulong) is 8 which made net_read_uint32 actually read too much and even returned the wrong value on big endian machines. (Note the second issue isn't that critical though, because the only architecture from the list above that uses big endian byte order is s390x ...) Also change the argument to void * because the pointer is not necessarily properly aligned. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>