potter: ipacm: fix build

Change-Id: I129c15664047306530225a5405970966c0edbf93
This commit is contained in:
Vachounet
2017-09-14 10:15:20 +02:00
parent 150294a722
commit f512e6b4b9
8 changed files with 93 additions and 54 deletions

View File

@@ -24,9 +24,8 @@ LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr
LOCAL_CFLAGS := -v LOCAL_CFLAGS := -DFEATURE_IPA_ANDROID
LOCAL_CFLAGS += -DFEATURE_IPA_ANDROID ifneq (,$(filter eng, $(TARGET_BUILD_VARIANT)))
ifneq (,$(filter userdebug eng, $(TARGET_BUILD_VARIANT)))
LOCAL_CFLAGS += -DDEBUG LOCAL_CFLAGS += -DDEBUG
endif endif

View File

@@ -482,7 +482,7 @@ int IPACM_Config::AddNatIfaces(char *dev_name)
if (ipa_nat_iface_entries < ipa_num_ipa_interfaces) if (ipa_nat_iface_entries < ipa_num_ipa_interfaces)
{ {
memcpy(pNatIfaces[ipa_nat_iface_entries - 1].iface_name, strlcpy(pNatIfaces[ipa_nat_iface_entries - 1].iface_name,
dev_name, IPA_IFACE_NAME_LEN); dev_name, IPA_IFACE_NAME_LEN);
IPACMDBG_H("Add Nat IfaceName: %s ,update nat-ifaces number: %d\n", IPACMDBG_H("Add Nat IfaceName: %s ,update nat-ifaces number: %d\n",

View File

@@ -169,10 +169,18 @@ int IPACM_ConntrackClient::IPA_Conntrack_Filters_Ignore_Bridge_Addrs
uint32_t ipv4_addr; uint32_t ipv4_addr;
struct ifreq ifr; struct ifreq ifr;
if(strlen(IPACM_Iface::ipacmcfg->ipa_virtual_iface_name) >= sizeof(ifr.ifr_name))
{
IPACMERR("interface name overflows: len %d\n",
strlen(IPACM_Iface::ipacmcfg->ipa_virtual_iface_name));
close(fd);
return -1;
}
/* retrieve bridge interface ipv4 address */ /* retrieve bridge interface ipv4 address */
memset(&ifr, 0, sizeof(struct ifreq)); memset(&ifr, 0, sizeof(struct ifreq));
ifr.ifr_addr.sa_family = AF_INET; ifr.ifr_addr.sa_family = AF_INET;
(void)strncpy(ifr.ifr_name, IPACM_Iface::ipacmcfg->ipa_virtual_iface_name, sizeof(ifr.ifr_name)); (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); IPACMDBG("bridge interface name (%s)\n", ifr.ifr_name);
ret = ioctl(fd, SIOCGIFADDR, &ifr); ret = ioctl(fd, SIOCGIFADDR, &ifr);

View File

@@ -924,30 +924,37 @@ int IPACM_Iface::ipa_get_if_index
int * if_index int * if_index
) )
{ {
int fd; int fd;
struct ifreq ifr; struct ifreq ifr;
if((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) if((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
{ {
IPACMERR("get interface index socket create failed \n"); IPACMERR("get interface index socket create failed \n");
return IPACM_FAILURE; return IPACM_FAILURE;
} }
memset(&ifr, 0, sizeof(struct ifreq)); if(strlen(if_name) >= sizeof(ifr.ifr_name))
(void)strncpy(ifr.ifr_name, if_name, sizeof(ifr.ifr_name)); {
IPACMDBG_H("interface name (%s)\n", if_name); IPACMERR("interface name overflows: len %d\n", strlen(if_name));
close(fd);
return IPACM_FAILURE;
}
if (ioctl(fd,SIOCGIFINDEX , &ifr) < 0) memset(&ifr, 0, sizeof(struct ifreq));
{ (void)strlcpy(ifr.ifr_name, if_name, sizeof(ifr.ifr_name));
IPACMERR("call_ioctl_on_dev: ioctl failed, interface name (%s):\n", ifr.ifr_name); IPACMDBG_H("interface name (%s)\n", if_name);
close(fd);
return IPACM_FAILURE;
}
*if_index = ifr.ifr_ifindex; if(ioctl(fd,SIOCGIFINDEX , &ifr) < 0)
IPACMDBG_H("Interface index %d\n", *if_index); {
close(fd); IPACMERR("call_ioctl_on_dev: ioctl failed, interface name (%s):\n", ifr.ifr_name);
return IPACM_SUCCESS; close(fd);
return IPACM_FAILURE;
}
*if_index = ifr.ifr_ifindex;
IPACMDBG_H("Interface index %d\n", *if_index);
close(fd);
return IPACM_SUCCESS;
} }
void IPACM_Iface::config_ip_type(ipa_ip_type iptype) void IPACM_Iface::config_ip_type(ipa_ip_type iptype)

View File

@@ -689,12 +689,12 @@ static int ipa_nl_decode_nlmsg
/* Add IPACM support for ECM plug-in/plug_out */ /* Add IPACM support for ECM plug-in/plug_out */
/*-------------------------------------------------------------------------- /*--------------------------------------------------------------------------
Check if the interface is running.If its a RTM_NEWLINK and the interface Check if the interface is running.If its a RTM_NEWLINK and the interface
is running then it means that its a link up event is running then it means that its a link up event
---------------------------------------------------------------------------*/ ---------------------------------------------------------------------------*/
if((msg_ptr->nl_link_info.metainfo.ifi_flags & IFF_RUNNING) && if((msg_ptr->nl_link_info.metainfo.ifi_flags & IFF_RUNNING) &&
(msg_ptr->nl_link_info.metainfo.ifi_flags & IFF_LOWER_UP)) (msg_ptr->nl_link_info.metainfo.ifi_flags & IFF_LOWER_UP))
{ {
data_fid = (ipacm_event_data_fid *)malloc(sizeof(ipacm_event_data_fid)); data_fid = (ipacm_event_data_fid *)malloc(sizeof(ipacm_event_data_fid));
if(data_fid == NULL) if(data_fid == NULL)
@@ -712,17 +712,17 @@ static int ipa_nl_decode_nlmsg
} }
IPACMDBG("Got a usb link_up event (Interface %s, %d) \n", dev_name, msg_ptr->nl_link_info.metainfo.ifi_index); IPACMDBG("Got a usb link_up event (Interface %s, %d) \n", dev_name, msg_ptr->nl_link_info.metainfo.ifi_index);
/*-------------------------------------------------------------------------- /*--------------------------------------------------------------------------
Post LAN iface (ECM) link up event Post LAN iface (ECM) link up event
---------------------------------------------------------------------------*/ ---------------------------------------------------------------------------*/
evt_data.event = IPA_USB_LINK_UP_EVENT; evt_data.event = IPA_USB_LINK_UP_EVENT;
evt_data.evt_data = data_fid; evt_data.evt_data = data_fid;
IPACM_EvtDispatcher::PostEvt(&evt_data);
IPACMDBG_H("Posting usb IPA_LINK_UP_EVENT with if index: %d\n", IPACMDBG_H("Posting usb IPA_LINK_UP_EVENT with if index: %d\n",
data_fid->if_index); data_fid->if_index);
} IPACM_EvtDispatcher::PostEvt(&evt_data);
else if(!(msg_ptr->nl_link_info.metainfo.ifi_flags & IFF_LOWER_UP)) }
{ else if (!(msg_ptr->nl_link_info.metainfo.ifi_flags & IFF_LOWER_UP))
{
data_fid = (ipacm_event_data_fid *)malloc(sizeof(ipacm_event_data_fid)); data_fid = (ipacm_event_data_fid *)malloc(sizeof(ipacm_event_data_fid));
if(data_fid == NULL) if(data_fid == NULL)
{ {
@@ -744,10 +744,10 @@ static int ipa_nl_decode_nlmsg
---------------------------------------------------------------------------*/ ---------------------------------------------------------------------------*/
evt_data.event = IPA_LINK_DOWN_EVENT; evt_data.event = IPA_LINK_DOWN_EVENT;
evt_data.evt_data = data_fid; evt_data.evt_data = data_fid;
IPACM_EvtDispatcher::PostEvt(&evt_data);
IPACMDBG_H("Posting usb IPA_LINK_DOWN_EVENT with if index: %d\n", IPACMDBG_H("Posting usb IPA_LINK_DOWN_EVENT with if index: %d\n",
data_fid->if_index); data_fid->if_index);
} IPACM_EvtDispatcher::PostEvt(&evt_data);
}
} }
break; break;

View File

@@ -267,8 +267,8 @@ static int ipacm_cfg_xml_parse_tree
{ {
str_size = strlen(content); str_size = strlen(content);
memset(content_buf, 0, sizeof(content_buf)); memset(content_buf, 0, sizeof(content_buf));
memcpy(content_buf, (void *)content, str_size); strlcpy(content_buf, content, MAX_XML_STR_LEN);
strlcpy(config->iface_config.iface_entries[config->iface_config.num_iface_entries - 1].iface_name, content_buf, str_size+1); strlcpy(config->iface_config.iface_entries[config->iface_config.num_iface_entries - 1].iface_name, content_buf, IPA_IFACE_NAME_LEN);
IPACMDBG_H("Name %s\n", config->iface_config.iface_entries[config->iface_config.num_iface_entries - 1].iface_name); IPACMDBG_H("Name %s\n", config->iface_config.iface_entries[config->iface_config.num_iface_entries - 1].iface_name);
} }
} }
@@ -644,12 +644,9 @@ static int IPACM_firewall_xml_parse_tree
memset(content_buf, 0, sizeof(content_buf)); memset(content_buf, 0, sizeof(content_buf));
memcpy(content_buf, (void *)content, str_size); memcpy(content_buf, (void *)content, str_size);
content_buf[MAX_XML_STR_LEN-1] = '\0'; content_buf[MAX_XML_STR_LEN-1] = '\0';
if (content_buf > 0) config->extd_firewall_entries[config->num_extd_firewall_entries - 1].attrib.u.v4.dst_addr_mask
{ = ntohl(inet_addr(content_buf));
config->extd_firewall_entries[config->num_extd_firewall_entries - 1].attrib.u.v4.dst_addr_mask IPACMDBG_H("IPv4 destination subnet mask is: %s \n", content_buf);
= ntohl(inet_addr(content_buf));
IPACMDBG_H("IPv4 destination subnet mask is: %s \n", content_buf);
}
} }
} }
else if (0 == IPACM_util_icmp_string((char*)xml_node->name, IPV4TypeOfService_TAG)) else if (0 == IPACM_util_icmp_string((char*)xml_node->name, IPV4TypeOfService_TAG))

View File

@@ -1527,13 +1527,20 @@ int ipa_nati_del_ipv4_rule(uint32_t tbl_hdl,
struct ipa_nat_ip4_table_cache *tbl_ptr; struct ipa_nat_ip4_table_cache *tbl_ptr;
del_type rule_pos; del_type rule_pos;
uint8_t tbl_indx = (uint8_t)(tbl_hdl - 1); uint8_t tbl_indx = (uint8_t)(tbl_hdl - 1);
int ret;
/* Parse the rule handle */ /* Parse the rule handle */
ipa_nati_parse_ipv4_rule_hdl(tbl_indx, (uint16_t)rule_hdl, ipa_nati_parse_ipv4_rule_hdl(tbl_indx, (uint16_t)rule_hdl,
&expn_tbl, &tbl_entry); &expn_tbl, &tbl_entry);
if (IPA_NAT_INVALID_NAT_ENTRY == tbl_entry) { if (IPA_NAT_INVALID_NAT_ENTRY == tbl_entry) {
IPAERR("Invalid Rule Entry\n"); IPAERR("Invalid Rule Entry\n");
return -EINVAL; ret = -EINVAL;
goto fail;
}
if (pthread_mutex_lock(&nat_mutex) != 0) {
ret = -1;
goto mutex_lock_error;
} }
IPADBG("Delete below rule\n"); IPADBG("Delete below rule\n");
@@ -1542,7 +1549,10 @@ int ipa_nati_del_ipv4_rule(uint32_t tbl_hdl,
tbl_ptr = &ipv4_nat_cache.ip4_tbl[tbl_indx]; tbl_ptr = &ipv4_nat_cache.ip4_tbl[tbl_indx];
if (!tbl_ptr->valid) { if (!tbl_ptr->valid) {
IPAERR("invalid table handle\n"); IPAERR("invalid table handle\n");
return -EINVAL; ret = -EINVAL;
if (pthread_mutex_unlock(&nat_mutex) != 0)
goto mutex_unlock_error;
goto fail;
} }
ipa_nati_find_rule_pos(tbl_ptr, expn_tbl, ipa_nati_find_rule_pos(tbl_ptr, expn_tbl,
@@ -1551,7 +1561,10 @@ int ipa_nati_del_ipv4_rule(uint32_t tbl_hdl,
if (ipa_nati_post_del_dma_cmd(tbl_indx, tbl_entry, if (ipa_nati_post_del_dma_cmd(tbl_indx, tbl_entry,
expn_tbl, rule_pos)) { expn_tbl, rule_pos)) {
return -EINVAL; ret = -EINVAL;
if (pthread_mutex_unlock(&nat_mutex) != 0)
goto mutex_unlock_error;
goto fail;
} }
ipa_nati_del_dead_ipv4_head_nodes(tbl_indx); ipa_nati_del_dead_ipv4_head_nodes(tbl_indx);
@@ -1565,7 +1578,22 @@ int ipa_nati_del_ipv4_rule(uint32_t tbl_hdl,
ipa_nat_dump_ipv4_table(tbl_hdl); ipa_nat_dump_ipv4_table(tbl_hdl);
#endif #endif
if (pthread_mutex_unlock(&nat_mutex) != 0) {
ret = -1;
goto mutex_unlock_error;
}
return 0; return 0;
mutex_lock_error:
IPAERR("unable to lock the nat mutex\n");
return ret;
mutex_unlock_error:
IPAERR("unable to unlock the nat mutex\n");
fail:
return ret;
} }
void ReorderCmds(struct ipa_ioc_nat_dma_cmd *cmd, int size) void ReorderCmds(struct ipa_ioc_nat_dma_cmd *cmd, int size)

View File

@@ -43,11 +43,11 @@ LOCAL_SRC_FILES := ipa_nat_test000.c \
LOCAL_SHARED_LIBRARIES := libipanat LOCAL_SHARED_LIBRARIES := libipanat
LOCAL_MODULE_TAGS := debug LOCAL_MODULE_TAGS := tests
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)/kernel-tests/ip_accelerator LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)/kernel-tests/ip_accelerator
include $(BUILD_EXECUTABLE) include $(BUILD_EXECUTABLE)
endif # $(TARGET_ARCH) endif # $(TARGET_ARCH)
endif endif
endif endif