From: Satyam Sharma Date: Fri, 10 Aug 2007 22:33:01 +0000 (-0700) Subject: [NET] netconsole: Introduce netconsole_netdev_notifier X-Git-Tag: upstream/snapshot3+hdmi~30758^2~806 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=17951f34b0970b05e29fd93a5b93fa05ec71308b;p=platform%2Fadaptation%2Frenesas_rcar%2Frenesas_kernel.git [NET] netconsole: Introduce netconsole_netdev_notifier Based upon initial work by Keiichi Kii . 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 Signed-off-by: Keiichi Kii Signed-off-by: Andrew Morton Signed-off-by: David S. Miller --- diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index be15ca6..5557098 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -80,6 +80,33 @@ static struct netconsole_target default_target = { }, }; +/* Handle network interface device notifications */ +static int netconsole_netdev_event(struct notifier_block *this, + unsigned long event, + void *ptr) +{ + struct net_device *dev = ptr; + struct netconsole_target *nt = &default_target; + + if (nt->np.dev == dev) { + switch (event) { + case NETDEV_CHANGEADDR: + memcpy(nt->np.local_mac, dev->dev_addr, ETH_ALEN); + break; + + case NETDEV_CHANGENAME: + strlcpy(nt->np.dev_name, dev->name, IFNAMSIZ); + break; + } + } + + return NOTIFY_DONE; +} + +static struct notifier_block netconsole_netdev_notifier = { + .notifier_call = netconsole_netdev_event, +}; + static void write_msg(struct console *con, const char *msg, unsigned int len) { int frag, left; @@ -122,6 +149,10 @@ static int __init init_netconsole(void) if (err) goto out; + err = register_netdevice_notifier(&netconsole_netdev_notifier); + if (err) + goto out; + register_console(&netconsole); printk(KERN_INFO "netconsole: network logging started\n"); @@ -134,6 +165,7 @@ static void __exit cleanup_netconsole(void) struct netconsole_target *nt = &default_target; unregister_console(&netconsole); + unregister_netdevice_notifier(&netconsole_netdev_notifier); netpoll_cleanup(&nt->np); }