summaryrefslogtreecommitdiff
path: root/ctdb/protocol/protocol_util.c
Commit message (Collapse)AuthorAgeFilesLines
* ctdb: Initialize addr struct to zero before reparsing as IPV4Zhu Shangzhong2019-03-261-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Failed to kill the tcp connection that using IPv4-mapped IPv6 address (e.g. ctdb_killtcp eth0 ::ffff:192.168.200.44:2049 ::ffff:192.168.200.45:863). When the ctdb_killtcp is used to kill the tcp connection, the IPs and ports in the connection will be parsed to conn.client and conn.server (call stack: main->ctdb_sock_addr_from_string->ip_from_string). In the ip_from_string, as we are using IPv4-mapped IPv6 addresses, the ipv6_from_string will be used to parse ip to addr.ip6 first. The next step the ipv4_from_string will be used to reparse ip to addr.ip. As a result, the data that dump from conn.server is "2 0 8 1 192 168 200 44 0 0 0 0 0 0 0 0 0 0 255 255 192 168 200 44 0 0 0 0", the data from conn.client is "2 0 3 95 192 168 200 45 0 0 0 0 0 0 0 0 0 0 255 255 192 168 200 45 0 0 0 0". The connection will be add to conn_list by ctdb_connection_list_add. Then the reset_connections_send uses conn_list as parameter to start to reset connections in the conn_list. In the reset_connections_send, the database "connections" will be created. The connections from conn_list will be written to the database(call db_hash_add), and use the data that dump from conn_client and conn_server as key. In the reset_connections_capture_tcp_handler, the ctdb_sys_read_tcp_packet will receive data on the raw socket. And extract the IPs and ports from the tcp packet. when extracting IP and port, the tcp4_extract OR tcp6_extract will be used. Then we got the new conn.client and conn.server. the data that dump from the conn.server is "2 0 8 1 192 168 200 44 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", the data from conn.client is "2 0 3 95 192 168 200 45 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0". Finally, we use the data as key to check if this connection is one being reset(call db_hash_delete). The db_hash_delete will return ENOENT. Because the two key that being used by db_hash_delete and db_hash_add are different. So, the TCP RST will be NOT sent for the connection forever. We should initialize addr struct to zero before reparsing as IPV4 in the ip_from_string. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13839 Signed-off-by: Zhu Shangzhong <zhu.shangzhong@zte.com.cn> Reviewed-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@samba.org> (cherry picked from commit 539b5ff32b32b7c75dfaaa119e41f5af6ff1e6fc)
* ctdb-common: Add fd argument to ctdb_connection_list_read()Amitay Isaacs2019-03-261-2/+4
| | | | | | | | | | This makes testing easier. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net> (cherry picked from commit 3bf753e830c20183ef4f3278880d3be362e53bef)
* ctdb-protocol: Avoid fgets in ctdb_connection_list_readAmitay Isaacs2019-03-261-37/+49
| | | | | | | | | | | C library buffering API can behave in unexpected fashion if underlying fd for stdin, stdout or stderr is closed and re-opened. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net> (cherry picked from commit c9b42d27e6cf9e6ae36f44970f0a388edc737a7a)
* ctdb-common: Use sin6_len only if the structure supports itAmitay Isaacs2018-07-101-1/+1
| | | | | | | | BUG: https://bugzilla.samba.org/show_bug.cgi?id=13493 Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net> (cherry picked from commit 79992dbb73ac9749ac987cb6a88964fa600b4c35)
* ctdb-protocol: Fix typo in type of return variableMartin Schwenke2017-10-161-1/+1
| | | | | | | This causes failures to be folded down to 1, which is incorrect. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Volker Lendecke <vl@samba.org>
* ctdb-protocol: Add ctdb_connection_list utilitiesMartin Schwenke2017-09-191-0/+144
| | | | | Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
* ctdb-protocol: Add ctdb_connection utilitiesMartin Schwenke2017-09-191-0/+95
| | | | | Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
* ctdb-protocol: Factor out static function ctdb_sock_addr_cmp_family()Martin Schwenke2017-09-191-4/+15
| | | | | Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
* ctdb-protocol: Add ctdb_sock_addr_from_string()Martin Schwenke2017-09-191-0/+126
| | | | | | | | | This and the supporting functions duplicate functionality (parse_ip() and parse_ip_port()) from common/system_util.c. The old functions will be removed at a later time. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
* ctdb-protocol: Optionally print port for address printing functionsMartin Schwenke2017-09-191-3/+16
| | | | | Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
* ctdb-protocol: Add utility function ctdb_sock_addr_to_buf()Martin Schwenke2017-09-191-12/+34
| | | | | Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
* ctdb-protocol: Add ctdb_sock_addr_port() and sock_addr_set_port()Martin Schwenke2017-09-191-0/+28
| | | | | Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
* ctdb-build: Split protocol-util as a separate subsystemMartin Schwenke2017-09-191-3/+1
| | | | | Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
* ctdb-protocol: Add generalised socket address comparisonMartin Schwenke2016-12-161-21/+47
| | | | | | | | | | | | | Add new function ctdb_sock_addr_cmp(), which returns a 3-way result useful for qsort(3). Reimplent ctdb_sock_addr_same() using this. In the process, make arguments const so that ctdb_sock_addr_cmp() can be used with qsort(). BUG: https://bugzilla.samba.org/show_bug.cgi?id=12470 Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
* ctdb-protocol: Add function ctdb_sock_addr_same_ipAmitay Isaacs2016-07-281-4/+24
| | | | | | | | ... to check if only the addresses are the same. Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Martin Schwenke <martin@meltin.net>
* ctdb-protocol: Add function to compare ctdb_sock_addrAmitay Isaacs2016-05-101-0/+33
| | | | | Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
* ctdb-protocol: Add utility function ctdb_sock_addr_to_stringAmitay Isaacs2015-11-251-0/+28
| | | | | | | | | | This is a duplicate function to ctdb_addr_to_str, but ctdb-util cannot be linked with the code using new API mainly because it code in ctdb-util requires struct ctdb_context. Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Jeremy Allison <jra@samba.org>
* ctdb-protocol: Add ctdb protocol serialization routinesAmitay Isaacs2015-10-071-0/+114
Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>