From: renato Date: Fri, 1 Jul 2016 23:36:38 +0000 (+0000) Subject: More renaming and whitespace cleanup. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=60e1e0e7d3cd0a42d5055ee10f8ce4458f9884f0;p=openbsd More renaming and whitespace cleanup. No binary change after "strip -s". --- diff --git a/usr.sbin/ldpd/address.c b/usr.sbin/ldpd/address.c index dec38cff901..ba546be5506 100644 --- a/usr.sbin/ldpd/address.c +++ b/usr.sbin/ldpd/address.c @@ -1,4 +1,4 @@ -/* $OpenBSD: address.c,v 1.27 2016/07/01 23:29:55 renato Exp $ */ +/* $OpenBSD: address.c,v 1.28 2016/07/01 23:36:38 renato Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -82,28 +82,28 @@ send_address(struct nbr *nbr, int af, struct if_addr *if_addr, int withdraw) int recv_address(struct nbr *nbr, char *buf, uint16_t len) { - struct ldp_msg addr; + struct ldp_msg msg; struct address_list_tlv alt; enum imsg_type type; struct lde_addr lde_addr; - memcpy(&addr, buf, sizeof(addr)); + memcpy(&msg, buf, sizeof(msg)); buf += LDP_MSG_SIZE; len -= LDP_MSG_SIZE; /* Address List TLV */ if (len < sizeof(alt)) { - session_shutdown(nbr, S_BAD_MSG_LEN, addr.msgid, addr.type); + session_shutdown(nbr, S_BAD_MSG_LEN, msg.id, msg.type); return (-1); } memcpy(&alt, buf, sizeof(alt)); - if (ntohs(alt.length) != len - TLV_HDR_LEN) { - session_shutdown(nbr, S_BAD_TLV_LEN, addr.msgid, addr.type); + if (ntohs(alt.length) != len - TLV_HDR_SIZE) { + session_shutdown(nbr, S_BAD_TLV_LEN, msg.id, msg.type); return (-1); } if (ntohs(alt.type) != TLV_TYPE_ADDRLIST) { - session_shutdown(nbr, S_UNKNOWN_TLV, addr.msgid, addr.type); + session_shutdown(nbr, S_UNKNOWN_TLV, msg.id, msg.type); return (-1); } switch (ntohs(alt.family)) { @@ -118,13 +118,13 @@ recv_address(struct nbr *nbr, char *buf, uint16_t len) return (0); break; default: - send_notification_nbr(nbr, S_UNSUP_ADDR, addr.msgid, addr.type); + send_notification_nbr(nbr, S_UNSUP_ADDR, msg.id, msg.type); return (-1); } buf += sizeof(alt); len -= sizeof(alt); - if (ntohs(addr.type) == MSG_TYPE_ADDR) + if (ntohs(msg.type) == MSG_TYPE_ADDR) type = IMSG_ADDRESS_ADD; else type = IMSG_ADDRESS_DEL; @@ -133,8 +133,8 @@ recv_address(struct nbr *nbr, char *buf, uint16_t len) switch (ntohs(alt.family)) { case AF_IPV4: if (len < sizeof(struct in_addr)) { - session_shutdown(nbr, S_BAD_TLV_LEN, addr.msgid, - addr.type); + session_shutdown(nbr, S_BAD_TLV_LEN, msg.id, + msg.type); return (-1); } @@ -147,8 +147,8 @@ recv_address(struct nbr *nbr, char *buf, uint16_t len) break; case AF_IPV6: if (len < sizeof(struct in6_addr)) { - session_shutdown(nbr, S_BAD_TLV_LEN, addr.msgid, - addr.type); + session_shutdown(nbr, S_BAD_TLV_LEN, msg.id, + msg.type); return (-1); } @@ -165,7 +165,7 @@ recv_address(struct nbr *nbr, char *buf, uint16_t len) log_debug("%s: lsr-id %s address %s%s", __func__, inet_ntoa(nbr->id), log_addr(lde_addr.af, &lde_addr.addr), - ntohs(addr.type) == MSG_TYPE_ADDR ? "" : " (withdraw)"); + ntohs(msg.type) == MSG_TYPE_ADDR ? "" : " (withdraw)"); ldpe_imsg_compose_lde(type, nbr->peerid, 0, &lde_addr, sizeof(lde_addr)); @@ -184,7 +184,7 @@ gen_address_list_tlv(struct ibuf *buf, uint16_t size, int af, memset(&alt, 0, sizeof(alt)); alt.type = TLV_TYPE_ADDRLIST; - alt.length = htons(size - TLV_HDR_LEN); + alt.length = htons(size - TLV_HDR_SIZE); switch (af) { case AF_INET: alt.family = htons(AF_IPV4); diff --git a/usr.sbin/ldpd/hello.c b/usr.sbin/ldpd/hello.c index 71d5f485d14..63c93b7b115 100644 --- a/usr.sbin/ldpd/hello.c +++ b/usr.sbin/ldpd/hello.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hello.c,v 1.55 2016/07/01 23:29:55 renato Exp $ */ +/* $OpenBSD: hello.c,v 1.56 2016/07/01 23:36:38 renato Exp $ */ /* * Copyright (c) 2013, 2016 Renato Westphal @@ -146,7 +146,7 @@ send_hello(enum hello_type type, struct iface_af *ia, struct tnbr *tnbr) } void -recv_hello(struct in_addr lsr_id, struct ldp_msg *lm, int af, +recv_hello(struct in_addr lsr_id, struct ldp_msg *msg, int af, union ldpd_addr *src, struct iface *iface, int multicast, char *buf, uint16_t len) { @@ -291,8 +291,8 @@ recv_hello(struct in_addr lsr_id, struct ldp_msg *lm, int af, log_debug("%s: lsr-id %s: remote transport preference does not " "match the local preference", __func__, inet_ntoa(lsr_id)); if (nbr) - session_shutdown(nbr, S_TRANS_MISMTCH, lm->msgid, - lm->type); + session_shutdown(nbr, S_TRANS_MISMTCH, msg->id, + msg->type); if (adj) adj_del(adj, S_SHUTDOWN); return; @@ -307,14 +307,14 @@ recv_hello(struct in_addr lsr_id, struct ldp_msg *lm, int af, case AF_INET: if (nbr_adj_count(nbr, AF_INET6) > 0) { session_shutdown(nbr, S_DS_NONCMPLNCE, - lm->msgid, lm->type); + msg->id, msg->type); return; } break; case AF_INET6: if (nbr_adj_count(nbr, AF_INET) > 0) { session_shutdown(nbr, S_DS_NONCMPLNCE, - lm->msgid, lm->type); + msg->id, msg->type); return; } break; @@ -468,7 +468,7 @@ tlv_decode_hello_prms(char *buf, uint16_t len, uint16_t *holdtime, if (tlv.type != htons(TLV_TYPE_COMMONHELLO)) return (-1); - if (ntohs(tlv.length) != sizeof(tlv) - TLV_HDR_LEN) + if (ntohs(tlv.length) != sizeof(tlv) - TLV_HDR_SIZE) return (-1); *holdtime = ntohs(tlv.holdtime); @@ -502,10 +502,10 @@ tlv_decode_opt_hello_prms(char *buf, uint16_t len, int *tlvs_rcvd, int af, * given address family". */ while (len >= sizeof(tlv)) { - memcpy(&tlv, buf, TLV_HDR_LEN); - buf += TLV_HDR_LEN; - len -= TLV_HDR_LEN; - total += TLV_HDR_LEN; + memcpy(&tlv, buf, TLV_HDR_SIZE); + buf += TLV_HDR_SIZE; + len -= TLV_HDR_SIZE; + total += TLV_HDR_SIZE; tlv_len = ntohs(tlv.length); switch (ntohs(tlv.type)) { diff --git a/usr.sbin/ldpd/init.c b/usr.sbin/ldpd/init.c index 819dd14086c..56cc14dcda0 100644 --- a/usr.sbin/ldpd/init.c +++ b/usr.sbin/ldpd/init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init.c,v 1.31 2016/07/01 23:29:55 renato Exp $ */ +/* $OpenBSD: init.c,v 1.32 2016/07/01 23:36:38 renato Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -56,37 +56,37 @@ send_init(struct nbr *nbr) int recv_init(struct nbr *nbr, char *buf, uint16_t len) { - struct ldp_msg init; + struct ldp_msg msg; struct sess_prms_tlv sess; uint16_t max_pdu_len; int r; log_debug("%s: lsr-id %s", __func__, inet_ntoa(nbr->id)); - memcpy(&init, buf, sizeof(init)); + memcpy(&msg, buf, sizeof(msg)); buf += LDP_MSG_SIZE; len -= LDP_MSG_SIZE; if (len < SESS_PRMS_SIZE) { - session_shutdown(nbr, S_BAD_MSG_LEN, init.msgid, init.type); + session_shutdown(nbr, S_BAD_MSG_LEN, msg.id, msg.type); return (-1); } memcpy(&sess, buf, sizeof(sess)); - if (ntohs(sess.length) != SESS_PRMS_SIZE - TLV_HDR_LEN) { - session_shutdown(nbr, S_BAD_TLV_LEN, init.msgid, init.type); + if (ntohs(sess.length) != SESS_PRMS_LEN) { + session_shutdown(nbr, S_BAD_TLV_LEN, msg.id, msg.type); return (-1); } if (ntohs(sess.proto_version) != LDP_VERSION) { - session_shutdown(nbr, S_BAD_PROTO_VER, init.msgid, init.type); + session_shutdown(nbr, S_BAD_PROTO_VER, msg.id, msg.type); return (-1); } if (ntohs(sess.keepalive_time) < MIN_KEEPALIVE) { - session_shutdown(nbr, S_KEEPALIVE_BAD, init.msgid, init.type); + session_shutdown(nbr, S_KEEPALIVE_BAD, msg.id, msg.type); return (-1); } if (sess.lsr_id != leconf->rtr_id.s_addr || ntohs(sess.lspace_id) != 0) { - session_shutdown(nbr, S_NO_HELLO, init.msgid, init.type); + session_shutdown(nbr, S_NO_HELLO, msg.id, msg.type); return (-1); } @@ -96,7 +96,7 @@ recv_init(struct nbr *nbr, char *buf, uint16_t len) /* just ignore all optional TLVs for now */ r = tlv_decode_opt_init_prms(buf, len); if (r == -1 || r != len) { - session_shutdown(nbr, S_BAD_TLV_VAL, init.msgid, init.type); + session_shutdown(nbr, S_BAD_TLV_VAL, msg.id, msg.type); return (-1); } @@ -125,7 +125,7 @@ gen_init_prms_tlv(struct ibuf *buf, struct nbr *nbr) memset(&parms, 0, sizeof(parms)); parms.type = htons(TLV_TYPE_COMMONSESSION); - parms.length = htons(SESS_PRMS_SIZE - TLV_HDR_LEN); + parms.length = htons(SESS_PRMS_LEN); parms.proto_version = htons(LDP_VERSION); parms.keepalive_time = htons(nbr_get_keepalive(nbr->af, nbr->id)); parms.reserved = 0; @@ -145,10 +145,10 @@ tlv_decode_opt_init_prms(char *buf, uint16_t len) int total = 0; while (len >= sizeof(tlv)) { - memcpy(&tlv, buf, TLV_HDR_LEN); - buf += TLV_HDR_LEN; - len -= TLV_HDR_LEN; - total += TLV_HDR_LEN; + memcpy(&tlv, buf, TLV_HDR_SIZE); + buf += TLV_HDR_SIZE; + len -= TLV_HDR_SIZE; + total += TLV_HDR_SIZE; tlv_len = ntohs(tlv.length); switch (ntohs(tlv.type)) { diff --git a/usr.sbin/ldpd/keepalive.c b/usr.sbin/ldpd/keepalive.c index 10cdecb80ff..9ab271f35a1 100644 --- a/usr.sbin/ldpd/keepalive.c +++ b/usr.sbin/ldpd/keepalive.c @@ -1,4 +1,4 @@ -/* $OpenBSD: keepalive.c,v 1.16 2016/05/23 19:11:42 renato Exp $ */ +/* $OpenBSD: keepalive.c,v 1.17 2016/07/01 23:36:38 renato Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -43,11 +43,11 @@ send_keepalive(struct nbr *nbr) int recv_keepalive(struct nbr *nbr, char *buf, uint16_t len) { - struct ldp_msg ka; + struct ldp_msg msg; - memcpy(&ka, buf, sizeof(ka)); + memcpy(&msg, buf, sizeof(msg)); if (len != LDP_MSG_SIZE) { - session_shutdown(nbr, S_BAD_MSG_LEN, ka.msgid, ka.type); + session_shutdown(nbr, S_BAD_MSG_LEN, msg.id, msg.type); return (-1); } diff --git a/usr.sbin/ldpd/l2vpn.c b/usr.sbin/ldpd/l2vpn.c index cdd0985ef5c..6996a39088d 100644 --- a/usr.sbin/ldpd/l2vpn.c +++ b/usr.sbin/ldpd/l2vpn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: l2vpn.c,v 1.20 2016/07/01 23:33:46 renato Exp $ */ +/* $OpenBSD: l2vpn.c,v 1.21 2016/07/01 23:36:38 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal @@ -258,7 +258,7 @@ int l2vpn_pw_negotiate(struct lde_nbr *ln, struct fec_node *fn, struct map *map) { struct l2vpn_pw *pw; - struct status_tlv status; + struct status_tlv st; /* NOTE: thanks martini & friends for all this mess */ @@ -279,10 +279,10 @@ l2vpn_pw_negotiate(struct lde_nbr *ln, struct fec_node *fn, struct map *map) } else if (!(map->flags & F_MAP_PW_CWORD) && (pw->flags & F_PW_CWORD_CONF)) { /* append a "Wrong C-bit" status code */ - status.status_code = S_WRONG_CBIT; - status.msg_id = map->messageid; - status.msg_type = htons(MSG_TYPE_LABELMAPPING); - lde_send_labelwithdraw(ln, fn, NO_LABEL, &status); + st.status_code = S_WRONG_CBIT; + st.msg_id = map->msg_id; + st.msg_type = htons(MSG_TYPE_LABELMAPPING); + lde_send_labelwithdraw(ln, fn, NO_LABEL, &st); pw->flags &= ~F_PW_CWORD; lde_send_labelmapping(ln, fn, 1); @@ -310,11 +310,9 @@ l2vpn_send_pw_status(uint32_t peerid, uint32_t status, struct fec *fec) struct notify_msg nm; memset(&nm, 0, sizeof(nm)); - nm.status = S_PW_STATUS; - + nm.status_code = S_PW_STATUS; nm.pw_status = status; nm.flags |= F_NOTIF_PW_STATUS; - lde_fec2map(fec, &nm.fec); nm.flags |= F_NOTIF_FEC; diff --git a/usr.sbin/ldpd/labelmapping.c b/usr.sbin/ldpd/labelmapping.c index 501cec93075..6b592f020d9 100644 --- a/usr.sbin/ldpd/labelmapping.c +++ b/usr.sbin/ldpd/labelmapping.c @@ -1,4 +1,4 @@ -/* $OpenBSD: labelmapping.c,v 1.54 2016/07/01 23:33:46 renato Exp $ */ +/* $OpenBSD: labelmapping.c,v 1.55 2016/07/01 23:36:38 renato Exp $ */ /* * Copyright (c) 2014, 2015 Renato Westphal @@ -74,7 +74,7 @@ send_labelmessage(struct nbr *nbr, uint16_t type, struct mapping_head *mh) } /* calculate size */ - msg_size = LDP_MSG_SIZE + TLV_HDR_LEN; + msg_size = LDP_MSG_SIZE + TLV_HDR_SIZE; switch (me->map.type) { case MAP_TYPE_WILDCARD: msg_size += FEC_ELM_WCARD_LEN; @@ -85,19 +85,18 @@ send_labelmessage(struct nbr *nbr, uint16_t type, struct mapping_head *mh) break; case MAP_TYPE_PWID: msg_size += FEC_PWID_ELM_MIN_LEN; - if (me->map.flags & F_MAP_PW_ID) - msg_size += sizeof(uint32_t); + msg_size += PW_STATUS_TLV_LEN; if (me->map.flags & F_MAP_PW_IFMTU) - msg_size += FEC_SUBTLV_IFMTU_LEN; + msg_size += FEC_SUBTLV_IFMTU_SIZE; if (me->map.flags & F_MAP_PW_STATUS) - msg_size += PW_STATUS_TLV_LEN; + msg_size += PW_STATUS_TLV_SIZE; break; } if (me->map.label != NO_LABEL) - msg_size += LABEL_TLV_LEN; + msg_size += LABEL_TLV_SIZE; if (me->map.flags & F_MAP_REQ_ID) - msg_size += REQID_TLV_LEN; + msg_size += REQID_TLV_SIZE; if (me->map.flags & F_MAP_STATUS) msg_size += STATUS_SIZE; @@ -120,8 +119,8 @@ send_labelmessage(struct nbr *nbr, uint16_t type, struct mapping_head *mh) if (me->map.flags & F_MAP_PW_STATUS) err |= gen_pw_status_tlv(buf, me->map.pw_status); if (me->map.flags & F_MAP_STATUS) - err |= gen_status_tlv(buf, me->map.status.code, - me->map.status.msg_id, me->map.status.msg_type); + err |= gen_status_tlv(buf, me->map.st.status_code, + me->map.st.msg_id, me->map.st.msg_type); if (err) { ibuf_free(buf); return; @@ -140,7 +139,7 @@ send_labelmessage(struct nbr *nbr, uint16_t type, struct mapping_head *mh) int recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type) { - struct ldp_msg lm; + struct ldp_msg msg; struct tlv ft; uint32_t label = NO_LABEL, reqid = 0; uint32_t pw_status = 0; @@ -150,45 +149,44 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type) struct mapping_head mh; struct map map; - memcpy(&lm, buf, sizeof(lm)); + memcpy(&msg, buf, sizeof(msg)); buf += LDP_MSG_SIZE; len -= LDP_MSG_SIZE; /* FEC TLV */ if (len < sizeof(ft)) { - session_shutdown(nbr, S_BAD_TLV_LEN, lm.msgid, lm.type); + session_shutdown(nbr, S_BAD_TLV_LEN, msg.id, msg.type); return (-1); } memcpy(&ft, buf, sizeof(ft)); if (ntohs(ft.type) != TLV_TYPE_FEC) { - send_notification_nbr(nbr, S_MISS_MSG, lm.msgid, lm.type); + send_notification_nbr(nbr, S_MISS_MSG, msg.id, msg.type); return (-1); } feclen = ntohs(ft.length); - - if (feclen > len - TLV_HDR_LEN) { - session_shutdown(nbr, S_BAD_TLV_LEN, lm.msgid, lm.type); + if (feclen > len - TLV_HDR_SIZE) { + session_shutdown(nbr, S_BAD_TLV_LEN, msg.id, msg.type); return (-1); } - buf += TLV_HDR_LEN; /* just advance to the end of the fec header */ - len -= TLV_HDR_LEN; + buf += TLV_HDR_SIZE; /* just advance to the end of the fec header */ + len -= TLV_HDR_SIZE; TAILQ_INIT(&mh); do { memset(&map, 0, sizeof(map)); - map.messageid = lm.msgid; + map.msg_id = msg.id; - if ((tlen = tlv_decode_fec_elm(nbr, &lm, buf, feclen, + if ((tlen = tlv_decode_fec_elm(nbr, &msg, buf, feclen, &map)) == -1) goto err; if (map.type == MAP_TYPE_PWID && !(map.flags & F_MAP_PW_ID) && type != MSG_TYPE_LABELWITHDRAW && type != MSG_TYPE_LABELRELEASE) { - send_notification_nbr(nbr, S_MISS_MSG, lm.msgid, - lm.type); + send_notification_nbr(nbr, S_MISS_MSG, msg.id, + msg.type); return (-1); } @@ -201,8 +199,8 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type) case MSG_TYPE_LABELMAPPING: case MSG_TYPE_LABELREQUEST: case MSG_TYPE_LABELABORTREQ: - session_shutdown(nbr, S_UNKNOWN_FEC, lm.msgid, - lm.type); + session_shutdown(nbr, S_UNKNOWN_FEC, msg.id, + msg.type); goto err; default: break; @@ -215,8 +213,7 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type) */ if (type != MSG_TYPE_LABELMAPPING && tlen != feclen) { - session_shutdown(nbr, S_BAD_TLV_VAL, lm.msgid, - lm.type); + session_shutdown(nbr, S_BAD_TLV_VAL, msg.id, msg.type); goto err; } @@ -229,7 +226,7 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type) /* Mandatory Label TLV */ if (type == MSG_TYPE_LABELMAPPING) { - lbllen = tlv_decode_label(nbr, &lm, buf, len, &label); + lbllen = tlv_decode_label(nbr, &msg, buf, len, &label); if (lbllen == -1) goto err; @@ -244,14 +241,13 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type) uint32_t reqbuf, labelbuf, statusbuf; if (len < sizeof(tlv)) { - session_shutdown(nbr, S_BAD_TLV_LEN, lm.msgid, - lm.type); + session_shutdown(nbr, S_BAD_TLV_LEN, msg.id, msg.type); goto err; } - memcpy(&tlv, buf, TLV_HDR_LEN); - buf += TLV_HDR_LEN; - len -= TLV_HDR_LEN; + memcpy(&tlv, buf, TLV_HDR_SIZE); + buf += TLV_HDR_SIZE; + len -= TLV_HDR_SIZE; tlv_len = ntohs(tlv.length); switch (ntohs(tlv.type)) { @@ -259,9 +255,9 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type) switch (type) { case MSG_TYPE_LABELMAPPING: case MSG_TYPE_LABELREQUEST: - if (tlv_len != 4) { + if (tlv_len != REQID_TLV_LEN) { session_shutdown(nbr, S_BAD_TLV_LEN, - lm.msgid, lm.type); + msg.id, msg.type); goto err; } @@ -278,9 +274,9 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type) switch (type) { case MSG_TYPE_LABELWITHDRAW: case MSG_TYPE_LABELRELEASE: - if (tlv_len != 4) { + if (tlv_len != LABEL_TLV_LEN) { session_shutdown(nbr, S_BAD_TLV_LEN, - lm.msgid, lm.type); + msg.id, msg.type); goto err; } @@ -298,8 +294,8 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type) case MSG_TYPE_LABELWITHDRAW: case MSG_TYPE_LABELRELEASE: /* unsupported */ - session_shutdown(nbr, S_BAD_TLV_VAL, lm.msgid, - lm.type); + session_shutdown(nbr, S_BAD_TLV_VAL, msg.id, + msg.type); goto err; break; default: @@ -309,8 +305,8 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type) break; case TLV_TYPE_STATUS: if (tlv_len != STATUS_TLV_LEN) { - session_shutdown(nbr, S_BAD_TLV_LEN, - lm.msgid, lm.type); + session_shutdown(nbr, S_BAD_TLV_LEN, msg.id, + msg.type); goto err; } /* ignore */ @@ -318,9 +314,9 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type) case TLV_TYPE_PW_STATUS: switch (type) { case MSG_TYPE_LABELMAPPING: - if (tlv_len != 4) { + if (tlv_len != PW_STATUS_TLV_LEN) { session_shutdown(nbr, S_BAD_TLV_LEN, - lm.msgid, lm.type); + msg.id, msg.type); goto err; } @@ -336,7 +332,7 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type) default: if (!(ntohs(tlv.type) & UNKNOWN_FLAG)) { send_notification_nbr(nbr, S_UNKNOWN_TLV, - lm.msgid, lm.type); + msg.id, msg.type); } /* ignore unknown tlv */ break; @@ -356,7 +352,7 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type) case AF_IPV4: if (label == MPLS_LABEL_IPV6NULL) { session_shutdown(nbr, S_BAD_TLV_VAL, - lm.msgid, lm.type); + msg.id, msg.type); goto err; } if (!nbr->v4_enabled) @@ -365,7 +361,7 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type) case AF_IPV6: if (label == MPLS_LABEL_IPV4NULL) { session_shutdown(nbr, S_BAD_TLV_VAL, - lm.msgid, lm.type); + msg.id, msg.type); goto err; } if (!nbr->v6_enabled) @@ -377,8 +373,8 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type) break; case MAP_TYPE_PWID: if (label <= MPLS_LABEL_RESERVED_MAX) { - session_shutdown(nbr, S_BAD_TLV_VAL, lm.msgid, - lm.type); + session_shutdown(nbr, S_BAD_TLV_VAL, msg.id, + msg.type); goto err; } if (me->map.flags & F_MAP_PW_STATUS) @@ -445,34 +441,34 @@ gen_label_tlv(struct ibuf *buf, uint32_t label) struct label_tlv lt; lt.type = htons(TLV_TYPE_GENERICLABEL); - lt.length = htons(sizeof(label)); + lt.length = htons(LABEL_TLV_LEN); lt.label = htonl(label); return (ibuf_add(buf, <, sizeof(lt))); } static int -tlv_decode_label(struct nbr *nbr, struct ldp_msg *lm, char *buf, +tlv_decode_label(struct nbr *nbr, struct ldp_msg *msg, char *buf, uint16_t len, uint32_t *label) { struct label_tlv lt; if (len < sizeof(lt)) { - session_shutdown(nbr, S_BAD_TLV_LEN, lm->msgid, lm->type); + session_shutdown(nbr, S_BAD_TLV_LEN, msg->id, msg->type); return (-1); } memcpy(<, buf, sizeof(lt)); if (!(ntohs(lt.type) & TLV_TYPE_GENERICLABEL)) { - send_notification_nbr(nbr, S_MISS_MSG, lm->msgid, lm->type); + send_notification_nbr(nbr, S_MISS_MSG, msg->id, msg->type); return (-1); } switch (htons(lt.type)) { case TLV_TYPE_GENERICLABEL: - if (ntohs(lt.length) != sizeof(lt) - TLV_HDR_LEN) { - session_shutdown(nbr, S_BAD_TLV_LEN, lm->msgid, - lm->type); + if (ntohs(lt.length) != sizeof(lt) - TLV_HDR_SIZE) { + session_shutdown(nbr, S_BAD_TLV_LEN, msg->id, + msg->type); return (-1); } @@ -482,8 +478,8 @@ tlv_decode_label(struct nbr *nbr, struct ldp_msg *lm, char *buf, *label != MPLS_LABEL_IPV4NULL && *label != MPLS_LABEL_IPV6NULL && *label != MPLS_LABEL_IMPLNULL)) { - session_shutdown(nbr, S_BAD_TLV_VAL, lm->msgid, - lm->type); + session_shutdown(nbr, S_BAD_TLV_VAL, msg->id, + msg->type); return (-1); } break; @@ -491,7 +487,7 @@ tlv_decode_label(struct nbr *nbr, struct ldp_msg *lm, char *buf, case TLV_TYPE_FRLABEL: default: /* unsupported */ - session_shutdown(nbr, S_BAD_TLV_VAL, lm->msgid, lm->type); + session_shutdown(nbr, S_BAD_TLV_VAL, msg->id, msg->type); return (-1); } @@ -504,7 +500,7 @@ gen_reqid_tlv(struct ibuf *buf, uint32_t reqid) struct reqid_tlv rt; rt.type = htons(TLV_TYPE_LABELREQUEST); - rt.length = htons(sizeof(reqid)); + rt.length = htons(REQID_TLV_LEN); rt.reqid = htonl(reqid); return (ibuf_add(buf, &rt, sizeof(rt))); @@ -516,7 +512,7 @@ gen_pw_status_tlv(struct ibuf *buf, uint32_t status) struct pw_status_tlv st; st.type = htons(TLV_TYPE_PW_STATUS); - st.length = htons(sizeof(status)); + st.length = htons(PW_STATUS_TLV_LEN); st.value = htonl(status); return (ibuf_add(buf, &st, sizeof(st))); @@ -555,9 +551,9 @@ gen_fec_tlv(struct ibuf *buf, struct map *map) break; case MAP_TYPE_PWID: if (map->flags & F_MAP_PW_ID) - pw_len += sizeof(uint32_t); + pw_len += PW_STATUS_TLV_LEN; if (map->flags & F_MAP_PW_IFMTU) - pw_len += FEC_SUBTLV_IFMTU_LEN; + pw_len += FEC_SUBTLV_IFMTU_SIZE; len = FEC_PWID_ELM_MIN_LEN + pw_len; @@ -581,7 +577,7 @@ gen_fec_tlv(struct ibuf *buf, struct map *map) struct subtlv stlv; stlv.type = SUBTLV_IFMTU; - stlv.length = FEC_SUBTLV_IFMTU_LEN; + stlv.length = FEC_SUBTLV_IFMTU_SIZE; err |= ibuf_add(buf, &stlv, sizeof(uint16_t)); ifmtu = htons(map->fec.pwid.ifmtu); @@ -596,7 +592,7 @@ gen_fec_tlv(struct ibuf *buf, struct map *map) } int -tlv_decode_fec_elm(struct nbr *nbr, struct ldp_msg *lm, char *buf, +tlv_decode_fec_elm(struct nbr *nbr, struct ldp_msg *msg, char *buf, uint16_t len, struct map *map) { uint16_t off = 0; @@ -610,15 +606,15 @@ tlv_decode_fec_elm(struct nbr *nbr, struct ldp_msg *lm, char *buf, if (len == FEC_ELM_WCARD_LEN) return (off); else { - session_shutdown(nbr, S_BAD_TLV_VAL, lm->msgid, - lm->type); + session_shutdown(nbr, S_BAD_TLV_VAL, msg->id, + msg->type); return (-1); } break; case MAP_TYPE_PREFIX: if (len < FEC_ELM_PREFIX_MIN_LEN) { - session_shutdown(nbr, S_BAD_TLV_LEN, lm->msgid, - lm->type); + session_shutdown(nbr, S_BAD_TLV_LEN, msg->id, + msg->type); return (-1); } @@ -629,8 +625,8 @@ tlv_decode_fec_elm(struct nbr *nbr, struct ldp_msg *lm, char *buf, off += sizeof(map->fec.prefix.af); if (map->fec.prefix.af != AF_IPV4 && map->fec.prefix.af != AF_IPV6) { - send_notification_nbr(nbr, S_UNSUP_ADDR, lm->msgid, - lm->type); + send_notification_nbr(nbr, S_UNSUP_ADDR, msg->id, + msg->type); return (-1); } @@ -638,8 +634,8 @@ tlv_decode_fec_elm(struct nbr *nbr, struct ldp_msg *lm, char *buf, map->fec.prefix.prefixlen = buf[off]; off += sizeof(uint8_t); if (len < off + PREFIX_SIZE(map->fec.prefix.prefixlen)) { - session_shutdown(nbr, S_BAD_TLV_LEN, lm->msgid, - lm->type); + session_shutdown(nbr, S_BAD_TLV_LEN, msg->id, + msg->type); return (-1); } @@ -652,8 +648,8 @@ tlv_decode_fec_elm(struct nbr *nbr, struct ldp_msg *lm, char *buf, return (off + PREFIX_SIZE(map->fec.prefix.prefixlen)); case MAP_TYPE_PWID: if (len < FEC_PWID_ELM_MIN_LEN) { - session_shutdown(nbr, S_BAD_TLV_LEN, lm->msgid, - lm->type); + session_shutdown(nbr, S_BAD_TLV_LEN, msg->id, + msg->type); return (-1); } @@ -671,8 +667,8 @@ tlv_decode_fec_elm(struct nbr *nbr, struct ldp_msg *lm, char *buf, off += sizeof(uint8_t); if (len != FEC_PWID_ELM_MIN_LEN + pw_len) { - session_shutdown(nbr, S_BAD_TLV_LEN, lm->msgid, - lm->type); + session_shutdown(nbr, S_BAD_TLV_LEN, msg->id, + msg->type); return (-1); } @@ -686,8 +682,8 @@ tlv_decode_fec_elm(struct nbr *nbr, struct ldp_msg *lm, char *buf, return (off); if (pw_len < sizeof(uint32_t)) { - session_shutdown(nbr, S_BAD_TLV_LEN, lm->msgid, - lm->type); + session_shutdown(nbr, S_BAD_TLV_LEN, msg->id, + msg->type); return (-1); } @@ -702,21 +698,21 @@ tlv_decode_fec_elm(struct nbr *nbr, struct ldp_msg *lm, char *buf, struct subtlv stlv; if (pw_len < sizeof(stlv)) { - session_shutdown(nbr, S_BAD_TLV_LEN, - lm->msgid, lm->type); + session_shutdown(nbr, S_BAD_TLV_LEN, msg->id, + msg->type); return (-1); } memcpy(&stlv, buf + off, sizeof(stlv)); switch (stlv.type) { case SUBTLV_IFMTU: - if (stlv.length != FEC_SUBTLV_IFMTU_LEN) { + if (stlv.length != FEC_SUBTLV_IFMTU_SIZE) { session_shutdown(nbr, S_BAD_TLV_LEN, - lm->msgid, lm->type); + msg->id, msg->type); return (-1); } memcpy(&map->fec.pwid.ifmtu, buf + off + - SUBTLV_HDR_LEN, sizeof(uint16_t)); + SUBTLV_HDR_SIZE, sizeof(uint16_t)); map->fec.pwid.ifmtu = ntohs(map->fec.pwid.ifmtu); map->flags |= F_MAP_PW_IFMTU; break; @@ -730,7 +726,7 @@ tlv_decode_fec_elm(struct nbr *nbr, struct ldp_msg *lm, char *buf, return (off); default: - send_notification_nbr(nbr, S_UNKNOWN_FEC, lm->msgid, lm->type); + send_notification_nbr(nbr, S_UNKNOWN_FEC, msg->id, msg->type); break; } diff --git a/usr.sbin/ldpd/lde.c b/usr.sbin/ldpd/lde.c index 81fe48e256b..c9f2daf54c2 100644 --- a/usr.sbin/ldpd/lde.c +++ b/usr.sbin/ldpd/lde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lde.c,v 1.60 2016/07/01 23:33:46 renato Exp $ */ +/* $OpenBSD: lde.c,v 1.61 2016/07/01 23:36:38 renato Exp $ */ /* * Copyright (c) 2013, 2016 Renato Westphal @@ -311,7 +311,7 @@ lde_dispatch_imsg(int fd, short event, void *bula) break; } - switch (nm.status) { + switch (nm.status_code) { case S_PW_STATUS: l2vpn_recv_pw_status(ln, &nm); break; @@ -794,7 +794,7 @@ lde_send_labelmapping(struct lde_nbr *ln, struct fec_node *fn, int single) lre = (struct lde_req *)fec_find(&ln->recv_req, &fn->fec); if (lre) { /* set label request msg id in the mapping response. */ - map.requestid = lre->msgid; + map.requestid = lre->msg_id; map.flags = F_MAP_REQ_ID; /* SL.7: delete record of pending request */ @@ -817,7 +817,7 @@ lde_send_labelmapping(struct lde_nbr *ln, struct fec_node *fn, int single) void lde_send_labelwithdraw(struct lde_nbr *ln, struct fec_node *fn, uint32_t label, - struct status_tlv *status) + struct status_tlv *st) { struct lde_wdraw *lw; struct map map; @@ -852,10 +852,10 @@ lde_send_labelwithdraw(struct lde_nbr *ln, struct fec_node *fn, uint32_t label, map.label = label; } - if (status) { - map.status.code = status->status_code; - map.status.msg_id = status->msg_id; - map.status.msg_type = status->msg_type; + if (st) { + map.st.status_code = st->status_code; + map.st.msg_id = st->msg_id; + map.st.msg_type = st->msg_type; map.flags |= F_MAP_STATUS; } @@ -931,16 +931,16 @@ lde_send_labelrelease(struct lde_nbr *ln, struct fec_node *fn, uint32_t label) } void -lde_send_notification(uint32_t peerid, uint32_t code, uint32_t msgid, - uint16_t type) +lde_send_notification(uint32_t peerid, uint32_t status_code, uint32_t msg_id, + uint16_t msg_type) { struct notify_msg nm; memset(&nm, 0, sizeof(nm)); - nm.status = code; - /* 'msgid' and 'type' should be in network byte order */ - nm.messageid = msgid; - nm.type = type; + nm.status_code = status_code; + /* 'msg_id' and 'msg_type' should be in network byte order */ + nm.msg_id = msg_id; + nm.msg_type = msg_type; lde_imsg_compose_ldpe(IMSG_NOTIFICATION_SEND, peerid, 0, &nm, sizeof(nm)); diff --git a/usr.sbin/ldpd/lde.h b/usr.sbin/ldpd/lde.h index 3d2a06c48cb..77431b87a3f 100644 --- a/usr.sbin/ldpd/lde.h +++ b/usr.sbin/ldpd/lde.h @@ -1,4 +1,4 @@ -/* $OpenBSD: lde.h,v 1.42 2016/07/01 23:33:46 renato Exp $ */ +/* $OpenBSD: lde.h,v 1.43 2016/07/01 23:36:38 renato Exp $ */ /* * Copyright (c) 2013, 2016 Renato Westphal @@ -55,8 +55,8 @@ RB_PROTOTYPE(fec_tree, fec, entry, fec_compare) /* request entries */ struct lde_req { - struct fec fec; - uint32_t msgid; + struct fec fec; + uint32_t msg_id; }; /* mapping entries */ diff --git a/usr.sbin/ldpd/lde_lib.c b/usr.sbin/ldpd/lde_lib.c index ac99fbd7e37..29e986151b3 100644 --- a/usr.sbin/ldpd/lde_lib.c +++ b/usr.sbin/ldpd/lde_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lde_lib.c,v 1.62 2016/07/01 23:29:55 renato Exp $ */ +/* $OpenBSD: lde_lib.c,v 1.63 2016/07/01 23:36:38 renato Exp $ */ /* * Copyright (c) 2013, 2016 Renato Westphal @@ -529,7 +529,7 @@ lde_check_request(struct map *map, struct lde_nbr *ln) fn = (struct fec_node *)fec_find(&ft, &fec); if (fn == NULL || LIST_EMPTY(&fn->nexthops)) { /* LRq.5: send No Route notification */ - lde_send_notification(ln->peerid, S_NO_ROUTE, map->messageid, + lde_send_notification(ln->peerid, S_NO_ROUTE, map->msg_id, htons(MSG_TYPE_LABELREQUEST)); return; } @@ -544,7 +544,7 @@ lde_check_request(struct map *map, struct lde_nbr *ln) /* LRq.4: send Loop Detected notification */ lde_send_notification(ln->peerid, S_LOOP_DETECTED, - map->messageid, htons(MSG_TYPE_LABELREQUEST)); + map->msg_id, htons(MSG_TYPE_LABELREQUEST)); return; default: break; @@ -560,7 +560,7 @@ lde_check_request(struct map *map, struct lde_nbr *ln) /* LRq.8: record label request */ lre = lde_req_add(ln, &fn->fec, 0); if (lre != NULL) - lre->msgid = ntohl(map->messageid); + lre->msg_id = ntohl(map->msg_id); /* LRq.9: perform LSR label distribution */ lde_send_labelmapping(ln, fn, 1); diff --git a/usr.sbin/ldpd/ldp.h b/usr.sbin/ldpd/ldp.h index a6442ed33d6..9049db51321 100644 --- a/usr.sbin/ldpd/ldp.h +++ b/usr.sbin/ldpd/ldp.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ldp.h,v 1.32 2016/07/01 23:22:42 renato Exp $ */ +/* $OpenBSD: ldp.h,v 1.33 2016/07/01 23:36:38 renato Exp $ */ /* * Copyright (c) 2013, 2016 Renato Westphal @@ -117,12 +117,12 @@ struct tlv { uint16_t type; uint16_t length; }; -#define TLV_HDR_LEN 4 +#define TLV_HDR_SIZE 4 struct ldp_msg { uint16_t type; uint16_t length; - uint32_t msgid; + uint32_t id; /* Mandatory Parameters */ /* Optional Parameters */ } __packed; @@ -140,7 +140,6 @@ struct hello_prms_tlv { uint16_t holdtime; uint16_t flags; }; - #define F_HELLO_TARGETED 0x8000 #define F_HELLO_REQ_TARG 0x4000 #define F_HELLO_GTSM 0x2000 @@ -216,6 +215,7 @@ struct sess_prms_tlv { } __packed; #define SESS_PRMS_SIZE 18 +#define SESS_PRMS_LEN 14 struct status_tlv { uint16_t type; @@ -258,37 +258,37 @@ struct subtlv { uint8_t type; uint8_t length; }; -#define SUBTLV_HDR_LEN 2 +#define SUBTLV_HDR_SIZE 2 #define SUBTLV_IFMTU 0x01 #define SUBTLV_VLANID 0x06 -#define FEC_SUBTLV_IFMTU_LEN 4 -#define FEC_SUBTLV_VLANID_LEN 4 +#define FEC_SUBTLV_IFMTU_SIZE 4 +#define FEC_SUBTLV_VLANID_SIZE 4 struct label_tlv { uint16_t type; uint16_t length; uint32_t label; }; - -#define LABEL_TLV_LEN 8 +#define LABEL_TLV_SIZE 8 +#define LABEL_TLV_LEN 4 struct reqid_tlv { uint16_t type; uint16_t length; uint32_t reqid; }; - -#define REQID_TLV_LEN 8 +#define REQID_TLV_SIZE 8 +#define REQID_TLV_LEN 4 struct pw_status_tlv { uint16_t type; uint16_t length; uint32_t value; }; - -#define PW_STATUS_TLV_LEN 8 +#define PW_STATUS_TLV_SIZE 8 +#define PW_STATUS_TLV_LEN 4 #define PW_FORWARDING 0 #define PW_NOT_FORWARDING (1 << 0) diff --git a/usr.sbin/ldpd/ldpd.h b/usr.sbin/ldpd/ldpd.h index de7902f381b..8a5f6292fff 100644 --- a/usr.sbin/ldpd/ldpd.h +++ b/usr.sbin/ldpd/ldpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ldpd.h,v 1.79 2016/07/01 23:33:46 renato Exp $ */ +/* $OpenBSD: ldpd.h,v 1.80 2016/07/01 23:36:38 renato Exp $ */ /* * Copyright (c) 2013, 2016 Renato Westphal @@ -191,7 +191,7 @@ TAILQ_HEAD(mapping_head, mapping_entry); struct map { uint8_t type; - uint32_t messageid; + uint32_t msg_id; union { struct { uint16_t af; @@ -206,10 +206,10 @@ struct map { } pwid; } fec; struct { - uint32_t code; + uint32_t status_code; uint32_t msg_id; uint16_t msg_type; - } status; + } st; uint32_t label; uint32_t requestid; uint32_t pw_status; @@ -223,9 +223,9 @@ struct map { #define F_MAP_PW_STATUS 0x20 /* pseudowire status */ struct notify_msg { - uint32_t status; - uint32_t messageid; /* network byte order */ - uint16_t type; /* network byte order */ + uint32_t status_code; + uint32_t msg_id; /* network byte order */ + uint16_t msg_type; /* network byte order */ uint32_t pw_status; struct map fec; uint8_t flags; diff --git a/usr.sbin/ldpd/log.c b/usr.sbin/ldpd/log.c index 16c1bbcae54..46224a50b6b 100644 --- a/usr.sbin/ldpd/log.c +++ b/usr.sbin/ldpd/log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: log.c,v 1.27 2016/05/23 19:11:42 renato Exp $ */ +/* $OpenBSD: log.c,v 1.28 2016/07/01 23:36:38 renato Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -318,7 +318,7 @@ if_type_name(enum iface_type type) } const char * -notification_name(uint32_t status) +status_code_name(uint32_t status) { static char buf[16]; diff --git a/usr.sbin/ldpd/log.h b/usr.sbin/ldpd/log.h index 18a338ac7af..01189027aad 100644 --- a/usr.sbin/ldpd/log.h +++ b/usr.sbin/ldpd/log.h @@ -1,4 +1,4 @@ -/* $OpenBSD: log.h,v 1.11 2016/05/23 19:09:25 renato Exp $ */ +/* $OpenBSD: log.h,v 1.12 2016/07/01 23:36:38 renato Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -44,7 +44,7 @@ const char *socket_name(int); const char *nbr_state_name(int); const char *if_state_name(int); const char *if_type_name(enum iface_type); -const char *notification_name(uint32_t); +const char *status_code_name(uint32_t); const char *pw_type_name(uint16_t); char *log_hello_src(const struct hello_source *); const char *log_map(const struct map *); diff --git a/usr.sbin/ldpd/notification.c b/usr.sbin/ldpd/notification.c index b482c099068..73788da9133 100644 --- a/usr.sbin/ldpd/notification.c +++ b/usr.sbin/ldpd/notification.c @@ -1,4 +1,4 @@ -/* $OpenBSD: notification.c,v 1.38 2016/07/01 23:33:46 renato Exp $ */ +/* $OpenBSD: notification.c,v 1.39 2016/07/01 23:36:38 renato Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -35,9 +35,9 @@ 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) - size += PW_STATUS_TLV_LEN; + size += PW_STATUS_TLV_SIZE; if (nm->flags & F_NOTIF_FEC) { - size += TLV_HDR_LEN; + size += TLV_HDR_SIZE; switch (nm->fec.type) { case MAP_TYPE_PWID: size += FEC_PWID_ELM_MIN_LEN; @@ -53,7 +53,7 @@ send_notification_full(struct tcp_conn *tcp, struct notify_msg *nm) 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, nm->messageid, nm->type); + 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); @@ -69,58 +69,58 @@ send_notification_full(struct tcp_conn *tcp, struct notify_msg *nm) /* send a notification without optional tlvs */ void -send_notification(uint32_t status, struct tcp_conn *tcp, uint32_t msgid, - uint16_t type) +send_notification(uint32_t status_code, struct tcp_conn *tcp, uint32_t msg_id, + uint16_t msg_type) { struct notify_msg nm; memset(&nm, 0, sizeof(nm)); - nm.status = status; - nm.messageid = msgid; - nm.type = type; + nm.status_code = status_code; + nm.msg_id = msg_id; + nm.msg_type = msg_type; send_notification_full(tcp, &nm); } void -send_notification_nbr(struct nbr *nbr, uint32_t status, uint32_t msgid, - uint16_t type) +send_notification_nbr(struct nbr *nbr, uint32_t status_code, uint32_t msg_id, + uint16_t msg_type) { log_debug("%s: lsr-id %s, status %s", __func__, inet_ntoa(nbr->id), - notification_name(status)); + status_code_name(status_code)); - send_notification(status, nbr->tcp, msgid, 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) { - struct ldp_msg not; + struct ldp_msg msg; struct status_tlv st; struct notify_msg nm; int tlen; - memcpy(¬, buf, sizeof(not)); + memcpy(&msg, buf, sizeof(msg)); buf += LDP_MSG_SIZE; len -= LDP_MSG_SIZE; if (len < STATUS_SIZE) { - session_shutdown(nbr, S_BAD_MSG_LEN, not.msgid, not.type); + session_shutdown(nbr, S_BAD_MSG_LEN, msg.id, msg.type); return (-1); } memcpy(&st, buf, sizeof(st)); - if (ntohs(st.length) > STATUS_SIZE - TLV_HDR_LEN || - ntohs(st.length) > len - TLV_HDR_LEN) { - session_shutdown(nbr, S_BAD_TLV_LEN, not.msgid, not.type); + if (ntohs(st.length) > STATUS_SIZE - TLV_HDR_SIZE || + ntohs(st.length) > len - TLV_HDR_SIZE) { + session_shutdown(nbr, S_BAD_TLV_LEN, msg.id, msg.type); return (-1); } buf += STATUS_SIZE; len -= STATUS_SIZE; memset(&nm, 0, sizeof(nm)); - nm.status = ntohl(st.status_code); + nm.status_code = ntohl(st.status_code); /* Optional Parameters */ while (len > 0) { @@ -128,14 +128,14 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len) uint16_t tlv_len; if (len < sizeof(tlv)) { - session_shutdown(nbr, S_BAD_TLV_LEN, not.msgid, - not.type); + session_shutdown(nbr, S_BAD_TLV_LEN, msg.id, + msg.type); return (-1); } - memcpy(&tlv, buf, TLV_HDR_LEN); - buf += TLV_HDR_LEN; - len -= TLV_HDR_LEN; + memcpy(&tlv, buf, TLV_HDR_SIZE); + buf += TLV_HDR_SIZE; + len -= TLV_HDR_SIZE; tlv_len = ntohs(tlv.length); switch (ntohs(tlv.type)) { @@ -147,7 +147,7 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len) case TLV_TYPE_PW_STATUS: if (tlv_len != 4) { session_shutdown(nbr, S_BAD_TLV_LEN, - not.msgid, not.type); + msg.id, msg.type); return (-1); } @@ -155,13 +155,13 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len) nm.flags |= F_NOTIF_PW_STATUS; break; case TLV_TYPE_FEC: - if ((tlen = tlv_decode_fec_elm(nbr, ¬, buf, + if ((tlen = tlv_decode_fec_elm(nbr, &msg, buf, tlv_len, &nm.fec)) == -1) return (-1); /* allow only one fec element */ if (tlen != tlv_len) { session_shutdown(nbr, S_BAD_TLV_VAL, - not.msgid, not.type); + msg.id, msg.type); return (-1); } nm.flags |= F_NOTIF_FEC; @@ -169,7 +169,7 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len) default: if (!(ntohs(tlv.type) & UNKNOWN_FLAG)) { send_notification_nbr(nbr, S_UNKNOWN_TLV, - not.msgid, not.type); + msg.id, msg.type); } /* ignore unknown tlv */ break; @@ -178,10 +178,10 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len) len -= tlv_len; } - if (nm.status == S_PW_STATUS) { + if (nm.status_code == S_PW_STATUS) { if (!(nm.flags & (F_NOTIF_PW_STATUS|F_NOTIF_FEC))) { send_notification_nbr(nbr, S_MISS_MSG, - not.msgid, not.type); + msg.id, msg.type); return (-1); } @@ -190,7 +190,7 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len) break; default: send_notification_nbr(nbr, S_BAD_TLV_VAL, - not.msgid, not.type); + msg.id, msg.type); return (-1); } } @@ -198,11 +198,11 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len) if (st.status_code & htonl(STATUS_FATAL)) log_warnx("received notification from lsr-id %s: %s", inet_ntoa(nbr->id), - notification_name(ntohl(st.status_code))); + status_code_name(ntohl(st.status_code))); else log_debug("received non-fatal notification from lsr-id " "%s: %s", inet_ntoa(nbr->id), - notification_name(ntohl(st.status_code))); + status_code_name(ntohl(st.status_code))); if (st.status_code & htonl(STATUS_FATAL)) { if (nbr->state == NBR_STA_OPENSENT) @@ -212,7 +212,7 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len) return (-1); } - if (nm.status == S_PW_STATUS) + if (nm.status_code == S_PW_STATUS) ldpe_imsg_compose_lde(IMSG_NOTIFICATION, nbr->peerid, 0, &nm, sizeof(nm)); @@ -220,19 +220,21 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len) } int -gen_status_tlv(struct ibuf *buf, uint32_t status, uint32_t msgid, uint16_t type) +gen_status_tlv(struct ibuf *buf, uint32_t status_code, uint32_t msg_id, + uint16_t msg_type) { struct status_tlv st; memset(&st, 0, sizeof(st)); - st.type = htons(TLV_TYPE_STATUS); st.length = htons(STATUS_TLV_LEN); - st.status_code = htonl(status); - - /* for convenience, msgid and type are already in network byte order */ - st.msg_id = msgid; - st.msg_type = type; + st.status_code = htonl(status_code); + /* + * For convenience, msg_id and msg_type are already in network + * byte order. + */ + st.msg_id = msg_id; + st.msg_type = msg_type; return (ibuf_add(buf, &st, STATUS_SIZE)); } diff --git a/usr.sbin/ldpd/packet.c b/usr.sbin/ldpd/packet.c index fa3f1941c60..adbe29273cf 100644 --- a/usr.sbin/ldpd/packet.c +++ b/usr.sbin/ldpd/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.66 2016/07/01 23:29:55 renato Exp $ */ +/* $OpenBSD: packet.c,v 1.67 2016/07/01 23:36:38 renato Exp $ */ /* * Copyright (c) 2013, 2016 Renato Westphal @@ -66,7 +66,7 @@ gen_msg_hdr(struct ibuf *buf, uint32_t type, uint16_t size) msg.type = htons(type); /* exclude the 'Type' and 'Length' fields from the total */ msg.length = htons(size - LDP_MSG_DEAD_LEN); - msg.msgid = htonl(++msgcnt); + msg.id = htonl(++msgcnt); return (ibuf_add(buf, &msg, sizeof(msg))); } @@ -122,7 +122,7 @@ disc_recv_packet(int fd, short event, void *bula) struct cmsghdr hdr; char buf[CMSG_SPACE(CMSG_MAXLEN)]; } cmsgbuf; - struct msghdr msg; + struct msghdr m; struct sockaddr_storage from; struct iovec iov; char *buf; @@ -136,7 +136,7 @@ disc_recv_packet(int fd, short event, void *bula) uint16_t len; struct ldp_hdr ldp_hdr; uint16_t pdu_len; - struct ldp_msg ldp_msg; + struct ldp_msg msg; uint16_t msg_len; struct in_addr lsr_id; @@ -144,24 +144,24 @@ disc_recv_packet(int fd, short event, void *bula) return; /* setup buffer */ - memset(&msg, 0, sizeof(msg)); + memset(&m, 0, sizeof(m)); iov.iov_base = buf = pkt_ptr; iov.iov_len = IBUF_READ_SIZE; - msg.msg_name = &from; - msg.msg_namelen = sizeof(from); - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - msg.msg_control = &cmsgbuf.buf; - msg.msg_controllen = sizeof(cmsgbuf.buf); - - if ((r = recvmsg(fd, &msg, 0)) == -1) { + m.msg_name = &from; + m.msg_namelen = sizeof(from); + m.msg_iov = &iov; + m.msg_iovlen = 1; + m.msg_control = &cmsgbuf.buf; + m.msg_controllen = sizeof(cmsgbuf.buf); + + if ((r = recvmsg(fd, &m, 0)) == -1) { if (errno != EAGAIN && errno != EINTR) log_debug("%s: read error: %s", __func__, strerror(errno)); return; } - multicast = (msg.msg_flags & MSG_MCAST) ? 1 : 0; + multicast = (m.msg_flags & MSG_MCAST) ? 1 : 0; sa2addr((struct sockaddr *)&from, &af, &src); if (bad_addr(af, &src)) { log_debug("%s: invalid source address: %s", __func__, @@ -169,8 +169,8 @@ disc_recv_packet(int fd, short event, void *bula) return; } - for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; - cmsg = CMSG_NXTHDR(&msg, cmsg)) { + for (cmsg = CMSG_FIRSTHDR(&m); cmsg != NULL; + cmsg = CMSG_NXTHDR(&m, cmsg)) { if (af == AF_INET && cmsg->cmsg_level == IPPROTO_IP && cmsg->cmsg_type == IP_RECVIF) { ifindex = ((struct sockaddr_dl *) @@ -228,23 +228,22 @@ disc_recv_packet(int fd, short event, void *bula) * not impose any restrictions since LDP uses UDP only for sending Hello * packets. */ - memcpy(&ldp_msg, buf, sizeof(ldp_msg)); + memcpy(&msg, buf, sizeof(msg)); /* check "Message Length" field */ - msg_len = ntohs(ldp_msg.length); + msg_len = ntohs(msg.length); if (msg_len < LDP_MSG_LEN || ((msg_len + LDP_MSG_DEAD_LEN) > pdu_len)) { log_debug("%s: invalid LDP message length %u, source %s", - __func__, ntohs(ldp_msg.length), log_addr(af, &src)); + __func__, ntohs(msg.length), log_addr(af, &src)); return; } buf += LDP_MSG_SIZE; len -= LDP_MSG_SIZE; /* switch LDP packet type */ - switch (ntohs(ldp_msg.type)) { + switch (ntohs(msg.type)) { case MSG_TYPE_HELLO: - recv_hello(lsr_id, &ldp_msg, af, &src, iface, multicast, - buf, len); + recv_hello(lsr_id, &msg, af, &src, iface, multicast, buf, len); break; default: log_debug("%s: unknown LDP packet type, source %s", __func__, @@ -419,7 +418,7 @@ session_read(int fd, short event, void *arg) struct nbr *nbr = arg; struct tcp_conn *tcp = nbr->tcp; struct ldp_hdr *ldp_hdr; - struct ldp_msg *ldp_msg; + struct ldp_msg *msg; char *buf, *pdu; ssize_t n, len; uint16_t pdu_len, msg_len, msg_size, max_pdu_len; @@ -486,13 +485,13 @@ session_read(int fd, short event, void *arg) while (len >= LDP_MSG_SIZE) { uint16_t type; - ldp_msg = (struct ldp_msg *)pdu; - type = ntohs(ldp_msg->type); - msg_len = ntohs(ldp_msg->length); + msg = (struct ldp_msg *)pdu; + type = ntohs(msg->type); + msg_len = ntohs(msg->length); msg_size = msg_len + LDP_MSG_DEAD_LEN; if (msg_len < LDP_MSG_LEN || msg_size > pdu_len) { - session_shutdown(nbr, S_BAD_TLV_LEN, - ldp_msg->msgid, ldp_msg->type); + session_shutdown(nbr, S_BAD_TLV_LEN, msg->id, + msg->type); free(buf); return; } @@ -504,7 +503,7 @@ session_read(int fd, short event, void *arg) if ((nbr->state != NBR_STA_INITIAL) && (nbr->state != NBR_STA_OPENSENT)) { session_shutdown(nbr, S_SHUTDOWN, - ldp_msg->msgid, ldp_msg->type); + msg->id, msg->type); free(buf); return; } @@ -513,7 +512,7 @@ session_read(int fd, short event, void *arg) if ((nbr->state == NBR_STA_INITIAL) || (nbr->state == NBR_STA_OPENSENT)) { session_shutdown(nbr, S_SHUTDOWN, - ldp_msg->msgid, ldp_msg->type); + msg->id, msg->type); free(buf); return; } @@ -527,7 +526,7 @@ session_read(int fd, short event, void *arg) case MSG_TYPE_LABELABORTREQ: if (nbr->state != NBR_STA_OPER) { session_shutdown(nbr, S_SHUTDOWN, - ldp_msg->msgid, ldp_msg->type); + msg->id, msg->type); free(buf); return; } @@ -562,10 +561,9 @@ session_read(int fd, short event, void *arg) default: log_debug("%s: unknown LDP message from nbr %s", __func__, inet_ntoa(nbr->id)); - if (!(ntohs(ldp_msg->type) & UNKNOWN_FLAG)) + if (!(ntohs(msg->type) & UNKNOWN_FLAG)) send_notification_nbr(nbr, - S_UNKNOWN_MSG, ldp_msg->msgid, - ldp_msg->type); + S_UNKNOWN_MSG, msg->id, msg->type); /* ignore the message */ ret = 0; break; @@ -615,8 +613,8 @@ session_write(int fd, short event, void *arg) } void -session_shutdown(struct nbr *nbr, uint32_t status, uint32_t msgid, - uint32_t type) +session_shutdown(struct nbr *nbr, uint32_t status, uint32_t msg_id, + uint32_t msg_type) { switch (nbr->state) { case NBR_STA_PRESENT: @@ -629,7 +627,7 @@ session_shutdown(struct nbr *nbr, uint32_t status, uint32_t msgid, case NBR_STA_OPER: log_debug("%s: lsr-id %s", __func__, inet_ntoa(nbr->id)); - send_notification_nbr(nbr, status, msgid, type); + send_notification_nbr(nbr, status, msg_id, msg_type); nbr_fsm(nbr, NBR_EVT_CLOSE_SESSION); break;