From patchwork Wed Jan 17 01:35:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaac Lee X-Patchwork-Id: 861974 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b="bu4VR1kQ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zLqRf5tJxz9ryk for ; Wed, 17 Jan 2018 12:35:58 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750846AbeAQBf4 (ORCPT ); Tue, 16 Jan 2018 20:35:56 -0500 Received: from gate2.alliedtelesis.co.nz ([202.36.163.20]:36120 "EHLO gate2.alliedtelesis.co.nz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750772AbeAQBfz (ORCPT ); Tue, 16 Jan 2018 20:35:55 -0500 Received: from mmarshal3.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id 728F08365B for ; Wed, 17 Jan 2018 14:35:52 +1300 (NZDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail; t=1516152952; bh=vwS8VQ6WdE+lrS/LMZc8tWM73barnTSleGWHbJ8r/b0=; h=From:To:Cc:Subject:Date; b=bu4VR1kQOUdWGMfHFpVh81qD7tGRi84xl3BD45Wun6Aq07TSz8tlQ0Ve5cCnIXBxD XTtz90sLNpI8wggAHvUCY3fz8KVzzWPBrgC2tnsn4rQXniwmXxs1VLvhTYED3kjNFi 3apQDH6c9VOe00kXOmfLB1+7mpTWT7QqiySGGvCA= Received: from smtp (Not Verified[10.32.16.33]) by mmarshal3.atlnz.lc with Trustwave SEG (v7, 5, 8, 10121) id ; Wed, 17 Jan 2018 14:35:52 +1300 Received: from isaacl-dl.ws.atlnz.lc (isaacl-dl.ws.atlnz.lc [10.33.11.25]) by smtp (Postfix) with ESMTP id 31B0F13ED4B; Wed, 17 Jan 2018 14:35:58 +1300 (NZDT) Received: by isaacl-dl.ws.atlnz.lc (Postfix, from userid 1431) id 50E62300682; Wed, 17 Jan 2018 14:35:52 +1300 (NZDT) From: Isaac Lee To: netdev@vger.kernel.org Cc: Isaac Lee Subject: [PATCH] net:l2tp: Allow MAC to be configured via netlink Date: Wed, 17 Jan 2018 14:35:37 +1300 Message-Id: <20180117013537.19895-1-isaac.lee@alliedtelesis.co.nz> X-Mailer: git-send-email 2.15.1 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The linux kernel by default uses random MAC address for l2tp interfaces. However, there are situations where it is desirable to have a deterministic MAC address. A sample scenario would be where the host IP stack is attached directly to a tunnel hence the "random" address is now propagated via ARP/ND to the other end of the tunnel. If the device reboots, a new MAC is used and the communication over the tunnel will be disrupted until the new MAC address is re-learned by the peer. Therefore it can be useful to have the mac address the same across reboots. The patch makes the MAC address to be configurable via netlink so that a userspace program can specify what MAC address to use at interface creation time in the kernel. Signed-off-by: Isaac Lee --- include/uapi/linux/l2tp.h | 1 + net/l2tp/l2tp_core.h | 1 + net/l2tp/l2tp_eth.c | 7 ++++++- net/l2tp/l2tp_netlink.c | 3 +++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/l2tp.h b/include/uapi/linux/l2tp.h index d84ce5c1c9aa..fec15fd774c4 100644 --- a/include/uapi/linux/l2tp.h +++ b/include/uapi/linux/l2tp.h @@ -126,6 +126,7 @@ enum { L2TP_ATTR_IP6_DADDR, /* struct in6_addr */ L2TP_ATTR_UDP_ZERO_CSUM6_TX, /* flag */ L2TP_ATTR_UDP_ZERO_CSUM6_RX, /* flag */ + L2TP_ATTR_HWADDR, /* 6 bytes */ L2TP_ATTR_PAD, __L2TP_ATTR_MAX, }; diff --git a/net/l2tp/l2tp_core.h b/net/l2tp/l2tp_core.h index 9534e16965cc..730021289ce5 100644 --- a/net/l2tp/l2tp_core.h +++ b/net/l2tp/l2tp_core.h @@ -71,6 +71,7 @@ struct l2tp_session_cfg { int mtu; int mru; char *ifname; + unsigned char hwaddr[ETH_ALEN]; }; struct l2tp_session { diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c index 5c366ecfa1cb..0e6ef5379b64 100644 --- a/net/l2tp/l2tp_eth.c +++ b/net/l2tp/l2tp_eth.c @@ -58,7 +58,9 @@ struct l2tp_eth_sess { static int l2tp_eth_dev_init(struct net_device *dev) { - eth_hw_addr_random(dev); + /* Use random MAC only when the interface is created without dev_addr */ + if (!dev->dev_addr || !is_valid_ether_addr(dev->dev_addr)) + eth_hw_addr_random(dev); eth_broadcast_addr(dev->broadcast); netdev_lockdep_set_classes(dev); @@ -309,6 +311,9 @@ static int l2tp_eth_create(struct net *net, struct l2tp_tunnel *tunnel, dev->max_mtu = ETH_MAX_MTU; l2tp_eth_adjust_mtu(tunnel, session, dev); + if (is_valid_ether_addr(cfg->hwaddr)) + ether_addr_copy(dev->dev_addr, cfg->hwaddr); + priv = netdev_priv(dev); priv->session = session; diff --git a/net/l2tp/l2tp_netlink.c b/net/l2tp/l2tp_netlink.c index a1f24fb2be98..dc2933c32121 100644 --- a/net/l2tp/l2tp_netlink.c +++ b/net/l2tp/l2tp_netlink.c @@ -607,6 +607,9 @@ static int l2tp_nl_cmd_session_create(struct sk_buff *skb, struct genl_info *inf if (info->attrs[L2TP_ATTR_MRU]) cfg.mru = nla_get_u16(info->attrs[L2TP_ATTR_MRU]); + if (info->attrs[L2TP_ATTR_HWADDR]) + memcpy(&cfg.hwaddr, nla_data(info->attrs[L2TP_ATTR_HWADDR]), ETH_ALEN); + #ifdef CONFIG_MODULES if (l2tp_nl_cmd_ops[cfg.pw_type] == NULL) { genl_unlock();