netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, Nicolas Dichtel <nicolas.dichtel@6wind.com>
Subject: [RFC PATCH net-next v2 2/5] rtnl/ipv6: use netconf msg to advertise forwarding status
Date: Wed, 24 Oct 2012 18:02:56 +0200	[thread overview]
Message-ID: <1351094579-3911-3-git-send-email-nicolas.dichtel@6wind.com> (raw)
In-Reply-To: <1351094579-3911-1-git-send-email-nicolas.dichtel@6wind.com>

Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
 include/uapi/linux/rtnetlink.h |  2 ++
 net/ipv6/addrconf.c            | 77 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 79 insertions(+)

diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
index 0043b41..a4d75ea 100644
--- a/include/uapi/linux/rtnetlink.h
+++ b/include/uapi/linux/rtnetlink.h
@@ -592,6 +592,8 @@ enum rtnetlink_groups {
 #define RTNLGRP_PHONET_ROUTE	RTNLGRP_PHONET_ROUTE
 	RTNLGRP_DCB,
 #define RTNLGRP_DCB		RTNLGRP_DCB
+	RTNLGRP_IPV6_NETCONF,
+#define RTNLGRP_IPV6_NETCONF	RTNLGRP_IPV6_NETCONF
 	__RTNLGRP_MAX
 };
 #define RTNLGRP_MAX	(__RTNLGRP_MAX - 1)
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 0424e4e..9bf4d1b 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -81,6 +81,7 @@
 #include <net/pkt_sched.h>
 #include <linux/if_tunnel.h>
 #include <linux/rtnetlink.h>
+#include <linux/netconf.h>
 
 #ifdef CONFIG_IPV6_PRIVACY
 #include <linux/random.h>
@@ -460,6 +461,72 @@ static struct inet6_dev *ipv6_find_idev(struct net_device *dev)
 	return idev;
 }
 
+static inline int inet6_netconf_msgsize_devconf(int type)
+{
+	int size =  NLMSG_ALIGN(sizeof(struct netconfmsg))
+		    + nla_total_size(4);	/* NETCONFA_IFINDEX */
+
+	if (type == NETCONFA_FORWARDING)
+		size += nla_total_size(4);
+
+	return size;
+}
+
+static int inet6_netconf_fill_devconf(struct sk_buff *skb, int ifindex,
+				      struct ipv6_devconf *devconf, u32 portid,
+				      u32 seq, int event, unsigned int flags,
+				      int type)
+{
+	struct nlmsghdr  *nlh;
+	struct netconfmsg *ncm;
+
+	nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct netconfmsg),
+			flags);
+	if (nlh == NULL)
+		return -EMSGSIZE;
+
+	ncm = nlmsg_data(nlh);
+	ncm->ncm_family = AF_INET6;
+
+	if (nla_put_s32(skb, NETCONFA_IFINDEX, ifindex) < 0)
+		goto nla_put_failure;
+
+	if (type == NETCONFA_FORWARDING &&
+	    nla_put_s32(skb, NETCONFA_FORWARDING, devconf->forwarding) < 0)
+		goto nla_put_failure;
+
+	return nlmsg_end(skb, nlh);
+
+nla_put_failure:
+	nlmsg_cancel(skb, nlh);
+	return -EMSGSIZE;
+}
+
+static void inet6_netconf_notify_devconf(struct net *net, int type, int ifindex,
+					 struct ipv6_devconf *devconf)
+{
+	struct sk_buff *skb;
+	int err = -ENOBUFS;
+
+	skb = nlmsg_new(inet6_netconf_msgsize_devconf(type), GFP_ATOMIC);
+	if (skb == NULL)
+		goto errout;
+
+	err = inet6_netconf_fill_devconf(skb, ifindex, devconf, 0, 0,
+					 RTM_NEWNETCONF, 0, type);
+	if (err < 0) {
+		/* -EMSGSIZE implies BUG in inet6_netconf_msgsize_devconf() */
+		WARN_ON(err == -EMSGSIZE);
+		kfree_skb(skb);
+		goto errout;
+	}
+	rtnl_notify(skb, net, 0, RTNLGRP_IPV6_NETCONF, NULL, GFP_ATOMIC);
+	return;
+errout:
+	if (err < 0)
+		rtnl_set_sk_err(net, RTNLGRP_IPV6_NETCONF, err);
+}
+
 #ifdef CONFIG_SYSCTL
 static void dev_forward_change(struct inet6_dev *idev)
 {
@@ -486,6 +553,8 @@ static void dev_forward_change(struct inet6_dev *idev)
 		else
 			addrconf_leave_anycast(ifa);
 	}
+	inet6_netconf_notify_devconf(dev_net(dev), NETCONFA_FORWARDING,
+				     dev->ifindex, &idev->cnf);
 }
 
 
@@ -518,6 +587,10 @@ static int addrconf_fixup_forwarding(struct ctl_table *table, int *p, int newf)
 	*p = newf;
 
 	if (p == &net->ipv6.devconf_dflt->forwarding) {
+		if ((!newf) ^ (!old))
+			inet6_netconf_notify_devconf(net, NETCONFA_FORWARDING,
+						     NETCONFA_IFINDEX_DEFAULT,
+						     net->ipv6.devconf_dflt);
 		rtnl_unlock();
 		return 0;
 	}
@@ -525,6 +598,10 @@ static int addrconf_fixup_forwarding(struct ctl_table *table, int *p, int newf)
 	if (p == &net->ipv6.devconf_all->forwarding) {
 		net->ipv6.devconf_dflt->forwarding = newf;
 		addrconf_forward_change(net, newf);
+		if ((!newf) ^ (!old))
+			inet6_netconf_notify_devconf(net, NETCONFA_FORWARDING,
+						     NETCONFA_IFINDEX_ALL,
+						     net->ipv6.devconf_all);
 	} else if ((!newf) ^ (!old))
 		dev_forward_change((struct inet6_dev *)table->extra1);
 	rtnl_unlock();
-- 
1.7.12

  parent reply	other threads:[~2012-10-24 15:54 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-23  9:49 [RFC PATCH net-next 0/1] Allow to monitor protocol configuration Nicolas Dichtel
2012-10-23  9:49 ` [RFC PATCH net-next 1/3] rtnl: add a new type of msg to advertise " Nicolas Dichtel
2012-10-23  9:49 ` [RFC PATCH net-next 2/3] rtnl/ipv6: use netconf msg to advertise forwarding status Nicolas Dichtel
2012-10-23 17:29   ` David Miller
2012-10-24 16:02     ` [RFC PATCH net-next v2 0/5] Allow to monitor protocol configuration Nicolas Dichtel
2012-10-24 16:02       ` [RFC PATCH net-next v2 1/5] rtnl: add a new type of msg to advertise " Nicolas Dichtel
2012-10-24 16:02       ` Nicolas Dichtel [this message]
2012-10-26  6:18         ` [RFC PATCH net-next v2 2/5] rtnl/ipv6: use netconf msg to advertise forwarding status David Miller
2012-10-26  8:28           ` [PATCH net-next v3 0/5] Allow to monitor protocol configuration Nicolas Dichtel
2012-10-26  8:28             ` [PATCH net-next v3 1/5] rtnl: add a new type of msg to advertise " Nicolas Dichtel
2012-10-26  8:28             ` [PATCH net-next v3 2/5] rtnl/ipv6: use netconf msg to advertise forwarding status Nicolas Dichtel
2012-10-26  8:28             ` [PATCH net-next v3 3/5] rtnl/ipv6: add support of RTM_GETNETCONF Nicolas Dichtel
2012-10-26  8:28             ` [PATCH net-next v3 4/5] rtnl/ipv4: use netconf msg to advertise forwarding status Nicolas Dichtel
2012-10-26  8:28             ` [PATCH net-next v3 5/5] rtnl/ipv4: add support of RTM_GETNETCONF Nicolas Dichtel
2012-10-28 23:05             ` [PATCH net-next v3 0/5] Allow to monitor protocol configuration David Miller
2012-10-26  9:03           ` [RFC PATCH net-next v2 2/5] rtnl/ipv6: use netconf msg to advertise forwarding status David Laight
2012-10-26  9:17             ` David Miller
2012-10-24 16:02       ` [RFC PATCH net-next v2 3/5] rtnl/ipv6: add support of RTM_GETNETCONF Nicolas Dichtel
2012-10-24 16:02       ` [RFC PATCH net-next v2 4/5] rtnl/ipv4: use netconf msg to advertise forwarding status Nicolas Dichtel
2012-10-24 16:02       ` [RFC PATCH net-next v2 5/5] rtnl/ipv4: add support of RTM_GETNETCONF Nicolas Dichtel
2012-10-26  6:19       ` [RFC PATCH net-next v2 0/5] Allow to monitor protocol configuration David Miller
2012-10-23  9:49 ` [RFC PATCH net-next 3/3] rtnl/ipv4: use netconf msg to advertise forwarding status Nicolas Dichtel
2012-10-23  9:54 ` [RFC PATCH iproute2] ip: allow to monitor netconf messages Nicolas Dichtel
2012-10-23 12:52   ` Stephen Hemminger

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=1351094579-3911-3-git-send-email-nicolas.dichtel@6wind.com \
    --to=nicolas.dichtel@6wind.com \
    --cc=davem@davemloft.net \
    --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;
as well as URLs for NNTP newsgroup(s).