1825eb42bSJan Lentfer /* 2825eb42bSJan Lentfer * packet.h 3825eb42bSJan Lentfer * 4825eb42bSJan Lentfer * DNS packet definitions 5825eb42bSJan Lentfer * 6825eb42bSJan Lentfer * a Net::DNS like library for C 7825eb42bSJan Lentfer * 8825eb42bSJan Lentfer * (c) NLnet Labs, 2005-2006 9825eb42bSJan Lentfer * 10825eb42bSJan Lentfer * See the file LICENSE for the license 11825eb42bSJan Lentfer */ 12825eb42bSJan Lentfer 13825eb42bSJan Lentfer /** 14825eb42bSJan Lentfer * \file 15825eb42bSJan Lentfer * 16825eb42bSJan Lentfer * Contains the definition of ldns_pkt and its parts, as well 17825eb42bSJan Lentfer * as functions to manipulate those. 18825eb42bSJan Lentfer */ 19825eb42bSJan Lentfer 20825eb42bSJan Lentfer 21825eb42bSJan Lentfer #ifndef LDNS_PACKET_H 22825eb42bSJan Lentfer #define LDNS_PACKET_H 23825eb42bSJan Lentfer 24825eb42bSJan Lentfer #define LDNS_MAX_PACKETLEN 65535 25825eb42bSJan Lentfer 265340022aSzrj /* allow flags to be given to ldns_pkt_query_new */ 275340022aSzrj #define LDNS_QR 1 /* Query Response flag */ 28825eb42bSJan Lentfer #define LDNS_AA 2 /* Authoritative Answer - server flag */ 29825eb42bSJan Lentfer #define LDNS_TC 4 /* TrunCated - server flag */ 30825eb42bSJan Lentfer #define LDNS_RD 8 /* Recursion Desired - query flag */ 31825eb42bSJan Lentfer #define LDNS_CD 16 /* Checking Disabled - query flag */ 32825eb42bSJan Lentfer #define LDNS_RA 32 /* Recursion Available - server flag */ 33825eb42bSJan Lentfer #define LDNS_AD 64 /* Authenticated Data - server flag */ 34825eb42bSJan Lentfer 35825eb42bSJan Lentfer #include <ldns/error.h> 36825eb42bSJan Lentfer #include <ldns/common.h> 37825eb42bSJan Lentfer #include <ldns/rr.h> 38*ee791febSAntonio Huete Jimenez #include <ldns/edns.h> 39825eb42bSJan Lentfer #include <sys/time.h> 40825eb42bSJan Lentfer 41ac996e71SJan Lentfer #ifdef __cplusplus 42ac996e71SJan Lentfer extern "C" { 43ac996e71SJan Lentfer #endif 44ac996e71SJan Lentfer 45825eb42bSJan Lentfer /* opcodes for pkt's */ 46825eb42bSJan Lentfer enum ldns_enum_pkt_opcode { 47825eb42bSJan Lentfer LDNS_PACKET_QUERY = 0, 48825eb42bSJan Lentfer LDNS_PACKET_IQUERY = 1, 49825eb42bSJan Lentfer LDNS_PACKET_STATUS = 2, /* there is no 3?? DNS is weird */ 50825eb42bSJan Lentfer LDNS_PACKET_NOTIFY = 4, 51825eb42bSJan Lentfer LDNS_PACKET_UPDATE = 5 52825eb42bSJan Lentfer }; 53825eb42bSJan Lentfer typedef enum ldns_enum_pkt_opcode ldns_pkt_opcode; 54825eb42bSJan Lentfer 55825eb42bSJan Lentfer /* rcodes for pkts */ 56825eb42bSJan Lentfer enum ldns_enum_pkt_rcode { 57825eb42bSJan Lentfer LDNS_RCODE_NOERROR = 0, 58825eb42bSJan Lentfer LDNS_RCODE_FORMERR = 1, 59825eb42bSJan Lentfer LDNS_RCODE_SERVFAIL = 2, 60825eb42bSJan Lentfer LDNS_RCODE_NXDOMAIN = 3, 61825eb42bSJan Lentfer LDNS_RCODE_NOTIMPL = 4, 62825eb42bSJan Lentfer LDNS_RCODE_REFUSED = 5, 63825eb42bSJan Lentfer LDNS_RCODE_YXDOMAIN = 6, 64825eb42bSJan Lentfer LDNS_RCODE_YXRRSET = 7, 65825eb42bSJan Lentfer LDNS_RCODE_NXRRSET = 8, 66825eb42bSJan Lentfer LDNS_RCODE_NOTAUTH = 9, 67825eb42bSJan Lentfer LDNS_RCODE_NOTZONE = 10 68825eb42bSJan Lentfer }; 69825eb42bSJan Lentfer typedef enum ldns_enum_pkt_rcode ldns_pkt_rcode; 70825eb42bSJan Lentfer 71825eb42bSJan Lentfer /** 72825eb42bSJan Lentfer * Header of a dns packet 73825eb42bSJan Lentfer * 74825eb42bSJan Lentfer * Contains the information about the packet itself, as specified in RFC1035 75825eb42bSJan Lentfer <pre> 76825eb42bSJan Lentfer 4.1.1. Header section format 77825eb42bSJan Lentfer 78825eb42bSJan Lentfer The header contains the following fields: 79825eb42bSJan Lentfer 80825eb42bSJan Lentfer 1 1 1 1 1 1 81825eb42bSJan Lentfer 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 82825eb42bSJan Lentfer +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 83825eb42bSJan Lentfer | ID | 84825eb42bSJan Lentfer +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 85825eb42bSJan Lentfer |QR| Opcode |AA|TC|RD|RA| Z | RCODE | 86825eb42bSJan Lentfer +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 87825eb42bSJan Lentfer | QDCOUNT | 88825eb42bSJan Lentfer +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 89825eb42bSJan Lentfer | ANCOUNT | 90825eb42bSJan Lentfer +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 91825eb42bSJan Lentfer | NSCOUNT | 92825eb42bSJan Lentfer +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 93825eb42bSJan Lentfer | ARCOUNT | 94825eb42bSJan Lentfer +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 95825eb42bSJan Lentfer 96825eb42bSJan Lentfer where: 97825eb42bSJan Lentfer 98825eb42bSJan Lentfer ID A 16 bit identifier assigned by the program that 99825eb42bSJan Lentfer generates any kind of query. This identifier is copied 100825eb42bSJan Lentfer the corresponding reply and can be used by the requester 101825eb42bSJan Lentfer to match up replies to outstanding queries. 102825eb42bSJan Lentfer 103825eb42bSJan Lentfer QR A one bit field that specifies whether this message is a 104825eb42bSJan Lentfer query (0), or a response (1). 105825eb42bSJan Lentfer 106825eb42bSJan Lentfer OPCODE A four bit field that specifies kind of query in this 107825eb42bSJan Lentfer message. This value is set by the originator of a query 108825eb42bSJan Lentfer and copied into the response. The values are: 109825eb42bSJan Lentfer 110825eb42bSJan Lentfer 0 a standard query (QUERY) 111825eb42bSJan Lentfer 112825eb42bSJan Lentfer 1 an inverse query (IQUERY) 113825eb42bSJan Lentfer 114825eb42bSJan Lentfer 2 a server status request (STATUS) 115825eb42bSJan Lentfer 116825eb42bSJan Lentfer 3-15 reserved for future use 117825eb42bSJan Lentfer 118825eb42bSJan Lentfer AA Authoritative Answer - this bit is valid in responses, 119825eb42bSJan Lentfer and specifies that the responding name server is an 120825eb42bSJan Lentfer authority for the domain name in question section. 121825eb42bSJan Lentfer 122825eb42bSJan Lentfer Note that the contents of the answer section may have 123825eb42bSJan Lentfer multiple owner names because of aliases. The AA bit 124825eb42bSJan Lentfer 125825eb42bSJan Lentfer corresponds to the name which matches the query name, or 126825eb42bSJan Lentfer the first owner name in the answer section. 127825eb42bSJan Lentfer 128825eb42bSJan Lentfer TC TrunCation - specifies that this message was truncated 129825eb42bSJan Lentfer due to length greater than that permitted on the 130825eb42bSJan Lentfer transmission channel. 131825eb42bSJan Lentfer 132825eb42bSJan Lentfer RD Recursion Desired - this bit may be set in a query and 133825eb42bSJan Lentfer is copied into the response. If RD is set, it directs 134825eb42bSJan Lentfer the name server to pursue the query recursively. 135825eb42bSJan Lentfer Recursive query support is optional. 136825eb42bSJan Lentfer 137825eb42bSJan Lentfer RA Recursion Available - this be is set or cleared in a 138825eb42bSJan Lentfer response, and denotes whether recursive query support is 139825eb42bSJan Lentfer available in the name server. 140825eb42bSJan Lentfer 141825eb42bSJan Lentfer Z Reserved for future use. Must be zero in all queries 142825eb42bSJan Lentfer and responses. 143825eb42bSJan Lentfer 144825eb42bSJan Lentfer RCODE Response code - this 4 bit field is set as part of 145825eb42bSJan Lentfer responses. The values have the following 146825eb42bSJan Lentfer interpretation: 147825eb42bSJan Lentfer 148825eb42bSJan Lentfer 0 No error condition 149825eb42bSJan Lentfer 150825eb42bSJan Lentfer 1 Format error - The name server was 151825eb42bSJan Lentfer unable to interpret the query. 152825eb42bSJan Lentfer 153825eb42bSJan Lentfer 2 Server failure - The name server was 154825eb42bSJan Lentfer unable to process this query due to a 155825eb42bSJan Lentfer problem with the name server. 156825eb42bSJan Lentfer 157825eb42bSJan Lentfer 3 Name Error - Meaningful only for 158825eb42bSJan Lentfer responses from an authoritative name 159825eb42bSJan Lentfer server, this code signifies that the 160825eb42bSJan Lentfer domain name referenced in the query does 161825eb42bSJan Lentfer not exist. 162825eb42bSJan Lentfer 163825eb42bSJan Lentfer 4 Not Implemented - The name server does 164825eb42bSJan Lentfer not support the requested kind of query. 165825eb42bSJan Lentfer 166825eb42bSJan Lentfer 5 Refused - The name server refuses to 167825eb42bSJan Lentfer perform the specified operation for 168825eb42bSJan Lentfer policy reasons. For example, a name 169825eb42bSJan Lentfer server may not wish to provide the 170825eb42bSJan Lentfer information to the particular requester, 171825eb42bSJan Lentfer or a name server may not wish to perform 172825eb42bSJan Lentfer a particular operation (e.g., zone 173825eb42bSJan Lentfer 174825eb42bSJan Lentfer transfer) for particular data. 175825eb42bSJan Lentfer 176825eb42bSJan Lentfer 6-15 Reserved for future use. 177825eb42bSJan Lentfer 178825eb42bSJan Lentfer QDCOUNT an unsigned 16 bit integer specifying the number of 179825eb42bSJan Lentfer entries in the question section. 180825eb42bSJan Lentfer 181825eb42bSJan Lentfer ANCOUNT an unsigned 16 bit integer specifying the number of 182825eb42bSJan Lentfer resource records in the answer section. 183825eb42bSJan Lentfer 184825eb42bSJan Lentfer NSCOUNT an unsigned 16 bit integer specifying the number of name 185825eb42bSJan Lentfer server resource records in the authority records 186825eb42bSJan Lentfer section. 187825eb42bSJan Lentfer 188825eb42bSJan Lentfer ARCOUNT an unsigned 16 bit integer specifying the number of 189825eb42bSJan Lentfer resource records in the additional records section. 190825eb42bSJan Lentfer 191825eb42bSJan Lentfer </pre> 192825eb42bSJan Lentfer */ 193825eb42bSJan Lentfer struct ldns_struct_hdr 194825eb42bSJan Lentfer { 195825eb42bSJan Lentfer /** Id of a packet */ 196825eb42bSJan Lentfer uint16_t _id; 197825eb42bSJan Lentfer /** Query bit (0=query, 1=answer) */ 198825eb42bSJan Lentfer bool _qr; 199825eb42bSJan Lentfer /** Authoritative answer */ 200825eb42bSJan Lentfer bool _aa; 201825eb42bSJan Lentfer /** Packet truncated */ 202825eb42bSJan Lentfer bool _tc; 203825eb42bSJan Lentfer /** Recursion desired */ 204825eb42bSJan Lentfer bool _rd; 205825eb42bSJan Lentfer /** Checking disabled */ 206825eb42bSJan Lentfer bool _cd; 207825eb42bSJan Lentfer /** Recursion available */ 208825eb42bSJan Lentfer bool _ra; 209825eb42bSJan Lentfer /** Authentic data */ 210825eb42bSJan Lentfer bool _ad; 211825eb42bSJan Lentfer /** Query type */ 212825eb42bSJan Lentfer ldns_pkt_opcode _opcode; /* XXX 8 bits? */ 213825eb42bSJan Lentfer /** Response code */ 214825eb42bSJan Lentfer uint8_t _rcode; 215825eb42bSJan Lentfer /** question sec */ 216825eb42bSJan Lentfer uint16_t _qdcount; 217825eb42bSJan Lentfer /** answer sec */ 218825eb42bSJan Lentfer uint16_t _ancount; 219825eb42bSJan Lentfer /** auth sec */ 220825eb42bSJan Lentfer uint16_t _nscount; 221825eb42bSJan Lentfer /** add sec */ 222825eb42bSJan Lentfer uint16_t _arcount; 223825eb42bSJan Lentfer }; 224825eb42bSJan Lentfer typedef struct ldns_struct_hdr ldns_hdr; 225825eb42bSJan Lentfer 226825eb42bSJan Lentfer /** 227825eb42bSJan Lentfer * DNS packet 228825eb42bSJan Lentfer * 229825eb42bSJan Lentfer * This structure contains a complete DNS packet (either a query or an answer) 230825eb42bSJan Lentfer * 231825eb42bSJan Lentfer * It is the complete representation of what you actually send to a 232825eb42bSJan Lentfer * nameserver, and what it sends back (assuming you are the client here). 233825eb42bSJan Lentfer */ 234825eb42bSJan Lentfer struct ldns_struct_pkt 235825eb42bSJan Lentfer { 236825eb42bSJan Lentfer /** Header section */ 237825eb42bSJan Lentfer ldns_hdr *_header; 238825eb42bSJan Lentfer /* extra items needed in a packet */ 2395340022aSzrj /** an rdf (A or AAAA) with the IP address of the server it is from */ 240825eb42bSJan Lentfer ldns_rdf *_answerfrom; 241825eb42bSJan Lentfer /** Timestamp of the time the packet was sent or created */ 242825eb42bSJan Lentfer struct timeval timestamp; 243825eb42bSJan Lentfer /** The duration of the query this packet is an answer to */ 244825eb42bSJan Lentfer uint32_t _querytime; 245825eb42bSJan Lentfer /** The size of the wire format of the packet in octets */ 246825eb42bSJan Lentfer size_t _size; 247825eb42bSJan Lentfer /** Optional tsig rr */ 248825eb42bSJan Lentfer ldns_rr *_tsig_rr; 249825eb42bSJan Lentfer /** EDNS0 available buffer size, see RFC2671 */ 250825eb42bSJan Lentfer uint16_t _edns_udp_size; 251825eb42bSJan Lentfer /** EDNS0 Extended rcode */ 252825eb42bSJan Lentfer uint8_t _edns_extended_rcode; 253825eb42bSJan Lentfer /** EDNS Version */ 254825eb42bSJan Lentfer uint8_t _edns_version; 2555340022aSzrj /* OPT pseudo-RR presence flag */ 2565340022aSzrj uint8_t _edns_present; 257825eb42bSJan Lentfer /** Reserved EDNS data bits */ 258825eb42bSJan Lentfer uint16_t _edns_z; 259825eb42bSJan Lentfer /** Arbitrary EDNS rdata */ 260825eb42bSJan Lentfer ldns_rdf *_edns_data; 261*ee791febSAntonio Huete Jimenez /** Structed EDNS data */ 262*ee791febSAntonio Huete Jimenez ldns_edns_option_list *_edns_list; 263825eb42bSJan Lentfer /** Question section */ 264825eb42bSJan Lentfer ldns_rr_list *_question; 265825eb42bSJan Lentfer /** Answer section */ 266825eb42bSJan Lentfer ldns_rr_list *_answer; 267825eb42bSJan Lentfer /** Authority section */ 268825eb42bSJan Lentfer ldns_rr_list *_authority; 269825eb42bSJan Lentfer /** Additional section */ 270825eb42bSJan Lentfer ldns_rr_list *_additional; 271825eb42bSJan Lentfer }; 272825eb42bSJan Lentfer typedef struct ldns_struct_pkt ldns_pkt; 273825eb42bSJan Lentfer 274825eb42bSJan Lentfer /** 275825eb42bSJan Lentfer * The sections of a packet 276825eb42bSJan Lentfer */ 277825eb42bSJan Lentfer enum ldns_enum_pkt_section { 278825eb42bSJan Lentfer LDNS_SECTION_QUESTION = 0, 279825eb42bSJan Lentfer LDNS_SECTION_ANSWER = 1, 280825eb42bSJan Lentfer LDNS_SECTION_AUTHORITY = 2, 281825eb42bSJan Lentfer LDNS_SECTION_ADDITIONAL = 3, 282825eb42bSJan Lentfer /** bogus section, if not interested */ 283825eb42bSJan Lentfer LDNS_SECTION_ANY = 4, 284825eb42bSJan Lentfer /** used to get all non-question rrs from a packet */ 285825eb42bSJan Lentfer LDNS_SECTION_ANY_NOQUESTION = 5 286825eb42bSJan Lentfer }; 287825eb42bSJan Lentfer typedef enum ldns_enum_pkt_section ldns_pkt_section; 288825eb42bSJan Lentfer 289825eb42bSJan Lentfer /** 290825eb42bSJan Lentfer * The different types of packets 291825eb42bSJan Lentfer */ 292825eb42bSJan Lentfer enum ldns_enum_pkt_type { 293825eb42bSJan Lentfer LDNS_PACKET_QUESTION, 294825eb42bSJan Lentfer LDNS_PACKET_REFERRAL, 295825eb42bSJan Lentfer LDNS_PACKET_ANSWER, 296825eb42bSJan Lentfer LDNS_PACKET_NXDOMAIN, 297825eb42bSJan Lentfer LDNS_PACKET_NODATA, 298825eb42bSJan Lentfer LDNS_PACKET_UNKNOWN 299825eb42bSJan Lentfer }; 300825eb42bSJan Lentfer typedef enum ldns_enum_pkt_type ldns_pkt_type; 301825eb42bSJan Lentfer 302825eb42bSJan Lentfer /* prototypes */ 303825eb42bSJan Lentfer 304825eb42bSJan Lentfer /* read */ 305825eb42bSJan Lentfer 306825eb42bSJan Lentfer /** 307825eb42bSJan Lentfer * Read the packet id 308825eb42bSJan Lentfer * \param[in] p the packet 309825eb42bSJan Lentfer * \return the packet id 310825eb42bSJan Lentfer */ 311825eb42bSJan Lentfer uint16_t ldns_pkt_id(const ldns_pkt *p); 312825eb42bSJan Lentfer /** 313825eb42bSJan Lentfer * Read the packet's qr bit 314825eb42bSJan Lentfer * \param[in] p the packet 315825eb42bSJan Lentfer * \return value of the bit 316825eb42bSJan Lentfer */ 317825eb42bSJan Lentfer bool ldns_pkt_qr(const ldns_pkt *p); 318825eb42bSJan Lentfer /** 319825eb42bSJan Lentfer * Read the packet's aa bit 320825eb42bSJan Lentfer * \param[in] p the packet 321825eb42bSJan Lentfer * \return value of the bit 322825eb42bSJan Lentfer */ 323825eb42bSJan Lentfer bool ldns_pkt_aa(const ldns_pkt *p); 324825eb42bSJan Lentfer /** 325825eb42bSJan Lentfer * Read the packet's tc bit 326825eb42bSJan Lentfer * \param[in] p the packet 327825eb42bSJan Lentfer * \return value of the bit 328825eb42bSJan Lentfer */ 329825eb42bSJan Lentfer bool ldns_pkt_tc(const ldns_pkt *p); 330825eb42bSJan Lentfer /** 331825eb42bSJan Lentfer * Read the packet's rd bit 332825eb42bSJan Lentfer * \param[in] p the packet 333825eb42bSJan Lentfer * \return value of the bit 334825eb42bSJan Lentfer */ 335825eb42bSJan Lentfer bool ldns_pkt_rd(const ldns_pkt *p); 336825eb42bSJan Lentfer /** 337825eb42bSJan Lentfer * Read the packet's cd bit 338825eb42bSJan Lentfer * \param[in] p the packet 339825eb42bSJan Lentfer * \return value of the bit 340825eb42bSJan Lentfer */ 341825eb42bSJan Lentfer bool ldns_pkt_cd(const ldns_pkt *p); 342825eb42bSJan Lentfer /** 343825eb42bSJan Lentfer * Read the packet's ra bit 344825eb42bSJan Lentfer * \param[in] p the packet 345825eb42bSJan Lentfer * \return value of the bit 346825eb42bSJan Lentfer */ 347825eb42bSJan Lentfer bool ldns_pkt_ra(const ldns_pkt *p); 348825eb42bSJan Lentfer /** 349825eb42bSJan Lentfer * Read the packet's ad bit 350825eb42bSJan Lentfer * \param[in] p the packet 351825eb42bSJan Lentfer * \return value of the bit 352825eb42bSJan Lentfer */ 353825eb42bSJan Lentfer bool ldns_pkt_ad(const ldns_pkt *p); 354825eb42bSJan Lentfer /** 355825eb42bSJan Lentfer * Read the packet's code 356825eb42bSJan Lentfer * \param[in] p the packet 357825eb42bSJan Lentfer * \return the opcode 358825eb42bSJan Lentfer */ 359825eb42bSJan Lentfer ldns_pkt_opcode ldns_pkt_get_opcode(const ldns_pkt *p); 360825eb42bSJan Lentfer /** 361*ee791febSAntonio Huete Jimenez * Return the packet's response code 362825eb42bSJan Lentfer * \param[in] p the packet 363*ee791febSAntonio Huete Jimenez * \return the response code 364825eb42bSJan Lentfer */ 365825eb42bSJan Lentfer ldns_pkt_rcode ldns_pkt_get_rcode(const ldns_pkt *p); 366825eb42bSJan Lentfer /** 367825eb42bSJan Lentfer * Return the packet's qd count 368825eb42bSJan Lentfer * \param[in] p the packet 369825eb42bSJan Lentfer * \return the qd count 370825eb42bSJan Lentfer */ 371825eb42bSJan Lentfer uint16_t ldns_pkt_qdcount(const ldns_pkt *p); 372825eb42bSJan Lentfer /** 373825eb42bSJan Lentfer * Return the packet's an count 374825eb42bSJan Lentfer * \param[in] p the packet 375825eb42bSJan Lentfer * \return the an count 376825eb42bSJan Lentfer */ 377825eb42bSJan Lentfer uint16_t ldns_pkt_ancount(const ldns_pkt *p); 378825eb42bSJan Lentfer /** 379825eb42bSJan Lentfer * Return the packet's ns count 380825eb42bSJan Lentfer * \param[in] p the packet 381825eb42bSJan Lentfer * \return the ns count 382825eb42bSJan Lentfer */ 383825eb42bSJan Lentfer uint16_t ldns_pkt_nscount(const ldns_pkt *p); 384825eb42bSJan Lentfer /** 385825eb42bSJan Lentfer * Return the packet's ar count 386825eb42bSJan Lentfer * \param[in] p the packet 387825eb42bSJan Lentfer * \return the ar count 388825eb42bSJan Lentfer */ 389825eb42bSJan Lentfer uint16_t ldns_pkt_arcount(const ldns_pkt *p); 390825eb42bSJan Lentfer 391825eb42bSJan Lentfer /** 392825eb42bSJan Lentfer * Return the packet's answerfrom 393825eb42bSJan Lentfer * \param[in] p packet 394825eb42bSJan Lentfer * \return the name of the server 395825eb42bSJan Lentfer */ 396825eb42bSJan Lentfer ldns_rdf *ldns_pkt_answerfrom(const ldns_pkt *p); 397825eb42bSJan Lentfer 398825eb42bSJan Lentfer /** 399825eb42bSJan Lentfer * Return the packet's timestamp 400825eb42bSJan Lentfer * \param[in] p the packet 401825eb42bSJan Lentfer * \return the timestamp 402825eb42bSJan Lentfer */ 403825eb42bSJan Lentfer struct timeval ldns_pkt_timestamp(const ldns_pkt *p); 404825eb42bSJan Lentfer /** 405825eb42bSJan Lentfer * Return the packet's querytime 406825eb42bSJan Lentfer * \param[in] p the packet 407825eb42bSJan Lentfer * \return the querytime 408825eb42bSJan Lentfer */ 409825eb42bSJan Lentfer uint32_t ldns_pkt_querytime(const ldns_pkt *p); 410825eb42bSJan Lentfer 411825eb42bSJan Lentfer /** 412825eb42bSJan Lentfer * Return the packet's size in bytes 413825eb42bSJan Lentfer * \param[in] p the packet 414825eb42bSJan Lentfer * \return the size 415825eb42bSJan Lentfer */ 416825eb42bSJan Lentfer size_t ldns_pkt_size(const ldns_pkt *p); 417825eb42bSJan Lentfer 418825eb42bSJan Lentfer /** 4195340022aSzrj * Return the number of RRs in the given section. 4205340022aSzrj * Returns the sum of all RRs when LDNS_SECTION_ANY is given. 4215340022aSzrj * Returns the sum of all non-question RRs when LDNS_SECTION_ANY_NOQUESTION 4225340022aSzrj * is given. 4235340022aSzrj * \param[in] p the packet 4245340022aSzrj * \param[in] s the section 4255340022aSzrj * \return the number of RRs in the given section 4265340022aSzrj */ 4275340022aSzrj uint16_t ldns_pkt_section_count(const ldns_pkt *p, ldns_pkt_section s); 4285340022aSzrj 4295340022aSzrj /** 430825eb42bSJan Lentfer * Return the packet's tsig pseudo rr's 431825eb42bSJan Lentfer * \param[in] p the packet 432825eb42bSJan Lentfer * \return the tsig rr 433825eb42bSJan Lentfer */ 434825eb42bSJan Lentfer ldns_rr *ldns_pkt_tsig(const ldns_pkt *p); 435825eb42bSJan Lentfer 436825eb42bSJan Lentfer /** 437825eb42bSJan Lentfer * Return the packet's question section 438825eb42bSJan Lentfer * \param[in] p the packet 439825eb42bSJan Lentfer * \return the section 440825eb42bSJan Lentfer */ 441825eb42bSJan Lentfer ldns_rr_list *ldns_pkt_question(const ldns_pkt *p); 442825eb42bSJan Lentfer /** 443825eb42bSJan Lentfer * Return the packet's answer section 444825eb42bSJan Lentfer * \param[in] p the packet 445825eb42bSJan Lentfer * \return the section 446825eb42bSJan Lentfer */ 447825eb42bSJan Lentfer ldns_rr_list *ldns_pkt_answer(const ldns_pkt *p); 448825eb42bSJan Lentfer /** 449825eb42bSJan Lentfer * Return the packet's authority section 450825eb42bSJan Lentfer * \param[in] p the packet 451825eb42bSJan Lentfer * \return the section 452825eb42bSJan Lentfer */ 453825eb42bSJan Lentfer ldns_rr_list *ldns_pkt_authority(const ldns_pkt *p); 454825eb42bSJan Lentfer /** 455825eb42bSJan Lentfer * Return the packet's additional section 456825eb42bSJan Lentfer * \param[in] p the packet 457825eb42bSJan Lentfer * \return the section 458825eb42bSJan Lentfer */ 459825eb42bSJan Lentfer ldns_rr_list *ldns_pkt_additional(const ldns_pkt *p); 460825eb42bSJan Lentfer /** 461825eb42bSJan Lentfer * Return the packet's question, answer, authority and additional sections 462825eb42bSJan Lentfer * concatenated, in a new rr_list clone. 463825eb42bSJan Lentfer * \param[in] p the packet 464825eb42bSJan Lentfer * \return the rrs 465825eb42bSJan Lentfer */ 466825eb42bSJan Lentfer ldns_rr_list *ldns_pkt_all(const ldns_pkt *p); 467825eb42bSJan Lentfer /** 468825eb42bSJan Lentfer * Return the packet's answer, authority and additional sections concatenated, 469825eb42bSJan Lentfer * in a new rr_list clone. Like ldns_pkt_all but without the questions. 470825eb42bSJan Lentfer * \param[in] p the packet 471825eb42bSJan Lentfer * \return the rrs except the question rrs 472825eb42bSJan Lentfer */ 473825eb42bSJan Lentfer ldns_rr_list *ldns_pkt_all_noquestion(const ldns_pkt *p); 474825eb42bSJan Lentfer 475825eb42bSJan Lentfer /** 476825eb42bSJan Lentfer * return all the rr_list's in the packet. Clone the lists, instead 477825eb42bSJan Lentfer * of returning pointers. 478825eb42bSJan Lentfer * \param[in] p the packet to look in 479825eb42bSJan Lentfer * \param[in] s what section(s) to return 480825eb42bSJan Lentfer * \return ldns_rr_list with the rr's or NULL if none were found 481825eb42bSJan Lentfer */ 482825eb42bSJan Lentfer ldns_rr_list *ldns_pkt_get_section_clone(const ldns_pkt *p, ldns_pkt_section s); 483825eb42bSJan Lentfer 484825eb42bSJan Lentfer /** 485825eb42bSJan Lentfer * return all the rr with a specific name from a packet. Optionally 486825eb42bSJan Lentfer * specify from which section in the packet 487825eb42bSJan Lentfer * \param[in] p the packet 488825eb42bSJan Lentfer * \param[in] r the name 489825eb42bSJan Lentfer * \param[in] s the packet's section 490825eb42bSJan Lentfer * \return a list with the rr's or NULL if none were found 491825eb42bSJan Lentfer */ 4925340022aSzrj ldns_rr_list *ldns_pkt_rr_list_by_name(const ldns_pkt *p, const ldns_rdf *r, ldns_pkt_section s); 493825eb42bSJan Lentfer /** 494825eb42bSJan Lentfer * return all the rr with a specific type from a packet. Optionally 495825eb42bSJan Lentfer * specify from which section in the packet 496825eb42bSJan Lentfer * \param[in] p the packet 497825eb42bSJan Lentfer * \param[in] t the type 498825eb42bSJan Lentfer * \param[in] s the packet's section 499825eb42bSJan Lentfer * \return a list with the rr's or NULL if none were found 500825eb42bSJan Lentfer */ 501825eb42bSJan Lentfer ldns_rr_list *ldns_pkt_rr_list_by_type(const ldns_pkt *p, ldns_rr_type t, ldns_pkt_section s); 502825eb42bSJan Lentfer /** 503825eb42bSJan Lentfer * return all the rr with a specific type and type from a packet. Optionally 504825eb42bSJan Lentfer * specify from which section in the packet 505825eb42bSJan Lentfer * \param[in] packet the packet 506825eb42bSJan Lentfer * \param[in] ownername the name 507825eb42bSJan Lentfer * \param[in] type the type 508825eb42bSJan Lentfer * \param[in] sec the packet's section 509825eb42bSJan Lentfer * \return a list with the rr's or NULL if none were found 510825eb42bSJan Lentfer */ 511825eb42bSJan Lentfer ldns_rr_list *ldns_pkt_rr_list_by_name_and_type(const ldns_pkt *packet, const ldns_rdf *ownername, ldns_rr_type type, ldns_pkt_section sec); 512825eb42bSJan Lentfer 513825eb42bSJan Lentfer 514825eb42bSJan Lentfer /** 515825eb42bSJan Lentfer * check to see if an rr exist in the packet 516825eb42bSJan Lentfer * \param[in] pkt the packet to examine 517825eb42bSJan Lentfer * \param[in] sec in which section to look 518825eb42bSJan Lentfer * \param[in] rr the rr to look for 519825eb42bSJan Lentfer */ 5205340022aSzrj bool ldns_pkt_rr(const ldns_pkt *pkt, ldns_pkt_section sec, const ldns_rr *rr); 521825eb42bSJan Lentfer 522825eb42bSJan Lentfer 523825eb42bSJan Lentfer /** 524825eb42bSJan Lentfer * sets the flags in a packet. 525825eb42bSJan Lentfer * \param[in] pkt the packet to operate on 526825eb42bSJan Lentfer * \param[in] flags ORed values: LDNS_QR| LDNS_AR for instance 527825eb42bSJan Lentfer * \return true on success otherwise false 528825eb42bSJan Lentfer */ 529825eb42bSJan Lentfer bool ldns_pkt_set_flags(ldns_pkt *pkt, uint16_t flags); 530825eb42bSJan Lentfer 531825eb42bSJan Lentfer /** 532825eb42bSJan Lentfer * Set the packet's id 533825eb42bSJan Lentfer * \param[in] p the packet 534825eb42bSJan Lentfer * \param[in] id the id to set 535825eb42bSJan Lentfer */ 536825eb42bSJan Lentfer void ldns_pkt_set_id(ldns_pkt *p, uint16_t id); 537825eb42bSJan Lentfer /** 538825eb42bSJan Lentfer * Set the packet's id to a random value 539825eb42bSJan Lentfer * \param[in] p the packet 540825eb42bSJan Lentfer */ 541825eb42bSJan Lentfer void ldns_pkt_set_random_id(ldns_pkt *p); 542825eb42bSJan Lentfer /** 543825eb42bSJan Lentfer * Set the packet's qr bit 544825eb42bSJan Lentfer * \param[in] p the packet 545825eb42bSJan Lentfer * \param[in] b the value to set (boolean) 546825eb42bSJan Lentfer */ 547825eb42bSJan Lentfer void ldns_pkt_set_qr(ldns_pkt *p, bool b); 548825eb42bSJan Lentfer /** 549825eb42bSJan Lentfer * Set the packet's aa bit 550825eb42bSJan Lentfer * \param[in] p the packet 551825eb42bSJan Lentfer * \param[in] b the value to set (boolean) 552825eb42bSJan Lentfer */ 553825eb42bSJan Lentfer void ldns_pkt_set_aa(ldns_pkt *p, bool b); 554825eb42bSJan Lentfer /** 555825eb42bSJan Lentfer * Set the packet's tc bit 556825eb42bSJan Lentfer * \param[in] p the packet 557825eb42bSJan Lentfer * \param[in] b the value to set (boolean) 558825eb42bSJan Lentfer */ 559825eb42bSJan Lentfer void ldns_pkt_set_tc(ldns_pkt *p, bool b); 560825eb42bSJan Lentfer /** 561825eb42bSJan Lentfer * Set the packet's rd bit 562825eb42bSJan Lentfer * \param[in] p the packet 563825eb42bSJan Lentfer * \param[in] b the value to set (boolean) 564825eb42bSJan Lentfer */ 565825eb42bSJan Lentfer void ldns_pkt_set_rd(ldns_pkt *p, bool b); 566825eb42bSJan Lentfer /** 567825eb42bSJan Lentfer * Set the packet's cd bit 568825eb42bSJan Lentfer * \param[in] p the packet 569825eb42bSJan Lentfer * \param[in] b the value to set (boolean) 570825eb42bSJan Lentfer */ 571825eb42bSJan Lentfer void ldns_pkt_set_cd(ldns_pkt *p, bool b); 572825eb42bSJan Lentfer /** 573825eb42bSJan Lentfer * Set the packet's ra bit 574825eb42bSJan Lentfer * \param[in] p the packet 575825eb42bSJan Lentfer * \param[in] b the value to set (boolean) 576825eb42bSJan Lentfer */ 577825eb42bSJan Lentfer void ldns_pkt_set_ra(ldns_pkt *p, bool b); 578825eb42bSJan Lentfer /** 579825eb42bSJan Lentfer * Set the packet's ad bit 580825eb42bSJan Lentfer * \param[in] p the packet 581825eb42bSJan Lentfer * \param[in] b the value to set (boolean) 582825eb42bSJan Lentfer */ 583825eb42bSJan Lentfer void ldns_pkt_set_ad(ldns_pkt *p, bool b); 584825eb42bSJan Lentfer 585825eb42bSJan Lentfer /** 586825eb42bSJan Lentfer * Set the packet's opcode 587825eb42bSJan Lentfer * \param[in] p the packet 588825eb42bSJan Lentfer * \param[in] c the opcode 589825eb42bSJan Lentfer */ 590825eb42bSJan Lentfer void ldns_pkt_set_opcode(ldns_pkt *p, ldns_pkt_opcode c); 591825eb42bSJan Lentfer /** 592*ee791febSAntonio Huete Jimenez * Set the packet's response code 593825eb42bSJan Lentfer * \param[in] p the packet 594825eb42bSJan Lentfer * \param[in] c the rcode 595825eb42bSJan Lentfer */ 596825eb42bSJan Lentfer void ldns_pkt_set_rcode(ldns_pkt *p, uint8_t c); 597825eb42bSJan Lentfer /** 598825eb42bSJan Lentfer * Set the packet's qd count 599825eb42bSJan Lentfer * \param[in] p the packet 600825eb42bSJan Lentfer * \param[in] c the count 601825eb42bSJan Lentfer */ 602825eb42bSJan Lentfer void ldns_pkt_set_qdcount(ldns_pkt *p, uint16_t c); 603825eb42bSJan Lentfer /** 604825eb42bSJan Lentfer * Set the packet's an count 605825eb42bSJan Lentfer * \param[in] p the packet 606825eb42bSJan Lentfer * \param[in] c the count 607825eb42bSJan Lentfer */ 608825eb42bSJan Lentfer void ldns_pkt_set_ancount(ldns_pkt *p, uint16_t c); 609825eb42bSJan Lentfer /** 610825eb42bSJan Lentfer * Set the packet's ns count 611825eb42bSJan Lentfer * \param[in] p the packet 612825eb42bSJan Lentfer * \param[in] c the count 613825eb42bSJan Lentfer */ 614825eb42bSJan Lentfer void ldns_pkt_set_nscount(ldns_pkt *p, uint16_t c); 615825eb42bSJan Lentfer /** 616825eb42bSJan Lentfer * Set the packet's arcount 617825eb42bSJan Lentfer * \param[in] p the packet 618825eb42bSJan Lentfer * \param[in] c the count 619825eb42bSJan Lentfer */ 620825eb42bSJan Lentfer void ldns_pkt_set_arcount(ldns_pkt *p, uint16_t c); 621825eb42bSJan Lentfer /** 622825eb42bSJan Lentfer * Set the packet's answering server 623825eb42bSJan Lentfer * \param[in] p the packet 624825eb42bSJan Lentfer * \param[in] r the address 625825eb42bSJan Lentfer */ 626825eb42bSJan Lentfer void ldns_pkt_set_answerfrom(ldns_pkt *p, ldns_rdf *r); 627825eb42bSJan Lentfer /** 628825eb42bSJan Lentfer * Set the packet's query time 629825eb42bSJan Lentfer * \param[in] p the packet 630825eb42bSJan Lentfer * \param[in] t the querytime in msec 631825eb42bSJan Lentfer */ 632825eb42bSJan Lentfer void ldns_pkt_set_querytime(ldns_pkt *p, uint32_t t); 633825eb42bSJan Lentfer /** 634825eb42bSJan Lentfer * Set the packet's size 635825eb42bSJan Lentfer * \param[in] p the packet 636825eb42bSJan Lentfer * \param[in] s the size 637825eb42bSJan Lentfer */ 638825eb42bSJan Lentfer void ldns_pkt_set_size(ldns_pkt *p, size_t s); 639825eb42bSJan Lentfer 640825eb42bSJan Lentfer /** 641825eb42bSJan Lentfer * Set the packet's timestamp 642825eb42bSJan Lentfer * \param[in] p the packet 643825eb42bSJan Lentfer * \param[in] timeval the timestamp 644825eb42bSJan Lentfer */ 645fd185f4dSJan Lentfer void ldns_pkt_set_timestamp(ldns_pkt *p, struct timeval timeval); 646825eb42bSJan Lentfer /** 647825eb42bSJan Lentfer * Set a packet's section count to x 648825eb42bSJan Lentfer * \param[in] p the packet 649825eb42bSJan Lentfer * \param[in] s the section 650825eb42bSJan Lentfer * \param[in] x the section count 651825eb42bSJan Lentfer */ 652825eb42bSJan Lentfer void ldns_pkt_set_section_count(ldns_pkt *p, ldns_pkt_section s, uint16_t x); 653825eb42bSJan Lentfer /** 654825eb42bSJan Lentfer * Set the packet's tsig rr 655825eb42bSJan Lentfer * \param[in] p the packet 656825eb42bSJan Lentfer * \param[in] t the tsig rr 657825eb42bSJan Lentfer */ 658825eb42bSJan Lentfer void ldns_pkt_set_tsig(ldns_pkt *p, ldns_rr *t); 659825eb42bSJan Lentfer 660825eb42bSJan Lentfer /** 661825eb42bSJan Lentfer * looks inside the packet to determine 662825eb42bSJan Lentfer * what kind of packet it is, AUTH, NXDOMAIN, REFERRAL, etc. 663825eb42bSJan Lentfer * \param[in] p the packet to examine 664825eb42bSJan Lentfer * \return the type of packet 665825eb42bSJan Lentfer */ 6665340022aSzrj ldns_pkt_type ldns_pkt_reply_type(const ldns_pkt *p); 667825eb42bSJan Lentfer 668825eb42bSJan Lentfer /** 669825eb42bSJan Lentfer * return the packet's edns udp size 670825eb42bSJan Lentfer * \param[in] packet the packet 671825eb42bSJan Lentfer * \return the size 672825eb42bSJan Lentfer */ 673825eb42bSJan Lentfer uint16_t ldns_pkt_edns_udp_size(const ldns_pkt *packet); 674825eb42bSJan Lentfer /** 675825eb42bSJan Lentfer * return the packet's edns extended rcode 676825eb42bSJan Lentfer * \param[in] packet the packet 677825eb42bSJan Lentfer * \return the rcode 678825eb42bSJan Lentfer */ 679825eb42bSJan Lentfer uint8_t ldns_pkt_edns_extended_rcode(const ldns_pkt *packet); 680825eb42bSJan Lentfer /** 681825eb42bSJan Lentfer * return the packet's edns version 682825eb42bSJan Lentfer * \param[in] packet the packet 683825eb42bSJan Lentfer * \return the version 684825eb42bSJan Lentfer */ 685825eb42bSJan Lentfer uint8_t ldns_pkt_edns_version(const ldns_pkt *packet); 686825eb42bSJan Lentfer /** 687825eb42bSJan Lentfer * return the packet's edns z value 688825eb42bSJan Lentfer * \param[in] packet the packet 689825eb42bSJan Lentfer * \return the z value 690825eb42bSJan Lentfer */ 691825eb42bSJan Lentfer uint16_t ldns_pkt_edns_z(const ldns_pkt *packet); 692825eb42bSJan Lentfer /** 693*ee791febSAntonio Huete Jimenez * return the packet's EDNS data 694825eb42bSJan Lentfer * \param[in] packet the packet 695825eb42bSJan Lentfer * \return the data 696825eb42bSJan Lentfer */ 697825eb42bSJan Lentfer ldns_rdf *ldns_pkt_edns_data(const ldns_pkt *packet); 698825eb42bSJan Lentfer 699825eb42bSJan Lentfer /** 700825eb42bSJan Lentfer * return the packet's edns do bit 701825eb42bSJan Lentfer * \param[in] packet the packet 702825eb42bSJan Lentfer * \return the bit's value 703825eb42bSJan Lentfer */ 704825eb42bSJan Lentfer bool ldns_pkt_edns_do(const ldns_pkt *packet); 705825eb42bSJan Lentfer /** 706825eb42bSJan Lentfer * Set the packet's edns do bit 707825eb42bSJan Lentfer * \param[in] packet the packet 708825eb42bSJan Lentfer * \param[in] value the bit's new value 709825eb42bSJan Lentfer */ 710825eb42bSJan Lentfer void ldns_pkt_set_edns_do(ldns_pkt *packet, bool value); 711825eb42bSJan Lentfer 712825eb42bSJan Lentfer /** 713819dec71SDaniel Fojt * return the packet's EDNS header bits that are unassigned. 714819dec71SDaniel Fojt */ 715819dec71SDaniel Fojt uint16_t ldns_pkt_edns_unassigned(const ldns_pkt *packet); 716819dec71SDaniel Fojt 717819dec71SDaniel Fojt /** 718819dec71SDaniel Fojt * Set the packet's EDNS header bits that are unassigned. 719819dec71SDaniel Fojt * \param[in] packet the packet 720819dec71SDaniel Fojt * \param[in] value the value 721819dec71SDaniel Fojt */ 722819dec71SDaniel Fojt void ldns_pkt_set_edns_unassigned(ldns_pkt *packet, uint16_t value); 723819dec71SDaniel Fojt 724819dec71SDaniel Fojt /** 725825eb42bSJan Lentfer * returns true if this packet needs and EDNS rr to be sent. 726825eb42bSJan Lentfer * At the moment the only reason is an expected packet 727825eb42bSJan Lentfer * size larger than 512 bytes, but for instance dnssec would 728825eb42bSJan Lentfer * be a good reason too. 729825eb42bSJan Lentfer * 730825eb42bSJan Lentfer * \param[in] packet the packet to check 731825eb42bSJan Lentfer * \return true if packet needs edns rr 732825eb42bSJan Lentfer */ 733825eb42bSJan Lentfer bool ldns_pkt_edns(const ldns_pkt *packet); 734825eb42bSJan Lentfer 735825eb42bSJan Lentfer /** 736*ee791febSAntonio Huete Jimenez * Returns a list of structured EDNS options. The list will be automatically 737*ee791febSAntonio Huete Jimenez * freed when the packet is freed. The option list can be manipulated and 738*ee791febSAntonio Huete Jimenez * will be used when converting the packet to wireformat with ldns_pkt2wire. 739*ee791febSAntonio Huete Jimenez * 740*ee791febSAntonio Huete Jimenez * \param[in] packet the packet which contains the EDNS data 741*ee791febSAntonio Huete Jimenez * \return the list of EDNS options 742*ee791febSAntonio Huete Jimenez */ 743*ee791febSAntonio Huete Jimenez ldns_edns_option_list* ldns_pkt_edns_get_option_list(ldns_pkt *packet); 744*ee791febSAntonio Huete Jimenez 745*ee791febSAntonio Huete Jimenez /** 746825eb42bSJan Lentfer * Set the packet's edns udp size 747825eb42bSJan Lentfer * \param[in] packet the packet 748825eb42bSJan Lentfer * \param[in] s the size 749825eb42bSJan Lentfer */ 750825eb42bSJan Lentfer void ldns_pkt_set_edns_udp_size(ldns_pkt *packet, uint16_t s); 751825eb42bSJan Lentfer /** 752825eb42bSJan Lentfer * Set the packet's edns extended rcode 753825eb42bSJan Lentfer * \param[in] packet the packet 754825eb42bSJan Lentfer * \param[in] c the code 755825eb42bSJan Lentfer */ 756825eb42bSJan Lentfer void ldns_pkt_set_edns_extended_rcode(ldns_pkt *packet, uint8_t c); 757825eb42bSJan Lentfer /** 758825eb42bSJan Lentfer * Set the packet's edns version 759825eb42bSJan Lentfer * \param[in] packet the packet 760825eb42bSJan Lentfer * \param[in] v the version 761825eb42bSJan Lentfer */ 762825eb42bSJan Lentfer void ldns_pkt_set_edns_version(ldns_pkt *packet, uint8_t v); 763825eb42bSJan Lentfer /** 764825eb42bSJan Lentfer * Set the packet's edns z value 765825eb42bSJan Lentfer * \param[in] packet the packet 766825eb42bSJan Lentfer * \param[in] z the value 767825eb42bSJan Lentfer */ 768825eb42bSJan Lentfer void ldns_pkt_set_edns_z(ldns_pkt *packet, uint16_t z); 769825eb42bSJan Lentfer /** 770*ee791febSAntonio Huete Jimenez * Set the packet's EDNS data 771825eb42bSJan Lentfer * \param[in] packet the packet 772825eb42bSJan Lentfer * \param[in] data the data 773825eb42bSJan Lentfer */ 774825eb42bSJan Lentfer void ldns_pkt_set_edns_data(ldns_pkt *packet, ldns_rdf *data); 775825eb42bSJan Lentfer 776825eb42bSJan Lentfer /** 777*ee791febSAntonio Huete Jimenez * Set the packet's structured EDNS data. Once an edns_option_list is set 778*ee791febSAntonio Huete Jimenez * (or get), the option list will be used for converting into wireformat. 779*ee791febSAntonio Huete Jimenez * \param[in] packet the packet 780*ee791febSAntonio Huete Jimenez * \param[in] list the options list that will create the data 781*ee791febSAntonio Huete Jimenez */ 782*ee791febSAntonio Huete Jimenez void ldns_pkt_set_edns_option_list(ldns_pkt *packet, ldns_edns_option_list *list); 783*ee791febSAntonio Huete Jimenez 784*ee791febSAntonio Huete Jimenez /** 785825eb42bSJan Lentfer * allocates and initializes a ldns_pkt structure. 786825eb42bSJan Lentfer * \return pointer to the new packet 787825eb42bSJan Lentfer */ 7885340022aSzrj ldns_pkt *ldns_pkt_new(void); 789825eb42bSJan Lentfer 790825eb42bSJan Lentfer /** 791825eb42bSJan Lentfer * frees the packet structure and all data that it contains. 792825eb42bSJan Lentfer * \param[in] packet The packet structure to free 793825eb42bSJan Lentfer * \return void 794825eb42bSJan Lentfer */ 795825eb42bSJan Lentfer void ldns_pkt_free(ldns_pkt *packet); 796825eb42bSJan Lentfer 797825eb42bSJan Lentfer /** 798825eb42bSJan Lentfer * creates a query packet for the given name, type, class. 799825eb42bSJan Lentfer * \param[out] p the packet to be returned 800825eb42bSJan Lentfer * \param[in] rr_name the name to query for (as string) 801825eb42bSJan Lentfer * \param[in] rr_type the type to query for 802825eb42bSJan Lentfer * \param[in] rr_class the class to query for 803825eb42bSJan Lentfer * \param[in] flags packet flags 804825eb42bSJan Lentfer * \return LDNS_STATUS_OK or a ldns_status mesg with the error 805825eb42bSJan Lentfer */ 806825eb42bSJan Lentfer ldns_status ldns_pkt_query_new_frm_str(ldns_pkt **p, const char *rr_name, ldns_rr_type rr_type, ldns_rr_class rr_class , uint16_t flags); 807825eb42bSJan Lentfer 808825eb42bSJan Lentfer /** 8095340022aSzrj * creates an IXFR request packet for the given name, class. 8105340022aSzrj * adds the SOA record to the authority section. 8115340022aSzrj * \param[out] p the packet to be returned 8125340022aSzrj * \param[in] rr_name the name to query for (as string) 8135340022aSzrj * \param[in] rr_class the class to query for 8145340022aSzrj * \param[in] flags packet flags 8155340022aSzrj * \param[in] soa soa record to be added to the authority section (not copied). 8165340022aSzrj * \return LDNS_STATUS_OK or a ldns_status mesg with the error 8175340022aSzrj */ 8185340022aSzrj ldns_status ldns_pkt_ixfr_request_new_frm_str(ldns_pkt **p, const char *rr_name, ldns_rr_class rr_class, uint16_t flags, ldns_rr* soa); 8195340022aSzrj 8205340022aSzrj /** 821825eb42bSJan Lentfer * creates a packet with a query in it for the given name, type and class. 8225340022aSzrj * \param[in] rr_name the name to query for (not copied). 8235340022aSzrj * The returned packet will take ownership of rr_name, so the caller should not free it. 824825eb42bSJan Lentfer * \param[in] rr_type the type to query for 825825eb42bSJan Lentfer * \param[in] rr_class the class to query for 826825eb42bSJan Lentfer * \param[in] flags packet flags 827825eb42bSJan Lentfer * \return ldns_pkt* a pointer to the new pkt 828825eb42bSJan Lentfer */ 829825eb42bSJan Lentfer ldns_pkt *ldns_pkt_query_new(ldns_rdf *rr_name, ldns_rr_type rr_type, ldns_rr_class rr_class, uint16_t flags); 830825eb42bSJan Lentfer 831825eb42bSJan Lentfer /** 8325340022aSzrj * creates an IXFR request packet for the given name, type and class. 8335340022aSzrj * adds the SOA record to the authority section. 8345340022aSzrj * \param[in] rr_name the name to query for (not copied). 8355340022aSzrj * The returned packet will take ownership of rr_name, so the caller should not free it. 8365340022aSzrj * \param[in] rr_class the class to query for 8375340022aSzrj * \param[in] flags packet flags 8385340022aSzrj * \param[in] soa soa record to be added to the authority section (not copied). 8395340022aSzrj * \return ldns_pkt* a pointer to the new pkt 8405340022aSzrj */ 8415340022aSzrj ldns_pkt *ldns_pkt_ixfr_request_new(ldns_rdf *rr_name, ldns_rr_class rr_class, uint16_t flags, ldns_rr* soa); 8425340022aSzrj 8435340022aSzrj /** 844825eb42bSJan Lentfer * clones the given packet, creating a fully allocated copy 845825eb42bSJan Lentfer * 846825eb42bSJan Lentfer * \param[in] pkt the packet to clone 847825eb42bSJan Lentfer * \return ldns_pkt* pointer to the new packet 848825eb42bSJan Lentfer */ 8495340022aSzrj ldns_pkt *ldns_pkt_clone(const ldns_pkt *pkt); 850825eb42bSJan Lentfer 851825eb42bSJan Lentfer /** 852825eb42bSJan Lentfer * directly set the additional section 853825eb42bSJan Lentfer * \param[in] p packet to operate on 854825eb42bSJan Lentfer * \param[in] rr rrlist to set 855825eb42bSJan Lentfer */ 856825eb42bSJan Lentfer void ldns_pkt_set_additional(ldns_pkt *p, ldns_rr_list *rr); 857825eb42bSJan Lentfer 858825eb42bSJan Lentfer /** 859825eb42bSJan Lentfer * directly set the answer section 860825eb42bSJan Lentfer * \param[in] p packet to operate on 861825eb42bSJan Lentfer * \param[in] rr rrlist to set 862825eb42bSJan Lentfer */ 863825eb42bSJan Lentfer void ldns_pkt_set_answer(ldns_pkt *p, ldns_rr_list *rr); 864825eb42bSJan Lentfer 865825eb42bSJan Lentfer /** 866825eb42bSJan Lentfer * directly set the question section 867825eb42bSJan Lentfer * \param[in] p packet to operate on 868825eb42bSJan Lentfer * \param[in] rr rrlist to set 869825eb42bSJan Lentfer */ 870825eb42bSJan Lentfer void ldns_pkt_set_question(ldns_pkt *p, ldns_rr_list *rr); 871825eb42bSJan Lentfer 872825eb42bSJan Lentfer /** 873*ee791febSAntonio Huete Jimenez * directly set the authority section 874825eb42bSJan Lentfer * \param[in] p packet to operate on 875825eb42bSJan Lentfer * \param[in] rr rrlist to set 876825eb42bSJan Lentfer */ 877825eb42bSJan Lentfer void ldns_pkt_set_authority(ldns_pkt *p, ldns_rr_list *rr); 878825eb42bSJan Lentfer 879825eb42bSJan Lentfer /** 880825eb42bSJan Lentfer * push an rr on a packet 881825eb42bSJan Lentfer * \param[in] packet packet to operate on 882825eb42bSJan Lentfer * \param[in] section where to put it 883825eb42bSJan Lentfer * \param[in] rr rr to push 884825eb42bSJan Lentfer * \return a boolean which is true when the rr was added 885825eb42bSJan Lentfer */ 886825eb42bSJan Lentfer bool ldns_pkt_push_rr(ldns_pkt *packet, ldns_pkt_section section, ldns_rr *rr); 887825eb42bSJan Lentfer 888825eb42bSJan Lentfer /** 889825eb42bSJan Lentfer * push an rr on a packet, provided the RR is not there. 890825eb42bSJan Lentfer * \param[in] pkt packet to operate on 891825eb42bSJan Lentfer * \param[in] sec where to put it 892825eb42bSJan Lentfer * \param[in] rr rr to push 893825eb42bSJan Lentfer * \return a boolean which is true when the rr was added 894825eb42bSJan Lentfer */ 895825eb42bSJan Lentfer bool ldns_pkt_safe_push_rr(ldns_pkt *pkt, ldns_pkt_section sec, ldns_rr *rr); 896825eb42bSJan Lentfer 897825eb42bSJan Lentfer /** 898825eb42bSJan Lentfer * push a rr_list on a packet 899825eb42bSJan Lentfer * \param[in] packet packet to operate on 900825eb42bSJan Lentfer * \param[in] section where to put it 901825eb42bSJan Lentfer * \param[in] list the rr_list to push 902825eb42bSJan Lentfer * \return a boolean which is true when the rr was added 903825eb42bSJan Lentfer */ 904825eb42bSJan Lentfer bool ldns_pkt_push_rr_list(ldns_pkt *packet, ldns_pkt_section section, ldns_rr_list *list); 905825eb42bSJan Lentfer 906825eb42bSJan Lentfer /** 907825eb42bSJan Lentfer * push an rr_list to a packet, provided the RRs are not already there. 908825eb42bSJan Lentfer * \param[in] pkt packet to operate on 909825eb42bSJan Lentfer * \param[in] sec where to put it 910825eb42bSJan Lentfer * \param[in] list the rr_list to push 911825eb42bSJan Lentfer * \return a boolean which is true when the rr was added 912825eb42bSJan Lentfer */ 913825eb42bSJan Lentfer bool ldns_pkt_safe_push_rr_list(ldns_pkt *pkt, ldns_pkt_section sec, ldns_rr_list *list); 914825eb42bSJan Lentfer 915825eb42bSJan Lentfer /** 916825eb42bSJan Lentfer * check if a packet is empty 917825eb42bSJan Lentfer * \param[in] p packet 918ac996e71SJan Lentfer * \return true: empty, false: not empty 919825eb42bSJan Lentfer */ 920825eb42bSJan Lentfer bool ldns_pkt_empty(ldns_pkt *p); 921825eb42bSJan Lentfer 922ac996e71SJan Lentfer #ifdef __cplusplus 923ac996e71SJan Lentfer } 924ac996e71SJan Lentfer #endif 925ac996e71SJan Lentfer 926825eb42bSJan Lentfer #endif /* LDNS_PACKET_H */ 927