#include "ngtcp2_path.h"
#include "ngtcp2_rcvry.h"
#include "ngtcp2_unreachable.h"
+#include "ngtcp2_net.h"
/* NGTCP2_FLOW_WINDOW_RTT_FACTOR is the factor of RTT when flow
control window auto-tuning is triggered. */
size_t other_versionslen,
uint32_t version) {
size_t i;
+ uint32_t v;
assert(!(other_versionslen & 0x3));
}
for (i = 0; i < other_versionslen; i += sizeof(uint32_t)) {
- if (version == ngtcp2_get_uint32(&other_versions[i])) {
+ other_versions = ngtcp2_get_uint32(&v, other_versions);
+
+ if (version == v) {
return 1;
}
}
if ((pkt[0] & NGTCP2_HEADER_FORM_BIT) && pktlen > 4) {
/* Not a Version Negotiation packet */
- version = ngtcp2_get_uint32(&pkt[1]);
+ ngtcp2_get_uint32(&version, &pkt[1]);
if (ngtcp2_pkt_get_type_long(version, pkt[0]) == NGTCP2_PKT_INITIAL) {
if (conn->server) {
if (is_unrecoverable_error((int)nread)) {
return 0;
}
+/*
+ * conn_allow_path_change_under_disable_active_migration returns
+ * nonzero if a packet from |path| is acceptable under
+ * disable_active_migration is on.
+ */
+static int
+conn_allow_path_change_under_disable_active_migration(ngtcp2_conn *conn,
+ const ngtcp2_path *path) {
+ uint32_t remote_addr_cmp;
+ const ngtcp2_preferred_addr *paddr;
+ ngtcp2_addr addr;
+
+ assert(conn->server);
+ assert(conn->local.transport_params.disable_active_migration);
+
+ /* If local address does not change, it must be passive migration
+ (NAT rebinding). */
+ if (ngtcp2_addr_eq(&conn->dcid.current.ps.path.local, &path->local)) {
+ remote_addr_cmp =
+ ngtcp2_addr_compare(&conn->dcid.current.ps.path.remote, &path->remote);
+
+ return (remote_addr_cmp | NGTCP2_ADDR_COMPARE_FLAG_PORT) ==
+ NGTCP2_ADDR_COMPARE_FLAG_PORT;
+ }
+
+ /* If local address changes, it must be one of the preferred
+ addresses. */
+
+ if (!conn->local.transport_params.preferred_address_present) {
+ return 0;
+ }
+
+ paddr = &conn->local.transport_params.preferred_address;
+
+ if (paddr->ipv4_present) {
+ ngtcp2_addr_init(&addr, (const ngtcp2_sockaddr *)&paddr->ipv4,
+ sizeof(paddr->ipv4));
+
+ if (ngtcp2_addr_eq(&addr, &path->local)) {
+ return 1;
+ }
+ }
+
+ if (paddr->ipv6_present) {
+ ngtcp2_addr_init(&addr, (const ngtcp2_sockaddr *)&paddr->ipv6,
+ sizeof(paddr->ipv6));
+
+ if (ngtcp2_addr_eq(&addr, &path->local)) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
/*
* conn_recv_pkt processes a packet contained in the buffer pointed by
* |pkt| of length |pktlen|. |pkt| may contain multiple QUIC packets.
int new_cid_used = 0;
int path_challenge_recved = 0;
+ if (conn->server && conn->local.transport_params.disable_active_migration &&
+ !ngtcp2_path_eq(&conn->dcid.current.ps.path, path) &&
+ !conn_allow_path_change_under_disable_active_migration(conn, path)) {
+ ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT,
+ "packet is discarded because active migration is disabled");
+
+ return NGTCP2_ERR_DISCARD_PKT;
+ }
+
if (pkt[0] & NGTCP2_HEADER_FORM_BIT) {
nread = ngtcp2_pkt_decode_hd_long(&hd, pkt, pktlen);
if (nread < 0) {
size_t other_versionslen,
uint32_t fallback_version) {
size_t i, j;
+ const uint8_t *p;
+ uint32_t v;
if (!preferred_versionslen ||
(!other_versionslen && chosen_version == fallback_version)) {
if (preferred_versions[i] == chosen_version) {
return chosen_version;
}
- for (j = 0; j < other_versionslen; j += sizeof(uint32_t)) {
- if (preferred_versions[i] != ngtcp2_get_uint32(&other_versions[j])) {
- continue;
- }
+ for (j = 0, p = other_versions; j < other_versionslen;
+ j += sizeof(uint32_t)) {
+ p = ngtcp2_get_uint32(&v, p);
- return preferred_versions[i];
+ if (preferred_versions[i] == v) {
+ return v;
+ }
}
}
#include "ngtcp2_net.h"
#include "ngtcp2_unreachable.h"
-uint64_t ngtcp2_get_uint64(const uint8_t *p) {
+const uint8_t *ngtcp2_get_uint64(uint64_t *dest, const uint8_t *p) {
uint64_t n;
- memcpy(&n, p, 8);
- return ngtcp2_ntohl64(n);
+ memcpy(&n, p, sizeof(n));
+ *dest = ngtcp2_ntohl64(n);
+ return p + sizeof(n);
}
-uint64_t ngtcp2_get_uint48(const uint8_t *p) {
+const uint8_t *ngtcp2_get_uint48(uint64_t *dest, const uint8_t *p) {
uint64_t n = 0;
memcpy(((uint8_t *)&n) + 2, p, 6);
- return ngtcp2_ntohl64(n);
+ *dest = ngtcp2_ntohl64(n);
+ return p + 6;
}
-uint32_t ngtcp2_get_uint32(const uint8_t *p) {
+const uint8_t *ngtcp2_get_uint32(uint32_t *dest, const uint8_t *p) {
uint32_t n;
- memcpy(&n, p, 4);
- return ngtcp2_ntohl(n);
+ memcpy(&n, p, sizeof(n));
+ *dest = ngtcp2_ntohl(n);
+ return p + sizeof(n);
}
-uint32_t ngtcp2_get_uint24(const uint8_t *p) {
+const uint8_t *ngtcp2_get_uint24(uint32_t *dest, const uint8_t *p) {
uint32_t n = 0;
memcpy(((uint8_t *)&n) + 1, p, 3);
- return ngtcp2_ntohl(n);
+ *dest = ngtcp2_ntohl(n);
+ return p + 3;
}
-uint16_t ngtcp2_get_uint16(const uint8_t *p) {
+const uint8_t *ngtcp2_get_uint16(uint16_t *dest, const uint8_t *p) {
uint16_t n;
- memcpy(&n, p, 2);
- return ngtcp2_ntohs(n);
+ memcpy(&n, p, sizeof(n));
+ *dest = ngtcp2_ntohs(n);
+ return p + sizeof(n);
}
-uint64_t ngtcp2_get_varint(size_t *plen, const uint8_t *p) {
+const uint8_t *ngtcp2_get_uint16be(uint16_t *dest, const uint8_t *p) {
+ memcpy(dest, p, sizeof(*dest));
+ return p + sizeof(*dest);
+}
+
+static uint64_t get_uvarint(size_t *plen, const uint8_t *p) {
union {
- char b[8];
+ uint8_t n8;
uint16_t n16;
uint32_t n32;
uint64_t n64;
return *p;
case 2:
memcpy(&n, p, 2);
- n.b[0] &= 0x3f;
+ n.n8 &= 0x3f;
return ngtcp2_ntohs(n.n16);
case 4:
memcpy(&n, p, 4);
- n.b[0] &= 0x3f;
+ n.n8 &= 0x3f;
return ngtcp2_ntohl(n.n32);
case 8:
memcpy(&n, p, 8);
- n.b[0] &= 0x3f;
+ n.n8 &= 0x3f;
return ngtcp2_ntohl64(n.n64);
default:
ngtcp2_unreachable();
}
+}
+
+const uint8_t *ngtcp2_get_uvarint(uint64_t *dest, const uint8_t *p) {
+ size_t len;
- return 0;
+ *dest = get_uvarint(&len, p);
+
+ return p + len;
+}
+
+const uint8_t *ngtcp2_get_varint(int64_t *dest, const uint8_t *p) {
+ size_t len;
+
+ *dest = (int64_t)get_uvarint(&len, p);
+
+ return p + len;
}
int64_t ngtcp2_get_pkt_num(const uint8_t *p, size_t pkt_numlen) {
+ uint32_t l;
+ uint16_t s;
+
switch (pkt_numlen) {
case 1:
return *p;
case 2:
- return (int64_t)ngtcp2_get_uint16(p);
+ ngtcp2_get_uint16(&s, p);
+ return (int64_t)s;
case 3:
- return (int64_t)ngtcp2_get_uint24(p);
+ ngtcp2_get_uint24(&l, p);
+ return (int64_t)l;
case 4:
- return (int64_t)ngtcp2_get_uint32(p);
+ ngtcp2_get_uint32(&l, p);
+ return (int64_t)l;
default:
ngtcp2_unreachable();
}
return ngtcp2_cpymem(p, (const uint8_t *)&n, sizeof(n));
}
-uint8_t *ngtcp2_put_varint(uint8_t *p, uint64_t n) {
+uint8_t *ngtcp2_put_uint16(uint8_t *p, uint16_t n) {
+ return ngtcp2_cpymem(p, (const uint8_t *)&n, sizeof(n));
+}
+
+uint8_t *ngtcp2_put_uvarint(uint8_t *p, uint64_t n) {
uint8_t *rv;
if (n < 64) {
*p++ = (uint8_t)n;
return rv;
}
-uint8_t *ngtcp2_put_varint30(uint8_t *p, uint32_t n) {
+uint8_t *ngtcp2_put_uvarint30(uint8_t *p, uint32_t n) {
uint8_t *rv;
assert(n < 1073741824);
}
}
-size_t ngtcp2_get_varint_len(const uint8_t *p) {
+size_t ngtcp2_get_uvarintlen(const uint8_t *p) {
return (size_t)(1u << (*p >> 6));
}
-size_t ngtcp2_put_varint_len(uint64_t n) {
+size_t ngtcp2_put_uvarintlen(uint64_t n) {
if (n < 64) {
return 1;
}
/*
* ngtcp2_get_uint64 reads 8 bytes from |p| as 64 bits unsigned
- * integer encoded as network byte order, and returns it in host byte
- * order.
+ * integer encoded as network byte order, and stores it in the buffer
+ * pointed by |dest| in host byte order. It returns |p| + 8.
*/
-uint64_t ngtcp2_get_uint64(const uint8_t *p);
+const uint8_t *ngtcp2_get_uint64(uint64_t *dest, const uint8_t *p);
/*
* ngtcp2_get_uint48 reads 6 bytes from |p| as 48 bits unsigned
- * integer encoded as network byte order, and returns it in host byte
- * order.
+ * integer encoded as network byte order, and stores it in the buffer
+ * pointed by |dest| in host byte order. It returns |p| + 6.
*/
-uint64_t ngtcp2_get_uint48(const uint8_t *p);
+const uint8_t *ngtcp2_get_uint48(uint64_t *dest, const uint8_t *p);
/*
* ngtcp2_get_uint32 reads 4 bytes from |p| as 32 bits unsigned
- * integer encoded as network byte order, and returns it in host byte
- * order.
+ * integer encoded as network byte order, and stores it in the buffer
+ * pointed by |dest| in host byte order. It returns |p| + 4.
*/
-uint32_t ngtcp2_get_uint32(const uint8_t *p);
+const uint8_t *ngtcp2_get_uint32(uint32_t *dest, const uint8_t *p);
/*
* ngtcp2_get_uint24 reads 3 bytes from |p| as 24 bits unsigned
- * integer encoded as network byte order, and returns it in host byte
- * order.
+ * integer encoded as network byte order, and stores it in the buffer
+ * pointed by |dest| in host byte order. It returns |p| + 3.
*/
-uint32_t ngtcp2_get_uint24(const uint8_t *p);
+const uint8_t *ngtcp2_get_uint24(uint32_t *dest, const uint8_t *p);
/*
* ngtcp2_get_uint16 reads 2 bytes from |p| as 16 bits unsigned
- * integer encoded as network byte order, and returns it in host byte
- * order.
+ * integer encoded as network byte order, and stores it in the buffer
+ * pointed by |dest| in host byte order. It returns |p| + 2.
*/
-uint16_t ngtcp2_get_uint16(const uint8_t *p);
+const uint8_t *ngtcp2_get_uint16(uint16_t *dest, const uint8_t *p);
/*
- * ngtcp2_get_varint reads variable-length integer from |p|, and
- * returns it in host byte order. The number of bytes read is stored
- * in |*plen|.
+ * ngtcp2_get_uint16be reads 2 bytes from |p| as 16 bits unsigned
+ * integer encoded as network byte order, and stores it in the buffer
+ * pointed by |dest| as is. It returns |p| + 2.
*/
-uint64_t ngtcp2_get_varint(size_t *plen, const uint8_t *p);
+const uint8_t *ngtcp2_get_uint16be(uint16_t *dest, const uint8_t *p);
+
+/*
+ * ngtcp2_get_uvarint reads variable-length unsigned integer from |p|,
+ * and stores it in the buffer pointed by |dest| in host byte order.
+ * It returns |p| plus the number of bytes read from |p|.
+ */
+const uint8_t *ngtcp2_get_uvarint(uint64_t *dest, const uint8_t *p);
+
+/*
+ * ngtcp2_get_varint reads variable-length unsigned integer from |p|,
+ * and casts it to the signed integer, and stores it in the buffer
+ * pointed by |dest| in host byte order. No information should be
+ * lost in this cast, because the variable-length integer is 62
+ * bits. It returns |p| plus the number of bytes read from |p|.
+ */
+const uint8_t *ngtcp2_get_varint(int64_t *dest, const uint8_t *p);
/*
* ngtcp2_get_pkt_num reads encoded packet number from |p|. The
uint8_t *ngtcp2_put_uint16be(uint8_t *p, uint16_t n);
/*
- * ngtcp2_put_varint writes |n| in |p| using variable-length integer
+ * ngtcp2_put_uint16 writes |n| as is in |p|. It returns the one
+ * beyond of the last written position.
+ */
+uint8_t *ngtcp2_put_uint16(uint8_t *p, uint16_t n);
+
+/*
+ * ngtcp2_put_uvarint writes |n| in |p| using variable-length integer
* encoding. It returns the one beyond of the last written position.
*/
-uint8_t *ngtcp2_put_varint(uint8_t *p, uint64_t n);
+uint8_t *ngtcp2_put_uvarint(uint8_t *p, uint64_t n);
/*
- * ngtcp2_put_varint30 writes |n| in |p| using variable-length integer
- * encoding. |n| must be strictly less than 1073741824. The function
- * always encodes |n| in 4 bytes. It returns the one beyond of the
- * last written position.
+ * ngtcp2_put_uvarint30 writes |n| in |p| using variable-length
+ * integer encoding. |n| must be strictly less than 1073741824. The
+ * function always encodes |n| in 4 bytes. It returns the one beyond
+ * of the last written position.
*/
-uint8_t *ngtcp2_put_varint30(uint8_t *p, uint32_t n);
+uint8_t *ngtcp2_put_uvarint30(uint8_t *p, uint32_t n);
/*
* ngtcp2_put_pkt_num encodes |pkt_num| using |len| bytes. It
uint8_t *ngtcp2_put_pkt_num(uint8_t *p, int64_t pkt_num, size_t len);
/*
- * ngtcp2_get_varint_len returns the required number of bytes to read
+ * ngtcp2_get_uvarintlen returns the required number of bytes to read
* variable-length integer starting at |p|.
*/
-size_t ngtcp2_get_varint_len(const uint8_t *p);
+size_t ngtcp2_get_uvarintlen(const uint8_t *p);
/*
- * ngtcp2_put_varint_len returns the required number of bytes to
+ * ngtcp2_put_uvarintlen returns the required number of bytes to
* encode |n|.
*/
-size_t ngtcp2_put_varint_len(uint64_t n);
+size_t ngtcp2_put_uvarintlen(uint64_t n);
/*
* ngtcp2_nth_server_bidi_id returns |n|-th server bidirectional
* which has variable integer in its parameter.
*/
static size_t varint_paramlen(ngtcp2_transport_param_id id, uint64_t param) {
- size_t valuelen = ngtcp2_put_varint_len(param);
- return ngtcp2_put_varint_len(id) + ngtcp2_put_varint_len(valuelen) + valuelen;
+ size_t valuelen = ngtcp2_put_uvarintlen(param);
+ return ngtcp2_put_uvarintlen(id) + ngtcp2_put_uvarintlen(valuelen) + valuelen;
}
/*
*/
static uint8_t *write_varint_param(uint8_t *p, ngtcp2_transport_param_id id,
uint64_t value) {
- p = ngtcp2_put_varint(p, id);
- p = ngtcp2_put_varint(p, ngtcp2_put_varint_len(value));
- return ngtcp2_put_varint(p, value);
+ p = ngtcp2_put_uvarint(p, id);
+ p = ngtcp2_put_uvarint(p, ngtcp2_put_uvarintlen(value));
+ return ngtcp2_put_uvarint(p, value);
}
/*
*/
static size_t cid_paramlen(ngtcp2_transport_param_id id,
const ngtcp2_cid *cid) {
- return ngtcp2_put_varint_len(id) + ngtcp2_put_varint_len(cid->datalen) +
+ return ngtcp2_put_uvarintlen(id) + ngtcp2_put_uvarintlen(cid->datalen) +
cid->datalen;
}
assert(cid->datalen == 0 || cid->datalen >= NGTCP2_MIN_CIDLEN);
assert(cid->datalen <= NGTCP2_MAX_CIDLEN);
- p = ngtcp2_put_varint(p, id);
- p = ngtcp2_put_varint(p, cid->datalen);
+ p = ngtcp2_put_uvarint(p, id);
+ p = ngtcp2_put_uvarint(p, cid->datalen);
if (cid->datalen) {
p = ngtcp2_cpymem(p, cid->data, cid->datalen);
}
/* For some reason, gcc 7.3.0 requires this initialization. */
size_t preferred_addrlen = 0;
size_t version_infolen = 0;
+ const ngtcp2_sockaddr_in *sa_in;
+ const ngtcp2_sockaddr_in6 *sa_in6;
(void)transport_params_version;
switch (exttype) {
if (params->stateless_reset_token_present) {
len +=
- ngtcp2_put_varint_len(NGTCP2_TRANSPORT_PARAM_STATELESS_RESET_TOKEN) +
- ngtcp2_put_varint_len(NGTCP2_STATELESS_RESET_TOKENLEN) +
+ ngtcp2_put_uvarintlen(NGTCP2_TRANSPORT_PARAM_STATELESS_RESET_TOKEN) +
+ ngtcp2_put_uvarintlen(NGTCP2_STATELESS_RESET_TOKENLEN) +
NGTCP2_STATELESS_RESET_TOKENLEN;
}
if (params->preferred_address_present) {
+ 1 +
params->preferred_address.cid.datalen /* CID */ +
NGTCP2_STATELESS_RESET_TOKENLEN;
- len += ngtcp2_put_varint_len(NGTCP2_TRANSPORT_PARAM_PREFERRED_ADDRESS) +
- ngtcp2_put_varint_len(preferred_addrlen) + preferred_addrlen;
+ len += ngtcp2_put_uvarintlen(NGTCP2_TRANSPORT_PARAM_PREFERRED_ADDRESS) +
+ ngtcp2_put_uvarintlen(preferred_addrlen) + preferred_addrlen;
}
if (params->retry_scid_present) {
len += cid_paramlen(NGTCP2_TRANSPORT_PARAM_RETRY_SOURCE_CONNECTION_ID,
}
if (params->disable_active_migration) {
len +=
- ngtcp2_put_varint_len(NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION) +
- ngtcp2_put_varint_len(0);
+ ngtcp2_put_uvarintlen(NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION) +
+ ngtcp2_put_uvarintlen(0);
}
if (params->max_ack_delay != NGTCP2_DEFAULT_MAX_ACK_DELAY) {
len += varint_paramlen(NGTCP2_TRANSPORT_PARAM_MAX_ACK_DELAY,
params->max_datagram_frame_size);
}
if (params->grease_quic_bit) {
- len += ngtcp2_put_varint_len(NGTCP2_TRANSPORT_PARAM_GREASE_QUIC_BIT) +
- ngtcp2_put_varint_len(0);
+ len += ngtcp2_put_uvarintlen(NGTCP2_TRANSPORT_PARAM_GREASE_QUIC_BIT) +
+ ngtcp2_put_uvarintlen(0);
}
if (params->version_info_present) {
version_infolen = sizeof(uint32_t) + params->version_info.other_versionslen;
- len += ngtcp2_put_varint_len(
+ len += ngtcp2_put_uvarintlen(
NGTCP2_TRANSPORT_PARAM_VERSION_INFORMATION_DRAFT) +
- ngtcp2_put_varint_len(version_infolen) + version_infolen;
+ ngtcp2_put_uvarintlen(version_infolen) + version_infolen;
}
if (dest == NULL && destlen == 0) {
¶ms->original_dcid);
if (params->stateless_reset_token_present) {
- p = ngtcp2_put_varint(p, NGTCP2_TRANSPORT_PARAM_STATELESS_RESET_TOKEN);
- p = ngtcp2_put_varint(p, sizeof(params->stateless_reset_token));
+ p = ngtcp2_put_uvarint(p, NGTCP2_TRANSPORT_PARAM_STATELESS_RESET_TOKEN);
+ p = ngtcp2_put_uvarint(p, sizeof(params->stateless_reset_token));
p = ngtcp2_cpymem(p, params->stateless_reset_token,
sizeof(params->stateless_reset_token));
}
if (params->preferred_address_present) {
- p = ngtcp2_put_varint(p, NGTCP2_TRANSPORT_PARAM_PREFERRED_ADDRESS);
- p = ngtcp2_put_varint(p, preferred_addrlen);
+ p = ngtcp2_put_uvarint(p, NGTCP2_TRANSPORT_PARAM_PREFERRED_ADDRESS);
+ p = ngtcp2_put_uvarint(p, preferred_addrlen);
if (params->preferred_address.ipv4_present) {
- p = ngtcp2_cpymem(p, params->preferred_address.ipv4_addr,
- sizeof(params->preferred_address.ipv4_addr));
- p = ngtcp2_put_uint16be(p, params->preferred_address.ipv4_port);
+ sa_in = ¶ms->preferred_address.ipv4;
+ p = ngtcp2_cpymem(p, &sa_in->sin_addr, sizeof(sa_in->sin_addr));
+ p = ngtcp2_put_uint16(p, sa_in->sin_port);
} else {
- p = ngtcp2_cpymem(p, empty_address,
- sizeof(params->preferred_address.ipv4_addr));
- p = ngtcp2_put_uint16be(p, 0);
+ p = ngtcp2_cpymem(p, empty_address, sizeof(sa_in->sin_addr));
+ p = ngtcp2_put_uint16(p, 0);
}
if (params->preferred_address.ipv6_present) {
- p = ngtcp2_cpymem(p, params->preferred_address.ipv6_addr,
- sizeof(params->preferred_address.ipv6_addr));
- p = ngtcp2_put_uint16be(p, params->preferred_address.ipv6_port);
+ sa_in6 = ¶ms->preferred_address.ipv6;
+ p = ngtcp2_cpymem(p, &sa_in6->sin6_addr, sizeof(sa_in6->sin6_addr));
+ p = ngtcp2_put_uint16(p, sa_in6->sin6_port);
} else {
- p = ngtcp2_cpymem(p, empty_address,
- sizeof(params->preferred_address.ipv6_addr));
- p = ngtcp2_put_uint16be(p, 0);
+ p = ngtcp2_cpymem(p, empty_address, sizeof(sa_in6->sin6_addr));
+ p = ngtcp2_put_uint16(p, 0);
}
*p++ = (uint8_t)params->preferred_address.cid.datalen;
}
if (params->disable_active_migration) {
- p = ngtcp2_put_varint(p, NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION);
- p = ngtcp2_put_varint(p, 0);
+ p = ngtcp2_put_uvarint(p, NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION);
+ p = ngtcp2_put_uvarint(p, 0);
}
if (params->max_ack_delay != NGTCP2_DEFAULT_MAX_ACK_DELAY) {
}
if (params->grease_quic_bit) {
- p = ngtcp2_put_varint(p, NGTCP2_TRANSPORT_PARAM_GREASE_QUIC_BIT);
- p = ngtcp2_put_varint(p, 0);
+ p = ngtcp2_put_uvarint(p, NGTCP2_TRANSPORT_PARAM_GREASE_QUIC_BIT);
+ p = ngtcp2_put_uvarint(p, 0);
}
if (params->version_info_present) {
- p = ngtcp2_put_varint(p, NGTCP2_TRANSPORT_PARAM_VERSION_INFORMATION_DRAFT);
- p = ngtcp2_put_varint(p, version_infolen);
+ p = ngtcp2_put_uvarint(p, NGTCP2_TRANSPORT_PARAM_VERSION_INFORMATION_DRAFT);
+ p = ngtcp2_put_uvarint(p, version_infolen);
p = ngtcp2_put_uint32be(p, params->version_info.chosen_version);
if (params->version_info.other_versionslen) {
p = ngtcp2_cpymem(p, params->version_info.other_versions,
/*
* decode_varint decodes a single varint from the buffer pointed by
- * |p| of length |end - p|. If it decodes an integer successfully, it
- * stores the integer in |*pdest| and returns 0. Otherwise it returns
- * -1.
+ * |*pp| of length |end - *pp|. If it decodes an integer
+ * successfully, it stores the integer in |*pdest|, increment |*pp| by
+ * the number of bytes read from |*pp|, and returns 0. Otherwise it
+ * returns -1.
*/
-static ngtcp2_ssize decode_varint(uint64_t *pdest, const uint8_t *p,
- const uint8_t *end) {
+static int decode_varint(uint64_t *pdest, const uint8_t **pp,
+ const uint8_t *end) {
+ const uint8_t *p = *pp;
size_t len;
if (p == end) {
return -1;
}
- len = ngtcp2_get_varint_len(p);
+ len = ngtcp2_get_uvarintlen(p);
if ((uint64_t)(end - p) < len) {
return -1;
}
- *pdest = ngtcp2_get_varint(&len, p);
+ *pp = ngtcp2_get_uvarint(pdest, p);
- return (ngtcp2_ssize)len;
+ return 0;
}
/*
* decode_varint_param decodes length prefixed value from the buffer
- * pointed by |p| of length |end - p|. The length and value are
+ * pointed by |*pp| of length |end - *pp|. The length and value are
* encoded in varint form. If it decodes a value successfully, it
- * stores the value in |*pdest| and returns 0. Otherwise it returns
- * -1.
+ * stores the value in |*pdest|, increment |*pp| by the number of
+ * bytes read from |*pp|, and returns 0. Otherwise it returns -1.
*/
-static ngtcp2_ssize decode_varint_param(uint64_t *pdest, const uint8_t *p,
- const uint8_t *end) {
- const uint8_t *begin = p;
- ngtcp2_ssize nread;
+static int decode_varint_param(uint64_t *pdest, const uint8_t **pp,
+ const uint8_t *end) {
+ const uint8_t *p = *pp;
uint64_t valuelen;
- size_t n;
- nread = decode_varint(&valuelen, p, end);
- if (nread < 0) {
+ if (decode_varint(&valuelen, &p, end) != 0) {
return -1;
}
- p += nread;
-
if (p == end) {
return -1;
}
return -1;
}
- if (ngtcp2_get_varint_len(p) != valuelen) {
+ if (ngtcp2_get_uvarintlen(p) != valuelen) {
return -1;
}
- *pdest = ngtcp2_get_varint(&n, p);
+ *pp = ngtcp2_get_uvarint(pdest, p);
- p += valuelen;
-
- return (ngtcp2_ssize)(p - begin);
+ return 0;
}
/*
* decode_cid_param decodes length prefixed ngtcp2_cid from the buffer
- * pointed by |p| of length |end - p|. The length is encoded in
+ * pointed by |*pp| of length |end - *pp|. The length is encoded in
* varint form. If it decodes a value successfully, it stores the
- * value in |*pdest| and returns the number of bytes read. Otherwise
- * it returns -1.
+ * value in |*pdest|, increment |*pp| by the number of read from
+ * |*pp|, and returns the number of bytes read. Otherwise it returns
+ * the one of the negative error code:
+ *
+ * NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM
+ * Could not decode Connection ID.
*/
-static ngtcp2_ssize decode_cid_param(ngtcp2_cid *pdest, const uint8_t *p,
- const uint8_t *end) {
- const uint8_t *begin = p;
+static int decode_cid_param(ngtcp2_cid *pdest, const uint8_t **pp,
+ const uint8_t *end) {
+ const uint8_t *p = *pp;
uint64_t valuelen;
- ngtcp2_ssize nread = decode_varint(&valuelen, p, end);
- if (nread < 0) {
+ if (decode_varint(&valuelen, &p, end) != 0) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- p += nread;
-
if ((valuelen != 0 && valuelen < NGTCP2_MIN_CIDLEN) ||
valuelen > NGTCP2_MAX_CIDLEN || (size_t)(end - p) < valuelen) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
p += valuelen;
- return (ngtcp2_ssize)(p - begin);
+ *pp = p;
+
+ return 0;
}
int ngtcp2_decode_transport_params_versioned(
int transport_params_version, ngtcp2_transport_params *params,
ngtcp2_transport_params_type exttype, const uint8_t *data, size_t datalen) {
- const uint8_t *p, *end;
+ const uint8_t *p, *end, *lend;
size_t len;
uint64_t param_type;
uint64_t valuelen;
- ngtcp2_ssize nread;
+ int rv;
int initial_scid_present = 0;
int original_dcid_present = 0;
- size_t i;
+ ngtcp2_sockaddr_in *sa_in;
+ ngtcp2_sockaddr_in6 *sa_in6;
+ uint32_t version;
+
(void)transport_params_version;
if (datalen == 0) {
end = data + datalen;
for (; (size_t)(end - p) >= 2;) {
- nread = decode_varint(¶m_type, p, end);
- if (nread < 0) {
+ if (decode_varint(¶m_type, &p, end) != 0) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- p += nread;
switch (param_type) {
case NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_BIDI_LOCAL:
- nread = decode_varint_param(¶ms->initial_max_stream_data_bidi_local,
- p, end);
- if (nread < 0) {
+ if (decode_varint_param(¶ms->initial_max_stream_data_bidi_local, &p,
+ end) != 0) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- p += nread;
break;
case NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_BIDI_REMOTE:
- nread = decode_varint_param(¶ms->initial_max_stream_data_bidi_remote,
- p, end);
- if (nread < 0) {
+ if (decode_varint_param(¶ms->initial_max_stream_data_bidi_remote, &p,
+ end) != 0) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- p += nread;
break;
case NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_UNI:
- nread = decode_varint_param(¶ms->initial_max_stream_data_uni, p, end);
- if (nread < 0) {
+ if (decode_varint_param(¶ms->initial_max_stream_data_uni, &p, end) !=
+ 0) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- p += nread;
break;
case NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_DATA:
- nread = decode_varint_param(¶ms->initial_max_data, p, end);
- if (nread < 0) {
+ if (decode_varint_param(¶ms->initial_max_data, &p, end) != 0) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- p += nread;
break;
case NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAMS_BIDI:
- nread = decode_varint_param(¶ms->initial_max_streams_bidi, p, end);
- if (nread < 0) {
+ if (decode_varint_param(¶ms->initial_max_streams_bidi, &p, end) !=
+ 0) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
if (params->initial_max_streams_bidi > NGTCP2_MAX_STREAMS) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- p += nread;
break;
case NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAMS_UNI:
- nread = decode_varint_param(¶ms->initial_max_streams_uni, p, end);
- if (nread < 0) {
+ if (decode_varint_param(¶ms->initial_max_streams_uni, &p, end) != 0) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
if (params->initial_max_streams_uni > NGTCP2_MAX_STREAMS) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- p += nread;
break;
case NGTCP2_TRANSPORT_PARAM_MAX_IDLE_TIMEOUT:
- nread = decode_varint_param(¶ms->max_idle_timeout, p, end);
- if (nread < 0) {
+ if (decode_varint_param(¶ms->max_idle_timeout, &p, end) != 0) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
params->max_idle_timeout *= NGTCP2_MILLISECONDS;
- p += nread;
break;
case NGTCP2_TRANSPORT_PARAM_MAX_UDP_PAYLOAD_SIZE:
- nread = decode_varint_param(¶ms->max_udp_payload_size, p, end);
- if (nread < 0) {
+ if (decode_varint_param(¶ms->max_udp_payload_size, &p, end) != 0) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- p += nread;
break;
case NGTCP2_TRANSPORT_PARAM_STATELESS_RESET_TOKEN:
if (exttype != NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- nread = decode_varint(&valuelen, p, end);
- if (nread < 0) {
+ if (decode_varint(&valuelen, &p, end) != 0) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- p += nread;
if ((size_t)valuelen != sizeof(params->stateless_reset_token)) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- memcpy(params->stateless_reset_token, p,
- sizeof(params->stateless_reset_token));
+ p = ngtcp2_get_bytes(params->stateless_reset_token, p,
+ sizeof(params->stateless_reset_token));
params->stateless_reset_token_present = 1;
- p += sizeof(params->stateless_reset_token);
break;
case NGTCP2_TRANSPORT_PARAM_ACK_DELAY_EXPONENT:
- nread = decode_varint_param(¶ms->ack_delay_exponent, p, end);
- if (nread < 0 || params->ack_delay_exponent > 20) {
+ if (decode_varint_param(¶ms->ack_delay_exponent, &p, end) != 0) {
+ return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
+ }
+ if (params->ack_delay_exponent > 20) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- p += nread;
break;
case NGTCP2_TRANSPORT_PARAM_PREFERRED_ADDRESS:
if (exttype != NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- nread = decode_varint(&valuelen, p, end);
- if (nread < 0) {
+ if (decode_varint(&valuelen, &p, end) != 0) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- p += nread;
if ((size_t)(end - p) < valuelen) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- memcpy(params->preferred_address.ipv4_addr, p,
- sizeof(params->preferred_address.ipv4_addr));
- p += sizeof(params->preferred_address.ipv4_addr);
- params->preferred_address.ipv4_port = ngtcp2_get_uint16(p);
- p += sizeof(uint16_t);
+ sa_in = ¶ms->preferred_address.ipv4;
- if (params->preferred_address.ipv4_port ||
- memcmp(empty_address, params->preferred_address.ipv4_addr,
- sizeof(params->preferred_address.ipv4_addr)) != 0) {
+ p = ngtcp2_get_bytes(&sa_in->sin_addr, p, sizeof(sa_in->sin_addr));
+ p = ngtcp2_get_uint16be(&sa_in->sin_port, p);
+
+ if (sa_in->sin_port || memcmp(empty_address, &sa_in->sin_addr,
+ sizeof(sa_in->sin_addr)) != 0) {
+ sa_in->sin_family = AF_INET;
params->preferred_address.ipv4_present = 1;
}
- memcpy(params->preferred_address.ipv6_addr, p,
- sizeof(params->preferred_address.ipv6_addr));
- p += sizeof(params->preferred_address.ipv6_addr);
- params->preferred_address.ipv6_port = ngtcp2_get_uint16(p);
- p += sizeof(uint16_t);
+ sa_in6 = ¶ms->preferred_address.ipv6;
+
+ p = ngtcp2_get_bytes(&sa_in6->sin6_addr, p, sizeof(sa_in6->sin6_addr));
+ p = ngtcp2_get_uint16be(&sa_in6->sin6_port, p);
- if (params->preferred_address.ipv6_port ||
- memcmp(empty_address, params->preferred_address.ipv6_addr,
- sizeof(params->preferred_address.ipv6_addr)) != 0) {
+ if (sa_in6->sin6_port || memcmp(empty_address, &sa_in6->sin6_addr,
+ sizeof(sa_in6->sin6_addr)) != 0) {
+ sa_in6->sin6_family = AF_INET6;
params->preferred_address.ipv6_present = 1;
}
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
if (params->preferred_address.cid.datalen) {
- memcpy(params->preferred_address.cid.data, p,
- params->preferred_address.cid.datalen);
- p += params->preferred_address.cid.datalen;
+ p = ngtcp2_get_bytes(params->preferred_address.cid.data, p,
+ params->preferred_address.cid.datalen);
}
/* stateless reset token */
- memcpy(params->preferred_address.stateless_reset_token, p,
- sizeof(params->preferred_address.stateless_reset_token));
- p += sizeof(params->preferred_address.stateless_reset_token);
+ p = ngtcp2_get_bytes(
+ params->preferred_address.stateless_reset_token, p,
+ sizeof(params->preferred_address.stateless_reset_token));
params->preferred_address_present = 1;
break;
case NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION:
- nread = decode_varint(&valuelen, p, end);
- if (nread < 0 || valuelen != 0) {
+ if (decode_varint(&valuelen, &p, end) != 0) {
+ return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
+ }
+ if (valuelen != 0) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- p += nread;
params->disable_active_migration = 1;
break;
case NGTCP2_TRANSPORT_PARAM_ORIGINAL_DESTINATION_CONNECTION_ID:
if (exttype != NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- nread = decode_cid_param(¶ms->original_dcid, p, end);
- if (nread < 0) {
- return (int)nread;
+ rv = decode_cid_param(¶ms->original_dcid, &p, end);
+ if (rv != 0) {
+ return rv;
}
original_dcid_present = 1;
- p += nread;
break;
case NGTCP2_TRANSPORT_PARAM_RETRY_SOURCE_CONNECTION_ID:
if (exttype != NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- nread = decode_cid_param(¶ms->retry_scid, p, end);
- if (nread < 0) {
- return (int)nread;
+ rv = decode_cid_param(¶ms->retry_scid, &p, end);
+ if (rv != 0) {
+ return rv;
}
params->retry_scid_present = 1;
- p += nread;
break;
case NGTCP2_TRANSPORT_PARAM_INITIAL_SOURCE_CONNECTION_ID:
- nread = decode_cid_param(¶ms->initial_scid, p, end);
- if (nread < 0) {
- return (int)nread;
+ rv = decode_cid_param(¶ms->initial_scid, &p, end);
+ if (rv != 0) {
+ return rv;
}
initial_scid_present = 1;
- p += nread;
break;
case NGTCP2_TRANSPORT_PARAM_MAX_ACK_DELAY:
- nread = decode_varint_param(¶ms->max_ack_delay, p, end);
- if (nread < 0 || params->max_ack_delay >= 16384) {
+ if (decode_varint_param(¶ms->max_ack_delay, &p, end) != 0) {
+ return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
+ }
+ if (params->max_ack_delay >= 16384) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
params->max_ack_delay *= NGTCP2_MILLISECONDS;
- p += nread;
break;
case NGTCP2_TRANSPORT_PARAM_ACTIVE_CONNECTION_ID_LIMIT:
- nread = decode_varint_param(¶ms->active_connection_id_limit, p, end);
- if (nread < 0) {
+ if (decode_varint_param(¶ms->active_connection_id_limit, &p, end) !=
+ 0) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- p += nread;
break;
case NGTCP2_TRANSPORT_PARAM_MAX_DATAGRAM_FRAME_SIZE:
- nread = decode_varint_param(¶ms->max_datagram_frame_size, p, end);
- if (nread < 0) {
+ if (decode_varint_param(¶ms->max_datagram_frame_size, &p, end) != 0) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- p += nread;
break;
case NGTCP2_TRANSPORT_PARAM_GREASE_QUIC_BIT:
- nread = decode_varint(&valuelen, p, end);
- if (nread < 0 || valuelen != 0) {
+ if (decode_varint(&valuelen, &p, end) != 0) {
+ return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
+ }
+ if (valuelen != 0) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- p += nread;
params->grease_quic_bit = 1;
break;
case NGTCP2_TRANSPORT_PARAM_VERSION_INFORMATION_DRAFT:
- nread = decode_varint(&valuelen, p, end);
- if (nread < 0) {
+ if (decode_varint(&valuelen, &p, end) != 0) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- p += nread;
if ((size_t)(end - p) < valuelen) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
if (valuelen < sizeof(uint32_t) || (valuelen & 0x3)) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- params->version_info.chosen_version = ngtcp2_get_uint32(p);
+ p = ngtcp2_get_uint32(¶ms->version_info.chosen_version, p);
if (params->version_info.chosen_version == 0) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- p += sizeof(uint32_t);
if (valuelen > sizeof(uint32_t)) {
params->version_info.other_versions = (uint8_t *)p;
params->version_info.other_versionslen =
(size_t)valuelen - sizeof(uint32_t);
- for (i = sizeof(uint32_t); i < valuelen;
- i += sizeof(uint32_t), p += sizeof(uint32_t)) {
- if (ngtcp2_get_uint32(p) == 0) {
+ for (lend = p + (valuelen - sizeof(uint32_t)); p != lend;) {
+ p = ngtcp2_get_uint32(&version, p);
+ if (version == 0) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
}
break;
default:
/* Ignore unknown parameter */
- nread = decode_varint(&valuelen, p, end);
- if (nread < 0) {
+ if (decode_varint(&valuelen, &p, end) != 0) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
- p += nread;
if ((size_t)(end - p) < valuelen) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
#include "ngtcp2_macro.h"
#include "ngtcp2_conv.h"
#include "ngtcp2_unreachable.h"
+#include "ngtcp2_net.h"
void ngtcp2_log_init(ngtcp2_log *log, const ngtcp2_cid *scid,
ngtcp2_printf log_printf, ngtcp2_tstamp ts,
uint8_t addr[16 * 2 + 7 + 1];
uint8_t cid[NGTCP2_MAX_CIDLEN * 2 + 1];
size_t i;
+ const ngtcp2_sockaddr_in *sa_in;
+ const ngtcp2_sockaddr_in6 *sa_in6;
+ const uint8_t *p;
+ uint32_t version;
if (!log->log_printf) {
return;
}
if (params->preferred_address_present) {
- log->log_printf(log->user_data,
- (NGTCP2_LOG_TP " preferred_address.ipv4_addr=%s"),
- NGTCP2_LOG_TP_HD_FIELDS,
- (const char *)ngtcp2_encode_ipv4(
- addr, params->preferred_address.ipv4_addr));
- log->log_printf(
- log->user_data, (NGTCP2_LOG_TP " preferred_address.ipv4_port=%u"),
- NGTCP2_LOG_TP_HD_FIELDS, params->preferred_address.ipv4_port);
-
- log->log_printf(log->user_data,
- (NGTCP2_LOG_TP " preferred_address.ipv6_addr=%s"),
- NGTCP2_LOG_TP_HD_FIELDS,
- (const char *)ngtcp2_encode_ipv6(
- addr, params->preferred_address.ipv6_addr));
- log->log_printf(
- log->user_data, (NGTCP2_LOG_TP " preferred_address.ipv6_port=%u"),
- NGTCP2_LOG_TP_HD_FIELDS, params->preferred_address.ipv6_port);
+ if (params->preferred_address.ipv4_present) {
+ sa_in = ¶ms->preferred_address.ipv4;
+
+ log->log_printf(log->user_data,
+ (NGTCP2_LOG_TP " preferred_address.ipv4_addr=%s"),
+ NGTCP2_LOG_TP_HD_FIELDS,
+ (const char *)ngtcp2_encode_ipv4(
+ addr, (const uint8_t *)&sa_in->sin_addr));
+ log->log_printf(log->user_data,
+ (NGTCP2_LOG_TP " preferred_address.ipv4_port=%u"),
+ NGTCP2_LOG_TP_HD_FIELDS, ngtcp2_ntohs(sa_in->sin_port));
+ }
+
+ if (params->preferred_address.ipv6_present) {
+ sa_in6 = ¶ms->preferred_address.ipv6;
+
+ log->log_printf(log->user_data,
+ (NGTCP2_LOG_TP " preferred_address.ipv6_addr=%s"),
+ NGTCP2_LOG_TP_HD_FIELDS,
+ (const char *)ngtcp2_encode_ipv6(
+ addr, (const uint8_t *)&sa_in6->sin6_addr));
+ log->log_printf(
+ log->user_data, (NGTCP2_LOG_TP " preferred_address.ipv6_port=%u"),
+ NGTCP2_LOG_TP_HD_FIELDS, ngtcp2_ntohs(sa_in6->sin6_port));
+ }
log->log_printf(log->user_data,
(NGTCP2_LOG_TP " preferred_address.cid=0x%s"),
assert(!(params->version_info.other_versionslen & 0x3));
- for (i = 0; i < params->version_info.other_versionslen;
- i += sizeof(uint32_t)) {
+ for (i = 0, p = params->version_info.other_versions;
+ i < params->version_info.other_versionslen; i += sizeof(uint32_t)) {
+ p = ngtcp2_get_uint32(&version, p);
+
log->log_printf(
log->user_data,
(NGTCP2_LOG_TP " version_information.other_versions[%zu]=0x%08x"),
- NGTCP2_LOG_TP_HD_FIELDS, i >> 2,
- ngtcp2_get_uint32(¶ms->version_info.other_versions[i]));
+ NGTCP2_LOG_TP_HD_FIELDS, i >> 2, version);
}
}
}
#include "ngtcp2_mem.h"
#include "ngtcp2_vec.h"
#include "ngtcp2_unreachable.h"
+#include "ngtcp2_str.h"
int ngtcp2_pkt_chain_new(ngtcp2_pkt_chain **ppc, const ngtcp2_path *path,
const ngtcp2_pkt_info *pi, const uint8_t *pkt,
return NGTCP2_ERR_INVALID_ARGUMENT;
}
- version = ngtcp2_get_uint32(&data[1]);
+ ngtcp2_get_uint32(&version, &data[1]);
supported_version = ngtcp2_is_supported_version(version);
return NGTCP2_ERR_INVALID_ARGUMENT;
}
- version = ngtcp2_get_uint32(&pkt[1]);
+ ngtcp2_get_uint32(&version, &pkt[1]);
if (version == 0) {
type = NGTCP2_PKT_VERSION_NEGOTIATION;
if (type == NGTCP2_PKT_INITIAL) {
/* Token Length */
- ntokenlen = ngtcp2_get_varint_len(p);
+ ntokenlen = ngtcp2_get_uvarintlen(p);
len += ntokenlen - 1;
if (pktlen < len) {
return NGTCP2_ERR_INVALID_ARGUMENT;
}
- vi = ngtcp2_get_varint(&ntokenlen, p);
+ p = ngtcp2_get_uvarint(&vi, p);
if (pktlen - len < vi) {
return NGTCP2_ERR_INVALID_ARGUMENT;
}
tokenlen = (size_t)vi;
len += tokenlen;
- p += ntokenlen;
-
if (tokenlen) {
token = p;
}
}
/* Length */
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (pktlen < len) {
break;
}
- vi = ngtcp2_get_varint(&n, p);
+ p = ngtcp2_get_uvarint(&vi, p);
if (vi > SIZE_MAX) {
return NGTCP2_ERR_INVALID_ARGUMENT;
}
dest->len = (size_t)vi;
- p += n;
}
assert((size_t)(p - pkt) == len);
}
if (hd->type == NGTCP2_PKT_INITIAL) {
- len += ngtcp2_put_varint_len(hd->token.len) + hd->token.len;
+ len += ngtcp2_put_uvarintlen(hd->token.len) + hd->token.len;
}
if (outlen < len) {
}
if (hd->type == NGTCP2_PKT_INITIAL) {
- p = ngtcp2_put_varint(p, hd->token.len);
+ p = ngtcp2_put_uvarint(p, hd->token.len);
if (hd->token.len) {
p = ngtcp2_cpymem(p, hd->token.base, hd->token.len);
}
}
if (hd->type != NGTCP2_PKT_RETRY) {
- p = ngtcp2_put_varint30(p, (uint32_t)hd->len);
+ p = ngtcp2_put_uvarint30(p, (uint32_t)hd->len);
p = ngtcp2_put_pkt_num(p, hd->pkt_num, hd->pkt_numlen);
}
p = payload + 1;
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
return NGTCP2_ERR_FRAME_ENCODING;
}
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
return NGTCP2_ERR_FRAME_ENCODING;
}
- ndatalen = ngtcp2_get_varint_len(p);
+ ndatalen = ngtcp2_get_uvarintlen(p);
len += ndatalen - 1;
if (payloadlen < len) {
return NGTCP2_ERR_FRAME_ENCODING;
}
- vi = ngtcp2_get_varint(&ndatalen, p);
+ /* p = */ ngtcp2_get_uvarint(&vi, p);
if (payloadlen - len < vi) {
return NGTCP2_ERR_FRAME_ENCODING;
}
dest->type = NGTCP2_FRAME_STREAM;
dest->flags = (uint8_t)(type & ~NGTCP2_FRAME_STREAM);
dest->fin = (type & NGTCP2_STREAM_FIN_BIT) != 0;
- dest->stream_id = (int64_t)ngtcp2_get_varint(&n, p);
- p += n;
+ p = ngtcp2_get_varint(&dest->stream_id, p);
if (type & NGTCP2_STREAM_OFF_BIT) {
- dest->offset = ngtcp2_get_varint(&n, p);
- p += n;
+ p = ngtcp2_get_uvarint(&dest->offset, p);
} else {
dest->offset = 0;
}
p = payload + 1;
/* Largest Acknowledged */
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
p += n;
/* ACK Delay */
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
p += n;
/* ACK Range Count */
- nrangecnt = ngtcp2_get_varint_len(p);
+ nrangecnt = ngtcp2_get_uvarintlen(p);
len += nrangecnt - 1;
if (payloadlen < len) {
return NGTCP2_ERR_FRAME_ENCODING;
}
- vi = ngtcp2_get_varint(&nrangecnt, p);
+ p = ngtcp2_get_uvarint(&vi, p);
if (vi > SIZE_MAX / (1 + 1) || payloadlen - len < vi * (1 + 1)) {
return NGTCP2_ERR_FRAME_ENCODING;
}
rangecnt = (size_t)vi;
len += rangecnt * (1 + 1);
- p += nrangecnt;
-
/* First ACK Range */
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
for (i = 0; i < rangecnt; ++i) {
/* Gap, and Additional ACK Range */
for (j = 0; j < 2; ++j) {
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
}
for (i = 0; i < 3; ++i) {
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
p = payload + 1;
dest->type = type;
- dest->largest_ack = (int64_t)ngtcp2_get_varint(&n, p);
- p += n;
- dest->ack_delay = ngtcp2_get_varint(&n, p);
+ p = ngtcp2_get_varint(&dest->largest_ack, p);
+ p = ngtcp2_get_uvarint(&dest->ack_delay, p);
/* This value will be assigned in the upper layer. */
dest->ack_delay_unscaled = 0;
- p += n;
dest->rangecnt = max_rangecnt;
p += nrangecnt;
- dest->first_ack_range = ngtcp2_get_varint(&n, p);
- p += n;
+ p = ngtcp2_get_uvarint(&dest->first_ack_range, p);
for (i = 0; i < max_rangecnt; ++i) {
range = &dest->ranges[i];
- range->gap = ngtcp2_get_varint(&n, p);
- p += n;
- range->len = ngtcp2_get_varint(&n, p);
- p += n;
+ p = ngtcp2_get_uvarint(&range->gap, p);
+ p = ngtcp2_get_uvarint(&range->len, p);
}
for (i = max_rangecnt; i < rangecnt; ++i) {
- p += ngtcp2_get_varint_len(p);
- p += ngtcp2_get_varint_len(p);
+ p += ngtcp2_get_uvarintlen(p);
+ p += ngtcp2_get_uvarintlen(p);
}
if (type == NGTCP2_FRAME_ACK_ECN) {
- dest->ecn.ect0 = ngtcp2_get_varint(&n, p);
- p += n;
-
- dest->ecn.ect1 = ngtcp2_get_varint(&n, p);
- p += n;
-
- dest->ecn.ce = ngtcp2_get_varint(&n, p);
- p += n;
+ p = ngtcp2_get_uvarint(&dest->ecn.ect0, p);
+ p = ngtcp2_get_uvarint(&dest->ecn.ect1, p);
+ p = ngtcp2_get_uvarint(&dest->ecn.ce, p);
}
assert((size_t)(p - payload) == len);
p = payload + 1;
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
return NGTCP2_ERR_FRAME_ENCODING;
}
p += n;
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
return NGTCP2_ERR_FRAME_ENCODING;
}
p += n;
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
return NGTCP2_ERR_FRAME_ENCODING;
p = payload + 1;
dest->type = NGTCP2_FRAME_RESET_STREAM;
- dest->stream_id = (int64_t)ngtcp2_get_varint(&n, p);
- p += n;
- dest->app_error_code = ngtcp2_get_varint(&n, p);
- p += n;
- dest->final_size = ngtcp2_get_varint(&n, p);
- p += n;
+ p = ngtcp2_get_varint(&dest->stream_id, p);
+ p = ngtcp2_get_uvarint(&dest->app_error_code, p);
+ p = ngtcp2_get_uvarint(&dest->final_size, p);
assert((size_t)(p - payload) == len);
p = payload + 1;
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
return NGTCP2_ERR_FRAME_ENCODING;
if (type == NGTCP2_FRAME_CONNECTION_CLOSE) {
++len;
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
return NGTCP2_ERR_FRAME_ENCODING;
p += n;
}
- nreasonlen = ngtcp2_get_varint_len(p);
+ nreasonlen = ngtcp2_get_uvarintlen(p);
len += nreasonlen - 1;
if (payloadlen < len) {
return NGTCP2_ERR_FRAME_ENCODING;
}
- vi = ngtcp2_get_varint(&nreasonlen, p);
+ p = ngtcp2_get_uvarint(&vi, p);
if (payloadlen - len < vi) {
return NGTCP2_ERR_FRAME_ENCODING;
}
p = payload + 1;
dest->type = type;
- dest->error_code = ngtcp2_get_varint(&n, p);
- p += n;
+ p = ngtcp2_get_uvarint(&dest->error_code, p);
if (type == NGTCP2_FRAME_CONNECTION_CLOSE) {
- dest->frame_type = ngtcp2_get_varint(&n, p);
- p += n;
+ p = ngtcp2_get_uvarint(&dest->frame_type, p);
} else {
dest->frame_type = 0;
}
p = payload + 1;
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
}
dest->type = NGTCP2_FRAME_MAX_DATA;
- dest->max_data = ngtcp2_get_varint(&n, p);
- p += n;
+ p = ngtcp2_get_uvarint(&dest->max_data, p);
assert((size_t)(p - payload) == len);
p = payload + 1;
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
p += n;
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
p = payload + 1;
dest->type = NGTCP2_FRAME_MAX_STREAM_DATA;
- dest->stream_id = (int64_t)ngtcp2_get_varint(&n, p);
- p += n;
- dest->max_stream_data = ngtcp2_get_varint(&n, p);
- p += n;
+ p = ngtcp2_get_varint(&dest->stream_id, p);
+ p = ngtcp2_get_uvarint(&dest->max_stream_data, p);
assert((size_t)(p - payload) == len);
p = payload + 1;
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
}
dest->type = payload[0];
- dest->max_streams = ngtcp2_get_varint(&n, p);
- p += n;
+ p = ngtcp2_get_uvarint(&dest->max_streams, p);
assert((size_t)(p - payload) == len);
p = payload + 1;
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
}
dest->type = NGTCP2_FRAME_DATA_BLOCKED;
- dest->offset = ngtcp2_get_varint(&n, p);
- p += n;
+ p = ngtcp2_get_uvarint(&dest->offset, p);
assert((size_t)(p - payload) == len);
p = payload + 1;
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
p += n;
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
p = payload + 1;
dest->type = NGTCP2_FRAME_STREAM_DATA_BLOCKED;
- dest->stream_id = (int64_t)ngtcp2_get_varint(&n, p);
- p += n;
- dest->offset = ngtcp2_get_varint(&n, p);
- p += n;
+ p = ngtcp2_get_varint(&dest->stream_id, p);
+ p = ngtcp2_get_uvarint(&dest->offset, p);
assert((size_t)(p - payload) == len);
p = payload + 1;
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
}
dest->type = payload[0];
- dest->max_streams = ngtcp2_get_varint(&n, p);
- p += n;
+ p = ngtcp2_get_uvarint(&dest->max_streams, p);
assert((size_t)(p - payload) == len);
p = payload + 1;
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
return NGTCP2_ERR_FRAME_ENCODING;
p += n;
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
return NGTCP2_ERR_FRAME_ENCODING;
p = payload + 1;
dest->type = NGTCP2_FRAME_NEW_CONNECTION_ID;
- dest->seq = ngtcp2_get_varint(&n, p);
- p += n;
- dest->retire_prior_to = ngtcp2_get_varint(&n, p);
- p += n + 1;
+ p = ngtcp2_get_uvarint(&dest->seq, p);
+ p = ngtcp2_get_uvarint(&dest->retire_prior_to, p);
+ ++p;
ngtcp2_cid_init(&dest->cid, p, cil);
p += cil;
- memcpy(dest->stateless_reset_token, p, NGTCP2_STATELESS_RESET_TOKENLEN);
- p += NGTCP2_STATELESS_RESET_TOKENLEN;
+ p = ngtcp2_get_bytes(dest->stateless_reset_token, p,
+ NGTCP2_STATELESS_RESET_TOKENLEN);
assert((size_t)(p - payload) == len);
p = payload + 1;
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
return NGTCP2_ERR_FRAME_ENCODING;
}
p += n;
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
p = payload + 1;
dest->type = NGTCP2_FRAME_STOP_SENDING;
- dest->stream_id = (int64_t)ngtcp2_get_varint(&n, p);
- p += n;
- dest->app_error_code = ngtcp2_get_varint(&n, p);
- p += n;
+ p = ngtcp2_get_varint(&dest->stream_id, p);
+ p = ngtcp2_get_uvarint(&dest->app_error_code, p);
assert((size_t)(p - payload) == len);
p = payload + 1;
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
p += n;
- ndatalen = ngtcp2_get_varint_len(p);
+ ndatalen = ngtcp2_get_uvarintlen(p);
len += ndatalen - 1;
if (payloadlen < len) {
return NGTCP2_ERR_FRAME_ENCODING;
}
- vi = ngtcp2_get_varint(&ndatalen, p);
+ p = ngtcp2_get_uvarint(&vi, p);
if (payloadlen - len < vi) {
return NGTCP2_ERR_FRAME_ENCODING;
}
p = payload + 1;
dest->type = NGTCP2_FRAME_CRYPTO;
- dest->offset = ngtcp2_get_varint(&n, p);
- p += n;
+ p = ngtcp2_get_uvarint(&dest->offset, p);
dest->data[0].len = datalen;
p += ndatalen;
if (dest->data[0].len) {
p = payload + 1;
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
return NGTCP2_ERR_FRAME_ENCODING;
}
- vi = ngtcp2_get_varint(&n, p);
+ p = ngtcp2_get_uvarint(&vi, p);
if (payloadlen - len < vi) {
return NGTCP2_ERR_FRAME_ENCODING;
}
dest->type = NGTCP2_FRAME_NEW_TOKEN;
dest->token.len = datalen;
- p += n;
dest->token.base = (uint8_t *)p;
p += dest->token.len;
p = payload + 1;
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
}
dest->type = NGTCP2_FRAME_RETIRE_CONNECTION_ID;
- dest->seq = ngtcp2_get_varint(&n, p);
- p += n;
+ p = ngtcp2_get_uvarint(&dest->seq, p);
assert((size_t)(p - payload) == len);
return NGTCP2_ERR_FRAME_ENCODING;
}
- n = ngtcp2_get_varint_len(p);
+ n = ngtcp2_get_uvarintlen(p);
len += n - 1;
if (payloadlen < len) {
return NGTCP2_ERR_FRAME_ENCODING;
}
- vi = ngtcp2_get_varint(&n, p);
+ p = ngtcp2_get_uvarint(&vi, p);
if (payloadlen - len < vi) {
return NGTCP2_ERR_FRAME_ENCODING;
}
if (datalen == 0) {
dest->datacnt = 0;
dest->data = NULL;
-
- if (type == NGTCP2_FRAME_DATAGRAM_LEN) {
- p += n;
- }
} else {
dest->datacnt = 1;
dest->data = dest->rdata;
dest->rdata[0].len = datalen;
- if (type == NGTCP2_FRAME_DATAGRAM_LEN) {
- p += n;
- }
-
dest->rdata[0].base = (uint8_t *)p;
p += datalen;
}
if (fr->offset) {
flags |= NGTCP2_STREAM_OFF_BIT;
- len += ngtcp2_put_varint_len(fr->offset);
+ len += ngtcp2_put_uvarintlen(fr->offset);
}
- len += ngtcp2_put_varint_len((uint64_t)fr->stream_id);
+ len += ngtcp2_put_uvarintlen((uint64_t)fr->stream_id);
for (i = 0; i < fr->datacnt; ++i) {
datalen += fr->data[i].len;
}
- len += ngtcp2_put_varint_len(datalen);
+ len += ngtcp2_put_uvarintlen(datalen);
len += datalen;
if (outlen < len) {
fr->flags = flags;
- p = ngtcp2_put_varint(p, (uint64_t)fr->stream_id);
+ p = ngtcp2_put_uvarint(p, (uint64_t)fr->stream_id);
if (fr->offset) {
- p = ngtcp2_put_varint(p, fr->offset);
+ p = ngtcp2_put_uvarint(p, fr->offset);
}
- p = ngtcp2_put_varint(p, datalen);
+ p = ngtcp2_put_uvarint(p, datalen);
for (i = 0; i < fr->datacnt; ++i) {
assert(fr->data[i].len);
ngtcp2_ssize ngtcp2_pkt_encode_ack_frame(uint8_t *out, size_t outlen,
ngtcp2_ack *fr) {
- size_t len = 1 + ngtcp2_put_varint_len((uint64_t)fr->largest_ack) +
- ngtcp2_put_varint_len(fr->ack_delay) +
- ngtcp2_put_varint_len(fr->rangecnt) +
- ngtcp2_put_varint_len(fr->first_ack_range);
+ size_t len = 1 + ngtcp2_put_uvarintlen((uint64_t)fr->largest_ack) +
+ ngtcp2_put_uvarintlen(fr->ack_delay) +
+ ngtcp2_put_uvarintlen(fr->rangecnt) +
+ ngtcp2_put_uvarintlen(fr->first_ack_range);
uint8_t *p;
size_t i;
const ngtcp2_ack_range *range;
for (i = 0; i < fr->rangecnt; ++i) {
range = &fr->ranges[i];
- len += ngtcp2_put_varint_len(range->gap);
- len += ngtcp2_put_varint_len(range->len);
+ len += ngtcp2_put_uvarintlen(range->gap);
+ len += ngtcp2_put_uvarintlen(range->len);
}
if (fr->type == NGTCP2_FRAME_ACK_ECN) {
- len += ngtcp2_put_varint_len(fr->ecn.ect0) +
- ngtcp2_put_varint_len(fr->ecn.ect1) +
- ngtcp2_put_varint_len(fr->ecn.ce);
+ len += ngtcp2_put_uvarintlen(fr->ecn.ect0) +
+ ngtcp2_put_uvarintlen(fr->ecn.ect1) +
+ ngtcp2_put_uvarintlen(fr->ecn.ce);
}
if (outlen < len) {
p = out;
*p++ = fr->type;
- p = ngtcp2_put_varint(p, (uint64_t)fr->largest_ack);
- p = ngtcp2_put_varint(p, fr->ack_delay);
- p = ngtcp2_put_varint(p, fr->rangecnt);
- p = ngtcp2_put_varint(p, fr->first_ack_range);
+ p = ngtcp2_put_uvarint(p, (uint64_t)fr->largest_ack);
+ p = ngtcp2_put_uvarint(p, fr->ack_delay);
+ p = ngtcp2_put_uvarint(p, fr->rangecnt);
+ p = ngtcp2_put_uvarint(p, fr->first_ack_range);
for (i = 0; i < fr->rangecnt; ++i) {
range = &fr->ranges[i];
- p = ngtcp2_put_varint(p, range->gap);
- p = ngtcp2_put_varint(p, range->len);
+ p = ngtcp2_put_uvarint(p, range->gap);
+ p = ngtcp2_put_uvarint(p, range->len);
}
if (fr->type == NGTCP2_FRAME_ACK_ECN) {
- p = ngtcp2_put_varint(p, fr->ecn.ect0);
- p = ngtcp2_put_varint(p, fr->ecn.ect1);
- p = ngtcp2_put_varint(p, fr->ecn.ce);
+ p = ngtcp2_put_uvarint(p, fr->ecn.ect0);
+ p = ngtcp2_put_uvarint(p, fr->ecn.ect1);
+ p = ngtcp2_put_uvarint(p, fr->ecn.ce);
}
assert((size_t)(p - out) == len);
ngtcp2_ssize
ngtcp2_pkt_encode_reset_stream_frame(uint8_t *out, size_t outlen,
const ngtcp2_reset_stream *fr) {
- size_t len = 1 + ngtcp2_put_varint_len((uint64_t)fr->stream_id) +
- ngtcp2_put_varint_len(fr->app_error_code) +
- ngtcp2_put_varint_len(fr->final_size);
+ size_t len = 1 + ngtcp2_put_uvarintlen((uint64_t)fr->stream_id) +
+ ngtcp2_put_uvarintlen(fr->app_error_code) +
+ ngtcp2_put_uvarintlen(fr->final_size);
uint8_t *p;
if (outlen < len) {
p = out;
*p++ = NGTCP2_FRAME_RESET_STREAM;
- p = ngtcp2_put_varint(p, (uint64_t)fr->stream_id);
- p = ngtcp2_put_varint(p, fr->app_error_code);
- p = ngtcp2_put_varint(p, fr->final_size);
+ p = ngtcp2_put_uvarint(p, (uint64_t)fr->stream_id);
+ p = ngtcp2_put_uvarint(p, fr->app_error_code);
+ p = ngtcp2_put_uvarint(p, fr->final_size);
assert((size_t)(p - out) == len);
ngtcp2_ssize
ngtcp2_pkt_encode_connection_close_frame(uint8_t *out, size_t outlen,
const ngtcp2_connection_close *fr) {
- size_t len = 1 + ngtcp2_put_varint_len(fr->error_code) +
+ size_t len = 1 + ngtcp2_put_uvarintlen(fr->error_code) +
(fr->type == NGTCP2_FRAME_CONNECTION_CLOSE
- ? ngtcp2_put_varint_len(fr->frame_type)
+ ? ngtcp2_put_uvarintlen(fr->frame_type)
: 0) +
- ngtcp2_put_varint_len(fr->reasonlen) + fr->reasonlen;
+ ngtcp2_put_uvarintlen(fr->reasonlen) + fr->reasonlen;
uint8_t *p;
if (outlen < len) {
p = out;
*p++ = fr->type;
- p = ngtcp2_put_varint(p, fr->error_code);
+ p = ngtcp2_put_uvarint(p, fr->error_code);
if (fr->type == NGTCP2_FRAME_CONNECTION_CLOSE) {
- p = ngtcp2_put_varint(p, fr->frame_type);
+ p = ngtcp2_put_uvarint(p, fr->frame_type);
}
- p = ngtcp2_put_varint(p, fr->reasonlen);
+ p = ngtcp2_put_uvarint(p, fr->reasonlen);
if (fr->reasonlen) {
p = ngtcp2_cpymem(p, fr->reason, fr->reasonlen);
}
ngtcp2_ssize ngtcp2_pkt_encode_max_data_frame(uint8_t *out, size_t outlen,
const ngtcp2_max_data *fr) {
- size_t len = 1 + ngtcp2_put_varint_len(fr->max_data);
+ size_t len = 1 + ngtcp2_put_uvarintlen(fr->max_data);
uint8_t *p;
if (outlen < len) {
p = out;
*p++ = NGTCP2_FRAME_MAX_DATA;
- p = ngtcp2_put_varint(p, fr->max_data);
+ p = ngtcp2_put_uvarint(p, fr->max_data);
assert((size_t)(p - out) == len);
ngtcp2_ssize
ngtcp2_pkt_encode_max_stream_data_frame(uint8_t *out, size_t outlen,
const ngtcp2_max_stream_data *fr) {
- size_t len = 1 + ngtcp2_put_varint_len((uint64_t)fr->stream_id) +
- ngtcp2_put_varint_len(fr->max_stream_data);
+ size_t len = 1 + ngtcp2_put_uvarintlen((uint64_t)fr->stream_id) +
+ ngtcp2_put_uvarintlen(fr->max_stream_data);
uint8_t *p;
if (outlen < len) {
p = out;
*p++ = NGTCP2_FRAME_MAX_STREAM_DATA;
- p = ngtcp2_put_varint(p, (uint64_t)fr->stream_id);
- p = ngtcp2_put_varint(p, fr->max_stream_data);
+ p = ngtcp2_put_uvarint(p, (uint64_t)fr->stream_id);
+ p = ngtcp2_put_uvarint(p, fr->max_stream_data);
assert((size_t)(p - out) == len);
ngtcp2_ssize ngtcp2_pkt_encode_max_streams_frame(uint8_t *out, size_t outlen,
const ngtcp2_max_streams *fr) {
- size_t len = 1 + ngtcp2_put_varint_len(fr->max_streams);
+ size_t len = 1 + ngtcp2_put_uvarintlen(fr->max_streams);
uint8_t *p;
if (outlen < len) {
p = out;
*p++ = fr->type;
- p = ngtcp2_put_varint(p, fr->max_streams);
+ p = ngtcp2_put_uvarint(p, fr->max_streams);
assert((size_t)(p - out) == len);
ngtcp2_ssize
ngtcp2_pkt_encode_data_blocked_frame(uint8_t *out, size_t outlen,
const ngtcp2_data_blocked *fr) {
- size_t len = 1 + ngtcp2_put_varint_len(fr->offset);
+ size_t len = 1 + ngtcp2_put_uvarintlen(fr->offset);
uint8_t *p;
if (outlen < len) {
p = out;
*p++ = NGTCP2_FRAME_DATA_BLOCKED;
- p = ngtcp2_put_varint(p, fr->offset);
+ p = ngtcp2_put_uvarint(p, fr->offset);
assert((size_t)(p - out) == len);
ngtcp2_ssize ngtcp2_pkt_encode_stream_data_blocked_frame(
uint8_t *out, size_t outlen, const ngtcp2_stream_data_blocked *fr) {
- size_t len = 1 + ngtcp2_put_varint_len((uint64_t)fr->stream_id) +
- ngtcp2_put_varint_len(fr->offset);
+ size_t len = 1 + ngtcp2_put_uvarintlen((uint64_t)fr->stream_id) +
+ ngtcp2_put_uvarintlen(fr->offset);
uint8_t *p;
if (outlen < len) {
p = out;
*p++ = NGTCP2_FRAME_STREAM_DATA_BLOCKED;
- p = ngtcp2_put_varint(p, (uint64_t)fr->stream_id);
- p = ngtcp2_put_varint(p, fr->offset);
+ p = ngtcp2_put_uvarint(p, (uint64_t)fr->stream_id);
+ p = ngtcp2_put_uvarint(p, fr->offset);
assert((size_t)(p - out) == len);
ngtcp2_ssize
ngtcp2_pkt_encode_streams_blocked_frame(uint8_t *out, size_t outlen,
const ngtcp2_streams_blocked *fr) {
- size_t len = 1 + ngtcp2_put_varint_len(fr->max_streams);
+ size_t len = 1 + ngtcp2_put_uvarintlen(fr->max_streams);
uint8_t *p;
if (outlen < len) {
p = out;
*p++ = fr->type;
- p = ngtcp2_put_varint(p, fr->max_streams);
+ p = ngtcp2_put_uvarint(p, fr->max_streams);
assert((size_t)(p - out) == len);
ngtcp2_ssize
ngtcp2_pkt_encode_new_connection_id_frame(uint8_t *out, size_t outlen,
const ngtcp2_new_connection_id *fr) {
- size_t len = 1 + ngtcp2_put_varint_len(fr->seq) +
- ngtcp2_put_varint_len(fr->retire_prior_to) + 1 +
+ size_t len = 1 + ngtcp2_put_uvarintlen(fr->seq) +
+ ngtcp2_put_uvarintlen(fr->retire_prior_to) + 1 +
fr->cid.datalen + NGTCP2_STATELESS_RESET_TOKENLEN;
uint8_t *p;
p = out;
*p++ = NGTCP2_FRAME_NEW_CONNECTION_ID;
- p = ngtcp2_put_varint(p, fr->seq);
- p = ngtcp2_put_varint(p, fr->retire_prior_to);
+ p = ngtcp2_put_uvarint(p, fr->seq);
+ p = ngtcp2_put_uvarint(p, fr->retire_prior_to);
*p++ = (uint8_t)fr->cid.datalen;
p = ngtcp2_cpymem(p, fr->cid.data, fr->cid.datalen);
p = ngtcp2_cpymem(p, fr->stateless_reset_token,
ngtcp2_ssize
ngtcp2_pkt_encode_stop_sending_frame(uint8_t *out, size_t outlen,
const ngtcp2_stop_sending *fr) {
- size_t len = 1 + ngtcp2_put_varint_len((uint64_t)fr->stream_id) +
- ngtcp2_put_varint_len(fr->app_error_code);
+ size_t len = 1 + ngtcp2_put_uvarintlen((uint64_t)fr->stream_id) +
+ ngtcp2_put_uvarintlen(fr->app_error_code);
uint8_t *p;
if (outlen < len) {
p = out;
*p++ = NGTCP2_FRAME_STOP_SENDING;
- p = ngtcp2_put_varint(p, (uint64_t)fr->stream_id);
- p = ngtcp2_put_varint(p, fr->app_error_code);
+ p = ngtcp2_put_uvarint(p, (uint64_t)fr->stream_id);
+ p = ngtcp2_put_uvarint(p, fr->app_error_code);
assert((size_t)(p - out) == len);
size_t i;
size_t datalen = 0;
- len += ngtcp2_put_varint_len(fr->offset);
+ len += ngtcp2_put_uvarintlen(fr->offset);
for (i = 0; i < fr->datacnt; ++i) {
datalen += fr->data[i].len;
}
- len += ngtcp2_put_varint_len(datalen);
+ len += ngtcp2_put_uvarintlen(datalen);
len += datalen;
if (outlen < len) {
*p++ = NGTCP2_FRAME_CRYPTO;
- p = ngtcp2_put_varint(p, fr->offset);
- p = ngtcp2_put_varint(p, datalen);
+ p = ngtcp2_put_uvarint(p, fr->offset);
+ p = ngtcp2_put_uvarint(p, datalen);
for (i = 0; i < fr->datacnt; ++i) {
assert(fr->data[i].base);
ngtcp2_ssize ngtcp2_pkt_encode_new_token_frame(uint8_t *out, size_t outlen,
const ngtcp2_new_token *fr) {
- size_t len = 1 + ngtcp2_put_varint_len(fr->token.len) + fr->token.len;
+ size_t len = 1 + ngtcp2_put_uvarintlen(fr->token.len) + fr->token.len;
uint8_t *p;
assert(fr->token.len);
*p++ = NGTCP2_FRAME_NEW_TOKEN;
- p = ngtcp2_put_varint(p, fr->token.len);
+ p = ngtcp2_put_uvarint(p, fr->token.len);
p = ngtcp2_cpymem(p, fr->token.base, fr->token.len);
assert((size_t)(p - out) == len);
ngtcp2_ssize ngtcp2_pkt_encode_retire_connection_id_frame(
uint8_t *out, size_t outlen, const ngtcp2_retire_connection_id *fr) {
- size_t len = 1 + ngtcp2_put_varint_len(fr->seq);
+ size_t len = 1 + ngtcp2_put_uvarintlen(fr->seq);
uint8_t *p;
if (outlen < len) {
*p++ = NGTCP2_FRAME_RETIRE_CONNECTION_ID;
- p = ngtcp2_put_varint(p, fr->seq);
+ p = ngtcp2_put_uvarint(p, fr->seq);
assert((size_t)(p - out) == len);
uint64_t datalen = ngtcp2_vec_len(fr->data, fr->datacnt);
uint64_t len =
1 +
- (fr->type == NGTCP2_FRAME_DATAGRAM ? 0 : ngtcp2_put_varint_len(datalen)) +
+ (fr->type == NGTCP2_FRAME_DATAGRAM ? 0 : ngtcp2_put_uvarintlen(datalen)) +
datalen;
uint8_t *p;
size_t i;
*p++ = fr->type;
if (fr->type == NGTCP2_FRAME_DATAGRAM_LEN) {
- p = ngtcp2_put_varint(p, datalen);
+ p = ngtcp2_put_uvarint(p, datalen);
}
for (i = 0; i < fr->datacnt; ++i) {
assert((payloadlen % sizeof(uint32_t)) == 0);
- for (; payload != end; payload += sizeof(uint32_t)) {
- *dest++ = ngtcp2_get_uint32(payload);
+ for (; payload != end;) {
+ payload = ngtcp2_get_uint32(dest++, payload);
}
return payloadlen / sizeof(uint32_t);
size_t ngtcp2_pkt_stream_max_datalen(int64_t stream_id, uint64_t offset,
uint64_t len, size_t left) {
- size_t n = 1 /* type */ + ngtcp2_put_varint_len((uint64_t)stream_id) +
- (offset ? ngtcp2_put_varint_len(offset) : 0);
+ size_t n = 1 /* type */ + ngtcp2_put_uvarintlen((uint64_t)stream_id) +
+ (offset ? ngtcp2_put_uvarintlen(offset) : 0);
if (left <= n) {
return (size_t)-1;
}
size_t ngtcp2_pkt_crypto_max_datalen(uint64_t offset, size_t len, size_t left) {
- size_t n = 1 /* type */ + ngtcp2_put_varint_len(offset);
+ size_t n = 1 /* type */ + ngtcp2_put_uvarintlen(offset);
/* CRYPTO frame must contain nonzero length data. Return -1 if
there is no space to write crypto data. */
}
size_t ngtcp2_pkt_datagram_framelen(size_t len) {
- return 1 /* type */ + ngtcp2_put_varint_len(len) + len;
+ return 1 /* type */ + ngtcp2_put_uvarintlen(len) + len;
}
int ngtcp2_is_supported_version(uint32_t version) {
if (hd->flags & NGTCP2_PKT_FLAG_LONG_FORM) {
ppe->len_offset = 1 + 4 + 1 + hd->dcid.datalen + 1 + hd->scid.datalen;
if (hd->type == NGTCP2_PKT_INITIAL) {
- ppe->len_offset += ngtcp2_put_varint_len(hd->token.len) + hd->token.len;
+ ppe->len_offset += ngtcp2_put_uvarintlen(hd->token.len) + hd->token.len;
}
ppe->pkt_num_offset = ppe->len_offset + NGTCP2_PKT_LENGTHLEN;
rv = ngtcp2_pkt_encode_hd_long(
assert(cc->hp_mask);
if (ppe->len_offset) {
- ngtcp2_put_varint30(
+ ngtcp2_put_uvarint30(
buf->begin + ppe->len_offset,
(uint16_t)(payloadlen + ppe->pkt_numlen + cc->aead.max_overhead));
}
uint8_t buf[1024];
uint8_t *p = buf;
const ngtcp2_preferred_addr *paddr;
+ const ngtcp2_sockaddr_in *sa_in;
+ const ngtcp2_sockaddr_in6 *sa_in6;
if (!qlog->write) {
return;
p = write_string(p, "preferred_address");
*p++ = ':';
*p++ = '{';
- p = write_pair_hex(p, "ip_v4", paddr->ipv4_addr, sizeof(paddr->ipv4_addr));
- *p++ = ',';
- p = write_pair_number(p, "port_v4", paddr->ipv4_port);
- *p++ = ',';
- p = write_pair_hex(p, "ip_v6", paddr->ipv6_addr, sizeof(paddr->ipv6_addr));
- *p++ = ',';
- p = write_pair_number(p, "port_v6", paddr->ipv6_port);
- *p++ = ',';
+
+ if (paddr->ipv4_present) {
+ sa_in = &paddr->ipv4;
+
+ p = write_pair_hex(p, "ip_v4", (const uint8_t *)&sa_in->sin_addr,
+ sizeof(sa_in->sin_addr));
+ *p++ = ',';
+ p = write_pair_number(p, "port_v4", ngtcp2_ntohs(sa_in->sin_port));
+ *p++ = ',';
+ }
+
+ if (paddr->ipv6_present) {
+ sa_in6 = &paddr->ipv6;
+
+ p = write_pair_hex(p, "ip_v6", (const uint8_t *)&sa_in6->sin6_addr,
+ sizeof(sa_in6->sin6_addr));
+ *p++ = ',';
+ p = write_pair_number(p, "port_v6", ngtcp2_ntohs(sa_in6->sin6_port));
+ *p++ = ',';
+ }
+
p = write_pair_cid(p, "connection_id", &paddr->cid);
p = write_verbatim(p, ",\"stateless_reset_token\":{");
p = write_pair_hex(p, "data", paddr->stateless_reset_token,
return dest + n;
}
+const void *ngtcp2_get_bytes(void *dest, const void *src, size_t n) {
+ memcpy(dest, src, n);
+ return (uint8_t *)src + n;
+}
+
#define LOWER_XDIGITS "0123456789abcdef"
uint8_t *ngtcp2_encode_hex(uint8_t *dest, const uint8_t *data, size_t len) {
* the buffer pointed by |dest|. It returns dest + n;
*/
uint8_t *ngtcp2_setmem(uint8_t *dest, uint8_t b, size_t n);
+
+/*
+ * ngtcp2_get_bytes copies |n| bytes from |src| to |dest|, and returns
+ * |src| + |n|.
+ */
+const void *ngtcp2_get_bytes(void *dest, const void *src, size_t n);
+
/*
* ngtcp2_encode_hex encodes |data| of length |len| in hex string. It
* writes additional NULL bytes at the end of the buffer. The buffer
*/
#define NGTCP2_TLSEXT_QUIC_TRANSPORT_PARAMETERS_DRAFT 0xffa5u
+#ifdef NGTCP2_USE_GENERIC_SOCKADDR
+typedef struct ngtcp2_sockaddr {
+ uint16_t sa_family;
+ uint8_t sa_data[14];
+} ngtcp2_sockaddr;
+
+typedef struct ngtcp2_in_addr {
+ uint32_t s_addr;
+} ngtcp2_in_addr;
+
+typedef struct ngtcp2_sockaddr_in {
+ uint16_t sin_family;
+ uint16_t sin_port;
+ ngtcp2_in_addr sin_addr;
+ uint8_t sin_zero[8];
+} ngtcp2_sockaddr_in;
+
+# define NGTCP2_SS_MAXSIZE 128
+# define NGTCP2_SS_ALIGNSIZE (sizeof(uint64_t))
+# define NGTCP2_SS_PAD1SIZE (NGTCP2_SS_ALIGNSIZE - sizeof(uint16_t))
+# define NGTCP2_SS_PAD2SIZE \
+ (NGTCP2_SS_MAXSIZE - \
+ (sizeof(uint16_t) + NGTCP2_SS_PAD1SIZE + NGTCP2_SS_ALIGNSIZE))
+
+typedef struct ngtcp2_sockaddr_storage {
+ uint16_t ss_family;
+ uint8_t _ss_pad1[NGTCP2_SS_PAD1SIZE];
+ uint64_t _ss_align;
+ uint8_t _ss_pad2[NGTCP2_SS_PAD2SIZE];
+} ngtcp2_sockaddr_storage;
+
+# undef NGTCP2_SS_PAD2SIZE
+# undef NGTCP2_SS_PAD1SIZE
+# undef NGTCP2_SS_ALIGNSIZE
+# undef NGTCP2_SS_MAXSIZE
+
+typedef uint32_t ngtcp2_socklen;
+#else
+/**
+ * @typedef
+ *
+ * :type:`ngtcp2_sockaddr` is typedefed to struct sockaddr. If
+ * :macro:`NGTCP2_USE_GENERIC_SOCKADDR` is defined, it is typedefed to
+ * the generic struct sockaddr defined in ngtcp2.h.
+ */
+typedef struct sockaddr ngtcp2_sockaddr;
+/**
+ * @typedef
+ *
+ * :type:`ngtcp2_sockaddr_storage` is typedefed to struct
+ * sockaddr_storage. If :macro:`NGTCP2_USE_GENERIC_SOCKADDR` is
+ * defined, it is typedefed to the generic struct sockaddr_storage
+ * defined in ngtcp2.h.
+ */
+typedef struct sockaddr_storage ngtcp2_sockaddr_storage;
+/**
+ * @typedef
+ *
+ * :type:`ngtcp2_sockaddr_in` is typedefed to struct sockaddr_in. If
+ * :macro:`NGTCP2_USE_GENERIC_SOCKADDR` is defined, it is typedefed to
+ * the generic struct sockaddr_in defined in ngtcp2.h.
+ */
+typedef struct sockaddr_in ngtcp2_sockaddr_in;
+/**
+ * @typedef
+ *
+ * :type:`ngtcp2_socklen` is typedefed to socklen_t. If
+ * :macro:`NGTCP2_USE_GENERIC_SOCKADDR` is defined, it is typedefed to
+ * uint32_t.
+ */
+typedef socklen_t ngtcp2_socklen;
+#endif
+
+#if defined(NGTCP2_USE_GENERIC_SOCKADDR) || \
+ defined(NGTCP2_USE_GENERIC_IPV6_SOCKADDR)
+typedef struct ngtcp2_in6_addr {
+ uint8_t in6_addr[16];
+} ngtcp2_in6_addr;
+
+typedef struct ngtcp2_sockaddr_in6 {
+ uint16_t sin6_family;
+ uint16_t sin6_port;
+ uint32_t sin6_flowinfo;
+ ngtcp2_in6_addr sin6_addr;
+ uint32_t sin6_scope_id;
+} ngtcp2_sockaddr_in6;
+#else
+/**
+ * @typedef
+ *
+ * :type:`ngtcp2_sockaddr_in6` is typedefed to struct sockaddr_in6.
+ * If :macro:`NGTCP2_USE_GENERIC_SOCKADDR` is defined, it is typedefed
+ * to the generic struct sockaddr_in6 defined in ngtcp2.h.
+ */
+typedef struct sockaddr_in6 ngtcp2_sockaddr_in6;
+#endif
+
+/**
+ * @struct
+ *
+ * :type:`ngtcp2_sockaddr_union` conveniently includes all supported
+ * address types.
+ */
+typedef union ngtcp2_sockaddr_union {
+ ngtcp2_sockaddr sa;
+ ngtcp2_sockaddr_in in;
+ ngtcp2_sockaddr_in6 in6;
+} ngtcp2_sockaddr_union;
+
/**
* @struct
*
*/
ngtcp2_cid cid;
/**
- * :member:`ipv4_port` is a port of IPv4 address.
- */
- uint16_t ipv4_port;
- /**
- * :member:`ipv6_port` is a port of IPv6 address.
- */
- uint16_t ipv6_port;
- /**
- * :member:`ipv4_addr` contains IPv4 address in network byte order.
+ * :member:`ipv4` contains IPv4 address and port.
*/
- uint8_t ipv4_addr[4];
+ ngtcp2_sockaddr_in ipv4;
/**
- * :member:`ipv6_addr` contains IPv6 address in network byte order.
+ * :member:`ipv6` contains IPv4 address and port.
*/
- uint8_t ipv6_addr[16];
+ ngtcp2_sockaddr_in6 ipv6;
/**
- * :member:`ipv4_present` indicates that :member:`ipv4_addr` and
- * :member:`ipv4_port` contain IPv4 address and port respectively.
+ * :member:`ipv4_present` indicates that :member:`ipv4` contains
+ * IPv4 address and port.
*/
uint8_t ipv4_present;
/**
- * :member:`ipv6_present` indicates that :member:`ipv6_addr` and
- * :member:`ipv6_port` contain IPv6 address and port respectively.
+ * :member:`ipv6_present` indicates that :member:`ipv6` contains
+ * IPv6 address and port.
*/
uint8_t ipv6_present;
/**
int no_pmtud;
} ngtcp2_settings;
-#ifdef NGTCP2_USE_GENERIC_SOCKADDR
-typedef struct ngtcp2_sockaddr {
- uint16_t sa_family;
- uint8_t sa_data[14];
-} ngtcp2_sockaddr;
-
-typedef struct ngtcp2_in_addr {
- uint32_t s_addr;
-} ngtcp2_in_addr;
-
-typedef struct ngtcp2_sockaddr_in {
- uint16_t sin_family;
- uint16_t sin_port;
- ngtcp2_in_addr sin_addr;
- uint8_t sin_zero[8];
-} ngtcp2_sockaddr_in;
-
-# define NGTCP2_SS_MAXSIZE 128
-# define NGTCP2_SS_ALIGNSIZE (sizeof(uint64_t))
-# define NGTCP2_SS_PAD1SIZE (NGTCP2_SS_ALIGNSIZE - sizeof(uint16_t))
-# define NGTCP2_SS_PAD2SIZE \
- (NGTCP2_SS_MAXSIZE - \
- (sizeof(uint16_t) + NGTCP2_SS_PAD1SIZE + NGTCP2_SS_ALIGNSIZE))
-
-typedef struct ngtcp2_sockaddr_storage {
- uint16_t ss_family;
- uint8_t _ss_pad1[NGTCP2_SS_PAD1SIZE];
- uint64_t _ss_align;
- uint8_t _ss_pad2[NGTCP2_SS_PAD2SIZE];
-} ngtcp2_sockaddr_storage;
-
-# undef NGTCP2_SS_PAD2SIZE
-# undef NGTCP2_SS_PAD1SIZE
-# undef NGTCP2_SS_ALIGNSIZE
-# undef NGTCP2_SS_MAXSIZE
-
-typedef uint32_t ngtcp2_socklen;
-#else
-/**
- * @typedef
- *
- * :type:`ngtcp2_sockaddr` is typedefed to struct sockaddr. If
- * :macro:`NGTCP2_USE_GENERIC_SOCKADDR` is defined, it is typedefed to
- * the generic struct sockaddr defined in ngtcp2.h.
- */
-typedef struct sockaddr ngtcp2_sockaddr;
-/**
- * @typedef
- *
- * :type:`ngtcp2_sockaddr_storage` is typedefed to struct
- * sockaddr_storage. If :macro:`NGTCP2_USE_GENERIC_SOCKADDR` is
- * defined, it is typedefed to the generic struct sockaddr_storage
- * defined in ngtcp2.h.
- */
-typedef struct sockaddr_storage ngtcp2_sockaddr_storage;
-typedef struct sockaddr_in ngtcp2_sockaddr_in;
-/**
- * @typedef
- *
- * :type:`ngtcp2_socklen` is typedefed to socklen_t. If
- * :macro:`NGTCP2_USE_GENERIC_SOCKADDR` is defined, it is typedefed to
- * uint32_t.
- */
-typedef socklen_t ngtcp2_socklen;
-#endif
-
-#if defined(NGTCP2_USE_GENERIC_SOCKADDR) || \
- defined(NGTCP2_USE_GENERIC_IPV6_SOCKADDR)
-typedef struct ngtcp2_in6_addr {
- uint8_t in6_addr[16];
-} ngtcp2_in6_addr;
-
-typedef struct ngtcp2_sockaddr_in6 {
- uint16_t sin6_family;
- uint16_t sin6_port;
- uint32_t sin6_flowinfo;
- ngtcp2_in6_addr sin6_addr;
- uint32_t sin6_scope_id;
-} ngtcp2_sockaddr_in6;
-#else
-typedef struct sockaddr_in6 ngtcp2_sockaddr_in6;
-#endif
-
/**
* @struct
*
/**
* :member:`local_addrbuf` is a buffer to store local address.
*/
- ngtcp2_sockaddr_storage local_addrbuf;
+ ngtcp2_sockaddr_union local_addrbuf;
/**
* :member:`remote_addrbuf` is a buffer to store remote address.
*/
- ngtcp2_sockaddr_storage remote_addrbuf;
+ ngtcp2_sockaddr_union remote_addrbuf;
} ngtcp2_path_storage;
/**
*
* Version number of the ngtcp2 library release.
*/
-#define NGTCP2_VERSION "0.11.0"
+#define NGTCP2_VERSION "0.12.0"
/**
* @macro
* number, 8 bits for minor and 8 bits for patch. Version 1.2.3
* becomes 0x010203.
*/
-#define NGTCP2_VERSION_NUM 0x000b00
+#define NGTCP2_VERSION_NUM 0x000c00
#endif /* VERSION_H */