diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2005-04-05 13:01:23 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2005-04-05 13:01:23 +0000 |
commit | c4bef21686f6c56c326ce78404e1621fc340958a (patch) | |
tree | 106f72dfc0551db2a580c4ece17f25c63b5b5ccc /usr.sbin/ospfd | |
parent | 75e08cafc7189a5824e9cbbc1d7b307340fd4518 (diff) |
Use the dynamic buffer API for packet generation and sending.
OK norby@
Diffstat (limited to 'usr.sbin/ospfd')
-rw-r--r-- | usr.sbin/ospfd/auth.c | 29 | ||||
-rw-r--r-- | usr.sbin/ospfd/database.c | 72 | ||||
-rw-r--r-- | usr.sbin/ospfd/hello.c | 68 | ||||
-rw-r--r-- | usr.sbin/ospfd/lsack.c | 32 | ||||
-rw-r--r-- | usr.sbin/ospfd/lsreq.c | 47 | ||||
-rw-r--r-- | usr.sbin/ospfd/lsupdate.c | 43 | ||||
-rw-r--r-- | usr.sbin/ospfd/ospfd.h | 3 | ||||
-rw-r--r-- | usr.sbin/ospfd/ospfe.h | 6 | ||||
-rw-r--r-- | usr.sbin/ospfd/packet.c | 30 |
9 files changed, 164 insertions, 166 deletions
diff --git a/usr.sbin/ospfd/auth.c b/usr.sbin/ospfd/auth.c index 0b7615be1b9..93d5b2c04fa 100644 --- a/usr.sbin/ospfd/auth.c +++ b/usr.sbin/ospfd/auth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: auth.c,v 1.4 2005/04/04 13:49:13 claudio Exp $ */ +/* $OpenBSD: auth.c,v 1.5 2005/04/05 13:01:21 claudio Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -18,6 +18,7 @@ #include <sys/types.h> #include <sys/socket.h> +#include <limits.h> #include <md5.h> #include <stdlib.h> #include <string.h> @@ -134,26 +135,30 @@ auth_validate(void *buf, u_int16_t len, struct iface *iface, struct nbr *nbr) } int -auth_gen(void *buf, u_int16_t len, struct iface *iface) +auth_gen(struct buf *buf, struct iface *iface) { MD5_CTX hash; u_int8_t digest[MD5_DIGEST_LENGTH]; - struct ospf_hdr *ospf_hdr = buf; + struct ospf_hdr *ospf_hdr; struct auth_md *md; - char *auth_data; + + if ((ospf_hdr = buf_seek(buf, 0, sizeof(ospf_hdr))) == NULL) + fatalx("auth_gen: buf_seek failed"); /* update length */ - ospf_hdr->len = htons(len); + if (buf->wpos > USHRT_MAX) + fatalx("auth_gen: resulting ospf packet to big"); + ospf_hdr->len = htons((u_int16_t)buf->wpos); /* clear auth_key field */ bzero(ospf_hdr->auth_key.simple, sizeof(ospf_hdr->auth_key.simple)); switch (iface->auth_type) { case AUTH_NONE: - ospf_hdr->chksum = in_cksum(buf, len); + ospf_hdr->chksum = in_cksum(buf->buf, buf->wpos); break; case AUTH_SIMPLE: - ospf_hdr->chksum = in_cksum(buf, len); + ospf_hdr->chksum = in_cksum(buf->buf, buf->wpos); strncpy(ospf_hdr->auth_key.simple, iface->auth_key, sizeof(ospf_hdr->auth_key.simple)); @@ -178,17 +183,11 @@ auth_gen(void *buf, u_int16_t len, struct iface *iface) /* calculate MD5 digest */ MD5Init(&hash); - MD5Update(&hash, buf, len); + MD5Update(&hash, buf->buf, buf->wpos); MD5Update(&hash, digest, MD5_DIGEST_LENGTH); MD5Final(digest, &hash); - /* insert MD5 digest */ - /* XXX this will be fixed soon, when we switch to dynamic - * buffers */ - auth_data = buf; - auth_data += len; - bcopy(digest, auth_data, sizeof(digest)); - break; + return (buf_add(buf, digest, MD5_DIGEST_LENGTH)); default: log_debug("auth_gen: unknown auth type, interface %s", iface->name); diff --git a/usr.sbin/ospfd/database.c b/usr.sbin/ospfd/database.c index daa300a741a..1eb73b9bf97 100644 --- a/usr.sbin/ospfd/database.c +++ b/usr.sbin/ospfd/database.c @@ -1,4 +1,4 @@ -/* $OpenBSD: database.c,v 1.6 2005/03/22 22:13:48 norby Exp $ */ +/* $OpenBSD: database.c,v 1.7 2005/04/05 13:01:21 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -20,6 +20,8 @@ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> #include <arpa/inet.h> #include <stdlib.h> #include <string.h> @@ -39,11 +41,9 @@ int send_db_description(struct nbr *nbr) { struct sockaddr_in dst; - struct db_dscrp_hdr *dd_hdr; - struct lsa_hdr *lsa_hdr; + struct db_dscrp_hdr dd_hdr; struct lsa_entry *le, *nle; - char *buf; - char *ptr; + struct buf *buf; int ret = 0; log_debug("send_db_description: neighbor ID %s, seq_num %x", @@ -52,19 +52,16 @@ send_db_description(struct nbr *nbr) if (nbr->iface->passive) return (0); - if ((ptr = buf = calloc(1, READ_BUF_SIZE)) == NULL) + if ((buf = buf_open(nbr->iface->mtu - sizeof(struct ip))) == NULL) fatal("send_db_description"); /* OSPF header */ - gen_ospf_hdr(ptr, nbr->iface, PACKET_TYPE_DD); - ptr += sizeof(struct ospf_hdr); - - /* database description header */ - dd_hdr = (struct db_dscrp_hdr *)ptr; - dd_hdr->opts = oeconf->options; - dd_hdr->dd_seq_num = htonl(nbr->dd_seq_num); + if (gen_ospf_hdr(buf, nbr->iface, PACKET_TYPE_DD)) + goto fail; - ptr += sizeof(*dd_hdr); + /* reserve space for database description header */ + if (buf_reserve(buf, sizeof(dd_hdr)) == NULL) + goto fail; switch (nbr->state) { case NBR_STA_DOWN: @@ -102,14 +99,13 @@ send_db_description(struct nbr *nbr) nbr->options &= ~OSPF_DBD_I; - /* build LSA list */ - lsa_hdr = (struct lsa_hdr *)ptr; - - for (le = TAILQ_FIRST(&nbr->db_sum_list); (le != NULL) && - ((ptr - buf) < nbr->iface->mtu - PACKET_HDR); le = nle) { + /* build LSA list, keep space for a possible md5 sum */ + for (le = TAILQ_FIRST(&nbr->db_sum_list); le != NULL && + buf->wpos + sizeof(struct lsa_hdr) < buf->max - + MD5_DIGEST_LENGTH; le = nle) { nbr->dd_end = nle = TAILQ_NEXT(le, entry); - memcpy(ptr, le->le_lsa, sizeof(struct lsa_hdr)); - ptr += sizeof(*lsa_hdr); + if (buf_add(buf, le->le_lsa, sizeof(struct lsa_hdr))) + goto fail; } break; case NBR_STA_LOAD: @@ -129,11 +125,7 @@ send_db_description(struct nbr *nbr) break; default: - log_debug("send_db_description: unknown neighbor state, " - "neighbor ID %s", inet_ntoa(nbr->id)); - ret = -1; - goto done; - break; + fatalx("send_db_description: unknown neighbor state"); } /* set destination */ @@ -143,36 +135,42 @@ send_db_description(struct nbr *nbr) switch (nbr->iface->type) { case IF_TYPE_POINTOPOINT: inet_aton(AllSPFRouters, &dst.sin_addr); - dd_hdr->iface_mtu = htons(nbr->iface->mtu); + dd_hdr.iface_mtu = htons(nbr->iface->mtu); break; case IF_TYPE_BROADCAST: dst.sin_addr = nbr->addr; - dd_hdr->iface_mtu = htons(nbr->iface->mtu); + dd_hdr.iface_mtu = htons(nbr->iface->mtu); break; case IF_TYPE_NBMA: case IF_TYPE_POINTOMULTIPOINT: case IF_TYPE_VIRTUALLINK: dst.sin_addr = nbr->addr; - dd_hdr->iface_mtu = 0; + dd_hdr.iface_mtu = 0; break; default: fatalx("send_db_description: unknown interface type"); } - dd_hdr->bits = nbr->options; + dd_hdr.opts = oeconf->options; + dd_hdr.bits = nbr->options; + dd_hdr.dd_seq_num = htonl(nbr->dd_seq_num); + + memcpy(buf_seek(buf, sizeof(struct ospf_hdr), sizeof(dd_hdr)), + &dd_hdr, sizeof(dd_hdr)); /* update authentication and calculate checksum */ - auth_gen(buf, ptr - buf, nbr->iface); + if (auth_gen(buf, nbr->iface)) + goto fail; /* transmit packet */ - if ((ret = send_packet(nbr->iface, buf, (ptr - buf), &dst)) == -1) - log_warnx("send_db_description: error sending packet on " - "interface %s", nbr->iface->name); - + ret = send_packet(nbr->iface, buf->buf, buf->wpos, &dst); done: - free(buf); - + buf_free(buf); return (ret); +fail: + log_warn("send_db_description"); + buf_free(buf); + return (-1); } void diff --git a/usr.sbin/ospfd/hello.c b/usr.sbin/ospfd/hello.c index eb76310b17f..dcca30b6140 100644 --- a/usr.sbin/ospfd/hello.c +++ b/usr.sbin/ospfd/hello.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hello.c,v 1.4 2005/02/09 15:51:30 claudio Exp $ */ +/* $OpenBSD: hello.c,v 1.5 2005/04/05 13:01:21 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -39,17 +39,16 @@ int send_hello(struct iface *iface) { struct sockaddr_in dst; - struct hello_hdr *hello; + struct hello_hdr hello; struct nbr *nbr; - char *buf; - char *ptr; - int ret = 0; + struct buf *buf; + int ret; if (iface->passive) return (0); - /* XXX use buffer API instead for better decoupling */ - if ((ptr = buf = calloc(1, READ_BUF_SIZE)) == NULL) + /* XXX READ_BUF_SIZE */ + if ((buf = buf_dynamic(PKG_DEF_SIZE, READ_BUF_SIZE)) == NULL) fatal("send_hello"); dst.sin_family = AF_INET; @@ -72,49 +71,48 @@ send_hello(struct iface *iface) } /* OSPF header */ - gen_ospf_hdr(ptr, iface, PACKET_TYPE_HELLO); - ptr += sizeof(struct ospf_hdr); + if (gen_ospf_hdr(buf, iface, PACKET_TYPE_HELLO)) + goto fail; /* hello header */ - hello = (struct hello_hdr *)ptr; - hello->mask = iface->mask.s_addr; - hello->hello_interval = htons(iface->hello_interval); - hello->opts = oeconf->options; - hello->rtr_priority = iface->priority; - hello->rtr_dead_interval = htonl(iface->dead_interval); + hello.mask = iface->mask.s_addr; + hello.hello_interval = htons(iface->hello_interval); + hello.opts = oeconf->options; + hello.rtr_priority = iface->priority; + hello.rtr_dead_interval = htonl(iface->dead_interval); if (iface->dr) { - hello->d_rtr = iface->dr->addr.s_addr; + hello.d_rtr = iface->dr->addr.s_addr; iface->self->dr.s_addr = iface->dr->addr.s_addr; - } + } else + hello.d_rtr = 0; if (iface->bdr) { - hello->bd_rtr = iface->bdr->addr.s_addr; + hello.bd_rtr = iface->bdr->addr.s_addr; iface->self->bdr.s_addr = iface->bdr->addr.s_addr; - } - ptr += sizeof(*hello); + } else + hello.bd_rtr = 0; + + if (buf_add(buf, &hello, sizeof(hello))) + goto fail; /* active neighbor(s) */ LIST_FOREACH(nbr, &iface->nbr_list, entry) { - if (ptr - buf > iface->mtu - PACKET_HDR) { - log_warnx("send_hello: too many neighbors on " - "interface %s", iface->name); - break; - } - if ((nbr->state >= NBR_STA_INIT) && (nbr != iface->self)) { - memcpy(ptr, &nbr->id, sizeof(nbr->id)); - ptr += sizeof(nbr->id); - } + if ((nbr->state >= NBR_STA_INIT) && (nbr != iface->self)) + if (buf_add(buf, &nbr->id, sizeof(nbr->id))) + goto fail; } /* update authentication and calculate checksum */ - auth_gen(buf, ptr - buf, iface); - - if ((ret = send_packet(iface, buf, (ptr - buf), &dst)) == -1) - log_warnx("send_hello: error sending packet on " - "interface %s", iface->name); + if (auth_gen(buf, iface)) + goto fail; - free(buf); + ret = send_packet(iface, buf->buf, buf->wpos, &dst); + buf_free(buf); return (ret); +fail: + log_warn("send_hello"); + buf_free(buf); + return (-1); } void diff --git a/usr.sbin/ospfd/lsack.c b/usr.sbin/ospfd/lsack.c index bfd0c9a1f7e..20f426bb00f 100644 --- a/usr.sbin/ospfd/lsack.c +++ b/usr.sbin/ospfd/lsack.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lsack.c,v 1.7 2005/03/22 22:13:48 norby Exp $ */ +/* $OpenBSD: lsack.c,v 1.8 2005/04/05 13:01:21 claudio Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -38,9 +38,8 @@ int send_ls_ack(struct iface *iface, struct in_addr addr, void *data, int len) { struct sockaddr_in dst; - char *buf; - char *ptr; - int ret = 0; + struct buf *buf; + int ret; log_debug("send_ls_ack: interface %s addr %s", iface->name, inet_ntoa(addr)); @@ -48,8 +47,8 @@ send_ls_ack(struct iface *iface, struct in_addr addr, void *data, int len) if (iface->passive) return (0); - /* XXX use buffer API instead for better decoupling */ - if ((ptr = buf = calloc(1, READ_BUF_SIZE)) == NULL) + /* XXX READ_BUF_SIZE */ + if ((buf = buf_dynamic(PKG_DEF_SIZE, READ_BUF_SIZE)) == NULL) fatal("send_ls_ack"); dst.sin_family = AF_INET; @@ -57,22 +56,25 @@ send_ls_ack(struct iface *iface, struct in_addr addr, void *data, int len) dst.sin_addr.s_addr = addr.s_addr; /* OSPF header */ - gen_ospf_hdr(ptr, iface, PACKET_TYPE_LS_ACK); - ptr += sizeof(struct ospf_hdr); + if (gen_ospf_hdr(buf, iface, PACKET_TYPE_LS_ACK)) + goto fail; /* LS ack(s) */ - memcpy(ptr, data, len); /* XXX size check ??? */ - ptr += len; + if (buf_add(buf, data, len)) + goto fail; /* update authentication and calculate checksum */ - auth_gen(buf, ptr - buf, iface); + if (auth_gen(buf, iface)) + goto fail; - if ((ret = send_packet(iface, buf, (ptr - buf), &dst)) == -1) - log_warnx("send_ls_ack: error sending packet on " - "interface %s", iface->name); + ret = send_packet(iface, buf->buf, buf->wpos, &dst); - free(buf); + buf_free(buf); return (ret); +fail: + log_warn("send_ls_ack"); + buf_free(buf); + return (-1); } void diff --git a/usr.sbin/ospfd/lsreq.c b/usr.sbin/ospfd/lsreq.c index 1c0e04a8e07..4298da02bb2 100644 --- a/usr.sbin/ospfd/lsreq.c +++ b/usr.sbin/ospfd/lsreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lsreq.c,v 1.6 2005/03/23 20:36:57 claudio Exp $ */ +/* $OpenBSD: lsreq.c,v 1.7 2005/04/05 13:01:22 claudio Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -34,19 +34,15 @@ int send_ls_req(struct nbr *nbr) { struct sockaddr_in dst; - struct ls_req_hdr *ls_req_hdr; + struct ls_req_hdr ls_req_hdr; struct lsa_entry *le, *nle; - char *buf = NULL; - char *ptr; - int ret = 0; - - log_debug("send_ls_req: neighbor ID %s", inet_ntoa(nbr->id)); + struct buf *buf; + int ret; if (nbr->iface->passive) return (0); - /* XXX use buffer API instead for better decoupling */ - if ((ptr = buf = calloc(1, READ_BUF_SIZE)) == NULL) + if ((buf = buf_open(nbr->iface->mtu - sizeof(struct ip))) == NULL) fatal("send_ls_req"); /* set destination */ @@ -68,28 +64,33 @@ send_ls_req(struct nbr *nbr) } /* OSPF header */ - gen_ospf_hdr(ptr, nbr->iface, PACKET_TYPE_LS_REQUEST); - ptr += sizeof(struct ospf_hdr); + if (gen_ospf_hdr(buf, nbr->iface, PACKET_TYPE_LS_REQUEST)) + goto fail; - /* LSA header(s) */ + /* LSA header(s), keep space for a possible md5 sum */ for (le = TAILQ_FIRST(&nbr->ls_req_list); le != NULL && - (ptr - buf) < nbr->iface->mtu - PACKET_HDR; le = nle) { + buf->wpos + sizeof(struct ls_req_hdr) < buf->max - + MD5_DIGEST_LENGTH; le = nle) { nbr->ls_req = nle = TAILQ_NEXT(le, entry); - ls_req_hdr = (struct ls_req_hdr *)ptr; - ls_req_hdr->type = htonl(le->le_lsa->type); - ls_req_hdr->ls_id = le->le_lsa->ls_id; - ls_req_hdr->adv_rtr = le->le_lsa->adv_rtr; - ptr += sizeof(*ls_req_hdr); + ls_req_hdr.type = htonl(le->le_lsa->type); + ls_req_hdr.ls_id = le->le_lsa->ls_id; + ls_req_hdr.adv_rtr = le->le_lsa->adv_rtr; + if (buf_add(buf, &ls_req_hdr, sizeof(ls_req_hdr))) + goto fail; } /* update authentication and calculate checksum */ - auth_gen(buf, ptr - buf, nbr->iface); + if (auth_gen(buf, nbr->iface)) + goto fail; + + ret = send_packet(nbr->iface, buf->buf, buf->wpos, &dst); - if ((ret = send_packet(nbr->iface, buf, (ptr - buf), &dst)) == -1) - log_warnx("send_ls_req: error sending packet on " - "interface %s", nbr->iface->name); - free(buf); + buf_free(buf); return (ret); +fail: + log_warn("send_ls_req"); + buf_free(buf); + return (-1); } void diff --git a/usr.sbin/ospfd/lsupdate.c b/usr.sbin/ospfd/lsupdate.c index ac5adf198d2..cc3691258dd 100644 --- a/usr.sbin/ospfd/lsupdate.c +++ b/usr.sbin/ospfd/lsupdate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lsupdate.c,v 1.8 2005/03/29 17:26:35 norby Exp $ */ +/* $OpenBSD: lsupdate.c,v 1.9 2005/04/05 13:01:22 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -146,11 +146,11 @@ int send_ls_update(struct iface *iface, struct in_addr addr, void *data, int len) { struct sockaddr_in dst; - char *buf; - char *ptr; + struct buf *buf; + size_t pos; u_int32_t nlsa; u_int16_t age; - int ret = 0; + int ret; log_debug("send_ls_update: interface %s addr %s", iface->name, inet_ntoa(addr)); @@ -158,8 +158,8 @@ send_ls_update(struct iface *iface, struct in_addr addr, void *data, int len) if (iface->passive) return (0); - /* XXX use buffer API instead for better decoupling */ - if ((ptr = buf = calloc(1, READ_BUF_SIZE)) == NULL) + /* XXX READ_BUF_SIZE */ + if ((buf = buf_dynamic(PKG_DEF_SIZE, READ_BUF_SIZE)) == NULL) fatal("send_ls_update"); /* set destination */ @@ -168,34 +168,37 @@ send_ls_update(struct iface *iface, struct in_addr addr, void *data, int len) dst.sin_addr.s_addr = addr.s_addr; /* OSPF header */ - gen_ospf_hdr(ptr, iface, PACKET_TYPE_LS_UPDATE); - ptr += sizeof(struct ospf_hdr); + if (gen_ospf_hdr(buf, iface, PACKET_TYPE_LS_UPDATE)) + goto fail; nlsa = htonl(1); - memcpy(ptr, &nlsa, sizeof(nlsa)); - ptr += sizeof(nlsa); + if (buf_add(buf, &nlsa, sizeof(nlsa))) + goto fail; - memcpy(ptr, data, len); /* XXX */ + pos = buf->wpos; + if (buf_add(buf, data, len)) + goto fail; /* age LSA befor sending it out */ - memcpy(&age, ptr, sizeof(age)); + memcpy(&age, data, sizeof(age)); age = ntohs(age); if ((age += iface->transmit_delay) >= MAX_AGE) age = MAX_AGE; age = ntohs(age); - memcpy(ptr, &age, sizeof(age)); - - ptr += len; + memcpy(buf_seek(buf, pos, sizeof(age)), &age, sizeof(age)); /* update authentication and calculate checksum */ - auth_gen(buf, ptr - buf, iface); + if (auth_gen(buf, iface)) + goto fail; - if ((ret = send_packet(iface, buf, (ptr - buf), &dst)) == -1) - log_warnx("send_ls_update: error sending packet on " - "interface %s", iface->name); + ret = send_packet(iface, buf->buf, buf->wpos, &dst); - free(buf); + buf_free(buf); return (ret); +fail: + log_warn("send_hello"); + buf_free(buf); + return (-1); } void diff --git a/usr.sbin/ospfd/ospfd.h b/usr.sbin/ospfd/ospfd.h index 7bf1bfb24e0..ee51a7d6ba3 100644 --- a/usr.sbin/ospfd/ospfd.h +++ b/usr.sbin/ospfd/ospfd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfd.h,v 1.24 2005/03/31 19:32:10 norby Exp $ */ +/* $OpenBSD: ospfd.h,v 1.25 2005/04/05 13:01:22 claudio Exp $ */ /* * Copyright (c) 2004 Esben Norby <norby@openbsd.org> @@ -37,6 +37,7 @@ #define LSA_HASHSIZE 512 #define READ_BUF_SIZE 65535 +#define PKG_DEF_SIZE 512 /* compromise */ #define RT_BUF_SIZE 16384 #define MAX_RTSOCK_BUF 128 * 1024 diff --git a/usr.sbin/ospfd/ospfe.h b/usr.sbin/ospfd/ospfe.h index 268ba23082e..3aa2d80235d 100644 --- a/usr.sbin/ospfd/ospfe.h +++ b/usr.sbin/ospfd/ospfe.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfe.h,v 1.10 2005/03/31 19:32:10 norby Exp $ */ +/* $OpenBSD: ospfe.h,v 1.11 2005/04/05 13:01:22 claudio Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -147,7 +147,7 @@ struct nbr { /* auth.c */ int auth_validate(void *buf, u_int16_t len, struct iface *, struct nbr *); -int auth_gen(void *, u_int16_t, struct iface *); +int auth_gen(struct buf *, struct iface *); void md_list_init(struct iface *); void md_list_add(struct iface *, u_int8_t, char *); void md_list_clr(struct iface *); @@ -291,7 +291,7 @@ const char *nbr_action_name(int); struct lsa_hdr *lsa_hdr_new(void); /* packet.c */ -void gen_ospf_hdr(void *, struct iface *, u_int8_t); +int gen_ospf_hdr(struct buf *, struct iface *, u_int8_t); int send_packet(struct iface *, char *, int, struct sockaddr_in *); void recv_packet(int, short, void *); diff --git a/usr.sbin/ospfd/packet.c b/usr.sbin/ospfd/packet.c index 3c95b8a3f28..ebf7fcd343e 100644 --- a/usr.sbin/ospfd/packet.c +++ b/usr.sbin/ospfd/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.6 2005/03/31 19:32:10 norby Exp $ */ +/* $OpenBSD: packet.c,v 1.7 2005/04/05 13:01:22 claudio Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -41,18 +41,19 @@ int ospf_hdr_sanity_check(const struct ip *, struct ospf_hdr *, u_int16_t, const struct iface *); struct iface *find_iface(struct ospfd_conf *, struct in_addr); -void -gen_ospf_hdr(void *buf, struct iface *iface, u_int8_t type) +int +gen_ospf_hdr(struct buf *buf, struct iface *iface, u_int8_t type) { - struct ospf_hdr *ospf_hdr = buf; - - ospf_hdr->version = OSPF_VERSION; - ospf_hdr->type = type; - ospf_hdr->len = 0; /* updated later */ - ospf_hdr->rtr_id = iface->rtr_id.s_addr; - ospf_hdr->area_id = iface->area->id.s_addr; - ospf_hdr->chksum = 0; /* updated later */ - ospf_hdr->auth_type = htons(iface->auth_type); + struct ospf_hdr ospf_hdr; + + bzero(&ospf_hdr, sizeof(ospf_hdr)); + ospf_hdr.version = OSPF_VERSION; + ospf_hdr.type = type; + ospf_hdr.rtr_id = iface->rtr_id.s_addr; + ospf_hdr.area_id = iface->area->id.s_addr; + ospf_hdr.auth_type = htons(iface->auth_type); + + return (buf_add(buf, &ospf_hdr, sizeof(ospf_hdr))); } /* send and receive packets */ @@ -65,11 +66,6 @@ send_packet(struct iface *iface, char *pkt, int len, struct sockaddr_in *dst) return (-1); } - /* XXX I don't like this */ - /* MD5 digest is _not_ part of the OSPF packet len */ - if (iface->auth_type == AUTH_CRYPT) - len += MD5_DIGEST_LENGTH; - /* set outgoing interface for multicast traffic */ if (IN_MULTICAST(ntohl(dst->sin_addr.s_addr))) if (if_set_mcast(iface) == -1) { |