Skip to contentSkip to conversation

batman-adv: add compat support for the new netlink ops

PATCH Superseded Antonio Quartulli 3 participants 12 messages Feb 17, 2013 – Feb 27, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 batman-adv: add compat support for the new netlink ops

This patches enable the new rtnl ops to compile on kernels starting from 2.6.32

---

Could not be uglier.
*Compile tested only* because linux-2.6.32 does not compile on my laptop

 compat.h | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
compat.h +40 -0
index 885e551..de22e2b 100644
@@ -71,6 +71,9 @@ static inline void batadv_this_cpu_add(uint64_t *count_ptr, size_t count)
 	put_cpu();
 }
 
+#define batadv_softif_destroy_netlink(dev, head) batadv_softif_destroy_netlink(dev)
+#define unregister_netdevice_queue(dev, head) unregister_netdevice(dev)
+
 #endif /* < KERNEL_VERSION(2, 6, 33) */
 
 
@@ -132,6 +135,43 @@ static inline int batadv_param_set_copystring(const char *val,
 #define kstrtoul strict_strtoul
 #define kstrtol  strict_strtol
 
+#define batadv_softif_slave_add(x, y) \
+batadv_softif_slave_add(struct net_device *dev, struct ifreq *rq, int cmd)\
+{\
+	return 0;\
+}\
+static int __batadv_softif_slave_add(x, y)
+
+#define batadv_softif_slave_del(x, y) \
+__batadv_softif_slave_del(struct net_device *dev, struct net_device *slave_dev);\
+static int batadv_softif_slave_del(struct net_device *dev, struct ifreq *rq, int cmd)\
+{\
+	struct batadv_priv *bat_priv = netdev_priv(dev);\
+	struct net_device *slave_dev;\
+	int ret;\
+	if (!capable(CAP_NET_ADMIN))\
+		return -EPERM;\
+	slave_dev = dev_get_by_index(&init_net, rq->ifr_ifindex);\
+	if (!dev)\
+		return -EINVAL;\
+	switch(cmd) {\
+	case SIOCBRADDIF:\
+		ret = __batadv_softif_slave_add(bat_priv->soft_iface, slave_dev);\
+	case SIOCBRDELIF:\
+		ret = __batadv_softif_slave_del(bat_priv->soft_iface, slave_dev);\
+	default:\
+		pr_debug("batman-adv does not support ioctl 0x%x\n", cmd);\
+		return -EOPNOTSUPP;\
+	}\
+\
+	dev_put(slave_dev);\
+	return ret;\
+}\
+static int __batadv_softif_slave_del(x, y)
+
+#define ndo_add_slave ndo_do_ioctl
+#define ndo_del_slave ndo_do_ioctl
+
 #endif /* < KERNEL_VERSION(2, 6, 39) */
 
 
Signature · 1 line
1.8.1.2
#1 lore raw

Hey Antonio,

I've tested this (just test, no code review) in my 2.6.32 qemu (Debian squeeze, iproute from wheezy). It generally loads and batctl if add/del seems to work, but there is something weird going on with bridge interaction. After calling the following 3 commands:

brctl addbr br0
batctl if add eth0
ip link set dev eth0 master br0

I would expect that eth0 moved from bat0 to br0 (or some error is reported). But what I see is:

root@debian:~# batctl if
eth0: active
br0: not in use
root@debian:~# brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.000000000000       no

Even more weird, after doing batctl if del eth0 or batctl if del br0, I don't get any output, but both devices remain in bat0 (according to batctl if). But I do get some output that it's trying to remove eth0:

[  102.788930] batman_adv: bat0: Interface deactivated: eth0                   
[  102.788935] batman_adv: bat0: Removing interface: eth0                    

Note that I don't have this behaviour on my host machine (3.2.0, Debian unstable kernel).

So I can't ack this now, although I don't know if the problem is in this patch, in the current batman-adv/netlink implementation or somewhere in 2.6.32 kernel release.

Cheers,
Simon

Quoted 74 lines · Antonio Quartulli

This patches enable the new rtnl ops to compile on kernels starting from 2.6.32

---

Could not be uglier.
*Compile tested only* because linux-2.6.32 does not compile on my laptop

 compat.h | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
compat.h +40 -0
index 885e551..de22e2b 100644
@@ -71,6 +71,9 @@ static inline void batadv_this_cpu_add(uint64_t *count_ptr, size_t count)
 	put_cpu();
 }
 
+#define batadv_softif_destroy_netlink(dev, head) batadv_softif_destroy_netlink(dev)
+#define unregister_netdevice_queue(dev, head) unregister_netdevice(dev)
+
 #endif /* < KERNEL_VERSION(2, 6, 33) */
 
 
@@ -132,6 +135,43 @@ static inline int batadv_param_set_copystring(const char *val,
 #define kstrtoul strict_strtoul
 #define kstrtol  strict_strtol
 
+#define batadv_softif_slave_add(x, y) \
+batadv_softif_slave_add(struct net_device *dev, struct ifreq *rq, int cmd)\
+{\
+	return 0;\
+}\
+static int __batadv_softif_slave_add(x, y)
+
+#define batadv_softif_slave_del(x, y) \
+__batadv_softif_slave_del(struct net_device *dev, struct net_device *slave_dev);\
+static int batadv_softif_slave_del(struct net_device *dev, struct ifreq *rq, int cmd)\
+{\
+	struct batadv_priv *bat_priv = netdev_priv(dev);\
+	struct net_device *slave_dev;\
+	int ret;\
+	if (!capable(CAP_NET_ADMIN))\
+		return -EPERM;\
+	slave_dev = dev_get_by_index(&init_net, rq->ifr_ifindex);\
+	if (!dev)\
+		return -EINVAL;\
+	switch(cmd) {\
+	case SIOCBRADDIF:\
+		ret = __batadv_softif_slave_add(bat_priv->soft_iface, slave_dev);\
+	case SIOCBRDELIF:\
+		ret = __batadv_softif_slave_del(bat_priv->soft_iface, slave_dev);\
+	default:\
+		pr_debug("batman-adv does not support ioctl 0x%x\n", cmd);\
+		return -EOPNOTSUPP;\
+	}\
+\
+	dev_put(slave_dev);\
+	return ret;\
+}\
+static int __batadv_softif_slave_del(x, y)
+
+#define ndo_add_slave ndo_do_ioctl
+#define ndo_del_slave ndo_do_ioctl
+
 #endif /* < KERNEL_VERSION(2, 6, 39) */
 
 
Signature · 1 line
1.8.1.2
#2 lore raw

Hi Simon,

Quoted 11 lines

I've tested this (just test, no code review) in my 2.6.32 qemu (Debian squeeze, iproute from wheezy). It generally loads and batctl if add/del seems to work, but there is something weird going on with bridge interaction. After calling the following 3 commands:

brctl addbr br0
batctl if add eth0
ip link set dev eth0 master br0

I would expect that eth0 moved from bat0 to br0 (or some error is reported).

I feel some confusion here. It could very well be that 2.6.32 did not yet support this kind of "interface transfer". You could repeat your test without any of the later patches (just go back to the last stable release) to see what happens. It is very likely that our patches have nothing to do with that.

These are the tests we should do in order to confirm the compat patch in question:

* batctl if add $iface && some OGMS here && batctl if del $iface
* ip link add dev bat0 type batadv && ip link set dev $iface master bat0 && some OGMS here && ip link set dev $iface nomaster && ip link del dev bat0

Even more interesting are combinations of those:
* batctl if add $iface && some OGMS here && ip link set dev $iface nomaster && ip link del dev bat0
* ip link add dev bat0 type batadv && ip link set dev $iface master bat0 && some OGMS here && batctl if del $iface

Thanks for testing!

Cheers,
Marek

#3 lore raw
Quoted 12 lines · Marek Lindner

Hi Simon,

Quoted 9 lines

I've tested this (just test, no code review) in my 2.6.32 qemu (Debian squeeze, iproute from wheezy). It generally loads and batctl if add/del seems to work, but there is something weird going on with bridge interaction. After calling the following 3 commands:

brctl addbr br0
batctl if add eth0
ip link set dev eth0 master br0

Quoted 7 lines
Quoted 2 lines

I would expect that eth0 moved from bat0 to br0 (or some error is reported).

I feel some confusion here. It could very well be that 2.6.32 did not yet support this kind of "interface transfer". You could repeat your test without any of the later patches (just go back to the last stable release) to see what happens. It is very likely that our patches have nothing to do with that.

you are right - I've checked 2013.0.0, same behaviour - and now that you mention it, this is all completely independent from batman-adv/netlink. Sorry for reporting stuff like that ... :)

Also it seems that batctl (2010.0.0, from debian stable) reports all devices, even if they are not added to batman-adv. It reports them as "not in use". This confused me, haven't seen that on other systems (unused devices are just skipped ...). After upding to the wheezy version of batctl (2012.1.0), this effect was gone.

Anyway, I've tested a little more and still I see some issues:

Quoted 5 lines

These are the tests we should do in order to confirm the compat patch in question:

* batctl if add $iface && some OGMS here && batctl if del $iface

This works fine, I see OGMs, and the interface is removed cleanly.

Quoted 1 line

* ip link add dev bat0 type batadv

This works fine.

Quoted 1 line

ip link set dev $iface master bat0

This doesn't work. eth0 is not added to batman. To further test, I've added it via batctl.

Quoted 1 line

some OGMS here

yes (bat0 created with ip, eth0 added using batctl)

Quoted 1 line

ip link set dev $iface nomaster

has no effect

Quoted 1 line

ip link del dev bat0

works.

Quoted 6 lines

Even more interesting are combinations of those:
* batctl if add $iface && some OGMS here && ip link set dev $iface nomaster && ip link del dev bat0
* ip link add dev bat0 type batadv && ip link set dev $iface master bat0 && some OGMS here && batctl if del $iface

Some of these combinations are tested above, but I'd suggest we should fix the general case first. :)

Cheers,
Simon

#4 lore raw

Hi Simon,

Quoted 5 lines
Quoted 2 lines

ip link set dev $iface master bat0

This doesn't work. eth0 is not added to batman. To further test, I've added it via batctl.

I'm not sure..but I think this does not work because the "set master" command does not use ioctl, but rtnl only. Since in this kernel we don't have rtnl for these operations (this is why we have this hacky patch) I did not expect this command to work.

Quoted 3 lines
Quoted 1 line

ip link set dev $iface nomaster

has no effect

same as before.

Quoted 9 lines
Quoted 6 lines

Even more interesting are combinations of those:
* batctl if add $iface && some OGMS here && ip link set dev $iface nomaster && ip link del dev bat0
* ip link add dev bat0 type batadv && ip link set dev $iface master bat0 && some OGMS here && batctl if del $iface

Some of these combinations are tested above, but I'd suggest we should fix the general case first. :)

what would you like to fix? :) We have just implemented a feature and now we don't have any userspace tool which can exploit it! :-D

Simon, Thanks a lot for testing!

Cheers,

Signature · 4 lines
Antonio Quartulli

..each of us alone is worth nothing..
Ernesto "Che" Guevara
#5 lore raw
Quoted 5 lines · Antonio Quartulli

Hi Simon,

Quoted 3 lines
Quoted 2 lines

ip link set dev $iface master bat0

Quoted 7 lines
Quoted 2 lines

This doesn't work. eth0 is not added to batman. To further test, I've added it via batctl.

I'm not sure..but I think this does not work because the "set master" command does not use ioctl, but rtnl only. Since in this kernel we don't have rtnl for these operations (this is why we have this hacky patch) I did not expect this command to work.

OK

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

Even more interesting are combinations of those:
* batctl if add $iface && some OGMS here && ip link set dev $iface nomaster && ip link del dev bat0
* ip link add dev bat0 type batadv && ip link set dev $iface master bat0 && some OGMS here && batctl if del $iface

Quoted 5 lines
Quoted 2 lines

Some of these combinations are tested above, but I'd suggest we should fix the general case first. :)

what would you like to fix? :) We have just implemented a feature and now we don't have any userspace tool which can exploit it! :-D

Well, if we don't expect this command to work then it's fine.

Personally I don't care as long as batctl works. :)

If there are any other things to test, please let me know.

Cheers,
Simon

#6 lore raw
Quoted 23 lines · Simon Wunderlich
Quoted 5 lines · Antonio Quartulli

Hi Simon,

Quoted 3 lines
Quoted 2 lines

ip link set dev $iface master bat0

Quoted 7 lines
Quoted 2 lines

This doesn't work. eth0 is not added to batman. To further test, I've added it via batctl.

I'm not sure..but I think this does not work because the "set master" command does not use ioctl, but rtnl only. Since in this kernel we don't have rtnl for these operations (this is why we have this hacky patch) I did not expect this command to work.

OK

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

Even more interesting are combinations of those:
* batctl if add $iface && some OGMS here && ip link set dev $iface nomaster && ip link del dev bat0
* ip link add dev bat0 type batadv && ip link set dev $iface master bat0 && some OGMS here && batctl if del $iface

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Some of these combinations are tested above, but I'd suggest we should fix the general case first. :)

what would you like to fix? :) We have just implemented a feature and now we don't have any userspace tool which can exploit it! :-D

Well, if we don't expect this command to work then it's fine.

I just double-checked. iplink handles the master subcommand by sending a rtnl request with the IFLA_MASTER flasg set, nothing else. Unluckily, this flag is not supported in 2.6.32.

Quoted 2 lines

Personally I don't care as long as batctl works. :)

yeah, that's the important point. And batman-adv is still working with this patch.

Quoted 3 lines

If there are any other things to test, please let me know.

Nothing on my side.
Thanks again :)

Cheers,

Signature · 4 lines
Antonio Quartulli

..each of us alone is worth nothing..
Ernesto "Che" Guevara
#7 lore raw
Quoted 3 lines · Antonio Quartulli

Nothing on my side.
Thanks again :)

I just realised that the ioctl commands this code is handling are for a bridge interface. Since batman-adv does not have its own set of ioctls, then the ndo_do_ioctl() callback should simply return EOPNOTSUPP.

I'm going to send v2. This will not affect any tested behaviour.

Cheers,

Signature · 4 lines
Antonio Quartulli

..each of us alone is worth nothing..
Ernesto "Che" Guevara
#8 lore raw

PATCH v2 1/1 batman-adv: add compat support for the new netlink ops

This patches enable the new rtnl ops to compile on kernels starting from 2.6.32

---

v2:
- do not handle ioctl. just return EOPNOTSUPP

 compat.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
compat.h +21 -0
index 425b3d9..23ced4a 100644
@@ -71,6 +71,9 @@ static inline void batadv_this_cpu_add(uint64_t *count_ptr, size_t count)
 	put_cpu();
 }
 
+#define batadv_softif_destroy_netlink(dev, head) batadv_softif_destroy_netlink(dev)
+#define unregister_netdevice_queue(dev, head) unregister_netdevice(dev)
+
 #endif /* < KERNEL_VERSION(2, 6, 33) */
 
 
@@ -132,6 +135,24 @@ static inline int batadv_param_set_copystring(const char *val,
 #define kstrtoul strict_strtoul
 #define kstrtol  strict_strtol
 
+#define batadv_softif_slave_add(x, y) \
+batadv_softif_slave_add(struct net_device *dev, struct ifreq *rq, int cmd)\
+{\
+	return -EOPNOTSUPP;\
+}\
+static int __attribute__((unused)) __batadv_softif_slave_add(x, y)
+
+#define batadv_softif_slave_del(x, y) \
+__batadv_softif_slave_del(struct net_device *dev, struct net_device *slave_dev);\
+static int batadv_softif_slave_del(struct net_device *dev, struct ifreq *rq, int cmd)\
+{\
+	return -EOPNOTSUPP;\
+}\
+static int __attribute__((unused)) __batadv_softif_slave_del(x, y)
+
+#define ndo_add_slave ndo_do_ioctl
+#define ndo_del_slave ndo_do_ioctl
+
 #endif /* < KERNEL_VERSION(2, 6, 39) */
 
 
Signature · 1 line
1.8.1.2
Tested-by on v2 1/1
#9 lore raw

Hey guys,

As requested, just did a quick test again:
* batctl if add $iface && some OGMS here && batctl if del $iface --> still works fine
* batctl link add dev bat0 type batadv
--> creates the bat0 interface
* ip link set dev eth0 master bat0
--> no output, no effect
* ip link del dev bat0
--> deletes the bat0 interface

Used: Debian stable (squeeze) with original kernel (linux-iamge-2.6.32-5-686, version 2.6.32-46) batctl (2012.1.0-1) and iproute (20120521-3) from wheezy

So no difference noticed here. :)

I've checked back with iproute package from squeeze (20120521-3):
* "ip link add dev bat0 type batadv" still works
* "ip link set dev eth0 master bat0" throws an error and does nothing:
Error: either "dev" is duplicate, or "master" is a garbage.

so to summarize: it compiles again, batctl works, and ip at least allows to add the bat0 interface but adding interfaces into a softiface using ip doesn't.

Hope that helps!
Cheers,
Simon

Quoted 53 lines · Antonio Quartulli

This patches enable the new rtnl ops to compile on kernels starting from 2.6.32

---

v2:
- do not handle ioctl. just return EOPNOTSUPP

 compat.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
compat.h +21 -0
index 425b3d9..23ced4a 100644
@@ -71,6 +71,9 @@ static inline void batadv_this_cpu_add(uint64_t *count_ptr, size_t count)
 	put_cpu();
 }
 
+#define batadv_softif_destroy_netlink(dev, head) batadv_softif_destroy_netlink(dev)
+#define unregister_netdevice_queue(dev, head) unregister_netdevice(dev)
+
 #endif /* < KERNEL_VERSION(2, 6, 33) */
 
 
@@ -132,6 +135,24 @@ static inline int batadv_param_set_copystring(const char *val,
 #define kstrtoul strict_strtoul
 #define kstrtol  strict_strtol
 
+#define batadv_softif_slave_add(x, y) \
+batadv_softif_slave_add(struct net_device *dev, struct ifreq *rq, int cmd)\
+{\
+	return -EOPNOTSUPP;\
+}\
+static int __attribute__((unused)) __batadv_softif_slave_add(x, y)
+
+#define batadv_softif_slave_del(x, y) \
+__batadv_softif_slave_del(struct net_device *dev, struct net_device *slave_dev);\
+static int batadv_softif_slave_del(struct net_device *dev, struct ifreq *rq, int cmd)\
+{\
+	return -EOPNOTSUPP;\
+}\
+static int __attribute__((unused)) __batadv_softif_slave_del(x, y)
+
+#define ndo_add_slave ndo_do_ioctl
+#define ndo_del_slave ndo_do_ioctl
+
 #endif /* < KERNEL_VERSION(2, 6, 39) */
 
 
Signature · 1 line
1.8.1.2
#10 lore raw
Quoted 22 lines · Simon Wunderlich

Hey guys,

As requested, just did a quick test again:
* batctl if add $iface && some OGMS here && batctl if del $iface --> still works fine
* batctl link add dev bat0 type batadv
--> creates the bat0 interface
* ip link set dev eth0 master bat0
--> no output, no effect
* ip link del dev bat0
--> deletes the bat0 interface

Used: Debian stable (squeeze) with original kernel (linux-iamge-2.6.32-5-686, version 2.6.32-46) batctl (2012.1.0-1) and iproute (20120521-3) from wheezy

So no difference noticed here. :)

I've checked back with iproute package from squeeze (20120521-3):
* "ip link add dev bat0 type batadv" still works
* "ip link set dev eth0 master bat0" throws an error and does nothing:
Error: either "dev" is duplicate, or "master" is a garbage.

Quoted 8 lines

so to summarize: it compiles again, batctl works, and ip at least allows to add the bat0 interface but adding interfaces into a softiface using ip doesn't.

Hope that helps!
Cheers,
Simon

Thank you very much Simon! :)
This is what we expected.

Cheers,

Signature · 4 lines
Antonio Quartulli

..each of us alone is worth nothing..
Ernesto "Che" Guevara