Skip to content

Commit ec8a2e5

Browse files
Jon Paul Maloydavem330
authored andcommitted
tipc: same receive code path for connection protocol and data messages
As a preparation to eliminate port_lock we need to bring reception of connection protocol messages under proper protection of bh_lock_sock or socket owner. We fix this by letting those messages follow the same code path as incoming data messages. As a side effect of this change, the last reference to the function net_route_msg() disappears, and we can eliminate that function. Signed-off-by: Jon Maloy <[email protected]> Reviewed-by: Erik Hugne <[email protected]> Reviewed-by: Ying Xue <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b786e2b commit ec8a2e5

File tree

6 files changed

+19
-55
lines changed

6 files changed

+19
-55
lines changed

net/tipc/link.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,7 @@ void tipc_rcv(struct sk_buff *head, struct tipc_bearer *b_ptr)
14791479
case TIPC_MEDIUM_IMPORTANCE:
14801480
case TIPC_HIGH_IMPORTANCE:
14811481
case TIPC_CRITICAL_IMPORTANCE:
1482+
case CONN_MANAGER:
14821483
tipc_node_unlock(n_ptr);
14831484
tipc_sk_rcv(buf);
14841485
continue;
@@ -1493,10 +1494,6 @@ void tipc_rcv(struct sk_buff *head, struct tipc_bearer *b_ptr)
14931494
tipc_node_unlock(n_ptr);
14941495
tipc_named_rcv(buf);
14951496
continue;
1496-
case CONN_MANAGER:
1497-
tipc_node_unlock(n_ptr);
1498-
tipc_port_proto_rcv(buf);
1499-
continue;
15001497
case BCAST_PROTOCOL:
15011498
tipc_link_sync_rcv(n_ptr, buf);
15021499
break;
@@ -2106,15 +2103,24 @@ void tipc_link_bundle_rcv(struct sk_buff *buf)
21062103
u32 msgcount = msg_msgcnt(buf_msg(buf));
21072104
u32 pos = INT_H_SIZE;
21082105
struct sk_buff *obuf;
2106+
struct tipc_msg *omsg;
21092107

21102108
while (msgcount--) {
21112109
obuf = buf_extract(buf, pos);
21122110
if (obuf == NULL) {
21132111
pr_warn("Link unable to unbundle message(s)\n");
21142112
break;
21152113
}
2116-
pos += align(msg_size(buf_msg(obuf)));
2117-
tipc_net_route_msg(obuf);
2114+
omsg = buf_msg(obuf);
2115+
pos += align(msg_size(omsg));
2116+
if (msg_isdata(omsg) || (msg_user(omsg) == CONN_MANAGER)) {
2117+
tipc_sk_rcv(obuf);
2118+
} else if (msg_user(omsg) == NAME_DISTRIBUTOR) {
2119+
tipc_named_rcv(obuf);
2120+
} else {
2121+
pr_warn("Illegal bundled msg: %u\n", msg_user(omsg));
2122+
kfree_skb(obuf);
2123+
}
21182124
}
21192125
kfree_skb(buf);
21202126
}

net/tipc/net.c

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -103,46 +103,6 @@
103103
* This is always used within the scope of a tipc_nametbl_lock(read).
104104
* - A local spin_lock protecting the queue of subscriber events.
105105
*/
106-
void tipc_net_route_msg(struct sk_buff *buf)
107-
{
108-
struct tipc_msg *msg;
109-
u32 dnode;
110-
111-
if (!buf)
112-
return;
113-
msg = buf_msg(buf);
114-
115-
/* Handle message for this node */
116-
dnode = msg_short(msg) ? tipc_own_addr : msg_destnode(msg);
117-
if (tipc_in_scope(dnode, tipc_own_addr)) {
118-
if (msg_isdata(msg)) {
119-
if (msg_mcast(msg))
120-
tipc_port_mcast_rcv(buf, NULL);
121-
else if (msg_destport(msg)) {
122-
tipc_sk_rcv(buf);
123-
} else {
124-
pr_warn("Cannot route msg; no destination\n");
125-
kfree_skb(buf);
126-
}
127-
return;
128-
}
129-
switch (msg_user(msg)) {
130-
case NAME_DISTRIBUTOR:
131-
tipc_named_rcv(buf);
132-
break;
133-
case CONN_MANAGER:
134-
tipc_port_proto_rcv(buf);
135-
break;
136-
default:
137-
kfree_skb(buf);
138-
}
139-
return;
140-
}
141-
142-
/* Handle message for another node */
143-
skb_trim(buf, msg_size(msg));
144-
tipc_link_xmit(buf, dnode, msg_link_selector(msg));
145-
}
146106

147107
int tipc_net_start(u32 addr)
148108
{

net/tipc/net.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
#ifndef _TIPC_NET_H
3838
#define _TIPC_NET_H
3939

40-
void tipc_net_route_msg(struct sk_buff *buf);
41-
4240
int tipc_net_start(u32 addr);
4341
void tipc_net_stop(void);
4442

net/tipc/port.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -365,16 +365,14 @@ static struct sk_buff *port_build_peer_abort_msg(struct tipc_port *p_ptr, u32 er
365365
return buf;
366366
}
367367

368-
void tipc_port_proto_rcv(struct sk_buff *buf)
368+
void tipc_port_proto_rcv(struct tipc_port *p_ptr, struct sk_buff *buf)
369369
{
370370
struct tipc_msg *msg = buf_msg(buf);
371-
struct tipc_port *p_ptr;
372371
struct sk_buff *r_buf = NULL;
373372
u32 destport = msg_destport(msg);
374373
int wakeable;
375374

376375
/* Validate connection */
377-
p_ptr = tipc_port_lock(destport);
378376
if (!p_ptr || !p_ptr->connected || !tipc_port_peer_msg(p_ptr, msg)) {
379377
r_buf = tipc_buf_acquire(BASIC_H_SIZE);
380378
if (r_buf) {
@@ -385,8 +383,6 @@ void tipc_port_proto_rcv(struct sk_buff *buf)
385383
msg_set_origport(msg, destport);
386384
msg_set_destport(msg, msg_origport(msg));
387385
}
388-
if (p_ptr)
389-
tipc_port_unlock(p_ptr);
390386
goto exit;
391387
}
392388

@@ -409,7 +405,6 @@ void tipc_port_proto_rcv(struct sk_buff *buf)
409405
break;
410406
}
411407
p_ptr->probing_state = CONFIRMED;
412-
tipc_port_unlock(p_ptr);
413408
exit:
414409
tipc_link_xmit2(r_buf, msg_destnode(msg), msg_link_selector(msg));
415410
kfree_skb(buf);

net/tipc/port.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ int tipc_port_mcast_xmit(struct tipc_port *port,
140140
unsigned int len);
141141

142142
struct sk_buff *tipc_port_get_ports(void);
143-
void tipc_port_proto_rcv(struct sk_buff *buf);
143+
void tipc_port_proto_rcv(struct tipc_port *port, struct sk_buff *buf);
144144
void tipc_port_mcast_rcv(struct sk_buff *buf, struct tipc_port_list *dp);
145145
void tipc_port_reinit(void);
146146

net/tipc/socket.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,11 @@ static int filter_rcv(struct sock *sk, struct sk_buff *buf)
14161416
unsigned int limit = rcvbuf_limit(sk, buf);
14171417
int rc = TIPC_OK;
14181418

1419+
if (unlikely(msg_user(msg) == CONN_MANAGER)) {
1420+
tipc_port_proto_rcv(&tsk->port, buf);
1421+
return TIPC_OK;
1422+
}
1423+
14191424
/* Reject message if it is wrong sort of message for socket */
14201425
if (msg_type(msg) > TIPC_DIRECT_MSG)
14211426
return -TIPC_ERR_NO_PORT;

0 commit comments

Comments
 (0)