Netdev List
 help / color / mirror / Atom feed
From: Stephen Hemminger <shemminger@vyatta.com>
To: Herbert Xu <herbert@gondor.apana.org.au>,
	David Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org
Subject: [PATCH] gre: propagate state of link back go to tunnel
Date: Mon, 19 Mar 2012 16:58:43 -0700	[thread overview]
Message-ID: <20120319165843.7b18412a@nehalam.linuxnetplumber.net> (raw)

GRE tunnels like other layered devices should propagate
carrier and RFC2863 state from lower device to tunnel.
Based on similar code in vlan device driver.
By using operstate it is possible for user mode to create tunnel
and use stepped outlined in Documentation/networking/operstate.txt
to control carrier.

Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>

---
Not urgent, can wait if the release window is already over the
queue limit

--- a/net/ipv4/ip_gre.c	2012-03-19 16:09:46.662376422 -0700
+++ b/net/ipv4/ip_gre.c	2012-03-19 16:13:49.845108466 -0700
@@ -961,6 +961,7 @@ static int ipgre_tunnel_bind_dev(struct
 	if (tdev) {
 		hlen = tdev->hard_header_len + tdev->needed_headroom;
 		mtu = tdev->mtu;
+		netif_stacked_transfer_operstate(tdev, dev);
 	}
 	dev->iflink = tunnel->parms.link;
 
@@ -1545,6 +1546,7 @@ static int ipgre_newlink(struct net *src
 
 	dev_hold(dev);
 	ipgre_tunnel_link(ign, nt);
+	linkwatch_fire_event(dev); /* _MUST_ call rfc2863_policy() */
 
 out:
 	return err;
@@ -1701,6 +1703,34 @@ static struct rtnl_link_ops ipgre_tap_op
 	.fill_info	= ipgre_fill_info,
 };
 
+/* If lower device changes state, reflect that to the tunnel. */
+static int ipgre_notify(struct notifier_block *unused,
+			unsigned long event, void *ptr)
+{
+	struct net_device *dev = ptr;
+	struct net *net = dev_net(dev);
+	struct ipgre_net *ign = net_generic(net, ipgre_net_id);
+	unsigned int i, h;
+	struct ip_tunnel *t;
+
+	if (event == NETDEV_CHANGE)
+		return NOTIFY_DONE;
+
+	for (i = 0; i < 4; i++)
+		for (h = 0; h < HASH_SIZE; h++)
+			for(t = ign->tunnels[i][h]; t; t = t->next) {
+				if (dev->ifindex != t->dev->iflink)
+					continue;
+				netif_stacked_transfer_operstate(dev, t->dev);
+			}
+
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block ipgre_notifier = {
+	.notifier_call = ipgre_notify,
+};
+
 /*
  *	And now the modules code and kernel interface.
  */
@@ -1729,9 +1759,15 @@ static int __init ipgre_init(void)
 	if (err < 0)
 		goto tap_ops_failed;
 
+	err = register_netdevice_notifier(&ipgre_notifier);
+	if (err < 0)
+		goto notify_failed;
+
 out:
 	return err;
 
+notify_failed:
+	rtnl_link_unregister(&ipgre_tap_ops);
 tap_ops_failed:
 	rtnl_link_unregister(&ipgre_link_ops);
 rtnl_link_failed:
@@ -1743,6 +1779,7 @@ add_proto_failed:
 
 static void __exit ipgre_fini(void)
 {
+	unregister_netdevice_notifier(&ipgre_notifier);
 	rtnl_link_unregister(&ipgre_tap_ops);
 	rtnl_link_unregister(&ipgre_link_ops);
 	if (gre_del_protocol(&ipgre_protocol, GREPROTO_CISCO) < 0)

             reply	other threads:[~2012-03-19 23:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-19 23:58 Stephen Hemminger [this message]
2012-03-22  2:18 ` [PATCH] gre: propagate state of link back go to tunnel David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120319165843.7b18412a@nehalam.linuxnetplumber.net \
    --to=shemminger@vyatta.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox