You've already forked mariadb-columnstore-engine
							
							
				mirror of
				https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
				synced 2025-11-03 17:13:17 +03:00 
			
		
		
		
	MCOL-547 - change to check for multiple ip address matches
This commit is contained in:
		@@ -53,10 +53,11 @@
 | 
				
			|||||||
#include <glob.h>
 | 
					#include <glob.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <arpa/inet.h>
 | 
					#include <arpa/inet.h>
 | 
				
			||||||
 | 
					#include <sys/socket.h>
 | 
				
			||||||
 | 
					#include <ifaddrs.h>
 | 
				
			||||||
#include <stdio.h>
 | 
					#include <stdio.h>
 | 
				
			||||||
#include <string.h> /* for strncpy */
 | 
					#include <string.h> /* for strncpy */
 | 
				
			||||||
#include <sys/types.h>
 | 
					#include <sys/types.h>
 | 
				
			||||||
#include <sys/socket.h>
 | 
					 | 
				
			||||||
#include <sys/ioctl.h>
 | 
					#include <sys/ioctl.h>
 | 
				
			||||||
#include <netinet/in.h>
 | 
					#include <netinet/in.h>
 | 
				
			||||||
#include <net/if.h>
 | 
					#include <net/if.h>
 | 
				
			||||||
@@ -433,43 +434,52 @@ int main(int argc, char *argv[])
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //check for local ip address as pm1
 | 
					    //check for local ip address as pm1
 | 
				
			||||||
        ModuleConfig moduleconfig;
 | 
					    ModuleConfig moduleconfig;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    try
 | 
					    try
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        oam.getSystemConfig("pm1", moduleconfig);
 | 
					        oam.getSystemConfig("pm1", moduleconfig);
 | 
				
			||||||
        HostConfigList::iterator pt1 = moduleconfig.hostConfigList.begin();
 | 
					        if (moduleconfig.hostConfigList.size() > 0 )
 | 
				
			||||||
        string PM1ipAdd = (*pt1).IPAddr;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if ( PM1ipAdd != "127.0.0.1")
 | 
					 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            // now get the local ip address
 | 
					            HostConfigList::iterator pt1 = moduleconfig.hostConfigList.begin();
 | 
				
			||||||
                        int fd;
 | 
					            string PM1ipAdd = (*pt1).IPAddr;
 | 
				
			||||||
            struct ifreq ifr;
 | 
					            cout << PM1ipAdd << endl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            fd = socket(AF_INET, SOCK_DGRAM, 0);
 | 
					            if ( PM1ipAdd != "127.0.0.1" && PM1ipAdd != "0.0.0.0")
 | 
				
			||||||
 | 
					 | 
				
			||||||
            /* I want to get an IPv4 IP address */
 | 
					 | 
				
			||||||
            ifr.ifr_addr.sa_family = AF_INET;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            /* I want IP address attached to "eth0" */
 | 
					 | 
				
			||||||
            strncpy(ifr.ifr_name, "eth0", IFNAMSIZ-1);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            ioctl(fd, SIOCGIFADDR, &ifr);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            close(fd);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            string localIPAddr = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if ( PM1ipAdd != localIPAddr )
 | 
					 | 
				
			||||||
            // configure pm1 and local ip address don't match, error out
 | 
					 | 
				
			||||||
            // can only install from pm1
 | 
					 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                cout << endl;
 | 
					                struct ifaddrs *ifap, *ifa;
 | 
				
			||||||
                cout << "ERROR: postConfigure install can only be done on the PM1" << endl;
 | 
					                struct sockaddr_in *sa;
 | 
				
			||||||
                cout << "designated node. The configured PM1 IP address doesn't match the local" << endl;
 | 
					                char *addr;
 | 
				
			||||||
                cout << "IP Address. exiting..." << endl;
 | 
					                bool found = false;
 | 
				
			||||||
                exit(1);
 | 
					
 | 
				
			||||||
 | 
					                getifaddrs (&ifap);
 | 
				
			||||||
 | 
					                for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
 | 
				
			||||||
 | 
					                    if (ifa->ifa_addr->sa_family==AF_INET) {
 | 
				
			||||||
 | 
					                        sa = (struct sockaddr_in *) ifa->ifa_addr;
 | 
				
			||||||
 | 
					                        addr = inet_ntoa(sa->sin_addr);
 | 
				
			||||||
 | 
					                        printf("Interface: %s\tAddress: %s\n", ifa->ifa_name, addr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        if ( PM1ipAdd == addr )
 | 
				
			||||||
 | 
					                        {
 | 
				
			||||||
 | 
												//match
 | 
				
			||||||
 | 
					                            found = true;
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    if (found)
 | 
				
			||||||
 | 
					                        break;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                freeifaddrs(ifap);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (!found)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    cout << endl;
 | 
				
			||||||
 | 
					                    cout << "ERROR: postConfigure install can only be done on the PM1" << endl;
 | 
				
			||||||
 | 
					                    cout << "designated node. The configured PM1 IP address doesn't match the local" << endl;
 | 
				
			||||||
 | 
					                    cout << "IP Address. exiting..." << endl;
 | 
				
			||||||
 | 
					                    exit(1);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -477,6 +487,7 @@ int main(int argc, char *argv[])
 | 
				
			|||||||
    {}
 | 
					    {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// run my.cnf upgrade script
 | 
						// run my.cnf upgrade script
 | 
				
			||||||
	if ( reuseConfig == "y" )
 | 
						if ( reuseConfig == "y" )
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user