From: Joan Lledó <[email protected]>

---
 lwip/iioctl-ops.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/lwip/iioctl-ops.c b/lwip/iioctl-ops.c
index fcdca865..bfc0ccc2 100644
--- a/lwip/iioctl-ops.c
+++ b/lwip/iioctl-ops.c
@@ -170,6 +170,19 @@ siocsifXaddr (struct sock_user *user,
   return err;
 }
 
+static void
+clear_gateways (void *arg)
+{
+  struct netif *netif;
+  struct ip4_addr gw;
+
+  gw.addr = INADDR_NONE;
+  NETIF_FOREACH (netif)
+  {
+    netif_set_gw (netif, &gw);
+  }
+}
+
 static void
 set_default_if (void *arg)
 {
@@ -255,6 +268,14 @@ lwip_S_rioctl_siocaddrt (struct sock_user *user,
          (ipv4_addrs[ADDR] & ipv4_addrs[NETMASK]))
        return EHOSTUNREACH;
 
+      /*
+       * Since we only allow setting a gateway when it will become the default 
gateway,
+       * any existing gateway must have been previously set as the default. 
However, there
+       * can only be one default gateway at a time, so we must clear any 
existing gateways
+       * before setting the new one.
+       */
+      tcpip_callback (clear_gateways, NULL);
+
       ipv4_addrs[GWADDR] = route.rt_gateway;
       tcpip_callback (set_default_if, netif);
     }
-- 
2.50.1


Reply via email to