Skip to content
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

cleanup code dealing with lack of updated API #616

Merged
merged 3 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions inc_internal/internal_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ XX(service_hosting_costs, int, map, serviceHostingCosts, __VA_ARGS__)
#define ZITI_EDGE_ROUTER_MODEL(XX, ...)\
XX(name, string, none, name, __VA_ARGS__)\
XX(hostname, string, none, hostname, __VA_ARGS__) \
XX(protocols, string, map, supportedProtocols, __VA_ARGS__) \
XX(ingress, string, map, urls, __VA_ARGS__) /* deprecated */
XX(protocols, string, map, supportedProtocols, __VA_ARGS__)

#define ZITI_NET_SESSION_MODEL(XX, ...) \
XX(token, string, none, token, __VA_ARGS__)\
Expand Down
5 changes: 0 additions & 5 deletions inc_internal/zt_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,18 +285,13 @@ struct ziti_ctx {
// map<service_id,*bool>
model_map service_forced_updates;

bool no_service_updates_api; // controller API has no last-update endpoint
bool no_bulk_posture_response_api; // controller API does not support bulk posture response submission
bool no_current_edge_routers;

char *last_update;

uv_timer_t *api_session_timer;
uv_timer_t *service_refresh_timer;
uv_prepare_t *prepper;

uv_loop_t *loop;
uv_thread_t loop_thread;

// map<erUrl,ziti_channel>
model_map channels;
Expand Down
3 changes: 0 additions & 3 deletions library/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,6 @@

MODEL_LIST_FOREACH(er, session->edge_routers) {
const char *tls = model_map_get(&er->protocols, "tls");
if (tls == NULL) {
tls = model_map_get(&er->ingress, "tls");
}

if (tls) {
ziti_channel_t *ch = model_map_get(&ztx->channels, tls);
Expand Down Expand Up @@ -898,7 +895,7 @@
}
}

CATCH(crypto) {

Check warning on line 898 in library/connect.c

View workflow job for this annotation

GitHub Actions / Windows x86_64

unreachable code [D:\a\ziti-sdk-c\ziti-sdk-c\build\library\ziti.vcxproj]

Check warning on line 898 in library/connect.c

View workflow job for this annotation

GitHub Actions / Windows ARM64

unreachable code [D:\a\ziti-sdk-c\ziti-sdk-c\build\library\ziti.vcxproj]
FREE(plain_text);
conn_set_state(conn, Disconnected);
conn->data_cb(conn, NULL, ZITI_CRYPTO_FAIL);
Expand Down
9 changes: 1 addition & 8 deletions library/posture.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,6 @@ static void ziti_pr_post_bulk_cb(ziti_pr_response *pr_resp, const ziti_error *er
if (err != NULL) {
ZTX_LOG(ERROR, "error during bulk posture response submission (%d) %s", err->http_code, err->message);
ztx->posture_checks->must_send = true; //error, must try again
if (err->http_code == 404) {
ztx->no_bulk_posture_response_api = true;
}
} else {
ztx->posture_checks->must_send = false; //did not error, can skip submissions
handle_pr_resp_timer_events(ztx, pr_resp);
Expand Down Expand Up @@ -508,11 +505,7 @@ static void ziti_pr_post_cb(ziti_pr_response *pr_resp, const ziti_error *err, vo
}

static void ziti_pr_send(ziti_context ztx) {
if (ztx->no_bulk_posture_response_api) {
ziti_pr_send_individually(ztx);
} else {
ziti_pr_send_bulk(ztx);
}
ziti_pr_send_bulk(ztx);
}

static void ziti_pr_send_bulk(ziti_context ztx) {
Expand Down
24 changes: 6 additions & 18 deletions library/ziti.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,14 @@
ziti_context ctx = NULL;
PREPF(ziti, ziti_errorstr);

if (options->config == NULL) {

Check warning on line 210 in library/ziti.c

View workflow job for this annotation

GitHub Actions / Linux x86_64

'config' is deprecated: ignored, will be removed [-Wdeprecated-declarations]

Check warning on line 210 in library/ziti.c

View workflow job for this annotation

GitHub Actions / Linux ARM64

'config' is deprecated: ignored, will be removed [-Wdeprecated-declarations]
ZITI_LOG(ERROR, "config or controller/tls has to be set");
return ZITI_INVALID_CONFIG;
}
ctx = calloc(1, sizeof(*ctx));

if (options->config != NULL) {

Check warning on line 216 in library/ziti.c

View workflow job for this annotation

GitHub Actions / Linux x86_64

'config' is deprecated: ignored, will be removed [-Wdeprecated-declarations]

Check warning on line 216 in library/ziti.c

View workflow job for this annotation

GitHub Actions / Linux ARM64

'config' is deprecated: ignored, will be removed [-Wdeprecated-declarations]
TRY(ziti, ziti_load_config(&ctx->config, options->config));

Check warning on line 217 in library/ziti.c

View workflow job for this annotation

GitHub Actions / Linux ARM64

'config' is deprecated: ignored, will be removed [-Wdeprecated-declarations]
}

if (ctx->config.id.ca && strncmp(ctx->config.id.ca, "file://", strlen("file://")) == 0) {
Expand Down Expand Up @@ -1251,10 +1251,8 @@
bool need_update = true;

if (err) { // API not supported - do refresh
if (err->http_code == 404) {
ZTX_LOG(INFO, "Controller does not support /current-api-session/service-updates API");
ztx->no_service_updates_api = true;
}
ZTX_LOG(WARN, "failed to poll service updates: code[%d] err[%d/%s]",
err->http_code, err->err, err->message);
if (err->err == ZITI_DISABLED) {
need_update = false;
}
Expand Down Expand Up @@ -1289,15 +1287,9 @@
return;
}

if (!ztx->no_current_edge_routers) {
ziti_ctrl_current_edge_routers(&ztx->controller, edge_routers_cb, ztx);
}
ziti_ctrl_current_edge_routers(&ztx->controller, edge_routers_cb, ztx);

if (ztx->no_service_updates_api) {
ziti_ctrl_get_services(&ztx->controller, update_services, ztx);
} else {
ziti_ctrl_get_services_update(&ztx->controller, check_service_update, ztx);
}
ziti_ctrl_get_services_update(&ztx->controller, check_service_update, ztx);
}

void ziti_services_refresh(ziti_context ztx, bool now) {
Expand All @@ -1316,11 +1308,8 @@
ziti_context ztx = ctx;

if (err) {
if (err->http_code == 404) {
ztx->no_current_edge_routers = true;
} else {
ZTX_LOG(ERROR, "failed to get current edge routers: %s/%s", err->code, err->message);
}
ZTX_LOG(ERROR, "failed to get current edge routers: code[%d] %s/%s",
err->http_code, err->code, err->message);
return;
}

Expand Down Expand Up @@ -1592,7 +1581,6 @@
static void api_session_cb(ziti_api_session *session, const ziti_error *err, void *ctx) {
struct ziti_init_req *init_req = ctx;
ziti_context ztx = init_req->ztx;
ztx->loop_thread = uv_thread_self();
ztx->active_session_request = false;

int errCode = err ? err->err : ZITI_OK;
Expand Down
139 changes: 107 additions & 32 deletions tests/test_ziti_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,46 +64,121 @@ TEST_CASE("posture response response", "[model]") {

TEST_CASE("multi-edge-router session", "[model]") {

const char *ns = "{\n"
" \"_links\": {\n"
" \"self\": {\n"
" \"href\": \"./sessions/1276df75-3ba3-4658-98ad-fe5a0e96021a\"\n"
" }\n"
" },\n"
" \"edgeRouters\": [\n"
" {\n"
" \"hostname\": \"ec2-18-223-205-231.us-east-2.compute.amazonaws.com\",\n"
" \"name\": \"ziti-bridge-us-east\",\n"
" \"urls\": {\n"
" \"tls\": \"tls://ec2-18-223-205-231.us-east-2.compute.amazonaws.com:3022\"\n"
" }\n"
" },\n"
" {\n"
" \"hostname\": \"ec2-18-188-224-88.us-east-2.compute.amazonaws.com\","
" \"name\": \"Test123\","
" \"urls\": {"
" \"tls\": \"tls://ec2-18-188-224-88.us-east-2.compute.amazonaws.com:3022\""
" }"
" }\n"
" ],\n"
" \"id\": \"1276df75-3ba3-4658-98ad-fe5a0e96021a\",\n"
" \"token\": \"caaf0f67-5394-4ddd-b718-bfdc8fcfb367\"\n"
"}";

const char *session_json = R"(
{
"_links": {
"route-path": {
"href": "./sessions/cls4w5p6w3nophj1hg3hh9grz/route-path"
},
"self": {
"href": "./sessions/cls4w5p6w3nophj1hg3hh9grz"
}
},
"createdAt": "2024-02-02T17:00:29.768Z",
"id": "cls4w5p6w3nophj1hg3hh9grz",
"tags": {},
"updatedAt": "2024-02-02T17:00:29.768Z",
"apiSession": {
"_links": {
"self": {
"href": "./api-sessions/cls4w569t3nnwhj1h5gca2mtb"
},
"sessions": {
"href": "./api-sessions/cls4w569t3nnwhj1h5gca2mtb/sessions"
}
},
"entity": "api-sessions",
"id": "cls4w569t3nnwhj1h5gca2mtb"
},
"apiSessionId": "cls4w569t3nnwhj1h5gca2mtb",
"edgeRouters": [
{
"cost": 0,
"disabled": false,
"hostname": "eccfca4e-b9ea-45c4-a26c-f61ce2acf6f5.production.netfoundry.io",
"isOnline": true,
"name": "Mattermost-Public-Edge-aws-ashburn-us-east-1-1",
"noTraversal": false,
"supportedProtocols": {
"tls": "tls://eccfca4e-b9ea-45c4-a26c-f61ce2acf6f5.production.netfoundry.io:443"
},
"syncStatus": "SYNC_DONE",
"urls": {
"tls": "tls://eccfca4e-b9ea-45c4-a26c-f61ce2acf6f5.production.netfoundry.io:443"
}
},
{
"cost": 0,
"disabled": false,
"hostname": "cd938be5-bd0b-48b3-8db8-67e4bf62eb10.production.netfoundry.io",
"isOnline": true,
"name": "Mattermost-Public-Edge-aws-mumbai-ap-south-1-1",
"noTraversal": false,
"supportedProtocols": {
"tls": "tls://cd938be5-bd0b-48b3-8db8-67e4bf62eb10.production.netfoundry.io:443"
},
"syncStatus": "SYNC_DONE",
"urls": {
"tls": "tls://cd938be5-bd0b-48b3-8db8-67e4bf62eb10.production.netfoundry.io:443"
}
},
{
"cost": 0,
"disabled": false,
"hostname": "0886eaea-5d1a-440d-b1a2-1db9e6d5c04d.production.netfoundry.io",
"isOnline": true,
"name": "Mattermost-Public-Edge-aws-boardman-us-west-2-1",
"noTraversal": false,
"supportedProtocols": {
"tls": "tls://0886eaea-5d1a-440d-b1a2-1db9e6d5c04d.production.netfoundry.io:443"
},
"syncStatus": "SYNC_DONE",
"urls": {
"tls": "tls://0886eaea-5d1a-440d-b1a2-1db9e6d5c04d.production.netfoundry.io:443"
}
}
],
"identityId": "CKr13vQdE",
"service": {
"_links": {
"configs": {
"href": "./services/f.n.2z-Xe/configs"
},
"self": {
"href": "./services/f.n.2z-Xe"
},
"service-edge-router-policies": {
"href": "./services/f.n.2z-Xe/service-edge-router-policies"
},
"service-policies": {
"href": "./services/f.n.2z-Xe/service-policies"
},
"terminators": {
"href": "./services/f.n.2z-Xe/terminators"
}
},
"entity": "services",
"id": "f.n.2z-Xe",
"name": "mattermost.tools.netfoundry.io"
},
"serviceId": "f.n.2z-Xe",
"token": "f49bbb5c-4623-4ae0-9e88-b6ea226434dc",
"type": "Dial"
})";
ziti_net_session *s;
int rc = parse_ziti_net_session_ptr(&s, ns, (int) strlen(ns));
REQUIRE(parse_ziti_net_session_ptr(&s, session_json, (int) strlen(session_json)) == strlen(session_json));

REQUIRE(model_list_size(&s->edge_routers) == 2);
REQUIRE(model_list_size(&s->edge_routers) == 3);

auto it = model_list_iterator(&s->edge_routers);
auto er = (ziti_edge_router *) model_list_it_element(it);
auto tls = (const char *) model_map_get(&er->ingress, "tls");
REQUIRE_THAT(tls, Catch::Matchers::Matches("tls://ec2-18-223-205-231.us-east-2.compute.amazonaws.com:3022"));
auto tls = (const char *) model_map_get(&er->protocols, "tls");
REQUIRE_THAT(tls, Catch::Matchers::Matches("tls://eccfca4e-b9ea-45c4-a26c-f61ce2acf6f5.production.netfoundry.io:443"));

it = model_list_it_next(it);
er = (ziti_edge_router *) model_list_it_element(it);
tls = (const char *) model_map_get(&er->ingress, "tls");
REQUIRE_THAT(tls, Catch::Matchers::Matches("tls://ec2-18-188-224-88.us-east-2.compute.amazonaws.com:3022"));
tls = (const char *) model_map_get(&er->protocols, "tls");
REQUIRE_THAT(tls, Catch::Matchers::Matches("tls://cd938be5-bd0b-48b3-8db8-67e4bf62eb10.production.netfoundry.io:443"));

free_ziti_net_session(s);
free(s);
Expand Down
Loading