This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Re: How to deconfigure an interface?


Tarmo Kuuse wrote:

> There could be a better way, but I just do SIOCGIFADDR to read the
> current addresses from an interface and delete them with SIOCDIFADDR. As
> input, the "struct ifreq" needs the interface's textual name (e.g.
> "eth0"). Works fine.

Yes, that's the same I'm doing now.

> Another task which needs doing is clearing the routes table. There
> exists a function "cyg_route_reinit()" which simply flushes all routes.
> Unfortunately it also deletes routes for the local loopback and all
> other interfaces you may have. I haven't yet figured out how to delete
> the routes only for a given interface.

I added such a function, it seems to work.


In net\common\current\include:

===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/common/current/include/network.h,v
retrieving revision 1.6
diff -u -r1.6 network.h
--- network.h   29 Jan 2009 17:49:57 -0000   1.6
+++ network.h   1 Sep 2009 09:36:34 -0000
@@ -68,6 +68,7 @@
 __externC void init_all_network_interfaces(void);

 __externC void     cyg_route_reinit(void);
+__externC void     cyg_route_reinit_iface(const char *);
 __externC void     perror(const char *) __THROW;
 __externC int      close(int);
 __externC ssize_t  read(int, void *, size_t);




In net\bsd_tcpip\current\src\sys\net:

===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/bsd_tcpip/current/src/sys/net/route.c,v
retrieving revision 1.5
diff -u -r1.5 route.c
--- route.c   29 Jan 2009 17:49:56 -0000   1.5
+++ route.c   1 Sep 2009 09:42:34 -0000
@@ -79,6 +79,8 @@
        struct sockaddr *, struct sockaddr *));
 static void rtable_init __P((void **));

+externC void if_indextoname(int indx, char *buf, int len);
+
 static void
 rtable_init(table)
    void **table;
@@ -116,6 +118,14 @@
 {
     struct rtentry *rt = (struct rtentry *)rn;
     if (rt->rt_ifa->ifa_addr->sa_family == AF_INET) {
+      int dodel = (vifp == NULL);
+      if (! dodel) {
+         char ifname[64];
+         if_indextoname(rt->rt_ifp->if_index, ifname, 64);
+         dodel = ! strcmp(ifname, (const char *) vifp);
+      }
+
+      if (dodel)
       rtrequest(RTM_DELETE, rt_key(rt), rt->rt_gateway, rt_mask(rt),
       0, NULL);
     }
@@ -135,6 +145,19 @@
     }
 }

+void
+cyg_route_reinit_iface(const char *iface)
+{
+    int i;
+    for (i = 0;  i < AF_MAX+1;  i++) {
+        struct radix_node_head *rnh;
+        rnh = rt_tables[i];
+        if (rnh) {
+            (*rnh->rnh_walktree)(rnh, rt_reinit_rtdelete, (void *) iface);
+        }
+    }
+}
+
 /*
  * Packet routing routines.
  */



Regards
-- 
                                         Stano

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]