Skip to contentSkip to conversation

Firewire networking assorted fixes

PATCH Applied Maxim Levitsky 6 participants 32 messages Nov 29, 2010 – Jan 11, 2011 2 messages not in the archive

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

v2 cover Firewire networking assorted fixes

Hi,

This is updated version of the patches.
I updated the changelogs, addressed comments on patch #2

Best regards,
Maxim Levitsky

#1 lore raw

PATCH v2 1/5 firewire: ohci: restore GUID on resume.

Some lousy BIOSes, e.g. my Aspire 5720 BIOS forget to restore the GUID register on resume from ram.

Fix that by setting it to the last value that
was read from it.

---
 drivers/firewire/ohci.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
drivers/firewire/ohci.c +7 -0
index 6dd56cd..0fbadb7 100644
@@ -3240,6 +3240,13 @@ static int pci_resume(struct pci_dev *dev)
 		return err;
 	}
 
+	/* Some systems don't setup GUID register on resume from ram  */
+	if (!reg_read(ohci, OHCI1394_GUIDLo) &&
+					!reg_read(ohci, OHCI1394_GUIDHi)) {
+		reg_write(ohci, OHCI1394_GUIDLo, (u32)ohci->card.guid);
+		reg_write(ohci, OHCI1394_GUIDHi, (u32)(ohci->card.guid >> 32));
+	}
+
 	return ohci_enable(&ohci->card, NULL, 0);
 }
 #endif
Signature · 1 line
1.7.1
#2 lore raw

PATCH v2 2/5 firewire: ohci: restart ISO DMA contexts on resume from low power mode

In reply to Maxim Levitsky

Restore ISO channels DMA so that ISO channels could continue to work after resume from ram/disk.

---
 drivers/firewire/ohci.c |   54 ++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 46 insertions(+), 8 deletions(-)
drivers/firewire/ohci.c +46 -8
index 0fbadb7..f5889d5 100644
@@ -40,6 +40,7 @@
 #include <linux/spinlock.h>
 #include <linux/string.h>
 #include <linux/time.h>
+#include <linux/bitops.h>
 
 #include <asm/byteorder.h>
 #include <asm/page.h>
@@ -152,6 +153,7 @@ struct context {
 	descriptor_callback_t callback;
 
 	struct tasklet_struct tasklet;
+	bool active;
 };
 
 #define IT_HEADER_SY(v)          ((v) <<  0)
@@ -167,6 +169,9 @@ struct iso_context {
 	int excess_bytes;
 	void *header;
 	size_t header_length;
+
+	u8 sync;
+	u8 tags;
 };
 
 #define CONFIG_ROM_SIZE 1024
@@ -183,7 +188,8 @@ struct fw_ohci {
 	u32 bus_time;
 	bool is_root;
 	bool csr_state_setclear_abdicate;
-
+	int n_ir;
+	int n_it;
 	/*
 	 * Spinlock for accessing fw_ohci data.  Never call out of
 	 * this driver with this lock held.
@@ -1156,6 +1162,7 @@ static struct descriptor *context_get_descriptors(struct context *ctx,
 static void context_run(struct context *ctx, u32 extra)
 {
 	struct fw_ohci *ohci = ctx->ohci;
+	ctx->active = true;
 
 	reg_write(ohci, COMMAND_PTR(ctx->regs),
 		  le32_to_cpu(ctx->last->branch_address));
@@ -1187,6 +1194,7 @@ static void context_stop(struct context *ctx)
 	u32 reg;
 	int i;
 
+	ctx->active = false;
 	reg_write(ctx->ohci, CONTROL_CLEAR(ctx->regs), CONTEXT_RUN);
 	flush_writes(ctx->ohci);
 
@@ -2614,6 +2622,10 @@ static int ohci_start_iso(struct fw_iso_context *base,
 		reg_write(ohci, OHCI1394_IsoRecvIntMaskSet, 1 << index);
 		reg_write(ohci, CONTEXT_MATCH(ctx->context.regs), match);
 		context_run(&ctx->context, control);
+
+		ctx->sync = sync;
+		ctx->tags = tags;
+
 		break;
 	}
 
@@ -2711,6 +2723,26 @@ static int ohci_set_iso_channels(struct fw_iso_context *base, u64 *channels)
 	return ret;
 }
 
+#ifdef CONFIG_PM
+static void ohci_resume_iso_dma(struct fw_ohci *ohci)
+{
+	int i;
+	struct iso_context *ctx;
+
+	for (i = 0 ; i < ohci->n_ir ; i++) {
+		ctx = &ohci->ir_context_list[i];
+		if (ctx->context.active)
+			ohci_start_iso(&ctx->base, 0, ctx->sync, ctx->tags);
+	}
+
+	for (i = 0 ; i < ohci->n_it ; i++) {
+		ctx = &ohci->it_context_list[i];
+		if (ctx->context.active)
+			ohci_start_iso(&ctx->base, 0, ctx->sync, ctx->tags);
+	}
+}
+#endif
+
 static int queue_iso_transmit(struct iso_context *ctx,
 			      struct fw_iso_packet *packet,
 			      struct fw_iso_buffer *buffer,
@@ -3020,7 +3052,7 @@ static int __devinit pci_probe(struct pci_dev *dev,
 	struct fw_ohci *ohci;
 	u32 bus_options, max_receive, link_speed, version;
 	u64 guid;
-	int i, err, n_ir, n_it;
+	int i, err;
 	size_t size;
 
 	ohci = kzalloc(sizeof(*ohci), GFP_KERNEL);
@@ -3092,15 +3124,15 @@ static int __devinit pci_probe(struct pci_dev *dev,
 	ohci->ir_context_channels = ~0ULL;
 	ohci->ir_context_mask = reg_read(ohci, OHCI1394_IsoRecvIntMaskSet);
 	reg_write(ohci, OHCI1394_IsoRecvIntMaskClear, ~0);
-	n_ir = hweight32(ohci->ir_context_mask);
-	size = sizeof(struct iso_context) * n_ir;
+	ohci->n_ir = hweight32(ohci->ir_context_mask);
+	size = sizeof(struct iso_context) * ohci->n_ir;
 	ohci->ir_context_list = kzalloc(size, GFP_KERNEL);
 
 	reg_write(ohci, OHCI1394_IsoXmitIntMaskSet, ~0);
 	ohci->it_context_mask = reg_read(ohci, OHCI1394_IsoXmitIntMaskSet);
 	reg_write(ohci, OHCI1394_IsoXmitIntMaskClear, ~0);
-	n_it = hweight32(ohci->it_context_mask);
-	size = sizeof(struct iso_context) * n_it;
+	ohci->n_it = hweight32(ohci->it_context_mask);
+	size = sizeof(struct iso_context) * ohci->n_it;
 	ohci->it_context_list = kzalloc(size, GFP_KERNEL);
 
 	if (ohci->it_context_list == NULL || ohci->ir_context_list == NULL) {
@@ -3132,7 +3164,7 @@ static int __devinit pci_probe(struct pci_dev *dev,
 	fw_notify("Added fw-ohci device %s, OHCI v%x.%x, "
 		  "%d IR + %d IT contexts, quirks 0x%x\n",
 		  dev_name(&dev->dev), version >> 16, version & 0xff,
-		  n_ir, n_it, ohci->quirks);
+		  ohci->n_ir, ohci->n_it, ohci->quirks);
 
 	return 0;
 
@@ -3247,7 +3279,13 @@ static int pci_resume(struct pci_dev *dev)
 		reg_write(ohci, OHCI1394_GUIDHi, (u32)(ohci->card.guid >> 32));
 	}
 
-	return ohci_enable(&ohci->card, NULL, 0);
+	err = ohci_enable(&ohci->card, NULL, 0);
+
+	if (err)
+		return err;
+
+	ohci_resume_iso_dma(ohci);
+	return 0;
 }
 #endif
 
Signature · 1 line
1.7.1
#3 lore raw

PATCH v2 3/5 NET: IPV4: ARP: allow to invalidate specific ARP entries

In reply to Maxim Levitsky

IPv4 over firewire needs to be able to remove ARP entries from the ARP cache that belong to nodes that are removed, because IPv4 over firewire uses ARP packets for private information about nodes.

This information becomes invalid as soon as node drops off the bus and when it reconnects, its only possible to start takling to is after it responded to an ARP packet. But ARP cache prevents such packets from being sent.

CC "David S. Miller" <[email protected]>
CC Alexey Kuznetsov <[email protected]>
CC James Morris <[email protected]>
CC Patrick McHardy <[email protected]>
---
 include/net/arp.h |    1 +
 net/ipv4/arp.c    |   29 ++++++++++++++++++-----------
 2 files changed, 19 insertions(+), 11 deletions(-)
include/net/arp.h +1 -0
index f4cf6ce..91f0568 100644
@@ -25,5 +25,6 @@ extern struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip,
 				  const unsigned char *src_hw,
 				  const unsigned char *target_hw);
 extern void arp_xmit(struct sk_buff *skb);
+int arp_invalidate(struct net_device *dev, __be32 ip);
 
 #endif	/* _ARP_H */
net/ipv4/arp.c +18 -11
index d8e540c..35b1272 100644
@@ -1142,6 +1142,23 @@ static int arp_req_get(struct arpreq *r, struct net_device *dev)
 	return err;
 }
 
+int arp_invalidate(struct net_device *dev, __be32 ip)
+{
+	int err = -ENXIO;
+	struct neighbour *neigh = neigh_lookup(&arp_tbl, &ip, dev);
+
+	if (neigh) {
+		if (neigh->nud_state & ~NUD_NOARP)
+			err = neigh_update(neigh, NULL, NUD_FAILED,
+					   NEIGH_UPDATE_F_OVERRIDE|
+					   NEIGH_UPDATE_F_ADMIN);
+		neigh_release(neigh);
+	}
+
+	return err;
+}
+EXPORT_SYMBOL(arp_invalidate);
+
 static int arp_req_delete_public(struct net *net, struct arpreq *r,
 		struct net_device *dev)
 {
@@ -1162,7 +1179,6 @@ static int arp_req_delete(struct net *net, struct arpreq *r,
 {
 	int err;
 	__be32 ip;
-	struct neighbour *neigh;
 
 	if (r->arp_flags & ATF_PUBL)
 		return arp_req_delete_public(net, r, dev);
@@ -1180,16 +1196,7 @@ static int arp_req_delete(struct net *net, struct arpreq *r,
 		if (!dev)
 			return -EINVAL;
 	}
-	err = -ENXIO;
-	neigh = neigh_lookup(&arp_tbl, &ip, dev);
-	if (neigh) {
-		if (neigh->nud_state & ~NUD_NOARP)
-			err = neigh_update(neigh, NULL, NUD_FAILED,
-					   NEIGH_UPDATE_F_OVERRIDE|
-					   NEIGH_UPDATE_F_ADMIN);
-		neigh_release(neigh);
-	}
-	return err;
+	return arp_invalidate(dev, ip);
 }
 
 /*
Signature · 1 line
1.7.1
#4 lore raw

Re: [PATCH 3/5] NET: IPV4: ARP: allow to invalidate specific ARP entries

Quoted 10 lines · Maxim Levitsky

IPv4 over firewire needs to be able to remove ARP entries from the ARP cache that belong to nodes that are removed, because IPv4 over firewire uses ARP packets for private information about nodes.

This information becomes invalid as soon as node drops off the bus and when it reconnects, its only possible to start takling to is after it responded to an ARP packet. But ARP cache prevents such packets from being sent.

Quoted 5 lines
CC "David S. Miller" <[email protected]>
CC Alexey Kuznetsov <[email protected]>
CC James Morris <[email protected]>
CC Patrick McHardy <[email protected]>

Anybody?

Best regards,
Maxim Levitsky

Quoted 73 lines
---
 include/net/arp.h |    1 +
 net/ipv4/arp.c    |   29 ++++++++++++++++++-----------
 2 files changed, 19 insertions(+), 11 deletions(-)
include/net/arp.h +1 -0
index f4cf6ce..91f0568 100644
@@ -25,5 +25,6 @@ extern struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip,
 				  const unsigned char *src_hw,
 				  const unsigned char *target_hw);
 extern void arp_xmit(struct sk_buff *skb);
+int arp_invalidate(struct net_device *dev, __be32 ip);
 
 #endif	/* _ARP_H */
net/ipv4/arp.c +18 -11
index d8e540c..35b1272 100644
@@ -1142,6 +1142,23 @@ static int arp_req_get(struct arpreq *r, struct net_device *dev)
 	return err;
 }
 
+int arp_invalidate(struct net_device *dev, __be32 ip)
+{
+	int err = -ENXIO;
+	struct neighbour *neigh = neigh_lookup(&arp_tbl, &ip, dev);
+
+	if (neigh) {
+		if (neigh->nud_state & ~NUD_NOARP)
+			err = neigh_update(neigh, NULL, NUD_FAILED,
+					   NEIGH_UPDATE_F_OVERRIDE|
+					   NEIGH_UPDATE_F_ADMIN);
+		neigh_release(neigh);
+	}
+
+	return err;
+}
+EXPORT_SYMBOL(arp_invalidate);
+
 static int arp_req_delete_public(struct net *net, struct arpreq *r,
 		struct net_device *dev)
 {
@@ -1162,7 +1179,6 @@ static int arp_req_delete(struct net *net, struct arpreq *r,
 {
 	int err;
 	__be32 ip;
-	struct neighbour *neigh;
 
 	if (r->arp_flags & ATF_PUBL)
 		return arp_req_delete_public(net, r, dev);
@@ -1180,16 +1196,7 @@ static int arp_req_delete(struct net *net, struct arpreq *r,
 		if (!dev)
 			return -EINVAL;
 	}
-	err = -ENXIO;
-	neigh = neigh_lookup(&arp_tbl, &ip, dev);
-	if (neigh) {
-		if (neigh->nud_state & ~NUD_NOARP)
-			err = neigh_update(neigh, NULL, NUD_FAILED,
-					   NEIGH_UPDATE_F_OVERRIDE|
-					   NEIGH_UPDATE_F_ADMIN);
-		neigh_release(neigh);
-	}
-	return err;
+	return arp_invalidate(dev, ip);
 }
 
 /*
#5 lore raw

Re: [PATCH 3/5] NET: IPV4: ARP: allow to invalidate specific ARP entries

Quoted 93 lines · Maxim Levitsky
Quoted 10 lines · Maxim Levitsky

IPv4 over firewire needs to be able to remove ARP entries from the ARP cache that belong to nodes that are removed, because IPv4 over firewire uses ARP packets for private information about nodes.

This information becomes invalid as soon as node drops off the bus and when it reconnects, its only possible to start takling to is after it responded to an ARP packet. But ARP cache prevents such packets from being sent.

Quoted 5 lines
CC "David S. Miller" <[email protected]>
CC Alexey Kuznetsov <[email protected]>
CC James Morris <[email protected]>
CC Patrick McHardy <[email protected]>

Anybody?

Best regards,
Maxim Levitsky

Quoted 72 lines
---
 include/net/arp.h |    1 +
 net/ipv4/arp.c    |   29 ++++++++++++++++++-----------
 2 files changed, 19 insertions(+), 11 deletions(-)
include/net/arp.h +1 -0
index f4cf6ce..91f0568 100644
@@ -25,5 +25,6 @@ extern struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip,
 				  const unsigned char *src_hw,
 				  const unsigned char *target_hw);
 extern void arp_xmit(struct sk_buff *skb);
+int arp_invalidate(struct net_device *dev, __be32 ip);
 
 #endif	/* _ARP_H */
net/ipv4/arp.c +18 -11
index d8e540c..35b1272 100644
@@ -1142,6 +1142,23 @@ static int arp_req_get(struct arpreq *r, struct net_device *dev)
 	return err;
 }
 
+int arp_invalidate(struct net_device *dev, __be32 ip)
+{
+	int err = -ENXIO;
+	struct neighbour *neigh = neigh_lookup(&arp_tbl, &ip, dev);
+
+	if (neigh) {
+		if (neigh->nud_state & ~NUD_NOARP)
+			err = neigh_update(neigh, NULL, NUD_FAILED,
+					   NEIGH_UPDATE_F_OVERRIDE|
+					   NEIGH_UPDATE_F_ADMIN);
+		neigh_release(neigh);
+	}
+
+	return err;
+}
+EXPORT_SYMBOL(arp_invalidate);
+
 static int arp_req_delete_public(struct net *net, struct arpreq *r,
 		struct net_device *dev)
 {
@@ -1162,7 +1179,6 @@ static int arp_req_delete(struct net *net, struct arpreq *r,
 {
 	int err;
 	__be32 ip;
-	struct neighbour *neigh;
 
 	if (r->arp_flags & ATF_PUBL)
 		return arp_req_delete_public(net, r, dev);
@@ -1180,16 +1196,7 @@ static int arp_req_delete(struct net *net, struct arpreq *r,
 		if (!dev)
 			return -EINVAL;
 	}
-	err = -ENXIO;
-	neigh = neigh_lookup(&arp_tbl, &ip, dev);
-	if (neigh) {
-		if (neigh->nud_state & ~NUD_NOARP)
-			err = neigh_update(neigh, NULL, NUD_FAILED,
-					   NEIGH_UPDATE_F_OVERRIDE|
-					   NEIGH_UPDATE_F_ADMIN);
-		neigh_release(neigh);
-	}
-	return err;
+	return arp_invalidate(dev, ip);
 }
 
Quoted 2 lines

net/ipv4/arp.c static int arp_req_delete(struct net *net, struct arpreq *r, · line 1202

Quoted 1 line
net/ipv4/arp.c +0 -0
 /*

Hmm..

If somebody can explain why RTNL is held in arp_ioctl() (and therefore in arp_req_delete()), we might first remove RTNL use in arp_ioctl() so that your patch can be applied.

Right now it is not good, because RTNL wont be necessarly held when you are going to call arp_invalidate() ?

#6 lore raw

PATCH 1/1 net: RCU conversion of dev_getbyhwaddr() and arp_ioctl()

Quoted 8 lines · Eric Dumazet

Hmm..

If somebody can explain why RTNL is held in arp_ioctl() (and therefore in arp_req_delete()), we might first remove RTNL use in arp_ioctl() so that your patch can be applied.

Right now it is not good, because RTNL wont be necessarly held when you are going to call arp_invalidate() ?

While doing this analysis, I found a refcount bug in llc, I'll send a patch for net-2.6

Meanwhile, here is the patch for net-next-2.6

Your patch then can be applied after mine.

Thanks

[PATCH] net: RCU conversion of dev_getbyhwaddr() and arp_ioctl()

dev_getbyhwaddr() was called under RTNL.

Rename it to dev_getbyhwaddr_rcu() and change all its caller to now use RCU locking instead of RTNL.

Change arp_ioctl() to use RCU instead of RTNL locking.

Note: this fix a dev refcount bug in llc

---
 include/linux/netdevice.h      |    3 ++-
 net/core/dev.c                 |   17 +++++++----------
 net/ieee802154/af_ieee802154.c |    6 +++---
 net/ipv4/arp.c                 |   17 +++++++++--------
 net/llc/af_llc.c               |   11 ++++++-----
 5 files changed, 27 insertions(+), 27 deletions(-)
include/linux/netdevice.h +2 -1
index a9ac5dc..d31bc3c 100644
@@ -1360,7 +1360,8 @@ static inline struct net_device *first_net_device(struct net *net)
 
 extern int 			netdev_boot_setup_check(struct net_device *dev);
 extern unsigned long		netdev_boot_base(const char *prefix, int unit);
-extern struct net_device    *dev_getbyhwaddr(struct net *net, unsigned short type, char *hwaddr);
+extern struct net_device *dev_getbyhwaddr_rcu(struct net *net, unsigned short type,
+					      const char *hwaddr);
 extern struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type);
 extern struct net_device *__dev_getfirstbyhwtype(struct net *net, unsigned short type);
 extern void		dev_add_pack(struct packet_type *pt);
net/core/dev.c +7 -10
index cd24374..8630142 100644
@@ -743,34 +743,31 @@ struct net_device *dev_get_by_index(struct net *net, int ifindex)
 EXPORT_SYMBOL(dev_get_by_index);
 
 /**
- *	dev_getbyhwaddr - find a device by its hardware address
+ *	dev_getbyhwaddr_rcu - find a device by its hardware address
  *	@net: the applicable net namespace
  *	@type: media type of device
  *	@ha: hardware address
  *
  *	Search for an interface by MAC address. Returns NULL if the device
- *	is not found or a pointer to the device. The caller must hold the
- *	rtnl semaphore. The returned device has not had its ref count increased
+ *	is not found or a pointer to the device. The caller must hold RCU
+ *	The returned device has not had its ref count increased
  *	and the caller must therefore be careful about locking
  *
- *	BUGS:
- *	If the API was consistent this would be __dev_get_by_hwaddr
  */
 
-struct net_device *dev_getbyhwaddr(struct net *net, unsigned short type, char *ha)
+struct net_device *dev_getbyhwaddr_rcu(struct net *net, unsigned short type,
+				       const char *ha)
 {
 	struct net_device *dev;
 
-	ASSERT_RTNL();
-
-	for_each_netdev(net, dev)
+	for_each_netdev_rcu(net, dev)
 		if (dev->type == type &&
 		    !memcmp(dev->dev_addr, ha, dev->addr_len))
 			return dev;
 
 	return NULL;
 }
-EXPORT_SYMBOL(dev_getbyhwaddr);
+EXPORT_SYMBOL(dev_getbyhwaddr_rcu);
 
 struct net_device *__dev_getfirstbyhwtype(struct net *net, unsigned short type)
 {
net/ieee802154/af_ieee802154.c +3 -3
index 93c91b6..6df6ecf 100644
@@ -52,11 +52,11 @@ struct net_device *ieee802154_get_dev(struct net *net,
 
 	switch (addr->addr_type) {
 	case IEEE802154_ADDR_LONG:
-		rtnl_lock();
-		dev = dev_getbyhwaddr(net, ARPHRD_IEEE802154, addr->hwaddr);
+		rcu_read_lock();
+		dev = dev_getbyhwaddr_rcu(net, ARPHRD_IEEE802154, addr->hwaddr);
 		if (dev)
 			dev_hold(dev);
-		rtnl_unlock();
+		rcu_read_unlock();
 		break;
 	case IEEE802154_ADDR_SHORT:
 		if (addr->pan_id == 0xffff ||
net/ipv4/arp.c +9 -8
index 7833f17..ec0966f 100644
@@ -1017,13 +1017,14 @@ static int arp_req_set_proxy(struct net *net, struct net_device *dev, int on)
 		IPV4_DEVCONF_ALL(net, PROXY_ARP) = on;
 		return 0;
 	}
-	if (__in_dev_get_rtnl(dev)) {
-		IN_DEV_CONF_SET(__in_dev_get_rtnl(dev), PROXY_ARP, on);
+	if (__in_dev_get_rcu(dev)) {
+		IN_DEV_CONF_SET(__in_dev_get_rcu(dev), PROXY_ARP, on);
 		return 0;
 	}
 	return -ENXIO;
 }
 
+/* must be called with rcu_read_lock() */
 static int arp_req_set_public(struct net *net, struct arpreq *r,
 		struct net_device *dev)
 {
@@ -1033,7 +1034,7 @@ static int arp_req_set_public(struct net *net, struct arpreq *r,
 	if (mask && mask != htonl(0xFFFFFFFF))
 		return -EINVAL;
 	if (!dev && (r->arp_flags & ATF_COM)) {
-		dev = dev_getbyhwaddr(net, r->arp_ha.sa_family,
+		dev = dev_getbyhwaddr_rcu(net, r->arp_ha.sa_family,
 				      r->arp_ha.sa_data);
 		if (!dev)
 			return -ENODEV;
@@ -1225,10 +1226,10 @@ int arp_ioctl(struct net *net, unsigned int cmd, void __user *arg)
 	if (!(r.arp_flags & ATF_NETMASK))
 		((struct sockaddr_in *)&r.arp_netmask)->sin_addr.s_addr =
 							   htonl(0xFFFFFFFFUL);
-	rtnl_lock();
+	rcu_read_lock();
 	if (r.arp_dev[0]) {
 		err = -ENODEV;
-		dev = __dev_get_by_name(net, r.arp_dev);
+		dev = dev_get_by_name_rcu(net, r.arp_dev);
 		if (dev == NULL)
 			goto out;
 
@@ -1252,12 +1253,12 @@ int arp_ioctl(struct net *net, unsigned int cmd, void __user *arg)
 		break;
 	case SIOCGARP:
 		err = arp_req_get(&r, dev);
-		if (!err && copy_to_user(arg, &r, sizeof(r)))
-			err = -EFAULT;
 		break;
 	}
 out:
-	rtnl_unlock();
+	rcu_read_unlock();
+	if (cmd == SIOCGARP && !err && copy_to_user(arg, &r, sizeof(r)))
+		err = -EFAULT;
 	return err;
 }
 
net/llc/af_llc.c +6 -5
index 5826129..dfd3a64 100644
@@ -316,9 +316,9 @@ static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
 	if (unlikely(addr->sllc_family != AF_LLC))
 		goto out;
 	rc = -ENODEV;
-	rtnl_lock();
+	rcu_read_lock();
 	if (sk->sk_bound_dev_if) {
-		llc->dev = dev_get_by_index(&init_net, sk->sk_bound_dev_if);
+		llc->dev = dev_get_by_index_rcu(&init_net, sk->sk_bound_dev_if);
 		if (llc->dev) {
 			if (!addr->sllc_arphrd)
 				addr->sllc_arphrd = llc->dev->type;
@@ -329,14 +329,15 @@ static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
 			    !llc_mac_match(addr->sllc_mac,
 					   llc->dev->dev_addr)) {
 				rc = -EINVAL;
-				dev_put(llc->dev);
 				llc->dev = NULL;
 			}
 		}
 	} else
-		llc->dev = dev_getbyhwaddr(&init_net, addr->sllc_arphrd,
+		llc->dev = dev_getbyhwaddr_rcu(&init_net, addr->sllc_arphrd,
 					   addr->sllc_mac);
-	rtnl_unlock();
+	if (llc->dev)
+		dev_hold(llc->dev);
+	rcu_read_unlock();
 	if (!llc->dev)
 		goto out;
 	if (!addr->sllc_sap) {
#7 lore raw

PATCH 1/1 llc: fix a device refcount imbalance

Quoted 8 lines · Eric Dumazet
Quoted 6 lines · Eric Dumazet

Hmm..

If somebody can explain why RTNL is held in arp_ioctl() (and therefore in arp_req_delete()), we might first remove RTNL use in arp_ioctl() so that your patch can be applied.

Quoted 5 lines
Quoted 2 lines

Right now it is not good, because RTNL wont be necessarly held when you are going to call arp_invalidate() ?

While doing this analysis, I found a refcount bug in llc, I'll send a patch for net-2.6

Oh well, of course I must first fix the bug in net-2.6, and wait David pull the fix in net-next-2.6 before sending this rcu conversion.

Note: this patch should be sent to stable teams (2.6.34 and up)

[PATCH net-2.6] llc: fix a device refcount imbalance

commit abf9d537fea225 (llc: add support for SO_BINDTODEVICE) added one refcount imbalance in llc_ui_bind(), because dev_getbyhwaddr() doesnt take a reference on device, while dev_get_by_index() does.

Fix this using RCU locking. And since an RCU conversion will be done for 2.6.38 for dev_getbyhwaddr(), put the rcu_read_lock/unlock exactly at their final place.

---
 net/llc/af_llc.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/llc/af_llc.c +3 -2
index 5826129..e35dbe5 100644
@@ -317,8 +317,9 @@ static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
 		goto out;
 	rc = -ENODEV;
 	rtnl_lock();
+	rcu_read_lock();
 	if (sk->sk_bound_dev_if) {
-		llc->dev = dev_get_by_index(&init_net, sk->sk_bound_dev_if);
+		llc->dev = dev_get_by_index_rcu(&init_net, sk->sk_bound_dev_if);
 		if (llc->dev) {
 			if (!addr->sllc_arphrd)
 				addr->sllc_arphrd = llc->dev->type;
@@ -329,13 +330,13 @@ static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
 			    !llc_mac_match(addr->sllc_mac,
 					   llc->dev->dev_addr)) {
 				rc = -EINVAL;
-				dev_put(llc->dev);
 				llc->dev = NULL;
 			}
 		}
 	} else
 		llc->dev = dev_getbyhwaddr(&init_net, addr->sllc_arphrd,
 					   addr->sllc_mac);
+	rcu_read_unlock();
 	rtnl_unlock();
 	if (!llc->dev)
 		goto out;
maintainer
#8 lore raw

Re: [PATCH net-2.6] llc: fix a device refcount imbalance

From: Eric Dumazet <[email protected]>
Date: Sun, 05 Dec 2010 13:03:26 +0100

Quoted 11 lines

[PATCH net-2.6] llc: fix a device refcount imbalance

commit abf9d537fea225 (llc: add support for SO_BINDTODEVICE) added one refcount imbalance in llc_ui_bind(), because dev_getbyhwaddr() doesnt take a reference on device, while dev_get_by_index() does.

Fix this using RCU locking. And since an RCU conversion will be done for 2.6.38 for dev_getbyhwaddr(), put the rcu_read_lock/unlock exactly at their final place.

Applied and queued up for -stable.

#9 lore raw

Re: [PATCH net-2.6] llc: fix a device refcount imbalance

Quoted 9 lines · David Miller

From: Eric Dumazet <[email protected]>
Date: Sun, 05 Dec 2010 13:03:26 +0100

Quoted 6 lines

[PATCH net-2.6] llc: fix a device refcount imbalance

commit abf9d537fea225 (llc: add support for SO_BINDTODEVICE) added one refcount imbalance in llc_ui_bind(), because dev_getbyhwaddr() doesnt take a reference on device, while dev_get_by_index() does.

Quoted 7 lines
Quoted 5 lines

Fix this using RCU locking. And since an RCU conversion will be done for 2.6.38 for dev_getbyhwaddr(), put the rcu_read_lock/unlock exactly at their final place.

Applied and queued up for -stable.

Hi,

Could I kindly ask if my patch is accepted?

Best regards,
Maxim Levitsky

#10 lore raw

Re: [PATCH net-2.6] llc: fix a device refcount imbalance

Quoted 16 lines · Maxim Levitsky
Quoted 15 lines · David Miller

From: Eric Dumazet <[email protected]>
Date: Sun, 05 Dec 2010 13:03:26 +0100

Quoted 11 lines

[PATCH net-2.6] llc: fix a device refcount imbalance

commit abf9d537fea225 (llc: add support for SO_BINDTODEVICE) added one refcount imbalance in llc_ui_bind(), because dev_getbyhwaddr() doesnt take a reference on device, while dev_get_by_index() does.

Fix this using RCU locking. And since an RCU conversion will be done for 2.6.38 for dev_getbyhwaddr(), put the rcu_read_lock/unlock exactly at their final place.

Quoted 9 lines
Quoted 1 line

Applied and queued up for -stable.

Hi,

Could I kindly ask if my patch is accepted?

Best regards,
Maxim Levitsky

Anybody?

Best regards,
Maxim Levitsky

maintainer Applied
#11 lore raw

Re: [PATCH] net: RCU conversion of dev_getbyhwaddr() and arp_ioctl()

In reply to Eric Dumazet

From: Eric Dumazet <[email protected]>
Date: Sun, 05 Dec 2010 12:23:53 +0100

Quoted 4 lines

[PATCH] net: RCU conversion of dev_getbyhwaddr() and arp_ioctl()

dev_getbyhwaddr() was called under RTNL.

Quoted 8 lines

Rename it to dev_getbyhwaddr_rcu() and change all its caller to now use RCU locking instead of RTNL.

Change arp_ioctl() to use RCU instead of RTNL locking.

Note: this fix a dev refcount bug in llc

Applied, thanks Eric.

#12 lore raw

Re: [PATCH] net: RCU conversion of dev_getbyhwaddr() and arp_ioctl()

Quoted 10 lines · David Miller

From: Eric Dumazet <[email protected]>
Date: Sun, 05 Dec 2010 12:23:53 +0100

Quoted 7 lines

[PATCH] net: RCU conversion of dev_getbyhwaddr() and arp_ioctl()

dev_getbyhwaddr() was called under RTNL.

Rename it to dev_getbyhwaddr_rcu() and change all its caller to now use RCU locking instead of RTNL.

Quoted 7 lines
Quoted 5 lines

Change arp_ioctl() to use RCU instead of RTNL locking.

Note: this fix a dev refcount bug in llc

Applied, thanks Eric.

Hmm, dont you want I resubmit it after the "llc: fix a device refcount imbalance" patch pulled from net-2.6 ?

Sorry for the mess...

maintainer
#13 lore raw

Re: [PATCH] net: RCU conversion of dev_getbyhwaddr() and arp_ioctl()

From: Eric Dumazet <[email protected]>
Date: Wed, 08 Dec 2010 19:07:34 +0100

Quoted 15 lines · David Miller
Quoted 14 lines

From: Eric Dumazet <[email protected]>
Date: Sun, 05 Dec 2010 12:23:53 +0100

Quoted 11 lines

[PATCH] net: RCU conversion of dev_getbyhwaddr() and arp_ioctl()

dev_getbyhwaddr() was called under RTNL.

Rename it to dev_getbyhwaddr_rcu() and change all its caller to now use RCU locking instead of RTNL.

Change arp_ioctl() to use RCU instead of RTNL locking.

Note: this fix a dev refcount bug in llc

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Applied, thanks Eric.

Hmm, dont you want I resubmit it after the "llc: fix a device refcount imbalance" patch pulled from net-2.6 ?

Sorry for the mess...

I know about the conflict and will resolve it when I do a merge in the next hour or so.

Don't worry about this.

#14 lore raw

Re: [PATCH] net: RCU conversion of dev_getbyhwaddr() and arp_ioctl()

Quoted 4 lines · David Miller

I know about the conflict and will resolve it when I do a merge in the next hour or so.

Don't worry about this.

Ah thats great, thanks !

#15 lore raw

Re: [PATCH 3/5] NET: IPV4: ARP: allow to invalidate specific ARP entries

In reply to Maxim Levitsky
Quoted 10 lines · Maxim Levitsky

IPv4 over firewire needs to be able to remove ARP entries from the ARP cache that belong to nodes that are removed, because IPv4 over firewire uses ARP packets for private information about nodes.

This information becomes invalid as soon as node drops off the bus and when it reconnects, its only possible to start takling to is after it responded to an ARP packet. But ARP cache prevents such packets from being sent.

Quoted 5 lines
CC "David S. Miller" <[email protected]>
CC Alexey Kuznetsov <[email protected]>
CC James Morris <[email protected]>
CC Patrick McHardy <[email protected]>

Anybody?

Best regards,
Maxim Levitsky

Quoted 73 lines
---
 include/net/arp.h |    1 +
 net/ipv4/arp.c    |   29 ++++++++++++++++++-----------
 2 files changed, 19 insertions(+), 11 deletions(-)
include/net/arp.h +1 -0
index f4cf6ce..91f0568 100644
@@ -25,5 +25,6 @@ extern struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip,
 				  const unsigned char *src_hw,
 				  const unsigned char *target_hw);
 extern void arp_xmit(struct sk_buff *skb);
+int arp_invalidate(struct net_device *dev, __be32 ip);
 
 #endif	/* _ARP_H */
net/ipv4/arp.c +18 -11
index d8e540c..35b1272 100644
@@ -1142,6 +1142,23 @@ static int arp_req_get(struct arpreq *r, struct net_device *dev)
 	return err;
 }
 
+int arp_invalidate(struct net_device *dev, __be32 ip)
+{
+	int err = -ENXIO;
+	struct neighbour *neigh = neigh_lookup(&arp_tbl, &ip, dev);
+
+	if (neigh) {
+		if (neigh->nud_state & ~NUD_NOARP)
+			err = neigh_update(neigh, NULL, NUD_FAILED,
+					   NEIGH_UPDATE_F_OVERRIDE|
+					   NEIGH_UPDATE_F_ADMIN);
+		neigh_release(neigh);
+	}
+
+	return err;
+}
+EXPORT_SYMBOL(arp_invalidate);
+
 static int arp_req_delete_public(struct net *net, struct arpreq *r,
 		struct net_device *dev)
 {
@@ -1162,7 +1179,6 @@ static int arp_req_delete(struct net *net, struct arpreq *r,
 {
 	int err;
 	__be32 ip;
-	struct neighbour *neigh;
 
 	if (r->arp_flags & ATF_PUBL)
 		return arp_req_delete_public(net, r, dev);
@@ -1180,16 +1196,7 @@ static int arp_req_delete(struct net *net, struct arpreq *r,
 		if (!dev)
 			return -EINVAL;
 	}
-	err = -ENXIO;
-	neigh = neigh_lookup(&arp_tbl, &ip, dev);
-	if (neigh) {
-		if (neigh->nud_state & ~NUD_NOARP)
-			err = neigh_update(neigh, NULL, NUD_FAILED,
-					   NEIGH_UPDATE_F_OVERRIDE|
-					   NEIGH_UPDATE_F_ADMIN);
-		neigh_release(neigh);
-	}
-	return err;
+	return arp_invalidate(dev, ip);
 }
 
 /*
#16 lore raw

Re: [PATCH 3/5] NET: IPV4: ARP: allow to invalidate specific ARP entries

Quoted 94 lines · Maxim Levitsky
Quoted 10 lines · Maxim Levitsky

IPv4 over firewire needs to be able to remove ARP entries from the ARP cache that belong to nodes that are removed, because IPv4 over firewire uses ARP packets for private information about nodes.

This information becomes invalid as soon as node drops off the bus and when it reconnects, its only possible to start takling to is after it responded to an ARP packet. But ARP cache prevents such packets from being sent.

Quoted 5 lines
CC "David S. Miller" <[email protected]>
CC Alexey Kuznetsov <[email protected]>
CC James Morris <[email protected]>
CC Patrick McHardy <[email protected]>

Anybody?

Best regards,
Maxim Levitsky

Quoted 72 lines
---
 include/net/arp.h |    1 +
 net/ipv4/arp.c    |   29 ++++++++++++++++++-----------
 2 files changed, 19 insertions(+), 11 deletions(-)
include/net/arp.h +1 -0
index f4cf6ce..91f0568 100644
@@ -25,5 +25,6 @@ extern struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip,
 				  const unsigned char *src_hw,
 				  const unsigned char *target_hw);
 extern void arp_xmit(struct sk_buff *skb);
+int arp_invalidate(struct net_device *dev, __be32 ip);
 
 #endif	/* _ARP_H */
net/ipv4/arp.c +18 -11
index d8e540c..35b1272 100644
@@ -1142,6 +1142,23 @@ static int arp_req_get(struct arpreq *r, struct net_device *dev)
 	return err;
 }
 
+int arp_invalidate(struct net_device *dev, __be32 ip)
+{
+	int err = -ENXIO;
+	struct neighbour *neigh = neigh_lookup(&arp_tbl, &ip, dev);
+
+	if (neigh) {
+		if (neigh->nud_state & ~NUD_NOARP)
+			err = neigh_update(neigh, NULL, NUD_FAILED,
+					   NEIGH_UPDATE_F_OVERRIDE|
+					   NEIGH_UPDATE_F_ADMIN);
+		neigh_release(neigh);
+	}
+
+	return err;
+}
+EXPORT_SYMBOL(arp_invalidate);
+
 static int arp_req_delete_public(struct net *net, struct arpreq *r,
 		struct net_device *dev)
 {
@@ -1162,7 +1179,6 @@ static int arp_req_delete(struct net *net, struct arpreq *r,
 {
 	int err;
 	__be32 ip;
-	struct neighbour *neigh;
 
 	if (r->arp_flags & ATF_PUBL)
 		return arp_req_delete_public(net, r, dev);
@@ -1180,16 +1196,7 @@ static int arp_req_delete(struct net *net, struct arpreq *r,
 		if (!dev)
 			return -EINVAL;
 	}
-	err = -ENXIO;
-	neigh = neigh_lookup(&arp_tbl, &ip, dev);
-	if (neigh) {
-		if (neigh->nud_state & ~NUD_NOARP)
-			err = neigh_update(neigh, NULL, NUD_FAILED,
-					   NEIGH_UPDATE_F_OVERRIDE|
-					   NEIGH_UPDATE_F_ADMIN);
-		neigh_release(neigh);
-	}
-	return err;
+	return arp_invalidate(dev, ip);
 }
 
Quoted 2 lines

net/ipv4/arp.c static int arp_req_delete(struct net *net, struct arpreq *r, · line 1202

Quoted 1 line
net/ipv4/arp.c +0 -0
 /*

Hi Maxim

You were supposed to respin your patch after my commit :

(941666c2e3e0f9f6a1 net: RCU conversion of dev_getbyhwaddr() and arp_ioctl())

Thanks

------------------------------------------------------------------------------
Gaining the trust of online customers is vital for the success of any company
that requires sensitive data to be transmitted over the Web. Learn how to
best implement a security strategy that keeps consumers' information secure and instills the confidence they need to proceed with transactions.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux1394-devel

#17 lore raw

Re: [PATCH 3/5] NET: IPV4: ARP: allow to invalidate specific ARP entries

Quoted 98 lines · Eric Dumazet
Quoted 94 lines · Maxim Levitsky
Quoted 10 lines · Maxim Levitsky

IPv4 over firewire needs to be able to remove ARP entries from the ARP cache that belong to nodes that are removed, because IPv4 over firewire uses ARP packets for private information about nodes.

This information becomes invalid as soon as node drops off the bus and when it reconnects, its only possible to start takling to is after it responded to an ARP packet. But ARP cache prevents such packets from being sent.

Quoted 5 lines
CC "David S. Miller" <[email protected]>
CC Alexey Kuznetsov <[email protected]>
CC James Morris <[email protected]>
CC Patrick McHardy <[email protected]>

Anybody?

Best regards,
Maxim Levitsky

Quoted 72 lines
---
 include/net/arp.h |    1 +
 net/ipv4/arp.c    |   29 ++++++++++++++++++-----------
 2 files changed, 19 insertions(+), 11 deletions(-)
include/net/arp.h +1 -0
index f4cf6ce..91f0568 100644
@@ -25,5 +25,6 @@ extern struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip,
 				  const unsigned char *src_hw,
 				  const unsigned char *target_hw);
 extern void arp_xmit(struct sk_buff *skb);
+int arp_invalidate(struct net_device *dev, __be32 ip);
 
 #endif	/* _ARP_H */
net/ipv4/arp.c +18 -11
index d8e540c..35b1272 100644
@@ -1142,6 +1142,23 @@ static int arp_req_get(struct arpreq *r, struct net_device *dev)
 	return err;
 }
 
+int arp_invalidate(struct net_device *dev, __be32 ip)
+{
+	int err = -ENXIO;
+	struct neighbour *neigh = neigh_lookup(&arp_tbl, &ip, dev);
+
+	if (neigh) {
+		if (neigh->nud_state & ~NUD_NOARP)
+			err = neigh_update(neigh, NULL, NUD_FAILED,
+					   NEIGH_UPDATE_F_OVERRIDE|
+					   NEIGH_UPDATE_F_ADMIN);
+		neigh_release(neigh);
+	}
+
+	return err;
+}
+EXPORT_SYMBOL(arp_invalidate);
+
 static int arp_req_delete_public(struct net *net, struct arpreq *r,
 		struct net_device *dev)
 {
@@ -1162,7 +1179,6 @@ static int arp_req_delete(struct net *net, struct arpreq *r,
 {
 	int err;
 	__be32 ip;
-	struct neighbour *neigh;
 
 	if (r->arp_flags & ATF_PUBL)
 		return arp_req_delete_public(net, r, dev);
@@ -1180,16 +1196,7 @@ static int arp_req_delete(struct net *net, struct arpreq *r,
 		if (!dev)
 			return -EINVAL;
 	}
-	err = -ENXIO;
-	neigh = neigh_lookup(&arp_tbl, &ip, dev);
-	if (neigh) {
-		if (neigh->nud_state & ~NUD_NOARP)
-			err = neigh_update(neigh, NULL, NUD_FAILED,
-					   NEIGH_UPDATE_F_OVERRIDE|
-					   NEIGH_UPDATE_F_ADMIN);
-		neigh_release(neigh);
-	}
-	return err;
+	return arp_invalidate(dev, ip);
 }
 
Quoted 2 lines

net/ipv4/arp.c static int arp_req_delete(struct net *net, struct arpreq *r, · line 1202

Quoted 1 line
net/ipv4/arp.c +0 -0
 /*
Quoted 8 lines

Hi Maxim

You were supposed to respin your patch after my commit :

(941666c2e3e0f9f6a1 net: RCU conversion of dev_getbyhwaddr() and arp_ioctl())

Thanks

Will do very soon.

Best regards,
Maxim Levitsky

#18 lore raw

Re: [PATCH 3/5] NET: IPV4: ARP: allow to invalidate specific ARP entries

In reply to Eric Dumazet
Quoted 98 lines · Eric Dumazet
Quoted 94 lines · Maxim Levitsky
Quoted 10 lines · Maxim Levitsky

IPv4 over firewire needs to be able to remove ARP entries from the ARP cache that belong to nodes that are removed, because IPv4 over firewire uses ARP packets for private information about nodes.

This information becomes invalid as soon as node drops off the bus and when it reconnects, its only possible to start takling to is after it responded to an ARP packet. But ARP cache prevents such packets from being sent.

Quoted 5 lines
CC "David S. Miller" <[email protected]>
CC Alexey Kuznetsov <[email protected]>
CC James Morris <[email protected]>
CC Patrick McHardy <[email protected]>

Anybody?

Best regards,
Maxim Levitsky

Quoted 72 lines
---
 include/net/arp.h |    1 +
 net/ipv4/arp.c    |   29 ++++++++++++++++++-----------
 2 files changed, 19 insertions(+), 11 deletions(-)
include/net/arp.h +1 -0
index f4cf6ce..91f0568 100644
@@ -25,5 +25,6 @@ extern struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip,
 				  const unsigned char *src_hw,
 				  const unsigned char *target_hw);
 extern void arp_xmit(struct sk_buff *skb);
+int arp_invalidate(struct net_device *dev, __be32 ip);
 
 #endif	/* _ARP_H */
net/ipv4/arp.c +18 -11
index d8e540c..35b1272 100644
@@ -1142,6 +1142,23 @@ static int arp_req_get(struct arpreq *r, struct net_device *dev)
 	return err;
 }
 
+int arp_invalidate(struct net_device *dev, __be32 ip)
+{
+	int err = -ENXIO;
+	struct neighbour *neigh = neigh_lookup(&arp_tbl, &ip, dev);
+
+	if (neigh) {
+		if (neigh->nud_state & ~NUD_NOARP)
+			err = neigh_update(neigh, NULL, NUD_FAILED,
+					   NEIGH_UPDATE_F_OVERRIDE|
+					   NEIGH_UPDATE_F_ADMIN);
+		neigh_release(neigh);
+	}
+
+	return err;
+}
+EXPORT_SYMBOL(arp_invalidate);
+
 static int arp_req_delete_public(struct net *net, struct arpreq *r,
 		struct net_device *dev)
 {
@@ -1162,7 +1179,6 @@ static int arp_req_delete(struct net *net, struct arpreq *r,
 {
 	int err;
 	__be32 ip;
-	struct neighbour *neigh;
 
 	if (r->arp_flags & ATF_PUBL)
 		return arp_req_delete_public(net, r, dev);
@@ -1180,16 +1196,7 @@ static int arp_req_delete(struct net *net, struct arpreq *r,
 		if (!dev)
 			return -EINVAL;
 	}
-	err = -ENXIO;
-	neigh = neigh_lookup(&arp_tbl, &ip, dev);
-	if (neigh) {
-		if (neigh->nud_state & ~NUD_NOARP)
-			err = neigh_update(neigh, NULL, NUD_FAILED,
-					   NEIGH_UPDATE_F_OVERRIDE|
-					   NEIGH_UPDATE_F_ADMIN);
-		neigh_release(neigh);
-	}
-	return err;
+	return arp_invalidate(dev, ip);
 }
 
Quoted 2 lines

net/ipv4/arp.c static int arp_req_delete(struct net *net, struct arpreq *r, · line 1202

Quoted 1 line
net/ipv4/arp.c +0 -0
 /*
Quoted 8 lines

Hi Maxim

You were supposed to respin your patch after my commit :

(941666c2e3e0f9f6a1 net: RCU conversion of dev_getbyhwaddr() and arp_ioctl())

Thanks

Hi,

After looking at the code (and honestly its hard to work with it as it has no documentation at all), I think I don't need any changes in my patch.

Here is the latest version for I use with the above commit applied (it is in mainline now).

---

commit 7da91d68d78b6a44ba6337be3b29b22ba2909b9e

Author: Maxim Levitsky <[email protected]>
Date:   Sat Nov 27 00:50:45 2010 +0200

NET: IPV4: ARP: allow to invalidate specific ARP entries

IPv4 over firewire needs to be able to remove ARP entries from the ARP cache that belong to nodes that are removed, because IPv4 over firewire uses ARP packets for private information about nodes.

This information becomes invalid as soon as node drops off the bus and when it reconnects, its only possible to start takling to is after it responded to an ARP packet. But ARP cache prevents such packets from being sent.

CC "David S. Miller" <[email protected]>
CC Alexey Kuznetsov <[email protected]>
CC James Morris <[email protected]>
CC Patrick McHardy <[email protected]>
include/net/arp.h +1 -0
index f4cf6ce..91f0568 100644
@@ -25,5 +25,6 @@ extern struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip,
 				  const unsigned char *src_hw,
 				  const unsigned char *target_hw);
 extern void arp_xmit(struct sk_buff *skb);
+int arp_invalidate(struct net_device *dev, __be32 ip);
 
 #endif	/* _ARP_H */
net/ipv4/arp.c +18 -11
index a2fc7b9..e941c75 100644
@@ -1143,6 +1143,23 @@ static int arp_req_get(struct arpreq *r, struct net_device *dev)
 	return err;
 }
 
+int arp_invalidate(struct net_device *dev, __be32 ip)
+{
+	int err = -ENXIO;
+	struct neighbour *neigh = neigh_lookup(&arp_tbl, &ip, dev);
+
+	if (neigh) {
+		if (neigh->nud_state & ~NUD_NOARP)
+			err = neigh_update(neigh, NULL, NUD_FAILED,
+					   NEIGH_UPDATE_F_OVERRIDE|
+					   NEIGH_UPDATE_F_ADMIN);
+		neigh_release(neigh);
+	}
+
+	return err;
+}
+EXPORT_SYMBOL(arp_invalidate);
+
 static int arp_req_delete_public(struct net *net, struct arpreq *r,
 		struct net_device *dev)
 {
@@ -1163,7 +1180,6 @@ static int arp_req_delete(struct net *net, struct arpreq *r,
 {
 	int err;
 	__be32 ip;
-	struct neighbour *neigh;
 
 	if (r->arp_flags & ATF_PUBL)
 		return arp_req_delete_public(net, r, dev);
@@ -1181,16 +1197,7 @@ static int arp_req_delete(struct net *net, struct arpreq *r,
 		if (!dev)
 			return -EINVAL;
 	}
-	err = -ENXIO;
-	neigh = neigh_lookup(&arp_tbl, &ip, dev);
-	if (neigh) {
-		if (neigh->nud_state & ~NUD_NOARP)
-			err = neigh_update(neigh, NULL, NUD_FAILED,
-					   NEIGH_UPDATE_F_OVERRIDE|
-					   NEIGH_UPDATE_F_ADMIN);
-		neigh_release(neigh);
-	}
-	return err;
+	return arp_invalidate(dev, ip);
 }
 
 /*
maintainer Applied
#19 lore raw

Re: [PATCH 3/5] NET: IPV4: ARP: allow to invalidate specific ARP entries

From: Maxim Levitsky <[email protected]>
Date: Sun, 09 Jan 2011 01:57:12 +0200

Quoted 7 lines

NET: IPV4: ARP: allow to invalidate specific ARP entries

IPv4 over firewire needs to be able to remove ARP entries from the ARP cache that belong to nodes that are removed, because IPv4 over firewire uses ARP packets for private information about nodes.

Quoted 6 lines

This information becomes invalid as soon as node drops off the bus and when it reconnects, its only possible to start takling to is after it responded to an ARP packet. But ARP cache prevents such packets from being sent.

Applied, thanks.

#20 lore raw

PATCH v2 4/5 firewire: net: invalidate ARP entries of removed nodes.

In reply to Maxim Levitsky

This makes it possible to resume communication with a node that dropped off the bus for a brief period. Otherwice communication will only be possible after ARP cache entry timeouts

---
 drivers/firewire/net.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
drivers/firewire/net.c +7 -0
index 1a467a9..d422519 100644
@@ -189,6 +189,7 @@ struct fwnet_peer {
 	struct fwnet_device *dev;
 	u64 guid;
 	u64 fifo;
+	__be32 ip;
 
 	/* guarded by dev->lock */
 	struct list_head pd_list; /* received partial datagrams */
@@ -568,6 +569,8 @@ static int fwnet_finish_incoming_packet(struct net_device *net,
 				peer->speed = sspd;
 			if (peer->max_payload > max_payload)
 				peer->max_payload = max_payload;
+
+			peer->ip = arp1394->sip;
 		}
 		spin_unlock_irqrestore(&dev->lock, flags);
 
@@ -1443,6 +1446,7 @@ static int fwnet_add_peer(struct fwnet_device *dev,
 	peer->dev = dev;
 	peer->guid = (u64)device->config_rom[3] << 32 | device->config_rom[4];
 	peer->fifo = FWNET_NO_FIFO_ADDR;
+	peer->ip = 0;
 	INIT_LIST_HEAD(&peer->pd_list);
 	peer->pdg_size = 0;
 	peer->datagram_label = 0;
@@ -1558,6 +1562,9 @@ static int fwnet_remove(struct device *_dev)
 
 	mutex_lock(&fwnet_device_mutex);
 
+	if (dev->netdev && peer->ip)
+		arp_invalidate(dev->netdev, peer->ip);
+
 	fwnet_remove_peer(peer);
 
 	if (list_empty(&dev->peer_list)) {
Signature · 1 line
1.7.1
#21 lore raw

PATCH v2 5/5 firewire: net: ratelimit error messages

In reply to Maxim Levitsky

Unfortunelly its easy to trigger such error messages by removing the cable while sending streams of data over the link.

Such errors are normal, and therefore this patch
stops firewire-net from flooding the kernel log
with these errors,
by combining series of same errors together.

---
 drivers/firewire/net.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)
drivers/firewire/net.c +12 -4
index d422519..ac563d6 100644
@@ -999,15 +999,23 @@ static void fwnet_transmit_packet_failed(struct fwnet_packet_task *ptask)
 static void fwnet_write_complete(struct fw_card *card, int rcode,
 				 void *payload, size_t length, void *data)
 {
-	struct fwnet_packet_task *ptask;
-
-	ptask = data;
+	struct fwnet_packet_task *ptask = data;
+	static unsigned long j;
+	static int last_rcode, errors_skipped;
 
 	if (rcode == RCODE_COMPLETE) {
 		fwnet_transmit_packet_done(ptask);
 	} else {
-		fw_error("fwnet_write_complete: failed: %x\n", rcode);
 		fwnet_transmit_packet_failed(ptask);
+
+		if (printk_timed_ratelimit(&j,  1000) || rcode != last_rcode) {
+			fw_error("fwnet_write_complete: "
+				"failed: %x (skipped %d)\n", rcode, errors_skipped);
+
+			errors_skipped = 0;
+			last_rcode = rcode;
+		} else
+			errors_skipped++;
 	}
 }
 
Signature · 1 line
1.7.1
#22 lore raw
In reply to Maxim Levitsky
Quoted 2 lines · On Nov 29 Maxim Levitsky wrote:

This is updated version of the patches.
I updated the changelogs, addressed comments on patch #2

I haven't applied and tested these patches yet but they look good to me.

Regarding 3/5 (and 4/5 which depends on it), I need of course an ack from an IPv4 maintainer, or a comment on how to do it differently if desired.

Patch 5/5 looks good for the next one or two kernel releases. If progress with firewire-net/-ohci stabilization keeps going like it does at the moment, we can later remove this logging entirely. (There is still the cancel_packet issue to tackle in fw-ohci/-core.)

Signature · 3 lines
Stefan Richter
-=====-==-=- =-== ===-=
http://arcgraph.de/sr/
#23 lore raw
In reply to Maxim Levitsky
Quoted 8 lines · Maxim Levitsky

Hi,

This is updated version of the patches.
I updated the changelogs, addressed comments on patch #2

Best regards,
Maxim Levitsky

Any update?

Best regards,
Maxim Levitsky

#24 lore raw
In reply to Maxim Levitsky
Quoted 8 lines · Maxim Levitsky

Hi,

This is updated version of the patches.
I updated the changelogs, addressed comments on patch #2

Best regards,
Maxim Levitsky

Today I have achieved the ultimate goal,
full support of firewire networking via NetworkManager.

Currently it is patched with few hacks but much less that I expected.

I also had to patch dhclient as it unfortunately sends raw packets together with hardware header (ethernet of course...)

I will soon clean up these hacks to turn them into patches and send to developers.

The kernel side needs only the attached patch.
It adds the link state detection to firewire-net

Just for fun, this is screenshot that proves that NM works:
http://img210.imageshack.us/img210/6019/screenshotdjk.png

Of course, I still need to clean up the patches to NM and dhclient, so more correctly I am not fully done yet.

Best regards,
Maxim Levitsky

Quoted 1 line

From d42274653bc06583871ec3230f8308236aff92c2 Mon Sep 17 00:00:00 2001

From: Maxim Levitsky <[email protected]>
Date: Wed, 8 Dec 2010 04:22:57 +0200
Subject: [PATCH] firewire: net: add carrier detection

To make userland, eg NM work with firewire
we need to be able if cable is plugged or not.

Simple and correct way of doing that is just couning number of peers.

No peers - no link and vise versa.

Best regards,
Maxim Levitsky

---
 drivers/firewire/net.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)
drivers/firewire/net.c +17 -0
index ac563d6..67bad9c 100644
@@ -178,6 +178,7 @@ struct fwnet_device {
 
 	/* Number of tx datagrams that have been queued but not yet acked */
 	int queued_datagrams;
+	int peer_count;
 
 	struct list_head peer_list;
 	struct fw_card *card;
@@ -1408,6 +1409,10 @@ static int fwnet_change_mtu(struct net_device *net, int new_mtu)
 	return 0;
 }
 
+static const struct ethtool_ops fwnet_ethtool_ops = {
+	.get_link	= ethtool_op_get_link,
+};
+
 static const struct net_device_ops fwnet_netdev_ops = {
 	.ndo_open       = fwnet_open,
 	.ndo_stop	= fwnet_stop,
@@ -1426,6 +1431,8 @@ static void fwnet_init_dev(struct net_device *net)
 	net->hard_header_len	= FWNET_HLEN;
 	net->type		= ARPHRD_IEEE1394;
 	net->tx_queue_len	= FWNET_TX_QUEUE_LEN;
+	net->ethtool_ops	= &fwnet_ethtool_ops;
+
 }
 
 /* caller must hold fwnet_device_mutex */
@@ -1467,6 +1474,7 @@ static int fwnet_add_peer(struct fwnet_device *dev,
 
 	spin_lock_irq(&dev->lock);
 	list_add_tail(&peer->peer_link, &dev->peer_list);
+	dev->peer_count++;
 	spin_unlock_irq(&dev->lock);
 
 	return 0;
@@ -1538,6 +1546,9 @@ static int fwnet_probe(struct device *_dev)
 		unregister_netdev(net);
 		list_del(&dev->dev_link);
 	}
+
+	if (dev->peer_count > 1)
+		netif_carrier_on(net);
  out:
 	if (ret && allocated_netdev)
 		free_netdev(net);
@@ -1553,6 +1564,7 @@ static void fwnet_remove_peer(struct fwnet_peer *peer)
 
 	spin_lock_irq(&peer->dev->lock);
 	list_del(&peer->peer_link);
+	peer->dev->peer_count--;
 	spin_unlock_irq(&peer->dev->lock);
 
 	list_for_each_entry_safe(pd, pd_next, &peer->pd_list, pd_link)
@@ -1575,6 +1587,11 @@ static int fwnet_remove(struct device *_dev)
 
 	fwnet_remove_peer(peer);
 
+	/* If we serve just one node, that means we lost link
+		with outer world */
+	if (dev->peer_count == 1)
+		netif_carrier_off(dev->netdev);
+
 	if (list_empty(&dev->peer_list)) {
 		net = dev->netdev;
 		unregister_netdev(net);
Signature · 1 line
1.7.1
#25 lore raw
Quoted 18 lines · Maxim Levitsky
Quoted 8 lines · Maxim Levitsky

Hi,

This is updated version of the patches.
I updated the changelogs, addressed comments on patch #2

Best regards,
Maxim Levitsky

Today I have achieved the ultimate goal,
full support of firewire networking via NetworkManager.

Currently it is patched with few hacks but much less that I expected.

I also had to patch dhclient as it unfortunately sends raw packets together with hardware header (ethernet of course...)

Quoted 8 lines

I will soon clean up these hacks to turn them into patches and send to developers.

The kernel side needs only the attached patch.
It adds the link state detection to firewire-net

Just for fun, this is screenshot that proves that NM works:
http://img210.imageshack.us/img210/6019/screenshotdjk.png

And cleaned up patches that add the support attached. Will send these to NM and dhcp ML soon.

Best regards,
Maxim Levitsky

Quoted 1 line

From 09750594f8c861d58762969d4fe1f1b3b81b0b5f Mon Sep 17 00:00:00 2001

From: Maxim Levitsky <[email protected]>
Date: Thu, 9 Dec 2010 02:49:23 +0200
Subject: [PATCH] Add support for RFC2855, DHCP over IEEE1394

---
 client/dhclient.c    |   18 ++++++++++
 common/Makefile.dist |    6 ++-
 common/discover.c    |   15 ++++++--
 common/firewire.c    |   90 ++++++++++++++++++++++++++++++++++++++++++++++++++
 common/lpf.c         |    9 ++++-
 common/packet.c      |   13 +++++++
 includes/dhcpd.h     |    7 ++++
 7 files changed, 151 insertions(+), 7 deletions(-)
 create mode 100644 common/firewire.c
client/dhclient.c +18 -0
index a9a0993..5f079b3 100644
@@ -1890,6 +1890,24 @@ void make_client_options (client, lease, type, sid, rip, prl, op)
 		client -> requested_address.len = 0;
 	}
 
+#ifdef HAVE_ARPHRD_IEEE1394
+	/* Per RFC2855, send hardware address inside client identifier
+		by default*/
+	if (client -> interface -> hw_address.hbuf [0] == ARPHRD_IEEE1394) {
+		i = DHO_DHCP_CLIENT_IDENTIFIER;
+		if (!(option_code_hash_lookup(&option, dhcp_universe.code_hash,
+						&i, 0, MDL) &&
+			make_const_option_cache(&oc, NULL,
+				&client -> interface -> hw_address.hbuf [1], 8,
+						option, MDL)))
+			log_error ("can't make requested address cache.");
+		else {
+			save_option (&dhcp_universe, *op, oc);
+			option_cache_dereference (&oc, MDL);
+		}
+		option_dereference(&option, MDL);
+	}
+#endif
 	i = DHO_DHCP_MESSAGE_TYPE;
 	if (!(option_code_hash_lookup(&option, dhcp_universe.code_hash, &i, 0,
 				      MDL) &&
common/Makefile.dist +4 -2
index 2b9faee..52f280b 100644
@@ -23,11 +23,13 @@
 CATMANPAGES = dhcp-options.cat5 dhcp-eval.cat5
 SEDMANPAGES = dhcp-options.man5 dhcp-eval.man5
 SRC    = raw.c parse.c nit.c icmp.c dispatch.c conflex.c upf.c bpf.c socket.c \
-	 lpf.c dlpi.c packet.c tr.c ethernet.c memory.c print.c options.c \
+	 lpf.c dlpi.c packet.c tr.c ethernet.c firewire.c \
+	 memory.c print.c options.c \
 	 inet.c tree.c tables.c alloc.c fddi.c ctrace.c dns.c resolv.c \
 	 execute.c discover.c comapi.c
 OBJ    = raw.o parse.o nit.o icmp.o dispatch.o conflex.o upf.o bpf.o socket.o \
-	 lpf.o dlpi.o packet.o tr.o ethernet.o memory.o print.o options.o \
+	 lpf.o dlpi.o packet.o tr.o ethernet.o firewire.o \
+	 memory.o print.o options.o \
 	 inet.o tree.o tables.o alloc.o fddi.o ctrace.o dns.o resolv.o \
 	 execute.o discover.o comapi.o
 MAN    = dhcp-options.5 dhcp-eval.5
common/discover.c +11 -4
index 69d23b1..979b1c4 100644
@@ -471,15 +471,22 @@ void discover_interfaces (state)
 		     case ARPHRD_SIT:
 			/* ignore IPv6-in-IPv4 interfaces. */
 #endif
-#ifdef HAVE_ARPHRD_IEEE1394
-		     case ARPHRD_IEEE1394:
-			/* ignore IEEE1394 interfaces. */
-#endif
 #ifdef HAVE_ARPHRD_LOOPBACK
 		      case ARPHRD_LOOPBACK:
 			/* ignore loopback interface */
 			break;
 #endif
+#ifdef HAVE_ARPHRD_IEEE1394
+		     case ARPHRD_IEEE1394:
+			/* According to RFC2855, we set hlen to 0,
+			but store hardware address in the client ID,
+			so store hardware address but set len to 0 */
+			tmp -> hw_address.hlen = 1;
+			tmp -> hw_address.hbuf [0] = ARPHRD_IEEE1394;
+			memcpy (&tmp -> hw_address.hbuf [1], sa.sa_data, 8);
+			break;
+#endif
+
 
 		      case ARPHRD_ETHER:
 			tmp -> hw_address.hlen = 7;
common/firewire.c new file +90 -0

90 lines not on this page · raw message

common/lpf.c +8 -1
index 5922660..a3fafef 100644
@@ -181,6 +181,13 @@ void if_register_receive (info)
 		lpf_tr_filter_setup (info);
 	else
 #endif
+#if defined (HAVE_ARPHRD_IEEE1394)
+	/* FIXME: this currently piggybacks on TR no-op filter, as
+		generic filter don't work for FW */
+	if (info -> hw_address.hbuf[0] == ARPHRD_IEEE1394)
+		lpf_tr_filter_setup (info);
+	else
+#endif
 		lpf_gen_filter_setup (info);
 
 	if (!quiet_interface_discovery)
@@ -245,7 +252,7 @@ static void lpf_gen_filter_setup (info)
 	}
 }
 
-#if defined (HAVE_TR_SUPPORT)
+#if defined (HAVE_TR_SUPPORT) || defined (HAVE_ARPHRD_IEEE1394)
 static void lpf_tr_filter_setup (info)
 	struct interface_info *info;
 {
common/packet.c +13 -0
index 4c878a6..378114e 100644
@@ -111,6 +111,8 @@ void assemble_hw_header (interface, buf, bufix, to)
 	unsigned *bufix;
 	struct hardware *to;
 {
+
+
 #if defined (HAVE_TR_SUPPORT)
 	if (interface -> hw_address.hbuf [0] == HTYPE_IEEE802)
 		assemble_tr_header (interface, buf, bufix, to);
@@ -121,6 +123,11 @@ void assemble_hw_header (interface, buf, bufix, to)
 		     assemble_fddi_header (interface, buf, bufix, to);
 	else
 #endif
+#if defined (HAVE_ARPHRD_IEEE1394)
+	     if (interface -> hw_address.hbuf [0] == ARPHRD_IEEE1394)
+		     assemble_fw_header(interface, buf, bufix, to);
+#endif
+	else
 		assemble_ethernet_header (interface, buf, bufix, to);
 
 }
@@ -198,6 +205,7 @@ ssize_t decode_hw_header (interface, buf, bufix, from)
      unsigned bufix;
      struct hardware *from;
 {
+
 #if defined (HAVE_TR_SUPPORT)
 	if (interface -> hw_address.hbuf [0] == HTYPE_IEEE802)
 		return decode_tr_header (interface, buf, bufix, from);
@@ -208,6 +216,11 @@ ssize_t decode_hw_header (interface, buf, bufix, from)
 		     return decode_fddi_header (interface, buf, bufix, from);
 	else
 #endif
+#if defined (HAVE_ARPHRD_IEEE1394)
+	     if (interface -> hw_address.hbuf [0] == ARPHRD_IEEE1394)
+		     return decode_fw_header (interface, buf, bufix, from);
+#endif
+	else
 		return decode_ethernet_header (interface, buf, bufix, from);
 }
 
includes/dhcpd.h +7 -0
index 50b899c..95b119a 100644
@@ -2135,6 +2135,13 @@ ssize_t decode_tr_header PROTO ((struct interface_info *,
 				 unsigned char *,
 				 unsigned, struct hardware *));
 
+/* firewire.c */
+void assemble_fw_header PROTO ((struct interface_info *, unsigned char *,
+				unsigned *, struct hardware *));
+ssize_t decode_fw_header PROTO ((struct interface_info *,
+				 unsigned char *,
+				 unsigned, struct hardware *));
+
 /* dhxpxlt.c */
 void convert_statement PROTO ((struct parse *));
 void convert_host_statement PROTO ((struct parse *, jrefproto));
Signature · 1 line
1.7.1
Quoted 1 line

From 93129738ca8450899e416420f630aee17c8301d5 Mon Sep 17 00:00:00 2001

From: Maxim Levitsky <[email protected]>
Date: Thu, 9 Dec 2010 00:30:55 +0200
Subject: [PATCH] NM: allow use of IPV4 over firewire

Don't ignore these devices since NM
works just fine with them iff the dhclient
works.
Patches are posted to make it work with
firewire networking link

---
 src/nm-udev-manager.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
src/nm-udev-manager.c +3 -1
index ff0ef68..3cd2970 100644
@@ -408,7 +408,9 @@ net_add (NMUdevManager *self, GUdevDevice *device)
 	g_return_if_fail (device != NULL);
 
 	etype = g_udev_device_get_sysfs_attr_as_int (device, "type");
-	if (etype != 1) {
+
+	/* firewire devices are similiar to ethernet, so allow them too */
+	if (etype != 1 && etype != 24) {
 		nm_log_dbg (LOGD_HW, "ignoring interface with type %d", etype);
 		return; /* Not using ethernet encapsulation, don't care */
 	}
Signature · 1 line
1.7.1

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): 1291809485.5421.0.camel@maxim-laptop

#28 lore raw

PATCH 1/1 firewire: net: add carrier detection

From: Maxim Levitsky <[email protected]>

To make userland, e.g. NetworkManager work with firewire, we need to detect whether cable is plugged or not. Simple and correct way of doing that is just counting number of peers. No peers - no link and vice versa.

---
Update: Moved netif_carrier_on/off calls into lock-protected sections.

 drivers/firewire/net.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/firewire/net.c +10 -0
Index: b/drivers/firewire/net.c
===================================================================
@@ -179,6 +179,7 @@ struct fwnet_device {
 	/* Number of tx datagrams that have been queued but not yet acked */
 	int queued_datagrams;
 
+	int peer_count;
 	struct list_head peer_list;
 	struct fw_card *card;
 	struct net_device *netdev;
@@ -1405,6 +1406,10 @@ static int fwnet_change_mtu(struct net_d
 	return 0;
 }
 
+static const struct ethtool_ops fwnet_ethtool_ops = {
+	.get_link	= ethtool_op_get_link,
+};
+
 static const struct net_device_ops fwnet_netdev_ops = {
 	.ndo_open       = fwnet_open,
 	.ndo_stop	= fwnet_stop,
@@ -1423,6 +1428,7 @@ static void fwnet_init_dev(struct net_de
 	net->hard_header_len	= FWNET_HLEN;
 	net->type		= ARPHRD_IEEE1394;
 	net->tx_queue_len	= FWNET_TX_QUEUE_LEN;
+	net->ethtool_ops	= &fwnet_ethtool_ops;
 }
 
 /* caller must hold fwnet_device_mutex */
@@ -1463,6 +1469,8 @@ static int fwnet_add_peer(struct fwnet_d
 
 	spin_lock_irq(&dev->lock);
 	list_add_tail(&peer->peer_link, &dev->peer_list);
+	if (++dev->peer_count > 1)
+		netif_carrier_on(dev->netdev);
 	spin_unlock_irq(&dev->lock);
 
 	return 0;
@@ -1549,6 +1557,8 @@ static void fwnet_remove_peer(struct fwn
 
 	spin_lock_irq(&peer->dev->lock);
 	list_del(&peer->peer_link);
+	if (--peer->dev->peer_count == 1)
+		netif_carrier_off(peer->dev->netdev);
 	spin_unlock_irq(&peer->dev->lock);
 
 	list_for_each_entry_safe(pd, pd_next, &peer->pd_list, pd_link)
Signature · 3 lines
Stefan Richter
-=====-==-=- ==-- -==--
http://arcgraph.de/sr/
#29 lore raw

Re: [PATCH update] firewire: net: add carrier detection

Quoted 6 lines · Stefan Richter

From: Maxim Levitsky <[email protected]>

To make userland, e.g. NetworkManager work with firewire, we need to detect whether cable is plugged or not. Simple and correct way of doing that is just counting number of peers. No peers - no link and vice versa.

[...]

NM doesn't use ETHTOOL_GLINK so you don't need to implement ethtool_ops::get_link.

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#30 lore raw

PATCH 1/1 firewire: net: add carrier detection

From: Maxim Levitsky <[email protected]>

To make userland, e.g. NetworkManager work with firewire, we need to detect whether cable is plugged or not. Simple and correct way of doing that is just counting number of peers. No peers - no link and vice versa.

(Stefan R.: Drop ethtool_ops.get_link)

---
Update 2: Removed ethtool related hunks; dev->peer_count does not need to be accessed within the spinlock as I first thought; reduced pointer reference depth in fwnet_remove_peer.

Maxim, do you observe a remaining need for a get_link implementation? I can't tell, I use rather minimal userland that doesn't care for link status.

 drivers/firewire/net.c |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/firewire/net.c +12 -4
Index: b/drivers/firewire/net.c
===================================================================
@@ -179,6 +179,7 @@ struct fwnet_device {
 	/* Number of tx datagrams that have been queued but not yet acked */
 	int queued_datagrams;
 
+	int peer_count;
 	struct list_head peer_list;
 	struct fw_card *card;
 	struct net_device *netdev;
@@ -1465,6 +1466,10 @@ static int fwnet_add_peer(struct fwnet_d
 	list_add_tail(&peer->peer_link, &dev->peer_list);
 	spin_unlock_irq(&dev->lock);
 
+	/* dev->peer_count acess is serialized by fwnet_device_mutex. */
+	if (++dev->peer_count > 1)
+		netif_carrier_on(dev->netdev);
+
 	return 0;
 }
 
@@ -1543,13 +1548,16 @@ static int fwnet_probe(struct device *_d
 	return ret;
 }
 
-static void fwnet_remove_peer(struct fwnet_peer *peer)
+static void fwnet_remove_peer(struct fwnet_peer *peer, struct fwnet_device *dev)
 {
 	struct fwnet_partial_datagram *pd, *pd_next;
 
-	spin_lock_irq(&peer->dev->lock);
+	if (--dev->peer_count == 1)
+		netif_carrier_off(dev->netdev);
+
+	spin_lock_irq(&dev->lock);
 	list_del(&peer->peer_link);
-	spin_unlock_irq(&peer->dev->lock);
+	spin_unlock_irq(&dev->lock);
 
 	list_for_each_entry_safe(pd, pd_next, &peer->pd_list, pd_link)
 		fwnet_pd_delete(pd);
@@ -1566,7 +1574,7 @@ static int fwnet_remove(struct device *_
 
 	mutex_lock(&fwnet_device_mutex);
 
-	fwnet_remove_peer(peer);
+	fwnet_remove_peer(peer, dev);
 
 	if (list_empty(&dev->peer_list)) {
 		net = dev->netdev;
Signature · 9 lines
Stefan Richter
-=====-==-=- ==-- -==-=
http://arcgraph.de/sr/

------------------------------------------------------------------------------
Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL,
new data types, scalar functions, improved concurrency, built-in packages, 
OCI, SQL*Plus, data movement tools, best practices and more.
http://p.sf.net/sfu/oracle-sfdev2dev 
#31 lore raw

PATCH 1/1 firewire: net: add carrier detection

From: Maxim Levitsky <[email protected]>

To make userland, e.g. NetworkManager work with firewire, we need to detect whether cable is plugged or not. Simple and correct way of doing that is just counting number of peers. No peers - no link and vice versa.

(Stefan R.: Combined peer_count inc/dec with tests, added link-down recognition in fwnet_open, added include.)

---
Update 3: added fwnet_open (ifup) hunk

 drivers/firewire/net.c |   29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)
drivers/firewire/net.c +25 -4
Index: b/drivers/firewire/net.c
===================================================================
@@ -9,6 +9,7 @@
 #include <linux/bug.h>
 #include <linux/delay.h>
 #include <linux/device.h>
+#include <linux/ethtool.h>
 #include <linux/firewire.h>
 #include <linux/firewire-constants.h>
 #include <linux/highmem.h>
@@ -179,6 +180,7 @@ struct fwnet_device {
 	/* Number of tx datagrams that have been queued but not yet acked */
 	int queued_datagrams;
 
+	int peer_count;
 	struct list_head peer_list;
 	struct fw_card *card;
 	struct net_device *netdev;
@@ -1234,6 +1236,13 @@ static int fwnet_open(struct net_device 
 	}
 	netif_start_queue(net);
 
+	mutex_lock(&fwnet_device_mutex);
+	if (dev->peer_count > 1)
+		netif_carrier_on(net);
+	else
+		netif_carrier_off(net);
+	mutex_unlock(&fwnet_device_mutex);
+
 	return 0;
 }
 
@@ -1412,6 +1421,10 @@ static const struct net_device_ops fwnet
 	.ndo_change_mtu = fwnet_change_mtu,
 };
 
+static const struct ethtool_ops fwnet_ethtool_ops = {
+	.get_link	= ethtool_op_get_link,
+};
+
 static void fwnet_init_dev(struct net_device *net)
 {
 	net->header_ops		= &fwnet_header_ops;
@@ -1423,6 +1436,7 @@ static void fwnet_init_dev(struct net_de
 	net->hard_header_len	= FWNET_HLEN;
 	net->type		= ARPHRD_IEEE1394;
 	net->tx_queue_len	= FWNET_TX_QUEUE_LEN;
+	net->ethtool_ops	= &fwnet_ethtool_ops;
 }
 
 /* caller must hold fwnet_device_mutex */
@@ -1465,6 +1479,10 @@ static int fwnet_add_peer(struct fwnet_d
 	list_add_tail(&peer->peer_link, &dev->peer_list);
 	spin_unlock_irq(&dev->lock);
 
+	/* serialized by fwnet_device_mutex */
+	if (++dev->peer_count > 1)
+		netif_carrier_on(dev->netdev);
+
 	return 0;
 }
 
@@ -1543,13 +1561,16 @@ static int fwnet_probe(struct device *_d
 	return ret;
 }
 
-static void fwnet_remove_peer(struct fwnet_peer *peer)
+static void fwnet_remove_peer(struct fwnet_peer *peer, struct fwnet_device *dev)
 {
 	struct fwnet_partial_datagram *pd, *pd_next;
 
-	spin_lock_irq(&peer->dev->lock);
+	if (--dev->peer_count == 1)
+		netif_carrier_off(dev->netdev);
+
+	spin_lock_irq(&dev->lock);
 	list_del(&peer->peer_link);
-	spin_unlock_irq(&peer->dev->lock);
+	spin_unlock_irq(&dev->lock);
 
 	list_for_each_entry_safe(pd, pd_next, &peer->pd_list, pd_link)
 		fwnet_pd_delete(pd);
@@ -1566,7 +1587,7 @@ static int fwnet_remove(struct device *_
 
 	mutex_lock(&fwnet_device_mutex);
 
-	fwnet_remove_peer(peer);
+	fwnet_remove_peer(peer, dev);
 
 	if (list_empty(&dev->peer_list)) {
 		net = dev->netdev;
Signature · 10 lines
Stefan Richter
-=====-==-=- ==-- -==-=
http://arcgraph.de/sr/

------------------------------------------------------------------------------
Lotusphere 2011
Register now for Lotusphere 2011 and learn how
to connect the dots, take your collaborative environment
to the next level, and enter the era of Social Business.
http://p.sf.net/sfu/lotusphere-d2d
#32 lore raw

Re: [PATCH update 3] firewire: net: add carrier detection

Quoted 7 lines · Stefan Richter

From: Maxim Levitsky <[email protected]>

To make userland, e.g. NetworkManager work with firewire, we need to detect whether cable is plugged or not. Simple and correct way of doing that is just counting number of peers. No peers - no link and vice versa.

Quoted 6 lines

(Stefan R.: Combined peer_count inc/dec with tests, added link-down recognition in fwnet_open, added include.)

---
Update 3: added fwnet_open (ifup) hunk

Thank you very much.
I tested this just in case, and it works just fine. Especially thanks for the missing carrier state initialization, Just one note, since you pretty much rewrite that little patch, it would be correct to attribute you as an author of it.
I was recently (and still am) busy with my DVB card, so I didn't test my original patch enough.

Beyond this patch, firewire networking is pretty much complete.

The only missing parts are IPV6 and multicast, and the latter works by using broadcast which for all means is enough.

Quoted 99 lines
 drivers/firewire/net.c |   29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

Index: b/drivers/firewire/net.c
===================================================================

drivers/firewire/net.c +25 -4
@@ -9,6 +9,7 @@
 #include <linux/bug.h>
 #include <linux/delay.h>
 #include <linux/device.h>
+#include <linux/ethtool.h>
 #include <linux/firewire.h>
 #include <linux/firewire-constants.h>
 #include <linux/highmem.h>
@@ -179,6 +180,7 @@ struct fwnet_device {
 	/* Number of tx datagrams that have been queued but not yet acked */
 	int queued_datagrams;
 
+	int peer_count;
 	struct list_head peer_list;
 	struct fw_card *card;
 	struct net_device *netdev;
@@ -1234,6 +1236,13 @@ static int fwnet_open(struct net_device 
 	}
 	netif_start_queue(net);
 
+	mutex_lock(&fwnet_device_mutex);
+	if (dev->peer_count > 1)
+		netif_carrier_on(net);
+	else
+		netif_carrier_off(net);
+	mutex_unlock(&fwnet_device_mutex);
+
 	return 0;
 }
 
@@ -1412,6 +1421,10 @@ static const struct net_device_ops fwnet
 	.ndo_change_mtu = fwnet_change_mtu,
 };
 
+static const struct ethtool_ops fwnet_ethtool_ops = {
+	.get_link	= ethtool_op_get_link,
+};
+
 static void fwnet_init_dev(struct net_device *net)
 {
 	net->header_ops		= &fwnet_header_ops;
@@ -1423,6 +1436,7 @@ static void fwnet_init_dev(struct net_de
 	net->hard_header_len	= FWNET_HLEN;
 	net->type		= ARPHRD_IEEE1394;
 	net->tx_queue_len	= FWNET_TX_QUEUE_LEN;
+	net->ethtool_ops	= &fwnet_ethtool_ops;
 }
 
 /* caller must hold fwnet_device_mutex */
@@ -1465,6 +1479,10 @@ static int fwnet_add_peer(struct fwnet_d
 	list_add_tail(&peer->peer_link, &dev->peer_list);
 	spin_unlock_irq(&dev->lock);
 
+	/* serialized by fwnet_device_mutex */
+	if (++dev->peer_count > 1)
+		netif_carrier_on(dev->netdev);
+
 	return 0;
 }
 
@@ -1543,13 +1561,16 @@ static int fwnet_probe(struct device *_d
 	return ret;
 }
 
-static void fwnet_remove_peer(struct fwnet_peer *peer)
+static void fwnet_remove_peer(struct fwnet_peer *peer, struct fwnet_device *dev)
 {
 	struct fwnet_partial_datagram *pd, *pd_next;
 
-	spin_lock_irq(&peer->dev->lock);
+	if (--dev->peer_count == 1)
+		netif_carrier_off(dev->netdev);
+
+	spin_lock_irq(&dev->lock);
 	list_del(&peer->peer_link);
-	spin_unlock_irq(&peer->dev->lock);
+	spin_unlock_irq(&dev->lock);
 
 	list_for_each_entry_safe(pd, pd_next, &peer->pd_list, pd_link)
 		fwnet_pd_delete(pd);
@@ -1566,7 +1587,7 @@ static int fwnet_remove(struct device *_
 
 	mutex_lock(&fwnet_device_mutex);
 
-	fwnet_remove_peer(peer);
+	fwnet_remove_peer(peer, dev);
 
 	if (list_empty(&dev->peer_list)) {
 		net = dev->netdev;
#33 lore raw

Re: [PATCH update 3] firewire: net: add carrier detection

In reply to Stefan Richter
Quoted 6 lines · Stefan Richter

From: Maxim Levitsky <[email protected]>

To make userland, e.g. NetworkManager work with firewire, we need to detect whether cable is plugged or not. Simple and correct way of doing that is just counting number of peers. No peers - no link and vice versa.

Oh you rock. Good stuff.

Dan

Quoted 97 lines

(Stefan R.: Combined peer_count inc/dec with tests, added link-down recognition in fwnet_open, added include.)

---
Update 3: added fwnet_open (ifup) hunk

 drivers/firewire/net.c |   29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

Index: b/drivers/firewire/net.c
===================================================================

drivers/firewire/net.c +24 -3
@@ -9,6 +9,7 @@
 #include <linux/bug.h>
 #include <linux/delay.h>
 #include <linux/device.h>
+#include <linux/ethtool.h>
 #include <linux/firewire.h>
 #include <linux/firewire-constants.h>
 #include <linux/highmem.h>
@@ -179,6 +180,7 @@ struct fwnet_device {
 	/* Number of tx datagrams that have been queued but not yet acked */
 	int queued_datagrams;
 
+	int peer_count;
 	struct list_head peer_list;
 	struct fw_card *card;
 	struct net_device *netdev;
@@ -1234,6 +1236,13 @@ static int fwnet_open(struct net_device 
 	}
 	netif_start_queue(net);
 
+	mutex_lock(&fwnet_device_mutex);
+	if (dev->peer_count > 1)
+		netif_carrier_on(net);
+	else
+		netif_carrier_off(net);
+	mutex_unlock(&fwnet_device_mutex);
+
 	return 0;
 }
 
@@ -1412,6 +1421,10 @@ static const struct net_device_ops fwnet
 	.ndo_change_mtu = fwnet_change_mtu,
 };
 
+static const struct ethtool_ops fwnet_ethtool_ops = {
+	.get_link	= ethtool_op_get_link,
+};
+
 static void fwnet_init_dev(struct net_device *net)
 {
 	net->header_ops		= &fwnet_header_ops;
@@ -1423,6 +1436,7 @@ static void fwnet_init_dev(struct net_de
 	net->hard_header_len	= FWNET_HLEN;
 	net->type		= ARPHRD_IEEE1394;
 	net->tx_queue_len	= FWNET_TX_QUEUE_LEN;
+	net->ethtool_ops	= &fwnet_ethtool_ops;
 }
 
 /* caller must hold fwnet_device_mutex */
@@ -1465,6 +1479,10 @@ static int fwnet_add_peer(struct fwnet_d
 	list_add_tail(&peer->peer_link, &dev->peer_list);
 	spin_unlock_irq(&dev->lock);
 
+	/* serialized by fwnet_device_mutex */
+	if (++dev->peer_count > 1)
+		netif_carrier_on(dev->netdev);
+
 	return 0;
 }
 
@@ -1543,13 +1561,16 @@ static int fwnet_probe(struct device *_d
 	return ret;
 }
 
-static void fwnet_remove_peer(struct fwnet_peer *peer)
+static void fwnet_remove_peer(struct fwnet_peer *peer, struct fwnet_device *dev)
 {
 	struct fwnet_partial_datagram *pd, *pd_next;
 
-	spin_lock_irq(&peer->dev->lock);
+	if (--dev->peer_count == 1)
+		netif_carrier_off(dev->netdev);
+
+	spin_lock_irq(&dev->lock);
 	list_del(&peer->peer_link);
-	spin_unlock_irq(&peer->dev->lock);
+	spin_unlock_irq(&dev->lock);
 
 	list_for_each_entry_safe(pd, pd_next, &peer->pd_list, pd_link)
 		fwnet_pd_delete(pd);

drivers/firewire/net.c static int fwnet_remove(struct device *_ · line 1593

Quoted 8 lines
drivers/firewire/net.c +1 -1
@@ -1566,7 +1587,7 @@ static int fwnet_remove(struct device *_
 
 	mutex_lock(&fwnet_device_mutex);
 
-	fwnet_remove_peer(peer);
+	fwnet_remove_peer(peer, dev);
 
 	if (list_empty(&dev->peer_list)) {
 		net = dev->netdev;

------------------------------------------------------------------------------
Lotusphere 2011
Register now for Lotusphere 2011 and learn how to connect the dots, take your collaborative environment to the next level, and enter the era of Social Business.
http://p.sf.net/sfu/lotusphere-d2d