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 2 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
17 changes: 17 additions & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,23 @@ else {
}
}

# NSID feature requires LDNS version >= 1.8.2
my $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";
}


# Libidn

Expand Down
66 changes: 66 additions & 0 deletions src/LDNS.xs
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,72 @@ 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_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