sdm660-common: Cleanup

* clean some duplicates,deprecated and not uses anymore
* build vendor.qti.hardware.btconfigstore@1.0 from source

Signed-off-by: clarencelol <clarencekuiek@icloud.com>
Signed-off-by: pix106 <sbordenave@gmail.com>
This commit is contained in:
clarencelol 2021-12-02 01:08:42 +08:00 committed by pix106
parent d64b0b54a9
commit b380d6f268
108 changed files with 4 additions and 48840 deletions

View file

@ -94,15 +94,9 @@ TARGET_USES_QTI_CAMERA2CLIENT := true
BOARD_QTI_CAMERA_32BIT_ONLY := true BOARD_QTI_CAMERA_32BIT_ONLY := true
TARGET_USES_MEDIA_EXTENSIONS := true TARGET_USES_MEDIA_EXTENSIONS := true
# Charger
HEALTHD_USE_BATTERY_INFO := true
# Clang # Clang
TARGET_KERNEL_CLANG_COMPILE := true TARGET_KERNEL_CLANG_COMPILE := true
# CNE and DPM
BOARD_USES_QCNE := true
# ConfigFS # ConfigFS
TARGET_FS_CONFIG_GEN := $(COMMON_PATH)/configs/config.fs TARGET_FS_CONFIG_GEN := $(COMMON_PATH)/configs/config.fs
@ -186,9 +180,6 @@ BOARD_ROOT_EXTRA_SYMLINKS := \
# Directory # Directory
TARGET_COPY_OUT_VENDOR := vendor TARGET_COPY_OUT_VENDOR := vendor
# Peripheral manager
TARGET_PER_MGR_ENABLED := true
# Properties # Properties
TARGET_ODM_PROP += $(COMMON_PATH)/properties/odm.prop TARGET_ODM_PROP += $(COMMON_PATH)/properties/odm.prop
TARGET_SYSTEM_EXT_PROP += $(COMMON_PATH)/properties/system_ext.prop TARGET_SYSTEM_EXT_PROP += $(COMMON_PATH)/properties/system_ext.prop
@ -221,12 +212,6 @@ SYSTEM_EXT_PRIVATE_SEPOLICY_DIRS += $(COMMON_PATH)/sepolicy/private
# SurfaceFlinger # SurfaceFlinger
TARGET_USE_AOSP_SURFACEFLINGER := true TARGET_USE_AOSP_SURFACEFLINGER := true
# Timeservice
BOARD_USES_QC_TIME_SERVICES := true
# USB
TARGET_QTI_USB_SUPPORTS_AUDIO_ACCESSORY := true
# VNDK # VNDK
BOARD_VNDK_VERSION := current BOARD_VNDK_VERSION := current

View file

@ -1,3 +0,0 @@
# List of MAC addresses that are allowed to authenticate (IEEE 802.11)
# with the AP. Optional VLAN ID can be assigned for clients based on the
# MAC address if dynamic VLANs (hostapd.conf dynamic_vlan option) are used.

File diff suppressed because it is too large Load diff

View file

@ -1,2 +0,0 @@
# List of MAC addresses that are not allowed to authenticate (IEEE 802.11)
# with the AP.

View file

@ -1,3 +0,0 @@
ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = foreign
SUBDIRS = ipanat/src ipacm/src/

View file

@ -1,58 +0,0 @@
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.65])
AC_INIT(data-ipa, 1.0.0)
AM_INIT_AUTOMAKE(data-ipa, 1.0.0)
AC_OUTPUT(Makefile ipanat/src/Makefile ipacm/src/Makefile)
AC_CONFIG_SRCDIR([ipanat/src/ipa_nat_drv.c])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
# Checks for programs.
AC_PROG_CC
AC_PROG_LIBTOOL
AC_PROG_CXX
PKG_CHECK_MODULES([LIBXML], [libxml-2.0])
AC_SUBST([LIBXML_CFLAGS])
AC_SUBST([LIBXML_LIBS])
# Checks for libraries.
AC_ARG_WITH(sanitized-headers,
AS_HELP_STRING([--with-sanitized-headers=DIR],
[Specify the location of the sanitized Linux headers]),
[CPPFLAGS="$CPPFLAGS -idirafter $withval"])
AM_CONDITIONAL(KERNELMODULES, [test -n -eq 0])
AC_ARG_WITH([glib],
AC_HELP_STRING([--with-glib],
[enable glib, building HLOS systems which use glib]))
if (test "x${with_glib}" = "xyes"); then
AC_DEFINE(ENABLE_USEGLIB, 1, [Define if HLOS systems uses glib])
PKG_CHECK_MODULES(GTHREAD, gthread-2.0 >= 2.16, dummy=yes,
AC_MSG_ERROR(GThread >= 2.16 is required))
PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.16, dummy=yes,
AC_MSG_ERROR(GLib >= 2.16 is required))
GLIB_CFLAGS="$GLIB_CFLAGS $GTHREAD_CFLAGS"
GLIB_LIBS="$GLIB_LIBS $GTHREAD_LIBS"
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)
fi
AM_CONDITIONAL(USE_GLIB, test "x${with_glib}" = "xyes")
# Checks for header files.
AC_CHECK_HEADERS([fcntl.h netinet/in.h sys/ioctl.h unistd.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_OFF_T
# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_MMAP
AC_CHECK_FUNCS([memset munmap])
AC_OUTPUT

View file

@ -1,25 +0,0 @@
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",
"libdl",
"libbase",
"libutils",
"libhardware_legacy",
"libhardware",
"android.hardware.tetheroffload.config@1.0",
"android.hardware.tetheroffload.control@1.0",
],
export_include_dirs: ["inc"],
vendor: true,
}

View file

@ -1,62 +0,0 @@
/*
* Copyright (c) 2017, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _CT_UPDATE_AMBASSADOR_H_
#define _CT_UPDATE_AMBASSADOR_H_
/* External Includes */
#include <hidl/HidlTransportSupport.h>
/* HIDL Includes */
#include <android/hardware/tetheroffload/control/1.0/ITetheringOffloadCallback.h>
/* Internal Includes */
#include "IOffloadManager.h"
/* Namespace pollution avoidance */
using ::android::hardware::tetheroffload::control::V1_0::ITetheringOffloadCallback;
using ::android::hardware::tetheroffload::control::V1_0::NetworkProtocol;
using HALIpAddrPortPair = ::android::hardware::tetheroffload::control::V1_0::IPv4AddrPortPair;
using HALNatTimeoutUpdate = ::android::hardware::tetheroffload::control::V1_0::NatTimeoutUpdate;
using IpaIpAddrPortPair = ::IOffloadManager::ConntrackTimeoutUpdater::IpAddrPortPair;
using IpaNatTimeoutUpdate = ::IOffloadManager::ConntrackTimeoutUpdater::NatTimeoutUpdate;
using IpaL4Protocol = ::IOffloadManager::ConntrackTimeoutUpdater::L4Protocol;
class CtUpdateAmbassador : public IOffloadManager::ConntrackTimeoutUpdater {
public:
CtUpdateAmbassador(const ::android::sp<ITetheringOffloadCallback>& /* cb */);
/* ------------------- CONNTRACK TIMEOUT UPDATER ------------------------ */
void updateTimeout(IpaNatTimeoutUpdate /* update */);
private:
static bool translate(IpaNatTimeoutUpdate /* in */, HALNatTimeoutUpdate& /* out */);
static bool translate(IpaIpAddrPortPair /* in */, HALIpAddrPortPair& /* out */);
static bool L4ToNetwork(IpaL4Protocol /* in */, NetworkProtocol& /* out */);
const ::android::sp<ITetheringOffloadCallback>& mFramework;
}; /* CtUpdateAmbassador */
#endif /* _CT_UPDATE_AMBASSADOR_H_ */

View file

@ -1,200 +0,0 @@
/*
* Copyright (c) 2017-2018, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _HAL_H_
#define _HAL_H_
/* HIDL Includes */
#include <android/hardware/tetheroffload/config/1.0/IOffloadConfig.h>
#include <android/hardware/tetheroffload/control/1.0/IOffloadControl.h>
#include <hidl/HidlTransportSupport.h>
/* External Includes */
#include <string>
#include <vector>
/* Internal Includes */
#include "CtUpdateAmbassador.h"
#include "IOffloadManager.h"
#include "IpaEventRelay.h"
#include "LocalLogBuffer.h"
/* Avoid the namespace litering everywhere */
using ::android::hardware::configureRpcThreadpool;
using ::android::hardware::joinRpcThreadpool;
using ::android::hardware::Return;
using ::android::hardware::hidl_handle;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using RET = ::IOffloadManager::RET;
using Prefix = ::IOffloadManager::Prefix;
using ::std::map;
using ::std::string;
using ::std::vector;
using ::android::hardware::tetheroffload::config::V1_0::IOffloadConfig;
using ::android::hardware::tetheroffload::control::V1_0::IOffloadControl;
using ::android::hardware::tetheroffload::control::V1_0::ITetheringOffloadCallback;
#define KERNEL_PAGE 4096
class HAL : public IOffloadControl, IOffloadConfig {
public:
/* Static Const Definitions */
static const uint32_t UDP_SUBSCRIPTIONS =
NF_NETLINK_CONNTRACK_NEW | NF_NETLINK_CONNTRACK_DESTROY;
static const uint32_t TCP_SUBSCRIPTIONS =
NF_NETLINK_CONNTRACK_UPDATE | NF_NETLINK_CONNTRACK_DESTROY;
/* Interface to IPACM */
/**
* @TODO This will likely need to be extended into a proper FactoryPattern
* when version bumps are needed.
*
* This makeIPAHAL function would move to a HALFactory class. Each HAL could
* then be versioned (class HAL_V1, class HAL_V2, etc) and inherit from a base class HAL.
* Then the version number in this function could be used to decide which one to return
* (if any).
*
* IPACM does not need to talk directly back to the returned HAL class. The other methods that
* IPACM needs to call are covered by registering the event listeners. If IPACM did need to
* talk directly back to the HAL object, without HAL registering a callback, these methods would
* need to be defined in the HAL base class.
*
* This would slightly break backwards compatibility so it should be discouraged; however, the
* base class could define a sane default implementation and not require that the child class
* implement this new method. This "sane default implementation" might only be possible in the
* case of listening to async events; if IPACM needs to query something, then this would not
* be backwards compatible and should be done via registering a callback so that IPACM knows
* this version of HAL supports that functionality.
*
* The above statements assume that only one version of the HAL will be instantiated at a time.
* Yet, it seems possible that a HAL_V1 and HAL_V2 service could both be registered, extending
* support to both old and new client implementations. It would be difficult to multiplex
* information from both versions. Additionally, IPACM would be responsible for instantiating
* two HALs (makeIPAHAL(1, ...); makeIPAHAL(2, ...)) which makes signaling between HAL versions
* (see next paragraph) slightly more difficult but not impossible.
*
* If concurrent versions of HAL are required, there will likely need to only be one master.
* Whichever version of HAL receives a client first may be allowed to take over control while
* other versions would be required to return failures (ETRYAGAIN: another version in use) until
* that version of the client relinquishes control. This should work seemlessly because we
* currently have an assumption that only one client will be present in system image.
* Logically, that client will have only a single version (or if it supports multiple, it will
* always attempt the newest version of HAL before falling back) and therefore no version
* collisions could possibly occur.
*
* Dislaimer:
* ==========
* Supporting multiple versions of an interface, in the same code base, at runtime, comes with a
* significant carrying cost and overhead in the form of developer headaches. This should not
* be done lightly and should be extensively scoped before committing to the effort.
*
* Perhaps the notion of minor version could be introduced to bridge the gaps created above.
* For example, 1.x and 1.y could be ran concurrently and supported from the same IPACM code.
* 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 Return<::android::sp<HAL>> makeIPAHAL(int /* version */, IOffloadManager* /* mgr */);
/* IOffloadConfig */
Return<void> setHandles(
const hidl_handle& /* fd1 */,
const hidl_handle& /* fd2 */,
setHandles_cb /* hidl_cb */);
/* IOffloadControl */
Return<void> initOffload(
const ::android::sp<ITetheringOffloadCallback>& /* cb */,
initOffload_cb /* hidl_cb */);
Return<void> stopOffload(
stopOffload_cb /* hidl_cb */);
Return<void> setLocalPrefixes(
const hidl_vec<hidl_string>& /* prefixes */,
setLocalPrefixes_cb /* hidl_cb */);
Return<void> getForwardedStats(
const hidl_string& /* upstream */,
getForwardedStats_cb /* hidl_cb */);
Return<void> setDataLimit(
const hidl_string& /* upstream */,
uint64_t /* limit */,
setDataLimit_cb /* hidl_cb */);
Return<void> setUpstreamParameters(
const hidl_string& /* iface */,
const hidl_string& /* v4Addr */,
const hidl_string& /* v4Gw */,
const hidl_vec<hidl_string>& /* v6Gws */,
setUpstreamParameters_cb /* hidl_cb */);
Return<void> addDownstream(
const hidl_string& /* iface */,
const hidl_string& /* prefix */,
addDownstream_cb /* hidl_cb */);
Return<void> removeDownstream(
const hidl_string& /* iface */,
const hidl_string& /* prefix */,
removeDownstream_cb /* hidl_cb */);
private:
typedef struct BoolResult {
bool success;
string errMsg;
} boolResult_t;
HAL(IOffloadManager* /* mgr */);
void registerAsSystemService(const char* /* name */);
void doLogcatDump();
static BoolResult makeInputCheckFailure(string /* customErr */);
static BoolResult ipaResultToBoolResult(RET /* in */);
static vector<string> convertHidlStrToStdStr(hidl_vec<hidl_string> /* in */);
void registerEventListeners();
void registerIpaCb();
void registerCtCb();
void unregisterEventListeners();
void unregisterIpaCb();
void unregisterCtCb();
void clearHandles();
bool isInitialized();
IOffloadManager* mIPA;
hidl_handle mHandle1;
hidl_handle mHandle2;
LocalLogBuffer mLogs;
::android::sp<ITetheringOffloadCallback> mCb;
IpaEventRelay *mCbIpa;
CtUpdateAmbassador *mCbCt;
}; /* HAL */
#endif /* _HAL_H_ */

View file

@ -1,350 +0,0 @@
/*
* Copyright (c) 2017, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _I_OFFLOAD_MANAGER_H_
#define _I_OFFLOAD_MANAGER_H_
/* External Includes */
#include <sys/types.h>
/* Internal Includes */
#include "OffloadStatistics.h"
class IOffloadManager {
public:
enum RET {
FAIL_TOO_MANY_PREFIXES = -6,
FAIL_UNSUPPORTED = -5,
FAIL_INPUT_CHECK = -4,
FAIL_HARDWARE = -3,
FAIL_UNNEEDED = -2,
FAIL_TRY_AGAIN = -1,
SUCCESS = 0,
SUCCESS_DUPLICATE_CONFIG = 1,
SUCCESS_NO_OP = 2,
SUCCESS_OPTIMIZED = 3
}; /* RET */
enum IP_FAM {
V4 = 0,
V6 = 1,
INVALID = 2
}; /* IP_FAM */
/* Overloading to use for addresses as well */
typedef struct Prefix {
IP_FAM fam;
uint32_t v4Addr;
uint32_t v4Mask;
uint32_t v6Addr[4];
uint32_t v6Mask[4];
} prefix_t;
/* ---------------------------- LIFECYCLE ------------------------------- */
virtual ~IOffloadManager(){}
/* ---------------------- ASYNC EVENT CALLBACKS ------------------------- */
class IpaEventListener {
public:
enum StoppedReason {
/**
* Offload was stopped due to the configuration being removed via
* setUpstreamParameters/removeDownstream.
*/
REQUESTED,
/**
* Offload was stopped due to an internal (to IPA or modem) error.
*
* Statistics may be temporarily unavailable.
*/
ERROR,
/**
* Offload was stopped because the upstream connection has
* migrated to unsupported radio access technology.
*
* Statistics will still be available.
*/
UNSUPPORTED
}; /* StoppedReason */
virtual ~IpaEventListener(){}
/**
* Called when Offload first begins to occur on any upstream and
* tether interface pair. It should be paired with an onOffloadStopped
* call.
*/
virtual void onOffloadStarted(){}
/**
* Called when Offload stops occurring on all upstream and tether
* interface pairs. It comes after a call to onOffloadStarted.
*
* @param reason Reason that Offload was stopped
*/
virtual void onOffloadStopped(StoppedReason /* reason */){}
/**
* Called when the hardware can support Offload again.
*
* Any statistics that were previously unavailable, may be queried
* again at this time.
*/
virtual void onOffloadSupportAvailable(){}
/**
* Called when the limit set via setQuota has expired.
*
* It is implied that Offload has been stopped on all upstream and
* tether interface pairs when this callback is called.
*/
virtual void onLimitReached(){}
}; /* IpaEventListener */
/**
* Request notifications about asynchronous events that occur in hardware.
*
* The calling client must be able to handle the callback on a separate
* thread (i.e. their implementation of IpaEventListener must be thread
* safe).
*
* @return SUCCESS iff callback successfully registered
*
* Remarks: This can't really be allowed to fail.
*/
virtual RET registerEventListener(IpaEventListener* /* listener */) = 0;
/**
* Unregister a previously registered listener.
*
* @return SUCCESS iff callback successfully unregistered
* FAIL_INPUT_CHECK if callback was never registered
*/
virtual RET unregisterEventListener(IpaEventListener* /* listener */) = 0;
class ConntrackTimeoutUpdater {
public:
enum L4Protocol {
TCP = 0,
UDP = 1
}; /* L4Protocol */
typedef struct IpAddrPortPair {
uint32_t ipAddr;
uint16_t port;
} ipAddrPortPair_t;
typedef struct NatTimeoutUpdate {
IpAddrPortPair src;
IpAddrPortPair dst;
L4Protocol proto;
} natTimeoutUpdate_t;
virtual ~ConntrackTimeoutUpdater(){}
virtual void updateTimeout(NatTimeoutUpdate /* update */) {}
}; /* ConntrackTimeoutUpdater */
/**
* Register a callback that may be called if the OffloadManager wants to
* update the timeout value in conntrack of kernel.
*
* The calling client must be able to handle the callback on a separate
* thread (i.e. their implementation of ConntrackTimeoutUpdater must be
* thread safe)
*
* @return SUCCESS iff callback successfully registered
*
* Remarks: This can't really be allowed to fail
*/
virtual RET registerCtTimeoutUpdater(ConntrackTimeoutUpdater* /* cb */) = 0;
/**
* Unregister a previously registered callback.
*
* @return SUCCESS iff callback successfully unregistered
* FAIL_INPUT_CHECK if callback was never registered
*/
virtual RET unregisterCtTimeoutUpdater(ConntrackTimeoutUpdater* /* cb */) = 0;
/* ----------------------------- CONFIG --------------------------------- */
/**
* Provide a file descriptor for use with conntrack library
*
* @param fd File Descriptor that has been opened and bound to groups
* @param groups Groups (bit mask) that fd has been bound to
*
* @return SUCCESS iff IOffloadManager needed this file descriptor and
* it was properly bound.
* FAIL_INPUT_CHECK if IOffloadManager needed this file descriptor
* but it was found to not be properly bound
* FAIL_UNNEEDED if IOffloadManager determined that it does not need
* a file descriptor bound to these groups.
*/
virtual RET provideFd(int /* fd */, unsigned int /* group */) = 0;
/**
* Indicate that IOffloadManager <b>must</b> cease using all file
* descriptors passed via provideFd API.
*
* After this call returns, the file descriptors will likely be closed by
* the calling client.
*
* @return SUCCESS iff IOffloadManager has stopped using all file
* descriptors
* FAIL_TRY_AGAIN if IOffloadManager needs more time with these
* file descriptors before it can release them
*
* Remarks: Currently, it would be very difficult to handle a FAIL_TRY_AGAIN
* because HAL serivce does not own a thread outside of RPC
* Threadpool to reschedule this call.
*/
virtual RET clearAllFds() = 0;
/**
* Query whether STA+AP offload is supported on this device.
*
* @return true if supported, false otherwise
*/
virtual bool isStaApSupported() = 0;
/* ------------------------------ ROUTE --------------------------------- */
/**
* Add a downstream prefix that <i>may</i> be forwarded.
*
* The Prefix may be an IPv4 or IPv6 address to signify which family can be
* offloaded from the specified tether interface. If the given IP family,
* as determined by the Prefix, has a corresponding upstream configured,
* then traffic should be forwarded between the two interfaces.
*
* Only traffic that has a downstream address within the specified Prefix
* can be forwarded. Traffic from the same downstream interface that falls
* outside of the Prefix will be unaffected and can be forwarded iff it was
* previously configured via a separate addDownstream call.
*
* If no upstream has been configured, then this information must be cached
* so that offload may begin once an upstream is configured.
*
* This API does <b>not</b> replace any previously configured downstreams
* and must be explicitly removed by calling removeDownstream or by clearing
* the entire configuration by calling stopAllOffload.
*
* @return SUCCESS The new information was accepted
* FAIL_TOO_MANY_PREFIXES The hardware has already accepted the max
* number of Prefixes that can be supported.
* If offload is desired on this Prefix then
* another must be removed first.
* FAIL_UNSUPPORTED The hardware cannot forward traffic from this
* downstream interface and will never be able to.
*/
virtual RET addDownstream(const char* /* downstream */,
const Prefix& /* prefix */) = 0;
/**
* Remove a downstream Prefix that forwarding was previously requested for.
*
* The Prefix may be an IPv4 or IPv6 address. Traffic outside of this
* Prefix is not affected.
*
* @return SUCCESS iff forwarding was previously occurring and has been
* stopped
* SUCCESS_NO_OP iff forwarding was not previously occurring and
* therefore no action needed to be taken
*/
virtual RET removeDownstream(const char* /* downstream */,
const Prefix& /* prefix */) = 0;
/**
* Indicate that hardware should forward traffic from any configured
* downstreams to the specified upstream.
*
* When iface is non-null and non-empty and v4Gw is valid, then any
* currently configured or future configured IPv4 downstreams should be
* forwarded to this upstream interface.
*
* When iface is non-null and non-empty and v6Gw is valid, then any
* currently configured or future configured IPv6 downstreams should be
* forwarded to this upstream interface.
*
* @param iface Upstream interface name. Only one is needed because IPv4
* and IPv6 interface names are required to match.
* @param v4Gw The address of the IPv4 Gateway on the iface
* @param v6Gw The address of one of the IPv6 Gateways on the iface
*
* @return SUCCESS iff the specified configuration was applied
* SUCCESS_DUPLICATE_CONFIG if this configuration <i>exactly</i>
* matches a previously provided
* configuration. This means that no
* action has to be taken, but, the
* configuration was previously accepted
* and applied.
* FAIL_UNSUPPORTED if hardware cannot support forwarding to this
* upstream interface
*
* Remarks: This overrides any previously configured parameters
*/
virtual RET setUpstream(const char* /* iface */, const Prefix& /* v4Gw */,
const Prefix& /* v6Gw */) = 0;
/**
* All traffic must be returned to the software path and all configuration
* (including provided file descriptors) must be forgotten.
*
* @return SUCCESS If all offload was successfully stopped and provided
* file descriptors were released.
*
* Remarks: This can't really fail?
*/
virtual RET stopAllOffload() = 0;
/* --------------------------- STATS/POLICY ----------------------------- */
/**
* Instruct hardware to stop forwarding traffic and send a callback after
* limit bytes have been transferred in either direction on this upstream
* interface.
*
* @param upstream Upstream interface name that the limit should apply to
* @param limit Bytes limit that can occur before action should be taken
*
* @return SUCCESS If the limit was successfully applied
* SUCCESS_OPTIMIZED If the limit was sufficiently high to be
* interpreted as "no quota".
* FAIL_HARDWARE If the limit was rejected by the hardware
* FAIL_UNSUPPORTED If metering is not supported on this interface
* FAIL_TRY_AGAIN If this upstream has not been previously
* configured to allow offload
* (via setUpstreamParameters)
*/
virtual RET setQuota(const char* /* upstream */, uint64_t /* limit */) = 0;
/**
* Query for statistics counters in hardware.
*
* This returns an aggregate of all hardware accelerated traffic which
* has occurred on this upstream interface.
*
* @param upstream Interface on which traffic entered/exited
* @param reset Whether hardware counters should reset after returning
* current statistics
* @param ret Output variable where statistics are returned
*
* @return SUCCESS If the statistics were successfully populated in ret and
* were successfully reset if requested.
* FAIL_TRY_AGAIN If the statistics are not currently available but
* may be available later. This may occur during
* a subsystem restart.
* FAIL_UNSUPPORTED If statistics are not supported on this upstream
*/
virtual RET getStats(const char* /* upstream */, bool /* reset */,
OffloadStatistics& /* ret */) = 0;
}; /* IOffloadManager */
#endif /* _I_OFFLOAD_MANAGER_H_ */

View file

@ -1,55 +0,0 @@
/*
* Copyright (c) 2017, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _IPA_EVENT_RELAY_H_
#define _IPA_EVENT_RELAY_H_
/* External Includes */
#include <hidl/HidlTransportSupport.h>
/* HIDL Includes */
#include <android/hardware/tetheroffload/control/1.0/ITetheringOffloadCallback.h>
/* Internal Includes */
#include "IOffloadManager.h"
/* Namespace pollution avoidance */
using ::android::hardware::tetheroffload::control::V1_0::ITetheringOffloadCallback;
class IpaEventRelay : public IOffloadManager::IpaEventListener {
public:
IpaEventRelay(const ::android::sp<ITetheringOffloadCallback>& /* cb */);
/* ----------------------- IPA EVENT LISTENER --------------------------- */
void onOffloadStarted();
void onOffloadStopped(StoppedReason /* reason */);
void onOffloadSupportAvailable();
void onLimitReached();
private:
const ::android::sp<ITetheringOffloadCallback>& mFramework;
}; /* IpaEventRelay */
#endif /* _IPA_EVENT_RELAY_H_ */

View file

@ -1,73 +0,0 @@
/*
* Copyright (c) 2017, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOCAL_LOG_BUFFER_H_
#define _LOCAL_LOG_BUFFER_H_
/* External Includes */
#include <deque>
#include <sstream>
#include <string>
#include <sys/types.h>
#include <vector>
/* Namespace pollution avoidance */
using ::std::deque;
using ::std::string;
using ::std::stringstream;
using ::std::vector;
class LocalLogBuffer {
public:
class FunctionLog {
public:
FunctionLog(string /* funcName */);
FunctionLog(const FunctionLog& /* other */);
void addArg(string /* kw */, string /* arg */);
void addArg(string /* kw */, vector<string> /* args */);
void addArg(string /* kw */, uint64_t /* arg */);
void setResult(bool /* success */, string /* msg */);
void setResult(vector<unsigned int> /* ret */);
void setResult(uint64_t /* rx */, uint64_t /* tx */);
string toString();
private:
void maybeAddArgsComma();
const string mName;
bool mArgsProvided;
stringstream mSSArgs;
stringstream mSSReturn;
}; /* FunctionLog */
LocalLogBuffer(string /* name */, int /* maxLogs */);
void addLog(FunctionLog /* log */);
void toLogcat();
private:
deque<FunctionLog> mLogs;
const string mName;
const size_t mMaxLogs;
}; /* LocalLogBuffer */
#endif /* _LOCAL_LOG_BUFFER_H_ */

View file

@ -1,49 +0,0 @@
/*
* Copyright (c) 2017, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _OFFLOAD_STATISTICS_H_
#define _OFFLOAD_STATISTICS_H_
#include <string>
#include <sys/types.h>
class OffloadStatistics {
public:
uint64_t rx;
uint64_t tx;
OffloadStatistics();
OffloadStatistics(std::string /* upstream */);
uint64_t getTotalRxBytes();
uint64_t getTotalTxBytes();
private:
std::string upstream;
}; /* OffloadStatistics */
#endif /* _OFFLOAD_STATISTICS_H_ */

View file

@ -1,80 +0,0 @@
/*
* Copyright (c) 2017, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _PREFIX_PARSER_H_
#define _PREFIX_PARSER_H_
/* External Includes */
#include <string.h>
#include <sys/types.h>
#include <vector>
/* Internal Includes */
#include "IOffloadManager.h"
/* Avoiding namespace pollution */
using IP_FAM = ::IOffloadManager::IP_FAM;
using Prefix = ::IOffloadManager::Prefix;
using ::std::string;
using ::std::vector;
class PrefixParser {
public:
PrefixParser();
bool add(vector<string> /* in */);
bool add(string /* in */);
bool addV4(vector<string> /* in */);
bool addV4(string /* in */);
bool addV6(vector<string> /* in */);
bool addV6(string /* in */);
int size();
bool allAreFullyQualified();
Prefix getFirstPrefix();
Prefix getFirstPrefix(IP_FAM);
string getLastErrAsStr();
private:
bool add(string /* in */, IP_FAM /* famHint */);
bool add(vector<string> /* in */, IP_FAM /* famHint */);
static IP_FAM guessIPFamily(string /* in */);
static bool splitIntoAddrAndMask(string /* in */, string& /* addr */,
string& /* mask */);
static int parseSubnetMask(string /* in */, IP_FAM /* famHint */);
static bool parseV4Addr(string /* in */, Prefix& /* out */);
static bool parseV6Addr(string /* in */, Prefix& /* out */);
static bool populateV4Mask(int /* mask */, Prefix& /* out */);
static bool populateV6Mask(int /* mask */, Prefix& /* out */);
static uint32_t createMask(int /* mask */);
static Prefix makeBlankPrefix(IP_FAM /* famHint */);
bool isMaskValid(int /* mask */, IP_FAM /* fam */);
static const uint32_t FULLY_QUALIFIED_MASK = ~0;
vector<Prefix> mPrefixes;
string mLastErr;
}; /* PrefixParser */
#endif /* _PREFIX_PARSER_H_ */

View file

@ -1,126 +0,0 @@
/*
* Copyright (c) 2017, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef DBG
#define DBG false
#endif /* DBG */
#define LOG_TAG "IPAHALService/CtUpdateAmbassador"
/* External Includes */
#include <arpa/inet.h>
#include <log/log.h>
/* HIDL Includes */
#include <android/hardware/tetheroffload/control/1.0/ITetheringOffloadCallback.h>
/* Internal Includes */
#include "CtUpdateAmbassador.h"
/* Namespace pollution avoidance */
using ::android::hardware::tetheroffload::control::V1_0::ITetheringOffloadCallback;
using ::android::hardware::tetheroffload::control::V1_0::NetworkProtocol;
using HALIpAddrPortPair = ::android::hardware::tetheroffload::control::V1_0::IPv4AddrPortPair;
using HALNatTimeoutUpdate = ::android::hardware::tetheroffload::control::V1_0::NatTimeoutUpdate;
using IpaIpAddrPortPair = ::IOffloadManager::ConntrackTimeoutUpdater::IpAddrPortPair;
using IpaNatTimeoutUpdate = ::IOffloadManager::ConntrackTimeoutUpdater::NatTimeoutUpdate;
using IpaL4Protocol = ::IOffloadManager::ConntrackTimeoutUpdater::L4Protocol;
CtUpdateAmbassador::CtUpdateAmbassador(
const ::android::sp<ITetheringOffloadCallback>& cb) : mFramework(cb) {
} /* CtUpdateAmbassador */
void CtUpdateAmbassador::updateTimeout(IpaNatTimeoutUpdate in) {
if (DBG) {
ALOGD("updateTimeout(src={%#010X, %#04X}, dest={%#010X, %#04X}, Proto=%d)",
in.src.ipAddr, in.src.port, in.dst.ipAddr, in.dst.port,
in.proto);
}
HALNatTimeoutUpdate out;
if (!translate(in, out)) {
/* Cannot log the input outside of DBG flag because it contains sensitive
* information. This will lead to a two step debug if the information
* cannot be gleaned from IPACM logs. The other option is to improve this
* with the use of our local log. That would likely still be hard to
* instruct testers to collect logs, because, assuming timeout updates
* are numerous, it will overrun the ring quickly. Therefore, the tester
* would have to know the exact moment as issue occurred. Or we make the
* ring massive. This would lead to a significant memory overhead.
* Because of this overhead, we would likely not want to check in a change
* with it and once we provide a debug build for increasing buffer size,
* why not just define the DBG flag?
*/
ALOGE("Failed to translate timeout event :(");
} else {
auto ret = mFramework->updateTimeout(out);
if (!ret.isOk()) {
ALOGE("Triggering updateTimeout Callback failed.");
}
}
} /* updateTimeout */
bool CtUpdateAmbassador::translate(IpaNatTimeoutUpdate in, HALNatTimeoutUpdate &out) {
return translate(in.src, out.src)
&& translate(in.dst, out.dst)
&& L4ToNetwork(in.proto, out.proto);
} /* translate */
bool CtUpdateAmbassador::translate(IpaIpAddrPortPair in, HALIpAddrPortPair& out) {
char ipAddrStr[INET_ADDRSTRLEN];
if (inet_ntop(AF_INET, &(in.ipAddr), ipAddrStr, INET_ADDRSTRLEN) == nullptr) {
/* errno would be valid here with EAFNOSUPPORT or ENOSPC, neither should really
* be possible in our scenario though.
*/
return false;
}
out.addr = ipAddrStr;
out.port = in.port;
return true;
} /* translate */
bool CtUpdateAmbassador::L4ToNetwork(IpaL4Protocol in, NetworkProtocol &out) {
bool ret = false;
switch(in) {
case IpaL4Protocol::TCP:
ret = true;
out = NetworkProtocol::TCP;
break;
case IpaL4Protocol::UDP:
ret = true;
out = NetworkProtocol::UDP;
break;
default:
ret = false;
break;
}
return ret;
} /* L4ToNetwork */

View file

@ -1,617 +0,0 @@
/*
* Copyright (c) 2017, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef DBG
#define DBG true
#endif /* DBG */
#define LOG_TAG "IPAHALService"
/* HIDL Includes */
#include <hwbinder/IPCThreadState.h>
#include <hwbinder/ProcessState.h>
/* Kernel Includes */
#include <linux/netfilter/nfnetlink_compat.h>
/* External Includes */
#include <log/log.h>
#include <cstring>
#include <sys/socket.h>
#include <sys/types.h>
#include <vector>
/* Internal Includes */
#include "HAL.h"
#include "LocalLogBuffer.h"
#include "PrefixParser.h"
/* Namespace pollution avoidance */
using ::android::hardware::Void;
using ::android::status_t;
using RET = ::IOffloadManager::RET;
using Prefix = ::IOffloadManager::Prefix;
using ::std::map;
using ::std::vector;
/* ------------------------------ PUBLIC ------------------------------------ */
Return<::android::sp<HAL>> HAL::makeIPAHAL(int version, IOffloadManager* mgr) {
android::hardware::ProcessState::initWithMmapSize((size_t)(2 * KERNEL_PAGE));
if (DBG)
ALOGI("makeIPAHAL(%d, %s)", version,
(mgr != nullptr) ? "provided" : "null");
if (nullptr == mgr) return NULL;
else if (version != 1) return NULL;
::android::sp<HAL> ret = new HAL(mgr);
if (nullptr == ret) return NULL;
configureRpcThreadpool(1, false);
ret->registerAsSystemService("ipacm");
return ret;
} /* makeIPAHAL */
/* ------------------------------ PRIVATE ----------------------------------- */
HAL::HAL(IOffloadManager* mgr) : mLogs("HAL Function Calls", 50) {
mIPA = mgr;
mCb.clear();
mCbIpa = nullptr;
mCbCt = nullptr;
} /* HAL */
void HAL::registerAsSystemService(const char* name) {
status_t ret = 0;
ret = IOffloadControl::registerAsService();
if (ret != 0) ALOGE("Failed to register IOffloadControl (%d) name(%s)", ret, name);
else if (DBG) {
ALOGI("Successfully registered IOffloadControl");
}
ret = IOffloadConfig::registerAsService();
if (ret != 0) ALOGE("Failed to register IOffloadConfig (%d)", ret);
else if (DBG) {
ALOGI("Successfully registered IOffloadConfig");
}
} /* registerAsSystemService */
void HAL::doLogcatDump() {
ALOGD("mHandles");
ALOGD("========");
/* @TODO This will segfault if they aren't initialized and I don't currently
* care to check for initialization in a function that isn't used anyways
* ALOGD("fd1->%d", mHandle1->data[0]);
* ALOGD("fd2->%d", mHandle2->data[0]);
*/
ALOGD("========");
} /* doLogcatDump */
HAL::BoolResult HAL::makeInputCheckFailure(string customErr) {
BoolResult ret;
ret.success = false;
ret.errMsg = "Failed Input Checks: " + customErr;
return ret;
} /* makeInputCheckFailure */
HAL::BoolResult HAL::ipaResultToBoolResult(RET in) {
BoolResult ret;
ret.success = (in >= RET::SUCCESS);
switch (in) {
case RET::FAIL_TOO_MANY_PREFIXES:
ret.errMsg = "Too Many Prefixes Provided";
break;
case RET::FAIL_UNSUPPORTED:
ret.errMsg = "Unsupported by Hardware";
break;
case RET::FAIL_INPUT_CHECK:
ret.errMsg = "Failed Input Checks";
break;
case RET::FAIL_HARDWARE:
ret.errMsg = "Hardware did not accept";
break;
case RET::FAIL_TRY_AGAIN:
ret.errMsg = "Try Again";
break;
case RET::SUCCESS:
ret.errMsg = "Successful";
break;
case RET::SUCCESS_DUPLICATE_CONFIG:
ret.errMsg = "Successful: Was a duplicate configuration";
break;
case RET::SUCCESS_NO_OP:
ret.errMsg = "Successful: No action needed";
break;
case RET::SUCCESS_OPTIMIZED:
ret.errMsg = "Successful: Performed optimized version of action";
break;
default:
ret.errMsg = "Unknown Error";
break;
}
return ret;
} /* ipaResultToBoolResult */
/* This will likely always result in doubling the number of loops the execution
* goes through. Obviously that is suboptimal. But if we first translate
* away from all HIDL specific code, then we can avoid sprinkling HIDL
* dependencies everywhere.
*/
vector<string> HAL::convertHidlStrToStdStr(hidl_vec<hidl_string> in) {
vector<string> ret;
for (size_t i = 0; i < in.size(); i++) {
string add = in[i];
ret.push_back(add);
}
return ret;
} /* convertHidlStrToStdStr */
void HAL::registerEventListeners() {
registerIpaCb();
registerCtCb();
} /* registerEventListeners */
void HAL::registerIpaCb() {
if (isInitialized() && mCbIpa == nullptr) {
LocalLogBuffer::FunctionLog fl("registerEventListener");
mCbIpa = new IpaEventRelay(mCb);
mIPA->registerEventListener(mCbIpa);
mLogs.addLog(fl);
} else {
ALOGE("Failed to registerIpaCb (isInitialized()=%s, (mCbIpa == nullptr)=%s)",
isInitialized() ? "true" : "false",
(mCbIpa == nullptr) ? "true" : "false");
}
} /* registerIpaCb */
void HAL::registerCtCb() {
if (isInitialized() && mCbCt == nullptr) {
LocalLogBuffer::FunctionLog fl("registerCtTimeoutUpdater");
mCbCt = new CtUpdateAmbassador(mCb);
mIPA->registerCtTimeoutUpdater(mCbCt);
mLogs.addLog(fl);
} else {
ALOGE("Failed to registerCtCb (isInitialized()=%s, (mCbCt == nullptr)=%s)",
isInitialized() ? "true" : "false",
(mCbCt == nullptr) ? "true" : "false");
}
} /* registerCtCb */
void HAL::unregisterEventListeners() {
unregisterIpaCb();
unregisterCtCb();
} /* unregisterEventListeners */
void HAL::unregisterIpaCb() {
if (mCbIpa != nullptr) {
LocalLogBuffer::FunctionLog fl("unregisterEventListener");
mIPA->unregisterEventListener(mCbIpa);
mCbIpa = nullptr;
mLogs.addLog(fl);
} else {
ALOGE("Failed to unregisterIpaCb");
}
} /* unregisterIpaCb */
void HAL::unregisterCtCb() {
if (mCbCt != nullptr) {
LocalLogBuffer::FunctionLog fl("unregisterCtTimeoutUpdater");
mIPA->unregisterCtTimeoutUpdater(mCbCt);
mCbCt = nullptr;
mLogs.addLog(fl);
} else {
ALOGE("Failed to unregisterCtCb");
}
} /* unregisterCtCb */
void HAL::clearHandles() {
ALOGI("clearHandles()");
/* @TODO handle this more gracefully... also remove the log
*
* Things that would be nice, but I can't do:
* [1] Destroy the object (it's on the stack)
* [2] Call freeHandle (it's private)
*
* Things I can do but are hacks:
* [1] Look at code and notice that setTo immediately calls freeHandle
*/
mHandle1.setTo(nullptr, true);
mHandle2.setTo(nullptr, true);
} /* clearHandles */
bool HAL::isInitialized() {
return mCb.get() != nullptr;
} /* isInitialized */
/* -------------------------- IOffloadConfig -------------------------------- */
Return<void> HAL::setHandles(
const hidl_handle &fd1,
const hidl_handle &fd2,
setHandles_cb hidl_cb
) {
LocalLogBuffer::FunctionLog fl(__func__);
if (fd1->numFds != 1) {
BoolResult res = makeInputCheckFailure("Must provide exactly one FD per handle (fd1)");
hidl_cb(res.success, res.errMsg);
fl.setResult(res.success, res.errMsg);
mLogs.addLog(fl);
return Void();
}
if (fd2->numFds != 1) {
BoolResult res = makeInputCheckFailure("Must provide exactly one FD per handle (fd2)");
hidl_cb(res.success, res.errMsg);
fl.setResult(res.success, res.errMsg);
mLogs.addLog(fl);
return Void();
}
/* The = operator calls freeHandle internally. Therefore, if we were using
* these handles previously, they're now gone... forever. But hopefully the
* new ones kick in very quickly.
*
* After freeing anything previously held, it will dup the FD so we have our
* own copy.
*/
mHandle1 = fd1;
mHandle2 = fd2;
/* Log the DUPed FD instead of the actual input FD so that we can lookup
* this value in ls -l /proc/<pid>/<fd>
*/
fl.addArg("fd1", mHandle1->data[0]);
fl.addArg("fd2", mHandle2->data[0]);
/* Try to provide each handle to IPACM. Destroy our DUPed hidl_handles if
* IPACM does not like either input. This keeps us from leaking FDs or
* providing half solutions.
*
* @TODO unfortunately, this does not cover duplicate configs where IPACM
* thinks it is still holding on to a handle that we would have freed above.
* It also probably means that IPACM would not know about the first FD being
* freed if it rejects the second FD.
*/
RET ipaReturn = mIPA->provideFd(mHandle1->data[0], UDP_SUBSCRIPTIONS);
if (ipaReturn == RET::SUCCESS) {
ipaReturn = mIPA->provideFd(mHandle2->data[0], TCP_SUBSCRIPTIONS);
}
if (ipaReturn != RET::SUCCESS) {
ALOGE("IPACM failed to accept the FDs (%d %d)", mHandle1->data[0],
mHandle2->data[0]);
clearHandles();
} else {
/* @TODO remove logs after stabilization */
ALOGI("IPACM was provided two FDs (%d, %d)", mHandle1->data[0],
mHandle2->data[0]);
}
BoolResult res = ipaResultToBoolResult(ipaReturn);
hidl_cb(res.success, res.errMsg);
fl.setResult(res.success, res.errMsg);
mLogs.addLog(fl);
return Void();
} /* setHandles */
/* -------------------------- IOffloadControl ------------------------------- */
Return<void> HAL::initOffload
(
const ::android::sp<ITetheringOffloadCallback>& cb,
initOffload_cb hidl_cb
) {
LocalLogBuffer::FunctionLog fl(__func__);
if (isInitialized()) {
BoolResult res = makeInputCheckFailure("Already initialized");
hidl_cb(res.success, res.errMsg);
fl.setResult(res.success, res.errMsg);
mLogs.addLog(fl);
} else {
/* Should storing the CB be a function? */
mCb = cb;
registerEventListeners();
BoolResult res = ipaResultToBoolResult(RET::SUCCESS);
hidl_cb(res.success, res.errMsg);
fl.setResult(res.success, res.errMsg);
mLogs.addLog(fl);
}
return Void();
} /* initOffload */
Return<void> HAL::stopOffload
(
stopOffload_cb hidl_cb
) {
LocalLogBuffer::FunctionLog fl(__func__);
if (!isInitialized()) {
BoolResult res = makeInputCheckFailure("Was never initialized");
hidl_cb(res.success, res.errMsg);
fl.setResult(res.success, res.errMsg);
mLogs.addLog(fl);
} else {
/* Should removing the CB be a function? */
mCb.clear();
unregisterEventListeners();
RET ipaReturn = mIPA->stopAllOffload();
if (ipaReturn != RET::SUCCESS) {
/* Ignore IPAs return value here and provide why stopAllOffload
* failed. However, if IPA failed to clearAllFds, then we can't
* clear our map because they may still be in use.
*/
RET ret = mIPA->clearAllFds();
if (ret == RET::SUCCESS) {
clearHandles();
}
} else {
ipaReturn = mIPA->clearAllFds();
/* If IPA fails, they may still be using these for some reason. */
if (ipaReturn == RET::SUCCESS) {
clearHandles();
} else {
ALOGE("IPACM failed to return success for clearAllFds so they will not be released...");
}
}
BoolResult res = ipaResultToBoolResult(ipaReturn);
hidl_cb(res.success, res.errMsg);
fl.setResult(res.success, res.errMsg);
mLogs.addLog(fl);
}
return Void();
} /* stopOffload */
Return<void> HAL::setLocalPrefixes
(
const hidl_vec<hidl_string>& prefixes,
setLocalPrefixes_cb hidl_cb
) {
BoolResult res;
PrefixParser parser;
vector<string> prefixesStr = convertHidlStrToStdStr(prefixes);
LocalLogBuffer::FunctionLog fl(__func__);
fl.addArg("prefixes", prefixesStr);
memset(&res,0,sizeof(BoolResult));
if (!isInitialized()) {
BoolResult res = makeInputCheckFailure("Not initialized");
} else if(prefixesStr.size() < 1) {
res = ipaResultToBoolResult(RET::FAIL_INPUT_CHECK);
} else if (!parser.add(prefixesStr)) {
res = makeInputCheckFailure(parser.getLastErrAsStr());
} else {
res = ipaResultToBoolResult(RET::SUCCESS);
}
hidl_cb(res.success, res.errMsg);
fl.setResult(res.success, res.errMsg);
mLogs.addLog(fl);
return Void();
} /* setLocalPrefixes */
Return<void> HAL::getForwardedStats
(
const hidl_string& upstream,
getForwardedStats_cb hidl_cb
) {
LocalLogBuffer::FunctionLog fl(__func__);
fl.addArg("upstream", upstream);
OffloadStatistics ret;
RET ipaReturn = mIPA->getStats(upstream.c_str(), true, ret);
if (ipaReturn == RET::SUCCESS) {
hidl_cb(ret.getTotalRxBytes(), ret.getTotalTxBytes());
fl.setResult(ret.getTotalRxBytes(), ret.getTotalTxBytes());
} else {
/* @TODO Ensure the output is zeroed, but this is probably not enough to
* tell Framework that an error has occurred. If, for example, they had
* not yet polled for statistics previously, they may incorrectly assume
* that simply no statistics have transpired on hardware path.
*
* Maybe ITetheringOffloadCallback:onEvent(OFFLOAD_STOPPED_ERROR) is
* enough to handle this case, time will tell.
*/
hidl_cb(0, 0);
fl.setResult(0, 0);
}
mLogs.addLog(fl);
return Void();
} /* getForwardedStats */
Return<void> HAL::setDataLimit
(
const hidl_string& upstream,
uint64_t limit,
setDataLimit_cb hidl_cb
) {
LocalLogBuffer::FunctionLog fl(__func__);
fl.addArg("upstream", upstream);
fl.addArg("limit", limit);
if (!isInitialized()) {
BoolResult res = makeInputCheckFailure("Not initialized (setDataLimit)");
hidl_cb(res.success, res.errMsg);
fl.setResult(res.success, res.errMsg);
} else {
RET ipaReturn = mIPA->setQuota(upstream.c_str(), limit);
if(ipaReturn == RET::FAIL_TRY_AGAIN) {
ipaReturn = RET::SUCCESS;
}
BoolResult res = ipaResultToBoolResult(ipaReturn);
hidl_cb(res.success, res.errMsg);
fl.setResult(res.success, res.errMsg);
}
mLogs.addLog(fl);
return Void();
} /* setDataLimit */
Return<void> HAL::setUpstreamParameters
(
const hidl_string& iface,
const hidl_string& v4Addr,
const hidl_string& v4Gw,
const hidl_vec<hidl_string>& v6Gws,
setUpstreamParameters_cb hidl_cb
) {
vector<string> v6GwStrs = convertHidlStrToStdStr(v6Gws);
LocalLogBuffer::FunctionLog fl(__func__);
fl.addArg("iface", iface);
fl.addArg("v4Addr", v4Addr);
fl.addArg("v4Gw", v4Gw);
fl.addArg("v6Gws", v6GwStrs);
PrefixParser v4AddrParser;
PrefixParser v4GwParser;
PrefixParser v6GwParser;
/* @TODO maybe we should enforce that these addresses and gateways are fully
* qualified here. But then, how do we allow them to be empty/null as well
* while still preserving a sane API on PrefixParser?
*/
if (!isInitialized()) {
BoolResult res = makeInputCheckFailure("Not initialized (setUpstreamParameters)");
hidl_cb(res.success, res.errMsg);
fl.setResult(res.success, res.errMsg);
} else if (!v4AddrParser.addV4(v4Addr) && !v4Addr.empty()) {
BoolResult res = makeInputCheckFailure(v4AddrParser.getLastErrAsStr());
hidl_cb(res.success, res.errMsg);
fl.setResult(res.success, res.errMsg);
} else if (!v4GwParser.addV4(v4Gw) && !v4Gw.empty()) {
BoolResult res = makeInputCheckFailure(v4GwParser.getLastErrAsStr());
hidl_cb(res.success, res.errMsg);
fl.setResult(res.success, res.errMsg);
} else if (v6GwStrs.size() >= 1 && !v6GwParser.addV6(v6GwStrs)) {
BoolResult res = makeInputCheckFailure(v6GwParser.getLastErrAsStr());
hidl_cb(res.success, res.errMsg);
fl.setResult(res.success, res.errMsg);
} else if (iface.size()>= 1) {
RET ipaReturn = mIPA->setUpstream(
iface.c_str(),
v4GwParser.getFirstPrefix(),
v6GwParser.getFirstPrefix());
BoolResult res = ipaResultToBoolResult(ipaReturn);
hidl_cb(res.success, res.errMsg);
fl.setResult(res.success, res.errMsg);
} else {
/* send NULL iface string when upstream down */
RET ipaReturn = mIPA->setUpstream(
NULL,
v4GwParser.getFirstPrefix(IP_FAM::V4),
v6GwParser.getFirstPrefix(IP_FAM::V6));
BoolResult res = ipaResultToBoolResult(ipaReturn);
hidl_cb(res.success, res.errMsg);
fl.setResult(res.success, res.errMsg);
}
mLogs.addLog(fl);
return Void();
} /* setUpstreamParameters */
Return<void> HAL::addDownstream
(
const hidl_string& iface,
const hidl_string& prefix,
addDownstream_cb hidl_cb
) {
LocalLogBuffer::FunctionLog fl(__func__);
fl.addArg("iface", iface);
fl.addArg("prefix", prefix);
PrefixParser prefixParser;
if (!isInitialized()) {
BoolResult res = makeInputCheckFailure("Not initialized (setUpstreamParameters)");
hidl_cb(res.success, res.errMsg);
fl.setResult(res.success, res.errMsg);
}
else if (!prefixParser.add(prefix)) {
BoolResult res = makeInputCheckFailure(prefixParser.getLastErrAsStr());
hidl_cb(res.success, res.errMsg);
fl.setResult(res.success, res.errMsg);
} else {
RET ipaReturn = mIPA->addDownstream(
iface.c_str(),
prefixParser.getFirstPrefix());
BoolResult res = ipaResultToBoolResult(ipaReturn);
hidl_cb(res.success, res.errMsg);
fl.setResult(res.success, res.errMsg);
}
mLogs.addLog(fl);
return Void();
} /* addDownstream */
Return<void> HAL::removeDownstream
(
const hidl_string& iface,
const hidl_string& prefix,
removeDownstream_cb hidl_cb
) {
LocalLogBuffer::FunctionLog fl(__func__);
fl.addArg("iface", iface);
fl.addArg("prefix", prefix);
PrefixParser prefixParser;
if (!isInitialized()) {
BoolResult res = makeInputCheckFailure("Not initialized (setUpstreamParameters)");
hidl_cb(res.success, res.errMsg);
fl.setResult(res.success, res.errMsg);
}
else if (!prefixParser.add(prefix)) {
BoolResult res = makeInputCheckFailure(prefixParser.getLastErrAsStr());
hidl_cb(res.success, res.errMsg);
fl.setResult(res.success, res.errMsg);
} else {
RET ipaReturn = mIPA->removeDownstream(
iface.c_str(),
prefixParser.getFirstPrefix());
BoolResult res = ipaResultToBoolResult(ipaReturn);
hidl_cb(res.success, res.errMsg);
fl.setResult(res.success, res.errMsg);
}
mLogs.addLog(fl);
return Void();
} /* removeDownstream */

View file

@ -1,96 +0,0 @@
/*
* Copyright (c) 2017, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define LOG_TAG "IPAHALService/IpaEventRelay"
/* External Includes */
#include <log/log.h>
/* HIDL Includes */
#include <android/hardware/tetheroffload/control/1.0/ITetheringOffloadCallback.h>
/* Internal Includes */
#include "IpaEventRelay.h"
/* Namespace pollution avoidance */
using ::android::hardware::tetheroffload::control::V1_0::ITetheringOffloadCallback;
using ::android::hardware::tetheroffload::control::V1_0::OffloadCallbackEvent;
IpaEventRelay::IpaEventRelay(
const ::android::sp<ITetheringOffloadCallback>& cb) : mFramework(cb) {
} /* IpaEventRelay */
void IpaEventRelay::onOffloadStarted() {
ALOGI("onOffloadStarted()");
auto ret = mFramework->onEvent(OffloadCallbackEvent::OFFLOAD_STARTED);
if (!ret.isOk()) {
ALOGE("Triggering OffloadStarted Callback failed.");
}
} /* onOffloadStarted */
void IpaEventRelay::onOffloadStopped(StoppedReason reason) {
ALOGI("onOffloadStopped(%d)", reason);
if( reason == StoppedReason::REQUESTED ) {
/*
* No way to communicate this to Framework right now, they make an
* assumption that offload is stopped when they remove the
* configuration.
*/
}
else if ( reason == StoppedReason::ERROR ) {
auto ret = mFramework->onEvent(OffloadCallbackEvent::OFFLOAD_STOPPED_ERROR);
if (!ret.isOk()) {
ALOGE("Triggering OffloadStopped Callback failed.");
}
}
else if ( reason == StoppedReason::UNSUPPORTED ) {
auto ret = mFramework->onEvent(OffloadCallbackEvent::OFFLOAD_STOPPED_UNSUPPORTED);
if (!ret.isOk()) {
ALOGE("Triggering OffloadStopped Callback failed.");
}
}
else {
ALOGE("Unknown stopped reason(%d)", reason);
}
} /* onOffloadStopped */
void IpaEventRelay::onOffloadSupportAvailable() {
ALOGI("onOffloadSupportAvailable()");
auto ret = mFramework->onEvent(OffloadCallbackEvent::OFFLOAD_SUPPORT_AVAILABLE);
if (!ret.isOk()) {
ALOGE("Triggering OffloadSupportAvailable Callback failed.");
}
} /* onOffloadSupportAvailable */
void IpaEventRelay::onLimitReached() {
ALOGI("onLimitReached()");
auto ret = mFramework->onEvent(OffloadCallbackEvent::OFFLOAD_STOPPED_LIMIT_REACHED);
if (!ret.isOk()) {
ALOGE("Triggering LimitReached Callback failed.");
}
} /* onLimitReached */

View file

@ -1,126 +0,0 @@
/*
* Copyright (c) 2017, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define LOG_TAG "IPAHALService/dump"
/* External Includes */
#include <log/log.h>
#include <deque>
#include <string>
#include <sys/types.h>
#include <vector>
/* Internal Includes */
#include "LocalLogBuffer.h"
/* Namespace pollution avoidance */
using ::std::deque;
using ::std::string;
using ::std::vector;
LocalLogBuffer::FunctionLog::FunctionLog(string funcName) : mName(funcName) {
mArgsProvided = false;
} /* FunctionLog */
LocalLogBuffer::FunctionLog::FunctionLog(const FunctionLog& other) :
mName(other.mName) {
mArgsProvided = other.mArgsProvided;
/* Is this right? How do you copy stringstreams without wizardry? */
mSSArgs.str(other.mSSArgs.str());
mSSReturn.str(other.mSSReturn.str());
} /* FunctionLog */
void LocalLogBuffer::FunctionLog::addArg(string kw, string arg) {
maybeAddArgsComma();
mSSArgs << kw << "=" << arg;
} /* addArg */
void LocalLogBuffer::FunctionLog::addArg(string kw, vector<string> args) {
maybeAddArgsComma();
mSSArgs << kw << "=[";
for (size_t i = 0; i < args.size(); i++) {
mSSArgs << args[i];
if (i < (args.size() - 1))
mSSArgs << ", ";
}
mSSArgs << "]";
} /* addArg */
void LocalLogBuffer::FunctionLog::addArg(string kw, uint64_t arg) {
maybeAddArgsComma();
mSSArgs << kw << "=" << arg;
} /* addArg */
void LocalLogBuffer::FunctionLog::maybeAddArgsComma() {
if (!mArgsProvided) {
mArgsProvided = true;
} else {
mSSArgs << ", ";
}
} /* maybeAddArgsComma */
void LocalLogBuffer::FunctionLog::setResult(bool success, string msg) {
mSSReturn << "[" << ((success) ? "success" : "failure") << ", " << msg
<< "]";
} /* setResult */
void LocalLogBuffer::FunctionLog::setResult(vector<unsigned int> ret) {
mSSReturn << "[";
for (size_t i = 0; i < ret.size(); i++) {
mSSReturn << ret[i];
if (i < (ret.size() - 1))
mSSReturn << ", ";
}
mSSReturn << "]";
} /* setResult */
void LocalLogBuffer::FunctionLog::setResult(uint64_t rx, uint64_t tx) {
mSSReturn << "[rx=" << rx << ", tx=" << tx << "]";
} /* setResult */
string LocalLogBuffer::FunctionLog::toString() {
stringstream ret;
ret << mName << "(" << mSSArgs.str() << ") returned " << mSSReturn.str();
return ret.str();
} /* toString */
LocalLogBuffer::LocalLogBuffer(string name, int maxLogs) : mName(name),
mMaxLogs(maxLogs) {
} /* LocalLogBuffer */
void LocalLogBuffer::addLog(FunctionLog log) {
while (mLogs.size() > mMaxLogs)
mLogs.pop_front();
mLogs.push_back(log);
} /* addLog */
void LocalLogBuffer::toLogcat() {
for (size_t i = 0; i < mLogs.size(); i++)
ALOGD("%s: %s", mName.c_str(), mLogs[i].toString().c_str());
} /* toLogcat */

View file

@ -1,57 +0,0 @@
/*
* Copyright (c) 2017, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include <sys/types.h>
#include "OffloadStatistics.h"
/* ------------------------------ PUBLIC ------------------------------------ */
OffloadStatistics::OffloadStatistics() {
this->upstream = "UNSET";
this->rx = 0;
this->tx = 0;
} /* OffloadStatistics */
OffloadStatistics::OffloadStatistics
(
std::string upstream
) {
this->upstream = upstream;
this->rx = 0;
this->tx =0;
} /* OffloadStatistics */
uint64_t OffloadStatistics::getTotalRxBytes() {
return rx;
} /* getTotalRxBytes */
uint64_t OffloadStatistics::getTotalTxBytes() {
return tx;
} /* getTotalTxBytes */

View file

@ -1,391 +0,0 @@
/*
* Copyright (c) 2017, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* External Includes */
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <vector>
/* Internal Includes */
#include "IOffloadManager.h"
#include "PrefixParser.h"
/* Avoiding namespace pollution */
using IP_FAM = ::IOffloadManager::IP_FAM;
using Prefix = ::IOffloadManager::Prefix;
using ::std::string;
using ::std::vector;
/* ------------------------------ PUBLIC ------------------------------------ */
PrefixParser::PrefixParser() {
mLastErr = "No Err";
} /* PrefixParser */
bool PrefixParser::add(vector<string> in) {
return add(in, IP_FAM::INVALID);
} /* add */
bool PrefixParser::add(string in) {
return add(in, IP_FAM::INVALID);
} /* add */
bool PrefixParser::addV4(string in) {
return add(in, IP_FAM::V4);
} /* addV4 */
bool PrefixParser::addV4(vector<string> in) {
return add(in, IP_FAM::V4);
} /* addV4 */
bool PrefixParser::addV6(string in) {
return add(in, IP_FAM::V6);
} /* addV6 */
bool PrefixParser::addV6(vector<string> in) {
for (size_t i = 0; i < in.size(); i++) {
if (!addV6(in[i]))
return false;
}
return true;
} /* addV6 */
int PrefixParser::size() {
return mPrefixes.size();
} /* size */
bool PrefixParser::allAreFullyQualified() {
for (size_t i = 0; i < mPrefixes.size(); i++) {
if (mPrefixes[i].fam == IP_FAM::V4) {
uint32_t masked = mPrefixes[i].v4Addr & mPrefixes[i].v4Mask;
if (masked != mPrefixes[i].v4Addr)
return false;
} else {
uint32_t masked[4];
masked[0] = mPrefixes[i].v6Addr[0] & mPrefixes[i].v6Mask[0];
masked[1] = mPrefixes[i].v6Addr[1] & mPrefixes[i].v6Mask[1];
masked[2] = mPrefixes[i].v6Addr[2] & mPrefixes[i].v6Mask[2];
masked[3] = mPrefixes[i].v6Addr[3] & mPrefixes[i].v6Mask[3];
for (int j = 0; j < 4; j++) {
if (masked[j] != mPrefixes[i].v6Addr[j])
return false;
}
}
}
return true;
} /* allAreFullyQualified */
Prefix PrefixParser::getFirstPrefix() {
if (size() >= 1)
return mPrefixes[0];
return makeBlankPrefix(IP_FAM::INVALID);
} /* getFirstPrefix */
Prefix PrefixParser::getFirstPrefix(IP_FAM famHint) {
if (size() >= 1)
return mPrefixes[0];
return makeBlankPrefix(famHint);
} /* getFirstPrefix */
string PrefixParser::getLastErrAsStr() {
return mLastErr;
} /* getLastErrAsStr */
/* ------------------------------ PRIVATE ----------------------------------- */
bool PrefixParser::add(vector<string> in, IP_FAM famHint) {
if (in.size() == 0)
return false;
for (size_t i = 0; i < in.size(); i++) {
if (!add(in[i], famHint))
return false;
}
return true;
} /* add */
bool PrefixParser::add(string in, IP_FAM famHint) {
if (in.length() == 0) {
mLastErr = "Failed to parse string, length = 0...";
return false;
}
if (famHint == IP_FAM::INVALID)
famHint = guessIPFamily(in);
string subnet;
string addr;
if (!splitIntoAddrAndMask(in, addr, subnet)) {
mLastErr = "Failed to split into Address and Mask(" + in + ")";
return false;
}
int mask = parseSubnetMask(subnet, famHint);
if (!isMaskValid(mask, famHint)) {
mLastErr = "Invalid mask";
return false;
}
Prefix pre = makeBlankPrefix(famHint);
if (famHint == IP_FAM::V4) {
if (!parseV4Addr(addr, pre)) {
mLastErr = "Failed to parse V4 Address(" + addr + ")";
return false;
}
} else if (!parseV6Addr(addr, pre)) {
mLastErr = "Failed to parse V6 Address(" + addr + ")";
return false;
}
if (famHint == IP_FAM::V4 && !populateV4Mask(mask, pre)) {
mLastErr = "Failed to populate IPv4 Mask(" + std::to_string(mask)
+ ", " + addr + ")";
return false;
} else if (!populateV6Mask(mask, pre)) {
mLastErr = "Failed to populate IPv6 Mask(" + std::to_string(mask)
+ ", " + addr + ")";
return false;
}
mPrefixes.push_back(pre);
return true;
} /* add */
/* Assumption (based on man inet_pton)
*
* X represents a hex character
* d represents a base 10 digit
* / represents the start of the subnet mask
* (assume that it can be left off of all below combinations)
*
* IPv4 Addresses always look like the following:
* ddd.ddd.ddd.ddd/dd
*
* IPv6 Addresses can look a few different ways:
* x:x:x:x:x:x:x:x/ddd
* x::x/ddd
* x:x:x:x:x:x:d.d.d.d/ddd
*
* Therefore, if a presentation of an IP Address contains a colon, then it
* may not be a valid IPv6, but, it is definitely not valid IPv4. If a
* presentation of an IP Address does not contain a colon, then it may not be
* a valid IPv4, but, it is definitely not IPv6.
*/
IP_FAM PrefixParser::guessIPFamily(string in) {
size_t found = in.find(":");
if (found != string::npos)
return IP_FAM::V6;
return IP_FAM::V4;
} /* guessIPFamily */
bool PrefixParser::splitIntoAddrAndMask(string in, string &addr, string &mask) {
size_t pos = in.find("/");
if (pos != string::npos && pos >= 1) {
/* addr is now everything up until the first / */
addr = in.substr(0, pos);
} else if (pos == string::npos) {
/* There is no /, so the entire input is an address */
addr = in;
} else {
/* There was nothing before the /, not recoverable */
return false;
}
if (pos != string::npos && pos < in.size()) {
/* There is a / and it is not the last character. Everything after /
* must be the subnet.
*/
mask = in.substr(pos + 1);
} else if (pos != string::npos && pos == in.size()) {
/* There is a /, but it is the last character. This is garbage, but,
* we may still be able to interpret the address so we will throw it
* out.
*/
mask = "";
} else if (pos == string::npos) {
/* There is no /, therefore, there is no subnet */
mask = "";
} else {
/* This really shouldn't be possible because it would imply that find
* returned a position larger than the size of the input. Just
* preserving sanity that mask is always initialized.
*/
mask = "";
}
return true;
} /* splitIntoAddrAndMask */
int PrefixParser::parseSubnetMask(string in, IP_FAM famHint) {
if (in.empty())
/* Treat no subnet mask as fully qualified */
return (famHint == IP_FAM::V6) ? 128 : 32;
return atoi(in.c_str());
} /* parseSubnetMask */
bool PrefixParser::parseV4Addr(string in, Prefix &out) {
struct sockaddr_in sa;
int ret = inet_pton(AF_INET, in.c_str(), &(sa.sin_addr));
if (ret < 0) {
/* errno would be valid */
return false;
} else if (ret == 0) {
/* input was not a valid IP address */
return false;
}
/* Address in network byte order */
out.v4Addr = htonl(sa.sin_addr.s_addr);
return true;
} /* parseV4Addr */
bool PrefixParser::parseV6Addr(string in, Prefix &out) {
struct sockaddr_in6 sa;
int ret = inet_pton(AF_INET6, in.c_str(), &(sa.sin6_addr));
if (ret < 0) {
/* errno would be valid */
return false;
} else if (ret == 0) {
/* input was not a valid IP address */
return false;
}
/* Translate unsigned chars to unsigned ints to match IPA
*
* TODO there must be a better way to do this beyond bit fiddling
* Maybe a Union since we've already made the assumption that the data
* structures match?
*/
out.v6Addr[0] = (sa.sin6_addr.s6_addr[0] << 24) |
(sa.sin6_addr.s6_addr[1] << 16) |
(sa.sin6_addr.s6_addr[2] << 8) |
(sa.sin6_addr.s6_addr[3]);
out.v6Addr[1] = (sa.sin6_addr.s6_addr[4] << 24) |
(sa.sin6_addr.s6_addr[5] << 16) |
(sa.sin6_addr.s6_addr[6] << 8) |
(sa.sin6_addr.s6_addr[7]);
out.v6Addr[2] = (sa.sin6_addr.s6_addr[8] << 24) |
(sa.sin6_addr.s6_addr[9] << 16) |
(sa.sin6_addr.s6_addr[10] << 8) |
(sa.sin6_addr.s6_addr[11]);
out.v6Addr[3] = (sa.sin6_addr.s6_addr[12] << 24) |
(sa.sin6_addr.s6_addr[13] << 16) |
(sa.sin6_addr.s6_addr[14] << 8) |
(sa.sin6_addr.s6_addr[15]);
return true;
} /* parseV6Addr */
bool PrefixParser::populateV4Mask(int mask, Prefix &out) {
if (mask < 0 || mask > 32)
return false;
out.v4Mask = createMask(mask);
return true;
} /* populateV4Mask */
bool PrefixParser::populateV6Mask(int mask, Prefix &out) {
if (mask < 0 || mask > 128)
return false;
for (int i = 0; i < 4; i++) {
out.v6Mask[i] = createMask(mask);
mask = (mask > 32) ? mask - 32 : 0;
}
return true;
} /* populateV6Mask */
uint32_t PrefixParser::createMask(int mask) {
uint32_t ret = 0;
if (mask >= 32) {
ret = ~ret;
return ret;
}
for (int i = 0; i < 32; i++) {
if (i < mask)
ret = (ret << 1) | 1;
else
ret = (ret << 1);
}
return ret;
} /* createMask */
Prefix PrefixParser::makeBlankPrefix(IP_FAM famHint) {
Prefix ret;
ret.fam = famHint;
ret.v4Addr = 0;
ret.v4Mask = 0;
ret.v6Addr[0] = 0;
ret.v6Addr[1] = 0;
ret.v6Addr[2] = 0;
ret.v6Addr[3] = 0;
ret.v6Mask[0] = 0;
ret.v6Mask[1] = 0;
ret.v6Mask[2] = 0;
ret.v6Mask[3] = 0;
return ret;
} /* makeBlankPrefix */
bool PrefixParser::isMaskValid(int mask, IP_FAM fam) {
if (mask < 0) {
mLastErr = "Failed parse subnet mask(" + std::to_string(mask) + ")";
return false;
} else if (mask == 0) {
mLastErr = "Subnet mask cannot be 0(" + std::to_string(mask) + ")";
return false;
} else if (fam == IP_FAM::V4 && mask > 32) {
mLastErr = "Interpreted address as V4 but mask was too large("
+ std::to_string(mask) + ")";
return false;
} else if (fam == IP_FAM::V6 && mask > 128) {
mLastErr = "Interpreted address as V6 but mask was too large("
+ std::to_string(mask) + ")";
return false;
}
return true;
} /* isMaskValid */

View file

@ -1,72 +0,0 @@
cc_binary {
name: "ipacm",
local_include_dirs: ["src"] + ["inc"],
header_libs: ["generated_kernel_headers"],
cflags: ["-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",
}

View file

@ -1,109 +0,0 @@
/*
Copyright (c) 2013-2016, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_CmdQueue.h
@brief
This file implements the IPAM Comment Queue definitions
@Author
*/
#ifndef IPA_CONNTRACK_MESSAGE_H
#define IPA_CONNTRACK_MESSAGE_H
#include <pthread.h>
#include "IPACM_Defs.h"
/*---------------------------------------------------------------------------
Event data required by IPA_CM
---------------------------------------------------------------------------*/
typedef struct _ipacm_cmd_q_data {
ipa_cm_event_id event;
void *evt_data;
}ipacm_cmd_q_data;
typedef struct cmd_s
{
void (*callback_ptr)(ipacm_cmd_q_data *);
ipacm_cmd_q_data data;
}cmd_t;
class Message
{
private:
Message *m_next;
public:
cmd_t evt;
Message()
{
m_next = NULL;
evt.callback_ptr = NULL;
}
~Message() { }
void setnext(Message *item) { m_next = item; }
Message* getnext() { return m_next; }
};
class MessageQueue
{
private:
Message *Head;
Message *Tail;
Message* dequeue(void);
static MessageQueue *inst_internal;
static MessageQueue *inst_external;
MessageQueue()
{
Head = NULL;
Tail = NULL;
}
public:
~MessageQueue() { }
void enqueue(Message *item);
static void* Process(void *);
static MessageQueue* getInstanceInternal();
static MessageQueue* getInstanceExternal();
};
#endif /* IPA_CONNTRACK_MESSAGE_H */

View file

@ -1,380 +0,0 @@
/*
Copyright (c) 2013-2019, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_Config.h
@brief
This file implements the IPACM Configuration from XML file
@Author
Skylar Chang
*/
#ifndef IPACM_CONFIG_H
#define IPACM_CONFIG_H
#include "IPACM_Defs.h"
#include "IPACM_Xml.h"
#include "IPACM_EvtDispatcher.h"
typedef struct
{
char iface_name[IPA_IFACE_NAME_LEN];
bool v4_up;
bool v6_up;
}NatIfaces;
/* for IPACM rm dependency use*/
typedef struct _ipa_rm_client
{
ipa_rm_resource_name producer_rm1;
ipa_rm_resource_name consumer_rm1;
ipa_rm_resource_name producer_rm2;
ipa_rm_resource_name consumer_rm2;
bool producer1_up; /* only monitor producer_rm1, not monitor producer_rm2 */
bool consumer1_up; /* only monitor consumer_rm1, not monitor consumer_rm2 */
bool rm_set; /* once producer1_up and consumer1_up, will add bi-directional dependency */
bool rx_bypass_ipa; /* support WLAN may not register RX-property, should not add dependency */
}ipa_rm_client;
#define MAX_NUM_EXT_PROPS 25
/* used to hold extended properties */
typedef struct
{
uint8_t num_ext_props;
ipa_ioc_ext_intf_prop prop[MAX_NUM_EXT_PROPS];
} ipacm_ext_prop;
/* iface */
class IPACM_Config
{
public:
/* IPACM ipa_client map to rm_resource*/
ipa_rm_resource_name ipa_client_rm_map_tbl[IPA_CLIENT_MAX];
/* IPACM monitored rm_depency table */
ipa_rm_client ipa_rm_tbl[IPA_MAX_RM_ENTRY];
/* IPACM rm_depency a2 endpoint check*/
int ipa_rm_a2_check;
/* Store interested interface and their configuration from XML file */
ipa_ifi_dev_name_t *iface_table;
/* Store interested ALG port from XML file */
ipacm_alg *alg_table;
/* Store private subnet configuration from XML file */
ipa_private_subnet private_subnet_table[IPA_MAX_PRIVATE_SUBNET_ENTRIES + IPA_MAX_MTU_ENTRIES];
/* Store the non nat iface names */
NatIfaces *pNatIfaces;
/* Store the bridge iface name */
char ipa_virtual_iface_name[IPA_IFACE_NAME_LEN];
/* Store the number of interface IPACM read from XML file */
int ipa_num_ipa_interfaces;
int ipa_num_private_subnet;
int ipa_num_alg_ports;
int ipa_nat_max_entries;
bool ipacm_odu_router_mode;
bool ipacm_odu_enable;
bool ipacm_odu_embms_enable;
bool ipacm_ip_passthrough_mode;
int ipa_nat_iface_entries;
/* Store the total number of wlan guest ap configured */
int ipa_num_wlan_guest_ap;
/* Max valid rm entry */
int ipa_max_valid_rm_entry;
/* Store SW-enable or not */
bool ipa_sw_rt_enable;
/* Store bridge mode or not */
bool ipa_bridge_enable;
/* Store bridge netdev mac */
uint8_t bridge_mac[IPA_MAC_ADDR_SIZE];
/* Store the flt rule count for each producer client*/
int flt_rule_count_v4[IPA_CLIENT_MAX];
int flt_rule_count_v6[IPA_CLIENT_MAX];
/* IPACM routing table name for v4/v6 */
struct ipa_ioc_get_rt_tbl rt_tbl_lan_v4, rt_tbl_wan_v4, rt_tbl_default_v4, rt_tbl_v6, rt_tbl_wan_v6;
struct ipa_ioc_get_rt_tbl rt_tbl_wan_dl;
struct ipa_ioc_get_rt_tbl rt_tbl_odu_v4, rt_tbl_odu_v6;
bool isMCC_Mode;
/* IPA_HW_FNR_STATS */
bool hw_fnr_stats_support;
int hw_counter_offset;
int sw_counter_offset;
/* To return the instance */
static IPACM_Config* GetInstance();
const char* getEventName(ipa_cm_event_id event_id);
inline void increaseFltRuleCount(int index, ipa_ip_type iptype, int increment)
{
if((index >= IPA_CLIENT_MAX) || (index < 0))
{
IPACMERR("Index is out of range: %d.\n", index);
return;
}
if(iptype == IPA_IP_v4)
{
flt_rule_count_v4[index] += increment;
IPACMDBG_H("Now num of v4 flt rules on client %d is %d.\n", index, flt_rule_count_v4[index]);
}
else
{
flt_rule_count_v6[index] += increment;
IPACMDBG_H("Now num of v6 flt rules on client %d is %d.\n", index, flt_rule_count_v6[index]);
}
return;
}
inline void decreaseFltRuleCount(int index, ipa_ip_type iptype, int decrement)
{
if((index >= IPA_CLIENT_MAX) || (index < 0))
{
IPACMERR("Index is out of range: %d.\n", index);
return;
}
if(iptype == IPA_IP_v4)
{
flt_rule_count_v4[index] -= decrement;
IPACMDBG_H("Now num of v4 flt rules on client %d is %d.\n", index, flt_rule_count_v4[index]);
}
else
{
flt_rule_count_v6[index] -= decrement;
IPACMDBG_H("Now num of v6 flt rules on client %d is %d.\n", index, flt_rule_count_v6[index]);
}
return;
}
inline int getFltRuleCount(int index, ipa_ip_type iptype)
{
if((index >= IPA_CLIENT_MAX) || (index < 0))
{
IPACMERR("Index is out of range: %d.\n", index);
return -1;
}
if(iptype == IPA_IP_v4)
{
return flt_rule_count_v4[index];
}
else
{
return flt_rule_count_v6[index];
}
}
inline int GetAlgPortCnt()
{
return ipa_num_alg_ports;
}
int GetAlgPorts(int nPorts, ipacm_alg *pAlgPorts);
inline int GetNatMaxEntries(void)
{
return ipa_nat_max_entries;
}
inline int GetNatIfacesCnt()
{
return ipa_nat_iface_entries;
}
int GetNatIfaces(int nPorts, NatIfaces *ifaces);
/* for IPACM resource manager dependency usage */
void AddRmDepend(ipa_rm_resource_name rm1,bool rx_bypass_ipa);
void DelRmDepend(ipa_rm_resource_name rm1);
int AddNatIfaces(char *dev_name, ipa_ip_type ip_type);
int DelNatIfaces(char *dev_name);
int CheckNatIfaces(const char *dev_name, ipa_ip_type ip_type);
inline void SetQmapId(uint8_t id)
{
qmap_id = id;
}
inline uint8_t GetQmapId()
{
return qmap_id;
}
int SetExtProp(ipa_ioc_query_intf_ext_props *prop);
ipacm_ext_prop* GetExtProp(ipa_ip_type ip_type);
int DelExtProp(ipa_ip_type ip_type);
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)
{
for(int cnt=0; cnt<ipa_num_private_subnet; cnt++)
{
if(private_subnet_table[cnt].subnet_addr ==
(private_subnet_table[cnt].subnet_mask & ip_addr))
{
return true;
}
}
return false;
}
#ifdef FEATURE_IPA_ANDROID
inline bool AddPrivateSubnet(uint32_t ip_addr, int ipa_if_index)
{
ipacm_cmd_q_data evt_data;
ipacm_event_data_fid *data_fid;
uint32_t subnet_mask = ~0;
for(int cnt=0; cnt<ipa_num_private_subnet; cnt++)
{
if(private_subnet_table[cnt].subnet_addr == ip_addr)
{
IPACMDBG("Already has private subnet_addr as: 0x%x in entry(%d) \n", ip_addr, cnt);
return true;
}
}
if(ipa_num_private_subnet < IPA_MAX_PRIVATE_SUBNET_ENTRIES)
{
IPACMDBG("Add IPACM private subnet_addr as: 0x%x in entry(%d) \n", ip_addr, ipa_num_private_subnet);
private_subnet_table[ipa_num_private_subnet].subnet_addr = ip_addr;
private_subnet_table[ipa_num_private_subnet].subnet_mask = (subnet_mask >> 8) << 8;
ipa_num_private_subnet++;
/* IPACM private subnet set changes */
data_fid = (ipacm_event_data_fid *)malloc(sizeof(ipacm_event_data_fid));
if(data_fid == NULL)
{
IPACMERR("unable to allocate memory for event data_fid\n");
return IPACM_FAILURE;
}
data_fid->if_index = ipa_if_index; // already ipa index, not fid index
evt_data.event = IPA_PRIVATE_SUBNET_CHANGE_EVENT;
evt_data.evt_data = data_fid;
/* Insert IPA_PRIVATE_SUBNET_CHANGE_EVENT to command queue */
IPACM_EvtDispatcher::PostEvt(&evt_data);
return true;
}
IPACMERR("IPACM private subnet_addr overflow, total entry(%d)\n", ipa_num_private_subnet);
return false;
}
inline bool DelPrivateSubnet(uint32_t ip_addr, int ipa_if_index)
{
ipacm_cmd_q_data evt_data;
ipacm_event_data_fid *data_fid;
for(int cnt=0; cnt<ipa_num_private_subnet; cnt++)
{
if(private_subnet_table[cnt].subnet_addr == ip_addr)
{
IPACMDBG("Found private subnet_addr as: 0x%x in entry(%d) \n", ip_addr, cnt);
for (; cnt < ipa_num_private_subnet - 1; cnt++)
{
private_subnet_table[cnt].subnet_addr = private_subnet_table[cnt+1].subnet_addr;
}
ipa_num_private_subnet = ipa_num_private_subnet - 1;
/* IPACM private subnet set changes */
data_fid = (ipacm_event_data_fid *)malloc(sizeof(ipacm_event_data_fid));
if(data_fid == NULL)
{
IPACMERR("unable to allocate memory for event data_fid\n");
return IPACM_FAILURE;
}
data_fid->if_index = ipa_if_index; // already ipa index, not fid index
evt_data.event = IPA_PRIVATE_SUBNET_CHANGE_EVENT;
evt_data.evt_data = data_fid;
/* Insert IPA_PRIVATE_SUBNET_CHANGE_EVENT to command queue */
IPACM_EvtDispatcher::PostEvt(&evt_data);
return true;
}
}
IPACMDBG("can't find private subnet_addr as: 0x%x \n", ip_addr);
return false;
}
#endif /* defined(FEATURE_IPA_ANDROID)*/
static const char *DEVICE_NAME_ODU;
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);
int m_fd; /* File descriptor of the IPA device node /dev/ipa */
uint8_t qmap_id;
ipacm_ext_prop ext_prop_v4;
ipacm_ext_prop ext_prop_v6;
};
#endif /* IPACM_CONFIG */

View file

@ -1,114 +0,0 @@
/*
Copyright (c) 2013, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef IPACM_CONNTRACK_FILTER_H
#define IPACM_CONNTRACK_FILTER_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef in_addr_t
typedef uint32_t in_addr_t;
#endif
#include <arpa/inet.h>
#include <netinet/in.h>
#include <errno.h>
#include "IPACM_ConntrackClient.h"
#include "IPACM_CmdQueue.h"
#include "IPACM_Conntrack_NATApp.h"
#include "IPACM_EvtDispatcher.h"
#include "IPACM_Defs.h"
#ifndef IPACM_DEBUG
#define IPACM_DEBUG
#endif
extern "C"
{
#include <libnetfilter_conntrack/libnetfilter_conntrack.h>
#include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
#include <sys/inotify.h>
}
using namespace std;
#define UDP_TIMEOUT_UPDATE 20
#define BROADCAST_IPV4_ADDR 0xFFFFFFFF
class IPACM_ConntrackClient
{
private:
static IPACM_ConntrackClient *pInstance;
struct nfct_handle *tcp_hdl;
struct nfct_handle *udp_hdl;
struct nfct_filter *tcp_filter;
struct nfct_filter *udp_filter;
static int IPA_Conntrack_Filters_Ignore_Local_Addrs(struct nfct_filter *filter);
static int IPA_Conntrack_Filters_Ignore_Bridge_Addrs(struct nfct_filter *filter);
static int IPA_Conntrack_Filters_Ignore_Local_Iface(struct nfct_filter *, ipacm_event_iface_up *);
IPACM_ConntrackClient();
public:
static int IPAConntrackEventCB(enum nf_conntrack_msg_type type,
struct nf_conntrack *ct,
void *data);
static int IPA_Conntrack_UDP_Filter_Init(void);
static int IPA_Conntrack_TCP_Filter_Init(void);
static void* TCPRegisterWithConnTrack(void *);
static void* UDPRegisterWithConnTrack(void *);
static void* UDPConnTimeoutUpdate(void *);
static void UpdateUDPFilters(void *, bool);
static void UpdateTCPFilters(void *, bool);
static void Read_TcpUdp_Timeout(char *in, int len);
static IPACM_ConntrackClient* GetInstance();
static void UNRegisterWithConnTrack(void);
int fd_tcp;
int fd_udp;
unsigned int subscrips_tcp;
unsigned int subscrips_udp;
#ifdef IPACM_DEBUG
#define iptodot(X,Y) \
IPACMLOG(" %s(0x%x): %d.%d.%d.%d\n", X, Y, ((Y>>24) & 0xFF), ((Y>>16) & 0xFF), ((Y>>8) & 0xFF), (Y & 0xFF));
#endif
#define log_nat(A,B,C,D,E,F) \
IPACMDBG_H("protocol %d Private IP: %d.%d.%d.%d\t Target IP: %d.%d.%d.%d\t private port: %d public port: %d %s",A,((B>>24) & 0xFF), ((B>>16) & 0xFF), ((B>>8) & 0xFF), (B & 0xFF), ((C>>24) & 0xFF), ((C>>16) & 0xFF),((C>>8) & 0xFF),(C & 0xFF),D,E,F);
};
#endif /* IPACM_CONNTRACK_FILTER_H */

View file

@ -1,142 +0,0 @@
/*
Copyright (c) 2013-2019, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef IPACM_CONNTRACK_LISTENER
#define IPACM_CONNTRACK_LISTENER
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#ifndef in_addr_t
typedef uint32_t in_addr_t;
#endif
#include <arpa/inet.h>
#include <netinet/in.h>
#include <errno.h>
#include "IPACM_CmdQueue.h"
#include "IPACM_Conntrack_NATApp.h"
#include "IPACM_Listener.h"
#ifdef CT_OPT
#include "IPACM_LanToLan.h"
#endif
#define MAX_IFACE_ADDRESS 50
#define MAX_STA_CLNT_IFACES 10
#define STA_CLNT_SUBNET_MASK 0xFFFFFF00
using namespace std;
typedef struct _nat_entry_bundle
{
struct nf_conntrack *ct;
enum nf_conntrack_msg_type type;
nat_table_entry *rule;
bool isTempEntry;
}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
{
private:
bool isCTReg;
bool isNatThreadStart;
bool WanUp;
bool isProcessCTDone;
NatApp *nat_inst;
int NatIfaceCnt;
int StaClntCnt;
NatIfaces *pNatIfaces;
uint32_t nat_iface_ipv4_addr[MAX_IFACE_ADDRESS];
uint32_t nonnat_iface_ipv4_addr[MAX_IFACE_ADDRESS];
uint32_t sta_clnt_ipv4_addr[MAX_STA_CLNT_IFACES];
IPACM_Config *pConfig;
ct_entry *ct_entries;
ct_entry ct_cache[MAX_CONNTRACK_ENTRIES];
#ifdef CT_OPT
IPACM_LanToLan *p_lan2lan;
#endif
void ProcessCTMessage(void *);
bool ProcessTCPorUDPMsg(struct nf_conntrack *,
enum nf_conntrack_msg_type, u_int8_t);
void TriggerWANUp(void *);
void TriggerWANDown(uint32_t);
int CreateNatThreads(void);
bool AddIface(nat_table_entry *, bool *);
void AddORDeleteNatEntry(const nat_entry_bundle *);
void PopulateTCPorUDPEntry(struct nf_conntrack *, uint32_t, nat_table_entry *);
void CheckSTAClient(const nat_table_entry *, bool *);
int CheckNatIface(ipacm_event_data_all *, bool *);
void HandleNonNatIPAddr(void *, bool);
#ifdef CT_OPT
void ProcessCTV6Message(void *);
void HandleLan2Lan(struct nf_conntrack *,
enum nf_conntrack_msg_type, nat_table_entry* );
#endif
public:
char wan_ifname[IPA_IFACE_NAME_LEN];
uint32_t wan_ipaddr;
ipacm_wan_iface_type backhaul_mode;
bool isReadCTDone;
IPACM_ConntrackListener();
void event_callback(ipa_cm_event_id, void *data);
inline bool isWanUp()
{
return WanUp;
}
void HandleNeighIpAddrAddEvt(ipacm_event_data_all *);
void HandleNeighIpAddrDelEvt(uint32_t);
void HandleSTAClientAddEvt(uint32_t);
void HandleSTAClientDelEvt(uint32_t);
int CreateConnTrackThreads(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;
#endif /* IPACM_CONNTRACK_LISTENER */

View file

@ -1,144 +0,0 @@
/*
Copyright (c) 2013-2019, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef IPACM_CONNTRACK_NATAPP_H
#define IPACM_CONNTRACK_NATAPP_H
#include <string.h> /* for stderror */
#include <stdlib.h>
#include <cstdio> /* for perror */
#include "IPACM_Config.h"
#include "IPACM_Xml.h"
extern "C"
{
#include <libnetfilter_conntrack/libnetfilter_conntrack.h>
#include <ipa_nat_drv.h>
}
#define MAX_TEMP_ENTRIES 25
#define IPACM_TCP_FULL_FILE_NAME "/proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_timeout_established"
#define IPACM_UDP_FULL_FILE_NAME "/proc/sys/net/ipv4/netfilter/ip_conntrack_udp_timeout_stream"
typedef struct _nat_table_entry
{
uint32_t private_ip;
uint16_t private_port;
uint32_t target_ip;
uint16_t target_port;
uint32_t public_ip;
uint16_t public_port;
u_int8_t protocol;
uint32_t timestamp;
bool dst_nat;
bool enabled;
uint32_t rule_hdl;
/* used for pcie-modem */
uint32_t rule_id;
}nat_table_entry;
#define CHK_TBL_HDL() if(nat_table_hdl == 0){ return -1; }
class NatApp
{
private:
static NatApp *pInstance;
nat_table_entry *cache;
nat_table_entry temp[MAX_TEMP_ENTRIES];
uint32_t pub_ip_addr;
uint32_t pub_ip_addr_pre;
uint32_t nat_table_hdl;
/* used for pcie-modem */
uint8_t pub_mux_id;
int curCnt, max_entries;
ipacm_alg *pALGPorts;
uint16_t nALGPort;
uint32_t tcp_timeout;
uint32_t udp_timeout;
uint32_t PwrSaveIfs[IPA_MAX_NUM_WIFI_CLIENTS];
struct nf_conntrack *ct;
struct nfct_handle *ct_hdl;
int m_fd_ipa;
NatApp();
~NatApp();
int Init();
void UpdateCTUdpTs(nat_table_entry *, uint32_t);
bool ChkForDup(const nat_table_entry *);
bool isAlgPort(uint8_t, uint16_t);
void Reset();
bool isPwrSaveIf(uint32_t);
uint32_t GenerateMetdata(uint8_t mux_id);
public:
static NatApp* GetInstance();
int AddTable(uint32_t, uint8_t mux_id);
uint32_t GetTableHdl(uint32_t);
int DeleteTable(uint32_t);
int AddEntry(const nat_table_entry *);
int DeleteEntry(const nat_table_entry *);
int AddConnection(const nat_table_entry *);
int DelConnection(const uint32_t);
void UpdateUDPTimeStamp();
int UpdatePwrSaveIf(uint32_t);
int ResetPwrSaveIf(uint32_t);
int DelEntriesOnClntDiscon(uint32_t);
int DelEntriesOnSTAClntDiscon(uint32_t);
void Read_TcpUdp_Timeout(void);
void AddTempEntry(const nat_table_entry *);
void CacheEntry(const nat_table_entry *);
void DeleteTempEntry(const nat_table_entry *);
void FlushTempEntries(uint32_t, bool, bool isDummy = false);
};
#endif /* IPACM_CONNTRACK_NATAPP_H */

View file

@ -1,421 +0,0 @@
/*
Copyright (c) 2013-2019, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_Defs.h
@brief
This file implements the common definitions amon all ifaces.
@Author
Skylar Chang
*/
#ifndef IPA_CM_DEFS_H
#define IPA_CM_DEFS_H
#include <unistd.h>
#include <fcntl.h>
#include <linux/msm_ipa.h>
#include "IPACM_Log.h"
#ifdef USE_GLIB
#include <glib.h>
#define strlcpy g_strlcpy
#define strlcat g_strlcat
#endif
extern "C"
{
#include <libnetfilter_conntrack/libnetfilter_conntrack.h>
#include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
}
#define IF_NAME_LEN 16
#define IPA_MAX_FILE_LEN 64
#define IPA_IFACE_NAME_LEN 16
#define IPA_ALG_PROTOCOL_NAME_LEN 10
#define IPA_WLAN_PARTIAL_HDR_OFFSET 0 // dst mac first then src mac
#define IPA_ODU_PARTIAL_HDR_OFFSET 8 // dst mac first then src mac
#define IPA_WLAN_PARTIAL_HDR_NAME_v4 "IEEE802_3_v4"
#define IPA_WLAN_PARTIAL_HDR_NAME_v6 "IEEE802_3_v6"
#define IPA_DUMMY_ETH_HDR_NAME_v6 "ETH_dummy_v6"
#define IPA_WAN_PARTIAL_HDR_NAME_v4 "IEEE802_3_STA_v4"
#define IPA_WAN_PARTIAL_HDR_NAME_v6 "IEEE802_3_STA_v6"
#define IPA_ETH_HDR_NAME_v4 "IPACM_ETH_v4"
#define IPA_ETH_HDR_NAME_v6 "IPACM_ETH_v6"
#define IPA_ODU_HDR_NAME_v4 "IPACM_ODU_v4"
#define IPA_ODU_HDR_NAME_v6 "IPACM_ODU_v6"
#define IPA_MAX_IFACE_ENTRIES 20
#define IPA_MAX_PRIVATE_SUBNET_ENTRIES 3
#define IPA_MAX_MTU_ENTRIES 3
#define IPA_MAX_ALG_ENTRIES 20
#define IPA_MAX_RM_ENTRY 6
#define IPV4_ADDR_LINKLOCAL 0xA9FE0000
#define IPV4_ADDR_LINKLOCAL_MASK 0xFFFF0000
#define V4_DEFAULT_ROUTE_TABLE_NAME "ipa_dflt_rt"
#define V4_LAN_ROUTE_TABLE_NAME "COMRTBLLANv4"
#define V4_WAN_ROUTE_TABLE_NAME "WANRTBLv4"
#define WAN_DL_ROUTE_TABLE_NAME "ipa_dflt_wan_rt"
#define V6_COMMON_ROUTE_TABLE_NAME "COMRTBLv6"
#define V6_WAN_ROUTE_TABLE_NAME "WANRTBLv6"
#define V4_ODU_ROUTE_TABLE_NAME "ODURTBLv4"
#define V6_ODU_ROUTE_TABLE_NAME "ODURTBLv6"
#define WWAN_QMI_IOCTL_DEVICE_NAME "/dev/wwan_ioctl"
#define IPA_DEVICE_NAME "/dev/ipa"
#define MAX_NUM_PROP 2
#define IPA_MAX_FLT_RULE 100
#define TCP_FIN_SHIFT 16
#define TCP_SYN_SHIFT 17
#define TCP_RST_SHIFT 18
#define NUM_IPV6_PREFIX_FLT_RULE 1
#define NUM_IPV6_PREFIX_MTU_RULE 1
#define MAX_CONNTRACK_ENTRIES 100
#define CT_ENTRIES_BUFFER_SIZE 8096
#define LOOPBACK_MASK 0xFF000000
#define LOOPBACK_ADDR 0x7F000000
/*---------------------------------------------------------------------------
Return values indicating error status
---------------------------------------------------------------------------*/
#define IPACM_SUCCESS 0 /* Successful operation */
#define IPACM_FAILURE -1 /* Unsuccessful operation */
#define IPACM_IP_NULL (ipa_ip_type)0xFF
#define IPACM_INVALID_INDEX (ipa_ip_type)0xFF
#define IPA_MAX_NUM_WIFI_CLIENTS 32
#define IPA_MAX_NUM_WAN_CLIENTS 10
#define IPA_MAX_NUM_ETH_CLIENTS 15
#define IPA_MAX_NUM_AMPDU_RULE 15
#define IPA_MAC_ADDR_SIZE 6
#define IPA_MAX_NUM_SW_PDNS 15
#define DEFAULT_MTU_SIZE 1500
/*===========================================================================
GLOBAL DEFINITIONS AND DECLARATIONS
===========================================================================*/
typedef enum
{
IPA_CFG_CHANGE_EVENT, /* NULL */
IPA_PRIVATE_SUBNET_CHANGE_EVENT, /* ipacm_event_data_fid */
IPA_FIREWALL_CHANGE_EVENT, /* NULL */
IPA_LINK_UP_EVENT, /* ipacm_event_data_fid */
IPA_LINK_DOWN_EVENT, /* ipacm_event_data_fid */
IPA_USB_LINK_UP_EVENT, /* ipacm_event_data_fid */
IPA_BRIDGE_LINK_UP_EVENT, /* ipacm_event_data_all */
IPA_WAN_EMBMS_LINK_UP_EVENT, /* ipacm_event_data_mac */
IPA_ADDR_ADD_EVENT, /* ipacm_event_data_addr */
IPA_ADDR_DEL_EVENT, /* no use */
IPA_ROUTE_ADD_EVENT, /* ipacm_event_data_addr */
IPA_ROUTE_DEL_EVENT, /* ipacm_event_data_addr */
IPA_WAN_UPSTREAM_ROUTE_ADD_EVENT, /* ipacm_event_data_fid */
IPA_WAN_UPSTREAM_ROUTE_DEL_EVENT, /* ipacm_event_data_fid */
IPA_WLAN_AP_LINK_UP_EVENT, /* ipacm_event_data_mac */
IPA_WLAN_STA_LINK_UP_EVENT, /* ipacm_event_data_mac */
IPA_WLAN_LINK_DOWN_EVENT, /* ipacm_event_data_mac */
IPA_WLAN_CLIENT_ADD_EVENT, /* ipacm_event_data_mac */
IPA_WLAN_CLIENT_ADD_EVENT_EX, /* ipacm_event_data_wlan_ex */
IPA_WLAN_CLIENT_DEL_EVENT, /* ipacm_event_data_mac */
IPA_WLAN_CLIENT_POWER_SAVE_EVENT, /* ipacm_event_data_mac */
IPA_WLAN_CLIENT_RECOVER_EVENT, /* ipacm_event_data_mac */
IPA_NEW_NEIGH_EVENT, /* ipacm_event_data_all */
IPA_DEL_NEIGH_EVENT, /* ipacm_event_data_all */
IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT, /* ipacm_event_data_all */
IPA_NEIGH_CLIENT_IP_ADDR_DEL_EVENT, /* ipacm_event_data_all */
IPA_SW_ROUTING_ENABLE, /* NULL */
IPA_SW_ROUTING_DISABLE, /* NULL */
IPA_PROCESS_CT_MESSAGE, /* ipacm_ct_evt_data */
IPA_PROCESS_CT_MESSAGE_V6, /* ipacm_ct_evt_data */
IPA_LAN_TO_LAN_NEW_CONNECTION, /* ipacm_event_connection */
IPA_LAN_TO_LAN_DEL_CONNECTION, /* ipacm_event_connection */
IPA_WLAN_SWITCH_TO_SCC, /* No Data */
IPA_WLAN_SWITCH_TO_MCC, /* No Data */
IPA_CRADLE_WAN_MODE_SWITCH, /* ipacm_event_cradle_wan_mode */
IPA_WAN_XLAT_CONNECT_EVENT, /* ipacm_event_data_fid */
IPA_TETHERING_STATS_UPDATE_EVENT, /* ipacm_event_data_fid */
IPA_NETWORK_STATS_UPDATE_EVENT, /* ipacm_event_data_fid */
IPA_DOWNSTREAM_ADD, /* ipacm_event_ipahal_stream */
IPA_DOWNSTREAM_DEL, /* ipacm_event_ipahal_stream */
IPA_EXTERNAL_EVENT_MAX,
IPA_HANDLE_WAN_UP, /* ipacm_event_iface_up */
IPA_HANDLE_WAN_DOWN, /* ipacm_event_iface_up */
IPA_HANDLE_WAN_UP_V6, /* ipacm_event_iface_up */
IPA_HANDLE_WAN_DOWN_V6, /* NULL */
IPA_HANDLE_WAN_UP_TETHER, /* ipacm_event_iface_up_tehter */
IPA_HANDLE_WAN_DOWN_TETHER, /* ipacm_event_iface_up_tehter */
IPA_HANDLE_WAN_UP_V6_TETHER, /* ipacm_event_iface_up_tehter */
IPA_HANDLE_WAN_DOWN_V6_TETHER, /* ipacm_event_iface_up_tehter */
IPA_HANDLE_WLAN_UP, /* ipacm_event_iface_up */
IPA_HANDLE_LAN_UP, /* ipacm_event_iface_up */
IPA_ETH_BRIDGE_IFACE_UP, /* ipacm_event_eth_bridge*/
IPA_ETH_BRIDGE_IFACE_DOWN, /* ipacm_event_eth_bridge*/
IPA_ETH_BRIDGE_CLIENT_ADD, /* ipacm_event_eth_bridge */
IPA_ETH_BRIDGE_CLIENT_DEL, /* ipacm_event_eth_bridge*/
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 */
IPA_ADD_L2TP_VLAN_MAPPING, /* ipa_ioc_l2tp_vlan_mapping_info */
IPA_DEL_L2TP_VLAN_MAPPING, /* ipa_ioc_l2tp_vlan_mapping_info */
IPA_HANDLE_VLAN_CLIENT_INFO, /* ipacm_event_data_all */
IPA_HANDLE_VLAN_IFACE_INFO, /* ipacm_event_data_all */
#endif
IPA_WLAN_FWR_SSR_BEFORE_SHUTDOWN_NOTICE,
IPA_LAN_DELETE_SELF, /* ipacm_event_data_fid */
IPA_WIGIG_CLIENT_ADD_EVENT, /* ipacm_event_data_mac_ep */
IPA_WIGIG_FST_SWITCH, /* ipacm_event_data_fst */
IPACM_EVENT_MAX
} ipa_cm_event_id;
typedef struct
{
uint8_t num_rule;
uint32_t rule_hdl[MAX_NUM_PROP];
} lan_to_lan_rt_rule_hdl;
typedef enum
{
LAN_IF = 0,
WLAN_IF,
WAN_IF,
VIRTUAL_IF,
ETH_IF,
EMBMS_IF,
ODU_IF,
UNKNOWN_IF
} ipacm_iface_type;
typedef enum
{
ROUTER = 0,
BRIDGE
} ipacm_cradle_iface_mode;
typedef enum
{
FULL,
INTERNET
} ipacm_wlan_access_mode;
typedef struct
{
struct nf_conntrack *ct;
enum nf_conntrack_msg_type type;
}ipacm_ct_evt_data;
typedef struct
{
char iface_name[IPA_IFACE_NAME_LEN];
ipacm_iface_type if_cat;
ipacm_cradle_iface_mode if_mode;
ipacm_wlan_access_mode wlan_mode;
int netlink_interface_index;
} ipa_ifi_dev_name_t;
typedef struct
{
uint32_t subnet_addr;
uint32_t subnet_mask;
} ipa_private_subnet;
typedef struct _ipacm_event_data_all
{
enum ipa_ip_type iptype;
int if_index;
uint32_t ipv4_addr;
uint32_t ipv6_addr[4];
uint8_t mac_addr[IPA_MAC_ADDR_SIZE];
char iface_name[IPA_IFACE_NAME_LEN];
} ipacm_event_data_all;
class IPACM_Lan;
typedef struct
{
ipacm_cradle_iface_mode cradle_wan_mode;
} ipacm_event_cradle_wan_mode;
typedef struct
{
IPACM_Lan *p_iface;
ipa_ip_type iptype;
uint8_t mac_addr[6];
char iface_name[IPA_IFACE_NAME_LEN];
int ep;
} ipacm_event_eth_bridge;
typedef struct
{
enum ipa_ip_type iptype;
uint32_t src_ipv4_addr;
uint32_t dst_ipv4_addr;
uint32_t src_ipv6_addr[4];
uint32_t dst_ipv6_addr[4];
} ipacm_event_connection;
typedef struct _ipacm_event_data_fid
{
int if_index;
} ipacm_event_data_fid;
typedef struct
{
ipacm_iface_type if_cat;
} ipacm_event_data_if_cat;
typedef struct _ipacm_event_data_iptype
{
int if_index;
int if_index_tether;
enum ipa_ip_type iptype;
#ifdef IPA_WAN_MSG_IPv6_ADDR_GW_LEN
uint32_t ipv4_addr_gw;
uint32_t ipv6_addr_gw[4];
#endif
} ipacm_event_data_iptype;
typedef struct _ipacm_event_data_addr
{
enum ipa_ip_type iptype;
char iface_name[IPA_IFACE_NAME_LEN];
int if_index;
uint32_t ipv4_addr_gw;
uint32_t ipv4_addr;
uint32_t ipv4_addr_mask;
uint32_t ipv6_addr[4];
uint32_t ipv6_addr_mask[4];
uint32_t ipv6_addr_gw[4];
} ipacm_event_data_addr;
typedef struct _ipacm_event_data_mac
{
int if_index;
int ipa_if_cate;
uint8_t mac_addr[IPA_MAC_ADDR_SIZE];
} ipacm_event_data_mac;
typedef struct _ipacm_event_data_mac_ep
{
int if_index;
enum ipa_client_type client;
uint8_t mac_addr[IPA_MAC_ADDR_SIZE];
} ipacm_event_data_mac_ep;
typedef struct _ipacm_event_data_fst
{
int if_index;
bool to_wigig;
uint8_t mac_addr[IPA_MAC_ADDR_SIZE];
} ipacm_event_data_fst;
typedef struct
{
int if_index;
uint8_t num_of_attribs;
struct ipa_wlan_hdr_attrib_val attribs[0];
} ipacm_event_data_wlan_ex;
typedef enum
{
Q6_WAN = 0,
WLAN_WAN,
ECM_WAN,
Q6_MHI_WAN
} ipacm_wan_iface_type;
typedef struct _ipacm_event_iface_up
{
ipacm_wan_iface_type backhaul_type;
char ifname[IPA_IFACE_NAME_LEN];
uint32_t ipv4_addr;
uint32_t addr_mask;
uint32_t ipv6_prefix[2];
uint8_t xlat_mux_id;
uint8_t mux_id;
}ipacm_event_iface_up;
typedef struct _ipacm_event_iface_up_tether
{
ipacm_wan_iface_type backhaul_type;
uint32_t if_index_tether;
uint32_t ipv6_prefix[2];
bool is_sta;
uint8_t xlat_mux_id;
}ipacm_event_iface_up_tehter;
typedef struct _ipacm_ifacemgr_data
{
int if_index;
ipacm_wan_iface_type if_type;
uint8_t mac_addr[IPA_MAC_ADDR_SIZE];
}ipacm_ifacemgr_data;
typedef struct _ipacm_offload_prefix {
enum ipa_ip_type iptype;
uint32_t v4Addr;
uint32_t v4Mask;
uint32_t v6Addr[4];
uint32_t v6Mask[4];
} ipacm_offload_prefix;
typedef struct {
int if_index;
_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 */

View file

@ -1,76 +0,0 @@
/*
Copyright (c) 2013, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_EvtDispatcher.h
@brief
This file implements the IPAM event dispatcher definitions
@Author
*/
#ifndef IPACM_EvtDispatcher_H
#define IPACM_EvtDispatcher_H
#include <stdio.h>
#include <IPACM_CmdQueue.h>
#include "IPACM_Defs.h"
#include "IPACM_Listener.h"
/* queue */
typedef struct _cmd_evts
{
ipa_cm_event_id event;
IPACM_Listener *obj;
//int ipa_interface_index;
_cmd_evts *next;
} cmd_evts;
class IPACM_EvtDispatcher
{
public:
/* api for all iface instances to register events */
static int registr(ipa_cm_event_id event, IPACM_Listener *obj);
/* api for all iface instances to de-register events */
static int deregistr(IPACM_Listener *obj);
static int PostEvt(ipacm_cmd_q_data *);
static void ProcessEvt(ipacm_cmd_q_data *);
private:
static cmd_evts *head;
};
#endif /* IPACM_EvtDispatcher_H */

View file

@ -1,88 +0,0 @@
/*
Copyright (c) 2013-2019, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_Filtering.h
@brief
This file implements the IPACM filtering definitions
@Author
Skylar Chang
*/
#ifndef IPACM_FILTERING_H
#define IPACM_FILTERING_H
#include <stdint.h>
#include <linux/msm_ipa.h>
#include <IPACM_Defs.h>
#include <linux/rmnet_ipa_fd_ioctl.h>
#define IPA_PCIE_MODEM_RULE_ID_START 69
#define IPA_PCIE_MODEM_RULE_ID_MAX 1000
class IPACM_Filtering
{
public:
IPACM_Filtering();
~IPACM_Filtering();
bool AddFilteringRule(struct ipa_ioc_add_flt_rule const *ruleTable);
bool AddFilteringRuleAfter(struct ipa_ioc_add_flt_rule_after const *ruleTable);
#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO
bool AddFilteringRule_hw_index(struct ipa_ioc_add_flt_rule *ruleTable, int hw_counter_index);
bool AddFilteringRuleAfter_hw_index(struct ipa_ioc_add_flt_rule_after *ruleTable, int hw_counter_index);
#endif //IPA_IOCTL_SET_FNR_COUNTER_INFO
bool DeleteFilteringRule(struct ipa_ioc_del_flt_rule *ruleTable);
bool Commit(enum ipa_ip_type ip);
bool Reset(enum ipa_ip_type ip);
bool DeviceNodeIsOpened();
bool DeleteFilteringHdls(uint32_t *flt_rule_hdls,
ipa_ip_type ip,
uint8_t num_rules);
bool AddWanDLFilteringRule(struct ipa_ioc_add_flt_rule const *rule_table_v4, struct ipa_ioc_add_flt_rule const * rule_table_v6, uint8_t mux_id);
bool AddOffloadFilteringRule(struct ipa_ioc_add_flt_rule *flt_rule_tbl, uint8_t mux_id, uint8_t default_path);
bool DelOffloadFilteringRule(struct ipa_ioc_del_flt_rule const *flt_rule_tbl);
bool SendFilteringRuleIndex(struct ipa_fltr_installed_notif_req_msg_v01* table);
bool ModifyFilteringRule(struct ipa_ioc_mdfy_flt_rule* ruleTable);
ipa_filter_action_enum_v01 GetQmiFilterAction(ipa_flt_action action);
private:
static const char *DEVICE_NAME;
int fd; /* File descriptor of the IPA device node /dev/ipa */
int total_num_offload_rules;
int pcie_modem_rule_id;
bool pcie_modem_rule_id_in_use[IPA_PCIE_MODEM_RULE_ID_MAX];
};
#endif //IPACM_FILTERING_H

View file

@ -1,70 +0,0 @@
/*
Copyright (c) 2013, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* IPACM_Header.h
*
* Created on: Jun 20, 2012
* Author: tatias
*/
//////////////////////////////////////////////////////////////////////////////////
#ifndef IPACM_HEADER_H
#define IPACM_HEADER_H
#include <stdint.h>
#include "linux/msm_ipa.h"
//////////////////////////////////////////////////////////////////////////////////
class IPACM_Header
{
private:
int m_fd;
public:
bool AddHeader(struct ipa_ioc_add_hdr *pHeaderTable);
bool DeleteHeader(struct ipa_ioc_del_hdr *pHeaderTable);
bool GetHeaderHandle(struct ipa_ioc_get_hdr *pHeaderStruct);
bool CopyHeader(struct ipa_ioc_copy_hdr *pCopyHeaderStruct);
bool Commit();
bool Reset();
bool DeleteHeaderHdl(uint32_t hdr_hdl);
bool AddHeaderProcCtx(struct ipa_ioc_add_hdr_proc_ctx* pHeader);
bool DeleteHeaderProcCtx(uint32_t hdl);
IPACM_Header();
~IPACM_Header();
bool DeviceNodeIsOpened();
};
#endif

View file

@ -1,158 +0,0 @@
/*
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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_iface.h
@brief
This file implements the basis Iface definitions.
@Author
Skylar Chang
*/
#ifndef IPACM_IFACE_H
#define IPACM_IFACE_H
#include <stdio.h>
#include <IPACM_CmdQueue.h>
#include <linux/msm_ipa.h>
#include "IPACM_Routing.h"
#include "IPACM_Filtering.h"
#include "IPACM_Header.h"
#include "IPACM_EvtDispatcher.h"
#include "IPACM_Xml.h"
#include "IPACM_Log.h"
#include "IPACM_Config.h"
#include "IPACM_Defs.h"
#include <string.h>
/* current support 2 ipv6-address*/
#define MAX_DEFAULT_v4_ROUTE_RULES 1
#define MAX_DEFAULT_v6_ROUTE_RULES 2
#define IPV4_DEFAULT_FILTERTING_RULES 3
#ifdef FEATURE_IPA_ANDROID
#define IPV6_DEFAULT_FILTERTING_RULES 5
#else
#define IPV6_DEFAULT_FILTERTING_RULES 4
#endif
#define IPV6_DEFAULT_LAN_FILTERTING_RULES 1
#define IPV6_NUM_ADDR 3
#define MAX_SOFTWAREROUTING_FILTERTING_RULES 2
#define INVALID_IFACE -1
/* iface */
class IPACM_Iface :public IPACM_Listener
{
public:
/* Static class for reading IPACM configuration from XML file*/
static IPACM_Config *ipacmcfg;
/* IPACM interface id */
int ipa_if_num;
/* IPACM interface category */
ipacm_iface_type ipa_if_cate;
/* IPACM interface name */
char dev_name[IF_NAME_LEN];
/* IPACM interface iptype v4, v6 or both */
ipa_ip_type ip_type;
/* IPACM interface v6 ip-address*/
uint32_t ipv6_addr[MAX_DEFAULT_v6_ROUTE_RULES][4];
uint32_t software_routing_fl_rule_hdl[MAX_SOFTWAREROUTING_FILTERTING_RULES];
bool softwarerouting_act;
/* IPACM number of default route rules for ipv6*/
uint32_t num_dft_rt_v6;
uint32_t dft_v4fl_rule_hdl[IPV4_DEFAULT_FILTERTING_RULES];
uint32_t dft_v6fl_rule_hdl[IPV6_DEFAULT_FILTERTING_RULES + IPV6_DEFAULT_LAN_FILTERTING_RULES];
/* create additional set of v6 RT-rules in Wanv6RT table*/
uint32_t dft_rt_rule_hdl[MAX_DEFAULT_v4_ROUTE_RULES+2*MAX_DEFAULT_v6_ROUTE_RULES];
ipa_ioc_query_intf *iface_query;
ipa_ioc_query_intf_tx_props *tx_prop;
ipa_ioc_query_intf_rx_props *rx_prop;
virtual int handle_down_evt() = 0;
virtual int handle_addr_evt(ipacm_event_data_addr *data) = 0;
IPACM_Iface(int iface_index);
virtual void event_callback(ipa_cm_event_id event,
void *data) = 0;
/* Query ipa_interface_index by given linux interface_index */
static int iface_ipa_index_query(int interface_index);
/* Query ipa_interface ipv4_addr by given linux interface_index */
static void iface_addr_query(int interface_index);
/*Query the IPA endpoint property */
int query_iface_property(void);
/*Configure the initial filter rules */
virtual int init_fl_rule(ipa_ip_type iptype);
/* Change IP Type.*/
void config_ip_type(ipa_ip_type iptype);
/* Get interface index */
virtual int ipa_get_if_index(char * if_name, int * if_index);
static IPACM_Routing m_routing;
static IPACM_Filtering m_filtering;
static IPACM_Header m_header;
void change_to_network_order(ipa_ip_type iptype, ipa_rule_attrib* attrib);
/* software routing enable */
virtual int handle_software_routing_enable(bool mhip);
/* software routing disable */
virtual int handle_software_routing_disable(bool mhip);
void delete_iface(void);
bool is_global_ipv6_addr(uint32_t* ipv6_addr);
private:
static const char *DEVICE_NAME;
};
#endif /* IPACM_IFACE_H */

View file

@ -1,90 +0,0 @@
/*
Copyright (c) 2013-2016, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_IfaceManager.h
@brief
This file implements the IPAM iface_manager definitions
@Author
Skylar Chang
*/
#ifndef IPACM_IFACEMANAGER_H
#define IPACM_IFACEMANAGER_H
#include <stdio.h>
#include <IPACM_CmdQueue.h>
#include "IPACM_Routing.h"
#include "IPACM_Filtering.h"
#include "IPACM_Listener.h"
#include "IPACM_Iface.h"
#define IPA_INSTANCE_NOT_FOUND 0
#define IPA_INSTANCE_FOUND 1
/* queue */
typedef struct _iface_instances
{
/* Linux interface id */
int ipa_if_index;
IPACM_Listener *obj;
_iface_instances *next;
} iface_instances;
class IPACM_IfaceManager : public IPACM_Listener
{
public:
IPACM_IfaceManager();
void event_callback(ipa_cm_event_id event,
void *data);
/* api for all iface instances to de-register instances */
static int deregistr(IPACM_Listener *param);
private:
int create_iface_instance(ipacm_ifacemgr_data *);
/* api to register instances */
int registr(int ipa_if_index, IPACM_Listener *obj);
int SearchInstance(int ipa_if_index);
static iface_instances *head;
};
#endif /* IPACM_IFACEMANAGER_H */

View file

@ -1,473 +0,0 @@
/*
Copyright (c) 2013-2019, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_Lan.h
@brief
This file implements the LAN iface definitions
@Author
Skylar Chang
*/
#ifndef IPACM_LAN_H
#define IPACM_LAN_H
#include <stdio.h>
#include <linux/msm_ipa.h>
#include "IPACM_CmdQueue.h"
#include "IPACM_Iface.h"
#include "IPACM_Routing.h"
#include "IPACM_Filtering.h"
#include "IPACM_Config.h"
#include "IPACM_Conntrack_NATApp.h"
#include "IPACM_Wan.h"
#define IPA_WAN_DEFAULT_FILTER_RULE_HANDLES 1
#define IPA_PRIV_SUBNET_FILTER_RULE_HANDLES 3
#define IPA_NUM_ODU_ROUTE_RULES 2
#define MAX_WAN_UL_FILTER_RULES MAX_NUM_EXT_PROPS
#define NUM_IPV4_ICMP_FLT_RULE 1
#define NUM_IPV6_ICMP_FLT_RULE 1
/* ndc bandwidth ipatetherstats <ifaceIn> <ifaceOut> */
/* <in->out_bytes> <in->out_pkts> <out->in_bytes> <out->in_pkts */
#define PIPE_STATS "%s %s %llu %llu %llu %llu"
#define IPA_PIPE_STATS_FILE_NAME "/data/misc/ipa/tether_stats"
/* store each lan-iface unicast routing rule and its handler*/
struct ipa_lan_rt_rule
{
ipa_ip_type ip;
uint32_t v4_addr;
uint32_t v4_addr_mask;
uint32_t v6_addr[4];
uint32_t rt_rule_hdl[0];
};
/* Support multiple eth client */
typedef struct _eth_client_rt_hdl
{
uint32_t eth_rt_rule_hdl_v4;
uint32_t eth_rt_rule_hdl_v6[IPV6_NUM_ADDR];
uint32_t eth_rt_rule_hdl_v6_wan[IPV6_NUM_ADDR];
}eth_client_rt_hdl;
typedef struct _ipa_eth_client
{
uint8_t mac[IPA_MAC_ADDR_SIZE];
uint32_t v4_addr;
uint32_t v6_addr[IPV6_NUM_ADDR][4];
uint32_t hdr_hdl_v4;
uint32_t hdr_hdl_v6;
bool route_rule_set_v4;
int route_rule_set_v6;
bool ipv4_set;
int ipv6_set;
bool ipv4_header_set;
bool ipv6_header_set;
/* used for pcie-modem */
uint32_t v6_rt_rule_id[IPV6_NUM_ADDR];
eth_client_rt_hdl eth_rt_hdl[0]; /* depends on number of tx properties */
}ipa_eth_client;
/* lan iface */
class IPACM_Lan : public IPACM_Iface
{
public:
IPACM_Lan(int iface_index);
~IPACM_Lan();
/* store lan's wan-up filter rule handlers */
uint32_t lan_wan_fl_rule_hdl[IPA_WAN_DEFAULT_FILTER_RULE_HANDLES];
/* store private-subnet filter rule handlers */
uint32_t private_fl_rule_hdl[IPA_MAX_PRIVATE_SUBNET_ENTRIES + IPA_MAX_MTU_ENTRIES];
/* LAN-iface's callback function */
void event_callback(ipa_cm_event_id event, void *data);
virtual int handle_wan_up(ipa_ip_type ip_type);
/* configure filter rule for wan_up event*/
virtual int handle_wan_up_ex(ipacm_ext_prop* ext_prop, ipa_ip_type iptype, uint8_t xlat_mux_id);
/* delete filter rule for wan_down event*/
virtual int handle_wan_down(ipacm_wan_iface_type backhaul_mode);
/* delete filter rule for wan_down event*/
virtual int handle_wan_down_v6(ipacm_wan_iface_type backhaul_mode);
/* configure private subnet filter rules*/
virtual int handle_private_subnet(ipa_ip_type iptype);
/* handle new_address event*/
int handle_addr_evt(ipacm_event_data_addr *data);
int handle_addr_evt_odu_bridge(ipacm_event_data_addr* data);
int handle_del_ipv6_addr(ipacm_event_data_all *data);
static bool odu_up;
/* install UL filter rule from Q6 */
virtual int handle_uplink_filter_rule(ipacm_ext_prop* prop, ipa_ip_type iptype, uint8_t xlat_mux_id);
int handle_cradle_wan_mode_switch(bool is_wan_bridge_mode);
int install_ipv4_icmp_flt_rule();
/* add header processing context and return handle to lan2lan controller */
int eth_bridge_add_hdr_proc_ctx(ipa_hdr_l2_type peer_l2_hdr_type, uint32_t *hdl);
/* add routing rule and return handle to lan2lan controller */
int eth_bridge_add_rt_rule(uint8_t *mac, char *rt_tbl_name, uint32_t hdr_proc_ctx_hdl,
ipa_hdr_l2_type peer_l2_hdr_type, ipa_ip_type iptype, uint32_t *rt_rule_hdl, int *rt_rule_count, int ep);
/* modify routing rule*/
int eth_bridge_modify_rt_rule(uint8_t *mac, uint32_t hdr_proc_ctx_hdl,
ipa_hdr_l2_type peer_l2_hdr_type, ipa_ip_type iptype, uint32_t *rt_rule_hdl, int rt_rule_count);
/* add filtering rule and return handle to lan2lan controller */
int eth_bridge_add_flt_rule(uint8_t *mac, uint32_t rt_tbl_hdl, ipa_ip_type iptype, uint32_t *flt_rule_hdl);
/* delete filtering rule */
int eth_bridge_del_flt_rule(uint32_t flt_rule_hdl, ipa_ip_type iptype);
/* delete routing rule */
int eth_bridge_del_rt_rule(uint32_t rt_rule_hdl, ipa_ip_type iptype);
/* delete header processing context */
int eth_bridge_del_hdr_proc_ctx(uint32_t hdr_proc_ctx_hdl);
#ifdef FEATURE_L2TP
/* add l2tp rt rule for l2tp client */
int add_l2tp_rt_rule(ipa_ip_type iptype, uint8_t *dst_mac, ipa_hdr_l2_type peer_l2_hdr_type,
uint32_t l2tp_session_id, uint32_t vlan_id, uint8_t *vlan_client_mac, uint32_t *vlan_iface_ipv6_addr,
uint32_t *vlan_client_ipv6_addr, uint32_t *first_pass_hdr_hdl, uint32_t *first_pass_hdr_proc_ctx_hdl,
uint32_t *second_pass_hdr_hdl, int *num_rt_hdl, uint32_t *first_pass_rt_rule_hdl, uint32_t *second_pass_rt_rule_hdl);
/* delete l2tp rt rule for l2tp client */
int del_l2tp_rt_rule(ipa_ip_type iptype, uint32_t first_pass_hdr_hdl, uint32_t first_pass_hdr_proc_ctx_hdl,
uint32_t second_pass_hdr_hdl, int num_rt_hdl, uint32_t *first_pass_rt_rule_hdl, uint32_t *second_pass_rt_rule_hdl);
/* add l2tp rt rule for non l2tp client */
int add_l2tp_rt_rule(ipa_ip_type iptype, uint8_t *dst_mac, uint32_t *hdr_proc_ctx_hdl,
int *num_rt_hdl, uint32_t *rt_rule_hdl);
/* delete l2tp rt rule for non l2tp client */
int del_l2tp_rt_rule(ipa_ip_type iptype, int num_rt_hdl, uint32_t *rt_rule_hdl);
/* add l2tp flt rule on l2tp interface */
int add_l2tp_flt_rule(uint8_t *dst_mac, uint32_t *flt_rule_hdl);
/* delete l2tp flt rule on l2tp interface */
int del_l2tp_flt_rule(uint32_t flt_rule_hdl);
/* add l2tp flt rule on non l2tp interface */
int add_l2tp_flt_rule(ipa_ip_type iptype, uint8_t *dst_mac, uint32_t *vlan_client_ipv6_addr,
uint32_t *first_pass_flt_rule_hdl, uint32_t *second_pass_flt_rule_hdl);
/* delete l2tp flt rule on non l2tp interface */
int del_l2tp_flt_rule(ipa_ip_type iptype, uint32_t first_pass_flt_rule_hdl, uint32_t second_pass_flt_rule_hdl);
#endif
protected:
int each_client_rt_rule_count[IPA_IP_MAX];
uint32_t eth_bridge_flt_rule_offset[IPA_IP_MAX];
/* mac address has to be provided for client related events */
void eth_bridge_post_event(ipa_cm_event_id evt, ipa_ip_type iptype, uint8_t *mac,
uint32_t *ipv6_addr, char *iface_name, int ep);
#ifdef FEATURE_L2TP
/* check if the event is associated with vlan interface */
bool is_vlan_event(char *event_iface_name);
/* check if the event is associated with l2tp interface */
bool is_l2tp_event(char *event_iface_name);
/* check if the IPv6 address is unique local address */
bool is_unique_local_ipv6_addr(uint32_t *ipv6_addr);
#endif
virtual int add_dummy_private_subnet_flt_rule(ipa_ip_type iptype);
int handle_private_subnet_android(ipa_ip_type iptype);
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();
int install_ipv6_icmp_flt_rule();
void post_del_self_evt();
/* handle tethering stats */
int handle_tethering_stats_event(ipa_get_data_stats_resp_msg_v01 *data);
/* handle tethering client */
int handle_tethering_client(bool reset, ipacm_client_enum ipa_client);
/* add tcp syn flt rule */
int add_tcp_syn_flt_rule(ipa_ip_type iptype);
/* add tcp syn flt rule for l2tp interface*/
int add_tcp_syn_flt_rule_l2tp(ipa_ip_type inner_ip_type);
/* store ipv4 UL filter rule handlers from Q6*/
uint32_t wan_ul_fl_rule_hdl_v4[MAX_WAN_UL_FILTER_RULES];
/* store ipv6 UL filter rule handlers from Q6*/
uint32_t wan_ul_fl_rule_hdl_v6[MAX_WAN_UL_FILTER_RULES];
uint32_t ipv4_icmp_flt_rule_hdl[NUM_IPV4_ICMP_FLT_RULE];
uint32_t ipv6_prefix_flt_rule_hdl[NUM_IPV6_PREFIX_FLT_RULE + NUM_IPV6_PREFIX_MTU_RULE];
uint32_t ipv6_icmp_flt_rule_hdl[NUM_IPV6_ICMP_FLT_RULE];
int num_wan_ul_fl_rule_v4;
int num_wan_ul_fl_rule_v6;
bool is_active;
bool modem_ul_v4_set;
uint8_t v4_mux_id;
bool modem_ul_v6_set;
uint8_t v6_mux_id;
bool sta_ul_v4_set;
bool sta_ul_v6_set;
uint32_t if_ipv4_subnet;
uint32_t ipv6_prefix[2];
bool is_upstream_set[IPA_IP_MAX];
bool is_downstream_set[IPA_IP_MAX];
_ipacm_offload_prefix prefix[IPA_IP_MAX];
uint32_t tcp_syn_flt_rule_hdl[IPA_IP_MAX];
private:
int set_client_pipe(enum ipa_client_type client, uint32_t *pipe);
int set_tether_client(wan_ioctl_set_tether_client_pipe *tether_client);
int set_tether_client_wigig(wan_ioctl_set_tether_client_pipe *tether_client);
/* get hdr proc ctx type given source and destination l2 hdr type */
ipa_hdr_proc_type eth_bridge_get_hdr_proc_type(ipa_hdr_l2_type t1, ipa_hdr_l2_type t2);
/* get partial header (header template of hdr proc ctx) */
int eth_bridge_get_hdr_template_hdl(uint32_t* hdr_hdl);
/* dynamically allocate lan iface's unicast routing rule structure */
bool is_mode_switch; /* indicate mode switch, need post internal up event */
int eth_client_len;
ipa_eth_client *eth_client;
int header_name_count;
uint32_t num_eth_client;
NatApp *Nat_App;
int ipv6_set;
uint32_t ODU_hdr_hdl_v4, ODU_hdr_hdl_v6;
uint32_t *odu_route_rule_v4_hdl;
uint32_t *odu_route_rule_v6_hdl;
bool ipv4_header_set;
bool ipv6_header_set;
inline ipa_eth_client* get_client_memptr(ipa_eth_client *param, int cnt)
{
char *ret = ((char *)param) + (eth_client_len * cnt);
return (ipa_eth_client *)ret;
}
inline int get_eth_client_index(uint8_t *mac_addr)
{
int cnt;
int num_eth_client_tmp = num_eth_client;
IPACMDBG_H("Passed 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]);
for(cnt = 0; cnt < num_eth_client_tmp; cnt++)
{
IPACMDBG_H("stored MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
get_client_memptr(eth_client, cnt)->mac[0],
get_client_memptr(eth_client, cnt)->mac[1],
get_client_memptr(eth_client, cnt)->mac[2],
get_client_memptr(eth_client, cnt)->mac[3],
get_client_memptr(eth_client, cnt)->mac[4],
get_client_memptr(eth_client, cnt)->mac[5]);
if(memcmp(get_client_memptr(eth_client, cnt)->mac,
mac_addr,
sizeof(get_client_memptr(eth_client, cnt)->mac)) == 0)
{
IPACMDBG_H("Matched client index: %d\n", cnt);
return cnt;
}
}
return IPACM_INVALID_INDEX;
}
inline int delete_eth_rtrules(int clt_indx, ipa_ip_type iptype)
{
uint32_t tx_index;
uint32_t rt_hdl;
int num_v6;
if(iptype == IPA_IP_v4)
{
for(tx_index = 0; tx_index < iface_query->num_tx_props; tx_index++)
{
if((tx_prop->tx[tx_index].ip == IPA_IP_v4) && (get_client_memptr(eth_client, clt_indx)->route_rule_set_v4==true)) /* for ipv4 */
{
IPACMDBG_H("Delete client index %d ipv4 RT-rules for tx:%d\n",clt_indx,tx_index);
rt_hdl = get_client_memptr(eth_client, clt_indx)->eth_rt_hdl[tx_index].eth_rt_rule_hdl_v4;
if(m_routing.DeleteRoutingHdl(rt_hdl, IPA_IP_v4) == false)
{
return IPACM_FAILURE;
}
}
} /* end of for loop */
/* clean the ipv4 RT rules for eth-client:clt_indx */
if(get_client_memptr(eth_client, clt_indx)->route_rule_set_v4==true) /* for ipv4 */
{
get_client_memptr(eth_client, clt_indx)->route_rule_set_v4 = false;
}
}
if(iptype == IPA_IP_v6)
{
for(tx_index = 0; tx_index < iface_query->num_tx_props; tx_index++)
{
if((tx_prop->tx[tx_index].ip == IPA_IP_v6) && (get_client_memptr(eth_client, clt_indx)->route_rule_set_v6 != 0)) /* for ipv6 */
{
for(num_v6 =0;num_v6 < get_client_memptr(eth_client, clt_indx)->route_rule_set_v6;num_v6++)
{
/* send client-v6 delete to pcie modem only with global ipv6 with tx_index = 1 one time*/
if(is_global_ipv6_addr(get_client_memptr(eth_client, clt_indx)->v6_addr[num_v6]) && (IPACM_Wan::backhaul_mode == Q6_MHI_WAN)
&& (get_client_memptr(eth_client, clt_indx)->v6_rt_rule_id[num_v6] > 0))
{
IPACMDBG_H("Delete client index %d ipv6 RT-rules for %d-st ipv6 for rule-id:%d\n", clt_indx,num_v6,
get_client_memptr(eth_client, clt_indx)->v6_rt_rule_id[num_v6]);
if (del_connection(clt_indx, num_v6))
{
IPACMERR("PCIE filter rule deletion failed! (%d-client) %d v6-entry\n",clt_indx, num_v6);
}
}
IPACMDBG_H("Delete client index %d ipv6 RT-rules for %d-st ipv6 for tx:%d\n", clt_indx,num_v6,tx_index);
rt_hdl = get_client_memptr(eth_client, clt_indx)->eth_rt_hdl[tx_index].eth_rt_rule_hdl_v6[num_v6];
if(m_routing.DeleteRoutingHdl(rt_hdl, IPA_IP_v6) == false)
{
return IPACM_FAILURE;
}
rt_hdl = get_client_memptr(eth_client, clt_indx)->eth_rt_hdl[tx_index].eth_rt_rule_hdl_v6_wan[num_v6];
if(m_routing.DeleteRoutingHdl(rt_hdl, IPA_IP_v6) == false)
{
return IPACM_FAILURE;
}
}
}
} /* end of for loop */
/* clean the ipv6 RT rules for eth-client:clt_indx */
if(get_client_memptr(eth_client, clt_indx)->route_rule_set_v6 != 0) /* for ipv6 */
{
get_client_memptr(eth_client, clt_indx)->route_rule_set_v6 = 0;
}
}
return IPACM_SUCCESS;
}
/* handle eth client initial, construct full headers (tx property) */
int handle_eth_hdr_init(uint8_t *mac_addr);
/* handle eth client ip-address */
int handle_eth_client_ipaddr(ipacm_event_data_all *data);
/* handle eth client routing rule*/
int handle_eth_client_route_rule(uint8_t *mac_addr, ipa_ip_type iptype);
/*handle eth client del mode*/
int handle_eth_client_down_evt(uint8_t *mac_addr);
/* handle odu client initial, construct full headers (tx property) */
int handle_odu_hdr_init(uint8_t *mac_addr);
/* handle odu default route rule configuration */
int handle_odu_route_add();
/* handle odu default route rule deletion */
int handle_odu_route_del();
/*handle lan iface down event*/
int handle_down_evt();
/*handle reset usb-client rt-rules */
int handle_lan_client_reset_rt(ipa_ip_type iptype);
/* for pcie modem */
virtual int add_connection(int client_index, int v6_num);
virtual int del_connection(int client_index, int v6_num);
int construct_mtu_rule(struct ipa_flt_rule *rule, enum ipa_ip_type iptype, uint16_t mtu);
};
#endif /* IPACM_LAN_H */

View file

@ -1,282 +0,0 @@
/*
Copyright (c) 2014-2019, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* IPACM_LanToLan.h
*
* Created on: Mar 4th, 2014
* Author: Shihuan Liu
*/
#ifndef IPACM_LANTOLAN_H
#define IPACM_LANTOLAN_H
#include <stdint.h>
#include "linux/msm_ipa.h"
#include "IPACM_Iface.h"
#include "IPACM_Defs.h"
#include "IPACM_Lan.h"
#ifdef FEATURE_IPA_ANDROID
#include <libxml/list.h>
#endif /* defined(FEATURE_IPA_ANDROID) */
#include <list>
#define MAX_NUM_CACHED_CLIENT_ADD_EVENT 10
#define MAX_NUM_IFACE 10
#define MAX_NUM_CLIENT 16
struct vlan_iface_info
{
char vlan_iface_name[IPA_RESOURCE_NAME_MAX];
uint8_t vlan_id;
uint32_t vlan_iface_ipv6_addr[4];
uint8_t vlan_client_mac[6];
uint32_t vlan_client_ipv6_addr[4];
};
struct l2tp_vlan_mapping_info
{
/* the following are l2tp iface info (name, session id) */
char l2tp_iface_name[IPA_RESOURCE_NAME_MAX];
uint8_t l2tp_session_id;
/* the following are mdm vlan iface info (name, vlan id, ipv6 addr) */
char vlan_iface_name[IPA_RESOURCE_NAME_MAX];
uint8_t vlan_id;
uint32_t vlan_iface_ipv6_addr[4];
/* the following are MIB3 vlan client info (mac, ipv6 addr) */
uint8_t vlan_client_mac[6];
uint32_t vlan_client_ipv6_addr[4];
/* the following is MIB3 l2tp client info (mac) */
uint8_t l2tp_client_mac[6];
};
struct rt_rule_info
{
int num_hdl[IPA_IP_MAX]; /* one client may need more than one routing rules on the same routing table depending on tx_prop */
uint32_t rule_hdl[IPA_IP_MAX][MAX_NUM_PROP];
};
struct l2tp_rt_rule_info
{
uint32_t first_pass_hdr_hdl; /* first pass hdr template (IPv4 and IPv6 use the same hdr template) */
uint32_t first_pass_hdr_proc_ctx_hdl[IPA_IP_MAX]; /* first pass hdr proc ctx */
uint32_t second_pass_hdr_hdl; /* second pass hdr template (IPv4 and IPv6 use the same hdr template) */
int num_rt_hdl[IPA_IP_MAX]; /* number of TX properties for IPv4 and IPv6 respectively */
uint32_t first_pass_rt_rule_hdl[IPA_IP_MAX][MAX_NUM_PROP]; /* first pass routing rule */
uint32_t second_pass_rt_rule_hdl[MAX_NUM_PROP]; /*second pass routing rule (only ipv6 rt rule is needed) */
};
struct client_info
{
uint8_t mac_addr[6];
rt_rule_info inter_iface_rt_rule_hdl[IPA_HDR_L2_MAX]; /* routing rule handles of inter interface communication based on source l2 header type */
rt_rule_info intra_iface_rt_rule_hdl; /* routing rule handles of inter interface communication */
bool is_l2tp_client;
l2tp_vlan_mapping_info *mapping_info;
l2tp_rt_rule_info l2tp_rt_rule_hdl[IPA_HDR_L2_MAX];
int ep;
};
struct flt_rule_info
{
client_info *p_client;
uint32_t flt_rule_hdl[IPA_IP_MAX];
uint32_t l2tp_first_pass_flt_rule_hdl[IPA_IP_MAX]; /* L2TP filtering rules are destination MAC based */
uint32_t l2tp_second_pass_flt_rule_hdl;
};
struct peer_iface_info
{
class IPACM_LanToLan_Iface *peer;
char rt_tbl_name_for_rt[IPA_IP_MAX][IPA_RESOURCE_NAME_MAX];
char rt_tbl_name_for_flt[IPA_IP_MAX][IPA_RESOURCE_NAME_MAX];
list<flt_rule_info> flt_rule;
};
class IPACM_LanToLan_Iface
{
public:
IPACM_LanToLan_Iface(IPACM_Lan *p_iface);
~IPACM_LanToLan_Iface();
void add_client_rt_rule_for_new_iface();
void add_all_inter_interface_client_flt_rule(ipa_ip_type iptype);
void add_all_intra_interface_client_flt_rule(ipa_ip_type iptype);
void handle_down_event();
void handle_wlan_scc_mcc_switch();
void handle_intra_interface_info();
void handle_new_iface_up(char rt_tbl_name_for_flt[][IPA_RESOURCE_NAME_MAX], char rt_tbl_name_for_rt[][IPA_RESOURCE_NAME_MAX],
IPACM_LanToLan_Iface *peer_iface);
void handle_client_add(uint8_t *mac, bool is_l2tp_client, l2tp_vlan_mapping_info *mapping_info, int ep);
void handle_client_del(uint8_t *mac);
void print_data_structure_info();
IPACM_Lan* get_iface_pointer();
bool get_m_is_ip_addr_assigned(ipa_ip_type iptype);
void set_m_is_ip_addr_assigned(ipa_ip_type iptype, bool value);
bool get_m_support_inter_iface_offload();
bool get_m_support_intra_iface_offload();
void increment_ref_cnt_peer_l2_hdr_type(ipa_hdr_l2_type peer_l2_type);
void decrement_ref_cnt_peer_l2_hdr_type(ipa_hdr_l2_type peer_l2_type);
#ifdef FEATURE_L2TP
void switch_to_l2tp_iface();
bool set_l2tp_iface(char *vlan_iface_name);
bool is_l2tp_iface();
void handle_l2tp_enable();
void handle_l2tp_disable();
#endif
private:
IPACM_Lan *m_p_iface;
bool m_is_ip_addr_assigned[IPA_IP_MAX];
bool m_support_inter_iface_offload;
bool m_support_intra_iface_offload;
bool m_is_l2tp_iface;
int ref_cnt_peer_l2_hdr_type[IPA_HDR_L2_MAX]; /* reference count of l2 header type of peer interfaces */
uint32_t hdr_proc_ctx_for_inter_interface[IPA_HDR_L2_MAX];
uint32_t hdr_proc_ctx_for_intra_interface;
uint32_t hdr_proc_ctx_for_l2tp; /* uc needs to remove 62 bytes IPv6 + L2TP + inner Ethernet header */
list<client_info> m_client_info; /* client list */
list<peer_iface_info> m_peer_iface_info; /* peer information list */
/* The following members are for intra-interface communication*/
peer_iface_info m_intra_interface_info;
void add_one_client_flt_rule(IPACM_LanToLan_Iface *peer_iface, client_info *client);
void add_client_flt_rule(peer_iface_info *peer, client_info *client, ipa_ip_type iptype);
void del_one_client_flt_rule(IPACM_LanToLan_Iface *peer_iface, client_info *client);
void del_client_flt_rule(peer_iface_info *peer, client_info *client);
void add_client_rt_rule(peer_iface_info *peer, client_info *client);
void del_client_rt_rule(peer_iface_info *peer, client_info *client);
void add_l2tp_client_rt_rule(peer_iface_info *peer, client_info *client);
void clear_all_flt_rule_for_one_peer_iface(peer_iface_info *peer);
void clear_all_rt_rule_for_one_peer_iface(peer_iface_info *peer);
void add_hdr_proc_ctx(ipa_hdr_l2_type peer_l2_type);
void del_hdr_proc_ctx(ipa_hdr_l2_type peer_l2_type);
void print_peer_info(peer_iface_info *peer_info);
};
class IPACM_LanToLan : public IPACM_Listener
{
public:
static IPACM_LanToLan* p_instance;
static IPACM_LanToLan* get_instance();
#ifdef FEATURE_L2TP
bool has_l2tp_iface();
#endif
private:
IPACM_LanToLan();
~IPACM_LanToLan();
bool m_has_l2tp_iface;
list<class IPACM_LanToLan_Iface> m_iface;
list<ipacm_event_eth_bridge> m_cached_client_add_event;
list<vlan_iface_info> m_vlan_iface;
list<l2tp_vlan_mapping_info> m_l2tp_vlan_mapping;
void handle_iface_up(ipacm_event_eth_bridge *data);
void handle_iface_down(ipacm_event_eth_bridge *data);
void handle_client_add(ipacm_event_eth_bridge *data);
void handle_client_del(ipacm_event_eth_bridge *data);
void handle_wlan_scc_mcc_switch(ipacm_event_eth_bridge *data);
#ifdef FEATURE_L2TP
void handle_add_vlan_iface(ipa_ioc_vlan_iface_info *data);
void handle_del_vlan_iface(ipa_ioc_vlan_iface_info *data);
void handle_add_l2tp_vlan_mapping(ipa_ioc_l2tp_vlan_mapping_info *data);
void handle_del_l2tp_vlan_mapping(ipa_ioc_l2tp_vlan_mapping_info *data);
void handle_vlan_client_info(ipacm_event_data_all *data);
void handle_vlan_iface_info(ipacm_event_data_all *data);
#endif
void handle_new_iface_up(IPACM_LanToLan_Iface *new_iface, IPACM_LanToLan_Iface *exist_iface);
void event_callback(ipa_cm_event_id event, void* param);
void handle_cached_client_add_event(IPACM_Lan *p_iface);
void clear_cached_client_add_event(IPACM_Lan *p_iface);
void print_data_structure_info();
};
#endif

View file

@ -1,54 +0,0 @@
/*
Copyright (c) 2013, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_Listener.h
@brief
This file implements the abstract class notifier.
@Author
Skylar Chang
*/
#ifndef IPACM_LISTENER_H
#define IPACM_LISTENER_H
#include "IPACM_Defs.h"
#include "IPACM_CmdQueue.h"
/* abstract class notifier */
class IPACM_Listener
{
public:
virtual void event_callback(ipa_cm_event_id event, void *data) = 0;
virtual ~IPACM_Listener(void) {};
};
#endif /* IPACM_LISTENER_H */

View file

@ -1,102 +0,0 @@
/*
Copyright (c) 2013, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_log.h
@brief
This file implements the IPAM log functionality.
@Author
Skylar Chang
*/
#ifndef IPACM_LOG_H
#define IPACM_LOG_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdio.h>
#include <string.h>
#include <syslog.h>
#define MAX_BUF_LEN 256
#ifdef FEATURE_IPA_ANDROID
#define IPACMLOG_FILE "/dev/socket/ipacm_log_file"
#else/* defined(FEATURE_IPA_ANDROID) */
#define IPACMLOG_FILE "/etc/ipacm_log_file"
#endif /* defined(NOT FEATURE_IPA_ANDROID)*/
typedef struct ipacm_log_buffer_s {
char user_data[MAX_BUF_LEN];
} ipacm_log_buffer_t;
void ipacm_log_send( void * user_data);
static char buffer_send[MAX_BUF_LEN];
static char dmesg_cmd[MAX_BUF_LEN];
#define IPACMDBG_DMESG(fmt, ...) memset(buffer_send, 0, MAX_BUF_LEN);\
snprintf(buffer_send,MAX_BUF_LEN,"%s:%d %s: " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);\
ipacm_log_send (buffer_send);\
printf("%s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \
memset(dmesg_cmd, 0, MAX_BUF_LEN);\
snprintf(dmesg_cmd, MAX_BUF_LEN, "echo %s > /dev/kmsg", buffer_send);\
system(dmesg_cmd);
#ifdef DEBUG
#define PERROR(fmt) memset(buffer_send, 0, MAX_BUF_LEN);\
snprintf(buffer_send,MAX_BUF_LEN,"%s:%d %s()", __FILE__, __LINE__, __FUNCTION__);\
ipacm_log_send (buffer_send); \
perror(fmt);
#define IPACMERR(fmt, ...) memset(buffer_send, 0, MAX_BUF_LEN);\
snprintf(buffer_send,MAX_BUF_LEN,"ERROR: %s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);\
ipacm_log_send (buffer_send);\
printf("ERROR: %s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);
#define IPACMDBG_H(fmt, ...) memset(buffer_send, 0, MAX_BUF_LEN);\
snprintf(buffer_send,MAX_BUF_LEN,"%s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);\
ipacm_log_send (buffer_send);\
printf("%s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);
#else
#define PERROR(fmt) perror(fmt)
#define IPACMERR(fmt, ...) printf("ERR: %s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);
#define IPACMDBG_H(fmt, ...) printf("%s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);
#endif
#define IPACMDBG(fmt, ...) printf("%s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);
#define IPACMLOG(fmt, ...) printf(fmt, ##__VA_ARGS__);
#ifdef __cplusplus
}
#endif
#endif /* IPACM_LOG_H */

View file

@ -1,83 +0,0 @@
/*
Copyright (c) 2013-2017, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_Neighbor.h
@brief
This file implements the functionality of handling IPACM Neighbor events.
@Author
Skylar Chang
*/
#ifndef IPACM_NEIGHBOR_H
#define IPACM_NEIGHBOR_H
#include <stdio.h>
#include <IPACM_CmdQueue.h>
#include <linux/msm_ipa.h>
#include "IPACM_Routing.h"
#include "IPACM_Filtering.h"
#include "IPACM_Listener.h"
#include "IPACM_Iface.h"
#define IPA_MAX_NUM_NEIGHBOR_CLIENTS 100
struct ipa_neighbor_client
{
uint8_t mac_addr[6];
int iface_index;
uint32_t v4_addr;
int ipa_if_num;
/* add support for handling L2TP clients which associated with eth0 vlan interface */
char iface_name[IPA_IFACE_NAME_LEN];
};
class IPACM_Neighbor : public IPACM_Listener
{
public:
IPACM_Neighbor();
void event_callback(ipa_cm_event_id event,
void *data);
private:
int num_neighbor_client;
int circular_index;
ipa_neighbor_client neighbor_client[IPA_MAX_NUM_NEIGHBOR_CLIENTS];
};
#endif /* IPACM_NEIGHBOR_H */

View file

@ -1,225 +0,0 @@
/*
Copyright (c) 2013, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPA_Netlink.h
@brief
IPACM Netlink Messaging Implementation File
@Author
Skylar Chang
*/
#ifndef IPACM_NETLINK_H
#define IPACM_NETLINK_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <pthread.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <linux/socket.h>
#define sockaddr_storage __kernel_sockaddr_storage
#include <linux/if.h>
#include <linux/if_addr.h>
#include <linux/rtnetlink.h>
#include <linux/netlink.h>
#include <netinet/in.h>
#include "IPACM_Defs.h"
#define MAX_NUM_OF_FD 10
#define IPA_NL_MSG_MAX_LEN (2048)
/*---------------------------------------------------------------------------
Type representing enumeration of NetLink event indication messages
---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
Types representing parsed NetLink message
---------------------------------------------------------------------------*/
#define IPA_NLA_PARAM_NONE (0x0000)
#define IPA_NLA_PARAM_PREFIXADDR (0x0001)
#define IPA_NLA_PARAM_LOCALADDR (0x0002)
#define IPA_NLA_PARAM_LABELNAME (0x0004)
#define IPA_NLA_PARAM_BCASTADDR (0x0008)
#define IPA_NLA_PARAM_ACASTADDR (0x0010)
#define IPA_NLA_PARAM_MCASTADDR (0x0020)
#define IPA_NLA_PARAM_CACHEINFO (0x0080)
#define IPA_NLA_PARAM_PROTOINFO (0x0100)
#define IPA_NLA_PARAM_FLAGS (0x0200)
#define IPA_RTA_PARAM_NONE (0x0000)
#define IPA_RTA_PARAM_DST (0x0001)
#define IPA_RTA_PARAM_SRC (0x0002)
#define IPA_RTA_PARAM_GATEWAY (0x0004)
#define IPA_RTA_PARAM_IIF (0x0008)
#define IPA_RTA_PARAM_OIF (0x0010)
#define IPA_RTA_PARAM_CACHEINFO (0x0020)
#define IPA_RTA_PARAM_PRIORITY (0x0080)
#define IPA_RTA_PARAM_METRICS (0x0100)
/*---------------------------------------------------------------------------
Type representing function callback registered with a socket listener
thread for reading from a socket on receipt of an incoming message
---------------------------------------------------------------------------*/
typedef int (*ipa_sock_thrd_fd_read_f)(int fd);
typedef enum
{
IPA_INIT = 0,
IPA_LINK_UP_WAIT,
IPA_LINK_UP,
IPA_LINK_DOWN_WAIT,
IPA_LINK_DOWN
} ipa_nl_state_e;
typedef struct
{
int sk_fd;
ipa_sock_thrd_fd_read_f read_func;
} ipa_nl_sk_fd_map_info_t;
typedef struct
{
ipa_nl_sk_fd_map_info_t sk_fds[MAX_NUM_OF_FD];
fd_set fdset;
int num_fd;
int max_fd;
} ipa_nl_sk_fd_set_info_t;
typedef struct
{
int sk_fd; /* socket descriptor */
struct sockaddr_nl sk_addr_loc; /* local address of socket */
} ipa_nl_sk_info_t;
typedef struct ipa_nl_addr_s {
struct sockaddr_storage ip_addr;
unsigned int mask;
} ipa_nl_addr_t;
typedef struct ipa_nl_proto_info_s {
unsigned int param_mask;
unsigned int flags;
struct ifla_cacheinfo cache_info;
} ipa_nl_proto_info_t;
typedef struct
{
struct ifinfomsg metainfo; /* from header */
} ipa_nl_link_info_t;
typedef struct ipa_nl_addr_info_s {
struct ifaddrmsg metainfo; /* from header */
struct /* attributes */
{
unsigned int param_mask;
unsigned char label_name[IF_NAME_LEN];
struct sockaddr_storage prefix_addr;
struct sockaddr_storage local_addr;
struct sockaddr_storage bcast_addr;
struct sockaddr_storage acast_addr;
struct sockaddr_storage mcast_addr;
} attr_info;
} ipa_nl_addr_info_t;
typedef struct ipa_nl_neigh_info_s {
struct ndmsg metainfo; /* from header */
struct /* attributes */
{
unsigned int param_mask;
struct sockaddr_storage local_addr;
struct sockaddr lladdr_hwaddr;
} attr_info;
} ipa_nl_neigh_info_t;
typedef struct ipa_nl_route_info_s {
struct rtmsg metainfo; /* from header */
struct /* attributes */
{
unsigned int param_mask;
struct sockaddr_storage dst_addr;
struct sockaddr_storage src_addr;
struct sockaddr_storage gateway_addr;
struct sockaddr_storage mark_addr;
struct rta_cacheinfo cache_info;
__u32 iif_index; /* Link index */
__u32 oif_index; /* Link index */
__u32 priority;
__u32 metrics;
ipa_nl_proto_info_t proto_info;
} attr_info;
} ipa_nl_route_info_t;
#define IPA_FLOW_TYPE_INVALID (-1)
typedef struct
{
unsigned int type;
bool link_event;
/* Optional parameters */
ipa_nl_link_info_t nl_link_info;
ipa_nl_addr_info_t nl_addr_info;
ipa_nl_neigh_info_t nl_neigh_info;
ipa_nl_route_info_t nl_route_info;
} ipa_nl_msg_t;
/* Initialization routine for listener on NetLink sockets interface */
int ipa_nl_listener_init
(
unsigned int nl_type,
unsigned int nl_groups,
ipa_nl_sk_fd_set_info_t *sk_fdset,
ipa_sock_thrd_fd_read_f read_f
);
/* Virtual function registered to receive incoming messages over the NETLINK routing socket*/
int ipa_nl_recv_msg(int fd);
/* map mask value for ipv6 */
int mask_v6(int index, uint32_t *mask);
#ifdef __cplusplus
}
#endif
#endif /* IPACM_NETLINK_H */

View file

@ -1,131 +0,0 @@
/*
* Copyright (c) 2017-2018, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _IPACM_OFFLOAD_MANAGER_H_
#define _IPACM_OFFLOAD_MANAGER_H_
#include <list>
#include <stdint.h>
#include <IOffloadManager.h>
#include "IPACM_Defs.h"
using RET = ::IOffloadManager::RET;
using Prefix = ::IOffloadManager::Prefix;
using IP_FAM = ::IOffloadManager::IP_FAM;
using L4Protocol = ::IOffloadManager::ConntrackTimeoutUpdater::L4Protocol;
using natTimeoutUpdate_t = ::IOffloadManager::ConntrackTimeoutUpdater::natTimeoutUpdate_t;
//using ipAddrPortPair_t = ::IOffloadManager::ConntrackTimeoutUpdater::ipAddrPortPair_t;
//using UDP = ::IOffloadManager::ConntrackTimeoutUpdater::UDP;
//using TCP = ::IOffloadManager::ConntrackTimeoutUpdater::TCP;
#define MAX_EVENT_CACHE 10
typedef struct _framework_event_cache
{
/* IPACM interface name */
ipa_cm_event_id event;
char dev_name[IF_NAME_LEN];
Prefix prefix_cache;
Prefix prefix_cache_v6; //for setupstream use
bool valid;
}framework_event_cache;
class IPACM_OffloadManager : public IOffloadManager
{
public:
IPACM_OffloadManager();
static IPACM_OffloadManager* GetInstance();
virtual RET registerEventListener(IpaEventListener* /* listener */);
virtual RET unregisterEventListener(IpaEventListener* /* listener */);
virtual RET registerCtTimeoutUpdater(ConntrackTimeoutUpdater* /* cb */);
virtual RET unregisterCtTimeoutUpdater(ConntrackTimeoutUpdater* /* cb */);
virtual RET provideFd(int /* fd */, unsigned int /* group */);
virtual RET clearAllFds();
virtual bool isStaApSupported();
/* ---------------------------- ROUTE ------------------------------- */
virtual RET setLocalPrefixes(std::vector<Prefix> &/* prefixes */);
virtual RET addDownstream(const char * /* downstream */,
const Prefix & /* prefix */);
virtual RET removeDownstream(const char * /* downstream */,
const Prefix &/* prefix */);
virtual RET setUpstream(const char* /* iface */, const Prefix& /* v4Gw */, const Prefix& /* v6Gw */);
virtual RET stopAllOffload();
/* ------------------------- STATS/POLICY --------------------------- */
virtual RET setQuota(const char * /* upstream */, uint64_t /* limit */);
virtual RET getStats(const char * /* upstream */, bool /* reset */,
OffloadStatistics& /* ret */);
static IPACM_OffloadManager *pInstance;
IpaEventListener *elrInstance;
ConntrackTimeoutUpdater *touInstance;
bool search_framwork_cache(char * interface_name);
bool push_framework_event(const char * if_name, _ipacm_offload_prefix prefix);
static int num_offload_v4_tethered_iface;
private:
std::list<std::string> valid_ifaces;
bool upstream_v4_up;
bool upstream_v6_up;
int default_gw_index;
int post_route_evt(enum ipa_ip_type iptype, int index, ipa_cm_event_id event, const Prefix &gw_addr);
int ipa_get_if_index(const char *if_name, int *if_index);
int resetTetherStats(const char *upstream_name);
#ifdef FEATURE_IPACM_RESTART
int push_iface_up(const char *if_name, bool upstream);
#endif
static const char *DEVICE_NAME;
/* cache the add_downstream events if netdev is not ready */
framework_event_cache event_cache[MAX_EVENT_CACHE];
/* latest update cache entry */
int latest_cache_index;
}; /* IPACM_OffloadManager */
#endif /* _IPACM_OFFLOAD_MANAGER_H_ */

View file

@ -1,82 +0,0 @@
/*
Copyright (c) 2013, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_Routing.cpp
@brief
This file implements the IPACM routing functionality.
@Author
Skylar Chang
*/
#ifndef IPACM_ROUTING_H
#define IPACM_ROUTING_H
#include <stdint.h>
#include <linux/msm_ipa.h>
#include <IPACM_Defs.h>
using namespace std;
class IPACM_Routing
{
public:
IPACM_Routing();
~IPACM_Routing();
bool AddRoutingRule(struct ipa_ioc_add_rt_rule *ruleTable);
#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO
bool AddRoutingRule_hw_index(struct ipa_ioc_add_rt_rule *ruleTable, int hw_counter_index);
#endif //IPA_IOCTL_SET_FNR_COUNTER_INFO
bool DeleteRoutingRule(struct ipa_ioc_del_rt_rule *ruleTable);
bool Commit(enum ipa_ip_type ip);
bool Reset(enum ipa_ip_type ip);
bool GetRoutingTable(struct ipa_ioc_get_rt_tbl *routingTable);
bool DeviceNodeIsOpened();
bool DeleteRoutingHdl(uint32_t rt_rule_hdl, ipa_ip_type ip);
bool ModifyRoutingRule(struct ipa_ioc_mdfy_rt_rule *);
private:
static const char *DEVICE_NAME;
int m_fd; /* File descriptor of the IPA device node /dev/ipa */
bool PutRoutingTable(uint32_t routingTableHandle);
};
#endif //IPACM_ROUTING_H

View file

@ -1,694 +0,0 @@
/*
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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_Wan.cpp
@brief
This file implements the WAN iface functionality.
@Author
Skylar Chang
*/
#ifndef IPACM_WAN_H
#define IPACM_WAN_H
#include <stdio.h>
#include <IPACM_CmdQueue.h>
#include <linux/msm_ipa.h>
#include "IPACM_Routing.h"
#include "IPACM_Filtering.h"
#include <IPACM_Iface.h>
#include <IPACM_Defs.h>
#include <IPACM_Xml.h>
#define IPA_NUM_DEFAULT_WAN_FILTER_RULES 3 /*1 for v4, 2 for v6*/
#define IPA_V2_NUM_DEFAULT_WAN_FILTER_RULE_IPV4 2
#ifdef FEATURE_IPA_ANDROID
#define IPA_V2_NUM_DEFAULT_WAN_FILTER_RULE_IPV6 4
#define IPA_V2_NUM_TCP_WAN_FILTER_RULE_IPV6 3
#define IPA_V2_NUM_MULTICAST_WAN_FILTER_RULE_IPV6 3
#define IPA_V2_NUM_FRAG_WAN_FILTER_RULE_IPV6 1
#else
#define IPA_V2_NUM_DEFAULT_WAN_FILTER_RULE_IPV6 3
#endif
#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
{
uint32_t wan_rt_rule_hdl_v4;
uint32_t wan_rt_rule_hdl_v6[IPV6_NUM_ADDR];
uint32_t wan_rt_rule_hdl_v6_wan[IPV6_NUM_ADDR];
}wan_client_rt_hdl;
typedef struct _ipa_wan_client
{
ipacm_event_data_wlan_ex* p_hdr_info;
uint8_t mac[IPA_MAC_ADDR_SIZE];
uint32_t v4_addr;
uint32_t v6_addr[IPV6_NUM_ADDR][4];
uint32_t hdr_hdl_v4;
uint32_t hdr_hdl_v6;
bool route_rule_set_v4;
int route_rule_set_v6;
bool ipv4_set;
int ipv6_set;
bool ipv4_header_set;
bool ipv6_header_set;
bool power_save_set;
wan_client_rt_hdl wan_rt_hdl[0]; /* depends on number of tx properties */
}ipa_wan_client;
typedef struct
{
bool coalesce_tcp_enable;
bool coalesce_udp_enable;
}ipacm_coalesce;
/* wan iface */
class IPACM_Wan : public IPACM_Iface
{
public:
/* IPACM pm_depency q6 check*/
static int ipa_pm_q6_check;
static bool wan_up;
static bool wan_up_v6;
static uint8_t xlat_mux_id;
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;
IPACM_Wan(int, ipacm_wan_iface_type, uint8_t *);
virtual ~IPACM_Wan();
static bool isWanUP(int ipa_if_num_tether)
{
#ifdef FEATURE_IPA_ANDROID
#ifdef FEATURE_IPACM_HAL
/*To avoid -Wall -Werror error */
IPACMDBG_H("ipa_if_num_tether: %d\n",ipa_if_num_tether);
return wan_up;
#else
uint32_t i;
for (i=0; i < ipa_if_num_tether_v4_total;i++)
{
if (ipa_if_num_tether_v4[i] == ipa_if_num_tether)
{
IPACMDBG_H("support ipv4 tether_iface(%s)\n",
IPACM_Iface::ipacmcfg->iface_table[ipa_if_num_tether].iface_name);
return wan_up;
break;
}
}
return false;
#endif
#else
return wan_up;
#endif
}
static uint16_t queryMTU(int ipa_if_num_tether, enum ipa_ip_type iptype)
{
if (iptype == IPA_IP_v4)
{
if (isWanUP(ipa_if_num_tether))
{
return mtu_default_wan_v4;
}
}
else if (iptype == IPA_IP_v6)
{
if (isWanUP_V6(ipa_if_num_tether))
{
return mtu_default_wan_v6;
}
}
return DEFAULT_MTU_SIZE;
}
static bool isWanUP_V6(int ipa_if_num_tether)
{
#ifdef FEATURE_IPA_ANDROID
#ifdef FEATURE_IPACM_HAL
/*To avoid -Wall -Werror error */
IPACMDBG_H("ipa_if_num_tether: %d\n",ipa_if_num_tether);
return wan_up_v6;
#else
uint32_t i;
for (i=0; i < ipa_if_num_tether_v6_total;i++)
{
if (ipa_if_num_tether_v6[i] == ipa_if_num_tether)
{
IPACMDBG_H("support ipv6 tether_iface(%s)\n",
IPACM_Iface::ipacmcfg->iface_table[ipa_if_num_tether].iface_name);
return wan_up_v6;
break;
}
}
return false;
#endif
#else
return wan_up_v6;
#endif
}
#ifdef FEATURE_IPA_ANDROID
static int delete_tether_iface(ipa_ip_type iptype, int ipa_if_num_tether)
{
uint32_t i, j;
if (iptype == IPA_IP_v4)
{
/* delete support tether ifaces to its array*/
for (i=0; i < IPACM_Wan::ipa_if_num_tether_v4_total; i++)
{
if(IPACM_Wan::ipa_if_num_tether_v4[i] == ipa_if_num_tether)
{
IPACMDBG_H("Found tether client at position %d name(%s)\n", i,
IPACM_Iface::ipacmcfg->iface_table[ipa_if_num_tether].iface_name);
break;
}
}
if(i == IPACM_Wan::ipa_if_num_tether_v4_total)
{
IPACMDBG_H("Not finding the tethered ipv4 client.\n");
return IPACM_FAILURE;
}
for(j = i+1; j < IPACM_Wan::ipa_if_num_tether_v4_total; j++)
{
IPACM_Wan::ipa_if_num_tether_v4[j-1] = IPACM_Wan::ipa_if_num_tether_v4[j];
}
IPACM_Wan::ipa_if_num_tether_v4_total--;
IPACMDBG_H("Now the total num of ipa_if_num_tether_v4_total is %d\n",
IPACM_Wan::ipa_if_num_tether_v4_total);
}
else
{
/* delete support tether ifaces to its array*/
for (i=0; i < IPACM_Wan::ipa_if_num_tether_v6_total; i++)
{
if(IPACM_Wan::ipa_if_num_tether_v6[i] == ipa_if_num_tether)
{
IPACMDBG_H("Found tether client at position %d name(%s)\n", i,
IPACM_Iface::ipacmcfg->iface_table[ipa_if_num_tether].iface_name);
break;
}
}
if(i == IPACM_Wan::ipa_if_num_tether_v6_total)
{
IPACMDBG_H("Not finding the tethered ipv6 client.\n");
return IPACM_FAILURE;
}
for(j = i+1; j < IPACM_Wan::ipa_if_num_tether_v6_total; j++)
{
IPACM_Wan::ipa_if_num_tether_v6[j-1] = IPACM_Wan::ipa_if_num_tether_v6[j];
}
IPACM_Wan::ipa_if_num_tether_v6_total--;
IPACMDBG_H("Now the total num of ipa_if_num_tether_v6_total is %d\n",
IPACM_Wan::ipa_if_num_tether_v6_total);
}
return IPACM_SUCCESS;
}
#endif
static void coalesce_config(uint8_t qmap_id, bool tcp_enable, bool udp_enable)
{
if (qmap_id >= IPA_MAX_NUM_SW_PDNS)
{
IPACMERR("qmap_id (%d) beyond the Max range (%d), abort\n",
qmap_id, IPA_MAX_NUM_SW_PDNS);
return ;
}
IPACM_Wan::coalesce_enable_info[qmap_id].coalesce_tcp_enable = tcp_enable;
IPACM_Wan::coalesce_enable_info[qmap_id].coalesce_udp_enable = udp_enable;
IPACMDBG_H(" Updated qmap(%d) coalesce enable TCP:%d UDP:%d\n",
qmap_id,
IPACM_Wan::coalesce_enable_info[qmap_id].coalesce_tcp_enable,
IPACM_Wan::coalesce_enable_info[qmap_id].coalesce_udp_enable);
return ;
}
static void coalesce_config_reset()
{
int i;
/* reset coalesce settings on all modem interfaces */
for (i = 0; i < IPA_MAX_NUM_SW_PDNS; i++)
IPACM_Wan::coalesce_config(i, false, false);
return ;
}
static uint32_t getWANIP()
{
return curr_wan_ip;
}
static int getXlat_Mux_Id()
{
if (is_xlat)
{
IPACMDBG_H("xlat_mux_id: %d\n", xlat_mux_id);
return xlat_mux_id;
} else {
IPACMDBG_H("no xlat return invalid mux-id: 0\n");
return 0;
}
}
static void clearExtProp()
{
IPACM_Wan::is_ext_prop_set = false;
IPACM_Iface::ipacmcfg->DelExtProp(IPA_IP_v4);
IPACM_Iface::ipacmcfg->DelExtProp(IPA_IP_v6);
}
void event_callback(ipa_cm_event_id event,
void *data);
static struct ipa_flt_rule_add flt_rule_v4[IPA_MAX_FLT_RULE];
static struct ipa_flt_rule_add flt_rule_v6[IPA_MAX_FLT_RULE];
static int num_v4_flt_rule;
static int num_v6_flt_rule;
ipacm_wan_iface_type m_is_sta_mode;
static ipacm_wan_iface_type backhaul_mode;
static bool is_ext_prop_set;
static uint32_t backhaul_ipv6_prefix[2];
static bool embms_is_on;
static bool backhaul_is_wan_bridge;
static bool is_xlat;
static bool isWan_Bridge_Mode()
{
return backhaul_is_wan_bridge;
}
#ifdef FEATURE_IPA_ANDROID
/* IPACM interface id */
static uint32_t ipa_if_num_tether_v4_total;
static int ipa_if_num_tether_v4[IPA_MAX_IFACE_ENTRIES];
static uint32_t ipa_if_num_tether_v6_total;
static int ipa_if_num_tether_v6[IPA_MAX_IFACE_ENTRIES];
static bool isXlat()
{
return is_xlat;
}
#endif
/* indicate coalesce support on tcp or udp*/
static ipacm_coalesce coalesce_enable_info[IPA_MAX_NUM_SW_PDNS];
private:
bool is_ipv6_frag_firewall_flt_rule_installed;
uint32_t ipv6_frag_firewall_flt_rule_hdl;
uint32_t *wan_route_rule_v4_hdl;
uint32_t *wan_route_rule_v6_hdl;
uint32_t *wan_route_rule_v6_hdl_a5;
uint32_t hdr_hdl_sta_v4;
uint32_t hdr_hdl_sta_v6;
uint32_t firewall_hdl_v4[IPACM_MAX_FIREWALL_ENTRIES];
uint32_t firewall_hdl_v6[IPACM_MAX_FIREWALL_ENTRIES];
uint32_t dft_wan_fl_hdl[IPA_NUM_DEFAULT_WAN_FILTER_RULES];
uint32_t ipv6_dest_flt_rule_hdl[MAX_DEFAULT_v6_ROUTE_RULES];
int num_ipv6_dest_flt_rule;
uint32_t ODU_fl_hdl[IPA_NUM_DEFAULT_WAN_FILTER_RULES];
int num_firewall_v4,num_firewall_v6;
uint32_t wan_v4_addr;
uint32_t wan_v4_addr_gw;
uint32_t wan_v6_addr_gw[4];
bool wan_v4_addr_set;
bool wan_v4_addr_gw_set;
bool wan_v6_addr_gw_set;
bool active_v4;
bool active_v6;
bool header_set_v4;
bool header_set_v6;
bool header_partial_default_wan_v4;
bool header_partial_default_wan_v6;
uint8_t ext_router_mac_addr[IPA_MAC_ADDR_SIZE];
uint8_t netdev_mac[IPA_MAC_ADDR_SIZE];
/* create additional set of v4 Coalesce RT-rules: tcp udp */
uint32_t dft_coalesce_rt_rule_hdl[2*MAX_DEFAULT_v4_ROUTE_RULES+ 2*MAX_DEFAULT_v6_ROUTE_RULES];
static int num_ipv4_modem_pdn;
static int num_ipv6_modem_pdn;
int modem_ipv4_pdn_index;
int modem_ipv6_pdn_index;
bool is_default_gateway;
uint32_t ipv6_prefix[2];
/* IPACM firewall Configuration file*/
IPACM_firewall_conf_t firewall_config;
/* STA mode wan-client*/
int wan_client_len;
ipa_wan_client *wan_client;
int header_name_count;
uint32_t num_wan_client;
uint8_t invalid_mac[IPA_MAC_ADDR_SIZE];
bool is_xlat_local;
/* update network stats for CNE */
int ipa_network_stats_fd;
uint32_t hdr_hdl_dummy_v6;
uint32_t hdr_proc_hdl_dummy_v6;
/* handle for UDP mhi frag rule */
uint32_t mhi_dl_v4_frag_hdl;
/* handle for icmpv6 exception rule */
uint32_t icmpv6_exception_hdl;
/* handle for TCP FIN rule */
uint32_t tcp_fin_hdl;
/* 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);
return (ipa_wan_client *)ret;
}
inline int get_wan_client_index(uint8_t *mac_addr)
{
int cnt;
int num_wan_client_tmp = num_wan_client;
IPACMDBG_H("Passed 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]);
for(cnt = 0; cnt < num_wan_client_tmp; cnt++)
{
IPACMDBG_H("stored MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
get_client_memptr(wan_client, cnt)->mac[0],
get_client_memptr(wan_client, cnt)->mac[1],
get_client_memptr(wan_client, cnt)->mac[2],
get_client_memptr(wan_client, cnt)->mac[3],
get_client_memptr(wan_client, cnt)->mac[4],
get_client_memptr(wan_client, cnt)->mac[5]);
if(memcmp(get_client_memptr(wan_client, cnt)->mac,
mac_addr,
sizeof(get_client_memptr(wan_client, cnt)->mac)) == 0)
{
IPACMDBG_H("Matched client index: %d\n", cnt);
return cnt;
}
}
return IPACM_INVALID_INDEX;
}
inline int get_wan_client_index_ipv4(uint32_t ipv4_addr)
{
int cnt;
int num_wan_client_tmp = num_wan_client;
IPACMDBG_H("Passed IPv4 %x\n", ipv4_addr);
for(cnt = 0; cnt < num_wan_client_tmp; cnt++)
{
if (get_client_memptr(wan_client, cnt)->ipv4_set)
{
IPACMDBG_H("stored IPv4 %x\n", get_client_memptr(wan_client, cnt)->v4_addr);
if(ipv4_addr == get_client_memptr(wan_client, cnt)->v4_addr)
{
IPACMDBG_H("Matched client index: %d\n", cnt);
IPACMDBG_H("The MAC is %02x:%02x:%02x:%02x:%02x:%02x\n",
get_client_memptr(wan_client, cnt)->mac[0],
get_client_memptr(wan_client, cnt)->mac[1],
get_client_memptr(wan_client, cnt)->mac[2],
get_client_memptr(wan_client, cnt)->mac[3],
get_client_memptr(wan_client, cnt)->mac[4],
get_client_memptr(wan_client, cnt)->mac[5]);
IPACMDBG_H("header set ipv4(%d) ipv6(%d)\n",
get_client_memptr(wan_client, cnt)->ipv4_header_set,
get_client_memptr(wan_client, cnt)->ipv6_header_set);
return cnt;
}
}
}
return IPACM_INVALID_INDEX;
}
inline int get_wan_client_index_ipv6(uint32_t* ipv6_addr)
{
int cnt, v6_num;
int num_wan_client_tmp = num_wan_client;
IPACMDBG_H("Get ipv6 address 0x%08x.0x%08x.0x%08x.0x%08x\n", ipv6_addr[0], ipv6_addr[1], ipv6_addr[2], ipv6_addr[3]);
for(cnt = 0; cnt < num_wan_client_tmp; cnt++)
{
if (get_client_memptr(wan_client, cnt)->ipv6_set)
{
for(v6_num=0;v6_num < get_client_memptr(wan_client, cnt)->ipv6_set;v6_num++)
{
IPACMDBG_H("stored IPv6 0x%08x.0x%08x.0x%08x.0x%08x\n", get_client_memptr(wan_client, cnt)->v6_addr[v6_num][0],
get_client_memptr(wan_client, cnt)->v6_addr[v6_num][1],
get_client_memptr(wan_client, cnt)->v6_addr[v6_num][2],
get_client_memptr(wan_client, cnt)->v6_addr[v6_num][3]);
if(ipv6_addr[0] == get_client_memptr(wan_client, cnt)->v6_addr[v6_num][0] &&
ipv6_addr[1] == get_client_memptr(wan_client, cnt)->v6_addr[v6_num][1] &&
ipv6_addr[2]== get_client_memptr(wan_client, cnt)->v6_addr[v6_num][2] &&
ipv6_addr[3] == get_client_memptr(wan_client, cnt)->v6_addr[v6_num][3])
{
IPACMDBG_H("Matched client index: %d\n", cnt);
IPACMDBG_H("The MAC is %02x:%02x:%02x:%02x:%02x:%02x\n",
get_client_memptr(wan_client, cnt)->mac[0],
get_client_memptr(wan_client, cnt)->mac[1],
get_client_memptr(wan_client, cnt)->mac[2],
get_client_memptr(wan_client, cnt)->mac[3],
get_client_memptr(wan_client, cnt)->mac[4],
get_client_memptr(wan_client, cnt)->mac[5]);
IPACMDBG_H("header set ipv4(%d) ipv6(%d)\n",
get_client_memptr(wan_client, cnt)->ipv4_header_set,
get_client_memptr(wan_client, cnt)->ipv6_header_set);
return cnt;
}
}
}
}
return IPACM_INVALID_INDEX;
}
inline int delete_wan_rtrules(int clt_indx, ipa_ip_type iptype)
{
uint32_t tx_index;
uint32_t rt_hdl;
int num_v6;
if(iptype == IPA_IP_v4)
{
for(tx_index = 0; tx_index < iface_query->num_tx_props; tx_index++)
{
if((tx_prop->tx[tx_index].ip == IPA_IP_v4) && (get_client_memptr(wan_client, clt_indx)->route_rule_set_v4==true)) /* for ipv4 */
{
IPACMDBG_H("Delete client index %d ipv4 Qos rules for tx:%d \n",clt_indx,tx_index);
rt_hdl = get_client_memptr(wan_client, clt_indx)->wan_rt_hdl[tx_index].wan_rt_rule_hdl_v4;
if(m_routing.DeleteRoutingHdl(rt_hdl, IPA_IP_v4) == false)
{
return IPACM_FAILURE;
}
}
} /* end of for loop */
/* clean the 4 Qos ipv4 RT rules for client:clt_indx */
if(get_client_memptr(wan_client, clt_indx)->route_rule_set_v4==true) /* for ipv4 */
{
get_client_memptr(wan_client, clt_indx)->route_rule_set_v4 = false;
}
}
if(iptype == IPA_IP_v6)
{
for(tx_index = 0; tx_index < iface_query->num_tx_props; tx_index++)
{
if((tx_prop->tx[tx_index].ip == IPA_IP_v6) && (get_client_memptr(wan_client, clt_indx)->route_rule_set_v6 != 0)) /* for ipv6 */
{
for(num_v6 =0;num_v6 < get_client_memptr(wan_client, clt_indx)->route_rule_set_v6;num_v6++)
{
IPACMDBG_H("Delete client index %d ipv6 Qos rules for %d-st ipv6 for tx:%d\n", clt_indx,num_v6,tx_index);
rt_hdl = get_client_memptr(wan_client, clt_indx)->wan_rt_hdl[tx_index].wan_rt_rule_hdl_v6[num_v6];
if(m_routing.DeleteRoutingHdl(rt_hdl, IPA_IP_v6) == false)
{
return IPACM_FAILURE;
}
rt_hdl = get_client_memptr(wan_client, clt_indx)->wan_rt_hdl[tx_index].wan_rt_rule_hdl_v6_wan[num_v6];
if(m_routing.DeleteRoutingHdl(rt_hdl, IPA_IP_v6) == false)
{
return IPACM_FAILURE;
}
}
}
} /* end of for loop */
/* clean the 4 Qos ipv6 RT rules for client:clt_indx */
if(get_client_memptr(wan_client, clt_indx)->route_rule_set_v6 != 0) /* for ipv6 */
{
get_client_memptr(wan_client, clt_indx)->route_rule_set_v6 = 0;
}
}
return IPACM_SUCCESS;
}
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);
/* handle new_address event for q6_mhi */
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, bool add_only = false);
/* construct complete STA ethernet header */
int handle_sta_header_add_evt(bool renew = false);
bool check_dft_firewall_rules_attr_mask(IPACM_firewall_conf_t *firewall_config);
#ifdef FEATURE_IPA_ANDROID
/* wan posting supported tether_iface */
int post_wan_up_tether_evt(ipa_ip_type iptype, int ipa_if_num_tether);
int post_wan_down_tether_evt(ipa_ip_type iptype, int ipa_if_num_tether);
#endif
int config_dft_firewall_rules(ipa_ip_type iptype);
/* 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, bool delete_only = false);
int del_dft_firewall_rules(ipa_ip_type iptype);
int handle_down_evt();
/*handle wan-iface down event */
int handle_down_evt_ex();
/* wan default route/filter rule delete */
int handle_route_del_evt_ex(ipa_ip_type iptype);
/* configure the initial firewall filter rules */
int config_dft_firewall_rules_ex(struct ipa_flt_rule_add* rules, int rule_offset,
ipa_ip_type iptype);
/* init filtering rule in wan dl filtering table */
int init_fl_rule_ex(ipa_ip_type iptype);
/* add ICMP and ALG rules in wan dl filtering table */
int add_icmp_alg_rules(struct ipa_flt_rule_add* rules, int rule_offset, ipa_ip_type iptype);
/* query extended property */
int query_ext_prop();
ipa_ioc_query_intf_ext_props *ext_prop;
int config_wan_firewall_rule(ipa_ip_type iptype);
int del_wan_firewall_rule(ipa_ip_type iptype);
int add_dft_filtering_rule(struct ipa_flt_rule_add* rules, int rule_offset, ipa_ip_type iptype);
int install_wan_filtering_rule(bool is_sw_routing);
void handle_wlan_SCC_MCC_switch(bool, ipa_ip_type);
void handle_wan_client_SCC_MCC_switch(bool, ipa_ip_type);
int handle_network_stats_evt();
int m_fd_ipa;
int handle_network_stats_update(ipa_get_apn_data_stats_resp_msg_v01 *data);
/* construct dummy ethernet header */
int add_dummy_rx_hdr();
int handle_coalesce_evt();
int add_offload_frag_rule();
int delete_offload_frag_rule();
int add_icmpv6_exception_rule();
int delete_icmpv6_exception_rule();
int add_tcp_fin_rst_exception_rule();
int delete_tcp_fin_rst_exception_rule();
/* MTU helper functions */
int query_mtu_size();
};
#endif /* IPACM_WAN_H */

View file

@ -1,268 +0,0 @@
/*
Copyright (c) 2013-2019, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_Wlan.h
@brief
This file implements the WLAN iface functionality.
@Author
Skylar Chang
*/
#ifndef IPACM_WLAN_H
#define IPACM_WLAN_H
#include <stdio.h>
#include <IPACM_CmdQueue.h>
#include <linux/msm_ipa.h>
#include "IPACM_Routing.h"
#include "IPACM_Filtering.h"
#include "IPACM_Lan.h"
#include "IPACM_Iface.h"
#include "IPACM_Conntrack_NATApp.h"
typedef struct _wlan_client_rt_hdl
{
uint32_t wifi_rt_rule_hdl_v4;
uint32_t wifi_rt_rule_hdl_v6[IPV6_NUM_ADDR];
uint32_t wifi_rt_rule_hdl_v6_wan[IPV6_NUM_ADDR];
}wlan_client_rt_hdl;
typedef struct _ipa_wlan_client
{
ipacm_event_data_wlan_ex* p_hdr_info;
uint8_t mac[IPA_MAC_ADDR_SIZE];
uint32_t v4_addr;
uint32_t v6_addr[IPV6_NUM_ADDR][4];
uint32_t hdr_hdl_v4;
uint32_t hdr_hdl_v6;
bool route_rule_set_v4;
int route_rule_set_v6;
bool ipv4_set;
int ipv6_set;
bool ipv4_header_set;
bool ipv6_header_set;
bool power_save_set;
enum ipa_client_type wigig_ipa_client;
/* used for pcie-modem */
uint32_t v6_rt_rule_id[IPV6_NUM_ADDR];
wlan_client_rt_hdl wifi_rt_hdl[0]; /* depends on number of tx properties */
}ipa_wlan_client;
/* wlan iface */
class IPACM_Wlan : public IPACM_Lan
{
public:
IPACM_Wlan(int iface_index);
virtual ~IPACM_Wlan(void);
static int total_num_wifi_clients;
void event_callback(ipa_cm_event_id event, void *data);
bool is_guest_ap();
private:
bool m_is_guest_ap;
/* handle wlan access mode switch in ethernet bridging*/
void eth_bridge_handle_wlan_mode_switch();
int wlan_client_len;
ipa_wlan_client *wlan_client;
int header_name_count;
uint32_t num_wifi_client;
int wlan_ap_index;
static int num_wlan_ap_iface;
NatApp *Nat_App;
inline ipa_wlan_client* get_client_memptr(ipa_wlan_client *param, int cnt)
{
char *ret = ((char *)param) + (wlan_client_len * cnt);
return (ipa_wlan_client *)ret;
}
inline int get_wlan_client_index(uint8_t *mac_addr)
{
int cnt;
int num_wifi_client_tmp = num_wifi_client;
IPACMDBG_H("Passed 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]);
for(cnt = 0; cnt < num_wifi_client_tmp; cnt++)
{
IPACMDBG_H("stored MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
get_client_memptr(wlan_client, cnt)->mac[0],
get_client_memptr(wlan_client, cnt)->mac[1],
get_client_memptr(wlan_client, cnt)->mac[2],
get_client_memptr(wlan_client, cnt)->mac[3],
get_client_memptr(wlan_client, cnt)->mac[4],
get_client_memptr(wlan_client, cnt)->mac[5]);
if(memcmp(get_client_memptr(wlan_client, cnt)->mac,
mac_addr,
sizeof(get_client_memptr(wlan_client, cnt)->mac)) == 0)
{
IPACMDBG_H("Matched client index: %d\n", cnt);
return cnt;
}
}
return IPACM_INVALID_INDEX;
}
inline int delete_default_qos_rtrules(int clt_indx, ipa_ip_type iptype)
{
uint32_t tx_index;
uint32_t rt_hdl;
int num_v6;
if(iptype == IPA_IP_v4)
{
for(tx_index = 0; tx_index < iface_query->num_tx_props; tx_index++)
{
if((tx_prop->tx[tx_index].ip == IPA_IP_v4) && (get_client_memptr(wlan_client, clt_indx)->route_rule_set_v4==true)) /* for ipv4 */
{
IPACMDBG_H("Delete client index %d ipv4 Qos rules for tx:%d \n",clt_indx,tx_index);
rt_hdl = get_client_memptr(wlan_client, clt_indx)->wifi_rt_hdl[tx_index].wifi_rt_rule_hdl_v4;
if(m_routing.DeleteRoutingHdl(rt_hdl, IPA_IP_v4) == false)
{
return IPACM_FAILURE;
}
}
} /* end of for loop */
/* clean the 4 Qos ipv4 RT rules for client:clt_indx */
if(get_client_memptr(wlan_client, clt_indx)->route_rule_set_v4==true) /* for ipv4 */
{
get_client_memptr(wlan_client, clt_indx)->route_rule_set_v4 = false;
}
}
if(iptype == IPA_IP_v6)
{
for(tx_index = 0; tx_index < iface_query->num_tx_props; tx_index++)
{
if((tx_prop->tx[tx_index].ip == IPA_IP_v6) && (get_client_memptr(wlan_client, clt_indx)->route_rule_set_v6 != 0)) /* for ipv6 */
{
for(num_v6 =0;num_v6 < get_client_memptr(wlan_client, clt_indx)->route_rule_set_v6;num_v6++)
{
/* send client-v6 delete to pcie modem only with global ipv6 with tx_index = 0 one time*/
if(is_global_ipv6_addr(get_client_memptr(wlan_client, clt_indx)->v6_addr[num_v6]) && (IPACM_Wan::backhaul_mode == Q6_MHI_WAN)
&& (get_client_memptr(wlan_client, clt_indx)->v6_rt_rule_id[num_v6] > 0))
{
IPACMDBG_H("Delete client index %d ipv6 RT-rules for %d-st ipv6 for rule-id:%d\n", clt_indx,num_v6,
get_client_memptr(wlan_client, clt_indx)->v6_rt_rule_id[num_v6]);
if (del_connection(clt_indx, num_v6))
{
IPACMERR("PCIE filter rule deletion failed! (%d-client) %d v6-entry\n",clt_indx, num_v6);
}
}
IPACMDBG_H("Delete client index %d ipv6 Qos rules for %d-st ipv6 for tx:%d\n", clt_indx,num_v6,tx_index);
rt_hdl = get_client_memptr(wlan_client, clt_indx)->wifi_rt_hdl[tx_index].wifi_rt_rule_hdl_v6[num_v6];
if(m_routing.DeleteRoutingHdl(rt_hdl, IPA_IP_v6) == false)
{
return IPACM_FAILURE;
}
rt_hdl = get_client_memptr(wlan_client, clt_indx)->wifi_rt_hdl[tx_index].wifi_rt_rule_hdl_v6_wan[num_v6];
if(m_routing.DeleteRoutingHdl(rt_hdl, IPA_IP_v6) == false)
{
return IPACM_FAILURE;
}
}
}
} /* end of for loop */
/* clean the 4 Qos ipv6 RT rules for client:clt_indx */
if(get_client_memptr(wlan_client, clt_indx)->route_rule_set_v6 != 0) /* for ipv6 */
{
get_client_memptr(wlan_client, clt_indx)->route_rule_set_v6 = 0;
}
}
return IPACM_SUCCESS;
}
int handle_wigig_client_add(ipacm_event_data_mac_ep *data);
/* for handle wifi client initial,copy all partial headers (tx property) */
int handle_wlan_client_init_ex(ipacm_event_data_wlan_ex *data);
/*handle wifi client */
int handle_wlan_client_ipaddr(ipacm_event_data_all *data);
/*handle wifi client routing rule*/
int handle_wlan_client_route_rule(uint8_t *mac_addr, ipa_ip_type iptype);
/*handle wifi client power-save mode*/
int handle_wlan_client_pwrsave(uint8_t *mac_addr);
/*handle wifi client del mode*/
int handle_wlan_client_down_evt(uint8_t *mac_addr);
/*handle wlan iface down event*/
int handle_down_evt();
/*handle reset wifi-client rt-rules */
int handle_wlan_client_reset_rt(ipa_ip_type iptype);
void handle_SCC_MCC_switch(ipa_ip_type);
/* for pcie modem */
int add_connection(int client_index, int v6_num);
int del_connection(int client_index, int v6_num);
#ifdef FEATURE_IPACM_RESTART
/*query wlan-clients */
int ipa_query_wlan_client();
#endif
};
#endif /* IPACM_WLAN_H */

View file

@ -1,306 +0,0 @@
/*
Copyright (c) 2013, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_Xml.h
@brief
This file implements the XML specific parsing functionality.
@Author
Skylar Chang/Shihuan Liu
*/
#ifndef IPACM_XML_H
#define IPACM_XML_H
#include <linux/msm_ipa.h>
#include "IPACM_Defs.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef in_addr_t
typedef uint32_t in_addr_t;
#endif
#include <arpa/inet.h>
#include <stdint.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#ifdef __cplusplus
extern "C" {
#endif
#define IPACM_ASSERT(a) \
if (!(a)) { \
fprintf(stderr, "%s, %d: assertion (a) failed!", \
__FILE__, \
__LINE__); \
abort(); \
}
/* Max allowed size of the XML file (2 MB) */
#define IPACM_XML_MAX_FILESIZE (2 << 20)
#define IPACM_MAX_FIREWALL_ENTRIES 50
#define IPACM_IPV6_ADDR_LEN 16
/* Defines for clipping space or space & quotes (single, double) */
#define IPACM_XML_CLIP_SPACE " "
#define IPACM_XML_CLIP_SPACE_QUOTES " '\""
#define MAX_XML_STR_LEN 120
/* IPA Config Entries */
#define system_TAG "system"
#define ODU_TAG "ODUCFG"
#define ODUMODE_TAG "OduMode"
#define ODUEMBMS_OFFLOAD_TAG "eMBMS_offload"
#define ODU_ROUTER_TAG "router"
#define ODU_BRIDGE_TAG "bridge"
#define IPACMCFG_TAG "IPACM"
#define IPACMIFACECFG_TAG "IPACMIface"
#define IFACE_TAG "Iface"
#define NAME_TAG "Name"
#define CATEGORY_TAG "Category"
#define MODE_TAG "Mode"
#define IPACMPRIVATESUBNETCFG_TAG "IPACMPrivateSubnet"
#define SUBNET_TAG "Subnet"
#define SUBNETADDRESS_TAG "SubnetAddress"
#define SUBNETMASK_TAG "SubnetMask"
#define WANIF_TAG "WAN"
#define LANIF_TAG "LAN"
#define WLANIF_TAG "WLAN"
#define WLAN_FULL_MODE_TAG "full"
#define WLAN_INTERNET_MODE_TAG "internet"
#define WLAN_MODE_TAG "WlanMode"
#define VIRTUALIF_TAG "VIRTUAL"
#define UNKNOWNIF_TAG "UNKNOWN"
#define ODUIF_TAG "ODU"
#define EMBMSIF_TAG "EMBMS"
#define ETHIF_TAG "ETH"
#define IFACE_ROUTER_MODE_TAG "ROUTER"
#define IFACE_BRIDGE_MODE_TAG "BRIDGE"
#define IPACMALG_TAG "IPACMALG"
#define ALG_TAG "ALG"
#define Protocol_TAG "Protocol"
#define Port_TAG "Port"
#define TCP_PROTOCOL_TAG "TCP"
#define UDP_PROTOCOL_TAG "UDP"
/* FIREWALL Config Entries */
#define Firewall_TAG "Firewall"
#define MobileAPFirewallCfg_TAG "MobileAPFirewallCfg"
#define FirewallEnabled_TAG "FirewallEnabled"
#define FirewallPktsAllowed_TAG "FirewallPktsAllowed"
#define IPFamily_TAG "IPFamily"
#define IPV4SourceAddress_TAG "IPV4SourceAddress"
#define IPV4SourceIPAddress_TAG "IPV4SourceIPAddress"
#define IPV4SourceSubnetMask_TAG "IPV4SourceSubnetMask"
#define IPV4DestinationAddress_TAG "IPV4DestinationAddress"
#define IPV4DestinationIPAddress_TAG "IPV4DestinationIPAddress"
#define IPV4DestinationSubnetMask_TAG "IPV4DestinationSubnetMask"
#define IPV4TypeOfService_TAG "IPV4TypeOfService"
#define TOSValue_TAG "TOSValue"
#define TOSMask_TAG "TOSMask"
#define IPV4NextHeaderProtocol_TAG "IPV4NextHeaderProtocol"
#define IPV6SourceAddress_TAG "IPV6SourceAddress"
#define IPV6SourceIPAddress_TAG "IPV6SourceIPAddress"
#define IPV6SourcePrefix_TAG "IPV6SourcePrefix"
#define IPV6DestinationAddress_TAG "IPV6DestinationAddress"
#define IPV6DestinationIPAddress_TAG "IPV6DestinationIPAddress"
#define IPV6DestinationPrefix_TAG "IPV6DestinationPrefix"
#define IPV6TrafficClass_TAG "IPV6TrafficClass"
#define TrfClsValue_TAG "TrfClsValue"
#define TrfClsMask_TAG "TrfClsMask"
#define IPV6NextHeaderProtocol_TAG "IPV6NextHeaderProtocol"
#define TCPSource_TAG "TCPSource"
#define TCPSourcePort_TAG "TCPSourcePort"
#define TCPSourceRange_TAG "TCPSourceRange"
#define TCPDestination_TAG "TCPDestination"
#define TCPDestinationPort_TAG "TCPDestinationPort"
#define TCPDestinationRange_TAG "TCPDestinationRange"
#define UDPSource_TAG "UDPSource"
#define UDPSourcePort_TAG "UDPSourcePort"
#define UDPSourceRange_TAG "UDPSourceRange"
#define UDPDestination_TAG "UDPDestination"
#define UDPDestinationPort_TAG "UDPDestinationPort"
#define UDPDestinationRange_TAG "UDPDestinationRange"
#define ICMPType_TAG "ICMPType"
#define ICMPCode_TAG "ICMPCode"
#define ESP_TAG "ESP"
#define ESPSPI_TAG "ESPSPI"
#define TCP_UDPSource_TAG "TCP_UDPSource"
#define TCP_UDPSourcePort_TAG "TCP_UDPSourcePort"
#define TCP_UDPSourceRange_TAG "TCP_UDPSourceRange"
#define TCP_UDPDestination_TAG "TCP_UDPDestination"
#define TCP_UDPDestinationPort_TAG "TCP_UDPDestinationPort"
#define TCP_UDPDestinationRange_TAG "TCP_UDPDestinationRange"
#define IPACMNat_TAG "IPACMNAT"
#define NAT_MaxEntries_TAG "MaxNatEntries"
#define IP_PassthroughFlag_TAG "IPPassthroughFlag"
#define IP_PassthroughMode_TAG "IPPassthroughMode"
/*---------------------------------------------------------------------------
IP protocol numbers - use in dss_socket() to identify protocols.
Also contains the extension header types for IPv6.
---------------------------------------------------------------------------*/
typedef enum
{
IPACM_FIREWALL_IPV6_BASE_HDR = 4, /* IPv6 Base Header */
IPACM_FIREWALL_IPPROTO_HOP_BY_HOP_OPT_HDR = 0, /* Hop-by-hop Option Header */
IPACM_FIREWALL_IPPROTO_ICMP = 1, /* ICMP protocol */
IPACM_FIREWALL_IPPROTO_IGMP = 2, /* IGMP protocol */
IPACM_FIREWALL_IPPROTO_IP = IPACM_FIREWALL_IPV6_BASE_HDR, /* IPv4 */
IPACM_FIREWALL_IPPROTO_TCP = 6, /* TCP Protocol */
IPACM_FIREWALL_IPPROTO_UDP = 17, /* UDP Protocol */
IPACM_FIREWALL_IPPROTO_IPV6 = 41, /* IPv6 */
IPACM_FIREWALL_IPPROTO_ROUTING_HDR = 43, /* Routing Header */
IPACM_FIREWALL_IPPROTO_FRAG_HDR = 44, /* Fragmentation Header */
IPACM_FIREWALL_IPPROTO_GRE = 47, /* GRE Protocol */
IPACM_FIREWALL_IPPROTO_ESP = 50, /* ESP Protocol */
IPACM_FIREWALL_IPPROTO_AH = 51, /* Authentication Header */
IPACM_FIREWALL_IPPROTO_ICMP6 = 58, /* ICMPv6 */
IPACM_FIREWALL_NO_NEXT_HDR = 59, /* No Next Header for IPv6 */
IPACM_FIREWALL_IPPROTO_DEST_OPT_HDR = 60, /* Destination Options Header */
IPACM_FIREWALL_IPPROTO_MOBILITY_HDR = 135, /* Mobility Header */
IPACM_FIREWALL_IPPROTO_TCP_UDP = 253 /* Unspecified protocol used for IPACM */
} ipacm_firewall_ip_protocol_enum_type;
/* define as mobileap firewall rule format*/
typedef enum
{
IP_V4 = 4,
IP_V6 = 6
} firewall_ip_version_enum;
/*---------------------------------------------------------------------------
Extended FireWall Entry Configuration.
---------------------------------------------------------------------------*/
typedef struct
{
struct ipa_rule_attrib attrib;
firewall_ip_version_enum ip_vsn;
} IPACM_extd_firewall_entry_conf_t;
/*---------------------------------------------------------------------------
Extended FireWall configuration.
---------------------------------------------------------------------------*/
typedef union
{
IPACM_extd_firewall_entry_conf_t extd_firewall_entry;
} IPACM_extd_firewall_conf_t;
typedef struct
{
char firewall_config_file[IPA_MAX_FILE_LEN];
uint8_t num_extd_firewall_entries;
IPACM_extd_firewall_entry_conf_t extd_firewall_entries[IPACM_MAX_FIREWALL_ENTRIES];
bool rule_action_accept;
bool firewall_enable;
} IPACM_firewall_conf_t;
typedef struct
{
uint8_t num_iface_entries;
ipa_ifi_dev_name_t iface_entries[IPA_MAX_IFACE_ENTRIES];
} ipacm_iface_conf_t;
typedef struct
{
uint8_t num_subnet_entries;
ipa_private_subnet private_subnet_entries[IPA_MAX_PRIVATE_SUBNET_ENTRIES];
} ipacm_private_subnet_conf_t;
typedef struct
{
uint8_t protocol;
uint16_t port;
} ipacm_alg;
typedef struct
{
uint8_t num_alg_entries;
ipacm_alg alg_entries[IPA_MAX_ALG_ENTRIES];
} ipacm_alg_conf_t;
typedef struct _IPACM_conf_t
{
ipacm_iface_conf_t iface_config;
ipacm_private_subnet_conf_t private_subnet_config;
ipacm_alg_conf_t alg_config;
int nat_max_entries;
bool odu_enable;
bool router_mode_enable;
bool odu_embms_enable;
int num_wlan_guest_ap;
bool ip_passthrough_mode;
} IPACM_conf_t;
/* This function read IPACM XML configuration*/
int ipacm_read_cfg_xml
(
char *xml_file, /* Filename and path */
IPACM_conf_t *config /* Mobile AP config data */
);
/* This function reads QCMAP Firewall XML and store in IPACM Firewall stucture */
int IPACM_read_firewall_xml
(
char *xml_file, /* Filename and path */
IPACM_firewall_conf_t *config /* Mobile AP config data */
);
#ifdef __cplusplus
}
#endif
#endif //IPACM_XML

View file

@ -1,216 +0,0 @@
/*
Copyright (c) 2013-2018, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_CmdQueue.cpp
@brief
This file implements the IPAM Comment Queue functionality
@Author
Sunil
*/
#include <string.h>
#include "IPACM_CmdQueue.h"
#include "IPACM_Log.h"
#include "IPACM_Iface.h"
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond_var = PTHREAD_COND_INITIALIZER;
MessageQueue* MessageQueue::inst_internal = NULL;
MessageQueue* MessageQueue::inst_external = NULL;
MessageQueue* MessageQueue::getInstanceInternal()
{
if(inst_internal == NULL)
{
inst_internal = new MessageQueue();
if(inst_internal == NULL)
{
IPACMERR("unable to create internal Message Queue instance\n");
return NULL;
}
}
return inst_internal;
}
MessageQueue* MessageQueue::getInstanceExternal()
{
if(inst_external == NULL)
{
inst_external = new MessageQueue();
if(inst_external == NULL)
{
IPACMERR("unable to create external Message Queue instance\n");
return NULL;
}
}
return inst_external;
}
void MessageQueue::enqueue(Message *item)
{
if(!Head)
{
Tail = item;
Head = item;
}
else
{
if(Tail == NULL)
{
IPACMDBG("Tail is null\n");
Head->setnext(item);
}
else
{
Tail->setnext(item);
}
Tail = item;
}
}
Message* MessageQueue::dequeue(void)
{
if(Head == NULL)
{
return NULL;
}
else
{
Message *tmp = Head;
Head = Head->getnext();
return tmp;
}
}
void* MessageQueue::Process(void *param)
{
MessageQueue *MsgQueueInternal = NULL;
MessageQueue *MsgQueueExternal = NULL;
Message *item = NULL;
param = NULL;
const char *eventName = NULL;
IPACMDBG("MessageQueue::Process()\n");
MsgQueueInternal = MessageQueue::getInstanceInternal();
if(MsgQueueInternal == NULL)
{
IPACMERR("unable to start internal cmd queue process\n");
return NULL;
}
MsgQueueExternal = MessageQueue::getInstanceExternal();
if(MsgQueueExternal == NULL)
{
IPACMERR("unable to start external cmd queue process\n");
return NULL;
}
while(1)
{
if(pthread_mutex_lock(&mutex) != 0)
{
IPACMERR("unable to lock the mutex\n");
return NULL;
}
item = MsgQueueInternal->dequeue();
if(item == NULL)
{
item = MsgQueueExternal->dequeue();
if(item)
{
eventName = IPACM_Iface::ipacmcfg->getEventName(item->evt.data.event);
if (eventName != NULL)
{
IPACMDBG("Get event %s from external queue.\n",
eventName);
}
}
}
else
{
eventName = IPACM_Iface::ipacmcfg->getEventName(item->evt.data.event);
if (eventName != NULL)
{
IPACMDBG("Get event %s from internal queue.\n",
eventName);
}
}
if(item == NULL)
{
IPACMDBG("Waiting for Message\n");
if(pthread_cond_wait(&cond_var, &mutex) != 0)
{
IPACMERR("unable to lock the mutex\n");
if(pthread_mutex_unlock(&mutex) != 0)
{
IPACMERR("unable to unlock the mutex\n");
return NULL;
}
return NULL;
}
if(pthread_mutex_unlock(&mutex) != 0)
{
IPACMERR("unable to unlock the mutex\n");
return NULL;
}
}
else
{
if(pthread_mutex_unlock(&mutex) != 0)
{
IPACMERR("unable to unlock the mutex\n");
return NULL;
}
IPACMDBG("Processing item %pK event ID: %d\n",item,item->evt.data.event);
item->evt.callback_ptr(&item->evt.data);
delete item;
item = NULL;
}
} /* Go forever until a termination indication is received */
}

View file

@ -1,963 +0,0 @@
/*
Copyright (c) 2013-2019, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_Config.cpp
@brief
This file implements the IPACM Configuration from XML file
@Author
Skylar Chang
*/
#include <IPACM_Config.h>
#include <IPACM_Log.h>
#include <IPACM_Iface.h>
#include <sys/ioctl.h>
#include <fcntl.h>
IPACM_Config *IPACM_Config::pInstance = NULL;
const char *IPACM_Config::DEVICE_NAME = "/dev/ipa";
const char *IPACM_Config::DEVICE_NAME_ODU = "/dev/odu_ipa_bridge";
#define __stringify(x...) #x
const char *ipacm_event_name[] = {
__stringify(IPA_CFG_CHANGE_EVENT), /* NULL */
__stringify(IPA_PRIVATE_SUBNET_CHANGE_EVENT), /* ipacm_event_data_fid */
__stringify(IPA_FIREWALL_CHANGE_EVENT), /* NULL */
__stringify(IPA_LINK_UP_EVENT), /* ipacm_event_data_fid */
__stringify(IPA_LINK_DOWN_EVENT), /* ipacm_event_data_fid */
__stringify(IPA_USB_LINK_UP_EVENT), /* ipacm_event_data_fid */
__stringify(IPA_BRIDGE_LINK_UP_EVENT), /* ipacm_event_data_all */
__stringify(IPA_WAN_EMBMS_LINK_UP_EVENT), /* ipacm_event_data_mac */
__stringify(IPA_ADDR_ADD_EVENT), /* ipacm_event_data_addr */
__stringify(IPA_ADDR_DEL_EVENT), /* no use */
__stringify(IPA_ROUTE_ADD_EVENT), /* ipacm_event_data_addr */
__stringify(IPA_ROUTE_DEL_EVENT), /* ipacm_event_data_addr */
__stringify(IPA_WAN_UPSTREAM_ROUTE_ADD_EVENT), /* ipacm_event_data_fid */
__stringify(IPA_WAN_UPSTREAM_ROUTE_DEL_EVENT), /* ipacm_event_data_fid */
__stringify(IPA_WLAN_AP_LINK_UP_EVENT), /* ipacm_event_data_mac */
__stringify(IPA_WLAN_STA_LINK_UP_EVENT), /* ipacm_event_data_mac */
__stringify(IPA_WLAN_LINK_DOWN_EVENT), /* ipacm_event_data_mac */
__stringify(IPA_WLAN_CLIENT_ADD_EVENT), /* ipacm_event_data_mac */
__stringify(IPA_WLAN_CLIENT_ADD_EVENT_EX), /* ipacm_event_data_wlan_ex */
__stringify(IPA_WLAN_CLIENT_DEL_EVENT), /* ipacm_event_data_mac */
__stringify(IPA_WLAN_CLIENT_POWER_SAVE_EVENT), /* ipacm_event_data_mac */
__stringify(IPA_WLAN_CLIENT_RECOVER_EVENT), /* ipacm_event_data_mac */
__stringify(IPA_NEW_NEIGH_EVENT), /* ipacm_event_data_all */
__stringify(IPA_DEL_NEIGH_EVENT), /* ipacm_event_data_all */
__stringify(IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT), /* ipacm_event_data_all */
__stringify(IPA_NEIGH_CLIENT_IP_ADDR_DEL_EVENT), /* ipacm_event_data_all */
__stringify(IPA_SW_ROUTING_ENABLE), /* NULL */
__stringify(IPA_SW_ROUTING_DISABLE), /* NULL */
__stringify(IPA_PROCESS_CT_MESSAGE), /* ipacm_ct_evt_data */
__stringify(IPA_PROCESS_CT_MESSAGE_V6), /* ipacm_ct_evt_data */
__stringify(IPA_LAN_TO_LAN_NEW_CONNECTION), /* ipacm_event_connection */
__stringify(IPA_LAN_TO_LAN_DEL_CONNECTION), /* ipacm_event_connection */
__stringify(IPA_WLAN_SWITCH_TO_SCC), /* No Data */
__stringify(IPA_WLAN_SWITCH_TO_MCC), /* No Data */
__stringify(IPA_CRADLE_WAN_MODE_SWITCH), /* ipacm_event_cradle_wan_mode */
__stringify(IPA_WAN_XLAT_CONNECT_EVENT), /* ipacm_event_data_fid */
__stringify(IPA_TETHERING_STATS_UPDATE_EVENT), /* ipacm_event_data_fid */
__stringify(IPA_NETWORK_STATS_UPDATE_EVENT), /* ipacm_event_data_fid */
__stringify(IPA_DOWNSTREAM_ADD), /* ipacm_event_ipahal_stream */
__stringify(IPA_DOWNSTREAM_DEL), /* ipacm_event_ipahal_stream */
__stringify(IPA_EXTERNAL_EVENT_MAX),
__stringify(IPA_HANDLE_WAN_UP), /* ipacm_event_iface_up */
__stringify(IPA_HANDLE_WAN_DOWN), /* ipacm_event_iface_up */
__stringify(IPA_HANDLE_WAN_UP_V6), /* NULL */
__stringify(IPA_HANDLE_WAN_DOWN_V6), /* NULL */
__stringify(IPA_HANDLE_WAN_UP_TETHER), /* ipacm_event_iface_up_tehter */
__stringify(IPA_HANDLE_WAN_DOWN_TETHER), /* ipacm_event_iface_up_tehter */
__stringify(IPA_HANDLE_WAN_UP_V6_TETHER), /* ipacm_event_iface_up_tehter */
__stringify(IPA_HANDLE_WAN_DOWN_V6_TETHER), /* ipacm_event_iface_up_tehter */
__stringify(IPA_HANDLE_WLAN_UP), /* ipacm_event_iface_up */
__stringify(IPA_HANDLE_LAN_UP), /* ipacm_event_iface_up */
__stringify(IPA_ETH_BRIDGE_IFACE_UP), /* ipacm_event_eth_bridge*/
__stringify(IPA_ETH_BRIDGE_IFACE_DOWN), /* ipacm_event_eth_bridge*/
__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_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 */
__stringify(IPA_ADD_L2TP_VLAN_MAPPING), /* ipa_ioc_l2tp_vlan_mapping_info */
__stringify(IPA_DEL_L2TP_VLAN_MAPPING), /* ipa_ioc_l2tp_vlan_mapping_info */
__stringify(IPA_VLAN_CLIENT_INFO), /* ipacm_event_data_all */
__stringify(IPA_VLAN_IFACE_INFO), /* ipacm_event_data_all */
#endif
__stringify(IPA_WLAN_FWR_SSR_BEFORE_SHUTDOWN_NOTICE), /* ipacm_event_iface*/
__stringify(IPA_LAN_DELETE_SELF), /* ipacm_event_data_fid */
__stringify(IPA_WIGIG_CLIENT_ADD_EVENT), /* ipacm_event_data_mac_ep */
__stringify(IPA_WIGIG_FST_SWITCH), /* ipacm_event_data_fst */
__stringify(IPACM_EVENT_MAX),
};
IPACM_Config::IPACM_Config()
{
iface_table = NULL;
alg_table = NULL;
pNatIfaces = NULL;
memset(&ipa_client_rm_map_tbl, 0, sizeof(ipa_client_rm_map_tbl));
memset(&ipa_rm_tbl, 0, sizeof(ipa_rm_tbl));
ipa_rm_a2_check=0;
ipacm_odu_enable = false;
ipacm_odu_router_mode = false;
ipa_num_wlan_guest_ap = 0;
ipa_num_ipa_interfaces = 0;
ipa_num_private_subnet = 0;
ipa_num_alg_ports = 0;
ipa_nat_max_entries = 0;
ipa_nat_iface_entries = 0;
ipa_sw_rt_enable = false;
ipa_bridge_enable = false;
isMCC_Mode = false;
ipa_max_valid_rm_entry = 0;
/* IPA_HW_FNR_STATS */
hw_fnr_stats_support = false;
hw_counter_offset = 0;
sw_counter_offset = 0;
memset(&rt_tbl_default_v4, 0, sizeof(rt_tbl_default_v4));
memset(&rt_tbl_lan_v4, 0, sizeof(rt_tbl_lan_v4));
memset(&rt_tbl_wan_v4, 0, sizeof(rt_tbl_wan_v4));
memset(&rt_tbl_v6, 0, sizeof(rt_tbl_v6));
memset(&rt_tbl_wan_v6, 0, sizeof(rt_tbl_wan_v6));
memset(&rt_tbl_wan_dl, 0, sizeof(rt_tbl_wan_dl));
memset(&rt_tbl_odu_v4, 0, sizeof(rt_tbl_odu_v4));
memset(&rt_tbl_odu_v6, 0, sizeof(rt_tbl_odu_v6));
memset(&ext_prop_v4, 0, sizeof(ext_prop_v4));
memset(&ext_prop_v6, 0, sizeof(ext_prop_v6));
qmap_id = ~0;
memset(flt_rule_count_v4, 0, IPA_CLIENT_MAX*sizeof(int));
memset(flt_rule_count_v6, 0, IPA_CLIENT_MAX*sizeof(int));
memset(bridge_mac, 0, IPA_MAC_ADDR_SIZE*sizeof(uint8_t));
IPACMDBG_H(" create IPACM_Config constructor\n");
return;
}
int IPACM_Config::Init(void)
{
/* Read IPACM Config file */
char IPACM_config_file[IPA_MAX_FILE_LEN];
IPACM_conf_t *cfg;
cfg = (IPACM_conf_t *)malloc(sizeof(IPACM_conf_t));
if(cfg == NULL)
{
IPACMERR("Unable to allocate cfg memory.\n");
return IPACM_FAILURE;
}
uint32_t subnet_addr;
uint32_t subnet_mask;
int i, ret = IPACM_SUCCESS;
struct in_addr in_addr_print;
m_fd = open(DEVICE_NAME, O_RDWR);
if (0 > m_fd)
{
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
strlcpy(IPACM_config_file, "/etc/IPACM_cfg.xml", sizeof(IPACM_config_file));
#endif
IPACMDBG_H("\n IPACM XML file is %s \n", IPACM_config_file);
if (IPACM_SUCCESS == ipacm_read_cfg_xml(IPACM_config_file, cfg))
{
IPACMDBG_H("\n IPACM XML read OK \n");
}
else
{
IPACMERR("\n IPACM XML read failed \n");
ret = IPACM_FAILURE;
goto fail;
}
/* Construct IPACM Iface table */
ipa_num_ipa_interfaces = cfg->iface_config.num_iface_entries;
if (iface_table != NULL)
{
free(iface_table);
iface_table = NULL;
IPACMDBG_H("RESET IPACM_Config::iface_table\n");
}
iface_table = (ipa_ifi_dev_name_t *)calloc(ipa_num_ipa_interfaces,
sizeof(ipa_ifi_dev_name_t));
if(iface_table == NULL)
{
IPACMERR("Unable to allocate iface_table memory.\n");
ret = IPACM_FAILURE;
goto fail;
}
for (i = 0; i < cfg->iface_config.num_iface_entries; i++)
{
strlcpy(iface_table[i].iface_name, cfg->iface_config.iface_entries[i].iface_name, sizeof(iface_table[i].iface_name));
iface_table[i].if_cat = cfg->iface_config.iface_entries[i].if_cat;
iface_table[i].if_mode = cfg->iface_config.iface_entries[i].if_mode;
iface_table[i].wlan_mode = cfg->iface_config.iface_entries[i].wlan_mode;
IPACMDBG_H("IPACM_Config::iface_table[%d] = %s, cat=%d, mode=%d wlan-mode=%d \n", i, iface_table[i].iface_name,
iface_table[i].if_cat, iface_table[i].if_mode, iface_table[i].wlan_mode);
/* copy bridge interface name to ipacmcfg */
if( iface_table[i].if_cat == VIRTUAL_IF)
{
strlcpy(ipa_virtual_iface_name, iface_table[i].iface_name, sizeof(ipa_virtual_iface_name));
IPACMDBG_H("ipa_virtual_iface_name(%s) \n", ipa_virtual_iface_name);
}
}
/* Construct IPACM Private_Subnet table */
memset(&private_subnet_table, 0, sizeof(private_subnet_table));
ipa_num_private_subnet = cfg->private_subnet_config.num_subnet_entries;
for (i = 0; i < cfg->private_subnet_config.num_subnet_entries; i++)
{
memcpy(&private_subnet_table[i].subnet_addr,
&cfg->private_subnet_config.private_subnet_entries[i].subnet_addr,
sizeof(cfg->private_subnet_config.private_subnet_entries[i].subnet_addr));
memcpy(&private_subnet_table[i].subnet_mask,
&cfg->private_subnet_config.private_subnet_entries[i].subnet_mask,
sizeof(cfg->private_subnet_config.private_subnet_entries[i].subnet_mask));
subnet_addr = htonl(private_subnet_table[i].subnet_addr);
memcpy(&in_addr_print,&subnet_addr,sizeof(in_addr_print));
IPACMDBG_H("%dst::private_subnet_table= %s \n ", i,
inet_ntoa(in_addr_print));
subnet_mask = htonl(private_subnet_table[i].subnet_mask);
memcpy(&in_addr_print,&subnet_mask,sizeof(in_addr_print));
IPACMDBG_H("%dst::private_subnet_table= %s \n ", i,
inet_ntoa(in_addr_print));
}
/* Construct IPACM ALG table */
ipa_num_alg_ports = cfg->alg_config.num_alg_entries;
if (alg_table != NULL)
{
free(alg_table);
alg_table = NULL;
IPACMDBG_H("RESET IPACM_Config::alg_table \n");
}
alg_table = (ipacm_alg *)calloc(ipa_num_alg_ports,
sizeof(ipacm_alg));
if(alg_table == NULL)
{
IPACMERR("Unable to allocate alg_table memory.\n");
ret = IPACM_FAILURE;
free(iface_table);
goto fail;;
}
for (i = 0; i < cfg->alg_config.num_alg_entries; i++)
{
alg_table[i].protocol = cfg->alg_config.alg_entries[i].protocol;
alg_table[i].port = cfg->alg_config.alg_entries[i].port;
IPACMDBG_H("IPACM_Config::ipacm_alg[%d] = %d, port=%d\n", i, alg_table[i].protocol, alg_table[i].port);
}
ipa_nat_max_entries = cfg->nat_max_entries;
IPACMDBG_H("Nat Maximum Entries %d\n", ipa_nat_max_entries);
/* Find ODU is either router mode or bridge mode*/
ipacm_odu_enable = cfg->odu_enable;
ipacm_odu_router_mode = cfg->router_mode_enable;
ipacm_odu_embms_enable = cfg->odu_embms_enable;
IPACMDBG_H("ipacm_odu_enable %d\n", ipacm_odu_enable);
IPACMDBG_H("ipacm_odu_mode %d\n", ipacm_odu_router_mode);
IPACMDBG_H("ipacm_odu_embms_enable %d\n", ipacm_odu_embms_enable);
ipacm_ip_passthrough_mode = cfg->ip_passthrough_mode;
IPACMDBG_H("ipacm_ip_passthrough_mode %d. \n", ipacm_ip_passthrough_mode);
ipa_num_wlan_guest_ap = cfg->num_wlan_guest_ap;
IPACMDBG_H("ipa_num_wlan_guest_ap %d\n",ipa_num_wlan_guest_ap);
/* Allocate more non-nat entries if the monitored iface dun have Tx/Rx properties */
if (pNatIfaces != NULL)
{
free(pNatIfaces);
pNatIfaces = NULL;
IPACMDBG_H("RESET IPACM_Config::pNatIfaces \n");
}
ipa_nat_iface_entries = 0;
pNatIfaces = (NatIfaces *)calloc(ipa_num_ipa_interfaces, sizeof(NatIfaces));
if (pNatIfaces == NULL)
{
IPACMERR("unable to allocate nat ifaces\n");
ret = IPACM_FAILURE;
free(iface_table);
free(alg_table);
goto fail;
}
/* Construct the routing table ictol name in iface static member*/
rt_tbl_default_v4.ip = IPA_IP_v4;
strlcpy(rt_tbl_default_v4.name, V4_DEFAULT_ROUTE_TABLE_NAME, sizeof(rt_tbl_default_v4.name));
rt_tbl_lan_v4.ip = IPA_IP_v4;
strlcpy(rt_tbl_lan_v4.name, V4_LAN_ROUTE_TABLE_NAME, sizeof(rt_tbl_lan_v4.name));
rt_tbl_wan_v4.ip = IPA_IP_v4;
strlcpy(rt_tbl_wan_v4.name, V4_WAN_ROUTE_TABLE_NAME, sizeof(rt_tbl_wan_v4.name));
rt_tbl_v6.ip = IPA_IP_v6;
strlcpy(rt_tbl_v6.name, V6_COMMON_ROUTE_TABLE_NAME, sizeof(rt_tbl_v6.name));
rt_tbl_wan_v6.ip = IPA_IP_v6;
strlcpy(rt_tbl_wan_v6.name, V6_WAN_ROUTE_TABLE_NAME, sizeof(rt_tbl_wan_v6.name));
rt_tbl_odu_v4.ip = IPA_IP_v4;
strlcpy(rt_tbl_odu_v4.name, V4_ODU_ROUTE_TABLE_NAME, sizeof(rt_tbl_odu_v4.name));
rt_tbl_odu_v6.ip = IPA_IP_v6;
strlcpy(rt_tbl_odu_v6.name, V6_ODU_ROUTE_TABLE_NAME, sizeof(rt_tbl_odu_v6.name));
rt_tbl_wan_dl.ip = IPA_IP_MAX;
strlcpy(rt_tbl_wan_dl.name, WAN_DL_ROUTE_TABLE_NAME, sizeof(rt_tbl_wan_dl.name));
/* Construct IPACM ipa_client map to rm_resource table */
ipa_client_rm_map_tbl[IPA_CLIENT_WLAN1_PROD]= IPA_RM_RESOURCE_WLAN_PROD;
ipa_client_rm_map_tbl[IPA_CLIENT_USB_PROD]= IPA_RM_RESOURCE_USB_PROD;
ipa_client_rm_map_tbl[IPA_CLIENT_A5_WLAN_AMPDU_PROD]= IPA_RM_RESOURCE_HSIC_PROD;
ipa_client_rm_map_tbl[IPA_CLIENT_A2_EMBEDDED_PROD]= IPA_RM_RESOURCE_Q6_PROD;
ipa_client_rm_map_tbl[IPA_CLIENT_A2_TETHERED_PROD]= IPA_RM_RESOURCE_Q6_PROD;
ipa_client_rm_map_tbl[IPA_CLIENT_APPS_LAN_WAN_PROD]= IPA_RM_RESOURCE_Q6_PROD;
ipa_client_rm_map_tbl[IPA_CLIENT_WLAN1_CONS]= IPA_RM_RESOURCE_WLAN_CONS;
ipa_client_rm_map_tbl[IPA_CLIENT_WLAN2_CONS]= IPA_RM_RESOURCE_WLAN_CONS;
ipa_client_rm_map_tbl[IPA_CLIENT_WLAN3_CONS]= IPA_RM_RESOURCE_WLAN_CONS;
ipa_client_rm_map_tbl[IPA_CLIENT_WLAN4_CONS]= IPA_RM_RESOURCE_WLAN_CONS;
ipa_client_rm_map_tbl[IPA_CLIENT_USB_CONS]= IPA_RM_RESOURCE_USB_CONS;
ipa_client_rm_map_tbl[IPA_CLIENT_A2_EMBEDDED_CONS]= IPA_RM_RESOURCE_Q6_CONS;
ipa_client_rm_map_tbl[IPA_CLIENT_A2_TETHERED_CONS]= IPA_RM_RESOURCE_Q6_CONS;
ipa_client_rm_map_tbl[IPA_CLIENT_APPS_WAN_CONS]= IPA_RM_RESOURCE_Q6_CONS;
ipa_client_rm_map_tbl[IPA_CLIENT_ODU_PROD]= IPA_RM_RESOURCE_ODU_ADAPT_PROD;
ipa_client_rm_map_tbl[IPA_CLIENT_ODU_EMB_CONS]= IPA_RM_RESOURCE_ODU_ADAPT_CONS;
ipa_client_rm_map_tbl[IPA_CLIENT_ODU_TETH_CONS]= IPA_RM_RESOURCE_ODU_ADAPT_CONS;
/* Create the entries which IPACM wants to add dependencies on */
ipa_rm_tbl[0].producer_rm1 = IPA_RM_RESOURCE_WLAN_PROD;
ipa_rm_tbl[0].consumer_rm1 = IPA_RM_RESOURCE_Q6_CONS;
ipa_rm_tbl[0].producer_rm2 = IPA_RM_RESOURCE_Q6_PROD;
ipa_rm_tbl[0].consumer_rm2 = IPA_RM_RESOURCE_WLAN_CONS;
ipa_rm_tbl[1].producer_rm1 = IPA_RM_RESOURCE_USB_PROD;
ipa_rm_tbl[1].consumer_rm1 = IPA_RM_RESOURCE_Q6_CONS;
ipa_rm_tbl[1].producer_rm2 = IPA_RM_RESOURCE_Q6_PROD;
ipa_rm_tbl[1].consumer_rm2 = IPA_RM_RESOURCE_USB_CONS;
ipa_rm_tbl[2].producer_rm1 = IPA_RM_RESOURCE_WLAN_PROD;
ipa_rm_tbl[2].consumer_rm1 = IPA_RM_RESOURCE_USB_CONS;
ipa_rm_tbl[2].producer_rm2 = IPA_RM_RESOURCE_USB_PROD;
ipa_rm_tbl[2].consumer_rm2 = IPA_RM_RESOURCE_WLAN_CONS;
ipa_rm_tbl[3].producer_rm1 = IPA_RM_RESOURCE_ODU_ADAPT_PROD;
ipa_rm_tbl[3].consumer_rm1 = IPA_RM_RESOURCE_Q6_CONS;
ipa_rm_tbl[3].producer_rm2 = IPA_RM_RESOURCE_Q6_PROD;
ipa_rm_tbl[3].consumer_rm2 = IPA_RM_RESOURCE_ODU_ADAPT_CONS;
ipa_rm_tbl[4].producer_rm1 = IPA_RM_RESOURCE_WLAN_PROD;
ipa_rm_tbl[4].consumer_rm1 = IPA_RM_RESOURCE_ODU_ADAPT_CONS;
ipa_rm_tbl[4].producer_rm2 = IPA_RM_RESOURCE_ODU_ADAPT_PROD;
ipa_rm_tbl[4].consumer_rm2 = IPA_RM_RESOURCE_WLAN_CONS;
ipa_rm_tbl[5].producer_rm1 = IPA_RM_RESOURCE_ODU_ADAPT_PROD;
ipa_rm_tbl[5].consumer_rm1 = IPA_RM_RESOURCE_USB_CONS;
ipa_rm_tbl[5].producer_rm2 = IPA_RM_RESOURCE_USB_PROD;
ipa_rm_tbl[5].consumer_rm2 = IPA_RM_RESOURCE_ODU_ADAPT_CONS;
ipa_max_valid_rm_entry = 6; /* max is IPA_MAX_RM_ENTRY (6)*/
IPACMDBG_H(" depend MAP-0 rm index %d to rm index: %d \n", IPA_RM_RESOURCE_WLAN_PROD, IPA_RM_RESOURCE_Q6_CONS);
IPACMDBG_H(" depend MAP-1 rm index %d to rm index: %d \n", IPA_RM_RESOURCE_USB_PROD, IPA_RM_RESOURCE_Q6_CONS);
IPACMDBG_H(" depend MAP-2 rm index %d to rm index: %d \n", IPA_RM_RESOURCE_WLAN_PROD, IPA_RM_RESOURCE_USB_CONS);
IPACMDBG_H(" depend MAP-3 rm index %d to rm index: %d \n", IPA_RM_RESOURCE_ODU_ADAPT_PROD, IPA_RM_RESOURCE_Q6_CONS);
IPACMDBG_H(" depend MAP-4 rm index %d to rm index: %d \n", IPA_RM_RESOURCE_WLAN_PROD, IPA_RM_RESOURCE_ODU_ADAPT_CONS);
IPACMDBG_H(" depend MAP-5 rm index %d to rm index: %d \n", IPA_RM_RESOURCE_ODU_ADAPT_PROD, IPA_RM_RESOURCE_USB_CONS);
fail:
if (cfg != NULL)
{
free(cfg);
cfg = NULL;
}
return ret;
}
IPACM_Config* IPACM_Config::GetInstance()
{
int res = IPACM_SUCCESS;
if (pInstance == NULL)
{
pInstance = new IPACM_Config();
res = pInstance->Init();
if (res != IPACM_SUCCESS)
{
delete pInstance;
IPACMERR("unable to initialize config instance\n");
return NULL;
}
}
return pInstance;
}
int IPACM_Config::GetAlgPorts(int nPorts, ipacm_alg *pAlgPorts)
{
if (nPorts <= 0 || pAlgPorts == NULL)
{
IPACMERR("Invalid input\n");
return -1;
}
for (int cnt = 0; cnt < nPorts; cnt++)
{
pAlgPorts[cnt].protocol = alg_table[cnt].protocol;
pAlgPorts[cnt].port = alg_table[cnt].port;
}
return 0;
}
int IPACM_Config::GetNatIfaces(int nIfaces, NatIfaces *pIfaces)
{
if (nIfaces <= 0 || pIfaces == NULL)
{
IPACMERR("Invalid input\n");
return -1;
}
for (int cnt=0; cnt<nIfaces; cnt++)
{
memcpy(pIfaces[cnt].iface_name,
pNatIfaces[cnt].iface_name,
sizeof(pIfaces[cnt].iface_name));
}
return 0;
}
int IPACM_Config::AddNatIfaces(char *dev_name, ipa_ip_type ip_type)
{
int i;
/* Check if this iface already in NAT-iface*/
for(i = 0; i < ipa_nat_iface_entries; i++)
{
if(strncmp(dev_name,
pNatIfaces[i].iface_name,
sizeof(pNatIfaces[i].iface_name)) == 0)
{
IPACMDBG_H("Interface (%s) is add to nat iface already\n", dev_name);
if (ip_type == IPA_IP_v4) {
pNatIfaces[i].v4_up = true;
IPACMDBG_H("Change v4_up to (%d) \n", pNatIfaces[i].v4_up);
}
if (ip_type == IPA_IP_v6) {
pNatIfaces[i].v6_up = true;
IPACMDBG_H("Change v6_up to (%d) \n", pNatIfaces[i].v6_up);
}
return 0;
}
}
IPACMDBG_H("Add iface %s to NAT-ifaces, origin it has %d nat ifaces\n",
dev_name, ipa_nat_iface_entries);
ipa_nat_iface_entries++;
if (ipa_nat_iface_entries < ipa_num_ipa_interfaces)
{
strlcpy(pNatIfaces[ipa_nat_iface_entries - 1].iface_name,
dev_name, IPA_IFACE_NAME_LEN);
IPACMDBG_H("Add Nat IfaceName: %s ,update nat-ifaces number: %d\n",
pNatIfaces[ipa_nat_iface_entries - 1].iface_name,
ipa_nat_iface_entries);
if (ip_type == IPA_IP_v4) {
pNatIfaces[ipa_nat_iface_entries - 1].v4_up = true;
IPACMDBG_H("Change v4_up to (%d) \n", pNatIfaces[ipa_nat_iface_entries - 1].v4_up);
}
if (ip_type == IPA_IP_v6) {
pNatIfaces[ipa_nat_iface_entries - 1].v6_up = true;
IPACMDBG_H("Change v6_up to (%d) \n", pNatIfaces[ipa_nat_iface_entries - 1].v6_up);
}
}
return 0;
}
int IPACM_Config::DelNatIfaces(char *dev_name)
{
int i = 0;
IPACMDBG_H("Del iface %s from NAT-ifaces, origin it has %d nat ifaces\n",
dev_name, ipa_nat_iface_entries);
for (i = 0; i < ipa_nat_iface_entries; i++)
{
if (strcmp(dev_name, pNatIfaces[i].iface_name) == 0)
{
IPACMDBG_H("Found Nat IfaceName: %s with nat-ifaces number: %d\n",
pNatIfaces[i].iface_name, ipa_nat_iface_entries);
/* Reset the matched entry */
memset(pNatIfaces[i].iface_name, 0, IPA_IFACE_NAME_LEN);
pNatIfaces[i].v4_up = false;
pNatIfaces[i].v6_up = false;
for (; i < ipa_nat_iface_entries - 1; i++)
{
memcpy(pNatIfaces[i].iface_name,
pNatIfaces[i + 1].iface_name, IPA_IFACE_NAME_LEN);
pNatIfaces[i].v4_up = pNatIfaces[i + 1].v4_up;
pNatIfaces[i].v6_up = pNatIfaces[i + 1].v6_up;
/* Reset the copied entry */
memset(pNatIfaces[i + 1].iface_name, 0, IPA_IFACE_NAME_LEN);
pNatIfaces[i + 1].v4_up = false;
pNatIfaces[i + 1].v6_up = false;
}
ipa_nat_iface_entries--;
IPACMDBG_H("Update nat-ifaces number: %d\n", ipa_nat_iface_entries);
return 0;
}
}
IPACMDBG_H("Can't find Nat IfaceName: %s with total nat-ifaces number: %d\n",
dev_name, ipa_nat_iface_entries);
return 0;
}
int IPACM_Config::CheckNatIfaces(const char *dev_name, ipa_ip_type ip_type)
{
int i = 0;
IPACMDBG_H("Check iface %s for ip-type %d from NAT-ifaces, currently it has %d nat ifaces\n",
dev_name, ip_type, ipa_nat_iface_entries);
for (i = 0; i < ipa_nat_iface_entries; i++)
{
if (strcmp(dev_name, pNatIfaces[i].iface_name) == 0)
{
IPACMDBG_H("Find Nat IfaceName: %s ,previous nat-ifaces number: %d, v4_up %d, v6_up %d \n",
pNatIfaces[i].iface_name, ipa_nat_iface_entries, pNatIfaces[i].v4_up, pNatIfaces[i].v6_up);
if (ip_type == IPA_IP_v4 && pNatIfaces[i].v4_up == true)
{
IPACMDBG_H(" v4_up=%d\n", pNatIfaces[i].v4_up);
return 0;
}
if (ip_type == IPA_IP_v6 && pNatIfaces[i].v6_up == true)
{
IPACMDBG_H(" v6_up=%d\n", pNatIfaces[i].v6_up);
return 0;
}
return -1;
}
}
IPACMDBG_H("Can't find Nat IfaceName: %s for ip_type %d up with total nat-ifaces number: %d\n",
dev_name, ip_type, ipa_nat_iface_entries);
return -1;
}
/* for IPACM resource manager dependency usage
add either Tx or Rx ipa_rm_resource_name and
also indicate that endpoint property if valid */
void IPACM_Config::AddRmDepend(ipa_rm_resource_name rm1,bool rx_bypass_ipa)
{
int retval = 0;
struct ipa_ioc_rm_dependency dep;
IPACMDBG_H(" Got rm add-depend index : %d \n", rm1);
/* ipa_rm_a2_check: IPA_RM_RESOURCE_Q6_CONS*/
if(rm1 == IPA_RM_RESOURCE_Q6_CONS)
{
ipa_rm_a2_check+=1;
IPACMDBG_H("got %d times default RT routing from A2 \n", ipa_rm_a2_check);
}
for(int i=0;i<ipa_max_valid_rm_entry;i++)
{
if(rm1 == ipa_rm_tbl[i].producer_rm1)
{
ipa_rm_tbl[i].producer1_up = true;
/* entry1's producer actually dun have registered Rx-property */
ipa_rm_tbl[i].rx_bypass_ipa = rx_bypass_ipa;
IPACMDBG_H("Matched RM_table entry: %d's producer_rm1 with non_rx_prop: %d \n", i,ipa_rm_tbl[i].rx_bypass_ipa);
if(ipa_rm_tbl[i].consumer1_up == true && ipa_rm_tbl[i].rm_set == false)
{
IPACMDBG_H("SETUP RM_table entry %d's bi-direction dependency \n", i);
/* add bi-directional dependency*/
if(ipa_rm_tbl[i].rx_bypass_ipa)
{
IPACMDBG_H("Skip ADD entry %d's dependency between WLAN-Pro: %d, Con: %d \n", i, ipa_rm_tbl[i].producer_rm1,ipa_rm_tbl[i].consumer_rm1);
}
else
{
memset(&dep, 0, sizeof(dep));
dep.resource_name = ipa_rm_tbl[i].producer_rm1;
dep.depends_on_name = ipa_rm_tbl[i].consumer_rm1;
retval = ioctl(m_fd, IPA_IOC_RM_ADD_DEPENDENCY, &dep);
IPACMDBG_H("ADD entry %d's dependency between Pro: %d, Con: %d \n", i,dep.resource_name,dep.depends_on_name);
if (retval)
{
IPACMERR("Failed adding dependecny for RM_table entry %d's bi-direction dependency (error:%d) \n", i,retval);
}
}
memset(&dep, 0, sizeof(dep));
dep.resource_name = ipa_rm_tbl[i].producer_rm2;
dep.depends_on_name = ipa_rm_tbl[i].consumer_rm2;
retval = ioctl(m_fd, IPA_IOC_RM_ADD_DEPENDENCY, &dep);
IPACMDBG_H("ADD entry %d's dependency between Pro: %d, Con: %d \n", i,dep.resource_name,dep.depends_on_name);
if (retval)
{
IPACMERR("Failed adding dependecny for RM_table entry %d's bi-direction dependency (error:%d) \n", i,retval);
}
ipa_rm_tbl[i].rm_set = true;
}
else
{
IPACMDBG_H("Not SETUP RM_table entry %d: prod_up:%d, cons_up:%d, rm_set: %d \n", i,ipa_rm_tbl[i].producer1_up, ipa_rm_tbl[i].consumer1_up, ipa_rm_tbl[i].rm_set);
}
}
if(rm1 == ipa_rm_tbl[i].consumer_rm1)
{
ipa_rm_tbl[i].consumer1_up = true;
IPACMDBG_H("Matched RM_table entry: %d's consumer_rm1 \n", i);
if(ipa_rm_tbl[i].producer1_up == true && ipa_rm_tbl[i].rm_set == false)
{
IPACMDBG_H("SETUP RM_table entry %d's bi-direction dependency \n", i);
/* add bi-directional dependency*/
if(ipa_rm_tbl[i].rx_bypass_ipa)
{
IPACMDBG_H("Skip ADD entry %d's dependency between WLAN-Pro: %d, Con: %d \n", i, ipa_rm_tbl[i].producer_rm1,ipa_rm_tbl[i].consumer_rm1);
}
else
{
memset(&dep, 0, sizeof(dep));
dep.resource_name = ipa_rm_tbl[i].producer_rm1;
dep.depends_on_name = ipa_rm_tbl[i].consumer_rm1;
retval = ioctl(m_fd, IPA_IOC_RM_ADD_DEPENDENCY, &dep);
IPACMDBG_H("ADD entry %d's dependency between Pro: %d, Con: %d \n", i,dep.resource_name,dep.depends_on_name);
if (retval)
{
IPACMERR("Failed adding dependecny for RM_table entry %d's bi-direction dependency (error:%d) \n", i,retval);
}
}
memset(&dep, 0, sizeof(dep));
dep.resource_name = ipa_rm_tbl[i].producer_rm2;
dep.depends_on_name = ipa_rm_tbl[i].consumer_rm2;
retval = ioctl(m_fd, IPA_IOC_RM_ADD_DEPENDENCY, &dep);
IPACMDBG_H("ADD entry %d's dependency between Pro: %d, Con: %d \n", i,dep.resource_name,dep.depends_on_name);
if (retval)
{
IPACMERR("Failed adding dependecny for RM_table entry %d's bi-direction dependency (error:%d) \n", i,retval);
}
ipa_rm_tbl[i].rm_set = true;
}
else
{
IPACMDBG_H("Not SETUP RM_table entry %d: prod_up:%d, cons_up:%d, rm_set: %d \n", i,ipa_rm_tbl[i].producer1_up, ipa_rm_tbl[i].consumer1_up, ipa_rm_tbl[i].rm_set);
}
}
}
return ;
}
/* for IPACM resource manager dependency usage
delete either Tx or Rx ipa_rm_resource_name */
void IPACM_Config::DelRmDepend(ipa_rm_resource_name rm1)
{
int retval = 0;
struct ipa_ioc_rm_dependency dep;
IPACMDBG_H(" Got rm del-depend index : %d \n", rm1);
/* ipa_rm_a2_check: IPA_RM_RESOURCE_Q6_CONS*/
if(rm1 == IPA_RM_RESOURCE_Q6_CONS)
{
ipa_rm_a2_check-=1;
IPACMDBG_H("Left %d times default RT routing from A2 \n", ipa_rm_a2_check);
}
for(int i=0;i<ipa_max_valid_rm_entry;i++)
{
if(rm1 == ipa_rm_tbl[i].producer_rm1)
{
if(ipa_rm_tbl[i].rm_set == true)
{
IPACMDBG_H("Matched RM_table entry: %d's producer_rm1 and dependency is up \n", i);
ipa_rm_tbl[i].rm_set = false;
/* delete bi-directional dependency*/
if(ipa_rm_tbl[i].rx_bypass_ipa)
{
IPACMDBG_H("Skip DEL entry %d's dependency between WLAN-Pro: %d, Con: %d \n", i, ipa_rm_tbl[i].producer_rm1,ipa_rm_tbl[i].consumer_rm1);
}
else
{
memset(&dep, 0, sizeof(dep));
dep.resource_name = ipa_rm_tbl[i].producer_rm1;
dep.depends_on_name = ipa_rm_tbl[i].consumer_rm1;
retval = ioctl(m_fd, IPA_IOC_RM_DEL_DEPENDENCY, &dep);
IPACMDBG_H("Delete entry %d's dependency between Pro: %d, Con: %d \n", i,dep.resource_name,dep.depends_on_name);
if (retval)
{
IPACMERR("Failed deleting dependecny for RM_table entry %d's bi-direction dependency (error:%d) \n", i,retval);
}
}
memset(&dep, 0, sizeof(dep));
dep.resource_name = ipa_rm_tbl[i].producer_rm2;
dep.depends_on_name = ipa_rm_tbl[i].consumer_rm2;
retval = ioctl(m_fd, IPA_IOC_RM_DEL_DEPENDENCY, &dep);
IPACMDBG_H("Delete entry %d's dependency between Pro: %d, Con: %d \n", i,dep.resource_name,dep.depends_on_name);
if (retval)
{
IPACMERR("Failed deleting dependecny for RM_table entry %d's bi-direction dependency (error:%d) \n", i,retval);
}
}
ipa_rm_tbl[i].producer1_up = false;
ipa_rm_tbl[i].rx_bypass_ipa = false;
}
if(rm1 == ipa_rm_tbl[i].consumer_rm1)
{
/* ipa_rm_a2_check: IPA_RM_RESOURCE_!6_CONS*/
if(ipa_rm_tbl[i].consumer_rm1 == IPA_RM_RESOURCE_Q6_CONS && ipa_rm_a2_check == 1)
{
IPACMDBG_H(" still have %d default RT routing from A2 \n", ipa_rm_a2_check);
continue;
}
if(ipa_rm_tbl[i].rm_set == true)
{
IPACMDBG_H("Matched RM_table entry: %d's consumer_rm1 and dependency is up \n", i);
ipa_rm_tbl[i].rm_set = false;
/* delete bi-directional dependency*/
if(ipa_rm_tbl[i].rx_bypass_ipa)
{
IPACMDBG_H("Skip DEL entry %d's dependency between WLAN-Pro: %d, Con: %d \n", i, ipa_rm_tbl[i].producer_rm1,ipa_rm_tbl[i].consumer_rm1);
}
else
{
memset(&dep, 0, sizeof(dep));
dep.resource_name = ipa_rm_tbl[i].producer_rm1;
dep.depends_on_name = ipa_rm_tbl[i].consumer_rm1;
retval = ioctl(m_fd, IPA_IOC_RM_DEL_DEPENDENCY, &dep);
IPACMDBG_H("Delete entry %d's dependency between Pro: %d, Con: %d \n", i,dep.resource_name,dep.depends_on_name);
if (retval)
{
IPACMERR("Failed deleting dependecny for RM_table entry %d's bi-direction dependency (error:%d) \n", i,retval);
}
}
memset(&dep, 0, sizeof(dep));
dep.resource_name = ipa_rm_tbl[i].producer_rm2;
dep.depends_on_name = ipa_rm_tbl[i].consumer_rm2;
retval = ioctl(m_fd, IPA_IOC_RM_DEL_DEPENDENCY, &dep);
IPACMDBG_H("Delete entry %d's dependency between Pro: %d, Con: %d \n", i,dep.resource_name,dep.depends_on_name);
if (retval)
{
IPACMERR("Failed deleting dependecny for RM_table entry %d's bi-direction dependency (error:%d) \n", i,retval);
}
}
ipa_rm_tbl[i].consumer1_up = false;
}
}
return ;
}
int IPACM_Config::SetExtProp(ipa_ioc_query_intf_ext_props *prop)
{
int i, num;
if(prop == NULL || prop->num_ext_props <= 0)
{
IPACMERR("There is no extended property!\n");
return IPACM_FAILURE;
}
num = prop->num_ext_props;
for(i=0; i<num; i++)
{
if(prop->ext[i].ip == IPA_IP_v4)
{
if(ext_prop_v4.num_ext_props >= MAX_NUM_EXT_PROPS)
{
IPACMERR("IPv4 extended property table is full!\n");
continue;
}
memcpy(&ext_prop_v4.prop[ext_prop_v4.num_ext_props], &prop->ext[i], sizeof(struct ipa_ioc_ext_intf_prop));
ext_prop_v4.num_ext_props++;
}
else if(prop->ext[i].ip == IPA_IP_v6)
{
if(ext_prop_v6.num_ext_props >= MAX_NUM_EXT_PROPS)
{
IPACMERR("IPv6 extended property table is full!\n");
continue;
}
memcpy(&ext_prop_v6.prop[ext_prop_v6.num_ext_props], &prop->ext[i], sizeof(struct ipa_ioc_ext_intf_prop));
ext_prop_v6.num_ext_props++;
}
else
{
IPACMERR("The IP type is not expected!\n");
return IPACM_FAILURE;
}
}
IPACMDBG_H("Set extended property succeeded.\n");
return IPACM_SUCCESS;
}
ipacm_ext_prop* IPACM_Config::GetExtProp(ipa_ip_type ip_type)
{
if(ip_type == IPA_IP_v4)
return &ext_prop_v4;
else if(ip_type == IPA_IP_v6)
return &ext_prop_v6;
else
{
IPACMERR("Failed to get extended property: the IP version is neither IPv4 nor IPv6!\n");
return NULL;
}
}
int IPACM_Config::DelExtProp(ipa_ip_type ip_type)
{
if(ip_type != IPA_IP_v6)
{
memset(&ext_prop_v4, 0, sizeof(ext_prop_v4));
}
if(ip_type != IPA_IP_v4)
{
memset(&ext_prop_v6, 0, sizeof(ext_prop_v6));
}
return IPACM_SUCCESS;
}
const char* IPACM_Config::getEventName(ipa_cm_event_id event_id)
{
if(event_id >= sizeof(ipacm_event_name)/sizeof(ipacm_event_name[0]))
{
IPACMERR("Event name array is not consistent with event array!\n");
return NULL;
}
return ipacm_event_name[event_id];
}
enum ipa_hw_type IPACM_Config::GetIPAVer(bool get)
{
int ret;
if(!get)
return ver;
ret = ioctl(m_fd, IPA_IOC_GET_HW_VERSION, &ver);
if(ret != 0)
{
IPACMERR("Failed to get IPA version with error %d.\n", ret);
ver = IPA_HW_None;
return IPA_HW_None;
}
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);
}

View file

@ -1,751 +0,0 @@
/*
Copyright (c) 2013-2018, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#ifndef in_addr_t
typedef uint32_t in_addr_t;
#endif
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include "IPACM_Iface.h"
#include "IPACM_ConntrackListener.h"
#include "IPACM_ConntrackClient.h"
#include "IPACM_Log.h"
#define LO_NAME "lo"
extern IPACM_EvtDispatcher cm_dis;
extern void ParseCTMessage(struct nf_conntrack *ct);
IPACM_ConntrackClient *IPACM_ConntrackClient::pInstance = NULL;
IPACM_ConntrackListener *CtList = NULL;
/* ================================
Local Function Definitions
=================================
*/
IPACM_ConntrackClient::IPACM_ConntrackClient()
{
IPACMDBG("\n");
tcp_hdl = NULL;
udp_hdl = NULL;
tcp_filter = NULL;
udp_filter = NULL;
fd_tcp = -1;
fd_udp = -1;
subscrips_tcp = NF_NETLINK_CONNTRACK_UPDATE | NF_NETLINK_CONNTRACK_DESTROY;
subscrips_udp = NF_NETLINK_CONNTRACK_NEW | NF_NETLINK_CONNTRACK_DESTROY;
}
IPACM_ConntrackClient* IPACM_ConntrackClient::GetInstance()
{
if(pInstance == NULL)
{
pInstance = new IPACM_ConntrackClient();
pInstance->udp_filter = nfct_filter_create();
if(pInstance->udp_filter == NULL)
{
IPACMERR("unable to create UDP filter\n");
delete pInstance;
return NULL;
}
IPACMDBG("Created UDP filter\n");
pInstance->tcp_filter = nfct_filter_create();
if(pInstance->tcp_filter == NULL)
{
IPACMERR("unable to create TCP filter\n");
delete pInstance;
return NULL;
}
IPACMDBG("Created TCP filter\n");
}
return pInstance;
}
int IPACM_ConntrackClient::IPAConntrackEventCB
(
enum nf_conntrack_msg_type type,
struct nf_conntrack *ct,
void *data
)
{
ipacm_cmd_q_data evt_data;
ipacm_ct_evt_data *ct_data;
uint8_t ip_type = 0;
data = NULL;
IPACMDBG("Event callback called with msgtype: %d\n",type);
/* Retrieve ip type */
ip_type = nfct_get_attr_u8(ct, ATTR_REPL_L3PROTO);
#ifndef CT_OPT
if(AF_INET6 == ip_type)
{
IPACMDBG("Ignoring ipv6(%d) connections\n", ip_type);
goto IGNORE;
}
#endif
ct_data = (ipacm_ct_evt_data *)malloc(sizeof(ipacm_ct_evt_data));
if(ct_data == NULL)
{
IPACMERR("unable to allocate memory \n");
goto IGNORE;
}
ct_data->ct = ct;
ct_data->type = type;
evt_data.event = IPA_PROCESS_CT_MESSAGE;
evt_data.evt_data = (void *)ct_data;
#ifdef CT_OPT
if(AF_INET6 == ip_type)
{
evt_data.event = IPA_PROCESS_CT_MESSAGE_V6;
}
#endif
if(0 != IPACM_EvtDispatcher::PostEvt(&evt_data))
{
IPACMERR("Error sending Conntrack message to processing thread!\n");
free(ct_data);
goto IGNORE;
}
/* NFCT_CB_STOLEN means that the conntrack object is not released after the
callback That must be manually done later when the object is no longer needed. */
return NFCT_CB_STOLEN;
IGNORE:
nfct_destroy(ct);
return NFCT_CB_STOLEN;
}
int IPACM_ConntrackClient::IPA_Conntrack_Filters_Ignore_Bridge_Addrs
(
struct nfct_filter *filter
)
{
int fd;
fd = socket(AF_INET, SOCK_DGRAM, 0);
if(fd < 0)
{
PERROR("unable to open socket");
return -1;
}
int ret;
uint32_t ipv4_addr;
struct ifreq ifr;
/* retrieve bridge interface ipv4 address */
memset(&ifr, 0, sizeof(struct ifreq));
ifr.ifr_addr.sa_family = AF_INET;
if(strlen(IPACM_Iface::ipacmcfg->ipa_virtual_iface_name) >= sizeof(ifr.ifr_name))
{
IPACMERR("interface name overflows: len %zu\n",
strlen(IPACM_Iface::ipacmcfg->ipa_virtual_iface_name));
close(fd);
return -1;
}
(void)strlcpy(ifr.ifr_name, IPACM_Iface::ipacmcfg->ipa_virtual_iface_name, sizeof(ifr.ifr_name));
IPACMDBG("bridge interface name (%s)\n", ifr.ifr_name);
ret = ioctl(fd, SIOCGIFADDR, &ifr);
if (ret < 0)
{
IPACMERR("unable to retrieve (%s) interface address\n",ifr.ifr_name);
close(fd);
return -1;
}
IPACMDBG("Interface (%s) address %s\n", ifr.ifr_name, inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr));
ipv4_addr = ntohl(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr);
close(fd);
/* ignore whatever is destined to or originates from broadcast ip address */
struct nfct_filter_ipv4 filter_ipv4;
filter_ipv4.addr = ipv4_addr;
filter_ipv4.mask = 0xffffffff;
nfct_filter_set_logic(filter,
NFCT_FILTER_DST_IPV4,
NFCT_FILTER_LOGIC_NEGATIVE);
nfct_filter_add_attr(filter, NFCT_FILTER_DST_IPV4, &filter_ipv4);
nfct_filter_set_logic(filter,
NFCT_FILTER_SRC_IPV4,
NFCT_FILTER_LOGIC_NEGATIVE);
nfct_filter_add_attr(filter, NFCT_FILTER_SRC_IPV4, &filter_ipv4);
return 0;
}
int IPACM_ConntrackClient::IPA_Conntrack_Filters_Ignore_Local_Iface
(
struct nfct_filter *filter,
ipacm_event_iface_up *param
)
{
struct nfct_filter_ipv4 filter_ipv4;
filter_ipv4.addr = param->ipv4_addr;
filter_ipv4.mask = 0xffffffff;
/* ignore whatever is destined to local interfaces */
IPACMDBG("Ignore connections destinated to interface %s", param->ifname);
iptodot("with ipv4 address", param->ipv4_addr);
nfct_filter_set_logic(filter,
NFCT_FILTER_DST_IPV4,
NFCT_FILTER_LOGIC_NEGATIVE);
nfct_filter_add_attr(filter, NFCT_FILTER_DST_IPV4, &filter_ipv4);
IPACMDBG("Ignore connections orignated from interface %s", param->ifname);
iptodot("with ipv4 address", filter_ipv4.addr);
nfct_filter_set_logic(filter,
NFCT_FILTER_SRC_IPV4,
NFCT_FILTER_LOGIC_NEGATIVE);
nfct_filter_add_attr(filter, NFCT_FILTER_SRC_IPV4, &filter_ipv4);
/* Retrieve broadcast address */
/* Intialize with 255.255.255.255 */
uint32_t bc_ip_addr = 0xFFFFFFFF;
/* calculate broadcast address from addr and addr_mask */
bc_ip_addr = (bc_ip_addr & (~param->addr_mask));
bc_ip_addr = (bc_ip_addr | (param->ipv4_addr & param->addr_mask));
/* netfitler expecting in host-byte order */
filter_ipv4.addr = bc_ip_addr;
filter_ipv4.mask = 0xffffffff;
iptodot("with broadcast address", filter_ipv4.addr);
nfct_filter_set_logic(filter,
NFCT_FILTER_DST_IPV4,
NFCT_FILTER_LOGIC_NEGATIVE);
nfct_filter_add_attr(filter, NFCT_FILTER_DST_IPV4, &filter_ipv4);
return 0;
}
/* Function which sets up filters to ignore
connections to and from local interfaces */
int IPACM_ConntrackClient::IPA_Conntrack_Filters_Ignore_Local_Addrs
(
struct nfct_filter *filter
)
{
struct nfct_filter_ipv4 filter_ipv4;
/* ignore whatever is destined to or originates from broadcast ip address */
filter_ipv4.addr = 0xffffffff;
filter_ipv4.mask = 0xffffffff;
nfct_filter_set_logic(filter,
NFCT_FILTER_DST_IPV4,
NFCT_FILTER_LOGIC_NEGATIVE);
nfct_filter_add_attr(filter, NFCT_FILTER_DST_IPV4, &filter_ipv4);
nfct_filter_set_logic(filter,
NFCT_FILTER_SRC_IPV4,
NFCT_FILTER_LOGIC_NEGATIVE);
nfct_filter_add_attr(filter, NFCT_FILTER_SRC_IPV4, &filter_ipv4);
return 0;
} /* IPA_Conntrack_Filters_Ignore_Local_Addrs() */
/* Initialize TCP Filter */
int IPACM_ConntrackClient::IPA_Conntrack_TCP_Filter_Init(void)
{
int ret = 0;
IPACM_ConntrackClient *pClient;
IPACMDBG("\n");
pClient = IPACM_ConntrackClient::GetInstance();
if(pClient == NULL)
{
IPACMERR("unable to get conntrack client instance\n");
return -1;
}
ret = nfct_filter_set_logic(pClient->tcp_filter,
NFCT_FILTER_L4PROTO,
NFCT_FILTER_LOGIC_POSITIVE);
if(ret == -1)
{
IPACMERR("Unable to set filter logic\n");
return -1;
}
/* set protocol filters as tcp and udp */
nfct_filter_add_attr_u32(pClient->tcp_filter, NFCT_FILTER_L4PROTO, IPPROTO_TCP);
struct nfct_filter_proto tcp_proto_state;
tcp_proto_state.proto = IPPROTO_TCP;
tcp_proto_state.state = TCP_CONNTRACK_ESTABLISHED;
ret = nfct_filter_set_logic(pClient->tcp_filter,
NFCT_FILTER_L4PROTO_STATE,
NFCT_FILTER_LOGIC_POSITIVE);
if(ret == -1)
{
IPACMERR("unable to set filter logic\n");
return -1;
}
nfct_filter_add_attr(pClient->tcp_filter,
NFCT_FILTER_L4PROTO_STATE,
&tcp_proto_state);
tcp_proto_state.proto = IPPROTO_TCP;
tcp_proto_state.state = TCP_CONNTRACK_FIN_WAIT;
ret = nfct_filter_set_logic(pClient->tcp_filter,
NFCT_FILTER_L4PROTO_STATE,
NFCT_FILTER_LOGIC_POSITIVE);
if(ret == -1)
{
IPACMERR("unable to set filter logic\n");
return -1;
}
nfct_filter_add_attr(pClient->tcp_filter,
NFCT_FILTER_L4PROTO_STATE,
&tcp_proto_state);
return 0;
}
/* Initialize UDP Filter */
int IPACM_ConntrackClient::IPA_Conntrack_UDP_Filter_Init(void)
{
int ret = 0;
IPACM_ConntrackClient *pClient = IPACM_ConntrackClient::GetInstance();
if(pClient == NULL)
{
IPACMERR("unable to get conntrack client instance\n");
return -1;
}
ret = nfct_filter_set_logic(pClient->udp_filter,
NFCT_FILTER_L4PROTO,
NFCT_FILTER_LOGIC_POSITIVE);
if(ret == -1)
{
IPACMERR("unable to set filter logic\n");
}
/* set protocol filters as tcp and udp */
nfct_filter_add_attr_u32(pClient->udp_filter, NFCT_FILTER_L4PROTO, IPPROTO_UDP);
return 0;
}
void* IPACM_ConntrackClient::UDPConnTimeoutUpdate(void *ptr)
{
NatApp *nat_inst = NULL;
ptr = NULL;
#ifdef IPACM_DEBUG
IPACMDBG("\n");
#endif
nat_inst = NatApp::GetInstance();
if(nat_inst == NULL)
{
IPACMERR("unable to create nat instance\n");
return NULL;
}
while(1)
{
nat_inst->UpdateUDPTimeStamp();
sleep(UDP_TIMEOUT_UPDATE);
} /* end of while(1) loop */
#ifdef IPACM_DEBUG
IPACMDBG("Returning from %s() %d\n", __FUNCTION__, __LINE__);
#endif
return NULL;
}
/* Thread to initialize TCP Conntrack Filters*/
void* IPACM_ConntrackClient::TCPRegisterWithConnTrack(void *)
{
int ret;
IPACM_ConntrackClient *pClient;
unsigned subscrips = 0;
IPACMDBG("\n");
pClient = IPACM_ConntrackClient::GetInstance();
if(pClient == NULL)
{
IPACMERR("unable to get conntrack client instance\n");
return NULL;
}
subscrips = (NF_NETLINK_CONNTRACK_UPDATE | NF_NETLINK_CONNTRACK_DESTROY);
#ifdef CT_OPT
subscrips |= NF_NETLINK_CONNTRACK_NEW;
#endif
#ifdef FEATURE_IPACM_HAL
if (pClient->fd_tcp < 0) {
IPACMERR("unable to get conntrack TCP handle due to fd_tcp is invalid \n");
return NULL;
} else {
pClient->tcp_hdl = nfct_open2(CONNTRACK, subscrips, pClient->fd_tcp);
}
#else
pClient->tcp_hdl = nfct_open(CONNTRACK, subscrips);
#endif
if(pClient->tcp_hdl == NULL)
{
PERROR("nfct_open failed on getting tcp_hdl\n");
return NULL;
}
/* Initialize the filter */
ret = IPA_Conntrack_TCP_Filter_Init();
if(ret == -1)
{
IPACMERR("Unable to initliaze TCP Filter\n");
return NULL;
}
/* Attach the filter to net filter handler */
ret = nfct_filter_attach(nfct_fd(pClient->tcp_hdl), pClient->tcp_filter);
if(ret == -1)
{
IPACMDBG("unable to attach TCP filter\n");
return NULL;
}
/* Register callback with netfilter handler */
IPACMDBG_H("tcp handle:%pK, fd:%d\n", pClient->tcp_hdl, nfct_fd(pClient->tcp_hdl));
#ifndef CT_OPT
nfct_callback_register(pClient->tcp_hdl,
(nf_conntrack_msg_type) (NFCT_T_UPDATE | NFCT_T_DESTROY | NFCT_T_NEW),
IPAConntrackEventCB, NULL);
#else
nfct_callback_register(pClient->tcp_hdl, (nf_conntrack_msg_type) NFCT_T_ALL, IPAConntrackEventCB, NULL);
#endif
/* Block to catch events from net filter connection track */
/* nfct_catch() receives conntrack events from kernel-space, by default it
blocks waiting for events. */
IPACMDBG("Waiting for events\n");
ctcatch:
ret = nfct_catch(pClient->tcp_hdl);
if((ret == -1) && (errno != ENOMSG))
{
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");
/* destroy the filter.. this will not detach the filter */
nfct_filter_destroy(pClient->tcp_filter);
pClient->tcp_filter = NULL;
/* de-register the callback */
nfct_callback_unregister(pClient->tcp_hdl);
/* close the handle */
#ifdef FEATURE_IPACM_HAL
nfct_close2(pClient->tcp_hdl, true);
#else
nfct_close(pClient->tcp_hdl);
#endif
pClient->tcp_hdl = NULL;
pthread_exit(NULL);
return NULL;
}
/* Thread to initialize UDP Conntrack Filters*/
void* IPACM_ConntrackClient::UDPRegisterWithConnTrack(void *)
{
int ret;
IPACM_ConntrackClient *pClient = NULL;
IPACMDBG("\n");
pClient = IPACM_ConntrackClient::GetInstance();
if(pClient == NULL)
{
IPACMERR("unable to retrieve instance of conntrack client\n");
return NULL;
}
#ifdef FEATURE_IPACM_HAL
if (pClient->fd_udp < 0) {
IPACMERR("unable to get conntrack UDP handle due to fd_udp is invalid \n");
return NULL;
} else {
pClient->udp_hdl = nfct_open2(CONNTRACK,
(NF_NETLINK_CONNTRACK_NEW | NF_NETLINK_CONNTRACK_DESTROY), pClient->fd_udp);
}
#else
pClient->udp_hdl = nfct_open(CONNTRACK,
(NF_NETLINK_CONNTRACK_NEW | NF_NETLINK_CONNTRACK_DESTROY));
#endif
if(pClient->udp_hdl == NULL)
{
PERROR("nfct_open failed on getting udp_hdl\n");
return NULL;
}
/* Initialize Filter */
ret = IPA_Conntrack_UDP_Filter_Init();
if(-1 == ret)
{
IPACMDBG("Unable to initalize udp filters\n");
return NULL;
}
/* Attach the filter to net filter handler */
ret = nfct_filter_attach(nfct_fd(pClient->udp_hdl), pClient->udp_filter);
if(ret == -1)
{
IPACMDBG("unable to attach the filter\n");
return NULL;
}
/* Register callback with netfilter handler */
IPACMDBG_H("udp handle:%pK, fd:%d\n", pClient->udp_hdl, nfct_fd(pClient->udp_hdl));
nfct_callback_register(pClient->udp_hdl,
(nf_conntrack_msg_type)(NFCT_T_NEW | NFCT_T_DESTROY),
IPAConntrackEventCB,
NULL);
/* Block to catch events from net filter connection track */
ctcatch:
ret = nfct_catch(pClient->udp_hdl);
/* Due to conntrack dump, sequence number might mismatch for initial events. */
if((ret == -1) && (errno != ENOMSG) && (errno != EILSEQ))
{
IPACMDBG("(%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 udp thread with ret: %d\n", ret);
/* destroy the filter.. this will not detach the filter */
nfct_filter_destroy(pClient->udp_filter);
pClient->udp_filter = NULL;
/* de-register the callback */
nfct_callback_unregister(pClient->udp_hdl);
/* close the handle */
#ifdef FEATURE_IPACM_HAL
nfct_close2(pClient->udp_hdl, true);
#else
nfct_close(pClient->udp_hdl);
#endif
pClient->udp_hdl = NULL;
pthread_exit(NULL);
return NULL;
}
/* Thread to initialize TCP Conntrack Filters*/
void IPACM_ConntrackClient::UNRegisterWithConnTrack(void)
{
IPACM_ConntrackClient *pClient = NULL;
IPACMDBG("\n");
pClient = IPACM_ConntrackClient::GetInstance();
if(pClient == NULL)
{
IPACMERR("unable to retrieve instance of conntrack client\n");
return;
}
/* destroy the TCP filter.. this will not detach the filter */
if (pClient->tcp_filter) {
nfct_filter_destroy(pClient->tcp_filter);
pClient->tcp_filter = NULL;
}
/* de-register the callback */
if (pClient->tcp_hdl) {
nfct_callback_unregister(pClient->tcp_hdl);
/* close the handle */
nfct_close(pClient->tcp_hdl);
pClient->tcp_hdl = NULL;
}
/* destroy the filter.. this will not detach the filter */
if (pClient->udp_filter) {
nfct_filter_destroy(pClient->udp_filter);
pClient->udp_filter = NULL;
}
/* de-register the callback */
if (pClient->udp_hdl) {
nfct_callback_unregister(pClient->udp_hdl);
/* close the handle */
nfct_close(pClient->udp_hdl);
pClient->udp_hdl = NULL;
}
pClient->fd_tcp = -1;
pClient->fd_udp = -1;
return;
}
void IPACM_ConntrackClient::UpdateUDPFilters(void *param, bool isWan)
{
static bool isIgnore = false;
int ret = 0;
IPACM_ConntrackClient *pClient = NULL;
pClient = IPACM_ConntrackClient::GetInstance();
if(pClient == NULL)
{
IPACMERR("unable to retrieve conntrack client instance\n");
return;
}
if(pClient->udp_filter == NULL)
{
return;
}
if(!isWan)
{
IPA_Conntrack_Filters_Ignore_Local_Iface(pClient->udp_filter,
(ipacm_event_iface_up *)param);
if(!isIgnore)
{
IPA_Conntrack_Filters_Ignore_Bridge_Addrs(pClient->udp_filter);
IPA_Conntrack_Filters_Ignore_Local_Addrs(pClient->udp_filter);
isIgnore = true;
}
}
/* Attach the filter to udp handle */
if(pClient->udp_hdl != NULL)
{
IPACMDBG("attaching the filter to udp handle\n");
ret = nfct_filter_attach(nfct_fd(pClient->udp_hdl), pClient->udp_filter);
if(ret == -1)
{
PERROR("unable to attach the filter to udp handle\n");
IPACMERR("udp handle:%pK, fd:%d Error: %d\n",pClient->udp_hdl, nfct_fd(pClient->udp_hdl), ret);
return;
}
}
return;
}
void IPACM_ConntrackClient::UpdateTCPFilters(void *param, bool isWan)
{
static bool isIgnore = false;
int ret = 0;
IPACM_ConntrackClient *pClient = NULL;
pClient = IPACM_ConntrackClient::GetInstance();
if(pClient == NULL)
{
IPACMERR("unable to retrieve conntrack client instance\n");
return;
}
if(pClient->tcp_filter == NULL)
return;
if(!isWan)
{
IPA_Conntrack_Filters_Ignore_Local_Iface(pClient->tcp_filter,
(ipacm_event_iface_up *)param);
if(!isIgnore)
{
IPA_Conntrack_Filters_Ignore_Bridge_Addrs(pClient->udp_filter);
IPA_Conntrack_Filters_Ignore_Local_Addrs(pClient->udp_filter);
isIgnore = true;
}
}
/* Attach the filter to tcp handle */
if(pClient->tcp_hdl != NULL)
{
IPACMDBG("attaching the filter to tcp handle\n");
ret = nfct_filter_attach(nfct_fd(pClient->tcp_hdl), pClient->tcp_filter);
if(ret == -1)
{
PERROR("unable to attach the filter to tcp handle\n");
IPACMERR("tcp handle:%pK, fd:%d Error: %d\n",pClient->tcp_hdl, nfct_fd(pClient->tcp_hdl), ret);
return;
}
}
return;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,214 +0,0 @@
/*
Copyright (c) 2013-2018, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_EvtDispatcher.cpp
@brief
This file implements the IPAM event dispatcher functionality
@Author
*/
#include <string.h>
#include <pthread.h>
#include <IPACM_EvtDispatcher.h>
#include <IPACM_Neighbor.h>
#include "IPACM_CmdQueue.h"
#include "IPACM_Defs.h"
extern pthread_mutex_t mutex;
extern pthread_cond_t cond_var;
cmd_evts *IPACM_EvtDispatcher::head = NULL;
extern uint32_t ipacm_event_stats[IPACM_EVENT_MAX];
int IPACM_EvtDispatcher::PostEvt
(
ipacm_cmd_q_data *data
)
{
Message *item = NULL;
MessageQueue *MsgQueue = NULL;
if(data->event < IPA_EXTERNAL_EVENT_MAX)
{
IPACMDBG("Insert event into external queue.\n");
MsgQueue = MessageQueue::getInstanceExternal();
}
else
{
IPACMDBG("Insert event into internal queue.\n");
MsgQueue = MessageQueue::getInstanceInternal();
}
if(MsgQueue == NULL)
{
IPACMERR("unable to retrieve MsgQueue instance\n");
return IPACM_FAILURE;
}
item = new Message();
if(item == NULL)
{
IPACMERR("unable to create new message item\n");
return IPACM_FAILURE;
}
item->evt.callback_ptr = IPACM_EvtDispatcher::ProcessEvt;
memcpy(&item->evt.data, data, sizeof(ipacm_cmd_q_data));
if(pthread_mutex_lock(&mutex) != 0)
{
IPACMERR("unable to lock the mutex\n");
return IPACM_FAILURE;
}
IPACMDBG("Enqueing item\n");
MsgQueue->enqueue(item);
IPACMDBG("Enqueued item %pK\n", item);
if(pthread_cond_signal(&cond_var) != 0)
{
IPACMDBG("unable to lock the mutex\n");
/* Release the mutex before you return failure */
if(pthread_mutex_unlock(&mutex) != 0)
{
IPACMERR("unable to unlock the mutex\n");
return IPACM_FAILURE;
}
return IPACM_FAILURE;
}
if(pthread_mutex_unlock(&mutex) != 0)
{
IPACMERR("unable to unlock the mutex\n");
return IPACM_FAILURE;
}
return IPACM_SUCCESS;
}
void IPACM_EvtDispatcher::ProcessEvt(ipacm_cmd_q_data *data)
{
cmd_evts *tmp = head, tmp1;
if(head == NULL)
{
IPACMDBG("Queue is empty\n");
}
while(tmp != NULL)
{
memcpy(&tmp1, tmp, sizeof(tmp1));
if(data->event == tmp1.event)
{
ipacm_event_stats[data->event]++;
tmp1.obj->event_callback(data->event, data->evt_data);
IPACMDBG(" Find matched registered events\n");
}
tmp = tmp1.next;
}
IPACMDBG(" Finished process events\n");
if(data->evt_data != NULL)
{
IPACMDBG("free the event:%d data: %pK\n", data->event, data->evt_data);
free(data->evt_data);
}
return;
}
int IPACM_EvtDispatcher::registr(ipa_cm_event_id event, IPACM_Listener *obj)
{
cmd_evts *tmp = head,*nw;
nw = (cmd_evts *)malloc(sizeof(cmd_evts));
if(nw != NULL)
{
nw->event = event;
nw->obj = obj;
nw->next = NULL;
}
else
{
return IPACM_FAILURE;
}
if(head == NULL)
{
head = nw;
}
else
{
while(tmp->next)
{
tmp = tmp->next;
}
tmp->next = nw;
}
return IPACM_SUCCESS;
}
int IPACM_EvtDispatcher::deregistr(IPACM_Listener *param)
{
cmd_evts *tmp = head,*tmp1,*prev = head;
while(tmp != NULL)
{
if(tmp->obj == param)
{
tmp1 = tmp;
if(tmp == head)
{
head = head->next;
}
else if(tmp->next == NULL)
{
prev->next = NULL;
}
else
{
prev->next = tmp->next;
}
tmp = tmp->next;
free(tmp1);
}
else
{
prev = tmp;
tmp = tmp->next;
}
}
return IPACM_SUCCESS;
}

File diff suppressed because it is too large Load diff

View file

@ -1,236 +0,0 @@
/*
Copyright (c) 2013, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <unistd.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include "IPACM_Header.h"
#include "IPACM_Log.h"
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//All interaction through the driver are made through this inode.
static const char *DEVICE_NAME = "/dev/ipa";
/////////////////////////////////////////////////////////////////////////////////////////////////////////
IPACM_Header::IPACM_Header()
{
m_fd = open(DEVICE_NAME, O_RDWR);
if (-1 == m_fd)
{
IPACMERR("Failed to open %s in IPACM_Header test application constructor.\n", DEVICE_NAME);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
IPACM_Header::~IPACM_Header()
{
if (-1 != m_fd)
{
close(m_fd);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
bool IPACM_Header::DeviceNodeIsOpened()
{
return (-1 != m_fd);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
bool IPACM_Header::AddHeader(struct ipa_ioc_add_hdr *pHeaderTableToAdd)
{
int nRetVal = 0;
//call the Driver ioctl in order to add header
nRetVal = ioctl(m_fd, IPA_IOC_ADD_HDR, pHeaderTableToAdd);
IPACMDBG("return value: %d\n", nRetVal);
return (-1 != nRetVal);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
bool IPACM_Header::DeleteHeader(struct ipa_ioc_del_hdr *pHeaderTableToDelete)
{
int nRetVal = 0;
//call the Driver ioctl in order to remove header
nRetVal = ioctl(m_fd, IPA_IOC_DEL_HDR, pHeaderTableToDelete);
IPACMDBG("return value: %d\n", nRetVal);
return (-1 != nRetVal);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
bool IPACM_Header::Commit()
{
int nRetVal = 0;
nRetVal = ioctl(m_fd, IPA_IOC_COMMIT_HDR);
IPACMDBG("return value: %d\n", nRetVal);
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
bool IPACM_Header::Reset()
{
int nRetVal = 0;
nRetVal = ioctl(m_fd, IPA_IOC_RESET_HDR);
nRetVal |= ioctl(m_fd, IPA_IOC_COMMIT_HDR);
IPACMDBG("return value: %d\n", nRetVal);
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
bool IPACM_Header::GetHeaderHandle(struct ipa_ioc_get_hdr *pHeaderStruct)
{
int retval = 0;
if (!DeviceNodeIsOpened()) return false;
retval = ioctl(m_fd, IPA_IOC_GET_HDR, pHeaderStruct);
if (retval)
{
IPACMERR("IPA_IOC_GET_HDR ioctl failed, routingTable =0x%p, retval=0x%x.\n", pHeaderStruct, retval);
return false;
}
IPACMDBG("IPA_IOC_GET_HDR ioctl issued to IPA header insertion block.\n");
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
bool IPACM_Header::CopyHeader(struct ipa_ioc_copy_hdr *pCopyHeaderStruct)
{
int retval = 0;
if (!DeviceNodeIsOpened()) return false;
retval = ioctl(m_fd, IPA_IOC_COPY_HDR, pCopyHeaderStruct);
if (retval)
{
IPACMERR("IPA_IOC_COPY_HDR ioctl failed, retval=0x%x.\n", retval);
return false;
}
IPACMDBG("IPA_IOC_COPY_HDR ioctl issued to IPA header insertion block.\n");
return true;
}
bool IPACM_Header::DeleteHeaderHdl(uint32_t hdr_hdl)
{
const uint8_t NUM_HDLS = 1;
struct ipa_ioc_del_hdr *pHeaderDescriptor = NULL;
struct ipa_hdr_del *hd_rule_entry;
int len = 0;
bool res = true;
if (hdr_hdl == 0)
{
IPACMERR("Invalid header handle passed. Ignoring it\n");
return false;
}
len = (sizeof(struct ipa_ioc_del_hdr)) + (NUM_HDLS * sizeof(struct ipa_hdr_del));
pHeaderDescriptor = (struct ipa_ioc_del_hdr *)malloc(len);
if (pHeaderDescriptor == NULL)
{
IPACMERR("Unable to allocate memory for del header\n");
return false;
}
memset(pHeaderDescriptor, 0, len);
pHeaderDescriptor->commit = true;
pHeaderDescriptor->num_hdls = NUM_HDLS;
hd_rule_entry = &pHeaderDescriptor->hdl[0];
hd_rule_entry->hdl = hdr_hdl;
hd_rule_entry->status = -1;
IPACMDBG("Deleting Header hdl:(%x)\n", hd_rule_entry->hdl);
if ((false == DeleteHeader(pHeaderDescriptor)) ||
(hd_rule_entry->status))
{
IPACMERR("Header hdl:(%x) deletion failed! status: %d\n", hd_rule_entry->hdl,hd_rule_entry->status);
res = false;
goto fail;
}
IPACMDBG_H("Deleted Header hdl:(%x) successfully\n", hd_rule_entry->hdl);
fail:
free(pHeaderDescriptor);
return res;
}
bool IPACM_Header::AddHeaderProcCtx(struct ipa_ioc_add_hdr_proc_ctx* pHeader)
{
int ret = 0;
//call the Driver ioctl to add header processing context
ret = ioctl(m_fd, IPA_IOC_ADD_HDR_PROC_CTX, pHeader);
return (ret == 0);
}
bool IPACM_Header::DeleteHeaderProcCtx(uint32_t hdl)
{
int len, ret;
struct ipa_ioc_del_hdr_proc_ctx* pHeaderTable = NULL;
len = sizeof(struct ipa_ioc_del_hdr_proc_ctx) + sizeof(struct ipa_hdr_proc_ctx_del);
pHeaderTable = (struct ipa_ioc_del_hdr_proc_ctx*)malloc(len);
if(pHeaderTable == NULL)
{
IPACMERR("Failed to allocate buffer.\n");
return false;
}
memset(pHeaderTable, 0, len);
pHeaderTable->commit = 1;
pHeaderTable->num_hdls = 1;
pHeaderTable->hdl[0].hdl = hdl;
ret = ioctl(m_fd, IPA_IOC_DEL_HDR_PROC_CTX, pHeaderTable);
if(ret != 0)
{
IPACMERR("Failed to delete hdr proc ctx: return value %d, status %d\n",
ret, pHeaderTable->hdl[0].status);
}
free(pHeaderTable);
return (ret == 0);
}

File diff suppressed because it is too large Load diff

View file

@ -1,621 +0,0 @@
/*
Copyright (c) 2013-2019, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_IfaceManager.cpp
@brief
This file implements the IPAM iface_manager functionality.
@Author
Skylar Chang
*/
#include <string.h>
#include <sys/ioctl.h>
#include <IPACM_IfaceManager.h>
#include <IPACM_EvtDispatcher.h>
#include <IPACM_Defs.h>
#include <IPACM_Wlan.h>
#include <IPACM_Lan.h>
#include <IPACM_Wan.h>
#include <IPACM_Iface.h>
#include <IPACM_Log.h>
iface_instances *IPACM_IfaceManager::head = NULL;
IPACM_IfaceManager::IPACM_IfaceManager()
{
IPACM_EvtDispatcher::registr(IPA_CFG_CHANGE_EVENT, this); // register for IPA_CFG_CHANGE event
IPACM_EvtDispatcher::registr(IPA_LINK_UP_EVENT, this);
IPACM_EvtDispatcher::registr(IPA_WLAN_AP_LINK_UP_EVENT, this); // register for wlan AP-iface
IPACM_EvtDispatcher::registr(IPA_WLAN_STA_LINK_UP_EVENT, this); // register for wlan STA-iface
#ifndef FEATURE_IPA_ANDROID
/* only MDM targets support device on bridge mode */
IPACM_EvtDispatcher::registr(IPA_BRIDGE_LINK_UP_EVENT, this); // register for IPA_BRIDGE_LINK_UP_EVENT event
#endif /* not defined(FEATURE_IPA_ANDROID)*/
IPACM_EvtDispatcher::registr(IPA_USB_LINK_UP_EVENT, this); // register for USB-iface
IPACM_EvtDispatcher::registr(IPA_WAN_EMBMS_LINK_UP_EVENT, this); // register for wan eMBMS-iface
return;
}
void IPACM_IfaceManager::event_callback(ipa_cm_event_id event, void *param)
{
int ipa_interface_index;
ipacm_event_data_fid *evt_data = (ipacm_event_data_fid *)param;
ipacm_event_data_mac *StaData = (ipacm_event_data_mac *)param;
ipacm_event_data_all *data_all = (ipacm_event_data_all *)param;
ipacm_ifacemgr_data ifmgr_data;
memset(&ifmgr_data,0,sizeof(ifmgr_data));
switch(event)
{
case IPA_CFG_CHANGE_EVENT:
IPACMDBG_H(" RESET IPACM_cfg \n");
IPACM_Iface::ipacmcfg->Init();
break;
case IPA_BRIDGE_LINK_UP_EVENT:
IPACMDBG_H(" Save the bridge0 mac info in IPACM_cfg \n");
ipa_interface_index = IPACM_Iface::iface_ipa_index_query(data_all->if_index);
/* check for failure return */
if (IPACM_FAILURE == ipa_interface_index) {
IPACMERR("IPA_BRIDGE_LINK_UP_EVENT: not supported iface id: %d\n", data_all->if_index);
break;
}
/* check if iface is bridge interface*/
if (strcmp(IPACM_Iface::ipacmcfg->ipa_virtual_iface_name, IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].iface_name) == 0)
{
IPACM_Iface::ipacmcfg->ipa_bridge_enable = true;
memcpy(IPACM_Iface::ipacmcfg->bridge_mac,
data_all->mac_addr,
sizeof(IPACM_Iface::ipacmcfg->bridge_mac));
IPACMDBG_H("cached bridge0 MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
IPACM_Iface::ipacmcfg->bridge_mac[0], IPACM_Iface::ipacmcfg->bridge_mac[1], IPACM_Iface::ipacmcfg->bridge_mac[2],
IPACM_Iface::ipacmcfg->bridge_mac[3], IPACM_Iface::ipacmcfg->bridge_mac[4], IPACM_Iface::ipacmcfg->bridge_mac[5]);
}
break;
case IPA_LINK_UP_EVENT:
IPACMDBG_H("Recieved IPA_LINK_UP_EVENT event: link up %d: \n", evt_data->if_index);
ipa_interface_index = IPACM_Iface::iface_ipa_index_query(evt_data->if_index);
/* check for failure return */
if (IPACM_FAILURE == ipa_interface_index) {
IPACMERR("IPA_LINK_UP_EVENT: not supported iface id: %d\n", evt_data->if_index);
break;
}
/* LTE-backhaul */
if(IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].if_cat == EMBMS_IF)
{
IPACMDBG("WAN-EMBMS (%s) link already up, iface: %d: \n", IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].iface_name,evt_data->if_index);
}
else if(IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].if_cat == WAN_IF)
{
IPACMDBG_H("WAN-LTE (%s) link up, iface: %d: \n", IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].iface_name,evt_data->if_index);
ifmgr_data.if_index = evt_data->if_index;
ifmgr_data.if_type = Q6_WAN;
create_iface_instance(&ifmgr_data);
}
break;
case IPA_USB_LINK_UP_EVENT:
IPACMDBG_H("Recieved IPA_USB_LINK_UP_EVENT event: link up %d: \n", evt_data->if_index);
ipa_interface_index = IPACM_Iface::iface_ipa_index_query(evt_data->if_index);
/* check for failure return */
if (IPACM_FAILURE == ipa_interface_index) {
IPACMERR("IPA_USB_LINK_UP_EVENT: not supported iface id: %d\n", evt_data->if_index);
break;
}
/* check if it's WAN_IF */
if(IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].if_cat == WAN_IF)
{
/* usb-backhaul using sta_mode ECM_WAN*/
IPACMDBG_H("WAN-usb (%s) link up, iface: %d: \n", IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].iface_name, evt_data->if_index);
ifmgr_data.if_index = evt_data->if_index;
ifmgr_data.if_type = ECM_WAN;
create_iface_instance(&ifmgr_data);
}
else
{
ifmgr_data.if_index = evt_data->if_index;
ifmgr_data.if_type = Q6_WAN;
create_iface_instance(&ifmgr_data);
}
break;
case IPA_WLAN_AP_LINK_UP_EVENT:
ipa_interface_index = IPACM_Iface::iface_ipa_index_query(evt_data->if_index);
/* check for failure return */
if (IPACM_FAILURE == ipa_interface_index) {
IPACMERR("IPA_WLAN_AP_LINK_UP_EVENT: not supported iface id: %d\n", evt_data->if_index);
break;
}
/* change iface category from unknown to WLAN_IF */
if(IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].if_cat == UNKNOWN_IF)
{
IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].if_cat = WLAN_IF;
IPACMDBG_H("WLAN AP (%s) link up, iface: %d: \n", IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].iface_name,evt_data->if_index);
ifmgr_data.if_index = evt_data->if_index;
ifmgr_data.if_type = Q6_WAN;
create_iface_instance(&ifmgr_data);
}
else
{
IPACMDBG_H("iface %s already up and act as %d mode: \n",IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].iface_name,IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].if_cat);
}
break;
case IPA_WLAN_STA_LINK_UP_EVENT:
ipa_interface_index = IPACM_Iface::iface_ipa_index_query(StaData->if_index);
/* check for failure return */
if (IPACM_FAILURE == ipa_interface_index) {
IPACMERR("IPA_WLAN_STA_LINK_UP_EVENT: not supported iface id: %d\n", StaData->if_index);
break;
}
/* change iface category from unknown to WAN_IF */
if(IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].if_cat == UNKNOWN_IF)
{
/* wlan-backhaul using sta_mode WLAN_WAN */
IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].if_cat = WAN_IF;
IPACMDBG_H("WLAN STA (%s) link up, iface: %d: \n",
IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].iface_name, StaData->if_index);
ifmgr_data.if_index = StaData->if_index;
ifmgr_data.if_type = WLAN_WAN;
memcpy(ifmgr_data.mac_addr, StaData->mac_addr, sizeof(ifmgr_data.mac_addr));
create_iface_instance(&ifmgr_data);
}
else
{
IPACMDBG_H("iface %s already up and act as %d mode: \n",
IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].iface_name,
IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].if_cat);
}
break;
/* Add new instance open for eMBMS iface and wan iface */
case IPA_WAN_EMBMS_LINK_UP_EVENT:
ipa_interface_index = IPACM_Iface::iface_ipa_index_query(evt_data->if_index);
/* check for failure return */
if (IPACM_FAILURE == ipa_interface_index) {
IPACMERR("IPA_WAN_EMBMS_LINK_UP_EVENT: not supported iface id: %d\n", evt_data->if_index);
break;
}
/* change iface category from unknown to EMBMS_IF */
if ((IPACM_Iface::ipacmcfg->ipacm_odu_enable == true) && (IPACM_Iface::ipacmcfg->ipacm_odu_embms_enable == true))
{
IPACMDBG(" ODU-mode enable or not (%d) \n",IPACM_Iface::ipacmcfg->ipacm_odu_enable);
if(IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].if_cat == WAN_IF)
{
IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].if_cat=EMBMS_IF;
IPACMDBG("WAN eMBMS (%s) link up, iface: %d: \n", IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].iface_name,evt_data->if_index);
ifmgr_data.if_index = StaData->if_index;
ifmgr_data.if_type = Q6_WAN;
create_iface_instance(&ifmgr_data);
}
else
{
IPACMDBG("iface %s already up and act as %d mode: \n",IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].iface_name,IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].if_cat);
}
}
break;
default:
break;
}
return;
}
int IPACM_IfaceManager::create_iface_instance(ipacm_ifacemgr_data *param)
{
int if_index = param->if_index;
ipacm_wan_iface_type is_sta_mode = param->if_type;
int ipa_interface_index;
ipa_interface_index = IPACM_Iface::iface_ipa_index_query(if_index);
if(ipa_interface_index == INVALID_IFACE)
{
IPACMDBG_H("Unhandled interface received, fid: %d\n",if_index);
return IPACM_SUCCESS;
}
/* check if duplicate instance*/
if(SearchInstance(ipa_interface_index) == IPA_INSTANCE_NOT_FOUND)
{
/* IPA_INSTANCE_NOT_FOUND */
switch(IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].if_cat)
{
case LAN_IF:
{
IPACMDBG_H("Creating Lan interface\n");
IPACM_Lan *lan = new IPACM_Lan(ipa_interface_index);
if (lan->rx_prop == NULL && lan->tx_prop == NULL)
{
/* close the netdev instance if IPA not support*/
lan->delete_iface();
return IPACM_FAILURE;
}
IPACM_EvtDispatcher::registr(IPA_ADDR_ADD_EVENT, lan);
//IPACM_EvtDispatcher::registr(IPA_ROUTE_ADD_EVENT, lan);
//IPACM_EvtDispatcher::registr(IPA_ROUTE_DEL_EVENT, lan);
IPACM_EvtDispatcher::registr(IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT, lan);
IPACM_EvtDispatcher::registr(IPA_NEIGH_CLIENT_IP_ADDR_DEL_EVENT, lan);
IPACM_EvtDispatcher::registr(IPA_SW_ROUTING_ENABLE, lan);
IPACM_EvtDispatcher::registr(IPA_SW_ROUTING_DISABLE, lan);
#ifdef FEATURE_IPA_ANDROID
IPACM_EvtDispatcher::registr(IPA_HANDLE_WAN_UP_TETHER, lan);
IPACM_EvtDispatcher::registr(IPA_HANDLE_WAN_UP_V6_TETHER, lan);
IPACM_EvtDispatcher::registr(IPA_HANDLE_WAN_DOWN_TETHER, lan);
IPACM_EvtDispatcher::registr(IPA_HANDLE_WAN_DOWN_V6_TETHER, lan);
#ifdef FEATURE_IPACM_HAL
IPACM_EvtDispatcher::registr(IPA_DOWNSTREAM_ADD, lan);
IPACM_EvtDispatcher::registr(IPA_DOWNSTREAM_DEL, lan);
#endif
#else
IPACM_EvtDispatcher::registr(IPA_HANDLE_WAN_UP, lan);
IPACM_EvtDispatcher::registr(IPA_HANDLE_WAN_UP_V6, lan);
IPACM_EvtDispatcher::registr(IPA_HANDLE_WAN_DOWN, lan);
IPACM_EvtDispatcher::registr(IPA_HANDLE_WAN_DOWN_V6, lan);
#endif
IPACM_EvtDispatcher::registr(IPA_CFG_CHANGE_EVENT, lan); // register for IPA_CFG_CHANGE event
IPACM_EvtDispatcher::registr(IPA_PRIVATE_SUBNET_CHANGE_EVENT, lan); // register for IPA_PRIVATE_SUBNET_CHANGE_EVENT event
#ifdef FEATURE_IPA_ANDROID
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);
IPACMDBG_H("ipa_LAN (%s):ipa_index (%d) instance open/registr ok\n", lan->dev_name, lan->ipa_if_num);
registr(ipa_interface_index, lan);
/* solve the new_addr comes earlier issue */
IPACM_Iface::iface_addr_query(if_index);
}
break;
case ETH_IF:
{
IPACMDBG_H("Creating ETH interface in router mode\n");
IPACM_Lan *ETH = new IPACM_Lan(ipa_interface_index);
IPACM_EvtDispatcher::registr(IPA_ADDR_ADD_EVENT, ETH);
IPACM_EvtDispatcher::registr(IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT, ETH);
IPACM_EvtDispatcher::registr(IPA_SW_ROUTING_ENABLE, ETH);
IPACM_EvtDispatcher::registr(IPA_SW_ROUTING_DISABLE, ETH);
IPACM_EvtDispatcher::registr(IPA_HANDLE_WAN_UP, ETH);
IPACM_EvtDispatcher::registr(IPA_HANDLE_WAN_UP_V6, ETH);
IPACM_EvtDispatcher::registr(IPA_HANDLE_WAN_DOWN, ETH);
IPACM_EvtDispatcher::registr(IPA_HANDLE_WAN_DOWN_V6, ETH);
IPACM_EvtDispatcher::registr(IPA_CRADLE_WAN_MODE_SWITCH, ETH);
IPACM_EvtDispatcher::registr(IPA_LINK_DOWN_EVENT, ETH);
/* IPA_LAN_DELETE_SELF should be always last */
IPACM_EvtDispatcher::registr(IPA_LAN_DELETE_SELF, ETH);
IPACMDBG_H("ipa_LAN (%s):ipa_index (%d) instance open/registr ok\n", ETH->dev_name, ETH->ipa_if_num);
registr(ipa_interface_index, ETH);
/* solve the new_addr comes earlier issue */
IPACM_Iface::iface_addr_query(if_index);
}
break;
case ODU_IF:
{
if(IPACM_Iface::ipacmcfg->ipacm_odu_router_mode == true)
{
IPACMDBG_H("Creating ODU interface in router mode\n");
IPACM_Lan *odu = new IPACM_Lan(ipa_interface_index);
IPACM_EvtDispatcher::registr(IPA_ADDR_ADD_EVENT, odu);
IPACM_EvtDispatcher::registr(IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT, odu);
IPACM_EvtDispatcher::registr(IPA_NEIGH_CLIENT_IP_ADDR_DEL_EVENT, odu);
IPACM_EvtDispatcher::registr(IPA_SW_ROUTING_ENABLE, odu);
IPACM_EvtDispatcher::registr(IPA_SW_ROUTING_DISABLE, odu);
IPACM_EvtDispatcher::registr(IPA_HANDLE_WAN_UP, odu);
IPACM_EvtDispatcher::registr(IPA_HANDLE_WAN_UP_V6, odu);
IPACM_EvtDispatcher::registr(IPA_HANDLE_WAN_DOWN, odu);
IPACM_EvtDispatcher::registr(IPA_HANDLE_WAN_DOWN_V6, odu);
IPACM_EvtDispatcher::registr(IPA_CRADLE_WAN_MODE_SWITCH, odu);
IPACM_EvtDispatcher::registr(IPA_LINK_DOWN_EVENT, odu);
/* IPA_LAN_DELETE_SELF should be always last */
IPACM_EvtDispatcher::registr(IPA_LAN_DELETE_SELF, odu);
IPACMDBG_H("ipa_LAN (%s):ipa_index (%d) instance open/registr ok\n", odu->dev_name, odu->ipa_if_num);
registr(ipa_interface_index, odu);
/* solve the new_addr comes earlier issue */
IPACM_Iface::iface_addr_query(if_index);
}
else
{
IPACMDBG_H("Creating ODU interface in bridge mode\n");
IPACM_Lan *odu = new IPACM_Lan(ipa_interface_index);
IPACM_EvtDispatcher::registr(IPA_ADDR_ADD_EVENT, odu);
IPACM_EvtDispatcher::registr(IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT, odu);
IPACM_EvtDispatcher::registr(IPA_SW_ROUTING_ENABLE, odu);
IPACM_EvtDispatcher::registr(IPA_SW_ROUTING_DISABLE, odu);
IPACM_EvtDispatcher::registr(IPA_LINK_DOWN_EVENT, odu);
/* IPA_LAN_DELETE_SELF should be always last */
IPACM_EvtDispatcher::registr(IPA_LAN_DELETE_SELF, odu);
IPACMDBG_H("ipa_LAN (%s):ipa_index (%d) instance open/registr ok\n", odu->dev_name, odu->ipa_if_num);
registr(ipa_interface_index, odu);
/* solve the new_addr comes earlier issue */
IPACM_Iface::iface_addr_query(if_index);
}
}
break;
case WLAN_IF:
{
IPACMDBG_H("Creating WLan interface\n");
IPACM_Wlan *wl = new IPACM_Wlan(ipa_interface_index);
if (wl->rx_prop == NULL && wl->tx_prop == NULL)
{
/* reset the AP-iface category to unknown */
IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].if_cat = UNKNOWN_IF;
/* close the netdev instance if IPA not support*/
wl->delete_iface();
return IPACM_FAILURE;
}
IPACM_EvtDispatcher::registr(IPA_ADDR_ADD_EVENT, wl);
IPACM_EvtDispatcher::registr(IPA_ROUTE_DEL_EVENT, wl);
IPACM_EvtDispatcher::registr(IPA_WLAN_CLIENT_ADD_EVENT, wl);
IPACM_EvtDispatcher::registr(IPA_WLAN_CLIENT_ADD_EVENT_EX, wl);
IPACM_EvtDispatcher::registr(IPA_WLAN_CLIENT_DEL_EVENT, wl);
IPACM_EvtDispatcher::registr(IPA_WLAN_CLIENT_POWER_SAVE_EVENT, wl);
IPACM_EvtDispatcher::registr(IPA_WLAN_CLIENT_RECOVER_EVENT, wl);
IPACM_EvtDispatcher::registr(IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT, wl);
IPACM_EvtDispatcher::registr(IPA_SW_ROUTING_ENABLE, wl);
IPACM_EvtDispatcher::registr(IPA_SW_ROUTING_DISABLE, wl);
#ifdef FEATURE_IPA_ANDROID
IPACM_EvtDispatcher::registr(IPA_HANDLE_WAN_UP_TETHER, wl);
IPACM_EvtDispatcher::registr(IPA_HANDLE_WAN_UP_V6_TETHER, wl);
IPACM_EvtDispatcher::registr(IPA_HANDLE_WAN_DOWN_TETHER, wl);
IPACM_EvtDispatcher::registr(IPA_HANDLE_WAN_DOWN_V6_TETHER, wl);
#ifdef FEATURE_IPACM_HAL
IPACM_EvtDispatcher::registr(IPA_DOWNSTREAM_ADD, wl);
IPACM_EvtDispatcher::registr(IPA_DOWNSTREAM_DEL, wl);
IPACM_EvtDispatcher::registr(IPA_SSR_NOTICE, wl);
#endif
#else
IPACM_EvtDispatcher::registr(IPA_HANDLE_WAN_UP, wl);
IPACM_EvtDispatcher::registr(IPA_HANDLE_WAN_UP_V6, wl);
IPACM_EvtDispatcher::registr(IPA_HANDLE_WAN_DOWN, wl);
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
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
IPACM_EvtDispatcher::registr(IPA_WLAN_SWITCH_TO_SCC, wl);
IPACM_EvtDispatcher::registr(IPA_WLAN_SWITCH_TO_MCC, wl);
#else
IPACM_EvtDispatcher::registr(IPA_TETHERING_STATS_UPDATE_EVENT, wl);
#endif
#ifdef FEATURE_IPACM_HAL
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);
registr(ipa_interface_index, wl);
/* solve the new_addr comes earlier issue */
IPACM_Iface::iface_addr_query(if_index);
}
break;
case WAN_IF:
{
if((IPACM_Iface::ipacmcfg->ipacm_odu_enable == false) || (IPACM_Iface::ipacmcfg->ipacm_odu_router_mode == true))
{
IPACMDBG_H("Creating Wan interface\n");
IPACM_Wan *w;
if(is_sta_mode == WLAN_WAN)
{
w = new IPACM_Wan(ipa_interface_index, is_sta_mode, param->mac_addr);
if (w->rx_prop == NULL && w->tx_prop == NULL)
{
/* reset the AP-iface category to unknown */
IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].if_cat = UNKNOWN_IF;
/* close the netdev instance if IPA not support*/
w->delete_iface();
return IPACM_FAILURE;
}
}
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
IPACM_EvtDispatcher::registr(IPA_WAN_UPSTREAM_ROUTE_ADD_EVENT, w);
IPACM_EvtDispatcher::registr(IPA_WAN_UPSTREAM_ROUTE_DEL_EVENT, w);
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);
IPACM_EvtDispatcher::registr(IPA_ROUTE_DEL_EVENT, w);
#endif /* not defined(FEATURE_IPA_ANDROID)*/
IPACM_EvtDispatcher::registr(IPA_FIREWALL_CHANGE_EVENT, w);
IPACM_EvtDispatcher::registr(IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT, w);
IPACM_EvtDispatcher::registr(IPA_SW_ROUTING_ENABLE, w);
IPACM_EvtDispatcher::registr(IPA_SW_ROUTING_DISABLE, w);
IPACM_EvtDispatcher::registr(IPA_CFG_CHANGE_EVENT, w); // register for IPA_CFG_CHANGE event
IPACM_EvtDispatcher::registr(IPA_WAN_XLAT_CONNECT_EVENT, w);
if(is_sta_mode == WLAN_WAN)
{
IPACM_EvtDispatcher::registr(IPA_WLAN_LINK_DOWN_EVENT, w); // for STA mode
#ifndef FEATURE_IPA_ANDROID
IPACM_EvtDispatcher::registr(IPA_WLAN_SWITCH_TO_SCC, w);
IPACM_EvtDispatcher::registr(IPA_WLAN_SWITCH_TO_MCC, w);
#ifdef FEATURE_IPACM_HAL
IPACM_EvtDispatcher::registr(IPA_SSR_NOTICE, w);
IPACM_EvtDispatcher::registr(IPA_WLAN_FWR_SSR_BEFORE_SHUTDOWN_NOTICE, w);
#endif
#endif
}
else
{
IPACM_EvtDispatcher::registr(IPA_COALESCE_NOTICE, w);
IPACM_EvtDispatcher::registr(IPA_LINK_DOWN_EVENT, w);
}
IPACMDBG_H("ipa_WAN (%s):ipa_index (%d) instance open/registr ok\n", w->dev_name, w->ipa_if_num);
registr(ipa_interface_index, w);
/* solve the new_addr comes earlier issue */
IPACM_Iface::iface_addr_query(if_index);
}
}
break;
/* WAN-eMBMS instance */
case EMBMS_IF:
{
IPACMDBG("Creating Wan-eMBSM interface\n");
IPACM_Wan *embms = new IPACM_Wan(ipa_interface_index, is_sta_mode, NULL);
IPACM_EvtDispatcher::registr(IPA_LINK_DOWN_EVENT, embms);
IPACMDBG("ipa_WAN (%s):ipa_index (%d) instance open/registr ok\n", embms->dev_name, embms->ipa_if_num);
registr(ipa_interface_index, embms);
}
break;
default:
IPACMDBG_H("Unhandled interface category received iface name: %s, category: %d\n",
IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].iface_name,
IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].if_cat);
return IPACM_SUCCESS;
}
}
return IPACM_SUCCESS;
}
int IPACM_IfaceManager::registr(int ipa_if_index, IPACM_Listener *obj)
{
iface_instances *tmp = head,*nw;
nw = (iface_instances *)malloc(sizeof(iface_instances));
if(nw != NULL)
{
nw->ipa_if_index = ipa_if_index;
nw->obj = obj;
nw->next = NULL;
}
else
{
return IPACM_FAILURE;
}
if(head == NULL)
{
head = nw;
}
else
{
while(tmp->next)
{
tmp = tmp->next;
}
tmp->next = nw;
}
return IPACM_SUCCESS;
}
int IPACM_IfaceManager::deregistr(IPACM_Listener *param)
{
iface_instances *tmp = head,*tmp1,*prev = head;
while(tmp != NULL)
{
if(tmp->obj == param)
{
tmp1 = tmp;
if(tmp == head)
{
head = head->next;
}
else if(tmp->next == NULL)
{
prev->next = NULL;
}
else
{
prev->next = tmp->next;
}
tmp = tmp->next;
free(tmp1);
}
else
{
prev = tmp;
tmp = tmp->next;
}
}
return IPACM_SUCCESS;
}
int IPACM_IfaceManager::SearchInstance(int ipa_if_index)
{
iface_instances *tmp = head;
while(tmp != NULL)
{
if(ipa_if_index == tmp->ipa_if_index)
{
IPACMDBG_H("Find existed iface-instance name: %s\n",
IPACM_Iface::ipacmcfg->iface_table[ipa_if_index].iface_name);
return IPA_INSTANCE_FOUND;
}
tmp = tmp->next;
}
IPACMDBG_H("No existed iface-instance name: %s,\n",
IPACM_Iface::ipacmcfg->iface_table[ipa_if_index].iface_name);
return IPA_INSTANCE_NOT_FOUND;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,102 +0,0 @@
/*
Copyright (c) 2013, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_log.cpp
@brief
This file implements the IPAM log functionality.
@Author
Skylar Chang
*/
#include "IPACM_Log.h"
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <asm/types.h>
#include <linux/if.h>
#include <sys/un.h>
#include <errno.h>
#include <IPACM_Defs.h>
/* start IPACMDIAG socket*/
int create_socket(int *sockfd)
{
if ((*sockfd = socket(AF_UNIX, SOCK_DGRAM, 0)) == IPACM_FAILURE)
{
perror("Error creating ipacm_log socket\n");
return IPACM_FAILURE;
}
if(fcntl(*sockfd, F_SETFD, FD_CLOEXEC) < 0)
{
perror("Couldn't set ipacm_log Close on Exec\n");
}
return IPACM_SUCCESS;
}
void ipacm_log_send( void * user_data)
{
ipacm_log_buffer_t ipacm_log_buffer;
int numBytes=0, len;
struct sockaddr_un ipacmlog_socket;
static int ipacm_log_sockfd = 0;
if(ipacm_log_sockfd == 0)
{
/* start ipacm_log socket */
if(create_socket(&ipacm_log_sockfd) < 0)
{
printf("unable to create ipacm_log socket\n");
return;
}
printf("create ipacm_log socket successfully\n");
}
ipacmlog_socket.sun_family = AF_UNIX;
strlcpy(ipacmlog_socket.sun_path, IPACMLOG_FILE,sizeof(ipacmlog_socket.sun_path));
len = strlen(ipacmlog_socket.sun_path) + sizeof(ipacmlog_socket.sun_family);
memcpy(ipacm_log_buffer.user_data, user_data, MAX_BUF_LEN);
//printf("send : %s\n", ipacm_log_buffer.user_data);
if ((numBytes = sendto(ipacm_log_sockfd, (void *)&ipacm_log_buffer, sizeof(ipacm_log_buffer.user_data), 0,
(struct sockaddr *)&ipacmlog_socket, len)) == -1)
{
printf("Send Failed(%d) %s \n",errno,strerror(errno));
return;
}
return;
}

File diff suppressed because it is too large Load diff

View file

@ -1,582 +0,0 @@
/*
Copyright (c) 2013-2019, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_Neighbor.cpp
@brief
This file implements the functionality of handling IPACM Neighbor events.
@Author
Skylar Chang
*/
#include <sys/ioctl.h>
#include <IPACM_Neighbor.h>
#include <IPACM_EvtDispatcher.h>
#include "IPACM_Defs.h"
#include "IPACM_Log.h"
IPACM_Neighbor::IPACM_Neighbor()
{
num_neighbor_client = 0;
circular_index = 0;
memset(neighbor_client, 0, IPA_MAX_NUM_NEIGHBOR_CLIENTS * sizeof(ipa_neighbor_client));
IPACM_EvtDispatcher::registr(IPA_WLAN_CLIENT_ADD_EVENT_EX, this);
IPACM_EvtDispatcher::registr(IPA_NEW_NEIGH_EVENT, this);
IPACM_EvtDispatcher::registr(IPA_DEL_NEIGH_EVENT, this);
return;
}
void IPACM_Neighbor::event_callback(ipa_cm_event_id event, void *param)
{
ipacm_event_data_all *data_all = NULL;
int i, ipa_interface_index;
ipacm_cmd_q_data evt_data;
int num_neighbor_client_temp = num_neighbor_client;
IPACMDBG("Recieved event %d\n", event);
switch (event)
{
case IPA_WLAN_CLIENT_ADD_EVENT_EX:
{
ipacm_event_data_wlan_ex *data = (ipacm_event_data_wlan_ex *)param;
ipa_interface_index = IPACM_Iface::iface_ipa_index_query(data->if_index);
/* check for failure return */
if (IPACM_FAILURE == ipa_interface_index) {
IPACMERR("IPA_WLAN_CLIENT_ADD_EVENT_EX: not supported iface id: %d\n", data->if_index);
break;
}
uint8_t client_mac_addr[6] = {0};
IPACMDBG_H("Received IPA_WLAN_CLIENT_ADD_EVENT\n");
for(i = 0; i < data->num_of_attribs; i++)
{
if(data->attribs[i].attrib_type == WLAN_HDR_ATTRIB_MAC_ADDR)
{
memcpy(client_mac_addr,
data->attribs[i].u.mac_addr,
sizeof(client_mac_addr));
IPACMDBG_H("AP Mac Address %02x:%02x:%02x:%02x:%02x:%02x\n",
client_mac_addr[0], client_mac_addr[1], client_mac_addr[2],
client_mac_addr[3], client_mac_addr[4], client_mac_addr[5]);
}
else
{
IPACMDBG_H("The attribute type is not expected!\n");
}
}
for (i = 0; i < num_neighbor_client_temp; i++)
{
/* find the client */
if (memcmp(neighbor_client[i].mac_addr, client_mac_addr, sizeof(neighbor_client[i].mac_addr)) == 0)
{
/* check if iface is not bridge interface*/
if (strcmp(IPACM_Iface::ipacmcfg->ipa_virtual_iface_name, IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].iface_name) != 0)
{
/* use previous ipv4 first */
if(data->if_index != neighbor_client[i].iface_index)
{
IPACMERR("update new kernel iface index \n");
neighbor_client[i].iface_index = data->if_index;
}
/* check if client associated with previous network interface */
if(ipa_interface_index != neighbor_client[i].ipa_if_num)
{
IPACMERR("client associate to different AP \n");
return;
}
if (neighbor_client[i].v4_addr != 0) /* not 0.0.0.0 */
{
evt_data.event = IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT;
data_all = (ipacm_event_data_all *)malloc(sizeof(ipacm_event_data_all));
if (data_all == NULL)
{
IPACMERR("Unable to allocate memory\n");
return;
}
memset(data_all,0,sizeof(ipacm_event_data_all));
data_all->iptype = IPA_IP_v4;
data_all->if_index = neighbor_client[i].iface_index;
data_all->ipv4_addr = neighbor_client[i].v4_addr; //use previous ipv4 address
memcpy(data_all->mac_addr,
neighbor_client[i].mac_addr,
sizeof(data_all->mac_addr));
memcpy(data_all->iface_name, neighbor_client[i].iface_name,
sizeof(data_all->iface_name));
evt_data.evt_data = (void *)data_all;
IPACM_EvtDispatcher::PostEvt(&evt_data);
/* ask for replaced iface name*/
ipa_interface_index = IPACM_Iface::iface_ipa_index_query(data_all->if_index);
/* check for failure return */
if (IPACM_FAILURE == ipa_interface_index) {
IPACMERR("not supported iface id: %d\n", data_all->if_index);
} else {
IPACMDBG_H("Posted event %d, with %s for ipv4 client re-connect\n",
evt_data.event,
data_all->iface_name);
}
}
}
break;
}
}
}
break;
default:
{
if (event == IPA_NEW_NEIGH_EVENT)
{
IPACMDBG_H("Received IPA_NEW_NEIGH_EVENT\n");
}
else
{
IPACMDBG_H("Received IPA_DEL_NEIGH_EVENT\n");
}
ipacm_event_data_all *data = (ipacm_event_data_all *)param;
ipa_interface_index = IPACM_Iface::iface_ipa_index_query(data->if_index);
#ifndef FEATURE_L2TP
/* check for failure return */
if (IPACM_FAILURE == ipa_interface_index) {
IPACMERR("not supported iface id: %d\n", data->if_index);
break;
}
#endif
if (data->iptype == IPA_IP_v4)
{
if (data->ipv4_addr != 0) /* not 0.0.0.0 */
{
IPACMDBG("Got Neighbor event with ipv4 address: 0x%x \n", data->ipv4_addr);
/* check if ipv4 address is link local(169.254.xxx.xxx) */
if ((data->ipv4_addr & IPV4_ADDR_LINKLOCAL_MASK) == IPV4_ADDR_LINKLOCAL)
{
IPACMDBG_H("This is link local ipv4 address: 0x%x : ignore this NEIGH_EVENT\n", data->ipv4_addr);
return;
}
/* check if iface is bridge interface */
if (strcmp(IPACM_Iface::ipacmcfg->ipa_virtual_iface_name, data->iface_name) == 0)
{
/* search if seen this client or not */
for (i = 0; i < num_neighbor_client_temp; i++)
{
if (memcmp(neighbor_client[i].mac_addr, data->mac_addr, sizeof(neighbor_client[i].mac_addr)) == 0)
{
data->if_index = neighbor_client[i].iface_index;
strlcpy(data->iface_name, neighbor_client[i].iface_name, sizeof(data->iface_name));
neighbor_client[i].v4_addr = data->ipv4_addr; // cache client's previous ipv4 address
/* construct IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT command and insert to command-queue */
if (event == IPA_NEW_NEIGH_EVENT)
evt_data.event = IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT;
else
/* not to clean-up the client mac cache on bridge0 delneigh */
evt_data.event = IPA_NEIGH_CLIENT_IP_ADDR_DEL_EVENT;
data_all = (ipacm_event_data_all *)malloc(sizeof(ipacm_event_data_all));
if (data_all == NULL)
{
IPACMERR("Unable to allocate memory\n");
return;
}
memcpy(data_all, data, sizeof(ipacm_event_data_all));
evt_data.evt_data = (void *)data_all;
IPACM_EvtDispatcher::PostEvt(&evt_data);
/* ask for replaced iface name*/
ipa_interface_index = IPACM_Iface::iface_ipa_index_query(data_all->if_index);
/* check for failure return */
if (IPACM_FAILURE == ipa_interface_index) {
IPACMERR("not supported iface id: %d\n", data_all->if_index);
} else {
IPACMDBG_H("Posted event %d,\
with %s for ipv4\n",
evt_data.event,
data->iface_name);
}
break;
}
}
}
else
{
/* construct IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT command and insert to command-queue */
if (event == IPA_NEW_NEIGH_EVENT)
{
evt_data.event = IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT;
/* Also save to cache for ipv4 */
/*searh if seen this client or not*/
for (i = 0; i < num_neighbor_client_temp; i++)
{
/* find the client */
if (memcmp(neighbor_client[i].mac_addr, data->mac_addr, sizeof(neighbor_client[i].mac_addr)) == 0)
{
/* update the network interface client associated */
neighbor_client[i].ipa_if_num = ipa_interface_index;
neighbor_client[i].v4_addr = data->ipv4_addr; // cache client's previous ipv4 address
strlcpy(neighbor_client[i].iface_name, data->iface_name, sizeof(neighbor_client[i].iface_name));
neighbor_client[i].iface_index = data->if_index;
IPACMDBG_H("update cache %d-entry, with %s iface, ipv4 address: 0x%x\n",
i, data->iface_name, data->ipv4_addr);
break;
}
}
/* not find client */
if (i == num_neighbor_client_temp)
{
if (num_neighbor_client_temp < IPA_MAX_NUM_NEIGHBOR_CLIENTS)
{
memcpy(neighbor_client[num_neighbor_client_temp].mac_addr,
data->mac_addr,
sizeof(data->mac_addr));
neighbor_client[num_neighbor_client_temp].iface_index = data->if_index;
/* cache the network interface client associated */
neighbor_client[num_neighbor_client_temp].ipa_if_num = ipa_interface_index;
neighbor_client[num_neighbor_client_temp].v4_addr = data->ipv4_addr;
strlcpy(neighbor_client[num_neighbor_client_temp].iface_name,
data->iface_name, sizeof(neighbor_client[num_neighbor_client_temp].iface_name));
num_neighbor_client++;
IPACMDBG_H("Cache client MAC %02x:%02x:%02x:%02x:%02x:%02x\n, total client: %d\n",
neighbor_client[num_neighbor_client_temp].mac_addr[0],
neighbor_client[num_neighbor_client_temp].mac_addr[1],
neighbor_client[num_neighbor_client_temp].mac_addr[2],
neighbor_client[num_neighbor_client_temp].mac_addr[3],
neighbor_client[num_neighbor_client_temp].mac_addr[4],
neighbor_client[num_neighbor_client_temp].mac_addr[5],
num_neighbor_client);
}
else
{
IPACMERR("error: neighbor client oversize! recycle %d-st entry ! \n", circular_index);
memcpy(neighbor_client[circular_index].mac_addr,
data->mac_addr,
sizeof(data->mac_addr));
neighbor_client[circular_index].iface_index = data->if_index;
/* cache the network interface client associated */
neighbor_client[circular_index].ipa_if_num = ipa_interface_index;
neighbor_client[circular_index].v4_addr = 0;
strlcpy(neighbor_client[circular_index].iface_name,
data->iface_name, sizeof(neighbor_client[circular_index].iface_name));
IPACMDBG_H("Copy wlan-iface client MAC %02x:%02x:%02x:%02x:%02x:%02x\n, total client: %d, circular %d\n",
neighbor_client[circular_index].mac_addr[0],
neighbor_client[circular_index].mac_addr[1],
neighbor_client[circular_index].mac_addr[2],
neighbor_client[circular_index].mac_addr[3],
neighbor_client[circular_index].mac_addr[4],
neighbor_client[circular_index].mac_addr[5],
num_neighbor_client,
circular_index);
circular_index = (circular_index + 1) % IPA_MAX_NUM_NEIGHBOR_CLIENTS;
}
}
}
else
{
evt_data.event = IPA_NEIGH_CLIENT_IP_ADDR_DEL_EVENT;
/*search if seen this client or not*/
for (i = 0; i < num_neighbor_client_temp; i++)
{
/* find the client */
if (memcmp(neighbor_client[i].mac_addr, data->mac_addr, sizeof(neighbor_client[i].mac_addr)) == 0)
{
IPACMDBG_H("Clean %d-st Cached client-MAC %02x:%02x:%02x:%02x:%02x:%02x\n, total client: %d\n",
i,
neighbor_client[i].mac_addr[0],
neighbor_client[i].mac_addr[1],
neighbor_client[i].mac_addr[2],
neighbor_client[i].mac_addr[3],
neighbor_client[i].mac_addr[4],
neighbor_client[i].mac_addr[5],
num_neighbor_client);
memset(neighbor_client[i].mac_addr, 0, sizeof(neighbor_client[i].mac_addr));
neighbor_client[i].iface_index = 0;
neighbor_client[i].v4_addr = 0;
neighbor_client[i].ipa_if_num = 0;
memset(neighbor_client[i].iface_name, 0, sizeof(neighbor_client[i].iface_name));
for (; i < num_neighbor_client_temp - 1; i++)
{
memcpy(neighbor_client[i].mac_addr,
neighbor_client[i + 1].mac_addr,
sizeof(neighbor_client[i].mac_addr));
neighbor_client[i].iface_index = neighbor_client[i + 1].iface_index;
neighbor_client[i].v4_addr = neighbor_client[i + 1].v4_addr;
neighbor_client[i].ipa_if_num = neighbor_client[i + 1].ipa_if_num;
strlcpy(neighbor_client[i].iface_name, neighbor_client[i + 1].iface_name,
sizeof(neighbor_client[i].iface_name));
}
num_neighbor_client--;
IPACMDBG_H(" total number of left cased clients: %d\n", num_neighbor_client);
break;
}
}
/* not find client, no need clean-up */
}
data_all = (ipacm_event_data_all *)malloc(sizeof(ipacm_event_data_all));
if (data_all == NULL)
{
IPACMERR("Unable to allocate memory\n");
return;
}
memcpy(data_all, data, sizeof(ipacm_event_data_all));
evt_data.evt_data = (void *)data_all;
IPACM_EvtDispatcher::PostEvt(&evt_data);
IPACMDBG_H("Posted event %d with %s for ipv4\n",
evt_data.event, data->iface_name);
}
}
}
else
{ //ipv6 starts
if ((data->ipv6_addr[0]) || (data->ipv6_addr[1]) || (data->ipv6_addr[2]) || (data->ipv6_addr[3]))
{
IPACMDBG("Got New_Neighbor event with ipv6 address \n");
/* check if iface is bridge interface */
if (strcmp(IPACM_Iface::ipacmcfg->ipa_virtual_iface_name, data->iface_name) == 0)
{
/* search if seen this client or not*/
for (i = 0; i < num_neighbor_client_temp; i++)
{
if (memcmp(neighbor_client[i].mac_addr, data->mac_addr, sizeof(neighbor_client[i].mac_addr)) == 0)
{
data->if_index = neighbor_client[i].iface_index;
strlcpy(data->iface_name, neighbor_client[i].iface_name, sizeof(data->iface_name));
/* construct IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT command and insert to command-queue */
if (event == IPA_NEW_NEIGH_EVENT)
evt_data.event = IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT;
else
evt_data.event = IPA_NEIGH_CLIENT_IP_ADDR_DEL_EVENT;
data_all = (ipacm_event_data_all *)malloc(sizeof(ipacm_event_data_all));
if (data_all == NULL)
{
IPACMERR("Unable to allocate memory\n");
return;
}
memcpy(data_all, data, sizeof(ipacm_event_data_all));
evt_data.evt_data = (void *)data_all;
IPACM_EvtDispatcher::PostEvt(&evt_data);
/* ask for replaced iface name*/
ipa_interface_index = IPACM_Iface::iface_ipa_index_query(data_all->if_index);
/* check for failure return */
if (IPACM_FAILURE == ipa_interface_index) {
IPACMERR("not supported iface id: %d\n", data_all->if_index);
} else {
IPACMDBG_H("Posted event %d,\
with %s for ipv6\n",
evt_data.event,
data->iface_name);
}
break;
};
}
}
else
{
/* construct IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT command and insert to command-queue */
if (event == IPA_NEW_NEIGH_EVENT)
evt_data.event = IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT;
else
evt_data.event = IPA_NEIGH_CLIENT_IP_ADDR_DEL_EVENT;
data_all = (ipacm_event_data_all *)malloc(sizeof(ipacm_event_data_all));
if (data_all == NULL)
{
IPACMERR("Unable to allocate memory\n");
return;
}
memcpy(data_all, data, sizeof(ipacm_event_data_all));
evt_data.evt_data = (void *)data_all;
IPACM_EvtDispatcher::PostEvt(&evt_data);
IPACMDBG_H("Posted event %d with %s for ipv6\n",
evt_data.event, data->iface_name);
}
}
else
{
IPACMDBG(" Got Neighbor event with no ipv6/ipv4 address \n");
/*no ipv6 in data searh if seen this client or not*/
for (i = 0; i < num_neighbor_client_temp; i++)
{
/* find the client */
if (memcmp(neighbor_client[i].mac_addr, data->mac_addr, sizeof(neighbor_client[i].mac_addr)) == 0)
{
IPACMDBG_H(" find %d-st client, MAC %02x:%02x:%02x:%02x:%02x:%02x\n, total client: %d\n",
i,
neighbor_client[i].mac_addr[0],
neighbor_client[i].mac_addr[1],
neighbor_client[i].mac_addr[2],
neighbor_client[i].mac_addr[3],
neighbor_client[i].mac_addr[4],
neighbor_client[i].mac_addr[5],
num_neighbor_client);
/* check if iface is not bridge interface*/
if (strcmp(IPACM_Iface::ipacmcfg->ipa_virtual_iface_name, data->iface_name) != 0)
{
/* use previous ipv4 first */
if(data->if_index != neighbor_client[i].iface_index)
{
IPACMDBG_H("update new kernel iface index \n");
neighbor_client[i].iface_index = data->if_index;
strlcpy(neighbor_client[i].iface_name, data->iface_name, sizeof(neighbor_client[i].iface_name));
}
/* check if client associated with previous network interface */
if(ipa_interface_index != neighbor_client[i].ipa_if_num)
{
IPACMDBG_H("client associate to different AP \n");
}
if (neighbor_client[i].v4_addr != 0) /* not 0.0.0.0 */
{
/* construct IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT command and insert to command-queue */
if (event == IPA_NEW_NEIGH_EVENT)
evt_data.event = IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT;
else
evt_data.event = IPA_NEIGH_CLIENT_IP_ADDR_DEL_EVENT;
data_all = (ipacm_event_data_all *)malloc(sizeof(ipacm_event_data_all));
if (data_all == NULL)
{
IPACMERR("Unable to allocate memory\n");
return;
}
data_all->iptype = IPA_IP_v4;
data_all->if_index = neighbor_client[i].iface_index;
data_all->ipv4_addr = neighbor_client[i].v4_addr; //use previous ipv4 address
memcpy(data_all->mac_addr, neighbor_client[i].mac_addr,
sizeof(data_all->mac_addr));
strlcpy(data_all->iface_name, neighbor_client[i].iface_name, sizeof(data_all->iface_name));
evt_data.evt_data = (void *)data_all;
IPACM_EvtDispatcher::PostEvt(&evt_data);
IPACMDBG_H("Posted event %d with %s for ipv4\n",
evt_data.event, data_all->iface_name);
}
}
/* delete cache neighbor entry */
if (event == IPA_DEL_NEIGH_EVENT)
{
IPACMDBG_H("Clean %d-st Cached client-MAC %02x:%02x:%02x:%02x:%02x:%02x\n, total client: %d\n",
i,
neighbor_client[i].mac_addr[0],
neighbor_client[i].mac_addr[1],
neighbor_client[i].mac_addr[2],
neighbor_client[i].mac_addr[3],
neighbor_client[i].mac_addr[4],
neighbor_client[i].mac_addr[5],
num_neighbor_client);
memset(neighbor_client[i].mac_addr, 0, sizeof(neighbor_client[i].mac_addr));
neighbor_client[i].iface_index = 0;
neighbor_client[i].v4_addr = 0;
neighbor_client[i].ipa_if_num = 0;
memset(neighbor_client[i].iface_name, 0, sizeof(neighbor_client[i].iface_name));
for(; i < num_neighbor_client_temp - 1; i++)
{
memcpy(neighbor_client[i].mac_addr,
neighbor_client[i + 1].mac_addr,
sizeof(neighbor_client[i].mac_addr));
neighbor_client[i].iface_index = neighbor_client[i + 1].iface_index;
neighbor_client[i].v4_addr = neighbor_client[i + 1].v4_addr;
neighbor_client[i].ipa_if_num = neighbor_client[i + 1].ipa_if_num;
strlcpy(neighbor_client[i].iface_name, neighbor_client[i + 1].iface_name,
sizeof(neighbor_client[i].iface_name));
}
num_neighbor_client--;
IPACMDBG_H(" total number of left cased clients: %d\n", num_neighbor_client);
}
break;
}
}
/* not find client */
if ((i == num_neighbor_client_temp) && (event == IPA_NEW_NEIGH_EVENT))
{
/* check if iface is not bridge interface*/
if (strcmp(IPACM_Iface::ipacmcfg->ipa_virtual_iface_name, data->iface_name) != 0)
{
if (num_neighbor_client_temp < IPA_MAX_NUM_NEIGHBOR_CLIENTS)
{
memcpy(neighbor_client[num_neighbor_client_temp].mac_addr,
data->mac_addr,
sizeof(data->mac_addr));
neighbor_client[num_neighbor_client_temp].iface_index = data->if_index;
/* cache the network interface client associated */
neighbor_client[num_neighbor_client_temp].ipa_if_num = ipa_interface_index;
neighbor_client[num_neighbor_client_temp].v4_addr = 0;
strlcpy(neighbor_client[num_neighbor_client_temp].iface_name, data->iface_name,
sizeof(neighbor_client[num_neighbor_client_temp].iface_name));
num_neighbor_client++;
IPACMDBG_H("Copy client MAC %02x:%02x:%02x:%02x:%02x:%02x\n, total client: %d\n",
neighbor_client[num_neighbor_client_temp].mac_addr[0],
neighbor_client[num_neighbor_client_temp].mac_addr[1],
neighbor_client[num_neighbor_client_temp].mac_addr[2],
neighbor_client[num_neighbor_client_temp].mac_addr[3],
neighbor_client[num_neighbor_client_temp].mac_addr[4],
neighbor_client[num_neighbor_client_temp].mac_addr[5],
num_neighbor_client);
return;
}
else
{
IPACMERR("error: neighbor client oversize! recycle %d-st entry ! \n", circular_index);
memcpy(neighbor_client[circular_index].mac_addr,
data->mac_addr,
sizeof(data->mac_addr));
neighbor_client[circular_index].iface_index = data->if_index;
/* cache the network interface client associated */
neighbor_client[circular_index].ipa_if_num = ipa_interface_index;
neighbor_client[circular_index].v4_addr = 0;
strlcpy(neighbor_client[circular_index].iface_name, data->iface_name,
sizeof(neighbor_client[circular_index].iface_name));
IPACMDBG_H("Copy wlan-iface client MAC %02x:%02x:%02x:%02x:%02x:%02x\n, total client: %d, circular %d\n",
neighbor_client[circular_index].mac_addr[0],
neighbor_client[circular_index].mac_addr[1],
neighbor_client[circular_index].mac_addr[2],
neighbor_client[circular_index].mac_addr[3],
neighbor_client[circular_index].mac_addr[4],
neighbor_client[circular_index].mac_addr[5],
num_neighbor_client,
circular_index);
circular_index = (circular_index + 1) % IPA_MAX_NUM_NEIGHBOR_CLIENTS;
return;
}
}
}
}
} //ipv6 ends
}
break;
}
return;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,385 +0,0 @@
/*
Copyright (c) 2013, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_Routing.cpp
@brief
This file implements the IPACM routing functionality.
@Author
*/
#include <unistd.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include "IPACM_Routing.h"
#include <IPACM_Log.h>
const char *IPACM_Routing::DEVICE_NAME = "/dev/ipa";
IPACM_Routing::IPACM_Routing()
{
m_fd = open(DEVICE_NAME, O_RDWR);
if (0 == m_fd)
{
IPACMERR("Failed opening %s.\n", DEVICE_NAME);
}
}
IPACM_Routing::~IPACM_Routing()
{
close(m_fd);
}
bool IPACM_Routing::DeviceNodeIsOpened()
{
int res = fcntl(m_fd, F_GETFL);
if (m_fd > 0 && res >= 0) return true;
else return false;
}
bool IPACM_Routing::AddRoutingRule(struct ipa_ioc_add_rt_rule *ruleTable)
{
int retval = 0, cnt=0;
bool isInvalid = false;
if (!DeviceNodeIsOpened())
{
IPACMERR("Device is not opened\n");
return false;
}
for(cnt=0; cnt<ruleTable->num_rules; cnt++)
{
if(ruleTable->rules[cnt].rule.dst > IPA_CLIENT_MAX)
{
IPACMERR("Invalid dst pipe, Rule:%d dst_pipe:%d\n", cnt, ruleTable->rules[cnt].rule.dst);
isInvalid = true;
}
}
if(isInvalid)
{
return false;
}
retval = ioctl(m_fd, IPA_IOC_ADD_RT_RULE, ruleTable);
if (retval)
{
IPACMERR("Failed adding routing rule %p\n", ruleTable);
return false;
}
for(cnt=0; cnt<ruleTable->num_rules; cnt++)
{
IPACMDBG("Rule:%d dst_pipe:%d\n", cnt, ruleTable->rules[cnt].rule.dst);
}
IPACMDBG_H("Added routing rule %p\n", ruleTable);
return true;
}
#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO
bool IPACM_Routing::AddRoutingRule_hw_index(struct ipa_ioc_add_rt_rule *ruleTable, int hw_counter_index)
{
int retval = 0, cnt = 0, len = 0;
struct ipa_ioc_add_rt_rule_v2 *ruleTable_v2;
struct ipa_rt_rule_add_v2 rt_rule_entry;
bool ret = true;
IPACMDBG("Printing routing add attributes\n");
IPACMDBG("ip type: %d\n", ruleTable->ip);
IPACMDBG("rt tbl type: %s\n", ruleTable->rt_tbl_name);
IPACMDBG("Number of rules: %d\n", ruleTable->num_rules);
IPACMDBG("commit value: %d\n", ruleTable->commit);
/* change to v2 format*/
len = sizeof(struct ipa_ioc_add_rt_rule_v2);
ruleTable_v2 = (struct ipa_ioc_add_rt_rule_v2*)malloc(len);
if (ruleTable_v2 == NULL)
{
IPACMERR("Error Locate ipa_ioc_add_rt_rule_v2 memory...\n");
return false;
}
memset(ruleTable_v2, 0, len);
ruleTable_v2->rules = (uint64_t)calloc(ruleTable->num_rules, sizeof(struct ipa_rt_rule_add_v2));
if (!ruleTable_v2->rules) {
IPACMERR("Failed to allocate memory for routing rules\n");
ret = false;
goto fail_tbl;
}
ruleTable_v2->commit = ruleTable->commit;
ruleTable_v2->ip = ruleTable->ip;
ruleTable_v2->num_rules = ruleTable->num_rules;
ruleTable_v2->rule_add_size = sizeof(struct ipa_rt_rule_add_v2);
memcpy(ruleTable_v2->rt_tbl_name,
ruleTable->rt_tbl_name,
sizeof(ruleTable_v2->rt_tbl_name));
for (cnt=0; cnt < ruleTable->num_rules; cnt++)
{
memset(&rt_rule_entry, 0, sizeof(struct ipa_rt_rule_add_v2));
rt_rule_entry.at_rear = ruleTable->rules[cnt].at_rear;
rt_rule_entry.rule.dst = ruleTable->rules[cnt].rule.dst;
rt_rule_entry.rule.hdr_hdl = ruleTable->rules[cnt].rule.hdr_hdl;
rt_rule_entry.rule.hdr_proc_ctx_hdl = ruleTable->rules[cnt].rule.hdr_proc_ctx_hdl;
rt_rule_entry.rule.max_prio = ruleTable->rules[cnt].rule.max_prio;
rt_rule_entry.rule.hashable = ruleTable->rules[cnt].rule.hashable;
rt_rule_entry.rule.retain_hdr = ruleTable->rules[cnt].rule.retain_hdr;
rt_rule_entry.rule.coalesce = ruleTable->rules[cnt].rule.coalesce;
memcpy(&rt_rule_entry.rule.attrib,
&ruleTable->rules[cnt].rule.attrib,
sizeof(rt_rule_entry.rule.attrib));
IPACMDBG("RT 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)
{
rt_rule_entry.rule.enable_stats = 1;
rt_rule_entry.rule.cnt_idx = hw_counter_index;
}
/* copy to v2 table*/
memcpy((void *)(ruleTable_v2->rules + (cnt * sizeof(struct ipa_rt_rule_add_v2))),
&rt_rule_entry, sizeof(rt_rule_entry));
}
retval = ioctl(m_fd, IPA_IOC_ADD_RT_RULE_V2, ruleTable_v2);
if (retval != 0)
{
IPACMERR("Failed adding Routing rule %pK\n", ruleTable_v2);
PERROR("unable to add routing rule:");
for (int cnt = 0; cnt < ruleTable_v2->num_rules; cnt++)
{
if (((struct ipa_rt_rule_add_v2 *)ruleTable_v2->rules)[cnt].status != 0)
{
IPACMERR("Adding Routing rule:%d failed with status:%d\n",
cnt, ((struct ipa_rt_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_rt_rule_add_v2 *)ruleTable_v2->rules)[cnt].status;
ruleTable->rules[cnt].rt_rule_hdl = ((struct ipa_rt_rule_add_v2 *)ruleTable_v2->rules)[cnt].rt_rule_hdl;
if(((struct ipa_rt_rule_add_v2 *)ruleTable_v2->rules)[cnt].status != 0)
{
IPACMERR("Adding Routing rule:%d failed with status:%d\n",
cnt, ((struct ipa_rt_rule_add_v2 *) ruleTable_v2->rules)[cnt].status);
}
}
IPACMDBG("Added Routing 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);
return ret;
}
#endif //IPA_IOCTL_SET_FNR_COUNTER_INFO
bool IPACM_Routing::DeleteRoutingRule(struct ipa_ioc_del_rt_rule *ruleTable)
{
int retval = 0;
if (!DeviceNodeIsOpened()) return false;
retval = ioctl(m_fd, IPA_IOC_DEL_RT_RULE, ruleTable);
if (retval)
{
IPACMERR("Failed deleting routing rule table %p\n", ruleTable);
return false;
}
IPACMDBG_H("Deleted routing rule %p\n", ruleTable);
return true;
}
bool IPACM_Routing::Commit(enum ipa_ip_type ip)
{
int retval = 0;
if (!DeviceNodeIsOpened()) return false;
retval = ioctl(m_fd, IPA_IOC_COMMIT_RT, ip);
if (retval)
{
IPACMERR("Failed commiting routing rules.\n");
return false;
}
IPACMDBG_H("Commited routing rules to IPA HW.\n");
return true;
}
bool IPACM_Routing::Reset(enum ipa_ip_type ip)
{
int retval = 0;
if (!DeviceNodeIsOpened()) return false;
retval = ioctl(m_fd, IPA_IOC_RESET_RT, ip);
retval |= ioctl(m_fd, IPA_IOC_COMMIT_RT, ip);
if (retval)
{
IPACMERR("Failed resetting routing block.\n");
return false;
}
IPACMDBG_H("Reset command issued to IPA routing block.\n");
return true;
}
bool IPACM_Routing::GetRoutingTable(struct ipa_ioc_get_rt_tbl *routingTable)
{
int retval = 0;
if (!DeviceNodeIsOpened()) return false;
retval = ioctl(m_fd, IPA_IOC_GET_RT_TBL, routingTable);
if (retval)
{
IPACMERR("IPA_IOCTL_GET_RT_TBL ioctl failed, routingTable =0x%p, retval=0x%x.\n", routingTable, retval);
return false;
}
IPACMDBG_H("IPA_IOCTL_GET_RT_TBL ioctl issued to IPA routing block.\n");
/* put routing table right after successfully get routing table */
PutRoutingTable(routingTable->hdl);
return true;
}
bool IPACM_Routing::PutRoutingTable(uint32_t routingTableHandle)
{
int retval = 0;
if (!DeviceNodeIsOpened()) return false;
retval = ioctl(m_fd, IPA_IOC_PUT_RT_TBL, routingTableHandle);
if (retval)
{
IPACMERR("IPA_IOCTL_PUT_RT_TBL ioctl failed.\n");
return false;
}
IPACMDBG_H("IPA_IOCTL_PUT_RT_TBL ioctl issued to IPA routing block.\n");
return true;
}
bool IPACM_Routing::DeleteRoutingHdl(uint32_t rt_rule_hdl, ipa_ip_type ip)
{
const uint8_t NUM_RULES = 1;
struct ipa_ioc_del_rt_rule *rt_rule;
struct ipa_rt_rule_del *rt_rule_entry;
bool res = true;
int len = 0;
if (rt_rule_hdl == 0)
{
IPACMERR(" No route handle passed. Ignoring it\n");
return res;
}
len = (sizeof(struct ipa_ioc_del_rt_rule)) + (NUM_RULES * sizeof(struct ipa_rt_rule_del));
rt_rule = (struct ipa_ioc_del_rt_rule *)malloc(len);
if (rt_rule == NULL)
{
IPACMERR("unable to allocate memory for del route rule\n");
return false;
}
memset(rt_rule, 0, len);
rt_rule->commit = 1;
rt_rule->num_hdls = NUM_RULES;
rt_rule->ip = ip;
rt_rule_entry = &rt_rule->hdl[0];
rt_rule_entry->status = -1;
rt_rule_entry->hdl = rt_rule_hdl;
IPACMDBG_H("Deleting Route hdl:(0x%x) with ip type: %d\n", rt_rule_entry->hdl, ip);
if ((false == DeleteRoutingRule(rt_rule)) ||
(rt_rule_entry->status))
{
PERROR("Routing rule deletion failed!\n");
goto fail;
res = false;
}
fail:
free(rt_rule);
return res;
}
bool IPACM_Routing::ModifyRoutingRule(struct ipa_ioc_mdfy_rt_rule *mdfyRules)
{
int retval = 0, cnt;
if (!DeviceNodeIsOpened())
{
IPACMERR("Device is not opened\n");
return false;
}
retval = ioctl(m_fd, IPA_IOC_MDFY_RT_RULE, mdfyRules);
if (retval)
{
IPACMERR("Failed modifying routing rules %p\n", mdfyRules);
return false;
}
for(cnt=0; cnt<mdfyRules->num_rules; cnt++)
{
if(mdfyRules->rules[cnt].status != 0)
{
IPACMERR("Unable to modify rule: %d\n", cnt);
}
}
IPACMDBG_H("Modified routing rules %p\n", mdfyRules);
return true;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,180 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<system xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ipacm_cfg.xsd">
<ODUCFG>
<OduMode>router</OduMode>
<eMBMS_offload>0</eMBMS_offload>
</ODUCFG>
<IPACM>
<IPACMIface>
<Iface>
<Name>rndis0</Name>
<Category>LAN</Category>
</Iface>
<Iface>
<Name>ecm0</Name>
<Category>LAN</Category>
<Mode>ROUTER</Mode>
</Iface>
<Iface>
<Name>rmnet_data0</Name>
<Category>WAN</Category>
<Mode>ROUTER</Mode>
</Iface>
<Iface>
<Name>rmnet_data1</Name>
<Category>WAN</Category>
</Iface>
<Iface>
<Name>rmnet_data2</Name>
<Category>WAN</Category>
</Iface>
<Iface>
<Name>rmnet_data3</Name>
<Category>WAN</Category>
</Iface>
<Iface>
<Name>rmnet_data4</Name>
<Category>WAN</Category>
</Iface>
<Iface>
<Name>rmnet_data5</Name>
<Category>WAN</Category>
</Iface>
<Iface>
<Name>rmnet_data6</Name>
<Category>WAN</Category>
</Iface>
<Iface>
<Name>rmnet_data7</Name>
<Category>WAN</Category>
</Iface>
<Iface>
<Name>softap0</Name>
<Category>UNKNOWN</Category>
<WlanMode>full</WlanMode>
</Iface>
<Iface>
<Name>wigig0</Name>
<Category>UNKNOWN</Category>
<WlanMode>full</WlanMode>
</Iface>
<Iface>
<Name>wlan0</Name>
<Category>UNKNOWN</Category>
<WlanMode>full</WlanMode>
</Iface>
<Iface>
<Name>wlan1</Name>
<Category>UNKNOWN</Category>
<WlanMode>full</WlanMode>
</Iface>
<Iface>
<Name>wlan2</Name>
<Category>UNKNOWN</Category>
<WlanMode>full</WlanMode>
</Iface>
<Iface>
<Name>wlan3</Name>
<Category>UNKNOWN</Category>
<WlanMode>full</WlanMode>
</Iface>
<Iface>
<Name>eth0</Name>
<Category>ODU</Category>
</Iface>
<Iface>
<Name>bridge0</Name>
<Category>VIRTUAL</Category>
</Iface>
</IPACMIface>
<IPPassthroughFlag>
<IPPassthroughMode>0</IPPassthroughMode>
</IPPassthroughFlag>
<IPACMPrivateSubnet>
<Subnet>
<SubnetAddress>192.168.225.0</SubnetAddress>
<SubnetMask>255.255.255.0</SubnetMask>
</Subnet>
</IPACMPrivateSubnet>
<IPACMALG>
<ALG>
<Protocol>TCP</Protocol>
<Port>21</Port>
<Description>FTP</Description>
</ALG>
<ALG>
<Protocol>TCP</Protocol>
<Port>554</Port>
<Description>RTSP</Description>
</ALG>
<ALG>
<Protocol>TCP</Protocol>
<Port>5060</Port>
<Description>SIP</Description>
</ALG>
<ALG>
<Protocol>UDP</Protocol>
<Port>5060</Port>
<Description>SIP</Description>
</ALG>
<ALG>
<Protocol>TCP</Protocol>
<Port>1723</Port>
<Description>PPTP</Description>
</ALG>
<ALG>
<Protocol>UDP</Protocol>
<Port>69</Port>
<Description>TFTP</Description>
</ALG>
<ALG>
<Protocol>UDP</Protocol>
<Port>53</Port>
<Description>DNS</Description>
</ALG>
<ALG>
<Protocol>TCP</Protocol>
<Port>53</Port>
<Description>DNS</Description>
</ALG>
<ALG>
<Protocol>UDP</Protocol>
<Port>10080</Port>
<Description>AMANDA</Description>
</ALG>
<ALG>
<Protocol>UDP</Protocol>
<Port>1719</Port>
<Description>H323</Description>
</ALG>
<ALG>
<Protocol>TCP</Protocol>
<Port>1720</Port>
<Description>H323</Description>
</ALG>
<ALG>
<Protocol>TCP</Protocol>
<Port>6667</Port>
<Description>IRC</Description>
</ALG>
<ALG>
<Protocol>UDP</Protocol>
<Port>137</Port>
<Description>NETBIOS_NS</Description>
</ALG>
<ALG>
<Protocol>UDP</Protocol>
<Port>138</Port>
<Description>NETBIOS_NS</Description>
</ALG>
<ALG>
<Protocol>TCP</Protocol>
<Port>6566</Port>
<Description>SANE</Description>
</ALG>
</IPACMALG>
<IPACMNAT>
<MaxNatEntries>500</MaxNatEntries>
</IPACMNAT>
</IPACM>
</system>

View file

@ -1,55 +0,0 @@
AM_CPPFLAGS = -I./../inc \
-I$(top_srcdir)/ipanat/inc \
${LIBXML_CFLAGS}
AM_CPPFLAGS += -Wall -Wundef -Wno-trigraphs
AM_CPPFLAGS += -DDEBUG -g -DFEATURE_ETH_BRIDGE_LE -DFEATURE_L2TP
AM_CPPFLAGS += -DFEATURE_IPA_V3
ipacm_SOURCES = IPACM_Main.cpp \
IPACM_Conntrack_NATApp.cpp\
IPACM_ConntrackClient.cpp \
IPACM_ConntrackListener.cpp \
IPACM_EvtDispatcher.cpp \
IPACM_Config.cpp \
IPACM_CmdQueue.cpp \
IPACM_Log.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_LanToLan.cpp
bin_PROGRAMS = ipacm
requiredlibs = ${LIBXML_LIB} -lxml2 -lpthread -lnetfilter_conntrack -lnfnetlink\
../../ipanat/src/libipanat.la
AM_CPPFLAGS += "-std=c++0x"
if USE_GLIB
ipacm_CFLAGS = $(AM_CFLAGS) -DUSE_GLIB @GLIB_CFLAGS@
ipacm_LDFLAGS = -lpthread @GLIB_LIBS@
ipacm_CPPFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(AM_CPPFLAGS) @GLIB_CFLAGS@
else
ipacm_CFLAGS = $(AM_CFLAGS)
ipacm_LDFLAGS = -lpthread
ipacm_CPPFLAGS = $(AM_CPPFLAGS)
endif
ipacm_LDADD = $(requiredlibs)
LOCAL_MODULE := libipanat
LOCAL_PRELINK_MODULE := false
include $(BUILD_SHARED_LIBRARY)
etcdir = ${sysconfdir}
etc_SCRIPTS = IPACM_cfg.xml
init_ddir = ${sysconfdir}/init.d
init_d_SCRIPTS = start_ipacm_le

View file

@ -1,36 +0,0 @@
# Copyright (c) 2019, 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
# met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of The Linux Foundation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# 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
user radio
group radio inet

View file

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<system xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="mobileap_firewall_cfg.xsd">
<MobileAPFirewallCfg>
<FirewallEnabled>1</FirewallEnabled>
<FirewallPktsAllowed>0</FirewallPktsAllowed>
</MobileAPFirewallCfg>
</system>

View file

@ -1,57 +0,0 @@
#! /bin/sh
#
################################
# Copyright (c) 2013, 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
# met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of The Linux Foundation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
################################
# ipacm init.d script to start the data-ipa Software's ipacm daemon
set -e
case "$1" in
start)
echo -n "Starting ipacm: "
start-stop-daemon -S -b -a ipacm
echo "done"
;;
stop)
echo -n "Stopping ipacm: "
start-stop-daemon -K -n ipacm
echo "done"
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage ipacm { start | stop | restart}" >&2
exit 1
;;
esac
exit 0

View file

@ -1,56 +0,0 @@
TARGET_DISABLE_IPACM := false
ifneq ($(TARGET_BOARD_SUFFIX),_au)
#IPACM_DATA
IPACM_DATA += IPACM_cfg.xml
IPACM_DATA += ipacm
IPACM_DATA += ipacm.rc
endif
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
BOARD_IPA_LOW_RAM_EXCP_LIST += monaco
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
ifeq ($(TARGET_BOARD_SUFFIX),_au)
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)))
PRODUCT_PACKAGES += $(IPACM_DATA)
endif # $(TARGET_ARCH)
endif
endif
endif

View file

@ -1,28 +0,0 @@
cc_library_shared {
name: "libipanat",
header_libs: ["generated_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,
}

View file

@ -1,147 +0,0 @@
/*
Copyright (c) 2013 - 2017, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef IPA_NAT_DRV_H
#define IPA_NAT_DRV_H
#include "string.h" /* memset */
#include "stdlib.h" /* free, malloc */
#include "stdint.h" /* uint32_t */
/**
* struct ipa_nat_ipv4_rule - To hold ipv4 nat rule
* @target_ip: destination ip address
* @private_ip: private ip address
* @target_port: destination port
* @private_port: private port
* @protocol: protocol of rule (tcp/udp)
* @pdn_index: PDN index in the PDN config table
*/
typedef struct {
uint32_t target_ip;
uint32_t private_ip;
uint16_t target_port;
uint16_t private_port;
uint16_t public_port;
uint8_t protocol;
uint8_t pdn_index;
} ipa_nat_ipv4_rule;
/**
* struct ipa_nat_pdn_entry - holds a PDN entry data
* @public_ip: PDN's public ip address
* @src_metadata: metadata to be used for source NAT metadata replacement
* @dst_metadata: metadata to be used for destination NAT metadata replacement
*/
typedef struct {
uint32_t public_ip;
uint32_t src_metadata;
uint32_t dst_metadata;
} ipa_nat_pdn_entry;
/**
* ipa_nat_add_ipv4_tbl() - create ipv4 nat table
* @public_ip_addr: [in] public ipv4 address
* @number_of_entries: [in] number of nat entries
* @table_handle: [out] Handle of new ipv4 nat table
*
* To create new ipv4 nat table
*
* Returns: 0 On Success, negative on failure
*/
int ipa_nat_add_ipv4_tbl(uint32_t public_ip_addr,
uint16_t number_of_entries,
uint32_t *table_handle);
/**
* ipa_nat_del_ipv4_tbl() - delete ipv4 table
* @table_handle: [in] Handle of ipv4 nat table
*
* To delete given ipv4 nat table
*
* Returns: 0 On Success, negative on failure
*/
int ipa_nat_del_ipv4_tbl(uint32_t table_handle);
/**
* ipa_nat_add_ipv4_rule() - to insert new ipv4 rule
* @table_handle: [in] handle of ipv4 nat table
* @rule: [in] Pointer to new rule
* @rule_handle: [out] Return the handle to rule
*
* To insert new ipv4 nat rule into ipv4 nat table
*
* Returns: 0 On Success, negative on failure
*/
int ipa_nat_add_ipv4_rule(uint32_t table_handle,
const ipa_nat_ipv4_rule * rule,
uint32_t *rule_handle);
/**
* ipa_nat_del_ipv4_rule() - to delete ipv4 nat rule
* @table_handle: [in] handle of ipv4 nat table
* @rule_handle: [in] ipv4 nat rule handle
*
* To insert new ipv4 nat rule into ipv4 nat table
*
* Returns: 0 On Success, negative on failure
*/
int ipa_nat_del_ipv4_rule(uint32_t table_handle,
uint32_t rule_handle);
/**
* ipa_nat_query_timestamp() - to query timestamp
* @table_handle: [in] handle of ipv4 nat table
* @rule_handle: [in] ipv4 nat rule handle
* @time_stamp: [out] time stamp of rule
*
* To retrieve the timestamp that lastly the
* nat rule was accessed
*
* Returns: 0 On Success, negative on failure
*/
int ipa_nat_query_timestamp(uint32_t table_handle,
uint32_t rule_handle,
uint32_t *time_stamp);
/**
* ipa_nat_modify_pdn() - modify single PDN entry in the PDN config table
* @table_handle: [in] handle of ipv4 nat table
* @pdn_index : [in] the index of the entry to be modified
* @pdn_info : [in] values for the PDN entry to be changed
*
* Modify a PDN entry
*
* Returns: 0 On Success, negative on failure
*/
int ipa_nat_modify_pdn(uint32_t tbl_hdl,
uint8_t pdn_index,
ipa_nat_pdn_entry *pdn_info);
#endif /* IPA_NAT_DRV_H */

View file

@ -1,508 +0,0 @@
/*
Copyright (c) 2013 - 2019, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef IPA_NAT_DRVI_H
#define IPA_NAT_DRVI_H
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <linux/msm_ipa.h>
#include <netinet/in.h>
#include <sys/inotify.h>
#include <errno.h>
#include <pthread.h>
#include <unistd.h>
#include "ipa_nat_logi.h"
#define NAT_DUMP
/*======= IMPLEMENTATION related data structures and functions ======= */
#ifdef IPA_ON_R3PC
#define NAT_MMAP_MEM_SIZE (2 * 1024UL * 1024UL - 1)
#endif
#define IPA_DEV_NAME "/dev/ipa"
#define NAT_DEV_DIR "/dev"
#define NAT_DEV_NAME "ipaNatTable"
#define NAT_DEV_FULL_NAME "/dev/ipaNatTable"
#define IPA_NAT_TABLE_VALID 1
#define IPA_NAT_MAX_IP4_TBLS 1
#define IPA_NAT_BASE_TABLE_PERCENTAGE .8
#define IPA_NAT_EXPANSION_TABLE_PERCENTAGE .2
#define IPA_NAT_NUM_OF_BASE_TABLES 2
#define IPA_NAT_UNUSED_BASE_ENTRIES 2
#define IPA_NAT_RULE_FLAG_FIELD_OFFSET 18
#define IPA_NAT_RULE_NEXT_FIELD_OFFSET 8
#define IPA_NAT_RULE_PROTO_FIELD_OFFSET 22
#define IPA_NAT_INDEX_RULE_NEXT_FIELD_OFFSET 2
#define IPA_NAT_INDEX_RULE_NAT_INDEX_FIELD_OFFSET 0
#define IPA_NAT_RULE_FLAG_FIELD_SIZE 2
#define IPA_NAT_RULE_NEXTFIELD_FIELD_SIZE 2
#define IPA_NAT_FLAG_ENABLE_BIT_MASK 0x8000
#define IPA_NAT_FLAG_DISABLE_BIT_MASK 0x0000
#define IPA_NAT_FLAG_ENABLE_BIT 1
#define IPA_NAT_FLAG_DISABLE_BIT 0
#define IPA_NAT_INVALID_PROTO_FIELD_VALUE 0xFF00
#define IPA_NAT_INVALID_INDEX 0xFF
#define IPA_NAT_INVALID_NAT_ENTRY 0x0
#define INDX_TBL_ENTRY_SIZE_IN_BITS 16
/* ----------- Rule id -----------------------
------------------------------------------------
| 3bits | 12 bits | 1 bit |
------------------------------------------------
| reserved | index into table | 0 - base |
| | | 1 - expansion |
------------------------------------------------
*/
#define IPA_NAT_RULE_HDL_TBL_TYPE_BITS 0x1
#define IPA_NAT_RULE_HDL_TBL_TYPE_MASK 0x1
/* ----------- sw specif parameter -----
------------------------------------
| 16 bits | 16 bits |
------------------------------------
| index table | prev index |
| entry | |
------------------------------------
-----------------------------------------*/
#define IPA_NAT_SW_PARAM_PREV_INDX_BYTE 0
#define IPA_NAT_SW_PARAM_INDX_TBL_ENTRY_BYTE 1
typedef enum {
IPA_NAT_BASE_TBL = 0,
IPA_NAT_EXPN_TBL = 1,
IPA_NAT_INDX_TBL = 2,
IPA_NAT_INDEX_EXPN_TBL = 3,
} nat_table_type;
typedef enum {
NEXT_INDEX_FIELD,
PUBLIC_PORT_FILED,
PRIVATE_PORT_FIELD,
TARGET_PORT_FIELD,
IP_CHKSUM_FIELD,
ENABLE_FIELD,
TIME_STAMP_FIELD,
PROTOCOL_FIELD,
TCP_UDP_CHKSUM_FIELD,
SW_SPEC_PARAM_PREV_INDEX_FIELD,
SW_SPEC_PARAM_INDX_TBL_ENTRY_FIELD,
INDX_TBL_TBL_ENTRY_FIELD,
INDX_TBL_NEXT_INDEX_FILED
} ipa_nat_rule_field_type;
/*
---------------------------------------------
| 3 | 2 | 1 | 0 |
---------------------------------------------
| Public Port(2B) | Next Index(2B) |
---------------------------------------------
*/
typedef struct {
uint32_t next_index:16;
uint32_t public_port:16;
} next_index_pub_port;
/*
---------------------------------------------
| 3 | 2 | 1 | 0 |
---------------------------------------------
| Flags(2B) | IP check sum Diff(2B)|
|EN|FIN|Resv | | |
---------------------------------------------
*/
typedef struct {
uint32_t ip_chksum:16;
uint32_t rsvd1:14;
uint32_t redirect:1;
uint32_t enable:1;
} ipcksum_enbl;
/*
---------------------------------------
| 7 | 6 | 5 | 4 |
---------------------------------------
| Proto | TimeStamp(3B) |
| (1B) | |
---------------------------------------
*/
typedef struct {
uint32_t time_stamp:24;
uint32_t protocol:8;
} time_stamp_proto;
/*
---------------------------------------------
| 3 | 2 | 1 | 0 |
---------------------------------------------
| next_index | Table entry |
----------------------------------------------
*/
typedef struct {
uint16_t tbl_entry;
uint16_t next_index;
} tbl_ent_nxt_indx;
/*--------------------------------------------------
32 bit sw_spec_params is interpreted as follows
------------------------------------
| 16 bits | 16 bits |
------------------------------------
| index table | prev index |
| entry | |
------------------------------------
--------------------------------------------------*/
typedef struct {
uint16_t prev_index;
uint16_t index_table_entry;
} sw_spec_params;
/*------------------------ NAT Table Entry ---------------------------------------
-----------------------------------------------------------------------------------
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
-----------------------------------------------------------------------------------
| Target IP(4B) | Private IP(4B) |
-----------------------------------------------------------------------------------
|Target Port(2B) | Private Port(2B) | Public Port(2B) | Next Index(2B) |
-----------------------------------------------------------------------------------
| Proto | TimeStamp(3B) | Flags(2B) | IP check sum Diff(2B)|
| (1B) | |EN|FIN|Resv | | |
-----------------------------------------------------------------------------------
| TCP/UDP checksum |PDN info| Reserved| SW Specific Parameters(4B) |
| diff (2B) | (1B) | (1B) | |
-----------------------------------------------------------------------------------
Dont change below structure definition.
It should be same as above(little endian order)
-------------------------------------------------------------------------------*/
struct ipa_nat_rule {
uint64_t private_ip:32;
uint64_t target_ip:32;
uint64_t nxt_indx_pub_port:32;
uint64_t private_port:16;
uint64_t target_port:16;
uint64_t ip_cksm_enbl:32;
uint64_t ts_proto:32;
/*--------------------------------------------------
32 bit sw_spec_params is interpreted as follows
------------------------------------
| 16 bits | 16 bits |
------------------------------------
| index table | prev index |
| entry | |
------------------------------------
--------------------------------------------------*/
uint64_t sw_spec_params:32;
uint64_t rsvd2:8;
/*-----------------------------------------
8 bit PDN info is interpreted as following
------------------------------------
| 4 bits | 4 bits |
------------------------------------
| PDN index | reserved |
| | |
------------------------------------
-------------------------------------------*/
uint64_t rsvd3:4;
uint64_t pdn_index:4;
uint64_t tcp_udp_chksum:16;
};
struct ipa_nat_sw_rule {
uint64_t private_ip:32;
uint64_t target_ip:32;
uint64_t next_index:16;
uint64_t public_port:16;
uint64_t private_port:16;
uint64_t target_port:16;
uint64_t ip_chksum:16;
uint64_t rsvd1:14;
uint64_t redirect:1;
uint64_t enable:1;
uint64_t time_stamp:24;
uint64_t protocol:8;
/*--------------------------------------------------
32 bit sw_spec_params is interpreted as follows
------------------------------------
| 16 bits | 16 bits |
------------------------------------
| index table | prev index |
| entry | |
------------------------------------
--------------------------------------------------*/
uint64_t prev_index:16;
uint64_t indx_tbl_entry:16;
uint64_t rsvd2 :8;
/*-----------------------------------------
8 bit PDN info is interpreted as following
------------------------------------
| 4 bits | 4 bits |
------------------------------------
| PDN index | reserved |
| | |
------------------------------------
-------------------------------------------*/
uint64_t rsvd3 :4;
uint64_t pdn_index :4;
uint64_t tcp_udp_chksum:16;
};
#define IPA_NAT_TABLE_ENTRY_SIZE 32
#define IPA_NAT_INDEX_TABLE_ENTRY_SIZE 4
struct ipa_nat_indx_tbl_rule {
uint32_t tbl_entry_nxt_indx;
};
struct ipa_nat_sw_indx_tbl_rule {
uint16_t tbl_entry;
uint16_t next_index;
};
struct ipa_nat_indx_tbl_meta_info {
uint16_t prev_index;
};
struct ipa_nat_ip4_table_cache {
uint8_t valid;
uint32_t public_addr;
int nat_fd;
int size;
uint32_t tbl_addr_offset;
char table_name[IPA_RESOURCE_NAME_MAX];
char *ipv4_rules_addr;
char *index_table_addr;
uint16_t table_entries;
char *ipv4_expn_rules_addr;
char *index_table_expn_addr;
uint16_t expn_table_entries;
struct ipa_nat_indx_tbl_meta_info *index_expn_table_meta;
uint16_t *rule_id_array;
#ifdef IPA_ON_R3PC
uint32_t mmap_offset;
#endif
uint16_t cur_tbl_cnt;
uint16_t cur_expn_tbl_cnt;
};
struct ipa_nat_cache {
struct ipa_nat_ip4_table_cache ip4_tbl[IPA_NAT_MAX_IP4_TBLS];
int ipa_fd;
uint8_t table_cnt;
enum ipa_hw_type ver;
};
struct ipa_nat_indx_tbl_sw_rule {
uint16_t tbl_entry;
uint16_t next_index;
uint16_t prev_index;
};
typedef enum {
IPA_NAT_DEL_TYPE_ONLY_ONE,
IPA_NAT_DEL_TYPE_HEAD,
IPA_NAT_DEL_TYPE_MIDDLE,
IPA_NAT_DEL_TYPE_LAST,
} del_type;
/**
* ipa_nati_parse_ipv4_rule_hdl() - prase rule handle
* @tbl_hdl: [in] nat table rule
* @rule_hdl: [in] nat rule handle
* @expn_tbl: [out] expansion table or not
* @tbl_entry: [out] index into table
*
* Parse the rule handle to retrieve the nat table
* type and entry of nat table
*
* Returns: None
*/
void ipa_nati_parse_ipv4_rule_hdl(uint8_t tbl_hdl,
uint16_t rule_hdl,
uint8_t *expn_tbl,
uint16_t *tbl_entry);
/**
* ipa_nati_make_rule_hdl() - makes nat rule handle
* @tbl_hdl: [in] nat table handle
* @tbl_entry: [in] nat table entry
*
* Calculate the nat rule handle which from
* nat entry which will be returned to client of
* nat driver
*
* Returns: >0 nat rule handle
*/
uint16_t ipa_nati_make_rule_hdl(uint16_t tbl_hdl,
uint16_t tbl_entry);
uint32_t ipa_nati_get_index_entry_offset(
struct ipa_nat_ip4_table_cache*,
nat_table_type tbl_type,
uint16_t indx_tbl_entry);
uint32_t ipa_nati_get_entry_offset(
struct ipa_nat_ip4_table_cache*,
nat_table_type tbl_type,
uint16_t tbl_entry);
int ipa_nati_add_ipv4_tbl(uint32_t public_ip_addr,
uint16_t number_of_entries,
uint32_t *table_hanle);
int ipa_nati_alloc_table(uint16_t number_of_entries,
struct ipa_ioc_nat_alloc_mem *mem,
uint16_t*, uint16_t*);
int ipa_nati_update_cache(struct ipa_ioc_nat_alloc_mem *,
uint32_t public_ip_addr,
uint16_t tbl_entries,
uint16_t expn_tbl_entries);
int ipa_nati_del_ipv4_table(uint32_t tbl_hdl);
int ipa_nati_reset_ipv4_table(uint32_t tbl_hdl);
int ipa_nati_post_ipv4_init_cmd(uint8_t tbl_index);
int ipa_nati_query_timestamp(uint32_t tbl_hdl,
uint32_t rule_hdl,
uint32_t *time_stamp);
int ipa_nati_modify_pdn(struct ipa_ioc_nat_pdn_entry *entry);
int ipa_nati_add_ipv4_rule(uint32_t tbl_hdl,
const ipa_nat_ipv4_rule *clnt_rule,
uint32_t *rule_hdl);
int ipa_nati_generate_rule(uint32_t tbl_hdl,
const ipa_nat_ipv4_rule *clnt_rule,
struct ipa_nat_sw_rule *rule,
struct ipa_nat_indx_tbl_sw_rule *index_sw_rule,
uint16_t *tbl_entry,
uint16_t *indx_tbl_entry);
uint16_t ipa_nati_expn_tbl_free_entry(struct ipa_nat_rule *expn_tbl,
uint16_t size);
uint16_t ipa_nati_generate_tbl_rule(const ipa_nat_ipv4_rule *clnt_rule,
struct ipa_nat_sw_rule *sw_rule,
struct ipa_nat_ip4_table_cache *tbl_ptr);
uint16_t ipa_nati_generate_index_rule(const ipa_nat_ipv4_rule *clnt_rule,
struct ipa_nat_indx_tbl_sw_rule *sw_rule,
struct ipa_nat_ip4_table_cache *tbl_ptr);
uint16_t ipa_nati_index_expn_get_free_entry(struct ipa_nat_indx_tbl_rule *tbl,
uint16_t size);
void ipa_nati_copy_ipv4_rule_to_hw(
struct ipa_nat_ip4_table_cache *ipv4_cache,
struct ipa_nat_sw_rule *rule,
uint16_t entry, uint8_t tbl_index);
void ipa_nati_copy_ipv4_index_rule_to_hw(
struct ipa_nat_ip4_table_cache *ipv4_cache,
struct ipa_nat_indx_tbl_sw_rule *indx_sw_rule,
uint16_t entry, uint8_t tbl_index);
void ipa_nati_write_next_index(uint8_t tbl_indx,
nat_table_type tbl_type,
uint16_t value,
uint32_t offset);
int ipa_nati_post_ipv4_dma_cmd(uint8_t tbl_indx,
uint16_t entry);
int ipa_nati_del_ipv4_rule(uint32_t tbl_hdl,
uint32_t rule_hdl);
int ipa_nati_post_del_dma_cmd(uint8_t tbl_indx,
uint16_t tbl_entry,
uint8_t expn_tbl,
del_type rule_pos);
void ipa_nati_find_index_rule_pos(
struct ipa_nat_ip4_table_cache *cache_ptr,
uint16_t tbl_entry,
del_type *rule_pos);
void ipa_nati_del_dead_ipv4_head_nodes(uint8_t tbl_indx);
void ipa_nati_find_rule_pos(struct ipa_nat_ip4_table_cache *cache_ptr,
uint8_t expn_tbl,
uint16_t tbl_entry,
del_type *rule_pos);
void ipa_nati_del_dead_ipv4_head_nodes(uint8_t tbl_indx);
uint16_t Read16BitFieldValue(uint32_t param,
ipa_nat_rule_field_type fld_type);
/* ========================================================
Debug functions
========================================================*/
#ifdef NAT_DUMP
void ipa_nati_print_rule(struct ipa_nat_rule*, uint32_t);
void ipa_nat_dump_ipv4_table(uint32_t);
void ipa_nati_print_index_rule(struct ipa_nat_indx_tbl_rule*,
uint32_t, uint16_t);
int ipa_nati_query_nat_rules(uint32_t, nat_table_type);
#endif
#endif /* #ifndef IPA_NAT_DRVI_H */

View file

@ -1,73 +0,0 @@
/*
Copyright (c) 2013, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
ipa_nat_logi.h
@brief
This file implements the IPAM log functionality.
@Author
*/
#ifndef IPA_NAT_LOGI_H
#define IPA_NAT_LOGI_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdio.h>
#include <string.h>
#include <syslog.h>
#define PERROR(fmt) printf("%s:%d %s()", __FILE__, __LINE__, __FUNCTION__);\
perror(fmt);
#define IPAERR(fmt, ...) printf("ERR: %s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);
#ifdef DEBUG
#define IPADBG(fmt, ...) printf("%s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);
#define IPADUMP(fmt, ...) printf(fmt, ##__VA_ARGS__);
#else
#define IPADBG(fmt, ...)
#define IPADUMP(fmt, ...)
#endif
#ifdef __cplusplus
}
#endif
#endif /* IPA_NAT_LOGI_H */

View file

@ -1,38 +0,0 @@
AM_CFLAGS = -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs
if KERNELMODULES
AM_CFLAGS += -I./../inc $(KERNEL_DIR)/include
else
AM_CFLAGS += -I./../inc
endif
#AM_CFLAGS += -DDEBUG -g
common_CFLAGS = -DUSE_GLIB @GLIB_CFLAGS@
if !KERNELMODULES
common_LDFLAGS = -lrt @GLIB_LIBS@
endif
if KERNELMODULES
library_includedir = ../inc $(KERNEL_DIR)/include $(pkgincludedir)
else
library_includedir = $(pkgincludedir)
endif
c_sources = ipa_nat_drv.c \
ipa_nat_drvi.c \
ipa_nat_logi.c
library_include_HEADERS = ./../inc/ipa_nat_drvi.h \
./../inc/ipa_nat_drv.h \
./../inc/ipa_nat_logi.h
if KERNELMODULES
noinst_LIBRARIES = libipanat.a
libipanat_a_C = @C@
libipanat_a_SOURCES = $(c_sources)
else
lib_LTLIBRARIES = libipanat.la
libipanat_la_C = @C@
libipanat_la_SOURCES = $(c_sources)
libipanat_la_CFLAGS = $(AM_CFLAGS) $(common_CFLAGS)
libipanat_la_LDFLAGS = -shared $(common_LDFLAGS) -version-info 1:0:0
endif

View file

@ -1,215 +0,0 @@
/*
Copyright (c) 2013 - 2017, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ipa_nat_drv.h"
#include "ipa_nat_drvi.h"
/**
* ipa_nat_add_ipv4_tbl() - create ipv4 nat table
* @public_ip_addr: [in] public ipv4 address
* @number_of_entries: [in] number of nat entries
* @table_handle: [out] Handle of new ipv4 nat table
*
* To create new ipv4 nat table
*
* Returns: 0 On Success, negative on failure
*/
int ipa_nat_add_ipv4_tbl(uint32_t public_ip_addr,
uint16_t number_of_entries,
uint32_t *tbl_hdl)
{
int ret;
if (NULL == tbl_hdl || 0 == number_of_entries) {
IPAERR("Invalid parameters \n");
return -EINVAL;
}
ret = ipa_nati_add_ipv4_tbl(public_ip_addr,
number_of_entries,
tbl_hdl);
if (ret != 0) {
IPAERR("unable to add table \n");
return -EINVAL;
}
IPADBG("Returning table handle 0x%x\n", *tbl_hdl);
return ret;
} /* __ipa_nat_add_ipv4_tbl() */
/**
* ipa_nat_del_ipv4_tbl() - delete ipv4 table
* @table_handle: [in] Handle of ipv4 nat table
*
* To delete given ipv4 nat table
*
* Returns: 0 On Success, negative on failure
*/
int ipa_nat_del_ipv4_tbl(uint32_t tbl_hdl)
{
if (IPA_NAT_INVALID_NAT_ENTRY == tbl_hdl ||
tbl_hdl > IPA_NAT_MAX_IP4_TBLS) {
IPAERR("invalid table handle passed \n");
return -EINVAL;
}
IPADBG("Passed Table Handle: 0x%x\n", tbl_hdl);
return ipa_nati_del_ipv4_table(tbl_hdl);
}
/**
* ipa_nat_add_ipv4_rule() - to insert new ipv4 rule
* @table_handle: [in] handle of ipv4 nat table
* @rule: [in] Pointer to new rule
* @rule_handle: [out] Return the handle to rule
*
* To insert new ipv4 nat rule into ipv4 nat table
*
* Returns: 0 On Success, negative on failure
*/
int ipa_nat_add_ipv4_rule(uint32_t tbl_hdl,
const ipa_nat_ipv4_rule *clnt_rule,
uint32_t *rule_hdl)
{
int result = -EINVAL;
if (IPA_NAT_INVALID_NAT_ENTRY == tbl_hdl ||
tbl_hdl > IPA_NAT_MAX_IP4_TBLS || NULL == rule_hdl ||
NULL == clnt_rule) {
IPAERR("invalide table handle passed \n");
return result;
}
IPADBG("Passed Table handle: 0x%x\n", tbl_hdl);
if (ipa_nati_add_ipv4_rule(tbl_hdl, clnt_rule, rule_hdl) != 0) {
return result;
}
IPADBG("returning rule handle 0x%x\n", *rule_hdl);
return 0;
}
/**
* ipa_nat_del_ipv4_rule() - to delete ipv4 nat rule
* @table_handle: [in] handle of ipv4 nat table
* @rule_handle: [in] ipv4 nat rule handle
*
* To insert new ipv4 nat rule into ipv4 nat table
*
* Returns: 0 On Success, negative on failure
*/
int ipa_nat_del_ipv4_rule(uint32_t tbl_hdl,
uint32_t rule_hdl)
{
int result = -EINVAL;
if (IPA_NAT_INVALID_NAT_ENTRY == tbl_hdl ||
IPA_NAT_INVALID_NAT_ENTRY == rule_hdl) {
IPAERR("invalide parameters\n");
return result;
}
IPADBG("Passed Table: 0x%x and rule handle 0x%x\n", tbl_hdl, rule_hdl);
result = ipa_nati_del_ipv4_rule(tbl_hdl, rule_hdl);
if (result) {
IPAERR("unable to delete rule from hw \n");
return result;
}
return 0;
}
/**
* ipa_nat_query_timestamp() - to query timestamp
* @table_handle: [in] handle of ipv4 nat table
* @rule_handle: [in] ipv4 nat rule handle
* @time_stamp: [out] time stamp of rule
*
* To retrieve the timestamp that lastly the
* nat rule was accessed
*
* Returns: 0 On Success, negative on failure
*/
int ipa_nat_query_timestamp(uint32_t tbl_hdl,
uint32_t rule_hdl,
uint32_t *time_stamp)
{
if (0 == tbl_hdl || tbl_hdl > IPA_NAT_MAX_IP4_TBLS ||
NULL == time_stamp) {
IPAERR("invalid parameters passed \n");
return -EINVAL;
}
IPADBG("Passed Table: 0x%x and rule handle 0x%x\n", tbl_hdl, rule_hdl);
return ipa_nati_query_timestamp(tbl_hdl, rule_hdl, time_stamp);
}
/**
* ipa_nat_modify_pdn() - modify single PDN entry in the PDN config table
* @table_handle: [in] handle of ipv4 nat table
* @pdn_index : [in] the index of the entry to be modified
* @pdn_info : [in] values for the PDN entry to be changed
*
* Modify a PDN entry
*
* Returns: 0 On Success, negative on failure
*/
int ipa_nat_modify_pdn(uint32_t tbl_hdl,
uint8_t pdn_index,
ipa_nat_pdn_entry *pdn_info)
{
struct ipa_ioc_nat_pdn_entry pdn_data;
if (0 == tbl_hdl || tbl_hdl > IPA_NAT_MAX_IP4_TBLS) {
IPAERR("invalid parameters passed \n");
return -EINVAL;
}
if (!pdn_info) {
IPAERR("pdn_info is NULL \n");
return -EINVAL;
}
if (pdn_index > IPA_MAX_PDN_NUM) {
IPAERR("PDN index is out of range %d", pdn_index);
return -EINVAL;
}
pdn_data.pdn_index = pdn_index;
pdn_data.public_ip = pdn_info->public_ip;
pdn_data.src_metadata = pdn_info->src_metadata;
pdn_data.dst_metadata = pdn_info->dst_metadata;
return ipa_nati_modify_pdn(&pdn_data);
}

File diff suppressed because it is too large Load diff

View file

@ -1,49 +0,0 @@
/*
Copyright (c) 2013, 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
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
@file
IPACM_log.cpp
@brief
This file implements the IPAM log functionality.
@Author
Skylar Chang
*/
#include "ipa_nat_logi.h"
#include <stdlib.h>
#include <unistd.h>
void log_nat_message(char *msg)
{
return;
}

View file

@ -1,51 +0,0 @@
BOARD_PLATFORM_LIST := test
ifeq ($(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)/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../ipanat/inc
LOCAL_HEADER_LIBRARIES := generated_kernel_headers
LOCAL_MODULE := ipa_nat_test
LOCAL_SRC_FILES := ipa_nat_test000.c \
ipa_nat_test001.c \
ipa_nat_test002.c \
ipa_nat_test003.c \
ipa_nat_test004.c \
ipa_nat_test005.c \
ipa_nat_test006.c \
ipa_nat_test007.c \
ipa_nat_test008.c \
ipa_nat_test009.c \
ipa_nat_test010.c \
ipa_nat_test011.c \
ipa_nat_test012.c \
ipa_nat_test013.c \
ipa_nat_test014.c \
ipa_nat_test015.c \
ipa_nat_test016.c \
ipa_nat_test017.c \
ipa_nat_test018.c \
ipa_nat_test019.c \
ipa_nat_test020.c \
ipa_nat_test021.c \
ipa_nat_test022.c \
main.c
LOCAL_SHARED_LIBRARIES := libipanat
LOCAL_MODULE_TAGS := tests
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)/kernel-tests/ip_accelerator
include $(BUILD_EXECUTABLE)
endif # $(TARGET_ARCH)
endif
endif

View file

@ -1,42 +0,0 @@
AM_CPPFLAGS = -I./../inc \
-I$(top_srcdir)/ipanat/inc
AM_CPPFLAGS += -Wall -Wundef -Wno-trigraphs
AM_CPPFLAGS += -g
ipanattest_SOURCES = ipa_nat_test000.c \
ipa_nat_test001.c \
ipa_nat_test002.c \
ipa_nat_test003.c \
ipa_nat_test004.c \
ipa_nat_test005.c \
ipa_nat_test006.c \
ipa_nat_test007.c \
ipa_nat_test008.c \
ipa_nat_test009.c \
ipa_nat_test010.c \
ipa_nat_test011.c \
ipa_nat_test012.c \
ipa_nat_test013.c \
ipa_nat_test014.c \
ipa_nat_test015.c \
ipa_nat_test016.c \
ipa_nat_test017.c \
ipa_nat_test018.c \
ipa_nat_test019.c \
ipa_nat_test020.c \
ipa_nat_test021.c \
ipa_nat_test022.c \
main.c
bin_PROGRAMS = ipanattest
requiredlibs = ../src/libipanat.la
ipanattest_LDADD = $(requiredlibs)
LOCAL_MODULE := libipanat
LOCAL_PRELINK_MODULE := false
include $(BUILD_SHARED_LIBRARY)

View file

@ -1,18 +0,0 @@
1 To run this suite separately(each test case creates table and delete table) use below command
- To execute test suite nt times with n entries, command "ipanatest sep nt n"
Example: To execute test suite 1 time with 100 entries, command "ipanattest sep 100"
2. To run test suite not separately(creates table and delete table only once) use below command
- To execute test suite nt times with n entries, command "ipanatest reg nt n"
Example: To execute test suite 5 times with 32 entries, command "ipanattest reg 5 32"
3. To run inotify regression test use command, "ipanattest inotify nt"
Example: To execute inotify 5 times, command "ipanattest inotify 5"
4. if we just give command "ipanattest", runs test suite 1 time with 100 entries (non separate)

View file

@ -1,104 +0,0 @@
/*
* Copyright (c) 2014, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*===========================================================================
INCLUDE FILES FOR MODULE
===========================================================================*/
#include "stdint.h" /* uint32_t */
#include "stdio.h"
#include <netinet/in.h> /* for proto definitions */
#define u32 uint32_t
#define u16 uint16_t
#define u8 uint8_t
/*============ Preconditions to run NAT Test cases =========*/
#define IPA_NAT_TEST_PRE_COND_TE 20
#define CHECK_ERR1(x, tbl_hdl) \
if(ipa_nat_validate_ipv4_table(tbl_hdl)) { \
if(sep) {\
ipa_nat_del_ipv4_tbl(tbl_hdl); \
}\
return -1;\
}\
if(x) { \
IPAERR("%d\n", ret); \
if(sep) {\
ipa_nat_del_ipv4_tbl(tbl_hdl); \
}\
return -1; \
}
#define CHECK_ERR(x) if(x) { \
IPAERR("%d\n", ret); \
return -1;\
}
#if 0
#define CHECK_ERR(x) if(x) { \
IPAERR("%d\n", ret); \
if(sep) {\
ipa_nat_del_ipv4_tbl(tbl_hdl); \
}\
return -1;\
}
#endif
#define IPADBG(fmt, args...) printf(" %s:%d " fmt, __FUNCTION__, __LINE__, ## args)
#define IPAERR(fmt, args...) printf(" %s:%d " fmt, __FUNCTION__, __LINE__, ## args)
#define NAT_DUMP
int ipa_nat_validate_ipv4_table(u32);
int ipa_nat_test000(int, u32, u8);
int ipa_nat_test001(int, u32, u8);
int ipa_nat_test002(int, u32, u8);
int ipa_nat_test003(int, u32, u8);
int ipa_nat_test004(int, u32, u8);
int ipa_nat_test005(int, u32, u8);
int ipa_nat_test006(int, u32, u8);
int ipa_nat_test007(int, u32, u8);
int ipa_nat_test008(int, u32, u8);
int ipa_nat_test009(int, u32, u8);
int ipa_nat_test010(int, u32, u8);
int ipa_nat_test011(int, u32, u8);
int ipa_nat_test012(int, u32, u8);
int ipa_nat_test013(int, u32, u8);
int ipa_nat_test014(int, u32, u8);
int ipa_nat_test015(int, u32, u8);
int ipa_nat_test016(int, u32, u8);
int ipa_nat_test017(int, u32, u8);
int ipa_nat_test018(int, u32, u8);
int ipa_nat_test019(int, u32, u8);
int ipa_nat_test020(int, u32, u8);
int ipa_nat_test021(int, int);
int ipa_nat_test022(int, u32, u8);

View file

@ -1,69 +0,0 @@
/*
* Copyright (c) 2014, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*=========================================================================*/
/*!
@file
ipa_nat_test000.c
@brief
Verify the following scenario:
1. Add ipv4 table
2. Delete ipv4 table
*/
/*===========================================================================*/
#include "ipa_nat_test.h"
#include "ipa_nat_drv.h"
int ipa_nat_test000(int total_entries, u32 tbl_hdl, u8 sep)
{
int ret;
u32 pub_ip_add = 0x011617c0; /* "192.23.22.1" */
ret = ipa_nat_add_ipv4_tbl(pub_ip_add, total_entries, &tbl_hdl);
if (0 != ret)
{
IPAERR("unable to create ipv4 nat table and returning Error:%d\n", ret);
return -1;
}
IPADBG("create nat ipv4 table successfully() \n");
IPADBG("calling ipa_nat_del_ipv4_tbl() \n");
ret = ipa_nat_del_ipv4_tbl(tbl_hdl);
if (0 != ret)
{
IPAERR("Unable to delete ipv4 nat table %d\n", ret);
return -1;
}
IPADBG("deleted ipv4 nat table successfully. Test passed \n");
return 0;
}

View file

@ -1,77 +0,0 @@
/*
* Copyright (c) 2014, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*=========================================================================*/
/*!
@file
ipa_nat_test001.c
@brief
Verify the following scenario:
1. Add ipv4 table
2. Add ipv4 rule
3. Delete ipv4 table
*/
/*===========================================================================*/
#include "ipa_nat_test.h"
#include "ipa_nat_drv.h"
int ipa_nat_test001(int total_entries, u32 tbl_hdl, u8 sep)
{
int ret;
u32 rule_hdl;
ipa_nat_ipv4_rule ipv4_rule;
u32 pub_ip_add = 0x011617c0; /* "192.23.22.1" */
ipv4_rule.target_ip = 0xC1171601; /* 193.23.22.1 */
ipv4_rule.target_port = 1234;
ipv4_rule.private_ip = 0xC2171601; /* 194.23.22.1 */
ipv4_rule.private_port = 5678;
ipv4_rule.protocol = IPPROTO_TCP;
ipv4_rule.public_port = 9050;
IPADBG("%s()\n",__FUNCTION__);
if(sep)
{
ret = ipa_nat_add_ipv4_tbl(pub_ip_add, total_entries, &tbl_hdl);
CHECK_ERR(ret);
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_tbl(tbl_hdl);
CHECK_ERR(ret);
}
return 0;
}

View file

@ -1,85 +0,0 @@
/*
* Copyright (c) 2014, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*=========================================================================*/
/*!
@file
ipa_nat_test002.c
@brief
Verify the following scenario:
1. Add ipv4 table
2. Add ipv4 rule
3. delete ipv4 rule
4. Delete ipv4 table
*/
/*=========================================================================*/
#include "ipa_nat_test.h"
#include "ipa_nat_drv.h"
int ipa_nat_test002(int total_entries, u32 tbl_hdl, u8 sep)
{
int ret;
u32 rule_hdl;
ipa_nat_ipv4_rule ipv4_rule;
u32 pub_ip_add = 0x011617c0; /* "192.23.22.1" */
ipv4_rule.target_ip = 0xC1171601; /* 193.23.22.1 */
ipv4_rule.target_port = 1234;
ipv4_rule.private_ip = 0xC2171601; /* 194.23.22.1 */
ipv4_rule.private_port = 5678;
ipv4_rule.protocol = IPPROTO_TCP;
ipv4_rule.public_port = 9050;
IPADBG("%s()\n",__FUNCTION__);
if(sep)
{
ret = ipa_nat_add_ipv4_tbl(pub_ip_add, total_entries, &tbl_hdl);
CHECK_ERR(ret);
}
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl);
CHECK_ERR(ret);
if(sep)
{
ret = ipa_nat_del_ipv4_tbl(tbl_hdl);
CHECK_ERR(ret);
}
return 0;
}

View file

@ -1,82 +0,0 @@
/*
* Copyright (c) 2014, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*=========================================================================*/
/*!
@file
IPA_NAT_ipa_nat_test003.cpp
@brief
Verify the following scenario:
1. Add ipv4 table
2. Add ipv4 rule
3. Add ipv4 rule
4. Delete ipv4 table
*/
/*=========================================================================*/
#include "ipa_nat_test.h"
#include "ipa_nat_drv.h"
int ipa_nat_test003(int total_entries, u32 tbl_hdl, u8 sep)
{
int ret;
u32 rule_hdl, rule_hdl1;
ipa_nat_ipv4_rule ipv4_rule;
u32 pub_ip_add = 0x011617c0; /* "192.23.22.1" */
ipv4_rule.target_ip = 0xC1171601; /* 193.23.22.1 */
ipv4_rule.target_port = 1234;
ipv4_rule.private_ip = 0xC2171601; /* 194.23.22.1 */
ipv4_rule.private_port = 5678;
ipv4_rule.protocol = IPPROTO_TCP;
ipv4_rule.public_port = 9050;
IPADBG("%s():\n",__FUNCTION__);
if(sep)
{
ret = ipa_nat_add_ipv4_tbl(pub_ip_add, total_entries, &tbl_hdl);
CHECK_ERR(ret);
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl);
CHECK_ERR(ret);
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl1);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_tbl(tbl_hdl);
CHECK_ERR(ret);
}
return 0;
}

View file

@ -1,70 +0,0 @@
/*
* Copyright (c) 2014, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*=========================================================================*/
/*!
@file
ipa_nat_test004.cpp
@brief
Verify the following scenario:
1. Add ipv4 table
2. Query nat table handle
3. Delete ipv4 table
*/
/*===========================================================================*/
#include "ipa_nat_test.h"
#include "ipa_nat_drv.h"
int ipa_nat_test004(int total_entries, u32 tbl_hdl, u8 sep)
{
int ret = 0;
u32 tbl_hdl1 = 0;
u32 pub_ip_add = 0x011617c0; /* "192.23.22.1" */
IPADBG("%s():\n",__FUNCTION__);
if(sep)
{
ret = ipa_nat_add_ipv4_tbl(pub_ip_add, total_entries, &tbl_hdl);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_tbl(tbl_hdl);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_tbl(tbl_hdl1);
if(ret == 0)
{
IPAERR("able to delete table using invalid table handle\n");
return -1;
}
}
return 0;
}

View file

@ -1,83 +0,0 @@
/*
* Copyright (c) 2014, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*=========================================================================*/
/*!
@file
ipa_nat_test005.c
@brief
Verify the following scenario:
1. Add ipv4 table
2. Add ipv4 rule
3. Delete ipv4 rule
4. Add ipv4 rule
5. Delete ipv4 table
*/
/*=========================================================================*/
#include "ipa_nat_test.h"
#include "ipa_nat_drv.h"
int ipa_nat_test005(int total_entries, u32 tbl_hdl, u8 sep)
{
int ret = 0;
u32 rule_hdl, rule_hdl1;
ipa_nat_ipv4_rule ipv4_rule;
u32 pub_ip_add = 0x011617c0; /* "192.23.22.1" */
ipv4_rule.target_ip = 0xC1171601; /* 193.23.22.1 */
ipv4_rule.target_port = 1234;
ipv4_rule.private_ip = 0xC2171601; /* 194.23.22.1 */
ipv4_rule.private_port = 5678;
ipv4_rule.protocol = IPPROTO_TCP;
ipv4_rule.public_port = 9050;
if (sep)
{
ret = ipa_nat_add_ipv4_tbl(pub_ip_add, total_entries, &tbl_hdl);
CHECK_ERR(ret);
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl);
CHECK_ERR(ret);
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl1);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_tbl(tbl_hdl);
CHECK_ERR(ret);
}
return 0;
}

View file

@ -1,91 +0,0 @@
/*
* Copyright (c) 2014, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*=========================================================================*/
/*!
@file
ipa_nat_test006.c
@brief
Verify the following scenario:
1. Add ipv4 table
2. add same ipv rules
3. delete first followed by second
4. Delete ipv4 table
*/
/*=========================================================================*/
#include "ipa_nat_test.h"
#include "ipa_nat_drv.h"
int ipa_nat_test006(int total_entries, u32 tbl_hdl, u8 sep)
{
int ret=0;
u32 rule_hdl, rule_hdl1;
ipa_nat_ipv4_rule ipv4_rule;
u32 pub_ip_add = 0x011617c0; /* "192.23.22.1" */
ipv4_rule.target_ip = 0xC1171601; /* 193.23.22.1 */
ipv4_rule.target_port = 1234;
ipv4_rule.private_ip = 0xC2171601; /* 194.23.22.1 */
ipv4_rule.private_port = 5678;
ipv4_rule.protocol = IPPROTO_TCP;
ipv4_rule.public_port = 9050;
IPADBG("%s():\n",__FUNCTION__);
if(sep)
{
ret = ipa_nat_add_ipv4_tbl(pub_ip_add, total_entries, &tbl_hdl);
CHECK_ERR(ret);
}
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl);
CHECK_ERR(ret);
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl1);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl1);
CHECK_ERR(ret);
if(sep)
{
ret = ipa_nat_del_ipv4_tbl(tbl_hdl);
CHECK_ERR(ret);
}
return 0;
}

View file

@ -1,88 +0,0 @@
/*
* Copyright (c) 2014, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*=========================================================================*/
/*!
@file
ipa_nat_test007.cpp
@brief
Verify the following scenario:
1. Add ipv4 table
2. add same ipv rules
3. delete second followed by first
4. Delete ipv4 table
*/
/*=========================================================================*/
#include "ipa_nat_test.h"
#include "ipa_nat_drv.h"
int ipa_nat_test007(int total_entries, u32 tbl_hdl, u8 sep)
{
int ret;
u32 rule_hdl, rule_hdl1;
ipa_nat_ipv4_rule ipv4_rule;
u32 pub_ip_add = 0x011617c0; /* "192.23.22.1" */
ipv4_rule.target_ip = 0xC1171601; /* 193.23.22.1 */
ipv4_rule.target_port = 1234;
ipv4_rule.private_ip = 0xC2171601; /* 194.23.22.1 */
ipv4_rule.private_port = 5678;
ipv4_rule.protocol = IPPROTO_TCP;
ipv4_rule.public_port = 9050;
IPADBG("%s():\n",__FUNCTION__);
if(sep)
{
ret = ipa_nat_add_ipv4_tbl(pub_ip_add, total_entries, &tbl_hdl);
CHECK_ERR(ret);
}
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl);
CHECK_ERR(ret);
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl1);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl1);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl);
CHECK_ERR(ret);
if(sep)
{
ret = ipa_nat_del_ipv4_tbl(tbl_hdl);
CHECK_ERR(ret);
}
return 0;
}

View file

@ -1,94 +0,0 @@
/*
* Copyright (c) 2014, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*=========================================================================*/
/*!
@file
ipa_nat_test008.c
@brief
Verify the following scenario:
1. Add ipv4 table
2. add 2 distinct rules
3. delete first followed by second
4. Delete ipv4 table
*/
/*=========================================================================*/
#include "ipa_nat_test.h"
#include "ipa_nat_drv.h"
int ipa_nat_test008(int total_entries, u32 tbl_hdl, u8 sep)
{
int ret;
u32 rule_hdl, rule_hdl1;
ipa_nat_ipv4_rule ipv4_rule, ipv4_rule1;
u32 pub_ip_add = 0x011617c0; /* "192.23.22.1" */
ipv4_rule.target_ip = 0xC1171601; /* 193.23.22.1 */
ipv4_rule.target_port = 1234;
ipv4_rule.private_ip = 0xC2171601; /* 194.23.22.1 */
ipv4_rule.private_port = 5678;
ipv4_rule.protocol = IPPROTO_TCP;
ipv4_rule.public_port = 9050;
ipv4_rule1.target_ip = 0xC1171602; /* 193.23.22.2 */
ipv4_rule1.target_port = 1234;
ipv4_rule1.private_ip = 0xC2171602; /* 194.23.22.2 */
ipv4_rule1.private_port = 5678;
ipv4_rule1.protocol = IPPROTO_TCP;
ipv4_rule1.public_port = 9050;
IPADBG("%s():\n",__FUNCTION__);
if(sep)
{
ret = ipa_nat_add_ipv4_tbl(pub_ip_add, total_entries, &tbl_hdl);
CHECK_ERR(ret);
}
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl);
CHECK_ERR(ret);
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule1, &rule_hdl1);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl1);
CHECK_ERR(ret);
if(sep)
{
ret = ipa_nat_del_ipv4_tbl(tbl_hdl);
CHECK_ERR(ret);
}
return 0;
}

View file

@ -1,96 +0,0 @@
/*
* Copyright (c) 2014, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*=========================================================================*/
/*!
@file
ipa_nat_test009.cpp
@brief
Verify the following scenario:
1. Add ipv4 table
2. add 2 distinct rules
3. delete second followed by first
4. Delete ipv4 table
*/
/*=========================================================================*/
#include "ipa_nat_test.h"
#include "ipa_nat_drv.h"
int ipa_nat_test009(int total_entries, u32 tbl_hdl, u8 sep)
{
int ret;
u32 rule_hdl, rule_hdl1;
ipa_nat_ipv4_rule ipv4_rule, ipv4_rule1;
u32 pub_ip_add = 0x011617c0; /* "192.23.22.1" */
ipv4_rule.target_ip = 0xC1171601; /* 193.23.22.1 */
ipv4_rule.target_port = 1234;
ipv4_rule.private_ip = 0xC2171601; /* 194.23.22.1 */
ipv4_rule.private_port = 5678;
ipv4_rule.protocol = IPPROTO_TCP;
ipv4_rule.public_port = 9050;
ipv4_rule1.target_ip = 0xC1171602; /* 193.23.22.2 */
ipv4_rule1.target_port = 1234;
ipv4_rule1.private_ip = 0xC2171602; /* 194.23.22.2 */
ipv4_rule1.private_port = 5678;
ipv4_rule1.protocol = IPPROTO_TCP;
ipv4_rule1.public_port = 9050;
IPADBG("%s():\n",__FUNCTION__);
if(sep)
{
ret = ipa_nat_add_ipv4_tbl(pub_ip_add, total_entries, &tbl_hdl);
CHECK_ERR(ret);
}
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl);
CHECK_ERR(ret);
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule1, &rule_hdl1);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl1);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl);
CHECK_ERR(ret);
if(sep)
{
ret = ipa_nat_del_ipv4_tbl(tbl_hdl);
CHECK_ERR(ret);
}
return 0;
}

View file

@ -1,108 +0,0 @@
/*
* Copyright (c) 2014, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*=========================================================================*/
/*!
@file
ipa_nat_test010.c
@brief
Verify the following scenario:
1. Add ipv4 table
2. add 3 distinct ipv4 rules
3. delete first, second followed by last
4. Delete ipv4 table
*/
/*=========================================================================*/
#include "ipa_nat_test.h"
#include "ipa_nat_drv.h"
int ipa_nat_test010(int total_entries, u32 tbl_hdl, u8 sep)
{
int ret;
u32 rule_hdl, rule_hdl1, rule_hdl2;
ipa_nat_ipv4_rule ipv4_rule, ipv4_rule1, ipv4_rule2;
u32 pub_ip_add = 0x011617c0; /* "192.23.22.1" */
ipv4_rule.target_ip = 0xC1171601; /* 193.23.22.1 */
ipv4_rule.target_port = 1234;
ipv4_rule.private_ip = 0xC2171601; /* 194.23.22.1 */
ipv4_rule.private_port = 5678;
ipv4_rule.protocol = IPPROTO_TCP;
ipv4_rule.public_port = 9050;
ipv4_rule1.target_ip = 0xC1171601; /* 193.23.22.1 */
ipv4_rule1.target_port = 1235;
ipv4_rule1.private_ip = 0xC2171601; /* 194.23.22.1 */
ipv4_rule1.private_port = 5679;
ipv4_rule1.protocol = IPPROTO_TCP;
ipv4_rule1.public_port = 9051;
ipv4_rule2.target_ip = 0xC1171602; /* 193.23.22.2 */
ipv4_rule2.target_port = 1235;
ipv4_rule2.private_ip = 0xC2171602; /* 194.23.22.2 */
ipv4_rule2.private_port = 5679;
ipv4_rule2.protocol = IPPROTO_TCP;
ipv4_rule2.public_port = 9051;
IPADBG("%s():\n",__FUNCTION__);
if(sep)
{
ret = ipa_nat_add_ipv4_tbl(pub_ip_add, total_entries, &tbl_hdl);
CHECK_ERR(ret);
}
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl);
CHECK_ERR(ret);
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule1, &rule_hdl1);
CHECK_ERR(ret);
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule2, &rule_hdl2);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl1);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl2);
CHECK_ERR(ret);
if(sep)
{
ret = ipa_nat_del_ipv4_tbl(tbl_hdl);
CHECK_ERR(ret);
}
return 0;
}

View file

@ -1,108 +0,0 @@
/*
* Copyright (c) 2014, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*=========================================================================*/
/*!
@file
ipa_nat_test011.cpp
@brief
Verify the following scenario:
1. Add ipv4 table
2. add 3 distinct ipv4 rules
3. delete second, first followed by last
4. Delete ipv4 table
*/
/*=========================================================================*/
#include "ipa_nat_test.h"
#include "ipa_nat_drv.h"
int ipa_nat_test011(int total_entries, u32 tbl_hdl, u8 sep)
{
int ret;
u32 rule_hdl, rule_hdl1, rule_hdl2;
ipa_nat_ipv4_rule ipv4_rule, ipv4_rule1, ipv4_rule2;
u32 pub_ip_add = 0x011617c0; /* "192.23.22.1" */
ipv4_rule.target_ip = 0xC1171601; /* 193.23.22.1 */
ipv4_rule.target_port = 1234;
ipv4_rule.private_ip = 0xC2171601; /* 194.23.22.1 */
ipv4_rule.private_port = 5678;
ipv4_rule.protocol = IPPROTO_TCP;
ipv4_rule.public_port = 9050;
ipv4_rule1.target_ip = 0xF1181601;
ipv4_rule1.target_port = 1555;
ipv4_rule1.private_ip = 0xF2151601;
ipv4_rule1.private_port = 5999;
ipv4_rule1.protocol = IPPROTO_TCP;
ipv4_rule1.public_port = 9111;
ipv4_rule2.target_ip = 0xC1166602;
ipv4_rule2.target_port = 1555;
ipv4_rule2.private_ip = 0xC2155602;
ipv4_rule2.private_port = 5777;
ipv4_rule2.protocol = IPPROTO_TCP;
ipv4_rule2.public_port = 9000;
IPADBG("%s():\n",__FUNCTION__);
if(sep)
{
ret = ipa_nat_add_ipv4_tbl(pub_ip_add, total_entries, &tbl_hdl);
CHECK_ERR(ret);
}
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl);
CHECK_ERR(ret);
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule1, &rule_hdl1);
CHECK_ERR(ret);
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule2, &rule_hdl2);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl1);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl2);
CHECK_ERR(ret);
if(sep)
{
ret = ipa_nat_del_ipv4_tbl(tbl_hdl);
CHECK_ERR(ret);
}
return 0;
}

View file

@ -1,109 +0,0 @@
/*
* Copyright (c) 2014, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*=========================================================================*/
/*!
@file
ipa_nat_test012.cpp
@brief
Verify the following scenario:
1. Add ipv4 table
2. add 3 distinct ipv4 rules
3. Delete third, second, first
4. Delete ipv4 table
*/
/*=========================================================================*/
#include "ipa_nat_test.h"
#include "ipa_nat_drv.h"
int ipa_nat_test012(int totoal_entries, u32 tbl_hdl, u8 sep)
{
int ret;
u32 rule_hdl, rule_hdl1, rule_hdl2;
ipa_nat_ipv4_rule ipv4_rule, ipv4_rule1, ipv4_rule2;
u32 pub_ip_add = 0x011617c0; /* "192.23.22.1" */
ipv4_rule.target_ip = 0xC1171601; /* 193.23.22.1 */
ipv4_rule.target_port = 1234;
ipv4_rule.private_ip = 0xC2171601; /* 194.23.22.1 */
ipv4_rule.private_port = 5678;
ipv4_rule.protocol = IPPROTO_TCP;
ipv4_rule.public_port = 9050;
ipv4_rule1.target_ip = 0xD1171601;
ipv4_rule1.target_port = 3512;
ipv4_rule1.private_ip = 0xD2471601;
ipv4_rule1.private_port = 9997;
ipv4_rule1.protocol = IPPROTO_TCP;
ipv4_rule1.public_port = 8881;
ipv4_rule2.target_ip = 0xC1172452;
ipv4_rule2.target_port = 1895;
ipv4_rule2.private_ip = 0xC2172452;
ipv4_rule2.private_port = 6668;
ipv4_rule2.protocol = IPPROTO_TCP;
ipv4_rule2.public_port = 5551;
IPADBG("%s():\n",__FUNCTION__);
if(sep)
{
ret = ipa_nat_add_ipv4_tbl(pub_ip_add, totoal_entries, &tbl_hdl);
CHECK_ERR(ret);
}
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl);
CHECK_ERR(ret);
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule1, &rule_hdl1);
CHECK_ERR(ret);
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule2, &rule_hdl2);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl2);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl1);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl);
CHECK_ERR(ret);
if(sep)
{
ret = ipa_nat_del_ipv4_tbl(tbl_hdl);
CHECK_ERR(ret);
}
return 0;
}

View file

@ -1,108 +0,0 @@
/*
* Copyright (c) 2014, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*=========================================================================*/
/*!
@file
ipa_nat_test013.cpp
@brief
Verify the following scenario:
1. Add ipv4 table
2. add 3 distinct ipv4 rules
3. Delete third, first and second
4. Delete ipv4 table
*/
/*=========================================================================*/
#include "ipa_nat_test.h"
#include "ipa_nat_drv.h"
int ipa_nat_test013(int total_entries, u32 tbl_hdl, u8 sep)
{
int ret;
u32 rule_hdl, rule_hdl1, rule_hdl2;
ipa_nat_ipv4_rule ipv4_rule, ipv4_rule1, ipv4_rule2;
u32 pub_ip_add = 0x011617c0; /* "192.23.22.1" */
ipv4_rule.target_ip = 0xC1171601; /* 193.23.22.1 */
ipv4_rule.target_port = 1234;
ipv4_rule.private_ip = 0xC2171601; /* 194.23.22.1 */
ipv4_rule.private_port = 5678;
ipv4_rule.protocol = IPPROTO_TCP;
ipv4_rule.public_port = 9050;
ipv4_rule1.target_ip = 0xC1171609; /* 193.23.22.9 */
ipv4_rule1.target_port = 1235;
ipv4_rule1.private_ip = 0xC2171609; /* 194.23.22.9 */
ipv4_rule1.private_port = 6579;
ipv4_rule1.protocol = IPPROTO_TCP;
ipv4_rule1.public_port = 8951;
ipv4_rule2.target_ip = 0xC1171606; /* 193.23.22.6 */
ipv4_rule2.target_port = 1235;
ipv4_rule2.private_ip = 0xC2171606; /* 194.23.22.6 */
ipv4_rule2.private_port = 7956;
ipv4_rule2.protocol = IPPROTO_TCP;
ipv4_rule2.public_port = 5109;
IPADBG("%s():\n",__FUNCTION__);
if(sep)
{
ret = ipa_nat_add_ipv4_tbl(pub_ip_add, total_entries, &tbl_hdl);
CHECK_ERR(ret);
}
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl);
CHECK_ERR(ret);
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule1, &rule_hdl1);
CHECK_ERR(ret);
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule2, &rule_hdl2);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl2);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl1);
CHECK_ERR(ret);
if(sep)
{
ret = ipa_nat_del_ipv4_tbl(tbl_hdl);
CHECK_ERR(ret);
}
return 0;
}

View file

@ -1,95 +0,0 @@
/*
* Copyright (c) 2014, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*=========================================================================*/
/*!
@file
ipa_nat_test014.cpp
@brief
Verify the following scenario:
1. Add ipv4 table
2. add same 3 ipv rules
3. delete first, second and third
4. Delete ipv4 table
*/
/*=========================================================================*/
#include "ipa_nat_test.h"
#include "ipa_nat_drv.h"
int ipa_nat_test014(int total_entries, u32 tbl_hdl, u8 sep)
{
int ret;
u32 rule_hdl1, rule_hdl2, rule_hdl3;
ipa_nat_ipv4_rule ipv4_rule;
u32 pub_ip_add = 0x011617c0; /* "192.23.22.1" */
ipv4_rule.target_ip = 0xC1171601; /* 193.23.22.1 */
ipv4_rule.target_port = 1234;
ipv4_rule.private_ip = 0xC2171601; /* 194.23.22.1 */
ipv4_rule.private_port = 5678;
ipv4_rule.protocol = IPPROTO_TCP;
ipv4_rule.public_port = 9050;
IPADBG("%s()\n", __FUNCTION__);
if(sep)
{
ret = ipa_nat_add_ipv4_tbl(pub_ip_add, total_entries, &tbl_hdl);
CHECK_ERR(ret);
}
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl1);
CHECK_ERR(ret);
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl2);
CHECK_ERR(ret);
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl3);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl1);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl2);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl3);
CHECK_ERR(ret);
if(sep)
{
ret = ipa_nat_del_ipv4_tbl(tbl_hdl);
CHECK_ERR(ret);
}
return 0;
}

View file

@ -1,97 +0,0 @@
/*
* Copyright (c) 2014, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*=========================================================================*/
/*!
@file
ipa_nat_test015.cpp
@brief
Verify the following scenario:
1. Add ipv4 table
2. add same 3 ipv rules
3. delete first, third and second
4. Delete ipv4 table
*/
/*=========================================================================*/
#include "ipa_nat_test.h"
#include "ipa_nat_drv.h"
int ipa_nat_test015(int total_entries, u32 tbl_hdl, u8 sep)
{
int ret;
u32 rule_hdl1, rule_hdl2, rule_hdl3;
ipa_nat_ipv4_rule ipv4_rule;
u32 pub_ip_add = 0x011617c0; /* "192.23.22.1" */
ipv4_rule.target_ip = 0xC1171601; /* 193.23.22.1 */
ipv4_rule.target_port = 1234;
ipv4_rule.private_ip = 0xC2171601; /* 194.23.22.1 */
ipv4_rule.private_port = 5678;
ipv4_rule.protocol = IPPROTO_TCP;
ipv4_rule.public_port = 9050;
IPADBG("%s():\n",__FUNCTION__);
if(sep)
{
ret = ipa_nat_add_ipv4_tbl(pub_ip_add, total_entries, &tbl_hdl);
CHECK_ERR(ret);
}
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl1);
CHECK_ERR(ret);
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl2);
CHECK_ERR(ret);
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl3);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl1);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl3);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl2);
CHECK_ERR(ret);
if(sep)
{
ret = ipa_nat_del_ipv4_tbl(tbl_hdl);
CHECK_ERR(ret);
}
return 0;
}

View file

@ -1,96 +0,0 @@
/*
* Copyright (c) 2014, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*=========================================================================*/
/*!
@file
ipa_nat_test016.cpp
@brief
Verify the following scenario:
1. Add ipv4 table
2. add same 3 ipv rules
3. delete second, first and third
4. Delete ipv4 table
*/
/*=========================================================================*/
#include "ipa_nat_test.h"
#include "ipa_nat_drv.h"
int ipa_nat_test016(int total_entries, u32 tbl_hdl, u8 sep)
{
int ret;
u32 rule_hdl1, rule_hdl2, rule_hdl3;
ipa_nat_ipv4_rule ipv4_rule;
u32 pub_ip_add = 0x011617c0; /* "192.23.22.1" */
ipv4_rule.target_ip = 0xC1171601; /* 193.23.22.1 */
ipv4_rule.target_port = 1234;
ipv4_rule.private_ip = 0xC2171601; /* 194.23.22.1 */
ipv4_rule.private_port = 5678;
ipv4_rule.protocol = IPPROTO_TCP;
ipv4_rule.public_port = 9050;
IPADBG("%s():\n",__FUNCTION__);
if(sep)
{
ret = ipa_nat_add_ipv4_tbl(pub_ip_add, total_entries, &tbl_hdl);
CHECK_ERR(ret);
}
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl1);
CHECK_ERR(ret);
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl2);
CHECK_ERR(ret);
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl3);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl2);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl1);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl3);
CHECK_ERR(ret);
if(sep)
{
ret = ipa_nat_del_ipv4_tbl(tbl_hdl);
CHECK_ERR(ret);
}
return 0;
}

View file

@ -1,96 +0,0 @@
/*
* Copyright (c) 2014, 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
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*=========================================================================*/
/*!
@file
ipa_nat_test017.cpp
@brief
Verify the following scenario:
1. Add ipv4 table
2. add same 3 ipv rules
3. delete second, third and first
4. Delete ipv4 table
*/
/*=========================================================================*/
#include "ipa_nat_test.h"
#include "ipa_nat_drv.h"
int ipa_nat_test017(int total_entries, u32 tbl_hdl, u8 sep)
{
int ret;
u32 rule_hdl1, rule_hdl2, rule_hdl3;
ipa_nat_ipv4_rule ipv4_rule;
u32 pub_ip_add = 0x011617c0; /* "192.23.22.1" */
ipv4_rule.target_ip = 0xC1171601; /* 193.23.22.1 */
ipv4_rule.target_port = 1234;
ipv4_rule.private_ip = 0xC2171601; /* 194.23.22.1 */
ipv4_rule.private_port = 5678;
ipv4_rule.protocol = IPPROTO_TCP;
ipv4_rule.public_port = 9050;
IPADBG("%s():\n",__FUNCTION__);
if(sep)
{
ret = ipa_nat_add_ipv4_tbl(pub_ip_add, total_entries, &tbl_hdl);
CHECK_ERR(ret);
}
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl1);
CHECK_ERR(ret);
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl2);
CHECK_ERR(ret);
ret = ipa_nat_add_ipv4_rule(tbl_hdl, &ipv4_rule, &rule_hdl3);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl2);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl3);
CHECK_ERR(ret);
ret = ipa_nat_del_ipv4_rule(tbl_hdl, rule_hdl1);
CHECK_ERR(ret);
if(sep)
{
ret = ipa_nat_del_ipv4_tbl(tbl_hdl);
CHECK_ERR(ret);
}
return 0;
}

Some files were not shown because too many files have changed in this diff Show more