Adding upstream version 5.7.5.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
This commit is contained in:
parent
bd60502c59
commit
fbc604e215
1284 changed files with 265844 additions and 0 deletions
47
.clang-tidy
Normal file
47
.clang-tidy
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
---
|
||||||
|
Checks:
|
||||||
|
- bugprone-*
|
||||||
|
- cert-*
|
||||||
|
- google-readability-casting
|
||||||
|
- misc-*
|
||||||
|
- readability-*
|
||||||
|
|
||||||
|
- -bugprone-assignment-in-if-condition # we explicitly put assignments into parentheses so they are very visible
|
||||||
|
- -bugprone-branch-clone
|
||||||
|
- -bugprone-easily-swappable-parameters
|
||||||
|
- -bugprone-inc-dec-in-conditions
|
||||||
|
- -bugprone-multi-level-implicit-pointer-conversion
|
||||||
|
- -bugprone-narrowing-conversions
|
||||||
|
- -bugprone-sizeof-expression # may be useful, but it's utterly broken
|
||||||
|
- -bugprone-suspicious-string-compare
|
||||||
|
- -cert-dcl03-c
|
||||||
|
- -clang-analyzer-deadcode.DeadStores
|
||||||
|
- -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling
|
||||||
|
- -clang-analyzer-unix.Malloc
|
||||||
|
- -clang-analyzer-valist.Uninitialized
|
||||||
|
- -clang-analyzer-optin.core.EnumCastOutOfRange # libknot uses enums as flags
|
||||||
|
- -misc-include-cleaner
|
||||||
|
- -misc-macro-parentheses
|
||||||
|
- -misc-no-recursion
|
||||||
|
- -misc-static-assert
|
||||||
|
- -misc-unused-parameters
|
||||||
|
- -readability-avoid-nested-conditional-operator
|
||||||
|
- -readability-avoid-unconditional-preprocessor-if
|
||||||
|
- -readability-braces-*
|
||||||
|
- -readability-cognitive-complexity
|
||||||
|
- -readability-else-after-return
|
||||||
|
- -readability-function-cognitive-complexity
|
||||||
|
- -readability-identifier-length
|
||||||
|
- -readability-isolate-declaration
|
||||||
|
- -readability-magic-numbers
|
||||||
|
- -readability-non-const-parameter
|
||||||
|
- -readability-redundant-declaration
|
||||||
|
WarningsAsErrors: 'cert-*,clang-analyzer-*,misc-*,readability-*,-readability-non-const-parameter'
|
||||||
|
HeaderFilterRegex: 'contrib/ucw/*.h'
|
||||||
|
CheckOptions:
|
||||||
|
- key: readability-identifier-naming
|
||||||
|
value: 'lower_case'
|
||||||
|
- key: readability-function-size.StatementThreshold
|
||||||
|
value: '400'
|
||||||
|
- key: readability-function-size.LineThreshold
|
||||||
|
value: '500'
|
10
.dir-locals.el
Normal file
10
.dir-locals.el
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
;; emacs local configuration settings for knot-resolver source
|
||||||
|
;; surmised by dkg on 2016-04-02 23:46:50-0300
|
||||||
|
;; SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
((c-mode
|
||||||
|
(indent-tabs-mode . t)
|
||||||
|
(tab-width . 8)
|
||||||
|
(c-basic-offset . 8)
|
||||||
|
(c-file-style . "linux"))
|
||||||
|
)
|
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
*.c diff=cpp
|
||||||
|
*.cpp diff=cpp
|
52
.github/workflows/macOS.yaml
vendored
Normal file
52
.github/workflows/macOS.yaml
vendored
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
name: macOS
|
||||||
|
|
||||||
|
on: push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-test:
|
||||||
|
name: Build & unit tests & sanity check
|
||||||
|
runs-on: macOS-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
knot-version: ['3.2', '3.3']
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout resolver code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
submodules: true
|
||||||
|
|
||||||
|
- name: Install dependecies from brew
|
||||||
|
run:
|
||||||
|
brew install cmocka luajit libuv lmdb meson nghttp2 autoconf automake m4 libtool pkg-config
|
||||||
|
|
||||||
|
- name: Install libknot from sources
|
||||||
|
env:
|
||||||
|
KNOT_DNS_VERSION: ${{ matrix.knot-version }}
|
||||||
|
run: |
|
||||||
|
git clone -b ${KNOT_DNS_VERSION} https://gitlab.nic.cz/knot/knot-dns.git
|
||||||
|
cd knot-dns
|
||||||
|
autoreconf -fi
|
||||||
|
./configure --prefix=${HOME}/.local/usr --disable-static --disable-fastparser --disable-documentation --disable-daemon --disable-utilities --with-lmdb=no
|
||||||
|
make -j2 install
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
- name: Build resolver
|
||||||
|
run: |
|
||||||
|
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:${HOME}/.local/usr/lib/pkgconfig"
|
||||||
|
meson build_darwin --default-library=static --buildtype=debugoptimized --prefix=${HOME}/.local/usr -Dc_args='-fno-omit-frame-pointer'
|
||||||
|
ninja -C build_darwin -v install
|
||||||
|
|
||||||
|
- name: Run unit tests
|
||||||
|
env:
|
||||||
|
MALLOC_CHECK_: 3
|
||||||
|
MALLOC_PERTURB_: 223
|
||||||
|
run: meson test -C build_darwin --suite unit
|
||||||
|
|
||||||
|
- name: Run kresd
|
||||||
|
env:
|
||||||
|
MALLOC_CHECK_: 3
|
||||||
|
MALLOC_PERTURB_: 223
|
||||||
|
run: |
|
||||||
|
export DYLD_FALLBACK_LIBRARY_PATH="${DYLD_FALLBACK_LIBRARY_PATH}:${HOME}/.local/usr/lib/"
|
||||||
|
echo "quit()" | ${HOME}/.local/usr/sbin/kresd -a 127.0.0.1@53535 .
|
83
.gitignore
vendored
Normal file
83
.gitignore
vendored
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
*.6
|
||||||
|
*.Plo
|
||||||
|
*.a
|
||||||
|
*.db
|
||||||
|
*.dylib
|
||||||
|
*.dylib.*
|
||||||
|
*.gcda
|
||||||
|
*.gcno
|
||||||
|
*.gcov
|
||||||
|
*.info
|
||||||
|
*.la
|
||||||
|
*.lo
|
||||||
|
*.log
|
||||||
|
*.mdb
|
||||||
|
*.o
|
||||||
|
*.out
|
||||||
|
*.so
|
||||||
|
*.so.*
|
||||||
|
*.swp
|
||||||
|
*~
|
||||||
|
.deps
|
||||||
|
.dirstamp
|
||||||
|
.libs
|
||||||
|
.pytest_cache
|
||||||
|
/.build-depend
|
||||||
|
/.cache
|
||||||
|
/aclocal.m4
|
||||||
|
/ar-lib
|
||||||
|
/autom4te.cache/*
|
||||||
|
/bench/bench_lru
|
||||||
|
/build*
|
||||||
|
/client/kresc
|
||||||
|
/compile
|
||||||
|
/compile_commands.json
|
||||||
|
/config.guess
|
||||||
|
/config.h
|
||||||
|
/config.log
|
||||||
|
/config.status
|
||||||
|
/config.sub
|
||||||
|
/configure
|
||||||
|
/control
|
||||||
|
/coverage
|
||||||
|
/coverage.stats
|
||||||
|
/daemon/kresd
|
||||||
|
/daemon/lua/*.inc
|
||||||
|
/daemon/lua/trust_anchors.lua
|
||||||
|
/depcomp
|
||||||
|
/distro/tests/*/.vagrant
|
||||||
|
/doc/.doctrees
|
||||||
|
/doc/doxyxml
|
||||||
|
/doc/html
|
||||||
|
/doc/kresd.8
|
||||||
|
/doc/texinfo
|
||||||
|
/ephemeral_key.pem
|
||||||
|
/install-sh
|
||||||
|
/libkres.pc
|
||||||
|
/libtool
|
||||||
|
/ltmain.sh
|
||||||
|
/missing
|
||||||
|
/modules/dnstap/dnstap.pb-c.d
|
||||||
|
/pkg
|
||||||
|
/self.crt
|
||||||
|
/self.key
|
||||||
|
/stamp-h1
|
||||||
|
/tags
|
||||||
|
/tests/dnstap/src/dnstap-test/go.sum
|
||||||
|
/tests/pytests/*/tcproxy
|
||||||
|
/tests/pytests/*/tlsproxy
|
||||||
|
/tests/pytests/pytests.*.html
|
||||||
|
/tests/pytests/*.junit.xml
|
||||||
|
/tests/test_array
|
||||||
|
/tests/test_lru
|
||||||
|
/tests/test_map
|
||||||
|
/tests/test_module
|
||||||
|
/tests/test_pack
|
||||||
|
/tests/test_set
|
||||||
|
/tests/test_utils
|
||||||
|
/tests/test_zonecut
|
||||||
|
/ylwrap
|
||||||
|
_obj
|
||||||
|
kresd.amalg.c
|
||||||
|
libkres.amalg.c
|
||||||
|
luacov.*.out
|
1012
.gitlab-ci.yml
Normal file
1012
.gitlab-ci.yml
Normal file
File diff suppressed because it is too large
Load diff
9
.gitmodules
vendored
Normal file
9
.gitmodules
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
[submodule "tests/integration/deckard"]
|
||||||
|
path = tests/integration/deckard
|
||||||
|
url = https://gitlab.nic.cz/knot/deckard.git
|
||||||
|
[submodule "modules/policy/lua-aho-corasick"]
|
||||||
|
path = modules/policy/lua-aho-corasick
|
||||||
|
url = https://gitlab.nic.cz/knot/3rdparty/lua-aho-corasick.git
|
||||||
|
[submodule "tests/config/tapered"]
|
||||||
|
path = tests/config/tapered
|
||||||
|
url = https://gitlab.nic.cz/knot/3rdparty/lua-tapered.git
|
99
.luacheckrc
Normal file
99
.luacheckrc
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
-- SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
std = 'luajit'
|
||||||
|
new_read_globals = {
|
||||||
|
'cache',
|
||||||
|
'eval_cmd',
|
||||||
|
'event',
|
||||||
|
'help',
|
||||||
|
'_hint_root_file',
|
||||||
|
'hostname',
|
||||||
|
'map',
|
||||||
|
'modules',
|
||||||
|
'net',
|
||||||
|
'package_version',
|
||||||
|
'quit',
|
||||||
|
'resolve',
|
||||||
|
'ta_update',
|
||||||
|
'fromjson',
|
||||||
|
'todname',
|
||||||
|
'tojson',
|
||||||
|
'user',
|
||||||
|
'worker',
|
||||||
|
'kluautil_list_dir',
|
||||||
|
-- Sandbox declarations
|
||||||
|
'kB',
|
||||||
|
'MB',
|
||||||
|
'GB',
|
||||||
|
'sec',
|
||||||
|
'second',
|
||||||
|
'minute',
|
||||||
|
'min',
|
||||||
|
'hour',
|
||||||
|
'day',
|
||||||
|
'panic',
|
||||||
|
'log',
|
||||||
|
'log_error',
|
||||||
|
'log_warn',
|
||||||
|
'log_info',
|
||||||
|
'log_debug',
|
||||||
|
'log_fmt',
|
||||||
|
'log_qry',
|
||||||
|
'log_req',
|
||||||
|
'log_level',
|
||||||
|
'log_target',
|
||||||
|
'log_groups',
|
||||||
|
'LOG_CRIT',
|
||||||
|
'LOG_ERR',
|
||||||
|
'LOG_WARNING',
|
||||||
|
'LOG_NOTICE',
|
||||||
|
'LOG_INFO',
|
||||||
|
'LOG_DEBUG',
|
||||||
|
'mode',
|
||||||
|
'reorder_RR',
|
||||||
|
'option',
|
||||||
|
'env',
|
||||||
|
'debugging',
|
||||||
|
'kres',
|
||||||
|
'libknot_SONAME',
|
||||||
|
'libzscanner_SONAME',
|
||||||
|
'table_print',
|
||||||
|
'_ENV',
|
||||||
|
}
|
||||||
|
|
||||||
|
new_globals = {
|
||||||
|
-- Modules are allowed to be set and accessed from global namespace
|
||||||
|
'policy',
|
||||||
|
'view',
|
||||||
|
'stats',
|
||||||
|
'http',
|
||||||
|
'trust_anchors',
|
||||||
|
'bogus_log',
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Luacheck < 0.18 doesn't support new_read_globals
|
||||||
|
for _, v in ipairs(new_read_globals) do
|
||||||
|
table.insert(new_globals, v)
|
||||||
|
end
|
||||||
|
|
||||||
|
exclude_files = {
|
||||||
|
'modules/policy/lua-aho-corasick', -- Vendored
|
||||||
|
'tests/config/tapered',
|
||||||
|
'build*/**', -- build outputs
|
||||||
|
'pkg/**', -- packaging outputs
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Ignore some pedantic checks
|
||||||
|
ignore = {
|
||||||
|
'4.1/err', -- Shadowing err
|
||||||
|
'4.1/.', -- Shadowing one letter variables
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Sandbox can set global variables
|
||||||
|
files['**/daemon/lua'].ignore = {'111', '121', '122'}
|
||||||
|
files['**/daemon/lua/kres-gen-*.lua'].ignore = {'631'} -- Allow overly long lines
|
||||||
|
-- Tests and scripts can use global variables
|
||||||
|
files['scripts'].ignore = {'111', '112', '113'}
|
||||||
|
files['tests'].ignore = {'111', '112', '113'}
|
||||||
|
files['**/utils/upgrade'].ignore = {'111', '112', '113'}
|
||||||
|
files['**/modules/**/*.test.lua'].ignore = {'111', '112', '113', '121', '122'}
|
||||||
|
files['**/daemon/**/*.test.lua'].ignore = {'111', '112', '113', '121', '122'}
|
57
.mailmap
Normal file
57
.mailmap
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
Aleš Mrázek <ales.mrazek@nic.cz>
|
||||||
|
Alex Forster <aforster@cloudflare.com>
|
||||||
|
Ali Asad Lotia <ali.asad.lotia@gmail.com>
|
||||||
|
Anbang Wen <anbang@cloudflare.com> <xofyarg@gmail.com>
|
||||||
|
Anbang Wen <anbang@cloudflare.com> <anb@dev.null>
|
||||||
|
Andreas Rammhold <andreas@rammhold.de>
|
||||||
|
Daniel Kahn Gillmor <dkg@fifthhorseman.net>
|
||||||
|
Daniel Salzman <daniel.salzman@nic.cz>
|
||||||
|
daurnimator <quae@daurnimator.com>
|
||||||
|
David Beitey <david@davidjb.com>
|
||||||
|
Grigorii Demidov <grigorii.demidov@nic.cz>
|
||||||
|
Hasnat <hasnat.ullah@gmail.com>
|
||||||
|
Jiří Helebrant <jiri.helebrant@nic.cz> <helb@helb.cz>
|
||||||
|
Ivana Krumlová <ivana.krumlova@nic.cz>
|
||||||
|
Jakub Ružička <jakub.ruzicka@nic.cz>
|
||||||
|
Jan Hák <jan.hak@nic.cz>
|
||||||
|
Jan Holuša <jan.holusa@nic.cz>
|
||||||
|
Jan Pavlinec <jan.pavlinec@nic.cz>
|
||||||
|
Jan Včelák <jan.vcelak@nic.cz> <jv@fcelda.cz>
|
||||||
|
Jan Včelák <jan.vcelak@nic.cz>
|
||||||
|
Jayson Reis <santosdosreis@gmail.com>
|
||||||
|
Jonathan Coetzee <jon@thancoetzee.com>
|
||||||
|
Josh Soref <jsoref@users.noreply.github.com>
|
||||||
|
Karel Slaný <karel.slany@nic.cz>
|
||||||
|
Libor Peltan <libor.peltan@nic.cz>
|
||||||
|
Lukáš Ježek <lukas.jezek@nic.cz>
|
||||||
|
Manu Bretelle <chantr4@gmail.com>
|
||||||
|
Marek Vavruša <mvavrusa@cloudflare.com> Marek Vavrusa <marek@vavrusa.com>
|
||||||
|
Marek Vavruša <mvavrusa@cloudflare.com> Marek Vavruša <mvavrusa@cloudflare.com>
|
||||||
|
Marek Vavruša <mvavrusa@cloudflare.com> Marek Vavruša <marek.vavrusa@nic.cz>
|
||||||
|
Marek Vavruša <mvavrusa@cloudflare.com> <marek@vavrusa.com>
|
||||||
|
Marek Vavruša <mvavrusa@cloudflare.com> <marek.vavrusa@nic.cz>
|
||||||
|
Michal Karm Babáček <karm@email.cz>
|
||||||
|
Michal Lupečka <mlupecka@nic.cz>
|
||||||
|
Ondřej Surý <ondrej.sury@nic.cz> <ondrej@sury.org>
|
||||||
|
Oto Šťáva <oto.stava@nic.cz> <oto.stava@gmail.com>
|
||||||
|
Paul Hoffman <paul.hoffman@icann.org> <phoffman@proper.com>
|
||||||
|
Paul Hoffman <paul.hoffman@icann.org>
|
||||||
|
Pavel Doležal <pavel.dolezal@nic.cz>
|
||||||
|
Pavel Valach <valach.pavel@gmail.com>
|
||||||
|
Petr Špaček <petr.spacek@nic.cz>
|
||||||
|
rickhg12hs <rickhg12hs@users.noreply.github.com>
|
||||||
|
Robert Šefr <robert.sefr@outlook.com>
|
||||||
|
SH <sh@analogic.cz>
|
||||||
|
Simon South <simon@simonsouth.net>
|
||||||
|
Štěpán Balážik <stepan@balazik.cz> <stepan.balazik@nic.cz>
|
||||||
|
Štěpán Kotek <stepan.kotek@nic.cz> Stepan Kotek <stepan.kotek@nic.cz>
|
||||||
|
Štěpán Kotek <stepan.kotek@nic.cz> <stepan.kotek@gmail.com>
|
||||||
|
The Gitter Badger <badger@gitter.im>
|
||||||
|
Tomáš Hozza <thozza@redhat.com>
|
||||||
|
Tomáš Křížek <tomas.krizek@nic.cz>
|
||||||
|
Ulrich Wisser <ulrich.wisser@iis.se>
|
||||||
|
Leo Vandewoestijne <github@unicycle.net>
|
||||||
|
Vašek Šraier <vaclav.sraier@nic.cz> <git@vakabus.cz>
|
||||||
|
Vicky Shrestha <vicky@cloudflare.com> <vicky@geeks.net.np>
|
||||||
|
Vítězslav Kříž <vitezslav.kriz@nic.cz>
|
||||||
|
Vladimír Čunát <vladimir.cunat@nic.cz> <vcunat@gmail.com>
|
17
.readthedocs.yaml
Normal file
17
.readthedocs.yaml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
version: 2
|
||||||
|
|
||||||
|
build:
|
||||||
|
os: ubuntu-22.04
|
||||||
|
tools:
|
||||||
|
python: "3.11"
|
||||||
|
|
||||||
|
sphinx:
|
||||||
|
configuration: doc/conf.py
|
||||||
|
|
||||||
|
python:
|
||||||
|
install:
|
||||||
|
- requirements: doc/requirements.txt
|
||||||
|
|
||||||
|
formats:
|
||||||
|
- pdf
|
||||||
|
- epub
|
87
AUTHORS
Normal file
87
AUTHORS
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
Knot Resolver was conceived and is being developed
|
||||||
|
by research department of CZ.NIC, the CZ TLD operator.
|
||||||
|
|
||||||
|
Over the years many organizations and individuals contributed to the project.
|
||||||
|
Special thanks belongs to following organizations:
|
||||||
|
- Comcast
|
||||||
|
- Cloudflare
|
||||||
|
- ICANN
|
||||||
|
|
||||||
|
People who contributed commits to our Git repo are:
|
||||||
|
Aleš Mrázek <ales.mrazek@nic.cz>
|
||||||
|
Alex Forster <aforster@cloudflare.com>
|
||||||
|
Ali Asad Lotia <ali.asad.lotia@gmail.com>
|
||||||
|
Anbang Wen <anbang@cloudflare.com>
|
||||||
|
Andreas Rammhold <andreas@rammhold.de>
|
||||||
|
Christophe Nowicki <cscm@csquad.org>
|
||||||
|
Christopher Ng <facboy@gmail.com>
|
||||||
|
cronfy <cronfy@gmail.com>
|
||||||
|
Daniel Kahn Gillmor <dkg@fifthhorseman.net>
|
||||||
|
Daniel Salzman <daniel.salzman@nic.cz>
|
||||||
|
daurnimator <quae@daurnimator.com>
|
||||||
|
David Beitey <david@davidjb.com>
|
||||||
|
Frantisek Tobias <frantisek.tobias@nic.cz>
|
||||||
|
Grigorii Demidov <grigorii.demidov@nic.cz>
|
||||||
|
Hasnat <hasnat.ullah@gmail.com>
|
||||||
|
Héctor Molinero Fernández <hector@molinero.dev>
|
||||||
|
Ivana Krumlová <ivana.krumlova@nic.cz>
|
||||||
|
Jakub Jirutka <jakub@jirutka.cz>
|
||||||
|
Jakub Ružička <jakub.ruzicka@nic.cz>
|
||||||
|
Jan Hák <jan.hak@nic.cz>
|
||||||
|
Jan Holuša <jan.holusa@nic.cz>
|
||||||
|
Jan Pavlinec <jan.pavlinec@nic.cz>
|
||||||
|
Jan Včelák <jan.vcelak@nic.cz>
|
||||||
|
Jayson Reis <santosdosreis@gmail.com>
|
||||||
|
Jiří Helebrant <jiri.helebrant@nic.cz>
|
||||||
|
Jonathan Coetzee <jon@thancoetzee.com>
|
||||||
|
Josh Soref <jsoref@users.noreply.github.com>
|
||||||
|
Karel Slaný <karel.slany@nic.cz>
|
||||||
|
Konstantin Amelichev <kostya.amelichev@gmail.com>
|
||||||
|
Leo Vandewoestijne <github@unicycle.net>
|
||||||
|
Libor Peltan <libor.peltan@nic.cz>
|
||||||
|
Lukáš Ježek <lukas.jezek@nic.cz>
|
||||||
|
Manu Bretelle <chantr4@gmail.com>
|
||||||
|
Marek Vavruša <mvavrusa@cloudflare.com>
|
||||||
|
Michal Karm Babáček <karm@email.cz>
|
||||||
|
Michal Lupečka <mlupecka@nic.cz>
|
||||||
|
Ondřej Surý <ondrej.sury@nic.cz>
|
||||||
|
Oto Šťáva <oto.stava@nic.cz>
|
||||||
|
Paul Hoffman <paul.hoffman@icann.org>
|
||||||
|
Pavel Doležal <pavel.dolezal@nic.cz>
|
||||||
|
Pavel Valach <valach.pavel@gmail.com>
|
||||||
|
Peter Keresztes Schmidt <carbenium@outlook.com>
|
||||||
|
Petr Špaček <petr.spacek@nic.cz>
|
||||||
|
realPy <t3sla@v-ip.fr>
|
||||||
|
rickhg12hs <rickhg12hs@users.noreply.github.com>
|
||||||
|
Robert Šefr <robert.sefr@outlook.com>
|
||||||
|
SH <sh@analogic.cz>
|
||||||
|
Simon South <simon@simonsouth.net>
|
||||||
|
Štěpán Balážik <stepan@balazik.cz>
|
||||||
|
Štěpán Kotek <stepan.kotek@nic.cz>
|
||||||
|
The Gitter Badger <badger@gitter.im>
|
||||||
|
Tomáš Hozza <thozza@redhat.com>
|
||||||
|
Tomáš Křížek <tomas.krizek@nic.cz>
|
||||||
|
Tom Herbers <mail@tomherbers.de>
|
||||||
|
Ulrich Wisser <ulrich.wisser@iis.se>
|
||||||
|
Vašek Šraier <vaclav.sraier@nic.cz>
|
||||||
|
Vicky Shrestha <vicky@cloudflare.com>
|
||||||
|
Vítězslav Kříž <vitezslav.kriz@nic.cz>
|
||||||
|
Vladimír Čunát <vladimir.cunat@nic.cz>
|
||||||
|
|
||||||
|
Knot Resolver source tree also bundles code and content published by:
|
||||||
|
Austin Appleby <aappleby@gmail.com>
|
||||||
|
Dan Vanderkam <danvdk@gmail.com>
|
||||||
|
Jonathan Allard <jonathan@allard.io>
|
||||||
|
Joseph A. Adams <joeyadams3.14159@gmail.com>
|
||||||
|
Mark DiMarco <mark.dimarco@gmail.com>
|
||||||
|
Michael Bostock <mike@ocks.org>
|
||||||
|
Rusty Russell <rusty@rustcorp.com.au>
|
||||||
|
Thomas Park <thomas@thomaspark.co>
|
||||||
|
Vincent Bernat <vincent@bernat.im>
|
||||||
|
Fastly
|
||||||
|
jQuery Foundation
|
||||||
|
Knot DNS contributors
|
||||||
|
Twitter
|
||||||
|
United Computer Wizards
|
||||||
|
|
||||||
|
Thanks to everyone who knowingly or unknowingly contributed!
|
19
CONTRIBUTING.md
Normal file
19
CONTRIBUTING.md
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
Contributing
|
||||||
|
============
|
||||||
|
|
||||||
|
Please file issues and merge requests against the upstream repository:
|
||||||
|
|
||||||
|
[https://gitlab.nic.cz/knot/knot-resolver](https://gitlab.nic.cz/knot/knot-resolver)
|
||||||
|
|
||||||
|
Opening a merge request on gitlab.nic.cz
|
||||||
|
----------------------------------------
|
||||||
|
|
||||||
|
Unfortunately, due to administrative policy, forking is disabled by default. To
|
||||||
|
be able to fork, please send us an e-mail with your username to knot-resolver@labs.nic.cz
|
||||||
|
|
||||||
|
We apologize for the inconvenience and if you can't be bothered, please
|
||||||
|
consider alternate ways of contributing, such as:
|
||||||
|
|
||||||
|
- Opening a pull request on [github.com](https://github.com/CZ-NIC/knot-resolver).
|
||||||
|
We'll take care of it and move it to our upstream.
|
||||||
|
- Sending a patch to the users list: knot-resolver-users@lists.nic.cz
|
695
COPYING
Normal file
695
COPYING
Normal file
|
@ -0,0 +1,695 @@
|
||||||
|
Unless specifically indicated otherwise in a file or directory,
|
||||||
|
files are licensed under GNU GPL license either version 3, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
SPDX-URL: https://spdx.org/licenses/GPL-3.0-or-later.html
|
||||||
|
License-Text:
|
||||||
|
|
||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<https://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||||
|
|
||||||
|
In addition, as a special exception, the copyright holders give
|
||||||
|
permission to link the code of portions of this program with the
|
||||||
|
OpenSSL library under certain conditions as described in each
|
||||||
|
individual source file, and distribute linked combinations including
|
||||||
|
the two.
|
||||||
|
You must obey the GNU General Public License in all respects for all
|
||||||
|
of the code used other than OpenSSL. If you modify file(s) with this
|
||||||
|
exception, you may extend this exception to your version of the
|
||||||
|
file(s), but you are not obligated to do so. If you do not wish to do
|
||||||
|
so, delete this exception statement from your version. If you delete
|
||||||
|
this exception statement from all source files in the program, then
|
||||||
|
also delete it here.
|
5
CodingStyle
Normal file
5
CodingStyle
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# Style
|
||||||
|
|
||||||
|
Linux kernel [coding style][lkstyle], same practices for API documentation.
|
||||||
|
|
||||||
|
[lkstyle]: https://www.kernel.org/doc/Documentation/process/coding-style.rst
|
78
Dockerfile
Normal file
78
Dockerfile
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
# Intermediate container for Knot DNS build (not persistent)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
FROM debian:12 AS knot-dns-build
|
||||||
|
ARG KNOT_DNS_VERSION=v3.2.9
|
||||||
|
|
||||||
|
# Build dependencies
|
||||||
|
ENV KNOT_DNS_BUILD_DEPS git-core build-essential libtool autoconf pkg-config \
|
||||||
|
libgnutls28-dev libprotobuf-dev libprotobuf-c-dev libfstrm-dev
|
||||||
|
ENV KNOT_RESOLVER_BUILD_DEPS build-essential pkg-config bsdmainutils liblmdb-dev \
|
||||||
|
libluajit-5.1-dev libuv1-dev libprotobuf-dev libprotobuf-c-dev \
|
||||||
|
libfstrm-dev luajit lua-http libssl-dev libnghttp2-dev protobuf-c-compiler \
|
||||||
|
meson
|
||||||
|
ENV BUILDENV_DEPS ${KNOT_DNS_BUILD_DEPS} ${KNOT_RESOLVER_BUILD_DEPS}
|
||||||
|
RUN apt-get update -qq && \
|
||||||
|
apt-get -y -qqq install ${BUILDENV_DEPS}
|
||||||
|
|
||||||
|
# Install Knot DNS from sources
|
||||||
|
RUN git clone -b $KNOT_DNS_VERSION --depth=1 https://gitlab.nic.cz/knot/knot-dns.git /tmp/knot-dns && \
|
||||||
|
cd /tmp/knot-dns && \
|
||||||
|
autoreconf -if && \
|
||||||
|
./configure --disable-static --disable-fastparser --disable-documentation \
|
||||||
|
--disable-daemon --disable-utilities --with-lmdb=no && \
|
||||||
|
make -j4 install && \
|
||||||
|
ldconfig
|
||||||
|
|
||||||
|
# Copy libknot, libdnssec, libzscanner to runtime
|
||||||
|
RUN mkdir -p /tmp/root/usr/local/include /tmp/root/usr/local/lib /tmp/root/usr/local/lib/pkgconfig && \
|
||||||
|
cp -rt /tmp/root/usr/local/include /usr/local/include/libknot /usr/local/include/libdnssec /usr/local/include/libzscanner && \
|
||||||
|
cp -rt /tmp/root/usr/local/lib /usr/local/lib/libknot* /usr/local/lib/libdnssec* /usr/local/lib/libzscanner* && \
|
||||||
|
cp -rt /tmp/root/usr/local/lib/pkgconfig /usr/local/lib/pkgconfig/libknot.pc /usr/local/lib/pkgconfig/libdnssec.pc /usr/local/lib/pkgconfig/libzscanner.pc
|
||||||
|
|
||||||
|
|
||||||
|
# Intermediate container with runtime dependencies
|
||||||
|
FROM debian:12-slim AS runtime
|
||||||
|
|
||||||
|
# Install runtime dependencies
|
||||||
|
ENV KNOT_DNS_RUNTIME_DEPS libgnutls30
|
||||||
|
ENV KNOT_RESOLVER_RUNTIME_DEPS liblmdb0 luajit libluajit-5.1-2 libuv1 lua-http libnghttp2-14
|
||||||
|
ENV KNOT_RESOLVER_RUNTIME_DEPS_HTTP lua-http lua-mmdb
|
||||||
|
ENV KNOT_RESOLVER_RUNTIME_DEPS_EXTRA lua-cqueues
|
||||||
|
ENV KNOT_RESOLVER_RUNTIME_DEPS_DNSTAP libfstrm0 libprotobuf-c1
|
||||||
|
ENV KNOT_RESOLVER_RUNTIME_DEPS_SSL ca-certificates
|
||||||
|
ENV RUNTIME_DEPS ${KNOT_DNS_RUNTIME_DEPS} ${KNOT_RESOLVER_RUNTIME_DEPS} \
|
||||||
|
${KNOT_RESOLVER_RUNTIME_DEPS_HTTP} ${KNOT_RESOLVER_RUNTIME_DEPS_EXTRA} \
|
||||||
|
${KNOT_RESOLVER_RUNTIME_DEPS_SSL} ${KNOT_RESOLVER_RUNTIME_DEPS_DNSTAP}
|
||||||
|
RUN apt-get update -qq && \
|
||||||
|
apt-get install -y -qqq ${RUNTIME_DEPS} && \
|
||||||
|
apt-get clean && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
|
||||||
|
# Intermediate container for Knot Resolver build
|
||||||
|
FROM knot-dns-build AS build
|
||||||
|
|
||||||
|
# Get Knot Resolver code from current directory
|
||||||
|
COPY . /tmp/knot-resolver
|
||||||
|
|
||||||
|
# Build Knot Resolver
|
||||||
|
RUN cd /tmp/knot-resolver && \
|
||||||
|
meson build_docker --buildtype=plain --prefix=/usr --libdir=lib -Dc_args="-O2 -fstack-protector -g" && \
|
||||||
|
DESTDIR=/tmp/root ninja -C build_docker install && \
|
||||||
|
cp /tmp/root/usr/share/doc/knot-resolver/examples/config.docker /tmp/root/etc/knot-resolver/kresd.conf
|
||||||
|
|
||||||
|
|
||||||
|
# Final container
|
||||||
|
FROM runtime
|
||||||
|
LABEL cz.knot-resolver.vendor="CZ.NIC"
|
||||||
|
LABEL maintainer="knot-resolver-users@lists.nic.cz"
|
||||||
|
|
||||||
|
# Export DNS over UDP & TCP, DNS-over-HTTPS, DNS-over-TLS, web interface
|
||||||
|
EXPOSE 53/UDP 53/TCP 443/TCP 853/TCP 8453/TCP
|
||||||
|
|
||||||
|
# Fetch Knot Resolver + Knot DNS libraries from build image
|
||||||
|
COPY --from=build /tmp/root/ /
|
||||||
|
RUN ldconfig
|
||||||
|
|
||||||
|
ENTRYPOINT ["/usr/sbin/kresd"]
|
||||||
|
CMD ["-c", "/etc/knot-resolver/kresd.conf"]
|
75
README.md
Normal file
75
README.md
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
# Knot Resolver
|
||||||
|
|
||||||
|
[](https://gitlab.nic.cz/knot/knot-resolver/commits/nightly)
|
||||||
|
[](https://knot.pages.nic.cz/knot-resolver/)
|
||||||
|
[](https://readthedocs.org/projects/knot-resolver/?badge=latest)
|
||||||
|
[](https://repology.org/project/knot-resolver/versions)
|
||||||
|
|
||||||
|
Knot Resolver is a caching full resolver implementation written in C and [LuaJIT][luajit], both a resolver library and a daemon. The core architecture is tiny and efficient, and provides a foundation and
|
||||||
|
a state-machine like API for extensions. There are three modules built-in - *iterator*, *validator*, *cache*, and a few more are loaded by default. Most of the [rich features](https://knot-resolver.readthedocs.io/en/latest/config-overview.html) are written in Lua(JIT) and C. Batteries are included, but optional.
|
||||||
|
|
||||||
|
The LuaJIT modules, support DNS privacy and DNSSEC, and persistent cache with low memory footprint make it a great personal DNS resolver or a research tool to tap into DNS data. TL;DR it's the [OpenResty][openresty] of DNS.
|
||||||
|
|
||||||
|
Strong filtering rules, and auto-configuration with etcd make it a great large-scale resolver solution.
|
||||||
|
|
||||||
|
The server adopts a [different scaling strategy][scaling] than the rest of the DNS recursors - no threading, shared-nothing architecture (except MVCC cache that may be shared) that allows you to pin instances on available CPU cores and grow by self-replication. You can start and stop additional nodes depending on the contention without downtime.
|
||||||
|
|
||||||
|
It also has strong support for DNS over TCP, notably TCP Fast-Open, query pipelining and deduplication, and response reordering.
|
||||||
|
|
||||||
|
### Packages
|
||||||
|
|
||||||
|
The latest stable packages for various distributions are available in our
|
||||||
|
[upstream repository](https://build.opensuse.org/package/show/home:CZ-NIC:knot-resolver-latest/knot-resolver).
|
||||||
|
Follow the
|
||||||
|
[installation instructions](https://software.opensuse.org//download.html?project=home%3ACZ-NIC%3Aknot-resolver-latest&package=knot-resolver)
|
||||||
|
to add this repository to your system.
|
||||||
|
|
||||||
|
Knot Resolver is also available from the following distributions' repositories.
|
||||||
|
|
||||||
|
* [Fedora and Fedora EPEL](https://src.fedoraproject.org/rpms/knot-resolver)
|
||||||
|
* [Debian stable](https://packages.debian.org/stable/knot-resolver),
|
||||||
|
[Debian testing](https://packages.debian.org/testing/knot-resolver),
|
||||||
|
[Debian unstable](https://packages.debian.org/sid/knot-resolver)
|
||||||
|
* [Ubuntu](https://packages.ubuntu.com/jammy/knot-resolver)
|
||||||
|
* [Arch Linux](https://archlinux.org/packages/community/x86_64/knot-resolver/)
|
||||||
|
* [Alpine Linux](https://pkgs.alpinelinux.org/packages?name=knot-resolver)
|
||||||
|
|
||||||
|
### Building from sources
|
||||||
|
|
||||||
|
Knot Resolver mainly [depends][depends] on Knot DNS libraries, [LuaJIT][luajit] and [libuv][libuv].
|
||||||
|
See the [Building project][depends] documentation page for more information.
|
||||||
|
|
||||||
|
### Docker image
|
||||||
|
|
||||||
|
This is simple and doesn't require any dependencies or system modifications, just run:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ docker run -Pit cznic/knot-resolver
|
||||||
|
```
|
||||||
|
|
||||||
|
The images are meant as an easy way to try knot-resolver, and they're not designed for production use.
|
||||||
|
|
||||||
|
### Running
|
||||||
|
|
||||||
|
The project builds a resolver library in the `lib` directory, and a daemon in the `daemon` directory. It requires no configuration or parameters to run a server on localhost.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ kresd
|
||||||
|
```
|
||||||
|
|
||||||
|
See the documentation at [knot-resolver.readthedocs.io][doc] for more options.
|
||||||
|
|
||||||
|
[depends]: https://knot-resolver.readthedocs.io/en/stable/build.html
|
||||||
|
[doc]: https://knot-resolver.readthedocs.io/en/stable/index.html
|
||||||
|
[scaling]: https://knot-resolver.readthedocs.io/en/stable/systemd-multiinst.html
|
||||||
|
[deckard]: https://gitlab.nic.cz/knot/deckard
|
||||||
|
[luajit]: https://luajit.org/
|
||||||
|
[libuv]: http://libuv.org
|
||||||
|
[openresty]: https://openresty.org/
|
||||||
|
|
||||||
|
### Contacting us
|
||||||
|
|
||||||
|
- [GitLab issues](https://gitlab.nic.cz/knot/knot-resolver/issues) (you may authenticate via GitHub)
|
||||||
|
- [mailing list](https://lists.nic.cz/postorius/lists/knot-resolver-announce.lists.nic.cz/)
|
||||||
|
- [](https://gitter.im/CZ-NIC/knot-resolver?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||||
|
|
242
bench/bench_lru.c
Normal file
242
bench/bench_lru.c
Normal file
|
@ -0,0 +1,242 @@
|
||||||
|
/* Copyright (C) CZ.NIC, z.s.p.o. <knot-resolver@labs.nic.cz>
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "contrib/ucw/lib.h"
|
||||||
|
#include "daemon/engine.h"
|
||||||
|
#include "lib/selection.h"
|
||||||
|
|
||||||
|
typedef lru_t(unsigned) lru_bench_t;
|
||||||
|
|
||||||
|
#define p_out(...) do { \
|
||||||
|
printf(__VA_ARGS__); \
|
||||||
|
(void)fflush(stdout); \
|
||||||
|
} while (0)
|
||||||
|
#define p_err(...) ((void)fprintf(stderr, __VA_ARGS__))
|
||||||
|
|
||||||
|
#ifndef LRU_RTT_SIZE
|
||||||
|
#define LRU_RTT_SIZE 65536 /**< NS RTT cache size */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int die(const char *cause)
|
||||||
|
{
|
||||||
|
(void)fprintf(stderr, "%s: %s\n", cause, strerror(errno));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void time_get(struct timeval *tv)
|
||||||
|
{
|
||||||
|
if (gettimeofday(tv, NULL))
|
||||||
|
die("gettimeofday");
|
||||||
|
}
|
||||||
|
static void time_print_diff(struct timeval *tv, size_t op_count)
|
||||||
|
{
|
||||||
|
struct timeval now;
|
||||||
|
time_get(&now);
|
||||||
|
now.tv_sec -= tv->tv_sec;
|
||||||
|
now.tv_usec -= tv->tv_usec;
|
||||||
|
if (now.tv_usec < 0) {
|
||||||
|
now.tv_sec -= 1;
|
||||||
|
now.tv_usec += 1000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t speed = round((double)(op_count) / 1000
|
||||||
|
/ (now.tv_sec + (double)(now.tv_usec)/1000000));
|
||||||
|
|
||||||
|
p_out("%ld.%06d", now.tv_sec, (int)now.tv_usec);
|
||||||
|
p_err(" s"); p_out(","); p_err("\t");
|
||||||
|
p_out("%zd", speed);
|
||||||
|
p_err(" kops/s"); p_out(","); p_err("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// initialize seed for random()
|
||||||
|
static int ssrandom(char *s)
|
||||||
|
{
|
||||||
|
if (*s == '-') { // initialize from time
|
||||||
|
struct timeval now;
|
||||||
|
time_get(&now);
|
||||||
|
srandom(now.tv_sec * 1000000 + now.tv_usec);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// initialize from a string
|
||||||
|
size_t len = strlen(s);
|
||||||
|
if (len < 12)
|
||||||
|
return(-1);
|
||||||
|
unsigned seed = s[0] | s[1] << 8 | s[2] << 16 | s[3] << 24;
|
||||||
|
initstate(seed, s+4, len-4);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct key {
|
||||||
|
size_t len;
|
||||||
|
char *chars;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// read lines from a file and reorder them randomly
|
||||||
|
static struct key * read_lines(const char *fname, size_t *count, char **pfree)
|
||||||
|
{
|
||||||
|
// read the file at once
|
||||||
|
int fd = open(fname, O_RDONLY);
|
||||||
|
if (fd < 0)
|
||||||
|
die("open");
|
||||||
|
struct stat st;
|
||||||
|
if (fstat(fd, &st) < 0)
|
||||||
|
die("stat");
|
||||||
|
size_t flen = (size_t)st.st_size;
|
||||||
|
char *fbuf = malloc(flen + 1);
|
||||||
|
*pfree = fbuf;
|
||||||
|
if (fbuf == NULL)
|
||||||
|
die("malloc");
|
||||||
|
if (read(fd, fbuf, flen) < 0)
|
||||||
|
die("read");
|
||||||
|
close(fd);
|
||||||
|
fbuf[flen] = '\0';
|
||||||
|
|
||||||
|
// get pointers to individual lines
|
||||||
|
size_t lines = 0;
|
||||||
|
for (size_t i = 0; i < flen; ++i)
|
||||||
|
if (fbuf[i] == '\n') {
|
||||||
|
fbuf[i] = 0;
|
||||||
|
++lines;
|
||||||
|
}
|
||||||
|
*count = lines;
|
||||||
|
size_t avg_len = (flen + 1) / lines - 1;
|
||||||
|
|
||||||
|
p_err("lines read: ");
|
||||||
|
p_out("%zu,", lines);
|
||||||
|
p_err("\taverage length ");
|
||||||
|
p_out("%zu,", avg_len);
|
||||||
|
|
||||||
|
struct key *result = calloc(lines, sizeof(struct key));
|
||||||
|
result[0].chars = fbuf;
|
||||||
|
for (size_t l = 0; l < lines; ++l) {
|
||||||
|
size_t i = 0;
|
||||||
|
while (result[l].chars[i])
|
||||||
|
++i;
|
||||||
|
result[l].len = i;
|
||||||
|
if (l + 1 < lines)
|
||||||
|
result[l + 1].chars = result[l].chars + i + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//return result;
|
||||||
|
// reorder the lines randomly (via "random select-sort")
|
||||||
|
// note: this makes their order non-sequential *in memory*
|
||||||
|
if (RAND_MAX < lines)
|
||||||
|
die("RAND_MAX is too small");
|
||||||
|
for (size_t i = 0; i < lines - 1; ++i) { // swap i with random j >= i
|
||||||
|
size_t j = i + random() % (lines - i);
|
||||||
|
if (j != i) {
|
||||||
|
struct key tmp = result[i];
|
||||||
|
result[i] = result[j];
|
||||||
|
result[j] = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// compatibility layer for the older lru_* names
|
||||||
|
#ifndef lru_create
|
||||||
|
#define lru_get_new lru_set
|
||||||
|
#define lru_get_try lru_get
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void usage(const char *progname)
|
||||||
|
{
|
||||||
|
p_err("usage: %s <log_count> <input> <seed> [lru_size]\n", progname);
|
||||||
|
p_err("The seed must be at least 12 characters or \"-\".\n"
|
||||||
|
"Standard output contains csv-formatted lines.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char ** argv)
|
||||||
|
{
|
||||||
|
if (argc != 4 && argc != 5)
|
||||||
|
usage(argv[0]);
|
||||||
|
if (ssrandom(argv[3]) < 0)
|
||||||
|
usage(argv[0]);
|
||||||
|
|
||||||
|
p_out("\n");
|
||||||
|
size_t key_count;
|
||||||
|
char *data_to_free = NULL;
|
||||||
|
struct key *keys = read_lines(argv[2], &key_count, &data_to_free);
|
||||||
|
size_t run_count;
|
||||||
|
{
|
||||||
|
size_t run_log = atoi(argv[1]); // NOLINT: atoi is fine for this tool...
|
||||||
|
assert(run_log < 64);
|
||||||
|
run_count = 1ULL << run_log;
|
||||||
|
p_err("\ntest run length:\t2^");
|
||||||
|
p_out("%zd,", run_log);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct timeval time;
|
||||||
|
const int lru_size = argc > 4 ? atoi(argv[4]) : LRU_RTT_SIZE; // NOLINT: ditto atoi
|
||||||
|
|
||||||
|
lru_bench_t *lru;
|
||||||
|
#ifdef lru_create
|
||||||
|
lru_create(&lru, lru_size, NULL, NULL);
|
||||||
|
#else
|
||||||
|
lru = malloc(lru_size(lru_bench_t, lru_size));
|
||||||
|
if (lru)
|
||||||
|
lru_init(lru, lru_size);
|
||||||
|
#endif
|
||||||
|
if (!lru)
|
||||||
|
die("malloc");
|
||||||
|
p_err("\nLRU capacity:\t");
|
||||||
|
p_out("%d,",
|
||||||
|
#ifdef lru_capacity
|
||||||
|
lru_capacity(lru) // report real capacity, if provided
|
||||||
|
#else
|
||||||
|
lru_size
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
|
size_t miss = 0;
|
||||||
|
p_err("\nload everything:\t");
|
||||||
|
time_get(&time);
|
||||||
|
for (size_t i = 0, ki = key_count - 1; i < run_count; ++i, --ki) {
|
||||||
|
unsigned *r = lru_get_new(lru, keys[ki].chars, keys[ki].len, NULL);
|
||||||
|
if (!r || *r == 0)
|
||||||
|
++miss;
|
||||||
|
if (r)
|
||||||
|
*r = 1;
|
||||||
|
if (unlikely(ki == 0))
|
||||||
|
ki = key_count;
|
||||||
|
}
|
||||||
|
time_print_diff(&time, run_count);
|
||||||
|
p_err("LRU misses [%%]:\t");
|
||||||
|
p_out("%zd,",(miss * 100 + 50) / run_count);
|
||||||
|
p_err("\n");
|
||||||
|
|
||||||
|
unsigned accum = 0; // compute something to make sure compiler can't remove code
|
||||||
|
p_err("search everything:\t");
|
||||||
|
time_get(&time);
|
||||||
|
for (size_t i = 0, ki = key_count - 1; i < run_count; ++i, --ki) {
|
||||||
|
unsigned *r = lru_get_try(lru, keys[ki].chars, keys[ki].len);
|
||||||
|
if (r)
|
||||||
|
accum += *r;
|
||||||
|
if (unlikely(ki == 0))
|
||||||
|
ki = key_count;
|
||||||
|
}
|
||||||
|
time_print_diff(&time, run_count);
|
||||||
|
p_err("ignore: %u\n", accum);
|
||||||
|
|
||||||
|
// free memory, at least with new LRU
|
||||||
|
#ifdef lru_create
|
||||||
|
lru_free(lru);
|
||||||
|
#endif
|
||||||
|
free(keys);
|
||||||
|
free(data_to_free);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
65536
bench/bench_lru_set1.tsv
Normal file
65536
bench/bench_lru_set1.tsv
Normal file
File diff suppressed because it is too large
Load diff
24
bench/meson.build
Normal file
24
bench/meson.build
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# bench
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
bench_lru_src = files([
|
||||||
|
'bench_lru.c',
|
||||||
|
])
|
||||||
|
|
||||||
|
cc = meson.get_compiler('c')
|
||||||
|
m_dep = cc.find_library('m', required : false)
|
||||||
|
|
||||||
|
bench_lru = executable(
|
||||||
|
'bench_lru',
|
||||||
|
bench_lru_src,
|
||||||
|
dependencies: [
|
||||||
|
contrib_dep,
|
||||||
|
libkres_dep,
|
||||||
|
m_dep,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
run_target(
|
||||||
|
'bench',
|
||||||
|
command: '../scripts/bench.sh',
|
||||||
|
)
|
13
ci/deckard_commit_check.sh
Executable file
13
ci/deckard_commit_check.sh
Executable file
|
@ -0,0 +1,13 @@
|
||||||
|
DECKARD_COMMIT=$(git ls-tree HEAD:tests/integration/ | grep commit | grep deckard | cut -f1 | cut -f3 '-d ')
|
||||||
|
DECKARD_PATH="tests/integration/deckard"
|
||||||
|
pushd $DECKARD_PATH > /dev/null
|
||||||
|
if git merge-base --is-ancestor $DECKARD_COMMIT origin/master; then
|
||||||
|
echo "Deckard submodule commit is on in its master branch. All good in the hood."
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "Deckard submodule commit $DECKARD_COMMIT is not in Deckard's master branch."
|
||||||
|
echo "This WILL cause CI breakages so make sure your changes in Deckard are merged"
|
||||||
|
echo "or point the submodule to another commit."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
5
ci/fix-meson-junit.sh
Executable file
5
ci/fix-meson-junit.sh
Executable file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/sh
|
||||||
|
sed 's|</testcase>|</testcase>\n|g' -i "$@"
|
||||||
|
sed -e '/<failure \/>/,/<\/testcase>/s/<\(\/\?\)system-\(out\|err\)>/<\1failure>/g' \
|
||||||
|
-e 's/<failure \/>//g' \
|
||||||
|
-i "$@"
|
59
ci/gh_actions.py
Executable file
59
ci/gh_actions.py
Executable file
|
@ -0,0 +1,59 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
BRANCH_API_ENDPOINT = "https://api.github.com/repos/CZ-NIC/knot-resolver/actions/runs?branch={branch}" # noqa
|
||||||
|
TIMEOUT = 20*60 # 20 mins max
|
||||||
|
POLL_DELAY = 60
|
||||||
|
SYNC_TIMEOUT = 10*60
|
||||||
|
|
||||||
|
|
||||||
|
def exit(msg='', html_url='', code=1):
|
||||||
|
print(msg, file=sys.stderr)
|
||||||
|
print(html_url)
|
||||||
|
sys.exit(code)
|
||||||
|
|
||||||
|
|
||||||
|
end_time = time.time() + TIMEOUT
|
||||||
|
sync_timeout = time.time() + SYNC_TIMEOUT
|
||||||
|
while time.time() < end_time:
|
||||||
|
response = requests.get(
|
||||||
|
BRANCH_API_ENDPOINT.format(branch=sys.argv[1]),
|
||||||
|
headers={"Accept": "application/vnd.github.v3+json"})
|
||||||
|
if response.status_code == 404:
|
||||||
|
pass # not created yet?
|
||||||
|
elif response.status_code == 200:
|
||||||
|
data = json.loads(response.content.decode('utf-8'))
|
||||||
|
try:
|
||||||
|
for i in range(0, 1): # two runs ATM
|
||||||
|
run = data['workflow_runs'][i]
|
||||||
|
conclusion = run['conclusion']
|
||||||
|
html_url = run['html_url']
|
||||||
|
commit_sha = run['head_sha']
|
||||||
|
except (KeyError, IndexError):
|
||||||
|
time.sleep(POLL_DELAY)
|
||||||
|
continue
|
||||||
|
|
||||||
|
if commit_sha != sys.argv[2]:
|
||||||
|
if time.time() < sync_timeout:
|
||||||
|
time.sleep(POLL_DELAY)
|
||||||
|
continue
|
||||||
|
exit("Fetched invalid GH Action: commit mismatch. Re-run or push again?")
|
||||||
|
|
||||||
|
if conclusion is None:
|
||||||
|
pass
|
||||||
|
if conclusion == "success":
|
||||||
|
exit("SUCCESS!", html_url, code=0)
|
||||||
|
elif isinstance(conclusion, str):
|
||||||
|
# failure, neutral, cancelled, skipped, timed_out, or action_required
|
||||||
|
exit("GitHub Actions Conclusion: {}!".format(conclusion.upper()), html_url)
|
||||||
|
else:
|
||||||
|
exit("API Response Code: {}".format(response.status_code), code=2)
|
||||||
|
time.sleep(POLL_DELAY)
|
||||||
|
|
||||||
|
exit("Timed out!")
|
3
ci/no_assert_check.sh
Executable file
3
ci/no_assert_check.sh
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
grep '\<assert\>' -- $(git ls-files | grep '\.[hc]$' | grep -vE '^(contrib|bench|tests)/')
|
||||||
|
test $? -eq 1
|
26
ci/respdiff/kresd.config
Normal file
26
ci/respdiff/kresd.config
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
-- SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
-- Refer to manual: https://knot-resolver.readthedocs.io/en/stable/
|
||||||
|
-- Listen on localhost and external interface
|
||||||
|
net.listen('127.0.0.1', 5353)
|
||||||
|
net.listen('127.0.0.1', 8853, { tls = true })
|
||||||
|
net.ipv6=false
|
||||||
|
|
||||||
|
-- Auto-maintain root TA
|
||||||
|
trust_anchors.add_file('.local/etc/knot-resolver/root.keys')
|
||||||
|
|
||||||
|
cache.size = 1024 * MB
|
||||||
|
|
||||||
|
-- Load Useful modules
|
||||||
|
modules = {
|
||||||
|
'workarounds < iterate',
|
||||||
|
'policy', -- Block queries to local zones/bad sites
|
||||||
|
'view', -- Views for certain clients
|
||||||
|
'hints > iterate', -- Allow loading /etc/hosts or custom root hints
|
||||||
|
'stats', -- Track internal statistics
|
||||||
|
}
|
||||||
|
|
||||||
|
-- avoid TC flags returned to respdiff
|
||||||
|
local _, up_bs = net.bufsize()
|
||||||
|
net.bufsize(4096, up_bs)
|
||||||
|
|
||||||
|
log_level('debug')
|
52
ci/respdiff/respdiff-tcp.conf
Normal file
52
ci/respdiff/respdiff-tcp.conf
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
[sendrecv]
|
||||||
|
# in seconds
|
||||||
|
timeout = 11
|
||||||
|
# number of queries to run simultaneously
|
||||||
|
jobs = 64
|
||||||
|
# in seconds (float); delay each query by a random time (uniformly distributed) between min and max; set max to 0 to disable
|
||||||
|
time_delay_min = 0
|
||||||
|
time_delay_max = 0
|
||||||
|
|
||||||
|
[servers]
|
||||||
|
names = kresd, bind, unbound
|
||||||
|
# symbolic names of DNS servers under test
|
||||||
|
# separate multiple values by ,
|
||||||
|
|
||||||
|
# each symbolic name in [servers] section refers to config section
|
||||||
|
# containing IP address and port of particular server
|
||||||
|
[kresd]
|
||||||
|
ip = 127.0.0.1
|
||||||
|
port = 5353
|
||||||
|
transport = tcp
|
||||||
|
graph_color = #00a2e2
|
||||||
|
restart_script = ./ci/respdiff/restart-kresd.sh
|
||||||
|
|
||||||
|
[bind]
|
||||||
|
ip = 127.0.0.1
|
||||||
|
port = 53533
|
||||||
|
transport = udp
|
||||||
|
graph_color = #e2a000
|
||||||
|
restart_script = ./ci/respdiff/restart-bind.sh
|
||||||
|
|
||||||
|
[unbound]
|
||||||
|
ip = 127.0.0.1
|
||||||
|
port = 53535
|
||||||
|
transport = udp
|
||||||
|
graph_color = #218669
|
||||||
|
restart_script = ./ci/respdiff/restart-unbound.sh
|
||||||
|
|
||||||
|
[diff]
|
||||||
|
# symbolic name of server under test
|
||||||
|
# other servers are used as reference when comparing answers from the target
|
||||||
|
target = kresd
|
||||||
|
|
||||||
|
# fields and comparison methods used when comparing two DNS messages
|
||||||
|
criteria = opcode, rcode, flags, question, answertypes, answerrrsigs
|
||||||
|
# other supported criteria values: authority, additional, edns, nsid
|
||||||
|
|
||||||
|
[report]
|
||||||
|
# diffsum reports mismatches in field values in this order
|
||||||
|
# if particular message has multiple mismatches, it is counted only once into category with highest weight
|
||||||
|
field_weights = timeout, malformed, opcode, question, rcode, flags, answertypes, answerrrsigs, answer, authority, additional, edns, nsid
|
52
ci/respdiff/respdiff-tls.conf
Normal file
52
ci/respdiff/respdiff-tls.conf
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
[sendrecv]
|
||||||
|
# in seconds
|
||||||
|
timeout = 11
|
||||||
|
# number of queries to run simultaneously
|
||||||
|
jobs = 64
|
||||||
|
# in seconds (float); delay each query by a random time (uniformly distributed) between min and max; set max to 0 to disable
|
||||||
|
time_delay_min = 0
|
||||||
|
time_delay_max = 0
|
||||||
|
|
||||||
|
[servers]
|
||||||
|
names = kresd, bind, unbound
|
||||||
|
# symbolic names of DNS servers under test
|
||||||
|
# separate multiple values by ,
|
||||||
|
|
||||||
|
# each symbolic name in [servers] section refers to config section
|
||||||
|
# containing IP address and port of particular server
|
||||||
|
[kresd]
|
||||||
|
ip = 127.0.0.1
|
||||||
|
port = 8853
|
||||||
|
transport = tls
|
||||||
|
graph_color = #00a2e2
|
||||||
|
restart_script = ./ci/respdiff/restart-kresd.sh
|
||||||
|
|
||||||
|
[bind]
|
||||||
|
ip = 127.0.0.1
|
||||||
|
port = 53533
|
||||||
|
transport = udp
|
||||||
|
graph_color = #e2a000
|
||||||
|
restart_script = ./ci/respdiff/restart-bind.sh
|
||||||
|
|
||||||
|
[unbound]
|
||||||
|
ip = 127.0.0.1
|
||||||
|
port = 53535
|
||||||
|
transport = udp
|
||||||
|
graph_color = #218669
|
||||||
|
restart_script = ./ci/respdiff/restart-unbound.sh
|
||||||
|
|
||||||
|
[diff]
|
||||||
|
# symbolic name of server under test
|
||||||
|
# other servers are used as reference when comparing answers from the target
|
||||||
|
target = kresd
|
||||||
|
|
||||||
|
# fields and comparison methods used when comparing two DNS messages
|
||||||
|
criteria = opcode, rcode, flags, question, answertypes, answerrrsigs
|
||||||
|
# other supported criteria values: authority, additional, edns, nsid
|
||||||
|
|
||||||
|
[report]
|
||||||
|
# diffsum reports mismatches in field values in this order
|
||||||
|
# if particular message has multiple mismatches, it is counted only once into category with highest weight
|
||||||
|
field_weights = timeout, malformed, opcode, question, rcode, flags, answertypes, answerrrsigs, answer, authority, additional, edns, nsid
|
52
ci/respdiff/respdiff-udp.conf
Normal file
52
ci/respdiff/respdiff-udp.conf
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
[sendrecv]
|
||||||
|
# in seconds
|
||||||
|
timeout = 11
|
||||||
|
# number of queries to run simultaneously
|
||||||
|
jobs = 64
|
||||||
|
# in seconds (float); delay each query by a random time (uniformly distributed) between min and max; set max to 0 to disable
|
||||||
|
time_delay_min = 0
|
||||||
|
time_delay_max = 0
|
||||||
|
|
||||||
|
[servers]
|
||||||
|
names = kresd, bind, unbound
|
||||||
|
# symbolic names of DNS servers under test
|
||||||
|
# separate multiple values by ,
|
||||||
|
|
||||||
|
# each symbolic name in [servers] section refers to config section
|
||||||
|
# containing IP address and port of particular server
|
||||||
|
[kresd]
|
||||||
|
ip = 127.0.0.1
|
||||||
|
port = 5353
|
||||||
|
transport = udp
|
||||||
|
graph_color = #00a2e2
|
||||||
|
restart_script = ./ci/respdiff/restart-kresd.sh
|
||||||
|
|
||||||
|
[bind]
|
||||||
|
ip = 127.0.0.1
|
||||||
|
port = 53533
|
||||||
|
transport = udp
|
||||||
|
graph_color = #e2a000
|
||||||
|
restart_script = ./ci/respdiff/restart-bind.sh
|
||||||
|
|
||||||
|
[unbound]
|
||||||
|
ip = 127.0.0.1
|
||||||
|
port = 53535
|
||||||
|
transport = udp
|
||||||
|
graph_color = #218669
|
||||||
|
restart_script = ./ci/respdiff/restart-unbound.sh
|
||||||
|
|
||||||
|
[diff]
|
||||||
|
# symbolic name of server under test
|
||||||
|
# other servers are used as reference when comparing answers from the target
|
||||||
|
target = kresd
|
||||||
|
|
||||||
|
# fields and comparison methods used when comparing two DNS messages
|
||||||
|
criteria = opcode, rcode, flags, question, answertypes, answerrrsigs
|
||||||
|
# other supported criteria values: authority, additional, edns, nsid
|
||||||
|
|
||||||
|
[report]
|
||||||
|
# diffsum reports mismatches in field values in this order
|
||||||
|
# if particular message has multiple mismatches, it is counted only once into category with highest weight
|
||||||
|
field_weights = timeout, malformed, opcode, question, rcode, flags, answertypes, answerrrsigs, answer, authority, additional, edns, nsid
|
3
ci/respdiff/restart-bind.sh
Executable file
3
ci/respdiff/restart-bind.sh
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
service named restart
|
12
ci/respdiff/restart-kresd.sh
Executable file
12
ci/respdiff/restart-kresd.sh
Executable file
|
@ -0,0 +1,12 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
exec > /dev/null
|
||||||
|
exec 2>&1
|
||||||
|
|
||||||
|
killall -w kresd
|
||||||
|
rm -f '*.mdb'
|
||||||
|
$PREFIX/sbin/kresd -n -q -c $(pwd)/ci/respdiff/kresd.config &>>kresd.log &
|
||||||
|
|
||||||
|
# wait until socket is receiving connections
|
||||||
|
sleep 1
|
4
ci/respdiff/restart-unbound.sh
Executable file
4
ci/respdiff/restart-unbound.sh
Executable file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
service unbound restart
|
27
ci/respdiff/run-respdiff-tests.sh
Executable file
27
ci/respdiff/run-respdiff-tests.sh
Executable file
|
@ -0,0 +1,27 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# $1 == udp/tcp/tls, it selects configuration file to use
|
||||||
|
# respdiff scripts must be present in /var/opt/respdiff
|
||||||
|
set -o errexit -o nounset -o xtrace
|
||||||
|
|
||||||
|
NDIFFREPRO=3
|
||||||
|
|
||||||
|
wget -qO- https://gitlab.nic.cz/knot/respdiff/snippets/238/raw?inline=false | head -n 5000 > /tmp/queries.txt
|
||||||
|
mkdir results
|
||||||
|
rm -rf respdiff.db
|
||||||
|
|
||||||
|
CONFIG="$(pwd)/ci/respdiff/respdiff-${1}.conf"
|
||||||
|
/var/opt/respdiff/qprep.py respdiff.db < /tmp/queries.txt
|
||||||
|
time /var/opt/respdiff/orchestrator.py respdiff.db -c "${CONFIG}"
|
||||||
|
time /var/opt/respdiff/msgdiff.py respdiff.db -c "${CONFIG}"
|
||||||
|
for i in $(seq $NDIFFREPRO); do
|
||||||
|
time /var/opt/respdiff/diffrepro.py -c "${CONFIG}" respdiff.db
|
||||||
|
done
|
||||||
|
/var/opt/respdiff/diffsum.py respdiff.db -c "${CONFIG}" > results/respdiff.txt
|
||||||
|
/var/opt/respdiff/histogram.py respdiff.db -c "${CONFIG}" -o results/histogram.svg
|
||||||
|
: minimize LMDB and log size so they can be effectively archived
|
||||||
|
mkdir results/respdiff.db
|
||||||
|
mdb_copy -c respdiff.db results/respdiff.db
|
||||||
|
xz -9 results/respdiff.db/data.mdb
|
||||||
|
xz kresd.log
|
13
ci/respdiff/start-resolvers.sh
Executable file
13
ci/respdiff/start-resolvers.sh
Executable file
|
@ -0,0 +1,13 @@
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
#run unbound
|
||||||
|
service unbound start && service unbound status;
|
||||||
|
# dig @localhost -p 53535
|
||||||
|
|
||||||
|
#run bind
|
||||||
|
service named start && service named status;
|
||||||
|
# dig @localhost -p 53533
|
||||||
|
|
||||||
|
#run kresd
|
||||||
|
$PREFIX/sbin/kresd -n -q -c $(pwd)/ci/respdiff/kresd.config &>kresd.log &
|
||||||
|
# dig @localhost -p 5353
|
5
client/.packaging/test.sh
Executable file
5
client/.packaging/test.sh
Executable file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
test -e sbin/kresc
|
||||||
|
sbin/kresc # command will fail because of invalid parameters
|
||||||
|
test "$?" -eq 1 # linker error would have different exit code
|
277
contrib/base32hex.c
Normal file
277
contrib/base32hex.c
Normal file
|
@ -0,0 +1,277 @@
|
||||||
|
/* Copyright (C) CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "base32hex.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/*! \brief Maximal length of binary input to Base32hex encoding. */
|
||||||
|
#define MAX_BIN_DATA_LEN ((INT32_MAX / 8) * 5)
|
||||||
|
|
||||||
|
/*! \brief Base32hex padding character. */
|
||||||
|
static const uint8_t base32hex_pad = '=';
|
||||||
|
/*! \brief Base32hex alphabet. Beware: original code was upper-case. */
|
||||||
|
static const uint8_t base32hex_enc[] = "0123456789abcdefghijklmnopqrstuv";
|
||||||
|
|
||||||
|
/*! \brief Indicates bad Base32hex character. */
|
||||||
|
#define KO 255
|
||||||
|
/*! \brief Indicates Base32hex padding character. */
|
||||||
|
#define PD 32
|
||||||
|
|
||||||
|
/*! \brief Transformation and validation table for decoding Base32hex. */
|
||||||
|
static const uint8_t base32hex_dec[256] = {
|
||||||
|
[ 0] = KO, [ 43] = KO, ['V'] = 31, [129] = KO, [172] = KO, [215] = KO,
|
||||||
|
[ 1] = KO, [ 44] = KO, ['W'] = KO, [130] = KO, [173] = KO, [216] = KO,
|
||||||
|
[ 2] = KO, [ 45] = KO, ['X'] = KO, [131] = KO, [174] = KO, [217] = KO,
|
||||||
|
[ 3] = KO, [ 46] = KO, ['Y'] = KO, [132] = KO, [175] = KO, [218] = KO,
|
||||||
|
[ 4] = KO, [ 47] = KO, ['Z'] = KO, [133] = KO, [176] = KO, [219] = KO,
|
||||||
|
[ 5] = KO, ['0'] = 0, [ 91] = KO, [134] = KO, [177] = KO, [220] = KO,
|
||||||
|
[ 6] = KO, ['1'] = 1, [ 92] = KO, [135] = KO, [178] = KO, [221] = KO,
|
||||||
|
[ 7] = KO, ['2'] = 2, [ 93] = KO, [136] = KO, [179] = KO, [222] = KO,
|
||||||
|
[ 8] = KO, ['3'] = 3, [ 94] = KO, [137] = KO, [180] = KO, [223] = KO,
|
||||||
|
[ 9] = KO, ['4'] = 4, [ 95] = KO, [138] = KO, [181] = KO, [224] = KO,
|
||||||
|
[ 10] = KO, ['5'] = 5, [ 96] = KO, [139] = KO, [182] = KO, [225] = KO,
|
||||||
|
[ 11] = KO, ['6'] = 6, ['a'] = 10, [140] = KO, [183] = KO, [226] = KO,
|
||||||
|
[ 12] = KO, ['7'] = 7, ['b'] = 11, [141] = KO, [184] = KO, [227] = KO,
|
||||||
|
[ 13] = KO, ['8'] = 8, ['c'] = 12, [142] = KO, [185] = KO, [228] = KO,
|
||||||
|
[ 14] = KO, ['9'] = 9, ['d'] = 13, [143] = KO, [186] = KO, [229] = KO,
|
||||||
|
[ 15] = KO, [ 58] = KO, ['e'] = 14, [144] = KO, [187] = KO, [230] = KO,
|
||||||
|
[ 16] = KO, [ 59] = KO, ['f'] = 15, [145] = KO, [188] = KO, [231] = KO,
|
||||||
|
[ 17] = KO, [ 60] = KO, ['g'] = 16, [146] = KO, [189] = KO, [232] = KO,
|
||||||
|
[ 18] = KO, ['='] = PD, ['h'] = 17, [147] = KO, [190] = KO, [233] = KO,
|
||||||
|
[ 19] = KO, [ 62] = KO, ['i'] = 18, [148] = KO, [191] = KO, [234] = KO,
|
||||||
|
[ 20] = KO, [ 63] = KO, ['j'] = 19, [149] = KO, [192] = KO, [235] = KO,
|
||||||
|
[ 21] = KO, [ 64] = KO, ['k'] = 20, [150] = KO, [193] = KO, [236] = KO,
|
||||||
|
[ 22] = KO, ['A'] = 10, ['l'] = 21, [151] = KO, [194] = KO, [237] = KO,
|
||||||
|
[ 23] = KO, ['B'] = 11, ['m'] = 22, [152] = KO, [195] = KO, [238] = KO,
|
||||||
|
[ 24] = KO, ['C'] = 12, ['n'] = 23, [153] = KO, [196] = KO, [239] = KO,
|
||||||
|
[ 25] = KO, ['D'] = 13, ['o'] = 24, [154] = KO, [197] = KO, [240] = KO,
|
||||||
|
[ 26] = KO, ['E'] = 14, ['p'] = 25, [155] = KO, [198] = KO, [241] = KO,
|
||||||
|
[ 27] = KO, ['F'] = 15, ['q'] = 26, [156] = KO, [199] = KO, [242] = KO,
|
||||||
|
[ 28] = KO, ['G'] = 16, ['r'] = 27, [157] = KO, [200] = KO, [243] = KO,
|
||||||
|
[ 29] = KO, ['H'] = 17, ['s'] = 28, [158] = KO, [201] = KO, [244] = KO,
|
||||||
|
[ 30] = KO, ['I'] = 18, ['t'] = 29, [159] = KO, [202] = KO, [245] = KO,
|
||||||
|
[ 31] = KO, ['J'] = 19, ['u'] = 30, [160] = KO, [203] = KO, [246] = KO,
|
||||||
|
[ 32] = KO, ['K'] = 20, ['v'] = 31, [161] = KO, [204] = KO, [247] = KO,
|
||||||
|
[ 33] = KO, ['L'] = 21, ['w'] = KO, [162] = KO, [205] = KO, [248] = KO,
|
||||||
|
[ 34] = KO, ['M'] = 22, ['x'] = KO, [163] = KO, [206] = KO, [249] = KO,
|
||||||
|
[ 35] = KO, ['N'] = 23, ['y'] = KO, [164] = KO, [207] = KO, [250] = KO,
|
||||||
|
[ 36] = KO, ['O'] = 24, ['z'] = KO, [165] = KO, [208] = KO, [251] = KO,
|
||||||
|
[ 37] = KO, ['P'] = 25, [123] = KO, [166] = KO, [209] = KO, [252] = KO,
|
||||||
|
[ 38] = KO, ['Q'] = 26, [124] = KO, [167] = KO, [210] = KO, [253] = KO,
|
||||||
|
[ 39] = KO, ['R'] = 27, [125] = KO, [168] = KO, [211] = KO, [254] = KO,
|
||||||
|
[ 40] = KO, ['S'] = 28, [126] = KO, [169] = KO, [212] = KO, [255] = KO,
|
||||||
|
[ 41] = KO, ['T'] = 29, [127] = KO, [170] = KO, [213] = KO,
|
||||||
|
[ 42] = KO, ['U'] = 30, [128] = KO, [171] = KO, [214] = KO,
|
||||||
|
};
|
||||||
|
|
||||||
|
int32_t base32hex_decode(const uint8_t *in,
|
||||||
|
const uint32_t in_len,
|
||||||
|
uint8_t *out,
|
||||||
|
const uint32_t out_len)
|
||||||
|
{
|
||||||
|
// Checking inputs.
|
||||||
|
if (in == NULL || out == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (in_len > INT32_MAX || out_len < ((in_len + 7) / 8) * 5) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if ((in_len % 8) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint8_t *stop = in + in_len;
|
||||||
|
uint8_t *bin = out;
|
||||||
|
uint8_t pad_len = 0;
|
||||||
|
uint8_t c1, c2, c3, c4, c5, c6, c7, c8;
|
||||||
|
|
||||||
|
// Decoding loop takes 8 characters and creates 5 bytes.
|
||||||
|
while (in < stop) {
|
||||||
|
// Filling and transforming 8 Base32hex chars.
|
||||||
|
c1 = base32hex_dec[in[0]];
|
||||||
|
c2 = base32hex_dec[in[1]];
|
||||||
|
c3 = base32hex_dec[in[2]];
|
||||||
|
c4 = base32hex_dec[in[3]];
|
||||||
|
c5 = base32hex_dec[in[4]];
|
||||||
|
c6 = base32hex_dec[in[5]];
|
||||||
|
c7 = base32hex_dec[in[6]];
|
||||||
|
c8 = base32hex_dec[in[7]];
|
||||||
|
|
||||||
|
// Check 8. char if is bad or padding.
|
||||||
|
if (c8 >= PD) {
|
||||||
|
if (c8 == PD && pad_len == 0) {
|
||||||
|
pad_len = 1;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check 7. char if is bad or padding (if so, 6. must be too).
|
||||||
|
if (c7 >= PD) {
|
||||||
|
if (c7 == PD && c6 == PD && pad_len == 1) {
|
||||||
|
pad_len = 3;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check 6. char if is bad or padding.
|
||||||
|
if (c6 >= PD) {
|
||||||
|
if (!(c6 == PD && pad_len == 3)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check 5. char if is bad or padding.
|
||||||
|
if (c5 >= PD) {
|
||||||
|
if (c5 == PD && pad_len == 3) {
|
||||||
|
pad_len = 4;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check 4. char if is bad or padding (if so, 3. must be too).
|
||||||
|
if (c4 >= PD) {
|
||||||
|
if (c4 == PD && c3 == PD && pad_len == 4) {
|
||||||
|
pad_len = 6;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check 3. char if is bad or padding.
|
||||||
|
if (c3 >= PD) {
|
||||||
|
if (!(c3 == PD && pad_len == 6)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. and 2. chars must not be padding.
|
||||||
|
if (c2 >= PD || c1 >= PD) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Computing of output data based on padding length.
|
||||||
|
switch (pad_len) {
|
||||||
|
case 0:
|
||||||
|
bin[4] = (c7 << 5) + c8;
|
||||||
|
case 1:
|
||||||
|
bin[3] = (c5 << 7) + (c6 << 2) + (c7 >> 3);
|
||||||
|
case 3:
|
||||||
|
bin[2] = (c4 << 4) + (c5 >> 1);
|
||||||
|
case 4:
|
||||||
|
bin[1] = (c2 << 6) + (c3 << 1) + (c4 >> 4);
|
||||||
|
case 6:
|
||||||
|
bin[0] = (c1 << 3) + (c2 >> 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update output end.
|
||||||
|
switch (pad_len) {
|
||||||
|
case 0:
|
||||||
|
bin += 5;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
bin += 4;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
bin += 3;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
bin += 2;
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
bin += 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
in += 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (bin - out);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t base32hex_encode(const uint8_t *in,
|
||||||
|
const uint32_t in_len,
|
||||||
|
uint8_t *out,
|
||||||
|
const uint32_t out_len)
|
||||||
|
{
|
||||||
|
// Checking inputs.
|
||||||
|
if (in == NULL || out == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (in_len > MAX_BIN_DATA_LEN || out_len < ((in_len + 4) / 5) * 8) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t rest_len = in_len % 5;
|
||||||
|
const uint8_t *stop = in + in_len - rest_len;
|
||||||
|
uint8_t *text = out;
|
||||||
|
|
||||||
|
// Encoding loop takes 5 bytes and creates 8 characters.
|
||||||
|
while (in < stop) {
|
||||||
|
text[0] = base32hex_enc[in[0] >> 3];
|
||||||
|
text[1] = base32hex_enc[(in[0] & 0x07) << 2 | in[1] >> 6];
|
||||||
|
text[2] = base32hex_enc[(in[1] & 0x3E) >> 1];
|
||||||
|
text[3] = base32hex_enc[(in[1] & 0x01) << 4 | in[2] >> 4];
|
||||||
|
text[4] = base32hex_enc[(in[2] & 0x0F) << 1 | in[3] >> 7];
|
||||||
|
text[5] = base32hex_enc[(in[3] & 0x7C) >> 2];
|
||||||
|
text[6] = base32hex_enc[(in[3] & 0x03) << 3 | in[4] >> 5];
|
||||||
|
text[7] = base32hex_enc[in[4] & 0x1F];
|
||||||
|
text += 8;
|
||||||
|
in += 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Processing of padding, if any.
|
||||||
|
switch (rest_len) {
|
||||||
|
case 4:
|
||||||
|
text[0] = base32hex_enc[in[0] >> 3];
|
||||||
|
text[1] = base32hex_enc[(in[0] & 0x07) << 2 | in[1] >> 6];
|
||||||
|
text[2] = base32hex_enc[(in[1] & 0x3E) >> 1];
|
||||||
|
text[3] = base32hex_enc[(in[1] & 0x01) << 4 | in[2] >> 4];
|
||||||
|
text[4] = base32hex_enc[(in[2] & 0x0F) << 1 | in[3] >> 7];
|
||||||
|
text[5] = base32hex_enc[(in[3] & 0x7C) >> 2];
|
||||||
|
text[6] = base32hex_enc[(in[3] & 0x03) << 3];
|
||||||
|
text[7] = base32hex_pad;
|
||||||
|
text += 8;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
text[0] = base32hex_enc[in[0] >> 3];
|
||||||
|
text[1] = base32hex_enc[(in[0] & 0x07) << 2 | in[1] >> 6];
|
||||||
|
text[2] = base32hex_enc[(in[1] & 0x3E) >> 1];
|
||||||
|
text[3] = base32hex_enc[(in[1] & 0x01) << 4 | in[2] >> 4];
|
||||||
|
text[4] = base32hex_enc[(in[2] & 0x0F) << 1];
|
||||||
|
text[5] = base32hex_pad;
|
||||||
|
text[6] = base32hex_pad;
|
||||||
|
text[7] = base32hex_pad;
|
||||||
|
text += 8;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
text[0] = base32hex_enc[in[0] >> 3];
|
||||||
|
text[1] = base32hex_enc[(in[0] & 0x07) << 2 | in[1] >> 6];
|
||||||
|
text[2] = base32hex_enc[(in[1] & 0x3E) >> 1];
|
||||||
|
text[3] = base32hex_enc[(in[1] & 0x01) << 4];
|
||||||
|
text[4] = base32hex_pad;
|
||||||
|
text[5] = base32hex_pad;
|
||||||
|
text[6] = base32hex_pad;
|
||||||
|
text[7] = base32hex_pad;
|
||||||
|
text += 8;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
text[0] = base32hex_enc[in[0] >> 3];
|
||||||
|
text[1] = base32hex_enc[(in[0] & 0x07) << 2];
|
||||||
|
text[2] = base32hex_pad;
|
||||||
|
text[3] = base32hex_pad;
|
||||||
|
text[4] = base32hex_pad;
|
||||||
|
text[5] = base32hex_pad;
|
||||||
|
text[6] = base32hex_pad;
|
||||||
|
text[7] = base32hex_pad;
|
||||||
|
text += 8;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (text - out);
|
||||||
|
}
|
60
contrib/base32hex.h
Normal file
60
contrib/base32hex.h
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
/* Copyright (C) CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
/*!
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief Base32hex implementation (RFC 4648).
|
||||||
|
*
|
||||||
|
* \note Input Base32hex string can contain a-v characters. These characters
|
||||||
|
* are considered as A-V equivalent.
|
||||||
|
*
|
||||||
|
* \addtogroup contrib
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Decodes text data using Base32hex.
|
||||||
|
*
|
||||||
|
* \note Input data needn't be terminated with '\0'.
|
||||||
|
*
|
||||||
|
* \note Input data must be continuous Base32hex string!
|
||||||
|
*
|
||||||
|
* \param in Input text data.
|
||||||
|
* \param in_len Length of input string.
|
||||||
|
* \param out Output data buffer.
|
||||||
|
* \param out_len Size of output buffer.
|
||||||
|
*
|
||||||
|
* \retval >=0 length of output data.
|
||||||
|
* \retval KNOT_E* if error.
|
||||||
|
*/
|
||||||
|
int32_t base32hex_decode(const uint8_t *in,
|
||||||
|
const uint32_t in_len,
|
||||||
|
uint8_t *out,
|
||||||
|
const uint32_t out_len);
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Encodes binary data using Base32hex. Lower case is used!
|
||||||
|
*
|
||||||
|
* \note Output data buffer contains Base32hex text string which isn't
|
||||||
|
* terminated with '\0'!
|
||||||
|
*
|
||||||
|
* \param in Input binary data.
|
||||||
|
* \param in_len Length of input data.
|
||||||
|
* \param out Output data buffer.
|
||||||
|
* \param out_len Size of output buffer.
|
||||||
|
*
|
||||||
|
* \retval >=0 length of output string.
|
||||||
|
* \retval <0 if error.
|
||||||
|
*/
|
||||||
|
int32_t base32hex_encode(const uint8_t *in,
|
||||||
|
const uint32_t in_len,
|
||||||
|
uint8_t *out,
|
||||||
|
const uint32_t out_len);
|
||||||
|
|
||||||
|
/*! @} */
|
10
contrib/base32hex.spdx
Normal file
10
contrib/base32hex.spdx
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
SPDXVersion: SPDX-2.1
|
||||||
|
DataLicense: CC0-1.0
|
||||||
|
SPDXID: SPDXRef-DOCUMENT
|
||||||
|
DocumentName: knotdns-base32hex
|
||||||
|
DocumentNamespace: http://spdx.org/spdxdocs/spdx-v2.1-4f29f08d-5fbf-4793-934c-9a6a2e6d5517
|
||||||
|
|
||||||
|
PackageName: knotdns-base32hex
|
||||||
|
PackageDownloadLocation: git+https://gitlab.nic.cz/knot/knot-dns.git@2b3c828a4cb8d9595318552483d4947345426c30#src/libknot/internal/base32hex.c
|
||||||
|
PackageOriginator: Organization: Knot DNS contributors
|
||||||
|
PackageLicenseDeclared: GPL-3.0-or-later
|
260
contrib/base64.c
Normal file
260
contrib/base64.c
Normal file
|
@ -0,0 +1,260 @@
|
||||||
|
/* Copyright (C) CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "base64.h"
|
||||||
|
#include "libknot/errcode.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/*! \brief Maximal length of binary input to Base64 encoding. */
|
||||||
|
#define MAX_BIN_DATA_LEN ((INT32_MAX / 4) * 3)
|
||||||
|
|
||||||
|
/*! \brief Base64 padding character. */
|
||||||
|
static const uint8_t base64_pad = '=';
|
||||||
|
/*! \brief Base64 alphabet. */
|
||||||
|
static const uint8_t base64_enc[] =
|
||||||
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||||
|
|
||||||
|
/*! \brief Indicates bad Base64 character. */
|
||||||
|
#define KO 255
|
||||||
|
/*! \brief Indicates Base64 padding character. */
|
||||||
|
#define PD 64
|
||||||
|
|
||||||
|
/*! \brief Transformation and validation table for decoding Base64. */
|
||||||
|
static const uint8_t base64_dec[256] = {
|
||||||
|
[ 0] = KO, ['+'] = 62, ['V'] = 21, [129] = KO, [172] = KO, [215] = KO,
|
||||||
|
[ 1] = KO, [ 44] = KO, ['W'] = 22, [130] = KO, [173] = KO, [216] = KO,
|
||||||
|
[ 2] = KO, [ 45] = KO, ['X'] = 23, [131] = KO, [174] = KO, [217] = KO,
|
||||||
|
[ 3] = KO, [ 46] = KO, ['Y'] = 24, [132] = KO, [175] = KO, [218] = KO,
|
||||||
|
[ 4] = KO, ['/'] = 63, ['Z'] = 25, [133] = KO, [176] = KO, [219] = KO,
|
||||||
|
[ 5] = KO, ['0'] = 52, [ 91] = KO, [134] = KO, [177] = KO, [220] = KO,
|
||||||
|
[ 6] = KO, ['1'] = 53, [ 92] = KO, [135] = KO, [178] = KO, [221] = KO,
|
||||||
|
[ 7] = KO, ['2'] = 54, [ 93] = KO, [136] = KO, [179] = KO, [222] = KO,
|
||||||
|
[ 8] = KO, ['3'] = 55, [ 94] = KO, [137] = KO, [180] = KO, [223] = KO,
|
||||||
|
[ 9] = KO, ['4'] = 56, [ 95] = KO, [138] = KO, [181] = KO, [224] = KO,
|
||||||
|
[ 10] = KO, ['5'] = 57, [ 96] = KO, [139] = KO, [182] = KO, [225] = KO,
|
||||||
|
[ 11] = KO, ['6'] = 58, ['a'] = 26, [140] = KO, [183] = KO, [226] = KO,
|
||||||
|
[ 12] = KO, ['7'] = 59, ['b'] = 27, [141] = KO, [184] = KO, [227] = KO,
|
||||||
|
[ 13] = KO, ['8'] = 60, ['c'] = 28, [142] = KO, [185] = KO, [228] = KO,
|
||||||
|
[ 14] = KO, ['9'] = 61, ['d'] = 29, [143] = KO, [186] = KO, [229] = KO,
|
||||||
|
[ 15] = KO, [ 58] = KO, ['e'] = 30, [144] = KO, [187] = KO, [230] = KO,
|
||||||
|
[ 16] = KO, [ 59] = KO, ['f'] = 31, [145] = KO, [188] = KO, [231] = KO,
|
||||||
|
[ 17] = KO, [ 60] = KO, ['g'] = 32, [146] = KO, [189] = KO, [232] = KO,
|
||||||
|
[ 18] = KO, ['='] = PD, ['h'] = 33, [147] = KO, [190] = KO, [233] = KO,
|
||||||
|
[ 19] = KO, [ 62] = KO, ['i'] = 34, [148] = KO, [191] = KO, [234] = KO,
|
||||||
|
[ 20] = KO, [ 63] = KO, ['j'] = 35, [149] = KO, [192] = KO, [235] = KO,
|
||||||
|
[ 21] = KO, [ 64] = KO, ['k'] = 36, [150] = KO, [193] = KO, [236] = KO,
|
||||||
|
[ 22] = KO, ['A'] = 0, ['l'] = 37, [151] = KO, [194] = KO, [237] = KO,
|
||||||
|
[ 23] = KO, ['B'] = 1, ['m'] = 38, [152] = KO, [195] = KO, [238] = KO,
|
||||||
|
[ 24] = KO, ['C'] = 2, ['n'] = 39, [153] = KO, [196] = KO, [239] = KO,
|
||||||
|
[ 25] = KO, ['D'] = 3, ['o'] = 40, [154] = KO, [197] = KO, [240] = KO,
|
||||||
|
[ 26] = KO, ['E'] = 4, ['p'] = 41, [155] = KO, [198] = KO, [241] = KO,
|
||||||
|
[ 27] = KO, ['F'] = 5, ['q'] = 42, [156] = KO, [199] = KO, [242] = KO,
|
||||||
|
[ 28] = KO, ['G'] = 6, ['r'] = 43, [157] = KO, [200] = KO, [243] = KO,
|
||||||
|
[ 29] = KO, ['H'] = 7, ['s'] = 44, [158] = KO, [201] = KO, [244] = KO,
|
||||||
|
[ 30] = KO, ['I'] = 8, ['t'] = 45, [159] = KO, [202] = KO, [245] = KO,
|
||||||
|
[ 31] = KO, ['J'] = 9, ['u'] = 46, [160] = KO, [203] = KO, [246] = KO,
|
||||||
|
[ 32] = KO, ['K'] = 10, ['v'] = 47, [161] = KO, [204] = KO, [247] = KO,
|
||||||
|
[ 33] = KO, ['L'] = 11, ['w'] = 48, [162] = KO, [205] = KO, [248] = KO,
|
||||||
|
[ 34] = KO, ['M'] = 12, ['x'] = 49, [163] = KO, [206] = KO, [249] = KO,
|
||||||
|
[ 35] = KO, ['N'] = 13, ['y'] = 50, [164] = KO, [207] = KO, [250] = KO,
|
||||||
|
[ 36] = KO, ['O'] = 14, ['z'] = 51, [165] = KO, [208] = KO, [251] = KO,
|
||||||
|
[ 37] = KO, ['P'] = 15, [123] = KO, [166] = KO, [209] = KO, [252] = KO,
|
||||||
|
[ 38] = KO, ['Q'] = 16, [124] = KO, [167] = KO, [210] = KO, [253] = KO,
|
||||||
|
[ 39] = KO, ['R'] = 17, [125] = KO, [168] = KO, [211] = KO, [254] = KO,
|
||||||
|
[ 40] = KO, ['S'] = 18, [126] = KO, [169] = KO, [212] = KO, [255] = KO,
|
||||||
|
[ 41] = KO, ['T'] = 19, [127] = KO, [170] = KO, [213] = KO,
|
||||||
|
[ 42] = KO, ['U'] = 20, [128] = KO, [171] = KO, [214] = KO,
|
||||||
|
};
|
||||||
|
|
||||||
|
int32_t kr_base64_encode(const uint8_t *in,
|
||||||
|
const uint32_t in_len,
|
||||||
|
uint8_t *out,
|
||||||
|
const uint32_t out_len)
|
||||||
|
{
|
||||||
|
// Checking inputs.
|
||||||
|
if (in == NULL || out == NULL) {
|
||||||
|
return KNOT_EINVAL;
|
||||||
|
}
|
||||||
|
if (in_len > MAX_BIN_DATA_LEN || out_len < ((in_len + 2) / 3) * 4) {
|
||||||
|
return KNOT_ERANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t rest_len = in_len % 3;
|
||||||
|
const uint8_t *stop = in + in_len - rest_len;
|
||||||
|
uint8_t *text = out;
|
||||||
|
|
||||||
|
// Encoding loop takes 3 bytes and creates 4 characters.
|
||||||
|
while (in < stop) {
|
||||||
|
text[0] = base64_enc[in[0] >> 2];
|
||||||
|
text[1] = base64_enc[(in[0] & 0x03) << 4 | in[1] >> 4];
|
||||||
|
text[2] = base64_enc[(in[1] & 0x0F) << 2 | in[2] >> 6];
|
||||||
|
text[3] = base64_enc[in[2] & 0x3F];
|
||||||
|
text += 4;
|
||||||
|
in += 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Processing of padding, if any.
|
||||||
|
switch (rest_len) {
|
||||||
|
case 2:
|
||||||
|
text[0] = base64_enc[in[0] >> 2];
|
||||||
|
text[1] = base64_enc[(in[0] & 0x03) << 4 | in[1] >> 4];
|
||||||
|
text[2] = base64_enc[(in[1] & 0x0F) << 2];
|
||||||
|
text[3] = base64_pad;
|
||||||
|
text += 4;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
text[0] = base64_enc[in[0] >> 2];
|
||||||
|
text[1] = base64_enc[(in[0] & 0x03) << 4];
|
||||||
|
text[2] = base64_pad;
|
||||||
|
text[3] = base64_pad;
|
||||||
|
text += 4;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (text - out);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t kr_base64_encode_alloc(const uint8_t *in,
|
||||||
|
const uint32_t in_len,
|
||||||
|
uint8_t **out)
|
||||||
|
{
|
||||||
|
// Checking inputs.
|
||||||
|
if (out == NULL) {
|
||||||
|
return KNOT_EINVAL;
|
||||||
|
}
|
||||||
|
if (in_len > MAX_BIN_DATA_LEN) {
|
||||||
|
return KNOT_ERANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute output buffer length.
|
||||||
|
uint32_t out_len = ((in_len + 2) / 3) * 4;
|
||||||
|
|
||||||
|
// Allocate output buffer.
|
||||||
|
*out = malloc(out_len);
|
||||||
|
if (*out == NULL) {
|
||||||
|
return KNOT_ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Encode data.
|
||||||
|
int32_t ret = kr_base64_encode(in, in_len, *out, out_len);
|
||||||
|
if (ret < 0) {
|
||||||
|
free(*out);
|
||||||
|
*out = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t kr_base64_decode(const uint8_t *in,
|
||||||
|
const uint32_t in_len,
|
||||||
|
uint8_t *out,
|
||||||
|
const uint32_t out_len)
|
||||||
|
{
|
||||||
|
// Checking inputs.
|
||||||
|
if (in == NULL || out == NULL) {
|
||||||
|
return KNOT_EINVAL;
|
||||||
|
}
|
||||||
|
if (in_len > INT32_MAX || out_len < ((in_len + 3) / 4) * 3) {
|
||||||
|
return KNOT_ERANGE;
|
||||||
|
}
|
||||||
|
if ((in_len % 4) != 0) {
|
||||||
|
return KNOT_BASE64_ESIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint8_t *stop = in + in_len;
|
||||||
|
uint8_t *bin = out;
|
||||||
|
uint8_t pad_len = 0;
|
||||||
|
uint8_t c1, c2, c3, c4;
|
||||||
|
|
||||||
|
// Decoding loop takes 4 characters and creates 3 bytes.
|
||||||
|
while (in < stop) {
|
||||||
|
// Filling and transforming 4 Base64 chars.
|
||||||
|
c1 = base64_dec[in[0]];
|
||||||
|
c2 = base64_dec[in[1]];
|
||||||
|
c3 = base64_dec[in[2]];
|
||||||
|
c4 = base64_dec[in[3]];
|
||||||
|
|
||||||
|
// Check 4. char if is bad or padding.
|
||||||
|
if (c4 >= PD) {
|
||||||
|
if (c4 == PD && pad_len == 0) {
|
||||||
|
pad_len = 1;
|
||||||
|
} else {
|
||||||
|
return KNOT_BASE64_ECHAR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check 3. char if is bad or padding.
|
||||||
|
if (c3 >= PD) {
|
||||||
|
if (c3 == PD && pad_len == 1) {
|
||||||
|
pad_len = 2;
|
||||||
|
} else {
|
||||||
|
return KNOT_BASE64_ECHAR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check 1. and 2. chars if are not padding.
|
||||||
|
if (c2 >= PD || c1 >= PD) {
|
||||||
|
return KNOT_BASE64_ECHAR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Computing of output data based on padding length.
|
||||||
|
switch (pad_len) {
|
||||||
|
case 0:
|
||||||
|
bin[2] = (c3 << 6) + c4;
|
||||||
|
// FALLTHROUGH
|
||||||
|
case 1:
|
||||||
|
bin[1] = (c2 << 4) + (c3 >> 2);
|
||||||
|
// FALLTHROUGH
|
||||||
|
case 2:
|
||||||
|
bin[0] = (c1 << 2) + (c2 >> 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update output end.
|
||||||
|
switch (pad_len) {
|
||||||
|
case 0:
|
||||||
|
bin += 3;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
bin += 2;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
bin += 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
in += 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (bin - out);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t kr_base64_decode_alloc(const uint8_t *in,
|
||||||
|
const uint32_t in_len,
|
||||||
|
uint8_t **out)
|
||||||
|
{
|
||||||
|
// Checking inputs.
|
||||||
|
if (out == NULL) {
|
||||||
|
return KNOT_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute output buffer length.
|
||||||
|
uint32_t out_len = ((in_len + 3) / 4) * 3;
|
||||||
|
|
||||||
|
// Allocate output buffer.
|
||||||
|
*out = malloc(out_len);
|
||||||
|
if (*out == NULL) {
|
||||||
|
return KNOT_ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decode data.
|
||||||
|
int32_t ret = kr_base64_decode(in, in_len, *out, out_len);
|
||||||
|
if (ret < 0) {
|
||||||
|
free(*out);
|
||||||
|
*out = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
95
contrib/base64.h
Normal file
95
contrib/base64.h
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
/* Copyright (C) CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
/*!
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief Base64 implementation (RFC 4648).
|
||||||
|
*
|
||||||
|
* \addtogroup contrib
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Encodes binary data using Base64.
|
||||||
|
*
|
||||||
|
* \note Output data buffer contains Base64 text string which isn't
|
||||||
|
* terminated with '\0'!
|
||||||
|
*
|
||||||
|
* \param in Input binary data.
|
||||||
|
* \param in_len Length of input data.
|
||||||
|
* \param out Output data buffer.
|
||||||
|
* \param out_len Size of output buffer.
|
||||||
|
*
|
||||||
|
* \retval >=0 length of output string.
|
||||||
|
* \retval KNOT_E* if error.
|
||||||
|
*/
|
||||||
|
int32_t kr_base64_encode(const uint8_t *in,
|
||||||
|
const uint32_t in_len,
|
||||||
|
uint8_t *out,
|
||||||
|
const uint32_t out_len);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Encodes binary data using Base64 and output stores to own buffer.
|
||||||
|
*
|
||||||
|
* \note Output data buffer contains Base64 text string which isn't
|
||||||
|
* terminated with '\0'!
|
||||||
|
*
|
||||||
|
* \note Output buffer should be deallocated after use.
|
||||||
|
*
|
||||||
|
* \param in Input binary data.
|
||||||
|
* \param in_len Length of input data.
|
||||||
|
* \param out Output data buffer.
|
||||||
|
*
|
||||||
|
* \retval >=0 length of output string.
|
||||||
|
* \retval KNOT_E* if error.
|
||||||
|
*/
|
||||||
|
int32_t kr_base64_encode_alloc(const uint8_t *in,
|
||||||
|
const uint32_t in_len,
|
||||||
|
uint8_t **out);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Decodes text data using Base64.
|
||||||
|
*
|
||||||
|
* \note Input data needn't be terminated with '\0'.
|
||||||
|
*
|
||||||
|
* \note Input data must be continuous Base64 string!
|
||||||
|
*
|
||||||
|
* \param in Input text data.
|
||||||
|
* \param in_len Length of input string.
|
||||||
|
* \param out Output data buffer.
|
||||||
|
* \param out_len Size of output buffer.
|
||||||
|
*
|
||||||
|
* \retval >=0 length of output data.
|
||||||
|
* \retval KNOT_E* if error.
|
||||||
|
*/
|
||||||
|
int32_t kr_base64_decode(const uint8_t *in,
|
||||||
|
const uint32_t in_len,
|
||||||
|
uint8_t *out,
|
||||||
|
const uint32_t out_len);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Decodes text data using Base64 and output stores to own buffer.
|
||||||
|
*
|
||||||
|
* \note Input data needn't be terminated with '\0'.
|
||||||
|
*
|
||||||
|
* \note Input data must be continuous Base64 string!
|
||||||
|
*
|
||||||
|
* \note Output buffer should be deallocated after use.
|
||||||
|
*
|
||||||
|
* \param in Input text data.
|
||||||
|
* \param in_len Length of input string.
|
||||||
|
* \param out Output data buffer.
|
||||||
|
*
|
||||||
|
* \retval >=0 length of output data.
|
||||||
|
* \retval KNOT_E* if error.
|
||||||
|
*/
|
||||||
|
int32_t kr_base64_decode_alloc(const uint8_t *in,
|
||||||
|
const uint32_t in_len,
|
||||||
|
uint8_t **out);
|
||||||
|
|
||||||
|
/*! @} */
|
10
contrib/base64.spdx
Normal file
10
contrib/base64.spdx
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
SPDXVersion: SPDX-2.1
|
||||||
|
DataLicense: CC0-1.0
|
||||||
|
SPDXID: SPDXRef-DOCUMENT
|
||||||
|
DocumentName: knotdns-base64
|
||||||
|
DocumentNamespace: http://spdx.org/spdxdocs/spdx-v2.1-669dfa8c-3b50-425f-92fc-9b7ce18999f2
|
||||||
|
|
||||||
|
PackageName: knotdns-base64
|
||||||
|
PackageDownloadLocation: git+https://gitlab.nic.cz/knot/knot-dns.git@2b3c828a4cb8d9595318552483d4947345426c30#src/libknot/internal/base64.c
|
||||||
|
PackageOriginator: Organization: Knot DNS contributors
|
||||||
|
PackageLicenseDeclared: GPL-3.0-or-later
|
287
contrib/base64url.c
Normal file
287
contrib/base64url.c
Normal file
|
@ -0,0 +1,287 @@
|
||||||
|
/* Copyright (C) CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
|
||||||
|
|
||||||
|
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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "contrib/base64url.h"
|
||||||
|
#include "libknot/errcode.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
/*! \brief Maximal length of binary input to Base64url encoding. */
|
||||||
|
#define MAX_BIN_DATA_LEN ((INT32_MAX / 4) * 3)
|
||||||
|
|
||||||
|
/*! \brief Base64url padding character. */
|
||||||
|
static const uint8_t base64url_pad = '\0';
|
||||||
|
/*! \brief Base64 alphabet. */
|
||||||
|
static const uint8_t base64url_enc[] =
|
||||||
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
||||||
|
|
||||||
|
/*! \brief Indicates bad Base64 character. */
|
||||||
|
#define KO 255
|
||||||
|
/*! \brief Indicates Base64 padding character. */
|
||||||
|
#define PD 64
|
||||||
|
|
||||||
|
/*! \brief Transformation and validation table for decoding Base64. */
|
||||||
|
static const uint8_t base64url_dec[256] = {
|
||||||
|
[ 0] = PD, [ 43] = KO, ['V'] = 21, [129] = KO, [172] = KO, [215] = KO,
|
||||||
|
[ 1] = KO, [ 44] = KO, ['W'] = 22, [130] = KO, [173] = KO, [216] = KO,
|
||||||
|
[ 2] = KO, ['-'] = 62, ['X'] = 23, [131] = KO, [174] = KO, [217] = KO,
|
||||||
|
[ 3] = KO, [ 46] = KO, ['Y'] = 24, [132] = KO, [175] = KO, [218] = KO,
|
||||||
|
[ 4] = KO, [ 47] = KO, ['Z'] = 25, [133] = KO, [176] = KO, [219] = KO,
|
||||||
|
[ 5] = KO, ['0'] = 52, [ 91] = KO, [134] = KO, [177] = KO, [220] = KO,
|
||||||
|
[ 6] = KO, ['1'] = 53, [ 92] = KO, [135] = KO, [178] = KO, [221] = KO,
|
||||||
|
[ 7] = KO, ['2'] = 54, [ 93] = KO, [136] = KO, [179] = KO, [222] = KO,
|
||||||
|
[ 8] = KO, ['3'] = 55, [ 94] = KO, [137] = KO, [180] = KO, [223] = KO,
|
||||||
|
[ 9] = KO, ['4'] = 56, ['_'] = 63, [138] = KO, [181] = KO, [224] = KO,
|
||||||
|
[ 10] = KO, ['5'] = 57, [ 96] = KO, [139] = KO, [182] = KO, [225] = KO,
|
||||||
|
[ 11] = KO, ['6'] = 58, ['a'] = 26, [140] = KO, [183] = KO, [226] = KO,
|
||||||
|
[ 12] = KO, ['7'] = 59, ['b'] = 27, [141] = KO, [184] = KO, [227] = KO,
|
||||||
|
[ 13] = KO, ['8'] = 60, ['c'] = 28, [142] = KO, [185] = KO, [228] = KO,
|
||||||
|
[ 14] = KO, ['9'] = 61, ['d'] = 29, [143] = KO, [186] = KO, [229] = KO,
|
||||||
|
[ 15] = KO, [ 58] = KO, ['e'] = 30, [144] = KO, [187] = KO, [230] = KO,
|
||||||
|
[ 16] = KO, [ 59] = KO, ['f'] = 31, [145] = KO, [188] = KO, [231] = KO,
|
||||||
|
[ 17] = KO, [ 60] = KO, ['g'] = 32, [146] = KO, [189] = KO, [232] = KO,
|
||||||
|
[ 18] = KO, [ 61] = KO, ['h'] = 33, [147] = KO, [190] = KO, [233] = KO,
|
||||||
|
[ 19] = KO, [ 62] = KO, ['i'] = 34, [148] = KO, [191] = KO, [234] = KO,
|
||||||
|
[ 20] = KO, [ 63] = KO, ['j'] = 35, [149] = KO, [192] = KO, [235] = KO,
|
||||||
|
[ 21] = KO, [ 64] = KO, ['k'] = 36, [150] = KO, [193] = KO, [236] = KO,
|
||||||
|
[ 22] = KO, ['A'] = 0, ['l'] = 37, [151] = KO, [194] = KO, [237] = KO,
|
||||||
|
[ 23] = KO, ['B'] = 1, ['m'] = 38, [152] = KO, [195] = KO, [238] = KO,
|
||||||
|
[ 24] = KO, ['C'] = 2, ['n'] = 39, [153] = KO, [196] = KO, [239] = KO,
|
||||||
|
[ 25] = KO, ['D'] = 3, ['o'] = 40, [154] = KO, [197] = KO, [240] = KO,
|
||||||
|
[ 26] = KO, ['E'] = 4, ['p'] = 41, [155] = KO, [198] = KO, [241] = KO,
|
||||||
|
[ 27] = KO, ['F'] = 5, ['q'] = 42, [156] = KO, [199] = KO, [242] = KO,
|
||||||
|
[ 28] = KO, ['G'] = 6, ['r'] = 43, [157] = KO, [200] = KO, [243] = KO,
|
||||||
|
[ 29] = KO, ['H'] = 7, ['s'] = 44, [158] = KO, [201] = KO, [244] = KO,
|
||||||
|
[ 30] = KO, ['I'] = 8, ['t'] = 45, [159] = KO, [202] = KO, [245] = KO,
|
||||||
|
[ 31] = KO, ['J'] = 9, ['u'] = 46, [160] = KO, [203] = KO, [246] = KO,
|
||||||
|
[ 32] = KO, ['K'] = 10, ['v'] = 47, [161] = KO, [204] = KO, [247] = KO,
|
||||||
|
[ 33] = KO, ['L'] = 11, ['w'] = 48, [162] = KO, [205] = KO, [248] = KO,
|
||||||
|
[ 34] = KO, ['M'] = 12, ['x'] = 49, [163] = KO, [206] = KO, [249] = KO,
|
||||||
|
[ 35] = KO, ['N'] = 13, ['y'] = 50, [164] = KO, [207] = KO, [250] = KO,
|
||||||
|
[ 36] = KO, ['O'] = 14, ['z'] = 51, [165] = KO, [208] = KO, [251] = KO,
|
||||||
|
['%'] = KO, ['P'] = 15, [123] = KO, [166] = KO, [209] = KO, [252] = KO,
|
||||||
|
[ 38] = KO, ['Q'] = 16, [124] = KO, [167] = KO, [210] = KO, [253] = KO,
|
||||||
|
[ 39] = KO, ['R'] = 17, [125] = KO, [168] = KO, [211] = KO, [254] = KO,
|
||||||
|
[ 40] = KO, ['S'] = 18, [126] = KO, [169] = KO, [212] = KO, [255] = KO,
|
||||||
|
[ 41] = KO, ['T'] = 19, [127] = KO, [170] = KO, [213] = KO,
|
||||||
|
[ 42] = KO, ['U'] = 20, [128] = KO, [171] = KO, [214] = KO,
|
||||||
|
};
|
||||||
|
|
||||||
|
int32_t kr_base64url_encode(const uint8_t *in,
|
||||||
|
const uint32_t in_len,
|
||||||
|
uint8_t *out,
|
||||||
|
const uint32_t out_len)
|
||||||
|
{
|
||||||
|
// Checking inputs.
|
||||||
|
if (in == NULL || out == NULL) {
|
||||||
|
return KNOT_EINVAL;
|
||||||
|
}
|
||||||
|
if (in_len > MAX_BIN_DATA_LEN || out_len < ((in_len + 2) / 3) * 4) {
|
||||||
|
return KNOT_ERANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t rest_len = in_len % 3;
|
||||||
|
const uint8_t *stop = in + in_len - rest_len;
|
||||||
|
uint8_t *text = out;
|
||||||
|
|
||||||
|
// Encoding loop takes 3 bytes and creates 4 characters.
|
||||||
|
while (in < stop) {
|
||||||
|
text[0] = base64url_enc[in[0] >> 2];
|
||||||
|
text[1] = base64url_enc[(in[0] & 0x03) << 4 | in[1] >> 4];
|
||||||
|
text[2] = base64url_enc[(in[1] & 0x0F) << 2 | in[2] >> 6];
|
||||||
|
text[3] = base64url_enc[in[2] & 0x3F];
|
||||||
|
text += 4;
|
||||||
|
in += 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Processing of padding, if any.
|
||||||
|
switch (rest_len) {
|
||||||
|
case 2:
|
||||||
|
text[0] = base64url_enc[in[0] >> 2];
|
||||||
|
text[1] = base64url_enc[(in[0] & 0x03) << 4 | in[1] >> 4];
|
||||||
|
text[2] = base64url_enc[(in[1] & 0x0F) << 2];
|
||||||
|
text[3] = base64url_pad;
|
||||||
|
text += 3;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
text[0] = base64url_enc[in[0] >> 2];
|
||||||
|
text[1] = base64url_enc[(in[0] & 0x03) << 4];
|
||||||
|
text[2] = base64url_pad;
|
||||||
|
text[3] = base64url_pad;
|
||||||
|
text += 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return (text - out);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t kr_base64url_encode_alloc(const uint8_t *in,
|
||||||
|
const uint32_t in_len,
|
||||||
|
uint8_t **out)
|
||||||
|
{
|
||||||
|
// Checking inputs.
|
||||||
|
if (out == NULL) {
|
||||||
|
return KNOT_EINVAL;
|
||||||
|
}
|
||||||
|
if (in_len > MAX_BIN_DATA_LEN) {
|
||||||
|
return KNOT_ERANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute output buffer length.
|
||||||
|
uint32_t out_len = ((in_len + 2) / 3) * 4;
|
||||||
|
|
||||||
|
// Allocate output buffer.
|
||||||
|
*out = malloc(out_len);
|
||||||
|
if (*out == NULL) {
|
||||||
|
return KNOT_ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Encode data.
|
||||||
|
int32_t ret = kr_base64url_encode(in, in_len, *out, out_len);
|
||||||
|
if (ret < 0) {
|
||||||
|
free(*out);
|
||||||
|
*out = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t kr_base64url_decode(const uint8_t *in,
|
||||||
|
uint32_t in_len,
|
||||||
|
uint8_t *out,
|
||||||
|
const uint32_t out_len)
|
||||||
|
{
|
||||||
|
// Checking inputs.
|
||||||
|
if (in == NULL || out == NULL) {
|
||||||
|
return KNOT_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// cut up to two "%3d" from the end of input
|
||||||
|
int pad3d = 0;
|
||||||
|
const uint8_t *end = in + in_len;
|
||||||
|
char *perc3d = "d3%d3%", *stop3d = perc3d + 6;
|
||||||
|
while (end != in && perc3d != stop3d && tolower(*--end) == *perc3d) {
|
||||||
|
if (*perc3d++ == '%') {
|
||||||
|
in_len -= 3;
|
||||||
|
pad3d++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_len > INT32_MAX || out_len < ((in_len + 3) / 4) * 3) {
|
||||||
|
return KNOT_ERANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint8_t *stop = in + in_len;
|
||||||
|
uint8_t *bin = out;
|
||||||
|
uint8_t pad_len = 0;
|
||||||
|
uint8_t c1, c2, c3, c4;
|
||||||
|
|
||||||
|
// Decoding loop takes 4 characters and creates 3 bytes.
|
||||||
|
while (in < stop) {
|
||||||
|
// Filling and transforming 4 Base64 chars.
|
||||||
|
c1 = base64url_dec[in[0]] ;
|
||||||
|
c2 = base64url_dec[in[1]] ;
|
||||||
|
c3 = (in + 2 < stop) ? base64url_dec[in[2]] : PD;
|
||||||
|
c4 = (in + 3 < stop) ? base64url_dec[in[3]] : PD;
|
||||||
|
|
||||||
|
// Check 1. and 2. chars if are not padding
|
||||||
|
if (c1 >= PD || c2 >= PD) {
|
||||||
|
return KNOT_BASE64_ECHAR;
|
||||||
|
}
|
||||||
|
// Check 3. char if is bad or padding.
|
||||||
|
else if (c3 >= PD) {
|
||||||
|
if (c3 == PD) {
|
||||||
|
pad_len = 2;
|
||||||
|
} else {
|
||||||
|
return KNOT_BASE64_ECHAR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Check 3. char if is bad or padding.
|
||||||
|
else if (c4 >= PD) {
|
||||||
|
if (c4 == PD) {
|
||||||
|
pad_len = 1;
|
||||||
|
} else {
|
||||||
|
return KNOT_BASE64_ECHAR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pad_len > 0 && in <= stop - 4) {
|
||||||
|
return KNOT_BASE64_ECHAR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Computing of output data based on padding length.
|
||||||
|
switch (pad_len) {
|
||||||
|
case 0:
|
||||||
|
bin[2] = (c3 << 6) + c4;
|
||||||
|
// FALLTHROUGH
|
||||||
|
case 1:
|
||||||
|
bin[1] = (c2 << 4) + (c3 >> 2);
|
||||||
|
// FALLTHROUGH
|
||||||
|
case 2:
|
||||||
|
bin[0] = (c1 << 2) + (c2 >> 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update output end.
|
||||||
|
switch (pad_len) {
|
||||||
|
case 0:
|
||||||
|
bin += 3;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
bin += 2;
|
||||||
|
goto end;
|
||||||
|
case 2:
|
||||||
|
bin += 1;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
in += 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
end:
|
||||||
|
if (pad3d > pad_len) {
|
||||||
|
return KNOT_BASE64_ECHAR;
|
||||||
|
}
|
||||||
|
return (bin - out);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t kr_base64url_decode_alloc(const uint8_t *in,
|
||||||
|
const uint32_t in_len,
|
||||||
|
uint8_t **out)
|
||||||
|
{
|
||||||
|
// Checking inputs.
|
||||||
|
if (out == NULL) {
|
||||||
|
return KNOT_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute output buffer length.
|
||||||
|
uint32_t out_len = ((in_len + 3) / 4) * 3;
|
||||||
|
|
||||||
|
// Allocate output buffer.
|
||||||
|
*out = malloc(out_len);
|
||||||
|
if (*out == NULL) {
|
||||||
|
return KNOT_ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decode data.
|
||||||
|
int32_t ret = kr_base64url_decode(in, in_len, *out, out_len);
|
||||||
|
if (ret < 0) {
|
||||||
|
free(*out);
|
||||||
|
*out = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
103
contrib/base64url.h
Normal file
103
contrib/base64url.h
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
/* Copyright (C) CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
|
||||||
|
|
||||||
|
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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Base64url implementation (RFC 4648).
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Encodes binary data using Base64.
|
||||||
|
*
|
||||||
|
* \note Output data buffer contains Base64 text string which isn't
|
||||||
|
* terminated with '\0'!
|
||||||
|
*
|
||||||
|
* \param in Input binary data.
|
||||||
|
* \param in_len Length of input data.
|
||||||
|
* \param out Output data buffer.
|
||||||
|
* \param out_len Size of output buffer.
|
||||||
|
*
|
||||||
|
* \retval >=0 length of output string.
|
||||||
|
* \retval KNOT_E* if error.
|
||||||
|
*/
|
||||||
|
int32_t kr_base64url_encode(const uint8_t *in,
|
||||||
|
const uint32_t in_len,
|
||||||
|
uint8_t *out,
|
||||||
|
const uint32_t out_len);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Encodes binary data using Base64 and output stores to own buffer.
|
||||||
|
*
|
||||||
|
* \note Output data buffer contains Base64 text string which isn't
|
||||||
|
* terminated with '\0'!
|
||||||
|
*
|
||||||
|
* \note Output buffer should be deallocated after use.
|
||||||
|
*
|
||||||
|
* \param in Input binary data.
|
||||||
|
* \param in_len Length of input data.
|
||||||
|
* \param out Output data buffer.
|
||||||
|
*
|
||||||
|
* \retval >=0 length of output string.
|
||||||
|
* \retval KNOT_E* if error.
|
||||||
|
*/
|
||||||
|
int32_t kr_base64url_encode_alloc(const uint8_t *in,
|
||||||
|
const uint32_t in_len,
|
||||||
|
uint8_t **out);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Decodes text data using Base64.
|
||||||
|
*
|
||||||
|
* \note Input data needn't be terminated with '\0'.
|
||||||
|
*
|
||||||
|
* \note Input data must be continuous Base64 string!
|
||||||
|
*
|
||||||
|
* \param in Input text data.
|
||||||
|
* \param in_len Length of input string.
|
||||||
|
* \param out Output data buffer.
|
||||||
|
* \param out_len Size of output buffer.
|
||||||
|
*
|
||||||
|
* \retval >=0 length of output data.
|
||||||
|
* \retval KNOT_E* if error.
|
||||||
|
*/
|
||||||
|
int32_t kr_base64url_decode(const uint8_t *in,
|
||||||
|
uint32_t in_len,
|
||||||
|
uint8_t *out,
|
||||||
|
const uint32_t out_len);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Decodes text data using Base64 and output stores to own buffer.
|
||||||
|
*
|
||||||
|
* \note Input data needn't be terminated with '\0'.
|
||||||
|
*
|
||||||
|
* \note Input data must be continuous Base64 string!
|
||||||
|
*
|
||||||
|
* \note Output buffer should be deallocated after use.
|
||||||
|
*
|
||||||
|
* \param in Input text data.
|
||||||
|
* \param in_len Length of input string.
|
||||||
|
* \param out Output data buffer.
|
||||||
|
*
|
||||||
|
* \retval >=0 length of output data.
|
||||||
|
* \retval KNOT_E* if error.
|
||||||
|
*/
|
||||||
|
int32_t kr_base64url_decode_alloc(const uint8_t *in,
|
||||||
|
const uint32_t in_len,
|
||||||
|
uint8_t **out);
|
||||||
|
|
||||||
|
/*! @} */
|
1
contrib/ccan/asprintf/LICENSE
Symbolic link
1
contrib/ccan/asprintf/LICENSE
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../../licenses/BSD-MIT
|
57
contrib/ccan/asprintf/asprintf.c
Normal file
57
contrib/ccan/asprintf/asprintf.c
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
/* SPDX-License-Identifier: MIT
|
||||||
|
* Source: https://ccodearchive.net/info/asprintf.html */
|
||||||
|
#include <ccan/asprintf/asprintf.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
char *PRINTF_FMT(1, 2) afmt(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
char *ptr;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
/* The BSD version apparently sets ptr to NULL on fail. GNU loses. */
|
||||||
|
if (vasprintf(&ptr, fmt, ap) < 0)
|
||||||
|
ptr = NULL;
|
||||||
|
va_end(ap);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !HAVE_ASPRINTF
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int vasprintf(char **strp, const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
va_list ap_copy;
|
||||||
|
|
||||||
|
/* We need to make a copy of ap, since it's a use-once. */
|
||||||
|
va_copy(ap_copy, ap);
|
||||||
|
len = vsnprintf(NULL, 0, fmt, ap_copy);
|
||||||
|
va_end(ap_copy);
|
||||||
|
|
||||||
|
/* Until version 2.0.6 glibc would return -1 on truncated output.
|
||||||
|
* OTOH, they had asprintf. */
|
||||||
|
if (len < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
*strp = malloc(len+1);
|
||||||
|
if (!*strp)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return vsprintf(*strp, fmt, ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
int asprintf(char **strp, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
len = vasprintf(strp, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
#endif /* !HAVE_ASPRINTF */
|
51
contrib/ccan/asprintf/asprintf.h
Normal file
51
contrib/ccan/asprintf/asprintf.h
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
/* SPDX-License-Identifier: MIT
|
||||||
|
* Source: https://ccodearchive.net/info/asprintf.html */
|
||||||
|
#ifndef CCAN_ASPRINTF_H
|
||||||
|
#define CCAN_ASPRINTF_H
|
||||||
|
#include "config.h"
|
||||||
|
#include <ccan/compiler/compiler.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* afmt - allocate and populate a string with the given format.
|
||||||
|
* @fmt: printf-style format.
|
||||||
|
*
|
||||||
|
* This is a simplified asprintf interface. Returns NULL on error.
|
||||||
|
*/
|
||||||
|
char *PRINTF_FMT(1, 2) afmt(const char *fmt, ...);
|
||||||
|
|
||||||
|
#if HAVE_ASPRINTF
|
||||||
|
#include <stdio.h>
|
||||||
|
#else
|
||||||
|
#include <stdarg.h>
|
||||||
|
/**
|
||||||
|
* asprintf - printf to a dynamically-allocated string.
|
||||||
|
* @strp: pointer to the string to allocate.
|
||||||
|
* @fmt: printf-style format.
|
||||||
|
*
|
||||||
|
* Returns -1 (and leaves @strp undefined) on an error. Otherwise returns
|
||||||
|
* number of bytes printed into @strp.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* static char *greeting(const char *name)
|
||||||
|
* {
|
||||||
|
* char *str;
|
||||||
|
* int len = asprintf(&str, "Hello %s", name);
|
||||||
|
* if (len < 0)
|
||||||
|
* return NULL;
|
||||||
|
* return str;
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
int PRINTF_FMT(2, 3) asprintf(char **strp, const char *fmt, ...);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* vasprintf - vprintf to a dynamically-allocated string.
|
||||||
|
* @strp: pointer to the string to allocate.
|
||||||
|
* @fmt: printf-style format.
|
||||||
|
*
|
||||||
|
* Returns -1 (and leaves @strp undefined) on an error. Otherwise returns
|
||||||
|
* number of bytes printed into @strp.
|
||||||
|
*/
|
||||||
|
int vasprintf(char **strp, const char *fmt, va_list ap);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* CCAN_ASPRINTF_H */
|
10
contrib/ccan/asprintf/asprintf.spdx
Normal file
10
contrib/ccan/asprintf/asprintf.spdx
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
SPDXVersion: SPDX-2.1
|
||||||
|
DataLicense: CC0-1.0
|
||||||
|
SPDXID: SPDXRef-DOCUMENT
|
||||||
|
DocumentName: ccan-asprintf
|
||||||
|
DocumentNamespace: http://spdx.org/spdxdocs/spdx-v2.1-40d4b71d-00e9-4e75-b6da-559203e6b815
|
||||||
|
|
||||||
|
PackageName: asprintf
|
||||||
|
PackageDownloadLocation: git+https://github.com/rustyrussell/ccan@fb1dfd092940905883ea6473162f5f6e36624da2#ccan/asprintf
|
||||||
|
PackageOriginator: Person: Rusty Russell (rusty@rustcorp.com.au)
|
||||||
|
PackageLicenseDeclared: MIT
|
1
contrib/ccan/compiler/LICENSE
Symbolic link
1
contrib/ccan/compiler/LICENSE
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../../licenses/CC0
|
232
contrib/ccan/compiler/compiler.h
Normal file
232
contrib/ccan/compiler/compiler.h
Normal file
|
@ -0,0 +1,232 @@
|
||||||
|
/* SPDX-License-Identifier: CC0-1.0
|
||||||
|
* Source: https://ccodearchive.net/info/compiler.html */
|
||||||
|
#ifndef CCAN_COMPILER_H
|
||||||
|
#define CCAN_COMPILER_H
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#ifndef COLD
|
||||||
|
#if HAVE_ATTRIBUTE_COLD
|
||||||
|
/**
|
||||||
|
* COLD - a function is unlikely to be called.
|
||||||
|
*
|
||||||
|
* Used to mark an unlikely code path and optimize appropriately.
|
||||||
|
* It is usually used on logging or error routines.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* static void COLD moan(const char *reason)
|
||||||
|
* {
|
||||||
|
* fprintf(stderr, "Error: %s (%s)\n", reason, strerror(errno));
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
#define COLD __attribute__((__cold__))
|
||||||
|
#else
|
||||||
|
#define COLD
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef NORETURN
|
||||||
|
#if HAVE_ATTRIBUTE_NORETURN
|
||||||
|
/**
|
||||||
|
* NORETURN - a function does not return
|
||||||
|
*
|
||||||
|
* Used to mark a function which exits; useful for suppressing warnings.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* static void NORETURN fail(const char *reason)
|
||||||
|
* {
|
||||||
|
* fprintf(stderr, "Error: %s (%s)\n", reason, strerror(errno));
|
||||||
|
* exit(1);
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
#define NORETURN __attribute__((__noreturn__))
|
||||||
|
#else
|
||||||
|
#define NORETURN
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef PRINTF_FMT
|
||||||
|
#if HAVE_ATTRIBUTE_PRINTF
|
||||||
|
/**
|
||||||
|
* PRINTF_FMT - a function takes printf-style arguments
|
||||||
|
* @nfmt: the 1-based number of the function's format argument.
|
||||||
|
* @narg: the 1-based number of the function's first variable argument.
|
||||||
|
*
|
||||||
|
* This allows the compiler to check your parameters as it does for printf().
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* void PRINTF_FMT(2,3) my_printf(const char *prefix, const char *fmt, ...);
|
||||||
|
*/
|
||||||
|
#define PRINTF_FMT(nfmt, narg) \
|
||||||
|
__attribute__((format(__printf__, nfmt, narg)))
|
||||||
|
#else
|
||||||
|
#define PRINTF_FMT(nfmt, narg)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONST_FUNCTION
|
||||||
|
#if HAVE_ATTRIBUTE_CONST
|
||||||
|
/**
|
||||||
|
* CONST_FUNCTION - a function's return depends only on its argument
|
||||||
|
*
|
||||||
|
* This allows the compiler to assume that the function will return the exact
|
||||||
|
* same value for the exact same arguments. This implies that the function
|
||||||
|
* must not use global variables, or dereference pointer arguments.
|
||||||
|
*/
|
||||||
|
#define CONST_FUNCTION __attribute__((__const__))
|
||||||
|
#else
|
||||||
|
#define CONST_FUNCTION
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef PURE_FUNCTION
|
||||||
|
#if HAVE_ATTRIBUTE_PURE
|
||||||
|
/**
|
||||||
|
* PURE_FUNCTION - a function is pure
|
||||||
|
*
|
||||||
|
* A pure function is one that has no side effects other than it's return value
|
||||||
|
* and uses no inputs other than it's arguments and global variables.
|
||||||
|
*/
|
||||||
|
#define PURE_FUNCTION __attribute__((__pure__))
|
||||||
|
#else
|
||||||
|
#define PURE_FUNCTION
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAVE_ATTRIBUTE_UNUSED
|
||||||
|
#ifndef UNNEEDED
|
||||||
|
/**
|
||||||
|
* UNNEEDED - a variable/function may not be needed
|
||||||
|
*
|
||||||
|
* This suppresses warnings about unused variables or functions, but tells
|
||||||
|
* the compiler that if it is unused it need not emit it into the source code.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* // With some preprocessor options, this is unnecessary.
|
||||||
|
* static UNNEEDED int counter;
|
||||||
|
*
|
||||||
|
* // With some preprocessor options, this is unnecessary.
|
||||||
|
* static UNNEEDED void add_to_counter(int add)
|
||||||
|
* {
|
||||||
|
* counter += add;
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
#define UNNEEDED __attribute__((__unused__))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef NEEDED
|
||||||
|
#if HAVE_ATTRIBUTE_USED
|
||||||
|
/**
|
||||||
|
* NEEDED - a variable/function is needed
|
||||||
|
*
|
||||||
|
* This suppresses warnings about unused variables or functions, but tells
|
||||||
|
* the compiler that it must exist even if it (seems) unused.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* // Even if this is unused, these are vital for debugging.
|
||||||
|
* static NEEDED int counter;
|
||||||
|
* static NEEDED void dump_counter(void)
|
||||||
|
* {
|
||||||
|
* printf("Counter is %i\n", counter);
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
#define NEEDED __attribute__((__used__))
|
||||||
|
#else
|
||||||
|
/* Before used, unused functions and vars were always emitted. */
|
||||||
|
#define NEEDED __attribute__((__unused__))
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef UNUSED
|
||||||
|
/**
|
||||||
|
* UNUSED - a parameter is unused
|
||||||
|
*
|
||||||
|
* Some compilers (eg. gcc with -W or -Wunused) warn about unused
|
||||||
|
* function parameters. This suppresses such warnings and indicates
|
||||||
|
* to the reader that it's deliberate.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* // This is used as a callback, so needs to have this prototype.
|
||||||
|
* static int some_callback(void *unused UNUSED)
|
||||||
|
* {
|
||||||
|
* return 0;
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
#define UNUSED __attribute__((__unused__))
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#ifndef UNNEEDED
|
||||||
|
#define UNNEEDED
|
||||||
|
#endif
|
||||||
|
#ifndef NEEDED
|
||||||
|
#define NEEDED
|
||||||
|
#endif
|
||||||
|
#ifndef UNUSED
|
||||||
|
#define UNUSED
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef IS_COMPILE_CONSTANT
|
||||||
|
#if HAVE_BUILTIN_CONSTANT_P
|
||||||
|
/**
|
||||||
|
* IS_COMPILE_CONSTANT - does the compiler know the value of this expression?
|
||||||
|
* @expr: the expression to evaluate
|
||||||
|
*
|
||||||
|
* When an expression manipulation is complicated, it is usually better to
|
||||||
|
* implement it in a function. However, if the expression being manipulated is
|
||||||
|
* known at compile time, it is better to have the compiler see the entire
|
||||||
|
* expression so it can simply substitute the result.
|
||||||
|
*
|
||||||
|
* This can be done using the IS_COMPILE_CONSTANT() macro.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* enum greek { ALPHA, BETA, GAMMA, DELTA, EPSILON };
|
||||||
|
*
|
||||||
|
* // Out-of-line version.
|
||||||
|
* const char *greek_name(enum greek greek);
|
||||||
|
*
|
||||||
|
* // Inline version.
|
||||||
|
* static inline const char *_greek_name(enum greek greek)
|
||||||
|
* {
|
||||||
|
* switch (greek) {
|
||||||
|
* case ALPHA: return "alpha";
|
||||||
|
* case BETA: return "beta";
|
||||||
|
* case GAMMA: return "gamma";
|
||||||
|
* case DELTA: return "delta";
|
||||||
|
* case EPSILON: return "epsilon";
|
||||||
|
* default: return "**INVALID**";
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* // Use inline if compiler knows answer. Otherwise call function
|
||||||
|
* // to avoid copies of the same code everywhere.
|
||||||
|
* #define greek_name(g) \
|
||||||
|
* (IS_COMPILE_CONSTANT(greek) ? _greek_name(g) : greek_name(g))
|
||||||
|
*/
|
||||||
|
#define IS_COMPILE_CONSTANT(expr) __builtin_constant_p(expr)
|
||||||
|
#else
|
||||||
|
/* If we don't know, assume it's not. */
|
||||||
|
#define IS_COMPILE_CONSTANT(expr) 0
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WARN_UNUSED_RESULT
|
||||||
|
#if HAVE_WARN_UNUSED_RESULT
|
||||||
|
/**
|
||||||
|
* WARN_UNUSED_RESULT - warn if a function return value is unused.
|
||||||
|
*
|
||||||
|
* Used to mark a function where it is extremely unlikely that the caller
|
||||||
|
* can ignore the result, eg realloc().
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* // buf param may be freed by this; need return value!
|
||||||
|
* static char *WARN_UNUSED_RESULT enlarge(char *buf, unsigned *size)
|
||||||
|
* {
|
||||||
|
* return realloc(buf, (*size) *= 2);
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
#define WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
|
||||||
|
#else
|
||||||
|
#define WARN_UNUSED_RESULT
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#endif /* CCAN_COMPILER_H */
|
10
contrib/ccan/compiler/compiler.spdx
Normal file
10
contrib/ccan/compiler/compiler.spdx
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
SPDXVersion: SPDX-2.1
|
||||||
|
DataLicense: CC0-1.0
|
||||||
|
SPDXID: SPDXRef-DOCUMENT
|
||||||
|
DocumentName: ccan-compiler
|
||||||
|
DocumentNamespace: http://spdx.org/spdxdocs/spdx-v2.1-1569e849-880d-4ce7-ba3e-f4aaec8fce52
|
||||||
|
|
||||||
|
PackageName: compiler
|
||||||
|
PackageDownloadLocation: git+https://github.com/rustyrussell/ccan@23e96f89d54b8d5c4675284bbcd44fba68d8f826#ccan/compiler
|
||||||
|
PackageOriginator: Person: Rusty Russell (rusty@rustcorp.com.au)
|
||||||
|
PackageLicenseDeclared: CC0-1.0
|
1
contrib/ccan/json/LICENSE
Symbolic link
1
contrib/ccan/json/LICENSE
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../../licenses/BSD-MIT
|
1362
contrib/ccan/json/json.c
Normal file
1362
contrib/ccan/json/json.c
Normal file
File diff suppressed because it is too large
Load diff
99
contrib/ccan/json/json.h
Normal file
99
contrib/ccan/json/json.h
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
/* SPDX-License-Identifier: MIT
|
||||||
|
* Source: https://ccodearchive.net/info/json.html
|
||||||
|
* Copyright (C) 2011 Joseph A. Adams (joeyadams3.14159@gmail.com) */
|
||||||
|
|
||||||
|
#ifndef CCAN_JSON_H
|
||||||
|
#define CCAN_JSON_H
|
||||||
|
|
||||||
|
#include <lib/defines.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
JSON_NULL,
|
||||||
|
JSON_BOOL,
|
||||||
|
JSON_STRING,
|
||||||
|
JSON_NUMBER,
|
||||||
|
JSON_ARRAY,
|
||||||
|
JSON_OBJECT,
|
||||||
|
} JsonTag;
|
||||||
|
|
||||||
|
typedef struct JsonNode JsonNode;
|
||||||
|
|
||||||
|
struct JsonNode
|
||||||
|
{
|
||||||
|
/* only if parent is an object or array (NULL otherwise) */
|
||||||
|
JsonNode *parent;
|
||||||
|
JsonNode *prev, *next;
|
||||||
|
|
||||||
|
/* only if parent is an object (NULL otherwise) */
|
||||||
|
char *key; /* Must be valid UTF-8. */
|
||||||
|
|
||||||
|
JsonTag tag;
|
||||||
|
union {
|
||||||
|
/* JSON_BOOL */
|
||||||
|
bool bool_;
|
||||||
|
|
||||||
|
/* JSON_STRING */
|
||||||
|
char *string_; /* Must be valid UTF-8. */
|
||||||
|
|
||||||
|
/* JSON_NUMBER */
|
||||||
|
double number_;
|
||||||
|
|
||||||
|
/* JSON_ARRAY */
|
||||||
|
/* JSON_OBJECT */
|
||||||
|
struct {
|
||||||
|
JsonNode *head, *tail;
|
||||||
|
} children;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/*** Encoding, decoding, and validation ***/
|
||||||
|
|
||||||
|
KR_EXPORT JsonNode *json_decode (const char *json);
|
||||||
|
KR_EXPORT char *json_encode (const JsonNode *node);
|
||||||
|
KR_EXPORT char *json_encode_string (const char *str);
|
||||||
|
KR_EXPORT char *json_stringify (const JsonNode *node, const char *space);
|
||||||
|
KR_EXPORT void json_delete (JsonNode *node);
|
||||||
|
|
||||||
|
KR_EXPORT bool json_validate (const char *json);
|
||||||
|
|
||||||
|
/*** Lookup and traversal ***/
|
||||||
|
|
||||||
|
KR_EXPORT JsonNode *json_find_element (JsonNode *array, int index);
|
||||||
|
KR_EXPORT JsonNode *json_find_member (JsonNode *object, const char *key);
|
||||||
|
|
||||||
|
KR_EXPORT JsonNode *json_first_child (const JsonNode *node);
|
||||||
|
|
||||||
|
#define json_foreach(i, object_or_array) \
|
||||||
|
for ((i) = json_first_child(object_or_array); \
|
||||||
|
(i) != NULL; \
|
||||||
|
(i) = (i)->next)
|
||||||
|
|
||||||
|
/*** Construction and manipulation ***/
|
||||||
|
|
||||||
|
KR_EXPORT JsonNode *json_mknull(void);
|
||||||
|
KR_EXPORT JsonNode *json_mkbool(bool b);
|
||||||
|
KR_EXPORT JsonNode *json_mkstring(const char *s);
|
||||||
|
KR_EXPORT JsonNode *json_mknumber(double n);
|
||||||
|
KR_EXPORT JsonNode *json_mkarray(void);
|
||||||
|
KR_EXPORT JsonNode *json_mkobject(void);
|
||||||
|
|
||||||
|
KR_EXPORT void json_append_element(JsonNode *array, JsonNode *element);
|
||||||
|
KR_EXPORT void json_prepend_element(JsonNode *array, JsonNode *element);
|
||||||
|
KR_EXPORT void json_append_member(JsonNode *object, const char *key, JsonNode *value);
|
||||||
|
KR_EXPORT void json_prepend_member(JsonNode *object, const char *key, JsonNode *value);
|
||||||
|
|
||||||
|
KR_EXPORT void json_remove_from_parent(JsonNode *node);
|
||||||
|
|
||||||
|
/*** Debugging ***/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Look for structure and encoding problems in a JsonNode or its descendents.
|
||||||
|
*
|
||||||
|
* If a problem is detected, return false, writing a description of the problem
|
||||||
|
* to errmsg (unless errmsg is NULL).
|
||||||
|
*/
|
||||||
|
KR_EXPORT bool json_check(const JsonNode *node, char errmsg[256]);
|
||||||
|
|
||||||
|
#endif
|
10
contrib/ccan/json/json.spdx
Normal file
10
contrib/ccan/json/json.spdx
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
SPDXVersion: SPDX-2.1
|
||||||
|
DataLicense: CC0-1.0
|
||||||
|
SPDXID: SPDXRef-DOCUMENT
|
||||||
|
DocumentName: ccan-json
|
||||||
|
DocumentNamespace: http://spdx.org/spdxdocs/spdx-v2.1-d9b4db4c-062f-4add-89b6-f603224f5a2c
|
||||||
|
|
||||||
|
PackageName: json
|
||||||
|
PackageDownloadLocation: git+https://github.com/rustyrussell/ccan@f4eb3a18caf946ee6cc2cb57e2a0c6a6f115157f#ccan/json
|
||||||
|
PackageOriginator: Person: Joseph A. Adams (joeyadams3.14159@gmail.com)
|
||||||
|
PackageLicenseDeclared: MIT
|
25
contrib/cleanup.h
Normal file
25
contrib/cleanup.h
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/* Copyright (C) CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Cleanup attributes.
|
||||||
|
* @cond internal
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define auto_free __attribute__((cleanup(_cleanup_free)))
|
||||||
|
static inline void _cleanup_free(const void *p) {
|
||||||
|
free(*(char **)p);
|
||||||
|
}
|
||||||
|
#define auto_close __attribute__((cleanup(_cleanup_close)))
|
||||||
|
static inline void _cleanup_close(int *p) {
|
||||||
|
if (*p != -1) close(*p);
|
||||||
|
}
|
||||||
|
#define auto_fclose __attribute__((cleanup(_cleanup_fclose)))
|
||||||
|
static inline void _cleanup_fclose(FILE **p) {
|
||||||
|
if (*p) fclose(*p);
|
||||||
|
}
|
||||||
|
/* @endcond */
|
7
contrib/config.h
Normal file
7
contrib/config.h
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
/* Dummy file, no real configuration here
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||||
|
#define HAVE_ATTRIBUTE_COLD 1
|
||||||
|
#define HAVE_ATTRIBUTE_NORETURN 1
|
||||||
|
#define HAVE_ATTRIBUTE_PURE 1
|
||||||
|
#define HAVE_ATTRIBUTE_UNUSED 1
|
||||||
|
#define HAVE_ATTRIBUTE_NONNULL 1
|
21
contrib/licenses/BSD-MIT
Normal file
21
contrib/licenses/BSD-MIT
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
SPDX-License-Identifier: MIT
|
||||||
|
SPDX-URL: https://spdx.org/licenses/MIT.html
|
||||||
|
License-Text:
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
32
contrib/licenses/CC0
Normal file
32
contrib/licenses/CC0
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
SPDX-License-Identifier: CC0-1.0
|
||||||
|
SPDX-URL: https://spdx.org/licenses/CC0-1.0.html
|
||||||
|
License-Text:
|
||||||
|
|
||||||
|
Statement of Purpose
|
||||||
|
|
||||||
|
The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work").
|
||||||
|
|
||||||
|
Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.
|
||||||
|
|
||||||
|
For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.
|
||||||
|
|
||||||
|
1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following:
|
||||||
|
|
||||||
|
the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;
|
||||||
|
moral rights retained by the original author(s) and/or performer(s);
|
||||||
|
publicity and privacy rights pertaining to a person's image or likeness depicted in a Work;
|
||||||
|
rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below;
|
||||||
|
rights protecting the extraction, dissemination, use and reuse of data in a Work;
|
||||||
|
database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and
|
||||||
|
other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.
|
||||||
|
|
||||||
|
2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose.
|
||||||
|
|
||||||
|
3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose.
|
||||||
|
|
||||||
|
4. Limitations and Disclaimers.
|
||||||
|
|
||||||
|
No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.
|
||||||
|
Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
|
||||||
|
Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.
|
||||||
|
Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.
|
506
contrib/licenses/LGPL2
Normal file
506
contrib/licenses/LGPL2
Normal file
|
@ -0,0 +1,506 @@
|
||||||
|
SPDX-License-Identifier: LGPL-2.1-or-later
|
||||||
|
SPDX-URL: http://spdx.org/licenses/LGPL-2.1
|
||||||
|
License-Text:
|
||||||
|
|
||||||
|
GNU LESSER GENERAL PUBLIC LICENSE
|
||||||
|
Version 2.1, February 1999
|
||||||
|
|
||||||
|
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
[This is the first released version of the Lesser GPL. It also counts
|
||||||
|
as the successor of the GNU Library Public License, version 2, hence
|
||||||
|
the version number 2.1.]
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The licenses for most software are designed to take away your
|
||||||
|
freedom to share and change it. By contrast, the GNU General Public
|
||||||
|
Licenses are intended to guarantee your freedom to share and change
|
||||||
|
free software--to make sure the software is free for all its users.
|
||||||
|
|
||||||
|
This license, the Lesser General Public License, applies to some
|
||||||
|
specially designated software packages--typically libraries--of the
|
||||||
|
Free Software Foundation and other authors who decide to use it. You
|
||||||
|
can use it too, but we suggest you first think carefully about whether
|
||||||
|
this license or the ordinary General Public License is the better
|
||||||
|
strategy to use in any particular case, based on the explanations below.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom of use,
|
||||||
|
not price. Our General Public Licenses are designed to make sure that
|
||||||
|
you have the freedom to distribute copies of free software (and charge
|
||||||
|
for this service if you wish); that you receive source code or can get
|
||||||
|
it if you want it; that you can change the software and use pieces of
|
||||||
|
it in new free programs; and that you are informed that you can do
|
||||||
|
these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to make restrictions that forbid
|
||||||
|
distributors to deny you these rights or to ask you to surrender these
|
||||||
|
rights. These restrictions translate to certain responsibilities for
|
||||||
|
you if you distribute copies of the library or if you modify it.
|
||||||
|
|
||||||
|
For example, if you distribute copies of the library, whether gratis
|
||||||
|
or for a fee, you must give the recipients all the rights that we gave
|
||||||
|
you. You must make sure that they, too, receive or can get the source
|
||||||
|
code. If you link other code with the library, you must provide
|
||||||
|
complete object files to the recipients, so that they can relink them
|
||||||
|
with the library after making changes to the library and recompiling
|
||||||
|
it. And you must show them these terms so they know their rights.
|
||||||
|
|
||||||
|
We protect your rights with a two-step method: (1) we copyright the
|
||||||
|
library, and (2) we offer you this license, which gives you legal
|
||||||
|
permission to copy, distribute and/or modify the library.
|
||||||
|
|
||||||
|
To protect each distributor, we want to make it very clear that
|
||||||
|
there is no warranty for the free library. Also, if the library is
|
||||||
|
modified by someone else and passed on, the recipients should know
|
||||||
|
that what they have is not the original version, so that the original
|
||||||
|
author's reputation will not be affected by problems that might be
|
||||||
|
introduced by others.
|
||||||
|
|
||||||
|
Finally, software patents pose a constant threat to the existence of
|
||||||
|
any free program. We wish to make sure that a company cannot
|
||||||
|
effectively restrict the users of a free program by obtaining a
|
||||||
|
restrictive license from a patent holder. Therefore, we insist that
|
||||||
|
any patent license obtained for a version of the library must be
|
||||||
|
consistent with the full freedom of use specified in this license.
|
||||||
|
|
||||||
|
Most GNU software, including some libraries, is covered by the
|
||||||
|
ordinary GNU General Public License. This license, the GNU Lesser
|
||||||
|
General Public License, applies to certain designated libraries, and
|
||||||
|
is quite different from the ordinary General Public License. We use
|
||||||
|
this license for certain libraries in order to permit linking those
|
||||||
|
libraries into non-free programs.
|
||||||
|
|
||||||
|
When a program is linked with a library, whether statically or using
|
||||||
|
a shared library, the combination of the two is legally speaking a
|
||||||
|
combined work, a derivative of the original library. The ordinary
|
||||||
|
General Public License therefore permits such linking only if the
|
||||||
|
entire combination fits its criteria of freedom. The Lesser General
|
||||||
|
Public License permits more lax criteria for linking other code with
|
||||||
|
the library.
|
||||||
|
|
||||||
|
We call this license the "Lesser" General Public License because it
|
||||||
|
does Less to protect the user's freedom than the ordinary General
|
||||||
|
Public License. It also provides other free software developers Less
|
||||||
|
of an advantage over competing non-free programs. These disadvantages
|
||||||
|
are the reason we use the ordinary General Public License for many
|
||||||
|
libraries. However, the Lesser license provides advantages in certain
|
||||||
|
special circumstances.
|
||||||
|
|
||||||
|
For example, on rare occasions, there may be a special need to
|
||||||
|
encourage the widest possible use of a certain library, so that it becomes
|
||||||
|
a de-facto standard. To achieve this, non-free programs must be
|
||||||
|
allowed to use the library. A more frequent case is that a free
|
||||||
|
library does the same job as widely used non-free libraries. In this
|
||||||
|
case, there is little to gain by limiting the free library to free
|
||||||
|
software only, so we use the Lesser General Public License.
|
||||||
|
|
||||||
|
In other cases, permission to use a particular library in non-free
|
||||||
|
programs enables a greater number of people to use a large body of
|
||||||
|
free software. For example, permission to use the GNU C Library in
|
||||||
|
non-free programs enables many more people to use the whole GNU
|
||||||
|
operating system, as well as its variant, the GNU/Linux operating
|
||||||
|
system.
|
||||||
|
|
||||||
|
Although the Lesser General Public License is Less protective of the
|
||||||
|
users' freedom, it does ensure that the user of a program that is
|
||||||
|
linked with the Library has the freedom and the wherewithal to run
|
||||||
|
that program using a modified version of the Library.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow. Pay close attention to the difference between a
|
||||||
|
"work based on the library" and a "work that uses the library". The
|
||||||
|
former contains code derived from the library, whereas the latter must
|
||||||
|
be combined with the library in order to run.
|
||||||
|
|
||||||
|
GNU LESSER GENERAL PUBLIC LICENSE
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
0. This License Agreement applies to any software library or other
|
||||||
|
program which contains a notice placed by the copyright holder or
|
||||||
|
other authorized party saying it may be distributed under the terms of
|
||||||
|
this Lesser General Public License (also called "this License").
|
||||||
|
Each licensee is addressed as "you".
|
||||||
|
|
||||||
|
A "library" means a collection of software functions and/or data
|
||||||
|
prepared so as to be conveniently linked with application programs
|
||||||
|
(which use some of those functions and data) to form executables.
|
||||||
|
|
||||||
|
The "Library", below, refers to any such software library or work
|
||||||
|
which has been distributed under these terms. A "work based on the
|
||||||
|
Library" means either the Library or any derivative work under
|
||||||
|
copyright law: that is to say, a work containing the Library or a
|
||||||
|
portion of it, either verbatim or with modifications and/or translated
|
||||||
|
straightforwardly into another language. (Hereinafter, translation is
|
||||||
|
included without limitation in the term "modification".)
|
||||||
|
|
||||||
|
"Source code" for a work means the preferred form of the work for
|
||||||
|
making modifications to it. For a library, complete source code means
|
||||||
|
all the source code for all modules it contains, plus any associated
|
||||||
|
interface definition files, plus the scripts used to control compilation
|
||||||
|
and installation of the library.
|
||||||
|
|
||||||
|
Activities other than copying, distribution and modification are not
|
||||||
|
covered by this License; they are outside its scope. The act of
|
||||||
|
running a program using the Library is not restricted, and output from
|
||||||
|
such a program is covered only if its contents constitute a work based
|
||||||
|
on the Library (independent of the use of the Library in a tool for
|
||||||
|
writing it). Whether that is true depends on what the Library does
|
||||||
|
and what the program that uses the Library does.
|
||||||
|
|
||||||
|
1. You may copy and distribute verbatim copies of the Library's
|
||||||
|
complete source code as you receive it, in any medium, provided that
|
||||||
|
you conspicuously and appropriately publish on each copy an
|
||||||
|
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||||
|
all the notices that refer to this License and to the absence of any
|
||||||
|
warranty; and distribute a copy of this License along with the
|
||||||
|
Library.
|
||||||
|
|
||||||
|
You may charge a fee for the physical act of transferring a copy,
|
||||||
|
and you may at your option offer warranty protection in exchange for a
|
||||||
|
fee.
|
||||||
|
|
||||||
|
2. You may modify your copy or copies of the Library or any portion
|
||||||
|
of it, thus forming a work based on the Library, and copy and
|
||||||
|
distribute such modifications or work under the terms of Section 1
|
||||||
|
above, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The modified work must itself be a software library.
|
||||||
|
|
||||||
|
b) You must cause the files modified to carry prominent notices
|
||||||
|
stating that you changed the files and the date of any change.
|
||||||
|
|
||||||
|
c) You must cause the whole of the work to be licensed at no
|
||||||
|
charge to all third parties under the terms of this License.
|
||||||
|
|
||||||
|
d) If a facility in the modified Library refers to a function or a
|
||||||
|
table of data to be supplied by an application program that uses
|
||||||
|
the facility, other than as an argument passed when the facility
|
||||||
|
is invoked, then you must make a good faith effort to ensure that,
|
||||||
|
in the event an application does not supply such function or
|
||||||
|
table, the facility still operates, and performs whatever part of
|
||||||
|
its purpose remains meaningful.
|
||||||
|
|
||||||
|
(For example, a function in a library to compute square roots has
|
||||||
|
a purpose that is entirely well-defined independent of the
|
||||||
|
application. Therefore, Subsection 2d requires that any
|
||||||
|
application-supplied function or table used by this function must
|
||||||
|
be optional: if the application does not supply it, the square
|
||||||
|
root function must still compute square roots.)
|
||||||
|
|
||||||
|
These requirements apply to the modified work as a whole. If
|
||||||
|
identifiable sections of that work are not derived from the Library,
|
||||||
|
and can be reasonably considered independent and separate works in
|
||||||
|
themselves, then this License, and its terms, do not apply to those
|
||||||
|
sections when you distribute them as separate works. But when you
|
||||||
|
distribute the same sections as part of a whole which is a work based
|
||||||
|
on the Library, the distribution of the whole must be on the terms of
|
||||||
|
this License, whose permissions for other licensees extend to the
|
||||||
|
entire whole, and thus to each and every part regardless of who wrote
|
||||||
|
it.
|
||||||
|
|
||||||
|
Thus, it is not the intent of this section to claim rights or contest
|
||||||
|
your rights to work written entirely by you; rather, the intent is to
|
||||||
|
exercise the right to control the distribution of derivative or
|
||||||
|
collective works based on the Library.
|
||||||
|
|
||||||
|
In addition, mere aggregation of another work not based on the Library
|
||||||
|
with the Library (or with a work based on the Library) on a volume of
|
||||||
|
a storage or distribution medium does not bring the other work under
|
||||||
|
the scope of this License.
|
||||||
|
|
||||||
|
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||||
|
License instead of this License to a given copy of the Library. To do
|
||||||
|
this, you must alter all the notices that refer to this License, so
|
||||||
|
that they refer to the ordinary GNU General Public License, version 2,
|
||||||
|
instead of to this License. (If a newer version than version 2 of the
|
||||||
|
ordinary GNU General Public License has appeared, then you can specify
|
||||||
|
that version instead if you wish.) Do not make any other change in
|
||||||
|
these notices.
|
||||||
|
|
||||||
|
Once this change is made in a given copy, it is irreversible for
|
||||||
|
that copy, so the ordinary GNU General Public License applies to all
|
||||||
|
subsequent copies and derivative works made from that copy.
|
||||||
|
|
||||||
|
This option is useful when you wish to copy part of the code of
|
||||||
|
the Library into a program that is not a library.
|
||||||
|
|
||||||
|
4. You may copy and distribute the Library (or a portion or
|
||||||
|
derivative of it, under Section 2) in object code or executable form
|
||||||
|
under the terms of Sections 1 and 2 above provided that you accompany
|
||||||
|
it with the complete corresponding machine-readable source code, which
|
||||||
|
must be distributed under the terms of Sections 1 and 2 above on a
|
||||||
|
medium customarily used for software interchange.
|
||||||
|
|
||||||
|
If distribution of object code is made by offering access to copy
|
||||||
|
from a designated place, then offering equivalent access to copy the
|
||||||
|
source code from the same place satisfies the requirement to
|
||||||
|
distribute the source code, even though third parties are not
|
||||||
|
compelled to copy the source along with the object code.
|
||||||
|
|
||||||
|
5. A program that contains no derivative of any portion of the
|
||||||
|
Library, but is designed to work with the Library by being compiled or
|
||||||
|
linked with it, is called a "work that uses the Library". Such a
|
||||||
|
work, in isolation, is not a derivative work of the Library, and
|
||||||
|
therefore falls outside the scope of this License.
|
||||||
|
|
||||||
|
However, linking a "work that uses the Library" with the Library
|
||||||
|
creates an executable that is a derivative of the Library (because it
|
||||||
|
contains portions of the Library), rather than a "work that uses the
|
||||||
|
library". The executable is therefore covered by this License.
|
||||||
|
Section 6 states terms for distribution of such executables.
|
||||||
|
|
||||||
|
When a "work that uses the Library" uses material from a header file
|
||||||
|
that is part of the Library, the object code for the work may be a
|
||||||
|
derivative work of the Library even though the source code is not.
|
||||||
|
Whether this is true is especially significant if the work can be
|
||||||
|
linked without the Library, or if the work is itself a library. The
|
||||||
|
threshold for this to be true is not precisely defined by law.
|
||||||
|
|
||||||
|
If such an object file uses only numerical parameters, data
|
||||||
|
structure layouts and accessors, and small macros and small inline
|
||||||
|
functions (ten lines or less in length), then the use of the object
|
||||||
|
file is unrestricted, regardless of whether it is legally a derivative
|
||||||
|
work. (Executables containing this object code plus portions of the
|
||||||
|
Library will still fall under Section 6.)
|
||||||
|
|
||||||
|
Otherwise, if the work is a derivative of the Library, you may
|
||||||
|
distribute the object code for the work under the terms of Section 6.
|
||||||
|
Any executables containing that work also fall under Section 6,
|
||||||
|
whether or not they are linked directly with the Library itself.
|
||||||
|
|
||||||
|
6. As an exception to the Sections above, you may also combine or
|
||||||
|
link a "work that uses the Library" with the Library to produce a
|
||||||
|
work containing portions of the Library, and distribute that work
|
||||||
|
under terms of your choice, provided that the terms permit
|
||||||
|
modification of the work for the customer's own use and reverse
|
||||||
|
engineering for debugging such modifications.
|
||||||
|
|
||||||
|
You must give prominent notice with each copy of the work that the
|
||||||
|
Library is used in it and that the Library and its use are covered by
|
||||||
|
this License. You must supply a copy of this License. If the work
|
||||||
|
during execution displays copyright notices, you must include the
|
||||||
|
copyright notice for the Library among them, as well as a reference
|
||||||
|
directing the user to the copy of this License. Also, you must do one
|
||||||
|
of these things:
|
||||||
|
|
||||||
|
a) Accompany the work with the complete corresponding
|
||||||
|
machine-readable source code for the Library including whatever
|
||||||
|
changes were used in the work (which must be distributed under
|
||||||
|
Sections 1 and 2 above); and, if the work is an executable linked
|
||||||
|
with the Library, with the complete machine-readable "work that
|
||||||
|
uses the Library", as object code and/or source code, so that the
|
||||||
|
user can modify the Library and then relink to produce a modified
|
||||||
|
executable containing the modified Library. (It is understood
|
||||||
|
that the user who changes the contents of definitions files in the
|
||||||
|
Library will not necessarily be able to recompile the application
|
||||||
|
to use the modified definitions.)
|
||||||
|
|
||||||
|
b) Use a suitable shared library mechanism for linking with the
|
||||||
|
Library. A suitable mechanism is one that (1) uses at run time a
|
||||||
|
copy of the library already present on the user's computer system,
|
||||||
|
rather than copying library functions into the executable, and (2)
|
||||||
|
will operate properly with a modified version of the library, if
|
||||||
|
the user installs one, as long as the modified version is
|
||||||
|
interface-compatible with the version that the work was made with.
|
||||||
|
|
||||||
|
c) Accompany the work with a written offer, valid for at
|
||||||
|
least three years, to give the same user the materials
|
||||||
|
specified in Subsection 6a, above, for a charge no more
|
||||||
|
than the cost of performing this distribution.
|
||||||
|
|
||||||
|
d) If distribution of the work is made by offering access to copy
|
||||||
|
from a designated place, offer equivalent access to copy the above
|
||||||
|
specified materials from the same place.
|
||||||
|
|
||||||
|
e) Verify that the user has already received a copy of these
|
||||||
|
materials or that you have already sent this user a copy.
|
||||||
|
|
||||||
|
For an executable, the required form of the "work that uses the
|
||||||
|
Library" must include any data and utility programs needed for
|
||||||
|
reproducing the executable from it. However, as a special exception,
|
||||||
|
the materials to be distributed need not include anything that is
|
||||||
|
normally distributed (in either source or binary form) with the major
|
||||||
|
components (compiler, kernel, and so on) of the operating system on
|
||||||
|
which the executable runs, unless that component itself accompanies
|
||||||
|
the executable.
|
||||||
|
|
||||||
|
It may happen that this requirement contradicts the license
|
||||||
|
restrictions of other proprietary libraries that do not normally
|
||||||
|
accompany the operating system. Such a contradiction means you cannot
|
||||||
|
use both them and the Library together in an executable that you
|
||||||
|
distribute.
|
||||||
|
|
||||||
|
7. You may place library facilities that are a work based on the
|
||||||
|
Library side-by-side in a single library together with other library
|
||||||
|
facilities not covered by this License, and distribute such a combined
|
||||||
|
library, provided that the separate distribution of the work based on
|
||||||
|
the Library and of the other library facilities is otherwise
|
||||||
|
permitted, and provided that you do these two things:
|
||||||
|
|
||||||
|
a) Accompany the combined library with a copy of the same work
|
||||||
|
based on the Library, uncombined with any other library
|
||||||
|
facilities. This must be distributed under the terms of the
|
||||||
|
Sections above.
|
||||||
|
|
||||||
|
b) Give prominent notice with the combined library of the fact
|
||||||
|
that part of it is a work based on the Library, and explaining
|
||||||
|
where to find the accompanying uncombined form of the same work.
|
||||||
|
|
||||||
|
8. You may not copy, modify, sublicense, link with, or distribute
|
||||||
|
the Library except as expressly provided under this License. Any
|
||||||
|
attempt otherwise to copy, modify, sublicense, link with, or
|
||||||
|
distribute the Library is void, and will automatically terminate your
|
||||||
|
rights under this License. However, parties who have received copies,
|
||||||
|
or rights, from you under this License will not have their licenses
|
||||||
|
terminated so long as such parties remain in full compliance.
|
||||||
|
|
||||||
|
9. You are not required to accept this License, since you have not
|
||||||
|
signed it. However, nothing else grants you permission to modify or
|
||||||
|
distribute the Library or its derivative works. These actions are
|
||||||
|
prohibited by law if you do not accept this License. Therefore, by
|
||||||
|
modifying or distributing the Library (or any work based on the
|
||||||
|
Library), you indicate your acceptance of this License to do so, and
|
||||||
|
all its terms and conditions for copying, distributing or modifying
|
||||||
|
the Library or works based on it.
|
||||||
|
|
||||||
|
10. Each time you redistribute the Library (or any work based on the
|
||||||
|
Library), the recipient automatically receives a license from the
|
||||||
|
original licensor to copy, distribute, link with or modify the Library
|
||||||
|
subject to these terms and conditions. You may not impose any further
|
||||||
|
restrictions on the recipients' exercise of the rights granted herein.
|
||||||
|
You are not responsible for enforcing compliance by third parties with
|
||||||
|
this License.
|
||||||
|
|
||||||
|
11. If, as a consequence of a court judgment or allegation of patent
|
||||||
|
infringement or for any other reason (not limited to patent issues),
|
||||||
|
conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot
|
||||||
|
distribute so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you
|
||||||
|
may not distribute the Library at all. For example, if a patent
|
||||||
|
license would not permit royalty-free redistribution of the Library by
|
||||||
|
all those who receive copies directly or indirectly through you, then
|
||||||
|
the only way you could satisfy both it and this License would be to
|
||||||
|
refrain entirely from distribution of the Library.
|
||||||
|
|
||||||
|
If any portion of this section is held invalid or unenforceable under any
|
||||||
|
particular circumstance, the balance of the section is intended to apply,
|
||||||
|
and the section as a whole is intended to apply in other circumstances.
|
||||||
|
|
||||||
|
It is not the purpose of this section to induce you to infringe any
|
||||||
|
patents or other property right claims or to contest validity of any
|
||||||
|
such claims; this section has the sole purpose of protecting the
|
||||||
|
integrity of the free software distribution system which is
|
||||||
|
implemented by public license practices. Many people have made
|
||||||
|
generous contributions to the wide range of software distributed
|
||||||
|
through that system in reliance on consistent application of that
|
||||||
|
system; it is up to the author/donor to decide if he or she is willing
|
||||||
|
to distribute software through any other system and a licensee cannot
|
||||||
|
impose that choice.
|
||||||
|
|
||||||
|
This section is intended to make thoroughly clear what is believed to
|
||||||
|
be a consequence of the rest of this License.
|
||||||
|
|
||||||
|
12. If the distribution and/or use of the Library is restricted in
|
||||||
|
certain countries either by patents or by copyrighted interfaces, the
|
||||||
|
original copyright holder who places the Library under this License may add
|
||||||
|
an explicit geographical distribution limitation excluding those countries,
|
||||||
|
so that distribution is permitted only in or among countries not thus
|
||||||
|
excluded. In such case, this License incorporates the limitation as if
|
||||||
|
written in the body of this License.
|
||||||
|
|
||||||
|
13. The Free Software Foundation may publish revised and/or new
|
||||||
|
versions of the Lesser General Public License from time to time.
|
||||||
|
Such new versions will be similar in spirit to the present version,
|
||||||
|
but may differ in detail to address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the Library
|
||||||
|
specifies a version number of this License which applies to it and
|
||||||
|
"any later version", you have the option of following the terms and
|
||||||
|
conditions either of that version or of any later version published by
|
||||||
|
the Free Software Foundation. If the Library does not specify a
|
||||||
|
license version number, you may choose any version ever published by
|
||||||
|
the Free Software Foundation.
|
||||||
|
|
||||||
|
14. If you wish to incorporate parts of the Library into other free
|
||||||
|
programs whose distribution conditions are incompatible with these,
|
||||||
|
write to the author to ask for permission. For software which is
|
||||||
|
copyrighted by the Free Software Foundation, write to the Free
|
||||||
|
Software Foundation; we sometimes make exceptions for this. Our
|
||||||
|
decision will be guided by the two goals of preserving the free status
|
||||||
|
of all derivatives of our free software and of promoting the sharing
|
||||||
|
and reuse of software generally.
|
||||||
|
|
||||||
|
NO WARRANTY
|
||||||
|
|
||||||
|
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||||
|
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||||
|
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||||
|
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||||
|
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||||
|
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||||
|
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||||
|
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||||
|
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||||
|
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||||
|
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||||
|
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||||
|
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||||
|
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||||
|
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||||
|
DAMAGES.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Libraries
|
||||||
|
|
||||||
|
If you develop a new library, and you want it to be of the greatest
|
||||||
|
possible use to the public, we recommend making it free software that
|
||||||
|
everyone can redistribute and change. You can do so by permitting
|
||||||
|
redistribution under these terms (or, alternatively, under the terms of the
|
||||||
|
ordinary General Public License).
|
||||||
|
|
||||||
|
To apply these terms, attach the following notices to the library. It is
|
||||||
|
safest to attach them to the start of each source file to most effectively
|
||||||
|
convey the exclusion of warranty; and each file should have at least the
|
||||||
|
"copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the library's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library 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
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or your
|
||||||
|
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||||
|
necessary. Here is a sample; alter the names:
|
||||||
|
|
||||||
|
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||||
|
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||||
|
|
||||||
|
<signature of Ty Coon>, 1 April 1990
|
||||||
|
Ty Coon, President of Vice
|
||||||
|
|
||||||
|
That's all there is to it!
|
151
contrib/mempattern.c
Normal file
151
contrib/mempattern.c
Normal file
|
@ -0,0 +1,151 @@
|
||||||
|
/* Copyright (C) CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
|
||||||
|
|
||||||
|
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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "contrib/mempattern.h"
|
||||||
|
#include "contrib/ucw/mempool.h"
|
||||||
|
|
||||||
|
static void mm_nofree(void *p)
|
||||||
|
{
|
||||||
|
/* nop */
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *mm_malloc(void *ctx, size_t n)
|
||||||
|
{
|
||||||
|
(void)ctx;
|
||||||
|
return malloc(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *mm_alloc(knot_mm_t *mm, size_t size)
|
||||||
|
{
|
||||||
|
if (mm) {
|
||||||
|
return mm->alloc(mm->ctx, size);
|
||||||
|
} else {
|
||||||
|
return malloc(size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void *mm_calloc(knot_mm_t *mm, size_t nmemb, size_t size)
|
||||||
|
{
|
||||||
|
if (nmemb == 0 || size == 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (mm) {
|
||||||
|
size_t total_size = nmemb * size;
|
||||||
|
if (total_size / nmemb != size) { // Overflow check
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
void *mem = mm_alloc(mm, total_size);
|
||||||
|
if (mem == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return memset(mem, 0, total_size);
|
||||||
|
} else {
|
||||||
|
return calloc(nmemb, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void *mm_realloc(knot_mm_t *mm, void *what, size_t size, size_t prev_size)
|
||||||
|
{
|
||||||
|
if (mm) {
|
||||||
|
void *p = mm->alloc(mm->ctx, size);
|
||||||
|
if (p == NULL) {
|
||||||
|
return NULL;
|
||||||
|
} else {
|
||||||
|
if (what) {
|
||||||
|
memcpy(p, what,
|
||||||
|
prev_size < size ? prev_size : size);
|
||||||
|
}
|
||||||
|
mm_free(mm, what);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return realloc(what, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char *mm_strdup(knot_mm_t *mm, const char *s)
|
||||||
|
{
|
||||||
|
if (s == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (mm) {
|
||||||
|
size_t len = strlen(s) + 1;
|
||||||
|
void *mem = mm_alloc(mm, len);
|
||||||
|
if (mem == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return memcpy(mem, s, len);
|
||||||
|
} else {
|
||||||
|
return strdup(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void mm_free(knot_mm_t *mm, void *what)
|
||||||
|
{
|
||||||
|
if (mm) {
|
||||||
|
if (mm->free) {
|
||||||
|
mm->free(what);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
free(what);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void mm_ctx_init(knot_mm_t *mm)
|
||||||
|
{
|
||||||
|
mm->ctx = NULL;
|
||||||
|
mm->alloc = mm_malloc;
|
||||||
|
mm->free = free;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mm_ctx_mempool(knot_mm_t *mm, size_t chunk_size)
|
||||||
|
{
|
||||||
|
mm->ctx = mp_new(chunk_size);
|
||||||
|
mm->alloc = (knot_mm_alloc_t)mp_alloc;
|
||||||
|
mm->free = mm_nofree;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Code in addition to Knot's mempattern. */
|
||||||
|
|
||||||
|
void *mm_malloc_aligned(void *ctx, size_t n)
|
||||||
|
{
|
||||||
|
size_t alignment = (size_t)ctx;
|
||||||
|
void *res;
|
||||||
|
int err = posix_memalign(&res, alignment, n);
|
||||||
|
if (err == 0) {
|
||||||
|
return res;
|
||||||
|
} else {
|
||||||
|
assert(err == -1 && errno == ENOMEM);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
knot_mm_t * mm_ctx_mempool2(size_t chunk_size)
|
||||||
|
{
|
||||||
|
knot_mm_t pool_tmp;
|
||||||
|
mm_ctx_mempool(&pool_tmp, chunk_size);
|
||||||
|
knot_mm_t *pool = mm_alloc(&pool_tmp, sizeof(*pool));
|
||||||
|
if (!pool) {
|
||||||
|
mp_delete(pool_tmp.ctx);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
memcpy(pool, &pool_tmp, sizeof(*pool));
|
||||||
|
return pool;
|
||||||
|
}
|
||||||
|
|
92
contrib/mempattern.h
Normal file
92
contrib/mempattern.h
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
/* Copyright (C) CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
|
||||||
|
|
||||||
|
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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Memory allocation related functions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <libknot/mm_ctx.h>
|
||||||
|
#include "contrib/ucw/mempool.h"
|
||||||
|
#include "lib/defines.h"
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/*! \brief Default memory block size. */
|
||||||
|
#define MM_DEFAULT_BLKSIZE 4096
|
||||||
|
|
||||||
|
/*! \brief Allocs using 'mm' if any, uses system malloc() otherwise. */
|
||||||
|
KR_EXPORT
|
||||||
|
void *mm_alloc(knot_mm_t *mm, size_t size);
|
||||||
|
|
||||||
|
/*! \brief Callocs using 'mm' if any, uses system calloc() otherwise. */
|
||||||
|
void *mm_calloc(knot_mm_t *mm, size_t nmemb, size_t size);
|
||||||
|
|
||||||
|
/*! \brief Reallocs using 'mm' if any, uses system realloc() otherwise. */
|
||||||
|
KR_EXPORT
|
||||||
|
void *mm_realloc(knot_mm_t *mm, void *what, size_t size, size_t prev_size);
|
||||||
|
|
||||||
|
/*! \brief Strdups using 'mm' if any, uses system strdup() otherwise. */
|
||||||
|
char *mm_strdup(knot_mm_t *mm, const char *s);
|
||||||
|
|
||||||
|
/*! \brief Free using 'mm' if any, uses system free() otherwise. */
|
||||||
|
KR_EXPORT
|
||||||
|
void mm_free(knot_mm_t *mm, void *what);
|
||||||
|
|
||||||
|
/*! \brief Initialize default memory allocation context. */
|
||||||
|
void mm_ctx_init(knot_mm_t *mm);
|
||||||
|
|
||||||
|
/*! \brief Memory pool context. */
|
||||||
|
void mm_ctx_mempool(knot_mm_t *mm, size_t chunk_size);
|
||||||
|
|
||||||
|
|
||||||
|
/* API in addition to Knot's mempattern. */
|
||||||
|
|
||||||
|
/*! \brief New memory pool context, allocated on itself. */
|
||||||
|
KR_EXPORT knot_mm_t * mm_ctx_mempool2(size_t chunk_size);
|
||||||
|
|
||||||
|
/*! \brief Delete a memory pool. OK to call on a non-pool. */
|
||||||
|
static inline void mm_ctx_delete(knot_mm_t *mm)
|
||||||
|
{
|
||||||
|
/* The mp_alloc comparison bears a risk of missing the private symbol from knot. */
|
||||||
|
if (mm && mm->ctx && mm->alloc == (knot_mm_alloc_t)mp_alloc)
|
||||||
|
mp_delete(mm->ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! \brief Readability: avoid const-casts in code. */
|
||||||
|
static inline void free_const(const void *what)
|
||||||
|
{
|
||||||
|
free((void *)what);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! \brief posix_memalign() wrapper. */
|
||||||
|
void *mm_malloc_aligned(void *ctx, size_t n);
|
||||||
|
|
||||||
|
/*! \brief Initialize mm with malloc+free with specified alignment (a power of two). */
|
||||||
|
static inline void mm_ctx_init_aligned(knot_mm_t *mm, size_t alignment)
|
||||||
|
{
|
||||||
|
assert(__builtin_popcount(alignment) == 1);
|
||||||
|
mm_ctx_init(mm);
|
||||||
|
mm->ctx = (uint8_t *)NULL + alignment; /*< roundabout to satisfy linters */
|
||||||
|
/* posix_memalign() doesn't allow alignment < sizeof(void*),
|
||||||
|
* and there's no point in using it for small values anyway,
|
||||||
|
* as plain malloc() guarantees at least max_align_t. */
|
||||||
|
if (alignment > sizeof(max_align_t)) {
|
||||||
|
mm->alloc = mm_malloc_aligned;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
28
contrib/meson.build
Normal file
28
contrib/meson.build
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
# contrib
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
contrib_src = files([
|
||||||
|
'ccan/asprintf/asprintf.c',
|
||||||
|
'ccan/json/json.c',
|
||||||
|
'ucw/mempool.c',
|
||||||
|
'ucw/mempool-fmt.c',
|
||||||
|
'mempattern.c',
|
||||||
|
'murmurhash3/murmurhash3.c',
|
||||||
|
'base32hex.c',
|
||||||
|
'base64.c',
|
||||||
|
'base64url.c'
|
||||||
|
])
|
||||||
|
|
||||||
|
contrib_inc = include_directories('.', '..')
|
||||||
|
|
||||||
|
contrib_lib = static_library(
|
||||||
|
'contrib',
|
||||||
|
contrib_src,
|
||||||
|
include_directories: contrib_inc,
|
||||||
|
dependencies: libknot,
|
||||||
|
)
|
||||||
|
|
||||||
|
contrib_dep = declare_dependency(
|
||||||
|
include_directories: contrib_inc,
|
||||||
|
link_with: contrib_lib,
|
||||||
|
)
|
1
contrib/murmurhash3/LICENSE
Symbolic link
1
contrib/murmurhash3/LICENSE
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../licenses/CC0
|
76
contrib/murmurhash3/murmurhash3.c
Normal file
76
contrib/murmurhash3/murmurhash3.c
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
/* This is MurmurHash3. The original C++ code was placed in the public domain
|
||||||
|
* by its author, Austin Appleby.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
|
* Source: https://github.com/aappleby/smhasher/blob/master/src/MurmurHash3.cpp */
|
||||||
|
|
||||||
|
#include "murmurhash3.h"
|
||||||
|
#include "string.h"
|
||||||
|
|
||||||
|
static inline uint32_t fmix(uint32_t h)
|
||||||
|
{
|
||||||
|
h ^= h >> 16;
|
||||||
|
h *= 0x85ebca6b;
|
||||||
|
h ^= h >> 13;
|
||||||
|
h *= 0xc2b2ae35;
|
||||||
|
h ^= h >> 16;
|
||||||
|
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint32_t rotl32(uint32_t x, int8_t r)
|
||||||
|
{
|
||||||
|
return (x << r) | (x >> (32 - r));
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t hash(const char* data, size_t len_)
|
||||||
|
{
|
||||||
|
const int len = (int) len_;
|
||||||
|
const int nblocks = len / 4;
|
||||||
|
|
||||||
|
uint32_t h1 = 0xc062fb4a;
|
||||||
|
|
||||||
|
uint32_t c1 = 0xcc9e2d51;
|
||||||
|
uint32_t c2 = 0x1b873593;
|
||||||
|
|
||||||
|
//----------
|
||||||
|
// body
|
||||||
|
|
||||||
|
for(int i = 0; i < nblocks; ++i)
|
||||||
|
{
|
||||||
|
uint32_t k1;
|
||||||
|
memcpy(&k1, data + i * sizeof(k1), sizeof(k1));
|
||||||
|
|
||||||
|
k1 *= c1;
|
||||||
|
k1 = rotl32(k1, 15);
|
||||||
|
k1 *= c2;
|
||||||
|
|
||||||
|
h1 ^= k1;
|
||||||
|
h1 = rotl32(h1, 13);
|
||||||
|
h1 = h1*5+0xe6546b64;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------
|
||||||
|
// tail
|
||||||
|
|
||||||
|
const uint8_t * tail = (const uint8_t*)(data + nblocks*4);
|
||||||
|
|
||||||
|
uint32_t k1 = 0;
|
||||||
|
|
||||||
|
switch(len & 3)
|
||||||
|
{
|
||||||
|
case 3: k1 ^= tail[2] << 16;
|
||||||
|
case 2: k1 ^= tail[1] << 8;
|
||||||
|
case 1: k1 ^= tail[0];
|
||||||
|
k1 *= c1; k1 = rotl32(k1,15); k1 *= c2; h1 ^= k1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------
|
||||||
|
// finalization
|
||||||
|
|
||||||
|
h1 ^= len;
|
||||||
|
|
||||||
|
h1 = fmix(h1);
|
||||||
|
|
||||||
|
return h1;
|
||||||
|
}
|
9
contrib/murmurhash3/murmurhash3.h
Normal file
9
contrib/murmurhash3/murmurhash3.h
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
/* SPDX-License-Identifier: CC0-1.0
|
||||||
|
* Source: https://github.com/aappleby/smhasher/blob/master/src/MurmurHash3.cpp */
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
uint32_t hash(const char* data, size_t len);
|
10
contrib/murmurhash3/murmurhash3.spdx
Normal file
10
contrib/murmurhash3/murmurhash3.spdx
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
SPDXVersion: SPDX-2.1
|
||||||
|
DataLicense: CC0-1.0
|
||||||
|
SPDXID: SPDXRef-DOCUMENT
|
||||||
|
DocumentName: ccan-json
|
||||||
|
DocumentNamespace: http://spdx.org/spdxdocs/spdx-v2.1-d9b4db4c-062f-4add-89b6-f603224f5a2c
|
||||||
|
|
||||||
|
PackageName: json
|
||||||
|
PackageDownloadLocation: git+https://github.com/aappleby/smhasher.git@73e075b203d9c76cd1e20d6c8907c2983d653f33#MurmurHash3.cpp
|
||||||
|
PackageOriginator: Person: Austin Appleby (aappleby@gmail.com)
|
||||||
|
PackageLicenseDeclared: CC0-1.0
|
1
contrib/ucw/LICENSE
Symbolic link
1
contrib/ucw/LICENSE
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../licenses/LGPL2
|
38
contrib/ucw/alloc.h
Normal file
38
contrib/ucw/alloc.h
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* UCW Library -- Generic allocators
|
||||||
|
*
|
||||||
|
* (c) 2014 Martin Mares <mj@ucw.cz>
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||||
|
* Source: https://www.ucw.cz/libucw/
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _UCW_ALLOC_H
|
||||||
|
#define _UCW_ALLOC_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This structure describes a generic allocator. It provides pointers
|
||||||
|
* to three functions, which handle the actual (re)allocations.
|
||||||
|
**/
|
||||||
|
struct ucw_allocator {
|
||||||
|
void * (*alloc)(struct ucw_allocator *alloc, size_t size);
|
||||||
|
void * (*realloc)(struct ucw_allocator *alloc, void *ptr, size_t old_size, size_t new_size);
|
||||||
|
void (*free)(struct ucw_allocator *alloc, void *ptr);
|
||||||
|
};
|
||||||
|
|
||||||
|
/* alloc-std.c */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [[std]]
|
||||||
|
* This allocator uses <<basics:xmalloc()>>, <<basics:xrealloc()>> and <<basics:xfree()>>. The memory
|
||||||
|
* it allocates is left uninitialized.
|
||||||
|
**/
|
||||||
|
extern struct ucw_allocator ucw_allocator_std;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [[zeroing]]
|
||||||
|
* This allocator uses <<basics:xmalloc()>>, <<basics:xrealloc()>> and <<basics:xfree()>>. All memory
|
||||||
|
* is zeroed upon allocation.
|
||||||
|
**/
|
||||||
|
extern struct ucw_allocator ucw_allocator_zeroed;
|
||||||
|
|
||||||
|
#endif
|
58
contrib/ucw/config.h
Normal file
58
contrib/ucw/config.h
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* UCW Library -- Configuration-Dependent Definitions
|
||||||
|
*
|
||||||
|
* (c) 1997--2012 Martin Mares <mj@ucw.cz>
|
||||||
|
* (c) 2006 Robert Spalek <robert@ucw.cz>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||||
|
* Source: https://www.ucw.cz/libucw/
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _UCW_CONFIG_H
|
||||||
|
#define _UCW_CONFIG_H
|
||||||
|
|
||||||
|
/* Default page size and pointer alignment */
|
||||||
|
#ifndef CPU_PAGE_SIZE
|
||||||
|
#define CPU_PAGE_SIZE 4096
|
||||||
|
#endif
|
||||||
|
#define CPU_STRUCT_ALIGN sizeof(void *)
|
||||||
|
|
||||||
|
/* Tell libc we're going to use all extensions available */
|
||||||
|
|
||||||
|
#ifndef _GNU_SOURCE
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Types (based on standard C99 integers) */
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
typedef uint8_t byte; /** Exactly 8 bits, unsigned **/
|
||||||
|
typedef uint8_t u8; /** Exactly 8 bits, unsigned **/
|
||||||
|
typedef int8_t s8; /** Exactly 8 bits, signed **/
|
||||||
|
typedef uint16_t u16; /** Exactly 16 bits, unsigned **/
|
||||||
|
typedef int16_t s16; /** Exactly 16 bits, signed **/
|
||||||
|
typedef uint32_t u32; /** Exactly 32 bits, unsigned **/
|
||||||
|
typedef int32_t s32; /** Exactly 32 bits, signed **/
|
||||||
|
typedef uint64_t u64; /** Exactly 64 bits, unsigned **/
|
||||||
|
typedef int64_t s64; /** Exactly 64 bits, signed **/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef uint /* Redefining typedef is a C11 feature. */
|
||||||
|
typedef unsigned int uint; /** A better pronounceable alias for `unsigned int` **/
|
||||||
|
#define uint uint
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef s64 timestamp_t; /** Milliseconds since an unknown epoch **/
|
||||||
|
|
||||||
|
// FIXME: This should be removed soon
|
||||||
|
typedef uint uns; /** Backwards compatible alias for `uint' ***/
|
||||||
|
|
||||||
|
#ifdef CONFIG_UCW_LARGE_FILES
|
||||||
|
typedef s64 ucw_off_t; /** File position (either 32- or 64-bit, depending on `CONFIG_UCW_LARGE_FILES`). **/
|
||||||
|
#else
|
||||||
|
typedef s32 ucw_off_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
125
contrib/ucw/lib.h
Normal file
125
contrib/ucw/lib.h
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
/*
|
||||||
|
* The UCW Library -- Miscellaneous Functions
|
||||||
|
*
|
||||||
|
* (c) 1997--2014 Martin Mares <mj@ucw.cz>
|
||||||
|
* (c) 2005--2014 Tomas Valla <tom@ucw.cz>
|
||||||
|
* (c) 2006 Robert Spalek <robert@ucw.cz>
|
||||||
|
* (c) 2007 Pavel Charvat <pchar@ucw.cz>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||||
|
* Source: https://www.ucw.cz/libucw/
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _UCW_LIB_H
|
||||||
|
#define _UCW_LIB_H
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_UCW_CLEAN_ABI
|
||||||
|
#define assert_failed ucw_assert_failed
|
||||||
|
#define assert_failed_msg ucw_assert_failed_msg
|
||||||
|
#define assert_failed_noinfo ucw_assert_failed_noinfo
|
||||||
|
#define big_alloc ucw_big_alloc
|
||||||
|
#define big_alloc_zero ucw_big_alloc_zero
|
||||||
|
#define big_free ucw_big_free
|
||||||
|
#define die ucw_die
|
||||||
|
#define log_die_hook ucw_log_die_hook
|
||||||
|
#define log_file ucw_log_file
|
||||||
|
#define log_fork ucw_log_fork
|
||||||
|
#define log_init ucw_log_init
|
||||||
|
#define log_pid ucw_log_pid
|
||||||
|
#define log_title ucw_log_title
|
||||||
|
#define msg ucw_msg
|
||||||
|
#define page_alloc ucw_page_alloc
|
||||||
|
#define page_alloc_zero ucw_page_alloc_zero
|
||||||
|
#define page_free ucw_page_free
|
||||||
|
#define page_realloc ucw_page_realloc
|
||||||
|
#define random_max ucw_random_max
|
||||||
|
#define random_max_u64 ucw_random_max_u64
|
||||||
|
#define random_u32 ucw_random_u32
|
||||||
|
#define random_u64 ucw_random_u64
|
||||||
|
#define vdie ucw_vdie
|
||||||
|
#define vmsg ucw_vmsg
|
||||||
|
#define xfree ucw_xfree
|
||||||
|
#define xmalloc ucw_xmalloc
|
||||||
|
#define xmalloc_zero ucw_xmalloc_zero
|
||||||
|
#define xrealloc ucw_xrealloc
|
||||||
|
#define xstrdup ucw_xstrdup
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*** === Macros for handling structures, offsets and alignment ***/
|
||||||
|
|
||||||
|
#define CHECK_PTR_TYPE(x, type) ((x)-(type)(x) + (type)(x)) /** Check that a pointer @x is of type @type. Fail compilation if not. **/
|
||||||
|
#define PTR_TO(s, i) &((s*)0)->i /** Return OFFSETOF() in form of a pointer. **/
|
||||||
|
#define OFFSETOF(s, i) ((uint)offsetof(s, i)) /** Offset of item @i from the start of structure @s **/
|
||||||
|
#define SKIP_BACK(s, i, p) ((s *)((char *)p - OFFSETOF(s, i))) /** Given a pointer @p to item @i of structure @s, return a pointer to the start of the struct. **/
|
||||||
|
|
||||||
|
/** Align an integer @s to the nearest higher multiple of @a (which should be a power of two) **/
|
||||||
|
#define ALIGN_TO(s, a) (((s)+a-1)&~(a-1))
|
||||||
|
|
||||||
|
/** Align a pointer @p to the nearest higher multiple of @s. **/
|
||||||
|
#define ALIGN_PTR(p, s) ((uintptr_t)(p) % (s) ? (typeof(p))((uintptr_t)(p) + (s) - (uintptr_t)(p) % (s)) : (p))
|
||||||
|
|
||||||
|
#define UNALIGNED_PART(ptr, type) (((uintptr_t) (ptr)) % sizeof(type))
|
||||||
|
|
||||||
|
/*** === Other utility macros ***/
|
||||||
|
|
||||||
|
#define MIN(a,b) (((a)<(b))?(a):(b)) /** Minimum of two numbers **/
|
||||||
|
#define MAX(a,b) (((a)>(b))?(a):(b)) /** Maximum of two numbers **/
|
||||||
|
#define CLAMP(x,min,max) ({ typeof(x) _t=x; (_t < min) ? min : (_t > max) ? max : _t; }) /** Clip a number @x to interval [@min,@max] **/
|
||||||
|
#define ABS(x) ((x) < 0 ? -(x) : (x)) /** Absolute value **/
|
||||||
|
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(*(a))) /** The number of elements of an array **/
|
||||||
|
#define STRINGIFY(x) #x /** Convert macro parameter to a string **/
|
||||||
|
#define STRINGIFY_EXPANDED(x) STRINGIFY(x) /** Convert an expanded macro parameter to a string **/
|
||||||
|
#define GLUE(x,y) x##y /** Glue two tokens together **/
|
||||||
|
#define GLUE_(x,y) x##_##y /** Glue two tokens together, separating them by an underscore **/
|
||||||
|
|
||||||
|
#define COMPARE(x,y) do { if ((x)<(y)) return -1; if ((x)>(y)) return 1; } while(0) /** Numeric comparison function for qsort() **/
|
||||||
|
#define REV_COMPARE(x,y) COMPARE(y,x) /** Reverse numeric comparison **/
|
||||||
|
#define COMPARE_LT(x,y) do { if ((x)<(y)) return 1; if ((x)>(y)) return 0; } while(0)
|
||||||
|
#define COMPARE_GT(x,y) COMPARE_LT(y,x)
|
||||||
|
|
||||||
|
#define ROL(x, bits) (((x) << (bits)) | ((uint)(x) >> (sizeof(uint)*8 - (bits)))) /** Bitwise rotation of an unsigned int to the left **/
|
||||||
|
#define ROR(x, bits) (((uint)(x) >> (bits)) | ((x) << (sizeof(uint)*8 - (bits)))) /** Bitwise rotation of an unsigned int to the right **/
|
||||||
|
|
||||||
|
/*** === Shortcuts for GCC Extensions ***/
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
|
||||||
|
#include "ccan/compiler/compiler.h"
|
||||||
|
#define FORMAT_CHECK(x,y,z) __attribute__((format(x,y,z))) /** Checking of printf-like format strings **/
|
||||||
|
#define likely(x) __builtin_expect((x),1) /** Use `if (likely(@x))` if @x is almost always true **/
|
||||||
|
#define unlikely(x) __builtin_expect((x),0) /** Use `if (unlikely(@x))` to hint that @x is almost always false **/
|
||||||
|
|
||||||
|
#if __GNUC__ >= 4 || __GNUC__ == 3 && __GNUC_MINOR__ >= 3
|
||||||
|
#define ALWAYS_INLINE inline __attribute__((always_inline)) /** Forcibly inline **/
|
||||||
|
#define NO_INLINE __attribute__((noinline)) /** Forcibly uninline **/
|
||||||
|
#else
|
||||||
|
#define ALWAYS_INLINE inline
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __GNUC__ >= 4
|
||||||
|
#define LIKE_MALLOC __attribute__((malloc)) /** Function returns a "new" pointer **/
|
||||||
|
#define SENTINEL_CHECK __attribute__((sentinel)) /** The last argument must be NULL **/
|
||||||
|
#else
|
||||||
|
#define LIKE_MALLOC
|
||||||
|
#define SENTINEL_CHECK
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error This program requires the GNU C compiler.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/***
|
||||||
|
* [[logging]]
|
||||||
|
*
|
||||||
|
* === Basic logging functions (see <<log:,Logging>> and <ucw/log.h> for more)
|
||||||
|
***/
|
||||||
|
|
||||||
|
#define DBG(x, ...) do { } while(0)
|
||||||
|
#define DBG_SPOT do { } while(0)
|
||||||
|
#define ASSERT(x)
|
||||||
|
|
||||||
|
#endif
|
10
contrib/ucw/libucw.spdx
Normal file
10
contrib/ucw/libucw.spdx
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
SPDXVersion: SPDX-2.1
|
||||||
|
DataLicense: CC0-1.0
|
||||||
|
SPDXID: SPDXRef-DOCUMENT
|
||||||
|
DocumentName: libucw
|
||||||
|
DocumentNamespace: http://spdx.org/spdxdocs/spdx-v2.1-c3d39e26-6b71-46d4-88ea-e52750932ff3
|
||||||
|
|
||||||
|
PackageName: libucw
|
||||||
|
PackageDownloadLocation: git://git.ucw.cz/libucw.git@f1bde7104b04d5254d1d1d7dcc8de790a43a416f#ucw/
|
||||||
|
PackageOriginator: Organization: United Computer Wizards
|
||||||
|
PackageLicenseDeclared: LGPL-2.1-or-later
|
99
contrib/ucw/mempool-fmt.c
Normal file
99
contrib/ucw/mempool-fmt.c
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
/*
|
||||||
|
* UCW Library -- Memory Pools (Formatting)
|
||||||
|
*
|
||||||
|
* (c) 2005 Martin Mares <mj@ucw.cz>
|
||||||
|
* (c) 2007 Pavel Charvat <pchar@ucw.cz>
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||||
|
* Source: https://www.ucw.cz/libucw/
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ucw/lib.h>
|
||||||
|
#include <ucw/mempool.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/* FIXME: migrate to Knot DNS version of mempools. */
|
||||||
|
#pragma GCC diagnostic ignored "-Wpointer-arith"
|
||||||
|
|
||||||
|
static char *
|
||||||
|
mp_vprintf_at(struct mempool *mp, size_t ofs, const char *fmt, va_list args)
|
||||||
|
{
|
||||||
|
char *ret = mp_grow(mp, ofs + 1) + ofs;
|
||||||
|
va_list args2;
|
||||||
|
va_copy(args2, args);
|
||||||
|
int cnt = vsnprintf(ret, mp_avail(mp) - ofs, fmt, args2);
|
||||||
|
va_end(args2);
|
||||||
|
if (cnt < 0)
|
||||||
|
{
|
||||||
|
/* Our C library doesn't support C99 return value of vsnprintf, so we need to iterate */
|
||||||
|
do
|
||||||
|
{
|
||||||
|
ret = mp_expand(mp) + ofs;
|
||||||
|
va_copy(args2, args);
|
||||||
|
cnt = vsnprintf(ret, mp_avail(mp) - ofs, fmt, args2);
|
||||||
|
va_end(args2);
|
||||||
|
}
|
||||||
|
while (cnt < 0);
|
||||||
|
}
|
||||||
|
else if ((uint)cnt >= mp_avail(mp) - ofs)
|
||||||
|
{
|
||||||
|
ret = mp_grow(mp, ofs + cnt + 1) + ofs;
|
||||||
|
va_copy(args2, args);
|
||||||
|
vsnprintf(ret, cnt + 1, fmt, args2);
|
||||||
|
va_end(args2);
|
||||||
|
}
|
||||||
|
mp_end(mp, ret + cnt + 1);
|
||||||
|
return ret - ofs;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
mp_vprintf(struct mempool *mp, const char *fmt, va_list args)
|
||||||
|
{
|
||||||
|
mp_start(mp, 1);
|
||||||
|
return mp_vprintf_at(mp, 0, fmt, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
mp_printf(struct mempool *p, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
char *res = mp_vprintf(p, fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
mp_vprintf_append(struct mempool *mp, char *ptr, const char *fmt, va_list args)
|
||||||
|
{
|
||||||
|
size_t ofs = mp_open(mp, ptr);
|
||||||
|
ASSERT(ofs && !ptr[ofs - 1]);
|
||||||
|
return mp_vprintf_at(mp, ofs - 1, fmt, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
mp_printf_append(struct mempool *mp, char *ptr, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
char *res = mp_vprintf_append(mp, ptr, fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef TEST
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
struct mempool *mp = mp_new(64);
|
||||||
|
char *x = mp_printf(mp, "<Hello, %s!>", "World");
|
||||||
|
fputs(x, stdout);
|
||||||
|
x = mp_printf_append(mp, x, "<Appended>");
|
||||||
|
fputs(x, stdout);
|
||||||
|
x = mp_printf(mp, "<Hello, %50s!>\n", "World");
|
||||||
|
fputs(x, stdout);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
601
contrib/ucw/mempool.c
Normal file
601
contrib/ucw/mempool.c
Normal file
|
@ -0,0 +1,601 @@
|
||||||
|
/*
|
||||||
|
* UCW Library -- Memory Pools (One-Time Allocation)
|
||||||
|
*
|
||||||
|
* (c) 1997--2014 Martin Mares <mj@ucw.cz>
|
||||||
|
* (c) 2007--2015 Pavel Charvat <pchar@ucw.cz>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||||
|
* Source: https://www.ucw.cz/libucw/
|
||||||
|
*/
|
||||||
|
|
||||||
|
#undef LOCAL_DEBUG
|
||||||
|
|
||||||
|
#include <ucw/config.h>
|
||||||
|
#include <ucw/lib.h>
|
||||||
|
#include <ucw/alloc.h>
|
||||||
|
#include <ucw/mempool.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/* FIXME: migrate to Knot DNS version of mempools. */
|
||||||
|
#pragma GCC diagnostic ignored "-Wpointer-arith"
|
||||||
|
|
||||||
|
#define MP_CHUNK_TAIL ALIGN_TO(sizeof(struct mempool_chunk), CPU_STRUCT_ALIGN)
|
||||||
|
#define MP_SIZE_MAX (SIZE_MAX - MP_CHUNK_TAIL - CPU_PAGE_SIZE)
|
||||||
|
|
||||||
|
struct mempool_chunk {
|
||||||
|
#ifdef CONFIG_DEBUG
|
||||||
|
struct mempool *pool; // Can be useful when analysing coredump for memory leaks
|
||||||
|
#endif
|
||||||
|
struct mempool_chunk *next;
|
||||||
|
size_t size;
|
||||||
|
};
|
||||||
|
|
||||||
|
static size_t
|
||||||
|
mp_align_size(size_t size)
|
||||||
|
{
|
||||||
|
#ifdef CONFIG_UCW_POOL_IS_MMAP
|
||||||
|
size = MAX(size, 64 + MP_CHUNK_TAIL);
|
||||||
|
return ALIGN_TO(size, CPU_PAGE_SIZE) - MP_CHUNK_TAIL;
|
||||||
|
#else
|
||||||
|
return ALIGN_TO(size, CPU_STRUCT_ALIGN);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *mp_allocator_alloc(struct ucw_allocator *a, size_t size)
|
||||||
|
{
|
||||||
|
struct mempool *mp = (struct mempool *) a;
|
||||||
|
return mp_alloc_fast(mp, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *mp_allocator_realloc(struct ucw_allocator *a, void *ptr, size_t old_size, size_t new_size)
|
||||||
|
{
|
||||||
|
if (new_size <= old_size)
|
||||||
|
return ptr;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* In the future, we might want to do something like mp_realloc(),
|
||||||
|
* but we have to check that it is indeed the last block in the pool.
|
||||||
|
*/
|
||||||
|
struct mempool *mp = (struct mempool *) a;
|
||||||
|
void *new = mp_alloc_fast(mp, new_size);
|
||||||
|
memcpy(new, ptr, old_size);
|
||||||
|
return new;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mp_allocator_free(struct ucw_allocator *a UNUSED, void *ptr UNUSED)
|
||||||
|
{
|
||||||
|
// Does nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mp_init(struct mempool *pool, size_t chunk_size)
|
||||||
|
{
|
||||||
|
chunk_size = mp_align_size(MAX(sizeof(struct mempool), chunk_size));
|
||||||
|
*pool = (struct mempool) {
|
||||||
|
.allocator = {
|
||||||
|
.alloc = mp_allocator_alloc,
|
||||||
|
.realloc = mp_allocator_realloc,
|
||||||
|
.free = mp_allocator_free,
|
||||||
|
},
|
||||||
|
.chunk_size = chunk_size,
|
||||||
|
.threshold = chunk_size >> 1,
|
||||||
|
.last_big = &pool->last_big
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *
|
||||||
|
mp_new_big_chunk(struct mempool *pool, size_t size)
|
||||||
|
{
|
||||||
|
struct mempool_chunk *chunk;
|
||||||
|
chunk = malloc(size + MP_CHUNK_TAIL);
|
||||||
|
if (!chunk)
|
||||||
|
return NULL;
|
||||||
|
chunk = (struct mempool_chunk *)((char *)chunk + size);
|
||||||
|
chunk->size = size;
|
||||||
|
if (pool)
|
||||||
|
pool->total_size += size + MP_CHUNK_TAIL;
|
||||||
|
return chunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mp_free_big_chunk(struct mempool *pool, struct mempool_chunk *chunk)
|
||||||
|
{
|
||||||
|
pool->total_size -= chunk->size + MP_CHUNK_TAIL;
|
||||||
|
free((void *)chunk - chunk->size);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *
|
||||||
|
mp_new_chunk(struct mempool *pool, size_t size)
|
||||||
|
{
|
||||||
|
#ifdef CONFIG_UCW_POOL_IS_MMAP
|
||||||
|
struct mempool_chunk *chunk;
|
||||||
|
chunk = page_alloc(size + MP_CHUNK_TAIL) + size;
|
||||||
|
chunk->size = size;
|
||||||
|
if (pool)
|
||||||
|
pool->total_size += size + MP_CHUNK_TAIL;
|
||||||
|
return chunk;
|
||||||
|
#else
|
||||||
|
return mp_new_big_chunk(pool, size);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mp_free_chunk(struct mempool *pool, struct mempool_chunk *chunk)
|
||||||
|
{
|
||||||
|
#ifdef CONFIG_UCW_POOL_IS_MMAP
|
||||||
|
pool->total_size -= chunk->size + MP_CHUNK_TAIL;
|
||||||
|
page_free((void *)chunk - chunk->size, chunk->size + MP_CHUNK_TAIL);
|
||||||
|
#else
|
||||||
|
mp_free_big_chunk(pool, chunk);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
struct mempool *
|
||||||
|
mp_new(size_t chunk_size)
|
||||||
|
{
|
||||||
|
chunk_size = mp_align_size(MAX(sizeof(struct mempool), chunk_size));
|
||||||
|
struct mempool_chunk *chunk = mp_new_chunk(NULL, chunk_size);
|
||||||
|
struct mempool *pool = (void *)chunk - chunk_size;
|
||||||
|
DBG("Creating mempool %p with %u bytes long chunks", pool, chunk_size);
|
||||||
|
chunk->next = NULL;
|
||||||
|
#ifdef CONFIG_DEBUG
|
||||||
|
chunk->pool = pool;
|
||||||
|
#endif
|
||||||
|
*pool = (struct mempool) {
|
||||||
|
.allocator = {
|
||||||
|
.alloc = mp_allocator_alloc,
|
||||||
|
.realloc = mp_allocator_realloc,
|
||||||
|
.free = mp_allocator_free,
|
||||||
|
},
|
||||||
|
.state = { .free = { chunk_size - sizeof(*pool) }, .last = { chunk } },
|
||||||
|
.chunk_size = chunk_size,
|
||||||
|
.threshold = chunk_size >> 1,
|
||||||
|
.last_big = &pool->last_big,
|
||||||
|
.total_size = chunk->size + MP_CHUNK_TAIL,
|
||||||
|
};
|
||||||
|
return pool;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mp_free_chain(struct mempool *pool, struct mempool_chunk *chunk)
|
||||||
|
{
|
||||||
|
while (chunk)
|
||||||
|
{
|
||||||
|
struct mempool_chunk *next = chunk->next;
|
||||||
|
mp_free_chunk(pool, chunk);
|
||||||
|
chunk = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mp_free_big_chain(struct mempool *pool, struct mempool_chunk *chunk)
|
||||||
|
{
|
||||||
|
while (chunk)
|
||||||
|
{
|
||||||
|
struct mempool_chunk *next = chunk->next;
|
||||||
|
mp_free_big_chunk(pool, chunk);
|
||||||
|
chunk = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mp_delete(struct mempool *pool)
|
||||||
|
{
|
||||||
|
DBG("Deleting mempool %p", pool);
|
||||||
|
mp_free_big_chain(pool, pool->state.last[1]);
|
||||||
|
mp_free_chain(pool, pool->unused);
|
||||||
|
mp_free_chain(pool, pool->state.last[0]); // can contain the mempool structure
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mp_flush(struct mempool *pool)
|
||||||
|
{
|
||||||
|
mp_free_big_chain(pool, pool->state.last[1]);
|
||||||
|
struct mempool_chunk *chunk, *next;
|
||||||
|
for (chunk = pool->state.last[0]; chunk && (void *)chunk - chunk->size != pool; chunk = next)
|
||||||
|
{
|
||||||
|
next = chunk->next;
|
||||||
|
chunk->next = pool->unused;
|
||||||
|
pool->unused = chunk;
|
||||||
|
}
|
||||||
|
pool->state.last[0] = chunk;
|
||||||
|
pool->state.free[0] = chunk ? chunk->size - sizeof(*pool) : 0;
|
||||||
|
pool->state.last[1] = NULL;
|
||||||
|
pool->state.free[1] = 0;
|
||||||
|
pool->state.next = NULL;
|
||||||
|
pool->last_big = &pool->last_big;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mp_stats_chain(struct mempool *pool, struct mempool_chunk *chunk, struct mempool_stats *stats, uint idx)
|
||||||
|
{
|
||||||
|
while (chunk)
|
||||||
|
{
|
||||||
|
stats->chain_size[idx] += chunk->size + MP_CHUNK_TAIL;
|
||||||
|
stats->chain_count[idx]++;
|
||||||
|
if (idx < 2)
|
||||||
|
{
|
||||||
|
stats->used_size += chunk->size;
|
||||||
|
if ((byte *)pool == (byte *)chunk - chunk->size)
|
||||||
|
stats->used_size -= sizeof(*pool);
|
||||||
|
}
|
||||||
|
chunk = chunk->next;
|
||||||
|
}
|
||||||
|
stats->total_size += stats->chain_size[idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mp_stats(struct mempool *pool, struct mempool_stats *stats)
|
||||||
|
{
|
||||||
|
bzero(stats, sizeof(*stats));
|
||||||
|
mp_stats_chain(pool, pool->state.last[0], stats, 0);
|
||||||
|
mp_stats_chain(pool, pool->state.last[1], stats, 1);
|
||||||
|
mp_stats_chain(pool, pool->unused, stats, 2);
|
||||||
|
stats->used_size -= pool->state.free[0] + pool->state.free[1];
|
||||||
|
ASSERT(stats->total_size == pool->total_size);
|
||||||
|
ASSERT(stats->used_size <= stats->total_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
u64
|
||||||
|
mp_total_size(struct mempool *pool)
|
||||||
|
{
|
||||||
|
return pool->total_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mp_shrink(struct mempool *pool, u64 min_total_size)
|
||||||
|
{
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
struct mempool_chunk *chunk = pool->unused;
|
||||||
|
if (!chunk || pool->total_size - (chunk->size + MP_CHUNK_TAIL) < min_total_size)
|
||||||
|
break;
|
||||||
|
pool->unused = chunk->next;
|
||||||
|
mp_free_chunk(pool, chunk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
mp_alloc_internal(struct mempool *pool, size_t size)
|
||||||
|
{
|
||||||
|
struct mempool_chunk *chunk;
|
||||||
|
if (size <= pool->threshold)
|
||||||
|
{
|
||||||
|
pool->idx = 0;
|
||||||
|
if (pool->unused)
|
||||||
|
{
|
||||||
|
chunk = pool->unused;
|
||||||
|
pool->unused = chunk->next;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
chunk = mp_new_chunk(pool, pool->chunk_size);
|
||||||
|
#ifdef CONFIG_DEBUG
|
||||||
|
chunk->pool = pool;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
chunk->next = pool->state.last[0];
|
||||||
|
pool->state.last[0] = chunk;
|
||||||
|
pool->state.free[0] = pool->chunk_size - size;
|
||||||
|
return (void *)chunk - pool->chunk_size;
|
||||||
|
}
|
||||||
|
else if (likely(size <= MP_SIZE_MAX))
|
||||||
|
{
|
||||||
|
pool->idx = 1;
|
||||||
|
size_t aligned = ALIGN_TO(size, CPU_STRUCT_ALIGN);
|
||||||
|
chunk = mp_new_big_chunk(pool, aligned);
|
||||||
|
chunk->next = pool->state.last[1];
|
||||||
|
#ifdef CONFIG_DEBUG
|
||||||
|
chunk->pool = pool;
|
||||||
|
#endif
|
||||||
|
pool->state.last[1] = chunk;
|
||||||
|
pool->state.free[1] = aligned - size;
|
||||||
|
return pool->last_big = (void *)chunk - aligned;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
mp_alloc(struct mempool *pool, size_t size)
|
||||||
|
{
|
||||||
|
return mp_alloc_fast(pool, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
mp_alloc_noalign(struct mempool *pool, size_t size)
|
||||||
|
{
|
||||||
|
return mp_alloc_fast_noalign(pool, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
mp_alloc_zero(struct mempool *pool, size_t size)
|
||||||
|
{
|
||||||
|
void *ptr = mp_alloc_fast(pool, size);
|
||||||
|
bzero(ptr, size);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
mp_start_internal(struct mempool *pool, size_t size)
|
||||||
|
{
|
||||||
|
void *ptr = mp_alloc_internal(pool, size);
|
||||||
|
if (!ptr)
|
||||||
|
return NULL;
|
||||||
|
pool->state.free[pool->idx] += size;
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
mp_start(struct mempool *pool, size_t size)
|
||||||
|
{
|
||||||
|
return mp_start_fast(pool, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
mp_start_noalign(struct mempool *pool, size_t size)
|
||||||
|
{
|
||||||
|
return mp_start_fast_noalign(pool, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
mp_grow_internal(struct mempool *pool, size_t size)
|
||||||
|
{
|
||||||
|
if (unlikely(size > MP_SIZE_MAX))
|
||||||
|
return NULL;
|
||||||
|
size_t avail = mp_avail(pool);
|
||||||
|
void *ptr = mp_ptr(pool);
|
||||||
|
if (pool->idx)
|
||||||
|
{
|
||||||
|
size_t amortized = likely(avail <= MP_SIZE_MAX / 2) ? avail * 2 : MP_SIZE_MAX;
|
||||||
|
amortized = MAX(amortized, size);
|
||||||
|
amortized = ALIGN_TO(amortized, CPU_STRUCT_ALIGN);
|
||||||
|
struct mempool_chunk *chunk = pool->state.last[1], *next = chunk->next;
|
||||||
|
pool->total_size = pool->total_size - chunk->size + amortized;
|
||||||
|
void *nptr = realloc(ptr, amortized + MP_CHUNK_TAIL);
|
||||||
|
if (!nptr)
|
||||||
|
return NULL;
|
||||||
|
ptr = nptr;
|
||||||
|
chunk = ptr + amortized;
|
||||||
|
chunk->next = next;
|
||||||
|
chunk->size = amortized;
|
||||||
|
pool->state.last[1] = chunk;
|
||||||
|
pool->state.free[1] = amortized;
|
||||||
|
pool->last_big = ptr;
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
void *p = mp_start_internal(pool, size);
|
||||||
|
memcpy(p, ptr, avail);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
mp_open(struct mempool *pool, void *ptr)
|
||||||
|
{
|
||||||
|
return mp_open_fast(pool, ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
mp_realloc(struct mempool *pool, void *ptr, size_t size)
|
||||||
|
{
|
||||||
|
return mp_realloc_fast(pool, ptr, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
mp_realloc_zero(struct mempool *pool, void *ptr, size_t size)
|
||||||
|
{
|
||||||
|
size_t old_size = mp_open_fast(pool, ptr);
|
||||||
|
ptr = mp_grow(pool, size);
|
||||||
|
if (size > old_size)
|
||||||
|
bzero(ptr + old_size, size - old_size);
|
||||||
|
mp_end(pool, ptr + size);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
mp_spread_internal(struct mempool *pool, void *p, size_t size)
|
||||||
|
{
|
||||||
|
void *old = mp_ptr(pool);
|
||||||
|
void *new = mp_grow_internal(pool, p-old+size);
|
||||||
|
if (!new) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return p-old+new;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mp_restore(struct mempool *pool, struct mempool_state *state)
|
||||||
|
{
|
||||||
|
struct mempool_chunk *chunk, *next;
|
||||||
|
struct mempool_state s = *state;
|
||||||
|
for (chunk = pool->state.last[0]; chunk != s.last[0]; chunk = next)
|
||||||
|
{
|
||||||
|
next = chunk->next;
|
||||||
|
chunk->next = pool->unused;
|
||||||
|
pool->unused = chunk;
|
||||||
|
}
|
||||||
|
for (chunk = pool->state.last[1]; chunk != s.last[1]; chunk = next)
|
||||||
|
{
|
||||||
|
next = chunk->next;
|
||||||
|
mp_free_big_chunk(pool, chunk);
|
||||||
|
}
|
||||||
|
pool->state = s;
|
||||||
|
pool->last_big = &pool->last_big;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct mempool_state *
|
||||||
|
mp_push(struct mempool *pool)
|
||||||
|
{
|
||||||
|
struct mempool_state state = pool->state;
|
||||||
|
struct mempool_state *p = mp_alloc_fast(pool, sizeof(*p));
|
||||||
|
*p = state;
|
||||||
|
pool->state.next = p;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mp_pop(struct mempool *pool)
|
||||||
|
{
|
||||||
|
ASSERT(pool->state.next);
|
||||||
|
mp_restore(pool, pool->state.next);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef TEST
|
||||||
|
|
||||||
|
#include <ucw/getopt.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
static void
|
||||||
|
fill(byte *ptr, uint len, uint magic)
|
||||||
|
{
|
||||||
|
while (len--)
|
||||||
|
*ptr++ = (magic++ & 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
check(byte *ptr, uint len, uint magic, uint align)
|
||||||
|
{
|
||||||
|
ASSERT(!((uintptr_t)ptr & (align - 1)));
|
||||||
|
while (len--)
|
||||||
|
if (*ptr++ != (magic++ & 255))
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
srand(time(NULL));
|
||||||
|
log_init(argv[0]);
|
||||||
|
cf_def_file = NULL;
|
||||||
|
if (cf_getopt(argc, argv, CF_SHORT_OPTS, CF_NO_LONG_OPTS, NULL) >= 0 || argc != optind)
|
||||||
|
die("Invalid usage");
|
||||||
|
|
||||||
|
uint max = 1000, n = 0, m = 0, can_realloc = 0;
|
||||||
|
void *ptr[max];
|
||||||
|
struct mempool_state *state[max];
|
||||||
|
uint len[max], num[max], align[max];
|
||||||
|
struct mempool *mp = mp_new(128), mp_static;
|
||||||
|
|
||||||
|
for (uint i = 0; i < 5000; i++)
|
||||||
|
{
|
||||||
|
for (uint j = 0; j < n; j++)
|
||||||
|
check(ptr[j], len[j], j, align[j]);
|
||||||
|
#if 0
|
||||||
|
DBG("free_small=%u free_big=%u idx=%u chunk_size=%u last_big=%p", mp->state.free[0], mp->state.free[1], mp->idx, mp->chunk_size, mp->last_big);
|
||||||
|
for (struct mempool_chunk *ch = mp->state.last[0]; ch; ch = ch->next)
|
||||||
|
DBG("small %p %p %p %d", (byte *)ch - ch->size, ch, ch + 1, ch->size);
|
||||||
|
for (struct mempool_chunk *ch = mp->state.last[1]; ch; ch = ch->next)
|
||||||
|
DBG("big %p %p %p %d", (byte *)ch - ch->size, ch, ch + 1, ch->size);
|
||||||
|
#endif
|
||||||
|
int r = random_max(100);
|
||||||
|
if ((r -= 1) < 0)
|
||||||
|
{
|
||||||
|
DBG("flush");
|
||||||
|
mp_flush(mp);
|
||||||
|
n = m = 0;
|
||||||
|
}
|
||||||
|
else if ((r -= 1) < 0)
|
||||||
|
{
|
||||||
|
DBG("delete & new");
|
||||||
|
mp_delete(mp);
|
||||||
|
if (random_max(2))
|
||||||
|
mp = mp_new(random_max(0x1000) + 1);
|
||||||
|
else
|
||||||
|
mp = &mp_static, mp_init(mp, random_max(512) + 1);
|
||||||
|
n = m = 0;
|
||||||
|
}
|
||||||
|
else if (n < max && (r -= 30) < 0)
|
||||||
|
{
|
||||||
|
len[n] = random_max(0x2000);
|
||||||
|
DBG("alloc(%u)", len[n]);
|
||||||
|
align[n] = random_max(2) ? CPU_STRUCT_ALIGN : 1;
|
||||||
|
ptr[n] = (align[n] == 1) ? mp_alloc_fast_noalign(mp, len[n]) : mp_alloc_fast(mp, len[n]);
|
||||||
|
DBG(" -> (%p)", ptr[n]);
|
||||||
|
fill(ptr[n], len[n], n);
|
||||||
|
n++;
|
||||||
|
can_realloc = 1;
|
||||||
|
}
|
||||||
|
else if (n < max && (r -= 20) < 0)
|
||||||
|
{
|
||||||
|
len[n] = random_max(0x2000);
|
||||||
|
DBG("start(%u)", len[n]);
|
||||||
|
align[n] = random_max(2) ? CPU_STRUCT_ALIGN : 1;
|
||||||
|
ptr[n] = (align[n] == 1) ? mp_start_fast_noalign(mp, len[n]) : mp_start_fast(mp, len[n]);
|
||||||
|
DBG(" -> (%p)", ptr[n]);
|
||||||
|
fill(ptr[n], len[n], n);
|
||||||
|
n++;
|
||||||
|
can_realloc = 1;
|
||||||
|
goto grow;
|
||||||
|
}
|
||||||
|
else if (can_realloc && n && (r -= 10) < 0)
|
||||||
|
{
|
||||||
|
if (mp_open(mp, ptr[n - 1]) != len[n - 1])
|
||||||
|
ASSERT(0);
|
||||||
|
grow:
|
||||||
|
{
|
||||||
|
uint k = n - 1;
|
||||||
|
for (uint i = random_max(4); i--; )
|
||||||
|
{
|
||||||
|
uint l = len[k];
|
||||||
|
len[k] = random_max(0x2000);
|
||||||
|
DBG("grow(%u)", len[k]);
|
||||||
|
ptr[k] = mp_grow(mp, len[k]);
|
||||||
|
DBG(" -> (%p)", ptr[k]);
|
||||||
|
check(ptr[k], MIN(l, len[k]), k, align[k]);
|
||||||
|
fill(ptr[k], len[k], k);
|
||||||
|
}
|
||||||
|
mp_end(mp, ptr[k] + len[k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (can_realloc && n && (r -= 20) < 0)
|
||||||
|
{
|
||||||
|
uint i = n - 1, l = len[i];
|
||||||
|
DBG("realloc(%p, %u)", ptr[i], len[i]);
|
||||||
|
ptr[i] = mp_realloc(mp, ptr[i], len[i] = random_max(0x2000));
|
||||||
|
DBG(" -> (%p, %u)", ptr[i], len[i]);
|
||||||
|
check(ptr[i], MIN(len[i], l), i, align[i]);
|
||||||
|
fill(ptr[i], len[i], i);
|
||||||
|
}
|
||||||
|
else if (m < max && (r -= 5) < 0)
|
||||||
|
{
|
||||||
|
DBG("push(%u)", m);
|
||||||
|
num[m] = n;
|
||||||
|
state[m++] = mp_push(mp);
|
||||||
|
can_realloc = 0;
|
||||||
|
}
|
||||||
|
else if (m && (r -= 2) < 0)
|
||||||
|
{
|
||||||
|
m--;
|
||||||
|
DBG("pop(%u)", m);
|
||||||
|
mp_pop(mp);
|
||||||
|
n = num[m];
|
||||||
|
can_realloc = 0;
|
||||||
|
}
|
||||||
|
else if (m && (r -= 1) < 0)
|
||||||
|
{
|
||||||
|
uint i = random_max(m);
|
||||||
|
DBG("restore(%u)", i);
|
||||||
|
mp_restore(mp, state[i]);
|
||||||
|
n = num[m = i];
|
||||||
|
can_realloc = 0;
|
||||||
|
}
|
||||||
|
else if (can_realloc && n && (r -= 5) < 0)
|
||||||
|
ASSERT(mp_size(mp, ptr[n - 1]) == len[n - 1]);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
struct mempool_stats stats;
|
||||||
|
mp_stats(mp, &stats);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mp_delete(mp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
572
contrib/ucw/mempool.h
Normal file
572
contrib/ucw/mempool.h
Normal file
|
@ -0,0 +1,572 @@
|
||||||
|
/*
|
||||||
|
* UCW Library -- Memory Pools
|
||||||
|
*
|
||||||
|
* (c) 1997--2015 Martin Mares <mj@ucw.cz>
|
||||||
|
* (c) 2007 Pavel Charvat <pchar@ucw.cz>
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||||
|
* Source: https://www.ucw.cz/libucw/
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _UCW_POOLS_H
|
||||||
|
#define _UCW_POOLS_H
|
||||||
|
|
||||||
|
#include "lib/defines.h"
|
||||||
|
#include <ucw/alloc.h>
|
||||||
|
#include <ucw/config.h>
|
||||||
|
#include <ucw/lib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_UCW_CLEAN_ABI
|
||||||
|
#define mp_alloc ucw_mp_alloc
|
||||||
|
#define mp_alloc_internal ucw_mp_alloc_internal
|
||||||
|
#define mp_alloc_noalign ucw_mp_alloc_noalign
|
||||||
|
#define mp_alloc_zero ucw_mp_alloc_zero
|
||||||
|
#define mp_delete ucw_mp_delete
|
||||||
|
#define mp_flush ucw_mp_flush
|
||||||
|
#define mp_grow_internal ucw_mp_grow_internal
|
||||||
|
#define mp_init ucw_mp_init
|
||||||
|
#define mp_memdup ucw_mp_memdup
|
||||||
|
#define mp_multicat ucw_mp_multicat
|
||||||
|
#define mp_new ucw_mp_new
|
||||||
|
#define mp_open ucw_mp_open
|
||||||
|
#define mp_pop ucw_mp_pop
|
||||||
|
#define mp_printf ucw_mp_printf
|
||||||
|
#define mp_printf_append ucw_mp_printf_append
|
||||||
|
#define mp_push ucw_mp_push
|
||||||
|
#define mp_realloc ucw_mp_realloc
|
||||||
|
#define mp_realloc_zero ucw_mp_realloc_zero
|
||||||
|
#define mp_restore ucw_mp_restore
|
||||||
|
#define mp_shrink ucw_mp_shrink
|
||||||
|
#define mp_spread_internal ucw_mp_spread_internal
|
||||||
|
#define mp_start ucw_mp_start
|
||||||
|
#define mp_start_internal ucw_mp_start_internal
|
||||||
|
#define mp_start_noalign ucw_mp_start_noalign
|
||||||
|
#define mp_stats ucw_mp_stats
|
||||||
|
#define mp_str_from_mem ucw_mp_str_from_mem
|
||||||
|
#define mp_strdup ucw_mp_strdup
|
||||||
|
#define mp_strjoin ucw_mp_strjoin
|
||||||
|
#define mp_total_size ucw_mp_total_size
|
||||||
|
#define mp_vprintf ucw_mp_vprintf
|
||||||
|
#define mp_vprintf_append ucw_mp_vprintf_append
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/***
|
||||||
|
* [[defs]]
|
||||||
|
* Definitions
|
||||||
|
* -----------
|
||||||
|
***/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Memory pool state (see @mp_push(), ...).
|
||||||
|
* You should use this one as an opaque handle only, the insides are internal.
|
||||||
|
**/
|
||||||
|
struct mempool_state {
|
||||||
|
size_t free[2];
|
||||||
|
void *last[2];
|
||||||
|
struct mempool_state *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Memory pool.
|
||||||
|
* You should use this one as an opaque handle only, the insides are internal.
|
||||||
|
**/
|
||||||
|
struct mempool {
|
||||||
|
struct ucw_allocator allocator; // This must be the first element
|
||||||
|
struct mempool_state state;
|
||||||
|
void *unused, *last_big;
|
||||||
|
size_t chunk_size, threshold;
|
||||||
|
uint idx;
|
||||||
|
u64 total_size;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct mempool_stats { /** Mempool statistics. See @mp_stats(). **/
|
||||||
|
u64 total_size; /* Real allocated size in bytes */
|
||||||
|
u64 used_size; /* Estimated size allocated from mempool to application */
|
||||||
|
uint chain_count[3]; /* Number of allocated chunks in small/big/unused chains */
|
||||||
|
u64 chain_size[3]; /* Size of allocated chunks in small/big/unused chains */
|
||||||
|
};
|
||||||
|
|
||||||
|
/***
|
||||||
|
* [[basic]]
|
||||||
|
* Basic manipulation
|
||||||
|
* ------------------
|
||||||
|
***/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize a given mempool structure.
|
||||||
|
* @chunk_size must be in the interval `[1, SIZE_MAX / 2]`.
|
||||||
|
* It will allocate memory by this large chunks and take
|
||||||
|
* memory to satisfy requests from them.
|
||||||
|
*
|
||||||
|
* Memory pools can be treated as <<trans:respools,resources>>, see <<trans:res_mempool()>>.
|
||||||
|
**/
|
||||||
|
KR_EXPORT
|
||||||
|
void mp_init(struct mempool *pool, size_t chunk_size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocate and initialize a new memory pool.
|
||||||
|
* See @mp_init() for @chunk_size limitations.
|
||||||
|
*
|
||||||
|
* The new mempool structure is allocated on the new mempool.
|
||||||
|
*
|
||||||
|
* Memory pools can be treated as <<trans:respools,resources>>, see <<trans:res_mempool()>>.
|
||||||
|
**/
|
||||||
|
KR_EXPORT
|
||||||
|
struct mempool *mp_new(size_t chunk_size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cleanup mempool initialized by mp_init or mp_new.
|
||||||
|
* Frees all the memory allocated by this mempool and,
|
||||||
|
* if created by @mp_new(), the @pool itself.
|
||||||
|
**/
|
||||||
|
KR_EXPORT
|
||||||
|
void mp_delete(struct mempool *pool);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frees all data on a memory pool, but leaves it working.
|
||||||
|
* It can keep some of the chunks allocated to serve
|
||||||
|
* further allocation requests. Leaves the @pool alive,
|
||||||
|
* even if it was created with @mp_new().
|
||||||
|
**/
|
||||||
|
KR_EXPORT
|
||||||
|
void mp_flush(struct mempool *pool);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute some statistics for debug purposes.
|
||||||
|
* See the definition of the <<struct_mempool_stats,mempool_stats structure>>.
|
||||||
|
* This function scans the chunk list, so it can be slow. If you are interested
|
||||||
|
* in total memory consumption only, mp_total_size() is faster.
|
||||||
|
**/
|
||||||
|
void mp_stats(struct mempool *pool, struct mempool_stats *stats);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return how many bytes were allocated by the pool, including unused parts
|
||||||
|
* of chunks. This function runs in constant time.
|
||||||
|
**/
|
||||||
|
u64 mp_total_size(struct mempool *pool);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Release unused chunks of memory reserved for further allocation
|
||||||
|
* requests, but stop if mp_total_size() would drop below @min_total_size.
|
||||||
|
**/
|
||||||
|
void mp_shrink(struct mempool *pool, u64 min_total_size);
|
||||||
|
|
||||||
|
/***
|
||||||
|
* [[alloc]]
|
||||||
|
* Allocation routines
|
||||||
|
* -------------------
|
||||||
|
***/
|
||||||
|
|
||||||
|
/* For internal use only, do not call directly */
|
||||||
|
void *mp_alloc_internal(struct mempool *pool, size_t size) LIKE_MALLOC;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The function allocates new @size bytes on a given memory pool.
|
||||||
|
* If the @size is zero, the resulting pointer is undefined,
|
||||||
|
* but it may be safely reallocated or used as the parameter
|
||||||
|
* to other functions below.
|
||||||
|
*
|
||||||
|
* The resulting pointer is always aligned to a multiple of
|
||||||
|
* `CPU_STRUCT_ALIGN` bytes and this condition remains true also
|
||||||
|
* after future reallocations.
|
||||||
|
**/
|
||||||
|
KR_EXPORT
|
||||||
|
void *mp_alloc(struct mempool *pool, size_t size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The same as @mp_alloc(), but the result may be unaligned.
|
||||||
|
**/
|
||||||
|
void *mp_alloc_noalign(struct mempool *pool, size_t size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The same as @mp_alloc(), but fills the newly allocated memory with zeroes.
|
||||||
|
**/
|
||||||
|
void *mp_alloc_zero(struct mempool *pool, size_t size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inlined version of @mp_alloc().
|
||||||
|
**/
|
||||||
|
static inline void *mp_alloc_fast(struct mempool *pool, size_t size)
|
||||||
|
{
|
||||||
|
size_t avail = pool->state.free[0] & ~(size_t)(CPU_STRUCT_ALIGN - 1);
|
||||||
|
if (size <= avail)
|
||||||
|
{
|
||||||
|
pool->state.free[0] = avail - size;
|
||||||
|
return (byte *)pool->state.last[0] - avail;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return mp_alloc_internal(pool, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inlined version of @mp_alloc_noalign().
|
||||||
|
**/
|
||||||
|
static inline void *mp_alloc_fast_noalign(struct mempool *pool, size_t size)
|
||||||
|
{
|
||||||
|
if (size <= pool->state.free[0])
|
||||||
|
{
|
||||||
|
void *ptr = (byte *)pool->state.last[0] - pool->state.free[0];
|
||||||
|
pool->state.free[0] -= size;
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return mp_alloc_internal(pool, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a generic allocator representing the given mempool.
|
||||||
|
**/
|
||||||
|
static inline struct ucw_allocator *mp_get_allocator(struct mempool *mp)
|
||||||
|
{
|
||||||
|
return &mp->allocator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* [[gbuf]]
|
||||||
|
* Growing buffers
|
||||||
|
* ---------------
|
||||||
|
*
|
||||||
|
* You do not need to know, how a buffer will need to be large,
|
||||||
|
* you can grow it incrementally to needed size. You can grow only
|
||||||
|
* one buffer at a time on a given mempool.
|
||||||
|
*
|
||||||
|
* Similar functionality is provided by <<growbuf:,growing buffers>> module.
|
||||||
|
***/
|
||||||
|
|
||||||
|
/* For internal use only, do not call directly */
|
||||||
|
void *mp_start_internal(struct mempool *pool, size_t size) LIKE_MALLOC;
|
||||||
|
void *mp_grow_internal(struct mempool *pool, size_t size);
|
||||||
|
void *mp_spread_internal(struct mempool *pool, void *p, size_t size);
|
||||||
|
|
||||||
|
static inline uint mp_idx(struct mempool *pool, void *ptr)
|
||||||
|
{
|
||||||
|
return ptr == pool->last_big;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open a new growing buffer (at least @size bytes long).
|
||||||
|
* If the @size is zero, the resulting pointer is undefined,
|
||||||
|
* but it may be safely reallocated or used as the parameter
|
||||||
|
* to other functions below.
|
||||||
|
*
|
||||||
|
* The resulting pointer is always aligned to a multiple of
|
||||||
|
* `CPU_STRUCT_ALIGN` bytes and this condition remains true also
|
||||||
|
* after future reallocations. There is an unaligned version as well.
|
||||||
|
*
|
||||||
|
* Keep in mind that you can't make any other pool allocations
|
||||||
|
* before you "close" the growing buffer with @mp_end().
|
||||||
|
*/
|
||||||
|
void *mp_start(struct mempool *pool, size_t size);
|
||||||
|
void *mp_start_noalign(struct mempool *pool, size_t size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inlined version of @mp_start().
|
||||||
|
**/
|
||||||
|
static inline void *mp_start_fast(struct mempool *pool, size_t size)
|
||||||
|
{
|
||||||
|
size_t avail = pool->state.free[0] & ~(size_t)(CPU_STRUCT_ALIGN - 1);
|
||||||
|
if (size <= avail)
|
||||||
|
{
|
||||||
|
pool->idx = 0;
|
||||||
|
pool->state.free[0] = avail;
|
||||||
|
return (byte *)pool->state.last[0] - avail;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return mp_start_internal(pool, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inlined version of @mp_start_noalign().
|
||||||
|
**/
|
||||||
|
static inline void *mp_start_fast_noalign(struct mempool *pool, size_t size)
|
||||||
|
{
|
||||||
|
if (size <= pool->state.free[0])
|
||||||
|
{
|
||||||
|
pool->idx = 0;
|
||||||
|
return (byte *)pool->state.last[0] - pool->state.free[0];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return mp_start_internal(pool, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return start pointer of the growing buffer allocated by latest @mp_start() or a similar function.
|
||||||
|
**/
|
||||||
|
static inline void *mp_ptr(struct mempool *pool)
|
||||||
|
{
|
||||||
|
return (byte *)pool->state.last[pool->idx] - pool->state.free[pool->idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the number of bytes available for extending the growing buffer.
|
||||||
|
* (Before a reallocation will be needed).
|
||||||
|
**/
|
||||||
|
static inline size_t mp_avail(struct mempool *pool)
|
||||||
|
{
|
||||||
|
return pool->state.free[pool->idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grow the buffer allocated by @mp_start() to be at least @size bytes long
|
||||||
|
* (@size may be less than @mp_avail(), even zero). Reallocated buffer may
|
||||||
|
* change its starting position. The content will be unchanged to the minimum
|
||||||
|
* of the old and new sizes; newly allocated memory will be uninitialized.
|
||||||
|
* Multiple calls to mp_grow() have amortized linear cost wrt. the maximum value of @size. */
|
||||||
|
static inline void *mp_grow(struct mempool *pool, size_t size)
|
||||||
|
{
|
||||||
|
return (size <= mp_avail(pool)) ? mp_ptr(pool) : mp_grow_internal(pool, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grow the buffer by at least one byte -- equivalent to <<mp_grow(),`mp_grow`>>`(@pool, @mp_avail(pool) + 1)`.
|
||||||
|
**/
|
||||||
|
static inline void *mp_expand(struct mempool *pool)
|
||||||
|
{
|
||||||
|
return mp_grow_internal(pool, mp_avail(pool) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure that there is at least @size bytes free after @p,
|
||||||
|
* if not, reallocate and adjust @p.
|
||||||
|
**/
|
||||||
|
static inline void *mp_spread(struct mempool *pool, void *p, size_t size)
|
||||||
|
{
|
||||||
|
return (((size_t)((byte *)pool->state.last[pool->idx] - (byte *)p) >= size) ? p : mp_spread_internal(pool, p, size));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append a character to the growing buffer. Called with @p pointing after
|
||||||
|
* the last byte in the buffer, returns a pointer after the last byte
|
||||||
|
* of the new (possibly reallocated) buffer.
|
||||||
|
**/
|
||||||
|
static inline char *mp_append_char(struct mempool *pool, char *p, uint c)
|
||||||
|
{
|
||||||
|
p = mp_spread(pool, p, 1);
|
||||||
|
*p++ = c;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append a memory block to the growing buffer. Called with @p pointing after
|
||||||
|
* the last byte in the buffer, returns a pointer after the last byte
|
||||||
|
* of the new (possibly reallocated) buffer.
|
||||||
|
**/
|
||||||
|
static inline void *mp_append_block(struct mempool *pool, void *p, const void *block, size_t size)
|
||||||
|
{
|
||||||
|
char *q = mp_spread(pool, p, size);
|
||||||
|
memcpy(q, block, size);
|
||||||
|
return q + size;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append a string to the growing buffer. Called with @p pointing after
|
||||||
|
* the last byte in the buffer, returns a pointer after the last byte
|
||||||
|
* of the new (possibly reallocated) buffer.
|
||||||
|
**/
|
||||||
|
static inline void *mp_append_string(struct mempool *pool, void *p, const char *str)
|
||||||
|
{
|
||||||
|
return mp_append_block(pool, p, str, strlen(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the growing buffer. The @end must point just behind the data, you want to keep
|
||||||
|
* allocated (so it can be in the interval `[@mp_ptr(@pool), @mp_ptr(@pool) + @mp_avail(@pool)]`).
|
||||||
|
* Returns a pointer to the beginning of the just closed block.
|
||||||
|
**/
|
||||||
|
static inline void *mp_end(struct mempool *pool, void *end)
|
||||||
|
{
|
||||||
|
void *p = mp_ptr(pool);
|
||||||
|
pool->state.free[pool->idx] = (byte *)pool->state.last[pool->idx] - (byte *)end;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the growing buffer as a string. That is, append a zero byte and call mp_end().
|
||||||
|
**/
|
||||||
|
static inline char *mp_end_string(struct mempool *pool, void *end)
|
||||||
|
{
|
||||||
|
end = mp_append_char(pool, end, 0);
|
||||||
|
return mp_end(pool, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return size in bytes of the last allocated memory block (with @mp_alloc() or @mp_end()).
|
||||||
|
**/
|
||||||
|
static inline size_t mp_size(struct mempool *pool, void *ptr)
|
||||||
|
{
|
||||||
|
uint idx = mp_idx(pool, ptr);
|
||||||
|
return ((byte *)pool->state.last[idx] - (byte *)ptr) - pool->state.free[idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open the last memory block (allocated with @mp_alloc() or @mp_end())
|
||||||
|
* for growing and return its size in bytes. The contents and the start pointer
|
||||||
|
* remain unchanged. Do not forget to call @mp_end() to close it.
|
||||||
|
**/
|
||||||
|
size_t mp_open(struct mempool *pool, void *ptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inlined version of @mp_open().
|
||||||
|
**/
|
||||||
|
static inline size_t mp_open_fast(struct mempool *pool, void *ptr)
|
||||||
|
{
|
||||||
|
pool->idx = mp_idx(pool, ptr);
|
||||||
|
size_t size = ((byte *)pool->state.last[pool->idx] - (byte *)ptr) - pool->state.free[pool->idx];
|
||||||
|
pool->state.free[pool->idx] += size;
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reallocate the last memory block (allocated with @mp_alloc() or @mp_end())
|
||||||
|
* to the new @size. Behavior is similar to @mp_grow(), but the resulting
|
||||||
|
* block is closed.
|
||||||
|
**/
|
||||||
|
void *mp_realloc(struct mempool *pool, void *ptr, size_t size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The same as @mp_realloc(), but fills the additional bytes (if any) with zeroes.
|
||||||
|
**/
|
||||||
|
void *mp_realloc_zero(struct mempool *pool, void *ptr, size_t size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inlined version of @mp_realloc().
|
||||||
|
**/
|
||||||
|
static inline void *mp_realloc_fast(struct mempool *pool, void *ptr, size_t size)
|
||||||
|
{
|
||||||
|
mp_open_fast(pool, ptr);
|
||||||
|
ptr = mp_grow(pool, size);
|
||||||
|
mp_end(pool, (byte *)ptr + size);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* [[store]]
|
||||||
|
* Storing and restoring state
|
||||||
|
* ---------------------------
|
||||||
|
*
|
||||||
|
* Mempools can remember history of what was allocated and return back
|
||||||
|
* in time.
|
||||||
|
***/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the current state of a memory pool.
|
||||||
|
* Do not call this function with an opened growing buffer.
|
||||||
|
**/
|
||||||
|
static inline void mp_save(struct mempool *pool, struct mempool_state *state)
|
||||||
|
{
|
||||||
|
*state = pool->state;
|
||||||
|
pool->state.next = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the current state to a newly allocated mempool_state structure.
|
||||||
|
* Do not call this function with an opened growing buffer.
|
||||||
|
**/
|
||||||
|
struct mempool_state *mp_push(struct mempool *pool);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restore the state saved by @mp_save() or @mp_push() and free all
|
||||||
|
* data allocated after that point (including the state structure itself).
|
||||||
|
* You can't reallocate the last memory block from the saved state.
|
||||||
|
**/
|
||||||
|
void mp_restore(struct mempool *pool, struct mempool_state *state);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inlined version of @mp_restore().
|
||||||
|
**/
|
||||||
|
static inline void mp_restore_fast(struct mempool *pool, struct mempool_state *state)
|
||||||
|
{
|
||||||
|
if (pool->state.last[0] != state->last[0] || pool->state.last[1] != state->last[1])
|
||||||
|
mp_restore(pool, state);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pool->state = *state;
|
||||||
|
pool->last_big = &pool->last_big;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restore the state saved by the last call to @mp_push().
|
||||||
|
* @mp_pop() and @mp_push() works as a stack so you can push more states safely.
|
||||||
|
**/
|
||||||
|
void mp_pop(struct mempool *pool);
|
||||||
|
|
||||||
|
|
||||||
|
/***
|
||||||
|
* [[string]]
|
||||||
|
* String operations
|
||||||
|
* -----------------
|
||||||
|
***/
|
||||||
|
|
||||||
|
char *mp_strdup(struct mempool *, const char *) LIKE_MALLOC; /** Makes a copy of a string on a mempool. Returns NULL for NULL string. **/
|
||||||
|
void *mp_memdup(struct mempool *, const void *, size_t) LIKE_MALLOC; /** Makes a copy of a memory block on a mempool. **/
|
||||||
|
/**
|
||||||
|
* Concatenates all passed strings. The last parameter must be NULL.
|
||||||
|
* This will concatenate two strings:
|
||||||
|
*
|
||||||
|
* char *message = mp_multicat(pool, "hello ", "world", NULL);
|
||||||
|
**/
|
||||||
|
char *mp_multicat(struct mempool *, ...) LIKE_MALLOC SENTINEL_CHECK;
|
||||||
|
/**
|
||||||
|
* Concatenates two strings and stores result on @mp.
|
||||||
|
*/
|
||||||
|
static inline char *LIKE_MALLOC mp_strcat(struct mempool *mp, const char *x, const char *y)
|
||||||
|
{
|
||||||
|
return mp_multicat(mp, x, y, NULL);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Join strings and place @sep between each two neighboring.
|
||||||
|
* @p is the mempool to provide memory, @a is array of strings and @n
|
||||||
|
* tells how many there is of them.
|
||||||
|
**/
|
||||||
|
char *mp_strjoin(struct mempool *p, char **a, uint n, uint sep) LIKE_MALLOC;
|
||||||
|
/**
|
||||||
|
* Convert memory block to a string. Makes a copy of the given memory block
|
||||||
|
* in the mempool @p, adding an extra terminating zero byte at the end.
|
||||||
|
**/
|
||||||
|
char *mp_str_from_mem(struct mempool *p, const void *mem, size_t len) LIKE_MALLOC;
|
||||||
|
|
||||||
|
|
||||||
|
/***
|
||||||
|
* [[format]]
|
||||||
|
* Formatted output
|
||||||
|
* ---------------
|
||||||
|
***/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* printf() into a in-memory string, allocated on the memory pool.
|
||||||
|
**/
|
||||||
|
KR_EXPORT
|
||||||
|
char *mp_printf(struct mempool *mp, const char *fmt, ...) FORMAT_CHECK(printf,2,3) LIKE_MALLOC;
|
||||||
|
/**
|
||||||
|
* Like @mp_printf(), but uses `va_list` for parameters.
|
||||||
|
**/
|
||||||
|
char *mp_vprintf(struct mempool *mp, const char *fmt, va_list args) LIKE_MALLOC;
|
||||||
|
/**
|
||||||
|
* Like @mp_printf(), but it appends the data at the end of string
|
||||||
|
* pointed to by @ptr. The string is @mp_open()ed, so you have to
|
||||||
|
* provide something that can be.
|
||||||
|
*
|
||||||
|
* Returns pointer to the beginning of the string (the pointer may have
|
||||||
|
* changed due to reallocation).
|
||||||
|
*
|
||||||
|
* In some versions of LibUCW, this function was called mp_append_printf(). However,
|
||||||
|
* this name turned out to be confusing -- unlike other appending functions, this one is
|
||||||
|
* not called on an opened growing buffer. The old name will be preserved for backward
|
||||||
|
* compatibility for the time being.
|
||||||
|
**/
|
||||||
|
KR_EXPORT
|
||||||
|
char *mp_printf_append(struct mempool *mp, char *ptr, const char *fmt, ...) FORMAT_CHECK(printf,3,4);
|
||||||
|
#define mp_append_printf mp_printf_append
|
||||||
|
/**
|
||||||
|
* Like @mp_printf_append(), but uses `va_list` for parameters.
|
||||||
|
*
|
||||||
|
* In some versions of LibUCW, this function was called mp_append_vprintf(). However,
|
||||||
|
* this name turned out to be confusing -- unlike other appending functions, this one is
|
||||||
|
* not called on an opened growing buffer. The old name will be preserved for backward
|
||||||
|
* compatibility for the time being.
|
||||||
|
**/
|
||||||
|
char *mp_vprintf_append(struct mempool *mp, char *ptr, const char *fmt, va_list args);
|
||||||
|
#define mp_append_vprintf mp_vprintf_append
|
||||||
|
|
||||||
|
#endif
|
13
daemon/.packaging/centos/7/builddeps
Normal file
13
daemon/.packaging/centos/7/builddeps
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
gcc
|
||||||
|
gcc-c++
|
||||||
|
gnutls
|
||||||
|
knot-libs
|
||||||
|
knot-devel
|
||||||
|
libcmocka-devel
|
||||||
|
libedit-devel
|
||||||
|
libcap-ng
|
||||||
|
libuv-devel
|
||||||
|
lmdb-devel
|
||||||
|
luajit-devel
|
||||||
|
meson
|
||||||
|
systemd-devel
|
9
daemon/.packaging/centos/7/pre-build.sh
Executable file
9
daemon/.packaging/centos/7/pre-build.sh
Executable file
|
@ -0,0 +1,9 @@
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
yum update -y
|
||||||
|
yum install -y wget epel-release
|
||||||
|
|
||||||
|
# add build repository
|
||||||
|
cd /etc/yum.repos.d/
|
||||||
|
wget https://download.opensuse.org/repositories/home:CZ-NIC:knot-resolver-build/CentOS_7_EPEL/home:CZ-NIC:knot-resolver-build.repo
|
||||||
|
|
8
daemon/.packaging/centos/7/pre-run.sh
Executable file
8
daemon/.packaging/centos/7/pre-run.sh
Executable file
|
@ -0,0 +1,8 @@
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
yum update -y
|
||||||
|
yum install -y wget epel-release
|
||||||
|
|
||||||
|
# add build repository
|
||||||
|
cd /etc/yum.repos.d/
|
||||||
|
wget https://download.opensuse.org/repositories/home:CZ-NIC:knot-resolver-latest/CentOS_7_EPEL/home:CZ-NIC:knot-resolver-latest.repo
|
6
daemon/.packaging/centos/7/rundeps
Normal file
6
daemon/.packaging/centos/7/rundeps
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
knot-libs
|
||||||
|
libedit
|
||||||
|
libuv
|
||||||
|
luajit
|
||||||
|
lua-basexx
|
||||||
|
lua-http
|
14
daemon/.packaging/centos/8/builddeps
Normal file
14
daemon/.packaging/centos/8/builddeps
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
gcc
|
||||||
|
gcc-c++
|
||||||
|
meson
|
||||||
|
"pkgconfig(cmocka)"
|
||||||
|
"pkgconfig(gnutls)"
|
||||||
|
"pkgconfig(libedit)"
|
||||||
|
"pkgconfig(libknot)"
|
||||||
|
"pkgconfig(libzscanner)"
|
||||||
|
"pkgconfig(libdnssec)"
|
||||||
|
"pkgconfig(libsystemd)"
|
||||||
|
"pkgconfig(libcap-ng)"
|
||||||
|
"pkgconfig(libuv)"
|
||||||
|
"pkgconfig(lmdb)"
|
||||||
|
"pkgconfig(luajit)"
|
9
daemon/.packaging/centos/8/pre-build.sh
Executable file
9
daemon/.packaging/centos/8/pre-build.sh
Executable file
|
@ -0,0 +1,9 @@
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
dnf install -y wget 'dnf-command(config-manager)' epel-release centos-release
|
||||||
|
|
||||||
|
dnf config-manager --enable PowerTools
|
||||||
|
dnf config-manager --enable Devel
|
||||||
|
dnf config-manager --add-repo https://download.opensuse.org/repositories/home:CZ-NIC:knot-resolver-build/CentOS_8_EPEL/home:CZ-NIC:knot-resolver-build.repo
|
||||||
|
dnf install -y knot
|
||||||
|
dnf upgrade -y
|
7
daemon/.packaging/centos/8/pre-run.sh
Executable file
7
daemon/.packaging/centos/8/pre-run.sh
Executable file
|
@ -0,0 +1,7 @@
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
dnf install -y wget 'dnf-command(config-manager)' epel-release centos-release
|
||||||
|
|
||||||
|
dnf config-manager --enable PowerTools
|
||||||
|
dnf config-manager --add-repo https://download.opensuse.org/repositories/home:CZ-NIC:knot-resolver-latest/CentOS_8_EPEL/home:CZ-NIC:knot-resolver-latest.repo
|
||||||
|
dnf upgrade -y
|
6
daemon/.packaging/centos/8/rundeps
Normal file
6
daemon/.packaging/centos/8/rundeps
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
libedit
|
||||||
|
knot-libs
|
||||||
|
libuv
|
||||||
|
luajit
|
||||||
|
lua5.1-basexx
|
||||||
|
lua5.1-http
|
12
daemon/.packaging/debian/10/builddeps
Normal file
12
daemon/.packaging/debian/10/builddeps
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
debhelper
|
||||||
|
libcmocka-dev
|
||||||
|
libedit-dev
|
||||||
|
libgnutls28-dev
|
||||||
|
libknot-dev
|
||||||
|
liblmdb-dev
|
||||||
|
luajit-5.1-dev
|
||||||
|
libsystemd-dev
|
||||||
|
libuv1-dev
|
||||||
|
luajit
|
||||||
|
pkg-config
|
||||||
|
meson
|
11
daemon/.packaging/debian/10/pre-build.sh
Executable file
11
daemon/.packaging/debian/10/pre-build.sh
Executable file
|
@ -0,0 +1,11 @@
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# add debian build repository
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y wget gnupg apt-utils
|
||||||
|
echo 'deb http://download.opensuse.org/repositories/home:/CZ-NIC:/knot-resolver-build/Debian_10/ /' > /etc/apt/sources.list.d/home:CZ-NIC:knot-resolver-build.list
|
||||||
|
wget -nv https://download.opensuse.org/repositories/home:CZ-NIC:knot-resolver-build/Debian_10/Release.key -O Release.key
|
||||||
|
apt-key add - < Release.key
|
||||||
|
|
||||||
|
apt-get update
|
||||||
|
apt-get upgrade -y
|
11
daemon/.packaging/debian/10/pre-run.sh
Executable file
11
daemon/.packaging/debian/10/pre-run.sh
Executable file
|
@ -0,0 +1,11 @@
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y wget gnupg apt-utils
|
||||||
|
|
||||||
|
echo 'deb http://download.opensuse.org/repositories/home:/CZ-NIC:/knot-resolver-latest/Debian_10/ /' > /etc/apt/sources.list.d/home:CZ-NIC:knot-resolver-latest.list
|
||||||
|
wget -nv https://download.opensuse.org/repositories/home:CZ-NIC:knot-resolver-latest/Debian_10/Release.key -O Release.key
|
||||||
|
apt-key add - < Release.key
|
||||||
|
|
||||||
|
apt-get update
|
||||||
|
apt-get upgrade -y
|
15
daemon/.packaging/debian/10/rundeps
Normal file
15
daemon/.packaging/debian/10/rundeps
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
adduser
|
||||||
|
dns-root-data
|
||||||
|
systemd
|
||||||
|
libc6
|
||||||
|
libdnssec7
|
||||||
|
libedit2
|
||||||
|
libgcc1
|
||||||
|
libgnutls30
|
||||||
|
libknot10
|
||||||
|
liblmdb0
|
||||||
|
libluajit-5.1-2
|
||||||
|
libstdc++6
|
||||||
|
libsystemd0
|
||||||
|
libuv1
|
||||||
|
libzscanner3
|
12
daemon/.packaging/debian/9/builddeps
Normal file
12
daemon/.packaging/debian/9/builddeps
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
debhelper
|
||||||
|
libcmocka-dev
|
||||||
|
libedit-dev
|
||||||
|
libgnutls28-dev
|
||||||
|
libknot-dev
|
||||||
|
liblmdb-dev
|
||||||
|
luajit-5.1-dev
|
||||||
|
libsystemd-dev
|
||||||
|
libuv1-dev
|
||||||
|
luajit
|
||||||
|
pkg-config
|
||||||
|
meson
|
11
daemon/.packaging/debian/9/pre-build.sh
Executable file
11
daemon/.packaging/debian/9/pre-build.sh
Executable file
|
@ -0,0 +1,11 @@
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# add debian build repository
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y wget gnupg apt-utils
|
||||||
|
echo 'deb http://download.opensuse.org/repositories/home:/CZ-NIC:/knot-resolver-build/Debian_9.0/ /' > /etc/apt/sources.list.d/home:CZ-NIC:knot-resolver-build.list
|
||||||
|
wget -nv https://download.opensuse.org/repositories/home:CZ-NIC:knot-resolver-build/Debian_9.0/Release.key -O Release.key
|
||||||
|
apt-key add - < Release.key
|
||||||
|
|
||||||
|
apt-get update
|
||||||
|
apt-get upgrade -y
|
11
daemon/.packaging/debian/9/pre-run.sh
Executable file
11
daemon/.packaging/debian/9/pre-run.sh
Executable file
|
@ -0,0 +1,11 @@
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y wget gnupg apt-utils
|
||||||
|
|
||||||
|
echo 'deb http://download.opensuse.org/repositories/home:/CZ-NIC:/knot-resolver-latest/Debian_9.0/ /' > /etc/apt/sources.list.d/home:CZ-NIC:knot-resolver-latest.list
|
||||||
|
wget -nv https://download.opensuse.org/repositories/home:CZ-NIC:knot-resolver-latest/Debian_9.0/Release.key -O Release.key
|
||||||
|
apt-key add - < Release.key
|
||||||
|
|
||||||
|
apt-get update
|
||||||
|
apt-get upgrade -y
|
15
daemon/.packaging/debian/9/rundeps
Normal file
15
daemon/.packaging/debian/9/rundeps
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
adduser
|
||||||
|
dns-root-data
|
||||||
|
systemd
|
||||||
|
libc6
|
||||||
|
libdnssec7
|
||||||
|
libedit2
|
||||||
|
libgcc1
|
||||||
|
libgnutls30
|
||||||
|
libknot10
|
||||||
|
liblmdb0
|
||||||
|
libluajit-5.1-2
|
||||||
|
libstdc++6
|
||||||
|
libsystemd0
|
||||||
|
libuv1
|
||||||
|
libzscanner3
|
14
daemon/.packaging/fedora/31/builddeps
Normal file
14
daemon/.packaging/fedora/31/builddeps
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
gcc
|
||||||
|
gcc-c++
|
||||||
|
meson
|
||||||
|
"pkgconfig(cmocka)"
|
||||||
|
"pkgconfig(gnutls)"
|
||||||
|
"pkgconfig(libedit)"
|
||||||
|
"pkgconfig(libknot)"
|
||||||
|
"pkgconfig(libzscanner)"
|
||||||
|
"pkgconfig(libdnssec)"
|
||||||
|
"pkgconfig(libsystemd)"
|
||||||
|
"pkgconfig(libcap-ng)"
|
||||||
|
"pkgconfig(libuv)"
|
||||||
|
"pkgconfig(lmdb)"
|
||||||
|
"pkgconfig(luajit)"
|
7
daemon/.packaging/fedora/31/pre-build.sh
Executable file
7
daemon/.packaging/fedora/31/pre-build.sh
Executable file
|
@ -0,0 +1,7 @@
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
dnf install -y wget
|
||||||
|
|
||||||
|
dnf config-manager --add-repo https://download.opensuse.org/repositories/home:CZ-NIC:knot-resolver-build/Fedora_31/home:CZ-NIC:knot-resolver-build.repo
|
||||||
|
dnf install -y knot
|
||||||
|
dnf upgrade -y
|
6
daemon/.packaging/fedora/31/pre-run.sh
Executable file
6
daemon/.packaging/fedora/31/pre-run.sh
Executable file
|
@ -0,0 +1,6 @@
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
dnf install -y wget
|
||||||
|
|
||||||
|
dnf config-manager --add-repo https://download.opensuse.org/repositories/home:CZ-NIC:knot-resolver-latest/Fedora_31/home:CZ-NIC:knot-resolver-latest.repo
|
||||||
|
dnf upgrade -y
|
7
daemon/.packaging/fedora/31/rundeps
Normal file
7
daemon/.packaging/fedora/31/rundeps
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
libedit
|
||||||
|
knot-libs
|
||||||
|
libuv
|
||||||
|
luajit
|
||||||
|
lua5.1-basexx
|
||||||
|
lua5.1-psl
|
||||||
|
lua5.1-http
|
14
daemon/.packaging/fedora/32/builddeps
Normal file
14
daemon/.packaging/fedora/32/builddeps
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
gcc
|
||||||
|
gcc-c++
|
||||||
|
meson
|
||||||
|
"pkgconfig(cmocka)"
|
||||||
|
"pkgconfig(gnutls)"
|
||||||
|
"pkgconfig(libedit)"
|
||||||
|
"pkgconfig(libknot)"
|
||||||
|
"pkgconfig(libzscanner)"
|
||||||
|
"pkgconfig(libdnssec)"
|
||||||
|
"pkgconfig(libsystemd)"
|
||||||
|
"pkgconfig(libcap-ng)"
|
||||||
|
"pkgconfig(libuv)"
|
||||||
|
"pkgconfig(lmdb)"
|
||||||
|
"pkgconfig(luajit)"
|
7
daemon/.packaging/fedora/32/pre-build.sh
Executable file
7
daemon/.packaging/fedora/32/pre-build.sh
Executable file
|
@ -0,0 +1,7 @@
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
dnf install -y wget
|
||||||
|
|
||||||
|
dnf config-manager --add-repo https://download.opensuse.org/repositories/home:CZ-NIC:knot-resolver-build/Fedora_32/home:CZ-NIC:knot-resolver-build.repo
|
||||||
|
dnf install -y knot
|
||||||
|
dnf upgrade -y
|
6
daemon/.packaging/fedora/32/pre-run.sh
Executable file
6
daemon/.packaging/fedora/32/pre-run.sh
Executable file
|
@ -0,0 +1,6 @@
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
dnf install -y wget
|
||||||
|
|
||||||
|
dnf config-manager --add-repo https://download.opensuse.org/repositories/home:CZ-NIC:knot-resolver-latest/Fedora_32/home:CZ-NIC:knot-resolver-latest.repo
|
||||||
|
dnf upgrade -y
|
7
daemon/.packaging/fedora/32/rundeps
Normal file
7
daemon/.packaging/fedora/32/rundeps
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
libedit
|
||||||
|
knot-libs
|
||||||
|
libuv
|
||||||
|
luajit
|
||||||
|
lua5.1-basexx
|
||||||
|
lua5.1-psl
|
||||||
|
lua5.1-http
|
14
daemon/.packaging/leap/15.2/builddeps
Normal file
14
daemon/.packaging/leap/15.2/builddeps
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
gcc
|
||||||
|
gcc-c++
|
||||||
|
lmdb-devel
|
||||||
|
meson
|
||||||
|
"pkgconfig(cmocka)"
|
||||||
|
"pkgconfig(gnutls)"
|
||||||
|
"pkgconfig(libedit)"
|
||||||
|
"pkgconfig(libknot)"
|
||||||
|
"pkgconfig(libzscanner)"
|
||||||
|
"pkgconfig(libdnssec)"
|
||||||
|
"pkgconfig(libsystemd)"
|
||||||
|
"pkgconfig(libcap-ng)"
|
||||||
|
"pkgconfig(libuv)"
|
||||||
|
"pkgconfig(luajit)"
|
6
daemon/.packaging/leap/15.2/pre-build.sh
Executable file
6
daemon/.packaging/leap/15.2/pre-build.sh
Executable file
|
@ -0,0 +1,6 @@
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
zypper addrepo https://download.opensuse.org/repositories/home:CZ-NIC:knot-resolver-build/openSUSE_Leap_15.2/home:CZ-NIC:knot-resolver-build.repo
|
||||||
|
zypper --no-gpg-checks refresh
|
||||||
|
zypper install -y knot
|
||||||
|
|
3
daemon/.packaging/leap/15.2/pre-run.sh
Executable file
3
daemon/.packaging/leap/15.2/pre-run.sh
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
zypper addrepo https://download.opensuse.org/repositories/home:CZ-NIC:knot-resolver-latest/openSUSE_Leap_15.2/home:CZ-NIC:knot-resolver-latest.repo
|
||||||
|
zypper --no-gpg-checks refresh
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue