]> git.puffer.fish Git - mirror/frr.git/commitdiff
ldpd: create helper functions to log sent/received messages
authorRenato Westphal <renato@opensourcerouting.org>
Fri, 3 Mar 2017 20:50:22 +0000 (17:50 -0300)
committerRenato Westphal <renato@opensourcerouting.org>
Fri, 3 Mar 2017 20:50:22 +0000 (17:50 -0300)
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
ldpd/address.c
ldpd/labelmapping.c
ldpd/ldp_debug.h
ldpd/notification.c

index 0bb4e048eb6fa5f8dea4ea542d709d6b57c9650d..cb2f505f7b7d10b2d0e54b5f6c65557e78b2fd42 100644 (file)
@@ -30,6 +30,8 @@ static int     gen_address_list_tlv(struct ibuf *, uint16_t, int,
                    struct if_addr_head *, unsigned int);
 static void     address_list_add(struct if_addr_head *, struct if_addr *);
 static void     address_list_clr(struct if_addr_head *);
+static void     log_msg_address(int, uint16_t, struct nbr *, int,
+                   union ldpd_addr *);
 
 static void
 send_address(struct nbr *nbr, int af, struct if_addr_head *addr_list,
@@ -92,9 +94,7 @@ send_address(struct nbr *nbr, int af, struct if_addr_head *addr_list,
                }
 
                while ((if_addr = LIST_FIRST(addr_list)) != NULL) {
-                       debug_msg_send("%s: lsr-id %s address %s",
-                           msg_name(msg_type), inet_ntoa(nbr->id),
-                           log_addr(af, &if_addr->addr));
+                       log_msg_address(1, msg_type, nbr, af, &if_addr->addr);
 
                        LIST_REMOVE(if_addr, entry);
                        free(if_addr);
@@ -223,8 +223,7 @@ recv_address(struct nbr *nbr, char *buf, uint16_t len)
                        fatalx("recv_address: unknown af");
                }
 
-               debug_msg_recv("%s: lsr-id %s address %s", msg_name(msg_type),
-                   inet_ntoa(nbr->id), log_addr(lde_addr.af, &lde_addr.addr));
+               log_msg_address(0, msg_type, nbr, lde_addr.af, &lde_addr.addr);
 
                ldpe_imsg_compose_lde(type, nbr->peerid, 0, &lde_addr,
                    sizeof(lde_addr));
@@ -292,3 +291,11 @@ address_list_clr(struct if_addr_head *addr_list)
                free(if_addr);
        }
 }
+
+static void
+log_msg_address(int out, uint16_t msg_type, struct nbr *nbr, int af,
+    union ldpd_addr *addr)
+{
+       debug_msg(out, "%s: lsr-id %s, address %s", msg_name(msg_type),
+           inet_ntoa(nbr->id), log_addr(af, addr));
+}
index 34cc1f83a2224e31c2e4a8340159bf22739dffb1..d9f71fdf6b592230ce0f89862e53ab94533622ca 100644 (file)
@@ -31,6 +31,7 @@ static int     gen_label_tlv(struct ibuf *, uint32_t);
 static int      tlv_decode_label(struct nbr *, struct ldp_msg *, char *,
                    uint16_t, uint32_t *);
 static int      gen_reqid_tlv(struct ibuf *, uint32_t);
+static void     log_msg_mapping(int, uint16_t, struct nbr *, struct map *);
 
 static void
 enqueue_pdu(struct nbr *nbr, struct ibuf *buf, uint16_t size)
@@ -124,9 +125,7 @@ send_labelmessage(struct nbr *nbr, uint16_t type, struct mapping_head *mh)
                        return;
                }
 
-               debug_msg_send("%s: lsr-id %s fec %s label %s", msg_name(type),
-                   inet_ntoa(nbr->id), log_map(&me->map),
-                   log_label(me->map.label));
+               log_msg_mapping(1, type, nbr, &me->map);
 
                TAILQ_REMOVE(mh, me, entry);
                free(me);
@@ -396,9 +395,7 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type)
                if (me->map.flags & F_MAP_REQ_ID)
                        me->map.requestid = reqid;
 
-               debug_msg_recv("%s: lsr-id %s fec %s label %s", msg_name(type),
-                   inet_ntoa(nbr->id), log_map(&me->map),
-                   log_label(me->map.label));
+               log_msg_mapping(0, type, nbr, &me->map);
 
                switch (type) {
                case MSG_TYPE_LABELMAPPING:
@@ -759,3 +756,10 @@ tlv_decode_fec_elm(struct nbr *nbr, struct ldp_msg *msg, char *buf,
 
        return (-1);
 }
+
+static void
+log_msg_mapping(int out, uint16_t msg_type, struct nbr *nbr, struct map *map)
+{
+       debug_msg(out, "%s: lsr-id %s, fec %s, label %s", msg_name(msg_type),
+           inet_ntoa(nbr->id), log_map(map), log_label(map->label));
+}
index aa0cd47e7bc66dd98c5c0450de01be8ebd7a0e13..f944851b6e3568b26bcd3e431982f9d5a210ae42 100644 (file)
@@ -104,6 +104,14 @@ do {                                                                       \
                log_debug("msg[out]: " emsg, __VA_ARGS__);              \
 } while (0)
 
+#define                 debug_msg(out, emsg, ...)                              \
+do {                                                                   \
+       if (out)                                                        \
+               debug_msg_send(emsg, __VA_ARGS__);                      \
+       else                                                            \
+               debug_msg_recv(emsg, __VA_ARGS__);                      \
+} while (0)
+
 #define                 debug_kalive_recv(emsg, ...)                           \
 do {                                                                   \
        if (LDP_DEBUG(msg, MSG_RECV_ALL))                               \
index d435bc8845b97ed61e1dec3707570738b889ebb2..d573925314b603d892e892e5754716a3e4c7085e 100644 (file)
@@ -24,6 +24,8 @@
 #include "ldpe.h"
 #include "ldp_debug.h"
 
+static void     log_msg_notification(int, struct nbr *, struct notify_msg *);
+
 void
 send_notification_full(struct tcp_conn *tcp, struct notify_msg *nm)
 {
@@ -64,15 +66,7 @@ send_notification_full(struct tcp_conn *tcp, struct notify_msg *nm)
        }
 
        if (tcp->nbr) {
-               debug_msg_send("notification: lsr-id %s status %s%s",
-                   inet_ntoa(tcp->nbr->id), status_code_name(nm->status_code),
-                   (nm->status_code & STATUS_FATAL) ? " (fatal)" : "");
-               if (nm->flags & F_NOTIF_FEC)
-                       debug_msg_send("notification:   fec %s",
-                           log_map(&nm->fec));
-               if (nm->flags & F_NOTIF_PW_STATUS)
-                       debug_msg_send("notification:   pw-status %s",
-                           (nm->pw_status) ? "not forwarding" : "forwarding");
+               log_msg_notification(1, tcp->nbr, nm);
                nbr_fsm(tcp->nbr, NBR_EVT_PDU_SENT);
        }
 
@@ -198,14 +192,7 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len)
                }
        }
 
-       debug_msg_recv("notification: lsr-id %s: %s%s", inet_ntoa(nbr->id),
-           status_code_name(ntohl(st.status_code)),
-           (st.status_code & htonl(STATUS_FATAL)) ? " (fatal)" : "");
-       if (nm.flags & F_NOTIF_FEC)
-               debug_msg_recv("notification:   fec %s", log_map(&nm.fec));
-       if (nm.flags & F_NOTIF_PW_STATUS)
-               debug_msg_recv("notification:   pw-status %s",
-                   (nm.pw_status) ? "not forwarding" : "forwarding");
+       log_msg_notification(0, nbr, &nm);
 
        if (st.status_code & htonl(STATUS_FATAL)) {
                if (nbr->state == NBR_STA_OPENSENT)
@@ -241,3 +228,22 @@ gen_status_tlv(struct ibuf *buf, uint32_t status_code, uint32_t msg_id,
 
        return (ibuf_add(buf, &st, STATUS_SIZE));
 }
+
+void
+log_msg_notification(int out, struct nbr *nbr, struct notify_msg *nm)
+{
+       if (nm->status_code & STATUS_FATAL) {
+               debug_msg(out, "notification: lsr-id %s, status %s "
+                   "(fatal error)", inet_ntoa(nbr->id),
+                   status_code_name(nm->status_code));
+               return;
+       }
+
+       debug_msg(out, "notification: lsr-id %s, status %s",
+           inet_ntoa(nbr->id), status_code_name(nm->status_code));
+       if (nm->flags & F_NOTIF_FEC)
+               debug_msg(out, "notification:   fec %s", log_map(&nm->fec));
+       if (nm->flags & F_NOTIF_PW_STATUS)
+               debug_msg(out, "notification:   pw-status %s",
+                   (nm->pw_status) ? "not forwarding" : "forwarding");
+}