netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Graf <tgraf@suug.ch>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org
Subject: [PATCH 07/16] [IPv4] address: Convert address notification to use rtnl_notify()
Date: Mon, 14 Aug 2006 00:00:07 +0200	[thread overview]
Message-ID: <20060814214341.215063778@postel.suug.ch> (raw)
In-Reply-To: 20060814213718.580598840@postel.suug.ch

[-- Attachment #1: rtnl_convert_ip4_addr --]
[-- Type: text/plain, Size: 4536 bytes --]

Adds support for NLM_F_ECHO allowing applications to easly
see which address have been deleted, added, or promoted.

Signed-off-by: Thomas Graf <tgraf@suug.ch>

Index: net-2.6.19.git/net/ipv4/devinet.c
===================================================================
--- net-2.6.19.git.orig/net/ipv4/devinet.c
+++ net-2.6.19.git/net/ipv4/devinet.c
@@ -88,7 +88,7 @@ static struct nla_policy ifa_ipv4_policy
 	[IFA_LABEL]     	= { .type = NLA_STRING },
 };
 
-static void rtmsg_ifa(int event, struct in_ifaddr *);
+static void rtmsg_ifa(int event, struct in_ifaddr *, struct nlmsghdr *, u32);
 
 static BLOCKING_NOTIFIER_HEAD(inetaddr_chain);
 static void inet_del_ifa(struct in_device *in_dev, struct in_ifaddr **ifap,
@@ -239,8 +239,8 @@ int inet_addr_onlink(struct in_device *i
 	return 0;
 }
 
-static void inet_del_ifa(struct in_device *in_dev, struct in_ifaddr **ifap,
-			 int destroy)
+static void __inet_del_ifa(struct in_device *in_dev, struct in_ifaddr **ifap,
+			 int destroy, struct nlmsghdr *nlh, u32 pid)
 {
 	struct in_ifaddr *promote = NULL;
 	struct in_ifaddr *ifa, *ifa1 = *ifap;
@@ -273,7 +273,7 @@ static void inet_del_ifa(struct in_devic
 			if (!do_promote) {
 				*ifap1 = ifa->ifa_next;
 
-				rtmsg_ifa(RTM_DELADDR, ifa);
+				rtmsg_ifa(RTM_DELADDR, ifa, nlh, pid);
 				blocking_notifier_call_chain(&inetaddr_chain,
 						NETDEV_DOWN, ifa);
 				inet_free_ifa(ifa);
@@ -298,7 +298,7 @@ static void inet_del_ifa(struct in_devic
 	   is valid, it will try to restore deleted routes... Grr.
 	   So that, this order is correct.
 	 */
-	rtmsg_ifa(RTM_DELADDR, ifa1);
+	rtmsg_ifa(RTM_DELADDR, ifa1, nlh, pid);
 	blocking_notifier_call_chain(&inetaddr_chain, NETDEV_DOWN, ifa1);
 
 	if (promote) {
@@ -310,7 +310,7 @@ static void inet_del_ifa(struct in_devic
 		}
 
 		promote->ifa_flags &= ~IFA_F_SECONDARY;
-		rtmsg_ifa(RTM_NEWADDR, promote);
+		rtmsg_ifa(RTM_NEWADDR, promote, nlh, pid);
 		blocking_notifier_call_chain(&inetaddr_chain,
 				NETDEV_UP, promote);
 		for (ifa = promote->ifa_next; ifa; ifa = ifa->ifa_next) {
@@ -329,7 +329,14 @@ static void inet_del_ifa(struct in_devic
 	}
 }
 
-static int inet_insert_ifa(struct in_ifaddr *ifa)
+static void inet_del_ifa(struct in_device *in_dev, struct in_ifaddr **ifap,
+			 int destroy)
+{
+	__inet_del_ifa(in_dev, ifap, destroy, NULL, 0);
+}
+
+static int __inet_insert_ifa(struct in_ifaddr *ifa, struct nlmsghdr *nlh,
+			     u32 pid)
 {
 	struct in_device *in_dev = ifa->ifa_dev;
 	struct in_ifaddr *ifa1, **ifap, **last_primary;
@@ -374,12 +381,17 @@ static int inet_insert_ifa(struct in_ifa
 	/* Send message first, then call notifier.
 	   Notifier will trigger FIB update, so that
 	   listeners of netlink will know about new ifaddr */
-	rtmsg_ifa(RTM_NEWADDR, ifa);
+	rtmsg_ifa(RTM_NEWADDR, ifa, nlh, pid);
 	blocking_notifier_call_chain(&inetaddr_chain, NETDEV_UP, ifa);
 
 	return 0;
 }
 
+static int inet_insert_ifa(struct in_ifaddr *ifa)
+{
+	return __inet_insert_ifa(ifa, NULL, 0);
+}
+
 static int inet_set_ifa(struct net_device *dev, struct in_ifaddr *ifa)
 {
 	struct in_device *in_dev = __in_dev_get_rtnl(dev);
@@ -466,7 +478,7 @@ static int inet_rtm_deladdr(struct sk_bu
 		    !inet_ifa_match(nla_get_u32(tb[IFA_ADDRESS]), ifa)))
 			continue;
 
-		inet_del_ifa(in_dev, ifap, 1);
+		__inet_del_ifa(in_dev, ifap, 1, nlh, NETLINK_CB(skb).pid);
 		return 0;
 	}
 
@@ -558,7 +570,7 @@ static int inet_rtm_newaddr(struct sk_bu
 	if (IS_ERR(ifa))
 		return PTR_ERR(ifa);
 
-	return inet_insert_ifa(ifa);
+	return __inet_insert_ifa(ifa, nlh, NETLINK_CB(skb).pid);
 }
 
 /*
@@ -1189,18 +1201,27 @@ done:
 	return skb->len;
 }
 
-static void rtmsg_ifa(int event, struct in_ifaddr* ifa)
+static void rtmsg_ifa(int event, struct in_ifaddr* ifa, struct nlmsghdr *nlh,
+		      u32 pid)
 {
 	struct sk_buff *skb;
+	u32 seq = nlh ? nlh->nlmsg_seq : 0;
+	int err = -ENOBUFS;
 
 	skb = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
 	if (skb == NULL)
-		netlink_set_err(rtnl, 0, RTNLGRP_IPV4_IFADDR, ENOBUFS);
-	else if (inet_fill_ifaddr(skb, ifa, 0, 0, event, 0) < 0) {
+		goto errout;
+
+	err = inet_fill_ifaddr(skb, ifa, pid, seq, event, 0);
+	if (err < 0) {
 		kfree_skb(skb);
-		netlink_set_err(rtnl, 0, RTNLGRP_IPV4_IFADDR, EINVAL);
-	} else
-		netlink_broadcast(rtnl, skb, 0, RTNLGRP_IPV4_IFADDR, GFP_KERNEL);
+		goto errout;
+	}
+
+	err = rtnl_notify(skb, pid, RTNLGRP_IPV4_IFADDR, nlh, GFP_KERNEL);
+errout:
+	if (err < 0)
+		rtnl_set_sk_err(RTNLGRP_IPV4_IFADDR, err);
 }
 
 static struct rtnetlink_link inet_rtnetlink_table[RTM_NR_MSGTYPES] = {


  parent reply	other threads:[~2006-08-14 21:44 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-14 21:37 [PATCHSET] rtnetlink notification rework Thomas Graf
2006-08-13 22:00 ` [PATCH 01/16] [RTNETLINK]: Use rtnl_unicast() for rtnetlink unicasts Thomas Graf
2006-08-13 22:00 ` [PATCH 02/16] [NETLINK]: Add notification message sending interface Thomas Graf
2006-08-13 22:00 ` [PATCH 03/16] [RTNETLINK]: Add rtnetlink notification interface Thomas Graf
2006-08-13 22:00 ` [PATCH 04/16] [NET] fib_rules: Convert fib rule notification to use rtnl_notify() Thomas Graf
2006-08-13 22:00 ` [PATCH 05/16] [NEIGH]: Convert neighbour notifications ot " Thomas Graf
2006-08-13 22:00 ` [PATCH 06/16] [DECNET]: Convert DECnet notifications to " Thomas Graf
2006-08-13 22:00 ` Thomas Graf [this message]
2006-08-13 22:00 ` [PATCH 08/16] [IPv4] route: Convert route " Thomas Graf
2006-08-13 22:00 ` [PATCH 09/16] [IPv6] address: Convert address notification " Thomas Graf
2006-08-14 23:43   ` jamal
2006-08-14 23:51     ` jamal
2006-08-15  7:20       ` Hasso Tepper
2006-08-15  9:50         ` jamal
2006-08-15  0:07     ` Thomas Graf
2006-08-15  0:12       ` jamal
2006-08-15  0:36     ` Alexey Kuznetsov
2006-08-15  0:56       ` Herbert Xu
2006-08-15  2:46         ` jamal
2006-08-15  3:03           ` jamal
2006-08-15 11:17       ` Thomas Graf
2006-08-15 12:08         ` Hasso Tepper
2006-08-15 12:23           ` Thomas Graf
2006-08-16  2:58             ` Herbert Xu
2006-08-16  3:04               ` Herbert Xu
2006-08-16 10:58               ` Thomas Graf
2006-08-16 11:03                 ` jamal
2006-08-16 11:12                 ` Herbert Xu
2006-08-16 11:39                   ` Herbert Xu
2006-08-16 12:04                     ` jamal
2006-08-16 12:08                       ` Herbert Xu
2006-08-16 12:08                       ` Thomas Graf
2006-08-16 12:36                         ` jamal
2006-08-16 13:04                           ` Alexey Kuznetsov
2006-08-16 13:11                             ` jamal
2006-08-16 12:13                     ` Thomas Graf
2006-08-16 11:40                   ` Thomas Graf
2006-08-16 11:57                     ` Herbert Xu
2006-08-16 12:05                       ` Thomas Graf
2006-08-16 12:08                         ` jamal
2006-08-16 12:54               ` Alexey Kuznetsov
2006-08-13 22:00 ` [PATCH 10/16] [IPv6] route: Convert route notifications " Thomas Graf
2006-08-13 22:00 ` [PATCH 11/16] [IPv6] link: Convert link " Thomas Graf
2006-08-13 22:00 ` [PATCH 12/16] [IPv6] prefix: Convert prefix " Thomas Graf
2006-08-13 22:00 ` [PATCH 13/16] [BRIDGE]: Convert " Thomas Graf
2006-08-13 22:00 ` [PATCH 14/16] [WIRELESS]: " Thomas Graf
2006-08-13 22:00 ` [PATCH 15/16] [NET] link: " Thomas Graf
2006-08-13 22:00 ` [PATCH 16/16] [RTNETLINK]: Unexport rtnl socket Thomas Graf
2006-08-15  7:38 ` [PATCHSET] rtnetlink notification rework 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=20060814214341.215063778@postel.suug.ch \
    --to=tgraf@suug.ch \
    --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).