Skip to content
Draft
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Compiled binaries and intermediate build files
qlinq-app
qlinq-emcon
qlinq-tun
libqlinq.a
/.build-config
Expand All @@ -18,6 +19,11 @@ t/assets/
/t/00util/test_datagram_mtu
/t/00util/test_directional_subscriptions
/t/00util/test_egress_errors
/t/00util/test_emcon_activation
/t/00util/test_emcon_manifest
/t/00util/test_emcon_rateless
/t/00util/test_emcon_receive_socket
/t/00util/test_emcon_session
/t/00util/test_fec
/t/00util/test_flexicast_regressions
/t/00util/test_flexicast_scale
Expand Down
47 changes: 43 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ endif
endif

# Include paths: use -isystem for quicly and picotls to suppress warning headers
INCLUDES = -Isrc/common -Ideps/nanors -Ideps/nanors/deps/obl -Ideps/nanorq/include -Ideps/nanorq/deps -isystem deps/quicly/include -isystem deps/quicly/deps/picotls/include -Ideps/quicly/deps/klib $(INCLUDES_OPENSSL)
INCLUDES = -Isrc/common -Ideps/nanors -Ideps/nanors/deps/obl -Ideps/nanorq/include -Ideps/nanorq/deps -isystem deps/quicly/include -isystem deps/quicly/lib -isystem deps/quicly/deps/picotls/include -Ideps/quicly/deps/klib $(INCLUDES_OPENSSL)

QUICLY_SRCS = deps/quicly/lib/quicly.c \
deps/quicly/lib/flexicast.c \
Expand Down Expand Up @@ -150,6 +150,16 @@ COMMON_OBJS = $(TRANSPORT_OBJS)

APP_OBJS = src/app/main.o src/app/xfer.o src/app/xfer_file.o

EMCON_OBJS = src/emcon/emcon_activation.o \
src/emcon/emcon_manifest.o \
src/emcon/emcon_rateless.o \
src/emcon/emcon_socket.o \
src/emcon/emcon_session.o \
src/common/cli_parse.o \
src/common/transport_memory.o \
src/common/transport_wire.o \
$(FEC_OBJS) $(QUICLY_OBJS)

FEC_OBJS = src/common/fec.o \
deps/nanors/rs.o \
deps/nanors/deps/obl/oblas_common.o \
Expand Down Expand Up @@ -203,7 +213,7 @@ deps/nanors/%.o deps/nanorq/%.o: private CODEC_CFLAGS = $(FEC_CFLAGS) $(FEC_NATI
deps/%.o: deps/%.c .build-config
$(CC) $(CFLAGS_COMMON) $(DEPFLAGS) $(INCLUDES) $(CFLAGS) $(CODEC_CFLAGS) -w -c $< -o $@

all: qlinq-app qlinq-tun
all: qlinq-app qlinq-emcon qlinq-tun

src/common/transport_tls.o t/00util/test_crypto_backend.o: .build-config Makefile

Expand All @@ -221,6 +231,9 @@ libqlinq.a: $(TRANSPORT_OBJS) .build-config
qlinq-app: $(APP_OBJS) libqlinq.a
$(CC) -o $@ $(APP_OBJS) libqlinq.a $(LDFLAGS)

qlinq-emcon: src/emcon/main.o $(EMCON_OBJS)
$(CC) -o $@ $^ $(LDFLAGS)

qlinq-tun: src/host/linux/tun_metrics.o src/host/linux/tun_control.o src/host/linux/tun_config.o src/host/linux/tun_json.o src/host/linux/tun_direct.o src/host/linux/tun_device.o src/common/tun_packet.o src/common/tun_segment.o src/common/tun_coalesce.o src/common/tun_receive_batch.o libqlinq.a
$(CC) -o $@ $^ $(LDFLAGS)

Expand Down Expand Up @@ -482,7 +495,11 @@ t/00util/test_recovery_latency: t/00util/test_recovery_latency.o $(ENGINE_OBJS)
t/00util/test_publication_deadlines: t/00util/test_publication_deadlines.o $(ENGINE_OBJS)
$(CC) -o $@ $^ $(LDFLAGS)

CHECK_BINARIES = t/00util/test_flexicast_transport $(TLS_BARRIER_TEST) t/00util/test_tls_groups t/00util/test_recovery_latency t/00util/test_transport_engine t/00util/test_transport_drive $(QUICLY_INTEGRATION_TEST) t/00util/test_repair_policy t/00util/test_xfer_file t/00util/test_xfer_protocol t/00util/test_fec t/00util/test_tun_json t/00util/test_tun_names t/00util/test_tun_queue t/00util/test_tun_packet t/00util/test_tun_receive_batch t/00util/test_tun_segment t/00util/test_tun_coalesce $(TUN_VNET_TEST) \
CHECK_BINARIES = t/00util/test_flexicast_transport \
t/00util/test_emcon_activation t/00util/test_emcon_manifest \
t/00util/test_emcon_rateless \
t/00util/test_emcon_receive_socket t/00util/test_emcon_session \
$(TLS_BARRIER_TEST) t/00util/test_tls_groups t/00util/test_recovery_latency t/00util/test_transport_engine t/00util/test_transport_drive $(QUICLY_INTEGRATION_TEST) t/00util/test_repair_policy t/00util/test_xfer_file t/00util/test_xfer_protocol t/00util/test_fec t/00util/test_tun_json t/00util/test_tun_names t/00util/test_tun_queue t/00util/test_tun_packet t/00util/test_tun_receive_batch t/00util/test_tun_segment t/00util/test_tun_coalesce $(TUN_VNET_TEST) \
t/00util/test_publication_deadlines \
t/00util/test_datagram_mtu \
t/00util/test_path_probe \
Expand Down Expand Up @@ -532,7 +549,7 @@ check: all $(CHECK_BINARIES) gencerts check-reports
prove -I. -v t/*.t

clean:
rm -f qlinq-app qlinq-tun libqlinq.a libqlinq.a.tmp .build-config .build-config.tmp tmp/fusion-config
rm -f qlinq-app qlinq-emcon qlinq-tun libqlinq.a libqlinq.a.tmp .build-config .build-config.tmp tmp/fusion-config
rm -f $(CHECK_BINARIES) $(TRANSPORT_TESTS) $(API_TESTS)
rm -f t/00util/test_tun_tx_kernel t/00util/test_tun_rx_kernel t/00util/fuzz_transport_wire
rm -f t/00util/test_transport_engine.map t/00util/test_recovery_latency.map
Expand Down Expand Up @@ -605,3 +622,25 @@ t/00util/test_tls_barrier: t/00util/test_tls_barrier.o $(COMMON_OBJS)

t/00util/test_flexicast_transport: t/00util/test_flexicast_transport.o $(COMMON_OBJS)
$(CC) -o $@ $^ $(LDFLAGS)

ifeq ($(UNAME_S),Linux)
t/00util/test_emcon_activation: private EMCON_ACTIVATION_TEST_LDFLAGS = -Wl,--wrap=fsync
endif
t/00util/test_emcon_activation: t/00util/test_emcon_activation.o src/emcon/emcon_activation.o src/emcon/emcon_manifest.o src/common/cli_parse.o
$(CC) -o $@ $^ $(LDFLAGS) $(EMCON_ACTIVATION_TEST_LDFLAGS)

t/00util/test_emcon_manifest: t/00util/test_emcon_manifest.o src/emcon/emcon_manifest.o src/common/cli_parse.o
$(CC) -o $@ $^ $(LDFLAGS)

t/00util/test_emcon_rateless: t/00util/test_emcon_rateless.o $(EMCON_OBJS)
$(CC) -o $@ $^ $(LDFLAGS)

t/00util/test_emcon_receive_socket: t/00util/test_emcon_receive_socket.o src/emcon/emcon_socket.o src/emcon/emcon_manifest.o src/common/cli_parse.o
$(CC) -o $@ $^ $(LDFLAGS)

t/00util/test_emcon_session: t/00util/test_emcon_session.o $(EMCON_OBJS)
$(CC) -o $@ $^ $(LDFLAGS)

.PHONY: check-emcon-netns
check-emcon-netns: qlinq-emcon
./t/netns_emcon_silence.sh
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,70 @@ QLINQ_AUTH_TOKEN='replace-with-a-secret' \
--cert peer.crt --key peer.key --ca mesh-ca.crt
```

## EMCON packet numbers and key epochs

qlinq owns EMCON sender state and uses quicly to protect each multicast
DATAGRAM. Connected Flexicast tracks acknowledgments for its attached members.

Set `replay_window_packets=64` in the manifest configuration, or omit the
setting to use that default. A receiver accepts an unseen authenticated
packet up to 63 packet numbers behind the largest authenticated packet.
EMCON senders transmit the low 32 bits of each QUIC packet number so a receiver
can authenticate packets after a reservation is skipped, without an ACK exchange.
Set `initial_packet_number` between 0 and 4,611,686,018,427,387,903 (`2^62 - 1`).
The sender can reserve up to 8,388,608 packet numbers per AES-128-GCM key epoch,
bounded by the remaining QUIC packet numbers. Each durable reservation counts,
including unused numbers skipped after a restart. The default reservation is
65,536 packet numbers. A sender restart can use the same epoch while numbers
remain. Provision a fresh key epoch after exhaustion.

Manifests with a different replay window must be regenerated and signed.
If the manifest has already been activated, provision a fresh key epoch for
the replacement. Activation state binds the original manifest to its epoch.

## Passive multicast file reception

For IPv4 and IPv6 multicast, start `qlinq-emcon receive` with
`--preprovisioned --interface NAME` on a dedicated receiver interface. `NAME`
is local to the receiver and can differ on each host. The manifest's
`interface_index` selects the sender's interface for IPv6 multicast.

Provision the receiver and network before starting the command:

1. Provide a receive-only link for the receiver's multicast interface. In a
Linux software deployment, use a dedicated interface with an administrator
installed egress drop. For example, on an interface without an existing
`clsact` qdisc or egress policy, run these commands as an administrator
before bringing up the link or joining multicast groups.

```bash
tc qdisc add dev "$RX_IF" clsact
tc filter add dev "$RX_IF" egress matchall skip_hw action drop
```

2. Configure upstream switches to forward the group to that port independently
of receiver reports. `qlinq-emcon send` fixes the IPv4 multicast TTL and IPv6
multicast hop limit to `1`, so multicast delivery is scoped to a single link
(or bridged L2 segment) and is not routed across L3 hops. The test harness
uses a dedicated bridge with snooping disabled. Assign a local address and a
route to the manifest's sender on the receiver interface.
3. Keep a separate UDP socket joined to the destination group on `RX_IF` in
the receiver's Linux network namespace. The kernel uses this host membership
for IP multicast delivery. The namespace test's `netns_emcon_multicast.py`
helper demonstrates how to hold a membership using `IP_ADD_MEMBERSHIP` or
`IPV6_JOIN_GROUP`.

`--preprovisioned` binds to the selected interface and accepts packets from the
manifest's source address and UDP port. It opens no group membership itself.
The host's existing membership can still trigger IGMP or MLD replies and the
host can generate other network traffic. The receive-only link or egress filter
must remain in effect for the entire silent interval, including receiver
startup and teardown. Verify silence from outside the receiving interface.

Use `--join-group` for lab networks that expect the application to join the
group and allow IGMP/MLD on the wire. This option also accepts `--interface NAME`
to override the manifest's numeric index on the receiver.

## Testing

To run the test suite:
Expand All @@ -140,5 +204,11 @@ To run the test suite:
make check
```

`make check-emcon-netns` exercises the production CLI in isolated Linux
network namespaces. It needs `ip`, `tc`, `nsenter`, `tcpdump`, `openssl`,
`python3`, `timeout` and permission to create user and network namespaces or
root with network namespace privileges. The test checks both receivers for
exact recovery and zero Ethernet egress while router queries reach each one.

Run `make indent` to format first-party C sources and headers using the
repository's `.clang-format` configuration.
24 changes: 6 additions & 18 deletions src/app/xfer_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#endif
#include "xfer_file.h"

#include "fs_util.h"

#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
Expand Down Expand Up @@ -497,12 +499,8 @@ static bool load_metadata(xfer_file_t *file, uint8_t prefix[32], bool *exists,
}

static bool sync_data(int fd, char *error, size_t cap) {
#if defined(__APPLE__)
int result = fsync(fd);
#else
int result = fdatasync(fd);
#endif
return result == 0 || syserr(error, cap, "sync transfer data");
return qlinq_sync_file_data(fd) == 0 ||
syserr(error, cap, "sync transfer data");
}

static bool save_metadata(xfer_file_t *file, char *error, size_t cap) {
Expand Down Expand Up @@ -531,18 +529,8 @@ static bool save_metadata(xfer_file_t *file, char *error, size_t cap) {
free(temporary);
return syserr(error, cap, "create resume metadata");
}
bool ok = true;
size_t offset = 0;
while (offset < sizeof(data)) {
ssize_t count = write(fd, data + offset, sizeof(data) - offset);
if (count < 0 && errno == EINTR)
continue;
if (count <= 0) {
ok = syserr(error, cap, "write resume metadata");
break;
}
offset += (size_t)count;
}
bool ok = qlinq_write_exact(fd, data, sizeof(data)) == 0 ||
syserr(error, cap, "write resume metadata");
if (ok && fsync(fd) != 0)
ok = syserr(error, cap, "sync resume metadata");
if (close(fd) != 0 && ok)
Expand Down
57 changes: 48 additions & 9 deletions src/common/cli_parse.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "cli_parse.h"
#include "transport.h"

#include <arpa/inet.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -61,25 +62,32 @@ bool cli_parse_congestion_control(const char *text,
return true;
}

bool cli_parse_u64(const char *text, uint64_t maximum, uint64_t *value) {
bool cli_parse_u64_base(const char *text, uint64_t maximum, int base,
uint64_t *value) {
char *end = NULL;
if (!text || !text[0] || text[0] < '0' || text[0] > '9' || !value)
return false;
errno = 0;
unsigned long long parsed = strtoull(text, &end, 10);
unsigned long long parsed = strtoull(text, &end, base);
if (errno != 0 || !end || *end != '\0' || parsed > maximum)
return false;
*value = (uint64_t)parsed;
return true;
}

bool cli_parse_endpoint(const char *text, char *host, size_t host_capacity,
uint16_t *port, bool *has_port) {
if (!text || !text[0] || !host || host_capacity == 0 || !port)
bool cli_parse_u64(const char *text, uint64_t maximum, uint64_t *value) {
return cli_parse_u64_base(text, maximum, 10, value);
}

static bool split_endpoint_host_port(const char *text, char *host,
size_t host_capacity,
const char **port_out, bool *bracketed) {
if (!text || !text[0] || !host || host_capacity == 0)
return false;
const char *start = text;
const char *port_text = NULL;
const char *start = text, *port_text = NULL;
size_t host_size = strlen(text);
if (bracketed)
*bracketed = text[0] == '[';
if (text[0] == '[') {
const char *closing = strchr(text + 1, ']');
if (!closing || (closing[1] != '\0' && closing[1] != ':'))
Expand All @@ -97,6 +105,18 @@ bool cli_parse_endpoint(const char *text, char *host, size_t host_capacity,
}
if (host_size == 0 || host_size >= host_capacity)
return false;
memcpy(host, start, host_size);
host[host_size] = '\0';
*port_out = port_text;
return true;
}

bool cli_parse_endpoint(const char *text, char *host, size_t host_capacity,
uint16_t *port, bool *has_port) {
const char *port_text = NULL;
if (!port ||
!split_endpoint_host_port(text, host, host_capacity, &port_text, NULL))
return false;
if (has_port)
*has_port = port_text != NULL;
if (port_text) {
Expand All @@ -105,7 +125,26 @@ bool cli_parse_endpoint(const char *text, char *host, size_t host_capacity,
return false;
*port = (uint16_t)parsed;
}
memcpy(host, start, host_size);
host[host_size] = '\0';
return true;
}

bool cli_parse_ip_endpoint(const char *text, int port_base, uint8_t *family,
uint8_t address[16], uint16_t *port) {
char host[INET6_ADDRSTRLEN];
const char *port_text = NULL;
bool bracketed = false;
uint64_t parsed_port = 0;
if (!family || !address || !port ||
!split_endpoint_host_port(text, host, sizeof(host), &port_text,
&bracketed) ||
!port_text ||
!cli_parse_u64_base(port_text, UINT16_MAX, port_base, &parsed_port) ||
parsed_port == 0)
return false;
memset(address, 0, 16);
if (inet_pton(bracketed ? AF_INET6 : AF_INET, host, address) != 1)
return false;
*family = bracketed ? 6U : 4U;
*port = (uint16_t)parsed_port;
return true;
}
12 changes: 12 additions & 0 deletions src/common/cli_parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,23 @@ bool cli_parse_track_mode(const char *text, uint8_t *flags);
bool cli_parse_congestion_control(const char *text,
qlinq_congestion_control_t *controller);

static inline bool cli_option_value(int argc, char **argv, int *index,
const char **value) {
if (*index + 1 >= argc)
return false;
*value = argv[++*index];
return true;
}

bool cli_parse_u64(const char *text, uint64_t maximum, uint64_t *value);
bool cli_parse_u64_base(const char *text, uint64_t maximum, int base,
uint64_t *value);

/* Parses HOST, HOST:PORT, [IPv6], or [IPv6]:PORT. The caller supplies the
* default port; has_port may be NULL when that distinction is unimportant. */
bool cli_parse_endpoint(const char *text, char *host, size_t host_capacity,
uint16_t *port, bool *has_port);
bool cli_parse_ip_endpoint(const char *text, int port_base, uint8_t *family,
uint8_t address[16], uint16_t *port);

#endif
Loading
Loading