aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/link.c
diff options
context:
space:
mode:
authorAllan Stephens <allan.stephens@windriver.com>2011-10-18 11:34:29 -0400
committerPaul Gortmaker <paul.gortmaker@windriver.com>2011-12-27 11:33:39 -0500
commit5c216e1d28c82332db0fa53e30536577fb6130c6 (patch)
tree66bc9a4653495c1fddf87cc5fd3d88ab1d14a3a7 /net/tipc/link.c
parentd6d4577ae48bcfde06894540ea793abf076e1643 (diff)
tipc: Allow run-time alteration of default link settings
Permits run-time alteration of default link settings on a per-media and per-bearer basis, in addition to the existing per-link basis. The following syntax can now be used: tipc-config -lt=<link-name|bearer-name|media-name>/<tolerance> tipc-config -lp=<link-name|bearer-name|media-name>/<priority> tipc-config -lw=<link-name|bearer-name|media-name>/<window> Note that changes to the default settings for a given media type has no effect on the default settings used by existing bearers. Similarly, changes to default bearer settings has no effect on existing link endpoints that utilize that interface. Thanks to Florian Westphal <fw@strlen.de> for his contributions to the development of this enhancement. Signed-off-by: Allan Stephens <allan.stephens@windriver.com> Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Diffstat (limited to 'net/tipc/link.c')
-rw-r--r--net/tipc/link.c150
1 files changed, 109 insertions, 41 deletions
diff --git a/net/tipc/link.c b/net/tipc/link.c
index ae98a72da11a..332915e43043 100644
--- a/net/tipc/link.c
+++ b/net/tipc/link.c
@@ -343,7 +343,7 @@ struct link *tipc_link_create(struct tipc_node *n_ptr,
343 l_ptr->checkpoint = 1; 343 l_ptr->checkpoint = 1;
344 l_ptr->peer_session = INVALID_SESSION; 344 l_ptr->peer_session = INVALID_SESSION;
345 l_ptr->b_ptr = b_ptr; 345 l_ptr->b_ptr = b_ptr;
346 link_set_supervision_props(l_ptr, b_ptr->media->tolerance); 346 link_set_supervision_props(l_ptr, b_ptr->tolerance);
347 l_ptr->state = RESET_UNKNOWN; 347 l_ptr->state = RESET_UNKNOWN;
348 348
349 l_ptr->pmsg = (struct tipc_msg *)&l_ptr->proto_msg; 349 l_ptr->pmsg = (struct tipc_msg *)&l_ptr->proto_msg;
@@ -355,7 +355,7 @@ struct link *tipc_link_create(struct tipc_node *n_ptr,
355 strcpy((char *)msg_data(msg), if_name); 355 strcpy((char *)msg_data(msg), if_name);
356 356
357 l_ptr->priority = b_ptr->priority; 357 l_ptr->priority = b_ptr->priority;
358 tipc_link_set_queue_limits(l_ptr, b_ptr->media->window); 358 tipc_link_set_queue_limits(l_ptr, b_ptr->window);
359 359
360 link_init_max_pkt(l_ptr); 360 link_init_max_pkt(l_ptr);
361 361
@@ -2754,13 +2754,113 @@ static struct link *link_find_link(const char *name, struct tipc_node **node)
2754 return l_ptr; 2754 return l_ptr;
2755} 2755}
2756 2756
2757/**
2758 * link_value_is_valid -- validate proposed link tolerance/priority/window
2759 *
2760 * @cmd - value type (TIPC_CMD_SET_LINK_*)
2761 * @new_value - the new value
2762 *
2763 * Returns 1 if value is within range, 0 if not.
2764 */
2765
2766static int link_value_is_valid(u16 cmd, u32 new_value)
2767{
2768 switch (cmd) {
2769 case TIPC_CMD_SET_LINK_TOL:
2770 return (new_value >= TIPC_MIN_LINK_TOL) &&
2771 (new_value <= TIPC_MAX_LINK_TOL);
2772 case TIPC_CMD_SET_LINK_PRI:
2773 return (new_value <= TIPC_MAX_LINK_PRI);
2774 case TIPC_CMD_SET_LINK_WINDOW:
2775 return (new_value >= TIPC_MIN_LINK_WIN) &&
2776 (new_value <= TIPC_MAX_LINK_WIN);
2777 }
2778 return 0;
2779}
2780
2781
2782/**
2783 * link_cmd_set_value - change priority/tolerance/window for link/bearer/media
2784 * @name - ptr to link, bearer, or media name
2785 * @new_value - new value of link, bearer, or media setting
2786 * @cmd - which link, bearer, or media attribute to set (TIPC_CMD_SET_LINK_*)
2787 *
2788 * Caller must hold 'tipc_net_lock' to ensure link/bearer/media is not deleted.
2789 *
2790 * Returns 0 if value updated and negative value on error.
2791 */
2792
2793static int link_cmd_set_value(const char *name, u32 new_value, u16 cmd)
2794{
2795 struct tipc_node *node;
2796 struct link *l_ptr;
2797 struct tipc_bearer *b_ptr;
2798 struct media *m_ptr;
2799
2800 l_ptr = link_find_link(name, &node);
2801 if (l_ptr) {
2802 /*
2803 * acquire node lock for tipc_link_send_proto_msg().
2804 * see "TIPC locking policy" in net.c.
2805 */
2806 tipc_node_lock(node);
2807 switch (cmd) {
2808 case TIPC_CMD_SET_LINK_TOL:
2809 link_set_supervision_props(l_ptr, new_value);
2810 tipc_link_send_proto_msg(l_ptr,
2811 STATE_MSG, 0, 0, new_value, 0, 0);
2812 break;
2813 case TIPC_CMD_SET_LINK_PRI:
2814 l_ptr->priority = new_value;
2815 tipc_link_send_proto_msg(l_ptr,
2816 STATE_MSG, 0, 0, 0, new_value, 0);
2817 break;
2818 case TIPC_CMD_SET_LINK_WINDOW:
2819 tipc_link_set_queue_limits(l_ptr, new_value);
2820 break;
2821 }
2822 tipc_node_unlock(node);
2823 return 0;
2824 }
2825
2826 b_ptr = tipc_bearer_find(name);
2827 if (b_ptr) {
2828 switch (cmd) {
2829 case TIPC_CMD_SET_LINK_TOL:
2830 b_ptr->tolerance = new_value;
2831 return 0;
2832 case TIPC_CMD_SET_LINK_PRI:
2833 b_ptr->priority = new_value;
2834 return 0;
2835 case TIPC_CMD_SET_LINK_WINDOW:
2836 b_ptr->window = new_value;
2837 return 0;
2838 }
2839 return -EINVAL;
2840 }
2841
2842 m_ptr = tipc_media_find(name);
2843 if (!m_ptr)
2844 return -ENODEV;
2845 switch (cmd) {
2846 case TIPC_CMD_SET_LINK_TOL:
2847 m_ptr->tolerance = new_value;
2848 return 0;
2849 case TIPC_CMD_SET_LINK_PRI:
2850 m_ptr->priority = new_value;
2851 return 0;
2852 case TIPC_CMD_SET_LINK_WINDOW:
2853 m_ptr->window = new_value;
2854 return 0;
2855 }
2856 return -EINVAL;
2857}
2858
2757struct sk_buff *tipc_link_cmd_config(const void *req_tlv_area, int req_tlv_space, 2859struct sk_buff *tipc_link_cmd_config(const void *req_tlv_area, int req_tlv_space,
2758 u16 cmd) 2860 u16 cmd)
2759{ 2861{
2760 struct tipc_link_config *args; 2862 struct tipc_link_config *args;
2761 u32 new_value; 2863 u32 new_value;
2762 struct link *l_ptr;
2763 struct tipc_node *node;
2764 int res; 2864 int res;
2765 2865
2766 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_CONFIG)) 2866 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_CONFIG))
@@ -2769,6 +2869,10 @@ struct sk_buff *tipc_link_cmd_config(const void *req_tlv_area, int req_tlv_space
2769 args = (struct tipc_link_config *)TLV_DATA(req_tlv_area); 2869 args = (struct tipc_link_config *)TLV_DATA(req_tlv_area);
2770 new_value = ntohl(args->value); 2870 new_value = ntohl(args->value);
2771 2871
2872 if (!link_value_is_valid(cmd, new_value))
2873 return tipc_cfg_reply_error_string(
2874 "cannot change, value invalid");
2875
2772 if (!strcmp(args->name, tipc_bclink_name)) { 2876 if (!strcmp(args->name, tipc_bclink_name)) {
2773 if ((cmd == TIPC_CMD_SET_LINK_WINDOW) && 2877 if ((cmd == TIPC_CMD_SET_LINK_WINDOW) &&
2774 (tipc_bclink_set_queue_limits(new_value) == 0)) 2878 (tipc_bclink_set_queue_limits(new_value) == 0))
@@ -2778,43 +2882,7 @@ struct sk_buff *tipc_link_cmd_config(const void *req_tlv_area, int req_tlv_space
2778 } 2882 }
2779 2883
2780 read_lock_bh(&tipc_net_lock); 2884 read_lock_bh(&tipc_net_lock);
2781 l_ptr = link_find_link(args->name, &node); 2885 res = link_cmd_set_value(args->name, new_value, cmd);
2782 if (!l_ptr) {
2783 read_unlock_bh(&tipc_net_lock);
2784 return tipc_cfg_reply_error_string("link not found");
2785 }
2786
2787 tipc_node_lock(node);
2788 res = -EINVAL;
2789 switch (cmd) {
2790 case TIPC_CMD_SET_LINK_TOL:
2791 if ((new_value >= TIPC_MIN_LINK_TOL) &&
2792 (new_value <= TIPC_MAX_LINK_TOL)) {
2793 link_set_supervision_props(l_ptr, new_value);
2794 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
2795 0, 0, new_value, 0, 0);
2796 res = 0;
2797 }
2798 break;
2799 case TIPC_CMD_SET_LINK_PRI:
2800 if ((new_value >= TIPC_MIN_LINK_PRI) &&
2801 (new_value <= TIPC_MAX_LINK_PRI)) {
2802 l_ptr->priority = new_value;
2803 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
2804 0, 0, 0, new_value, 0);
2805 res = 0;
2806 }
2807 break;
2808 case TIPC_CMD_SET_LINK_WINDOW:
2809 if ((new_value >= TIPC_MIN_LINK_WIN) &&
2810 (new_value <= TIPC_MAX_LINK_WIN)) {
2811 tipc_link_set_queue_limits(l_ptr, new_value);
2812 res = 0;
2813 }
2814 break;
2815 }
2816 tipc_node_unlock(node);
2817
2818 read_unlock_bh(&tipc_net_lock); 2886 read_unlock_bh(&tipc_net_lock);
2819 if (res) 2887 if (res)
2820 return tipc_cfg_reply_error_string("cannot change link setting"); 2888 return tipc_cfg_reply_error_string("cannot change link setting");