diff options
author | Renato Westphal <renato@cvs.openbsd.org> | 2017-03-03 23:50:46 +0000 |
---|---|---|
committer | Renato Westphal <renato@cvs.openbsd.org> | 2017-03-03 23:50:46 +0000 |
commit | 56f5d45cf1489d075f76f9893c96f663184204ec (patch) | |
tree | cfd570c2565b0b25440802c4610c567d220de52d /usr.sbin | |
parent | cf98b5cef64de505b5a9deda78ff0b71bff6ceb2 (diff) |
Create helper functions to log sent/received messages.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ldpd/address.c | 20 | ||||
-rw-r--r-- | usr.sbin/ldpd/labelmapping.c | 19 | ||||
-rw-r--r-- | usr.sbin/ldpd/notification.c | 45 |
3 files changed, 52 insertions, 32 deletions
diff --git a/usr.sbin/ldpd/address.c b/usr.sbin/ldpd/address.c index 669f9dbb725..cfb80511d4b 100644 --- a/usr.sbin/ldpd/address.c +++ b/usr.sbin/ldpd/address.c @@ -1,4 +1,4 @@ -/* $OpenBSD: address.c,v 1.31 2017/03/03 23:44:35 renato Exp $ */ +/* $OpenBSD: address.c,v 1.32 2017/03/03 23:50:45 renato Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -32,6 +32,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, @@ -94,9 +96,7 @@ send_address(struct nbr *nbr, int af, struct if_addr_head *addr_list, } while ((if_addr = LIST_FIRST(addr_list)) != NULL) { - log_debug("msg-out: %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); @@ -225,9 +225,7 @@ recv_address(struct nbr *nbr, char *buf, uint16_t len) fatalx("recv_address: unknown af"); } - log_debug("msg-in: %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)); @@ -295,3 +293,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) +{ + log_debug("msg-%s: %s: lsr-id %s, address %s", (out) ? "out" : "in", + msg_name(msg_type), inet_ntoa(nbr->id), log_addr(af, addr)); +} diff --git a/usr.sbin/ldpd/labelmapping.c b/usr.sbin/ldpd/labelmapping.c index 61a6a8ae75f..964cc44286e 100644 --- a/usr.sbin/ldpd/labelmapping.c +++ b/usr.sbin/ldpd/labelmapping.c @@ -1,4 +1,4 @@ -/* $OpenBSD: labelmapping.c,v 1.63 2017/03/03 23:44:35 renato Exp $ */ +/* $OpenBSD: labelmapping.c,v 1.64 2017/03/03 23:50:45 renato Exp $ */ /* * Copyright (c) 2014, 2015 Renato Westphal <renato@openbsd.org> @@ -34,6 +34,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) @@ -127,9 +128,7 @@ send_labelmessage(struct nbr *nbr, uint16_t type, struct mapping_head *mh) return; } - log_debug("msg-out: %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); @@ -399,9 +398,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; - log_debug("msg-in: %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: @@ -762,3 +759,11 @@ 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) +{ + log_debug("msg-%s: %s: lsr-id %s, fec %s, label %s", + (out) ? "out" : "in", msg_name(msg_type), inet_ntoa(nbr->id), + log_map(map), log_label(map->label)); +} diff --git a/usr.sbin/ldpd/notification.c b/usr.sbin/ldpd/notification.c index 6af02ba2419..b8fab3476b5 100644 --- a/usr.sbin/ldpd/notification.c +++ b/usr.sbin/ldpd/notification.c @@ -1,4 +1,4 @@ -/* $OpenBSD: notification.c,v 1.43 2017/03/03 23:47:41 renato Exp $ */ +/* $OpenBSD: notification.c,v 1.44 2017/03/03 23:50:45 renato Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -25,6 +25,8 @@ #include "log.h" #include "ldpe.h" +static void log_msg_notification(int, struct nbr *, struct notify_msg *); + void send_notification_full(struct tcp_conn *tcp, struct notify_msg *nm) { @@ -65,15 +67,7 @@ send_notification_full(struct tcp_conn *tcp, struct notify_msg *nm) } if (tcp->nbr) { - log_debug("msg-out: 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) - log_debug("msg-out: notification: fec %s", - log_map(&nm->fec)); - if (nm->flags & F_NOTIF_PW_STATUS) - log_debug("msg-out: 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); } @@ -199,14 +193,7 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len) } } - log_warnx("msg-in: notification: lsr-id %s, status %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) - log_debug("msg-in: notification: fec %s", log_map(&nm.fec)); - if (nm.flags & F_NOTIF_PW_STATUS) - log_debug("msg-in: 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) @@ -242,3 +229,25 @@ 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) +{ + const char *dir = (out) ? "out" : "in"; + + if (nm->status_code & STATUS_FATAL) { + log_warnx("msg-%s: notification: lsr-id %s, status %s " + "(fatal error)", dir, inet_ntoa(nbr->id), + status_code_name(nm->status_code)); + return; + } + + log_debug("msg-%s: notification: lsr-id %s, status %s", dir, + inet_ntoa(nbr->id), status_code_name(nm->status_code)); + if (nm->flags & F_NOTIF_FEC) + log_debug("msg-%s: notification: fec %s", dir, + log_map(&nm->fec)); + if (nm->flags & F_NOTIF_PW_STATUS) + log_debug("msg-%s: notification: pw-status %s", dir, + (nm->pw_status) ? "not forwarding" : "forwarding"); +} |