int check_send_expect(struct ctl_tcp_event *cte) { u_char *b; /* * ensure string is nul-terminated. */ b = ibuf_reserve(cte->buf, 1); if (b == NULL) fatal("out of memory"); *b = '\0'; if (fnmatch(cte->table->conf.exbuf, cte->buf->buf, 0) == 0) { cte->host->he = HCE_SEND_EXPECT_OK; cte->host->up = HOST_UP; return (0); } cte->host->he = HCE_SEND_EXPECT_FAIL; cte->host->up = HOST_UNKNOWN; /* * go back to original position. */ cte->buf->wpos--; return (1); }
int check_http_code(struct ctl_tcp_event *cte) { char *head; char scode[4]; const char *estr; u_char *b; int code; struct host *host; /* * ensure string is nul-terminated. */ b = ibuf_reserve(cte->buf, 1); if (b == NULL) fatal("out of memory"); *b = '\0'; head = cte->buf->buf; host = cte->host; host->he = HCE_HTTP_CODE_ERROR; if (strncmp(head, "HTTP/1.1 ", strlen("HTTP/1.1 ")) && strncmp(head, "HTTP/1.0 ", strlen("HTTP/1.0 "))) { log_debug("%s: %s failed (cannot parse HTTP version)", __func__, host->conf.name); host->up = HOST_DOWN; return (1); } head += strlen("HTTP/1.1 "); if (strlen(head) < 5) /* code + \r\n */ { host->up = HOST_DOWN; return (1); } (void)strlcpy(scode, head, sizeof(scode)); code = strtonum(scode, 100, 999, &estr); if (estr != NULL) { log_debug("%s: %s failed (cannot parse HTTP code)", __func__, host->conf.name); host->up = HOST_DOWN; return (1); } if (code != cte->table->conf.retcode) { log_debug("%s: %s failed (invalid HTTP code returned)", __func__, host->conf.name); host->he = HCE_HTTP_CODE_FAIL; host->up = HOST_DOWN; } else { host->he = HCE_HTTP_CODE_OK; host->up = HOST_UP; } return (!(host->up == HOST_UP)); }
int check_http_digest(struct ctl_tcp_event *cte) { char *head; u_char *b; char digest[SHA1_DIGEST_STRING_LENGTH]; struct host *host; /* * ensure string is nul-terminated. */ b = ibuf_reserve(cte->buf, 1); if (b == NULL) fatal("out of memory"); *b = '\0'; head = cte->buf->buf; host = cte->host; host->he = HCE_HTTP_DIGEST_ERROR; if ((head = strstr(head, "\r\n\r\n")) == NULL) { log_debug("%s: %s failed (no end of headers)", __func__, host->conf.name); host->up = HOST_DOWN; return (1); } head += strlen("\r\n\r\n"); digeststr(cte->table->conf.digest_type, head, strlen(head), digest); if (strcmp(cte->table->conf.digest, digest)) { log_warnx("%s: %s failed (wrong digest)", __func__, host->conf.name); host->he = HCE_HTTP_DIGEST_FAIL; host->up = HOST_DOWN; } else { host->he = HCE_HTTP_DIGEST_OK; host->up = HOST_UP; } return (!(host->up == HOST_UP)); }
/* database description packet handling */ int send_db_description(struct nbr *nbr) { struct in6_addr dst; struct db_dscrp_hdr dd_hdr; struct lsa_entry *le, *nle; struct ibuf *buf; int ret = 0; u_int8_t bits = 0; if ((buf = ibuf_open(nbr->iface->mtu - sizeof(struct ip))) == NULL) fatal("send_db_description"); /* OSPF header */ if (gen_ospf_hdr(buf, nbr->iface, PACKET_TYPE_DD)) goto fail; /* reserve space for database description header */ if (ibuf_reserve(buf, sizeof(dd_hdr)) == NULL) goto fail; switch (nbr->state) { case NBR_STA_DOWN: case NBR_STA_ATTEMPT: case NBR_STA_INIT: case NBR_STA_2_WAY: case NBR_STA_SNAP: log_debug("send_db_description: cannot send packet in state %s," " neighbor ID %s", nbr_state_name(nbr->state), inet_ntoa(nbr->id)); ret = -1; goto done; case NBR_STA_XSTRT: bits |= OSPF_DBD_MS | OSPF_DBD_M | OSPF_DBD_I; nbr->dd_more = 1; break; case NBR_STA_XCHNG: if (nbr->dd_master) bits |= OSPF_DBD_MS; else bits &= ~OSPF_DBD_MS; if (TAILQ_EMPTY(&nbr->db_sum_list)) { bits &= ~OSPF_DBD_M; nbr->dd_more = 0; } else { bits |= OSPF_DBD_M; nbr->dd_more = 1; } bits &= ~OSPF_DBD_I; /* build LSA list */ for (le = TAILQ_FIRST(&nbr->db_sum_list); le != NULL && buf->wpos + sizeof(struct lsa_hdr) < buf->max; le = nle) { nbr->dd_end = nle = TAILQ_NEXT(le, entry); if (ibuf_add(buf, le->le_lsa, sizeof(struct lsa_hdr))) goto fail; } break; case NBR_STA_LOAD: case NBR_STA_FULL: if (nbr->dd_master) bits |= OSPF_DBD_MS; else bits &= ~OSPF_DBD_MS; bits &= ~OSPF_DBD_M; bits &= ~OSPF_DBD_I; nbr->dd_more = 0; break; default: fatalx("send_db_description: unknown neighbor state"); } bzero(&dd_hdr, sizeof(dd_hdr)); switch (nbr->iface->type) { case IF_TYPE_POINTOPOINT: inet_pton(AF_INET6, AllSPFRouters, &dst); dd_hdr.iface_mtu = htons(nbr->iface->mtu); break; case IF_TYPE_BROADCAST: dst = nbr->addr; dd_hdr.iface_mtu = htons(nbr->iface->mtu); break; case IF_TYPE_NBMA: case IF_TYPE_POINTOMULTIPOINT: /* XXX not supported */ break; case IF_TYPE_VIRTUALLINK: dst = nbr->iface->dst; dd_hdr.iface_mtu = 0; break; default: fatalx("send_db_description: unknown interface type"); } dd_hdr.opts = htonl(area_ospf_options(area_find(oeconf, nbr->iface->area_id))); dd_hdr.bits = bits; dd_hdr.dd_seq_num = htonl(nbr->dd_seq_num); memcpy(ibuf_seek(buf, sizeof(struct ospf_hdr), sizeof(dd_hdr)), &dd_hdr, sizeof(dd_hdr)); /* calculate checksum */ if (upd_ospf_hdr(buf, nbr->iface)) goto fail; /* transmit packet */ ret = send_packet(nbr->iface, buf->buf, buf->wpos, &dst); done: ibuf_free(buf); return (ret); fail: log_warn("send_db_description"); ibuf_free(buf); return (-1); }