From patchwork Fri Jul 3 12:58:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Khlebnikov X-Patchwork-Id: 491047 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.180.67]) by ozlabs.org (Postfix) with ESMTP id 5A01C140777 for ; Fri, 3 Jul 2015 22:58:55 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=yandex-team.ru header.i=@yandex-team.ru header.b=rZUxOVI0; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753434AbbGCM6v (ORCPT ); Fri, 3 Jul 2015 08:58:51 -0400 Received: from forward-corp1g.mail.yandex.net ([95.108.253.251]:59525 "EHLO forward-corp1g.mail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755181AbbGCM6p (ORCPT ); Fri, 3 Jul 2015 08:58:45 -0400 Received: from smtpcorp1m.mail.yandex.net (smtpcorp1m.mail.yandex.net [77.88.61.150]) by forward-corp1g.mail.yandex.net (Yandex) with ESMTP id 1EFF536607D4; Fri, 3 Jul 2015 15:58:42 +0300 (MSK) Received: from smtpcorp1m.mail.yandex.net (localhost [127.0.0.1]) by smtpcorp1m.mail.yandex.net (Yandex) with ESMTP id 0194A2CA0587; Fri, 3 Jul 2015 15:58:42 +0300 (MSK) Received: from unknown (unknown [2a02:6b8:0:408:40d2:8ae4:e9f:4635]) by smtpcorp1m.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 6TMFMotfcu-wfnGG6uG; Fri, 3 Jul 2015 15:58:41 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1435928322; bh=bE7R/aDrzXuuuogB2Jv9oqSNWIn3Us+30NqIK99J2hw=; h=Subject:From:To:Cc:Date:Message-ID:In-Reply-To:References: User-Agent:MIME-Version:Content-Type:Content-Transfer-Encoding; b=rZUxOVI0nqIfwtBgmQCm1rkjDHRz3zvWF3HDscjV/+x0I29W3+tPOq5hFlCIwb7Nk dNzdD+VzsmdUvdMcWOg/GkHtGS+o9MtXpuc18+hLbOxfabVhIZiCWPFG04/eC6O2+x cqvPy1dj5EpMxB1SHn7Nqtgd91Kd+2FtwAzwa82s= Authentication-Results: smtpcorp1m.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Subject: [PATCH v2 5/5] ipvlan: set dev_id for l2 ports to generate unique IPv6 addresses From: Konstantin Khlebnikov To: netdev@vger.kernel.org, "David S. Miller" Cc: Mahesh Bandewar , Jiri Benc Date: Fri, 03 Jul 2015 15:58:41 +0300 Message-ID: <20150703125841.24121.73888.stgit@buzz> In-Reply-To: <20150703125132.24121.50592.stgit@buzz> References: <20150703125132.24121.50592.stgit@buzz> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org All ipvlan ports use one MAC address, this way ipv6 RA tries to assign one ipv6 address to all of them. This patch assigns unique dev_id to each ipvlan port. This field is used instead of common FF-FE in Modified EUI-64. Signed-off-by: Konstantin Khlebnikov --- Documentation/networking/ipvlan.txt | 11 ++++++++++- drivers/net/ipvlan/ipvlan.h | 1 + drivers/net/ipvlan/ipvlan_main.c | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) -- 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 diff --git a/Documentation/networking/ipvlan.txt b/Documentation/networking/ipvlan.txt index cf996394e466..d1123de81469 100644 --- a/Documentation/networking/ipvlan.txt +++ b/Documentation/networking/ipvlan.txt @@ -24,7 +24,7 @@ using IProute2/ip utility. ip link add link type ipvlan mode { l2 | L3 } - e.g. ip link add link ipvl0 eth0 type ipvlan mode l2 + e.g. ip link add link eth0 ipvl0 type ipvlan mode l2 4. Operating modes: @@ -41,6 +41,15 @@ slave device and packets are switched and queued to the master device to send out. In this mode the slaves will RX/TX multicast and broadcast (if applicable) as well. + In L2 mode slave devices receive Router Advertisements from the network +and perform autoconfiguration as well as master device. Each port has unique +16-bit device id which is used for filling octets 4-5 of Modified EUI-64. +That gives 65533 addresses (FF-FE used by master, FF-FF/00-00 reserved/not used). + + Also lower half of IPv6 address could be set as interface token: + + ip token set ::aaaa:bbbb:cccc:dddd dev ipvl0 + 4.2 L3 mode: In this mode TX processing upto L3 happens on the stack instance attached to the slave device and packets are switched to the stack instance of the diff --git a/drivers/net/ipvlan/ipvlan.h b/drivers/net/ipvlan/ipvlan.h index a23069aec4d9..0d1f5e8ed75f 100644 --- a/drivers/net/ipvlan/ipvlan.h +++ b/drivers/net/ipvlan/ipvlan.h @@ -98,6 +98,7 @@ struct ipvl_port { int count; u16 mode; spinlock_t addr_lock; + struct ida ida; }; static inline struct ipvl_port *ipvlan_port_get_rcu(const struct net_device *d) diff --git a/drivers/net/ipvlan/ipvlan_main.c b/drivers/net/ipvlan/ipvlan_main.c index 83a936f76248..d465b2c287cb 100644 --- a/drivers/net/ipvlan/ipvlan_main.c +++ b/drivers/net/ipvlan/ipvlan_main.c @@ -53,6 +53,7 @@ static int ipvlan_port_create(struct net_device *dev) INIT_LIST_HEAD(&port->ipvlans); for (idx = 0; idx < IPVLAN_HASH_SIZE; idx++) INIT_HLIST_HEAD(&port->hlhead[idx]); + ida_init(&port->ida); skb_queue_head_init(&port->backlog); INIT_WORK(&port->wq, ipvlan_process_multicast); @@ -78,6 +79,7 @@ static void ipvlan_port_destroy(struct net_device *dev) netdev_rx_handler_unregister(dev); cancel_work_sync(&port->wq); __skb_queue_purge(&port->backlog); + ida_destroy(&port->ida); kfree_rcu(port, rcu); } @@ -481,6 +483,18 @@ static int ipvlan_link_new(struct net *src_net, struct net_device *dev, */ memcpy(dev->dev_addr, phy_dev->dev_addr, ETH_ALEN); + if (port->mode == IPVLAN_MODE_L2) { + /* + * IPv6 addrconf uses it to produce unique addresses, + * see function addrconf_ifid_eui48. + */ + err = ida_simple_get(&port->ida, 1, 0xFFFE, GFP_KERNEL); + if (err > 0) + dev->dev_id = err; + else if (err != -ENOSPC) + goto ipvlan_destroy_port; + } + dev->priv_flags |= IFF_IPVLAN_SLAVE; port->count += 1; @@ -517,6 +531,11 @@ static void ipvlan_link_delete(struct net_device *dev, struct list_head *head) } ipvlan_addr_unlock_bh(ipvlan); + if (dev->dev_id) { + ida_simple_remove(&ipvlan->port->ida, dev->dev_id); + dev->dev_id = 0; + } + list_del_rcu(&ipvlan->pnode); unregister_netdevice_queue(dev, head); netdev_upper_dev_unlink(ipvlan->phy_dev, dev);