Adding helpers and defines needed for extending the
arp_ip_target parameters.

Signed-off-by: David Wilder <[email protected]>
---
 include/net/bonding.h | 52 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/include/net/bonding.h b/include/net/bonding.h
index 3497e5061f90..0537b92c65eb 100644
--- a/include/net/bonding.h
+++ b/include/net/bonding.h
@@ -809,4 +809,56 @@ static inline netdev_tx_t bond_tx_drop(struct net_device 
*dev, struct sk_buff *s
        return NET_XMIT_DROP;
 }
 
+/* Helpers for handling arp_ip_target */
+#define BOND_OPTION_STRING_MAX_SIZE 64
+#define BOND_MAX_VLAN_TAGS 5
+#define BOND_VLAN_PROTO_NONE cpu_to_be16(0xffff)
+
+static inline char *bond_arp_target_to_string(const struct bond_arp_target 
*target,
+                                             char *buf, int size)
+{
+       struct bond_vlan_tag *tags = target->tags;
+       int i, num = 0;
+
+       BUILD_BUG_ON(size != BOND_OPTION_STRING_MAX_SIZE);
+
+       if (!(target->flags & BOND_TARGET_USERTAGS)) {
+               num = snprintf(&buf[0], size, "%pI4", &target->target_ip);
+               return buf;
+       }
+
+       num = snprintf(&buf[0], size, "%pI4[", &target->target_ip);
+       if (tags) {
+               for (i = 0; (tags[i].vlan_proto != BOND_VLAN_PROTO_NONE); i++) {
+                       if (!tags[i].vlan_id)
+                               continue;
+                       if (i != 0)
+                               num = num + snprintf(&buf[num], size - num, 
"/");
+                       num = num + snprintf(&buf[num], size - num, "%u",
+                                            tags[i].vlan_id);
+               }
+       }
+       snprintf(&buf[num], size - num, "]");
+       return buf;
+}
+
+static inline void bond_free_vlan_tag(struct bond_arp_target *target)
+{
+       struct bond_vlan_tag *tags = target->tags;
+
+       target->tags = NULL;
+       target->flags = 0;
+       kfree(tags);
+}
+
+static inline void __bond_free_vlan_tags(struct bond_arp_target *targets)
+{
+       int i;
+
+       for (i = 0; i < BOND_MAX_ARP_TARGETS && targets[i].tags; i++)
+               bond_free_vlan_tag(&targets[i]);
+}
+
+#define bond_free_vlan_tags(targets)  __bond_free_vlan_tags(targets)
+
 #endif /* _NET_BONDING_H */
-- 
2.50.1


Reply via email to