From 40cef8b0b6b2cfdf302dc1ce6001abd7f5370e54 Mon Sep 17 00:00:00 2001 From: Sherik Sensin A Date: Wed, 20 Nov 2024 08:51:37 +0000 Subject: [PATCH] RDKCOM-5612: RDKBNETWOR-16 DNS Relay Feature Reason for change: Implementation of DNS forward proxy Test Procedure: DNS Relay DM functionality and proxy functionality Refer to JIRA Risks: None. Change-Id: I930ffa57b58c2e2123f731d5b6cb74fd88cd594c Signed-off-by: Sherik Sensin A --- source/include/utapi/utapi.h | 1 + source/include/utctx/utctx_api.h | 2 + source/scripts/init/service.d/lan_handler.sh | 18 + .../init/service.d/service_dhcp_server.sh | 336 +++++++++++++++--- .../dhcp_server_functions.sh | 102 ++++++ source/utapi/lib/utapi.h | 1 + source/utapi/lib/utapi_dns.c | 22 ++ source/utapi/lib/utapi_dns.h | 28 ++ source/utctx/lib/utctx.c | 2 + source/utctx/lib/utctx_api.h | 2 + 10 files changed, 467 insertions(+), 47 deletions(-) create mode 100644 source/utapi/lib/utapi_dns.h diff --git a/source/include/utapi/utapi.h b/source/include/utapi/utapi.h index 03df17d2..01bbf276 100644 --- a/source/include/utapi/utapi.h +++ b/source/include/utapi/utapi.h @@ -3400,6 +3400,7 @@ int Utopia_SetLanMngmLanNapt(UtopiaContext *ctx, napt_mode_t enable); typedef struct dns_client{ char dns_server[DNS_CLIENT_NAMESERVER_CNT][IPADDR_SZ]; + char s_alias[DNS_CLIENT_NAMESERVER_CNT][TR_ALIAS_SZ]; }DNS_Client_t; /** diff --git a/source/include/utctx/utctx_api.h b/source/include/utctx/utctx_api.h index 93003b35..aa5566dd 100644 --- a/source/include/utctx/utctx_api.h +++ b/source/include/utctx/utctx_api.h @@ -610,6 +610,8 @@ typedef enum _UtopiaValue UtopiaValue_PFR_PrevRuleEnabledState, UtopiaValue_PRT_PrevRuleEnabledState, UtopiaValue_HashPassword, + UtopiaValue_Dns_Relay_Enable, + UtopiaValue_Dns_ForwardCount, #if defined(_WAN_MANAGER_ENABLED_) UtopiaValue_WanMode, UtopiaValue_WanConnEnabled, diff --git a/source/scripts/init/service.d/lan_handler.sh b/source/scripts/init/service.d/lan_handler.sh index 7a38a307..c98a56d2 100755 --- a/source/scripts/init/service.d/lan_handler.sh +++ b/source/scripts/init/service.d/lan_handler.sh @@ -315,6 +315,24 @@ case "$1" in sysevent set multinet-up 9 fi + # -------------------------------------------------------------------- + # RPi specific change begin + # -------------------------------------------------------------------- + + PHY_BRIDGE_IFNAME=`syscfg get lan_ifname` + PHY_ETH_IFNAMES=`syscfg get lan_ethernet_physical_ifnames` + IFS=' ' read -r -a PHY_ETH_IFNAME_ARRAY <<< "$PHY_ETH_IFNAMES" + for PHY_ETH_IFNAME in "${PHY_ETH_IFNAME_ARRAY[@]}" + do + echo "LAN HANDLER : PHY_ETH_IFNAME = $PHY_ETH_IFNAME" + ifconfig $PHY_ETH_IFNAME up + brctl addif $PHY_BRIDGE_IFNAME $PHY_ETH_IFNAME + done + + # -------------------------------------------------------------------- + # RPi specific change end + # -------------------------------------------------------------------- + echo_t "LAN HANDLER : Triggering RDKB_FIREWALL_RESTART after nfqhandler" t2CountNotify "RF_INFO_RDKB_FIREWALL_RESTART" sysevent set firewall-restart diff --git a/source/scripts/init/service.d/service_dhcp_server.sh b/source/scripts/init/service.d/service_dhcp_server.sh index 0d824885..62b59c05 100755 --- a/source/scripts/init/service.d/service_dhcp_server.sh +++ b/source/scripts/init/service.d/service_dhcp_server.sh @@ -60,11 +60,15 @@ SERVICE_NAME="dhcp_server" #DHCP_CONF=/etc/dnsmasq.conf DHCP_CONF=/var/dnsmasq.conf +DHCP_CONF_WAN=/var/dnsmasq_wan.conf +DHCP_CONF_LAN=/var/dnsmasq_lan.conf RESOLV_CONF=/etc/resolv.conf BIN=dnsmasq SERVER=${BIN} PMON=/etc/utopia/service.d/pmon.sh PID_FILE=/var/run/dnsmasq.pid +WAN_PID_FILE=/var/run/dnsmasq_wan.pid +LAN_PID_FILE=/var/run/dnsmasq_lan.pid PID=$$ LXC_PID_FILE=/run/lxc/dnsmasq.pid @@ -139,9 +143,33 @@ dnsmasq_server_start () fi fi else - $SERVER -P 4096 -C $DHCP_CONF $DNS_ADDITIONAL_OPTION #--enable-dbus - fi + SYSCFG_RELAY_ENABLE=`syscfg get dns_relay_enable` + if [ "$SYSCFG_RELAY_ENABLE" = "1" ] ; then + ##"SERVICE DHCP : Relay On" + $SERVER -u nobody -P 4096 -C $DHCP_CONF_LAN + $SERVER -u nobody -P 4096 -C $DHCP_CONF_WAN + + WANPID=`ps -ef | grep dnsmasq_wan | head -n 1| cut -d" " -f1` + if [ -z "$WANPID" ] ; then + WANPID=`ps -ef | grep dnsmasq_wan | head -n 1| cut -d" " -f2` + echo $WANPID > $WAN_PID_FILE + else + echo $WANPID > $WAN_PID_FILE + fi + LANPID=`ps -ef | grep dnsmasq_lan | head -n 1| cut -d" " -f1` + if [ -z "$LANPID" ] ; then + LANPID=`ps -ef | grep dnsmasq_lan | head -n 1| cut -d" " -f2` + echo $LANPID > $LAN_PID_FILE + else + echo $LANPID > $LAN_PID_FILE + fi + else + ## "SERVICE DHCP : Relay off" + sysevent set dns_proxy_status stopped + $SERVER -u nobody -P 4096 -C $DHCP_CONF #--enable-dbus + fi + fi } @@ -229,7 +257,7 @@ restart_request () wait_till_end_state dns wait_till_end_state dhcp_server - + DNS_PROXY_STATUS=`sysevent get dns_proxy_status` # save a copy of the dnsmasq conf file to help determine whether or not to # kill the server DHCP_TMP_CONF="/tmp/dnsmasq.conf.orig" @@ -247,37 +275,110 @@ restart_request () sanitize_leases_file fi + DHCP_TMP_WAN_CONF="/tmp/dnsmasq_wan.conf.orig" + if [ -f $DHCP_CONF_WAN ];then + cp -f $DHCP_CONF_WAN $DHCP_TMP_WAN_CONF + fi + + DHCP_TMP_LAN_CONF="/tmp/dnsmasq_lan.conf.orig" + if [ -f $DHCP_CONF_LAN ];then + cp -f $DHCP_CONF_LAN $DHCP_TMP_LAN_CONF + fi + # we need to decide whether to completely restart the dns/dhcp_server # or whether to just have it reread everything # SIGHUP is reread (except for dnsmasq.conf) RESTART=0 - if ! cmp -s $DHCP_CONF $DHCP_TMP_CONF ; then - RESTART=1 + FOO="" + if [ "started" = "$DNS_PROXY_STATUS" ] ; then + ##Relay on mode + FOO1="" + if [ -f $DHCP_CONF_WAN ] && [ -f $DHCP_TMP_WAN_CONF ];then + FOO=`diff $DHCP_CONF_WAN $DHCP_TMP_WAN_CONF` + fi + + if [ -f $DHCP_CONF_LAN ] && [ -f $DHCP_TMP_LAN_CONF ];then + FOO1=`diff $DHCP_CONF_LAN $DHCP_TMP_LAN_CONF` + fi + + if [ -n "$FOO" ] || [ -n "$FOO1"]; then + RESTART=1 + fi + + LAN_CONF_PID="" + WAN_CONF_PID="" + if [ -f $LAN_PID_FILE ];then + LAN_CONF_PID=`cat $LAN_PID_FILE` + fi + + if [ -f $WAN_PID_FILE ];then + WAN_CONF_PID=`cat $WAN_PID_FILE` + fi + + if [ -z "$LAN_PID_FILE" ] || [ -z "$WAN_PID_FILE" ] ; then + RESTART=1 + else + RUNNING_PIDS=`pidof dnsmasq` + if [ -z "$RUNNING_PIDS" ] ; then + RESTART=1 + else + FOO=`echo $RUNNING_PIDS | grep $LAN_CONF_PID` + FOO1=`echo $RUNNING_PIDS | grep $WAN_CONF_PID` + if [ -z "$FOO" ] || [ -z "$FOO1" ] ; then + RESTART=1 + fi + + #Check for the case where dnsmasq is running without config file + FOO=`cat /proc/${LAN_CONF_PID}/cmdline | grep "$DHCP_LAN_CONF"` + FOO1=`cat /proc/${WAN_CONF_PID}/cmdline | grep "$DHCP_WAN_CONF"` + if [ -z "$FOO" ] || [ -z "$FOO1" ]; then + RESTART=1 + fi + + fi + fi else - CURRENT_PID=`cat $PID_FILE 2>/dev/null` - if [ -z "$CURRENT_PID" ] ; then - RESTART=1 - else - RUNNING_PIDS=`pidof dnsmasq` - if [ -z "$RUNNING_PIDS" ] ; then + ##Relay off - Default mode + if [ -f $DHCP_CONF ] && [ -f $DHCP_TMP_CONF ];then + FOO=`diff $DHCP_CONF $DHCP_TMP_CONF` + fi + + if [ -n "$FOO" ] ; then + RESTART=1 + fi + + CURRENT_PID="" + if [ -f $PID_FILE ];then + CURRENT_PID=`cat $PID_FILE` + fi + + if [ -z "$CURRENT_PID" ] ; then RESTART=1 - else - FOO=`echo $RUNNING_PIDS | grep $CURRENT_PID` - if [ -z "$FOO" ] ; then - RESTART=1 + else + CURRENT_PIDS=`pidof dnsmasq` + if [ -z "$CURRENT_PIDS" ] ; then + RESTART=1 else - # Intel Proposed RDKB Generic Bug Fix from XB6 SDK - # Check for the case where dnsmasq is running without config file - FOO=`cat /proc/${CURRENT_PID}/cmdline | grep "$DHCP_CONF"` - if [ -z "$FOO" ] ; then - RESTART=1 - fi + RUNNING_PIDS=`pidof dnsmasq` + FOO=`echo $RUNNING_PIDS | grep $CURRENT_PID` + if [ -z "$FOO" ] ; then + RESTART=1 + fi + + #Intel Proposed RDKB Generic Bug Fix from XB6 SDK + #Check for the case where dnsmasq is running without config file + FOO=`cat /proc/${CURRENT_PID}/cmdline | grep "$DHCP_CONF"` + if [ -z "$FOO" ] ; then + RESTART=1 + fi fi - fi - fi + + fi fi rm -f $DHCP_TMP_CONF + rm -f $DHCP_TMP_WAN_CONF + rm -f $DHCP_TMP_LAN_CONF killall -HUP `basename $SERVER` if [ "0" = "$RESTART" ] ; then @@ -285,7 +386,12 @@ restart_request () fi killall `basename $SERVER` - rm -f $PID_FILE + if [ "started" = "$DNS_PROXY_STATUS" ] ; then + rm -f $WAN_PID_FILE + rm -f $LAN_PID_FILE + else + rm -f $PID_FILE + fi if [ "$CONTAINER_SUPPORT" = "1" ]; then dnsserver_start_lxc @@ -432,6 +538,7 @@ reset_eth_usb_ports () #----------------------------------------------------------------- dhcp_server_start () { + DNS_PROXY_STATUS=`sysevent get dns_proxy_status` if [ "0" = "$SYSCFG_dhcp_server_enabled" ] ; then #when disable dhcp server in gui, we need remove the corresponding process in backend, or the dhcp server still work. dhcp_server_stop @@ -486,6 +593,17 @@ dhcp_server_start () if [ -f $DHCP_CONF ];then cp -f $DHCP_CONF $DHCP_TMP_CONF fi + + DHCP_TMP_WAN_CONF="/tmp/dnsmasq_wan.conf.orig" + if [ -f $DHCP_CONF_WAN ];then + cp -f $DHCP_CONF_WAN $DHCP_TMP_WAN_CONF + fi + + DHCP_TMP_LAN_CONF="/tmp/dnsmasq_lan.conf.orig" + if [ -f $DHCP_CONF_LAN ];then + cp -f $DHCP_CONF_LAN $DHCP_TMP_LAN_CONF + fi + # set hostname and /etc/hosts cause we are the dns forwarder prepare_hostname # also prepare dhcp conf cause we are the dhcp server too @@ -493,37 +611,105 @@ dhcp_server_start () # remove any extraneous leases sanitize_leases_file + #prepare dns proxy lan conf file + prepare_dns_proxy_conf + # we need to decide whether to completely restart the dns/dhcp_server # or whether to just have it reread everything # SIGHUP is reread (except for dnsmasq.conf) RESTART=0 - if ! cmp -s $DHCP_CONF $DHCP_TMP_CONF ; then - RESTART=1 + FOO="" + if [ "started" = "$DNS_PROXY_STATUS" ] ; then + ##Relay on mode + FOO1="" + if [ -f $DHCP_CONF_WAN ] && [ -f $DHCP_TMP_WAN_CONF ];then + FOO=`diff $DHCP_CONF_WAN $DHCP_TMP_WAN_CONF` + fi + + if [ -f $DHCP_CONF_LAN ] && [ -f $DHCP_TMP_LAN_CONF ];then + FOO1=`diff $DHCP_CONF_LAN $DHCP_TMP_LAN_CONF` + fi + + if [ -n "$FOO" ] || [ -n "$FOO1" ]; then + RESTART=1 + fi + + LAN_CONF_PID="" + WAN_CONF_PID="" + if [ -f $LAN_PID_FILE ];then + LAN_CONF_PID=`cat $LAN_PID_FILE` + fi + + if [ -f $WAN_PID_FILE ];then + WAN_CONF_PID=`cat $WAN_PID_FILE` + fi + + if [ -z "$LAN_PID_FILE" ] || [ -z "$WAN_PID_FILE" ] ; then + RESTART=1 + else + RUNNING_PIDS=`pidof dnsmasq` + if [ -z "$RUNNING_PIDS" ] ; then + RESTART=1 + else + FOO=`echo $RUNNING_PIDS | grep $LAN_CONF_PID` + FOO1=`echo $RUNNING_PIDS | grep $WAN_CONF_PID` + if [ -z "$FOO" ] || [ -z "$FOO1" ] ; then + RESTART=1 + fi + + #Check for the case where dnsmasq is running without config file + FOO=`cat /proc/${LAN_CONF_PID}/cmdline | grep "$DHCP_CONF_LAN"` + FOO1=`cat /proc/${WAN_CONF_PID}/cmdline | grep "$DHCP_CONF_WAN"` + if [ -z "$FOO" ] || [ -z "$FOO1" ]; then + RESTART=1 + fi + + fi + fi else - CURRENT_PID=`cat $PID_FILE 2>/dev/null` - if [ -z "$CURRENT_PID" ] ; then - RESTART=1 - else - RUNNING_PIDS=`pidof dnsmasq` - if [ -z "$RUNNING_PIDS" ] ; then - RESTART=1 - else - FOO=`echo $RUNNING_PIDS | grep $CURRENT_PID` - if [ -z "$FOO" ] ; then + ##Relay off or default mode + if [ -f $DHCP_CONF ] && [ -f $DHCP_TMP_CONF ];then + FOO=`diff $DHCP_CONF $DHCP_TMP_CONF` + fi + + if [ -n "$FOO" ] ; then + RESTART=1 + fi + + CURRENT_PID="" + if [ -f $PID_FILE ];then + CURRENT_PID=`cat $PID_FILE` + fi + + if [ -f $PID_FILE ];then + CURRENT_PID=`cat $PID_FILE` + fi + + if [ -z "$CURRENT_PID" ] ; then + RESTART=1 + else + RUNNING_PIDS=`pidof dnsmasq` + if [ -z "$RUNNING_PIDS" ] ; then RESTART=1 - else - # Intel Proposed RDKB Generic Bug Fix from XB6 SDK - # Check for the case where dnsmasq is running without config file + else + FOO=`echo $RUNNING_PIDS | grep $CURRENT_PID` + if [ -z "$FOO" ] ; then + RESTART=1 + fi + + #Intel Proposed RDKB Generic Bug Fix from XB6 SDK + #Check for the case where dnsmasq is running without config file FOO=`cat /proc/${CURRENT_PID}/cmdline | grep "$DHCP_CONF"` if [ -z "$FOO" ] ; then - RESTART=1 + RESTART=1 fi fi - fi - fi + fi fi rm -f $DHCP_TMP_CONF + rm -f $DHCP_TMP_WAN_CONF + rm -f $DHCP_TMP_LAN_CONF killall -HUP `basename $SERVER` if [ "0" = "$RESTART" ] ; then @@ -541,8 +727,13 @@ dhcp_server_start () sysevent set dns-status stopped killall `basename $SERVER` - rm -f $PID_FILE - + if [ "started" = "$DNS_PROXY_STATUS" ] ; then + rm -f $WAN_PID_FILE + rm -f $LAN_PID_FILE + else + rm -f $PID_FILE + fi + #Send SIGKILL to dnsmasq process if its not killed properly with SIGTERM if [ ! -z `pidof dnsmasq` ] ; then echo_t "SERVICE DHCP : dnsmasq process killed with SIGKILL " @@ -673,7 +864,15 @@ dhcp_server_start () echo_t "Xfinityhome service is not UP yet" fi - $PMON setproc dhcp_server $BIN $PID_FILE "/etc/utopia/service.d/service_dhcp_server.sh dhcp_server-restart" + if [ "started" = "$DNS_PROXY_STATUS" ] ; then + $PMON register dhcp_server_wan + $PMON register dhcp_server_lan + $PMON setproc dhcp_server_wan $BIN $WAN_PID_FILE "/etc/utopia/service.d/service_dhcp_server.sh dhcp_server_wan-restart" + $PMON setproc dhcp_server_lan $BIN $LAN_PID_FILE "/etc/utopia/service.d/service_dhcp_server.sh dhcp_server_lan-restart" + else + $PMON setproc dhcp_server $BIN $PID_FILE "/etc/utopia/service.d/service_dhcp_server.sh dhcp_server-restart" + fi + sysevent set dns-status started sysevent set dhcp_server-status started sysevent set dhcp_server-progress completed @@ -723,12 +922,23 @@ dhcp_server_stop () fi #dns is always running + prepare_dns_proxy_conf prepare_hostname prepare_dhcp_conf $SYSCFG_lan_ipaddr $SYSCFG_lan_netmask dns_only - $PMON unsetproc dhcp_server sysevent set dns-status stopped + DNS_PROXY_STATUS=`sysevent get dns_proxy_status` + if [ "started" = "$DNS_PROXY_STATUS" ] ; then + $PMON unregister dhcp_server_wan + $PMON unregister dhcp_server_lan + $PMON unsetproc dhcp_server_wan + $PMON unsetproc dhcp_server_lan + rm -f $LAN_PID_FILE + rm -f $WAN_PID_FILE + else + $PMON unsetproc dhcp_server + rm -f $PID_FILE + fi killall `basename $SERVER` - rm -f $PID_FILE sysevent set dhcp_server-status stopped if [ "$CONTAINER_SUPPORT" = "1" ]; then @@ -861,6 +1071,32 @@ dns_start () $PMON setproc dhcp_server $BIN $PID_FILE "/etc/utopia/service.d/service_dhcp_server.sh dns-restart" } +dhcp_server_wan_restart () +{ + echo_t "dns proxy wan restart called by pmon" + $SERVER -u nobody -P 4096 -C $DHCP_CONF_WAN + WANPID=`ps -ef | grep dnsmasq_wan | head -n 1| cut -d" " -f1` + if [ -z "$WANPID" ] ; then + WANPID=`ps -ef | grep dnsmasq_wan | head -n 1| cut -d" " -f2` + echo $WANPID > $WAN_PID_FILE + else + echo $WANPID > $WAN_PID_FILE + fi +} + +dhcp_server_lan_restart () +{ + echo_t "dns proxy lan restart called by pmon" + $SERVER -u nobody -P 4096 -C $DHCP_CONF_LAN + LANPID=`ps -ef | grep dnsmasq_lan | head -n 1| cut -d" " -f1` + if [ -z "$LANPID" ] ; then + LANPID=`ps -ef | grep dnsmasq_lan | head -n 1| cut -d" " -f2` + echo $LANPID > $LAN_PID_FILE + else + echo $LANPID > $LAN_PID_FILE + fi +} + #----------------------------------------------------------------------- #----------------------------------------------------------------------- @@ -906,6 +1142,12 @@ case "$1" in dhcp_server_start $2 fi ;; + ${SERVICE_NAME}_wan-restart) + dhcp_server_wan_restart + ;; + ${SERVICE_NAME}_lan-restart) + dhcp_server_lan_restart + ;; lan-status) echo_t "SERVICE DHCP : Got lan_status" lan_status_change $CURRENT_LAN_STATE diff --git a/source/scripts/init/service.d/service_dhcp_server/dhcp_server_functions.sh b/source/scripts/init/service.d/service_dhcp_server/dhcp_server_functions.sh index ff6b4861..8817a78e 100755 --- a/source/scripts/init/service.d/service_dhcp_server/dhcp_server_functions.sh +++ b/source/scripts/init/service.d/service_dhcp_server/dhcp_server_functions.sh @@ -38,6 +38,10 @@ source /lib/rdk/t2Shared_api.sh source /etc/waninfo.sh DHCP_CONF=/etc/dnsmasq.conf + +DHCP_CONF_WAN=/var/dnsmasq_wan.conf +DHCP_CONF_LAN=/var/dnsmasq_lan.conf + DHCP_STATIC_HOSTS_FILE=/etc/dhcp_static_hosts DHCP_OPTIONS_FILE=/var/dhcp_options SelfHealSupport=`sysevent get SelfhelpWANConnectionDiagSupport` @@ -49,10 +53,16 @@ LOCAL_DHCP_STATIC_HOSTS_FILE=/tmp/dhcp_static_hosts LOCAL_DHCP_OPTIONS_FILE=/tmp/dhcp_options else LOCAL_DHCP_CONF=/tmp/dnsmasq.conf$$ +LOCAL_DHCP_CONF_WAN=/tmp/dnsmasq_wan.conf$$ +LOCAL_DHCP_CONF_LAN=/tmp/dnsmasq_lan.conf$$ LOCAL_DHCP_STATIC_HOSTS_FILE=/tmp/dhcp_static_hosts$$ LOCAL_DHCP_OPTIONS_FILE=/tmp/dhcp_options$$ fi RESOLV_CONF=/etc/resolv.conf +DNS_PROXY_RESOLV_CONF=/var/resolv_lan.dnsmasq +DNS_PROXY_RESOLV_CONF_TMP=/tmp/resolv_lan.dnsmasq +STATIC_DNS_IPv4="" +STATIC_DNS_IPv6="" TMP_RESOLVE_CONF=/tmp/lte_resolv.conf WAN_INTERFACE=$(getWanInterfaceName) if [ "$BOX_TYPE" = "SR300" ] || [ "$BOX_TYPE" = "SR213" ] || [ "$BOX_TYPE" = "HUB4" ] || [ "$SelfHealSupport" = "true" ]; then @@ -676,6 +686,55 @@ prepare_whitelist_urls() fi } +get_static_dns_ips(){ + ind=1 + + if [ "$1" == "ipv6" ] ; then + STATIC_DNS_IPv6="" + delim=":" + else + STATIC_DNS_IPv4="" + delim="\." + fi + + count=`syscfg get dns_forward_count` + if [ -z "$count" ] ; then + count="0" + fi + + while [ "$ind" -le "$count" ] + do + DnsEnable=`psmcli get dmsb.dns.forwarding.$ind.enable` + if [ "$DnsEnable" = "1" ] ; then + ip=`psmcli get dmsb.dns.forwarding.$ind.dnsserver | grep $delim` + if [ -n "$ip" ] ; then + static_ips=$static_ips""$ip" " + fi + fi + ((ind++)) + done + + if [ "$1" == "ipv6" ] ; then + STATIC_DNS_IPv6=$static_ips + else + STATIC_DNS_IPv4=$static_ips + fi +} + +prepare_dns_proxy_conf() +{ + get_static_dns_ips ipv6 + get_static_dns_ips ipv4 + ind=0 + for ip in $STATIC_DNS_IPv4; + do + ((ind++)) + echo "nameserver $ip" >> $DNS_PROXY_RESOLV_CONF_TMP + done + cat $DNS_PROXY_RESOLV_CONF_TMP > $DNS_PROXY_RESOLV_CONF + rm $DNS_PROXY_RESOLV_CONF_TMP +} + prepare_static_dns_urls() { if [ -f $STATIC_DNS_URLS_FILE ]; then @@ -1022,6 +1081,9 @@ fi then echo "domain-needed" >> $LOCAL_DHCP_CONF echo "bogus-priv" >> $LOCAL_DHCP_CONF + echo "domain-needed" >> $LOCAL_DHCP_CONF_WAN + echo "bogus-priv" >> $LOCAL_DHCP_CONF_WAN + echo "bind-interfaces" >> $LOCAL_DHCP_CONF_WAN PARTNER_ID=`syscfg get PartnerID` if [ "$BOX_TYPE" = "SR213" ] || [ "$PARTNER_ID" = "sky-uk" ] ; then @@ -1039,6 +1101,7 @@ fi touch $DEFAULT_RESOLV_CONF echo "nameserver 127.0.0.1" > $DEFAULT_RESOLV_CONF echo "resolv-file=$DEFAULT_RESOLV_CONF" >> $LOCAL_DHCP_CONF + echo "resolv-file=$DEFAULT_RESOLV_CONF" >> $LOCAL_DHCP_CONF_WAN #echo "address=/#/$addr" >> $DHCP_CONF else if [ -e $DEFAULT_RESOLV_CONF ] @@ -1048,10 +1111,24 @@ fi if [ "0" = "$NAMESERVERENABLED" ] && [ $isLocalDNSOnly -eq 0 ] ; then echo "resolv-file=$RESOLV_CONF" >> $LOCAL_DHCP_CONF + echo "resolv-file=$RESOLV_CONF" >> $LOCAL_DHCP_CONF_WAN fi fi + cat $LOCAL_DHCP_CONF_WAN >> $LOCAL_DHCP_CONF_LAN + resolvFile=$(mktemp) + for checkString in $LOCAL_DHCP_CONF_LAN; do + awk '!/resolv-file/' $checkString > $resolvFile + cp $resolvFile $checkString + done + rm $resolvFile + + echo "resolv-file=$DNS_PROXY_RESOLV_CONF" >> $LOCAL_DHCP_CONF_LAN + echo "interface=lo" >> $LOCAL_DHCP_CONF_WAN + echo "except-interface=brlan0" >> $LOCAL_DHCP_CONF_WAN + echo "except-interface=lo" >> $LOCAL_DHCP_CONF_LAN + # if we are provisioned to use the wan domain name, the we do so # otherwise we use the lan domain name if grep "domain=" $LOCAL_DHCP_CONF >/dev/null @@ -1070,6 +1147,8 @@ fi if [ -n "$LAN_DOMAIN" ] ; then echo "domain=$LAN_DOMAIN" >> $LOCAL_DHCP_CONF echo "local=/$LAN_DOMAIN/" >> $LOCAL_DHCP_CONF + echo "domain=$LAN_DOMAIN" >> $LOCAL_DHCP_CONF_LAN + echo "local=/$LAN_DOMAIN/" >> $LOCAL_DHCP_CONF_LAN fi fi else @@ -1079,6 +1158,8 @@ fi #echo "interface=$LAN_IFNAME" >> $LOCAL_DHCP_CONF echo "expand-hosts" >> $LOCAL_DHCP_CONF echo "address=/.c.f.ip6.arpa/" >> $LOCAL_DHCP_CONF + echo "expand-hosts" >> $LOCAL_DHCP_CONF_LAN + echo "address=/.c.f.ip6.arpa/" >> $LOCAL_DHCP_CONF_LAN LOG_LEVEL=`syscfg get log_level` if [ -z "$LOG_LEVEL" ] ; then @@ -1087,12 +1168,15 @@ fi if [ "$3" = "dns_only" ] ; then echo "no-dhcp-interface=$LAN_IFNAME" >> $LOCAL_DHCP_CONF + echo "no-dhcp-interface=$LAN_IFNAME" >> $LOCAL_DHCP_CONF_WAN fi #echo "$PREFIX""dhcp-range=$DHCP_START_ADDR,$DHCP_END_ADDR,$2,$DHCP_LEASE_TIME" >> $LOCAL_DHCP_CONF echo "dhcp-leasefile=$DHCP_LEASE_FILE" >> $LOCAL_DHCP_CONF + echo "dhcp-leasefile=$DHCP_LEASE_FILE" >> $LOCAL_DHCP_CONF_LAN # echo "$PREFIX""dhcp-script=$DHCP_ACTION_SCRIPT" >> $LOCAL_DHCP_CONF # echo "$PREFIX""dhcp-lease-max=$DHCP_NUM" >> $LOCAL_DHCP_CONF echo "dhcp-hostsfile=$DHCP_STATIC_HOSTS_FILE" >> $LOCAL_DHCP_CONF + echo "dhcp-hostsfile=$DHCP_STATIC_HOSTS_FILE" >> $LOCAL_DHCP_CONF_LAN if [ "$RF_CAPTIVE_PORTAL" != "true" ] then @@ -1101,6 +1185,7 @@ fi if [ $isLocalDNSOnly -eq 0 ] then echo "dhcp-optsfile=$DHCP_OPTIONS_FILE" >> $LOCAL_DHCP_CONF + echo "dhcp-optsfile=$DHCP_OPTIONS_FILE" >> $LOCAL_DHCP_CONF_LAN fi fi fi @@ -1144,14 +1229,18 @@ fi if [ "started" = "$CURRENT_LAN_STATE" ]; then calculate_dhcp_range "$LAN_IPADDR" "$LAN_NETMASK" echo "interface=$LAN_IFNAME" >> $LOCAL_DHCP_CONF + echo "interface=$LAN_IFNAME" >> $LOCAL_DHCP_CONF_LAN if [ $DHCP_LEASE_TIME == -1 ]; then echo "$PREFIX""dhcp-range=$DHCP_START_ADDR,$DHCP_END_ADDR,$LAN_NETMASK,infinite" >> $LOCAL_DHCP_CONF + echo "$PREFIX""dhcp-range=$DHCP_START_ADDR,$DHCP_END_ADDR,$LAN_NETMASK,infinite" >> $LOCAL_DHCP_CONF_LAN else echo "$PREFIX""dhcp-range=$DHCP_START_ADDR,$DHCP_END_ADDR,$LAN_NETMASK,$DHCP_LEASE_TIME" >> $LOCAL_DHCP_CONF + echo "$PREFIX""dhcp-range=$DHCP_START_ADDR,$DHCP_END_ADDR,$LAN_NETMASK,$DHCP_LEASE_TIME" >> $LOCAL_DHCP_CONF_LAN fi if [ "1" = "$NAMESERVERENABLED" ]; then DHCP_OPTION_FOR_LAN=`get_dhcp_option_for_brlan0` echo "$PREFIX""$DHCP_OPTION_FOR_LAN" >> $LOCAL_DHCP_CONF + echo "$PREFIX""$DHCP_OPTION_FOR_LAN" >> $LOCAL_DHCP_CONF_LAN echo_t "DHCP_SERVER : $PREFIX$DHCP_OPTION_FOR_LAN" SECUREWEBUI_ENABLED=`syscfg get SecureWebUI_Enable` if [ "$SECUREWEBUI_ENABLED" = "true" ]; then @@ -1159,6 +1248,8 @@ fi LOCDOMAIN_NAME=`syscfg get SecureWebUI_LocalFqdn` echo "address=/$LOCDOMAIN_NAME/$locaddr" >> $LOCAL_DHCP_CONF echo "server=/$LOCDOMAIN_NAME/$locaddr" >> $LOCAL_DHCP_CONF + echo "address=/$LOCDOMAIN_NAME/$locaddr" >> $LOCAL_DHCP_CONF_LAN + echo "server=/$LOCDOMAIN_NAME/$locaddr" >> $LOCAL_DHCP_CONF_LAN fi fi @@ -1187,14 +1278,19 @@ fi IOT_END_ADDR=`syscfg get iot_dhcp_end` IOT_NETMASK=`syscfg get iot_netmask` echo "interface=$IOT_IFNAME" >> $LOCAL_DHCP_CONF + echo "interface=$IOT_IFNAME" >> $LOCAL_DHCP_CONF_LAN + echo "except-interface=$IOT_IFNAME" >> $LOCAL_DHCP_CONF_WAN if [ $DHCP_LEASE_TIME == -1 ]; then echo "$PREFIX""dhcp-range=$IOT_START_ADDR,$IOT_END_ADDR,$IOT_NETMASK,infinite" >> $LOCAL_DHCP_CONF + echo "$PREFIX""dhcp-range=$IOT_START_ADDR,$IOT_END_ADDR,$IOT_NETMASK,infinite" >> $LOCAL_DHCP_CONF_LAN else echo "$PREFIX""dhcp-range=$IOT_START_ADDR,$IOT_END_ADDR,$IOT_NETMASK,86400" >> $LOCAL_DHCP_CONF + echo "$PREFIX""dhcp-range=$IOT_START_ADDR,$IOT_END_ADDR,$IOT_NETMASK,86400" >> $LOCAL_DHCP_CONF_LAN fi if [ "1" == "$NAMESERVERENABLED" ] && [ -n "$WAN_DHCP_NS" ]; then echo "${PREFIX}""dhcp-option=${IOT_IFNAME},6,$WAN_DHCP_NS" >> $LOCAL_DHCP_CONF + echo "${PREFIX}""dhcp-option=${IOT_IFNAME},6,$WAN_DHCP_NS" >> $LOCAL_DHCP_CONF_LAN fi fi @@ -1425,6 +1521,10 @@ fi cat $LOCAL_DHCP_CONF > $DHCP_CONF rm -f $LOCAL_DHCP_CONF + cat $LOCAL_DHCP_CONF_WAN > $DHCP_CONF_WAN + cat $LOCAL_DHCP_CONF_LAN > $DHCP_CONF_LAN + rm -f $LOCAL_DHCP_CONF_WAN $LOCAL_DHCP_CONF_LAN + echo "DHCP SERVER : Completed preparing DHCP configuration" if [ "$WanFailOverSupportEnable" = true ] && [ "$rdkb_extender" != "true" ] && @@ -1505,6 +1605,8 @@ do_extra_pools () { then echo "${PREFIX}interface=${IFNAME}" >> $LOCAL_DHCP_CONF echo "${PREFIX}""dhcp-range=set:$i,${m_DHCP_START_ADDR},${m_DHCP_END_ADDR},$m_LAN_SUBNET,${m_DHCP_LEASE_TIME}" >> $LOCAL_DHCP_CONF + echo "${PREFIX}""interface="${IFNAME} >> $LOCAL_DHCP_CONF_LAN + echo "${PREFIX}""dhcp-range=set:$i,${m_DHCP_START_ADDR},${m_DHCP_END_ADDR},$m_LAN_SUBNET,${m_DHCP_LEASE_TIME}" >> $LOCAL_DHCP_CONF_LAN echo_t "DHCP_SERVER : [BRLAN1] ${PREFIX}""dhcp-range=set:$i,${m_DHCP_START_ADDR},${m_DHCP_END_ADDR},$m_LAN_SUBNET,${m_DHCP_LEASE_TIME}" fi diff --git a/source/utapi/lib/utapi.h b/source/utapi/lib/utapi.h index 06828152..bf78ce8b 100644 --- a/source/utapi/lib/utapi.h +++ b/source/utapi/lib/utapi.h @@ -3379,6 +3379,7 @@ int Utopia_SetLanMngmLanNapt(UtopiaContext *ctx, napt_mode_t enable); typedef struct dns_client{ char dns_server[DNS_CLIENT_NAMESERVER_CNT][IPADDR_SZ]; + char s_alias[DNS_CLIENT_NAMESERVER_CNT][TR_ALIAS_SZ]; }DNS_Client_t; /** diff --git a/source/utapi/lib/utapi_dns.c b/source/utapi/lib/utapi_dns.c index ecf9da06..603d80b9 100644 --- a/source/utapi/lib/utapi_dns.c +++ b/source/utapi/lib/utapi_dns.c @@ -44,6 +44,7 @@ #include "DM_TR181.h" #include #include "safec_lib_common.h" +#include "utapi_dns.h" int Utopia_Get_DeviceDnsRelayForwarding(UtopiaContext *pCtx, int index, void *str_handle) { @@ -134,3 +135,24 @@ int Utopia_Set_DeviceDnsRelayForwarding(UtopiaContext *pCtx, int index, void *st return UT_SUCCESS; } + +int Utopia_GetDnsRelayEnabled(UtopiaContext *ctx, boolean_t *enabled) +{ + return Utopia_GetBool(ctx, UtopiaValue_Dns_Relay_Enable, enabled); +} + +int Utopia_SetDnsRelayEnabled(UtopiaContext *ctx, boolean_t enabled) +{ + return Utopia_SetBool(ctx, UtopiaValue_Dns_Relay_Enable, enabled); +} + +static int g_Dns_ForwardCount = 0; + +int Utopia_GetNumberOfDnsForwards(UtopiaContext *ctx) +{ + if(g_Dns_ForwardCount == 0) + { + Utopia_GetInt(ctx, UtopiaValue_Dns_ForwardCount, &g_Dns_ForwardCount); + } + return g_Dns_ForwardCount; +} diff --git a/source/utapi/lib/utapi_dns.h b/source/utapi/lib/utapi_dns.h new file mode 100644 index 00000000..3145667e --- /dev/null +++ b/source/utapi/lib/utapi_dns.h @@ -0,0 +1,28 @@ +/********************************************************************************* + If not stated otherwise in this file or this component's Licenses.txt file the + * following copyright and licenses apply: + * + * Copyright 2024 Deutsche Telekom AG. + * + * 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. +********************************************************************************/ + +#ifndef _UTAPI_DNS_H_ +#define _UTAPI_DNS_H_ + +#include "utapi.h" + +int Utopia_GetNumberOfDnsForwards(UtopiaContext *ctx); +int Utopia_SetDnsRelayEnabled(UtopiaContext *ctx, boolean_t enabled); +int Utopia_GetDnsRelayEnabled(UtopiaContext *ctx, boolean_t *enabled); +#endif diff --git a/source/utctx/lib/utctx.c b/source/utctx/lib/utctx.c index 3237b370..da619332 100755 --- a/source/utctx/lib/utctx.c +++ b/source/utctx/lib/utctx.c @@ -769,6 +769,8 @@ static struct { Utopia_Type_IndexedConfig, Utopia_Event_Firewall_Restart, Utopia_Static__NONE__, Utopia_Index_For_NS, 1, "prev_rule_enabled_state", UtopiaValue_PortRangeForward }, /* UtopiaValue_PFR_PrevRuleEnabledState */ { Utopia_Type_IndexedConfig, Utopia_Event_Firewall_Restart, Utopia_Static__NONE__, Utopia_Index_For_NS, 1, "prev_rule_enabled_state", UtopiaValue_PortRangeTrigger }, /* UtopiaValue_PRT_PrevRuleEnabledState */ { Utopia_Type_IndexedConfig, Utopia_Event__NONE__, Utopia_Static__NONE__, Utopia_Index_For_Key, 1, "hash_password_%d", UtopiaValue__UNKNOWN__ }, /* UtopiaValue_HashPassword */ + { Utopia_Type_Config, Utopia_Event__NONE__, Utopia_Static__NONE__, Utopia_For__NONE__, 1, "dns_relay_enable", UtopiaValue__UNKNOWN__ }, /* UtopiaValue_Dns_Relay_Enable*/ + { Utopia_Type_Config, Utopia_Event__NONE__, Utopia_Static__NONE__, Utopia_For__NONE__, 1, "dns_forward_count", UtopiaValue__UNKNOWN__ }, /* UtopiaValue_Dns_ForwardCount */ #if defined(_WAN_MANAGER_ENABLED_) { Utopia_Type_Config, Utopia_Event__NONE__, Utopia_Static__NONE__, Utopia_For__NONE__, 1, "wan_mode", UtopiaValue__UNKNOWN__ }, /* UtopiaValue_WanMode */ { Utopia_Type_Config, Utopia_Event__NONE__, Utopia_Static__NONE__, Utopia_For__NONE__, 1, "wan_conn_enabled", UtopiaValue__UNKNOWN__ }, /* UtopiaValue_WanConnEnabled */ diff --git a/source/utctx/lib/utctx_api.h b/source/utctx/lib/utctx_api.h index d91abb62..13a99b28 100644 --- a/source/utctx/lib/utctx_api.h +++ b/source/utctx/lib/utctx_api.h @@ -608,6 +608,8 @@ typedef enum _UtopiaValue UtopiaValue_PFR_PrevRuleEnabledState, UtopiaValue_PRT_PrevRuleEnabledState, UtopiaValue_HashPassword, + UtopiaValue_Dns_Relay_Enable, + UtopiaValue_Dns_ForwardCount, #if defined(_WAN_MANAGER_ENABLED_) UtopiaValue_WanMode, UtopiaValue_WanConnEnabled,