freezero:
   25|  7.14k|{
   26|       |	/* This is legal. */
   27|  7.14k|	if (ptr == NULL)
  ------------------
  |  Branch (27:6): [True: 2.03k, False: 5.10k]
  ------------------
   28|  2.03k|		return;
   29|       |
   30|  5.10k|	explicit_bzero(ptr, sz);
   31|  5.10k|	free(ptr);
   32|  5.10k|}

ibuf_dynamic:
   78|  7.14k|{
   79|  7.14k|	struct ibuf	*buf;
   80|       |
   81|  7.14k|	if (max == 0 || max < len) {
  ------------------
  |  Branch (81:6): [True: 0, False: 7.14k]
  |  Branch (81:18): [True: 0, False: 7.14k]
  ------------------
   82|      0|		errno = EINVAL;
   83|      0|		return (NULL);
   84|      0|	}
   85|       |
   86|  7.14k|	if ((buf = calloc(1, sizeof(struct ibuf))) == NULL)
  ------------------
  |  Branch (86:6): [True: 0, False: 7.14k]
  ------------------
   87|      0|		return (NULL);
   88|  7.14k|	if (len > 0) {
  ------------------
  |  Branch (88:6): [True: 5.10k, False: 2.03k]
  ------------------
   89|  5.10k|		if ((buf->buf = calloc(len, 1)) == NULL) {
  ------------------
  |  Branch (89:7): [True: 0, False: 5.10k]
  ------------------
   90|      0|			free(buf);
   91|      0|			return (NULL);
   92|      0|		}
   93|  5.10k|	}
   94|  7.14k|	buf->size = len;
   95|  7.14k|	buf->max = max;
   96|  7.14k|	buf->fd = -1;
   97|       |
   98|  7.14k|	return (buf);
   99|  7.14k|}
ibuf_reserve:
  103|  5.10k|{
  104|  5.10k|	void	*b;
  105|       |
  106|  5.10k|	if (len > SIZE_MAX - buf->wpos) {
  ------------------
  |  Branch (106:6): [True: 0, False: 5.10k]
  ------------------
  107|      0|		errno = ERANGE;
  108|      0|		return (NULL);
  109|      0|	}
  110|  5.10k|	if (buf->fd == IBUF_FD_MARK_ON_STACK) {
  ------------------
  |  |   55|  5.10k|#define	IBUF_FD_MARK_ON_STACK	-2
  ------------------
  |  Branch (110:6): [True: 0, False: 5.10k]
  ------------------
  111|       |		/* can not grow stack buffers */
  112|      0|		errno = EINVAL;
  113|      0|		return (NULL);
  114|      0|	}
  115|       |
  116|  5.10k|	if (buf->wpos + len > buf->size) {
  ------------------
  |  Branch (116:6): [True: 0, False: 5.10k]
  ------------------
  117|      0|		unsigned char	*nb;
  118|       |
  119|       |		/* check if buffer is allowed to grow */
  120|      0|		if (buf->wpos + len > buf->max) {
  ------------------
  |  Branch (120:7): [True: 0, False: 0]
  ------------------
  121|      0|			errno = ERANGE;
  122|      0|			return (NULL);
  123|      0|		}
  124|      0|		nb = realloc(buf->buf, buf->wpos + len);
  125|      0|		if (nb == NULL)
  ------------------
  |  Branch (125:7): [True: 0, False: 0]
  ------------------
  126|      0|			return (NULL);
  127|      0|		memset(nb + buf->size, 0, buf->wpos + len - buf->size);
  128|      0|		buf->buf = nb;
  129|      0|		buf->size = buf->wpos + len;
  130|      0|	}
  131|       |
  132|  5.10k|	b = buf->buf + buf->wpos;
  133|  5.10k|	buf->wpos += len;
  134|  5.10k|	return (b);
  135|  5.10k|}
ibuf_add:
  139|  5.08k|{
  140|  5.08k|	void *b;
  141|       |
  142|  5.08k|	if (len == 0)
  ------------------
  |  Branch (142:6): [True: 0, False: 5.08k]
  ------------------
  143|      0|		return (0);
  144|       |
  145|  5.08k|	if ((b = ibuf_reserve(buf, len)) == NULL)
  ------------------
  |  Branch (145:6): [True: 0, False: 5.08k]
  ------------------
  146|      0|		return (-1);
  147|       |
  148|  5.08k|	memcpy(b, data, len);
  149|  5.08k|	return (0);
  150|  5.08k|}
ibuf_add_zero:
  238|     21|{
  239|     21|	void *b;
  240|       |
  241|     21|	if (len == 0)
  ------------------
  |  Branch (241:6): [True: 0, False: 21]
  ------------------
  242|      0|		return (0);
  243|       |
  244|     21|	if ((b = ibuf_reserve(buf, len)) == NULL)
  ------------------
  |  Branch (244:6): [True: 0, False: 21]
  ------------------
  245|      0|		return (-1);
  246|     21|	memset(b, 0, len);
  247|     21|	return (0);
  248|     21|}
ibuf_seek:
  271|  53.0k|{
  272|       |	/* only allow seeking between rpos and wpos */
  273|  53.0k|	if (ibuf_size(buf) < pos || SIZE_MAX - pos < len ||
  ------------------
  |  Branch (273:6): [True: 0, False: 53.0k]
  |  Branch (273:30): [True: 0, False: 53.0k]
  ------------------
  274|  53.0k|	    ibuf_size(buf) < pos + len) {
  ------------------
  |  Branch (274:6): [True: 0, False: 53.0k]
  ------------------
  275|      0|		errno = ERANGE;
  276|      0|		return (NULL);
  277|      0|	}
  278|       |
  279|  53.0k|	return (buf->buf + buf->rpos + pos);
  280|  53.0k|}
ibuf_data:
  401|   130k|{
  402|   130k|	return (buf->buf + buf->rpos);
  403|   130k|}
ibuf_size:
  407|   109k|{
  408|   109k|	return (buf->wpos - buf->rpos);
  409|   109k|}
ibuf_free:
  591|  37.8k|{
  592|  37.8k|	int save_errno = errno;
  593|       |
  594|  37.8k|	if (buf == NULL)
  ------------------
  |  Branch (594:6): [True: 30.6k, False: 7.14k]
  ------------------
  595|  30.6k|		return;
  596|       |	/* if buf lives on the stack abort before causing more harm */
  597|  7.14k|	if (buf->fd == IBUF_FD_MARK_ON_STACK)
  ------------------
  |  |   55|  7.14k|#define	IBUF_FD_MARK_ON_STACK	-2
  ------------------
  |  Branch (597:6): [True: 0, False: 7.14k]
  ------------------
  598|      0|		abort();
  599|  7.14k|	if (buf->fd >= 0)
  ------------------
  |  Branch (599:6): [True: 0, False: 7.14k]
  ------------------
  600|      0|		close(buf->fd);
  601|  7.14k|	freezero(buf->buf, buf->size);
  602|  7.14k|	free(buf);
  603|       |	errno = save_errno;
  604|  7.14k|}

recallocarray:
   32|     36|{
   33|     36|	size_t oldsize, newsize;
   34|     36|	void *newptr;
   35|       |
   36|     36|	if (ptr == NULL)
  ------------------
  |  Branch (36:6): [True: 36, False: 0]
  ------------------
   37|     36|		return calloc(newnmemb, size);
   38|       |
   39|      0|	if ((newnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
  ------------------
  |  |   28|      0|#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
  ------------------
              	if ((newnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
  ------------------
  |  |   28|      0|#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
  ------------------
  |  Branch (39:7): [True: 0, False: 0]
  |  Branch (39:38): [True: 0, False: 0]
  ------------------
   40|      0|	    newnmemb > 0 && SIZE_MAX / newnmemb < size) {
  ------------------
  |  Branch (40:6): [True: 0, False: 0]
  |  Branch (40:22): [True: 0, False: 0]
  ------------------
   41|      0|		errno = ENOMEM;
   42|      0|		return NULL;
   43|      0|	}
   44|      0|	newsize = newnmemb * size;
   45|       |
   46|      0|	if ((oldnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
  ------------------
  |  |   28|      0|#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
  ------------------
              	if ((oldnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
  ------------------
  |  |   28|      0|#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
  ------------------
  |  Branch (46:7): [True: 0, False: 0]
  |  Branch (46:38): [True: 0, False: 0]
  ------------------
   47|      0|	    oldnmemb > 0 && SIZE_MAX / oldnmemb < size) {
  ------------------
  |  Branch (47:6): [True: 0, False: 0]
  |  Branch (47:22): [True: 0, False: 0]
  ------------------
   48|      0|		errno = EINVAL;
   49|      0|		return NULL;
   50|      0|	}
   51|      0|	oldsize = oldnmemb * size;
   52|       |	
   53|       |	/*
   54|       |	 * Don't bother too much if we're shrinking just a bit,
   55|       |	 * we do not shrink for series of small steps, oh well.
   56|       |	 */
   57|      0|	if (newsize <= oldsize) {
  ------------------
  |  Branch (57:6): [True: 0, False: 0]
  ------------------
   58|      0|		size_t d = oldsize - newsize;
   59|       |
   60|      0|		if (d < oldsize / 2 && d < (size_t)getpagesize()) {
  ------------------
  |  Branch (60:7): [True: 0, False: 0]
  |  Branch (60:26): [True: 0, False: 0]
  ------------------
   61|      0|			memset((char *)ptr + newsize, 0, d);
   62|      0|			return ptr;
   63|      0|		}
   64|      0|	}
   65|       |
   66|      0|	newptr = malloc(newsize);
   67|      0|	if (newptr == NULL)
  ------------------
  |  Branch (67:6): [True: 0, False: 0]
  ------------------
   68|      0|		return NULL;
   69|       |
   70|      0|	if (newsize > oldsize) {
  ------------------
  |  Branch (70:6): [True: 0, False: 0]
  ------------------
   71|      0|		memcpy(newptr, ptr, oldsize);
   72|      0|		memset((char *)newptr + oldsize, 0, newsize - oldsize);
   73|      0|	} else
   74|      0|		memcpy(newptr, ptr, newsize);
   75|       |
   76|      0|	explicit_bzero(ptr, oldsize);
   77|      0|	free(ptr);
   78|       |
   79|      0|	return newptr;
   80|      0|}

ikev2_pld_parse:
  120|  2.58k|{
  121|  2.58k|	log_debug("%s: header ispi %s rspi %s"
  122|  2.58k|	    " nextpayload %s version 0x%02x exchange %s flags 0x%02x"
  123|  2.58k|	    " msgid %d length %u response %d", __func__,
  124|  2.58k|	    print_spi(betoh64(hdr->ike_ispi), 8),
  125|  2.58k|	    print_spi(betoh64(hdr->ike_rspi), 8),
  126|  2.58k|	    print_map(hdr->ike_nextpayload, ikev2_payload_map),
  127|  2.58k|	    hdr->ike_version,
  128|  2.58k|	    print_map(hdr->ike_exchange, ikev2_exchange_map),
  129|  2.58k|	    hdr->ike_flags,
  130|  2.58k|	    betoh32(hdr->ike_msgid),
  131|  2.58k|	    betoh32(hdr->ike_length),
  132|  2.58k|	    msg->msg_response);
  133|       |
  134|  2.58k|	if (ibuf_size(msg->msg_data) < betoh32(hdr->ike_length)) {
  ------------------
  |  Branch (134:6): [True: 31, False: 2.54k]
  ------------------
  135|     31|		log_debug("%s: short message", __func__);
  136|     31|		return (-1);
  137|     31|	}
  138|       |
  139|  2.54k|	offset += sizeof(*hdr);
  140|       |
  141|  2.54k|	return (ikev2_pld_payloads(env, msg, offset,
  142|       |	    betoh32(hdr->ike_length), hdr->ike_nextpayload));
  143|  2.58k|}
ikev2_validate_pld:
  148|  43.3k|{
  149|  43.3k|	uint8_t		*msgbuf = ibuf_data(msg->msg_data);
  150|  43.3k|	size_t		 pld_length;
  151|       |
  152|       |	/* We need at least the generic header. */
  153|  43.3k|	if (left < sizeof(*pld)) {
  ------------------
  |  Branch (153:6): [True: 223, False: 43.0k]
  ------------------
  154|    223|		log_debug("%s: malformed payload: too short for generic "
  155|    223|		    "header (%zu < %zu)", __func__, left, sizeof(*pld));
  156|    223|		return (-1);
  157|    223|	}
  158|  43.0k|	memcpy(pld, msgbuf + offset, sizeof(*pld));
  159|       |
  160|       |	/*
  161|       |	 * We need at least the specified number of bytes.
  162|       |	 * pld_length is the full size of the payload including
  163|       |	 * the generic payload header.
  164|       |	 */
  165|  43.0k|	pld_length = betoh16(pld->pld_length);
  166|  43.0k|	if (left < pld_length) {
  ------------------
  |  Branch (166:6): [True: 302, False: 42.7k]
  ------------------
  167|    302|		log_debug("%s: malformed payload: shorter than specified "
  168|    302|		    "(%zu < %zu)", __func__, left, pld_length);
  169|    302|		return (-1);
  170|    302|	}
  171|       |	/*
  172|       |	 * Sanity check the specified payload size, it must
  173|       |	 * be at least the size of the generic payload header.
  174|       |	 */
  175|  42.7k|	if (pld_length < sizeof(*pld)) {
  ------------------
  |  Branch (175:6): [True: 109, False: 42.6k]
  ------------------
  176|    109|		log_debug("%s: malformed payload: shorter than minimum "
  177|    109|		    "header size (%zu < %zu)", __func__, pld_length,
  178|    109|		    sizeof(*pld));
  179|    109|		return (-1);
  180|    109|	}
  181|       |
  182|  42.6k|	return (0);
  183|  42.7k|}
ikev2_pld_payloads:
  188|  3.81k|{
  189|  3.81k|	struct ikev2_payload	 pld;
  190|  3.81k|	unsigned int		 e;
  191|  3.81k|	int			 ret;
  192|  3.81k|	uint8_t			*msgbuf = ibuf_data(msg->msg_data);
  193|  3.81k|	size_t			 total, left;
  194|       |
  195|       |	/* Check if message was decrypted in an E payload */
  196|  3.81k|	e = msg->msg_e ? IKED_E : 0;
  ------------------
  |  |   76|  1.26k|#define IKED_E			0x1000	/* Decrypted flag */
  ------------------
  |  Branch (196:6): [True: 1.26k, False: 2.54k]
  ------------------
  197|       |
  198|       |	/* Bytes left in datagram. */
  199|  3.81k|	total = length - offset;
  200|       |
  201|  44.7k|	while (payload != 0 && offset < length) {
  ------------------
  |  Branch (201:9): [True: 44.3k, False: 353]
  |  Branch (201:25): [True: 43.3k, False: 1.02k]
  ------------------
  202|  43.3k|		if (ikev2_validate_pld(msg, offset, total, &pld))
  ------------------
  |  Branch (202:7): [True: 634, False: 42.6k]
  ------------------
  203|    634|			return (-1);
  204|       |
  205|  42.6k|		log_debug("%s: %spayload %s"
  206|  42.6k|		    " nextpayload %s critical 0x%02x length %d",
  207|  42.6k|		    __func__, e ? "decrypted " : "",
  ------------------
  |  Branch (207:17): [True: 26.9k, False: 15.7k]
  ------------------
  208|  42.6k|		    print_map(payload, ikev2_payload_map),
  209|  42.6k|		    print_map(pld.pld_nextpayload, ikev2_payload_map),
  210|  42.6k|		    pld.pld_reserved & IKEV2_CRITICAL_PAYLOAD,
  ------------------
  |  |   89|  42.6k|#define IKEV2_CRITICAL_PAYLOAD	0x01	/* First bit in the reserved field */
  ------------------
  211|  42.6k|		    betoh16(pld.pld_length));
  212|       |
  213|       |		/* Skip over generic payload header. */
  214|  42.6k|		offset += sizeof(pld);
  215|  42.6k|		total -= sizeof(pld);
  216|  42.6k|		left = betoh16(pld.pld_length) - sizeof(pld);
  217|  42.6k|		ret = 0;
  218|       |
  219|  42.6k|		switch (payload | e) {
  220|  3.87k|		case IKEV2_PAYLOAD_SA:
  ------------------
  |  |   93|  3.87k|#define IKEV2_PAYLOAD_SA	33	/* Security Association */
  ------------------
  |  Branch (220:3): [True: 3.87k, False: 38.8k]
  ------------------
  221|  4.78k|		case IKEV2_PAYLOAD_SA | IKED_E:
  ------------------
  |  |   93|  4.78k|#define IKEV2_PAYLOAD_SA	33	/* Security Association */
  ------------------
              		case IKEV2_PAYLOAD_SA | IKED_E:
  ------------------
  |  |   76|  4.78k|#define IKED_E			0x1000	/* Decrypted flag */
  ------------------
  |  Branch (221:3): [True: 911, False: 41.7k]
  ------------------
  222|  4.78k|			ret = ikev2_pld_sa(env, &pld, msg, offset, left);
  223|  4.78k|			break;
  224|    627|		case IKEV2_PAYLOAD_KE:
  ------------------
  |  |   94|    627|#define IKEV2_PAYLOAD_KE	34	/* Key Exchange */
  ------------------
  |  Branch (224:3): [True: 627, False: 42.0k]
  ------------------
  225|  1.06k|		case IKEV2_PAYLOAD_KE | IKED_E:
  ------------------
  |  |   94|  1.06k|#define IKEV2_PAYLOAD_KE	34	/* Key Exchange */
  ------------------
              		case IKEV2_PAYLOAD_KE | IKED_E:
  ------------------
  |  |   76|  1.06k|#define IKED_E			0x1000	/* Decrypted flag */
  ------------------
  |  Branch (225:3): [True: 437, False: 42.2k]
  ------------------
  226|  1.06k|			ret = ikev2_pld_ke(env, &pld, msg, offset, left);
  227|  1.06k|			break;
  228|    748|		case IKEV2_PAYLOAD_IDi | IKED_E:
  ------------------
  |  |   95|    748|#define IKEV2_PAYLOAD_IDi	35	/* Identification - Initiator */
  ------------------
              		case IKEV2_PAYLOAD_IDi | IKED_E:
  ------------------
  |  |   76|    748|#define IKED_E			0x1000	/* Decrypted flag */
  ------------------
  |  Branch (228:3): [True: 748, False: 41.9k]
  ------------------
  229|  1.53k|		case IKEV2_PAYLOAD_IDr | IKED_E:
  ------------------
  |  |   96|  1.53k|#define IKEV2_PAYLOAD_IDr	36	/* Identification - Responder */
  ------------------
              		case IKEV2_PAYLOAD_IDr | IKED_E:
  ------------------
  |  |   76|  1.53k|#define IKED_E			0x1000	/* Decrypted flag */
  ------------------
  |  Branch (229:3): [True: 791, False: 41.8k]
  ------------------
  230|  1.53k|			ret = ikev2_pld_id(env, &pld, msg, offset, left,
  231|  1.53k|			    payload);
  232|  1.53k|			break;
  233|  2.10k|		case IKEV2_PAYLOAD_CERT | IKED_E:
  ------------------
  |  |   97|  2.10k|#define IKEV2_PAYLOAD_CERT	37	/* Certificate */
  ------------------
              		case IKEV2_PAYLOAD_CERT | IKED_E:
  ------------------
  |  |   76|  2.10k|#define IKED_E			0x1000	/* Decrypted flag */
  ------------------
  |  Branch (233:3): [True: 2.10k, False: 40.5k]
  ------------------
  234|  2.10k|			ret = ikev2_pld_cert(env, &pld, msg, offset, left);
  235|  2.10k|			break;
  236|  2.99k|		case IKEV2_PAYLOAD_CERTREQ:
  ------------------
  |  |   98|  2.99k|#define IKEV2_PAYLOAD_CERTREQ	38	/* Certificate Request */
  ------------------
  |  Branch (236:3): [True: 2.99k, False: 39.6k]
  ------------------
  237|  3.88k|		case IKEV2_PAYLOAD_CERTREQ | IKED_E:
  ------------------
  |  |   98|  3.88k|#define IKEV2_PAYLOAD_CERTREQ	38	/* Certificate Request */
  ------------------
              		case IKEV2_PAYLOAD_CERTREQ | IKED_E:
  ------------------
  |  |   76|  3.88k|#define IKED_E			0x1000	/* Decrypted flag */
  ------------------
  |  Branch (237:3): [True: 891, False: 41.7k]
  ------------------
  238|  3.88k|			ret = ikev2_pld_certreq(env, &pld, msg, offset, left);
  239|  3.88k|			break;
  240|  1.00k|		case IKEV2_PAYLOAD_AUTH | IKED_E:
  ------------------
  |  |   99|  1.00k|#define IKEV2_PAYLOAD_AUTH	39	/* Authentication */
  ------------------
              		case IKEV2_PAYLOAD_AUTH | IKED_E:
  ------------------
  |  |   76|  1.00k|#define IKED_E			0x1000	/* Decrypted flag */
  ------------------
  |  Branch (240:3): [True: 1.00k, False: 41.6k]
  ------------------
  241|  1.00k|			ret = ikev2_pld_auth(env, &pld, msg, offset, left);
  242|  1.00k|			break;
  243|    515|		case IKEV2_PAYLOAD_NONCE:
  ------------------
  |  |  100|    515|#define IKEV2_PAYLOAD_NONCE	40	/* Nonce */
  ------------------
  |  Branch (243:3): [True: 515, False: 42.1k]
  ------------------
  244|    940|		case IKEV2_PAYLOAD_NONCE | IKED_E:
  ------------------
  |  |  100|    940|#define IKEV2_PAYLOAD_NONCE	40	/* Nonce */
  ------------------
              		case IKEV2_PAYLOAD_NONCE | IKED_E:
  ------------------
  |  |   76|    940|#define IKED_E			0x1000	/* Decrypted flag */
  ------------------
  |  Branch (244:3): [True: 425, False: 42.2k]
  ------------------
  245|    940|			ret = ikev2_pld_nonce(env, &pld, msg, offset, left);
  246|    940|			break;
  247|  3.23k|		case IKEV2_PAYLOAD_NOTIFY:
  ------------------
  |  |  101|  3.23k|#define IKEV2_PAYLOAD_NOTIFY	41	/* Notify */
  ------------------
  |  Branch (247:3): [True: 3.23k, False: 39.4k]
  ------------------
  248|  7.76k|		case IKEV2_PAYLOAD_NOTIFY | IKED_E:
  ------------------
  |  |  101|  7.76k|#define IKEV2_PAYLOAD_NOTIFY	41	/* Notify */
  ------------------
              		case IKEV2_PAYLOAD_NOTIFY | IKED_E:
  ------------------
  |  |   76|  7.76k|#define IKED_E			0x1000	/* Decrypted flag */
  ------------------
  |  Branch (248:3): [True: 4.52k, False: 38.1k]
  ------------------
  249|  7.76k|			ret = ikev2_pld_notify(env, &pld, msg, offset, left);
  250|  7.76k|			break;
  251|  3.85k|		case IKEV2_PAYLOAD_DELETE | IKED_E:
  ------------------
  |  |  102|  3.85k|#define IKEV2_PAYLOAD_DELETE	42	/* Delete */
  ------------------
              		case IKEV2_PAYLOAD_DELETE | IKED_E:
  ------------------
  |  |   76|  3.85k|#define IKED_E			0x1000	/* Decrypted flag */
  ------------------
  |  Branch (251:3): [True: 3.85k, False: 38.8k]
  ------------------
  252|  3.85k|			ret = ikev2_pld_delete(env, &pld, msg, offset, left);
  253|  3.85k|			break;
  254|  1.55k|		case IKEV2_PAYLOAD_TSi | IKED_E:
  ------------------
  |  |  104|  1.55k|#define IKEV2_PAYLOAD_TSi	44	/* Traffic Selector - Initiator */
  ------------------
              		case IKEV2_PAYLOAD_TSi | IKED_E:
  ------------------
  |  |   76|  1.55k|#define IKED_E			0x1000	/* Decrypted flag */
  ------------------
  |  Branch (254:3): [True: 1.55k, False: 41.1k]
  ------------------
  255|  3.21k|		case IKEV2_PAYLOAD_TSr | IKED_E:
  ------------------
  |  |  105|  3.21k|#define IKEV2_PAYLOAD_TSr	45	/* Traffic Selector - Responder */
  ------------------
              		case IKEV2_PAYLOAD_TSr | IKED_E:
  ------------------
  |  |   76|  3.21k|#define IKED_E			0x1000	/* Decrypted flag */
  ------------------
  |  Branch (255:3): [True: 1.66k, False: 41.0k]
  ------------------
  256|  3.21k|			ret = ikev2_pld_tss(env, &pld, msg, offset, left);
  257|  3.21k|			break;
  258|  1.24k|		case IKEV2_PAYLOAD_SK:
  ------------------
  |  |  106|  1.24k|#define IKEV2_PAYLOAD_SK	46	/* Encrypted */
  ------------------
  |  Branch (258:3): [True: 1.24k, False: 41.4k]
  ------------------
  259|  1.24k|			ret = ikev2_pld_e(env, &pld, msg, offset, left);
  260|  1.24k|			break;
  261|    112|		case IKEV2_PAYLOAD_SKF:
  ------------------
  |  |  110|    112|#define IKEV2_PAYLOAD_SKF	53	/* RFC7383 Encrypted Fragment Payload */
  ------------------
  |  Branch (261:3): [True: 112, False: 42.5k]
  ------------------
  262|    112|			ret = ikev2_pld_ef(env, &pld, msg, offset, left);
  263|    112|			break;
  264|  1.92k|		case IKEV2_PAYLOAD_CP | IKED_E:
  ------------------
  |  |  107|  1.92k|#define IKEV2_PAYLOAD_CP	47	/* Configuration Payload */
  ------------------
              		case IKEV2_PAYLOAD_CP | IKED_E:
  ------------------
  |  |   76|  1.92k|#define IKED_E			0x1000	/* Decrypted flag */
  ------------------
  |  Branch (264:3): [True: 1.92k, False: 40.7k]
  ------------------
  265|  1.92k|			ret = ikev2_pld_cp(env, &pld, msg, offset, left);
  266|  1.92k|			break;
  267|  2.15k|		case IKEV2_PAYLOAD_EAP | IKED_E:
  ------------------
  |  |  108|  2.15k|#define IKEV2_PAYLOAD_EAP	48	/* Extensible Authentication */
  ------------------
              		case IKEV2_PAYLOAD_EAP | IKED_E:
  ------------------
  |  |   76|  2.15k|#define IKED_E			0x1000	/* Decrypted flag */
  ------------------
  |  Branch (267:3): [True: 2.15k, False: 40.5k]
  ------------------
  268|  2.15k|			ret = ikev2_pld_eap(env, &pld, msg, offset, left);
  269|  2.15k|			break;
  270|  7.10k|		default:
  ------------------
  |  Branch (270:3): [True: 7.10k, False: 35.5k]
  ------------------
  271|  7.10k|			print_hex(msgbuf, offset,
  272|  7.10k|			    betoh16(pld.pld_length) - sizeof(pld));
  273|  7.10k|			break;
  274|  42.6k|		}
  275|       |
  276|  42.6k|		if (ret != 0 && ikev2_msg_frompeer(msg)) {
  ------------------
  |  Branch (276:7): [True: 18.7k, False: 23.9k]
  |  Branch (276:19): [True: 946, False: 17.8k]
  ------------------
  277|    946|			(void)ikev2_send_informational(env, msg);
  278|    946|			return (-1);
  279|    946|		}
  280|       |
  281|       |		/* Encrypted payloads must appear last */
  282|  41.7k|		if ((payload == IKEV2_PAYLOAD_SK) ||
  ------------------
  |  |  106|  41.7k|#define IKEV2_PAYLOAD_SK	46	/* Encrypted */
  ------------------
  |  Branch (282:7): [True: 778, False: 40.9k]
  ------------------
  283|  40.9k|		    (payload == IKEV2_PAYLOAD_SKF))
  ------------------
  |  |  110|  40.9k|#define IKEV2_PAYLOAD_SKF	53	/* RFC7383 Encrypted Fragment Payload */
  ------------------
  |  Branch (283:7): [True: 74, False: 40.8k]
  ------------------
  284|    852|			return (0);
  285|       |
  286|  40.8k|		payload = pld.pld_nextpayload;
  287|  40.8k|		offset += left;
  288|  40.8k|		total -= left;
  289|  40.8k|	}
  290|       |
  291|  1.38k|	return (0);
  292|  3.81k|}
ikev2_validate_sa:
  297|  6.42k|{
  298|  6.42k|	uint8_t		*msgbuf = ibuf_data(msg->msg_data);
  299|  6.42k|	size_t		 sap_length;
  300|       |
  301|  6.42k|	if (left < sizeof(*sap)) {
  ------------------
  |  Branch (301:6): [True: 1.16k, False: 5.26k]
  ------------------
  302|  1.16k|		log_debug("%s: malformed payload: too short for header "
  303|  1.16k|		    "(%zu < %zu)", __func__, left, sizeof(*sap));
  304|  1.16k|		return (-1);
  305|  1.16k|	}
  306|  5.26k|	memcpy(sap, msgbuf + offset, sizeof(*sap));
  307|       |
  308|  5.26k|	sap_length = betoh16(sap->sap_length);
  309|  5.26k|	if (sap_length < sizeof(*sap)) {
  ------------------
  |  Branch (309:6): [True: 335, False: 4.92k]
  ------------------
  310|    335|		log_debug("%s: malformed payload: shorter than minimum header "
  311|    335|		    "size (%zu < %zu)", __func__, sap_length, sizeof(*sap));
  312|    335|		return (-1);
  313|    335|	}
  314|  4.92k|	if (left < sap_length) {
  ------------------
  |  Branch (314:6): [True: 435, False: 4.49k]
  ------------------
  315|    435|		log_debug("%s: malformed payload: too long for actual payload "
  316|    435|		    "size (%zu < %zu)", __func__, left, sap_length);
  317|    435|		return (-1);
  318|    435|	}
  319|       |	/*
  320|       |	 * If there is only one proposal, sap_length must be the
  321|       |	 * total payload size.
  322|       |	 */
  323|  4.49k|	if (!sap->sap_more && left != sap_length) {
  ------------------
  |  Branch (323:6): [True: 1.73k, False: 2.76k]
  |  Branch (323:24): [True: 251, False: 1.47k]
  ------------------
  324|    251|		log_debug("%s: malformed payload: SA payload length mismatches "
  325|    251|		    "single proposal substructure length (%zu != %zu)",
  326|    251|		    __func__, left, sap_length);
  327|    251|		return (-1);
  328|    251|	}
  329|       |	/*
  330|       |	 * If there are more than one proposal, there must be bytes
  331|       |	 * left in the payload.
  332|       |	 */
  333|  4.23k|	if (sap->sap_more && left <= sap_length) {
  ------------------
  |  Branch (333:6): [True: 2.76k, False: 1.47k]
  |  Branch (333:23): [True: 265, False: 2.49k]
  ------------------
  334|    265|		log_debug("%s: malformed payload: SA payload too small for "
  335|    265|		    "further proposals (%zu <= %zu)", __func__,
  336|    265|		    left, sap_length);
  337|    265|		return (-1);
  338|    265|	}
  339|  3.97k|	return (0);
  340|  4.23k|}
ikev2_pld_sa:
  345|  4.78k|{
  346|  4.78k|	struct ikev2_sa_proposal	 sap;
  347|  4.78k|	struct iked_proposal		*prop = NULL;
  348|  4.78k|	uint32_t			 spi32;
  349|  4.78k|	uint64_t			 spi = 0, spi64;
  350|  4.78k|	uint8_t				*msgbuf = ibuf_data(msg->msg_data);
  351|  4.78k|	int				 r;
  352|  4.78k|	struct iked_proposals		*props;
  353|  4.78k|	size_t				 total;
  354|       |
  355|  6.42k|	do {
  356|  6.42k|		if (ikev2_validate_sa(msg, offset, left, &sap))
  ------------------
  |  Branch (356:7): [True: 2.45k, False: 3.97k]
  ------------------
  357|  2.45k|			return (-1);
  358|       |
  359|       |		/* Assumed size of the first proposals, including SPI if present. */
  360|  3.97k|		total = (betoh16(sap.sap_length) - sizeof(sap));
  361|       |
  362|  3.97k|		props = &msg->msg_parent->msg_proposals;
  363|       |
  364|  3.97k|		offset += sizeof(sap);
  365|  3.97k|		left -= sizeof(sap);
  366|       |
  367|  3.97k|		if (sap.sap_spisize) {
  ------------------
  |  Branch (367:7): [True: 1.20k, False: 2.76k]
  ------------------
  368|  1.20k|			if (left < sap.sap_spisize) {
  ------------------
  |  Branch (368:8): [True: 310, False: 897]
  ------------------
  369|    310|				log_debug("%s: malformed payload: SPI larger than "
  370|    310|				    "actual payload (%zu < %d)", __func__, left,
  371|    310|				    sap.sap_spisize);
  372|    310|				return (-1);
  373|    310|			}
  374|    897|			if (total < sap.sap_spisize) {
  ------------------
  |  Branch (374:8): [True: 77, False: 820]
  ------------------
  375|     77|				log_debug("%s: malformed payload: SPI larger than "
  376|     77|				    "proposal (%zu < %d)", __func__, total,
  377|     77|				    sap.sap_spisize);
  378|     77|				return (-1);
  379|     77|			}
  380|    820|			switch (sap.sap_spisize) {
  381|    270|			case 4:
  ------------------
  |  Branch (381:4): [True: 270, False: 550]
  ------------------
  382|    270|				memcpy(&spi32, msgbuf + offset, 4);
  383|    270|				spi = betoh32(spi32);
  384|    270|				break;
  385|    313|			case 8:
  ------------------
  |  Branch (385:4): [True: 313, False: 507]
  ------------------
  386|    313|				memcpy(&spi64, msgbuf + offset, 8);
  387|    313|				spi = betoh64(spi64);
  388|    313|				break;
  389|    237|			default:
  ------------------
  |  Branch (389:4): [True: 237, False: 583]
  ------------------
  390|    237|				log_debug("%s: unsupported SPI size %d",
  391|    237|				    __func__, sap.sap_spisize);
  392|    237|				return (-1);
  393|    820|			}
  394|       |
  395|    583|			offset += sap.sap_spisize;
  396|    583|			left -= sap.sap_spisize;
  397|       |
  398|       |			/* Assumed size of the proposal, now without SPI. */
  399|    583|			total -= sap.sap_spisize;
  400|    583|		}
  401|       |
  402|       |		/*
  403|       |		 * As we verified sanity of packet headers, this check will
  404|       |		 * be always false, but just to be sure we keep it.
  405|       |		 */
  406|  3.35k|		if (left < total) {
  ------------------
  |  Branch (406:7): [True: 0, False: 3.35k]
  ------------------
  407|      0|			log_debug("%s: malformed payload: too long for payload "
  408|      0|			    "(%zu < %zu)", __func__, left, total);
  409|      0|			return (-1);
  410|      0|		}
  411|       |
  412|  3.35k|		log_debug("%s: more %d reserved %d length %d"
  413|  3.35k|		    " proposal #%d protoid %s spisize %d xforms %d spi %s",
  414|  3.35k|		    __func__, sap.sap_more, sap.sap_reserved,
  415|  3.35k|		    betoh16(sap.sap_length), sap.sap_proposalnr,
  416|  3.35k|		    print_map(sap.sap_protoid, ikev2_saproto_map), sap.sap_spisize,
  417|  3.35k|		    sap.sap_transforms, print_spi(spi, sap.sap_spisize));
  418|       |
  419|  3.35k|		if (ikev2_msg_frompeer(msg)) {
  ------------------
  |  Branch (419:7): [True: 4, False: 3.34k]
  ------------------
  420|      4|			if ((msg->msg_parent->msg_prop = config_add_proposal(props,
  ------------------
  |  Branch (420:8): [True: 4, False: 0]
  ------------------
  421|      4|			    sap.sap_proposalnr, sap.sap_protoid)) == NULL) {
  422|      4|				log_debug("%s: invalid proposal", __func__);
  423|      4|				return (-1);
  424|      4|			}
  425|      0|			prop = msg->msg_parent->msg_prop;
  426|      0|			prop->prop_peerspi.spi = spi;
  427|      0|			prop->prop_peerspi.spi_protoid = sap.sap_protoid;
  428|      0|			prop->prop_peerspi.spi_size = sap.sap_spisize;
  429|       |
  430|      0|			prop->prop_localspi.spi_protoid = sap.sap_protoid;
  431|      0|			prop->prop_localspi.spi_size = sap.sap_spisize;
  432|      0|		}
  433|       |
  434|       |		/*
  435|       |		 * Parse the attached transforms
  436|       |		 */
  437|  3.34k|		if (sap.sap_transforms) {
  ------------------
  |  Branch (437:7): [True: 1.68k, False: 1.66k]
  ------------------
  438|  1.68k|			r = ikev2_pld_xform(env, msg, offset, total);
  439|  1.68k|			if ((r == -2) && ikev2_msg_frompeer(msg)) {
  ------------------
  |  Branch (439:8): [True: 0, False: 1.68k]
  |  Branch (439:21): [True: 0, False: 0]
  ------------------
  440|      0|				log_debug("%s: invalid proposal transform",
  441|      0|				    __func__);
  442|       |
  443|       |				/* cleanup and ignore proposal */
  444|      0|				config_free_proposal(props, prop);
  445|      0|				prop = msg->msg_parent->msg_prop = NULL;
  446|  1.68k|			} else if (r != 0) {
  ------------------
  |  Branch (446:15): [True: 1.45k, False: 233]
  ------------------
  447|  1.45k|				log_debug("%s: invalid proposal transforms",
  448|  1.45k|				    __func__);
  449|  1.45k|				return (-1);
  450|  1.45k|			}
  451|  1.68k|		}
  452|       |
  453|  1.89k|		offset += total;
  454|  1.89k|		left -= total;
  455|  1.89k|	} while (sap.sap_more);
  ------------------
  |  Branch (455:11): [True: 1.64k, False: 254]
  ------------------
  456|       |
  457|    254|	return (0);
  458|  4.78k|}
ikev2_validate_xform:
  463|  3.32k|{
  464|  3.32k|	uint8_t		*msgbuf = ibuf_data(msg->msg_data);
  465|  3.32k|	size_t		 xfrm_length;
  466|       |
  467|  3.32k|	if (total < sizeof(*xfrm)) {
  ------------------
  |  Branch (467:6): [True: 350, False: 2.97k]
  ------------------
  468|    350|		log_debug("%s: malformed payload: too short for header "
  469|    350|		    "(%zu < %zu)", __func__, total, sizeof(*xfrm));
  470|    350|		return (-1);
  471|    350|	}
  472|  2.97k|	memcpy(xfrm, msgbuf + offset, sizeof(*xfrm));
  473|       |
  474|  2.97k|	xfrm_length = betoh16(xfrm->xfrm_length);
  475|  2.97k|	if (xfrm_length < sizeof(*xfrm)) {
  ------------------
  |  Branch (475:6): [True: 211, False: 2.76k]
  ------------------
  476|    211|		log_debug("%s: malformed payload: shorter than minimum header "
  477|    211|		    "size (%zu < %zu)", __func__, xfrm_length, sizeof(*xfrm));
  478|    211|		return (-1);
  479|    211|	}
  480|  2.76k|	if (total < xfrm_length) {
  ------------------
  |  Branch (480:6): [True: 305, False: 2.45k]
  ------------------
  481|    305|		log_debug("%s: malformed payload: too long for payload size "
  482|    305|		    "(%zu < %zu)", __func__, total, xfrm_length);
  483|    305|		return (-1);
  484|    305|	}
  485|       |
  486|  2.45k|	return (0);
  487|  2.76k|}
ikev2_pld_xform:
  492|  1.68k|{
  493|  1.68k|	struct ikev2_transform		 xfrm;
  494|  1.68k|	char				 id[BUFSIZ];
  495|  1.68k|	int				 r;
  496|  1.68k|	size_t				 xfrm_length;
  497|       |
  498|  3.32k|	do {
  499|  3.32k|		if (ikev2_validate_xform(msg, offset, total, &xfrm))
  ------------------
  |  Branch (499:7): [True: 866, False: 2.45k]
  ------------------
  500|    866|			return (-1);
  501|       |
  502|  2.45k|		xfrm_length = betoh16(xfrm.xfrm_length);
  503|       |
  504|  2.45k|		switch (xfrm.xfrm_type) {
  505|    389|		case IKEV2_XFORMTYPE_ENCR:
  ------------------
  |  |  156|    389|#define IKEV2_XFORMTYPE_ENCR		1	/* Encryption */
  ------------------
  |  Branch (505:3): [True: 389, False: 2.06k]
  ------------------
  506|    389|			strlcpy(id, print_map(betoh16(xfrm.xfrm_id),
  507|    389|			    ikev2_xformencr_map), sizeof(id));
  508|    389|			break;
  509|    519|		case IKEV2_XFORMTYPE_PRF:
  ------------------
  |  |  157|    519|#define IKEV2_XFORMTYPE_PRF		2	/* Pseudo-Random Function */
  ------------------
  |  Branch (509:3): [True: 519, False: 1.93k]
  ------------------
  510|    519|			strlcpy(id, print_map(betoh16(xfrm.xfrm_id),
  511|    519|			    ikev2_xformprf_map), sizeof(id));
  512|    519|			break;
  513|    141|		case IKEV2_XFORMTYPE_INTEGR:
  ------------------
  |  |  158|    141|#define IKEV2_XFORMTYPE_INTEGR		3	/* Integrity Algorithm */
  ------------------
  |  Branch (513:3): [True: 141, False: 2.31k]
  ------------------
  514|    141|			strlcpy(id, print_map(betoh16(xfrm.xfrm_id),
  515|    141|			    ikev2_xformauth_map), sizeof(id));
  516|    141|			break;
  517|    449|		case IKEV2_XFORMTYPE_DH:
  ------------------
  |  |  159|    449|#define IKEV2_XFORMTYPE_DH		4	/* Diffie-Hellman Group */
  ------------------
  |  Branch (517:3): [True: 449, False: 2.00k]
  ------------------
  518|    449|			strlcpy(id, print_map(betoh16(xfrm.xfrm_id),
  519|    449|			    ikev2_xformdh_map), sizeof(id));
  520|    449|			break;
  521|    194|		case IKEV2_XFORMTYPE_ESN:
  ------------------
  |  |  160|    194|#define IKEV2_XFORMTYPE_ESN		5	/* Extended Sequence Numbers */
  ------------------
  |  Branch (521:3): [True: 194, False: 2.26k]
  ------------------
  522|    194|			strlcpy(id, print_map(betoh16(xfrm.xfrm_id),
  523|    194|			    ikev2_xformesn_map), sizeof(id));
  524|    194|			break;
  525|    763|		default:
  ------------------
  |  Branch (525:3): [True: 763, False: 1.69k]
  ------------------
  526|    763|			snprintf(id, sizeof(id), "<%d>", betoh16(xfrm.xfrm_id));
  527|    763|			break;
  528|  2.45k|		}
  529|       |
  530|  2.45k|		log_debug("%s: more %d reserved %d length %zu"
  531|  2.45k|		    " type %s id %s",
  532|  2.45k|		    __func__, xfrm.xfrm_more, xfrm.xfrm_reserved, xfrm_length,
  533|  2.45k|		    print_map(xfrm.xfrm_type, ikev2_xformtype_map), id);
  534|       |
  535|       |		/*
  536|       |		 * Parse transform attributes, if available
  537|       |		 */
  538|  2.45k|		msg->msg_attrlength = 0;
  539|  2.45k|		if (xfrm_length > sizeof(xfrm)) {
  ------------------
  |  Branch (539:7): [True: 1.08k, False: 1.36k]
  ------------------
  540|  1.08k|			if (ikev2_pld_attr(env, &xfrm, msg,
  ------------------
  |  Branch (540:8): [True: 486, False: 601]
  ------------------
  541|  1.08k|			    offset + sizeof(xfrm),
  542|  1.08k|			    xfrm_length - sizeof(xfrm)) != 0) {
  543|    486|				return (-1);
  544|    486|			}
  545|  1.08k|		}
  546|       |
  547|  1.96k|		if (ikev2_msg_frompeer(msg)) {
  ------------------
  |  Branch (547:7): [True: 0, False: 1.96k]
  ------------------
  548|      0|			r = config_add_transform(msg->msg_parent->msg_prop,
  549|      0|			    xfrm.xfrm_type, betoh16(xfrm.xfrm_id),
  550|      0|			    msg->msg_attrlength, msg->msg_attrlength);
  551|      0|			if (r == -1) {
  ------------------
  |  Branch (551:8): [True: 0, False: 0]
  ------------------
  552|      0|				log_debug("%s: failed to add transform:"
  553|      0|				    " alloc error", __func__);
  554|      0|				return (r);
  555|      0|			} else if (r == -2) {
  ------------------
  |  Branch (555:15): [True: 0, False: 0]
  ------------------
  556|      0|				log_debug("%s: failed to add transform:"
  557|      0|				    " unknown type", __func__);
  558|      0|				return (r);
  559|      0|			}
  560|      0|		}
  561|       |
  562|       |		/* Next transform */
  563|  1.96k|		offset += xfrm_length;
  564|  1.96k|		total -= xfrm_length;
  565|  1.96k|	} while (xfrm.xfrm_more == IKEV2_XFORM_MORE);
  ------------------
  |  |  154|  1.96k|#define IKEV2_XFORM_MORE		3
  ------------------
  |  Branch (565:11): [True: 1.63k, False: 331]
  ------------------
  566|       |
  567|    331|	if (total != 0) {
  ------------------
  |  Branch (567:6): [True: 98, False: 233]
  ------------------
  568|       |		/* No more transforms but still some data left. */
  569|     98|		log_debug("%s: less data than specified, %zu bytes left",
  570|     98|		    __func__, total);
  571|     98|		return (-1);
  572|     98|	}
  573|       |
  574|    233|	return (0);
  575|    331|}
ikev2_validate_attr:
  580|  1.73k|{
  581|  1.73k|	uint8_t		*msgbuf = ibuf_data(msg->msg_data);
  582|       |
  583|  1.73k|	if (total < sizeof(*attr)) {
  ------------------
  |  Branch (583:6): [True: 145, False: 1.58k]
  ------------------
  584|    145|		log_debug("%s: malformed payload: too short for header "
  585|    145|		    "(%zu < %zu)", __func__, total, sizeof(*attr));
  586|    145|		return (-1);
  587|    145|	}
  588|  1.58k|	memcpy(attr, msgbuf + offset, sizeof(*attr));
  589|       |
  590|  1.58k|	return (0);
  591|  1.73k|}
ikev2_pld_attr:
  596|  1.08k|{
  597|  1.08k|	struct ikev2_attribute		 attr;
  598|  1.08k|	unsigned int			 type;
  599|  1.08k|	uint8_t				*msgbuf = ibuf_data(msg->msg_data);
  600|  1.08k|	size_t				 attr_length;
  601|       |
  602|  1.73k|	do {
  603|  1.73k|		if (ikev2_validate_attr(msg, offset, total, &attr))
  ------------------
  |  Branch (603:7): [True: 145, False: 1.58k]
  ------------------
  604|    145|			return (-1);
  605|       |
  606|  1.58k|		type = betoh16(attr.attr_type) & ~IKEV2_ATTRAF_TV;
  ------------------
  |  |  278|  1.58k|#define IKEV2_ATTRAF_TV			0x8000	/* Type-Value format */
  ------------------
  607|       |
  608|  1.58k|		log_debug("%s: attribute type %s length %d total %zu",
  609|  1.58k|		    __func__, print_map(type, ikev2_attrtype_map),
  610|  1.58k|		    betoh16(attr.attr_length), total);
  611|       |
  612|  1.58k|		if (betoh16(attr.attr_type) & IKEV2_ATTRAF_TV) {
  ------------------
  |  |  278|  1.58k|#define IKEV2_ATTRAF_TV			0x8000	/* Type-Value format */
  ------------------
  |  Branch (612:7): [True: 932, False: 655]
  ------------------
  613|       |			/* Type-Value attribute */
  614|    932|			offset += sizeof(attr);
  615|    932|			total -= sizeof(attr);
  616|       |
  617|    932|			if (type == IKEV2_ATTRTYPE_KEY_LENGTH)
  ------------------
  |  |  280|    932|#define IKEV2_ATTRTYPE_KEY_LENGTH	14	/* Key length */
  ------------------
  |  Branch (617:8): [True: 314, False: 618]
  ------------------
  618|    314|				msg->msg_attrlength = betoh16(attr.attr_length);
  619|    932|		} else {
  620|       |			/* Type-Length-Value attribute */
  621|    655|			attr_length = betoh16(attr.attr_length);
  622|    655|			if (attr_length < sizeof(attr)) {
  ------------------
  |  Branch (622:8): [True: 125, False: 530]
  ------------------
  623|    125|				log_debug("%s: malformed payload: shorter than "
  624|    125|				    "minimum header size (%zu < %zu)", __func__,
  625|    125|				    attr_length, sizeof(attr));
  626|    125|				return (-1);
  627|    125|			}
  628|    530|			if (total < attr_length) {
  ------------------
  |  Branch (628:8): [True: 216, False: 314]
  ------------------
  629|    216|				log_debug("%s: malformed payload: attribute "
  630|    216|				    "larger than actual payload (%zu < %zu)",
  631|    216|				    __func__, total, attr_length);
  632|    216|				return (-1);
  633|    216|			}
  634|    314|			print_hex(msgbuf, offset + sizeof(attr),
  635|    314|			    attr_length - sizeof(attr));
  636|    314|			offset += attr_length;
  637|    314|			total -= attr_length;
  638|    314|		}
  639|       |		/* Next attribute */
  640|  1.58k|	} while (total > 0);
  ------------------
  |  Branch (640:11): [True: 645, False: 601]
  ------------------
  641|       |
  642|    601|	return (0);
  643|  1.08k|}
ikev2_validate_ke:
  648|  1.06k|{
  649|  1.06k|	uint8_t		*msgbuf = ibuf_data(msg->msg_data);
  650|       |
  651|  1.06k|	if (left < sizeof(*kex)) {
  ------------------
  |  Branch (651:6): [True: 563, False: 501]
  ------------------
  652|    563|		log_debug("%s: malformed payload: too short for header "
  653|    563|		    "(%zu < %zu)", __func__, left, sizeof(*kex));
  654|    563|		return (-1);
  655|    563|	}
  656|    501|	memcpy(kex, msgbuf + offset, sizeof(*kex));
  657|       |
  658|    501|	return (0);
  659|  1.06k|}
ikev2_pld_ke:
  664|  1.06k|{
  665|  1.06k|	struct ikev2_keyexchange	 kex;
  666|  1.06k|	uint8_t				*buf;
  667|  1.06k|	size_t				 len;
  668|  1.06k|	uint8_t				*msgbuf = ibuf_data(msg->msg_data);
  669|       |
  670|  1.06k|	if (ikev2_validate_ke(msg, offset, left, &kex))
  ------------------
  |  Branch (670:6): [True: 563, False: 501]
  ------------------
  671|    563|		return (-1);
  672|       |
  673|    501|	log_debug("%s: dh group %s reserved %d", __func__,
  674|    501|	    print_map(betoh16(kex.kex_dhgroup), ikev2_xformdh_map),
  675|    501|	    betoh16(kex.kex_reserved));
  676|       |
  677|    501|	buf = msgbuf + offset + sizeof(kex);
  678|    501|	len = left - sizeof(kex);
  679|       |
  680|    501|	if (len == 0) {
  ------------------
  |  Branch (680:6): [True: 228, False: 273]
  ------------------
  681|    228|		log_debug("%s: malformed payload: no KE data given", __func__);
  682|    228|		return (-1);
  683|    228|	}
  684|       |
  685|    273|	print_hex(buf, 0, len);
  686|       |
  687|    273|	if (ikev2_msg_frompeer(msg)) {
  ------------------
  |  Branch (687:6): [True: 11, False: 262]
  ------------------
  688|     11|		if (msg->msg_parent->msg_ke != NULL) {
  ------------------
  |  Branch (688:7): [True: 1, False: 10]
  ------------------
  689|      1|			log_info("%s: duplicate KE payload", __func__);
  690|      1|			return (-1);
  691|      1|		}
  692|     10|		if ((msg->msg_parent->msg_ke = ibuf_new(buf, len)) == NULL) {
  ------------------
  |  Branch (692:7): [True: 0, False: 10]
  ------------------
  693|      0|			log_debug("%s: failed to get exchange", __func__);
  694|      0|			return (-1);
  695|      0|		}
  696|     10|		msg->msg_parent->msg_dhgroup = betoh16(kex.kex_dhgroup);
  697|     10|	}
  698|       |
  699|    272|	return (0);
  700|    273|}
ikev2_validate_id:
  705|  1.53k|{
  706|  1.53k|	uint8_t		*msgbuf = ibuf_data(msg->msg_data);
  707|       |
  708|  1.53k|	if (left < sizeof(*id)) {
  ------------------
  |  Branch (708:6): [True: 732, False: 807]
  ------------------
  709|    732|		log_debug("%s: malformed payload: too short for header "
  710|    732|		    "(%zu < %zu)", __func__, left, sizeof(*id));
  711|    732|		return (-1);
  712|    732|	}
  713|    807|	memcpy(id, msgbuf + offset, sizeof(*id));
  714|       |
  715|    807|	if (id->id_type == IKEV2_ID_NONE) {
  ------------------
  |  |  396|    807|#define IKEV2_ID_NONE		0	/* No ID */
  ------------------
  |  Branch (715:6): [True: 285, False: 522]
  ------------------
  716|    285|		log_debug("%s: malformed payload: invalid ID type.",
  717|    285|		    __func__);
  718|    285|		return (-1);
  719|    285|	}
  720|       |
  721|    522|	return (0);
  722|    807|}
ikev2_pld_id:
  727|  1.53k|{
  728|  1.53k|	uint8_t				*ptr;
  729|  1.53k|	struct ikev2_id			 id;
  730|  1.53k|	size_t				 len;
  731|  1.53k|	struct iked_id			*idp, idb;
  732|  1.53k|	const struct iked_sa		*sa = msg->msg_sa;
  733|  1.53k|	uint8_t				*msgbuf = ibuf_data(msg->msg_data);
  734|  1.53k|	char				 idstr[IKED_ID_SIZE];
  735|       |
  736|  1.53k|	if (ikev2_validate_id(msg, offset, left, &id))
  ------------------
  |  Branch (736:6): [True: 1.01k, False: 522]
  ------------------
  737|  1.01k|		return (-1);
  738|       |
  739|    522|	bzero(&idb, sizeof(idb));
  740|       |
  741|       |	/* Don't strip the Id payload header */
  742|    522|	ptr = msgbuf + offset;
  743|    522|	len = left;
  744|       |
  745|    522|	idb.id_type = id.id_type;
  746|    522|	idb.id_offset = sizeof(id);
  747|    522|	if ((idb.id_buf = ibuf_new(ptr, len)) == NULL)
  ------------------
  |  Branch (747:6): [True: 0, False: 522]
  ------------------
  748|      0|		return (-1);
  749|       |
  750|    522|	if (ikev2_print_id(&idb, idstr, sizeof(idstr)) == -1) {
  ------------------
  |  Branch (750:6): [True: 0, False: 522]
  ------------------
  751|      0|		ibuf_free(idb.id_buf);
  752|      0|		log_debug("%s: malformed id", __func__);
  753|      0|		return (-1);
  754|      0|	}
  755|       |
  756|    522|	log_debug("%s: id %s length %zu", __func__, idstr, len);
  757|       |
  758|    522|	if (!ikev2_msg_frompeer(msg)) {
  ------------------
  |  Branch (758:6): [True: 466, False: 56]
  ------------------
  759|    466|		ibuf_free(idb.id_buf);
  760|    466|		return (0);
  761|    466|	}
  762|       |
  763|     56|	if (((sa->sa_hdr.sh_initiator && payload == IKEV2_PAYLOAD_IDr) ||
  ------------------
  |  |   96|      0|#define IKEV2_PAYLOAD_IDr	36	/* Identification - Responder */
  ------------------
  |  Branch (763:8): [True: 0, False: 56]
  |  Branch (763:35): [True: 0, False: 0]
  ------------------
  764|     56|	    (!sa->sa_hdr.sh_initiator && payload == IKEV2_PAYLOAD_IDi)))
  ------------------
  |  |   95|     56|#define IKEV2_PAYLOAD_IDi	35	/* Identification - Initiator */
  ------------------
  |  Branch (764:7): [True: 56, False: 0]
  |  Branch (764:35): [True: 25, False: 31]
  ------------------
  765|     25|		idp = &msg->msg_parent->msg_peerid;
  766|     31|	else if (!sa->sa_hdr.sh_initiator && payload == IKEV2_PAYLOAD_IDr)
  ------------------
  |  |   96|     31|#define IKEV2_PAYLOAD_IDr	36	/* Identification - Responder */
  ------------------
  |  Branch (766:11): [True: 31, False: 0]
  |  Branch (766:39): [True: 31, False: 0]
  ------------------
  767|     31|		idp = &msg->msg_parent->msg_localid;
  768|      0|	else {
  769|      0|		ibuf_free(idb.id_buf);
  770|      0|		log_debug("%s: unexpected id payload", __func__);
  771|      0|		return (0);
  772|      0|	}
  773|       |
  774|     56|	if (idp->id_type) {
  ------------------
  |  Branch (774:6): [True: 11, False: 45]
  ------------------
  775|     11|		ibuf_free(idb.id_buf);
  776|     11|		log_debug("%s: duplicate id payload", __func__);
  777|     11|		return (-1);
  778|     11|	}
  779|       |
  780|     45|	idp->id_buf = idb.id_buf;
  781|     45|	idp->id_offset = idb.id_offset;
  782|     45|	idp->id_type = idb.id_type;
  783|       |
  784|     45|	return (0);
  785|     56|}
ikev2_validate_cert:
  790|  2.10k|{
  791|  2.10k|	uint8_t		*msgbuf = ibuf_data(msg->msg_data);
  792|       |
  793|  2.10k|	if (left < sizeof(*cert)) {
  ------------------
  |  Branch (793:6): [True: 335, False: 1.77k]
  ------------------
  794|    335|		log_debug("%s: malformed payload: too short for header "
  795|    335|		    "(%zu < %zu)", __func__, left, sizeof(*cert));
  796|    335|		return (-1);
  797|    335|	}
  798|  1.77k|	memcpy(cert, msgbuf + offset, sizeof(*cert));
  799|  1.77k|	if (cert->cert_type == IKEV2_CERT_NONE) {
  ------------------
  |  |  417|  1.77k|#define IKEV2_CERT_NONE			0	/* None */
  ------------------
  |  Branch (799:6): [True: 266, False: 1.50k]
  ------------------
  800|    266|		log_debug("%s: malformed payload: invalid cert type", __func__);
  801|    266|		return (-1);
  802|    266|	}
  803|       |
  804|  1.50k|	return (0);
  805|  1.77k|}
ikev2_pld_cert:
  810|  2.10k|{
  811|  2.10k|	struct ikev2_cert		 cert;
  812|  2.10k|	uint8_t				*buf;
  813|  2.10k|	size_t				 len;
  814|  2.10k|	struct iked_id			*certid;
  815|  2.10k|	uint8_t				*msgbuf = ibuf_data(msg->msg_data);
  816|  2.10k|	const struct iked_sa		*sa = msg->msg_sa;
  817|  2.10k|	int				 i;
  818|       |
  819|  2.10k|	if (ikev2_validate_cert(msg, offset, left, &cert))
  ------------------
  |  Branch (819:6): [True: 601, False: 1.50k]
  ------------------
  820|    601|		return (-1);
  821|  1.50k|	offset += sizeof(cert);
  822|       |
  823|  1.50k|	buf = msgbuf + offset;
  824|  1.50k|	len = left - sizeof(cert);
  825|       |
  826|  1.50k|	log_debug("%s: type %s length %zu",
  827|  1.50k|	    __func__, print_map(cert.cert_type, ikev2_cert_map), len);
  828|       |
  829|  1.50k|	print_hex(buf, 0, len);
  830|       |
  831|  1.50k|	if (!ikev2_msg_frompeer(msg))
  ------------------
  |  Branch (831:6): [True: 358, False: 1.14k]
  ------------------
  832|    358|		return (0);
  833|       |
  834|       |	/* do not accept internal encoding in the wire */
  835|  1.14k|	if (cert.cert_type == IKEV2_CERT_BUNDLE) {
  ------------------
  |  |  437|  1.14k|#define IKEV2_CERT_BUNDLE		254	/* Private */
  ------------------
  |  Branch (835:6): [True: 260, False: 887]
  ------------------
  836|    260|		log_debug("%s: ignoring IKEV2_CERT_BUNDLE",
  837|    260|		   SPI_SA(sa, __func__));
  ------------------
  |  | 1112|    260|#define SPI_SA(sa, f)    SPI_SH(&(sa)->sa_hdr, (f))
  |  |  ------------------
  |  |  |  | 1111|    260|#define SPI_SH(sh, f)    ikev2_ikesa_info((sh)->sh_ispi, (f))
  |  |  ------------------
  ------------------
  838|    260|		return (0);
  839|    260|	}
  840|       |
  841|    887|	certid = &msg->msg_parent->msg_cert;
  842|    887|	if (certid->id_type) {
  ------------------
  |  Branch (842:6): [True: 791, False: 96]
  ------------------
  843|       |		/* try to set supplemental certs */
  844|  2.79k|		for (i = 0; i < IKED_SCERT_MAX; i++) {
  ------------------
  |  |  476|  2.79k|#define IKED_SCERT_MAX	3 /* max # of supplemental cert payloads */
  ------------------
  |  Branch (844:15): [True: 2.17k, False: 618]
  ------------------
  845|  2.17k|			certid = &msg->msg_parent->msg_scert[i];
  846|  2.17k|			if (!certid->id_type)
  ------------------
  |  Branch (846:8): [True: 173, False: 2.00k]
  ------------------
  847|    173|				break;
  848|  2.17k|		}
  849|    791|		if (certid->id_type) {
  ------------------
  |  Branch (849:7): [True: 618, False: 173]
  ------------------
  850|    618|			log_debug("%s: too many cert payloads, ignoring",
  851|    618|			   SPI_SA(sa, __func__));
  ------------------
  |  | 1112|    618|#define SPI_SA(sa, f)    SPI_SH(&(sa)->sa_hdr, (f))
  |  |  ------------------
  |  |  |  | 1111|    618|#define SPI_SH(sh, f)    ikev2_ikesa_info((sh)->sh_ispi, (f))
  |  |  ------------------
  ------------------
  852|    618|			return (0);
  853|    618|		}
  854|    791|	}
  855|       |
  856|    269|	if ((certid->id_buf = ibuf_new(buf, len)) == NULL) {
  ------------------
  |  Branch (856:6): [True: 0, False: 269]
  ------------------
  857|      0|		log_debug("%s: failed to save cert", __func__);
  858|      0|		return (-1);
  859|      0|	}
  860|    269|	certid->id_type = cert.cert_type;
  861|    269|	certid->id_offset = 0;
  862|       |
  863|    269|	return (0);
  864|    269|}
ikev2_validate_certreq:
  869|  3.88k|{
  870|  3.88k|	uint8_t		*msgbuf = ibuf_data(msg->msg_data);
  871|       |
  872|  3.88k|	if (left < sizeof(*cert)) {
  ------------------
  |  Branch (872:6): [True: 572, False: 3.31k]
  ------------------
  873|    572|		log_debug("%s: malformed payload: too short for header "
  874|    572|		    "(%zu < %zu)", __func__, left, sizeof(*cert));
  875|    572|		return (-1);
  876|    572|	}
  877|  3.31k|	memcpy(cert, msgbuf + offset, sizeof(*cert));
  878|       |
  879|  3.31k|	return (0);
  880|  3.88k|}
ikev2_pld_certreq:
  885|  3.88k|{
  886|  3.88k|	struct ikev2_cert		 cert;
  887|  3.88k|	struct iked_certreq		*cr;
  888|  3.88k|	uint8_t				*buf;
  889|  3.88k|	ssize_t				 len;
  890|  3.88k|	uint8_t				*msgbuf = ibuf_data(msg->msg_data);
  891|       |
  892|  3.88k|	if (ikev2_validate_certreq(msg, offset, left, &cert))
  ------------------
  |  Branch (892:6): [True: 572, False: 3.31k]
  ------------------
  893|    572|		return (-1);
  894|  3.31k|	offset += sizeof(cert);
  895|       |
  896|  3.31k|	buf = msgbuf + offset;
  897|  3.31k|	len = left - sizeof(cert);
  898|       |
  899|  3.31k|	log_debug("%s: type %s length %zd",
  900|  3.31k|	    __func__, print_map(cert.cert_type, ikev2_cert_map), len);
  901|       |
  902|  3.31k|	print_hex(buf, 0, len);
  903|       |
  904|  3.31k|	if (!ikev2_msg_frompeer(msg))
  ------------------
  |  Branch (904:6): [True: 853, False: 2.45k]
  ------------------
  905|    853|		return (0);
  906|       |
  907|  2.45k|	if (cert.cert_type == IKEV2_CERT_X509_CERT) {
  ------------------
  |  |  421|  2.45k|#define IKEV2_CERT_X509_CERT		4	/* RFC7296 */
  ------------------
  |  Branch (907:6): [True: 473, False: 1.98k]
  ------------------
  908|    473|		if (len == 0) {
  ------------------
  |  Branch (908:7): [True: 266, False: 207]
  ------------------
  909|    266|			log_info("%s: invalid length 0", __func__);
  910|    266|			return (0);
  911|    266|		}
  912|    207|		if ((len % SHA_DIGEST_LENGTH) != 0) {
  ------------------
  |  Branch (912:7): [True: 6, False: 201]
  ------------------
  913|      6|			log_info("%s: invalid certificate request",
  914|      6|			    __func__);
  915|      6|			return (-1);
  916|      6|		}
  917|    207|	}
  918|       |
  919|  2.18k|	if ((cr = calloc(1, sizeof(struct iked_certreq))) == NULL) {
  ------------------
  |  Branch (919:6): [True: 0, False: 2.18k]
  ------------------
  920|      0|		log_info("%s: failed to allocate certreq.", __func__);
  921|      0|		return (-1);
  922|      0|	}
  923|  2.18k|	if ((cr->cr_data = ibuf_new(buf, len)) == NULL) {
  ------------------
  |  Branch (923:6): [True: 0, False: 2.18k]
  ------------------
  924|      0|		log_info("%s: failed to allocate buffer.", __func__);
  925|      0|		free(cr);
  926|      0|		return (-1);
  927|      0|	}
  928|  2.18k|	cr->cr_type = cert.cert_type;
  929|  2.18k|	SIMPLEQ_INSERT_TAIL(&msg->msg_parent->msg_certreqs, cr, cr_entry);
  ------------------
  |  |  296|  2.18k|#define SIMPLEQ_INSERT_TAIL(head, elm, field) do {			\
  |  |  297|  2.18k|	(elm)->field.sqe_next = NULL;					\
  |  |  298|  2.18k|	*(head)->sqh_last = (elm);					\
  |  |  299|  2.18k|	(head)->sqh_last = &(elm)->field.sqe_next;			\
  |  |  300|  2.18k|} while (0)
  |  |  ------------------
  |  |  |  Branch (300:10): [Folded, False: 2.18k]
  |  |  ------------------
  ------------------
  930|       |
  931|  2.18k|	return (0);
  932|  2.18k|}
ikev2_validate_auth:
  937|  1.00k|{
  938|  1.00k|	uint8_t		*msgbuf = ibuf_data(msg->msg_data);
  939|       |
  940|  1.00k|	if (left < sizeof(*auth)) {
  ------------------
  |  Branch (940:6): [True: 435, False: 572]
  ------------------
  941|    435|		log_debug("%s: malformed payload: too short for header "
  942|    435|		    "(%zu < %zu)", __func__, left, sizeof(*auth));
  943|    435|		return (-1);
  944|    435|	}
  945|    572|	memcpy(auth, msgbuf + offset, sizeof(*auth));
  946|       |
  947|    572|	if (auth->auth_method == 0) {
  ------------------
  |  Branch (947:6): [True: 243, False: 329]
  ------------------
  948|    243|		log_info("%s: malformed payload: invalid auth method",
  949|    243|		    __func__);
  950|    243|		return (-1);
  951|    243|	}
  952|       |
  953|    329|	return (0);
  954|    572|}
ikev2_pld_auth:
  959|  1.00k|{
  960|  1.00k|	struct ikev2_auth		 auth;
  961|  1.00k|	struct iked_id			*idp;
  962|  1.00k|	uint8_t				*buf;
  963|  1.00k|	size_t				 len;
  964|  1.00k|	uint8_t				*msgbuf = ibuf_data(msg->msg_data);
  965|       |
  966|  1.00k|	if (ikev2_validate_auth(msg, offset, left, &auth))
  ------------------
  |  Branch (966:6): [True: 678, False: 329]
  ------------------
  967|    678|		return (-1);
  968|    329|	offset += sizeof(auth);
  969|       |
  970|    329|	buf = msgbuf + offset;
  971|    329|	len = left - sizeof(auth);
  972|       |
  973|    329|	log_debug("%s: method %s length %zu",
  974|    329|	    __func__, print_map(auth.auth_method, ikev2_auth_map), len);
  975|       |
  976|    329|	print_hex(buf, 0, len);
  977|       |
  978|    329|	if (!ikev2_msg_frompeer(msg))
  ------------------
  |  Branch (978:6): [True: 302, False: 27]
  ------------------
  979|    302|		return (0);
  980|       |
  981|     27|	idp = &msg->msg_parent->msg_auth;
  982|     27|	if (idp->id_type) {
  ------------------
  |  Branch (982:6): [True: 8, False: 19]
  ------------------
  983|      8|		log_debug("%s: duplicate auth payload", __func__);
  984|      8|		return (-1);
  985|      8|	}
  986|       |
  987|     19|	ibuf_free(idp->id_buf);
  988|     19|	idp->id_type = auth.auth_method;
  989|     19|	idp->id_offset = 0;
  990|     19|	if ((idp->id_buf = ibuf_new(buf, len)) == NULL)
  ------------------
  |  Branch (990:6): [True: 0, False: 19]
  ------------------
  991|      0|		return (-1);
  992|       |
  993|     19|	return (0);
  994|     19|}
ikev2_pld_nonce:
  999|    940|{
 1000|    940|	size_t		 len;
 1001|    940|	uint8_t		*buf;
 1002|    940|	uint8_t		*msgbuf = ibuf_data(msg->msg_data);
 1003|       |
 1004|    940|	buf = msgbuf + offset;
 1005|    940|	len = left;
 1006|       |
 1007|    940|	if (len == 0) {
  ------------------
  |  Branch (1007:6): [True: 563, False: 377]
  ------------------
 1008|    563|		log_debug("%s: malformed payload: no NONCE given", __func__);
 1009|    563|		return (-1);
 1010|    563|	}
 1011|       |
 1012|    377|	print_hex(buf, 0, len);
 1013|       |
 1014|    377|	if (ikev2_msg_frompeer(msg)) {
  ------------------
  |  Branch (1014:6): [True: 19, False: 358]
  ------------------
 1015|     19|		if (msg->msg_parent->msg_nonce != NULL) {
  ------------------
  |  Branch (1015:7): [True: 3, False: 16]
  ------------------
 1016|      3|			log_info("%s: duplicate NONCE payload", __func__);
 1017|      3|			return (-1);
 1018|      3|		}
 1019|     16|		if ((msg->msg_nonce = ibuf_new(buf, len)) == NULL) {
  ------------------
  |  Branch (1019:7): [True: 0, False: 16]
  ------------------
 1020|      0|			log_debug("%s: failed to get peer nonce", __func__);
 1021|      0|			return (-1);
 1022|      0|		}
 1023|     16|		msg->msg_parent->msg_nonce = msg->msg_nonce;
 1024|     16|	}
 1025|       |
 1026|    374|	return (0);
 1027|    377|}
ikev2_validate_notify:
 1032|  7.76k|{
 1033|  7.76k|	uint8_t		*msgbuf = ibuf_data(msg->msg_data);
 1034|       |
 1035|  7.76k|	if (left < sizeof(*n)) {
  ------------------
  |  Branch (1035:6): [True: 521, False: 7.23k]
  ------------------
 1036|    521|		log_debug("%s: malformed payload: too short for header "
 1037|    521|		    "(%zu < %zu)", __func__, left, sizeof(*n));
 1038|    521|		return (-1);
 1039|    521|	}
 1040|  7.23k|	memcpy(n, msgbuf + offset, sizeof(*n));
 1041|       |
 1042|  7.23k|	return (0);
 1043|  7.76k|}
ikev2_pld_notify:
 1048|  7.76k|{
 1049|  7.76k|	struct ikev2_notify	 n;
 1050|  7.76k|	const struct iked_sa	*sa = msg->msg_sa;
 1051|  7.76k|	uint8_t			*buf, md[SHA_DIGEST_LENGTH];
 1052|  7.76k|	uint32_t		 spi32;
 1053|  7.76k|	uint64_t		 spi64;
 1054|  7.76k|	struct iked_spi		*rekey;
 1055|  7.76k|	uint16_t		 type;
 1056|  7.76k|	uint16_t		 signature_hash;
 1057|       |
 1058|  7.76k|	if (ikev2_validate_notify(msg, offset, left, &n))
  ------------------
  |  Branch (1058:6): [True: 521, False: 7.23k]
  ------------------
 1059|    521|		return (-1);
 1060|  7.23k|	type = betoh16(n.n_type);
 1061|       |
 1062|  7.23k|	log_debug("%s: protoid %s spisize %d type %s",
 1063|  7.23k|	    __func__,
 1064|  7.23k|	    print_map(n.n_protoid, ikev2_saproto_map), n.n_spisize,
 1065|  7.23k|	    print_map(type, ikev2_n_map));
 1066|       |
 1067|  7.23k|	left -= sizeof(n);
 1068|  7.23k|	if ((buf = ibuf_seek(msg->msg_data, offset + sizeof(n), left)) == NULL)
  ------------------
  |  Branch (1068:6): [True: 0, False: 7.23k]
  ------------------
 1069|      0|		return (-1);
 1070|       |
 1071|  7.23k|	print_hex(buf, 0, left);
 1072|       |
 1073|  7.23k|	if (!ikev2_msg_frompeer(msg))
  ------------------
  |  Branch (1073:6): [True: 358, False: 6.88k]
  ------------------
 1074|    358|		return (0);
 1075|       |
 1076|  6.88k|	switch (type) {
  ------------------
  |  Branch (1076:10): [True: 5.66k, False: 1.22k]
  ------------------
 1077|    232|	case IKEV2_N_NAT_DETECTION_SOURCE_IP:
  ------------------
  |  |  329|    232|#define IKEV2_N_NAT_DETECTION_SOURCE_IP		16388	/* RFC7296 */
  ------------------
  |  Branch (1077:2): [True: 232, False: 6.64k]
  ------------------
 1078|    632|	case IKEV2_N_NAT_DETECTION_DESTINATION_IP:
  ------------------
  |  |  330|    632|#define IKEV2_N_NAT_DETECTION_DESTINATION_IP	16389	/* RFC7296 */
  ------------------
  |  Branch (1078:2): [True: 400, False: 6.48k]
  ------------------
 1079|    632|		if (left != sizeof(md)) {
  ------------------
  |  Branch (1079:7): [True: 26, False: 606]
  ------------------
 1080|     26|			log_debug("%s: malformed payload: hash size mismatch"
 1081|     26|			    " (%zu != %zu)", __func__, left, sizeof(md));
 1082|     26|			return (-1);
 1083|     26|		}
 1084|    606|		if (ikev2_nat_detection(env, msg, md, sizeof(md), type,
  ------------------
  |  Branch (1084:7): [True: 0, False: 606]
  ------------------
 1085|    606|		    ikev2_msg_frompeer(msg)) == -1)
 1086|      0|			return (-1);
 1087|    606|		if (memcmp(buf, md, left) != 0) {
  ------------------
  |  Branch (1087:7): [True: 391, False: 215]
  ------------------
 1088|    391|			log_debug("%s: %s detected NAT", __func__,
 1089|    391|			    print_map(type, ikev2_n_map));
 1090|    391|			if (type == IKEV2_N_NAT_DETECTION_SOURCE_IP)
  ------------------
  |  |  329|    391|#define IKEV2_N_NAT_DETECTION_SOURCE_IP		16388	/* RFC7296 */
  ------------------
  |  Branch (1090:8): [True: 208, False: 183]
  ------------------
 1091|    208|				msg->msg_parent->msg_nat_detected
 1092|    208|				    |= IKED_MSG_NAT_SRC_IP;
  ------------------
  |  |  687|    208|#define IKED_MSG_NAT_SRC_IP				0x01
  ------------------
 1093|    183|			else
 1094|    183|				msg->msg_parent->msg_nat_detected
 1095|    183|				    |= IKED_MSG_NAT_DST_IP;
  ------------------
  |  |  688|    183|#define IKED_MSG_NAT_DST_IP				0x02
  ------------------
 1096|    391|		}
 1097|    606|		print_hex(md, 0, sizeof(md));
 1098|       |		/* remember for MOBIKE */
 1099|    606|		msg->msg_parent->msg_natt_rcvd = 1;
 1100|    606|		break;
 1101|      3|	case IKEV2_N_AUTHENTICATION_FAILED:
  ------------------
  |  |  313|      3|#define IKEV2_N_AUTHENTICATION_FAILED		24	/* RFC7296 */
  ------------------
  |  Branch (1101:2): [True: 3, False: 6.87k]
  ------------------
 1102|      3|		if (!msg->msg_e) {
  ------------------
  |  Branch (1102:7): [True: 2, False: 1]
  ------------------
 1103|      2|			log_debug("%s: AUTHENTICATION_FAILED not encrypted",
 1104|      2|			    __func__);
 1105|      2|			return (-1);
 1106|      2|		}
 1107|       |		/*
 1108|       |		 * If we are the responder, then we only accept
 1109|       |		 * AUTHENTICATION_FAILED from authenticated peers.
 1110|       |		 * If we are the initiator, the peer cannot be authenticated.
 1111|       |		 */
 1112|      1|		if (!sa->sa_hdr.sh_initiator) {
  ------------------
  |  Branch (1112:7): [True: 1, False: 0]
  ------------------
 1113|      1|			if (!sa_stateok(sa, IKEV2_STATE_VALID)) {
  ------------------
  |  |   41|      1|#define IKEV2_STATE_VALID		7	/* authenticated AND validated certs */
  ------------------
  |  Branch (1113:8): [True: 1, False: 0]
  ------------------
 1114|      1|				log_debug("%s: ignoring AUTHENTICATION_FAILED"
 1115|      1|				    " from unauthenticated initiator",
 1116|      1|				    __func__);
 1117|      1|				return (-1);
 1118|      1|			}
 1119|      1|		} else {
 1120|      0|			if (sa_stateok(sa, IKEV2_STATE_VALID)) {
  ------------------
  |  |   41|      0|#define IKEV2_STATE_VALID		7	/* authenticated AND validated certs */
  ------------------
  |  Branch (1120:8): [True: 0, False: 0]
  ------------------
 1121|      0|				log_debug("%s: ignoring AUTHENTICATION_FAILED"
 1122|      0|				    " from authenticated responder",
 1123|      0|				    __func__);
 1124|      0|				return (-1);
 1125|      0|			}
 1126|      0|		}
 1127|      0|		msg->msg_parent->msg_flags
 1128|      0|		    |= IKED_MSG_FLAGS_AUTHENTICATION_FAILED;
  ------------------
  |  |  695|      0|#define IKED_MSG_FLAGS_AUTHENTICATION_FAILED		0x0020
  ------------------
 1129|      0|		break;
 1130|    212|	case IKEV2_N_INVALID_KE_PAYLOAD:
  ------------------
  |  |  312|    212|#define IKEV2_N_INVALID_KE_PAYLOAD		17	/* RFC7296 */
  ------------------
  |  Branch (1130:2): [True: 212, False: 6.66k]
  ------------------
 1131|    212|		if (sa_stateok(sa, IKEV2_STATE_VALID) &&
  ------------------
  |  |   41|    212|#define IKEV2_STATE_VALID		7	/* authenticated AND validated certs */
  ------------------
  |  Branch (1131:7): [True: 0, False: 212]
  ------------------
 1132|      0|		    !msg->msg_e) {
  ------------------
  |  Branch (1132:7): [True: 0, False: 0]
  ------------------
 1133|      0|			log_debug("%s: INVALID_KE_PAYLOAD not encrypted",
 1134|      0|			    __func__);
 1135|      0|			return (-1);
 1136|      0|		}
 1137|    212|		if (left != sizeof(msg->msg_parent->msg_group)) {
  ------------------
  |  Branch (1137:7): [True: 15, False: 197]
  ------------------
 1138|     15|			log_debug("%s: malformed payload: group size mismatch"
 1139|     15|			    " (%zu != %zu)", __func__, left,
 1140|     15|			    sizeof(msg->msg_parent->msg_group));
 1141|     15|			return (-1);
 1142|     15|		}
 1143|    197|		memcpy(&msg->msg_parent->msg_group, buf, left);
 1144|    197|		msg->msg_parent->msg_flags |= IKED_MSG_FLAGS_INVALID_KE;
  ------------------
  |  |  696|    197|#define IKED_MSG_FLAGS_INVALID_KE			0x0040
  ------------------
 1145|    197|		break;
 1146|    309|	case IKEV2_N_NO_ADDITIONAL_SAS:
  ------------------
  |  |  315|    309|#define IKEV2_N_NO_ADDITIONAL_SAS		35	/* RFC7296 */
  ------------------
  |  Branch (1146:2): [True: 309, False: 6.57k]
  ------------------
 1147|    309|		if (!msg->msg_e) {
  ------------------
  |  Branch (1147:7): [True: 1, False: 308]
  ------------------
 1148|      1|			log_debug("%s: NO_ADDITIONAL_SAS not encrypted",
 1149|      1|			    __func__);
 1150|      1|			return (-1);
 1151|      1|		}
 1152|    308|		msg->msg_parent->msg_flags |= IKED_MSG_FLAGS_NO_ADDITIONAL_SAS;
  ------------------
  |  |  694|    308|#define IKED_MSG_FLAGS_NO_ADDITIONAL_SAS		0x0010
  ------------------
 1153|    308|		break;
 1154|    774|	case IKEV2_N_REKEY_SA:
  ------------------
  |  |  334|    774|#define IKEV2_N_REKEY_SA			16393	/* RFC7296 */
  ------------------
  |  Branch (1154:2): [True: 774, False: 6.10k]
  ------------------
 1155|    774|		if (!msg->msg_e) {
  ------------------
  |  Branch (1155:7): [True: 2, False: 772]
  ------------------
 1156|      2|			log_debug("%s: N_REKEY_SA not encrypted", __func__);
 1157|      2|			return (-1);
 1158|      2|		}
 1159|    772|		if (left != n.n_spisize) {
  ------------------
  |  Branch (1159:7): [True: 26, False: 746]
  ------------------
 1160|     26|			log_debug("%s: malformed notification", __func__);
 1161|     26|			return (-1);
 1162|     26|		}
 1163|    746|		rekey = &msg->msg_parent->msg_rekey;
 1164|    746|		if (rekey->spi != 0) {
  ------------------
  |  Branch (1164:7): [True: 102, False: 644]
  ------------------
 1165|    102|			log_debug("%s: rekeying of multiple SAs not supported",
 1166|    102|			    __func__);
 1167|    102|			return (-1);
 1168|    102|		}
 1169|    644|		switch (n.n_spisize) {
 1170|    243|		case 4:
  ------------------
  |  Branch (1170:3): [True: 243, False: 401]
  ------------------
 1171|    243|			memcpy(&spi32, buf, left);
 1172|    243|			rekey->spi = betoh32(spi32);
 1173|    243|			break;
 1174|    400|		case 8:
  ------------------
  |  Branch (1174:3): [True: 400, False: 244]
  ------------------
 1175|    400|			memcpy(&spi64, buf, left);
 1176|    400|			rekey->spi = betoh64(spi64);
 1177|    400|			break;
 1178|      1|		default:
  ------------------
  |  Branch (1178:3): [True: 1, False: 643]
  ------------------
 1179|      1|			log_debug("%s: invalid spi size %d", __func__,
 1180|      1|			    n.n_spisize);
 1181|      1|			return (-1);
 1182|    644|		}
 1183|    643|		rekey->spi_size = n.n_spisize;
 1184|    643|		rekey->spi_protoid = n.n_protoid;
 1185|       |
 1186|    643|		log_debug("%s: rekey %s spi %s", __func__,
 1187|    643|		    print_map(n.n_protoid, ikev2_saproto_map),
 1188|    643|		    print_spi(rekey->spi, n.n_spisize));
 1189|    643|		break;
 1190|    278|	case IKEV2_N_TEMPORARY_FAILURE:
  ------------------
  |  |  323|    278|#define IKEV2_N_TEMPORARY_FAILURE		43	/* RFC7296 */
  ------------------
  |  Branch (1190:2): [True: 278, False: 6.60k]
  ------------------
 1191|    278|		if (!msg->msg_e) {
  ------------------
  |  Branch (1191:7): [True: 3, False: 275]
  ------------------
 1192|      3|			log_debug("%s: IKEV2_N_TEMPORARY_FAILURE not encrypted",
 1193|      3|			    __func__);
 1194|      3|			return (-1);
 1195|      3|		}
 1196|    275|		msg->msg_parent->msg_flags |= IKED_MSG_FLAGS_TEMPORARY_FAILURE;
  ------------------
  |  |  699|    275|#define IKED_MSG_FLAGS_TEMPORARY_FAILURE		0x0200
  ------------------
 1197|    275|		break;
 1198|    450|	case IKEV2_N_IPCOMP_SUPPORTED:
  ------------------
  |  |  328|    450|#define IKEV2_N_IPCOMP_SUPPORTED		16387	/* RFC7296 */
  ------------------
  |  Branch (1198:2): [True: 450, False: 6.43k]
  ------------------
 1199|    450|		if (!msg->msg_e) {
  ------------------
  |  Branch (1199:7): [True: 1, False: 449]
  ------------------
 1200|      1|			log_debug("%s: N_IPCOMP_SUPPORTED not encrypted",
 1201|      1|			    __func__);
 1202|      1|			return (-1);
 1203|      1|		}
 1204|    449|		if (left < sizeof(msg->msg_parent->msg_cpi) +
  ------------------
  |  Branch (1204:7): [True: 213, False: 236]
  ------------------
 1205|    449|		    sizeof(msg->msg_parent->msg_transform)) {
 1206|    213|			log_debug("%s: ignoring malformed ipcomp notification",
 1207|    213|			    __func__);
 1208|    213|			return (0);
 1209|    213|		}
 1210|    236|		memcpy(&msg->msg_parent->msg_cpi, buf,
 1211|    236|		    sizeof(msg->msg_parent->msg_cpi));
 1212|    236|		memcpy(&msg->msg_parent->msg_transform,
 1213|    236|		    buf + sizeof(msg->msg_parent->msg_cpi),
 1214|    236|		    sizeof(msg->msg_parent->msg_transform));
 1215|       |
 1216|    236|		log_debug("%s: %s cpi 0x%x, transform %s, length %zu", __func__,
 1217|    236|		    msg->msg_parent->msg_response ? "res" : "req",
  ------------------
  |  Branch (1217:7): [True: 0, False: 236]
  ------------------
 1218|    236|		    betoh16(msg->msg_parent->msg_cpi),
 1219|    236|		    print_map(msg->msg_parent->msg_transform,
 1220|    236|		    ikev2_ipcomp_map), left);
 1221|       |
 1222|    236|		msg->msg_parent->msg_flags |= IKED_MSG_FLAGS_IPCOMP_SUPPORTED;
  ------------------
  |  |  697|    236|#define IKED_MSG_FLAGS_IPCOMP_SUPPORTED			0x0080
  ------------------
 1223|    236|		break;
 1224|    229|	case IKEV2_N_CHILD_SA_NOT_FOUND:
  ------------------
  |  |  324|    229|#define IKEV2_N_CHILD_SA_NOT_FOUND		44	/* RFC7296 */
  ------------------
  |  Branch (1224:2): [True: 229, False: 6.65k]
  ------------------
 1225|    229|		if (!msg->msg_e) {
  ------------------
  |  Branch (1225:7): [True: 1, False: 228]
  ------------------
 1226|      1|			log_debug("%s: N_CHILD_SA_NOT_FOUND not encrypted",
 1227|      1|			    __func__);
 1228|      1|			return (-1);
 1229|      1|		}
 1230|    228|		msg->msg_parent->msg_flags |= IKED_MSG_FLAGS_CHILD_SA_NOT_FOUND;
  ------------------
  |  |  693|    228|#define IKED_MSG_FLAGS_CHILD_SA_NOT_FOUND		0x0008
  ------------------
 1231|    228|		break;
 1232|    195|	case IKEV2_N_NO_PROPOSAL_CHOSEN:
  ------------------
  |  |  311|    195|#define IKEV2_N_NO_PROPOSAL_CHOSEN		14	/* RFC7296 */
  ------------------
  |  Branch (1232:2): [True: 195, False: 6.68k]
  ------------------
 1233|    195|		msg->msg_parent->msg_flags |= IKED_MSG_FLAGS_NO_PROPOSAL_CHOSEN;
  ------------------
  |  |  700|    195|#define IKED_MSG_FLAGS_NO_PROPOSAL_CHOSEN		0x0400
  ------------------
 1234|    195|		break;
 1235|    330|	case IKEV2_N_MOBIKE_SUPPORTED:
  ------------------
  |  |  337|    330|#define IKEV2_N_MOBIKE_SUPPORTED		16396	/* RFC4555 */
  ------------------
  |  Branch (1235:2): [True: 330, False: 6.55k]
  ------------------
 1236|    330|		if (!msg->msg_e) {
  ------------------
  |  Branch (1236:7): [True: 1, False: 329]
  ------------------
 1237|      1|			log_debug("%s: N_MOBIKE_SUPPORTED not encrypted",
 1238|      1|			    __func__);
 1239|      1|			return (-1);
 1240|      1|		}
 1241|    329|		if (left != 0) {
  ------------------
  |  Branch (1241:7): [True: 97, False: 232]
  ------------------
 1242|     97|			log_debug("%s: ignoring malformed mobike"
 1243|     97|			    " notification: %zu", __func__, left);
 1244|     97|			return (0);
 1245|     97|		}
 1246|    232|		msg->msg_parent->msg_flags |= IKED_MSG_FLAGS_MOBIKE;
  ------------------
  |  |  691|    232|#define IKED_MSG_FLAGS_MOBIKE				0x0002
  ------------------
 1247|    232|		break;
 1248|    362|	case IKEV2_N_USE_TRANSPORT_MODE:
  ------------------
  |  |  332|    362|#define IKEV2_N_USE_TRANSPORT_MODE		16391	/* RFC7296 */
  ------------------
  |  Branch (1248:2): [True: 362, False: 6.51k]
  ------------------
 1249|    362|		if (!msg->msg_e) {
  ------------------
  |  Branch (1249:7): [True: 1, False: 361]
  ------------------
 1250|      1|			log_debug("%s: N_USE_TRANSPORT_MODE not encrypted",
 1251|      1|			    __func__);
 1252|      1|			return (-1);
 1253|      1|		}
 1254|    361|		if (left != 0) {
  ------------------
  |  Branch (1254:7): [True: 215, False: 146]
  ------------------
 1255|    215|			log_debug("%s: ignoring malformed transport mode"
 1256|    215|			    " notification: %zu", __func__, left);
 1257|    215|			return (0);
 1258|    215|		}
 1259|    146|		if (msg->msg_parent->msg_response) {
  ------------------
  |  Branch (1259:7): [True: 0, False: 146]
  ------------------
 1260|      0|			if (!(msg->msg_policy->pol_flags & IKED_POLICY_TRANSPORT)) {
  ------------------
  |  |  264|      0|#define IKED_POLICY_TRANSPORT		 0x040
  ------------------
  |  Branch (1260:8): [True: 0, False: 0]
  ------------------
 1261|      0|				log_debug("%s: ignoring transport mode"
 1262|      0|				    " notification (policy)", __func__);
 1263|      0|				return (0);
 1264|      0|			}
 1265|      0|		}
 1266|    146|		msg->msg_parent->msg_flags |= IKED_MSG_FLAGS_USE_TRANSPORT;
  ------------------
  |  |  698|    146|#define IKED_MSG_FLAGS_USE_TRANSPORT			0x0100
  ------------------
 1267|    146|		break;
 1268|    219|	case IKEV2_N_UPDATE_SA_ADDRESSES:
  ------------------
  |  |  341|    219|#define IKEV2_N_UPDATE_SA_ADDRESSES		16400	/* RFC4555 */
  ------------------
  |  Branch (1268:2): [True: 219, False: 6.66k]
  ------------------
 1269|    219|		if (!msg->msg_e) {
  ------------------
  |  Branch (1269:7): [True: 1, False: 218]
  ------------------
 1270|      1|			log_debug("%s: N_UPDATE_SA_ADDRESSES not encrypted",
 1271|      1|			    __func__);
 1272|      1|			return (-1);
 1273|      1|		}
 1274|    218|		if (!sa->sa_mobike) {
  ------------------
  |  Branch (1274:7): [True: 218, False: 0]
  ------------------
 1275|    218|			log_debug("%s: ignoring update sa addresses"
 1276|    218|			    " notification w/o mobike: %zu", __func__, left);
 1277|    218|			return (0);
 1278|    218|		}
 1279|      0|		if (left != 0) {
  ------------------
  |  Branch (1279:7): [True: 0, False: 0]
  ------------------
 1280|      0|			log_debug("%s: ignoring malformed update sa addresses"
 1281|      0|			    " notification: %zu", __func__, left);
 1282|      0|			return (0);
 1283|      0|		}
 1284|      0|		msg->msg_parent->msg_update_sa_addresses = 1;
 1285|      0|		break;
 1286|    200|	case IKEV2_N_COOKIE2:
  ------------------
  |  |  342|    200|#define IKEV2_N_COOKIE2				16401	/* RFC4555 */
  ------------------
  |  Branch (1286:2): [True: 200, False: 6.68k]
  ------------------
 1287|    200|		if (!msg->msg_e) {
  ------------------
  |  Branch (1287:7): [True: 1, False: 199]
  ------------------
 1288|      1|			log_debug("%s: N_COOKIE2 not encrypted",
 1289|      1|			    __func__);
 1290|      1|			return (-1);
 1291|      1|		}
 1292|    199|		if (!sa->sa_mobike) {
  ------------------
  |  Branch (1292:7): [True: 199, False: 0]
  ------------------
 1293|    199|			log_debug("%s: ignoring cookie2 notification"
 1294|    199|			    " w/o mobike: %zu", __func__, left);
 1295|    199|			return (0);
 1296|    199|		}
 1297|      0|		if (left < IKED_COOKIE2_MIN || left > IKED_COOKIE2_MAX) {
  ------------------
  |  |   61|      0|#define IKED_COOKIE2_MIN	8	/* min 8 bytes */
  ------------------
              		if (left < IKED_COOKIE2_MIN || left > IKED_COOKIE2_MAX) {
  ------------------
  |  |   62|      0|#define IKED_COOKIE2_MAX	64	/* max 64 bytes */
  ------------------
  |  Branch (1297:7): [True: 0, False: 0]
  |  Branch (1297:34): [True: 0, False: 0]
  ------------------
 1298|      0|			log_debug("%s: ignoring malformed cookie2"
 1299|      0|			    " notification: %zu", __func__, left);
 1300|      0|			return (0);
 1301|      0|		}
 1302|      0|		ibuf_free(msg->msg_cookie2);	/* should not happen */
 1303|      0|		if ((msg->msg_cookie2 = ibuf_new(buf, left)) == NULL) {
  ------------------
  |  Branch (1303:7): [True: 0, False: 0]
  ------------------
 1304|      0|			log_debug("%s: failed to get peer cookie2", __func__);
 1305|      0|			return (-1);
 1306|      0|		}
 1307|      0|		msg->msg_parent->msg_cookie2 = msg->msg_cookie2;
 1308|      0|		break;
 1309|    458|	case IKEV2_N_COOKIE:
  ------------------
  |  |  331|    458|#define IKEV2_N_COOKIE				16390	/* RFC7296 */
  ------------------
  |  Branch (1309:2): [True: 458, False: 6.42k]
  ------------------
 1310|    458|		if (msg->msg_e) {
  ------------------
  |  Branch (1310:7): [True: 1, False: 457]
  ------------------
 1311|      1|			log_debug("%s: N_COOKIE encrypted",
 1312|      1|			    __func__);
 1313|      1|			return (-1);
 1314|      1|		}
 1315|    457|		if (left < IKED_COOKIE_MIN || left > IKED_COOKIE_MAX) {
  ------------------
  |  |   58|    914|#define IKED_COOKIE_MIN		1	/* min 1 bytes */
  ------------------
              		if (left < IKED_COOKIE_MIN || left > IKED_COOKIE_MAX) {
  ------------------
  |  |   59|    262|#define IKED_COOKIE_MAX		64	/* max 64 bytes */
  ------------------
  |  Branch (1315:7): [True: 195, False: 262]
  |  Branch (1315:33): [True: 44, False: 218]
  ------------------
 1316|    239|			log_debug("%s: ignoring malformed cookie"
 1317|    239|			    " notification: %zu", __func__, left);
 1318|    239|			return (0);
 1319|    239|		}
 1320|    218|		log_debug("%s: received cookie, len %zu", __func__, left);
 1321|    218|		print_hex(buf, 0, left);
 1322|       |
 1323|    218|		ibuf_free(msg->msg_cookie);
 1324|    218|		if ((msg->msg_cookie = ibuf_new(buf, left)) == NULL) {
  ------------------
  |  Branch (1324:7): [True: 0, False: 218]
  ------------------
 1325|      0|			log_debug("%s: failed to get peer cookie", __func__);
 1326|      0|			return (-1);
 1327|      0|		}
 1328|    218|		msg->msg_parent->msg_cookie = msg->msg_cookie;
 1329|    218|		break;
 1330|    571|	case IKEV2_N_FRAGMENTATION_SUPPORTED:
  ------------------
  |  |  370|    571|#define IKEV2_N_FRAGMENTATION_SUPPORTED		16430	/* RFC7383 */
  ------------------
  |  Branch (1330:2): [True: 571, False: 6.31k]
  ------------------
 1331|    571|		if (msg->msg_e) {
  ------------------
  |  Branch (1331:7): [True: 1, False: 570]
  ------------------
 1332|      1|			log_debug("%s: N_FRAGMENTATION_SUPPORTED encrypted",
 1333|      1|			    __func__);
 1334|      1|			return (-1);
 1335|      1|		}
 1336|    570|		if (left != 0) {
  ------------------
  |  Branch (1336:7): [True: 140, False: 430]
  ------------------
 1337|    140|			log_debug("%s: ignoring malformed fragmentation"
 1338|    140|			    " notification: %zu", __func__, left);
 1339|    140|			return (0);
 1340|    140|		}
 1341|    430|		msg->msg_parent->msg_flags |= IKED_MSG_FLAGS_FRAGMENTATION;
  ------------------
  |  |  690|    430|#define IKED_MSG_FLAGS_FRAGMENTATION			0x0001
  ------------------
 1342|    430|		break;
 1343|    439|	case IKEV2_N_SIGNATURE_HASH_ALGORITHMS:
  ------------------
  |  |  371|    439|#define IKEV2_N_SIGNATURE_HASH_ALGORITHMS	16431	/* RFC7427 */
  ------------------
  |  Branch (1343:2): [True: 439, False: 6.44k]
  ------------------
 1344|    439|		if (msg->msg_e) {
  ------------------
  |  Branch (1344:7): [True: 1, False: 438]
  ------------------
 1345|      1|			log_debug("%s: SIGNATURE_HASH_ALGORITHMS: encrypted",
 1346|      1|			    __func__);
 1347|      1|			return (-1);
 1348|      1|		}
 1349|    438|		if (sa == NULL) {
  ------------------
  |  Branch (1349:7): [True: 0, False: 438]
  ------------------
 1350|      0|			log_debug("%s: SIGNATURE_HASH_ALGORITHMS: no SA",
 1351|      0|			    __func__);
 1352|      0|			return (-1);
 1353|      0|		}
 1354|    438|		if (sa->sa_sigsha2) {
  ------------------
  |  Branch (1354:7): [True: 0, False: 438]
  ------------------
 1355|      0|			log_debug("%s: SIGNATURE_HASH_ALGORITHMS: "
 1356|      0|			    "duplicate notify", __func__);
 1357|      0|			return (0);
 1358|      0|		}
 1359|    438|		if (left < sizeof(signature_hash) ||
  ------------------
  |  Branch (1359:7): [True: 220, False: 218]
  ------------------
 1360|    292|		    left % sizeof(signature_hash)) {
  ------------------
  |  Branch (1360:7): [True: 72, False: 146]
  ------------------
 1361|    292|			log_debug("%s: malformed signature hash notification"
 1362|    292|			    "(%zu bytes)", __func__, left);
 1363|    292|			return (0);
 1364|    292|		}
 1365|  2.59k|		while (left >= sizeof(signature_hash)) {
  ------------------
  |  Branch (1365:10): [True: 2.44k, False: 146]
  ------------------
 1366|  2.44k|			memcpy(&signature_hash, buf, sizeof(signature_hash));
 1367|  2.44k|			signature_hash = betoh16(signature_hash);
 1368|  2.44k|			log_debug("%s: signature hash %s (%x)", __func__,
 1369|  2.44k|			    print_map(signature_hash, ikev2_sighash_map),
 1370|  2.44k|			    signature_hash);
 1371|  2.44k|			left -= sizeof(signature_hash);
 1372|  2.44k|			buf += sizeof(signature_hash);
 1373|  2.44k|			if (signature_hash == IKEV2_SIGHASH_SHA2_256)
  ------------------
  |  |  498|  2.44k|#define IKEV2_SIGHASH_SHA2_256		2	/* RFC7427 */
  ------------------
  |  Branch (1373:8): [True: 210, False: 2.23k]
  ------------------
 1374|    210|				msg->msg_parent->msg_flags
 1375|    210|				    |= IKED_MSG_FLAGS_SIGSHA2;
  ------------------
  |  |  692|    210|#define IKED_MSG_FLAGS_SIGSHA2				0x0004
  ------------------
 1376|  2.44k|		}
 1377|    146|		break;
 1378|  6.88k|	}
 1379|       |
 1380|  5.08k|	return (0);
 1381|  6.88k|}
ikev2_validate_delete:
 1386|  3.85k|{
 1387|  3.85k|	uint8_t		*msgbuf = ibuf_data(msg->msg_data);
 1388|       |
 1389|  3.85k|	if (left < sizeof(*del)) {
  ------------------
  |  Branch (1389:6): [True: 913, False: 2.94k]
  ------------------
 1390|    913|		log_debug("%s: malformed payload: too short for header "
 1391|    913|		    "(%zu < %zu)", __func__, left, sizeof(*del));
 1392|    913|		return (-1);
 1393|    913|	}
 1394|  2.94k|	memcpy(del, msgbuf + offset, sizeof(*del));
 1395|       |
 1396|  2.94k|	if (del->del_protoid == 0) {
  ------------------
  |  Branch (1396:6): [True: 267, False: 2.67k]
  ------------------
 1397|    267|		log_info("%s: malformed payload: invalid protoid", __func__);
 1398|    267|		return (-1);
 1399|    267|	}
 1400|       |
 1401|  2.67k|	return (0);
 1402|  2.94k|}
ikev2_pld_delete:
 1407|  3.85k|{
 1408|  3.85k|	struct ikev2_delete	 del;
 1409|  3.85k|	uint8_t			*buf, *msgbuf = ibuf_data(msg->msg_data);
 1410|  3.85k|	size_t			 cnt, sz, len;
 1411|       |
 1412|  3.85k|	if (ikev2_validate_delete(msg, offset, left, &del))
  ------------------
  |  Branch (1412:6): [True: 1.18k, False: 2.67k]
  ------------------
 1413|  1.18k|		return (-1);
 1414|       |
 1415|       |	/* Skip if it's a response, then we don't have to deal with it */
 1416|  2.67k|	if (ikev2_msg_frompeer(msg) &&
  ------------------
  |  Branch (1416:6): [True: 330, False: 2.34k]
  ------------------
 1417|    330|	    msg->msg_parent->msg_response)
  ------------------
  |  Branch (1417:6): [True: 0, False: 330]
  ------------------
 1418|      0|		return (0);
 1419|       |
 1420|  2.67k|	cnt = betoh16(del.del_nspi);
 1421|  2.67k|	sz = del.del_spisize;
 1422|  2.67k|	len = left - sizeof(del);
 1423|       |
 1424|  2.67k|	switch (del.del_protoid) {
 1425|  1.23k|	case IKEV2_SAPROTO_IKE:
  ------------------
  |  |  134|  1.23k|#define IKEV2_SAPROTO_IKE		1	/* IKEv2 */
  ------------------
  |  Branch (1425:2): [True: 1.23k, False: 1.44k]
  ------------------
 1426|  1.23k|		if (sz != 0 || cnt != 0 || len != 0) {
  ------------------
  |  Branch (1426:7): [True: 251, False: 981]
  |  Branch (1426:18): [True: 283, False: 698]
  |  Branch (1426:30): [True: 125, False: 573]
  ------------------
 1427|    659|			log_debug("%s: malformed IKE delete", __func__);
 1428|    659|			return (-1);
 1429|    659|		}
 1430|    573|		break;
 1431|    573|	case IKEV2_SAPROTO_AH:
  ------------------
  |  |  135|    467|#define IKEV2_SAPROTO_AH		2	/* AH */
  ------------------
  |  Branch (1431:2): [True: 467, False: 2.20k]
  ------------------
 1432|  1.06k|	case IKEV2_SAPROTO_ESP:
  ------------------
  |  |  136|  1.06k|#define IKEV2_SAPROTO_ESP		3	/* ESP */
  ------------------
  |  Branch (1432:2): [True: 593, False: 2.08k]
  ------------------
 1433|  1.06k|		if (sz != 4 || cnt == 0 || len != sz * cnt) {
  ------------------
  |  Branch (1433:7): [True: 553, False: 507]
  |  Branch (1433:18): [True: 73, False: 434]
  |  Branch (1433:30): [True: 350, False: 84]
  ------------------
 1434|    976|			log_debug("%s: malformed AH/ESP delete", __func__);
 1435|    976|			return (-1);
 1436|    976|		}
 1437|     84|		break;
 1438|    381|	default:
  ------------------
  |  Branch (1438:2): [True: 381, False: 2.29k]
  ------------------
 1439|    381|		log_debug("%s: unsupported protoid %d for delete", __func__,
 1440|    381|		    del.del_protoid);
 1441|    381|		return (-1);
 1442|  2.67k|	}
 1443|       |
 1444|    657|	log_debug("%s: proto %s spisize %zu nspi %zu",
 1445|    657|	    __func__, print_map(del.del_protoid, ikev2_saproto_map),
 1446|    657|	    sz, cnt);
 1447|       |
 1448|    657|	if (msg->msg_parent->msg_del_protoid) {
  ------------------
  |  Branch (1448:6): [True: 620, False: 37]
  ------------------
 1449|    620|		log_debug("%s: duplicate delete payload", __func__);
 1450|    620|		return (0);
 1451|    620|	}
 1452|       |
 1453|     37|	msg->msg_parent->msg_del_protoid = del.del_protoid;
 1454|     37|	msg->msg_parent->msg_del_cnt = cnt;
 1455|     37|	msg->msg_parent->msg_del_spisize = sz;
 1456|       |
 1457|     37|	if (del.del_protoid == IKEV2_SAPROTO_IKE)
  ------------------
  |  |  134|     37|#define IKEV2_SAPROTO_IKE		1	/* IKEv2 */
  ------------------
  |  Branch (1457:6): [True: 23, False: 14]
  ------------------
 1458|     23|		return (0);
 1459|       |
 1460|     14|	buf = msgbuf + offset + sizeof(del);
 1461|       |
 1462|     14|	print_hex(buf, 0, len);
 1463|       |
 1464|     14|	msg->msg_parent->msg_del_buf = ibuf_new(buf, len);
 1465|       |
 1466|     14|	return (0);
 1467|     37|}
ikev2_validate_tss:
 1472|  3.21k|{
 1473|  3.21k|	uint8_t		*msgbuf = ibuf_data(msg->msg_data);
 1474|       |
 1475|  3.21k|	if (left < sizeof(*tsp)) {
  ------------------
  |  Branch (1475:6): [True: 784, False: 2.43k]
  ------------------
 1476|    784|		log_debug("%s: malformed payload: too short for header "
 1477|    784|		    "(%zu < %zu)", __func__, left, sizeof(*tsp));
 1478|    784|		return (-1);
 1479|    784|	}
 1480|  2.43k|	memcpy(tsp, msgbuf + offset, sizeof(*tsp));
 1481|       |
 1482|  2.43k|	return (0);
 1483|  3.21k|}
ikev2_pld_tss:
 1488|  3.21k|{
 1489|  3.21k|	struct ikev2_tsp		 tsp;
 1490|  3.21k|	struct ikev2_ts			 ts;
 1491|  3.21k|	size_t				 ts_len, i;
 1492|       |
 1493|  3.21k|	if (ikev2_validate_tss(msg, offset, left, &tsp))
  ------------------
  |  Branch (1493:6): [True: 784, False: 2.43k]
  ------------------
 1494|    784|		return (-1);
 1495|       |
 1496|  2.43k|	offset += sizeof(tsp);
 1497|  2.43k|	left -= sizeof(tsp);
 1498|       |
 1499|  2.43k|	log_debug("%s: count %d length %zu", __func__,
 1500|  2.43k|	    tsp.tsp_count, left);
 1501|       |
 1502|  3.36k|	for (i = 0; i < tsp.tsp_count; i++) {
  ------------------
  |  Branch (1502:14): [True: 2.83k, False: 533]
  ------------------
 1503|  2.83k|		if (ikev2_validate_ts(msg, offset, left, &ts))
  ------------------
  |  Branch (1503:7): [True: 1.43k, False: 1.40k]
  ------------------
 1504|  1.43k|			return (-1);
 1505|       |
 1506|  1.40k|		log_debug("%s: type %s protoid %u length %d "
 1507|  1.40k|		    "startport %u endport %u", __func__,
 1508|  1.40k|		    print_map(ts.ts_type, ikev2_ts_map),
 1509|  1.40k|		    ts.ts_protoid, betoh16(ts.ts_length),
 1510|  1.40k|		    betoh16(ts.ts_startport),
 1511|  1.40k|		    betoh16(ts.ts_endport));
 1512|       |
 1513|  1.40k|		offset += sizeof(ts);
 1514|  1.40k|		left -= sizeof(ts);
 1515|       |
 1516|  1.40k|		ts_len = betoh16(ts.ts_length) - sizeof(ts);
 1517|  1.40k|		if (ikev2_pld_ts(env, pld, msg, offset, ts_len, ts.ts_type))
  ------------------
  |  Branch (1517:7): [True: 467, False: 933]
  ------------------
 1518|    467|			return (-1);
 1519|       |
 1520|    933|		offset += ts_len;
 1521|    933|		left -= ts_len;
 1522|    933|	}
 1523|       |
 1524|    533|	return (0);
 1525|  2.43k|}
ikev2_validate_ts:
 1530|  2.83k|{
 1531|  2.83k|	uint8_t		*msgbuf = ibuf_data(msg->msg_data);
 1532|  2.83k|	size_t		 ts_length;
 1533|       |
 1534|  2.83k|	if (left < sizeof(*ts)) {
  ------------------
  |  Branch (1534:6): [True: 767, False: 2.06k]
  ------------------
 1535|    767|		log_debug("%s: malformed payload: too short for header "
 1536|    767|		    "(%zu < %zu)", __func__, left, sizeof(*ts));
 1537|    767|		return (-1);
 1538|    767|	}
 1539|  2.06k|	memcpy(ts, msgbuf + offset, sizeof(*ts));
 1540|       |
 1541|  2.06k|	ts_length = betoh16(ts->ts_length);
 1542|  2.06k|	if (ts_length < sizeof(*ts)) {
  ------------------
  |  Branch (1542:6): [True: 252, False: 1.81k]
  ------------------
 1543|    252|		log_debug("%s: malformed payload: shorter than minimum header "
 1544|    252|		    "size (%zu < %zu)", __func__, ts_length, sizeof(*ts));
 1545|    252|		return (-1);
 1546|    252|	}
 1547|  1.81k|	if (left < ts_length) {
  ------------------
  |  Branch (1547:6): [True: 413, False: 1.40k]
  ------------------
 1548|    413|		log_debug("%s: malformed payload: too long for payload size "
 1549|    413|		    "(%zu < %zu)", __func__, left, ts_length);
 1550|    413|		return (-1);
 1551|    413|	}
 1552|       |
 1553|  1.40k|	return (0);
 1554|  1.81k|}
ikev2_pld_ts:
 1559|  1.40k|{
 1560|  1.40k|	struct sockaddr_in		 start4, end4;
 1561|  1.40k|	struct sockaddr_in6		 start6, end6;
 1562|  1.40k|	uint8_t				*msgbuf = ibuf_data(msg->msg_data);
 1563|  1.40k|	uint8_t				*ptr;
 1564|       |
 1565|  1.40k|	ptr = msgbuf + offset;
 1566|       |
 1567|  1.40k|	switch (type) {
 1568|    861|	case IKEV2_TS_IPV4_ADDR_RANGE:
  ------------------
  |  |  459|    861|#define IKEV2_TS_IPV4_ADDR_RANGE	7	/* RFC7296 */
  ------------------
  |  Branch (1568:2): [True: 861, False: 539]
  ------------------
 1569|    861|		if (left < 2 * 4) {
  ------------------
  |  Branch (1569:7): [True: 266, False: 595]
  ------------------
 1570|    266|			log_debug("%s: malformed payload: too short "
 1571|    266|			    "for ipv4 addr range (%zu < %u)",
 1572|    266|			    __func__, left, 2 * 4);
 1573|    266|			return (-1);
 1574|    266|		}
 1575|       |
 1576|    595|		bzero(&start4, sizeof(start4));
 1577|    595|		start4.sin_family = AF_INET;
 1578|       |#ifdef HAVE_SOCKADDR_SA_LEN
 1579|       |		start4.sin_len = sizeof(start4);
 1580|       |#endif
 1581|    595|		memcpy(&start4.sin_addr.s_addr, ptr, 4);
 1582|    595|		ptr += 4;
 1583|    595|		left -= 4;
 1584|       |
 1585|    595|		bzero(&end4, sizeof(end4));
 1586|    595|		end4.sin_family = AF_INET;
 1587|       |#ifdef HAVE_SOCKADDR_SA_LEN
 1588|       |		end4.sin_len = sizeof(end4);
 1589|       |#endif
 1590|    595|		memcpy(&end4.sin_addr.s_addr, ptr, 4);
 1591|    595|		left -= 4;
 1592|       |
 1593|    595|		log_debug("%s: start %s end %s", __func__,
 1594|    595|		    print_addr(&start4), print_addr(&end4));
 1595|    595|		break;
 1596|    186|	case IKEV2_TS_IPV6_ADDR_RANGE:
  ------------------
  |  |  460|    186|#define IKEV2_TS_IPV6_ADDR_RANGE	8	/* RFC7296 */
  ------------------
  |  Branch (1596:2): [True: 186, False: 1.21k]
  ------------------
 1597|    186|		if (left < 2 * 16) {
  ------------------
  |  Branch (1597:7): [True: 103, False: 83]
  ------------------
 1598|    103|			log_debug("%s: malformed payload: too short "
 1599|    103|			    "for ipv6 addr range (%zu < %u)",
 1600|    103|			    __func__, left, 2 * 16);
 1601|    103|			return (-1);
 1602|    103|		}
 1603|     83|		bzero(&start6, sizeof(start6));
 1604|     83|		start6.sin6_family = AF_INET6;
 1605|       |#ifdef HAVE_SOCKADDR_SA_LEN
 1606|       |		start6.sin6_len = sizeof(start6);
 1607|       |#endif
 1608|     83|		memcpy(&start6.sin6_addr, ptr, 16);
 1609|     83|		ptr += 16;
 1610|     83|		left -= 16;
 1611|       |
 1612|     83|		bzero(&end6, sizeof(end6));
 1613|     83|		end6.sin6_family = AF_INET6;
 1614|       |#ifdef HAVE_SOCKADDR_SA_LEN
 1615|       |		end6.sin6_len = sizeof(end6);
 1616|       |#endif
 1617|     83|		memcpy(&end6.sin6_addr, ptr, 16);
 1618|     83|		left -= 16;
 1619|       |
 1620|     83|		log_debug("%s: start %s end %s", __func__,
 1621|     83|		    print_addr(&start6), print_addr(&end6));
 1622|     83|		break;
 1623|    353|	default:
  ------------------
  |  Branch (1623:2): [True: 353, False: 1.04k]
  ------------------
 1624|    353|		log_debug("%s: ignoring unknown TS type %u", __func__, type);
 1625|    353|		return (0);
 1626|  1.40k|	}
 1627|       |
 1628|    678|	if (left > 0) {
  ------------------
  |  Branch (1628:6): [True: 98, False: 580]
  ------------------
 1629|     98|		log_debug("%s: malformed payload: left (%zu) > 0",
 1630|     98|		    __func__, left);
 1631|     98|		return (-1);
 1632|     98|	}
 1633|       |
 1634|    580|	return (0);
 1635|    678|}
ikev2_validate_ef:
 1640|    112|{
 1641|    112|	uint8_t		*msgbuf = ibuf_data(msg->msg_data);
 1642|       |
 1643|    112|	if (left < sizeof(*frag)) {
  ------------------
  |  Branch (1643:6): [True: 4, False: 108]
  ------------------
 1644|      4|		log_debug("%s: malformed payload: too short for header "
 1645|      4|		    "(%zu < %zu)", __func__, left, sizeof(*frag));
 1646|      4|		return (-1);
 1647|      4|	}
 1648|    108|	memcpy(frag, msgbuf + offset, sizeof(*frag));
 1649|       |
 1650|    108|	return (0);
 1651|    112|}
ikev2_pld_ef:
 1656|    112|{
 1657|    112|	struct iked_sa			*sa = msg->msg_sa;
 1658|    112|	struct iked_frag		*sa_frag = &sa->sa_fragments;
 1659|    112|	struct iked_frag_entry		*el;
 1660|    112|	struct ikev2_frag_payload	 frag;
 1661|    112|	uint8_t				*msgbuf = ibuf_data(msg->msg_data);
 1662|    112|	uint8_t				*buf;
 1663|    112|	struct ibuf			*e = NULL;
 1664|    112|	size_t				 frag_num, frag_total;
 1665|    112|	size_t				 len;
 1666|    112|	int				 ret = -1;
 1667|    112|	int				 processed = 0;
 1668|    112|	ssize_t				 elen;
 1669|       |
 1670|    112|	if (ikev2_validate_ef(msg, offset, left, &frag) != 0)
  ------------------
  |  Branch (1670:6): [True: 4, False: 108]
  ------------------
 1671|      4|		return (-1);
 1672|       |
 1673|    108|	frag_num = betoh16(frag.frag_num);
 1674|    108|	frag_total = betoh16(frag.frag_total);
 1675|       |
 1676|    108|	offset += sizeof(frag);
 1677|    108|	buf = msgbuf + offset;
 1678|    108|	len = left - sizeof(frag);
 1679|       |
 1680|    108|	ikestat_inc(env, ikes_frag_rcvd);
  ------------------
  |  |  579|    108|#define ikestat_inc(env, c)	ikestat_add(env, c, 1)
  |  |  ------------------
  |  |  |  |  578|    108|#define ikestat_add(env, c, n)	do { env->sc_stats.c += (n); } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (578:69): [Folded, False: 108]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1681|       |
 1682|       |	/* Limit number of total fragments to avoid DOS */
 1683|    108|	if (frag_total > IKED_FRAG_TOTAL_MAX ) {
  ------------------
  |  |  398|    108|#define IKED_FRAG_TOTAL_MAX	  111		/* upper limit (64kB / 576B) */
  ------------------
  |  Branch (1683:6): [True: 14, False: 94]
  ------------------
 1684|     14|		log_debug("%s: Total Fragments too big  %zu",
 1685|     14|		    __func__, frag_total);
 1686|     14|		goto dropall;
 1687|     14|	}
 1688|       |
 1689|       |	/* Check sanity of fragment header */
 1690|     94|	if (frag_num == 0 || frag_total == 0) {
  ------------------
  |  Branch (1690:6): [True: 2, False: 92]
  |  Branch (1690:23): [True: 22, False: 70]
  ------------------
 1691|     24|		log_debug("%s: Malformed fragment received: %zu of %zu",
 1692|     24|		    __func__, frag_num, frag_total);
 1693|     24|		goto done;
 1694|     24|	}
 1695|     70|	log_debug("%s: Received fragment: %zu of %zu",
 1696|     70|	    __func__, frag_num, frag_total);
 1697|       |
 1698|       |	/* Drop fragment if frag_num and frag_total don't match */
 1699|     70|	if (frag_num > frag_total)
  ------------------
  |  Branch (1699:6): [True: 34, False: 36]
  ------------------
 1700|     34|		goto done;
 1701|       |
 1702|       |	/* Decrypt fragment */
 1703|     36|	if ((e = ibuf_new(buf, len)) == NULL)
  ------------------
  |  Branch (1703:6): [True: 0, False: 36]
  ------------------
 1704|      0|		goto done;
 1705|       |
 1706|     36|	if ((e = ikev2_msg_decrypt(env, msg->msg_sa, msg->msg_data, e))
  ------------------
  |  Branch (1706:6): [True: 0, False: 36]
  ------------------
 1707|     36|	    == NULL ) {
 1708|      0|		log_debug("%s: Failed to decrypt fragment: %zu of %zu",
 1709|      0|		    __func__, frag_num, frag_total);
 1710|      0|		goto done;
 1711|      0|	}
 1712|     36|	elen = ibuf_size(e);
 1713|       |
 1714|       |	/* Check new fragmented message */
 1715|     36|	if (sa_frag->frag_arr == NULL) {
  ------------------
  |  Branch (1715:6): [True: 36, False: 0]
  ------------------
 1716|     36|		sa_frag->frag_arr = recallocarray(NULL, 0, frag_total,
 1717|     36|		    sizeof(struct iked_frag_entry*));
 1718|     36|		if (sa_frag->frag_arr == NULL) {
  ------------------
  |  Branch (1718:7): [True: 0, False: 36]
  ------------------
 1719|      0|			log_info("%s: recallocarray sa_frag->frag_arr.", __func__);
 1720|      0|			goto done;
 1721|      0|		}
 1722|     36|		sa_frag->frag_total = frag_total;
 1723|     36|	} else {
 1724|       |		/* Drop all fragments if frag_total doesn't match previous */
 1725|      0|		if (frag_total != sa_frag->frag_total)
  ------------------
  |  Branch (1725:7): [True: 0, False: 0]
  ------------------
 1726|      0|			goto dropall;
 1727|       |
 1728|       |		/* Silent drop if fragment already stored */
 1729|      0|		if (sa_frag->frag_arr[frag_num-1] != NULL)
  ------------------
  |  Branch (1729:7): [True: 0, False: 0]
  ------------------
 1730|      0|			goto done;
 1731|      0|	}
 1732|       |
 1733|       |	/* The first fragments IKE header determines pld_nextpayload */
 1734|     36|	if (frag_num == 1)
  ------------------
  |  Branch (1734:6): [True: 24, False: 12]
  ------------------
 1735|     24|		sa_frag->frag_nextpayload = pld->pld_nextpayload;
 1736|       |
 1737|       |	/* Insert new list element */
 1738|     36|	el = calloc(1, sizeof(struct iked_frag_entry));
 1739|     36|	if (el == NULL) {
  ------------------
  |  Branch (1739:6): [True: 0, False: 36]
  ------------------
 1740|      0|		log_info("%s: Failed allocating new fragment: %zu of %zu",
 1741|      0|		    __func__, frag_num, frag_total);
 1742|      0|		goto done;
 1743|      0|	}
 1744|       |
 1745|     36|	sa_frag->frag_arr[frag_num-1] = el;
 1746|     36|	el->frag_size = elen;
 1747|     36|	el->frag_data = calloc(1, elen);
 1748|     36|	if (el->frag_data == NULL) {
  ------------------
  |  Branch (1748:6): [True: 0, False: 36]
  ------------------
 1749|      0|		log_debug("%s: Failed allocating new fragment data: %zu of %zu",
 1750|      0|		    __func__, frag_num, frag_total);
 1751|      0|		goto done;
 1752|      0|	}
 1753|       |
 1754|       |	/* Copy plaintext to fragment */
 1755|     36|	memcpy(el->frag_data, ibuf_seek(e, 0, 0), elen);
 1756|     36|	sa_frag->frag_total_size += elen;
 1757|     36|	sa_frag->frag_count++;
 1758|       |
 1759|       |	/* If all frags are received start reassembly */
 1760|     36|	if (sa_frag->frag_count == sa_frag->frag_total) {
  ------------------
  |  Branch (1760:6): [True: 23, False: 13]
  ------------------
 1761|     23|		log_debug("%s: All fragments received: %zu of %zu",
 1762|     23|		    __func__, frag_num, frag_total);
 1763|     23|		ret = ikev2_frags_reassemble(env, pld, msg);
 1764|     23|	} else {
 1765|     13|		ret = 0;
 1766|     13|	}
 1767|     36|	processed = 1;
 1768|       |
 1769|     94|done:
 1770|     94|	if (!processed)
  ------------------
  |  Branch (1770:6): [True: 58, False: 36]
  ------------------
 1771|     94|		ikestat_inc(env, ikes_frag_rcvd_drop);
  ------------------
  |  |  579|     58|#define ikestat_inc(env, c)	ikestat_add(env, c, 1)
  |  |  ------------------
  |  |  |  |  578|     58|#define ikestat_add(env, c, n)	do { env->sc_stats.c += (n); } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (578:69): [Folded, False: 58]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1772|     94|	ibuf_free(e);
 1773|     94|	return (ret);
 1774|     14|dropall:
 1775|     14|	ikestat_add(env, ikes_frag_rcvd_drop, sa_frag->frag_count + 1);
  ------------------
  |  |  578|     14|#define ikestat_add(env, c, n)	do { env->sc_stats.c += (n); } while(0)
  |  |  ------------------
  |  |  |  Branch (578:69): [Folded, False: 14]
  |  |  ------------------
  ------------------
 1776|     14|	config_free_fragments(sa_frag);
 1777|     14|	ibuf_free(e);
 1778|     14|	return -1;
 1779|     36|}
ikev2_frags_reassemble:
 1784|     23|{
 1785|     23|	struct iked_frag		*sa_frag = &msg->msg_sa->sa_fragments;
 1786|     23|	struct ibuf			*e = NULL;
 1787|     23|	struct iked_frag_entry		*el;
 1788|     23|	uint8_t				*ptr;
 1789|     23|	size_t				 offset;
 1790|     23|	size_t				 i;
 1791|     23|	struct iked_message		 emsg;
 1792|     23|	int				 ret = -1;
 1793|     23|	int				 processed = 0;
 1794|       |
 1795|       |	/* Reassemble fragments to single buffer */
 1796|     23|	if ((e = ibuf_new(NULL, sa_frag->frag_total_size)) == NULL) {
  ------------------
  |  Branch (1796:6): [True: 0, False: 23]
  ------------------
 1797|      0|		log_debug("%s: Failed allocating SK buffer.", __func__);
 1798|      0|		goto done;
 1799|      0|	}
 1800|       |
 1801|       |	/* Empty queue to new buffer */
 1802|     23|	offset = 0;
 1803|     44|	for (i = 0; i < sa_frag->frag_total; i++) {
  ------------------
  |  Branch (1803:14): [True: 23, False: 21]
  ------------------
 1804|     23|		if ((el = sa_frag->frag_arr[i]) == NULL)
  ------------------
  |  Branch (1804:7): [True: 0, False: 23]
  ------------------
 1805|      0|			fatalx("Tried to reassemble shallow frag_arr");
 1806|     23|		ptr = ibuf_seek(e, offset, el->frag_size);
 1807|     23|		if (ptr == NULL) {
  ------------------
  |  Branch (1807:7): [True: 2, False: 21]
  ------------------
 1808|      2|			log_info("%s: failed to reassemble fragments", __func__);
 1809|      2|			goto done;
 1810|      2|		}
 1811|     21|		memcpy(ptr, el->frag_data, el->frag_size);
 1812|     21|		offset += el->frag_size;
 1813|     21|	}
 1814|       |
 1815|     21|	log_debug("%s: Defragmented length %zd", __func__,
 1816|     21|	    sa_frag->frag_total_size);
 1817|     21|	print_hex(ibuf_data(e), 0,  sa_frag->frag_total_size);
 1818|       |
 1819|       |	/* Drop the original request's packets from the retransmit queue */
 1820|     21|	if (msg->msg_response)
  ------------------
  |  Branch (1820:6): [True: 0, False: 21]
  ------------------
 1821|      0|		ikev2_msg_flushqueue(env, &msg->msg_sa->sa_requests);
 1822|       |
 1823|       |	/*
 1824|       |	 * Parse decrypted payload
 1825|       |	 */
 1826|     21|	bzero(&emsg, sizeof(emsg));
 1827|     21|	memcpy(&emsg, msg, sizeof(*msg));
 1828|     21|	emsg.msg_data = e;
 1829|     21|	emsg.msg_e = 1;
 1830|     21|	emsg.msg_parent = msg;
 1831|     21|	TAILQ_INIT(&emsg.msg_proposals);
  ------------------
  |  |  465|     21|#define	TAILQ_INIT(head) do {						\
  |  |  466|     21|	(head)->tqh_first = NULL;					\
  |  |  467|     21|	(head)->tqh_last = &(head)->tqh_first;				\
  |  |  468|     21|} while (0)
  |  |  ------------------
  |  |  |  Branch (468:10): [Folded, False: 21]
  |  |  ------------------
  ------------------
 1832|       |
 1833|     21|	ret = ikev2_pld_payloads(env, &emsg, 0, ibuf_size(e),
 1834|     21|	    sa_frag->frag_nextpayload);
 1835|     21|	processed = 1;
 1836|     23|done:
 1837|     23|	if (processed)
  ------------------
  |  Branch (1837:6): [True: 21, False: 2]
  ------------------
 1838|     21|		ikestat_add(env, ikes_frag_reass_ok, sa_frag->frag_total);
  ------------------
  |  |  578|     21|#define ikestat_add(env, c, n)	do { env->sc_stats.c += (n); } while(0)
  |  |  ------------------
  |  |  |  Branch (578:69): [Folded, False: 21]
  |  |  ------------------
  ------------------
 1839|      2|	else
 1840|      2|		ikestat_add(env, ikes_frag_reass_drop, sa_frag->frag_total);
  ------------------
  |  |  578|      2|#define ikestat_add(env, c, n)	do { env->sc_stats.c += (n); } while(0)
  |  |  ------------------
  |  |  |  Branch (578:69): [Folded, False: 2]
  |  |  ------------------
  ------------------
 1841|     23|	config_free_fragments(sa_frag);
 1842|     23|	ibuf_free(e);
 1843|       |
 1844|     23|	return (ret);
 1845|     21|}
ikev2_pld_e:
 1850|  1.24k|{
 1851|  1.24k|	struct iked_sa		*sa = msg->msg_sa;
 1852|  1.24k|	struct ibuf		*e = NULL;
 1853|  1.24k|	uint8_t			*msgbuf = ibuf_data(msg->msg_data);
 1854|  1.24k|	struct iked_message	 emsg;
 1855|  1.24k|	uint8_t			*buf;
 1856|  1.24k|	size_t			 len;
 1857|  1.24k|	int			 ret = -1;
 1858|       |
 1859|  1.24k|	if (sa->sa_fragments.frag_arr != NULL) {
  ------------------
  |  Branch (1859:6): [True: 0, False: 1.24k]
  ------------------
 1860|      0|		log_warn("%s: Received SK payload when SKFs are in queue.",
 1861|      0|		    __func__);
 1862|      0|		config_free_fragments(&sa->sa_fragments);
 1863|      0|		return (ret);
 1864|      0|	}
 1865|       |
 1866|  1.24k|	buf = msgbuf + offset;
 1867|  1.24k|	len = left;
 1868|       |
 1869|  1.24k|	if ((e = ibuf_new(buf, len)) == NULL)
  ------------------
  |  Branch (1869:6): [True: 0, False: 1.24k]
  ------------------
 1870|      0|		goto done;
 1871|       |
 1872|  1.24k|	if (ikev2_msg_frompeer(msg)) {
  ------------------
  |  Branch (1872:6): [True: 645, False: 597]
  ------------------
 1873|    645|		e = ikev2_msg_decrypt(env, msg->msg_sa, msg->msg_data, e);
 1874|    645|	} else {
 1875|    597|		sa->sa_hdr.sh_initiator = sa->sa_hdr.sh_initiator ? 0 : 1;
  ------------------
  |  Branch (1875:29): [True: 0, False: 597]
  ------------------
 1876|    597|		e = ikev2_msg_decrypt(env, msg->msg_sa, msg->msg_data, e);
 1877|    597|		sa->sa_hdr.sh_initiator = sa->sa_hdr.sh_initiator ? 0 : 1;
  ------------------
  |  Branch (1877:29): [True: 597, False: 0]
  ------------------
 1878|    597|	}
 1879|       |
 1880|  1.24k|	if (e == NULL)
  ------------------
  |  Branch (1880:6): [True: 0, False: 1.24k]
  ------------------
 1881|      0|		goto done;
 1882|       |
 1883|       |	/*
 1884|       |	 * Parse decrypted payload
 1885|       |	 */
 1886|  1.24k|	bzero(&emsg, sizeof(emsg));
 1887|  1.24k|	memcpy(&emsg, msg, sizeof(*msg));
 1888|  1.24k|	emsg.msg_data = e;
 1889|  1.24k|	emsg.msg_e = 1;
 1890|  1.24k|	emsg.msg_parent = msg;
 1891|  1.24k|	TAILQ_INIT(&emsg.msg_proposals);
  ------------------
  |  |  465|  1.24k|#define	TAILQ_INIT(head) do {						\
  |  |  466|  1.24k|	(head)->tqh_first = NULL;					\
  |  |  467|  1.24k|	(head)->tqh_last = &(head)->tqh_first;				\
  |  |  468|  1.24k|} while (0)
  |  |  ------------------
  |  |  |  Branch (468:10): [Folded, False: 1.24k]
  |  |  ------------------
  ------------------
 1892|       |
 1893|  1.24k|	ret = ikev2_pld_payloads(env, &emsg, 0, ibuf_size(e),
 1894|  1.24k|	    pld->pld_nextpayload);
 1895|       |
 1896|  1.24k| done:
 1897|  1.24k|	ibuf_free(e);
 1898|       |
 1899|  1.24k|	return (ret);
 1900|  1.24k|}
ikev2_validate_cp:
 1905|  1.92k|{
 1906|  1.92k|	uint8_t		*msgbuf = ibuf_data(msg->msg_data);
 1907|       |
 1908|  1.92k|	if (left < sizeof(*cp)) {
  ------------------
  |  Branch (1908:6): [True: 440, False: 1.48k]
  ------------------
 1909|    440|		log_debug("%s: malformed payload: too short for header "
 1910|    440|		    "(%zu < %zu)", __func__, left, sizeof(*cp));
 1911|    440|		return (-1);
 1912|    440|	}
 1913|  1.48k|	memcpy(cp, msgbuf + offset, sizeof(*cp));
 1914|       |
 1915|  1.48k|	return (0);
 1916|  1.92k|}
ikev2_pld_cp:
 1921|  1.92k|{
 1922|  1.92k|	struct ikev2_cp		 cp;
 1923|  1.92k|	struct ikev2_cfg	*cfg;
 1924|  1.92k|	struct iked_addr	*addr;
 1925|  1.92k|	struct sockaddr_in	*in4;
 1926|  1.92k|	struct sockaddr_in6	*in6;
 1927|  1.92k|	uint8_t			*msgbuf = ibuf_data(msg->msg_data);
 1928|  1.92k|	uint8_t			*ptr;
 1929|  1.92k|	size_t			 len;
 1930|  1.92k|	int			 cfg_type;
 1931|       |
 1932|  1.92k|	if (ikev2_validate_cp(msg, offset, left, &cp))
  ------------------
  |  Branch (1932:6): [True: 440, False: 1.48k]
  ------------------
 1933|    440|		return (-1);
 1934|       |
 1935|  1.48k|	ptr = msgbuf + offset + sizeof(cp);
 1936|  1.48k|	len = left - sizeof(cp);
 1937|       |
 1938|  1.48k|	log_debug("%s: type %s length %zu",
 1939|  1.48k|	    __func__, print_map(cp.cp_type, ikev2_cp_map), len);
 1940|  1.48k|	print_hex(ptr, 0, len);
 1941|       |
 1942|  5.29k|	while (len > 0) {
  ------------------
  |  Branch (1942:9): [True: 4.38k, False: 911]
  ------------------
 1943|  4.38k|		if (len < sizeof(*cfg)) {
  ------------------
  |  Branch (1943:7): [True: 259, False: 4.12k]
  ------------------
 1944|    259|			log_debug("%s: malformed payload: too short for cfg "
 1945|    259|			    "(%zu < %zu)", __func__, len, sizeof(*cfg));
 1946|    259|			return (-1);
 1947|    259|		}
 1948|  4.12k|		cfg = (struct ikev2_cfg *)ptr;
 1949|       |
 1950|  4.12k|		log_debug("%s: %s 0x%04x length %d", __func__,
 1951|  4.12k|		    print_map(betoh16(cfg->cfg_type), ikev2_cfg_map),
 1952|  4.12k|		    betoh16(cfg->cfg_type),
 1953|  4.12k|		    betoh16(cfg->cfg_length));
 1954|       |
 1955|  4.12k|		ptr += sizeof(*cfg);
 1956|  4.12k|		len -= sizeof(*cfg);
 1957|       |
 1958|  4.12k|		if (len < betoh16(cfg->cfg_length)) {
  ------------------
  |  Branch (1958:7): [True: 300, False: 3.82k]
  ------------------
 1959|    300|			log_debug("%s: malformed payload: too short for "
 1960|    300|			    "cfg_length (%zu < %u)", __func__, len,
 1961|    300|			    betoh16(cfg->cfg_length));
 1962|    300|			return (-1);
 1963|    300|		}
 1964|       |
 1965|  3.82k|		print_hex(ptr, sizeof(*cfg), betoh16(cfg->cfg_length));
 1966|       |
 1967|  3.82k|		cfg_type = betoh16(cfg->cfg_type);
 1968|  3.82k|		switch (cfg_type) {
  ------------------
  |  Branch (1968:11): [True: 2.28k, False: 1.53k]
  ------------------
 1969|    652|		case IKEV2_CFG_INTERNAL_IP4_ADDRESS:
  ------------------
  |  |  527|    652|#define IKEV2_CFG_INTERNAL_IP4_ADDRESS		1	/* RFC7296 */
  ------------------
  |  Branch (1969:3): [True: 652, False: 3.17k]
  ------------------
 1970|  1.28k|		case IKEV2_CFG_INTERNAL_IP4_DNS:
  ------------------
  |  |  529|  1.28k|#define IKEV2_CFG_INTERNAL_IP4_DNS		3	/* RFC7296 */
  ------------------
  |  Branch (1970:3): [True: 637, False: 3.18k]
  ------------------
 1971|  1.28k|			if (!ikev2_msg_frompeer(msg))
  ------------------
  |  Branch (1971:8): [True: 566, False: 723]
  ------------------
 1972|    566|				break;
 1973|    723|			if (betoh16(cfg->cfg_length) == 0)
  ------------------
  |  Branch (1973:8): [True: 482, False: 241]
  ------------------
 1974|    482|				break;
 1975|       |			/* XXX multiple-valued */
 1976|    241|			if (betoh16(cfg->cfg_length) < 4) {
  ------------------
  |  Branch (1976:8): [True: 5, False: 236]
  ------------------
 1977|      5|				log_debug("%s: malformed payload: too short "
 1978|      5|				    "for ipv4 addr (%u < %u)",
 1979|      5|				    __func__, betoh16(cfg->cfg_length), 4);
 1980|      5|				return (-1);
 1981|      5|			}
 1982|    236|			switch(cfg_type) {
 1983|    137|			case IKEV2_CFG_INTERNAL_IP4_ADDRESS:
  ------------------
  |  |  527|    137|#define IKEV2_CFG_INTERNAL_IP4_ADDRESS		1	/* RFC7296 */
  ------------------
  |  Branch (1983:4): [True: 137, False: 99]
  ------------------
 1984|    137|				if (msg->msg_parent->msg_cp_addr != NULL) {
  ------------------
  |  Branch (1984:9): [True: 103, False: 34]
  ------------------
 1985|    103|					log_debug("%s: address already set", __func__);
 1986|    103|					goto skip;
 1987|    103|				}
 1988|     34|				break;
 1989|     99|			case IKEV2_CFG_INTERNAL_IP4_DNS:
  ------------------
  |  |  529|     99|#define IKEV2_CFG_INTERNAL_IP4_DNS		3	/* RFC7296 */
  ------------------
  |  Branch (1989:4): [True: 99, False: 137]
  ------------------
 1990|     99|				if (msg->msg_parent->msg_cp_dns != NULL) {
  ------------------
  |  Branch (1990:9): [True: 77, False: 22]
  ------------------
 1991|     77|					log_debug("%s: dns already set", __func__);
 1992|     77|					goto skip;
 1993|     77|				}
 1994|     22|				break;
 1995|     22|			default:
  ------------------
  |  Branch (1995:4): [True: 0, False: 236]
  ------------------
 1996|      0|				break;
 1997|    236|			}
 1998|     56|			if ((addr = calloc(1, sizeof(*addr))) == NULL) {
  ------------------
  |  Branch (1998:8): [True: 0, False: 56]
  ------------------
 1999|      0|				log_debug("%s: malloc failed", __func__);
 2000|      0|				break;
 2001|      0|			}
 2002|     56|			addr->addr_af = AF_INET;
 2003|     56|			in4 = (struct sockaddr_in *)&addr->addr;
 2004|     56|			in4->sin_family = AF_INET;
 2005|       |#ifdef HAVE_SOCKADDR_SA_LEN
 2006|       |			in4->sin_len = sizeof(*in4);
 2007|       |#endif
 2008|     56|			memcpy(&in4->sin_addr.s_addr, ptr, 4);
 2009|     56|			switch(cfg_type) {
 2010|     34|			case IKEV2_CFG_INTERNAL_IP4_ADDRESS:
  ------------------
  |  |  527|     34|#define IKEV2_CFG_INTERNAL_IP4_ADDRESS		1	/* RFC7296 */
  ------------------
  |  Branch (2010:4): [True: 34, False: 22]
  ------------------
 2011|     34|				msg->msg_parent->msg_cp_addr = addr;
 2012|     34|				log_debug("%s: IP4_ADDRESS %s", __func__,
 2013|     34|				    print_addr(&addr->addr));
 2014|     34|				break;
 2015|     22|			case IKEV2_CFG_INTERNAL_IP4_DNS:
  ------------------
  |  |  529|     22|#define IKEV2_CFG_INTERNAL_IP4_DNS		3	/* RFC7296 */
  ------------------
  |  Branch (2015:4): [True: 22, False: 34]
  ------------------
 2016|     22|				msg->msg_parent->msg_cp_dns = addr;
 2017|     22|				log_debug("%s: IP4_DNS %s", __func__,
 2018|     22|				    print_addr(&addr->addr));
 2019|     22|				break;
 2020|      0|			default:
  ------------------
  |  Branch (2020:4): [True: 0, False: 56]
  ------------------
 2021|      0|				log_debug("%s: cfg %s", __func__,
 2022|      0|				    print_addr(&addr->addr));
 2023|      0|				break;
 2024|     56|			}
 2025|     56|			break;
 2026|    511|		case IKEV2_CFG_INTERNAL_IP6_ADDRESS:
  ------------------
  |  |  534|    511|#define IKEV2_CFG_INTERNAL_IP6_ADDRESS		8	/* RFC7296 */
  ------------------
  |  Branch (2026:3): [True: 511, False: 3.31k]
  ------------------
 2027|    996|		case IKEV2_CFG_INTERNAL_IP6_DNS:
  ------------------
  |  |  535|    996|#define IKEV2_CFG_INTERNAL_IP6_DNS		10	/* RFC7296 */
  ------------------
  |  Branch (2027:3): [True: 485, False: 3.33k]
  ------------------
 2028|    996|			if (!ikev2_msg_frompeer(msg))
  ------------------
  |  Branch (2028:8): [True: 268, False: 728]
  ------------------
 2029|    268|				break;
 2030|    728|			if (betoh16(cfg->cfg_length) == 0)
  ------------------
  |  Branch (2030:8): [True: 416, False: 312]
  ------------------
 2031|    416|				break;
 2032|       |			/* XXX multiple-valued */
 2033|    312|			if (betoh16(cfg->cfg_length) < 16) {
  ------------------
  |  Branch (2033:8): [True: 5, False: 307]
  ------------------
 2034|      5|				log_debug("%s: malformed payload: too short "
 2035|      5|				    "for ipv6 addr w/prefixlen (%u < %u)",
 2036|      5|				    __func__, betoh16(cfg->cfg_length), 16);
 2037|      5|				return (-1);
 2038|      5|			}
 2039|    307|			switch(cfg_type) {
  ------------------
  |  Branch (2039:11): [True: 307, False: 0]
  ------------------
 2040|    217|			case IKEV2_CFG_INTERNAL_IP6_ADDRESS:
  ------------------
  |  |  534|    217|#define IKEV2_CFG_INTERNAL_IP6_ADDRESS		8	/* RFC7296 */
  ------------------
  |  Branch (2040:4): [True: 217, False: 90]
  ------------------
 2041|    217|				if (msg->msg_parent->msg_cp_addr6 != NULL) {
  ------------------
  |  Branch (2041:9): [True: 195, False: 22]
  ------------------
 2042|    195|					log_debug("%s: address6 already set", __func__);
 2043|    195|					goto skip;
 2044|    195|				}
 2045|     22|				break;
 2046|     90|			case IKEV2_CFG_INTERNAL_IP6_DNS:
  ------------------
  |  |  535|     90|#define IKEV2_CFG_INTERNAL_IP6_DNS		10	/* RFC7296 */
  ------------------
  |  Branch (2046:4): [True: 90, False: 217]
  ------------------
 2047|     90|				if (msg->msg_parent->msg_cp_dns != NULL) {
  ------------------
  |  Branch (2047:9): [True: 76, False: 14]
  ------------------
 2048|     76|					log_debug("%s: dns already set", __func__);
 2049|     76|					goto skip;
 2050|     76|				}
 2051|     14|				break;
 2052|    307|			}
 2053|     36|			if ((addr = calloc(1, sizeof(*addr))) == NULL) {
  ------------------
  |  Branch (2053:8): [True: 0, False: 36]
  ------------------
 2054|      0|				log_debug("%s: malloc failed", __func__);
 2055|      0|				break;
 2056|      0|			}
 2057|     36|			addr->addr_af = AF_INET6;
 2058|     36|			in6 = (struct sockaddr_in6 *)&addr->addr;
 2059|     36|			in6->sin6_family = AF_INET6;
 2060|       |#ifdef HAVE_SOCKADDR_SA_LEN
 2061|       |			in6->sin6_len = sizeof(*in6);
 2062|       |#endif
 2063|     36|			memcpy(&in6->sin6_addr, ptr, 16);
 2064|     36|			switch(cfg_type) {
 2065|     22|			case IKEV2_CFG_INTERNAL_IP6_ADDRESS:
  ------------------
  |  |  534|     22|#define IKEV2_CFG_INTERNAL_IP6_ADDRESS		8	/* RFC7296 */
  ------------------
  |  Branch (2065:4): [True: 22, False: 14]
  ------------------
 2066|     22|				msg->msg_parent->msg_cp_addr6 = addr;
 2067|     22|				log_debug("%s: IP6_ADDRESS %s", __func__,
 2068|     22|				    print_addr(&addr->addr));
 2069|     22|				break;
 2070|     14|			case IKEV2_CFG_INTERNAL_IP6_DNS:
  ------------------
  |  |  535|     14|#define IKEV2_CFG_INTERNAL_IP6_DNS		10	/* RFC7296 */
  ------------------
  |  Branch (2070:4): [True: 14, False: 22]
  ------------------
 2071|     14|				msg->msg_parent->msg_cp_dns = addr;
 2072|     14|				log_debug("%s: IP6_DNS %s", __func__,
 2073|     14|				    print_addr(&addr->addr));
 2074|     14|				break;
 2075|      0|			default:
  ------------------
  |  Branch (2075:4): [True: 0, False: 36]
  ------------------
 2076|      0|				log_debug("%s: cfg %s/%d", __func__,
 2077|      0|				    print_addr(&addr->addr), ptr[16]);
 2078|      0|				break;
 2079|     36|			}
 2080|     36|			break;
 2081|  3.82k|		}
 2082|       |
 2083|  3.81k| skip:
 2084|  3.81k|		ptr += betoh16(cfg->cfg_length);
 2085|  3.81k|		len -= betoh16(cfg->cfg_length);
 2086|  3.81k|	}
 2087|       |
 2088|    911|	if (!ikev2_msg_frompeer(msg))
  ------------------
  |  Branch (2088:6): [True: 446, False: 465]
  ------------------
 2089|    446|		return (0);
 2090|       |
 2091|    465|	msg->msg_parent->msg_cp = cp.cp_type;
 2092|       |
 2093|    465|	return (0);
 2094|    911|}
ikev2_validate_eap:
 2099|  2.15k|{
 2100|  2.15k|	uint8_t		*msgbuf = ibuf_data(msg->msg_data);
 2101|       |
 2102|  2.15k|	if (left < sizeof(*hdr)) {
  ------------------
  |  Branch (2102:6): [True: 1.03k, False: 1.12k]
  ------------------
 2103|  1.03k|		log_debug("%s: malformed payload: too short for header "
 2104|  1.03k|		    "(%zu < %zu)", __func__, left, sizeof(*hdr));
 2105|  1.03k|		return (-1);
 2106|  1.03k|	}
 2107|  1.12k|	memcpy(hdr, msgbuf + offset, sizeof(*hdr));
 2108|       |
 2109|  1.12k|	return (0);
 2110|  2.15k|}
ikev2_pld_eap:
 2115|  2.15k|{
 2116|  2.15k|	struct eap_header		 hdr;
 2117|  2.15k|	struct eap_message		*eap = NULL;
 2118|  2.15k|	const struct iked_sa		*sa = msg->msg_sa;
 2119|  2.15k|	size_t				 eap_len;
 2120|       |
 2121|  2.15k|	if (ikev2_validate_eap(msg, offset, left, &hdr))
  ------------------
  |  Branch (2121:6): [True: 1.03k, False: 1.12k]
  ------------------
 2122|  1.03k|		return (-1);
 2123|       |
 2124|  1.12k|	eap_len = betoh16(hdr.eap_length);
 2125|  1.12k|	if (left != eap_len) {
  ------------------
  |  Branch (2125:6): [True: 508, False: 613]
  ------------------
 2126|    508|		log_info("%s: malformed payload: EAP length does not match"
 2127|    508|		    " payload length (%zu != %zu)", __func__, left, eap_len);
 2128|    508|		return (-1);
 2129|    508|	}
 2130|       |
 2131|    613|	if (eap_len < sizeof(*eap)) {
  ------------------
  |  Branch (2131:6): [True: 266, False: 347]
  ------------------
 2132|    266|		log_info("%s: %s id %d length %d", SPI_SA(sa, __func__),
  ------------------
  |  | 1112|    266|#define SPI_SA(sa, f)    SPI_SH(&(sa)->sa_hdr, (f))
  |  |  ------------------
  |  |  |  | 1111|    266|#define SPI_SH(sh, f)    ikev2_ikesa_info((sh)->sh_ispi, (f))
  |  |  ------------------
  ------------------
 2133|    266|		    print_map(hdr.eap_code, eap_code_map),
 2134|    266|		    hdr.eap_id, betoh16(hdr.eap_length));
 2135|    347|	} else {
 2136|       |		/* Now try to get the indicated length */
 2137|    347|		if ((eap = ibuf_seek(msg->msg_data, offset, eap_len)) == NULL) {
  ------------------
  |  Branch (2137:7): [True: 0, False: 347]
  ------------------
 2138|      0|			log_debug("%s: invalid EAP length", __func__);
 2139|      0|			return (-1);
 2140|      0|		}
 2141|       |
 2142|    347|		log_info("%s: %s id %d length %d EAP-%s", SPI_SA(sa, __func__),
  ------------------
  |  | 1112|    347|#define SPI_SA(sa, f)    SPI_SH(&(sa)->sa_hdr, (f))
  |  |  ------------------
  |  |  |  | 1111|    347|#define SPI_SH(sh, f)    ikev2_ikesa_info((sh)->sh_ispi, (f))
  |  |  ------------------
  ------------------
 2143|    347|		    print_map(eap->eap_code, eap_code_map),
 2144|    347|		    eap->eap_id, betoh16(eap->eap_length),
 2145|    347|		    print_map(eap->eap_type, eap_type_map));
 2146|       |
 2147|    347|		if (eap_parse(env, sa, msg, eap, msg->msg_response) == -1)
  ------------------
  |  Branch (2147:7): [True: 0, False: 347]
  ------------------
 2148|      0|			return (-1);
 2149|    347|		msg->msg_parent->msg_eap.eam_found = 1;
 2150|    347|	}
 2151|       |
 2152|    613|	return (0);
 2153|    613|}

ibuf_new:
   41|  7.14k|{
   42|  7.14k|	struct ibuf	*buf;
   43|       |
   44|  7.14k|	if ((buf = ibuf_dynamic(len,
  ------------------
  |  Branch (44:6): [True: 0, False: 7.14k]
  ------------------
   45|  7.14k|	    IKED_MSGBUF_MAX)) == NULL)
  ------------------
  |  |   66|  7.14k|#define IKED_MSGBUF_MAX		8192
  ------------------
   46|      0|		return (NULL);
   47|       |
   48|  7.14k|	if (len == 0)
  ------------------
  |  Branch (48:6): [True: 2.03k, False: 5.10k]
  ------------------
   49|  2.03k|		return (buf);
   50|       |
   51|  5.10k|	if (data == NULL) {
  ------------------
  |  Branch (51:6): [True: 21, False: 5.08k]
  ------------------
   52|     21|		if (ibuf_add_zero(buf, len) != 0) {
  ------------------
  |  Branch (52:7): [True: 0, False: 21]
  ------------------
   53|      0|			ibuf_free(buf);
   54|      0|			return (NULL);
   55|      0|		}
   56|  5.08k|	} else {
   57|  5.08k|		if (ibuf_add(buf, data, len) != 0) {
  ------------------
  |  Branch (57:7): [True: 0, False: 5.08k]
  ------------------
   58|      0|			ibuf_free(buf);
   59|      0|			return (NULL);
   60|      0|		}
   61|  5.08k|	}
   62|       |
   63|  5.10k|	return (buf);
   64|  5.10k|}

log_getverbose:
   82|  26.6k|{
   83|  26.6k|	return (verbose);
   84|  26.6k|}
vlog:
   98|  1.90k|{
   99|  1.90k|	char	*nfmt;
  100|  1.90k|	int	 saved_errno = errno;
  101|       |
  102|  1.90k|	if (debug) {
  ------------------
  |  Branch (102:6): [True: 0, False: 1.90k]
  ------------------
  103|       |		/* best effort in out of mem situations */
  104|      0|		if (asprintf(&nfmt, "%s\n", fmt) == -1) {
  ------------------
  |  Branch (104:7): [True: 0, False: 0]
  ------------------
  105|      0|			vfprintf(stderr, fmt, ap);
  106|      0|			fprintf(stderr, "\n");
  107|      0|		} else {
  108|      0|			vfprintf(stderr, nfmt, ap);
  109|      0|			free(nfmt);
  110|      0|		}
  111|      0|		fflush(stderr);
  112|      0|	} else
  113|  1.90k|		vsyslog(pri, fmt, ap);
  114|       |
  115|       |	errno = saved_errno;
  116|  1.90k|}
log_info:
  158|  1.90k|{
  159|  1.90k|	va_list	 ap;
  160|       |
  161|  1.90k|	va_start(ap, emsg);
  162|  1.90k|	vlog(LOG_INFO, emsg, ap);
  163|       |	va_end(ap);
  164|  1.90k|}
log_debug:
  168|   103k|{
  169|   103k|	va_list	 ap;
  170|       |
  171|   103k|	if (verbose > 1) {
  ------------------
  |  Branch (171:6): [True: 0, False: 103k]
  ------------------
  172|      0|		va_start(ap, emsg);
  173|      0|		vlog(LOG_DEBUG, emsg, ap);
  174|       |		va_end(ap);
  175|      0|	}
  176|   103k|}

socket_getport:
   71|  1.44k|{
   72|  1.44k|	switch (sa->sa_family) {
   73|  1.24k|	case AF_INET:
  ------------------
  |  Branch (73:2): [True: 1.24k, False: 202]
  ------------------
   74|  1.24k|		return (ntohs(((struct sockaddr_in *)sa)->sin_port));
   75|    202|	case AF_INET6:
  ------------------
  |  Branch (75:2): [True: 202, False: 1.24k]
  ------------------
   76|    202|		return (ntohs(((struct sockaddr_in6 *)sa)->sin6_port));
   77|      0|	default:
  ------------------
  |  Branch (77:2): [True: 0, False: 1.44k]
  ------------------
   78|      0|		return (0);
   79|  1.44k|	}
   80|       |
   81|       |	/* NOTREACHED */
   82|      0|	return (0);
   83|  1.44k|}
print_spi:
  499|  9.15k|{
  500|  9.15k|	static char		 buf[IKED_CYCLE_BUFFERS][32];
  501|  9.15k|	static int		 i = 0;
  502|  9.15k|	char			*ptr;
  503|       |
  504|  9.15k|	ptr = buf[i];
  505|       |
  506|  9.15k|	switch (size) {
  507|      0|	case 2:
  ------------------
  |  Branch (507:2): [True: 0, False: 9.15k]
  ------------------
  508|      0|		snprintf(ptr, 32, "0x%04x", (uint16_t)spi);
  509|      0|		break;
  510|    513|	case 4:
  ------------------
  |  Branch (510:2): [True: 513, False: 8.64k]
  ------------------
  511|    513|		snprintf(ptr, 32, "0x%08x", (uint32_t)spi);
  512|    513|		break;
  513|  5.87k|	case 8:
  ------------------
  |  Branch (513:2): [True: 5.87k, False: 3.28k]
  ------------------
  514|  5.87k|		snprintf(ptr, 32, "0x%016llx", (long long unsigned)spi);
  515|  5.87k|		break;
  516|  2.76k|	default:
  ------------------
  |  Branch (516:2): [True: 2.76k, False: 6.38k]
  ------------------
  517|  2.76k|		snprintf(ptr, 32, "%llu", (long long unsigned)spi);
  518|  2.76k|		break;
  519|  9.15k|	}
  520|       |
  521|  9.15k|	if (++i >= IKED_CYCLE_BUFFERS)
  ------------------
  |  |   70|  9.15k|#define IKED_CYCLE_BUFFERS	8	/* # of static buffers for mapping */
  ------------------
  |  Branch (521:6): [True: 1.14k, False: 8.00k]
  ------------------
  522|  1.14k|		i = 0;
  523|       |
  524|  9.15k|	return (ptr);
  525|  9.15k|}
print_map:
  529|   132k|{
  530|   132k|	unsigned int		 i;
  531|   132k|	static char		 buf[IKED_CYCLE_BUFFERS][32];
  532|   132k|	static int		 idx = 0;
  533|   132k|	const char		*name = NULL;
  534|       |
  535|   132k|	if (idx >= IKED_CYCLE_BUFFERS)
  ------------------
  |  |   70|   132k|#define IKED_CYCLE_BUFFERS	8	/* # of static buffers for mapping */
  ------------------
  |  Branch (535:6): [True: 16.5k, False: 115k]
  ------------------
  536|  16.5k|		idx = 0;
  537|   132k|	bzero(buf[idx], sizeof(buf[idx]));
  538|       |
  539|  2.66M|	for (i = 0; map[i].cm_name != NULL; i++) {
  ------------------
  |  Branch (539:14): [True: 2.53M, False: 132k]
  ------------------
  540|  2.53M|		if (map[i].cm_type == type)
  ------------------
  |  Branch (540:7): [True: 100k, False: 2.43M]
  ------------------
  541|   100k|			name = map[i].cm_name;
  542|  2.53M|	}
  543|       |
  544|   132k|	if (name == NULL)
  ------------------
  |  Branch (544:6): [True: 31.4k, False: 100k]
  ------------------
  545|   132k|		snprintf(buf[idx], sizeof(buf[idx]), "<UNKNOWN:%u>", type);
  546|   100k|	else
  547|   100k|		strlcpy(buf[idx], name, sizeof(buf[idx]));
  548|       |
  549|   132k|	return (buf[idx++]);
  550|   132k|}
print_hex:
  561|  26.6k|{
  562|  26.6k|	unsigned int	 i;
  563|       |
  564|  26.6k|	if (log_getverbose() < 3 || !length)
  ------------------
  |  Branch (564:6): [True: 26.6k, False: 0]
  |  Branch (564:30): [True: 0, False: 0]
  ------------------
  565|  26.6k|		return;
  566|       |
  567|      0|	for (i = 0; i < length; i++) {
  ------------------
  |  Branch (567:14): [True: 0, False: 0]
  ------------------
  568|      0|		if (i && (i % 4) == 0) {
  ------------------
  |  Branch (568:7): [True: 0, False: 0]
  |  Branch (568:12): [True: 0, False: 0]
  ------------------
  569|      0|			if ((i % 32) == 0)
  ------------------
  |  Branch (569:8): [True: 0, False: 0]
  ------------------
  570|      0|				print_debug("\n");
  571|      0|			else
  572|      0|				print_debug(" ");
  573|      0|		}
  574|      0|		print_debug("%02x", buf[offset + i]);
  575|      0|	}
  576|      0|	print_debug("\n");
  577|      0|}
print_addr:
  737|  1.44k|{
  738|  1.44k|	static char	 sbuf[IKED_CYCLE_BUFFERS][NI_MAXHOST + 9];
  739|  1.44k|	static int	 idx;
  740|  1.44k|	struct sockaddr	*sa = addr;
  741|  1.44k|	char		*buf, *hbuf;
  742|  1.44k|	size_t		 len, hlen;
  743|  1.44k|	char		 pbuf[7];
  744|  1.44k|	in_port_t	 port;
  745|       |
  746|  1.44k|	hbuf = buf = sbuf[idx];
  747|  1.44k|	hlen = len = sizeof(sbuf[idx]);
  748|  1.44k|	if (++idx >= IKED_CYCLE_BUFFERS)
  ------------------
  |  |   70|  1.44k|#define IKED_CYCLE_BUFFERS	8	/* # of static buffers for mapping */
  ------------------
  |  Branch (748:6): [True: 181, False: 1.26k]
  ------------------
  749|    181|		idx = 0;
  750|       |
  751|  1.44k|	if (sa->sa_family == AF_UNSPEC) {
  ------------------
  |  Branch (751:6): [True: 0, False: 1.44k]
  ------------------
  752|      0|		strlcpy(buf, "any", len);
  753|      0|		return (buf);
  754|      0|	}
  755|       |
  756|  1.44k|	if ((port = socket_getport(sa)) != 0 && sa->sa_family == AF_INET6) {
  ------------------
  |  Branch (756:6): [True: 0, False: 1.44k]
  |  Branch (756:42): [True: 0, False: 0]
  ------------------
  757|       |		/* surround [] */
  758|      0|		*(hbuf++) = '[';
  759|      0|		hlen--;
  760|      0|	}
  761|       |
  762|  1.44k|	if (getnameinfo(sa, SA_LEN(sa),
  ------------------
  |  |  113|  1.44k|	((sa->sa_family == AF_INET)  ? sizeof(struct sockaddr_in) :	\
  |  |  ------------------
  |  |  |  Branch (113:3): [True: 1.24k, False: 202]
  |  |  ------------------
  |  |  114|  1.44k|	(sa->sa_family == AF_INET6) ? sizeof(struct sockaddr_in6) :	\
  |  |  ------------------
  |  |  |  Branch (114:2): [True: 202, False: 0]
  |  |  ------------------
  |  |  115|    202|	sizeof(struct sockaddr))
  ------------------
  |  Branch (762:6): [True: 0, False: 1.44k]
  ------------------
  763|  1.44k|	    hbuf, hlen, NULL, 0, NI_NUMERICHOST) != 0) {
  764|      0|		strlcpy(buf, "unknown", len);
  765|      0|		return (buf);
  766|      0|	}
  767|       |
  768|  1.44k|	if (port != 0) {
  ------------------
  |  Branch (768:6): [True: 0, False: 1.44k]
  ------------------
  769|      0|		if (sa->sa_family == AF_INET6)
  ------------------
  |  Branch (769:7): [True: 0, False: 0]
  ------------------
  770|      0|			(void)strlcat(buf, "]", len);
  771|      0|		snprintf(pbuf, sizeof(pbuf), ":%d", port);
  772|      0|		(void)strlcat(buf, pbuf, len);
  773|      0|	}
  774|       |
  775|  1.44k|	return (buf);
  776|  1.44k|}

eap_parse:
   61|    347|{
   62|    347|	return (0);
   63|    347|}
ikev2_msg_frompeer:
   68|  45.3k|{
   69|  45.3k|	struct iked_sa		*sa = msg->msg_sa;
   70|  45.3k|	struct ike_header	*hdr;
   71|       |
   72|  45.3k|	msg = msg->msg_parent;
   73|       |
   74|  45.3k|	if (sa == NULL ||
  ------------------
  |  Branch (74:6): [True: 0, False: 45.3k]
  ------------------
   75|  45.3k|	    (hdr = ibuf_seek(msg->msg_data, 0, sizeof(*hdr))) == NULL)
  ------------------
  |  Branch (75:6): [True: 0, False: 45.3k]
  ------------------
   76|      0|		return (0);
   77|       |
   78|  45.3k|	if (!sa->sa_hdr.sh_initiator &&
  ------------------
  |  Branch (78:6): [True: 45.3k, False: 0]
  ------------------
   79|  45.3k|	    (hdr->ike_flags & IKEV2_FLAG_INITIATOR))
  ------------------
  |  |   20|  45.3k|#define IKEV2_FLAG_INITIATOR            0x08    /* Sent by the initiator */
  ------------------
  |  Branch (79:6): [True: 15.0k, False: 30.3k]
  ------------------
   80|  15.0k|		return (1);
   81|  30.3k|	else if (sa->sa_hdr.sh_initiator &&
  ------------------
  |  Branch (81:11): [True: 0, False: 30.3k]
  ------------------
   82|      0|	    (hdr->ike_flags & IKEV2_FLAG_INITIATOR) == 0)
  ------------------
  |  |   20|      0|#define IKEV2_FLAG_INITIATOR            0x08    /* Sent by the initiator */
  ------------------
  |  Branch (82:6): [True: 0, False: 0]
  ------------------
   83|      0|		return (1);
   84|       |
   85|  30.3k|	return (0);
   86|  45.3k|}
ikev2_ikesa_info:
  102|  1.49k|{
  103|  1.49k|	return "";
  104|  1.49k|}
sa_stateok:
  121|    213|{
  122|    213|	return (0);
  123|    213|}
ikev2_nat_detection:
  165|    606|{
  166|    606|	bzero(ptr, len);
  167|    606|	return (0);
  168|    606|}
ikev2_print_id:
  180|    522|{
  181|    522|	return (0);
  182|    522|}
config_add_proposal:
  193|      4|{
  194|       |	return (NULL);
  195|      4|}
config_free_fragments:
  205|  2.61k|{
  206|  2.61k|	size_t i;
  207|       |
  208|  2.61k|	if (frag && frag->frag_arr) {
  ------------------
  |  Branch (208:6): [True: 2.61k, False: 0]
  |  Branch (208:14): [True: 36, False: 2.58k]
  ------------------
  209|    815|		for (i = 0; i < frag->frag_total; i++) {
  ------------------
  |  Branch (209:15): [True: 779, False: 36]
  ------------------
  210|    779|			if (frag->frag_arr[i] != NULL)
  ------------------
  |  Branch (210:8): [True: 36, False: 743]
  ------------------
  211|     36|				free(frag->frag_arr[i]->frag_data);
  212|    779|			free(frag->frag_arr[i]);
  213|    779|		}
  214|     36|		free(frag->frag_arr);
  215|     36|		bzero(frag, sizeof(struct iked_frag));
  216|     36|	}
  217|  2.61k|}
ikev2_send_informational:
  221|    946|{
  222|    946|	return (0);
  223|    946|}
ikev2_msg_decrypt:
  228|  1.27k|{
  229|  1.27k|	if (src == NULL){
  ------------------
  |  Branch (229:6): [True: 0, False: 1.27k]
  ------------------
  230|      0|                fprintf(stderr, "%s\n", "msg_decrypt: src == NULL!");
  231|      0|                exit(-1);
  232|      0|        }
  233|       |
  234|       |	/* do no really decryption */
  235|  1.27k|	return (src);
  236|  1.27k|}
ikev2_msg_cleanup:
  258|  2.58k|{
  259|  2.58k|	struct iked_certreq *cr;
  260|  2.58k|	struct iked_proposal *prop, *proptmp;
  261|  2.58k|	int			 i;
  262|       |
  263|  2.58k|	if (msg == msg->msg_parent) {
  ------------------
  |  Branch (263:6): [True: 2.58k, False: 0]
  ------------------
  264|  2.58k|		ibuf_free(msg->msg_nonce);
  265|  2.58k|		ibuf_free(msg->msg_ke);
  266|  2.58k|		ibuf_free(msg->msg_auth.id_buf);
  267|  2.58k|		ibuf_free(msg->msg_peerid.id_buf);
  268|  2.58k|		ibuf_free(msg->msg_localid.id_buf);
  269|  2.58k|		ibuf_free(msg->msg_cert.id_buf);
  270|  10.3k|		for (i = 0; i < IKED_SCERT_MAX; i++)
  ------------------
  |  |  476|  10.3k|#define IKED_SCERT_MAX	3 /* max # of supplemental cert payloads */
  ------------------
  |  Branch (270:15): [True: 7.74k, False: 2.58k]
  ------------------
  271|  7.74k|			ibuf_free(msg->msg_scert[i].id_buf);
  272|  2.58k|		ibuf_free(msg->msg_cookie);
  273|  2.58k|		ibuf_free(msg->msg_cookie2);
  274|  2.58k|		ibuf_free(msg->msg_del_buf);
  275|  2.58k|		free(msg->msg_eap.eam_user);
  276|  2.58k|		free(msg->msg_cp_addr);
  277|  2.58k|		free(msg->msg_cp_addr6);
  278|  2.58k|		free(msg->msg_cp_dns);
  279|       |
  280|  2.58k|		TAILQ_FOREACH_SAFE(prop, &msg->msg_proposals, prop_entry,
  ------------------
  |  |  445|  2.58k|	for ((var) = TAILQ_FIRST(head);					\
  |  |  ------------------
  |  |  |  |  428|  2.58k|#define	TAILQ_FIRST(head)		((head)->tqh_first)
  |  |  ------------------
  |  |  446|  2.58k|	    (var) != TAILQ_END(head) &&					\
  |  |  ------------------
  |  |  |  |  429|  5.16k|#define	TAILQ_END(head)			NULL
  |  |  ------------------
  |  |  |  Branch (446:6): [True: 0, False: 2.58k]
  |  |  ------------------
  |  |  447|  2.58k|	    ((tvar) = TAILQ_NEXT(var, field), 1);			\
  |  |  ------------------
  |  |  |  |  430|      0|#define	TAILQ_NEXT(elm, field)		((elm)->field.tqe_next)
  |  |  ------------------
  |  |  |  Branch (447:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  448|  2.58k|	    (var) = (tvar))
  ------------------
  281|  2.58k|		    proptmp) {
  282|      0|			TAILQ_REMOVE(&msg->msg_proposals, prop, prop_entry);
  ------------------
  |  |  504|      0|#define TAILQ_REMOVE(head, elm, field) do {				\
  |  |  505|      0|	if (((elm)->field.tqe_next) != NULL)				\
  |  |  ------------------
  |  |  |  Branch (505:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  506|      0|		(elm)->field.tqe_next->field.tqe_prev =			\
  |  |  507|      0|		    (elm)->field.tqe_prev;				\
  |  |  508|      0|	else								\
  |  |  509|      0|		(head)->tqh_last = (elm)->field.tqe_prev;		\
  |  |  510|      0|	*(elm)->field.tqe_prev = (elm)->field.tqe_next;			\
  |  |  511|      0|	_Q_INVALIDATE((elm)->field.tqe_prev);				\
  |  |  512|      0|	_Q_INVALIDATE((elm)->field.tqe_next);				\
  |  |  513|      0|} while (0)
  |  |  ------------------
  |  |  |  Branch (513:10): [Folded, False: 0]
  |  |  ------------------
  ------------------
  283|      0|			if (prop->prop_nxforms)
  ------------------
  |  Branch (283:8): [True: 0, False: 0]
  ------------------
  284|      0|				free(prop->prop_xforms);
  285|      0|			free(prop);
  286|      0|		}
  287|       |
  288|  2.58k|		msg->msg_nonce = NULL;
  289|  2.58k|		msg->msg_ke = NULL;
  290|  2.58k|		msg->msg_auth.id_buf = NULL;
  291|  2.58k|		msg->msg_peerid.id_buf = NULL;
  292|  2.58k|		msg->msg_localid.id_buf = NULL;
  293|  2.58k|		msg->msg_cert.id_buf = NULL;
  294|  10.3k|		for (i = 0; i < IKED_SCERT_MAX; i++)
  ------------------
  |  |  476|  10.3k|#define IKED_SCERT_MAX	3 /* max # of supplemental cert payloads */
  ------------------
  |  Branch (294:15): [True: 7.74k, False: 2.58k]
  ------------------
  295|  7.74k|			msg->msg_scert[i].id_buf = NULL;
  296|  2.58k|		msg->msg_cookie = NULL;
  297|  2.58k|		msg->msg_cookie2 = NULL;
  298|  2.58k|		msg->msg_del_buf = NULL;
  299|  2.58k|		msg->msg_eap.eam_user = NULL;
  300|  2.58k|		msg->msg_cp_addr = NULL;
  301|  2.58k|		msg->msg_cp_addr6 = NULL;
  302|  2.58k|		msg->msg_cp_dns = NULL;
  303|       |
  304|  4.76k|		while ((cr = SIMPLEQ_FIRST(&msg->msg_certreqs))) {
  ------------------
  |  |  267|  4.76k|#define	SIMPLEQ_FIRST(head)	    ((head)->sqh_first)
  ------------------
  |  Branch (304:10): [True: 2.18k, False: 2.58k]
  ------------------
  305|  2.18k|			ibuf_free(cr->cr_data);
  306|  2.18k|			SIMPLEQ_REMOVE_HEAD(&msg->msg_certreqs, cr_entry);
  ------------------
  |  |  308|  2.18k|#define SIMPLEQ_REMOVE_HEAD(head, field) do {			\
  |  |  309|  2.18k|	if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
  |  |  ------------------
  |  |  |  Branch (309:6): [True: 91, False: 2.09k]
  |  |  ------------------
  |  |  310|  2.18k|		(head)->sqh_last = &(head)->sqh_first;			\
  |  |  311|  2.18k|} while (0)
  |  |  ------------------
  |  |  |  Branch (311:10): [Folded, False: 2.18k]
  |  |  ------------------
  ------------------
  307|  2.18k|			free(cr);
  308|  2.18k|		}
  309|  2.58k|	}
  310|       |
  311|  2.58k|	if (msg->msg_data != NULL) {
  ------------------
  |  Branch (311:6): [True: 2.58k, False: 0]
  ------------------
  312|  2.58k|		ibuf_free(msg->msg_data);
  313|       |		msg->msg_data = NULL;
  314|  2.58k|	}
  315|  2.58k|}

LLVMFuzzerTestOneInput:
  107|  2.59k|{
  108|  2.59k|	static struct iked	 env;
  109|  2.59k|	struct ibuf		*fuzzed;
  110|  2.59k|	struct ike_header	 hdr;
  111|  2.59k|	struct iked_message	 msg;
  112|       |
  113|  2.59k|	bzero(&env, sizeof(env));
  114|  2.59k|	bzero(&hdr, sizeof(hdr));
  115|  2.59k|	bzero(&msg, sizeof(msg));
  116|       |
  117|  2.59k|	fuzzed = ibuf_new(data, size);
  118|  2.59k|	if (fuzzed == NULL){
  ------------------
  |  Branch (118:6): [True: 0, False: 2.59k]
  ------------------
  119|      0|		fprintf(stderr, "%s\n", "ERROR: fuzzed == NULL! "
  120|      0|		    "(hint: fuzz-input too long?)");
  121|      0|		return -1;
  122|      0|	}	
  123|       |	
  124|       |	/* size too small? */
  125|  2.59k|	if (size < sizeof(cookies) + sizeof(genhdr)){
  ------------------
  |  Branch (125:6): [True: 11, False: 2.58k]
  ------------------
  126|     11|		ibuf_free(fuzzed);
  127|     11|		return 0;
  128|     11|	}	       
  129|       |
  130|  2.58k|	prepare_header(&hdr, fuzzed);
  131|  2.58k|	prepare_message(&msg, fuzzed);
  132|       |
  133|  2.58k|	ikev2_pld_parse(&env, &hdr, &msg, 0);
  134|       |
  135|  2.58k|	ikev2_msg_cleanup(&env, &msg);
  136|       |
  137|  2.58k|	return 0;
  138|  2.59k|}
test_parser_fuzz.c:prepare_header:
   75|  2.58k|{
   76|  2.58k|	bzero(hdr, sizeof(*hdr));
   77|  2.58k|	bcopy(get_icookie(ibuf_data(data)), &hdr->ike_ispi,
   78|  2.58k|	    sizeof(hdr->ike_ispi));
   79|  2.58k|	bcopy(get_rcookie(ibuf_data(data)), &hdr->ike_rspi,
   80|  2.58k|	    sizeof(hdr->ike_rspi));
   81|  2.58k|	hdr->ike_nextpayload = get_nextpayload(ibuf_data(data));
   82|  2.58k|	hdr->ike_version = get_version(ibuf_data(data));
   83|  2.58k|	hdr->ike_exchange = get_exchange(ibuf_data(data));
   84|  2.58k|	hdr->ike_length = get_length(ibuf_data(data));
   85|  2.58k|}
test_parser_fuzz.c:get_icookie:
   39|  2.58k|{
   40|  2.58k|	return &data[OFFSET_ICOOKIE];
  ------------------
  |  |   30|  2.58k|#define OFFSET_ICOOKIE		0
  ------------------
   41|  2.58k|}
test_parser_fuzz.c:get_rcookie:
   45|  2.58k|{
   46|  2.58k|	return &data[OFFSET_RCOOKIE];
  ------------------
  |  |   31|  2.58k|#define OFFSET_RCOOKIE		8
  ------------------
   47|  2.58k|}
test_parser_fuzz.c:get_nextpayload:
   51|  2.58k|{
   52|  2.58k|	return data[OFFSET_NEXTPAYLOAD];
  ------------------
  |  |   32|  2.58k|#define OFFSET_NEXTPAYLOAD	(0 + sizeof(cookies))
  ------------------
   53|  2.58k|}
test_parser_fuzz.c:get_version:
   57|  2.58k|{
   58|  2.58k|	return data[OFFSET_VERSION];
  ------------------
  |  |   33|  2.58k|#define OFFSET_VERSION		(1 + sizeof(cookies))
  ------------------
   59|  2.58k|}
test_parser_fuzz.c:get_exchange:
   63|  2.58k|{
   64|  2.58k|	return data[OFFSET_EXCHANGE];
  ------------------
  |  |   34|  2.58k|#define OFFSET_EXCHANGE		(2 + sizeof(cookies))
  ------------------
   65|  2.58k|}
test_parser_fuzz.c:get_length:
   69|  2.58k|{
   70|  2.58k|	return *(u_int32_t *)&data[OFFSET_LENGTH];
  ------------------
  |  |   35|  2.58k|#define OFFSET_LENGTH		(8 + sizeof(cookies))
  ------------------
   71|  2.58k|}
test_parser_fuzz.c:prepare_message:
   89|  2.58k|{
   90|  2.58k|	static struct iked_sa	sa;
   91|       |
   92|  2.58k|	config_free_fragments(&sa.sa_fragments);
   93|  2.58k|	bzero(&sa, sizeof(sa));
   94|  2.58k|	bzero(msg, sizeof(*msg));
   95|       |
   96|  2.58k|	msg->msg_sa = &sa;
   97|  2.58k|	msg->msg_data = data;
   98|  2.58k|	msg->msg_parent = msg;
   99|       |
  100|  2.58k|	TAILQ_INIT(&msg->msg_proposals);
  ------------------
  |  |  465|  2.58k|#define	TAILQ_INIT(head) do {						\
  |  |  466|  2.58k|	(head)->tqh_first = NULL;					\
  |  |  467|  2.58k|	(head)->tqh_last = &(head)->tqh_first;				\
  |  |  468|  2.58k|} while (0)
  |  |  ------------------
  |  |  |  Branch (468:10): [Folded, False: 2.58k]
  |  |  ------------------
  ------------------
  101|       |	SIMPLEQ_INIT(&msg->msg_certreqs);
  ------------------
  |  |  285|  2.58k|#define	SIMPLEQ_INIT(head) do {						\
  |  |  286|  2.58k|	(head)->sqh_first = NULL;					\
  |  |  287|  2.58k|	(head)->sqh_last = &(head)->sqh_first;				\
  |  |  288|  2.58k|} while (0)
  |  |  ------------------
  |  |  |  Branch (288:10): [Folded, False: 2.58k]
  |  |  ------------------
  ------------------
  102|  2.58k|}

