-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
zitilib: populate dial_identity according to intercept.dial_options.identity
#722
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -587,6 +587,42 @@ static const char* find_service(ztx_wrap_t *wrap, int type, const char *host, ui | |
return best; | ||
} | ||
|
||
const char *fmt_identity(const ziti_intercept_cfg_v1 *intercept, const char* proto, const char *host, int port) { | ||
if (intercept == NULL) return NULL; | ||
|
||
tag *id_tag = model_map_get(&intercept->dial_options, "identity"); | ||
if (id_tag == NULL || id_tag->type != tag_string) { | ||
return NULL; | ||
} | ||
|
||
static char identity[1024]; | ||
const char *p = id_tag->string_value; | ||
char *o = identity; | ||
while(*p != 0) { | ||
if (*p == '$') { | ||
p++; | ||
if (strncmp(p, "dst_protocol", strlen("dst_protocol")) == 0) { | ||
o += snprintf(o, sizeof(identity) - (o - identity), "%s", proto); | ||
p += strlen("dst_protocol"); | ||
} | ||
if (strncmp(p, "dst_hostname", strlen("dst_hostname")) == 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't these be else ifs? why do the if's if not needed? |
||
o += snprintf(o, sizeof(identity) - (o - identity), "%s", host); | ||
p += strlen("dst_hostname"); | ||
} | ||
if (strncmp(p, "dst_port", strlen("dst_port")) == 0) { | ||
o += snprintf(o, sizeof(identity) - (o - identity), "%d", port); | ||
p += strlen("dst_port"); | ||
} | ||
} else { | ||
*o++ = *p++; | ||
} | ||
|
||
if (o >= identity + sizeof(identity)) | ||
break; | ||
} | ||
return identity; | ||
} | ||
|
||
static void do_ziti_connect(struct conn_req_s *req, future_t *f, uv_loop_t *l) { | ||
ZITI_LOG(DEBUG, "connecting fd[%d] to %s:%d", req->fd, req->host, req->port); | ||
ziti_sock_t *zs = model_map_get_key(&ziti_sockets, &req->fd, sizeof(req->fd)); | ||
|
@@ -611,6 +647,7 @@ static void do_ziti_connect(struct conn_req_s *req, future_t *f, uv_loop_t *l) { | |
host = req->host; | ||
} | ||
|
||
ziti_intercept_cfg_v1 *intercept = NULL; | ||
if (req->ztx == NULL) { | ||
MODEL_MAP_FOR(it, ziti_contexts) { | ||
ztx_wrap_t *wrap = model_map_it_value(it); | ||
|
@@ -619,6 +656,7 @@ static void do_ziti_connect(struct conn_req_s *req, future_t *f, uv_loop_t *l) { | |
if (service_name != NULL) { | ||
req->ztx = wrap->ztx; | ||
req->service = service_name; | ||
intercept = model_map_get(&wrap->intercepts, service_name); | ||
break; | ||
} | ||
} | ||
|
@@ -638,10 +676,13 @@ static void do_ziti_connect(struct conn_req_s *req, future_t *f, uv_loop_t *l) { | |
size_t len = snprintf(app_data, sizeof(app_data), | ||
"{\"dst_protocol\": \"%s\", \"dst_hostname\": \"%s\", \"dst_port\": \"%u\"}", | ||
proto_str, req->host, req->port); | ||
|
||
ziti_dial_opts opts = { | ||
.app_data = app_data, | ||
.app_data_sz = len, | ||
.identity = req->terminator, | ||
.identity = (char*)(req->terminator ? | ||
req->terminator : | ||
fmt_identity(intercept, proto_str, req->host, req->port)), | ||
}; | ||
ZITI_LOG(DEBUG, "connecting fd[%d] to service[%s]", zs->fd, req->service); | ||
ziti_dial_with_options(zs->conn, req->service, &opts, on_ziti_connect, NULL); | ||
|
@@ -690,7 +731,7 @@ int Ziti_connect(ziti_socket_t socket, ziti_context ztx, const char *service, co | |
.fd = socket, | ||
.ztx = ztx, | ||
.service = service, | ||
.terminator = terminator, | ||
.terminator = terminator ? strdup(terminator) : NULL, | ||
}; | ||
|
||
future_t *f = schedule_on_loop((loop_work_cb) do_ziti_connect, &req, true); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dst_protocol, dst_hostname, dst_port are used here multiple times as well as used in
library/ziti_src.c
andlibrary/zitilib.c
too... it feel like it should be centralized... maybe defined in a single location?