home *** CD-ROM | disk | FTP | other *** search
/ ftp.uv.es / 2014.11.ftp.uv.es.tar / ftp.uv.es / pub / unix / bootp.2.2+FdC.tar.Z / bootp.2.2+FdC.tar / gmods < prev    next >
Text File  |  1992-03-23  |  5KB  |  165 lines

  1. Folks,
  2.  
  3. Here is a summary of the gateway mods needed for BOOTP (to allow
  4. cross gateway booting), and some pseudo-code.  First the
  5. BOOTP packet (which is enclosed in an IP/UDP):
  6.  
  7. ====
  8.  
  9. /*
  10.  * Bootstrap Protocol (BOOTP).  RFC 951.
  11.  */
  12.  
  13. struct bootp {
  14.     u_char    bp_op;        /* packet opcode type */
  15. #define    BOOTREQUEST    1
  16. #define    BOOTREPLY    2
  17.     u_char    bp_htype;    /* hardware addr type */
  18.     u_char    bp_hlen;    /* hardware addr length */
  19.     u_char    bp_hops;    /* gateway hops */
  20.     u_long    bp_xid;        /* transaction ID */
  21.     u_short    bp_secs;    /* seconds since boot began */    
  22.     u_short    bp_unused;
  23.     iaddr_t    bp_ciaddr;    /* client IP address */
  24.     iaddr_t    bp_yiaddr;    /* 'your' IP address */
  25.     iaddr_t    bp_siaddr;    /* server IP address */
  26.     iaddr_t    bp_giaddr;    /* gateway IP address */
  27.     u_char    bp_chaddr[16];    /* client hardware address */
  28.     u_char    bp_sname[64];    /* server host name */
  29.     u_char    bp_file[128];    /* boot file name */
  30.     u_char    bp_vend[64];    /* vendor-specific area */
  31. };
  32.  
  33. #define    IPPORT_BOOTPS        67
  34. #define    IPPORT_BOOTPC        68
  35.  
  36. ====
  37.  
  38. Next, here is the section from [sri-nic]<rfc>rfc951.txt that has
  39. most to do with gateway issues.  However you will probably want to
  40. hardcopy the entire document.
  41.  
  42. ====
  43.  
  44.  
  45. RFC 951                                                   September 1985
  46. Bootstrap Protocol                        [Page 9]
  47.  
  48.  
  49. 8. Booting Through Gateways
  50.  
  51.    This part of the protocol is optional and requires some additional
  52.    code in cooperating gateways and servers, but it allows cross-gateway
  53.    booting.  This is mainly useful when gateways are diskless machines.
  54.    Gateways containing disks (e.g. a UNIX machine acting as a gateway),
  55.    might as well run their own BOOTP/TFTP servers.
  56.  
  57.    Gateways listening to broadcast BOOTREQUESTs may decide to forward or
  58.    rebroadcast these requests 'when appropriate'.  For example, the
  59.    gateway could have, as part of his configuration tables, a list of
  60.    other networks or hosts to receive a copy of any broadcast
  61.    BOOTREQUESTs.  Even though a 'hops' field exists, it is a poor idea
  62.    to simply globally rebroadcast the requests, since broadcast loops
  63.    will almost certainly occur.
  64.  
  65.    The forwarding could begin immediately, or wait until the 'secs'
  66.    (seconds client has been trying) field passes a certain threshold.
  67.  
  68.    If a gateway does decide to forward the request, it should look at
  69.    the 'giaddr' (gateway IP address) field.  If zero, it should plug its
  70.    own IP address (on the receiving cable) into this field.  It may also
  71.    use the 'hops' field to optionally control how far the packet is
  72.    reforwarded. Hops should be incremented on each forwarding.  For
  73.    example, if hops passes '3', the packet should probably be discarded.
  74.  
  75. ====
  76.  
  77. And here is some pseudo-code:
  78.  
  79.  
  80. /*
  81.  * Each gateway will probably have a locally configured table
  82.  * that lists the addresses of hosts (or gateways)
  83.  * (or net numbers) to which BOOTP's can be
  84.  * forwarded.  Assume this table is called 'bootplist'.  It
  85.  * can be initialized at compile time, or via a config file.
  86.  *
  87.  * The easiest case will be to use specific host (or gateway)
  88.  * addresses; if net addresses (e.g. 36.45.0.0) 
  89.  * are used, that will probably require implementing IP directed
  90.  * broadcasts.  It is probably best to start with the simple case
  91.  * of a host list.
  92.  */
  93. xxxxxxx    bootplist[] = { , , , };
  94.  
  95.  
  96. /*
  97.  * "ipreceive" is called with each incoming IP datagram.
  98.  *
  99.  * Packet headers for the respective layers are in: ether,ip,udp,bootp.
  100.  */
  101. ipreceive()
  102. {
  103.     if (ether.dst == broadcast && ether.src == from_our_interfaces)
  104.         goto discard;
  105.     if (ipchecksum == bad || --ip.ttl <= 0)
  106.         goto discard;
  107.     if (ip.proto != UDP || udp.port != IPPORT_BOOTPS) 
  108.         goto forward;
  109.     if (ip.dst != broadcast && ip.dst != one_of_my_interfaces)
  110.         goto forward;
  111.     /*
  112.      * We now have a UDP for the BOOTP Server port.
  113.      */
  114.     switch (bootp.bp_op) {
  115.     case BOOTREQUEST:
  116.         if (bootp.bp_secs <= 5 || ++bootp.bp_hops > 5)
  117.             goto discard;
  118.         if (bootp.bp_giaddr == 0)
  119.             ip.src = bootp.bp_giaddr = my IP address;
  120.             /* of incoming interface, if possible */
  121.         for (each host in bootplist) {
  122.             copy_packet_into_new_buffer;
  123.             ip.dst = host address;
  124.             send_ip;
  125.         }
  126.         goto discard;    /* discard original packet */
  127.  
  128.     case BOOTREPLY:
  129.         if (bootp.bp_yiaddr != directly_accessable)
  130.             goto discard;    /* if not 0 hops from me */
  131.         /*
  132.          * At this point, we need to use one of the methods
  133.          * described in RFC951, section 4, to send the reply
  134.          * to the client.  Usually this will be: setup a
  135.          * temporary arp cache entry for bp_yiaddr at
  136.          * hardware address bp_chaddr.
  137.          */
  138.         set_arp_cache(bootp.bp_yiaddr, bootp.bp_chaddr);
  139.         ip.dst = bootp.bp_yiaddr;
  140.         udp.port = IPPORT_BOOTPC;    /* for client only now */
  141.         goto forward;
  142.  
  143.     default:
  144.         goto discard;    /* bad opcode */
  145.     }
  146.  
  147. forward:
  148.     if (ether.dst == broadcast || ip.dst == broadcast)
  149.         goto discard;
  150.     forward_ip;    /* recomputes ip checksum if needed */
  151.     return;
  152. discard:
  153.     discard_packet;
  154.     return;
  155. }
  156.  
  157.  
  158. ====
  159.  
  160. Notes:
  161.  
  162. The "if (xxx == broadcast)" tests can use 4 or 6 bytes of all ones
  163. (currently).  However if directed broadcasts are eventually implemented,
  164. the test would be a little different.
  165.