[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
loopback interface
- Date: Mon, 13 Sep 1999 08:41:41 -0600
- From: eric at cls.usask.ca (Eric Norum)
- Subject: loopback interface
Thomas Doerfler wrote:
>
> Hello,
>
> I am currently finishing a project under rtems-4.0.0 using the
> gen68360 BSP. Today I wanted to add a function that connects to a
> local server (on the same RTEMS machine). I used the standard "local"
> IP address 127.0.0.1 and to my suprise I found that the standard
> "local loopback interface" was not installed on my machine. (I
> derived the network setup from some networking test code)
>
> Well, I tried to add the local loopback interface from if_loop.c, but
> get stuck with a rtems_panic stating, that during initialization
> setting the broadcast address fails.
>
> Before I fuzz around too long, maybe somebody can give me a hint on
> how to properly add the local loopback interface?
>
> I tried it the following way (except of my netconfig.h):
>
> ----- snip ---------------
> /*
> * Loopback network interface
> */
> int rtems_bsdnet_loopattach(struct rtems_bsdnet_ifconfig *);
> static struct rtems_bsdnet_ifconfig loopdriver_config = {
> "lo0", /* name */
> rtems_bsdnet_loopattach, /* attach function */
> NULL, /* link to next interface */
> "127.0.0.1", /* IP address */
> "255.0.0.0", /* IP net mask */
> NULL, /* Driver supplies hardware address */
> 0 /* Use default driver parameters */
> };
>
> /*
> * Default network interface
> */
> static struct rtems_bsdnet_ifconfig netdriver_config = {
> RTEMS_BSP_NETWORK_DRIVER_NAME, /* name */
> RTEMS_BSP_NETWORK_DRIVER_ATTACH, /* attach function */
>
> &loopdriver_config, /* link to next interface */
>
> #if (defined (RTEMS_USE_BOOTP))
> NULL, /* BOOTP supplies IP address */
> NULL, /* BOOTP supplies IP net mask */
> #else
> "192.168.64.40", /* IP address */
> "255.255.255.0", /* IP net mask */
> #endif /* !RTEMS_USE_BOOTP */
>
> #if (defined (RTEMS_SET_ETHERNET_ADDRESS))
> ethernet_address, /* Ethernet hardware address */
> #else
> NULL, /* Driver supplies hardware
> address */
> #endif
> 0 /* Use default driver parameters */
> };
>
> /*
> * Network configuration
> */
> struct rtems_bsdnet_config rtems_bsdnet_config = {
> &netdriver_config,
>
> #if (defined (RTEMS_USE_BOOTP))
> rtems_bsdnet_do_bootp,
> #else
> NULL,
> #endif
>
> 0, /* Default network task priority */
> 0, /* Default mbuf capacity */
> 0, /* Default mbuf cluster capacity */
>
> #if (!defined (RTEMS_USE_BOOTP))
> "mde360", /* Host name */
> "imd.m.isar.de", /* Domain name */
> "192.168.64.1", /* Gateway */
> "192.168.64.20", /* Log host */
> {"192.168.64.1" }, /* Name server(s) */
> #endif /* !RTEMS_USE_BOOTP */
>
> };
Your configuration is correct.
There's nothing special about the loopback interface. It should be
configured like any other interace. However, when I tried the above
configuration
out I found that it, as reported above, didn't work. The initialization
code tries
to set a broadcast
address for the loopback device and panics when this operation fails.
The fix is simple -- just change rtems_panic to a printf. The fix
for the infinite loop in rtems_bsdnet_show_if_stats is also simple
(it was due to a sign-extension problem). I've included both patches
as an attachment.
With the patches in place rtems_bsdnet_show_inet_routes() displays:
Destination Gateway/Mask/Hw Flags Refs Use Expire
Interface
default 128.233.14.100 UGS 0 0 0 scc1
127.0.0.1 127.0.0.1 UH 0 0 0 lo0
128.233.14.0 255.255.255.0 U 0 0 1 scc1
128.233.14.1 08:00:20:09:4A:02 UHL 0 1 1232 scc1
128.233.14.50 UHL 0 1 20 scc1
128.233.14.100 UHL 1 0 1 scc1
and rtems_bsdnet_show_if_stats() displays:
************ INTERFACE STATISTICS ************
***** scc1 *****
Address:128.233.14.105 Broadcast Address:128.233.14.255
Flags: Up Broadcast Running Simplex
Send queue limit:50 length:0 Dropped:0
Rx Interrupts:12 Not First:0 Not Last:0
Giant:0 Runt:0 Non-octet:0
Bad CRC:0 Overrun:0 Collision:0
Discarded:0
Tx Interrupts:0 Deferred:0 Missed Hearbeat:0
No Carrier:0 Retransmit Limit:0 Late Collision:0
Underrun:0 Raw output wait:0
***** lo0 *****
Address:127.0.0.1
Flags: Up Loopback Running Multicast
Send queue limit:0 length:0 Dropped:0
--
Eric Norum eric at cls.usask.ca
Canadian Light Source Phone: (306) 966-6308
University of Saskatchewan FAX: (306) 966-6058
Saskatoon, Canada.
-------------- next part --------------
Changes:
rtems_glue.c
Failure to set interface broacast address is no longer fatal.
rtems_showifstat.c
Avoid infinite loop when showing flags (sign-extension problem).
diff -ur rtems-19990820.orig/c/src/lib/libnetworking/rtems/rtems_glue.c rtems-19990820/c/src/lib/libnetworking/rtems/rtems_glue.c
--- rtems-19990820.orig/c/src/lib/libnetworking/rtems/rtems_glue.c Fri Jun 11 08:11:44 1999
+++ rtems-19990820/c/src/lib/libnetworking/rtems/rtems_glue.c Sun Sep 12 17:10:39 1999
@@ -809,7 +809,7 @@
broadcast.sin_addr.s_addr = address.sin_addr.s_addr | ~netmask.sin_addr.s_addr;
memcpy (&ifreq.ifr_broadaddr, &broadcast, sizeof broadcast);
if (ioctl (s, SIOCSIFBRDADDR, &ifreq) < 0)
- rtems_panic ("Can't set %s broadcast address: %s", ifp->name, strerror (errno));
+ printf ("Can't set %s broadcast address: %s\n", ifp->name, strerror (errno));
}
/*
diff -ur rtems-19990820.orig/c/src/lib/libnetworking/rtems/rtems_showifstat.c rtems-19990820/c/src/lib/libnetworking/rtems/rtems_showifstat.c
--- rtems-19990820.orig/c/src/lib/libnetworking/rtems/rtems_showifstat.c Thu Aug 20 15:56:25 1998
+++ rtems-19990820/c/src/lib/libnetworking/rtems/rtems_showifstat.c Sun Sep 12 20:03:49 1999
@@ -37,7 +37,7 @@
{
struct ifnet *ifp;
struct ifaddr *ifa;
- unsigned int bit, flags;
+ unsigned short bit, flags;
int printed;
printf ("************ INTERFACE STATISTICS ************\n");
@@ -57,8 +57,9 @@
printf ("Flags:");
for (bit = 1, flags = ifp->if_flags ; flags ; bit <<= 1) {
char *cp;
+ char xbuf[20];
switch (flags & bit) {
- default: cp = NULL; break;
+ case 0: cp = NULL; break;
case IFF_UP: cp = "Up"; break;
case IFF_BROADCAST: cp = "Broadcast"; break;
case IFF_DEBUG: cp = "Debug"; break;
@@ -74,6 +75,7 @@
case IFF_LINK1: cp = "Link1"; break;
case IFF_LINK2: cp = "Link2"; break;
case IFF_MULTICAST: cp = "Multicast"; break;
+ default: sprintf (xbuf, "%#x", bit); cp = xbuf; break;
}
if (cp) {
flags &= ~bit;