You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(6) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(9) |
Feb
(11) |
Mar
(22) |
Apr
(73) |
May
(78) |
Jun
(146) |
Jul
(80) |
Aug
(27) |
Sep
(5) |
Oct
(14) |
Nov
(18) |
Dec
(27) |
2005 |
Jan
(20) |
Feb
(30) |
Mar
(19) |
Apr
(28) |
May
(50) |
Jun
(31) |
Jul
(32) |
Aug
(14) |
Sep
(36) |
Oct
(43) |
Nov
(74) |
Dec
(63) |
2006 |
Jan
(34) |
Feb
(32) |
Mar
(21) |
Apr
(76) |
May
(106) |
Jun
(72) |
Jul
(70) |
Aug
(175) |
Sep
(130) |
Oct
(39) |
Nov
(81) |
Dec
(43) |
2007 |
Jan
(81) |
Feb
(36) |
Mar
(20) |
Apr
(43) |
May
(54) |
Jun
(34) |
Jul
(44) |
Aug
(55) |
Sep
(44) |
Oct
(54) |
Nov
(43) |
Dec
(41) |
2008 |
Jan
(42) |
Feb
(84) |
Mar
(73) |
Apr
(30) |
May
(119) |
Jun
(54) |
Jul
(54) |
Aug
(93) |
Sep
(173) |
Oct
(130) |
Nov
(145) |
Dec
(153) |
2009 |
Jan
(59) |
Feb
(12) |
Mar
(28) |
Apr
(18) |
May
(56) |
Jun
(9) |
Jul
(28) |
Aug
(62) |
Sep
(16) |
Oct
(19) |
Nov
(15) |
Dec
(17) |
2010 |
Jan
(14) |
Feb
(36) |
Mar
(37) |
Apr
(30) |
May
(33) |
Jun
(53) |
Jul
(42) |
Aug
(50) |
Sep
(67) |
Oct
(66) |
Nov
(69) |
Dec
(36) |
2011 |
Jan
(52) |
Feb
(45) |
Mar
(49) |
Apr
(21) |
May
(34) |
Jun
(13) |
Jul
(19) |
Aug
(37) |
Sep
(43) |
Oct
(10) |
Nov
(23) |
Dec
(30) |
2012 |
Jan
(42) |
Feb
(36) |
Mar
(46) |
Apr
(25) |
May
(96) |
Jun
(146) |
Jul
(40) |
Aug
(28) |
Sep
(61) |
Oct
(45) |
Nov
(100) |
Dec
(53) |
2013 |
Jan
(79) |
Feb
(24) |
Mar
(134) |
Apr
(156) |
May
(118) |
Jun
(75) |
Jul
(278) |
Aug
(145) |
Sep
(136) |
Oct
(168) |
Nov
(137) |
Dec
(439) |
2014 |
Jan
(284) |
Feb
(158) |
Mar
(231) |
Apr
(275) |
May
(259) |
Jun
(91) |
Jul
(222) |
Aug
(215) |
Sep
(165) |
Oct
(166) |
Nov
(211) |
Dec
(150) |
2015 |
Jan
(164) |
Feb
(324) |
Mar
(299) |
Apr
(214) |
May
(111) |
Jun
(109) |
Jul
(105) |
Aug
(36) |
Sep
(58) |
Oct
(131) |
Nov
(68) |
Dec
(30) |
2016 |
Jan
(46) |
Feb
(87) |
Mar
(135) |
Apr
(174) |
May
(132) |
Jun
(135) |
Jul
(149) |
Aug
(125) |
Sep
(79) |
Oct
(49) |
Nov
(95) |
Dec
(102) |
2017 |
Jan
(104) |
Feb
(75) |
Mar
(72) |
Apr
(53) |
May
(18) |
Jun
(5) |
Jul
(14) |
Aug
(19) |
Sep
(2) |
Oct
(13) |
Nov
(21) |
Dec
(67) |
2018 |
Jan
(56) |
Feb
(50) |
Mar
(148) |
Apr
(41) |
May
(37) |
Jun
(34) |
Jul
(34) |
Aug
(11) |
Sep
(52) |
Oct
(48) |
Nov
(28) |
Dec
(46) |
2019 |
Jan
(29) |
Feb
(63) |
Mar
(95) |
Apr
(54) |
May
(14) |
Jun
(71) |
Jul
(60) |
Aug
(49) |
Sep
(3) |
Oct
(64) |
Nov
(115) |
Dec
(57) |
2020 |
Jan
(15) |
Feb
(9) |
Mar
(38) |
Apr
(27) |
May
(60) |
Jun
(53) |
Jul
(35) |
Aug
(46) |
Sep
(37) |
Oct
(64) |
Nov
(20) |
Dec
(25) |
2021 |
Jan
(20) |
Feb
(31) |
Mar
(27) |
Apr
(23) |
May
(21) |
Jun
(30) |
Jul
(30) |
Aug
(7) |
Sep
(18) |
Oct
|
Nov
(15) |
Dec
(4) |
2022 |
Jan
(3) |
Feb
(1) |
Mar
(10) |
Apr
|
May
(2) |
Jun
(26) |
Jul
(5) |
Aug
|
Sep
(1) |
Oct
(2) |
Nov
(9) |
Dec
(2) |
2023 |
Jan
(4) |
Feb
(4) |
Mar
(5) |
Apr
(10) |
May
(29) |
Jun
(17) |
Jul
|
Aug
|
Sep
(1) |
Oct
(1) |
Nov
(2) |
Dec
|
2024 |
Jan
|
Feb
(6) |
Mar
|
Apr
(1) |
May
(6) |
Jun
|
Jul
(5) |
Aug
|
Sep
(3) |
Oct
|
Nov
|
Dec
|
2025 |
Jan
|
Feb
(3) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(6) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Hoang Le <hoa...@de...> - 2021-04-09 08:17:32
|
The using of the node address and node link identity are not thread safe, meaning that two publications may be published the same values, as result one of them will get failure because of already existing in the name table. To avoid this we have to use the node address and node link identity values from inside the node item's write lock protection. Fixes: 50a3499ab853 ("tipc: simplify signature of tipc_namtbl_publish()") Signed-off-by: Hoang Le <hoa...@de...> --- net/tipc/node.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/net/tipc/node.c b/net/tipc/node.c index 707d0dc71fad..b8cf298a3413 100644 --- a/net/tipc/node.c +++ b/net/tipc/node.c @@ -423,18 +423,18 @@ static void tipc_node_write_unlock(struct tipc_node *n) write_unlock_bh(&n->lock); if (flags & TIPC_NOTIFY_NODE_DOWN) - tipc_publ_notify(net, publ_list, n->addr, n->capabilities); + tipc_publ_notify(net, publ_list, sk.node, n->capabilities); if (flags & TIPC_NOTIFY_NODE_UP) - tipc_named_node_up(net, n->addr, n->capabilities); + tipc_named_node_up(net, sk.node, n->capabilities); if (flags & TIPC_NOTIFY_LINK_UP) { - tipc_mon_peer_up(net, n->addr, bearer_id); - tipc_nametbl_publish(net, &ua, &sk, n->link_id); + tipc_mon_peer_up(net, sk.node, bearer_id); + tipc_nametbl_publish(net, &ua, &sk, sk.ref); } if (flags & TIPC_NOTIFY_LINK_DOWN) { - tipc_mon_peer_down(net, n->addr, bearer_id); - tipc_nametbl_withdraw(net, &ua, &sk, n->link_id); + tipc_mon_peer_down(net, sk.node, bearer_id); + tipc_nametbl_withdraw(net, &ua, &sk, sk.ref); } } -- 2.25.1 |
From: <jm...@re...> - 2021-04-07 20:59:33
|
From: Jon Maloy <jm...@re...> We eliminate the redundant fields conn_type and conn_instance in struct tipc_sock. On the connecting side, this information is already present in the unused (after the connection is established) part of the pre-allocated header, and on the accepting side, we put the info there when the new socket is created. Signed-off-by: Jon Maloy <jm...@re...> --- net/tipc/socket.c | 53 ++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/net/tipc/socket.c b/net/tipc/socket.c index f21162aa0cf7..12a97755bc80 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c @@ -73,9 +73,6 @@ struct sockaddr_pair { /** * struct tipc_sock - TIPC socket structure * @sk: socket - interacts with 'port' and with user via the socket API - * @conn_type: TIPC type used when connection was established - * @conn_instance: TIPC instance used when connection was established - * @published: non-zero if port has one or more associated names * @max_pkt: maximum packet size "hint" used when building messages sent by port * @maxnagle: maximum size of msg which can be subject to nagle * @portid: unique port identity in TIPC socket hash table @@ -106,11 +103,11 @@ struct sockaddr_pair { * @expect_ack: whether this TIPC socket is expecting an ack * @nodelay: setsockopt() TIPC_NODELAY setting * @group_is_open: TIPC socket group is fully open (FIXME) + * @published: true if port has one or more associated names + * @conn_addrtype: address type used when establishing connection */ struct tipc_sock { struct sock sk; - u32 conn_type; - u32 conn_instance; u32 max_pkt; u32 maxnagle; u32 portid; @@ -141,6 +138,7 @@ struct tipc_sock { bool nodelay; bool group_is_open; bool published; + u8 conn_addrtype; }; static int tipc_sk_backlog_rcv(struct sock *sk, struct sk_buff *skb); @@ -1460,10 +1458,8 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dlen) return -EISCONN; if (tsk->published) return -EOPNOTSUPP; - if (atype == TIPC_SERVICE_ADDR) { - tsk->conn_type = ua->sa.type; - tsk->conn_instance = ua->sa.instance; - } + if (atype == TIPC_SERVICE_ADDR) + tsk->conn_addrtype = atype; msg_set_syn(hdr, 1); } @@ -1780,10 +1776,10 @@ static int tipc_sk_anc_data_recv(struct msghdr *m, struct sk_buff *skb, anc_data[2] = msg_nameupper(msg); break; case TIPC_CONN_MSG: - has_name = (tsk->conn_type != 0); - anc_data[0] = tsk->conn_type; - anc_data[1] = tsk->conn_instance; - anc_data[2] = tsk->conn_instance; + has_name = !!tsk->conn_addrtype; + anc_data[0] = msg_nametype(&tsk->phdr); + anc_data[1] = msg_nameinst(&tsk->phdr); + anc_data[2] = anc_data[1]; break; default: has_name = 0; @@ -2747,8 +2743,9 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags, tsk_set_importance(new_sk, msg_importance(msg)); if (msg_named(msg)) { - new_tsock->conn_type = msg_nametype(msg); - new_tsock->conn_instance = msg_nameinst(msg); + new_tsock->conn_addrtype = TIPC_SERVICE_ADDR; + msg_set_nametype(&new_tsock->phdr, msg_nametype(msg)); + msg_set_nameinst(&new_tsock->phdr, msg_nameinst(msg)); } /* @@ -3452,13 +3449,14 @@ void tipc_socket_stop(void) /* Caller should hold socket lock for the passed tipc socket. */ static int __tipc_nl_add_sk_con(struct sk_buff *skb, struct tipc_sock *tsk) { - u32 peer_node; - u32 peer_port; + u32 peer_node, peer_port; + u32 conn_type, conn_instance; struct nlattr *nest; peer_node = tsk_peer_node(tsk); peer_port = tsk_peer_port(tsk); - + conn_type = msg_nametype(&tsk->phdr); + conn_instance = msg_nameinst(&tsk->phdr); nest = nla_nest_start_noflag(skb, TIPC_NLA_SOCK_CON); if (!nest) return -EMSGSIZE; @@ -3468,12 +3466,12 @@ static int __tipc_nl_add_sk_con(struct sk_buff *skb, struct tipc_sock *tsk) if (nla_put_u32(skb, TIPC_NLA_CON_SOCK, peer_port)) goto msg_full; - if (tsk->conn_type != 0) { + if (tsk->conn_addrtype != 0) { if (nla_put_flag(skb, TIPC_NLA_CON_FLAG)) goto msg_full; - if (nla_put_u32(skb, TIPC_NLA_CON_TYPE, tsk->conn_type)) + if (nla_put_u32(skb, TIPC_NLA_CON_TYPE, conn_type)) goto msg_full; - if (nla_put_u32(skb, TIPC_NLA_CON_INST, tsk->conn_instance)) + if (nla_put_u32(skb, TIPC_NLA_CON_INST, conn_instance)) goto msg_full; } nla_nest_end(skb, nest); @@ -3863,9 +3861,9 @@ bool tipc_sk_filtering(struct sock *sk) } if (!tipc_sk_type_connectionless(sk)) { - type = tsk->conn_type; - lower = tsk->conn_instance; - upper = tsk->conn_instance; + type = msg_nametype(&tsk->phdr); + lower = msg_nameinst(&tsk->phdr); + upper = lower; } if ((_type && _type != type) || (_lower && _lower != lower) || @@ -3930,6 +3928,7 @@ int tipc_sk_dump(struct sock *sk, u16 dqueues, char *buf) { int i = 0; size_t sz = (dqueues) ? SK_LMAX : SK_LMIN; + u32 conn_type, conn_instance; struct tipc_sock *tsk; struct publication *p; bool tsk_connected; @@ -3950,8 +3949,10 @@ int tipc_sk_dump(struct sock *sk, u16 dqueues, char *buf) if (tsk_connected) { i += scnprintf(buf + i, sz - i, " %x", tsk_peer_node(tsk)); i += scnprintf(buf + i, sz - i, " %u", tsk_peer_port(tsk)); - i += scnprintf(buf + i, sz - i, " %u", tsk->conn_type); - i += scnprintf(buf + i, sz - i, " %u", tsk->conn_instance); + conn_type = msg_nametype(&tsk->phdr); + conn_instance = msg_nameinst(&tsk->phdr); + i += scnprintf(buf + i, sz - i, " %u", conn_type); + i += scnprintf(buf + i, sz - i, " %u", conn_instance); } i += scnprintf(buf + i, sz - i, " | %u", tsk->published); if (tsk->published) { -- 2.29.2 |
From: <jm...@re...> - 2021-04-07 20:59:08
|
From: Jon Maloy <jm...@re...> We introduce a new macro TIPC_ANY_SCOPE to make the handling of the lookup scope value more comprehensible during multicast reception. The (unchanged) rules go as follows: 1) Multicast messages sent from own node are delivered to all matching sockets on the own node, irrespective of their binding scope. 2) Multicast messages sent from other nodes arrive here because they have found TIPC_CLUSTER_SCOPE bindings coming from this node. Those messages should be delivered to exactly those sockets, but not to local sockets bound with TIPC_NODE_SCOPE, since the latter obviously were not meant to be visible for those senders. 3) Group multicast/broadcast messages are delivered to the sockets with a binding scope matching exactly the lookup scope indicated in the message header, and nobodey else. Signed-off-by: Jon Maloy <jm...@re...> --- net/tipc/name_table.c | 6 +++--- net/tipc/name_table.h | 4 +++- net/tipc/socket.c | 19 +++++++------------ 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c index 6db9f9e7c0ac..86007bcaf47c 100644 --- a/net/tipc/name_table.c +++ b/net/tipc/name_table.c @@ -671,12 +671,12 @@ bool tipc_nametbl_lookup_group(struct net *net, struct tipc_uaddr *ua, * Returns a list of local sockets */ void tipc_nametbl_lookup_mcast_sockets(struct net *net, struct tipc_uaddr *ua, - bool exact, struct list_head *dports) + struct list_head *dports) { struct service_range *sr; struct tipc_service *sc; struct publication *p; - u32 scope = ua->scope; + u8 scope = ua->scope; rcu_read_lock(); sc = tipc_service_find(net, ua); @@ -686,7 +686,7 @@ void tipc_nametbl_lookup_mcast_sockets(struct net *net, struct tipc_uaddr *ua, spin_lock_bh(&sc->lock); service_range_foreach_match(sr, sc, ua->sr.lower, ua->sr.upper) { list_for_each_entry(p, &sr->local_publ, local_publ) { - if (p->scope == scope || (!exact && p->scope < scope)) + if (scope == p->scope || scope == TIPC_ANY_SCOPE) tipc_dest_push(dports, 0, p->sk.ref); } } diff --git a/net/tipc/name_table.h b/net/tipc/name_table.h index c7c9a3ddd420..148b0f640959 100644 --- a/net/tipc/name_table.h +++ b/net/tipc/name_table.h @@ -51,6 +51,8 @@ struct tipc_uaddr; #define TIPC_PUBL_SCOPE_NUM (TIPC_NODE_SCOPE + 1) #define TIPC_NAMETBL_SIZE 1024 /* must be a power of 2 */ +#define TIPC_ANY_SCOPE 255 + /** * struct publication - info about a published service address or range * @sr: service range represented by this publication @@ -113,7 +115,7 @@ int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb); bool tipc_nametbl_lookup_anycast(struct net *net, struct tipc_uaddr *ua, struct tipc_socket_addr *sk); void tipc_nametbl_lookup_mcast_sockets(struct net *net, struct tipc_uaddr *ua, - bool exact, struct list_head *dports); + struct list_head *dports); void tipc_nametbl_lookup_mcast_nodes(struct net *net, struct tipc_uaddr *ua, struct tipc_nlist *nodes); bool tipc_nametbl_lookup_group(struct net *net, struct tipc_uaddr *ua, diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 61aefb9f6fd8..c85859b73adf 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c @@ -1200,7 +1200,6 @@ void tipc_sk_mcast_rcv(struct net *net, struct sk_buff_head *arrvq, struct tipc_msg *hdr; struct tipc_uaddr ua; int user, mtyp, hlen; - bool exact; __skb_queue_head_init(&tmpq); INIT_LIST_HEAD(&dports); @@ -1214,6 +1213,12 @@ void tipc_sk_mcast_rcv(struct net *net, struct sk_buff_head *arrvq, hlen = skb_headroom(skb) + msg_hdr_sz(hdr); onode = msg_orignode(hdr); ua.sr.type = msg_nametype(hdr); + ua.sr.lower = msg_namelower(hdr); + ua.sr.upper = msg_nameupper(hdr); + if (onode == self) + ua.scope = TIPC_ANY_SCOPE; + else + ua.scope = TIPC_CLUSTER_SCOPE; if (mtyp == TIPC_GRP_UCAST_MSG || user == GROUP_PROTOCOL) { spin_lock_bh(&inputq->lock); @@ -1231,20 +1236,10 @@ void tipc_sk_mcast_rcv(struct net *net, struct sk_buff_head *arrvq, ua.sr.lower = 0; ua.sr.upper = ~0; ua.scope = msg_lookup_scope(hdr); - exact = true; - } else { - /* TIPC_NODE_SCOPE means "any scope" in this context */ - if (onode == self) - ua.scope = TIPC_NODE_SCOPE; - else - ua.scope = TIPC_CLUSTER_SCOPE; - exact = false; - ua.sr.lower = msg_namelower(hdr); - ua.sr.upper = msg_nameupper(hdr); } /* Create destination port list: */ - tipc_nametbl_lookup_mcast_sockets(net, &ua, exact, &dports); + tipc_nametbl_lookup_mcast_sockets(net, &ua, &dports); /* Clone message per destination */ while (tipc_dest_pop(&dports, NULL, &portid)) { -- 2.29.2 |
From: <jm...@re...> - 2021-04-07 20:59:08
|
From: Jon Maloy <jm...@re...> We refactor tipc_sk_anc_data_recv() to make it slighltly more comprehensible, but also to prepare for some additions to the code in a future commit. Signed-off-by: Jon Maloy <jm...@re...> --- net/tipc/socket.c | 85 +++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 47 deletions(-) diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 12a97755bc80..61aefb9f6fd8 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c @@ -1730,67 +1730,58 @@ static void tipc_sk_set_orig_addr(struct msghdr *m, struct sk_buff *skb) static int tipc_sk_anc_data_recv(struct msghdr *m, struct sk_buff *skb, struct tipc_sock *tsk) { - struct tipc_msg *msg; - u32 anc_data[3]; - u32 err; - u32 dest_type; - int has_name; - int res; + struct tipc_msg *hdr; + u32 data[3] = {0,}; + bool has_addr; + int dlen, rc; if (likely(m->msg_controllen == 0)) return 0; - msg = buf_msg(skb); - /* Optionally capture errored message object(s) */ - err = msg ? msg_errcode(msg) : 0; - if (unlikely(err)) { - anc_data[0] = err; - anc_data[1] = msg_data_sz(msg); - res = put_cmsg(m, SOL_TIPC, TIPC_ERRINFO, 8, anc_data); - if (res) - return res; - if (anc_data[1]) { - if (skb_linearize(skb)) - return -ENOMEM; - msg = buf_msg(skb); - res = put_cmsg(m, SOL_TIPC, TIPC_RETDATA, anc_data[1], - msg_data(msg)); - if (res) - return res; - } + hdr = buf_msg(skb); + dlen = msg_data_sz(hdr); + + /* Capture errored message object, if any */ + if (msg_errcode(hdr)) { + if (skb_linearize(skb)) + return -ENOMEM; + hdr = buf_msg(skb); + data[0] = msg_errcode(hdr); + data[1] = dlen; + rc = put_cmsg(m, SOL_TIPC, TIPC_ERRINFO, 8, data); + if (rc || !dlen) + return rc; + rc = put_cmsg(m, SOL_TIPC, TIPC_RETDATA, dlen, msg_data(hdr)); + if (rc) + return rc; } - /* Optionally capture message destination object */ - dest_type = msg ? msg_type(msg) : TIPC_DIRECT_MSG; - switch (dest_type) { + /* Capture TIPC_SERVICE_ADDR/RANGE destination address, if any */ + switch (msg_type(hdr)) { case TIPC_NAMED_MSG: - has_name = 1; - anc_data[0] = msg_nametype(msg); - anc_data[1] = msg_namelower(msg); - anc_data[2] = msg_namelower(msg); + has_addr = true; + data[0] = msg_nametype(hdr); + data[1] = msg_namelower(hdr); + data[2] = data[1]; break; case TIPC_MCAST_MSG: - has_name = 1; - anc_data[0] = msg_nametype(msg); - anc_data[1] = msg_namelower(msg); - anc_data[2] = msg_nameupper(msg); + has_addr = true; + data[0] = msg_nametype(hdr); + data[1] = msg_namelower(hdr); + data[2] = msg_nameupper(hdr); break; case TIPC_CONN_MSG: - has_name = !!tsk->conn_addrtype; - anc_data[0] = msg_nametype(&tsk->phdr); - anc_data[1] = msg_nameinst(&tsk->phdr); - anc_data[2] = anc_data[1]; + has_addr = !!tsk->conn_addrtype; + data[0] = msg_nametype(&tsk->phdr); + data[1] = msg_nameinst(&tsk->phdr); + data[2] = data[1]; break; default: - has_name = 0; - } - if (has_name) { - res = put_cmsg(m, SOL_TIPC, TIPC_DESTNAME, 12, anc_data); - if (res) - return res; + has_addr = false; } - - return 0; + if (!has_addr) + return 0; + return put_cmsg(m, SOL_TIPC, TIPC_DESTNAME, 12, data); } static struct sk_buff *tipc_sk_build_ack(struct tipc_sock *tsk) -- 2.29.2 |
From: <jm...@re...> - 2021-04-07 20:59:06
|
From: Jon Maloy <jm...@re...> We make some minor code cleanups and improvements. --- v2: - Removed patch #1 from v1, which has now been applied upstream - Fixed memory leak in patch #2 as identified by Hoang Jon Maloy (3): tipc: eliminate redundant fields in struct tipc_sock tipc: refactor function tipc_sk_anc_data_recv() tipc: simplify handling of lookup scope during multicast message reception net/tipc/name_table.c | 6 +- net/tipc/name_table.h | 4 +- net/tipc/socket.c | 149 +++++++++++++++++++----------------------- 3 files changed, 74 insertions(+), 85 deletions(-) -- 2.29.2 |
From: David M. <da...@da...> - 2021-04-07 00:04:59
|
From: Zheng Yongjun <zhe...@hu...> Date: Tue, 6 Apr 2021 23:19:09 +0800 > These patches fix a series of spelling errors in net/tipc module. > > Reported-by: Hulk Robot <hu...@hu...> > Signed-off-by: Zheng Yongjun <zhe...@hu...> This does not apply to net-next, please respin. Thanks. |
From: Xin L. <luc...@gm...> - 2021-04-06 02:45:42
|
Li Shuang found a NULL pointer dereference crash in her testing: [] BUG: unable to handle kernel NULL pointer dereference at 0000000000000020 [] RIP: 0010:tipc_crypto_rcv_complete+0xc8/0x7e0 [tipc] [] Call Trace: [] <IRQ> [] tipc_crypto_rcv+0x2d9/0x8f0 [tipc] [] tipc_rcv+0x2fc/0x1120 [tipc] [] tipc_udp_recv+0xc6/0x1e0 [tipc] [] udpv6_queue_rcv_one_skb+0x16a/0x460 [] udp6_unicast_rcv_skb.isra.35+0x41/0xa0 [] ip6_protocol_deliver_rcu+0x23b/0x4c0 [] ip6_input+0x3d/0xb0 [] ipv6_rcv+0x395/0x510 [] __netif_receive_skb_core+0x5fc/0xc40 This is caused by NULL returned by tipc_aead_get(), and then crashed when dereferencing it later in tipc_crypto_rcv_complete(). This might happen when tipc_crypto_rcv_complete() is called by two threads at the same time: the tmp attached by tipc_crypto_key_attach() in one thread may be released by the one attached by that in the other thread. This patch is to fix it by incrementing the tmp's refcnt before attaching it instead of calling tipc_aead_get() after attaching it. Fixes: fc1b6d6de220 ("tipc: introduce TIPC encryption & authentication") Reported-by: Li Shuang <sh...@re...> Signed-off-by: Xin Long <luc...@gm...> --- net/tipc/crypto.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/tipc/crypto.c b/net/tipc/crypto.c index f4fca8f..97710ce 100644 --- a/net/tipc/crypto.c +++ b/net/tipc/crypto.c @@ -1941,12 +1941,13 @@ static void tipc_crypto_rcv_complete(struct net *net, struct tipc_aead *aead, goto rcv; if (tipc_aead_clone(&tmp, aead) < 0) goto rcv; + WARN_ON(!refcount_inc_not_zero(&tmp->refcnt)); if (tipc_crypto_key_attach(rx, tmp, ehdr->tx_key, false) < 0) { tipc_aead_free(&tmp->rcu); goto rcv; } tipc_aead_put(aead); - aead = tipc_aead_get(tmp); + aead = tmp; } if (unlikely(err)) { -- 2.1.0 |
From: Duzan, G. D <Gar...@fi...> - 2021-04-06 00:12:34
|
I'm testing some TIPC code between a Debian host and a Fedora host and getting some nasty looking kernel messages. Could someone take a quick look and see if these are known issues and whether there are known workarounds? Description: Debian GNU/Linux 10 (buster) Linux post 4.19.0-14-amd64 #1 SMP Debian 4.19.171-2 (2021-01-30) x86_64 GNU/Linux [Mon Apr 5 11:54:13 2021] list_del corruption, ffffa5fd89417d80->next is LIST_POISON1 (dead000000000100) [Mon Apr 5 11:54:13 2021] ------------[ cut here ]------------ [Mon Apr 5 11:54:13 2021] kernel BUG at lib/list_debug.c:47! [Mon Apr 5 11:54:13 2021] invalid opcode: 0000 [#1] SMP PTI [Mon Apr 5 11:54:13 2021] CPU: 42 PID: 254384 Comm: mupip Not tainted 4.19.0-14-amd64 #1 Debian 4.19.171-2 [Mon Apr 5 11:54:13 2021] Hardware name: Dell Inc. PowerEdge R730xd/072T6D, BIOS 2.1.7 06/16/2016 [Mon Apr 5 11:54:13 2021] RIP: 0010:__list_del_entry_valid.cold.1+0x12/0x47 [Mon Apr 5 11:54:13 2021] Code: ff ff 0f 0b 48 89 c1 4c 89 c6 48 c7 c7 90 ae 09 89 e8 90 24 ff ff 0f 0b 48 89 fe 48 89 c2 48 c7 c7 20 af 09 89 e8 7c 24 ff ff <0f> 0b 48 c7 c7 d0 af 09 89 e8 6e 24 ff ff 0f 0b 48 89 f2 48 89 fe [Mon Apr 5 11:54:13 2021] RSP: 0018:ffffa5fd89417d10 EFLAGS: 00010046 [Mon Apr 5 11:54:13 2021] RAX: 000000000000004e RBX: ffffa5fd89417d68 RCX: 0000000000000000 [Mon Apr 5 11:54:13 2021] RDX: 0000000000000000 RSI: ffff89b23f9566b8 RDI: ffff89b23f9566b8 [Mon Apr 5 11:54:13 2021] RBP: ffff89a5d3099800 R08: 00000000000006eb R09: 0000000000aaaaaa [Mon Apr 5 11:54:13 2021] R10: 0000000000000000 R11: 0000000000000001 R12: 0000000000000286 [Mon Apr 5 11:54:13 2021] R13: ffff89a8f9d370c0 R14: ffffa5fd89417e28 R15: 0000000000000008 [Mon Apr 5 11:54:13 2021] FS: 00007f9abfcaa3c0(0000) GS:ffff89b23f940000(0000) knlGS:0000000000000000 [Mon Apr 5 11:54:13 2021] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [Mon Apr 5 11:54:13 2021] list_del corruption, ffffa5fd8834bd80->next is LIST_POISON1 (dead000000000100) [Mon Apr 5 11:54:13 2021] CR2: 00007fbf0ebcd000 CR3: 00000006d95a0005 CR4: 00000000003606e0 [Mon Apr 5 11:54:13 2021] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [Mon Apr 5 11:54:13 2021] ------------[ cut here ]------------ [Mon Apr 5 11:54:13 2021] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [Mon Apr 5 11:54:13 2021] kernel BUG at lib/list_debug.c:47! [Mon Apr 5 11:54:13 2021] Call Trace: [Mon Apr 5 11:54:13 2021] remove_wait_queue+0x20/0x60 [Mon Apr 5 11:54:13 2021] __tipc_sendmsg+0x2bb/0x570 [tipc] [Mon Apr 5 11:54:13 2021] ? do_wait_intr_irq+0xb0/0xb0 [Mon Apr 5 11:54:13 2021] tipc_sendmsg+0x30/0x50 [tipc] [Mon Apr 5 11:54:13 2021] sock_sendmsg+0x36/0x40 [Mon Apr 5 11:54:13 2021] __sys_sendto+0xee/0x160 [Mon Apr 5 11:54:13 2021] list_del corruption, ffffa5fd88823d80->next is LIST_POISON1 (dead000000000100) [Mon Apr 5 11:54:13 2021] ? vfs_write+0x16d/0x1a0 [Mon Apr 5 11:54:13 2021] ------------[ cut here ]------------ [Mon Apr 5 11:54:13 2021] ? vfs_write+0xe9/0x1a0 [Mon Apr 5 11:54:13 2021] kernel BUG at lib/list_debug.c:47! [Mon Apr 5 11:54:13 2021] __x64_sys_sendto+0x24/0x30 [Mon Apr 5 11:54:13 2021] do_syscall_64+0x53/0x110 [Mon Apr 5 11:54:13 2021] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [Mon Apr 5 11:54:13 2021] RIP: 0033:0x7f9abffe49b7 [Mon Apr 5 11:54:13 2021] Code: 64 89 02 48 c7 c0 ff ff ff ff eb b6 0f 1f 80 00 00 00 00 48 8d 05 49 5d 0c 00 41 89 ca 8b 00 85 c0 75 10 b8 2c 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 71 c3 41 57 4d 89 c7 41 56 41 89 ce 41 55 49 [Mon Apr 5 11:54:13 2021] RSP: 002b:00007ffd979ddb18 EFLAGS: 00000246 ORIG_RAX: 000000000000002c [Mon Apr 5 11:54:13 2021] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f9abffe49b7 [Mon Apr 5 11:54:13 2021] RDX: 0000000000000008 RSI: 00007ffd979ddb28 RDI: 0000000000000003 [Mon Apr 5 11:54:13 2021] RBP: 00007ffd979ddb40 R08: 00007f9ac02c2120 R09: 0000000000000010 [Mon Apr 5 11:54:13 2021] R10: 0000000000000000 R11: 0000000000000246 R12: 000055d11e4c8250 [Mon Apr 5 11:54:13 2021] R13: 00007ffd979efa40 R14: 0000000000000000 R15: 0000000000000000 [Mon Apr 5 11:54:13 2021] Modules linked in: btrfs zstd_compress zstd_decompress xxhash fuse vfat fat loop rpcsec_gss_krb5 nfsv4 dns_resolver nfs lockd grace fscache binfmt_misc ext4 crc16 mbcache jbd2 f2fs fscrypto ecb intel_rapl sb_edac x86_pkg_temp_thermal intel_powerclamp coretemp kvm_intel kvm irqbypass crct10dif_pclmul ipmi_ssif crc32_pclmul mgag200 ttm ghash_clmulni_intel drm_kms_helper drm intel_cstate iTCO_wdt sg dcdbas i2c_algo_bit mei_me iTCO_vendor_support intel_uncore intel_rapl_perf evdev mxm_wmi mei pcspkr pcc_cpufreq ipmi_si ipmi_devintf wmi ipmi_msghandler button acpi_power_meter dm_mod auth_rpcgss tipc sunrpc ip6_udp_tunnel udp_tunnel ip_tables x_tables autofs4 xfs raid10 raid456 async_raid6_recov async_memcpy async_pq async_xor async_tx xor sd_mod raid6_pq libcrc32c crc32c_generic raid1 raid0 [Mon Apr 5 11:54:13 2021] multipath linear md_mod crc32c_intel ahci libahci aesni_intel nvme ehci_pci aes_x86_64 crypto_simd libata ehci_hcd megaraid_sas cryptd glue_helper nvme_core usbcore tg3 lpc_ich scsi_mod libphy mfd_core usb_common [Mon Apr 5 11:54:13 2021] ---[ end trace bb3c37742d449893 ]--- Description: Fedora release 33 (Thirty Three) Linux lltcgtmfed01.fisdev.local 5.10.23-200.fc33.x86_64 #1 SMP Thu Mar 11 22:18:30 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux [Mon Apr 5 14:29:30 2021] tipc: Gacks on 1866da4db38c:eno1-1866da4d75f5:eno1: 64, ql: 339! [Mon Apr 5 14:29:32 2021] tipc: Gacks on 1866da4db38c:eno1-1866da4d75f5:eno1: 64, ql: 339! I suspect I lost at least one datagram due to one of these, as I know that it was sent, and the recv()ing process (now stuck) was only expecting this one datagram reply, making buffer issues unlikely. Thanks. Gary Duzan FIS - GT.M Core Team The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you. |
From: David A. <ds...@gm...> - 2021-04-03 01:16:14
|
On 3/31/21 8:34 PM, Hoang Le wrote: > To avoid code duplication, tipc should be converted to use the helper > functions for working with libmnl in lib/mnl_utils.c > > Acked-by: Jon Maloy <jm...@re...> > Signed-off-by: Hoang Le <hoa...@de...> > --- > tipc/bearer.c | 38 ++++++-------- > tipc/cmdl.c | 2 - > tipc/link.c | 37 +++++-------- > tipc/media.c | 15 +++--- > tipc/msg.c | 132 +++-------------------------------------------- > tipc/msg.h | 2 +- > tipc/nametable.c | 5 +- > tipc/node.c | 33 +++++------- > tipc/peer.c | 8 ++- > tipc/socket.c | 10 ++-- > tipc/tipc.c | 21 +++++++- > 11 files changed, 83 insertions(+), 220 deletions(-) > applied to iproute2-next. |
From: Hoang H. Le <hoa...@de...> - 2021-04-01 04:12:12
|
> -----Original Message----- > From: jm...@re... <jm...@re...> > Sent: Thursday, March 25, 2021 10:56 PM > To: tip...@li... > Cc: Tung Quang Nguyen <tun...@de...>; Hoang Huu Le <hoa...@de...>; Tuong Tong Lien > <tuo...@de...>; jm...@re...; ma...@do...; lx...@re...; yin...@wi...; > par...@gm... > Subject: [net-next 3/4] tipc: refactor function tipc_sk_anc_data_recv() > > From: Jon Maloy <jm...@re...> > > We refactor tipc_sk_anc_data_recv() to make it slighltly more > comprehensible, but also to facilitate application of some additions > to the code in a future commit. > > Signed-off-by: Jon Maloy <jm...@re...> > --- > net/tipc/socket.c | 85 +++++++++++++++++++++-------------------------- > 1 file changed, 38 insertions(+), 47 deletions(-) > > diff --git a/net/tipc/socket.c b/net/tipc/socket.c > index 12a97755bc80..358d1f2494a7 100644 > --- a/net/tipc/socket.c > +++ b/net/tipc/socket.c > @@ -1730,67 +1730,58 @@ static void tipc_sk_set_orig_addr(struct msghdr *m, struct sk_buff *skb) > static int tipc_sk_anc_data_recv(struct msghdr *m, struct sk_buff *skb, > struct tipc_sock *tsk) > { > - struct tipc_msg *msg; > - u32 anc_data[3]; > - u32 err; > - u32 dest_type; > - int has_name; > - int res; > + struct tipc_msg *hdr; > + bool has_addr; > + int data[12]; Potential memory leak here! > + int dlen, rc; > > if (likely(m->msg_controllen == 0)) > return 0; > - msg = buf_msg(skb); > > - /* Optionally capture errored message object(s) */ > - err = msg ? msg_errcode(msg) : 0; > - if (unlikely(err)) { > - anc_data[0] = err; > - anc_data[1] = msg_data_sz(msg); > - res = put_cmsg(m, SOL_TIPC, TIPC_ERRINFO, 8, anc_data); > - if (res) > - return res; > - if (anc_data[1]) { > - if (skb_linearize(skb)) > - return -ENOMEM; > - msg = buf_msg(skb); > - res = put_cmsg(m, SOL_TIPC, TIPC_RETDATA, anc_data[1], > - msg_data(msg)); > - if (res) > - return res; > - } > + hdr = buf_msg(skb); > + dlen = msg_data_sz(hdr); > + > + /* Capture errored message object, if any */ > + if (msg_errcode(hdr)) { > + if (skb_linearize(skb)) > + return -ENOMEM; > + hdr = buf_msg(skb); > + data[0] = msg_errcode(hdr); > + data[1] = dlen; > + rc = put_cmsg(m, SOL_TIPC, TIPC_ERRINFO, 8, data); > + if (rc || !dlen) > + return rc; > + rc = put_cmsg(m, SOL_TIPC, TIPC_RETDATA, dlen, msg_data(hdr)); > + if (rc) > + return rc; > } > > - /* Optionally capture message destination object */ > - dest_type = msg ? msg_type(msg) : TIPC_DIRECT_MSG; > - switch (dest_type) { > + /* Capture TIPC_SERVICE_ADDR/RANGE destination address, if any */ > + switch (msg_type(hdr)) { > case TIPC_NAMED_MSG: > - has_name = 1; > - anc_data[0] = msg_nametype(msg); > - anc_data[1] = msg_namelower(msg); > - anc_data[2] = msg_namelower(msg); > + has_addr = true; > + data[0] = msg_nametype(hdr); > + data[1] = msg_namelower(hdr); > + data[2] = data[1]; > break; > case TIPC_MCAST_MSG: > - has_name = 1; > - anc_data[0] = msg_nametype(msg); > - anc_data[1] = msg_namelower(msg); > - anc_data[2] = msg_nameupper(msg); > + has_addr = true; > + data[0] = msg_nametype(hdr); > + data[1] = msg_namelower(hdr); > + data[2] = msg_nameupper(hdr); > break; > case TIPC_CONN_MSG: > - has_name = !!tsk->conn_addrtype; > - anc_data[0] = msg_nametype(&tsk->phdr); > - anc_data[1] = msg_nameinst(&tsk->phdr); > - anc_data[2] = anc_data[1]; > + has_addr = !!tsk->conn_addrtype; > + data[0] = msg_nametype(&tsk->phdr); > + data[1] = msg_nameinst(&tsk->phdr); > + data[2] = data[1]; > break; > default: > - has_name = 0; > - } > - if (has_name) { > - res = put_cmsg(m, SOL_TIPC, TIPC_DESTNAME, 12, anc_data); > - if (res) > - return res; > + has_addr = false; > } > - > - return 0; > + if (!has_addr) > + return 0; > + return put_cmsg(m, SOL_TIPC, TIPC_DESTNAME, 12, data); > } > > static struct sk_buff *tipc_sk_build_ack(struct tipc_sock *tsk) > -- > 2.29.2 |
From: Hoang Le <hoa...@de...> - 2021-04-01 04:07:57
|
To avoid code duplication, tipc should be converted to use the helper functions for working with libmnl in lib/mnl_utils.c Acked-by: Jon Maloy <jm...@re...> Signed-off-by: Hoang Le <hoa...@de...> --- tipc/bearer.c | 38 ++++++-------- tipc/cmdl.c | 2 - tipc/link.c | 37 +++++-------- tipc/media.c | 15 +++--- tipc/msg.c | 132 +++-------------------------------------------- tipc/msg.h | 2 +- tipc/nametable.c | 5 +- tipc/node.c | 33 +++++------- tipc/peer.c | 8 ++- tipc/socket.c | 10 ++-- tipc/tipc.c | 21 +++++++- 11 files changed, 83 insertions(+), 220 deletions(-) diff --git a/tipc/bearer.c b/tipc/bearer.c index 4470819e4a96..2afc48b9b108 100644 --- a/tipc/bearer.c +++ b/tipc/bearer.c @@ -21,9 +21,6 @@ #include <linux/genetlink.h> #include <linux/if.h> -#include <libmnl/libmnl.h> -#include <sys/socket.h> - #include "utils.h" #include "cmdl.h" #include "msg.h" @@ -101,11 +98,11 @@ static int get_netid_cb(const struct nlmsghdr *nlh, void *data) static int generate_multicast(short af, char *buf, int bufsize) { - int netid; - char mnl_msg[MNL_SOCKET_BUFFER_SIZE]; struct nlmsghdr *nlh; + int netid; - if (!(nlh = msg_init(mnl_msg, TIPC_NL_NET_GET))) { + nlh = msg_init(TIPC_NL_NET_GET); + if (!nlh) { fprintf(stderr, "error, message initialization failed\n"); return -1; } @@ -399,7 +396,6 @@ static int cmd_bearer_add_media(struct nlmsghdr *nlh, const struct cmd *cmd, { int err; char *media; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct opt *opt; struct nlattr *attrs; struct opt opts[] = { @@ -435,7 +431,8 @@ static int cmd_bearer_add_media(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - if (!(nlh = msg_init(buf, TIPC_NL_BEARER_ADD))) { + nlh = msg_init(TIPC_NL_BEARER_ADD); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } @@ -482,7 +479,6 @@ static int cmd_bearer_enable(struct nlmsghdr *nlh, const struct cmd *cmd, int err; struct opt *opt; struct nlattr *nest; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct opt opts[] = { { "device", OPT_KEYVAL, NULL }, { "domain", OPT_KEYVAL, NULL }, @@ -508,7 +504,8 @@ static int cmd_bearer_enable(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - if (!(nlh = msg_init(buf, TIPC_NL_BEARER_ENABLE))) { + nlh = msg_init(TIPC_NL_BEARER_ENABLE); + if (!nlh) { fprintf(stderr, "error: message initialisation failed\n"); return -1; } @@ -563,7 +560,6 @@ static int cmd_bearer_disable(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { int err; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *nest; struct opt opts[] = { { "device", OPT_KEYVAL, NULL }, @@ -584,7 +580,8 @@ static int cmd_bearer_disable(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - if (!(nlh = msg_init(buf, TIPC_NL_BEARER_DISABLE))) { + nlh = msg_init(TIPC_NL_BEARER_DISABLE); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } @@ -628,7 +625,6 @@ static int cmd_bearer_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, int err; int val; int prop; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *props; struct nlattr *attrs; struct opt opts[] = { @@ -675,7 +671,8 @@ static int cmd_bearer_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, } } - if (!(nlh = msg_init(buf, TIPC_NL_BEARER_SET))) { + nlh = msg_init(TIPC_NL_BEARER_SET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } @@ -876,7 +873,6 @@ static int cmd_bearer_get_media(struct nlmsghdr *nlh, const struct cmd *cmd, { int err; char *media; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct opt *opt; struct cb_data cb_data = {0}; struct nlattr *attrs; @@ -918,7 +914,8 @@ static int cmd_bearer_get_media(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - if (!(nlh = msg_init(buf, TIPC_NL_BEARER_GET))) { + nlh = msg_init(TIPC_NL_BEARER_GET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } @@ -956,7 +953,6 @@ static int cmd_bearer_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, { int err; int prop; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *attrs; struct opt opts[] = { { "device", OPT_KEYVAL, NULL }, @@ -1001,7 +997,8 @@ static int cmd_bearer_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, } } - if (!(nlh = msg_init(buf, TIPC_NL_BEARER_GET))) { + nlh = msg_init(TIPC_NL_BEARER_GET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } @@ -1056,14 +1053,13 @@ static int bearer_list_cb(const struct nlmsghdr *nlh, void *data) static int cmd_bearer_list(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; - if (help_flag) { fprintf(stderr, "Usage: %s bearer list\n", cmdl->argv[0]); return -EINVAL; } - if (!(nlh = msg_init(buf, TIPC_NL_BEARER_GET))) { + nlh = msg_init(TIPC_NL_BEARER_GET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } diff --git a/tipc/cmdl.c b/tipc/cmdl.c index 981e268ebf94..feaac2da175f 100644 --- a/tipc/cmdl.c +++ b/tipc/cmdl.c @@ -13,8 +13,6 @@ #include <string.h> #include <errno.h> -#include <libmnl/libmnl.h> - #include "cmdl.h" static const struct cmd *find_cmd(const struct cmd *cmds, char *str) diff --git a/tipc/link.c b/tipc/link.c index 192736eaa154..2123f109c694 100644 --- a/tipc/link.c +++ b/tipc/link.c @@ -17,7 +17,6 @@ #include <linux/tipc_netlink.h> #include <linux/tipc.h> #include <linux/genetlink.h> -#include <libmnl/libmnl.h> #include "cmdl.h" #include "msg.h" @@ -60,7 +59,6 @@ static int link_list_cb(const struct nlmsghdr *nlh, void *data) static int cmd_link_list(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; int err = 0; if (help_flag) { @@ -68,7 +66,7 @@ static int cmd_link_list(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - nlh = msg_init(buf, TIPC_NL_LINK_GET); + nlh = msg_init(TIPC_NL_LINK_GET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -126,7 +124,6 @@ static int cmd_link_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { int prop; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *attrs; struct opt *opt; struct opt opts[] = { @@ -151,7 +148,7 @@ static int cmd_link_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, if (parse_opts(opts, cmdl) < 0) return -EINVAL; - nlh = msg_init(buf, TIPC_NL_LINK_GET); + nlh = msg_init(TIPC_NL_LINK_GET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -241,7 +238,6 @@ static int cmd_link_get_bcast(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { int prop = TIPC_NLA_PROP_BROADCAST; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *attrs; if (help_flag) { @@ -249,7 +245,7 @@ static int cmd_link_get_bcast(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - nlh = msg_init(buf, TIPC_NL_LINK_GET); + nlh = msg_init(TIPC_NL_LINK_GET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -284,7 +280,6 @@ static int cmd_link_stat_reset(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { char *link; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct opt *opt; struct nlattr *nest; struct opt opts[] = { @@ -302,7 +297,7 @@ static int cmd_link_stat_reset(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - nlh = msg_init(buf, TIPC_NL_LINK_RESET_STATS); + nlh = msg_init(TIPC_NL_LINK_RESET_STATS); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -550,7 +545,6 @@ static int cmd_link_stat_show(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { char *link = NULL; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct opt *opt; struct opt opts[] = { { "link", OPT_KEYVAL, NULL }, @@ -564,7 +558,7 @@ static int cmd_link_stat_show(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - nlh = msg_init(buf, TIPC_NL_LINK_GET); + nlh = msg_init(TIPC_NL_LINK_GET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -626,7 +620,6 @@ static int cmd_link_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, { int val; int prop; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *props; struct nlattr *attrs; struct opt *opt; @@ -658,7 +651,7 @@ static int cmd_link_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, if (parse_opts(opts, cmdl) < 0) return -EINVAL; - nlh = msg_init(buf, TIPC_NL_LINK_SET); + nlh = msg_init(TIPC_NL_LINK_SET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -704,7 +697,6 @@ static void cmd_link_set_bcast_help(struct cmdl *cmdl) static int cmd_link_set_bcast(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *props; struct nlattr *attrs; struct opt *opt; @@ -734,7 +726,7 @@ static int cmd_link_set_bcast(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - nlh = msg_init(buf, TIPC_NL_LINK_SET); + nlh = msg_init(TIPC_NL_LINK_SET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -788,7 +780,6 @@ static int cmd_link_mon_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { int size; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *attrs; if (cmdl->argc != cmdl->optind + 1) { @@ -797,7 +788,7 @@ static int cmd_link_mon_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, } size = atoi(shift_cmdl(cmdl)); - nlh = msg_init(buf, TIPC_NL_MON_SET); + nlh = msg_init(TIPC_NL_MON_SET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -841,7 +832,6 @@ static int link_mon_summary_cb(const struct nlmsghdr *nlh, void *data) static int cmd_link_mon_summary(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; int err = 0; if (help_flag) { @@ -849,7 +839,7 @@ static int cmd_link_mon_summary(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - nlh = msg_init(buf, TIPC_NL_MON_GET); + nlh = msg_init(TIPC_NL_MON_GET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -1004,11 +994,10 @@ exit: static int link_mon_peer_list(uint32_t mon_ref) { struct nlmsghdr *nlh; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *nest; int err = 0; - nlh = msg_init(buf, TIPC_NL_MON_PEER_GET); + nlh = msg_init(TIPC_NL_MON_PEER_GET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -1080,7 +1069,6 @@ static void cmd_link_mon_list_udp_help(struct cmdl *cmdl, char *media) static int cmd_link_mon_list(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; char bname[TIPC_MAX_BEARER_NAME] = {0}; struct opt opts[] = { { "media", OPT_KEYVAL, NULL }, @@ -1112,7 +1100,7 @@ static int cmd_link_mon_list(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - nlh = msg_init(buf, TIPC_NL_MON_GET); + nlh = msg_init(TIPC_NL_MON_GET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -1176,9 +1164,8 @@ static int link_mon_get_cb(const struct nlmsghdr *nlh, void *data) static int cmd_link_mon_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; - nlh = msg_init(buf, TIPC_NL_MON_GET); + nlh = msg_init(TIPC_NL_MON_GET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; diff --git a/tipc/media.c b/tipc/media.c index 969ef6578b3b..a3fec681cbf4 100644 --- a/tipc/media.c +++ b/tipc/media.c @@ -15,9 +15,7 @@ #include <errno.h> #include <linux/tipc_netlink.h> -#include <linux/tipc.h> #include <linux/genetlink.h> -#include <libmnl/libmnl.h> #include "cmdl.h" #include "msg.h" @@ -45,14 +43,13 @@ static int media_list_cb(const struct nlmsghdr *nlh, void *data) static int cmd_media_list(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; - if (help_flag) { fprintf(stderr, "Usage: %s media list\n", cmdl->argv[0]); return -EINVAL; } - if (!(nlh = msg_init(buf, TIPC_NL_MEDIA_GET))) { + nlh = msg_init(TIPC_NL_MEDIA_GET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } @@ -89,7 +86,6 @@ static int cmd_media_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { int prop; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *nest; struct opt *opt; struct opt opts[] = { @@ -116,7 +112,8 @@ static int cmd_media_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, if (parse_opts(opts, cmdl) < 0) return -EINVAL; - if (!(nlh = msg_init(buf, TIPC_NL_MEDIA_GET))) { + nlh = msg_init(TIPC_NL_MEDIA_GET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } @@ -179,7 +176,6 @@ static int cmd_media_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, { int val; int prop; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *props; struct nlattr *attrs; struct opt *opt; @@ -213,7 +209,8 @@ static int cmd_media_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, if (parse_opts(opts, cmdl) < 0) return -EINVAL; - if (!(nlh = msg_init(buf, TIPC_NL_MEDIA_SET))) { + nlh = msg_init(TIPC_NL_MEDIA_SET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } diff --git a/tipc/msg.c b/tipc/msg.c index dc09d05048f3..1225691c9a81 100644 --- a/tipc/msg.c +++ b/tipc/msg.c @@ -13,13 +13,13 @@ #include <time.h> #include <errno.h> -#include <linux/tipc_netlink.h> -#include <linux/tipc.h> -#include <linux/genetlink.h> #include <libmnl/libmnl.h> +#include "mnl_utils.h" #include "msg.h" +extern struct mnlu_gen_socket tipc_nlg; + int parse_attrs(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; @@ -30,141 +30,23 @@ int parse_attrs(const struct nlattr *attr, void *data) return MNL_CB_OK; } -static int family_id_cb(const struct nlmsghdr *nlh, void *data) -{ - struct nlattr *tb[CTRL_ATTR_MAX + 1] = {}; - struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh); - int *id = data; - - mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, tb); - if (!tb[CTRL_ATTR_FAMILY_ID]) - return MNL_CB_ERROR; - - *id = mnl_attr_get_u16(tb[CTRL_ATTR_FAMILY_ID]); - - return MNL_CB_OK; -} - -static struct mnl_socket *msg_send(struct nlmsghdr *nlh) -{ - int ret; - struct mnl_socket *nl; - - nl = mnl_socket_open(NETLINK_GENERIC); - if (nl == NULL) { - perror("mnl_socket_open"); - return NULL; - } - - ret = mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID); - if (ret < 0) { - perror("mnl_socket_bind"); - return NULL; - } - - ret = mnl_socket_sendto(nl, nlh, nlh->nlmsg_len); - if (ret < 0) { - perror("mnl_socket_send"); - return NULL; - } - - return nl; -} - -static int msg_recv(struct mnl_socket *nl, mnl_cb_t callback, void *data, int seq) -{ - int ret; - unsigned int portid; - char buf[MNL_SOCKET_BUFFER_SIZE]; - - portid = mnl_socket_get_portid(nl); - - ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); - while (ret > 0) { - ret = mnl_cb_run(buf, ret, seq, portid, callback, data); - if (ret <= 0) - break; - ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); - } - if (ret == -1) - perror("error"); - - mnl_socket_close(nl); - - return ret; -} - -static int msg_query(struct nlmsghdr *nlh, mnl_cb_t callback, void *data) -{ - unsigned int seq; - struct mnl_socket *nl; - - seq = time(NULL); - nlh->nlmsg_seq = seq; - - nl = msg_send(nlh); - if (!nl) - return -ENOTSUP; - - return msg_recv(nl, callback, data, seq); -} - -static int get_family(void) -{ - int err; - int nl_family; - struct nlmsghdr *nlh; - struct genlmsghdr *genl; - char buf[MNL_SOCKET_BUFFER_SIZE]; - - nlh = mnl_nlmsg_put_header(buf); - nlh->nlmsg_type = GENL_ID_CTRL; - nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; - - genl = mnl_nlmsg_put_extra_header(nlh, sizeof(struct genlmsghdr)); - genl->cmd = CTRL_CMD_GETFAMILY; - genl->version = 1; - - mnl_attr_put_u16(nlh, CTRL_ATTR_FAMILY_ID, GENL_ID_CTRL); - mnl_attr_put_strz(nlh, CTRL_ATTR_FAMILY_NAME, TIPC_GENL_V2_NAME); - - if ((err = msg_query(nlh, family_id_cb, &nl_family))) - return err; - - return nl_family; -} - int msg_doit(struct nlmsghdr *nlh, mnl_cb_t callback, void *data) { nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; - return msg_query(nlh, callback, data); + return mnlu_gen_socket_sndrcv(&tipc_nlg, nlh, callback, data); } int msg_dumpit(struct nlmsghdr *nlh, mnl_cb_t callback, void *data) { nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP; - return msg_query(nlh, callback, data); + return mnlu_gen_socket_sndrcv(&tipc_nlg, nlh, callback, data); } -struct nlmsghdr *msg_init(char *buf, int cmd) +struct nlmsghdr *msg_init(int cmd) { - int family; struct nlmsghdr *nlh; - struct genlmsghdr *genl; - - family = get_family(); - if (family <= 0) { - fprintf(stderr, - "Unable to get TIPC nl family id (module loaded?)\n"); - return NULL; - } - - nlh = mnl_nlmsg_put_header(buf); - nlh->nlmsg_type = family; - genl = mnl_nlmsg_put_extra_header(nlh, sizeof(struct genlmsghdr)); - genl->cmd = cmd; - genl->version = 1; + nlh = mnlu_gen_socket_cmd_prepare(&tipc_nlg, cmd, 0); return nlh; } diff --git a/tipc/msg.h b/tipc/msg.h index 41fd1ad1403a..56af5a705fb9 100644 --- a/tipc/msg.h +++ b/tipc/msg.h @@ -12,7 +12,7 @@ #ifndef _TIPC_MSG_H #define _TIPC_MSG_H -struct nlmsghdr *msg_init(char *buf, int cmd); +struct nlmsghdr *msg_init(int cmd); int msg_doit(struct nlmsghdr *nlh, mnl_cb_t callback, void *data); int msg_dumpit(struct nlmsghdr *nlh, mnl_cb_t callback, void *data); int parse_attrs(const struct nlattr *attr, void *data); diff --git a/tipc/nametable.c b/tipc/nametable.c index d899eeb67c07..b09ed5fc7280 100644 --- a/tipc/nametable.c +++ b/tipc/nametable.c @@ -15,7 +15,6 @@ #include <linux/tipc_netlink.h> #include <linux/tipc.h> #include <linux/genetlink.h> -#include <libmnl/libmnl.h> #include "cmdl.h" #include "msg.h" @@ -82,7 +81,6 @@ static int cmd_nametable_show(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { int iteration = 0; - char buf[MNL_SOCKET_BUFFER_SIZE]; int rc = 0; if (help_flag) { @@ -90,7 +88,8 @@ static int cmd_nametable_show(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - if (!(nlh = msg_init(buf, TIPC_NL_NAME_TABLE_GET))) { + nlh = msg_init(TIPC_NL_NAME_TABLE_GET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } diff --git a/tipc/node.c b/tipc/node.c index 05246013487f..ae75bfff7d2f 100644 --- a/tipc/node.c +++ b/tipc/node.c @@ -17,7 +17,6 @@ #include <linux/tipc_netlink.h> #include <linux/tipc.h> #include <linux/genetlink.h> -#include <libmnl/libmnl.h> #include "cmdl.h" #include "msg.h" @@ -52,14 +51,13 @@ static int node_list_cb(const struct nlmsghdr *nlh, void *data) static int cmd_node_list(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; - if (help_flag) { fprintf(stderr, "Usage: %s node list\n", cmdl->argv[0]); return -EINVAL; } - if (!(nlh = msg_init(buf, TIPC_NL_NODE_GET))) { + nlh = msg_init(TIPC_NL_NODE_GET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } @@ -73,7 +71,6 @@ static int cmd_node_set_addr(struct nlmsghdr *nlh, const struct cmd *cmd, char *str; uint32_t addr; struct nlattr *nest; - char buf[MNL_SOCKET_BUFFER_SIZE]; if (cmdl->argc != cmdl->optind + 1) { fprintf(stderr, "Usage: %s node set address ADDRESS\n", @@ -86,7 +83,8 @@ static int cmd_node_set_addr(struct nlmsghdr *nlh, const struct cmd *cmd, if (!addr) return -1; - if (!(nlh = msg_init(buf, TIPC_NL_NET_SET))) { + nlh = msg_init(TIPC_NL_NET_SET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } @@ -126,7 +124,6 @@ static int cmd_node_get_addr(struct nlmsghdr *nlh, const struct cmd *cmd, static int cmd_node_set_nodeid(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; uint8_t id[16] = {0,}; uint64_t *w0 = (uint64_t *) &id[0]; uint64_t *w1 = (uint64_t *) &id[8]; @@ -145,7 +142,7 @@ static int cmd_node_set_nodeid(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - nlh = msg_init(buf, TIPC_NL_NET_SET); + nlh = msg_init(TIPC_NL_NET_SET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -201,7 +198,6 @@ static int cmd_node_set_key(struct nlmsghdr *nlh, const struct cmd *cmd, }; struct nlattr *nest; struct opt *opt_algname, *opt_nodeid, *opt_master, *opt_rekeying; - char buf[MNL_SOCKET_BUFFER_SIZE]; uint8_t id[TIPC_NODEID_LEN] = {0,}; uint32_t rekeying = 0; bool has_key = false; @@ -262,7 +258,7 @@ get_ops: } /* Init & do the command */ - nlh = msg_init(buf, TIPC_NL_KEY_SET); + nlh = msg_init(TIPC_NL_KEY_SET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -287,15 +283,13 @@ get_ops: static int cmd_node_flush_key(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; - if (help_flag) { (cmd->help)(cmdl); return -EINVAL; } /* Init & do the command */ - nlh = msg_init(buf, TIPC_NL_KEY_FLUSH); + nlh = msg_init(TIPC_NL_KEY_FLUSH); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -332,14 +326,12 @@ static int nodeid_get_cb(const struct nlmsghdr *nlh, void *data) static int cmd_node_get_nodeid(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; - if (help_flag) { (cmd->help)(cmdl); return -EINVAL; } - nlh = msg_init(buf, TIPC_NL_NET_GET); + nlh = msg_init(TIPC_NL_NET_GET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -370,14 +362,13 @@ static int netid_get_cb(const struct nlmsghdr *nlh, void *data) static int cmd_node_get_netid(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; - if (help_flag) { (cmd->help)(cmdl); return -EINVAL; } - if (!(nlh = msg_init(buf, TIPC_NL_NET_GET))) { + nlh = msg_init(TIPC_NL_NET_GET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } @@ -389,7 +380,6 @@ static int cmd_node_set_netid(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { int netid; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *nest; if (help_flag) { @@ -397,7 +387,8 @@ static int cmd_node_set_netid(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - if (!(nlh = msg_init(buf, TIPC_NL_NET_SET))) { + nlh = msg_init(TIPC_NL_NET_SET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } diff --git a/tipc/peer.c b/tipc/peer.c index f14ec35e6f71..ed18efc552fa 100644 --- a/tipc/peer.c +++ b/tipc/peer.c @@ -17,7 +17,6 @@ #include <linux/tipc_netlink.h> #include <linux/tipc.h> #include <linux/genetlink.h> -#include <libmnl/libmnl.h> #include "cmdl.h" #include "msg.h" @@ -30,7 +29,6 @@ static int cmd_peer_rm_addr(struct nlmsghdr *nlh, const struct cmd *cmd, char *str; uint32_t addr; struct nlattr *nest; - char buf[MNL_SOCKET_BUFFER_SIZE]; if ((cmdl->argc != cmdl->optind + 1) || help_flag) { fprintf(stderr, "Usage: %s peer remove address ADDRESS\n", @@ -47,7 +45,8 @@ static int cmd_peer_rm_addr(struct nlmsghdr *nlh, const struct cmd *cmd, if (!addr) return -1; - if (!(nlh = msg_init(buf, TIPC_NL_PEER_REMOVE))) { + nlh = msg_init(TIPC_NL_PEER_REMOVE); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } @@ -62,7 +61,6 @@ static int cmd_peer_rm_addr(struct nlmsghdr *nlh, const struct cmd *cmd, static int cmd_peer_rm_nodeid(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; __u8 id[16] = {0,}; __u64 *w0 = (__u64 *)&id[0]; __u64 *w1 = (__u64 *)&id[8]; @@ -81,7 +79,7 @@ static int cmd_peer_rm_nodeid(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - nlh = msg_init(buf, TIPC_NL_PEER_REMOVE); + nlh = msg_init(TIPC_NL_PEER_REMOVE); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; diff --git a/tipc/socket.c b/tipc/socket.c index 852984ecd1e7..deae12af4409 100644 --- a/tipc/socket.c +++ b/tipc/socket.c @@ -15,7 +15,6 @@ #include <linux/tipc.h> #include <linux/tipc_netlink.h> #include <linux/genetlink.h> -#include <libmnl/libmnl.h> #include "cmdl.h" #include "msg.h" @@ -46,10 +45,10 @@ static int publ_list_cb(const struct nlmsghdr *nlh, void *data) static int publ_list(uint32_t sock) { struct nlmsghdr *nlh; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *nest; - if (!(nlh = msg_init(buf, TIPC_NL_PUBL_GET))) { + nlh = msg_init(TIPC_NL_PUBL_GET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } @@ -103,14 +102,13 @@ static int sock_list_cb(const struct nlmsghdr *nlh, void *data) static int cmd_socket_list(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; - if (help_flag) { fprintf(stderr, "Usage: %s socket list\n", cmdl->argv[0]); return -EINVAL; } - if (!(nlh = msg_init(buf, TIPC_NL_SOCK_GET))) { + nlh = msg_init(TIPC_NL_SOCK_GET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } diff --git a/tipc/tipc.c b/tipc/tipc.c index 60176a044f8d..9f23a4bfd25d 100644 --- a/tipc/tipc.c +++ b/tipc/tipc.c @@ -13,7 +13,11 @@ #include <stdlib.h> #include <getopt.h> #include <unistd.h> +#include <linux/tipc_netlink.h> +#include <libmnl/libmnl.h> +#include <errno.h> +#include "mnl_utils.h" #include "bearer.h" #include "link.h" #include "nametable.h" @@ -26,6 +30,7 @@ int help_flag; int json; +struct mnlu_gen_socket tipc_nlg; static void about(struct cmdl *cmdl) { @@ -110,8 +115,20 @@ int main(int argc, char *argv[]) cmdl.argc = argc; cmdl.argv = argv; - if ((res = run_cmd(NULL, &cmd, cmds, &cmdl, NULL)) != 0) - return 1; + res = mnlu_gen_socket_open(&tipc_nlg, TIPC_GENL_V2_NAME, + TIPC_GENL_V2_VERSION); + if (res) { + fprintf(stderr, + "Unable to get TIPC nl family id (module loaded?)\n"); + return -1; + } + res = run_cmd(NULL, &cmd, cmds, &cmdl, &tipc_nlg); + if (res != 0) { + mnlu_gen_socket_close(&tipc_nlg); + return -1; + } + + mnlu_gen_socket_close(&tipc_nlg); return 0; } -- 2.25.1 |
From: Hoang Le <hoa...@de...> - 2021-04-01 03:03:42
|
When enabling a bearer by name, we don't sanity check its name with higher slot in bearer list. This may have the effect that the name of an already enabled bearer bypasses the check. To fix the above issue, we just perform an extra checking with all existing bearers. Fixes: cb30a63384bc9 ("tipc: refactor function tipc_enable_bearer()") Cc: st...@vg... Acked-by: Jon Maloy <jm...@re...> Signed-off-by: Hoang Le <hoa...@de...> --- net/tipc/bearer.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index d47e0b940ac9..443f8e5b9477 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c @@ -256,6 +256,7 @@ static int tipc_enable_bearer(struct net *net, const char *name, int bearer_id = 0; int res = -EINVAL; char *errstr = ""; + u32 i; if (!bearer_name_validate(name, &b_names)) { errstr = "illegal name"; @@ -280,31 +281,38 @@ static int tipc_enable_bearer(struct net *net, const char *name, prio = m->priority; /* Check new bearer vs existing ones and find free bearer id if any */ - while (bearer_id < MAX_BEARERS) { - b = rtnl_dereference(tn->bearer_list[bearer_id]); - if (!b) - break; + bearer_id = MAX_BEARERS; + i = MAX_BEARERS; + while (i-- != 0) { + b = rtnl_dereference(tn->bearer_list[i]); + if (!b) { + bearer_id = i; + continue; + } if (!strcmp(name, b->name)) { errstr = "already enabled"; NL_SET_ERR_MSG(extack, "Already enabled"); goto rejected; } - bearer_id++; - if (b->priority != prio) - continue; - if (++with_this_prio <= 2) - continue; - pr_warn("Bearer <%s>: already 2 bearers with priority %u\n", - name, prio); - if (prio == TIPC_MIN_LINK_PRI) { - errstr = "cannot adjust to lower"; - NL_SET_ERR_MSG(extack, "Cannot adjust to lower"); - goto rejected; + + if (b->priority == prio && + (++with_this_prio > 2)) { + pr_warn("Bearer <%s>: already 2 bearers with priority %u\n", + name, prio); + + if (prio == TIPC_MIN_LINK_PRI) { + errstr = "cannot adjust to lower"; + NL_SET_ERR_MSG(extack, "Cannot adjust to lower"); + goto rejected; + } + + pr_warn("Bearer <%s>: trying with adjusted priority\n", + name); + prio--; + bearer_id = MAX_BEARERS; + i = MAX_BEARERS; + with_this_prio = 1; } - pr_warn("Bearer <%s>: trying with adjusted priority\n", name); - prio--; - bearer_id = 0; - with_this_prio = 1; } if (bearer_id >= MAX_BEARERS) { -- 2.25.1 |
From: Jon M. <jm...@re...> - 2021-03-31 14:56:19
|
On 3/29/21 6:59 AM, Hoang Le wrote: > To avoid duplication, avoid code duplication > tipc should be converted to use the helper > functions for working with libmnl in lib/mnl_utils.c > > Signed-off-by: Hoang Le <hoa...@de...> > --- > tipc/bearer.c | 38 ++++++-------- > tipc/cmdl.c | 2 - > tipc/link.c | 37 +++++-------- > tipc/media.c | 15 +++--- > tipc/msg.c | 132 +++-------------------------------------------- > tipc/msg.h | 2 +- > tipc/nametable.c | 5 +- > tipc/node.c | 33 +++++------- > tipc/peer.c | 8 ++- > tipc/socket.c | 10 ++-- > tipc/tipc.c | 21 +++++++- > 11 files changed, 83 insertions(+), 220 deletions(-) > > diff --git a/tipc/bearer.c b/tipc/bearer.c > index 4470819e4a96..2afc48b9b108 100644 > --- a/tipc/bearer.c > +++ b/tipc/bearer.c > @@ -21,9 +21,6 @@ > #include <linux/genetlink.h> > #include <linux/if.h> > > -#include <libmnl/libmnl.h> > -#include <sys/socket.h> > - > #include "utils.h" > #include "cmdl.h" > #include "msg.h" > @@ -101,11 +98,11 @@ static int get_netid_cb(const struct nlmsghdr *nlh, void *data) > > static int generate_multicast(short af, char *buf, int bufsize) > { > - int netid; > - char mnl_msg[MNL_SOCKET_BUFFER_SIZE]; > struct nlmsghdr *nlh; > + int netid; > > - if (!(nlh = msg_init(mnl_msg, TIPC_NL_NET_GET))) { > + nlh = msg_init(TIPC_NL_NET_GET); > + if (!nlh) { > fprintf(stderr, "error, message initialization failed\n"); > return -1; > } > @@ -399,7 +396,6 @@ static int cmd_bearer_add_media(struct nlmsghdr *nlh, const struct cmd *cmd, > { > int err; > char *media; > - char buf[MNL_SOCKET_BUFFER_SIZE]; > struct opt *opt; > struct nlattr *attrs; > struct opt opts[] = { > @@ -435,7 +431,8 @@ static int cmd_bearer_add_media(struct nlmsghdr *nlh, const struct cmd *cmd, > return -EINVAL; > } > > - if (!(nlh = msg_init(buf, TIPC_NL_BEARER_ADD))) { > + nlh = msg_init(TIPC_NL_BEARER_ADD); > + if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > } > @@ -482,7 +479,6 @@ static int cmd_bearer_enable(struct nlmsghdr *nlh, const struct cmd *cmd, > int err; > struct opt *opt; > struct nlattr *nest; > - char buf[MNL_SOCKET_BUFFER_SIZE]; > struct opt opts[] = { > { "device", OPT_KEYVAL, NULL }, > { "domain", OPT_KEYVAL, NULL }, > @@ -508,7 +504,8 @@ static int cmd_bearer_enable(struct nlmsghdr *nlh, const struct cmd *cmd, > return -EINVAL; > } > > - if (!(nlh = msg_init(buf, TIPC_NL_BEARER_ENABLE))) { > + nlh = msg_init(TIPC_NL_BEARER_ENABLE); > + if (!nlh) { > fprintf(stderr, "error: message initialisation failed\n"); > return -1; > } > @@ -563,7 +560,6 @@ static int cmd_bearer_disable(struct nlmsghdr *nlh, const struct cmd *cmd, > struct cmdl *cmdl, void *data) > { > int err; > - char buf[MNL_SOCKET_BUFFER_SIZE]; > struct nlattr *nest; > struct opt opts[] = { > { "device", OPT_KEYVAL, NULL }, > @@ -584,7 +580,8 @@ static int cmd_bearer_disable(struct nlmsghdr *nlh, const struct cmd *cmd, > return -EINVAL; > } > > - if (!(nlh = msg_init(buf, TIPC_NL_BEARER_DISABLE))) { > + nlh = msg_init(TIPC_NL_BEARER_DISABLE); > + if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > } > @@ -628,7 +625,6 @@ static int cmd_bearer_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, > int err; > int val; > int prop; > - char buf[MNL_SOCKET_BUFFER_SIZE]; > struct nlattr *props; > struct nlattr *attrs; > struct opt opts[] = { > @@ -675,7 +671,8 @@ static int cmd_bearer_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, > } > } > > - if (!(nlh = msg_init(buf, TIPC_NL_BEARER_SET))) { > + nlh = msg_init(TIPC_NL_BEARER_SET); > + if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > } > @@ -876,7 +873,6 @@ static int cmd_bearer_get_media(struct nlmsghdr *nlh, const struct cmd *cmd, > { > int err; > char *media; > - char buf[MNL_SOCKET_BUFFER_SIZE]; > struct opt *opt; > struct cb_data cb_data = {0}; > struct nlattr *attrs; > @@ -918,7 +914,8 @@ static int cmd_bearer_get_media(struct nlmsghdr *nlh, const struct cmd *cmd, > return -EINVAL; > } > > - if (!(nlh = msg_init(buf, TIPC_NL_BEARER_GET))) { > + nlh = msg_init(TIPC_NL_BEARER_GET); > + if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > } > @@ -956,7 +953,6 @@ static int cmd_bearer_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, > { > int err; > int prop; > - char buf[MNL_SOCKET_BUFFER_SIZE]; > struct nlattr *attrs; > struct opt opts[] = { > { "device", OPT_KEYVAL, NULL }, > @@ -1001,7 +997,8 @@ static int cmd_bearer_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, > } > } > > - if (!(nlh = msg_init(buf, TIPC_NL_BEARER_GET))) { > + nlh = msg_init(TIPC_NL_BEARER_GET); > + if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > } > @@ -1056,14 +1053,13 @@ static int bearer_list_cb(const struct nlmsghdr *nlh, void *data) > static int cmd_bearer_list(struct nlmsghdr *nlh, const struct cmd *cmd, > struct cmdl *cmdl, void *data) > { > - char buf[MNL_SOCKET_BUFFER_SIZE]; > - > if (help_flag) { > fprintf(stderr, "Usage: %s bearer list\n", cmdl->argv[0]); > return -EINVAL; > } > > - if (!(nlh = msg_init(buf, TIPC_NL_BEARER_GET))) { > + nlh = msg_init(TIPC_NL_BEARER_GET); > + if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > } > diff --git a/tipc/cmdl.c b/tipc/cmdl.c > index 981e268ebf94..feaac2da175f 100644 > --- a/tipc/cmdl.c > +++ b/tipc/cmdl.c > @@ -13,8 +13,6 @@ > #include <string.h> > #include <errno.h> > > -#include <libmnl/libmnl.h> > - > #include "cmdl.h" > > static const struct cmd *find_cmd(const struct cmd *cmds, char *str) > diff --git a/tipc/link.c b/tipc/link.c > index 192736eaa154..2123f109c694 100644 > --- a/tipc/link.c > +++ b/tipc/link.c > @@ -17,7 +17,6 @@ > #include <linux/tipc_netlink.h> > #include <linux/tipc.h> > #include <linux/genetlink.h> > -#include <libmnl/libmnl.h> > > #include "cmdl.h" > #include "msg.h" > @@ -60,7 +59,6 @@ static int link_list_cb(const struct nlmsghdr *nlh, void *data) > static int cmd_link_list(struct nlmsghdr *nlh, const struct cmd *cmd, > struct cmdl *cmdl, void *data) > { > - char buf[MNL_SOCKET_BUFFER_SIZE]; > int err = 0; > > if (help_flag) { > @@ -68,7 +66,7 @@ static int cmd_link_list(struct nlmsghdr *nlh, const struct cmd *cmd, > return -EINVAL; > } > > - nlh = msg_init(buf, TIPC_NL_LINK_GET); > + nlh = msg_init(TIPC_NL_LINK_GET); > if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > @@ -126,7 +124,6 @@ static int cmd_link_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, > struct cmdl *cmdl, void *data) > { > int prop; > - char buf[MNL_SOCKET_BUFFER_SIZE]; > struct nlattr *attrs; > struct opt *opt; > struct opt opts[] = { > @@ -151,7 +148,7 @@ static int cmd_link_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, > if (parse_opts(opts, cmdl) < 0) > return -EINVAL; > > - nlh = msg_init(buf, TIPC_NL_LINK_GET); > + nlh = msg_init(TIPC_NL_LINK_GET); > if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > @@ -241,7 +238,6 @@ static int cmd_link_get_bcast(struct nlmsghdr *nlh, const struct cmd *cmd, > struct cmdl *cmdl, void *data) > { > int prop = TIPC_NLA_PROP_BROADCAST; > - char buf[MNL_SOCKET_BUFFER_SIZE]; > struct nlattr *attrs; > > if (help_flag) { > @@ -249,7 +245,7 @@ static int cmd_link_get_bcast(struct nlmsghdr *nlh, const struct cmd *cmd, > return -EINVAL; > } > > - nlh = msg_init(buf, TIPC_NL_LINK_GET); > + nlh = msg_init(TIPC_NL_LINK_GET); > if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > @@ -284,7 +280,6 @@ static int cmd_link_stat_reset(struct nlmsghdr *nlh, const struct cmd *cmd, > struct cmdl *cmdl, void *data) > { > char *link; > - char buf[MNL_SOCKET_BUFFER_SIZE]; > struct opt *opt; > struct nlattr *nest; > struct opt opts[] = { > @@ -302,7 +297,7 @@ static int cmd_link_stat_reset(struct nlmsghdr *nlh, const struct cmd *cmd, > return -EINVAL; > } > > - nlh = msg_init(buf, TIPC_NL_LINK_RESET_STATS); > + nlh = msg_init(TIPC_NL_LINK_RESET_STATS); > if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > @@ -550,7 +545,6 @@ static int cmd_link_stat_show(struct nlmsghdr *nlh, const struct cmd *cmd, > struct cmdl *cmdl, void *data) > { > char *link = NULL; > - char buf[MNL_SOCKET_BUFFER_SIZE]; > struct opt *opt; > struct opt opts[] = { > { "link", OPT_KEYVAL, NULL }, > @@ -564,7 +558,7 @@ static int cmd_link_stat_show(struct nlmsghdr *nlh, const struct cmd *cmd, > return -EINVAL; > } > > - nlh = msg_init(buf, TIPC_NL_LINK_GET); > + nlh = msg_init(TIPC_NL_LINK_GET); > if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > @@ -626,7 +620,6 @@ static int cmd_link_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, > { > int val; > int prop; > - char buf[MNL_SOCKET_BUFFER_SIZE]; > struct nlattr *props; > struct nlattr *attrs; > struct opt *opt; > @@ -658,7 +651,7 @@ static int cmd_link_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, > if (parse_opts(opts, cmdl) < 0) > return -EINVAL; > > - nlh = msg_init(buf, TIPC_NL_LINK_SET); > + nlh = msg_init(TIPC_NL_LINK_SET); > if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > @@ -704,7 +697,6 @@ static void cmd_link_set_bcast_help(struct cmdl *cmdl) > static int cmd_link_set_bcast(struct nlmsghdr *nlh, const struct cmd *cmd, > struct cmdl *cmdl, void *data) > { > - char buf[MNL_SOCKET_BUFFER_SIZE]; > struct nlattr *props; > struct nlattr *attrs; > struct opt *opt; > @@ -734,7 +726,7 @@ static int cmd_link_set_bcast(struct nlmsghdr *nlh, const struct cmd *cmd, > return -EINVAL; > } > > - nlh = msg_init(buf, TIPC_NL_LINK_SET); > + nlh = msg_init(TIPC_NL_LINK_SET); > if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > @@ -788,7 +780,6 @@ static int cmd_link_mon_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, > struct cmdl *cmdl, void *data) > { > int size; > - char buf[MNL_SOCKET_BUFFER_SIZE]; > struct nlattr *attrs; > > if (cmdl->argc != cmdl->optind + 1) { > @@ -797,7 +788,7 @@ static int cmd_link_mon_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, > } > size = atoi(shift_cmdl(cmdl)); > > - nlh = msg_init(buf, TIPC_NL_MON_SET); > + nlh = msg_init(TIPC_NL_MON_SET); > if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > @@ -841,7 +832,6 @@ static int link_mon_summary_cb(const struct nlmsghdr *nlh, void *data) > static int cmd_link_mon_summary(struct nlmsghdr *nlh, const struct cmd *cmd, > struct cmdl *cmdl, void *data) > { > - char buf[MNL_SOCKET_BUFFER_SIZE]; > int err = 0; > > if (help_flag) { > @@ -849,7 +839,7 @@ static int cmd_link_mon_summary(struct nlmsghdr *nlh, const struct cmd *cmd, > return -EINVAL; > } > > - nlh = msg_init(buf, TIPC_NL_MON_GET); > + nlh = msg_init(TIPC_NL_MON_GET); > if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > @@ -1004,11 +994,10 @@ exit: > static int link_mon_peer_list(uint32_t mon_ref) > { > struct nlmsghdr *nlh; > - char buf[MNL_SOCKET_BUFFER_SIZE]; > struct nlattr *nest; > int err = 0; > > - nlh = msg_init(buf, TIPC_NL_MON_PEER_GET); > + nlh = msg_init(TIPC_NL_MON_PEER_GET); > if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > @@ -1080,7 +1069,6 @@ static void cmd_link_mon_list_udp_help(struct cmdl *cmdl, char *media) > static int cmd_link_mon_list(struct nlmsghdr *nlh, const struct cmd *cmd, > struct cmdl *cmdl, void *data) > { > - char buf[MNL_SOCKET_BUFFER_SIZE]; > char bname[TIPC_MAX_BEARER_NAME] = {0}; > struct opt opts[] = { > { "media", OPT_KEYVAL, NULL }, > @@ -1112,7 +1100,7 @@ static int cmd_link_mon_list(struct nlmsghdr *nlh, const struct cmd *cmd, > return -EINVAL; > } > > - nlh = msg_init(buf, TIPC_NL_MON_GET); > + nlh = msg_init(TIPC_NL_MON_GET); > if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > @@ -1176,9 +1164,8 @@ static int link_mon_get_cb(const struct nlmsghdr *nlh, void *data) > static int cmd_link_mon_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, > struct cmdl *cmdl, void *data) > { > - char buf[MNL_SOCKET_BUFFER_SIZE]; > > - nlh = msg_init(buf, TIPC_NL_MON_GET); > + nlh = msg_init(TIPC_NL_MON_GET); > if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > diff --git a/tipc/media.c b/tipc/media.c > index 969ef6578b3b..a3fec681cbf4 100644 > --- a/tipc/media.c > +++ b/tipc/media.c > @@ -15,9 +15,7 @@ > #include <errno.h> > > #include <linux/tipc_netlink.h> > -#include <linux/tipc.h> > #include <linux/genetlink.h> > -#include <libmnl/libmnl.h> > > #include "cmdl.h" > #include "msg.h" > @@ -45,14 +43,13 @@ static int media_list_cb(const struct nlmsghdr *nlh, void *data) > static int cmd_media_list(struct nlmsghdr *nlh, const struct cmd *cmd, > struct cmdl *cmdl, void *data) > { > - char buf[MNL_SOCKET_BUFFER_SIZE]; > - > if (help_flag) { > fprintf(stderr, "Usage: %s media list\n", cmdl->argv[0]); > return -EINVAL; > } > > - if (!(nlh = msg_init(buf, TIPC_NL_MEDIA_GET))) { > + nlh = msg_init(TIPC_NL_MEDIA_GET); > + if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > } > @@ -89,7 +86,6 @@ static int cmd_media_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, > struct cmdl *cmdl, void *data) > { > int prop; > - char buf[MNL_SOCKET_BUFFER_SIZE]; > struct nlattr *nest; > struct opt *opt; > struct opt opts[] = { > @@ -116,7 +112,8 @@ static int cmd_media_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, > if (parse_opts(opts, cmdl) < 0) > return -EINVAL; > > - if (!(nlh = msg_init(buf, TIPC_NL_MEDIA_GET))) { > + nlh = msg_init(TIPC_NL_MEDIA_GET); > + if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > } > @@ -179,7 +176,6 @@ static int cmd_media_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, > { > int val; > int prop; > - char buf[MNL_SOCKET_BUFFER_SIZE]; > struct nlattr *props; > struct nlattr *attrs; > struct opt *opt; > @@ -213,7 +209,8 @@ static int cmd_media_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, > if (parse_opts(opts, cmdl) < 0) > return -EINVAL; > > - if (!(nlh = msg_init(buf, TIPC_NL_MEDIA_SET))) { > + nlh = msg_init(TIPC_NL_MEDIA_SET); > + if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > } > diff --git a/tipc/msg.c b/tipc/msg.c > index dc09d05048f3..1225691c9a81 100644 > --- a/tipc/msg.c > +++ b/tipc/msg.c > @@ -13,13 +13,13 @@ > #include <time.h> > #include <errno.h> > > -#include <linux/tipc_netlink.h> > -#include <linux/tipc.h> > -#include <linux/genetlink.h> > #include <libmnl/libmnl.h> > > +#include "mnl_utils.h" > #include "msg.h" > > +extern struct mnlu_gen_socket tipc_nlg; > + > int parse_attrs(const struct nlattr *attr, void *data) > { > const struct nlattr **tb = data; > @@ -30,141 +30,23 @@ int parse_attrs(const struct nlattr *attr, void *data) > return MNL_CB_OK; > } > > -static int family_id_cb(const struct nlmsghdr *nlh, void *data) > -{ > - struct nlattr *tb[CTRL_ATTR_MAX + 1] = {}; > - struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh); > - int *id = data; > - > - mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, tb); > - if (!tb[CTRL_ATTR_FAMILY_ID]) > - return MNL_CB_ERROR; > - > - *id = mnl_attr_get_u16(tb[CTRL_ATTR_FAMILY_ID]); > - > - return MNL_CB_OK; > -} > - > -static struct mnl_socket *msg_send(struct nlmsghdr *nlh) > -{ > - int ret; > - struct mnl_socket *nl; > - > - nl = mnl_socket_open(NETLINK_GENERIC); > - if (nl == NULL) { > - perror("mnl_socket_open"); > - return NULL; > - } > - > - ret = mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID); > - if (ret < 0) { > - perror("mnl_socket_bind"); > - return NULL; > - } > - > - ret = mnl_socket_sendto(nl, nlh, nlh->nlmsg_len); > - if (ret < 0) { > - perror("mnl_socket_send"); > - return NULL; > - } > - > - return nl; > -} > - > -static int msg_recv(struct mnl_socket *nl, mnl_cb_t callback, void *data, int seq) > -{ > - int ret; > - unsigned int portid; > - char buf[MNL_SOCKET_BUFFER_SIZE]; > - > - portid = mnl_socket_get_portid(nl); > - > - ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); > - while (ret > 0) { > - ret = mnl_cb_run(buf, ret, seq, portid, callback, data); > - if (ret <= 0) > - break; > - ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); > - } > - if (ret == -1) > - perror("error"); > - > - mnl_socket_close(nl); > - > - return ret; > -} > - > -static int msg_query(struct nlmsghdr *nlh, mnl_cb_t callback, void *data) > -{ > - unsigned int seq; > - struct mnl_socket *nl; > - > - seq = time(NULL); > - nlh->nlmsg_seq = seq; > - > - nl = msg_send(nlh); > - if (!nl) > - return -ENOTSUP; > - > - return msg_recv(nl, callback, data, seq); > -} > - > -static int get_family(void) > -{ > - int err; > - int nl_family; > - struct nlmsghdr *nlh; > - struct genlmsghdr *genl; > - char buf[MNL_SOCKET_BUFFER_SIZE]; > - > - nlh = mnl_nlmsg_put_header(buf); > - nlh->nlmsg_type = GENL_ID_CTRL; > - nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; > - > - genl = mnl_nlmsg_put_extra_header(nlh, sizeof(struct genlmsghdr)); > - genl->cmd = CTRL_CMD_GETFAMILY; > - genl->version = 1; > - > - mnl_attr_put_u16(nlh, CTRL_ATTR_FAMILY_ID, GENL_ID_CTRL); > - mnl_attr_put_strz(nlh, CTRL_ATTR_FAMILY_NAME, TIPC_GENL_V2_NAME); > - > - if ((err = msg_query(nlh, family_id_cb, &nl_family))) > - return err; > - > - return nl_family; > -} > - > int msg_doit(struct nlmsghdr *nlh, mnl_cb_t callback, void *data) > { > nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; > - return msg_query(nlh, callback, data); > + return mnlu_gen_socket_sndrcv(&tipc_nlg, nlh, callback, data); > } > > int msg_dumpit(struct nlmsghdr *nlh, mnl_cb_t callback, void *data) > { > nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP; > - return msg_query(nlh, callback, data); > + return mnlu_gen_socket_sndrcv(&tipc_nlg, nlh, callback, data); > } > > -struct nlmsghdr *msg_init(char *buf, int cmd) > +struct nlmsghdr *msg_init(int cmd) > { > - int family; > struct nlmsghdr *nlh; > - struct genlmsghdr *genl; > - > - family = get_family(); > - if (family <= 0) { > - fprintf(stderr, > - "Unable to get TIPC nl family id (module loaded?)\n"); > - return NULL; > - } > - > - nlh = mnl_nlmsg_put_header(buf); > - nlh->nlmsg_type = family; > > - genl = mnl_nlmsg_put_extra_header(nlh, sizeof(struct genlmsghdr)); > - genl->cmd = cmd; > - genl->version = 1; > + nlh = mnlu_gen_socket_cmd_prepare(&tipc_nlg, cmd, 0); > > return nlh; > } > diff --git a/tipc/msg.h b/tipc/msg.h > index 41fd1ad1403a..56af5a705fb9 100644 > --- a/tipc/msg.h > +++ b/tipc/msg.h > @@ -12,7 +12,7 @@ > #ifndef _TIPC_MSG_H > #define _TIPC_MSG_H > > -struct nlmsghdr *msg_init(char *buf, int cmd); > +struct nlmsghdr *msg_init(int cmd); > int msg_doit(struct nlmsghdr *nlh, mnl_cb_t callback, void *data); > int msg_dumpit(struct nlmsghdr *nlh, mnl_cb_t callback, void *data); > int parse_attrs(const struct nlattr *attr, void *data); > diff --git a/tipc/nametable.c b/tipc/nametable.c > index d899eeb67c07..b09ed5fc7280 100644 > --- a/tipc/nametable.c > +++ b/tipc/nametable.c > @@ -15,7 +15,6 @@ > #include <linux/tipc_netlink.h> > #include <linux/tipc.h> > #include <linux/genetlink.h> > -#include <libmnl/libmnl.h> > > #include "cmdl.h" > #include "msg.h" > @@ -82,7 +81,6 @@ static int cmd_nametable_show(struct nlmsghdr *nlh, const struct cmd *cmd, > struct cmdl *cmdl, void *data) > { > int iteration = 0; > - char buf[MNL_SOCKET_BUFFER_SIZE]; > int rc = 0; > > if (help_flag) { > @@ -90,7 +88,8 @@ static int cmd_nametable_show(struct nlmsghdr *nlh, const struct cmd *cmd, > return -EINVAL; > } > > - if (!(nlh = msg_init(buf, TIPC_NL_NAME_TABLE_GET))) { > + nlh = msg_init(TIPC_NL_NAME_TABLE_GET); > + if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > } > diff --git a/tipc/node.c b/tipc/node.c > index 05246013487f..ae75bfff7d2f 100644 > --- a/tipc/node.c > +++ b/tipc/node.c > @@ -17,7 +17,6 @@ > #include <linux/tipc_netlink.h> > #include <linux/tipc.h> > #include <linux/genetlink.h> > -#include <libmnl/libmnl.h> > > #include "cmdl.h" > #include "msg.h" > @@ -52,14 +51,13 @@ static int node_list_cb(const struct nlmsghdr *nlh, void *data) > static int cmd_node_list(struct nlmsghdr *nlh, const struct cmd *cmd, > struct cmdl *cmdl, void *data) > { > - char buf[MNL_SOCKET_BUFFER_SIZE]; > - > if (help_flag) { > fprintf(stderr, "Usage: %s node list\n", cmdl->argv[0]); > return -EINVAL; > } > > - if (!(nlh = msg_init(buf, TIPC_NL_NODE_GET))) { > + nlh = msg_init(TIPC_NL_NODE_GET); > + if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > } > @@ -73,7 +71,6 @@ static int cmd_node_set_addr(struct nlmsghdr *nlh, const struct cmd *cmd, > char *str; > uint32_t addr; > struct nlattr *nest; > - char buf[MNL_SOCKET_BUFFER_SIZE]; > > if (cmdl->argc != cmdl->optind + 1) { > fprintf(stderr, "Usage: %s node set address ADDRESS\n", > @@ -86,7 +83,8 @@ static int cmd_node_set_addr(struct nlmsghdr *nlh, const struct cmd *cmd, > if (!addr) > return -1; > > - if (!(nlh = msg_init(buf, TIPC_NL_NET_SET))) { > + nlh = msg_init(TIPC_NL_NET_SET); > + if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > } > @@ -126,7 +124,6 @@ static int cmd_node_get_addr(struct nlmsghdr *nlh, const struct cmd *cmd, > static int cmd_node_set_nodeid(struct nlmsghdr *nlh, const struct cmd *cmd, > struct cmdl *cmdl, void *data) > { > - char buf[MNL_SOCKET_BUFFER_SIZE]; > uint8_t id[16] = {0,}; > uint64_t *w0 = (uint64_t *) &id[0]; > uint64_t *w1 = (uint64_t *) &id[8]; > @@ -145,7 +142,7 @@ static int cmd_node_set_nodeid(struct nlmsghdr *nlh, const struct cmd *cmd, > return -EINVAL; > } > > - nlh = msg_init(buf, TIPC_NL_NET_SET); > + nlh = msg_init(TIPC_NL_NET_SET); > if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > @@ -201,7 +198,6 @@ static int cmd_node_set_key(struct nlmsghdr *nlh, const struct cmd *cmd, > }; > struct nlattr *nest; > struct opt *opt_algname, *opt_nodeid, *opt_master, *opt_rekeying; > - char buf[MNL_SOCKET_BUFFER_SIZE]; > uint8_t id[TIPC_NODEID_LEN] = {0,}; > uint32_t rekeying = 0; > bool has_key = false; > @@ -262,7 +258,7 @@ get_ops: > } > > /* Init & do the command */ > - nlh = msg_init(buf, TIPC_NL_KEY_SET); > + nlh = msg_init(TIPC_NL_KEY_SET); > if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > @@ -287,15 +283,13 @@ get_ops: > static int cmd_node_flush_key(struct nlmsghdr *nlh, const struct cmd *cmd, > struct cmdl *cmdl, void *data) > { > - char buf[MNL_SOCKET_BUFFER_SIZE]; > - > if (help_flag) { > (cmd->help)(cmdl); > return -EINVAL; > } > > /* Init & do the command */ > - nlh = msg_init(buf, TIPC_NL_KEY_FLUSH); > + nlh = msg_init(TIPC_NL_KEY_FLUSH); > if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > @@ -332,14 +326,12 @@ static int nodeid_get_cb(const struct nlmsghdr *nlh, void *data) > static int cmd_node_get_nodeid(struct nlmsghdr *nlh, const struct cmd *cmd, > struct cmdl *cmdl, void *data) > { > - char buf[MNL_SOCKET_BUFFER_SIZE]; > - > if (help_flag) { > (cmd->help)(cmdl); > return -EINVAL; > } > > - nlh = msg_init(buf, TIPC_NL_NET_GET); > + nlh = msg_init(TIPC_NL_NET_GET); > if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > @@ -370,14 +362,13 @@ static int netid_get_cb(const struct nlmsghdr *nlh, void *data) > static int cmd_node_get_netid(struct nlmsghdr *nlh, const struct cmd *cmd, > struct cmdl *cmdl, void *data) > { > - char buf[MNL_SOCKET_BUFFER_SIZE]; > - > if (help_flag) { > (cmd->help)(cmdl); > return -EINVAL; > } > > - if (!(nlh = msg_init(buf, TIPC_NL_NET_GET))) { > + nlh = msg_init(TIPC_NL_NET_GET); > + if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > } > @@ -389,7 +380,6 @@ static int cmd_node_set_netid(struct nlmsghdr *nlh, const struct cmd *cmd, > struct cmdl *cmdl, void *data) > { > int netid; > - char buf[MNL_SOCKET_BUFFER_SIZE]; > struct nlattr *nest; > > if (help_flag) { > @@ -397,7 +387,8 @@ static int cmd_node_set_netid(struct nlmsghdr *nlh, const struct cmd *cmd, > return -EINVAL; > } > > - if (!(nlh = msg_init(buf, TIPC_NL_NET_SET))) { > + nlh = msg_init(TIPC_NL_NET_SET); > + if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > } > diff --git a/tipc/peer.c b/tipc/peer.c > index f14ec35e6f71..ed18efc552fa 100644 > --- a/tipc/peer.c > +++ b/tipc/peer.c > @@ -17,7 +17,6 @@ > #include <linux/tipc_netlink.h> > #include <linux/tipc.h> > #include <linux/genetlink.h> > -#include <libmnl/libmnl.h> > > #include "cmdl.h" > #include "msg.h" > @@ -30,7 +29,6 @@ static int cmd_peer_rm_addr(struct nlmsghdr *nlh, const struct cmd *cmd, > char *str; > uint32_t addr; > struct nlattr *nest; > - char buf[MNL_SOCKET_BUFFER_SIZE]; > > if ((cmdl->argc != cmdl->optind + 1) || help_flag) { > fprintf(stderr, "Usage: %s peer remove address ADDRESS\n", > @@ -47,7 +45,8 @@ static int cmd_peer_rm_addr(struct nlmsghdr *nlh, const struct cmd *cmd, > if (!addr) > return -1; > > - if (!(nlh = msg_init(buf, TIPC_NL_PEER_REMOVE))) { > + nlh = msg_init(TIPC_NL_PEER_REMOVE); > + if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > } > @@ -62,7 +61,6 @@ static int cmd_peer_rm_addr(struct nlmsghdr *nlh, const struct cmd *cmd, > static int cmd_peer_rm_nodeid(struct nlmsghdr *nlh, const struct cmd *cmd, > struct cmdl *cmdl, void *data) > { > - char buf[MNL_SOCKET_BUFFER_SIZE]; > __u8 id[16] = {0,}; > __u64 *w0 = (__u64 *)&id[0]; > __u64 *w1 = (__u64 *)&id[8]; > @@ -81,7 +79,7 @@ static int cmd_peer_rm_nodeid(struct nlmsghdr *nlh, const struct cmd *cmd, > return -EINVAL; > } > > - nlh = msg_init(buf, TIPC_NL_PEER_REMOVE); > + nlh = msg_init(TIPC_NL_PEER_REMOVE); > if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > diff --git a/tipc/socket.c b/tipc/socket.c > index 852984ecd1e7..deae12af4409 100644 > --- a/tipc/socket.c > +++ b/tipc/socket.c > @@ -15,7 +15,6 @@ > #include <linux/tipc.h> > #include <linux/tipc_netlink.h> > #include <linux/genetlink.h> > -#include <libmnl/libmnl.h> > > #include "cmdl.h" > #include "msg.h" > @@ -46,10 +45,10 @@ static int publ_list_cb(const struct nlmsghdr *nlh, void *data) > static int publ_list(uint32_t sock) > { > struct nlmsghdr *nlh; > - char buf[MNL_SOCKET_BUFFER_SIZE]; > struct nlattr *nest; > > - if (!(nlh = msg_init(buf, TIPC_NL_PUBL_GET))) { > + nlh = msg_init(TIPC_NL_PUBL_GET); > + if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > } > @@ -103,14 +102,13 @@ static int sock_list_cb(const struct nlmsghdr *nlh, void *data) > static int cmd_socket_list(struct nlmsghdr *nlh, const struct cmd *cmd, > struct cmdl *cmdl, void *data) > { > - char buf[MNL_SOCKET_BUFFER_SIZE]; > - > if (help_flag) { > fprintf(stderr, "Usage: %s socket list\n", cmdl->argv[0]); > return -EINVAL; > } > > - if (!(nlh = msg_init(buf, TIPC_NL_SOCK_GET))) { > + nlh = msg_init(TIPC_NL_SOCK_GET); > + if (!nlh) { > fprintf(stderr, "error, message initialisation failed\n"); > return -1; > } > diff --git a/tipc/tipc.c b/tipc/tipc.c > index 60176a044f8d..9f23a4bfd25d 100644 > --- a/tipc/tipc.c > +++ b/tipc/tipc.c > @@ -13,7 +13,11 @@ > #include <stdlib.h> > #include <getopt.h> > #include <unistd.h> > +#include <linux/tipc_netlink.h> > +#include <libmnl/libmnl.h> > +#include <errno.h> > > +#include "mnl_utils.h" > #include "bearer.h" > #include "link.h" > #include "nametable.h" > @@ -26,6 +30,7 @@ > > int help_flag; > int json; > +struct mnlu_gen_socket tipc_nlg; > > static void about(struct cmdl *cmdl) > { > @@ -110,8 +115,20 @@ int main(int argc, char *argv[]) > cmdl.argc = argc; > cmdl.argv = argv; > > - if ((res = run_cmd(NULL, &cmd, cmds, &cmdl, NULL)) != 0) > - return 1; > + res = mnlu_gen_socket_open(&tipc_nlg, TIPC_GENL_V2_NAME, > + TIPC_GENL_V2_VERSION); > + if (res) { > + fprintf(stderr, > + "Unable to get TIPC nl family id (module loaded?)\n"); > + return -1; > + } > > + res = run_cmd(NULL, &cmd, cmds, &cmdl, &tipc_nlg); > + if (res != 0) { > + mnlu_gen_socket_close(&tipc_nlg); > + return -1; > + } > + > + mnlu_gen_socket_close(&tipc_nlg); > return 0; > } Acked-by: Jon Maloy <jm...@re...> |
From: Jon M. <jm...@re...> - 2021-03-31 14:53:42
|
On 3/29/21 10:16 PM, Hoang Le wrote: > When enabling a bearer s/with identify//g > by name, we don't sanity check > its name with higher slot in bearer list. This lead to duplicate > bearer names bypassed the check. This may have the effect that the name of an already enabled bearer bypasses the check. > > To fix the above issue, we just perform an extra checking with all > existing bearers. > > Fixes: cb30a63384bc9 ("tipc: refactor function tipc_enable_bearer()") > Signed-off-by: Hoang Le <hoa...@de...> > --- > net/tipc/bearer.c | 45 ++++++++++++++++++++++++++------------------- > 1 file changed, 26 insertions(+), 19 deletions(-) > > diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c > index d47e0b940ac9..94eddc67d52e 100644 > --- a/net/tipc/bearer.c > +++ b/net/tipc/bearer.c > @@ -256,6 +256,7 @@ static int tipc_enable_bearer(struct net *net, const char *name, > int bearer_id = 0; > int res = -EINVAL; > char *errstr = ""; > + u32 i; > > if (!bearer_name_validate(name, &b_names)) { > errstr = "illegal name"; > @@ -280,31 +281,37 @@ static int tipc_enable_bearer(struct net *net, const char *name, > prio = m->priority; > > /* Check new bearer vs existing ones and find free bearer id if any */ > - while (bearer_id < MAX_BEARERS) { > - b = rtnl_dereference(tn->bearer_list[bearer_id]); > - if (!b) > - break; > + bearer_id = MAX_BEARERS; > + i = MAX_BEARERS; > + while (i-- != 0) { > + b = rtnl_dereference(tn->bearer_list[i]); > + if (!b) { > + bearer_id = i; > + continue; > + } > if (!strcmp(name, b->name)) { > errstr = "already enabled"; > NL_SET_ERR_MSG(extack, "Already enabled"); > goto rejected; > } > - bearer_id++; > - if (b->priority != prio) > - continue; > - if (++with_this_prio <= 2) > - continue; > - pr_warn("Bearer <%s>: already 2 bearers with priority %u\n", > - name, prio); > - if (prio == TIPC_MIN_LINK_PRI) { > - errstr = "cannot adjust to lower"; > - NL_SET_ERR_MSG(extack, "Cannot adjust to lower"); > - goto rejected; > + > + if (b->priority == prio && > + (++with_this_prio > 2)) { > + pr_warn("Bearer <%s>: already 2 bearers with priority %u\n", > + name, prio); > + > + if (prio == TIPC_MIN_LINK_PRI) { > + errstr = "cannot adjust to lower"; > + NL_SET_ERR_MSG(extack, "Cannot adjust to lower"); > + goto rejected; > + } > + > + pr_warn("Bearer <%s>: trying with adjusted priority\n", name); > + prio--; > + bearer_id = MAX_BEARERS; > + i = MAX_BEARERS; > + with_this_prio = 1; > } > - pr_warn("Bearer <%s>: trying with adjusted priority\n", name); > - prio--; > - bearer_id = 0; > - with_this_prio = 1; > } > > if (bearer_id >= MAX_BEARERS) { Acked-by: Jon Maloy <jm...@re...> |
From: Hoang Le <hoa...@de...> - 2021-03-30 02:32:56
|
When enabling a bearer with identify by name, we don't sanity check its name with higher slot in bearer list. This lead to duplicate bearer names bypassed the check. To fix the above issue, we just perform an extra checking with all existing bearers. Fixes: cb30a63384bc9 ("tipc: refactor function tipc_enable_bearer()") Signed-off-by: Hoang Le <hoa...@de...> --- net/tipc/bearer.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index d47e0b940ac9..94eddc67d52e 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c @@ -256,6 +256,7 @@ static int tipc_enable_bearer(struct net *net, const char *name, int bearer_id = 0; int res = -EINVAL; char *errstr = ""; + u32 i; if (!bearer_name_validate(name, &b_names)) { errstr = "illegal name"; @@ -280,31 +281,37 @@ static int tipc_enable_bearer(struct net *net, const char *name, prio = m->priority; /* Check new bearer vs existing ones and find free bearer id if any */ - while (bearer_id < MAX_BEARERS) { - b = rtnl_dereference(tn->bearer_list[bearer_id]); - if (!b) - break; + bearer_id = MAX_BEARERS; + i = MAX_BEARERS; + while (i-- != 0) { + b = rtnl_dereference(tn->bearer_list[i]); + if (!b) { + bearer_id = i; + continue; + } if (!strcmp(name, b->name)) { errstr = "already enabled"; NL_SET_ERR_MSG(extack, "Already enabled"); goto rejected; } - bearer_id++; - if (b->priority != prio) - continue; - if (++with_this_prio <= 2) - continue; - pr_warn("Bearer <%s>: already 2 bearers with priority %u\n", - name, prio); - if (prio == TIPC_MIN_LINK_PRI) { - errstr = "cannot adjust to lower"; - NL_SET_ERR_MSG(extack, "Cannot adjust to lower"); - goto rejected; + + if (b->priority == prio && + (++with_this_prio > 2)) { + pr_warn("Bearer <%s>: already 2 bearers with priority %u\n", + name, prio); + + if (prio == TIPC_MIN_LINK_PRI) { + errstr = "cannot adjust to lower"; + NL_SET_ERR_MSG(extack, "Cannot adjust to lower"); + goto rejected; + } + + pr_warn("Bearer <%s>: trying with adjusted priority\n", name); + prio--; + bearer_id = MAX_BEARERS; + i = MAX_BEARERS; + with_this_prio = 1; } - pr_warn("Bearer <%s>: trying with adjusted priority\n", name); - prio--; - bearer_id = 0; - with_this_prio = 1; } if (bearer_id >= MAX_BEARERS) { -- 2.25.1 |
From: Hoang Le <hoa...@de...> - 2021-03-29 10:59:41
|
To avoid duplication, tipc should be converted to use the helper functions for working with libmnl in lib/mnl_utils.c Signed-off-by: Hoang Le <hoa...@de...> --- tipc/bearer.c | 38 ++++++-------- tipc/cmdl.c | 2 - tipc/link.c | 37 +++++-------- tipc/media.c | 15 +++--- tipc/msg.c | 132 +++-------------------------------------------- tipc/msg.h | 2 +- tipc/nametable.c | 5 +- tipc/node.c | 33 +++++------- tipc/peer.c | 8 ++- tipc/socket.c | 10 ++-- tipc/tipc.c | 21 +++++++- 11 files changed, 83 insertions(+), 220 deletions(-) diff --git a/tipc/bearer.c b/tipc/bearer.c index 4470819e4a96..2afc48b9b108 100644 --- a/tipc/bearer.c +++ b/tipc/bearer.c @@ -21,9 +21,6 @@ #include <linux/genetlink.h> #include <linux/if.h> -#include <libmnl/libmnl.h> -#include <sys/socket.h> - #include "utils.h" #include "cmdl.h" #include "msg.h" @@ -101,11 +98,11 @@ static int get_netid_cb(const struct nlmsghdr *nlh, void *data) static int generate_multicast(short af, char *buf, int bufsize) { - int netid; - char mnl_msg[MNL_SOCKET_BUFFER_SIZE]; struct nlmsghdr *nlh; + int netid; - if (!(nlh = msg_init(mnl_msg, TIPC_NL_NET_GET))) { + nlh = msg_init(TIPC_NL_NET_GET); + if (!nlh) { fprintf(stderr, "error, message initialization failed\n"); return -1; } @@ -399,7 +396,6 @@ static int cmd_bearer_add_media(struct nlmsghdr *nlh, const struct cmd *cmd, { int err; char *media; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct opt *opt; struct nlattr *attrs; struct opt opts[] = { @@ -435,7 +431,8 @@ static int cmd_bearer_add_media(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - if (!(nlh = msg_init(buf, TIPC_NL_BEARER_ADD))) { + nlh = msg_init(TIPC_NL_BEARER_ADD); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } @@ -482,7 +479,6 @@ static int cmd_bearer_enable(struct nlmsghdr *nlh, const struct cmd *cmd, int err; struct opt *opt; struct nlattr *nest; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct opt opts[] = { { "device", OPT_KEYVAL, NULL }, { "domain", OPT_KEYVAL, NULL }, @@ -508,7 +504,8 @@ static int cmd_bearer_enable(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - if (!(nlh = msg_init(buf, TIPC_NL_BEARER_ENABLE))) { + nlh = msg_init(TIPC_NL_BEARER_ENABLE); + if (!nlh) { fprintf(stderr, "error: message initialisation failed\n"); return -1; } @@ -563,7 +560,6 @@ static int cmd_bearer_disable(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { int err; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *nest; struct opt opts[] = { { "device", OPT_KEYVAL, NULL }, @@ -584,7 +580,8 @@ static int cmd_bearer_disable(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - if (!(nlh = msg_init(buf, TIPC_NL_BEARER_DISABLE))) { + nlh = msg_init(TIPC_NL_BEARER_DISABLE); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } @@ -628,7 +625,6 @@ static int cmd_bearer_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, int err; int val; int prop; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *props; struct nlattr *attrs; struct opt opts[] = { @@ -675,7 +671,8 @@ static int cmd_bearer_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, } } - if (!(nlh = msg_init(buf, TIPC_NL_BEARER_SET))) { + nlh = msg_init(TIPC_NL_BEARER_SET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } @@ -876,7 +873,6 @@ static int cmd_bearer_get_media(struct nlmsghdr *nlh, const struct cmd *cmd, { int err; char *media; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct opt *opt; struct cb_data cb_data = {0}; struct nlattr *attrs; @@ -918,7 +914,8 @@ static int cmd_bearer_get_media(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - if (!(nlh = msg_init(buf, TIPC_NL_BEARER_GET))) { + nlh = msg_init(TIPC_NL_BEARER_GET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } @@ -956,7 +953,6 @@ static int cmd_bearer_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, { int err; int prop; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *attrs; struct opt opts[] = { { "device", OPT_KEYVAL, NULL }, @@ -1001,7 +997,8 @@ static int cmd_bearer_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, } } - if (!(nlh = msg_init(buf, TIPC_NL_BEARER_GET))) { + nlh = msg_init(TIPC_NL_BEARER_GET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } @@ -1056,14 +1053,13 @@ static int bearer_list_cb(const struct nlmsghdr *nlh, void *data) static int cmd_bearer_list(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; - if (help_flag) { fprintf(stderr, "Usage: %s bearer list\n", cmdl->argv[0]); return -EINVAL; } - if (!(nlh = msg_init(buf, TIPC_NL_BEARER_GET))) { + nlh = msg_init(TIPC_NL_BEARER_GET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } diff --git a/tipc/cmdl.c b/tipc/cmdl.c index 981e268ebf94..feaac2da175f 100644 --- a/tipc/cmdl.c +++ b/tipc/cmdl.c @@ -13,8 +13,6 @@ #include <string.h> #include <errno.h> -#include <libmnl/libmnl.h> - #include "cmdl.h" static const struct cmd *find_cmd(const struct cmd *cmds, char *str) diff --git a/tipc/link.c b/tipc/link.c index 192736eaa154..2123f109c694 100644 --- a/tipc/link.c +++ b/tipc/link.c @@ -17,7 +17,6 @@ #include <linux/tipc_netlink.h> #include <linux/tipc.h> #include <linux/genetlink.h> -#include <libmnl/libmnl.h> #include "cmdl.h" #include "msg.h" @@ -60,7 +59,6 @@ static int link_list_cb(const struct nlmsghdr *nlh, void *data) static int cmd_link_list(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; int err = 0; if (help_flag) { @@ -68,7 +66,7 @@ static int cmd_link_list(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - nlh = msg_init(buf, TIPC_NL_LINK_GET); + nlh = msg_init(TIPC_NL_LINK_GET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -126,7 +124,6 @@ static int cmd_link_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { int prop; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *attrs; struct opt *opt; struct opt opts[] = { @@ -151,7 +148,7 @@ static int cmd_link_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, if (parse_opts(opts, cmdl) < 0) return -EINVAL; - nlh = msg_init(buf, TIPC_NL_LINK_GET); + nlh = msg_init(TIPC_NL_LINK_GET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -241,7 +238,6 @@ static int cmd_link_get_bcast(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { int prop = TIPC_NLA_PROP_BROADCAST; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *attrs; if (help_flag) { @@ -249,7 +245,7 @@ static int cmd_link_get_bcast(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - nlh = msg_init(buf, TIPC_NL_LINK_GET); + nlh = msg_init(TIPC_NL_LINK_GET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -284,7 +280,6 @@ static int cmd_link_stat_reset(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { char *link; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct opt *opt; struct nlattr *nest; struct opt opts[] = { @@ -302,7 +297,7 @@ static int cmd_link_stat_reset(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - nlh = msg_init(buf, TIPC_NL_LINK_RESET_STATS); + nlh = msg_init(TIPC_NL_LINK_RESET_STATS); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -550,7 +545,6 @@ static int cmd_link_stat_show(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { char *link = NULL; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct opt *opt; struct opt opts[] = { { "link", OPT_KEYVAL, NULL }, @@ -564,7 +558,7 @@ static int cmd_link_stat_show(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - nlh = msg_init(buf, TIPC_NL_LINK_GET); + nlh = msg_init(TIPC_NL_LINK_GET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -626,7 +620,6 @@ static int cmd_link_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, { int val; int prop; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *props; struct nlattr *attrs; struct opt *opt; @@ -658,7 +651,7 @@ static int cmd_link_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, if (parse_opts(opts, cmdl) < 0) return -EINVAL; - nlh = msg_init(buf, TIPC_NL_LINK_SET); + nlh = msg_init(TIPC_NL_LINK_SET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -704,7 +697,6 @@ static void cmd_link_set_bcast_help(struct cmdl *cmdl) static int cmd_link_set_bcast(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *props; struct nlattr *attrs; struct opt *opt; @@ -734,7 +726,7 @@ static int cmd_link_set_bcast(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - nlh = msg_init(buf, TIPC_NL_LINK_SET); + nlh = msg_init(TIPC_NL_LINK_SET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -788,7 +780,6 @@ static int cmd_link_mon_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { int size; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *attrs; if (cmdl->argc != cmdl->optind + 1) { @@ -797,7 +788,7 @@ static int cmd_link_mon_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, } size = atoi(shift_cmdl(cmdl)); - nlh = msg_init(buf, TIPC_NL_MON_SET); + nlh = msg_init(TIPC_NL_MON_SET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -841,7 +832,6 @@ static int link_mon_summary_cb(const struct nlmsghdr *nlh, void *data) static int cmd_link_mon_summary(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; int err = 0; if (help_flag) { @@ -849,7 +839,7 @@ static int cmd_link_mon_summary(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - nlh = msg_init(buf, TIPC_NL_MON_GET); + nlh = msg_init(TIPC_NL_MON_GET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -1004,11 +994,10 @@ exit: static int link_mon_peer_list(uint32_t mon_ref) { struct nlmsghdr *nlh; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *nest; int err = 0; - nlh = msg_init(buf, TIPC_NL_MON_PEER_GET); + nlh = msg_init(TIPC_NL_MON_PEER_GET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -1080,7 +1069,6 @@ static void cmd_link_mon_list_udp_help(struct cmdl *cmdl, char *media) static int cmd_link_mon_list(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; char bname[TIPC_MAX_BEARER_NAME] = {0}; struct opt opts[] = { { "media", OPT_KEYVAL, NULL }, @@ -1112,7 +1100,7 @@ static int cmd_link_mon_list(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - nlh = msg_init(buf, TIPC_NL_MON_GET); + nlh = msg_init(TIPC_NL_MON_GET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -1176,9 +1164,8 @@ static int link_mon_get_cb(const struct nlmsghdr *nlh, void *data) static int cmd_link_mon_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; - nlh = msg_init(buf, TIPC_NL_MON_GET); + nlh = msg_init(TIPC_NL_MON_GET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; diff --git a/tipc/media.c b/tipc/media.c index 969ef6578b3b..a3fec681cbf4 100644 --- a/tipc/media.c +++ b/tipc/media.c @@ -15,9 +15,7 @@ #include <errno.h> #include <linux/tipc_netlink.h> -#include <linux/tipc.h> #include <linux/genetlink.h> -#include <libmnl/libmnl.h> #include "cmdl.h" #include "msg.h" @@ -45,14 +43,13 @@ static int media_list_cb(const struct nlmsghdr *nlh, void *data) static int cmd_media_list(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; - if (help_flag) { fprintf(stderr, "Usage: %s media list\n", cmdl->argv[0]); return -EINVAL; } - if (!(nlh = msg_init(buf, TIPC_NL_MEDIA_GET))) { + nlh = msg_init(TIPC_NL_MEDIA_GET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } @@ -89,7 +86,6 @@ static int cmd_media_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { int prop; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *nest; struct opt *opt; struct opt opts[] = { @@ -116,7 +112,8 @@ static int cmd_media_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, if (parse_opts(opts, cmdl) < 0) return -EINVAL; - if (!(nlh = msg_init(buf, TIPC_NL_MEDIA_GET))) { + nlh = msg_init(TIPC_NL_MEDIA_GET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } @@ -179,7 +176,6 @@ static int cmd_media_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, { int val; int prop; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *props; struct nlattr *attrs; struct opt *opt; @@ -213,7 +209,8 @@ static int cmd_media_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, if (parse_opts(opts, cmdl) < 0) return -EINVAL; - if (!(nlh = msg_init(buf, TIPC_NL_MEDIA_SET))) { + nlh = msg_init(TIPC_NL_MEDIA_SET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } diff --git a/tipc/msg.c b/tipc/msg.c index dc09d05048f3..1225691c9a81 100644 --- a/tipc/msg.c +++ b/tipc/msg.c @@ -13,13 +13,13 @@ #include <time.h> #include <errno.h> -#include <linux/tipc_netlink.h> -#include <linux/tipc.h> -#include <linux/genetlink.h> #include <libmnl/libmnl.h> +#include "mnl_utils.h" #include "msg.h" +extern struct mnlu_gen_socket tipc_nlg; + int parse_attrs(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; @@ -30,141 +30,23 @@ int parse_attrs(const struct nlattr *attr, void *data) return MNL_CB_OK; } -static int family_id_cb(const struct nlmsghdr *nlh, void *data) -{ - struct nlattr *tb[CTRL_ATTR_MAX + 1] = {}; - struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh); - int *id = data; - - mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, tb); - if (!tb[CTRL_ATTR_FAMILY_ID]) - return MNL_CB_ERROR; - - *id = mnl_attr_get_u16(tb[CTRL_ATTR_FAMILY_ID]); - - return MNL_CB_OK; -} - -static struct mnl_socket *msg_send(struct nlmsghdr *nlh) -{ - int ret; - struct mnl_socket *nl; - - nl = mnl_socket_open(NETLINK_GENERIC); - if (nl == NULL) { - perror("mnl_socket_open"); - return NULL; - } - - ret = mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID); - if (ret < 0) { - perror("mnl_socket_bind"); - return NULL; - } - - ret = mnl_socket_sendto(nl, nlh, nlh->nlmsg_len); - if (ret < 0) { - perror("mnl_socket_send"); - return NULL; - } - - return nl; -} - -static int msg_recv(struct mnl_socket *nl, mnl_cb_t callback, void *data, int seq) -{ - int ret; - unsigned int portid; - char buf[MNL_SOCKET_BUFFER_SIZE]; - - portid = mnl_socket_get_portid(nl); - - ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); - while (ret > 0) { - ret = mnl_cb_run(buf, ret, seq, portid, callback, data); - if (ret <= 0) - break; - ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); - } - if (ret == -1) - perror("error"); - - mnl_socket_close(nl); - - return ret; -} - -static int msg_query(struct nlmsghdr *nlh, mnl_cb_t callback, void *data) -{ - unsigned int seq; - struct mnl_socket *nl; - - seq = time(NULL); - nlh->nlmsg_seq = seq; - - nl = msg_send(nlh); - if (!nl) - return -ENOTSUP; - - return msg_recv(nl, callback, data, seq); -} - -static int get_family(void) -{ - int err; - int nl_family; - struct nlmsghdr *nlh; - struct genlmsghdr *genl; - char buf[MNL_SOCKET_BUFFER_SIZE]; - - nlh = mnl_nlmsg_put_header(buf); - nlh->nlmsg_type = GENL_ID_CTRL; - nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; - - genl = mnl_nlmsg_put_extra_header(nlh, sizeof(struct genlmsghdr)); - genl->cmd = CTRL_CMD_GETFAMILY; - genl->version = 1; - - mnl_attr_put_u16(nlh, CTRL_ATTR_FAMILY_ID, GENL_ID_CTRL); - mnl_attr_put_strz(nlh, CTRL_ATTR_FAMILY_NAME, TIPC_GENL_V2_NAME); - - if ((err = msg_query(nlh, family_id_cb, &nl_family))) - return err; - - return nl_family; -} - int msg_doit(struct nlmsghdr *nlh, mnl_cb_t callback, void *data) { nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; - return msg_query(nlh, callback, data); + return mnlu_gen_socket_sndrcv(&tipc_nlg, nlh, callback, data); } int msg_dumpit(struct nlmsghdr *nlh, mnl_cb_t callback, void *data) { nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP; - return msg_query(nlh, callback, data); + return mnlu_gen_socket_sndrcv(&tipc_nlg, nlh, callback, data); } -struct nlmsghdr *msg_init(char *buf, int cmd) +struct nlmsghdr *msg_init(int cmd) { - int family; struct nlmsghdr *nlh; - struct genlmsghdr *genl; - - family = get_family(); - if (family <= 0) { - fprintf(stderr, - "Unable to get TIPC nl family id (module loaded?)\n"); - return NULL; - } - - nlh = mnl_nlmsg_put_header(buf); - nlh->nlmsg_type = family; - genl = mnl_nlmsg_put_extra_header(nlh, sizeof(struct genlmsghdr)); - genl->cmd = cmd; - genl->version = 1; + nlh = mnlu_gen_socket_cmd_prepare(&tipc_nlg, cmd, 0); return nlh; } diff --git a/tipc/msg.h b/tipc/msg.h index 41fd1ad1403a..56af5a705fb9 100644 --- a/tipc/msg.h +++ b/tipc/msg.h @@ -12,7 +12,7 @@ #ifndef _TIPC_MSG_H #define _TIPC_MSG_H -struct nlmsghdr *msg_init(char *buf, int cmd); +struct nlmsghdr *msg_init(int cmd); int msg_doit(struct nlmsghdr *nlh, mnl_cb_t callback, void *data); int msg_dumpit(struct nlmsghdr *nlh, mnl_cb_t callback, void *data); int parse_attrs(const struct nlattr *attr, void *data); diff --git a/tipc/nametable.c b/tipc/nametable.c index d899eeb67c07..b09ed5fc7280 100644 --- a/tipc/nametable.c +++ b/tipc/nametable.c @@ -15,7 +15,6 @@ #include <linux/tipc_netlink.h> #include <linux/tipc.h> #include <linux/genetlink.h> -#include <libmnl/libmnl.h> #include "cmdl.h" #include "msg.h" @@ -82,7 +81,6 @@ static int cmd_nametable_show(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { int iteration = 0; - char buf[MNL_SOCKET_BUFFER_SIZE]; int rc = 0; if (help_flag) { @@ -90,7 +88,8 @@ static int cmd_nametable_show(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - if (!(nlh = msg_init(buf, TIPC_NL_NAME_TABLE_GET))) { + nlh = msg_init(TIPC_NL_NAME_TABLE_GET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } diff --git a/tipc/node.c b/tipc/node.c index 05246013487f..ae75bfff7d2f 100644 --- a/tipc/node.c +++ b/tipc/node.c @@ -17,7 +17,6 @@ #include <linux/tipc_netlink.h> #include <linux/tipc.h> #include <linux/genetlink.h> -#include <libmnl/libmnl.h> #include "cmdl.h" #include "msg.h" @@ -52,14 +51,13 @@ static int node_list_cb(const struct nlmsghdr *nlh, void *data) static int cmd_node_list(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; - if (help_flag) { fprintf(stderr, "Usage: %s node list\n", cmdl->argv[0]); return -EINVAL; } - if (!(nlh = msg_init(buf, TIPC_NL_NODE_GET))) { + nlh = msg_init(TIPC_NL_NODE_GET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } @@ -73,7 +71,6 @@ static int cmd_node_set_addr(struct nlmsghdr *nlh, const struct cmd *cmd, char *str; uint32_t addr; struct nlattr *nest; - char buf[MNL_SOCKET_BUFFER_SIZE]; if (cmdl->argc != cmdl->optind + 1) { fprintf(stderr, "Usage: %s node set address ADDRESS\n", @@ -86,7 +83,8 @@ static int cmd_node_set_addr(struct nlmsghdr *nlh, const struct cmd *cmd, if (!addr) return -1; - if (!(nlh = msg_init(buf, TIPC_NL_NET_SET))) { + nlh = msg_init(TIPC_NL_NET_SET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } @@ -126,7 +124,6 @@ static int cmd_node_get_addr(struct nlmsghdr *nlh, const struct cmd *cmd, static int cmd_node_set_nodeid(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; uint8_t id[16] = {0,}; uint64_t *w0 = (uint64_t *) &id[0]; uint64_t *w1 = (uint64_t *) &id[8]; @@ -145,7 +142,7 @@ static int cmd_node_set_nodeid(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - nlh = msg_init(buf, TIPC_NL_NET_SET); + nlh = msg_init(TIPC_NL_NET_SET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -201,7 +198,6 @@ static int cmd_node_set_key(struct nlmsghdr *nlh, const struct cmd *cmd, }; struct nlattr *nest; struct opt *opt_algname, *opt_nodeid, *opt_master, *opt_rekeying; - char buf[MNL_SOCKET_BUFFER_SIZE]; uint8_t id[TIPC_NODEID_LEN] = {0,}; uint32_t rekeying = 0; bool has_key = false; @@ -262,7 +258,7 @@ get_ops: } /* Init & do the command */ - nlh = msg_init(buf, TIPC_NL_KEY_SET); + nlh = msg_init(TIPC_NL_KEY_SET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -287,15 +283,13 @@ get_ops: static int cmd_node_flush_key(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; - if (help_flag) { (cmd->help)(cmdl); return -EINVAL; } /* Init & do the command */ - nlh = msg_init(buf, TIPC_NL_KEY_FLUSH); + nlh = msg_init(TIPC_NL_KEY_FLUSH); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -332,14 +326,12 @@ static int nodeid_get_cb(const struct nlmsghdr *nlh, void *data) static int cmd_node_get_nodeid(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; - if (help_flag) { (cmd->help)(cmdl); return -EINVAL; } - nlh = msg_init(buf, TIPC_NL_NET_GET); + nlh = msg_init(TIPC_NL_NET_GET); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -370,14 +362,13 @@ static int netid_get_cb(const struct nlmsghdr *nlh, void *data) static int cmd_node_get_netid(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; - if (help_flag) { (cmd->help)(cmdl); return -EINVAL; } - if (!(nlh = msg_init(buf, TIPC_NL_NET_GET))) { + nlh = msg_init(TIPC_NL_NET_GET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } @@ -389,7 +380,6 @@ static int cmd_node_set_netid(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { int netid; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *nest; if (help_flag) { @@ -397,7 +387,8 @@ static int cmd_node_set_netid(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - if (!(nlh = msg_init(buf, TIPC_NL_NET_SET))) { + nlh = msg_init(TIPC_NL_NET_SET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } diff --git a/tipc/peer.c b/tipc/peer.c index f14ec35e6f71..ed18efc552fa 100644 --- a/tipc/peer.c +++ b/tipc/peer.c @@ -17,7 +17,6 @@ #include <linux/tipc_netlink.h> #include <linux/tipc.h> #include <linux/genetlink.h> -#include <libmnl/libmnl.h> #include "cmdl.h" #include "msg.h" @@ -30,7 +29,6 @@ static int cmd_peer_rm_addr(struct nlmsghdr *nlh, const struct cmd *cmd, char *str; uint32_t addr; struct nlattr *nest; - char buf[MNL_SOCKET_BUFFER_SIZE]; if ((cmdl->argc != cmdl->optind + 1) || help_flag) { fprintf(stderr, "Usage: %s peer remove address ADDRESS\n", @@ -47,7 +45,8 @@ static int cmd_peer_rm_addr(struct nlmsghdr *nlh, const struct cmd *cmd, if (!addr) return -1; - if (!(nlh = msg_init(buf, TIPC_NL_PEER_REMOVE))) { + nlh = msg_init(TIPC_NL_PEER_REMOVE); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } @@ -62,7 +61,6 @@ static int cmd_peer_rm_addr(struct nlmsghdr *nlh, const struct cmd *cmd, static int cmd_peer_rm_nodeid(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; __u8 id[16] = {0,}; __u64 *w0 = (__u64 *)&id[0]; __u64 *w1 = (__u64 *)&id[8]; @@ -81,7 +79,7 @@ static int cmd_peer_rm_nodeid(struct nlmsghdr *nlh, const struct cmd *cmd, return -EINVAL; } - nlh = msg_init(buf, TIPC_NL_PEER_REMOVE); + nlh = msg_init(TIPC_NL_PEER_REMOVE); if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; diff --git a/tipc/socket.c b/tipc/socket.c index 852984ecd1e7..deae12af4409 100644 --- a/tipc/socket.c +++ b/tipc/socket.c @@ -15,7 +15,6 @@ #include <linux/tipc.h> #include <linux/tipc_netlink.h> #include <linux/genetlink.h> -#include <libmnl/libmnl.h> #include "cmdl.h" #include "msg.h" @@ -46,10 +45,10 @@ static int publ_list_cb(const struct nlmsghdr *nlh, void *data) static int publ_list(uint32_t sock) { struct nlmsghdr *nlh; - char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlattr *nest; - if (!(nlh = msg_init(buf, TIPC_NL_PUBL_GET))) { + nlh = msg_init(TIPC_NL_PUBL_GET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } @@ -103,14 +102,13 @@ static int sock_list_cb(const struct nlmsghdr *nlh, void *data) static int cmd_socket_list(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { - char buf[MNL_SOCKET_BUFFER_SIZE]; - if (help_flag) { fprintf(stderr, "Usage: %s socket list\n", cmdl->argv[0]); return -EINVAL; } - if (!(nlh = msg_init(buf, TIPC_NL_SOCK_GET))) { + nlh = msg_init(TIPC_NL_SOCK_GET); + if (!nlh) { fprintf(stderr, "error, message initialisation failed\n"); return -1; } diff --git a/tipc/tipc.c b/tipc/tipc.c index 60176a044f8d..9f23a4bfd25d 100644 --- a/tipc/tipc.c +++ b/tipc/tipc.c @@ -13,7 +13,11 @@ #include <stdlib.h> #include <getopt.h> #include <unistd.h> +#include <linux/tipc_netlink.h> +#include <libmnl/libmnl.h> +#include <errno.h> +#include "mnl_utils.h" #include "bearer.h" #include "link.h" #include "nametable.h" @@ -26,6 +30,7 @@ int help_flag; int json; +struct mnlu_gen_socket tipc_nlg; static void about(struct cmdl *cmdl) { @@ -110,8 +115,20 @@ int main(int argc, char *argv[]) cmdl.argc = argc; cmdl.argv = argv; - if ((res = run_cmd(NULL, &cmd, cmds, &cmdl, NULL)) != 0) - return 1; + res = mnlu_gen_socket_open(&tipc_nlg, TIPC_GENL_V2_NAME, + TIPC_GENL_V2_VERSION); + if (res) { + fprintf(stderr, + "Unable to get TIPC nl family id (module loaded?)\n"); + return -1; + } + res = run_cmd(NULL, &cmd, cmds, &cmdl, &tipc_nlg); + if (res != 0) { + mnlu_gen_socket_close(&tipc_nlg); + return -1; + } + + mnlu_gen_socket_close(&tipc_nlg); return 0; } -- 2.25.1 |
From: Hoang Le <hoa...@de...> - 2021-03-29 10:18:32
|
When enabling a bearer with identify by name, we don't sanity check its name with higher slot in bearer list. This lead to duplicate bearer names bypassed the check. To fix the above issue, we just perform an extra checking with all existing bearers. Fixes: cb30a63384bc9 ("tipc: refactor function tipc_enable_bearer()") Signed-off-by: Hoang Le <hoa...@de...> --- net/tipc/bearer.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index d47e0b940ac9..6fae68f0e654 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c @@ -256,6 +256,7 @@ static int tipc_enable_bearer(struct net *net, const char *name, int bearer_id = 0; int res = -EINVAL; char *errstr = ""; + u32 i; if (!bearer_name_validate(name, &b_names)) { errstr = "illegal name"; @@ -313,6 +314,18 @@ static int tipc_enable_bearer(struct net *net, const char *name, goto rejected; } + /* Check new bearer from free slot up to MAX_BEARERS */ + for (i = bearer_id + 1; i <= MAX_BEARERS; ++i) { + b = rtnl_dereference(tn->bearer_list[i]); + if (!b) + continue; + if (!strcmp(name, b->name)) { + errstr = "already enabled"; + NL_SET_ERR_MSG(extack, "Already enabled"); + goto rejected; + } + } + b = kzalloc(sizeof(*b), GFP_ATOMIC); if (!b) return -ENOMEM; -- 2.25.1 |
From: Hoang Le <hoa...@de...> - 2021-03-26 09:14:50
|
Fix kernel-doc warning introduced in commit b83e214b2e04 ("tipc: add extack messages for bearer/media failure"): net/tipc/bearer.c:248: warning: Function parameter or member 'extack' not described in 'tipc_enable_bearer' Fixes: b83e214b2e04 ("tipc: add extack messages for bearer/media failure") Signed-off-by: Hoang Le <hoa...@de...> --- net/tipc/bearer.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index 1090f21fcfac..d47e0b940ac9 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c @@ -240,6 +240,7 @@ void tipc_bearer_remove_dest(struct net *net, u32 bearer_id, u32 dest) * @disc_domain: bearer domain * @prio: bearer priority * @attr: nlattr array + * @extack: netlink extended ack */ static int tipc_enable_bearer(struct net *net, const char *name, u32 disc_domain, u32 prio, -- 2.25.1 |
From: <jm...@re...> - 2021-03-25 15:56:54
|
From: Jon Maloy <jm...@re...> We refactor tipc_sk_anc_data_recv() to make it slighltly more comprehensible, but also to facilitate application of some additions to the code in a future commit. Signed-off-by: Jon Maloy <jm...@re...> --- net/tipc/socket.c | 85 +++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 47 deletions(-) diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 12a97755bc80..358d1f2494a7 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c @@ -1730,67 +1730,58 @@ static void tipc_sk_set_orig_addr(struct msghdr *m, struct sk_buff *skb) static int tipc_sk_anc_data_recv(struct msghdr *m, struct sk_buff *skb, struct tipc_sock *tsk) { - struct tipc_msg *msg; - u32 anc_data[3]; - u32 err; - u32 dest_type; - int has_name; - int res; + struct tipc_msg *hdr; + bool has_addr; + int data[12]; + int dlen, rc; if (likely(m->msg_controllen == 0)) return 0; - msg = buf_msg(skb); - /* Optionally capture errored message object(s) */ - err = msg ? msg_errcode(msg) : 0; - if (unlikely(err)) { - anc_data[0] = err; - anc_data[1] = msg_data_sz(msg); - res = put_cmsg(m, SOL_TIPC, TIPC_ERRINFO, 8, anc_data); - if (res) - return res; - if (anc_data[1]) { - if (skb_linearize(skb)) - return -ENOMEM; - msg = buf_msg(skb); - res = put_cmsg(m, SOL_TIPC, TIPC_RETDATA, anc_data[1], - msg_data(msg)); - if (res) - return res; - } + hdr = buf_msg(skb); + dlen = msg_data_sz(hdr); + + /* Capture errored message object, if any */ + if (msg_errcode(hdr)) { + if (skb_linearize(skb)) + return -ENOMEM; + hdr = buf_msg(skb); + data[0] = msg_errcode(hdr); + data[1] = dlen; + rc = put_cmsg(m, SOL_TIPC, TIPC_ERRINFO, 8, data); + if (rc || !dlen) + return rc; + rc = put_cmsg(m, SOL_TIPC, TIPC_RETDATA, dlen, msg_data(hdr)); + if (rc) + return rc; } - /* Optionally capture message destination object */ - dest_type = msg ? msg_type(msg) : TIPC_DIRECT_MSG; - switch (dest_type) { + /* Capture TIPC_SERVICE_ADDR/RANGE destination address, if any */ + switch (msg_type(hdr)) { case TIPC_NAMED_MSG: - has_name = 1; - anc_data[0] = msg_nametype(msg); - anc_data[1] = msg_namelower(msg); - anc_data[2] = msg_namelower(msg); + has_addr = true; + data[0] = msg_nametype(hdr); + data[1] = msg_namelower(hdr); + data[2] = data[1]; break; case TIPC_MCAST_MSG: - has_name = 1; - anc_data[0] = msg_nametype(msg); - anc_data[1] = msg_namelower(msg); - anc_data[2] = msg_nameupper(msg); + has_addr = true; + data[0] = msg_nametype(hdr); + data[1] = msg_namelower(hdr); + data[2] = msg_nameupper(hdr); break; case TIPC_CONN_MSG: - has_name = !!tsk->conn_addrtype; - anc_data[0] = msg_nametype(&tsk->phdr); - anc_data[1] = msg_nameinst(&tsk->phdr); - anc_data[2] = anc_data[1]; + has_addr = !!tsk->conn_addrtype; + data[0] = msg_nametype(&tsk->phdr); + data[1] = msg_nameinst(&tsk->phdr); + data[2] = data[1]; break; default: - has_name = 0; - } - if (has_name) { - res = put_cmsg(m, SOL_TIPC, TIPC_DESTNAME, 12, anc_data); - if (res) - return res; + has_addr = false; } - - return 0; + if (!has_addr) + return 0; + return put_cmsg(m, SOL_TIPC, TIPC_DESTNAME, 12, data); } static struct sk_buff *tipc_sk_build_ack(struct tipc_sock *tsk) -- 2.29.2 |
From: <jm...@re...> - 2021-03-25 15:56:54
|
From: Jon Maloy <jm...@re...> We eliminate the redundant fields conn_type and conn_instance in struct tipc_sock. On the connecting side, this information is already present in the unused (after the connection is established) part of the pre-allocated header, and on the accepting side, we put it there when the new socket is created. Signed-off-by: Jon Maloy <jm...@re...> --- net/tipc/socket.c | 53 ++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/net/tipc/socket.c b/net/tipc/socket.c index f21162aa0cf7..12a97755bc80 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c @@ -73,9 +73,6 @@ struct sockaddr_pair { /** * struct tipc_sock - TIPC socket structure * @sk: socket - interacts with 'port' and with user via the socket API - * @conn_type: TIPC type used when connection was established - * @conn_instance: TIPC instance used when connection was established - * @published: non-zero if port has one or more associated names * @max_pkt: maximum packet size "hint" used when building messages sent by port * @maxnagle: maximum size of msg which can be subject to nagle * @portid: unique port identity in TIPC socket hash table @@ -106,11 +103,11 @@ struct sockaddr_pair { * @expect_ack: whether this TIPC socket is expecting an ack * @nodelay: setsockopt() TIPC_NODELAY setting * @group_is_open: TIPC socket group is fully open (FIXME) + * @published: true if port has one or more associated names + * @conn_addrtype: address type used when establishing connection */ struct tipc_sock { struct sock sk; - u32 conn_type; - u32 conn_instance; u32 max_pkt; u32 maxnagle; u32 portid; @@ -141,6 +138,7 @@ struct tipc_sock { bool nodelay; bool group_is_open; bool published; + u8 conn_addrtype; }; static int tipc_sk_backlog_rcv(struct sock *sk, struct sk_buff *skb); @@ -1460,10 +1458,8 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dlen) return -EISCONN; if (tsk->published) return -EOPNOTSUPP; - if (atype == TIPC_SERVICE_ADDR) { - tsk->conn_type = ua->sa.type; - tsk->conn_instance = ua->sa.instance; - } + if (atype == TIPC_SERVICE_ADDR) + tsk->conn_addrtype = atype; msg_set_syn(hdr, 1); } @@ -1780,10 +1776,10 @@ static int tipc_sk_anc_data_recv(struct msghdr *m, struct sk_buff *skb, anc_data[2] = msg_nameupper(msg); break; case TIPC_CONN_MSG: - has_name = (tsk->conn_type != 0); - anc_data[0] = tsk->conn_type; - anc_data[1] = tsk->conn_instance; - anc_data[2] = tsk->conn_instance; + has_name = !!tsk->conn_addrtype; + anc_data[0] = msg_nametype(&tsk->phdr); + anc_data[1] = msg_nameinst(&tsk->phdr); + anc_data[2] = anc_data[1]; break; default: has_name = 0; @@ -2747,8 +2743,9 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags, tsk_set_importance(new_sk, msg_importance(msg)); if (msg_named(msg)) { - new_tsock->conn_type = msg_nametype(msg); - new_tsock->conn_instance = msg_nameinst(msg); + new_tsock->conn_addrtype = TIPC_SERVICE_ADDR; + msg_set_nametype(&new_tsock->phdr, msg_nametype(msg)); + msg_set_nameinst(&new_tsock->phdr, msg_nameinst(msg)); } /* @@ -3452,13 +3449,14 @@ void tipc_socket_stop(void) /* Caller should hold socket lock for the passed tipc socket. */ static int __tipc_nl_add_sk_con(struct sk_buff *skb, struct tipc_sock *tsk) { - u32 peer_node; - u32 peer_port; + u32 peer_node, peer_port; + u32 conn_type, conn_instance; struct nlattr *nest; peer_node = tsk_peer_node(tsk); peer_port = tsk_peer_port(tsk); - + conn_type = msg_nametype(&tsk->phdr); + conn_instance = msg_nameinst(&tsk->phdr); nest = nla_nest_start_noflag(skb, TIPC_NLA_SOCK_CON); if (!nest) return -EMSGSIZE; @@ -3468,12 +3466,12 @@ static int __tipc_nl_add_sk_con(struct sk_buff *skb, struct tipc_sock *tsk) if (nla_put_u32(skb, TIPC_NLA_CON_SOCK, peer_port)) goto msg_full; - if (tsk->conn_type != 0) { + if (tsk->conn_addrtype != 0) { if (nla_put_flag(skb, TIPC_NLA_CON_FLAG)) goto msg_full; - if (nla_put_u32(skb, TIPC_NLA_CON_TYPE, tsk->conn_type)) + if (nla_put_u32(skb, TIPC_NLA_CON_TYPE, conn_type)) goto msg_full; - if (nla_put_u32(skb, TIPC_NLA_CON_INST, tsk->conn_instance)) + if (nla_put_u32(skb, TIPC_NLA_CON_INST, conn_instance)) goto msg_full; } nla_nest_end(skb, nest); @@ -3863,9 +3861,9 @@ bool tipc_sk_filtering(struct sock *sk) } if (!tipc_sk_type_connectionless(sk)) { - type = tsk->conn_type; - lower = tsk->conn_instance; - upper = tsk->conn_instance; + type = msg_nametype(&tsk->phdr); + lower = msg_nameinst(&tsk->phdr); + upper = lower; } if ((_type && _type != type) || (_lower && _lower != lower) || @@ -3930,6 +3928,7 @@ int tipc_sk_dump(struct sock *sk, u16 dqueues, char *buf) { int i = 0; size_t sz = (dqueues) ? SK_LMAX : SK_LMIN; + u32 conn_type, conn_instance; struct tipc_sock *tsk; struct publication *p; bool tsk_connected; @@ -3950,8 +3949,10 @@ int tipc_sk_dump(struct sock *sk, u16 dqueues, char *buf) if (tsk_connected) { i += scnprintf(buf + i, sz - i, " %x", tsk_peer_node(tsk)); i += scnprintf(buf + i, sz - i, " %u", tsk_peer_port(tsk)); - i += scnprintf(buf + i, sz - i, " %u", tsk->conn_type); - i += scnprintf(buf + i, sz - i, " %u", tsk->conn_instance); + conn_type = msg_nametype(&tsk->phdr); + conn_instance = msg_nameinst(&tsk->phdr); + i += scnprintf(buf + i, sz - i, " %u", conn_type); + i += scnprintf(buf + i, sz - i, " %u", conn_instance); } i += scnprintf(buf + i, sz - i, " | %u", tsk->published); if (tsk->published) { -- 2.29.2 |
From: <jm...@re...> - 2021-03-25 15:56:50
|
From: Jon Maloy <jm...@re...> We introduce a new macro TIPC_ANY_SCOPE to make the handling of the lookup scope value more comprehensible during multicast reception. The (unchanged) rules go as follows: 1) Multicast messages sent from own node are delivered to all matching sockets on the own node, irrespective of their binding scope. 2) Multicast messages sent from other nodes arrive here because they have found TIPC_CLUSTER_SCOPE bindings emanating from this node. Those messages should be delivered to exactly those sockets, but not to local sockets bound with TIPC_NODE_SCOPE, since the latter obviously were not meant to be visible for those senders. 3) Group multicast/broadcast messages are delivered to the sockets with a binding scope matching exactly the lookup scope indicated in the message header, and nobody else. Signed-off-by: Jon Maloy <jm...@re...> --- net/tipc/name_table.c | 6 +++--- net/tipc/name_table.h | 4 +++- net/tipc/socket.c | 19 +++++++------------ 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c index 6db9f9e7c0ac..86007bcaf47c 100644 --- a/net/tipc/name_table.c +++ b/net/tipc/name_table.c @@ -671,12 +671,12 @@ bool tipc_nametbl_lookup_group(struct net *net, struct tipc_uaddr *ua, * Returns a list of local sockets */ void tipc_nametbl_lookup_mcast_sockets(struct net *net, struct tipc_uaddr *ua, - bool exact, struct list_head *dports) + struct list_head *dports) { struct service_range *sr; struct tipc_service *sc; struct publication *p; - u32 scope = ua->scope; + u8 scope = ua->scope; rcu_read_lock(); sc = tipc_service_find(net, ua); @@ -686,7 +686,7 @@ void tipc_nametbl_lookup_mcast_sockets(struct net *net, struct tipc_uaddr *ua, spin_lock_bh(&sc->lock); service_range_foreach_match(sr, sc, ua->sr.lower, ua->sr.upper) { list_for_each_entry(p, &sr->local_publ, local_publ) { - if (p->scope == scope || (!exact && p->scope < scope)) + if (scope == p->scope || scope == TIPC_ANY_SCOPE) tipc_dest_push(dports, 0, p->sk.ref); } } diff --git a/net/tipc/name_table.h b/net/tipc/name_table.h index c7c9a3ddd420..148b0f640959 100644 --- a/net/tipc/name_table.h +++ b/net/tipc/name_table.h @@ -51,6 +51,8 @@ struct tipc_uaddr; #define TIPC_PUBL_SCOPE_NUM (TIPC_NODE_SCOPE + 1) #define TIPC_NAMETBL_SIZE 1024 /* must be a power of 2 */ +#define TIPC_ANY_SCOPE 255 + /** * struct publication - info about a published service address or range * @sr: service range represented by this publication @@ -113,7 +115,7 @@ int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb); bool tipc_nametbl_lookup_anycast(struct net *net, struct tipc_uaddr *ua, struct tipc_socket_addr *sk); void tipc_nametbl_lookup_mcast_sockets(struct net *net, struct tipc_uaddr *ua, - bool exact, struct list_head *dports); + struct list_head *dports); void tipc_nametbl_lookup_mcast_nodes(struct net *net, struct tipc_uaddr *ua, struct tipc_nlist *nodes); bool tipc_nametbl_lookup_group(struct net *net, struct tipc_uaddr *ua, diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 358d1f2494a7..c0508f76197b 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c @@ -1200,7 +1200,6 @@ void tipc_sk_mcast_rcv(struct net *net, struct sk_buff_head *arrvq, struct tipc_msg *hdr; struct tipc_uaddr ua; int user, mtyp, hlen; - bool exact; __skb_queue_head_init(&tmpq); INIT_LIST_HEAD(&dports); @@ -1214,6 +1213,12 @@ void tipc_sk_mcast_rcv(struct net *net, struct sk_buff_head *arrvq, hlen = skb_headroom(skb) + msg_hdr_sz(hdr); onode = msg_orignode(hdr); ua.sr.type = msg_nametype(hdr); + ua.sr.lower = msg_namelower(hdr); + ua.sr.upper = msg_nameupper(hdr); + if (onode == self) + ua.scope = TIPC_ANY_SCOPE; + else + ua.scope = TIPC_CLUSTER_SCOPE; if (mtyp == TIPC_GRP_UCAST_MSG || user == GROUP_PROTOCOL) { spin_lock_bh(&inputq->lock); @@ -1231,20 +1236,10 @@ void tipc_sk_mcast_rcv(struct net *net, struct sk_buff_head *arrvq, ua.sr.lower = 0; ua.sr.upper = ~0; ua.scope = msg_lookup_scope(hdr); - exact = true; - } else { - /* TIPC_NODE_SCOPE means "any scope" in this context */ - if (onode == self) - ua.scope = TIPC_NODE_SCOPE; - else - ua.scope = TIPC_CLUSTER_SCOPE; - exact = false; - ua.sr.lower = msg_namelower(hdr); - ua.sr.upper = msg_nameupper(hdr); } /* Create destination port list: */ - tipc_nametbl_lookup_mcast_sockets(net, &ua, exact, &dports); + tipc_nametbl_lookup_mcast_sockets(net, &ua, &dports); /* Clone message per destination */ while (tipc_dest_pop(&dports, NULL, &portid)) { -- 2.29.2 |
From: <jm...@re...> - 2021-03-25 15:56:43
|
From: Jon Maloy <jm...@re...> We fix a couple of warnings and make some minor code cleanups and improvements. Jon Maloy (4): tipc: fix htmldoc and smatch warnings tipc: eliminate redundant fields in struct tipc_sock tipc: refactor function tipc_sk_anc_data_recv() tipc: simplify handling of lookup scope during multicast message reception net/tipc/name_table.c | 6 +- net/tipc/name_table.h | 4 +- net/tipc/socket.c | 151 +++++++++++++++++++----------------------- net/tipc/subscr.h | 3 +- 4 files changed, 77 insertions(+), 87 deletions(-) -- 2.29.2 |
From: <jm...@re...> - 2021-03-25 15:56:41
|
From: Jon Maloy <jm...@re...> We fix a warning from the htmldoc tool and an indentation error reported by smatch. There are no functional changes in this commit. Signed-off-by: Jon Maloy <jm...@re...> --- net/tipc/socket.c | 2 +- net/tipc/subscr.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 117a472a8e61..f21162aa0cf7 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c @@ -1450,7 +1450,7 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dlen) ua = (struct tipc_uaddr *)&tsk->peer; if (!syn && ua->family != AF_TIPC) return -EDESTADDRREQ; - atype = ua->addrtype; + atype = ua->addrtype; } if (unlikely(syn)) { diff --git a/net/tipc/subscr.h b/net/tipc/subscr.h index ddea6554ec46..60b877531b66 100644 --- a/net/tipc/subscr.h +++ b/net/tipc/subscr.h @@ -49,12 +49,13 @@ struct tipc_conn; /** * struct tipc_subscription - TIPC network topology subscription object + * @s: host-endian copy of the user subscription + * @evt: template for events generated by subscription * @kref: reference count for this subscription * @net: network namespace associated with subscription * @timer: timer governing subscription duration (optional) * @service_list: adjacent subscriptions in name sequence's subscription list * @sub_list: adjacent subscriptions in subscriber's subscription list - * @evt: template for events generated by subscription * @conid: connection identifier of topology server * @inactive: true if this subscription is inactive * @lock: serialize up/down and timer events -- 2.29.2 |
From: Hoang H. Le <hoa...@de...> - 2021-03-25 07:25:38
|
> -----Original Message----- > From: David Ahern <ds...@gm...> > Sent: Thursday, March 25, 2021 10:08 AM > To: Hoang Huu Le <hoa...@de...>; ne...@vg...; tip...@li...; > jm...@re...; ma...@do...; yin...@wi...; Tuan Anh Vo <tua...@de...>; Tung Quang > Nguyen <tun...@de...> > Subject: Re: [iproute2-next] tipc: add support for the netlink extack > > On 3/24/21 7:56 PM, Hoang Le wrote: > > Add support extack in tipc to dump the netlink extack error messages > > (i.e -EINVAL) sent from kernel. > > > > Acked-by: Jon Maloy <jm...@re...> > > Signed-off-by: Hoang Le <hoa...@de...> > > --- > > tipc/msg.c | 29 ++++++++++++++++++++++------- > > 1 file changed, 22 insertions(+), 7 deletions(-) > > > > tipc should be converted to use the library functions in lib/mnl_utils.c. It's really a big change. So, we will do in next commit. |
From: David A. <ds...@gm...> - 2021-03-25 03:07:59
|
On 3/24/21 7:56 PM, Hoang Le wrote: > Add support extack in tipc to dump the netlink extack error messages > (i.e -EINVAL) sent from kernel. > > Acked-by: Jon Maloy <jm...@re...> > Signed-off-by: Hoang Le <hoa...@de...> > --- > tipc/msg.c | 29 ++++++++++++++++++++++------- > 1 file changed, 22 insertions(+), 7 deletions(-) > tipc should be converted to use the library functions in lib/mnl_utils.c. |