/* FIXME This is VERY uneficient, I have huge endianity problems */ void lsasum_calculate(struct ospf_lsa_header *h, void *body) { u16 length = h->length; // log(L_WARN "Checksum %R %R %d start (len %d)", h->id, h->rt, h->type, length); lsa_hton_hdr(h, h); lsa_hton_body1(body, length - sizeof(struct ospf_lsa_header)); /* char buf[1024]; memcpy(buf, h, sizeof(struct ospf_lsa_header)); memcpy(buf + sizeof(struct ospf_lsa_header), body, length - sizeof(struct ospf_lsa_header)); buf_dump("CALC", buf, length); */ (void) lsasum_check(h, body, 1); // log(L_WARN "Checksum result %4x", h->checksum); lsa_ntoh_hdr(h, h); lsa_ntoh_body1(body, length - sizeof(struct ospf_lsa_header)); }
static int ospf_process_dbdes(struct ospf_proto *p, struct ospf_packet *pkt, struct ospf_neighbor *n) { struct ospf_iface *ifa = n->ifa; struct ospf_lsa_header *lsas, lsa; struct top_hash_entry *en, *req; const char *err_dsc = NULL; u32 lsa_type, lsa_domain; uint i, lsa_count; ospf_dbdes_body(p, pkt, &lsas, &lsa_count); for (i = 0; i < lsa_count; i++) { lsa_ntoh_hdr(lsas + i, &lsa); lsa_get_type_domain(&lsa, ifa, &lsa_type, &lsa_domain); /* RFC 2328 10.6 and RFC 5340 4.2.2 */ if (!lsa_type) DROP1("LSA of unknown type"); if (!oa_is_ext(ifa->oa) && (LSA_SCOPE(lsa_type) == LSA_SCOPE_AS)) DROP1("LSA with AS scope in stub area"); /* Errata 3746 to RFC 2328 - rt-summary-LSAs forbidden in stub areas */ if (!oa_is_ext(ifa->oa) && (lsa_type == LSA_T_SUM_RT)) DROP1("rt-summary-LSA in stub area"); /* Not explicitly mentioned in RFC 5340 4.2.2 but makes sense */ if (LSA_SCOPE(lsa_type) == LSA_SCOPE_RES) DROP1("LSA with invalid scope"); en = ospf_hash_find(p->gr, lsa_domain, lsa.id, lsa.rt, lsa_type); if (!en || (lsa_comp(&lsa, &(en->lsa)) == CMP_NEWER)) { /* This should be splitted to ospf_lsa_lsrq_up() */ req = ospf_hash_get(n->lsrqh, lsa_domain, lsa.id, lsa.rt, lsa_type); if (!SNODE_VALID(req)) s_add_tail(&n->lsrql, SNODE req); if (!SNODE_VALID(n->lsrqi)) n->lsrqi = req; req->lsa = lsa; req->lsa_body = LSA_BODY_DUMMY; if (!tm_active(n->lsrq_timer)) tm_start(n->lsrq_timer, 0); } } return 0; drop: LOG_LSA1("Bad LSA (Type: %04x, Id: %R, Rt: %R) in DBDES", lsa_type, lsa.id, lsa.rt); LOG_LSA2(" received from nbr %R on %s - %s", n->rid, ifa->ifname, err_dsc); ospf_neigh_sm(n, INM_SEQMIS); return -1; }