view src/event/quic/ngx_event_quic_migration.h @ 8913:40445fc7c403 quic

QUIC: fixed migration during NAT rebinding. The RFC 9000 allows a packet from known CID arrive from unknown path: These requirements regarding connection ID reuse apply only to the sending of packets, as unintentional changes in path without a change in connection ID are possible. For example, after a period of network inactivity, NAT rebinding might cause packets to be sent on a new path when the client resumes sending. Before the patch, such packets were rejected with an error in the ngx_quic_check_migration() function. Removing the check makes the separate function excessive - remaining checks are early migration check and "disable_active_migration" check. The latter is a transport parameter sent to client and it should not be used by server. The server should send "disable_active_migration" "if the endpoint does not support active connection migration" (18.2). The support status depends on nginx configuration: to have migration working with multiple workers, you need bpf helper, available on recent Linux systems. The patch does not set "disable_active_migration" automatically and leaves it for the administrator. By default, active migration is enabled. RFC 900 says that it is ok to migrate if the peer violates "disable_active_migration" flag requirements: If the peer violates this requirement, the endpoint MUST either drop the incoming packets on that path without generating a Stateless Reset OR proceed with path validation and allow the peer to migrate. Generating a Stateless Reset or closing the connection would allow third parties in the network to cause connections to close by spoofing or otherwise manipulating observed traffic. So, nginx adheres to the second option and proceeds to path validation. Note: The ngtcp2 may be used for testing both active migration and NAT rebinding: ngtcp2/client --change-local-addr=200ms --delay-stream=500ms <ip> <port> <url> ngtcp2/client --change-local-addr=200ms --delay-stream=500ms --nat-rebinding \ <ip> <port> <url>
author Vladimir Homutov <vl@nginx.com>
date Mon, 29 Nov 2021 11:51:14 +0300
parents 5186ee5a94b9
children ddd5e5c0f87d
line wrap: on
line source


/*
 * Copyright (C) Nginx, Inc.
 */


#ifndef _NGX_EVENT_QUIC_MIGRATION_H_INCLUDED_
#define _NGX_EVENT_QUIC_MIGRATION_H_INCLUDED_


#include <ngx_config.h>
#include <ngx_core.h>

#define NGX_QUIC_PATH_RETRIES          3

#define NGX_QUIC_PATH_NEW              0
#define NGX_QUIC_PATH_VALIDATING       1
#define NGX_QUIC_PATH_VALIDATED        2

#define NGX_QUIC_PATH_VALID_TIME       600 /* seconds */


#define ngx_quic_path_state_str(p)                                            \
    ((p)->state == NGX_QUIC_PATH_NEW) ? "new" :                               \
        (((p)->state == NGX_QUIC_PATH_VALIDATED) ? "validated" : "validating")


ngx_int_t ngx_quic_handle_path_challenge_frame(ngx_connection_t *c,
    ngx_quic_path_challenge_frame_t *f);
ngx_int_t ngx_quic_handle_path_response_frame(ngx_connection_t *c,
    ngx_quic_path_challenge_frame_t *f);

ngx_quic_path_t *ngx_quic_find_path(ngx_connection_t *c,
    struct sockaddr *sockaddr, socklen_t socklen);
ngx_quic_path_t *ngx_quic_add_path(ngx_connection_t *c,
    struct sockaddr *sockaddr, socklen_t socklen);

ngx_int_t ngx_quic_update_paths(ngx_connection_t *c, ngx_quic_header_t *pkt);
ngx_int_t ngx_quic_handle_migration(ngx_connection_t *c,
    ngx_quic_header_t *pkt);

void ngx_quic_path_validation_handler(ngx_event_t *ev);

#endif /* _NGX_EVENT_QUIC_MIGRATION_H_INCLUDED_ */