Skip to main content

krun_set_port_map

Function krun_set_port_map 

Source
pub unsafe extern "C" fn krun_set_port_map(
    ctx_id: u32,
    port_map: *const *const c_char,
) -> i32
Expand description

Configures a map of host to guest TCP ports for the microVM.

Arguments: “ctx_id” - the configuration context ID. “port_map” - an array of string pointers with format “host_port:guest_port”

Returns: Zero on success or a negative error number on failure. Documented errors: -ENOTSUP when passt networking is used

Notes: Passing NULL (or not calling this function) as “port_map” has a different meaning than passing an empty array. The first one will instruct libkrun to attempt to expose all listening ports in the guest to the host, while the second means that no port from the guest will be exposed to host.

Exposed ports will only become accessible by their “host_port” in the guest too. This means that for a map such as “8080:80”, applications running inside the guest will also need to access the service through the “8080” port.

If past networking mode is used (krun_set_passt_fd was called), port mapping is not supported as an API of libkrun (but you can still do port mapping using command line arguments of passt)