Skip to content

Commit

Permalink
Fix Health Check HTTP url parsing
Browse files Browse the repository at this point in the history
Issue:
------
usage of same variable name in local scope caused the
parsed value being destroyed with the scope, causing
url path to remain unset

Fix:
----
use http_parser to parse url provided for HTTP method,
where in case of error agent fall backs to use
http://<interface_primary_ip>/ as health check url

Closes-Bug: 1533606
Closes-Bug: 1533608
Related-Bug: 1530539
Change-Id: I60773eaef30b10008c693254de51933553b9561f
  • Loading branch information
Prabhjot Singh Sethi committed Feb 1, 2016
1 parent 11324c3 commit c12c746
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def execute_util(self, ip, timeout, uri, out_fd):

class HealthCheckHttp(HealthCheckBase):
def execute_util(self, ip, timeout, uri, out_fd):
return call(["curl", "-m" + str(timeout), "http://" + ip + "/" + uri],
return call(["curl", "-m" + str(timeout), "http://" + ip + uri],
stdout=out_fd, stderr=out_fd)

def HealthCheckService(x):
Expand Down
26 changes: 15 additions & 11 deletions src/vnsw/agent/oper/health_check.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
*/

#include "http_parser/http_parser.h"

#include <boost/uuid/uuid_io.hpp>
#include <boost/algorithm/string/case_conv.hpp>

Expand Down Expand Up @@ -414,17 +416,19 @@ static HealthCheckServiceData *BuildData(Agent *agent, IFMapNode *node,
dest_ip = Ip4Address::from_string(p.url_path, ec);
url_path = p.url_path;
} else {
std::string url = p.url_path;
boost::algorithm::to_lower(url);
std::size_t found = url.find("http://");
assert(found == 0);
std::string url_path = p.url_path.substr(7);
found = url_path.find("/");
assert(found != 0);
std::string dest_ip_str = p.url_path.substr(7, found);
url_path = p.url_path.substr(7 + found + 1);
boost::system::error_code ec;
dest_ip = Ip4Address::from_string(dest_ip_str, ec);
struct http_parser_url urldata;
int ret = http_parser_parse_url(p.url_path.c_str(), p.url_path.size(),
false, &urldata);
if (ret == 0) {
std::string dest_ip_str =
p.url_path.substr(urldata.field_data[UF_HOST].off,
urldata.field_data[UF_HOST].len);
// Parse dest-ip from the url to translate to metadata IP
dest_ip = Ip4Address::from_string(dest_ip_str, ec);
// keep rest of the url string as is
url_path = p.url_path.substr(urldata.field_data[UF_HOST].off +\
urldata.field_data[UF_HOST].len);
}
}
HealthCheckServiceData *data =
new HealthCheckServiceData(agent, dest_ip, node->name(),
Expand Down

0 comments on commit c12c746

Please sign in to comment.