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

B #132: Sanitize/Check valid IPv4s #133

Open
wants to merge 1 commit into
base: master
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
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ is_link_local() {
get_onegate_ip() {
if [[ -n $ONEGATE_ENDPOINT ]]; then
# Regular expression to match an IPv4 address
ipv4_regex="([0-9]{1,3}\.){3}[0-9]{1,3}"
ipv4_regex="(([1-9]?[0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))\.){3}([1-9]?[0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))"

export onegate_host=$(echo "$ONEGATE_ENDPOINT" | grep -oE "$ipv4_regex")
fi
Expand All @@ -628,3 +628,7 @@ get_onegate_ip() {
missing_onegate_proxy_route() {
is_link_local "$onegate_host" && [[ $onegate_proxy_route_missing == "yes" ]]
}

valid_ipv4() {
[[ -n "$1" && "$1" =~ ^(([1-9]?[0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))\.){3}([1-9]?[0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))$ ]]
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ iface ${dev} inet static
netmask ${mask}
EOT

if [ -n "$gateway" ]; then
if valid_ipv4 $gateway; then
echo " gateway ${gateway}"

if [ -n "$metric" ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ EOT

echo "[Route]"

if [ -n "$gateway" ]; then
if valid_ipv4 $gateway; then
echo "Gateway=${gateway}"

if [ -n "$metric" ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ gen_iface_conf()
{
nmcli con mod "${dev}" ipv4.method manual ipv4.addresses "${ip}/${cidr}"

if [ -n "$gateway" ]; then
if valid_ipv4 $gateway; then
nmcli con mod "${dev}" ipv4.gateway "${gateway}"
else
nmcli con mod "${dev}" ipv4.gateway ""
Expand Down