Beispiel #1
0
void print_header_xfr(const knot_pkt_t *packet, const style_t  *style)
{
    if (style == NULL) {
        DBG_NULL;
        return;
    }

    char xfr[16] = "AXFR";

    switch (knot_pkt_qtype(packet)) {
    case KNOT_RRTYPE_AXFR:
        break;
    case KNOT_RRTYPE_IXFR:
        xfr[0] = 'I';
        break;
    default:
        return;
    }

    if (style->show_header) {
        char *owner = knot_dname_to_str_alloc(knot_pkt_qname(packet));
        if (style->style.ascii_to_idn != NULL) {
            style->style.ascii_to_idn(&owner);
        }
        if (owner != NULL) {
            printf(";; %s for %s\n", xfr, owner);
            free(owner);
        }
    }
}
Beispiel #2
0
static void print_error_host(const uint16_t   code,
                             const knot_pkt_t *packet,
                             const style_t    *style)
{
    const char *rcode_str = "Unknown";
    char type[32] = "Unknown";
    char *owner;

    lookup_table_t *rcode;

    owner = knot_dname_to_str_alloc(knot_pkt_qname(packet));
    if (style->style.ascii_to_idn != NULL) {
        style->style.ascii_to_idn(&owner);
    }

    rcode = lookup_by_id(knot_rcode_names, code);
    if (rcode != NULL) {
        rcode_str = rcode->name;
    }
    knot_rrtype_to_string(knot_pkt_qtype(packet), type, sizeof(type));

    if (code == KNOT_RCODE_NOERROR) {
        printf("Host %s has no %s record\n", owner, type);
    } else {
        printf("Host %s type %s error: %s\n", owner, type, rcode_str);
    }

    free(owner);
}
Beispiel #3
0
static void print_section_host(const knot_rrset_t *rrsets,
                               const uint16_t     count,
                               const style_t      *style)
{
    size_t buflen = 8192;
    char   *buf = calloc(buflen, 1);

    for (size_t i = 0; i < count; i++) {
        const knot_rrset_t *rrset = &rrsets[i];
        lookup_table_t     *descr;
        char               type[32] = "NULL";
        char               *owner;

        owner = knot_dname_to_str_alloc(rrset->owner);
        if (style->style.ascii_to_idn != NULL) {
            style->style.ascii_to_idn(&owner);
        }
        descr = lookup_by_id(rtypes, rrset->type);

        uint16_t rrset_rdata_count = rrset->rrs.rr_count;
        for (uint16_t j = 0; j < rrset_rdata_count; j++) {
            if (rrset->type == KNOT_RRTYPE_CNAME &&
                    style->hide_cname) {
                continue;
            }

            while (knot_rrset_txt_dump_data(rrset, j, buf, buflen,
                                            &(style->style)) < 0) {
                buflen += 4096;
                // Oversize protection.
                if (buflen > 100000) {
                    WARN("can't print whole section\n");
                    break;
                }

                char *newbuf = realloc(buf, buflen);
                if (newbuf == NULL) {
                    WARN("can't print whole section\n");
                    break;
                }
                buf = newbuf;
            }

            if (descr != NULL) {
                printf("%s %s %s\n", owner, descr->name, buf);
            } else {
                knot_rrtype_to_string(rrset->type, type,
                                      sizeof(type));
                printf("%s has %s record %s\n",
                       owner, type, buf);
            }
        }

        free(owner);
    }

    free(buf);
}
Beispiel #4
0
int zone_contents_remove_node(zone_contents_t *contents, const knot_dname_t *owner)
{
	if (contents == NULL || owner == NULL) {
		return KNOT_EINVAL;
	}

dbg_zone_exec_verb(
	char *name = knot_dname_to_str_alloc(owner);
	dbg_zone_verb("Removing zone node: %s\n", name);
	free(name);
);
Beispiel #5
0
int log_msg_zone(int priority, const knot_dname_t *zone, const char *fmt, ...)
{
	va_list args;
	va_start(args, fmt);
	char *zone_str = knot_dname_to_str_alloc(zone);
	int result = log_msg_text(priority,
				  zone_str ? zone_str : LOG_NULL_ZONE_STRING,
				  fmt, args);
	free(zone_str);
	va_end(args);

	return result;
}
Beispiel #6
0
int zone_tree_get_less_or_equal(zone_tree_t *tree,
                                const knot_dname_t *owner,
                                zone_node_t **found,
                                zone_node_t **previous)
{
	if (owner == NULL || found == NULL || previous == NULL) {
		return KNOT_EINVAL;
	}

	if (zone_tree_is_empty(tree)) {
		return KNOT_ENONODE;
	}

	uint8_t lf[KNOT_DNAME_MAXLEN];
	knot_dname_lf(lf, owner, NULL);

	value_t *fval = NULL;
	int ret = hattrie_find_leq(tree, (char*)lf+1, *lf, &fval);
	if (fval) {
		*found = (zone_node_t *)(*fval);
	}
	int exact_match = 0;
	if (ret == 0) {
		if (fval) {
			*previous = (*found)->prev;
		}
		exact_match = 1;
	} else if (ret < 0) {
		*previous = *found;
		*found = NULL;
	} else if (ret > 0) {
		/* Previous should be the rightmost node.
		 * For regular zone it is the node left of apex, but for some
		 * cases like NSEC3, there is no such sort of thing (name wise).
		 */
		/*! \todo We could store rightmost node in zonetree probably. */
		hattrie_iter_t *i = hattrie_iter_begin(tree, 1);
		*previous = *(zone_node_t **)hattrie_iter_val(i); /* leftmost */
		*previous = (*previous)->prev; /* rightmost */
		*found = NULL;
		hattrie_iter_free(i);
	}

	/* Previous node for proof must be non-empty and authoritative. */
	if (*previous &&
	    ((*previous)->rrset_count == 0 || (*previous)->flags & NODE_FLAGS_NONAUTH)) {
		*previous = (*previous)->prev;
	}

dbg_zone_exec_detail(
		char *name = knot_dname_to_str_alloc(owner);
		char *name_f = (*found != NULL)
			? knot_dname_to_str_alloc((*found)->owner)
			: "none";

		dbg_zone_detail("Searched for owner %s in zone tree.\n",
				name);
		dbg_zone_detail("Exact match: %d\n", exact_match);
		dbg_zone_detail("Found node: %p: %s.\n", *found, name_f);
		dbg_zone_detail("Previous node: %p.\n", *previous);

		free(name);
		if (*found != NULL) {
			free(name_f);
		}
);