Github user SolidWallOfCode commented on a diff in the pull request:

    https://github.com/apache/trafficserver/pull/843#discussion_r74256058
  
    --- Diff: plugins/experimental/carp/CarpConfigPool.cc ---
    @@ -0,0 +1,218 @@
    +/** @file
    +
    +  Manage a list of CARP configurations
    +
    +  @section license License
    +
    +  Licensed to the Apache Software Foundation (ASF) under one
    +  or more contributor license agreements.  See the NOTICE file
    +  distributed with this work for additional information
    +  regarding copyright ownership.  The ASF licenses this file
    +  to you under the Apache License, Version 2.0 (the
    +  "License"); you may not use this file except in compliance
    +  with the License.  You may obtain a copy of the License at
    +
    +      http://www.apache.org/licenses/LICENSE-2.0
    +
    +  Unless required by applicable law or agreed to in writing, software
    +  distributed under the License is distributed on an "AS IS" BASIS,
    +  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +  See the License for the specific language governing permissions and
    +  limitations under the License.
    + */
    +#include <sstream>
    +
    +#include "Common.h"
    +#include "CarpConfigPool.h"
    +#include "UrlComponents.h"
    +#include "CarpHost.h"
    +
    +#include <netdb.h>
    +#include <ts/ts.h>
    + 
    +using namespace std;
    +
    +/*******************************************************************/
    +CarpConfigPool::CarpConfigPool()
    +{
    +  _globalHash = NULL;
    +  _globalConfig = NULL;
    +}
    +
    +/*******************************************************************/
    +CarpConfigPool::~CarpConfigPool()
    +{
    +  for(CarpConfigListIter it=_configList.begin(); it != _configList.end(); 
it++) {
    +    it->second->_config->stop();
    +    delete it->second;
    +  }
    +}
    +/*******************************************************************/
    +static int initCarpConfigAndHash(CarpConfigAndHash * cch, string 
sFilename) {
    +  cch->_configPath = sFilename;
    +  cch->_config = new CarpConfig();
    +  TSAssert(cch->_config);
    +
    +  if (!cch->_config->loadConfig(sFilename)) {
    +    return -1;
    +  }
    +
    +  cch->_hashAlgo = new CarpHashAlgorithm(cch->_config);
    +
    +  TSAssert(cch->_hashAlgo);
    +
    +  CarpHostList* hostList = cch->_config->getHostList();
    +  // add hosts, etc to hash algo
    +  char szServerName[256];
    +  *szServerName = 0;
    +
    +  if (!gethostname(szServerName, 255)) { // success!
    +    TSDebug(DEBUG_TAG_INIT, "using %s as server name to detect 'self'",
    +        szServerName);
    +  }
    +  char buf[1024];
    +  struct hostent self, *selfhe = getHostIp(string(szServerName), &self, 
buf,
    +      sizeof(buf));
    +
    +  for (CarpHostListIter i = hostList->begin(); i != hostList->end(); i++) {
    +    HashNode *hashNode;
    +    bool bSelf = false;
    +    if (NULL != selfhe) { // check for 'self'
    +      // include hostname and port
    +      bSelf = isSelf((*i)->getName(), (*i)->getPort(), selfhe);
    +    }
    +    if (cch->_config->getHealthCheckPort() == -1) {        // did they 
specify 'PORT'?
    +      (*i)->setHealthCheckPort((*i)->getPort()); // set HC port from 
server spec'd port
    +    } else {
    +      (*i)->setHealthCheckPort(cch->_config->getHealthCheckPort()); // set 
HC port
    +    }
    +    string sHCUrl = cch->_config->getHealthCheckUrl();
    +    size_t pos = sHCUrl.find("{port}");
    +    if (pos != string::npos) { // need to replace '{port}' with servers 
port
    +      stringstream ss;
    +      ss << (*i)->getPort();
    +      sHCUrl.replace(pos, 6, ss.str()); // 6 = strlen of '{port}'
    +    }
    +    pos = sHCUrl.find("{host}");
    +    if (pos != string::npos) {
    +      sHCUrl.replace(pos, 6, (*i)->getName());
    +    }
    +    (*i)->setHealthCheckUrl(sHCUrl); // set HC Url
    +
    +    // Look up host and create addr struct for healthchecks
    +    char hBuf[1024];
    +    struct hostent host, *hosthe = getHostIp((*i)->getName(), &host, hBuf,
    +        sizeof(hBuf));
    +    if (hosthe) {
    +      // convert hostent to sockaddr_in structure
    +      sockaddr_in hIn;
    +      memcpy(&hIn.sin_addr, hosthe->h_addr_list[0], hosthe->h_length);
    +      hIn.sin_port = htons((*i)->getHealthCheckPort()); // set port
    +      if (hosthe->h_length == 4) { // size match IPv4? assume such
    --- End diff --
    
    If it's really an IP address the family member of the sockaddr should be 
checked, not the length.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to