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/uts/common/inet/ipf/solaris.c
          +++ new/usr/src/uts/common/inet/ipf/solaris.c
   1    1  /*
   2    2   * Copyright (C) 1993-2001, 2003 by Darren Reed.
   3    3   *
   4    4   * See the IPFILTER.LICENCE file for details on licencing.
   5    5   *
   6    6   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
   7    7   * Use is subject to license terms.
   8    8   *
   9      - * Copyright (c) 2014, Joyent, Inc.  All rights reserved.
        9 + * Copyright 2019 Joyent, Inc.
  10   10   */
  11   11  
  12   12  /*
  13   13   * ipfilter kernel module mutexes and locking:
  14   14   *
  15   15   * Enabling ipfilter creates a per-netstack ipf_stack_t object that is
  16   16   * stored in the ipf_stacks list, which is protected by ipf_stack_lock.
  17   17   * ipf_stack_t objects are accessed in three contexts:
  18   18   *
  19   19   * 1) administering that filter (eg: ioctls handled with iplioctl())
↓ open down ↓ 89 lines elided ↑ open up ↑
 109  109  static  int     ipf_identify __P((dev_info_t *));
 110  110  #endif
 111  111  static  int     ipf_attach __P((dev_info_t *, ddi_attach_cmd_t));
 112  112  static  int     ipf_detach __P((dev_info_t *, ddi_detach_cmd_t));
 113  113  static  void    *ipf_stack_create __P((const netid_t));
 114  114  static  void    ipf_stack_destroy __P((const netid_t, void *));
 115  115  static  void    ipf_stack_shutdown __P((const netid_t, void *));
 116  116  static  int     ipf_property_g_update __P((dev_info_t *));
 117  117  static  char    *ipf_devfiles[] = { IPL_NAME, IPNAT_NAME, IPSTATE_NAME,
 118  118                                      IPAUTH_NAME, IPSYNC_NAME, IPSCAN_NAME,
 119      -                                    IPLOOKUP_NAME, NULL };
      119 +                                    IPLOOKUP_NAME, IPFEV_NAME, NULL };
 120  120  extern void     *ipf_state;     /* DDI state */
 121  121  extern vmem_t   *ipf_minor;     /* minor number arena */
 122  122  
 123  123  static struct cb_ops ipf_cb_ops = {
 124  124          iplopen,
 125  125          iplclose,
 126  126          nodev,          /* strategy */
 127  127          nodev,          /* print */
 128  128          nodev,          /* dump */
 129  129          iplread,
↓ open down ↓ 604 lines elided ↑ open up ↑
 734  734                          if (s == NULL)
 735  735                                  continue;
 736  736                          s++;
 737  737                          if (ddi_create_minor_node(dip, s, S_IFCHR, i,
 738  738                              DDI_PSEUDO, 0) == DDI_FAILURE)
 739  739                                  goto attach_failed;
 740  740                  }
 741  741  
 742  742                  ipf_dev_info = dip;
 743  743  
      744 +                if (ipf_cfw_ring_resize(IPF_CFW_RING_ALLOCATE) != 0)
      745 +                        goto attach_failed;
      746 +
 744  747                  ipfncb = net_instance_alloc(NETINFO_VERSION);
 745  748                  if (ipfncb == NULL)
 746  749                          goto attach_failed;
 747  750  
 748  751                  ipfncb->nin_name = "ipf";
 749  752                  ipfncb->nin_create = ipf_stack_create;
 750  753                  ipfncb->nin_destroy = ipf_stack_destroy;
 751  754                  ipfncb->nin_shutdown = ipf_stack_shutdown;
 752  755                  if (net_instance_register(ipfncb) == DDI_FAILURE) {
 753  756                          net_instance_free(ipfncb);
↓ open down ↓ 7 lines elided ↑ open up ↑
 761  764                  cmn_err(CE_CONT, "IP Filter:stack_create callback_reg=%d", i);
 762  765  #endif
 763  766  
 764  767                  return (DDI_SUCCESS);
 765  768                  /* NOTREACHED */
 766  769          default:
 767  770                  break;
 768  771          }
 769  772  
 770  773  attach_failed:
      774 +        (void) ipf_cfw_ring_resize(IPF_CFW_RING_DESTROY);
 771  775          ddi_remove_minor_node(dip, NULL);
 772  776          ddi_prop_remove_all(dip);
 773  777          ddi_soft_state_fini(&ipf_state);
 774  778          return (DDI_FAILURE);
 775  779  }
 776  780  
 777  781  
 778  782  static int ipf_detach(dip, cmd)
 779  783  dev_info_t *dip;
 780  784  ddi_detach_cmd_t cmd;
↓ open down ↓ 7 lines elided ↑ open up ↑
 788  792          case DDI_DETACH:
 789  793                  if (ipf_detach_check_all() != 0)
 790  794                          return (DDI_FAILURE);
 791  795  
 792  796                  /*
 793  797                   * Undo what we did in ipf_attach, freeing resources
 794  798                   * and removing things we installed.  The system
 795  799                   * framework guarantees we are not active with this devinfo
 796  800                   * node in any other entry points at this time.
 797  801                   */
      802 +                (void) ipf_cfw_ring_resize(IPF_CFW_RING_DESTROY);
 798  803                  ddi_prop_remove_all(dip);
 799  804                  i = ddi_get_instance(dip);
 800  805                  ddi_remove_minor_node(dip, NULL);
 801  806                  if (i > 0) {
 802  807                          cmn_err(CE_CONT, "IP Filter: still attached (%d)\n", i);
 803  808                          return (DDI_FAILURE);
 804  809                  }
 805  810  
 806  811                  vmem_destroy(ipf_minor);
 807  812                  ddi_soft_state_fini(&ipf_state);
↓ open down ↓ 108 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX