Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge issue/325 into v0.65 #391

Open
wants to merge 3 commits into
base: v0.65
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

[//]: # (END_SECTION HEADER)
[//]: # (START_SECTION COMMITS
7287564593dd788bdfc5e3472cca0bd89b84a4bc
d8ac84aa08a89a604320df81870c18c734f8fdf0
3893533afbfaf9d5aedb02b45688ac94920cbd4f
f8bfe45b3cc64e49d3decc0adb7a10f493ff22a0
Expand Down Expand Up @@ -1969,6 +1970,32 @@ a72121b9551921aa3dced32d943c6034ba318f82
ce6c5aac0db5476dc496c34388e4f9ce2c4b86e5
b46b1e64f06f448bde78b98e3ae8228ce5f96067
END_SECTION COMMITS)
[//]: # (START_SECTION 7287564593dd788bdfc5e3472cca0bd89b84a4bc)
### Improved DNS Hostname Resolution And Caching

> Commit: [7287564593dd788bdfc5e3472cca0bd89b84a4bc](https://github.com/dOpensource/dsiprouter/commit/7287564593dd788bdfc5e3472cca0bd89b84a4bc)
> Date: Thu, 1 Jul 2021 12:25:12 -0400
> Author: Tyler Moore ([email protected])
> Committer: Tyler Moore ([email protected])
> Signed: Tyler Moore (devopsec) <[email protected]>


- Resolves [#325](https://github.com/dOpensource/dsiprouter/issues/325)
- implement new caching system via cronjob
- update dr_gateways DNS names to resolve to all available IP's
- update uacreg DNS names to resolve to all available IP's
- update DNS names every 5 minutes
- update backend to transparently access/store JSON in description/tag fields
- update all other tables to use new schema for JSON storage
- move local address to cron updated entry in address table
- add FLT_INTERNAL flag for internal use addresses
- add/update a few utility functions to `dsip_lib.sh`
- update default imports to use new JSON structure


---

[//]: # (END_SECTION 7287564593dd788bdfc5e3472cca0bd89b84a4bc)
[//]: # (START_SECTION d8ac84aa08a89a604320df81870c18c734f8fdf0)
### Fix Bug In Commit 9e7949a

Expand Down
232 changes: 212 additions & 20 deletions dsiprouter.sh

Large diffs are not rendered by default.

56 changes: 50 additions & 6 deletions dsiprouter/dsip_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -170,25 +170,25 @@ function decryptConfigAttrib() {
}
export -f decryptConfigAttrib

# $1 == attribute name
# $1 == feature name
# $2 == kamailio config file
function enableKamailioConfigAttrib() {
function enableKamailioConfigFeature() {
local NAME="$1"
local CONFIG_FILE="$2"

sed -i -r -e "s~#+(!(define|trydef|redefine)[[:space:]]? $NAME)~#\1~g" ${CONFIG_FILE}
}
export -f enableKamailioConfigAttrib
export -f enableKamailioConfigFeature

# $1 == attribute name
# $1 == feature name
# $2 == kamailio config file
function disableKamailioConfigAttrib() {
function disableKamailioConfigFeature() {
local NAME="$1"
local CONFIG_FILE="$2"

sed -i -r -e "s~#+(!(define|trydef|redefine)[[:space:]]? $NAME)~##\1~g" ${CONFIG_FILE}
}
export -f disableKamailioConfigAttrib
export -f disableKamailioConfigFeature

# $1 == name of defined url to change
# $2 == value to change url to
Expand All @@ -204,6 +204,24 @@ function setKamailioConfigDburl() {
}
export -f setKamailioConfigDburl

# $1 == name of define to change
# $2 ==
# $3 == kamailio config file
# $4 == -q (quote as string)
function setKamailioConfigDef() {
local NAME="$1"
local VALUE="$2"
local CONFIG_FILE="$3"

if [[ "$4" == "-q" ]]; then
VALUE='"'"${VALUE}"'"'
fi

perl -e "\$name='${NAME}'; \$value='${VALUE}';" \
-i -pe 's%(#+\!)(define|trydef|redefine)([ \t]+${name}[ \t]+).*%\1\2\3${value}%g' ${CONFIG_FILE}
}
export -f setKamailioConfigDef

# $1 == name of substdef to change
# $2 == value to change substdef to
# $3 == kamailio config file
Expand Down Expand Up @@ -388,6 +406,8 @@ export -f ipv6Test
# notes: prints internal ip, or empty string if not available
# notes: tries ipv4 first then ipv6
function getInternalIP() {
local IPV6_ENABLED=${IPV6_ENABLED:-0}

local IP=$(ip -4 route get $GOOGLE_DNS_IPV4 2>/dev/null | head -1 | grep -oP 'src \K([^\s]+)')
if (( ${IPV6_ENABLED} == 1 )) && [[ -z "$IP" ]]; then
IP=$(ip -6 route get $GOOGLE_DNS_IPV6 2>/dev/null | head -1 | grep -oP 'src \K([^\s]+)')
Expand Down Expand Up @@ -470,11 +490,14 @@ export -f getInternalFQDN
# notes: will use EXTERNAL_IP if available or look it up dynamically
# notes: tries ipv4 first then ipv6
function getExternalFQDN() {
local IPV6_ENABLED=${IPV6_ENABLED:-0}

local EXTERNAL_IP=${EXTERNAL_IP:-$(getExternalIP)}
local EXTERNAL_FQDN=$(dig @${GOOGLE_DNS_IPV4} +short -x ${EXTERNAL_IP} 2>/dev/null | head -1 | sed 's/\.$//')
if (( ${IPV6_ENABLED} == 1 )) && [[ -z "$EXTERNAL_FQDN" ]]; then
EXTERNAL_FQDN=$(dig @${GOOGLE_DNS_IPV6} +short -x ${EXTERNAL_IP} 2>/dev/null | head -1 | sed 's/\.$//')
fi

printf '%s' "$EXTERNAL_FQDN"
}
export -f getExternalFQDN
Expand All @@ -483,6 +506,7 @@ export -f getExternalFQDN
# notes: prints internal CIDR address, or empty string if not available
# notes: tries ipv4 first then ipv6
function getInternalCIDR() {
local IPV6_ENABLED=${IPV6_ENABLED:-0}
local PREFIX_LEN="" DEF_IFACE=""
local IP=$(ip -4 route get $GOOGLE_DNS_IPV4 2>/dev/null | head -1 | grep -oP 'src \K([^\s]+)')

Expand All @@ -505,6 +529,26 @@ function getInternalCIDR() {
}
export -f getInternalCIDR

# $1 == host to resolve
# $2 == -a (return all resolved IPs)
# output: IP address(es) of host
function hostToIP() {
local IPV6_ENABLED=${IPV6_ENABLED:-0}
local HOST="$1"

local IP_ADDR=$(dig @${GOOGLE_DNS_IPV4} +short A ${HOST} 2>/dev/null)
if (( ${IPV6_ENABLED} == 1 )) && [[ -z "$EXTERNAL_FQDN" ]]; then
IP_ADDR=$(dig @${GOOGLE_DNS_IPV6} +short AAAA ${HOST} 2>/dev/null | head -1 | sed 's/\.$//')
fi

if [[ "$2" == "-a" ]]; then
echo -n "$IP_ADDR"
else
echo -n "$IP_ADDR" | head -1
fi
}
export -f hostToIP

# $1 == cmd as executed in systemd (by ExecStart=)
# notes: take precaution when adding long running functions as they will block startup in boot order
# notes: adding init commands on an AMI instance must not be long running processes, otherwise they will fail
Expand Down
Loading