From patchwork Fri Nov 21 21:46:59 2008 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: stephen hemminger X-Patchwork-Id: 10134 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id 3731FDDE08 for ; Sat, 22 Nov 2008 08:47:12 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752786AbYKUVrH (ORCPT ); Fri, 21 Nov 2008 16:47:07 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752482AbYKUVrF (ORCPT ); Fri, 21 Nov 2008 16:47:05 -0500 Received: from mail.vyatta.com ([76.74.103.46]:36680 "EHLO mail.vyatta.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752675AbYKUVrE (ORCPT ); Fri, 21 Nov 2008 16:47:04 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.vyatta.com (Postfix) with ESMTP id 3569E4F4228 for ; Fri, 21 Nov 2008 13:47:04 -0800 (PST) X-Virus-Scanned: amavisd-new at X-Spam-Flag: NO X-Spam-Score: -1.279 X-Spam-Level: X-Spam-Status: No, score=-1.279 tagged_above=-10 required=3 tests=[AWL=-0.562, BAYES_00=-2.599, RCVD_IN_PBL=0.905, RCVD_IN_SORBS_DUL=0.877, RDNS_NONE=0.1] Received: from mail.vyatta.com ([127.0.0.1]) by localhost (mail.vyatta.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oHNuWaLykKai for ; Fri, 21 Nov 2008 13:47:02 -0800 (PST) Received: from extreme (unknown [96.225.231.79]) by mail.vyatta.com (Postfix) with ESMTP id 002744F4226 for ; Fri, 21 Nov 2008 13:47:01 -0800 (PST) Date: Fri, 21 Nov 2008 13:46:59 -0800 From: Stephen Hemminger To: netdev@vger.kernel.org Subject: [RFC] network devices generating uevents? Message-ID: <20081121134659.5b305b5c@extreme> Organization: Vyatta X-Mailer: Claws Mail 3.3.1 (GTK+ 2.12.9; x86_64-pc-linux-gnu) Mime-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Perhaps the following would make it easier for applications to track network device events without having to use netlink. Compile tested only so far. The implementation is almost trivial... --- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- a/net/core/Makefile 2008-11-21 12:25:31.000000000 -0800 +++ b/net/core/Makefile 2008-11-21 13:32:30.000000000 -0800 @@ -17,3 +17,4 @@ obj-$(CONFIG_NET_PKTGEN) += pktgen.o obj-$(CONFIG_NETPOLL) += netpoll.o obj-$(CONFIG_NET_DMA) += user_dma.o obj-$(CONFIG_FIB_RULES) += fib_rules.o +obj-$(CONFIG_HOTPLUG) += uevent.o --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ b/net/core/uevent.c 2008-11-21 13:42:13.000000000 -0800 @@ -0,0 +1,45 @@ +/* + * Linux network device event notification + * + * Author: + * Stephen Hemminger + */ + +#include +#include +#include +#include + +static int netdev_event(struct notifier_block *this, unsigned long event, void *ptr) +{ + struct net_device *netdev = ptr; + + switch (event) { + case NETDEV_UNREGISTER: + kobject_uevent(&netdev->dev.kobj, KOBJ_REMOVE); + break; + case NETDEV_REGISTER: + kobject_uevent(&netdev->dev.kobj, KOBJ_ADD); + break; + case NETDEV_UP: + kobject_uevent(&netdev->dev.kobj, KOBJ_ONLINE); + break; + case NETDEV_DOWN: + kobject_uevent(&netdev->dev.kobj, KOBJ_OFFLINE); + break; + case NETDEV_CHANGE: + kobject_uevent(&netdev->dev.kobj, KOBJ_CHANGE); + break; + } + return NOTIFY_DONE; +} + +static struct notifier_block netdev_uevent_notifier = { + .notifier_call = netdev_event, +}; + +static int __init netdev_uevent_init(void) +{ + return register_netdevice_notifier(&netdev_uevent_notifier); +} +device_initcall(netdev_uevent_init);