[pve-devel] [PATCH proxmox-firewall 09/37] config: firewall: add types for rules

Lukas Wagner l.wagner at proxmox.com
Tue Apr 9 16:55:47 CEST 2024


On  2024-04-03 12:46, Max Carrara wrote:
>> +
>> +#[derive(Clone, Debug)]
>> +#[cfg_attr(test, derive(Eq, PartialEq))]
>> +pub enum IcmpType {
>> +    Numeric(u8),
>> +    Named(&'static str),
>> +}
>> +
>> +// MUST BE SORTED!
> 
> Should maaaybe note that it must be sorted for binary search, not just
> for any reason. :P
> 
>> +const ICMP_TYPES: &[(&str, u8)] = &[
>> +    ("address-mask-reply", 18),
>> +    ("address-mask-request", 17),
>> +    ("destination-unreachable", 3),
>> +    ("echo-reply", 0),
>> +    ("echo-request", 8),
>> +    ("info-reply", 16),
>> +    ("info-request", 15),
>> +    ("parameter-problem", 12),
>> +    ("redirect", 5),
>> +    ("router-advertisement", 9),
>> +    ("router-solicitation", 10),
>> +    ("source-quench", 4),
>> +    ("time-exceeded", 11),
>> +    ("timestamp-reply", 14),
>> +    ("timestamp-request", 13),
>> +];

I think `proxmox-sortable-macro` might come in handy here. From its examples:

    #[sortable]
    const FOO2: [(&str, usize); 3] = sorted!([("3", 1), ("2", 2), ("1", 3)]);
    assert_eq!(FOO2, [("1", 3), ("2", 2), ("3", 1)]);


-- 
- Lukas




More information about the pve-devel mailing list