Feature #4891

Handle gateway metric on OpenNebula vrouter (Alpine) - v 5.2

Added by Nicolas Belan almost 4 years ago. Updated over 3 years ago.

Status:ClosedStart date:11/03/2016
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Context
Target version:Release 5.4
Resolution:wontfix Pull request:

Description

Hi,
When using multiple network on vrouter, you may have multiple default gateway defined (1 per vnet)

To choose the right gateway, it is possible to set "metric", as in:

localhost:~# cat /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
  address 172.25.104.254
  network 172.25.104.0
  netmask 255.255.255.0
  gateway 172.25.104.254
  metric 1000

auto eth1
iface eth1 inet static
  address 172.25.101.201
  network 172.25.101.0
  netmask 255.255.0.0
  gateway 172.25.8.20
  metric 101

Metric may be set in context variable, and retrieve from context, using something like:

# Gets the gateway metric
get_metric() {
    if is_gateway; then
        metric=$(get_iface_var "METRIC")

        if [ -z "$metric" ]; then
            if [ "$DEV" = "eth0" ]; then
                metric=1000
            else
                metric=$((100+$IFACE_NUM))
            fi
        fi

        echo $metric
   fi
}

Using that code, by default, the second network interface is the default gateway (1=LAN, 2=WAN), and that can be change using ETH{X}_METRIC=10

Perhaps a hardcoded "eth0" is not correct; but this is a starting point.

Adding the right call "METRIC=$(get_metric)" in the interface loop, this makes the job for me :)

History

#1 Updated by Nicolas Belan almost 4 years ago

Here comes the full diff:

--- /etc/one-context.d/00-network.orig
+++ /etc/one-context.d/00-network
@@ -88,7 +88,23 @@
         echo $gateway
     fi
 }
+# Gets the gateway metric
+get_metric() {
+    if is_gateway; then
+        metric=$(get_iface_var "METRIC")

+        if [ -z "$metric" ]; then
+            if [ "$DEV" = "eth0" ]; then
+                metric=1000
+            else
+                metric=$((100+$IFACE_NUM))
+            fi
+        fi
+
+        echo $metric
+   fi
+}
+
 # Gets the network gateway6
 get_gateway6() {
     if is_gateway; then
@@ -147,6 +163,10 @@
         echo "  gateway $GATEWAY6" 
     fi

+    if [ -n "$METRIC" ]; then
+        echo "  metric $METRIC" 
+    fi
+
     echo "" 
 }

@@ -191,6 +211,7 @@
         MASK=$(get_mask)
         MTU=$(get_mtu)
         GATEWAY=$(get_gateway)
+        METRIC=$(get_metric)

         IPV6=$(get_iface_var "IPV6")
         [[ -z $IPV6 ]] && IPV6=$(get_iface_var "IP6")

#2 Updated by Ruben S. Montero almost 4 years ago

  • Status changed from Pending to New
  • Target version set to Release 5.4

#3 Updated by Ruben S. Montero over 3 years ago

  • Status changed from New to Closed
  • Resolution set to wontfix

Moved this issue to addon-alpine-context:

https://github.com/OpenNebula/addon-context-alpine/issues/5

Closing as "wontfix" to address this as part of the alpine distro

Also available in: Atom PDF