/src/suricata7/rust/src/dhcp/detect.rs
Line | Count | Source |
1 | | /* Copyright (C) 2022 Open Information Security Foundation |
2 | | * |
3 | | * You can copy, redistribute or modify this Program under the terms of |
4 | | * the GNU General Public License version 2 as published by the Free |
5 | | * Software Foundation. |
6 | | * |
7 | | * This program is distributed in the hope that it will be useful, |
8 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 | | * GNU General Public License for more details. |
11 | | * |
12 | | * You should have received a copy of the GNU General Public License |
13 | | * version 2 along with this program; if not, write to the Free Software |
14 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
15 | | * 02110-1301, USA. |
16 | | */ |
17 | | |
18 | | use super::dhcp::{ |
19 | | DHCPTransaction, DHCP_OPT_ADDRESS_TIME, DHCP_OPT_REBINDING_TIME, DHCP_OPT_RENEWAL_TIME, |
20 | | }; |
21 | | use super::parser::DHCPOptionWrapper; |
22 | | |
23 | | #[no_mangle] |
24 | 6 | pub unsafe extern "C" fn rs_dhcp_tx_get_leasetime( |
25 | 6 | tx: &mut DHCPTransaction, leasetime: *mut u64, |
26 | 6 | ) -> u8 { |
27 | 28 | for option in &tx.message.options { |
28 | 23 | if option.code == DHCP_OPT_ADDRESS_TIME { |
29 | 1 | if let DHCPOptionWrapper::TimeValue(ref time_value) = option.option { |
30 | 1 | *leasetime = time_value.seconds as u64; |
31 | 1 | return 1; |
32 | 0 | } |
33 | 22 | } |
34 | | } |
35 | 5 | return 0; |
36 | 6 | } |
37 | | |
38 | | #[no_mangle] |
39 | 6 | pub unsafe extern "C" fn rs_dhcp_tx_get_rebinding_time( |
40 | 6 | tx: &mut DHCPTransaction, res: *mut u64, |
41 | 6 | ) -> u8 { |
42 | 30 | for option in &tx.message.options { |
43 | 25 | if option.code == DHCP_OPT_REBINDING_TIME { |
44 | 1 | if let DHCPOptionWrapper::TimeValue(ref time_value) = option.option { |
45 | 1 | *res = time_value.seconds as u64; |
46 | 1 | return 1; |
47 | 0 | } |
48 | 24 | } |
49 | | } |
50 | 5 | return 0; |
51 | 6 | } |
52 | | |
53 | | #[no_mangle] |
54 | 5 | pub unsafe extern "C" fn rs_dhcp_tx_get_renewal_time( |
55 | 5 | tx: &mut DHCPTransaction, res: *mut u64, |
56 | 5 | ) -> u8 { |
57 | 25 | for option in &tx.message.options { |
58 | 21 | if option.code == DHCP_OPT_RENEWAL_TIME { |
59 | 1 | if let DHCPOptionWrapper::TimeValue(ref time_value) = option.option { |
60 | 1 | *res = time_value.seconds as u64; |
61 | 1 | return 1; |
62 | 0 | } |
63 | 20 | } |
64 | | } |
65 | 4 | return 0; |
66 | 5 | } |