├── .editorconfig ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.yml │ └── feature-request.md ├── builder_containers │ ├── README.md │ ├── entware-aarch64-3.10.Dockerfile │ ├── entware-armv7-2.6.Dockerfile │ ├── entware-armv7-3.2.Dockerfile │ ├── entware-mips-3.4.Dockerfile │ ├── entware-mipsel-3.4.Dockerfile │ ├── entware-x64-3.2.Dockerfile │ ├── entware-x86-2.6.Dockerfile │ ├── kernel-3.0.101.Dockerfile │ ├── kernel-3.10.108.Dockerfile │ ├── kernel-4.19.322.Dockerfile │ ├── kernel-4.4.302.Dockerfile │ ├── kernel-5.15.167.Dockerfile │ ├── kernel-5.4.284.Dockerfile │ └── kernel-6.6.52.Dockerfile └── workflows │ ├── build-ci.yml │ └── test.yml ├── .gitignore ├── .gitmodules ├── Kbuild ├── LICENSE ├── Makefile ├── Padavan.md ├── README.md ├── deps ├── cyclone │ ├── Makefile │ ├── aes.c │ ├── cpu_endian.c │ ├── ecb.c │ ├── gcm.c │ ├── hkdf.c │ ├── hmac.c │ ├── include │ │ ├── aead │ │ │ └── gcm.h │ │ ├── cipher │ │ │ └── aes.h │ │ ├── cipher_modes │ │ │ └── ecb.h │ │ ├── compiler_port.h │ │ ├── core │ │ │ ├── crypto.h │ │ │ └── crypto_legacy.h │ │ ├── cpu_endian.h │ │ ├── crypto_config.h │ │ ├── error.h │ │ ├── hash │ │ │ ├── hash_algorithms.h │ │ │ └── sha256.h │ │ ├── kdf │ │ │ └── hkdf.h │ │ ├── mac │ │ │ └── hmac.h │ │ └── os_port.h │ └── sha256.c ├── libmnl │ ├── .gitignore │ ├── COPYING │ ├── Make_global.am │ ├── Makefile.am │ ├── README │ ├── autogen.sh │ ├── configure.ac │ ├── doxygen │ │ ├── .gitignore │ │ ├── Makefile.am │ │ ├── doxygen.cfg.in │ │ └── finalize_manpages.sh │ ├── examples │ │ ├── Makefile.am │ │ ├── genl │ │ │ ├── .gitignore │ │ │ ├── Makefile.am │ │ │ ├── genl-family-get.c │ │ │ └── genl-group-events.c │ │ ├── kobject │ │ │ ├── .gitignore │ │ │ ├── Makefile.am │ │ │ └── kobject-event.c │ │ ├── netfilter │ │ │ ├── .gitignore │ │ │ ├── Makefile.am │ │ │ ├── nf-log.c │ │ │ ├── nf-queue.c │ │ │ ├── nfct-create-batch.c │ │ │ ├── nfct-daemon.c │ │ │ ├── nfct-dump.c │ │ │ └── nfct-event.c │ │ └── rtnl │ │ │ ├── .gitignore │ │ │ ├── Makefile.am │ │ │ ├── rtnl-addr-add.c │ │ │ ├── rtnl-addr-dump.c │ │ │ ├── rtnl-link-can.c │ │ │ ├── rtnl-link-dump.c │ │ │ ├── rtnl-link-dump2.c │ │ │ ├── rtnl-link-dump3.c │ │ │ ├── rtnl-link-event.c │ │ │ ├── rtnl-link-set.c │ │ │ ├── rtnl-neigh-dump.c │ │ │ ├── rtnl-route-add.c │ │ │ ├── rtnl-route-dump.c │ │ │ └── rtnl-route-event.c │ ├── include │ │ ├── Makefile.am │ │ ├── libmnl │ │ │ ├── Makefile.am │ │ │ └── libmnl.h │ │ └── linux │ │ │ ├── Makefile.am │ │ │ ├── can.h │ │ │ ├── can │ │ │ ├── Makefile.am │ │ │ └── netlink.h │ │ │ ├── netfilter │ │ │ ├── Makefile.am │ │ │ └── nfnetlink_conntrack.h │ │ │ ├── netlink.h │ │ │ └── socket.h │ ├── libmnl.pc.in │ ├── m4 │ │ ├── .gitignore │ │ └── gcc4_visibility.m4 │ └── src │ │ ├── Makefile.am │ │ ├── attr.c │ │ ├── callback.c │ │ ├── internal.h │ │ ├── libmnl.map │ │ ├── nlmsg.c │ │ └── socket.c ├── libnetfilter_queue │ ├── .gitignore │ ├── COPYING │ ├── Make_global.am │ ├── Makefile.am │ ├── autogen.sh │ ├── configure.ac │ ├── doxygen │ │ ├── Makefile.am │ │ ├── build_man.sh │ │ └── doxygen.cfg.in │ ├── examples │ │ ├── Makefile.am │ │ └── nf-queue.c │ ├── include │ │ ├── Makefile.am │ │ ├── libnetfilter_queue │ │ │ ├── Makefile.am │ │ │ ├── libnetfilter_queue.h │ │ │ ├── libnetfilter_queue_icmp.h │ │ │ ├── libnetfilter_queue_ipv4.h │ │ │ ├── libnetfilter_queue_ipv6.h │ │ │ ├── libnetfilter_queue_tcp.h │ │ │ ├── libnetfilter_queue_udp.h │ │ │ ├── linux_nfnetlink_queue.h │ │ │ └── pktbuff.h │ │ └── linux │ │ │ ├── Makefile.am │ │ │ └── netfilter │ │ │ ├── Makefile.am │ │ │ └── nfnetlink_queue.h │ ├── libnetfilter_queue.pc.in │ ├── m4 │ │ ├── .gitignore │ │ └── gcc4_visibility.m4 │ ├── src │ │ ├── Makefile.am │ │ ├── extra │ │ │ ├── checksum.c │ │ │ ├── icmp.c │ │ │ ├── ipv4.c │ │ │ ├── ipv6.c │ │ │ ├── pktbuff.c │ │ │ ├── tcp.c │ │ │ └── udp.c │ │ ├── internal.h │ │ ├── libnetfilter_queue.c │ │ └── nlmsg.c │ └── utils │ │ ├── .gitignore │ │ ├── Makefile.am │ │ └── nfqnl_test.c └── libnfnetlink │ ├── .gitignore │ ├── COPYING │ ├── Make_global.am │ ├── Makefile.am │ ├── README │ ├── autogen.sh │ ├── configure.ac │ ├── doxygen.cfg.in │ ├── include │ ├── Makefile.am │ ├── libnfnetlink │ │ ├── Makefile.am │ │ ├── libnfnetlink.h │ │ ├── linux_nfnetlink.h │ │ └── linux_nfnetlink_compat.h │ └── linux_list.h │ ├── libnfnetlink.pc.in │ ├── m4 │ └── .gitignore │ ├── src │ ├── Makefile.am │ ├── iftable.c │ ├── iftable.h │ ├── libnfnetlink.c │ ├── nfnl.version │ ├── rtnl.c │ └── rtnl.h │ └── utils │ ├── .gitignore │ ├── Makefile.am │ └── iftest.c ├── kmake.mk ├── src ├── args.c ├── args.h ├── config.h ├── getopt.c ├── getopt.h ├── inet_ntop.c ├── kytunblock.c ├── logging.h ├── mangle.c ├── mangle.h ├── quic.c ├── quic.h ├── quic_crypto.c ├── raw_replacements.h ├── tls.c ├── tls.h ├── trie.c ├── trie.h ├── types.h ├── utils.c ├── utils.h └── youtubeUnblock.c ├── test ├── main_fn.c ├── quic.c ├── tls.c ├── trie.c └── unity │ ├── unity.c │ ├── unity.h │ ├── unity_fixture.c │ ├── unity_fixture.h │ ├── unity_fixture_internals.h │ ├── unity_internals.h │ ├── unity_memory.c │ └── unity_memory.h ├── uspace.mk └── youtubeUnblock.service /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | indent_size = 8 6 | tab_width = 8 7 | 8 | [*.yml] 9 | indent_style = space 10 | indent_size = 2 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | name: Bug report 2 | description: Use this issue template when you are pretty sure here is a bug. Make sure the trouble you are experiencing haven't been already reported earlier and haven't been talked about in discussions. 3 | body: 4 | - type: markdown 5 | attributes: 6 | value: | 7 | Use this issue template when you are pretty sure here is a bug. 8 | Make sure the trouble you are experiencing haven't been already reported earlier and haven't been talked about in [discussions](https://github.com/Waujito/youtubeUnblock/discussions). 9 | 10 | Note, that *bugs* are internal program errors: crashes, freezes and other types of undefined behavior. You may also report problems with routers infrastructure here, but **NOT** questions like *My router doesn't work help please*. Your questions and other stuff with custom routers setup should be discussed [here](https://github.com/Waujito/youtubeUnblock/discussions/172) 11 | 12 | Discuss problems like *youtube doesn't unblock* [here](https://github.com/Waujito/youtubeUnblock/discussions/173) 13 | - type: textarea 14 | id: bug-report 15 | attributes: 16 | label: Bug description 17 | validations: 18 | required: true 19 | 20 | - type: input 21 | id: linux-distro 22 | attributes: 23 | label: Linux distribution 24 | description: Pass here your linux distro e.g. OpenWRT, Entware, Merlin, Padavan, Ubuntu, Debian 25 | validations: 26 | required: false 27 | 28 | - type: textarea 29 | id: architecture 30 | attributes: 31 | label: Device architecture 32 | description: Pass here the architecture of your device. (On openwrt do `cat /etc/openwrt_release`, on other systems `lscpu` or `cat /proc/cpuinfo`) 33 | validations: 34 | required: false 35 | 36 | - type: textarea 37 | id: configs 38 | attributes: 39 | label: Configuration 40 | description: Pass here the configuration of youtubeUnblock being used. You may pass output of `cat /etc/config/youtubeUnblock` on OpenWRT or raw flags of youtubeUnblock. 41 | validations: 42 | required: false 43 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /.github/builder_containers/README.md: -------------------------------------------------------------------------------- 1 | This directory contains dockerfiles for large docker containers. This allows not to rebuild binaries every build and not to utilize cache. 2 | -------------------------------------------------------------------------------- /.github/builder_containers/entware-aarch64-3.10.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM waujito/entware_builder 2 | RUN git clone --depth 1 https://github.com/Entware/Entware.git 3 | WORKDIR /home/me/Entware 4 | RUN make package/symlinks 5 | RUN cp -v configs/aarch64-3.10.config .config 6 | RUN make -j$(nproc) toolchain/install 7 | -------------------------------------------------------------------------------- /.github/builder_containers/entware-armv7-2.6.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM waujito/entware_builder 2 | RUN git clone --depth 1 https://github.com/Entware/Entware.git -b k2.6 3 | WORKDIR /home/me/Entware 4 | RUN make package/symlinks 5 | RUN cp -v configs/armv7-2.6.config .config 6 | RUN make -j$(nproc) toolchain/install 7 | -------------------------------------------------------------------------------- /.github/builder_containers/entware-armv7-3.2.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM waujito/entware_builder 2 | RUN git clone --depth 1 https://github.com/Entware/Entware.git 3 | WORKDIR /home/me/Entware 4 | RUN make package/symlinks 5 | RUN cp -v configs/armv7-3.2.config .config 6 | RUN make -j$(nproc) toolchain/install 7 | -------------------------------------------------------------------------------- /.github/builder_containers/entware-mips-3.4.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM waujito/entware_builder 2 | RUN git clone --depth 1 https://github.com/Entware/Entware.git 3 | WORKDIR /home/me/Entware 4 | RUN make package/symlinks 5 | RUN cp -v configs/mips-3.4.config .config 6 | RUN make -j$(nproc) toolchain/install 7 | -------------------------------------------------------------------------------- /.github/builder_containers/entware-mipsel-3.4.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM waujito/entware_builder 2 | RUN git clone --depth 1 https://github.com/Entware/Entware.git 3 | WORKDIR /home/me/Entware 4 | RUN make package/symlinks 5 | RUN cp -v configs/mipsel-3.4.config .config 6 | RUN make -j$(nproc) toolchain/install 7 | -------------------------------------------------------------------------------- /.github/builder_containers/entware-x64-3.2.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM waujito/entware_builder 2 | RUN git clone --depth 1 https://github.com/Entware/Entware.git 3 | WORKDIR /home/me/Entware 4 | RUN make package/symlinks 5 | RUN cp -v configs/x64-3.2.config .config 6 | RUN make -j$(nproc) toolchain/install 7 | -------------------------------------------------------------------------------- /.github/builder_containers/entware-x86-2.6.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM waujito/entware_builder 2 | RUN git clone --depth 1 https://github.com/Entware/Entware.git -b k2.6 3 | WORKDIR /home/me/Entware 4 | RUN make package/symlinks 5 | RUN cp -v configs/x86-2.6.config .config 6 | RUN make -j$(nproc) toolchain/install 7 | -------------------------------------------------------------------------------- /.github/builder_containers/kernel-3.0.101.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:14.04 2 | 3 | RUN apt update && apt install -y build-essential flex bc bison libelf-dev elfutils libssl-dev wget 4 | 5 | RUN wget https://cdn.kernel.org/pub/linux/kernel/v3.x/linux-3.0.101.tar.xz -O kernel.tar.xz 6 | RUN tar -xf kernel.tar.xz 7 | RUN rm -f kernel.tar.xz 8 | RUN /bin/bash -c "mv linux-* linux" 9 | 10 | WORKDIR /linux 11 | RUN make defconfig 12 | RUN make -j$(nproc) 13 | -------------------------------------------------------------------------------- /.github/builder_containers/kernel-3.10.108.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:16.04 2 | 3 | RUN apt update && apt install -y build-essential flex bc bison libelf-dev elfutils libssl-dev wget 4 | 5 | RUN wget https://cdn.kernel.org/pub/linux/kernel/v3.x/linux-3.10.108.tar.xz -O kernel.tar.xz 6 | RUN tar -xf kernel.tar.xz 7 | RUN rm -f kernel.tar.xz 8 | RUN /bin/bash -c "mv linux-* linux" 9 | 10 | WORKDIR /linux 11 | RUN make defconfig 12 | RUN make -j$(nproc) 13 | -------------------------------------------------------------------------------- /.github/builder_containers/kernel-4.19.322.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:24.04 2 | 3 | RUN apt update && apt install -y build-essential flex bc bison libelf-dev elfutils libssl-dev wget 4 | 5 | RUN wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.19.322.tar.xz -O kernel.tar.xz 6 | RUN tar -xf kernel.tar.xz 7 | RUN rm -f kernel.tar.xz 8 | RUN /bin/bash -c "mv linux-* linux" 9 | 10 | WORKDIR /linux 11 | RUN make defconfig 12 | RUN make -j$(nproc) 13 | -------------------------------------------------------------------------------- /.github/builder_containers/kernel-4.4.302.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:24.04 2 | 3 | RUN apt update && apt install -y build-essential flex bc bison libelf-dev elfutils libssl-dev wget 4 | 5 | RUN wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.4.302.tar.xz -O kernel.tar.xz 6 | RUN tar -xf kernel.tar.xz 7 | RUN rm -f kernel.tar.xz 8 | RUN /bin/bash -c "mv linux-* linux" 9 | 10 | WORKDIR /linux 11 | RUN make defconfig 12 | RUN make -j$(nproc) 13 | -------------------------------------------------------------------------------- /.github/builder_containers/kernel-5.15.167.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:24.04 2 | 3 | RUN apt update && apt install -y build-essential flex bc bison libelf-dev elfutils libssl-dev wget 4 | 5 | RUN wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.167.tar.xz -O kernel.tar.xz 6 | RUN tar -xf kernel.tar.xz 7 | RUN rm -f kernel.tar.xz 8 | RUN /bin/bash -c "mv linux-* linux" 9 | 10 | WORKDIR /linux 11 | RUN make defconfig 12 | RUN make -j$(nproc) 13 | -------------------------------------------------------------------------------- /.github/builder_containers/kernel-5.4.284.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:24.04 2 | 3 | RUN apt update && apt install -y build-essential flex bc bison libelf-dev elfutils libssl-dev wget 4 | 5 | RUN wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.4.284.tar.xz -O kernel.tar.xz 6 | RUN tar -xf kernel.tar.xz 7 | RUN rm -f kernel.tar.xz 8 | RUN /bin/bash -c "mv linux-* linux" 9 | 10 | WORKDIR /linux 11 | RUN make defconfig 12 | RUN make -j$(nproc) 13 | -------------------------------------------------------------------------------- /.github/builder_containers/kernel-6.6.52.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:24.04 2 | 3 | RUN apt update && apt install -y build-essential flex bc bison libelf-dev elfutils libssl-dev wget 4 | 5 | RUN wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.6.52.tar.xz -O kernel.tar.xz 6 | RUN tar -xf kernel.tar.xz 7 | RUN rm -f kernel.tar.xz 8 | RUN /bin/bash -c "mv linux-* linux" 9 | 10 | WORKDIR /linux 11 | RUN make defconfig 12 | RUN make -j$(nproc) 13 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: "youtubeUnblock build test" 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | paths-ignore: 8 | - '.editorconfig' 9 | - '.gitignore' 10 | - 'LICENSE' 11 | - 'README.md' 12 | workflow_dispatch: 13 | pull_request: 14 | 15 | jobs: 16 | prepare: 17 | runs-on: ubuntu-latest 18 | outputs: 19 | version: ${{ steps.gh.outputs.version }} 20 | sha: ${{ steps.gh.outputs.sha }} 21 | steps: 22 | - name: Checkout 23 | uses: actions/checkout@v4 24 | with: 25 | ref: 'openwrt' 26 | 27 | - name: GH 28 | id: gh 29 | env: 30 | REPO: ${{ github.repository }} 31 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 32 | shell: bash 33 | run: | 34 | echo "version=$(cat youtubeUnblock/Makefile | grep PKG_VERSION | sed 's/PKG_VERSION:=//')" >> $GITHUB_OUTPUT 35 | if [[ "${{ github.event_name }}" != "pull_request" ]]; then 36 | echo "sha=$(echo ${GITHUB_SHA::7})" >> $GITHUB_OUTPUT 37 | else 38 | echo "sha=$(gh api repos/$REPO/commits/main --jq '.sha[:7]')" >> $GITHUB_OUTPUT 39 | fi 40 | 41 | build-static: 42 | needs: prepare 43 | name: build-static ${{ matrix.arch }} 44 | runs-on: ubuntu-latest 45 | strategy: 46 | matrix: 47 | arch: [x86_64] 48 | branch: [latest-stable] 49 | steps: 50 | - name: Checkout 51 | uses: actions/checkout@v4 52 | 53 | - name: Build 54 | id: build 55 | env: 56 | ARCH: ${{ matrix.arch }} 57 | VERSION: ${{ needs.prepare.outputs.version }} 58 | SHA: ${{ needs.prepare.outputs.sha }} 59 | shell: bash 60 | run: | 61 | make -j$(nproc) 62 | strip -s build/youtubeUnblock 63 | cp -va build/youtubeUnblock . 64 | tar -czvf static-youtubeUnblock-$VERSION-$SHA-$PLATFORM.tar.gz youtubeUnblock youtubeUnblock.service README.md 65 | 66 | - name: Upload artifacts 67 | if: steps.build.outcome == 'success' 68 | uses: actions/upload-artifact@v4 69 | with: 70 | name: static-youtubeUnblock-${{ matrix.arch }} 71 | path: ./**/static-youtubeUnblock*.tar.gz 72 | 73 | test: 74 | needs: prepare 75 | name: test 76 | runs-on: ubuntu-latest 77 | strategy: 78 | matrix: 79 | arch: [x86_64] 80 | branch: [latest-stable] 81 | steps: 82 | - name: Checkout 83 | uses: actions/checkout@v4 84 | 85 | - name: Build 86 | id: build 87 | shell: bash 88 | run: | 89 | make build_test -j$(nproc) 90 | 91 | - name: Test 92 | id: test 93 | run: 94 | ./build/testYoutubeUnblock 95 | 96 | build-kmod: 97 | needs: prepare 98 | name: build-kmod ${{ matrix.kernel_version }} 99 | runs-on: ubuntu-latest 100 | strategy: 101 | matrix: 102 | kernel_version: 103 | - 6.6.52 104 | - 5.15.167 105 | - 5.4.284 106 | - 4.19.322 107 | - 4.4.302 108 | - 3.10.108 109 | - 3.0.101 110 | steps: 111 | - name: Checkout 112 | uses: actions/checkout@v4 113 | 114 | - name: Build kernel module 115 | id: build 116 | env: 117 | VERSION: ${{ needs.prepare.outputs.version }} 118 | SHA: ${{ needs.prepare.outputs.sha }} 119 | shell: bash 120 | run: | 121 | docker run --rm -v ./:/youtubeUnblock -w /youtubeUnblock waujito/kernel-bins:${{ matrix.kernel_version }} make kmake KERNEL_BUILDER_MAKEDIR:=/linux 122 | tar -czvf kmod-youtubeUnblock-$VERSION-$SHA-linux-${{ matrix.kernel_version }}.tar.gz kyoutubeUnblock.ko 123 | 124 | - name: Upload artifacts 125 | if: steps.build.outcome == 'success' 126 | uses: actions/upload-artifact@v4 127 | with: 128 | name: kmod-youtubeUnblock-linux-${{ matrix.kernel_version }} 129 | path: ./**/kmod-youtubeUnblock*.tar.gz 130 | 131 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | compile_commands.json 2 | .cache 3 | build 4 | 5 | configure~ 6 | 7 | # Kernel module files 8 | *.o 9 | .* 10 | *.mod.* 11 | *.mod 12 | modules.order 13 | Module.symvers 14 | *.so 15 | *.ko 16 | *.a 17 | 18 | !/.github 19 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule ".github/builder_containers/entware_docker"] 2 | path = .github/builder_containers/entware_docker 3 | url = https://github.com/Entware/docker.git 4 | -------------------------------------------------------------------------------- /Kbuild: -------------------------------------------------------------------------------- 1 | obj-m := kyoutubeUnblock.o 2 | kyoutubeUnblock-objs := src/kytunblock.o src/mangle.o src/quic.o src/quic_crypto.o src/utils.o src/tls.o src/getopt.o src/inet_ntop.o src/args.o src/trie.o deps/cyclone/aes.o deps/cyclone/cpu_endian.o deps/cyclone/ecb.o deps/cyclone/gcm.o deps/cyclone/hkdf.o deps/cyclone/hmac.o deps/cyclone/sha256.o 3 | ccflags-y := -std=gnu99 -DKERNEL_SPACE -Wno-error -Wno-declaration-after-statement -I$(src)/src -I$(src)/deps/cyclone/include 4 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | USPACE_TARGETS := default all install uninstall dev run_dev 2 | KMAKE_TARGETS := kmake kload kunload kreload xmod xtclean 3 | 4 | PKG_VERSION := 1.0.0 5 | PKG_RELEASE := 10 6 | 7 | PKG_FULLVERSION := $(PKG_VERSION)-$(PKG_RELEASE) 8 | 9 | export PKG_VERSION PKG_RELEASE PKG_FULLVERSION 10 | 11 | .PHONY: $(USPACE_TARGETS) $(KMAKE_TARGETS) test build_test clean distclean kclean 12 | $(USPACE_TARGETS): 13 | @$(MAKE) -f uspace.mk $@ 14 | 15 | $(KMAKE_TARGETS): 16 | @$(MAKE) -f kmake.mk $@ 17 | 18 | build_test: 19 | -@$(MAKE) -f uspace.mk build_test 20 | 21 | test: 22 | -@$(MAKE) -f uspace.mk test 23 | 24 | clean: 25 | -@$(MAKE) -f uspace.mk clean 26 | 27 | distclean: clean 28 | -@$(MAKE) -f uspace.mk distclean 29 | 30 | 31 | kclean: 32 | -@$(MAKE) -f kmake.mk kclean 33 | -------------------------------------------------------------------------------- /Padavan.md: -------------------------------------------------------------------------------- 1 | ## Padavan 2 | На падаване есть раздел, доступный для записи (/etc/storage), и, докинув нужные модули, можно запустить youtubeUblock на уже установленной прошивке без USB. Установка самого youtubeUblock мало будет отличаться от классичкской установки. Наибольшая сложность заключается в получении модулей ядра специально для вашего роутера. 3 | 4 | **Версия youtubeUblock должна быть не меньше v1.0.0-rc4.** 5 | 6 | ### Сборка прошивки с модулями 7 | 8 | Необходимо собрать ядро с модулями nfqueue. Собирать можно у себя локально, а можно и в github actions (https://github.com/shvchk/padavan-builder-workflow) 9 | 10 | Добавить строки ниже в `padavan-ng/trunk/configs/boards/TPLINK/TL_C5-V4/kernel-3.4.x.config` (вместо TPLINK/TL_C5-V4 нужно выбрать свою модель): 11 | 12 | ```sh 13 | CONFIG_NETFILTER_NETLINK=m 14 | CONFIG_NETFILTER_NETLINK_QUEUE=m 15 | CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m 16 | CONFIG_IP_NF_QUEUE=m 17 | CONFIG_IP6_NF_QUEUE=m 18 | ``` 19 | 20 | Сборка 21 | ```sh 22 | cd padavan-ng/trunk 23 | cp configs/templates/tplink/tl_c5-v4.config .config 24 | ./build_firmware.sh 25 | ``` 26 | Если финальный размер превышает максимум, то можно отключить что-нибудь в .config, например FTP. 27 | 28 | После сборки необходимо установить прошивку на роутер. Подробнее в гитлабе падавана: https://gitlab.com/hadzhioglu/padavan-ng. Как устанавливать: https://4pda.to/forum/index.php?showtopic=975687&st=12980#Spoil-115912586-5 29 | 30 | Далее скачать youtubeUnblock, закинуть его на роутер, добавить правила фаервола и запустить. Можно скачивать static бинарник и запускать вручную, а можно загрузить entware на usb или в память, и поставить соответствующую версию youtubeUblock. 31 | -------------------------------------------------------------------------------- /deps/cyclone/Makefile: -------------------------------------------------------------------------------- 1 | SRCS := $(shell find -name "*.c") 2 | OBJS := $(SRCS:%.c=build/%.o) 3 | override CFLAGS += -Iinclude -Wno-pedantic 4 | LIBNAME := libcyclone.a 5 | CC := gcc 6 | 7 | 8 | run: $(OBJS) 9 | @echo "AR $(LIBNAME)" 10 | @ar rcs libcyclone.a $(OBJS) 11 | 12 | prep_dirs: 13 | mkdir -p build 14 | 15 | 16 | build/%.o: %.c prep_dirs 17 | $(CC) $(CFLAGS) -c -o $@ $< 18 | 19 | clean: 20 | @rm $(OBJS) || true 21 | @rm libcyclone.a || true 22 | @rm -rf build || true 23 | 24 | 25 | -------------------------------------------------------------------------------- /deps/cyclone/cpu_endian.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file cpu_endian.c 3 | * @brief Byte order conversion 4 | * 5 | * @section License 6 | * 7 | * SPDX-License-Identifier: GPL-2.0-or-later 8 | * 9 | * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved. 10 | * 11 | * This program is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU General Public License 13 | * as published by the Free Software Foundation; either version 2 14 | * of the License, or (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software Foundation, 23 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 24 | * 25 | * @author Oryx Embedded SARL (www.oryx-embedded.com) 26 | * @version 2.4.4 27 | **/ 28 | 29 | //Dependencies 30 | #include "cpu_endian.h" 31 | 32 | 33 | /** 34 | * @brief Reverse the byte order of a 16-bit word 35 | * @param[in] value 16-bit value 36 | * @return 16-bit value with byte order swapped 37 | **/ 38 | 39 | uint16_t swapInt16(uint16_t value) 40 | { 41 | return SWAPINT16(value); 42 | } 43 | 44 | 45 | /** 46 | * @brief Reverse the byte order of a 32-bit word 47 | * @param[in] value 32-bit value 48 | * @return 32-bit value with byte order swapped 49 | **/ 50 | 51 | uint32_t swapInt32(uint32_t value) 52 | { 53 | return SWAPINT32(value); 54 | } 55 | 56 | 57 | /** 58 | * @brief Reverse the byte order of a 64-bit word 59 | * @param[in] value 64-bit value 60 | * @return 64-bit value with byte order swapped 61 | **/ 62 | 63 | uint64_t swapInt64(uint64_t value) 64 | { 65 | return SWAPINT64(value); 66 | } 67 | 68 | 69 | /** 70 | * @brief Reverse bit order in a 4-bit word 71 | * @param[in] value 4-bit value 72 | * @return 4-bit value with bit order reversed 73 | **/ 74 | 75 | uint8_t reverseInt4(uint8_t value) 76 | { 77 | value = ((value & 0x0C) >> 2) | ((value & 0x03) << 2); 78 | value = ((value & 0x0A) >> 1) | ((value & 0x05) << 1); 79 | 80 | return value; 81 | } 82 | 83 | 84 | /** 85 | * @brief Reverse bit order in a byte 86 | * @param[in] value 8-bit value 87 | * @return 8-bit value with bit order reversed 88 | **/ 89 | 90 | uint8_t reverseInt8(uint8_t value) 91 | { 92 | value = ((value & 0xF0) >> 4) | ((value & 0x0F) << 4); 93 | value = ((value & 0xCC) >> 2) | ((value & 0x33) << 2); 94 | value = ((value & 0xAA) >> 1) | ((value & 0x55) << 1); 95 | 96 | return value; 97 | } 98 | 99 | 100 | /** 101 | * @brief Reverse bit order in a 16-bit word 102 | * @param[in] value 16-bit value 103 | * @return 16-bit value with bit order reversed 104 | **/ 105 | 106 | uint16_t reverseInt16(uint16_t value) 107 | { 108 | value = ((value & 0xFF00) >> 8) | ((value & 0x00FF) << 8); 109 | value = ((value & 0xF0F0) >> 4) | ((value & 0x0F0F) << 4); 110 | value = ((value & 0xCCCC) >> 2) | ((value & 0x3333) << 2); 111 | value = ((value & 0xAAAA) >> 1) | ((value & 0x5555) << 1); 112 | 113 | return value; 114 | } 115 | 116 | 117 | /** 118 | * @brief Reverse bit order in a 32-bit word 119 | * @param[in] value 32-bit value 120 | * @return 32-bit value with bit order reversed 121 | **/ 122 | 123 | uint32_t reverseInt32(uint32_t value) 124 | { 125 | value = ((value & 0xFFFF0000UL) >> 16) | ((value & 0x0000FFFFUL) << 16); 126 | value = ((value & 0xFF00FF00UL) >> 8) | ((value & 0x00FF00FFUL) << 8); 127 | value = ((value & 0xF0F0F0F0UL) >> 4) | ((value & 0x0F0F0F0FUL) << 4); 128 | value = ((value & 0xCCCCCCCCUL) >> 2) | ((value & 0x33333333UL) << 2); 129 | value = ((value & 0xAAAAAAAAUL) >> 1) | ((value & 0x55555555UL) << 1); 130 | 131 | return value; 132 | } 133 | 134 | 135 | /** 136 | * @brief Reverse bit order in a 64-bit word 137 | * @param[in] value 64-bit value 138 | * @return 64-bit value with bit order reversed 139 | **/ 140 | 141 | uint64_t reverseInt64(uint64_t value) 142 | { 143 | value = ((value & 0xFFFFFFFF00000000ULL) >> 32) | ((value & 0x00000000FFFFFFFFULL) << 32); 144 | value = ((value & 0xFFFF0000FFFF0000ULL) >> 16) | ((value & 0x0000FFFF0000FFFFULL) << 16); 145 | value = ((value & 0xFF00FF00FF00FF00ULL) >> 8) | ((value & 0x00FF00FF00FF00FFULL) << 8); 146 | value = ((value & 0xF0F0F0F0F0F0F0F0ULL) >> 4) | ((value & 0x0F0F0F0F0F0F0F0FULL) << 4); 147 | value = ((value & 0xCCCCCCCCCCCCCCCCULL) >> 2) | ((value & 0x3333333333333333ULL) << 2); 148 | value = ((value & 0xAAAAAAAAAAAAAAAAULL) >> 1) | ((value & 0x5555555555555555ULL) << 1); 149 | 150 | return value; 151 | } 152 | -------------------------------------------------------------------------------- /deps/cyclone/ecb.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ecb.c 3 | * @brief Electronic Codebook (ECB) mode 4 | * 5 | * @section License 6 | * 7 | * SPDX-License-Identifier: GPL-2.0-or-later 8 | * 9 | * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved. 10 | * 11 | * This file is part of CycloneCRYPTO Open. 12 | * 13 | * This program is free software; you can redistribute it and/or 14 | * modify it under the terms of the GNU General Public License 15 | * as published by the Free Software Foundation; either version 2 16 | * of the License, or (at your option) any later version. 17 | * 18 | * This program is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with this program; if not, write to the Free Software Foundation, 25 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 26 | * 27 | * @section Description 28 | * 29 | * The Electronic Codebook (ECB) mode is a confidentiality mode that features, 30 | * for a given key, the assignment of a fixed ciphertext block to each 31 | * plaintext block, analogous to the assignment of code words in a codebook. 32 | * Refer to SP 800-38A for more details 33 | * 34 | * @author Oryx Embedded SARL (www.oryx-embedded.com) 35 | * @version 2.4.4 36 | **/ 37 | 38 | //Switch to the appropriate trace level 39 | #define TRACE_LEVEL CRYPTO_TRACE_LEVEL 40 | 41 | //Dependencies 42 | #include "core/crypto.h" 43 | #include "cipher_modes/ecb.h" 44 | 45 | //Check crypto library configuration 46 | #if (ECB_SUPPORT == ENABLED) 47 | 48 | 49 | /** 50 | * @brief ECB encryption 51 | * @param[in] cipher Cipher algorithm 52 | * @param[in] context Cipher algorithm context 53 | * @param[in] p Plaintext to be encrypted 54 | * @param[out] c Ciphertext resulting from the encryption 55 | * @param[in] length Total number of data bytes to be encrypted 56 | * @return Error code 57 | **/ 58 | 59 | __weak_func error_t ecbEncrypt(const CipherAlgo *cipher, void *context, 60 | const uint8_t *p, uint8_t *c, size_t length) 61 | { 62 | //ECB mode operates in a block-by-block fashion 63 | while(length >= cipher->blockSize) 64 | { 65 | //Encrypt current block 66 | cipher->encryptBlock(context, p, c); 67 | 68 | //Next block 69 | p += cipher->blockSize; 70 | c += cipher->blockSize; 71 | length -= cipher->blockSize; 72 | } 73 | 74 | //The plaintext must be a multiple of the block size 75 | if(length != 0) 76 | return ERROR_INVALID_LENGTH; 77 | 78 | //Successful encryption 79 | return NO_ERROR; 80 | } 81 | 82 | 83 | /** 84 | * @brief ECB decryption 85 | * @param[in] cipher Cipher algorithm 86 | * @param[in] context Cipher algorithm context 87 | * @param[in] c Ciphertext to be decrypted 88 | * @param[out] p Plaintext resulting from the decryption 89 | * @param[in] length Total number of data bytes to be decrypted 90 | * @return Error code 91 | **/ 92 | 93 | __weak_func error_t ecbDecrypt(const CipherAlgo *cipher, void *context, 94 | const uint8_t *c, uint8_t *p, size_t length) 95 | { 96 | //ECB mode operates in a block-by-block fashion 97 | while(length >= cipher->blockSize) 98 | { 99 | //Decrypt current block 100 | cipher->decryptBlock(context, c, p); 101 | 102 | //Next block 103 | c += cipher->blockSize; 104 | p += cipher->blockSize; 105 | length -= cipher->blockSize; 106 | } 107 | 108 | //The ciphertext must be a multiple of the block size 109 | if(length != 0) 110 | return ERROR_INVALID_LENGTH; 111 | 112 | //Successful encryption 113 | return NO_ERROR; 114 | } 115 | 116 | #endif 117 | -------------------------------------------------------------------------------- /deps/cyclone/include/aead/gcm.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file gcm.h 3 | * @brief Galois/Counter Mode (GCM) 4 | * 5 | * @section License 6 | * 7 | * SPDX-License-Identifier: GPL-2.0-or-later 8 | * 9 | * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved. 10 | * 11 | * This file is part of CycloneCRYPTO Open. 12 | * 13 | * This program is free software; you can redistribute it and/or 14 | * modify it under the terms of the GNU General Public License 15 | * as published by the Free Software Foundation; either version 2 16 | * of the License, or (at your option) any later version. 17 | * 18 | * This program is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with this program; if not, write to the Free Software Foundation, 25 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 26 | * 27 | * @author Oryx Embedded SARL (www.oryx-embedded.com) 28 | * @version 2.4.4 29 | **/ 30 | 31 | #ifndef _GCM_H 32 | #define _GCM_H 33 | 34 | //Dependencies 35 | #include "core/crypto.h" 36 | 37 | //Precalculated table width, in bits 38 | #ifndef GCM_TABLE_W 39 | #define GCM_TABLE_W 4 40 | #elif (GCM_TABLE_W != 4 && GCM_TABLE_W != 8) 41 | #error GCM_TABLE_W parameter is not valid 42 | #endif 43 | 44 | //4-bit or 8-bit precalculated table? 45 | #if (GCM_TABLE_W == 4) 46 | #define GCM_TABLE_N 16 47 | #define GCM_REVERSE_BITS(n) reverseInt4(n) 48 | #else 49 | #define GCM_TABLE_N 256 50 | #define GCM_REVERSE_BITS(n) reverseInt8(n) 51 | #endif 52 | 53 | //C++ guard 54 | #ifdef __cplusplus 55 | extern "C" { 56 | #endif 57 | 58 | 59 | /** 60 | * @brief GCM context 61 | **/ 62 | 63 | typedef struct 64 | { 65 | const CipherAlgo *cipherAlgo; ///> 8) & 0xFF) 64 | #endif 65 | 66 | #ifndef MIN 67 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) 68 | #endif 69 | 70 | #ifndef MAX 71 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) 72 | #endif 73 | 74 | #ifndef arraysize 75 | #define arraysize(a) (sizeof(a) / sizeof(a[0])) 76 | #endif 77 | 78 | //Memory management 79 | #ifndef osAllocMem 80 | #define osAllocMem malloc 81 | #endif 82 | #ifndef osFreeMem 83 | #define osFreeMem free 84 | #endif 85 | 86 | //Fill block of memory 87 | #ifndef osMemset 88 | #define osMemset(p, value, length) (void) memset(p, value, length) 89 | #endif 90 | 91 | //Copy block of memory 92 | #ifndef osMemcpy 93 | #define osMemcpy(dest, src, length) (void) memcpy(dest, src, length) 94 | #endif 95 | 96 | //Move block of memory 97 | #ifndef osMemmove 98 | #define osMemmove(dest, src, length) (void) memmove(dest, src, length) 99 | #endif 100 | 101 | //Compare two blocks of memory 102 | #ifndef osMemcmp 103 | #define osMemcmp(p1, p2, length) memcmp(p1, p2, length) 104 | #endif 105 | 106 | //Search for the first occurrence of a given character 107 | #ifndef osMemchr 108 | #define osMemchr(p, c, length) memchr(p, c, length) 109 | #endif 110 | #endif 111 | -------------------------------------------------------------------------------- /deps/libmnl/.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.la 3 | *.lo 4 | *.o 5 | .deps/ 6 | .libs/ 7 | Makefile 8 | Makefile.in 9 | 10 | /aclocal.m4 11 | /autom4te.cache/ 12 | /build-aux/ 13 | /config.* 14 | /configure 15 | /libtool 16 | /stamp-h1 17 | 18 | /libmnl.pc 19 | 20 | /libmnl-*.tar.bz2 21 | -------------------------------------------------------------------------------- /deps/libmnl/Make_global.am: -------------------------------------------------------------------------------- 1 | # This is _NOT_ the library release version, it's an API version. 2 | # Extracted from Chapter 6 "Library interface versions" of the libtool docs. 3 | # 4 | # 5 | # Here are a set of rules to help you update your library version information: 6 | # 7 | # 1. Start with version information of `0:0:0' for each libtool library. 8 | # 2. Update the version information only immediately before a public release 9 | # of your software. More frequent updates are unnecessary, and only guarantee 10 | # that the current interface number gets larger faster. 11 | # 3. If the library source code has changed at all since the last update, 12 | # then increment revision (`c:r:a' becomes `c:r+1:a'). 13 | # 4. If any interfaces have been added, removed, or changed since the last 14 | # update, increment current, and set revision to 0. 15 | # 5. If any interfaces have been added since the last public release, then 16 | # increment age. 17 | # 6. If any interfaces have been removed since the last public release, then 18 | # set age to 0. 19 | # 20 | # 21 | LIBVERSION=2:0:2 22 | 23 | AM_CPPFLAGS = ${regular_CPPFLAGS} -I${top_srcdir}/include 24 | AM_CFLAGS = ${regular_CFLAGS} ${GCC_FVISIBILITY_HIDDEN} 25 | -------------------------------------------------------------------------------- /deps/libmnl/Makefile.am: -------------------------------------------------------------------------------- 1 | include $(top_srcdir)/Make_global.am 2 | 3 | ACLOCAL_AMFLAGS = -I m4 4 | 5 | SUBDIRS = src include examples doxygen 6 | DIST_SUBDIRS = src include examples doxygen 7 | 8 | pkgconfigdir = $(libdir)/pkgconfig 9 | pkgconfig_DATA = libmnl.pc 10 | 11 | ${pkgconfig_DATA}: ${top_builddir}/config.status 12 | -------------------------------------------------------------------------------- /deps/libmnl/README: -------------------------------------------------------------------------------- 1 | = What is libmnl? = 2 | 3 | libmnl is a minimalistic user-space library oriented to Netlink developers. 4 | There are a lot of common tasks in parsing, validating, constructing of 5 | both the Netlink header and TLVs that are repetitive and easy to get wrong. 6 | This library aims to provide simple helpers that allows you to re-use code 7 | and to avoid re-inventing the wheel. The main features of this library are: 8 | 9 | * Small: the shared library requires around 30KB for an x86-based computer. 10 | * Simple: this library avoids complexity and elaborated abstractions that 11 | tend to hide Netlink details. 12 | * Easy to use: the library simplifies the work for Netlink-wise developers. 13 | It provides functions to make socket handling, message building, validating, 14 | parsing and sequence tracking, easier. 15 | * Easy to re-use: you can use the library to build your own abstraction layer 16 | on top of this library. 17 | * Decoupling: the interdependency of the main bricks that compose the library 18 | is reduced, i.e. the library provides many helpers, but the programmer is not 19 | forced to use them. 20 | 21 | = Example files = 22 | 23 | You can find several example files under examples/ that you can compile by 24 | invoking `make check'. 25 | 26 | -- 27 | 08/sep/2010 28 | Pablo Neira Ayuso 29 | -------------------------------------------------------------------------------- /deps/libmnl/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | 3 | autoreconf -fi 4 | rm -Rf autom4te.cache 5 | -------------------------------------------------------------------------------- /deps/libmnl/configure.ac: -------------------------------------------------------------------------------- 1 | dnl Process this file with autoconf to create configure. 2 | 3 | AC_INIT([libmnl], [1.0.5]) 4 | AC_CONFIG_AUX_DIR([build-aux]) 5 | AC_CANONICAL_HOST 6 | AC_CONFIG_MACRO_DIR([m4]) 7 | AC_CONFIG_HEADERS([config.h]) 8 | AM_INIT_AUTOMAKE([foreign tar-pax no-dist-gzip dist-xz 1.6 subdir-objects]) 9 | 10 | dnl kernel style compile messages 11 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 12 | 13 | AC_PROG_CC 14 | AM_PROG_CC_C_O 15 | AC_EXEEXT 16 | AC_DISABLE_STATIC 17 | LT_INIT 18 | CHECK_GCC_FVISIBILITY 19 | case "$host" in 20 | *-*-linux* | *-*-uclinux*) ;; 21 | *) AC_MSG_ERROR([Linux only, dude!]);; 22 | esac 23 | 24 | regular_CPPFLAGS="-D_FILE_OFFSET_BITS=64 -D_REENTRANT" 25 | regular_CFLAGS="-Wall -Waggregate-return -Wmissing-declarations \ 26 | -Wmissing-prototypes -Wshadow -Wstrict-prototypes \ 27 | -Wformat=2 -pipe" 28 | AC_SUBST([regular_CPPFLAGS]) 29 | AC_SUBST([regular_CFLAGS]) 30 | AC_CONFIG_FILES([Makefile 31 | src/Makefile 32 | include/Makefile 33 | include/libmnl/Makefile 34 | include/linux/Makefile 35 | include/linux/can/Makefile 36 | include/linux/netfilter/Makefile 37 | examples/Makefile 38 | examples/genl/Makefile 39 | examples/kobject/Makefile 40 | examples/netfilter/Makefile 41 | examples/rtnl/Makefile 42 | libmnl.pc 43 | doxygen/doxygen.cfg 44 | doxygen/Makefile]) 45 | 46 | AC_ARG_WITH([doxygen], [AS_HELP_STRING([--with-doxygen], 47 | [create doxygen documentation])], 48 | [with_doxygen="$withval"], [with_doxygen=yes]) 49 | 50 | AS_IF([test "x$with_doxygen" != xno], [ 51 | AC_CHECK_PROGS([DOXYGEN], [doxygen]) 52 | AC_CHECK_PROGS([DOT], [dot], [""]) 53 | AS_IF([test "x$DOT" != "x"], 54 | [AC_SUBST(HAVE_DOT, YES)], 55 | [AC_SUBST(HAVE_DOT, NO)]) 56 | ]) 57 | 58 | AM_CONDITIONAL([HAVE_DOXYGEN], [test -n "$DOXYGEN"]) 59 | AS_IF([test "x$DOXYGEN" = x], [ 60 | AS_IF([test "x$with_doxygen" != xno], [ 61 | dnl Only run doxygen Makefile if doxygen installed 62 | AC_MSG_WARN([Doxygen not found - continuing without Doxygen support]) 63 | with_doxygen=no 64 | ]) 65 | ]) 66 | AC_OUTPUT 67 | 68 | echo " 69 | libmnl configuration: 70 | doxygen: ${with_doxygen}" 71 | -------------------------------------------------------------------------------- /deps/libmnl/doxygen/.gitignore: -------------------------------------------------------------------------------- 1 | doxyfile.stamp 2 | doxygen.cfg 3 | html/ 4 | man/ 5 | -------------------------------------------------------------------------------- /deps/libmnl/doxygen/Makefile.am: -------------------------------------------------------------------------------- 1 | if HAVE_DOXYGEN 2 | doc_srcs = $(shell find $(top_srcdir)/src -name '*.c') 3 | 4 | doxyfile.stamp: $(doc_srcs) Makefile.am 5 | rm -rf html man 6 | doxygen doxygen.cfg >/dev/null 7 | $(SHELL) $(top_srcdir)/doxygen/finalize_manpages.sh 8 | touch doxyfile.stamp 9 | 10 | CLEANFILES = doxyfile.stamp 11 | 12 | all-local: doxyfile.stamp 13 | clean-local: 14 | rm -rf $(top_srcdir)/doxygen/man $(top_srcdir)/doxygen/html 15 | install-data-local: 16 | mkdir -p $(DESTDIR)$(mandir)/man3 17 | cp --no-dereference --preserve=links,mode,timestamps man/man3/*.3\ 18 | $(DESTDIR)$(mandir)/man3/ 19 | 20 | # make distcheck needs uninstall-local 21 | uninstall-local: 22 | rm -r $(DESTDIR)$(mandir) man html doxyfile.stamp 23 | endif 24 | 25 | EXTRA_DIST = finalize_manpages.sh 26 | -------------------------------------------------------------------------------- /deps/libmnl/doxygen/doxygen.cfg.in: -------------------------------------------------------------------------------- 1 | # Difference with default Doxyfile 1.8.20 2 | PROJECT_NAME = @PACKAGE@ 3 | PROJECT_NUMBER = @VERSION@ 4 | OUTPUT_DIRECTORY = . 5 | ABBREVIATE_BRIEF = 6 | FULL_PATH_NAMES = NO 7 | TAB_SIZE = 8 8 | OPTIMIZE_OUTPUT_FOR_C = YES 9 | INPUT = @top_srcdir@ 10 | FILE_PATTERNS = */src/*.c 11 | RECURSIVE = YES 12 | EXCLUDE_SYMBOLS = EXPORT_SYMBOL mnl_nlmsg_batch mnl_socket 13 | EXAMPLE_PATTERNS = 14 | INPUT_FILTER = "sed 's/EXPORT_SYMBOL//g'" 15 | SOURCE_BROWSER = YES 16 | ALPHABETICAL_INDEX = NO 17 | SEARCHENGINE = NO 18 | GENERATE_LATEX = NO 19 | LATEX_CMD_NAME = latex 20 | GENERATE_MAN = YES 21 | MAN_LINKS = YES 22 | HAVE_DOT = @HAVE_DOT@ 23 | DOT_TRANSPARENT = YES 24 | -------------------------------------------------------------------------------- /deps/libmnl/doxygen/finalize_manpages.sh: -------------------------------------------------------------------------------- 1 | # 2 | # We need to use bash for its associative array facility 3 | # 4 | [ "$BASH" ] || exec bash $0 5 | # 6 | # (`bash -p` prevents import of functions from the environment). 7 | # 8 | set -p 9 | 10 | declare -A renamed_page 11 | 12 | main(){ set -e; cd man/man3; rm -f _* 13 | count_real_pages 14 | rename_real_pages 15 | make_symlinks 16 | } 17 | 18 | count_real_pages(){ page_count=0 19 | for i in $(ls -S) 20 | do head -n1 $i | grep -E -q '^\.so' && break 21 | page_count=$(($page_count + 1)) 22 | done 23 | first_link=$(($page_count + 1)) 24 | } 25 | 26 | rename_real_pages(){ for i in $(ls -S | head -n$page_count) 27 | do for j in $(ls -S | tail -n+$first_link) 28 | do grep -E -q $i$ $j && break 29 | done 30 | mv -f $i $j 31 | renamed_page[$i]=$j 32 | done 33 | } 34 | 35 | make_symlinks(){ for j in $(ls -S | tail -n+$first_link) 36 | do ln -sf ${renamed_page[$(cat $j | cut -f2 -d/)]} $j 37 | done 38 | } 39 | 40 | main 41 | -------------------------------------------------------------------------------- /deps/libmnl/examples/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = genl kobject netfilter rtnl 2 | -------------------------------------------------------------------------------- /deps/libmnl/examples/genl/.gitignore: -------------------------------------------------------------------------------- 1 | /genl-family-get 2 | /genl-group-events -------------------------------------------------------------------------------- /deps/libmnl/examples/genl/Makefile.am: -------------------------------------------------------------------------------- 1 | include $(top_srcdir)/Make_global.am 2 | 3 | check_PROGRAMS = genl-family-get \ 4 | genl-group-events 5 | 6 | genl_family_get_SOURCES = genl-family-get.c 7 | genl_family_get_LDADD = ../../src/libmnl.la 8 | 9 | genl_group_events_SOURCES = genl-group-events.c 10 | genl_group_events_LDADD = ../../src/libmnl.la 11 | -------------------------------------------------------------------------------- /deps/libmnl/examples/genl/genl-group-events.c: -------------------------------------------------------------------------------- 1 | /* This example is placed in the public domain. */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | static int group; 11 | 12 | static int data_cb(const struct nlmsghdr *nlh, void *data) 13 | { 14 | printf("received event type=%d from genetlink group %d\n", 15 | nlh->nlmsg_type, group); 16 | return MNL_CB_OK; 17 | } 18 | 19 | int main(int argc, char *argv[]) 20 | { 21 | struct mnl_socket *nl; 22 | char buf[MNL_SOCKET_BUFFER_SIZE]; 23 | int ret; 24 | 25 | if (argc != 2) { 26 | printf("%s [group]\n", argv[0]); 27 | exit(EXIT_FAILURE); 28 | } 29 | group = atoi(argv[1]); 30 | 31 | nl = mnl_socket_open(NETLINK_GENERIC); 32 | if (nl == NULL) { 33 | perror("mnl_socket_open"); 34 | exit(EXIT_FAILURE); 35 | } 36 | 37 | if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) { 38 | perror("mnl_socket_bind"); 39 | exit(EXIT_FAILURE); 40 | } 41 | 42 | if (mnl_socket_setsockopt(nl, NETLINK_ADD_MEMBERSHIP, &group, 43 | sizeof(int)) < 0) { 44 | perror("mnl_socket_setsockopt"); 45 | exit(EXIT_FAILURE); 46 | } 47 | 48 | ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); 49 | while (ret > 0) { 50 | ret = mnl_cb_run(buf, ret, 0, 0, data_cb, NULL); 51 | if (ret <= 0) 52 | break; 53 | ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); 54 | } 55 | if (ret == -1) { 56 | perror("error"); 57 | exit(EXIT_FAILURE); 58 | } 59 | 60 | mnl_socket_close(nl); 61 | 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /deps/libmnl/examples/kobject/.gitignore: -------------------------------------------------------------------------------- 1 | /kobject-event 2 | -------------------------------------------------------------------------------- /deps/libmnl/examples/kobject/Makefile.am: -------------------------------------------------------------------------------- 1 | include $(top_srcdir)/Make_global.am 2 | 3 | check_PROGRAMS = kobject-event 4 | 5 | kobject_event_SOURCES = kobject-event.c 6 | kobject_event_LDADD = ../../src/libmnl.la 7 | -------------------------------------------------------------------------------- /deps/libmnl/examples/kobject/kobject-event.c: -------------------------------------------------------------------------------- 1 | /* This example is placed in the public domain. */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | int main(int argc, char *argv[]) 11 | { 12 | struct mnl_socket *nl; 13 | char buf[MNL_SOCKET_BUFFER_SIZE]; 14 | int ret; 15 | 16 | nl = mnl_socket_open(NETLINK_KOBJECT_UEVENT); 17 | if (nl == NULL) { 18 | perror("mnl_socket_open"); 19 | exit(EXIT_FAILURE); 20 | } 21 | 22 | /* There is one single group in kobject over netlink */ 23 | if (mnl_socket_bind(nl, (1<<0), MNL_SOCKET_AUTOPID) < 0) { 24 | perror("mnl_socket_bind"); 25 | exit(EXIT_FAILURE); 26 | } 27 | 28 | ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); 29 | while (ret > 0) { 30 | int i; 31 | 32 | /* kobject uses a string based protocol, with no initial 33 | * netlink header. 34 | */ 35 | for (i=0; i 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | int main(int argc, char *argv[]) 16 | { 17 | struct mnl_socket *nl; 18 | char buf[MNL_SOCKET_BUFFER_SIZE]; 19 | struct nlmsghdr *nlh; 20 | struct ifaddrmsg *ifm; 21 | uint32_t seq, portid; 22 | union { 23 | in_addr_t ip; 24 | struct in6_addr ip6; 25 | } addr; 26 | int ret, family = AF_INET; 27 | 28 | uint32_t prefix; 29 | int iface; 30 | 31 | 32 | if (argc <= 3) { 33 | printf("Usage: %s iface destination cidr\n", argv[0]); 34 | printf("Example: %s eth0 10.0.1.12 32\n", argv[0]); 35 | printf(" %s eth0 ffff::10.0.1.12 128\n", argv[0]); 36 | exit(EXIT_FAILURE); 37 | } 38 | 39 | iface = if_nametoindex(argv[1]); 40 | if (iface == 0) { 41 | perror("if_nametoindex"); 42 | exit(EXIT_FAILURE); 43 | } 44 | 45 | if (!inet_pton(AF_INET, argv[2], &addr)) { 46 | if (!inet_pton(AF_INET6, argv[2], &addr)) { 47 | perror("inet_pton"); 48 | exit(EXIT_FAILURE); 49 | } 50 | family = AF_INET6; 51 | } 52 | 53 | if (sscanf(argv[3], "%u", &prefix) == 0) { 54 | perror("sscanf"); 55 | exit(EXIT_FAILURE); 56 | } 57 | 58 | nlh = mnl_nlmsg_put_header(buf); 59 | nlh->nlmsg_type = RTM_NEWADDR; 60 | 61 | nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_REPLACE | NLM_F_ACK; 62 | nlh->nlmsg_seq = seq = time(NULL); 63 | 64 | ifm = mnl_nlmsg_put_extra_header(nlh, sizeof(struct ifaddrmsg)); 65 | 66 | ifm->ifa_family = family; 67 | ifm->ifa_prefixlen = prefix; 68 | ifm->ifa_flags = IFA_F_PERMANENT; 69 | 70 | ifm->ifa_scope = RT_SCOPE_UNIVERSE; 71 | ifm->ifa_index = iface; 72 | 73 | /* 74 | * The exact meaning of IFA_LOCAL and IFA_ADDRESS depend 75 | * on the address family being used and the device type. 76 | * For broadcast devices (like the interfaces we use), 77 | * for IPv4 we specify both and they are used interchangeably. 78 | * For IPv6, only IFA_ADDRESS needs to be set. 79 | */ 80 | if (family == AF_INET) { 81 | mnl_attr_put_u32(nlh, IFA_LOCAL, addr.ip); 82 | mnl_attr_put_u32(nlh, IFA_ADDRESS, addr.ip); 83 | } else { 84 | mnl_attr_put(nlh, IFA_ADDRESS, sizeof(struct in6_addr), &addr); 85 | } 86 | 87 | nl = mnl_socket_open(NETLINK_ROUTE); 88 | if (nl == NULL) { 89 | perror("mnl_socket_open"); 90 | exit(EXIT_FAILURE); 91 | } 92 | 93 | if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) { 94 | perror("mnl_socket_bind"); 95 | exit(EXIT_FAILURE); 96 | } 97 | portid = mnl_socket_get_portid(nl); 98 | 99 | if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) { 100 | perror("mnl_socket_sendto"); 101 | exit(EXIT_FAILURE); 102 | } 103 | 104 | ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); 105 | if (ret < 0) { 106 | perror("mnl_socket_recvfrom"); 107 | exit(EXIT_FAILURE); 108 | } 109 | 110 | ret = mnl_cb_run(buf, ret, seq, portid, NULL, NULL); 111 | if (ret < 0) { 112 | perror("mnl_cb_run"); 113 | exit(EXIT_FAILURE); 114 | } 115 | 116 | mnl_socket_close(nl); 117 | 118 | return 0; 119 | } 120 | -------------------------------------------------------------------------------- /deps/libmnl/examples/rtnl/rtnl-addr-dump.c: -------------------------------------------------------------------------------- 1 | /* This example is placed in the public domain. */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | static int data_attr_cb(const struct nlattr *attr, void *data) 15 | { 16 | const struct nlattr **tb = data; 17 | int type = mnl_attr_get_type(attr); 18 | 19 | /* skip unsupported attribute in user-space */ 20 | if (mnl_attr_type_valid(attr, IFA_MAX) < 0) 21 | return MNL_CB_OK; 22 | 23 | switch(type) { 24 | case IFA_ADDRESS: 25 | if (mnl_attr_validate(attr, MNL_TYPE_BINARY) < 0) { 26 | perror("mnl_attr_validate"); 27 | return MNL_CB_ERROR; 28 | } 29 | break; 30 | } 31 | tb[type] = attr; 32 | return MNL_CB_OK; 33 | } 34 | 35 | static int data_cb(const struct nlmsghdr *nlh, void *data) 36 | { 37 | struct nlattr *tb[IFA_MAX + 1] = {}; 38 | struct ifaddrmsg *ifa = mnl_nlmsg_get_payload(nlh); 39 | 40 | printf("index=%d family=%d ", ifa->ifa_index, ifa->ifa_family); 41 | 42 | mnl_attr_parse(nlh, sizeof(*ifa), data_attr_cb, tb); 43 | printf("addr="); 44 | if (tb[IFA_ADDRESS]) { 45 | void *addr = mnl_attr_get_payload(tb[IFA_ADDRESS]); 46 | char out[INET6_ADDRSTRLEN]; 47 | 48 | if (inet_ntop(ifa->ifa_family, addr, out, sizeof(out))) 49 | printf("%s ", out); 50 | } 51 | printf("scope="); 52 | switch(ifa->ifa_scope) { 53 | case 0: 54 | printf("global "); 55 | break; 56 | case 200: 57 | printf("site "); 58 | break; 59 | case 253: 60 | printf("link "); 61 | break; 62 | case 254: 63 | printf("host "); 64 | break; 65 | case 255: 66 | printf("nowhere "); 67 | break; 68 | default: 69 | printf("%d ", ifa->ifa_scope); 70 | break; 71 | } 72 | 73 | printf("\n"); 74 | return MNL_CB_OK; 75 | } 76 | 77 | int main(int argc, char *argv[]) 78 | { 79 | char buf[MNL_SOCKET_DUMP_SIZE]; 80 | unsigned int seq, portid; 81 | struct mnl_socket *nl; 82 | struct nlmsghdr *nlh; 83 | struct rtgenmsg *rt; 84 | int ret; 85 | 86 | if (argc != 2) { 87 | fprintf(stderr, "Usage: %s \n", argv[0]); 88 | exit(EXIT_FAILURE); 89 | } 90 | 91 | nlh = mnl_nlmsg_put_header(buf); 92 | nlh->nlmsg_type = RTM_GETADDR; 93 | nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP; 94 | nlh->nlmsg_seq = seq = time(NULL); 95 | rt = mnl_nlmsg_put_extra_header(nlh, sizeof(struct rtgenmsg)); 96 | if (strcmp(argv[1], "inet") == 0) 97 | rt->rtgen_family = AF_INET; 98 | else if (strcmp(argv[1], "inet6") == 0) 99 | rt->rtgen_family = AF_INET6; 100 | 101 | nl = mnl_socket_open(NETLINK_ROUTE); 102 | if (nl == NULL) { 103 | perror("mnl_socket_open"); 104 | exit(EXIT_FAILURE); 105 | } 106 | 107 | if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) { 108 | perror("mnl_socket_bind"); 109 | exit(EXIT_FAILURE); 110 | } 111 | portid = mnl_socket_get_portid(nl); 112 | 113 | if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) { 114 | perror("mnl_socket_sendto"); 115 | exit(EXIT_FAILURE); 116 | } 117 | 118 | ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); 119 | while (ret > 0) { 120 | ret = mnl_cb_run(buf, ret, seq, portid, data_cb, NULL); 121 | if (ret <= MNL_CB_STOP) 122 | break; 123 | ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); 124 | } 125 | if (ret == -1) { 126 | perror("error"); 127 | exit(EXIT_FAILURE); 128 | } 129 | 130 | mnl_socket_close(nl); 131 | 132 | return 0; 133 | } 134 | -------------------------------------------------------------------------------- /deps/libmnl/examples/rtnl/rtnl-link-dump.c: -------------------------------------------------------------------------------- 1 | /* This example is placed in the public domain. */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | static int data_attr_cb(const struct nlattr *attr, void *data) 14 | { 15 | const struct nlattr **tb = data; 16 | int type = mnl_attr_get_type(attr); 17 | 18 | /* skip unsupported attribute in user-space */ 19 | if (mnl_attr_type_valid(attr, IFLA_MAX) < 0) 20 | return MNL_CB_OK; 21 | 22 | switch(type) { 23 | case IFLA_ADDRESS: 24 | if (mnl_attr_validate(attr, MNL_TYPE_BINARY) < 0) { 25 | perror("mnl_attr_validate"); 26 | return MNL_CB_ERROR; 27 | } 28 | break; 29 | case IFLA_MTU: 30 | if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0) { 31 | perror("mnl_attr_validate"); 32 | return MNL_CB_ERROR; 33 | } 34 | break; 35 | case IFLA_IFNAME: 36 | if (mnl_attr_validate(attr, MNL_TYPE_STRING) < 0) { 37 | perror("mnl_attr_validate"); 38 | return MNL_CB_ERROR; 39 | } 40 | break; 41 | } 42 | tb[type] = attr; 43 | return MNL_CB_OK; 44 | } 45 | 46 | static int data_cb(const struct nlmsghdr *nlh, void *data) 47 | { 48 | struct nlattr *tb[IFLA_MAX+1] = {}; 49 | struct ifinfomsg *ifm = mnl_nlmsg_get_payload(nlh); 50 | 51 | printf("index=%d type=%d flags=%d family=%d ", 52 | ifm->ifi_index, ifm->ifi_type, 53 | ifm->ifi_flags, ifm->ifi_family); 54 | 55 | if (ifm->ifi_flags & IFF_RUNNING) 56 | printf("[RUNNING] "); 57 | else 58 | printf("[NOT RUNNING] "); 59 | 60 | mnl_attr_parse(nlh, sizeof(*ifm), data_attr_cb, tb); 61 | if (tb[IFLA_MTU]) { 62 | printf("mtu=%d ", mnl_attr_get_u32(tb[IFLA_MTU])); 63 | } 64 | if (tb[IFLA_IFNAME]) { 65 | printf("name=%s ", mnl_attr_get_str(tb[IFLA_IFNAME])); 66 | } 67 | if (tb[IFLA_ADDRESS]) { 68 | uint8_t *hwaddr = mnl_attr_get_payload(tb[IFLA_ADDRESS]); 69 | int i; 70 | 71 | printf("hwaddr="); 72 | for (i=0; inlmsg_type = RTM_GETLINK; 93 | nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP; 94 | nlh->nlmsg_seq = seq = time(NULL); 95 | rt = mnl_nlmsg_put_extra_header(nlh, sizeof(struct rtgenmsg)); 96 | rt->rtgen_family = AF_PACKET; 97 | 98 | nl = mnl_socket_open(NETLINK_ROUTE); 99 | if (nl == NULL) { 100 | perror("mnl_socket_open"); 101 | exit(EXIT_FAILURE); 102 | } 103 | 104 | if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) { 105 | perror("mnl_socket_bind"); 106 | exit(EXIT_FAILURE); 107 | } 108 | portid = mnl_socket_get_portid(nl); 109 | 110 | if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) { 111 | perror("mnl_socket_sendto"); 112 | exit(EXIT_FAILURE); 113 | } 114 | 115 | ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); 116 | while (ret > 0) { 117 | ret = mnl_cb_run(buf, ret, seq, portid, data_cb, NULL); 118 | if (ret <= MNL_CB_STOP) 119 | break; 120 | ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); 121 | } 122 | if (ret == -1) { 123 | perror("error"); 124 | exit(EXIT_FAILURE); 125 | } 126 | 127 | mnl_socket_close(nl); 128 | 129 | return 0; 130 | } 131 | -------------------------------------------------------------------------------- /deps/libmnl/examples/rtnl/rtnl-link-dump2.c: -------------------------------------------------------------------------------- 1 | /* This example is placed in the public domain. */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | static int data_attr_cb(const struct nlattr *attr, void *data) 13 | { 14 | /* skip unsupported attribute in user-space */ 15 | if (mnl_attr_type_valid(attr, IFLA_MAX) < 0) 16 | return MNL_CB_OK; 17 | 18 | switch(mnl_attr_get_type(attr)) { 19 | case IFLA_MTU: 20 | if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0) { 21 | perror("mnl_attr_validate"); 22 | return MNL_CB_ERROR; 23 | } 24 | printf("mtu=%d ", mnl_attr_get_u32(attr)); 25 | break; 26 | case IFLA_IFNAME: 27 | if (mnl_attr_validate(attr, MNL_TYPE_STRING) < 0) { 28 | perror("mnl_attr_validate"); 29 | return MNL_CB_ERROR; 30 | } 31 | printf("name=%s ", mnl_attr_get_str(attr)); 32 | break; 33 | } 34 | return MNL_CB_OK; 35 | } 36 | 37 | static int data_cb(const struct nlmsghdr *nlh, void *data) 38 | { 39 | struct ifinfomsg *ifm = mnl_nlmsg_get_payload(nlh); 40 | 41 | printf("index=%d type=%d flags=%d family=%d ", 42 | ifm->ifi_index, ifm->ifi_type, 43 | ifm->ifi_flags, ifm->ifi_family); 44 | 45 | if (ifm->ifi_flags & IFF_RUNNING) 46 | printf("[RUNNING] "); 47 | else 48 | printf("[NOT RUNNING] "); 49 | 50 | mnl_attr_parse(nlh, sizeof(*ifm), data_attr_cb, NULL); 51 | printf("\n"); 52 | return MNL_CB_OK; 53 | } 54 | 55 | int main(void) 56 | { 57 | char buf[MNL_SOCKET_DUMP_SIZE]; 58 | unsigned int seq, portid; 59 | struct mnl_socket *nl; 60 | struct nlmsghdr *nlh; 61 | struct rtgenmsg *rt; 62 | int ret; 63 | 64 | nlh = mnl_nlmsg_put_header(buf); 65 | nlh->nlmsg_type = RTM_GETLINK; 66 | nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP; 67 | nlh->nlmsg_seq = seq = time(NULL); 68 | rt = mnl_nlmsg_put_extra_header(nlh, sizeof(struct rtgenmsg)); 69 | rt->rtgen_family = AF_PACKET; 70 | 71 | nl = mnl_socket_open(NETLINK_ROUTE); 72 | if (nl == NULL) { 73 | perror("mnl_socket_open"); 74 | exit(EXIT_FAILURE); 75 | } 76 | 77 | if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) { 78 | perror("mnl_socket_bind"); 79 | exit(EXIT_FAILURE); 80 | } 81 | portid = mnl_socket_get_portid(nl); 82 | 83 | if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) { 84 | perror("mnl_socket_sendto"); 85 | exit(EXIT_FAILURE); 86 | } 87 | 88 | ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); 89 | while (ret > 0) { 90 | ret = mnl_cb_run(buf, ret, seq, portid, data_cb, NULL); 91 | if (ret <= MNL_CB_STOP) 92 | break; 93 | ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); 94 | } 95 | if (ret == -1) { 96 | perror("error"); 97 | exit(EXIT_FAILURE); 98 | } 99 | 100 | mnl_socket_close(nl); 101 | 102 | return 0; 103 | } 104 | -------------------------------------------------------------------------------- /deps/libmnl/examples/rtnl/rtnl-link-dump3.c: -------------------------------------------------------------------------------- 1 | /* This example is placed in the public domain. */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | static int data_cb(const struct nlmsghdr *nlh, void *data) 13 | { 14 | struct ifinfomsg *ifm = mnl_nlmsg_get_payload(nlh); 15 | struct nlattr *attr; 16 | 17 | printf("index=%d type=%d flags=%d family=%d ", 18 | ifm->ifi_index, ifm->ifi_type, 19 | ifm->ifi_flags, ifm->ifi_family); 20 | 21 | if (ifm->ifi_flags & IFF_RUNNING) 22 | printf("[RUNNING] "); 23 | else 24 | printf("[NOT RUNNING] "); 25 | 26 | mnl_attr_for_each(attr, nlh, sizeof(*ifm)) { 27 | int type = mnl_attr_get_type(attr); 28 | 29 | /* skip unsupported attribute in user-space */ 30 | if (mnl_attr_type_valid(attr, IFLA_MAX) < 0) 31 | continue; 32 | 33 | switch(type) { 34 | case IFLA_MTU: 35 | if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0) { 36 | perror("mnl_attr_validate"); 37 | return MNL_CB_ERROR; 38 | } 39 | printf("mtu=%d ", mnl_attr_get_u32(attr)); 40 | break; 41 | case IFLA_IFNAME: 42 | if (mnl_attr_validate(attr, MNL_TYPE_STRING) < 0) { 43 | perror("mnl_attr_validate"); 44 | return MNL_CB_ERROR; 45 | } 46 | printf("name=%s ", mnl_attr_get_str(attr)); 47 | break; 48 | } 49 | } 50 | printf("\n"); 51 | 52 | return MNL_CB_OK; 53 | } 54 | 55 | int main(void) 56 | { 57 | char buf[MNL_SOCKET_DUMP_SIZE]; 58 | unsigned int seq, portid; 59 | struct mnl_socket *nl; 60 | struct nlmsghdr *nlh; 61 | struct rtgenmsg *rt; 62 | int ret; 63 | 64 | nlh = mnl_nlmsg_put_header(buf); 65 | nlh->nlmsg_type = RTM_GETLINK; 66 | nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP; 67 | nlh->nlmsg_seq = seq = time(NULL); 68 | rt = mnl_nlmsg_put_extra_header(nlh, sizeof(struct rtgenmsg)); 69 | rt->rtgen_family = AF_PACKET; 70 | 71 | nl = mnl_socket_open(NETLINK_ROUTE); 72 | if (nl == NULL) { 73 | perror("mnl_socket_open"); 74 | exit(EXIT_FAILURE); 75 | } 76 | 77 | if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) { 78 | perror("mnl_socket_bind"); 79 | exit(EXIT_FAILURE); 80 | } 81 | portid = mnl_socket_get_portid(nl); 82 | 83 | if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) { 84 | perror("mnl_socket_sendto"); 85 | exit(EXIT_FAILURE); 86 | } 87 | 88 | ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); 89 | while (ret > 0) { 90 | ret = mnl_cb_run(buf, ret, seq, portid, data_cb, NULL); 91 | if (ret <= MNL_CB_STOP) 92 | break; 93 | ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); 94 | } 95 | if (ret == -1) { 96 | perror("error"); 97 | exit(EXIT_FAILURE); 98 | } 99 | 100 | mnl_socket_close(nl); 101 | 102 | return 0; 103 | } 104 | -------------------------------------------------------------------------------- /deps/libmnl/examples/rtnl/rtnl-link-event.c: -------------------------------------------------------------------------------- 1 | /* This example is placed in the public domain. */ 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | static int data_attr_cb(const struct nlattr *attr, void *data) 12 | { 13 | const struct nlattr **tb = data; 14 | int type = mnl_attr_get_type(attr); 15 | 16 | /* skip unsupported attribute in user-space */ 17 | if (mnl_attr_type_valid(attr, IFLA_MAX) < 0) 18 | return MNL_CB_OK; 19 | 20 | switch(type) { 21 | case IFLA_MTU: 22 | if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0) { 23 | perror("mnl_attr_validate"); 24 | return MNL_CB_ERROR; 25 | } 26 | break; 27 | case IFLA_IFNAME: 28 | if (mnl_attr_validate(attr, MNL_TYPE_STRING) < 0) { 29 | perror("mnl_attr_validate"); 30 | return MNL_CB_ERROR; 31 | } 32 | break; 33 | } 34 | tb[type] = attr; 35 | return MNL_CB_OK; 36 | } 37 | 38 | static int data_cb(const struct nlmsghdr *nlh, void *data) 39 | { 40 | struct nlattr *tb[IFLA_MAX+1] = {}; 41 | struct ifinfomsg *ifm = mnl_nlmsg_get_payload(nlh); 42 | 43 | printf("index=%d type=%d flags=%d family=%d ", 44 | ifm->ifi_index, ifm->ifi_type, 45 | ifm->ifi_flags, ifm->ifi_family); 46 | 47 | if (ifm->ifi_flags & IFF_RUNNING) 48 | printf("[RUNNING] "); 49 | else 50 | printf("[NOT RUNNING] "); 51 | 52 | mnl_attr_parse(nlh, sizeof(*ifm), data_attr_cb, tb); 53 | if (tb[IFLA_MTU]) { 54 | printf("mtu=%d ", mnl_attr_get_u32(tb[IFLA_MTU])); 55 | } 56 | if (tb[IFLA_IFNAME]) { 57 | printf("name=%s", mnl_attr_get_str(tb[IFLA_IFNAME])); 58 | } 59 | printf("\n"); 60 | return MNL_CB_OK; 61 | } 62 | 63 | int main(void) 64 | { 65 | struct mnl_socket *nl; 66 | char buf[MNL_SOCKET_BUFFER_SIZE]; 67 | int ret; 68 | 69 | nl = mnl_socket_open(NETLINK_ROUTE); 70 | if (nl == NULL) { 71 | perror("mnl_socket_open"); 72 | exit(EXIT_FAILURE); 73 | } 74 | 75 | if (mnl_socket_bind(nl, RTMGRP_LINK, MNL_SOCKET_AUTOPID) < 0) { 76 | perror("mnl_socket_bind"); 77 | exit(EXIT_FAILURE); 78 | } 79 | 80 | ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); 81 | while (ret > 0) { 82 | ret = mnl_cb_run(buf, ret, 0, 0, data_cb, NULL); 83 | if (ret <= 0) 84 | break; 85 | ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); 86 | } 87 | if (ret == -1) { 88 | perror("error"); 89 | exit(EXIT_FAILURE); 90 | } 91 | 92 | mnl_socket_close(nl); 93 | 94 | return 0; 95 | } 96 | -------------------------------------------------------------------------------- /deps/libmnl/examples/rtnl/rtnl-link-set.c: -------------------------------------------------------------------------------- 1 | /* This example is placed in the public domain. */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | struct mnl_socket *nl; 16 | char buf[MNL_SOCKET_BUFFER_SIZE]; 17 | struct nlmsghdr *nlh; 18 | struct ifinfomsg *ifm; 19 | int ret; 20 | unsigned int seq, portid, change = 0, flags = 0; 21 | 22 | if (argc != 3) { 23 | printf("Usage: %s [ifname] [up|down]\n", argv[0]); 24 | exit(EXIT_FAILURE); 25 | } 26 | 27 | if (strncasecmp(argv[2], "up", strlen("up")) == 0) { 28 | change |= IFF_UP; 29 | flags |= IFF_UP; 30 | } else if (strncasecmp(argv[2], "down", strlen("down")) == 0) { 31 | change |= IFF_UP; 32 | flags &= ~IFF_UP; 33 | } else { 34 | fprintf(stderr, "%s is not `up' nor `down'\n", argv[2]); 35 | exit(EXIT_FAILURE); 36 | } 37 | 38 | nlh = mnl_nlmsg_put_header(buf); 39 | nlh->nlmsg_type = RTM_NEWLINK; 40 | nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; 41 | nlh->nlmsg_seq = seq = time(NULL); 42 | ifm = mnl_nlmsg_put_extra_header(nlh, sizeof(*ifm)); 43 | ifm->ifi_family = AF_UNSPEC; 44 | ifm->ifi_change = change; 45 | ifm->ifi_flags = flags; 46 | 47 | mnl_attr_put_str(nlh, IFLA_IFNAME, argv[1]); 48 | 49 | nl = mnl_socket_open(NETLINK_ROUTE); 50 | if (nl == NULL) { 51 | perror("mnl_socket_open"); 52 | exit(EXIT_FAILURE); 53 | } 54 | 55 | if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) { 56 | perror("mnl_socket_bind"); 57 | exit(EXIT_FAILURE); 58 | } 59 | portid = mnl_socket_get_portid(nl); 60 | 61 | mnl_nlmsg_fprintf(stdout, nlh, nlh->nlmsg_len, 62 | sizeof(struct ifinfomsg)); 63 | 64 | if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) { 65 | perror("mnl_socket_sendto"); 66 | exit(EXIT_FAILURE); 67 | } 68 | 69 | ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); 70 | if (ret == -1) { 71 | perror("mnl_socket_recvfrom"); 72 | exit(EXIT_FAILURE); 73 | } 74 | 75 | ret = mnl_cb_run(buf, ret, seq, portid, NULL, NULL); 76 | if (ret == -1){ 77 | perror("mnl_cb_run"); 78 | exit(EXIT_FAILURE); 79 | } 80 | 81 | mnl_socket_close(nl); 82 | 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /deps/libmnl/examples/rtnl/rtnl-neigh-dump.c: -------------------------------------------------------------------------------- 1 | /* This example is placed in the public domain. */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | static int data_attr_cb(const struct nlattr *attr, void *data) 15 | { 16 | const struct nlattr **tb = data; 17 | int type = mnl_attr_get_type(attr); 18 | 19 | /* skip unsupported attribute in user-space */ 20 | if (mnl_attr_type_valid(attr, NDA_MAX) < 0) 21 | return MNL_CB_OK; 22 | 23 | switch(type) { 24 | case NDA_DST: 25 | case NDA_LLADDR: 26 | if (mnl_attr_validate(attr, MNL_TYPE_BINARY) < 0) { 27 | perror("mnl_attr_validate"); 28 | return MNL_CB_ERROR; 29 | } 30 | break; 31 | } 32 | tb[type] = attr; 33 | return MNL_CB_OK; 34 | } 35 | 36 | static int data_cb(const struct nlmsghdr *nlh, void *data) 37 | { 38 | struct nlattr *tb[NDA_MAX + 1] = {}; 39 | struct ndmsg *ndm = mnl_nlmsg_get_payload(nlh); 40 | 41 | printf("index=%d family=%d ", ndm->ndm_ifindex, ndm->ndm_family); 42 | 43 | mnl_attr_parse(nlh, sizeof(*ndm), data_attr_cb, tb); 44 | printf("dst="); 45 | if (tb[NDA_DST]) { 46 | void *addr = mnl_attr_get_payload(tb[NDA_DST]); 47 | char out[INET6_ADDRSTRLEN]; 48 | 49 | if (inet_ntop(ndm->ndm_family, addr, out, sizeof(out))) 50 | printf("%s ", out); 51 | } 52 | 53 | mnl_attr_parse(nlh, sizeof(*ndm), data_attr_cb, tb); 54 | printf("lladdr="); 55 | if (tb[NDA_LLADDR]) { 56 | void *addr = mnl_attr_get_payload(tb[NDA_LLADDR]); 57 | unsigned char lladdr[6] = {0}; 58 | 59 | if (memcpy(&lladdr, addr, 6)) 60 | printf("%02x:%02x:%02x:%02x:%02x:%02x ", 61 | lladdr[0], lladdr[1], lladdr[2], 62 | lladdr[3], lladdr[4], lladdr[5]); 63 | } 64 | 65 | printf("state="); 66 | switch(ndm->ndm_state) { 67 | case NUD_INCOMPLETE: 68 | printf("incomplete "); 69 | break; 70 | case NUD_REACHABLE: 71 | printf("reachable "); 72 | break; 73 | case NUD_STALE: 74 | printf("stale "); 75 | break; 76 | case NUD_DELAY: 77 | printf("delay "); 78 | break; 79 | case NUD_PROBE: 80 | printf("probe "); 81 | break; 82 | case NUD_FAILED: 83 | printf("failed "); 84 | break; 85 | case NUD_NOARP: 86 | printf("noarp "); 87 | break; 88 | case NUD_PERMANENT: 89 | printf("permanent "); 90 | break; 91 | default: 92 | printf("%d ", ndm->ndm_state); 93 | break; 94 | } 95 | 96 | printf("\n"); 97 | return MNL_CB_OK; 98 | } 99 | 100 | int main(int argc, char *argv[]) 101 | { 102 | char buf[MNL_SOCKET_DUMP_SIZE]; 103 | unsigned int seq, portid; 104 | struct mnl_socket *nl; 105 | struct nlmsghdr *nlh; 106 | struct ndmsg *nd; 107 | int ret; 108 | 109 | if (argc != 2) { 110 | fprintf(stderr, "Usage: %s \n", argv[0]); 111 | exit(EXIT_FAILURE); 112 | } 113 | 114 | nlh = mnl_nlmsg_put_header(buf); 115 | nlh->nlmsg_type = RTM_GETNEIGH; 116 | nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP; 117 | nlh->nlmsg_seq = seq = time(NULL); 118 | 119 | nd = mnl_nlmsg_put_extra_header(nlh, sizeof(struct ndmsg)); 120 | if (strcmp(argv[1], "inet") == 0) 121 | nd->ndm_family = AF_INET; 122 | else if (strcmp(argv[1], "inet6") == 0) 123 | nd->ndm_family = AF_INET6; 124 | 125 | nl = mnl_socket_open(NETLINK_ROUTE); 126 | if (nl == NULL) { 127 | perror("mnl_socket_open"); 128 | exit(EXIT_FAILURE); 129 | } 130 | 131 | if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) { 132 | perror("mnl_socket_bind"); 133 | exit(EXIT_FAILURE); 134 | } 135 | portid = mnl_socket_get_portid(nl); 136 | 137 | if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) { 138 | perror("mnl_socket_sendto"); 139 | exit(EXIT_FAILURE); 140 | } 141 | 142 | ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); 143 | while (ret > 0) { 144 | ret = mnl_cb_run(buf, ret, seq, portid, data_cb, NULL); 145 | if (ret <= MNL_CB_STOP) 146 | break; 147 | ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); 148 | } 149 | 150 | if (ret == -1) { 151 | perror("error"); 152 | exit(EXIT_FAILURE); 153 | } 154 | 155 | mnl_socket_close(nl); 156 | 157 | return 0; 158 | } 159 | -------------------------------------------------------------------------------- /deps/libmnl/examples/rtnl/rtnl-route-add.c: -------------------------------------------------------------------------------- 1 | /* This example is placed in the public domain. */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | int main(int argc, char *argv[]) 16 | { 17 | struct mnl_socket *nl; 18 | char buf[MNL_SOCKET_BUFFER_SIZE]; 19 | struct nlmsghdr *nlh; 20 | struct rtmsg *rtm; 21 | uint32_t prefix, seq, portid; 22 | union { 23 | in_addr_t ip; 24 | struct in6_addr ip6; 25 | } dst; 26 | union { 27 | in_addr_t ip; 28 | struct in6_addr ip6; 29 | } gw; 30 | int iface, ret, family = AF_INET; 31 | 32 | if (argc <= 3) { 33 | printf("Usage: %s iface destination cidr [gateway]\n", argv[0]); 34 | printf("Example: %s eth0 10.0.1.12 32 10.0.1.11\n", argv[0]); 35 | printf(" %s eth0 ffff::10.0.1.12 128 fdff::1\n", argv[0]); 36 | exit(EXIT_FAILURE); 37 | } 38 | 39 | iface = if_nametoindex(argv[1]); 40 | if (iface == 0) { 41 | perror("if_nametoindex"); 42 | exit(EXIT_FAILURE); 43 | } 44 | 45 | if (!inet_pton(AF_INET, argv[2], &dst)) { 46 | if (!inet_pton(AF_INET6, argv[2], &dst)) { 47 | perror("inet_pton"); 48 | exit(EXIT_FAILURE); 49 | } 50 | family = AF_INET6; 51 | } 52 | 53 | if (sscanf(argv[3], "%u", &prefix) == 0) { 54 | perror("sscanf"); 55 | exit(EXIT_FAILURE); 56 | } 57 | 58 | if (argc == 5 && !inet_pton(family, argv[4], &gw)) { 59 | perror("inet_pton"); 60 | exit(EXIT_FAILURE); 61 | } 62 | 63 | nlh = mnl_nlmsg_put_header(buf); 64 | nlh->nlmsg_type = RTM_NEWROUTE; 65 | nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_ACK; 66 | nlh->nlmsg_seq = seq = time(NULL); 67 | 68 | rtm = mnl_nlmsg_put_extra_header(nlh, sizeof(struct rtmsg)); 69 | rtm->rtm_family = family; 70 | rtm->rtm_dst_len = prefix; 71 | rtm->rtm_src_len = 0; 72 | rtm->rtm_tos = 0; 73 | rtm->rtm_protocol = RTPROT_STATIC; 74 | rtm->rtm_table = RT_TABLE_MAIN; 75 | rtm->rtm_type = RTN_UNICAST; 76 | /* is there any gateway? */ 77 | rtm->rtm_scope = (argc == 4) ? RT_SCOPE_LINK : RT_SCOPE_UNIVERSE; 78 | rtm->rtm_flags = 0; 79 | 80 | if (family == AF_INET) 81 | mnl_attr_put_u32(nlh, RTA_DST, dst.ip); 82 | else 83 | mnl_attr_put(nlh, RTA_DST, sizeof(struct in6_addr), &dst); 84 | 85 | mnl_attr_put_u32(nlh, RTA_OIF, iface); 86 | if (argc == 5) { 87 | if (family == AF_INET) 88 | mnl_attr_put_u32(nlh, RTA_GATEWAY, gw.ip); 89 | else { 90 | mnl_attr_put(nlh, RTA_GATEWAY, sizeof(struct in6_addr), 91 | &gw.ip6); 92 | } 93 | } 94 | 95 | nl = mnl_socket_open(NETLINK_ROUTE); 96 | if (nl == NULL) { 97 | perror("mnl_socket_open"); 98 | exit(EXIT_FAILURE); 99 | } 100 | 101 | if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) { 102 | perror("mnl_socket_bind"); 103 | exit(EXIT_FAILURE); 104 | } 105 | portid = mnl_socket_get_portid(nl); 106 | 107 | if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) { 108 | perror("mnl_socket_sendto"); 109 | exit(EXIT_FAILURE); 110 | } 111 | 112 | ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); 113 | if (ret < 0) { 114 | perror("mnl_socket_recvfrom"); 115 | exit(EXIT_FAILURE); 116 | } 117 | 118 | ret = mnl_cb_run(buf, ret, seq, portid, NULL, NULL); 119 | if (ret < 0) { 120 | perror("mnl_cb_run"); 121 | exit(EXIT_FAILURE); 122 | } 123 | 124 | mnl_socket_close(nl); 125 | 126 | return 0; 127 | } 128 | -------------------------------------------------------------------------------- /deps/libmnl/include/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = libmnl linux 2 | -------------------------------------------------------------------------------- /deps/libmnl/include/libmnl/Makefile.am: -------------------------------------------------------------------------------- 1 | pkginclude_HEADERS = libmnl.h 2 | -------------------------------------------------------------------------------- /deps/libmnl/include/linux/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = can netfilter 2 | noinst_HEADERS = can.h netlink.h socket.h 3 | -------------------------------------------------------------------------------- /deps/libmnl/include/linux/can/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_HEADERS = netlink.h 2 | -------------------------------------------------------------------------------- /deps/libmnl/include/linux/netfilter/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_HEADERS = nfnetlink_conntrack.h 2 | -------------------------------------------------------------------------------- /deps/libmnl/include/linux/netlink.h: -------------------------------------------------------------------------------- 1 | #ifndef __LINUX_NETLINK_H 2 | #define __LINUX_NETLINK_H 3 | 4 | #include /* for __kernel_sa_family_t */ 5 | #include 6 | 7 | #define NETLINK_ROUTE 0 /* Routing/device hook */ 8 | #define NETLINK_UNUSED 1 /* Unused number */ 9 | #define NETLINK_USERSOCK 2 /* Reserved for user mode socket protocols */ 10 | #define NETLINK_FIREWALL 3 /* Unused number, formerly ip_queue */ 11 | #define NETLINK_SOCK_DIAG 4 /* socket monitoring */ 12 | #define NETLINK_NFLOG 5 /* netfilter/iptables ULOG */ 13 | #define NETLINK_XFRM 6 /* ipsec */ 14 | #define NETLINK_SELINUX 7 /* SELinux event notifications */ 15 | #define NETLINK_ISCSI 8 /* Open-iSCSI */ 16 | #define NETLINK_AUDIT 9 /* auditing */ 17 | #define NETLINK_FIB_LOOKUP 10 18 | #define NETLINK_CONNECTOR 11 19 | #define NETLINK_NETFILTER 12 /* netfilter subsystem */ 20 | #define NETLINK_IP6_FW 13 21 | #define NETLINK_DNRTMSG 14 /* DECnet routing messages */ 22 | #define NETLINK_KOBJECT_UEVENT 15 /* Kernel messages to userspace */ 23 | #define NETLINK_GENERIC 16 24 | /* leave room for NETLINK_DM (DM Events) */ 25 | #define NETLINK_SCSITRANSPORT 18 /* SCSI Transports */ 26 | #define NETLINK_ECRYPTFS 19 27 | #define NETLINK_RDMA 20 28 | #define NETLINK_CRYPTO 21 /* Crypto layer */ 29 | 30 | #define NETLINK_INET_DIAG NETLINK_SOCK_DIAG 31 | 32 | #define MAX_LINKS 32 33 | 34 | struct sockaddr_nl { 35 | __kernel_sa_family_t nl_family; /* AF_NETLINK */ 36 | unsigned short nl_pad; /* zero */ 37 | __u32 nl_pid; /* port ID */ 38 | __u32 nl_groups; /* multicast groups mask */ 39 | }; 40 | 41 | struct nlmsghdr { 42 | __u32 nlmsg_len; /* Length of message including header */ 43 | __u16 nlmsg_type; /* Message content */ 44 | __u16 nlmsg_flags; /* Additional flags */ 45 | __u32 nlmsg_seq; /* Sequence number */ 46 | __u32 nlmsg_pid; /* Sending process port ID */ 47 | }; 48 | 49 | /* Flags values */ 50 | 51 | #define NLM_F_REQUEST 1 /* It is request message. */ 52 | #define NLM_F_MULTI 2 /* Multipart message, terminated by NLMSG_DONE */ 53 | #define NLM_F_ACK 4 /* Reply with ack, with zero or error code */ 54 | #define NLM_F_ECHO 8 /* Echo this request */ 55 | #define NLM_F_DUMP_INTR 16 /* Dump was inconsistent due to sequence change */ 56 | 57 | /* Modifiers to GET request */ 58 | #define NLM_F_ROOT 0x100 /* specify tree root */ 59 | #define NLM_F_MATCH 0x200 /* return all matching */ 60 | #define NLM_F_ATOMIC 0x400 /* atomic GET */ 61 | #define NLM_F_DUMP (NLM_F_ROOT|NLM_F_MATCH) 62 | 63 | /* Modifiers to NEW request */ 64 | #define NLM_F_REPLACE 0x100 /* Override existing */ 65 | #define NLM_F_EXCL 0x200 /* Do not touch, if it exists */ 66 | #define NLM_F_CREATE 0x400 /* Create, if it does not exist */ 67 | #define NLM_F_APPEND 0x800 /* Add to end of list */ 68 | 69 | /* 70 | 4.4BSD ADD NLM_F_CREATE|NLM_F_EXCL 71 | 4.4BSD CHANGE NLM_F_REPLACE 72 | 73 | True CHANGE NLM_F_CREATE|NLM_F_REPLACE 74 | Append NLM_F_CREATE 75 | Check NLM_F_EXCL 76 | */ 77 | 78 | #define NLMSG_ALIGNTO 4U 79 | #define NLMSG_ALIGN(len) ( ((len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) ) 80 | #define NLMSG_HDRLEN ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr))) 81 | #define NLMSG_LENGTH(len) ((len)+NLMSG_ALIGN(NLMSG_HDRLEN)) 82 | #define NLMSG_SPACE(len) NLMSG_ALIGN(NLMSG_LENGTH(len)) 83 | #define NLMSG_DATA(nlh) ((void*)(((char*)nlh) + NLMSG_LENGTH(0))) 84 | #define NLMSG_NEXT(nlh,len) ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \ 85 | (struct nlmsghdr*)(((char*)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len))) 86 | #define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \ 87 | (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \ 88 | (nlh)->nlmsg_len <= (len)) 89 | #define NLMSG_PAYLOAD(nlh,len) ((nlh)->nlmsg_len - NLMSG_SPACE((len))) 90 | 91 | #define NLMSG_NOOP 0x1 /* Nothing. */ 92 | #define NLMSG_ERROR 0x2 /* Error */ 93 | #define NLMSG_DONE 0x3 /* End of a dump */ 94 | #define NLMSG_OVERRUN 0x4 /* Data lost */ 95 | 96 | #define NLMSG_MIN_TYPE 0x10 /* < 0x10: reserved control messages */ 97 | 98 | struct nlmsgerr { 99 | int error; 100 | struct nlmsghdr msg; 101 | }; 102 | 103 | #define NETLINK_ADD_MEMBERSHIP 1 104 | #define NETLINK_DROP_MEMBERSHIP 2 105 | #define NETLINK_PKTINFO 3 106 | #define NETLINK_BROADCAST_ERROR 4 107 | #define NETLINK_NO_ENOBUFS 5 108 | 109 | struct nl_pktinfo { 110 | __u32 group; 111 | }; 112 | 113 | #define NET_MAJOR 36 /* Major 36 is reserved for networking */ 114 | 115 | enum { 116 | NETLINK_UNCONNECTED = 0, 117 | NETLINK_CONNECTED, 118 | }; 119 | 120 | /* 121 | * <------- NLA_HDRLEN ------> <-- NLA_ALIGN(payload)--> 122 | * +---------------------+- - -+- - - - - - - - - -+- - -+ 123 | * | Header | Pad | Payload | Pad | 124 | * | (struct nlattr) | ing | | ing | 125 | * +---------------------+- - -+- - - - - - - - - -+- - -+ 126 | * <-------------- nlattr->nla_len --------------> 127 | */ 128 | 129 | struct nlattr { 130 | __u16 nla_len; 131 | __u16 nla_type; 132 | }; 133 | 134 | /* 135 | * nla_type (16 bits) 136 | * +---+---+-------------------------------+ 137 | * | N | O | Attribute Type | 138 | * +---+---+-------------------------------+ 139 | * N := Carries nested attributes 140 | * O := Payload stored in network byte order 141 | * 142 | * Note: The N and O flag are mutually exclusive. 143 | */ 144 | #define NLA_F_NESTED (1 << 15) 145 | #define NLA_F_NET_BYTEORDER (1 << 14) 146 | #define NLA_TYPE_MASK ~(NLA_F_NESTED | NLA_F_NET_BYTEORDER) 147 | 148 | #define NLA_ALIGNTO 4 149 | #define NLA_ALIGN(len) (((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1)) 150 | #define NLA_HDRLEN ((int) NLA_ALIGN(sizeof(struct nlattr))) 151 | 152 | 153 | #endif /* __LINUX_NETLINK_H */ 154 | -------------------------------------------------------------------------------- /deps/libmnl/include/linux/socket.h: -------------------------------------------------------------------------------- 1 | #ifndef _LINUX_SOCKET_H 2 | #define _LINUX_SOCKET_H 3 | 4 | /* 5 | * Desired design of maximum size and alignment (see RFC2553) 6 | */ 7 | #define _K_SS_MAXSIZE 128 /* Implementation specific max size */ 8 | #define _K_SS_ALIGNSIZE (__alignof__ (struct sockaddr *)) 9 | /* Implementation specific desired alignment */ 10 | 11 | typedef unsigned short __kernel_sa_family_t; 12 | 13 | struct __kernel_sockaddr_storage { 14 | __kernel_sa_family_t ss_family; /* address family */ 15 | /* Following field(s) are implementation specific */ 16 | char __data[_K_SS_MAXSIZE - sizeof(unsigned short)]; 17 | /* space to achieve desired size, */ 18 | /* _SS_MAXSIZE value minus size of ss_family */ 19 | } __attribute__ ((aligned(_K_SS_ALIGNSIZE))); /* force desired alignment */ 20 | 21 | #endif /* _LINUX_SOCKET_H */ 22 | -------------------------------------------------------------------------------- /deps/libmnl/libmnl.pc.in: -------------------------------------------------------------------------------- 1 | # libmnl pkg-config file 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | libdir=@libdir@ 6 | includedir=@includedir@ 7 | 8 | Name: libmnl 9 | Description: Minimalistic Netlink communication library 10 | URL: http://netfilter.org/projects/libmnl/ 11 | Version: @VERSION@ 12 | Requires: 13 | Conflicts: 14 | Libs: -L${libdir} -lmnl 15 | Cflags: -I${includedir} 16 | -------------------------------------------------------------------------------- /deps/libmnl/m4/.gitignore: -------------------------------------------------------------------------------- 1 | /libtool.m4 2 | /lt*.m4 3 | -------------------------------------------------------------------------------- /deps/libmnl/m4/gcc4_visibility.m4: -------------------------------------------------------------------------------- 1 | 2 | # GCC 4.x -fvisibility=hidden 3 | 4 | AC_DEFUN([CHECK_GCC_FVISIBILITY], [ 5 | AC_LANG_PUSH([C]) 6 | saved_CFLAGS="$CFLAGS" 7 | CFLAGS="$saved_CFLAGS -fvisibility=hidden" 8 | AC_CACHE_CHECK([whether compiler accepts -fvisibility=hidden], 9 | [ac_cv_fvisibility_hidden], AC_COMPILE_IFELSE( 10 | [AC_LANG_SOURCE()], 11 | [ac_cv_fvisibility_hidden=yes], 12 | [ac_cv_fvisibility_hidden=no] 13 | )) 14 | if test "$ac_cv_fvisibility_hidden" = "yes"; then 15 | AC_DEFINE([HAVE_VISIBILITY_HIDDEN], [1], 16 | [True if compiler supports -fvisibility=hidden]) 17 | AC_SUBST([GCC_FVISIBILITY_HIDDEN], [-fvisibility=hidden]) 18 | fi 19 | CFLAGS="$saved_CFLAGS" 20 | AC_LANG_POP([C]) 21 | ]) 22 | -------------------------------------------------------------------------------- /deps/libmnl/src/Makefile.am: -------------------------------------------------------------------------------- 1 | include $(top_srcdir)/Make_global.am 2 | lib_LTLIBRARIES = libmnl.la 3 | 4 | libmnl_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libmnl.map -version-info $(LIBVERSION) 5 | libmnl_la_SOURCES = socket.c callback.c nlmsg.c attr.c internal.h libmnl.map 6 | -------------------------------------------------------------------------------- /deps/libmnl/src/internal.h: -------------------------------------------------------------------------------- 1 | #ifndef INTERNAL_H 2 | #define INTERNAL_H 1 3 | 4 | #include "config.h" 5 | #ifdef HAVE_VISIBILITY_HIDDEN 6 | # define EXPORT_SYMBOL __attribute__((visibility("default"))) 7 | #else 8 | # define EXPORT_SYMBOL 9 | #endif 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /deps/libmnl/src/libmnl.map: -------------------------------------------------------------------------------- 1 | LIBMNL_1.0 { 2 | global: 3 | mnl_attr_get_len; 4 | mnl_attr_get_payload; 5 | mnl_attr_get_payload_len; 6 | mnl_attr_get_str; 7 | mnl_attr_get_type; 8 | mnl_attr_get_u16; 9 | mnl_attr_get_u32; 10 | mnl_attr_get_u64; 11 | mnl_attr_get_u8; 12 | mnl_attr_nest_end; 13 | mnl_attr_nest_start; 14 | mnl_attr_nest_start_check; 15 | mnl_attr_nest_cancel; 16 | mnl_attr_next; 17 | mnl_attr_ok; 18 | mnl_attr_parse; 19 | mnl_attr_parse_nested; 20 | mnl_attr_put; 21 | mnl_attr_put_str; 22 | mnl_attr_put_strz; 23 | mnl_attr_put_u16; 24 | mnl_attr_put_u32; 25 | mnl_attr_put_u64; 26 | mnl_attr_put_u8; 27 | mnl_attr_put_check; 28 | mnl_attr_put_str_check; 29 | mnl_attr_put_strz_check; 30 | mnl_attr_put_u16_check; 31 | mnl_attr_put_u32_check; 32 | mnl_attr_put_u64_check; 33 | mnl_attr_put_u8_check; 34 | mnl_attr_type_valid; 35 | mnl_attr_validate; 36 | mnl_attr_validate2; 37 | mnl_cb_run; 38 | mnl_cb_run2; 39 | mnl_nlmsg_fprintf; 40 | mnl_nlmsg_get_payload; 41 | mnl_nlmsg_get_payload_len; 42 | mnl_nlmsg_get_payload_offset; 43 | mnl_nlmsg_get_payload_tail; 44 | mnl_nlmsg_next; 45 | mnl_nlmsg_ok; 46 | mnl_nlmsg_portid_ok; 47 | mnl_nlmsg_put_extra_header; 48 | mnl_nlmsg_put_header; 49 | mnl_nlmsg_seq_ok; 50 | mnl_nlmsg_size; 51 | mnl_nlmsg_batch_start; 52 | mnl_nlmsg_batch_stop; 53 | mnl_nlmsg_batch_next; 54 | mnl_nlmsg_batch_size; 55 | mnl_nlmsg_batch_reset; 56 | mnl_nlmsg_batch_current; 57 | mnl_nlmsg_batch_head; 58 | mnl_nlmsg_batch_is_empty; 59 | mnl_socket_bind; 60 | mnl_socket_close; 61 | mnl_socket_get_fd; 62 | mnl_socket_get_portid; 63 | mnl_socket_getsockopt; 64 | mnl_socket_open; 65 | mnl_socket_recvfrom; 66 | mnl_socket_sendto; 67 | mnl_socket_setsockopt; 68 | 69 | local: *; 70 | }; 71 | 72 | LIBMNL_1.1 { 73 | mnl_attr_parse_payload; 74 | } LIBMNL_1.0; 75 | 76 | LIBMNL_1.2 { 77 | mnl_socket_open2; 78 | mnl_socket_fdopen; 79 | } LIBMNL_1.1; 80 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/.gitignore: -------------------------------------------------------------------------------- 1 | .deps/ 2 | .libs/ 3 | Makefile 4 | Makefile.in 5 | .dirstamp 6 | *.o 7 | *.la 8 | *.lo 9 | 10 | /aclocal.m4 11 | /autom4te.cache/ 12 | /build-aux/ 13 | /config.* 14 | /configure 15 | /libtool 16 | /stamp-h1 17 | 18 | /doxygen/doxygen.cfg 19 | /libnetfilter_queue.pc 20 | 21 | /examples/nf-queue 22 | /doxygen/doxyfile.stamp 23 | /doxygen/html/ 24 | /doxygen/man/ 25 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/Make_global.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I${top_srcdir}/include ${LIBNFNETLINK_CFLAGS} ${LIBMNL_CFLAGS} 2 | AM_CFLAGS = -Wall ${GCC_FVISIBILITY_HIDDEN} 3 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/Makefile.am: -------------------------------------------------------------------------------- 1 | ACLOCAL_AMFLAGS = -I m4 2 | 3 | EXTRA_DIST = $(man_MANS) include/linux 4 | 5 | SUBDIRS = src utils include examples doxygen 6 | 7 | man_MANS = #nfnetlink_queue.3 nfnetlink_queue.7 8 | 9 | pkgconfigdir = $(libdir)/pkgconfig 10 | pkgconfig_DATA = libnetfilter_queue.pc 11 | 12 | EXTRA_DIST += Make_global.am 13 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | 3 | include () 4 | { 5 | # If we keep a copy of the kernel header in the SVN tree, we'll have 6 | # to worry about synchronization issues forever. Instead, we just copy 7 | # the headers that we need from the lastest kernel version at autogen 8 | # stage. 9 | 10 | INCLUDEDIR=${KERNEL_DIR:-/lib/modules/`uname -r`/build}/include/linux 11 | if [ -f $INCLUDEDIR/netfilter/nfnetlink_queue.h ] 12 | then 13 | TARGET=include/libnetfilter_queue/linux_nfnetlink_queue.h 14 | echo "Copying nfnetlink_queue.h to linux_nfnetlink_queue.h" 15 | cp $INCLUDEDIR/netfilter/nfnetlink_queue.h $TARGET 16 | TEMP=`tempfile` 17 | sed 's/linux\/netfilter\/nfnetlink.h/libnfnetlink\/linux_nfnetlink.h/g' $TARGET > $TEMP 18 | # Add aligned_u64 definition after #define _NFNETLINK_QUEUE_H 19 | awk '{ 20 | if ( $0 == "#define _NFNETLINK_QUEUE_H" ) { 21 | print $0 22 | getline 23 | print $0 24 | print "#ifndef aligned_u64" 25 | print "#define aligned_u64 unsigned long long __attribute__((aligned(8)))" 26 | print "#endif" 27 | } 28 | 29 | print $0 30 | }' $TEMP > $TARGET 31 | else 32 | echo "can't find nfnetlink_queue.h kernel file in $INCLUDEDIR" 33 | exit 1 34 | fi 35 | } 36 | 37 | [ "x$1" = "xdistrib" ] && include 38 | autoreconf -fi 39 | rm -Rf autom4te.cache 40 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/configure.ac: -------------------------------------------------------------------------------- 1 | dnl Process this file with autoconf to create configure. 2 | 3 | AC_INIT([libnetfilter_queue], [1.0.5]) 4 | AC_CONFIG_AUX_DIR([build-aux]) 5 | AC_CANONICAL_HOST 6 | AC_CONFIG_MACRO_DIR([m4]) 7 | AC_CONFIG_HEADERS([config.h]) 8 | 9 | AM_INIT_AUTOMAKE([-Wall foreign subdir-objects 10 | tar-pax no-dist-gzip dist-xz 1.6]) 11 | m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) 12 | 13 | dnl kernel style compile messages 14 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 15 | 16 | AC_ARG_ENABLE([html-doc], 17 | AS_HELP_STRING([--enable-html-doc], [Enable html documentation]), 18 | [], [enable_html_doc=no]) 19 | AM_CONDITIONAL([BUILD_HTML], [test "$enable_html_doc" = yes]) 20 | AS_IF([test "$enable_html_doc" = yes], 21 | [AC_SUBST(GEN_HTML, YES)], 22 | [AC_SUBST(GEN_HTML, NO)]) 23 | 24 | AC_ARG_ENABLE([man-pages], 25 | AS_HELP_STRING([--disable-man-pages], [Disable man page documentation]), 26 | [], [enable_man_pages=yes]) 27 | AM_CONDITIONAL([BUILD_MAN], [test "$enable_man_pages" = yes]) 28 | AS_IF([test "$enable_man_pages" = yes], 29 | [AC_SUBST(GEN_MAN, YES)], 30 | [AC_SUBST(GEN_MAN, NO)]) 31 | 32 | AC_PROG_CC 33 | AM_PROG_CC_C_O 34 | AC_DISABLE_STATIC 35 | AM_PROG_LIBTOOL 36 | AC_PROG_INSTALL 37 | CHECK_GCC_FVISIBILITY 38 | 39 | case "$host" in 40 | *-*-linux* | *-*-uclinux*) ;; 41 | *) AC_MSG_ERROR([Linux only, dude!]);; 42 | esac 43 | 44 | dnl Dependencies 45 | PKG_CHECK_MODULES([LIBNFNETLINK], [libnfnetlink >= 0.0.41]) 46 | PKG_CHECK_MODULES([LIBMNL], [libmnl >= 1.0.3]) 47 | 48 | AS_IF([test "$enable_man_pages" = no -a "$enable_html_doc" = no], 49 | [with_doxygen=no], [with_doxygen=yes]) 50 | 51 | AS_IF([test "x$with_doxygen" != xno], [ 52 | AC_CHECK_PROGS([DOXYGEN], [doxygen], [""]) 53 | AC_CHECK_PROGS([DOT], [dot], [""]) 54 | AS_IF([test "x$DOT" != "x"], 55 | [AC_SUBST(HAVE_DOT, YES)], 56 | [AC_SUBST(HAVE_DOT, NO)]) 57 | ]) 58 | 59 | AM_CONDITIONAL([HAVE_DOXYGEN], [test -n "$DOXYGEN"]) 60 | AS_IF([test "x$DOXYGEN" = x], [ 61 | AS_IF([test "x$with_doxygen" != xno], [ 62 | dnl Only run doxygen Makefile if doxygen installed 63 | AC_MSG_WARN([Doxygen not found - not building documentation]) 64 | enable_html_doc=no 65 | enable_man_pages=no 66 | ]) 67 | ], [ 68 | dnl Warn user if html docs will be missing diagrams 69 | AS_IF([test "$enable_html_doc" = yes -a -z "$DOT"], 70 | AC_MSG_WARN([Dot not found - install graphviz to get interactive diagrams in HTML])) 71 | ]) 72 | 73 | dnl Output the makefiles 74 | AC_CONFIG_FILES([Makefile src/Makefile utils/Makefile examples/Makefile 75 | libnetfilter_queue.pc 76 | include/Makefile include/libnetfilter_queue/Makefile 77 | doxygen/Makefile doxygen/doxygen.cfg 78 | include/linux/Makefile include/linux/netfilter/Makefile]) 79 | 80 | AC_OUTPUT 81 | 82 | echo " 83 | libnetfilter_queue configuration: 84 | man pages: ${enable_man_pages} 85 | html docs: ${enable_html_doc}" 86 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/doxygen/Makefile.am: -------------------------------------------------------------------------------- 1 | if HAVE_DOXYGEN 2 | 3 | doc_srcs = $(top_srcdir)/src/libnetfilter_queue.c\ 4 | $(top_srcdir)/src/nlmsg.c\ 5 | $(top_srcdir)/src/extra/checksum.c\ 6 | $(top_srcdir)/src/extra/ipv4.c\ 7 | $(top_srcdir)/src/extra/pktbuff.c\ 8 | $(top_srcdir)/src/extra/ipv6.c\ 9 | $(top_srcdir)/src/extra/tcp.c\ 10 | $(top_srcdir)/src/extra/udp.c\ 11 | $(top_srcdir)/src/extra/icmp.c 12 | 13 | doxyfile.stamp: $(doc_srcs) Makefile build_man.sh 14 | rm -rf html man 15 | doxygen doxygen.cfg >/dev/null 16 | 17 | if BUILD_MAN 18 | $(abs_top_srcdir)/doxygen/build_man.sh libnetfilter_queue libnetfilter_queue.c 19 | endif 20 | 21 | touch doxyfile.stamp 22 | 23 | CLEANFILES = doxyfile.stamp 24 | 25 | all-local: doxyfile.stamp 26 | clean-local: 27 | rm -rf man html 28 | install-data-local: 29 | if BUILD_MAN 30 | mkdir -p $(DESTDIR)$(mandir)/man3 31 | cp --no-dereference --preserve=links,mode,timestamps man/man3/*.3\ 32 | $(DESTDIR)$(mandir)/man3/ 33 | endif 34 | if BUILD_HTML 35 | mkdir -p $(DESTDIR)$(htmldir) 36 | cp --no-dereference --preserve=links,mode,timestamps html/*\ 37 | $(DESTDIR)$(htmldir) 38 | endif 39 | 40 | # make distcheck needs uninstall-local 41 | uninstall-local: 42 | rm -rf $(DESTDIR)$(mandir) man html doxyfile.stamp $(DESTDIR)$(htmldir) 43 | endif 44 | 45 | EXTRA_DIST = build_man.sh 46 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/doxygen/doxygen.cfg.in: -------------------------------------------------------------------------------- 1 | # Difference with default Doxyfile 1.8.20 2 | PROJECT_NAME = @PACKAGE@ 3 | PROJECT_NUMBER = @VERSION@ 4 | ABBREVIATE_BRIEF = 5 | FULL_PATH_NAMES = NO 6 | TAB_SIZE = 8 7 | OPTIMIZE_OUTPUT_FOR_C = YES 8 | INPUT = @abs_top_srcdir@/src 9 | FILE_PATTERNS = *.c 10 | RECURSIVE = YES 11 | EXCLUDE_SYMBOLS = EXPORT_SYMBOL \ 12 | tcp_word_hdr \ 13 | nfq_handle \ 14 | nfq_data \ 15 | nfq_q_handle \ 16 | tcp_flag_word 17 | EXAMPLE_PATTERNS = 18 | INPUT_FILTER = "sed 's/EXPORT_SYMBOL//g'" 19 | SOURCE_BROWSER = YES 20 | ALPHABETICAL_INDEX = NO 21 | SEARCHENGINE = NO 22 | GENERATE_LATEX = NO 23 | LATEX_CMD_NAME = latex 24 | GENERATE_MAN = @GEN_MAN@ 25 | GENERATE_HTML = @GEN_HTML@ 26 | MAN_LINKS = YES 27 | HAVE_DOT = @HAVE_DOT@ 28 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/examples/Makefile.am: -------------------------------------------------------------------------------- 1 | include ${top_srcdir}/Make_global.am 2 | 3 | check_PROGRAMS = nf-queue 4 | 5 | nf_queue_SOURCES = nf-queue.c 6 | nf_queue_LDADD = ../src/libnetfilter_queue.la -lmnl 7 | nf_queue_LDFLAGS = -dynamic 8 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/include/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS= libnetfilter_queue linux 2 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/include/libnetfilter_queue/Makefile.am: -------------------------------------------------------------------------------- 1 | pkginclude_HEADERS = libnetfilter_queue.h \ 2 | linux_nfnetlink_queue.h \ 3 | libnetfilter_queue_icmp.h \ 4 | libnetfilter_queue_ipv4.h \ 5 | libnetfilter_queue_ipv6.h \ 6 | libnetfilter_queue_tcp.h \ 7 | libnetfilter_queue_udp.h \ 8 | pktbuff.h 9 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/include/libnetfilter_queue/libnetfilter_queue.h: -------------------------------------------------------------------------------- 1 | /* libnfqnetlink.h: Header file for the Netfilter Queue library. 2 | * 3 | * (C) 2005 by Harald Welte 4 | * 5 | * 6 | * Changelog : 7 | * (2005/08/11) added parsing function (Eric Leblond ) 8 | * 9 | * This software may be used and distributed according to the terms 10 | * of the GNU General Public License, incorporated herein by reference. 11 | */ 12 | 13 | #ifndef __LIBCTNETLINK_H 14 | #define __LIBCTNETLINK_H 15 | 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | struct nfq_handle; 26 | struct nfq_q_handle; 27 | struct nfq_data; 28 | 29 | extern int nfq_errno; 30 | 31 | extern struct nfnl_handle *nfq_nfnlh(struct nfq_handle *h); 32 | extern int nfq_fd(struct nfq_handle *h); 33 | 34 | typedef int nfq_callback(struct nfq_q_handle *gh, struct nfgenmsg *nfmsg, 35 | struct nfq_data *nfad, void *data); 36 | 37 | 38 | extern struct nfq_handle *nfq_open(void); 39 | extern struct nfq_handle *nfq_open_nfnl(struct nfnl_handle *nfnlh); 40 | extern int nfq_close(struct nfq_handle *h); 41 | 42 | extern int nfq_bind_pf(struct nfq_handle *h, uint16_t pf); 43 | extern int nfq_unbind_pf(struct nfq_handle *h, uint16_t pf); 44 | 45 | extern struct nfq_q_handle *nfq_create_queue(struct nfq_handle *h, 46 | uint16_t num, 47 | nfq_callback *cb, 48 | void *data); 49 | extern int nfq_destroy_queue(struct nfq_q_handle *qh); 50 | 51 | extern int nfq_handle_packet(struct nfq_handle *h, char *buf, int len); 52 | 53 | extern int nfq_set_mode(struct nfq_q_handle *qh, 54 | uint8_t mode, unsigned int len); 55 | 56 | int nfq_set_queue_maxlen(struct nfq_q_handle *qh, 57 | uint32_t queuelen); 58 | 59 | extern int nfq_set_queue_flags(struct nfq_q_handle *qh, 60 | uint32_t mask, uint32_t flags); 61 | 62 | extern int nfq_set_verdict(struct nfq_q_handle *qh, 63 | uint32_t id, 64 | uint32_t verdict, 65 | uint32_t data_len, 66 | const unsigned char *buf); 67 | 68 | extern int nfq_set_verdict2(struct nfq_q_handle *qh, 69 | uint32_t id, 70 | uint32_t verdict, 71 | uint32_t mark, 72 | uint32_t datalen, 73 | const unsigned char *buf); 74 | 75 | extern int nfq_set_verdict_batch(struct nfq_q_handle *qh, 76 | uint32_t id, 77 | uint32_t verdict); 78 | 79 | extern int nfq_set_verdict_batch2(struct nfq_q_handle *qh, 80 | uint32_t id, 81 | uint32_t verdict, 82 | uint32_t mark); 83 | 84 | extern __attribute__((deprecated)) 85 | int nfq_set_verdict_mark(struct nfq_q_handle *qh, 86 | uint32_t id, 87 | uint32_t verdict, 88 | uint32_t mark, 89 | uint32_t datalen, 90 | const unsigned char *buf); 91 | 92 | /* message parsing function */ 93 | 94 | extern struct nfqnl_msg_packet_hdr * 95 | nfq_get_msg_packet_hdr(struct nfq_data *nfad); 96 | 97 | extern uint32_t nfq_get_nfmark(struct nfq_data *nfad); 98 | 99 | extern int nfq_get_timestamp(struct nfq_data *nfad, struct timeval *tv); 100 | 101 | /* return 0 if not set */ 102 | extern uint32_t nfq_get_indev(struct nfq_data *nfad); 103 | extern uint32_t nfq_get_physindev(struct nfq_data *nfad); 104 | extern uint32_t nfq_get_outdev(struct nfq_data *nfad); 105 | extern uint32_t nfq_get_physoutdev(struct nfq_data *nfad); 106 | extern uint32_t nfq_get_skbinfo(struct nfq_data *nfad); 107 | extern int nfq_get_uid(struct nfq_data *nfad, uint32_t *uid); 108 | extern int nfq_get_gid(struct nfq_data *nfad, uint32_t *gid); 109 | extern int nfq_get_secctx(struct nfq_data *nfad, unsigned char **secdata); 110 | 111 | extern int nfq_get_indev_name(struct nlif_handle *nlif_handle, 112 | struct nfq_data *nfad, char *name); 113 | extern int nfq_get_physindev_name(struct nlif_handle *nlif_handle, 114 | struct nfq_data *nfad, char *name); 115 | extern int nfq_get_outdev_name(struct nlif_handle *nlif_handle, 116 | struct nfq_data *nfad, char *name); 117 | extern int nfq_get_physoutdev_name(struct nlif_handle *nlif_handle, 118 | struct nfq_data *nfad, char *name); 119 | 120 | extern struct nfqnl_msg_packet_hw *nfq_get_packet_hw(struct nfq_data *nfad); 121 | 122 | /* return -1 if problem, length otherwise */ 123 | extern int nfq_get_payload(struct nfq_data *nfad, unsigned char **data); 124 | 125 | enum { 126 | NFQ_XML_HW = (1 << 0), 127 | NFQ_XML_MARK = (1 << 1), 128 | NFQ_XML_DEV = (1 << 2), 129 | NFQ_XML_PHYSDEV = (1 << 3), 130 | NFQ_XML_PAYLOAD = (1 << 4), 131 | NFQ_XML_TIME = (1 << 5), 132 | NFQ_XML_UID = (1 << 6), 133 | NFQ_XML_GID = (1 << 7), 134 | NFQ_XML_SECCTX = (1 << 8), 135 | NFQ_XML_ALL = ~0U, 136 | }; 137 | 138 | extern int nfq_snprintf_xml(char *buf, size_t len, struct nfq_data *tb, int flags); 139 | 140 | /* 141 | * New API based on libmnl 142 | */ 143 | 144 | void nfq_nlmsg_cfg_put_cmd(struct nlmsghdr *nlh, uint16_t pf, uint8_t cmd); 145 | void nfq_nlmsg_cfg_put_params(struct nlmsghdr *nlh, uint8_t mode, int range); 146 | void nfq_nlmsg_cfg_put_qmaxlen(struct nlmsghdr *nlh, uint32_t qmaxlen); 147 | 148 | void nfq_nlmsg_verdict_put(struct nlmsghdr *nlh, int id, int verdict); 149 | void nfq_nlmsg_verdict_put_mark(struct nlmsghdr *nlh, uint32_t mark); 150 | void nfq_nlmsg_verdict_put_pkt(struct nlmsghdr *nlh, const void *pkt, uint32_t pktlen); 151 | 152 | int nfq_nlmsg_parse(const struct nlmsghdr *nlh, struct nlattr **attr); 153 | struct nlmsghdr *nfq_nlmsg_put(char *buf, int type, uint32_t queue_num); 154 | struct nlmsghdr *nfq_nlmsg_put2(char *buf, int type, uint32_t queue_num, uint16_t flags); 155 | 156 | #ifdef __cplusplus 157 | } /* extern "C" */ 158 | #endif 159 | 160 | #endif /* __LIBNFQNETLINK_H */ 161 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/include/libnetfilter_queue/libnetfilter_queue_icmp.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIBNFQUEUE_ICMP_H_ 2 | #define _LIBNFQUEUE_ICMP_H_ 3 | 4 | struct pkt_buff; 5 | 6 | struct icmphdr *nfq_icmp_get_hdr(struct pkt_buff *pktb); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/include/libnetfilter_queue/libnetfilter_queue_ipv4.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIBNFQUEUE_IPV4_ 2 | #define _LIBNFQUEUE_IPV4_ 3 | 4 | struct pkt_buff; 5 | struct iphdr; 6 | 7 | struct iphdr *nfq_ip_get_hdr(struct pkt_buff *pktb); 8 | int nfq_ip_set_transport_header(struct pkt_buff *pktb, struct iphdr *iph); 9 | void nfq_ip_set_checksum(struct iphdr *iph); 10 | int nfq_ip_mangle(struct pkt_buff *pktb, unsigned int dataoff, unsigned int match_offset, unsigned int match_len, const char *rep_buffer, unsigned int rep_len); 11 | int nfq_ip_snprintf(char *buf, size_t size, const struct iphdr *iph); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/include/libnetfilter_queue/libnetfilter_queue_ipv6.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIBNFQUEUE_H_ 2 | #define _LIBNFQUEUE_H_ 3 | 4 | struct pkt_buff; 5 | struct ip6_hdr; 6 | 7 | struct ip6_hdr *nfq_ip6_get_hdr(struct pkt_buff *pktb); 8 | int nfq_ip6_set_transport_header(struct pkt_buff *pktb, struct ip6_hdr *iph, uint8_t target); 9 | int nfq_ip6_mangle(struct pkt_buff *pktb, unsigned int dataoff,unsigned int match_offset, unsigned int match_len,const char *rep_buffer, unsigned int rep_len); 10 | int nfq_ip6_snprintf(char *buf, size_t size, const struct ip6_hdr *ip6h); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/include/libnetfilter_queue/libnetfilter_queue_tcp.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIBNFQUEUE_TCP_H_ 2 | #define _LIBNFQUEUE_TCP_H_ 3 | 4 | struct pkt_buff; 5 | 6 | struct tcphdr *nfq_tcp_get_hdr(struct pkt_buff *pktb); 7 | void *nfq_tcp_get_payload(struct tcphdr *tcph, struct pkt_buff *pktb); 8 | unsigned int nfq_tcp_get_payload_len(struct tcphdr *tcph, struct pkt_buff *pktb); 9 | 10 | struct iphdr; 11 | struct ip6_hdr; 12 | 13 | void nfq_tcp_compute_checksum_ipv4(struct tcphdr *tcph, struct iphdr *iph); 14 | void nfq_tcp_compute_checksum_ipv6(struct tcphdr *tcph, struct ip6_hdr *ip6h); 15 | 16 | int nfq_tcp_mangle_ipv4(struct pkt_buff *pktb, unsigned int match_offset, unsigned int match_len, const char *rep_buffer, unsigned int rep_len); 17 | int nfq_tcp_mangle_ipv6(struct pkt_buff *pktb, unsigned int match_offset, unsigned int match_len, const char *rep_buffer, unsigned int rep_len); 18 | 19 | int nfq_tcp_snprintf(char *buf, size_t size, const struct tcphdr *tcp); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/include/libnetfilter_queue/libnetfilter_queue_udp.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIBNFQUEUE_UDP_H_ 2 | #define _LIBNFQUEUE_UDP_H_ 3 | 4 | struct pkt_buff; 5 | 6 | struct udphdr *nfq_udp_get_hdr(struct pkt_buff *pktb); 7 | void *nfq_udp_get_payload(struct udphdr *udph, struct pkt_buff *pktb); 8 | unsigned int nfq_udp_get_payload_len(struct udphdr *udph, struct pkt_buff *pktb); 9 | 10 | void nfq_udp_compute_checksum_ipv4(struct udphdr *udph, struct iphdr *iph); 11 | void nfq_udp_compute_checksum_ipv6(struct udphdr *udph, struct ip6_hdr *ip6h); 12 | 13 | int nfq_udp_mangle_ipv4(struct pkt_buff *pktb, unsigned int match_offset, unsigned int match_len, const char *rep_buffer, unsigned int rep_len); 14 | int nfq_udp_mangle_ipv6(struct pkt_buff *pktb, unsigned int match_offset, unsigned int match_len, const char *rep_buffer, unsigned int rep_len); 15 | 16 | int nfq_udp_snprintf(char *buf, size_t size, const struct udphdr *udp); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/include/libnetfilter_queue/linux_nfnetlink_queue.h: -------------------------------------------------------------------------------- 1 | #ifndef _NFNETLINK_QUEUE_H 2 | #define _NFNETLINK_QUEUE_H 3 | 4 | #warning "libnetfilter_queue/linux_nfnetlink_queue.h is deprecated, add #include to your source code before #include " 5 | 6 | #ifndef aligned_u64 7 | #define aligned_u64 unsigned long long __attribute__((aligned(8))) 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | enum nfqnl_msg_types { 14 | NFQNL_MSG_PACKET, /* packet from kernel to userspace */ 15 | NFQNL_MSG_VERDICT, /* verdict from userspace to kernel */ 16 | NFQNL_MSG_CONFIG, /* connect to a particular queue */ 17 | NFQNL_MSG_VERDICT_BATCH, /* batchv from userspace to kernel */ 18 | 19 | NFQNL_MSG_MAX 20 | }; 21 | 22 | struct nfqnl_msg_packet_hdr { 23 | __be32 packet_id; /* unique ID of packet in queue */ 24 | __be16 hw_protocol; /* hw protocol (network order) */ 25 | __u8 hook; /* netfilter hook */ 26 | } __attribute__ ((packed)); 27 | 28 | struct nfqnl_msg_packet_hw { 29 | __be16 hw_addrlen; 30 | __u16 _pad; 31 | __u8 hw_addr[8]; 32 | }; 33 | 34 | struct nfqnl_msg_packet_timestamp { 35 | __aligned_be64 sec; 36 | __aligned_be64 usec; 37 | }; 38 | 39 | enum nfqnl_attr_type { 40 | NFQA_UNSPEC, 41 | NFQA_PACKET_HDR, 42 | NFQA_VERDICT_HDR, /* nfqnl_msg_verdict_hrd */ 43 | NFQA_MARK, /* __u32 nfmark */ 44 | NFQA_TIMESTAMP, /* nfqnl_msg_packet_timestamp */ 45 | NFQA_IFINDEX_INDEV, /* __u32 ifindex */ 46 | NFQA_IFINDEX_OUTDEV, /* __u32 ifindex */ 47 | NFQA_IFINDEX_PHYSINDEV, /* __u32 ifindex */ 48 | NFQA_IFINDEX_PHYSOUTDEV, /* __u32 ifindex */ 49 | NFQA_HWADDR, /* nfqnl_msg_packet_hw */ 50 | NFQA_PAYLOAD, /* opaque data payload */ 51 | NFQA_CT, /* nfnetlink_conntrack.h */ 52 | NFQA_CT_INFO, /* enum ip_conntrack_info */ 53 | NFQA_CAP_LEN, /* __u32 length of captured packet */ 54 | NFQA_SKB_INFO, /* __u32 skb meta information */ 55 | NFQA_EXP, /* nfnetlink_conntrack.h */ 56 | NFQA_UID, /* __u32 sk uid */ 57 | NFQA_GID, /* __u32 sk gid */ 58 | NFQA_SECCTX, /* security context string */ 59 | 60 | __NFQA_MAX 61 | }; 62 | #define NFQA_MAX (__NFQA_MAX - 1) 63 | 64 | struct nfqnl_msg_verdict_hdr { 65 | __be32 verdict; 66 | __be32 id; 67 | }; 68 | 69 | 70 | enum nfqnl_msg_config_cmds { 71 | NFQNL_CFG_CMD_NONE, 72 | NFQNL_CFG_CMD_BIND, 73 | NFQNL_CFG_CMD_UNBIND, 74 | NFQNL_CFG_CMD_PF_BIND, 75 | NFQNL_CFG_CMD_PF_UNBIND, 76 | }; 77 | 78 | struct nfqnl_msg_config_cmd { 79 | __u8 command; /* nfqnl_msg_config_cmds */ 80 | __u8 _pad; 81 | __be16 pf; /* AF_xxx for PF_[UN]BIND */ 82 | }; 83 | 84 | enum nfqnl_config_mode { 85 | NFQNL_COPY_NONE, 86 | NFQNL_COPY_META, 87 | NFQNL_COPY_PACKET, 88 | }; 89 | 90 | struct nfqnl_msg_config_params { 91 | __be32 copy_range; 92 | __u8 copy_mode; /* enum nfqnl_config_mode */ 93 | } __attribute__ ((packed)); 94 | 95 | 96 | enum nfqnl_attr_config { 97 | NFQA_CFG_UNSPEC, 98 | NFQA_CFG_CMD, /* nfqnl_msg_config_cmd */ 99 | NFQA_CFG_PARAMS, /* nfqnl_msg_config_params */ 100 | NFQA_CFG_QUEUE_MAXLEN, /* __u32 */ 101 | NFQA_CFG_MASK, /* identify which flags to change */ 102 | NFQA_CFG_FLAGS, /* value of these flags (__u32) */ 103 | __NFQA_CFG_MAX 104 | }; 105 | #define NFQA_CFG_MAX (__NFQA_CFG_MAX-1) 106 | 107 | /* Flags for NFQA_CFG_FLAGS */ 108 | #define NFQA_CFG_F_FAIL_OPEN (1 << 0) 109 | #define NFQA_CFG_F_CONNTRACK (1 << 1) 110 | #define NFQA_CFG_F_GSO (1 << 2) 111 | #define NFQA_CFG_F_UID_GID (1 << 3) 112 | #define NFQA_CFG_F_SECCTX (1 << 4) 113 | #define NFQA_CFG_F_MAX (1 << 5) 114 | 115 | /* flags for NFQA_SKB_INFO */ 116 | /* packet appears to have wrong checksums, but they are ok */ 117 | #define NFQA_SKB_CSUMNOTREADY (1 << 0) 118 | /* packet is GSO (i.e., exceeds device mtu) */ 119 | #define NFQA_SKB_GSO (1 << 1) 120 | /* csum not validated (incoming device doesn't support hw checksum, etc.) */ 121 | #define NFQA_SKB_CSUM_NOTVERIFIED (1 << 2) 122 | 123 | #endif /* _NFNETLINK_QUEUE_H */ 124 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/include/libnetfilter_queue/pktbuff.h: -------------------------------------------------------------------------------- 1 | #ifndef _PKTBUFF_H_ 2 | #define _PKTBUFF_H_ 3 | 4 | #include 5 | 6 | struct pkt_buff; 7 | 8 | struct pkt_buff *pktb_alloc(int family, void *data, size_t len, size_t extra); 9 | void pktb_free(struct pkt_buff *pktb); 10 | 11 | struct pkt_buff *pktb_setup_raw(void *pktb, int family, void *data, size_t len, size_t extra); 12 | size_t pktb_head_size(void); 13 | 14 | uint8_t *pktb_data(struct pkt_buff *pktb); 15 | uint32_t pktb_len(struct pkt_buff *pktb); 16 | 17 | void pktb_push(struct pkt_buff *pktb, unsigned int len); 18 | void pktb_pull(struct pkt_buff *pktb, unsigned int len); 19 | void pktb_put(struct pkt_buff *pktb, unsigned int len); 20 | void pktb_trim(struct pkt_buff *pktb, unsigned int len); 21 | unsigned int pktb_tailroom(struct pkt_buff *pktb); 22 | 23 | uint8_t *pktb_mac_header(struct pkt_buff *pktb); 24 | uint8_t *pktb_network_header(struct pkt_buff *pktb); 25 | uint8_t *pktb_transport_header(struct pkt_buff *pktb); 26 | 27 | int pktb_mangle(struct pkt_buff *pktb, int dataoff, unsigned int match_offset, unsigned int match_len, const char *rep_buffer, unsigned int rep_len); 28 | 29 | bool pktb_mangled(const struct pkt_buff *pktb); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/include/linux/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = netfilter 2 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/include/linux/netfilter/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_HEADERS = nfnetlink_queue.h 2 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/include/linux/netfilter/nfnetlink_queue.h: -------------------------------------------------------------------------------- 1 | #ifndef _NFNETLINK_QUEUE_H 2 | #define _NFNETLINK_QUEUE_H 3 | 4 | #include 5 | #include 6 | 7 | enum nfqnl_msg_types { 8 | NFQNL_MSG_PACKET, /* packet from kernel to userspace */ 9 | NFQNL_MSG_VERDICT, /* verdict from userspace to kernel */ 10 | NFQNL_MSG_CONFIG, /* connect to a particular queue */ 11 | NFQNL_MSG_VERDICT_BATCH, /* batchv from userspace to kernel */ 12 | 13 | NFQNL_MSG_MAX 14 | }; 15 | 16 | struct nfqnl_msg_packet_hdr { 17 | __be32 packet_id; /* unique ID of packet in queue */ 18 | __be16 hw_protocol; /* hw protocol (network order) */ 19 | __u8 hook; /* netfilter hook */ 20 | } __attribute__ ((packed)); 21 | 22 | struct nfqnl_msg_packet_hw { 23 | __be16 hw_addrlen; 24 | __u16 _pad; 25 | __u8 hw_addr[8]; 26 | }; 27 | 28 | struct nfqnl_msg_packet_timestamp { 29 | __aligned_be64 sec; 30 | __aligned_be64 usec; 31 | }; 32 | 33 | enum nfqnl_attr_type { 34 | NFQA_UNSPEC, 35 | NFQA_PACKET_HDR, 36 | NFQA_VERDICT_HDR, /* nfqnl_msg_verdict_hrd */ 37 | NFQA_MARK, /* __u32 nfmark */ 38 | NFQA_TIMESTAMP, /* nfqnl_msg_packet_timestamp */ 39 | NFQA_IFINDEX_INDEV, /* __u32 ifindex */ 40 | NFQA_IFINDEX_OUTDEV, /* __u32 ifindex */ 41 | NFQA_IFINDEX_PHYSINDEV, /* __u32 ifindex */ 42 | NFQA_IFINDEX_PHYSOUTDEV, /* __u32 ifindex */ 43 | NFQA_HWADDR, /* nfqnl_msg_packet_hw */ 44 | NFQA_PAYLOAD, /* opaque data payload */ 45 | NFQA_CT, /* nfnetlink_conntrack.h */ 46 | NFQA_CT_INFO, /* enum ip_conntrack_info */ 47 | NFQA_CAP_LEN, /* __u32 length of captured packet */ 48 | NFQA_SKB_INFO, /* __u32 skb meta information */ 49 | NFQA_EXP, /* nfnetlink_conntrack.h */ 50 | NFQA_UID, /* __u32 sk uid */ 51 | NFQA_GID, /* __u32 sk gid */ 52 | NFQA_SECCTX, 53 | 54 | __NFQA_MAX 55 | }; 56 | #define NFQA_MAX (__NFQA_MAX - 1) 57 | 58 | struct nfqnl_msg_verdict_hdr { 59 | __be32 verdict; 60 | __be32 id; 61 | }; 62 | 63 | 64 | enum nfqnl_msg_config_cmds { 65 | NFQNL_CFG_CMD_NONE, 66 | NFQNL_CFG_CMD_BIND, 67 | NFQNL_CFG_CMD_UNBIND, 68 | NFQNL_CFG_CMD_PF_BIND, 69 | NFQNL_CFG_CMD_PF_UNBIND, 70 | }; 71 | 72 | struct nfqnl_msg_config_cmd { 73 | __u8 command; /* nfqnl_msg_config_cmds */ 74 | __u8 _pad; 75 | __be16 pf; /* AF_xxx for PF_[UN]BIND */ 76 | }; 77 | 78 | enum nfqnl_config_mode { 79 | NFQNL_COPY_NONE, 80 | NFQNL_COPY_META, 81 | NFQNL_COPY_PACKET, 82 | }; 83 | 84 | struct nfqnl_msg_config_params { 85 | __be32 copy_range; 86 | __u8 copy_mode; /* enum nfqnl_config_mode */ 87 | } __attribute__ ((packed)); 88 | 89 | 90 | enum nfqnl_attr_config { 91 | NFQA_CFG_UNSPEC, 92 | NFQA_CFG_CMD, /* nfqnl_msg_config_cmd */ 93 | NFQA_CFG_PARAMS, /* nfqnl_msg_config_params */ 94 | NFQA_CFG_QUEUE_MAXLEN, /* __u32 */ 95 | NFQA_CFG_MASK, /* identify which flags to change */ 96 | NFQA_CFG_FLAGS, /* value of these flags (__u32) */ 97 | __NFQA_CFG_MAX 98 | }; 99 | #define NFQA_CFG_MAX (__NFQA_CFG_MAX-1) 100 | 101 | /* Flags for NFQA_CFG_FLAGS */ 102 | #define NFQA_CFG_F_FAIL_OPEN (1 << 0) 103 | #define NFQA_CFG_F_CONNTRACK (1 << 1) 104 | #define NFQA_CFG_F_GSO (1 << 2) 105 | #define NFQA_CFG_F_UID_GID (1 << 3) 106 | #define NFQA_CFG_F_SECCTX (1 << 4) 107 | #define NFQA_CFG_F_MAX (1 << 5) 108 | 109 | /* flags for NFQA_SKB_INFO */ 110 | /* packet appears to have wrong checksums, but they are ok */ 111 | #define NFQA_SKB_CSUMNOTREADY (1 << 0) 112 | /* packet is GSO (i.e., exceeds device mtu) */ 113 | #define NFQA_SKB_GSO (1 << 1) 114 | 115 | #endif /* _NFNETLINK_QUEUE_H */ 116 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/libnetfilter_queue.pc.in: -------------------------------------------------------------------------------- 1 | # libnetfilter_queue pkg-config file 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | libdir=@libdir@ 6 | includedir=@includedir@ 7 | 8 | Name: libnetfilter_queue 9 | Description: netfilter userspace packet queueing library 10 | URL: http://netfilter.org/projects/libnetfilter_queue/ 11 | Version: @VERSION@ 12 | Requires: libnfnetlink 13 | Conflicts: 14 | Libs: -L${libdir} -lnetfilter_queue 15 | Libs.private: @LIBNFNETLINK_LIBS@ 16 | Cflags: -I${includedir} 17 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/m4/.gitignore: -------------------------------------------------------------------------------- 1 | /libtool.m4 2 | /lt*.m4 3 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/m4/gcc4_visibility.m4: -------------------------------------------------------------------------------- 1 | 2 | # GCC 4.x -fvisibility=hidden 3 | 4 | AC_DEFUN([CHECK_GCC_FVISIBILITY], [ 5 | AC_LANG_PUSH([C]) 6 | saved_CFLAGS="$CFLAGS" 7 | CFLAGS="$saved_CFLAGS -fvisibility=hidden" 8 | AC_CACHE_CHECK([whether compiler accepts -fvisibility=hidden], 9 | [ac_cv_fvisibility_hidden], AC_COMPILE_IFELSE( 10 | [AC_LANG_SOURCE()], 11 | [ac_cv_fvisibility_hidden=yes], 12 | [ac_cv_fvisibility_hidden=no] 13 | )) 14 | if test "$ac_cv_fvisibility_hidden" = "yes"; then 15 | AC_DEFINE([HAVE_VISIBILITY_HIDDEN], [1], 16 | [True if compiler supports -fvisibility=hidden]) 17 | AC_SUBST([GCC_FVISIBILITY_HIDDEN], [-fvisibility=hidden]) 18 | fi 19 | CFLAGS="$saved_CFLAGS" 20 | AC_LANG_POP([C]) 21 | ]) 22 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/src/Makefile.am: -------------------------------------------------------------------------------- 1 | # This is _NOT_ the library release version, it's an API version. 2 | # Extracted from Chapter 6 "Library interface versions" of the libtool docs. 3 | # 4 | # 5 | # Here are a set of rules to help you update your library version information: 6 | # 7 | # 1. Start with version information of `0:0:0' for each libtool library. 8 | # 2. Update the version information only immediately before a public release 9 | # of your software. More frequent updates are unnecessary, and only guarantee 10 | # that the current interface number gets larger faster. 11 | # 3. If the library source code has changed at all since the last update, 12 | # then increment revision (`c:r:a' becomes `c:r+1:a'). 13 | # 4. If any interfaces have been added, removed, or changed since the last 14 | # update, increment current, and set revision to 0. 15 | # 5. If any interfaces have been added since the last public release, then 16 | # increment age. 17 | # 6. If any interfaces have been removed since the last public release, then 18 | # set age to 0. 19 | # 20 | # 21 | LIBVERSION=6:0:5 22 | 23 | include ${top_srcdir}/Make_global.am 24 | 25 | lib_LTLIBRARIES = libnetfilter_queue.la 26 | 27 | noinst_HEADERS = internal.h 28 | 29 | libnetfilter_queue_la_LDFLAGS = -Wc,-nostartfiles \ 30 | -version-info $(LIBVERSION) 31 | libnetfilter_queue_la_SOURCES = libnetfilter_queue.c \ 32 | nlmsg.c \ 33 | extra/checksum.c \ 34 | extra/icmp.c \ 35 | extra/ipv6.c \ 36 | extra/tcp.c \ 37 | extra/ipv4.c \ 38 | extra/pktbuff.c \ 39 | extra/udp.c 40 | 41 | libnetfilter_queue_la_LIBADD = ${LIBNFNETLINK_LIBS} ${LIBMNL_LIBS} 42 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/src/extra/checksum.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) 2012 by Pablo Neira Ayuso 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 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This code has been sponsored by Vyatta Inc. 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | #include "internal.h" 24 | 25 | uint16_t nfq_checksum(uint32_t sum, uint16_t *buf, int size) 26 | { 27 | while (size > 1) { 28 | sum += *buf++; 29 | size -= sizeof(uint16_t); 30 | } 31 | if (size) { 32 | #if __BYTE_ORDER == __BIG_ENDIAN 33 | sum += (uint16_t)*(uint8_t *)buf << 8; 34 | #else 35 | sum += (uint16_t)*(uint8_t *)buf; 36 | #endif 37 | } 38 | 39 | sum = (sum >> 16) + (sum & 0xffff); 40 | sum += (sum >>16); 41 | 42 | return (uint16_t)(~sum); 43 | } 44 | 45 | uint16_t nfq_checksum_tcpudp_ipv4(struct iphdr *iph, uint16_t protonum) 46 | { 47 | uint32_t sum = 0; 48 | uint32_t iph_len = iph->ihl*4; 49 | uint32_t len = ntohs(iph->tot_len) - iph_len; 50 | uint8_t *payload = (uint8_t *)iph + iph_len; 51 | 52 | sum += (iph->saddr >> 16) & 0xFFFF; 53 | sum += (iph->saddr) & 0xFFFF; 54 | sum += (iph->daddr >> 16) & 0xFFFF; 55 | sum += (iph->daddr) & 0xFFFF; 56 | sum += htons(protonum); 57 | sum += htons(len); 58 | 59 | return nfq_checksum(sum, (uint16_t *)payload, len); 60 | } 61 | 62 | uint16_t nfq_checksum_tcpudp_ipv6(struct ip6_hdr *ip6h, void *transport_hdr, 63 | uint16_t protonum) 64 | { 65 | uint32_t sum = 0; 66 | uint32_t hdr_len = (uint8_t *)transport_hdr - (uint8_t *)ip6h; 67 | /* Allow for extra headers before the UDP header */ 68 | /* TODO: Deal with routing headers */ 69 | uint32_t len = ntohs(ip6h->ip6_plen) - (hdr_len - sizeof *ip6h); 70 | uint8_t *payload = (uint8_t *)ip6h + hdr_len; 71 | int i; 72 | 73 | for (i=0; i<8; i++) { 74 | sum += (ip6h->ip6_src.s6_addr16[i]); 75 | } 76 | for (i=0; i<8; i++) { 77 | sum += (ip6h->ip6_dst.s6_addr16[i]); 78 | } 79 | sum += htons(protonum); 80 | sum += htons(len); 81 | 82 | return nfq_checksum(sum, (uint16_t *)payload, len); 83 | } 84 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/src/extra/icmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) 2012 by Pablo Neira Ayuso 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 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This code has been sponsored by Vyatta Inc. 10 | */ 11 | 12 | #include 13 | #define _GNU_SOURCE 14 | #include 15 | 16 | #include 17 | 18 | #include "internal.h" 19 | 20 | /** 21 | * \defgroup icmp ICMP helper functions 22 | * 23 | * \manonly 24 | .SH SYNOPSIS 25 | .nf 26 | \fB 27 | #include 28 | #include 29 | \endmanonly 30 | * 31 | * @{ 32 | */ 33 | 34 | /** 35 | * nfq_icmp_get_hdr - get the ICMP header. 36 | * \param pktb: pointer to user-space network packet buffer 37 | * \returns validated pointer to the ICMP header or NULL if the ICMP header was 38 | * not set or if a minimal length check fails. 39 | * \note You have to call nfq_ip_set_transport_header() or 40 | * nfq_ip6_set_transport_header() first to set the ICMP header. 41 | */ 42 | EXPORT_SYMBOL 43 | struct icmphdr *nfq_icmp_get_hdr(struct pkt_buff *pktb) 44 | { 45 | if (pktb->transport_header == NULL) 46 | return NULL; 47 | 48 | /* No room for the ICMP header. */ 49 | if (pktb_tail(pktb) - pktb->transport_header < sizeof(struct icmphdr)) 50 | return NULL; 51 | 52 | return (struct icmphdr *)pktb->transport_header; 53 | } 54 | 55 | /** 56 | * @} 57 | */ 58 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/src/internal.h: -------------------------------------------------------------------------------- 1 | #ifndef INTERNAL_H 2 | #define INTERNAL_H 1 3 | 4 | #include "config.h" 5 | #include 6 | #include 7 | #ifdef HAVE_VISIBILITY_HIDDEN 8 | # define EXPORT_SYMBOL __attribute__((visibility("default"))) 9 | #else 10 | # define EXPORT_SYMBOL 11 | #endif 12 | 13 | struct iphdr; 14 | struct ip6_hdr; 15 | 16 | uint16_t nfq_checksum(uint32_t sum, uint16_t *buf, int size); 17 | uint16_t nfq_checksum_tcpudp_ipv4(struct iphdr *iph, uint16_t protonum); 18 | uint16_t nfq_checksum_tcpudp_ipv6(struct ip6_hdr *ip6h, void *transport_hdr, 19 | uint16_t protonum); 20 | 21 | struct pkt_buff { 22 | uint8_t *mac_header; 23 | uint8_t *network_header; 24 | uint8_t *transport_header; 25 | 26 | uint8_t *data; 27 | 28 | uint32_t len; 29 | uint32_t data_len; 30 | 31 | bool mangled; 32 | }; 33 | 34 | static inline uint8_t *pktb_tail(struct pkt_buff *pktb) 35 | { 36 | return pktb->data + pktb->len; 37 | } 38 | #endif 39 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/utils/.gitignore: -------------------------------------------------------------------------------- 1 | /nfqnl_test 2 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/utils/Makefile.am: -------------------------------------------------------------------------------- 1 | include ${top_srcdir}/Make_global.am 2 | 3 | check_PROGRAMS = nfqnl_test 4 | 5 | nfqnl_test_SOURCES = nfqnl_test.c 6 | nfqnl_test_LDADD = ../src/libnetfilter_queue.la 7 | nfqnl_test_LDFLAGS = -dynamic 8 | 9 | 10 | -------------------------------------------------------------------------------- /deps/libnetfilter_queue/utils/nfqnl_test.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include /* for NF_ACCEPT */ 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | /* returns packet id */ 14 | static uint32_t print_pkt (struct nfq_data *tb) 15 | { 16 | int id = 0; 17 | struct nfqnl_msg_packet_hdr *ph; 18 | struct nfqnl_msg_packet_hw *hwph; 19 | uint32_t mark, ifi, uid, gid; 20 | int ret; 21 | unsigned char *data, *secdata; 22 | 23 | ph = nfq_get_msg_packet_hdr(tb); 24 | if (ph) { 25 | id = ntohl(ph->packet_id); 26 | printf("hw_protocol=0x%04x hook=%u id=%u ", 27 | ntohs(ph->hw_protocol), ph->hook, id); 28 | } 29 | 30 | hwph = nfq_get_packet_hw(tb); 31 | if (hwph) { 32 | int i, hlen = ntohs(hwph->hw_addrlen); 33 | 34 | printf("hw_src_addr="); 35 | for (i = 0; i < hlen-1; i++) 36 | printf("%02x:", hwph->hw_addr[i]); 37 | printf("%02x ", hwph->hw_addr[hlen-1]); 38 | } 39 | 40 | mark = nfq_get_nfmark(tb); 41 | if (mark) 42 | printf("mark=%u ", mark); 43 | 44 | ifi = nfq_get_indev(tb); 45 | if (ifi) 46 | printf("indev=%u ", ifi); 47 | 48 | ifi = nfq_get_outdev(tb); 49 | if (ifi) 50 | printf("outdev=%u ", ifi); 51 | ifi = nfq_get_physindev(tb); 52 | if (ifi) 53 | printf("physindev=%u ", ifi); 54 | 55 | ifi = nfq_get_physoutdev(tb); 56 | if (ifi) 57 | printf("physoutdev=%u ", ifi); 58 | 59 | if (nfq_get_uid(tb, &uid)) 60 | printf("uid=%u ", uid); 61 | 62 | if (nfq_get_gid(tb, &gid)) 63 | printf("gid=%u ", gid); 64 | 65 | ret = nfq_get_secctx(tb, &secdata); 66 | if (ret > 0) 67 | printf("secctx=\"%.*s\" ", ret, secdata); 68 | 69 | ret = nfq_get_payload(tb, &data); 70 | if (ret >= 0) 71 | printf("payload_len=%d ", ret); 72 | 73 | fputc('\n', stdout); 74 | 75 | return id; 76 | } 77 | 78 | 79 | static int cb(struct nfq_q_handle *qh, struct nfgenmsg *nfmsg, 80 | struct nfq_data *nfa, void *data) 81 | { 82 | uint32_t id = print_pkt(nfa); 83 | printf("entering callback\n"); 84 | return nfq_set_verdict(qh, id, NF_ACCEPT, 0, NULL); 85 | } 86 | 87 | int main(int argc, char **argv) 88 | { 89 | struct nfq_handle *h; 90 | struct nfq_q_handle *qh; 91 | int fd; 92 | int rv; 93 | uint32_t queue = 0; 94 | char buf[4096] __attribute__ ((aligned)); 95 | 96 | if (argc == 2) { 97 | queue = atoi(argv[1]); 98 | if (queue > 65535) { 99 | fprintf(stderr, "Usage: %s [<0-65535>]\n", argv[0]); 100 | exit(EXIT_FAILURE); 101 | } 102 | } 103 | 104 | printf("opening library handle\n"); 105 | h = nfq_open(); 106 | if (!h) { 107 | fprintf(stderr, "error during nfq_open()\n"); 108 | exit(1); 109 | } 110 | 111 | printf("unbinding existing nf_queue handler for AF_INET (if any)\n"); 112 | if (nfq_unbind_pf(h, AF_INET) < 0) { 113 | fprintf(stderr, "error during nfq_unbind_pf()\n"); 114 | exit(1); 115 | } 116 | 117 | printf("binding nfnetlink_queue as nf_queue handler for AF_INET\n"); 118 | if (nfq_bind_pf(h, AF_INET) < 0) { 119 | fprintf(stderr, "error during nfq_bind_pf()\n"); 120 | exit(1); 121 | } 122 | 123 | printf("binding this socket to queue '%d'\n", queue); 124 | qh = nfq_create_queue(h, queue, &cb, NULL); 125 | if (!qh) { 126 | fprintf(stderr, "error during nfq_create_queue()\n"); 127 | exit(1); 128 | } 129 | 130 | printf("setting copy_packet mode\n"); 131 | if (nfq_set_mode(qh, NFQNL_COPY_PACKET, 0xffff) < 0) { 132 | fprintf(stderr, "can't set packet_copy mode\n"); 133 | exit(1); 134 | } 135 | 136 | printf("setting flags to request UID and GID\n"); 137 | if (nfq_set_queue_flags(qh, NFQA_CFG_F_UID_GID, NFQA_CFG_F_UID_GID)) { 138 | fprintf(stderr, "This kernel version does not allow to " 139 | "retrieve process UID/GID.\n"); 140 | } 141 | 142 | printf("setting flags to request security context\n"); 143 | if (nfq_set_queue_flags(qh, NFQA_CFG_F_SECCTX, NFQA_CFG_F_SECCTX)) { 144 | fprintf(stderr, "This kernel version does not allow to " 145 | "retrieve security context.\n"); 146 | } 147 | 148 | printf("Waiting for packets...\n"); 149 | 150 | fd = nfq_fd(h); 151 | 152 | for (;;) { 153 | if ((rv = recv(fd, buf, sizeof(buf), 0)) >= 0) { 154 | printf("pkt received\n"); 155 | nfq_handle_packet(h, buf, rv); 156 | continue; 157 | } 158 | /* if your application is too slow to digest the packets that 159 | * are sent from kernel-space, the socket buffer that we use 160 | * to enqueue packets may fill up returning ENOBUFS. Depending 161 | * on your application, this error may be ignored. Please, see 162 | * the doxygen documentation of this library on how to improve 163 | * this situation. 164 | */ 165 | if (rv < 0 && errno == ENOBUFS) { 166 | printf("losing packets!\n"); 167 | continue; 168 | } 169 | perror("recv failed"); 170 | break; 171 | } 172 | 173 | printf("unbinding from queue 0\n"); 174 | nfq_destroy_queue(qh); 175 | 176 | #ifdef INSANE 177 | /* normally, applications SHOULD NOT issue this command, since 178 | * it detaches other programs/sockets from AF_INET, too ! */ 179 | printf("unbinding from AF_INET\n"); 180 | nfq_unbind_pf(h, AF_INET); 181 | #endif 182 | 183 | printf("closing library handle\n"); 184 | nfq_close(h); 185 | 186 | exit(0); 187 | } 188 | -------------------------------------------------------------------------------- /deps/libnfnetlink/.gitignore: -------------------------------------------------------------------------------- 1 | .deps/ 2 | .libs/ 3 | Makefile 4 | Makefile.in 5 | *.o 6 | *.la 7 | *.lo 8 | 9 | /aclocal.m4 10 | /autom4te.cache/ 11 | /build-aux/ 12 | /config.* 13 | /configure 14 | /libtool 15 | /stamp-h1 16 | 17 | /*.pc 18 | doxygen.cfg 19 | -------------------------------------------------------------------------------- /deps/libnfnetlink/Make_global.am: -------------------------------------------------------------------------------- 1 | # This is _NOT_ the library release version, it's an API version. 2 | # Please read Chapter 6 "Library interface versions" of the libtool 3 | # documentation before making any modification 4 | # http://sources.redhat.com/autobook/autobook/autobook_91.html 5 | LIBVERSION=2:0:2 6 | 7 | AM_CPPFLAGS = -I$(top_srcdir)/include 8 | AM_CFLAGS = -Wall -fvisibility=hidden -D'NFNL_EXPORT=__attribute__((visibility("default")))' 9 | -------------------------------------------------------------------------------- /deps/libnfnetlink/Makefile.am: -------------------------------------------------------------------------------- 1 | include $(top_srcdir)/Make_global.am 2 | 3 | ACLOCAL_AMFLAGS = -I m4 4 | 5 | EXTRA_DIST = $(man_MANS) 6 | 7 | SUBDIRS = src include utils 8 | DIST_SUBDIRS = src include utils 9 | 10 | man_MANS = #nfnetlink.3 11 | 12 | pkgconfigdir = $(libdir)/pkgconfig 13 | pkgconfig_DATA = libnfnetlink.pc 14 | 15 | dist-hook: 16 | rm -rf `find $(distdir)/debian -name .svn` 17 | -------------------------------------------------------------------------------- /deps/libnfnetlink/README: -------------------------------------------------------------------------------- 1 | libnfnetlink - userspace library for handling of netfilter netlink messages 2 | (C) 2001-2005 Netfilter Core Team 3 | =========================================================================== 4 | 5 | What is nfnetlink? 6 | 7 | nfnetlink is a netlink(7) based kernel/userspace transport layer. It 8 | provides a unified kernel/userspace interface for the various netfilter 9 | subsystems, such as connection tracking, logging and queueing. 10 | 11 | 12 | What is libnfnetlink? 13 | 14 | libnfnetlink is a userspace library that provides some low-level 15 | nfnetlink handling functions. It is used as a foundation for other, netfilter 16 | subsystem specific libraries such as libnfnetlink_conntrack, libnfnetlink_log 17 | and libnfnetlink_queue. 18 | 19 | 20 | Prerequirements for libnfnetlink 21 | 22 | You will need kernel headers from a kernel that has nfnetlink support. The 23 | first official kernel release to include nfnetlink support is 2.6.14. 24 | You can specify the location of your kernel sources using the "--with-kernel=" 25 | configure option. 26 | 27 | 28 | Where can I find documentation? 29 | 30 | At the moment, you will have to RTFS. Sorry, but we have barely enough 31 | manpower to keep development ongoing. If you want to conribute documentation, 32 | please contact us. 33 | 34 | 35 | It has bugs. Where do I report them? 36 | 37 | Please report all libnfnetlink bugs to https://bugzilla.netfilter.org/, using 38 | the "libnfnetlink" Product. 39 | 40 | 41 | License 42 | 43 | This library is released under GPLv2+. 44 | 45 | 46 | Where do I get support? 47 | 48 | The netfilter@lists.netfilter.org and netfilter-devel@lists.netfilter.org 49 | mailinglists server as support forum. 50 | 51 | -------------------------------------------------------------------------------- /deps/libnfnetlink/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | 3 | include () 4 | { 5 | # If we keep a copy of the kernel header in the SVN tree, we'll have 6 | # to worry about synchronization issues forever. Instead, we just copy 7 | # the headers that we need from the lastest kernel version at autogen 8 | # stage. 9 | 10 | INCLUDEDIR=${KERNEL_DIR:-/lib/modules/`uname -r`/build}/include/linux 11 | 12 | if [ -f $INCLUDEDIR/netfilter/nfnetlink.h ] 13 | then 14 | TARGET=include/libnfnetlink/linux_nfnetlink.h 15 | echo "Copying nfnetlink.h to linux_nfnetlink.h" 16 | cp $INCLUDEDIR/netfilter/nfnetlink.h $TARGET 17 | TMP=`mktemp` 18 | sed 's/#include /#include /g' $TARGET > $TMP 19 | cp $TMP $TARGET 20 | else 21 | echo "can't find nfnetlink.h kernel file in $INCLUDEDIR" 22 | exit 1 23 | fi 24 | 25 | if [ -f $INCLUDEDIR/netfilter/nfnetlink_compat.h ] 26 | then 27 | TARGET=include/libnfnetlink/linux_nfnetlink_compat.h 28 | echo "Copying nfnetlink_compat.h to linux_nfnetlink_compat.h" 29 | cp $INCLUDEDIR/netfilter/nfnetlink_compat.h $TARGET 30 | else 31 | echo "can't find nfnetlink.h kernel file in $INCLUDEDIR, ignoring" 32 | fi 33 | } 34 | 35 | [ "x$1" = "xdistrib" ] && include 36 | autoreconf -fi 37 | rm -Rf autom4te.cache 38 | -------------------------------------------------------------------------------- /deps/libnfnetlink/configure.ac: -------------------------------------------------------------------------------- 1 | dnl Process this file with autoconf to create configure. 2 | 3 | AC_INIT(libnfnetlink, 1.0.2) 4 | AC_CONFIG_AUX_DIR([build-aux]) 5 | AC_CONFIG_MACRO_DIR([m4]) 6 | AC_CANONICAL_HOST 7 | 8 | AM_INIT_AUTOMAKE([-Wall foreign subdir-objects 9 | tar-pax no-dist-gzip dist-xz 1.6]) 10 | m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) 11 | 12 | dnl kernel style compile messages 13 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 14 | 15 | AC_PROG_CC 16 | AM_PROG_CC_C_O 17 | AC_DISABLE_STATIC 18 | AM_PROG_LIBTOOL 19 | 20 | case "$host" in 21 | *-*-linux* | *-*-uclinux*) ;; 22 | *) AC_MSG_ERROR([Linux only, dude!]);; 23 | esac 24 | 25 | 26 | dnl-------------------------------- 27 | dnl-------------------------------- 28 | 29 | 30 | dnl Output the makefile 31 | AC_CONFIG_FILES([Makefile src/Makefile include/Makefile doxygen.cfg 32 | include/libnfnetlink/Makefile utils/Makefile libnfnetlink.pc]) 33 | AC_OUTPUT 34 | -------------------------------------------------------------------------------- /deps/libnfnetlink/include/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = libnfnetlink 2 | noinst_HEADERS = linux_list.h 3 | -------------------------------------------------------------------------------- /deps/libnfnetlink/include/libnfnetlink/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | pkginclude_HEADERS = libnfnetlink.h linux_nfnetlink.h linux_nfnetlink_compat.h 3 | 4 | -------------------------------------------------------------------------------- /deps/libnfnetlink/include/libnfnetlink/linux_nfnetlink.h: -------------------------------------------------------------------------------- 1 | #ifndef _NFNETLINK_H 2 | #define _NFNETLINK_H 3 | #include 4 | #include 5 | 6 | enum nfnetlink_groups { 7 | NFNLGRP_NONE, 8 | #define NFNLGRP_NONE NFNLGRP_NONE 9 | NFNLGRP_CONNTRACK_NEW, 10 | #define NFNLGRP_CONNTRACK_NEW NFNLGRP_CONNTRACK_NEW 11 | NFNLGRP_CONNTRACK_UPDATE, 12 | #define NFNLGRP_CONNTRACK_UPDATE NFNLGRP_CONNTRACK_UPDATE 13 | NFNLGRP_CONNTRACK_DESTROY, 14 | #define NFNLGRP_CONNTRACK_DESTROY NFNLGRP_CONNTRACK_DESTROY 15 | NFNLGRP_CONNTRACK_EXP_NEW, 16 | #define NFNLGRP_CONNTRACK_EXP_NEW NFNLGRP_CONNTRACK_EXP_NEW 17 | NFNLGRP_CONNTRACK_EXP_UPDATE, 18 | #define NFNLGRP_CONNTRACK_EXP_UPDATE NFNLGRP_CONNTRACK_EXP_UPDATE 19 | NFNLGRP_CONNTRACK_EXP_DESTROY, 20 | #define NFNLGRP_CONNTRACK_EXP_DESTROY NFNLGRP_CONNTRACK_EXP_DESTROY 21 | __NFNLGRP_MAX, 22 | }; 23 | #define NFNLGRP_MAX (__NFNLGRP_MAX - 1) 24 | 25 | /* General form of address family dependent message. 26 | */ 27 | struct nfgenmsg { 28 | __u8 nfgen_family; /* AF_xxx */ 29 | __u8 version; /* nfnetlink version */ 30 | __be16 res_id; /* resource id */ 31 | }; 32 | 33 | #define NFNETLINK_V0 0 34 | 35 | /* netfilter netlink message types are split in two pieces: 36 | * 8 bit subsystem, 8bit operation. 37 | */ 38 | 39 | #define NFNL_SUBSYS_ID(x) ((x & 0xff00) >> 8) 40 | #define NFNL_MSG_TYPE(x) (x & 0x00ff) 41 | 42 | /* No enum here, otherwise __stringify() trick of MODULE_ALIAS_NFNL_SUBSYS() 43 | * won't work anymore */ 44 | #define NFNL_SUBSYS_NONE 0 45 | #define NFNL_SUBSYS_CTNETLINK 1 46 | #define NFNL_SUBSYS_CTNETLINK_EXP 2 47 | #define NFNL_SUBSYS_QUEUE 3 48 | #define NFNL_SUBSYS_ULOG 4 49 | #define NFNL_SUBSYS_OSF 5 50 | #define NFNL_SUBSYS_IPSET 6 51 | #define NFNL_SUBSYS_COUNT 7 52 | 53 | #endif /* _NFNETLINK_H */ 54 | -------------------------------------------------------------------------------- /deps/libnfnetlink/include/libnfnetlink/linux_nfnetlink_compat.h: -------------------------------------------------------------------------------- 1 | #ifndef _NFNETLINK_COMPAT_H 2 | #define _NFNETLINK_COMPAT_H 3 | 4 | #include 5 | 6 | /* Old nfnetlink macros for userspace */ 7 | 8 | /* nfnetlink groups: Up to 32 maximum */ 9 | #define NF_NETLINK_CONNTRACK_NEW 0x00000001 10 | #define NF_NETLINK_CONNTRACK_UPDATE 0x00000002 11 | #define NF_NETLINK_CONNTRACK_DESTROY 0x00000004 12 | #define NF_NETLINK_CONNTRACK_EXP_NEW 0x00000008 13 | #define NF_NETLINK_CONNTRACK_EXP_UPDATE 0x00000010 14 | #define NF_NETLINK_CONNTRACK_EXP_DESTROY 0x00000020 15 | 16 | /* Generic structure for encapsulation optional netfilter information. 17 | * It is reminiscent of sockaddr, but with sa_family replaced 18 | * with attribute type. 19 | * ! This should someday be put somewhere generic as now rtnetlink and 20 | * ! nfnetlink use the same attributes methods. - J. Schulist. 21 | */ 22 | 23 | struct nfattr { 24 | __u16 nfa_len; 25 | __u16 nfa_type; /* we use 15 bits for the type, and the highest 26 | * bit to indicate whether the payload is nested */ 27 | }; 28 | 29 | /* FIXME: Apart from NFNL_NFA_NESTED shamelessly copy and pasted from 30 | * rtnetlink.h, it's time to put this in a generic file */ 31 | 32 | #define NFNL_NFA_NEST 0x8000 33 | #define NFA_TYPE(attr) ((attr)->nfa_type & 0x7fff) 34 | 35 | #define NFA_ALIGNTO 4 36 | #define NFA_ALIGN(len) (((len) + NFA_ALIGNTO - 1) & ~(NFA_ALIGNTO - 1)) 37 | #define NFA_OK(nfa,len) ((len) > 0 && (nfa)->nfa_len >= sizeof(struct nfattr) \ 38 | && (nfa)->nfa_len <= (len)) 39 | #define NFA_NEXT(nfa,attrlen) ((attrlen) -= NFA_ALIGN((nfa)->nfa_len), \ 40 | (struct nfattr *)(((char *)(nfa)) + NFA_ALIGN((nfa)->nfa_len))) 41 | #define NFA_LENGTH(len) (NFA_ALIGN(sizeof(struct nfattr)) + (len)) 42 | #define NFA_SPACE(len) NFA_ALIGN(NFA_LENGTH(len)) 43 | #define NFA_DATA(nfa) ((void *)(((char *)(nfa)) + NFA_LENGTH(0))) 44 | #define NFA_PAYLOAD(nfa) ((int)((nfa)->nfa_len) - NFA_LENGTH(0)) 45 | #define NFA_NEST(skb, type) \ 46 | ({ struct nfattr *__start = (struct nfattr *)skb_tail_pointer(skb); \ 47 | NFA_PUT(skb, (NFNL_NFA_NEST | type), 0, NULL); \ 48 | __start; }) 49 | #define NFA_NEST_END(skb, start) \ 50 | ({ (start)->nfa_len = skb_tail_pointer(skb) - (unsigned char *)(start); \ 51 | (skb)->len; }) 52 | #define NFA_NEST_CANCEL(skb, start) \ 53 | ({ if (start) \ 54 | skb_trim(skb, (unsigned char *) (start) - (skb)->data); \ 55 | -1; }) 56 | 57 | #define NFM_NFA(n) ((struct nfattr *)(((char *)(n)) \ 58 | + NLMSG_ALIGN(sizeof(struct nfgenmsg)))) 59 | #define NFM_PAYLOAD(n) NLMSG_PAYLOAD(n, sizeof(struct nfgenmsg)) 60 | 61 | #endif /* _NFNETLINK_COMPAT_H */ 62 | -------------------------------------------------------------------------------- /deps/libnfnetlink/libnfnetlink.pc.in: -------------------------------------------------------------------------------- 1 | # libnfnetlink pkg-config file 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | libdir=@libdir@ 6 | includedir=@includedir@ 7 | 8 | Name: libnfnetlink 9 | Description: Low-level netfilter netlink communication library 10 | URL: http://netfilter.org/projects/libnfnetlink/ 11 | Version: @VERSION@ 12 | Requires: 13 | Conflicts: 14 | Libs: -L${libdir} -lnfnetlink 15 | Cflags: -I${includedir} 16 | -------------------------------------------------------------------------------- /deps/libnfnetlink/m4/.gitignore: -------------------------------------------------------------------------------- 1 | /libtool.m4 2 | /lt*.m4 3 | -------------------------------------------------------------------------------- /deps/libnfnetlink/src/Makefile.am: -------------------------------------------------------------------------------- 1 | include $(top_srcdir)/Make_global.am 2 | 3 | lib_LTLIBRARIES = libnfnetlink.la 4 | 5 | libnfnetlink_la_LDFLAGS = -Wc,-nostartfiles \ 6 | -version-info $(LIBVERSION) \ 7 | -Wl,--version-script=$(srcdir)/nfnl.version 8 | libnfnetlink_la_SOURCES = libnfnetlink.c iftable.c rtnl.c nfnl.version 9 | EXTRA_libnfnetlink_la_DEPENDENCIES = $(srcdir)/nfnl.version 10 | 11 | noinst_HEADERS = iftable.h rtnl.h 12 | -------------------------------------------------------------------------------- /deps/libnfnetlink/src/iftable.h: -------------------------------------------------------------------------------- 1 | #ifndef _IFTABLE_H 2 | #define _IFTABLE_H 3 | 4 | int iftable_delete(uint32_t dst, uint32_t mask, uint32_t gw, uint32_t oif); 5 | int iftable_insert(uint32_t dst, uint32_t mask, uint32_t gw, uint32_t oif); 6 | 7 | int iftable_init(void); 8 | void iftable_fini(void); 9 | 10 | int iftable_dump(FILE *outfd); 11 | int iftable_up(unsigned int index); 12 | #endif 13 | -------------------------------------------------------------------------------- /deps/libnfnetlink/src/nfnl.version: -------------------------------------------------------------------------------- 1 | NFNETLINK_1.0.1 { 2 | global: 3 | nfnl_fd; 4 | nfnl_portid; 5 | nfnl_open; 6 | nfnl_close; 7 | nfnl_subsys_open; 8 | nfnl_subsys_close; 9 | nfnl_set_sequence_tracking; 10 | nfnl_unset_sequence_tracking; 11 | nfnl_set_rcv_buffer_size; 12 | nfnl_send; 13 | nfnl_sendmsg; 14 | nfnl_sendiov; 15 | nfnl_fill_hdr; 16 | nfnl_talk; 17 | nfnl_listen; 18 | nfnl_recv; 19 | nfnl_callback_register; 20 | nfnl_callback_unregister; 21 | nfnl_handle_packet; 22 | nfnl_parse_hdr; 23 | nfnl_check_attributes; 24 | nfnl_get_msg_first; 25 | nfnl_get_msg_next; 26 | nfnl_join; 27 | nfnl_process; 28 | nfnl_iterator_create; 29 | nfnl_iterator_destroy; 30 | nfnl_iterator_process; 31 | nfnl_iterator_next; 32 | nfnl_catch; 33 | nfnl_query; 34 | nfnl_addattr_l; 35 | nfnl_addattr8; 36 | nfnl_addattr16; 37 | nfnl_addattr32; 38 | nfnl_nfa_addattr_l; 39 | nfnl_nfa_addattr16; 40 | nfnl_nfa_addattr32; 41 | nfnl_parse_attr; 42 | nfnl_build_nfa_iovec; 43 | nfnl_rcvbufsiz; 44 | nfnl_dump_packet; 45 | nlif_open; 46 | nlif_close; 47 | nlif_fd; 48 | nlif_query; 49 | nlif_catch; 50 | nlif_index2name; 51 | nlif_get_ifflags; 52 | 53 | local: 54 | *; 55 | }; 56 | -------------------------------------------------------------------------------- /deps/libnfnetlink/src/rtnl.h: -------------------------------------------------------------------------------- 1 | #ifndef _RTNL_H 2 | #define _RTNL_H 3 | 4 | #include 5 | #include 6 | 7 | struct rtnl_handler { 8 | struct rtnl_handler *next; 9 | 10 | uint16_t nlmsg_type; 11 | int (*handlefn)(struct nlmsghdr *h, void *arg); 12 | void *arg; 13 | }; 14 | 15 | struct rtnl_handle { 16 | int rtnl_fd; 17 | int rtnl_seq; 18 | int rtnl_dump; 19 | struct sockaddr_nl rtnl_local; 20 | struct rtnl_handler *handlers; 21 | }; 22 | 23 | /* api for handler plugins */ 24 | int rtnl_handler_register(struct rtnl_handle *rtnl_handle, 25 | struct rtnl_handler *hdlr); 26 | int rtnl_handler_unregister(struct rtnl_handle *rtnl_handle, 27 | struct rtnl_handler *hdlr); 28 | int rtnl_parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len); 29 | int rtnl_dump_type(struct rtnl_handle *rtnl_handle, unsigned int type); 30 | 31 | /* api for core program */ 32 | struct rtnl_handle *rtnl_open(void); 33 | void rtnl_close(struct rtnl_handle *rtnl_handle); 34 | int rtnl_receive(struct rtnl_handle *rtnl_handle); 35 | int rtnl_receive_multi(struct rtnl_handle *rtnl_handle); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /deps/libnfnetlink/utils/.gitignore: -------------------------------------------------------------------------------- 1 | /iftest 2 | -------------------------------------------------------------------------------- /deps/libnfnetlink/utils/Makefile.am: -------------------------------------------------------------------------------- 1 | include $(top_srcdir)/Make_global.am 2 | 3 | check_PROGRAMS = iftest 4 | 5 | iftest_SOURCES = iftest.c 6 | iftest_LDADD = ../src/libnfnetlink.la 7 | iftest_LDFLAGS = -dynamic -ldl 8 | -------------------------------------------------------------------------------- /deps/libnfnetlink/utils/iftest.c: -------------------------------------------------------------------------------- 1 | /* simple test for index to interface name API */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | int idx; 14 | struct nlif_handle *h; 15 | char name[IFNAMSIZ]; 16 | unsigned int flags; 17 | 18 | if (argc != 2) { 19 | fprintf(stderr, "Usage: %s \n", argv[0]); 20 | exit(EXIT_FAILURE); 21 | } 22 | 23 | h = nlif_open(); 24 | if (h == NULL) { 25 | perror("nlif_open"); 26 | exit(EXIT_FAILURE); 27 | } 28 | 29 | if (nlif_query(h) == -1) { 30 | fprintf(stderr, "failed query to retrieve interfaces: %s\n", 31 | strerror(errno)); 32 | exit(EXIT_FAILURE); 33 | } 34 | 35 | idx = if_nametoindex(argv[1]); 36 | 37 | /* Superfluous: just to make sure nlif_index2name is working fine */ 38 | if (nlif_index2name(h, idx, name) == -1) 39 | fprintf(stderr, "Cannot translate device idx=%u\n", idx); 40 | 41 | if (nlif_get_ifflags(h, idx, &flags) == -1) { 42 | fprintf(stderr, "Cannot get flags for device `%s'\n", argv[1]); 43 | exit(EXIT_FAILURE); 44 | } 45 | 46 | printf("index (%d) is %s (%s) (%s)\n", idx, argv[1], 47 | flags & IFF_RUNNING ? "RUNNING" : "NOT RUNNING", 48 | flags & IFF_UP ? "UP" : "DOWN"); 49 | 50 | nlif_close(h); 51 | return EXIT_SUCCESS; 52 | } 53 | -------------------------------------------------------------------------------- /kmake.mk: -------------------------------------------------------------------------------- 1 | #Kernel module makes here 2 | PWD := $(CURDIR) 3 | 4 | CC := gcc 5 | CCLD := $(CC) 6 | LD := ld 7 | CFLAGS := 8 | LDFLAGS := 9 | 10 | KERNEL_BUILDER_MAKEDIR:=/lib/modules/$(shell uname -r)/build 11 | 12 | override EXTRA_CFLAGS += -DPKG_VERSION=\"$(PKG_FULLVERSION)\" 13 | 14 | .PHONY: kmake kload kunload kreload kclean kmclean xclean 15 | kmake: kmod 16 | 17 | kmod: 18 | $(MAKE) -C $(KERNEL_BUILDER_MAKEDIR) M=$(PWD) EXTRA_CFLAGS='$(EXTRA_CFLAGS)' modules 19 | 20 | kload: 21 | insmod kyoutubeUnblock.ko 22 | 23 | kunload: 24 | -rmmod kyoutubeUnblock 25 | 26 | kreload: kunload kload 27 | 28 | kclean: kmclean 29 | 30 | kmclean: 31 | -$(MAKE) -C $(KERNEL_BUILDER_MAKEDIR) M=$(PWD) clean 32 | -------------------------------------------------------------------------------- /src/args.h: -------------------------------------------------------------------------------- 1 | /* 2 | youtubeUnblock - https://github.com/Waujito/youtubeUnblock 3 | 4 | Copyright (C) 2024-2025 Vadim Vetrov 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. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #ifndef ARGS_H 21 | #define ARGS_H 22 | #include "types.h" 23 | #include "config.h" 24 | 25 | void print_version(void); 26 | void print_usage(const char *argv0); 27 | /** 28 | * Initializes _config_ and parses args to it. 29 | */ 30 | int yparse_args(struct config_t *config, int argc, char *argv[]); 31 | size_t print_config(const struct config_t *config, char *buffer, size_t buffer_size); 32 | void parse_global_lgconf(const struct config_t *config); 33 | 34 | // Initializes configuration storage. 35 | int init_config(struct config_t *config); 36 | // Allocates and initializes configuration section. 37 | int init_section_config(struct section_config_t **section, struct section_config_t *prev); 38 | // Frees configuration section 39 | void free_config_section(struct section_config_t *config); 40 | // Frees sections under config 41 | void free_config(struct config_t *config); 42 | 43 | /* Prints starting messages */ 44 | void print_welcome(const struct config_t *config); 45 | 46 | #endif /* ARGS_H */ 47 | -------------------------------------------------------------------------------- /src/getopt.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2005-2014 Rich Felker, et al. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef _GETOPT_H 25 | #define _GETOPT_H 26 | 27 | int getopt(int, char * const [], const char *); 28 | extern char *optarg; 29 | extern int optind, opterr, optopt, optreset; 30 | 31 | struct option { 32 | const char *name; 33 | int has_arg; 34 | int *flag; 35 | int val; 36 | }; 37 | 38 | int getopt_long(int, char *const *, const char *, const struct option *, int *); 39 | int getopt_long_only(int, char *const *, const char *, const struct option *, int *); 40 | 41 | #define no_argument 0 42 | #define required_argument 1 43 | #define optional_argument 2 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/inet_ntop.c: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | musl libc 4 | 5 | musl, pronounced like the word "mussel", is an MIT-licensed 6 | implementation of the standard C library targetting the Linux syscall 7 | API, suitable for use in a wide range of deployment environments. musl 8 | offers efficient static and dynamic linking support, lightweight code 9 | and low runtime overhead, strong fail-safe guarantees under correct 10 | usage, and correctness in the sense of standards conformance and 11 | safety. musl is built on the principle that these goals are best 12 | achieved through simple code that is easy to understand and maintain. 13 | 14 | The 1.1 release series for musl features coverage for all interfaces 15 | defined in ISO C99 and POSIX 2008 base, along with a number of 16 | non-standardized interfaces for compatibility with Linux, BSD, and 17 | glibc functionality. 18 | 19 | For basic installation instructions, see the included INSTALL file. 20 | Information on full musl-targeted compiler toolchains, system 21 | bootstrapping, and Linux distributions built on musl can be found on 22 | the project website: 23 | 24 | http://www.musl-libc.org/ 25 | */ 26 | 27 | #include "types.h" 28 | 29 | // #ifndef KERNEL_SPACE 30 | // #error "For user space use glibc inet_ntop" 31 | // #endif 32 | 33 | const char *inet_ntop(int af, const void *restrict a0, char *restrict s, socklen_t l) 34 | { 35 | const unsigned char *a = a0; 36 | int i, j, max, best; 37 | char buf[100]; 38 | 39 | switch (af) { 40 | case AF_INET: 41 | if (snprintf(s, l, "%d.%d.%d.%d", a[0],a[1],a[2],a[3]) < l) 42 | return s; 43 | break; 44 | case AF_INET6: 45 | if (memcmp(a, "\0\0\0\0\0\0\0\0\0\0\377\377", 12)) 46 | snprintf(buf, sizeof buf, 47 | "%x:%x:%x:%x:%x:%x:%x:%x", 48 | 256*a[0]+a[1],256*a[2]+a[3], 49 | 256*a[4]+a[5],256*a[6]+a[7], 50 | 256*a[8]+a[9],256*a[10]+a[11], 51 | 256*a[12]+a[13],256*a[14]+a[15]); 52 | else 53 | snprintf(buf, sizeof buf, 54 | "%x:%x:%x:%x:%x:%x:%d.%d.%d.%d", 55 | 256*a[0]+a[1],256*a[2]+a[3], 56 | 256*a[4]+a[5],256*a[6]+a[7], 57 | 256*a[8]+a[9],256*a[10]+a[11], 58 | a[12],a[13],a[14],a[15]); 59 | /* Replace longest /(^0|:)[:0]{2,}/ with "::" */ 60 | for (i=best=0, max=2; buf[i]; i++) { 61 | if (i && buf[i] != ':') continue; 62 | j = strspn(buf+i, ":0"); 63 | if (j>max) best=i, max=j; 64 | } 65 | if (max>3) { 66 | buf[best] = buf[best+1] = ':'; 67 | memmove(buf+best+2, buf+best+max, i-best-max+1); 68 | } 69 | if (strlen(buf) < l) { 70 | strcpy(s, buf); 71 | return s; 72 | } 73 | break; 74 | default: 75 | return 0; 76 | } 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /src/logging.h: -------------------------------------------------------------------------------- 1 | /* 2 | youtubeUnblock - https://github.com/Waujito/youtubeUnblock 3 | 4 | Copyright (C) 2024-2025 Vadim Vetrov 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. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LOGGING_H 21 | #define LOGGING_H 22 | #include "config.h" 23 | 24 | /** 25 | * Defined in args.c 26 | */ 27 | #define LOGGING_BUFSIZE 4096 28 | extern char ylgh_buf[LOGGING_BUFSIZE]; 29 | extern size_t ylgh_leftbuf; 30 | extern char *ylgh_curptr; 31 | extern int ylgh_ndnl; 32 | 33 | #define LOG_LEVEL (logging_conf.verbose) 34 | #define DO_INSTAFLUSH (logging_conf.instaflush) 35 | #define DO_SYSLOG (logging_conf.syslog) 36 | 37 | #ifdef KERNEL_SPACE 38 | #define LOG_ERR KERN_ERR 39 | #define LOG_INFO KERN_INFO 40 | #define LOG_WARNING KERN_WARNING 41 | 42 | #include 43 | #include 44 | #define printf pr_info 45 | #define perror pr_err 46 | #define print_message(level, msg, ...) \ 47 | (printk(level msg, ##__VA_ARGS__)) 48 | 49 | #else 50 | #include // IWYU pragma: export 51 | #include 52 | #include 53 | 54 | #define print_message(level, msg, ...) \ 55 | (DO_SYSLOG ? (void)(syslog((level), msg, ##__VA_ARGS__)) : (void)(printf(msg, ##__VA_ARGS__) + fflush(stdout))) 56 | 57 | #endif /* PROGRAM_SPACE */ 58 | 59 | /** 60 | * For flushing only. Use log_buf_write for writing. 61 | */ 62 | #define log_buf_flush(level) __extension__ ({ \ 63 | if (ylgh_leftbuf != LOGGING_BUFSIZE) { \ 64 | print_message(level, "%s", ylgh_buf);\ 65 | ylgh_curptr = ylgh_buf; \ 66 | ylgh_leftbuf = LOGGING_BUFSIZE; \ 67 | } \ 68 | }) 69 | 70 | #define log_buf(level, msg, ...) __extension__ ({ \ 71 | int lgrtrt; \ 72 | lgrtrt=snprintf(ylgh_curptr, ylgh_leftbuf, msg, ##__VA_ARGS__); \ 73 | if (lgrtrt < 0 || lgrtrt >= ylgh_leftbuf) { \ 74 | ylgh_leftbuf = 0; \ 75 | log_buf_flush(level); \ 76 | } else { \ 77 | ylgh_leftbuf -= lgrtrt; \ 78 | ylgh_curptr += lgrtrt; \ 79 | } \ 80 | }) 81 | 82 | #define log_buf_write(level) __extension__ ({ \ 83 | if (ylgh_ndnl) { \ 84 | log_buf(level, "\n"); \ 85 | ylgh_ndnl = 0; \ 86 | } \ 87 | log_buf_flush(level); \ 88 | }) 89 | 90 | #define log_message(level, msg, ...) __extension__ ({ \ 91 | if (ylgh_leftbuf != LOGGING_BUFSIZE) { \ 92 | log_buf_write(LOG_INFO); \ 93 | log_buf(level, "[NOTICE] "); \ 94 | } \ 95 | log_buf(level, msg, ##__VA_ARGS__); \ 96 | ylgh_ndnl = 1; \ 97 | log_buf_write(level); \ 98 | }) 99 | 100 | #ifdef KERNEL_SPACE 101 | #define lgerror(code, msg, ...) \ 102 | (log_message(LOG_ERR, msg ": %d", ##__VA_ARGS__, code)) 103 | #else 104 | #define lgerror(code, msg, ...) \ 105 | log_message(LOG_ERR, msg ": %s", ##__VA_ARGS__, strerror(-code)); 106 | #endif 107 | 108 | 109 | #define lgerr(msg, ...) \ 110 | (log_message(LOG_ERR, msg, ##__VA_ARGS__)) 111 | 112 | #define lgwarning(msg, ...) \ 113 | (log_message(LOG_WARNING, msg, ##__VA_ARGS__)) 114 | 115 | 116 | #define lginfo(msg, ...) \ 117 | (log_message(LOG_INFO, msg, ##__VA_ARGS__)) 118 | 119 | #define lgdebug(msg, ...) \ 120 | (LOG_LEVEL >= VERBOSE_DEBUG ? log_message(LOG_INFO, msg, ##__VA_ARGS__) : (void)0) 121 | 122 | #define lgtrace(msg, ...) \ 123 | (LOG_LEVEL >= VERBOSE_TRACE ? log_message(LOG_INFO, msg, ##__VA_ARGS__) : (void)0) 124 | 125 | #define lgtrace_start() \ 126 | lgtrace("---[TRACE PACKET START]---") 127 | 128 | #define lgtrace_wr(msg, ...) __extension__ ({ \ 129 | if (LOG_LEVEL >= VERBOSE_TRACE) { \ 130 | ylgh_ndnl = 1; \ 131 | log_buf(LOG_INFO, msg, ##__VA_ARGS__); \ 132 | if (DO_INSTAFLUSH) { \ 133 | log_buf_flush(LOG_INFO); \ 134 | } \ 135 | } \ 136 | }) 137 | 138 | #define lgtrace_addp(msg, ...) \ 139 | lgtrace_wr(msg ", ", ##__VA_ARGS__) 140 | 141 | #define lgtrace_write() \ 142 | (LOG_LEVEL >= VERBOSE_TRACE ? log_buf_write(LOG_INFO) : (void)0) 143 | 144 | #define lgtrace_end() __extension__ ({ \ 145 | if (LOG_LEVEL >= VERBOSE_TRACE) { \ 146 | log_buf_write(LOG_INFO); \ 147 | print_message(LOG_INFO, "\n"); \ 148 | } \ 149 | }) 150 | 151 | #endif /* LOGGING_H */ 152 | -------------------------------------------------------------------------------- /src/mangle.h: -------------------------------------------------------------------------------- 1 | /* 2 | youtubeUnblock - https://github.com/Waujito/youtubeUnblock 3 | 4 | Copyright (C) 2024-2025 Vadim Vetrov 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. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #ifndef YU_MANGLE_H 21 | #define YU_MANGLE_H 22 | 23 | #include "types.h" 24 | #include "tls.h" 25 | #include "config.h" 26 | 27 | #define PKT_ACCEPT 0 28 | #define PKT_DROP 1 29 | // Used for section config 30 | #define PKT_CONTINUE 2 31 | 32 | /** 33 | * Processes the packet and returns verdict. 34 | * This is the primary function that traverses the packet. 35 | */ 36 | int process_packet(const struct config_t *config, const struct packet_data *pd); 37 | 38 | 39 | /** 40 | * Processe the TCP packet. 41 | * Returns verdict. 42 | */ 43 | int process_tcp_packet(const struct section_config_t *section, const uint8_t *raw_payload, size_t raw_payload_len); 44 | 45 | 46 | /** 47 | * Processes the UDP packet. 48 | * Returns verdict. 49 | */ 50 | int process_udp_packet(const struct section_config_t *section, const uint8_t *pkt, size_t pktlen); 51 | 52 | 53 | 54 | /** 55 | * Sends fake client hello. 56 | */ 57 | int post_fake_sni(struct fake_type f_type, 58 | const void *iph, unsigned int iph_len, 59 | const struct tcphdr *tcph, unsigned int tcph_len); 60 | 61 | /** 62 | * Splits packet by poses and posts. 63 | * Poses are relative to start of TCP payload. 64 | * dvs used internally and should be zero. 65 | */ 66 | int send_tcp_frags(const struct section_config_t *section, 67 | const uint8_t *packet, size_t pktlen, 68 | const size_t *poses, size_t poses_len, size_t dvs); 69 | 70 | /** 71 | * Splits packet by poses and posts. 72 | * Poses are relative to start of TCP payload. 73 | * dvs used internally and should be zero. 74 | */ 75 | int send_ip4_frags(const struct section_config_t *section, 76 | const uint8_t *packet, size_t pktlen, 77 | const size_t *poses, size_t poses_len, size_t dvs); 78 | #endif /* YU_MANGLE_H */ 79 | -------------------------------------------------------------------------------- /src/raw_replacements.h: -------------------------------------------------------------------------------- 1 | #ifndef RAW_REPLACEMENTS_H 2 | #define RAW_REPLACEMENTS_H 3 | 4 | #define FAKE_SNI_MAXLEN 1500 5 | 6 | static const char fake_sni[] = "\026\003\001\002\000\001\000\001\374\003\003\323[\345\201f\362\200:B\356Uq\355X\315i\235*\021\367\331\272\a>\233\254\355\307/\342\372\265 \275\2459l&r\222\313\361\3729`\376\256\233\333O\001\373\33050\r\260f,\231\035 \324^\000>\023\002\023\003\023\001\300,\3000\000\237\314\251\314\250\314\252\300+\300/\000\236\300$\300(\000k\300#\300'\000g\300\n\300\024\0009\300\t\300\023\0003\000\235\000\234\000=\000<\0005\000/\000\377\001\000\001u\000\000\000\023\000\021\000\000\016www.google.com\000\v\000\004\003\000\001\002\000\n\000\026\000\024\000\035\000\027\000\036\000\031\000\030\001\000\001\001\001\002\001\003\001\004\000\020\000\016\000\f\002h2\bhttp/1.1\000\026\000\000\000\027\000\000\0001\000\000\000\r\0000\000.\004\003\005\003\006\003\b\a\b\b\b\032\b\033\b\034\b\t\b\n\b\v\b\004\b\005\b\006\004\001\005\001\006\001\003\003\003\001\003\002\004\002\005\002\006\002\000+\000\005\004\003\004\003\003\000-\000\002\001\001\0003\000&\000$\000\035\000 \004\224\206\021\256\f\222\266\3435\216\202\342\2573\341\3503\2107\341\023\016\240r|6\000^K\310s\000\025\000\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"; 7 | 8 | static const char fake_sni_old[] = "\026\003\001\004\316\001\000\004\312\003\003K+\272\314\340\306\374>dw%\f\223\346\225\270\270~\335\027\f\264\341H\267\357\303\216T\322[\371 \245\320\212V6\374\3706\232\0216B\325\273P\b\300>\0332>\362\323\033\322\301\204\022f8\223\214\000\"\023\001\023\003\023\002\300+\300/\314\251\314\250\300,\3000\300\n\300\t\300\023\300\024\000\234\000\235\000/\0005\001\000\004_\000\000\000\023\000\021\000\000\016www.google.com\000\027\000\000\377\001\000\001\000\000\n\000\016\000\f\000\035\000\027\000\030\000\031\001\000\001\001\000\v\000\002\001\000\000\020\000\v\000\t\bhttp/1.1\000\005\000\005\001\000\000\000\000\000\"\000\n\000\b\004\003\005\003\006\003\002\003\0003\000k\000i\000\035\000 \333C\212\234-\t\237#\202\\\231\311\022]\333\341t(\t\276U\373u\234\316J~,^|*Z\000\027\000A\004k\n\255\254\376X\226t\001;n~\033\034.\245\027\024\3762_\352$\374\346^f\fF,\201\275\263\336O\231\001\032\200\357dI\266y\031\323\311vR\232\004\r\366FT\004\335\326\356\256\230B\t\313\000*\000\000\000+\000\005\004\003\004\003\003\000\r\000\030\000\026\004\003\005\003\006\003\b\004\b\005\b\006\004\001\005\001\006\001\002\003\002\001\000-\000\002\001\001\000\034\000\002@\001\376\r\0029\000\000\001\000\003\344\000 \337\306\243\332Y\033\a\252\352\025\365Z\035\223\226\304\255\363\215G\356g\344%}7\217\033n\211^\201\002\017g\267\334\326OD}\336\341ZC\230\226'\225\313\357\211\\\242\273\030k\216\377U\315\206\2410\200\203\332Z\223\005\370\b\304\370f\017\200\023\241\223~?\270{\037b\312\001\270\227\366\356\352\002\314\351\006\237\241q\226\300\314\321o\247{\201\317\230}B\005T\3660\335\320\332r?S\217\tq\036\031\326I|\237]\311 c\f\024r\031\310W\373\257\314q)q\030\237\261\227\217Kd?\257'G\320\020\340\256ND\247\005\341\324\024OP>\370\350\270b\311wAj\t\311\213\365i\203\230x\207\354\245<\274\202\230c\v0Y\263\364\022\303a\200\022\031\314\271rl=\327\336\001\327\264\267\342\353\352=\354[u\224\260\257\034\004\232\023\226}\227\030e\221\"\350\207\027dId\324\305\362N:\035\307`\204\337\201;\221\320\266b\362hrH\345e\206\246%\006\020a4\3430\036\225\215\274\275\360Q&\271\237)\222uK\362\017o\220\226W\357\267#\357\v\023\354\213\2629\331\ad\005/~6k\000[\247\301\270\310qJ\004\303|m5\363\376Y\002\243}6\251x\024\331)GH\335\205rI\032\f\210\a\212\347]\271\030\347.\021\213\365\026\030\340/Ny\r\332\3577\3203\026iX}>\2507\327&XRXU!\017\270I\313\352\350^?\352Uss\017\266pF\222NI\245\307_\305#\361\352\243+-\266\317Q\036s\243\277\355{S&\023>\275\360\215\032V\237XOY\345u>\002\305\252T\354\035\327v{P\352M\233\366\221\270\377\251\261f+rF\201wL2W\266X\252\242X\2536I\337c\205uZ\254Fe\305h\t\371\376\216r\336Y\327h\347*\331\257-ZQ{(\336\226\206\017\037\036\021\341\027z\033\254\235\252\227\224\004?p\243\351\\\263\352\205\327#W\345\255\256\375\267bP\3047\363!*K\003t\212(\306\214P\215\3506j\025\375\213e\254s\000)\001\034\000\367\000\361\002\276W%\232?\326\223\277\211v\017\a\361\347\312N\226\024L\260v\210\271j\324[|\270\344\3773\321-\313b>~\310\253XIR\324)&;\033{g;)\344\255\226\370\347I\\y\020\324\360\211vC\310\226s\267|\273$\341\332\2045qh\245w\2255\214\316\030\255\301\326C\343\304=\245\231h`yd\000#s\002\370\374Z\0336\245\361\226\222\306\032k\2457\016h\314(R;\326T~EHH\352\307\023^\247\363\321`V\340\253Z\233\357\227I\373\337z\177\nv\261\252\371\017\226\223\345\005\315y4\b\236N0\2630\017\215c\305&L\260\346J\237\203Q(\335W\027|>\3553\275j\307?W5\3463kc\350\262C\361 \037w!\371}\214\"I\377|\331@a;\342\3566\312\272Z\327u7\204'\215YBLL\235\236\242\345\215\245T\211a\312\263\342\000! \221\202X$\302\317\203\246\207c{\231\330\264\324\\k\271\272\336\356\002|\261O\207\030+\367P\317\356"; 9 | 10 | #endif /*RAW_REPLACEMENTS_H*/ 11 | -------------------------------------------------------------------------------- /src/tls.h: -------------------------------------------------------------------------------- 1 | /* 2 | youtubeUnblock - https://github.com/Waujito/youtubeUnblock 3 | 4 | Copyright (C) 2024-2025 Vadim Vetrov 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. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #ifndef TLS_H 21 | #define TLS_H 22 | 23 | #include "types.h" 24 | #include "utils.h" 25 | 26 | 27 | /** 28 | * Result of analyze_tls_data function 29 | */ 30 | struct tls_verdict { 31 | const uint8_t *sni_ptr; 32 | int sni_len; 33 | 34 | int target_sni; /* boolean, 1 if target found */ 35 | const uint8_t *target_sni_ptr; /* pointer to target domain instead of entire sni */ 36 | int target_sni_len; /* length of target domain instead of entire sni */ 37 | }; 38 | 39 | #define TLS_CONTENT_TYPE_HANDSHAKE 0x16 40 | #define TLS_HANDSHAKE_TYPE_CLIENT_HELLO 0x01 41 | #define TLS_EXTENSION_SNI 0x0000 42 | #define TLS_EXTENSION_CLIENT_HELLO_ENCRYPTED 0xfe0d 43 | 44 | #define TLS_MESSAGE_ANALYZE_INVALID -1 45 | #define TLS_MESSAGE_ANALYZE_FOUND 0 46 | #define TLS_MESSAGE_ANALYZE_GOTO_NEXT 1 47 | 48 | /** 49 | * Analyzes each TLS Client Hello message (inside TLS Record or QUIC CRYPTO FRAME) 50 | */ 51 | int analyze_tls_message( 52 | const struct section_config_t *section, 53 | const uint8_t *message_data, 54 | size_t message_length, 55 | struct tls_verdict *tlsv 56 | ); 57 | 58 | /** 59 | * Tries to bruteforce over the packet and match domains as plain text 60 | */ 61 | int bruteforce_analyze_sni_str( 62 | const struct section_config_t *section, 63 | const uint8_t *data, size_t dlen, 64 | struct tls_verdict *vrd 65 | ); 66 | 67 | 68 | /** 69 | * Processes the packet and finds TLS Client Hello information inside it. 70 | * data pointer points to start of TLS Message (TCP Payload) 71 | * 72 | * Note that all the constant pointers of tls_verdict will be relative to data pointer 73 | */ 74 | struct tls_verdict analyze_tls_data(const struct section_config_t *section, const uint8_t *data, size_t dlen); 75 | 76 | 77 | /** 78 | * Allocates and generates the fake client hello message 79 | */ 80 | int gen_fake_sni(struct fake_type type, 81 | const void *iph, size_t iph_len, 82 | const struct tcphdr *tcph, size_t tcph_len, 83 | uint8_t **ubuf, size_t *ubuflen); 84 | 85 | #endif /* TLS_H */ 86 | -------------------------------------------------------------------------------- /src/trie.c: -------------------------------------------------------------------------------- 1 | /* 2 | youtubeUnblock - https://github.com/Waujito/youtubeUnblock 3 | 4 | Copyright (C) 2024-2025 Vadim Vetrov 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. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | /** 21 | * This is slightly optimized Aho-Corasick implementation 22 | * 23 | * Big thanks to e-maxx http://e-maxx.ru/algo/aho_corasick 24 | * for the best description and reference code samples 25 | */ 26 | 27 | #include "trie.h" 28 | 29 | int trie_init(struct trie_container *trie) { 30 | void *vx = malloc(sizeof(struct trie_vertex) * TRIE_STARTSZ); 31 | if (vx == NULL) { 32 | return -ENOMEM; 33 | } 34 | trie->vx = vx; 35 | trie->arrsz = TRIE_STARTSZ; 36 | trie->sz = 1; 37 | 38 | struct trie_vertex *trx = trie->vx; 39 | trx->p = trx->link = -1; 40 | trx->leaf = 0; 41 | trx->depth = 0; 42 | trx->pch = 0; 43 | memset(trx->go, 0xff, sizeof(trie->vx[0].go)); 44 | 45 | return 0; 46 | } 47 | 48 | void trie_destroy(struct trie_container *trie) { 49 | trie->arrsz = 0; 50 | trie->sz = 0; 51 | free(trie->vx); 52 | trie->vx = NULL; 53 | } 54 | 55 | /** 56 | * 57 | * Increases trie vertex container size. 58 | * Returns new vertex index or ret < 0 on error 59 | * 60 | */ 61 | static int trie_push_vertex(struct trie_container *trie) { 62 | if (trie->sz == NMAX - 1) { 63 | return -EINVAL; 64 | } 65 | 66 | if (trie->arrsz == trie->sz) { // realloc 67 | void *pt = realloc(trie->vx, 68 | sizeof(struct trie_vertex) * trie->arrsz * 2); 69 | if (pt == NULL) { 70 | return -ENOMEM; 71 | } 72 | 73 | trie->arrsz *= 2; 74 | trie->vx = pt; 75 | } 76 | 77 | return trie->sz++; 78 | } 79 | 80 | 81 | int trie_add_string(struct trie_container *trie, 82 | const uint8_t *str, size_t strlen) { 83 | if (trie == NULL || trie->vx == NULL) { 84 | return -EINVAL; 85 | } 86 | 87 | int v = 0; 88 | int nv; 89 | 90 | for (size_t i = 0; i < strlen; ++i) { 91 | uint8_t c = str[i]; 92 | if (c >= TRIE_ALPHABET) { 93 | return -EINVAL; 94 | } 95 | 96 | if (trie->vx[v].go[c] == -1) { 97 | nv = trie_push_vertex(trie); 98 | if (nv < 0) { 99 | return nv; 100 | } 101 | struct trie_vertex *tvx = trie->vx + nv; 102 | 103 | memset(tvx->go, 0xff, sizeof(tvx->go)); 104 | tvx->link = -1; 105 | tvx->p = v; 106 | tvx->depth = trie->vx[v].depth + 1; 107 | tvx->leaf = 0; 108 | tvx->pch = c; 109 | trie->vx[v].go[c] = nv; 110 | } 111 | v = trie->vx[v].go[c]; 112 | } 113 | 114 | if (v != 0) { 115 | trie->vx[v].leaf = 1; 116 | } 117 | 118 | return 0; 119 | } 120 | 121 | static int trie_go(struct trie_container *trie, 122 | int v, uint8_t c); 123 | 124 | static int trie_get_link(struct trie_container *trie, 125 | int v) { 126 | struct trie_vertex *tvx = trie->vx + v; 127 | 128 | if (tvx->link == -1) { 129 | if (v == 0 || tvx->p == 0) { 130 | tvx->link = 0; 131 | } else { 132 | tvx->link = trie_go(trie, 133 | trie_get_link(trie, tvx->p), tvx->pch); 134 | } 135 | } 136 | 137 | return tvx->link; 138 | } 139 | 140 | static int trie_go(struct trie_container *trie, int v, uint8_t c) { 141 | struct trie_vertex *tvx = trie->vx + v; 142 | 143 | if (tvx->go[c] == -1) { 144 | tvx->go[c] = v == 0 ? 0 : 145 | trie_go(trie, trie_get_link(trie, v), c); 146 | } 147 | 148 | return tvx->go[c]; 149 | } 150 | 151 | 152 | int trie_process_str( 153 | struct trie_container *trie, 154 | const uint8_t *str, size_t strlen, 155 | int flags, 156 | size_t *offset, size_t *offlen 157 | ) { 158 | if (trie == NULL || trie->vx == NULL) { 159 | return 0; 160 | } 161 | 162 | int v = 0; 163 | size_t i = 0; 164 | uint8_t c; 165 | int len; 166 | 167 | for (; i < strlen; ++i) { 168 | c = str[i]; 169 | if (c >= TRIE_ALPHABET) { 170 | v = 0; 171 | continue; 172 | } 173 | 174 | v = trie->vx[v].go[c] != -1 ? trie->vx[v].go[c] : 175 | trie_go(trie, v, str[i]); 176 | 177 | if (trie->vx[v].leaf && 178 | ((flags & TRIE_OPT_MAP_TO_END) != TRIE_OPT_MAP_TO_END || 179 | i == strlen - 1) 180 | ) { 181 | ++i; 182 | break; 183 | } 184 | } 185 | 186 | len = trie->vx[v].depth; 187 | if ( trie->vx[v].leaf && 188 | i >= len 189 | ) { 190 | size_t sp = i - len; 191 | *offset = sp; 192 | *offlen = len; 193 | return 1; 194 | } 195 | 196 | return 0; 197 | } 198 | -------------------------------------------------------------------------------- /src/trie.h: -------------------------------------------------------------------------------- 1 | /* 2 | youtubeUnblock - https://github.com/Waujito/youtubeUnblock 3 | 4 | Copyright (C) 2024-2025 Vadim Vetrov 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. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | /** 21 | * This is slightly optimized Aho-Corasick implementation 22 | * 23 | * Big thanks to e-maxx http://e-maxx.ru/algo/aho_corasick 24 | * for the best description and reference code samples 25 | * 26 | */ 27 | 28 | /** 29 | * 30 | * This algorithm allows us to search inside the string 31 | * for a list of patterns in the linear time. 32 | * 33 | * The algorithm will lazily initialize itself while 34 | * youtubeUnblock works. Lazy initializations considered 35 | * safe for multithreading and operate without atomicity 36 | * or synchronization primitives. 37 | * 38 | */ 39 | 40 | #ifndef TRIE_H 41 | #define TRIE_H 42 | 43 | #include "types.h" 44 | 45 | // ASCII alphabet 46 | #define TRIE_ALPHABET 128 47 | // Maximum of vertexes in the trie 48 | #define NMAX ((1 << 15) - 1) 49 | 50 | struct trie_vertex { 51 | int leaf; // boolean flag 52 | int depth; // depth of tree (length of substring) 53 | int p; // parent 54 | uint8_t pch; // vertex char 55 | int link; // sufflink 56 | int16_t go[TRIE_ALPHABET]; // dynamically filled pushes 57 | }; 58 | 59 | struct trie_container { 60 | struct trie_vertex *vx; 61 | size_t arrsz; 62 | size_t sz; 63 | }; 64 | 65 | #define TRIE_STARTSZ 32 66 | int trie_init(struct trie_container *trie); 67 | void trie_destroy(struct trie_container *trie); 68 | 69 | int trie_add_string(struct trie_container *trie, 70 | const uint8_t *str, size_t strlen); 71 | 72 | /** 73 | * Aligns the pattern to the end 74 | */ 75 | #define TRIE_OPT_MAP_TO_END (1 << 1) 76 | 77 | /** 78 | * Searches the string for the patterns. 79 | * flags is TRIE_OPT binary mask with options for search. 80 | * offset, offlen are destination variables with 81 | * offset of the given string and length of target. 82 | * 83 | * returns 1 if target found, 0 otherwise 84 | */ 85 | int trie_process_str( 86 | struct trie_container *trie, 87 | const uint8_t *str, size_t strlen, 88 | int flags, 89 | size_t *offset, size_t *offlen 90 | ); 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /src/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | youtubeUnblock - https://github.com/Waujito/youtubeUnblock 3 | 4 | Copyright (C) 2024-2025 Vadim Vetrov 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. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #define _GNU_SOURCE 21 | #ifndef TYPES_H 22 | #define TYPES_H 23 | #include 24 | 25 | #ifdef KERNEL_SPACE 26 | #include // IWYU pragma: export 27 | #include // IWYU pragma: export 28 | 29 | #include 30 | 31 | typedef __u8 uint8_t; 32 | typedef __u16 uint16_t; 33 | typedef __u32 uint32_t; 34 | typedef __u64 uint64_t; 35 | typedef __s8 int8_t; 36 | typedef __s16 int16_t; 37 | typedef __s32 int32_t; 38 | typedef __s64 int64_t; 39 | 40 | typedef __s32 int_least32_t; /* integer of >= 32 bits */ 41 | typedef __s16 int_least16_t; /* integer of >= 16 bits */ 42 | #else /* USER_SPACE */ 43 | 44 | #include // IWYU pragma: export 45 | #include // IWYU pragma: export 46 | #include // IWYU pragma: export 47 | #include // IWYU pragma: export 48 | #include // IWYU pragma: export 49 | 50 | 51 | #define _NO_GETRANDOM ((__GLIBC__ <= 2 && __GLIBC_MINOR__ < 25)) 52 | 53 | #if !_NO_GETRANDOM 54 | #include // IWYU pragma: export 55 | #endif 56 | 57 | #endif /* SPACES */ 58 | 59 | // Network specific structures 60 | #ifdef KERNEL_SPACE 61 | #include // IWYU pragma: export 62 | #include // IWYU pragma: export 63 | #include // IWYU pragma: export 64 | #include // IWYU pragma: export 65 | #include // IWYU pragma: export 66 | #include // IWYU pragma: export 67 | #include 68 | 69 | #define free kfree 70 | #define malloc(size) kmalloc((size), GFP_KERNEL) 71 | #define realloc(pt, size) krealloc((pt), (size), GFP_KERNEL) 72 | #define calloc(n, size) kcalloc((n), (size), GFP_KERNEL) 73 | 74 | #define ip6_hdr ipv6hdr 75 | 76 | /* from */ 77 | #define IP_RF 0x8000 /* reserved fragment flag */ 78 | #define IP_DF 0x4000 /* dont fragment flag */ 79 | #define IP_MF 0x2000 /* more fragments flag */ 80 | #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ 81 | 82 | #ifdef __LITTLE_ENDIAN 83 | #define __BIG_ENDIAN 4321 84 | #define __BYTE_ORDER __LITTLE_ENDIAN 85 | #elif defined(__BIG_ENDIAN) 86 | #define __LITTLE_ENDIAN 1234 87 | #define __BYTE_ORDER __BIG_ENDIAN 88 | #else 89 | #error "Unsupported endian" 90 | #endif 91 | 92 | #define ip6_plen payload_len 93 | #define ip6_nxt nexthdr 94 | #define ip6_hops hop_limit 95 | #define ip6_hlim hop_limit 96 | #define ip6_src saddr 97 | #define ip6_dst daddr 98 | 99 | #else /* USER_SPACE */ 100 | #include // IWYU pragma: export 101 | #include // IWYU pragma: export 102 | #include // IWYU pragma: export 103 | #include // IWYU pragma: export 104 | #include // IWYU pragma: export 105 | #endif 106 | 107 | #define SFREE(item) do { \ 108 | free((item)); \ 109 | (item) = NULL; \ 110 | } while (0) 111 | 112 | #ifndef KERNEL_SPACE 113 | 114 | #define max(a,b)__extension__\ 115 | ({ \ 116 | __typeof__ (a) _a = (a); \ 117 | __typeof__ (b) _b = (b); \ 118 | _a > _b ? _a : _b; \ 119 | }) 120 | 121 | #define min(a,b)__extension__\ 122 | ({ \ 123 | __typeof__ (a) _a = (a); \ 124 | __typeof__ (b) _b = (b); \ 125 | _a < _b ? _a : _b; \ 126 | }) 127 | 128 | #endif /* not a KERNEL_SPACE */ 129 | 130 | static inline int randint(void) { 131 | int rnd; 132 | 133 | #ifdef KERNEL_SPACE 134 | get_random_bytes(&rnd, sizeof(rnd)); 135 | #else 136 | rnd = random(); 137 | #endif 138 | 139 | return rnd; 140 | } 141 | 142 | #ifdef KERNEL_SPACE 143 | #define socklen_t size_t 144 | #endif 145 | const char *inet_ntop(int af, const void * a0, char * s, socklen_t l); 146 | 147 | #endif /* TYPES_H */ 148 | -------------------------------------------------------------------------------- /test/main_fn.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | #include "unity_fixture.h" 3 | 4 | struct instance_config_t instance_config = { 5 | .send_raw_packet = NULL, 6 | .send_delayed_packet = NULL, 7 | }; 8 | 9 | static void RunAllTests(void) 10 | { 11 | RUN_TEST_GROUP(TLSTest) 12 | RUN_TEST_GROUP(QuicTest); 13 | RUN_TEST_GROUP(TrieTest); 14 | } 15 | 16 | int main(int argc, const char * argv[]) 17 | { 18 | return UnityMain(argc, argv, RunAllTests); 19 | } 20 | -------------------------------------------------------------------------------- /test/tls.c: -------------------------------------------------------------------------------- 1 | static const char tls_chlo_message[] = "\001\000\002\000\003\003*{D\360FDTZ\305\231\272\006\240\246oa\365}ut\321\033\354\361}\334\227\342\215\257]\332\000\000\006\023\001\023\002\023\003\001\000\001\321\0009\000_\t\002@g\017\000\005\004\200`\000\000q'\004\200\001\026\210\a\004\200`\000\000\001\004\200\000u0\003\002E\300\006\004\200`\000\000\316E,\310\0160;\306\003g\201k\004\004\200\360\000\000\200\000GR\004\000\000\000\001 \004\200\001\000\000\200\377s\333\f\000\000\000\001\n\212\nJ\000\000\000\001\b\002@d\000\020\000\005\000\003\002h3\000+\000\003\002\003\004\000\n\000\b\000\006\000\035\000\027\000\030\000\033\000\003\002\000\002Di\000\005\000\003\002h3\000\r\000\024\000\022\004\003\b\004\004\001\005\003\b\005\005\001\b\006\006\001\002\001\000-\000\002\001\001\376\r\000\332\000\000\001\000\001|\000 \004\256\340\330}\337lC3\304gv\325}\rT\370O,i^\001\357\323\373?\205@3\023\354{\000\260\247cf\207\3276\312\205G\017\213Y\231\b\301~\225r\v\001X\026\335\254H\231\237\237\263\027b\b\327\0351W\000\177tc\213:^\f\362\340\225_\272\331\351\002\026rds\326\034\345*5!\221\265\206\270\240\375\nw\v\340 \003\340\307\230H\203#\212\371\364\257H\220\230L\230{\243\355\v'\325@\240EZ\306\230a\233;\033|=(\372P\232\216\215\203\374\234\222\375\004\3058l\275+?\f\306\335\342Q\313\"F\377G<2Jqb\033\033,|\302w\337bO\032\276\374\312X\364}\255xq\274\2348\247K\345t\327\345\322M\004\220\376*\344\365\0003\000&\000$\000\035\000 W\356I\271\201\350\263[cn\\H?\376s``\v\230\306?E=2\017u\306\027\nc{c\000\000\000\030\000\026\000\000\023abc.defghijklm.ndev"; 2 | 3 | static const char tls_bruteforce_message[] = "ahl qlwer 12oi34j 1l2kjrdosij f982j jfa osdijwoeij rasdjf oiajsqw9erj pqwoijf lasdj foijyoutube.com"; 4 | 5 | #include "unity.h" 6 | #include "unity_fixture.h" 7 | 8 | #include "types.h" 9 | #include 10 | #include "tls.h" 11 | #include "config.h" 12 | #include "logging.h" 13 | 14 | static struct section_config_t sconf = default_section_config; 15 | 16 | TEST_GROUP(TLSTest); 17 | 18 | TEST_SETUP(TLSTest) 19 | { 20 | } 21 | 22 | TEST_TEAR_DOWN(TLSTest) 23 | { 24 | } 25 | 26 | TEST(TLSTest, Test_CHLO_message_detect) 27 | { 28 | struct tls_verdict tlsv; 29 | int ret; 30 | ret = analyze_tls_message(&sconf, (const uint8_t *)tls_chlo_message, sizeof(tls_chlo_message) - 1, &tlsv); 31 | TEST_ASSERT_EQUAL(0, ret); 32 | TEST_ASSERT_GREATER_OR_EQUAL(19, tlsv.sni_len); 33 | TEST_ASSERT_EQUAL_STRING_LEN("abc.defghijklm.ndev", tlsv.sni_ptr, 19); 34 | } 35 | 36 | TEST(TLSTest, Test_Bruteforce_detects) 37 | { 38 | struct tls_verdict tlsv; 39 | struct trie_container trie; 40 | int ret; 41 | ret = trie_init(&trie); 42 | ret = trie_add_string(&trie, (uint8_t *)"youtube.com", 11); 43 | sconf.sni_domains = trie; 44 | 45 | ret = bruteforce_analyze_sni_str(&sconf, (const uint8_t *)tls_bruteforce_message, sizeof(tls_bruteforce_message) - 1, &tlsv); 46 | TEST_ASSERT_EQUAL(0, ret); 47 | TEST_ASSERT_EQUAL(11, tlsv.sni_len); 48 | TEST_ASSERT_EQUAL_STRING_LEN("youtube.com", tlsv.sni_ptr, 11); 49 | TEST_ASSERT_EQUAL_PTR(tls_bruteforce_message + 50 | sizeof(tls_bruteforce_message) - 12, tlsv.sni_ptr); 51 | trie_destroy(&trie); 52 | } 53 | 54 | TEST_GROUP_RUNNER(TLSTest) 55 | { 56 | RUN_TEST_CASE(TLSTest, Test_CHLO_message_detect); 57 | RUN_TEST_CASE(TLSTest, Test_Bruteforce_detects); 58 | } 59 | -------------------------------------------------------------------------------- /test/trie.c: -------------------------------------------------------------------------------- 1 | #include "unity.h" 2 | #include "unity_fixture.h" 3 | 4 | #include "trie.h" 5 | 6 | TEST_GROUP(TrieTest); 7 | 8 | TEST_SETUP(TrieTest) 9 | { 10 | } 11 | 12 | TEST_TEAR_DOWN(TrieTest) 13 | { 14 | } 15 | 16 | const char ASTR[] = "abacaba"; 17 | const char BSTR[] = "BABABABA"; 18 | const char CSTR[] = "abracadabra"; 19 | 20 | const char tstr[] = "aBABABABDADAabacabracadabraabbbabacabaaaaaabacaba"; 21 | 22 | 23 | TEST(TrieTest, Trie_string_adds) 24 | { 25 | int ret; 26 | size_t offset; 27 | size_t offlen; 28 | struct trie_container trie; 29 | 30 | ret = trie_init(&trie); 31 | TEST_ASSERT_EQUAL(0, ret); 32 | ret = trie_add_string(&trie, (uint8_t *)ASTR, sizeof(ASTR) - 1); 33 | TEST_ASSERT_EQUAL(0, ret); 34 | ret = trie_add_string(&trie, (uint8_t *)BSTR, sizeof(BSTR) - 1); 35 | TEST_ASSERT_EQUAL(0, ret); 36 | ret = trie_add_string(&trie, (uint8_t *)CSTR, sizeof(CSTR) - 1); 37 | TEST_ASSERT_EQUAL(0, ret); 38 | 39 | TEST_ASSERT_EQUAL(25, trie.sz); 40 | 41 | trie_destroy(&trie); 42 | } 43 | 44 | TEST(TrieTest, Trie_string_finds) 45 | { 46 | int ret; 47 | size_t offset; 48 | size_t offlen; 49 | struct trie_container trie; 50 | 51 | ret = trie_init(&trie); 52 | ret = trie_add_string(&trie, (uint8_t *)ASTR, sizeof(ASTR) - 1); 53 | ret = trie_add_string(&trie, (uint8_t *)BSTR, sizeof(BSTR) - 1); 54 | ret = trie_add_string(&trie, (uint8_t *)CSTR, sizeof(CSTR) - 1); 55 | 56 | ret = trie_process_str(&trie, 57 | (uint8_t *)tstr, sizeof(tstr) - 1, 58 | 0, &offset, &offlen 59 | ); 60 | TEST_ASSERT_EQUAL(1, ret); 61 | TEST_ASSERT_EQUAL(11, offlen); 62 | TEST_ASSERT_EQUAL_STRING_LEN("abracadabra", tstr + offset, offlen); 63 | 64 | trie_destroy(&trie); 65 | } 66 | 67 | TEST(TrieTest, Trie_string_finds_opt_end) 68 | { 69 | int ret; 70 | size_t offset; 71 | size_t offlen; 72 | struct trie_container trie; 73 | 74 | ret = trie_init(&trie); 75 | ret = trie_add_string(&trie, (uint8_t *)ASTR, sizeof(ASTR) - 1); 76 | ret = trie_add_string(&trie, (uint8_t *)BSTR, sizeof(BSTR) - 1); 77 | ret = trie_add_string(&trie, (uint8_t *)CSTR, sizeof(CSTR) - 1); 78 | 79 | ret = trie_process_str(&trie, 80 | (uint8_t *)tstr, sizeof(tstr) - 1, 81 | TRIE_OPT_MAP_TO_END, 82 | &offset, &offlen 83 | ); 84 | TEST_ASSERT_EQUAL(1, ret); 85 | TEST_ASSERT_EQUAL(7, offlen); 86 | TEST_ASSERT_EQUAL_STRING_LEN("abacaba", tstr + offset, offlen); 87 | 88 | ret = trie_process_str(&trie, 89 | (uint8_t *)tstr, sizeof(tstr), 90 | TRIE_OPT_MAP_TO_END, 91 | &offset, &offlen 92 | ); 93 | TEST_ASSERT_EQUAL(0, ret); 94 | 95 | trie_destroy(&trie); 96 | } 97 | 98 | TEST(TrieTest, Trie_single_vertex) 99 | { 100 | int ret; 101 | size_t offset; 102 | size_t offlen; 103 | struct trie_container trie; 104 | 105 | ret = trie_init(&trie); 106 | 107 | ret = trie_process_str(&trie, 108 | (uint8_t *)tstr, sizeof(tstr) - 1, 109 | 0, 110 | &offset, &offlen 111 | ); 112 | TEST_ASSERT_EQUAL(0, ret); 113 | 114 | trie_destroy(&trie); 115 | 116 | } 117 | 118 | TEST(TrieTest, Trie_uninitialized) 119 | { 120 | int ret; 121 | size_t offset; 122 | size_t offlen; 123 | struct trie_container trie = {0}; 124 | 125 | // ret = trie_init(&trie); 126 | 127 | ret = trie_add_string(&trie, (uint8_t *)ASTR, sizeof(ASTR) - 1); 128 | TEST_ASSERT_EQUAL(-EINVAL, ret); 129 | 130 | ret = trie_process_str(&trie, 131 | (uint8_t *)tstr, sizeof(tstr) - 1, 132 | 0, 133 | &offset, &offlen 134 | ); 135 | TEST_ASSERT_EQUAL(0, ret); 136 | 137 | } 138 | 139 | 140 | TEST_GROUP_RUNNER(TrieTest) 141 | { 142 | RUN_TEST_CASE(TrieTest, Trie_string_adds); 143 | RUN_TEST_CASE(TrieTest, Trie_string_finds); 144 | RUN_TEST_CASE(TrieTest, Trie_string_finds_opt_end); 145 | RUN_TEST_CASE(TrieTest, Trie_single_vertex); 146 | RUN_TEST_CASE(TrieTest, Trie_uninitialized); 147 | } 148 | -------------------------------------------------------------------------------- /test/unity/unity_fixture.h: -------------------------------------------------------------------------------- 1 | /* ========================================================================= 2 | Unity - A Test Framework for C 3 | ThrowTheSwitch.org 4 | Copyright (c) 2007-25 Mike Karlesky, Mark VanderVoord, & Greg Williams 5 | SPDX-License-Identifier: MIT 6 | ========================================================================= */ 7 | 8 | #ifndef UNITY_FIXTURE_H_ 9 | #define UNITY_FIXTURE_H_ 10 | 11 | #include "unity.h" 12 | #include "unity_fixture_internals.h" 13 | 14 | #ifndef UNITY_FIXTURE_NO_EXTRAS 15 | #include "unity_memory.h" 16 | #endif 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include "unity_internals.h" 24 | 25 | 26 | int UnityMain(int argc, const char* argv[], void (*runAllTests)(void)); 27 | 28 | 29 | #define TEST_GROUP(group)\ 30 | static const char* TEST_GROUP_##group = #group 31 | 32 | #define TEST_SETUP(group) void TEST_##group##_SETUP(void);\ 33 | void TEST_##group##_SETUP(void) 34 | 35 | #define TEST_TEAR_DOWN(group) void TEST_##group##_TEAR_DOWN(void);\ 36 | void TEST_##group##_TEAR_DOWN(void) 37 | 38 | 39 | #define TEST(group, name) \ 40 | void TEST_##group##_##name##_(void);\ 41 | void TEST_##group##_##name##_run(void);\ 42 | void TEST_##group##_##name##_run(void)\ 43 | {\ 44 | UnityTestRunner(TEST_##group##_SETUP,\ 45 | TEST_##group##_##name##_,\ 46 | TEST_##group##_TEAR_DOWN,\ 47 | "TEST(" #group ", " #name ")",\ 48 | TEST_GROUP_##group, #name,\ 49 | __FILE__, __LINE__);\ 50 | }\ 51 | void TEST_##group##_##name##_(void) 52 | 53 | #define IGNORE_TEST(group, name) \ 54 | void TEST_##group##_##name##_(void);\ 55 | void TEST_##group##_##name##_run(void);\ 56 | void TEST_##group##_##name##_run(void)\ 57 | {\ 58 | UnityIgnoreTest("IGNORE_TEST(" #group ", " #name ")", TEST_GROUP_##group, #name);\ 59 | }\ 60 | void TEST_##group##_##name##_(void) 61 | 62 | /* Call this for each test, insider the group runner */ 63 | #define RUN_TEST_CASE(group, name) \ 64 | { void TEST_##group##_##name##_run(void);\ 65 | TEST_##group##_##name##_run(); } 66 | 67 | /* This goes at the bottom of each test file or in a separate c file */ 68 | #define TEST_GROUP_RUNNER(group)\ 69 | void TEST_##group##_GROUP_RUNNER(void);\ 70 | void TEST_##group##_GROUP_RUNNER(void) 71 | 72 | /* Call this from main */ 73 | #define RUN_TEST_GROUP(group)\ 74 | { void TEST_##group##_GROUP_RUNNER(void);\ 75 | TEST_##group##_GROUP_RUNNER(); } 76 | 77 | /* CppUTest Compatibility Macros */ 78 | #ifndef UNITY_EXCLUDE_CPPUTEST_ASSERTS 79 | /* Sets a pointer and automatically restores it to its old value after teardown */ 80 | #define UT_PTR_SET(ptr, newPointerValue) UnityPointer_Set((void**)&(ptr), (void*)(newPointerValue), __LINE__) 81 | #define TEST_ASSERT_POINTERS_EQUAL(expected, actual) TEST_ASSERT_EQUAL_PTR((expected), (actual)) 82 | #define TEST_ASSERT_BYTES_EQUAL(expected, actual) TEST_ASSERT_EQUAL_HEX8(0xff & (expected), 0xff & (actual)) 83 | #define FAIL(message) TEST_FAIL_MESSAGE((message)) 84 | #define CHECK(condition) TEST_ASSERT_TRUE((condition)) 85 | #define LONGS_EQUAL(expected, actual) TEST_ASSERT_EQUAL_INT((expected), (actual)) 86 | #define STRCMP_EQUAL(expected, actual) TEST_ASSERT_EQUAL_STRING((expected), (actual)) 87 | #define DOUBLES_EQUAL(expected, actual, delta) TEST_ASSERT_DOUBLE_WITHIN((delta), (expected), (actual)) 88 | #endif 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | 94 | #endif /* UNITY_FIXTURE_H_ */ 95 | -------------------------------------------------------------------------------- /test/unity/unity_fixture_internals.h: -------------------------------------------------------------------------------- 1 | /* ========================================================================= 2 | Unity - A Test Framework for C 3 | ThrowTheSwitch.org 4 | Copyright (c) 2007-25 Mike Karlesky, Mark VanderVoord, & Greg Williams 5 | SPDX-License-Identifier: MIT 6 | ========================================================================= */ 7 | 8 | #ifndef UNITY_FIXTURE_INTERNALS_H_ 9 | #define UNITY_FIXTURE_INTERNALS_H_ 10 | 11 | #ifdef __cplusplus 12 | extern "C" 13 | { 14 | #endif 15 | 16 | struct UNITY_FIXTURE_T 17 | { 18 | int Verbose; 19 | int Silent; 20 | unsigned int RepeatCount; 21 | const char* NameFilter; 22 | const char* GroupFilter; 23 | }; 24 | extern struct UNITY_FIXTURE_T UnityFixture; 25 | 26 | typedef void unityfunction(void); 27 | void UnityTestRunner(unityfunction* setup, 28 | unityfunction* testBody, 29 | unityfunction* teardown, 30 | const char* printableName, 31 | const char* group, 32 | const char* name, 33 | const char* file, unsigned int line); 34 | 35 | void UnityIgnoreTest(const char* printableName, const char* group, const char* name); 36 | int UnityGetCommandLineOptions(int argc, const char* argv[]); 37 | void UnityConcludeFixtureTest(void); 38 | 39 | void UnityPointer_Set(void** pointer, void* newValue, UNITY_LINE_TYPE line); 40 | void UnityPointer_UndoAllSets(void); 41 | void UnityPointer_Init(void); 42 | #ifndef UNITY_MAX_POINTERS 43 | #define UNITY_MAX_POINTERS 5 44 | #endif 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* UNITY_FIXTURE_INTERNALS_H_ */ 51 | -------------------------------------------------------------------------------- /test/unity/unity_memory.h: -------------------------------------------------------------------------------- 1 | /* ========================================================================= 2 | Unity - A Test Framework for C 3 | ThrowTheSwitch.org 4 | Copyright (c) 2007-25 Mike Karlesky, Mark VanderVoord, & Greg Williams 5 | SPDX-License-Identifier: MIT 6 | ========================================================================= */ 7 | 8 | #ifndef UNITY_MEMORY_OVERRIDES_H_ 9 | #define UNITY_MEMORY_OVERRIDES_H_ 10 | 11 | #ifdef __cplusplus 12 | extern "C" 13 | { 14 | #endif 15 | 16 | #include 17 | 18 | #ifdef UNITY_EXCLUDE_STDLIB_MALLOC 19 | /* Define this macro to remove the use of stdlib.h, malloc, and free. 20 | * Many embedded systems do not have a heap or malloc/free by default. 21 | * This internal unity_malloc() provides allocated memory deterministically from 22 | * the end of an array only, unity_free() only releases from end-of-array, 23 | * blocks are not coalesced, and memory not freed in LIFO order is stranded. */ 24 | #ifndef UNITY_INTERNAL_HEAP_SIZE_BYTES 25 | #define UNITY_INTERNAL_HEAP_SIZE_BYTES 256 26 | #endif 27 | #endif 28 | 29 | /* These functions are used by Unity to allocate and release memory 30 | * on the heap and can be overridden with platform-specific implementations. 31 | * For example, when using FreeRTOS UNITY_MALLOC becomes pvPortMalloc() 32 | * and UNITY_FREE becomes vPortFree(). */ 33 | #if !defined(UNITY_MALLOC) || !defined(UNITY_FREE) 34 | #include 35 | #define UNITY_MALLOC(size) malloc(size) 36 | #define UNITY_FREE(ptr) free(ptr) 37 | #else 38 | extern void* UNITY_MALLOC(size_t size); 39 | extern void UNITY_FREE(void* ptr); 40 | #endif 41 | 42 | #define malloc unity_malloc 43 | #define calloc unity_calloc 44 | #define realloc unity_realloc 45 | #define free unity_free 46 | 47 | void* unity_malloc(size_t size); 48 | void* unity_calloc(size_t num, size_t size); 49 | void* unity_realloc(void * oldMem, size_t size); 50 | void unity_free(void * mem); 51 | 52 | /* You must compile with malloc replacement, as defined in unity_fixture_malloc_overrides.h */ 53 | void UnityMalloc_StartTest(void); 54 | void UnityMalloc_EndTest(void); 55 | void UnityMalloc_MakeMallocFailAfterCount(int countdown); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /uspace.mk: -------------------------------------------------------------------------------- 1 | #Check for using system libs 2 | USE_SYS_LIBS := no 3 | 4 | #Userspace app makes here 5 | BUILD_DIR := $(CURDIR)/build 6 | DEPSDIR := $(BUILD_DIR)/deps 7 | INCLUDE_DIR := $(CURDIR)/src 8 | SRC_DIR := $(CURDIR)/src 9 | 10 | CC:=gcc 11 | CCLD:=$(CC) 12 | LD:=ld 13 | 14 | ifeq ($(USE_SYS_LIBS), no) 15 | override CFLAGS += -I$(DEPSDIR)/include 16 | override LDFLAGS += -L$(DEPSDIR)/lib 17 | REQ = $(LIBNETFILTER_QUEUE) $(LIBMNL) $(LIBCRYPTO) 18 | endif 19 | 20 | override CFLAGS += -DPKG_VERSION=\"$(PKG_FULLVERSION)\" -I$(INCLUDE_DIR) -Wall -Wpedantic -Wno-unused-variable -std=gnu99 -Ideps/cyclone/include 21 | 22 | LIBNFNETLINK_CFLAGS := -I$(DEPSDIR)/include 23 | LIBNFNETLINK_LIBS := -L$(DEPSDIR)/lib 24 | LIBMNL_CFLAGS := -I$(DEPSDIR)/include 25 | LIBMNL_LIBS := -L$(DEPSDIR)/lib 26 | 27 | # PREFIX is environment variable, if not set default to /usr/local 28 | ifeq ($(PREFIX),) 29 | PREFIX := /usr/local 30 | endif 31 | 32 | export CC CCLD LD CFLAGS LDFLAGS LIBNFNETLINK_CFLAGS LIBNFNETLINK_LIBS LIBMNL_CFLAGS LIBMNL_LIBS 33 | 34 | APP:=$(BUILD_DIR)/youtubeUnblock 35 | TEST_APP:=$(BUILD_DIR)/testYoutubeUnblock 36 | 37 | SRCS := mangle.c args.c utils.c quic.c tls.c getopt.c quic_crypto.c inet_ntop.c trie.c 38 | OBJS := $(SRCS:%.c=$(BUILD_DIR)/%.o) 39 | APP_EXEC := youtubeUnblock.c 40 | APP_OBJ := $(APP_EXEC:%.c=$(BUILD_DIR)/%.o) 41 | 42 | 43 | TEST_SRCS := $(shell find test -name "*.c") 44 | TEST_OBJS := $(TEST_SRCS:%.c=$(BUILD_DIR)/%.o) 45 | TEST_CFLAGS := -Itest/unity -Itest 46 | 47 | LIBNFNETLINK := $(DEPSDIR)/lib/libnfnetlink.la 48 | LIBMNL := $(DEPSDIR)/lib/libmnl.la 49 | LIBNETFILTER_QUEUE := $(DEPSDIR)/lib/libnetfilter_queue.la 50 | LIBCYCLONE := $(DEPSDIR)/lib/libcyclone.a 51 | 52 | .PHONY: default all test build_test dev dev_attrs prepare_dirs 53 | default: all 54 | 55 | run_dev: dev 56 | bash -c "sudo $(APP)" 57 | 58 | dev: dev_attrs all 59 | 60 | dev_attrs: 61 | $(eval CFLAGS := $(CFLAGS) -DDEBUG -ggdb -g3) 62 | 63 | all: prepare_dirs $(APP) 64 | 65 | build_test: prepare_dirs $(TEST_APP) 66 | test: build_test 67 | $(TEST_APP) 68 | 69 | prepare_dirs: 70 | mkdir -p $(BUILD_DIR) 71 | mkdir -p $(BUILD_DIR)/crypto 72 | mkdir -p $(BUILD_DIR)/test 73 | mkdir -p $(BUILD_DIR)/test/unity 74 | mkdir -p $(DEPSDIR) 75 | 76 | $(LIBCYCLONE): 77 | $(MAKE) -C deps/cyclone CFLAGS="$(CFLAGS)" 78 | mkdir -p $(DEPSDIR)/lib 79 | cp deps/cyclone/libcyclone.a $(DEPSDIR)/lib/libcyclone.a 80 | 81 | $(LIBNFNETLINK): 82 | cd deps/libnfnetlink && ./autogen.sh && ./configure --prefix=$(DEPSDIR) $(if $(CROSS_COMPILE_PLATFORM),--host=$(CROSS_COMPILE_PLATFORM),) --enable-static --disable-shared 83 | $(MAKE) -C deps/libnfnetlink 84 | $(MAKE) install -C deps/libnfnetlink 85 | 86 | $(LIBMNL): 87 | cd deps/libmnl && ./autogen.sh && ./configure --prefix=$(DEPSDIR) $(if $(CROSS_COMPILE_PLATFORM),--host=$(CROSS_COMPILE_PLATFORM),) --enable-static --disable-shared 88 | $(MAKE) -C deps/libmnl 89 | $(MAKE) install -C deps/libmnl 90 | 91 | $(LIBNETFILTER_QUEUE): $(LIBNFNETLINK) $(LIBMNL) 92 | cd deps/libnetfilter_queue && ./autogen.sh && ./configure --prefix=$(DEPSDIR) $(if $(CROSS_COMPILE_PLATFORM),--host=$(CROSS_COMPILE_PLATFORM),) --enable-static --disable-shared 93 | $(MAKE) -C deps/libnetfilter_queue 94 | $(MAKE) install -C deps/libnetfilter_queue 95 | 96 | $(APP): $(OBJS) $(APP_OBJ) $(REQ) $(LIBCYCLONE) 97 | @echo 'CCLD $(APP)' 98 | $(CCLD) $(OBJS) $(APP_OBJ) -o $(APP) $(LDFLAGS) -lmnl -lnetfilter_queue -lpthread -lcyclone 99 | 100 | $(TEST_APP): $(APP) $(TEST_OBJS) $(REQ) $(LIBCYCLONE) 101 | @echo 'CCLD $(TEST_APP)' 102 | $(CCLD) $(OBJS) $(TEST_OBJS) -o $(TEST_APP) $(LDFLAGS) -lmnl -lnetfilter_queue -lpthread -lcyclone 103 | 104 | $(BUILD_DIR)/%.o: src/%.c $(REQ) $(INCLUDE_DIR)/config.h 105 | @echo 'CC $@' 106 | $(CC) -c $(CFLAGS) $(LDFLAGS) $< -o $@ 107 | 108 | $(BUILD_DIR)/test/%.o: test/%.c $(REQ) $(INCLUDE_DIR)/config.h 109 | @echo 'CC $@' 110 | $(CC) -c $(CFLAGS) $(LDFLAGS) $(TEST_CFLAGS) $< -o $@ 111 | 112 | install: 113 | ifeq (,$(wildcard $(APP))) 114 | $(error Make the binary first) 115 | endif 116 | install -d $(DESTDIR)$(PREFIX)/bin/ 117 | install -m 755 $(APP) $(DESTDIR)$(PREFIX)/bin/ 118 | install -d $(DESTDIR)$(PREFIX)/lib/systemd/system/ 119 | @cp youtubeUnblock.service $(BUILD_DIR) 120 | @sed -i 's/$$(PREFIX)/$(subst /,\/,$(PREFIX))/g' $(BUILD_DIR)/youtubeUnblock.service 121 | install -m 644 $(BUILD_DIR)/youtubeUnblock.service $(DESTDIR)$(PREFIX)/lib/systemd/system/ 122 | 123 | uninstall: 124 | rm $(DESTDIR)$(PREFIX)/bin/youtubeUnblock 125 | rm $(DESTDIR)$(PREFIX)/lib/systemd/system/youtubeUnblock.service 126 | -systemctl disable youtubeUnblock.service 127 | 128 | clean: 129 | find $(BUILD_DIR) -maxdepth 1 -type f | xargs rm -rf 130 | 131 | distclean: clean 132 | rm -rf $(BUILD_DIR) 133 | ifeq ($(USE_SYS_LIBS), no) 134 | $(MAKE) distclean -C deps/libnetfilter_queue || true 135 | $(MAKE) distclean -C deps/libmnl || true 136 | $(MAKE) distclean -C deps/libnfnetlink || true 137 | endif 138 | $(MAKE) clean -C deps/cyclone || true 139 | -------------------------------------------------------------------------------- /youtubeUnblock.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=youtubeUnblock 3 | 4 | [Service] 5 | StandardError=journal 6 | StandardOutput=journal 7 | StandardInput=null 8 | ExecStartPre=iptables -t mangle -A OUTPUT -p tcp -m tcp --dport 443 -m connbytes --connbytes-dir original --connbytes-mode packets --connbytes 0:19 -j NFQUEUE --queue-num 537 --queue-bypass 9 | ExecStart=$(PREFIX)/bin/youtubeUnblock 10 | ExecStop=iptables -t mangle -D OUTPUT -p tcp -m tcp --dport 443 -m connbytes --connbytes-dir original --connbytes-mode packets --connbytes 0:19 -j NFQUEUE --queue-num 537 --queue-bypass 11 | 12 | [Install] 13 | WantedBy=multi-user.target 14 | --------------------------------------------------------------------------------