ldpd: kill send_notification_nbr()

Be more clever and trigger the PDU SENT event inside send_notification()
when tcp->nbr is set. This way we can eliminate send_notification_nbr()
and always use send_notification() instead.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
Renato Westphal 2017-03-03 17:50:22 -03:00
parent 05aac414e6
commit adbdf4653f
6 changed files with 19 additions and 27 deletions

View File

@ -177,7 +177,7 @@ recv_address(struct nbr *nbr, char *buf, uint16_t len)
return (0);
break;
default:
send_notification_nbr(nbr, S_UNSUP_ADDR, msg.id, msg.type);
send_notification(nbr->tcp, S_UNSUP_ADDR, msg.id, msg.type);
return (-1);
}
buf += sizeof(alt);

View File

@ -118,7 +118,7 @@ recv_init(struct nbr *nbr, char *buf, uint16_t len)
return (-1);
default:
if (!(ntohs(tlv.type) & UNKNOWN_FLAG))
send_notification_nbr(nbr, S_UNKNOWN_TLV,
send_notification(nbr->tcp, S_UNKNOWN_TLV,
msg.id, msg.type);
/* ignore unknown tlv */
break;

View File

@ -163,7 +163,7 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type)
memcpy(&ft, buf, sizeof(ft));
if (ntohs(ft.type) != TLV_TYPE_FEC) {
send_notification_nbr(nbr, S_MISS_MSG, msg.id, msg.type);
send_notification(nbr->tcp, S_MISS_MSG, msg.id, msg.type);
return (-1);
}
feclen = ntohs(ft.length);
@ -187,7 +187,7 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type)
!(map.flags & F_MAP_PW_ID) &&
type != MSG_TYPE_LABELWITHDRAW &&
type != MSG_TYPE_LABELRELEASE) {
send_notification_nbr(nbr, S_MISS_MSG, msg.id,
send_notification(nbr->tcp, S_MISS_MSG, msg.id,
msg.type);
return (-1);
}
@ -341,7 +341,7 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type)
break;
default:
if (!(ntohs(tlv.type) & UNKNOWN_FLAG))
send_notification_nbr(nbr, S_UNKNOWN_TLV,
send_notification(nbr->tcp, S_UNKNOWN_TLV,
msg.id, msg.type);
/* ignore unknown tlv */
break;
@ -462,7 +462,7 @@ tlv_decode_label(struct nbr *nbr, struct ldp_msg *msg, char *buf,
memcpy(&lt, buf, sizeof(lt));
if (!(ntohs(lt.type) & TLV_TYPE_GENERICLABEL)) {
send_notification_nbr(nbr, S_MISS_MSG, msg->id, msg->type);
send_notification(nbr->tcp, S_MISS_MSG, msg->id, msg->type);
return (-1);
}
@ -642,7 +642,7 @@ tlv_decode_fec_elm(struct nbr *nbr, struct ldp_msg *msg, char *buf,
map->fec.prefix.af = AF_INET6;
break;
default:
send_notification_nbr(nbr, S_UNSUP_ADDR, msg->id,
send_notification(nbr->tcp, S_UNSUP_ADDR, msg->id,
msg->type);
return (-1);
}
@ -753,7 +753,7 @@ tlv_decode_fec_elm(struct nbr *nbr, struct ldp_msg *msg, char *buf,
return (off);
default:
send_notification_nbr(nbr, S_UNKNOWN_FEC, msg->id, msg->type);
send_notification(nbr->tcp, S_UNKNOWN_FEC, msg->id, msg->type);
break;
}

View File

@ -166,9 +166,7 @@ int recv_keepalive(struct nbr *, char *, uint16_t);
/* notification.c */
void send_notification_full(struct tcp_conn *, struct notify_msg *);
void send_notification(uint32_t, struct tcp_conn *, uint32_t,
uint16_t);
void send_notification_nbr(struct nbr *, uint32_t, uint32_t, uint16_t);
void send_notification(struct tcp_conn *, uint32_t, uint32_t, uint16_t);
int recv_notification(struct nbr *, char *, uint16_t);
int gen_status_tlv(struct ibuf *, uint32_t, uint32_t, uint16_t);

View File

@ -63,17 +63,19 @@ send_notification_full(struct tcp_conn *tcp, struct notify_msg *nm)
return;
}
if (tcp->nbr)
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)" : "");
nbr_fsm(tcp->nbr, NBR_EVT_PDU_SENT);
}
evbuf_enqueue(&tcp->wbuf, buf);
}
/* send a notification without optional tlvs */
void
send_notification(uint32_t status_code, struct tcp_conn *tcp, uint32_t msg_id,
send_notification(struct tcp_conn *tcp, uint32_t status_code, uint32_t msg_id,
uint16_t msg_type)
{
struct notify_msg nm;
@ -86,14 +88,6 @@ send_notification(uint32_t status_code, struct tcp_conn *tcp, uint32_t msg_id,
send_notification_full(tcp, &nm);
}
void
send_notification_nbr(struct nbr *nbr, uint32_t status_code, uint32_t msg_id,
uint16_t msg_type)
{
send_notification(status_code, nbr->tcp, msg_id, msg_type);
nbr_fsm(nbr, NBR_EVT_PDU_SENT);
}
int
recv_notification(struct nbr *nbr, char *buf, uint16_t len)
{
@ -172,7 +166,7 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len)
break;
default:
if (!(ntohs(tlv.type) & UNKNOWN_FLAG))
send_notification_nbr(nbr, S_UNKNOWN_TLV,
send_notification(nbr->tcp, S_UNKNOWN_TLV,
msg.id, msg.type);
/* ignore unknown tlv */
break;
@ -183,7 +177,7 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len)
if (nm.status_code == S_PW_STATUS) {
if (!(nm.flags & (F_NOTIF_PW_STATUS|F_NOTIF_FEC))) {
send_notification_nbr(nbr, S_MISS_MSG,
send_notification(nbr->tcp, S_MISS_MSG,
msg.id, msg.type);
return (-1);
}
@ -192,7 +186,7 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len)
case MAP_TYPE_PWID:
break;
default:
send_notification_nbr(nbr, S_BAD_TLV_VAL,
send_notification(nbr->tcp, S_BAD_TLV_VAL,
msg.id, msg.type);
return (-1);
}

View File

@ -564,7 +564,7 @@ session_read(struct thread *thread)
log_debug("%s: unknown LDP message from nbr %s",
__func__, inet_ntoa(nbr->id));
if (!(ntohs(msg->type) & UNKNOWN_FLAG))
send_notification_nbr(nbr,
send_notification(nbr->tcp,
S_UNKNOWN_MSG, msg->id, msg->type);
/* ignore the message */
ret = 0;
@ -632,7 +632,7 @@ session_shutdown(struct nbr *nbr, uint32_t status, uint32_t msg_id,
case NBR_STA_OPER:
log_debug("%s: lsr-id %s", __func__, inet_ntoa(nbr->id));
send_notification_nbr(nbr, status, msg_id, msg_type);
send_notification(nbr->tcp, status, msg_id, msg_type);
nbr_fsm(nbr, NBR_EVT_CLOSE_SESSION);
break;
@ -788,7 +788,7 @@ pending_conn_timeout(struct thread *thread)
* notification message reliably.
*/
tcp = tcp_new(pconn->fd, NULL);
send_notification(S_NO_HELLO, tcp, 0, 0);
send_notification(tcp, S_NO_HELLO, 0, 0);
msgbuf_write(&tcp->wbuf.wbuf);
pending_conn_del(pconn);