summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Pion <pion@afnic.fr>2022-08-23 19:00:34 +0200
committerAlexandre Pion <pion@afnic.fr>2022-09-28 15:32:11 +0200
commit4fdde0900fa27cb27444f99c959573b8d6267166 (patch)
treed43ee0ab3a2b7fd7d881aa74f41f3cf780a03545
parentb545a9fc10a70dc5370ea04950d4bb5fbe390f60 (diff)
Set and get EDNS option NSID for/from a packet
-rw-r--r--src/LDNS.xs54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/LDNS.xs b/src/LDNS.xs
index becb907..3806c10 100644
--- a/src/LDNS.xs
+++ b/src/LDNS.xs
@@ -1407,6 +1407,60 @@ 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:
+ 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);
+
+#
+# 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:
+ 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;
+ OUTPUT:
+ RETVAL
+
SV *
packet_type(obj)
Zonemaster::LDNS::Packet obj;