[comp.protocols.tcp-ip.ibmpc] ka9q support for subnets

nerd@percival.rain.com (Michael Galassi) (05/19/91)

FRUTIG%BRLNCC@CUNYVM.CUNY.EDU writes:

>	I am using KA9Q (NOS) package as an IP gateway between
>	two Ethernets, but I am experimenting a routing problem.
>	This is the scene :

>                            KA9Q                   IP/X25
>	     Sun  Sun        PC              Sun-----------> world
>	      |    |       |    |             |
>	      --------------    ---------------
>		138.82.2	139.82.1

>	I have defined a default route in the configuration file, so
>	all the hosts on the 139.82.2 side can reach the world. But,
>	the problem is that the KA9Q gateway sends this route to
>	both subnets, changing the default route of the hosts at the
>	139.82.1 side, pointing it back to the KA9Q gateway !
>        I don't want to add a route explicitly at every host of
>	139.82.2 subnet, and want that KA9Q gateway continue to supply
>	its routing table to both subnets (see the rip add commands below).

>Any help/idea/suggestion would be GREAT ! Thanks in advance.

For starters KA9Q has some problems with subnets, if you issue a route
command you will notice that all known routes are either 32 bits (i.e.
a host address) or 8, 16, or 24 bits (bit aligned netmasks).  I fixed
this in rip.c and include a routine which fixes this at the end of this
post.

>attach packet 0x60 ec0 5 1500 [139.82.1.1]
>ifconfig ec0 ipaddr 139.82.1.1 netmask 0xffffffc0 broadcast 139.82.1.0
>#
>attach packet 0x61 ec1 5 1500 [139.82.2.1]
>ifconfig ec1 ipaddr 139.82.2.1 netmask 0xffffffc0 broadcast 139.82.2.0

It is my understanding that the broadcast address should be the address
in a subnet which has all the host bits set to 0.  In your case this
would make the above ifconfig lines read:
ifconfig ec0 ipaddr 139.82.1.1 netmask 0xffffffc0 broadcast 139.82.1.63
and
ifconfig ec1 ipaddr 139.82.2.1 netmask 0xffffffc0 broadcast 139.82.2.63

>route add 139.82.1.0/26 ec0
>route add 139.82.2.0/26 ec1

You don't need these, once you install the patches to rip.c the subnets
will have their routes added by rip working correctly.

>rip add 139.82.1.0 60
>rip add 139.82.2.0 60

You do want to do split horizon processing, this means you add a '1' to
the end of these two lines.  Also, you may want to change the 60s to 30s
to conform with section 3.5 of rfc1058, on an ether network the added
bandwith of the rip packets is negligible.

>rip merge on

Never used the merge command, so can't comment on it.  It does apear that
it would have no effect in your setup though.

These are the changes I made to the file rip.c from version 0420.  They
should apply fairly easily to 0423 as well (I think).  I'm a novice net-
hacker, if I 'done bad' please flame me by mail, don't post.  If you have
good advice, comments or questions I'd like to hear them too.

In the file rip.h change the declaration of nbits from:
int nbits __ARGS((int32 target));
to:
int nbits __ARGS((int32 target,int32 netmask));


In the file rip.c change the invocation of nbits from:
	bits = nbits(ep->target);
to:
	bits = nbits(ep->target, iface->netmask);

This is the only place this routine is called from in all ka9q.

Replace the whole nbits routine with what follows:
---- cut here for nbits() ----
/*
** An attempt is made to return valid lengths for subnets rather than treat
** anything other than a byte aligned net as a host.  The information used
** for this comes from rfc1058, specificaly the second half of section 3.2
** which speaks of the content of the "address" field of a RIP packet.  I
** do make an assumption about all subnets within a network being of the
** same size but this assumption is driven by the 3rd paragraph of section 3.
**
** Michael Galassi -- nerd@percival.rain.com -- 05/07/91
*/

int
nbits(target, netmask)
int32 target;
int32 netmask;
{
#define CLASS_A_BITS 0xff000000L	/* network bits in class A */
#define CLASS_B_BITS 0xffff0000L	/* network bits in class B */
#define CLASS_C_BITS 0xffffff00L	/* network bits in class C */

	if(target == 0)
		return(0);	/* Special case: 0 is the default route */
/*
** check network type (i.e. class A, B, or C), if host part is 0 then assume
** this is not subneted and return 24 for class C, 16 for a B and 8 for an A.
*/
	switch (hibyte(hiword(target)) >> 6) {
	case 3:	/* Class C address */
		if((target & ~(CLASS_C_BITS)) == 0)
			return(24);
		break;
	case 2:  /* Class B address */
		if((target & ~(CLASS_B_BITS)) == 0)
			return(16);
		break;
	case 0:	  /* Class A address */
	case 1:
		if((target & ~(CLASS_A_BITS)) == 0)
			return(8);
		break;
	}
/*
** If 'host' part is not 0 check if any bits are set in the host part for the
** interface this update came through.  If none are set then this is most
** likely a subnet in the same network as the interface it came in on and we
** can use the netmask of that interface.  Otherwise we assume we have a host
** route and treak all 32 bits as valid.  Note: the above assumption is but
** one of the many reasons we can't do variable size subnets with RIP. yuck
*/
	if ((target & ~(netmask)) == 0) {
/*
** Start with 32 bits, for each 0 on the end of the netmask we subtract one
** from the bitcount and shift the mask right to drop the 0 off the end.  This
** makes assumptions about the sequence of network and host bits in the
** netmask.  For RIP I can't envisions this not being an OK assumption.
*/
		register int bitcount = 32;
		while((netmask & 1) == 0) {
			--bitcount;
			netmask >>= 1;
		}
		return(bitcount);
	}
	else
		return(32);	/* if all else fails assume its a host */
}

---- cut here ----
-- 
Michael Galassi				| nerd@percival.rain.com
MS-DOS:  The ultimate PC virus.		| ...!tektronix!percy!nerd

nerd@percival.rain.com (Michael Galassi) (05/19/91)

nerd@percival.rain.com (Michael Galassi) writes:

>It is my understanding that the broadcast address should be the address
>in a subnet which has all the host bits set to 0.  In your case this
                                                ^
Oh what a dolt I am, servs me right for turning the brain off.  The '0'
above is suposed to be a '1' as has been pointed out to me. <blush>
-- 
Michael Galassi				| nerd@percival.rain.com
MS-DOS:  The ultimate PC virus.		| ...!tektronix!percy!nerd