lldpd_alloc_mgmt:
  267|    132|{
  268|    132|	struct lldpd_mgmt *mgmt;
  269|       |
  270|    132|	log_debug("alloc", "allocate a new management address (family: %d)", family);
  271|       |
  272|    132|	if (family <= LLDPD_AF_UNSPEC || family >= LLDPD_AF_LAST) {
  ------------------
  |  Branch (272:6): [True: 0, False: 132]
  |  Branch (272:35): [True: 0, False: 132]
  ------------------
  273|      0|		errno = EAFNOSUPPORT;
  274|      0|		return NULL;
  275|      0|	}
  276|    132|	if (addrsize > LLDPD_MGMT_MAXADDRSIZE) {
  ------------------
  |  |  157|    132|#define LLDPD_MGMT_MAXADDRSIZE 16 /* sizeof(struct in6_addr) */
  ------------------
  |  Branch (276:6): [True: 0, False: 132]
  ------------------
  277|      0|		errno = EOVERFLOW;
  278|      0|		return NULL;
  279|      0|	}
  280|    132|	mgmt = calloc(1, sizeof(struct lldpd_mgmt));
  281|    132|	if (mgmt == NULL) {
  ------------------
  |  Branch (281:6): [True: 0, False: 132]
  ------------------
  282|      0|		errno = ENOMEM;
  283|      0|		return NULL;
  284|      0|	}
  285|    132|	mgmt->m_family = family;
  286|    132|	memcpy(&mgmt->m_addr, addrptr, addrsize);
  287|    132|	mgmt->m_addrsize = addrsize;
  288|    132|	mgmt->m_iface = iface;
  289|    132|	return mgmt;
  290|    132|}

cdp_decode:
  283|    568|{
  284|    568|	struct lldpd_chassis *chassis;
  285|    568|	struct lldpd_port *port;
  286|    568|	struct lldpd_mgmt *mgmt;
  287|    568|	struct in_addr addr;
  288|       |#  if 0
  289|       |	u_int16_t cksum;
  290|       |#  endif
  291|    568|	u_int8_t *software = NULL, *platform = NULL;
  292|    568|	int software_len = 0, platform_len = 0, proto, version, nb, caps;
  293|    568|	const unsigned char cdpaddr[] = CDP_MULTICAST_ADDR;
  ------------------
  |  |   21|    568|#define CDP_MULTICAST_ADDR { 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc }
  ------------------
  294|    568|#  ifdef ENABLE_FDP
  295|    568|	const unsigned char fdpaddr[] = FDP_MULTICAST_ADDR;
  ------------------
  |  |   23|    568|	{                  \
  |  |   24|    568|		0x01,      \
  |  |   25|    568|		0xe0,      \
  |  |   26|    568|		0x52,      \
  |  |   27|    568|		0xcc,      \
  |  |   28|    568|		0xcc,      \
  |  |   29|    568|		0xcc,      \
  |  |   30|    568|	}
  ------------------
  296|    568|	int fdp = 0;
  297|    568|#  endif
  298|    568|	u_int8_t *pos, *tlv, *pos_address, *pos_next_address;
  299|    568|	int length, len_eth, tlv_type, tlv_len, addresses_len, address_len;
  300|    568|#  ifdef ENABLE_DOT1
  301|    568|	struct lldpd_vlan *vlan;
  302|    568|#  endif
  303|       |
  304|    568|	log_debug("cdp", "decode CDP frame received on %s", hardware->h_ifname);
  305|       |
  306|    568|	if ((chassis = calloc(1, sizeof(struct lldpd_chassis))) == NULL) {
  ------------------
  |  Branch (306:6): [True: 0, False: 568]
  ------------------
  307|      0|		log_warn("cdp", "failed to allocate remote chassis");
  308|      0|		return -1;
  309|      0|	}
  310|    568|	TAILQ_INIT(&chassis->c_mgmt);
  ------------------
  |  Branch (310:2): [Folded, False: 568]
  ------------------
  311|    568|	if ((port = calloc(1, sizeof(struct lldpd_port))) == NULL) {
  ------------------
  |  Branch (311:6): [True: 0, False: 568]
  ------------------
  312|      0|		log_warn("cdp", "failed to allocate remote port");
  313|      0|		free(chassis);
  314|      0|		return -1;
  315|      0|	}
  316|    568|#  ifdef ENABLE_DOT1
  317|    568|	TAILQ_INIT(&port->p_vlans);
  ------------------
  |  Branch (317:2): [Folded, False: 568]
  ------------------
  318|    568|#  endif
  319|       |
  320|    568|	length = s;
  321|    568|	pos = (u_int8_t *)frame;
  322|       |
  323|    568|	if (length < 2 * ETHER_ADDR_LEN + sizeof(u_int16_t) /* Ethernet */ +
  ------------------
  |  Branch (323:6): [True: 0, False: 568]
  ------------------
  324|    568|		8 /* LLC */ + 4 /* CDP header */) {
  325|      0|		log_warn("cdp", "too short CDP/FDP frame received on %s",
  326|      0|		    hardware->h_ifname);
  327|      0|		goto malformed;
  328|      0|	}
  329|       |
  330|    568|	if (PEEK_CMP(cdpaddr, sizeof(cdpaddr)) != 0) {
  ------------------
  |  |   80|    568|	(length -= (bytes), pos += (bytes), memcmp(pos - bytes, value, bytes))
  ------------------
  |  Branch (330:6): [True: 0, False: 568]
  ------------------
  331|      0|#  ifdef ENABLE_FDP
  332|      0|		PEEK_RESTORE((u_int8_t *)frame);
  ------------------
  |  |   82|      0|#define PEEK_RESTORE POKE_RESTORE
  |  |  ------------------
  |  |  |  |   48|      0|	do {                                       \
  |  |  |  |   49|      0|		if ((where) > pos)                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (49:7): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   50|      0|			length -= ((where) - pos); \
  |  |  |  |   51|      0|		else                               \
  |  |  |  |   52|      0|			length += (pos - (where)); \
  |  |  |  |   53|      0|		pos = (where);                     \
  |  |  |  |   54|      0|	} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (54:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  333|      0|		if (PEEK_CMP(fdpaddr, sizeof(fdpaddr)) == 0)
  ------------------
  |  |   80|      0|	(length -= (bytes), pos += (bytes), memcmp(pos - bytes, value, bytes))
  ------------------
  |  Branch (333:7): [True: 0, False: 0]
  ------------------
  334|      0|			fdp = 1;
  335|      0|		else {
  336|      0|#  endif
  337|      0|			log_info("cdp",
  338|      0|			    "frame not targeted at CDP/FDP multicast address received on %s",
  339|      0|			    hardware->h_ifname);
  340|      0|			goto malformed;
  341|      0|#  ifdef ENABLE_FDP
  342|      0|		}
  343|      0|#  endif
  344|      0|	}
  345|    568|	PEEK_DISCARD(ETHER_ADDR_LEN); /* Don't care of source address */
  ------------------
  |  |   72|    568|	do {                       \
  |  |   73|    568|		length -= (bytes); \
  |  |   74|    568|		pos += (bytes);    \
  |  |   75|    568|	} while (0)
  |  |  ------------------
  |  |  |  Branch (75:11): [Folded, False: 568]
  |  |  ------------------
  ------------------
  346|    568|	len_eth = PEEK_UINT16;
  ------------------
  |  |   63|    568|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  ------------------
  |  |  |  |   60|    568|	(memcpy(&type, pos, sizeof(type)), length -= sizeof(type), \
  |  |  |  |   61|    568|	    pos += sizeof(type), func(type))
  |  |  |  |  ------------------
  |  |  |  |  |  |   63|    568|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  347|    568|	if (len_eth > length) {
  ------------------
  |  Branch (347:6): [True: 12, False: 556]
  ------------------
  348|     12|		log_warnx("cdp", "incorrect 802.3 frame size reported on %s",
  349|     12|		    hardware->h_ifname);
  350|     12|		goto malformed;
  351|     12|	}
  352|       |
  353|       |	/* This is the correct length of the CDP + LLC packets */
  354|    556|	length = len_eth;
  355|       |
  356|    556|	PEEK_DISCARD(6); /* Skip beginning of LLC */
  ------------------
  |  |   72|    556|	do {                       \
  |  |   73|    556|		length -= (bytes); \
  |  |   74|    556|		pos += (bytes);    \
  |  |   75|    556|	} while (0)
  |  |  ------------------
  |  |  |  Branch (75:11): [Folded, False: 556]
  |  |  ------------------
  ------------------
  357|    556|	proto = PEEK_UINT16;
  ------------------
  |  |   63|    556|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  ------------------
  |  |  |  |   60|    556|	(memcpy(&type, pos, sizeof(type)), length -= sizeof(type), \
  |  |  |  |   61|    556|	    pos += sizeof(type), func(type))
  |  |  |  |  ------------------
  |  |  |  |  |  |   63|    556|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  358|    556|	if (proto != LLC_PID_CDP) {
  ------------------
  |  |   33|    556|#define LLC_PID_CDP 0x2000
  ------------------
  |  Branch (358:6): [True: 93, False: 463]
  ------------------
  359|     93|		if ((proto != LLC_PID_DRIP) && (proto != LLC_PID_PAGP) &&
  ------------------
  |  |   35|     93|#define LLC_PID_DRIP 0x102
  ------------------
              		if ((proto != LLC_PID_DRIP) && (proto != LLC_PID_PAGP) &&
  ------------------
  |  |   36|     92|#define LLC_PID_PAGP 0x104
  ------------------
  |  Branch (359:7): [True: 92, False: 1]
  |  Branch (359:34): [True: 88, False: 4]
  ------------------
  360|     88|		    (proto != LLC_PID_PVSTP) && (proto != LLC_PID_UDLD) &&
  ------------------
  |  |   37|     88|#define LLC_PID_PVSTP 0x10b
  ------------------
              		    (proto != LLC_PID_PVSTP) && (proto != LLC_PID_UDLD) &&
  ------------------
  |  |   38|     87|#define LLC_PID_UDLD 0x111
  ------------------
  |  Branch (360:7): [True: 87, False: 1]
  |  Branch (360:35): [True: 83, False: 4]
  ------------------
  361|     83|		    (proto != LLC_PID_VTP) && (proto != LLC_PID_DTP) &&
  ------------------
  |  |   39|     83|#define LLC_PID_VTP 0x2003
  ------------------
              		    (proto != LLC_PID_VTP) && (proto != LLC_PID_DTP) &&
  ------------------
  |  |   40|     80|#define LLC_PID_DTP 0x2004
  ------------------
  |  Branch (361:7): [True: 80, False: 3]
  |  Branch (361:33): [True: 79, False: 1]
  ------------------
  362|     79|		    (proto != LLC_PID_STP))
  ------------------
  |  |   41|     79|#define LLC_PID_STP 0x200a
  ------------------
  |  Branch (362:7): [True: 78, False: 1]
  ------------------
  363|     78|			log_debug("cdp", "incorrect LLC protocol ID received on %s",
  364|     78|			    hardware->h_ifname);
  365|     93|		goto malformed;
  366|     93|	}
  367|       |
  368|       |#  if 0
  369|       |	/* Check checksum */
  370|       |	cksum = frame_checksum(pos, len_eth - 8,
  371|       |#    ifdef ENABLE_FDP
  372|       |	    !fdp		/* fdp = 0 -> cisco checksum */
  373|       |#    else
  374|       |	    1			/* cisco checksum */
  375|       |#    endif
  376|       |		);
  377|       |	if (cksum != 0) {
  378|       |		log_info("cdp", "incorrect CDP/FDP checksum for frame received on %s (%d)",
  379|       |			  hardware->h_ifname, cksum);
  380|       |		goto malformed;
  381|       |	}
  382|       |#  endif
  383|       |
  384|       |	/* Check version */
  385|    463|	version = PEEK_UINT8;
  ------------------
  |  |   62|    463|#define PEEK_UINT8 PEEK(types.f_uint8, )
  |  |  ------------------
  |  |  |  |   60|    463|	(memcpy(&type, pos, sizeof(type)), length -= sizeof(type), \
  |  |  |  |   61|    463|	    pos += sizeof(type), func(type))
  |  |  ------------------
  ------------------
  386|    463|	if ((version != 1) && (version != 2)) {
  ------------------
  |  Branch (386:6): [True: 463, False: 0]
  |  Branch (386:24): [True: 0, False: 463]
  ------------------
  387|      0|		log_warnx("cdp",
  388|      0|		    "incorrect CDP/FDP version (%d) for frame received on %s", version,
  389|      0|		    hardware->h_ifname);
  390|      0|		goto malformed;
  391|      0|	}
  392|    463|	port->p_ttl = PEEK_UINT8; /* TTL */
  ------------------
  |  |   62|    463|#define PEEK_UINT8 PEEK(types.f_uint8, )
  |  |  ------------------
  |  |  |  |   60|    463|	(memcpy(&type, pos, sizeof(type)), length -= sizeof(type), \
  |  |  |  |   61|    463|	    pos += sizeof(type), func(type))
  |  |  ------------------
  ------------------
  393|    463|	PEEK_DISCARD_UINT16;	  /* Checksum, already checked */
  ------------------
  |  |   77|    463|#define PEEK_DISCARD_UINT16 PEEK_DISCARD(2)
  |  |  ------------------
  |  |  |  |   72|    463|	do {                       \
  |  |  |  |   73|    463|		length -= (bytes); \
  |  |  |  |   74|    463|		pos += (bytes);    \
  |  |  |  |   75|    463|	} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (75:11): [Folded, False: 463]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  394|       |
  395|  5.47k|	while (length) {
  ------------------
  |  Branch (395:9): [True: 5.22k, False: 256]
  ------------------
  396|  5.22k|		if (length < 4) {
  ------------------
  |  Branch (396:7): [True: 27, False: 5.19k]
  ------------------
  397|     27|			log_warnx("cdp",
  398|     27|			    "CDP/FDP TLV header is too large for "
  399|     27|			    "frame received on %s",
  400|     27|			    hardware->h_ifname);
  401|     27|			goto malformed;
  402|     27|		}
  403|  5.19k|		tlv_type = PEEK_UINT16;
  ------------------
  |  |   63|  5.19k|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  ------------------
  |  |  |  |   60|  5.19k|	(memcpy(&type, pos, sizeof(type)), length -= sizeof(type), \
  |  |  |  |   61|  5.19k|	    pos += sizeof(type), func(type))
  |  |  |  |  ------------------
  |  |  |  |  |  |   63|  5.19k|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  404|  5.19k|		tlv_len = PEEK_UINT16 - 4;
  ------------------
  |  |   63|  5.19k|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  ------------------
  |  |  |  |   60|  5.19k|	(memcpy(&type, pos, sizeof(type)), length -= sizeof(type), \
  |  |  |  |   61|  5.19k|	    pos += sizeof(type), func(type))
  |  |  |  |  ------------------
  |  |  |  |  |  |   63|  5.19k|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  405|       |
  406|  5.19k|		(void)PEEK_SAVE(tlv);
  ------------------
  |  |   81|  5.19k|#define PEEK_SAVE POKE_SAVE
  |  |  ------------------
  |  |  |  |   46|  5.19k|#define POKE_SAVE(where) (where = pos, 1)
  |  |  ------------------
  ------------------
  407|  5.19k|		if ((tlv_len < 0) || (length < tlv_len)) {
  ------------------
  |  Branch (407:7): [True: 4, False: 5.19k]
  |  Branch (407:24): [True: 37, False: 5.15k]
  ------------------
  408|     41|			log_warnx("cdp",
  409|     41|			    "incorrect size in CDP/FDP TLV header for frame "
  410|     41|			    "received on %s",
  411|     41|			    hardware->h_ifname);
  412|     41|			goto malformed;
  413|     41|		}
  414|  5.15k|		switch (tlv_type) {
  415|    406|		case CDP_TLV_CHASSIS:
  ------------------
  |  Branch (415:3): [True: 406, False: 4.74k]
  ------------------
  416|    406|			free(chassis->c_name);
  417|    406|			if ((chassis->c_name = (char *)calloc(1, tlv_len + 1)) ==
  ------------------
  |  Branch (417:8): [True: 0, False: 406]
  ------------------
  418|    406|			    NULL) {
  419|      0|				log_warn("cdp",
  420|      0|				    "unable to allocate memory for chassis name");
  421|      0|				goto malformed;
  422|      0|			}
  423|    406|			PEEK_BYTES(chassis->c_name, tlv_len);
  ------------------
  |  |   66|    406|	do {                               \
  |  |   67|    406|		memcpy(value, pos, bytes); \
  |  |   68|    406|		length -= (bytes);         \
  |  |   69|    406|		pos += (bytes);            \
  |  |   70|    406|	} while (0)
  |  |  ------------------
  |  |  |  Branch (70:11): [Folded, False: 406]
  |  |  ------------------
  ------------------
  424|    406|			chassis->c_id_subtype = LLDP_CHASSISID_SUBTYPE_LOCAL;
  ------------------
  |  |   37|    406|#define LLDP_CHASSISID_SUBTYPE_LOCAL 7
  ------------------
  425|    406|			free(chassis->c_id);
  426|    406|			if ((chassis->c_id = (char *)malloc(tlv_len)) == NULL) {
  ------------------
  |  Branch (426:8): [True: 0, False: 406]
  ------------------
  427|      0|				log_warn("cdp",
  428|      0|				    "unable to allocate memory for chassis ID");
  429|      0|				goto malformed;
  430|      0|			}
  431|    406|			memcpy(chassis->c_id, chassis->c_name, tlv_len);
  432|    406|			chassis->c_id_len = tlv_len;
  433|    406|			break;
  434|    530|		case CDP_TLV_ADDRESSES:
  ------------------
  |  Branch (434:3): [True: 530, False: 4.62k]
  ------------------
  435|    530|			CHECK_TLV_SIZE(4, "Address");
  ------------------
  |  |  271|    530|	  do {                                                              \
  |  |  272|    530|		  if (tlv_len < (x)) {                                      \
  |  |  ------------------
  |  |  |  Branch (272:9): [True: 3, False: 527]
  |  |  ------------------
  |  |  273|      3|			  log_warnx("cdp",                                  \
  |  |  274|      3|			      name " CDP/FDP TLV too short received on %s", \
  |  |  275|      3|			      hardware->h_ifname);                          \
  |  |  276|      3|			  goto malformed;                                   \
  |  |  277|      3|		  }                                                         \
  |  |  278|    530|	  } while (0)
  |  |  ------------------
  |  |  |  Branch (278:13): [Folded, False: 527]
  |  |  ------------------
  ------------------
  436|    527|			addresses_len = tlv_len - 4;
  437|  2.00k|			for (nb = PEEK_UINT32; nb > 0; nb--) {
  ------------------
  |  |   64|    527|#define PEEK_UINT32 PEEK(types.f_uint32, ntohl)
  |  |  ------------------
  |  |  |  |   60|    527|	(memcpy(&type, pos, sizeof(type)), length -= sizeof(type), \
  |  |  |  |   61|    527|	    pos += sizeof(type), func(type))
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|    527|#define PEEK_UINT32 PEEK(types.f_uint32, ntohl)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (437:27): [True: 1.59k, False: 403]
  ------------------
  438|  1.59k|				(void)PEEK_SAVE(pos_address);
  ------------------
  |  |   81|  1.59k|#define PEEK_SAVE POKE_SAVE
  |  |  ------------------
  |  |  |  |   46|  1.59k|#define POKE_SAVE(where) (where = pos, 1)
  |  |  ------------------
  ------------------
  439|       |				/* We first try to get the real length of the packet */
  440|  1.59k|				if (addresses_len < 2) {
  ------------------
  |  Branch (440:9): [True: 64, False: 1.53k]
  ------------------
  441|     64|					log_warn("cdp",
  442|     64|					    "too short address subframe "
  443|     64|					    "received on %s",
  444|     64|					    hardware->h_ifname);
  445|     64|					goto malformed;
  446|     64|				}
  447|  1.53k|				PEEK_DISCARD_UINT8;
  ------------------
  |  |   76|  1.53k|#define PEEK_DISCARD_UINT8 PEEK_DISCARD(1)
  |  |  ------------------
  |  |  |  |   72|  1.53k|	do {                       \
  |  |  |  |   73|  1.53k|		length -= (bytes); \
  |  |  |  |   74|  1.53k|		pos += (bytes);    \
  |  |  |  |   75|  1.53k|	} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (75:11): [Folded, False: 1.53k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  448|  1.53k|				addresses_len--;
  449|  1.53k|				address_len = PEEK_UINT8;
  ------------------
  |  |   62|  1.53k|#define PEEK_UINT8 PEEK(types.f_uint8, )
  |  |  ------------------
  |  |  |  |   60|  1.53k|	(memcpy(&type, pos, sizeof(type)), length -= sizeof(type), \
  |  |  |  |   61|  1.53k|	    pos += sizeof(type), func(type))
  |  |  ------------------
  ------------------
  450|  1.53k|				addresses_len--;
  451|  1.53k|				if (addresses_len < address_len + 2) {
  ------------------
  |  Branch (451:9): [True: 29, False: 1.50k]
  ------------------
  452|     29|					log_warn("cdp",
  453|     29|					    "too short address subframe "
  454|     29|					    "received on %s",
  455|     29|					    hardware->h_ifname);
  456|     29|					goto malformed;
  457|     29|				}
  458|  1.50k|				PEEK_DISCARD(address_len);
  ------------------
  |  |   72|  1.50k|	do {                       \
  |  |   73|  1.50k|		length -= (bytes); \
  |  |   74|  1.50k|		pos += (bytes);    \
  |  |   75|  1.50k|	} while (0)
  |  |  ------------------
  |  |  |  Branch (75:11): [Folded, False: 1.50k]
  |  |  ------------------
  ------------------
  459|  1.50k|				addresses_len -= address_len;
  460|  1.50k|				address_len = PEEK_UINT16;
  ------------------
  |  |   63|  1.50k|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  ------------------
  |  |  |  |   60|  1.50k|	(memcpy(&type, pos, sizeof(type)), length -= sizeof(type), \
  |  |  |  |   61|  1.50k|	    pos += sizeof(type), func(type))
  |  |  |  |  ------------------
  |  |  |  |  |  |   63|  1.50k|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  461|  1.50k|				addresses_len -= 2;
  462|  1.50k|				if (addresses_len < address_len) {
  ------------------
  |  Branch (462:9): [True: 31, False: 1.47k]
  ------------------
  463|     31|					log_warn("cdp",
  464|     31|					    "too short address subframe "
  465|     31|					    "received on %s",
  466|     31|					    hardware->h_ifname);
  467|     31|					goto malformed;
  468|     31|				}
  469|  1.47k|				PEEK_DISCARD(address_len);
  ------------------
  |  |   72|  1.47k|	do {                       \
  |  |   73|  1.47k|		length -= (bytes); \
  |  |   74|  1.47k|		pos += (bytes);    \
  |  |   75|  1.47k|	} while (0)
  |  |  ------------------
  |  |  |  Branch (75:11): [Folded, False: 1.47k]
  |  |  ------------------
  ------------------
  470|  1.47k|				addresses_len -= address_len;
  471|  1.47k|				(void)PEEK_SAVE(pos_next_address);
  ------------------
  |  |   81|  1.47k|#define PEEK_SAVE POKE_SAVE
  |  |  ------------------
  |  |  |  |   46|  1.47k|#define POKE_SAVE(where) (where = pos, 1)
  |  |  ------------------
  ------------------
  472|       |				/* Next, we go back and try to extract
  473|       |				   IPv4 address */
  474|  1.47k|				PEEK_RESTORE(pos_address);
  ------------------
  |  |   82|  1.47k|#define PEEK_RESTORE POKE_RESTORE
  |  |  ------------------
  |  |  |  |   48|  1.47k|	do {                                       \
  |  |  |  |   49|  1.47k|		if ((where) > pos)                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (49:7): [True: 0, False: 1.47k]
  |  |  |  |  ------------------
  |  |  |  |   50|  1.47k|			length -= ((where) - pos); \
  |  |  |  |   51|  1.47k|		else                               \
  |  |  |  |   52|  1.47k|			length += (pos - (where)); \
  |  |  |  |   53|  1.47k|		pos = (where);                     \
  |  |  |  |   54|  1.47k|	} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (54:11): [Folded, False: 1.47k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  475|  1.47k|				if ((PEEK_UINT8 == 1) && (PEEK_UINT8 == 1) &&
  ------------------
  |  |   62|  1.47k|#define PEEK_UINT8 PEEK(types.f_uint8, )
  |  |  ------------------
  |  |  |  |   60|  1.47k|	(memcpy(&type, pos, sizeof(type)), length -= sizeof(type), \
  |  |  |  |   61|  1.47k|	    pos += sizeof(type), func(type))
  |  |  ------------------
  ------------------
              				if ((PEEK_UINT8 == 1) && (PEEK_UINT8 == 1) &&
  ------------------
  |  |   62|  1.04k|#define PEEK_UINT8 PEEK(types.f_uint8, )
  |  |  ------------------
  |  |  |  |   60|  1.04k|	(memcpy(&type, pos, sizeof(type)), length -= sizeof(type), \
  |  |  |  |   61|  1.04k|	    pos += sizeof(type), func(type))
  |  |  ------------------
  ------------------
  |  Branch (475:9): [True: 1.04k, False: 428]
  |  Branch (475:30): [True: 802, False: 244]
  ------------------
  476|    802|				    (PEEK_UINT8 == CDP_ADDRESS_PROTO_IP) &&
  ------------------
  |  |   62|    802|#define PEEK_UINT8 PEEK(types.f_uint8, )
  |  |  ------------------
  |  |  |  |   60|    802|	(memcpy(&type, pos, sizeof(type)), length -= sizeof(type), \
  |  |  |  |   61|    802|	    pos += sizeof(type), func(type))
  |  |  ------------------
  ------------------
              				    (PEEK_UINT8 == CDP_ADDRESS_PROTO_IP) &&
  ------------------
  |  |   56|    802|#define CDP_ADDRESS_PROTO_IP 0xcc
  ------------------
  |  Branch (476:9): [True: 511, False: 291]
  ------------------
  477|    511|				    (PEEK_UINT16 == sizeof(struct in_addr))) {
  ------------------
  |  |   63|    511|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  ------------------
  |  |  |  |   60|    511|	(memcpy(&type, pos, sizeof(type)), length -= sizeof(type), \
  |  |  |  |   61|    511|	    pos += sizeof(type), func(type))
  |  |  |  |  ------------------
  |  |  |  |  |  |   63|    511|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (477:9): [True: 132, False: 379]
  ------------------
  478|    132|					PEEK_BYTES(&addr, sizeof(struct in_addr));
  ------------------
  |  |   66|    132|	do {                               \
  |  |   67|    132|		memcpy(value, pos, bytes); \
  |  |   68|    132|		length -= (bytes);         \
  |  |   69|    132|		pos += (bytes);            \
  |  |   70|    132|	} while (0)
  |  |  ------------------
  |  |  |  Branch (70:11): [Folded, False: 132]
  |  |  ------------------
  ------------------
  479|    132|					mgmt = lldpd_alloc_mgmt(LLDPD_AF_IPV4, &addr,
  480|    132|					    sizeof(struct in_addr), 0);
  481|    132|					if (mgmt == NULL) {
  ------------------
  |  Branch (481:10): [True: 0, False: 132]
  ------------------
  482|      0|						if (errno == ENOMEM)
  ------------------
  |  Branch (482:11): [True: 0, False: 0]
  ------------------
  483|      0|							log_warn("cdp",
  484|      0|							    "unable to allocate memory for management address");
  485|      0|						else
  486|      0|							log_warn("cdp",
  487|      0|							    "too large management address received on %s",
  488|      0|							    hardware->h_ifname);
  489|      0|						goto malformed;
  490|      0|					}
  491|    132|					TAILQ_INSERT_TAIL(&chassis->c_mgmt, mgmt,
  ------------------
  |  Branch (491:6): [Folded, False: 132]
  ------------------
  492|    132|					    m_entries);
  493|    132|				}
  494|       |				/* Go to the end of the address */
  495|  1.47k|				PEEK_RESTORE(pos_next_address);
  ------------------
  |  |   82|  1.47k|#define PEEK_RESTORE POKE_RESTORE
  |  |  ------------------
  |  |  |  |   48|  1.47k|	do {                                       \
  |  |  |  |   49|  1.47k|		if ((where) > pos)                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (49:7): [True: 983, False: 491]
  |  |  |  |  ------------------
  |  |  |  |   50|  1.47k|			length -= ((where) - pos); \
  |  |  |  |   51|  1.47k|		else                               \
  |  |  |  |   52|  1.47k|			length += (pos - (where)); \
  |  |  |  |   53|  1.47k|		pos = (where);                     \
  |  |  |  |   54|  1.47k|	} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (54:11): [Folded, False: 1.47k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  496|  1.47k|			}
  497|    403|			break;
  498|    403|		case CDP_TLV_PORT:
  ------------------
  |  Branch (498:3): [True: 318, False: 4.83k]
  ------------------
  499|    318|			if (tlv_len == 0) {
  ------------------
  |  Branch (499:8): [True: 1, False: 317]
  ------------------
  500|      1|				log_warn("cdp", "too short port description received");
  501|      1|				goto malformed;
  502|      1|			}
  503|    317|			free(port->p_descr);
  504|    317|			if ((port->p_descr = (char *)calloc(1, tlv_len + 1)) == NULL) {
  ------------------
  |  Branch (504:8): [True: 0, False: 317]
  ------------------
  505|      0|				log_warn("cdp",
  506|      0|				    "unable to allocate memory for port description");
  507|      0|				goto malformed;
  508|      0|			}
  509|    317|			PEEK_BYTES(port->p_descr, tlv_len);
  ------------------
  |  |   66|    317|	do {                               \
  |  |   67|    317|		memcpy(value, pos, bytes); \
  |  |   68|    317|		length -= (bytes);         \
  |  |   69|    317|		pos += (bytes);            \
  |  |   70|    317|	} while (0)
  |  |  ------------------
  |  |  |  Branch (70:11): [Folded, False: 317]
  |  |  ------------------
  ------------------
  510|    317|			port->p_id_subtype = LLDP_PORTID_SUBTYPE_IFNAME;
  ------------------
  |  |   45|    317|#define LLDP_PORTID_SUBTYPE_IFNAME 5
  ------------------
  511|    317|			free(port->p_id);
  512|    317|			if ((port->p_id = (char *)calloc(1, tlv_len)) == NULL) {
  ------------------
  |  Branch (512:8): [True: 0, False: 317]
  ------------------
  513|      0|				log_warn("cdp",
  514|      0|				    "unable to allocate memory for port ID");
  515|      0|				goto malformed;
  516|      0|			}
  517|    317|			memcpy(port->p_id, port->p_descr, tlv_len);
  518|    317|			port->p_id_len = tlv_len;
  519|    317|			break;
  520|    896|		case CDP_TLV_CAPABILITIES:
  ------------------
  |  Branch (520:3): [True: 896, False: 4.25k]
  ------------------
  521|    896|#  ifdef ENABLE_FDP
  522|    896|			if (fdp) {
  ------------------
  |  Branch (522:8): [True: 0, False: 896]
  ------------------
  523|       |				/* Capabilities are string with FDP */
  524|      0|				if (!strncmp("Router", (char *)pos, tlv_len))
  ------------------
  |  Branch (524:9): [True: 0, False: 0]
  ------------------
  525|      0|					chassis->c_cap_enabled = LLDP_CAP_ROUTER;
  ------------------
  |  |  260|      0|#define LLDP_CAP_ROUTER 0x10
  ------------------
  526|      0|				else if (!strncmp("Switch", (char *)pos, tlv_len))
  ------------------
  |  Branch (526:14): [True: 0, False: 0]
  ------------------
  527|      0|					chassis->c_cap_enabled = LLDP_CAP_BRIDGE;
  ------------------
  |  |  258|      0|#define LLDP_CAP_BRIDGE 0x04
  ------------------
  528|      0|				else if (!strncmp("Bridge", (char *)pos, tlv_len))
  ------------------
  |  Branch (528:14): [True: 0, False: 0]
  ------------------
  529|      0|					chassis->c_cap_enabled = LLDP_CAP_REPEATER;
  ------------------
  |  |  257|      0|#define LLDP_CAP_REPEATER 0x02
  ------------------
  530|      0|				else
  531|      0|					chassis->c_cap_enabled = LLDP_CAP_STATION;
  ------------------
  |  |  263|      0|#define LLDP_CAP_STATION 0x80
  ------------------
  532|      0|				chassis->c_cap_available = chassis->c_cap_enabled;
  533|      0|				break;
  534|      0|			}
  535|    896|#  endif
  536|    896|			CHECK_TLV_SIZE(4, "Capabilities");
  ------------------
  |  |  271|    896|	  do {                                                              \
  |  |  272|    896|		  if (tlv_len < (x)) {                                      \
  |  |  ------------------
  |  |  |  Branch (272:9): [True: 4, False: 892]
  |  |  ------------------
  |  |  273|      4|			  log_warnx("cdp",                                  \
  |  |  274|      4|			      name " CDP/FDP TLV too short received on %s", \
  |  |  275|      4|			      hardware->h_ifname);                          \
  |  |  276|      4|			  goto malformed;                                   \
  |  |  277|      4|		  }                                                         \
  |  |  278|    896|	  } while (0)
  |  |  ------------------
  |  |  |  Branch (278:13): [Folded, False: 892]
  |  |  ------------------
  ------------------
  537|    892|			caps = PEEK_UINT32;
  ------------------
  |  |   64|    892|#define PEEK_UINT32 PEEK(types.f_uint32, ntohl)
  |  |  ------------------
  |  |  |  |   60|    892|	(memcpy(&type, pos, sizeof(type)), length -= sizeof(type), \
  |  |  |  |   61|    892|	    pos += sizeof(type), func(type))
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|    892|#define PEEK_UINT32 PEEK(types.f_uint32, ntohl)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  538|    892|			if (caps & CDP_CAP_ROUTER)
  ------------------
  |  |   58|    892|#define CDP_CAP_ROUTER 0x01
  ------------------
  |  Branch (538:8): [True: 393, False: 499]
  ------------------
  539|    393|				chassis->c_cap_enabled |= LLDP_CAP_ROUTER;
  ------------------
  |  |  260|    393|#define LLDP_CAP_ROUTER 0x10
  ------------------
  540|    892|			if (caps & 0x0e) chassis->c_cap_enabled |= LLDP_CAP_BRIDGE;
  ------------------
  |  |  258|    450|#define LLDP_CAP_BRIDGE 0x04
  ------------------
  |  Branch (540:8): [True: 450, False: 442]
  ------------------
  541|    892|			if (chassis->c_cap_enabled == 0)
  ------------------
  |  Branch (541:8): [True: 41, False: 851]
  ------------------
  542|     41|				chassis->c_cap_enabled = LLDP_CAP_STATION;
  ------------------
  |  |  263|     41|#define LLDP_CAP_STATION 0x80
  ------------------
  543|    892|			chassis->c_cap_available = chassis->c_cap_enabled;
  544|    892|			break;
  545|    385|		case CDP_TLV_SOFTWARE:
  ------------------
  |  Branch (545:3): [True: 385, False: 4.77k]
  ------------------
  546|    385|			software_len = tlv_len;
  547|    385|			(void)PEEK_SAVE(software);
  ------------------
  |  |   81|    385|#define PEEK_SAVE POKE_SAVE
  |  |  ------------------
  |  |  |  |   46|    385|#define POKE_SAVE(where) (where = pos, 1)
  |  |  ------------------
  ------------------
  548|    385|			break;
  549|    464|		case CDP_TLV_PLATFORM:
  ------------------
  |  Branch (549:3): [True: 464, False: 4.69k]
  ------------------
  550|    464|			platform_len = tlv_len;
  551|    464|			(void)PEEK_SAVE(platform);
  ------------------
  |  |   81|    464|#define PEEK_SAVE POKE_SAVE
  |  |  ------------------
  |  |  |  |   46|    464|#define POKE_SAVE(where) (where = pos, 1)
  |  |  ------------------
  ------------------
  552|    464|			break;
  553|      0|#  ifdef ENABLE_DOT1
  554|    341|		case CDP_TLV_NATIVEVLAN:
  ------------------
  |  Branch (554:3): [True: 341, False: 4.81k]
  ------------------
  555|    341|			CHECK_TLV_SIZE(2, "Native VLAN");
  ------------------
  |  |  271|    341|	  do {                                                              \
  |  |  272|    341|		  if (tlv_len < (x)) {                                      \
  |  |  ------------------
  |  |  |  Branch (272:9): [True: 2, False: 339]
  |  |  ------------------
  |  |  273|      2|			  log_warnx("cdp",                                  \
  |  |  274|      2|			      name " CDP/FDP TLV too short received on %s", \
  |  |  275|      2|			      hardware->h_ifname);                          \
  |  |  276|      2|			  goto malformed;                                   \
  |  |  277|      2|		  }                                                         \
  |  |  278|    341|	  } while (0)
  |  |  ------------------
  |  |  |  Branch (278:13): [Folded, False: 339]
  |  |  ------------------
  ------------------
  556|    339|			if ((vlan = (struct lldpd_vlan *)calloc(1,
  ------------------
  |  Branch (556:8): [True: 0, False: 339]
  ------------------
  557|    339|				 sizeof(struct lldpd_vlan))) == NULL) {
  558|      0|				log_warn("cdp",
  559|      0|				    "unable to alloc vlan "
  560|      0|				    "structure for "
  561|      0|				    "tlv received on %s",
  562|      0|				    hardware->h_ifname);
  563|      0|				goto malformed;
  564|      0|			}
  565|    339|			vlan->v_vid = port->p_pvid = PEEK_UINT16;
  ------------------
  |  |   63|    339|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  ------------------
  |  |  |  |   60|    339|	(memcpy(&type, pos, sizeof(type)), length -= sizeof(type), \
  |  |  |  |   61|    339|	    pos += sizeof(type), func(type))
  |  |  |  |  ------------------
  |  |  |  |  |  |   63|    339|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  566|    339|			if (asprintf(&vlan->v_name, "VLAN #%d", vlan->v_vid) == -1) {
  ------------------
  |  Branch (566:8): [True: 0, False: 339]
  ------------------
  567|      0|				log_warn("cdp",
  568|      0|				    "unable to alloc VLAN name for "
  569|      0|				    "TLV received on %s",
  570|      0|				    hardware->h_ifname);
  571|      0|				free(vlan);
  572|      0|				goto malformed;
  573|      0|			}
  574|    339|			TAILQ_INSERT_TAIL(&port->p_vlans, vlan, v_entries);
  ------------------
  |  Branch (574:4): [Folded, False: 339]
  ------------------
  575|    339|			break;
  576|      0|#  endif
  577|      0|#  ifdef ENABLE_DOT3
  578|    389|		case CDP_TLV_POWER_AVAILABLE:
  ------------------
  |  Branch (578:3): [True: 389, False: 4.76k]
  ------------------
  579|    389|			CHECK_TLV_SIZE(12, "Power Available");
  ------------------
  |  |  271|    389|	  do {                                                              \
  |  |  272|    389|		  if (tlv_len < (x)) {                                      \
  |  |  ------------------
  |  |  |  Branch (272:9): [True: 5, False: 384]
  |  |  ------------------
  |  |  273|      5|			  log_warnx("cdp",                                  \
  |  |  274|      5|			      name " CDP/FDP TLV too short received on %s", \
  |  |  275|      5|			      hardware->h_ifname);                          \
  |  |  276|      5|			  goto malformed;                                   \
  |  |  277|      5|		  }                                                         \
  |  |  278|    389|	  } while (0)
  |  |  ------------------
  |  |  |  Branch (278:13): [Folded, False: 384]
  |  |  ------------------
  ------------------
  580|       |			/* check if it is a respone to a request id */
  581|    384|			if (PEEK_UINT16 > 0) {
  ------------------
  |  |   63|    384|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  ------------------
  |  |  |  |   60|    384|	(memcpy(&type, pos, sizeof(type)), length -= sizeof(type), \
  |  |  |  |   61|    384|	    pos += sizeof(type), func(type))
  |  |  |  |  ------------------
  |  |  |  |  |  |   63|    384|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (581:8): [True: 295, False: 89]
  ------------------
  582|    295|				port->p_cdp_power.management_id = PEEK_UINT16;
  ------------------
  |  |   63|    295|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  ------------------
  |  |  |  |   60|    295|	(memcpy(&type, pos, sizeof(type)), length -= sizeof(type), \
  |  |  |  |   61|    295|	    pos += sizeof(type), func(type))
  |  |  |  |  ------------------
  |  |  |  |  |  |   63|    295|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  583|    295|				port->p_power.allocated = PEEK_UINT32;
  ------------------
  |  |   64|    295|#define PEEK_UINT32 PEEK(types.f_uint32, ntohl)
  |  |  ------------------
  |  |  |  |   60|    295|	(memcpy(&type, pos, sizeof(type)), length -= sizeof(type), \
  |  |  |  |   61|    295|	    pos += sizeof(type), func(type))
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|    295|#define PEEK_UINT32 PEEK(types.f_uint32, ntohl)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  584|    295|				port->p_power.allocated /= 100;
  585|    295|				port->p_power.supported = 1;
  586|    295|				port->p_power.enabled = 1;
  587|    295|				port->p_power.devicetype = LLDP_DOT3_POWER_PSE;
  ------------------
  |  |  204|    295|#define LLDP_DOT3_POWER_PSE 1
  ------------------
  588|    295|				port->p_power.powertype = LLDP_DOT3_POWER_8023AT_TYPE2;
  ------------------
  |  |  214|    295|#define LLDP_DOT3_POWER_8023AT_TYPE2 2
  ------------------
  589|    295|				log_debug("cdp", "Allocated power %d00",
  590|    295|				    port->p_power.allocated);
  591|    295|				if (port->p_power.allocated > CDP_CLASS_3_MAX_PSE_POE) {
  ------------------
  |  |   27|    295|#define CDP_CLASS_3_MAX_PSE_POE 154	 /* 15.4W Max PoE at PSE class 3 */
  ------------------
  |  Branch (591:9): [True: 86, False: 209]
  ------------------
  592|     86|					port->p_power.allocated -=
  593|     86|					    CDP_SWITCH_POE_CLASS_4_OFFSET;
  ------------------
  |  |   30|     86|#define CDP_SWITCH_POE_CLASS_4_OFFSET 45 /* 4.5W  max loss from cable */
  ------------------
  594|    209|				} else if (port->p_power.allocated >
  ------------------
  |  Branch (594:16): [True: 101, False: 108]
  ------------------
  595|    209|				    CDP_SWITCH_POE_CLASS_3_OFFSET) {
  ------------------
  |  |   31|    209|#define CDP_SWITCH_POE_CLASS_3_OFFSET 24 /* 2.4W  max loss from cable */
  ------------------
  596|    101|					port->p_power.allocated -=
  597|    101|					    CDP_SWITCH_POE_CLASS_3_OFFSET;
  ------------------
  |  |   31|    101|#define CDP_SWITCH_POE_CLASS_3_OFFSET 24 /* 2.4W  max loss from cable */
  ------------------
  598|    108|				} else {
  599|    108|					port->p_power.allocated = 0;
  600|    108|				}
  601|    295|				port->p_power.requested =
  602|    295|				    hardware->h_lport.p_power.requested;
  603|    295|			}
  604|    384|			break;
  605|      0|#  endif
  606|  1.42k|		default:
  ------------------
  |  Branch (606:3): [True: 1.42k, False: 3.72k]
  ------------------
  607|  1.42k|			log_debug("cdp", "unknown CDP/FDP TLV type (%d) received on %s",
  608|  1.42k|			    ntohs(tlv_type), hardware->h_ifname);
  609|  1.42k|			hardware->h_rx_unrecognized_cnt++;
  610|  5.15k|		}
  611|  5.01k|		PEEK_DISCARD(tlv + tlv_len - pos);
  ------------------
  |  |   72|  5.01k|	do {                       \
  |  |   73|  5.01k|		length -= (bytes); \
  |  |   74|  5.01k|		pos += (bytes);    \
  |  |   75|  5.01k|	} while (0)
  |  |  ------------------
  |  |  |  Branch (75:11): [Folded, False: 5.01k]
  |  |  ------------------
  ------------------
  612|  5.01k|	}
  613|    256|	if (!software && platform) {
  ------------------
  |  Branch (613:6): [True: 217, False: 39]
  |  Branch (613:19): [True: 70, False: 147]
  ------------------
  614|     70|		if ((chassis->c_descr = (char *)calloc(1, platform_len + 1)) == NULL) {
  ------------------
  |  Branch (614:7): [True: 0, False: 70]
  ------------------
  615|      0|			log_warn("cdp",
  616|      0|			    "unable to allocate memory for chassis description");
  617|      0|			goto malformed;
  618|      0|		}
  619|     70|		memcpy(chassis->c_descr, platform, platform_len);
  620|    186|	} else if (software && !platform) {
  ------------------
  |  Branch (620:13): [True: 39, False: 147]
  |  Branch (620:25): [True: 25, False: 14]
  ------------------
  621|     25|		if ((chassis->c_descr = (char *)calloc(1, software_len + 1)) == NULL) {
  ------------------
  |  Branch (621:7): [True: 0, False: 25]
  ------------------
  622|      0|			log_warn("cdp",
  623|      0|			    "unable to allocate memory for chassis description");
  624|      0|			goto malformed;
  625|      0|		}
  626|     25|		memcpy(chassis->c_descr, software, software_len);
  627|    161|	} else if (software && platform) {
  ------------------
  |  Branch (627:13): [True: 14, False: 147]
  |  Branch (627:25): [True: 14, False: 0]
  ------------------
  628|     14|#  define CONCAT_PLATFORM " running on\n"
  629|     14|		if ((chassis->c_descr = (char *)calloc(1,
  ------------------
  |  Branch (629:7): [True: 0, False: 14]
  ------------------
  630|     14|			 software_len + platform_len + strlen(CONCAT_PLATFORM) + 1)) ==
  ------------------
  |  |  628|     14|#  define CONCAT_PLATFORM " running on\n"
  ------------------
  631|     14|		    NULL) {
  632|      0|			log_warn("cdp",
  633|      0|			    "unable to allocate memory for chassis description");
  634|      0|			goto malformed;
  635|      0|		}
  636|     14|		memcpy(chassis->c_descr, platform, platform_len);
  637|     14|		memcpy(chassis->c_descr + platform_len, CONCAT_PLATFORM,
  ------------------
  |  |  628|     14|#  define CONCAT_PLATFORM " running on\n"
  ------------------
  638|     14|		    strlen(CONCAT_PLATFORM));
  ------------------
  |  |  628|     14|#  define CONCAT_PLATFORM " running on\n"
  ------------------
  639|     14|		memcpy(chassis->c_descr + platform_len + strlen(CONCAT_PLATFORM),
  ------------------
  |  |  628|     14|#  define CONCAT_PLATFORM " running on\n"
  ------------------
  640|     14|		    software, software_len);
  641|     14|	}
  642|    256|	if ((chassis->c_id == NULL) || (port->p_id == NULL) ||
  ------------------
  |  Branch (642:6): [True: 141, False: 115]
  |  Branch (642:33): [True: 22, False: 93]
  ------------------
  643|     93|	    (chassis->c_name == NULL) || (chassis->c_descr == NULL) ||
  ------------------
  |  Branch (643:6): [True: 0, False: 93]
  |  Branch (643:35): [True: 4, False: 89]
  ------------------
  644|     89|	    (port->p_descr == NULL) || (port->p_ttl == 0) ||
  ------------------
  |  Branch (644:6): [True: 0, False: 89]
  |  Branch (644:33): [True: 2, False: 87]
  ------------------
  645|    181|	    (chassis->c_cap_enabled == 0)) {
  ------------------
  |  Branch (645:6): [True: 12, False: 75]
  ------------------
  646|    181|		log_warnx("cdp",
  647|    181|		    "some mandatory CDP/FDP tlv are missing for frame received on %s",
  648|    181|		    hardware->h_ifname);
  649|    181|		goto malformed;
  650|    181|	}
  651|     75|	*newchassis = chassis;
  652|     75|	*newport = port;
  653|     75|	return 1;
  654|       |
  655|    493|malformed:
  656|    493|	lldpd_chassis_cleanup(chassis, 1);
  657|    493|	lldpd_port_cleanup(port, 1);
  658|    493|	free(port);
  659|    493|	return -1;
  660|    256|}
cdpv2_guess:
  707|    637|{
  708|    637|	return cdp_guess(frame, len, 2);
  709|    637|}
cdp.c:cdp_guess:
  687|    637|{
  688|    637|	const u_int8_t mcastaddr[] = CDP_MULTICAST_ADDR;
  ------------------
  |  |   21|    637|#define CDP_MULTICAST_ADDR { 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc }
  ------------------
  689|    637|	if (length < 2 * ETHER_ADDR_LEN + sizeof(u_int16_t) /* Ethernet */ +
  ------------------
  |  Branch (689:6): [True: 10, False: 627]
  ------------------
  690|    637|		8 /* LLC */ + 4 /* CDP header */)
  691|     10|		return 0;
  692|    627|	if (PEEK_CMP(mcastaddr, ETHER_ADDR_LEN) != 0) return 0;
  ------------------
  |  |   80|    627|	(length -= (bytes), pos += (bytes), memcmp(pos - bytes, value, bytes))
  ------------------
  |  Branch (692:6): [True: 49, False: 578]
  ------------------
  693|    578|	PEEK_DISCARD(ETHER_ADDR_LEN);
  ------------------
  |  |   72|    578|	do {                       \
  |  |   73|    578|		length -= (bytes); \
  |  |   74|    578|		pos += (bytes);    \
  |  |   75|    578|	} while (0)
  |  |  ------------------
  |  |  |  Branch (75:11): [Folded, False: 578]
  |  |  ------------------
  ------------------
  694|    578|	PEEK_DISCARD_UINT16; /* Ethernet */
  ------------------
  |  |   77|    578|#define PEEK_DISCARD_UINT16 PEEK_DISCARD(2)
  |  |  ------------------
  |  |  |  |   72|    578|	do {                       \
  |  |  |  |   73|    578|		length -= (bytes); \
  |  |  |  |   74|    578|		pos += (bytes);    \
  |  |  |  |   75|    578|	} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (75:11): [Folded, False: 578]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  695|    578|	PEEK_DISCARD(8);     /* LLC */
  ------------------
  |  |   72|    578|	do {                       \
  |  |   73|    578|		length -= (bytes); \
  |  |   74|    578|		pos += (bytes);    \
  |  |   75|    578|	} while (0)
  |  |  ------------------
  |  |  |  Branch (75:11): [Folded, False: 578]
  |  |  ------------------
  ------------------
  696|    578|	return (PEEK_UINT8 == version);
  ------------------
  |  |   62|    578|#define PEEK_UINT8 PEEK(types.f_uint8, )
  |  |  ------------------
  |  |  |  |   60|    578|	(memcpy(&type, pos, sizeof(type)), length -= sizeof(type), \
  |  |  |  |   61|    578|	    pos += sizeof(type), func(type))
  |  |  ------------------
  ------------------
  697|    627|}

lldpd_chassis_mgmt_cleanup:
   26|    568|{
   27|    568|	struct lldpd_mgmt *mgmt, *mgmt_next;
   28|       |
   29|    568|	log_debug("alloc", "cleanup management addresses for chassis %s",
   30|    568|	    chassis->c_name ? chassis->c_name : "(unknown)");
  ------------------
  |  Branch (30:6): [True: 124, False: 444]
  ------------------
   31|       |
   32|    700|	for (mgmt = TAILQ_FIRST(&chassis->c_mgmt); mgmt != NULL; mgmt = mgmt_next) {
  ------------------
  |  Branch (32:45): [True: 132, False: 568]
  ------------------
   33|    132|		mgmt_next = TAILQ_NEXT(mgmt, m_entries);
   34|    132|		free(mgmt);
   35|    132|	}
   36|       |	TAILQ_INIT(&chassis->c_mgmt);
  ------------------
  |  Branch (36:2): [Folded, False: 568]
  ------------------
   37|    568|}
lldpd_chassis_cleanup:
   41|    568|{
   42|    568|	lldpd_chassis_mgmt_cleanup(chassis);
   43|    568|	log_debug("alloc", "cleanup chassis %s",
   44|    568|	    chassis->c_name ? chassis->c_name : "(unknown)");
  ------------------
  |  Branch (44:6): [True: 124, False: 444]
  ------------------
   45|    568|#ifdef ENABLE_LLDPMED
   46|    568|	free(chassis->c_med_hw);
   47|    568|	free(chassis->c_med_sw);
   48|    568|	free(chassis->c_med_fw);
   49|    568|	free(chassis->c_med_sn);
   50|    568|	free(chassis->c_med_manuf);
   51|    568|	free(chassis->c_med_model);
   52|    568|	free(chassis->c_med_asset);
   53|    568|#endif
   54|    568|	free(chassis->c_id);
   55|    568|	free(chassis->c_name);
   56|    568|	free(chassis->c_descr);
   57|    568|	if (all) free(chassis);
  ------------------
  |  Branch (57:6): [True: 568, False: 0]
  ------------------
   58|    568|}
lldpd_vlan_cleanup:
   63|    568|{
   64|    568|	struct lldpd_vlan *vlan, *vlan_next;
   65|    907|	for (vlan = TAILQ_FIRST(&port->p_vlans); vlan != NULL; vlan = vlan_next) {
  ------------------
  |  Branch (65:43): [True: 339, False: 568]
  ------------------
   66|    339|		free(vlan->v_name);
   67|    339|		vlan_next = TAILQ_NEXT(vlan, v_entries);
   68|    339|		free(vlan);
   69|    339|	}
   70|       |	TAILQ_INIT(&port->p_vlans);
  ------------------
  |  Branch (70:2): [Folded, False: 568]
  ------------------
   71|    568|	port->p_pvid = 0;
   72|    568|}
lldpd_ppvid_cleanup:
   76|    568|{
   77|    568|	struct lldpd_ppvid *ppvid, *ppvid_next;
   78|    568|	for (ppvid = TAILQ_FIRST(&port->p_ppvids); ppvid != NULL; ppvid = ppvid_next) {
  ------------------
  |  Branch (78:45): [True: 0, False: 568]
  ------------------
   79|      0|		ppvid_next = TAILQ_NEXT(ppvid, p_entries);
   80|      0|		free(ppvid);
   81|      0|	}
   82|       |	TAILQ_INIT(&port->p_ppvids);
  ------------------
  |  Branch (82:2): [Folded, False: 568]
  ------------------
   83|    568|}
lldpd_pi_cleanup:
   87|    568|{
   88|    568|	struct lldpd_pi *pi, *pi_next;
   89|    568|	for (pi = TAILQ_FIRST(&port->p_pids); pi != NULL; pi = pi_next) {
  ------------------
  |  Branch (89:40): [True: 0, False: 568]
  ------------------
   90|      0|		free(pi->p_pi);
   91|      0|		pi_next = TAILQ_NEXT(pi, p_entries);
   92|      0|		free(pi);
   93|      0|	}
   94|       |	TAILQ_INIT(&port->p_pids);
  ------------------
  |  Branch (94:2): [Folded, False: 568]
  ------------------
   95|    568|}
lldpd_custom_list_cleanup:
  141|    568|{
  142|    568|	struct lldpd_custom *custom, *custom_next;
  143|    568|	for (custom = TAILQ_FIRST(&port->p_custom_list); custom != NULL;
  ------------------
  |  Branch (143:51): [True: 0, False: 568]
  ------------------
  144|    568|	    custom = custom_next) {
  145|      0|		custom_next = TAILQ_NEXT(custom, next);
  146|      0|		free(custom->oui_info);
  147|      0|		free(custom);
  148|      0|	}
  149|       |	TAILQ_INIT(&port->p_custom_list);
  ------------------
  |  Branch (149:2): [Folded, False: 568]
  ------------------
  150|    568|}
lldpd_port_cleanup:
  196|    568|{
  197|    568|#ifdef ENABLE_LLDPMED
  198|    568|	int i;
  199|    568|	if (all)
  ------------------
  |  Branch (199:6): [True: 568, False: 0]
  ------------------
  200|  2.27k|		for (i = 0; i < LLDP_MED_LOCFORMAT_LAST; i++)
  ------------------
  |  |  301|  2.27k|#define LLDP_MED_LOCFORMAT_LAST LLDP_MED_LOCFORMAT_ELIN
  |  |  ------------------
  |  |  |  |  300|  2.27k|#define LLDP_MED_LOCFORMAT_ELIN 3
  |  |  ------------------
  ------------------
  |  Branch (200:15): [True: 1.70k, False: 568]
  ------------------
  201|  1.70k|			free(port->p_med_location[i].data);
  202|    568|#endif
  203|    568|#ifdef ENABLE_DOT1
  204|    568|	lldpd_vlan_cleanup(port);
  205|    568|	lldpd_ppvid_cleanup(port);
  206|    568|	lldpd_pi_cleanup(port);
  207|    568|#endif
  208|       |	/* will set these to NULL so we don't free wrong memory */
  209|       |
  210|    568|	if (all) {
  ------------------
  |  Branch (210:6): [True: 568, False: 0]
  ------------------
  211|    568|		free(port->p_id);
  212|    568|		port->p_id = NULL;
  213|    568|		free(port->p_descr);
  214|    568|		port->p_descr = NULL;
  215|    568|		free(port->p_lastframe);
  216|    568|		if (port->p_chassis) { /* chassis may not have been attributed, yet */
  ------------------
  |  Branch (216:7): [True: 0, False: 568]
  ------------------
  217|      0|			port->p_chassis->c_refcount--;
  218|      0|			port->p_chassis = NULL;
  219|      0|		}
  220|    568|		free(port->p_vlan_advertise_pattern);
  221|       |		port->p_vlan_advertise_pattern = NULL;
  222|    568|#ifdef ENABLE_CUSTOM
  223|    568|		lldpd_custom_list_cleanup(port);
  224|    568|#endif
  225|    568|	}
  226|    568|}

log_register:
   64|    637|{
   65|    637|	logh = cb;
   66|    637|}
log_warn:
  190|    125|{
  191|    125|	char *nfmt = NULL;
  192|    125|	va_list ap;
  193|       |
  194|       |	/* best effort to even work in out of memory situations */
  195|    125|	if (emsg == NULL)
  ------------------
  |  Branch (195:6): [True: 0, False: 125]
  ------------------
  196|      0|		logit(LOG_WARNING, "%s", strerror(errno));
  197|    125|	else {
  198|    125|		va_start(ap, emsg);
  199|       |
  200|    125|		if (asprintf(&nfmt, "%s: %s", emsg, strerror(errno)) == -1) {
  ------------------
  |  Branch (200:7): [True: 0, False: 125]
  ------------------
  201|       |			/* we tried it... */
  202|      0|			vlog(LOG_WARNING, token, emsg, ap);
  203|      0|			logit(LOG_WARNING, "%s", strerror(errno));
  204|    125|		} else {
  205|    125|			vlog(LOG_WARNING, token, nfmt, ap);
  206|    125|			free(nfmt);
  207|    125|		}
  208|       |		va_end(ap);
  209|    125|	}
  210|    125|}
log_warnx:
  214|    275|{
  215|    275|	va_list ap;
  216|       |
  217|    275|	va_start(ap, emsg);
  218|    275|	vlog(LOG_WARNING, token, emsg, ap);
  219|       |	va_end(ap);
  220|    275|}
log_debug:
  247|  3.63k|{
  248|  3.63k|	va_list ap;
  249|       |
  250|  3.63k|	if ((debug > 1 && log_debug_accept_token(token)) || logh) {
  ------------------
  |  Branch (250:7): [True: 0, False: 3.63k]
  |  Branch (250:20): [True: 0, False: 0]
  |  Branch (250:54): [True: 3.63k, False: 0]
  ------------------
  251|  3.63k|		va_start(ap, emsg);
  252|  3.63k|		vlog(LOG_DEBUG, token, emsg, ap);
  253|       |		va_end(ap);
  254|  3.63k|	}
  255|  3.63k|}
log.c:vlog:
  154|  4.03k|{
  155|  4.03k|	if (logh) {
  ------------------
  |  Branch (155:6): [True: 4.03k, False: 0]
  ------------------
  156|  4.03k|		char *result = NULL;
  157|  4.03k|		if (vasprintf(&result, fmt, ap) != -1) {
  ------------------
  |  Branch (157:7): [True: 4.03k, False: 0]
  ------------------
  158|  4.03k|			logh(pri, result);
  159|  4.03k|			free(result);
  160|  4.03k|			return;
  161|  4.03k|		}
  162|       |		/* Otherwise, abort. We don't know if "ap" is still OK. We could
  163|       |		 * have made a copy, but this is too much overhead for a
  164|       |		 * situation that shouldn't happen. */
  165|      0|		return;
  166|  4.03k|	}
  167|       |
  168|       |	/* Log to syslog if requested */
  169|      0|	if (use_syslog) {
  ------------------
  |  Branch (169:6): [True: 0, False: 0]
  ------------------
  170|      0|		va_list ap2;
  171|      0|		va_copy(ap2, ap);
  172|      0|		vsyslog(pri, fmt, ap2);
  173|      0|		va_end(ap2);
  174|      0|	}
  175|       |
  176|       |	/* Log to standard error in all cases. Format the caller's message
  177|       |	 * first so it is not re-interpreted as a format string by the
  178|       |	 * surrounding fprintf. */
  179|      0|	char *body = NULL;
  180|      0|	if (vasprintf(&body, fmt, ap) == -1) body = NULL;
  ------------------
  |  Branch (180:6): [True: 0, False: 0]
  ------------------
  181|      0|	fprintf(stderr, "%s %s%s%s]%s %s\n", date(), translate(STDERR_FILENO, pri),
  182|      0|	    token ? "/" : "", token ? token : "",
  ------------------
  |  Branch (182:6): [True: 0, False: 0]
  |  Branch (182:24): [True: 0, False: 0]
  ------------------
  183|      0|	    isatty(STDERR_FILENO) ? "\033[0m" : "", body ? body : fmt);
  ------------------
  |  Branch (183:6): [True: 0, False: 0]
  |  Branch (183:46): [True: 0, False: 0]
  ------------------
  184|      0|	free(body);
  185|       |	fflush(stderr);
  186|      0|}

donothing:
   24|  4.03k|void donothing(int pri, const char *msg) { };
LLVMFuzzerTestOneInput:
   28|    662|{
   29|    662|	if (Size < kMinInputLength || Size > kMaxInputLength) {
  ------------------
  |  |   20|  1.32k|#define kMinInputLength 5
  ------------------
              	if (Size < kMinInputLength || Size > kMaxInputLength) {
  ------------------
  |  |   21|    658|#define kMaxInputLength 2048
  ------------------
  |  Branch (29:6): [True: 4, False: 658]
  |  Branch (29:32): [True: 21, False: 637]
  ------------------
   30|     25|		return 1;
   31|     25|	}
   32|       |
   33|    637|	struct lldpd_chassis *nchassis = NULL;
   34|    637|	struct lldpd_port *nport = NULL;
   35|    637|	struct lldpd_hardware hardware;
   36|       |
   37|    637|	log_register(donothing);
   38|       |
   39|    637|	if (!cdpv2_guess((char *)Data, Size)) {
  ------------------
  |  Branch (39:6): [True: 69, False: 568]
  ------------------
   40|     69|		return 1;
   41|     69|	}
   42|       |
   43|    568|	cdp_decode(NULL, (char *)Data, Size, &hardware, &nchassis, &nport);
   44|       |
   45|    568|	if (!nchassis || !nport) {
  ------------------
  |  Branch (45:6): [True: 493, False: 75]
  |  Branch (45:19): [True: 0, False: 75]
  ------------------
   46|    493|		return 1;
   47|    493|	}
   48|       |
   49|     75|	lldpd_port_cleanup(nport, 1);
   50|     75|	free(nport);
   51|     75|	lldpd_chassis_cleanup(nchassis, 1);
   52|       |
   53|     75|	return 0;
   54|    568|}

