Nicolas Borla / Mbed OS BBR_1Ebene
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers fnet_dns_prv.h Source File

fnet_dns_prv.h

00001 /**************************************************************************
00002 *
00003 * Copyright 2014-2016 by Andrey Butok. FNET Community.
00004 *
00005 ***************************************************************************
00006 *
00007 *  Licensed under the Apache License, Version 2.0 (the "License"); you may
00008 *  not use this file except in compliance with the License.
00009 *  You may obtain a copy of the License at
00010 *
00011 *  http://www.apache.org/licenses/LICENSE-2.0
00012 *
00013 *  Unless required by applicable law or agreed to in writing, software
00014 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00015 *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016 *  See the License for the specific language governing permissions and
00017 *  limitations under the License.
00018 *
00019 **********************************************************************/
00020 /*!
00021 * @brief DNS Definitions.
00022 *
00023 ***************************************************************************/
00024 
00025 #ifndef _FNET_DNS_PRV_H_
00026 
00027 #define _FNET_DNS_PRV_H_
00028 
00029 /************************************************************************
00030 *     Definitions
00031 *************************************************************************/
00032 /* Size limits. */
00033 #define FNET_DNS_MAME_SIZE      (255U)     /* RFC1035:To simplify implementations, the total length of a domain name (i.e.,
00034                                            * label octets and label length octets) is restricted to 255 octets or less.*/
00035 #define FNET_DNS_MESSAGE_SIZE   (512U)     /* Messages carried by UDP are restricted to 512 bytes (not counting the IP
00036                                            * or UDP headers).  
00037                                            * Longer messages (not supported) are truncated and the TC bit is set in
00038                                            * the header.*/
00039 
00040 /********************************************************************/ /*!
00041 * @brief DNS Resorce Record Types
00042 *************************************************************************/
00043 #define    FNET_DNS_TYPE_A      (0x0001U)    /**< @brief IPv4 address. */
00044 #define    FNET_DNS_TYPE_AAAA   (0x001CU)    /**< @brief IPv6 address. */
00045 
00046 /************************************************************************
00047 *    DNS header [RFC1035, 4.1.1.]
00048 *************************************************************************
00049       0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5
00050     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
00051     |                      ID                       |
00052     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
00053     |QR|   Opcode  |AA|TC|RD|RA|   Z    |   RCODE   |
00054     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
00055     |                    QDCOUNT                    |
00056     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
00057     |                    ANCOUNT                    |
00058     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
00059     |                    NSCOUNT                    |
00060     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
00061     |                    ARCOUNT                    |
00062     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
00063 */
00064 FNET_COMP_PACKED_BEGIN
00065 typedef struct
00066 {
00067     fnet_uint16_t id FNET_COMP_PACKED;         /* A 16 bit identifier assigned by the program that
00068                                                 * generates any kind of query. This identifier is copied
00069                                                 * the corresponding reply and can be used by the requester
00070                                                 * to match up replies to outstanding queries. */
00071     fnet_uint16_t flags FNET_COMP_PACKED;      /* Flags.*/
00072     fnet_uint16_t qdcount FNET_COMP_PACKED;    /* An unsigned 16 bit integer specifying the number of
00073                                                 * entries in the question section.*/
00074     fnet_uint16_t ancount FNET_COMP_PACKED;    /* An unsigned 16 bit integer specifying the number of
00075                                                 * resource records in the answer section.*/
00076     fnet_uint16_t nscount FNET_COMP_PACKED;    /* an unsigned 16 bit integer specifying the number of name
00077                                                 * server resource records in the authority records
00078                                                 * section.*/
00079     fnet_uint16_t arcount FNET_COMP_PACKED;    /* An unsigned 16 bit integer specifying the number of
00080                                                 * resource records in the additional records section.*/
00081 
00082 } fnet_dns_header_t;
00083 FNET_COMP_PACKED_END
00084 
00085 #define FNET_DNS_HEADER_FLAGS_QR    (0x8000U) /* Query (0), Response (1)*/
00086 #define FNET_DNS_HEADER_FLAGS_AA    (0x0400U) /* Authoritative Answer. */
00087 #define FNET_DNS_HEADER_FLAGS_TC    (0x0200U) /* TrunCation. */
00088 #define FNET_DNS_HEADER_FLAGS_RD    (0x0100U) /* Recursion Desired. */
00089 #define FNET_DNS_HEADER_FLAGS_RA    (0x0080U) /* Recursion Available. */
00090 
00091 /************************************************************************
00092 *    DNS Question section [RFC1035, 4.1.2.]
00093 *************************************************************************
00094       0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5
00095     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
00096     |                                               |
00097     /                     QNAME                     /
00098     /                                               /
00099     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
00100     |                     QTYPE                     |
00101     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
00102     |                     QCLASS                    |
00103     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
00104 */
00105 FNET_COMP_PACKED_BEGIN
00106 typedef struct
00107 {
00108     fnet_uint8_t   zero_length FNET_COMP_PACKED;   /* The domain name terminates with the
00109                                                     * zero length octet for the null label of the root. */
00110     fnet_uint16_t  qtype FNET_COMP_PACKED;         /* Specifies the type of the query.*/
00111     fnet_uint16_t  qclass FNET_COMP_PACKED;        /* Specifies the class of the query.*/
00112 
00113 } fnet_dns_q_tail_t;
00114 FNET_COMP_PACKED_END
00115 
00116 /************************************************************************
00117 *    DNS Resource Record header [RFC1035, 4.1.3.] with message compression
00118 *************************************************************************
00119       0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5
00120     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
00121     |                                               |
00122     /                                               /
00123     /                      NAME                     /
00124     |                                               |
00125     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
00126     |                      TYPE                     |
00127     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
00128     |                     CLASS                     |
00129     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
00130     |                      TTL                      |
00131     |                                               |
00132     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
00133     |                   RDLENGTH                    |
00134     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
00135     /                     RDATA                     /
00136     /                                               /
00137     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
00138 */
00139 FNET_COMP_PACKED_BEGIN
00140 typedef struct
00141 {
00142     union
00143     {
00144         fnet_uint8_t   name_ptr_c[2] FNET_COMP_PACKED; /* A domain name to which this resource record pertains.
00145                                                         * For compression, it is replaced with a pointer to a prior occurance
00146                                                         * of the same name */
00147         fnet_uint16_t  name_ptr FNET_COMP_PACKED;
00148     } name;
00149     fnet_uint16_t   type FNET_COMP_PACKED;          /* This field specifies the meaning of the data in the RDATA
00150                                                     * field.*/
00151     fnet_uint16_t   rr_class FNET_COMP_PACKED;     /* An unsigned 16 bit integer specifying the number of
00152                                                     * entries in the question section.*/
00153     fnet_uint32_t   ttl FNET_COMP_PACKED;           /* Specifies the time interval (in seconds) that the
00154                                                     * resource record may be
00155                                                     * cached before it should be discarded.*/
00156     fnet_uint16_t   rdlength FNET_COMP_PACKED;      /* Length in octets of the RDATA field.*/
00157     fnet_uint32_t   rdata FNET_COMP_PACKED;         /* The format of this information varies
00158                                                     * according to the TYPE and CLASS of the resource record.
00159                                                     * If the TYPE is A and the CLASS is IN,
00160                                                     * the RDATA field is a 4 octet ARPA Internet address.*/
00161 
00162 } fnet_dns_rr_header_t;
00163 FNET_COMP_PACKED_END
00164 
00165 /* [RFC1035 4.1.4.] In order to reduce the size of messages, the domain system utilizes a
00166 * compression scheme which eliminates the repetition of domain names in a
00167 * message. In this scheme, an entire domain name or a list of labels at
00168 * the end of a domain name is replaced with a pointer to a prior occurance
00169 * of the same name.
00170 * The pointer takes the form of a two octet sequence:
00171 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
00172 * | 1  1|                OFFSET                   |
00173 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
00174 */
00175 #define     FNET_DNS_NAME_COMPRESSED_MASK           (0xC0U)       /**< @brief Mark that name is compressed. */
00176 #define     FNET_DNS_NAME_COMPRESSED_INDEX_MASK     (0x3FFFU)     /**< @brief Index of compressed name. */
00177 
00178 #define FNET_DNS_HEADER_CLASS_IN    (0x01U)  /* The Internet.*/
00179 
00180 #endif /* _FNET_DNS_PRV_H_*/