inverse-inc / packetfence

PacketFence is a fully supported, trusted, Free and Open Source network access control (NAC) solution. Boasting an impressive feature set including a captive-portal for registration and remediation, centralized wired and wireless management, powerful BYOD management options, 802.1X support, layer-2 isolation of problematic devices; PacketFence can be used to effectively secure networks small to very large heterogeneous networks.
https://packetfence.org
GNU General Public License v2.0
1.38k stars 289 forks source link

Searching by 'Source Switch Identifier' for a switch range doesn't work #5792

Closed julsemaan closed 4 years ago

julsemaan commented 4 years ago

Describe the bug When you use the switch group search menu on the left in the nodes and search for a switch range, the search is inconsistent with how the data is stored in the DB.

To Reproduce

  1. Create a switch range 10.0.0.0/24 part of the default switch group
  2. Insert the following row in the locationlog (data from a valid RADIUS request):
          tenant_id: 1
                mac: 02:00:00:00:00:01
             switch: 10.9.8.7
               port: 0
               vlan: 2
               role: registration
    connection_type: Wireless-802.11-EAP
    connection_sub_type: 26
     dot1x_username: administrator
               ssid: 
         start_time: 2020-09-14 08:09:36
           end_time: 0000-00-00 00:00:00
          switch_ip: 10.9.8.7
         switch_mac: NULL
    stripped_user_name: administrator
              realm: null
         session_id: NULL
             ifDesc: NULL
               voip: no
  3. Insert the following node if necessary
          tenant_id: 1
                mac: 02:00:00:00:00:01
                pid: default
        category_id: NULL
        detect_date: 2020-09-14 07:59:40
            regdate: 0000-00-00 00:00:00
          unregdate: 0000-00-00 00:00:00
           lastskip: 0000-00-00 00:00:00
       time_balance: NULL
    bandwidth_balance: NULL
             status: unreg
         user_agent: NULL
       computername: NULL
              notes: NULL
           last_arp: 0000-00-00 00:00:00
          last_dhcp: 0000-00-00 00:00:00
    dhcp_fingerprint: NULL
    dhcp6_fingerprint: NULL
        dhcp_vendor: NULL
    dhcp6_enterprise: NULL
        device_type: NULL
       device_class: NULL
     device_version: NULL
       device_score: NULL
    device_manufacturer: NULL
        bypass_vlan: NULL
               voip: no
            autoreg: no
          sessionid: NULL
    machine_account: NULL
     bypass_role_id: NULL
          last_seen: 2020-09-14 08:11:25
  4. Go in the Nodes, then expand 'Switch Groups' and then expand default and then click on '10.0.0.0/8'
  5. It will search for 'Source Switch Identifier' '10.0.0.0/8' and the backend will not expand this value to search for all the switches in that range so our entry will not show up

Expected behavior When searching for a switch range, all the nodes that are connected in a switch in that switch range should show up

Additional context This is on 10.1.0 in the new admin but I tested on 8.1.0 in the old admin and it was also broken.

satkunas commented 4 years ago

There's a couple different ways we can deal with switch/netmask. We can either change/add a locationlog.switch_ip db column as an INT so we can use > and < operators, otherwise the network has to be split into compound ORs using string operators starts_with, which can generate pretty verbose statements using many ORs across large subnets.

Example, 10.0.0.0/9 = range 10.0.0.1 - 10.127.255.254, thus we'd need to concat 128 OR statements to filter/search properly using string (locationlog.switch_ip starts_with '10.0.' or locationlog.switch_ip starts_with '10.1.' ... locationlog.switch_ip starts_with '10.127.')

julsemaan commented 4 years ago

For the maintenance: could we use a starts_with for the masks that can work in strings (/8, /16, /24, /32) and show an error to the user for the other masks ?

Then for the real fix, I think storing the switch as an int in another field would be useful for searching.

Using the string representation to search uncommon masks will be too messy like @satkunas described.

Could we implement a fix for the maintenance so that it works for common subnets and provides an error to users for subnets we can't support at the moment?