diff options
author | Antonio Quartulli <antonio@open-mesh.com> | 2016-01-16 03:40:14 -0500 |
---|---|---|
committer | Antonio Quartulli <a@unstable.cc> | 2016-02-29 03:05:32 -0500 |
commit | 0b5ecc6811bd576ecc9813bbe069f2293cb1c6aa (patch) | |
tree | a75d24c012f6c6ca6ae5fa8904a4eee4e7ed0f98 | |
parent | 9323158ef9f49935f0c61509919acd31dda8f11b (diff) |
batman-adv: add throughput override attribute to hard_ifaces
This attribute is exported to user space to disable the link
throughput auto-detection by setting a fixed value.
The throughput override value is used when batman-adv is
computing the link throughput towards a neighbour.
If the value is set to 0 then batman-adv will try to detect
the throughput by itself.
Signed-off-by: Antonio Quartulli <antonio@open-mesh.com>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
-rw-r--r-- | Documentation/ABI/testing/sysfs-class-net-batman-adv | 9 | ||||
-rw-r--r-- | net/batman-adv/bat_v.c | 6 | ||||
-rw-r--r-- | net/batman-adv/gateway_common.c | 4 | ||||
-rw-r--r-- | net/batman-adv/gateway_common.h | 2 | ||||
-rw-r--r-- | net/batman-adv/sysfs.c | 74 | ||||
-rw-r--r-- | net/batman-adv/types.h | 2 |
6 files changed, 95 insertions, 2 deletions
diff --git a/Documentation/ABI/testing/sysfs-class-net-batman-adv b/Documentation/ABI/testing/sysfs-class-net-batman-adv index aea78db983bc..518f6a1dbc0c 100644 --- a/Documentation/ABI/testing/sysfs-class-net-batman-adv +++ b/Documentation/ABI/testing/sysfs-class-net-batman-adv | |||
@@ -1,4 +1,13 @@ | |||
1 | 1 | ||
2 | What: /sys/class/net/<iface>/batman-adv/throughput_override | ||
3 | Date: Feb 2014 | ||
4 | Contact: Antonio Quartulli <antonio@meshcoding.com> | ||
5 | description: | ||
6 | Defines the throughput value to be used by B.A.T.M.A.N. V | ||
7 | when estimating the link throughput using this interface. | ||
8 | If the value is set to 0 then batman-adv will try to | ||
9 | estimate the throughput by itself. | ||
10 | |||
2 | What: /sys/class/net/<iface>/batman-adv/elp_interval | 11 | What: /sys/class/net/<iface>/batman-adv/elp_interval |
3 | Date: Feb 2014 | 12 | Date: Feb 2014 |
4 | Contact: Linus Lüssing <linus.luessing@web.de> | 13 | Contact: Linus Lüssing <linus.luessing@web.de> |
diff --git a/net/batman-adv/bat_v.c b/net/batman-adv/bat_v.c index b90a4dfe8ba6..d9cb5c4922c1 100644 --- a/net/batman-adv/bat_v.c +++ b/net/batman-adv/bat_v.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include "bat_algo.h" | 18 | #include "bat_algo.h" |
19 | #include "main.h" | 19 | #include "main.h" |
20 | 20 | ||
21 | #include <linux/atomic.h> | ||
21 | #include <linux/cache.h> | 22 | #include <linux/cache.h> |
22 | #include <linux/init.h> | 23 | #include <linux/init.h> |
23 | 24 | ||
@@ -37,6 +38,11 @@ static int batadv_v_iface_enable(struct batadv_hard_iface *hard_iface) | |||
37 | if (ret < 0) | 38 | if (ret < 0) |
38 | batadv_v_elp_iface_disable(hard_iface); | 39 | batadv_v_elp_iface_disable(hard_iface); |
39 | 40 | ||
41 | /* enable link throughput auto-detection by setting the throughput | ||
42 | * override to zero | ||
43 | */ | ||
44 | atomic_set(&hard_iface->bat_v.throughput_override, 0); | ||
45 | |||
40 | return ret; | 46 | return ret; |
41 | } | 47 | } |
42 | 48 | ||
diff --git a/net/batman-adv/gateway_common.c b/net/batman-adv/gateway_common.c index 5ee04f7140af..4423047889e1 100644 --- a/net/batman-adv/gateway_common.c +++ b/net/batman-adv/gateway_common.c | |||
@@ -40,8 +40,8 @@ | |||
40 | * | 40 | * |
41 | * Return: false on parse error and true otherwise. | 41 | * Return: false on parse error and true otherwise. |
42 | */ | 42 | */ |
43 | static bool batadv_parse_throughput(struct net_device *net_dev, char *buff, | 43 | bool batadv_parse_throughput(struct net_device *net_dev, char *buff, |
44 | const char *description, u32 *throughput) | 44 | const char *description, u32 *throughput) |
45 | { | 45 | { |
46 | enum batadv_bandwidth_units bw_unit_type = BATADV_BW_UNIT_KBIT; | 46 | enum batadv_bandwidth_units bw_unit_type = BATADV_BW_UNIT_KBIT; |
47 | u64 lthroughput; | 47 | u64 lthroughput; |
diff --git a/net/batman-adv/gateway_common.h b/net/batman-adv/gateway_common.h index b58346350024..8a5e1ddf1175 100644 --- a/net/batman-adv/gateway_common.h +++ b/net/batman-adv/gateway_common.h | |||
@@ -49,5 +49,7 @@ ssize_t batadv_gw_bandwidth_set(struct net_device *net_dev, char *buff, | |||
49 | void batadv_gw_tvlv_container_update(struct batadv_priv *bat_priv); | 49 | void batadv_gw_tvlv_container_update(struct batadv_priv *bat_priv); |
50 | void batadv_gw_init(struct batadv_priv *bat_priv); | 50 | void batadv_gw_init(struct batadv_priv *bat_priv); |
51 | void batadv_gw_free(struct batadv_priv *bat_priv); | 51 | void batadv_gw_free(struct batadv_priv *bat_priv); |
52 | bool batadv_parse_throughput(struct net_device *net_dev, char *buff, | ||
53 | const char *description, u32 *throughput); | ||
52 | 54 | ||
53 | #endif /* _NET_BATMAN_ADV_GATEWAY_COMMON_H_ */ | 55 | #endif /* _NET_BATMAN_ADV_GATEWAY_COMMON_H_ */ |
diff --git a/net/batman-adv/sysfs.c b/net/batman-adv/sysfs.c index e86014332e1c..e7cf51333a36 100644 --- a/net/batman-adv/sysfs.c +++ b/net/batman-adv/sysfs.c | |||
@@ -917,12 +917,85 @@ static ssize_t batadv_show_iface_status(struct kobject *kobj, | |||
917 | return length; | 917 | return length; |
918 | } | 918 | } |
919 | 919 | ||
920 | #ifdef CONFIG_BATMAN_ADV_BATMAN_V | ||
921 | |||
922 | /** | ||
923 | * batadv_store_throughput_override - parse and store throughput override | ||
924 | * entered by the user | ||
925 | * @kobj: kobject representing the private mesh sysfs directory | ||
926 | * @attr: the batman-adv attribute the user is interacting with | ||
927 | * @buff: the buffer containing the user data | ||
928 | * @count: number of bytes in the buffer | ||
929 | * | ||
930 | * Return: 'count' on success or a negative error code in case of failure | ||
931 | */ | ||
932 | static ssize_t batadv_store_throughput_override(struct kobject *kobj, | ||
933 | struct attribute *attr, | ||
934 | char *buff, size_t count) | ||
935 | { | ||
936 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); | ||
937 | struct batadv_hard_iface *hard_iface; | ||
938 | u32 tp_override; | ||
939 | u32 old_tp_override; | ||
940 | bool ret; | ||
941 | |||
942 | hard_iface = batadv_hardif_get_by_netdev(net_dev); | ||
943 | if (!hard_iface) | ||
944 | return -EINVAL; | ||
945 | |||
946 | if (buff[count - 1] == '\n') | ||
947 | buff[count - 1] = '\0'; | ||
948 | |||
949 | ret = batadv_parse_throughput(net_dev, buff, "throughput_override", | ||
950 | &tp_override); | ||
951 | if (!ret) | ||
952 | return count; | ||
953 | |||
954 | old_tp_override = atomic_read(&hard_iface->bat_v.throughput_override); | ||
955 | if (old_tp_override == tp_override) | ||
956 | goto out; | ||
957 | |||
958 | batadv_info(net_dev, "%s: Changing from: %u.%u MBit to: %u.%u MBit\n", | ||
959 | "throughput_override", | ||
960 | old_tp_override / 10, old_tp_override % 10, | ||
961 | tp_override / 10, tp_override % 10); | ||
962 | |||
963 | atomic_set(&hard_iface->bat_v.throughput_override, tp_override); | ||
964 | |||
965 | out: | ||
966 | batadv_hardif_put(hard_iface); | ||
967 | return count; | ||
968 | } | ||
969 | |||
970 | static ssize_t batadv_show_throughput_override(struct kobject *kobj, | ||
971 | struct attribute *attr, | ||
972 | char *buff) | ||
973 | { | ||
974 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); | ||
975 | struct batadv_hard_iface *hard_iface; | ||
976 | u32 tp_override; | ||
977 | |||
978 | hard_iface = batadv_hardif_get_by_netdev(net_dev); | ||
979 | if (!hard_iface) | ||
980 | return -EINVAL; | ||
981 | |||
982 | tp_override = atomic_read(&hard_iface->bat_v.throughput_override); | ||
983 | |||
984 | return sprintf(buff, "%u.%u MBit\n", tp_override / 10, | ||
985 | tp_override % 10); | ||
986 | } | ||
987 | |||
988 | #endif | ||
989 | |||
920 | static BATADV_ATTR(mesh_iface, S_IRUGO | S_IWUSR, batadv_show_mesh_iface, | 990 | static BATADV_ATTR(mesh_iface, S_IRUGO | S_IWUSR, batadv_show_mesh_iface, |
921 | batadv_store_mesh_iface); | 991 | batadv_store_mesh_iface); |
922 | static BATADV_ATTR(iface_status, S_IRUGO, batadv_show_iface_status, NULL); | 992 | static BATADV_ATTR(iface_status, S_IRUGO, batadv_show_iface_status, NULL); |
923 | #ifdef CONFIG_BATMAN_ADV_BATMAN_V | 993 | #ifdef CONFIG_BATMAN_ADV_BATMAN_V |
924 | BATADV_ATTR_HIF_UINT(elp_interval, bat_v.elp_interval, S_IRUGO | S_IWUSR, | 994 | BATADV_ATTR_HIF_UINT(elp_interval, bat_v.elp_interval, S_IRUGO | S_IWUSR, |
925 | 2 * BATADV_JITTER, INT_MAX, NULL); | 995 | 2 * BATADV_JITTER, INT_MAX, NULL); |
996 | static BATADV_ATTR(throughput_override, S_IRUGO | S_IWUSR, | ||
997 | batadv_show_throughput_override, | ||
998 | batadv_store_throughput_override); | ||
926 | #endif | 999 | #endif |
927 | 1000 | ||
928 | static struct batadv_attribute *batadv_batman_attrs[] = { | 1001 | static struct batadv_attribute *batadv_batman_attrs[] = { |
@@ -930,6 +1003,7 @@ static struct batadv_attribute *batadv_batman_attrs[] = { | |||
930 | &batadv_attr_iface_status, | 1003 | &batadv_attr_iface_status, |
931 | #ifdef CONFIG_BATMAN_ADV_BATMAN_V | 1004 | #ifdef CONFIG_BATMAN_ADV_BATMAN_V |
932 | &batadv_attr_elp_interval, | 1005 | &batadv_attr_elp_interval, |
1006 | &batadv_attr_throughput_override, | ||
933 | #endif | 1007 | #endif |
934 | NULL, | 1008 | NULL, |
935 | }; | 1009 | }; |
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h index cf55cd0586b5..a6f0952d2840 100644 --- a/net/batman-adv/types.h +++ b/net/batman-adv/types.h | |||
@@ -92,12 +92,14 @@ struct batadv_hard_iface_bat_iv { | |||
92 | * @elp_seqno: current ELP sequence number | 92 | * @elp_seqno: current ELP sequence number |
93 | * @elp_skb: base skb containing the ELP message to send | 93 | * @elp_skb: base skb containing the ELP message to send |
94 | * @elp_wq: workqueue used to schedule ELP transmissions | 94 | * @elp_wq: workqueue used to schedule ELP transmissions |
95 | * @throughput_override: throughput override to disable link auto-detection | ||
95 | */ | 96 | */ |
96 | struct batadv_hard_iface_bat_v { | 97 | struct batadv_hard_iface_bat_v { |
97 | atomic_t elp_interval; | 98 | atomic_t elp_interval; |
98 | atomic_t elp_seqno; | 99 | atomic_t elp_seqno; |
99 | struct sk_buff *elp_skb; | 100 | struct sk_buff *elp_skb; |
100 | struct delayed_work elp_wq; | 101 | struct delayed_work elp_wq; |
102 | atomic_t throughput_override; | ||
101 | }; | 103 | }; |
102 | 104 | ||
103 | /** | 105 | /** |