mirror of
https://github.com/Lienol/openwrt
synced 2025-01-07 03:06:49 +08:00
shortcut-fe: update
This commit is contained in:
parent
6a4f5d00a6
commit
f50e2d44ba
@ -1,8 +1,23 @@
|
||||
#
|
||||
# Copyright (c) 2013-2018 The Linux Foundation. All rights reserved.
|
||||
# Permission to use, copy, modify, and/or distribute this software for
|
||||
# any purpose with or without fee is hereby granted, provided that the
|
||||
# above copyright notice and this permission notice appear in all copies.
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
include $(INCLUDE_DIR)/kernel.mk
|
||||
|
||||
PKG_NAME:=fast-classifier
|
||||
PKG_RELEASE:=1
|
||||
PKG_CONFIG_DEPENDS := CONFIG_IPV6
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
@ -13,8 +28,11 @@ define KernelPackage/$(PKG_NAME)/Default
|
||||
DEPENDS:=+kmod-ipt-conntrack +kmod-shortcut-fe
|
||||
TITLE:=Kernel driver for FAST Classifier
|
||||
FILES:=$(PKG_BUILD_DIR)/fast-classifier.ko
|
||||
KCONFIG:=CONFIG_NF_CONNTRACK_CHAIN_EVENTS=y CONFIG_NF_CONNTRACK_MARK=y
|
||||
PROVIDES:=$(PKG_NAME)
|
||||
KCONFIG:=CONFIG_NF_CONNTRACK_EVENTS=y \
|
||||
CONFIG_NF_CONNTRACK_CHAIN_EVENTS=y \
|
||||
CONFIG_NF_CONNTRACK_MARK=y \
|
||||
CONFIG_XFRM=y
|
||||
CONFLICTS:=kmod-shortcut-fe-drv kmod-shortcut-fe-cm
|
||||
endef
|
||||
|
||||
define KernelPackage/$(PKG_NAME)
|
||||
@ -49,14 +67,17 @@ Example user space program that communicates with fast
|
||||
classifier kernel module
|
||||
endef
|
||||
|
||||
SFE_MAKE_OPTS:=SFE_SUPPORT_IPV6=y
|
||||
SFE_MAKE_OPTS:=SFE_SUPPORT_IPV6=$(if $(CONFIG_IPV6),y,n)
|
||||
HAVE_ECM:=$(CONFIG_PACKAGE_kmod-qca-nss-ecm-premium)$(CONFIG_PACKAGE_kmod-qca-nss-ecm-noload)$(CONFIG_PACKAGE_kmod-qca-nss-ecm-premium-noload)$(CONFIG_PACKAGE_kmod-qca-nss-ecm-standard)
|
||||
|
||||
|
||||
define Build/Compile/kmod
|
||||
+$(MAKE) $(PKG_JOBS) -C "$(LINUX_DIR)" $(strip $(SFE_MAKE_OPTS)) \
|
||||
+$(MAKE) $(PKG_JOBS) -C "$(LINUX_DIR)" $(SFE_MAKE_OPTS) \
|
||||
$(KERNEL_MAKE_FLAGS) \
|
||||
$(PKG_MAKE_FLAGS) \
|
||||
M="$(PKG_BUILD_DIR)" \
|
||||
CONFIG_FAST_CLASSIFIER=m \
|
||||
$(if $(HAVE_ECM),EXTRA_CFLAGS+="-DCONFIG_SFE_ECM" CONFIG_SFE_ECM=y,) \
|
||||
EXTRA_CFLAGS="$(EXTRA_CFLAGS)" \
|
||||
modules
|
||||
endef
|
||||
|
@ -345,7 +345,9 @@ static bool fast_classifier_find_dev_and_mac_addr(struct sk_buff *skb, sfe_ip_ad
|
||||
}
|
||||
|
||||
dst = (struct dst_entry *)rt;
|
||||
} else {
|
||||
}
|
||||
#ifdef SFE_SUPPORT_IPV6
|
||||
else {
|
||||
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 17, 0))
|
||||
rt6 = rt6_lookup(&init_net, (struct in6_addr *)addr->ip6, 0, 0, NULL, 0);
|
||||
#else
|
||||
@ -357,6 +359,7 @@ static bool fast_classifier_find_dev_and_mac_addr(struct sk_buff *skb, sfe_ip_ad
|
||||
|
||||
dst = (struct dst_entry *)rt6;
|
||||
}
|
||||
#endif
|
||||
|
||||
skip_dst_lookup:
|
||||
rcu_read_lock();
|
||||
@ -1741,8 +1744,11 @@ static int __init fast_classifier_init(void)
|
||||
{
|
||||
struct fast_classifier *sc = &__sc;
|
||||
int result = -1;
|
||||
#ifdef CONFIG_SFE_ECM
|
||||
int (*fast_recv)(struct sk_buff *skb);
|
||||
#endif
|
||||
|
||||
printk(KERN_ALERT "fast-classifier (PBR safe v2.1.4a): starting up\n");
|
||||
printk(KERN_ALERT "fast-classifier: starting up\n");
|
||||
DEBUG_INFO("SFE CM init\n");
|
||||
|
||||
hash_init(fc_conn_ht);
|
||||
@ -1807,6 +1813,7 @@ static int __init fast_classifier_init(void)
|
||||
goto exit3;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NF_CONNTRACK_EVENTS
|
||||
/*
|
||||
* Register a notifier hook to get fast notifications of expired connections.
|
||||
*/
|
||||
@ -1814,12 +1821,14 @@ static int __init fast_classifier_init(void)
|
||||
result = nf_conntrack_register_chain_notifier(&init_net, &fast_classifier_conntrack_notifier);
|
||||
#else
|
||||
result = nf_conntrack_register_notifier(&init_net, &fast_classifier_conntrack_notifier);
|
||||
#endif
|
||||
if (result < 0) {
|
||||
DEBUG_ERROR("can't register nf notifier hook: %d\n", result);
|
||||
goto exit4;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0))
|
||||
result = genl_register_family(&fast_classifier_gnl_family);
|
||||
if (result) {
|
||||
@ -1862,7 +1871,16 @@ static int __init fast_classifier_init(void)
|
||||
/*
|
||||
* Hook the receive path in the network stack.
|
||||
*/
|
||||
#ifdef CONFIG_SFE_ECM
|
||||
rcu_read_lock();
|
||||
fast_recv = rcu_dereference(athrs_fast_nat_recv);
|
||||
rcu_read_unlock();
|
||||
if (!fast_recv) {
|
||||
BUG_ON(athrs_fast_nat_recv);
|
||||
}
|
||||
#else
|
||||
BUG_ON(athrs_fast_nat_recv);
|
||||
#endif
|
||||
RCU_INIT_POINTER(athrs_fast_nat_recv, fast_classifier_recv);
|
||||
|
||||
/*
|
||||
|
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2014 The Linux Foundation. All rights reserved.
|
||||
# Copyright (c) 2013-2018, 2020 The Linux Foundation. All rights reserved.
|
||||
# Permission to use, copy, modify, and/or distribute this software for
|
||||
# any purpose with or without fee is hereby granted, provided that the
|
||||
# above copyright notice and this permission notice appear in all copies.
|
||||
@ -23,13 +23,14 @@ define KernelPackage/shortcut-fe
|
||||
SECTION:=kernel
|
||||
CATEGORY:=Kernel modules
|
||||
SUBMENU:=Network Support
|
||||
DEPENDS:=
|
||||
DEPENDS:=@IPV6
|
||||
TITLE:=Kernel driver for SFE
|
||||
FILES:=$(PKG_BUILD_DIR)/shortcut-fe.ko $(PKG_BUILD_DIR)/shortcut-fe-ipv6.ko
|
||||
FILES:=$(PKG_BUILD_DIR)/shortcut-fe.ko $(if $(CONFIG_IPV6),$(PKG_BUILD_DIR)/shortcut-fe-ipv6.ko,)
|
||||
KCONFIG:=CONFIG_NF_CONNTRACK_EVENTS=y \
|
||||
CONFIG_NF_CONNTRACK_TIMEOUT=y \
|
||||
CONFIG_SHORTCUT_FE=y \
|
||||
CONFIG_XFRM=y
|
||||
PROVIDES:=$(PKG_NAME)
|
||||
AUTOLOAD:=$(call AutoLoad,09,shortcut-fe shortcut-fe-ipv6)
|
||||
endef
|
||||
|
||||
@ -38,10 +39,14 @@ Shortcut is an in-Linux-kernel IP packet forwarding engine.
|
||||
endef
|
||||
|
||||
define KernelPackage/shortcut-fe/install
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_BIN) ./files/etc/init.d/shortcut-fe $(1)/etc/init.d
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(INSTALL_BIN) ./files/usr/bin/sfe_dump $(1)/usr/bin
|
||||
endef
|
||||
|
||||
HAVE_ECM:=$(CONFIG_PACKAGE_kmod-qca-nss-ecm-premium)$(CONFIG_PACKAGE_kmod-qca-nss-ecm-noload)$(CONFIG_PACKAGE_kmod-qca-nss-ecm-premium-noload)$(CONFIG_PACKAGE_kmod-qca-nss-ecm-standard)
|
||||
|
||||
define KernelPackage/shortcut-fe-cm
|
||||
SECTION:=kernel
|
||||
CATEGORY:=Kernel modules
|
||||
@ -49,22 +54,23 @@ define KernelPackage/shortcut-fe-cm
|
||||
DEPENDS:=+kmod-ipt-conntrack +kmod-shortcut-fe
|
||||
TITLE:=Kernel driver for SFE
|
||||
FILES:=$(PKG_BUILD_DIR)/shortcut-fe-cm.ko
|
||||
KCONFIG:=CONFIG_NF_CONNTRACK_CHAIN_EVENTS=y
|
||||
KCONFIG:=CONFIG_NF_CONNTRACK_CHAIN_EVENTS=y \
|
||||
CONFIG_NF_CONNTRACK_EVENTS=y \
|
||||
CONFIG_XFRM=y
|
||||
CONFLICTS:=kmod-shortcut-fe-drv
|
||||
endef
|
||||
|
||||
define KernelPackage/shortcut-fe-cm/Description
|
||||
Simple connection manager for the Shortcut forwarding engine.
|
||||
endef
|
||||
|
||||
EXTRA_CFLAGS+=-DSFE_SUPPORT_IPV6
|
||||
|
||||
define Build/Compile
|
||||
+$(MAKE) $(PKG_JOBS) -C "$(LINUX_DIR)" \
|
||||
$(MAKE) $(PKG_JOBS) -C "$(LINUX_DIR)" \
|
||||
$(KERNEL_MAKE_FLAGS) \
|
||||
$(PKG_MAKE_FLAGS) \
|
||||
M="$(PKG_BUILD_DIR)" \
|
||||
EXTRA_CFLAGS="$(EXTRA_CFLAGS)" \
|
||||
SFE_SUPPORT_IPV6=1 \
|
||||
$(if $(CONFIG_IPV6),EXTRA_CFLAGS+="-DSFE_SUPPORT_IPV6" SFE_SUPPORT_IPV6=y,) \
|
||||
$(if $(HAVE_ECM),EXTRA_CFLAGS+="-DCONFIG_SFE_ECM" CONFIG_SFE_ECM=y,) \
|
||||
modules
|
||||
endef
|
||||
|
||||
|
49
package/kernel/shortcut-fe/shortcut-fe/files/etc/init.d/shortcut-fe
Executable file
49
package/kernel/shortcut-fe/shortcut-fe/files/etc/init.d/shortcut-fe
Executable file
@ -0,0 +1,49 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
#
|
||||
# Copyright (c) 2014-2015 The Linux Foundation. All rights reserved.
|
||||
# Permission to use, copy, modify, and/or distribute this software for
|
||||
# any purpose with or without fee is hereby granted, provided that the
|
||||
# above copyright notice and this permission notice appear in all copies.
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
#
|
||||
|
||||
#SFE connection manager has a lower priority, it should be started after other connection manager
|
||||
#to detect the existence of connection manager with higher priority
|
||||
START=99
|
||||
|
||||
have_cm() {
|
||||
[ -d "/sys/kernel/debug/ecm" ] && echo 1 && return
|
||||
|
||||
echo 0
|
||||
}
|
||||
|
||||
#load shortcut-fe and connection manager
|
||||
load_sfe() {
|
||||
local kernel_version=$(uname -r)
|
||||
|
||||
[ -d "/sys/module/shortcut_fe" ] || insmod /lib/modules/$kernel_version/shortcut-fe.ko
|
||||
[ -d "/sys/module/shortcut_fe_ipv6" ] || insmod /lib/modules/$kernel_version/shortcut-fe-ipv6.ko
|
||||
|
||||
[ -e "/lib/modules/$kernel_version/shortcut-fe-cm.ko" ] && {
|
||||
[ -d /sys/module/shortcut_fe_cm ] || insmod /lib/modules/$kernel_version/shortcut-fe-cm.ko
|
||||
}
|
||||
[ -e "/lib/modules/$kernel_version/fast-classifier.ko" ] && {
|
||||
[ -d /sys/module/fast_classifier ] || insmod /lib/modules/$kernel_version/fast-classifier.ko
|
||||
}
|
||||
}
|
||||
|
||||
start() {
|
||||
[ "$(have_cm)" = "0" ] && load_sfe
|
||||
}
|
||||
|
||||
stop() {
|
||||
[ -d "/sys/module/shortcut_fe_drv" ] && rmmod shortcut_fe_drv
|
||||
[ -d "/sys/module/shortcut_fe_cm" ] && rmmod shortcut_fe_cm
|
||||
[ -d "/sys/module/fast_classifier" ] && rmmod fast_classifier
|
||||
}
|
0
package/kernel/shortcut-fe/shortcut-fe/files/usr/bin/sfe_dump
Normal file → Executable file
0
package/kernel/shortcut-fe/shortcut-fe/files/usr/bin/sfe_dump
Normal file → Executable file
@ -21,3 +21,4 @@ endif
|
||||
shortcut-fe-cm-objs := \
|
||||
sfe_cm.o
|
||||
|
||||
ccflags-y += -Werror -Wall
|
||||
|
@ -180,7 +180,7 @@ static inline struct net_device *sfe_dev_get_master(struct net_device *dev)
|
||||
#endif
|
||||
|
||||
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0))
|
||||
#define sfe_dst_get_neighbour(dst, daddr) dst_neigh_lookup(dst, daddr)
|
||||
#define sfe_dst_get_neighbour(dst, daddr) dst_neigh_lookup(dst, addr)
|
||||
#else
|
||||
static inline struct neighbour *
|
||||
sfe_dst_get_neighbour(struct dst_entry *dst, void *daddr)
|
||||
|
@ -2,7 +2,7 @@
|
||||
* sfe-cm.c
|
||||
* Shortcut forwarding engine connection manager.
|
||||
*
|
||||
* Copyright (c) 2013-2018 The Linux Foundation. All rights reserved.
|
||||
* Copyright (c) 2013-2018, 2020 The Linux Foundation. All rights reserved.
|
||||
* Permission to use, copy, modify, and/or distribute this software for
|
||||
* any purpose with or without fee is hereby granted, provided that the
|
||||
* above copyright notice and this permission notice appear in all copies.
|
||||
@ -199,7 +199,7 @@ int sfe_cm_recv(struct sk_buff *skb)
|
||||
* structure, obtain the hardware address. This means this function also
|
||||
* works if the neighbours are routers too.
|
||||
*/
|
||||
static bool sfe_cm_find_dev_and_mac_addr(sfe_ip_addr_t *addr, struct net_device **dev, u8 *mac_addr, int is_v4)
|
||||
static bool sfe_cm_find_dev_and_mac_addr(struct sk_buff *skb, sfe_ip_addr_t *addr, struct net_device **dev, u8 *mac_addr, int is_v4)
|
||||
{
|
||||
struct neighbour *neigh;
|
||||
struct rtable *rt;
|
||||
@ -207,6 +207,15 @@ static bool sfe_cm_find_dev_and_mac_addr(sfe_ip_addr_t *addr, struct net_device
|
||||
struct dst_entry *dst;
|
||||
struct net_device *mac_dev;
|
||||
|
||||
/*
|
||||
* If we have skb provided, use it as the original code is unable
|
||||
* to lookup routes that are policy routed.
|
||||
*/
|
||||
if (unlikely(skb)) {
|
||||
dst = skb_dst(skb);
|
||||
goto skip_dst_lookup;
|
||||
}
|
||||
|
||||
/*
|
||||
* Look up the rtable entry for the IP address then get the hardware
|
||||
* address from its neighbour structure. This means this work when the
|
||||
@ -220,11 +229,11 @@ static bool sfe_cm_find_dev_and_mac_addr(sfe_ip_addr_t *addr, struct net_device
|
||||
|
||||
dst = (struct dst_entry *)rt;
|
||||
} else {
|
||||
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 17, 0))
|
||||
rt6 = rt6_lookup(&init_net, (struct in6_addr *)addr->ip6, 0, 0, NULL, 0);
|
||||
#else
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 17, 0))
|
||||
rt6 = rt6_lookup(&init_net, (struct in6_addr *)addr->ip6, 0, 0, 0);
|
||||
#endif /*KERNEL_VERSION(4, 17, 0)*/
|
||||
#else
|
||||
rt6 = rt6_lookup(&init_net, (struct in6_addr *)addr->ip6, 0, 0, NULL, 0);
|
||||
#endif
|
||||
if (!rt6) {
|
||||
goto ret_fail;
|
||||
}
|
||||
@ -232,18 +241,21 @@ static bool sfe_cm_find_dev_and_mac_addr(sfe_ip_addr_t *addr, struct net_device
|
||||
dst = (struct dst_entry *)rt6;
|
||||
}
|
||||
|
||||
skip_dst_lookup:
|
||||
rcu_read_lock();
|
||||
neigh = sfe_dst_get_neighbour(dst, addr);
|
||||
if (unlikely(!neigh)) {
|
||||
rcu_read_unlock();
|
||||
dst_release(dst);
|
||||
if (likely(!skb))
|
||||
dst_release(dst);
|
||||
goto ret_fail;
|
||||
}
|
||||
|
||||
if (unlikely(!(neigh->nud_state & NUD_VALID))) {
|
||||
rcu_read_unlock();
|
||||
neigh_release(neigh);
|
||||
dst_release(dst);
|
||||
if (likely(!skb))
|
||||
dst_release(dst);
|
||||
goto ret_fail;
|
||||
}
|
||||
|
||||
@ -251,7 +263,8 @@ static bool sfe_cm_find_dev_and_mac_addr(sfe_ip_addr_t *addr, struct net_device
|
||||
if (!mac_dev) {
|
||||
rcu_read_unlock();
|
||||
neigh_release(neigh);
|
||||
dst_release(dst);
|
||||
if (likely(!skb))
|
||||
dst_release(dst);
|
||||
goto ret_fail;
|
||||
}
|
||||
|
||||
@ -261,7 +274,8 @@ static bool sfe_cm_find_dev_and_mac_addr(sfe_ip_addr_t *addr, struct net_device
|
||||
*dev = mac_dev;
|
||||
rcu_read_unlock();
|
||||
neigh_release(neigh);
|
||||
dst_release(dst);
|
||||
if (likely(!skb))
|
||||
dst_release(dst);
|
||||
|
||||
return true;
|
||||
|
||||
@ -291,6 +305,7 @@ static unsigned int sfe_cm_post_routing(struct sk_buff *skb, int is_v4)
|
||||
struct net_device *dest_dev;
|
||||
struct net_device *src_dev_tmp;
|
||||
struct net_device *dest_dev_tmp;
|
||||
struct sk_buff *tmp_skb = NULL;
|
||||
struct net_device *src_br_dev = NULL;
|
||||
struct net_device *dest_br_dev = NULL;
|
||||
struct nf_conntrack_tuple orig_tuple;
|
||||
@ -352,16 +367,18 @@ static unsigned int sfe_cm_post_routing(struct sk_buff *skb, int is_v4)
|
||||
return NF_ACCEPT;
|
||||
}
|
||||
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0))
|
||||
/*
|
||||
* Don't process untracked connections.
|
||||
*/
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0))
|
||||
if (unlikely(nf_ct_is_untracked(ct))) {
|
||||
#else
|
||||
if (unlikely(ctinfo == IP_CT_UNTRACKED)) {
|
||||
#endif
|
||||
sfe_cm_incr_exceptions(SFE_CM_EXCEPTION_CT_NO_TRACK);
|
||||
DEBUG_TRACE("untracked connection\n");
|
||||
return NF_ACCEPT;
|
||||
}
|
||||
#endif /*KERNEL_VERSION(4, 12, 0)*/
|
||||
|
||||
/*
|
||||
* Unconfirmed connection may be dropped by Linux at the final step,
|
||||
@ -510,6 +527,21 @@ static unsigned int sfe_cm_post_routing(struct sk_buff *skb, int is_v4)
|
||||
return NF_ACCEPT;
|
||||
}
|
||||
spin_unlock_bh(&ct->lock);
|
||||
|
||||
/*
|
||||
* Somehow, SFE is not playing nice with IPSec traffic.
|
||||
* Do not accelerate for now.
|
||||
*/
|
||||
if (ntohs(sic.dest_port) == 4500 || ntohs(sic.dest_port) == 500) {
|
||||
if (likely(is_v4))
|
||||
DEBUG_TRACE("IPsec bypass: %pI4:%d(%pI4:%d) to %pI4:%d(%pI4:%d)\n",
|
||||
&sic.src_ip.ip, ntohs(sic.src_port), &sic.src_ip_xlate.ip, ntohs(sic.src_port_xlate),
|
||||
&sic.dest_ip.ip, ntohs(sic.dest_port), &sic.dest_ip_xlate.ip, ntohs(sic.dest_port_xlate));
|
||||
else
|
||||
DEBUG_TRACE("IPsec bypass: %pI6:%d to %pI6:%d\n",
|
||||
&sic.src_ip.ip6, ntohs(sic.src_port), &sic.dest_ip.ip6, ntohs(sic.dest_port));
|
||||
return NF_ACCEPT;
|
||||
}
|
||||
break;
|
||||
|
||||
case IPPROTO_UDP:
|
||||
@ -533,10 +565,10 @@ static unsigned int sfe_cm_post_routing(struct sk_buff *skb, int is_v4)
|
||||
* For packets de-capsulated from xfrm, we still can accelerate it
|
||||
* on the direction we just received the packet.
|
||||
*/
|
||||
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0))
|
||||
if (unlikely(skb_ext_exist(skb, SKB_EXT_SEC_PATH))) {
|
||||
#else
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0))
|
||||
if (unlikely(skb->sp)) {
|
||||
#else
|
||||
if (unlikely(secpath_exists(skb))) {
|
||||
#endif
|
||||
if (sic.protocol == IPPROTO_TCP &&
|
||||
!(sic.flags & SFE_CREATE_FLAG_NO_SEQ_CHECK)) {
|
||||
@ -564,25 +596,27 @@ static unsigned int sfe_cm_post_routing(struct sk_buff *skb, int is_v4)
|
||||
* Get the net device and MAC addresses that correspond to the various source and
|
||||
* destination host addresses.
|
||||
*/
|
||||
if (!sfe_cm_find_dev_and_mac_addr(&sic.src_ip, &src_dev_tmp, sic.src_mac, is_v4)) {
|
||||
if (!sfe_cm_find_dev_and_mac_addr(NULL, &sic.src_ip, &src_dev_tmp, sic.src_mac, is_v4)) {
|
||||
sfe_cm_incr_exceptions(SFE_CM_EXCEPTION_NO_SRC_DEV);
|
||||
return NF_ACCEPT;
|
||||
}
|
||||
src_dev = src_dev_tmp;
|
||||
|
||||
if (!sfe_cm_find_dev_and_mac_addr(&sic.src_ip_xlate, &dev, sic.src_mac_xlate, is_v4)) {
|
||||
if (!sfe_cm_find_dev_and_mac_addr(NULL, &sic.src_ip_xlate, &dev, sic.src_mac_xlate, is_v4)) {
|
||||
sfe_cm_incr_exceptions(SFE_CM_EXCEPTION_NO_SRC_XLATE_DEV);
|
||||
goto done1;
|
||||
}
|
||||
dev_put(dev);
|
||||
|
||||
if (!sfe_cm_find_dev_and_mac_addr(&sic.dest_ip, &dev, sic.dest_mac, is_v4)) {
|
||||
/* Somehow, for IPv6, we need this workaround as well */
|
||||
if (unlikely(!is_v4))
|
||||
tmp_skb = skb;
|
||||
if (!sfe_cm_find_dev_and_mac_addr(tmp_skb, &sic.dest_ip, &dev, sic.dest_mac, is_v4)) {
|
||||
sfe_cm_incr_exceptions(SFE_CM_EXCEPTION_NO_DEST_DEV);
|
||||
goto done1;
|
||||
}
|
||||
dev_put(dev);
|
||||
|
||||
if (!sfe_cm_find_dev_and_mac_addr(&sic.dest_ip_xlate, &dest_dev_tmp, sic.dest_mac_xlate, is_v4)) {
|
||||
if (!sfe_cm_find_dev_and_mac_addr(skb, &sic.dest_ip_xlate, &dest_dev_tmp, sic.dest_mac_xlate, is_v4)) {
|
||||
sfe_cm_incr_exceptions(SFE_CM_EXCEPTION_NO_DEST_XLATE_DEV);
|
||||
goto done1;
|
||||
}
|
||||
@ -688,14 +722,11 @@ static int sfe_cm_conntrack_event(unsigned int events, struct nf_ct_event *item)
|
||||
}
|
||||
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0))
|
||||
/*
|
||||
* If this is an untracked connection then we can't have any state either.
|
||||
*/
|
||||
if (unlikely(nf_ct_is_untracked(ct))) {
|
||||
DEBUG_TRACE("ignoring untracked conn\n");
|
||||
return NOTIFY_DONE;
|
||||
}
|
||||
#endif /*KERNEL_VERSION(4, 12, 0)*/
|
||||
#endif
|
||||
|
||||
/*
|
||||
* We're only interested in destroy events.
|
||||
@ -825,18 +856,17 @@ static void sfe_cm_sync_rule(struct sfe_connection_sync *sis)
|
||||
ct = nf_ct_tuplehash_to_ctrack(h);
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0))
|
||||
NF_CT_ASSERT(ct->timeout.data == (unsigned long)ct);
|
||||
#endif /*KERNEL_VERSION(4, 9, 0)*/
|
||||
|
||||
#endif
|
||||
/*
|
||||
* Only update if this is not a fixed timeout
|
||||
*/
|
||||
if (!test_bit(IPS_FIXED_TIMEOUT_BIT, &ct->status)) {
|
||||
spin_lock_bh(&ct->lock);
|
||||
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0))
|
||||
ct->timeout += sis->delta_jiffies;
|
||||
#else
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0))
|
||||
ct->timeout.expires += sis->delta_jiffies;
|
||||
#endif /*KERNEL_VERSION(4, 9, 0)*/
|
||||
#else
|
||||
ct->timeout += sis->delta_jiffies;
|
||||
#endif
|
||||
spin_unlock_bh(&ct->lock);
|
||||
}
|
||||
|
||||
@ -891,26 +921,26 @@ static void sfe_cm_sync_rule(struct sfe_connection_sync *sis)
|
||||
|
||||
if (reply_pkts != 0) {
|
||||
unsigned int *timeouts;
|
||||
|
||||
struct nf_conntrack_l4proto *l4proto __maybe_unused;
|
||||
set_bit(IPS_SEEN_REPLY_BIT, &ct->status);
|
||||
set_bit(IPS_ASSURED_BIT, &ct->status);
|
||||
|
||||
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0))
|
||||
timeouts = nf_ct_timeout_lookup(ct);
|
||||
#else
|
||||
struct nf_conntrack_l4proto *l4proto;
|
||||
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0))
|
||||
l4proto = __nf_ct_l4proto_find((sis->is_v6 ? AF_INET6 : AF_INET), IPPROTO_UDP);
|
||||
timeouts = nf_ct_timeout_lookup(&init_net, ct, l4proto);
|
||||
#endif /*KERNEL_VERSION(4, 19, 0)*/
|
||||
spin_lock_bh(&ct->lock);
|
||||
ct->timeout.expires = jiffies + timeouts[UDP_CT_REPLIED];
|
||||
spin_unlock_bh(&ct->lock);
|
||||
#else
|
||||
timeouts = nf_ct_timeout_lookup(ct);
|
||||
if (!timeouts) {
|
||||
timeouts = udp_get_timeouts(nf_ct_net(ct));
|
||||
}
|
||||
|
||||
spin_lock_bh(&ct->lock);
|
||||
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0))
|
||||
ct->timeout = jiffies + timeouts[UDP_CT_REPLIED];
|
||||
#else
|
||||
ct->timeout.expires = jiffies + timeouts[UDP_CT_REPLIED];
|
||||
#endif /*KERNEL_VERSION(4, 9, 0)*/
|
||||
spin_unlock_bh(&ct->lock);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -1001,6 +1031,9 @@ static int __init sfe_cm_init(void)
|
||||
{
|
||||
struct sfe_cm *sc = &__sc;
|
||||
int result = -1;
|
||||
#ifdef CONFIG_SFE_ECM
|
||||
int (*fast_recv)(struct sk_buff *skb);
|
||||
#endif
|
||||
|
||||
DEBUG_INFO("SFE CM init\n");
|
||||
|
||||
@ -1036,7 +1069,11 @@ static int __init sfe_cm_init(void)
|
||||
/*
|
||||
* Register our netfilter hooks.
|
||||
*/
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 13, 0))
|
||||
result = nf_register_hooks(sfe_cm_ops_post_routing, ARRAY_SIZE(sfe_cm_ops_post_routing));
|
||||
#else
|
||||
result = nf_register_net_hooks(&init_net, sfe_cm_ops_post_routing, ARRAY_SIZE(sfe_cm_ops_post_routing));
|
||||
#endif
|
||||
if (result < 0) {
|
||||
DEBUG_ERROR("can't register nf post routing hook: %d\n", result);
|
||||
goto exit3;
|
||||
@ -1049,22 +1086,30 @@ static int __init sfe_cm_init(void)
|
||||
*/
|
||||
#ifdef CONFIG_NF_CONNTRACK_EVENTS
|
||||
#ifdef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
|
||||
(void)nf_conntrack_register_chain_notifier(&init_net, &sfe_cm_conntrack_notifier);
|
||||
result = nf_conntrack_register_chain_notifier(&init_net, &sfe_cm_conntrack_notifier);
|
||||
#else
|
||||
result = nf_conntrack_register_notifier(&init_net, &sfe_cm_conntrack_notifier);
|
||||
#endif
|
||||
if (result < 0) {
|
||||
DEBUG_ERROR("can't register nf notifier hook: %d\n", result);
|
||||
goto exit4;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
spin_lock_init(&sc->lock);
|
||||
|
||||
/*
|
||||
* Hook the receive path in the network stack.
|
||||
*/
|
||||
#ifdef CONFIG_SFE_ECM
|
||||
rcu_read_lock();
|
||||
fast_recv = rcu_dereference(athrs_fast_nat_recv);
|
||||
rcu_read_unlock();
|
||||
if (!fast_recv) {
|
||||
BUG_ON(athrs_fast_nat_recv);
|
||||
}
|
||||
#else
|
||||
BUG_ON(athrs_fast_nat_recv);
|
||||
#endif
|
||||
RCU_INIT_POINTER(athrs_fast_nat_recv, sfe_cm_recv);
|
||||
|
||||
/*
|
||||
@ -1075,10 +1120,15 @@ static int __init sfe_cm_init(void)
|
||||
return 0;
|
||||
|
||||
#ifdef CONFIG_NF_CONNTRACK_EVENTS
|
||||
#ifndef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
|
||||
exit4:
|
||||
#ifdef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 13, 0))
|
||||
nf_unregister_hooks(sfe_cm_ops_post_routing, ARRAY_SIZE(sfe_cm_ops_post_routing));
|
||||
#else
|
||||
nf_unregister_net_hooks(&init_net, sfe_cm_ops_post_routing, ARRAY_SIZE(sfe_cm_ops_post_routing));
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
exit3:
|
||||
unregister_inet6addr_notifier(&sc->inet6_notifier);
|
||||
@ -1129,8 +1179,12 @@ static void __exit sfe_cm_exit(void)
|
||||
nf_conntrack_unregister_notifier(&init_net, &sfe_cm_conntrack_notifier);
|
||||
#endif
|
||||
#endif
|
||||
nf_unregister_net_hooks(&init_net, sfe_cm_ops_post_routing, ARRAY_SIZE(sfe_cm_ops_post_routing));
|
||||
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 13, 0))
|
||||
nf_unregister_hooks(sfe_cm_ops_post_routing, ARRAY_SIZE(sfe_cm_ops_post_routing));
|
||||
#else
|
||||
nf_unregister_net_hooks(&init_net, sfe_cm_ops_post_routing, ARRAY_SIZE(sfe_cm_ops_post_routing));
|
||||
#endif
|
||||
unregister_inet6addr_notifier(&sc->inet6_notifier);
|
||||
unregister_inetaddr_notifier(&sc->inet_notifier);
|
||||
unregister_netdevice_notifier(&sc->dev_notifier);
|
||||
|
@ -2,7 +2,7 @@
|
||||
* sfe_ipv4.c
|
||||
* Shortcut forwarding engine - IPv4 edition.
|
||||
*
|
||||
* Copyright (c) 2013-2016, 2019, The Linux Foundation. All rights reserved.
|
||||
* Copyright (c) 2013-2016, 2019-2020 The Linux Foundation. All rights reserved.
|
||||
* Permission to use, copy, modify, and/or distribute this software for
|
||||
* any purpose with or without fee is hereby granted, provided that the
|
||||
* above copyright notice and this permission notice appear in all copies.
|
||||
@ -1311,14 +1311,13 @@ static int sfe_ipv4_recv_udp(struct sfe_ipv4 *si, struct sk_buff *skb, struct ne
|
||||
* change the cloned skb's data section.
|
||||
*/
|
||||
if (unlikely(skb_cloned(skb))) {
|
||||
DEBUG_TRACE("%p: skb is a cloned skb\n", skb);
|
||||
DEBUG_TRACE("%px: skb is a cloned skb\n", skb);
|
||||
skb = skb_unshare(skb, GFP_ATOMIC);
|
||||
if (!skb) {
|
||||
DEBUG_WARN("Failed to unshare the cloned skb\n");
|
||||
si->exception_events[SFE_IPV4_EXCEPTION_EVENT_CLONED_SKB_UNSHARE_ERROR]++;
|
||||
si->packets_not_forwarded++;
|
||||
spin_unlock_bh(&si->lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1891,14 +1890,13 @@ static int sfe_ipv4_recv_tcp(struct sfe_ipv4 *si, struct sk_buff *skb, struct ne
|
||||
* change the cloned skb's data section.
|
||||
*/
|
||||
if (unlikely(skb_cloned(skb))) {
|
||||
DEBUG_TRACE("%p: skb is a cloned skb\n", skb);
|
||||
DEBUG_TRACE("%px: skb is a cloned skb\n", skb);
|
||||
skb = skb_unshare(skb, GFP_ATOMIC);
|
||||
if (!skb) {
|
||||
DEBUG_WARN("Failed to unshare the cloned skb\n");
|
||||
si->exception_events[SFE_IPV4_EXCEPTION_EVENT_CLONED_SKB_UNSHARE_ERROR]++;
|
||||
si->packets_not_forwarded++;
|
||||
spin_unlock_bh(&si->lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -2512,7 +2510,7 @@ int sfe_ipv4_create_rule(struct sfe_connection_create *sic)
|
||||
spin_unlock_bh(&si->lock);
|
||||
|
||||
DEBUG_TRACE("connection already exists - mark: %08x, p: %d\n"
|
||||
" s: %s:%pM:%pI4:%u, d: %s:%pM:%pI4:%u\n",
|
||||
" s: %s:%pxM:%pI4:%u, d: %s:%pxM:%pI4:%u\n",
|
||||
sic->mark, sic->protocol,
|
||||
sic->src_dev->name, sic->src_mac, &sic->src_ip.ip, ntohs(sic->src_port),
|
||||
sic->dest_dev->name, sic->dest_mac, &sic->dest_ip.ip, ntohs(sic->dest_port));
|
||||
@ -2728,8 +2726,8 @@ int sfe_ipv4_create_rule(struct sfe_connection_create *sic)
|
||||
* We have everything we need!
|
||||
*/
|
||||
DEBUG_INFO("new connection - mark: %08x, p: %d\n"
|
||||
" s: %s:%pM(%pM):%pI4(%pI4):%u(%u)\n"
|
||||
" d: %s:%pM(%pM):%pI4(%pI4):%u(%u)\n",
|
||||
" s: %s:%pxM(%pxM):%pI4(%pI4):%u(%u)\n"
|
||||
" d: %s:%pxM(%pxM):%pI4(%pI4):%u(%u)\n",
|
||||
sic->mark, sic->protocol,
|
||||
sic->src_dev->name, sic->src_mac, sic->src_mac_xlate,
|
||||
&sic->src_ip.ip, &sic->src_ip_xlate.ip, ntohs(sic->src_port), ntohs(sic->src_port_xlate),
|
||||
@ -2858,17 +2856,17 @@ another_round:
|
||||
/*
|
||||
* sfe_ipv4_periodic_sync()
|
||||
*/
|
||||
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0))
|
||||
static void sfe_ipv4_periodic_sync(struct timer_list *arg)
|
||||
#else
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0))
|
||||
static void sfe_ipv4_periodic_sync(unsigned long arg)
|
||||
#endif /*KERNEL_VERSION(4, 15, 0)*/
|
||||
{
|
||||
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0))
|
||||
struct sfe_ipv4 *si = (struct sfe_ipv4 *)arg->cust_data;
|
||||
#else
|
||||
static void sfe_ipv4_periodic_sync(struct timer_list *tl)
|
||||
#endif
|
||||
{
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0))
|
||||
struct sfe_ipv4 *si = (struct sfe_ipv4 *)arg;
|
||||
#endif /*KERNEL_VERSION(4, 15, 0)*/
|
||||
#else
|
||||
struct sfe_ipv4 *si = from_timer(si, tl, timer);
|
||||
#endif
|
||||
u64 now_jiffies;
|
||||
int quota;
|
||||
sfe_sync_rule_callback_t sync_rule_callback;
|
||||
@ -3547,12 +3545,11 @@ static int __init sfe_ipv4_init(void)
|
||||
/*
|
||||
* Create a timer to handle periodic statistics.
|
||||
*/
|
||||
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0))
|
||||
timer_setup(&si->timer, sfe_ipv4_periodic_sync, 0);
|
||||
si->timer.cust_data = (unsigned long)si;
|
||||
#else
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0))
|
||||
setup_timer(&si->timer, sfe_ipv4_periodic_sync, (unsigned long)si);
|
||||
#endif /*KERNEL_VERSION(4, 15, 0)*/
|
||||
#else
|
||||
timer_setup(&si->timer, sfe_ipv4_periodic_sync, 0);
|
||||
#endif
|
||||
mod_timer(&si->timer, jiffies + ((HZ + 99) / 100));
|
||||
|
||||
spin_lock_init(&si->lock);
|
||||
|
@ -2,7 +2,7 @@
|
||||
* sfe_ipv6.c
|
||||
* Shortcut forwarding engine - IPv6 support.
|
||||
*
|
||||
* Copyright (c) 2015-2016, 2019, The Linux Foundation. All rights reserved.
|
||||
* Copyright (c) 2015-2016, 2019-2020 The Linux Foundation. All rights reserved.
|
||||
* Permission to use, copy, modify, and/or distribute this software for
|
||||
* any purpose with or without fee is hereby granted, provided that the
|
||||
* above copyright notice and this permission notice appear in all copies.
|
||||
@ -1369,14 +1369,13 @@ static int sfe_ipv6_recv_udp(struct sfe_ipv6 *si, struct sk_buff *skb, struct ne
|
||||
* change the cloned skb's data section.
|
||||
*/
|
||||
if (unlikely(skb_cloned(skb))) {
|
||||
DEBUG_TRACE("%p: skb is a cloned skb\n", skb);
|
||||
DEBUG_TRACE("%px: skb is a cloned skb\n", skb);
|
||||
skb = skb_unshare(skb, GFP_ATOMIC);
|
||||
if (!skb) {
|
||||
DEBUG_WARN("Failed to unshare the cloned skb\n");
|
||||
si->exception_events[SFE_IPV6_EXCEPTION_EVENT_CLONED_SKB_UNSHARE_ERROR]++;
|
||||
si->packets_not_forwarded++;
|
||||
spin_unlock_bh(&si->lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1929,14 +1928,13 @@ static int sfe_ipv6_recv_tcp(struct sfe_ipv6 *si, struct sk_buff *skb, struct ne
|
||||
* change the cloned skb's data section.
|
||||
*/
|
||||
if (unlikely(skb_cloned(skb))) {
|
||||
DEBUG_TRACE("%p: skb is a cloned skb\n", skb);
|
||||
DEBUG_TRACE("%px: skb is a cloned skb\n", skb);
|
||||
skb = skb_unshare(skb, GFP_ATOMIC);
|
||||
if (!skb) {
|
||||
DEBUG_WARN("Failed to unshare the cloned skb\n");
|
||||
si->exception_events[SFE_IPV6_EXCEPTION_EVENT_CLONED_SKB_UNSHARE_ERROR]++;
|
||||
si->packets_not_forwarded++;
|
||||
spin_unlock_bh(&si->lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -2328,7 +2326,7 @@ int sfe_ipv6_recv(struct net_device *dev, struct sk_buff *skb)
|
||||
si->packets_not_forwarded++;
|
||||
spin_unlock_bh(&si->lock);
|
||||
|
||||
DEBUG_TRACE("payload_len: %u, exceeds len: %u\n", payload_len, (len - sizeof(struct sfe_ipv6_ip_hdr)));
|
||||
DEBUG_TRACE("payload_len: %u, exceeds len: %u\n", payload_len, (len - (unsigned int)sizeof(struct sfe_ipv6_ip_hdr)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -2526,7 +2524,7 @@ int sfe_ipv6_create_rule(struct sfe_connection_create *sic)
|
||||
spin_unlock_bh(&si->lock);
|
||||
|
||||
DEBUG_TRACE("connection already exists - mark: %08x, p: %d\n"
|
||||
" s: %s:%pM:%pI6:%u, d: %s:%pM:%pI6:%u\n",
|
||||
" s: %s:%pxM:%pI6:%u, d: %s:%pxM:%pI6:%u\n",
|
||||
sic->mark, sic->protocol,
|
||||
sic->src_dev->name, sic->src_mac, sic->src_ip.ip6, ntohs(sic->src_port),
|
||||
sic->dest_dev->name, sic->dest_mac, sic->dest_ip.ip6, ntohs(sic->dest_port));
|
||||
@ -2742,8 +2740,8 @@ int sfe_ipv6_create_rule(struct sfe_connection_create *sic)
|
||||
* We have everything we need!
|
||||
*/
|
||||
DEBUG_INFO("new connection - mark: %08x, p: %d\n"
|
||||
" s: %s:%pM(%pM):%pI6(%pI6):%u(%u)\n"
|
||||
" d: %s:%pM(%pM):%pI6(%pI6):%u(%u)\n",
|
||||
" s: %s:%pxM(%pxM):%pI6(%pI6):%u(%u)\n"
|
||||
" d: %s:%pxM(%pxM):%pI6(%pI6):%u(%u)\n",
|
||||
sic->mark, sic->protocol,
|
||||
sic->src_dev->name, sic->src_mac, sic->src_mac_xlate,
|
||||
sic->src_ip.ip6, sic->src_ip_xlate.ip6, ntohs(sic->src_port), ntohs(sic->src_port_xlate),
|
||||
@ -2866,17 +2864,17 @@ another_round:
|
||||
/*
|
||||
* sfe_ipv6_periodic_sync()
|
||||
*/
|
||||
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0))
|
||||
static void sfe_ipv6_periodic_sync(struct timer_list *arg)
|
||||
#else
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0))
|
||||
static void sfe_ipv6_periodic_sync(unsigned long arg)
|
||||
#endif /*KERNEL_VERSION(4, 15, 0)*/
|
||||
{
|
||||
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0))
|
||||
struct sfe_ipv6 *si = (struct sfe_ipv6 *)arg->cust_data;
|
||||
#else
|
||||
static void sfe_ipv6_periodic_sync(struct timer_list *tl)
|
||||
#endif
|
||||
{
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0))
|
||||
struct sfe_ipv6 *si = (struct sfe_ipv6 *)arg;
|
||||
#endif /*KERNEL_VERSION(4, 15, 0)*/
|
||||
#else
|
||||
struct sfe_ipv6 *si = from_timer(si, tl, timer);
|
||||
#endif
|
||||
u64 now_jiffies;
|
||||
int quota;
|
||||
sfe_sync_rule_callback_t sync_rule_callback;
|
||||
@ -3555,12 +3553,11 @@ static int __init sfe_ipv6_init(void)
|
||||
/*
|
||||
* Create a timer to handle periodic statistics.
|
||||
*/
|
||||
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0))
|
||||
timer_setup(&si->timer, sfe_ipv6_periodic_sync, 0);
|
||||
si->timer.cust_data = (unsigned long)si;
|
||||
#else
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0))
|
||||
setup_timer(&si->timer, sfe_ipv6_periodic_sync, (unsigned long)si);
|
||||
#endif /*KERNEL_VERSION(4, 15, 0)*/
|
||||
#else
|
||||
timer_setup(&si->timer, sfe_ipv6_periodic_sync, 0);
|
||||
#endif
|
||||
mod_timer(&si->timer, jiffies + ((HZ + 99) / 100));
|
||||
|
||||
spin_lock_init(&si->lock);
|
||||
|
60
package/kernel/shortcut-fe/simulated-driver/Makefile
Normal file
60
package/kernel/shortcut-fe/simulated-driver/Makefile
Normal file
@ -0,0 +1,60 @@
|
||||
#
|
||||
# Copyright (c) 2015,2016 The Linux Foundation. All rights reserved.
|
||||
# Permission to use, copy, modify, and/or distribute this software for
|
||||
# any purpose with or without fee is hereby granted, provided that the
|
||||
# above copyright notice and this permission notice appear in all copies.
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
include $(INCLUDE_DIR)/kernel.mk
|
||||
|
||||
PKG_NAME:=shortcut-fe-simulated-driver
|
||||
PKG_RELEASE:=1
|
||||
PKG_CONFIG_DEPENDS := CONFIG_IPV6
|
||||
|
||||
PKG_SOURCE_URL:=https://source.codeaurora.org/quic/qsdk/oss/lklm/shortcut-fe
|
||||
PKG_SOURCE_PROTO:=git
|
||||
PKG_SOURCE_DATE:=2021-03-17
|
||||
PKG_SOURCE_VERSION:=697977d8d0ccf0ab596e5692d08608a75dd7f33d
|
||||
PKG_MIRROR_HASH:=659fa82a431e15af797a6c7069faeee02810453ad8b576c51c29f95a1761a045
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define KernelPackage/shortcut-fe-drv
|
||||
SECTION:=kernel
|
||||
CATEGORY:=Kernel modules
|
||||
SUBMENU:=Network Support
|
||||
DEPENDS:=@TARGET_ipq806x||TARGET_ipq807x +kmod-shortcut-fe
|
||||
KCONFIG:=CONFIG_NET_CLS_ACT=y \
|
||||
CONFIG_XFRM=y
|
||||
TITLE:=Simulated sfe driver for ECM
|
||||
FILES:=$(PKG_BUILD_DIR)/simulated-driver/shortcut-fe-drv.ko
|
||||
endef
|
||||
|
||||
define KernelPackage/shortcut-fe-drv/Description
|
||||
Simulated sfe driver which act as an adapter to convert message between a connection manager and the SFE core engine.
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
$(MAKE) $(PKG_JOBS) -C "$(LINUX_DIR)" \
|
||||
$(KERNEL_MAKE_FLAGS) \
|
||||
$(PKG_MAKE_FLAGS) \
|
||||
M="$(PKG_BUILD_DIR)/simulated-driver" \
|
||||
$(if $(CONFIG_IPV6),EXTRA_CFLAGS+="-DSFE_SUPPORT_IPV6" SFE_SUPPORT_IPV6=y,) \
|
||||
EXTRA_CFLAGS="$(EXTRA_CFLAGS)" \
|
||||
modules
|
||||
endef
|
||||
|
||||
define Build/InstallDev
|
||||
$(INSTALL_DIR) $(1)/usr/include/shortcut-fe
|
||||
$(CP) -rf $(PKG_BUILD_DIR)/simulated-driver/sfe_drv.h $(1)/usr/include/shortcut-fe
|
||||
endef
|
||||
|
||||
$(eval $(call KernelPackage,shortcut-fe-drv))
|
@ -0,0 +1,11 @@
|
||||
--- ./simulated-driver/sfe_drv.c.orig 2020-06-16 12:49:47.680153371 +0800
|
||||
+++ ./simulated-driver/sfe_drv.c 2020-06-16 12:50:18.540153371 +0800
|
||||
@@ -1167,7 +1167,7 @@ int sfe_drv_recv(struct sk_buff *skb)
|
||||
* If ingress Qdisc configured, and packet not processed by ingress Qdisc yet
|
||||
* We can not accelerate this packet.
|
||||
*/
|
||||
- if (dev->ingress_queue && !(skb->tc_verd & TC_NCLS)) {
|
||||
+ if (dev->ingress_queue && !(skb->tc_verd_qca_nss & TC_NCLS)) {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
@ -0,0 +1,34 @@
|
||||
From ba041eb8000e4a8f556ca641335894f7e7429dbb Mon Sep 17 00:00:00 2001
|
||||
From: Ailick <277498654@qq.com>
|
||||
Date: Sat, 21 Aug 2021 17:12:22 +0800
|
||||
Subject: [PATCH] net: patch linux kernel to support shortcut-fe-cm
|
||||
|
||||
---
|
||||
nf_conntrack_proto_udp.c | 3 ++-
|
||||
nf_conntrack_timeout.h | 2 +
|
||||
1 file changed, 2 insertion(+)
|
||||
|
||||
--- a/include/net/netfilter/nf_conntrack_timeout.h
|
||||
+++ b/include/net/netfilter/nf_conntrack_timeout.h
|
||||
@@ -124,4 +124,6 @@ extern struct nf_ct_timeout *(*nf_ct_tim
|
||||
extern void (*nf_ct_timeout_put_hook)(struct nf_ct_timeout *timeout);
|
||||
#endif
|
||||
|
||||
+extern unsigned int *udp_get_timeouts(struct net *net);
|
||||
+
|
||||
#endif /* _NF_CONNTRACK_TIMEOUT_H */
|
||||
--- a/net/netfilter/nf_conntrack_proto_udp.c
|
||||
+++ b/net/netfilter/nf_conntrack_proto_udp.c
|
||||
@@ -29,10 +29,11 @@ static const unsigned int udp_timeouts[U
|
||||
[UDP_CT_REPLIED] = 120*HZ,
|
||||
};
|
||||
|
||||
-static unsigned int *udp_get_timeouts(struct net *net)
|
||||
+unsigned int *udp_get_timeouts(struct net *net)
|
||||
{
|
||||
return nf_udp_pernet(net)->timeouts;
|
||||
}
|
||||
+EXPORT_SYMBOL(udp_get_timeouts);
|
||||
|
||||
static void udp_error_log(const struct sk_buff *skb,
|
||||
const struct nf_hook_state *state,
|
@ -49,7 +49,7 @@
|
||||
int (*fcn)(unsigned int events, struct nf_ct_event *item);
|
||||
--- a/net/bridge/br_if.c
|
||||
+++ b/net/bridge/br_if.c
|
||||
@@ -746,6 +746,28 @@ void br_port_flags_change(struct net_bri
|
||||
@@ -763,6 +763,28 @@ void br_port_flags_change(struct net_bri
|
||||
br_recalculate_neigh_suppress_enabled(br);
|
||||
}
|
||||
|
||||
@ -78,10 +78,9 @@
|
||||
bool br_port_flag_is_set(const struct net_device *dev, unsigned long flag)
|
||||
{
|
||||
struct net_bridge_port *p;
|
||||
|
||||
--- a/net/core/dev.c
|
||||
+++ b/net/core/dev.c
|
||||
@@ -3189,8 +3189,17 @@ static int xmit_one(struct sk_buff *skb, struct net_device *dev,
|
||||
@@ -3218,8 +3218,17 @@ static int xmit_one(struct sk_buff *skb,
|
||||
unsigned int len;
|
||||
int rc;
|
||||
|
||||
@ -99,7 +98,7 @@
|
||||
|
||||
#ifdef CONFIG_ETHERNET_PACKET_MANGLE
|
||||
if (!dev->eth_mangle_tx ||
|
||||
@@ -4683,6 +4691,11 @@ void netdev_rx_handler_unregister(struct
|
||||
@@ -4754,6 +4763,11 @@ void netdev_rx_handler_unregister(struct
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(netdev_rx_handler_unregister);
|
||||
|
||||
@ -111,18 +110,18 @@
|
||||
/*
|
||||
* Limit the use of PFMEMALLOC reserves to those protocols that implement
|
||||
* the special handling of PFMEMALLOC skbs.
|
||||
@@ -4733,6 +4746,10 @@ static int __netif_receive_skb_core(stru
|
||||
@@ -4803,6 +4817,10 @@ static int __netif_receive_skb_core(stru
|
||||
bool deliver_exact = false;
|
||||
int ret = NET_RX_DROP;
|
||||
__be16 type;
|
||||
|
||||
+
|
||||
+#ifdef CONFIG_SHORTCUT_FE
|
||||
+ int (*fast_recv)(struct sk_buff *skb);
|
||||
+#endif
|
||||
+
|
||||
net_timestamp_check(!netdev_tstamp_prequeue, skb);
|
||||
|
||||
trace_netif_receive_skb(skb);
|
||||
@@ -4772,6 +4789,16 @@ another_round:
|
||||
net_timestamp_check(!READ_ONCE(netdev_tstamp_prequeue), skb);
|
||||
|
||||
@@ -4843,6 +4861,16 @@ another_round:
|
||||
goto out;
|
||||
}
|
||||
|
||||
@ -172,7 +171,7 @@
|
||||
static int nf_ct_tcp_loose __read_mostly = 1;
|
||||
--- a/net/netfilter/nf_conntrack_ecache.c
|
||||
+++ b/net/netfilter/nf_conntrack_ecache.c
|
||||
@@ -162,7 +162,11 @@ int nf_conntrack_eventmask_report(unsigned int eventmask, struct nf_conn *ct,
|
||||
@@ -162,7 +162,11 @@ int nf_conntrack_eventmask_report(unsign
|
||||
|
||||
rcu_read_lock();
|
||||
notify = rcu_dereference(net->ct.nf_conntrack_event_cb);
|
||||
@ -184,7 +183,7 @@
|
||||
goto out_unlock;
|
||||
|
||||
e = nf_ct_ecache_find(ct);
|
||||
@@ -181,7 +185,14 @@ int nf_conntrack_eventmask_report(unsigned int eventmask, struct nf_conn *ct,
|
||||
@@ -181,7 +185,14 @@ int nf_conntrack_eventmask_report(unsign
|
||||
if (!((eventmask | missed) & e->ctmask))
|
||||
goto out_unlock;
|
||||
|
||||
@ -199,7 +198,7 @@
|
||||
if (unlikely(ret < 0 || missed)) {
|
||||
spin_lock_bh(&ct->lock);
|
||||
if (ret < 0) {
|
||||
@@ -263,7 +274,11 @@ void nf_ct_deliver_cached_events(struct nf_conn *ct)
|
||||
@@ -263,7 +274,11 @@ void nf_ct_deliver_cached_events(struct
|
||||
|
||||
rcu_read_lock();
|
||||
notify = rcu_dereference(net->ct.nf_conntrack_event_cb);
|
||||
@ -211,7 +210,7 @@
|
||||
goto out_unlock;
|
||||
|
||||
e = nf_ct_ecache_find(ct);
|
||||
@@ -287,7 +302,15 @@ void nf_ct_deliver_cached_events(struct nf_conn *ct)
|
||||
@@ -287,7 +302,15 @@ void nf_ct_deliver_cached_events(struct
|
||||
item.portid = 0;
|
||||
item.report = 0;
|
||||
|
||||
@ -227,9 +226,9 @@
|
||||
|
||||
if (likely(ret == 0 && !missed))
|
||||
goto out_unlock;
|
||||
@@ -340,6 +363,11 @@ int nf_conntrack_register_notifier(struct net *net, struct notifier_block *nb)
|
||||
@@ -340,6 +363,11 @@ int nf_conntrack_register_notifier(struc
|
||||
{
|
||||
return atomic_notifier_chain_register(&net->ct.nf_conntrack_chain, nb);
|
||||
return atomic_notifier_chain_register(&net->ct.nf_conntrack_chain, nb);
|
||||
}
|
||||
+int nf_conntrack_register_chain_notifier(struct net *net, struct notifier_block *nb)
|
||||
+{
|
||||
@ -239,7 +238,7 @@
|
||||
#else
|
||||
int nf_conntrack_register_notifier(struct net *net,
|
||||
struct nf_ct_event_notifier *new)
|
||||
@@ -369,6 +397,11 @@ int nf_conntrack_unregister_notifier(struct net *net, struct notifier_block *nb)
|
||||
@@ -369,6 +397,11 @@ int nf_conntrack_unregister_notifier(str
|
||||
{
|
||||
return atomic_notifier_chain_unregister(&net->ct.nf_conntrack_chain, nb);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user