diff options
Diffstat (limited to 'net/tipc/socket.c')
| -rw-r--r-- | net/tipc/socket.c | 491 |
1 files changed, 382 insertions, 109 deletions
diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 49810fdff4c5..1217c90a363b 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c | |||
| @@ -46,8 +46,9 @@ | |||
| 46 | #include "bcast.h" | 46 | #include "bcast.h" |
| 47 | #include "netlink.h" | 47 | #include "netlink.h" |
| 48 | #include "group.h" | 48 | #include "group.h" |
| 49 | #include "trace.h" | ||
| 49 | 50 | ||
| 50 | #define CONN_TIMEOUT_DEFAULT 8000 /* default connect timeout = 8s */ | 51 | #define CONN_TIMEOUT_DEFAULT 8000 /* default connect timeout = 8s */ |
| 51 | #define CONN_PROBING_INTV msecs_to_jiffies(3600000) /* [ms] => 1 h */ | 52 | #define CONN_PROBING_INTV msecs_to_jiffies(3600000) /* [ms] => 1 h */ |
| 52 | #define TIPC_FWD_MSG 1 | 53 | #define TIPC_FWD_MSG 1 |
| 53 | #define TIPC_MAX_PORT 0xffffffff | 54 | #define TIPC_MAX_PORT 0xffffffff |
| @@ -80,7 +81,6 @@ struct sockaddr_pair { | |||
| 80 | * @publications: list of publications for port | 81 | * @publications: list of publications for port |
| 81 | * @blocking_link: address of the congested link we are currently sleeping on | 82 | * @blocking_link: address of the congested link we are currently sleeping on |
| 82 | * @pub_count: total # of publications port has made during its lifetime | 83 | * @pub_count: total # of publications port has made during its lifetime |
| 83 | * @probing_state: | ||
| 84 | * @conn_timeout: the time we can wait for an unresponded setup request | 84 | * @conn_timeout: the time we can wait for an unresponded setup request |
| 85 | * @dupl_rcvcnt: number of bytes counted twice, in both backlog and rcv queue | 85 | * @dupl_rcvcnt: number of bytes counted twice, in both backlog and rcv queue |
| 86 | * @cong_link_cnt: number of congested links | 86 | * @cong_link_cnt: number of congested links |
| @@ -102,8 +102,8 @@ struct tipc_sock { | |||
| 102 | struct list_head cong_links; | 102 | struct list_head cong_links; |
| 103 | struct list_head publications; | 103 | struct list_head publications; |
| 104 | u32 pub_count; | 104 | u32 pub_count; |
| 105 | uint conn_timeout; | ||
| 106 | atomic_t dupl_rcvcnt; | 105 | atomic_t dupl_rcvcnt; |
| 106 | u16 conn_timeout; | ||
| 107 | bool probe_unacked; | 107 | bool probe_unacked; |
| 108 | u16 cong_link_cnt; | 108 | u16 cong_link_cnt; |
| 109 | u16 snt_unacked; | 109 | u16 snt_unacked; |
| @@ -234,6 +234,7 @@ static u16 tsk_inc(struct tipc_sock *tsk, int msglen) | |||
| 234 | */ | 234 | */ |
| 235 | static void tsk_advance_rx_queue(struct sock *sk) | 235 | static void tsk_advance_rx_queue(struct sock *sk) |
| 236 | { | 236 | { |
| 237 | trace_tipc_sk_advance_rx(sk, NULL, TIPC_DUMP_SK_RCVQ, " "); | ||
| 237 | kfree_skb(__skb_dequeue(&sk->sk_receive_queue)); | 238 | kfree_skb(__skb_dequeue(&sk->sk_receive_queue)); |
| 238 | } | 239 | } |
| 239 | 240 | ||
| @@ -248,6 +249,7 @@ static void tipc_sk_respond(struct sock *sk, struct sk_buff *skb, int err) | |||
| 248 | if (!tipc_msg_reverse(onode, &skb, err)) | 249 | if (!tipc_msg_reverse(onode, &skb, err)) |
| 249 | return; | 250 | return; |
| 250 | 251 | ||
| 252 | trace_tipc_sk_rej_msg(sk, skb, TIPC_DUMP_NONE, "@sk_respond!"); | ||
| 251 | dnode = msg_destnode(buf_msg(skb)); | 253 | dnode = msg_destnode(buf_msg(skb)); |
| 252 | selector = msg_origport(buf_msg(skb)); | 254 | selector = msg_origport(buf_msg(skb)); |
| 253 | tipc_node_xmit_skb(sock_net(sk), skb, dnode, selector); | 255 | tipc_node_xmit_skb(sock_net(sk), skb, dnode, selector); |
| @@ -483,6 +485,7 @@ static int tipc_sk_create(struct net *net, struct socket *sock, | |||
| 483 | tsk_set_unreliable(tsk, true); | 485 | tsk_set_unreliable(tsk, true); |
| 484 | } | 486 | } |
| 485 | 487 | ||
| 488 | trace_tipc_sk_create(sk, NULL, TIPC_DUMP_NONE, " "); | ||
| 486 | return 0; | 489 | return 0; |
| 487 | } | 490 | } |
| 488 | 491 | ||
| @@ -507,6 +510,9 @@ static void __tipc_shutdown(struct socket *sock, int error) | |||
| 507 | tipc_wait_for_cond(sock, &timeout, (!tsk->cong_link_cnt && | 510 | tipc_wait_for_cond(sock, &timeout, (!tsk->cong_link_cnt && |
| 508 | !tsk_conn_cong(tsk))); | 511 | !tsk_conn_cong(tsk))); |
| 509 | 512 | ||
| 513 | /* Remove any pending SYN message */ | ||
| 514 | __skb_queue_purge(&sk->sk_write_queue); | ||
| 515 | |||
| 510 | /* Reject all unreceived messages, except on an active connection | 516 | /* Reject all unreceived messages, except on an active connection |
| 511 | * (which disconnects locally & sends a 'FIN+' to peer). | 517 | * (which disconnects locally & sends a 'FIN+' to peer). |
| 512 | */ | 518 | */ |
| @@ -569,6 +575,7 @@ static int tipc_release(struct socket *sock) | |||
| 569 | tsk = tipc_sk(sk); | 575 | tsk = tipc_sk(sk); |
| 570 | lock_sock(sk); | 576 | lock_sock(sk); |
| 571 | 577 | ||
| 578 | trace_tipc_sk_release(sk, NULL, TIPC_DUMP_ALL, " "); | ||
| 572 | __tipc_shutdown(sock, TIPC_ERR_NO_PORT); | 579 | __tipc_shutdown(sock, TIPC_ERR_NO_PORT); |
| 573 | sk->sk_shutdown = SHUTDOWN_MASK; | 580 | sk->sk_shutdown = SHUTDOWN_MASK; |
| 574 | tipc_sk_leave(tsk); | 581 | tipc_sk_leave(tsk); |
| @@ -715,7 +722,8 @@ static __poll_t tipc_poll(struct file *file, struct socket *sock, | |||
| 715 | struct tipc_sock *tsk = tipc_sk(sk); | 722 | struct tipc_sock *tsk = tipc_sk(sk); |
| 716 | __poll_t revents = 0; | 723 | __poll_t revents = 0; |
| 717 | 724 | ||
| 718 | sock_poll_wait(file, wait); | 725 | sock_poll_wait(file, sock, wait); |
| 726 | trace_tipc_sk_poll(sk, NULL, TIPC_DUMP_ALL, " "); | ||
| 719 | 727 | ||
| 720 | if (sk->sk_shutdown & RCV_SHUTDOWN) | 728 | if (sk->sk_shutdown & RCV_SHUTDOWN) |
| 721 | revents |= EPOLLRDHUP | EPOLLIN | EPOLLRDNORM; | 729 | revents |= EPOLLRDHUP | EPOLLIN | EPOLLRDNORM; |
| @@ -802,9 +810,12 @@ static int tipc_sendmcast(struct socket *sock, struct tipc_name_seq *seq, | |||
| 802 | rc = tipc_msg_build(hdr, msg, 0, dlen, mtu, &pkts); | 810 | rc = tipc_msg_build(hdr, msg, 0, dlen, mtu, &pkts); |
| 803 | 811 | ||
| 804 | /* Send message if build was successful */ | 812 | /* Send message if build was successful */ |
| 805 | if (unlikely(rc == dlen)) | 813 | if (unlikely(rc == dlen)) { |
| 814 | trace_tipc_sk_sendmcast(sk, skb_peek(&pkts), | ||
| 815 | TIPC_DUMP_SK_SNDQ, " "); | ||
| 806 | rc = tipc_mcast_xmit(net, &pkts, method, &dsts, | 816 | rc = tipc_mcast_xmit(net, &pkts, method, &dsts, |
| 807 | &tsk->cong_link_cnt); | 817 | &tsk->cong_link_cnt); |
| 818 | } | ||
| 808 | 819 | ||
| 809 | tipc_nlist_purge(&dsts); | 820 | tipc_nlist_purge(&dsts); |
| 810 | 821 | ||
| @@ -878,7 +889,6 @@ static int tipc_send_group_unicast(struct socket *sock, struct msghdr *m, | |||
| 878 | DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name); | 889 | DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name); |
| 879 | int blks = tsk_blocks(GROUP_H_SIZE + dlen); | 890 | int blks = tsk_blocks(GROUP_H_SIZE + dlen); |
| 880 | struct tipc_sock *tsk = tipc_sk(sk); | 891 | struct tipc_sock *tsk = tipc_sk(sk); |
| 881 | struct tipc_group *grp = tsk->group; | ||
| 882 | struct net *net = sock_net(sk); | 892 | struct net *net = sock_net(sk); |
| 883 | struct tipc_member *mb = NULL; | 893 | struct tipc_member *mb = NULL; |
| 884 | u32 node, port; | 894 | u32 node, port; |
| @@ -892,7 +902,9 @@ static int tipc_send_group_unicast(struct socket *sock, struct msghdr *m, | |||
| 892 | /* Block or return if destination link or member is congested */ | 902 | /* Block or return if destination link or member is congested */ |
| 893 | rc = tipc_wait_for_cond(sock, &timeout, | 903 | rc = tipc_wait_for_cond(sock, &timeout, |
| 894 | !tipc_dest_find(&tsk->cong_links, node, 0) && | 904 | !tipc_dest_find(&tsk->cong_links, node, 0) && |
| 895 | !tipc_group_cong(grp, node, port, blks, &mb)); | 905 | tsk->group && |
| 906 | !tipc_group_cong(tsk->group, node, port, blks, | ||
| 907 | &mb)); | ||
| 896 | if (unlikely(rc)) | 908 | if (unlikely(rc)) |
| 897 | return rc; | 909 | return rc; |
| 898 | 910 | ||
| @@ -922,7 +934,6 @@ static int tipc_send_group_anycast(struct socket *sock, struct msghdr *m, | |||
| 922 | struct tipc_sock *tsk = tipc_sk(sk); | 934 | struct tipc_sock *tsk = tipc_sk(sk); |
| 923 | struct list_head *cong_links = &tsk->cong_links; | 935 | struct list_head *cong_links = &tsk->cong_links; |
| 924 | int blks = tsk_blocks(GROUP_H_SIZE + dlen); | 936 | int blks = tsk_blocks(GROUP_H_SIZE + dlen); |
| 925 | struct tipc_group *grp = tsk->group; | ||
| 926 | struct tipc_msg *hdr = &tsk->phdr; | 937 | struct tipc_msg *hdr = &tsk->phdr; |
| 927 | struct tipc_member *first = NULL; | 938 | struct tipc_member *first = NULL; |
| 928 | struct tipc_member *mbr = NULL; | 939 | struct tipc_member *mbr = NULL; |
| @@ -939,9 +950,10 @@ static int tipc_send_group_anycast(struct socket *sock, struct msghdr *m, | |||
| 939 | type = msg_nametype(hdr); | 950 | type = msg_nametype(hdr); |
| 940 | inst = dest->addr.name.name.instance; | 951 | inst = dest->addr.name.name.instance; |
| 941 | scope = msg_lookup_scope(hdr); | 952 | scope = msg_lookup_scope(hdr); |
| 942 | exclude = tipc_group_exclude(grp); | ||
| 943 | 953 | ||
| 944 | while (++lookups < 4) { | 954 | while (++lookups < 4) { |
| 955 | exclude = tipc_group_exclude(tsk->group); | ||
| 956 | |||
| 945 | first = NULL; | 957 | first = NULL; |
| 946 | 958 | ||
| 947 | /* Look for a non-congested destination member, if any */ | 959 | /* Look for a non-congested destination member, if any */ |
| @@ -950,7 +962,8 @@ static int tipc_send_group_anycast(struct socket *sock, struct msghdr *m, | |||
| 950 | &dstcnt, exclude, false)) | 962 | &dstcnt, exclude, false)) |
| 951 | return -EHOSTUNREACH; | 963 | return -EHOSTUNREACH; |
| 952 | tipc_dest_pop(&dsts, &node, &port); | 964 | tipc_dest_pop(&dsts, &node, &port); |
| 953 | cong = tipc_group_cong(grp, node, port, blks, &mbr); | 965 | cong = tipc_group_cong(tsk->group, node, port, blks, |
| 966 | &mbr); | ||
| 954 | if (!cong) | 967 | if (!cong) |
| 955 | break; | 968 | break; |
| 956 | if (mbr == first) | 969 | if (mbr == first) |
| @@ -969,7 +982,8 @@ static int tipc_send_group_anycast(struct socket *sock, struct msghdr *m, | |||
| 969 | /* Block or return if destination link or member is congested */ | 982 | /* Block or return if destination link or member is congested */ |
| 970 | rc = tipc_wait_for_cond(sock, &timeout, | 983 | rc = tipc_wait_for_cond(sock, &timeout, |
| 971 | !tipc_dest_find(cong_links, node, 0) && | 984 | !tipc_dest_find(cong_links, node, 0) && |
| 972 | !tipc_group_cong(grp, node, port, | 985 | tsk->group && |
| 986 | !tipc_group_cong(tsk->group, node, port, | ||
| 973 | blks, &mbr)); | 987 | blks, &mbr)); |
| 974 | if (unlikely(rc)) | 988 | if (unlikely(rc)) |
| 975 | return rc; | 989 | return rc; |
| @@ -1004,8 +1018,7 @@ static int tipc_send_group_bcast(struct socket *sock, struct msghdr *m, | |||
| 1004 | struct sock *sk = sock->sk; | 1018 | struct sock *sk = sock->sk; |
| 1005 | struct net *net = sock_net(sk); | 1019 | struct net *net = sock_net(sk); |
| 1006 | struct tipc_sock *tsk = tipc_sk(sk); | 1020 | struct tipc_sock *tsk = tipc_sk(sk); |
| 1007 | struct tipc_group *grp = tsk->group; | 1021 | struct tipc_nlist *dsts; |
| 1008 | struct tipc_nlist *dsts = tipc_group_dests(grp); | ||
| 1009 | struct tipc_mc_method *method = &tsk->mc_method; | 1022 | struct tipc_mc_method *method = &tsk->mc_method; |
| 1010 | bool ack = method->mandatory && method->rcast; | 1023 | bool ack = method->mandatory && method->rcast; |
| 1011 | int blks = tsk_blocks(MCAST_H_SIZE + dlen); | 1024 | int blks = tsk_blocks(MCAST_H_SIZE + dlen); |
| @@ -1014,15 +1027,17 @@ static int tipc_send_group_bcast(struct socket *sock, struct msghdr *m, | |||
| 1014 | struct sk_buff_head pkts; | 1027 | struct sk_buff_head pkts; |
| 1015 | int rc = -EHOSTUNREACH; | 1028 | int rc = -EHOSTUNREACH; |
| 1016 | 1029 | ||
| 1017 | if (!dsts->local && !dsts->remote) | ||
| 1018 | return -EHOSTUNREACH; | ||
| 1019 | |||
| 1020 | /* Block or return if any destination link or member is congested */ | 1030 | /* Block or return if any destination link or member is congested */ |
| 1021 | rc = tipc_wait_for_cond(sock, &timeout, !tsk->cong_link_cnt && | 1031 | rc = tipc_wait_for_cond(sock, &timeout, |
| 1022 | !tipc_group_bc_cong(grp, blks)); | 1032 | !tsk->cong_link_cnt && tsk->group && |
| 1033 | !tipc_group_bc_cong(tsk->group, blks)); | ||
| 1023 | if (unlikely(rc)) | 1034 | if (unlikely(rc)) |
| 1024 | return rc; | 1035 | return rc; |
| 1025 | 1036 | ||
| 1037 | dsts = tipc_group_dests(tsk->group); | ||
| 1038 | if (!dsts->local && !dsts->remote) | ||
| 1039 | return -EHOSTUNREACH; | ||
| 1040 | |||
| 1026 | /* Complete message header */ | 1041 | /* Complete message header */ |
| 1027 | if (dest) { | 1042 | if (dest) { |
| 1028 | msg_set_type(hdr, TIPC_GRP_MCAST_MSG); | 1043 | msg_set_type(hdr, TIPC_GRP_MCAST_MSG); |
| @@ -1034,7 +1049,7 @@ static int tipc_send_group_bcast(struct socket *sock, struct msghdr *m, | |||
| 1034 | msg_set_hdr_sz(hdr, GROUP_H_SIZE); | 1049 | msg_set_hdr_sz(hdr, GROUP_H_SIZE); |
| 1035 | msg_set_destport(hdr, 0); | 1050 | msg_set_destport(hdr, 0); |
| 1036 | msg_set_destnode(hdr, 0); | 1051 | msg_set_destnode(hdr, 0); |
| 1037 | msg_set_grp_bc_seqno(hdr, tipc_group_bc_snd_nxt(grp)); | 1052 | msg_set_grp_bc_seqno(hdr, tipc_group_bc_snd_nxt(tsk->group)); |
| 1038 | 1053 | ||
| 1039 | /* Avoid getting stuck with repeated forced replicasts */ | 1054 | /* Avoid getting stuck with repeated forced replicasts */ |
| 1040 | msg_set_grp_bc_ack_req(hdr, ack); | 1055 | msg_set_grp_bc_ack_req(hdr, ack); |
| @@ -1206,8 +1221,10 @@ static void tipc_sk_conn_proto_rcv(struct tipc_sock *tsk, struct sk_buff *skb, | |||
| 1206 | bool conn_cong; | 1221 | bool conn_cong; |
| 1207 | 1222 | ||
| 1208 | /* Ignore if connection cannot be validated: */ | 1223 | /* Ignore if connection cannot be validated: */ |
| 1209 | if (!tsk_peer_msg(tsk, hdr)) | 1224 | if (!tsk_peer_msg(tsk, hdr)) { |
| 1225 | trace_tipc_sk_drop_msg(sk, skb, TIPC_DUMP_NONE, "@proto_rcv!"); | ||
| 1210 | goto exit; | 1226 | goto exit; |
| 1227 | } | ||
| 1211 | 1228 | ||
| 1212 | if (unlikely(msg_errcode(hdr))) { | 1229 | if (unlikely(msg_errcode(hdr))) { |
| 1213 | tipc_set_sk_state(sk, TIPC_DISCONNECTING); | 1230 | tipc_set_sk_state(sk, TIPC_DISCONNECTING); |
| @@ -1329,6 +1346,7 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dlen) | |||
| 1329 | tsk->conn_type = dest->addr.name.name.type; | 1346 | tsk->conn_type = dest->addr.name.name.type; |
| 1330 | tsk->conn_instance = dest->addr.name.name.instance; | 1347 | tsk->conn_instance = dest->addr.name.name.instance; |
| 1331 | } | 1348 | } |
| 1349 | msg_set_syn(hdr, 1); | ||
| 1332 | } | 1350 | } |
| 1333 | 1351 | ||
| 1334 | seq = &dest->addr.nameseq; | 1352 | seq = &dest->addr.nameseq; |
| @@ -1371,7 +1389,10 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dlen) | |||
| 1371 | rc = tipc_msg_build(hdr, m, 0, dlen, mtu, &pkts); | 1389 | rc = tipc_msg_build(hdr, m, 0, dlen, mtu, &pkts); |
| 1372 | if (unlikely(rc != dlen)) | 1390 | if (unlikely(rc != dlen)) |
| 1373 | return rc; | 1391 | return rc; |
| 1392 | if (unlikely(syn && !tipc_msg_skb_clone(&pkts, &sk->sk_write_queue))) | ||
| 1393 | return -ENOMEM; | ||
| 1374 | 1394 | ||
| 1395 | trace_tipc_sk_sendmsg(sk, skb_peek(&pkts), TIPC_DUMP_SK_SNDQ, " "); | ||
| 1375 | rc = tipc_node_xmit(net, &pkts, dnode, tsk->portid); | 1396 | rc = tipc_node_xmit(net, &pkts, dnode, tsk->portid); |
| 1376 | if (unlikely(rc == -ELINKCONG)) { | 1397 | if (unlikely(rc == -ELINKCONG)) { |
| 1377 | tipc_dest_push(clinks, dnode, 0); | 1398 | tipc_dest_push(clinks, dnode, 0); |
| @@ -1449,6 +1470,8 @@ static int __tipc_sendstream(struct socket *sock, struct msghdr *m, size_t dlen) | |||
| 1449 | if (unlikely(rc != send)) | 1470 | if (unlikely(rc != send)) |
| 1450 | break; | 1471 | break; |
| 1451 | 1472 | ||
| 1473 | trace_tipc_sk_sendstream(sk, skb_peek(&pkts), | ||
| 1474 | TIPC_DUMP_SK_SNDQ, " "); | ||
| 1452 | rc = tipc_node_xmit(net, &pkts, dnode, tsk->portid); | 1475 | rc = tipc_node_xmit(net, &pkts, dnode, tsk->portid); |
| 1453 | if (unlikely(rc == -ELINKCONG)) { | 1476 | if (unlikely(rc == -ELINKCONG)) { |
| 1454 | tsk->cong_link_cnt = 1; | 1477 | tsk->cong_link_cnt = 1; |
| @@ -1490,6 +1513,7 @@ static void tipc_sk_finish_conn(struct tipc_sock *tsk, u32 peer_port, | |||
| 1490 | struct net *net = sock_net(sk); | 1513 | struct net *net = sock_net(sk); |
| 1491 | struct tipc_msg *msg = &tsk->phdr; | 1514 | struct tipc_msg *msg = &tsk->phdr; |
| 1492 | 1515 | ||
| 1516 | msg_set_syn(msg, 0); | ||
| 1493 | msg_set_destnode(msg, peer_node); | 1517 | msg_set_destnode(msg, peer_node); |
| 1494 | msg_set_destport(msg, peer_port); | 1518 | msg_set_destport(msg, peer_port); |
| 1495 | msg_set_type(msg, TIPC_CONN_MSG); | 1519 | msg_set_type(msg, TIPC_CONN_MSG); |
| @@ -1501,6 +1525,7 @@ static void tipc_sk_finish_conn(struct tipc_sock *tsk, u32 peer_port, | |||
| 1501 | tipc_node_add_conn(net, peer_node, tsk->portid, peer_port); | 1525 | tipc_node_add_conn(net, peer_node, tsk->portid, peer_port); |
| 1502 | tsk->max_pkt = tipc_node_get_mtu(net, peer_node, tsk->portid); | 1526 | tsk->max_pkt = tipc_node_get_mtu(net, peer_node, tsk->portid); |
| 1503 | tsk->peer_caps = tipc_node_get_capabilities(net, peer_node); | 1527 | tsk->peer_caps = tipc_node_get_capabilities(net, peer_node); |
| 1528 | __skb_queue_purge(&sk->sk_write_queue); | ||
| 1504 | if (tsk->peer_caps & TIPC_BLOCK_FLOWCTL) | 1529 | if (tsk->peer_caps & TIPC_BLOCK_FLOWCTL) |
| 1505 | return; | 1530 | return; |
| 1506 | 1531 | ||
| @@ -1548,16 +1573,17 @@ static void tipc_sk_set_orig_addr(struct msghdr *m, struct sk_buff *skb) | |||
| 1548 | /** | 1573 | /** |
| 1549 | * tipc_sk_anc_data_recv - optionally capture ancillary data for received message | 1574 | * tipc_sk_anc_data_recv - optionally capture ancillary data for received message |
| 1550 | * @m: descriptor for message info | 1575 | * @m: descriptor for message info |
| 1551 | * @msg: received message header | 1576 | * @skb: received message buffer |
| 1552 | * @tsk: TIPC port associated with message | 1577 | * @tsk: TIPC port associated with message |
| 1553 | * | 1578 | * |
| 1554 | * Note: Ancillary data is not captured if not requested by receiver. | 1579 | * Note: Ancillary data is not captured if not requested by receiver. |
| 1555 | * | 1580 | * |
| 1556 | * Returns 0 if successful, otherwise errno | 1581 | * Returns 0 if successful, otherwise errno |
| 1557 | */ | 1582 | */ |
| 1558 | static int tipc_sk_anc_data_recv(struct msghdr *m, struct tipc_msg *msg, | 1583 | static int tipc_sk_anc_data_recv(struct msghdr *m, struct sk_buff *skb, |
| 1559 | struct tipc_sock *tsk) | 1584 | struct tipc_sock *tsk) |
| 1560 | { | 1585 | { |
| 1586 | struct tipc_msg *msg; | ||
| 1561 | u32 anc_data[3]; | 1587 | u32 anc_data[3]; |
| 1562 | u32 err; | 1588 | u32 err; |
| 1563 | u32 dest_type; | 1589 | u32 dest_type; |
| @@ -1566,6 +1592,7 @@ static int tipc_sk_anc_data_recv(struct msghdr *m, struct tipc_msg *msg, | |||
| 1566 | 1592 | ||
| 1567 | if (likely(m->msg_controllen == 0)) | 1593 | if (likely(m->msg_controllen == 0)) |
| 1568 | return 0; | 1594 | return 0; |
| 1595 | msg = buf_msg(skb); | ||
| 1569 | 1596 | ||
| 1570 | /* Optionally capture errored message object(s) */ | 1597 | /* Optionally capture errored message object(s) */ |
| 1571 | err = msg ? msg_errcode(msg) : 0; | 1598 | err = msg ? msg_errcode(msg) : 0; |
| @@ -1576,6 +1603,9 @@ static int tipc_sk_anc_data_recv(struct msghdr *m, struct tipc_msg *msg, | |||
| 1576 | if (res) | 1603 | if (res) |
| 1577 | return res; | 1604 | return res; |
| 1578 | if (anc_data[1]) { | 1605 | if (anc_data[1]) { |
| 1606 | if (skb_linearize(skb)) | ||
| 1607 | return -ENOMEM; | ||
| 1608 | msg = buf_msg(skb); | ||
| 1579 | res = put_cmsg(m, SOL_TIPC, TIPC_RETDATA, anc_data[1], | 1609 | res = put_cmsg(m, SOL_TIPC, TIPC_RETDATA, anc_data[1], |
| 1580 | msg_data(msg)); | 1610 | msg_data(msg)); |
| 1581 | if (res) | 1611 | if (res) |
| @@ -1737,9 +1767,10 @@ static int tipc_recvmsg(struct socket *sock, struct msghdr *m, | |||
| 1737 | 1767 | ||
| 1738 | /* Collect msg meta data, including error code and rejected data */ | 1768 | /* Collect msg meta data, including error code and rejected data */ |
| 1739 | tipc_sk_set_orig_addr(m, skb); | 1769 | tipc_sk_set_orig_addr(m, skb); |
| 1740 | rc = tipc_sk_anc_data_recv(m, hdr, tsk); | 1770 | rc = tipc_sk_anc_data_recv(m, skb, tsk); |
| 1741 | if (unlikely(rc)) | 1771 | if (unlikely(rc)) |
| 1742 | goto exit; | 1772 | goto exit; |
| 1773 | hdr = buf_msg(skb); | ||
| 1743 | 1774 | ||
| 1744 | /* Capture data if non-error msg, otherwise just set return value */ | 1775 | /* Capture data if non-error msg, otherwise just set return value */ |
| 1745 | if (likely(!err)) { | 1776 | if (likely(!err)) { |
| @@ -1849,9 +1880,10 @@ static int tipc_recvstream(struct socket *sock, struct msghdr *m, | |||
| 1849 | /* Collect msg meta data, incl. error code and rejected data */ | 1880 | /* Collect msg meta data, incl. error code and rejected data */ |
| 1850 | if (!copied) { | 1881 | if (!copied) { |
| 1851 | tipc_sk_set_orig_addr(m, skb); | 1882 | tipc_sk_set_orig_addr(m, skb); |
| 1852 | rc = tipc_sk_anc_data_recv(m, hdr, tsk); | 1883 | rc = tipc_sk_anc_data_recv(m, skb, tsk); |
| 1853 | if (rc) | 1884 | if (rc) |
| 1854 | break; | 1885 | break; |
| 1886 | hdr = buf_msg(skb); | ||
| 1855 | } | 1887 | } |
| 1856 | 1888 | ||
| 1857 | /* Copy data if msg ok, otherwise return error/partial data */ | 1889 | /* Copy data if msg ok, otherwise return error/partial data */ |
| @@ -1971,91 +2003,90 @@ static void tipc_sk_proto_rcv(struct sock *sk, | |||
| 1971 | } | 2003 | } |
| 1972 | 2004 | ||
| 1973 | /** | 2005 | /** |
| 1974 | * tipc_filter_connect - Handle incoming message for a connection-based socket | 2006 | * tipc_sk_filter_connect - check incoming message for a connection-based socket |
| 1975 | * @tsk: TIPC socket | 2007 | * @tsk: TIPC socket |
| 1976 | * @skb: pointer to message buffer. Set to NULL if buffer is consumed | 2008 | * @skb: pointer to message buffer. |
| 1977 | * | 2009 | * Returns true if message should be added to receive queue, false otherwise |
| 1978 | * Returns true if everything ok, false otherwise | ||
| 1979 | */ | 2010 | */ |
| 1980 | static bool tipc_sk_filter_connect(struct tipc_sock *tsk, struct sk_buff *skb) | 2011 | static bool tipc_sk_filter_connect(struct tipc_sock *tsk, struct sk_buff *skb) |
| 1981 | { | 2012 | { |
| 1982 | struct sock *sk = &tsk->sk; | 2013 | struct sock *sk = &tsk->sk; |
| 1983 | struct net *net = sock_net(sk); | 2014 | struct net *net = sock_net(sk); |
| 1984 | struct tipc_msg *hdr = buf_msg(skb); | 2015 | struct tipc_msg *hdr = buf_msg(skb); |
| 1985 | u32 pport = msg_origport(hdr); | 2016 | bool con_msg = msg_connected(hdr); |
| 1986 | u32 pnode = msg_orignode(hdr); | 2017 | u32 pport = tsk_peer_port(tsk); |
| 2018 | u32 pnode = tsk_peer_node(tsk); | ||
| 2019 | u32 oport = msg_origport(hdr); | ||
| 2020 | u32 onode = msg_orignode(hdr); | ||
| 2021 | int err = msg_errcode(hdr); | ||
| 2022 | unsigned long delay; | ||
| 1987 | 2023 | ||
| 1988 | if (unlikely(msg_mcast(hdr))) | 2024 | if (unlikely(msg_mcast(hdr))) |
| 1989 | return false; | 2025 | return false; |
| 1990 | 2026 | ||
| 1991 | switch (sk->sk_state) { | 2027 | switch (sk->sk_state) { |
| 1992 | case TIPC_CONNECTING: | 2028 | case TIPC_CONNECTING: |
| 1993 | /* Accept only ACK or NACK message */ | 2029 | /* Setup ACK */ |
| 1994 | if (unlikely(!msg_connected(hdr))) { | 2030 | if (likely(con_msg)) { |
| 1995 | if (pport != tsk_peer_port(tsk) || | 2031 | if (err) |
| 1996 | pnode != tsk_peer_node(tsk)) | 2032 | break; |
| 1997 | return false; | 2033 | tipc_sk_finish_conn(tsk, oport, onode); |
| 1998 | 2034 | msg_set_importance(&tsk->phdr, msg_importance(hdr)); | |
| 1999 | tipc_set_sk_state(sk, TIPC_DISCONNECTING); | 2035 | /* ACK+ message with data is added to receive queue */ |
| 2000 | sk->sk_err = ECONNREFUSED; | 2036 | if (msg_data_sz(hdr)) |
| 2001 | sk->sk_state_change(sk); | 2037 | return true; |
| 2002 | return true; | 2038 | /* Empty ACK-, - wake up sleeping connect() and drop */ |
| 2003 | } | 2039 | sk->sk_data_ready(sk); |
| 2004 | 2040 | msg_set_dest_droppable(hdr, 1); | |
| 2005 | if (unlikely(msg_errcode(hdr))) { | 2041 | return false; |
| 2006 | tipc_set_sk_state(sk, TIPC_DISCONNECTING); | ||
| 2007 | sk->sk_err = ECONNREFUSED; | ||
| 2008 | sk->sk_state_change(sk); | ||
| 2009 | return true; | ||
| 2010 | } | ||
| 2011 | |||
| 2012 | if (unlikely(!msg_isdata(hdr))) { | ||
| 2013 | tipc_set_sk_state(sk, TIPC_DISCONNECTING); | ||
| 2014 | sk->sk_err = EINVAL; | ||
| 2015 | sk->sk_state_change(sk); | ||
| 2016 | return true; | ||
| 2017 | } | 2042 | } |
| 2043 | /* Ignore connectionless message if not from listening socket */ | ||
| 2044 | if (oport != pport || onode != pnode) | ||
| 2045 | return false; | ||
| 2018 | 2046 | ||
| 2019 | tipc_sk_finish_conn(tsk, msg_origport(hdr), msg_orignode(hdr)); | 2047 | /* Rejected SYN */ |
| 2020 | msg_set_importance(&tsk->phdr, msg_importance(hdr)); | 2048 | if (err != TIPC_ERR_OVERLOAD) |
| 2021 | 2049 | break; | |
| 2022 | /* If 'ACK+' message, add to socket receive queue */ | ||
| 2023 | if (msg_data_sz(hdr)) | ||
| 2024 | return true; | ||
| 2025 | |||
| 2026 | /* If empty 'ACK-' message, wake up sleeping connect() */ | ||
| 2027 | sk->sk_data_ready(sk); | ||
| 2028 | 2050 | ||
| 2029 | /* 'ACK-' message is neither accepted nor rejected: */ | 2051 | /* Prepare for new setup attempt if we have a SYN clone */ |
| 2030 | msg_set_dest_droppable(hdr, 1); | 2052 | if (skb_queue_empty(&sk->sk_write_queue)) |
| 2053 | break; | ||
| 2054 | get_random_bytes(&delay, 2); | ||
| 2055 | delay %= (tsk->conn_timeout / 4); | ||
| 2056 | delay = msecs_to_jiffies(delay + 100); | ||
| 2057 | sk_reset_timer(sk, &sk->sk_timer, jiffies + delay); | ||
| 2031 | return false; | 2058 | return false; |
| 2032 | |||
| 2033 | case TIPC_OPEN: | 2059 | case TIPC_OPEN: |
| 2034 | case TIPC_DISCONNECTING: | 2060 | case TIPC_DISCONNECTING: |
| 2035 | break; | 2061 | return false; |
| 2036 | case TIPC_LISTEN: | 2062 | case TIPC_LISTEN: |
| 2037 | /* Accept only SYN message */ | 2063 | /* Accept only SYN message */ |
| 2038 | if (!msg_connected(hdr) && !(msg_errcode(hdr))) | 2064 | if (!msg_is_syn(hdr) && |
| 2065 | tipc_node_get_capabilities(net, onode) & TIPC_SYN_BIT) | ||
| 2066 | return false; | ||
| 2067 | if (!con_msg && !err) | ||
| 2039 | return true; | 2068 | return true; |
| 2040 | break; | 2069 | return false; |
| 2041 | case TIPC_ESTABLISHED: | 2070 | case TIPC_ESTABLISHED: |
| 2042 | /* Accept only connection-based messages sent by peer */ | 2071 | /* Accept only connection-based messages sent by peer */ |
| 2043 | if (unlikely(!tsk_peer_msg(tsk, hdr))) | 2072 | if (likely(con_msg && !err && pport == oport && pnode == onode)) |
| 2073 | return true; | ||
| 2074 | if (!tsk_peer_msg(tsk, hdr)) | ||
| 2044 | return false; | 2075 | return false; |
| 2045 | 2076 | if (!err) | |
| 2046 | if (unlikely(msg_errcode(hdr))) { | 2077 | return true; |
| 2047 | tipc_set_sk_state(sk, TIPC_DISCONNECTING); | 2078 | tipc_set_sk_state(sk, TIPC_DISCONNECTING); |
| 2048 | /* Let timer expire on it's own */ | 2079 | tipc_node_remove_conn(net, pnode, tsk->portid); |
| 2049 | tipc_node_remove_conn(net, tsk_peer_node(tsk), | 2080 | sk->sk_state_change(sk); |
| 2050 | tsk->portid); | ||
| 2051 | sk->sk_state_change(sk); | ||
| 2052 | } | ||
| 2053 | return true; | 2081 | return true; |
| 2054 | default: | 2082 | default: |
| 2055 | pr_err("Unknown sk_state %u\n", sk->sk_state); | 2083 | pr_err("Unknown sk_state %u\n", sk->sk_state); |
| 2056 | } | 2084 | } |
| 2057 | 2085 | /* Abort connection setup attempt */ | |
| 2058 | return false; | 2086 | tipc_set_sk_state(sk, TIPC_DISCONNECTING); |
| 2087 | sk->sk_err = ECONNREFUSED; | ||
| 2088 | sk->sk_state_change(sk); | ||
| 2089 | return true; | ||
| 2059 | } | 2090 | } |
| 2060 | 2091 | ||
| 2061 | /** | 2092 | /** |
| @@ -2115,6 +2146,7 @@ static void tipc_sk_filter_rcv(struct sock *sk, struct sk_buff *skb, | |||
| 2115 | struct sk_buff_head inputq; | 2146 | struct sk_buff_head inputq; |
| 2116 | int limit, err = TIPC_OK; | 2147 | int limit, err = TIPC_OK; |
| 2117 | 2148 | ||
| 2149 | trace_tipc_sk_filter_rcv(sk, skb, TIPC_DUMP_ALL, " "); | ||
| 2118 | TIPC_SKB_CB(skb)->bytes_read = 0; | 2150 | TIPC_SKB_CB(skb)->bytes_read = 0; |
| 2119 | __skb_queue_head_init(&inputq); | 2151 | __skb_queue_head_init(&inputq); |
| 2120 | __skb_queue_tail(&inputq, skb); | 2152 | __skb_queue_tail(&inputq, skb); |
| @@ -2134,17 +2166,25 @@ static void tipc_sk_filter_rcv(struct sock *sk, struct sk_buff *skb, | |||
| 2134 | (!grp && msg_in_group(hdr))) | 2166 | (!grp && msg_in_group(hdr))) |
| 2135 | err = TIPC_ERR_NO_PORT; | 2167 | err = TIPC_ERR_NO_PORT; |
| 2136 | else if (sk_rmem_alloc_get(sk) + skb->truesize >= limit) { | 2168 | else if (sk_rmem_alloc_get(sk) + skb->truesize >= limit) { |
| 2169 | trace_tipc_sk_dump(sk, skb, TIPC_DUMP_ALL, | ||
| 2170 | "err_overload2!"); | ||
| 2137 | atomic_inc(&sk->sk_drops); | 2171 | atomic_inc(&sk->sk_drops); |
| 2138 | err = TIPC_ERR_OVERLOAD; | 2172 | err = TIPC_ERR_OVERLOAD; |
| 2139 | } | 2173 | } |
| 2140 | 2174 | ||
| 2141 | if (unlikely(err)) { | 2175 | if (unlikely(err)) { |
| 2142 | tipc_skb_reject(net, err, skb, xmitq); | 2176 | if (tipc_msg_reverse(tipc_own_addr(net), &skb, err)) { |
| 2177 | trace_tipc_sk_rej_msg(sk, skb, TIPC_DUMP_NONE, | ||
| 2178 | "@filter_rcv!"); | ||
| 2179 | __skb_queue_tail(xmitq, skb); | ||
| 2180 | } | ||
| 2143 | err = TIPC_OK; | 2181 | err = TIPC_OK; |
| 2144 | continue; | 2182 | continue; |
| 2145 | } | 2183 | } |
| 2146 | __skb_queue_tail(&sk->sk_receive_queue, skb); | 2184 | __skb_queue_tail(&sk->sk_receive_queue, skb); |
| 2147 | skb_set_owner_r(skb, sk); | 2185 | skb_set_owner_r(skb, sk); |
| 2186 | trace_tipc_sk_overlimit2(sk, skb, TIPC_DUMP_ALL, | ||
| 2187 | "rcvq >90% allocated!"); | ||
| 2148 | sk->sk_data_ready(sk); | 2188 | sk->sk_data_ready(sk); |
| 2149 | } | 2189 | } |
| 2150 | } | 2190 | } |
| @@ -2210,14 +2250,21 @@ static void tipc_sk_enqueue(struct sk_buff_head *inputq, struct sock *sk, | |||
| 2210 | if (!sk->sk_backlog.len) | 2250 | if (!sk->sk_backlog.len) |
| 2211 | atomic_set(dcnt, 0); | 2251 | atomic_set(dcnt, 0); |
| 2212 | lim = rcvbuf_limit(sk, skb) + atomic_read(dcnt); | 2252 | lim = rcvbuf_limit(sk, skb) + atomic_read(dcnt); |
| 2213 | if (likely(!sk_add_backlog(sk, skb, lim))) | 2253 | if (likely(!sk_add_backlog(sk, skb, lim))) { |
| 2254 | trace_tipc_sk_overlimit1(sk, skb, TIPC_DUMP_ALL, | ||
| 2255 | "bklg & rcvq >90% allocated!"); | ||
| 2214 | continue; | 2256 | continue; |
| 2257 | } | ||
| 2215 | 2258 | ||
| 2259 | trace_tipc_sk_dump(sk, skb, TIPC_DUMP_ALL, "err_overload!"); | ||
| 2216 | /* Overload => reject message back to sender */ | 2260 | /* Overload => reject message back to sender */ |
| 2217 | onode = tipc_own_addr(sock_net(sk)); | 2261 | onode = tipc_own_addr(sock_net(sk)); |
| 2218 | atomic_inc(&sk->sk_drops); | 2262 | atomic_inc(&sk->sk_drops); |
| 2219 | if (tipc_msg_reverse(onode, &skb, TIPC_ERR_OVERLOAD)) | 2263 | if (tipc_msg_reverse(onode, &skb, TIPC_ERR_OVERLOAD)) { |
| 2264 | trace_tipc_sk_rej_msg(sk, skb, TIPC_DUMP_ALL, | ||
| 2265 | "@sk_enqueue!"); | ||
| 2220 | __skb_queue_tail(xmitq, skb); | 2266 | __skb_queue_tail(xmitq, skb); |
| 2267 | } | ||
| 2221 | break; | 2268 | break; |
| 2222 | } | 2269 | } |
| 2223 | } | 2270 | } |
| @@ -2266,6 +2313,8 @@ void tipc_sk_rcv(struct net *net, struct sk_buff_head *inputq) | |||
| 2266 | /* Prepare for message rejection */ | 2313 | /* Prepare for message rejection */ |
| 2267 | if (!tipc_msg_reverse(tipc_own_addr(net), &skb, err)) | 2314 | if (!tipc_msg_reverse(tipc_own_addr(net), &skb, err)) |
| 2268 | continue; | 2315 | continue; |
| 2316 | |||
| 2317 | trace_tipc_sk_rej_msg(NULL, skb, TIPC_DUMP_NONE, "@sk_rcv!"); | ||
| 2269 | xmit: | 2318 | xmit: |
| 2270 | dnode = msg_destnode(buf_msg(skb)); | 2319 | dnode = msg_destnode(buf_msg(skb)); |
| 2271 | tipc_node_xmit_skb(net, skb, dnode, dport); | 2320 | tipc_node_xmit_skb(net, skb, dnode, dport); |
| @@ -2539,6 +2588,7 @@ static int tipc_shutdown(struct socket *sock, int how) | |||
| 2539 | 2588 | ||
| 2540 | lock_sock(sk); | 2589 | lock_sock(sk); |
| 2541 | 2590 | ||
| 2591 | trace_tipc_sk_shutdown(sk, NULL, TIPC_DUMP_ALL, " "); | ||
| 2542 | __tipc_shutdown(sock, TIPC_CONN_SHUTDOWN); | 2592 | __tipc_shutdown(sock, TIPC_CONN_SHUTDOWN); |
| 2543 | sk->sk_shutdown = SEND_SHUTDOWN; | 2593 | sk->sk_shutdown = SEND_SHUTDOWN; |
| 2544 | 2594 | ||
| @@ -2557,43 +2607,78 @@ static int tipc_shutdown(struct socket *sock, int how) | |||
| 2557 | return res; | 2607 | return res; |
| 2558 | } | 2608 | } |
| 2559 | 2609 | ||
| 2610 | static void tipc_sk_check_probing_state(struct sock *sk, | ||
| 2611 | struct sk_buff_head *list) | ||
| 2612 | { | ||
| 2613 | struct tipc_sock *tsk = tipc_sk(sk); | ||
| 2614 | u32 pnode = tsk_peer_node(tsk); | ||
| 2615 | u32 pport = tsk_peer_port(tsk); | ||
| 2616 | u32 self = tsk_own_node(tsk); | ||
| 2617 | u32 oport = tsk->portid; | ||
| 2618 | struct sk_buff *skb; | ||
| 2619 | |||
| 2620 | if (tsk->probe_unacked) { | ||
| 2621 | tipc_set_sk_state(sk, TIPC_DISCONNECTING); | ||
| 2622 | sk->sk_err = ECONNABORTED; | ||
| 2623 | tipc_node_remove_conn(sock_net(sk), pnode, pport); | ||
| 2624 | sk->sk_state_change(sk); | ||
| 2625 | return; | ||
| 2626 | } | ||
| 2627 | /* Prepare new probe */ | ||
| 2628 | skb = tipc_msg_create(CONN_MANAGER, CONN_PROBE, INT_H_SIZE, 0, | ||
| 2629 | pnode, self, pport, oport, TIPC_OK); | ||
| 2630 | if (skb) | ||
| 2631 | __skb_queue_tail(list, skb); | ||
| 2632 | tsk->probe_unacked = true; | ||
| 2633 | sk_reset_timer(sk, &sk->sk_timer, jiffies + CONN_PROBING_INTV); | ||
| 2634 | } | ||
| 2635 | |||
| 2636 | static void tipc_sk_retry_connect(struct sock *sk, struct sk_buff_head *list) | ||
| 2637 | { | ||
| 2638 | struct tipc_sock *tsk = tipc_sk(sk); | ||
| 2639 | |||
| 2640 | /* Try again later if dest link is congested */ | ||
| 2641 | if (tsk->cong_link_cnt) { | ||
| 2642 | sk_reset_timer(sk, &sk->sk_timer, msecs_to_jiffies(100)); | ||
| 2643 | return; | ||
| 2644 | } | ||
| 2645 | /* Prepare SYN for retransmit */ | ||
| 2646 | tipc_msg_skb_clone(&sk->sk_write_queue, list); | ||
| 2647 | } | ||
| 2648 | |||
| 2560 | static void tipc_sk_timeout(struct timer_list *t) | 2649 | static void tipc_sk_timeout(struct timer_list *t) |
| 2561 | { | 2650 | { |
| 2562 | struct sock *sk = from_timer(sk, t, sk_timer); | 2651 | struct sock *sk = from_timer(sk, t, sk_timer); |
| 2563 | struct tipc_sock *tsk = tipc_sk(sk); | 2652 | struct tipc_sock *tsk = tipc_sk(sk); |
| 2564 | u32 peer_port = tsk_peer_port(tsk); | 2653 | u32 pnode = tsk_peer_node(tsk); |
| 2565 | u32 peer_node = tsk_peer_node(tsk); | 2654 | struct sk_buff_head list; |
| 2566 | u32 own_node = tsk_own_node(tsk); | 2655 | int rc = 0; |
| 2567 | u32 own_port = tsk->portid; | ||
| 2568 | struct net *net = sock_net(sk); | ||
| 2569 | struct sk_buff *skb = NULL; | ||
| 2570 | 2656 | ||
| 2657 | skb_queue_head_init(&list); | ||
| 2571 | bh_lock_sock(sk); | 2658 | bh_lock_sock(sk); |
| 2572 | if (!tipc_sk_connected(sk)) | ||
| 2573 | goto exit; | ||
| 2574 | 2659 | ||
| 2575 | /* Try again later if socket is busy */ | 2660 | /* Try again later if socket is busy */ |
| 2576 | if (sock_owned_by_user(sk)) { | 2661 | if (sock_owned_by_user(sk)) { |
| 2577 | sk_reset_timer(sk, &sk->sk_timer, jiffies + HZ / 20); | 2662 | sk_reset_timer(sk, &sk->sk_timer, jiffies + HZ / 20); |
| 2578 | goto exit; | 2663 | bh_unlock_sock(sk); |
| 2664 | return; | ||
| 2579 | } | 2665 | } |
| 2580 | 2666 | ||
| 2581 | if (tsk->probe_unacked) { | 2667 | if (sk->sk_state == TIPC_ESTABLISHED) |
| 2582 | tipc_set_sk_state(sk, TIPC_DISCONNECTING); | 2668 | tipc_sk_check_probing_state(sk, &list); |
| 2583 | tipc_node_remove_conn(net, peer_node, peer_port); | 2669 | else if (sk->sk_state == TIPC_CONNECTING) |
| 2584 | sk->sk_state_change(sk); | 2670 | tipc_sk_retry_connect(sk, &list); |
| 2585 | goto exit; | 2671 | |
| 2586 | } | ||
| 2587 | /* Send new probe */ | ||
| 2588 | skb = tipc_msg_create(CONN_MANAGER, CONN_PROBE, INT_H_SIZE, 0, | ||
| 2589 | peer_node, own_node, peer_port, own_port, | ||
| 2590 | TIPC_OK); | ||
| 2591 | tsk->probe_unacked = true; | ||
| 2592 | sk_reset_timer(sk, &sk->sk_timer, jiffies + CONN_PROBING_INTV); | ||
| 2593 | exit: | ||
| 2594 | bh_unlock_sock(sk); | 2672 | bh_unlock_sock(sk); |
| 2595 | if (skb) | 2673 | |
| 2596 | tipc_node_xmit_skb(net, skb, peer_node, own_port); | 2674 | if (!skb_queue_empty(&list)) |
| 2675 | rc = tipc_node_xmit(sock_net(sk), &list, pnode, tsk->portid); | ||
| 2676 | |||
| 2677 | /* SYN messages may cause link congestion */ | ||
| 2678 | if (rc == -ELINKCONG) { | ||
| 2679 | tipc_dest_push(&tsk->cong_links, pnode, 0); | ||
| 2680 | tsk->cong_link_cnt = 1; | ||
| 2681 | } | ||
| 2597 | sock_put(sk); | 2682 | sock_put(sk); |
| 2598 | } | 2683 | } |
| 2599 | 2684 | ||
| @@ -2676,11 +2761,15 @@ void tipc_sk_reinit(struct net *net) | |||
| 2676 | rhashtable_walk_start(&iter); | 2761 | rhashtable_walk_start(&iter); |
| 2677 | 2762 | ||
| 2678 | while ((tsk = rhashtable_walk_next(&iter)) && !IS_ERR(tsk)) { | 2763 | while ((tsk = rhashtable_walk_next(&iter)) && !IS_ERR(tsk)) { |
| 2679 | spin_lock_bh(&tsk->sk.sk_lock.slock); | 2764 | sock_hold(&tsk->sk); |
| 2765 | rhashtable_walk_stop(&iter); | ||
| 2766 | lock_sock(&tsk->sk); | ||
| 2680 | msg = &tsk->phdr; | 2767 | msg = &tsk->phdr; |
| 2681 | msg_set_prevnode(msg, tipc_own_addr(net)); | 2768 | msg_set_prevnode(msg, tipc_own_addr(net)); |
| 2682 | msg_set_orignode(msg, tipc_own_addr(net)); | 2769 | msg_set_orignode(msg, tipc_own_addr(net)); |
| 2683 | spin_unlock_bh(&tsk->sk.sk_lock.slock); | 2770 | release_sock(&tsk->sk); |
| 2771 | rhashtable_walk_start(&iter); | ||
| 2772 | sock_put(&tsk->sk); | ||
| 2684 | } | 2773 | } |
| 2685 | 2774 | ||
| 2686 | rhashtable_walk_stop(&iter); | 2775 | rhashtable_walk_stop(&iter); |
| @@ -3516,3 +3605,187 @@ int tipc_nl_publ_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
| 3516 | 3605 | ||
| 3517 | return skb->len; | 3606 | return skb->len; |
| 3518 | } | 3607 | } |
| 3608 | |||
| 3609 | /** | ||
| 3610 | * tipc_sk_filtering - check if a socket should be traced | ||
| 3611 | * @sk: the socket to be examined | ||
| 3612 | * @sysctl_tipc_sk_filter[]: the socket tuple for filtering, | ||
| 3613 | * (portid, sock type, name type, name lower, name upper) | ||
| 3614 | * | ||
| 3615 | * Returns true if the socket meets the socket tuple data | ||
| 3616 | * (value 0 = 'any') or when there is no tuple set (all = 0), | ||
| 3617 | * otherwise false | ||
| 3618 | */ | ||
| 3619 | bool tipc_sk_filtering(struct sock *sk) | ||
| 3620 | { | ||
| 3621 | struct tipc_sock *tsk; | ||
| 3622 | struct publication *p; | ||
| 3623 | u32 _port, _sktype, _type, _lower, _upper; | ||
| 3624 | u32 type = 0, lower = 0, upper = 0; | ||
| 3625 | |||
| 3626 | if (!sk) | ||
| 3627 | return true; | ||
| 3628 | |||
| 3629 | tsk = tipc_sk(sk); | ||
| 3630 | |||
| 3631 | _port = sysctl_tipc_sk_filter[0]; | ||
| 3632 | _sktype = sysctl_tipc_sk_filter[1]; | ||
| 3633 | _type = sysctl_tipc_sk_filter[2]; | ||
| 3634 | _lower = sysctl_tipc_sk_filter[3]; | ||
| 3635 | _upper = sysctl_tipc_sk_filter[4]; | ||
| 3636 | |||
| 3637 | if (!_port && !_sktype && !_type && !_lower && !_upper) | ||
| 3638 | return true; | ||
| 3639 | |||
| 3640 | if (_port) | ||
| 3641 | return (_port == tsk->portid); | ||
| 3642 | |||
| 3643 | if (_sktype && _sktype != sk->sk_type) | ||
| 3644 | return false; | ||
| 3645 | |||
| 3646 | if (tsk->published) { | ||
| 3647 | p = list_first_entry_or_null(&tsk->publications, | ||
| 3648 | struct publication, binding_sock); | ||
| 3649 | if (p) { | ||
| 3650 | type = p->type; | ||
| 3651 | lower = p->lower; | ||
| 3652 | upper = p->upper; | ||
| 3653 | } | ||
| 3654 | } | ||
| 3655 | |||
| 3656 | if (!tipc_sk_type_connectionless(sk)) { | ||
| 3657 | type = tsk->conn_type; | ||
| 3658 | lower = tsk->conn_instance; | ||
| 3659 | upper = tsk->conn_instance; | ||
| 3660 | } | ||
| 3661 | |||
| 3662 | if ((_type && _type != type) || (_lower && _lower != lower) || | ||
| 3663 | (_upper && _upper != upper)) | ||
| 3664 | return false; | ||
| 3665 | |||
| 3666 | return true; | ||
| 3667 | } | ||
| 3668 | |||
| 3669 | u32 tipc_sock_get_portid(struct sock *sk) | ||
| 3670 | { | ||
| 3671 | return (sk) ? (tipc_sk(sk))->portid : 0; | ||
| 3672 | } | ||
| 3673 | |||
| 3674 | /** | ||
| 3675 | * tipc_sk_overlimit1 - check if socket rx queue is about to be overloaded, | ||
| 3676 | * both the rcv and backlog queues are considered | ||
| 3677 | * @sk: tipc sk to be checked | ||
| 3678 | * @skb: tipc msg to be checked | ||
| 3679 | * | ||
| 3680 | * Returns true if the socket rx queue allocation is > 90%, otherwise false | ||
| 3681 | */ | ||
| 3682 | |||
| 3683 | bool tipc_sk_overlimit1(struct sock *sk, struct sk_buff *skb) | ||
| 3684 | { | ||
| 3685 | atomic_t *dcnt = &tipc_sk(sk)->dupl_rcvcnt; | ||
| 3686 | unsigned int lim = rcvbuf_limit(sk, skb) + atomic_read(dcnt); | ||
| 3687 | unsigned int qsize = sk->sk_backlog.len + sk_rmem_alloc_get(sk); | ||
| 3688 | |||
| 3689 | return (qsize > lim * 90 / 100); | ||
| 3690 | } | ||
| 3691 | |||
| 3692 | /** | ||
| 3693 | * tipc_sk_overlimit2 - check if socket rx queue is about to be overloaded, | ||
| 3694 | * only the rcv queue is considered | ||
| 3695 | * @sk: tipc sk to be checked | ||
| 3696 | * @skb: tipc msg to be checked | ||
| 3697 | * | ||
| 3698 | * Returns true if the socket rx queue allocation is > 90%, otherwise false | ||
| 3699 | */ | ||
| 3700 | |||
| 3701 | bool tipc_sk_overlimit2(struct sock *sk, struct sk_buff *skb) | ||
| 3702 | { | ||
| 3703 | unsigned int lim = rcvbuf_limit(sk, skb); | ||
| 3704 | unsigned int qsize = sk_rmem_alloc_get(sk); | ||
| 3705 | |||
| 3706 | return (qsize > lim * 90 / 100); | ||
| 3707 | } | ||
| 3708 | |||
| 3709 | /** | ||
| 3710 | * tipc_sk_dump - dump TIPC socket | ||
| 3711 | * @sk: tipc sk to be dumped | ||
| 3712 | * @dqueues: bitmask to decide if any socket queue to be dumped? | ||
| 3713 | * - TIPC_DUMP_NONE: don't dump socket queues | ||
| 3714 | * - TIPC_DUMP_SK_SNDQ: dump socket send queue | ||
| 3715 | * - TIPC_DUMP_SK_RCVQ: dump socket rcv queue | ||
| 3716 | * - TIPC_DUMP_SK_BKLGQ: dump socket backlog queue | ||
| 3717 | * - TIPC_DUMP_ALL: dump all the socket queues above | ||
| 3718 | * @buf: returned buffer of dump data in format | ||
| 3719 | */ | ||
| 3720 | int tipc_sk_dump(struct sock *sk, u16 dqueues, char *buf) | ||
| 3721 | { | ||
| 3722 | int i = 0; | ||
| 3723 | size_t sz = (dqueues) ? SK_LMAX : SK_LMIN; | ||
| 3724 | struct tipc_sock *tsk; | ||
| 3725 | struct publication *p; | ||
| 3726 | bool tsk_connected; | ||
| 3727 | |||
| 3728 | if (!sk) { | ||
| 3729 | i += scnprintf(buf, sz, "sk data: (null)\n"); | ||
| 3730 | return i; | ||
| 3731 | } | ||
| 3732 | |||
| 3733 | tsk = tipc_sk(sk); | ||
| 3734 | tsk_connected = !tipc_sk_type_connectionless(sk); | ||
| 3735 | |||
| 3736 | i += scnprintf(buf, sz, "sk data: %u", sk->sk_type); | ||
| 3737 | i += scnprintf(buf + i, sz - i, " %d", sk->sk_state); | ||
| 3738 | i += scnprintf(buf + i, sz - i, " %x", tsk_own_node(tsk)); | ||
| 3739 | i += scnprintf(buf + i, sz - i, " %u", tsk->portid); | ||
| 3740 | i += scnprintf(buf + i, sz - i, " | %u", tsk_connected); | ||
| 3741 | if (tsk_connected) { | ||
| 3742 | i += scnprintf(buf + i, sz - i, " %x", tsk_peer_node(tsk)); | ||
| 3743 | i += scnprintf(buf + i, sz - i, " %u", tsk_peer_port(tsk)); | ||
| 3744 | i += scnprintf(buf + i, sz - i, " %u", tsk->conn_type); | ||
| 3745 | i += scnprintf(buf + i, sz - i, " %u", tsk->conn_instance); | ||
| 3746 | } | ||
| 3747 | i += scnprintf(buf + i, sz - i, " | %u", tsk->published); | ||
| 3748 | if (tsk->published) { | ||
| 3749 | p = list_first_entry_or_null(&tsk->publications, | ||
| 3750 | struct publication, binding_sock); | ||
| 3751 | i += scnprintf(buf + i, sz - i, " %u", (p) ? p->type : 0); | ||
| 3752 | i += scnprintf(buf + i, sz - i, " %u", (p) ? p->lower : 0); | ||
| 3753 | i += scnprintf(buf + i, sz - i, " %u", (p) ? p->upper : 0); | ||
| 3754 | } | ||
| 3755 | i += scnprintf(buf + i, sz - i, " | %u", tsk->snd_win); | ||
| 3756 | i += scnprintf(buf + i, sz - i, " %u", tsk->rcv_win); | ||
| 3757 | i += scnprintf(buf + i, sz - i, " %u", tsk->max_pkt); | ||
| 3758 | i += scnprintf(buf + i, sz - i, " %x", tsk->peer_caps); | ||
| 3759 | i += scnprintf(buf + i, sz - i, " %u", tsk->cong_link_cnt); | ||
| 3760 | i += scnprintf(buf + i, sz - i, " %u", tsk->snt_unacked); | ||
| 3761 | i += scnprintf(buf + i, sz - i, " %u", tsk->rcv_unacked); | ||
| 3762 | i += scnprintf(buf + i, sz - i, " %u", atomic_read(&tsk->dupl_rcvcnt)); | ||
| 3763 | i += scnprintf(buf + i, sz - i, " %u", sk->sk_shutdown); | ||
| 3764 | i += scnprintf(buf + i, sz - i, " | %d", sk_wmem_alloc_get(sk)); | ||
| 3765 | i += scnprintf(buf + i, sz - i, " %d", sk->sk_sndbuf); | ||
| 3766 | i += scnprintf(buf + i, sz - i, " | %d", sk_rmem_alloc_get(sk)); | ||
| 3767 | i += scnprintf(buf + i, sz - i, " %d", sk->sk_rcvbuf); | ||
| 3768 | i += scnprintf(buf + i, sz - i, " | %d\n", sk->sk_backlog.len); | ||
| 3769 | |||
| 3770 | if (dqueues & TIPC_DUMP_SK_SNDQ) { | ||
| 3771 | i += scnprintf(buf + i, sz - i, "sk_write_queue: "); | ||
| 3772 | i += tipc_list_dump(&sk->sk_write_queue, false, buf + i); | ||
| 3773 | } | ||
| 3774 | |||
| 3775 | if (dqueues & TIPC_DUMP_SK_RCVQ) { | ||
| 3776 | i += scnprintf(buf + i, sz - i, "sk_receive_queue: "); | ||
| 3777 | i += tipc_list_dump(&sk->sk_receive_queue, false, buf + i); | ||
| 3778 | } | ||
| 3779 | |||
| 3780 | if (dqueues & TIPC_DUMP_SK_BKLGQ) { | ||
| 3781 | i += scnprintf(buf + i, sz - i, "sk_backlog:\n head "); | ||
| 3782 | i += tipc_skb_dump(sk->sk_backlog.head, false, buf + i); | ||
| 3783 | if (sk->sk_backlog.tail != sk->sk_backlog.head) { | ||
| 3784 | i += scnprintf(buf + i, sz - i, " tail "); | ||
| 3785 | i += tipc_skb_dump(sk->sk_backlog.tail, false, | ||
| 3786 | buf + i); | ||
| 3787 | } | ||
| 3788 | } | ||
| 3789 | |||
| 3790 | return i; | ||
| 3791 | } | ||
