Skip to content

Commit 17951f3

Browse files
Satyam SharmaDavid S. Miller
authored andcommitted
[NET] netconsole: Introduce netconsole_netdev_notifier
Based upon initial work by Keiichi Kii <k-keiichi@bx.jp.nec.com>. To update fields of underlying netpoll structure at runtime on corresponding NETDEV_CHANGEADDR or NETDEV_CHANGENAME notifications. ioctl(SIOCSIFHWADDR or SIOCSIFNAME) could be used to change the hardware/MAC address or name of the local interface that our netpoll is attached to. Whenever this happens, netdev notifier chain is called out with the NETDEV_CHANGEADDR or NETDEV_CHANGENAME event message. We respond to that and update the local_mac or dev_name field of the struct netpoll. This makes sense anyway, but is especially required for dynamic netconsole because the netpoll structure's internal members become user visible files when either sysfs or configfs are used. So this helps us to keep up with the MAC address/name changes and keep values in struct netpoll uptodate. [ Note that ioctl(SIOCSIFADDR) to change IP address of interface at runtime is not handled (to update local_ip of netpoll) on purpose -- some setups may set the local_ip to a private address, not necessary the actual IP address of the sender host, as presently allowed. ] Signed-off-by: Satyam Sharma <satyam@infradead.org> Signed-off-by: Keiichi Kii <k-keiichi@bx.jp.nec.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent df180e3 commit 17951f3

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

‎drivers/net/netconsole.c‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,33 @@ static struct netconsole_target default_target = {
8080
},
8181
};
8282

83+
/* Handle network interface device notifications */
84+
static int netconsole_netdev_event(struct notifier_block *this,
85+
unsigned long event,
86+
void *ptr)
87+
{
88+
struct net_device *dev = ptr;
89+
struct netconsole_target *nt = &default_target;
90+
91+
if (nt->np.dev == dev) {
92+
switch (event) {
93+
case NETDEV_CHANGEADDR:
94+
memcpy(nt->np.local_mac, dev->dev_addr, ETH_ALEN);
95+
break;
96+
97+
case NETDEV_CHANGENAME:
98+
strlcpy(nt->np.dev_name, dev->name, IFNAMSIZ);
99+
break;
100+
}
101+
}
102+
103+
return NOTIFY_DONE;
104+
}
105+
106+
static struct notifier_block netconsole_netdev_notifier = {
107+
.notifier_call = netconsole_netdev_event,
108+
};
109+
83110
static void write_msg(struct console *con, const char *msg, unsigned int len)
84111
{
85112
int frag, left;
@@ -122,6 +149,10 @@ static int __init init_netconsole(void)
122149
if (err)
123150
goto out;
124151

152+
err = register_netdevice_notifier(&netconsole_netdev_notifier);
153+
if (err)
154+
goto out;
155+
125156
register_console(&netconsole);
126157
printk(KERN_INFO "netconsole: network logging started\n");
127158

@@ -134,6 +165,7 @@ static void __exit cleanup_netconsole(void)
134165
struct netconsole_target *nt = &default_target;
135166

136167
unregister_console(&netconsole);
168+
unregister_netdevice_notifier(&netconsole_netdev_notifier);
137169
netpoll_cleanup(&nt->np);
138170
}
139171

0 commit comments

Comments
 (0)