Merge "[qca-ssdk]: Support eth with or without vlan"
diff --git a/app/nathelper/linux/host_helper.c b/app/nathelper/linux/host_helper.c
index 865f8f1..239777d 100755
--- a/app/nathelper/linux/host_helper.c
+++ b/app/nathelper/linux/host_helper.c
@@ -759,11 +759,17 @@
             devmac = (uint8_t *)nat_dev->dev_addr;
         }
         /* get vid */
+#if 0
 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
         vid = vlan_dev_vlan_id(nat_dev);
 #else
         vid = 0;
 #endif
+#endif
+		if(is_wan)
+			vid = nat_wan_vid;
+		else
+			vid = nat_lan_vid;
 #ifdef CONFIG_IPV6_HWACCEL
         ipv6 = 1;
         if (is_wan)
@@ -860,12 +866,12 @@
 				/*wan port*/
 				HNAT_PRINTK("wan port vid:%d\n", tmp_vid);
 				nat_wan_vid = tmp_vid;
-				snprintf(nat_wan_dev_list, IFNAMSIZ, "eth0.%d", tmp_vid);
+				snprintf(nat_wan_dev_list, IFNAMSIZ, "eth0.%d eth0", tmp_vid);
 			} else {
 				/*lan port*/
 				HNAT_PRINTK("lan port vid:%d\n", tmp_vid);
 				nat_lan_vid = tmp_vid;
-				snprintf(nat_lan_dev_list, IFNAMSIZ, "eth0.%d", tmp_vid);
+				snprintf(nat_lan_dev_list, IFNAMSIZ, "eth0.%d eth1", tmp_vid);
 			}
 		}
 	}
diff --git a/app/nathelper/linux/napt_helper.c b/app/nathelper/linux/napt_helper.c
index 436972f..e9ae59c 100755
--- a/app/nathelper/linux/napt_helper.c
+++ b/app/nathelper/linux/napt_helper.c
@@ -28,6 +28,7 @@
 #include <linux/if_arp.h>
 #include <linux/if_vlan.h>
 #include <linux/inetdevice.h>
+#include <linux/string.h>
 #include <net/netfilter/nf_conntrack_acct.h>
 #include <net/netfilter/nf_conntrack_helper.h>
 #include <net/netfilter/nf_conntrack.h>
@@ -238,9 +239,8 @@
 	dev = ip_dev_find(&init_net, dst_ip);
 	if(dev) {
 		if(dev->type == ARPHRD_ETHER) {
-			if (is_vlan_dev(dev)) {
+			if(strstr(dev->name, "eth0"))
 				return 1;
-			}
 		}
 	}
 
diff --git a/app/nathelper/linux/napt_helper.h b/app/nathelper/linux/napt_helper.h
index b5aa840..4cd21a9 100755
--- a/app/nathelper/linux/napt_helper.h
+++ b/app/nathelper/linux/napt_helper.h
@@ -87,12 +87,5 @@
 
 #endif
 
-//#define HNAT_DEBUG 1
-
-#ifdef HNAT_DEBUG
-#define HNAT_PRINTK(x...) aos_printk(x)
-#else
-#define HNAT_PRINTK(x...)
-#endif
 
 #endif
diff --git a/app/nathelper/linux/napt_procfs.c b/app/nathelper/linux/napt_procfs.c
index 9507e9e..b6b1729 100755
--- a/app/nathelper/linux/napt_procfs.c
+++ b/app/nathelper/linux/napt_procfs.c
@@ -65,7 +65,7 @@
 unsigned char nf_athrs17_hnat_ppp_peer_mac[ETH_ALEN] = {0};
 unsigned char nf_athrs17_hnat_wan_mac[ETH_ALEN] = {0};
 extern int nf_athrs17_hnat_sync_counter_en;
-
+extern char  hnat_log_en;
 /* for IPv6 over PPPoE (only for S17c)*/
 int nf_athrs17_hnat_ppp_id2 = 0;
 unsigned char nf_athrs17_hnat_ppp_peer_mac2[ETH_ALEN] = {0};
@@ -776,6 +776,38 @@
 	return count;
 }
 
+static ssize_t napt_log_en_get(struct device *dev,
+		  struct device_attribute *attr,
+		  char *buf)
+{
+	ssize_t count;
+	a_uint32_t num;
+
+	num = (a_uint32_t)hnat_log_en;
+
+	count = snprintf(buf, (ssize_t)PAGE_SIZE, "%u", num);
+	return count;
+}
+
+static ssize_t napt_log_en_set(struct device *dev,
+		  struct device_attribute *attr,
+		  const char *buf, size_t count)
+{
+	char num_buf[12];
+	a_uint32_t num;
+
+
+	if (count >= sizeof(num_buf)) return 0;
+	memcpy(num_buf, buf, count);
+	num_buf[count] = '\0';
+	sscanf(num_buf, "%u", &num);
+
+	hnat_log_en = num;
+
+	return count;
+}
+
+
 
 struct kobject *napt_sys = NULL;
 static const struct device_attribute napt_hnat_attr =
@@ -800,6 +832,8 @@
 	__ATTR(peer_mac2, S_IWUGO | S_IRUGO, napt_peer_mac2_get, napt_peer_mac2_set);
 static const struct device_attribute napt_sync_counter_en_attr =
 	__ATTR(sync_counter_en, S_IWUGO | S_IRUGO, napt_sync_counter_en_get, napt_sync_counter_en_set);
+static const struct device_attribute napt_log_en_attr =
+	__ATTR(log_en, S_IWUGO | S_IRUGO, napt_log_en_get, napt_log_en_set);
 
 
 
@@ -870,8 +904,15 @@
 		printk("Failed to register sync counter en SysFS file\n");
 		goto CLEANUP_11;
 	}
+	ret = sysfs_create_file(napt_sys, &napt_log_en_attr.attr);
+	if (ret) {
+		printk("Failed to register log en SysFS file\n");
+		goto CLEANUP_12;
+	}
 	return 0;
 
+CLEANUP_12:
+	sysfs_remove_file(napt_sys, &napt_log_en_attr.attr);
 CLEANUP_11:
 	sysfs_remove_file(napt_sys, &napt_sync_counter_en_attr.attr);
 CLEANUP_10:
@@ -902,6 +943,8 @@
 {
 	printk("napt procfs exit\n");
 
+	sysfs_remove_file(napt_sys, &napt_log_en_attr.attr);
+	sysfs_remove_file(napt_sys, &napt_sync_counter_en_attr.attr);
 	sysfs_remove_file(napt_sys, &napt_ppp_peer_mac2_attr.attr);
 	sysfs_remove_file(napt_sys, &napt_ppp_id2_attr.attr);
 	sysfs_remove_file(napt_sys, &napt_wan_mac_attr.attr);
diff --git a/app/nathelper/linux/nat_helper.c b/app/nathelper/linux/nat_helper.c
index 2a6cfb5..6da6c87 100755
--- a/app/nathelper/linux/nat_helper.c
+++ b/app/nathelper/linux/nat_helper.c
@@ -18,9 +18,27 @@
 #else
 #include <linux/autoconf.h>
 #endif
+#include <linux/string.h>
+
 
 #include "nat_helper.h"
 
+char hnat_log_en = 0;
+
+void hnat_log_msg(int level, char *string, ...)
+{
+
+	va_list   ptr;
+	char buffer[NAT_LOG_MAX_SIZE];
+
+	if(!hnat_log_en)
+		return;
+	memset(buffer, 0, sizeof(buffer));
+	va_start(ptr,string);
+	vsprintf(buffer , string, ptr);
+	va_end(ptr);
+	aos_printk("%s\n", buffer);
+}
 
 
 sw_error_t
diff --git a/app/nathelper/linux/nat_helper.h b/app/nathelper/linux/nat_helper.h
index 53d4a5b..3eb04a7 100755
--- a/app/nathelper/linux/nat_helper.h
+++ b/app/nathelper/linux/nat_helper.h
@@ -30,23 +30,17 @@
 void nat_helper_bg_task_init(void);
 void nat_helper_bg_task_exit(void);
 
-
-//#define HNAT_DEBUG 1
-
-#ifdef HNAT_DEBUG
-#define HNAT_PRINTK(x...) aos_printk(x)
-#else
-#define HNAT_PRINTK(x...)
-#endif
-
-//#define HNAT_ERR_DEBUG 1
-
-#ifdef HNAT_ERR_DEBUG
-#define HNAT_ERR_PRINTK(x...) aos_printk(x)
-#else
-#define HNAT_ERR_PRINTK(x...)
-#endif
-
+void hnat_log_msg(int level, char *string, ...);
+#define NAT_LOG_MAX_SIZE 1024
+enum {
+	HNAT_LOG_LEVEL_DEBUG = 0,
+	HNAT_LOG_LEVEL_INFO,
+	HNAT_LOG_LEVEL_ERR
+};
+#define HNAT_PRINTK(arg...)  \
+			hnat_log_msg(HNAT_LOG_LEVEL_DEBUG, arg)
+#define HNAT_ERR_PRINTK(arg...)  \
+			hnat_log_msg(HNAT_LOG_LEVEL_ERR, arg)
 
 
 #endif