Commit ae1d9cc3 authored by David S. Miller's avatar David S. Miller

Merge branch 'tipc-cleanups'

Jon Maloy says:

====================
tipc: some small cleanups

We make some minor code cleanups and improvements.

v2: Changed value of TIPC_ANY_SCOPE macro in patch #3
    to avoid compiler warning
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents eda1bc65 5ef21325
...@@ -673,12 +673,12 @@ bool tipc_nametbl_lookup_group(struct net *net, struct tipc_uaddr *ua, ...@@ -673,12 +673,12 @@ bool tipc_nametbl_lookup_group(struct net *net, struct tipc_uaddr *ua,
* Returns a list of local sockets * Returns a list of local sockets
*/ */
void tipc_nametbl_lookup_mcast_sockets(struct net *net, struct tipc_uaddr *ua, 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 service_range *sr;
struct tipc_service *sc; struct tipc_service *sc;
struct publication *p; struct publication *p;
u32 scope = ua->scope; u8 scope = ua->scope;
rcu_read_lock(); rcu_read_lock();
sc = tipc_service_find(net, ua); sc = tipc_service_find(net, ua);
...@@ -688,7 +688,7 @@ void tipc_nametbl_lookup_mcast_sockets(struct net *net, struct tipc_uaddr *ua, ...@@ -688,7 +688,7 @@ void tipc_nametbl_lookup_mcast_sockets(struct net *net, struct tipc_uaddr *ua,
spin_lock_bh(&sc->lock); spin_lock_bh(&sc->lock);
service_range_foreach_match(sr, sc, ua->sr.lower, ua->sr.upper) { service_range_foreach_match(sr, sc, ua->sr.lower, ua->sr.upper) {
list_for_each_entry(p, &sr->local_publ, local_publ) { 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); tipc_dest_push(dports, 0, p->sk.ref);
} }
} }
......
...@@ -51,6 +51,8 @@ struct tipc_uaddr; ...@@ -51,6 +51,8 @@ struct tipc_uaddr;
#define TIPC_PUBL_SCOPE_NUM (TIPC_NODE_SCOPE + 1) #define TIPC_PUBL_SCOPE_NUM (TIPC_NODE_SCOPE + 1)
#define TIPC_NAMETBL_SIZE 1024 /* must be a power of 2 */ #define TIPC_NAMETBL_SIZE 1024 /* must be a power of 2 */
#define TIPC_ANY_SCOPE 10 /* Both node and cluster scope will match */
/** /**
* struct publication - info about a published service address or range * struct publication - info about a published service address or range
* @sr: service range represented by this publication * @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); ...@@ -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, bool tipc_nametbl_lookup_anycast(struct net *net, struct tipc_uaddr *ua,
struct tipc_socket_addr *sk); struct tipc_socket_addr *sk);
void tipc_nametbl_lookup_mcast_sockets(struct net *net, struct tipc_uaddr *ua, 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, void tipc_nametbl_lookup_mcast_nodes(struct net *net, struct tipc_uaddr *ua,
struct tipc_nlist *nodes); struct tipc_nlist *nodes);
bool tipc_nametbl_lookup_group(struct net *net, struct tipc_uaddr *ua, bool tipc_nametbl_lookup_group(struct net *net, struct tipc_uaddr *ua,
......
...@@ -73,9 +73,6 @@ struct sockaddr_pair { ...@@ -73,9 +73,6 @@ struct sockaddr_pair {
/** /**
* struct tipc_sock - TIPC socket structure * struct tipc_sock - TIPC socket structure
* @sk: socket - interacts with 'port' and with user via the socket API * @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 * @max_pkt: maximum packet size "hint" used when building messages sent by port
* @maxnagle: maximum size of msg which can be subject to nagle * @maxnagle: maximum size of msg which can be subject to nagle
* @portid: unique port identity in TIPC socket hash table * @portid: unique port identity in TIPC socket hash table
...@@ -106,11 +103,11 @@ struct sockaddr_pair { ...@@ -106,11 +103,11 @@ struct sockaddr_pair {
* @expect_ack: whether this TIPC socket is expecting an ack * @expect_ack: whether this TIPC socket is expecting an ack
* @nodelay: setsockopt() TIPC_NODELAY setting * @nodelay: setsockopt() TIPC_NODELAY setting
* @group_is_open: TIPC socket group is fully open (FIXME) * @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 tipc_sock {
struct sock sk; struct sock sk;
u32 conn_type;
u32 conn_instance;
u32 max_pkt; u32 max_pkt;
u32 maxnagle; u32 maxnagle;
u32 portid; u32 portid;
...@@ -141,6 +138,7 @@ struct tipc_sock { ...@@ -141,6 +138,7 @@ struct tipc_sock {
bool nodelay; bool nodelay;
bool group_is_open; bool group_is_open;
bool published; bool published;
u8 conn_addrtype;
}; };
static int tipc_sk_backlog_rcv(struct sock *sk, struct sk_buff *skb); static int tipc_sk_backlog_rcv(struct sock *sk, struct sk_buff *skb);
...@@ -1202,12 +1200,12 @@ void tipc_sk_mcast_rcv(struct net *net, struct sk_buff_head *arrvq, ...@@ -1202,12 +1200,12 @@ void tipc_sk_mcast_rcv(struct net *net, struct sk_buff_head *arrvq,
struct tipc_msg *hdr; struct tipc_msg *hdr;
struct tipc_uaddr ua; struct tipc_uaddr ua;
int user, mtyp, hlen; int user, mtyp, hlen;
bool exact;
__skb_queue_head_init(&tmpq); __skb_queue_head_init(&tmpq);
INIT_LIST_HEAD(&dports); INIT_LIST_HEAD(&dports);
ua.addrtype = TIPC_SERVICE_RANGE; ua.addrtype = TIPC_SERVICE_RANGE;
/* tipc_skb_peek() increments the head skb's reference counter */
skb = tipc_skb_peek(arrvq, &inputq->lock); skb = tipc_skb_peek(arrvq, &inputq->lock);
for (; skb; skb = tipc_skb_peek(arrvq, &inputq->lock)) { for (; skb; skb = tipc_skb_peek(arrvq, &inputq->lock)) {
hdr = buf_msg(skb); hdr = buf_msg(skb);
...@@ -1216,6 +1214,12 @@ void tipc_sk_mcast_rcv(struct net *net, struct sk_buff_head *arrvq, ...@@ -1216,6 +1214,12 @@ void tipc_sk_mcast_rcv(struct net *net, struct sk_buff_head *arrvq,
hlen = skb_headroom(skb) + msg_hdr_sz(hdr); hlen = skb_headroom(skb) + msg_hdr_sz(hdr);
onode = msg_orignode(hdr); onode = msg_orignode(hdr);
ua.sr.type = msg_nametype(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) { if (mtyp == TIPC_GRP_UCAST_MSG || user == GROUP_PROTOCOL) {
spin_lock_bh(&inputq->lock); spin_lock_bh(&inputq->lock);
...@@ -1233,20 +1237,10 @@ void tipc_sk_mcast_rcv(struct net *net, struct sk_buff_head *arrvq, ...@@ -1233,20 +1237,10 @@ void tipc_sk_mcast_rcv(struct net *net, struct sk_buff_head *arrvq,
ua.sr.lower = 0; ua.sr.lower = 0;
ua.sr.upper = ~0; ua.sr.upper = ~0;
ua.scope = msg_lookup_scope(hdr); 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: */ /* 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 */ /* Clone message per destination */
while (tipc_dest_pop(&dports, NULL, &portid)) { while (tipc_dest_pop(&dports, NULL, &portid)) {
...@@ -1258,13 +1252,11 @@ void tipc_sk_mcast_rcv(struct net *net, struct sk_buff_head *arrvq, ...@@ -1258,13 +1252,11 @@ void tipc_sk_mcast_rcv(struct net *net, struct sk_buff_head *arrvq,
} }
pr_warn("Failed to clone mcast rcv buffer\n"); pr_warn("Failed to clone mcast rcv buffer\n");
} }
/* Append to inputq if not already done by other thread */ /* Append clones to inputq only if skb is still head of arrvq */
spin_lock_bh(&inputq->lock); spin_lock_bh(&inputq->lock);
if (skb_peek(arrvq) == skb) { if (skb_peek(arrvq) == skb) {
skb_queue_splice_tail_init(&tmpq, inputq); skb_queue_splice_tail_init(&tmpq, inputq);
/* Decrease the skb's refcnt as increasing in the /* Decrement the skb's refcnt */
* function tipc_skb_peek
*/
kfree_skb(__skb_dequeue(arrvq)); kfree_skb(__skb_dequeue(arrvq));
} }
spin_unlock_bh(&inputq->lock); spin_unlock_bh(&inputq->lock);
...@@ -1463,10 +1455,8 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dlen) ...@@ -1463,10 +1455,8 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dlen)
return -EISCONN; return -EISCONN;
if (tsk->published) if (tsk->published)
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (atype == TIPC_SERVICE_ADDR) { if (atype == TIPC_SERVICE_ADDR)
tsk->conn_type = ua->sa.type; tsk->conn_addrtype = atype;
tsk->conn_instance = ua->sa.instance;
}
msg_set_syn(hdr, 1); msg_set_syn(hdr, 1);
} }
...@@ -1737,67 +1727,58 @@ static void tipc_sk_set_orig_addr(struct msghdr *m, struct sk_buff *skb) ...@@ -1737,67 +1727,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, static int tipc_sk_anc_data_recv(struct msghdr *m, struct sk_buff *skb,
struct tipc_sock *tsk) struct tipc_sock *tsk)
{ {
struct tipc_msg *msg; struct tipc_msg *hdr;
u32 anc_data[3]; u32 data[3] = {0,};
u32 err; bool has_addr;
u32 dest_type; int dlen, rc;
int has_name;
int res;
if (likely(m->msg_controllen == 0)) if (likely(m->msg_controllen == 0))
return 0; return 0;
msg = buf_msg(skb);
/* Optionally capture errored message object(s) */ hdr = buf_msg(skb);
err = msg ? msg_errcode(msg) : 0; dlen = msg_data_sz(hdr);
if (unlikely(err)) {
anc_data[0] = err; /* Capture errored message object, if any */
anc_data[1] = msg_data_sz(msg); if (msg_errcode(hdr)) {
res = put_cmsg(m, SOL_TIPC, TIPC_ERRINFO, 8, anc_data); if (skb_linearize(skb))
if (res) return -ENOMEM;
return res; hdr = buf_msg(skb);
if (anc_data[1]) { data[0] = msg_errcode(hdr);
if (skb_linearize(skb)) data[1] = dlen;
return -ENOMEM; rc = put_cmsg(m, SOL_TIPC, TIPC_ERRINFO, 8, data);
msg = buf_msg(skb); if (rc || !dlen)
res = put_cmsg(m, SOL_TIPC, TIPC_RETDATA, anc_data[1], return rc;
msg_data(msg)); rc = put_cmsg(m, SOL_TIPC, TIPC_RETDATA, dlen, msg_data(hdr));
if (res) if (rc)
return res; return rc;
}
} }
/* Optionally capture message destination object */ /* Capture TIPC_SERVICE_ADDR/RANGE destination address, if any */
dest_type = msg ? msg_type(msg) : TIPC_DIRECT_MSG; switch (msg_type(hdr)) {
switch (dest_type) {
case TIPC_NAMED_MSG: case TIPC_NAMED_MSG:
has_name = 1; has_addr = true;
anc_data[0] = msg_nametype(msg); data[0] = msg_nametype(hdr);
anc_data[1] = msg_namelower(msg); data[1] = msg_namelower(hdr);
anc_data[2] = msg_namelower(msg); data[2] = data[1];
break; break;
case TIPC_MCAST_MSG: case TIPC_MCAST_MSG:
has_name = 1; has_addr = true;
anc_data[0] = msg_nametype(msg); data[0] = msg_nametype(hdr);
anc_data[1] = msg_namelower(msg); data[1] = msg_namelower(hdr);
anc_data[2] = msg_nameupper(msg); data[2] = msg_nameupper(hdr);
break; break;
case TIPC_CONN_MSG: case TIPC_CONN_MSG:
has_name = (tsk->conn_type != 0); has_addr = !!tsk->conn_addrtype;
anc_data[0] = tsk->conn_type; data[0] = msg_nametype(&tsk->phdr);
anc_data[1] = tsk->conn_instance; data[1] = msg_nameinst(&tsk->phdr);
anc_data[2] = tsk->conn_instance; data[2] = data[1];
break; break;
default: default:
has_name = 0; has_addr = false;
} }
if (has_name) { if (!has_addr)
res = put_cmsg(m, SOL_TIPC, TIPC_DESTNAME, 12, anc_data); return 0;
if (res) return put_cmsg(m, SOL_TIPC, TIPC_DESTNAME, 12, data);
return res;
}
return 0;
} }
static struct sk_buff *tipc_sk_build_ack(struct tipc_sock *tsk) static struct sk_buff *tipc_sk_build_ack(struct tipc_sock *tsk)
...@@ -2750,8 +2731,9 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags, ...@@ -2750,8 +2731,9 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags,
tsk_set_importance(new_sk, msg_importance(msg)); tsk_set_importance(new_sk, msg_importance(msg));
if (msg_named(msg)) { if (msg_named(msg)) {
new_tsock->conn_type = msg_nametype(msg); new_tsock->conn_addrtype = TIPC_SERVICE_ADDR;
new_tsock->conn_instance = msg_nameinst(msg); msg_set_nametype(&new_tsock->phdr, msg_nametype(msg));
msg_set_nameinst(&new_tsock->phdr, msg_nameinst(msg));
} }
/* /*
...@@ -3455,13 +3437,14 @@ void tipc_socket_stop(void) ...@@ -3455,13 +3437,14 @@ void tipc_socket_stop(void)
/* Caller should hold socket lock for the passed tipc socket. */ /* 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) static int __tipc_nl_add_sk_con(struct sk_buff *skb, struct tipc_sock *tsk)
{ {
u32 peer_node; u32 peer_node, peer_port;
u32 peer_port; u32 conn_type, conn_instance;
struct nlattr *nest; struct nlattr *nest;
peer_node = tsk_peer_node(tsk); peer_node = tsk_peer_node(tsk);
peer_port = tsk_peer_port(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); nest = nla_nest_start_noflag(skb, TIPC_NLA_SOCK_CON);
if (!nest) if (!nest)
return -EMSGSIZE; return -EMSGSIZE;
...@@ -3471,12 +3454,12 @@ static int __tipc_nl_add_sk_con(struct sk_buff *skb, struct tipc_sock *tsk) ...@@ -3471,12 +3454,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)) if (nla_put_u32(skb, TIPC_NLA_CON_SOCK, peer_port))
goto msg_full; goto msg_full;
if (tsk->conn_type != 0) { if (tsk->conn_addrtype != 0) {
if (nla_put_flag(skb, TIPC_NLA_CON_FLAG)) if (nla_put_flag(skb, TIPC_NLA_CON_FLAG))
goto msg_full; 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; 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; goto msg_full;
} }
nla_nest_end(skb, nest); nla_nest_end(skb, nest);
...@@ -3866,9 +3849,9 @@ bool tipc_sk_filtering(struct sock *sk) ...@@ -3866,9 +3849,9 @@ bool tipc_sk_filtering(struct sock *sk)
} }
if (!tipc_sk_type_connectionless(sk)) { if (!tipc_sk_type_connectionless(sk)) {
type = tsk->conn_type; type = msg_nametype(&tsk->phdr);
lower = tsk->conn_instance; lower = msg_nameinst(&tsk->phdr);
upper = tsk->conn_instance; upper = lower;
} }
if ((_type && _type != type) || (_lower && _lower != lower) || if ((_type && _type != type) || (_lower && _lower != lower) ||
...@@ -3933,6 +3916,7 @@ int tipc_sk_dump(struct sock *sk, u16 dqueues, char *buf) ...@@ -3933,6 +3916,7 @@ int tipc_sk_dump(struct sock *sk, u16 dqueues, char *buf)
{ {
int i = 0; int i = 0;
size_t sz = (dqueues) ? SK_LMAX : SK_LMIN; size_t sz = (dqueues) ? SK_LMAX : SK_LMIN;
u32 conn_type, conn_instance;
struct tipc_sock *tsk; struct tipc_sock *tsk;
struct publication *p; struct publication *p;
bool tsk_connected; bool tsk_connected;
...@@ -3953,8 +3937,10 @@ int tipc_sk_dump(struct sock *sk, u16 dqueues, char *buf) ...@@ -3953,8 +3937,10 @@ int tipc_sk_dump(struct sock *sk, u16 dqueues, char *buf)
if (tsk_connected) { if (tsk_connected) {
i += scnprintf(buf + i, sz - i, " %x", tsk_peer_node(tsk)); 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_peer_port(tsk));
i += scnprintf(buf + i, sz - i, " %u", tsk->conn_type); conn_type = msg_nametype(&tsk->phdr);
i += scnprintf(buf + i, sz - i, " %u", tsk->conn_instance); 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); i += scnprintf(buf + i, sz - i, " | %u", tsk->published);
if (tsk->published) { if (tsk->published) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment