0003-batman-adv-introduce-no_rebroadcast-option.patch 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. From: Matthias Schiffer <mschiffer@universe-factory.net>
  2. Date: Wed, 7 Jan 2015 16:48:06 +0100
  3. Subject: batman-adv: introduce 'no_rebroadcast' option
  4. diff --git a/batman-adv/patches/0001-batman-adv-introduce-no_rebroadcast-option.patch b/batman-adv/patches/0001-batman-adv-introduce-no_rebroadcast-option.patch
  5. new file mode 100644
  6. index 0000000..cd79917
  7. --- /dev/null
  8. +++ b/batman-adv/patches/0001-batman-adv-introduce-no_rebroadcast-option.patch
  9. @@ -0,0 +1,185 @@
  10. +From 5ba3f1eac041857deabe39432fdfe1a584bbdd81 Mon Sep 17 00:00:00 2001
  11. +Message-Id: <5ba3f1eac041857deabe39432fdfe1a584bbdd81.1420645650.git.mschiffer@universe-factory.net>
  12. +From: =?UTF-8?q?Linus=20L=C3=BCssing?= <linus.luessing@web.de>
  13. +Date: Tue, 24 Sep 2013 04:36:27 +0200
  14. +Subject: [PATCH] batman-adv: introduce 'no_rebroadcast' option
  15. +MIME-Version: 1.0
  16. +Content-Type: text/plain; charset=UTF-8
  17. +Content-Transfer-Encoding: 8bit
  18. +
  19. +This patch introduces a new sysfs option named "no_rebroadcast" on
  20. +a per hard interface basis. It allows manually enabling a split-horizon
  21. +like behaviour for the layer 2 multicast payload frames, in that
  22. +incoming multicast payload frames on such a hard interface are only
  23. +being rebroadcasted on all interfaces except the incoming one instead
  24. +of being rebroadcasted on all interfaces.
  25. +
  26. +Such an option should only be enabled if you are certain that these
  27. +rebroadcasts are unnecessary. This is usually the case for instance
  28. +for point-to-point wifi longshots or wired links.
  29. +
  30. +This option can especially safe a significant amount of upload overhead
  31. +if the neighbourhood on a link is rather large, for instance in some
  32. +transitive, symmetric VPN configurations.
  33. +
  34. +Using this option wrongly will break your mesh network, use this option
  35. +wisely and at your own risk!
  36. +
  37. +Signed-off-by: Linus Lüssing <linus.luessing@web.de>
  38. +---
  39. + hard-interface.c | 2 ++
  40. + send.c | 4 ++++
  41. + sysfs-class-net-batman-adv | 10 ++++++++
  42. + sysfs.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++
  43. + types.h | 1 +
  44. + 5 files changed, 76 insertions(+)
  45. +
  46. +diff --git a/hard-interface.c b/hard-interface.c
  47. +index fbda6b5..3997f9c 100644
  48. +--- a/hard-interface.c
  49. ++++ b/hard-interface.c
  50. +@@ -591,6 +591,8 @@ batadv_hardif_add_interface(struct net_device *net_dev)
  51. + /* extra reference for return */
  52. + atomic_set(&hard_iface->refcount, 2);
  53. +
  54. ++ atomic_set(&hard_iface->no_rebroadcast, 0);
  55. ++
  56. + batadv_check_known_mac_addr(hard_iface->net_dev);
  57. + list_add_tail_rcu(&hard_iface->list, &batadv_hardif_list);
  58. +
  59. +diff --git a/send.c b/send.c
  60. +index d27161e..4383a66 100644
  61. +--- a/send.c
  62. ++++ b/send.c
  63. +@@ -513,6 +513,10 @@ static void batadv_send_outstanding_bcast_packet(struct work_struct *work)
  64. + if (forw_packet->num_packets >= hard_iface->num_bcasts)
  65. + continue;
  66. +
  67. ++ if (atomic_read(&hard_iface->no_rebroadcast) &&
  68. ++ forw_packet->skb->dev == hard_iface->net_dev)
  69. ++ continue;
  70. ++
  71. + /* send a copy of the saved skb */
  72. + skb1 = skb_clone(forw_packet->skb, GFP_ATOMIC);
  73. + if (skb1)
  74. +diff --git a/sysfs-class-net-batman-adv b/sysfs-class-net-batman-adv
  75. +index 7f34a95..cf7fe00 100644
  76. +--- a/sysfs-class-net-batman-adv
  77. ++++ b/sysfs-class-net-batman-adv
  78. +@@ -13,3 +13,13 @@ Description:
  79. + displays the batman mesh interface this <iface>
  80. + currently is associated with.
  81. +
  82. ++What: /sys/class/net/<iface>/batman-adv/no_rebroadcast
  83. ++Date: Sep 2013
  84. ++Contact: Linus Lüssing <linus.luessing@web.de>
  85. ++Description:
  86. ++ With this option set incoming multicast payload frames on
  87. ++ <iface> are not being rebroadcasted on <iface> again. This
  88. ++ option should be set on links which are known to be transitive
  89. ++ and symmetric only, for instance point-to-point wifi longshots
  90. ++ or wired links. Using this option wrongly is going to
  91. ++ break your mesh network, use at your own risk!
  92. +diff --git a/sysfs.c b/sysfs.c
  93. +index fc47baa..adaeca4 100644
  94. +--- a/sysfs.c
  95. ++++ b/sysfs.c
  96. +@@ -110,6 +110,17 @@ struct batadv_attribute batadv_attr_vlan_##_name = { \
  97. + .store = _store, \
  98. + }
  99. +
  100. ++/* Use this, if you have customized show and store functions
  101. ++ * for hard interface attrs
  102. ++ */
  103. ++#define BATADV_ATTR_HIF(_name, _mode, _show, _store) \
  104. ++struct batadv_attribute batadv_attr_hif_##_name = { \
  105. ++ .attr = {.name = __stringify(_name), \
  106. ++ .mode = _mode }, \
  107. ++ .show = _show, \
  108. ++ .store = _store, \
  109. ++};
  110. ++
  111. + /* Use this, if you have customized show and store functions */
  112. + #define BATADV_ATTR(_name, _mode, _show, _store) \
  113. + struct batadv_attribute batadv_attr_##_name = { \
  114. +@@ -221,6 +232,52 @@ ssize_t batadv_show_vlan_##_name(struct kobject *kobj, \
  115. + static BATADV_ATTR_VLAN(_name, _mode, batadv_show_vlan_##_name, \
  116. + batadv_store_vlan_##_name)
  117. +
  118. ++#define BATADV_ATTR_HIF_STORE_BOOL(_name, _post_func) \
  119. ++ssize_t batadv_store_hif_##_name(struct kobject *kobj, \
  120. ++ struct attribute *attr, char *buff, \
  121. ++ size_t count) \
  122. ++{ \
  123. ++ struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \
  124. ++ struct batadv_hard_iface *hard_iface; \
  125. ++ size_t res; \
  126. ++ \
  127. ++ hard_iface = batadv_hardif_get_by_netdev(net_dev); \
  128. ++ if (!hard_iface) \
  129. ++ return 0; \
  130. ++ \
  131. ++ res = __batadv_store_bool_attr(buff, count, _post_func, \
  132. ++ attr, &hard_iface->_name, \
  133. ++ hard_iface->soft_iface); \
  134. ++ batadv_hardif_free_ref(hard_iface); \
  135. ++ return res; \
  136. ++}
  137. ++
  138. ++#define BATADV_ATTR_HIF_SHOW_BOOL(_name) \
  139. ++ssize_t batadv_show_hif_##_name(struct kobject *kobj, \
  140. ++ struct attribute *attr, char *buff) \
  141. ++{ \
  142. ++ struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \
  143. ++ struct batadv_hard_iface *hard_iface; \
  144. ++ size_t res; \
  145. ++ \
  146. ++ hard_iface = batadv_hardif_get_by_netdev(net_dev); \
  147. ++ if (!hard_iface) \
  148. ++ return 0; \
  149. ++ \
  150. ++ res = sprintf(buff, "%s\n", \
  151. ++ atomic_read(&hard_iface->_name) == 0 ? \
  152. ++ "disabled" : "enabled"); \
  153. ++ batadv_hardif_free_ref(hard_iface); \
  154. ++ return res; \
  155. ++}
  156. ++
  157. ++/* Use this, if you are going to turn a [name] in the vlan struct on or off */
  158. ++#define BATADV_ATTR_HIF_BOOL(_name, _mode, _post_func) \
  159. ++ static BATADV_ATTR_HIF_STORE_BOOL(_name, _post_func) \
  160. ++ static BATADV_ATTR_HIF_SHOW_BOOL(_name) \
  161. ++ static BATADV_ATTR_HIF(_name, _mode, batadv_show_hif_##_name, \
  162. ++ batadv_store_hif_##_name)
  163. ++
  164. + static int batadv_store_bool_attr(char *buff, size_t count,
  165. + struct net_device *net_dev,
  166. + const char *attr_name, atomic_t *attr)
  167. +@@ -844,10 +901,12 @@ static ssize_t batadv_show_iface_status(struct kobject *kobj,
  168. + static BATADV_ATTR(mesh_iface, S_IRUGO | S_IWUSR, batadv_show_mesh_iface,
  169. + batadv_store_mesh_iface);
  170. + static BATADV_ATTR(iface_status, S_IRUGO, batadv_show_iface_status, NULL);
  171. ++BATADV_ATTR_HIF_BOOL(no_rebroadcast, S_IRUGO | S_IWUSR, NULL);
  172. +
  173. + static struct batadv_attribute *batadv_batman_attrs[] = {
  174. + &batadv_attr_mesh_iface,
  175. + &batadv_attr_iface_status,
  176. ++ &batadv_attr_hif_no_rebroadcast,
  177. + NULL,
  178. + };
  179. +
  180. +diff --git a/types.h b/types.h
  181. +index 8854c05..39619fb 100644
  182. +--- a/types.h
  183. ++++ b/types.h
  184. +@@ -101,6 +101,7 @@ struct batadv_hard_iface {
  185. + struct batadv_hard_iface_bat_iv bat_iv;
  186. + struct work_struct cleanup_work;
  187. + struct dentry *debug_dir;
  188. ++ atomic_t no_rebroadcast;
  189. + };
  190. +
  191. + /**
  192. +--
  193. +2.2.1
  194. +