diff --git a/data-ipa-cfg-mgr/hal/Android.bp b/data-ipa-cfg-mgr/hal/Android.bp new file mode 100644 index 00000000..14d37457 --- /dev/null +++ b/data-ipa-cfg-mgr/hal/Android.bp @@ -0,0 +1,26 @@ +cc_library_shared { + name: "liboffloadhal", + srcs: [ + "src/CtUpdateAmbassador.cpp", + "src/HAL.cpp", + "src/IpaEventRelay.cpp", + "src/LocalLogBuffer.cpp", + "src/OffloadStatistics.cpp", + "src/PrefixParser.cpp", + ], + + shared_libs: [ + "libhidlbase", + "liblog", + "libcutils", + "libdl", + "libbase", + "libutils", + "libhardware_legacy", + "libhardware", + "android.hardware.tetheroffload.config@1.0", + "android.hardware.tetheroffload.control@1.0", + ], + export_include_dirs: ["inc"], + vendor: true, +} diff --git a/data-ipa-cfg-mgr/hal/Android.mk b/data-ipa-cfg-mgr/hal/Android.mk deleted file mode 100644 index 6ebca469..00000000 --- a/data-ipa-cfg-mgr/hal/Android.mk +++ /dev/null @@ -1,31 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) -LOCAL_ARM_MODE := arm -LOCAL_SRC_FILES := src/CtUpdateAmbassador.cpp \ - src/HAL.cpp \ - src/IpaEventRelay.cpp \ - src/LocalLogBuffer.cpp \ - src/OffloadStatistics.cpp \ - src/PrefixParser.cpp -LOCAL_C_INCLUDES := $(LOCAL_PATH)/inc -LOCAL_MODULE := liboffloadhal - -#LOCAL_CPP_FLAGS := -Wall -Werror -LOCAL_SHARED_LIBRARIES := libhwbinder \ - libhidlbase \ - libhidltransport \ - liblog \ - libcutils \ - libdl \ - libbase \ - libutils \ - libhardware_legacy \ - libhardware \ - android.hardware.tetheroffload.config@1.0 \ - android.hardware.tetheroffload.control@1.0 -LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/inc -LOCAL_VENDOR_MODULE := true -LOCAL_MODULE_PATH_32 := $(TARGET_OUT_VENDOR)/lib -LOCAL_MODULE_PATH_64 := $(TARGET_OUT_VENDOR)/lib64 -include $(BUILD_SHARED_LIBRARY) diff --git a/data-ipa-cfg-mgr/hal/inc/HAL.h b/data-ipa-cfg-mgr/hal/inc/HAL.h index 894438f1..92ec1358 100644 --- a/data-ipa-cfg-mgr/hal/inc/HAL.h +++ b/data-ipa-cfg-mgr/hal/inc/HAL.h @@ -123,7 +123,7 @@ public: * Yet, a major version update, would not be backwards compatible. This means that a 2.x HAL * could not linked into the same IPACM code base as a 1.x HAL. */ - static HAL* makeIPAHAL(int /* version */, IOffloadManager* /* mgr */); + static Return<::android::sp> makeIPAHAL(int /* version */, IOffloadManager* /* mgr */); /* IOffloadConfig */ Return setHandles( diff --git a/data-ipa-cfg-mgr/hal/src/CtUpdateAmbassador.cpp b/data-ipa-cfg-mgr/hal/src/CtUpdateAmbassador.cpp index b5e60e28..eba6b930 100644 --- a/data-ipa-cfg-mgr/hal/src/CtUpdateAmbassador.cpp +++ b/data-ipa-cfg-mgr/hal/src/CtUpdateAmbassador.cpp @@ -33,7 +33,7 @@ /* External Includes */ #include -#include +#include /* HIDL Includes */ #include diff --git a/data-ipa-cfg-mgr/hal/src/HAL.cpp b/data-ipa-cfg-mgr/hal/src/HAL.cpp index 2d8ff2fd..f18767a5 100644 --- a/data-ipa-cfg-mgr/hal/src/HAL.cpp +++ b/data-ipa-cfg-mgr/hal/src/HAL.cpp @@ -39,7 +39,7 @@ #include /* External Includes */ -#include +#include #include #include #include @@ -62,7 +62,7 @@ using ::std::vector; /* ------------------------------ PUBLIC ------------------------------------ */ -HAL* HAL::makeIPAHAL(int version, IOffloadManager* mgr) { +Return<::android::sp> HAL::makeIPAHAL(int version, IOffloadManager* mgr) { android::hardware::ProcessState::initWithMmapSize((size_t)(2 * KERNEL_PAGE)); if (DBG) @@ -70,7 +70,7 @@ HAL* HAL::makeIPAHAL(int version, IOffloadManager* mgr) { (mgr != nullptr) ? "provided" : "null"); if (nullptr == mgr) return NULL; else if (version != 1) return NULL; - HAL* ret = new HAL(mgr); + ::android::sp ret = new HAL(mgr); if (nullptr == ret) return NULL; configureRpcThreadpool(1, false); ret->registerAsSystemService("ipacm"); @@ -86,7 +86,7 @@ HAL::HAL(IOffloadManager* mgr) : mLogs("HAL Function Calls", 50) { mCbCt = nullptr; } /* HAL */ -void HAL::registerAsSystemService(const char* name __unused) { +void HAL::registerAsSystemService(const char* name) { status_t ret = 0; ret = IOffloadControl::registerAsService(); diff --git a/data-ipa-cfg-mgr/hal/src/IpaEventRelay.cpp b/data-ipa-cfg-mgr/hal/src/IpaEventRelay.cpp index 484355a5..137092fb 100644 --- a/data-ipa-cfg-mgr/hal/src/IpaEventRelay.cpp +++ b/data-ipa-cfg-mgr/hal/src/IpaEventRelay.cpp @@ -28,7 +28,7 @@ */ #define LOG_TAG "IPAHALService/IpaEventRelay" /* External Includes */ -#include +#include /* HIDL Includes */ #include diff --git a/data-ipa-cfg-mgr/hal/src/LocalLogBuffer.cpp b/data-ipa-cfg-mgr/hal/src/LocalLogBuffer.cpp index 50fa91ce..f556e40c 100644 --- a/data-ipa-cfg-mgr/hal/src/LocalLogBuffer.cpp +++ b/data-ipa-cfg-mgr/hal/src/LocalLogBuffer.cpp @@ -29,7 +29,7 @@ #define LOG_TAG "IPAHALService/dump" /* External Includes */ -#include +#include #include #include #include diff --git a/data-ipa-cfg-mgr/ipacm/Android.bp b/data-ipa-cfg-mgr/ipacm/Android.bp new file mode 100644 index 00000000..0ce21f79 --- /dev/null +++ b/data-ipa-cfg-mgr/ipacm/Android.bp @@ -0,0 +1,72 @@ + +cc_binary { + name: "ipacm", + + local_include_dirs: ["src"] + ["inc"], + header_libs: ["qti_kernel_headers"], + + cflags: ["-v"] + ["-DFEATURE_IPA_ANDROID"] + ["-DFEATURE_IPACM_RESTART"] + [ + "-DFEATURE_IPACM_HAL", + "-DDEBUG", + "-Wall", + "-Werror", + "-Wno-error=macro-redefined", + ], + + srcs: [ + "src/IPACM_Main.cpp", + "src/IPACM_EvtDispatcher.cpp", + "src/IPACM_Config.cpp", + "src/IPACM_CmdQueue.cpp", + "src/IPACM_Filtering.cpp", + "src/IPACM_Routing.cpp", + "src/IPACM_Header.cpp", + "src/IPACM_Lan.cpp", + "src/IPACM_Iface.cpp", + "src/IPACM_Wlan.cpp", + "src/IPACM_Wan.cpp", + "src/IPACM_IfaceManager.cpp", + "src/IPACM_Neighbor.cpp", + "src/IPACM_Netlink.cpp", + "src/IPACM_Xml.cpp", + "src/IPACM_Conntrack_NATApp.cpp", + "src/IPACM_ConntrackClient.cpp", + "src/IPACM_ConntrackListener.cpp", + "src/IPACM_Log.cpp", + "src/IPACM_OffloadManager.cpp", + "src/IPACM_LanToLan.cpp", + ], + + init_rc: ["src/ipacm.rc"], + clang: true, + vendor: true, + + shared_libs: [ + "liboffloadhal", + "libipanat", + "libxml2", + "libnfnetlink", + "libnetfilter_conntrack", + "libhidlbase", + "liblog", + "libcutils", + "libdl", + "libbase", + "libutils", + "libhardware_legacy", + "libhardware", + "android.hardware.tetheroffload.config@1.0", + "android.hardware.tetheroffload.control@1.0", + ], +} + +//############################################################################### + +prebuilt_etc { + name: "IPACM_cfg.xml", + + vendor: true, + owner: "ipacm", + src: "src/IPACM_cfg.xml", + +} diff --git a/data-ipa-cfg-mgr/ipacm/inc/IPACM_Config.h b/data-ipa-cfg-mgr/ipacm/inc/IPACM_Config.h index 2792f626..a0a8bb85 100644 --- a/data-ipa-cfg-mgr/ipacm/inc/IPACM_Config.h +++ b/data-ipa-cfg-mgr/ipacm/inc/IPACM_Config.h @@ -261,6 +261,14 @@ public: enum ipa_hw_type GetIPAVer(bool get = false); +#ifdef IPA_IOCTL_GET_HW_FEATURE_SUPPORT + int GetIPAFeatureSupport(bool get = false); +#endif + + bool isEthBridgingSupported(); + + bool isIPAv3Supported(); + int Init(void); inline bool isPrivateSubnet(uint32_t ip_addr) @@ -357,6 +365,9 @@ public: private: enum ipa_hw_type ver; +#ifdef IPA_IOCTL_GET_HW_FEATURE_SUPPORT + uint32_t hw_feature; +#endif static IPACM_Config *pInstance; static const char *DEVICE_NAME; IPACM_Config(void); diff --git a/data-ipa-cfg-mgr/ipacm/inc/IPACM_ConntrackListener.h b/data-ipa-cfg-mgr/ipacm/inc/IPACM_ConntrackListener.h index 6cc4188b..2977af70 100644 --- a/data-ipa-cfg-mgr/ipacm/inc/IPACM_ConntrackListener.h +++ b/data-ipa-cfg-mgr/ipacm/inc/IPACM_ConntrackListener.h @@ -61,6 +61,13 @@ typedef struct _nat_entry_bundle }nat_entry_bundle; +typedef struct _ct_entry +{ + struct nf_conntrack *ct; + u_int8_t protocol; + enum nf_conntrack_msg_type type; +}ct_entry; + class IPACM_ConntrackListener : public IPACM_Listener { @@ -78,13 +85,14 @@ private: uint32_t nonnat_iface_ipv4_addr[MAX_IFACE_ADDRESS]; uint32_t sta_clnt_ipv4_addr[MAX_STA_CLNT_IFACES]; IPACM_Config *pConfig; - struct nf_conntrack **ct_entries; + ct_entry *ct_entries; + ct_entry ct_cache[MAX_CONNTRACK_ENTRIES]; #ifdef CT_OPT IPACM_LanToLan *p_lan2lan; #endif void ProcessCTMessage(void *); - void ProcessTCPorUDPMsg(struct nf_conntrack *, + bool ProcessTCPorUDPMsg(struct nf_conntrack *, enum nf_conntrack_msg_type, u_int8_t); void TriggerWANUp(void *); void TriggerWANDown(uint32_t); @@ -119,8 +127,11 @@ public: void HandleSTAClientAddEvt(uint32_t); void HandleSTAClientDelEvt(uint32_t); int CreateConnTrackThreads(void); - void readConntrack(void); + void readConntrack(int fd); void processConntrack(void); + void CacheORDeleteConntrack(struct nf_conntrack *ct, + enum nf_conntrack_msg_type type, u_int8_t protocol); + void processCacheConntrack(void); }; extern IPACM_ConntrackListener *CtList; diff --git a/data-ipa-cfg-mgr/ipacm/inc/IPACM_Defs.h b/data-ipa-cfg-mgr/ipacm/inc/IPACM_Defs.h index f1113e8b..82e9c6b5 100644 --- a/data-ipa-cfg-mgr/ipacm/inc/IPACM_Defs.h +++ b/data-ipa-cfg-mgr/ipacm/inc/IPACM_Defs.h @@ -97,11 +97,7 @@ extern "C" #define IPA_DEVICE_NAME "/dev/ipa" #define MAX_NUM_PROP 2 -#ifndef FEATURE_IPA_V3 -#define IPA_MAX_FLT_RULE 50 -#else #define IPA_MAX_FLT_RULE 100 -#endif #define TCP_FIN_SHIFT 16 #define TCP_SYN_SHIFT 17 @@ -197,6 +193,10 @@ typedef enum IPA_ETH_BRIDGE_WLAN_SCC_MCC_SWITCH, /* ipacm_event_eth_bridge*/ IPA_SSR_NOTICE, /* NULL*/ IPA_COALESCE_NOTICE, /* NULL*/ +#ifdef IPA_MTU_EVENT_MAX + IPA_MTU_SET, /* ipa_mtu_info */ + IPA_MTU_UPDATE, /* ipacm_event_mtu_info */ +#endif #ifdef FEATURE_L2TP IPA_ADD_VLAN_IFACE, /* ipa_ioc_vlan_iface_info */ IPA_DEL_VLAN_IFACE, /* ipa_ioc_vlan_iface_info */ @@ -411,4 +411,11 @@ typedef struct { _ipacm_offload_prefix prefix; } ipacm_event_ipahal_stream; +#ifdef IPA_MTU_EVENT_MAX +typedef struct _ipacm_event_mtu_info +{ + int if_index; + ipa_mtu_info mtu_info; +} ipacm_event_mtu_info; +#endif #endif /* IPA_CM_DEFS_H */ diff --git a/data-ipa-cfg-mgr/ipacm/inc/IPACM_Lan.h b/data-ipa-cfg-mgr/ipacm/inc/IPACM_Lan.h index 605edb59..de64be18 100644 --- a/data-ipa-cfg-mgr/ipacm/inc/IPACM_Lan.h +++ b/data-ipa-cfg-mgr/ipacm/inc/IPACM_Lan.h @@ -230,6 +230,8 @@ protected: int reset_to_dummy_flt_rule(ipa_ip_type iptype, uint32_t rule_hdl); + virtual int modify_ipv6_prefix_flt_rule(uint32_t* prefix); + virtual int install_ipv6_prefix_flt_rule(uint32_t* prefix); virtual void delete_ipv6_prefix_flt_rule(); diff --git a/data-ipa-cfg-mgr/ipacm/inc/IPACM_Wan.h b/data-ipa-cfg-mgr/ipacm/inc/IPACM_Wan.h index ad627835..94609387 100644 --- a/data-ipa-cfg-mgr/ipacm/inc/IPACM_Wan.h +++ b/data-ipa-cfg-mgr/ipacm/inc/IPACM_Wan.h @@ -63,6 +63,7 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define NETWORK_STATS "%s %llu %llu %llu %llu" #define IPA_NETWORK_STATS_FILE_NAME "/data/misc/ipa/network_stats" +#define IPA_OFFLOAD_TETHER_STATE_FILE_NAME "/data/vendor/ipa/offload_state" typedef struct _wan_client_rt_hdl { @@ -105,8 +106,10 @@ public: static bool wan_up; static bool wan_up_v6; static uint8_t xlat_mux_id; - static uint16_t mtu_default_wan; - uint16_t mtu_size; + + static uint16_t mtu_default_wan_v4; + static uint16_t mtu_default_wan_v6; + /* IPACM interface name */ static char wan_up_dev_name[IF_NAME_LEN]; static uint32_t curr_wan_ip; @@ -145,15 +148,14 @@ public: { if (isWanUP(ipa_if_num_tether)) { - return mtu_default_wan; + return mtu_default_wan_v4; } } else if (iptype == IPA_IP_v6) { if (isWanUP_V6(ipa_if_num_tether)) { - return mtu_default_wan; - + return mtu_default_wan_v6; } } return DEFAULT_MTU_SIZE; @@ -405,6 +407,14 @@ private: /* handle for TCP RST rule */ uint32_t tcp_rst_hdl; + /* V4 MTU value. */ + uint16_t mtu_v4; + bool mtu_v4_set; + + /* V6 MTU value. */ + uint16_t mtu_v6; + bool mtu_v6_set; + inline ipa_wan_client* get_client_memptr(ipa_wan_client *param, int cnt) { char *ret = ((char *)param) + (wan_client_len * cnt); @@ -583,10 +593,13 @@ private: return IPACM_SUCCESS; } - int handle_wan_hdr_init(uint8_t *mac_addr); + int handle_wan_hdr_init(uint8_t *mac_addr, bool replaced = false, int entry = 0); int handle_wan_client_ipaddr(ipacm_event_data_all *data); int handle_wan_client_route_rule(uint8_t *mac_addr, ipa_ip_type iptype); + /* handle_gw_mac_renew, index_client valiud is success */ + int handle_gw_mac_renew(ipacm_event_data_all *data, int index_client); + /* handle new_address event */ int handle_addr_evt(ipacm_event_data_addr *data); @@ -594,10 +607,10 @@ private: int handle_addr_evt_mhi_q6(ipacm_event_data_addr *data); /* wan default route/filter rule configuration */ - int handle_route_add_evt(ipa_ip_type iptype); + int handle_route_add_evt(ipa_ip_type iptype, bool add_only = false); /* construct complete STA ethernet header */ - int handle_sta_header_add_evt(); + int handle_sta_header_add_evt(bool renew = false); bool check_dft_firewall_rules_attr_mask(IPACM_firewall_conf_t *firewall_config); @@ -612,7 +625,7 @@ private: /* configure the initial firewall filter rules */ int config_dft_embms_rules(ipa_ioc_add_flt_rule *pFilteringTable_v4, ipa_ioc_add_flt_rule *pFilteringTable_v6); - int handle_route_del_evt(ipa_ip_type iptype); + int handle_route_del_evt(ipa_ip_type iptype, bool delete_only = false); int del_dft_firewall_rules(ipa_ip_type iptype); @@ -674,7 +687,7 @@ private: int delete_tcp_fin_rst_exception_rule(); - /* Query mtu size */ + /* MTU helper functions */ int query_mtu_size(); }; diff --git a/data-ipa-cfg-mgr/ipacm/src/Android.mk b/data-ipa-cfg-mgr/ipacm/src/Android.mk deleted file mode 100644 index ad271153..00000000 --- a/data-ipa-cfg-mgr/ipacm/src/Android.mk +++ /dev/null @@ -1,162 +0,0 @@ -TARGET_DISABLE_IPACM := false - -ifeq ($(TARGET_USES_QMAA),true) -ifneq ($(TARGET_USES_QMAA_OVERRIDE_DATA),true) - TARGET_DISABLE_IPACM := true -endif #TARGET_USES_QMAA_OVERRIDE_DATA -endif #TARGET_USES_QMAA - -BOARD_IPA_LOW_RAM_EXCP_LIST := bengal - -ifeq ($(TARGET_HAS_LOW_RAM),true) -ifneq ($(call is-board-platform-in-list,$(BOARD_IPA_LOW_RAM_EXCP_LIST)),true) - TARGET_DISABLE_IPACM := true -endif -endif - -ifneq ($(TARGET_DISABLE_IPACM),true) -BOARD_PLATFORM_LIST := msm8909 -BOARD_PLATFORM_LIST += msm8916 -BOARD_PLATFORM_LIST += msm8917 -BOARD_PLATFORM_LIST += qm215 -ifeq ($(TARGET_BOARD_SUFFIX),_gvmq) -BOARD_PLATFORM_LIST += msmnile -endif -BOARD_IPAv3_LIST := msm8998 -BOARD_IPAv3_LIST += sdm845 -BOARD_IPAv3_LIST += sdm710 -BOARD_IPAv3_LIST += msmnile -BOARD_IPAv3_LIST += kona -BOARD_IPAv3_LIST += $(MSMSTEPPE) -BOARD_IPAv3_LIST += $(TRINKET) -BOARD_IPAv3_LIST += lito -BOARD_IPAv3_LIST += atoll -BOARD_IPAv3_LIST += bengal -BOARD_ETH_BRIDGE_LIST := msmnile -BOARD_ETH_BRIDGE_LIST += kona - -ifneq ($(call is-board-platform-in-list,$(BOARD_PLATFORM_LIST)),true) -ifneq (,$(filter $(QCOM_BOARD_PLATFORMS),$(TARGET_BOARD_PLATFORM))) -ifneq (, $(filter aarch64 arm arm64, $(TARGET_ARCH))) - -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_C_INCLUDES := $(LOCAL_PATH)/../src -LOCAL_C_INCLUDES += $(LOCAL_PATH)/../inc - -LOCAL_HEADER_LIBRARIES := generated_kernel_headers - -LOCAL_CFLAGS := -DFEATURE_IPA_ANDROID -LOCAL_CFLAGS += -DFEATURE_IPACM_RESTART - -ifeq ($(call is-board-platform-in-list,$(BOARD_ETH_BRIDGE_LIST)),true) -LOCAL_CFLAGS += -DFEATURE_ETH_BRIDGE_LE -endif - -LOCAL_CFLAGS += -DFEATURE_IPACM_HAL -LOCAL_CFLAGS += \ - -Wall \ - -Werror \ - -Wno-constant-logical-operand \ - -Wno-format \ - -Wno-missing-field-initializers \ - -Wno-sign-compare \ - -Wno-sometimes-uninitialized \ - -Wno-unused-parameter \ - -Wno-unused-value \ - -Wno-unused-variable \ - -Wno-writable-strings \ - -Wno-error=implicit-fallthrough - -ifneq (,$(filter eng, $(TARGET_BUILD_VARIANT))) -LOCAL_CFLAGS += -DDEBUG -endif - -ifeq ($(call is-board-platform-in-list,$(BOARD_IPAv3_LIST)),true) -LOCAL_CFLAGS += -DFEATURE_IPA_V3 -endif - -filetoadd = bionic/libc/kernel/arch-arm/asm/posix_types.h -LOCAL_CFLAGS += $(shell if [ -a $(filetoadd) ] ; then echo -include $(filetoadd) ; fi ;) -filetoadd = bionic/libc/kernel/arch-arm/asm/byteorder.h -LOCAL_CFLAGS += $(shell if [ -a $(filetoadd) ] ; then echo -include $(filetoadd) ; fi ;) - -LOCAL_SRC_FILES := IPACM_Main.cpp \ - IPACM_EvtDispatcher.cpp \ - IPACM_Config.cpp \ - IPACM_CmdQueue.cpp \ - IPACM_Filtering.cpp \ - IPACM_Routing.cpp \ - IPACM_Header.cpp \ - IPACM_Lan.cpp \ - IPACM_Iface.cpp \ - IPACM_Wlan.cpp \ - IPACM_Wan.cpp \ - IPACM_IfaceManager.cpp \ - IPACM_Neighbor.cpp \ - IPACM_Netlink.cpp \ - IPACM_Xml.cpp \ - IPACM_Conntrack_NATApp.cpp\ - IPACM_ConntrackClient.cpp \ - IPACM_ConntrackListener.cpp \ - IPACM_Log.cpp \ - IPACM_OffloadManager.cpp \ - IPACM_LanToLan.cpp - -LOCAL_MODULE := ipacm -LOCAL_INIT_RC := ipacm.rc -LOCAL_CLANG := false -LOCAL_MODULE_TAGS := optional - -LOCAL_SHARED_LIBRARIES := liboffloadhal -LOCAL_SHARED_LIBRARIES += libipanat -LOCAL_SHARED_LIBRARIES += libxml2 -LOCAL_SHARED_LIBRARIES += libnfnetlink -LOCAL_SHARED_LIBRARIES += libnetfilter_conntrack -LOCAL_SHARED_LIBRARIES += libhwbinder \ - libhidlbase \ - libhidltransport \ - liblog \ - libcutils \ - libdl \ - libbase \ - libutils \ - libhardware_legacy \ - libhardware \ - android.hardware.tetheroffload.config@1.0 \ - android.hardware.tetheroffload.control@1.0 - -LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_EXECUTABLES) - -LOCAL_CLANG := true -include $(BUILD_EXECUTABLE) - -################################################################################ - -define ADD_TEST - -include $(CLEAR_VARS) -LOCAL_MODULE := $1 -LOCAL_SRC_FILES := $1 -LOCAL_MODULE_CLASS := ipacm -LOCAL_MODULE_TAGS := optional -LOCAL_MODULE_PATH := $(TARGET_OUT_ETC) -include $(BUILD_PREBUILT) - -endef - -include $(CLEAR_VARS) -LOCAL_MODULE := IPACM_cfg.xml -LOCAL_MODULE_CLASS := ETC -LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_ETC) -LOCAL_MODULE_TAGS := optional -LOCAL_SRC_FILES := $(LOCAL_MODULE) -LOCAL_MODULE_OWNER := ipacm -include $(BUILD_PREBUILT) - -endif # $(TARGET_ARCH) -endif -endif -endif diff --git a/data-ipa-cfg-mgr/ipacm/src/IPACM_Config.cpp b/data-ipa-cfg-mgr/ipacm/src/IPACM_Config.cpp index 781f1cbf..05fd07d7 100644 --- a/data-ipa-cfg-mgr/ipacm/src/IPACM_Config.cpp +++ b/data-ipa-cfg-mgr/ipacm/src/IPACM_Config.cpp @@ -106,7 +106,12 @@ const char *ipacm_event_name[] = { __stringify(IPA_ETH_BRIDGE_CLIENT_ADD), /* ipacm_event_eth_bridge*/ __stringify(IPA_ETH_BRIDGE_CLIENT_DEL), /* ipacm_event_eth_bridge*/ __stringify(IPA_ETH_BRIDGE_WLAN_SCC_MCC_SWITCH), /* ipacm_event_eth_bridge*/ - __stringify(IPA_SSR_NOTICE) /* NULL*/ + __stringify(IPA_SSR_NOTICE), /* NULL*/ + __stringify(IPA_COALESCE_NOTICE), /* NULL*/ +#ifdef IPA_MTU_EVENT_MAX + __stringify(IPA_MTU_SET), /* ipa_mtu_info */ + __stringify(IPA_MTU_UPDATE), /* ipacm_event_mtu_info */ +#endif #ifdef FEATURE_L2TP __stringify(IPA_ADD_VLAN_IFACE), /* ipa_ioc_vlan_iface_info */ __stringify(IPA_DEL_VLAN_IFACE), /* ipa_ioc_vlan_iface_info */ @@ -192,6 +197,9 @@ int IPACM_Config::Init(void) IPACMERR("Failed opening %s.\n", DEVICE_NAME); } ver = GetIPAVer(true); +#ifdef IPA_IOCTL_GET_HW_FEATURE_SUPPORT + hw_feature = GetIPAFeatureSupport(true); +#endif #ifdef FEATURE_IPACM_HAL strlcpy(IPACM_config_file, "/vendor/etc/IPACM_cfg.xml", sizeof(IPACM_config_file)); #else @@ -905,3 +913,51 @@ enum ipa_hw_type IPACM_Config::GetIPAVer(bool get) IPACMDBG_H("IPA version is %d.\n", ver); return ver; } + +#ifdef IPA_IOCTL_GET_HW_FEATURE_SUPPORT +int IPACM_Config::GetIPAFeatureSupport(bool get) +{ + int ret; + + if(!get) + return hw_feature; + + ret = ioctl(m_fd, IPA_IOC_GET_HW_FEATURE_SUPPORT, &hw_feature); + if(ret != 0) + { + IPACMERR("Failed to get IPA HW feature support %d.\n", ret); + hw_feature = 0; + return hw_feature; + } + IPACMDBG_H("IPA HW supported feature %d.\n", hw_feature); + return hw_feature; +} +#endif + +bool IPACM_Config::isEthBridgingSupported() +{ + enum ipa_hw_type hw_type; + + hw_type = GetIPAVer(); +#ifdef IPA_IOCTL_GET_HW_FEATURE_SUPPORT + if (hw_type >= IPA_HW_v4_11) { + return ((hw_feature & IPA_HW_ETH_BRIDGING_SUPPORT_BMSK) != 0); + } +#endif + +#ifdef IPA_HW_v4_7 + return ((hw_type >= IPA_HW_v4_5) && + (hw_type != IPA_HW_v4_7)); +#else + return (hw_type >= IPA_HW_v4_5); +#endif +} + +bool IPACM_Config::isIPAv3Supported() +{ + enum ipa_hw_type hw_type; + + hw_type = GetIPAVer(); + + return (hw_type >= IPA_HW_v3_0); +} diff --git a/data-ipa-cfg-mgr/ipacm/src/IPACM_ConntrackClient.cpp b/data-ipa-cfg-mgr/ipacm/src/IPACM_ConntrackClient.cpp index 24f95a33..29afd504 100644 --- a/data-ipa-cfg-mgr/ipacm/src/IPACM_ConntrackClient.cpp +++ b/data-ipa-cfg-mgr/ipacm/src/IPACM_ConntrackClient.cpp @@ -421,17 +421,6 @@ void* IPACM_ConntrackClient::TCPRegisterWithConnTrack(void *) unsigned subscrips = 0; IPACMDBG("\n"); - /* In Android we get conntrack handles once after tethering is enabled but we - loose connections info for embedded traffic if running before. So no NAT - entries are added for embedded traffic due to which we see NAT exception and - data takes S/W path which results in less throughput. Hence for embedded - traffic info, framework sends conntrack dump before providing handles. Here - reading ct entries before creating filter on Fd in order to have NAT entries - for both TCP/UDP embedded traffic. */ - if(CtList != NULL && !CtList->isReadCTDone) - { - CtList->readConntrack(); - } pClient = IPACM_ConntrackClient::GetInstance(); if(pClient == NULL) @@ -493,12 +482,18 @@ void* IPACM_ConntrackClient::TCPRegisterWithConnTrack(void *) blocks waiting for events. */ IPACMDBG("Waiting for events\n"); +ctcatch: ret = nfct_catch(pClient->tcp_hdl); - if(ret == -1) + if((ret == -1) && (errno != ENOMSG)) { - IPACMERR("(%d)(%s)\n", ret, strerror(errno)); + IPACMERR("(%d)(%d)(%s)\n", ret, errno, strerror(errno)); return NULL; } + else + { + IPACMDBG("ctcatch ret:%d, errno:%d\n", ret, errno); + goto ctcatch; + } IPACMDBG("Exit from tcp thread\n"); @@ -579,14 +574,15 @@ void* IPACM_ConntrackClient::UDPRegisterWithConnTrack(void *) /* Block to catch events from net filter connection track */ ctcatch: ret = nfct_catch(pClient->udp_hdl); - if(ret == -1) + /* Due to conntrack dump, sequence number might mismatch for initial events. */ + if((ret == -1) && (errno != ENOMSG) && (errno != EILSEQ)) { - IPACMDBG("(%d)(%s)\n", ret, strerror(errno)); + IPACMDBG("(%d)(%d)(%s)\n", ret, errno, strerror(errno)); return NULL; } else { - IPACMDBG("ctcatch ret:%d\n", ret); + IPACMDBG("ctcatch ret:%d, errno:%d\n", ret, errno); goto ctcatch; } diff --git a/data-ipa-cfg-mgr/ipacm/src/IPACM_ConntrackListener.cpp b/data-ipa-cfg-mgr/ipacm/src/IPACM_ConntrackListener.cpp index fff6bfc5..fd1566da 100644 --- a/data-ipa-cfg-mgr/ipacm/src/IPACM_ConntrackListener.cpp +++ b/data-ipa-cfg-mgr/ipacm/src/IPACM_ConntrackListener.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2013-2019, The Linux Foundation. All rights reserved. +Copyright (c) 2013-2020, The Linux Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are @@ -40,7 +40,6 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. IPACM_ConntrackListener::IPACM_ConntrackListener() { IPACMDBG("\n"); - isNatThreadStart = false; isCTReg = false; WanUp = false; @@ -70,6 +69,9 @@ IPACM_ConntrackListener::IPACM_ConntrackListener() #ifdef CT_OPT p_lan2lan = IPACM_LanToLan::getLan2LanInstance(); #endif + + /* Initialize the CT cache. */ + memset(ct_cache, 0, sizeof(ct_cache)); } void IPACM_ConntrackListener::event_callback(ipa_cm_event_id evt, @@ -105,6 +107,8 @@ void IPACM_ConntrackListener::event_callback(ipa_cm_event_id evt, { processConntrack(); } + /* Process the cached entries. */ + processCacheConntrack(); break; case IPA_HANDLE_WAN_DOWN: @@ -675,6 +679,7 @@ void IPACM_ConntrackListener::ProcessCTMessage(void *param) { ipacm_ct_evt_data *evt_data = (ipacm_ct_evt_data *)param; u_int8_t l4proto = 0; + bool cache_ct = false; #ifdef IPACM_DEBUG char buf[1024]; @@ -696,11 +701,14 @@ void IPACM_ConntrackListener::ProcessCTMessage(void *param) } else { - ProcessTCPorUDPMsg(evt_data->ct, evt_data->type, l4proto); + cache_ct = ProcessTCPorUDPMsg(evt_data->ct, evt_data->type, l4proto); } /* Cleanup item that was allocated during the original CT callback */ - nfct_destroy(evt_data->ct); + if (!cache_ct) + nfct_destroy(evt_data->ct); + else + CacheORDeleteConntrack(evt_data->ct, evt_data->type, l4proto); return; } @@ -847,7 +855,7 @@ void IPACM_ConntrackListener::AddORDeleteNatEntry(const nat_entry_bundle *input) } else if (IPPROTO_UDP == input->rule->protocol) { - if (NFCT_T_NEW == input->type) + if (NFCT_T_NEW == input->type || NFCT_T_UPDATE == input->type) { IPACMDBG("New UDP connection at time %ld\n", time(NULL)); if (!CtList->isWanUp()) @@ -880,6 +888,8 @@ void IPACM_ConntrackListener::PopulateTCPorUDPEntry( uint32_t status, nat_table_entry *rule) { + uint32_t repl_dst_ip; + if (IPS_DST_NAT == status) { IPACMDBG("Destination NAT\n"); @@ -964,6 +974,15 @@ void IPACM_ConntrackListener::PopulateTCPorUDPEntry( { IPACMDBG("unable to retrieve private port\n"); } + + /* If Reply destination IP is not Public IP, install dummy NAT rule. */ + repl_dst_ip = nfct_get_attr_u32(ct, ATTR_REPL_IPV4_DST); + repl_dst_ip = ntohl(repl_dst_ip); + if(repl_dst_ip != rule->public_ip) + { + IPACMDBG_H("Reply dst IP:0x%x not equal to wan ip:0x%x\n",repl_dst_ip, rule->public_ip); + rule->private_ip = rule->public_ip; + } } return; @@ -1037,7 +1056,7 @@ void IPACM_ConntrackListener::CheckSTAClient( } /* conntrack send in host order and ipa expects in host order */ -void IPACM_ConntrackListener::ProcessTCPorUDPMsg( +bool IPACM_ConntrackListener::ProcessTCPorUDPMsg( struct nf_conntrack *ct, enum nf_conntrack_msg_type type, u_int8_t l4proto) @@ -1046,6 +1065,7 @@ void IPACM_ConntrackListener::ProcessTCPorUDPMsg( uint32_t status = 0; uint32_t orig_src_ip, orig_dst_ip; bool isAdd = false; + bool cache_ct = false; nat_entry_bundle nat_entry; nat_entry.isTempEntry = false; @@ -1075,7 +1095,7 @@ void IPACM_ConntrackListener::ProcessTCPorUDPMsg( if(orig_src_ip == 0) { IPACMERR("unable to retrieve orig src ip address\n"); - return; + return cache_ct; } orig_dst_ip = nfct_get_attr_u32(ct, ATTR_ORIG_IPV4_DST); @@ -1083,7 +1103,7 @@ void IPACM_ConntrackListener::ProcessTCPorUDPMsg( if(orig_dst_ip == 0) { IPACMERR("unable to retrieve orig dst ip address\n"); - return; + return cache_ct; } if(orig_src_ip == wan_ipaddr) @@ -1104,13 +1124,16 @@ void IPACM_ConntrackListener::ProcessTCPorUDPMsg( #ifdef CT_OPT HandleLan2Lan(ct, type, &rule); #endif - IPACMDBG("Neither source Nor destination nat\n"); - goto IGNORE; + IPACMDBG("Neither source Nor destination nat.\n"); + /* If WAN is not up, cache the event. */ + if(!CtList->isWanUp()) + cache_ct = true; + goto IGNORE; } } - PopulateTCPorUDPEntry(ct, status, &rule); rule.public_ip = wan_ipaddr; + PopulateTCPorUDPEntry(ct, status, &rule); if (rule.private_ip != wan_ipaddr) { @@ -1137,7 +1160,7 @@ void IPACM_ConntrackListener::ProcessTCPorUDPMsg( CheckSTAClient(&rule, &nat_entry.isTempEntry); nat_entry.rule = &rule; AddORDeleteNatEntry(&nat_entry); - return; + return cache_ct; IGNORE: IPACMDBG_H("ignoring below Nat Entry\n"); @@ -1147,7 +1170,7 @@ IGNORE: IPACMDBG("private port or src port: 0x%x, Decimal:%d\n", rule.private_port, rule.private_port); IPACMDBG("public port or reply dst port: 0x%x, Decimal:%d\n", rule.public_port, rule.public_port); IPACMDBG("Protocol: %d, destination nat flag: %d\n", rule.protocol, rule.dst_nat); - return; + return cache_ct; } void IPACM_ConntrackListener::HandleSTAClientAddEvt(uint32_t clnt_ip_addr) @@ -1219,78 +1242,97 @@ bool isLocalHostAddr(uint32_t src_ip_addr, uint32_t dst_ip_addr) { return false; } -void IPACM_ConntrackListener::readConntrack() { +void IPACM_ConntrackListener::readConntrack(int fd) { - IPACM_ConntrackClient *pClient; - int len_fil = 0, recv_bytes = -1, index = 0, len =0; + int recv_bytes = -1, index = 0, len =0; char buffer[CT_ENTRIES_BUFFER_SIZE]; - char *buf = &buffer[0]; struct nf_conntrack *ct; struct nlmsghdr *nl_header; - static struct sockaddr_nl nlAddr = { - .nl_family = AF_NETLINK + struct iovec iov = { + .iov_base = buffer, + .iov_len = CT_ENTRIES_BUFFER_SIZE, + }; + struct sockaddr_nl addr; + struct msghdr msg = { + .msg_name = &addr, + .msg_namelen = sizeof(struct sockaddr_nl), + .msg_iov = &iov, + .msg_iovlen = 1, + .msg_control = NULL, + .msg_controllen = 0, + .msg_flags = 0, }; - unsigned int addr_len = sizeof(nlAddr); - pClient = IPACM_ConntrackClient::GetInstance(); - len = MAX_CONNTRACK_ENTRIES * sizeof(struct nf_conntrack **); + len = MAX_CONNTRACK_ENTRIES * sizeof(ct_entry); - ct_entries = (struct nf_conntrack **) malloc(len); - memset(ct_entries, 0, len); - - if( pClient->fd_tcp < 0) + ct_entries = (ct_entry *) malloc(len); + if(ct_entries == NULL) { - IPACMDBG_H("Invalid fd %d \n",pClient->fd_tcp); + IPACMERR("unable to allocate ct_entries memory \n"); return; } + memset(ct_entries, 0, len); - IPACMDBG_H("receiving conntrack entries started.\n"); - while(len_fil < sizeof(buffer) && index < MAX_CONNTRACK_ENTRIES) + if( fd < 0) { - recv_bytes = recvfrom( pClient->fd_tcp, buf, sizeof(buffer)-len_fil, 0, (struct sockaddr *)&nlAddr, (socklen_t *)&addr_len); + IPACMDBG_H("Invalid fd %d \n",fd); + free(ct_entries); + return; + } + IPACMDBG_H("receiving conntrack entries started.\n"); + len = CT_ENTRIES_BUFFER_SIZE; + while (len > 0) + { + memset(buffer, 0, CT_ENTRIES_BUFFER_SIZE); + recv_bytes = recvmsg(fd, &msg, 0); if(recv_bytes < 0) { - IPACMDBG_H("error in receiving conntrack entries %d%s",errno, strerror(errno)); + IPACMDBG_H("error in receiving conntrack entries %d%s\n",errno, strerror(errno)); break; } else { - nl_header = (struct nlmsghdr *)buf; - - if (NLMSG_OK(nl_header, recv_bytes) == 0 || nl_header->nlmsg_type == NLMSG_ERROR) + len -= recv_bytes; + nl_header = (struct nlmsghdr *)buffer; + IPACMDBG_H("Number of bytes:%d to parse\n", recv_bytes); + while(NLMSG_OK(nl_header, recv_bytes) && (index < MAX_CONNTRACK_ENTRIES)) { - IPACMDBG_H("recv_bytes is %d\n",recv_bytes); - break; - } - ct = nfct_new(); - if (ct != NULL) - { - int parseResult = nfct_parse_conntrack((nf_conntrack_msg_type) NFCT_T_ALL,nl_header, ct); - if(parseResult != NFCT_T_ERROR) + if (nl_header->nlmsg_type == NLMSG_ERROR) { - ct_entries[index++] = ct; + IPACMDBG_H("Error, recv_bytes is %d\n",recv_bytes); + break; + } + ct = nfct_new(); + if (ct != NULL) + { + int parseResult = nfct_parse_conntrack((nf_conntrack_msg_type) NFCT_T_ALL,nl_header, ct); + if(parseResult != NFCT_T_ERROR && parseResult != 0) + { + ct_entries[index].ct = ct; + ct_entries[index++].type = (nf_conntrack_msg_type)parseResult; + } + else + { + IPACMDBG_H("error in parsing %d%s \n", errno, strerror(errno)); + nfct_destroy(ct); + } } else { - IPACMDBG_H("error in parsing %d%s \n", errno, strerror(errno)); + IPACMDBG_H("ct allocation failed\n"); } + if (nl_header->nlmsg_type == NLMSG_DONE) + { + IPACMDBG_H("Message is done.\n"); + break; + } + nl_header = NLMSG_NEXT(nl_header, recv_bytes); } - else - { - IPACMDBG_H("ct allocation failed"); - continue; - } - - if((nl_header->nlmsg_type & NLM_F_MULTI) == 0) - { - break; - } - len_fil += recv_bytes; - buf = buf + recv_bytes; } } + isReadCTDone = true; - IPACMDBG_H("receiving conntrack entries ended.\n"); + IPACMDBG_H("receiving conntrack entries ended. No of entries: %d\n", index); if(isWanUp() && !isProcessCTDone) { IPACMDBG_H("wan is up, process ct entries \n"); @@ -1305,15 +1347,14 @@ void IPACM_ConntrackListener::processConntrack() { uint8_t ip_type; int index = 0; ipacm_ct_evt_data *ct_data; - enum nf_conntrack_msg_type type = NFCT_T_ALL; IPACMDBG_H("process conntrack started \n"); if(ct_entries != NULL) { - while(ct_entries[index] != NULL) + while(ct_entries[index].ct != NULL) { - ip_type = nfct_get_attr_u8(ct_entries[index], ATTR_REPL_L3PROTO); - if(!(AF_INET6 == ip_type) && isLocalHostAddr(nfct_get_attr_u32(ct_entries[index], ATTR_ORIG_IPV4_SRC), - nfct_get_attr_u32(ct_entries[index], ATTR_ORIG_IPV4_DST))) + ip_type = nfct_get_attr_u8(ct_entries[index].ct, ATTR_REPL_L3PROTO); + if((AF_INET == ip_type) && isLocalHostAddr(nfct_get_attr_u32(ct_entries[index].ct, ATTR_ORIG_IPV4_SRC), + nfct_get_attr_u32(ct_entries[index].ct, ATTR_ORIG_IPV4_DST))) { IPACMDBG_H(" loopback entry \n"); goto IGNORE; @@ -1334,8 +1375,8 @@ void IPACM_ConntrackListener::processConntrack() { goto IGNORE; } - ct_data->ct = ct_entries[index]; - ct_data->type = type; + ct_data->ct = ct_entries[index].ct; + ct_data->type = ct_entries[index].type; #ifdef CT_OPT if(AF_INET6 == ip_type) @@ -1349,7 +1390,7 @@ void IPACM_ConntrackListener::processConntrack() { free(ct_data); continue; IGNORE: - nfct_destroy(ct_entries[index]); + nfct_destroy(ct_entries[index].ct); index++; } } @@ -1360,6 +1401,114 @@ IGNORE: } isProcessCTDone = true; free(ct_entries); - IPACMDBG_H("process conntrack ended \n"); + ct_entries = NULL; + IPACMDBG_H("process conntrack ended. Number of entries:%d \n", index); return; } + +void IPACM_ConntrackListener::CacheORDeleteConntrack +( + struct nf_conntrack *ct, + enum nf_conntrack_msg_type type, + u_int8_t protocol +) +{ + u_int8_t tcp_state; + int i = 0, free_idx = -1; + + IPACMDBG("CT entry, type (%d), protocol(%d)\n", type, protocol); + /* Check for duplicate entry and in parallel find first free index. */ + for(; i < MAX_CONNTRACK_ENTRIES; i++) + { + if (ct_cache[i].ct != NULL) + { + if (nfct_cmp(ct_cache[i].ct, ct, NFCT_CMP_ORIG | NFCT_CMP_REPL)) + { + /* Duplicate entry. */ + IPACMDBG("Duplicate CT entry, type (%d), protocol(%d)\n", + type, protocol); + break; + } + } + else if ((ct_cache[i].ct == NULL) && (free_idx == -1)) + { + /* Cache the first free index. */ + free_idx = i; + } + } + + /* Duplicate entry handling. */ + if (i < MAX_CONNTRACK_ENTRIES) + { + if (IPPROTO_TCP == protocol) + { + tcp_state = nfct_get_attr_u8(ct, ATTR_TCP_STATE); + if (TCP_CONNTRACK_FIN_WAIT == tcp_state || type == NFCT_T_DESTROY) + { + IPACMDBG("TCP state TCP_CONNTRACK_FIN_WAIT(%d) " + "or type NFCT_T_DESTROY\n", tcp_state); + nfct_destroy(ct_cache[i].ct); + nfct_destroy(ct); + memset(&ct_cache[i], 0, sizeof(ct_cache[i])); + return ; + } + } + if ((IPPROTO_UDP == protocol) && (type == NFCT_T_DESTROY)) + { + IPACMDBG("UDP type NFCT_T_DESTROY\n"); + nfct_destroy(ct_cache[i].ct); + nfct_destroy(ct); + memset(&ct_cache[i], 0, sizeof(ct_cache[i])); + return; + } + } + else if ((i == MAX_CONNTRACK_ENTRIES) && + (type != NFCT_T_DESTROY) && (free_idx != -1)) + { + if (IPPROTO_TCP == protocol) + { + tcp_state = nfct_get_attr_u8(ct, ATTR_TCP_STATE); + if (TCP_CONNTRACK_ESTABLISHED == tcp_state) + { + IPACMDBG("TCP state TCP_CONNTRACK_ESTABLISHED\n"); + /* Cache the entry. */ + ct_cache[free_idx].ct = ct; + ct_cache[free_idx].protocol = protocol; + ct_cache[free_idx].type = type; + return; + } + } + if (IPPROTO_UDP == protocol) + { + if (NFCT_T_NEW == type) + { + IPACMDBG("New UDP connection\n"); + /* Cache the entry. */ + ct_cache[free_idx].ct = ct; + ct_cache[free_idx].protocol = protocol; + ct_cache[free_idx].type = type; + return; + } + } + } + /* In all other cases, free the conntracy entry. */ + nfct_destroy(ct); + return ; +} +void IPACM_ConntrackListener::processCacheConntrack(void) +{ + int i = 0; + + IPACMDBG("Entry:\n"); + for(; i < MAX_CONNTRACK_ENTRIES; i++) + { + if (ct_cache[i].ct != NULL) + { + ProcessTCPorUDPMsg(ct_cache[i].ct, ct_cache[i].type, ct_cache[i].protocol); + nfct_destroy(ct_cache[i].ct); + memset(&ct_cache[i], 0, sizeof(ct_cache[i])); + } + } + IPACMDBG("Exit:\n"); +} + diff --git a/data-ipa-cfg-mgr/ipacm/src/IPACM_Conntrack_NATApp.cpp b/data-ipa-cfg-mgr/ipacm/src/IPACM_Conntrack_NATApp.cpp index 0cf101ff..a9c7140c 100644 --- a/data-ipa-cfg-mgr/ipacm/src/IPACM_Conntrack_NATApp.cpp +++ b/data-ipa-cfg-mgr/ipacm/src/IPACM_Conntrack_NATApp.cpp @@ -195,12 +195,6 @@ int NatApp::AddTable(uint32_t pub_ip, uint8_t mux_id) } } - /* configure NAT initialization paramater */ - pub_ip_addr = pub_ip; - pub_mux_id = mux_id; - IPACMDBG(" Set pub_mux_id: %d\t", pub_mux_id); - - /* Add back the cached NAT-entry */ if (pub_ip == pub_ip_addr_pre) { @@ -228,8 +222,6 @@ int NatApp::AddTable(uint32_t pub_ip, uint8_t mux_id) /* send connections info to pcie modem only with DL direction */ if ((CtList->backhaul_mode == Q6_MHI_WAN) && (cache[cnt].dst_nat == true || cache[cnt].protocol == IPPROTO_TCP)) { - /* propagate pub_ip info */ - cache[cnt].public_ip = pub_ip; ret = AddConnection(&cache[cnt]); if(ret > 0) { @@ -254,6 +246,9 @@ int NatApp::AddTable(uint32_t pub_ip, uint8_t mux_id) } } + pub_ip_addr = pub_ip; + pub_mux_id = mux_id; + IPACMDBG(" Set pub_mux_id: %d\t", pub_mux_id); return 0; } @@ -551,9 +546,8 @@ int NatApp::AddConnection(const nat_table_entry *rule) flt_rule_entry.rule.to_uc = 0; flt_rule_entry.rule.eq_attrib_type = 1; flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; flt_rule_entry.rule.attrib.attrib_mask |= IPA_FLT_SRC_PORT; flt_rule_entry.rule.attrib.src_port = rule->target_port; flt_rule_entry.rule.attrib.attrib_mask |= IPA_FLT_DST_PORT; diff --git a/data-ipa-cfg-mgr/ipacm/src/IPACM_Filtering.cpp b/data-ipa-cfg-mgr/ipacm/src/IPACM_Filtering.cpp index 217f3102..875a7949 100644 --- a/data-ipa-cfg-mgr/ipacm/src/IPACM_Filtering.cpp +++ b/data-ipa-cfg-mgr/ipacm/src/IPACM_Filtering.cpp @@ -46,6 +46,7 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "IPACM_Filtering.h" #include #include "IPACM_Defs.h" +#include "IPACM_Iface.h" const char *IPACM_Filtering::DEVICE_NAME = "/dev/ipa"; @@ -235,156 +236,162 @@ fail_tbl: bool IPACM_Filtering::AddFilteringRuleAfter_hw_index(struct ipa_ioc_add_flt_rule_after *ruleTable, int hw_counter_index) { bool ret = true; -#ifdef FEATURE_IPA_V3 int retval=0, cnt = 0, len = 0; struct ipa_ioc_add_flt_rule_after_v2 *ruleTable_v2; struct ipa_flt_rule_add_v2 flt_rule_entry; - IPACMDBG("Printing filter add attributes\n"); - IPACMDBG("ep: %d\n", ruleTable->ep); - IPACMDBG("ip type: %d\n", ruleTable->ip); - IPACMDBG("Number of rules: %d\n", ruleTable->num_rules); - IPACMDBG("add_after_hdl: %d\n", ruleTable->add_after_hdl); - IPACMDBG("commit value: %d\n", ruleTable->commit); - - /* change to v2 format*/ - len = sizeof(struct ipa_ioc_add_flt_rule_after_v2); - ruleTable_v2 = (struct ipa_ioc_add_flt_rule_after_v2*)malloc(len); - if (ruleTable_v2 == NULL) + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) { - IPACMERR("Error Locate ipa_ioc_add_flt_rule_after_v2 memory...\n"); - return false; - } - memset(ruleTable_v2, 0, len); - ruleTable_v2->rules = (uint64_t)calloc(ruleTable->num_rules, sizeof(struct ipa_flt_rule_add_v2)); - if (!ruleTable_v2->rules) { - IPACMERR("Failed to allocate memory for filtering rules\n"); - ret = false; - goto fail_tbl; - } + IPACMDBG("Printing filter add attributes\n"); + IPACMDBG("ep: %d\n", ruleTable->ep); + IPACMDBG("ip type: %d\n", ruleTable->ip); + IPACMDBG("Number of rules: %d\n", ruleTable->num_rules); + IPACMDBG("add_after_hdl: %d\n", ruleTable->add_after_hdl); + IPACMDBG("commit value: %d\n", ruleTable->commit); - ruleTable_v2->commit = ruleTable->commit; - ruleTable_v2->ep = ruleTable->ep; - ruleTable_v2->ip = ruleTable->ip; - ruleTable_v2->num_rules = ruleTable->num_rules; - ruleTable_v2->add_after_hdl = ruleTable->add_after_hdl; - ruleTable_v2->flt_rule_size = sizeof(struct ipa_flt_rule_add_v2); - - for (cnt=0; cnt < ruleTable->num_rules; cnt++) - { - memset(&flt_rule_entry, 0, sizeof(struct ipa_flt_rule_add_v2)); - flt_rule_entry.at_rear = ruleTable->rules[cnt].at_rear; - flt_rule_entry.rule.retain_hdr = ruleTable->rules[cnt].rule.retain_hdr; - flt_rule_entry.rule.to_uc = ruleTable->rules[cnt].rule.to_uc; - flt_rule_entry.rule.action = ruleTable->rules[cnt].rule.action; - flt_rule_entry.rule.rt_tbl_hdl = ruleTable->rules[cnt].rule.rt_tbl_hdl; - flt_rule_entry.rule.rt_tbl_idx = ruleTable->rules[cnt].rule.rt_tbl_idx; - flt_rule_entry.rule.eq_attrib_type = ruleTable->rules[cnt].rule.eq_attrib_type; - flt_rule_entry.rule.max_prio = ruleTable->rules[cnt].rule.max_prio; - flt_rule_entry.rule.hashable = ruleTable->rules[cnt].rule.hashable; - flt_rule_entry.rule.rule_id = ruleTable->rules[cnt].rule.rule_id; - flt_rule_entry.rule.set_metadata = ruleTable->rules[cnt].rule.set_metadata; - flt_rule_entry.rule.pdn_idx = ruleTable->rules[cnt].rule.pdn_idx; - memcpy(&flt_rule_entry.rule.eq_attrib, - &ruleTable->rules[cnt].rule.eq_attrib, - sizeof(flt_rule_entry.rule.eq_attrib)); - memcpy(&flt_rule_entry.rule.attrib, - &ruleTable->rules[cnt].rule.attrib, - sizeof(flt_rule_entry.rule.attrib)); - IPACMDBG("Filter rule:%d attrib mask: 0x%x\n", cnt, - ruleTable->rules[cnt].rule.attrib.attrib_mask); - /* 0 means disable hw-counter-sats */ - if (hw_counter_index != 0) + /* change to v2 format*/ + len = sizeof(struct ipa_ioc_add_flt_rule_after_v2); + ruleTable_v2 = (struct ipa_ioc_add_flt_rule_after_v2*)malloc(len); + if (ruleTable_v2 == NULL) { - flt_rule_entry.rule.enable_stats = 1; - flt_rule_entry.rule.cnt_idx = hw_counter_index; + IPACMERR("Error Locate ipa_ioc_add_flt_rule_after_v2 memory...\n"); + return false; + } + memset(ruleTable_v2, 0, len); + ruleTable_v2->rules = (uint64_t)calloc(ruleTable->num_rules, sizeof(struct ipa_flt_rule_add_v2)); + if (!ruleTable_v2->rules) { + IPACMERR("Failed to allocate memory for filtering rules\n"); + ret = false; + goto fail_tbl; } - /* copy to v2 table*/ - memcpy((void *)(ruleTable_v2->rules + (cnt * sizeof(struct ipa_flt_rule_add_v2))), - &flt_rule_entry, sizeof(flt_rule_entry)); - } + ruleTable_v2->commit = ruleTable->commit; + ruleTable_v2->ep = ruleTable->ep; + ruleTable_v2->ip = ruleTable->ip; + ruleTable_v2->num_rules = ruleTable->num_rules; + ruleTable_v2->add_after_hdl = ruleTable->add_after_hdl; + ruleTable_v2->flt_rule_size = sizeof(struct ipa_flt_rule_add_v2); - retval = ioctl(fd, IPA_IOC_ADD_FLT_RULE_AFTER_V2, ruleTable_v2); - if (retval != 0) - { - IPACMERR("Failed adding Filtering rule %pK\n", ruleTable_v2); - PERROR("unable to add filter rule:"); - - for (int cnt = 0; cnt < ruleTable_v2->num_rules; cnt++) + for (cnt=0; cnt < ruleTable->num_rules; cnt++) { - if (((struct ipa_flt_rule_add_v2 *)ruleTable_v2->rules)[cnt].status != 0) + memset(&flt_rule_entry, 0, sizeof(struct ipa_flt_rule_add_v2)); + flt_rule_entry.at_rear = ruleTable->rules[cnt].at_rear; + flt_rule_entry.rule.retain_hdr = ruleTable->rules[cnt].rule.retain_hdr; + flt_rule_entry.rule.to_uc = ruleTable->rules[cnt].rule.to_uc; + flt_rule_entry.rule.action = ruleTable->rules[cnt].rule.action; + flt_rule_entry.rule.rt_tbl_hdl = ruleTable->rules[cnt].rule.rt_tbl_hdl; + flt_rule_entry.rule.rt_tbl_idx = ruleTable->rules[cnt].rule.rt_tbl_idx; + flt_rule_entry.rule.eq_attrib_type = ruleTable->rules[cnt].rule.eq_attrib_type; + flt_rule_entry.rule.max_prio = ruleTable->rules[cnt].rule.max_prio; + flt_rule_entry.rule.hashable = ruleTable->rules[cnt].rule.hashable; + flt_rule_entry.rule.rule_id = ruleTable->rules[cnt].rule.rule_id; + flt_rule_entry.rule.set_metadata = ruleTable->rules[cnt].rule.set_metadata; + flt_rule_entry.rule.pdn_idx = ruleTable->rules[cnt].rule.pdn_idx; + memcpy(&flt_rule_entry.rule.eq_attrib, + &ruleTable->rules[cnt].rule.eq_attrib, + sizeof(flt_rule_entry.rule.eq_attrib)); + memcpy(&flt_rule_entry.rule.attrib, + &ruleTable->rules[cnt].rule.attrib, + sizeof(flt_rule_entry.rule.attrib)); + IPACMDBG("Filter rule:%d attrib mask: 0x%x\n", cnt, + ruleTable->rules[cnt].rule.attrib.attrib_mask); + /* 0 means disable hw-counter-sats */ + if (hw_counter_index != 0) + { + flt_rule_entry.rule.enable_stats = 1; + flt_rule_entry.rule.cnt_idx = hw_counter_index; + } + + /* copy to v2 table*/ + memcpy((void *)(ruleTable_v2->rules + (cnt * sizeof(struct ipa_flt_rule_add_v2))), + &flt_rule_entry, sizeof(flt_rule_entry)); + } + + retval = ioctl(fd, IPA_IOC_ADD_FLT_RULE_AFTER_V2, ruleTable_v2); + if (retval != 0) + { + IPACMERR("Failed adding Filtering rule %pK\n", ruleTable_v2); + PERROR("unable to add filter rule:"); + + for (int cnt = 0; cnt < ruleTable_v2->num_rules; cnt++) + { + if (((struct ipa_flt_rule_add_v2 *)ruleTable_v2->rules)[cnt].status != 0) + { + IPACMERR("Adding Filter rule:%d failed with status:%d\n", + cnt, ((struct ipa_flt_rule_add_v2 *)ruleTable_v2->rules)[cnt].status); + } + } + ret = false; + goto fail_rule; + } + + /* copy results from v2 to v1 format */ + for (int cnt = 0; cnt < ruleTable->num_rules; cnt++) + { + /* copy status to v1 format */ + ruleTable->rules[cnt].status = ((struct ipa_flt_rule_add_v2 *)ruleTable_v2->rules)[cnt].status; + ruleTable->rules[cnt].flt_rule_hdl = ((struct ipa_flt_rule_add_v2 *)ruleTable_v2->rules)[cnt].flt_rule_hdl; + + if(((struct ipa_flt_rule_add_v2 *)ruleTable_v2->rules)[cnt].status != 0) { IPACMERR("Adding Filter rule:%d failed with status:%d\n", - cnt, ((struct ipa_flt_rule_add_v2 *)ruleTable_v2->rules)[cnt].status); + cnt, ((struct ipa_flt_rule_add_v2 *) ruleTable_v2->rules)[cnt].status); } } - ret = false; - goto fail_rule; - } - /* copy results from v2 to v1 format */ - for (int cnt = 0; cnt < ruleTable->num_rules; cnt++) + IPACMDBG("Added Filtering rule %pK\n", ruleTable_v2); + + fail_rule: + if((void *)ruleTable_v2->rules != NULL) + free((void *)ruleTable_v2->rules); + fail_tbl: + if (ruleTable_v2 != NULL) + free(ruleTable_v2); + } + else { - /* copy status to v1 format */ - ruleTable->rules[cnt].status = ((struct ipa_flt_rule_add_v2 *)ruleTable_v2->rules)[cnt].status; - ruleTable->rules[cnt].flt_rule_hdl = ((struct ipa_flt_rule_add_v2 *)ruleTable_v2->rules)[cnt].flt_rule_hdl; - - if(((struct ipa_flt_rule_add_v2 *)ruleTable_v2->rules)[cnt].status != 0) - { - IPACMERR("Adding Filter rule:%d failed with status:%d\n", - cnt, ((struct ipa_flt_rule_add_v2 *) ruleTable_v2->rules)[cnt].status); - } + if (ruleTable) + IPACMERR("Not support adding Filtering rule %pK\n", ruleTable); } - - IPACMDBG("Added Filtering rule %pK\n", ruleTable_v2); - -fail_rule: - if((void *)ruleTable_v2->rules != NULL) - free((void *)ruleTable_v2->rules); -fail_tbl: - if (ruleTable_v2 != NULL) - free(ruleTable_v2); -#else - if (ruleTable) - IPACMERR("Not support adding Filtering rule %pK\n", ruleTable); -#endif return ret; } #endif //IPA_IOCTL_SET_FNR_COUNTER_INFO bool IPACM_Filtering::AddFilteringRuleAfter(struct ipa_ioc_add_flt_rule_after const *ruleTable) { -#ifdef FEATURE_IPA_V3 int retval = 0; - IPACMDBG("Printing filter add attributes\n"); - IPACMDBG("ip type: %d\n", ruleTable->ip); - IPACMDBG("Number of rules: %d\n", ruleTable->num_rules); - IPACMDBG("End point: %d\n", ruleTable->ep); - IPACMDBG("commit value: %d\n", ruleTable->commit); - - retval = ioctl(fd, IPA_IOC_ADD_FLT_RULE_AFTER, ruleTable); - - for (int cnt = 0; cntnum_rules; cnt++) + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) { - if(ruleTable->rules[cnt].status != 0) + IPACMDBG("Printing filter add attributes\n"); + IPACMDBG("ip type: %d\n", ruleTable->ip); + IPACMDBG("Number of rules: %d\n", ruleTable->num_rules); + IPACMDBG("End point: %d\n", ruleTable->ep); + IPACMDBG("commit value: %d\n", ruleTable->commit); + + retval = ioctl(fd, IPA_IOC_ADD_FLT_RULE_AFTER, ruleTable); + + for (int cnt = 0; cntnum_rules; cnt++) { - IPACMERR("Adding Filter rule:%d failed with status:%d\n", - cnt, ruleTable->rules[cnt].status); + if(ruleTable->rules[cnt].status != 0) + { + IPACMERR("Adding Filter rule:%d failed with status:%d\n", + cnt, ruleTable->rules[cnt].status); + } } - } - if (retval != 0) - { - IPACMERR("Failed adding Filtering rule %pK\n", ruleTable); - return false; + if (retval != 0) + { + IPACMERR("Failed adding Filtering rule %pK\n", ruleTable); + return false; + } + IPACMDBG("Added Filtering rule %pK\n", ruleTable); + } + else + { + if (ruleTable) + IPACMERR("Not support adding Filtering rule %pK\n", ruleTable); } - IPACMDBG("Added Filtering rule %pK\n", ruleTable); -#else - if (ruleTable) - IPACMERR("Not support adding Filtering rule %pK\n", ruleTable); -#endif return true; } @@ -502,9 +509,7 @@ bool IPACM_Filtering::AddWanDLFilteringRule(struct ipa_ioc_add_flt_rule const *r { int ret = 0, cnt, num_rules = 0, pos = 0; ipa_install_fltr_rule_req_msg_v01 qmi_rule_msg; -#ifdef FEATURE_IPA_V3 ipa_install_fltr_rule_req_ex_msg_v01 qmi_rule_ex_msg; -#endif memset(&qmi_rule_msg, 0, sizeof(qmi_rule_msg)); int fd_wwan_ioctl = open(WWAN_QMI_IOCTL_DEVICE_NAME, O_RDWR); @@ -526,175 +531,178 @@ bool IPACM_Filtering::AddWanDLFilteringRule(struct ipa_ioc_add_flt_rule const *r } /* if it is not IPA v3, use old QMI format */ -#ifndef FEATURE_IPA_V3 - if(num_rules > QMI_IPA_MAX_FILTERS_V01) + if (!IPACM_Iface::ipacmcfg->isIPAv3Supported()) { - IPACMERR("The number of filtering rules exceed limit.\n"); - close(fd_wwan_ioctl); - return false; - } - else - { - if (num_rules > 0) + if(num_rules > QMI_IPA_MAX_FILTERS_V01) { - qmi_rule_msg.filter_spec_list_valid = true; - } - else - { - qmi_rule_msg.filter_spec_list_valid = false; - } - - qmi_rule_msg.filter_spec_list_len = num_rules; - qmi_rule_msg.source_pipe_index_valid = 0; - - IPACMDBG_H("Get %d WAN DL filtering rules in total.\n", num_rules); - - if(rule_table_v4 != NULL) - { - for(cnt = rule_table_v4->num_rules - 1; cnt >= 0; cnt--) - { - if (pos < QMI_IPA_MAX_FILTERS_V01) - { - qmi_rule_msg.filter_spec_list[pos].filter_spec_identifier = pos; - qmi_rule_msg.filter_spec_list[pos].ip_type = QMI_IPA_IP_TYPE_V4_V01; - qmi_rule_msg.filter_spec_list[pos].filter_action = GetQmiFilterAction(rule_table_v4->rules[cnt].rule.action); - qmi_rule_msg.filter_spec_list[pos].is_routing_table_index_valid = 1; - qmi_rule_msg.filter_spec_list[pos].route_table_index = rule_table_v4->rules[cnt].rule.rt_tbl_idx; - qmi_rule_msg.filter_spec_list[pos].is_mux_id_valid = 1; - qmi_rule_msg.filter_spec_list[pos].mux_id = mux_id; - memcpy(&qmi_rule_msg.filter_spec_list[pos].filter_rule, - &rule_table_v4->rules[cnt].rule.eq_attrib, - sizeof(struct ipa_filter_rule_type_v01)); - pos++; - } - else - { - IPACMERR(" QMI only support max %d rules, current (%d)\n ",QMI_IPA_MAX_FILTERS_V01, pos); - } - } - } - - if(rule_table_v6 != NULL) - { - for(cnt = rule_table_v6->num_rules - 1; cnt >= 0; cnt--) - { - if (pos < QMI_IPA_MAX_FILTERS_V01) - { - qmi_rule_msg.filter_spec_list[pos].filter_spec_identifier = pos; - qmi_rule_msg.filter_spec_list[pos].ip_type = QMI_IPA_IP_TYPE_V6_V01; - qmi_rule_msg.filter_spec_list[pos].filter_action = GetQmiFilterAction(rule_table_v6->rules[cnt].rule.action); - qmi_rule_msg.filter_spec_list[pos].is_routing_table_index_valid = 1; - qmi_rule_msg.filter_spec_list[pos].route_table_index = rule_table_v6->rules[cnt].rule.rt_tbl_idx; - qmi_rule_msg.filter_spec_list[pos].is_mux_id_valid = 1; - qmi_rule_msg.filter_spec_list[pos].mux_id = mux_id; - memcpy(&qmi_rule_msg.filter_spec_list[pos].filter_rule, - &rule_table_v6->rules[cnt].rule.eq_attrib, - sizeof(struct ipa_filter_rule_type_v01)); - pos++; - } - else - { - IPACMERR(" QMI only support max %d rules, current (%d)\n ",QMI_IPA_MAX_FILTERS_V01, pos); - } - } - } - - ret = ioctl(fd_wwan_ioctl, WAN_IOC_ADD_FLT_RULE, &qmi_rule_msg); - if (ret != 0) - { - IPACMERR("Failed adding Filtering rule %p with ret %d\n ", &qmi_rule_msg, ret); + IPACMERR("The number of filtering rules exceed limit.\n"); close(fd_wwan_ioctl); return false; } - } + else + { + if (num_rules > 0) + { + qmi_rule_msg.filter_spec_list_valid = true; + } + else + { + qmi_rule_msg.filter_spec_list_valid = false; + } + + qmi_rule_msg.filter_spec_list_len = num_rules; + qmi_rule_msg.source_pipe_index_valid = 0; + + IPACMDBG_H("Get %d WAN DL filtering rules in total.\n", num_rules); + + if(rule_table_v4 != NULL) + { + for(cnt = rule_table_v4->num_rules - 1; cnt >= 0; cnt--) + { + if (pos < QMI_IPA_MAX_FILTERS_V01) + { + qmi_rule_msg.filter_spec_list[pos].filter_spec_identifier = pos; + qmi_rule_msg.filter_spec_list[pos].ip_type = QMI_IPA_IP_TYPE_V4_V01; + qmi_rule_msg.filter_spec_list[pos].filter_action = GetQmiFilterAction(rule_table_v4->rules[cnt].rule.action); + qmi_rule_msg.filter_spec_list[pos].is_routing_table_index_valid = 1; + qmi_rule_msg.filter_spec_list[pos].route_table_index = rule_table_v4->rules[cnt].rule.rt_tbl_idx; + qmi_rule_msg.filter_spec_list[pos].is_mux_id_valid = 1; + qmi_rule_msg.filter_spec_list[pos].mux_id = mux_id; + memcpy(&qmi_rule_msg.filter_spec_list[pos].filter_rule, + &rule_table_v4->rules[cnt].rule.eq_attrib, + sizeof(struct ipa_filter_rule_type_v01)); + pos++; + } + else + { + IPACMERR(" QMI only support max %d rules, current (%d)\n ",QMI_IPA_MAX_FILTERS_V01, pos); + } + } + } + + if(rule_table_v6 != NULL) + { + for(cnt = rule_table_v6->num_rules - 1; cnt >= 0; cnt--) + { + if (pos < QMI_IPA_MAX_FILTERS_V01) + { + qmi_rule_msg.filter_spec_list[pos].filter_spec_identifier = pos; + qmi_rule_msg.filter_spec_list[pos].ip_type = QMI_IPA_IP_TYPE_V6_V01; + qmi_rule_msg.filter_spec_list[pos].filter_action = GetQmiFilterAction(rule_table_v6->rules[cnt].rule.action); + qmi_rule_msg.filter_spec_list[pos].is_routing_table_index_valid = 1; + qmi_rule_msg.filter_spec_list[pos].route_table_index = rule_table_v6->rules[cnt].rule.rt_tbl_idx; + qmi_rule_msg.filter_spec_list[pos].is_mux_id_valid = 1; + qmi_rule_msg.filter_spec_list[pos].mux_id = mux_id; + memcpy(&qmi_rule_msg.filter_spec_list[pos].filter_rule, + &rule_table_v6->rules[cnt].rule.eq_attrib, + sizeof(struct ipa_filter_rule_type_v01)); + pos++; + } + else + { + IPACMERR(" QMI only support max %d rules, current (%d)\n ",QMI_IPA_MAX_FILTERS_V01, pos); + } + } + } + + ret = ioctl(fd_wwan_ioctl, WAN_IOC_ADD_FLT_RULE, &qmi_rule_msg); + if (ret != 0) + { + IPACMERR("Failed adding Filtering rule %p with ret %d\n ", &qmi_rule_msg, ret); + close(fd_wwan_ioctl); + return false; + } + } /* if it is IPA v3, use new QMI format */ -#else - if(num_rules > QMI_IPA_MAX_FILTERS_EX_V01) - { - IPACMERR("The number of filtering rules exceed limit.\n"); - close(fd_wwan_ioctl); - return false; } else { - memset(&qmi_rule_ex_msg, 0, sizeof(qmi_rule_ex_msg)); - - if (num_rules > 0) + if(num_rules > QMI_IPA_MAX_FILTERS_EX_V01) { - qmi_rule_ex_msg.filter_spec_ex_list_valid = true; - } - else - { - qmi_rule_ex_msg.filter_spec_ex_list_valid = false; - } - qmi_rule_ex_msg.filter_spec_ex_list_len = num_rules; - qmi_rule_ex_msg.source_pipe_index_valid = 0; - - IPACMDBG_H("Get %d WAN DL filtering rules in total.\n", num_rules); - - if(rule_table_v4 != NULL) - { - for(cnt = rule_table_v4->num_rules - 1; cnt >= 0; cnt--) - { - if (pos < QMI_IPA_MAX_FILTERS_EX_V01) - { - qmi_rule_ex_msg.filter_spec_ex_list[pos].ip_type = QMI_IPA_IP_TYPE_V4_V01; - qmi_rule_ex_msg.filter_spec_ex_list[pos].filter_action = GetQmiFilterAction(rule_table_v4->rules[cnt].rule.action); - qmi_rule_ex_msg.filter_spec_ex_list[pos].is_routing_table_index_valid = 1; - qmi_rule_ex_msg.filter_spec_ex_list[pos].route_table_index = rule_table_v4->rules[cnt].rule.rt_tbl_idx; - qmi_rule_ex_msg.filter_spec_ex_list[pos].is_mux_id_valid = 1; - qmi_rule_ex_msg.filter_spec_ex_list[pos].mux_id = mux_id; - qmi_rule_ex_msg.filter_spec_ex_list[pos].rule_id = rule_table_v4->rules[cnt].rule.rule_id; - qmi_rule_ex_msg.filter_spec_ex_list[pos].is_rule_hashable = rule_table_v4->rules[cnt].rule.hashable; - memcpy(&qmi_rule_ex_msg.filter_spec_ex_list[pos].filter_rule, - &rule_table_v4->rules[cnt].rule.eq_attrib, - sizeof(struct ipa_filter_rule_type_v01)); - - pos++; - } - else - { - IPACMERR(" QMI only support max %d rules, current (%d)\n ",QMI_IPA_MAX_FILTERS_EX_V01, pos); - } - } - } - - if(rule_table_v6 != NULL) - { - for(cnt = rule_table_v6->num_rules - 1; cnt >= 0; cnt--) - { - if (pos < QMI_IPA_MAX_FILTERS_EX_V01) - { - qmi_rule_ex_msg.filter_spec_ex_list[pos].ip_type = QMI_IPA_IP_TYPE_V6_V01; - qmi_rule_ex_msg.filter_spec_ex_list[pos].filter_action = GetQmiFilterAction(rule_table_v6->rules[cnt].rule.action); - qmi_rule_ex_msg.filter_spec_ex_list[pos].is_routing_table_index_valid = 1; - qmi_rule_ex_msg.filter_spec_ex_list[pos].route_table_index = rule_table_v6->rules[cnt].rule.rt_tbl_idx; - qmi_rule_ex_msg.filter_spec_ex_list[pos].is_mux_id_valid = 1; - qmi_rule_ex_msg.filter_spec_ex_list[pos].mux_id = mux_id; - qmi_rule_ex_msg.filter_spec_ex_list[pos].rule_id = rule_table_v6->rules[cnt].rule.rule_id; - qmi_rule_ex_msg.filter_spec_ex_list[pos].is_rule_hashable = rule_table_v6->rules[cnt].rule.hashable; - memcpy(&qmi_rule_ex_msg.filter_spec_ex_list[pos].filter_rule, - &rule_table_v6->rules[cnt].rule.eq_attrib, - sizeof(struct ipa_filter_rule_type_v01)); - - pos++; - } - else - { - IPACMERR(" QMI only support max %d rules, current (%d)\n ",QMI_IPA_MAX_FILTERS_EX_V01, pos); - } - } - } - - ret = ioctl(fd_wwan_ioctl, WAN_IOC_ADD_FLT_RULE_EX, &qmi_rule_ex_msg); - if (ret != 0) - { - IPACMERR("Failed adding Filtering rule %pK with ret %d\n ", &qmi_rule_ex_msg, ret); + IPACMERR("The number of filtering rules exceed limit.\n"); close(fd_wwan_ioctl); return false; } + else + { + memset(&qmi_rule_ex_msg, 0, sizeof(qmi_rule_ex_msg)); + + if (num_rules > 0) + { + qmi_rule_ex_msg.filter_spec_ex_list_valid = true; + } + else + { + qmi_rule_ex_msg.filter_spec_ex_list_valid = false; + } + qmi_rule_ex_msg.filter_spec_ex_list_len = num_rules; + qmi_rule_ex_msg.source_pipe_index_valid = 0; + + IPACMDBG_H("Get %d WAN DL filtering rules in total.\n", num_rules); + + if(rule_table_v4 != NULL) + { + for(cnt = rule_table_v4->num_rules - 1; cnt >= 0; cnt--) + { + if (pos < QMI_IPA_MAX_FILTERS_EX_V01) + { + qmi_rule_ex_msg.filter_spec_ex_list[pos].ip_type = QMI_IPA_IP_TYPE_V4_V01; + qmi_rule_ex_msg.filter_spec_ex_list[pos].filter_action = GetQmiFilterAction(rule_table_v4->rules[cnt].rule.action); + qmi_rule_ex_msg.filter_spec_ex_list[pos].is_routing_table_index_valid = 1; + qmi_rule_ex_msg.filter_spec_ex_list[pos].route_table_index = rule_table_v4->rules[cnt].rule.rt_tbl_idx; + qmi_rule_ex_msg.filter_spec_ex_list[pos].is_mux_id_valid = 1; + qmi_rule_ex_msg.filter_spec_ex_list[pos].mux_id = mux_id; + qmi_rule_ex_msg.filter_spec_ex_list[pos].rule_id = rule_table_v4->rules[cnt].rule.rule_id; + qmi_rule_ex_msg.filter_spec_ex_list[pos].is_rule_hashable = rule_table_v4->rules[cnt].rule.hashable; + memcpy(&qmi_rule_ex_msg.filter_spec_ex_list[pos].filter_rule, + &rule_table_v4->rules[cnt].rule.eq_attrib, + sizeof(struct ipa_filter_rule_type_v01)); + + pos++; + } + else + { + IPACMERR(" QMI only support max %d rules, current (%d)\n ",QMI_IPA_MAX_FILTERS_EX_V01, pos); + } + } + } + + if(rule_table_v6 != NULL) + { + for(cnt = rule_table_v6->num_rules - 1; cnt >= 0; cnt--) + { + if (pos < QMI_IPA_MAX_FILTERS_EX_V01) + { + qmi_rule_ex_msg.filter_spec_ex_list[pos].ip_type = QMI_IPA_IP_TYPE_V6_V01; + qmi_rule_ex_msg.filter_spec_ex_list[pos].filter_action = GetQmiFilterAction(rule_table_v6->rules[cnt].rule.action); + qmi_rule_ex_msg.filter_spec_ex_list[pos].is_routing_table_index_valid = 1; + qmi_rule_ex_msg.filter_spec_ex_list[pos].route_table_index = rule_table_v6->rules[cnt].rule.rt_tbl_idx; + qmi_rule_ex_msg.filter_spec_ex_list[pos].is_mux_id_valid = 1; + qmi_rule_ex_msg.filter_spec_ex_list[pos].mux_id = mux_id; + qmi_rule_ex_msg.filter_spec_ex_list[pos].rule_id = rule_table_v6->rules[cnt].rule.rule_id; + qmi_rule_ex_msg.filter_spec_ex_list[pos].is_rule_hashable = rule_table_v6->rules[cnt].rule.hashable; + memcpy(&qmi_rule_ex_msg.filter_spec_ex_list[pos].filter_rule, + &rule_table_v6->rules[cnt].rule.eq_attrib, + sizeof(struct ipa_filter_rule_type_v01)); + + pos++; + } + else + { + IPACMERR(" QMI only support max %d rules, current (%d)\n ",QMI_IPA_MAX_FILTERS_EX_V01, pos); + } + } + } + + ret = ioctl(fd_wwan_ioctl, WAN_IOC_ADD_FLT_RULE_EX, &qmi_rule_ex_msg); + if (ret != 0) + { + IPACMERR("Failed adding Filtering rule %pK with ret %d\n ", &qmi_rule_ex_msg, ret); + close(fd_wwan_ioctl); + return false; + } + } } -#endif close(fd_wwan_ioctl); return true; diff --git a/data-ipa-cfg-mgr/ipacm/src/IPACM_Iface.cpp b/data-ipa-cfg-mgr/ipacm/src/IPACM_Iface.cpp index c63fa9b6..55cf71d2 100644 --- a/data-ipa-cfg-mgr/ipacm/src/IPACM_Iface.cpp +++ b/data-ipa-cfg-mgr/ipacm/src/IPACM_Iface.cpp @@ -133,9 +133,8 @@ int IPACM_Iface::handle_software_routing_enable(bool mhip) flt_rule_entry.flt_rule_hdl = -1; flt_rule_entry.status = -1; flt_rule_entry.rule.action = IPA_PASS_TO_EXCEPTION; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, sizeof(flt_rule_entry.rule.attrib)); @@ -772,10 +771,11 @@ int IPACM_Iface::init_fl_rule(ipa_ip_type iptype) flt_rule_entry.flt_rule_hdl = -1; flt_rule_entry.status = -1; flt_rule_entry.rule.action = IPA_PASS_TO_EXCEPTION; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.at_rear = false; - flt_rule_entry.rule.hashable = false; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + { + flt_rule_entry.at_rear = false; + flt_rule_entry.rule.hashable = false; + } IPACMDBG_H("rx property attrib mask:0x%x\n", rx_prop->rx[0].attrib.attrib_mask); memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, @@ -791,19 +791,21 @@ int IPACM_Iface::init_fl_rule(ipa_ip_type iptype) flt_rule_entry.rule.attrib.attrib_mask |= IPA_FLT_DST_ADDR; flt_rule_entry.rule.attrib.u.v4.dst_addr_mask = 0xF0000000; flt_rule_entry.rule.attrib.u.v4.dst_addr = 0xE0000000; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.at_rear = true; - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + { + flt_rule_entry.at_rear = true; + flt_rule_entry.rule.hashable = true; + } memcpy(&(m_pFilteringTable->rules[1]), &flt_rule_entry, sizeof(struct ipa_flt_rule_add)); /* Configuring Broadcast Filtering Rule */ flt_rule_entry.rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF; flt_rule_entry.rule.attrib.u.v4.dst_addr = 0xFFFFFFFF; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.at_rear = true; - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + { + flt_rule_entry.at_rear = true; + flt_rule_entry.rule.hashable = true; + } memcpy(&(m_pFilteringTable->rules[2]), &flt_rule_entry, sizeof(struct ipa_flt_rule_add)); #ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO @@ -886,10 +888,11 @@ int IPACM_Iface::init_fl_rule(ipa_ip_type iptype) flt_rule_entry.rule.attrib.u.v6.dst_addr[1] = 0x00000000; flt_rule_entry.rule.attrib.u.v6.dst_addr[2] = 0x00000000; flt_rule_entry.rule.attrib.u.v6.dst_addr[3] = 0X00000000; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.at_rear = true; - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + { + flt_rule_entry.at_rear = true; + flt_rule_entry.rule.hashable = true; + } memcpy(&(m_pFilteringTable->rules[0]), &flt_rule_entry, sizeof(struct ipa_flt_rule_add)); /* Configuring fe80::/10 Link-Scoped Unicast Filtering Rule */ @@ -901,10 +904,11 @@ int IPACM_Iface::init_fl_rule(ipa_ip_type iptype) flt_rule_entry.rule.attrib.u.v6.dst_addr[1] = 0x00000000; flt_rule_entry.rule.attrib.u.v6.dst_addr[2] = 0x00000000; flt_rule_entry.rule.attrib.u.v6.dst_addr[3] = 0X00000000; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.at_rear = true; - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + { + flt_rule_entry.at_rear = true; + flt_rule_entry.rule.hashable = true; + } memcpy(&(m_pFilteringTable->rules[1]), &flt_rule_entry, sizeof(struct ipa_flt_rule_add)); /* Configuring fec0::/10 Reserved by IETF Filtering Rule */ @@ -916,10 +920,11 @@ int IPACM_Iface::init_fl_rule(ipa_ip_type iptype) flt_rule_entry.rule.attrib.u.v6.dst_addr[1] = 0x00000000; flt_rule_entry.rule.attrib.u.v6.dst_addr[2] = 0x00000000; flt_rule_entry.rule.attrib.u.v6.dst_addr[3] = 0X00000000; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.at_rear = true; - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + { + flt_rule_entry.at_rear = true; + flt_rule_entry.rule.hashable = true; + } memcpy(&(m_pFilteringTable->rules[2]), &flt_rule_entry, sizeof(struct ipa_flt_rule_add)); /* Configuring fd00::/8 Unique Local Ipv6 Address */ @@ -931,10 +936,11 @@ int IPACM_Iface::init_fl_rule(ipa_ip_type iptype) flt_rule_entry.rule.attrib.u.v6.dst_addr[1] = 0x00000000; flt_rule_entry.rule.attrib.u.v6.dst_addr[2] = 0x00000000; flt_rule_entry.rule.attrib.u.v6.dst_addr[3] = 0X00000000; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.at_rear = true; - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + { + flt_rule_entry.at_rear = true; + flt_rule_entry.rule.hashable = true; + } memcpy(&(m_pFilteringTable->rules[3]), &flt_rule_entry, sizeof(struct ipa_flt_rule_add)); #ifdef FEATURE_IPA_ANDROID @@ -1003,7 +1009,7 @@ fail: return res; } -/* get ipa interface name */ +/* get ipa interface index from name */ int IPACM_Iface::ipa_get_if_index ( char * if_name, diff --git a/data-ipa-cfg-mgr/ipacm/src/IPACM_IfaceManager.cpp b/data-ipa-cfg-mgr/ipacm/src/IPACM_IfaceManager.cpp index 3e825dd3..1392a1ad 100644 --- a/data-ipa-cfg-mgr/ipacm/src/IPACM_IfaceManager.cpp +++ b/data-ipa-cfg-mgr/ipacm/src/IPACM_IfaceManager.cpp @@ -291,6 +291,9 @@ int IPACM_IfaceManager::create_iface_instance(ipacm_ifacemgr_data *param) IPACM_EvtDispatcher::registr(IPA_TETHERING_STATS_UPDATE_EVENT, lan); #endif IPACM_EvtDispatcher::registr(IPA_CRADLE_WAN_MODE_SWITCH, lan); +#ifdef IPA_MTU_EVENT_MAX + IPACM_EvtDispatcher::registr(IPA_MTU_UPDATE, lan); +#endif IPACM_EvtDispatcher::registr(IPA_LINK_DOWN_EVENT, lan); /* IPA_LAN_DELETE_SELF should be always last */ IPACM_EvtDispatcher::registr(IPA_LAN_DELETE_SELF, lan); @@ -406,9 +409,8 @@ int IPACM_IfaceManager::create_iface_instance(ipacm_ifacemgr_data *param) IPACM_EvtDispatcher::registr(IPA_HANDLE_WAN_DOWN_V6, wl); #endif IPACM_EvtDispatcher::registr(IPA_PRIVATE_SUBNET_CHANGE_EVENT, wl); // register for IPA_PRIVATE_SUBNET_CHANGE_EVENT event -#ifdef FEATURE_ETH_BRIDGE_LE - IPACM_EvtDispatcher::registr(IPA_CFG_CHANGE_EVENT, wl); -#endif + if (IPACM_Iface::ipacmcfg->isEthBridgingSupported()) + IPACM_EvtDispatcher::registr(IPA_CFG_CHANGE_EVENT, wl); IPACM_EvtDispatcher::registr(IPA_CRADLE_WAN_MODE_SWITCH, wl); IPACM_EvtDispatcher::registr(IPA_WLAN_LINK_DOWN_EVENT, wl); #ifndef FEATURE_IPA_ANDROID @@ -421,6 +423,9 @@ int IPACM_IfaceManager::create_iface_instance(ipacm_ifacemgr_data *param) IPACM_EvtDispatcher::registr(IPA_WLAN_FWR_SSR_BEFORE_SHUTDOWN_NOTICE, wl); #endif IPACM_EvtDispatcher::registr(IPA_WIGIG_CLIENT_ADD_EVENT, wl); +#ifdef IPA_MTU_EVENT_MAX + IPACM_EvtDispatcher::registr(IPA_MTU_UPDATE, wl); +#endif /* IPA_LAN_DELETE_SELF should be always last */ IPACM_EvtDispatcher::registr(IPA_LAN_DELETE_SELF, wl); IPACMDBG_H("ipa_WLAN (%s):ipa_index (%d) instance open/registr ok\n", wl->dev_name, wl->ipa_if_num); @@ -451,6 +456,12 @@ int IPACM_IfaceManager::create_iface_instance(ipacm_ifacemgr_data *param) else { w = new IPACM_Wan(ipa_interface_index, is_sta_mode, NULL); + if (w->rx_prop == NULL && w->tx_prop == NULL) + { + /* close the netdev instance if IPA not support*/ + w->delete_iface(); + return IPACM_FAILURE; + } } IPACM_EvtDispatcher::registr(IPA_ADDR_ADD_EVENT, w); #ifdef FEATURE_IPA_ANDROID @@ -459,6 +470,9 @@ int IPACM_IfaceManager::create_iface_instance(ipacm_ifacemgr_data *param) if(is_sta_mode == Q6_WAN) { IPACM_EvtDispatcher::registr(IPA_NETWORK_STATS_UPDATE_EVENT, w); +#ifdef IPA_MTU_EVENT_MAX + IPACM_EvtDispatcher::registr(IPA_MTU_SET, w); +#endif }; #else/* defined(FEATURE_IPA_ANDROID) */ IPACM_EvtDispatcher::registr(IPA_ROUTE_ADD_EVENT, w); diff --git a/data-ipa-cfg-mgr/ipacm/src/IPACM_Lan.cpp b/data-ipa-cfg-mgr/ipacm/src/IPACM_Lan.cpp index 5e1c4ff6..c83a729f 100644 --- a/data-ipa-cfg-mgr/ipacm/src/IPACM_Lan.cpp +++ b/data-ipa-cfg-mgr/ipacm/src/IPACM_Lan.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2013-2019, The Linux Foundation. All rights reserved. +Copyright (c) 2013-2020, The Linux Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are @@ -342,20 +342,21 @@ void IPACM_Lan::event_callback(ipa_cm_event_id event, void *param) } #endif -#ifdef FEATURE_ETH_BRIDGE_LE - if(rx_prop != NULL) + if (IPACM_Iface::ipacmcfg->isEthBridgingSupported()) { - free(rx_prop); + if(rx_prop != NULL) + { + free(rx_prop); + } + if(tx_prop != NULL) + { + free(tx_prop); + } + if(iface_query != NULL) + { + free(iface_query); + } } - if(tx_prop != NULL) - { - free(tx_prop); - } - if(iface_query != NULL) - { - free(iface_query); - } -#endif delete this; } break; @@ -750,25 +751,7 @@ void IPACM_Lan::event_callback(ipa_cm_event_id event, void *param) if (ipa_interface_index == ipa_if_num) { IPACMDBG_H("Received IPA_DOWNSTREAM_ADD event.\n"); -#ifdef FEATURE_IPA_ANDROID - if (IPACM_Wan::isXlat() && (data->prefix.iptype == IPA_IP_v4)) - { - /* indicate v4-offload */ - IPACM_OffloadManager::num_offload_v4_tethered_iface++; - IPACMDBG_H("in xlat: update num_offload_v4_tethered_iface %d\n", IPACM_OffloadManager::num_offload_v4_tethered_iface); - /* xlat not support for 2st tethered iface */ - if (IPACM_OffloadManager::num_offload_v4_tethered_iface > 1) - { - IPACMDBG_H("Not support 2st downstream iface %s for xlat, cur: %d\n", dev_name, - IPACM_OffloadManager::num_offload_v4_tethered_iface); - return; - } - } - - IPACMDBG_H(" support downstream iface %s, cur %d\n", dev_name, - IPACM_OffloadManager::num_offload_v4_tethered_iface); -#endif if (data->prefix.iptype < IPA_IP_MAX && is_downstream_set[data->prefix.iptype] == false) { IPACMDBG_H("Add downstream for IP iptype %d\n", data->prefix.iptype); @@ -1127,6 +1110,36 @@ void IPACM_Lan::event_callback(ipa_cm_event_id event, void *param) } break; +#ifdef IPA_MTU_EVENT_MAX + case IPA_MTU_UPDATE: + { + IPACMDBG_H("Received IPA_MTU_UPDATE"); + ipacm_event_mtu_info *evt_data = (ipacm_event_mtu_info *)param; + ipa_mtu_info *data = &(evt_data->mtu_info); + + /* IPA_IP_MAX means both ipv4 and ipv6 */ + if ((data->ip_type == IPA_IP_v4 || data->ip_type == IPA_IP_MAX) && IPACM_Wan::isWanUP(ipa_if_num)) + { + handle_private_subnet_android(IPA_IP_v4); + } + + /* IPA_IP_MAX means both ipv4 and ipv6 */ + if ((data->ip_type == IPA_IP_v6 || data->ip_type == IPA_IP_MAX) && IPACM_Wan::isWanUP_V6(ipa_if_num)) + { + /* check if the prefix + MTU rules are installed */ + if (ipv6_prefix_flt_rule_hdl[0] && ipv6_prefix_flt_rule_hdl[1]) + { + modify_ipv6_prefix_flt_rule(IPACM_Wan::backhaul_ipv6_prefix); + } + else + { + IPACMERR("Failed to update prefix MTU rules, no prefix rules set"); + } + } + } + break; +#endif + default: break; } @@ -1273,12 +1286,15 @@ int IPACM_Lan::handle_wan_down(ipacm_wan_iface_type backhaul_mode) return IPACM_FAILURE; } flt_index.install_status = IPA_QMI_RESULT_SUCCESS_V01; -#ifndef FEATURE_IPA_V3 - flt_index.filter_index_list_len = 0; -#else /* defined (FEATURE_IPA_V3) */ - flt_index.rule_id_valid = 1; - flt_index.rule_id_len = 0; -#endif + if (!IPACM_Iface::ipacmcfg->isIPAv3Supported()) + { + flt_index.filter_index_list_len = 0; + } + else /* IPAv3 */ + { + flt_index.rule_id_valid = 1; + flt_index.rule_id_len = 0; + } flt_index.embedded_pipe_index_valid = 1; flt_index.embedded_pipe_index = ioctl(fd, IPA_IOC_QUERY_EP_MAPPING, IPA_CLIENT_APPS_LAN_WAN_PROD); if ((int)flt_index.embedded_pipe_index == -1) @@ -1371,9 +1387,8 @@ int IPACM_Lan::handle_addr_evt(ipacm_event_data_addr *data) strlcpy(rt_rule->rt_tbl_name, IPACM_Iface::ipacmcfg->rt_tbl_lan_v4.name, sizeof(rt_rule->rt_tbl_name)); rt_rule_entry->rule.attrib.u.v4.dst_addr = data->ipv4_addr; rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF; -#ifdef FEATURE_IPA_V3 - rt_rule_entry->rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + rt_rule_entry->rule.hashable = true; if (false == m_routing.AddRoutingRule(rt_rule)) { IPACMERR("Routing rule addition failed!\n"); @@ -1449,9 +1464,8 @@ int IPACM_Lan::handle_addr_evt(ipacm_event_data_addr *data) ipv6_addr[num_dft_rt_v6][1] = data->ipv6_addr[1]; ipv6_addr[num_dft_rt_v6][2] = data->ipv6_addr[2]; ipv6_addr[num_dft_rt_v6][3] = data->ipv6_addr[3]; -#ifdef FEATURE_IPA_V3 - rt_rule_entry->rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + rt_rule_entry->rule.hashable = true; if (false == m_routing.AddRoutingRule(rt_rule)) { IPACMERR("Routing rule addition failed!\n"); @@ -1581,9 +1595,8 @@ int IPACM_Lan::handle_private_subnet(ipa_ip_type iptype) flt_rule_entry.flt_rule_hdl = -1; flt_rule_entry.status = -1; flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; /* Support private subnet feature including guest-AP can't talk to primary AP etc */ flt_rule_entry.rule.rt_tbl_hdl = IPACM_Iface::ipacmcfg->rt_tbl_default_v4.hdl; IPACMDBG_H(" private filter rule use table: %s\n",IPACM_Iface::ipacmcfg->rt_tbl_default_v4.name); @@ -1658,9 +1671,9 @@ int IPACM_Lan::handle_wan_up(ipa_ip_type ip_type) /* Update ipv6 MTU here if WAN_v6 is up and filter rules were installed */ if (IPACM_Wan::isWanUP_V6(ipa_if_num)) { - if (ipv6_prefix_flt_rule_hdl[0] && ipv6_prefix_flt_rule_hdl[1] ) { - delete_ipv6_prefix_flt_rule(); - install_ipv6_prefix_flt_rule(IPACM_Wan::backhaul_ipv6_prefix); + if (ipv6_prefix_flt_rule_hdl[0] && ipv6_prefix_flt_rule_hdl[1]) + { + modify_ipv6_prefix_flt_rule(IPACM_Wan::backhaul_ipv6_prefix); } } @@ -1707,9 +1720,8 @@ int IPACM_Lan::handle_wan_up(ipa_ip_type ip_type) { flt_rule_entry.rule.action = IPA_PASS_TO_SRC_NAT; //IPA_PASS_TO_ROUTING } -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; flt_rule_entry.rule.rt_tbl_hdl = IPACM_Iface::ipacmcfg->rt_tbl_wan_v4.hdl; memcpy(&flt_rule_entry.rule.attrib, @@ -1796,9 +1808,8 @@ int IPACM_Lan::handle_wan_up(ipa_ip_type ip_type) flt_rule_entry.flt_rule_hdl = -1; flt_rule_entry.status = -1; flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; flt_rule_entry.rule.rt_tbl_hdl = IPACM_Iface::ipacmcfg->rt_tbl_v6.hdl; memcpy(&flt_rule_entry.rule.attrib, @@ -1906,15 +1917,34 @@ int IPACM_Lan::handle_wan_up_ex(ipacm_ext_prop *ext_prop, ipa_ip_type iptype, ui ret = handle_uplink_filter_rule(ext_prop, iptype, xlat_mux_id); modem_ul_v6_set = true; } else if (iptype ==IPA_IP_v4 && modem_ul_v4_set == false) { +#ifdef FEATURE_IPA_ANDROID + if (IPACM_Wan::isXlat()) + { + /* indicate v4-offload */ + IPACM_OffloadManager::num_offload_v4_tethered_iface++; + IPACMDBG_H("in xlat: update num_offload_v4_tethered_iface %d\n", IPACM_OffloadManager::num_offload_v4_tethered_iface); + + /* xlat not support for 2st tethered iface */ + if (IPACM_OffloadManager::num_offload_v4_tethered_iface > 1) + { + IPACMDBG_H("Not support 2st downstream iface %s for xlat, cur: %d\n", dev_name, + IPACM_OffloadManager::num_offload_v4_tethered_iface); + return IPACM_FAILURE; + } + } + + IPACMDBG_H(" support downstream iface %s, cur %d\n", dev_name, + IPACM_OffloadManager::num_offload_v4_tethered_iface); +#endif /* add MTU rules for ipv4 */ handle_private_subnet_android(IPA_IP_v4); /* Update ipv6 MTU here if WAN_v6 is up and filter rules were installed */ if (IPACM_Wan::isWanUP_V6(ipa_if_num)) { - if (ipv6_prefix_flt_rule_hdl[0] && ipv6_prefix_flt_rule_hdl[1] ) { - delete_ipv6_prefix_flt_rule(); - install_ipv6_prefix_flt_rule(IPACM_Wan::backhaul_ipv6_prefix); + if (ipv6_prefix_flt_rule_hdl[0] && ipv6_prefix_flt_rule_hdl[1]) + { + modify_ipv6_prefix_flt_rule(IPACM_Wan::backhaul_ipv6_prefix); } } @@ -2458,9 +2488,8 @@ int IPACM_Lan::handle_eth_client_route_rule(uint8_t *mac_addr, ipa_ip_type iptyp rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF; rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF; rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF; -#ifdef FEATURE_IPA_V3 - rt_rule_entry->rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + rt_rule_entry->rule.hashable = true; if (false == m_routing.AddRoutingRule(rt_rule)) { IPACMERR("Routing rule addition failed!\n"); @@ -2490,9 +2519,8 @@ int IPACM_Lan::handle_eth_client_route_rule(uint8_t *mac_addr, ipa_ip_type iptyp rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF; rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF; rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF; -#ifdef FEATURE_IPA_V3 - rt_rule_entry->rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + rt_rule_entry->rule.hashable = true; if (false == m_routing.AddRoutingRule(rt_rule)) { IPACMERR("Routing rule addition failed!\n"); @@ -2773,9 +2801,8 @@ int IPACM_Lan::handle_odu_route_add() { rt_rule_entry->rule.attrib.u.v4.dst_addr = 0; rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0; -#ifdef FEATURE_IPA_V3 - rt_rule_entry->rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + rt_rule_entry->rule.hashable = true; if (false == m_routing.AddRoutingRule(rt_rule)) { IPACMERR("Routing rule addition failed!\n"); @@ -2798,9 +2825,8 @@ int IPACM_Lan::handle_odu_route_add() rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0; rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0; rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0; -#ifdef FEATURE_IPA_V3 - rt_rule_entry->rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + rt_rule_entry->rule.hashable = true; if (false == m_routing.AddRoutingRule(rt_rule)) { IPACMERR("Routing rule addition failed!\n"); @@ -3281,25 +3307,25 @@ fail: IPACM_Iface::ipacmcfg->DelRmDepend(IPACM_Iface::ipacmcfg->ipa_client_rm_map_tbl[rx_prop->rx[0].src_pipe]); IPACMDBG_H("Finished delete dependency \n "); } -#ifndef FEATURE_ETH_BRIDGE_LE - free(rx_prop); -#endif + if (!(IPACM_Iface::ipacmcfg->isEthBridgingSupported())) + free(rx_prop); } if (eth_client != NULL) { free(eth_client); } -#ifndef FEATURE_ETH_BRIDGE_LE - if (tx_prop != NULL) + if (!(IPACM_Iface::ipacmcfg->isEthBridgingSupported())) { - free(tx_prop); + if (tx_prop != NULL) + { + free(tx_prop); + } + if (iface_query != NULL) + { + free(iface_query); + } } - if (iface_query != NULL) - { - free(iface_query); - } -#endif is_active = false; post_del_self_evt(); @@ -3356,12 +3382,15 @@ int IPACM_Lan::handle_uplink_filter_rule(ipacm_ext_prop *prop, ipa_ip_type iptyp } flt_index.install_status = IPA_QMI_RESULT_SUCCESS_V01; -#ifndef FEATURE_IPA_V3 - flt_index.filter_index_list_len = prop->num_ext_props; -#else /* defined (FEATURE_IPA_V3) */ - flt_index.rule_id_valid = 1; - flt_index.rule_id_len = prop->num_ext_props; -#endif + if (!IPACM_Iface::ipacmcfg->isIPAv3Supported()) + { + flt_index.filter_index_list_len = prop->num_ext_props; + } + else /* IPAv3 */ + { + flt_index.rule_id_valid = 1; + flt_index.rule_id_len = prop->num_ext_props; + } flt_index.embedded_pipe_index_valid = 1; flt_index.embedded_pipe_index = ioctl(fd, IPA_IOC_QUERY_EP_MAPPING, IPA_CLIENT_APPS_LAN_WAN_PROD); if ((int)flt_index.embedded_pipe_index == -1) @@ -3377,13 +3406,16 @@ int IPACM_Lan::handle_uplink_filter_rule(ipacm_ext_prop *prop, ipa_ip_type iptyp qmap_id = IPACM_Iface::ipacmcfg->GetQmapId(); xlat_debug = IPACM_Wan::getXlat_Mux_Id(); flt_index.embedded_call_mux_id = qmap_id; -#ifndef FEATURE_IPA_V3 - IPACMDBG_H("flt_index: src pipe: %d, num of rules: %d, ebd pipe: %d, mux id: %d, xlat_mux id: %d, wan-debug %d\n", - flt_index.source_pipe_index, flt_index.filter_index_list_len, flt_index.embedded_pipe_index, flt_index.embedded_call_mux_id, xlat_mux_id, xlat_debug); -#else /* defined (FEATURE_IPA_V3) */ - IPACMDBG_H("flt_index: src pipe: %d, num of rules: %d, ebd pipe: %d, mux id: %d, xlat_mux id: %d, wan-debug %d\n", - flt_index.source_pipe_index, flt_index.rule_id_len, flt_index.embedded_pipe_index, flt_index.embedded_call_mux_id, xlat_mux_id, xlat_debug); -#endif + if (!IPACM_Iface::ipacmcfg->isIPAv3Supported()) + { + IPACMDBG_H("flt_index: src pipe: %d, num of rules: %d, ebd pipe: %d, mux id: %d, xlat_mux id: %d, wan-debug %d\n", + flt_index.source_pipe_index, flt_index.filter_index_list_len, flt_index.embedded_pipe_index, flt_index.embedded_call_mux_id, xlat_mux_id, xlat_debug); + } + else /* IPAv3 */ + { + IPACMDBG_H("flt_index: src pipe: %d, num of rules: %d, ebd pipe: %d, mux id: %d, xlat_mux id: %d, wan-debug %d\n", + flt_index.source_pipe_index, flt_index.rule_id_len, flt_index.embedded_pipe_index, flt_index.embedded_call_mux_id, xlat_mux_id, xlat_debug); + } len = sizeof(struct ipa_ioc_add_flt_rule) + prop->num_ext_props * sizeof(struct ipa_flt_rule_add); pFilteringTable = (struct ipa_ioc_add_flt_rule*)malloc(len); if (pFilteringTable == NULL) @@ -3402,10 +3434,9 @@ int IPACM_Lan::handle_uplink_filter_rule(ipacm_ext_prop *prop, ipa_ip_type iptyp memset(&flt_rule_entry, 0, sizeof(struct ipa_flt_rule_add)); // Zero All Fields flt_rule_entry.at_rear = 1; -#ifdef FEATURE_IPA_V3 - if (flt_rule_entry.rule.eq_attrib.ipv4_frag_eq_present) - flt_rule_entry.at_rear = 0; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + if (flt_rule_entry.rule.eq_attrib.ipv4_frag_eq_present) + flt_rule_entry.at_rear = 0; flt_rule_entry.flt_rule_hdl = -1; flt_rule_entry.status = -1; @@ -3482,25 +3513,28 @@ int IPACM_Lan::handle_uplink_filter_rule(ipacm_ext_prop *prop, ipa_ip_type iptyp { flt_rule_entry.rule.eq_attrib.num_offset_meq_32++; eq_index = flt_rule_entry.rule.eq_attrib.num_offset_meq_32 - 1; -#ifdef FEATURE_IPA_V3 - if(eq_index == 0) + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) { - flt_rule_entry.rule.eq_attrib.rule_eq_bitmap |= (1<<5); + if(eq_index == 0) + { + flt_rule_entry.rule.eq_attrib.rule_eq_bitmap |= (1<<5); + } + else + { + flt_rule_entry.rule.eq_attrib.rule_eq_bitmap |= (1<<6); + } } else { - flt_rule_entry.rule.eq_attrib.rule_eq_bitmap |= (1<<6); + if(eq_index == 0) + { + flt_rule_entry.rule.eq_attrib.rule_eq_bitmap |= (1<<2); + } + else + { + flt_rule_entry.rule.eq_attrib.rule_eq_bitmap |= (1<<3); + } } -#else - if(eq_index == 0) - { - flt_rule_entry.rule.eq_attrib.rule_eq_bitmap |= (1<<2); - } - else - { - flt_rule_entry.rule.eq_attrib.rule_eq_bitmap |= (1<<3); - } -#endif flt_rule_entry.rule.eq_attrib.offset_meq_32[eq_index].offset = 12; flt_rule_entry.rule.eq_attrib.offset_meq_32[eq_index].mask = prefix[IPA_IP_v4].v4Mask; flt_rule_entry.rule.eq_attrib.offset_meq_32[eq_index].value = prefix[IPA_IP_v4].v4Addr; @@ -3518,88 +3552,95 @@ int IPACM_Lan::handle_uplink_filter_rule(ipacm_ext_prop *prop, ipa_ip_type iptyp { flt_rule_entry.rule.eq_attrib.num_offset_meq_128++; eq_index = flt_rule_entry.rule.eq_attrib.num_offset_meq_128 - 1; -#ifdef FEATURE_IPA_V3 - if(eq_index == 0) + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) { - flt_rule_entry.rule.eq_attrib.rule_eq_bitmap |= (1<<3); + if(eq_index == 0) + { + flt_rule_entry.rule.eq_attrib.rule_eq_bitmap |= (1<<3); + } + else + { + flt_rule_entry.rule.eq_attrib.rule_eq_bitmap |= (1<<4); + } + *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].mask + 0) + = prefix[IPA_IP_v6].v6Mask[3]; + *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].mask + 4) + = prefix[IPA_IP_v6].v6Mask[2]; + *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].mask + 8) + = prefix[IPA_IP_v6].v6Mask[1]; + *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].mask + 12) + = prefix[IPA_IP_v6].v6Mask[0]; + *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].value + 0) + = prefix[IPA_IP_v6].v6Addr[3]; + *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].value + 4) + = prefix[IPA_IP_v6].v6Addr[2]; + *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].value + 8) + = prefix[IPA_IP_v6].v6Addr[1]; + *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].value + 12) + = prefix[IPA_IP_v6].v6Addr[0]; } else { - flt_rule_entry.rule.eq_attrib.rule_eq_bitmap |= (1<<4); + if(eq_index == 0) + { + flt_rule_entry.rule.eq_attrib.rule_eq_bitmap |= (1<<9); + } + else + { + flt_rule_entry.rule.eq_attrib.rule_eq_bitmap |= (1<<10); + } + *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].mask + 0) + = prefix[IPA_IP_v6].v6Mask[0]; + *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].mask + 4) + = prefix[IPA_IP_v6].v6Mask[1]; + *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].mask + 8) + = prefix[IPA_IP_v6].v6Mask[2]; + *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].mask + 12) + = prefix[IPA_IP_v6].v6Mask[3]; + *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].value + 0) + = prefix[IPA_IP_v6].v6Addr[0]; + *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].value + 4) + = prefix[IPA_IP_v6].v6Addr[1]; + *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].value + 8) + = prefix[IPA_IP_v6].v6Addr[2]; + *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].value + 12) + = prefix[IPA_IP_v6].v6Addr[3]; } - *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].mask + 0) - = prefix[IPA_IP_v6].v6Mask[3]; - *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].mask + 4) - = prefix[IPA_IP_v6].v6Mask[2]; - *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].mask + 8) - = prefix[IPA_IP_v6].v6Mask[1]; - *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].mask + 12) - = prefix[IPA_IP_v6].v6Mask[0]; - *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].value + 0) - = prefix[IPA_IP_v6].v6Addr[3]; - *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].value + 4) - = prefix[IPA_IP_v6].v6Addr[2]; - *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].value + 8) - = prefix[IPA_IP_v6].v6Addr[1]; - *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].value + 12) - = prefix[IPA_IP_v6].v6Addr[0]; -#else - if(eq_index == 0) - { - flt_rule_entry.rule.eq_attrib.rule_eq_bitmap |= (1<<9); - } - else - { - flt_rule_entry.rule.eq_attrib.rule_eq_bitmap |= (1<<10); - } - *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].mask + 0) - = prefix[IPA_IP_v6].v6Mask[0]; - *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].mask + 4) - = prefix[IPA_IP_v6].v6Mask[1]; - *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].mask + 8) - = prefix[IPA_IP_v6].v6Mask[2]; - *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].mask + 12) - = prefix[IPA_IP_v6].v6Mask[3]; - *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].value + 0) - = prefix[IPA_IP_v6].v6Addr[0]; - *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].value + 4) - = prefix[IPA_IP_v6].v6Addr[1]; - *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].value + 8) - = prefix[IPA_IP_v6].v6Addr[2]; - *(uint32_t *)(flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].value + 12) - = prefix[IPA_IP_v6].v6Addr[3]; -#endif flt_rule_entry.rule.eq_attrib.offset_meq_128[eq_index].offset = 8; } else { IPACMERR("Run out of MEQ128 equation.\n"); - flt_rule_entry.rule.eq_attrib.num_offset_meq_128--; + flt_rule_entry.rule.eq_attrib.num_offset_meq_128--; } } -#endif -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = prop->prop[cnt].is_rule_hashable; - flt_rule_entry.rule.rule_id = prop->prop[cnt].rule_id; - if(rx_prop->rx[0].attrib.attrib_mask & IPA_FLT_META_DATA) //turn on meta-data equation - { - flt_rule_entry.rule.eq_attrib.rule_eq_bitmap |= (1<<9); - flt_rule_entry.rule.eq_attrib.metadata_meq32_present = 1; - flt_rule_entry.rule.eq_attrib.metadata_meq32.offset = 0; - flt_rule_entry.rule.eq_attrib.metadata_meq32.value |= rx_prop->rx[0].attrib.meta_data; - flt_rule_entry.rule.eq_attrib.metadata_meq32.mask |= rx_prop->rx[0].attrib.meta_data_mask; - } #endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + { + flt_rule_entry.rule.hashable = prop->prop[cnt].is_rule_hashable; + flt_rule_entry.rule.rule_id = prop->prop[cnt].rule_id; + if(rx_prop->rx[0].attrib.attrib_mask & IPA_FLT_META_DATA) //turn on meta-data equation + { + flt_rule_entry.rule.eq_attrib.rule_eq_bitmap |= (1<<9); + flt_rule_entry.rule.eq_attrib.metadata_meq32_present = 1; + flt_rule_entry.rule.eq_attrib.metadata_meq32.offset = 0; + flt_rule_entry.rule.eq_attrib.metadata_meq32.value |= rx_prop->rx[0].attrib.meta_data; + flt_rule_entry.rule.eq_attrib.metadata_meq32.mask |= rx_prop->rx[0].attrib.meta_data_mask; + } + } memcpy(&pFilteringTable->rules[cnt], &flt_rule_entry, sizeof(flt_rule_entry)); IPACMDBG_H("Modem UL filtering rule %d has index %d\n", cnt, index); -#ifndef FEATURE_IPA_V3 - flt_index.filter_index_list[cnt].filter_index = index; - flt_index.filter_index_list[cnt].filter_handle = prop->prop[cnt].filter_hdl; -#else /* defined (FEATURE_IPA_V3) */ - flt_index.rule_id[cnt] = prop->prop[cnt].rule_id; -#endif + if (!IPACM_Iface::ipacmcfg->isIPAv3Supported()) + { + flt_index.filter_index_list[cnt].filter_index = index; + flt_index.filter_index_list[cnt].filter_handle = prop->prop[cnt].filter_hdl; + } + else /* IPAv3 */ + { + flt_index.rule_id[cnt] = prop->prop[cnt].rule_id; + } index++; } @@ -3717,12 +3758,15 @@ int IPACM_Lan::handle_wan_down_v6(ipacm_wan_iface_type backhaul_mode) return IPACM_FAILURE; } flt_index.install_status = IPA_QMI_RESULT_SUCCESS_V01; -#ifndef FEATURE_IPA_V3 - flt_index.filter_index_list_len = 0; -#else /* defined (FEATURE_IPA_V3) */ - flt_index.rule_id_valid = 1; - flt_index.rule_id_len = 0; -#endif + if (!IPACM_Iface::ipacmcfg->isIPAv3Supported()) + { + flt_index.filter_index_list_len = 0; + } + else /* IPAv3 */ + { + flt_index.rule_id_valid = 1; + flt_index.rule_id_len = 0; + } flt_index.embedded_pipe_index_valid = 1; flt_index.embedded_pipe_index = ioctl(fd, IPA_IOC_QUERY_EP_MAPPING, IPA_CLIENT_APPS_LAN_WAN_PROD); if ((int)flt_index.embedded_pipe_index == -1) @@ -3947,9 +3991,8 @@ int IPACM_Lan::install_ipv4_icmp_flt_rule() flt_rule_entry.flt_rule_hdl = -1; flt_rule_entry.status = -1; flt_rule_entry.rule.action = IPA_PASS_TO_EXCEPTION; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, sizeof(flt_rule_entry.rule.attrib)); flt_rule_entry.rule.attrib.attrib_mask |= IPA_FLT_PROTOCOL; @@ -4020,9 +4063,8 @@ int IPACM_Lan::install_ipv6_icmp_flt_rule() flt_rule_entry.flt_rule_hdl = -1; flt_rule_entry.status = -1; flt_rule_entry.rule.action = IPA_PASS_TO_EXCEPTION; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = false; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = false; memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, sizeof(flt_rule_entry.rule.attrib)); flt_rule_entry.rule.attrib.attrib_mask |= IPA_FLT_NEXT_HDR; flt_rule_entry.rule.attrib.u.v6.next_hdr = (uint8_t)IPACM_FIREWALL_IPPROTO_ICMP6; @@ -4099,9 +4141,8 @@ int IPACM_Lan::add_dummy_private_subnet_flt_rule(ipa_ip_type iptype) flt_rule.flt_rule_hdl = -1; flt_rule.status = -1; flt_rule.rule.action = IPA_PASS_TO_EXCEPTION; -#ifdef FEATURE_IPA_V3 - flt_rule.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule.rule.hashable = true; memcpy(&flt_rule.rule.attrib, &rx_prop->rx[0].attrib, sizeof(flt_rule.rule.attrib)); @@ -4201,7 +4242,7 @@ int IPACM_Lan::handle_private_subnet_android(ipa_ip_type iptype) } else { - IPACMERR("MTU is 0"); + IPACMDBG_H("MTU is zero\n"); } } IPACMDBG_H("total %d MTU rules are needed\n", mtu_rule_cnt); @@ -4282,8 +4323,13 @@ fail: return res; } -int IPACM_Lan::install_ipv6_prefix_flt_rule(uint32_t* prefix) +int IPACM_Lan::modify_ipv6_prefix_flt_rule(uint32_t* prefix) { + int len, res = IPACM_SUCCESS; + struct ipa_flt_rule_mdfy flt_rule_entry; + struct ipa_ioc_mdfy_flt_rule* flt_rule; + int rule_cnt = 1; + if(prefix == NULL) { IPACMERR("IPv6 prefix is empty.\n"); @@ -4291,12 +4337,114 @@ int IPACM_Lan::install_ipv6_prefix_flt_rule(uint32_t* prefix) } IPACMDBG_H("Receive IPv6 prefix: 0x%08x%08x.\n", prefix[0], prefix[1]); + uint16_t mtu = IPACM_Wan::queryMTU(ipa_if_num, IPA_IP_v6); + if (mtu > 0) + { + IPACMDBG_H("MTU is %d\n", mtu); + rule_cnt ++; + } + else + { + IPACMERR("MTU is 0"); + } + + + if(rx_prop == NULL) + { + IPACMERR("no rx props\n"); + return IPACM_FAILURE; + } + + len = sizeof(struct ipa_ioc_mdfy_flt_rule) + rule_cnt * sizeof(struct ipa_flt_rule_mdfy); + flt_rule = (struct ipa_ioc_mdfy_flt_rule*)malloc(len); + if(!flt_rule) + { + IPACMERR("Failed to allocate ipa_ioc_mdfy_flt_rule memory...\n"); + return IPACM_FAILURE; + } + memset(flt_rule, 0, len); + + flt_rule->commit = 1; + flt_rule->ip = IPA_IP_v6; + flt_rule->num_rules = rule_cnt; + + memset(&flt_rule_entry, 0, sizeof(struct ipa_flt_rule_mdfy)); + flt_rule_entry.status = -1; + flt_rule_entry.rule.retain_hdr = 1; + flt_rule_entry.rule.to_uc = 0; + flt_rule_entry.rule.action = IPA_PASS_TO_EXCEPTION; + flt_rule_entry.rule.eq_attrib_type = 0; + flt_rule_entry.rule_hdl = ipv6_prefix_flt_rule_hdl[0]; + + memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, sizeof(flt_rule_entry.rule.attrib)); + flt_rule_entry.rule.attrib.attrib_mask |= IPA_FLT_DST_ADDR; + flt_rule_entry.rule.attrib.u.v6.dst_addr[0] = prefix[0]; + flt_rule_entry.rule.attrib.u.v6.dst_addr[1] = prefix[1]; + flt_rule_entry.rule.attrib.u.v6.dst_addr[2] = 0x0; + flt_rule_entry.rule.attrib.u.v6.dst_addr[3] = 0x0; + flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF; + flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF; + flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[2] = 0x0; + flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[3] = 0x0; + memcpy(&(flt_rule->rules[0]), &flt_rule_entry, sizeof(struct ipa_flt_rule_mdfy)); + + + flt_rule_entry.rule_hdl = ipv6_prefix_flt_rule_hdl[1]; + memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, sizeof(flt_rule_entry.rule.attrib)); // this will remove the IPA_FLT_DST_ADDR + flt_rule_entry.rule.attrib.u.v6.src_addr[3] = prefix[0]; + flt_rule_entry.rule.attrib.u.v6.src_addr[2] = prefix[1]; + flt_rule_entry.rule.attrib.u.v6.src_addr[1] = 0x0; + flt_rule_entry.rule.attrib.u.v6.src_addr[0] = 0x0; + flt_rule_entry.rule.attrib.u.v6.src_addr_mask[3] = 0xFFFFFFFF; + flt_rule_entry.rule.attrib.u.v6.src_addr_mask[2] = 0xFFFFFFFF; + flt_rule_entry.rule.attrib.u.v6.src_addr_mask[1] = 0x0; + flt_rule_entry.rule.attrib.u.v6.src_addr_mask[0] = 0x0; + flt_rule_entry.rule.attrib.attrib_mask |= IPA_FLT_SRC_ADDR; + + /* Add an MTU rule with every new private prefix */ + if (mtu > 0) + { + if (construct_mtu_rule(&flt_rule_entry.rule, IPA_IP_v6, mtu)) + { + IPACMERR("Failed to add MTU filtering rule.\n") + } + else + { + memcpy(&(flt_rule->rules[1]), &flt_rule_entry, sizeof(struct ipa_flt_rule_mdfy)); + } + } + + + if(false == m_filtering.ModifyFilteringRule(flt_rule)) + { + IPACMERR("Failed to modify prefix filtering rules.\n"); + res = IPACM_FAILURE; + goto fail; + } + +fail: + if(flt_rule != NULL) + { + free(flt_rule); + } + return res; +} + +int IPACM_Lan::install_ipv6_prefix_flt_rule(uint32_t* prefix) +{ int len; struct ipa_ioc_add_flt_rule* flt_rule; struct ipa_flt_rule_add flt_rule_entry; bool result; int rule_cnt = 1; + if(prefix == NULL) + { + IPACMERR("IPv6 prefix is empty.\n"); + return IPACM_FAILURE; + } + IPACMDBG_H("Receive IPv6 prefix: 0x%08x%08x.\n", prefix[0], prefix[1]); + uint16_t mtu = IPACM_Wan::queryMTU(ipa_if_num, IPA_IP_v6); if (mtu > 0) { @@ -4334,9 +4482,8 @@ int IPACM_Lan::install_ipv6_prefix_flt_rule(uint32_t* prefix) flt_rule_entry.flt_rule_hdl = -1; flt_rule_entry.status = -1; flt_rule_entry.rule.action = IPA_PASS_TO_EXCEPTION; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, sizeof(flt_rule_entry.rule.attrib)); flt_rule_entry.rule.attrib.attrib_mask |= IPA_FLT_DST_ADDR; flt_rule_entry.rule.attrib.u.v6.dst_addr[0] = prefix[0]; @@ -4373,18 +4520,7 @@ int IPACM_Lan::install_ipv6_prefix_flt_rule(uint32_t* prefix) } } -#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO - /* use index hw-counter */ - if(ipa_if_cate == WLAN_IF && IPACM_Iface::ipacmcfg->hw_fnr_stats_support) - { - IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); - result = m_filtering.AddFilteringRule_hw_index(flt_rule, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); - } else { - result = m_filtering.AddFilteringRule(flt_rule); - } -#else result = m_filtering.AddFilteringRule(flt_rule); -#endif if (result == false) { @@ -5050,9 +5186,8 @@ int IPACM_Lan::eth_bridge_add_rt_rule(uint8_t *mac, char *rt_tbl_name, uint32_t rt_rule.at_rear = false; rt_rule.status = -1; rt_rule.rt_rule_hdl = -1; -#ifdef FEATURE_IPA_V3 - rt_rule.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + rt_rule.rule.hashable = true; rt_rule.rule.hdr_hdl = 0; rt_rule.rule.hdr_proc_ctx_hdl = hdr_proc_ctx_hdl; @@ -5184,9 +5319,8 @@ int IPACM_Lan::eth_bridge_modify_rt_rule(uint8_t *mac, uint32_t hdr_proc_ctx_hdl rt_rule_entry->rule.hdr_hdl = 0; rt_rule_entry->rule.hdr_proc_ctx_hdl = hdr_proc_ctx_hdl; -#ifdef FEATURE_IPA_V3 - rt_rule_entry->rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + rt_rule_entry->rule.hashable = true; memcpy(&rt_rule_entry->rule.attrib, &tx_prop->tx[index].attrib, sizeof(rt_rule_entry->rule.attrib)); if(peer_l2_hdr_type == IPA_HDR_L2_ETHERNET_II) @@ -5225,90 +5359,92 @@ end: int IPACM_Lan::eth_bridge_add_flt_rule(uint8_t *mac, uint32_t rt_tbl_hdl, ipa_ip_type iptype, uint32_t *flt_rule_hdl) { int res = IPACM_SUCCESS; - - IPACMDBG_H("Received client MAC 0x%02x%02x%02x%02x%02x%02x.\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - IPACMDBG_H("Received rt_tbl_hdl :%d iptype %d\n", rt_tbl_hdl,iptype); - *flt_rule_hdl = 0; - -#ifdef FEATURE_IPA_V3 int len; struct ipa_flt_rule_add flt_rule_entry; struct ipa_ioc_add_flt_rule_after *pFilteringTable = NULL; bool result; - if (rx_prop == NULL || tx_prop == NULL) + IPACMDBG_H("Received client MAC 0x%02x%02x%02x%02x%02x%02x.\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + IPACMDBG_H("Received rt_tbl_hdl :%d iptype %d\n", rt_tbl_hdl,iptype); + *flt_rule_hdl = 0; + + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) { - IPACMDBG_H("No rx or tx properties registered for iface %s\n", dev_name); - return IPACM_FAILURE; - } + if (rx_prop == NULL || tx_prop == NULL) + { + IPACMDBG_H("No rx or tx properties registered for iface %s\n", dev_name); + return IPACM_FAILURE; + } - len = sizeof(struct ipa_ioc_add_flt_rule_after) + sizeof(struct ipa_flt_rule_add); - pFilteringTable = (struct ipa_ioc_add_flt_rule_after*)malloc(len); - if (!pFilteringTable) - { - IPACMERR("Failed to allocate ipa_ioc_add_flt_rule_after memory...\n"); - return IPACM_FAILURE; - } - memset(pFilteringTable, 0, len); + len = sizeof(struct ipa_ioc_add_flt_rule_after) + sizeof(struct ipa_flt_rule_add); + pFilteringTable = (struct ipa_ioc_add_flt_rule_after*)malloc(len); + if (!pFilteringTable) + { + IPACMERR("Failed to allocate ipa_ioc_add_flt_rule_after memory...\n"); + return IPACM_FAILURE; + } + memset(pFilteringTable, 0, len); - /* add mac based rule*/ - pFilteringTable->commit = 1; - pFilteringTable->ep = rx_prop->rx[0].src_pipe; - pFilteringTable->ip = iptype; - pFilteringTable->num_rules = 1; - pFilteringTable->add_after_hdl = eth_bridge_flt_rule_offset[iptype]; + /* add mac based rule*/ + pFilteringTable->commit = 1; + pFilteringTable->ep = rx_prop->rx[0].src_pipe; + pFilteringTable->ip = iptype; + pFilteringTable->num_rules = 1; + pFilteringTable->add_after_hdl = eth_bridge_flt_rule_offset[iptype]; - memset(&flt_rule_entry, 0, sizeof(flt_rule_entry)); - flt_rule_entry.at_rear = 1; + memset(&flt_rule_entry, 0, sizeof(flt_rule_entry)); + flt_rule_entry.at_rear = 1; - flt_rule_entry.rule.retain_hdr = 0; - flt_rule_entry.rule.to_uc = 0; - flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; - flt_rule_entry.rule.eq_attrib_type = 0; - flt_rule_entry.rule.rt_tbl_hdl = rt_tbl_hdl; - flt_rule_entry.rule.hashable = true; + flt_rule_entry.rule.retain_hdr = 0; + flt_rule_entry.rule.to_uc = 0; + flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; + flt_rule_entry.rule.eq_attrib_type = 0; + flt_rule_entry.rule.rt_tbl_hdl = rt_tbl_hdl; + flt_rule_entry.rule.hashable = true; - memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, sizeof(flt_rule_entry.rule.attrib)); - if(tx_prop->tx[0].hdr_l2_type == IPA_HDR_L2_ETHERNET_II) - { - flt_rule_entry.rule.attrib.attrib_mask |= IPA_FLT_MAC_DST_ADDR_ETHER_II; + memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, sizeof(flt_rule_entry.rule.attrib)); + if(tx_prop->tx[0].hdr_l2_type == IPA_HDR_L2_ETHERNET_II) + { + flt_rule_entry.rule.attrib.attrib_mask |= IPA_FLT_MAC_DST_ADDR_ETHER_II; + } + else + { + flt_rule_entry.rule.attrib.attrib_mask |= IPA_FLT_MAC_DST_ADDR_802_3; + } + + memcpy(flt_rule_entry.rule.attrib.dst_mac_addr, mac, sizeof(flt_rule_entry.rule.attrib.dst_mac_addr)); + memset(flt_rule_entry.rule.attrib.dst_mac_addr_mask, 0xFF, sizeof(flt_rule_entry.rule.attrib.dst_mac_addr_mask)); + + memcpy(&(pFilteringTable->rules[0]), &flt_rule_entry, sizeof(flt_rule_entry)); +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(ipa_if_cate == WLAN_IF && IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); + result = m_filtering.AddFilteringRuleAfter_hw_index(pFilteringTable, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); + } else { + result = m_filtering.AddFilteringRuleAfter(pFilteringTable); + } +#else + result = m_filtering.AddFilteringRuleAfter(pFilteringTable); +#endif + if (result == false) + { + IPACMERR("Failed to add client filtering rules.\n"); + res = IPACM_FAILURE; + goto end; + } + *flt_rule_hdl = pFilteringTable->rules[0].flt_rule_hdl; + +end: + free(pFilteringTable); } else { - flt_rule_entry.rule.attrib.attrib_mask |= IPA_FLT_MAC_DST_ADDR_802_3; + IPACMDBG_H("Received client MAC 0x%02x%02x%02x%02x%02x%02x.\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + IPACMDBG_H("Not support rt_tbl_hdl %d flt_rule_hdl %p ip-type %d\n", rt_tbl_hdl, flt_rule_hdl, iptype); } - - memcpy(flt_rule_entry.rule.attrib.dst_mac_addr, mac, sizeof(flt_rule_entry.rule.attrib.dst_mac_addr)); - memset(flt_rule_entry.rule.attrib.dst_mac_addr_mask, 0xFF, sizeof(flt_rule_entry.rule.attrib.dst_mac_addr_mask)); - - memcpy(&(pFilteringTable->rules[0]), &flt_rule_entry, sizeof(flt_rule_entry)); -#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO - /* use index hw-counter */ - if(ipa_if_cate == WLAN_IF && IPACM_Iface::ipacmcfg->hw_fnr_stats_support) - { - IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); - result = m_filtering.AddFilteringRuleAfter_hw_index(pFilteringTable, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); - } else { - result = m_filtering.AddFilteringRuleAfter(pFilteringTable); - } -#else - result = m_filtering.AddFilteringRuleAfter(pFilteringTable); -#endif - if (result == false) - { - IPACMERR("Failed to add client filtering rules.\n"); - res = IPACM_FAILURE; - goto end; - } - *flt_rule_hdl = pFilteringTable->rules[0].flt_rule_hdl; - -end: - free(pFilteringTable); -#else - IPACMDBG_H("Received client MAC 0x%02x%02x%02x%02x%02x%02x.\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - IPACMDBG_H("Not support rt_tbl_hdl %d flt_rule_hdl %p ip-type %d\n", rt_tbl_hdl, flt_rule_hdl, iptype); -#endif return res; } @@ -5909,78 +6045,79 @@ int IPACM_Lan::add_l2tp_flt_rule(uint8_t *dst_mac, uint32_t *flt_rule_hdl) struct ipa_ioc_add_flt_rule_after *pFilteringTable = NULL; ipa_ioc_get_rt_tbl rt_tbl; -#ifdef FEATURE_IPA_V3 - if (rx_prop == NULL || tx_prop == NULL) + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) { - IPACMDBG_H("No rx or tx properties registered for iface %s\n", dev_name); - return IPACM_FAILURE; - } + if (rx_prop == NULL || tx_prop == NULL) + { + IPACMDBG_H("No rx or tx properties registered for iface %s\n", dev_name); + return IPACM_FAILURE; + } - len = sizeof(struct ipa_ioc_add_flt_rule_after) + sizeof(struct ipa_flt_rule_add); - pFilteringTable = (struct ipa_ioc_add_flt_rule_after*)malloc(len); - if (!pFilteringTable) - { - IPACMERR("Failed to allocate ipa_ioc_add_flt_rule_after memory...\n"); - return IPACM_FAILURE; - } - memset(pFilteringTable, 0, len); + len = sizeof(struct ipa_ioc_add_flt_rule_after) + sizeof(struct ipa_flt_rule_add); + pFilteringTable = (struct ipa_ioc_add_flt_rule_after*)malloc(len); + if (!pFilteringTable) + { + IPACMERR("Failed to allocate ipa_ioc_add_flt_rule_after memory...\n"); + return IPACM_FAILURE; + } + memset(pFilteringTable, 0, len); - pFilteringTable->commit = 1; - pFilteringTable->ep = rx_prop->rx[0].src_pipe; - pFilteringTable->ip = IPA_IP_v6; - pFilteringTable->num_rules = 1; - pFilteringTable->add_after_hdl = eth_bridge_flt_rule_offset[IPA_IP_v6]; + pFilteringTable->commit = 1; + pFilteringTable->ep = rx_prop->rx[0].src_pipe; + pFilteringTable->ip = IPA_IP_v6; + pFilteringTable->num_rules = 1; + pFilteringTable->add_after_hdl = eth_bridge_flt_rule_offset[IPA_IP_v6]; - fd_ipa = open(IPA_DEVICE_NAME, O_RDWR); - if(fd_ipa == 0) - { - IPACMERR("Failed to open %s\n",IPA_DEVICE_NAME); - free(pFilteringTable); - return IPACM_FAILURE; - } + fd_ipa = open(IPA_DEVICE_NAME, O_RDWR); + if(fd_ipa == 0) + { + IPACMERR("Failed to open %s\n",IPA_DEVICE_NAME); + free(pFilteringTable); + return IPACM_FAILURE; + } + + rt_tbl.ip = IPA_IP_v6; + snprintf(rt_tbl.name, sizeof(rt_tbl.name), "l2tp"); + rt_tbl.name[IPA_RESOURCE_NAME_MAX-1] = '\0'; + IPACMDBG_H("This flt rule points to rt tbl %s.\n", rt_tbl.name); + if(m_routing.GetRoutingTable(&rt_tbl) == false) + { + IPACMERR("Failed to get routing table from name\n"); + free(pFilteringTable); + close(fd_ipa); + return IPACM_FAILURE; + } + + memset(&flt_rule_entry, 0, sizeof(flt_rule_entry)); + flt_rule_entry.at_rear = 1; + + flt_rule_entry.rule.retain_hdr = 0; + flt_rule_entry.rule.to_uc = 0; + flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; + flt_rule_entry.rule.eq_attrib_type = 0; + flt_rule_entry.rule.rt_tbl_hdl = rt_tbl.hdl; + flt_rule_entry.rule.hashable = false; //ETH->WLAN direction rules need to be non-hashable due to encapsulation + + memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, sizeof(flt_rule_entry.rule.attrib)); + + /* flt rule is matching dst MAC within 62 bytes header */ + flt_rule_entry.rule.attrib.attrib_mask |= IPA_FLT_MAC_DST_ADDR_L2TP; + memset(flt_rule_entry.rule.attrib.dst_mac_addr_mask, 0xFF, sizeof(flt_rule_entry.rule.attrib.dst_mac_addr_mask)); + memcpy(flt_rule_entry.rule.attrib.dst_mac_addr, dst_mac, sizeof(flt_rule_entry.rule.attrib.dst_mac_addr)); + + memcpy(&(pFilteringTable->rules[0]), &flt_rule_entry, sizeof(flt_rule_entry)); + if(m_filtering.AddFilteringRuleAfter(pFilteringTable) == false) + { + IPACMERR("Failed to add client filtering rules.\n"); + free(pFilteringTable); + close(fd_ipa); + return IPACM_FAILURE; + } + *flt_rule_hdl = pFilteringTable->rules[0].flt_rule_hdl; - rt_tbl.ip = IPA_IP_v6; - snprintf(rt_tbl.name, sizeof(rt_tbl.name), "l2tp"); - rt_tbl.name[IPA_RESOURCE_NAME_MAX-1] = '\0'; - IPACMDBG_H("This flt rule points to rt tbl %s.\n", rt_tbl.name); - if(m_routing.GetRoutingTable(&rt_tbl) == false) - { - IPACMERR("Failed to get routing table from name\n"); free(pFilteringTable); close(fd_ipa); - return IPACM_FAILURE; } - - memset(&flt_rule_entry, 0, sizeof(flt_rule_entry)); - flt_rule_entry.at_rear = 1; - - flt_rule_entry.rule.retain_hdr = 0; - flt_rule_entry.rule.to_uc = 0; - flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; - flt_rule_entry.rule.eq_attrib_type = 0; - flt_rule_entry.rule.rt_tbl_hdl = rt_tbl.hdl; - flt_rule_entry.rule.hashable = false; //ETH->WLAN direction rules need to be non-hashable due to encapsulation - - memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, sizeof(flt_rule_entry.rule.attrib)); - - /* flt rule is matching dst MAC within 62 bytes header */ - flt_rule_entry.rule.attrib.attrib_mask |= IPA_FLT_MAC_DST_ADDR_L2TP; - memset(flt_rule_entry.rule.attrib.dst_mac_addr_mask, 0xFF, sizeof(flt_rule_entry.rule.attrib.dst_mac_addr_mask)); - memcpy(flt_rule_entry.rule.attrib.dst_mac_addr, dst_mac, sizeof(flt_rule_entry.rule.attrib.dst_mac_addr)); - - memcpy(&(pFilteringTable->rules[0]), &flt_rule_entry, sizeof(flt_rule_entry)); - if(m_filtering.AddFilteringRuleAfter(pFilteringTable) == false) - { - IPACMERR("Failed to add client filtering rules.\n"); - free(pFilteringTable); - close(fd_ipa); - return IPACM_FAILURE; - } - *flt_rule_hdl = pFilteringTable->rules[0].flt_rule_hdl; - - free(pFilteringTable); - close(fd_ipa); -#endif return IPACM_SUCCESS; } @@ -6004,123 +6141,123 @@ int IPACM_Lan::add_l2tp_flt_rule(ipa_ip_type iptype, uint8_t *dst_mac, uint32_t struct ipa_ioc_add_flt_rule_after *pFilteringTable = NULL; ipa_ioc_get_rt_tbl rt_tbl; -#ifdef FEATURE_IPA_V3 - if (rx_prop == NULL || tx_prop == NULL) + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) { - IPACMDBG_H("No rx or tx properties registered for iface %s\n", dev_name); - return IPACM_FAILURE; - } + if (rx_prop == NULL || tx_prop == NULL) + { + IPACMDBG_H("No rx or tx properties registered for iface %s\n", dev_name); + return IPACM_FAILURE; + } - IPACMDBG_H("Dst client MAC 0x%02x%02x%02x%02x%02x%02x.\n", dst_mac[0], dst_mac[1], - dst_mac[2], dst_mac[3], dst_mac[4], dst_mac[5]); + IPACMDBG_H("Dst client MAC 0x%02x%02x%02x%02x%02x%02x.\n", dst_mac[0], dst_mac[1], + dst_mac[2], dst_mac[3], dst_mac[4], dst_mac[5]); - len = sizeof(struct ipa_ioc_add_flt_rule_after) + sizeof(struct ipa_flt_rule_add); - pFilteringTable = (struct ipa_ioc_add_flt_rule_after*)malloc(len); - if (!pFilteringTable) - { - IPACMERR("Failed to allocate ipa_ioc_add_flt_rule_after memory...\n"); - return IPACM_FAILURE; - } - memset(pFilteringTable, 0, len); + len = sizeof(struct ipa_ioc_add_flt_rule_after) + sizeof(struct ipa_flt_rule_add); + pFilteringTable = (struct ipa_ioc_add_flt_rule_after*)malloc(len); + if (!pFilteringTable) + { + IPACMERR("Failed to allocate ipa_ioc_add_flt_rule_after memory...\n"); + return IPACM_FAILURE; + } + memset(pFilteringTable, 0, len); - pFilteringTable->commit = 1; - pFilteringTable->ep = rx_prop->rx[0].src_pipe; - pFilteringTable->ip = iptype; - pFilteringTable->num_rules = 1; - pFilteringTable->add_after_hdl = eth_bridge_flt_rule_offset[iptype]; + pFilteringTable->commit = 1; + pFilteringTable->ep = rx_prop->rx[0].src_pipe; + pFilteringTable->ip = iptype; + pFilteringTable->num_rules = 1; + pFilteringTable->add_after_hdl = eth_bridge_flt_rule_offset[iptype]; - /* =========== add first pass flt rule (match dst MAC) ============= */ - rt_tbl.ip = iptype; - snprintf(rt_tbl.name, sizeof(rt_tbl.name), "l2tp"); - IPACMDBG_H("This flt rule points to rt tbl %s.\n", rt_tbl.name); + /* =========== add first pass flt rule (match dst MAC) ============= */ + rt_tbl.ip = iptype; + snprintf(rt_tbl.name, sizeof(rt_tbl.name), "l2tp"); + IPACMDBG_H("This flt rule points to rt tbl %s.\n", rt_tbl.name); + + if(m_routing.GetRoutingTable(&rt_tbl) == false) + { + IPACMERR("Failed to get routing table.\n"); + return IPACM_FAILURE; + } + + memset(&flt_rule_entry, 0, sizeof(flt_rule_entry)); + flt_rule_entry.at_rear = 1; + + flt_rule_entry.rule.retain_hdr = 0; + flt_rule_entry.rule.to_uc = 0; + flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; + flt_rule_entry.rule.eq_attrib_type = 0; + flt_rule_entry.rule.rt_tbl_hdl = rt_tbl.hdl; + flt_rule_entry.rule.hashable = false; //WLAN->ETH direction rules are set to non-hashable to keep consistent with the other direction + + memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, sizeof(flt_rule_entry.rule.attrib)); + if(tx_prop->tx[0].hdr_l2_type == IPA_HDR_L2_ETHERNET_II) + { + flt_rule_entry.rule.attrib.attrib_mask |= IPA_FLT_MAC_DST_ADDR_ETHER_II; + } + else + { + flt_rule_entry.rule.attrib.attrib_mask |= IPA_FLT_MAC_DST_ADDR_802_3; + } + + memcpy(flt_rule_entry.rule.attrib.dst_mac_addr, dst_mac, sizeof(flt_rule_entry.rule.attrib.dst_mac_addr)); + memset(flt_rule_entry.rule.attrib.dst_mac_addr_mask, 0xFF, sizeof(flt_rule_entry.rule.attrib.dst_mac_addr_mask)); + + memcpy(&(pFilteringTable->rules[0]), &flt_rule_entry, sizeof(flt_rule_entry)); + if (false == m_filtering.AddFilteringRuleAfter(pFilteringTable)) + { + IPACMERR("Failed to add first pass filtering rules.\n"); + free(pFilteringTable); + return IPACM_FAILURE; + } + *first_pass_flt_rule_hdl = pFilteringTable->rules[0].flt_rule_hdl; + + /* =========== add second pass flt rule (match VLAN interface IPv6 address at client side) ============= */ + if(*second_pass_flt_rule_hdl != 0) + { + IPACMDBG_H("Second pass flt rule was added before, return.\n"); + free(pFilteringTable); + return IPACM_SUCCESS; + } + + rt_tbl.ip = IPA_IP_v6; + snprintf(rt_tbl.name, sizeof(rt_tbl.name), "l2tp"); + IPACMDBG_H("This flt rule points to rt tbl %s.\n", rt_tbl.name); + + if(m_routing.GetRoutingTable(&rt_tbl) == false) + { + IPACMERR("Failed to get routing table.\n"); + return IPACM_FAILURE; + } + + pFilteringTable->ip = IPA_IP_v6; + pFilteringTable->add_after_hdl = eth_bridge_flt_rule_offset[IPA_IP_v6]; + + memset(&flt_rule_entry, 0, sizeof(flt_rule_entry)); + flt_rule_entry.at_rear = 1; + + flt_rule_entry.rule.retain_hdr = 0; + flt_rule_entry.rule.to_uc = 0; + flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; + flt_rule_entry.rule.eq_attrib_type = 0; + flt_rule_entry.rule.rt_tbl_hdl = rt_tbl.hdl; + flt_rule_entry.rule.hashable = false; //WLAN->ETH direction rules are set to non-hashable to keep consistent with the other direction + + memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, sizeof(flt_rule_entry.rule.attrib)); + flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_DST_ADDR; + + memcpy(flt_rule_entry.rule.attrib.u.v6.dst_addr, vlan_client_ipv6_addr, sizeof(flt_rule_entry.rule.attrib.u.v6.dst_addr)); + memset(flt_rule_entry.rule.attrib.u.v6.dst_addr_mask, 0xFF, sizeof(flt_rule_entry.rule.attrib.u.v6.dst_addr_mask)); + + memcpy(&(pFilteringTable->rules[0]), &flt_rule_entry, sizeof(flt_rule_entry)); + if (false == m_filtering.AddFilteringRuleAfter(pFilteringTable)) + { + IPACMERR("Failed to add client filtering rules.\n"); + free(pFilteringTable); + return IPACM_FAILURE; + } + *second_pass_flt_rule_hdl = pFilteringTable->rules[0].flt_rule_hdl; - if(m_routing.GetRoutingTable(&rt_tbl) == false) - { - IPACMERR("Failed to get routing table.\n"); free(pFilteringTable); - return IPACM_FAILURE; } - - memset(&flt_rule_entry, 0, sizeof(flt_rule_entry)); - flt_rule_entry.at_rear = 1; - - flt_rule_entry.rule.retain_hdr = 0; - flt_rule_entry.rule.to_uc = 0; - flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; - flt_rule_entry.rule.eq_attrib_type = 0; - flt_rule_entry.rule.rt_tbl_hdl = rt_tbl.hdl; - flt_rule_entry.rule.hashable = false; //WLAN->ETH direction rules are set to non-hashable to keep consistent with the other direction - - memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, sizeof(flt_rule_entry.rule.attrib)); - if(tx_prop->tx[0].hdr_l2_type == IPA_HDR_L2_ETHERNET_II) - { - flt_rule_entry.rule.attrib.attrib_mask |= IPA_FLT_MAC_DST_ADDR_ETHER_II; - } - else - { - flt_rule_entry.rule.attrib.attrib_mask |= IPA_FLT_MAC_DST_ADDR_802_3; - } - - memcpy(flt_rule_entry.rule.attrib.dst_mac_addr, dst_mac, sizeof(flt_rule_entry.rule.attrib.dst_mac_addr)); - memset(flt_rule_entry.rule.attrib.dst_mac_addr_mask, 0xFF, sizeof(flt_rule_entry.rule.attrib.dst_mac_addr_mask)); - - memcpy(&(pFilteringTable->rules[0]), &flt_rule_entry, sizeof(flt_rule_entry)); - if (false == m_filtering.AddFilteringRuleAfter(pFilteringTable)) - { - IPACMERR("Failed to add first pass filtering rules.\n"); - free(pFilteringTable); - return IPACM_FAILURE; - } - *first_pass_flt_rule_hdl = pFilteringTable->rules[0].flt_rule_hdl; - - /* =========== add second pass flt rule (match VLAN interface IPv6 address at client side) ============= */ - if(*second_pass_flt_rule_hdl != 0) - { - IPACMDBG_H("Second pass flt rule was added before, return.\n"); - free(pFilteringTable); - return IPACM_SUCCESS; - } - - rt_tbl.ip = IPA_IP_v6; - snprintf(rt_tbl.name, sizeof(rt_tbl.name), "l2tp"); - IPACMDBG_H("This flt rule points to rt tbl %s.\n", rt_tbl.name); - - if(m_routing.GetRoutingTable(&rt_tbl) == false) - { - IPACMERR("Failed to get routing table.\n"); - return IPACM_FAILURE; - } - - pFilteringTable->ip = IPA_IP_v6; - pFilteringTable->add_after_hdl = eth_bridge_flt_rule_offset[IPA_IP_v6]; - - memset(&flt_rule_entry, 0, sizeof(flt_rule_entry)); - flt_rule_entry.at_rear = 1; - - flt_rule_entry.rule.retain_hdr = 0; - flt_rule_entry.rule.to_uc = 0; - flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; - flt_rule_entry.rule.eq_attrib_type = 0; - flt_rule_entry.rule.rt_tbl_hdl = rt_tbl.hdl; - flt_rule_entry.rule.hashable = false; //WLAN->ETH direction rules are set to non-hashable to keep consistent with the other direction - - memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, sizeof(flt_rule_entry.rule.attrib)); - flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_DST_ADDR; - - memcpy(flt_rule_entry.rule.attrib.u.v6.dst_addr, vlan_client_ipv6_addr, sizeof(flt_rule_entry.rule.attrib.u.v6.dst_addr)); - memset(flt_rule_entry.rule.attrib.u.v6.dst_addr_mask, 0xFF, sizeof(flt_rule_entry.rule.attrib.u.v6.dst_addr_mask)); - - memcpy(&(pFilteringTable->rules[0]), &flt_rule_entry, sizeof(flt_rule_entry)); - if (false == m_filtering.AddFilteringRuleAfter(pFilteringTable)) - { - IPACMERR("Failed to add client filtering rules.\n"); - free(pFilteringTable); - return IPACM_FAILURE; - } - *second_pass_flt_rule_hdl = pFilteringTable->rules[0].flt_rule_hdl; - - free(pFilteringTable); -#endif return IPACM_SUCCESS; } @@ -6343,9 +6480,8 @@ int IPACM_Lan::add_connection(int client_index, int v6_num) flt_rule_entry.rule.to_uc = 0; flt_rule_entry.rule.eq_attrib_type = 1; flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; flt_rule_entry.rule.attrib.attrib_mask |= IPA_FLT_DST_ADDR; flt_rule_entry.rule.attrib.u.v6.dst_addr[0] = get_client_memptr(eth_client, client_index)->v6_addr[v6_num][0]; flt_rule_entry.rule.attrib.u.v6.dst_addr[1] = get_client_memptr(eth_client, client_index)->v6_addr[v6_num][1]; diff --git a/data-ipa-cfg-mgr/ipacm/src/IPACM_LanToLan.cpp b/data-ipa-cfg-mgr/ipacm/src/IPACM_LanToLan.cpp index ea016ef1..00754180 100644 --- a/data-ipa-cfg-mgr/ipacm/src/IPACM_LanToLan.cpp +++ b/data-ipa-cfg-mgr/ipacm/src/IPACM_LanToLan.cpp @@ -1308,8 +1308,12 @@ void IPACM_LanToLan_Iface::handle_down_event() it_own_peer_info++) { /* decrement reference count of peer l2 header type on both interfaces*/ - decrement_ref_cnt_peer_l2_hdr_type(it_own_peer_info->peer->get_iface_pointer()->tx_prop->tx[0].hdr_l2_type); - it_own_peer_info->peer->decrement_ref_cnt_peer_l2_hdr_type(m_p_iface->tx_prop->tx[0].hdr_l2_type); + if (it_own_peer_info->peer && + it_own_peer_info->peer->get_iface_pointer() && + it_own_peer_info->peer->get_iface_pointer()->tx_prop) + decrement_ref_cnt_peer_l2_hdr_type(it_own_peer_info->peer->get_iface_pointer()->tx_prop->tx[0].hdr_l2_type); + if (it_own_peer_info->peer && m_p_iface && m_p_iface->tx_prop) + it_own_peer_info->peer->decrement_ref_cnt_peer_l2_hdr_type(m_p_iface->tx_prop->tx[0].hdr_l2_type); /* first clear all flt rule on target interface */ IPACMDBG_H("Clear all flt rule on target interface.\n"); @@ -1330,7 +1334,8 @@ void IPACM_LanToLan_Iface::handle_down_event() other_iface->clear_all_rt_rule_for_one_peer_iface(&(*it_other_iface_peer_info)); /* remove the peer info from the list */ other_iface->m_peer_iface_info.erase(it_other_iface_peer_info); - other_iface->del_hdr_proc_ctx(m_p_iface->tx_prop->tx[0].hdr_l2_type); + if (m_p_iface && m_p_iface->tx_prop) + other_iface->del_hdr_proc_ctx(m_p_iface->tx_prop->tx[0].hdr_l2_type); break; } } @@ -1338,6 +1343,9 @@ void IPACM_LanToLan_Iface::handle_down_event() /* then clear rt rule and hdr proc ctx and release rt table on target interface */ IPACMDBG_H("Clear rt rules and hdr proc ctx and release rt table on target interface.\n"); clear_all_rt_rule_for_one_peer_iface(&(*it_own_peer_info)); + if (it_own_peer_info->peer && + it_own_peer_info->peer->get_iface_pointer() && + it_own_peer_info->peer->get_iface_pointer()->tx_prop) del_hdr_proc_ctx(it_own_peer_info->peer->get_iface_pointer()->tx_prop->tx[0].hdr_l2_type); } m_peer_iface_info.clear(); diff --git a/data-ipa-cfg-mgr/ipacm/src/IPACM_Main.cpp b/data-ipa-cfg-mgr/ipacm/src/IPACM_Main.cpp index bb5d6c40..6bd117e6 100644 --- a/data-ipa-cfg-mgr/ipacm/src/IPACM_Main.cpp +++ b/data-ipa-cfg-mgr/ipacm/src/IPACM_Main.cpp @@ -121,7 +121,7 @@ int ipa_reset_hw_index_counter(); #ifdef FEATURE_IPACM_HAL IPACM_OffloadManager* OffloadMng; - HAL *hal; + ::android::sp hal; #endif /* start netlink socket monitor*/ @@ -270,6 +270,10 @@ void* ipa_driver_msg_notifier(void *param) #endif ipacm_cmd_q_data new_neigh_evt; ipacm_event_data_all* new_neigh_data; +#ifdef IPA_MTU_EVENT_MAX + ipacm_event_mtu_info *mtu_event = NULL; + ipa_mtu_info *mtu_info; +#endif param = NULL; fd = open(IPA_DRIVER, O_RDWR); @@ -450,12 +454,11 @@ void* ipa_driver_msg_notifier(void *param) } memcpy(event_ex, buffer + sizeof(struct ipa_msg_meta), length); data_ex = (ipacm_event_data_wlan_ex *)malloc(sizeof(ipacm_event_data_wlan_ex) + event_ex_o.num_of_attribs * sizeof(ipa_wlan_hdr_attrib_val)); - if (data_ex == NULL) - { + if (data_ex == NULL) + { IPACMERR("unable to allocate memory for event data\n"); - free(event_ex); - return NULL; - } + return NULL; + } data_ex->num_of_attribs = event_ex->num_of_attribs; memcpy(data_ex->attribs, @@ -761,10 +764,19 @@ void* ipa_driver_msg_notifier(void *param) IPACMERR("calling OffloadMng->elrInstance->onOffloadStopped \n"); OffloadMng->elrInstance->onOffloadStopped(IpaEventRelay::ERROR); } - /* WA to clean up wlan instances during SSR */ - evt_data.event = IPA_SSR_NOTICE; - evt_data.evt_data = NULL; - break; + /* Starting from Hastings, WLAN is not restarted as part of Modem SSR. + * No need to reset NAT Iface. + */ +#ifdef IPA_HW_v4_9 + if (IPACM_Iface::ipacmcfg->GetIPAVer() != IPA_HW_v4_9) +#endif + { + /* WA to clean up wlan instances during SSR */ + evt_data.event = IPA_SSR_NOTICE; + evt_data.evt_data = NULL; + break; + } + continue; case IPA_SSR_AFTER_POWERUP: IPACMDBG_H("Received IPA_SSR_AFTER_POWERUP\n"); OffloadMng = IPACM_OffloadManager::GetInstance(); @@ -866,6 +878,32 @@ void* ipa_driver_msg_notifier(void *param) break; #endif +#ifdef IPA_MTU_EVENT_MAX + case IPA_SET_MTU: + mtu_event = (ipacm_event_mtu_info *)malloc(sizeof(*mtu_event)); + if(mtu_event == NULL) + { + IPACMERR("Failed to allocate memory.\n"); + return NULL; + } + mtu_info = &(mtu_event->mtu_info); + memcpy(mtu_info, buffer + sizeof(struct ipa_msg_meta), sizeof(struct ipa_mtu_info)); + IPACMDBG_H("Received IPA_SET_MTU if_name %s ip_type %d mtu_v4 %d mtu_v6 %d\n", + mtu_info->if_name, mtu_info->ip_type, mtu_info->mtu_v4, mtu_info->mtu_v6); + if (mtu_info->ip_type > IPA_IP_MAX) + { + IPACMERR("ip_type (%d) beyond the Max range (%d), abort\n", + mtu_info->ip_type, IPA_IP_MAX); + return NULL; + } + + ipa_get_if_index(mtu_info->if_name, &(mtu_event->if_index)); + + evt_data.event = IPA_MTU_SET; + evt_data.evt_data = mtu_event; + break; +#endif + default: IPACMDBG_H("Unhandled message type: %d\n", event_hdr.msg_type); continue; @@ -952,11 +990,11 @@ int main(int argc, char **argv) IPACMDBG_H(" START IPACM_OffloadManager and link to android framework\n"); #endif -#ifdef FEATURE_ETH_BRIDGE_LE - IPACM_LanToLan* lan2lan = IPACM_LanToLan::get_instance(); - IPACMDBG_H("Staring IPACM_LanToLan instance %p\n", lan2lan); -#endif - + if (IPACM_Iface::ipacmcfg->isEthBridgingSupported()) + { + IPACM_LanToLan* lan2lan = IPACM_LanToLan::get_instance(); + IPACMDBG_H("Staring IPACM_LanToLan instance %p\n", lan2lan); + } CtList = new IPACM_ConntrackListener(); IPACMDBG_H("Staring IPA main\n"); diff --git a/data-ipa-cfg-mgr/ipacm/src/IPACM_Netlink.cpp b/data-ipa-cfg-mgr/ipacm/src/IPACM_Netlink.cpp index fa0f7acb..fa4b8b77 100644 --- a/data-ipa-cfg-mgr/ipacm/src/IPACM_Netlink.cpp +++ b/data-ipa-cfg-mgr/ipacm/src/IPACM_Netlink.cpp @@ -709,7 +709,6 @@ static int ipa_nl_decode_nlmsg if(ret_val != IPACM_SUCCESS) { IPACMERR("Error while getting interface name\n"); - free(data_fid); return IPACM_FAILURE; } IPACMDBG_H("Got a usb link_up event (Interface %s, %d) \n", dev_name, msg_ptr->nl_link_info.metainfo.ifi_index); diff --git a/data-ipa-cfg-mgr/ipacm/src/IPACM_OffloadManager.cpp b/data-ipa-cfg-mgr/ipacm/src/IPACM_OffloadManager.cpp index 79194139..708725b8 100644 --- a/data-ipa-cfg-mgr/ipacm/src/IPACM_OffloadManager.cpp +++ b/data-ipa-cfg-mgr/ipacm/src/IPACM_OffloadManager.cpp @@ -120,8 +120,9 @@ RET IPACM_OffloadManager::unregisterCtTimeoutUpdater(ConntrackTimeoutUpdater* ) RET IPACM_OffloadManager::provideFd(int fd, unsigned int groups) { + struct timeval tv; IPACM_ConntrackClient *cc; - int on = 1, rel; + int on = 1, rel = 0; struct sockaddr_nl local; unsigned int addr_len; @@ -155,13 +156,39 @@ RET IPACM_OffloadManager::provideFd(int fd, unsigned int groups) IPACMERR( "setsockopt returned error code %d ( %s )", errno, strerror( errno ) ); } } else if (groups == cc->subscrips_udp) { + /* Set receive timeout to 1s on the FD which is used to read conntrack dump. */ + memset(&tv,0, sizeof(struct timeval)); + tv.tv_sec = 1; /* 1s timeout */ + rel = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO,(struct timeval *)&tv,sizeof(struct timeval)); + if (rel == -1) + { + IPACMERR("setsockopt returned error code %d ( %s )\n", errno, strerror(errno)); + } + + /* In Android we get conntrack handles once after tethering is enabled but we + loose connections info for embedded traffic if running before. So no NAT + entries are added for embedded traffic due to which we see NAT exception and + data takes S/W path which results in less throughput. Hence for embedded + traffic info, framework sends conntrack dump before providing handles. Here + reading ct entries before creating filter on Fd in order to have NAT entries + for both TCP/UDP embedded traffic. + */ + CtList->readConntrack(fd); + /* Reset receive timeout on the FD which is used to read conntrack dump. */ + memset(&tv,0, sizeof(struct timeval)); + rel = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO,(struct timeval *)&tv,sizeof(struct timeval)); + if (rel == -1) + { + IPACMERR("setsockopt returned error code %d ( %s )\n", errno, strerror(errno)); + } + cc->fd_udp = dup(fd); IPACMDBG_H("Received fd %d with groups %d.\n", fd, groups); /* set netlink buf */ - rel = setsockopt(cc->fd_tcp, SOL_NETLINK, NETLINK_NO_ENOBUFS, &on, sizeof(int) ); + rel = setsockopt(cc->fd_udp, SOL_NETLINK, NETLINK_NO_ENOBUFS, &on, sizeof(int) ); if (rel == -1) { - IPACMERR( "setsockopt returned error code %d ( %s )", errno, strerror( errno ) ); + IPACMERR("setsockopt returned error code %d ( %s )\n", errno, strerror(errno)); } } else { IPACMERR("Received unexpected fd with groups %d.\n", groups); diff --git a/data-ipa-cfg-mgr/ipacm/src/IPACM_Wan.cpp b/data-ipa-cfg-mgr/ipacm/src/IPACM_Wan.cpp index c15fad0b..f17eb037 100644 --- a/data-ipa-cfg-mgr/ipacm/src/IPACM_Wan.cpp +++ b/data-ipa-cfg-mgr/ipacm/src/IPACM_Wan.cpp @@ -92,7 +92,8 @@ int IPACM_Wan::ipa_if_num_tether_v4[IPA_MAX_IFACE_ENTRIES]; int IPACM_Wan::ipa_if_num_tether_v6[IPA_MAX_IFACE_ENTRIES]; #endif -uint16_t IPACM_Wan::mtu_default_wan = DEFAULT_MTU_SIZE; +uint16_t IPACM_Wan::mtu_default_wan_v4 = DEFAULT_MTU_SIZE; +uint16_t IPACM_Wan::mtu_default_wan_v6 = DEFAULT_MTU_SIZE; IPACM_Wan::IPACM_Wan(int iface_index, ipacm_wan_iface_type is_sta_mode, @@ -132,7 +133,11 @@ IPACM_Wan::IPACM_Wan(int iface_index, ext_prop = NULL; is_ipv6_frag_firewall_flt_rule_installed = false; ipv6_frag_firewall_flt_rule_hdl = 0; - mtu_size = DEFAULT_MTU_SIZE; + + mtu_v4 = DEFAULT_MTU_SIZE; + mtu_v4_set = false; + mtu_v6 = DEFAULT_MTU_SIZE; + mtu_v6_set = false; num_wan_client = 0; header_name_count = 0; @@ -146,6 +151,53 @@ IPACM_Wan::IPACM_Wan(int iface_index, wan_client_len = 0; m_is_sta_mode = is_sta_mode; +#ifdef IPA_MTU_EVENT_MAX + /* Query WAN MTU to handle IPACM restart scenarios. */ + if(is_sta_mode == Q6_WAN) + { + int fd_wwan_ioctl; + ipa_mtu_info *mtu_info = (ipa_mtu_info *)malloc(sizeof(ipa_mtu_info)); + if (mtu_info) + { + memset(mtu_info, 0, sizeof(ipa_mtu_info)); + memcpy(mtu_info->if_name, dev_name, IPA_IFACE_NAME_LEN); + fd_wwan_ioctl = open(WWAN_QMI_IOCTL_DEVICE_NAME, O_RDWR); + if(fd_wwan_ioctl < 0) + { + IPACMERR("Failed to open %s.\n",WWAN_QMI_IOCTL_DEVICE_NAME); + } + else + { + IPACMDBG_H("send WAN_IOC_GET_WAN_MTU for %s\n", mtu_info->if_name); + if(ioctl(fd_wwan_ioctl, WAN_IOC_GET_WAN_MTU, mtu_info)) + { + IPACMERR("Failed to send WAN_IOC_GET_WAN_MTU\n "); + } + else + { + /* Updated MTU values.*/ + if (mtu_info->mtu_v4) + { + mtu_v4 = mtu_info->mtu_v4; + mtu_v4_set = true; + IPACMDBG_H("Updated v4 mtu=[%d] for (%s)\n", + mtu_v4, mtu_info->if_name); + } + if (mtu_info->mtu_v6) + { + mtu_v6 = mtu_info->mtu_v6; + mtu_v6_set = true; + IPACMDBG_H("Updated v6 mtu=[%d] for (%s)\n", + mtu_v6, mtu_info->if_name); + } + } + close(fd_wwan_ioctl); + } + free(mtu_info); + } + } +#endif + if(iface_query != NULL) { IPACMDBG_H("index:%d constructor: Tx properties:%d\n", iface_index, iface_query->num_tx_props); @@ -295,9 +347,8 @@ int IPACM_Wan::handle_addr_evt(ipacm_event_data_addr *data) ipv6_addr[num_dft_rt_v6][1] = data->ipv6_addr[1]; ipv6_addr[num_dft_rt_v6][2] = data->ipv6_addr[2]; ipv6_addr[num_dft_rt_v6][3] = data->ipv6_addr[3]; -#ifdef FEATURE_IPA_V3 - rt_rule_entry->rule.hashable = false; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + rt_rule_entry->rule.hashable = false; if(m_is_sta_mode == Q6_WAN) { strlcpy(hdr.name, tx_prop->tx[0].hdr_name, sizeof(hdr.name)); @@ -491,9 +542,8 @@ int IPACM_Wan::handle_addr_evt(ipacm_event_data_addr *data) flt_rule_entry.flt_rule_hdl = -1; flt_rule_entry.status = -1; flt_rule_entry.rule.action = IPA_PASS_TO_EXCEPTION; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, sizeof(flt_rule_entry.rule.attrib)); flt_rule_entry.rule.attrib.attrib_mask |= IPA_FLT_DST_ADDR; @@ -599,9 +649,8 @@ int IPACM_Wan::handle_addr_evt(ipacm_event_data_addr *data) strlcpy(rt_rule->rt_tbl_name, IPACM_Iface::ipacmcfg->rt_tbl_lan_v4.name, sizeof(rt_rule->rt_tbl_name)); rt_rule_entry->rule.attrib.u.v4.dst_addr = data->ipv4_addr; rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF; -#ifdef FEATURE_IPA_V3 - rt_rule_entry->rule.hashable = false; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + rt_rule_entry->rule.hashable = false; if(m_is_sta_mode == Q6_WAN) { /* query qmap header*/ @@ -813,7 +862,7 @@ int IPACM_Wan::handle_addr_evt_mhi_q6(ipacm_event_data_addr *data) IPACMDBG_H(" Has rx/tx properties registered for iface %s, add for NATTING for ip-family %d \n", dev_name, IPA_IP_v6); IPACM_Iface::ipacmcfg->AddNatIfaces(dev_name, IPA_IP_v6); } - /* skylar setup v6-wan-tbl */ + /* setup v6-wan-tbl */ rt_rule = (struct ipa_ioc_add_rt_rule *) calloc(1, sizeof(struct ipa_ioc_add_rt_rule) + NUM_RULES * sizeof(struct ipa_rt_rule_add)); @@ -854,9 +903,8 @@ int IPACM_Wan::handle_addr_evt_mhi_q6(ipacm_event_data_addr *data) ipv6_addr[0][1] = data->ipv6_addr[1]; ipv6_addr[0][2] = data->ipv6_addr[2]; ipv6_addr[0][3] = data->ipv6_addr[3]; -#ifdef FEATURE_IPA_V3 - rt_rule_entry->rule.hashable = false; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + rt_rule_entry->rule.hashable = false; if (false == m_routing.AddRoutingRule(rt_rule)) { IPACMERR("Routing rule addition failed!\n"); @@ -935,9 +983,8 @@ int IPACM_Wan::handle_addr_evt_mhi_q6(ipacm_event_data_addr *data) strlcpy(rt_rule->rt_tbl_name, IPACM_Iface::ipacmcfg->rt_tbl_lan_v4.name, sizeof(rt_rule->rt_tbl_name)); rt_rule_entry->rule.attrib.u.v4.dst_addr = data->ipv4_addr; rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF; -#ifdef FEATURE_IPA_V3 - rt_rule_entry->rule.hashable = false; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + rt_rule_entry->rule.hashable = false; if (false == m_routing.AddRoutingRule(rt_rule)) { IPACMERR("Routing rule addition failed!\n"); @@ -1117,6 +1164,7 @@ void IPACM_Wan::event_callback(ipa_cm_event_id event, void *param) } } break; + case IPA_LINK_DOWN_EVENT: { ipacm_event_data_fid *data = (ipacm_event_data_fid *)param; @@ -1580,6 +1628,8 @@ void IPACM_Wan::event_callback(ipa_cm_event_id event, void *param) { ipacm_event_data_all *data = (ipacm_event_data_all *)param; ipa_interface_index = iface_ipa_index_query(data->if_index); + int index = 0; + bool renew = false; if (ipa_interface_index == ipa_if_num) { @@ -1611,6 +1661,7 @@ void IPACM_Wan::event_callback(ipa_cm_event_id event, void *param) } IPACMDBG_H("wan-iface got client \n"); + /* first construc WAN-client full header */ if(memcmp(data->mac_addr, invalid_mac, @@ -1622,7 +1673,20 @@ void IPACM_Wan::event_callback(ipa_cm_event_id event, void *param) return; } - handle_wan_hdr_init(data->mac_addr); + /* check if same as GW_ip need replacing */ + if( handle_gw_mac_renew(data, index) == IPACM_SUCCESS) + { + renew = true; + IPACMDBG_H("Renew is happening with client-index (%d)\n", index); + /* clinet renew procedure */ + handle_wan_hdr_init(data->mac_addr, true, index); + } + else + { + IPACMDBG_H("Renew is no need!\n"); + handle_wan_hdr_init(data->mac_addr); + } + IPACMDBG_H("construct wan-client header and route rules \n"); /* Associate with IP and construct RT-rule */ if (handle_wan_client_ipaddr(data) == IPACM_FAILURE) @@ -1631,7 +1695,7 @@ void IPACM_Wan::event_callback(ipa_cm_event_id event, void *param) } handle_wan_client_route_rule(data->mac_addr, data->iptype); /* Check & construct STA header */ - handle_sta_header_add_evt(); + handle_sta_header_add_evt(renew); return; } } @@ -1726,54 +1790,117 @@ void IPACM_Wan::event_callback(ipa_cm_event_id event, void *param) } break; - case IPA_WLAN_SWITCH_TO_SCC: - if(IPACM_Wan::backhaul_mode == WLAN_WAN) + case IPA_WLAN_SWITCH_TO_SCC: + if(IPACM_Wan::backhaul_mode == WLAN_WAN) + { + IPACMDBG_H("Received IPA_WLAN_SWITCH_TO_SCC\n"); + if(ip_type == IPA_IP_MAX) { - IPACMDBG_H("Received IPA_WLAN_SWITCH_TO_SCC\n"); - if(ip_type == IPA_IP_MAX) - { - handle_wlan_SCC_MCC_switch(true, IPA_IP_v4); - handle_wlan_SCC_MCC_switch(true, IPA_IP_v6); - handle_wan_client_SCC_MCC_switch(true, IPA_IP_v4); - handle_wan_client_SCC_MCC_switch(true, IPA_IP_v6); - } - else - { - handle_wlan_SCC_MCC_switch(true, ip_type); - handle_wan_client_SCC_MCC_switch(true, ip_type); - } + handle_wlan_SCC_MCC_switch(true, IPA_IP_v4); + handle_wlan_SCC_MCC_switch(true, IPA_IP_v6); + handle_wan_client_SCC_MCC_switch(true, IPA_IP_v4); + handle_wan_client_SCC_MCC_switch(true, IPA_IP_v6); } - break; - - case IPA_WLAN_SWITCH_TO_MCC: - if(IPACM_Wan::backhaul_mode == WLAN_WAN) + else { - IPACMDBG_H("Received IPA_WLAN_SWITCH_TO_MCC\n"); - if(ip_type == IPA_IP_MAX) - { - handle_wlan_SCC_MCC_switch(false, IPA_IP_v4); - handle_wlan_SCC_MCC_switch(false, IPA_IP_v6); - handle_wan_client_SCC_MCC_switch(false, IPA_IP_v4); - handle_wan_client_SCC_MCC_switch(false, IPA_IP_v6); - } - else - { - handle_wlan_SCC_MCC_switch(false, ip_type); - handle_wan_client_SCC_MCC_switch(false, ip_type); - } - } - break; -#ifdef FEATURE_IPACM_HAL - /* WA for WLAN to clean up NAT instance during SSR */ - case IPA_SSR_NOTICE: - case IPA_WLAN_FWR_SSR_BEFORE_SHUTDOWN_NOTICE: - IPACMDBG_H("Received IPA_SSR_NOTICE event.\n"); - if(m_is_sta_mode == WLAN_WAN) - { - IPACM_Iface::ipacmcfg->DelNatIfaces(dev_name); // delete NAT-iface + handle_wlan_SCC_MCC_switch(true, ip_type); + handle_wan_client_SCC_MCC_switch(true, ip_type); } + } break; + + case IPA_WLAN_SWITCH_TO_MCC: + if(IPACM_Wan::backhaul_mode == WLAN_WAN) + { + IPACMDBG_H("Received IPA_WLAN_SWITCH_TO_MCC\n"); + if(ip_type == IPA_IP_MAX) + { + handle_wlan_SCC_MCC_switch(false, IPA_IP_v4); + handle_wlan_SCC_MCC_switch(false, IPA_IP_v6); + handle_wan_client_SCC_MCC_switch(false, IPA_IP_v4); + handle_wan_client_SCC_MCC_switch(false, IPA_IP_v6); + } + else + { + handle_wlan_SCC_MCC_switch(false, ip_type); + handle_wan_client_SCC_MCC_switch(false, ip_type); + } + } + break; +#ifdef FEATURE_IPACM_HAL + /* WA for WLAN to clean up NAT instance during SSR */ + case IPA_SSR_NOTICE: + case IPA_WLAN_FWR_SSR_BEFORE_SHUTDOWN_NOTICE: + { + IPACMDBG_H("Received IPA_SSR_NOTICE event.\n"); + if(m_is_sta_mode == WLAN_WAN) + { + IPACM_Iface::ipacmcfg->DelNatIfaces(dev_name); // delete NAT-iface + } + } + break; #endif +#ifdef IPA_MTU_EVENT_MAX + case IPA_MTU_SET: + { + ipacm_event_mtu_info *data = (ipacm_event_mtu_info *)param; + ipa_mtu_info *mtu_info = &(data->mtu_info); + ipa_interface_index = iface_ipa_index_query(data->if_index); + + if (ipa_interface_index == ipa_if_num) + { + IPACMDBG_H("Received IPA_MTU_SET (Android) for interface (%d)\n", + ipa_interface_index); + if (mtu_info->ip_type == IPA_IP_v4 || mtu_info->ip_type == IPA_IP_MAX) + { + /* Update v4_mtu. */ + mtu_v4 = mtu_info->mtu_v4; + mtu_v4_set = true; + + if (active_v4) + { + /* upstream interface. update default MTU. */ + mtu_default_wan_v4 = mtu_v4; + } + IPACMDBG_H("Updated v4 mtu=[%d] for (%s), upstream_mtu=[%d]\n", + mtu_v4, mtu_info->if_name, mtu_default_wan_v4); + } + if (mtu_info->ip_type == IPA_IP_v6 || mtu_info->ip_type == IPA_IP_MAX) + { + /* Update v4_mtu. */ + mtu_v6 = mtu_info->mtu_v6; + mtu_v6_set = true; + if (active_v6) + { + /* upstream interface. update default MTU. */ + mtu_default_wan_v6 = mtu_v6; + } + IPACMDBG_H("Updated v6 mtu=[%d] for (%s), upstream_mtu=[%d]\n", + mtu_v6, mtu_info->if_name, mtu_default_wan_v6); + } + + if (active_v4 || active_v6) + { + ipacm_event_mtu_info *mtu_event; + ipacm_cmd_q_data evt_data; + mtu_event = (ipacm_event_mtu_info *)malloc(sizeof(*mtu_event)); + if(mtu_event == NULL) + { + IPACMERR("Failed to allocate memory.\n"); + return; + } + memcpy(&mtu_event->mtu_info, mtu_info, sizeof(ipa_mtu_info)); + evt_data.event = IPA_MTU_UPDATE; + evt_data.evt_data = mtu_event; + /* finish command queue */ + IPACMDBG_H("Posting IPA_MTU_UPDATE event\n"); + IPACM_EvtDispatcher::PostEvt(&evt_data); + } + } + } + break; +#endif + default: break; } @@ -1782,9 +1909,8 @@ void IPACM_Wan::event_callback(ipa_cm_event_id event, void *param) } /* wan default route/filter rule configuration */ -int IPACM_Wan::handle_route_add_evt(ipa_ip_type iptype) +int IPACM_Wan::handle_route_add_evt(ipa_ip_type iptype, bool add_only) { - /* add default WAN route */ struct ipa_ioc_add_rt_rule *rt_rule = NULL; struct ipa_rt_rule_add *rt_rule_entry; @@ -1822,8 +1948,14 @@ int IPACM_Wan::handle_route_add_evt(ipa_ip_type iptype) } IPACMDBG_H("backhaul_is_wan_bridge ?: %d \n", IPACM_Wan::backhaul_is_wan_bridge); - /* query MTU size of the interface */ - query_mtu_size(); + /* query MTU size of the interface if MTU is not set via ioctl. */ + if (!mtu_v4_set && !mtu_v6_set) + { + if(query_mtu_size()) + { + IPACMERR("Failed to query mtu"); + } + } if (m_is_sta_mode ==Q6_WAN) { @@ -1855,7 +1987,7 @@ int IPACM_Wan::handle_route_add_evt(ipa_ip_type iptype) { /* treat Q6_MHI_WAN as STA mode also */ IPACMDBG_H("Q6-MHI ipv4/v6-header already constructed \n"); - IPACM_Wan::backhaul_mode = m_is_sta_mode; + IPACM_Wan::backhaul_mode = m_is_sta_mode; IPACMDBG_H("Setting up QMAP ID %d.\n", ext_prop->ext[0].mux_id); IPACM_Iface::ipacmcfg->SetQmapId(ext_prop->ext[0].mux_id); /* sending mux-id info to PCIE-modem for UL */ @@ -1987,9 +2119,8 @@ int IPACM_Wan::handle_route_add_evt(ipa_ip_type iptype) { rt_rule_entry->rule.attrib.u.v4.dst_addr = 0; rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0; -#ifdef FEATURE_IPA_V3 - rt_rule_entry->rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + rt_rule_entry->rule.hashable = true; #ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO /* use index hw-counter */ if((m_is_sta_mode == WLAN_WAN) && IPACM_Iface::ipacmcfg->hw_fnr_stats_support) @@ -2024,9 +2155,8 @@ int IPACM_Wan::handle_route_add_evt(ipa_ip_type iptype) rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0; rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0; rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0; -#ifdef FEATURE_IPA_V3 - rt_rule_entry->rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + rt_rule_entry->rule.hashable = true; #ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO /* use index hw-counter */ if((m_is_sta_mode == WLAN_WAN) && IPACM_Iface::ipacmcfg->hw_fnr_stats_support) @@ -2098,9 +2228,8 @@ int IPACM_Wan::handle_route_add_evt(ipa_ip_type iptype) rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0; rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0; rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0; -#ifdef FEATURE_IPA_V3 - rt_rule_entry->rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + rt_rule_entry->rule.hashable = true; if (false == m_routing.AddRoutingRule(rt_rule)) { IPACMERR("Routing rule addition failed!\n"); @@ -2112,10 +2241,16 @@ int IPACM_Wan::handle_route_add_evt(ipa_ip_type iptype) wan_route_rule_v6_hdl_a5[0], 0, iptype); } - /* set mtu_default_wan to current default wan instance */ - mtu_default_wan = mtu_size; - - IPACMDBG_H("replace the mtu_default_wan to %d\n", mtu_default_wan); + /* support delete only, not post wan_down event */ + if (add_only) + { + IPACMDBG_H(" Only add default WAN routing rules (%d)\n", add_only); + if(rt_rule != NULL) + { + free(rt_rule); + } + return IPACM_SUCCESS; + } ipacm_event_iface_up *wanup_data; wanup_data = (ipacm_event_iface_up *)malloc(sizeof(ipacm_event_iface_up)); @@ -2130,6 +2265,10 @@ int IPACM_Wan::handle_route_add_evt(ipa_ip_type iptype) /* handling filter rule construction */ if (iptype == IPA_IP_v4) { + /* set mtu_default_wan to current default wan instance */ + mtu_default_wan_v4 = mtu_v4; + IPACMDBG_H("replace the mtu_wan to %d\n", mtu_default_wan_v4); + IPACM_Wan::wan_up = true; active_v4 = true; memcpy(IPACM_Wan::wan_up_dev_name, @@ -2189,6 +2328,10 @@ int IPACM_Wan::handle_route_add_evt(ipa_ip_type iptype) } else { + /* set mtu_default_wan to current default wan instance */ + mtu_default_wan_v6 = mtu_v6; + IPACMDBG_H("replace the mtu_wan to %d\n", mtu_default_wan_v6); + memcpy(backhaul_ipv6_prefix, ipv6_prefix, sizeof(backhaul_ipv6_prefix)); IPACMDBG_H("Setup backhaul ipv6 prefix to be 0x%08x%08x.\n", backhaul_ipv6_prefix[0], backhaul_ipv6_prefix[1]); @@ -2244,11 +2387,28 @@ int IPACM_Wan::handle_route_add_evt(ipa_ip_type iptype) } IPACMDBG_H("send WAN_IOC_NOTIFY_WAN_STATE up to IPA_PM\n"); wan_state.up = true; +#ifdef WAN_IOCTL_NOTIFY_WAN_INTF_NAME + strlcpy(wan_state.upstreamIface, dev_name, IFNAMSIZ); +#endif if(ioctl(fd_wwan_ioctl, WAN_IOC_NOTIFY_WAN_STATE, &wan_state)) { IPACMERR("Failed to send WAN_IOC_NOTIFY_WAN_STATE as up %d\n ", wan_state.up); } close(fd_wwan_ioctl); + + /* Store the Offload state. */ + FILE *fp = NULL; + fp = fopen(IPA_OFFLOAD_TETHER_STATE_FILE_NAME, "w"); + if (fp == NULL) + { + IPACMERR("Failed to write offload state to %s, error is %d - %s\n", + IPA_OFFLOAD_TETHER_STATE_FILE_NAME, errno, strerror(errno)); + } + else + { + fprintf(fp, "UPSTREAM=%s,STATE=UP", dev_name); + fclose(fp); + } } ipa_pm_q6_check++; IPACMDBG_H("update ipa_pm_q6_check to %d\n", ipa_pm_q6_check); @@ -2376,7 +2536,7 @@ int IPACM_Wan::post_wan_down_tether_evt(ipa_ip_type iptype, int ipa_if_num_tethe #endif /* construct complete ethernet header */ -int IPACM_Wan::handle_sta_header_add_evt() +int IPACM_Wan::handle_sta_header_add_evt(bool renew) { int res = IPACM_SUCCESS, index = IPACM_INVALID_INDEX; if((header_set_v4 == true) || (header_set_v6 == true)) @@ -2433,7 +2593,13 @@ int IPACM_Wan::handle_sta_header_add_evt() } } - /* checking if the ipv4 same as default route */ + /* see if v4 default routes are setup before constructing full header */ + if(header_partial_default_wan_v4 == true) + { + handle_route_add_evt(IPA_IP_v4, renew); + } + + /* checking if the ipv6 same as default route */ if(wan_v6_addr_gw_set) { index = get_wan_client_index_ipv6(wan_v6_addr_gw); @@ -2481,15 +2647,11 @@ int IPACM_Wan::handle_sta_header_add_evt() } } - /* see if default routes are setup before constructing full header */ - if(header_partial_default_wan_v4 == true) - { - handle_route_add_evt(IPA_IP_v4); - } + /* see if v6 default routes are setup before constructing full header */ if(header_partial_default_wan_v6 == true) { - handle_route_add_evt(IPA_IP_v6); + handle_route_add_evt(IPA_IP_v6, renew); } return res; } @@ -2567,7 +2729,7 @@ int IPACM_Wan::config_dft_firewall_rules(ipa_ip_type iptype) } else { - IPACMDBG_H("in Q6_MHI_WAN mode, skip firewall, use default configuration \n"); + IPACMDBG_H("in Q6_MHI_WAN mode, skip firewall, use default configuration \n"); } /* construct ipa_ioc_add_flt_rule with N firewall rules */ ipa_ioc_add_flt_rule *m_pFilteringTable = NULL; @@ -2591,10 +2753,11 @@ int IPACM_Wan::config_dft_firewall_rules(ipa_ip_type iptype) memset(&flt_rule_entry, 0, sizeof(struct ipa_flt_rule_add)); flt_rule_entry.at_rear = true; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.at_rear = false; - flt_rule_entry.rule.hashable = false; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + { + flt_rule_entry.at_rear = false; + flt_rule_entry.rule.hashable = false; + } flt_rule_entry.flt_rule_hdl = -1; flt_rule_entry.status = -1; flt_rule_entry.rule.action = IPA_PASS_TO_EXCEPTION; @@ -2686,10 +2849,11 @@ int IPACM_Wan::config_dft_firewall_rules(ipa_ip_type iptype) flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; } } -#ifdef FEATURE_IPA_V3 - flt_rule_entry.at_rear = true; - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + { + flt_rule_entry.at_rear = true; + flt_rule_entry.rule.hashable = true; + } flt_rule_entry.rule.rt_tbl_hdl = IPACM_Iface::ipacmcfg->rt_tbl_lan_v4.hdl; memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, @@ -2783,9 +2947,8 @@ int IPACM_Wan::config_dft_firewall_rules(ipa_ip_type iptype) { flt_rule_entry.rule.action = IPA_PASS_TO_EXCEPTION; } -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; memcpy(&flt_rule_entry.rule.attrib, &firewall_config.extd_firewall_entries[i].attrib, sizeof(struct ipa_rule_attrib)); @@ -2953,9 +3116,8 @@ int IPACM_Wan::config_dft_firewall_rules(ipa_ip_type iptype) flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; } } -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; flt_rule_entry.rule.rt_tbl_hdl = IPACM_Iface::ipacmcfg->rt_tbl_lan_v4.hdl; memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, @@ -3020,9 +3182,8 @@ int IPACM_Wan::config_dft_firewall_rules(ipa_ip_type iptype) flt_rule_entry.rule.retain_hdr = 1; flt_rule_entry.rule.eq_attrib_type = 0; flt_rule_entry.rule.action = IPA_PASS_TO_EXCEPTION; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, sizeof(struct ipa_rule_attrib)); @@ -3059,7 +3220,7 @@ int IPACM_Wan::config_dft_firewall_rules(ipa_ip_type iptype) } else { - IPACMDBG_H("in Q6_MHI_WAN mode, skip ICMPv6 flt rule \n"); + IPACMDBG_H("in Q6_MHI_WAN mode, skip ICMPv6 flt rule \n"); } /* v6 default route */ memset(&flt_rule_entry, 0, sizeof(struct ipa_flt_rule_add)); @@ -3093,9 +3254,8 @@ int IPACM_Wan::config_dft_firewall_rules(ipa_ip_type iptype) flt_rule_entry.at_rear = true; flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; } -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, sizeof(struct ipa_rule_attrib)); @@ -3183,10 +3343,9 @@ int IPACM_Wan::config_dft_firewall_rules(ipa_ip_type iptype) { flt_rule_entry.rule.action = IPA_PASS_TO_EXCEPTION; } -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif - flt_rule_entry.rule.rt_tbl_hdl = IPACM_Iface::ipacmcfg->rt_tbl_wan_v6.hdl; + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; + flt_rule_entry.rule.rt_tbl_hdl = IPACM_Iface::ipacmcfg->rt_tbl_wan_v6.hdl; memcpy(&flt_rule_entry.rule.attrib, &firewall_config.extd_firewall_entries[i].attrib, sizeof(struct ipa_rule_attrib)); @@ -3304,9 +3463,8 @@ int IPACM_Wan::config_dft_firewall_rules(ipa_ip_type iptype) flt_rule_entry.rule.retain_hdr = 1; flt_rule_entry.rule.eq_attrib_type = 0; flt_rule_entry.rule.action = IPA_PASS_TO_EXCEPTION; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, sizeof(struct ipa_rule_attrib)); @@ -3368,9 +3526,8 @@ int IPACM_Wan::config_dft_firewall_rules(ipa_ip_type iptype) flt_rule_entry.at_rear = true; flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; } -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, sizeof(struct ipa_rule_attrib)); @@ -3467,9 +3624,8 @@ int IPACM_Wan::config_dft_firewall_rules_ex(struct ipa_flt_rule_add *rules, int { memset(&flt_rule_entry, 0, sizeof(struct ipa_flt_rule_add)); flt_rule_entry.at_rear = true; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.at_rear = false; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.at_rear = false; flt_rule_entry.flt_rule_hdl = -1; flt_rule_entry.status = -1; @@ -3477,10 +3633,11 @@ int IPACM_Wan::config_dft_firewall_rules_ex(struct ipa_flt_rule_add *rules, int flt_rule_entry.rule.to_uc = 0; flt_rule_entry.rule.eq_attrib_type = 1; flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.at_rear = false; - flt_rule_entry.rule.hashable = false; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + { + flt_rule_entry.at_rear = false; + flt_rule_entry.rule.hashable = false; + } memset(&rt_tbl_idx, 0, sizeof(rt_tbl_idx)); rt_tbl_idx.ip = IPA_IP_v6; strlcpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_dl.name, IPA_RESOURCE_NAME_MAX); @@ -3546,9 +3703,8 @@ int IPACM_Wan::config_dft_firewall_rules_ex(struct ipa_flt_rule_add *rules, int { flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; } -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; memset(&rt_tbl_idx, 0, sizeof(rt_tbl_idx)); rt_tbl_idx.ip = iptype; if(flt_rule_entry.rule.action == IPA_PASS_TO_ROUTING) @@ -3683,9 +3839,8 @@ int IPACM_Wan::config_dft_firewall_rules_ex(struct ipa_flt_rule_add *rules, int flt_rule_entry.rule.action = IPA_PASS_TO_DST_NAT; } } -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; memset(&rt_tbl_idx, 0, sizeof(rt_tbl_idx)); rt_tbl_idx.ip = iptype; @@ -3758,9 +3913,8 @@ int IPACM_Wan::config_dft_firewall_rules_ex(struct ipa_flt_rule_add *rules, int flt_rule_entry.rule.to_uc = 0; flt_rule_entry.rule.eq_attrib_type = 1; flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; memset(&rt_tbl_idx, 0, sizeof(rt_tbl_idx)); rt_tbl_idx.ip = iptype; @@ -3871,9 +4025,8 @@ int IPACM_Wan::config_dft_firewall_rules_ex(struct ipa_flt_rule_add *rules, int flt_rule_entry.rule.to_uc = 0; flt_rule_entry.rule.eq_attrib_type = 1; flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; memset(&rt_tbl_idx, 0, sizeof(rt_tbl_idx)); rt_tbl_idx.ip = iptype; /* firewall disable, all traffic are allowed */ @@ -4025,9 +4178,8 @@ int IPACM_Wan::add_icmp_alg_rules(struct ipa_flt_rule_add *rules, int rule_offse flt_rule_entry.rule.to_uc = 0; flt_rule_entry.rule.eq_attrib_type = 1; flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; flt_rule_entry.rule.rt_tbl_idx = rt_tbl_idx.idx; /* Configuring ICMP filtering rule */ @@ -4143,9 +4295,8 @@ int IPACM_Wan::add_icmp_alg_rules(struct ipa_flt_rule_add *rules, int rule_offse flt_rule_entry.rule.to_uc = 0; flt_rule_entry.rule.eq_attrib_type = 1; flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; flt_rule_entry.rule.rt_tbl_idx = rt_tbl_idx.idx; /* Configuring ICMP filtering rule */ @@ -4225,15 +4376,18 @@ int IPACM_Wan::query_ext_prop() for (cnt = 0; cnt < ext_prop->num_ext_props; cnt++) { -#ifndef FEATURE_IPA_V3 - IPACMDBG_H("Ex(%d): ip-type: %d, mux_id: %d, flt_action: %d\n, rt_tbl_idx: %d, is_xlat_rule: %d flt_hdl: %d\n", - cnt, ext_prop->ext[cnt].ip, ext_prop->ext[cnt].mux_id, ext_prop->ext[cnt].action, - ext_prop->ext[cnt].rt_tbl_idx, ext_prop->ext[cnt].is_xlat_rule, ext_prop->ext[cnt].filter_hdl); -#else /* defined (FEATURE_IPA_V3) */ - IPACMDBG_H("Ex(%d): ip-type: %d, mux_id: %d, flt_action: %d\n, rt_tbl_idx: %d, is_xlat_rule: %d rule_id: %d\n", - cnt, ext_prop->ext[cnt].ip, ext_prop->ext[cnt].mux_id, ext_prop->ext[cnt].action, - ext_prop->ext[cnt].rt_tbl_idx, ext_prop->ext[cnt].is_xlat_rule, ext_prop->ext[cnt].rule_id); -#endif + if (!IPACM_Iface::ipacmcfg->isIPAv3Supported()) + { + IPACMDBG_H("Ex(%d): ip-type: %d, mux_id: %d, flt_action: %d\n, rt_tbl_idx: %d, is_xlat_rule: %d flt_hdl: %d\n", + cnt, ext_prop->ext[cnt].ip, ext_prop->ext[cnt].mux_id, ext_prop->ext[cnt].action, + ext_prop->ext[cnt].rt_tbl_idx, ext_prop->ext[cnt].is_xlat_rule, ext_prop->ext[cnt].filter_hdl); + } + else /* IPA_V3 */ + { + IPACMDBG_H("Ex(%d): ip-type: %d, mux_id: %d, flt_action: %d\n, rt_tbl_idx: %d, is_xlat_rule: %d rule_id: %d\n", + cnt, ext_prop->ext[cnt].ip, ext_prop->ext[cnt].mux_id, ext_prop->ext[cnt].action, + ext_prop->ext[cnt].rt_tbl_idx, ext_prop->ext[cnt].is_xlat_rule, ext_prop->ext[cnt].rule_id); + } } if(IPACM_Wan::is_ext_prop_set == false) @@ -4343,9 +4497,8 @@ int IPACM_Wan::add_dft_filtering_rule(struct ipa_flt_rule_add *rules, int rule_o flt_rule_entry.rule.to_uc = 0; flt_rule_entry.rule.eq_attrib_type = 1; flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; flt_rule_entry.rule.rt_tbl_idx = rt_tbl_idx.idx; IPACMDBG_H("rx property attrib mask:0x%x\n", rx_prop->rx[0].attrib.attrib_mask); @@ -4426,9 +4579,8 @@ int IPACM_Wan::add_dft_filtering_rule(struct ipa_flt_rule_add *rules, int rule_o flt_rule_entry.rule.to_uc = 0; flt_rule_entry.rule.eq_attrib_type = 1; flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; flt_rule_entry.rule.rt_tbl_idx = rt_tbl_idx.idx; /* Configuring Multicast Filtering Rule */ @@ -4687,7 +4839,7 @@ int IPACM_Wan::del_dft_firewall_rules(ipa_ip_type iptype) } /* for STA mode: wan default route/filter rule delete */ -int IPACM_Wan::handle_route_del_evt(ipa_ip_type iptype) +int IPACM_Wan::handle_route_del_evt(ipa_ip_type iptype, bool delete_only) { uint32_t tx_index; ipacm_cmd_q_data evt_data; @@ -4712,39 +4864,42 @@ int IPACM_Wan::handle_route_del_evt(ipa_ip_type iptype) if (((iptype == IPA_IP_v4) && (active_v4 == true)) || ((iptype == IPA_IP_v6) && (active_v6 == true))) { - if(IPACM_Iface::ipacmcfg->GetIPAVer() >= IPA_HW_None && IPACM_Iface::ipacmcfg->GetIPAVer() < IPA_HW_v4_0) + if (!delete_only) { - /* Delete corresponding ipa_rm_resource_name of TX-endpoint after delete IPV4/V6 RT-rule */ - IPACMDBG_H("dev %s delete producer dependency\n", dev_name); - IPACMDBG_H("depend Got pipe %d rm index : %d \n", tx_prop->tx[0].dst_pipe, IPACM_Iface::ipacmcfg->ipa_client_rm_map_tbl[tx_prop->tx[0].dst_pipe]); - IPACM_Iface::ipacmcfg->DelRmDepend(IPACM_Iface::ipacmcfg->ipa_client_rm_map_tbl[tx_prop->tx[0].dst_pipe]); - } - else - { - /* change wan_state for Q6_MHI */ -#ifdef WAN_IOC_NOTIFY_WAN_STATE - IPACMDBG_H("ipa_pm_q6_check to %d\n", ipa_pm_q6_check); - if(ipa_pm_q6_check == 1 && m_is_sta_mode == Q6_MHI_WAN) + if(IPACM_Iface::ipacmcfg->GetIPAVer() >= IPA_HW_None && IPACM_Iface::ipacmcfg->GetIPAVer() < IPA_HW_v4_0) { - fd_wwan_ioctl = open(WWAN_QMI_IOCTL_DEVICE_NAME, O_RDWR); - if(fd_wwan_ioctl < 0) - { - IPACMERR("Failed to open %s.\n",WWAN_QMI_IOCTL_DEVICE_NAME); - return false; - } - IPACMDBG_H("send WAN_IOC_NOTIFY_WAN_STATE down to IPA_PM\n"); - if(ioctl(fd_wwan_ioctl, WAN_IOC_NOTIFY_WAN_STATE, &wan_state)) - { - IPACMERR("Failed to send WAN_IOC_NOTIFY_WAN_STATE as up %d\n ", wan_state.up); - } - close(fd_wwan_ioctl); + /* Delete corresponding ipa_rm_resource_name of TX-endpoint after delete IPV4/V6 RT-rule */ + IPACMDBG_H("dev %s delete producer dependency\n", dev_name); + IPACMDBG_H("depend Got pipe %d rm index : %d \n", tx_prop->tx[0].dst_pipe, IPACM_Iface::ipacmcfg->ipa_client_rm_map_tbl[tx_prop->tx[0].dst_pipe]); + IPACM_Iface::ipacmcfg->DelRmDepend(IPACM_Iface::ipacmcfg->ipa_client_rm_map_tbl[tx_prop->tx[0].dst_pipe]); } - if (ipa_pm_q6_check > 0) - ipa_pm_q6_check--; else - IPACMERR(" ipa_pm_q6_check becomes negative !!!\n"); + { + /* change wan_state for Q6_MHI */ +#ifdef WAN_IOC_NOTIFY_WAN_STATE + IPACMDBG_H("ipa_pm_q6_check to %d\n", ipa_pm_q6_check); + if(ipa_pm_q6_check == 1 && m_is_sta_mode == Q6_MHI_WAN) + { + fd_wwan_ioctl = open(WWAN_QMI_IOCTL_DEVICE_NAME, O_RDWR); + if(fd_wwan_ioctl < 0) + { + IPACMERR("Failed to open %s.\n",WWAN_QMI_IOCTL_DEVICE_NAME); + return false; + } + IPACMDBG_H("send WAN_IOC_NOTIFY_WAN_STATE down to IPA_PM\n"); + if(ioctl(fd_wwan_ioctl, WAN_IOC_NOTIFY_WAN_STATE, &wan_state)) + { + IPACMERR("Failed to send WAN_IOC_NOTIFY_WAN_STATE as up %d\n ", wan_state.up); + } + close(fd_wwan_ioctl); + } + if (ipa_pm_q6_check > 0) + ipa_pm_q6_check--; + else + IPACMERR(" ipa_pm_q6_check becomes negative !!!\n"); #endif - } + } + } // end of delete_only for (tx_index = 0; tx_index < iface_query->num_tx_props; tx_index++) { @@ -4787,6 +4942,14 @@ int IPACM_Wan::handle_route_del_evt(ipa_ip_type iptype) return IPACM_FAILURE; } } + + /* support delete only, not post wan_down event */ + if(delete_only) + { + IPACMDBG_H(" Only delete default WAN routing rules (%d)\n", delete_only); + return IPACM_SUCCESS; + } + ipacm_event_iface_up *wandown_data; wandown_data = (ipacm_event_iface_up *)malloc(sizeof(ipacm_event_iface_up)); if (wandown_data == NULL) @@ -4916,11 +5079,28 @@ int IPACM_Wan::handle_route_del_evt_ex(ipa_ip_type iptype) return false; } IPACMDBG_H("send WAN_IOC_NOTIFY_WAN_STATE down to IPA_PM\n"); +#ifdef WAN_IOCTL_NOTIFY_WAN_INTF_NAME + strlcpy(wan_state.upstreamIface, dev_name, IFNAMSIZ); +#endif if(ioctl(fd_wwan_ioctl, WAN_IOC_NOTIFY_WAN_STATE, &wan_state)) { IPACMERR("Failed to send WAN_IOC_NOTIFY_WAN_STATE as up %d\n ", wan_state.up); } close(fd_wwan_ioctl); + + /* Store the Offload state. */ + FILE *fp = NULL; + fp = fopen(IPA_OFFLOAD_TETHER_STATE_FILE_NAME, "w"); + if (fp == NULL) + { + IPACMERR("Failed to write offload state to %s, error is %d - %s\n", + IPA_OFFLOAD_TETHER_STATE_FILE_NAME, errno, strerror(errno)); + } + else + { + fprintf(fp, "UPSTREAM=%s,STATE=DOWN", dev_name); + fclose(fp); + } } if (ipa_pm_q6_check > 0) ipa_pm_q6_check--; @@ -5044,9 +5224,8 @@ int IPACM_Wan::config_dft_embms_rules(ipa_ioc_add_flt_rule *pFilteringTable_v4, flt_rule_entry.rule.to_uc = 0; flt_rule_entry.rule.eq_attrib_type = 1; flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; flt_rule_entry.rule.rt_tbl_idx = rt_tbl_idx.idx; memcpy(&flt_rule_entry.rule.attrib, @@ -5093,9 +5272,8 @@ int IPACM_Wan::config_dft_embms_rules(ipa_ioc_add_flt_rule *pFilteringTable_v4, flt_rule_entry.rule.to_uc = 0; flt_rule_entry.rule.eq_attrib_type = 1; flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; flt_rule_entry.rule.rt_tbl_idx = rt_tbl_idx.idx; memcpy(&flt_rule_entry.rule.attrib, @@ -5446,8 +5624,13 @@ int IPACM_Wan::handle_down_evt_ex() goto fail; } +#ifndef IPA_MTU_EVENT_MAX /* reset the mtu size */ - mtu_size = DEFAULT_MTU_SIZE; + mtu_v4 = DEFAULT_MTU_SIZE; + mtu_v4_set = false; + mtu_v6 = DEFAULT_MTU_SIZE; + mtu_v6_set = false; +#endif if(ip_type == IPA_IP_v4) { @@ -5807,9 +5990,8 @@ int IPACM_Wan::install_wan_filtering_rule(bool is_sw_routing) flt_rule_entry.flt_rule_hdl = -1; flt_rule_entry.status = -1; flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; flt_rule_entry.rule.rt_tbl_idx = rt_tbl_idx.idx; @@ -5869,9 +6051,8 @@ int IPACM_Wan::install_wan_filtering_rule(bool is_sw_routing) flt_rule_entry.flt_rule_hdl = -1; flt_rule_entry.status = -1; flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; flt_rule_entry.rule.rt_tbl_idx = rt_tbl_idx.idx; memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, @@ -6014,7 +6195,7 @@ fail: /* handle STA WAN-client */ /* handle WAN client initial, construct full headers (tx property) */ -int IPACM_Wan::handle_wan_hdr_init(uint8_t *mac_addr) +int IPACM_Wan::handle_wan_hdr_init(uint8_t *mac_addr, bool replaced, int entry) { #define WAN_IFACE_INDEX_LEN 2 @@ -6026,38 +6207,41 @@ int IPACM_Wan::handle_wan_hdr_init(uint8_t *mac_addr) uint32_t cnt; int clnt_indx; - clnt_indx = get_wan_client_index(mac_addr); - - if (clnt_indx != IPACM_INVALID_INDEX) - { - IPACMERR("eth client is found/attached already with index %d \n", clnt_indx); - return IPACM_FAILURE; - } - - /* add header to IPA */ - if (num_wan_client >= IPA_MAX_NUM_WAN_CLIENTS) - { - IPACMERR("Reached maximum number(%d) of eth clients\n", IPA_MAX_NUM_WAN_CLIENTS); - return IPACM_FAILURE; - } - IPACMDBG_H("WAN client number: %d\n", num_wan_client); - memcpy(get_client_memptr(wan_client, num_wan_client)->mac, + if(!replaced) + { + clnt_indx = get_wan_client_index(mac_addr); + + if (clnt_indx != IPACM_INVALID_INDEX) + { + IPACMERR("eth client is found/attached already with index %d \n", clnt_indx); + return IPACM_FAILURE; + } + + /* add header to IPA */ + if (num_wan_client >= IPA_MAX_NUM_WAN_CLIENTS) + { + IPACMERR("Reached maximum number(%d) of eth clients\n", IPA_MAX_NUM_WAN_CLIENTS); + return IPACM_FAILURE; + } + + memcpy(get_client_memptr(wan_client, num_wan_client)->mac, mac_addr, sizeof(get_client_memptr(wan_client, num_wan_client)->mac)); - IPACMDBG_H("Received Client MAC %02x:%02x:%02x:%02x:%02x:%02x\n", + IPACMDBG_H("Received Client MAC %02x:%02x:%02x:%02x:%02x:%02x\n", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); - IPACMDBG_H("stored MAC %02x:%02x:%02x:%02x:%02x:%02x\n", + IPACMDBG_H("stored MAC %02x:%02x:%02x:%02x:%02x:%02x\n", get_client_memptr(wan_client, num_wan_client)->mac[0], get_client_memptr(wan_client, num_wan_client)->mac[1], get_client_memptr(wan_client, num_wan_client)->mac[2], get_client_memptr(wan_client, num_wan_client)->mac[3], get_client_memptr(wan_client, num_wan_client)->mac[4], get_client_memptr(wan_client, num_wan_client)->mac[5]); + } /* add header to IPA */ if(tx_prop != NULL) @@ -6158,13 +6342,23 @@ int IPACM_Wan::handle_wan_hdr_init(uint8_t *mac_addr) goto fail; } - get_client_memptr(wan_client, num_wan_client)->hdr_hdl_v4 = pHeaderDescriptor->hdr[0].hdr_hdl; - IPACMDBG_H("eth-client(%d) v4 full header name:%s header handle:(0x%x)\n", + if (!replaced) + { + get_client_memptr(wan_client, num_wan_client)->hdr_hdl_v4 = pHeaderDescriptor->hdr[0].hdr_hdl; + IPACMDBG_H("eth-client(%d) v4 full header name:%s header handle:(0x%x)\n", num_wan_client, pHeaderDescriptor->hdr[0].name, get_client_memptr(wan_client, num_wan_client)->hdr_hdl_v4); get_client_memptr(wan_client, num_wan_client)->ipv4_header_set=true; - + } else + { + get_client_memptr(wan_client, entry)->hdr_hdl_v4 = pHeaderDescriptor->hdr[0].hdr_hdl; + IPACMDBG_H("replaced eth-client(%d) v4 full header name:%s header handle:(0x%x)\n", + entry, + pHeaderDescriptor->hdr[0].name, + get_client_memptr(wan_client, entry)->hdr_hdl_v4); + get_client_memptr(wan_client, entry)->ipv4_header_set=true; + } break; } } @@ -6254,24 +6448,45 @@ int IPACM_Wan::handle_wan_hdr_init(uint8_t *mac_addr) goto fail; } - get_client_memptr(wan_client, num_wan_client)->hdr_hdl_v6 = pHeaderDescriptor->hdr[0].hdr_hdl; - IPACMDBG_H("eth-client(%d) v6 full header name:%s header handle:(0x%x)\n", + if (!replaced) + { + get_client_memptr(wan_client, num_wan_client)->hdr_hdl_v6 = pHeaderDescriptor->hdr[0].hdr_hdl; + IPACMDBG_H("eth-client(%d) v6 full header name:%s header handle:(0x%x)\n", num_wan_client, pHeaderDescriptor->hdr[0].name, get_client_memptr(wan_client, num_wan_client)->hdr_hdl_v6); - get_client_memptr(wan_client, num_wan_client)->ipv6_header_set=true; + } + else + { + get_client_memptr(wan_client, entry)->hdr_hdl_v6 = pHeaderDescriptor->hdr[0].hdr_hdl; + IPACMDBG_H("replaced eth-client(%d) v6 full header name:%s header handle:(0x%x)\n", + entry, + pHeaderDescriptor->hdr[0].name, + get_client_memptr(wan_client, entry)->hdr_hdl_v6); + get_client_memptr(wan_client, entry)->ipv6_header_set=true; + } break; } } /* initialize wifi client*/ - get_client_memptr(wan_client, num_wan_client)->route_rule_set_v4 = false; - get_client_memptr(wan_client, num_wan_client)->route_rule_set_v6 = 0; - get_client_memptr(wan_client, num_wan_client)->ipv4_set = false; - get_client_memptr(wan_client, num_wan_client)->ipv6_set = 0; - num_wan_client++; + if (!replaced) + { + get_client_memptr(wan_client, num_wan_client)->route_rule_set_v4 = false; + get_client_memptr(wan_client, num_wan_client)->route_rule_set_v6 = 0; + get_client_memptr(wan_client, num_wan_client)->ipv4_set = false; + get_client_memptr(wan_client, num_wan_client)->ipv6_set = 0; + num_wan_client++; + } + else + { + get_client_memptr(wan_client, entry)->route_rule_set_v4 = false; + get_client_memptr(wan_client, entry)->route_rule_set_v6 = 0; + get_client_memptr(wan_client, entry)->ipv4_set = false; + get_client_memptr(wan_client, entry)->ipv6_set = 0; + } header_name_count++; //keep increasing header_name_count res = IPACM_SUCCESS; IPACMDBG_H("eth client number: %d\n", num_wan_client); @@ -6499,9 +6714,8 @@ int IPACM_Wan::handle_wan_client_route_rule(uint8_t *mac_addr, ipa_ip_type iptyp rt_rule_entry->rule.hdr_hdl = get_client_memptr(wan_client, wan_index)->hdr_hdl_v4; rt_rule_entry->rule.attrib.u.v4.dst_addr = get_client_memptr(wan_client, wan_index)->v4_addr; rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF; -#ifdef FEATURE_IPA_V3 - rt_rule_entry->rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + rt_rule_entry->rule.hashable = true; if (false == m_routing.AddRoutingRule(rt_rule)) { IPACMERR("Routing rule addition failed!\n"); @@ -6549,9 +6763,8 @@ int IPACM_Wan::handle_wan_client_route_rule(uint8_t *mac_addr, ipa_ip_type iptyp rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF; rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF; rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF; -#ifdef FEATURE_IPA_V3 - rt_rule_entry->rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + rt_rule_entry->rule.hashable = true; if (false == m_routing.AddRoutingRule(rt_rule)) { IPACMERR("Routing rule addition failed!\n"); @@ -7125,9 +7338,8 @@ int IPACM_Wan::handle_coalesce_evt() strlcpy(rt_rule->rt_tbl_name, IPACM_Iface::ipacmcfg->rt_tbl_lan_v4.name, sizeof(rt_rule->rt_tbl_name)); rt_rule_entry->rule.attrib.u.v4.dst_addr = wan_v4_addr; rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF; -#ifdef FEATURE_IPA_V3 - rt_rule_entry->rule.hashable = false; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + rt_rule_entry->rule.hashable = false; /* query qmap header*/ memset(&hdr, 0, sizeof(hdr)); strlcpy(hdr.name, tx_prop->tx[0].hdr_name, sizeof(hdr.name)); @@ -7249,17 +7461,16 @@ fail: rt_rule_entry = &rt_rule->rules[0]; rt_rule_entry->at_rear = false; rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR; - rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = ipv6_addr[num_dft_rt_v6][0]; - rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = ipv6_addr[num_dft_rt_v6][1]; - rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = ipv6_addr[num_dft_rt_v6][2]; - rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = ipv6_addr[num_dft_rt_v6][3]; + rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = ipv6_addr[i][0]; + rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = ipv6_addr[i][1]; + rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = ipv6_addr[i][2]; + rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = ipv6_addr[i][3]; rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF; rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF; rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF; rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF; -#ifdef FEATURE_IPA_V3 - rt_rule_entry->rule.hashable = false; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + rt_rule_entry->rule.hashable = false; strlcpy(hdr.name, tx_prop->tx[0].hdr_name, sizeof(hdr.name)); hdr.name[IPA_RESOURCE_NAME_MAX-1] = '\0'; if(m_header.GetHeaderHandle(&hdr) == false) @@ -7400,9 +7611,8 @@ int IPACM_Wan::add_offload_frag_rule() flt_rule_entry.rule.to_uc = 0; flt_rule_entry.rule.eq_attrib_type = 1; flt_rule_entry.rule.action = IPA_PASS_TO_EXCEPTION; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; IPACMDBG_H("rx property attrib mask:0x%x\n", rx_prop->rx[0].attrib.attrib_mask); memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, @@ -7541,9 +7751,8 @@ int IPACM_Wan::add_icmpv6_exception_rule() flt_rule_entry.flt_rule_hdl = -1; flt_rule_entry.status = -1; flt_rule_entry.rule.action = IPA_PASS_TO_EXCEPTION; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; IPACMDBG_H("rx property attrib mask:0x%x\n", rx_prop->rx[0].attrib.attrib_mask); memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, sizeof(flt_rule_entry.rule.attrib)); flt_rule_entry.rule.attrib.attrib_mask |= IPA_FLT_NEXT_HDR; @@ -7714,11 +7923,10 @@ int IPACM_Wan::add_tcp_fin_rst_exception_rule() sizeof(flt_rule_entry.rule.eq_attrib)); /* set the bit mask to use MEQ32_IHL offset */ - #ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.eq_attrib.rule_eq_bitmap |= (1<<7); - #else - flt_rule_entry.rule.eq_attrib.rule_eq_bitmap |= (1<<8); - #endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.eq_attrib.rule_eq_bitmap |= (1<<7); + else + flt_rule_entry.rule.eq_attrib.rule_eq_bitmap |= (1<<8); /* add offset to compare TCP flags */ flt_rule_entry.rule.eq_attrib.num_ihl_offset_meq_32 = 1; @@ -7830,11 +8038,126 @@ int IPACM_Wan::query_mtu_size() return IPACM_FAILURE; } IPACMDBG_H("mtu=[%d]\n", if_mtu.ifr_mtu); - if (if_mtu.ifr_mtu < DEFAULT_MTU_SIZE) { - mtu_size = if_mtu.ifr_mtu; - IPACMDBG_H("replaced mtu=[%d] for (%s)\n", mtu_size, dev_name); + if (if_mtu.ifr_mtu <= DEFAULT_MTU_SIZE) { + mtu_v4 = mtu_v6 = if_mtu.ifr_mtu; + }else { + mtu_v4 = mtu_v6 = DEFAULT_MTU_SIZE; } + IPACMDBG_H("Updated mtu=[%d] for (%s)\n", mtu_v4, dev_name); close(fd); return IPACM_SUCCESS; } + +/* construct complete ethernet header */ +int IPACM_Wan::handle_gw_mac_renew(ipacm_event_data_all *data, int index_client) +{ + int index = IPACM_INVALID_INDEX; + + /* checking if client has same ipv4, v6 will put future work */ + if (data->iptype == IPA_IP_v4) + { + index = get_wan_client_index_ipv4(data->ipv4_addr); + if (index != IPACM_INVALID_INDEX) + { + IPACMDBG_H("Matched client index: %d\n", index); + IPACMDBG_H("Client MAC in cache %02x:%02x:%02x:%02x:%02x:%02x\n", + get_client_memptr(wan_client, index)->mac[0], + get_client_memptr(wan_client, index)->mac[1], + get_client_memptr(wan_client, index)->mac[2], + get_client_memptr(wan_client, index)->mac[3], + get_client_memptr(wan_client, index)->mac[4], + get_client_memptr(wan_client, index)->mac[5]); + + /* check mac same or not */ + if ((data->mac_addr[0] == get_client_memptr(wan_client, index)->mac[0]) && + (data->mac_addr[1] == get_client_memptr(wan_client, index)->mac[1]) && + (data->mac_addr[2] == get_client_memptr(wan_client, index)->mac[2]) && + (data->mac_addr[3] == get_client_memptr(wan_client, index)->mac[3]) && + (data->mac_addr[4] == get_client_memptr(wan_client, index)->mac[4]) && + (data->mac_addr[5] == get_client_memptr(wan_client, index)->mac[5])) + { + IPACMDBG_H(" No need client (%d) mac renew with IPv4 (0x%x)\n", index, data->ipv4_addr); + return IPACM_FAILURE; + } + else + { + IPACMDBG_H(" client %d need mac renew with IPv4 (0x%x)\n", index, data->ipv4_addr); + + /* Del NAT rules before ipv4 RT rules are delete */ + if(get_client_memptr(wan_client, index)->ipv4_set == true) + { + IPACMDBG_H("Clean Nat Rules for ipv4:0x%x\n", get_client_memptr(wan_client, index)->v4_addr); + CtList->HandleSTAClientDelEvt(get_client_memptr(wan_client, index)->v4_addr); + } + + /* clean up STA header / routing rule */ + if (data->ipv4_addr == wan_v4_addr_gw && active_v4) + { + handle_route_del_evt(IPA_IP_v4, true); + IPACMDBG_H("Delete default v4 routing rules\n"); + hdr_hdl_sta_v4 = 0; + header_set_v4 = false; + header_partial_default_wan_v4 = true; + + if (active_v6) + { + handle_route_del_evt(IPA_IP_v6, true); + IPACMDBG_H("Delete default v6 routing rules\n"); + header_partial_default_wan_v6 = true; + } + hdr_hdl_sta_v6 = 0; + header_set_v6 = false; + } + + /* clean up client header routing rule entry */ + if(delete_wan_rtrules(index, IPA_IP_v4)) + { + IPACMERR("unbale to delete wan-client v4 route rules for index %d\n", index); + return IPACM_FAILURE; + } + + get_client_memptr(wan_client, index)->route_rule_set_v4 = false; + get_client_memptr(wan_client, index)->ipv4_set = false; + + IPACMDBG_H("Delete client %d header\n", index); + if(get_client_memptr(wan_client, index)->ipv4_header_set == true) + { + if (m_header.DeleteHeaderHdl(get_client_memptr(wan_client, index)->hdr_hdl_v4) == false) + { + IPACMERR("unable to delete client v4 header for index %d\n", index); + return IPACM_FAILURE; + } + get_client_memptr(wan_client, index)->ipv4_header_set = false; + } + + if(delete_wan_rtrules(index, IPA_IP_v6)) + { + IPACMERR("unbale to delete wan-client v6 route rules for index %d\n", index); + return IPACM_FAILURE; + } + get_client_memptr(wan_client, index)->route_rule_set_v6 = 0; + get_client_memptr(wan_client, index)->ipv6_set = 0; + if(get_client_memptr(wan_client, index)->ipv6_header_set == true) + { + if (m_header.DeleteHeaderHdl(get_client_memptr(wan_client, index)->hdr_hdl_v6) == false) + { + IPACMERR("unable to delete client v6 header for index %d\n", index); + return IPACM_FAILURE; + } + get_client_memptr(wan_client, index)->ipv6_header_set = false; + } + /* replacing the old mac to new_mac on same entry */ + get_client_memptr(wan_client, index)->mac[0] = data->mac_addr[0]; + get_client_memptr(wan_client, index)->mac[1] = data->mac_addr[1]; + get_client_memptr(wan_client, index)->mac[2] = data->mac_addr[2]; + get_client_memptr(wan_client, index)->mac[3] = data->mac_addr[3]; + get_client_memptr(wan_client, index)->mac[4] = data->mac_addr[4]; + get_client_memptr(wan_client, index)->mac[5] = data->mac_addr[5]; + index_client = index; + return IPACM_SUCCESS; + } + } + } + return IPACM_FAILURE; +} diff --git a/data-ipa-cfg-mgr/ipacm/src/IPACM_Wlan.cpp b/data-ipa-cfg-mgr/ipacm/src/IPACM_Wlan.cpp index d5d38caa..eeb4b01f 100644 --- a/data-ipa-cfg-mgr/ipacm/src/IPACM_Wlan.cpp +++ b/data-ipa-cfg-mgr/ipacm/src/IPACM_Wlan.cpp @@ -206,20 +206,21 @@ void IPACM_Wlan::event_callback(ipa_cm_event_id event, void *param) IPACMDBG_H("Received IPA_LAN_DELETE_SELF event.\n"); IPACMDBG_H("ipa_WLAN (%s):ipa_index (%d) instance close \n", IPACM_Iface::ipacmcfg->iface_table[ipa_if_num].iface_name, ipa_if_num); -#ifdef FEATURE_ETH_BRIDGE_LE - if(rx_prop != NULL) + if (IPACM_Iface::ipacmcfg->isEthBridgingSupported()) { - free(rx_prop); + if(rx_prop != NULL) + { + free(rx_prop); + } + if(tx_prop != NULL) + { + free(tx_prop); + } + if(iface_query != NULL) + { + free(iface_query); + } } - if(tx_prop != NULL) - { - free(tx_prop); - } - if(iface_query != NULL) - { - free(iface_query); - } -#endif delete this; } break; @@ -561,25 +562,6 @@ void IPACM_Wlan::event_callback(ipa_cm_event_id event, void *param) if(ipa_interface_index == ipa_if_num) { IPACMDBG_H("Received IPA_DOWNSTREAM_ADD event.\n"); -#ifdef FEATURE_IPA_ANDROID - if (IPACM_Wan::isXlat() && (data->prefix.iptype == IPA_IP_v4)) - { - /* indicate v4-offload */ - IPACM_OffloadManager::num_offload_v4_tethered_iface++; - IPACMDBG_H("in xlat: update num_offload_v4_tethered_iface %d\n", IPACM_OffloadManager::num_offload_v4_tethered_iface); - - /* xlat not support for 2st tethered iface */ - if (IPACM_OffloadManager::num_offload_v4_tethered_iface > 1) - { - IPACMDBG_H("Not support 2st downstream iface %s for xlat, cur: %d\n", dev_name, - IPACM_OffloadManager::num_offload_v4_tethered_iface); - return; - } - } - - IPACMDBG_H(" support downstream iface %s, cur %d\n", dev_name, - IPACM_OffloadManager::num_offload_v4_tethered_iface); -#endif if(data->prefix.iptype < IPA_IP_MAX && is_downstream_set[data->prefix.iptype] == false) { IPACMDBG_H("Add downstream for IP iptype %d.\n", data->prefix.iptype); @@ -650,6 +632,35 @@ void IPACM_Wlan::event_callback(ipa_cm_event_id event, void *param) } break; } +#ifdef IPA_MTU_EVENT_MAX + case IPA_MTU_UPDATE: + { + IPACMDBG_H("Received IPA_MTU_UPDATE"); + ipacm_event_mtu_info *evt_data = (ipacm_event_mtu_info *)param; + ipa_mtu_info *data = &(evt_data->mtu_info); + + /* IPA_IP_MAX means both ipv4 and ipv6 */ + if ((data->ip_type == IPA_IP_v4 || data->ip_type == IPA_IP_MAX) && IPACM_Wan::isWanUP(ipa_if_num)) + { + handle_private_subnet_android(IPA_IP_v4); + } + + /* IPA_IP_MAX means both ipv4 and ipv6 */ + if ((data->ip_type == IPA_IP_v6 || data->ip_type == IPA_IP_MAX) && IPACM_Wan::isWanUP_V6(ipa_if_num)) + { + //check if the prefix + MTU rules are installed + if (ipv6_prefix_flt_rule_hdl[0] && ipv6_prefix_flt_rule_hdl[1]) { + modify_ipv6_prefix_flt_rule(IPACM_Wan::backhaul_ipv6_prefix); + } + else + { + IPACMERR("failed to update prefix MTU rules, no prefix rules set"); + } + } + } + break; +#endif + #else case IPA_HANDLE_WAN_UP: IPACMDBG_H("Received IPA_HANDLE_WAN_UP event\n"); @@ -1633,9 +1644,8 @@ int IPACM_Wlan::handle_wlan_client_route_rule(uint8_t *mac_addr, ipa_ip_type ipt rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF; rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF; rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF; -#ifdef FEATURE_IPA_V3 - rt_rule_entry->rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + rt_rule_entry->rule.hashable = true; if (false == m_routing.AddRoutingRule(rt_rule)) { IPACMERR("Routing rule addition failed!\n"); @@ -1685,9 +1695,8 @@ int IPACM_Wlan::handle_wlan_client_route_rule(uint8_t *mac_addr, ipa_ip_type ipt rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF; rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF; rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF; -#ifdef FEATURE_IPA_V3 - rt_rule_entry->rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + rt_rule_entry->rule.hashable = true; #ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO /* use index hw-counter */ if(IPACM_Iface::ipacmcfg->hw_fnr_stats_support) @@ -2137,9 +2146,8 @@ fail: IPACMDBG_H("depend Got pipe %d rm index : %d \n", rx_prop->rx[0].src_pipe, IPACM_Iface::ipacmcfg->ipa_client_rm_map_tbl[rx_prop->rx[0].src_pipe]); IPACM_Iface::ipacmcfg->DelRmDepend(IPACM_Iface::ipacmcfg->ipa_client_rm_map_tbl[rx_prop->rx[0].src_pipe]); } -#ifndef FEATURE_ETH_BRIDGE_LE - free(rx_prop); -#endif + if (!(IPACM_Iface::ipacmcfg->isEthBridgingSupported())) + free(rx_prop); } for (i = 0; i < num_wifi_client; i++) @@ -2153,17 +2161,18 @@ fail: { free(wlan_client); } -#ifndef FEATURE_ETH_BRIDGE_LE - if (tx_prop != NULL) + if (!(IPACM_Iface::ipacmcfg->isEthBridgingSupported())) { - free(tx_prop); - } + if (tx_prop != NULL) + { + free(tx_prop); + } - if (iface_query != NULL) - { - free(iface_query); + if (iface_query != NULL) + { + free(iface_query); + } } -#endif is_active = false; post_del_self_evt(); @@ -2504,9 +2513,8 @@ int IPACM_Wlan::add_connection(int client_index, int v6_num) flt_rule_entry.rule.to_uc = 0; flt_rule_entry.rule.eq_attrib_type = 1; flt_rule_entry.rule.action = IPA_PASS_TO_ROUTING; -#ifdef FEATURE_IPA_V3 - flt_rule_entry.rule.hashable = true; -#endif + if (IPACM_Iface::ipacmcfg->isIPAv3Supported()) + flt_rule_entry.rule.hashable = true; flt_rule_entry.rule.attrib.attrib_mask |= IPA_FLT_DST_ADDR; flt_rule_entry.rule.attrib.u.v6.dst_addr[0] = get_client_memptr(wlan_client, client_index)->v6_addr[v6_num][0]; flt_rule_entry.rule.attrib.u.v6.dst_addr[1] = get_client_memptr(wlan_client, client_index)->v6_addr[v6_num][1]; diff --git a/data-ipa-cfg-mgr/ipacm/src/ipacm.rc b/data-ipa-cfg-mgr/ipacm/src/ipacm.rc index 8381bf22..c1c876be 100644 --- a/data-ipa-cfg-mgr/ipacm/src/ipacm.rc +++ b/data-ipa-cfg-mgr/ipacm/src/ipacm.rc @@ -25,13 +25,10 @@ # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# msm specific files that need to be created on /data -on post-fs-data - mkdir /data/vendor/ipa 0770 radio radio - chmod 0770 /data/vendor/ipa - service vendor.ipacm /system/vendor/bin/ipacm - class late_start + class main user radio group radio inet - writepid /dev/cpuset/system-background/tasks + +on post-fs + start vendor.ipacm diff --git a/data-ipa-cfg-mgr/ipacm_vendor_product.mk b/data-ipa-cfg-mgr/ipacm_vendor_product.mk new file mode 100644 index 00000000..f225a303 --- /dev/null +++ b/data-ipa-cfg-mgr/ipacm_vendor_product.mk @@ -0,0 +1,50 @@ +TARGET_DISABLE_IPACM := false + +#IPACM_DATA +IPACM_DATA += IPACM_cfg.xml +IPACM_DATA += ipacm +IPACM_DATA += ipacm.rc + +ifeq ($(TARGET_USES_QMAA),true) +ifneq ($(TARGET_USES_QMAA_OVERRIDE_DATA),true) + TARGET_DISABLE_IPACM := true +endif #TARGET_USES_QMAA_OVERRIDE_DATA +endif #TARGET_USES_QMAA + +BOARD_IPA_LOW_RAM_EXCP_LIST := bengal + +ifeq ($(TARGET_HAS_LOW_RAM),true) +ifneq ($(call is-board-platform-in-list,$(BOARD_IPA_LOW_RAM_EXCP_LIST)),true) + TARGET_DISABLE_IPACM := true +endif +endif + +ifneq ($(TARGET_DISABLE_IPACM),true) +BOARD_PLATFORM_LIST := msm8909 +BOARD_PLATFORM_LIST += msm8916 +BOARD_PLATFORM_LIST += msm8917 +BOARD_PLATFORM_LIST += qm215 +BOARD_PLATFORM_LIST += msm8937 +BOARD_IPAv3_LIST := msm8998 +BOARD_IPAv3_LIST += sdm845 +BOARD_IPAv3_LIST += sdm710 +BOARD_IPAv3_LIST += msmnile +BOARD_IPAv3_LIST += kona +BOARD_IPAv3_LIST += $(MSMSTEPPE) +BOARD_IPAv3_LIST += $(TRINKET) +BOARD_IPAv3_LIST += lito +BOARD_IPAv3_LIST += atoll +BOARD_IPAv3_LIST += bengal +BOARD_ETH_BRIDGE_LIST := msmnile +BOARD_ETH_BRIDGE_LIST += kona + +ifneq ($(call is-board-platform-in-list,$(BOARD_PLATFORM_LIST)),true) +ifneq (,$(filter $(QCOM_BOARD_PLATFORMS),$(TARGET_BOARD_PLATFORM))) +ifneq (, $(filter aarch64 arm arm64, $(TARGET_ARCH))) + +PRODUCT_PACKAGES += $(IPACM_DATA) + +endif # $(TARGET_ARCH) +endif +endif +endif diff --git a/data-ipa-cfg-mgr/ipanat/Android.bp b/data-ipa-cfg-mgr/ipanat/Android.bp new file mode 100644 index 00000000..310304d6 --- /dev/null +++ b/data-ipa-cfg-mgr/ipanat/Android.bp @@ -0,0 +1,28 @@ + + +cc_library_shared { + name: "libipanat", + + header_libs: ["qti_kernel_headers"], + + srcs: [ + "src/ipa_nat_drv.c", + "src/ipa_nat_drvi.c", + ], + + shared_libs: + ["libcutils", + "libdl", + "libbase", + "libutils", + ], + export_include_dirs: ["inc"], + vendor: true, + cflags: [ + "-DDEBUG", + "-Wall", + "-Werror", + ] + ["-DFEATURE_IPA_ANDROID"], + + clang: true, +} diff --git a/data-ipa-cfg-mgr/ipanat/inc/ipa_nat_drvi.h b/data-ipa-cfg-mgr/ipanat/inc/ipa_nat_drvi.h index 3f6efc67..292a47b9 100644 --- a/data-ipa-cfg-mgr/ipanat/inc/ipa_nat_drvi.h +++ b/data-ipa-cfg-mgr/ipanat/inc/ipa_nat_drvi.h @@ -30,9 +30,9 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef IPA_NAT_DRVI_H #define IPA_NAT_DRVI_H -#include #include #include +#include #include #include #include @@ -40,12 +40,11 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include "ipa_nat_logi.h" -#ifdef DEBUG #define NAT_DUMP -#endif /*======= IMPLEMENTATION related data structures and functions ======= */ #ifdef IPA_ON_R3PC diff --git a/data-ipa-cfg-mgr/ipanat/src/Android.mk b/data-ipa-cfg-mgr/ipanat/src/Android.mk deleted file mode 100644 index fc7b7ea8..00000000 --- a/data-ipa-cfg-mgr/ipanat/src/Android.mk +++ /dev/null @@ -1,49 +0,0 @@ -BOARD_PLATFORM_LIST := msm8909 -BOARD_PLATFORM_LIST += msm8916 -BOARD_PLATFORM_LIST += msm8917 -ifeq ($(TARGET_BOARD_SUFFIX),_gvmq) -BOARD_PLATFORM_LIST += msmnile -endif -TARGET_DISABLE_IPANAT := false - -ifeq ($(TARGET_USES_QMAA),true) -ifneq ($(TARGET_USES_QMAA_OVERRIDE_DATA),true) - TARGET_DISABLE_IPANAT := true -endif #TARGET_USES_QMAA_OVERRIDE_DATA -endif #TARGET_USES_QMAA - -ifneq ($(TARGET_DISABLE_IPANAT),true) -ifneq ($(call is-board-platform-in-list,$(BOARD_PLATFORM_LIST)),true) -ifneq (,$(filter $(QCOM_BOARD_PLATFORMS),$(TARGET_BOARD_PLATFORM))) -ifneq (, $(filter aarch64 arm arm64, $(TARGET_ARCH))) - -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_C_INCLUDES := $(LOCAL_PATH)/../inc - -LOCAL_HEADER_LIBRARIES := generated_kernel_headers - -LOCAL_SRC_FILES := ipa_nat_drv.c \ - ipa_nat_drvi.c - -LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/../inc -LOCAL_VENDOR_MODULE := true -LOCAL_MODULE_PATH_64 := $(TARGET_OUT_VENDOR)/lib64 -LOCAL_MODULE_PATH_32 := $(TARGET_OUT_VENDOR)/lib -ifneq (,$(filter eng, $(TARGET_BUILD_VARIANT))) -LOCAL_CFLAGS := -DDEBUG -endif -LOCAL_CFLAGS += -Wall -Werror -LOCAL_CFLAGS += -DFEATURE_IPA_ANDROID -LOCAL_MODULE := libipanat -LOCAL_MODULE_TAGS := optional -LOCAL_PRELINK_MODULE := false -LOCAL_CLANG := true -include $(BUILD_SHARED_LIBRARY) - -endif # $(TARGET_ARCH) -endif -endif -endif diff --git a/data-ipa-cfg-mgr/ipanat/test/Android.mk b/data-ipa-cfg-mgr/ipanat/test/Android.mk index a6bb4b03..b8ae6a4b 100644 --- a/data-ipa-cfg-mgr/ipanat/test/Android.mk +++ b/data-ipa-cfg-mgr/ipanat/test/Android.mk @@ -10,7 +10,8 @@ include $(CLEAR_VARS) LOCAL_C_INCLUDES := $(LOCAL_PATH)/ LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../ipanat/inc -LOCAL_HEADER_LIBRARIES := generated_kernel_headers +LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include +LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr LOCAL_MODULE := ipa_nat_test LOCAL_SRC_FILES := ipa_nat_test000.c \ @@ -41,7 +42,7 @@ LOCAL_SRC_FILES := ipa_nat_test000.c \ LOCAL_SHARED_LIBRARIES := libipanat -LOCAL_MODULE_TAGS := tests +LOCAL_MODULE_TAGS := debug LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)/kernel-tests/ip_accelerator include $(BUILD_EXECUTABLE)