diff options
author | Parthasarathy Bhuvaragan <parthasarathy.bhuvaragan@ericsson.com> | 2016-11-01 09:02:40 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-11-01 11:53:24 -0400 |
commit | d6fb7e9c9946578667283805b9a73f318e3a0554 (patch) | |
tree | 2270e200a2550c081f3c2b5eae1c2d29f5b224a9 /net/tipc/socket.c | |
parent | 87227fe7e42060af9bc8977fc17427e7c9cadb5d (diff) |
tipc: remove tsk->connected from tipc_sock
Until now, we determine if a socket is connected or not based on
tsk->connected, which is set once when the probing state is set
to TIPC_CONN_OK. It is unset when the sock->state is updated from
SS_CONNECTED to any other state.
In this commit, we remove connected variable from tipc_sock and
derive socket connection status from the following condition:
sock->state == SS_CONNECTED => tsk->connected
There is no functional change in this commit.
Acked-by: Ying Xue <ying.xue@windriver.com>
Acked-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: Parthasarathy Bhuvaragan <parthasarathy.bhuvaragan@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc/socket.c')
-rw-r--r-- | net/tipc/socket.c | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 524abe47560d..7b6a1847cf8a 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c | |||
@@ -58,7 +58,6 @@ | |||
58 | /** | 58 | /** |
59 | * struct tipc_sock - TIPC socket structure | 59 | * struct tipc_sock - TIPC socket structure |
60 | * @sk: socket - interacts with 'port' and with user via the socket API | 60 | * @sk: socket - interacts with 'port' and with user via the socket API |
61 | * @connected: non-zero if port is currently connected to a peer port | ||
62 | * @conn_type: TIPC type used when connection was established | 61 | * @conn_type: TIPC type used when connection was established |
63 | * @conn_instance: TIPC instance used when connection was established | 62 | * @conn_instance: TIPC instance used when connection was established |
64 | * @published: non-zero if port has one or more associated names | 63 | * @published: non-zero if port has one or more associated names |
@@ -80,7 +79,6 @@ | |||
80 | */ | 79 | */ |
81 | struct tipc_sock { | 80 | struct tipc_sock { |
82 | struct sock sk; | 81 | struct sock sk; |
83 | int connected; | ||
84 | u32 conn_type; | 82 | u32 conn_type; |
85 | u32 conn_instance; | 83 | u32 conn_instance; |
86 | int published; | 84 | int published; |
@@ -293,6 +291,11 @@ static void tsk_rej_rx_queue(struct sock *sk) | |||
293 | tipc_sk_respond(sk, skb, TIPC_ERR_NO_PORT); | 291 | tipc_sk_respond(sk, skb, TIPC_ERR_NO_PORT); |
294 | } | 292 | } |
295 | 293 | ||
294 | static bool tipc_sk_connected(struct sock *sk) | ||
295 | { | ||
296 | return sk->sk_socket->state == SS_CONNECTED; | ||
297 | } | ||
298 | |||
296 | /* tsk_peer_msg - verify if message was sent by connected port's peer | 299 | /* tsk_peer_msg - verify if message was sent by connected port's peer |
297 | * | 300 | * |
298 | * Handles cases where the node's network address has changed from | 301 | * Handles cases where the node's network address has changed from |
@@ -300,12 +303,13 @@ static void tsk_rej_rx_queue(struct sock *sk) | |||
300 | */ | 303 | */ |
301 | static bool tsk_peer_msg(struct tipc_sock *tsk, struct tipc_msg *msg) | 304 | static bool tsk_peer_msg(struct tipc_sock *tsk, struct tipc_msg *msg) |
302 | { | 305 | { |
303 | struct tipc_net *tn = net_generic(sock_net(&tsk->sk), tipc_net_id); | 306 | struct sock *sk = &tsk->sk; |
307 | struct tipc_net *tn = net_generic(sock_net(sk), tipc_net_id); | ||
304 | u32 peer_port = tsk_peer_port(tsk); | 308 | u32 peer_port = tsk_peer_port(tsk); |
305 | u32 orig_node; | 309 | u32 orig_node; |
306 | u32 peer_node; | 310 | u32 peer_node; |
307 | 311 | ||
308 | if (unlikely(!tsk->connected)) | 312 | if (unlikely(!tipc_sk_connected(sk))) |
309 | return false; | 313 | return false; |
310 | 314 | ||
311 | if (unlikely(msg_origport(msg) != peer_port)) | 315 | if (unlikely(msg_origport(msg) != peer_port)) |
@@ -470,7 +474,6 @@ static int tipc_release(struct socket *sock) | |||
470 | if ((sock->state == SS_CONNECTING) || | 474 | if ((sock->state == SS_CONNECTING) || |
471 | (sock->state == SS_CONNECTED)) { | 475 | (sock->state == SS_CONNECTED)) { |
472 | sock->state = SS_DISCONNECTING; | 476 | sock->state = SS_DISCONNECTING; |
473 | tsk->connected = 0; | ||
474 | tipc_node_remove_conn(net, dnode, tsk->portid); | 477 | tipc_node_remove_conn(net, dnode, tsk->portid); |
475 | } | 478 | } |
476 | tipc_sk_respond(sk, skb, TIPC_ERR_NO_PORT); | 479 | tipc_sk_respond(sk, skb, TIPC_ERR_NO_PORT); |
@@ -480,7 +483,7 @@ static int tipc_release(struct socket *sock) | |||
480 | tipc_sk_withdraw(tsk, 0, NULL); | 483 | tipc_sk_withdraw(tsk, 0, NULL); |
481 | sk_stop_timer(sk, &sk->sk_timer); | 484 | sk_stop_timer(sk, &sk->sk_timer); |
482 | tipc_sk_remove(tsk); | 485 | tipc_sk_remove(tsk); |
483 | if (tsk->connected) { | 486 | if (tipc_sk_connected(sk)) { |
484 | skb = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, | 487 | skb = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, |
485 | TIPC_CONN_MSG, SHORT_H_SIZE, 0, dnode, | 488 | TIPC_CONN_MSG, SHORT_H_SIZE, 0, dnode, |
486 | tsk_own_node(tsk), tsk_peer_port(tsk), | 489 | tsk_own_node(tsk), tsk_peer_port(tsk), |
@@ -1010,7 +1013,7 @@ static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p) | |||
1010 | done = sk_wait_event(sk, timeo_p, | 1013 | done = sk_wait_event(sk, timeo_p, |
1011 | (!tsk->link_cong && | 1014 | (!tsk->link_cong && |
1012 | !tsk_conn_cong(tsk)) || | 1015 | !tsk_conn_cong(tsk)) || |
1013 | !tsk->connected); | 1016 | !tipc_sk_connected(sk)); |
1014 | finish_wait(sk_sleep(sk), &wait); | 1017 | finish_wait(sk_sleep(sk), &wait); |
1015 | } while (!done); | 1018 | } while (!done); |
1016 | return 0; | 1019 | return 0; |
@@ -1152,7 +1155,6 @@ static void tipc_sk_finish_conn(struct tipc_sock *tsk, u32 peer_port, | |||
1152 | 1155 | ||
1153 | tsk->probing_intv = CONN_PROBING_INTERVAL; | 1156 | tsk->probing_intv = CONN_PROBING_INTERVAL; |
1154 | tsk->probing_state = TIPC_CONN_OK; | 1157 | tsk->probing_state = TIPC_CONN_OK; |
1155 | tsk->connected = 1; | ||
1156 | sk_reset_timer(sk, &sk->sk_timer, jiffies + tsk->probing_intv); | 1158 | sk_reset_timer(sk, &sk->sk_timer, jiffies + tsk->probing_intv); |
1157 | tipc_node_add_conn(net, peer_node, tsk->portid, peer_port); | 1159 | tipc_node_add_conn(net, peer_node, tsk->portid, peer_port); |
1158 | tsk->max_pkt = tipc_node_get_mtu(net, peer_node, tsk->portid); | 1160 | tsk->max_pkt = tipc_node_get_mtu(net, peer_node, tsk->portid); |
@@ -1261,13 +1263,14 @@ static int tipc_sk_anc_data_recv(struct msghdr *m, struct tipc_msg *msg, | |||
1261 | 1263 | ||
1262 | static void tipc_sk_send_ack(struct tipc_sock *tsk) | 1264 | static void tipc_sk_send_ack(struct tipc_sock *tsk) |
1263 | { | 1265 | { |
1264 | struct net *net = sock_net(&tsk->sk); | 1266 | struct sock *sk = &tsk->sk; |
1267 | struct net *net = sock_net(sk); | ||
1265 | struct sk_buff *skb = NULL; | 1268 | struct sk_buff *skb = NULL; |
1266 | struct tipc_msg *msg; | 1269 | struct tipc_msg *msg; |
1267 | u32 peer_port = tsk_peer_port(tsk); | 1270 | u32 peer_port = tsk_peer_port(tsk); |
1268 | u32 dnode = tsk_peer_node(tsk); | 1271 | u32 dnode = tsk_peer_node(tsk); |
1269 | 1272 | ||
1270 | if (!tsk->connected) | 1273 | if (!tipc_sk_connected(sk)) |
1271 | return; | 1274 | return; |
1272 | skb = tipc_msg_create(CONN_MANAGER, CONN_ACK, INT_H_SIZE, 0, | 1275 | skb = tipc_msg_create(CONN_MANAGER, CONN_ACK, INT_H_SIZE, 0, |
1273 | dnode, tsk_own_node(tsk), peer_port, | 1276 | dnode, tsk_own_node(tsk), peer_port, |
@@ -1596,7 +1599,6 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb) | |||
1596 | 1599 | ||
1597 | if (unlikely(msg_errcode(hdr))) { | 1600 | if (unlikely(msg_errcode(hdr))) { |
1598 | sock->state = SS_DISCONNECTING; | 1601 | sock->state = SS_DISCONNECTING; |
1599 | tsk->connected = 0; | ||
1600 | /* Let timer expire on it's own */ | 1602 | /* Let timer expire on it's own */ |
1601 | tipc_node_remove_conn(net, tsk_peer_node(tsk), | 1603 | tipc_node_remove_conn(net, tsk_peer_node(tsk), |
1602 | tsk->portid); | 1604 | tsk->portid); |
@@ -2189,7 +2191,6 @@ restart: | |||
2189 | if (skb) | 2191 | if (skb) |
2190 | tipc_node_xmit_skb(net, skb, dnode, tsk->portid); | 2192 | tipc_node_xmit_skb(net, skb, dnode, tsk->portid); |
2191 | } | 2193 | } |
2192 | tsk->connected = 0; | ||
2193 | sock->state = SS_DISCONNECTING; | 2194 | sock->state = SS_DISCONNECTING; |
2194 | tipc_node_remove_conn(net, dnode, tsk->portid); | 2195 | tipc_node_remove_conn(net, dnode, tsk->portid); |
2195 | /* fall through */ | 2196 | /* fall through */ |
@@ -2221,7 +2222,7 @@ static void tipc_sk_timeout(unsigned long data) | |||
2221 | u32 own_node = tsk_own_node(tsk); | 2222 | u32 own_node = tsk_own_node(tsk); |
2222 | 2223 | ||
2223 | bh_lock_sock(sk); | 2224 | bh_lock_sock(sk); |
2224 | if (!tsk->connected) { | 2225 | if (!tipc_sk_connected(sk)) { |
2225 | bh_unlock_sock(sk); | 2226 | bh_unlock_sock(sk); |
2226 | goto exit; | 2227 | goto exit; |
2227 | } | 2228 | } |
@@ -2231,7 +2232,6 @@ static void tipc_sk_timeout(unsigned long data) | |||
2231 | if (tsk->probing_state == TIPC_CONN_PROBING) { | 2232 | if (tsk->probing_state == TIPC_CONN_PROBING) { |
2232 | if (!sock_owned_by_user(sk)) { | 2233 | if (!sock_owned_by_user(sk)) { |
2233 | sk->sk_socket->state = SS_DISCONNECTING; | 2234 | sk->sk_socket->state = SS_DISCONNECTING; |
2234 | tsk->connected = 0; | ||
2235 | tipc_node_remove_conn(sock_net(sk), tsk_peer_node(tsk), | 2235 | tipc_node_remove_conn(sock_net(sk), tsk_peer_node(tsk), |
2236 | tsk_peer_port(tsk)); | 2236 | tsk_peer_port(tsk)); |
2237 | sk->sk_state_change(sk); | 2237 | sk->sk_state_change(sk); |
@@ -2257,11 +2257,12 @@ exit: | |||
2257 | static int tipc_sk_publish(struct tipc_sock *tsk, uint scope, | 2257 | static int tipc_sk_publish(struct tipc_sock *tsk, uint scope, |
2258 | struct tipc_name_seq const *seq) | 2258 | struct tipc_name_seq const *seq) |
2259 | { | 2259 | { |
2260 | struct net *net = sock_net(&tsk->sk); | 2260 | struct sock *sk = &tsk->sk; |
2261 | struct net *net = sock_net(sk); | ||
2261 | struct publication *publ; | 2262 | struct publication *publ; |
2262 | u32 key; | 2263 | u32 key; |
2263 | 2264 | ||
2264 | if (tsk->connected) | 2265 | if (tipc_sk_connected(sk)) |
2265 | return -EINVAL; | 2266 | return -EINVAL; |
2266 | key = tsk->portid + tsk->pub_count + 1; | 2267 | key = tsk->portid + tsk->pub_count + 1; |
2267 | if (key == tsk->portid) | 2268 | if (key == tsk->portid) |
@@ -2719,6 +2720,7 @@ static int __tipc_nl_add_sk(struct sk_buff *skb, struct netlink_callback *cb, | |||
2719 | struct nlattr *attrs; | 2720 | struct nlattr *attrs; |
2720 | struct net *net = sock_net(skb->sk); | 2721 | struct net *net = sock_net(skb->sk); |
2721 | struct tipc_net *tn = net_generic(net, tipc_net_id); | 2722 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
2723 | struct sock *sk = &tsk->sk; | ||
2722 | 2724 | ||
2723 | hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, | 2725 | hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, |
2724 | &tipc_genl_family, NLM_F_MULTI, TIPC_NL_SOCK_GET); | 2726 | &tipc_genl_family, NLM_F_MULTI, TIPC_NL_SOCK_GET); |
@@ -2733,7 +2735,7 @@ static int __tipc_nl_add_sk(struct sk_buff *skb, struct netlink_callback *cb, | |||
2733 | if (nla_put_u32(skb, TIPC_NLA_SOCK_ADDR, tn->own_addr)) | 2735 | if (nla_put_u32(skb, TIPC_NLA_SOCK_ADDR, tn->own_addr)) |
2734 | goto attr_msg_cancel; | 2736 | goto attr_msg_cancel; |
2735 | 2737 | ||
2736 | if (tsk->connected) { | 2738 | if (tipc_sk_connected(sk)) { |
2737 | err = __tipc_nl_add_sk_con(skb, tsk); | 2739 | err = __tipc_nl_add_sk_con(skb, tsk); |
2738 | if (err) | 2740 | if (err) |
2739 | goto attr_msg_cancel; | 2741 | goto attr_msg_cancel; |