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

cdp_decode:
  282|    580|{
  283|    580|	struct lldpd_chassis *chassis;
  284|    580|	struct lldpd_port *port;
  285|    580|	struct lldpd_mgmt *mgmt;
  286|    580|	struct in_addr addr;
  287|       |#  if 0
  288|       |	u_int16_t cksum;
  289|       |#  endif
  290|    580|	u_int8_t *software = NULL, *platform = NULL;
  291|    580|	int software_len = 0, platform_len = 0, proto, version, nb, caps;
  292|    580|	const unsigned char cdpaddr[] = CDP_MULTICAST_ADDR;
  ------------------
  |  |   22|    580|  {                                    \
  |  |   23|    580|    0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc \
  |  |   24|    580|  }
  ------------------
  293|    580|#  ifdef ENABLE_FDP
  294|    580|	const unsigned char fdpaddr[] = CDP_MULTICAST_ADDR;
  ------------------
  |  |   22|    580|  {                                    \
  |  |   23|    580|    0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc \
  |  |   24|    580|  }
  ------------------
  295|    580|	int fdp = 0;
  296|    580|#  endif
  297|    580|	u_int8_t *pos, *tlv, *pos_address, *pos_next_address;
  298|    580|	int length, len_eth, tlv_type, tlv_len, addresses_len, address_len;
  299|    580|#  ifdef ENABLE_DOT1
  300|    580|	struct lldpd_vlan *vlan;
  301|    580|#  endif
  302|       |
  303|    580|	log_debug("cdp", "decode CDP frame received on %s", hardware->h_ifname);
  304|       |
  305|    580|	if ((chassis = calloc(1, sizeof(struct lldpd_chassis))) == NULL) {
  ------------------
  |  Branch (305:6): [True: 0, False: 580]
  ------------------
  306|      0|		log_warn("cdp", "failed to allocate remote chassis");
  307|      0|		return -1;
  308|      0|	}
  309|    580|	TAILQ_INIT(&chassis->c_mgmt);
  310|    580|	if ((port = calloc(1, sizeof(struct lldpd_port))) == NULL) {
  ------------------
  |  Branch (310:6): [True: 0, False: 580]
  ------------------
  311|      0|		log_warn("cdp", "failed to allocate remote port");
  312|      0|		free(chassis);
  313|      0|		return -1;
  314|      0|	}
  315|    580|#  ifdef ENABLE_DOT1
  316|    580|	TAILQ_INIT(&port->p_vlans);
  317|    580|#  endif
  318|       |
  319|    580|	length = s;
  320|    580|	pos = (u_int8_t *)frame;
  321|       |
  322|    580|	if (length < 2 * ETHER_ADDR_LEN + sizeof(u_int16_t) /* Ethernet */ +
  ------------------
  |  Branch (322:6): [True: 0, False: 580]
  ------------------
  323|    580|		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|    580|	if (PEEK_CMP(cdpaddr, sizeof(cdpaddr)) != 0) {
  ------------------
  |  |   80|    580|  (length -= (bytes), pos += (bytes), memcmp(pos - bytes, value, bytes))
  ------------------
  |  Branch (329:6): [True: 0, False: 580]
  ------------------
  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 - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|    580|	PEEK_DISCARD(ETHER_ADDR_LEN); /* Don't care of source address */
  ------------------
  |  |   72|    580|  do {                      \
  |  |   73|    580|    length -= (bytes);      \
  |  |   74|    580|    pos += (bytes);         \
  |  |   75|    580|  } while (0)
  |  |  ------------------
  |  |  |  Branch (75:12): [Folded - Ignored]
  |  |  ------------------
  ------------------
  345|    580|	len_eth = PEEK_UINT16;
  ------------------
  |  |   63|    580|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  ------------------
  |  |  |  |   60|    580|  (memcpy(&type, pos, sizeof(type)), length -= sizeof(type), pos += sizeof(type), \
  |  |  |  |   61|    580|      func(type))
  |  |  |  |  ------------------
  |  |  |  |  |  |   63|    580|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  346|    580|	if (len_eth > length) {
  ------------------
  |  Branch (346:6): [True: 20, False: 560]
  ------------------
  347|     20|		log_warnx("cdp", "incorrect 802.3 frame size reported on %s",
  348|     20|		    hardware->h_ifname);
  349|     20|		goto malformed;
  350|     20|	}
  351|       |
  352|       |	/* This is the correct length of the CDP + LLC packets */
  353|    560|	length = len_eth;
  354|       |
  355|    560|	PEEK_DISCARD(6); /* Skip beginning of LLC */
  ------------------
  |  |   72|    560|  do {                      \
  |  |   73|    560|    length -= (bytes);      \
  |  |   74|    560|    pos += (bytes);         \
  |  |   75|    560|  } while (0)
  |  |  ------------------
  |  |  |  Branch (75:12): [Folded - Ignored]
  |  |  ------------------
  ------------------
  356|    560|	proto = PEEK_UINT16;
  ------------------
  |  |   63|    560|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  ------------------
  |  |  |  |   60|    560|  (memcpy(&type, pos, sizeof(type)), length -= sizeof(type), pos += sizeof(type), \
  |  |  |  |   61|    560|      func(type))
  |  |  |  |  ------------------
  |  |  |  |  |  |   63|    560|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  357|    560|	if (proto != LLC_PID_CDP) {
  ------------------
  |  |   37|    560|#define LLC_PID_CDP 0x2000
  ------------------
  |  Branch (357:6): [True: 95, False: 465]
  ------------------
  358|     95|		if ((proto != LLC_PID_DRIP) && (proto != LLC_PID_PAGP) &&
  ------------------
  |  |   39|     95|#define LLC_PID_DRIP 0x102
  ------------------
              		if ((proto != LLC_PID_DRIP) && (proto != LLC_PID_PAGP) &&
  ------------------
  |  |   40|     94|#define LLC_PID_PAGP 0x104
  ------------------
  |  Branch (358:7): [True: 94, False: 1]
  |  Branch (358:34): [True: 93, False: 1]
  ------------------
  359|     95|		    (proto != LLC_PID_PVSTP) && (proto != LLC_PID_UDLD) &&
  ------------------
  |  |   41|     93|#define LLC_PID_PVSTP 0x10b
  ------------------
              		    (proto != LLC_PID_PVSTP) && (proto != LLC_PID_UDLD) &&
  ------------------
  |  |   42|     92|#define LLC_PID_UDLD 0x111
  ------------------
  |  Branch (359:7): [True: 92, False: 1]
  |  Branch (359:35): [True: 91, False: 1]
  ------------------
  360|     95|		    (proto != LLC_PID_VTP) && (proto != LLC_PID_DTP) &&
  ------------------
  |  |   43|     91|#define LLC_PID_VTP 0x2003
  ------------------
              		    (proto != LLC_PID_VTP) && (proto != LLC_PID_DTP) &&
  ------------------
  |  |   44|     90|#define LLC_PID_DTP 0x2004
  ------------------
  |  Branch (360:7): [True: 90, False: 1]
  |  Branch (360:33): [True: 89, False: 1]
  ------------------
  361|     95|		    (proto != LLC_PID_STP))
  ------------------
  |  |   45|     89|#define LLC_PID_STP 0x200a
  ------------------
  |  Branch (361:7): [True: 88, False: 1]
  ------------------
  362|     88|			log_debug("cdp", "incorrect LLC protocol ID received on %s",
  363|     88|			    hardware->h_ifname);
  364|     95|		goto malformed;
  365|     95|	}
  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|    465|	version = PEEK_UINT8;
  ------------------
  |  |   62|    465|#define PEEK_UINT8 PEEK(types.f_uint8, )
  |  |  ------------------
  |  |  |  |   60|    465|  (memcpy(&type, pos, sizeof(type)), length -= sizeof(type), pos += sizeof(type), \
  |  |  |  |   61|    465|      func(type))
  |  |  ------------------
  ------------------
  385|    465|	if ((version != 1) && (version != 2)) {
  ------------------
  |  Branch (385:6): [True: 465, False: 0]
  |  Branch (385:24): [True: 0, False: 465]
  ------------------
  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|    465|	port->p_ttl = PEEK_UINT8; /* TTL */
  ------------------
  |  |   62|    465|#define PEEK_UINT8 PEEK(types.f_uint8, )
  |  |  ------------------
  |  |  |  |   60|    465|  (memcpy(&type, pos, sizeof(type)), length -= sizeof(type), pos += sizeof(type), \
  |  |  |  |   61|    465|      func(type))
  |  |  ------------------
  ------------------
  392|    465|	PEEK_DISCARD_UINT16;	  /* Checksum, already checked */
  ------------------
  |  |   77|    465|#define PEEK_DISCARD_UINT16 PEEK_DISCARD(2)
  |  |  ------------------
  |  |  |  |   72|    465|  do {                      \
  |  |  |  |   73|    465|    length -= (bytes);      \
  |  |  |  |   74|    465|    pos += (bytes);         \
  |  |  |  |   75|    465|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (75:12): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  393|       |
  394|  3.24k|	while (length) {
  ------------------
  |  Branch (394:9): [True: 3.04k, False: 207]
  ------------------
  395|  3.04k|		if (length < 4) {
  ------------------
  |  Branch (395:7): [True: 46, False: 2.99k]
  ------------------
  396|     46|			log_warnx("cdp",
  397|     46|			    "CDP/FDP TLV header is too large for "
  398|     46|			    "frame received on %s",
  399|     46|			    hardware->h_ifname);
  400|     46|			goto malformed;
  401|     46|		}
  402|  2.99k|		tlv_type = PEEK_UINT16;
  ------------------
  |  |   63|  2.99k|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  ------------------
  |  |  |  |   60|  2.99k|  (memcpy(&type, pos, sizeof(type)), length -= sizeof(type), pos += sizeof(type), \
  |  |  |  |   61|  2.99k|      func(type))
  |  |  |  |  ------------------
  |  |  |  |  |  |   63|  2.99k|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  403|  2.99k|		tlv_len = PEEK_UINT16 - 4;
  ------------------
  |  |   63|  2.99k|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  ------------------
  |  |  |  |   60|  2.99k|  (memcpy(&type, pos, sizeof(type)), length -= sizeof(type), pos += sizeof(type), \
  |  |  |  |   61|  2.99k|      func(type))
  |  |  |  |  ------------------
  |  |  |  |  |  |   63|  2.99k|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  404|       |
  405|  2.99k|		(void)PEEK_SAVE(tlv);
  ------------------
  |  |   81|  2.99k|#define PEEK_SAVE POKE_SAVE
  |  |  ------------------
  |  |  |  |   46|  2.99k|#define POKE_SAVE(where) (where = pos, 1)
  |  |  ------------------
  ------------------
  406|  2.99k|		if ((tlv_len < 0) || (length < tlv_len)) {
  ------------------
  |  Branch (406:7): [True: 11, False: 2.98k]
  |  Branch (406:24): [True: 53, False: 2.93k]
  ------------------
  407|     64|			log_warnx("cdp",
  408|     64|			    "incorrect size in CDP/FDP TLV header for frame "
  409|     64|			    "received on %s",
  410|     64|			    hardware->h_ifname);
  411|     64|			goto malformed;
  412|     64|		}
  413|  2.93k|		switch (tlv_type) {
  414|    220|		case CDP_TLV_CHASSIS:
  ------------------
  |  Branch (414:3): [True: 220, False: 2.71k]
  ------------------
  415|    220|			free(chassis->c_name);
  416|    220|			if ((chassis->c_name = (char *)calloc(1, tlv_len + 1)) ==
  ------------------
  |  Branch (416:8): [True: 0, False: 220]
  ------------------
  417|    220|			    NULL) {
  418|      0|				log_warn("cdp",
  419|      0|				    "unable to allocate memory for chassis name");
  420|      0|				goto malformed;
  421|      0|			}
  422|    220|			PEEK_BYTES(chassis->c_name, tlv_len);
  ------------------
  |  |   66|    220|  do {                           \
  |  |   67|    220|    memcpy(value, pos, bytes);   \
  |  |   68|    220|    length -= (bytes);           \
  |  |   69|    220|    pos += (bytes);              \
  |  |   70|    220|  } while (0)
  |  |  ------------------
  |  |  |  Branch (70:12): [Folded - Ignored]
  |  |  ------------------
  ------------------
  423|    220|			chassis->c_id_subtype = LLDP_CHASSISID_SUBTYPE_LOCAL;
  ------------------
  |  |   37|    220|#define LLDP_CHASSISID_SUBTYPE_LOCAL 7
  ------------------
  424|    220|			free(chassis->c_id);
  425|    220|			if ((chassis->c_id = (char *)malloc(tlv_len)) == NULL) {
  ------------------
  |  Branch (425:8): [True: 0, False: 220]
  ------------------
  426|      0|				log_warn("cdp",
  427|      0|				    "unable to allocate memory for chassis ID");
  428|      0|				goto malformed;
  429|      0|			}
  430|    220|			memcpy(chassis->c_id, chassis->c_name, tlv_len);
  431|    220|			chassis->c_id_len = tlv_len;
  432|    220|			break;
  433|    380|		case CDP_TLV_ADDRESSES:
  ------------------
  |  Branch (433:3): [True: 380, False: 2.55k]
  ------------------
  434|    380|			CHECK_TLV_SIZE(4, "Address");
  ------------------
  |  |  271|    380|    do {                                                               \
  |  |  272|    380|      if (tlv_len < (x)) {                                             \
  |  |  ------------------
  |  |  |  Branch (272:11): [True: 4, False: 376]
  |  |  ------------------
  |  |  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|    380|    } while (0)
  |  |  ------------------
  |  |  |  Branch (277:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  435|    376|			addresses_len = tlv_len - 4;
  436|  1.34k|			for (nb = PEEK_UINT32; nb > 0; nb--) {
  ------------------
  |  |   64|    376|#define PEEK_UINT32 PEEK(types.f_uint32, ntohl)
  |  |  ------------------
  |  |  |  |   60|    376|  (memcpy(&type, pos, sizeof(type)), length -= sizeof(type), pos += sizeof(type), \
  |  |  |  |   61|    376|      func(type))
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|    376|#define PEEK_UINT32 PEEK(types.f_uint32, ntohl)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (436:27): [True: 1.10k, False: 245]
  ------------------
  437|  1.10k|				(void)PEEK_SAVE(pos_address);
  ------------------
  |  |   81|  1.10k|#define PEEK_SAVE POKE_SAVE
  |  |  ------------------
  |  |  |  |   46|  1.10k|#define POKE_SAVE(where) (where = pos, 1)
  |  |  ------------------
  ------------------
  438|       |				/* We first try to get the real length of the packet */
  439|  1.10k|				if (addresses_len < 2) {
  ------------------
  |  Branch (439:9): [True: 52, False: 1.04k]
  ------------------
  440|     52|					log_warn("cdp",
  441|     52|					    "too short address subframe "
  442|     52|					    "received on %s",
  443|     52|					    hardware->h_ifname);
  444|     52|					goto malformed;
  445|     52|				}
  446|  1.04k|				PEEK_DISCARD_UINT8;
  ------------------
  |  |   76|  1.04k|#define PEEK_DISCARD_UINT8 PEEK_DISCARD(1)
  |  |  ------------------
  |  |  |  |   72|  1.04k|  do {                      \
  |  |  |  |   73|  1.04k|    length -= (bytes);      \
  |  |  |  |   74|  1.04k|    pos += (bytes);         \
  |  |  |  |   75|  1.04k|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (75:12): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  447|  1.04k|				addresses_len--;
  448|  1.04k|				address_len = PEEK_UINT8;
  ------------------
  |  |   62|  1.04k|#define PEEK_UINT8 PEEK(types.f_uint8, )
  |  |  ------------------
  |  |  |  |   60|  1.04k|  (memcpy(&type, pos, sizeof(type)), length -= sizeof(type), pos += sizeof(type), \
  |  |  |  |   61|  1.04k|      func(type))
  |  |  ------------------
  ------------------
  449|  1.04k|				addresses_len--;
  450|  1.04k|				if (addresses_len < address_len + 2) {
  ------------------
  |  Branch (450:9): [True: 37, False: 1.01k]
  ------------------
  451|     37|					log_warn("cdp",
  452|     37|					    "too short address subframe "
  453|     37|					    "received on %s",
  454|     37|					    hardware->h_ifname);
  455|     37|					goto malformed;
  456|     37|				}
  457|  1.01k|				PEEK_DISCARD(address_len);
  ------------------
  |  |   72|  1.01k|  do {                      \
  |  |   73|  1.01k|    length -= (bytes);      \
  |  |   74|  1.01k|    pos += (bytes);         \
  |  |   75|  1.01k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (75:12): [Folded - Ignored]
  |  |  ------------------
  ------------------
  458|  1.01k|				addresses_len -= address_len;
  459|  1.01k|				address_len = PEEK_UINT16;
  ------------------
  |  |   63|  1.01k|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  ------------------
  |  |  |  |   60|  1.01k|  (memcpy(&type, pos, sizeof(type)), length -= sizeof(type), pos += sizeof(type), \
  |  |  |  |   61|  1.01k|      func(type))
  |  |  |  |  ------------------
  |  |  |  |  |  |   63|  1.01k|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  460|  1.01k|				addresses_len -= 2;
  461|  1.01k|				if (addresses_len < address_len) {
  ------------------
  |  Branch (461:9): [True: 42, False: 969]
  ------------------
  462|     42|					log_warn("cdp",
  463|     42|					    "too short address subframe "
  464|     42|					    "received on %s",
  465|     42|					    hardware->h_ifname);
  466|     42|					goto malformed;
  467|     42|				}
  468|    969|				PEEK_DISCARD(address_len);
  ------------------
  |  |   72|    969|  do {                      \
  |  |   73|    969|    length -= (bytes);      \
  |  |   74|    969|    pos += (bytes);         \
  |  |   75|    969|  } while (0)
  |  |  ------------------
  |  |  |  Branch (75:12): [Folded - Ignored]
  |  |  ------------------
  ------------------
  469|    969|				addresses_len -= address_len;
  470|    969|				(void)PEEK_SAVE(pos_next_address);
  ------------------
  |  |   81|    969|#define PEEK_SAVE POKE_SAVE
  |  |  ------------------
  |  |  |  |   46|    969|#define POKE_SAVE(where) (where = pos, 1)
  |  |  ------------------
  ------------------
  471|       |				/* Next, we go back and try to extract
  472|       |				   IPv4 address */
  473|    969|				PEEK_RESTORE(pos_address);
  ------------------
  |  |   82|    969|#define PEEK_RESTORE POKE_RESTORE
  |  |  ------------------
  |  |  |  |   48|    969|  do {                           \
  |  |  |  |   49|    969|    if ((where) > pos)           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (49:9): [True: 0, False: 969]
  |  |  |  |  ------------------
  |  |  |  |   50|    969|      length -= ((where)-pos);   \
  |  |  |  |   51|    969|    else                         \
  |  |  |  |   52|    969|      length += (pos - (where)); \
  |  |  |  |   53|    969|    pos = (where);               \
  |  |  |  |   54|    969|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (54:12): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  474|    969|				if ((PEEK_UINT8 == 1) && (PEEK_UINT8 == 1) &&
  ------------------
  |  |   62|    969|#define PEEK_UINT8 PEEK(types.f_uint8, )
  |  |  ------------------
  |  |  |  |   60|    969|  (memcpy(&type, pos, sizeof(type)), length -= sizeof(type), pos += sizeof(type), \
  |  |  |  |   61|    969|      func(type))
  |  |  ------------------
  ------------------
              				if ((PEEK_UINT8 == 1) && (PEEK_UINT8 == 1) &&
  ------------------
  |  |   62|    496|#define PEEK_UINT8 PEEK(types.f_uint8, )
  |  |  ------------------
  |  |  |  |   60|    496|  (memcpy(&type, pos, sizeof(type)), length -= sizeof(type), pos += sizeof(type), \
  |  |  |  |   61|    496|      func(type))
  |  |  ------------------
  ------------------
  |  Branch (474:9): [True: 496, False: 473]
  |  Branch (474:30): [True: 389, False: 107]
  ------------------
  475|    969|				    (PEEK_UINT8 == CDP_ADDRESS_PROTO_IP) &&
  ------------------
  |  |   62|    389|#define PEEK_UINT8 PEEK(types.f_uint8, )
  |  |  ------------------
  |  |  |  |   60|    389|  (memcpy(&type, pos, sizeof(type)), length -= sizeof(type), pos += sizeof(type), \
  |  |  |  |   61|    389|      func(type))
  |  |  ------------------
  ------------------
              				    (PEEK_UINT8 == CDP_ADDRESS_PROTO_IP) &&
  ------------------
  |  |   60|    389|#define CDP_ADDRESS_PROTO_IP 0xcc
  ------------------
  |  Branch (475:9): [True: 239, False: 150]
  ------------------
  476|    969|				    (PEEK_UINT16 == sizeof(struct in_addr))) {
  ------------------
  |  |   63|    239|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  ------------------
  |  |  |  |   60|    239|  (memcpy(&type, pos, sizeof(type)), length -= sizeof(type), pos += sizeof(type), \
  |  |  |  |   61|    239|      func(type))
  |  |  |  |  ------------------
  |  |  |  |  |  |   63|    239|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (476:9): [True: 132, False: 107]
  ------------------
  477|    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:12): [Folded - Ignored]
  |  |  ------------------
  ------------------
  478|    132|					mgmt = lldpd_alloc_mgmt(LLDPD_AF_IPV4, &addr,
  479|    132|					    sizeof(struct in_addr), 0);
  480|    132|					if (mgmt == NULL) {
  ------------------
  |  Branch (480:10): [True: 0, False: 132]
  ------------------
  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|    132|					TAILQ_INSERT_TAIL(&chassis->c_mgmt, mgmt,
  491|    132|					    m_entries);
  492|    132|				}
  493|       |				/* Go to the end of the address */
  494|    969|				PEEK_RESTORE(pos_next_address);
  ------------------
  |  |   82|    969|#define PEEK_RESTORE POKE_RESTORE
  |  |  ------------------
  |  |  |  |   48|    969|  do {                           \
  |  |  |  |   49|    969|    if ((where) > pos)           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (49:9): [True: 751, False: 218]
  |  |  |  |  ------------------
  |  |  |  |   50|    969|      length -= ((where)-pos);   \
  |  |  |  |   51|    969|    else                         \
  |  |  |  |   52|    969|      length += (pos - (where)); \
  |  |  |  |   53|    969|    pos = (where);               \
  |  |  |  |   54|    969|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (54:12): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  495|    969|			}
  496|    245|			break;
  497|    245|		case CDP_TLV_PORT:
  ------------------
  |  Branch (497:3): [True: 93, False: 2.83k]
  ------------------
  498|     93|			if (tlv_len == 0) {
  ------------------
  |  Branch (498:8): [True: 2, False: 91]
  ------------------
  499|      2|				log_warn("cdp", "too short port description received");
  500|      2|				goto malformed;
  501|      2|			}
  502|     91|			free(port->p_descr);
  503|     91|			if ((port->p_descr = (char *)calloc(1, tlv_len + 1)) == NULL) {
  ------------------
  |  Branch (503:8): [True: 0, False: 91]
  ------------------
  504|      0|				log_warn("cdp",
  505|      0|				    "unable to allocate memory for port description");
  506|      0|				goto malformed;
  507|      0|			}
  508|     91|			PEEK_BYTES(port->p_descr, tlv_len);
  ------------------
  |  |   66|     91|  do {                           \
  |  |   67|     91|    memcpy(value, pos, bytes);   \
  |  |   68|     91|    length -= (bytes);           \
  |  |   69|     91|    pos += (bytes);              \
  |  |   70|     91|  } while (0)
  |  |  ------------------
  |  |  |  Branch (70:12): [Folded - Ignored]
  |  |  ------------------
  ------------------
  509|     91|			port->p_id_subtype = LLDP_PORTID_SUBTYPE_IFNAME;
  ------------------
  |  |   45|     91|#define LLDP_PORTID_SUBTYPE_IFNAME 5
  ------------------
  510|     91|			free(port->p_id);
  511|     91|			if ((port->p_id = (char *)calloc(1, tlv_len)) == NULL) {
  ------------------
  |  Branch (511:8): [True: 0, False: 91]
  ------------------
  512|      0|				log_warn("cdp",
  513|      0|				    "unable to allocate memory for port ID");
  514|      0|				goto malformed;
  515|      0|			}
  516|     91|			memcpy(port->p_id, port->p_descr, tlv_len);
  517|     91|			port->p_id_len = tlv_len;
  518|     91|			break;
  519|    638|		case CDP_TLV_CAPABILITIES:
  ------------------
  |  Branch (519:3): [True: 638, False: 2.29k]
  ------------------
  520|    638|#  ifdef ENABLE_FDP
  521|    638|			if (fdp) {
  ------------------
  |  Branch (521:8): [True: 0, False: 638]
  ------------------
  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;
  ------------------
  |  |  254|      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;
  ------------------
  |  |  252|      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;
  ------------------
  |  |  251|      0|#define LLDP_CAP_REPEATER 0x02
  ------------------
  529|      0|				else
  530|      0|					chassis->c_cap_enabled = LLDP_CAP_STATION;
  ------------------
  |  |  257|      0|#define LLDP_CAP_STATION 0x80
  ------------------
  531|      0|				chassis->c_cap_available = chassis->c_cap_enabled;
  532|      0|				break;
  533|      0|			}
  534|    638|#  endif
  535|    638|			CHECK_TLV_SIZE(4, "Capabilities");
  ------------------
  |  |  271|    638|    do {                                                               \
  |  |  272|    638|      if (tlv_len < (x)) {                                             \
  |  |  ------------------
  |  |  |  Branch (272:11): [True: 3, False: 635]
  |  |  ------------------
  |  |  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|    638|    } while (0)
  |  |  ------------------
  |  |  |  Branch (277:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  536|    635|			caps = PEEK_UINT32;
  ------------------
  |  |   64|    635|#define PEEK_UINT32 PEEK(types.f_uint32, ntohl)
  |  |  ------------------
  |  |  |  |   60|    635|  (memcpy(&type, pos, sizeof(type)), length -= sizeof(type), pos += sizeof(type), \
  |  |  |  |   61|    635|      func(type))
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|    635|#define PEEK_UINT32 PEEK(types.f_uint32, ntohl)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  537|    635|			if (caps & CDP_CAP_ROUTER)
  ------------------
  |  |   62|    635|#define CDP_CAP_ROUTER 0x01
  ------------------
  |  Branch (537:8): [True: 335, False: 300]
  ------------------
  538|    335|				chassis->c_cap_enabled |= LLDP_CAP_ROUTER;
  ------------------
  |  |  254|    335|#define LLDP_CAP_ROUTER 0x10
  ------------------
  539|    635|			if (caps & 0x0e) chassis->c_cap_enabled |= LLDP_CAP_BRIDGE;
  ------------------
  |  |  252|    472|#define LLDP_CAP_BRIDGE 0x04
  ------------------
  |  Branch (539:8): [True: 472, False: 163]
  ------------------
  540|    635|			if (chassis->c_cap_enabled == 0)
  ------------------
  |  Branch (540:8): [True: 16, False: 619]
  ------------------
  541|     16|				chassis->c_cap_enabled = LLDP_CAP_STATION;
  ------------------
  |  |  257|     16|#define LLDP_CAP_STATION 0x80
  ------------------
  542|    635|			chassis->c_cap_available = chassis->c_cap_enabled;
  543|    635|			break;
  544|    137|		case CDP_TLV_SOFTWARE:
  ------------------
  |  Branch (544:3): [True: 137, False: 2.79k]
  ------------------
  545|    137|			software_len = tlv_len;
  546|    137|			(void)PEEK_SAVE(software);
  ------------------
  |  |   81|    137|#define PEEK_SAVE POKE_SAVE
  |  |  ------------------
  |  |  |  |   46|    137|#define POKE_SAVE(where) (where = pos, 1)
  |  |  ------------------
  ------------------
  547|    137|			break;
  548|    313|		case CDP_TLV_PLATFORM:
  ------------------
  |  Branch (548:3): [True: 313, False: 2.61k]
  ------------------
  549|    313|			platform_len = tlv_len;
  550|    313|			(void)PEEK_SAVE(platform);
  ------------------
  |  |   81|    313|#define PEEK_SAVE POKE_SAVE
  |  |  ------------------
  |  |  |  |   46|    313|#define POKE_SAVE(where) (where = pos, 1)
  |  |  ------------------
  ------------------
  551|    313|			break;
  552|      0|#  ifdef ENABLE_DOT1
  553|    349|		case CDP_TLV_NATIVEVLAN:
  ------------------
  |  Branch (553:3): [True: 349, False: 2.58k]
  ------------------
  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 - Ignored]
  |  |  ------------------
  ------------------
  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);
  574|    347|			break;
  575|      0|#  endif
  576|      0|#  ifdef ENABLE_DOT3
  577|    324|		case CDP_TLV_POWER_AVAILABLE:
  ------------------
  |  Branch (577:3): [True: 324, False: 2.60k]
  ------------------
  578|    324|			CHECK_TLV_SIZE(12, "Power Available");
  ------------------
  |  |  271|    324|    do {                                                               \
  |  |  272|    324|      if (tlv_len < (x)) {                                             \
  |  |  ------------------
  |  |  |  Branch (272:11): [True: 6, False: 318]
  |  |  ------------------
  |  |  273|      6|	log_warnx("cdp", name " CDP/FDP TLV too short received on %s", \
  |  |  274|      6|	    hardware->h_ifname);                                       \
  |  |  275|      6|	goto malformed;                                                \
  |  |  276|      6|      }                                                                \
  |  |  277|    324|    } while (0)
  |  |  ------------------
  |  |  |  Branch (277:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  579|       |			/* check if it is a respone to a request id */
  580|    318|			if (PEEK_UINT16 > 0) {
  ------------------
  |  |   63|    318|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  ------------------
  |  |  |  |   60|    318|  (memcpy(&type, pos, sizeof(type)), length -= sizeof(type), pos += sizeof(type), \
  |  |  |  |   61|    318|      func(type))
  |  |  |  |  ------------------
  |  |  |  |  |  |   63|    318|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (580:8): [True: 246, False: 72]
  ------------------
  581|    246|				port->p_cdp_power.management_id = PEEK_UINT16;
  ------------------
  |  |   63|    246|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  ------------------
  |  |  |  |   60|    246|  (memcpy(&type, pos, sizeof(type)), length -= sizeof(type), pos += sizeof(type), \
  |  |  |  |   61|    246|      func(type))
  |  |  |  |  ------------------
  |  |  |  |  |  |   63|    246|#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  582|    246|				port->p_power.allocated = PEEK_UINT32;
  ------------------
  |  |   64|    246|#define PEEK_UINT32 PEEK(types.f_uint32, ntohl)
  |  |  ------------------
  |  |  |  |   60|    246|  (memcpy(&type, pos, sizeof(type)), length -= sizeof(type), pos += sizeof(type), \
  |  |  |  |   61|    246|      func(type))
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|    246|#define PEEK_UINT32 PEEK(types.f_uint32, ntohl)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  583|    246|				port->p_power.allocated /= 100;
  584|    246|				port->p_power.supported = 1;
  585|    246|				port->p_power.enabled = 1;
  586|    246|				port->p_power.devicetype = LLDP_DOT3_POWER_PSE;
  ------------------
  |  |  198|    246|#define LLDP_DOT3_POWER_PSE 1
  ------------------
  587|    246|				port->p_power.powertype = LLDP_DOT3_POWER_8023AT_TYPE2;
  ------------------
  |  |  208|    246|#define LLDP_DOT3_POWER_8023AT_TYPE2 2
  ------------------
  588|    246|				log_debug("cdp", "Allocated power %d00",
  589|    246|				    port->p_power.allocated);
  590|    246|				if (port->p_power.allocated > CDP_CLASS_3_MAX_PSE_POE) {
  ------------------
  |  |   27|    246|#define CDP_CLASS_3_MAX_PSE_POE 154	 /* 15.4W Max PoE at PSE class 3 */
  ------------------
  |  Branch (590:9): [True: 75, False: 171]
  ------------------
  591|     75|					port->p_power.allocated -=
  592|     75|					    CDP_SWITCH_POE_CLASS_4_OFFSET;
  ------------------
  |  |   30|     75|#define CDP_SWITCH_POE_CLASS_4_OFFSET 45 /* 4.5W  max loss from cable */
  ------------------
  593|    171|				} else if (port->p_power.allocated >
  ------------------
  |  Branch (593:16): [True: 86, False: 85]
  ------------------
  594|    171|				    CDP_SWITCH_POE_CLASS_3_OFFSET) {
  ------------------
  |  |   31|    171|#define CDP_SWITCH_POE_CLASS_3_OFFSET 24 /* 2.4W  max loss from cable */
  ------------------
  595|     86|					port->p_power.allocated -=
  596|     86|					    CDP_SWITCH_POE_CLASS_3_OFFSET;
  ------------------
  |  |   31|     86|#define CDP_SWITCH_POE_CLASS_3_OFFSET 24 /* 2.4W  max loss from cable */
  ------------------
  597|     86|				} else {
  598|     85|					port->p_power.allocated = 0;
  599|     85|				}
  600|    246|				port->p_power.requested =
  601|    246|				    hardware->h_lport.p_power.requested;
  602|    246|			}
  603|    318|			break;
  604|      0|#  endif
  605|    477|		default:
  ------------------
  |  Branch (605:3): [True: 477, False: 2.45k]
  ------------------
  606|    477|			log_debug("cdp", "unknown CDP/FDP TLV type (%d) received on %s",
  607|    477|			    ntohs(tlv_type), hardware->h_ifname);
  608|    477|			hardware->h_rx_unrecognized_cnt++;
  609|  2.93k|		}
  610|  2.78k|		PEEK_DISCARD(tlv + tlv_len - pos);
  ------------------
  |  |   72|  2.78k|  do {                      \
  |  |   73|  2.78k|    length -= (bytes);      \
  |  |   74|  2.78k|    pos += (bytes);         \
  |  |   75|  2.78k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (75:12): [Folded - Ignored]
  |  |  ------------------
  ------------------
  611|  2.78k|	}
  612|    207|	if (!software && platform) {
  ------------------
  |  Branch (612:6): [True: 197, False: 10]
  |  Branch (612:19): [True: 17, False: 180]
  ------------------
  613|     17|		if ((chassis->c_descr = (char *)calloc(1, platform_len + 1)) == NULL) {
  ------------------
  |  Branch (613:7): [True: 0, False: 17]
  ------------------
  614|      0|			log_warn("cdp",
  615|      0|			    "unable to allocate memory for chassis description");
  616|      0|			goto malformed;
  617|      0|		}
  618|     17|		memcpy(chassis->c_descr, platform, platform_len);
  619|    190|	} else if (software && !platform) {
  ------------------
  |  Branch (619:13): [True: 10, False: 180]
  |  Branch (619:25): [True: 9, False: 1]
  ------------------
  620|      9|		if ((chassis->c_descr = (char *)calloc(1, software_len + 1)) == NULL) {
  ------------------
  |  Branch (620:7): [True: 0, False: 9]
  ------------------
  621|      0|			log_warn("cdp",
  622|      0|			    "unable to allocate memory for chassis description");
  623|      0|			goto malformed;
  624|      0|		}
  625|      9|		memcpy(chassis->c_descr, software, software_len);
  626|    181|	} else if (software && platform) {
  ------------------
  |  Branch (626:13): [True: 1, False: 180]
  |  Branch (626:25): [True: 1, False: 0]
  ------------------
  627|      1|#  define CONCAT_PLATFORM " running on\n"
  628|      1|		if ((chassis->c_descr = (char *)calloc(1,
  ------------------
  |  Branch (628:7): [True: 0, False: 1]
  ------------------
  629|      1|			 software_len + platform_len + strlen(CONCAT_PLATFORM) + 1)) ==
  ------------------
  |  |  627|      1|#  define CONCAT_PLATFORM " running on\n"
  ------------------
  630|      1|		    NULL) {
  631|      0|			log_warn("cdp",
  632|      0|			    "unable to allocate memory for chassis description");
  633|      0|			goto malformed;
  634|      0|		}
  635|      1|		memcpy(chassis->c_descr, platform, platform_len);
  636|      1|		memcpy(chassis->c_descr + platform_len, CONCAT_PLATFORM,
  ------------------
  |  |  627|      1|#  define CONCAT_PLATFORM " running on\n"
  ------------------
  637|      1|		    strlen(CONCAT_PLATFORM));
  ------------------
  |  |  627|      1|#  define CONCAT_PLATFORM " running on\n"
  ------------------
  638|      1|		memcpy(chassis->c_descr + platform_len + strlen(CONCAT_PLATFORM),
  ------------------
  |  |  627|      1|#  define CONCAT_PLATFORM " running on\n"
  ------------------
  639|      1|		    software, software_len);
  640|      1|	}
  641|    207|	if ((chassis->c_id == NULL) || (port->p_id == NULL) ||
  ------------------
  |  Branch (641:6): [True: 185, False: 22]
  |  Branch (641:33): [True: 9, False: 13]
  ------------------
  642|    207|	    (chassis->c_name == NULL) || (chassis->c_descr == NULL) ||
  ------------------
  |  Branch (642:6): [True: 0, False: 13]
  |  Branch (642:35): [True: 1, False: 12]
  ------------------
  643|    207|	    (port->p_descr == NULL) || (port->p_ttl == 0) ||
  ------------------
  |  Branch (643:6): [True: 0, False: 12]
  |  Branch (643:33): [True: 1, False: 11]
  ------------------
  644|    207|	    (chassis->c_cap_enabled == 0)) {
  ------------------
  |  Branch (644:6): [True: 8, False: 3]
  ------------------
  645|    204|		log_warnx("cdp",
  646|    204|		    "some mandatory CDP/FDP tlv are missing for frame received on %s",
  647|    204|		    hardware->h_ifname);
  648|    204|		goto malformed;
  649|    204|	}
  650|      3|	*newchassis = chassis;
  651|      3|	*newport = port;
  652|      3|	return 1;
  653|       |
  654|    577|malformed:
  655|    577|	lldpd_chassis_cleanup(chassis, 1);
  656|    577|	lldpd_port_cleanup(port, 1);
  657|    577|	free(port);
  658|    577|	return -1;
  659|    207|}
cdpv2_guess:
  706|    653|{
  707|    653|	return cdp_guess(frame, len, 2);
  708|    653|}
cdp.c:cdp_guess:
  686|    653|{
  687|    653|	const u_int8_t mcastaddr[] = CDP_MULTICAST_ADDR;
  ------------------
  |  |   22|    653|  {                                    \
  |  |   23|    653|    0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc \
  |  |   24|    653|  }
  ------------------
  688|    653|	if (length < 2 * ETHER_ADDR_LEN + sizeof(u_int16_t) /* Ethernet */ +
  ------------------
  |  Branch (688:6): [True: 10, False: 643]
  ------------------
  689|    653|		8 /* LLC */ + 4 /* CDP header */)
  690|     10|		return 0;
  691|    643|	if (PEEK_CMP(mcastaddr, ETHER_ADDR_LEN) != 0) return 0;
  ------------------
  |  |   80|    643|  (length -= (bytes), pos += (bytes), memcmp(pos - bytes, value, bytes))
  ------------------
  |  Branch (691:6): [True: 52, False: 591]
  ------------------
  692|    591|	PEEK_DISCARD(ETHER_ADDR_LEN);
  ------------------
  |  |   72|    591|  do {                      \
  |  |   73|    591|    length -= (bytes);      \
  |  |   74|    591|    pos += (bytes);         \
  |  |   75|    591|  } while (0)
  |  |  ------------------
  |  |  |  Branch (75:12): [Folded - Ignored]
  |  |  ------------------
  ------------------
  693|    591|	PEEK_DISCARD_UINT16; /* Ethernet */
  ------------------
  |  |   77|    591|#define PEEK_DISCARD_UINT16 PEEK_DISCARD(2)
  |  |  ------------------
  |  |  |  |   72|    591|  do {                      \
  |  |  |  |   73|    591|    length -= (bytes);      \
  |  |  |  |   74|    591|    pos += (bytes);         \
  |  |  |  |   75|    591|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (75:12): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  694|    591|	PEEK_DISCARD(8);     /* LLC */
  ------------------
  |  |   72|    591|  do {                      \
  |  |   73|    591|    length -= (bytes);      \
  |  |   74|    591|    pos += (bytes);         \
  |  |   75|    591|  } while (0)
  |  |  ------------------
  |  |  |  Branch (75:12): [Folded - Ignored]
  |  |  ------------------
  ------------------
  695|    591|	return (PEEK_UINT8 == version);
  ------------------
  |  |   62|    591|#define PEEK_UINT8 PEEK(types.f_uint8, )
  |  |  ------------------
  |  |  |  |   60|    591|  (memcpy(&type, pos, sizeof(type)), length -= sizeof(type), pos += sizeof(type), \
  |  |  |  |   61|    591|      func(type))
  |  |  ------------------
  ------------------
  696|    643|}

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

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

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

