pimd: Protect log messages with debug in pim_pim.c

Protect the log messages in pim_pim.c with PIM_DEBUG_PIM_PACKETS

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
This commit is contained in:
Donald Sharp 2016-11-15 21:27:28 -05:00
parent 5f9cf1d209
commit def1e80732

View File

@ -143,13 +143,15 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len)
struct pim_neighbor *neigh; struct pim_neighbor *neigh;
if (!ifp->info) { if (!ifp->info) {
zlog_warn("%s: PIM not enabled on interface %s", if (PIM_DEBUG_PIM_PACKETS)
zlog_debug("%s: PIM not enabled on interface %s",
__PRETTY_FUNCTION__, ifp->name); __PRETTY_FUNCTION__, ifp->name);
return -1; return -1;
} }
if (len < sizeof(*ip_hdr)) { if (len < sizeof(*ip_hdr)) {
zlog_warn("PIM packet size=%zu shorter than minimum=%zu", if (PIM_DEBUG_PIM_PACKETS)
zlog_debug("PIM packet size=%zu shorter than minimum=%zu",
len, sizeof(*ip_hdr)); len, sizeof(*ip_hdr));
return -1; return -1;
} }
@ -167,18 +169,21 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len)
} }
if (ip_hdr->ip_p != PIM_IP_PROTO_PIM) { if (ip_hdr->ip_p != PIM_IP_PROTO_PIM) {
zlog_warn("IP packet protocol=%d is not PIM=%d", if (PIM_DEBUG_PIM_PACKETS)
zlog_debug("IP packet protocol=%d is not PIM=%d",
ip_hdr->ip_p, PIM_IP_PROTO_PIM); ip_hdr->ip_p, PIM_IP_PROTO_PIM);
return -1; return -1;
} }
if (ip_hlen < PIM_IP_HEADER_MIN_LEN) { if (ip_hlen < PIM_IP_HEADER_MIN_LEN) {
zlog_warn("IP packet header size=%zu shorter than minimum=%d", if (PIM_DEBUG_PIM_PACKETS)
zlog_debug("IP packet header size=%zu shorter than minimum=%d",
ip_hlen, PIM_IP_HEADER_MIN_LEN); ip_hlen, PIM_IP_HEADER_MIN_LEN);
return -1; return -1;
} }
if (ip_hlen > PIM_IP_HEADER_MAX_LEN) { if (ip_hlen > PIM_IP_HEADER_MAX_LEN) {
zlog_warn("IP packet header size=%zu greater than maximum=%d", if (PIM_DEBUG_PIM_PACKETS)
zlog_debug("IP packet header size=%zu greater than maximum=%d",
ip_hlen, PIM_IP_HEADER_MAX_LEN); ip_hlen, PIM_IP_HEADER_MAX_LEN);
return -1; return -1;
} }
@ -200,7 +205,8 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len)
pim_type = PIM_MSG_HDR_GET_TYPE(pim_msg); pim_type = PIM_MSG_HDR_GET_TYPE(pim_msg);
if (pim_version != PIM_PROTO_VERSION) { if (pim_version != PIM_PROTO_VERSION) {
zlog_warn("Ignoring PIM pkt from %s with unsupported version: %d", if (PIM_DEBUG_PIM_PACKETS)
zlog_debug("Ignoring PIM pkt from %s with unsupported version: %d",
ifp->name, pim_version); ifp->name, pim_version);
return -1; return -1;
} }
@ -213,7 +219,8 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len)
checksum = in_cksum(pim_msg, pim_msg_len); checksum = in_cksum(pim_msg, pim_msg_len);
if (checksum != pim_checksum) { if (checksum != pim_checksum) {
zlog_warn("Ignoring PIM pkt from %s with invalid checksum: received=%x calculated=%x", if (PIM_DEBUG_PIM_PACKETS)
zlog_debug("Ignoring PIM pkt from %s with invalid checksum: received=%x calculated=%x",
ifp->name, pim_checksum, checksum); ifp->name, pim_checksum, checksum);
return -1; return -1;
} }
@ -246,7 +253,8 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len)
case PIM_MSG_TYPE_JOIN_PRUNE: case PIM_MSG_TYPE_JOIN_PRUNE:
neigh = pim_neighbor_find(ifp, ip_hdr->ip_src); neigh = pim_neighbor_find(ifp, ip_hdr->ip_src);
if (!neigh) { if (!neigh) {
zlog_warn("%s %s: non-hello PIM message type=%d from non-neighbor %s on %s", if (PIM_DEBUG_PIM_PACKETS)
zlog_debug("%s %s: non-hello PIM message type=%d from non-neighbor %s on %s",
__FILE__, __PRETTY_FUNCTION__, __FILE__, __PRETTY_FUNCTION__,
pim_type, src_str, ifp->name); pim_type, src_str, ifp->name);
return -1; return -1;
@ -259,7 +267,8 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len)
case PIM_MSG_TYPE_ASSERT: case PIM_MSG_TYPE_ASSERT:
neigh = pim_neighbor_find(ifp, ip_hdr->ip_src); neigh = pim_neighbor_find(ifp, ip_hdr->ip_src);
if (!neigh) { if (!neigh) {
zlog_warn("%s %s: non-hello PIM message type=%d from non-neighbor %s on %s", if (PIM_DEBUG_PIM_PACKETS)
zlog_debug("%s %s: non-hello PIM message type=%d from non-neighbor %s on %s",
__FILE__, __PRETTY_FUNCTION__, __FILE__, __PRETTY_FUNCTION__,
pim_type, src_str, ifp->name); pim_type, src_str, ifp->name);
return -1; return -1;
@ -790,7 +799,8 @@ int pim_sock_add(struct interface *ifp)
zassert(pim_ifp); zassert(pim_ifp);
if (pim_ifp->pim_sock_fd >= 0) { if (pim_ifp->pim_sock_fd >= 0) {
zlog_warn("Can't recreate existing PIM socket fd=%d for interface %s", if (PIM_DEBUG_PIM_PACKETS)
zlog_debug("Can't recreate existing PIM socket fd=%d for interface %s",
pim_ifp->pim_sock_fd, ifp->name); pim_ifp->pim_sock_fd, ifp->name);
return -1; return -1;
} }
@ -799,7 +809,8 @@ int pim_sock_add(struct interface *ifp)
pim_ifp->pim_sock_fd = pim_sock_open(ifaddr, ifp->ifindex); pim_ifp->pim_sock_fd = pim_sock_open(ifaddr, ifp->ifindex);
if (pim_ifp->pim_sock_fd < 0) { if (pim_ifp->pim_sock_fd < 0) {
zlog_warn("Could not open PIM socket on interface %s", if (PIM_DEBUG_PIM_PACKETS)
zlog_debug("Could not open PIM socket on interface %s",
ifp->name); ifp->name);
return -2; return -2;
} }