From mboxrd@z Thu Jan 1 00:00:00 1970 From: Grant Edwards To: Nick Barnes Cc: bartv@redhat.com, ecos-discuss@sourceware.cygnus.com Subject: Re: [ECOS] Notes on static configuration of an eCos network interface Date: Tue, 18 Jul 2000 08:03:00 -0000 Message-id: <20000718150357.A2075@visi.com> References: <200007171359.OAA06167@sheesh.cygnus.co.uk> <145.963924726@raven.ravenbrook.com> X-SW-Source: 2000-07/msg00168.html On Tue, Jul 18, 2000 at 01:52:06PM +0100, Nick Barnes wrote: > > Instead you could have an upper bound on the number of such routes and > > have the appropriate number of config options. Or you could put > > multiple routes into one configuration value, although extracting all > > the information at compile-time can then prove tricky. Alternatively > > the configury would support only the most common situation of a single > > route, with an opt-out to defer the whole thing to application code. > > I am not sure which of these approaches would be most appropriate in > > this case. > > Either way. This isn't very important to me. > > Another option would be to have a single string option for additional > static routes, which is then parsed in network_support.c. > > It's an interesting problem. As other writers have pointed out, > there's a case for taking this out of the kernel configuration > altogether. It's handy having a default configuration when writing test programs, but my real applications will all configure the network "manually", since I don't know until run-time whether to use bootp/DHCP or not. > For my project I'm now intending to use the ioctl()s > directly, and never call init_all_network_interfaces(). Yesterday I changed over to calling the ioctl()s directly. So far it seems to be working. The eCos system is trying to use the router I configure, but I don't have one on the network right now, so I've got to set up one of my Linux machines as a router to make sure. FWIW, here's the init code I'm using: void StackInit( void ) { int s,rc; struct sockaddr_in *addrp; struct ifreq ifr; int one = 1; struct ecos_rtentry route; #ifdef MTM_NET_DEBUG extern int net_debug; net_debug = 1; #endif if ( DhcpData.MyIpAddr == 0 ) // not gonna do ip return; s = socket(AF_INET, SOCK_DGRAM, 0); if (s < 0) { diag_printf("socket: %d\n",s); return; } if ((rc=setsockopt(s, SOL_SOCKET, SO_BROADCAST, &one, sizeof(one)))) { diag_printf("setsockopt: %d\n",rc); close(s); return; } strcpy(ifr.ifr_name, "eth0"); addrp = (struct sockaddr_in *) &ifr.ifr_addr; memset(addrp, 0, sizeof(*addrp)); addrp->sin_family = AF_INET; addrp->sin_len = sizeof(*addrp); addrp->sin_port = 0; addrp->sin_addr.s_addr = DhcpData.MyIpAddr; if ((rc=ioctl(s, SIOCSIFADDR, &ifr))) { diag_printf("SIOCSIFADDR: %d\n",rc); close(s); return; } addrp->sin_addr.s_addr = DhcpData.SubnetMask; if ((rc=ioctl(s, SIOCSIFNETMASK, &ifr))) { diag_printf("SIOCSIFNETMASK: %d\n",rc); close(s); return; } addrp->sin_addr.s_addr = ~DhcpData.SubnetMask | DhcpData.Subnet; if ((rc=ioctl(s, SIOCSIFBRDADDR, &ifr))) { diag_printf("SIOCSIFBRDADDR: %d\n",rc); close(s); return; } // Set up routing diag_printf(" IP = %08x\n", DhcpData.MyIpAddr); diag_printf(" Mask = %08x\n", DhcpData.SubnetMask); diag_printf(" Gate = %08x\n", DhcpData.Gateways[0]); memset(&route, 0, sizeof(route)); addrp->sin_addr.s_addr = 0; memcpy(&route.rt_dst, addrp, sizeof(*addrp)); memcpy(&route.rt_genmask, addrp, sizeof(*addrp)); addrp->sin_addr.s_addr = DhcpData.Gateways[0]; memcpy(&route.rt_gateway, addrp, sizeof(*addrp)); route.rt_dev = ifr.ifr_name; route.rt_flags = RTF_UP|RTF_GATEWAY; route.rt_metric = 0; if ((rc=ioctl(s, SIOCADDRT, &route))) diag_printf("Route Failed: %d\n",rc); else { diag_printf("Net init complete.\n"); StackOk = 1; } close(s); } -- Grant Edwards grante@visi.com