diff options
-rw-r--r-- | ldpd/notification.c | 73 |
1 files changed, 32 insertions, 41 deletions
diff --git a/ldpd/notification.c b/ldpd/notification.c index af5bb267d..1709098d0 100644 --- a/ldpd/notification.c +++ b/ldpd/notification.c @@ -25,28 +25,28 @@ send_notification_full(struct tcp_conn *tcp, struct notify_msg *nm) /* calculate size */ size = LDP_HDR_SIZE + LDP_MSG_SIZE + STATUS_SIZE; - if (nm->flags & F_NOTIF_PW_STATUS) + if (CHECK_FLAG(nm->flags, F_NOTIF_PW_STATUS)) size += PW_STATUS_TLV_SIZE; - if (nm->flags & F_NOTIF_FEC) + if (CHECK_FLAG(nm->flags, F_NOTIF_FEC)) size += len_fec_tlv(&nm->fec); - if (nm->flags & F_NOTIF_RETURNED_TLVS) + if (CHECK_FLAG(nm->flags, F_NOTIF_RETURNED_TLVS)) size += TLV_HDR_SIZE * 2 + nm->rtlvs.length; if ((buf = ibuf_open(size)) == NULL) fatal(__func__); - err |= gen_ldp_hdr(buf, size); + SET_FLAG(err, gen_ldp_hdr(buf, size)); size -= LDP_HDR_SIZE; - err |= gen_msg_hdr(buf, MSG_TYPE_NOTIFICATION, size); - err |= gen_status_tlv(buf, nm->status_code, nm->msg_id, nm->msg_type); + SET_FLAG(err, gen_msg_hdr(buf, MSG_TYPE_NOTIFICATION, size)); + SET_FLAG(err, gen_status_tlv(buf, nm->status_code, nm->msg_id, nm->msg_type)); /* optional tlvs */ - if (nm->flags & F_NOTIF_PW_STATUS) - err |= gen_pw_status_tlv(buf, nm->pw_status); - if (nm->flags & F_NOTIF_FEC) - err |= gen_fec_tlv(buf, &nm->fec); - if (nm->flags & F_NOTIF_RETURNED_TLVS) - err |= gen_returned_tlvs(buf, nm->rtlvs.type, nm->rtlvs.length, - nm->rtlvs.data); + if (CHECK_FLAG(nm->flags, F_NOTIF_PW_STATUS)) + SET_FLAG(err, gen_pw_status_tlv(buf, nm->pw_status)); + if (CHECK_FLAG(nm->flags, F_NOTIF_FEC)) + SET_FLAG(err, gen_fec_tlv(buf, &nm->fec)); + if (CHECK_FLAG(nm->flags, F_NOTIF_RETURNED_TLVS)) + SET_FLAG(err, gen_returned_tlvs(buf, nm->rtlvs.type, nm->rtlvs.length, + nm->rtlvs.data)); if (err) { ibuf_free(buf); return; @@ -121,7 +121,7 @@ send_notification_rtlvs(struct nbr *nbr, uint32_t status_code, uint32_t msg_id, nm.rtlvs.type = tlv_type; nm.rtlvs.length = tlv_len; nm.rtlvs.data = tlv_data; - nm.flags |= F_NOTIF_RETURNED_TLVS; + SET_FLAG(nm.flags, F_NOTIF_RETURNED_TLVS); } send_notification_full(nbr->tcp, &nm); @@ -189,13 +189,12 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len) break; case TLV_TYPE_PW_STATUS: if (tlv_len != 4) { - session_shutdown(nbr, S_BAD_TLV_LEN, - msg.id, msg.type); + session_shutdown(nbr, S_BAD_TLV_LEN, msg.id, msg.type); return (-1); } nm.pw_status = ntohl(*(uint32_t *)buf); - nm.flags |= F_NOTIF_PW_STATUS; + SET_FLAG(nm.flags, F_NOTIF_PW_STATUS); break; case TLV_TYPE_FEC: if ((tlen = tlv_decode_fec_elm(nbr, &msg, buf, @@ -203,12 +202,11 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len) return (-1); /* allow only one fec element */ if (tlen != tlv_len) { - session_shutdown(nbr, S_BAD_TLV_VAL, - msg.id, msg.type); + session_shutdown(nbr, S_BAD_TLV_VAL, msg.id, msg.type); leconf->stats.bad_tlv_len++; return (-1); } - nm.flags |= F_NOTIF_FEC; + SET_FLAG(nm.flags, F_NOTIF_FEC); break; default: if (!(ntohs(tlv.type) & UNKNOWN_FLAG)) { @@ -226,9 +224,8 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len) /* sanity checks */ switch (nm.status_code) { case S_PW_STATUS: - if (!(nm.flags & (F_NOTIF_PW_STATUS|F_NOTIF_FEC))) { - send_notification(nbr->tcp, S_MISS_MSG, - msg.id, msg.type); + if (!CHECK_FLAG(nm.flags, (F_NOTIF_PW_STATUS|F_NOTIF_FEC))) { + send_notification(nbr->tcp, S_MISS_MSG, msg.id, msg.type); return (-1); } @@ -236,20 +233,17 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len) case MAP_TYPE_PWID: break; default: - send_notification(nbr->tcp, S_BAD_TLV_VAL, - msg.id, msg.type); + send_notification(nbr->tcp, S_BAD_TLV_VAL, msg.id, msg.type); return (-1); } break; case S_ENDOFLIB: - if (!(nm.flags & F_NOTIF_FEC)) { - send_notification(nbr->tcp, S_MISS_MSG, - msg.id, msg.type); + if (!CHECK_FLAG(nm.flags, F_NOTIF_FEC)) { + send_notification(nbr->tcp, S_MISS_MSG, msg.id, msg.type); return (-1); } if (nm.fec.type != MAP_TYPE_TYPED_WCARD) { - send_notification(nbr->tcp, S_BAD_TLV_VAL, - msg.id, msg.type); + send_notification(nbr->tcp, S_BAD_TLV_VAL, msg.id, msg.type); return (-1); } break; @@ -259,7 +253,7 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len) log_msg_notification(0, nbr, &nm); - if (st.status_code & htonl(STATUS_FATAL)) { + if (CHECK_FLAG(st.status_code, htonl(STATUS_FATAL))) { if (nbr->state == NBR_STA_OPENSENT) nbr_start_idtimer(nbr); @@ -269,11 +263,9 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len) * initialization, it SHOULD transmit a Shutdown message and * then close the transport connection". */ - if (nbr->state != NBR_STA_OPER && - nm.status_code == S_SHUTDOWN) { + if (nbr->state != NBR_STA_OPER && nm.status_code == S_SHUTDOWN) { leconf->stats.session_attempts++; - send_notification(nbr->tcp, S_SHUTDOWN, - msg.id, msg.type); + send_notification(nbr->tcp, S_SHUTDOWN, msg.id, msg.type); } leconf->stats.shutdown_rcv_notify++; @@ -287,8 +279,7 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len) switch (nm.status_code) { case S_PW_STATUS: case S_ENDOFLIB: - ldpe_imsg_compose_lde(IMSG_NOTIFICATION, nbr->peerid, 0, - &nm, sizeof(nm)); + ldpe_imsg_compose_lde(IMSG_NOTIFICATION, nbr->peerid, 0, &nm, sizeof(nm)); break; case S_NO_HELLO: leconf->stats.session_rejects_hello++; @@ -361,8 +352,8 @@ gen_returned_tlvs(struct ibuf *buf, uint16_t type, uint16_t length, tlv.length = htons(length); err = ibuf_add(buf, &rtlvs, sizeof(rtlvs)); - err |= ibuf_add(buf, &tlv, sizeof(tlv)); - err |= ibuf_add(buf, tlv_data, length); + SET_FLAG(err, ibuf_add(buf, &tlv, sizeof(tlv))); + SET_FLAG(err, ibuf_add(buf, tlv_data, length)); return (err); } @@ -378,9 +369,9 @@ log_msg_notification(int out, struct nbr *nbr, struct notify_msg *nm) debug_msg(out, "notification: lsr-id %pI4, status %s", &nbr->id, status_code_name(nm->status_code)); - if (nm->flags & F_NOTIF_FEC) + if (CHECK_FLAG(nm->flags, F_NOTIF_FEC)) debug_msg(out, "notification: fec %s", log_map(&nm->fec)); - if (nm->flags & F_NOTIF_PW_STATUS) + if (CHECK_FLAG(nm->flags, F_NOTIF_PW_STATUS)) debug_msg(out, "notification: pw-status %s", (nm->pw_status == PW_FORWARDING) ? "forwarding" : "not forwarding"); } |