Skip to content

Commit 37e2d48

Browse files
Richard Alpedavem330
authored andcommitted
tipc: convert legacy nl link prop set to nl compat
Convert setting of link proprieties to compat doit calls. Commands converted in this patch: TIPC_CMD_SET_LINK_TOL TIPC_CMD_SET_LINK_PRI TIPC_CMD_SET_LINK_WINDOW Signed-off-by: Richard Alpe <richard.alpe@ericsson.com> Reviewed-by: Erik Hugne <erik.hugne@ericsson.com> Reviewed-by: Ying Xue <ying.xue@windriver.com> Reviewed-by: Jon Maloy <jon.maloy@ericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 357ebdb commit 37e2d48

4 files changed

Lines changed: 48 additions & 153 deletions

File tree

‎net/tipc/config.c‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,6 @@ struct sk_buff *tipc_cfg_do_cmd(struct net *net, u32 orig_node, u16 cmd,
226226
case TIPC_CMD_SHOW_STATS:
227227
rep_tlv_buf = tipc_show_stats();
228228
break;
229-
case TIPC_CMD_SET_LINK_TOL:
230-
case TIPC_CMD_SET_LINK_PRI:
231-
case TIPC_CMD_SET_LINK_WINDOW:
232-
rep_tlv_buf = tipc_link_cmd_config(net, req_tlv_area,
233-
req_tlv_space, cmd);
234-
break;
235229
case TIPC_CMD_SET_NODE_ADDR:
236230
rep_tlv_buf = cfg_set_own_addr(net);
237231
break;

‎net/tipc/link.c‎

Lines changed: 1 addition & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,150 +1958,6 @@ static struct tipc_node *tipc_link_find_owner(struct net *net,
19581958
return found_node;
19591959
}
19601960

1961-
/**
1962-
* link_value_is_valid -- validate proposed link tolerance/priority/window
1963-
*
1964-
* @cmd: value type (TIPC_CMD_SET_LINK_*)
1965-
* @new_value: the new value
1966-
*
1967-
* Returns 1 if value is within range, 0 if not.
1968-
*/
1969-
static int link_value_is_valid(u16 cmd, u32 new_value)
1970-
{
1971-
switch (cmd) {
1972-
case TIPC_CMD_SET_LINK_TOL:
1973-
return (new_value >= TIPC_MIN_LINK_TOL) &&
1974-
(new_value <= TIPC_MAX_LINK_TOL);
1975-
case TIPC_CMD_SET_LINK_PRI:
1976-
return (new_value <= TIPC_MAX_LINK_PRI);
1977-
case TIPC_CMD_SET_LINK_WINDOW:
1978-
return (new_value >= TIPC_MIN_LINK_WIN) &&
1979-
(new_value <= TIPC_MAX_LINK_WIN);
1980-
}
1981-
return 0;
1982-
}
1983-
1984-
/**
1985-
* link_cmd_set_value - change priority/tolerance/window for link/bearer/media
1986-
* @net: the applicable net namespace
1987-
* @name: ptr to link, bearer, or media name
1988-
* @new_value: new value of link, bearer, or media setting
1989-
* @cmd: which link, bearer, or media attribute to set (TIPC_CMD_SET_LINK_*)
1990-
*
1991-
* Caller must hold RTNL lock to ensure link/bearer/media is not deleted.
1992-
*
1993-
* Returns 0 if value updated and negative value on error.
1994-
*/
1995-
static int link_cmd_set_value(struct net *net, const char *name, u32 new_value,
1996-
u16 cmd)
1997-
{
1998-
struct tipc_node *node;
1999-
struct tipc_link *l_ptr;
2000-
struct tipc_bearer *b_ptr;
2001-
struct tipc_media *m_ptr;
2002-
int bearer_id;
2003-
int res = 0;
2004-
2005-
node = tipc_link_find_owner(net, name, &bearer_id);
2006-
if (node) {
2007-
tipc_node_lock(node);
2008-
l_ptr = node->links[bearer_id];
2009-
2010-
if (l_ptr) {
2011-
switch (cmd) {
2012-
case TIPC_CMD_SET_LINK_TOL:
2013-
link_set_supervision_props(l_ptr, new_value);
2014-
tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, 0,
2015-
new_value, 0, 0);
2016-
break;
2017-
case TIPC_CMD_SET_LINK_PRI:
2018-
l_ptr->priority = new_value;
2019-
tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, 0,
2020-
0, new_value, 0);
2021-
break;
2022-
case TIPC_CMD_SET_LINK_WINDOW:
2023-
tipc_link_set_queue_limits(l_ptr, new_value);
2024-
break;
2025-
default:
2026-
res = -EINVAL;
2027-
break;
2028-
}
2029-
}
2030-
tipc_node_unlock(node);
2031-
return res;
2032-
}
2033-
2034-
b_ptr = tipc_bearer_find(net, name);
2035-
if (b_ptr) {
2036-
switch (cmd) {
2037-
case TIPC_CMD_SET_LINK_TOL:
2038-
b_ptr->tolerance = new_value;
2039-
break;
2040-
case TIPC_CMD_SET_LINK_PRI:
2041-
b_ptr->priority = new_value;
2042-
break;
2043-
case TIPC_CMD_SET_LINK_WINDOW:
2044-
b_ptr->window = new_value;
2045-
break;
2046-
default:
2047-
res = -EINVAL;
2048-
break;
2049-
}
2050-
return res;
2051-
}
2052-
2053-
m_ptr = tipc_media_find(name);
2054-
if (!m_ptr)
2055-
return -ENODEV;
2056-
switch (cmd) {
2057-
case TIPC_CMD_SET_LINK_TOL:
2058-
m_ptr->tolerance = new_value;
2059-
break;
2060-
case TIPC_CMD_SET_LINK_PRI:
2061-
m_ptr->priority = new_value;
2062-
break;
2063-
case TIPC_CMD_SET_LINK_WINDOW:
2064-
m_ptr->window = new_value;
2065-
break;
2066-
default:
2067-
res = -EINVAL;
2068-
break;
2069-
}
2070-
return res;
2071-
}
2072-
2073-
struct sk_buff *tipc_link_cmd_config(struct net *net, const void *req_tlv_area,
2074-
int req_tlv_space, u16 cmd)
2075-
{
2076-
struct tipc_link_config *args;
2077-
u32 new_value;
2078-
int res;
2079-
2080-
if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_CONFIG))
2081-
return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
2082-
2083-
args = (struct tipc_link_config *)TLV_DATA(req_tlv_area);
2084-
new_value = ntohl(args->value);
2085-
2086-
if (!link_value_is_valid(cmd, new_value))
2087-
return tipc_cfg_reply_error_string(
2088-
"cannot change, value invalid");
2089-
2090-
if (!strcmp(args->name, tipc_bclink_name)) {
2091-
if ((cmd == TIPC_CMD_SET_LINK_WINDOW) &&
2092-
(tipc_bclink_set_queue_limits(net, new_value) == 0))
2093-
return tipc_cfg_reply_none();
2094-
return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
2095-
" (cannot change setting on broadcast link)");
2096-
}
2097-
2098-
res = link_cmd_set_value(net, args->name, new_value, cmd);
2099-
if (res)
2100-
return tipc_cfg_reply_error_string("cannot change link setting");
2101-
2102-
return tipc_cfg_reply_none();
2103-
}
2104-
21051961
/**
21061962
* link_reset_statistics - reset link statistics
21071963
* @l_ptr: pointer to link
@@ -2216,7 +2072,7 @@ int tipc_nl_link_set(struct sk_buff *skb, struct genl_info *info)
22162072
struct tipc_link *link;
22172073
struct tipc_node *node;
22182074
struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1];
2219-
struct net *net = genl_info_net(info);
2075+
struct net *net = sock_net(skb->sk);
22202076

22212077
if (!info->attrs[TIPC_NLA_LINK])
22222078
return -EINVAL;

‎net/tipc/link.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,6 @@ void tipc_link_reset_fragments(struct tipc_link *l_ptr);
215215
int tipc_link_is_up(struct tipc_link *l_ptr);
216216
int tipc_link_is_active(struct tipc_link *l_ptr);
217217
void tipc_link_purge_queues(struct tipc_link *l_ptr);
218-
struct sk_buff *tipc_link_cmd_config(struct net *net, const void *req_tlv_area,
219-
int req_tlv_space, u16 cmd);
220218
struct sk_buff *tipc_link_cmd_reset_stats(struct net *net,
221219
const void *req_tlv_area,
222220
int req_tlv_space);

‎net/tipc/netlink_compat.c‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,43 @@ static int tipc_nl_compat_link_dump(struct tipc_nl_compat_msg *msg,
569569
&link_info, sizeof(link_info));
570570
}
571571

572+
static int tipc_nl_compat_link_set(struct sk_buff *skb,
573+
struct tipc_nl_compat_msg *msg)
574+
{
575+
struct nlattr *link;
576+
struct nlattr *prop;
577+
struct tipc_link_config *lc;
578+
579+
lc = (struct tipc_link_config *)TLV_DATA(msg->req);
580+
581+
link = nla_nest_start(skb, TIPC_NLA_LINK);
582+
if (!link)
583+
return -EMSGSIZE;
584+
585+
if (nla_put_string(skb, TIPC_NLA_LINK_NAME, lc->name))
586+
return -EMSGSIZE;
587+
588+
prop = nla_nest_start(skb, TIPC_NLA_LINK_PROP);
589+
if (!prop)
590+
return -EMSGSIZE;
591+
592+
if (msg->cmd == TIPC_CMD_SET_LINK_PRI) {
593+
if (nla_put_u32(skb, TIPC_NLA_PROP_PRIO, ntohl(lc->value)))
594+
return -EMSGSIZE;
595+
} else if (msg->cmd == TIPC_CMD_SET_LINK_TOL) {
596+
if (nla_put_u32(skb, TIPC_NLA_PROP_TOL, ntohl(lc->value)))
597+
return -EMSGSIZE;
598+
} else if (msg->cmd == TIPC_CMD_SET_LINK_WINDOW) {
599+
if (nla_put_u32(skb, TIPC_NLA_PROP_WIN, ntohl(lc->value)))
600+
return -EMSGSIZE;
601+
}
602+
603+
nla_nest_end(skb, prop);
604+
nla_nest_end(skb, link);
605+
606+
return 0;
607+
}
608+
572609
static int tipc_nl_compat_handle(struct tipc_nl_compat_msg *msg)
573610
{
574611
struct tipc_nl_compat_cmd_dump dump;
@@ -606,6 +643,13 @@ static int tipc_nl_compat_handle(struct tipc_nl_compat_msg *msg)
606643
dump.dumpit = tipc_nl_link_dump;
607644
dump.format = tipc_nl_compat_link_dump;
608645
return tipc_nl_compat_dumpit(&dump, msg);
646+
case TIPC_CMD_SET_LINK_TOL:
647+
case TIPC_CMD_SET_LINK_PRI:
648+
case TIPC_CMD_SET_LINK_WINDOW:
649+
msg->req_type = TIPC_TLV_LINK_CONFIG;
650+
doit.doit = tipc_nl_link_set;
651+
doit.transcode = tipc_nl_compat_link_set;
652+
return tipc_nl_compat_doit(&doit, msg);
609653
}
610654

611655
return -EOPNOTSUPP;
@@ -707,6 +751,9 @@ static int tipc_nl_compat_tmp_wrap(struct sk_buff *skb, struct genl_info *info)
707751
case TIPC_CMD_DISABLE_BEARER:
708752
case TIPC_CMD_SHOW_LINK_STATS:
709753
case TIPC_CMD_GET_LINKS:
754+
case TIPC_CMD_SET_LINK_TOL:
755+
case TIPC_CMD_SET_LINK_PRI:
756+
case TIPC_CMD_SET_LINK_WINDOW:
710757
return tipc_nl_compat_recv(skb, info);
711758
}
712759

0 commit comments

Comments
 (0)