Print this page
OS-7667 IPFilter needs to keep and report state for cloud firewall logging
Portions contributed by: Mike Gerdts <mike.gerdts@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/ipf/tools/ipf_y.y
          +++ new/usr/src/cmd/ipf/tools/ipf_y.y
   1    1  %{
   2    2  /*
   3    3   * Copyright (C) 2003 by Darren Reed.
   4    4   *
   5    5   * See the IPFILTER.LICENCE file for details on licencing.
   6    6   *
   7    7   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
   8    8   * Use is subject to license terms.
        9 + * Copyright 2019 Joyent, Inc.
   9   10   */
  10   11  
  11   12  #include "ipf.h"
  12   13  #include <sys/ioctl.h>
  13   14  #include <syslog.h>
  14   15  #ifdef IPFILTER_BPF
  15   16  # include "pcap-bpf.h"
  16   17  # define _NET_BPF_H_
  17   18  # include <pcap.h>
  18   19  #endif
       20 +#include <uuid/uuid.h>
  19   21  #include "netinet/ip_pool.h"
  20   22  #include "netinet/ip_htable.h"
  21   23  #include "netinet/ipl.h"
  22   24  #include "ipf_l.h"
  23   25  
  24   26  #define YYDEBUG 1
  25   27  #define DOALL(x)        for (fr = frc; fr != NULL; fr = fr->fr_next) { x }
  26   28  #define DOREM(x)        for (; fr != NULL; fr = fr->fr_next) { x }
  27   29  
  28   30  #define OPTION_LOG              0x1
↓ open down ↓ 62 lines elided ↑ open up ↑
  91   93          struct  {
  92   94                  u_short p1;
  93   95                  u_short p2;
  94   96                  int     pc;
  95   97          } pc;
  96   98          struct  {
  97   99                  union   i6addr  a;
  98  100                  union   i6addr  m;
  99  101          } ipp;
 100  102          union   i6addr  ip6;
      103 +        uuid_t  uuid;
 101  104  };
 102  105  
 103  106  %type   <port>  portnum
 104  107  %type   <num>   facility priority icmpcode seclevel secname icmptype
 105  108  %type   <num>   opt compare range opttype flagset optlist ipv6hdrlist ipv6hdr
 106  109  %type   <num>   portc porteq
 107  110  %type   <ipa>   ipv4 ipv4_16 ipv4_24
 108  111  %type   <ip6>   hostname mask
 109  112  %type   <ipp>   addr ipaddr
 110  113  %type   <str>   servicename name interfacename
 111  114  %type   <pc>    portrange portcomp
 112  115  %type   <alist> addrlist poollist
 113  116  
 114  117  %token  <num>   YY_NUMBER YY_HEX
 115  118  %token  <str>   YY_STR
 116  119  %token          YY_COMMENT
 117  120  %token          YY_CMP_EQ YY_CMP_NE YY_CMP_LE YY_CMP_GE YY_CMP_LT YY_CMP_GT
 118  121  %token          YY_RANGE_OUT YY_RANGE_IN
 119  122  %token  <ip6>   YY_IPV6
      123 +%token  <uuid>  YY_UUID
 120  124  
 121  125  %token  IPFY_PASS IPFY_BLOCK IPFY_COUNT IPFY_CALL
 122  126  %token  IPFY_RETICMP IPFY_RETRST IPFY_RETICMPASDST
 123  127  %token  IPFY_IN IPFY_OUT
 124  128  %token  IPFY_QUICK IPFY_ON IPFY_OUTVIA IPFY_INVIA
 125  129  %token  IPFY_DUPTO IPFY_TO IPFY_FROUTE IPFY_REPLY_TO IPFY_ROUTETO
 126  130  %token  IPFY_TOS IPFY_TTL IPFY_PROTO
 127  131  %token  IPFY_HEAD IPFY_GROUP
 128  132  %token  IPFY_AUTH IPFY_PREAUTH
 129  133  %token  IPFY_LOG IPFY_BODY IPFY_FIRST IPFY_LEVEL IPFY_ORBLOCK
      134 +%token  IPFY_UUID IPFY_CFWLOG
 130  135  %token  IPFY_LOGTAG IPFY_MATCHTAG IPFY_SETTAG IPFY_SKIP
 131  136  %token  IPFY_FROM IPFY_ALL IPFY_ANY IPFY_BPFV4 IPFY_BPFV6 IPFY_POOL IPFY_HASH
 132  137  %token  IPFY_PPS
 133  138  %token  IPFY_ESP IPFY_AH
 134  139  %token  IPFY_WITH IPFY_AND IPFY_NOT IPFY_NO IPFY_OPT
 135  140  %token  IPFY_TCPUDP IPFY_TCP IPFY_UDP
 136  141  %token  IPFY_FLAGS IPFY_MULTICAST
 137  142  %token  IPFY_MASK IPFY_BROADCAST IPFY_NETWORK IPFY_NETMASKED IPFY_PEER
 138  143  %token  IPFY_PORT
 139  144  %token  IPFY_NOW
↓ open down ↓ 371 lines elided ↑ open up ↑
 511  516          ;
 512  517  
 513  518  taginlist:
 514  519          taginspec
 515  520          | taginlist ',' taginspec
 516  521          ;
 517  522  
 518  523  taginspec:
 519  524          logtag
 520  525          |nattag
      526 +        |uuidtag
      527 +        |cfwtag
 521  528          ;
 522  529  
 523  530  nattag: IPFY_NAT '=' YY_STR             { DOALL(strncpy(fr->fr_nattag.ipt_tag,\
 524  531                                                  $3, IPFTAG_LEN););
 525  532                                            free($3); }
 526  533          | IPFY_NAT '=' YY_NUMBER        { DOALL(sprintf(fr->fr_nattag.ipt_tag,\
 527  534                                                  "%d", $3 & 0xffffffff);) }
 528  535          ;
 529  536  
 530  537  logtag: IPFY_LOG '=' YY_NUMBER          { DOALL(fr->fr_logtag = $3;) }
 531  538          ;
 532  539  
      540 +cfwtag: IPFY_CFWLOG                     { DOALL(fr->fr_flags |= FR_CFWLOG;) }
      541 +        ;
      542 +
      543 +uuidtag: IPFY_UUID '=' YY_UUID          { DOALL(uuid_copy(fr->fr_uuid, $3);) }
      544 +        ;
      545 +
 533  546  settagout:
 534  547          | IPFY_SETTAG '(' tagoutlist ')'
 535  548          ;
 536  549  
 537  550  tagoutlist:
 538  551          tagoutspec
 539  552          | tagoutlist ',' tagoutspec
 540  553          ;
 541  554  
 542  555  tagoutspec:
 543  556          logtag
 544  557          | nattag
      558 +        | uuidtag
      559 +        | cfwtag
 545  560          ;
 546  561  
 547  562  matchtagin:
 548  563          | IPFY_MATCHTAG '(' tagoutlist ')'
 549  564          ;
 550  565  
 551  566  matchtagout:
 552  567          | IPFY_MATCHTAG '(' taginlist ')'
 553  568          ;
 554  569  
↓ open down ↓ 1004 lines elided ↑ open up ↑
1559 1574          { "bad-nat",                    IPFY_BADNAT },
1560 1575          { "bad-src",                    IPFY_BADSRC },
1561 1576          { "bcast",                      IPFY_BROADCAST },
1562 1577          { "block",                      IPFY_BLOCK },
1563 1578          { "body",                       IPFY_BODY },
1564 1579          { "bpf-v4",                     IPFY_BPFV4 },
1565 1580  #ifdef USE_INET6
1566 1581          { "bpf-v6",                     IPFY_BPFV6 },
1567 1582  #endif
1568 1583          { "call",                       IPFY_CALL },
     1584 +        { "cfwlog",                     IPFY_CFWLOG },
1569 1585          { "code",                       IPFY_ICMPCODE },
1570 1586          { "count",                      IPFY_COUNT },
1571 1587          { "dup-to",                     IPFY_DUPTO },
1572 1588          { "eq",                         YY_CMP_EQ },
1573 1589          { "esp",                        IPFY_ESP },
1574 1590          { "fastroute",                  IPFY_FROUTE },
1575 1591          { "first",                      IPFY_FIRST },
1576 1592          { "flags",                      IPFY_FLAGS },
1577 1593          { "frag",                       IPFY_FRAG },
1578 1594          { "frag-body",                  IPFY_FRAGBODY },
↓ open down ↓ 55 lines elided ↑ open up ↑
1634 1650          { "state",                      IPFY_STATE },
1635 1651          { "state-age",                  IPFY_AGE },
1636 1652          { "strict",                     IPFY_STRICT },
1637 1653          { "sync",                       IPFY_SYNC },
1638 1654          { "tcp",                        IPFY_TCP },
1639 1655          { "tcp-udp",                    IPFY_TCPUDP },
1640 1656          { "tos",                        IPFY_TOS },
1641 1657          { "to",                         IPFY_TO },
1642 1658          { "ttl",                        IPFY_TTL },
1643 1659          { "udp",                        IPFY_UDP },
     1660 +        { "uuid",                       IPFY_UUID },
1644 1661          { "v6hdrs",                     IPF6_V6HDRS },
1645 1662          { "with",                       IPFY_WITH },
1646 1663          { NULL,                         0 }
1647 1664  };
1648 1665  
1649 1666  static  struct  wordtab addrwords[4] = {
1650 1667          { "any",                        IPFY_ANY },
1651 1668          { "hash",                       IPFY_HASH },
1652 1669          { "pool",                       IPFY_POOL },
1653 1670          { NULL,                         0 }
↓ open down ↓ 673 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX