ASR_BASE

Change-Id: Icf3719cc0afe3eeb3edc7fa80a2eb5199ca9dda1
diff --git a/marvell/services/piped/piped_dns.c b/marvell/services/piped/piped_dns.c
new file mode 100644
index 0000000..ae4f473
--- /dev/null
+++ b/marvell/services/piped/piped_dns.c
@@ -0,0 +1,173 @@
+
+#include "piped.h"
+#include "piped_uci.h"
+#include "piped_util.h"
+#include "piped_nw.h"
+#include "piped_dhcp.h"
+#include "piped_dns.h"
+
+static int pd_add_del_dns6(struct pd_context *pdc, struct pd_iface *pdi,
+			    bool add)
+{
+	struct uci_context *c = pdc->c;
+
+	if (!pdi_test(pdi, PDI_DNS6P) && !pdi_test(pdi, PDI_DNS6S))
+		return 0;
+
+	if (add) {
+		if (pdi_test(pdi, PDI_DNS6P) && pd_uci_add_list(c,
+								UCI_PKG_DHCP,
+								UCI_SEC_LAN,
+								UCI_OPT_DNS,
+								pdi->dns6p)) {
+			PD_ERR(pd_add_del_dns6, "add dns6p failed\n");
+			return 1;
+		}
+		if (pdi_test(pdi, PDI_DNS6S) && pd_uci_add_list(c, UCI_PKG_DHCP,
+								UCI_SEC_LAN,
+								UCI_OPT_DNS,
+								pdi->dns6s)) {
+			PD_ERR(pd_add_del_dns61, "add dns6s failed\n");
+			return 1;
+		}
+	} else {
+		if (pdi_test(pdi, PDI_DNS6P) && pd_uci_del_from_list(c,
+								UCI_PKG_DHCP,
+								UCI_SEC_LAN,
+								UCI_OPT_DNS,
+								pdi->dns6p)) {
+			PD_ERR(pd_add_del_dns62, "del dns6p failed\n");
+			return 1;
+		}
+		if (pdi_test(pdi, PDI_DNS6S) && pd_uci_del_from_list(c,
+								UCI_PKG_DHCP,
+								UCI_SEC_LAN,
+								UCI_OPT_DNS,
+								pdi->dns6s)) {
+			PD_ERR(pd_add_del_dns63, "del dns6p failed\n");
+			return 1;
+		}
+	}
+
+	pd_set(&pdc->status, PDC_ODHCPD_CHANGED);
+
+	return 0;
+}
+
+static int pd_add_del_dns4(struct pd_context *pdc, struct pd_iface *pdi,
+			    bool add)
+{
+	struct uci_context *c = pdc->c;
+	char options[MAX_DHCP_OPT_STR_LEN];
+
+	if (!pdi_test(pdi, PDI_DNS4P) && !pdi_test(pdi, PDI_DNS4S))
+		return 0;
+
+	strcpy(options, UCI_DHCP_OPTNUM_DNS);
+
+	if (pdi_test(pdi, PDI_DNS4P)) {
+		strcat(options, ",");
+		strcat(options, pdi->dns4p);
+	}
+	if (pdi_test(pdi, PDI_DNS4S)) {
+		strcat(options, ",");
+		strcat(options, pdi->dns4s);
+	}
+
+	if (add && pd_uci_add_list(c, UCI_PKG_DHCP, UCI_SEC_LAN,
+				   UCI_OPT_DHCP_OPT, options)) {
+		PD_ERR(pd_add_del_dns4, "dhcp add dns4 failed\n");
+		return 1;
+	} else if (!add && pd_uci_del_from_list(c, UCI_PKG_DHCP, UCI_SEC_LAN,
+						UCI_OPT_DHCP_OPT, options)) {
+		PD_ERR(pd_add_del_dns41, "dhcp del dns4 failed\n");
+		return 1;
+	}
+
+	pd_set(&pdc->status, PDC_DNSMASQ_CHANGED);
+
+	return 0;
+}
+
+int pd_dns4_add(struct pd_context *pdc, struct pd_iface *pdi)
+{
+	if (pd_add_del_dns4(pdc, pdi, true)) {
+		PD_ERR(pd_dns4_add, "pd_add_del_dns4 failed for %s\n", pdi->sec);
+		return 1;
+	}
+
+	return 0;
+}
+
+int pd_dns4_del(struct pd_context *pdc, struct pd_iface *pdi)
+{
+	if (pd_add_del_dns4(pdc, pdi, false)) {
+		PD_ERR(pd_dns4_del, "pd_add_del_dns4 failed for %s\n", pdi->sec);
+		return 1;
+	}
+
+	return 0;
+}
+
+int pd_dns4_change(struct pd_context *pdc, struct pd_iface *oldi,
+		  struct pd_iface *newi)
+{
+	if (pd_dns4_del(pdc, oldi)) {
+		PD_ERR(pd_dns4_change, "pd_dns4_del failed\n");
+		return 1;
+	}
+	if (pd_dns4_add(pdc, newi)) {
+		PD_ERR(pd_dns4_change1, "pd_dns4_add failed\n");
+		return 1;
+	}
+
+	return 0;
+}
+
+
+int pd_dns6_add(struct pd_context *pdc, struct pd_iface *pdi)
+{
+	if (pd_add_del_dns6(pdc, pdi, true)) {
+		PD_ERR(pd_dns6_add, "pd_add_del_dns6 failed for %s\n", pdi->sec);
+		return 1;
+	}
+
+	return 0;
+}
+int pd_dns6_change(struct pd_context *pdc, struct pd_iface *oldi,
+		  struct pd_iface *newi)
+{
+	if (pd_dns6_del(pdc, oldi)) {
+		PD_ERR(pd_dns6_change, "pd_dns6_del failed\n");
+		return 1;
+	}
+	if (pd_dns6_add(pdc, newi)) {
+		PD_ERR(pd_dns6_change1, "pd_dns6_add failed\n");
+		return 1;
+	}
+
+	return 0;
+}
+
+int pd_dns6_del(struct pd_context *pdc, struct pd_iface *pdi)
+{
+
+	if (pd_add_del_dns6(pdc, pdi, false)) {
+		PD_ERR(pd_dns6_del, "pd_add_del_dns6 failed\n");
+		return 1;
+	}
+
+	return 0;
+}
+
+void pd_dns_clean(struct pd_context *pdc)
+{
+	struct uci_context *c = pdc->c;
+
+	if (pd_uci_del(c, UCI_PKG_DHCP, UCI_SEC_LAN, UCI_OPT_DNS, NULL))
+		return;
+
+	PD_INFO(pd_dns_clean, "cleaning dns configuration\n");
+
+	pd_set(&pdc->status, PDC_ODHCPD_CHANGED);
+}