Help with writing Makefile for iptables-faketcp

I need Help With creating this package https://github.com/xdqi/iptables-faketcp for OpenWrt x86_64

the Makefile I write:

include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk

PKG_NAME:=faketcp
PKG_RELEASE:=3

PKG_SOURCE_DATE:=2019-10-21
PKG_LICENSE:=GPL-2.0
PKG_LICENSE_FILES:=LICENSE
PKG_SOURCE:=iptables-faketcp
include $(INCLUDE_DIR)/package.mk

define Package/iptables-mod-faketcp
  SUBMENU:=Firewall
  SECTION:=net
  CATEGORY:=Network
  TITLE:=FAKETCP iptables extension
  DEPENDS:=+iptables +kmod-ipt-faketcp
  MAINTAINER:=Chion Tang <tech@chionlab.moe>
endef

define Package/iptables-mod-faketcp/install
	$(INSTALL_DIR) $(1)/usr/lib/iptables
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/libipt_FAKETCP.so $(1)/usr/lib/iptables
endef

define KernelPackage/ipt-faketcp
  SUBMENU:=Netfilter Extensions
  TITLE:=FAKETCP netfilter module
  DEPENDS:=+kmod-nf-ipt +kmod-nf-nat
  MAINTAINER:=Chion Tang <tech@chionlab.moe>
  KCONFIG:=CONFIG_NF_CONNTRACK_EVENTS=y CONFIG_NF_CONNTRACK_CHAIN_EVENTS=y
  FILES:=$(PKG_BUILD_DIR)/xt_FAKETCP.ko
endef

include $(INCLUDE_DIR)/kernel-defaults.mk

define Build/Prepare
	$(call Build/Prepare/Default)
	$(CP) ./files/Makefile $(PKG_BUILD_DIR)/
endef

define Build/Compile
	+$(MAKE) $(PKG_JOBS) -C "$(LINUX_DIR)" \
        CROSS_COMPILE="$(TARGET_CROSS)" \
        ARCH="$(LINUX_KARCH)" \
        M="$(PKG_BUILD_DIR)" \
        EXTRA_CFLAGS="$(BUILDFLAGS)" \
        modules
	$(call Build/Compile/Default)
endef

$(eval $(call BuildPackage,iptables-mod-faketcp))
$(eval $(call KernelPackage,ipt-faketcp))

....... and the issue is ?

i can't build it it gave errors can you help mw

you did right not to post them .... A+.

:smile:


H="x86" M="/home/isso/Downloads/openwrt-sdk-21.02.2-x86-64_gcc-8.4.0_musl.Linux-x86_64/build_dir/target-x86_64_musl/linux-x86_64/faketcp" EXTRA_CFLAGS="" modules
make[3]: Entering directory '/home/isso/Downloads/openwrt-sdk-21.02.2-x86-64_gcc-8.4.0_musl.Linux-x86_64/build_dir/target-x86_64_musl/linux-x86_64/linux-5.4.179'
make[4]: *** No rule to make target '/home/isso/Downloads/openwrt-sdk-21.02.2-x86-64_gcc-8.4.0_musl.Linux-x86_64/build_dir/target-x86_64_musl/linux-x86_64/faketcp/xt_FAKETCP.o', needed by '__build'.  Stop.
make[3]: *** [Makefile:1734: /home/isso/Downloads/openwrt-sdk-21.02.2-x86-64_gcc-8.4.0_musl.Linux-x86_64/build_dir/target-x86_64_musl/linux-x86_64/faketcp] Error 2
make[3]: Leaving directory '/home/isso/Downloads/openwrt-sdk-21.02.2-x86-64_gcc-8.4.0_musl.Linux-x86_64/build_dir/target-x86_64_musl/linux-x86_64/linux-5.4.179'
make[2]: *** [Makefile:56: /home/isso/Downloads/openwrt-sdk-21.02.2-x86-64_gcc-8.4.0_musl.Linux-x86_64/build_dir/target-x86_64_musl/linux-x86_64/faketcp/.built] Error 2
make[2]: Leaving directory '/home/isso/Downloads/openwrt-sdk-21.02.2-x86-64_gcc-8.4.0_musl.Linux-x86_64/package/iptables-faketcp'
time: package/iptables-faketcp/compile#1.63#1.71#3.64
    ERROR: package/iptables-faketcp failed to build.
make[1]: *** [package/Makefile:116: package/iptables-faketcp/compile] Error 1
make[1]: Leaving directory '/home/isso/Downloads/openwrt-sdk-21.02.2-x86-64_gcc-8.4.0_musl.Linux-x86_64'
make: *** [/home/isso/Downloads/openwrt-sdk-21.02.2-x86-64_gcc-8.4.0_musl.Linux-x86_64/include/toplevel.mk:223: package/iptables-faketcp/compile] Error 2

can you help me to make this package for openwrt

haven't done it in a while, but have a look at Kernel module build but not installed to image

There is no reason to put two topics on the same thing..

@tmomas Can these be merged?

1 Like

i able to build kmod-ipt-faketcp with this Makefile:


include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk

PKG_NAME:=kmod-ipt-faketcp
PKG_VERSION:=5.1.0
PKG_RELEASE:=3

REDIST_TARGET:=linux
PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(PKG_NAME)-$(REDIST_RELEASE)

include $(INCLUDE_DIR)/package.mk

define KernelPackage/ipt-faketcp
	SUBMENU:=Custom Modules
	TITLE:=Faketcp
	FILES:=$(PKG_BUILD_DIR)/xt_FAKETCP.ko
	DEPENDS:=+kmod-nf-ipt +libxtables

endef

define KernelPackage/faketcp/description
My Testing Module
endef

define Build/Prepare
	$(call Build/Prepare/Default)
	$(CP) /home/isso/iptables-faketcp/ko/xt_FAKETCP.c $(PKG_BUILD_DIR)/xt_FAKETCP.c
	$(CP) /home/isso/iptables-faketcp/ko/Makefile $(PKG_BUILD_DIR)/Makefile
endef


define Build/Compile
	+$(MAKE) $(PKG_JOBS) -C "$(LINUX_DIR)" \
        CROSS_COMPILE="$(TARGET_CROSS)" \
        ARCH="$(LINUX_KARCH)" \
        M="$(PKG_BUILD_DIR)" \
        EXTRA_CFLAGS="$(BUILDFLAGS)" \
        modules
	$(call Build/Compile/Default)
endef

$(eval $(call KernelPackage,ipt-faketcp))

now i'm trying to compile iptables-mod-faketcp with this makefile

nclude $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk

PKG_NAME:=faketcp
PKG_RELEASE:=3

PKG_SOURCE_DATE:=2019-10-21
PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(PKG_NAME)-$(REDIST_RELEASE)


PKG_LICENSE:=GPL-2.0
PKG_LICENSE_FILES:=LICENSE

include $(INCLUDE_DIR)/package.mk

define Package/iptables-mod-faketcp
  SUBMENU:=Firewall
  SECTION:=net
  CATEGORY:=Network
  TITLE:=FAKETCP iptables extension
  DEPENDS:=+iptables

endef

define Package/iptables-mod-faketcp/install
	$(INSTALL_DIR) $(1)/usr/lib/iptables
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/libipt_FAKETCP.so $(1)/usr/lib/iptables
endef


define Build/Prepare
	$(call Build/Prepare/Default)
	$(CP) ./files/Makefile $(PKG_BUILD_DIR)/Makefile
	$(CP) ./files/libipt_FAKETCP.c $(PKG_BUILD_DIR)/libipt_FAKETCP.c
endef

define Build/Compile
	+$(MAKE) $(PKG_JOBS) -C "$(LINUX_DIR)" \
        CROSS_COMPILE="$(TARGET_CROSS)" \
        ARCH="$(LINUX_KARCH)" \
        M="$(PKG_BUILD_DIR)" \
        EXTRA_CFLAGS="$(BUILDFLAGS)" \
        modules
	$(call Build/Compile/Default)
endef

$(eval $(call BuildPackage,iptables-mod-faketcp))

and it give this error

touch /home/isso/Downloads/openwrt-sdk-21.02.2-x86-64_gcc-8.4.0_musl.Linux-x86_64/staging_dir/target-x86_64_musl/root-x86/stamp/.ip6tables-mod-nat_installed
touch -r /home/isso/Downloads/openwrt-sdk-21.02.2-x86-64_gcc-8.4.0_musl.Linux-x86_64/build_dir/target-x86_64_musl/linux-x86_64/iptables-1.8.7/.built /home/isso/Downloads/openwrt-sdk-21.02.2-x86-64_gcc-8.4.0_musl.Linux-x86_64/build_dir/target-x86_64_musl/linux-x86_64/iptables-1.8.7/.autoremove 2>/dev/null >/dev/null
find /home/isso/Downloads/openwrt-sdk-21.02.2-x86-64_gcc-8.4.0_musl.Linux-x86_64/build_dir/target-x86_64_musl/linux-x86_64/iptables-1.8.7 -mindepth 1 -maxdepth 1 -not '(' -type f -and -name '.*' -and -size 0 ')' -and -not -name '.pkgdir' | xargs -r rm -rf
make[2]: Leaving directory '/home/isso/Downloads/openwrt-sdk-21.02.2-x86-64_gcc-8.4.0_musl.Linux-x86_64/feeds/base/package/network/utils/iptables'
time: package/feeds/base/iptables/compile#44.90#20.86#66.12
make[2]: Entering directory '/home/isso/Downloads/openwrt-sdk-21.02.2-x86-64_gcc-8.4.0_musl.Linux-x86_64/package/iptables-mod-faketcp'
touch -r /home/isso/Downloads/openwrt-sdk-21.02.2-x86-64_gcc-8.4.0_musl.Linux-x86_64/build_dir/target-x86_64_musl/linux-x86_64/faketcp-/.built /home/isso/Downloads/openwrt-sdk-21.02.2-x86-64_gcc-8.4.0_musl.Linux-x86_64/build_dir/target-x86_64_musl/linux-x86_64/faketcp-/.autoremove 2>/dev/null >/dev/null
make[2]: [Makefile:47: compile] Error 1 (ignored)
find /home/isso/Downloads/openwrt-sdk-21.02.2-x86-64_gcc-8.4.0_musl.Linux-x86_64/build_dir/target-x86_64_musl/linux-x86_64/faketcp- -mindepth 1 -maxdepth 1 -not '(' -type f -and -name '.*' -and -size 0 ')' -and -not -name '.pkgdir' | xargs -r rm -rf
make[2]: Leaving directory '/home/isso/Downloads/openwrt-sdk-21.02.2-x86-64_gcc-8.4.0_musl.Linux-x86_64/package/iptables-mod-faketcp'
time: package/iptables-mod-faketcp/compile#0.24#0.24#0.44
make[1]: Leaving directory '/home/isso/Downloads/openwrt-sdk-21.02.2-x86-64_gcc-8.4.0_musl.Linux-x86_64'

probably want to enable verbosity during compilation ....

-j1 V=s, if i remember correctly.

1 Like

this the output of make package/iptables-mod-faketcp/compile V=sc

problem solved when i changed the PKG_BUILD_DIR thanks all for your help

You had asked about local files vs the Git repo in the other thread.

If you have any interest in sending in a Pull-Request for that package, so that others might also use it if they find a need for it, you'll need to reference something outside of your local machine. Also, the build system will pull the repo, archive it and stash it in dl/ (the error you were seeing previously about invalid archive formats is due to this)

i will give the working makefiles, my friend helped me to make this work so the first Makefile is for kmod-ipt-faketcp:


Makefile of kmod-ipt-faketcp
include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk

PKG_NAME:=kmod-ipt-faketcp
PKG_VERSION:=5.1.0
PKG_RELEASE:=3

REDIST_TARGET:=linux
PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(PKG_NAME)-$(REDIST_RELEASE)

include $(INCLUDE_DIR)/package.mk

define KernelPackage/ipt-faketcp
	SUBMENU:=Custom Modules
	TITLE:=Faketcp
	FILES:=$(PKG_BUILD_DIR)/xt_FAKETCP.ko
	DEPENDS:=+kmod-nf-ipt +libxtables

endef

define KernelPackage/faketcp/description
My Testing Module
endef

define Build/Prepare
	$(call Build/Prepare/Default)
	$(CP) /home/isso/iptables-faketcp/ko/xt_FAKETCP.c $(PKG_BUILD_DIR)/xt_FAKETCP.c
	$(CP) /home/isso/iptables-faketcp/ko/Makefile $(PKG_BUILD_DIR)/Makefile
endef


define Build/Compile
	+$(MAKE) $(PKG_JOBS) -C "$(LINUX_DIR)" \
        CROSS_COMPILE="$(TARGET_CROSS)" \
        ARCH="$(LINUX_KARCH)" \
        M="$(PKG_BUILD_DIR)" \
        EXTRA_CFLAGS="$(BUILDFLAGS)" \
        modules
	$(call Build/Compile/Default)
endef

$(eval $(call KernelPackage,ipt-faketcp))

second is for iptables-mod-faketcp


include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk

PKG_NAME:=iptables-mod-faketcp
PKG_VERSION:=5.1.0
PKG_RELEASE:=3

REDIST_TARGET:=linux
PKG_BUILD_DIR:=/home/isso/iptables-mod-faketcp

include $(INCLUDE_DIR)/package.mk

define Package/iptables-mod-faketcp
  SUBMENU:=Firewall
  SECTION:=net
  CATEGORY:=Network
  TITLE:=FAKETCP iptables extension
  DEPENDS:=+iptables

endef

define Package/iptables-mod-faketcp/install
	$(INSTALL_DIR) $(1)/usr/lib/iptables
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/libipt_FAKETCP.so $(1)/usr/lib/iptables
endef
define Build/Prepare
	$(call Build/Prepare/Default)
	$(CP) /home/isso/iptables-faketcp/so/libipt_FAKETCP.c $(PKG_BUILD_DIR)/libipt_FAKETCP.c
	$(CP) /home/isso/iptables-faketcp/so/Makefile $(PKG_BUILD_DIR)/Makefile
endef


define Build/Compile
	+$(MAKE) $(PKG_JOBS) -C "$(LINUX_DIR)" \
        CROSS_COMPILE="$(TARGET_CROSS)" \
        ARCH="$(LINUX_KARCH)" \
        M="$(PKG_BUILD_DIR)" \
        EXTRA_CFLAGS="$(BUILDFLAGS)" \
        modules
	$(call Build/Compile/Default)
endef

$(eval $(call BuildPackage,iptables-mod-faketcp))

you can edit it if you want