diff options
-rw-r--r-- | usr.sbin/ospfd/iso_cksum.c | 38 | ||||
-rw-r--r-- | usr.sbin/ospfd/rde.c | 22 |
2 files changed, 40 insertions, 20 deletions
diff --git a/usr.sbin/ospfd/iso_cksum.c b/usr.sbin/ospfd/iso_cksum.c index f3a050b37fe..de8d2c6a156 100644 --- a/usr.sbin/ospfd/iso_cksum.c +++ b/usr.sbin/ospfd/iso_cksum.c @@ -1,4 +1,4 @@ -/* $OpenBSD: iso_cksum.c,v 1.1 2005/01/28 14:05:40 claudio Exp $ */ +/* $OpenBSD: iso_cksum.c,v 1.2 2005/10/12 09:51:58 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -21,17 +21,18 @@ #include "ospfd.h" #include "log.h" +/* implementation of Fletcher Checksum -- see RFC 1008 for more info */ + /* pos needs to be 0 for verify and 2 <= pos < len for calculation */ u_int16_t iso_cksum(void *buf, u_int16_t len, u_int16_t pos) { u_int8_t *p = buf; - int c0 = 0, c1 = 0; /* counters */ - int r0, r1; /* results */ + int c0 = 0, c1 = 0, x; /* counters */ u_int16_t sop; - sop = len - pos - 1; /* pos is an offset (pos 2 is at len 3) */ - p += 2; + sop = len - pos - 1; /* pos is an offset (pos 2 is 3rd element) */ + p += 2; /* jump over age field */ len -= 2; while (len--) { c0 += *p++; @@ -41,18 +42,27 @@ iso_cksum(void *buf, u_int16_t len, u_int16_t pos) c0 %= 255; c1 %= 255; } +#ifdef DEBUG + if (c0 + 256 < c0 || c1 + 256 < c1) + fatalx("iso_cksum: overflowed"); +#endif } - r0 = c0 = c0 % 255; - r1 = c1 % 255; if (pos) { - r0 = ((sop * r0 - r1)) % 255; - if (r0 <= 0) - r0 += 255; - r1 = 510 - r0 - c0; - if (r1 > 255) - r1 -= 255; + x = ((sop * c0 - c1)) % 255; + if (x <= 0) + x += 255; +#if 1 + c1 = 510 - c0 - x; + if (c1 > 255) + c1 -= 255; +#else + c1 = (-c0 - x) % 255; + if (c1 < 0) + c1 += 255; +#endif + c0 = x; } - return (r0 << 8 | r1); + return (c0 << 8 | c1); } diff --git a/usr.sbin/ospfd/rde.c b/usr.sbin/ospfd/rde.c index f538f41cde2..200d5fc3f13 100644 --- a/usr.sbin/ospfd/rde.c +++ b/usr.sbin/ospfd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.29 2005/10/12 09:42:57 claudio Exp $ */ +/* $OpenBSD: rde.c,v 1.30 2005/10/12 09:51:58 claudio Exp $ */ /* * Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org> @@ -402,20 +402,30 @@ rde_dispatch_imsg(int fd, short event, void *bula) /* lsa not added so free it */ if (self) free(lsa); - } else if (rde_req_list_exists(nbr, &lsa->hdr)) { - /* lsa no longer needed */ - free(lsa); - imsg_compose(ibuf_ospfe, IMSG_LS_BADREQ, - imsg.hdr.peerid, 0, -1, NULL, 0); } else if (r < 0) { /* lsa no longer needed */ free(lsa); + /* + * point 6 of "The Flooding Procedure" + * We are violating the RFC here because + * it does not make sense to reset a session + * because a equal LSA is already in the table. + * Only if the LSA sent is older than the one + * in the table we should reset the session. + */ + if (rde_req_list_exists(nbr, &lsa->hdr)) { + imsg_compose(ibuf_ospfe, IMSG_LS_BADREQ, + imsg.hdr.peerid, 0, -1, NULL, 0); + break; + } + /* new LSA older than DB */ if (ntohl(db_hdr->seq_num) == MAX_SEQ_NUM && ntohs(db_hdr->age) == MAX_AGE) /* seq-num wrap */ break; + if (v->changed + MIN_LS_ARRIVAL >= now) break; |