<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 10 (filtered)">
<style>
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman";}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{color:purple;
text-decoration:underline;}
pre
{margin:0cm;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";}
span.EmailStyle17
{font-family:Arial;
color:windowtext;}
@page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
</style>
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>Hi RTEMS Users,</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> </span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>I was having the same problem that Alex Zolotov had
in message <a
href="http://www.rtems.com/ml/rtems-users/2008/january/msg00062.html">http://www.rtems.com/ml/rtems-users/2008/january/msg00062.html</a>
regarding multiple interfaces in the same subnet. I can’t find a reply or
solution to his post.</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> </span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>We have 2 physical interfaces on the same subnet
(for redundancy not load sharing).</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>eth0 192.168.65.32 255.255.255.0</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>eth1 192.168.65.33 255.255.255.0</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> </span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>Eth0 inits fine but then the following errors
messages are displayed:</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>Can't set eth1 address: File exists</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>Can't set eth2 address: File exists</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>(Which corresponds to EEXIST.)</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> </span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>The error message immediately comes from:</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>rtems_glue.c: rtems_bsdnet_setup() Code attached below</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>and further down</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>route.c: rtrequest() Code attached below</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> </span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>I think it is when BSDnet is trying to add the
following entries to the route table:</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>192.168.65.0
255.255.255.0
U
0 0 14 eth0</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> </span></font></p>
<pre><font size=2 face="Courier New"><span style='font-size:10.0pt'>It should be noted that the latest BSDnet code in in.c (<a
href="http://www.freebsd.org/cgi/cvsweb.cgi/~checkout~/src/sys/netinet/in.c?rev=1.102.2.1;content-type=text%2Fplain">http://www.freebsd.org/cgi/cvsweb.cgi/~checkout~/src/sys/netinet/in.c?rev=1.102.2.1;content-type=text%2Fplain</a>) differs in the function in_ifinit() from even the latest RTEMS code. Tt has a new function in_addprefix() which searches for existing entries in the route table and the does nothing if it is a duplicate. This function is called in place of rtinit() but will call rtinit() if no route entry has been found.</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>See latest RTEMS in.c : in_ifinit() Code attached below</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>See latest bsdnet (Note that I modified it slightly to work with RTEMS) Code attached below</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>This *patch* allows bsdnet to successful initialize without errors. </span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>However, this causes the next problem. It seems all packets are sent from the eth0 interface. This has been tested in the following ways:</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>* </span></font>Ping from an external host to 192.168.65.34 (eth1) only returns when the eth0 cable is plugged in</pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>* The replies to the ping (when the cable is in) from eth1 have the eth0 MAC address</span></font></pre>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>* Any packets generated by the card always have eth0
MAC address (eg open a socket and bind to the eth1 address and then send
… packets have the eth1 ip but have the eth0 MAC)</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> </span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>Is this behavior as expected? I think so as only
eth0 will have a route.</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> </span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>So I wrote a quick custom patch for bsdnet ip_output.c
ip_output() which searches through the interface addresses and tries to match
the packet header ip src and address. Then it ‘corrects’ the ia and
ifp pointers.</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> </span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> /*</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> * If routing to
interface only,</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> * short circuit
routing lookup.</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> */</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>#define ifatoia(ifa) ((struct in_ifaddr
*)(ifa))</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>#define sintosa(sin) ((struct sockaddr
*)(sin))</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> if (flags &
IP_ROUTETOIF) {</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> if
((ia = ifatoia(ifa_ifwithdstaddr(sintosa(dst)))) == 0 &&</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
(ia = ifatoia(ifa_ifwithnet(sintosa(dst)))) == 0) {</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> ipstat.ips_noroute++;</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> error
= ENETUNREACH;</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> goto
bad;</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> }</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> ifp
= ia->ia_ifp;</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> ip->ip_ttl
= 1;</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> isbroadcast
= in_broadcast(dst->sin_addr, ifp);</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> } else {</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> /*</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> *
If this is the case, we probably don't want to allocate</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> *
a protocol-cloned route since we didn't get one from the</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> *
ULP. This lets TCP do its thing, while not burdening</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> *
forwarding or ICMP with the overhead of cloning a route.</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> *
Of course, we still want to do any cloning requested by</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> *
the link layer, as this is probably required in all cases</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> *
for correct operation (as it is for ARP).</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> */</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> if
(ro->ro_rt == 0)</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> rtalloc_ign(ro,
RTF_PRCLONING);</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> if
(ro->ro_rt == 0) {</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> ipstat.ips_noroute++;</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> error
= EHOSTUNREACH;</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> goto
bad;</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> }</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> ia
= ifatoia(ro->ro_rt->rt_ifa);</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> ifp
= ro->ro_rt->rt_ifp;</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>-- patch start --</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> /* dball:
Note custom patch here</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> *
Use the user ip src address to search through the interfaces</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> * to
find the 'right' interface to send from.</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> */</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> struct in_ifaddr
*ia_search = ia;</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> do {</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
if (Bcmp((void *) &ip->ip_src,</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
(void *) &IA_SIN(ia_search)->sin_addr,</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
IA_SIN(ia_search)->sin_len) == 0) {</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
ia = ia_search;</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
ifp = ia_search->ia_ifp;</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
break;</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
}</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> }
while ( (ia_search = ia_search->ia_next) != 0);</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>-- patch end --</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> ro->ro_rt->rt_use++;</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> if
(ro->ro_rt->rt_flags & RTF_GATEWAY)</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> dst
= (struct sockaddr_in *)ro->ro_rt->rt_gateway;</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> if
(ro->ro_rt->rt_flags & RTF_HOST)</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> isbroadcast
= (ro->ro_rt->rt_flags & RTF_BROADCAST);</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> else</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> isbroadcast
= in_broadcast(dst->sin_addr, ifp);</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> }</span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> </span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>This makes it work as I want with the packets been sent from the
correct physical interfaces and having the correct MAC addresses. (Note that I
know it isn’t a complete solution, eg I really should search for all
addresses attached to each interface)</span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> </span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>What do you think of this patch?</span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> </span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>I am on RTEMS 4.7 (with many imported patches),
PowerPC BSP.</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> </span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>Regards,</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>David Ball</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> </span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> </span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>rtems_glue.c: rtems_bsdnet_setup()</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>**</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
/*</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
* Set interface address</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
*/</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
memset (&address, '\0', sizeof address);</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
address.sin_len = sizeof address;</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
address.sin_family = AF_INET;</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
address.sin_addr.s_addr = inet_addr (ifp->ip_address);</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
if (rtems_bsdnet_ifconfig (ifp->name, SIOCSIFADDR, &address) < 0) {</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
printf ("Can't set %s address: %s\n", ifp->name, strerror (errno));</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
continue;</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
}</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>**</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> </span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>route.c: rtrequest</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>**</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
/*</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
* This moved from below so that rnh->rnh_addaddr() can</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
* examine the ifa and ifp if it so desires.</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
*/</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
ifa->ifa_refcnt++;</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
rt->rt_ifa = ifa;</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
rt->rt_ifp = ifa->ifa_ifp;</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> </span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
rn = rnh->rnh_addaddr((caddr_t)ndst, (caddr_t)netmask,</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
rnh, rt->rt_nodes);</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
if (rn == 0) {</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
struct rtentry *rt2;</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
/*</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
* Uh-oh, we already have one of these in the tree.</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
* We do a special hack: if the route that's already</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
* there was generated by the protocol-cloning</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
* mechanism, then we just blow it away and retry</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
* the insertion of the new one.</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
*/</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
rt2 = rtalloc1(dst, 0, RTF_PRCLONING);</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
if (rt2 && rt2->rt_parent) {</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
rtrequest(RTM_DELETE, </span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
(struct sockaddr *)rt_key(rt2),</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
rt2->rt_gateway,</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
rt_mask(rt2), rt2->rt_flags, 0);</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
RTFREE(rt2);</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
rn = rnh->rnh_addaddr((caddr_t)ndst,</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
(caddr_t)netmask,</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
rnh, rt->rt_nodes);</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
} else if (rt2) {</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
RTFREE(rt2);</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
}</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
}</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'> </span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
if (rn == 0) {</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
if (rt->rt_gwroute)</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
rtfree(rt->rt_gwroute);</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
if (rt->rt_ifa) {</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
IFAFREE(rt->rt_ifa);</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
}</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
Free(rt_key(rt));</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
Free(rt);</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
senderr(EEXIST);</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>
}</span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>**</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> </span></font></p>
<pre><font size=2 face="Courier New"><span style='font-size:10.0pt'>RTEMS in.c : in_ifinit()</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> /*</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> * Add route for the network.</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> */</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> ia->ia_ifa.ifa_metric = ifp->if_metric;</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> if (ifp->if_flags & IFF_BROADCAST) {</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> ia->ia_broadaddr.sin_addr.s_addr =</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> htonl(ia->ia_subnet | ~ia->ia_subnetmask);</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> ia->ia_netbroadcast.s_addr =</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> htonl(ia->ia_net | ~ ia->ia_netmask);</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> } else if (ifp->if_flags & IFF_LOOPBACK) {</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> ia->ia_ifa.ifa_dstaddr = ia->ia_ifa.ifa_addr;</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> flags |= RTF_HOST;</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> } else if (ifp->if_flags & IFF_POINTOPOINT) {</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> if (ia->ia_dstaddr.sin_family != AF_INET)</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> return (0);</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> flags |= RTF_HOST;</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> }</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> if ((error = rtinit(&(ia->ia_ifa), (int)RTM_ADD, flags)) == 0)</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> ia->ia_flags |= IFA_ROUTE;</span></font></pre>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> </span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> </span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>in.c in_ifinit() (</span></font>Latest bsdnet (Note that I
modified it slightly to work with RTEMS))</p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>**</span></font></p>
<pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> /*</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> * Add route for the network.</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> */</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> ia->ia_ifa.ifa_metric = ifp->if_metric;</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> if (ifp->if_flags & IFF_BROADCAST) {</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> ia->ia_broadaddr.sin_addr.s_addr =</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> htonl(ia->ia_subnet | ~ia->ia_subnetmask);</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> ia->ia_netbroadcast.s_addr =</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> htonl(ia->ia_net | ~ ia->ia_netmask);</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> } else if (ifp->if_flags & IFF_LOOPBACK) {</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> ia->ia_dstaddr = ia->ia_addr;</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> flags |= RTF_HOST;</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> } else if (ifp->if_flags & IFF_POINTOPOINT) {</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> if (ia->ia_dstaddr.sin_family != AF_INET)</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> return (0);</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> flags |= RTF_HOST;</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> }</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> if ((error = in_addprefix(ia, flags)) != 0)</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> return (error);</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>--- snip ---</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>#define rtinitflags(x) \</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> ((((x)->ia_ifp->if_flags & (IFF_LOOPBACK | IFF_POINTOPOINT)) != 0) \</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> ? RTF_HOST : 0)</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>/*</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> * Check if we have a route for the given prefix already or add one accordingly.</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> */</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>static int</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>in_addprefix(struct in_ifaddr *target, int flags)</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>{</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> struct in_ifaddr *ia;</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> struct in_addr prefix, mask, p, m;</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> int error;</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> if ((flags & RTF_HOST) != 0) {</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> prefix = target->ia_dstaddr.sin_addr;</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> mask.s_addr = 0;</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> } else {</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> prefix = target->ia_addr.sin_addr;</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> mask = target->ia_sockmask.sin_addr;</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> prefix.s_addr &= mask.s_addr;</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> }</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> for (ia = in_ifaddr; ia; ia = ia->ia_next) {</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> if (rtinitflags(ia)) {</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> p = ia->ia_addr.sin_addr;</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> if (prefix.s_addr != p.s_addr)</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> continue;</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> } else {</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> p = ia->ia_addr.sin_addr;</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> m = ia->ia_sockmask.sin_addr;</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> p.s_addr &= m.s_addr;</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> if (prefix.s_addr != p.s_addr ||</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> mask.s_addr != m.s_addr)</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> continue;</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> }</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> /*</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> * If we got a matching prefix route inserted by other</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> * interface address, we are done here.</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> */</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> if (ia->ia_flags & IFA_ROUTE) {</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> return (0);</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> }</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> }</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> /*</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> * No-one seem to have this prefix route, so we try to insert it.</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> */</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> error = rtinit(&target->ia_ifa, (int)RTM_ADD, flags);</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> if (!error)</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> target->ia_flags |= IFA_ROUTE;</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> return error;</span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>}</span></font></pre>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>**</span></font></p>
</div>
</body>
</html>