Home
Softono
ziti-tunnel-sdk-c

ziti-tunnel-sdk-c

Open source Apache-2.0 C
60
Stars
35
Forks
91
Issues
9
Watchers
1 week
Last Commit

About ziti-tunnel-sdk-c

The Ziti Tunneler SDK is a C library that provides protocol translation and shared functionality for building Ziti Tunnelers across supported operating systems. It handles common tasks including communicating with TCP/IP peers, mapping TCP/IP connections to Ziti sessions, and responding to DNS queries for Ziti service hostnames. Developers using the SDK only need to implement platform-specific functionality, such as creating a virtual network interface and providing a user interface. The SDK includes a set of callback functions that interact with a chosen ziti-sdk, and provides a built-in implementation of these callbacks for ziti-sdk-c. A minimal C tunneler application can be created by initializing the SDK with a network device and ziti-sdk callbacks, then specifying which services to expose. Docker images and multi-platform Linux crossbuild container instructions are also available for streamlined deployment and compilation.

Platforms

Web Self-hosted

Languages

C

Links

Apache 2.0 Latest Release Build Status

Ziti Tunneler SDK

The Ziti Tunneler SDK provides protocol translation and other common functions that are useful to Ziti Tunnelers.

What's a Ziti Tunneler?

The main article about tunnelers is here. Editors may follow the "Edit this page" link on every page.

What is the Ziti Tunneler SDK?

The Ziti Tunneler SDK provides functionality that is common to Ziti Tunnelers across supported operating systems:

  • Converse with TCP/IP peers
  • Map TCP/IP connections to Ziti sessions
  • Respond to DNS queries for Ziti service hostnames

A Ziti Tunneler application that uses the Ziti Tunneler SDK only needs to implement platform-specific functionality, such as creating a virtual network interface, and providing a user interface.

A set of callback functions that interact with the specific ziti-sdk that the application uses (e.g. ziti-sdk-c, ziti-sdk-go).

The Ziti Tunneler SDK includes an implementation of the required callback functions for ziti-sdk-c. Here's how a minimal tunneler application written in C could use the Ziti Tunneler SDK:

int main(int argc, char *argv[]) {
    uv_loop_t *nf_loop = uv_default_loop();
    netif_driver tun = tun_open(NULL, 0); /* open a tun device, and */

    if (tun == NULL) {
        fprintf(stderr, "failed to open network interface: %s\n", tun_error);
        return 1;
    }

    tunneler_sdk_options tunneler_opts = {
            .netif_driver = tun,
            .ziti_dial = ziti_sdk_c_dial,
            .ziti_close = ziti_sdk_c_close,
            .ziti_write = ziti_sdk_c_write
    };
    tunneler_context TUNNEL_CTX = NF_tunneler_init(&tunneler_opts, nf_loop);

    nf_options opts = {
            .init_cb = on_nf_init,
            .config = argv[1],
            .service_cb = on_service,
            .ctx = TUNNEL_CTX, /* this is passed to the service_cb */
            .refresh_interval = 10,
            .config_types = cfg_types,
    };

    if (NF_init_opts(&opts, nf_loop, NULL) != 0) {
        fprintf(stderr, "failed to initialize ziti\n");
        return 1;
    }

    if (uv_run(nf_loop, UV_RUN_DEFAULT) != 0) {
        fprintf(stderr, "failed to run event loop\n");
        exit(1);
    }

    free(TUNNEL_CTX);
    return 0;
}

Once the Ziti Tunneler SDK is initialized with a network device and ziti-sdk callbacks, a tunneler application only needs to indicate which service(s) that should be

Run with Docker

Refer to the Docker README for instructions to run ziti-edge-tunnel with Docker.

Multi-Platform Linux Crossbuild Container

Refer to the BUILD article for instructions to build ziti-edge-tunnel, including the crossbuild container image.