1 /* 2 * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above 10 * copyright notice, this list of conditions and the following 11 * disclaimer in the documentation and/or other materials provided 12 * with the distribution. 13 * * Neither the name of The Linux Foundation nor the names of its 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 #ifndef _IPACM_OFFLOAD_MANAGER_H_ 30 #define _IPACM_OFFLOAD_MANAGER_H_ 31 32 #include <list> 33 #include <stdint.h> 34 #include <IOffloadManager.h> 35 #include "IPACM_Defs.h" 36 37 using RET = ::IOffloadManager::RET; 38 using Prefix = ::IOffloadManager::Prefix; 39 using IP_FAM = ::IOffloadManager::IP_FAM; 40 using L4Protocol = ::IOffloadManager::ConntrackTimeoutUpdater::L4Protocol; 41 using natTimeoutUpdate_t = ::IOffloadManager::ConntrackTimeoutUpdater::natTimeoutUpdate_t; 42 //using ipAddrPortPair_t = ::IOffloadManager::ConntrackTimeoutUpdater::ipAddrPortPair_t; 43 //using UDP = ::IOffloadManager::ConntrackTimeoutUpdater::UDP; 44 //using TCP = ::IOffloadManager::ConntrackTimeoutUpdater::TCP; 45 46 #define MAX_EVENT_CACHE 10 47 48 typedef struct _framework_event_cache 49 { 50 /* IPACM interface name */ 51 ipa_cm_event_id event; 52 char dev_name[IF_NAME_LEN]; 53 Prefix prefix_cache; 54 Prefix prefix_cache_v6; //for setupstream use 55 bool valid; 56 }framework_event_cache; 57 58 class IPACM_OffloadManager : public IOffloadManager 59 { 60 61 public: 62 63 IPACM_OffloadManager(); 64 static IPACM_OffloadManager* GetInstance(); 65 66 virtual RET registerEventListener(IpaEventListener* /* listener */); 67 virtual RET unregisterEventListener(IpaEventListener* /* listener */); 68 virtual RET registerCtTimeoutUpdater(ConntrackTimeoutUpdater* /* cb */); 69 virtual RET unregisterCtTimeoutUpdater(ConntrackTimeoutUpdater* /* cb */); 70 71 virtual RET provideFd(int /* fd */, unsigned int /* group */); 72 virtual RET clearAllFds(); 73 virtual bool isStaApSupported(); 74 75 /* ---------------------------- ROUTE ------------------------------- */ 76 virtual RET setLocalPrefixes(std::vector<Prefix> &/* prefixes */); 77 virtual RET addDownstream(const char * /* downstream */, 78 const Prefix & /* prefix */); 79 virtual RET removeDownstream(const char * /* downstream */, 80 const Prefix &/* prefix */); 81 virtual RET setUpstream(const char* /* iface */, const Prefix& /* v4Gw */, const Prefix& /* v6Gw */); 82 virtual RET stopAllOffload(); 83 84 /* ------------------------- STATS/POLICY --------------------------- */ 85 virtual RET setQuota(const char * /* upstream */, uint64_t /* limit */); 86 virtual RET getStats(const char * /* upstream */, bool /* reset */, 87 OffloadStatistics& /* ret */); 88 89 static IPACM_OffloadManager *pInstance; 90 91 IpaEventListener *elrInstance; 92 93 ConntrackTimeoutUpdater *touInstance; 94 95 bool search_framwork_cache(char * interface_name); 96 97 bool push_framework_event(const char * if_name, _ipacm_offload_prefix prefix); 98 99 static int num_offload_v4_tethered_iface; 100 101 private: 102 103 std::list<std::string> valid_ifaces; 104 105 bool upstream_v4_up; 106 107 bool upstream_v6_up; 108 109 int default_gw_index; 110 111 int post_route_evt(enum ipa_ip_type iptype, int index, ipa_cm_event_id event, const Prefix &gw_addr); 112 113 int ipa_get_if_index(const char *if_name, int *if_index); 114 115 int resetTetherStats(const char *upstream_name); 116 117 #ifdef FEATURE_IPACM_RESTART 118 int push_iface_up(const char *if_name, bool upstream); 119 #endif 120 121 static const char *DEVICE_NAME; 122 123 /* cache the add_downstream events if netdev is not ready */ 124 framework_event_cache event_cache[MAX_EVENT_CACHE]; 125 126 /* latest update cache entry */ 127 int latest_cache_index; 128 129 }; /* IPACM_OffloadManager */ 130 131 #endif /* _IPACM_OFFLOAD_MANAGER_H_ */ 132