diff options
author | Alexandre Pion <pion@afnic.fr> | 2022-11-03 13:30:44 +0100 |
---|---|---|
committer | Alexandre Pion <pion@afnic.fr> | 2022-11-03 13:30:44 +0100 |
commit | b5930f6dfb20947a2ba06ffcb8115cad74c2831e (patch) | |
tree | 98fcf8c66fae16ecaffb37405abed1a56bc6c5d7 | |
parent | 1411fcb2509788ce70e9fd25670e0550572e9f51 (diff) | |
parent | 7535a41d35e7d8ebfa4ba603b00ac89dfe2dd0a0 (diff) |
Merge pull request #151 from pnax/nsid
Add support for NSID option + update internal LDNS to 1.8.3
-rw-r--r-- | MANIFEST | 7 | ||||
-rw-r--r-- | Makefile.PL | 22 | ||||
m--------- | ldns | 0 | ||||
-rw-r--r-- | src/LDNS.xs | 70 | ||||
-rw-r--r-- | t/nsid.t | 22 |
5 files changed, 120 insertions, 1 deletions
@@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/Makefile.PL b/Makefile.PL index 9f4fc66..1a066bd 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -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"; @@ -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"; } diff --git a/ldns b/ldns -Subproject 53bc57512c19b11eebc403a4cb2bbf7295eb0db +Subproject 173fbf303518d060e0d2bdc0bbd1830c0ec8f21 diff --git a/src/LDNS.xs b/src/LDNS.xs index bf051ff..822018a 100644 --- a/src/LDNS.xs +++ b/src/LDNS.xs @@ -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; diff --git a/t/nsid.t b/t/nsid.t new file mode 100644 index 0000000..f4a5478 --- /dev/null +++ b/t/nsid.t @@ -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(); |