From patchwork Wed Sep 9 10:00:05 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?R=C3=A9mi_Denis-Courmont?= X-Patchwork-Id: 33172 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@bilbo.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (ozlabs.org [203.10.76.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mx.ozlabs.org", Issuer "CA Cert Signing Authority" (verified OK)) by bilbo.ozlabs.org (Postfix) with ESMTPS id E1C65B7079 for ; Wed, 9 Sep 2009 20:10:59 +1000 (EST) Received: by ozlabs.org (Postfix) id C1C8EDDD0C; Wed, 9 Sep 2009 20:10:59 +1000 (EST) 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 15816DDD04 for ; Wed, 9 Sep 2009 20:10:59 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752110AbZIIKKt (ORCPT ); Wed, 9 Sep 2009 06:10:49 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752060AbZIIKKt (ORCPT ); Wed, 9 Sep 2009 06:10:49 -0400 Received: from yop.chewa.net ([91.121.105.214]:45983 "EHLO yop.chewa.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752035AbZIIKKt (ORCPT ); Wed, 9 Sep 2009 06:10:49 -0400 Received: by yop.chewa.net (Postfix, from userid 1007) id 6C5DB390; Wed, 9 Sep 2009 12:00:06 +0200 (CEST) From: =?utf-8?q?R=C3=A9mi=20Denis-Courmont?= To: netdev@vger.kernel.org Cc: =?utf-8?q?R=C3=A9mi=20Denis-Courmont?= Subject: [PATCH 1/2] Phonet: back-end for autoconfigured addresses Date: Wed, 9 Sep 2009 13:00:05 +0300 Message-Id: <1252490406-27951-1-git-send-email-remi@remlab.net> X-Mailer: git-send-email 1.5.6.5 MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Rémi Denis-Courmont In some cases, the network device driver knows what layer-3 address the device should have. This adds support for the Phonet stack to automatically request from the driver and add that address to the network device. Signed-off-by: Rémi Denis-Courmont --- include/linux/phonet.h | 17 +++++++++++++++++ net/phonet/pn_dev.c | 26 +++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletions(-) diff --git a/include/linux/phonet.h b/include/linux/phonet.h index ee5e3c9..82b45d1 100644 --- a/include/linux/phonet.h +++ b/include/linux/phonet.h @@ -170,4 +170,21 @@ static inline __u8 pn_sockaddr_get_resource(const struct sockaddr_pn *spn) return spn->spn_resource; } +/* Phonet device ioctl requests */ +#ifdef __KERNEL__ +#define SIOCPNGAUTOCONF (SIOCDEVPRIVATE + 0) + +struct if_phonet_autoconf { + uint8_t device; +}; + +struct if_phonet_req { + char ifr_phonet_name[16]; + union { + struct if_phonet_autoconf ifru_phonet_autoconf; + } ifr_ifru; +}; +#define ifr_phonet_autoconf ifr_ifru.ifru_phonet_autoconf +#endif /* __KERNEL__ */ + #endif diff --git a/net/phonet/pn_dev.c b/net/phonet/pn_dev.c index 5ae4c01..2f65dca 100644 --- a/net/phonet/pn_dev.c +++ b/net/phonet/pn_dev.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -195,14 +196,37 @@ found: return err; } +/* automatically configure a Phonet device, if supported */ +static int phonet_device_autoconf(struct net_device *dev) +{ + struct if_phonet_req req; + int ret; + + if (!dev->netdev_ops->ndo_do_ioctl) + return -EOPNOTSUPP; + + ret = dev->netdev_ops->ndo_do_ioctl(dev, (struct ifreq *)&req, + SIOCPNGAUTOCONF); + if (ret < 0) + return ret; + return phonet_address_add(dev, req.ifr_phonet_autoconf.device); +} + /* notify Phonet of device events */ static int phonet_device_notify(struct notifier_block *me, unsigned long what, void *arg) { struct net_device *dev = arg; - if (what == NETDEV_UNREGISTER) + switch (what) { + case NETDEV_REGISTER: + if (dev->type == ARPHRD_PHONET) + phonet_device_autoconf(dev); + break; + case NETDEV_UNREGISTER: phonet_device_destroy(dev); + break; + } return 0; }