static void netbios_parser_dtor(struct netbios_parser *netbios_parser) { SLOG(LOG_DEBUG, "Destructing netbios_parser@%p", netbios_parser); parser_unref(&netbios_parser->msg_parser); parser_dtor(&netbios_parser->parser); streambuf_dtor(&netbios_parser->sbuf); }
static enum proto_parse_status netbios_parse(struct parser *parser, struct proto_layer *parent, unsigned way, uint8_t const *packet, size_t cap_len, size_t wire_len, struct timeval const *now, proto_okfn_t *okfn) { /* Sanity checks */ if (wire_len < NETBIOS_HEADER_SIZE) return PROTO_PARSE_ERR; if (cap_len < NETBIOS_HEADER_SIZE) return PROTO_TOO_SHORT; if (! packet_is_netbios(packet, cap_len)) return PROTO_PARSE_ERR; /* Parse */ struct netbios_proto_info info; netbios_proto_info_ctor(&info, NETBIOS_HEADER_SIZE, wire_len - NETBIOS_HEADER_SIZE); struct proto_layer layer; proto_layer_ctor(&layer, parent, parser, &info.info); uint8_t const *next_packet = packet + NETBIOS_HEADER_SIZE; struct parser *subparser = proto_cifs->ops->parser_new(proto_cifs, now); if (! subparser) goto fallback; /* List of protocols above NetBios: CIFS, SMB, ... */ int err = proto_parse(subparser, parent, way, next_packet, cap_len - NETBIOS_HEADER_SIZE, wire_len - NETBIOS_HEADER_SIZE, now, okfn); parser_unref(subparser); if (err) goto fallback; return PROTO_OK; fallback: (void)proto_parse(NULL, parent, way, next_packet, cap_len - NETBIOS_HEADER_SIZE, wire_len - NETBIOS_HEADER_SIZE, now, okfn); return PROTO_OK; }
static void callid_2_sdp_dtor(struct callid_2_sdp *c2s) { SLOG(LOG_DEBUG, "Destruct callid_2_sdp@%p for callid '%s'", c2s, c2s->call_id); HASH_REMOVE(&callids_2_sdps, c2s, entry); TAILQ_REMOVE(&callids_2_sdps_used, c2s, used_entry); parser_unref(&c2s->sdp_parser); }
static void tds_parser_dtor(struct tds_parser *tds_parser) { SLOG(LOG_DEBUG, "Destructing tds_parser@%p", tds_parser); parser_unref(&tds_parser->msg_parser); parser_dtor(&tds_parser->parser); streambuf_dtor(&tds_parser->sbuf); }
void stress_check(struct proto *proto) { struct timeval now; timeval_set_now(&now); log_set_level(LOG_ERR, NULL); srand(time(NULL)); struct parser *parser = proto->ops->parser_new(proto); assert(parser); for (unsigned nb_tests = 0; nb_tests < 10000 ; nb_tests ++) { size_t size; uint8_t *buf = random_buffer(&size, 20, 60); parser->proto->ops->parse(parser, NULL, rand()%1, buf, size, size, &now, size, buf); free(buf); } parser_unref(&parser); }
static enum proto_parse_status dns_tcp_parse(struct parser unused_ *parser, struct proto_layer *parent, unsigned way, uint8_t const *packet, size_t cap_len, size_t wire_len, struct timeval const *now, proto_okfn_t *okfn) { size_t const hlen = 2; size_t offset = 0; while (offset + hlen < cap_len) { size_t len = ntohs(*(uint16_t*)packet); offset += hlen; // Sanity check if (offset + len > wire_len) return PROTO_PARSE_ERR; struct parser *subparser = proto_dns->ops->parser_new(proto_dns, now); if (! subparser) break; int err = proto_parse(subparser, parent, way, packet+offset, cap_len-offset, wire_len-offset, now, okfn); parser_unref(subparser); if (err) break; offset += len; } return PROTO_OK; }
static enum proto_parse_status dns_tcp_parse(struct parser unused_ *parser, struct proto_info *parent, unsigned way, uint8_t const *packet, size_t cap_len, size_t wire_len, struct timeval const *now, size_t tot_cap_len, uint8_t const *tot_packet) { size_t const hlen = 2; size_t offset = 0; while (offset + hlen < cap_len) { size_t len = READ_U16N(packet); offset += hlen; // Sanity check if (offset + len > wire_len) return PROTO_PARSE_ERR; struct parser *dns = proto_dns->ops->parser_new(proto_dns); if (! dns) break; enum proto_parse_status status = proto_parse(dns, parent, way, packet+offset, cap_len-offset, wire_len-offset, now, tot_cap_len, tot_packet); parser_unref(&dns); if (status != PROTO_OK) break; offset += len; } return PROTO_OK; }
static void mgcp_parser_dtor(struct mgcp_parser *mgcp_parser) { parser_unref(&mgcp_parser->sdp_parser); parser_dtor(&mgcp_parser->parser); }