├── .gitignore ├── AUTHORS ├── Build.hs ├── CHANGELOG.md ├── Development └── SimpleBuilder.hs ├── INSTALL.md ├── LICENSE ├── Makefile ├── README.md ├── define.mk ├── docs ├── c-api.doxy ├── cpp-api.doxy ├── cpp-lang.doxy ├── lang.haddock ├── library.haddock └── make_docs.sh ├── kernel ├── COPYING ├── Makefile ├── lang │ ├── bloom.c │ ├── bloom.h │ ├── combinator.c │ ├── combinator.h │ ├── control.c │ ├── control.h │ ├── dummy.c │ ├── engine.c │ ├── engine.h │ ├── filter.c │ ├── filter.h │ ├── forward.c │ ├── forward.h │ ├── headers.h │ ├── maybe.h │ ├── misc.c │ ├── misc.h │ ├── module.h │ ├── monad.h │ ├── predicate.c │ ├── predicate.h │ ├── property.c │ ├── qbuff.h │ ├── signature.c │ ├── signature.h │ ├── steering.c │ ├── string-view.h │ ├── symtable.c │ ├── symtable.h │ ├── types.h │ └── vlan.c ├── linux │ ├── pf_q-kcompat.h │ └── pf_q.h ├── module │ ├── RTP │ │ ├── Makefile │ │ └── RTP.c │ └── dummy │ │ ├── Makefile │ │ └── dummy.c ├── pf_q.c └── pfq │ ├── alloc.h │ ├── atomic.h │ ├── bitops.h │ ├── bpf.c │ ├── bpf.h │ ├── define.h │ ├── devmap.c │ ├── devmap.h │ ├── endpoint.c │ ├── endpoint.h │ ├── global.c │ ├── global.h │ ├── group.c │ ├── group.h │ ├── io.c │ ├── io.h │ ├── kcompat.h │ ├── memory.c │ ├── memory.h │ ├── module.h │ ├── netdev.c │ ├── netdev.h │ ├── nethdr.h │ ├── param.c │ ├── percpu.c │ ├── percpu.h │ ├── pool.c │ ├── pool.h │ ├── prefetch.h │ ├── printk.c │ ├── printk.h │ ├── proc.c │ ├── proc.h │ ├── qbuff.c │ ├── qbuff.h │ ├── queue.c │ ├── queue.h │ ├── shmem.c │ ├── shmem.h │ ├── skbuff.h │ ├── sock.c │ ├── sock.h │ ├── sockopt.c │ ├── sockopt.h │ ├── sparse.h │ ├── spsc_fifo.h │ ├── stats.c │ ├── stats.h │ ├── string.h │ ├── thread.c │ ├── thread.h │ ├── timer.c │ ├── timer.h │ ├── types.h │ ├── vlan.c │ └── vlan.h ├── misc ├── Fanout │ └── Fanout.hs ├── alloc │ └── KernelAPI ├── cabal │ ├── cabal.config-LTS-2-GHC-7.8.global │ └── cabal.config-LTS-3-GHC-7.10.global ├── maybe │ ├── CMakeLists.txt │ └── test-maybe.c ├── patches │ ├── i40e-1.2.48-xmit_more-plus.patch │ └── ixgbe-3.22.3-xmit_more-plus.patch ├── signature │ ├── CMakeLists.txt │ ├── kcompat.h │ ├── linux │ │ └── ctype.h │ ├── pragma │ │ ├── diagnostic_pop │ │ └── diagnostic_push │ ├── test-signature-ext.c │ ├── test-signature.c │ └── test-string-view.c └── spsc │ ├── spsc_fifo.h │ └── spsc_test.cpp ├── pfq.cabal └── user ├── LICENSE ├── lib ├── C++ │ └── pfq │ │ ├── Makefile │ │ ├── exception.hpp │ │ ├── lang │ │ ├── default.hpp │ │ ├── experimental.hpp │ │ ├── lang.hpp │ │ └── util.hpp │ │ ├── pfq.hpp │ │ ├── queue.hpp │ │ └── util.hpp ├── C │ ├── CMakeLists.txt │ ├── cJSON.c │ ├── cJSON.h │ ├── libpfq.c │ └── pfq │ │ ├── pfq-int.h │ │ └── pfq.h ├── Haskell │ ├── Network │ │ ├── PFQ.hsc │ │ └── PFQ │ │ │ ├── Lang.hs │ │ │ ├── Lang │ │ │ ├── Default.hs │ │ │ ├── Experimental.hs │ │ │ └── Prelude.hs │ │ │ └── Types.hs │ ├── Setup.hs │ ├── pfq.cabal │ └── stack.yaml ├── README.md ├── common │ ├── CMakeLists.txt │ └── lib │ │ ├── more │ │ ├── affinity.hpp │ │ ├── binding.hpp │ │ ├── pretty.hpp │ │ └── vt100.hpp │ │ └── yats.hpp └── libpcap-1.8.1-fanout │ ├── .gitattributes │ ├── .travis-coverity-scan-build.sh │ ├── .travis.yml │ ├── CHANGES │ ├── CMakeLists.txt │ ├── CREDITS │ ├── ChmodBPF │ ├── ChmodBPF │ └── StartupParameters.plist │ ├── GenVersion.bat │ ├── INSTALL.txt │ ├── LICENSE │ ├── Makefile-devel-adds │ ├── Makefile.in │ ├── README │ ├── README.Win32 │ ├── README.aix │ ├── README.dag │ ├── README.hpux │ ├── README.linux │ ├── README.macosx │ ├── README.septel │ ├── README.sita │ ├── README.tru64 │ ├── SUNOS4 │ ├── nit_if.o.sparc │ ├── nit_if.o.sun3 │ └── nit_if.o.sun4c.4.0.3c │ ├── TODO │ ├── VERSION │ ├── Win32 │ ├── Include │ │ └── Gnuc.h │ └── Prj │ │ ├── wpcap.sln │ │ ├── wpcap.vcxproj │ │ └── wpcap.vcxproj.filters │ ├── aclocal.m4 │ ├── arcnet.h │ ├── atmuni31.h │ ├── bpf │ └── net │ │ └── bpf_filter.c │ ├── bpf_dump.c │ ├── bpf_image.c │ ├── chmod_bpf │ ├── cmake │ └── preconfigure.cmake │ ├── cmakeconfig.h.in │ ├── config.guess │ ├── config.h.in │ ├── config.sub │ ├── config │ └── have_siocglifconf.c │ ├── configure │ ├── configure.ac │ ├── dlpisubs.c │ ├── dlpisubs.h │ ├── doc │ ├── pcap.html │ ├── pcap.txt │ └── pcap.xml │ ├── etherent.c │ ├── ethertype.h │ ├── extract.h │ ├── fad-getad.c │ ├── fad-gifc.c │ ├── fad-glifc.c │ ├── fad-helpers.c │ ├── gen_version_c.sh │ ├── gen_version_header.sh │ ├── gencode.c │ ├── gencode.h │ ├── grammar.y │ ├── ieee80211.h │ ├── inet.c │ ├── install-sh │ ├── lbl │ ├── os-aix4.h │ ├── os-aix7.h │ ├── os-hpux11.h │ ├── os-osf4.h │ ├── os-osf5.h │ ├── os-solaris2.h │ ├── os-sunos4.h │ └── os-ultrix4.h │ ├── llc.h │ ├── missing │ ├── getopt.c │ ├── getopt.h │ ├── snprintf.c │ ├── strtok_r.c │ └── win_snprintf.c │ ├── mkdep │ ├── msdos │ ├── bin2c.c │ ├── common.dj │ ├── makefile │ ├── makefile.dj │ ├── makefile.wc │ ├── ndis2.c │ ├── ndis2.h │ ├── ndis_0.asm │ ├── pkt_rx0.asm │ ├── pkt_rx1.s │ ├── pktdrvr.c │ ├── pktdrvr.h │ └── readme.dos │ ├── nametoaddr.c │ ├── nametoaddr.h │ ├── nlpid.h │ ├── optimize.c │ ├── org.tcpdump.chmod_bpf.plist │ ├── pcap-bpf.c │ ├── pcap-bpf.h │ ├── pcap-bt-linux.c │ ├── pcap-bt-linux.h │ ├── pcap-bt-monitor-linux.c │ ├── pcap-bt-monitor-linux.h │ ├── pcap-common.c │ ├── pcap-common.h │ ├── pcap-config.1 │ ├── pcap-config.c │ ├── pcap-config.h │ ├── pcap-config.in │ ├── pcap-dag.c │ ├── pcap-dag.h │ ├── pcap-dbus.c │ ├── pcap-dbus.h │ ├── pcap-dlpi.c │ ├── pcap-dos.c │ ├── pcap-dos.h │ ├── pcap-enet.c │ ├── pcap-filter.manmisc.in │ ├── pcap-int.h │ ├── pcap-libdlpi.c │ ├── pcap-linktype.manmisc.in │ ├── pcap-linux.c │ ├── pcap-namedb.h │ ├── pcap-netfilter-linux.c │ ├── pcap-netfilter-linux.h │ ├── pcap-new.c │ ├── pcap-nit.c │ ├── pcap-null.c │ ├── pcap-pf.c │ ├── pcap-pfq-linux.c │ ├── pcap-pfq-linux.h │ ├── pcap-rpcap.c │ ├── pcap-rpcap.h │ ├── pcap-savefile.manfile.in │ ├── pcap-septel.c │ ├── pcap-septel.h │ ├── pcap-sita.c │ ├── pcap-sita.h │ ├── pcap-sita.html │ ├── pcap-snf.c │ ├── pcap-snf.h │ ├── pcap-snit.c │ ├── pcap-snoop.c │ ├── pcap-stdinc.h │ ├── pcap-tc.c │ ├── pcap-tc.h │ ├── pcap-tstamp.manmisc.in │ ├── pcap-usb-linux.c │ ├── pcap-usb-linux.h │ ├── pcap-win32.c │ ├── pcap.3pcap.in │ ├── pcap.c │ ├── pcap.h │ ├── pcap │ ├── bluetooth.h │ ├── bpf.h │ ├── can_socketcan.h │ ├── dlt.h │ ├── export-defs.h │ ├── ipnet.h │ ├── namedb.h │ ├── nflog.h │ ├── pcap.h │ ├── sll.h │ ├── usb.h │ └── vlan.h │ ├── pcap_compile.3pcap.in │ ├── pcap_datalink.3pcap.in │ ├── pcap_dump_open.3pcap.in │ ├── pcap_get_tstamp_precision.3pcap.in │ ├── pcap_list_datalinks.3pcap.in │ ├── pcap_list_tstamp_types.3pcap.in │ ├── pcap_open_dead.3pcap.in │ ├── pcap_open_offline.3pcap.in │ ├── pcap_set_tstamp_precision.3pcap.in │ ├── pcap_set_tstamp_type.3pcap.in │ ├── pcap_version.h.in │ ├── portability.h │ ├── ppp.h │ ├── remote-ext.h │ ├── savefile.c │ ├── scanner.l │ ├── sf-pcap-ng.c │ ├── sf-pcap-ng.h │ ├── sf-pcap.c │ ├── sf-pcap.h │ ├── sockutils.c │ ├── sockutils.h │ ├── sunatmpos.h │ └── tests │ ├── BPF │ ├── 1.txt │ ├── 2.txt │ ├── 3.txt │ ├── 4.txt │ ├── 5.txt │ ├── 6.txt │ └── 7.txt │ ├── CMakeLists.txt │ ├── can_set_rfmon_test.c │ ├── capturetest.c │ ├── filtertest.c │ ├── findalldevstest.c │ ├── opentest.c │ ├── pcap_compile_test.c │ ├── reactivatetest.c │ ├── selpolltest.c │ ├── valgrindtest.c │ └── visopts.py ├── pfq-affinity ├── LICENSE ├── Setup.hs ├── pfq-affinity.cabal ├── pfq-affinity.hs └── stack.yaml ├── pfq-hcounters ├── LICENSE ├── Setup.hs ├── pfq-hcounters.cabal ├── pfq-hcounters.hs └── stack.yaml ├── pfq-lang ├── LICENSE ├── Setup.hs ├── examples │ ├── Lib │ │ └── Filter.hs │ ├── basic.hs │ ├── conditional.hs │ ├── do-notation.hs │ ├── imports.hs │ ├── kleisli.hs │ ├── module.hs │ └── regression.hs ├── pfq-lang.cabal ├── src │ ├── CmdLine.hs │ ├── Lang │ │ ├── Compiler.hs │ │ ├── FDescr.hs │ │ ├── JSON.hs │ │ ├── Kernel.hs │ │ └── Parser.hs │ ├── Main.hs │ ├── Options.hs │ └── Paths.hs └── stack.yaml ├── pfq-load ├── LICENSE ├── Setup.hs ├── pfq-load.cabal ├── pfq-load.hs ├── pfq.example.conf ├── pfq.example.yaml └── stack.yaml ├── pfq-omatic ├── LICENSE ├── Setup.hs ├── pfq-omatic.cabal ├── pfq-omatic.hs └── stack.yaml ├── pfq-regression ├── C │ ├── CMakeLists.txt │ ├── test-bloom.cpp │ ├── test-bpf.cpp │ ├── test-dispatch.c │ ├── test-dump.cpp │ ├── test-for-range.cpp │ ├── test-lang-default.cpp │ ├── test-lang-experimental.cpp │ ├── test-lang-functional.cpp │ ├── test-lang.c │ ├── test-lang.cpp │ ├── test-read++.cpp │ ├── test-read.c │ ├── test-regression++.cpp │ ├── test-regression-capture.cpp │ ├── test-regression-pcap-rewrite.cpp │ ├── test-regression.c │ ├── test-send++.cpp │ ├── test-send.c │ └── test-vlan.cpp └── Haskell │ ├── LICENSE │ ├── Setup.hs │ ├── pfq-htest.cabal │ ├── stack.yaml │ ├── test-bloom.hs │ ├── test-dispatch.hs │ ├── test-lang.hs │ ├── test-read.hs │ └── test-send.hs ├── pfq-stress ├── LICENSE ├── Setup.hs ├── pfq-stress.cabal ├── pfq-stress.hs └── stack.yaml ├── pfq-tools ├── CMakeLists.txt ├── pfq-bridge.cpp ├── pfq-capture.cpp └── pfq-gen.cpp └── pfqd ├── LICENSE ├── Setup.hs ├── example └── pfqd-conf.hs ├── pfqd.cabal ├── pfqd.hs ├── src ├── Config.hs ├── Daemon.hs ├── Main.hs ├── Options.hs └── PFQDaemon.hs └── stack.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | pfq.mod.c 3 | *.symvers 4 | modules.order 5 | sandbox/* 6 | dist 7 | install_manifest.txt 8 | *.so 9 | *.a 10 | *.3pcap 11 | *.manfile 12 | *.manmisc 13 | cabal.sandbox.config 14 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Author 2 | ------ 3 | 4 | Nicola Bonelli 5 | 6 | Contributors 7 | ------------ 8 | 9 | Andrea Di Pietro 10 | Loris Gazzarrini 11 | Gregorio Procissi 12 | Luca Abeni 13 | Giacomo Volpi 14 | Tolysz 15 | LSB 16 | Andrey Korolyov 17 | MrClick 18 | Paul Emmerich 19 | Bach Le 20 | Marian Jancar 21 | nizq 22 | 23 | -------------------------------------------------------------------------------- /docs/lang.haddock: -------------------------------------------------------------------------------- 1 | PFQ-Lang eDLS. 2 | 3 | -------------------------------------------------------------------------------- /docs/library.haddock: -------------------------------------------------------------------------------- 1 | The PFQ interface for user-level packet capture. 2 | 3 | -------------------------------------------------------------------------------- /docs/make_docs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # (C) 2011-14 Nicola Bonelli 4 | 5 | # set -x 6 | set -e 7 | 8 | API_DIR="api" 9 | LANG_DIR="lang" 10 | API_VERSION="v6.1" 11 | LANG_VERSION="(Spec 0.1)" 12 | BOLD=`tput bold` 13 | RESET=`tput sgr0` 14 | 15 | function echoB { 16 | echo "${BOLD}${1}${RESET}" 17 | } 18 | 19 | echoB "Creating folders:" 20 | 21 | rm -rf ${API_DIR} 22 | rm -rf ${LANG_DIR} 23 | 24 | mkdir -p api/c 25 | mkdir -p api/cpp 26 | mkdir -p api/haskell 27 | mkdir -p lang/cpp 28 | mkdir -p lang/haskell 29 | 30 | echoB "C: library docs:" 31 | 32 | cd ../user && cat ../docs/c-api.doxy | doxygen - 33 | 34 | echoB "C++: library docs:" 35 | 36 | cd ../user && cat ../docs/cpp-api.doxy | doxygen - 37 | 38 | echoB "C++: Q-Lang docs:" 39 | 40 | cd ../user && cat ../docs/cpp-lang.doxy | doxygen - 41 | 42 | echoB "Haskell: library docs:" 43 | cd ../user/Haskell && runhaskell Setup configure --user && runhaskell Setup build && haddock -h -o ../../docs/api/haskell -t "PFQ Library ${API_VERSION}" \ 44 | -p ../../docs/library.haddock dist/build/Network/PFQ.hs 45 | cd - 46 | 47 | echoB "Haskell: Q-Lang docs:" 48 | cd ../user/Haskell && haddock -h -o ../../docs/lang/haskell -t "pfq-lang ${LANG_VERSION}" \ 49 | -p ../../docs/lang.haddock \ 50 | Network/PFQ/Types.hs \ 51 | Network/PFQ/Lang/Prelude.hs \ 52 | Network/PFQ/Lang/Default.hs \ 53 | Network/PFQ/Lang/Experimental.hs 54 | 55 | echoB "pfq API documentation created in ${API_DIR}." 56 | echoB "pfq-lang documentation created in ${LANG_DIR}." 57 | 58 | 59 | -------------------------------------------------------------------------------- /kernel/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # (C) 2011-16 Nicola Bonelli 3 | # 4 | 5 | TARGET = pfq 6 | 7 | EXTRA_CFLAGS += -I$(obj) 8 | EXTRA_CFLAGS += -g -O3 -march=native -Wno-attributes 9 | EXTRA_CFLAGS += -DEXPORT_SYMTAB 10 | 11 | EXTRA_CFLAGS += -DPFQ_USE_PREFETCH 12 | EXTRA_CFLAGS += -DPFQ_USE_SKB_POOL 13 | EXTRA_CFLAGS += -DPFQ_USE_EXTRA_COUNTERS 14 | 15 | #EXTRA_CFLAGS += -DPFQ_DEBUG 16 | #EXTRA_CFLAGS += -DDEBUG 17 | 18 | 19 | obj-m := $(TARGET).o 20 | 21 | pfq-y := pf_q.o pfq/proc.o pfq/shmem.o pfq/memory.o pfq/pool.o pfq/bpf.o pfq/vlan.o \ 22 | pfq/sock.o pfq/thread.o pfq/netdev.o pfq/global.o \ 23 | pfq/param.o pfq/timer.o pfq/io.o pfq/percpu.o pfq/qbuff.o \ 24 | pfq/sockopt.o pfq/queue.o pfq/global.o pfq/percpu.o pfq/devmap.o \ 25 | pfq/sock.o pfq/group.o pfq/endpoint.o pfq/stats.o pfq/printk.o \ 26 | lang/engine.o lang/signature.o lang/symtable.o \ 27 | lang/filter.o lang/steering.o lang/forward.o \ 28 | lang/predicate.o lang/combinator.o lang/control.o \ 29 | lang/property.o lang/bloom.o lang/vlan.o lang/misc.o \ 30 | lang/dummy.o 31 | 32 | KERNELVERSION := $(shell uname -r) 33 | 34 | INSTDIR := $(DESTDIR)/lib/modules/${KERNELVERSION}/kernel/net/pfq 35 | 36 | all: 37 | $(MAKE) -C /lib/modules/${KERNELVERSION}/build M=$(PWD) modules 38 | 39 | clean: 40 | $(MAKE) -C /lib/modules/${KERNELVERSION}/build M=$(PWD) clean 41 | 42 | install: 43 | mkdir -p $(INSTDIR) 44 | cp ${TARGET}.ko $(INSTDIR) 45 | cp linux/pf_q.h $(DESTDIR)/usr/include/linux 46 | cp linux/pf_q-kcompat.h $(DESTDIR)/usr/include/linux 47 | mkdir -p /usr/local/include/pfq/ 48 | cp Module.symvers $(INSTDIR) 49 | 50 | ifeq (,$(DESTDIR)) 51 | -/sbin/depmod -a ${KERNELVERSION} 52 | endif 53 | -------------------------------------------------------------------------------- /kernel/lang/combinator.c: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #include 25 | #include 26 | 27 | struct pfq_lang_function_descr combinator_functions[] = { 28 | 29 | { "or", "(Qbuff -> Bool) -> (Qbuff -> Bool) -> Qbuff -> Bool", or , NULL, NULL }, 30 | { "and", "(Qbuff -> Bool) -> (Qbuff -> Bool) -> Qbuff -> Bool", and , NULL, NULL }, 31 | { "xor", "(Qbuff -> Bool) -> (Qbuff -> Bool) -> Qbuff -> Bool", xor , NULL, NULL }, 32 | { "not", "(Qbuff -> Bool) -> Qbuff -> Bool", not , NULL, NULL }, 33 | 34 | { NULL }}; 35 | 36 | -------------------------------------------------------------------------------- /kernel/lang/combinator.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #ifndef PFQ_LANG_COMBINATOR_H 25 | #define PFQ_LANG_COMBINATOR_H 26 | 27 | #include 28 | 29 | 30 | static inline 31 | bool not(arguments_t args, struct qbuff * b) 32 | { 33 | predicate_t p1 = GET_ARG(predicate_t, args); 34 | 35 | return !EVAL_PREDICATE(p1,b); 36 | } 37 | 38 | static inline 39 | bool or(arguments_t args, struct qbuff * b) 40 | { 41 | predicate_t p1 = GET_ARG_0(predicate_t, args); 42 | predicate_t p2 = GET_ARG_1(predicate_t, args); 43 | 44 | return EVAL_PREDICATE(p1,b) || EVAL_PREDICATE(p2, b); 45 | } 46 | 47 | 48 | static inline 49 | bool and(arguments_t args, struct qbuff * b) 50 | { 51 | predicate_t p1 = GET_ARG_0(predicate_t, args); 52 | predicate_t p2 = GET_ARG_1(predicate_t, args); 53 | 54 | return EVAL_PREDICATE(p1, b) && EVAL_PREDICATE(p2, b); 55 | } 56 | 57 | 58 | static inline 59 | bool xor(arguments_t args, struct qbuff * b) 60 | { 61 | predicate_t p1 = GET_ARG_0(predicate_t, args); 62 | predicate_t p2 = GET_ARG_1(predicate_t, args); 63 | 64 | return EVAL_PREDICATE(p1, b) != EVAL_PREDICATE(p2, b); 65 | } 66 | 67 | 68 | #endif /* PFQ_LANG_COMBINATOR_H */ 69 | -------------------------------------------------------------------------------- /kernel/lang/filter.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #ifndef PFQ_LANG_FILTER_H 25 | #define PFQ_LANG_FILTER_H 26 | 27 | #include 28 | #include 29 | 30 | 31 | static inline ActionQbuff 32 | filter_ip(arguments_t args, struct qbuff * b) 33 | { 34 | return is_ip(b) ? Pass(b) : Drop(b); 35 | } 36 | 37 | static inline ActionQbuff 38 | filter_udp(arguments_t args, struct qbuff * b) 39 | { 40 | return is_udp(b) ? Pass(b) : Drop(b); 41 | } 42 | 43 | static inline ActionQbuff 44 | filter_tcp(arguments_t args, struct qbuff * b) 45 | { 46 | return is_tcp(b) ? Pass(b) : Drop(b); 47 | } 48 | 49 | static inline ActionQbuff 50 | filter_icmp(arguments_t args, struct qbuff * b) 51 | { 52 | return is_icmp(b) ? Pass(b) : Drop(b); 53 | } 54 | 55 | static inline ActionQbuff 56 | filter_flow(arguments_t args, struct qbuff * b) 57 | { 58 | return is_flow(b) ? Pass(b) : Drop(b); 59 | } 60 | 61 | static inline ActionQbuff 62 | filter_vlan(arguments_t args, struct qbuff * b) 63 | { 64 | return has_vlan(b) ? Pass(b) : Drop(b); 65 | } 66 | 67 | static inline ActionQbuff 68 | unit(arguments_t args, struct qbuff * b) 69 | { 70 | return Pass(b); 71 | } 72 | 73 | #endif /* PFQ_LANG_FILTER_H */ 74 | -------------------------------------------------------------------------------- /kernel/lang/forward.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #ifndef PFQ_LANG_FORWARD_H 25 | #define PFQ_LANG_FORWARD_H 26 | 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | static inline ActionQbuff 33 | forward_drop(arguments_t args, struct qbuff * b) 34 | { 35 | return Drop(b); 36 | } 37 | 38 | static inline ActionQbuff 39 | forward_broadcast(arguments_t args, struct qbuff * b) 40 | { 41 | return Broadcast(b); 42 | } 43 | 44 | static inline ActionQbuff 45 | forward_kernel(arguments_t args, struct qbuff * b) 46 | { 47 | return Pass(to_kernel(b)); 48 | } 49 | 50 | static inline ActionQbuff 51 | detour_kernel(arguments_t args, struct qbuff * b) 52 | { 53 | return Drop(to_kernel(b)); 54 | } 55 | 56 | 57 | static inline ActionQbuff 58 | forward_class(arguments_t args, struct qbuff * b) 59 | { 60 | const int c = GET_ARG(int, args); 61 | 62 | if (!c) { 63 | if (printk_ratelimit()) 64 | printk(KERN_INFO "[pfq-lang] forward class: internal error!\n"); 65 | return Pass(b); 66 | } 67 | 68 | return Pass(class(b, (1ULL << c))); 69 | } 70 | 71 | #endif /* PFQ_LANG_FORWARD_H */ 72 | -------------------------------------------------------------------------------- /kernel/lang/headers.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #ifndef PFQ_LANG_HEADERS_H 25 | #define PFQ_LANG_HEADERS_H 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #endif /* PFQ_LANG_HEADERS_H */ 35 | -------------------------------------------------------------------------------- /kernel/lang/misc.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #ifndef PFQ_LANG_MISC_H 25 | #define PFQ_LANG_MISC_H 26 | 27 | #include 28 | 29 | static inline ActionQbuff 30 | mark(arguments_t args, struct qbuff * b) 31 | { 32 | const uint32_t value = GET_ARG(uint32_t, args); 33 | set_mark(b, value); 34 | return Pass(b); 35 | } 36 | 37 | static inline ActionQbuff 38 | put_state(arguments_t args, struct qbuff * b) 39 | { 40 | const uint32_t value = GET_ARG(uint32_t, args); 41 | set_state(b, value); 42 | return Pass(b); 43 | } 44 | 45 | 46 | #endif /* PFQ_LANG_MISC_H */ 47 | -------------------------------------------------------------------------------- /kernel/lang/signature.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #ifndef PFQ_LANG_SIGNATURE_H 25 | #define PFQ_LANG_SIGNATURE_H 26 | 27 | #include 28 | 29 | string_view_t pfq_lang_signature_simplify(string_view_t sig); 30 | string_view_t pfq_lang_signature_bind(string_view_t sig, unsigned int n); 31 | string_view_t pfq_lang_signature_arg(string_view_t sig, unsigned int n); 32 | string_view_t pfq_lang_signature_remove_extent(string_view_t str); 33 | 34 | int pfq_lang_signature_redundant_brackets(string_view_t sig); 35 | int pfq_lang_signature_arity(string_view_t sig); 36 | bool pfq_lang_signature_equal(string_view_t a, string_view_t b); 37 | bool pfq_lang_signature_is_function(string_view_t sig); 38 | 39 | ptrdiff_t pfq_lang_signature_sizeof(string_view_t str); 40 | 41 | bool pfq_lang_signature_check(string_view_t sig); 42 | bool pfq_lang_signature_type_check(string_view_t t); 43 | 44 | 45 | #endif /* PFQ_LANG_SIGNATURE_H */ 46 | -------------------------------------------------------------------------------- /kernel/lang/types.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #ifndef PFQ_LANG_TYPES_H 25 | #define PFQ_LANG_TYPES_H 26 | 27 | 28 | #include 29 | 30 | 31 | /* CIDR notation */ 32 | 33 | struct CIDR 34 | { 35 | __be32 addr; 36 | int prefix; 37 | }; 38 | 39 | struct CIDR_ 40 | { 41 | __be32 addr; 42 | __be32 mask; 43 | }; 44 | 45 | 46 | /* note: use can use inet_mask_len(data->mask) to get the prefix */ 47 | 48 | static inline 49 | void to_CIDR_(struct CIDR *data) 50 | { 51 | struct CIDR_ * data_ = (struct CIDR_ *)data; 52 | __be32 mask = inet_make_mask(data->prefix); 53 | data_->addr &= mask; 54 | data_->mask = mask; 55 | } 56 | 57 | #define CIDR_INIT(a,i) to_CIDR_((struct CIDR *)&ARGS_TYPE(a)->arg[i].value) 58 | 59 | #endif /* PFQ_LANG_TYPES_H */ 60 | -------------------------------------------------------------------------------- /kernel/module/RTP/Makefile: -------------------------------------------------------------------------------- 1 | # (C) 2011-16 Nicola Bonelli 2 | # 3 | 4 | 5 | TARGET = RTP 6 | 7 | EXTRA_CFLAGS += -I/usr/include/ -I$(src)/../../ 8 | EXTRA_CFLAGS += -Ofast -march=native -Wno-attributes 9 | 10 | KERNELVERSION := $(shell uname -r) 11 | KBUILD_EXTRA_SYMBOLS := /lib/modules/${KERNELVERSION}/kernel/net/pfq/Module.symvers 12 | 13 | obj-m := $(TARGET).o 14 | 15 | 16 | all: 17 | make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules 18 | 19 | clean: 20 | make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean 21 | 22 | -------------------------------------------------------------------------------- /kernel/module/dummy/Makefile: -------------------------------------------------------------------------------- 1 | # (C) 2011-16 Nicola Bonelli 2 | # 3 | 4 | 5 | TARGET = dummy 6 | 7 | EXTRA_CFLAGS += -I$(src)/../../ -Wno-attributes 8 | 9 | obj-m := $(TARGET).o 10 | 11 | all: 12 | make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules 13 | 14 | clean: 15 | make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean 16 | 17 | -------------------------------------------------------------------------------- /kernel/module/dummy/dummy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | static int __init pfq_init_module(void) 6 | { 7 | return 0; 8 | } 9 | 10 | static void __exit pfq_exit_module(void) 11 | { 12 | } 13 | 14 | 15 | module_init(pfq_init_module); 16 | module_exit(pfq_exit_module); 17 | 18 | -------------------------------------------------------------------------------- /kernel/pfq/alloc.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * Loris Gazzarrini 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 2 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, write to the Free Software Foundation, 18 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * The full GNU General Public License is included in this distribution in 21 | * the file called "COPYING". 22 | * 23 | ****************************************************************/ 24 | 25 | #ifndef PFQ_ALLOC_H 26 | #define PFQ_ALLOC_H 27 | 28 | #include 29 | 30 | inline static 31 | void *pfq_malloc_pages(size_t size, gfp_t gfp_flags) 32 | { 33 | int po; 34 | if (WARN_ON(!size)) 35 | return NULL; 36 | gfp_flags |= __GFP_COMP; 37 | po = get_order(size); 38 | return (void *) __get_free_pages(gfp_flags, po); 39 | } 40 | 41 | 42 | inline static 43 | void pfq_free_pages(void *addr, size_t size) 44 | { 45 | int po; 46 | if (addr == NULL) 47 | return; 48 | po = get_order(size); 49 | free_pages((unsigned long) addr, po); 50 | } 51 | 52 | #endif /* PFQ_ALLOC_H */ 53 | 54 | -------------------------------------------------------------------------------- /kernel/pfq/atomic.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #ifndef PFQ_ATOMIC_H 25 | #define PFQ_ATOMIC_H 26 | 27 | #include 28 | #include 29 | 30 | #endif /* PFQ_ATOMIC_H */ 31 | -------------------------------------------------------------------------------- /kernel/pfq/bpf.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * Loris Gazzarrini 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 2 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, write to the Free Software Foundation, 18 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * The full GNU General Public License is included in this distribution in 21 | * the file called "COPYING". 22 | * 23 | ****************************************************************/ 24 | 25 | #ifndef PFQ_BPF_H 26 | #define PFQ_BPF_H 27 | 28 | #include 29 | 30 | extern struct sk_filter * pfq_alloc_sk_filter(struct sock_fprog *fprog); 31 | extern void pfq_free_sk_filter(struct sk_filter *filter); 32 | 33 | #endif /* PFQ_BPF_H */ 34 | -------------------------------------------------------------------------------- /kernel/pfq/define.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #ifndef PFQ_DEFINE_H 25 | #define PFQ_DEFINE_H 26 | 27 | #include 28 | 29 | #define Q_MAX_ID ((int)sizeof(long)<<3) 30 | #define Q_MAX_GID ((int)sizeof(long)<<3) 31 | #define Q_BUFF_BATCH_LEN ((int)sizeof(__int128)<<3) 32 | 33 | #define Q_BUFF_LOG_LEN 16 34 | #define Q_BUFF_QUEUE_LEN 512 35 | 36 | #define Q_MAX_STEERING_MASK 512 37 | 38 | #define Q_MAX_DEVICE 4096 39 | #define Q_MAX_DEVICE_MASK (Q_MAX_DEVICE-1) 40 | #define Q_MAX_QUEUE 256 41 | #define Q_MAX_QUEUE_MASK (Q_MAX_QUEUE-1) 42 | 43 | #define Q_MAX_TX_SKB_COPY 256 44 | 45 | #define Q_GRACE_PERIOD 200 /* msec */ 46 | 47 | #define Q_FUN_SYMB_LEN 256 48 | #define Q_FUN_SIGN_LEN 1024 49 | #define Q_FUN_MAX_ENTRIES 1024 50 | 51 | #define Q_MAX_CPU 256 52 | #define Q_MAX_CPU_MASK (Q_MAX_CPU-1) 53 | 54 | #define Q_GROUP_PERSIST_MEM 64 55 | #define Q_GROUP_PERSIST_DATA 1024 56 | 57 | #define Q_MAX_SOCKQUEUE_LEN 262144 58 | 59 | #define Q_INVALID_ID (__force pfq_id_t)-1 60 | 61 | 62 | #endif /* PFQ_DEFINE_H */ 63 | -------------------------------------------------------------------------------- /kernel/pfq/endpoint.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #ifndef PFQ_ENDPOINT_H 25 | #define PFQ_ENDPOINT_H 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | 33 | struct pfq_qbuff_queue; 34 | struct pfq_sock; 35 | struct net_device; 36 | struct qbuff; 37 | 38 | 39 | enum pfq_endpoint_type 40 | { 41 | Q_ENDPOINT_SOCKET, 42 | Q_ENDPOINT_DEVICE 43 | }; 44 | 45 | 46 | struct pfq_endpoint_info 47 | { 48 | struct net_device * dev[Q_BUFF_LOG_LEN]; 49 | size_t cnt [Q_BUFF_LOG_LEN]; 50 | size_t cnt_total; 51 | size_t num; 52 | }; 53 | 54 | 55 | extern void pfq_add_dev_to_endpoints(struct net_device *dev, struct pfq_endpoint_info *ts); 56 | 57 | extern size_t pfq_copy_to_endpoint_qbuffs( struct pfq_sock *so 58 | , struct pfq_qbuff_queue *buffs 59 | , unsigned __int128 mask 60 | , int cpu); 61 | 62 | extern void pfq_get_lazy_endpoints(struct pfq_qbuff_queue *qb, struct pfq_endpoint_info *ts); 63 | 64 | #endif /* PFQ_ENDPOINT_H */ 65 | -------------------------------------------------------------------------------- /kernel/pfq/kcompat.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #ifndef PFQ_KCOMPACT_H 25 | #define PFQ_KCOMPACT_H 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #if (LINUX_VERSION_CODE <= KERNEL_VERSION(3,14,0)) 33 | static inline bool netif_xmit_frozen_or_drv_stopped(const struct netdev_queue *queue) 34 | { 35 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0)) 36 | return netif_tx_queue_frozen_or_stopped(queue); 37 | #else 38 | return netif_xmit_frozen_or_stopped(queue); 39 | #endif 40 | } 41 | #endif 42 | 43 | #if (LINUX_VERSION_CODE <= KERNEL_VERSION(3,10,0)) 44 | static inline struct net_device * 45 | netdev_notifier_info_to_dev(void *data) 46 | { 47 | return data; 48 | } 49 | #endif 50 | 51 | 52 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0)) 53 | # define PFQ_BUILD_BUG_ON_MSG(...) BUILD_BUG_ON_MSG(__VA_ARGS__) 54 | #else 55 | # define PFQ_BUILD_BUG_ON_MSG(...) 56 | #endif 57 | 58 | 59 | #endif /* PFQ_KCOMPACT_H */ 60 | -------------------------------------------------------------------------------- /kernel/pfq/module.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #ifndef PFQ_MODULE_H 25 | #define PFQ_MODULE_H 26 | 27 | #include 28 | #include 29 | 30 | #endif /* PFQ_MODULE_H */ 31 | -------------------------------------------------------------------------------- /kernel/pfq/netdev.c: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #include 25 | 26 | 27 | int 28 | pfq_dev_refcnt_read_by_index(struct net *net, int ifindex) 29 | { 30 | struct net_device *dev; 31 | int ref = -1; 32 | rcu_read_lock(); 33 | dev = dev_get_by_index_rcu(net, ifindex); 34 | if (dev) { 35 | ref = netdev_refcnt_read(dev); 36 | } 37 | rcu_read_unlock(); 38 | return ref; 39 | } 40 | 41 | 42 | 43 | int pfq_dev_queue_get(struct net *net, int ifindex, int queue, struct pfq_dev_queue *dq) 44 | { 45 | struct net_device *dev = dev_get_by_index(net, ifindex); 46 | if (dev == NULL) { 47 | *dq = (struct pfq_dev_queue){.dev = NULL, .queue = NULL, .mapping = 0}; 48 | return -EFAULT; 49 | } 50 | 51 | dq->dev = dev; 52 | dq->mapping = __pfq_dev_cap_txqueue(dev, queue); 53 | dq->queue = netdev_get_tx_queue(dev, dq->mapping); 54 | return 0; 55 | } 56 | 57 | 58 | void pfq_dev_queue_put(struct pfq_dev_queue *dq) 59 | { 60 | if(likely(dq->dev)) { 61 | dev_put(dq->dev); 62 | dq->dev = NULL; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /kernel/pfq/nethdr.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #ifndef PFQ_NET_HEADERS_H 25 | #define PFQ_NET_HEADERS_H 26 | 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #endif /* PFQ_NET_HEADERS_H */ 39 | 40 | -------------------------------------------------------------------------------- /kernel/pfq/percpu.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #ifndef PFQ_PERCPU_H 25 | #define PFQ_PERCPU_H 26 | 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include 38 | 39 | extern int pfq_percpu_init(void); 40 | extern int pfq_percpu_qbuff_queue_reset(void); 41 | extern int pfq_percpu_destruct(void); 42 | 43 | 44 | struct pfq_percpu_pool 45 | { 46 | struct spinlock tx_lock; 47 | 48 | struct pfq_skb_pool tx; 49 | struct pfq_skb_pool rx; 50 | 51 | } ____pfq_cacheline_aligned; 52 | 53 | 54 | int pfq_percpu_alloc(void); 55 | void pfq_percpu_free(void); 56 | 57 | 58 | struct pfq_percpu_data 59 | { 60 | struct pfq_qbuff_long_queue *qbuff_queue; 61 | 62 | ktime_t last_rx; 63 | struct timer_list timer; 64 | uint32_t counter; 65 | 66 | } ____pfq_cacheline_aligned; 67 | 68 | 69 | 70 | #endif /* PFQ_PERCPU_H */ 71 | 72 | -------------------------------------------------------------------------------- /kernel/pfq/pool.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #ifndef PFQ_POOL_H 25 | #define PFQ_POOL_H 26 | 27 | #include 28 | #include 29 | 30 | 31 | #define PFQ_POOL_CACHELINE_PAD (64/sizeof(void *)) 32 | 33 | 34 | struct pfq_skb_pool 35 | { 36 | struct pfq_spsc_fifo *fifo; 37 | void *base; 38 | size_t base_size; 39 | void *data; 40 | size_t data_size; 41 | }; 42 | 43 | 44 | extern int pfq_skb_pool_init_all(void); 45 | extern int pfq_skb_pool_free_all(void); 46 | extern struct pfq_pool_stats pfq_get_skb_pool_stats(void); 47 | 48 | 49 | static inline 50 | struct pfq_spsc_fifo *pfq_skb_pool_get(struct pfq_skb_pool *pool, size_t size) 51 | { 52 | if (likely(size <= global->max_slot_size)) 53 | return pool->fifo; 54 | return NULL; 55 | } 56 | 57 | 58 | #endif /* PFQ_POOL_H */ 59 | -------------------------------------------------------------------------------- /kernel/pfq/prefetch.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #ifndef PFQ_PREFETCH_H 25 | #define PFQ_PREFETCH_H 26 | 27 | #include 28 | 29 | #ifdef PFQ_USE_PREFETCH 30 | 31 | #define prefetch_w3(a) __builtin_prefetch(a, 1, 3) 32 | #define prefetch_w2(a) __builtin_prefetch(a, 1, 2) 33 | #define prefetch_w1(a) __builtin_prefetch(a, 1, 1) 34 | #define prefetch_w0(a) __builtin_prefetch(a, 1, 0) 35 | 36 | #define prefetch_r3(a) __builtin_prefetch(a, 0, 3) 37 | #define prefetch_r2(a) __builtin_prefetch(a, 0, 2) 38 | #define prefetch_r1(a) __builtin_prefetch(a, 0, 1) 39 | #define prefetch_r0(a) __builtin_prefetch(a, 0, 0) 40 | 41 | static inline void prefetchw_nt_range(void *addr, size_t len) 42 | { 43 | #ifdef ARCH_HAS_PREFETCH 44 | char *cp; 45 | char *end = addr + len; 46 | for (cp = addr; cp < end; cp += PREFETCH_STRIDE) 47 | prefetchw_nt(cp); 48 | #endif 49 | } 50 | 51 | #else 52 | 53 | #define prefetch_w3(a) 54 | #define prefetch_w2(a) 55 | #define prefetch_w1(a) 56 | #define prefetch_w0(a) 57 | 58 | #define prefetch_r3(a) 59 | #define prefetch_r2(a) 60 | #define prefetch_r1(a) 61 | #define prefetch_r0(a) 62 | 63 | static inline void prefetchw_nt_range(void *addr, size_t len) 64 | { 65 | } 66 | 67 | #endif 68 | 69 | #endif /* PFQ_SOCK_H */ 70 | -------------------------------------------------------------------------------- /kernel/pfq/printk.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #ifndef PFQ_PRINTK_H 25 | #define PFQ_PRINTK_H 26 | 27 | #include 28 | 29 | #include 30 | 31 | struct pfq_lang_computation_descr; 32 | struct pfq_lang_computation_tree; 33 | struct pfq_lang_functional_node; 34 | 35 | extern void pr_devel_group(pfq_gid_t gid); 36 | extern void pr_devel_buffer(const unsigned char *buff, size_t len); 37 | extern void pr_devel_computation_descr(struct pfq_lang_computation_descr const *); 38 | extern void pr_devel_computation_tree(struct pfq_lang_computation_tree const *); 39 | extern size_t snprintf_functional_node(char *buffer, size_t size, struct pfq_lang_functional_node const *node, size_t index); 40 | 41 | 42 | #endif /* PFQ_PRINTK_H */ 43 | -------------------------------------------------------------------------------- /kernel/pfq/proc.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #ifndef PFQ_PROC_H 25 | #define PFQ_PROC_H 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | extern struct proc_dir_entry *pfq_proc_dir; 33 | 34 | extern int pfq_proc_init(void); 35 | extern int pfq_proc_destruct(void); 36 | 37 | #endif /* PFQ_PROC_H */ 38 | -------------------------------------------------------------------------------- /kernel/pfq/qbuff.c: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #include 25 | #include 26 | 27 | bool 28 | qbuff_ingress(struct qbuff const *buff, struct iphdr const *ip) 29 | { 30 | struct in_device *in_dev; 31 | bool ret = false; 32 | bool ctx = buff->monad->ep_ctx; 33 | 34 | rcu_read_lock(); 35 | in_dev = __in_dev_get_rcu(QBUFF_SKB(buff)->dev); 36 | if (in_dev != NULL) { 37 | for_primary_ifa(in_dev) { 38 | if (((ifa->ifa_address == ip->daddr) && (ctx & EPOINT_DST)) || 39 | ((ifa->ifa_address == ip->saddr) && (ctx & EPOINT_SRC))){ 40 | ret = true; 41 | break; 42 | } 43 | } endfor_ifa(in_dev); 44 | } 45 | rcu_read_unlock(); 46 | 47 | return ret; 48 | } 49 | 50 | 51 | -------------------------------------------------------------------------------- /kernel/pfq/sockopt.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #ifndef PFQ_SOCKOPT_H 25 | #define PFQ_SOCKOPT_H 26 | 27 | #include 28 | #include 29 | 30 | extern int pfq_getsockopt(struct socket *sock, 31 | int level, int optname, 32 | char __user * optval, int __user * optlen); 33 | 34 | extern int pfq_setsockopt(struct socket *sock, 35 | int level, int optname, 36 | char __user * optval, 37 | unsigned int optlen); 38 | 39 | #endif /* PFQ_SOCKOPT_H */ 40 | -------------------------------------------------------------------------------- /kernel/pfq/string.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #ifndef PFQ_STRING_H 25 | #define PFQ_STRING_H 26 | 27 | #include 28 | #include 29 | 30 | #endif /* PFQ_NET_STRING_H */ 31 | 32 | -------------------------------------------------------------------------------- /kernel/pfq/timer.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #ifndef PFQ_TIMER_H 25 | #define PFQ_TIMER_H 26 | 27 | #include 28 | #include 29 | 30 | extern void pfq_timer_init(void); 31 | extern void pfq_timer_fini(void); 32 | 33 | #endif /* PFQ_TIMER_H */ 34 | 35 | -------------------------------------------------------------------------------- /kernel/pfq/types.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #ifndef PFQ_TYPES_H 25 | #define PFQ_TYPES_H 26 | 27 | #include 28 | #include 29 | 30 | typedef int __bitwise pfq_id_t; 31 | typedef int __bitwise pfq_gid_t; 32 | 33 | 34 | #endif /* PFQ_TYPES_H */ 35 | -------------------------------------------------------------------------------- /kernel/pfq/vlan.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #ifndef PFQ_VLAN_H 25 | #define PFQ_VLAN_H 26 | 27 | #include 28 | #include 29 | 30 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0)) 31 | 32 | extern struct sk_buff *pfq_vlan_untag(struct sk_buff *skb); 33 | 34 | #elif (LINUX_VERSION_CODE < KERNEL_VERSION(3,16,6)) 35 | 36 | static inline 37 | struct sk_buff *pfq_vlan_untag(struct sk_buff *skb) 38 | { 39 | return vlan_untag(skb); 40 | } 41 | 42 | #else 43 | 44 | static inline 45 | struct sk_buff *pfq_vlan_untag(struct sk_buff *skb) 46 | { 47 | return skb_vlan_untag(skb); 48 | } 49 | 50 | #endif 51 | 52 | #endif /* PFQ_VLAN_H */ 53 | -------------------------------------------------------------------------------- /misc/alloc/KernelAPI: -------------------------------------------------------------------------------- 1 | List of kernel API used to allocate socket buffers: 2 | 3 | sk_buff.h sk_buff.c 4 | 5 | 1. __alloc_skb * 6 | 2. alloc_skb -> __alloc_skb * 7 | 3. alloc_skb_fclone -> __alloc_skb * 8 | 4. alloc_skb_with_frags * 9 | 5. __alloc_skb_head * 10 | 6. alloc_skb_head -> __alloc_skb_head * 11 | 7. __netdev_alloc_skb * 12 | 8. netdev_alloc_skb -> __netdev_alloc_skb * 13 | 9. __dev_alloc_skb -> __netdev_alloc_skb * 14 | 10. dev_alloc_skb -> netdev_alloc_skb * 15 | 11. __netdev_alloc_skb_ip_align -> __netdev_alloc_skb * 16 | 12. netdev_alloc_skb_ip_align -> __netdev_alloc_skb_ip_align * 17 | 13. __napi_alloc_skb * 18 | 14. napi_alloc_skb -> __napi_alloc_skb * 19 | -------------------------------------------------------------------------------- /misc/maybe/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") 4 | 5 | include_directories(../../kernel/) 6 | 7 | add_executable(test-maybe test-maybe.c) 8 | 9 | -------------------------------------------------------------------------------- /misc/patches/i40e-1.2.48-xmit_more-plus.patch: -------------------------------------------------------------------------------- 1 | diff --git a/src/i40e/i40e_txrx.c b/src/i40e/i40e_txrx.c 2 | index 7f1c718..cf830cf 100644 3 | --- a/src/i40e/i40e_txrx.c 4 | +++ b/src/i40e/i40e_txrx.c 5 | @@ -2745,6 +2745,16 @@ static void i40e_tx_map(struct i40e_ring *tx_ring, struct sk_buff *skb, 6 | tx_ring->next_to_use = i; 7 | 8 | /* notify HW of packet */ 9 | + if ( 10 | + 11 | +#if(LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0)) 12 | + !skb->xmit_more 13 | +#else 14 | + !skb->mark 15 | +#endif 16 | + || 17 | + netif_xmit_stopped(netdev_get_tx_queue(tx_ring->netdev, 18 | + tx_ring->queue_index))) 19 | writel(i, tx_ring->tail); 20 | 21 | return; 22 | -------------------------------------------------------------------------------- /misc/patches/ixgbe-3.22.3-xmit_more-plus.patch: -------------------------------------------------------------------------------- 1 | diff --git a/src/ixgbe_main.c b/src/ixgbe_main.c 2 | index 8bca2b9..92a3798 100644 3 | --- a/src/ixgbe_main.c 4 | +++ b/src/ixgbe_main.c 5 | @@ -8000,6 +8000,13 @@ static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc, 6 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); 7 | } 8 | 9 | + 10 | +static inline struct netdev_queue *txring_txq(const struct ixgbe_ring *ring) 11 | +{ 12 | + return netdev_get_tx_queue(ring->netdev, ring->queue_index); 13 | +} 14 | + 15 | + 16 | #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \ 17 | IXGBE_TXD_CMD_RS) 18 | 19 | @@ -8123,8 +8130,16 @@ static void ixgbe_tx_map(struct ixgbe_ring *tx_ring, 20 | 21 | tx_ring->next_to_use = i; 22 | 23 | - /* notify HW of packet */ 24 | - ixgbe_write_tail(tx_ring, i); 25 | + if (netif_xmit_stopped(txring_txq(tx_ring)) || 26 | +#if(LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0)) 27 | + !skb->xmit_more 28 | +#else 29 | + !skb->mark 30 | +#endif 31 | + ) { 32 | + /* notify HW of packet */ 33 | + ixgbe_write_tail(tx_ring, i); 34 | + } 35 | 36 | /* 37 | * we need this if more than one processor can write to our tail 38 | -------------------------------------------------------------------------------- /misc/signature/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | include_directories(. ../../kernel/) 4 | 5 | add_executable(test-string-view test-string-view.c) 6 | add_executable(test-signature test-signature.c ../../kernel/lang/signature.c) 7 | add_executable(test-signature-ext test-signature-ext.c ../../kernel/lang/signature.c) 8 | 9 | -------------------------------------------------------------------------------- /misc/signature/kcompat.h: -------------------------------------------------------------------------------- 1 | #ifndef __KCOMPAT__ 2 | #define __KCOMPAT__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define min(X,Y) ((X) < (Y) ? (X) : (Y)) 11 | #define max(X,Y) ((X) > (Y) ? (X) : (Y)) 12 | 13 | typedef int bool; 14 | 15 | static const bool false = 0; 16 | static const bool true = 1; 17 | 18 | #endif /* __KCOMPAT__ */ 19 | -------------------------------------------------------------------------------- /misc/signature/linux/ctype.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | -------------------------------------------------------------------------------- /misc/signature/pragma/diagnostic_pop: -------------------------------------------------------------------------------- 1 | ../../../kernel/pragma/diagnostic_pop -------------------------------------------------------------------------------- /misc/signature/pragma/diagnostic_push: -------------------------------------------------------------------------------- 1 | ../../../kernel/pragma/diagnostic_push -------------------------------------------------------------------------------- /misc/spsc/spsc_fifo.h: -------------------------------------------------------------------------------- 1 | ../../kernel/pfq/spsc_fifo.h -------------------------------------------------------------------------------- /misc/spsc/spsc_test.cpp: -------------------------------------------------------------------------------- 1 | #include "spsc_fifo_new.h" 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | 9 | core_spsc_fifo *fifo; 10 | 11 | unsigned long top = 1000000000UL; 12 | 13 | 14 | inline 15 | void set_affinity(std::thread &t, size_t n) 16 | { 17 | if(t.get_id() == std::thread::id()) 18 | throw std::runtime_error("thread not running"); 19 | 20 | cpu_set_t cpuset; 21 | 22 | CPU_ZERO(&cpuset); 23 | CPU_SET(n, &cpuset); 24 | 25 | auto pth = t.native_handle(); 26 | if ( ::pthread_setaffinity_np(pth, sizeof(cpuset), &cpuset) != 0) 27 | throw std::runtime_error("pthread_setaffinity_np"); 28 | } 29 | 30 | 31 | void producer() 32 | { 33 | for(auto n = 1ULL; n <= top;) { 34 | if (core_spsc_push(fifo, (void *)n)) { 35 | n++; 36 | } 37 | } 38 | 39 | core_spsc_push_sync(fifo); 40 | } 41 | 42 | 43 | void consumer() 44 | { 45 | unsigned long sum = 0; 46 | 47 | for(auto n = 1ULL; n <= top;) 48 | { 49 | auto p = core_spsc_pop(fifo); 50 | if (p != NULL) { 51 | sum += (unsigned long)p; 52 | n++; 53 | } 54 | } 55 | 56 | std::cout << "total pop: " << sum << std::endl; 57 | } 58 | 59 | 60 | int 61 | main(int argc, char *argv[]) 62 | { 63 | fifo = core_spsc_init(8192, 0); 64 | 65 | std::cout << "total sum: " << ((top*(top+1))/2) << std::endl; 66 | 67 | auto t = std::thread(producer); 68 | set_affinity(t, 0); 69 | t.detach(); 70 | 71 | std::thread(consumer).join(); 72 | 73 | return 0; 74 | } 75 | 76 | -------------------------------------------------------------------------------- /pfq.cabal: -------------------------------------------------------------------------------- 1 | name: pfq-framework 2 | version: 6.1 3 | synopsis: PFQ framework 4 | description: PFQ framework 5 | maintainer: Nicola Bonelli 6 | author: Nicola Bonelli 7 | homepage: https://www.pfq.io/ 8 | bug-reports: https://github.com/pfq/PFQ/issues 9 | category: Network 10 | cabal-version: >= 1.10 11 | build-type: Simple 12 | 13 | Library 14 | default-language: Haskell2010 15 | default-extensions: ForeignFunctionInterface, CPP 16 | build-depends: base >= 4.7, 17 | ansi-terminal, 18 | bytestring, 19 | clock, 20 | cmdargs, 21 | containers, 22 | daemons, 23 | directory, 24 | filepath, 25 | here, 26 | hslogger, 27 | mtl, 28 | network, 29 | old-time, 30 | process, 31 | regex-posix, 32 | semigroups, 33 | split, 34 | aeson, 35 | scientific, 36 | storable-record, 37 | storable-tuple, 38 | storablevector, 39 | unix, 40 | yaml, 41 | hint, 42 | atomic-primops 43 | 44 | -------------------------------------------------------------------------------- /user/LICENSE: -------------------------------------------------------------------------------- 1 | ../LICENSE -------------------------------------------------------------------------------- /user/lib/C++/pfq/Makefile: -------------------------------------------------------------------------------- 1 | INSTDIR:=/usr/local/include/pfq 2 | all: 3 | clean: 4 | install: 5 | mkdir -p ${INSTDIR} 6 | mkdir -p ${INSTDIR}/lang 7 | cp pfq.hpp ${INSTDIR} 8 | cp exception.hpp ${INSTDIR} 9 | cp queue.hpp ${INSTDIR} 10 | cp util.hpp ${INSTDIR} 11 | cp lang/lang.hpp ${INSTDIR}/lang 12 | cp lang/default.hpp ${INSTDIR}/lang 13 | cp lang/util.hpp ${INSTDIR}/lang 14 | -------------------------------------------------------------------------------- /user/lib/C++/pfq/exception.hpp: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #pragma once 25 | 26 | #include 27 | 28 | namespace pfq { 29 | 30 | /** system_error represent problems related to the PFQ system. 31 | * @brief Subclass of std::system_error. 32 | */ 33 | 34 | class system_error final : public std::system_error 35 | { 36 | public: 37 | 38 | system_error(std::string const &reason) 39 | : std::system_error(0, std::generic_category(), reason.c_str()) 40 | {} 41 | 42 | system_error(int ev, std::string const &reason) 43 | : std::system_error(ev, std::generic_category(), reason.c_str()) 44 | {} 45 | 46 | system_error(int ev, const char * reason) 47 | : std::system_error(ev, std::generic_category(), reason) 48 | {} 49 | 50 | system_error(const char *reason) 51 | : std::system_error(0, std::generic_category(), reason) 52 | {} 53 | 54 | system_error(const system_error &) = default; 55 | 56 | virtual ~system_error() noexcept 57 | {} 58 | }; 59 | 60 | } // namespace pfq 61 | 62 | -------------------------------------------------------------------------------- /user/lib/C/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.4) 2 | 3 | set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O3 -march=native -fomit-frame-pointer -Wall -Wextra -Wshadow -Wconversion") 4 | 5 | include_directories(../../kernel .) 6 | 7 | add_definitions(-D_GNU_SOURCE) 8 | 9 | add_library(pfq_static STATIC libpfq.c cJSON.c) 10 | add_library(pfq SHARED libpfq.c cJSON.c) 11 | 12 | install_targets(/lib pfq) 13 | install_targets(/lib pfq_static) 14 | 15 | install_files(/include/pfq FILES pfq/pfq.h pfq/pfq-int.h) 16 | -------------------------------------------------------------------------------- /user/lib/C/pfq/pfq-int.h: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 Nicola Bonelli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | ****************************************************************/ 23 | 24 | #ifndef PFQ_INT_H 25 | #define PFQ_INT_H 26 | 27 | #include 28 | 29 | /*! PFQ descriptor. */ 30 | 31 | typedef struct pfq_data_int pfq_t; 32 | 33 | /*! PFQ iterator type. */ 34 | 35 | typedef char * pfq_iterator_t; 36 | 37 | 38 | /*! pfq_net_queue_t is a struct which represents a net queue. */ 39 | 40 | struct pfq_net_queue 41 | { 42 | pfq_iterator_t queue; /* net queue */ 43 | size_t len; /* number of packets in the queue */ 44 | size_t slot_size; 45 | uint32_t index; /* current queue index */ 46 | }; 47 | 48 | 49 | /*! PFQ data */ 50 | 51 | struct pfq_data_int 52 | { 53 | void * shm_addr; 54 | size_t shm_size; 55 | 56 | void * shm_hugepages; 57 | size_t shm_hugepages_size; 58 | 59 | void * tx_queue_addr; 60 | size_t tx_queue_size; 61 | 62 | void * rx_queue_addr; 63 | size_t rx_queue_size; 64 | 65 | size_t rx_slots; 66 | size_t rx_slot_size; 67 | 68 | size_t tx_slots; 69 | size_t tx_slot_size; 70 | 71 | size_t tx_len; 72 | size_t rx_len; 73 | 74 | size_t tx_attempt; 75 | size_t tx_num_async; 76 | 77 | const char * error; 78 | 79 | int fd; 80 | int hd; 81 | 82 | int id; 83 | int gid; 84 | 85 | struct pfq_net_queue nq; 86 | }; 87 | 88 | #endif /* PFQ_INT_H */ 89 | -------------------------------------------------------------------------------- /user/lib/Haskell/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /user/lib/Haskell/pfq.cabal: -------------------------------------------------------------------------------- 1 | name: pfq 2 | version: 6.1 3 | synopsis: PFQ interface for user-level packet capture 4 | description: PFQ interface for user-level packet capture 5 | maintainer: Nicola Bonelli 6 | author: Nicola Bonelli 7 | homepage: https://www.pfq.io/ 8 | bug-reports: https://github.com/pfq/PFQ/issues 9 | category: Network 10 | cabal-version: >= 1.10 11 | build-type: Simple 12 | 13 | Library 14 | default-language: Haskell2010 15 | default-extensions: ForeignFunctionInterface, CPP 16 | build-depends: base >= 4.7, bytestring, 17 | storable-tuple, 18 | storablevector, 19 | storable-record, 20 | process, 21 | network, 22 | aeson, 23 | scientific, 24 | clock, 25 | mtl 26 | 27 | exposed-modules: Network.PFQ 28 | Network.PFQ.Types 29 | Network.PFQ.Lang 30 | Network.PFQ.Lang.Prelude 31 | Network.PFQ.Lang.Default 32 | Network.PFQ.Lang.Experimental 33 | ghc-options: -Wall -fno-warn-missing-signatures 34 | extra-libraries: pfq 35 | -------------------------------------------------------------------------------- /user/lib/Haskell/stack.yaml: -------------------------------------------------------------------------------- 1 | # This file was automatically generated by 'stack init' 2 | # 3 | # Some commonly used options have been documented as comments in this file. 4 | # For advanced use and comprehensive documentation of the format, please see: 5 | # https://docs.haskellstack.org/en/stable/yaml_configuration/ 6 | 7 | # Resolver to choose a 'specific' stackage snapshot or a compiler version. 8 | # A snapshot resolver dictates the compiler version and the set of packages 9 | # to be used for project dependencies. For example: 10 | # 11 | # resolver: lts-3.5 12 | # resolver: nightly-2015-09-21 13 | # resolver: ghc-7.10.2 14 | # resolver: ghcjs-0.1.0_ghc-7.10.2 15 | # resolver: 16 | # name: custom-snapshot 17 | # location: "./custom-snapshot.yaml" 18 | resolver: lts-11.8 19 | 20 | # User packages to be built. 21 | # Various formats can be used as shown in the example below. 22 | # 23 | # packages: 24 | # - some-directory 25 | # - https://example.com/foo/bar/baz-0.0.2.tar.gz 26 | # - location: 27 | # git: https://github.com/commercialhaskell/stack.git 28 | # commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a 29 | # - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a 30 | # extra-dep: true 31 | # subdirs: 32 | # - auto-update 33 | # - wai 34 | # 35 | # A package marked 'extra-dep: true' will only be built if demanded by a 36 | # non-dependency (i.e. a user package), and its test suites and benchmarks 37 | # will not be run. This is useful for tweaking upstream packages. 38 | packages: 39 | - . 40 | # Dependency packages to be pulled from upstream that are not in the resolver 41 | # (e.g., acme-missiles-0.3) 42 | extra-deps: [] 43 | 44 | # Override default flag values for local packages and extra-deps 45 | flags: {} 46 | 47 | # Extra package databases containing global packages 48 | extra-package-dbs: [] 49 | 50 | # Control whether we use the GHC we find on the path 51 | # system-ghc: true 52 | # 53 | # Require a specific version of stack, using version ranges 54 | # require-stack-version: -any # Default 55 | # require-stack-version: ">=1.5" 56 | # 57 | # Override the architecture used by stack, especially useful on Windows 58 | # arch: i386 59 | # arch: x86_64 60 | # 61 | # Extra directories used by stack for building 62 | # extra-include-dirs: [/path/to/dir] 63 | extra-lib-dirs: [../C/] 64 | # 65 | # Allow a newer minor version of GHC than the snapshot specifies 66 | # compiler-check: newer-minor 67 | -------------------------------------------------------------------------------- /user/lib/common/lib/more/affinity.hpp: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 - Nicola Bonelli 4 | * 5 | ****************************************************************/ 6 | 7 | #pragma once 8 | 9 | #ifndef _GNU_SOURCE 10 | #define _GNU_SOURCE 11 | #endif 12 | 13 | #include 14 | #include // pthread_setaffinity_np 15 | 16 | #include 17 | #include 18 | 19 | namespace more { 20 | 21 | static inline 22 | void set_affinity(std::thread &t, size_t n) 23 | { 24 | if(t.get_id() == std::thread::id()) 25 | throw std::runtime_error("thread not running"); 26 | 27 | cpu_set_t cpuset; 28 | 29 | CPU_ZERO(&cpuset); 30 | CPU_SET(n, &cpuset); 31 | 32 | auto pth = t.native_handle(); 33 | if ( ::pthread_setaffinity_np(pth, sizeof(cpuset), &cpuset) != 0) 34 | throw std::runtime_error("pthread_setaffinity_np"); 35 | } 36 | 37 | } // namespace more 38 | 39 | -------------------------------------------------------------------------------- /user/lib/common/lib/more/pretty.hpp: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 - Nicola Bonelli 4 | * 5 | ****************************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace more { 15 | 16 | namespace detail { 17 | 18 | template 19 | std::string to_string(std::ostringstream &out, T &&arg) 20 | { 21 | out << std::move(arg); 22 | return out.str(); 23 | } 24 | template 25 | std::string to_string(std::ostringstream &out, T &&arg, Ts&&... args) 26 | { 27 | out << std::move(arg); 28 | return to_string(out, std::forward(args)...); 29 | } 30 | } 31 | 32 | template 33 | U persecond(T value, Duration dur) 34 | { 35 | return static_cast(value) * 1000000 / static_cast(std::chrono::duration_cast(dur).count()); 36 | } 37 | 38 | template 39 | inline std::string 40 | to_string(Ts&& ... args) 41 | { 42 | std::ostringstream out; 43 | return detail::to_string(out, std::forward(args)...); 44 | } 45 | 46 | template 47 | inline std::string 48 | pretty_number(T value) 49 | { 50 | if (value < 1000000000) { 51 | if (value < 1000000) { 52 | if (value < 1000) { 53 | return to_string(value); 54 | } 55 | else return to_string(value/1000, "_K"); 56 | } 57 | else return to_string(value/1000000, "_M"); 58 | } 59 | else return to_string(value/1000000000, "_G"); 60 | } 61 | 62 | bool any_strcmp(const char *arg, const char *opt) 63 | { 64 | return strcmp(arg,opt) == 0; 65 | } 66 | template 67 | bool any_strcmp(const char *arg, const char *opt, Ts&&...args) 68 | { 69 | return (strcmp(arg,opt) == 0 ? true : any_strcmp(arg, std::forward(args)...)); 70 | } 71 | 72 | } // namespace more 73 | 74 | -------------------------------------------------------------------------------- /user/lib/common/lib/more/vt100.hpp: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * 3 | * (C) 2011-16 - Nicola Bonelli 4 | * 5 | ****************************************************************/ 6 | 7 | #pragma once 8 | 9 | namespace more { namespace vt100 10 | { 11 | namespace 12 | { 13 | const char * const CLEAR = "\E[2J"; 14 | const char * const EDOWN = "\E[J"; 15 | const char * const DOWN = "\E[1B"; 16 | const char * const HOME = "\E[H"; 17 | const char * const ELINE = "\E[K"; 18 | const char * const BOLD = "\E[1m"; 19 | const char * const RESET = "\E[0m"; 20 | const char * const BLUE = "\E[1;34m"; 21 | const char * const RED = "\E[31m"; 22 | } 23 | } 24 | } // namespace more 25 | 26 | -------------------------------------------------------------------------------- /user/lib/libpcap-1.8.1-fanout/.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /user/lib/libpcap-1.8.1-fanout/ChmodBPF/ChmodBPF: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | . /etc/rc.common 4 | 5 | StartService () 6 | { 7 | # 8 | # Unfortunately, Mac OS X's devfs is based on the old FreeBSD 9 | # one, not the current one, so there's no way to configure it 10 | # to create BPF devices with particular owners or groups. 11 | # This startup item will make it owned by the admin group, 12 | # with permissions rw-rw----, so that anybody in the admin 13 | # group can use programs that capture or send raw packets. 14 | # 15 | # Change this as appropriate for your site, e.g. to make 16 | # it owned by a particular user without changing the permissions, 17 | # so only that user and the super-user can capture or send raw 18 | # packets, or give it the permissions rw-r-----, so that 19 | # only the super-user can send raw packets but anybody in the 20 | # admin group can capture packets. 21 | # 22 | chgrp admin /dev/bpf* 23 | chmod g+rw /dev/bpf* 24 | } 25 | 26 | StopService () 27 | { 28 | return 0; 29 | } 30 | 31 | RestartService () { StartService; } 32 | 33 | RunService "$1" 34 | -------------------------------------------------------------------------------- /user/lib/libpcap-1.8.1-fanout/ChmodBPF/StartupParameters.plist: -------------------------------------------------------------------------------- 1 | { 2 | Description = "Change BPF permissions"; 3 | Provides = ("ChmodBPF"); 4 | } 5 | -------------------------------------------------------------------------------- /user/lib/libpcap-1.8.1-fanout/GenVersion.bat: -------------------------------------------------------------------------------- 1 | REM 2 | REM Automatically generate pcap_version.h based on pcap_version.h.in 3 | REM for Windows 4 | REM The version string comes from VERSION 5 | REM @echo off 6 | REM 7 | 8 | setlocal enableextensions disabledelayedexpansion 9 | 10 | set "search=%%%%LIBPCAP_VERSION%%%%" 11 | set /p replace=<%1 12 | 13 | if exist %3 del %3 2>nul 14 | 15 | for /f "delims=" %%i in ('type %2' ) do ( 16 | set "line=%%i" 17 | setlocal enabledelayedexpansion 18 | set "line=!line:%search%=%replace%!" 19 | >>%3 echo(!line! 20 | endlocal 21 | ) 22 | 23 | echo pcap_version.h generated 24 | -------------------------------------------------------------------------------- /user/lib/libpcap-1.8.1-fanout/LICENSE: -------------------------------------------------------------------------------- 1 | License: BSD 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in 11 | the documentation and/or other materials provided with the 12 | distribution. 13 | 3. The names of the authors may not be used to endorse or promote 14 | products derived from this software without specific prior 15 | written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 18 | IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 | -------------------------------------------------------------------------------- /user/lib/libpcap-1.8.1-fanout/Makefile-devel-adds: -------------------------------------------------------------------------------- 1 | # 2 | # Auto-regenerate configure script or Makefile when things change. 3 | # From autoconf.info . Works best with GNU Make. 4 | # 5 | ${srcdir}/configure: configure.ac aclocal.m4 6 | cd ${srcdir} && autoconf 7 | 8 | # autoheader might not change config.h.in, so touch a stamp file. 9 | ${srcdir}/config.h.in: ${srcdir}/stamp-h.in 10 | ${srcdir}/stamp-h.in: configure.ac aclocal.m4 11 | cd ${srcdir} && autoheader 12 | echo timestamp > ${srcdir}/stamp-h.in 13 | 14 | config.h: stamp-h 15 | stamp-h: ${srcdir}/config.h.in config.status 16 | ./config.status 17 | 18 | Makefile: Makefile.in config.status 19 | ./config.status 20 | 21 | config.status: ${srcdir}/configure 22 | ./config.status --recheck 23 | -------------------------------------------------------------------------------- /user/lib/libpcap-1.8.1-fanout/README.Win32: -------------------------------------------------------------------------------- 1 | Under Win32, libpcap is integrated in the WinPcap packet capture system. 2 | WinPcap provides a framework that allows libpcap to capture the packets 3 | under Windows 95, Windows 98, Windows ME, Windows NT 4, Windows 2000 4 | and Windows XP. 5 | WinPcap binaries and source code can be found at http://winpcap.polito.it: 6 | they include also a developer's pack with all the necessary to compile 7 | libpcap-based applications under Windows. 8 | 9 | How to compile libpcap with Visual Studio 10 | ----------------------------------------- 11 | 12 | In order to compile libpcap you will need: 13 | 14 | - version 6 (or higher) of Microsoft Visual Studio 15 | - The November 2001 (or later) edition of Microsoft Platform 16 | Software Development Kit (SDK), that contains some necessary includes 17 | for IPv6 support. You can download it from http://www.microsoft.com/sdk 18 | - the latest WinPcap sources from http://winpcap.polito.it/install 19 | 20 | The WinPcap source code already contains a recent (usually the latest 21 | stable) version of libpcap. If you need to compile a different one, 22 | simply download it from www.tcpdump.org and copy the sources in the 23 | winpcap\wpcap\libpcap folder of the WinPcap distribution. If you want to 24 | compile a libpcap source retrieved from the tcpdump.org Git, you will 25 | have to create the scanner and the grammar by hand (with lex and yacc) 26 | or with the cygnus makefile, since The Visual Studio project is not able 27 | to build them. 28 | 29 | Open the project file winpcap\wpcap\prj\wpcap.dsw with Visual Studio and 30 | build wpcap.dll. wpcap.lib, the library file to link with the applications, 31 | will be generated in winpcap\wpcap\lib\. wpcap.dll will be generated in 32 | winpcap\wpcap\prj\release or winpcap\wpcap\prj\debug depending on the type 33 | of binary that is being created. 34 | 35 | How to compile libpcap with Cygnus 36 | ---------------------------------- 37 | 38 | To build wpcap.dll, cd to the directory WPCAP/PRJ of the WinPcap source code 39 | distribution and type "make". libwpcap.a, the library file to link with the 40 | applications, will be generated in winpcap\wpcap\lib\. wpcap.dll will be 41 | generated in winpcap\wpcap\prj. 42 | 43 | Remember, you CANNOT use the MSVC-generated .lib files with gcc, use 44 | libwpcap.a instead. 45 | 46 | "make install" installs wpcap.dll in the Windows system folder. 47 | -------------------------------------------------------------------------------- /user/lib/libpcap-1.8.1-fanout/README.septel: -------------------------------------------------------------------------------- 1 | The following instructions apply if you have a Linux platform and want 2 | libpcap to support the Septel range of passive network monitoring cards 3 | from Intel (http://www.intel.com) 4 | 5 | 1) Install and build the Septel software distribution by following the 6 | instructions supplied with that package. 7 | 8 | 2) Configure libcap. To allow the 'configure' script to locate the Septel 9 | software distribution use the '--with-septel' option: 10 | 11 | ./configure --with-septel=DIR 12 | 13 | where DIR is the root of the Septel software distribution, for example 14 | /var/src/septel. 15 | 16 | By default (if you write only ./configure --with-septel) it takes 17 | ./../septel as argument for DIR. 18 | 19 | If the Septel software is correctly detected 'configure' will 20 | report: 21 | 22 | checking whether we have Septel API... yes 23 | 24 | If 'configure' reports that there is no Septel API, the directory may have been 25 | incorrectly specified or the Septel software was not built before configuring 26 | libpcap. 27 | 28 | See also the libpcap INSTALL.txt file for further libpcap configuration 29 | options. 30 | 31 | Building libpcap at this stage will include support for both the native 32 | packet capture stream and for capturing from Septel cards. To build 33 | libpcap with only Septel support specify the capture type as 'septel' 34 | when configuring libpcap: 35 | 36 | ./configure --with-septel=DIR --with-pcap=septel 37 | 38 | Applications built with libpcap configured in this way will only detect Septel 39 | cards and will not capture from the native OS packet stream. 40 | 41 | Note: As mentioned in pcap-septel.c we should first edit the system.txt 42 | file to change the user part example (UPE) module id to 0xdd instead of 43 | 0x2d for technical reason. So this change in system.txt is crutial and 44 | things will go wrong if it's not done. System.txt along with config.txt 45 | are configuration files that are edited by the user before running the 46 | gctload program that uses these files for initialising modules and 47 | configuring parameters. 48 | 49 | ---------------------------------------------------------------------- 50 | for more information please contact me : gil_hoyek@hotmail.com 51 | -------------------------------------------------------------------------------- /user/lib/libpcap-1.8.1-fanout/README.tru64: -------------------------------------------------------------------------------- 1 | The following instructions are applicable to Tru64 UNIX 2 | (formerly Digital UNIX (formerly DEC OSF/1)) version 4.0, and 3 | probably to later versions as well; at least some options apply to 4 | Digital UNIX 3.2 - perhaps all do. 5 | 6 | In order to use kernel packet filtering on this system, you have 7 | to configure it in such a way: 8 | 9 | Kernel configuration 10 | -------------------- 11 | 12 | The packet filtering kernel option must be enabled at kernel 13 | installation. If it was not the case, you can rebuild the kernel with 14 | "doconfig -c" after adding the following line in the kernel 15 | configuration file (/sys/conf/): 16 | 17 | option PACKETFILTER 18 | 19 | or use "doconfig" without any arguments to add the packet filter driver 20 | option via the kernel option menu (see the system administration 21 | documentation for information on how to do this). 22 | 23 | Device configuration 24 | -------------------- 25 | 26 | Devices used for packet filtering must be created thanks to 27 | the following command (executed in the /dev directory): 28 | 29 | ./MAKEDEV pfilt 30 | 31 | Interface configuration 32 | ----------------------- 33 | 34 | In order to capture all packets on a network, you may want to allow 35 | applications to put the interface on that network into "local copy" 36 | mode, so that tcpdump can see packets sent by the host on which it's 37 | running as well as packets received by that host, and to put the 38 | interface into "promiscuous" mode, so that tcpdump can see packets on 39 | the network segment not sent to the host on which it's running, by using 40 | the pfconfig(1) command: 41 | 42 | pfconfig +c +p 43 | 44 | or allow application to put any interface into "local copy" or 45 | "promiscuous" mode by using the command: 46 | 47 | pfconfig +c +p -a 48 | 49 | Note: all instructions given require root privileges. 50 | -------------------------------------------------------------------------------- /user/lib/libpcap-1.8.1-fanout/SUNOS4/nit_if.o.sparc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pfq/PFQ/4b03e315fadce53039b905c133a1738572e79e8c/user/lib/libpcap-1.8.1-fanout/SUNOS4/nit_if.o.sparc -------------------------------------------------------------------------------- /user/lib/libpcap-1.8.1-fanout/SUNOS4/nit_if.o.sun3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pfq/PFQ/4b03e315fadce53039b905c133a1738572e79e8c/user/lib/libpcap-1.8.1-fanout/SUNOS4/nit_if.o.sun3 -------------------------------------------------------------------------------- /user/lib/libpcap-1.8.1-fanout/SUNOS4/nit_if.o.sun4c.4.0.3c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pfq/PFQ/4b03e315fadce53039b905c133a1738572e79e8c/user/lib/libpcap-1.8.1-fanout/SUNOS4/nit_if.o.sun4c.4.0.3c -------------------------------------------------------------------------------- /user/lib/libpcap-1.8.1-fanout/TODO: -------------------------------------------------------------------------------- 1 | TODO list for libpcap 2 | ======================= 3 | 4 | Important stuff (to be done before the next release) 5 | --------------- 6 | 7 | General 8 | 9 | - configure should not be in Git. Most open source projects have an 10 | autogen.sh script to run autoconf etc. after checkout. I think we 11 | should stick to the standard. 12 | 13 | - The source files should be better documented. There is no official 14 | design guideline for what is done where. There should be a common coding 15 | style (okay, you can guess that by looking at the code) and a guide for 16 | what needs to be documented. 17 | 18 | Less urgent items 19 | ----------------- 20 | 21 | - Better documentation and cleanup of the interface. I am seeing a few 22 | problems at the first glance which needs fixing: 23 | + pcap_lookupnet makes little to no sense with protocols != IPv4 24 | + not very well suited for interactive programs (think ethereal). There 25 | should be a way for the application to get a file descriptor which it 26 | has to monitor and a callback in pcap which has to be called on 27 | activity (XXX - "pcap_fileno()" handles the first part, although 28 | "select()" and "poll()" don't work on BPF devices on most BSDs, and 29 | you can call "pcap_dispatch()" as the dispatch routine after putting 30 | the descriptor into non-blocking mode) 31 | + too many functions. There are a lot of functions for everything which 32 | violates the KISS principle. Why do we need pcap_strerror, pcap_perror 33 | and pcap_geterr? 34 | + the manpage has a brief description of each function but where is the 35 | big picture? Seems like you need to buy UNP for that... 36 | -------------------------------------------------------------------------------- /user/lib/libpcap-1.8.1-fanout/VERSION: -------------------------------------------------------------------------------- 1 | 1.8.1-fanout 2 | -------------------------------------------------------------------------------- /user/lib/libpcap-1.8.1-fanout/Win32/Include/Gnuc.h: -------------------------------------------------------------------------------- 1 | /* inline foo */ 2 | #ifndef __cplusplus 3 | #ifdef __GNUC__ 4 | #define inline __inline 5 | #else 6 | #define inline 7 | #endif 8 | #endif 9 | -------------------------------------------------------------------------------- /user/lib/libpcap-1.8.1-fanout/Win32/Prj/wpcap.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.40629.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wpcap", "wpcap.vcxproj", "{8E92D840-6A36-452A-A13C-6E1BA5A2C5A9}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Debug|x64 = Debug|x64 12 | Release|Win32 = Release|Win32 13 | Release|x64 = Release|x64 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {8E92D840-6A36-452A-A13C-6E1BA5A2C5A9}.Debug|Win32.ActiveCfg = Debug|Win32 17 | {8E92D840-6A36-452A-A13C-6E1BA5A2C5A9}.Debug|Win32.Build.0 = Debug|Win32 18 | {8E92D840-6A36-452A-A13C-6E1BA5A2C5A9}.Debug|x64.ActiveCfg = Debug|x64 19 | {8E92D840-6A36-452A-A13C-6E1BA5A2C5A9}.Debug|x64.Build.0 = Debug|x64 20 | {8E92D840-6A36-452A-A13C-6E1BA5A2C5A9}.Release|Win32.ActiveCfg = Release|Win32 21 | {8E92D840-6A36-452A-A13C-6E1BA5A2C5A9}.Release|Win32.Build.0 = Release|Win32 22 | {8E92D840-6A36-452A-A13C-6E1BA5A2C5A9}.Release|x64.ActiveCfg = Release|x64 23 | {8E92D840-6A36-452A-A13C-6E1BA5A2C5A9}.Release|x64.Build.0 = Release|x64 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /user/lib/libpcap-1.8.1-fanout/bpf_dump.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that: (1) source code distributions 7 | * retain the above copyright notice and this paragraph in its entirety, (2) 8 | * distributions including binary code include the above copyright notice and 9 | * this paragraph in its entirety in the documentation or other materials 10 | * provided with the distribution, and (3) all advertising materials mentioning 11 | * features or use of this software display the following acknowledgement: 12 | * ``This product includes software developed by the University of California, 13 | * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14 | * the University nor the names of its contributors may be used to endorse 15 | * or promote products derived from this software without specific prior 16 | * written permission. 17 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 | */ 21 | 22 | #ifdef HAVE_CONFIG_H 23 | #include "config.h" 24 | #endif 25 | 26 | #include 27 | #include 28 | 29 | void 30 | bpf_dump(const struct bpf_program *p, int option) 31 | { 32 | const struct bpf_insn *insn; 33 | int i; 34 | int n = p->bf_len; 35 | 36 | insn = p->bf_insns; 37 | if (option > 2) { 38 | printf("%d\n", n); 39 | for (i = 0; i < n; ++insn, ++i) { 40 | printf("%u %u %u %u\n", insn->code, 41 | insn->jt, insn->jf, insn->k); 42 | } 43 | return ; 44 | } 45 | if (option > 1) { 46 | for (i = 0; i < n; ++insn, ++i) 47 | printf("{ 0x%x, %d, %d, 0x%08x },\n", 48 | insn->code, insn->jt, insn->jf, insn->k); 49 | return; 50 | } 51 | for (i = 0; i < n; ++insn, ++i) { 52 | #ifdef BDEBUG 53 | extern int bids[]; 54 | if (bids[i] > 0) 55 | printf("[%02d]", bids[i] - 1); 56 | else 57 | printf(" -- "); 58 | #endif 59 | puts(bpf_image(insn, i)); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /user/lib/libpcap-1.8.1-fanout/chmod_bpf: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # 4 | # Unfortunately, Mac OS X's devfs is based on the old FreeBSD 5 | # one, not the current one, so there's no way to configure it 6 | # to create BPF devices with particular owners or groups. 7 | # This startup item will make it owned by the admin group, 8 | # with permissions rw-rw----, so that anybody in the admin 9 | # group can use programs that capture or send raw packets. 10 | # 11 | # Change this as appropriate for your site, e.g. to make 12 | # it owned by a particular user without changing the permissions, 13 | # so only that user and the super-user can capture or send raw 14 | # packets, or give it the permissions rw-r-----, so that 15 | # only the super-user can send raw packets but anybody in the 16 | # admin group can capture packets. 17 | # 18 | chgrp admin /dev/bpf* 19 | chmod g+rw /dev/bpf* 20 | -------------------------------------------------------------------------------- /user/lib/libpcap-1.8.1-fanout/config/have_siocglifconf.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() { 5 | ioctl(0, SIOCGLIFCONF, (char *)0); 6 | } 7 | -------------------------------------------------------------------------------- /user/lib/libpcap-1.8.1-fanout/dlpisubs.h: -------------------------------------------------------------------------------- 1 | #ifndef dlpisubs_h 2 | #define dlpisubs_h 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | /* 9 | * Private data for capturing on DLPI devices. 10 | */ 11 | struct pcap_dlpi { 12 | #ifdef HAVE_LIBDLPI 13 | dlpi_handle_t dlpi_hd; 14 | #endif /* HAVE_LIBDLPI */ 15 | #ifdef DL_HP_RAWDLS 16 | int send_fd; 17 | #endif /* DL_HP_RAWDLS */ 18 | 19 | struct pcap_stat stat; 20 | }; 21 | 22 | /* 23 | * Functions defined by dlpisubs.c. 24 | */ 25 | int pcap_stats_dlpi(pcap_t *, struct pcap_stat *); 26 | int pcap_process_pkts(pcap_t *, pcap_handler, u_char *, int, u_char *, int); 27 | int pcap_process_mactype(pcap_t *, u_int); 28 | #ifdef HAVE_SYS_BUFMOD_H 29 | int pcap_conf_bufmod(pcap_t *, int); 30 | #endif 31 | int pcap_alloc_databuf(pcap_t *); 32 | int strioctl(int, int, int, char *); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /user/lib/libpcap-1.8.1-fanout/gen_version_c.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | echo '#include ' > "$2" 3 | echo 'PCAP_API_DEF' >> "$2" 4 | if grep GIT "$1" >/dev/null; then 5 | read ver <"$1" 6 | echo $ver | tr -d '\012' 7 | date +_%Y_%m_%d 8 | else 9 | cat "$1" 10 | fi | sed -e 's/.*/char pcap_version[] = "&";/' >> "$2" 11 | 12 | -------------------------------------------------------------------------------- /user/lib/libpcap-1.8.1-fanout/gen_version_header.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | print_version_string() 3 | { 4 | if grep GIT "$1" >/dev/null 5 | then 6 | read ver <"$1" 7 | echo $ver | tr -d '\012' 8 | date +_%Y_%m_%d 9 | else 10 | cat "$1" 11 | fi 12 | } 13 | if test $# != 3 14 | then 15 | echo "Usage: gen_version_header.sh