home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / bsd / 10761 < prev    next >
Encoding:
Internet Message Format  |  1992-12-30  |  6.0 KB

  1. Path: sparky!uunet!spool.mu.edu!yale.edu!yale!mintaka.lcs.mit.edu!ai-lab!hal.gnu.ai.mit.edu!mycroft
  2. From: mycroft@hal.gnu.ai.mit.edu (Charles Hannum)
  3. Newsgroups: comp.unix.bsd
  4. Subject: [386BSD] NE/2000 and packet filter
  5. Date: 30 Dec 1992 11:43:29 GMT
  6. Organization: MIT Artificial Intelligence Lab
  7. Lines: 219
  8. Distribution: world
  9. Message-ID: <1hs211INNig3@life.ai.mit.edu>
  10. NNTP-Posting-Host: hal.gnu.ai.mit.edu
  11.  
  12.  
  13. Below are diffs to make the modified NE/2000 driver posted by Curt
  14. Mayer work with the Berkeley packet filter.
  15.  
  16. There were a couple of problems with the filter itself, and with
  17. `tcpdump'.  I will post diffs of both shortly (when I get this one last
  18. bug fixed).
  19.  
  20. -----8<-----snip-----8<-----snip-----8<-----snip-----8<-----snip-----8<-----
  21. *** /src/386bsd/if_ne.c    Mon Dec 21 18:10:33 1992
  22. --- if_ne.c    Tue Dec 29 20:35:19 1992
  23. ***************
  24. *** 43,48 ****
  25. --- 43,50 ----
  26.    * receive bottom end totally rewritten by Curt Mayer, Dec 1992.
  27.    * no longer loses back to back packets. 
  28.    * note to driver writers: RTFM!
  29. +  *
  30. +  * hooks for packet filter added by Charles Hannum, 29DEC1992.
  31.    */
  32.   
  33.   #include "ne.h"
  34. ***************
  35. *** 75,80 ****
  36. --- 77,88 ----
  37.   #include "netns/ns_if.h"
  38.   #endif
  39.   
  40. + #include "bpfilter.h"
  41. + #if NBPFILTER > 0
  42. + #include "net/bpf.h"
  43. + #include "net/bpfdesc.h"
  44. + #endif
  45.   #include "i386/isa/isa_device.h"
  46.   #include "i386/isa/if_nereg.h"
  47.   #include "i386/isa/icu.h"
  48. ***************
  49. *** 104,109 ****
  50. --- 112,120 ----
  51.   #define    ns_addr    ns_ac.ac_enaddr        /* hardware Ethernet address */
  52.       int    ns_flags;
  53.   #define    DSF_LOCK    1        /* block re-entering enstart */
  54. + #if NBPFILTER > 0
  55. + #define    DSF_ATTACHED    2
  56. + #endif
  57.       int    ns_oactive;
  58.       int    ns_mask;
  59.       struct    prhdr    ns_ph;        /* hardware header of incoming packet*/
  60. ***************
  61. *** 113,118 ****
  62. --- 124,130 ----
  63.       u_char    ns_rxend;        /* receiver buffer end */
  64.       short    ns_port;        /* i/o port base */
  65.       short    ns_mode;        /* word/byte mode */
  66. +     caddr_t    ns_bpf;
  67.   } ne_softc[NNE] ;
  68.   #define    ENBUFSIZE    (sizeof(struct ether_header) + ETHERMTU + 2 + ETHER_MIN_LEN)
  69.   
  70. ***************
  71. *** 304,310 ****
  72.       ifp->if_unit = unit;
  73.       ifp->if_name = nedriver.name ;
  74.       ifp->if_mtu = ETHERMTU;
  75. !     printf (" ne%d, address %s", 
  76.           (ns->ns_mode & DSDC_WTS) ? 2000 : 1000,
  77.           ether_sprintf(ns->ns_addr)) ;
  78.       ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS;
  79. --- 316,322 ----
  80.       ifp->if_unit = unit;
  81.       ifp->if_name = nedriver.name ;
  82.       ifp->if_mtu = ETHERMTU;
  83. !     printf (" ne%d, address %s",
  84.           (ns->ns_mode & DSDC_WTS) ? 2000 : 1000,
  85.           ether_sprintf(ns->ns_addr)) ;
  86.       ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS;
  87. ***************
  88. *** 315,320 ****
  89. --- 327,336 ----
  90.       ifp->if_reset = nereset;
  91.       ifp->if_watchdog = 0;
  92.       if_attach(ifp);
  93. + #if NBPFILTER > 0
  94. +     ns->ns_flags &= ~DSF_ATTACHED;
  95. + #endif
  96.   }
  97.   
  98.   /*
  99. ***************
  100. *** 330,335 ****
  101. --- 346,364 ----
  102.       int i; char *cp;
  103.       register nec = ns->ns_port;
  104.   
  105. + #if NBPFILTER > 0
  106. +     if ((ns->ns_flags & DSF_ATTACHED) == 0) {
  107. +         bpfattach(&ns->ns_bpf, ifp, DLT_EN10MB,
  108. +               sizeof (struct ether_header));
  109. +         ns->ns_flags |= DSF_ATTACHED;
  110. +     }
  111. + #endif
  112. + #ifdef NEDEBUG
  113. +     printf ("ne: initializing, promiscuous mode %s\n",
  114. +         ns->ns_if.if_flags & IFF_PROMISC ? "on" : "off");
  115. + #endif
  116.        if (ifp->if_addrlist == (struct ifaddr *)0) return;
  117.       if (ifp->if_flags & IFF_RUNNING) return;
  118.   
  119. ***************
  120. *** 358,364 ****
  121.       outb (nec+ds_cmd, DSCM_NODMA|DSCM_PG1|DSCM_STOP);
  122.       outb(nec+ds1_curr, ns->ns_rxstart);
  123.       outb (nec+ds_cmd, DSCM_NODMA|DSCM_PG0|DSCM_START);
  124. !     outb (nec+ds0_rcr, DSRC_AB);
  125.       outb(nec+ds0_dcr, ns->ns_mode);
  126.       outb (nec+ds0_imr, 0xff);
  127.   
  128. --- 387,396 ----
  129.       outb (nec+ds_cmd, DSCM_NODMA|DSCM_PG1|DSCM_STOP);
  130.       outb(nec+ds1_curr, ns->ns_rxstart);
  131.       outb (nec+ds_cmd, DSCM_NODMA|DSCM_PG0|DSCM_START);
  132. !     if (ns->ns_if.if_flags & IFF_PROMISC)
  133. !         outb (nec+ds0_rcr, DSRC_AB|DSRC_PRO);
  134. !     else
  135. !         outb (nec+ds0_rcr, DSRC_AB);
  136.       outb(nec+ds0_dcr, ns->ns_mode);
  137.       outb (nec+ds0_imr, 0xff);
  138.   
  139. ***************
  140. *** 417,435 ****
  141.           
  142.       m = m0;
  143.       total = t;
  144.       for (m0 = m; m != 0; ) {
  145. -         
  146.           if (m->m_len&1 && t > m->m_len) {
  147. !             neput(ns, mtod(m, caddr_t), buffer, m->m_len - 1);
  148. !             t -= m->m_len - 1;
  149. !             buffer += m->m_len - 1;
  150. !             m->m_data += m->m_len - 1;
  151.               m->m_len = 1;
  152.               m = m_pullup(m, 2);
  153.           } else {
  154.               neput(ns, mtod(m, caddr_t), buffer, m->m_len);
  155. -             buffer += m->m_len;
  156.               t -= m->m_len;
  157.               MFREE(m, m0);
  158.               m = m0;
  159.           }
  160. --- 449,473 ----
  161.           
  162.       m = m0;
  163.       total = t;
  164. + #if NBPFILTER > 0
  165. +     if (ns->ns_bpf)
  166. +         bpf_mtap(ns->ns_bpf, m);
  167. + #endif
  168.       for (m0 = m; m != 0; ) {
  169.           if (m->m_len&1 && t > m->m_len) {
  170. !             m->m_len -= 1;
  171. !             neput(ns, mtod(m, caddr_t), buffer, m->m_len);
  172. !             t -= m->m_len;
  173. !             buffer += m->m_len;
  174. !             m->m_data += m->m_len;
  175.               m->m_len = 1;
  176.               m = m_pullup(m, 2);
  177.           } else {
  178.               neput(ns, mtod(m, caddr_t), buffer, m->m_len);
  179.               t -= m->m_len;
  180. +             buffer += m->m_len;
  181.               MFREE(m, m0);
  182.               m = m0;
  183.           }
  184. ***************
  185. *** 648,653 ****
  186. --- 686,703 ----
  187.   
  188.       if (len == 0) return;
  189.   
  190. + #if NBPFILTER > 0
  191. +     if (ns->ns_bpf)
  192. +         bpf_tap(ns->ns_bpf, buf, len + sizeof(struct ether_header));
  193. + #endif
  194. +     if ((ns->ns_if.if_flags & IFF_PROMISC)
  195. +         && bcmp(eh->ether_dhost, ns->ns_addr,
  196. +             sizeof(eh->ether_dhost)) != 0
  197. +         && bcmp(eh->ether_dhost, etherbroadcastaddr,
  198. +             sizeof(eh->ether_dhost)) != 0)
  199. +         return;
  200.       /*
  201.        * Pull packet off interface.  Off is nonzero if packet
  202.        * has trailing header; neget will then force this header
  203. ***************
  204. *** 797,802 ****
  205. --- 847,857 ----
  206.           break;
  207.   
  208.       case SIOCSIFFLAGS:
  209. + #ifdef NEDEBUG
  210. +         printf ("ne: setting flags, up: %s, running: %s\n",
  211. +             ifp->if_flags & IFF_UP ? "yes" : "no",
  212. +             ifp->if_flags & IFF_RUNNING ? "yes" : "no");
  213. + #endif
  214.           if ((ifp->if_flags & IFF_UP) == 0 &&
  215.               ifp->if_flags & IFF_RUNNING) {
  216.               ifp->if_flags &= ~IFF_RUNNING;
  217. -----8<-----snip-----8<-----snip-----8<-----snip-----8<-----snip-----8<-----
  218.  
  219. -- 
  220.  \  /   Charles Hannum, mycroft@ai.mit.edu
  221.  /\ \   PGP public key available on request.  MIME, AMS, NextMail accepted.
  222. Scheme  White heterosexual atheist male (WHAM) pride!
  223.