From: Daniel Salzman Date: Tue, 23 Jan 2018 09:20:14 +0000 (+0100) Subject: libknot/pkt/wire: make simple functions static inline X-Git-Tag: v2.7.0~245 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec87136d2d748936d939f54fb401b2d73a4ae589;p=thirdparty%2Fknot-dns.git libknot/pkt/wire: make simple functions static inline --- diff --git a/Knot.files b/Knot.files index 6e360a137d..ec03866a93 100644 --- a/Knot.files +++ b/Knot.files @@ -350,7 +350,6 @@ src/libknot/packet/pkt.c src/libknot/packet/pkt.h src/libknot/packet/rrset-wire.c src/libknot/packet/rrset-wire.h -src/libknot/packet/wire.c src/libknot/packet/wire.h src/libknot/rdata.h src/libknot/rdataset.c diff --git a/src/Makefile.am b/src/Makefile.am index a50c73505b..124e767b7e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -150,7 +150,6 @@ libknot_la_SOURCES = \ libknot/packet/compr.c \ libknot/packet/pkt.c \ libknot/packet/rrset-wire.c \ - libknot/packet/wire.c \ libknot/rdataset.c \ libknot/rrset-dump.c \ libknot/rrset.c \ diff --git a/src/libknot/packet/wire.c b/src/libknot/packet/wire.c deleted file mode 100644 index 40032e984a..0000000000 --- a/src/libknot/packet/wire.c +++ /dev/null @@ -1,126 +0,0 @@ -/* Copyright (C) 2018 CZ.NIC, z.s.p.o. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - */ - -#include - -#include "libknot/attribute.h" -#include "libknot/packet/wire.h" -#include "libknot/wire.h" - -_public_ -uint16_t knot_wire_get_id(const uint8_t *packet) -{ - return knot_wire_read_u16(packet + KNOT_WIRE_OFFSET_ID); -} - -_public_ -void knot_wire_set_id(uint8_t *packet, uint16_t id) -{ - knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_ID, id); -} - -_public_ -uint16_t knot_wire_get_qdcount(const uint8_t *packet) -{ - return knot_wire_read_u16(packet + KNOT_WIRE_OFFSET_QDCOUNT); -} - -_public_ -void knot_wire_set_qdcount(uint8_t *packet, uint16_t qdcount) -{ - knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_QDCOUNT, qdcount); -} - -_public_ -void knot_wire_add_qdcount(uint8_t *packet, int16_t n) -{ - knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_QDCOUNT, - knot_wire_get_qdcount(packet) + n); -} - -_public_ -uint16_t knot_wire_get_ancount(const uint8_t *packet) -{ - return knot_wire_read_u16(packet + KNOT_WIRE_OFFSET_ANCOUNT); -} - -_public_ -void knot_wire_set_ancount(uint8_t *packet, uint16_t ancount) -{ - knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_ANCOUNT, ancount); -} - -_public_ -void knot_wire_add_ancount(uint8_t *packet, int16_t n) -{ - knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_ANCOUNT, - knot_wire_get_ancount(packet) + n); -} - -_public_ -uint16_t knot_wire_get_nscount(const uint8_t *packet) -{ - return knot_wire_read_u16(packet + KNOT_WIRE_OFFSET_NSCOUNT); -} - -_public_ -void knot_wire_set_nscount(uint8_t *packet, uint16_t nscount) -{ - knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_NSCOUNT, nscount); -} - -_public_ -void knot_wire_add_nscount(uint8_t *packet, int16_t n) -{ - knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_NSCOUNT, - knot_wire_get_nscount(packet) + n); -} - -_public_ -uint16_t knot_wire_get_arcount(const uint8_t *packet) -{ - return knot_wire_read_u16(packet + KNOT_WIRE_OFFSET_ARCOUNT); -} - -_public_ -void knot_wire_set_arcount(uint8_t *packet, uint16_t arcount) -{ - knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_ARCOUNT, arcount); -} - -_public_ -void knot_wire_add_arcount(uint8_t *packet, int16_t n) -{ - knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_ARCOUNT, - knot_wire_get_arcount(packet) + n); -} - -_public_ -void knot_wire_put_pointer(uint8_t *pos, uint16_t ptr) -{ - knot_wire_write_u16(pos, ptr); // Write pointer offset. - assert((pos[0] & KNOT_WIRE_PTR) == 0); // Check for maximal offset. - pos[0] |= KNOT_WIRE_PTR; // Add pointer mark. -} - -_public_ -uint16_t knot_wire_get_pointer(const uint8_t *pos) -{ - assert(knot_wire_is_pointer(pos)); // Check pointer. - return (knot_wire_read_u16(pos) - KNOT_WIRE_PTR_BASE); // Return offset. -} - -/*! @} */ diff --git a/src/libknot/packet/wire.h b/src/libknot/packet/wire.h index e519ca0b09..26bc80e5cc 100644 --- a/src/libknot/packet/wire.h +++ b/src/libknot/packet/wire.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 CZ.NIC, z.s.p.o. +/* Copyright (C) 2018 CZ.NIC, z.s.p.o. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,9 +24,11 @@ #pragma once +#include #include -#include + #include "libknot/attribute.h" +#include "libknot/wire.h" /*! \brief Offset of DNS header fields in wireformat. */ enum knot_wire_offsets { @@ -62,7 +64,10 @@ enum knot_wire_sizes { * * \return DNS packet ID. */ -uint16_t knot_wire_get_id(const uint8_t *packet); +static inline uint16_t knot_wire_get_id(const uint8_t *packet) +{ + return knot_wire_read_u16(packet + KNOT_WIRE_OFFSET_ID); +} /*! * \brief Sets the ID to the wire format of the packet. @@ -70,7 +75,10 @@ uint16_t knot_wire_get_id(const uint8_t *packet); * \param packet Wire format of the packet. * \param id DNS packet ID. */ -void knot_wire_set_id(uint8_t *packet, uint16_t id); +static inline void knot_wire_set_id(uint8_t *packet, uint16_t id) +{ + knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_ID, id); +} /*! * \brief Returns the first byte of flags from wire format of the packet. @@ -126,7 +134,10 @@ static inline uint8_t knot_wire_set_flags2(uint8_t *packet, uint8_t flags2) * * \return QDCOUNT (count of Question entries in the packet). */ -uint16_t knot_wire_get_qdcount(const uint8_t *packet); +static inline uint16_t knot_wire_get_qdcount(const uint8_t *packet) +{ + return knot_wire_read_u16(packet + KNOT_WIRE_OFFSET_QDCOUNT); +} /*! * \brief Sets the QDCOUNT (count of Question entries) to wire format of the @@ -135,12 +146,19 @@ uint16_t knot_wire_get_qdcount(const uint8_t *packet); * \param packet Wire format of the packet. * \param qdcount QDCOUNT (count of Question entries in the packet). */ -void knot_wire_set_qdcount(uint8_t *packet, uint16_t qdcount); +static inline void knot_wire_set_qdcount(uint8_t *packet, uint16_t qdcount) +{ + knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_QDCOUNT, qdcount); +} /*! * \brief Adds to QDCOUNT. */ -void knot_wire_add_qdcount(uint8_t *packet, int16_t n); +static inline void knot_wire_add_qdcount(uint8_t *packet, int16_t n) +{ + knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_QDCOUNT, + knot_wire_get_qdcount(packet) + n); +} /*! * \brief Returns the ANCOUNT (count of Answer entries) from wire format of @@ -150,7 +168,10 @@ void knot_wire_add_qdcount(uint8_t *packet, int16_t n); * * \return ANCOUNT (count of Answer entries in the packet). */ -uint16_t knot_wire_get_ancount(const uint8_t *packet); +static inline uint16_t knot_wire_get_ancount(const uint8_t *packet) +{ + return knot_wire_read_u16(packet + KNOT_WIRE_OFFSET_ANCOUNT); +} /*! * \brief Sets the ANCOUNT (count of Answer entries) to wire format of the @@ -159,12 +180,19 @@ uint16_t knot_wire_get_ancount(const uint8_t *packet); * \param packet Wire format of the packet. * \param ancount ANCOUNT (count of Answer entries in the packet). */ -void knot_wire_set_ancount(uint8_t *packet, uint16_t ancount); +static inline void knot_wire_set_ancount(uint8_t *packet, uint16_t ancount) +{ + knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_ANCOUNT, ancount); +} /*! * \brief Adds to ANCOUNT. */ -void knot_wire_add_ancount(uint8_t *packet, int16_t n); +static inline void knot_wire_add_ancount(uint8_t *packet, int16_t n) +{ + knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_ANCOUNT, + knot_wire_get_ancount(packet) + n); +} /*! * \brief Returns the NSCOUNT (count of Authority entries) from wire format of @@ -174,7 +202,10 @@ void knot_wire_add_ancount(uint8_t *packet, int16_t n); * * \return NSCOUNT (count of Authority entries in the packet). */ -uint16_t knot_wire_get_nscount(const uint8_t *packet); +static inline uint16_t knot_wire_get_nscount(const uint8_t *packet) +{ + return knot_wire_read_u16(packet + KNOT_WIRE_OFFSET_NSCOUNT); +} /*! * \brief Sets the NSCOUNT (count of Authority entries) to wire format of the @@ -183,12 +214,19 @@ uint16_t knot_wire_get_nscount(const uint8_t *packet); * \param packet Wire format of the packet. * \param nscount NSCOUNT (count of Authority entries in the packet). */ -void knot_wire_set_nscount(uint8_t *packet, uint16_t nscount); +static inline void knot_wire_set_nscount(uint8_t *packet, uint16_t nscount) +{ + knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_NSCOUNT, nscount); +} /*! * \brief Adds to NSCOUNT. */ -void knot_wire_add_nscount(uint8_t *packet, int16_t n); +static inline void knot_wire_add_nscount(uint8_t *packet, int16_t n) +{ + knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_NSCOUNT, + knot_wire_get_nscount(packet) + n); +} /*! * \brief Returns the ARCOUNT (count of Additional entries) from wire format of @@ -198,7 +236,10 @@ void knot_wire_add_nscount(uint8_t *packet, int16_t n); * * \return ARCOUNT (count of Additional entries in the packet). */ -uint16_t knot_wire_get_arcount(const uint8_t *packet); +static inline uint16_t knot_wire_get_arcount(const uint8_t *packet) +{ + return knot_wire_read_u16(packet + KNOT_WIRE_OFFSET_ARCOUNT); +} /*! * \brief Sets the ARCOUNT (count of Additional entries) to wire format of the @@ -207,12 +248,19 @@ uint16_t knot_wire_get_arcount(const uint8_t *packet); * \param packet Wire format of the packet. * \param arcount ARCOUNT (count of Additional entries in the packet). */ -void knot_wire_set_arcount(uint8_t *packet, uint16_t arcount); +static inline void knot_wire_set_arcount(uint8_t *packet, uint16_t arcount) +{ + knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_ARCOUNT, arcount); +} /*! * \brief Adds to ARCOUNT. */ -void knot_wire_add_arcount(uint8_t *packet, int16_t n); +static inline void knot_wire_add_arcount(uint8_t *packet, int16_t n) +{ + knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_ARCOUNT, + knot_wire_get_arcount(packet) + n); +} /* * Packet header flags manipulation functions. @@ -885,6 +933,11 @@ enum knot_wire_pointer_consts { KNOT_WIRE_PTR_MAX = (uint16_t)0x3FFF }; +static inline int knot_wire_is_pointer(const uint8_t *pos) +{ + return pos && ((pos[0] & KNOT_WIRE_PTR) == KNOT_WIRE_PTR); +} + /*! * \brief Creates a DNS packet pointer and stores it in wire format. * @@ -892,13 +945,17 @@ enum knot_wire_pointer_consts { * \param ptr Relative position of the item to which the pointer should point in * the wire format of the packet. */ -void knot_wire_put_pointer(uint8_t *pos, uint16_t ptr); - -uint16_t knot_wire_get_pointer(const uint8_t *pos); +static inline void knot_wire_put_pointer(uint8_t *pos, uint16_t ptr) +{ + knot_wire_write_u16(pos, ptr); // Write pointer offset. + assert((pos[0] & KNOT_WIRE_PTR) == 0); // Check for maximal offset. + pos[0] |= KNOT_WIRE_PTR; // Add pointer mark. +} -static inline int knot_wire_is_pointer(const uint8_t *pos) +static inline uint16_t knot_wire_get_pointer(const uint8_t *pos) { - return pos && ((pos[0] & KNOT_WIRE_PTR) == KNOT_WIRE_PTR); + assert(knot_wire_is_pointer(pos)); // Check pointer. + return (knot_wire_read_u16(pos) - KNOT_WIRE_PTR_BASE); // Return offset. } _pure_ _mustcheck_