Skip to contentSkip to conversation

PATCH: ioctl send PID in netlink events

PATCH Applied jamal 3 participants 5 messages Jun 2, 2005 – Jun 3, 2005

Subsystems (3)
lore
Share & tools
lore

jamal

author
#0 lore raw

This is where i was trying to get to ;->
This patch is on top of the earlier one i sent for explicit types. I still have to think about how to best do IPV6 routes as well as ARP and NDISC. If anyone has suggestions or wants to tackle them let me know, the v6 route is not going to be a pretty one i think.

cheers,
jamal

This patch ensures that netlink events created as a result of programns using ioctls (such as ifconfig, route etc) contains the correct PID of those events.

net/core/rtnetlink.c: needs update
net/ipv4/devinet.c: needs update
net/ipv4/fib_semantics.c: needs update
net/ipv6/addrconf.c: needs update
Index: net/core/rtnetlink.c
===================================================================

net/core/rtnetlink.c (mode:100644) +1 -1
@@ -452,7 +452,7 @@
 	if (!skb)
 		return;
 
-	if (rtnetlink_fill_ifinfo(skb, dev, type, 0, 0, change, 0) < 0) {
+	if (rtnetlink_fill_ifinfo(skb, dev, type, current->pid, 0, change, 0) < 0) {
 		kfree_skb(skb);
 		return;
 	}
net/ipv4/devinet.c (mode:100644) +3 -1
Index: net/ipv4/devinet.c
===================================================================
@@ -236,6 +236,7 @@
 	struct in_ifaddr *promote = NULL;
 	struct in_ifaddr *ifa1 = *ifap;
 
+	printk("inet_del_ifa: pid %d\n",current->pid);
 	ASSERT_RTNL();
 
 	/* 1. Deleting primary ifaddr forces deletion all secondaries 
@@ -305,6 +306,7 @@
 
 	ASSERT_RTNL();
 
+	printk("inet_insert_ifa: pid %d\n",current->pid);
 	if (!ifa->ifa_local) {
 		inet_free_ifa(ifa);
 		return 0;
@@ -1112,7 +1114,7 @@
 
 	if (!skb)
 		netlink_set_err(rtnl, 0, RTMGRP_IPV4_IFADDR, ENOBUFS);
-	else if (inet_fill_ifaddr(skb, ifa, 0, 0, event, 0) < 0) {
+	else if (inet_fill_ifaddr(skb, ifa, current->pid, 0, event, 0) < 0) {
 		kfree_skb(skb);
 		netlink_set_err(rtnl, 0, RTMGRP_IPV4_IFADDR, EINVAL);
 	} else {
net/ipv4/fib_semantics.c (mode:100644) +2 -2
Index: net/ipv4/fib_semantics.c
===================================================================
@@ -276,7 +276,7 @@
 	       struct nlmsghdr *n, struct netlink_skb_parms *req)
 {
 	struct sk_buff *skb;
-	u32 pid = req ? req->pid : 0;
+	u32 pid = req ? req->pid : n->nlmsg_pid;
 	int size = NLMSG_SPACE(sizeof(struct rtmsg)+256);
 
 	skb = alloc_skb(size, GFP_KERNEL);
@@ -1035,7 +1035,7 @@
 	}
 
 	nl->nlmsg_flags = NLM_F_REQUEST;
-	nl->nlmsg_pid = 0;
+	nl->nlmsg_pid = current->pid;
 	nl->nlmsg_seq = 0;
 	nl->nlmsg_len = NLMSG_LENGTH(sizeof(*rtm));
 	if (cmd == SIOCDELRT) {
net/ipv6/addrconf.c (mode:100644) +3 -3
Index: net/ipv6/addrconf.c
===================================================================
@@ -2872,7 +2872,7 @@
 		netlink_set_err(rtnl, 0, RTMGRP_IPV6_IFADDR, ENOBUFS);
 		return;
 	}
-	if (inet6_fill_ifaddr(skb, ifa, 0, 0, event, 0) < 0) {
+	if (inet6_fill_ifaddr(skb, ifa, current->pid, 0, event, 0) < 0) {
 		kfree_skb(skb);
 		netlink_set_err(rtnl, 0, RTMGRP_IPV6_IFADDR, EINVAL);
 		return;
@@ -3007,7 +3007,7 @@
 		netlink_set_err(rtnl, 0, RTMGRP_IPV6_IFINFO, ENOBUFS);
 		return;
 	}
-	if (inet6_fill_ifinfo(skb, idev, 0, 0, event, 0) < 0) {
+	if (inet6_fill_ifinfo(skb, idev, current->pid, 0, event, 0) < 0) {
 		kfree_skb(skb);
 		netlink_set_err(rtnl, 0, RTMGRP_IPV6_IFINFO, EINVAL);
 		return;
@@ -3064,7 +3064,7 @@
 		netlink_set_err(rtnl, 0, RTMGRP_IPV6_PREFIX, ENOBUFS);
 		return;
 	}
-	if (inet6_fill_prefix(skb, idev, pinfo, 0, 0, event, 0) < 0) {
+	if (inet6_fill_prefix(skb, idev, pinfo, current->pid, 0, event, 0) < 0) {
 		kfree_skb(skb);
 		netlink_set_err(rtnl, 0, RTMGRP_IPV6_PREFIX, EINVAL);
 		return;
#1 lore raw
Quoted 13 lines

Index: net/ipv4/devinet.c
===================================================================

net/ipv4/devinet.c (mode:100644) +1 -0
@@ -236,6 +236,7 @@
 	struct in_ifaddr *promote = NULL;
 	struct in_ifaddr *ifa1 = *ifap;
 
+	printk("inet_del_ifa: pid %d\n",current->pid);
 	ASSERT_RTNL();
 
 	/* 1. Deleting primary ifaddr forces deletion all secondaries 

net/ipv4/devinet.c (mode:100644) line 312

Quoted 7 lines
net/ipv4/devinet.c (mode:100644) +1 -0
@@ -305,6 +306,7 @@
 
 	ASSERT_RTNL();
 
+	printk("inet_insert_ifa: pid %d\n",current->pid);
 	if (!ifa->ifa_local) {
 		inet_free_ifa(ifa);
 		return 0;

Don't you want to remove these?

Quoted 14 lines

Index: net/ipv4/fib_semantics.c
===================================================================

net/ipv4/fib_semantics.c (mode:100644) +1 -1
@@ -276,7 +276,7 @@
 	       struct nlmsghdr *n, struct netlink_skb_parms *req)
 {
 	struct sk_buff *skb;
-	u32 pid = req ? req->pid : 0;
+	u32 pid = req ? req->pid : n->nlmsg_pid;
 	int size = NLMSG_SPACE(sizeof(struct rtmsg)+256);
 
 	skb = alloc_skb(size, GFP_KERNEL);

net/ipv4/fib_semantics.c (mode:100644) line 1041

Quoted 8 lines
net/ipv4/fib_semantics.c (mode:100644) +1 -1
@@ -1035,7 +1035,7 @@
 	}
 
 	nl->nlmsg_flags = NLM_F_REQUEST;
-	nl->nlmsg_pid = 0;
+	nl->nlmsg_pid = current->pid;
 	nl->nlmsg_seq = 0;
 	nl->nlmsg_len = NLMSG_LENGTH(sizeof(*rtm));
 	if (cmd == SIOCDELRT) {

Neat ;->

author
#2 lore raw
Quoted 14 lines · Thomas Graf
Quoted 14 lines

Index: net/ipv4/devinet.c
===================================================================

net/ipv4/devinet.c (mode:100644) +1 -0
@@ -236,6 +236,7 @@
 	struct in_ifaddr *promote = NULL;
 	struct in_ifaddr *ifa1 = *ifap;
 
+	printk("inet_del_ifa: pid %d\n",current->pid);
 	ASSERT_RTNL();
 
 	/* 1. Deleting primary ifaddr forces deletion all secondaries 
@@ -305,6 +306,7 @@
 
Quoted 10 lines

net/ipv4/devinet.c (mode:100644) line 312

Quoted 6 lines
net/ipv4/devinet.c (mode:100644) +1 -0
 	ASSERT_RTNL();
 
+	printk("inet_insert_ifa: pid %d\n",current->pid);
 	if (!ifa->ifa_local) {
 		inet_free_ifa(ifa);
 		return 0;

Don't you want to remove these?

Yes, how did those get there? ;->

Quoted 16 lines
Quoted 16 lines

Index: net/ipv4/fib_semantics.c
===================================================================

net/ipv4/fib_semantics.c (mode:100644) +1 -1
@@ -276,7 +276,7 @@
 	       struct nlmsghdr *n, struct netlink_skb_parms *req)
 {
 	struct sk_buff *skb;
-	u32 pid = req ? req->pid : 0;
+	u32 pid = req ? req->pid : n->nlmsg_pid;
 	int size = NLMSG_SPACE(sizeof(struct rtmsg)+256);
 
 	skb = alloc_skb(size, GFP_KERNEL);
@@ -1035,7 +1035,7 @@
 	}
 
Quoted 8 lines

net/ipv4/fib_semantics.c (mode:100644) line 1041

Quoted 6 lines
net/ipv4/fib_semantics.c (mode:100644) +1 -1
 	nl->nlmsg_flags = NLM_F_REQUEST;
-	nl->nlmsg_pid = 0;
+	nl->nlmsg_pid = current->pid;
 	nl->nlmsg_seq = 0;
 	nl->nlmsg_len = NLMSG_LENGTH(sizeof(*rtm));
 	if (cmd == SIOCDELRT) {

Neat ;->

The second one could probably use the new macros.
Maybe i will wait until Dave puts this in his tree and send a small change; else you could send it.

cheers,
jamal

author
#3 lore raw

Dave,

If you havent applied that patch to net-2.6.13 heres one that removes those extrenous printks.

Quoted 4 lines · jamal

The second one could probably use the new macros.
Maybe i will wait until Dave puts this in his tree and send a small change; else you could send it.

Actually cant be done, sorry i lied ;->

cheers,
jamal

net/core/rtnetlink.c: needs update
net/ipv4/devinet.c: needs update
net/ipv4/fib_semantics.c: needs update
net/ipv6/addrconf.c: needs update
Index: net/core/rtnetlink.c
===================================================================

net/core/rtnetlink.c (mode:100644) +1 -1
@@ -452,7 +452,7 @@
 	if (!skb)
 		return;
 
-	if (rtnetlink_fill_ifinfo(skb, dev, type, 0, 0, change, 0) < 0) {
+	if (rtnetlink_fill_ifinfo(skb, dev, type, current->pid, 0, change, 0) < 0) {
 		kfree_skb(skb);
 		return;
 	}
net/ipv4/devinet.c (mode:100644) +1 -1
Index: net/ipv4/devinet.c
===================================================================
@@ -1112,7 +1112,7 @@
 
 	if (!skb)
 		netlink_set_err(rtnl, 0, RTMGRP_IPV4_IFADDR, ENOBUFS);
-	else if (inet_fill_ifaddr(skb, ifa, 0, 0, event, 0) < 0) {
+	else if (inet_fill_ifaddr(skb, ifa, current->pid, 0, event, 0) < 0) {
 		kfree_skb(skb);
 		netlink_set_err(rtnl, 0, RTMGRP_IPV4_IFADDR, EINVAL);
 	} else {
net/ipv4/fib_semantics.c (mode:100644) +2 -2
Index: net/ipv4/fib_semantics.c
===================================================================
@@ -276,7 +276,7 @@
 	       struct nlmsghdr *n, struct netlink_skb_parms *req)
 {
 	struct sk_buff *skb;
-	u32 pid = req ? req->pid : 0;
+	u32 pid = req ? req->pid : n->nlmsg_pid;
 	int size = NLMSG_SPACE(sizeof(struct rtmsg)+256);
 
 	skb = alloc_skb(size, GFP_KERNEL);
@@ -1035,7 +1035,7 @@
 	}
 
 	nl->nlmsg_flags = NLM_F_REQUEST;
-	nl->nlmsg_pid = 0;
+	nl->nlmsg_pid = current->pid;
 	nl->nlmsg_seq = 0;
 	nl->nlmsg_len = NLMSG_LENGTH(sizeof(*rtm));
 	if (cmd == SIOCDELRT) {
net/ipv6/addrconf.c (mode:100644) +3 -3
Index: net/ipv6/addrconf.c
===================================================================
@@ -2872,7 +2872,7 @@
 		netlink_set_err(rtnl, 0, RTMGRP_IPV6_IFADDR, ENOBUFS);
 		return;
 	}
-	if (inet6_fill_ifaddr(skb, ifa, 0, 0, event, 0) < 0) {
+	if (inet6_fill_ifaddr(skb, ifa, current->pid, 0, event, 0) < 0) {
 		kfree_skb(skb);
 		netlink_set_err(rtnl, 0, RTMGRP_IPV6_IFADDR, EINVAL);
 		return;
@@ -3007,7 +3007,7 @@
 		netlink_set_err(rtnl, 0, RTMGRP_IPV6_IFINFO, ENOBUFS);
 		return;
 	}
-	if (inet6_fill_ifinfo(skb, idev, 0, 0, event, 0) < 0) {
+	if (inet6_fill_ifinfo(skb, idev, current->pid, 0, event, 0) < 0) {
 		kfree_skb(skb);
 		netlink_set_err(rtnl, 0, RTMGRP_IPV6_IFINFO, EINVAL);
 		return;
@@ -3064,7 +3064,7 @@
 		netlink_set_err(rtnl, 0, RTMGRP_IPV6_PREFIX, ENOBUFS);
 		return;
 	}
-	if (inet6_fill_prefix(skb, idev, pinfo, 0, 0, event, 0) < 0) {
+	if (inet6_fill_prefix(skb, idev, pinfo, current->pid, 0, event, 0) < 0) {
 		kfree_skb(skb);
 		netlink_set_err(rtnl, 0, RTMGRP_IPV6_PREFIX, EINVAL);
 		return;
maintainer Applied
#4 lore raw

From: jamal <[email protected]>
Date: Thu, 02 Jun 2005 23:32:55 -0400

Quoted 2 lines

If you havent applied that patch to net-2.6.13 heres one that removes those extrenous printks.

Applied, thanks Jamal.