Skip to content

Commit bcd3ffd

Browse files
Jon Paul Maloydavem330
authored andcommitted
tipc: introduce new tipc_sk_respond() function
Currently, we use the code sequence if (msg_reverse()) tipc_link_xmit_skb() at numerous locations in socket.c. The preparation of arguments for these calls, as well as the sequence itself, makes the code unecessarily complex. In this commit, we introduce a new function, tipc_sk_respond(), that performs this call combination. We also replace some, but not yet all, of these explicit call sequences with calls to the new function. Notably, we let the function tipc_sk_proto_rcv() use the new function to directly send out PROBE_REPLY messages, instead of deferring this to the calling tipc_sk_rcv() function, as we do now. Reviewed-by: Ying Xue <[email protected]> Signed-off-by: Jon Maloy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 29042e1 commit bcd3ffd

File tree

3 files changed

+47
-39
lines changed

3 files changed

+47
-39
lines changed

net/tipc/msg.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ bool tipc_msg_make_bundle(struct sk_buff **skb, struct tipc_msg *msg,
469469
* Consumes buffer at failure
470470
* Returns true if success, otherwise false
471471
*/
472-
bool tipc_msg_reverse(u32 own_node, struct sk_buff **skb, u32 *dnode, int err)
472+
bool tipc_msg_reverse(u32 own_node, struct sk_buff **skb, int err)
473473
{
474474
struct sk_buff *_skb = *skb;
475475
struct tipc_msg *hdr = buf_msg(_skb);
@@ -508,7 +508,6 @@ bool tipc_msg_reverse(u32 own_node, struct sk_buff **skb, u32 *dnode, int err)
508508
msg_set_prevnode(hdr, own_node);
509509
msg_set_orignode(hdr, own_node);
510510
msg_set_size(hdr, msg_hdr_sz(hdr) + dlen);
511-
*dnode = msg_destnode(hdr);
512511
skb_trim(_skb, msg_size(hdr));
513512
skb_orphan(_skb);
514513
return true;

net/tipc/msg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ static inline bool msg_peer_is_up(struct tipc_msg *m)
785785

786786
struct sk_buff *tipc_buf_acquire(u32 size);
787787
bool tipc_msg_validate(struct sk_buff *skb);
788-
bool tipc_msg_reverse(u32 own_addr, struct sk_buff **skb, u32 *dnode, int err);
788+
bool tipc_msg_reverse(u32 own_addr, struct sk_buff **skb, int err);
789789
void tipc_msg_init(u32 own_addr, struct tipc_msg *m, u32 user, u32 type,
790790
u32 hsize, u32 destnode);
791791
struct sk_buff *tipc_msg_create(uint user, uint type, uint hdr_sz,

net/tipc/socket.c

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,22 @@ static void tsk_advance_rx_queue(struct sock *sk)
248248
kfree_skb(__skb_dequeue(&sk->sk_receive_queue));
249249
}
250250

251+
/* tipc_sk_respond() : send response message back to sender
252+
*/
253+
static void tipc_sk_respond(struct sock *sk, struct sk_buff *skb, int err)
254+
{
255+
u32 selector;
256+
u32 dnode;
257+
u32 onode = tipc_own_addr(sock_net(sk));
258+
259+
if (!tipc_msg_reverse(onode, &skb, err))
260+
return;
261+
262+
dnode = msg_destnode(buf_msg(skb));
263+
selector = msg_origport(buf_msg(skb));
264+
tipc_node_xmit_skb(sock_net(sk), skb, dnode, selector);
265+
}
266+
251267
/**
252268
* tsk_rej_rx_queue - reject all buffers in socket receive queue
253269
*
@@ -256,13 +272,9 @@ static void tsk_advance_rx_queue(struct sock *sk)
256272
static void tsk_rej_rx_queue(struct sock *sk)
257273
{
258274
struct sk_buff *skb;
259-
u32 dnode;
260-
u32 own_node = tsk_own_node(tipc_sk(sk));
261275

262-
while ((skb = __skb_dequeue(&sk->sk_receive_queue))) {
263-
if (tipc_msg_reverse(own_node, &skb, &dnode, TIPC_ERR_NO_PORT))
264-
tipc_node_xmit_skb(sock_net(sk), skb, dnode, 0);
265-
}
276+
while ((skb = __skb_dequeue(&sk->sk_receive_queue)))
277+
tipc_sk_respond(sk, skb, TIPC_ERR_NO_PORT);
266278
}
267279

268280
/* tsk_peer_msg - verify if message was sent by connected port's peer
@@ -441,9 +453,7 @@ static int tipc_release(struct socket *sock)
441453
tsk->connected = 0;
442454
tipc_node_remove_conn(net, dnode, tsk->portid);
443455
}
444-
if (tipc_msg_reverse(tsk_own_node(tsk), &skb, &dnode,
445-
TIPC_ERR_NO_PORT))
446-
tipc_node_xmit_skb(net, skb, dnode, 0);
456+
tipc_sk_respond(sk, skb, TIPC_ERR_NO_PORT);
447457
}
448458
}
449459

@@ -764,35 +774,35 @@ void tipc_sk_mcast_rcv(struct net *net, struct sk_buff_head *arrvq,
764774
/**
765775
* tipc_sk_proto_rcv - receive a connection mng protocol message
766776
* @tsk: receiving socket
767-
* @skb: pointer to message buffer. Set to NULL if buffer is consumed.
777+
* @skb: pointer to message buffer.
768778
*/
769-
static void tipc_sk_proto_rcv(struct tipc_sock *tsk, struct sk_buff **skb)
779+
static void tipc_sk_proto_rcv(struct tipc_sock *tsk, struct sk_buff *skb)
770780
{
771-
struct tipc_msg *msg = buf_msg(*skb);
781+
struct sock *sk = &tsk->sk;
782+
struct tipc_msg *hdr = buf_msg(skb);
783+
int mtyp = msg_type(hdr);
772784
int conn_cong;
773-
u32 dnode;
774-
u32 own_node = tsk_own_node(tsk);
785+
775786
/* Ignore if connection cannot be validated: */
776-
if (!tsk_peer_msg(tsk, msg))
787+
if (!tsk_peer_msg(tsk, hdr))
777788
goto exit;
778789

779790
tsk->probing_state = TIPC_CONN_OK;
780791

781-
if (msg_type(msg) == CONN_ACK) {
792+
if (mtyp == CONN_PROBE) {
793+
msg_set_type(hdr, CONN_PROBE_REPLY);
794+
tipc_sk_respond(sk, skb, TIPC_OK);
795+
return;
796+
} else if (mtyp == CONN_ACK) {
782797
conn_cong = tsk_conn_cong(tsk);
783-
tsk->sent_unacked -= msg_msgcnt(msg);
798+
tsk->sent_unacked -= msg_msgcnt(hdr);
784799
if (conn_cong)
785-
tsk->sk.sk_write_space(&tsk->sk);
786-
} else if (msg_type(msg) == CONN_PROBE) {
787-
if (tipc_msg_reverse(own_node, skb, &dnode, TIPC_OK)) {
788-
msg_set_type(msg, CONN_PROBE_REPLY);
789-
return;
790-
}
800+
sk->sk_write_space(sk);
801+
} else if (mtyp != CONN_PROBE_REPLY) {
802+
pr_warn("Received unknown CONN_PROTO msg\n");
791803
}
792-
/* Do nothing if msg_type() == CONN_PROBE_REPLY */
793804
exit:
794-
kfree_skb(*skb);
795-
*skb = NULL;
805+
kfree_skb(skb);
796806
}
797807

798808
static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p)
@@ -1638,7 +1648,7 @@ static int filter_rcv(struct sock *sk, struct sk_buff **skb)
16381648
int rc = TIPC_OK;
16391649

16401650
if (unlikely(msg_user(msg) == CONN_MANAGER)) {
1641-
tipc_sk_proto_rcv(tsk, skb);
1651+
tipc_sk_proto_rcv(tsk, *skb);
16421652
return TIPC_OK;
16431653
}
16441654

@@ -1690,7 +1700,7 @@ static int tipc_backlog_rcv(struct sock *sk, struct sk_buff *skb)
16901700
{
16911701
int err;
16921702
atomic_t *dcnt;
1693-
u32 dnode;
1703+
u32 dnode = msg_prevnode(buf_msg(skb));
16941704
struct tipc_sock *tsk = tipc_sk(sk);
16951705
struct net *net = sock_net(sk);
16961706
uint truesize = skb->truesize;
@@ -1702,7 +1712,7 @@ static int tipc_backlog_rcv(struct sock *sk, struct sk_buff *skb)
17021712
atomic_add(truesize, dcnt);
17031713
return 0;
17041714
}
1705-
if (!err || tipc_msg_reverse(tsk_own_node(tsk), &skb, &dnode, -err))
1715+
if (!err || tipc_msg_reverse(tsk_own_node(tsk), &skb, -err))
17061716
tipc_node_xmit_skb(net, skb, dnode, tsk->portid);
17071717
return 0;
17081718
}
@@ -1794,9 +1804,11 @@ int tipc_sk_rcv(struct net *net, struct sk_buff_head *inputq)
17941804
if (!err) {
17951805
dnode = msg_destnode(buf_msg(skb));
17961806
goto xmit;
1807+
} else {
1808+
dnode = msg_prevnode(buf_msg(skb));
17971809
}
17981810
tn = net_generic(net, tipc_net_id);
1799-
if (!tipc_msg_reverse(tn->own_addr, &skb, &dnode, -err))
1811+
if (!tipc_msg_reverse(tn->own_addr, &skb, -err))
18001812
continue;
18011813
xmit:
18021814
tipc_node_xmit_skb(net, skb, dnode, dport);
@@ -2083,20 +2095,17 @@ static int tipc_shutdown(struct socket *sock, int how)
20832095
case SS_CONNECTED:
20842096

20852097
restart:
2098+
dnode = tsk_peer_node(tsk);
2099+
20862100
/* Disconnect and send a 'FIN+' or 'FIN-' message to peer */
20872101
skb = __skb_dequeue(&sk->sk_receive_queue);
20882102
if (skb) {
20892103
if (TIPC_SKB_CB(skb)->handle != NULL) {
20902104
kfree_skb(skb);
20912105
goto restart;
20922106
}
2093-
if (tipc_msg_reverse(tsk_own_node(tsk), &skb, &dnode,
2094-
TIPC_CONN_SHUTDOWN))
2095-
tipc_node_xmit_skb(net, skb, dnode,
2096-
tsk->portid);
2107+
tipc_sk_respond(sk, skb, TIPC_CONN_SHUTDOWN);
20972108
} else {
2098-
dnode = tsk_peer_node(tsk);
2099-
21002109
skb = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE,
21012110
TIPC_CONN_MSG, SHORT_H_SIZE,
21022111
0, dnode, tsk_own_node(tsk),

0 commit comments

Comments
 (0)