├── .dockerignore ├── .gitignore ├── AUTHORS ├── COPYING ├── ChangeLog ├── GPL-3.txt ├── INSTALL ├── Makefile.am ├── NEWS ├── README ├── TODO ├── autogen.sh ├── cmake-projects ├── .gitignore ├── Makefile.am ├── README ├── jsonpath │ ├── .gitignore │ ├── CMakeLists.txt │ ├── ast.c │ ├── ast.h │ ├── contrib │ │ ├── lemon.c │ │ └── lempar.c │ ├── lexer.c │ ├── lexer.h │ ├── libubox │ │ ├── .gitignore │ │ ├── CMakeLists.txt │ │ ├── avl-cmp.c │ │ ├── avl-cmp.h │ │ ├── avl.c │ │ ├── avl.h │ │ ├── base64.c │ │ ├── blob.c │ │ ├── blob.h │ │ ├── blobmsg.c │ │ ├── blobmsg.h │ │ ├── blobmsg_json.c │ │ ├── blobmsg_json.h │ │ ├── examples │ │ │ ├── CMakeLists.txt │ │ │ ├── blobmsg-example.c │ │ │ ├── json_script-example.c │ │ │ ├── json_script-example.json │ │ │ ├── json_script-tests.sh │ │ │ ├── runqueue-example.c │ │ │ ├── shunit2 │ │ │ ├── uloop-example.lua │ │ │ ├── uloop_pid_test.sh │ │ │ └── ustream-example.c │ │ ├── jshn.c │ │ ├── json_script.c │ │ ├── json_script.h │ │ ├── kvlist.c │ │ ├── kvlist.h │ │ ├── list.h │ │ ├── lua │ │ │ ├── CMakeLists.txt │ │ │ └── uloop.c │ │ ├── md5.c │ │ ├── md5.h │ │ ├── runqueue.c │ │ ├── runqueue.h │ │ ├── safe_list.c │ │ ├── safe_list.h │ │ ├── sh │ │ │ └── jshn.sh │ │ ├── tests │ │ │ ├── CMakeLists.txt │ │ │ ├── cram │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── inputs │ │ │ │ │ ├── invalid.ucert │ │ │ │ │ ├── json-script.json │ │ │ │ │ ├── key-build.ucert │ │ │ │ │ ├── procd-instance-nlbwmon.bin │ │ │ │ │ └── signature.ucert │ │ │ │ ├── test_avl.t │ │ │ │ ├── test_base64.t │ │ │ │ ├── test_blob_parse.t │ │ │ │ ├── test_blobmsg.t │ │ │ │ ├── test_blobmsg_check_array.t │ │ │ │ ├── test_blobmsg_parse.t │ │ │ │ ├── test_blobmsg_procd_instance.t │ │ │ │ ├── test_blobmsg_types.t │ │ │ │ ├── test_jshn.t │ │ │ │ ├── test_json_script.t │ │ │ │ ├── test_list.t │ │ │ │ └── test_runqueue.t │ │ │ ├── fuzz │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── corpus │ │ │ │ │ ├── 71520a5c4b5ca73903216857abbad54a8002d44a │ │ │ │ │ ├── c1dfd96eea8cc2b62785275bca38ac261256e278 │ │ │ │ │ ├── c42ac1c46f1d4e211c735cc7dfad4ff8391110e9 │ │ │ │ │ ├── crash-1b8fb1be45db3aff7699100f497fb74138f3df4f │ │ │ │ │ ├── crash-333757b203a44751d3535f24b05f467183a96d09 │ │ │ │ │ ├── crash-4c4d2c3c9ade5da9347534e290305c3b9760f627 │ │ │ │ │ ├── crash-5e9937b197c88bf4e7b7ee2612456cad4cb83f5b │ │ │ │ │ ├── crash-75b146c4e6fac64d3e62236b27c64b50657bab2a │ │ │ │ │ ├── crash-813f3e68661da09c26d4a87dbb9d5099e92be50f │ │ │ │ │ ├── crash-98595faa58ba01d85ba4fd0b109cd3d490b45795 │ │ │ │ │ ├── crash-a3585b70f1c7ffbdec10f6dadc964336118485c4 │ │ │ │ │ ├── crash-b3585b70f1c7ffbdec10f6dadc964336118485c4 │ │ │ │ │ ├── crash-d0f3aa7d60a094b021f635d4edb7807c055a4ea1 │ │ │ │ │ ├── crash-df9d1243057b27bbad6211e5a23d1cb699028aa2 │ │ │ │ │ ├── crash-e0f8ecc694d96a09a1fced27b2a0838b670d34a0 │ │ │ │ │ ├── crash-e2fd5ecb3b37926743256f1083f47a07c39e10c2 │ │ │ │ │ └── valid-blobmsg.bin │ │ │ │ └── test-fuzz.c │ │ │ ├── shunit2 │ │ │ │ ├── CMakeLists.txt │ │ │ │ └── shunit2 │ │ │ │ │ └── shunit2 │ │ │ ├── test-avl.c │ │ │ ├── test-b64.c │ │ │ ├── test-b64_decode.c │ │ │ ├── test-b64_encode.c │ │ │ ├── test-blob-parse.c │ │ │ ├── test-blobmsg-parse.c │ │ │ ├── test-blobmsg-procd-instance.c │ │ │ ├── test-blobmsg-types.c │ │ │ ├── test-blobmsg.c │ │ │ ├── test-blobmsg_check_array.c │ │ │ ├── test-json-script.c │ │ │ ├── test-list.c │ │ │ └── test-runqueue.c │ │ ├── ubox_assert.h │ │ ├── ulog.c │ │ ├── ulog.h │ │ ├── uloop-epoll.c │ │ ├── uloop-kqueue.c │ │ ├── uloop.c │ │ ├── uloop.h │ │ ├── usock.c │ │ ├── usock.h │ │ ├── ustream-fd.c │ │ ├── ustream.c │ │ ├── ustream.h │ │ ├── utils.c │ │ ├── utils.h │ │ ├── vlist.c │ │ └── vlist.h │ ├── main.c │ ├── matcher.c │ ├── matcher.h │ └── parser.y ├── jsonpath_changes.patch └── libubox_changes.patch ├── configure.ac ├── debian ├── .gitignore ├── br.nic.simet.simet-ma-reports.desktop ├── changelog ├── compat ├── control ├── copyright ├── dhclient-exit-hook │ └── simet-ma ├── dhcpcd-hook │ └── 90-simet-ma.conf ├── etc.apt.conf.d │ └── 55nicbr-unattended-upgrades ├── etc.apt.sources.list.d │ └── simet.apt.source.template ├── etc.apt │ └── nicbr-simet.apt.key.gpg ├── networkd-dispatcher.routable │ └── 50simet-ma ├── networkmanager-dispatcher │ └── 50simet-ma ├── rules ├── simet-lmapd.init ├── simet-ma.cron.daily ├── simet-ma.cron.weekly ├── simet-ma.if-up ├── simet-ma.init ├── simet-ma.install ├── simet-ma.lintian-overrides ├── simet-ma.postinst ├── simet-ma.postrm ├── simet-ma.ppp.ip-up ├── simetnicbr.svg └── source │ ├── format │ └── lintian-overrides ├── docker ├── Dockerfile ├── Dockerfile.reference-container ├── README.txt ├── helpers │ └── simet-ma-prepare.sh ├── policy-rc.d ├── rsyslog.conf └── simet-ma.foreground.sh ├── docs ├── README.build.txt ├── SIMET-overview.txt ├── developer-notes.txt ├── firmware_vendor_release_notes.txt ├── task_exit_status.h └── task_module_api.txt ├── inetup-client-c ├── .gitignore ├── AUTHORS ├── COPYING ├── ChangeLog ├── INSTALL ├── Makefile.am ├── NEWS ├── README ├── autogen.sh ├── configure.ac ├── m4 │ ├── ax_append_compile_flags.m4 │ ├── ax_append_flag.m4 │ ├── ax_append_link_flags.m4 │ ├── ax_check_compile_flag.m4 │ ├── ax_check_link_flag.m4 │ └── ax_require_defined.m4 ├── src │ ├── Makefile.am │ ├── logger.h │ ├── netinet-tcp-compat.h │ ├── retry.h │ ├── simet-inetuptime.c │ ├── simet-inetuptime.h │ ├── simet_err.h │ ├── sys-linux.c │ ├── sys-linux.h │ ├── tcpaq.c │ └── tcpaq.h └── version.sh ├── simet-api ├── .gitignore ├── API.md ├── Makefile.am ├── README ├── conf │ ├── lmap-emergency-schedule.json │ ├── lmap-empty-schedule.json │ ├── lmap-sched-template.simet.json │ ├── lmap-sched-template.simetbox.json │ └── simet-ma.conf.in ├── config.d │ ├── simet-ma_base-config.json.in │ └── simetbox_base-config.json.in ├── examples │ ├── vendor.get_platform_simet_label │ └── vendor.get_platform_simet_secret ├── lmap-tasks │ ├── lmap-traceroute-wrapper.sh.in │ ├── lmap-wrapper.sh.in │ ├── simet2-agent-info.sh.in │ └── simetbox_fping-to-gateway.sh.in ├── registry.d │ ├── simet-ma_base-registry.json.in │ ├── simet.nic.br_subsystem-id.tag-registry.json │ └── simetbox_base-registry.json.in ├── simet_create_vlabel.simet.sh.in ├── simet_create_vlabel.simetbox.sh.in ├── simet_geolocation.sh.in ├── simet_issuebanner-generator.sh.in ├── simet_lib.simet.sh.in ├── simet_lib.simetbox.sh.in ├── simet_lib_config.sh.in ├── simet_lib_lmapd.sh.in ├── simet_lmap-create-report.sh.in ├── simet_lmap-fetch-schedule.sh.in ├── simet_lmap-send-report.sh.in ├── simet_lmap-stdout-wrapper.sh.in ├── simet_pairing_info.sh.in ├── simet_qrcode.sh.in ├── simet_read_vlabel.simet.sh.in ├── simet_read_vlabel.simetbox.sh.in ├── simet_register_ma.sh.in ├── simet_report-queue-flush.sh.in ├── simet_spoofer_v2.sh.in ├── simet_view_results.sh.in ├── simetbox_lmap-fetch-schedule.sh.in └── utils │ ├── .gitignore │ ├── AUTHORS │ ├── COPYING │ ├── ChangeLog │ ├── INSTALL │ ├── Makefile.am │ ├── NEWS │ ├── README │ ├── autogen.sh │ ├── configure.ac │ ├── m4 │ ├── ax_append_compile_flags.m4 │ ├── ax_append_flag.m4 │ ├── ax_append_link_flags.m4 │ ├── ax_check_compile_flag.m4 │ ├── ax_check_link_flag.m4 │ └── ax_require_defined.m4 │ ├── src │ ├── Makefile.am │ ├── base64.c │ ├── base64.h │ ├── base64_test.c │ ├── crc16.c │ ├── crc16.h │ ├── sha256.c │ ├── sha256.h │ └── simet_gen_vlabel.c │ └── version.sh ├── simet-dnsaddr-c ├── .gitignore ├── AUTHORS ├── COPYING ├── ChangeLog ├── INSTALL ├── Makefile.am ├── NEWS ├── README ├── autogen.sh ├── configure.ac ├── m4 │ ├── ax_append_compile_flags.m4 │ ├── ax_append_flag.m4 │ ├── ax_append_link_flags.m4 │ ├── ax_check_compile_flag.m4 │ ├── ax_check_link_flag.m4 │ └── ax_require_defined.m4 ├── src │ ├── Makefile.am │ ├── base64.c │ ├── base64.h │ ├── base64_test.c │ ├── logger.h │ ├── report.c │ ├── report.h │ ├── retry.h │ ├── simet_dnsaddr.c │ ├── simet_err.h │ ├── simet_random.c │ ├── simet_random.h │ └── timespec.h └── version.sh ├── simet-runner ├── .gitignore ├── Dockerfile ├── Makefile.am ├── autogen.sh ├── configure.ac ├── src │ ├── defines.sh.in │ ├── log.sh │ ├── main.sh │ ├── subtask_msmtparams.sh │ ├── subtask_serversel.sh │ ├── task_authentication.sh │ ├── task_authorization.sh │ ├── task_discover.sh │ ├── task_environment.sh │ ├── task_geolocation.sh │ ├── task_traceroute.sh │ ├── templates.sh │ └── util.sh ├── test │ ├── services-example.json │ └── simet-ma.conf └── version.sh ├── sspoofer-client-c ├── .gitignore ├── AUTHORS ├── COPYING ├── ChangeLog ├── INSTALL ├── Makefile.am ├── NEWS ├── README ├── TODO.txt ├── autogen.sh ├── configure.ac ├── m4 │ ├── ax_append_compile_flags.m4 │ ├── ax_append_flag.m4 │ ├── ax_append_link_flags.m4 │ ├── ax_check_compile_flag.m4 │ ├── ax_check_link_flag.m4 │ └── ax_require_defined.m4 ├── src │ ├── Makefile.am │ ├── base64.c │ ├── base64.h │ ├── base64_test.c │ ├── logger.h │ ├── misc.c │ ├── msmtpkt.c │ ├── netinet-tcp-compat.h │ ├── report.c │ ├── report.h │ ├── retry.h │ ├── simet_err.h │ ├── sspooferc.c │ ├── sspooferc.h │ ├── sys-linux.c │ ├── sys-linux.h │ ├── tcpaq.c │ ├── tcpaq.h │ └── timespec.h └── version.sh ├── tcpbw-client-c ├── .gitignore ├── AUTHORS ├── COPYING ├── ChangeLog ├── INSTALL ├── Makefile.am ├── NEWS ├── README ├── autogen.sh ├── configure.ac ├── environment │ └── alpine │ │ └── Dockerfile ├── m4 │ ├── ax_append_compile_flags.m4 │ ├── ax_append_flag.m4 │ ├── ax_append_link_flags.m4 │ ├── ax_check_compile_flag.m4 │ ├── ax_check_link_flag.m4 │ ├── ax_require_defined.m4 │ └── libcurl.m4 ├── src │ ├── Makefile.am │ ├── libubox │ │ ├── usock.c │ │ └── usock.h │ ├── logger.h │ ├── report.c │ ├── report.h │ ├── retry.h │ ├── simet_err.h │ ├── tcpbwc-tcp.c │ ├── tcpbwc.c │ ├── tcpbwc.h │ ├── tcpinfo.h │ └── timespec.h └── version.sh ├── twamp-client-c ├── .gitignore ├── AUTHORS ├── COPYING ├── ChangeLog ├── Dockerfile ├── INSTALL ├── Makefile.am ├── NEWS ├── README ├── autogen.sh ├── configure.ac ├── m4 │ ├── ax_append_compile_flags.m4 │ ├── ax_append_flag.m4 │ ├── ax_append_link_flags.m4 │ ├── ax_check_compile_flag.m4 │ ├── ax_check_link_flag.m4 │ └── ax_require_defined.m4 ├── src │ ├── Makefile.am │ ├── base64.c │ ├── base64.h │ ├── base64_test.c │ ├── libubox │ │ ├── usock.c │ │ └── usock.h │ ├── logger.h │ ├── message.c │ ├── message.h │ ├── report.c │ ├── report.h │ ├── retry.h │ ├── simet_err.h │ ├── timespec.h │ ├── timestamp.c │ ├── timestamp.h │ ├── twamp.c │ ├── twamp.h │ └── twampc.c └── version.sh ├── version └── version.sh /.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /Makefile 2 | /Makefile.in 3 | aclocal.m4 4 | autom4te.cache/ 5 | /compile 6 | config.guess 7 | config.log 8 | config.status 9 | config.sub 10 | /configure 11 | depcomp 12 | install-sh 13 | missing 14 | dist 15 | doc 16 | notes 17 | 18 | *.orig 19 | *.rej 20 | *.swp 21 | *~ 22 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Main authors: 2 | NIC.br - Núcleo de Informação e Coordenação do Ponto BR 3 | * Fábio Nokai 4 | * Henrique de Moraes Holschuh 5 | * Holger Wiehen 6 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | * Nothing yet, tracked as git log 2 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | v0.10.0: 2 | * Initial LMAP scheduler support. simet-ma now requires 3 | the simet-lmapd package to be installed, or measurements 4 | won't run. Crontab and boot services are still required 5 | for critical administrative tasks that must not (or cannot) 6 | depend on lmapd. 7 | 8 | v0.9.1: 9 | * Docker container support/examples (build and run) 10 | * Some documentation added to docs/ 11 | 12 | v0.9.0: 13 | * First public release. BETA code, which will still undergo 14 | several relevant changes. 15 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | NIC.br SIMET-MA: SIMET2 Measurement Agent 2 | Copyright (c) 2018,2019 NIC.br 3 | 4 | 5 | Please refer to the docs/ directory for details about the SIMET2 system 6 | and about this software. 7 | 8 | You will also find a quick guide on how to compile the software there. 9 | 10 | This package has a runtime dependency on the simet-lmapd package: both 11 | packages must be installed for measurements tasks to be run. 12 | 13 | This package contains recipes and helper scripts for building and/or 14 | running a SIMET-MA instance through a docker image. Please refer to the 15 | docker/ directory for details. 16 | 17 | The copyright license for the SIMET-MA source code and software is on 18 | the COPYING file. It is based on the GNU GPL version 3 license WITH 19 | ADDITIONAL TERMS AND PERMISSIONS. 20 | 21 | The text of the original GPL version 3 is in the GPL-3.txt file, and it 22 | was included as a convenience, only. THE ADDITIONAL TERMS AND 23 | PERMISSIONS present in the COPYING file ARE A PART OF THIS SOFTWARE AND 24 | SOURCE CODE LICENSE. 25 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | Main TODO: 2 | 3 | ! Move to a lmapd-based scheduling core and extension system 4 | + Teach json to lmapd to avoid libxml2 runtime cost on embedded 5 | 6 | * Unify the common source and functions and while at it clean up 7 | and consolidate the build system. 8 | 9 | * Drop the use of libubox, we want more visibility to the underlying 10 | details than it gives us, and it doesn't do everything we need it to 11 | anyway. 12 | 13 | * Write proper lua or C replacements for shell hacks. 14 | 15 | * O.S./hardware timestamping for LAN measurement (Internet 16 | measurements are too coarse to need this). 17 | 18 | * Refactor most of the code as we go, much of it is basically a 19 | working prototype... and nauseating to look at for too long. 20 | 21 | * Add all the missing functionality ;-) 22 | 23 | * Valgrind is our friend, so we should invite it to tea at every 24 | "make test". 25 | 26 | * Actually add "make test" (unit tests and systemic tests), use 27 | "check" for the C unit tests, and a harness for the systemic 28 | tests. 29 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2018,2019 NIC.br 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. In every case, additional 9 | # restrictions and permissions apply, refer to the COPYING file in the 10 | # program Source for details. 11 | # 12 | # This program is distributed in the hope that it will be useful, but 13 | # WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | # General Public License and the COPYING file in the program Source 16 | # for details. 17 | # 18 | # 19 | # Commands required to prepare tree for building after a clean 20 | # checkout: 21 | # 22 | # Embedded libubox/jsonpath build dependencies: 23 | # libjson-c-dev cmake 24 | # 25 | # Main project build dependencies: 26 | # autoconf, automake, libtool (recent versions!) 27 | 28 | ./version.sh >/dev/null 2>&1 || { 29 | echo "$0: missing version file and not in a worktree" >&2 30 | exit 1 31 | } 32 | autoreconf -i 33 | -------------------------------------------------------------------------------- /cmake-projects/.gitignore: -------------------------------------------------------------------------------- 1 | /Makefile 2 | /Makefile.in 3 | /jsonpath/contrib/lemon 4 | /jsonpath/parser.out 5 | simet-build-dir/ 6 | -------------------------------------------------------------------------------- /cmake-projects/Makefile.am: -------------------------------------------------------------------------------- 1 | # Automake <-> CMake impedence matching layer 2 | # 3 | # all 4 | # clean 5 | # dist 6 | # distclean 7 | # install 8 | # 9 | # distdir (for dist/distcheck) 10 | # 11 | # CMake notes: 12 | # * must use out-of-source builds 13 | # and the CMake development team are holding back the world by refusing to 14 | # support -H, -B, so we have to do nasty hacks 15 | # * must manually adjust this file for each new projetc, to take advantage 16 | # of cmake -D 17 | 18 | # something unlikely to be in a vendor source 19 | cmake_build_subdir = simet-build-dir 20 | 21 | EMPTY_AUTOMAKE_TARGETS = dvi pdf ps info html tags ctags 22 | .PHONY: $(EMPTY_AUTOMAKE_TARGETS) 23 | $(EMPTY_AUTOMAKE_TARGETS): 24 | 25 | if SIMETBOX_BUILD 26 | # we do not need these when doing an OpenWRT build 27 | cmakeprojectsubdirs = 28 | cmakeprojectdeps = 29 | else 30 | # we typically need these when not doing an OpenWRT build 31 | cmakeprojectsubdirs = jsonpath 32 | cmakeprojectdeps = jsonpath/$(cmake_build_subdir)/Makefile 33 | endif 34 | 35 | jsonpath/$(cmake_build_subdir)/Makefile: jsonpath/CMakeLists.txt 36 | (cd jsonpath && rm -fr "$(cmake_build_subdir)" && $(MKDIR_P) -- "$(cmake_build_subdir)" && \ 37 | cd "$(cmake_build_subdir)" && cmake -DCMAKE_INSTALL_PREFIX="$(prefix)" -DBUILD_LUA=OFF -DBUILD_EXAMPLES=OFF ..) \ 38 | || exit $? 39 | 40 | all-local: $(cmakeprojectdeps) 41 | for i in $(cmakeprojectsubdirs) ; do $(MAKE) -C "$$i/$(cmake_build_subdir)" all $(AM_MAKEFLAGS) ; done 42 | 43 | check-local: 44 | for i in $(cmakeprojectsubdirs) ; do $(MAKE) -C "$$i/$(cmake_build_subdir)" test $(AM_MAKEFLAGS) ; done 45 | 46 | clean-local: 47 | for i in $(cmakeprojectsubdirs) ; do $(MAKE) -C "$$i/$(cmake_build_subdir)" clean $(AM_MAKEFLAGS) ; rm -fr "$$i/$(cmake_build_subdir)" ; done 48 | 49 | distclean-local: clean-local 50 | 51 | install-cmake: 52 | for i in $(cmakeprojectsubdirs) ; do $(MAKE) -C "$$i/$(cmake_build_subdir)" install $(AM_MAKEFLAGS) ; done 53 | 54 | install-data-local: install-cmake 55 | install-exec-local: install-cmake 56 | 57 | # Distribute files from here. 58 | EXTRA_DIST = $(cmakeprojectsubdirs) jsonpath_changes.patch libubox_changes.patch 59 | #dist-hook: 60 | -------------------------------------------------------------------------------- /cmake-projects/README: -------------------------------------------------------------------------------- 1 | Local modifications: 2 | 3 | JSONFILTER (jsonpath): 4 | https://git.openwrt.org/project/jsonpath.git 5 | added libubox/, do a static build (and use libubox-static for that) 6 | 7 | libubox (in jsonpath/libubox/) 8 | https://git.openwrt.org/project/libubox.git 9 | disabled all install() CMake commands, since we use it only during the build 10 | 11 | These modifications are available as patches on this directory. 12 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | CMakeCache.txt 3 | CMakeFiles 4 | *.cmake 5 | install_manifest.txt 6 | jsonpath 7 | parser.[ch] 8 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | 3 | PROJECT(jsonpath C) 4 | ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -Wmissing-declarations -Wno-error=unused-variable -ffunction-sections -D_GNU_SOURCE) 5 | 6 | IF(NOT APPLE) 7 | SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-Wl,--gc-sections") 8 | ENDIF() 9 | 10 | find_library(json NAMES json-c json) 11 | 12 | IF(DEBUG) 13 | ADD_DEFINITIONS(-DDEBUG -g3) 14 | ENDIF() 15 | 16 | INCLUDE(FindPkgConfig) 17 | PKG_CHECK_MODULES(JSONC json-c json) 18 | IF(JSONC_FOUND) 19 | ADD_DEFINITIONS(-DJSONC) 20 | INCLUDE_DIRECTORIES(${JSONC_INCLUDE_DIRS}) 21 | ENDIF() 22 | 23 | ADD_CUSTOM_COMMAND( 24 | OUTPUT lemon 25 | DEPENDS ${CMAKE_SOURCE_DIR}/contrib/lemon.c ${CMAKE_SOURCE_DIR}/contrib/lempar.c 26 | COMMAND gcc -o lemon -I "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/contrib/lemon.c" 27 | COMMENT "Generating lemon parser generator" 28 | ) 29 | 30 | ADD_CUSTOM_COMMAND( 31 | OUTPUT ${CMAKE_SOURCE_DIR}/parser.c 32 | DEPENDS ${CMAKE_SOURCE_DIR}/parser.y lemon 33 | COMMAND cd "${CMAKE_SOURCE_DIR}" && ${CMAKE_BINARY_DIR}/lemon -T${CMAKE_SOURCE_DIR}/contrib/lempar.c parser.y 34 | COMMENT "Generating parser.c" 35 | ) 36 | 37 | FIND_PATH(ubox_include_dir libubox/list.h) 38 | IF(ubox_include_dir MATCHES "NOTFOUND$") 39 | ADD_SUBDIRECTORY(libubox) 40 | INCLUDE_DIRECTORIES(libubox) 41 | ELSE() 42 | INCLUDE_DIRECTORIES(${ubox_include_dir}) 43 | ENDIF() 44 | 45 | SET_PROPERTY(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "lemon;parser.h;parser.out") 46 | SET_SOURCE_FILES_PROPERTIES("parser.c" PROPERTIES GENERATED TRUE) 47 | 48 | SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a") 49 | SET(BUILD_SHARED_LIBS OFF) 50 | SET(CMAKE_EXE_LINKER_FLAGS "-static") 51 | 52 | ADD_EXECUTABLE(jsonpath main.c ast.c lexer.c parser.c matcher.c) 53 | TARGET_LINK_LIBRARIES(jsonpath ubox-static ${json}) 54 | 55 | INSTALL(TARGETS jsonpath RUNTIME DESTINATION bin) 56 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/ast.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014 Jo-Philipp Wich 3 | * 4 | * Permission to use, copy, modify, and/or distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef __AST_H_ 18 | #define __AST_H_ 19 | 20 | #include 21 | 22 | struct jp_opcode { 23 | int type; 24 | struct jp_opcode *next; 25 | struct jp_opcode *down; 26 | struct jp_opcode *sibling; 27 | char *str; 28 | int num; 29 | }; 30 | 31 | struct jp_state { 32 | struct jp_opcode *pool; 33 | struct jp_opcode *path; 34 | int error_pos; 35 | int error_code; 36 | int off; 37 | }; 38 | 39 | static inline struct jp_opcode * 40 | append_op(struct jp_opcode *a, struct jp_opcode *b) 41 | { 42 | struct jp_opcode *tail = a; 43 | 44 | while (tail->sibling) 45 | tail = tail->sibling; 46 | 47 | tail->sibling = b; 48 | 49 | return a; 50 | } 51 | 52 | struct jp_opcode *jp_alloc_op(struct jp_state *s, int type, int num, char *str, ...); 53 | struct jp_state *jp_parse(const char *expr); 54 | void jp_free(struct jp_state *s); 55 | 56 | void *ParseAlloc(void *(*mfunc)(size_t)); 57 | void Parse(void *pParser, int type, struct jp_opcode *op, struct jp_state *s); 58 | void ParseFree(void *pParser, void (*ffunc)(void *)); 59 | 60 | #endif /* __AST_H_ */ 61 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/lexer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014 Jo-Philipp Wich 3 | * 4 | * Permission to use, copy, modify, and/or distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef __LEXER_H_ 18 | #define __LEXER_H_ 19 | 20 | #include "ast.h" 21 | 22 | extern const char *tokennames[25]; 23 | 24 | struct jp_opcode * 25 | jp_get_token(struct jp_state *s, const char *input, int *mlen); 26 | 27 | #endif /* __LEXER_H_ */ 28 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | CMakeCache.txt 3 | CMakeFiles 4 | *.cmake 5 | *.a 6 | *.so 7 | *.dylib 8 | install_manifest.txt 9 | jshn 10 | *-example 11 | tests.* 12 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/avl-cmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Felix Fietkau 3 | * 4 | * Permission to use, copy, modify, and/or distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | #include 17 | #include "avl-cmp.h" 18 | #include "blob.h" 19 | 20 | static inline int _min(int v1, int v2) 21 | { 22 | return v1 < v2 ? v1 : v2; 23 | } 24 | 25 | int 26 | avl_strcmp(const void *k1, const void *k2, void *ptr) 27 | { 28 | return strcmp(k1, k2); 29 | } 30 | 31 | int 32 | avl_blobcmp(const void *k1, const void *k2, void *ptr) 33 | { 34 | int len = _min(blob_raw_len(k1), blob_raw_len(k2)); 35 | 36 | return memcmp(k1, k2, len); 37 | } 38 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/avl-cmp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Felix Fietkau 3 | * 4 | * Permission to use, copy, modify, and/or distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | #ifndef __AVL_CMP_H 17 | #define __AVL_CMP_H 18 | 19 | int avl_strcmp(const void *k1, const void *k2, void *ptr); 20 | int avl_blobcmp(const void *k1, const void *k2, void *ptr); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/blobmsg_json.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010-2012 Felix Fietkau 3 | * 4 | * Permission to use, copy, modify, and/or distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | #ifndef __BLOBMSG_JSON_H 17 | #define __BLOBMSG_JSON_H 18 | 19 | struct json_object; 20 | 21 | #include 22 | #include "blobmsg.h" 23 | 24 | bool blobmsg_add_object(struct blob_buf *b, struct json_object *obj); 25 | bool blobmsg_add_json_element(struct blob_buf *b, const char *name, struct json_object *obj); 26 | bool blobmsg_add_json_from_string(struct blob_buf *b, const char *str); 27 | bool blobmsg_add_json_from_file(struct blob_buf *b, const char *file); 28 | 29 | typedef const char *(*blobmsg_json_format_t)(void *priv, struct blob_attr *attr); 30 | 31 | char *blobmsg_format_json_with_cb(struct blob_attr *attr, bool list, 32 | blobmsg_json_format_t cb, void *priv, 33 | int indent); 34 | 35 | static inline char *blobmsg_format_json(struct blob_attr *attr, bool list) 36 | { 37 | return blobmsg_format_json_with_cb(attr, list, NULL, NULL, -1); 38 | } 39 | 40 | static inline char *blobmsg_format_json_indent(struct blob_attr *attr, bool list, int indent) 41 | { 42 | return blobmsg_format_json_with_cb(attr, list, NULL, NULL, indent); 43 | } 44 | 45 | char *blobmsg_format_json_value_with_cb(struct blob_attr *attr, 46 | blobmsg_json_format_t cb, void *priv, 47 | int indent); 48 | 49 | static inline char *blobmsg_format_json_value(struct blob_attr *attr) 50 | { 51 | return blobmsg_format_json_value_with_cb(attr, NULL, NULL, -1); 52 | } 53 | 54 | static inline char *blobmsg_format_json_value_indent(struct blob_attr *attr, int indent) 55 | { 56 | return blobmsg_format_json_value_with_cb(attr, NULL, NULL, indent); 57 | } 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | 3 | IF (BUILD_EXAMPLES) 4 | PROJECT(ubox-examples C) 5 | ADD_DEFINITIONS(-O1 -Wall -Werror --std=gnu99 -g3) 6 | 7 | INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/..) 8 | LINK_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/..) 9 | 10 | FIND_LIBRARY(json NAMES json-c json) 11 | 12 | ADD_EXECUTABLE(ustream-example ustream-example.c) 13 | TARGET_LINK_LIBRARIES(ustream-example ubox) 14 | 15 | ADD_EXECUTABLE(json_script-example json_script-example.c) 16 | TARGET_LINK_LIBRARIES(json_script-example ubox blobmsg_json json_script ${json}) 17 | ENDIF() 18 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/examples/json_script-example.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include "blobmsg.h" 6 | #include "blobmsg_json.h" 7 | #include "json_script.h" 8 | 9 | struct json_script_ctx jctx; 10 | struct blob_buf b_vars; 11 | struct blob_buf b_script; 12 | 13 | static void handle_command(struct json_script_ctx *ctx, const char *name, 14 | struct blob_attr *data, struct blob_attr *vars) 15 | { 16 | struct blob_attr *cur; 17 | size_t rem; 18 | 19 | fprintf(stdout, "%s", name); 20 | blobmsg_for_each_attr(cur, data, rem) 21 | fprintf(stdout, " %s", (char *) blobmsg_data(cur)); 22 | fprintf(stdout, "\n"); 23 | } 24 | 25 | static struct json_script_file * 26 | handle_file(struct json_script_ctx *ctx, const char *filename) 27 | { 28 | json_object *obj; 29 | 30 | obj = json_object_from_file(filename); 31 | if (!obj) { 32 | fprintf(stderr, "load JSON data from %s failed.\n", filename); 33 | return NULL; 34 | } 35 | 36 | blob_buf_init(&b_script, 0); 37 | blobmsg_add_json_element(&b_script, "", obj); 38 | json_object_put(obj); 39 | 40 | return json_script_file_from_blobmsg(filename, 41 | blob_data(b_script.head), blob_len(b_script.head)); 42 | } 43 | 44 | static void usage(const char *prog, int exit_code) 45 | { 46 | fprintf(stderr, "Usage: %s [VARNAME=value] \n", prog); 47 | exit(exit_code); 48 | } 49 | 50 | int main(int argc, char *argv[]) 51 | { 52 | int i; 53 | char *file = NULL; 54 | const char *prog = argv[0]; 55 | 56 | blobmsg_buf_init(&b_vars); 57 | blobmsg_buf_init(&b_script); 58 | 59 | json_script_init(&jctx); 60 | jctx.handle_command = handle_command; 61 | jctx.handle_file = handle_file; 62 | 63 | for (i = 1; i < argc; i++) { 64 | char *sep = strchr(argv[i], '='); 65 | if (sep) { 66 | *sep = '\0'; 67 | blobmsg_add_string(&b_vars, argv[i], sep + 1); 68 | } else if (!file) { 69 | file = argv[i]; 70 | } else { 71 | usage(prog, -1); 72 | } 73 | } 74 | if (i < argc || !file) 75 | usage(prog, -2); 76 | 77 | json_script_run(&jctx, file, b_vars.head); 78 | 79 | json_script_free(&jctx); 80 | blob_buf_free(&b_script); 81 | blob_buf_free(&b_vars); 82 | 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/examples/json_script-example.json: -------------------------------------------------------------------------------- 1 | [ 2 | [ "exec", "%EXECVAR%", "/%%/" ], 3 | [ "if", 4 | [ "eq", "EQVAR", "eqval" ], 5 | [ "exec_if", "%VAR%", "%%", "jk" ] 6 | ], 7 | [ "case", "CASEVAR", { 8 | "caseval0": ["cmd_case_0", "cmd_case_arg0", "case_cmd_arg1"], 9 | "caseval1": ["cmd_case_1", "cmd_case_arg0", "case_cmd_arg1"] 10 | } ], 11 | 12 | [ "if", 13 | [ "and", [ "eq", "EQVAR", "eqval" ], 14 | [ "has", "HASVAR" ], 15 | [ "regex", "REGEXVAR0", "regexval" ], 16 | [ "regex", "REGEXVAR1", [ "regexval10", "regexval11" ] ], 17 | [ "not", [ "eq", "NOTEQVAR", "noteqval" ] ] ], 18 | [ "exec_if_and", "%ANDVAR%" ] 19 | ], 20 | 21 | [ "if", 22 | [ "or", [ "eq", "EQVAR", "eqval" ], 23 | [ "has", "HASVAR" ], 24 | [ "regex", "REGEXVAR0", "regexval" ], 25 | [ "regex", "REGEXVAR1", [ "regexval10", "regexval11" ] ], 26 | [ "not", [ "eq", "NOTEQVAR", "noteqval" ] ] ], 27 | [ "exec_if_or", "%ORVAR%" ] 28 | ], 29 | 30 | [ "if", 31 | [ "isdir", "%ISDIRVAR%" ], 32 | [ "exec_isdir", "%ISDIRVAR%" ] 33 | ], 34 | 35 | [ "return", "foobar" ], 36 | 37 | [ "exec_non_reachable", "Arghhh" ] 38 | ] 39 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/examples/uloop-example.lua: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lua 2 | 3 | local socket = require "socket" 4 | 5 | local uloop = require("uloop") 6 | uloop.init() 7 | 8 | local udp = socket.udp() 9 | udp:settimeout(0) 10 | udp:setsockname('*', 8080) 11 | 12 | -- timer example 1 (will run repeatedly) 13 | local timer 14 | function t() 15 | print("1000 ms timer run"); 16 | timer:set(1000) 17 | end 18 | timer = uloop.timer(t) 19 | timer:set(1000) 20 | 21 | -- timer example 2 (will run once) 22 | uloop.timer(function() print("2000 ms timer run"); end, 2000) 23 | 24 | -- timer example 3 (will never run) 25 | uloop.timer(function() print("3000 ms timer run"); end, 3000):cancel() 26 | 27 | -- process 28 | function p1(r) 29 | print("Process 1 completed") 30 | print(r) 31 | end 32 | 33 | function p2(r) 34 | print("Process 2 completed") 35 | print(r) 36 | end 37 | 38 | uloop.timer( 39 | function() 40 | uloop.process("uloop_pid_test.sh", {"foo", "bar"}, {"PROCESS=1"}, p1) 41 | end, 1000 42 | ) 43 | uloop.timer( 44 | function() 45 | uloop.process("uloop_pid_test.sh", {"foo", "bar"}, {"PROCESS=2"}, p2) 46 | end, 2000 47 | ) 48 | 49 | -- Keep udp_ev reference, events will be gc'd, even if the callback is still referenced 50 | -- .delete will manually untrack. 51 | udp_ev = uloop.fd_add(udp, function(ufd, events) 52 | local words, msg_or_ip, port_or_nil = ufd:receivefrom() 53 | print('Recv UDP packet from '..msg_or_ip..':'..port_or_nil..' : '..words) 54 | if words == "Stop!" then 55 | udp_ev:delete() 56 | end 57 | end, uloop.ULOOP_READ) 58 | 59 | udp_count = 0 60 | udp_send_timer = uloop.timer( 61 | function() 62 | local s = socket.udp() 63 | local words 64 | if udp_count > 3 then 65 | words = "Stop!" 66 | udp_send_timer:cancel() 67 | else 68 | words = 'Hello!' 69 | udp_send_timer:set(1000) 70 | end 71 | print('Send UDP packet to 127.0.0.1:8080 :'..words) 72 | s:sendto(words, '127.0.0.1', 8080) 73 | s:close() 74 | 75 | udp_count = udp_count + 1 76 | end, 3000 77 | ) 78 | 79 | uloop.run() 80 | 81 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/examples/uloop_pid_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo $0 $* 4 | echo Environment: 5 | env 6 | 7 | sleep 2 8 | 9 | echo "stopping child" 10 | 11 | exit 5 12 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/kvlist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * kvlist - simple key/value store 3 | * 4 | * Copyright (C) 2014 Felix Fietkau 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | #ifndef __LIBUBOX_KVLIST_H 19 | #define __LIBUBOX_KVLIST_H 20 | 21 | #include "avl-cmp.h" 22 | #include "avl.h" 23 | 24 | struct kvlist { 25 | struct avl_tree avl; 26 | 27 | int (*get_len)(struct kvlist *kv, const void *data); 28 | }; 29 | 30 | struct kvlist_node { 31 | struct avl_node avl; 32 | 33 | char data[0] __attribute__((aligned(4))); 34 | }; 35 | 36 | #define KVLIST_INIT(_name, _get_len) \ 37 | { \ 38 | .avl = AVL_TREE_INIT(_name.avl, avl_strcmp, false, NULL), \ 39 | .get_len = _get_len \ 40 | } 41 | 42 | #define KVLIST(_name, _get_len) \ 43 | struct kvlist _name = KVLIST_INIT(_name, _get_len) 44 | 45 | #define __ptr_to_kv(_ptr) container_of(((char *) (_ptr)), struct kvlist_node, data[0]) 46 | #define __avl_list_to_kv(_l) container_of(_l, struct kvlist_node, avl.list) 47 | 48 | #define kvlist_for_each(kv, name, value) \ 49 | for (value = (void *) __avl_list_to_kv((kv)->avl.list_head.next)->data, \ 50 | name = (const char *) __ptr_to_kv(value)->avl.key, (void) name; \ 51 | &__ptr_to_kv(value)->avl.list != &(kv)->avl.list_head; \ 52 | value = (void *) (__avl_list_to_kv(__ptr_to_kv(value)->avl.list.next))->data, \ 53 | name = (const char *) __ptr_to_kv(value)->avl.key) 54 | 55 | void kvlist_init(struct kvlist *kv, int (*get_len)(struct kvlist *kv, const void *data)); 56 | void kvlist_free(struct kvlist *kv); 57 | void *kvlist_get(struct kvlist *kv, const char *name); 58 | bool kvlist_set(struct kvlist *kv, const char *name, const void *data); 59 | bool kvlist_delete(struct kvlist *kv, const char *name); 60 | 61 | int kvlist_strlen(struct kvlist *kv, const void *data); 62 | int kvlist_blob_len(struct kvlist *kv, const void *data); 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/lua/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | 3 | PROJECT(uloop C) 4 | 5 | SET(CMAKE_INSTALL_PREFIX /) 6 | 7 | IF(NOT LUA_CFLAGS) 8 | pkg_search_module(LUA lua5.1 lua-5.1) 9 | ENDIF() 10 | 11 | ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -I.. ${LUA_CFLAGS}) 12 | LINK_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/..) 13 | 14 | IF(APPLE) 15 | SET(CMAKE_SHARED_MODULE_CREATE_C_FLAGS "${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} -undefined dynamic_lookup") 16 | ENDIF(APPLE) 17 | 18 | IF(NOT LUAPATH) 19 | EXECUTE_PROCESS( 20 | COMMAND lua -e "for k in string.gmatch(package.cpath .. \";\", \"([^;]+)/..so;\") do if k:sub(1,1) == \"/\" then print(k) break end end" 21 | OUTPUT_VARIABLE LUAPATH 22 | RESULT_VARIABLE LUA_CHECK_RES 23 | OUTPUT_STRIP_TRAILING_WHITESPACE 24 | ) 25 | 26 | IF(BUILD_LUA) 27 | IF(NOT ${LUA_CHECK_RES} EQUAL 0 OR "${LUAPATH}" EQUAL "") 28 | MESSAGE(SEND_ERROR "Lua was not found on your system") 29 | ENDIF() 30 | ENDIF() 31 | ENDIF() 32 | 33 | IF(BUILD_LUA) 34 | ADD_LIBRARY(uloop_lua MODULE uloop.c) 35 | SET_TARGET_PROPERTIES(uloop_lua PROPERTIES 36 | OUTPUT_NAME uloop 37 | PREFIX "" 38 | ) 39 | TARGET_LINK_LIBRARIES(uloop_lua ubox) 40 | 41 | INSTALL(TARGETS uloop_lua 42 | LIBRARY DESTINATION ${LUAPATH} 43 | ) 44 | ENDIF() 45 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/md5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Felix Fietkau 3 | * 4 | * Permission to use, copy, modify, and/or distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | /* 17 | * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc. 18 | * MD5 Message-Digest Algorithm (RFC 1321). 19 | * 20 | * Homepage: 21 | * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5 22 | * 23 | * Author: 24 | * Alexander Peslyak, better known as Solar Designer 25 | * 26 | * This software was written by Alexander Peslyak in 2001. No copyright is 27 | * claimed, and the software is hereby placed in the public domain. 28 | * In case this attempt to disclaim copyright and place the software in the 29 | * public domain is deemed null and void, then the software is 30 | * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the 31 | * general public under the following terms: 32 | * 33 | * Redistribution and use in source and binary forms, with or without 34 | * modification, are permitted. 35 | * 36 | * There's ABSOLUTELY NO WARRANTY, express or implied. 37 | * 38 | * See md5.c for more information. 39 | */ 40 | 41 | #ifndef _LIBUBOX_MD5_H 42 | #define _LIBUBOX_MD5_H 43 | 44 | #include 45 | #include 46 | 47 | typedef struct md5_ctx { 48 | uint32_t lo, hi; 49 | uint32_t a, b, c, d; 50 | unsigned char buffer[64]; 51 | } md5_ctx_t; 52 | 53 | extern void md5_begin(md5_ctx_t *ctx); 54 | extern void md5_hash(const void *data, size_t length, md5_ctx_t *ctx); 55 | extern void md5_end(void *resbuf, md5_ctx_t *ctx); 56 | int md5sum(const char *file, void *md5_buf); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/safe_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * safe_list - linked list protected against recursive iteration with deletes 3 | * 4 | * Copyright (C) 2013 Felix Fietkau 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | /* 20 | * Use this linked list implementation as a replacement for list.h if you 21 | * want to allow deleting arbitrary list entries from within one or more 22 | * recursive iterator calling context 23 | */ 24 | 25 | #ifndef __LIBUBOX_SAFE_LIST_H 26 | #define __LIBUBOX_SAFE_LIST_H 27 | 28 | #include 29 | #include "list.h" 30 | #include "utils.h" 31 | 32 | struct safe_list; 33 | struct safe_list_iterator; 34 | 35 | struct safe_list { 36 | struct list_head list; 37 | struct safe_list_iterator *i; 38 | }; 39 | 40 | int safe_list_for_each(struct safe_list *list, 41 | int (*cb)(void *ctx, struct safe_list *list), 42 | void *ctx); 43 | 44 | void safe_list_add(struct safe_list *list, struct safe_list *head); 45 | void safe_list_add_first(struct safe_list *list, struct safe_list *head); 46 | void safe_list_del(struct safe_list *list); 47 | 48 | #define INIT_SAFE_LIST(_head) \ 49 | do { \ 50 | INIT_LIST_HEAD(_head.list); \ 51 | (_head)->i = NULL; \ 52 | } while (0) 53 | 54 | #define SAFE_LIST_INIT(_name) { LIST_HEAD_INIT(_name.list), NULL } 55 | #define SAFE_LIST(_name) struct safe_list _name = SAFE_LIST_INIT(_name) 56 | 57 | static inline bool safe_list_empty(struct safe_list *head) 58 | { 59 | return list_empty(&head->list); 60 | } 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_SUBDIRECTORY(cram) 2 | ADD_SUBDIRECTORY(shunit2) 3 | 4 | MACRO(ADD_UNIT_TEST name) 5 | ADD_EXECUTABLE(${name} ${name}.c) 6 | TARGET_LINK_LIBRARIES(${name} ubox blobmsg_json json_script ${json}) 7 | TARGET_INCLUDE_DIRECTORIES(${name} PRIVATE ${PROJECT_SOURCE_DIR}) 8 | ENDMACRO(ADD_UNIT_TEST) 9 | 10 | FILE(GLOB test_cases "test-*.c") 11 | FOREACH(test_case ${test_cases}) 12 | GET_FILENAME_COMPONENT(test_case ${test_case} NAME_WE) 13 | ADD_UNIT_TEST(${test_case}) 14 | ADD_UNIT_TEST_SAN(${test_case}) 15 | ENDFOREACH(test_case) 16 | 17 | IF(CMAKE_C_COMPILER_ID STREQUAL "Clang") 18 | ADD_SUBDIRECTORY(fuzz) 19 | ENDIF() 20 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/cram/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FIND_PACKAGE(PythonInterp 3 REQUIRED) 2 | FILE(GLOB test_cases "test_*.t") 3 | 4 | SET(PYTHON_VENV_DIR "${CMAKE_CURRENT_BINARY_DIR}/.venv") 5 | SET(PYTHON_VENV_PIP "${PYTHON_VENV_DIR}/bin/pip") 6 | SET(PYTHON_VENV_CRAM "${PYTHON_VENV_DIR}/bin/cram") 7 | 8 | ADD_CUSTOM_COMMAND( 9 | OUTPUT ${PYTHON_VENV_CRAM} 10 | COMMAND ${PYTHON_EXECUTABLE} -m venv ${PYTHON_VENV_DIR} 11 | COMMAND ${PYTHON_VENV_PIP} install cram 12 | ) 13 | ADD_CUSTOM_TARGET(prepare-cram-venv ALL DEPENDS ${PYTHON_VENV_CRAM}) 14 | 15 | ADD_TEST( 16 | NAME cram 17 | COMMAND ${PYTHON_VENV_CRAM} ${test_cases} 18 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 19 | ) 20 | 21 | SET_PROPERTY(TEST cram APPEND PROPERTY ENVIRONMENT "JSHN=$") 22 | SET_PROPERTY(TEST cram APPEND PROPERTY ENVIRONMENT "TEST_BIN_DIR=$") 23 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/cram/inputs/invalid.ucert: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simetnicbr/simet-ma/ec2c8fc045271fcb23d49193577b4af87652dd47/cmake-projects/jsonpath/libubox/tests/cram/inputs/invalid.ucert -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/cram/inputs/json-script.json: -------------------------------------------------------------------------------- 1 | [ 2 | [ "exec", "%EXECVAR%", "/%%/" ], 3 | [ "if", 4 | [ "eq", "EQVAR", "eqval" ], 5 | [ "exec_if", "%VAR%", "%%", "jk" ] 6 | ], 7 | [ "case", "CASEVAR", { 8 | "caseval0": ["cmd_case_0", "cmd_case_arg0", "case_cmd_arg1"], 9 | "caseval1": ["cmd_case_1", "cmd_case_arg0", "case_cmd_arg1"] 10 | } ], 11 | 12 | [ "if", 13 | [ "and", [ "eq", "EQVAR", "eqval" ], 14 | [ "has", "HASVAR" ], 15 | [ "regex", "REGEXVAR0", "regexval" ], 16 | [ "regex", "REGEXVAR1", [ "regexval10", "regexval11" ] ], 17 | [ "not", [ "eq", "NOTEQVAR", "noteqval" ] ] ], 18 | [ "exec_if_and", "%ANDVAR%" ] 19 | ], 20 | 21 | [ "if", 22 | [ "or", [ "eq", "EQVAR", "eqval" ], 23 | [ "has", "HASVAR" ], 24 | [ "regex", "REGEXVAR0", "regexval" ], 25 | [ "regex", "REGEXVAR1", [ "regexval10", "regexval11" ] ], 26 | [ "not", [ "eq", "NOTEQVAR", "noteqval" ] ] ], 27 | [ "exec_if_or", "%ORVAR%" ] 28 | ], 29 | 30 | [ "if", 31 | [ "isdir", "%ISDIRVAR%" ], 32 | [ "exec_isdir", "%ISDIRVAR%" ] 33 | ], 34 | 35 | [ "return", "foobar" ], 36 | 37 | [ "exec_non_reachable", "Arghhh" ] 38 | ] 39 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/cram/inputs/key-build.ucert: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simetnicbr/simet-ma/ec2c8fc045271fcb23d49193577b4af87652dd47/cmake-projects/jsonpath/libubox/tests/cram/inputs/key-build.ucert -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/cram/inputs/procd-instance-nlbwmon.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simetnicbr/simet-ma/ec2c8fc045271fcb23d49193577b4af87652dd47/cmake-projects/jsonpath/libubox/tests/cram/inputs/procd-instance-nlbwmon.bin -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/cram/inputs/signature.ucert: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simetnicbr/simet-ma/ec2c8fc045271fcb23d49193577b4af87652dd47/cmake-projects/jsonpath/libubox/tests/cram/inputs/signature.ucert -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/cram/test_avl.t: -------------------------------------------------------------------------------- 1 | check that avl is producing expected results: 2 | 3 | $ [ -n "$TEST_BIN_DIR" ] && export PATH="$TEST_BIN_DIR:$PATH" 4 | $ valgrind --quiet --leak-check=full test-avl 5 | test_basics: insert: 0=zero 0=one 0=two 0=three 0=four 0=five 0=six 0=seven 0=eight 0=nine 0=ten 0=eleven 0=twelve 6 | test_basics: insert duplicate: -1=zero -1=one -1=two -1=three -1=four -1=five -1=six -1=seven -1=eight -1=nine -1=ten -1=eleven -1=twelve 7 | test_basics: first=eight last=zero 8 | test_basics: for each element: eight eleven five four nine one seven six ten three twelve two zero 9 | test_basics: delete 'one' element 10 | test_basics: for each element reverse: zero two twelve three ten six seven nine four five eleven eight 11 | test_basics: delete all elements 12 | 13 | $ test-avl-san 14 | test_basics: insert: 0=zero 0=one 0=two 0=three 0=four 0=five 0=six 0=seven 0=eight 0=nine 0=ten 0=eleven 0=twelve 15 | test_basics: insert duplicate: -1=zero -1=one -1=two -1=three -1=four -1=five -1=six -1=seven -1=eight -1=nine -1=ten -1=eleven -1=twelve 16 | test_basics: first=eight last=zero 17 | test_basics: for each element: eight eleven five four nine one seven six ten three twelve two zero 18 | test_basics: delete 'one' element 19 | test_basics: for each element reverse: zero two twelve three ten six seven nine four five eleven eight 20 | test_basics: delete all elements 21 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/cram/test_base64.t: -------------------------------------------------------------------------------- 1 | set test bin path: 2 | 3 | $ [ -n "$TEST_BIN_DIR" ] && export PATH="$TEST_BIN_DIR:$PATH" 4 | 5 | check that base64 is producing expected results: 6 | 7 | $ valgrind --quiet --leak-check=full test-b64 8 | 0 9 | 4 Zg== 10 | 4 Zm8= 11 | 4 Zm9v 12 | 8 Zm9vYg== 13 | 8 Zm9vYmE= 14 | 8 Zm9vYmFy 15 | 0 16 | 1 f 17 | 2 fo 18 | 3 foo 19 | 4 foob 20 | 5 fooba 21 | 6 foobar 22 | 23 | $ test-b64-san 24 | 0 25 | 4 Zg== 26 | 4 Zm8= 27 | 4 Zm9v 28 | 8 Zm9vYg== 29 | 8 Zm9vYmE= 30 | 8 Zm9vYmFy 31 | 0 32 | 1 f 33 | 2 fo 34 | 3 foo 35 | 4 foob 36 | 5 fooba 37 | 6 foobar 38 | 39 | check that b64_encode and b64_decode assert invalid input 40 | 41 | $ alias check="grep Assertion output.log | sed 's;.*\(b64_.*code\).*\(Assertion.*$\);\1: \2;' | LC_ALL=C sort" 42 | 43 | $ test-b64_decode > output.log 2>&1; check 44 | b64_decode: Assertion `dest && targsize > 0' failed. 45 | 46 | $ test-b64_encode > output.log 2>&1; check 47 | b64_encode: Assertion `dest && targsize > 0' failed. 48 | 49 | $ test-b64_decode-san > output.log 2>&1; check 50 | b64_decode: Assertion `dest && targsize > 0' failed. 51 | 52 | $ test-b64_encode-san > output.log 2>&1; check 53 | b64_encode: Assertion `dest && targsize > 0' failed. 54 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/cram/test_blobmsg_check_array.t: -------------------------------------------------------------------------------- 1 | check that blobmsg_check_array() is producing expected results: 2 | 3 | $ [ -n "$TEST_BIN_DIR" ] && export PATH="$TEST_BIN_DIR:$PATH" 4 | 5 | $ test-blobmsg_check_array 6 | Process array_a: entry 0 7 | array_b contains string: 1 8 | blobmsg_check_array() test passed 9 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/cram/test_blobmsg_procd_instance.t: -------------------------------------------------------------------------------- 1 | check that blobmsg parsing/checking would produce expected results in procd: 2 | 3 | $ [ -n "$TEST_BIN_DIR" ] && export PATH="$TEST_BIN_DIR:$PATH" 4 | $ export INPUTS="$TESTDIR/inputs" 5 | 6 | $ for blob in $(LC_ALL=C find $INPUTS -type f | sort ); do 7 | > valgrind --quiet --leak-check=full test-blobmsg-procd-instance $blob; \ 8 | > test-blobmsg-procd-instance-san $blob; \ 9 | > done 10 | procd-instance-nlbwmon.bin: OK 11 | procd-instance-nlbwmon.bin: OK 12 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/cram/test_list.t: -------------------------------------------------------------------------------- 1 | check that list is producing expected results: 2 | 3 | $ [ -n "$TEST_BIN_DIR" ] && export PATH="$TEST_BIN_DIR:$PATH" 4 | $ valgrind --quiet --leak-check=full test-list 5 | init_list: list_empty: yes 6 | init_list: list_add_tail: zero one two three four five six seven eight nine ten eleven twelve 7 | init_list: list_empty: no 8 | test_basics: first=zero last=twelve 9 | test_basics: 'zero' is first, yes 10 | test_basics: 'twelve' is last, yes 11 | test_basics: removing 'twelve' and 'zero' 12 | test_basics: first=one last=eleven 13 | test_basics: 'one' is first, yes 14 | test_basics: 'eleven' is last, yes 15 | test_basics: moving 'one' to the tail 16 | test_basics: first=two last=one 17 | test_basics: 'two' is first, yes 18 | test_basics: 'one' is last, yes 19 | test_basics: list_for_each_entry: two three four five six seven eight nine ten eleven one 20 | test_basics: list_for_each_entry_reverse: one eleven ten nine eight seven six five four three two 21 | test_basics: delete all entries 22 | test_basics: list_empty: yes 23 | init_list: list_empty: yes 24 | init_list: list_add_tail: zero one two three four five six seven eight nine ten eleven twelve 25 | init_list: list_empty: no 26 | test_while_list_empty: delete all entries 27 | test_while_list_empty: list_empty: yes 28 | 29 | $ test-list-san 30 | init_list: list_empty: yes 31 | init_list: list_add_tail: zero one two three four five six seven eight nine ten eleven twelve 32 | init_list: list_empty: no 33 | test_basics: first=zero last=twelve 34 | test_basics: 'zero' is first, yes 35 | test_basics: 'twelve' is last, yes 36 | test_basics: removing 'twelve' and 'zero' 37 | test_basics: first=one last=eleven 38 | test_basics: 'one' is first, yes 39 | test_basics: 'eleven' is last, yes 40 | test_basics: moving 'one' to the tail 41 | test_basics: first=two last=one 42 | test_basics: 'two' is first, yes 43 | test_basics: 'one' is last, yes 44 | test_basics: list_for_each_entry: two three four five six seven eight nine ten eleven one 45 | test_basics: list_for_each_entry_reverse: one eleven ten nine eight seven six five four three two 46 | test_basics: delete all entries 47 | test_basics: list_empty: yes 48 | init_list: list_empty: yes 49 | init_list: list_add_tail: zero one two three four five six seven eight nine ten eleven twelve 50 | init_list: list_empty: no 51 | test_while_list_empty: delete all entries 52 | test_while_list_empty: list_empty: yes 53 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/cram/test_runqueue.t: -------------------------------------------------------------------------------- 1 | check that runqueue is producing expected results: 2 | 3 | $ [ -n "$TEST_BIN_DIR" ] && export PATH="$TEST_BIN_DIR:$PATH" 4 | $ valgrind --quiet --leak-check=full test-runqueue 5 | [1/1] start 'sleep 1' (killer) 6 | [1/1] killing process (killer) 7 | [0/1] finish 'sleep 1' (killer) 8 | [0/1] finish 'sleep 1' (killer) 9 | [0/1] finish 'sleep 1' (killer) 10 | [1/1] start 'sleep 1' (sleeper) 11 | [1/1] cancel 'sleep 1' (sleeper) 12 | [0/1] finish 'sleep 1' (sleeper) 13 | [1/1] start 'sleep 1' (sleeper) 14 | [1/1] cancel 'sleep 1' (sleeper) 15 | [0/1] finish 'sleep 1' (sleeper) 16 | [1/1] start 'sleep 1' (sleeper) 17 | [1/1] cancel 'sleep 1' (sleeper) 18 | [0/1] finish 'sleep 1' (sleeper) 19 | All done! 20 | 21 | $ test-runqueue-san 22 | [1/1] start 'sleep 1' (killer) 23 | [1/1] killing process (killer) 24 | [0/1] finish 'sleep 1' (killer) 25 | [0/1] finish 'sleep 1' (killer) 26 | [0/1] finish 'sleep 1' (killer) 27 | [1/1] start 'sleep 1' (sleeper) 28 | [1/1] cancel 'sleep 1' (sleeper) 29 | [0/1] finish 'sleep 1' (sleeper) 30 | [1/1] start 'sleep 1' (sleeper) 31 | [1/1] cancel 'sleep 1' (sleeper) 32 | [0/1] finish 'sleep 1' (sleeper) 33 | [1/1] start 'sleep 1' (sleeper) 34 | [1/1] cancel 'sleep 1' (sleeper) 35 | [0/1] finish 'sleep 1' (sleeper) 36 | All done! 37 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/fuzz/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FILE(GLOB test_cases "test-*.c") 2 | 3 | MACRO(ADD_FUZZER_TEST name) 4 | ADD_EXECUTABLE(${name} ${name}.c) 5 | TARGET_COMPILE_OPTIONS(${name} PRIVATE -g -O1 -fno-omit-frame-pointer -fsanitize=fuzzer,address,leak,undefined) 6 | TARGET_INCLUDE_DIRECTORIES(${name} PRIVATE ${PROJECT_SOURCE_DIR}) 7 | TARGET_LINK_OPTIONS(${name} PRIVATE -stdlib=libc++ -fsanitize=fuzzer,address,leak,undefined) 8 | TARGET_LINK_LIBRARIES(${name} ubox blobmsg_json json_script ${json}) 9 | ADD_TEST( 10 | NAME ${name} 11 | COMMAND ${name} -max_len=256 -timeout=10 -max_total_time=300 ${CMAKE_CURRENT_SOURCE_DIR}/corpus 12 | ) 13 | ENDMACRO(ADD_FUZZER_TEST) 14 | 15 | FOREACH(test_case ${test_cases}) 16 | GET_FILENAME_COMPONENT(test_case ${test_case} NAME_WE) 17 | ADD_FUZZER_TEST(${test_case}) 18 | ENDFOREACH(test_case) 19 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/fuzz/corpus/71520a5c4b5ca73903216857abbad54a8002d44a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simetnicbr/simet-ma/ec2c8fc045271fcb23d49193577b4af87652dd47/cmake-projects/jsonpath/libubox/tests/fuzz/corpus/71520a5c4b5ca73903216857abbad54a8002d44a -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/fuzz/corpus/c1dfd96eea8cc2b62785275bca38ac261256e278: -------------------------------------------------------------------------------- 1 | 6 -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/fuzz/corpus/c42ac1c46f1d4e211c735cc7dfad4ff8391110e9: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/fuzz/corpus/crash-1b8fb1be45db3aff7699100f497fb74138f3df4f: -------------------------------------------------------------------------------- 1 | 2 | A -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/fuzz/corpus/crash-333757b203a44751d3535f24b05f467183a96d09: -------------------------------------------------------------------------------- 1 | 2 | 6 -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/fuzz/corpus/crash-4c4d2c3c9ade5da9347534e290305c3b9760f627: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simetnicbr/simet-ma/ec2c8fc045271fcb23d49193577b4af87652dd47/cmake-projects/jsonpath/libubox/tests/fuzz/corpus/crash-4c4d2c3c9ade5da9347534e290305c3b9760f627 -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/fuzz/corpus/crash-5e9937b197c88bf4e7b7ee2612456cad4cb83f5b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simetnicbr/simet-ma/ec2c8fc045271fcb23d49193577b4af87652dd47/cmake-projects/jsonpath/libubox/tests/fuzz/corpus/crash-5e9937b197c88bf4e7b7ee2612456cad4cb83f5b -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/fuzz/corpus/crash-75b146c4e6fac64d3e62236b27c64b50657bab2a: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/fuzz/corpus/crash-813f3e68661da09c26d4a87dbb9d5099e92be50f: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simetnicbr/simet-ma/ec2c8fc045271fcb23d49193577b4af87652dd47/cmake-projects/jsonpath/libubox/tests/fuzz/corpus/crash-813f3e68661da09c26d4a87dbb9d5099e92be50f -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/fuzz/corpus/crash-98595faa58ba01d85ba4fd0b109cd3d490b45795: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |  -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/fuzz/corpus/crash-a3585b70f1c7ffbdec10f6dadc964336118485c4: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/fuzz/corpus/crash-b3585b70f1c7ffbdec10f6dadc964336118485c4: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/fuzz/corpus/crash-d0f3aa7d60a094b021f635d4edb7807c055a4ea1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simetnicbr/simet-ma/ec2c8fc045271fcb23d49193577b4af87652dd47/cmake-projects/jsonpath/libubox/tests/fuzz/corpus/crash-d0f3aa7d60a094b021f635d4edb7807c055a4ea1 -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/fuzz/corpus/crash-df9d1243057b27bbad6211e5a23d1cb699028aa2: -------------------------------------------------------------------------------- 1 |   -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/fuzz/corpus/crash-e0f8ecc694d96a09a1fced27b2a0838b670d34a0: -------------------------------------------------------------------------------- 1 | 5% -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/fuzz/corpus/crash-e2fd5ecb3b37926743256f1083f47a07c39e10c2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simetnicbr/simet-ma/ec2c8fc045271fcb23d49193577b4af87652dd47/cmake-projects/jsonpath/libubox/tests/fuzz/corpus/crash-e2fd5ecb3b37926743256f1083f47a07c39e10c2 -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/fuzz/corpus/valid-blobmsg.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simetnicbr/simet-ma/ec2c8fc045271fcb23d49193577b4af87652dd47/cmake-projects/jsonpath/libubox/tests/fuzz/corpus/valid-blobmsg.bin -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/shunit2/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_TEST( 2 | NAME shunit2 3 | COMMAND tests.sh 4 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 5 | ) 6 | 7 | SET_PROPERTY(TEST shunit2 APPEND PROPERTY ENVIRONMENT "TEST_JSON_SCRIPT=$") 8 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/test-avl.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "avl.h" 6 | #include "avl-cmp.h" 7 | #include "utils.h" 8 | 9 | #define OUT(fmt, ...) do { \ 10 | fprintf(stdout, "%s: " fmt, __func__, ## __VA_ARGS__); \ 11 | } while (0); 12 | 13 | struct node { 14 | struct avl_node avl; 15 | }; 16 | 17 | static void test_basics() 18 | { 19 | size_t i; 20 | struct avl_tree t; 21 | struct node *temp; 22 | struct node *elem; 23 | struct node *last; 24 | struct node *first; 25 | const char *vals[] = { 26 | "zero", "one", "two", "three", "four", "five", "six", 27 | "seven", "eight", "nine", "ten", "eleven", "twelve" 28 | }; 29 | 30 | avl_init(&t, avl_strcmp, false, NULL); 31 | 32 | OUT("insert: "); 33 | for (i=0; iavl.key = vals[i]; 36 | 37 | int r = avl_insert(&t, &n->avl); 38 | fprintf(stdout, "%d=%s ", r, (char *)n->avl.key); 39 | } 40 | fprintf(stdout, "\n"); 41 | 42 | OUT("insert duplicate: "); 43 | for (i=0; iavl.key = vals[i]; 46 | 47 | int r = avl_insert(&t, &n->avl); 48 | fprintf(stdout, "%d=%s ", r, (char *)n->avl.key); 49 | 50 | if (r) 51 | free(n); 52 | } 53 | fprintf(stdout, "\n"); 54 | 55 | first = avl_first_element(&t, first, avl); 56 | last = avl_last_element(&t, last, avl); 57 | OUT("first=%s last=%s\n", (char*)first->avl.key, (char*)last->avl.key); 58 | 59 | OUT("for each element: "); 60 | avl_for_each_element(&t, elem, avl) { 61 | fprintf(stdout, "%s ", (char*)elem->avl.key); 62 | } 63 | fprintf(stdout, "\n"); 64 | 65 | OUT("delete 'one' element\n"); 66 | elem = avl_find_element(&t, "one", elem, avl); 67 | avl_delete(&t, &elem->avl); 68 | free(elem); 69 | 70 | OUT("for each element reverse: "); 71 | avl_for_each_element_reverse(&t, elem, avl) { 72 | fprintf(stdout, "%s ", (char*)elem->avl.key); 73 | } 74 | fprintf(stdout, "\n"); 75 | 76 | OUT("delete all elements\n"); 77 | avl_for_each_element_safe(&t, elem, avl, temp) { 78 | avl_delete(&t, &elem->avl); 79 | free(elem); 80 | } 81 | } 82 | 83 | int main() 84 | { 85 | test_basics(); 86 | return 0; 87 | } 88 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/test-b64.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "utils.h" 6 | 7 | #define BUF_LEN 255 8 | 9 | static void test_b64_encode(const char *src) 10 | { 11 | char *dst = malloc(BUF_LEN+1); 12 | int r = b64_encode(src, strlen(src), dst, BUF_LEN); 13 | fprintf(stdout, "%d %s\n", r, dst); 14 | free(dst); 15 | } 16 | 17 | static void test_b64_decode(const char *src) 18 | { 19 | char *dst = malloc(BUF_LEN+1); 20 | int r = b64_decode(src, dst, BUF_LEN); 21 | fprintf(stdout, "%d %s\n", r, dst); 22 | free(dst); 23 | } 24 | 25 | int main() 26 | { 27 | test_b64_encode(""); 28 | test_b64_encode("f"); 29 | test_b64_encode("fo"); 30 | test_b64_encode("foo"); 31 | test_b64_encode("foob"); 32 | test_b64_encode("fooba"); 33 | test_b64_encode("foobar"); 34 | 35 | test_b64_decode(""); 36 | test_b64_decode("Zg=="); 37 | test_b64_decode("Zm8="); 38 | test_b64_decode("Zm9v"); 39 | test_b64_decode("Zm9vYg=="); 40 | test_b64_decode("Zm9vYmE="); 41 | test_b64_decode("Zm9vYmFy"); 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/test-b64_decode.c: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | int main() 4 | { 5 | b64_decode("Zg==", NULL, 2); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/test-b64_encode.c: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | int main() 4 | { 5 | b64_encode("foo", 3, NULL, 2); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/test-blobmsg-parse.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "blobmsg.h" 7 | 8 | enum { 9 | FOO_MESSAGE, 10 | FOO_LIST, 11 | FOO_TESTDATA, 12 | __FOO_MAX 13 | }; 14 | 15 | static const struct blobmsg_policy foo_policy[] = { 16 | [FOO_MESSAGE] = { 17 | .name = "message", 18 | .type = BLOBMSG_TYPE_STRING, 19 | }, 20 | [FOO_LIST] = { 21 | .name = "list", 22 | .type = BLOBMSG_TYPE_ARRAY, 23 | }, 24 | [FOO_TESTDATA] = { 25 | .name = "testdata", 26 | .type = BLOBMSG_TYPE_TABLE, 27 | }, 28 | }; 29 | 30 | static void dump_result(const char *fn, int r, const char *filename, struct blob_attr **tb) 31 | { 32 | fprintf(stdout, "%s: %s: %c%c%c (%d)\n", basename((char *) filename), fn, 33 | tb[FOO_MESSAGE] ? 'M' : '.', 34 | tb[FOO_LIST] ? 'L' : '.', 35 | tb[FOO_TESTDATA] ? 'T' : '.', 36 | r); 37 | } 38 | 39 | static void test_blobmsg(const char *filename) 40 | { 41 | #define BUF_LEN 256 42 | int r = 0; 43 | size_t len = 0; 44 | FILE *fd = NULL; 45 | char *buf = NULL; 46 | struct blob_attr *tb[__FOO_MAX]; 47 | 48 | fd = fopen(filename, "r"); 49 | if (!fd) { 50 | fprintf(stderr, "unable to open %s\n", filename); 51 | return; 52 | } 53 | 54 | buf = malloc(BUF_LEN+1); 55 | if (!buf) 56 | return; 57 | 58 | len = fread(buf, 1, BUF_LEN, fd); 59 | fclose(fd); 60 | 61 | r = blobmsg_parse(foo_policy, ARRAY_SIZE(foo_policy), tb, buf, len); 62 | dump_result("blobmsg_parse", r, filename, tb); 63 | 64 | r = blobmsg_parse_array(foo_policy, ARRAY_SIZE(foo_policy), tb, buf, len); 65 | dump_result("blobmsg_parse_array", r, filename, tb); 66 | 67 | free(buf); 68 | } 69 | 70 | int main(int argc, char *argv[]) 71 | { 72 | if (argc != 2) { 73 | fprintf(stderr, "Usage: %s \n", argv[0]); 74 | return 3; 75 | } 76 | 77 | test_blobmsg(argv[1]); 78 | 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/tests/test-json-script.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include "blobmsg.h" 6 | #include "blobmsg_json.h" 7 | #include "json_script.h" 8 | 9 | struct json_script_ctx jctx; 10 | struct blob_buf b_vars; 11 | struct blob_buf b_script; 12 | 13 | static void handle_command(struct json_script_ctx *ctx, const char *name, 14 | struct blob_attr *data, struct blob_attr *vars) 15 | { 16 | struct blob_attr *cur; 17 | size_t rem; 18 | 19 | fprintf(stdout, "%s", name); 20 | blobmsg_for_each_attr(cur, data, rem) 21 | fprintf(stdout, " %s", (char *) blobmsg_data(cur)); 22 | fprintf(stdout, "\n"); 23 | } 24 | 25 | static struct json_script_file * 26 | handle_file(struct json_script_ctx *ctx, const char *filename) 27 | { 28 | json_object *obj; 29 | 30 | obj = json_object_from_file(filename); 31 | if (!obj) { 32 | fprintf(stderr, "load JSON data from %s failed.\n", filename); 33 | return NULL; 34 | } 35 | 36 | blob_buf_init(&b_script, 0); 37 | blobmsg_add_json_element(&b_script, "", obj); 38 | json_object_put(obj); 39 | 40 | return json_script_file_from_blobmsg(filename, 41 | blob_data(b_script.head), blob_len(b_script.head)); 42 | } 43 | 44 | static void usage(const char *prog, int exit_code) 45 | { 46 | fprintf(stderr, "Usage: %s [VARNAME=value] \n", prog); 47 | exit(exit_code); 48 | } 49 | 50 | int main(int argc, char *argv[]) 51 | { 52 | int i; 53 | char *file = NULL; 54 | const char *prog = argv[0]; 55 | 56 | blobmsg_buf_init(&b_vars); 57 | blobmsg_buf_init(&b_script); 58 | 59 | json_script_init(&jctx); 60 | jctx.handle_command = handle_command; 61 | jctx.handle_file = handle_file; 62 | 63 | for (i = 1; i < argc; i++) { 64 | char *sep = strchr(argv[i], '='); 65 | if (sep) { 66 | *sep = '\0'; 67 | blobmsg_add_string(&b_vars, argv[i], sep + 1); 68 | } else if (!file) { 69 | file = argv[i]; 70 | } else { 71 | usage(prog, -1); 72 | } 73 | } 74 | if (i < argc || !file) 75 | usage(prog, -2); 76 | 77 | json_script_run(&jctx, file, b_vars.head); 78 | 79 | json_script_free(&jctx); 80 | blob_buf_free(&b_script); 81 | blob_buf_free(&b_vars); 82 | 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/ubox_assert.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef NDEBUG 4 | #undef NDEBUG 5 | #include 6 | #define NDEBUG 7 | #else 8 | #include 9 | #endif 10 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/ulog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ulog - simple logging functions 3 | * 4 | * Copyright (C) 2015 Jo-Philipp Wich 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef __LIBUBOX_ULOG_H 20 | #define __LIBUBOX_ULOG_H 21 | 22 | #include 23 | 24 | enum { 25 | ULOG_KMSG = (1 << 0), 26 | ULOG_SYSLOG = (1 << 1), 27 | ULOG_STDIO = (1 << 2) 28 | }; 29 | 30 | void ulog_open(int channels, int facility, const char *ident); 31 | void ulog_close(void); 32 | 33 | void ulog_threshold(int threshold); 34 | 35 | void ulog(int priority, const char *fmt, ...) 36 | __attribute__ ((format (printf, 2, 3))); 37 | 38 | #define ULOG_INFO(fmt, ...) ulog(LOG_INFO, fmt, ## __VA_ARGS__) 39 | #define ULOG_NOTE(fmt, ...) ulog(LOG_NOTICE, fmt, ## __VA_ARGS__) 40 | #define ULOG_WARN(fmt, ...) ulog(LOG_WARNING, fmt, ## __VA_ARGS__) 41 | #define ULOG_ERR(fmt, ...) ulog(LOG_ERR, fmt, ## __VA_ARGS__) 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/usock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * usock - socket helper functions 3 | * 4 | * Copyright (C) 2010 Steven Barth 5 | * Copyright (C) 2011-2012 Felix Fietkau 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | */ 19 | #ifndef USOCK_H_ 20 | #define USOCK_H_ 21 | 22 | #define USOCK_TCP 0 23 | #define USOCK_UDP 1 24 | 25 | #define USOCK_SERVER 0x0100 26 | #define USOCK_NOCLOEXEC 0x0200 27 | #define USOCK_NONBLOCK 0x0400 28 | #define USOCK_NUMERIC 0x0800 29 | #define USOCK_IPV6ONLY 0x2000 30 | #define USOCK_IPV4ONLY 0x4000 31 | #define USOCK_UNIX 0x8000 32 | 33 | const char *usock_port(int port); 34 | int usock(int type, const char *host, const char *service); 35 | int usock_inet_timeout(int type, const char *host, const char *service, 36 | void *addr, int timeout); 37 | static inline int 38 | usock_inet(int type, const char *host, const char *service, void *addr) 39 | { 40 | return usock_inet_timeout(type, host, service, addr, -1); 41 | } 42 | 43 | /** 44 | * Wait for a socket to become ready. 45 | * 46 | * This may be useful for users of USOCK_NONBLOCK to wait (with a timeout) 47 | * for a socket. 48 | * 49 | * @param fd file descriptor of socket 50 | * @param msecs timeout in microseconds 51 | */ 52 | int usock_wait_ready(int fd, int msecs); 53 | 54 | #endif /* USOCK_H_ */ 55 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/libubox/vlist.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Felix Fietkau 3 | * 4 | * Permission to use, copy, modify, and/or distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | #include "vlist.h" 17 | 18 | void 19 | vlist_init(struct vlist_tree *tree, avl_tree_comp cmp, vlist_update_cb update) 20 | { 21 | tree->update = update; 22 | tree->version = 1; 23 | 24 | avl_init(&tree->avl, cmp, 0, tree); 25 | } 26 | 27 | void 28 | vlist_delete(struct vlist_tree *tree, struct vlist_node *node) 29 | { 30 | if (!tree->no_delete) 31 | avl_delete(&tree->avl, &node->avl); 32 | tree->update(tree, NULL, node); 33 | } 34 | 35 | void 36 | vlist_add(struct vlist_tree *tree, struct vlist_node *node, const void *key) 37 | { 38 | struct vlist_node *old_node = NULL; 39 | struct avl_node *anode; 40 | 41 | node->avl.key = key; 42 | node->version = tree->version; 43 | 44 | anode = avl_find(&tree->avl, key); 45 | if (anode) { 46 | old_node = container_of(anode, struct vlist_node, avl); 47 | if (tree->keep_old || tree->no_delete) { 48 | old_node->version = tree->version; 49 | goto update_only; 50 | } 51 | 52 | avl_delete(&tree->avl, anode); 53 | } 54 | 55 | avl_insert(&tree->avl, &node->avl); 56 | 57 | update_only: 58 | tree->update(tree, node, old_node); 59 | } 60 | 61 | void 62 | vlist_flush(struct vlist_tree *tree) 63 | { 64 | struct vlist_node *node, *tmp; 65 | 66 | avl_for_each_element_safe(&tree->avl, node, avl, tmp) { 67 | if ((node->version == tree->version || node->version == -1) && 68 | tree->version != -1) 69 | continue; 70 | 71 | vlist_delete(tree, node); 72 | } 73 | } 74 | 75 | void 76 | vlist_flush_all(struct vlist_tree *tree) 77 | { 78 | tree->version = -1; 79 | vlist_flush(tree); 80 | } 81 | 82 | 83 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath/matcher.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014 Jo-Philipp Wich 3 | * 4 | * Permission to use, copy, modify, and/or distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef __MATCHER_H_ 18 | #define __MATCHER_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #ifdef JSONC 26 | #include 27 | #else 28 | #include 29 | #endif 30 | 31 | #include "ast.h" 32 | 33 | typedef void (*jp_match_cb_t)(struct json_object *res, void *priv); 34 | 35 | struct json_object * 36 | jp_match(struct jp_opcode *path, struct json_object *jsobj, 37 | jp_match_cb_t cb, void *priv); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /cmake-projects/jsonpath_changes.patch: -------------------------------------------------------------------------------- 1 | diff -ru orig.jsonpath/ast.c jsonpath/ast.c 2 | --- orig.jsonpath/ast.c 2018-10-11 11:39:16.329251656 -0300 3 | +++ jsonpath/ast.c 2018-10-10 17:12:05.795452663 -0300 4 | @@ -21,7 +21,7 @@ 5 | #include 6 | #include 7 | #include 8 | -#include 9 | +#include "libubox/utils.h" 10 | 11 | struct jp_opcode * 12 | jp_alloc_op(struct jp_state *s, int type, int num, char *str, ...) 13 | diff -ru orig.jsonpath/CMakeLists.txt jsonpath/CMakeLists.txt 14 | --- orig.jsonpath/CMakeLists.txt 2018-10-11 11:39:16.329251656 -0300 15 | +++ jsonpath/CMakeLists.txt 2018-10-11 11:37:43.100092488 -0300 16 | @@ -21,25 +21,35 @@ 17 | ENDIF() 18 | 19 | ADD_CUSTOM_COMMAND( 20 | - OUTPUT contrib/lemon 21 | - DEPENDS contrib/lemon.c contrib/lempar.c 22 | - COMMAND gcc -o contrib/lemon contrib/lemon.c 23 | + OUTPUT lemon 24 | + DEPENDS ${CMAKE_SOURCE_DIR}/contrib/lemon.c ${CMAKE_SOURCE_DIR}/contrib/lempar.c 25 | + COMMAND gcc -o lemon -I "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/contrib/lemon.c" 26 | COMMENT "Generating lemon parser generator" 27 | ) 28 | 29 | ADD_CUSTOM_COMMAND( 30 | - OUTPUT parser.c 31 | - DEPENDS parser.y contrib/lemon 32 | - COMMAND ./contrib/lemon parser.y 33 | + OUTPUT ${CMAKE_SOURCE_DIR}/parser.c 34 | + DEPENDS ${CMAKE_SOURCE_DIR}/parser.y lemon 35 | + COMMAND cd "${CMAKE_SOURCE_DIR}" && ${CMAKE_BINARY_DIR}/lemon -T${CMAKE_SOURCE_DIR}/contrib/lempar.c parser.y 36 | COMMENT "Generating parser.c" 37 | ) 38 | 39 | FIND_PATH(ubox_include_dir libubox/list.h) 40 | -INCLUDE_DIRECTORIES(${ubox_include_dir}) 41 | +IF(ubox_include_dir MATCHES "NOTFOUND$") 42 | + ADD_SUBDIRECTORY(libubox) 43 | + INCLUDE_DIRECTORIES(libubox) 44 | +ELSE() 45 | + INCLUDE_DIRECTORIES(${ubox_include_dir}) 46 | +ENDIF() 47 | 48 | SET_PROPERTY(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "lemon;parser.h;parser.out") 49 | SET_SOURCE_FILES_PROPERTIES("parser.c" PROPERTIES GENERATED TRUE) 50 | + 51 | +SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a") 52 | +SET(BUILD_SHARED_LIBS OFF) 53 | +SET(CMAKE_EXE_LINKER_FLAGS "-static") 54 | + 55 | ADD_EXECUTABLE(jsonpath main.c ast.c lexer.c parser.c matcher.c) 56 | -TARGET_LINK_LIBRARIES(jsonpath ubox ${json}) 57 | +TARGET_LINK_LIBRARIES(jsonpath ubox-static ${json}) 58 | 59 | INSTALL(TARGETS jsonpath RUNTIME DESTINATION bin) 60 | diff -ru orig.jsonpath/main.c jsonpath/main.c 61 | --- orig.jsonpath/main.c 2018-10-11 11:39:16.333251706 -0300 62 | +++ jsonpath/main.c 2018-10-10 17:12:05.807452815 -0300 63 | @@ -26,7 +26,7 @@ 64 | #include 65 | #endif 66 | 67 | -#include 68 | +#include "libubox/list.h" 69 | 70 | #include "lexer.h" 71 | #include "parser.h" 72 | -------------------------------------------------------------------------------- /debian/.gitignore: -------------------------------------------------------------------------------- 1 | simet-ma/ 2 | tmp/ 3 | files 4 | *.debhelper 5 | *.debhelper.log 6 | simet-ma.substvars 7 | etc.apt.sources.list.d/*.list 8 | -------------------------------------------------------------------------------- /debian/br.nic.simet.simet-ma-reports.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Type=Application 3 | Name=SIMET Reports 4 | Name[pt]=Relatórios SIMET 5 | GenericName=Internet connection quality report 6 | GenericName[pt]=Relatório de qualidade da conexão à Internet 7 | Comment=Opens a web page with SIMET reports for this system 8 | Comment[pt]=Abre uma página web com relatórios SIMET para esse sistema 9 | Path=/opt/simet 10 | TryExec=/opt/simet/bin/simet_view_results.sh 11 | Exec=/opt/simet/bin/simet_view_results.sh 12 | Icon=simetnicbr 13 | Terminal=false 14 | Categories=Application;Network;Monitor; 15 | Keywords=network;measurement;IP;Internet; 16 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: simet-ma 2 | Section: net 3 | Priority: optional 4 | Maintainer: NIC.br SIMET Team 5 | Build-Depends: debhelper (>= 9), cmake, pkg-config, automake, libjson-c-dev, libcurl4-gnutls-dev | libcurl-dev, lsb-release 6 | Standards-Version: 4.1.0 7 | Homepage: https://simet.nic.br/projetos/ 8 | Vcs-Browser: https://github.com/simetnicbr/simet-ma 9 | Vcs-Git: https://github.com/simetnicbr/simet-ma.git 10 | 11 | Package: simet-ma 12 | Architecture: any 13 | Pre-Depends: ${misc:Pre-Depends} 14 | Depends: ${shlibs:Depends}, ${misc:Depends}, adduser, lsb-release, curl, cron | cron-daemon, gawk | mawk, simet-lmapd (>= 0.15.6~), lsb-base, libcap2-bin 15 | Recommends: apt-utils, unattended-upgrades, apt-transport-https, iproute2, iw, fping, iputils-ping, traceroute (>= 1:2.0), dnsutils | ldnsutils 16 | Suggests: xdg-utils | sensible-utils, qrencode 17 | Breaks: sysvinit (<< 2.88dsf-52~) 18 | Description: NIC.br SIMET Measurement Agent 19 | This is the Measurement Agent for the SIMET system from NIC.br. It 20 | performs several measurements of the Internet connectivity against 21 | SIMET measurement peers hosted at the IX.br Internet Exchanges as well 22 | as in NIC.br datacenters, and reports the measurement results to the 23 | SIMET central servers. 24 | . 25 | The user can access the measurement results through a web interface. 26 | The ISPs can access anonymized measurements done on their networks 27 | through a separate interface. 28 | . 29 | The collected data is used in an aggregated, anonymized format by 30 | CETIC.br to produce statistics on Internet connectivity [in Brazil], 31 | and also to generate reports of any relevant issues affecting a large 32 | number of Brazillian users to CGI.br - Brazil's Internet Steering 33 | Committee. 34 | -------------------------------------------------------------------------------- /debian/dhclient-exit-hook/simet-ma: -------------------------------------------------------------------------------- 1 | # SIMET-MA dhclient exit hook 2 | # Copytight (c) 2023 NIC.br 3 | # 4 | # Distributed under the GPLv3+ license with additional terms and permissions 5 | # Refer to the COPYING file on the program source for details 6 | 7 | simetma_interfaceup() 8 | ( 9 | # Note: runs in subshell 10 | 11 | test -x /opt/simet/bin/simet_register_ma.sh || return 0 12 | 13 | start-stop-daemon -b -c nicbr-simet --start --name simet_reg_ma \ 14 | --startas /opt/simet/bin/simet_register_ma.sh \ 15 | -- --boot >/dev/null &1 || : 16 | 17 | invoke-rc.d simet-ma start >/dev/null 2>&1 || : 18 | ) 19 | 20 | case "$reason" in 21 | BOUND|RENEW|REBIND|REBOOT) 22 | simetma_interfaceup || : 23 | ;; 24 | EXPIRE|FAIL|RELEASE|STOP) 25 | : 26 | ;; 27 | esac 28 | 29 | -------------------------------------------------------------------------------- /debian/dhcpcd-hook/90-simet-ma.conf: -------------------------------------------------------------------------------- 1 | # SIMET-MA dhcpcd dispatcher script 2 | # Copytight (c) 2024 NIC.br 3 | # 4 | # Distributed under the GPLv3+ license with additional terms and permissions 5 | # Refer to the COPYING file on the program source for details 6 | 7 | simetma_interfaceup() 8 | ( 9 | # Note: runs in subshell 10 | 11 | export LC_ALL=C 12 | start-stop-daemon -b -c nicbr-simet --start --name simet_reg_ma \ 13 | --startas /opt/simet/bin/simet_register_ma.sh \ 14 | -- --boot >/dev/null &1 || : 15 | 16 | invoke-rc.d simet-ma start >/dev/null 2>&1 || : 17 | ) 18 | 19 | if [ -x /opt/simet/bin/simet_register_ma.sh ] && $if_up ; then 20 | simetma_interfaceup || : 21 | fi 22 | 23 | # vi: ft=sh 24 | -------------------------------------------------------------------------------- /debian/etc.apt.conf.d/55nicbr-unattended-upgrades: -------------------------------------------------------------------------------- 1 | # Allow unattended upgrades of any already-installed NIC.br software 2 | Unattended-Upgrade::Allowed-Origins { 3 | "NIC.br:*"; 4 | }; 5 | -------------------------------------------------------------------------------- /debian/etc.apt.sources.list.d/simet.apt.source.template: -------------------------------------------------------------------------------- 1 | # NIC.br SIMET Measurement Agent 2 | deb [ signed-by=/etc/apt/nicbr-simet.apt.key.gpg pdiffs=no ] http://download.simet.nic.br/medidores/simet-ma/linux/apt/@distro@ @codename@ main 3 | -------------------------------------------------------------------------------- /debian/etc.apt/nicbr-simet.apt.key.gpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simetnicbr/simet-ma/ec2c8fc045271fcb23d49193577b4af87652dd47/debian/etc.apt/nicbr-simet.apt.key.gpg -------------------------------------------------------------------------------- /debian/networkd-dispatcher.routable/50simet-ma: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # SIMET-MA systemd-networkd dispatcher script, routable.d 3 | # Copytight (c) 2023 NIC.br 4 | # 5 | # Distributed under the GPLv3+ license with additional terms and permissions 6 | # Refer to the COPYING file on the program source for details 7 | 8 | export LC_ALL=C 9 | 10 | [ "$IFACE" = "lo" ] && exit 0 11 | test -x /opt/simet/bin/simet_register_ma.sh || exit 0 12 | 13 | start-stop-daemon -b -c nicbr-simet --start --name simet_reg_ma \ 14 | --startas /opt/simet/bin/simet_register_ma.sh \ 15 | -- --boot >/dev/null &1 || : 16 | 17 | invoke-rc.d simet-ma start >/dev/null 2>&1 || : 18 | : 19 | -------------------------------------------------------------------------------- /debian/networkmanager-dispatcher/50simet-ma: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # SIMET-MA NetworkManager dispatcher script 3 | # Copytight (c) 2023 NIC.br 4 | # 5 | # Distributed under the GPLv3+ license with additional terms and permissions 6 | # Refer to the COPYING file on the program source for details 7 | 8 | export LC_ALL=C 9 | test -x /opt/simet/bin/simet_register_ma.sh || exit 0 10 | 11 | [ "$2" = "connectivity-change" ] && [ "$CONNECTIVITY_STATE" = "FULL" ] || exit 0 12 | 13 | start-stop-daemon -b -c nicbr-simet --start --name simet_reg_ma \ 14 | --startas /opt/simet/bin/simet_register_ma.sh \ 15 | -- --boot >/dev/null &1 || : 16 | 17 | invoke-rc.d simet-ma start >/dev/null 2>&1 || : 18 | : 19 | -------------------------------------------------------------------------------- /debian/simet-ma.cron.daily: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # simet-ma.cron.daily - daily maintenance for the SIMET Measurement Agent 3 | # Copyright (c) 2018,2019 NIC.br 4 | # 5 | # Distributed under the GPLv3+ license with additional terms and permissions 6 | # Refer to the COPYING file on the program source for details 7 | 8 | # Refresh agent registry in case it has to change auth tokens 9 | test -f /opt/simet/bin/simet_register_ma.sh && { 10 | # Random sleep (limited to 300 seconds) 11 | # 12 | # This is required to break group sync behavior caused 13 | # by the fixed-local-time running of cron.daily in many distros. 14 | # 15 | # DO NOT REMOVE THIS DEFENSE, WE ARE VERY SERIOUS ABOUT THIS 16 | 17 | # shellcheck disable=SC3028 18 | SLTIME="$RANDOM" 19 | [ "$SLTIME" -ge 0 ] 2>/dev/null \ 20 | || SLTIME=$(( $(dd if=/dev/urandom bs=4 count=1 2> /dev/null | cksum | cut -d ' ' -f 1) % 4096 )) || : 21 | [ "$SLTIME" -ge 0 ] 2>/dev/null || SLTIME=$$ 22 | sleep $((SLTIME % 300 + 1)) || : 23 | 24 | start-stop-daemon -c nicbr-simet --start --name simet_reg_ma \ 25 | --startas /opt/simet/bin/simet_register_ma.sh \ 26 | -- --daily >/dev/null 2>&1 || true 27 | 28 | # Attempt to contact the controller if the main schedule is too old 29 | # shellcheck disable=SC2015 30 | [ -x /opt/simet/bin/simet_lmap-fetch-schedule.sh ] \ 31 | && [ -n "$(find /var/run/lmapd/lmap-schedule.json -maxdepth 0 -type f -mtime +1 2>/dev/null)" ] \ 32 | && start-stop-daemon -c nicbr-simet --start --name simetgetsched \ 33 | --startas /opt/simet/bin/simet_lmap-fetch-schedule.sh || true 34 | } 35 | : 36 | -------------------------------------------------------------------------------- /debian/simet-ma.cron.weekly: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # simet-ma.cron.weekly - weekly maintenance for the SIMET Measurement Agent 3 | # Copyright (c) 2018-2023 NIC.br 4 | # 5 | # Distributed under the GPLv3+ license with additional terms and permissions 6 | # Refer to the COPYING file on the program source for details 7 | 8 | SIMET_PACKAGES="$(dpkg-query --showformat '${Package}\t${db:Status-Abbrev}\n' --show 'simet*' | sed -n -e '/[\t]i/ { s/\t.*// ; p }')" || SIMET_PACKAGES= 9 | [ -z "$SIMET_PACKAGES" ] && SIMET_PACKAGES="simet-ma simet-lmapd" 10 | 11 | # Attempt to auto-update regardless of unattended-updates, otherwise we end up 12 | # with installs running very outdated software (well over an year old). We 13 | # do restrict ourselves to just the core SIMET packages, and any dependencies 14 | # that have versioned requirements. 15 | test -f /opt/simet/bin/simet_register_ma.sh && { 16 | # Random sleep (limited to 300 seconds) 17 | # 18 | # This is required to break group sync behavior caused 19 | # by the fixed-local-time running of cron.daily in many distros. 20 | 21 | # shellcheck disable=SC3028 22 | SLTIME="$RANDOM" 23 | [ "$SLTIME" -ge 0 ] 2>/dev/null \ 24 | || SLTIME=$(( $(dd if=/dev/urandom bs=4 count=1 2> /dev/null | cksum | cut -d ' ' -f 1) % 4096 )) || : 25 | [ "$SLTIME" -ge 0 ] 2>/dev/null || SLTIME=$$ 26 | sleep $((SLTIME % 300 + 1)) || : 27 | 28 | # update package lists 29 | apt-get update -qq || true 30 | # self-heal anything can be self-healed by apt 31 | DEBIAN_FRONTEND=noninteractive apt-get -f install --reinstall -qq -y || true 32 | # shellcheck disable=SC2086 33 | UCF_FORCE_CONFFNEW=1 DEBIAN_FRONTEND=noninteractive \ 34 | apt-get install -qq --install-recommends -y \ 35 | -o Dpkg::Options::=--force-confmiss -o Dpkg::Options::=--force-confnew \ 36 | $SIMET_PACKAGES 37 | } 38 | : 39 | -------------------------------------------------------------------------------- /debian/simet-ma.if-up: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # SIMET-MA ifupdown dispatcher script, if-up 3 | # Copytight (c) 2023 NIC.br 4 | # 5 | # Distributed under the GPLv3+ license with additional terms and permissions 6 | # Refer to the COPYING file on the program source for details 7 | 8 | export LC_ALL=C 9 | [ "$IFACE" = "lo" ] && exit 0 10 | [ "$IFACE" = "--all" ] && exit 0 11 | [ "$METHOD" = "NetworkManager" ] && exit 0 12 | 13 | test -x /opt/simet/bin/simet_register_ma.sh || exit 0 14 | 15 | ( 16 | sleep 10 17 | start-stop-daemon -b -c nicbr-simet --start --name simet_reg_ma \ 18 | --startas /opt/simet/bin/simet_register_ma.sh \ 19 | -- --boot || : 20 | invoke-rc.d simet-ma start || : 21 | ) /dev/null 2>&1 & 22 | : 23 | -------------------------------------------------------------------------------- /debian/simet-ma.install: -------------------------------------------------------------------------------- 1 | debian/etc.apt/* etc/apt/ 2 | debian/etc.apt.conf.d/* etc/apt/apt.conf.d/ 3 | debian/etc.apt.sources.list.d/*list etc/apt/sources.list.d/ 4 | debian/*.desktop usr/share/applications/ 5 | debian/simetnicbr.svg /usr/share/icons/hicolor/scalable/apps/ 6 | debian/networkd-dispatcher.routable/* /usr/lib/networkd-dispatcher/routable.d/ 7 | debian/networkmanager-dispatcher/* /etc/NetworkManager/dispatcher.d/ 8 | debian/dhclient-exit-hook/simet-ma /etc/dhcp/dhclient-exit-hooks.d/ 9 | debian/dhcpcd-hook/* /lib/dhcpcd/dhcpcd-hooks/ 10 | opt/ 11 | -------------------------------------------------------------------------------- /debian/simet-ma.lintian-overrides: -------------------------------------------------------------------------------- 1 | # We are an add-on vendor package that uses /opt/simet 2 | simet-ma: dir-or-file-in-opt 3 | simet-ma: unusual-interpreter 4 | simet-ma: copyright-should-refer-to-common-license-file-for-gpl 5 | simet-ma: package-installs-apt-sources 6 | -------------------------------------------------------------------------------- /debian/simet-ma.postrm: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # postrm script for simet-ma 3 | # 4 | # see: dh_installdeb(1) 5 | 6 | set -e 7 | 8 | # summary of how this script can be called: 9 | # * `remove' 10 | # * `purge' 11 | # * `upgrade' 12 | # * `failed-upgrade' 13 | # * `abort-install' 14 | # * `abort-install' 15 | # * `abort-upgrade' 16 | # * `disappear' 17 | # 18 | # for details, see https://www.debian.org/doc/debian-policy/ or 19 | # the debian-policy package 20 | 21 | 22 | case "$1" in 23 | purge) 24 | deluser --quiet --system nicbr-simet >/dev/null || true 25 | deluser --quiet --system --group nicbr-simet >/dev/null || true 26 | # conffiles will be removed by dpkg. But not autogenerated config files 27 | rm -f /etc/cron.d/simet-ma 28 | rm -fr /var/run/lmapd/ /var/spool/lmapd/ /opt/simet/etc /var/run/simet/ /var/run/simet_public 29 | ;; 30 | remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) 31 | ;; 32 | 33 | *) 34 | echo "postrm called with unknown argument \`$1'" >&2 35 | exit 1 36 | ;; 37 | esac 38 | 39 | # dh_installdeb will replace this with shell code automatically 40 | # generated by other debhelper scripts. 41 | 42 | #DEBHELPER# 43 | 44 | exit 0 45 | -------------------------------------------------------------------------------- /debian/simet-ma.ppp.ip-up: -------------------------------------------------------------------------------- 1 | simet-ma.if-up -------------------------------------------------------------------------------- /debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (native) 2 | -------------------------------------------------------------------------------- /debian/source/lintian-overrides: -------------------------------------------------------------------------------- 1 | ../simet-ma.lintian-overrides -------------------------------------------------------------------------------- /docker/policy-rc.d: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | [ "$1" = "simet-ma" ] && exit 0 3 | [ "$1" = "simet-lmapd" ] && exit 0 4 | exit 101 5 | -------------------------------------------------------------------------------- /docker/rsyslog.conf: -------------------------------------------------------------------------------- 1 | # /etc/rsyslog.conf configuration file for rsyslog 2 | # 3 | # For more information install rsyslog-doc and see 4 | # /usr/share/doc/rsyslog-doc/html/configuration/index.html 5 | 6 | 7 | ################# 8 | #### MODULES #### 9 | ################# 10 | 11 | module(load="imuxsock") # provides support for local system logging 12 | #module(load="imklog") # provides kernel logging support 13 | #module(load="immark") # provides --MARK-- message capability 14 | 15 | # provides UDP syslog reception 16 | #module(load="imudp") 17 | #input(type="imudp" port="514") 18 | 19 | # provides TCP syslog reception 20 | #module(load="imtcp") 21 | #input(type="imtcp" port="514") 22 | 23 | 24 | ########################### 25 | #### GLOBAL DIRECTIVES #### 26 | ########################### 27 | 28 | template(name="SIMET_NoTsFileFormat" type="list") { 29 | property(name="syslogtag") 30 | property(name="msg" spifno1stsp="on") 31 | property(name="msg" droplastlf="on") 32 | constant(value="\n") 33 | } 34 | $ActionFileDefaultTemplate SIMET_NoTsFileFormat 35 | 36 | # 37 | # Set the default permissions for all log files. 38 | # 39 | $FileOwner root 40 | $FileGroup adm 41 | $FileCreateMode 0640 42 | $DirCreateMode 0755 43 | $Umask 0022 44 | 45 | # 46 | # Where to place spool and state files 47 | # 48 | $WorkDirectory /var/spool/rsyslog 49 | 50 | # 51 | # Include all config files in /etc/rsyslog.d/ 52 | # 53 | $IncludeConfig /etc/rsyslog.d/*.conf 54 | 55 | 56 | ############### 57 | #### RULES #### 58 | ############### 59 | 60 | # Docker: try the stdout/stderr of PID 1 61 | *.=info;*.=notice;auth,authpriv.none -/proc/1/fd/1 62 | *.warning;auth,authpriv.none -/proc/1/fd/2 63 | -------------------------------------------------------------------------------- /docs/developer-notes.txt: -------------------------------------------------------------------------------- 1 | Developer notes: 2 | 3 | SIMETBOX is an OpenWRT-based measurement system for home routers and such 4 | "big" embedded devices. 5 | 6 | Files with "simetbox" in the name are SIMETBOX-specific, they usually have 7 | a "simet" counterpart that is generic. 8 | 9 | For a SIMETBOX build, you would typically want this: 10 | --enable-simetbox --prefix=/usr --sysconfdir=/etc --localstatedir=/var 11 | (and OpenWRT will already set everything but --enable-simetbox for you) 12 | 13 | For a Linux build, watch out for localstatedir, we do -NOT- create 14 | ${localstatedir}/lock except in the simet_register_ma.sh script, and this 15 | can become a problem if you also give --prefix to configure and would need 16 | ${prefix}/var to be created. 17 | 18 | An example of the correct usage is: 19 | --prefix=/opt/simet --localstatedir=/var 20 | 21 | Linux builds will use an embedded copy of OpenWRT's jsonpath/jsonfilter 22 | and libubox. SIMETBOX builds will use the system copy of jsonfilter, 23 | which must be in the system path. 24 | 25 | 26 | Conventions: 27 | 28 | Look into simet-api/Makefile.am for conventions for scripts and config files. 29 | 30 | Configuration (after install): 31 | * Hardcoded defaults go into $LIBDIR/simet/*conf 32 | * These defaults can be user-overridden through 33 | $SYSCONFDIR/simet/.conf 34 | 35 | Versioning: 36 | The main version is set by the top level "version" file. If working from 37 | a git checkout, it will be based on "git describe" instead (see version.sh). 38 | 39 | Please always commit an up-to-date version file and then tag the new release: 40 | 41 | echo "v1.2.3" > version ; git add version ; git commit -m "version: update" ; git tag -m "simet-ma version $(cat version)" $(cat version) 42 | -------------------------------------------------------------------------------- /docs/task_module_api.txt: -------------------------------------------------------------------------------- 1 | SIMET2 - task/module API 2 | Copyright (c) 2018,2019 NIC.br 3 | 4 | This program is free software: you can redistribute it and/or modify it 5 | under the terms of the GNU General Public License as published by the Free 6 | Software Foundation, either version 3 of the License, or (at your option) 7 | any later version. In every case, additional restrictions and permissions 8 | apply, refer to the COPYING file in the program Source for details. 9 | 10 | This program is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 12 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | and the COPYING file in the program Source for details. 14 | 15 | 16 | Pre-lmapd API: 17 | -------------- 18 | 19 | This is what is currently implemented. 20 | 21 | 22 | stdin: JSON, task-specific. Data from previous pipeline (currently unused) 23 | 24 | stdout: JSON, lmap report format. Contents for the "table" list, without [ ] 25 | the task can output zero or more complete tables. 26 | 27 | stderr: user/debug output, free-form 28 | 29 | exit status: refer to docs/task_exit_status.h 30 | 31 | The task executable is called by the simet-runner script, with hardcoded 32 | parameters. All interaction with generic SIMET2 system are done by 33 | simet-runner itself, as is the LMAP report generation based on the task 34 | output, and grouping. Scheduling done by the system cron daemon. 35 | 36 | CLI: task executables should support: 37 | 38 | -V output name and version, separated by space on first line 39 | copyright and license on following lines 40 | (long: --version) 41 | -q quiet human output, only startup and errors to stderr 42 | -v verbose (twice for debug, tree times for tracing) 43 | -h usage and help (long: --help) 44 | 45 | 46 | lmapd-based API: 47 | ---------------- 48 | 49 | In the planning stage. High priority. 50 | 51 | stdin: , some structured input channel 52 | stdout: , the CSV used by current lmapd does not meet multi-output spec. 53 | stderr: user/debug output, free-form (human-centric output cleanups and common 54 | format is planned for later) 55 | 56 | exit status: refer to docs/task_exit_status.h 57 | 58 | -------------------------------------------------------------------------------- /inetup-client-c/.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | Makefile.in 3 | aclocal.m4 4 | autom4te.cache/ 5 | compile 6 | config.guess 7 | config.log 8 | config.status 9 | config.sub 10 | configure 11 | depcomp 12 | install-sh 13 | missing 14 | src/.deps/ 15 | src/Makefile 16 | src/Makefile.in 17 | stamp-h1 18 | simet-inetuptime_config.h 19 | simet-inetuptime_config.h.in 20 | version 21 | err.log 22 | src/*.o 23 | src/inetupc 24 | -------------------------------------------------------------------------------- /inetup-client-c/AUTHORS: -------------------------------------------------------------------------------- 1 | Main authors: 2 | NIC.br - Núcleo de Informação e Coordenação do Ponto BR 3 | * Fábio Nokai 4 | * Henrique de Moraes Holschuh 5 | * Holger Wiehen 6 | -------------------------------------------------------------------------------- /inetup-client-c/ChangeLog: -------------------------------------------------------------------------------- 1 | * Nothing yet 2 | -------------------------------------------------------------------------------- /inetup-client-c/Makefile.am: -------------------------------------------------------------------------------- 1 | ## 2 | ## Makefile.am for inetupc - SIMET2 MA Internet network availability (client) 3 | ## Copyright (c) 2018,2019 NIC.br 4 | ## 5 | ## This program is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. In every case, additional 9 | ## restrictions and permissions apply, refer to the COPYING file in the 10 | ## program Source for details. 11 | ## 12 | ## This program is distributed in the hope that it will be useful, but 13 | ## WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | ## General Public License and the COPYING file in the program Source 16 | ## for details. 17 | 18 | SUBDIRS = src 19 | 20 | EXTRA_DIST = autogen.sh version version.sh 21 | 22 | dist-local: version 23 | 24 | version: $(top_srcdir)/version.sh 25 | $(top_srcdir)/version.sh > version 26 | -------------------------------------------------------------------------------- /inetup-client-c/NEWS: -------------------------------------------------------------------------------- 1 | No news is good news 2 | -------------------------------------------------------------------------------- /inetup-client-c/README: -------------------------------------------------------------------------------- 1 | Source code structure: 2 | 3 |
4 | m4/ - autotools macros 5 | src/ - module 6 | -------------------------------------------------------------------------------- /inetup-client-c/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (c) 2018,2019 NIC.br 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. In every case, additional 8 | # restrictions and permissions apply, refer to the COPYING file in the 9 | # program Source for details. 10 | # 11 | # This program is distributed in the hope that it will be useful, but 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License and the COPYING file in the program Source 15 | # for details. 16 | 17 | ./version.sh >/dev/null 2>&1 || { 18 | echo "$0: missing version file and not in a worktree" >&2 19 | exit 1 20 | } 21 | autoreconf -i 22 | -------------------------------------------------------------------------------- /inetup-client-c/m4/ax_require_defined.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_require_defined.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_REQUIRE_DEFINED(MACRO) 8 | # 9 | # DESCRIPTION 10 | # 11 | # AX_REQUIRE_DEFINED is a simple helper for making sure other macros have 12 | # been defined and thus are available for use. This avoids random issues 13 | # where a macro isn't expanded. Instead the configure script emits a 14 | # non-fatal: 15 | # 16 | # ./configure: line 1673: AX_CFLAGS_WARN_ALL: command not found 17 | # 18 | # It's like AC_REQUIRE except it doesn't expand the required macro. 19 | # 20 | # Here's an example: 21 | # 22 | # AX_REQUIRE_DEFINED([AX_CHECK_LINK_FLAG]) 23 | # 24 | # LICENSE 25 | # 26 | # Copyright (c) 2014 Mike Frysinger 27 | # 28 | # Copying and distribution of this file, with or without modification, are 29 | # permitted in any medium without royalty provided the copyright notice 30 | # and this notice are preserved. This file is offered as-is, without any 31 | # warranty. 32 | 33 | #serial 1 34 | 35 | AC_DEFUN([AX_REQUIRE_DEFINED], [dnl 36 | m4_ifndef([$1], [m4_fatal([macro ]$1[ is not defined; is a m4 file missing?])]) 37 | ])dnl AX_REQUIRE_DEFINED 38 | -------------------------------------------------------------------------------- /inetup-client-c/src/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Copyright (c) 2018,2019 NIC.br 2 | ## 3 | ## This program is free software: you can redistribute it and/or modify 4 | ## it under the terms of the GNU General Public License as published by 5 | ## the Free Software Foundation, either version 3 of the License, or 6 | ## (at your option) any later version. In every case, additional 7 | ## restrictions and permissions apply, refer to the COPYING file in the 8 | ## program Source for details. 9 | ## 10 | ## This program is distributed in the hope that it will be useful, but 11 | ## WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | ## General Public License and the COPYING file in the program Source 14 | ## for details. 15 | 16 | bin_PROGRAMS = inetupc 17 | 18 | inetupc_SOURCES = ../simet-inetuptime_config.h simet_err.h \ 19 | logger.h netinet-tcp-compat.h retry.h \ 20 | sys-linux.h sys-linux.c \ 21 | tcpaq.h tcpaq.c \ 22 | simet-inetuptime.h simet-inetuptime.c 23 | 24 | inetupc_LDADD = ${JSON_LIBS} 25 | -------------------------------------------------------------------------------- /inetup-client-c/src/logger.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018,2019 NIC.br 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. In every case, additional 8 | * restrictions and permissions apply, refer to the COPYING file in the 9 | * program Source for details. 10 | * 11 | * This program is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License and the COPYING file in the program Source 15 | * for details. 16 | */ 17 | 18 | #ifndef LOGGER_H_ 19 | #define LOGGER_H_ 20 | 21 | #include 22 | 23 | extern int log_level; /* 0: errors; 1: quiet; 2: normal; 3: debug/verbose ; 4: trace */ 24 | extern const char *progname; 25 | 26 | #define MSG_ALWAYS 0 27 | #define MSG_IMPORTANT 1 28 | #define MSG_NORMAL 2 29 | #define MSG_DEBUG 3 30 | #define MSG_TRACE 4 31 | 32 | #define print_msg_u(format, arg...) \ 33 | do { fflush(stdout); fprintf(stderr, "%s: " format "\n", progname, ## arg); } while (0) 34 | 35 | #define print_msg(level, format, arg...) \ 36 | do { \ 37 | if (log_level >= (level)) { \ 38 | fflush(stdout); \ 39 | fprintf(stderr, "%s: " format "\n", progname, ## arg); \ 40 | } \ 41 | } while (0) 42 | 43 | #define print_err(format, arg...) \ 44 | do { fflush(stdout); fprintf(stderr, "%s: error: " format "\n", progname, ## arg); } while (0) 45 | 46 | #define print_warn(format, arg...) \ 47 | do { fflush(stdout); fprintf(stderr, "%s: warning: " format "\n", progname, ## arg); } while (0) 48 | 49 | #endif /* LOGGER_H_ */ 50 | -------------------------------------------------------------------------------- /inetup-client-c/src/netinet-tcp-compat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018,2019 NIC.br 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. In every case, additional 8 | * restrictions and permissions apply, refer to the COPYING file in the 9 | * program Source for details. 10 | * 11 | * This program is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License and the COPYING file in the program Source 15 | * for details. 16 | */ 17 | 18 | #ifndef NETINET_TCP_COMPAT_H 19 | #define NETINET_TCP_COMPAT_H 20 | 21 | #include 22 | 23 | #ifdef __linux__ 24 | /* 25 | * Missing socket options in OpenWRT CC uClibc 26 | * (OpenWRT CC uses Linux kernel 3.18.109) 27 | */ 28 | 29 | /* tcp-thin supported since Linux 2.6.34 */ 30 | #ifndef TCP_THIN_LINEAR_TIMEOUTS 31 | #define TCP_THIN_LINEAR_TIMEOUTS 16 32 | #endif 33 | #ifndef TCP_THIN_DUPACK 34 | #define TCP_THIN_DUPACK 17 35 | #endif 36 | 37 | /* TCP user timeouts supported since Linux 2.6.37 */ 38 | #ifndef TCP_USER_TIMEOUT 39 | #define TCP_USER_TIMEOUT 18 40 | #endif 41 | 42 | #endif /* __linux__ */ 43 | #endif /* NETINET_TCP_COMPAT_H */ 44 | -------------------------------------------------------------------------------- /inetup-client-c/src/retry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Retry macros for EINTR, EAGAIN, EWOULDBLOCK 3 | * Copyright (c) 2024 NIC.br 4 | * 5 | * SPDX-License-Identifier: BSD-3-CLAUSE 6 | */ 7 | 8 | #ifndef SRETRY_H_ 9 | #define SRETRY_H_ 10 | 11 | #include 12 | 13 | #define MAXIMUM_SYSCALL_RETRIES 50 14 | #define MAXIMUM_GAI_RETRIES 5 15 | 16 | #define RETRY_EINTR(x) ({ \ 17 | typeof(x) _r; \ 18 | char _tries = MAXIMUM_SYSCALL_RETRIES; \ 19 | do { \ 20 | _r = (x); \ 21 | } while (_r == -1 && errno == EINTR && (--_tries) > 0); \ 22 | _r; \ 23 | }) 24 | 25 | #define RETRY_GAI(x) ({ \ 26 | char _tries = MAXIMUM_GAI_RETRIES; \ 27 | int _r; \ 28 | do { \ 29 | _r = (x); \ 30 | } while (( (_r == EAI_SYSTEM && errno == EINTR) || (_r == EAI_AGAIN)) \ 31 | && (--_tries) > 0); \ 32 | _r; \ 33 | }) 34 | 35 | #endif /* SRETRY_H_ */ 36 | /* vim: set et ts=8 sw=4 : */ 37 | -------------------------------------------------------------------------------- /inetup-client-c/src/tcpaq.h: -------------------------------------------------------------------------------- 1 | /* 2 | * tcp-aq: tcp async queueing layer 3 | * Copyright (c) 2018-2024 NIC.br 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. In every case, additional 9 | * restrictions and permissions apply, refer to the COPYING file in the 10 | * program Source for details. 11 | * 12 | * This program is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * General Public License and the COPYING file in the program Source 16 | * for details. 17 | */ 18 | 19 | #ifndef SIMET_TCPAQ_H 20 | #define SIMET_TCPAQ_H 21 | 22 | #include 23 | 24 | #define SIMET_TCPAQ_QUEUESIZE 8192U 25 | struct tcpaq_queue { 26 | char *buffer; 27 | size_t buffer_size; 28 | size_t rd_pos; 29 | size_t wr_pos_reserved; 30 | size_t wr_pos; 31 | }; 32 | 33 | struct tcpaq_conn { 34 | struct tcpaq_queue in_queue; 35 | struct tcpaq_queue out_queue; 36 | 37 | sa_family_t ai_family; 38 | int socket; 39 | }; 40 | 41 | int tcpaq_init(struct tcpaq_conn * const s, size_t qsize); 42 | void tcpaq_free_members(struct tcpaq_conn * const s); 43 | void tcpaq_close(struct tcpaq_conn * const s); 44 | int tcpaq_reserve(struct tcpaq_conn * const s, size_t size); 45 | int tcpaq_unreserve(struct tcpaq_conn * const s, size_t size); 46 | int tcpaq_queue(struct tcpaq_conn * const s, void *data, size_t size, int reserved); 47 | int tcpaq_is_out_queue_empty(struct tcpaq_conn * const s); 48 | int tcpaq_flush_nowait(struct tcpaq_conn * const s); /* same as send_nowait but returns -EAGAIN, -EINTR */ 49 | int tcpaq_send_nowait(struct tcpaq_conn * const s); 50 | int tcpaq_drain(struct tcpaq_conn * const s); 51 | int tcpaq_discard(struct tcpaq_conn * const s, size_t object_size); 52 | int tcpaq_receive_nowait(struct tcpaq_conn * const s, size_t object_size, void *buf) __attribute__((__unused__)); 53 | int tcpaq_peek_nowait(struct tcpaq_conn * const s, size_t object_size, const char **pbuf); 54 | 55 | #endif /* SIMET_TCPAQ_H */ 56 | 57 | /* vim: set et ts=4 sw=4 : */ 58 | -------------------------------------------------------------------------------- /inetup-client-c/version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # one-level subproject version handler 3 | # Copyright (c) 2018,2019 NIC.br 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. In every case, additional 9 | # restrictions and permissions apply, refer to the COPYING file in the 10 | # program Source for details. 11 | # 12 | # This program is distributed in the hope that it will be useful, but 13 | # WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | # General Public License and the COPYING file in the program Source 16 | # for details. 17 | 18 | GIT_VER= 19 | ME=$(realpath -q -e "$0") 20 | BME=$(dirname "$ME") 21 | 22 | exiterr() { 23 | echo "unknown" 24 | exit 1 25 | } 26 | 27 | cd "$BME" || exiterr 28 | if git rev-parse --git-dir >/dev/null 2>&1 ; then 29 | [ -n "$(git rev-parse --show-prefix 2>/dev/null)" ] && cd .. 30 | [ -z "$(git rev-parse --show-prefix 2>/dev/null)" ] && \ 31 | GIT_VER=$(git describe --dirty=+ --abbrev=10 --tags --long --match 'v*' --always 2>/dev/null) 32 | fi 33 | [ -z "$GIT_VER" ] && GIT_VER=$(cat version 2>/dev/null || cat ../version 2>/dev/null) 34 | [ -z "$GIT_VER" ] && exiterr 35 | echo "$GIT_VER" 36 | : 37 | -------------------------------------------------------------------------------- /simet-api/.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | Makefile.in 3 | agent-version.txt 4 | conf/simet-ma.conf 5 | conf/lmap-sched-template.json 6 | config.d/simet-ma_base-config.json 7 | config.d/simet-ma_tasklet-config.json 8 | config.d/simetbox_base-config.json 9 | registry.d/simet-ma_base-registry.json 10 | registry.d/simet-ma_tasklet-registry.json 11 | registry.d/simetbox_base-registry.json 12 | simet*_register_ma.sh 13 | simet*_view_results.sh 14 | simet-ma_periodic.sh 15 | simet_report-queue-flush.sh 16 | simet*_lmap-fetch-schedule.sh 17 | simet*_lmap-create-report.sh 18 | simet*_lmap-send-report.sh 19 | simet*_lmap-stdout-wrapper.sh 20 | simet*_geolocation.sh 21 | simet_read_vlabel.sh* 22 | simet_spoofer_v2.sh 23 | simet_create_vlabel.sh* 24 | simet_issuebanner-generator.sh 25 | simet_qrcode.sh 26 | simet_pairing_info.sh 27 | simet_lib.sh* 28 | simet_lib_config.sh 29 | simet_lib_lmapd.sh 30 | lmap-tasks/*.sh 31 | -------------------------------------------------------------------------------- /simet-api/README: -------------------------------------------------------------------------------- 1 | This uses the toplevel configure.ac 2 | This uses the toplevel Makefile.am via SUBDIRS 3 | 4 | API.md describes the API. Some of it is not stable, and intended to be 5 | replaced soon with scripts that implement a more stable API. Those are only 6 | described in the source code. 7 | 8 | For OpenWRT ("SIMETBox") builds, refer to the openwrt feed, it has a higher 9 | level ubus RPC API that should be used, and its implementation can shed light 10 | on the current inner workings of the SIMET measurement engine. 11 | -------------------------------------------------------------------------------- /simet-api/conf/lmap-emergency-schedule.json: -------------------------------------------------------------------------------- 1 | {"ietf-lmap-control:lmap":{ 2 | "schedules":{"schedule":[ 3 | { "name":"ma-local_emergency-sched-refresh", 4 | "tag":["ma-local_locally-generated-schedule","ma-local_emergency-schedule"], 5 | "start":"every-hour", 6 | "execution-mode":"sequential", 7 | "action":[{"name":"simet.nic.br_reschedule","task":"simet.nic.br_reschedule"}] 8 | }, 9 | { "name":"ma-local_report-queue-flush", 10 | "start":"every-fifteen-minutes", 11 | "execution-mode":"sequential", 12 | "action":[{"name":"simet.nic.br_report-queue-flush","task":"simet.nic.br_report-queue-flush"}] 13 | } 14 | ]},"events":{"event":[ 15 | { "name":"every-fifteen-minutes","random-spread":15,"periodic":{"interval":900} }, 16 | { "name":"every-hour","random-spread":90,"periodic":{"interval":3600} } 17 | ]} }} 18 | -------------------------------------------------------------------------------- /simet-api/conf/lmap-empty-schedule.json: -------------------------------------------------------------------------------- 1 | {"ietf-lmap-control:lmap":{ 2 | "schedules":{"schedule":[]}, 3 | "events":{"event":[]} 4 | }} 5 | -------------------------------------------------------------------------------- /simet-api/conf/simet-ma.conf.in: -------------------------------------------------------------------------------- 1 | CURL_APIBASE="--connect-timeout 15 --location --post301 --post302 --proto =https -s" 2 | CURL_APIOPT="--max-time 75 --retry 8 --retry-max-time 300" 3 | CURL_APIOPT_FAST="--max-time 30 --retry 3 --retry-max-time 75" 4 | 5 | API_SIMET_AGENT_REG=https://api.simet.nic.br/agent-registry 6 | 7 | SIMET_LOCK_DIR=@SIMETLOCKDIR@ 8 | 9 | AGENT_ID_FILE=@SIMETCONFDIR@/agent-id-v2 10 | AGENT_PAIR_FILE=@SIMETCONFDIR@/pairing-id 11 | AGENT_PAIRBKP_FILE=@SIMETCONFDIR@/old-pairing-id 12 | AGENT_VLABEL_FILE=@SIMETCONFDIR@/agent-vlabel 13 | AGENT_TOKEN_FILE=@SIMETCONFDIR@/agent-v2.jwt 14 | AGENT_TOKEN_LOCK="${SIMET_LOCK_DIR}/simet-agent-token.lock" 15 | AGENT_LOCK="${SIMET_LOCK_DIR}/simet-ma.lock" 16 | AGENT_VERSION_FILE=@SIMETLIBDIR@/agent-version.txt 17 | 18 | SIMET_RUNSTATE_DIR=@SIMETRUNDIR@ 19 | SIMET_VARSTATE_DIR=@SIMETVARDIR@ 20 | SIMET_CACHE_DIR=@SIMETCACHEDIR@ 21 | AGENT_VTK_FILE="$SIMET_RUNSTATE_DIR/agent-vtk" 22 | AGENT_PARTICIPANT_INFO="$SIMET_RUNSTATE_DIR/agent-owner-info" 23 | 24 | SIMET_PUBRUNSTATE_DIR=@SIMETPUBRUNDIR@ 25 | AGENT_VIEW_CREDENTIALS_FILE="$SIMET_PUBRUNSTATE_DIR/view-credentials" 26 | URL_AGENT_INTERACTIVE_PAIRING="https://simet.nic.br/ativar" 27 | 28 | LMAP_AGENT_FILE=@SIMETCONFDIR@/lmap/agent-id.json 29 | LMAP_CHANNEL_URL=https://api.simet.nic.br/controller 30 | 31 | LMAP_SCHEDULE_FILE=@LOCALSTATEDIR@/run/lmapd/lmap-schedule.json 32 | 33 | LMAP_SPOOL_DIR=@LMAPSPOOLDIR@ 34 | LMAP_REPORT_QUEUE_DIR=@LMAPSPOOLDIR@/reports 35 | LMAP_QUEUE_DIR_PREFIX=@LMAPSPOOLDIR@/queue 36 | LMAP_RUN_DIR_PREFIX=@LOCALSTATEDIR@/run/lmapd 37 | 38 | #SIMET_SERVICELIST_OVERRIDE= 39 | TEMPLATE_DIR=@SIMETLIBDIR@ 40 | 41 | SIMET_INETUP_SERVER=simet-monitor-inetup.simet.nic.br 42 | 43 | API_SIMET_GEO=https://api.simet.nic.br/geolocation 44 | GEOLOC_CACHE="$SIMET_CACHE_DIR/geoloc-cache.txt" 45 | 46 | LMAP_COLLECTOR=https://api.simet.nic.br/collector/measure 47 | API_SERVICE_DISCOVERY="https://api.simet.nic.br/service-list/services?filter%5Bservices%5D=serverMonitor,twamp,tcpbw,collector,spoofer" 48 | API_SERVER_SELECTION="https://api.simet.nic.br/server_selection_measurement" 49 | API_MSMT_PROFILE="https://api.simet.nic.br/msmt_profile" 50 | LMAP_SCHEDULE="anatel-resolution-574" 51 | LMAP_TASK_NAME_PREFIX="simet.nic.br_" 52 | GEOLOCATE=@BINDIR@/simet_geolocation.sh 53 | TWAMPC=@BINDIR@/twampc 54 | TCPBWC=@BINDIR@/tcpbwc 55 | SSPOOFERC=@BINDIR@/sspooferc 56 | JSONFILTER=@JSONFILTER@ 57 | LMAPSENDREPORT=@BINDIR@/simet_lmap-send-report.sh 58 | -------------------------------------------------------------------------------- /simet-api/config.d/simetbox_base-config.json.in: -------------------------------------------------------------------------------- 1 | {"ietf-lmap-control:lmap":{ 2 | "tasks":{"task":[ 3 | { "name":"simet.nic.br_gateway-ping", 4 | "tag":["simet.nic.br_engine-name:@SIMET_ENGINE_NAME@", 5 | "simet.nic.br_engine-version:@PACKAGEVERSION@", 6 | "simet.nic.br_task-version:@PACKAGEVERSION@" ], 7 | "program":"@LMAPBINDIR@/simetbox_fping-to-gateway.sh" } 8 | ]}}} 9 | -------------------------------------------------------------------------------- /simet-api/examples/vendor.get_platform_simet_label: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This is an example of vendor/get_platform_simet_label, usually installed 4 | # either at /opt/simet/lib/simet/vendor or /usr/lib/simet/vendor. 5 | # 6 | # Returns the device's pairing secret ("Etiqueta SIMET") *when it is a printed 7 | # label that the device's owner can read directly*. While the example is an 8 | # executable script, this could be any executable (e.g. a compiled C program, 9 | # or an executable Lua script). 10 | # 11 | # It should be present when the device has a printed label on its outside with 12 | # a device-unique password or secret, that the owner can read. If the device 13 | # has no such printed label, this executable SHOULD NOT BE PRESENT in the 14 | # device, or it must return exit status 1. 15 | # 16 | # This script should return in stdout the exact contents of the information 17 | # requested, as printed in the device's label. In that case, it must return 18 | # exit status 0. 19 | # 20 | # If the requested information cannot be retrieved *at this time* (i.e. it is a 21 | # temporary error), and the system should retry sometime later, it must return 22 | # an exit status other than 0 or 1. Any functionality that depends on the 23 | # requested information will be unavailable until the attempt is retried and 24 | # succeeds. 25 | # 26 | # NOTES: 27 | # Error messages must be sent to stderr, never to stdout. 28 | # 29 | # Returning DISABLED on stdout, or an empty stdout, and exit status 0 would 30 | # disable the SIMET virtual label functionality. This is NOT usually wanted, 31 | # as it forces the device into a stand-alone mode that cannot meaningfully 32 | # interact with any of the SIMET web portals. 33 | # 34 | # It must return status 2 for requests of unknown resouces (see below). 35 | # 36 | # 37 | # Command line: 38 | # get_platform_simet_label 39 | # 40 | # resources: 41 | # vlabel - SIMET pairing secret ("etiqueta SIMET") 42 | # 43 | # example: 44 | # FOO=$(get_platform_simet_label vlabel) && echo "The SIMET label is: $FOO" 45 | 46 | simet_psl_retrieve_label_from_flash() { 47 | # code here that gets the data from device flash and 48 | # outputs it to stdout, or exits with status 3 to 126 49 | # if it is a temporary error, or exits with status 1 if 50 | # the device doesn't have a printed label 51 | # 52 | # errors go to stderr 53 | 54 | #printf '%s' "$the_label_as_printed" 55 | 56 | return 1 57 | } 58 | 59 | case "$1" in 60 | vlabel) 61 | simet_psl_retrieve_label_from_flash || return $? 62 | exit 0 63 | ;; 64 | *) 65 | exit 2 66 | ;; 67 | esac 68 | exit 2 69 | -------------------------------------------------------------------------------- /simet-api/lmap-tasks/lmap-traceroute-wrapper.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # SIMET LMAP wrapping helper script (traceroute) 3 | # Copyright (c) 2019 NIC.br 4 | # Distributed under the GPLv3+ license with additional terms and permissions 5 | 6 | MYPATH=$(readlink -f "$0") ; MYSELF=$(basename "$0") 7 | TN1="${MYSELF#lmap-task-}" ; VC="${TN1%%_*}" 8 | TN2="${TN1#*_}" ; TOOL="${TN2#*_}" ; METRIC="${TN2%%_*}" 9 | 10 | case "$METRIC" in 11 | icmp*|ICMP*) 12 | PROTO="-I" 13 | ;; 14 | udp*|UDP*) 15 | PROTO= 16 | ;; 17 | *) 18 | echo "$MYPATH: ($0): unsupported protocol in metric: $METRIC" >&2 19 | exit 1 20 | ;; 21 | esac 22 | 23 | # Force tool, so that we can have tasklets like icmp-traceroute, etc. 24 | if command -v traceroute.db >/dev/null 2>&1 ; then 25 | # Prefer known-good traceroute for Debian/Ubuntu 26 | TOOL=traceroute.db 27 | else 28 | TOOL=traceroute 29 | fi 30 | 31 | 32 | exec "@BINDIR@/simet_lmap-stdout-wrapper.sh" exec "$TOOL" "-$VC" "$METRIC" $PROTO "$@" 33 | -------------------------------------------------------------------------------- /simet-api/lmap-tasks/lmap-wrapper.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # SIMET LMAP wrapping helper script 3 | # Copyright (c) 2019 NIC.br 4 | # Distributed under the GPLv3+ license with additional terms and permissions 5 | # 6 | # usage: symlink this script to the real tool's name, prefixed with 7 | # lmap-{task}-{option}_{metric}_, where {option} would be v for -v, -version for --version 8 | # and {task} must be "task", or "task", where mode will be used instead of exec 9 | # when calling simet_lmap-stdout-wrapper. "metric" can be empty (default) or the metric 10 | # to be used. 11 | # 12 | # example: to call traceroute, which has --version and a specific metric: 13 | # ln -s lmap-task--version_UDP-traceroute_traceroute 14 | # to call fping, which has -v: 15 | # ln -s (our name) lmap-task-v__fping 16 | 17 | MYPATH=$(readlink -f "$0") ; MYSELF=$(basename "$0") 18 | MO="${MYSELF#lmap-task}" ; MO="${MO%%-*}" ; [ -z "$MO" ] && MO=exec 19 | TN1="${MYSELF#lmap-task*-}" ; VC="${TN1%%_*}" 20 | TN2="${TN1#*_}" ; TOOL="${TN2#*_}" ; METRIC="${TN2%%_*}" 21 | [ -n "$TOOL" ] && \ 22 | exec "@BINDIR@/simet_lmap-stdout-wrapper.sh" "$MO" "$TOOL" "-$VC" "$METRIC" "$@" 23 | echo "$MYPATH: ($0): unknown or unlisted tool: $TOOL" >&2 24 | exit 1 25 | -------------------------------------------------------------------------------- /simet-api/lmap-tasks/simet2-agent-info.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # SIMET2 agent-info ambient metric 3 | # Copyright (c) 2019 NIC.br 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. In every case, additional 9 | # restrictions and permissions apply, refer to the COPYING file in the 10 | # program Source for details. 11 | # 12 | # This program is distributed in the hope that it will be useful, but 13 | # WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | # General Public License and the COPYING file in the program Source 16 | # for details. 17 | 18 | set -e 19 | . @SIMETLIBDIR@/simet_lib.sh 20 | simet2_agentinfo || exit 1 21 | a1=$(simet_jo "@SIMET_ENGINE_NAME@") 22 | a2=$(simet_jo "@PACKAGEVERSION@") 23 | a3=$(simet_jo "$SIMET2_AGENT_FAMILY") 24 | a4=$(simet_jo "$SIMET2_AGENT_ENVNAME") 25 | a5=$(simet_jo "$SIMET2_AGENT_ENVVERSION") 26 | a6=$(simet_jo "$SIMET2_FIRMWARE_VENDOR") 27 | a7=$(simet_jo "$SIMET2_DEVICE_MODEL") 28 | printf '{"function":[{"uri":"urn:ietf:metrics:perf:Priv_SPMonitor_Passive_AgentInfo__Multiple_Singleton"}], 29 | "column":["engine_name","engine_version","agent_family","agent_environment_name","agent_environment_version","firmware_vendor","device_model"], 30 | "row":[{"value":["%s","%s","%s","%s","%s","%s","%s"]}] }' \ 31 | "$a1" "$a2" "$a3" "$a4" "$a5" "$a6" "$a7" 32 | : 33 | -------------------------------------------------------------------------------- /simet-api/lmap-tasks/simetbox_fping-to-gateway.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # SIMET LMAP fping-to-gateway measurement, SIMETBox version 3 | # Copyright (c) 2020 NIC.br 4 | # Distributed under the GPLv3+ license with additional terms and permissions 5 | 6 | METRIC=fping-to-gateway-raw 7 | FPING_OPTIONS="-Adam" 8 | FPING_INT= 9 | GWS= 10 | 11 | usage() { 12 | printf '%s\n' "usage: $0 -4|-6 [-c ]" 13 | exit 2 14 | } 15 | pgw_device_offline() { 16 | printf '%s: device is offline, gateway undefined\n' "$1" >&2 17 | exit 11 18 | } 19 | 20 | ipf= 21 | count=5 22 | while [ $# -gt 0 ] ; do 23 | case "$1" in 24 | "-4"|"-6") 25 | ipf="$1" 26 | ;; 27 | "-c") 28 | shift 29 | count="$1" 30 | [ "$count" -ge 1 ] 2>/dev/null || usage 31 | ;; 32 | *) 33 | usage 34 | ;; 35 | esac 36 | shift 37 | done 38 | [ -z "$ipf" ] && usage 39 | 40 | # detect non-functional ubus/ACL, network.sh needs it 41 | ubus list network.interface >/dev/null 2>&1 || exit 3 42 | . /lib/functions/network.sh >/dev/null 2>&1 || exit 3 43 | 44 | if [ "$ipf" = "-4" ] ; then 45 | network_find_wan IP4WAN false && [ -n "$IP4WAN" ] \ 46 | && network_is_up "$IP4WAN" \ 47 | && network_get_gateway IP4GW "$IP4WAN" && [ -n "$IP4GW" ] \ 48 | && network_get_device IP4L3DEV "$IP4WAN" && [ -n "$IP4L3DEV" ] \ 49 | && { 50 | FPING_INT="$IP4L3DEV" 51 | GWS="$IP4GW" 52 | } 53 | [ -z "$GWS" ] && pgw_device_offline ip4 54 | 55 | else 56 | network_find_wan6 IP6WAN false && [ -n "$IP6WAN" ] \ 57 | && network_is_up "$IP6WAN" \ 58 | && network_get_gateway6 IP6GW "$IP6WAN" && [ -n "$IP6GW" ] \ 59 | && network_get_device IP6L3DEV "$IP6WAN" && [ -n "$IP6L3DEV" ] \ 60 | && { 61 | FPING_INT="$IP6L3DEV" 62 | GWS="$IP6GW" 63 | } 64 | [ -z "$GWS" ] && pgw_device_offline ip6 65 | fi 66 | [ -z "$GWS" ] && exit 3 67 | 68 | exec "@BINDIR@/simet_lmap-stdout-wrapper.sh" exec21ok "fping" "-v" "$METRIC" $FPING_OPTIONS "$ipf" -I "$FPING_INT" -C "$count" $GWS 69 | -------------------------------------------------------------------------------- /simet-api/registry.d/simet-ma_base-registry.json.in: -------------------------------------------------------------------------------- 1 | {"ietf-lmap-control:lmap":{"capabilities":{ 2 | "tag":["simet.nic.br_engine-name:@SIMET_ENGINE_NAME@","simet.nic.br_engine-version:@PACKAGEVERSION@"], 3 | "tasks":{"task":[ 4 | { "name":"simet.nic.br_agent-info","version":"@PACKAGEVERSION@","program":"@LMAPBINDIR@/simet2-agent-info.sh" }, 5 | { "name":"simet.nic.br_reschedule","version":"@PACKAGEVERSION@","program":"@BINDIR@/@SBPREFIX@_lmap-fetch-schedule.sh" }, 6 | { "name":"simet.nic.br_register","version":"@PACKAGEVERSION@","program":"@BINDIR@/simet_register_ma.sh" }, 7 | { "name":"simet.nic.br_geolocation","version":"@PACKAGEVERSION@","program":"@BINDIR@/simet_geolocation.sh" }, 8 | { "name":"simet.nic.br_basic-tests","version":"@PACKAGEVERSION@","program":"@BINDIR@/simet-ma_run.sh" }, 9 | { "name":"simet.nic.br_srvlist-mp-latency","version":"@PACKAGEVERSION@","program":"@BINDIR@/simet-ma_run.sh" }, 10 | { "name":"simet.nic.br_twampc","version":"@PACKAGEVERSION@","program":"@BINDIR@/twampc" }, 11 | { "name":"simet.nic.br_internet-availability","version":"@PACKAGEVERSION@","program":"@BINDIR@/inetupc" }, 12 | { "name":"simet.nic.br_sspooferc","version":"@PACKAGEVERSION@","program":"@BINDIR@/sspooferc" }, 13 | { "name":"simet.nic.br_spoofer-v2","version":"@PACKAGEVERSION@","program":"@BINDIR@/simet_spoofer_v2.sh" }, 14 | { "name":"simet.nic.br_sdnsaddr","version":"@PACKAGEVERSION@","program":"@BINDIR@/simet_dnsaddr" }, 15 | { "name":"simet.nic.br_report","version":"@PACKAGEVERSION@","program":"@BINDIR@/simet_lmap-send-report.sh" }, 16 | { "name":"simet.nic.br_report-queue-flush","version":"@PACKAGEVERSION@","program":"@BINDIR@/simet_report-queue-flush.sh" }, 17 | { "name":"simet.nic.br_nop","version":"@PACKAGEVERSION@","program":"/bin/true" }, 18 | { "name":"simet.nic.br_err","version":"@PACKAGEVERSION@","program":"/bin/false" } 19 | ]}}}} 20 | -------------------------------------------------------------------------------- /simet-api/registry.d/simet.nic.br_subsystem-id.tag-registry.json: -------------------------------------------------------------------------------- 1 | {"ietf-lmap-control:lmap":{"capabilities":{ 2 | "tag":["simet.nic.br_subsystem-id:simet2_std-v1"] 3 | }}} 4 | -------------------------------------------------------------------------------- /simet-api/registry.d/simetbox_base-registry.json.in: -------------------------------------------------------------------------------- 1 | {"ietf-lmap-control:lmap":{"capabilities":{ 2 | "tasks":{"task":[ 3 | { "name":"simet.nic.br_gateway-ping","version":"@PACKAGEVERSION@","program":"@LMAPBINDIR@/simetbox_fping-to-gateway.sh" } 4 | ]}}}} 5 | -------------------------------------------------------------------------------- /simet-api/simet_lib_config.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # SIMET-MA compatibility layer (shell script) 3 | # DO NOT FAIL OR EXIT WITH NON-ZERO STATUS HERE IF AT ALL POSSIBLE 4 | 5 | simetlib_shopt="$-" 6 | set +e 7 | SIMET_CFG_LOAD_ERROR= 8 | { 9 | [ -r @SIMETLIBDIR@/simet-ma.conf ] && { . @SIMETLIBDIR@/simet-ma.conf || SIMET_CFG_LOAD_ERROR=1 ; } 10 | [ -d @SIMETLIBDIR@/conf.d ] && { 11 | for i in @SIMETLIBDIR@/conf.d/*.conf ; do 12 | [ -r "$i" ] && { . "$i" || SIMET_CFG_LOAD_ERROR=1 ; } 13 | done 14 | } 15 | [ -r @SIMETCONFDIR@/simet-ma.conf ] && { . @SIMETCONFDIR@/simet-ma.conf || SIMET_CFG_LOAD_ERROR=1 ; } 16 | : 17 | } < /dev/null >&2 18 | case "$simetlib_shopt" in 19 | *e*) set -e ;; 20 | esac 21 | unset simetlib_shopt 22 | : 23 | -------------------------------------------------------------------------------- /simet-api/simet_read_vlabel.simet.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## simet_read_vlabel.sh - retrieve the SIMET2 virtual label 3 | ## Copyright (c) 2019,2020 NIC.br 4 | ## 5 | ## Retrieves to stdout the SIMET2 virtual label, if one already exists 6 | 7 | set -e 8 | set -o pipefail 9 | 10 | abend() { 11 | echo "$0: error: $*" >&2 12 | exit "$RC" 13 | } 14 | 15 | . @SIMETLIBDIR@/simet_lib.sh || RC=3 abend "simet_lib.sh malfunction" 16 | 17 | RC=1 18 | 19 | [ -z "$AGENT_VLABEL_FILE" ] && RC=3 abend "MA does not know where to keep its virtual label" 20 | [ -r "$AGENT_VLABEL_FILE" ] || RC=20 abend "MA is missing its virtual label" 21 | 22 | VLABEL=$(sed -n -e "1 {p;q}" "$AGENT_VLABEL_FILE") || RC=3 abend "failed to read virtual label" 23 | [ -z "$VLABEL" ] && exit 0 24 | [ "$VLABEL" = "DISABLED" ] && exit 0 25 | 26 | printf '%s\n' "$VLABEL" 27 | : 28 | -------------------------------------------------------------------------------- /simet-api/simet_read_vlabel.simetbox.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## simet_read_vlabel.sh - retrieve the SIMET2 virtual label 3 | ## Copyright (c) 2019,2020 NIC.br 4 | ## 5 | ## Retrieves to stdout the SIMET2 virtual label, if one already exists 6 | 7 | set -e 8 | set -o pipefail 9 | 10 | abend() { 11 | echo "$0: error: $*" >&2 12 | exit "$RC" 13 | } 14 | 15 | . @SIMETLIBDIR@/simet_lib.sh || RC=3 abend "simet_lib.sh malfunction" 16 | 17 | RC=1 18 | 19 | [ -z "$AGENT_VLABEL_FILE" ] && RC=3 abend "MA does not know where to keep its virtual label" 20 | [ -r "$AGENT_VLABEL_FILE" ] || RC=20 abend "MA is missing its virtual label" 21 | 22 | VLABEL=$(sed -n -e "1 {p;q}" "$AGENT_VLABEL_FILE") || RC=3 abend "failed to read virtual label" 23 | [ -z "$VLABEL" ] && exit 0 24 | [ "$VLABEL" = "DISABLED" ] && exit 0 25 | 26 | [ -n "$SIMET_MAC_LABEL" ] && grep -q "^MAC[[:blank:]]${SIMET_MAC_LABEL}[[:blank:]]" "$AGENT_VLABEL_FILE" \ 27 | || RC=20 abend "MA virtual label invalid: MAC address changed" 28 | 29 | printf '%s\n' "$VLABEL" 30 | : 31 | -------------------------------------------------------------------------------- /simet-api/simet_spoofer_v2.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec @BINDIR@/simet-ma_run.sh --test SPOOFER "$@" 3 | -------------------------------------------------------------------------------- /simet-api/utils/.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | Makefile.in 3 | aclocal.m4 4 | autom4te.cache/ 5 | compile 6 | config.guess 7 | config.log 8 | config.status 9 | config.sub 10 | configure 11 | depcomp 12 | install-sh 13 | missing 14 | src/.deps/ 15 | src/Makefile 16 | src/Makefile.in 17 | stamp-h1 18 | simet-api-utils_config.h 19 | simet-api-utils_config.h.in 20 | version 21 | err.log 22 | src/*.o 23 | src/simet_gen_vlabel 24 | src/base64_test 25 | -------------------------------------------------------------------------------- /simet-api/utils/AUTHORS: -------------------------------------------------------------------------------- 1 | Main authors: 2 | NIC.br - Núcleo de Informação e Coordenação do Ponto BR 3 | * Henrique de Moraes Holschuh 4 | -------------------------------------------------------------------------------- /simet-api/utils/ChangeLog: -------------------------------------------------------------------------------- 1 | * Nothing yet, tracked as git log 2 | -------------------------------------------------------------------------------- /simet-api/utils/Makefile.am: -------------------------------------------------------------------------------- 1 | ## 2 | ## Makefile.am for inetupc - SIMET2 MA Internet network availability (client) 3 | ## Copyright (c) 2018,2019 NIC.br 4 | ## 5 | ## This program is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. In every case, additional 9 | ## restrictions and permissions apply, refer to the COPYING file in the 10 | ## program Source for details. 11 | ## 12 | ## This program is distributed in the hope that it will be useful, but 13 | ## WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | ## General Public License and the COPYING file in the program Source 16 | ## for details. 17 | 18 | SUBDIRS = src 19 | 20 | EXTRA_DIST = autogen.sh version version.sh 21 | 22 | dist-local: version 23 | 24 | version: $(top_srcdir)/version.sh 25 | $(top_srcdir)/version.sh > version 26 | -------------------------------------------------------------------------------- /simet-api/utils/NEWS: -------------------------------------------------------------------------------- 1 | Please refer to main NEWS 2 | -------------------------------------------------------------------------------- /simet-api/utils/README: -------------------------------------------------------------------------------- 1 | Please refer to main README 2 | -------------------------------------------------------------------------------- /simet-api/utils/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (c) 2018,2019 NIC.br 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. In every case, additional 8 | # restrictions and permissions apply, refer to the COPYING file in the 9 | # program Source for details. 10 | # 11 | # This program is distributed in the hope that it will be useful, but 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License and the COPYING file in the program Source 15 | # for details. 16 | 17 | ./version.sh >/dev/null 2>&1 || { 18 | echo "$0: missing version file and not in a worktree" >&2 19 | exit 1 20 | } 21 | autoreconf -i 22 | -------------------------------------------------------------------------------- /simet-api/utils/m4/ax_require_defined.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_require_defined.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_REQUIRE_DEFINED(MACRO) 8 | # 9 | # DESCRIPTION 10 | # 11 | # AX_REQUIRE_DEFINED is a simple helper for making sure other macros have 12 | # been defined and thus are available for use. This avoids random issues 13 | # where a macro isn't expanded. Instead the configure script emits a 14 | # non-fatal: 15 | # 16 | # ./configure: line 1673: AX_CFLAGS_WARN_ALL: command not found 17 | # 18 | # It's like AC_REQUIRE except it doesn't expand the required macro. 19 | # 20 | # Here's an example: 21 | # 22 | # AX_REQUIRE_DEFINED([AX_CHECK_LINK_FLAG]) 23 | # 24 | # LICENSE 25 | # 26 | # Copyright (c) 2014 Mike Frysinger 27 | # 28 | # Copying and distribution of this file, with or without modification, are 29 | # permitted in any medium without royalty provided the copyright notice 30 | # and this notice are preserved. This file is offered as-is, without any 31 | # warranty. 32 | 33 | #serial 1 34 | 35 | AC_DEFUN([AX_REQUIRE_DEFINED], [dnl 36 | m4_ifndef([$1], [m4_fatal([macro ]$1[ is not defined; is a m4 file missing?])]) 37 | ])dnl AX_REQUIRE_DEFINED 38 | -------------------------------------------------------------------------------- /simet-api/utils/src/Makefile.am: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS = simet_gen_vlabel 2 | 3 | simet_gen_vlabel_SOURCES = crc16.h crc16.c \ 4 | sha256.h sha256.c \ 5 | base64.h base64.c \ 6 | simet_gen_vlabel.c 7 | 8 | # "make check" and run manually for now 9 | check_PROGRAMS = base64_test 10 | base64_test_SOURCES = base64.h base64.c base64_test.c 11 | -------------------------------------------------------------------------------- /simet-api/utils/src/crc16.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Library: libcrc 3 | * File: include/checksum.h 4 | * Author: Lammert Bies 5 | * 6 | * This file is licensed under the MIT License as stated below 7 | * 8 | * Copyright (c) 1999-2018 Lammert Bies 9 | * 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy 11 | * of this software and associated documentation files (the "Software"), to deal 12 | * in the Software without restriction, including without limitation the rights 13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | * copies of the Software, and to permit persons to whom the Software is 15 | * furnished to do so, subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be included in all 18 | * copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | * SOFTWARE. 27 | * 28 | * Description 29 | * ----------- 30 | * The headerfile include/checksum.h contains the definitions and prototypes 31 | * for routines that can be used to calculate several kinds of checksums. 32 | * 33 | * Notes: prunned for just crc16 for SIMET-MA, changed some types. 34 | */ 35 | 36 | #ifndef DEF_LIBCRC_CHECKSUM_H 37 | #define DEF_LIBCRC_CHECKSUM_H 38 | 39 | #include 40 | #include 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /* 47 | * #define CRC_POLY_xxxx 48 | * 49 | * The constants of the form CRC_POLY_xxxx define the polynomials for some well 50 | * known CRC calculations. 51 | */ 52 | 53 | #define CRC_POLY_16 0xA001 54 | 55 | /* 56 | * #define CRC_START_xxxx 57 | * 58 | * The constants of the form CRC_START_xxxx define the values that are used for 59 | * initialization of a CRC value for common used calculation methods. 60 | */ 61 | 62 | #define CRC_START_16 0x0000 63 | 64 | /* 65 | * Prototype list of global functions 66 | */ 67 | 68 | uint16_t crc_16( const char *input_str, size_t num_bytes ); 69 | 70 | #ifdef __cplusplus 71 | }// Extern C 72 | #endif 73 | 74 | #endif // DEF_LIBCRC_CHECKSUM_H 75 | -------------------------------------------------------------------------------- /simet-api/utils/src/sha256.h: -------------------------------------------------------------------------------- 1 | #ifndef SHA256_H 2 | #define SHA256_H 3 | 4 | #define SHA256_BLKSIZE 64 5 | #define SHA256_DIGEST_LENGTH 32 6 | 7 | #include 8 | #include 9 | 10 | struct SHA256_CTX { 11 | uint32_t state[8]; 12 | uint64_t size; 13 | uint32_t offset; 14 | uint8_t buf[SHA256_BLKSIZE]; 15 | }; 16 | 17 | typedef struct SHA256_CTX SHA256_CTX; 18 | typedef uint8_t SHA256_DIGEST[SHA256_DIGEST_LENGTH]; 19 | 20 | void SHA256_Init(SHA256_CTX *ctx); 21 | void SHA256_Update(SHA256_CTX *ctx, const void *data, size_t len); 22 | void SHA256_Final(SHA256_DIGEST digest, SHA256_CTX *ctx); 23 | 24 | /* HMAC-SHA256 */ 25 | void HMAC_SHA256(SHA256_DIGEST digest, 26 | const void * key_in, size_t key_len, 27 | const void * data, size_t data_len); 28 | 29 | /* drains fd, returns 0 (ok) or -1 (error), errno set */ 30 | int HMAC_SHA256_from_fd(SHA256_DIGEST digest, 31 | const void * key_in, size_t key_len, 32 | int fd); 33 | 34 | /* PBKDF2-HMAC-SHA256 */ 35 | 36 | /* returns 0 (ok), -1 (error), errno set */ 37 | int pbkdf2_hmac_sha256(const uint8_t *pw, size_t pw_len, 38 | const uint8_t *salt, size_t salt_len, 39 | uint32_t iterations, 40 | uint8_t *key_out, size_t key_out_len); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /simet-api/utils/version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # one-level subproject version handler 3 | # Copyright (c) 2018,2019 NIC.br 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. In every case, additional 9 | # restrictions and permissions apply, refer to the COPYING file in the 10 | # program Source for details. 11 | # 12 | # This program is distributed in the hope that it will be useful, but 13 | # WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | # General Public License and the COPYING file in the program Source 16 | # for details. 17 | 18 | GIT_VER= 19 | ME=$(realpath -q -e "$0") 20 | BME=$(dirname "$ME") 21 | 22 | exiterr() { 23 | echo "unknown" 24 | exit 1 25 | } 26 | 27 | cd "$BME" || exiterr 28 | if git rev-parse --git-dir >/dev/null 2>&1 ; then 29 | [ -n "$(git rev-parse --show-prefix 2>/dev/null)" ] && cd .. 30 | [ -z "$(git rev-parse --show-prefix 2>/dev/null)" ] && \ 31 | GIT_VER=$(git describe --dirty=+ --abbrev=10 --tags --long --match 'v*' --always 2>/dev/null) 32 | fi 33 | [ -z "$GIT_VER" ] && GIT_VER=$(cat version 2>/dev/null || cat ../version 2>/dev/null) 34 | [ -z "$GIT_VER" ] && exiterr 35 | echo "$GIT_VER" 36 | : 37 | -------------------------------------------------------------------------------- /simet-dnsaddr-c/.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | Makefile.in 3 | aclocal.m4 4 | autom4te.cache/ 5 | compile 6 | config.guess 7 | config.log 8 | config.status 9 | config.sub 10 | configure 11 | depcomp 12 | install-sh 13 | missing 14 | src/.deps/ 15 | src/Makefile 16 | src/Makefile.in 17 | stamp-h1 18 | *_config.h 19 | *_config.h.in 20 | version 21 | err.log 22 | src/*.o 23 | src/simet_dnsaddr 24 | -------------------------------------------------------------------------------- /simet-dnsaddr-c/AUTHORS: -------------------------------------------------------------------------------- 1 | Main authors: 2 | NIC.br - Núcleo de Informação e Coordenação do Ponto BR 3 | * Henrique de Moraes Holschuh 4 | -------------------------------------------------------------------------------- /simet-dnsaddr-c/ChangeLog: -------------------------------------------------------------------------------- 1 | * Nothing yet, tracked as git log 2 | -------------------------------------------------------------------------------- /simet-dnsaddr-c/Makefile.am: -------------------------------------------------------------------------------- 1 | ## 2 | ## Makefile.am for inetupc - SIMET2 MA Internet network availability (client) 3 | ## Copyright (c) 2018,2019 NIC.br 4 | ## 5 | ## This program is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. In every case, additional 9 | ## restrictions and permissions apply, refer to the COPYING file in the 10 | ## program Source for details. 11 | ## 12 | ## This program is distributed in the hope that it will be useful, but 13 | ## WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | ## General Public License and the COPYING file in the program Source 16 | ## for details. 17 | 18 | SUBDIRS = src 19 | 20 | EXTRA_DIST = autogen.sh version version.sh 21 | 22 | dist-local: version 23 | 24 | version: $(top_srcdir)/version.sh 25 | $(top_srcdir)/version.sh > version 26 | -------------------------------------------------------------------------------- /simet-dnsaddr-c/NEWS: -------------------------------------------------------------------------------- 1 | Please refer to main NEWS 2 | -------------------------------------------------------------------------------- /simet-dnsaddr-c/README: -------------------------------------------------------------------------------- 1 | Please refer to main README 2 | -------------------------------------------------------------------------------- /simet-dnsaddr-c/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (c) 2018,2019 NIC.br 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. In every case, additional 8 | # restrictions and permissions apply, refer to the COPYING file in the 9 | # program Source for details. 10 | # 11 | # This program is distributed in the hope that it will be useful, but 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License and the COPYING file in the program Source 15 | # for details. 16 | 17 | ./version.sh >/dev/null 2>&1 || { 18 | echo "$0: missing version file and not in a worktree" >&2 19 | exit 1 20 | } 21 | autoreconf -i 22 | -------------------------------------------------------------------------------- /simet-dnsaddr-c/m4/ax_require_defined.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_require_defined.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_REQUIRE_DEFINED(MACRO) 8 | # 9 | # DESCRIPTION 10 | # 11 | # AX_REQUIRE_DEFINED is a simple helper for making sure other macros have 12 | # been defined and thus are available for use. This avoids random issues 13 | # where a macro isn't expanded. Instead the configure script emits a 14 | # non-fatal: 15 | # 16 | # ./configure: line 1673: AX_CFLAGS_WARN_ALL: command not found 17 | # 18 | # It's like AC_REQUIRE except it doesn't expand the required macro. 19 | # 20 | # Here's an example: 21 | # 22 | # AX_REQUIRE_DEFINED([AX_CHECK_LINK_FLAG]) 23 | # 24 | # LICENSE 25 | # 26 | # Copyright (c) 2014 Mike Frysinger 27 | # 28 | # Copying and distribution of this file, with or without modification, are 29 | # permitted in any medium without royalty provided the copyright notice 30 | # and this notice are preserved. This file is offered as-is, without any 31 | # warranty. 32 | 33 | #serial 1 34 | 35 | AC_DEFUN([AX_REQUIRE_DEFINED], [dnl 36 | m4_ifndef([$1], [m4_fatal([macro ]$1[ is not defined; is a m4 file missing?])]) 37 | ])dnl AX_REQUIRE_DEFINED 38 | -------------------------------------------------------------------------------- /simet-dnsaddr-c/src/Makefile.am: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS = simet_dnsaddr 2 | 3 | simet_dnsaddr_SOURCES = base64.h base64.c \ 4 | retry.h timespec.h simet_err.h logger.h \ 5 | report.h report.c \ 6 | simet_random.h simet_random.c \ 7 | simet_dnsaddr.c 8 | 9 | simet_dnsaddr_LDADD = ${JSON_LIBS} 10 | 11 | # "make check" and run manually for now 12 | check_PROGRAMS = base64_test 13 | base64_test_SOURCES = base64.h base64.c base64_test.c 14 | -------------------------------------------------------------------------------- /simet-dnsaddr-c/src/logger.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018,2019 NIC.br 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. In every case, additional 8 | * restrictions and permissions apply, refer to the COPYING file in the 9 | * program Source for details. 10 | * 11 | * This program is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License and the COPYING file in the program Source 15 | * for details. 16 | */ 17 | 18 | #ifndef LOGGER_H_ 19 | #define LOGGER_H_ 20 | 21 | #include 22 | 23 | extern int log_level; /* 0: errors; 1: quiet; 2: normal; 3: debug/verbose ; 4: trace */ 24 | extern const char *progname; 25 | 26 | #define MSG_ALWAYS 0 27 | #define MSG_IMPORTANT 1 28 | #define MSG_NORMAL 2 29 | #define MSG_DEBUG 3 30 | #define MSG_TRACE 4 31 | 32 | #define print_msg_u(format, arg...) \ 33 | do { fflush(stdout); fprintf(stderr, "%s: " format "\n", progname, ## arg); } while (0) 34 | 35 | #define print_msg(level, format, arg...) \ 36 | do { \ 37 | if (log_level >= (level)) { \ 38 | fflush(stdout); \ 39 | fprintf(stderr, "%s: " format "\n", progname, ## arg); \ 40 | } \ 41 | } while (0) 42 | 43 | #define print_err(format, arg...) \ 44 | do { fflush(stdout); fprintf(stderr, "%s: error: " format "\n", progname, ## arg); } while (0) 45 | 46 | #define print_warn(format, arg...) \ 47 | do { fflush(stdout); fprintf(stderr, "%s: warning: " format "\n", progname, ## arg); } while (0) 48 | 49 | #endif /* LOGGER_H_ */ 50 | -------------------------------------------------------------------------------- /simet-dnsaddr-c/src/report.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SIMET2 MA SIMET Spoofer client (sspooferc) - reports 3 | * Copyright (c) 2024 NIC.br 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. In every case, additional 9 | * restrictions and permissions apply, refer to the COPYING file in the 10 | * program Source for details. 11 | * 12 | * This program is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * General Public License and the COPYING file in the program Source 16 | * for details. 17 | */ 18 | 19 | #ifndef REPORT_H_ 20 | #define REPORT_H_ 21 | 22 | #include 23 | 24 | enum report_mode { 25 | SSPOOF_REPORT_MODE_FRAGMENT = 0, /* Array contents */ 26 | SSPOOF_REPORT_MODE_OBJECT = 1, /* array or object */ 27 | SSPOOF_REPORT_MODE_EOL 28 | }; 29 | 30 | typedef union sockaddr_any_t_ { 31 | struct sockaddr sa; 32 | struct sockaddr_in in; 33 | struct sockaddr_in6 in6; 34 | } sockaddr_any_t_; 35 | 36 | struct dns_addrinfo_result { 37 | struct dns_addrinfo_result *next; 38 | sockaddr_any_t_ last_resolver; 39 | int64_t query_time_us; 40 | }; 41 | 42 | struct dns_addrinfo_head { 43 | struct dns_addrinfo_result *head; 44 | struct dns_addrinfo_result *tail; 45 | }; 46 | 47 | int sdnsa_render_report(struct dns_addrinfo_head * const data_nocache, 48 | struct dns_addrinfo_head * const data_cached, 49 | enum report_mode report_mode); 50 | 51 | #endif /* REPORT_H_ */ 52 | 53 | /* vim: set et ts=8 sw=4 : */ 54 | -------------------------------------------------------------------------------- /simet-dnsaddr-c/src/retry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Retry macros for EINTR, EAGAIN, EWOULDBLOCK 3 | * Copyright (c) 2024 NIC.br 4 | * 5 | * SPDX-License-Identifier: BSD-3-CLAUSE 6 | */ 7 | 8 | #ifndef SRETRY_H_ 9 | #define SRETRY_H_ 10 | 11 | #include 12 | 13 | #define MAXIMUM_SYSCALL_RETRIES 50 14 | #define MAXIMUM_GAI_RETRIES 5 15 | 16 | #define RETRY_EINTR(x) ({ \ 17 | typeof(x) _r; \ 18 | char _tries = MAXIMUM_SYSCALL_RETRIES; \ 19 | do { \ 20 | _r = (x); \ 21 | } while (_r == -1 && errno == EINTR && (--_tries) > 0); \ 22 | _r; \ 23 | }) 24 | 25 | #define RETRY_GAI(x) ({ \ 26 | char _tries = MAXIMUM_GAI_RETRIES; \ 27 | int _r; \ 28 | do { \ 29 | _r = (x); \ 30 | } while (( (_r == EAI_SYSTEM && errno == EINTR) || (_r == EAI_AGAIN)) \ 31 | && (--_tries) > 0); \ 32 | _r; \ 33 | }) 34 | 35 | #endif /* SRETRY_H_ */ 36 | /* vim: set et ts=8 sw=4 : */ 37 | -------------------------------------------------------------------------------- /simet-dnsaddr-c/src/simet_random.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SIMET2 MA - urandom access 3 | * Copyright (c) 2024 NIC.br 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. In every case, additional 9 | * restrictions and permissions apply, refer to the COPYING file in the 10 | * program Source for details. 11 | * 12 | * This program is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * General Public License and the COPYING file in the program Source 16 | * for details. 17 | */ 18 | 19 | #include 20 | 21 | #define SIMET_RANDOM_SOURCE "/dev/urandom" 22 | 23 | /* 24 | * Fills buf with random data from getrandom() or SIMET_RANDOM_SOURCE, 25 | * returns 0 if sucessfull, -1 with errno set otherwise 26 | */ 27 | int simet_getrandom(void * const buf, size_t buf_len); 28 | 29 | /* vim: set et ts=8 sw=4 : */ 30 | -------------------------------------------------------------------------------- /simet-dnsaddr-c/version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # one-level subproject version handler 3 | # Copyright (c) 2018,2019 NIC.br 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. In every case, additional 9 | # restrictions and permissions apply, refer to the COPYING file in the 10 | # program Source for details. 11 | # 12 | # This program is distributed in the hope that it will be useful, but 13 | # WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | # General Public License and the COPYING file in the program Source 16 | # for details. 17 | 18 | GIT_VER= 19 | ME=$(realpath -q -e "$0") 20 | BME=$(dirname "$ME") 21 | 22 | exiterr() { 23 | echo "unknown" 24 | exit 1 25 | } 26 | 27 | cd "$BME" || exiterr 28 | if git rev-parse --git-dir >/dev/null 2>&1 ; then 29 | [ -n "$(git rev-parse --show-prefix 2>/dev/null)" ] && cd .. 30 | [ -z "$(git rev-parse --show-prefix 2>/dev/null)" ] && \ 31 | GIT_VER=$(git describe --dirty=+ --abbrev=10 --tags --long --match 'v*' --always 2>/dev/null) 32 | fi 33 | [ -z "$GIT_VER" ] && GIT_VER=$(cat version 2>/dev/null || cat ../version 2>/dev/null) 34 | [ -z "$GIT_VER" ] && exiterr 35 | echo "$GIT_VER" 36 | : 37 | -------------------------------------------------------------------------------- /simet-runner/.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | Makefile.in 3 | aclocal.m4 4 | autom4te.cache/ 5 | compile 6 | config.guess 7 | config.log 8 | config.status 9 | config.sub 10 | configure 11 | depcomp 12 | install-sh 13 | missing 14 | src/.deps/ 15 | src/Makefile 16 | src/Makefile.in 17 | src/defines.sh 18 | stamp-h1 19 | version 20 | simet-ma_run.sh 21 | -------------------------------------------------------------------------------- /simet-runner/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM katta/openwrt-rootfs:lede-17.01.4 2 | 3 | RUN mkdir -p /var/lock \ 4 | && opkg update \ 5 | && opkg install curl ca-bundle 6 | 7 | EXPOSE 80 443 22 8 | 9 | CMD ["/sbin/init"] -------------------------------------------------------------------------------- /simet-runner/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (c) 2018,2019 NIC.br 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. In every case, additional 8 | # restrictions and permissions apply, refer to the COPYING file in the 9 | # program Source for details. 10 | # 11 | # This program is distributed in the hope that it will be useful, but 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License and the COPYING file in the program Source 15 | # for details. 16 | 17 | ./version.sh >/dev/null 2>&1 || { 18 | echo "$0: missing version file and not in a worktree" >&2 19 | exit 1 20 | } 21 | autoreconf -i 22 | -------------------------------------------------------------------------------- /simet-runner/configure.ac: -------------------------------------------------------------------------------- 1 | dnl Process this file with autoconf 2.69+ to produce a configure script. 2 | dnl 3 | dnl Copyright (c) 2018,2019 NIC.br 4 | dnl 5 | dnl This program is free software: you can redistribute it and/or modify 6 | dnl it under the terms of the GNU General Public License as published by 7 | dnl the Free Software Foundation, either version 3 of the License, or 8 | dnl (at your option) any later version. In every case, additional 9 | dnl restrictions and permissions apply, refer to the COPYING file in the 10 | dnl program Source for details. 11 | dnl 12 | dnl This program is distributed in the hope that it will be useful, but 13 | dnl WITHOUT ANY WARRANTY; without even the implied warranty of 14 | dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | dnl General Public License and the COPYING file in the program Source 16 | dnl for details. 17 | 18 | AC_PREREQ([2.69]) 19 | AC_INIT([simet-ma-runner], m4_esyscmd_s([./version.sh]), 20 | [medicoes@simet.nic.br], 21 | [simet-ma-runner], 22 | [http://simet.nic.br]) 23 | AC_COPYRIGHT([Copyright (c) 2018,2019 NIC.br ]) 24 | 25 | AC_CONFIG_AUX_DIR([.]) 26 | AC_CANONICAL_HOST 27 | AM_INIT_AUTOMAKE([1.13 foreign tar-pax no-dist-gzip dist-xz -Wall]) 28 | AC_CONFIG_FILES([Makefile]) 29 | AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ['$(top_srcdir)/version.sh $(top_srcdir)/version']) 30 | 31 | if test ! -r version ; then 32 | echo "$PACKAGE_VERSION" > version 33 | fi 34 | 35 | AC_ARG_ENABLE([simetbox], 36 | [AC_HELP_STRING([--enable-simetbox], 37 | [build for SIMETBOX (OpenWRT)])], 38 | [case "${enableval}" in 39 | yes) simetbox=true ;; 40 | no) simetbox=false ;; 41 | *) AC_MSG_ERROR([bad value ${enableval} for --enable-simetbox]) ;; 42 | esac], 43 | [simetbox=false]) 44 | AM_CONDITIONAL([SIMETBOX_BUILD], [test x$simetbox = xtrue]) 45 | AM_COND_IF([SIMETBOX_BUILD], 46 | [AC_MSG_NOTICE([building for SIMETBOX (OpenWRT)])]) 47 | 48 | AC_OUTPUT 49 | -------------------------------------------------------------------------------- /simet-runner/src/defines.sh.in: -------------------------------------------------------------------------------- 1 | #shellcheck shell=ash 2 | # Copyright (c) 2019 NIC.br 3 | # Source code fraction, for license information refer to the 4 | # main program source code. 5 | 6 | . @SIMETLIBDIR@/simet_lib.sh || exit 3 7 | 8 | SIMET_USERAGENT=$(get_http_useragent) || exit 3 9 | simet2_agentinfo || exit 3 10 | 11 | # defined at this point (empty for optional ones like SIMET_MAC_LABEL): 12 | # SIMET_USERAGENT, SIMET_MAC_LABEL 13 | # SIMET2_AGENT_FAMILY, SIMET2_AGENT_ENVNAME, SIMET2_AGENT_ENVVERSION 14 | # SIMET2_MAHOSTNAME, SIMET2_MADESCRIPTION, SIMET2_DEVICE_MODEL 15 | 16 | PACKAGE_NAME="@RUNNERNAME@" 17 | PACKAGE_VERSION="@RUNNERVERSION@" 18 | PACKAGE_STRING="@RUNNERSTRING@" 19 | SIMET_ENGINE_NAME="@SIMET_ENGINE_NAME@" 20 | SIMET_CONFIG_FILES="@SIMETLIBDIR@/simet-ma.conf @SIMETLIBDIR@/conf.d/*.conf @SIMETCONFDIR@/simet-ma.conf" 21 | TRACEROUTE_HELPER=$(find -L @SIMETLMAPBINDIR@ -type f -name '*traceroute' | sed -n -e '1 {p;q}' ) 22 | AGENTINFO_HELPER="@SIMETLMAPBINDIR@/simet2-agent-info.sh" 23 | TWAMPFAST_OPT="-c 50 -i 50000 -T 2000000" 24 | 25 | # keep line 26 | -------------------------------------------------------------------------------- /simet-runner/src/log.sh: -------------------------------------------------------------------------------- 1 | #shellcheck shell=ash 2 | # Copyright (c) 2018,2019 NIC.br 3 | # Source code fraction, for license information refer to the 4 | # main program source code. 5 | 6 | do_log(){ 7 | local pri="$1" 8 | shift 9 | [ -n "$LOG_TO_SYSLOG" ] && \ 10 | logger -t simet-ma -p "daemon.$pri" "$*" 11 | case $pri in 12 | err|error) 13 | printf "%s: error: %s\n" "$0" "$*" 14 | ;; 15 | warning) 16 | printf "%s: warning: %s\n" "$0" "$*" 17 | ;; 18 | info|notice) 19 | printf "%s: %s\n" "$0" "$*" 20 | ;; 21 | *) 22 | printf "%s: %s: %s\n" "$0" "$pri" "$*" 23 | ;; 24 | esac 25 | } 26 | 27 | log_error(){ 28 | do_log err "$@" >&2 29 | } 30 | 31 | log_warn(){ 32 | do_log warning "$@" >&2 33 | } 34 | 35 | log_info(){ 36 | [ "$QUIET" != "true" ] && do_log info "$@" 37 | : 38 | } 39 | 40 | log_notice(){ 41 | [ "$QUIET" != "true" ] && do_log notice "$@" 42 | : 43 | } 44 | 45 | log_debug(){ 46 | [ "$DEBUG" = "true" ] && do_log debug "$@" 47 | : 48 | } 49 | 50 | log_measurement(){ 51 | log_info "starting measurement task: $*" 52 | } 53 | log_verbose(){ 54 | [ "$VERBOSE" = "true" ] && log_info "$@" 55 | : 56 | } 57 | log_important(){ 58 | do_log notice "$@" 59 | } 60 | # keep line 61 | -------------------------------------------------------------------------------- /simet-runner/src/subtask_msmtparams.sh: -------------------------------------------------------------------------------- 1 | #shellcheck shell=ash 2 | # Copyright (c) 2023 NIC.br 3 | # Source code fraction, for license information refer to the 4 | # main program source code. 5 | 6 | ################################################################################ 7 | # 8 | # Builds parameters for several measurements from a profile 9 | # 10 | # function subtask_msmtprofile_tcpbw 11 | # - input var: AGENT_ID, AGENT_TOKEN 12 | # - input data: msmt_profiles.json, MEDIANRTT (us) 13 | # - output var: TCPBW_MSMT_PARAMS 14 | # 15 | # Dependencies: 16 | # - jsonfilter (default installed at OpenWRT) as $JSONFILTER 17 | # 18 | # msmt_profiles.json: 19 | # must be ordered from lowest to highest RTT in the selector. 20 | # 21 | ################################################################################ 22 | 23 | subtask_msmtprofile_tcpbw() { 24 | TCPBW_MSMT_PARAMS= 25 | [ -s "$BASEDIR/msmt_profiles.json" ] || return 0 26 | 27 | # for now, we use the RTT from TWAMP and have no other sources 28 | # of RTT 29 | [ "$TWAMP_MEDIANRTT" -gt 0 ] 2>/dev/null && { 30 | MEDIANRTT="$TWAMP_MEDIANRTT" 31 | log_debug "TCPBW: measurement profile selection will be based on TWAMP median RTT" 32 | } 33 | 34 | # RTT <= 49ms covers >75% of the non-wifi/non-mobile SIMET MAs in 2023 35 | local mrtt 36 | if [ "$MEDIANRTT" -ge 0 ] 2>/dev/null ; then 37 | mrtt=$(( MEDIANRTT / 1000 )) || mrtt=49 38 | else 39 | mrtt=49 40 | fi 41 | 42 | # NULL selector is the default entry 43 | local mjson 44 | mjson=$("$JSONFILTER" -i "$BASEDIR/msmt_profiles.json" -l1 -e "@.profile_tcpbw[@.selector.rtt_ge_ms <= $mrtt]") \ 45 | || mjson=$("$JSONFILTER" -i "$BASEDIR/msmt_profiles.json" -l1 -e "@.profile_tcpbw[!@.selector]") \ 46 | || return 0 47 | [ -n "$mjson" ] || return 0 48 | 49 | log_debug "TCPBW: selected profile $(printf "%s" "$mjson" | tr -s ' \t\n\v\r' ' ')" || : 50 | 51 | local p 52 | p=$("$JSONFILTER" -s "$mjson" -e "@.streams") && \ 53 | TCPBW_MSMT_PARAMS=$(append_list "$TCPBW_MSMT_PARAMS" -c "$p") 54 | p=$("$JSONFILTER" -s "$mjson" -e "@.max_duration_s") && 55 | TCPBW_MSMT_PARAMS=$(append_list "$TCPBW_MSMT_PARAMS" -l "$p") 56 | p=$("$JSONFILTER" -s "$mjson" -e "@.sample_period_ms") && 57 | TCPBW_MSMT_PARAMS=$(append_list "$TCPBW_MSMT_PARAMS" -s "$p") 58 | p=$("$JSONFILTER" -s "$mjson" -e "@.stream_pacing_bytespersec") && 59 | TCPBW_MSMT_PARAMS=$(append_list "$TCPBW_MSMT_PARAMS" -X "pacing=$p") 60 | p=$("$JSONFILTER" -s "$mjson" -e "@.stream_start_delay") && 61 | TCPBW_MSMT_PARAMS=$(append_list "$TCPBW_MSMT_PARAMS" -X "txdelay=$p") 62 | 63 | return 0 64 | } 65 | 66 | # keep line 67 | -------------------------------------------------------------------------------- /simet-runner/src/task_authentication.sh: -------------------------------------------------------------------------------- 1 | #shellcheck shell=ash 2 | # Copyright (c) 2018,2019 NIC.br 3 | # Source code fraction, for license information refer to the 4 | # main program source code. 5 | 6 | ################################################################################ 7 | # 8 | # function authentication() 9 | # - input var: AGENT_ID_FILE, AGENT_TOKEN_FILE 10 | # - output var: AGENT_ID, AGENT_TOKEN 11 | # - exit 1, on missing input var or files 12 | # 13 | # Execution: 14 | # echo myagentid > /tmp/agent_id 15 | # echo myagenttoken > /tmp/agent_token 16 | # AGENT_ID_FILE=/tmp/agent_id AGENT_TOKEN_FILE=/tmp/agent_token ./task_authentication.sh 17 | # 18 | # Dependencies: 19 | # - none 20 | # 21 | ################################################################################ 22 | 23 | authentication() { 24 | AGENT_ID=$( _authentication_agent_id ) || exit $? 25 | AGENT_TOKEN=$( _authentication_agent_token ) || exit $? 26 | } 27 | 28 | _authentication_agent_id(){ 29 | if [ "$AGENT_ID_FILE" = "" ]; then 30 | log_error "Exit. Missing configuration 'AGENT_ID_FILE'." 31 | exit 1 32 | fi 33 | 34 | if [ ! -e "$AGENT_ID_FILE" ]; then 35 | log_error "Exit. 'AGENT_ID_FILE' $AGENT_ID_FILE does not exist." 36 | exit 1 37 | fi 38 | cat "$AGENT_ID_FILE" 39 | } 40 | 41 | _authentication_agent_token(){ 42 | if [ "$AGENT_TOKEN_FILE" = "" ]; then 43 | log_error "Exit. Missing configuration 'AGENT_TOKEN_FILE'." 44 | exit 1 45 | fi 46 | 47 | if [ ! -e "$AGENT_TOKEN_FILE" ]; then 48 | log_error "Exit. 'AGENT_TOKEN_FILE' $AGENT_TOKEN_FILE does not exist." 49 | exit 1 50 | fi 51 | cat "$AGENT_TOKEN_FILE" 52 | } 53 | 54 | # execute main function, when script is executed directly 55 | if [ $(basename ${0//-/}) = "task_authentication.sh" ]; then 56 | source ./log.sh 57 | authentication "$@" 58 | log_info "$AGENT_ID" 59 | log_info "$AGENT_TOKEN" 60 | fi 61 | # keep line 62 | -------------------------------------------------------------------------------- /simet-runner/src/task_authorization.sh: -------------------------------------------------------------------------------- 1 | #shellcheck shell=ash 2 | # Copyright (c) 2018,2019 NIC.br 3 | # Source code fraction, for license information refer to the 4 | # main program source code. 5 | 6 | ################################################################################ 7 | # 8 | # function authorization() 9 | # - input param: endpoint_base agent_token 10 | # - input var: MOCK_AUTHORIZATION (optional var) 11 | # - output var: AUTHORIZATION_TOKEN 12 | # - return 0, on authorization 13 | # - return 1, on non authorization 14 | # 15 | # Execution: 16 | # 17 | # Dependencies: 18 | # - curl 19 | # - jsonfilter (configured as $JSONFILTER) 20 | # 21 | ################################################################################ 22 | 23 | authorization() { 24 | if [ -n "$SIMET_SERVICELIST_OVERRIDE" ]; then 25 | log_debug "Disabling authorization token support." 26 | AUTHORIZATION_TOKEN= 27 | return 0 28 | fi 29 | 30 | local _endpoint="${1}measure-allowed" 31 | local _agent_token="$2" 32 | 33 | curl $CURL_APIBASE $CURL_APIOPT_FAST \ 34 | --request GET \ 35 | --user-agent "$SIMET_USERAGENT" \ 36 | --header "Authorization: Bearer $_agent_token" \ 37 | --silent \ 38 | --show-error \ 39 | --fail \ 40 | --output "$BASEDIR/auth_response.json" \ 41 | --url "$_endpoint" \ 42 | || { 43 | log_error "Authorization request failed at: $_endpoint" 44 | return 1 45 | } 46 | 47 | local _allowed=$($JSONFILTER -i $BASEDIR/auth_response.json -e "@.measureAllowed") 48 | if [ $_allowed != "true" ]; then 49 | log_error "Authorization request denied at: $_endpoint" 50 | return 1 51 | fi 52 | 53 | log_debug "Authorization success at: $_endpoint" 54 | AUTHORIZATION_TOKEN=$($JSONFILTER -i $BASEDIR/auth_response.json -e "@.measurementToken") 55 | } 56 | # keep line 57 | -------------------------------------------------------------------------------- /simet-runner/src/task_environment.sh: -------------------------------------------------------------------------------- 1 | #shellcheck shell=ash 2 | # Copyright (c) 2018 NIC.br 3 | # Source code fraction, for license information refer to the 4 | # main program source code. 5 | 6 | ################################################################################ 7 | # 8 | # function task_environment() 9 | # - output: json to stdout when successful 10 | # - return 0, metric json sent to stdout 11 | # - return 1, failed 12 | # 13 | # Dependencies: 14 | # 15 | ################################################################################ 16 | 17 | 18 | # Output metrics related to measurement agent metadata for the whole report 19 | # We could instead report them once per task, but that wastes space since they 20 | # are invariant during a measurement run. 21 | ma_environment() { 22 | [ -n "$AGENTINFO_HELPER" ] && [ -x "$AGENTINFO_HELPER" ] && { 23 | "$AGENTINFO_HELPER" || return "$?" 24 | return 0 25 | } 26 | 27 | # fallback 28 | [ -z "$SIMET_ENGINE_NAME" ] || [ -z "$SIMET2_AGENT_FAMILY" ] || [ -z "$PACKAGE_VERSION" ] && return 1 29 | cat << EOF1AGITEMPLATE 30 | { 31 | "function": [ { "uri": "urn:ietf:metrics:perf:Priv_SPMonitor_Passive_AgentInfo__Multiple_Singleton" } ], 32 | "column": [ "engine_name", "engine_version", "agent_family", "agent_environment_name", "agent_environment_version" ], 33 | "row": [ { "value": [ "$SIMET_ENGINE_NAME", "$(simet_jo "$PACKAGE_VERSION")", "$SIMET2_AGENT_FAMILY", "$(simet_jo "$SIMET2_AGENT_ENVNAME")", "$(simet_jo "$SIMET2_AGENT_ENVVERSION")" ] } ] 34 | } 35 | EOF1AGITEMPLATE 36 | } 37 | # keep line 38 | -------------------------------------------------------------------------------- /simet-runner/src/task_geolocation.sh: -------------------------------------------------------------------------------- 1 | #shellcheck shell=ash 2 | # Copyright (c) 2018,2019 NIC.br 3 | # Source code fraction, for license information refer to the 4 | # main program source code. 5 | 6 | ################################################################################ 7 | # 8 | # function geolocate() 9 | # - input param: GEOLOCATE (simet_geolocation.sh full path) 10 | # - needs simet_geolocation API v2 (LMAP-like output) 11 | # - output: json to stdout when successful 12 | # simet_geolocation.sh debug output to stderr 13 | # - return 0, geolocate metric json sent to stdout 14 | # - return 1, no geolocation metric available 15 | # 16 | # Dependencies: 17 | # - simet_geolocation.sh 18 | # 19 | ################################################################################ 20 | 21 | geolocate() { 22 | GEOLOCATE=${GEOLOCATE:-simet_geolocation.sh} 23 | GEOSCRIPT=$(command -v "$GEOLOCATE") || return 1 24 | $GEOSCRIPT || return $? 25 | : 26 | } 27 | # keep line 28 | -------------------------------------------------------------------------------- /simet-runner/src/task_traceroute.sh: -------------------------------------------------------------------------------- 1 | #shellcheck shell=ash 2 | # Copyright (c) 2018,2019 NIC.br 3 | # Source code fraction, for license information refer to the 4 | # main program source code. 5 | 6 | # Connected to twamp, so enabled/disabled through TWAMP 7 | # Connected to SPOOFER, so enabled/disabled through SPOOFER 8 | # WARNING: MAY BE RUN IN BACKGROUND IN PARALLEL WITH OTHER TWAMP/TRACEROUTES! 9 | _task_traceroute(){ 10 | local _af="$1" 11 | local _tst_prefix="$2" 12 | if [[ "$_af" != "4" && "$_af" != "6" ]]; then 13 | log_error "Aborting task traceroute IPvX. Unknown address familiy '$_af'." 14 | return 1 15 | fi 16 | if [[ -z "$TRACEROUTE_HELPER" || "$TRACEROUTE_HELPER" = "NO" || "$TRACEROUTE_HELPER" = "no" || "$TRACEROUTE_HELPER" = "No" ]]; then 17 | log_info "Skipping task traceroute IPv$_af" 18 | return 0 19 | fi 20 | log_measurement "traceroute ${_tst_prefix}IPv$_af" 21 | local _host="ipv$_af.$( discover_service TRACEROUTE HOST )" 22 | 23 | export _task_name="${LMAP_TASK_NAME_PREFIX}tool_traceroute" 24 | export _task_version="$PACKAGE_VERSION" 25 | export _task_dir="$BASEDIR/report/traceroute-${_tst_prefix}ipv$_af" 26 | export _task_action="traceroute_to-simet-measurement-peer_${_tst_prefix}ip$_af" 27 | export _task_parameters='{ "host": "'$_host'" }' 28 | export _task_options='[]' 29 | export _task_extra_tags="\"simet.nic.br_peer-name:$_host\"," 30 | export _task_start=$(date -u +"%Y-%m-%dT%H:%M:%SZ") 31 | mkdir -p "$_task_dir/tables" 32 | if haspipefail && [ "$VERBOSE" = "true" ] ; then 33 | set -o pipefail 34 | eval "$TRACEROUTE_HELPER -$_af $_host 3>&2 2>&1 1>&3 3<&- >\"$_task_dir/tables/traceroute.json\"" | tee "$_task_dir/tables/stderr.txt" 35 | export _task_status="$?" 36 | set +o pipefail 37 | else 38 | eval "$TRACEROUTE_HELPER -$_af $_host >\"$_task_dir/tables/traceroute.json\"" 2>"$_task_dir/tables/stderr.txt" 39 | export _task_status="$?" 40 | fi 41 | export _task_end=$(date -u +"%Y-%m-%dT%H:%M:%SZ") 42 | if [ "$_task_status" -ne 0 ]; then 43 | log_error "Task traceroute IPv$_af, failed with exit code: $_task_status" 44 | [ -s "$_task_dir/tables/stderr.txt" ] && \ 45 | error_template < "$_task_dir/tables/stderr.txt" > "$_task_dir/tables/stderr.json" && \ 46 | rm -f "$_task_dir/tables/stderr.txt" 47 | # rm -f "$_task_dir/tables/traceroute.json" 48 | else 49 | rm -f "$_task_dir/tables/stderr.txt" 50 | fi 51 | task_template > "$_task_dir/result.json" 52 | log_debug "End Task traceroute ${_tst_prefix}IPv$_af" 53 | } 54 | 55 | # keep line 56 | -------------------------------------------------------------------------------- /simet-runner/src/util.sh: -------------------------------------------------------------------------------- 1 | #shellcheck shell=ash 2 | # Copyright (c) 2022 NIC.br 3 | # Source code fraction, for license information refer to the 4 | # main program source code. 5 | 6 | # space-separated list append, with space trimming 7 | append_list() { 8 | printf "%s" "$*" | sed -e 's/^[ \t\n]*//' -e 's/[ \t\n]*$//' || : 9 | } 10 | 11 | condwait() { 12 | [ -n "$SERIALIZE_DISABLE" ] && { 13 | wait || return $? 14 | return 0 15 | } 16 | [ -n "$SERIALIZE_MEMLIMIT" ] && [ "$SERIALIZE_MEMLIMIT" -gt 0 ] 2>/dev/null && { 17 | [ "$(awk \ 18 | 'BEGIN { MAV=99999999 } ; 19 | /^MemAvailable:.*kB$/ { MAV=$2 } ; 20 | END { print MAV }' \ 21 | /proc/meminfo || printf 0)" -ge "$SERIALIZE_MEMLIMIT" \ 22 | ] 2>/dev/null || { 23 | wait || return $? 24 | return 0 25 | } 26 | } 27 | sleep 1 28 | : 29 | } 30 | 31 | # keep line 32 | -------------------------------------------------------------------------------- /simet-runner/test/services-example.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "locality": "Test Locality", 3 | "serverMonitor": [{ 4 | "serviceName": "serverMonitor", 5 | "hostname": "hostname.example.com", 6 | "basePath": "server-monitor/", 7 | "ports": [ 8 | 443 9 | ] 10 | }], 11 | "collector": [{ 12 | "serviceName": "collector", 13 | "hostname": "api.hostname.example.com", 14 | "basePath": "collector/", 15 | "ports": [ 16 | 443 17 | ] 18 | }], 19 | "twamp": [{ 20 | "serviceName": "twamp", 21 | "hostname": "twamp-mp.example.com", 22 | "basePath": "", 23 | "ports": [ 24 | 862 25 | ] 26 | }], 27 | "tcpbw": [{ 28 | "serviceName": "tcpbw", 29 | "hostname": "tcpbw-mp.example.com", 30 | "basePath": "tcp-server/", 31 | "ports": [ 32 | 443 33 | ] 34 | }] 35 | }] 36 | -------------------------------------------------------------------------------- /simet-runner/test/simet-ma.conf: -------------------------------------------------------------------------------- 1 | # development config 2 | 3 | ################################################################################ 4 | # Dev config; not supplied on deployment; 5 | ################################################################################ 6 | 7 | # mock service discovery API 8 | MOCK_AUTHORIZATION="false" 9 | MOCK_API_SERVICE_DISCOVERY="false" 10 | MOCK_SERVICE_DISCOVERY_RESPONSE="./dist/services.mock.json" 11 | 12 | # ################################################################################ 13 | # # Main config; supplied externally on deployment; 14 | # ################################################################################ 15 | 16 | AGENT_ID_FILE="./dist/agent-id" 17 | AGENT_TOKEN_FILE="./dist/agent.jwt" 18 | 19 | AGENT_LOCK=/var/lock/simet-ma.lock 20 | 21 | API_SERVICE_DISCOVERY="https://api.simet.nic.br/service-list/services?filter%5Bservices%5D=serverMonitor,twamp,tcpbw,collector" 22 | 23 | TEMPLATE_DIR="./dist" 24 | 25 | TWAMPC=no 26 | TCPBWC=no 27 | LMAP_SCHEDULE="anatel-resolution-574" 28 | LMAP_TASK_NAME_PREFIX="simet2_simet-ma_" 29 | #TWAMPC="mock() { echo {} ; return 0; } ; mock " 30 | #TCPBWC="mock() { echo {} ; return 0; } ; mock " 31 | JSONFILTER=jsonfilter 32 | 33 | 34 | 35 | 36 | ################################################################################ 37 | # Config version for manual testing on SimetBox 38 | ################################################################################ 39 | # MOCK_AUTHORIZATION="true" 40 | # MOCK_API_SERVICE_DISCOVERY="true" 41 | # MOCK_SERVICE_DISCOVERY_RESPONSE=/usr/lib/simet/services.mock.json 42 | 43 | # AGENT_ID_FILE=/etc/simet/agent-id 44 | # AGENT_TOKEN_FILE=/etc/simet/agent.jwt 45 | # AGENT_TOKEN_LOCK=/var/lock/simet-ma.lock 46 | # AGENT_LOCK=/var/lock/simet-ma.lock 47 | # AGENT_VERSION_FILE=/usr/lib/simet/agent-version.txt 48 | 49 | # TEMPLATE_DIR=/usr/lib/simet 50 | 51 | # API_AGENT_TOKEN=https://api.simet.nic.br/measurement/jwt 52 | # API_SERVICE_DISCOVERY="https://api.simet.nic.br/service-list/services?filter%5Bservices%5D=serverMonitor,twamp,tcpbw,collector" 53 | # LMAP_SCHEDULE="anatel-resolution-574" 54 | # LMAP_TASK_NAME_PREFIX="simet2_simet-ma_" 55 | # TWAMPC=twampc 56 | # TCPBWC=tcpbwc 57 | # JSONFILTER=jsonfilter 58 | -------------------------------------------------------------------------------- /simet-runner/version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # one-level subproject version handler 3 | # Copyright (c) 2018,2019 NIC.br 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. In every case, additional 9 | # restrictions and permissions apply, refer to the COPYING file in the 10 | # program Source for details. 11 | # 12 | # This program is distributed in the hope that it will be useful, but 13 | # WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | # General Public License and the COPYING file in the program Source 16 | # for details. 17 | 18 | GIT_VER= 19 | ME=$(realpath -q -e "$0") 20 | BME=$(dirname "$ME") 21 | 22 | exiterr() { 23 | echo "unknown" 24 | exit 1 25 | } 26 | 27 | cd "$BME" || exiterr 28 | if git rev-parse --git-dir >/dev/null 2>&1 ; then 29 | [ -n "$(git rev-parse --show-prefix 2>/dev/null)" ] && cd .. 30 | [ -z "$(git rev-parse --show-prefix 2>/dev/null)" ] && \ 31 | GIT_VER=$(git describe --dirty=+ --abbrev=10 --tags --long --match 'v*' --always 2>/dev/null) 32 | fi 33 | [ -z "$GIT_VER" ] && GIT_VER=$(cat version 2>/dev/null || cat ../version 2>/dev/null) 34 | [ -z "$GIT_VER" ] && exiterr 35 | echo "$GIT_VER" 36 | : 37 | -------------------------------------------------------------------------------- /sspoofer-client-c/.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | Makefile.in 3 | aclocal.m4 4 | autom4te.cache/ 5 | compile 6 | config.guess 7 | config.log 8 | config.status 9 | config.sub 10 | configure 11 | depcomp 12 | install-sh 13 | missing 14 | src/.deps/ 15 | src/Makefile 16 | src/Makefile.in 17 | stamp-h1 18 | sspooferc_config.h 19 | sspooferc_config.h.in 20 | version 21 | err.log 22 | src/*.o 23 | src/sspooferc 24 | -------------------------------------------------------------------------------- /sspoofer-client-c/AUTHORS: -------------------------------------------------------------------------------- 1 | Main authors: 2 | NIC.br - Núcleo de Informação e Coordenação do Ponto BR 3 | * Henrique de Moraes Holschuh 4 | -------------------------------------------------------------------------------- /sspoofer-client-c/ChangeLog: -------------------------------------------------------------------------------- 1 | * Nothing yet 2 | -------------------------------------------------------------------------------- /sspoofer-client-c/Makefile.am: -------------------------------------------------------------------------------- 1 | ## 2 | ## Makefile.am for inetupc - SIMET2 MA Internet network availability (client) 3 | ## Copyright (c) 2018,2019 NIC.br 4 | ## 5 | ## This program is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. In every case, additional 9 | ## restrictions and permissions apply, refer to the COPYING file in the 10 | ## program Source for details. 11 | ## 12 | ## This program is distributed in the hope that it will be useful, but 13 | ## WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | ## General Public License and the COPYING file in the program Source 16 | ## for details. 17 | 18 | SUBDIRS = src 19 | 20 | EXTRA_DIST = autogen.sh version version.sh 21 | 22 | dist-local: version 23 | 24 | version: $(top_srcdir)/version.sh 25 | $(top_srcdir)/version.sh > version 26 | -------------------------------------------------------------------------------- /sspoofer-client-c/NEWS: -------------------------------------------------------------------------------- 1 | No news is good news 2 | -------------------------------------------------------------------------------- /sspoofer-client-c/README: -------------------------------------------------------------------------------- 1 | Source code structure: 2 | 3 |
4 | m4/ - autotools macros 5 | src/ - module 6 | -------------------------------------------------------------------------------- /sspoofer-client-c/TODO.txt: -------------------------------------------------------------------------------- 1 | 1. ensure server drains output chan after it sent MSMTDATA, 2 | receiving for close/disconnect 3 | 4 | 2. client needs to output reports of whatever is in done. 5 | -------------------------------------------------------------------------------- /sspoofer-client-c/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (c) 2018,2019 NIC.br 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. In every case, additional 8 | # restrictions and permissions apply, refer to the COPYING file in the 9 | # program Source for details. 10 | # 11 | # This program is distributed in the hope that it will be useful, but 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License and the COPYING file in the program Source 15 | # for details. 16 | 17 | ./version.sh >/dev/null 2>&1 || { 18 | echo "$0: missing version file and not in a worktree" >&2 19 | exit 1 20 | } 21 | autoreconf -i 22 | -------------------------------------------------------------------------------- /sspoofer-client-c/m4/ax_require_defined.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_require_defined.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_REQUIRE_DEFINED(MACRO) 8 | # 9 | # DESCRIPTION 10 | # 11 | # AX_REQUIRE_DEFINED is a simple helper for making sure other macros have 12 | # been defined and thus are available for use. This avoids random issues 13 | # where a macro isn't expanded. Instead the configure script emits a 14 | # non-fatal: 15 | # 16 | # ./configure: line 1673: AX_CFLAGS_WARN_ALL: command not found 17 | # 18 | # It's like AC_REQUIRE except it doesn't expand the required macro. 19 | # 20 | # Here's an example: 21 | # 22 | # AX_REQUIRE_DEFINED([AX_CHECK_LINK_FLAG]) 23 | # 24 | # LICENSE 25 | # 26 | # Copyright (c) 2014 Mike Frysinger 27 | # 28 | # Copying and distribution of this file, with or without modification, are 29 | # permitted in any medium without royalty provided the copyright notice 30 | # and this notice are preserved. This file is offered as-is, without any 31 | # warranty. 32 | 33 | #serial 1 34 | 35 | AC_DEFUN([AX_REQUIRE_DEFINED], [dnl 36 | m4_ifndef([$1], [m4_fatal([macro ]$1[ is not defined; is a m4 file missing?])]) 37 | ])dnl AX_REQUIRE_DEFINED 38 | -------------------------------------------------------------------------------- /sspoofer-client-c/src/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Copyright (c) 2018,2019 NIC.br 2 | ## 3 | ## This program is free software: you can redistribute it and/or modify 4 | ## it under the terms of the GNU General Public License as published by 5 | ## the Free Software Foundation, either version 3 of the License, or 6 | ## (at your option) any later version. In every case, additional 7 | ## restrictions and permissions apply, refer to the COPYING file in the 8 | ## program Source for details. 9 | ## 10 | ## This program is distributed in the hope that it will be useful, but 11 | ## WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | ## General Public License and the COPYING file in the program Source 14 | ## for details. 15 | 16 | bin_PROGRAMS = sspooferc 17 | 18 | sspooferc_SOURCES = ../sspooferc_config.h \ 19 | simet_err.h logger.h timespec.h retry.h \ 20 | netinet-tcp-compat.h \ 21 | sys-linux.h sys-linux.c \ 22 | base64.h base64.c \ 23 | tcpaq.h tcpaq.c \ 24 | msmtpkt.c misc.c \ 25 | report.h report.c \ 26 | sspooferc.h sspooferc.c 27 | 28 | sspooferc_LDADD = ${JSON_LIBS} 29 | 30 | check_PROGRAMS = base64_test 31 | base64_test_SOURCES = base64.h base64.c base64_test.c 32 | -------------------------------------------------------------------------------- /sspoofer-client-c/src/logger.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018,2019 NIC.br 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. In every case, additional 8 | * restrictions and permissions apply, refer to the COPYING file in the 9 | * program Source for details. 10 | * 11 | * This program is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License and the COPYING file in the program Source 15 | * for details. 16 | */ 17 | 18 | #ifndef LOGGER_H_ 19 | #define LOGGER_H_ 20 | 21 | #include 22 | 23 | extern int log_level; /* 0: errors; 1: quiet; 2: normal; 3: debug/verbose ; 4: trace */ 24 | extern const char *progname; 25 | 26 | #define MSG_ALWAYS 0 27 | #define MSG_IMPORTANT 1 28 | #define MSG_NORMAL 2 29 | #define MSG_DEBUG 3 30 | #define MSG_TRACE 4 31 | 32 | #define print_msg_u(format, arg...) \ 33 | do { fflush(stdout); fprintf(stderr, "%s: " format "\n", progname, ## arg); } while (0) 34 | 35 | #define print_msg(level, format, arg...) \ 36 | do { \ 37 | if (log_level >= (level)) { \ 38 | fflush(stdout); \ 39 | fprintf(stderr, "%s: " format "\n", progname, ## arg); \ 40 | } \ 41 | } while (0) 42 | 43 | #define print_err(format, arg...) \ 44 | do { fflush(stdout); fprintf(stderr, "%s: error: " format "\n", progname, ## arg); } while (0) 45 | 46 | #define print_warn(format, arg...) \ 47 | do { fflush(stdout); fprintf(stderr, "%s: warning: " format "\n", progname, ## arg); } while (0) 48 | 49 | #endif /* LOGGER_H_ */ 50 | -------------------------------------------------------------------------------- /sspoofer-client-c/src/netinet-tcp-compat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018,2019 NIC.br 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. In every case, additional 8 | * restrictions and permissions apply, refer to the COPYING file in the 9 | * program Source for details. 10 | * 11 | * This program is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License and the COPYING file in the program Source 15 | * for details. 16 | */ 17 | 18 | #ifndef NETINET_TCP_COMPAT_H 19 | #define NETINET_TCP_COMPAT_H 20 | 21 | #include 22 | 23 | #ifdef __linux__ 24 | /* 25 | * Missing socket options in OpenWRT CC uClibc 26 | * (OpenWRT CC uses Linux kernel 3.18.109) 27 | */ 28 | 29 | /* tcp-thin supported since Linux 2.6.34 */ 30 | #ifndef TCP_THIN_LINEAR_TIMEOUTS 31 | #define TCP_THIN_LINEAR_TIMEOUTS 16 32 | #endif 33 | #ifndef TCP_THIN_DUPACK 34 | #define TCP_THIN_DUPACK 17 35 | #endif 36 | 37 | /* TCP user timeouts supported since Linux 2.6.37 */ 38 | #ifndef TCP_USER_TIMEOUT 39 | #define TCP_USER_TIMEOUT 18 40 | #endif 41 | 42 | #endif /* __linux__ */ 43 | #endif /* NETINET_TCP_COMPAT_H */ 44 | -------------------------------------------------------------------------------- /sspoofer-client-c/src/report.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SIMET2 MA SIMET Spoofer client (sspooferc) - reports 3 | * Copyright (c) 2024 NIC.br 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. In every case, additional 9 | * restrictions and permissions apply, refer to the COPYING file in the 10 | * program Source for details. 11 | * 12 | * This program is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * General Public License and the COPYING file in the program Source 16 | * for details. 17 | */ 18 | 19 | #ifndef REPORT_H_ 20 | #define REPORT_H_ 21 | 22 | #include "sspooferc_config.h" 23 | 24 | #include 25 | 26 | enum report_mode { 27 | SSPOOF_REPORT_MODE_FRAGMENT = 0, /* Array contents */ 28 | SSPOOF_REPORT_MODE_OBJECT = 1, /* array or object */ 29 | SSPOOF_REPORT_MODE_EOL 30 | }; 31 | 32 | int sspoof_render_report(struct sspoof_server ** svec, unsigned int nvec, enum report_mode report_mode); 33 | 34 | #endif /* REPORT_H_ */ 35 | -------------------------------------------------------------------------------- /sspoofer-client-c/src/retry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Retry macros for EINTR, EAGAIN, EWOULDBLOCK 3 | * Copyright (c) 2024 NIC.br 4 | * 5 | * SPDX-License-Identifier: BSD-3-CLAUSE 6 | */ 7 | 8 | #ifndef SRETRY_H_ 9 | #define SRETRY_H_ 10 | 11 | #include 12 | 13 | #define MAXIMUM_SYSCALL_RETRIES 50 14 | #define MAXIMUM_GAI_RETRIES 5 15 | 16 | #define RETRY_EINTR(x) ({ \ 17 | typeof(x) _r; \ 18 | char _tries = MAXIMUM_SYSCALL_RETRIES; \ 19 | do { \ 20 | _r = (x); \ 21 | } while (_r == -1 && errno == EINTR && (--_tries) > 0); \ 22 | _r; \ 23 | }) 24 | 25 | #define RETRY_GAI(x) ({ \ 26 | char _tries = MAXIMUM_GAI_RETRIES; \ 27 | int _r; \ 28 | do { \ 29 | _r = (x); \ 30 | } while (( (_r == EAI_SYSTEM && errno == EINTR) || (_r == EAI_AGAIN)) \ 31 | && (--_tries) > 0); \ 32 | _r; \ 33 | }) 34 | 35 | #endif /* SRETRY_H_ */ 36 | /* vim: set et ts=8 sw=4 : */ 37 | -------------------------------------------------------------------------------- /sspoofer-client-c/src/sys-linux.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 NIC.br 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. In every case, additional 8 | * restrictions and permissions apply, refer to the COPYING file in the 9 | * program Source for details. 10 | * 11 | * This program is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License and the COPYING file in the program Source 15 | * for details. 16 | */ 17 | 18 | #ifndef SIMET_SYSLINUX_H 19 | #define SIMET_SYSLINUX_H 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #ifdef __linux__ 26 | 27 | /* 28 | * Because gcc has been sitting on this since 2016. 29 | */ 30 | static bool is_EAGAIN_WOULDBLOCK(const int e) __attribute__((__unused__,__const__)); 31 | static bool is_EAGAIN_WOULDBLOCK(const int e) 32 | { 33 | #if defined(EAGAIN) && defined (EWOULDBLOCK) && (EAGAIN == EWOULDBLOCK) 34 | return (e == EAGAIN); 35 | #else 36 | return (e == EAGAIN || e == EWOULDBLOCK); 37 | #endif 38 | } 39 | 40 | /* Get the number of seconds since boot in *val, limited to LONG_MAX. 41 | * returns 0 if sucessful, -EINVAL or -ENOTSUP otherwise */ 42 | int os_seconds_since_boot(int64_t * const uptime); 43 | 44 | #else 45 | 46 | static int os_seconds_since_boot(int64_t * const uptime) { return (uptime)? -ENOTSUP : -EINVAL; } 47 | 48 | #endif /* __linux__ */ 49 | 50 | #endif /* SIMET_INETUPTIME_H */ 51 | -------------------------------------------------------------------------------- /sspoofer-client-c/src/tcpaq.h: -------------------------------------------------------------------------------- 1 | /* 2 | * tcp-aq: tcp async queueing layer 3 | * Copyright (c) 2018-2024 NIC.br 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. In every case, additional 9 | * restrictions and permissions apply, refer to the COPYING file in the 10 | * program Source for details. 11 | * 12 | * This program is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * General Public License and the COPYING file in the program Source 16 | * for details. 17 | */ 18 | 19 | #ifndef SIMET_TCPAQ_H 20 | #define SIMET_TCPAQ_H 21 | 22 | #include 23 | 24 | #define SIMET_TCPAQ_QUEUESIZE 8192U 25 | struct tcpaq_queue { 26 | char *buffer; 27 | size_t buffer_size; 28 | size_t rd_pos; 29 | size_t wr_pos_reserved; 30 | size_t wr_pos; 31 | }; 32 | 33 | struct tcpaq_conn { 34 | struct tcpaq_queue in_queue; 35 | struct tcpaq_queue out_queue; 36 | 37 | sa_family_t ai_family; 38 | int socket; 39 | }; 40 | 41 | int tcpaq_init(struct tcpaq_conn * const s, size_t qsize); 42 | void tcpaq_free_members(struct tcpaq_conn * const s); 43 | void tcpaq_close(struct tcpaq_conn * const s); 44 | int tcpaq_reserve(struct tcpaq_conn * const s, size_t size); 45 | int tcpaq_unreserve(struct tcpaq_conn * const s, size_t size); 46 | int tcpaq_queue(struct tcpaq_conn * const s, void *data, size_t size, int reserved); 47 | int tcpaq_is_out_queue_empty(struct tcpaq_conn * const s); 48 | int tcpaq_flush_nowait(struct tcpaq_conn * const s); /* same as send_nowait but returns -EAGAIN, -EINTR */ 49 | int tcpaq_send_nowait(struct tcpaq_conn * const s); 50 | int tcpaq_drain(struct tcpaq_conn * const s); 51 | int tcpaq_discard(struct tcpaq_conn * const s, size_t object_size); 52 | int tcpaq_receive_nowait(struct tcpaq_conn * const s, size_t object_size, void *buf) __attribute__((__unused__)); 53 | int tcpaq_peek_nowait(struct tcpaq_conn * const s, size_t object_size, const char **pbuf); 54 | 55 | #endif /* SIMET_TCPAQ_H */ 56 | 57 | /* vim: set et ts=8 sw=4 : */ 58 | -------------------------------------------------------------------------------- /sspoofer-client-c/version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # one-level subproject version handler 3 | # Copyright (c) 2018,2019 NIC.br 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. In every case, additional 9 | # restrictions and permissions apply, refer to the COPYING file in the 10 | # program Source for details. 11 | # 12 | # This program is distributed in the hope that it will be useful, but 13 | # WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | # General Public License and the COPYING file in the program Source 16 | # for details. 17 | 18 | GIT_VER= 19 | ME=$(realpath -q -e "$0") 20 | BME=$(dirname "$ME") 21 | 22 | exiterr() { 23 | echo "unknown" 24 | exit 1 25 | } 26 | 27 | cd "$BME" || exiterr 28 | if git rev-parse --git-dir >/dev/null 2>&1 ; then 29 | [ -n "$(git rev-parse --show-prefix 2>/dev/null)" ] && cd .. 30 | [ -z "$(git rev-parse --show-prefix 2>/dev/null)" ] && \ 31 | GIT_VER=$(git describe --dirty=+ --abbrev=10 --tags --long --match 'v*' --always 2>/dev/null) 32 | fi 33 | [ -z "$GIT_VER" ] && GIT_VER=$(cat version 2>/dev/null || cat ../version 2>/dev/null) 34 | [ -z "$GIT_VER" ] && exiterr 35 | echo "$GIT_VER" 36 | : 37 | -------------------------------------------------------------------------------- /tcpbw-client-c/.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | Makefile.in 3 | aclocal.m4 4 | autom4te.cache/ 5 | compile 6 | config.guess 7 | config.log 8 | config.status 9 | config.sub 10 | configure 11 | depcomp 12 | install-sh 13 | missing 14 | src/.deps/ 15 | src/Makefile 16 | src/Makefile.in 17 | stamp-h1 18 | tcpbwc_config.h 19 | tcpbwc_config.h.in 20 | version 21 | err.log 22 | src/*.o 23 | src/tcpbwc 24 | -------------------------------------------------------------------------------- /tcpbw-client-c/AUTHORS: -------------------------------------------------------------------------------- 1 | Main authors: 2 | NIC.br - Núcleo de Informação e Coordenação do Ponto BR 3 | * Fábio Nokai 4 | * Henrique de Moraes Holschuh 5 | * Holger Wiehen 6 | -------------------------------------------------------------------------------- /tcpbw-client-c/ChangeLog: -------------------------------------------------------------------------------- 1 | * Nothing yet 2 | -------------------------------------------------------------------------------- /tcpbw-client-c/Makefile.am: -------------------------------------------------------------------------------- 1 | ## 2 | ## Makefile.am for tcpbwc - SIMET2 MA TCP bandwidth test client 3 | ## Copyright (c) 2018,2019 NIC.br 4 | ## 5 | ## This program is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. In every case, additional 9 | ## restrictions and permissions apply, refer to the COPYING file in the 10 | ## program Source for details. 11 | ## 12 | ## This program is distributed in the hope that it will be useful, but 13 | ## WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | ## General Public License and the COPYING file in the program Source 16 | ## for details. 17 | 18 | SUBDIRS = src 19 | 20 | EXTRA_DIST = autogen.sh version version.sh 21 | 22 | dist-local: version 23 | 24 | version: $(top_srcdir)/version.sh 25 | $(top_srcdir)/version.sh > version 26 | -------------------------------------------------------------------------------- /tcpbw-client-c/NEWS: -------------------------------------------------------------------------------- 1 | No news is good news 2 | -------------------------------------------------------------------------------- /tcpbw-client-c/README: -------------------------------------------------------------------------------- 1 | Source code structure: 2 | 3 |
4 | m4/ - autotools macros 5 | src/ - module 6 | -------------------------------------------------------------------------------- /tcpbw-client-c/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (c) 2018,2019 NIC.br 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. In every case, additional 8 | # restrictions and permissions apply, refer to the COPYING file in the 9 | # program Source for details. 10 | # 11 | # This program is distributed in the hope that it will be useful, but 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License and the COPYING file in the program Source 15 | # for details. 16 | 17 | ./version.sh >/dev/null 2>&1 || { 18 | echo "$0: missing version file and not in a worktree" >&2 19 | exit 1 20 | } 21 | autoreconf -i 22 | -------------------------------------------------------------------------------- /tcpbw-client-c/environment/alpine/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.7 2 | # Update Packages 3 | RUN apk update 4 | # Tools 5 | RUN apk add make g++ 6 | RUN apk add git cmake 7 | # Libs 8 | RUN apk add curl-dev 9 | # Install libubox 10 | RUN apk add lua-dev lua json-c-dev 11 | RUN git clone git://git.openwrt.org/project/libubox.git 12 | RUN cd libubox && git checkout 6eff829d788b36939325557066f58aafd6a05321 . && cmake . && make && make install 13 | # Create and Set WORKDIR 14 | RUN mkdir -p "c/code.ceptro.br/simet2/tcp-client-c" 15 | WORKDIR c/code.ceptro.br/simet2/tcp-client-c -------------------------------------------------------------------------------- /tcpbw-client-c/m4/ax_require_defined.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_require_defined.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_REQUIRE_DEFINED(MACRO) 8 | # 9 | # DESCRIPTION 10 | # 11 | # AX_REQUIRE_DEFINED is a simple helper for making sure other macros have 12 | # been defined and thus are available for use. This avoids random issues 13 | # where a macro isn't expanded. Instead the configure script emits a 14 | # non-fatal: 15 | # 16 | # ./configure: line 1673: AX_CFLAGS_WARN_ALL: command not found 17 | # 18 | # It's like AC_REQUIRE except it doesn't expand the required macro. 19 | # 20 | # Here's an example: 21 | # 22 | # AX_REQUIRE_DEFINED([AX_CHECK_LINK_FLAG]) 23 | # 24 | # LICENSE 25 | # 26 | # Copyright (c) 2014 Mike Frysinger 27 | # 28 | # Copying and distribution of this file, with or without modification, are 29 | # permitted in any medium without royalty provided the copyright notice 30 | # and this notice are preserved. This file is offered as-is, without any 31 | # warranty. 32 | 33 | #serial 1 34 | 35 | AC_DEFUN([AX_REQUIRE_DEFINED], [dnl 36 | m4_ifndef([$1], [m4_fatal([macro ]$1[ is not defined; is a m4 file missing?])]) 37 | ])dnl AX_REQUIRE_DEFINED 38 | -------------------------------------------------------------------------------- /tcpbw-client-c/src/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Copyright (c) 2018,2019 NIC.br 2 | ## 3 | ## This program is free software: you can redistribute it and/or modify 4 | ## it under the terms of the GNU General Public License as published by 5 | ## the Free Software Foundation, either version 3 of the License, or 6 | ## (at your option) any later version. In every case, additional 7 | ## restrictions and permissions apply, refer to the COPYING file in the 8 | ## program Source for details. 9 | ## 10 | ## This program is distributed in the hope that it will be useful, but 11 | ## WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | ## General Public License and the COPYING file in the program Source 14 | ## for details. 15 | 16 | bin_PROGRAMS = tcpbwc 17 | 18 | tcpbwc_SOURCES = libubox/usock.h libubox/usock.c\ 19 | timespec.h retry.h \ 20 | tcpinfo.h \ 21 | tcpbwc.h simet_err.h \ 22 | logger.h \ 23 | report.h report.c \ 24 | tcpbwc-tcp.c tcpbwc.c 25 | 26 | tcpbwc_CPPFLAGS = @LIBCURL_CPPFLAGS@ 27 | tcpbwc_CFLAGS = -I .. -pthread -L json 28 | tcpbwc_LDFLAGS = -pthread -L json 29 | tcpbwc_LDADD = ${JSON_LIBS} @LIBCURL@ 30 | 31 | -------------------------------------------------------------------------------- /tcpbw-client-c/src/libubox/usock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * usock - socket helper functions 3 | * 4 | * Copyright (C) 2010 Steven Barth 5 | * Copyright (C) 2011-2012 Felix Fietkau 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | */ 19 | #ifndef USOCK_H_ 20 | #define USOCK_H_ 21 | 22 | #define USOCK_TCP 0 23 | #define USOCK_UDP 1 24 | 25 | #define USOCK_SERVER 0x0100 26 | #define USOCK_NOCLOEXEC 0x0200 27 | #define USOCK_NONBLOCK 0x0400 28 | #define USOCK_NUMERIC 0x0800 29 | #define USOCK_IPV6ONLY 0x2000 30 | #define USOCK_IPV4ONLY 0x4000 31 | #define USOCK_UNIX 0x8000 32 | 33 | const char *usock_port(int port); 34 | int usock(int type, const char *host, const char *service); 35 | int usock_inet_timeout(int type, const char *host, const char *service, 36 | void *addr, int timeout); 37 | static inline int 38 | usock_inet(int type, const char *host, const char *service, void *addr) 39 | { 40 | return usock_inet_timeout(type, host, service, addr, -1); 41 | } 42 | 43 | /** 44 | * Wait for a socket to become ready. 45 | * 46 | * This may be useful for users of USOCK_NONBLOCK to wait (with a timeout) 47 | * for a socket. 48 | * 49 | * @param fd file descriptor of socket 50 | * @param msecs timeout in microseconds 51 | */ 52 | int usock_wait_ready(int fd, int msecs); 53 | 54 | #endif /* USOCK_H_ */ 55 | -------------------------------------------------------------------------------- /tcpbw-client-c/src/logger.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018,2019 NIC.br 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. In every case, additional 8 | * restrictions and permissions apply, refer to the COPYING file in the 9 | * program Source for details. 10 | * 11 | * This program is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License and the COPYING file in the program Source 15 | * for details. 16 | */ 17 | 18 | #ifndef LOGGER_H_ 19 | #define LOGGER_H_ 20 | 21 | #include 22 | 23 | extern int log_level; /* 0: errors; 1: quiet; 2: normal; 3: debug/verbose ; 4: trace */ 24 | extern const char *progname; 25 | 26 | #define MSG_ALWAYS 0 27 | #define MSG_IMPORTANT 1 28 | #define MSG_NORMAL 2 29 | #define MSG_DEBUG 3 30 | #define MSG_TRACE 4 31 | 32 | #define print_msg_u(format, arg...) \ 33 | do { fflush(stdout); fprintf(stderr, "%s: " format "\n", progname, ## arg); } while (0) 34 | 35 | #define print_msg(level, format, arg...) \ 36 | do { \ 37 | if (log_level >= (level)) { \ 38 | fflush(stdout); \ 39 | fprintf(stderr, "%s: " format "\n", progname, ## arg); \ 40 | } \ 41 | } while (0) 42 | 43 | #define print_err(format, arg...) \ 44 | do { fflush(stdout); fprintf(stderr, "%s: error: " format "\n", progname, ## arg); } while (0) 45 | 46 | #define print_warn(format, arg...) \ 47 | do { fflush(stdout); fprintf(stderr, "%s: warning: " format "\n", progname, ## arg); } while (0) 48 | 49 | #endif /* LOGGER_H_ */ 50 | -------------------------------------------------------------------------------- /tcpbw-client-c/src/retry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Retry macros for EINTR, EAGAIN, EWOULDBLOCK 3 | * Copyright (c) 2024 NIC.br 4 | * 5 | * SPDX-License-Identifier: BSD-3-CLAUSE 6 | */ 7 | 8 | #ifndef SRETRY_H_ 9 | #define SRETRY_H_ 10 | 11 | #include 12 | 13 | #define MAXIMUM_SYSCALL_RETRIES 50 14 | #define MAXIMUM_GAI_RETRIES 5 15 | 16 | #define RETRY_EINTR(x) ({ \ 17 | typeof(x) _r; \ 18 | char _tries = MAXIMUM_SYSCALL_RETRIES; \ 19 | do { \ 20 | _r = (x); \ 21 | } while (_r == -1 && errno == EINTR && (--_tries) > 0); \ 22 | _r; \ 23 | }) 24 | 25 | #define RETRY_GAI(x) ({ \ 26 | char _tries = MAXIMUM_GAI_RETRIES; \ 27 | int _r; \ 28 | do { \ 29 | _r = (x); \ 30 | } while (( (_r == EAI_SYSTEM && errno == EINTR) || (_r == EAI_AGAIN)) \ 31 | && (--_tries) > 0); \ 32 | _r; \ 33 | }) 34 | 35 | #endif /* SRETRY_H_ */ 36 | /* vim: set et ts=8 sw=4 : */ 37 | -------------------------------------------------------------------------------- /tcpbw-client-c/version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # one-level subproject version handler 3 | # Copyright (c) 2018,2019 NIC.br 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. In every case, additional 9 | # restrictions and permissions apply, refer to the COPYING file in the 10 | # program Source for details. 11 | # 12 | # This program is distributed in the hope that it will be useful, but 13 | # WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | # General Public License and the COPYING file in the program Source 16 | # for details. 17 | 18 | GIT_VER= 19 | ME=$(realpath -q -e "$0") 20 | BME=$(dirname "$ME") 21 | 22 | exiterr() { 23 | echo "unknown" 24 | exit 1 25 | } 26 | 27 | cd "$BME" || exiterr 28 | if git rev-parse --git-dir >/dev/null 2>&1 ; then 29 | [ -n "$(git rev-parse --show-prefix 2>/dev/null)" ] && cd .. 30 | [ -z "$(git rev-parse --show-prefix 2>/dev/null)" ] && \ 31 | GIT_VER=$(git describe --dirty=+ --abbrev=10 --tags --long --match 'v*' --always 2>/dev/null) 32 | fi 33 | [ -z "$GIT_VER" ] && GIT_VER=$(cat version 2>/dev/null || cat ../version 2>/dev/null) 34 | [ -z "$GIT_VER" ] && exiterr 35 | echo "$GIT_VER" 36 | : 37 | -------------------------------------------------------------------------------- /twamp-client-c/.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | Makefile.in 3 | aclocal.m4 4 | autom4te.cache/ 5 | compile 6 | config.guess 7 | config.log 8 | config.status 9 | config.sub 10 | configure 11 | depcomp 12 | install-sh 13 | missing 14 | src/.deps/ 15 | src/Makefile 16 | src/Makefile.in 17 | stamp-h1 18 | twampc_config.h 19 | twampc_config.h.in 20 | version 21 | err.log 22 | src/*.o 23 | src/twampc -------------------------------------------------------------------------------- /twamp-client-c/AUTHORS: -------------------------------------------------------------------------------- 1 | Main authors: 2 | NIC.br - Núcleo de Informação e Coordenação do Ponto BR 3 | * Fábio Nokai 4 | * Henrique de Moraes Holschuh 5 | * Holger Wiehen 6 | -------------------------------------------------------------------------------- /twamp-client-c/ChangeLog: -------------------------------------------------------------------------------- 1 | * Nothing yet 2 | -------------------------------------------------------------------------------- /twamp-client-c/Dockerfile: -------------------------------------------------------------------------------- 1 | # Production dockerfile 2 | 3 | # Build image 4 | FROM alpine:3.7 as builder 5 | RUN apk update 6 | RUN apk add automake autoconf g++ make libtool cmake 7 | RUN apk add json-c-dev 8 | RUN addgroup -S src ; adduser -S build -D -G src 9 | COPY --chown=build:src . /usr/src/twamp-client-c/ 10 | WORKDIR /usr/src/twamp-client-c/twamp-src 11 | USER build:src 12 | RUN ./autogen.sh && ./configure && make 13 | USER root 14 | RUN make install 15 | 16 | # Exec image 17 | FROM alpine:3.7 18 | RUN apk update --no-cache ; apk add json-c 19 | COPY --from=builder /usr/local/bin/* /opt/simet/ 20 | WORKDIR /opt/simet 21 | ENTRYPOINT ["/opt/simet/twampc"] 22 | CMD ["-h localhost"] 23 | 24 | -------------------------------------------------------------------------------- /twamp-client-c/Makefile.am: -------------------------------------------------------------------------------- 1 | ## 2 | ## Makefile.am for twampc 3 | ## Copyright (c) 2018,2019 NIC.br 4 | ## 5 | ## This program is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. In every case, additional 9 | ## restrictions and permissions apply, refer to the COPYING file in the 10 | ## program Source for details. 11 | ## 12 | ## This program is distributed in the hope that it will be useful, but 13 | ## WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | ## General Public License and the COPYING file in the program Source 16 | ## for details. 17 | 18 | SUBDIRS = src 19 | 20 | EXTRA_DIST = autogen.sh version version.sh 21 | 22 | dist-local: version 23 | 24 | version: $(top_srcdir)/version.sh 25 | $(top_srcdir)/version.sh > version 26 | -------------------------------------------------------------------------------- /twamp-client-c/NEWS: -------------------------------------------------------------------------------- 1 | No news is good news 2 | -------------------------------------------------------------------------------- /twamp-client-c/README: -------------------------------------------------------------------------------- 1 | 2 | 3 | Source code structure: 4 | 5 |
6 | m4/ - autotools macros 7 | src/ - TWAMP client module 8 | -------------------------------------------------------------------------------- /twamp-client-c/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (c) 2018,2019 NIC.br 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. In every case, additional 8 | # restrictions and permissions apply, refer to the COPYING file in the 9 | # program Source for details. 10 | # 11 | # This program is distributed in the hope that it will be useful, but 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License and the COPYING file in the program Source 15 | # for details. 16 | 17 | ./version.sh >/dev/null 2>&1 || { 18 | echo "$0: missing version file and not in a worktree" >&2 19 | exit 1 20 | } 21 | autoreconf -i 22 | -------------------------------------------------------------------------------- /twamp-client-c/m4/ax_require_defined.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_require_defined.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_REQUIRE_DEFINED(MACRO) 8 | # 9 | # DESCRIPTION 10 | # 11 | # AX_REQUIRE_DEFINED is a simple helper for making sure other macros have 12 | # been defined and thus are available for use. This avoids random issues 13 | # where a macro isn't expanded. Instead the configure script emits a 14 | # non-fatal: 15 | # 16 | # ./configure: line 1673: AX_CFLAGS_WARN_ALL: command not found 17 | # 18 | # It's like AC_REQUIRE except it doesn't expand the required macro. 19 | # 20 | # Here's an example: 21 | # 22 | # AX_REQUIRE_DEFINED([AX_CHECK_LINK_FLAG]) 23 | # 24 | # LICENSE 25 | # 26 | # Copyright (c) 2014 Mike Frysinger 27 | # 28 | # Copying and distribution of this file, with or without modification, are 29 | # permitted in any medium without royalty provided the copyright notice 30 | # and this notice are preserved. This file is offered as-is, without any 31 | # warranty. 32 | 33 | #serial 1 34 | 35 | AC_DEFUN([AX_REQUIRE_DEFINED], [dnl 36 | m4_ifndef([$1], [m4_fatal([macro ]$1[ is not defined; is a m4 file missing?])]) 37 | ])dnl AX_REQUIRE_DEFINED 38 | -------------------------------------------------------------------------------- /twamp-client-c/src/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Copyright (c) 2018,2019 NIC.br 2 | ## 3 | ## This program is free software: you can redistribute it and/or modify 4 | ## it under the terms of the GNU General Public License as published by 5 | ## the Free Software Foundation, either version 3 of the License, or 6 | ## (at your option) any later version. In every case, additional 7 | ## restrictions and permissions apply, refer to the COPYING file in the 8 | ## program Source for details. 9 | ## 10 | ## This program is distributed in the hope that it will be useful, but 11 | ## WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | ## General Public License and the COPYING file in the program Source 14 | ## for details. 15 | 16 | bin_PROGRAMS = twampc 17 | 18 | twampc_SOURCES = libubox/usock.h libubox/usock.c \ 19 | retry.h logger.h simet_err.h \ 20 | twamp.h twamp.c \ 21 | base64.h base64.c \ 22 | message.h message.c \ 23 | timestamp.h timestamp.c \ 24 | timespec.h \ 25 | report.h report.c \ 26 | twampc.c 27 | twampc_CFLAGS = -I .. -pthread -L json 28 | twampc_LDFLAGS = -pthread -L json 29 | twampc_LDADD = ${JSON_LIBS} 30 | 31 | check_PROGRAMS = base64_test 32 | base64_test_SOURCES = base64.h base64.c base64_test.c 33 | 34 | #valgrind: twampc 35 | # valgrind --leak-check=full --track-origins=yes --xml-file=twampc_log.xml --xml=yes ./$(TWAMP_CLI) 36 | # valkyrie --view-log ./twampc_log.xml 37 | 38 | #clean: 39 | # rm -f *.o 40 | # rm -f $(TWAMP_CLI) 41 | # rm -f twampc_log.xml 42 | -------------------------------------------------------------------------------- /twamp-client-c/src/libubox/usock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * usock - socket helper functions 3 | * 4 | * Copyright (C) 2010 Steven Barth 5 | * Copyright (C) 2011-2012 Felix Fietkau 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | */ 19 | #ifndef USOCK_H_ 20 | #define USOCK_H_ 21 | 22 | #define USOCK_TCP 0 23 | #define USOCK_UDP 1 24 | 25 | #define USOCK_SERVER 0x0100 26 | #define USOCK_NOCLOEXEC 0x0200 27 | #define USOCK_NONBLOCK 0x0400 28 | #define USOCK_NUMERIC 0x0800 29 | #define USOCK_IPV6ONLY 0x2000 30 | #define USOCK_IPV4ONLY 0x4000 31 | #define USOCK_UNIX 0x8000 32 | 33 | const char *usock_port(int port); 34 | int usock(int type, const char *host, const char *service); 35 | int usock_inet_timeout(int type, const char *host, const char *service, 36 | void *addr, int timeout); 37 | static inline int 38 | usock_inet(int type, const char *host, const char *service, void *addr) 39 | { 40 | return usock_inet_timeout(type, host, service, addr, -1); 41 | } 42 | 43 | /** 44 | * Wait for a socket to become ready. 45 | * 46 | * This may be useful for users of USOCK_NONBLOCK to wait (with a timeout) 47 | * for a socket. 48 | * 49 | * @param fd file descriptor of socket 50 | * @param msecs timeout in microseconds 51 | */ 52 | int usock_wait_ready(int fd, int msecs); 53 | 54 | #endif /* USOCK_H_ */ 55 | -------------------------------------------------------------------------------- /twamp-client-c/src/logger.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018,2019 NIC.br 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. In every case, additional 8 | * restrictions and permissions apply, refer to the COPYING file in the 9 | * program Source for details. 10 | * 11 | * This program is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License and the COPYING file in the program Source 15 | * for details. 16 | */ 17 | 18 | #ifndef LOGGER_H_ 19 | #define LOGGER_H_ 20 | 21 | #include 22 | 23 | extern int log_level; /* 0: errors; 1: quiet; 2: normal; 3: debug/verbose ; 4: trace */ 24 | extern const char *progname; 25 | 26 | #define MSG_ALWAYS 0 27 | #define MSG_IMPORTANT 1 28 | #define MSG_NORMAL 2 29 | #define MSG_DEBUG 3 30 | #define MSG_TRACE 4 31 | 32 | #define print_msg_u(format, arg...) \ 33 | do { fflush(stdout); fprintf(stderr, "%s: " format "\n", progname, ## arg); } while (0) 34 | 35 | #define print_msg(level, format, arg...) \ 36 | do { \ 37 | if (log_level >= (level)) { \ 38 | fflush(stdout); \ 39 | fprintf(stderr, "%s: " format "\n", progname, ## arg); \ 40 | } \ 41 | } while (0) 42 | 43 | #define print_err(format, arg...) \ 44 | do { fflush(stdout); fprintf(stderr, "%s: error: " format "\n", progname, ## arg); } while (0) 45 | 46 | #define print_warn(format, arg...) \ 47 | do { fflush(stdout); fprintf(stderr, "%s: warning: " format "\n", progname, ## arg); } while (0) 48 | 49 | #endif /* LOGGER_H_ */ 50 | -------------------------------------------------------------------------------- /twamp-client-c/src/retry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Retry macros for EINTR, EAGAIN, EWOULDBLOCK 3 | * Copyright (c) 2024 NIC.br 4 | * 5 | * SPDX-License-Identifier: BSD-3-CLAUSE 6 | */ 7 | 8 | #ifndef SRETRY_H_ 9 | #define SRETRY_H_ 10 | 11 | #include 12 | 13 | #define MAXIMUM_SYSCALL_RETRIES 50 14 | #define MAXIMUM_GAI_RETRIES 5 15 | 16 | #define RETRY_EINTR(x) ({ \ 17 | typeof(x) _r; \ 18 | char _tries = MAXIMUM_SYSCALL_RETRIES; \ 19 | do { \ 20 | _r = (x); \ 21 | } while (_r == -1 && errno == EINTR && (--_tries) > 0); \ 22 | _r; \ 23 | }) 24 | 25 | #define RETRY_GAI(x) ({ \ 26 | char _tries = MAXIMUM_GAI_RETRIES; \ 27 | int _r; \ 28 | do { \ 29 | _r = (x); \ 30 | } while (( (_r == EAI_SYSTEM && errno == EINTR) || (_r == EAI_AGAIN)) \ 31 | && (--_tries) > 0); \ 32 | _r; \ 33 | }) 34 | 35 | #endif /* SRETRY_H_ */ 36 | /* vim: set et ts=8 sw=4 : */ 37 | -------------------------------------------------------------------------------- /twamp-client-c/version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # one-level subproject version handler 3 | # Copyright (c) 2018,2019 NIC.br 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. In every case, additional 9 | # restrictions and permissions apply, refer to the COPYING file in the 10 | # program Source for details. 11 | # 12 | # This program is distributed in the hope that it will be useful, but 13 | # WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | # General Public License and the COPYING file in the program Source 16 | # for details. 17 | 18 | GIT_VER= 19 | ME=$(realpath -q -e "$0") 20 | BME=$(dirname "$ME") 21 | 22 | exiterr() { 23 | echo "unknown" 24 | exit 1 25 | } 26 | 27 | cd "$BME" || exiterr 28 | if git rev-parse --git-dir >/dev/null 2>&1 ; then 29 | [ -n "$(git rev-parse --show-prefix 2>/dev/null)" ] && cd .. 30 | [ -z "$(git rev-parse --show-prefix 2>/dev/null)" ] && \ 31 | GIT_VER=$(git describe --dirty=+ --abbrev=10 --tags --long --match 'v*' --always 2>/dev/null) 32 | fi 33 | [ -z "$GIT_VER" ] && GIT_VER=$(cat version 2>/dev/null || cat ../version 2>/dev/null) 34 | [ -z "$GIT_VER" ] && exiterr 35 | echo "$GIT_VER" 36 | : 37 | -------------------------------------------------------------------------------- /version: -------------------------------------------------------------------------------- 1 | v0.18.12.2 2 | -------------------------------------------------------------------------------- /version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # top-level version handler 3 | # 4 | # Copyright (c) 2018,2019 NIC.br 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. In every case, additional 10 | # restrictions and permissions apply, refer to the COPYING file in the 11 | # program Source for details. 12 | # 13 | # This program is distributed in the hope that it will be useful, but 14 | # WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | # General Public License and the COPYING file in the program Source 17 | # for details. 18 | 19 | GIT_VER= 20 | ME=$(realpath -q -e "$0") 21 | BME=$(dirname "$ME") 22 | 23 | exiterr() { 24 | echo "unknown" 25 | exit 1 26 | } 27 | 28 | cd "$BME" || exiterr 29 | if $(git rev-parse --git-dir >/dev/null 2>&1) && [ -z "$(git rev-parse --show-prefix 2>/dev/null)" ] ; then 30 | GIT_VER=$(git describe --dirty=+ --abbrev=10 --tags --long --match 'v*' --always 2>/dev/null) 31 | fi 32 | [ -z "$GIT_VER" ] && GIT_VER=$(cat version) 33 | [ -z "$GIT_VER" ] && exiterr 34 | echo "$GIT_VER" 35 | : 36 | --------------------------------------------------------------------------------