Commit e717c2cb authored by jan.koester's avatar jan.koester
Browse files

Add accept() debug logging for QUIC remote diagnosis

parent 9bd1a4e2
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
libnetplus (20260424+19) unstable; urgency=medium

  * Add accept() debug logging for QUIC remote connection diagnosis

 -- Jan Koester <jan.koester@tuxist.de>  Thu, 24 Apr 2026 16:15:00 +0200

libnetplus (20260424+18) unstable; urgency=medium

  * Enable QUIC debug logging for HTTP/3 handshake diagnosis
+24 −0
Original line number Diff line number Diff line
@@ -1190,6 +1190,22 @@ void quic::accept(std::unique_ptr<socket>& csock, bool nonblock) {
    
    dgram.resize(static_cast<size_t>(recv_len));

    {
        char peer_ip_dbg[INET6_ADDRSTRLEN] = {};
        uint16_t peer_port_dbg = 0;
        if (peer_addr.ss_family == AF_INET) {
            auto* sa4 = reinterpret_cast<struct sockaddr_in*>(&peer_addr);
            inet_ntop(AF_INET, &sa4->sin_addr, peer_ip_dbg, sizeof(peer_ip_dbg));
            peer_port_dbg = ntohs(sa4->sin_port);
        } else if (peer_addr.ss_family == AF_INET6) {
            auto* sa6 = reinterpret_cast<struct sockaddr_in6*>(&peer_addr);
            inet_ntop(AF_INET6, &sa6->sin6_addr, peer_ip_dbg, sizeof(peer_ip_dbg));
            peer_port_dbg = ntohs(sa6->sin6_port);
        }
        QUIC_DBG("accept: recv %zd bytes from %s:%u first_byte=0x%02x _Socket=%d",
                 recv_len, peer_ip_dbg, peer_port_dbg, dgram[0], _Socket);
    }
    
    // Check if this is a long header packet (Initial, Handshake, etc.)
    if ((dgram[0] & 0x80) == 0) {
        // Short header - this is for an existing connection
@@ -1257,8 +1273,11 @@ void quic::accept(std::unique_ptr<socket>& csock, bool nonblock) {
                       (static_cast<uint32_t>(dgram[3]) << 8) |
                       static_cast<uint32_t>(dgram[4]);
    
    QUIC_DBG("accept: long header version=0x%08x", version);

    // Check for version negotiation (version == 0 means VN)
    if (version == 0) {
        QUIC_DBG("accept: skipping VN packet");
        continue;  // Skip VN packets
    }
    
@@ -1350,9 +1369,11 @@ void quic::accept(std::unique_ptr<socket>& csock, bool nonblock) {
    // Check packet type - must be Initial (0x00) for new connections
    uint8_t packet_type = (dgram[0] & 0x30) >> 4;
    if (packet_type != 0x00) {
        QUIC_DBG("accept: not Initial pkt_type=%u for unknown CID, dropping", packet_type);
        // Not an Initial packet and no existing connection found - skip
        continue;
    }
    QUIC_DBG("accept: NEW Initial from remote, creating child connection");
    
    {
        char peer_ip[INET6_ADDRSTRLEN] = {};
@@ -1370,10 +1391,13 @@ void quic::accept(std::unique_ptr<socket>& csock, bool nonblock) {
    
    // Verify supported version
    if (version != QUIC_VERSION_1 && version != QUIC_VERSION_2) {
        QUIC_DBG("accept: UNSUPPORTED version 0x%08x, dropping", version);
        // Send Version Negotiation packet
        // TODO: Implement version negotiation
        continue;
    }
    QUIC_DBG("accept: version OK, dcid_len=%u scid_len=%u pkt_type=%u",
             dcid_len, scid_len, (dgram[0] & 0x30) >> 4);
    
    // Parse token (for Initial packets)
    if (offset >= dgram.size()) {