コード例 #1
0
ファイル: exec.c プロジェクト: gitter-badger/knot
static void print_section_opt(const knot_rrset_t *rr, const uint8_t rcode)
{
    uint8_t        ercode = knot_edns_get_ext_rcode(rr);
    uint16_t       ext_rcode_id = knot_edns_whole_rcode(ercode, rcode);
    const char     *ext_rcode_str = "Unused";
    lookup_table_t *ext_rcode;

    if (ercode > 0) {
        ext_rcode = lookup_by_id(knot_rcode_names, ext_rcode_id);
        if (ext_rcode != NULL) {
            ext_rcode_str = ext_rcode->name;
        } else {
            ext_rcode_str = "Unknown";
        }
    }

    printf("Version: %u; flags: %s; UDP size: %u B; ext-rcode: %s\n",
           knot_edns_get_version(rr),
           (knot_edns_do(rr) != 0) ? "do" : "",
           knot_edns_get_payload(rr),
           ext_rcode_str);

    knot_rdata_t *rdata = knot_rdataset_at(&rr->rrs, 0);
    assert(rdata != NULL);

    uint16_t data_len = knot_rdata_rdlen(rdata);
    uint8_t *data = knot_rdata_data(rdata);
    int pos = 0;

    while (pos < data_len - KNOT_EDNS_OPTION_HDRLEN) {
        uint16_t opt_code = wire_read_u16(data + pos);
        uint16_t opt_len = wire_read_u16(data + pos + 2);
        uint8_t *opt_data = data + pos + 4;

        switch (opt_code) {
        case KNOT_EDNS_OPTION_NSID:
            printf(";; NSID: ");
            short_hex_print(opt_data, opt_len);
            if (opt_len > 0) {
                printf(";;     :  ");
                txt_print(opt_data, opt_len);
            }
            break;
        case KNOT_EDNS_OPTION_CLIENT_SUBNET:
            printf(";; CLIENT-SUBNET: ");
            print_edns_client_subnet(opt_data, opt_len);
            break;
        default:
            printf(";; Option (%u): ", opt_code);
            short_hex_print(opt_data, opt_len);
        }

        pos += 4 + opt_len;
    }
}
コード例 #2
0
ファイル: bindings.c プロジェクト: PaulosV/knot-resolver
/** Set UDP maximum payload size. */
static int net_bufsize(lua_State *L)
{
    struct engine *engine = engine_luaget(L);
    knot_rrset_t *opt_rr = engine->resolver.opt_rr;
    if (!lua_isnumber(L, 1)) {
        lua_pushnumber(L, knot_edns_get_payload(opt_rr));
        return 1;
    }
    int bufsize = lua_tointeger(L, 1);
    if (bufsize < KNOT_EDNS_MIN_DNSSEC_PAYLOAD || bufsize > UINT16_MAX) {
        format_error(L, "bufsize must be within <1220, 65535>");
        lua_error(L);
    }
    knot_edns_set_payload(opt_rr, (uint16_t) bufsize);
    return 0;
}
コード例 #3
0
ファイル: edns.c プロジェクト: idtek/knot
static bool test_getters(knot_rrset_t *opt_rr, int *done)
{
	assert(opt_rr != NULL);
	assert(done != NULL);
	bool success = true;

	/* These values should be set from the setters test:
	 * Max UDP payload: E_MAX_PLD2
	 * Version:         E_VERSION2
	 * RCODE:           E_RCODE2
	 * Flags:           E_FLAGS | KNOT_EDNS_FLAG_DO
	 * OPTIONs:         1) KNOT_EDNS_OPTION_NSID, E_NSID_LEN, E_NSID_STR
	 *                  2) E_OPT3_CODE, 0, 0
	 *                  3) E_OPT4_CODE, 0, 0
	 */

	/* Payload */
	bool check = (knot_edns_get_payload(opt_rr) == E_MAX_PLD2);
	ok(check, "OPT RR getters: payload");
	success &= check;
	(*done)++;

	/* Extended RCODE */
	check = (knot_edns_get_ext_rcode(opt_rr) == E_RCODE2);
	ok(check, "OPT RR getters: extended RCODE");
	success &= check;
	(*done)++;

	/* Extended RCODE */
	check = (knot_edns_get_version(opt_rr) == E_VERSION2);
	ok(check, "OPT RR getters: version");
	success &= check;
	(*done)++;

	/* DO bit */
	check = knot_edns_do(opt_rr);
	ok(check, "OPT RR getters: DO bit check");
	success &= check;
	(*done)++;

	/* Wire size */
	size_t total_size = KNOT_EDNS_MIN_SIZE
	                    + E_NSID_SIZE + E_OPT3_SIZE + E_OPT4_SIZE;
	size_t actual_size = knot_edns_wire_size(opt_rr);
	check = actual_size == total_size;
	ok(check, "OPT RR getters: wire size (expected: %zu, actual: %zu)",
	   total_size, actual_size);
	success &= check;
	(*done)++;

	/* NSID */
	check = knot_edns_has_option(opt_rr, KNOT_EDNS_OPTION_NSID);
	ok(check, "OPT RR getters: NSID check");
	success &= check;
	(*done)++;

	/* Other OPTIONs */
	check = knot_edns_has_option(opt_rr, E_OPT3_CODE);
	ok(check, "OPT RR getters: empty option 1");
	success &= check;
	(*done)++;

	check = knot_edns_has_option(opt_rr, E_OPT4_CODE);
	ok(check, "OPT RR getters: empty option 2");
	success &= check;
	(*done)++;

	return success;
}