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

Database error on node_add_simple #4945

Closed fdurand closed 4 years ago

fdurand commented 4 years ago

Describe the bug If it's the first time a device appear on the network then packetfence try to add twice an entry in the node table.

The dhcp process is to quick between a request and a ack than packetfence detect that the device is not yet in the database so the second node_add_simple return a error message:

Nov 19 17:24:26 e21svcpfwifi pfqueue: pfqueue(5806) ERROR: [mac:unknown] Database query failed with non retryable error: Duplicate entry '1-90:61:ae:0e:ec:4b' for key 'PRIMARY' (errno: 1062) [INSERT INTO `node` ( `autoreg`, `bandwidth_balance`, `bypass_role_id`, `bypass_vlan`, `category_id`, `computername`, `detect_date`, `device_class`, `device_manufacturer`, `device_score`, `device_type`, `device_version`, `dhcp6_enterprise`, `dhcp6_fingerprint`, `dhcp_fingerprint`, `dhcp_vendor`, `last_arp`, `last_dhcp`, `last_seen`, `lastskip`, `mac`, `machine_account`, `notes`, `pid`, `regdate`, `sessionid`, `status`, `tenant_id`, `time_balance`, `unregdate`, `user_agent`, `voip`) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )]{no, NULL, NULL, , NULL, , 2019-11-19 17:24:26, NULL, NULL, NULL, NULL, NULL, NULL, NULL, , NULL, 0000-00-00 00:00:00, 0000-00-00 00:00:00, 0000-00-00 00:00:00, 0000-00-00 00:00:00, 90:61:ae:0e:ec:4b, NULL, , default, 0000-00-00 00:00:00, , unreg, 1, NULL, 0000-00-00 00:00:00, , no} (pf::dal::db_execute)

We should use REPLACE instead of INSERT

satkunas commented 4 years ago

Use INSERT IGNORE

fdurand commented 4 years ago

Do we update the query with "INSERT IGNORE" ?

jrouzierinverse commented 4 years ago

It makes sense as replace will reset any fields add unless that is what you want?

fdurand commented 4 years ago

Ok so let's go for it.