aboutsummaryrefslogtreecommitdiff
path: root/data-ipa-cfg-mgr/ipacm/inc/IPACM_Lan.h
diff options
context:
space:
mode:
authorBruno Martins <bgcngm@gmail.com>2018-01-08 12:51:07 +0000
committerDavide Garberi <dade.garberi@gmail.com>2018-01-20 09:30:21 +0100
commit1c67f47d4a205e12650dcb6255c00bafc0046082 (patch)
tree72bb48ca2152cb2295b0f8de39497490d8616f6f /data-ipa-cfg-mgr/ipacm/inc/IPACM_Lan.h
parent6b0c862328f58e523e2a6efa667a2f4b3a609bf3 (diff)
msm8996-common: Import IPACM back
* QC package: LA.UM.6.5.r1-05300-8x96.0 * Squashed with commits 08e2a5b9b, 055b183 and 8fcf57b Change-Id: I2f7a792dc0155986e065d1bf79e1f08370c3d79c Signed-off-by: Davide Garberi <dade.garberi@gmail.com>
Diffstat (limited to 'data-ipa-cfg-mgr/ipacm/inc/IPACM_Lan.h')
-rw-r--r--data-ipa-cfg-mgr/ipacm/inc/IPACM_Lan.h438
1 files changed, 438 insertions, 0 deletions
diff --git a/data-ipa-cfg-mgr/ipacm/inc/IPACM_Lan.h b/data-ipa-cfg-mgr/ipacm/inc/IPACM_Lan.h
new file mode 100644
index 0000000..f27cb82
--- /dev/null
+++ b/data-ipa-cfg-mgr/ipacm/inc/IPACM_Lan.h
@@ -0,0 +1,438 @@
+/*
+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_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"
+
+#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;
+ 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];
+
+ /* 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(bool is_sta_mode);
+
+ /* delete filter rule for wan_down event*/
+ virtual int handle_wan_down_v6(bool is_sta_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);
+
+ /* 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);
+
+#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 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);
+
+ /* 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];
+ 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];
+
+private:
+
+ /* 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++)
+ {
+ 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);
+};
+
+#endif /* IPACM_LAN_H */