home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume40 / ipp / part04 < prev    next >
Text File  |  1993-11-24  |  67KB  |  2,021 lines

  1. Newsgroups: comp.sources.misc
  2. From: db15@ukc.ac.uk (Damiano Bolla)
  3. Subject: v40i162:  ipp - IPP Routing Architecture Toolkit, Part04/06
  4. Message-ID: <1993Nov24.193828.7704@sparky.sterling.com>
  5. X-Md4-Signature: e42d34231a50290a9467ee2b26e79fd8
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Computing Lab, University of Kent at Canterbury, UK.
  8. Date: Wed, 24 Nov 1993 19:38:28 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: db15@ukc.ac.uk (Damiano Bolla)
  12. Posting-number: Volume 40, Issue 162
  13. Archive-name: ipp/part04
  14. Environment: INET
  15.  
  16. #! /bin/sh
  17. # This is a shell archive.  Remove anything before this line, then feed it
  18. # into a shell via "sh file" or similar.  To overwrite existing files,
  19. # type "sh file -c".
  20. # Contents:  IPP/config/ex1/16config IPP/config/ex1/config
  21. #   IPP/config/ex2/2config IPP/config/ex2/3config
  22. #   IPP/config/ex2/5config IPP/ethernet/Tnet.c IPP/host/HostInit.c
  23. #   IPP/include/packet.h IPP/lib/route/FindParentRoute.c
  24. #   IPP/lib/route/FindSubnetRoute.c IPP/lib/route/RouteMgr.c
  25. #   IPP/lib/utils/Connect.c IPP/lib/utils/Debug.c
  26. #   IPP/monitor/monitor.c IPP/router/ParseData.c
  27. #   IPP/router/ParsePack.c IPP/router/ProcessPack.c
  28. #   IPP/router/README_config IPP/router/TableInit.c
  29. #   IPP/router/router.c
  30. # Wrapped by kent@sparky on Wed Nov 24 11:51:02 1993
  31. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  32. echo If this archive is complete, you will see the following message:
  33. echo '          "shar: End of archive 4 (of 6)."'
  34. if test -f 'IPP/config/ex1/16config' -a "${1}" != "-c" ; then 
  35.   echo shar: Will not clobber existing file \"'IPP/config/ex1/16config'\"
  36. else
  37.   echo shar: Extracting \"'IPP/config/ex1/16config'\" \(2047 characters\)
  38.   sed "s/^X//" >'IPP/config/ex1/16config' <<'END_OF_FILE'
  39. X# The config file is quite strict in terms of layout, Comments MUST start with a #
  40. X# You cannot place comments anywhere you want...
  41. X# You are allowed blank lines...
  42. X# ONLY spaces are allowed as separators...
  43. X# The FIRST thing you have to write is the address of the router.,
  44. X
  45. XAddress 16
  46. X
  47. X# The n you have to write the interface specification.. the thing begins with
  48. X# a special keyword... otherwise it is too complicated.
  49. X# The other thing is tha all parameters fit in one line... in the following order
  50. X# Number LinkType Listen Parameters
  51. X
  52. XInterface 1 sock no localhost 1031
  53. X
  54. X#Interface 1 sock yes
  55. XInterface 2 sock yes
  56. XInterface 3 sock yes
  57. XInterface 4 sock yes
  58. X
  59. X# Routing gets more complicated....
  60. X# If a routing entry overwrite another one a WARNING message will follow !
  61. X# Note how a routing entry does not know about interface technology
  62. X#
  63. X# The routing entry is more complicated... follows a list of explanation
  64. X# 1) below/here/above    This indicate if the route is for this level. down up 
  65. X# 2) number        Indicate the hash table entry this route is for
  66. X# 4) number        Indicate the IPP address of next hop 1-254
  67. X# 5) number        Indicate the interface 0==none    1-n
  68. X# 6) number         Indicate the cost of a route 1-254
  69. X
  70. X# Ex: the following entry says that the route for host 11 in this level
  71. X# is trought the host 11 itself and uses interface 1 with cost 1
  72. XRoute Host 1 15 1 1
  73. XRoute Host 2 15 1 1
  74. XRoute Host 5 15 1 1
  75. XRoute Host 10 15 1 1
  76. X#Route Host 11 11 4 1
  77. XRoute Host 15 15 1 1
  78. X
  79. X# this syas that route to subnet 10 can be done trough router 11 that is not
  80. X# directly connected with a cost of 1
  81. X# The fact that router 11 is not directly connected means that it is on 
  82. X# this same network.
  83. X#Route Net 10 11 0 1
  84. X
  85. X# this says that a route to subnet 10 can be done via host 12 that is directly 
  86. X# connected but with a cost of 2
  87. X# Being directly connected means that the next hop is subnet.router
  88. X#Route Net 10 12 1 2
  89. XRoute Net 1 2 0 2
  90. X
  91. X# A route to the parent network, the dummy entry is used to somplify
  92. X# the parsing algorithms.
  93. X#Route Parent dummy 12 1 2 
  94. X
  95. END_OF_FILE
  96.   if test 2047 -ne `wc -c <'IPP/config/ex1/16config'`; then
  97.     echo shar: \"'IPP/config/ex1/16config'\" unpacked with wrong size!
  98.   fi
  99.   # end of 'IPP/config/ex1/16config'
  100. fi
  101. if test -f 'IPP/config/ex1/config' -a "${1}" != "-c" ; then 
  102.   echo shar: Will not clobber existing file \"'IPP/config/ex1/config'\"
  103. else
  104.   echo shar: Extracting \"'IPP/config/ex1/config'\" \(2364 characters\)
  105.   sed "s/^X//" >'IPP/config/ex1/config' <<'END_OF_FILE'
  106. X# The config file is quite strict in terms of layout, Comments MUST start with a #
  107. X# You cannot place comments anywhere you want...
  108. X# You are allowed blank lines...
  109. X# ONLY spaces are allowed as separators...
  110. X# The FIRST thing you have to write is the address of the router.,
  111. X
  112. XAddress 1.1
  113. X
  114. X# The n you have to write the interface specification.. the thing begins with
  115. X# a special keyword... otherwise it is too complicated.
  116. X# The other thing is tha all parameters fit in one line... in the following order
  117. X# Number    The number of this interface (0 not allowed)
  118. X# Technology    Can be sock, atm, ... (Only sock allowed now)
  119. X# yes/no    Says if the interface is a Listen interface or not
  120. X# Parameters of the connect call in case the If is a calling interface
  121. X
  122. X#Interface 1 sock no localhost 1026
  123. X
  124. X#Interface 1 sock yes
  125. X#Interface 2 sock yes
  126. X#Interface 3 sock yes
  127. XInterface 4 sock yes
  128. X
  129. X# Routing gets more complicated....
  130. X# If a routing entry overwrite another one a WARNING message will follow !
  131. X# Note how a routing entry does not know about interface technology
  132. X#
  133. X# The routing entry is more complicated... follows a list of explanation
  134. X# 1) host/net/parent    This indicate if the route is for this level. down up 
  135. X# 2) number        Indicate the hash table entry this route is for
  136. X# 4) number        Indicate the IPP address of next hop 1-254
  137. X# 5) number        Indicate the interface 0==none    1-n
  138. X# 6) number         Indicate the cost of a route 1-254
  139. X
  140. X# Ex: the following entry says that the route for host 11 in this level
  141. X# is trought the host 11 itself and uses interface 1 with cost 1
  142. X# NOTE: Host route MUST have a directly connected next hop
  143. X#Route Host 11 11 1 1
  144. X#Route Host 3 3 1 1
  145. X#Route Host 4 4 1 1
  146. X#Route Host 5 5 1 1
  147. X
  148. X# this syas that route to subnet 10 can be done trough router 11 that is not
  149. X# directly connected with a cost of 1
  150. X# Being not directly connected means that you have to use other routers in this
  151. X# same net to reache the desired one.
  152. X#Route Net 10 11 0 1
  153. X
  154. X# this says that a route to subnet 10 can be done via host 12 that is directly 
  155. X# connected but with a cost of 2
  156. X# Being directly connected means that the next hop is subnet.router
  157. X#Route Net 10 12 1 2
  158. X
  159. X# A route to the parent network, the dummy entry is used to somplify
  160. X# the parsing algorithms.
  161. X# The fields are as follows, routing host, interface, cost
  162. X#Route Parent dummy 1 1 2 
  163. X#Route Parent dummy 1 2 1
  164. END_OF_FILE
  165.   if test 2364 -ne `wc -c <'IPP/config/ex1/config'`; then
  166.     echo shar: \"'IPP/config/ex1/config'\" unpacked with wrong size!
  167.   fi
  168.   # end of 'IPP/config/ex1/config'
  169. fi
  170. if test -f 'IPP/config/ex2/2config' -a "${1}" != "-c" ; then 
  171.   echo shar: Will not clobber existing file \"'IPP/config/ex2/2config'\"
  172. else
  173.   echo shar: Extracting \"'IPP/config/ex2/2config'\" \(2335 characters\)
  174.   sed "s/^X//" >'IPP/config/ex2/2config' <<'END_OF_FILE'
  175. X# The config file is quite strict in terms of layout, Comments MUST start with a #
  176. X# You cannot place comments anywhere you want...
  177. X# You are allowed blank lines...
  178. X# ONLY spaces are allowed as separators...
  179. X# The FIRST thing you have to write is the address of the router.,
  180. X
  181. XAddress 2
  182. X
  183. X# The n you have to write the interface specification.. the thing begins with
  184. X# a special keyword... otherwise it is too complicated.
  185. X# The other thing is tha all parameters fit in one line... in the following order
  186. X# Number LinkType Listen Parameters
  187. X
  188. X#Interface 1 sock no localhost 4326
  189. X#Interface 2 sock no localhost 4366
  190. X
  191. XInterface 1 sock yes
  192. XInterface 2 sock yes
  193. XInterface 3 sock yes
  194. XInterface 4 sock yes
  195. XInterface 5 sock yes
  196. X
  197. X# Routing gets more complicated....
  198. X# If a routing entry overwrite another one a WARNING message will follow !
  199. X# Note how a routing entry does not know about interface technology
  200. X#
  201. X# The routing entry is more complicated... follows a list of explanation
  202. X# 1) below/here/above    This indicate if the route is for this level. down up 
  203. X# 2) number        Indicate the hash table entry this route is for
  204. X# 4) number        Indicate the IPP address of next hop 1-254
  205. X# 5) number        Indicate the interface 0==none    1-n
  206. X# 6) number         Indicate the cost of a route 1-254
  207. X
  208. X# Ex: the following entry says that the route for host 11 in this level
  209. X# is trought the host 11 itself and uses interface 1 with cost 1
  210. X# NOTE: ALL next hop of a host must be directly connected
  211. X# NOTE: You should NOT setup a route for a calling host.
  212. X
  213. X# This is a multile route but NO loop since the other hosts are set ok
  214. XRoute Host 7 3 2 1
  215. XRoute Host 7 5 4 2
  216. XRoute Host 7 4 3 2
  217. X
  218. X# Now a multiple route to host 8
  219. XRoute Host 8 4 3 1
  220. XRoute Host 8 5 4 3
  221. XRoute Host 8 3 2 3
  222. X
  223. XRoute Host 9 5 4 1
  224. X
  225. X# this syas that route to subnet 10 can be done trough router 11 that is not
  226. X# directly connected with a cost of 1
  227. X# The fact that router 11 is not directly connected means that it is on 
  228. X# this same network.
  229. X#Route Net 10 11 0 1
  230. X
  231. X# this says that a route to subnet 10 can be done via host 12 that is directly 
  232. X# connected but with a cost of 2
  233. X# Being directly connected means that the next hop is subnet.router
  234. X#Route Net 10 12 1 2
  235. X#Route Net 1 1 1 2
  236. X
  237. X# A route to the parent network, the dummy entry is used to somplify
  238. X# the parsing algorithms.
  239. X#Route Parent dummy 12 1 2 
  240. X
  241. END_OF_FILE
  242.   if test 2335 -ne `wc -c <'IPP/config/ex2/2config'`; then
  243.     echo shar: \"'IPP/config/ex2/2config'\" unpacked with wrong size!
  244.   fi
  245.   # end of 'IPP/config/ex2/2config'
  246. fi
  247. if test -f 'IPP/config/ex2/3config' -a "${1}" != "-c" ; then 
  248.   echo shar: Will not clobber existing file \"'IPP/config/ex2/3config'\"
  249. else
  250.   echo shar: Extracting \"'IPP/config/ex2/3config'\" \(2330 characters\)
  251.   sed "s/^X//" >'IPP/config/ex2/3config' <<'END_OF_FILE'
  252. X# The config file is quite strict in terms of layout, Comments MUST start with a #
  253. X# You cannot place comments anywhere you want...
  254. X# You are allowed blank lines...
  255. X# ONLY spaces are allowed as separators...
  256. X# The FIRST thing you have to write is the address of the router.,
  257. X
  258. XAddress 3
  259. X
  260. X# The n you have to write the interface specification.. the thing begins with
  261. X# a special keyword... otherwise it is too complicated.
  262. X# The other thing is tha all parameters fit in one line... in the following order
  263. X# Number LinkType Listen Parameters
  264. X
  265. X#Interface 1 sock no localhost 4326
  266. X
  267. XInterface 1 sock yes
  268. XInterface 2 sock yes
  269. XInterface 3 sock yes
  270. XInterface 4 sock no localhost 4366
  271. XInterface 5 sock yes
  272. X
  273. X# Routing gets more complicated....
  274. X# If a routing entry overwrite another one a WARNING message will follow !
  275. X# Note how a routing entry does not know about interface technology
  276. X#
  277. X# The routing entry is more complicated... follows a list of explanation
  278. X# 1) below/here/above    This indicate if the route is for this level. down up 
  279. X# 2) number        Indicate the hash table entry this route is for
  280. X# 4) number        Indicate the IPP address of next hop 1-254
  281. X# 5) number        Indicate the interface 0==none    1-n
  282. X# 6) number         Indicate the cost of a route 1-254
  283. X
  284. X# Ex: the following entry says that the route for host 11 in this level
  285. X# is trought the host 11 itself and uses interface 1 with cost 1
  286. X# NOTE: ALL next hop of a host must be directly connected
  287. X# NOTE: You should NOT setup a route for a calling host.
  288. XRoute Host 1 2 4 1
  289. XRoute Host 2 2 4 1
  290. XRoute Host 6 2 4 1
  291. X
  292. X# Multiple route to host 8 (With loops)
  293. XRoute Host 8 4 2 1
  294. XRoute Host 8 2 4 3
  295. XRoute Host 8 5 3 3
  296. X
  297. X# This is a multiple router without looping
  298. XRoute Host 9 5 3 1
  299. XRoute Host 9 2 4 2
  300. XRoute Host 9 4 2 2
  301. X
  302. X# this syas that route to subnet 10 can be done trough router 11 that is not
  303. X# directly connected with a cost of 1
  304. X# The fact that router 11 is not directly connected means that it is on 
  305. X# this same network.
  306. X#Route Net 10 11 0 1
  307. X
  308. X# this says that a route to subnet 10 can be done via host 12 that is directly 
  309. X# connected but with a cost of 2
  310. X# Being directly connected means that the next hop is subnet.router
  311. X#Route Net 10 12 1 2
  312. X#Route Net 1 1 1 2
  313. X
  314. X# A route to the parent network, the dummy entry is used to somplify
  315. X# the parsing algorithms.
  316. X#Route Parent dummy 12 1 2 
  317. X
  318. END_OF_FILE
  319.   if test 2330 -ne `wc -c <'IPP/config/ex2/3config'`; then
  320.     echo shar: \"'IPP/config/ex2/3config'\" unpacked with wrong size!
  321.   fi
  322.   # end of 'IPP/config/ex2/3config'
  323. fi
  324. if test -f 'IPP/config/ex2/5config' -a "${1}" != "-c" ; then 
  325.   echo shar: Will not clobber existing file \"'IPP/config/ex2/5config'\"
  326. else
  327.   echo shar: Extracting \"'IPP/config/ex2/5config'\" \(2311 characters\)
  328.   sed "s/^X//" >'IPP/config/ex2/5config' <<'END_OF_FILE'
  329. X# The config file is quite strict in terms of layout, Comments MUST start with a #
  330. X# You cannot place comments anywhere you want...
  331. X# You are allowed blank lines...
  332. X# ONLY spaces are allowed as separators...
  333. X# The FIRST thing you have to write is the address of the router.,
  334. X
  335. XAddress 5
  336. X
  337. X# The n you have to write the interface specification.. the thing begins with
  338. X# a special keyword... otherwise it is too complicated.
  339. X# The other thing is tha all parameters fit in one line... in the following order
  340. X# Number LinkType Listen Parameters
  341. X
  342. X#Interface 1 sock no localhost 4326
  343. X
  344. XInterface 1 sock yes
  345. XInterface 2 sock no localhost 4366
  346. XInterface 3 sock no localhost 4366
  347. XInterface 4 sock no localhost 4366
  348. XInterface 5 sock yes
  349. X
  350. X# Routing gets more complicated....
  351. X# If a routing entry overwrite another one a WARNING message will follow !
  352. X# Note how a routing entry does not know about interface technology
  353. X#
  354. X# The routing entry is more complicated... follows a list of explanation
  355. X# 1) below/here/above    This indicate if the route is for this level. down up 
  356. X# 2) number        Indicate the hash table entry this route is for
  357. X# 4) number        Indicate the IPP address of next hop 1-254
  358. X# 5) number        Indicate the interface 0==none    1-n
  359. X# 6) number         Indicate the cost of a route 1-254
  360. X
  361. X# Ex: the following entry says that the route for host 11 in this level
  362. X# is trought the host 11 itself and uses interface 1 with cost 1
  363. X# NOTE: ALL next hop of a host must be directly connected
  364. X# NOTE: You should NOT setup a route for a calling host.
  365. XRoute Host 1 2 2 1
  366. XRoute Host 2 2 2 1
  367. XRoute Host 3 3 3 1
  368. XRoute Host 4 4 4 1
  369. XRoute Host 6 2 2 1
  370. XRoute Host 7 3 3 1
  371. X
  372. X# Multiple route to host 8 with loops
  373. XRoute Host 8 4 4 1
  374. XRoute Host 8 2 2 3
  375. XRoute Host 8 3 3 3
  376. X
  377. X# this syas that route to subnet 10 can be done trough router 11 that is not
  378. X# directly connected with a cost of 1
  379. X# The fact that router 11 is not directly connected means that it is on 
  380. X# this same network.
  381. X#Route Net 10 11 0 1
  382. X
  383. X# this says that a route to subnet 10 can be done via host 12 that is directly 
  384. X# connected but with a cost of 2
  385. X# Being directly connected means that the next hop is subnet.router
  386. X#Route Net 10 12 1 2
  387. X#Route Net 1 1 1 2
  388. X
  389. X# A route to the parent network, the dummy entry is used to somplify
  390. X# the parsing algorithms.
  391. X#Route Parent dummy 12 1 2 
  392. X
  393. END_OF_FILE
  394.   if test 2311 -ne `wc -c <'IPP/config/ex2/5config'`; then
  395.     echo shar: \"'IPP/config/ex2/5config'\" unpacked with wrong size!
  396.   fi
  397.   # end of 'IPP/config/ex2/5config'
  398. fi
  399. if test -f 'IPP/ethernet/Tnet.c' -a "${1}" != "-c" ; then 
  400.   echo shar: Will not clobber existing file \"'IPP/ethernet/Tnet.c'\"
  401. else
  402.   echo shar: Extracting \"'IPP/ethernet/Tnet.c'\" \(2900 characters\)
  403.   sed "s/^X//" >'IPP/ethernet/Tnet.c' <<'END_OF_FILE'
  404. X/* -----------------------------------------------------------------------------
  405. X * Ident: Tnet.c
  406. X * Author: Damiano Bolla 1993
  407. X * All this project is covered by the GNU Copyright.
  408. X */
  409. X
  410. X
  411. X#include <stdio.h>
  412. X#include <sys/types.h>
  413. X#include <sys/time.h>
  414. X#include "defs.h"
  415. X#include "debug.h"
  416. X#include "ethernet.h"
  417. X#include "func_defs.h"
  418. X
  419. Xstruct Debug dbg;
  420. X
  421. X/* This program tryes to simulate the behaviour of an ethernet interface
  422. X * The simulation is more like a Tnet based net since each host has 
  423. X * Its own "wire"
  424. X */
  425. X
  426. Xint main (int argc, char *argv[])
  427. X   {
  428. X   int    c;    /* The usual counter, no poit to have a long name        */
  429. X   int error;
  430. X   struct timeval timeout;
  431. X
  432. X   struct Ethernet eth;
  433. X   
  434. X   if ( DebugInit ( "localhost", "1234", "ethernet") ) exit (1);
  435. X   if ( Setup ( ð )) exit (1);
  436. X
  437. X   printf ("ListeningAddress %s %d \n",eth.Host,eth.ListenPort );
  438. X
  439. X   /* Then what it has to do is a select on the various lines and see what happens
  440. X    * It should select on the line that has the listen too.
  441. X    */
  442. X
  443. X   for (;;)
  444. X      {
  445. X      FD_ZERO (&(eth.readfds));        /* Reset all bits            */
  446. X      timeout.tv_sec = IDLE_TOUT;    /* Timeout in  seconds            */
  447. X      timeout.tv_usec = 0;        /* and no microseconds            */
  448. X
  449. X      /* We have to set the mask each time we come here...            */
  450. X      for (c=0; c <ADDR_NUM; c++ ) if ( eth.IoFd[c] ) 
  451. X     FD_SET (eth.IoFd[c], ð.readfds);
  452. X      FD_SET (eth.ListenFd, ð.readfds);
  453. X
  454. X      error = select  (MAX_FILES, &(eth.readfds), NULL, NULL, &timeout);
  455. X
  456. X      /* Done nothing, I got a timeout, let's write it down...            */
  457. X      if ( error == 0 ) eth.Idle++;
  458. X
  459. X      /* Good there is something to do, let's do it                */
  460. X      if ( error > 0 ) EthIo ( ð );
  461. X
  462. X      if ( error < 0 )
  463. X         {
  464. X     sprintf (dbg.msg,"ethernet: Select failed");
  465. X     DebugCall ( ERR_SELECT, DEBUG_CRITICAL );
  466. X     /* It may be a descriptor gone out, check for it !    */
  467. X         }
  468. X
  469. X      } /* End of the newerending for                    */
  470. X
  471. X   } /* End of the main program                        */
  472. X
  473. X
  474. X
  475. X
  476. X
  477. X/* -----------------------------------------------------------------------------
  478. X * This function is in charge to set the system up.
  479. X * If there are error it will report using the Debug function that uses the logd
  480. X * daemon.
  481. X * This function returns 0 if all is ok 1 otherwise.
  482. X */
  483. X
  484. Xint Setup ( struct Ethernet *eth )
  485. X   {
  486. X   int c;
  487. X
  488. X   /* Well, so far all ok...    now it is time to set the ethernet data        */
  489. X   /* first thing is to sett al those descriptors in the right way        */
  490. X   for ( c=0; c<ADDR_NUM; c++ ) eth->IoFd[c]=0;
  491. X
  492. X   /* The let's try to get alistening socket to work with            */
  493. X   /* Error messages are sent to the logd                    */
  494. X   if ( Listen ( ð->ListenFd, eth->Host, ð->ListenPort ) )
  495. X      return (NOT_DONE);
  496. X
  497. X   eth->Idle=0;        /* This also has to be initialized            */
  498. X   eth->BadPack=0;    /* This also has to be initialized            */
  499. X   eth->LostPack=0;    /* This also has to be initialized            */
  500. X
  501. X   return (DONE);    
  502. X   }
  503. END_OF_FILE
  504.   if test 2900 -ne `wc -c <'IPP/ethernet/Tnet.c'`; then
  505.     echo shar: \"'IPP/ethernet/Tnet.c'\" unpacked with wrong size!
  506.   fi
  507.   # end of 'IPP/ethernet/Tnet.c'
  508. fi
  509. if test -f 'IPP/host/HostInit.c' -a "${1}" != "-c" ; then 
  510.   echo shar: Will not clobber existing file \"'IPP/host/HostInit.c'\"
  511. else
  512.   echo shar: Extracting \"'IPP/host/HostInit.c'\" \(3328 characters\)
  513.   sed "s/^X//" >'IPP/host/HostInit.c' <<'END_OF_FILE'
  514. X/* ------------------------------------------------------------------------------
  515. X * Ident: HostInit.c
  516. X * Author: Damiano Bolla 1993
  517. X * All this project is covered by the GNU Copyright.
  518. X */
  519. X
  520. X#include <stdio.h>
  521. X#include <string.h>
  522. X#include <sys/types.h>
  523. X#include <sys/socket.h>
  524. X#include <netdb.h>
  525. X#include <sys/time.h>
  526. X#include <netinet/in.h>
  527. X#include "defs.h"
  528. X#include "debug.h"
  529. X#include "packet.h"
  530. X#include "commands.h"
  531. X#include "router.h"
  532. X#include "host.h"
  533. X#include "func_defs.h"
  534. X
  535. Xextern struct Debug dbg;
  536. X
  537. Xint TableInit ( struct Host *hostdata );
  538. X
  539. X/* This is a host. It can only have one link 
  540. X * The link is setup at startup time by command line.
  541. X */
  542. X
  543. Xint HostInit ( struct Host *hostdata )
  544. X   {
  545. X   char *Line;
  546. X   char *Cmd;
  547. X   char *Arg;
  548. X   char Null[2]={0};
  549. X
  550. X   /* I must be shure that the tables are initilized properly                   */
  551. X   TableInit ( hostdata );
  552. X
  553. X   /* Then first thing to do is to get my own address...                        */
  554. X   if ( GetAddress (&hostdata->Myaddr) ) return (NOT_DONE);
  555. X
  556. X   /* Ok, now... we get a line and see what the key is                          */
  557. X   while ( (Line=ReadConfig(stdin)) != NULL )
  558. X      {
  559. X      if ((Cmd=strtok(Line,CMD_SEP))==NULL) { Cmd=Null; Arg=Null; }
  560. X      else Arg=Cmd+strlen(Cmd)+1;
  561. X
  562. X      if ( strcasecmp (Cmd, CMD_INTERFACE) == 0 )
  563. X         SetInterface (hostdata, Arg);
  564. X
  565. X      if ( strcasecmp (Cmd, CMD_ROUTER) == 0 )
  566. X         hostdata->Router = ipp_atoi(Arg);
  567. X
  568. X      if ( strcasecmp (Cmd, CMD_TALKTO) == 0 )
  569. X         SetPeer ( hostdata, Arg );
  570. X      }
  571. X
  572. X   return (DONE);
  573. X   }
  574. X
  575. Xint SetPeer ( struct Host *hostdata, char *Arg )
  576. X   {
  577. X   struct IPPaddr *Taddr;
  578. X   int c;
  579. X
  580. X   Taddr = ipp_aton (Arg);
  581. X   if ( Taddr == NULL ) 
  582. X      {
  583. X      sprintf (dbg.msg,"SetPerr: Cannot conver to net address %s",Arg);
  584. X      DebugCall ( ERR_BADADDR, DEBUG_NOTICE );
  585. X      return (NOT_DONE);
  586. X      }
  587. X
  588. X   for (c=0; c<PEER_MAX; c++ )
  589. X      {
  590. X      if ( hostdata->Peer[c].Peer.Al > 0 ) continue;
  591. X      ipp_AtoA ( &hostdata->Peer[c].Peer, Taddr );
  592. X      break;
  593. X      }
  594. X
  595. X   return(DONE);
  596. X   }
  597. X
  598. Xint SetInterface ( struct Host *hostdata, char *Arg )
  599. X   {
  600. X   int  EndPort;        /* An integer indicating the end port to connect            */
  601. X   char *Tech;          /* Technology used for this link                            */
  602. X   char *EndNam;        /* A string indicating the name of the endpoint(host)       */
  603. X   char Null[2]={0};
  604. X   int  Line;
  605. X
  606. X   if ((Tech=strtok (Arg,CMD_SEP))==NULL) Tech=Null;
  607. X   if ((EndNam=strtok (NULL,CMD_SEP))==NULL) EndNam=Null;
  608. X   EndPort = ipp_atoi(strtok (NULL,CMD_SEP));
  609. X
  610. X   if ( strcasecmp(Tech,SOCK_TECH_NAM) != 0 )
  611. X      {
  612. X      sprintf (dbg.msg,"SetInetrface: This technology is not supported %s",Tech);
  613. X      DebugCall ( ERR_NOTECH, DEBUG_ALERT );
  614. X      return (NOT_DONE);
  615. X      }
  616. X
  617. X      
  618. X   if ( Connect ( EndNam, EndPort, &Line, &hostdata->Myaddr ) ) return (NOT_DONE);
  619. X
  620. X   /* Ok we are connected now ! let's store the values !            */
  621. X   hostdata->NetFd = Line;
  622. X
  623. X   return (DONE);
  624. X   }
  625. X
  626. X
  627. Xint TableInit ( struct Host *hostdata )
  628. X   {
  629. X   int c;
  630. X
  631. X   hostdata->PackId = 0;
  632. X   hostdata->BadPack = 0;
  633. X   hostdata->CurPeer = 0;
  634. X
  635. X   for (c=0; c<PEER_MAX; c++ )
  636. X      {
  637. X      hostdata->Peer[c].Peer.Al = 0;
  638. X      hostdata->Peer[c].Freq = 0;
  639. X      hostdata->Peer[c].SndCount = 0;
  640. X      hostdata->Peer[c].RcvCount = 0;
  641. X      }
  642. X
  643. X   return (DONE);
  644. X   }
  645. X
  646. END_OF_FILE
  647.   if test 3328 -ne `wc -c <'IPP/host/HostInit.c'`; then
  648.     echo shar: \"'IPP/host/HostInit.c'\" unpacked with wrong size!
  649.   fi
  650.   # end of 'IPP/host/HostInit.c'
  651. fi
  652. if test -f 'IPP/include/packet.h' -a "${1}" != "-c" ; then 
  653.   echo shar: Will not clobber existing file \"'IPP/include/packet.h'\"
  654. else
  655.   echo shar: Extracting \"'IPP/include/packet.h'\" \(3232 characters\)
  656.   sed "s/^X//" >'IPP/include/packet.h' <<'END_OF_FILE'
  657. X/* ----------------------------------------------------------------------
  658. X * AUthor: Damiano Bolla, 1993
  659. X * All this project is covered by the GNU Copyright.
  660. X */
  661. X
  662. X#ifndef PACKET_H
  663. X#define PACKET_H
  664. X
  665. X
  666. X#define    PTYPE_DATA    1    /* The packet just contains data        */
  667. X#define    PTYPE_PING    2    /* The packet request for a ping        */
  668. X#define    PTYPE_RR    3    /* The packet is asking for ROute Record    */
  669. X
  670. X/* This file defines the structure of a TEST IPP packet.
  671. X * An IPP packet is very similar to a IP packet apart the fields
  672. X * related to the addressing scheme. 
  673. X * A test IPP packet does not need information about resequencing or
  674. X * window control it only needs routing information and a TTL.
  675. X * To enhance the security of the system a simple checksum will be added
  676. X */
  677. X
  678. X/* What follows is the structure that will hold a packet internally
  679. X * This structure is slightly different from the way a packet is sent in the ne
  680. X * since the internal rappresentation has to be fast instead the network
  681. X * reppresentation has to be size efficient.
  682. X * Note also that the network rappresentation IS in a network order
  683. X * instead this rappresentation is in host order.
  684. X * Note also that the network reppresentation has additional fields
  685. X * packLen and Ckecksum that are NOT present here.
  686. X */
  687. Xstruct IPP
  688. X   {
  689. X   u_char Sl;                /* Sender length             */
  690. X   u_char SndAddr[ADDR_DEPTH+2];    /* The sender address, max         */
  691. X   u_char Rl;                /* Receiver length             */
  692. X   u_char RcvAddr[ADDR_DEPTH+2];    /* The receiver address, max         */
  693. X   u_char From;                /* The host that just sent this packet    */
  694. X   u_char Sender;            /* The original host (In this domain)    */
  695. X   u_char PackId;            /* An Id for this domain..        */
  696. X   u_char NextRouter;            /* Next router we have to reach        */
  697. X   u_char NextHop;            /* The Next address to reach (This net)    */
  698. X   u_char Depth;            /* The depth in the common tree        */
  699. X   u_char TTL;            /* The time to live of a packet            */
  700. X   u_char Type;            /* Packet Type, Ping, Route-Record...    Data    */
  701. X   u_short DataLen;        /* The lenght of the data            */
  702. X   char Data[IPP_DATA+2];    /* Tooo messy to have a pointer around..    */
  703. X   };
  704. X
  705. Xstruct IPPaddr
  706. X   {
  707. X   u_char Al;            /* Address length                */
  708. X   u_char Depth;        /* The depth level of this address        */
  709. X   u_char Addr[ADDR_DEPTH+2];    /* The address we are storing            */
  710. X   };
  711. X
  712. X
  713. X/* This part describes what a packet should look like when it is sent down the net
  714. X * There will be a function that does the job of translating one rapp. to the 
  715. X * other once for alla functions.
  716. X *
  717. X
  718. X 2 bytes         Length of the entire packet BUT a max of IPP_DATA * 2
  719. X 4 bits            Length of the sender address (In bytes)
  720. X 4 bits         Length of the receiver address (In bytes)
  721. X Max of 15 bytes    The sender address
  722. X Max of 15 bytes    The receiver address
  723. X 4 bits            Unused 
  724. X 4 bits         Depth where the addresses are common
  725. X 1 u_char         The From host, the one that just sent the packet
  726. X 1 u_char         The Sender host in this domain
  727. X 1 u_char         The packetId for this domain and the Sender host
  728. X 1 u_char        The address of the next router if any
  729. X 1 u_char         The next hop to reach
  730. X 1 u_char        The TIME to live of a packet (Initally 255)
  731. X 1 u_char        The pachet type
  732. X 2 bytes        The lenght of the data BUT a max of IPP_DATA
  733. X Max IPP_DATA bytes
  734. X 4 bytes        Checksum unsigned long
  735. X
  736. X */
  737. X
  738. X#endif
  739. END_OF_FILE
  740.   if test 3232 -ne `wc -c <'IPP/include/packet.h'`; then
  741.     echo shar: \"'IPP/include/packet.h'\" unpacked with wrong size!
  742.   fi
  743.   # end of 'IPP/include/packet.h'
  744. fi
  745. if test -f 'IPP/lib/route/FindParentRoute.c' -a "${1}" != "-c" ; then 
  746.   echo shar: Will not clobber existing file \"'IPP/lib/route/FindParentRoute.c'\"
  747. else
  748.   echo shar: Extracting \"'IPP/lib/route/FindParentRoute.c'\" \(3144 characters\)
  749.   sed "s/^X//" >'IPP/lib/route/FindParentRoute.c' <<'END_OF_FILE'
  750. X/* ---------------------------------------------------------------------------
  751. X * Ident: FindParentRoute.c
  752. X * Author: Damiano Bolla 1993
  753. X * All this project is covered by the GNU Copyright.
  754. X */
  755. X
  756. X#include <stdio.h>
  757. X#include <sys/types.h>
  758. X#include <sys/time.h>
  759. X#include "defs.h"
  760. X#include "debug.h"
  761. X#include "packet.h"
  762. X#include "router.h"
  763. X#include "func_defs.h"
  764. X
  765. Xextern struct Debug dbg;
  766. X
  767. X/* This tryes to find a route to the parent
  768. X * It wants the routing table, the destination, and returns
  769. X * what is the right next with the given depth and the interface.
  770. X * NOTE: The interface returned is NOT a file descriptor it is anumber
  771. X * indicating what interface to use !!!
  772. X */
  773. Xint FindParentRoute ( struct Routing *rinfo, 
  774. X    u_char *NextRouter,
  775. X    u_char *NextHop,
  776. X    int    *Interf )
  777. X   {
  778. X   struct NetEntry *Entry;
  779. X   struct HostEntry *EntryH;
  780. X   int    UseThis;
  781. X   int    Interface;
  782. X   int    NextRo;
  783. X
  784. X   /* If the following is true.. I have to use a Direct route            */
  785. X   if ( *NextRouter )
  786. X      {
  787. X      Entry   = &rinfo->parentdata;
  788. X      UseThis = Entry->Direct;
  789. X      if ( UseThis )
  790. X         {
  791. X         *Interf     = Entry->Link[UseThis].Interface;
  792. X         *NextHop    = Entry->Link[UseThis].Next;
  793. X         *NextRouter = NOT_USED;        
  794. X         Entry->Link[UseThis].Cumulated += Entry->Link[UseThis].Cost;
  795. X         RouteNetMgr ( Entry );
  796. X         return (DONE);
  797. X         }
  798. X      else
  799. X         {
  800. X         sprintf (dbg.msg,"FindParentRoute: No direct route Parent");
  801. X         DebugCall ( ERR_BADROUTE, DEBUG_ALERT );
  802. X         return (NOT_DONE);
  803. X         }
  804. X      }
  805. X
  806. X
  807. X   /* If this Parent net has any route I can use it...                */
  808. X   /* Othervise I have to say there is no route available...            */
  809. X   Entry = &rinfo->parentdata;
  810. X   UseThis = Entry->Try;
  811. X   if ( !UseThis )
  812. X      {
  813. X      sprintf (dbg.msg,"FindParentRoute: No route at all to Parent");
  814. X      DebugCall ( ERR_BADROUTE, DEBUG_ALERT );
  815. X      return (NOT_DONE);
  816. X      }
  817. X
  818. X   /* Let me see... is this a direct hop or am I using another host ?    */
  819. X   /* NOTE: I have to increase the cost of this route anyway...        */
  820. X   Interface = Entry->Link[UseThis].Interface;
  821. X   NextRo    = Entry->Link[UseThis].Next;
  822. X   Entry->Link[UseThis].Cumulated += Entry->Link[UseThis].Cost;
  823. X   RouteNetMgr ( Entry );
  824. X   if ( Interface )
  825. X      {
  826. X      *NextRouter = NOT_USED;
  827. X      *NextHop    = NextRo;
  828. X      *Interf     = Interface;
  829. X      return (DONE);
  830. X      }
  831. X
  832. X   /* nop. This is an indirect link. The next is not directly connected
  833. X    * Therefore I have to lookup THIS next in the HOST table and see...
  834. X    * NOTE: If the routing table IS correct you can still have the craziest
  835. X    * redundant configuration on earth.
  836. X    */
  837. X   EntryH = &rinfo->hostdata[NextRo];
  838. X   UseThis = EntryH->Direct;
  839. X   if ( !UseThis )
  840. X      {
  841. X      sprintf (dbg.msg,"FindParentRoute: No route to router %d",NextRo);
  842. X      DebugCall ( ERR_BADROUTE, DEBUG_ALERT );
  843. X      return (NOT_DONE);
  844. X      }
  845. X
  846. X   *NextRouter = NextRo;
  847. X   *NextHop    = EntryH->Link[UseThis].Next;
  848. X   *Interf     = EntryH->Link[UseThis].Interface;
  849. X   EntryH->Link[UseThis].Cumulated += EntryH->Link[UseThis].Cost;
  850. X   RouteHostMgr ( EntryH );
  851. X   return (DONE);
  852. X   }
  853. END_OF_FILE
  854.   if test 3144 -ne `wc -c <'IPP/lib/route/FindParentRoute.c'`; then
  855.     echo shar: \"'IPP/lib/route/FindParentRoute.c'\" unpacked with wrong size!
  856.   fi
  857.   # end of 'IPP/lib/route/FindParentRoute.c'
  858. fi
  859. if test -f 'IPP/lib/route/FindSubnetRoute.c' -a "${1}" != "-c" ; then 
  860.   echo shar: Will not clobber existing file \"'IPP/lib/route/FindSubnetRoute.c'\"
  861. else
  862.   echo shar: Extracting \"'IPP/lib/route/FindSubnetRoute.c'\" \(3418 characters\)
  863.   sed "s/^X//" >'IPP/lib/route/FindSubnetRoute.c' <<'END_OF_FILE'
  864. X/* ------------------------------------------------------------------------------
  865. X * Ident: FindSubnetRoute.c
  866. X * Author: Damiano Bolla 1993
  867. X * All this project is covered by the GNU Copyright.
  868. X */
  869. X
  870. X#include <stdio.h>
  871. X#include <sys/types.h>
  872. X#include <sys/time.h>
  873. X#include "defs.h"
  874. X#include "debug.h"
  875. X#include "packet.h"
  876. X#include "router.h"
  877. X#include "func_defs.h"
  878. X
  879. Xextern struct Debug dbg;
  880. X
  881. X/* This tryes to find a route to the desired network
  882. X * It wants the routing table, the destination, and returns
  883. X * what is the right next with the given depth and the interface.
  884. X * NOTE: The interface returned is NOT a file descriptor it is anumber
  885. X * indicating what interface to use !!!
  886. X * NOTE: This ONLY find a route to a network
  887. X */
  888. Xint FindSubnetRoute ( struct Routing *rinfo, 
  889. X    u_char Dest,
  890. X    u_char *NextRouter,
  891. X    u_char *NextHop,
  892. X    int    *Interf )
  893. X   {
  894. X   struct NetEntry *Entry;
  895. X   struct HostEntry *EntryH;
  896. X   int    UseThis;
  897. X   int    Interface;
  898. X   int    NextRo;
  899. X
  900. X   /* If the following is true ... it means that I have to find a DIRECT
  901. X    * route to the network, since I am the second router hop to a network
  902. X    * NOTE: The fact that NextRouter is really me has been checked above
  903. X    */
  904. X   if ( *NextRouter )
  905. X      {
  906. X      Entry = &rinfo->netdata[Dest];
  907. X      UseThis = Entry->Direct;
  908. X      if ( UseThis )
  909. X         {
  910. X         *Interf = Entry->Link[UseThis].Interface;
  911. X         *NextHop    = Entry->Link[UseThis].Next;
  912. X         *NextRouter = NOT_USED;    
  913. X         Entry->Link[UseThis].Cumulated += Entry->Link[UseThis].Cost;
  914. X         RouteNetMgr ( Entry );
  915. X         return (DONE);
  916. X         }
  917. X      else
  918. X         {
  919. X         sprintf (dbg.msg,"FindSubnetRoute: Cannot find direct route to %d",Dest);
  920. X         DebugCall ( ERR_BADROUTE, DEBUG_ALERT );
  921. X         return (NOT_DONE);
  922. X         }
  923. X      }
  924. X
  925. X   /* If this Net has any route I can use it...    
  926. X    * Othervise I have to say there is no route available...
  927. X    */
  928. X   Entry = &rinfo->netdata[Dest];
  929. X   UseThis = Entry->Try;
  930. X   if ( !UseThis )
  931. X      {
  932. X      sprintf (dbg.msg,"FindSubnetRoute: No kind of route to %d",Dest);
  933. X      DebugCall ( ERR_BADROUTE, DEBUG_ALERT );
  934. X      return (NOT_DONE);
  935. X      }
  936. X
  937. X   /* Let me see... is this a direct hop or am I using another host ?
  938. X    * NOTE: I have to increase the cost of this route anyway...    
  939. X    */
  940. X   Interface = Entry->Link[UseThis].Interface;
  941. X   NextRo    = Entry->Link[UseThis].Next;
  942. X   Entry->Link[UseThis].Cumulated += Entry->Link[UseThis].Cost;
  943. X   RouteNetMgr ( Entry );
  944. X   if ( Interface )
  945. X      {
  946. X      /* Wow ! a nice direct link !                        */
  947. X      *NextRouter = NOT_USED;
  948. X      *NextHop    = NextRo;
  949. X      *Interf     = Interface;
  950. X      return (DONE);
  951. X      }
  952. X
  953. X   /* nop. This is an indirect link. The next is not directly connected
  954. X    * Therefore I have to lookup THIS next in the HOST table and see...
  955. X    * NOTE: If the routing table IS correct you can still have the craziest
  956. X    * redundant configuration on earth.
  957. X    */
  958. X   EntryH = &rinfo->hostdata[NextRo];
  959. X   UseThis = EntryH->Direct;
  960. X   if ( !UseThis )
  961. X      {
  962. X      sprintf (dbg.msg,"FindSubnetRoute: No direct to router %d",NextRo);
  963. X      DebugCall ( ERR_BADROUTE, DEBUG_ALERT );
  964. X      return (NOT_DONE);
  965. X      }
  966. X
  967. X   *NextRouter = NextRo;
  968. X   *NextHop    = EntryH->Link[UseThis].Next;
  969. X   *Interf     = EntryH->Link[UseThis].Interface;
  970. X   EntryH->Link[UseThis].Cumulated += EntryH->Link[UseThis].Cost;
  971. X   RouteHostMgr ( EntryH );
  972. X   return (DONE);
  973. X   }
  974. END_OF_FILE
  975.   if test 3418 -ne `wc -c <'IPP/lib/route/FindSubnetRoute.c'`; then
  976.     echo shar: \"'IPP/lib/route/FindSubnetRoute.c'\" unpacked with wrong size!
  977.   fi
  978.   # end of 'IPP/lib/route/FindSubnetRoute.c'
  979. fi
  980. if test -f 'IPP/lib/route/RouteMgr.c' -a "${1}" != "-c" ; then 
  981.   echo shar: Will not clobber existing file \"'IPP/lib/route/RouteMgr.c'\"
  982. else
  983.   echo shar: Extracting \"'IPP/lib/route/RouteMgr.c'\" \(2648 characters\)
  984.   sed "s/^X//" >'IPP/lib/route/RouteMgr.c' <<'END_OF_FILE'
  985. X/* ---------------------------------------------------------------------------
  986. X * Ident: RouteMgr.c
  987. X * Author: Damiano Bolla 1993
  988. X * All this project is covered by the GNU Copyright.
  989. X */
  990. X
  991. X#include <stdio.h>
  992. X#include <sys/types.h>
  993. X#include <sys/time.h>
  994. X#include "defs.h"
  995. X#include "debug.h"
  996. X#include "packet.h"
  997. X#include "router.h"
  998. X#include "func_defs.h"
  999. X
  1000. X/* This function is the one that can be offlined.
  1001. X * What it does is to find what is the next "best" Link to try for a route
  1002. X * It uses the cumulated cost as a means. It also has the job of selecting
  1003. X * a "valid" link in case one has been shut down.
  1004. X * Note the complexity interoduced by the direct link concept
  1005. X */
  1006. X
  1007. Xint RouteNetMgr ( struct NetEntry *route )
  1008. X   {
  1009. X   int c;
  1010. X   int Try;
  1011. X   int Direct;
  1012. X   u_int Cur;        /* The current cumulated                */
  1013. X
  1014. X   /* I dont really care about his, should I ? :-) Damiano            */
  1015. X   if ( route==NULL ) return (DONE);
  1016. X
  1017. X   /* Warning !!! algoritmo Extra stupido !!! NON sottrae il costo..        */
  1018. X   /* Double WARNING il valore di Cur e' passibile di overlow...        */
  1019. X
  1020. X   Cur     = 1234567;    /* We start with a big cost and then go down    */
  1021. X   Try     = NOT_USED;    /* Assume no link is available            */
  1022. X   Direct  = NOT_USED;    /* The same for the direct route        */
  1023. X
  1024. X   for (c=1; c<=ROUTE_MAX; c++ )
  1025. X      {
  1026. X      if ( route->Link[c].Next == NOT_USED ) continue;
  1027. X
  1028. X      /* I NEEED to find a direct link anyway if I dont' have one...    */
  1029. X      if ( !Direct && route->Link[c].Interface ) Direct = c;
  1030. X
  1031. X      if ( route->Link[c].Cumulated <= Cur ) 
  1032. X         { 
  1033. X         Cur=route->Link[c].Cumulated; 
  1034. X         if ( route->Link[c].Interface ) Direct = c;
  1035. X         Try=c; 
  1036. X         }
  1037. X      }
  1038. X
  1039. X   route->Try    = Try;
  1040. X   route->Direct = Direct;
  1041. X
  1042. X   return (DONE);
  1043. X   }
  1044. X
  1045. Xint RouteHostMgr ( struct HostEntry *route )
  1046. X   {
  1047. X   int c;
  1048. X   int Direct;
  1049. X   int Another;
  1050. X   u_int Cur;        /* The current cumulated                */
  1051. X
  1052. X   /* I dont really care about his, should I ? :-) Damiano            */
  1053. X   if ( route==NULL ) return (DONE);
  1054. X
  1055. X   /* Warning !!! algoritmo Extra stupido !!! NON sottrae il costo..        */
  1056. X   /* Double WARNING il valore di Cur e' passibile di overlow...        */
  1057. X
  1058. X   Cur     = 1234567;    /* We start with a big cost and then go down    */
  1059. X   Direct  = NOT_USED;    /* The same for the direct route        */
  1060. X   Another = NOT_USED;    /* Assume no link is available            */
  1061. X
  1062. X   for (c=1; c<=ROUTE_MAX; c++ )
  1063. X      {
  1064. X      if ( route->Link[c].Next == NOT_USED ) continue;
  1065. X
  1066. X      if ( route->Link[c].Cumulated < Cur ) 
  1067. X         { 
  1068. X         Cur=route->Link[c].Cumulated; 
  1069. X         Another=Direct;
  1070. X         Direct=c; 
  1071. X         }
  1072. X      }
  1073. X
  1074. X   route->Direct   = Direct;
  1075. X   route->Another  = Another;
  1076. X
  1077. X   return (DONE);
  1078. X   }
  1079. X
  1080. END_OF_FILE
  1081.   if test 2648 -ne `wc -c <'IPP/lib/route/RouteMgr.c'`; then
  1082.     echo shar: \"'IPP/lib/route/RouteMgr.c'\" unpacked with wrong size!
  1083.   fi
  1084.   # end of 'IPP/lib/route/RouteMgr.c'
  1085. fi
  1086. if test -f 'IPP/lib/utils/Connect.c' -a "${1}" != "-c" ; then 
  1087.   echo shar: Will not clobber existing file \"'IPP/lib/utils/Connect.c'\"
  1088. else
  1089.   echo shar: Extracting \"'IPP/lib/utils/Connect.c'\" \(2444 characters\)
  1090.   sed "s/^X//" >'IPP/lib/utils/Connect.c' <<'END_OF_FILE'
  1091. X/* ---------------------------------------------------------------------------------
  1092. X * Ident: Connect.c
  1093. X * Author: Damiano Bolla
  1094. X * All this project is covered by the GNU Copyright.
  1095. X */
  1096. X
  1097. X#include <stdio.h>
  1098. X#include <unistd.h>
  1099. X#include <string.h>
  1100. X#include <sys/types.h>
  1101. X#include <sys/socket.h>
  1102. X#include <netdb.h>
  1103. X#include <sys/time.h>
  1104. X#include <netinet/in.h>
  1105. X#include "defs.h"
  1106. X#include "packet.h"
  1107. X#include "debug.h"
  1108. X#include "func_defs.h"
  1109. X
  1110. Xextern struct Debug dbg;
  1111. X
  1112. X/* This function tryes to create a new socket and connet it to the given 
  1113. X * address and port.
  1114. X * It will deal with errors in a distributed way and will return 
  1115. X * DONE if all is fine (0) or NOT_DONE otherwise.
  1116. X * The connection will send to the other side my address.
  1117. X */
  1118. X
  1119. Xint Connect ( char *host, u_short port, int *sock, struct IPPaddr *Myaddr )
  1120. X   {
  1121. X   struct sockaddr_in to_where;
  1122. X   struct hostent *host_data;
  1123. X   int    newsocket;
  1124. X   char   Buff[CONF_LLEN+2];
  1125. X   
  1126. X   host_data = gethostbyname ( host );
  1127. X   if ( host_data == NULL )
  1128. X      {
  1129. X      sprintf (dbg.msg,"Connect: Cannot get address of %s ",host);
  1130. X      DebugCall ( ERR_NOHOST, DEBUG_ALERT );
  1131. X      return (NOT_DONE);
  1132. X      }
  1133. X   newsocket = socket ( AF_INET, SOCK_STREAM, 0);
  1134. X   if ( newsocket < 0 )
  1135. X      {
  1136. X      sprintf (dbg.msg,"Connect: Cannot Create a new socket to be used ");
  1137. X      DebugCall ( ERR_NOSOCK, DEBUG_ALERT );
  1138. X      return (NOT_DONE);
  1139. X      }
  1140. X
  1141. X   /* Good, let's fill the destination where I want to connect            */
  1142. X   to_where.sin_family = AF_INET;
  1143. X   to_where.sin_port = htons(port);
  1144. X   memcpy ((char *)&to_where.sin_addr.s_addr ,host_data->h_addr_list[0] ,4 );
  1145. X   memset ((char*)&to_where.sin_zero, 0, sizeof(to_where.sin_zero));
  1146. X
  1147. X   /* NOTE: This call may block... what can I do ?    Damiano            */
  1148. X   if ( connect ( newsocket, (struct sockaddr *)&to_where, sizeof(to_where)) )
  1149. X      {
  1150. X      sprintf (dbg.msg,"Connect: Cannot connect to %s port %d ",host,port);
  1151. X      DebugCall ( ERR_BADCONN, DEBUG_ALERT );
  1152. X      close (newsocket);    /* Remembar this...                */
  1153. X      return (NOT_DONE);
  1154. X      }
  1155. X
  1156. X   /* Ok, the socket is connected and is up... should I mark it non block ?    */
  1157. X   /* Not for the moment.. . let me try something Damiano            */
  1158. X   *sock = newsocket;
  1159. X
  1160. X   /* What follows is a bit of a quick hack... I rely on the watchdog to 
  1161. X    * catch possible lockings... Damiano
  1162. X    */
  1163. X   sprintf (Buff,"Address %s \n",ipp_ntoa(Myaddr));
  1164. X   write (newsocket, Buff, strlen(Buff));
  1165. X
  1166. X   return (DONE);
  1167. X   }
  1168. END_OF_FILE
  1169.   if test 2444 -ne `wc -c <'IPP/lib/utils/Connect.c'`; then
  1170.     echo shar: \"'IPP/lib/utils/Connect.c'\" unpacked with wrong size!
  1171.   fi
  1172.   # end of 'IPP/lib/utils/Connect.c'
  1173. fi
  1174. if test -f 'IPP/lib/utils/Debug.c' -a "${1}" != "-c" ; then 
  1175.   echo shar: Will not clobber existing file \"'IPP/lib/utils/Debug.c'\"
  1176. else
  1177.   echo shar: Extracting \"'IPP/lib/utils/Debug.c'\" \(3218 characters\)
  1178.   sed "s/^X//" >'IPP/lib/utils/Debug.c' <<'END_OF_FILE'
  1179. X/* -----------------------------------------------------------------------------
  1180. X * Ident: Debug.c
  1181. X * Author: Damiano Bolla 1993
  1182. X * All this project is covered by the GNU Copyright.
  1183. X */
  1184. X
  1185. X#include <stdio.h>
  1186. X#include <unistd.h>
  1187. X#include <memory.h>
  1188. X#include <sys/types.h>
  1189. X#include <sys/socket.h>
  1190. X#include <netdb.h>
  1191. X#include <netinet/in.h>
  1192. X#include <signal.h>
  1193. X#include <sys/utsname.h>
  1194. X#include <errno.h>
  1195. X#include "defs.h"
  1196. X#include "debug.h"
  1197. X#include "func_defs.h"
  1198. X
  1199. Xextern struct Debug dbg;
  1200. X
  1201. X/* This function is in charge to send debug information to the logd daemon.
  1202. X * It requests various things to be filled.
  1203. X * It does not return errors since I would not know how to handle them.
  1204. X */
  1205. X
  1206. Xvoid DebugCall ( int ErrType, int ErrLevel )
  1207. X   {
  1208. X   struct sockaddr_in address;
  1209. X   int address_len;
  1210. X   int packet_len;
  1211. X   int error;
  1212. X
  1213. X   dbg.type = ErrType;
  1214. X   dbg.debug_level = ErrLevel;
  1215. X
  1216. X   /* If the debug level is not appropriate do nothing                */
  1217. X   if ( dbg.current_level > dbg.debug_level ) return;
  1218. X
  1219. X   sprintf (dbg.MsgBuff,"Program %s\nIdent %s\nPid %d\nErrType %d\nErrLevel %d\nErrMsg %s",
  1220. X    dbg.prog, dbg.ident, dbg.pid, dbg.type, dbg.debug_level, dbg.msg );
  1221. X
  1222. X   address.sin_family = SOCK_DGRAM;    
  1223. X   address.sin_port = htons(dbg.logd_port);    
  1224. X   address.sin_addr.s_addr = dbg.logd_host;
  1225. X   memset (address.sin_zero, 0, sizeof(address.sin_zero));
  1226. X
  1227. X   address_len = sizeof (struct sockaddr_in);
  1228. X   packet_len = strlen (dbg.MsgBuff);    /* Do not sent the zero at the end    */
  1229. X   error = sendto (dbg.send_socket,     /* The socket from where to get data    */
  1230. X        dbg.MsgBuff,         /* Destination buffer            */
  1231. X        packet_len,         /* Size of the buffer            */
  1232. X        0,            /* Options                */
  1233. X        (struct sockaddr *)&address,     /* A place where to store     */
  1234. X        address_len         /* The length of address        */
  1235. X        );
  1236. X
  1237. X   /* After I sent it I have to NULL the message                */
  1238. X   dbg.msg[0]=0;
  1239. X   }
  1240. X
  1241. X/* ----------------------------------------------------------------------------
  1242. X * This function set up the debug system.
  1243. X * Since the debug system is THE MOST VITAL PART and HAS to be the first
  1244. X * to be initialized if there is ANY error here the program termintes.
  1245. X * Program termination is anyway duty of the caller.
  1246. X */
  1247. X
  1248. Xint DebugInit ( char *logd_host, char *logd_port, char *prog )
  1249. X   {
  1250. X   struct hostent *host;
  1251. X   u_short port;
  1252. X
  1253. X   host=gethostbyname(logd_host);
  1254. X   if ( host==NULL ) 
  1255. X      {
  1256. X      fprintf (stderr,"DebugInit: Cannot find the loghost %s \n",logd_host);
  1257. X      return (NOT_DONE);
  1258. X      }
  1259. X
  1260. X   if ( host->h_length < 0 )
  1261. X      {
  1262. X      fprintf (stderr,"DebugInit: Cannot find address for loghost %s \n",logd_host);
  1263. X      return (NOT_DONE);
  1264. X      }
  1265. X
  1266. X   memcpy ((char *)&dbg.logd_host ,host->h_addr_list[0] ,4 );
  1267. X
  1268. X   port=ipp_atoi(logd_port);
  1269. X   dbg.logd_port=port;        /* Internal data are in internal format        */
  1270. X
  1271. X   /* I create a working socket now to be shure that I have when is needed    */
  1272. X   dbg.send_socket = socket ( PF_INET, SOCK_DGRAM, 0);
  1273. X   if ( dbg.send_socket < 0 )
  1274. X      {
  1275. X      fprintf (stderr,"DebugInit: Cannot create a working socket \n");
  1276. X      return (NOT_DONE);
  1277. X      }
  1278. X
  1279. X   strncpy (dbg.prog, prog, ERR_LEN);
  1280. X   dbg.ident[0]=0;
  1281. X   dbg.pid = getpid();
  1282. X   dbg.type=ERR_OK;
  1283. X   dbg.current_level=DEBUG_LEVEL;
  1284. X   dbg.msg[0]=0;
  1285. X   return (DONE);
  1286. X   }
  1287. X
  1288. X
  1289. END_OF_FILE
  1290.   if test 3218 -ne `wc -c <'IPP/lib/utils/Debug.c'`; then
  1291.     echo shar: \"'IPP/lib/utils/Debug.c'\" unpacked with wrong size!
  1292.   fi
  1293.   # end of 'IPP/lib/utils/Debug.c'
  1294. fi
  1295. if test -f 'IPP/monitor/monitor.c' -a "${1}" != "-c" ; then 
  1296.   echo shar: Will not clobber existing file \"'IPP/monitor/monitor.c'\"
  1297. else
  1298.   echo shar: Extracting \"'IPP/monitor/monitor.c'\" \(2282 characters\)
  1299.   sed "s/^X//" >'IPP/monitor/monitor.c' <<'END_OF_FILE'
  1300. X/* ------------------------------------------------------------------------------
  1301. X * Ident: monitor.c
  1302. X * Author: Damiano Bolla 1993
  1303. X * All this project is covered by the GNU Copyright.
  1304. X */
  1305. X
  1306. X#include <stdio.h>
  1307. X#include <string.h>
  1308. X#include <sys/types.h>
  1309. X#include <sys/socket.h>
  1310. X#include <netdb.h>
  1311. X#include <sys/time.h>
  1312. X#include <netinet/in.h>
  1313. X#include "defs.h"
  1314. X#include "debug.h"
  1315. X#include "packet.h"
  1316. X#include "router.h"
  1317. X#include "func_defs.h"
  1318. X
  1319. X#define STDIN         0
  1320. X
  1321. Xstruct Debug dbg;
  1322. X
  1323. X/* This is a monitor. It can only have one link 
  1324. X * The link is setup at startup time by command line.
  1325. X * This is an interactive monitor.
  1326. X * It waits for you to type an address and a message and whow a message
  1327. X * sent to his host.
  1328. X */
  1329. X
  1330. Xint main ( int argc, char *argv[] )
  1331. X   {
  1332. X   int error;
  1333. X   int talksock;
  1334. X
  1335. X   struct IPPaddr myaddr;    /* My address..                    */
  1336. X   struct IPPaddr *Taddr;
  1337. X   int    NextHop;        /* Address of next hop...            */
  1338. X   u_char PackId=0;
  1339. X
  1340. X   int  EthPort;
  1341. X   char TmpBuff[CONF_LLEN+2];
  1342. X
  1343. X   fd_set readfds;   
  1344. X
  1345. X   /* First thing to do is to setup the debugging unit...            */
  1346. X   if ( DebugInit ( "localhost", "1234", "Monitor") ) return (1);
  1347. X
  1348. X   /* Then I have to wire up the system...                    */
  1349. X   printf ("Port for wiring up > ");fflush (stdout);
  1350. X   scanf ("%d",&EthPort);
  1351. X
  1352. X   printf ("My IPP address in full > ");fflush (stdout);
  1353. X   while (TtyGets (TmpBuff,CONF_LLEN), strlen(TmpBuff) == 0);
  1354. X   Taddr = ipp_aton(TmpBuff);
  1355. X   if ( Taddr == NULL ) exit (0);
  1356. X   ipp_AtoA (&myaddr, Taddr);
  1357. X
  1358. X   printf ("Address of router, single byte  > "); fflush (stdout);
  1359. X   scanf ("%d",&NextHop);
  1360. X
  1361. X   if ( Connect ( "localhost", EthPort, &talksock, &myaddr ) ) return (1);
  1362. X
  1363. X   strcpy (dbg.ident, ipp_ntoa(&myaddr));
  1364. X
  1365. X   for (;;)
  1366. X      {
  1367. X      FD_ZERO (&readfds);           /* Reset all bits                       */
  1368. X
  1369. X      /* We have to set the mask each time we come here...                      */
  1370. X      FD_SET (STDIN, &readfds);
  1371. X      FD_SET (talksock, &readfds);
  1372. X
  1373. X      error = select  (MAX_FILES, &readfds, NULL, NULL, NULL);
  1374. X
  1375. X      if ( error <= 0 ) continue;
  1376. X
  1377. X      if ( FD_ISSET (STDIN, &readfds ) ) 
  1378. X         if ( Send ( &myaddr, talksock, NextHop, &PackId ) ) return (0);
  1379. X
  1380. X      if ( FD_ISSET (talksock, &readfds ) ) 
  1381. X         if ( Receive ( &myaddr, talksock, NextHop ) ) return (0);
  1382. X      }
  1383. X   }
  1384. END_OF_FILE
  1385.   if test 2282 -ne `wc -c <'IPP/monitor/monitor.c'`; then
  1386.     echo shar: \"'IPP/monitor/monitor.c'\" unpacked with wrong size!
  1387.   fi
  1388.   # end of 'IPP/monitor/monitor.c'
  1389. fi
  1390. if test -f 'IPP/router/ParseData.c' -a "${1}" != "-c" ; then 
  1391.   echo shar: Will not clobber existing file \"'IPP/router/ParseData.c'\"
  1392. else
  1393.   echo shar: Extracting \"'IPP/router/ParseData.c'\" \(2774 characters\)
  1394.   sed "s/^X//" >'IPP/router/ParseData.c' <<'END_OF_FILE'
  1395. X/* --------------------------------------------------------------------------
  1396. X * Ident: ParseData.c
  1397. X * Author: Damiano Bolla 1993
  1398. X * All this project is covered by the GNU Copyright.
  1399. X */
  1400. X
  1401. X#include <stdio.h>
  1402. X#include <string.h>
  1403. X#include <sys/types.h>
  1404. X#include <sys/time.h>
  1405. X#include "defs.h"
  1406. X#include "debug.h"
  1407. X#include "packet.h"
  1408. X#include "router.h"
  1409. X#include "commands.h"
  1410. X#include "func_defs.h"
  1411. X
  1412. Xextern struct Debug dbg;
  1413. X
  1414. X/* This function parse the data inside a packet and do what requested.
  1415. X * The destination address and sender address has to be changed !!
  1416. X */
  1417. Xint ParseData ( struct Routing *rinfo, struct IPP *ipp, int *Sendit )
  1418. X   {
  1419. X   struct IPPaddr Receiver;
  1420. X   char *Command;
  1421. X   char *Argument;
  1422. X   char *Params;
  1423. X   char Null[2]={0};
  1424. X
  1425. X   /* First thing to make shure is that there is a zero at the end of the data    */
  1426. X   ipp->Data[ipp->DataLen] = 0;
  1427. X
  1428. X   /* Note the strtok breaking string, it is quite complex in a way        */
  1429. X   if ((Command=strtok(ipp->Data, CMD_SEP))==NULL) Command=Null;
  1430. X   if ((Argument=strtok(NULL,CMD_SEP))==NULL) { Argument=Null; Params=Null; }
  1431. X   else Params = Argument+strlen(Argument)+1; 
  1432. X
  1433. X   /* Now I have to transform the current sender as the receiver of the packet    */
  1434. X   ipp_StoA (ipp, &Receiver);
  1435. X   if ( SetPackAddr (ipp, &rinfo->MyAddr, &Receiver ) )
  1436. X      {
  1437. X      sprintf (dbg.msg,"ParseData: Cannot set packet address ");
  1438. X      DebugCall ( ERR_BADADDR, DEBUG_ALERT );
  1439. X      *Sendit = FALSE;
  1440. X      return (NOT_DONE);
  1441. X      }
  1442. X
  1443. X   if ( strcasecmp (Command,CMD_SHOW) == 0 )
  1444. X      {
  1445. X      if (strcasecmp (Argument, CMD_ROUTE) == 0 ) 
  1446. X         ShowRoute ( rinfo, ipp->Data, IPP_DATA);
  1447. X      if (strcasecmp (Argument, CMD_INTERFACE) == 0 ) 
  1448. X         ShowInterface ( rinfo, ipp->Data, IPP_DATA);
  1449. X      if (strcasecmp (Argument, CMD_STAT) == 0 ) 
  1450. X         ShowStat ( rinfo, ipp->Data, IPP_DATA);
  1451. X      ipp->DataLen = strlen(ipp->Data);
  1452. X      *Sendit = TRUE;
  1453. X      return (DONE);
  1454. X      }
  1455. X
  1456. X   if ( strcasecmp (Command,CMD_SET) == 0 )
  1457. X      {
  1458. X      int Errcode;
  1459. X      Errcode = DONE;
  1460. X
  1461. X      if (strcasecmp (Argument, CMD_ROUTE) == 0 ) 
  1462. X         Errcode = RouteAdd ( rinfo, Params );
  1463. X      if (strcasecmp (Argument, CMD_INTERFACE) == 0 ) 
  1464. X         Errcode = SetInterface ( rinfo, Params );
  1465. X      if (strcasecmp (Argument, CMD_DEBUG) == 0 ) 
  1466. X         dbg.current_level = ipp_atoi (Params);
  1467. X
  1468. X      if ( Errcode == DONE ) sprintf (ipp->Data,"Done ");
  1469. X      else sprintf (ipp->Data,"Failed" );
  1470. X
  1471. X      ipp->DataLen = strlen(ipp->Data);
  1472. X      *Sendit = TRUE;
  1473. X      return (DONE);
  1474. X      }
  1475. X
  1476. X   /* The following may be a bit drasitic...                    */
  1477. X   if ( strcasecmp (Command,CMD_EXIT) == 0 ) exit (0);
  1478. X
  1479. X   sprintf (dbg.msg,"ParseData: I was expec. a comm. got %s ",Command);
  1480. X   DebugCall ( ERR_NOCOMM, DEBUG_ALERT );
  1481. X   *Sendit = FALSE;
  1482. X   return (DONE);
  1483. X   }
  1484. END_OF_FILE
  1485.   if test 2774 -ne `wc -c <'IPP/router/ParseData.c'`; then
  1486.     echo shar: \"'IPP/router/ParseData.c'\" unpacked with wrong size!
  1487.   fi
  1488.   # end of 'IPP/router/ParseData.c'
  1489. fi
  1490. if test -f 'IPP/router/ParsePack.c' -a "${1}" != "-c" ; then 
  1491.   echo shar: Will not clobber existing file \"'IPP/router/ParsePack.c'\"
  1492. else
  1493.   echo shar: Extracting \"'IPP/router/ParsePack.c'\" \(2920 characters\)
  1494.   sed "s/^X//" >'IPP/router/ParsePack.c' <<'END_OF_FILE'
  1495. X/* ----------------------------------------------------------------------------- 
  1496. X * Ident: ParsePack.c
  1497. X * Author: Damiano Bolla 1993
  1498. X * All this project is covered by the GNU Copyright.
  1499. X */
  1500. X
  1501. X
  1502. X#include <stdio.h>
  1503. X#include <sys/types.h>
  1504. X#include <sys/time.h>
  1505. X#include "defs.h"
  1506. X#include "debug.h"
  1507. X#include "packet.h"
  1508. X#include "router.h"
  1509. X#include "func_defs.h"
  1510. X
  1511. Xextern struct Debug dbg;
  1512. X
  1513. X/* This function has a packet and tryes to determine what to do with it.
  1514. X * Some things have to be done according to the packet type.
  1515. X * Some others depending on the data in the packet.
  1516. X */
  1517. X
  1518. Xint ParsePack ( struct Routing *rinfo, struct IPP *ipp, int *Sendit )
  1519. X   {
  1520. X   struct IPPaddr Dest;
  1521. X   u_char Mylastbyte;
  1522. X
  1523. X   /* I get this so things get a bit simpler...                    */
  1524. X   Mylastbyte = rinfo->MyAddr.Addr[rinfo->MyAddr.Al -1];
  1525. X
  1526. X   /* I now should ckeck if this packet has as "next" relally me        */
  1527. X   /* Finish this part when the host has a routing table Damiano        */
  1528. X   if ( ipp->NextHop != Mylastbyte )
  1529. X      {
  1530. X      sprintf (dbg.msg,"ParsePack: The received Next is %d",ipp->NextHop);
  1531. X      DebugCall ( ERR_BADNEXT, DEBUG_NOTICE );
  1532. X      /* I continue anyway... it is not too bad...                */
  1533. X      }
  1534. X
  1535. X   /* Ok, it is a right packet, now what does it ask me to do ??        */
  1536. X   /* The next one does NOT care if the receiver is ME or not...        */
  1537. X   if ( ipp->Type == PTYPE_RR )
  1538. X      {
  1539. X      /* I have to be shure there is a null at the end...            */
  1540. X      ipp->Data[ipp->DataLen] = 0;    
  1541. X      if ( RecordRoute ( &rinfo->MyAddr, ipp->Data, IPP_DATA ) )
  1542. X         {
  1543. X         *Sendit = FALSE;
  1544. X         return (NOT_DONE);
  1545. X         }
  1546. X
  1547. X      /* I do not appear to be the Sender of this packet... therefore        */
  1548. X      /* I do not need to set the sender byte                    */
  1549. X      ipp->DataLen = strlen(ipp->Data);
  1550. X      *Sendit = TRUE;
  1551. X      return (DONE);
  1552. X      }
  1553. X
  1554. X   /* BUT the following DO care if the receiver is ME !!! I better check then    */
  1555. X   ipp_RtoA (ipp, &Dest );
  1556. X   if ( AddressMatch ( &rinfo->MyAddr, &Dest, ipp->Depth ) == FALSE )
  1557. X      {
  1558. X      /* The packet is not for me.. baaa :-), I just have to forward it !    */
  1559. X      *Sendit = TRUE;
  1560. X      return (DONE);
  1561. X      }
  1562. X
  1563. X   /* Here I KNOW that the packet IS for me !!!    
  1564. X    * I then know that I MUST set to null the information regarding the
  1565. X    * NextHop and NetRouter
  1566. X    */
  1567. X   ipp->From     = NOT_USED;
  1568. X   ipp->Sender   = Mylastbyte;
  1569. X   ipp->PackId   = ++rinfo->PackId;
  1570. X   ipp->NextHop  = NOT_USED;
  1571. X   ipp->NextRouter = NOT_USED;
  1572. X
  1573. X   if ( ipp->Type == PTYPE_PING )
  1574. X      {
  1575. X      sprintf (dbg.msg,"ParsePack:  PING function not done ");
  1576. X      DebugCall ( ERR_NOTIMPL, DEBUG_ALERT );
  1577. X      *Sendit = FALSE;
  1578. X      return (DONE);
  1579. X      }
  1580. X
  1581. X   if ( ipp->Type == PTYPE_DATA )
  1582. X      {
  1583. X      ParseData ( rinfo, ipp, Sendit );
  1584. X      return (DONE);
  1585. X      }
  1586. X
  1587. X   sprintf (dbg.msg,"ParsePack:  Unknown packet type %d ",ipp->Type);
  1588. X   DebugCall ( ERR_NOTIMPL, DEBUG_ALERT );
  1589. X   *Sendit = FALSE;
  1590. X   return (DONE);
  1591. X   }
  1592. X
  1593. END_OF_FILE
  1594.   if test 2920 -ne `wc -c <'IPP/router/ParsePack.c'`; then
  1595.     echo shar: \"'IPP/router/ParsePack.c'\" unpacked with wrong size!
  1596.   fi
  1597.   # end of 'IPP/router/ParsePack.c'
  1598. fi
  1599. if test -f 'IPP/router/ProcessPack.c' -a "${1}" != "-c" ; then 
  1600.   echo shar: Will not clobber existing file \"'IPP/router/ProcessPack.c'\"
  1601. else
  1602.   echo shar: Extracting \"'IPP/router/ProcessPack.c'\" \(3066 characters\)
  1603.   sed "s/^X//" >'IPP/router/ProcessPack.c' <<'END_OF_FILE'
  1604. X/* -------------------------------------------------------------------------
  1605. X * Ident: ProcessPack.c
  1606. X * Author: Damiano Bolla 1993
  1607. X * All this project is covered by the GNU Copyright.
  1608. X */
  1609. X
  1610. X#include <stdio.h>
  1611. X#include <sys/types.h>
  1612. X#include <sys/time.h>
  1613. X#include "defs.h"
  1614. X#include "debug.h"
  1615. X#include "packet.h"
  1616. X#include "router.h"
  1617. X#include "func_defs.h"
  1618. X
  1619. Xextern struct Debug dbg;
  1620. X
  1621. X/* This function knows that there is apacket waiting, gets it, 
  1622. X * And then do whatwver is needed
  1623. X * At the moment only TCp is supported...
  1624. X */
  1625. X
  1626. Xint ProcessPack ( struct Routing *rinfo, int RcvIf )
  1627. X   {
  1628. X   struct IPP ipp;    /* The working packet buffer                */
  1629. X   struct IPPaddr Dest;
  1630. X   u_char NextRo;
  1631. X   u_char NextHo;
  1632. X   int    Eof;     
  1633. X   int    SendIt;
  1634. X   int    SndIf;
  1635. X
  1636. X   Eof    = FALSE;
  1637. X   SendIt = FALSE;
  1638. X
  1639. X   if ( RcvPack ( &ipp, rinfo->ifdata[RcvIf].Line, &Eof ) )
  1640. X      {
  1641. X      if ( Eof ) CloseIf ( rinfo, RcvIf );
  1642. X      rinfo->BadCount++;
  1643. X      return (NOT_DONE);
  1644. X      }
  1645. X
  1646. X   /* Let's update the statistics... one more packet received..            */
  1647. X   rinfo->ifdata[RcvIf].Received++;
  1648. X
  1649. X   /* Now.. do I have seen this packet already ??                */
  1650. X   if ( SeenAlready ( rinfo->seendata, ipp.Sender, ipp.PackId ))
  1651. X      {
  1652. X      rinfo->LoopCount++;
  1653. X      sprintf (dbg.msg,"ProcessPack: Packet From %d Id %d already seen",ipp.Sender,ipp.PackId);
  1654. X      DebugCall ( ERR_TTL, DEBUG_ALERT );
  1655. X      return (NOT_DONE);
  1656. X      }
  1657. X
  1658. X
  1659. X   /* The ttl is defined as an u_char, therefore it cannot go below zero    */
  1660. X   if ( ipp.TTL-- == 0 )
  1661. X      {
  1662. X      rinfo->TTLCount++;
  1663. X      sprintf (dbg.msg,"ProcessPack: Packet TTL is ZERO");
  1664. X      DebugCall ( ERR_TTL, DEBUG_ALERT );
  1665. X      return (NOT_DONE);
  1666. X      }
  1667. X
  1668. X   /* Now I have to see what the packet wants to do and then do it
  1669. X    * If the resulting packet need to be sent I will set the flag SendIt
  1670. X    * This part will check if the packet is for me and do things... 
  1671. X    * If this part changes the destination it MUST zero the NextRouter and 
  1672. X    * NextHop field in the packet
  1673. X    */
  1674. X   if ( ParsePack ( rinfo, &ipp, &SendIt ) )
  1675. X      {
  1676. X      sprintf (dbg.msg,"ProcessPack: Could not parse a packet ");
  1677. X      DebugCall ( ERR_BADPACK, DEBUG_ALERT );
  1678. X      return (NOT_DONE);
  1679. X      }
  1680. X
  1681. X   /* Nothing mutch to do if we don't have to send the resulting packet        */
  1682. X   if ( SendIt == FALSE ) return (DONE);
  1683. X
  1684. X   /* I have to get the destination again the ParsePack may have changed it    */
  1685. X   ipp_RtoA (&ipp, &Dest );
  1686. X   sprintf (dbg.msg,"ProcessPack: Finding route to %s",ipp_ntoa(&Dest));
  1687. X   DebugCall ( ERR_MSG, DEBUG_TEXT );
  1688. X
  1689. X   if ( FindRoute ( rinfo, &ipp, &SndIf) )
  1690. X      {
  1691. X      sprintf (dbg.msg,"ProcessPack: No route to %s",ipp_ntoa(&Dest));
  1692. X      DebugCall ( ERR_NOROUTE, DEBUG_NOTICE );
  1693. X      return (NOT_DONE);
  1694. X      }
  1695. X   
  1696. X   /* What remains is just to send it...                    */
  1697. X   Eof = FALSE;
  1698. X   if ( SndPack ( &ipp, rinfo->ifdata[SndIf].Line, &Eof ) )
  1699. X      { 
  1700. X      if ( Eof ) CloseIf ( rinfo, SndIf ); 
  1701. X      rinfo->BadCount++;
  1702. X      return (NOT_DONE); 
  1703. X      }
  1704. X
  1705. X   /* Some more statistics...                            */
  1706. X   rinfo->ifdata[SndIf].Sent++;
  1707. X
  1708. X   return (DONE);
  1709. X   }
  1710. X
  1711. END_OF_FILE
  1712.   if test 3066 -ne `wc -c <'IPP/router/ProcessPack.c'`; then
  1713.     echo shar: \"'IPP/router/ProcessPack.c'\" unpacked with wrong size!
  1714.   fi
  1715.   # end of 'IPP/router/ProcessPack.c'
  1716. fi
  1717. if test -f 'IPP/router/README_config' -a "${1}" != "-c" ; then 
  1718.   echo shar: Will not clobber existing file \"'IPP/router/README_config'\"
  1719. else
  1720.   echo shar: Extracting \"'IPP/router/README_config'\" \(2757 characters\)
  1721.   sed "s/^X//" >'IPP/router/README_config' <<'END_OF_FILE'
  1722. X# This is an example of a config file.
  1723. X# The config file is quite strict in terms of layout, Comments MUST start with a #
  1724. X# You cannot place comments anywhere you want...
  1725. X# You are allowed blank lines...
  1726. X# ONLY spaces are allowed as separators...
  1727. X# The FIRST thing you have to write is the address of the router.,
  1728. X# Addresses are the FULL address of this router Ex: Address 1.2.3
  1729. X
  1730. XAddress 2
  1731. X
  1732. X# Then you have to write the interface specification.. the thing begins with
  1733. X# a special keyword... otherwise it is too complicated.
  1734. X# The other thing is tha all parameters fit in one line... in the following order
  1735. X# 1) Number indicating which interface you are setting
  1736. X# 2) Technology of this interface
  1737. X# 3) Yes/no    Is this interface a listening interface or not ?
  1738. X# 4) The parameters for a NOT listening interface to connect to the other end
  1739. X#    In this case the host and the port to connect to.
  1740. X
  1741. X#Interface 1 sock no localhost 4326
  1742. X#Interface 2 sock no localhost 4366
  1743. X
  1744. XInterface 1 sock yes
  1745. XInterface 2 sock yes
  1746. XInterface 3 sock yes
  1747. XInterface 4 sock yes
  1748. X
  1749. X# Follows the routing information
  1750. X# If a routing entry overwrite another one a WARNING message will follow !
  1751. X# Note how a routing entry does not know about interface technology
  1752. X#
  1753. X# The routing entry is more complicated... follows a list of explanation
  1754. X# 1) host/net/parent    This indicate what this route is
  1755. X# 2) number        Indicate the direct table entry this route is for
  1756. X# 4) number        Indicate the IPP address of next hop 1-254
  1757. X# 5) number        Indicate the interface 0==none    1-n
  1758. X# 6) number         Indicate the cost of a route 1-254
  1759. X
  1760. X# Ex: the following entry says that the route for host 11 in this domain
  1761. X# is trought the host 11 itself and uses interface 1 with cost 1
  1762. X#Route Host 11 11 1 1
  1763. X
  1764. X# NOTE: ALL next hop of a host must be directly connected
  1765. X# NOTE: You should NOT setup a route for a calling host since such route gets
  1766. X# created when the calling host actually connect to the router
  1767. X# Follows some more routing examples
  1768. X
  1769. X#Route Host 5 15 1 1
  1770. X# Route Host 10 10 2 1
  1771. X#Route Host 11 15 1 1
  1772. X#Route Host 15 15 1 1
  1773. X#Route Host 16 15 1 1
  1774. X
  1775. X# this syas that route to subnet 10 can be done trough router 11 that is not
  1776. X# directly connected with a cost of 1
  1777. X# The fact that router 11 is not directly connected means that it is a distant router
  1778. X# in this domain for subnet 10
  1779. X#Route Net 10 11 0 1
  1780. X
  1781. X# this says that a route to subnet 10 can be done via host 12 that is directly 
  1782. X# connected but with a cost of 2
  1783. X# NOTE: The next (in this case 12) is the address of the destination router in the subnet.
  1784. X#Route Net 10 12 1 2
  1785. X
  1786. X# A route to the parent network, the dummy entry is used to somplify
  1787. X# the parsing algorithm. 
  1788. X# Apart this it follows the same structure as the subnet routing entry.
  1789. X#Route Parent dummy 12 1 2 
  1790. X
  1791. END_OF_FILE
  1792.   if test 2757 -ne `wc -c <'IPP/router/README_config'`; then
  1793.     echo shar: \"'IPP/router/README_config'\" unpacked with wrong size!
  1794.   fi
  1795.   # end of 'IPP/router/README_config'
  1796. fi
  1797. if test -f 'IPP/router/TableInit.c' -a "${1}" != "-c" ; then 
  1798.   echo shar: Will not clobber existing file \"'IPP/router/TableInit.c'\"
  1799. else
  1800.   echo shar: Extracting \"'IPP/router/TableInit.c'\" \(2513 characters\)
  1801.   sed "s/^X//" >'IPP/router/TableInit.c' <<'END_OF_FILE'
  1802. X/* ------------------------------------------------------------------------
  1803. X * Ident: TableInit.c
  1804. X * Author: Damiano Bolla 1993
  1805. X * All this project is covered by the GNU Copyright.
  1806. X */
  1807. X
  1808. X#include <stdio.h>
  1809. X#include <string.h>
  1810. X#include <sys/types.h>
  1811. X#include <sys/time.h>
  1812. X#include "defs.h"
  1813. X#include "debug.h"
  1814. X#include "packet.h"
  1815. X#include "router.h"
  1816. X#include "func_defs.h"
  1817. X
  1818. X/* This function initializes the routing tables to null.
  1819. X * It cannot fails since all data is already allocated...
  1820. X */
  1821. X
  1822. Xvoid TableInit ( struct Routing *rinfo )
  1823. X   {
  1824. X   int c;
  1825. X   int d;
  1826. X
  1827. X   for (c=0; c<ADDR_NUM; c++ )
  1828. X      {
  1829. X      rinfo->hostdata[c].Direct = NOT_USED;
  1830. X      rinfo->hostdata[c].Another = NOT_USED;
  1831. X      for (d=0; d<=ROUTE_MAX; d++)
  1832. X     {
  1833. X         rinfo->hostdata[c].Link[d].Next = NOT_USED;
  1834. X         rinfo->hostdata[c].Link[d].Interface = NOT_USED;
  1835. X         rinfo->hostdata[c].Link[d].Cost = NOT_USED;
  1836. X         rinfo->hostdata[c].Link[d].Cumulated = NOT_USED;
  1837. X         rinfo->hostdata[c].Link[d].Flag = NOT_USED;
  1838. X     }
  1839. X      }
  1840. X
  1841. X   for (c=0; c<ADDR_NUM; c++ )
  1842. X      {
  1843. X      rinfo->netdata[c].Try = NOT_USED;
  1844. X      rinfo->netdata[c].Direct = NOT_USED;
  1845. X      for (d=0; d<=ROUTE_MAX; d++)
  1846. X     {
  1847. X         rinfo->netdata[c].Link[d].Next = NOT_USED;
  1848. X         rinfo->netdata[c].Link[d].Interface = NOT_USED;
  1849. X         rinfo->netdata[c].Link[d].Cost = NOT_USED;
  1850. X         rinfo->netdata[c].Link[d].Cumulated = NOT_USED;
  1851. X         rinfo->netdata[c].Link[d].Flag = NOT_USED;
  1852. X     }
  1853. X      }
  1854. X
  1855. X   for (c=0; c<ADDR_NUM; c++ )
  1856. X      {
  1857. X      for (d=0; d<ADDR_NUM; d++)
  1858. X         {
  1859. X         rinfo->seendata[c][d].Sec=NOT_USED;
  1860. X         }
  1861. X      }
  1862. X
  1863. X   rinfo->parentdata.Try = NOT_USED;
  1864. X   rinfo->parentdata.Direct = NOT_USED;
  1865. X   for (d=0; d<=ROUTE_MAX; d++)
  1866. X      {
  1867. X      rinfo->parentdata.Link[d].Next = NOT_USED;
  1868. X      rinfo->parentdata.Link[d].Interface = NOT_USED;
  1869. X      rinfo->parentdata.Link[d].Cost = NOT_USED;
  1870. X      rinfo->parentdata.Link[d].Cumulated = NOT_USED;
  1871. X      rinfo->parentdata.Link[d].Flag = NOT_USED;
  1872. X      }
  1873. X
  1874. X   /* The best way to set an address to "NULL" is this            */
  1875. X   rinfo->MyAddr.Al = 0;
  1876. X
  1877. X   /* NOTE the <= comparison !!!                        */
  1878. X   for (c=0; c<=IF_MAX; c++ )
  1879. X      {
  1880. X      rinfo->ifdata[c].Line = NOT_USED;
  1881. X      rinfo->ifdata[c].Technology = NOT_USED;
  1882. X      rinfo->ifdata[c].Ring = NOT_USED;
  1883. X      rinfo->ifdata[c].RingPort = NOT_USED;
  1884. X      rinfo->ifdata[c].Sent = NOT_USED;
  1885. X      rinfo->ifdata[c].Received = NOT_USED;
  1886. X      }
  1887. X
  1888. X   rinfo->Idle = 0;
  1889. X   rinfo->BadCount = 0;
  1890. X   rinfo->LoopCount = 0;
  1891. X   rinfo->TTLCount = 0;
  1892. X   }
  1893. X
  1894. END_OF_FILE
  1895.   if test 2513 -ne `wc -c <'IPP/router/TableInit.c'`; then
  1896.     echo shar: \"'IPP/router/TableInit.c'\" unpacked with wrong size!
  1897.   fi
  1898.   # end of 'IPP/router/TableInit.c'
  1899. fi
  1900. if test -f 'IPP/router/router.c' -a "${1}" != "-c" ; then 
  1901.   echo shar: Will not clobber existing file \"'IPP/router/router.c'\"
  1902. else
  1903.   echo shar: Extracting \"'IPP/router/router.c'\" \(2629 characters\)
  1904.   sed "s/^X//" >'IPP/router/router.c' <<'END_OF_FILE'
  1905. X/* -----------------------------------------------------------------------------------
  1906. X * Ident: router.c
  1907. X * Author: Damiano Bolla 1993
  1908. X * All this project is covered by the GNU Copyright.
  1909. X */
  1910. X
  1911. X#include <stdio.h>
  1912. X#include <unistd.h>
  1913. X#include <fcntl.h>
  1914. X#include <sys/types.h>
  1915. X#include <sys/time.h>
  1916. X#include "defs.h"
  1917. X#include "debug.h"
  1918. X#include "packet.h"
  1919. X#include "router.h"
  1920. X#include "func_defs.h"
  1921. X
  1922. Xstruct Debug dbg;
  1923. X
  1924. X/* This is the main file of a routing machine. 
  1925. X * What a routing machine has to do is set itself up using the comand line
  1926. X * Cycle in a loop that read a packet for each interface that is UP
  1927. X * Them act on the packet.
  1928. X */
  1929. X
  1930. Xint main (char *argv[], int argc)
  1931. X   {
  1932. X   struct Routing rinfo;
  1933. X
  1934. X   int error;    /* For the select..                        */
  1935. X   struct timeval timeout;
  1936. X
  1937. X   int c;
  1938. X
  1939. X   /* Oh, well, here I am ... I have to setup the damm machine.///..        */
  1940. X   /* First thing to do is to setup dhe debug system... no ?            */
  1941. X   if ( DebugInit ( "localhost", "1234", "Router") ) exit (1);
  1942. X
  1943. X   /* The we setup the whole systemmm, debug info already go via dbg        */
  1944. X   if ( RouterInit ( &rinfo ) ) exit (1);
  1945. X
  1946. X   /* Ok, I have to close the stdout and stderr fd, NOT stdin (0)        */
  1947. X   fclose (stdout);
  1948. X   fclose (stderr);
  1949. X
  1950. X   /* Now I must have my own address, I put it into the debug ident field    */
  1951. X   strcpy (dbg.ident, ipp_ntoa(&rinfo.MyAddr));
  1952. X
  1953. X   for (;;)
  1954. X      {
  1955. X      FD_ZERO (&rinfo.readfds);        /* Reset all bits            */
  1956. X      timeout.tv_sec = IDLE_TOUT;    /* Timeout in  seconds            */
  1957. X      timeout.tv_usec = 0;        /* and no microseconds            */
  1958. X
  1959. X      /* We have to set the mask each time we come here...            */
  1960. X      for (c=1; c <=IF_MAX; c++ ) if ( rinfo.ifdata[c].Line )
  1961. X     FD_SET (rinfo.ifdata[c].Line, &rinfo.readfds);
  1962. X
  1963. X      /* Not only we have to wait for possible packets BUT for rings too    */
  1964. X      for (c=1; c <=IF_MAX; c++ ) if ( rinfo.ifdata[c].Ring )
  1965. X     FD_SET (rinfo.ifdata[c].Ring, &rinfo.readfds);
  1966. X
  1967. X      error = select  (MAX_FILES, &rinfo.readfds, NULL, NULL, &timeout);
  1968. X
  1969. X      /* Done nothing, I got a timeout, let's write it down...            */
  1970. X      if ( error == 0 ) 
  1971. X     {
  1972. X     sprintf (dbg.msg,"router: Being Idle");
  1973. X     DebugCall ( ERR_MSG, DEBUG_TEXT );
  1974. X     rinfo.Idle++;
  1975. X     }
  1976. X
  1977. X      /* Good there is something to do, let's do it                */
  1978. X      if ( error > 0 ) 
  1979. X     {
  1980. X     sprintf (dbg.msg,"router: Calling RouterIo");
  1981. X     DebugCall ( ERR_MSG, DEBUG_TEXT );
  1982. X     RouterIo ( &rinfo );
  1983. X         }
  1984. X
  1985. X      if ( error < 0 )
  1986. X     {
  1987. X     sprintf (dbg.msg,"router: Select failed");
  1988. X     DebugCall ( ERR_SELECT, DEBUG_CRITICAL );
  1989. X     /* It may be a descriptor gone out, check for it !    */
  1990. X     }
  1991. X
  1992. X      } /* End of the newerending for loop...                    */
  1993. X
  1994. X   exit (0);    
  1995. X   }
  1996. X
  1997. END_OF_FILE
  1998.   if test 2629 -ne `wc -c <'IPP/router/router.c'`; then
  1999.     echo shar: \"'IPP/router/router.c'\" unpacked with wrong size!
  2000.   fi
  2001.   # end of 'IPP/router/router.c'
  2002. fi
  2003. echo shar: End of archive 4 \(of 6\).
  2004. cp /dev/null ark4isdone
  2005. MISSING=""
  2006. for I in 1 2 3 4 5 6 ; do
  2007.     if test ! -f ark${I}isdone ; then
  2008.     MISSING="${MISSING} ${I}"
  2009.     fi
  2010. done
  2011. if test "${MISSING}" = "" ; then
  2012.     echo You have unpacked all 6 archives.
  2013.     rm -f ark[1-9]isdone
  2014. else
  2015.     echo You still must unpack the following archives:
  2016.     echo "        " ${MISSING}
  2017. fi
  2018. exit 0
  2019. exit 0 # Just in case...
  2020.