diff options
-rw-r--r-- | usr.sbin/ldpd/address.c | 27 | ||||
-rw-r--r-- | usr.sbin/ldpd/hello.c | 6 | ||||
-rw-r--r-- | usr.sbin/ldpd/init.c | 9 | ||||
-rw-r--r-- | usr.sbin/ldpd/keepalive.c | 7 | ||||
-rw-r--r-- | usr.sbin/ldpd/labelmapping.c | 61 | ||||
-rw-r--r-- | usr.sbin/ldpd/lde.c | 18 | ||||
-rw-r--r-- | usr.sbin/ldpd/lde.h | 5 | ||||
-rw-r--r-- | usr.sbin/ldpd/lde_lib.c | 8 | ||||
-rw-r--r-- | usr.sbin/ldpd/ldpd.h | 8 | ||||
-rw-r--r-- | usr.sbin/ldpd/ldpe.c | 11 | ||||
-rw-r--r-- | usr.sbin/ldpd/ldpe.h | 9 | ||||
-rw-r--r-- | usr.sbin/ldpd/neighbor.c | 4 | ||||
-rw-r--r-- | usr.sbin/ldpd/notification.c | 29 | ||||
-rw-r--r-- | usr.sbin/ldpd/packet.c | 26 |
14 files changed, 105 insertions, 123 deletions
diff --git a/usr.sbin/ldpd/address.c b/usr.sbin/ldpd/address.c index d43bacdf697..82c67f84b0e 100644 --- a/usr.sbin/ldpd/address.c +++ b/usr.sbin/ldpd/address.c @@ -1,4 +1,4 @@ -/* $OpenBSD: address.c,v 1.1 2009/06/01 20:59:45 michele Exp $ */ +/* $OpenBSD: address.c,v 1.2 2009/06/05 22:34:45 michele Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -89,7 +89,7 @@ recv_address(struct nbr *nbr, char *buf, u_int16_t len) struct ldp_msg *addr; struct address_list_tlv *alt; struct in_addr *address; - u_int32_t messageid, addrs_len; + u_int32_t addrs_len; log_debug("recv_address: neighbor ID %s", inet_ntoa(nbr->id)); @@ -99,12 +99,10 @@ recv_address(struct nbr *nbr, char *buf, u_int16_t len) addr = (struct ldp_msg *)buf; if ((len - TLV_HDR_LEN) < ntohs(addr->length)) { - /* XXX: send notification */ + session_shutdown(nbr, S_BAD_MSG_LEN, addr->msgid, addr->type); return (-1); } - messageid = addr->msgid; - buf += sizeof(struct ldp_msg); len -= sizeof(struct ldp_msg); @@ -112,20 +110,21 @@ recv_address(struct nbr *nbr, char *buf, u_int16_t len) if (len < sizeof(*alt) || (len - TLV_HDR_LEN) < ntohs(alt->length)) { - /* XXX: send notification */ + session_shutdown(nbr, S_BAD_TLV_LEN, addr->msgid, addr->type); return (-1); } addrs_len = (ntohs(alt->length) - sizeof(alt->family)); if (alt->type != TLV_TYPE_ADDRLIST) { - /* XXX: send notification */ + session_shutdown(nbr, S_UNKNOWN_TLV, addr->msgid, addr->type); return (-1); } /* For now we only support IPv4 */ if (alt->family != htons(ADDR_IPV4)) { - /* XXX: send notification */ + send_notification_nbr(nbr, S_UNSUP_ADDR, addr->msgid, + addr->type); return (-1); } @@ -207,20 +206,16 @@ recv_address_withdraw(struct nbr *nbr, char *buf, u_int16_t len) struct ldp_msg *aw; struct address_list_tlv *alt; struct in_addr *address; - u_int32_t messageid; log_debug("recv_address_withdraw: neighbor ID %s", inet_ntoa(nbr->id)); aw = (struct ldp_msg *)buf; - if ((len - TLV_HDR_LEN) < ntohs(aw->length)) { - /* XXX: send notification */ + session_shutdown(nbr, S_BAD_MSG_LEN, aw->msgid, aw->type); return (-1); } - messageid = aw->msgid; - buf += sizeof(struct ldp_msg); len -= sizeof(struct ldp_msg); @@ -228,18 +223,18 @@ recv_address_withdraw(struct nbr *nbr, char *buf, u_int16_t len) if (len < sizeof(*alt) || (len - TLV_HDR_LEN) < ntohs(alt->length)) { - /* XXX: send notification */ + session_shutdown(nbr, S_BAD_TLV_LEN, aw->msgid, aw->type); return (-1); } if (alt->type != TLV_TYPE_ADDRLIST) { - /* XXX: send notification */ + session_shutdown(nbr, S_UNKNOWN_TLV, aw->msgid, aw->type); return (-1); } /* For now we just support IPv4 */ if (alt->family != AF_INET) { - /* XXX: send notification */ + send_notification_nbr(nbr, S_UNSUP_ADDR, aw->msgid, aw->type); return (-1); } diff --git a/usr.sbin/ldpd/hello.c b/usr.sbin/ldpd/hello.c index 3363af68983..49ccfc6b49b 100644 --- a/usr.sbin/ldpd/hello.c +++ b/usr.sbin/ldpd/hello.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hello.c,v 1.1 2009/06/01 20:59:45 michele Exp $ */ +/* $OpenBSD: hello.c,v 1.2 2009/06/05 22:34:45 michele Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -98,10 +98,8 @@ recv_hello(struct iface *iface, struct in_addr src, char *buf, u_int16_t len) hello = (struct ldp_msg *)buf; - if ((len - TLV_HDR_LEN) < ntohs(hello->length)) { - /* XXX: send notification */ + if ((len - TLV_HDR_LEN) < ntohs(hello->length)) return; - } messageid = hello->msgid; diff --git a/usr.sbin/ldpd/init.c b/usr.sbin/ldpd/init.c index 68667108b73..fc49ced7bec 100644 --- a/usr.sbin/ldpd/init.c +++ b/usr.sbin/ldpd/init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init.c,v 1.1 2009/06/01 20:59:45 michele Exp $ */ +/* $OpenBSD: init.c,v 1.2 2009/06/05 22:34:45 michele Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -75,7 +75,6 @@ int recv_init(struct nbr *nbr, char *buf, u_int16_t len) { struct ldp_msg *init; - u_int32_t messageid; struct sess_prms_tlv *sess_tlv; log_debug("recv_init: neighbor ID %s", inet_ntoa(nbr->id)); @@ -83,12 +82,10 @@ recv_init(struct nbr *nbr, char *buf, u_int16_t len) init = (struct ldp_msg *)buf; if ((len - TLV_HDR_LEN) < ntohs(init->length)) { - /* XXX: send notification */ + session_shutdown(nbr, S_BAD_MSG_LEN, init->msgid, init->type); return (-1); } - messageid = init->msgid; - buf += sizeof(struct ldp_msg); len -= sizeof(struct ldp_msg); @@ -96,7 +93,7 @@ recv_init(struct nbr *nbr, char *buf, u_int16_t len) if (len < SESS_PRMS_SIZE || ntohs(sess_tlv->length) != (SESS_PRMS_SIZE - TLV_HDR_LEN)) { - /* XXX: send notification */ + session_shutdown(nbr, S_BAD_TLV_LEN, init->msgid, init->type); return (-1); } diff --git a/usr.sbin/ldpd/keepalive.c b/usr.sbin/ldpd/keepalive.c index e4ab62c22f2..5507c269cc2 100644 --- a/usr.sbin/ldpd/keepalive.c +++ b/usr.sbin/ldpd/keepalive.c @@ -1,4 +1,4 @@ -/* $OpenBSD: keepalive.c,v 1.1 2009/06/01 20:59:45 michele Exp $ */ +/* $OpenBSD: keepalive.c,v 1.2 2009/06/05 22:34:45 michele Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -69,19 +69,16 @@ int recv_keepalive(struct nbr *nbr, char *buf, u_int16_t len) { struct ldp_msg *ka; - u_int32_t messageid; log_debug("recv_keepalive: neighbor ID %s", inet_ntoa(nbr->id)); ka = (struct ldp_msg *)buf; if ((len - TLV_HDR_LEN) < ntohs(ka->length)) { - /* XXX: send notification */ + session_shutdown(nbr, S_BAD_MSG_LEN, ka->msgid, ka->type); return (-1); } - messageid = ka->msgid; - buf += sizeof(struct ldp_msg); len -= sizeof(struct ldp_msg); diff --git a/usr.sbin/ldpd/labelmapping.c b/usr.sbin/ldpd/labelmapping.c index aac097161b7..ba0da8ae593 100644 --- a/usr.sbin/ldpd/labelmapping.c +++ b/usr.sbin/ldpd/labelmapping.c @@ -1,4 +1,4 @@ -/* $OpenBSD: labelmapping.c,v 1.1 2009/06/01 20:59:45 michele Exp $ */ +/* $OpenBSD: labelmapping.c,v 1.2 2009/06/05 22:34:45 michele Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -95,7 +95,6 @@ recv_labelmapping(struct nbr *nbr, char *buf, u_int16_t len) struct fec_tlv *ft; struct label_tlv *lt; struct map map; - u_int32_t messageid; int feclen; log_debug("recv_labelmapping: neighbor ID %s", inet_ntoa(nbr->id)); @@ -107,12 +106,10 @@ recv_labelmapping(struct nbr *nbr, char *buf, u_int16_t len) lm = (struct ldp_msg *)buf; if ((len - TLV_HDR_LEN) < ntohs(lm->length)) { - /* XXX: send notification */ + session_shutdown(nbr, S_BAD_MSG_LEN, lm->msgid, lm->type); return (-1); } - messageid = lm->msgid; - buf += sizeof(struct ldp_msg); len -= sizeof(struct ldp_msg); @@ -120,21 +117,19 @@ recv_labelmapping(struct nbr *nbr, char *buf, u_int16_t len) lt = (struct label_tlv *)(buf + TLV_HDR_LEN + ntohs(ft->length)); if (len < (sizeof(*ft) + LABEL_TLV_LEN)) { - /* XXX: send notification */ + session_shutdown(nbr, S_BAD_TLV_LEN, lm->msgid, lm->type); return (-1); } feclen = ntohs(ft->length); if (len - TLV_HDR_LEN < feclen) { - /* XXX: send notification */ + session_shutdown(nbr, S_BAD_TLV_LEN, lm->msgid, lm->type); return (-1); } map.label = tlv_decode_label(lt); if (map.label == NO_LABEL) { - log_debug("recv_labelmapping: packet malformed from " - "neighbor ID %s", inet_ntoa(nbr->id)); - /* XXX: send notification */ + session_shutdown(nbr, S_BAD_TLV_VAL, lm->msgid, lm->type); return (-1); } @@ -143,7 +138,8 @@ recv_labelmapping(struct nbr *nbr, char *buf, u_int16_t len) while (feclen >= FEC_ELM_MIN_LEN) { if (validate_fec_elm(buf) < 0) { - /* XXX: send notification */ + session_shutdown(nbr, S_BAD_TLV_VAL, lm->msgid, + lm->type); return (-1); } @@ -211,7 +207,6 @@ recv_labelrequest(struct nbr *nbr, char *buf, u_int16_t len) struct ldp_msg *lr; struct fec_tlv *ft; struct map map; - u_int32_t messageid; int feclen; log_debug("recv_labelrequest: neighbor ID %s", inet_ntoa(nbr->id)); @@ -223,12 +218,10 @@ recv_labelrequest(struct nbr *nbr, char *buf, u_int16_t len) lr = (struct ldp_msg *)buf; if ((len - TLV_HDR_LEN) < ntohs(lr->length)) { - /* XXX: send notification */ + session_shutdown(nbr, S_BAD_MSG_LEN, lr->msgid, lr->type); return (-1); } - messageid = lr->msgid; - buf += sizeof(struct ldp_msg); len -= sizeof(struct ldp_msg); @@ -236,7 +229,7 @@ recv_labelrequest(struct nbr *nbr, char *buf, u_int16_t len) if (len < sizeof(*ft) || (len - TLV_HDR_LEN) < ntohs(ft->length)) { - /* XXX: send notification */ + session_shutdown(nbr, S_BAD_TLV_LEN, lr->msgid, lr->type); return (-1); } @@ -247,14 +240,15 @@ recv_labelrequest(struct nbr *nbr, char *buf, u_int16_t len) while (feclen >= FEC_ELM_MIN_LEN) { if (validate_fec_elm(buf) < 0) { - /* XXX: send notification */ + session_shutdown(nbr, S_BAD_TLV_VAL, lr->msgid, + lr->type); return (-1); } map.prefix = decode_fec_elm(buf); map.prefixlen = decode_fec_len_elm(buf); map.prefix &= prefixlen2mask(map.prefixlen); - map.messageid = messageid; + map.messageid = lr->msgid; ldpe_imsg_compose_lde(IMSG_LABEL_REQUEST, nbr->peerid, 0, &map, sizeof(map)); @@ -322,7 +316,6 @@ int recv_labelwithdraw(struct nbr *nbr, char *buf, u_int16_t len) { struct ldp_msg *lw; - u_int32_t messageid; log_debug("recv_labelwithdraw: neighbor ID %s", inet_ntoa(nbr->id)); @@ -332,12 +325,10 @@ recv_labelwithdraw(struct nbr *nbr, char *buf, u_int16_t len) lw = (struct ldp_msg *)buf; if ((len - TLV_HDR_LEN) < ntohs(lw->length)) { - /* XXX: send notification */ + session_shutdown(nbr, S_BAD_MSG_LEN, lw->msgid, lw->type); return (-1); } - messageid = lw->msgid; - buf += sizeof(struct ldp_msg); len -= sizeof(struct ldp_msg); @@ -399,7 +390,6 @@ int recv_labelrelease(struct nbr *nbr, char *buf, u_int16_t len) { struct ldp_msg *lr; - u_int32_t messageid; log_debug("recv_labelrelease: neighbor ID %s", inet_ntoa(nbr->id)); @@ -409,12 +399,10 @@ recv_labelrelease(struct nbr *nbr, char *buf, u_int16_t len) lr = (struct ldp_msg *)buf; if ((len - TLV_HDR_LEN) < ntohs(lr->length)) { - /* XXX: send notification */ + session_shutdown(nbr, S_BAD_MSG_LEN, lr->msgid, lr->type); return (-1); } - messageid = lr->msgid; - buf += sizeof(struct ldp_msg); len -= sizeof(struct ldp_msg); @@ -457,7 +445,6 @@ int recv_labelabortreq(struct nbr *nbr, char *buf, u_int16_t len) { struct ldp_msg *la; - u_int32_t messageid; log_debug("recv_labelabortreq: neighbor ID %s", inet_ntoa(nbr->id)); @@ -467,12 +454,10 @@ recv_labelabortreq(struct nbr *nbr, char *buf, u_int16_t len) la = (struct ldp_msg *)buf; if ((len - TLV_HDR_LEN) < ntohs(la->length)) { - /* XXX: send notification */ + session_shutdown(nbr, S_BAD_MSG_LEN, la->msgid, la->type); return (-1); } - messageid = la->msgid; - buf += sizeof(struct ldp_msg); len -= sizeof(struct ldp_msg); @@ -525,15 +510,11 @@ gen_label_tlv(struct buf *buf, u_int32_t label) u_int32_t tlv_decode_label(struct label_tlv *lt) { - if (lt->type != htons(TLV_TYPE_GENERICLABEL)) { - /* XXX: send notification */ + if (lt->type != htons(TLV_TYPE_GENERICLABEL)) return (NO_LABEL); - } - if (ntohs(lt->length) != sizeof(lt->label)) { - /* XXX: send notification */ + if (ntohs(lt->length) != sizeof(lt->label)) return (NO_LABEL); - } return (ntohl(lt->label)); } @@ -544,18 +525,14 @@ validate_fec_elm(char *buf) u_int16_t *family; if (*buf != FEC_WILDCARD && *buf != FEC_PREFIX && *buf != - FEC_ADDRESS) { - /* XXX: send notification */ + FEC_ADDRESS) return (-1); - } buf += sizeof(u_int8_t); family = (u_int16_t *)buf; - if (*family != htons(FEC_IPV4)) { - /* XXX: send notification */ + if (*family != htons(FEC_IPV4)) return (-1); - } return (0); } diff --git a/usr.sbin/ldpd/lde.c b/usr.sbin/ldpd/lde.c index de86d890bdf..6bb8ad4fcaf 100644 --- a/usr.sbin/ldpd/lde.c +++ b/usr.sbin/ldpd/lde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lde.c,v 1.1 2009/06/01 20:59:45 michele Exp $ */ +/* $OpenBSD: lde.c,v 1.2 2009/06/05 22:34:45 michele Exp $ */ /* * Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org> @@ -505,10 +505,20 @@ lde_send_labelrelease(u_int32_t peerid, struct map *map) } void -lde_send_notification(u_int32_t peerid, u_int32_t code) +lde_send_notification(u_int32_t peerid, u_int32_t code, u_int32_t msgid, + u_int32_t type) { - imsg_compose(ibuf_ldpe, IMSG_NOTIFICATION_SEND, peerid, 0, &code, - sizeof(u_int32_t)); + struct notify_msg nm; + + bzero(&nm, sizeof(nm)); + + /* Every field is in host byte order, to keep things clear */ + nm.status = code; + nm.messageid = ntohl(msgid); + nm.type = type; + + imsg_compose(ibuf_ldpe, IMSG_NOTIFICATION_SEND, peerid, 0, &nm, + sizeof(nm)); } LIST_HEAD(lde_nbr_head, lde_nbr); diff --git a/usr.sbin/ldpd/lde.h b/usr.sbin/ldpd/lde.h index 7ba1b09a3ca..1f60365965e 100644 --- a/usr.sbin/ldpd/lde.h +++ b/usr.sbin/ldpd/lde.h @@ -1,4 +1,4 @@ -/* $OpenBSD: lde.h,v 1.1 2009/06/01 20:59:45 michele Exp $ */ +/* $OpenBSD: lde.h,v 1.2 2009/06/05 22:34:45 michele Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -98,7 +98,8 @@ void lde_send_delete_klabel(struct rt_node *); void lde_send_labelmapping(u_int32_t, struct map *); void lde_send_labelrequest(u_int32_t, struct map *); void lde_send_labelrelease(u_int32_t, struct map *); -void lde_send_notification(u_int32_t, u_int32_t); +void lde_send_notification(u_int32_t, u_int32_t, u_int32_t, + u_int32_t); void lde_nbr_del(struct lde_nbr *); struct lde_nbr *lde_find_address(struct in_addr); diff --git a/usr.sbin/ldpd/lde_lib.c b/usr.sbin/ldpd/lde_lib.c index ef99606a1ce..ce5388d8326 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.1 2009/06/01 20:59:45 michele Exp $ */ +/* $OpenBSD: lde_lib.c,v 1.2 2009/06/05 22:34:45 michele Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -325,12 +325,14 @@ lde_check_request(struct map *map, struct lde_nbr *ln) rn = rt_find(map->prefix, map->prefixlen); if (rn == NULL || rn->remote_label == NO_LABEL) { - lde_send_notification(ln->peerid, S_NO_ROUTE); + lde_send_notification(ln->peerid, S_NO_ROUTE, map->messageid, + MSG_TYPE_LABELREQUEST); return; } if (lde_address_find(ln, &rn->nexthop)) { - lde_send_notification(ln->peerid, S_LOOP_DETECTED); + lde_send_notification(ln->peerid, S_LOOP_DETECTED, + map->messageid, MSG_TYPE_LABELREQUEST); return; } diff --git a/usr.sbin/ldpd/ldpd.h b/usr.sbin/ldpd/ldpd.h index 3e76e53c1fb..98a552ab399 100644 --- a/usr.sbin/ldpd/ldpd.h +++ b/usr.sbin/ldpd/ldpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ldpd.h,v 1.1 2009/06/01 20:59:45 michele Exp $ */ +/* $OpenBSD: ldpd.h,v 1.2 2009/06/05 22:34:45 michele Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -228,6 +228,12 @@ struct map { u_int32_t messageid; }; +struct notify_msg { + u_int32_t messageid; + u_int32_t status; + u_int32_t type; +}; + struct iface { LIST_ENTRY(iface) entry; struct event hello_timer; diff --git a/usr.sbin/ldpd/ldpe.c b/usr.sbin/ldpd/ldpe.c index 3e1dddf19a5..63398c47cdb 100644 --- a/usr.sbin/ldpd/ldpe.c +++ b/usr.sbin/ldpd/ldpe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ldpe.c,v 1.1 2009/06/01 20:59:45 michele Exp $ */ +/* $OpenBSD: ldpe.c,v 1.2 2009/06/05 22:34:45 michele Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -366,8 +366,8 @@ ldpe_dispatch_lde(int fd, short event, void *bula) struct imsgbuf *ibuf = bula; struct imsg imsg; struct map map; + struct notify_msg nm; int n, shut = 0; - u_int32_t code; struct nbr *nbr = NULL; if (event & EV_READ) { @@ -436,9 +436,9 @@ ldpe_dispatch_lde(int fd, short event, void *bula) send_labelrelease(nbr); break; case IMSG_NOTIFICATION_SEND: - if (imsg.hdr.len - IMSG_HEADER_SIZE != sizeof(code)) + if (imsg.hdr.len - IMSG_HEADER_SIZE != sizeof(nm)) fatalx("invalid size of OE request"); - memcpy(&code, imsg.data, sizeof(code)); + memcpy(&nm, imsg.data, sizeof(nm)); nbr = nbr_find_peerid(imsg.hdr.peerid); if (nbr == NULL) { @@ -447,7 +447,8 @@ ldpe_dispatch_lde(int fd, short event, void *bula) return; } - send_notification_nbr(nbr, code); + send_notification_nbr(nbr, nm.status, + htonl(nm.messageid), htonl(nm.type)); break; case IMSG_REQUEST_ADD: if (imsg.hdr.len - IMSG_HEADER_SIZE != sizeof(map)) diff --git a/usr.sbin/ldpd/ldpe.h b/usr.sbin/ldpd/ldpe.h index 06ba54798d8..55dc94e0ad9 100644 --- a/usr.sbin/ldpd/ldpe.h +++ b/usr.sbin/ldpd/ldpe.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ldpe.h,v 1.1 2009/06/01 20:59:45 michele Exp $ */ +/* $OpenBSD: ldpe.h,v 1.2 2009/06/05 22:34:45 michele Exp $ */ /* * Copyright (c) 2004, 2005, 2008 Esben Norby <norby@openbsd.org> @@ -88,8 +88,9 @@ int send_keepalive(struct nbr *); int recv_keepalive(struct nbr *, char *, u_int16_t); /* notification.c */ -int send_notification(int, struct iface *, int); -int send_notification_nbr(struct nbr *, u_int32_t); +int send_notification(u_int32_t, struct iface *, int, u_int32_t, + u_int32_t); +int send_notification_nbr(struct nbr *, u_int32_t, u_int32_t, u_int32_t); int recv_notification(struct nbr *, char *, u_int16_t); /* address.c */ @@ -205,9 +206,9 @@ void disc_recv_packet(int, short, void *); void session_recv_packet(int, short, void *); void session_read(struct bufferevent *, void *); -void session_write(struct bufferevent *, void *); void session_error(struct bufferevent *, short, void *); void session_close(struct nbr *); +void session_shutdown(struct nbr *, u_int32_t, u_int32_t, u_int32_t); char *pkt_ptr; /* packet buffer */ diff --git a/usr.sbin/ldpd/neighbor.c b/usr.sbin/ldpd/neighbor.c index 123f460bb21..6f9f09167f6 100644 --- a/usr.sbin/ldpd/neighbor.c +++ b/usr.sbin/ldpd/neighbor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: neighbor.c,v 1.1 2009/06/01 20:59:45 michele Exp $ */ +/* $OpenBSD: neighbor.c,v 1.2 2009/06/05 22:34:45 michele Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -457,7 +457,7 @@ nbr_ktimeout(int fd, short event, void *arg) log_debug("nbr_ktimeout: neighbor ID %s peerid %lu", inet_ntoa(nbr->id), nbr->peerid); - send_notification_nbr(nbr, S_KEEPALIVE_TMR); + send_notification_nbr(nbr, S_KEEPALIVE_TMR, 0, 0); close(nbr->fd); } diff --git a/usr.sbin/ldpd/notification.c b/usr.sbin/ldpd/notification.c index 01613fbf570..9d5fa27c4d0 100644 --- a/usr.sbin/ldpd/notification.c +++ b/usr.sbin/ldpd/notification.c @@ -1,4 +1,4 @@ -/* $OpenBSD: notification.c,v 1.1 2009/06/01 20:59:45 michele Exp $ */ +/* $OpenBSD: notification.c,v 1.2 2009/06/05 22:34:45 michele Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -37,21 +37,23 @@ #include "log.h" #include "ldpe.h" -int gen_status_tlv(struct buf *, int); +int gen_status_tlv(struct buf *, u_int32_t, u_int32_t, u_int32_t); int -send_notification_nbr(struct nbr *nbr, u_int32_t status) +send_notification_nbr(struct nbr *nbr, u_int32_t status, u_int32_t msgid, + u_int32_t type) { if (nbr->iface->passive) return (0); log_debug("send_notification: neighbor ID %s", inet_ntoa(nbr->id)); - return (send_notification(status, nbr->iface, nbr->fd)); + return (send_notification(status, nbr->iface, nbr->fd, msgid, type)); } int -send_notification(int status, struct iface *iface, int fd) +send_notification(u_int32_t status, struct iface *iface, int fd, + u_int32_t msgid, u_int32_t type) { struct buf *buf; u_int16_t size; @@ -69,7 +71,7 @@ send_notification(int status, struct iface *iface, int fd) size -= sizeof(struct ldp_msg); - gen_status_tlv(buf, status); + gen_status_tlv(buf, status, msgid, type); write(fd, buf->buf, buf->wpos); buf_free(buf); @@ -82,19 +84,16 @@ recv_notification(struct nbr *nbr, char *buf, u_int16_t len) { struct ldp_msg *not; struct status_tlv *st; - u_int32_t messageid; log_debug("recv_notification: neighbor ID %s", inet_ntoa(nbr->id)); not = (struct ldp_msg *)buf; if ((len - TLV_HDR_LEN) < ntohs(not->length)) { - /* XXX: send notification */ + session_shutdown(nbr, S_BAD_MSG_LEN, not->msgid, not->type); return (-1); } - messageid = not->msgid; - buf += sizeof(struct ldp_msg); len -= sizeof(struct ldp_msg); @@ -102,7 +101,7 @@ recv_notification(struct nbr *nbr, char *buf, u_int16_t len) if (len < STATUS_SIZE || (STATUS_SIZE - TLV_HDR_LEN) != ntohs(st->length)) { - /* XXX: send notification */ + session_shutdown(nbr, S_BAD_TLV_LEN, not->msgid, not->type); return (-1); } @@ -115,7 +114,8 @@ recv_notification(struct nbr *nbr, char *buf, u_int16_t len) } int -gen_status_tlv(struct buf *buf, int status) +gen_status_tlv(struct buf *buf, u_int32_t status, u_int32_t msgid, + u_int32_t type) { struct status_tlv st; @@ -125,9 +125,8 @@ gen_status_tlv(struct buf *buf, int status) st.length = htons(STATUS_TLV_LEN); st.status_code = htonl(status); - /* XXX */ - st.msg_id = 0; - st.msg_type = 0; + st.msg_id = msgid; + st.msg_type = type; return (buf_add(buf, &st, STATUS_SIZE)); } diff --git a/usr.sbin/ldpd/packet.c b/usr.sbin/ldpd/packet.c index 41e18fdc215..de2a157b711 100644 --- a/usr.sbin/ldpd/packet.c +++ b/usr.sbin/ldpd/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.1 2009/06/01 20:59:45 michele Exp $ */ +/* $OpenBSD: packet.c,v 1.2 2009/06/05 22:34:45 michele Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -297,7 +297,7 @@ session_recv_packet(int fd, short event, void *bula) if (nbr == NULL) { /* If there is no neighbor matching there is no Hello adjacency: send notification */ - send_notification(S_NO_HELLO, iface, newfd); + send_notification(S_NO_HELLO, iface, newfd, 0, 0); close(newfd); return; } @@ -325,21 +325,14 @@ another_packet: ldp_hdr = (struct ldp_hdr *)buf; if (ntohs(ldp_hdr->version) != LDP_VERSION) { - log_debug("session_read: nbr ID %s invalid LDP version %d", - inet_ntoa(nbr->id), ldp_hdr->version); - send_notification_nbr(nbr, S_BAD_PROTO_VER); - session_close(nbr); - /* XXX: notify lde */ + session_shutdown(nbr, S_BAD_PROTO_VER, 0, 0); return; } pdu_len = ntohs(ldp_hdr->length); if (pdu_len < LDP_HDR_SIZE || pdu_len > LDP_MAX_LEN) { - log_debug("session_read: packet malformed"); - send_notification_nbr(nbr, S_BAD_MSG_LEN); - session_close(nbr); - /* XXX: notify lde */ + session_shutdown(nbr, S_BAD_MSG_LEN, 0, 0); return; } @@ -405,14 +398,19 @@ another_packet: } void -session_write(struct bufferevent *bev, void *arg) +session_error(struct bufferevent *bev, short what, void *arg) { + struct nbr *nbr = arg; + + nbr_fsm(nbr, NBR_EVT_CLOSE_SESSION); } void -session_error(struct bufferevent *bev, short what, void *arg) +session_shutdown(struct nbr *nbr, u_int32_t status, u_int32_t msgid, + u_int32_t type) { - struct nbr *nbr = arg; + send_notification_nbr(nbr, status, msgid, type); + send_notification_nbr(nbr, S_SHUTDOWN, msgid, type); nbr_fsm(nbr, NBR_EVT_CLOSE_SESSION); } |