* [ECOS] How to deconfigure an interface? @ 2009-08-31 16:58 Stanislav Meduna 2009-09-01 8:59 ` [ECOS] " Tarmo Kuuse 0 siblings, 1 reply; 4+ messages in thread From: Stanislav Meduna @ 2009-08-31 16:58 UTC (permalink / raw) To: eCos Discussion Hi, I'd like to be able to change an IP address of an interface without reboot. The comment at init_net says // [Re]initialize the network interface with the info passed from BOOTP however, the new provided address is _added_ to the interface and the interface responds to both old and new IP address afterwards. The same happens if I try to set the address using SIOCSIFADDR. Is this the intended behaviour? Shouldn't the SIFADDR change the address and AIFADDR add a new one? Is there a way to bring the IP stack back to the clean state, or does one needs to deconfigure the interface step-by step by removing addresses already configured using SIOCDIFADDR (which works)? I tried to look at the bootp code, but my suspicion is that if the BOOTP server assigns a new address, the same thing will happen - I do not have the environment to confirm this. I am using the FreeBSD networking stack. Thanks -- 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [ECOS] Re: How to deconfigure an interface? 2009-08-31 16:58 [ECOS] How to deconfigure an interface? Stanislav Meduna @ 2009-09-01 8:59 ` Tarmo Kuuse 2009-09-01 9:59 ` Stanislav Meduna 0 siblings, 1 reply; 4+ messages in thread From: Tarmo Kuuse @ 2009-09-01 8:59 UTC (permalink / raw) To: ecos-discuss Hi Stanislav, Stanislav Meduna wrote: > I'd like to be able to change an IP address of an interface > without reboot. Same here. > The same happens if I try to set the address using SIOCSIFADDR. > Is this the intended behaviour? Shouldn't the SIFADDR > change the address and AIFADDR add a new one? I think it's intended behaviour. > Is there a way to bring the IP stack back to the clean > state, or does one needs to deconfigure the interface > step-by step by removing addresses already configured > using SIOCDIFADDR (which works)? 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. 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. Have a look at function do_dhcp_down_net() in dhcp_prot.c for an example. -- Kind regards, Tarmo Kuuse -- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [ECOS] Re: How to deconfigure an interface? 2009-09-01 8:59 ` [ECOS] " Tarmo Kuuse @ 2009-09-01 9:59 ` Stanislav Meduna 2009-09-01 13:59 ` Tarmo Kuuse 0 siblings, 1 reply; 4+ messages in thread From: Stanislav Meduna @ 2009-09-01 9:59 UTC (permalink / raw) To: Tarmo Kuuse, eCos Discussion 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [ECOS] Re: How to deconfigure an interface? 2009-09-01 9:59 ` Stanislav Meduna @ 2009-09-01 13:59 ` Tarmo Kuuse 0 siblings, 0 replies; 4+ messages in thread From: Tarmo Kuuse @ 2009-09-01 13:59 UTC (permalink / raw) To: ecos-discuss Stanislav Meduna wrote: > Tarmo Kuuse wrote: >> 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. Thank you, that was a very handy piece of code. -- Kind regards, Tarmo Kuuse -- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-09-01 13:59 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2009-08-31 16:58 [ECOS] How to deconfigure an interface? Stanislav Meduna 2009-09-01 8:59 ` [ECOS] " Tarmo Kuuse 2009-09-01 9:59 ` Stanislav Meduna 2009-09-01 13:59 ` Tarmo Kuuse
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).