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

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

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

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

