Print this page
3168 pfmod commands could be more useful


   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 #pragma ident   "%Z%%M% %I%     %E% SMI"
  27 
  28 /*
  29  * STREAMS Packet Filter Module
  30  *
  31  * This module applies a filter to messages arriving on its read
  32  * queue, passing on messages that the filter accepts adn discarding
  33  * the others.  It supports ioctls for setting the filter.
  34  *
  35  * On the write side, the module simply passes everything through
  36  * unchanged.
  37  *
  38  * Based on SunOS 4.x version.  This version has minor changes:
  39  *      - general SVR4 porting stuff
  40  *      - change name and prefixes from "nit" buffer to streams buffer
  41  *      - multithreading assumes configured as D_MTQPAIR
  42  */
  43 
  44 #include <sys/types.h>
  45 #include <sys/sysmacros.h>
  46 #include <sys/errno.h>
  47 #include <sys/debug.h>
  48 #include <sys/time.h>
  49 #include <sys/stropts.h>
  50 #include <sys/stream.h>
  51 #include <sys/conf.h>
  52 #include <sys/ddi.h>
  53 #include <sys/sunddi.h>
  54 #include <sys/kmem.h>
  55 #include <sys/strsun.h>
  56 #include <sys/pfmod.h>
  57 #include <sys/modctl.h>

  58 
  59 /*
  60  * Expanded version of the Packetfilt structure that includes
  61  * some additional fields that aid filter execution efficiency.
  62  */
  63 struct epacketfilt {
  64         struct Pf_ext_packetfilt        pf;
  65 #define pf_Priority     pf.Pf_Priority
  66 #define pf_FilterLen    pf.Pf_FilterLen
  67 #define pf_Filter       pf.Pf_Filter
  68         /* pointer to word immediately past end of filter */
  69         ushort_t                *pf_FilterEnd;
  70         /* length in bytes of packet prefix the filter examines */
  71         ushort_t                pf_PByteLen;
  72 };
  73 
  74 /*
  75  * (Internal) packet descriptor for FilterPacket
  76  */
  77 struct packdesc {


 417 
 418                         case ENF_LOAD_OFFSET:
 419                                 /* Point to the offset */
 420                                 fwp++;
 421                                 if (*fwp > maxoffreg)
 422                                         maxoffreg = *fwp;
 423                                 break;
 424 
 425                         case ENF_PUSHLIT:
 426                         case ENF_BRTR:
 427                         case ENF_BRFL:
 428                                 /* Skip over the literal. */
 429                                 fwp++;
 430                                 break;
 431 
 432                         case ENF_PUSHZERO:
 433                         case ENF_PUSHONE:
 434                         case ENF_PUSHFFFF:
 435                         case ENF_PUSHFF00:
 436                         case ENF_PUSH00FF:


 437                         case ENF_NOPUSH:
 438                         case ENF_POP:
 439                                 break;
 440                         }
 441                 }
 442 
 443                 /*
 444                  * Convert word offset to length in bytes.
 445                  */
 446                 pfp->pf_PByteLen = (maxoff + maxoffreg + 1) * sizeof (ushort_t);
 447                 miocack(wq, mp, 0, 0);
 448                 break;
 449 
 450         default:
 451                 putnext(wq, mp);
 452                 break;
 453         }
 454 }
 455 
 456 /* #define      DEBUG   1 */


 529                 }
 530                 break;
 531         case ENF_PUSHLIT:
 532                 *--sp = *fp++;
 533                 break;
 534         case ENF_PUSHZERO:
 535                 *--sp = 0;
 536                 break;
 537         case ENF_PUSHONE:
 538                 *--sp = 1;
 539                 break;
 540         case ENF_PUSHFFFF:
 541                 *--sp = 0xffff;
 542                 break;
 543         case ENF_PUSHFF00:
 544                 *--sp = 0xff00;
 545                 break;
 546         case ENF_PUSH00FF:
 547                 *--sp = 0x00ff;
 548                 break;






 549         case ENF_LOAD_OFFSET:
 550                 offreg = *fp++;
 551                 break;
 552         case ENF_BRTR:
 553                 if (*sp != 0)
 554                         fp += *fp;
 555                 else
 556                         fp++;
 557                 if (fp >= fpe) {
 558                         enprintf(("BRTR: fp>=fpe\n"));
 559                         return (0);
 560                 }
 561                 break;
 562         case ENF_BRFL:
 563                 if (*sp == 0)
 564                         fp += *fp;
 565                 else
 566                         fp++;
 567                 if (fp >= fpe) {
 568                         enprintf(("BRFL: fp>=fpe\n"));




   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 


  26 /*
  27  * STREAMS Packet Filter Module
  28  *
  29  * This module applies a filter to messages arriving on its read
  30  * queue, passing on messages that the filter accepts adn discarding
  31  * the others.  It supports ioctls for setting the filter.
  32  *
  33  * On the write side, the module simply passes everything through
  34  * unchanged.
  35  *
  36  * Based on SunOS 4.x version.  This version has minor changes:
  37  *      - general SVR4 porting stuff
  38  *      - change name and prefixes from "nit" buffer to streams buffer
  39  *      - multithreading assumes configured as D_MTQPAIR
  40  */
  41 
  42 #include <sys/types.h>
  43 #include <sys/sysmacros.h>
  44 #include <sys/errno.h>
  45 #include <sys/debug.h>
  46 #include <sys/time.h>
  47 #include <sys/stropts.h>
  48 #include <sys/stream.h>
  49 #include <sys/conf.h>
  50 #include <sys/ddi.h>
  51 #include <sys/sunddi.h>
  52 #include <sys/kmem.h>
  53 #include <sys/strsun.h>
  54 #include <sys/pfmod.h>
  55 #include <sys/modctl.h>
  56 #include <netinet/in.h>
  57 
  58 /*
  59  * Expanded version of the Packetfilt structure that includes
  60  * some additional fields that aid filter execution efficiency.
  61  */
  62 struct epacketfilt {
  63         struct Pf_ext_packetfilt        pf;
  64 #define pf_Priority     pf.Pf_Priority
  65 #define pf_FilterLen    pf.Pf_FilterLen
  66 #define pf_Filter       pf.Pf_Filter
  67         /* pointer to word immediately past end of filter */
  68         ushort_t                *pf_FilterEnd;
  69         /* length in bytes of packet prefix the filter examines */
  70         ushort_t                pf_PByteLen;
  71 };
  72 
  73 /*
  74  * (Internal) packet descriptor for FilterPacket
  75  */
  76 struct packdesc {


 416 
 417                         case ENF_LOAD_OFFSET:
 418                                 /* Point to the offset */
 419                                 fwp++;
 420                                 if (*fwp > maxoffreg)
 421                                         maxoffreg = *fwp;
 422                                 break;
 423 
 424                         case ENF_PUSHLIT:
 425                         case ENF_BRTR:
 426                         case ENF_BRFL:
 427                                 /* Skip over the literal. */
 428                                 fwp++;
 429                                 break;
 430 
 431                         case ENF_PUSHZERO:
 432                         case ENF_PUSHONE:
 433                         case ENF_PUSHFFFF:
 434                         case ENF_PUSHFF00:
 435                         case ENF_PUSH00FF:
 436                         case ENF_PUSHFF00_N:
 437                         case ENF_PUSH00FF_N:
 438                         case ENF_NOPUSH:
 439                         case ENF_POP:
 440                                 break;
 441                         }
 442                 }
 443 
 444                 /*
 445                  * Convert word offset to length in bytes.
 446                  */
 447                 pfp->pf_PByteLen = (maxoff + maxoffreg + 1) * sizeof (ushort_t);
 448                 miocack(wq, mp, 0, 0);
 449                 break;
 450 
 451         default:
 452                 putnext(wq, mp);
 453                 break;
 454         }
 455 }
 456 
 457 /* #define      DEBUG   1 */


 530                 }
 531                 break;
 532         case ENF_PUSHLIT:
 533                 *--sp = *fp++;
 534                 break;
 535         case ENF_PUSHZERO:
 536                 *--sp = 0;
 537                 break;
 538         case ENF_PUSHONE:
 539                 *--sp = 1;
 540                 break;
 541         case ENF_PUSHFFFF:
 542                 *--sp = 0xffff;
 543                 break;
 544         case ENF_PUSHFF00:
 545                 *--sp = 0xff00;
 546                 break;
 547         case ENF_PUSH00FF:
 548                 *--sp = 0x00ff;
 549                 break;
 550         case ENF_PUSHFF00_N:
 551                 *--sp = htons(0xff00);
 552                 break;
 553         case ENF_PUSH00FF_N:
 554                 *--sp = htons(0x00ff);
 555                 break;
 556         case ENF_LOAD_OFFSET:
 557                 offreg = *fp++;
 558                 break;
 559         case ENF_BRTR:
 560                 if (*sp != 0)
 561                         fp += *fp;
 562                 else
 563                         fp++;
 564                 if (fp >= fpe) {
 565                         enprintf(("BRTR: fp>=fpe\n"));
 566                         return (0);
 567                 }
 568                 break;
 569         case ENF_BRFL:
 570                 if (*sp == 0)
 571                         fp += *fp;
 572                 else
 573                         fp++;
 574                 if (fp >= fpe) {
 575                         enprintf(("BRFL: fp>=fpe\n"));