Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for NSID option + update internal LDNS to 1.8.3 #151

Merged
7 commits merged into from Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ inc/Module/Install/Win32.pm
inc/Module/Install/WriteAll.pm
inc/Module/Install/XSUtil.pm
include/LDNS.h
ldns/.github/FUNDING.yml
ldns/.github/workflows/testsuite.yml
ldns/buffer.c
ldns/compat/b64_ntop.c
ldns/compat/b64_pton.c
Expand All @@ -25,6 +27,7 @@ ldns/dnssec_sign.c
ldns/dnssec_verify.c
ldns/dnssec_zone.c
ldns/duration.c
ldns/edns.c
ldns/error.c
ldns/higher.c
ldns/host2str.c
Expand All @@ -41,6 +44,7 @@ ldns/ldns/dnssec_sign.h
ldns/ldns/dnssec_verify.h
ldns/ldns/dnssec_zone.h
ldns/ldns/duration.h
ldns/ldns/edns.h
ldns/ldns/error.h
ldns/ldns/higher.h
ldns/ldns/host2str.h
Expand All @@ -64,6 +68,7 @@ ldns/ldns/update.h
ldns/ldns/util.h.in
ldns/ldns/wire2host.h
ldns/ldns/zone.h
ldns/libdns.doxygen.in
ldns/LICENSE
ldns/ltmain.sh
ldns/Makefile.in
Expand All @@ -75,6 +80,7 @@ ldns/parse.c
ldns/radix.c
ldns/rbtree.c
ldns/rdata.c
ldns/README-Travis.md
ldns/resolver.c
ldns/rr.c
ldns/rr_functions.c
Expand Down Expand Up @@ -180,6 +186,7 @@ t/example.org
t/idn.t
t/load_zonefile.t
t/netldns.t
t/nsid.t
t/packet.t
t/regression.t
t/resolver.t
Expand Down
22 changes: 21 additions & 1 deletion Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,15 @@ else {
}


# LDNS
# LDNS and NSID

my $ldns_has_nsid;

if ( $opt_internal_ldns ) {
print "Feature internal ldns enabled\n";
cc_libs '-Lldns/lib';
cc_include_paths 'ldns';
$ldns_has_nsid = 1;
}
else {
print "Feature internal ldns disabled\n";
Expand All @@ -241,6 +244,23 @@ else {
function => 'if(LDNS_ED25519) return 0; else return 1;'
);
}

# NSID feature requires LDNS version >= 1.8.2
$ldns_has_nsid = check_lib(
debug => $opt_debug,
lib => 'ldns',
header => 'ldns/util.h',
%{ $assert_lib_args{ldns} },
function => 'if ( LDNS_REVISION >= ((1<<16)|(8<<8)|(2)) ) return 0; else return 1;'
);
}

if ( $ldns_has_nsid ) {
print "Feature NSID enabled\n";
cc_define '-DNSID_SUPPORT';
}
else {
print "Feature NSID disabled\n";
}


Expand Down
2 changes: 1 addition & 1 deletion ldns
Submodule ldns updated 204 files
70 changes: 70 additions & 0 deletions src/LDNS.xs
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,76 @@ packet_needs_edns(obj)
OUTPUT:
RETVAL

#
# Function: nsid
# --------------
# Set the EDNS option NSID in the packet
#
void
packet_nsid(obj)
Zonemaster::LDNS::Packet obj;
CODE:
{
#ifdef NSID_SUPPORT
ldns_edns_option_list* edns_list;
ldns_edns_option* edns_opt;

edns_list = ldns_pkt_edns_get_option_list(obj);

if ( !edns_list )
edns_list = ldns_edns_option_list_new();

edns_opt = ldns_edns_new_from_data(LDNS_EDNS_NSID, 0, NULL);
if ( edns_list == NULL || edns_opt == NULL )
croak("Could not allocate EDNS option");
if ( ! ldns_edns_option_list_push(edns_list, edns_opt) )
croak("Could not attach EDNS option NSID");
ldns_pkt_set_edns_option_list(obj, edns_list);
#else
croak("NSID not supported");
#endif
}

#
# Function: get_nsid
# ------------------
# Get the EDNS option NSID if any from the packet
#
# returns: a bytes string (or undef if no NSID is found)
#
SV *
packet_get_nsid(obj)
Zonemaster::LDNS::Packet obj;
CODE:
{
#ifdef NSID_SUPPORT
ldns_edns_option_list* edns_list;
ldns_edns_option* edns_opt;
size_t count;

edns_list = ldns_pkt_edns_get_option_list(obj);
if ( edns_list == NULL )
XSRETURN_UNDEF;

RETVAL = NULL;
count = ldns_edns_option_list_get_count(edns_list);
for ( int i=0; i<count; i++ )
{
edns_opt = ldns_edns_option_list_get_option(edns_list, i);
if ( edns_opt == NULL )
continue;
if ( ldns_edns_get_code(edns_opt) == LDNS_EDNS_NSID )
RETVAL = newSVpv(ldns_edns_get_data(edns_opt), ldns_edns_get_size(edns_opt));
}
if ( RETVAL == NULL )
XSRETURN_UNDEF;
#else
croak("NSID not supported");
#endif
}
OUTPUT:
RETVAL

SV *
packet_type(obj)
Zonemaster::LDNS::Packet obj;
Expand Down
22 changes: 22 additions & 0 deletions t/nsid.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use strict;
use warnings;

use Test::More;
use Zonemaster::LDNS;

SKIP: {
skip 'no network', 1 unless $ENV{TEST_WITH_NETWORK};

my $host = '192.134.4.1'; #ns1.nic.fr with nsid: ns1.th3.nic.fr
my $expected_nsid = "ns1.th3.nic.fr";

my $pkt = Zonemaster::LDNS::Packet->new('domain.example');
$pkt->nsid; # set the NSID EDNS option
my $res = Zonemaster::LDNS->new($host)->query_with_pkt($pkt);

my $nsid = $res->get_nsid();

is( $nsid, $expected_nsid, 'Correct NSID' );
};

done_testing();