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

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

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

log_register:
   64|    630|{
   65|    630|	logh = cb;
   66|    630|}
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|    270|{
  215|    270|	va_list ap;
  216|       |
  217|    270|	va_start(ap, emsg);
  218|    270|	vlog(LOG_WARNING, token, emsg, ap);
  219|       |	va_end(ap);
  220|    270|}
log_debug:
  247|  3.54k|{
  248|  3.54k|	va_list ap;
  249|       |
  250|  3.54k|	if ((debug > 1 && log_debug_accept_token(token)) || logh) {
  ------------------
  |  Branch (250:7): [True: 0, False: 3.54k]
  |  Branch (250:20): [True: 0, False: 0]
  |  Branch (250:54): [True: 3.54k, False: 0]
  ------------------
  251|  3.54k|		va_start(ap, emsg);
  252|  3.54k|		vlog(LOG_DEBUG, token, emsg, ap);
  253|       |		va_end(ap);
  254|  3.54k|	}
  255|  3.54k|}
log.c:vlog:
  154|  3.94k|{
  155|  3.94k|	if (logh) {
  ------------------
  |  Branch (155:6): [True: 3.94k, False: 0]
  ------------------
  156|  3.94k|		char *result = NULL;
  157|  3.94k|		if (vasprintf(&result, fmt, ap) != -1) {
  ------------------
  |  Branch (157:7): [True: 3.94k, False: 0]
  ------------------
  158|  3.94k|			logh(pri, result);
  159|  3.94k|			free(result);
  160|  3.94k|			return;
  161|  3.94k|		}
  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|  3.94k|	}
  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|  3.94k|void donothing(int pri, const char *msg) {};
LLVMFuzzerTestOneInput:
   28|    656|{
   29|    656|	if (Size < kMinInputLength || Size > kMaxInputLength) {
  ------------------
  |  |   20|  1.31k|#define kMinInputLength 5
  ------------------
              	if (Size < kMinInputLength || Size > kMaxInputLength) {
  ------------------
  |  |   21|    652|#define kMaxInputLength 2048
  ------------------
  |  Branch (29:6): [True: 4, False: 652]
  |  Branch (29:32): [True: 22, False: 630]
  ------------------
   30|     26|		return 1;
   31|     26|	}
   32|       |
   33|    630|	struct lldpd_chassis *nchassis = NULL;
   34|    630|	struct lldpd_port *nport = NULL;
   35|    630|	struct lldpd_hardware hardware;
   36|       |
   37|    630|	log_register(donothing);
   38|       |
   39|    630|	if (!cdpv2_guess((char *)Data, Size)) {
  ------------------
  |  Branch (39:6): [True: 66, False: 564]
  ------------------
   40|     66|		return 1;
   41|     66|	}
   42|       |
   43|    564|	cdp_decode(NULL, (char *)Data, Size, &hardware, &nchassis, &nport);
   44|       |
   45|    564|	if (!nchassis || !nport) {
  ------------------
  |  Branch (45:6): [True: 487, False: 77]
  |  Branch (45:19): [True: 0, False: 77]
  ------------------
   46|    487|		return 1;
   47|    487|	}
   48|       |
   49|     77|	lldpd_port_cleanup(nport, 1);
   50|     77|	free(nport);
   51|     77|	lldpd_chassis_cleanup(nchassis, 1);
   52|       |
   53|     77|	return 0;
   54|    564|}

