1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-03 12:58:35 +03:00

we don't need the is_loopback logic in ctdb any more

(This used to be ctdb commit 4ecf29ade0099c7180932288191de9840c8d90a9)
This commit is contained in:
Andrew Tridgell 2007-09-13 10:45:06 +10:00
parent 4f261ae191
commit 3c0f61cb92
4 changed files with 14 additions and 120 deletions

View File

@ -165,15 +165,11 @@ int ctdb_sys_send_tcp(int s,
we try to bind to it, and if that fails then we don't have that IP
on an interface
*/
bool ctdb_sys_have_ip(struct sockaddr_in ip, bool *is_loopback, TALLOC_CTX *mem_ctx, char **ifname)
bool ctdb_sys_have_ip(struct sockaddr_in ip)
{
int s;
int ret;
if (is_loopback) {
DEBUG(0,(__location__ " NOT IMPLEMENTED YET: ctdb_sys_have_ip() does not yet support is_loopback on AIX. This needs to be implemented similar to system_linux.c\n"));
}
ip.sin_port = 0;
s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s == -1) {

View File

@ -241,100 +241,20 @@ int ctdb_sys_send_tcp(int s,
we try to bind to it, and if that fails then we don't have that IP
on an interface
if is_loopback is specified it will also return whether the ip address
is attached to the loopback interface or not
ifname, if non-NULL, will return the name of the interface this ip is tied to
*/
bool ctdb_sys_have_ip(struct sockaddr_in ip, bool *is_loopback, TALLOC_CTX *mem_ctx, char **ifname)
bool ctdb_sys_have_ip(struct sockaddr_in ip)
{
struct ifreq *ifr = NULL;
struct ifconf ifc;
int s, i, num_ifs;
int s;
int ret;
if (is_loopback) {
*is_loopback = false;
}
if (*ifname) {
*ifname = NULL;
}
ip.sin_port = 0;
s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s == -1) {
return false;
}
ret = bind(s, (struct sockaddr *)&ip, sizeof(ip));
if (ret) {
goto finished;
}
/* find out how much space we need to store the interface details */
ifc.ifc_len = 0;
ifc.ifc_req = NULL;
ret = ioctl(s, SIOCGIFCONF, &ifc);
if (ret) {
DEBUG(0,(__location__ " ioctl to read interface list failed\n"));
goto finished;
}
ifr = talloc_size(mem_ctx, ifc.ifc_len);
/* get a list of all interface names and addresses */
ifc.ifc_req = ifr;
ret = ioctl(s, SIOCGIFCONF, &ifc);
if (ret) {
DEBUG(0,(__location__ " ioctl to read interface list failed\n"));
goto finished;
}
/* loop over all interfaces and search for the one matching ip */
num_ifs = ifc.ifc_len/sizeof(struct ifreq);
for (i=0; i<num_ifs;i++) {
struct sockaddr_in *sa;
/* we only care bout ipv4 addresses */
sa = (struct sockaddr_in *)&ifr[i].ifr_addr;
if (sa->sin_family != AF_INET) {
continue;
}
/* this is not the interface you are looking for */
if (!ctdb_same_ip(sa, &ip)) {
continue;
}
/* this is the ifr entry for this interface/address
read the interface flags so we can tell if it is
loopback or not
*/
ret = ioctl(s, SIOCGIFFLAGS, &ifr[i]);
if (ret) {
DEBUG(0,(__location__ " failed to read interface flags for interface %s\n", ifr[i].ifr_name));
goto finished;
}
/* was this ip tied to a loopback interface ? */
if (ifr[i].ifr_flags & IFF_LOOPBACK) {
if (is_loopback != NULL) {
*is_loopback = true;
}
}
if (ifname) {
*ifname = talloc_asprintf(mem_ctx, "%s", ifr[i].ifr_name);
}
/* if we got this far, we have found our interface so we can
exit the loop.
*/
break;
}
finished:
talloc_free(ifr);
close(s);
return ret == 0;
}

View File

@ -1062,7 +1062,7 @@ int ctdb_ctrl_get_public_ips(struct ctdb_context *ctdb,
/* from takeover/system.c */
int ctdb_sys_send_arp(const struct sockaddr_in *saddr, const char *iface);
bool ctdb_sys_have_ip(struct sockaddr_in ip, bool *is_loopback, TALLOC_CTX *mem_ctx, char **ifname);
bool ctdb_sys_have_ip(struct sockaddr_in ip);
int ctdb_sys_send_tcp(int fd,
const struct sockaddr_in *dest,
const struct sockaddr_in *src,

View File

@ -205,29 +205,22 @@ int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb,
TDB_DATA indata,
bool *async_reply)
{
TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
int ret;
struct takeover_callback_state *state;
struct ctdb_public_ip *pip = (struct ctdb_public_ip *)indata.dptr;
struct ctdb_vnn *vnn;
bool have_ip, is_loopback;
char *ifname = NULL;
/* update out vnn list */
vnn = find_public_ip_vnn(ctdb, pip->sin);
if (vnn == NULL) {
DEBUG(0,("takeoverip called for an ip '%s' that is not a public address\n",
inet_ntoa(pip->sin.sin_addr)));
talloc_free(tmp_ctx);
return 0;
}
vnn->pnn = pip->pnn;
/* if our kernel already has this IP, do nothing */
have_ip = ctdb_sys_have_ip(pip->sin, &is_loopback, tmp_ctx, &ifname);
/* if we have the ip and it is not set to a loopback address */
if (have_ip && !is_loopback) {
talloc_free(tmp_ctx);
if (ctdb_sys_have_ip(pip->sin)) {
return 0;
}
@ -257,7 +250,6 @@ int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb,
if (ret != 0) {
DEBUG(0,(__location__ " Failed to takeover IP %s on interface %s\n",
inet_ntoa(pip->sin.sin_addr), vnn->iface));
talloc_free(tmp_ctx);
talloc_free(state);
return -1;
}
@ -265,7 +257,6 @@ int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb,
/* tell ctdb_control.c that we will be replying asynchronously */
*async_reply = true;
talloc_free(tmp_ctx);
return 0;
}
@ -334,20 +325,16 @@ int32_t ctdb_control_release_ip(struct ctdb_context *ctdb,
TDB_DATA indata,
bool *async_reply)
{
TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
int ret;
struct takeover_callback_state *state;
struct ctdb_public_ip *pip = (struct ctdb_public_ip *)indata.dptr;
struct ctdb_vnn *vnn;
bool have_ip, is_loopback;
char *ifname = NULL;
/* update our vnn list */
vnn = find_public_ip_vnn(ctdb, pip->sin);
if (vnn == NULL) {
DEBUG(0,("releaseip called for an ip '%s' that is not a public address\n",
inet_ntoa(pip->sin.sin_addr)));
talloc_free(tmp_ctx);
return 0;
}
vnn->pnn = pip->pnn;
@ -356,12 +343,10 @@ int32_t ctdb_control_release_ip(struct ctdb_context *ctdb,
talloc_free(vnn->takeover_ctx);
vnn->takeover_ctx = NULL;
have_ip = ctdb_sys_have_ip(pip->sin, &is_loopback, tmp_ctx, &ifname);
if ( (!have_ip) || is_loopback) {
DEBUG(0,("Redundant release of IP %s/%u on interface %s (ip not held)\n",
if (!ctdb_sys_have_ip(pip->sin)) {
DEBUG(2,("Redundant release of IP %s/%u on interface %s (ip not held)\n",
inet_ntoa(pip->sin.sin_addr), vnn->public_netmask_bits,
vnn->iface));
talloc_free(tmp_ctx);
return 0;
}
@ -391,15 +376,12 @@ int32_t ctdb_control_release_ip(struct ctdb_context *ctdb,
if (ret != 0) {
DEBUG(0,(__location__ " Failed to release IP %s on interface %s\n",
inet_ntoa(pip->sin.sin_addr), vnn->iface));
talloc_free(tmp_ctx);
talloc_free(state);
return -1;
}
/* tell the control that we will be reply asynchronously */
*async_reply = true;
talloc_free(tmp_ctx);
return 0;
}
@ -1147,21 +1129,17 @@ void ctdb_takeover_client_destructor_hook(struct ctdb_client *client)
void ctdb_release_all_ips(struct ctdb_context *ctdb)
{
struct ctdb_vnn *vnn;
TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
bool have_ip, is_loopback;
char *ifname = NULL;
for (vnn=ctdb->vnn;vnn;vnn=vnn->next) {
have_ip = ctdb_sys_have_ip(vnn->public_address, &is_loopback, tmp_ctx, &ifname);
if (have_ip && !is_loopback) {
ctdb_event_script(ctdb, "releaseip %s %s %u",
vnn->iface,
inet_ntoa(vnn->public_address.sin_addr),
vnn->public_netmask_bits);
release_kill_clients(ctdb, vnn->public_address);
if (!ctdb_sys_have_ip(vnn->public_address)) {
continue;
}
ctdb_event_script(ctdb, "releaseip %s %s %u",
vnn->iface,
inet_ntoa(vnn->public_address.sin_addr),
vnn->public_netmask_bits);
release_kill_clients(ctdb, vnn->public_address);
}
talloc_free(tmp_ctx);
}