home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume4 / subnet.arp < prev    next >
Internet Message Format  |  1986-11-30  |  13KB

  1. From: talcott!ut-sally!jsq (John Quarterman)
  2. Subject: 4.3BSD IP subnet ARP hack
  3. Newsgroups: mod.sources
  4. Approved: jpn@panda.UUCP
  5.  
  6. Mod.sources:  Volume 4, Issue 64
  7. Submitted by: talcott!ut-sally!jsq (John Quarterman)
  8.  
  9.  
  10. : This is a shar archive.  Extract with sh, not csh.
  11. echo x - README
  12. sed -e 's/^X//' > README << '!RoNnIe!RaYgUn!'
  13. XThese are the mods necessary to 4.3BSD to add a subnet ARP hack.
  14. XThey allow a subnet gateway machine to act as a bridge so that only
  15. Xit need know of the existence of subnets.  This is quite useful if
  16. Xmany machines on the local network do not have RFC950 subnet code
  17. Xand you do not have sources for them.
  18. X
  19. XTo turn on the subarp code, you need to do "ifconfig xxn subarp".
  20. X
  21. X/sys/netinet/if_ether.c:    subnet ARP hack
  22. X/sys/net/if.h:            IFF_SUBARP
  23. X/sys/net/route.c:        splimp instead of splnet in rtalloc
  24. X/sys/netinet/in.c:        in_mainnetof
  25. X/sys/netinet/in.h:        in_mainnetof
  26. X/usr/src/etc/ifconfig/ifconfig.c: IFF_SUBARP (subarp, -subarp)
  27. X/usr/man/man8/ifconfig.8c:    subarp, -subarp
  28. X
  29. !RoNnIe!RaYgUn!
  30. echo x - Install
  31. sed -e 's/^X//' > Install << '!RoNnIe!RaYgUn!'
  32. Xcp if_ether.c.diff /sys/netinet/if_ether.c.diff
  33. Xcp in.c.diff /sys/netinet/in.c.diff
  34. Xcp in.h.diff /sys/netinet/in.h.diff
  35. Xcp if.h.diff /sys/net/if.h.diff
  36. Xcp route.c.diff /sys/net/route.c.diff
  37. Xcp ifconfig.c.diff /usr/src/etc/ifconfig/ifconfig.c.diff
  38. Xcp ifconfig.8c.diff /usr/man/man8/ifconfig.8c.diff
  39. X
  40. Xcd /sys/netinet
  41. Xsccs edit if_ether.c
  42. Xpatch if_ether.c.diff
  43. Xecho 'subarp' | sccs delget if_ether.c
  44. X
  45. Xcd /sys/netinet
  46. Xsccs edit in.c
  47. Xpatch in.c.diff
  48. Xecho 'subarp' | sccs delget in.c
  49. X
  50. Xcd /sys/netinet
  51. Xsccs edit in.h
  52. Xpatch in.h.diff
  53. Xecho 'subarp' | sccs delget in.h
  54. X
  55. Xcd /sys/net
  56. Xsccs edit if.h
  57. Xpatch if.h.diff
  58. Xecho 'subarp' | sccs delget if.h
  59. X
  60. Xcd /sys/net
  61. Xsccs edit route.c
  62. Xpatch route.c.diff
  63. Xecho 'subarp' | sccs delget route.c
  64. X
  65. Xcd /usr/src/etc/ifconfig
  66. Xsccs edit ifconfig.c
  67. Xpatch ifconfig.c.diff
  68. Xecho 'subarp' | sccs delget ifconfig.c
  69. X
  70. Xcd /usr/man/man8
  71. Xsccs edit ifconfig.8c
  72. Xpatch ifconfig.8c.diff
  73. Xecho 'subarp' | sccs delget ifconfig.8c
  74. !RoNnIe!RaYgUn!
  75. echo x - if_ether.c.diff
  76. sed -e 's/^X//' > if_ether.c.diff << '!RoNnIe!RaYgUn!'
  77. X*** if_ether.c.orig    Sun Apr  6 14:42:51 1986
  78. X--- if_ether.c    Sun Apr  6 14:42:53 1986
  79. X***************
  80. X*** 21,27 ****
  81. X--- 21,29 ----
  82. X  #include "syslog.h"
  83. X  
  84. X  #include "../net/if.h"
  85. X+ #include "../net/route.h"
  86. X  #include "in.h"
  87. X+ #include "in_var.h"
  88. X  #include "in_systm.h"
  89. X  #include "ip.h"
  90. X  #include "if_ether.h"
  91. X***************
  92. X*** 343,348 ****
  93. X--- 345,364 ----
  94. X              sizeof(ea->arp_sha));
  95. X          bcopy((caddr_t)ac->ac_enaddr, (caddr_t)ea->arp_sha,
  96. X              sizeof(ea->arp_sha));
  97. X+     } else
  98. X+     /*
  99. X+      * Subnet ARP hack (subarp).  This allows a site to run the subnet
  100. X+      * kernel only on the gateway machines by allowing the gateway
  101. X+      * to reply to ARP requests for a target machine on a locally 
  102. X+      * attached subnet or reachable via a route from this gateway.
  103. X+      */
  104. X+     if (ac->ac_if.if_flags & IFF_SUBARP
  105. X+         && in_netof(isaddr) != in_netof(itaddr) 
  106. X+         && if_subarp(isaddr, itaddr, &(ac->ac_if))) {
  107. X+         bcopy((caddr_t)ea->arp_sha, (caddr_t)ea->arp_tha,
  108. X+             sizeof(ea->arp_sha));
  109. X+         bcopy((caddr_t)ac->ac_enaddr, (caddr_t)ea->arp_sha,
  110. X+             sizeof(ea->arp_sha));
  111. X      } else {
  112. X          ARPTAB_LOOK(at, itaddr.s_addr);
  113. X          if (at == NULL || (at->at_flags & ATF_PUBL) == 0)
  114. X***************
  115. X*** 352,358 ****
  116. X          bcopy((caddr_t)at->at_enaddr, (caddr_t)ea->arp_sha,
  117. X              sizeof(ea->arp_sha));
  118. X      }
  119. X- 
  120. X      bcopy((caddr_t)ea->arp_spa, (caddr_t)ea->arp_tpa,
  121. X          sizeof(ea->arp_spa));
  122. X      bcopy((caddr_t)&itaddr, (caddr_t)ea->arp_spa,
  123. X--- 368,373 ----
  124. X***************
  125. X*** 528,531 ****
  126. X--- 543,619 ----
  127. X      }
  128. X      *--cp = 0;
  129. X      return (etherbuf);
  130. X+ }
  131. X+ 
  132. X+ /*
  133. X+  * Determine if interface of target address has ARP subnet routing enabled.
  134. X+  */
  135. X+ int if_subarplog = 1;
  136. X+ #define sublog    if (if_subarplog) log
  137. X+ if_subarp(isaddr, itaddr, sifp)
  138. X+ struct in_addr isaddr, itaddr;
  139. X+ register struct ifnet *sifp;
  140. X+ {
  141. X+     register u_long net;
  142. X+     register struct in_ifaddr *ia;
  143. X+     struct route ro;
  144. X+     register struct sockaddr_in *sin;
  145. X+     register struct ifaddr *taddr;
  146. X+     register struct ifnet *tifp;
  147. X+ 
  148. X+     net = in_mainnetof(itaddr);
  149. X+     if (net != in_mainnetof(isaddr))    /* sanity check */
  150. X+         return(0);
  151. X+     for (ia = in_ifaddr; ia; ia = ia->ia_next)
  152. X+         if (net == ia->ia_net)
  153. X+             break;
  154. X+     if (ia) { /* don't respond to requests for IP broadcast addresses */
  155. X+         register u_long m, l;
  156. X+ 
  157. X+         m = ~ia->ia_subnetmask;
  158. X+         l = ntohl(itaddr.s_addr) & m;
  159. X+         if (l == (INADDR_BROADCAST & m) || l == (INADDR_ANY & m))
  160. X+             return(0);
  161. X+         m = ~ia->ia_netmask;
  162. X+         l = ntohl(itaddr.s_addr) & m;
  163. X+         if (l == (INADDR_BROADCAST & m) || l == (INADDR_ANY & m))
  164. X+             return(0);
  165. X+     }
  166. X+     sin = (struct sockaddr_in *)&(ro.ro_dst);
  167. X+     sin->sin_family = AF_INET;
  168. X+     sin->sin_addr = itaddr;
  169. X+     tifp = (struct ifnet *)0;
  170. X+     if ((taddr = ifa_ifwithnet((struct sockaddr *)sin)) != NULL)
  171. X+         tifp = taddr->ifa_ifp;    /* is subnet of an interface */
  172. X+     else {    /* look in routing table for non-local target */
  173. X+         extern struct rtentry nowildcard;
  174. X+ 
  175. X+         ro.ro_rt = &nowildcard;
  176. X+         (void) rtalloc(&ro);
  177. X+         if (ro.ro_rt != (struct rtentry *)0) {
  178. X+             tifp = ro.ro_rt->rt_ifp;
  179. X+             RTFREE(ro.ro_rt);
  180. X+         }
  181. X+     }
  182. X+     if (tifp == (struct ifnet *)0) {
  183. X+         if ((sifp->if_flags & IFF_DEBUG) != 0)
  184. X+         sublog(LOG_DEBUG, "subarp %s%d:%x to ?:%x - no route\n",
  185. X+             sifp->if_name, sifp->if_unit,
  186. X+             ntohl(isaddr.s_addr), ntohl(itaddr.s_addr));
  187. X+         return(0);
  188. X+     }
  189. X+     if ((tifp->if_flags & IFF_SUBARP) == 0)
  190. X+         return(0);
  191. X+     /* Sanity check:  ignore request if from same interface as target. */
  192. X+     if (sifp->if_addrlist->ifa_ifp == tifp) {
  193. X+         if ((sifp->if_flags & IFF_DEBUG) != 0)
  194. X+         sublog(LOG_DEBUG,"subarp %s%d:%x to %s%d:%x - same interface\n",
  195. X+             sifp->if_name, sifp->if_unit, ntohl(isaddr.s_addr),
  196. X+             tifp->if_name, tifp->if_unit, ntohl(itaddr.s_addr));
  197. X+         return(0);
  198. X+     }
  199. X+     sublog(LOG_INFO, "subarp %s%d:%x to %s%d:%x\n",
  200. X+         sifp->if_name, sifp->if_unit, ntohl(isaddr.s_addr),
  201. X+         tifp->if_name, tifp->if_unit, ntohl(itaddr.s_addr));
  202. X+     return(1);
  203. X  }
  204. !RoNnIe!RaYgUn!
  205. echo x - in.c.diff
  206. sed -e 's/^X//' > in.c.diff << '!RoNnIe!RaYgUn!'
  207. X*** in.c.orig    Sun Apr  6 14:43:01 1986
  208. X--- in.c    Sun Apr  6 14:43:03 1986
  209. X***************
  210. X*** 74,79 ****
  211. X--- 74,98 ----
  212. X   * Return the network number from an internet address.
  213. X   */
  214. X  u_long
  215. X+ in_mainnetof(in)
  216. X+     struct in_addr in;
  217. X+ {
  218. X+     register u_long i = ntohl(in.s_addr);
  219. X+     register u_long net;
  220. X+ 
  221. X+     if (IN_CLASSA(i))
  222. X+         net = i & IN_CLASSA_NET;
  223. X+     else if (IN_CLASSB(i))
  224. X+         net = i & IN_CLASSB_NET;
  225. X+     else
  226. X+         net = i & IN_CLASSC_NET;
  227. X+     return (net);
  228. X+ }
  229. X+ 
  230. X+ /*
  231. X+  * Return the network number from an internet address.
  232. X+  */
  233. X+ u_long
  234. X  in_netof(in)
  235. X      struct in_addr in;
  236. X  {
  237. !RoNnIe!RaYgUn!
  238. echo x - in.h.diff
  239. sed -e 's/^X//' > in.h.diff << '!RoNnIe!RaYgUn!'
  240. X*** in.h.orig    Sun Apr  6 14:43:09 1986
  241. X--- in.h    Sun Apr  6 14:43:11 1986
  242. X***************
  243. X*** 104,108 ****
  244. X  extern    struct domain inetdomain;
  245. X  extern    struct protosw inetsw[];
  246. X  struct    in_addr in_makeaddr();
  247. X! u_long    in_netof(), in_lnaof();
  248. X  #endif
  249. X--- 104,108 ----
  250. X  extern    struct domain inetdomain;
  251. X  extern    struct protosw inetsw[];
  252. X  struct    in_addr in_makeaddr();
  253. X! u_long    in_netof(), in_lnaof(), in_mainnetof();
  254. X  #endif
  255. !RoNnIe!RaYgUn!
  256. echo x - if.h.diff
  257. sed -e 's/^X//' > if.h.diff << '!RoNnIe!RaYgUn!'
  258. X*** if.h.orig    Mon Mar 24 15:24:20 1986
  259. X--- if.h    Mon Mar 24 15:24:22 1986
  260. X***************
  261. X*** 75,80 ****
  262. X--- 75,81 ----
  263. X  #define    IFF_NOTRAILERS    0x20        /* avoid use of trailers */
  264. X  #define    IFF_RUNNING    0x40        /* resources allocated */
  265. X  #define    IFF_NOARP    0x80        /* no address resolution protocol */
  266. X+ #define    IFF_SUBARP    0x200        /* ARP subnet gateway hack */
  267. X  /* flags set internally only: */
  268. X  #define    IFF_CANTCHANGE    (IFF_BROADCAST | IFF_POINTOPOINT | IFF_RUNNING)
  269. X  
  270. !RoNnIe!RaYgUn!
  271. echo x - route.c.diff
  272. sed -e 's/^X//' > route.c.diff << '!RoNnIe!RaYgUn!'
  273. X*** route.c.orig    Sun Apr  6 14:43:23 1986
  274. X--- route.c    Sun Apr  6 14:43:25 1986
  275. X***************
  276. X*** 22,27 ****
  277. X--- 22,28 ----
  278. X  
  279. X  int    rttrash;        /* routes not in table but not freed */
  280. X  struct    sockaddr wildcard;    /* zero valued cookie for wildcard searches */
  281. X+ struct    rtentry    nowildcard;    /* indicates rtalloc shouldn't use wildcard */
  282. X  int    rthashsize = RTHASHSIZ;    /* for netstat, etc. */
  283. X  
  284. X  /*
  285. X***************
  286. X*** 34,44 ****
  287. X      register struct mbuf *m;
  288. X      register u_long hash;
  289. X      struct sockaddr *dst = &ro->ro_dst;
  290. X!     int (*match)(), doinghost, s;
  291. X      struct afhash h;
  292. X      u_int af = dst->sa_family;
  293. X      struct mbuf **table;
  294. X  
  295. X      if (ro->ro_rt && ro->ro_rt->rt_ifp && (ro->ro_rt->rt_flags & RTF_UP))
  296. X          return;                 /* XXX */
  297. X      if (af >= AF_MAX)
  298. X--- 35,50 ----
  299. X      register struct mbuf *m;
  300. X      register u_long hash;
  301. X      struct sockaddr *dst = &ro->ro_dst;
  302. X!     int (*match)(), doinghost, s, nowild;
  303. X      struct afhash h;
  304. X      u_int af = dst->sa_family;
  305. X      struct mbuf **table;
  306. X  
  307. X+     nowild = 0;
  308. X+     if (ro->ro_rt == &nowildcard) {
  309. X+         ro->ro_rt = NULL;
  310. X+         nowild++;
  311. X+     }
  312. X      if (ro->ro_rt && ro->ro_rt->rt_ifp && (ro->ro_rt->rt_flags & RTF_UP))
  313. X          return;                 /* XXX */
  314. X      if (af >= AF_MAX)
  315. X***************
  316. X*** 46,52 ****
  317. X      (*afswitch[af].af_hash)(dst, &h);
  318. X      match = afswitch[af].af_netmatch;
  319. X      hash = h.afh_hosthash, table = rthost, doinghost = 1;
  320. X!     s = splnet();
  321. X  again:
  322. X      for (m = table[RTHASHMOD(hash)]; m; m = m->m_next) {
  323. X          rt = mtod(m, struct rtentry *);
  324. X--- 52,58 ----
  325. X      (*afswitch[af].af_hash)(dst, &h);
  326. X      match = afswitch[af].af_netmatch;
  327. X      hash = h.afh_hosthash, table = rthost, doinghost = 1;
  328. X!     s = splimp(); /* splnet not high enough:  also called from interrupt. */
  329. X  again:
  330. X      for (m = table[RTHASHMOD(hash)]; m; m = m->m_next) {
  331. X          rt = mtod(m, struct rtentry *);
  332. X***************
  333. X*** 79,85 ****
  334. X      /*
  335. X       * Check for wildcard gateway, by convention network 0.
  336. X       */
  337. X!     if (dst != &wildcard) {
  338. X          dst = &wildcard, hash = 0;
  339. X          goto again;
  340. X      }
  341. X--- 85,91 ----
  342. X      /*
  343. X       * Check for wildcard gateway, by convention network 0.
  344. X       */
  345. X!     if (!nowild && dst != &wildcard) {
  346. X          dst = &wildcard, hash = 0;
  347. X          goto again;
  348. X      }
  349. !RoNnIe!RaYgUn!
  350. echo x - ifconfig.c.diff
  351. sed -e 's/^X//' > ifconfig.c.diff << '!RoNnIe!RaYgUn!'
  352. X*** ifconfig.c.orig    Sun Apr  6 14:43:30 1986
  353. X--- ifconfig.c    Sun Apr  6 14:43:32 1986
  354. X***************
  355. X*** 62,67 ****
  356. X--- 62,69 ----
  357. X      { "-trailers",    IFF_NOTRAILERS,    setifflags },
  358. X      { "arp",    -IFF_NOARP,    setifflags },
  359. X      { "-arp",    IFF_NOARP,    setifflags },
  360. X+     { "subarp",    IFF_SUBARP,    setifflags },
  361. X+     { "-subarp",    -IFF_SUBARP,    setifflags },
  362. X      { "debug",    IFF_DEBUG,    setifflags },
  363. X      { "-debug",    -IFF_DEBUG,    setifflags },
  364. X  #ifdef notdef
  365. X***************
  366. X*** 106,117 ****
  367. X  {
  368. X      int af = AF_INET;
  369. X      if (argc < 2) {
  370. X!         fprintf(stderr, "usage: ifconfig interface\n%s%s%s%s",
  371. X              "\t[ af [ address [ dest_addr ] ] [ up ] [ down ]",
  372. X                  "[ netmask mask ] ]\n",
  373. X              "\t[ metric n ]\n",
  374. X              "\t[ trailers | -trailers ]\n",
  375. X!             "\t[ arp | -arp ]\n");
  376. X          exit(1);
  377. X      }
  378. X      argc--, argv++;
  379. X--- 108,119 ----
  380. X  {
  381. X      int af = AF_INET;
  382. X      if (argc < 2) {
  383. X!         fprintf(stderr, "usage: ifconfig interface\n%s%s%s%s%s",
  384. X              "\t[ af [ address [ dest_addr ] ] [ up ] [ down ]",
  385. X                  "[ netmask mask ] ]\n",
  386. X              "\t[ metric n ]\n",
  387. X              "\t[ trailers | -trailers ]\n",
  388. X!             "\t[ arp | -arp ]\t[ subarp | -subarp ]\n");
  389. X          exit(1);
  390. X      }
  391. X      argc--, argv++;
  392. X***************
  393. X*** 287,292 ****
  394. X--- 289,295 ----
  395. X  
  396. X  #define    IFFBITS \
  397. X  "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6NOTRAILERS\7RUNNING\10NOARP\
  398. X+ \12SUBARP\
  399. X  "
  400. X  
  401. X  /*
  402. !RoNnIe!RaYgUn!
  403. echo x - ifconfig.8c.diff
  404. sed -e 's/^X//' > ifconfig.8c.diff << '!RoNnIe!RaYgUn!'
  405. X*** ifconfig.8c.orig    Sun Apr  6 14:43:39 1986
  406. X--- ifconfig.8c    Sun Apr  6 14:43:41 1986
  407. X***************
  408. X*** 101,106 ****
  409. X--- 101,119 ----
  410. X  .B \-arp
  411. X  Disable the use of the Address Resolution Protocol.
  412. X  .TP 15
  413. X+ .B subarp
  414. X+ Enable an interface on a subnet gateway to respond to ARP requests 
  415. X+ for hosts reachable via this subnet.  
  416. X+ Only useful on hardware which supports ARP.
  417. X+ This allows a gateway between two subnets to respond to ARP requests
  418. X+ received on an enabled interface to respond for hosts on another
  419. X+ enabled interface and route packets thru the gateway.
  420. X+ This allows a network configuration where only the gateway hosts need to
  421. X+ be aware of the existence of subnets.
  422. X+ .TP 15
  423. X+ .B \-subarp
  424. X+ Disable the ARP subnet code.
  425. X+ .TP 15
  426. X  .BI metric " n"
  427. X  Set the routing metric of the interface to
  428. X  .IR n ,
  429. !RoNnIe!RaYgUn!
  430. exit
  431.  
  432.