netconsole: allow selection of egress interface via MAC address
Subsystems (8)
v5 cover netconsole: allow selection of egress interface via MAC address
This series adds support for selecting a netconsole egress interface by specifying the MAC address (in place of the interface name) in the boot/module parameter.
---
Changes in v5:
- Drop Breno Leitao's patch to add (non-RCU) dev_getbyhwaddr from this
set since it has landed on net-next (Jakub Kicinski)
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- Incorporate Breno Leitao's patch to add (non-RCU) dev_getbyhwaddr and
use it (Jakub Kicinski)
- Use MAC_ADDR_STR_LEN in ieee80211_sta_debugfs_add as well (Michal Swiatkowski)
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Rename MAC_ADDR_LEN to MAC_ADDR_STR_LEN (Johannes Berg)
- Link to v2: https://lore.kernel.org/r/[email protected]
---
Uday Shankar (2):
net, treewide: define and use MAC_ADDR_STR_LEN
netconsole: allow selection of egress interface via MAC address
Documentation/networking/netconsole.rst | 6 +++- drivers/net/netconsole.c | 2 +- drivers/nvmem/brcm_nvram.c | 2 +- drivers/nvmem/layouts/u-boot-env.c | 2 +- include/linux/if_ether.h | 3 ++ include/linux/netpoll.h | 6 ++++ lib/net_utils.c | 4 +-- net/core/netpoll.c | 51 +++++++++++++++++++++++++-------- net/mac80211/debugfs_sta.c | 7 +++-- 9 files changed, 61 insertions(+), 22 deletions(-)
---
base-commit: 1340461e5168f8a33b2b3e0ed04557742664bee1
change-id: 20250204-netconsole-4c610e2f871c
Best regards,
Signature · 1 line
Uday Shankar <[email protected]>
PATCH v5 1/2 net, treewide: define and use MAC_ADDR_STR_LEN
There are a few places in the tree which compute the length of the string representation of a MAC address as 3 * ETH_ALEN - 1. Define a constant for this and use it where relevant. No functionality changes are expected.
--- drivers/net/netconsole.c | 2 +- drivers/nvmem/brcm_nvram.c | 2 +- drivers/nvmem/layouts/u-boot-env.c | 2 +- include/linux/if_ether.h | 3 +++ lib/net_utils.c | 4 +--- net/mac80211/debugfs_sta.c | 7 ++++--- 6 files changed, 11 insertions(+), 9 deletions(-)
drivers/net/netconsole.c +1 -1
@@ -721,7 +721,7 @@ static ssize_t remote_mac_store(struct config_item *item, const char *buf,if (!mac_pton (buf, remote_mac)) goto out_unlock; -if (buf[3 *ETH_ALEN -1 ] && buf[3 *ETH_ALEN -1 ] !='\n' ) +if (buf[MAC_ADDR_STR_LEN ] && buf[MAC_ADDR_STR_LEN ] !='\n' ) goto out_unlock;memcpy (nt->np.remote_mac, remote_mac,ETH_ALEN );
drivers/nvmem/brcm_nvram.c +1 -1
@@ -100,7 +100,7 @@ static int brcm_nvram_read_post_process_macaddr(void *context, const char *id, i {u8 mac[ETH_ALEN ]; -if (bytes !=3 *ETH_ALEN -1 ) +if (bytes !=MAC_ADDR_STR_LEN )return -EINVAL ;if (!mac_pton (buf, mac))
drivers/nvmem/layouts/u-boot-env.c +1 -1
@@ -37,7 +37,7 @@ static int u_boot_env_read_post_process_ethaddr(void *context, const char *id, i {u8 mac[ETH_ALEN ]; -if (bytes !=3 *ETH_ALEN -1 ) +if (bytes !=MAC_ADDR_STR_LEN )return -EINVAL ;if (!mac_pton (buf, mac))
include/linux/if_ether.h +3 -0
@@ -19,6 +19,9 @@#include <linux/skbuff.h> #include <uapi/linux/if_ether.h> +/* XX:XX:XX:XX:XX:XX */ +#define MAC_ADDR_STR_LEN (3 * ETH_ALEN - 1) +static inline struct ethhdr *eth_hdr (const struct sk_buff *skb) {return (struct ethhdr *)skb_mac_header (skb);
lib/net_utils.c +1 -3
@@ -7,11 +7,9 @@bool mac_pton (const char *s,u8 *mac) { -size_t maxlen =3 *ETH_ALEN -1 ;int i; -/* XX:XX:XX:XX:XX:XX */ -if (strnlen (s, maxlen) < maxlen) +if (strnlen (s,MAC_ADDR_STR_LEN ) <MAC_ADDR_STR_LEN )return false;/* Don't dirty result unless string is valid MAC. */
net/mac80211/debugfs_sta.c +4 -3
@@ -457,11 +457,12 @@ static ssize_t link_sta_addr_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { struct link_sta_info *link_sta = file->private_data; -u8 mac[3 *ETH_ALEN +1 ]; +u8 mac[MAC_ADDR_STR_LEN +2 ];snprintf (mac,sizeof (mac),"%pM\n" , link_sta->pub->addr); -return simple_read_from_buffer (userbuf, count, ppos, mac,3 *ETH_ALEN ); +return simple_read_from_buffer (userbuf, count, ppos, mac, +MAC_ADDR_STR_LEN +1 ); }LINK_STA_OPS (addr);
@@ -1240,7 +1241,7 @@ void ieee80211_sta_debugfs_add(struct sta_info *sta)struct ieee80211_local *local = sta->local;struct ieee80211_sub_if_data *sdata = sta->sdata;struct dentry *stations_dir = sta->sdata->debugfs.subdir_stations; -u8 mac[3 *ETH_ALEN ]; +u8 mac[MAC_ADDR_STR_LEN +1 ];if (!stations_dir)return ;
Signature · 1 line
2.34.1
Breno Leitao
maintainerRe: [PATCH net-next v5 1/2] net, treewide: define and use MAC_ADDR_STR_LEN
Quoted 8 lines · Uday Shankar
There are a few places in the tree which compute the length of the string representation of a MAC address as 3 *
ETH_ALEN- 1. Define a constant for this and use it where relevant. No functionality changes are expected.Signed-off-by Uday Shankar <[email protected]>Reviewed-by Michal Swiatkowski <[email protected]>Acked-by Johannes Berg <[email protected]>
Re: [PATCH net-next v5 1/2] net, treewide: define and use MAC_ADDR_STR_LEN
In reply to Uday ShankarQuoted 4 lines · On Thu, 20 Feb 2025 18:29:20 -0700 Uday Shankar <[email protected]>…
There are a few places in the tree which compute the length of the string representation of a MAC address as 3 *
ETH_ALEN- 1. Define a constant for this and use it where relevant. No functionality changes are expected.
The fact that you have to keep adding 1 or 2 is a good indication that it really isn't a good idea.
David
Quoted 112 lines
Signed-off-by Uday Shankar <[email protected]>Reviewed-by Michal Swiatkowski <[email protected]>Acked-by Johannes Berg <[email protected]>--- drivers/net/netconsole.c | 2 +- drivers/nvmem/brcm_nvram.c | 2 +- drivers/nvmem/layouts/u-boot-env.c | 2 +- include/linux/if_ether.h | 3 +++ lib/net_utils.c | 4 +--- net/mac80211/debugfs_sta.c | 7 ++++--- 6 files changed, 11 insertions(+), 9 deletions(-)drivers/net/netconsole.c +1
-1@@ -721,7 +721,7 @@ static ssize_t remote_mac_store(struct config_item *item, const char *buf,if (!mac_pton (buf, remote_mac)) goto out_unlock; -if (buf[3 *ETH_ALEN -1 ] && buf[3 *ETH_ALEN -1 ] !='\n' ) +if (buf[MAC_ADDR_STR_LEN ] && buf[MAC_ADDR_STR_LEN ] !='\n' ) goto out_unlock;memcpy (nt->np.remote_mac, remote_mac,ETH_ALEN );drivers/nvmem/brcm_nvram.c +1
-1@@ -100,7 +100,7 @@ static int brcm_nvram_read_post_process_macaddr(void *context, const char *id, i {u8 mac[ETH_ALEN ]; -if (bytes !=3 *ETH_ALEN -1 ) +if (bytes !=MAC_ADDR_STR_LEN )return -EINVAL ;if (!mac_pton (buf, mac))drivers/nvmem/layouts/u-boot-env.c +1
-1@@ -37,7 +37,7 @@ static int u_boot_env_read_post_process_ethaddr(void *context, const char *id, i {u8 mac[ETH_ALEN ]; -if (bytes !=3 *ETH_ALEN -1 ) +if (bytes !=MAC_ADDR_STR_LEN )return -EINVAL ;if (!mac_pton (buf, mac))include/linux/if_ether.h +3
-0@@ -19,6 +19,9 @@#include <linux/skbuff.h> #include <uapi/linux/if_ether.h> +/* XX:XX:XX:XX:XX:XX */ +#define MAC_ADDR_STR_LEN (3 * ETH_ALEN - 1) +static inline struct ethhdr *eth_hdr (const struct sk_buff *skb) {return (struct ethhdr *)skb_mac_header (skb);lib/net_utils.c +1
-3@@ -7,11 +7,9 @@bool mac_pton (const char *s,u8 *mac) { -size_t maxlen =3 *ETH_ALEN -1 ;int i; -/* XX:XX:XX:XX:XX:XX */ -if (strnlen (s, maxlen) < maxlen) +if (strnlen (s,MAC_ADDR_STR_LEN ) <MAC_ADDR_STR_LEN )return false;/* Don't dirty result unless string is valid MAC. */ net/mac80211/debugfs_sta.c +4
-3@@ -457,11 +457,12 @@ static ssize_t link_sta_addr_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { struct link_sta_info *link_sta = file->private_data; -u8 mac[3 *ETH_ALEN +1 ]; +u8 mac[MAC_ADDR_STR_LEN +2 ];snprintf (mac,sizeof (mac),"%pM\n" , link_sta->pub->addr); -return simple_read_from_buffer (userbuf, count, ppos, mac,3 *ETH_ALEN ); +return simple_read_from_buffer (userbuf, count, ppos, mac, +MAC_ADDR_STR_LEN +1 ); }LINK_STA_OPS (addr);@@ -1240,7 +1241,7 @@ void ieee80211_sta_debugfs_add(struct sta_info *sta)struct ieee80211_local *local = sta->local;struct ieee80211_sub_if_data *sdata = sta->sdata;struct dentry *stations_dir = sta->sdata->debugfs.subdir_stations; -u8 mac[3 *ETH_ALEN ]; +u8 mac[MAC_ADDR_STR_LEN +1 ];if (!stations_dir)return ;
Re: [PATCH net-next v5 1/2] net, treewide: define and use MAC_ADDR_STR_LEN
Quoted 2 lines · David Laight
The fact that you have to keep adding 1 or 2 is a good indication that it really isn't a good idea.
Having to adjust by 1 when converting between string lengths and buffer sizes is super standard in C since strings are NUL-terminated. There are tons of preexisting examples in the tree.
I agree that the + 2 is a bit of an eyesore but its needed in that case because that code wants to tack on a newline in addition to a NUL-terminator. Maybe adding a comment there would help?
In any case, MAC_ADDR_STR_LEN is a much more descriptive name for what all the changed code is actually doing compared against 3 * ETH_ALEN - 1.
Re: [PATCH net-next v5 1/2] net, treewide: define and use MAC_ADDR_STR_LEN
In reply to Uday ShankarQuoted 8 lines · Uday Shankar
There are a few places in the tree which compute the length of the string representation of a MAC address as 3 *
ETH_ALEN- 1. Define a constant for this and use it where relevant. No functionality changes are expected.Signed-off-by Uday Shankar <[email protected]>Reviewed-by Michal Swiatkowski <[email protected]>Acked-by Johannes Berg <[email protected]>
PATCH v5 2/2 netconsole: allow selection of egress interface via MAC address
In reply to Uday ShankarCurrently, netconsole has two methods of configuration - module parameter and configfs. The former interface allows for netconsole activation earlier during boot (by specifying the module parameter on the kernel command line), so it is preferred for debugging issues which arise before userspace is up/the configfs interface can be used. The module parameter syntax requires specifying the egress interface name. This requirement makes it hard to use for a couple reasons:
- The egress interface name can be hard or impossible to predict. For example, installing a new network card in a system can change the interface names assigned by the kernel.
- When constructing the module parameter, one may have trouble determining the original (kernel-assigned) name of the interface (which is the name that should be given to netconsole) if some stable interface naming scheme is in effect. A human can usually look at kernel logs to determine the original name, but this is very painful if automation is constructing the parameter.
For these reasons, allow selection of the egress interface via MAC address when configuring netconsole using the module parameter. Update the netconsole documentation with an example of the new syntax. Selection of egress interface by MAC address via configfs is far less interesting (since when this interface can be used, one should be able to easily convert between MAC address and interface name), so it is left unimplemented.
--- Documentation/networking/netconsole.rst | 6 +++- include/linux/netpoll.h | 6 ++++ net/core/netpoll.c | 51 +++++++++++++++++++++++++-------- 3 files changed, 50 insertions(+), 13 deletions(-)
Documentation/networking/netconsole.rst +5 -1
@@ -47,7 +47,7 @@ following format:: r if present, prepend kernel version (release) to the message src-port source for UDP packets (defaults to 6665) src-ip source IP to use (interface address) - dev network interface (eth0) + dev network interface name (eth0) or MAC address tgt-port port for logging agent (6666) tgt-ip IP address for logging agent tgt-macaddr ethernet MAC address for logging agent (broadcast)
@@ -64,6 +64,10 @@ or using IPv6:: insmod netconsole netconsole=@/,@fd00:1:2:3::1/ +or using a MAC address to select the egress interface:: + + linux [email protected]/22:33:44:55:66:77,[email protected]/12:34:56:78:9a:bc + It also supports logging to multiple remote agents by specifying parameters for the multiple agents separated by semicolons and the complete string enclosed in "quotes", thusly::
include/linux/netpoll.h +6 -0
@@ -25,7 +25,13 @@ union inet_addr {struct netpoll {struct net_device *dev;netdevice_tracker dev_tracker; +/* +* Either dev_name or dev_mac can be used to specify the local +* interface - dev_name is used if it is a nonempty string, else +* dev_mac is used. +*/ char dev_name[IFNAMSIZ ]; +u8 dev_mac[ETH_ALEN ];const char *name;union inet_addr local_ip, remote_ip;
net/core/netpoll.c +39 -12
111 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 25 lines · Uday Shankar
Currently, netconsole has two methods of configuration - module parameter and configfs. The former interface allows for netconsole activation earlier during boot (by specifying the module parameter on the kernel command line), so it is preferred for debugging issues which arise before userspace is up/the configfs interface can be used. The module parameter syntax requires specifying the egress interface name. This requirement makes it hard to use for a couple reasons:
- The egress interface name can be hard or impossible to predict. For example, installing a new network card in a system can change the interface names assigned by the kernel.
- When constructing the module parameter, one may have trouble determining the original (kernel-assigned) name of the interface (which is the name that should be given to netconsole) if some stable interface naming scheme is in effect. A human can usually look at kernel logs to determine the original name, but this is very painful if automation is constructing the parameter.For these reasons, allow selection of the egress interface via MAC address when configuring netconsole using the module parameter. Update the netconsole documentation with an example of the new syntax. Selection of egress interface by MAC address via configfs is far less interesting (since when this interface can be used, one should be able to easily convert between MAC address and interface name), so it is left unimplemented.
Quoted 3 lines
Signed-off-by Uday Shankar <[email protected]>Reviewed-by Breno Leitao <[email protected]>Tested-by Breno Leitao <[email protected]>
Quoted 1 line · Simon Horman
Reviewed-by Simon Horman <[email protected]>
Hey, since this has gotten quiet for a while, just wanted to confirm that there's no action needed from my end? Is this in the queue for net-next?
Simon Horman
reviewerQuoted 6 lines · Uday Shankar
Quoted 1 line · Simon Horman
Reviewed-by Simon Horman <[email protected]>Hey, since this has gotten quiet for a while, just wanted to confirm that there's no action needed from my end? Is this in the queue for net-next?
Hi Uday,
It seems that this series has been marked as Changes Requested in patchwork, which may explain the lack of progress. But that designation doesn't seem correct to me. So let's see if this can move this series back into the queue for the maintainers.
Signature · 1 line
pw-bot: under-review
Jakub Kicinski
maintainerQuoted 4 lines · On Tue, 11 Mar 2025 12:13:01 +0100 Simon Horman wrote:
Quoted 3 lines · Uday Shankar
Quoted 1 line · Simon Horman
Reviewed-by Simon Horman <[email protected]>
Quoted 8 lines
Quoted 3 lines
Hey, since this has gotten quiet for a while, just wanted to confirm that there's no action needed from my end? Is this in the queue for net-next?
It seems that this series has been marked as Changes Requested in patchwork, which may explain the lack of progress. But that designation doesn't seem correct to me. So let's see if this can move this series back into the queue for the maintainers.
Unclear why the designation was chosen, indeed, but let's get this reposted per normal process. The posting is a month old.
Quoted 9 lines · Jakub Kicinski
Quoted 8 lines · On Tue, 11 Mar 2025 12:13:01 +0100 Simon Horman wrote:
Quoted 6 lines · Uday Shankar
Quoted 1 line · Simon Horman
Reviewed-by Simon Horman <[email protected]>Hey, since this has gotten quiet for a while, just wanted to confirm that there's no action needed from my end? Is this in the queue for net-next?
Quoted 7 lines
Quoted 4 lines
It seems that this series has been marked as Changes Requested in patchwork, which may explain the lack of progress. But that designation doesn't seem correct to me. So let's see if this can move this series back into the queue for the maintainers.
Unclear why the designation was chosen, indeed, but let's get this reposted per normal process. The posting is a month old.
Sounds good, I've posted a v6 which is listed at
https://patchwork.kernel.org/project/netdevbpf/list/?series=943246 as "new" even though it has several reviews from maintainers. Anything else for me to do?