Add skeleton of DNS Lookup 07/200507/2
authorYu <jiung.yu@samsung.com>
Tue, 26 Feb 2019 01:52:21 +0000 (10:52 +0900)
committerYu <jiung.yu@samsung.com>
Wed, 27 Feb 2019 08:11:37 +0000 (17:11 +0900)
Change-Id: I586bccbcd566aed960cbf46cc74c50b387b02a99
Signed-off-by: Yu Jiung <jiung.yu@samsung.com>
include/inm-dns-lookup.h [new file with mode: 0644]
packaging/inm-manager.spec
src/CMakeLists.txt
src/inm-dns-lookup.c [new file with mode: 0644]
src/inm-manager.c

diff --git a/include/inm-dns-lookup.h b/include/inm-dns-lookup.h
new file mode 100644 (file)
index 0000000..f883cc1
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Network Monitoring Module
+ *
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/**
+ * This file defines macros and declares functions for dns-look-up.
+ *
+ * @file        inm-dns-lookup.h
+ * @author      Jiung Yu (jiung.yu@samsung.com)
+ */
+
+#ifndef __INM_DNS_LOOKUP_H__
+#define __INM_DNS_LOOKUP_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+       INM_DNS_LOOKUP_ERROR_NONE = 0,
+       INM_DNS_LOOKUP_ERROR_NOT_INITIALIZED,
+       INM_DNS_LOOKUP_ERROR_INVALID_PARAMETER,
+       INM_DNS_LOOKUP_ERROR_OPERATION_FAILED,
+       INM_DNS_LOOKUP_ERROR_IN_PROGRESS,
+       INM_DNS_LOOKUP_ERROR_TIMEOUT,
+} inm_dns_lookup_error_e;
+
+int inm_dns_lookup_init();
+int inm_dns_lookup_deinit();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __INM_DNS_LOOKUP_H__ */
index 0ccd4fe679fbac390114a4f8024d2aa194e63631..8a11e1617235fcc86b4555cb78fc88d0e5b36476 100644 (file)
@@ -17,6 +17,7 @@ BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires:  pkgconfig(vconf)
 BuildRequires:  pkgconfig(libcurl)
 BuildRequires:  pkgconfig(libnl-2.0)
+BuildRequires:  pkgconfig(libcares)
 BuildRequires:  python
 BuildRequires:  python-xml
 Requires:       security-config
index 13f46da0aebfe0f39437075616a468191649b7d4..359dae41020a4dcdff88020be88b532abc19ec94 100644 (file)
@@ -27,6 +27,7 @@ PKG_CHECK_MODULES(inm_pkgs REQUIRED
        libnl-2.0
        vconf
        libcurl
+       libcares
        )
 
 SET(REQUIRED_LIBS "-ldl")
@@ -69,6 +70,7 @@ SET(SRCS
        ${CMAKE_SOURCE_DIR}/src/inm-icmp-ping.c
        ${CMAKE_SOURCE_DIR}/src/inm-trace-route.c
        ${CMAKE_SOURCE_DIR}/src/inm-rtnl.c
+       ${CMAKE_SOURCE_DIR}/src/inm-dns-lookup.c
        )
 
 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fpic -Wall -Werror-implicit-function-declaration -fvisibility=hidden")
diff --git a/src/inm-dns-lookup.c b/src/inm-dns-lookup.c
new file mode 100644 (file)
index 0000000..4866bc9
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Network Monitoring Module
+ *
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/**
+ * This file implements DNS lookup functions.
+ *
+ * @file        inm-dns-lookup.c
+ * @author      Jiung Yu (jiung.yu@samsung.com)
+ */
+
+#include <ares.h>
+#include <glib.h>
+
+#include "inm-manager-log.h"
+#include "inm-manager.h"
+#include "inm-util.h"
+#include "inm-dns-lookup.h"
+
+int inm_dns_lookup_init()
+{
+       int version;
+
+       INM_LOGI("c-ares version %s", ares_version(&version));
+
+       return INM_DNS_LOOKUP_ERROR_NONE;
+}
+
+int inm_dns_lookup_deinit()
+{
+       return INM_DNS_LOOKUP_ERROR_NONE;
+}
index 137fc7e75689a0743540ae8ef92e60b34b9495d6..32ee0b2d81e8cf5eddda0a0c93498a17dd4c1b5f 100644 (file)
@@ -38,6 +38,7 @@
 #include "inm-connman.h"
 #include "inm-manager.h"
 #include "inm-rtnl.h"
+#include "inm-dns-lookup.h"
 #include "inm-manager-log.h"
 #include "inm-error.h"
 
@@ -696,6 +697,30 @@ static inline void __deinit_reacher()
        __INM_FUNC_EXIT__;
        return;
 }
+
+static inline void __init_dns_lookup()
+{
+       __INM_FUNC_ENTER__;
+       if (inm_dns_lookup_init() < 0) {
+               INM_LOGW("dns lookup init failed");
+               __INM_FUNC_EXIT__;
+               return;
+       }
+
+       __INM_FUNC_EXIT__;
+}
+
+static inline void __deinit_dns_lookup()
+{
+       __INM_FUNC_ENTER__;
+
+       if (inm_dns_lookup_deinit() < 0)
+               INM_LOGW("dns lookup deinit failed");
+
+       __INM_FUNC_EXIT__;
+       return;
+}
+
 static void __ethernet_cable_state_changed_cb(char *iface_name, int state, void *user_data)
 {
        gboolean is_attached = FALSE;
@@ -1200,6 +1225,7 @@ int inm_manager_init()
        __init_retry_tx_rate_monitor();
        __init_channel_interference_monitor();
        __init_congestion_mon();
+       __init_dns_lookup();
 
        __INM_FUNC_EXIT__;
        return ret;
@@ -1227,6 +1253,7 @@ int inm_manager_deinit()
        __deinit_retry_tx_rate_monitor();
        __deinit_channel_interference_monitor();
        __deinit_congestion_mon();
+       __deinit_dns_lookup();
 
 
        g_free(g_inm_manager);