These are chat archives for CZ-NIC/knot-resolver

23rd
Aug 2018
Elctro
@Elctro
Aug 23 2018 16:29

Hello. I'd like to redirect DNS requests - I want a knot-resolver module modify the answer in a way that it gives the consumer A record of a localhost for any type of question. This is my redirect method, which modifies answer in the finish callback, and works as expected for both A (or AAAA) type of answers, but it struggles with CNAME answers. Any ideas what I missed?

static int redirect(struct kr_request * request, struct kr_query *last, int rrtype, struct ip_addr * origin)
{
    uint16_t msgid = knot_wire_get_id(request->answer->wire);
    char message[KNOT_DNAME_MAXLEN] = {};
    struct sockaddr_storage sinkhole;
    parse_addr_str(&sinkhole, "127.0.0.1")
    kr_pkt_recycle(request->answer);
    knot_pkt_put_question(request->answer, last->sname, last->sclass, last->stype);
    knot_pkt_begin(request->answer, KNOT_ANSWER);
    size_t addr_len = kr_inaddr_len((struct sockaddr *)&sinkhole);
    const uint8_t *raw_addr = (const uint8_t *)kr_inaddr((struct sockaddr *)&sinkhole);
    static knot_rdata_t rdata_arr[RDATA_ARR_MAX];
    knot_wire_set_id(request->answer->wire, msgid);
    kr_pkt_put(request->answer, last->sname, 1, KNOT_CLASS_IN, rrtype, raw_addr, addr_len);

    return KNOT_STATE_DONE;
}

I tried to change the rrtype from KNOT_RRTYPE_CNAME to KNOT_RRTYPE_A in the kr_pkt_put call, but that is not enough :(