diff --git a/code-generator/src/main.rs b/code-generator/src/main.rs index d2d8337..4456bf1 100644 --- a/code-generator/src/main.rs +++ b/code-generator/src/main.rs @@ -135,7 +135,7 @@ fn main() { let mut attribute_name_to_rfc_name: HashMap = HashMap::new(); for dict_file_path in dict_file_paths { - let (radius_attributes, radius_attribute_to_values_map) = + let ((radius_attributes, radius_attribute_to_values_map), dict_file_lines) = parse_dict_file(dict_file_path).unwrap(); let value_defined_attributes_set = radius_attribute_to_values_map @@ -145,7 +145,7 @@ fn main() { let rfc_name = dict_file_path.extension().unwrap().to_str().unwrap(); let mut w = BufWriter::new(File::create(out_dir.join(format!("{}.rs", rfc_name))).unwrap()); - generate_header(&mut w, &rfc_names); + generate_header(&mut w, &rfc_names, rfc_name, dict_file_lines); generate_attributes_code(&mut w, &radius_attributes, &value_defined_attributes_set); generate_values_code( &mut w, @@ -160,20 +160,39 @@ fn main() { } } -fn generate_header(w: &mut BufWriter, rfc_names: &[String]) { - let code = b"// Code generated by machine generator; DO NOT EDIT. +fn generate_header( + w: &mut BufWriter, + rfc_names: &[String], + rfc_name: &str, + dict_file_lines: io::Lines>, +) { + let code = format!( + "// Code generated by machine generator; DO NOT EDIT. -use std::net::{Ipv4Addr, Ipv6Addr}; +//! Utility for {rfc_name} packet. +//! +//! This module handles the packet according to the following definition: +//! ```text +//! {dict_file_contents} +//! ``` -use chrono::{DateTime, Utc}; +use std::net::{{Ipv4Addr, Ipv6Addr}}; -use crate::core::avp::{AVP, AVPType, AVPError}; +use chrono::{{DateTime, Utc}}; + +use crate::core::avp::{{AVP, AVPType, AVPError}}; use crate::core::packet::Packet; use crate::core::tag::Tag; -"; +", + rfc_name = rfc_name, + dict_file_contents = dict_file_lines + .map(|line| format!("//! {}", line.unwrap())) + .collect::>() + .join("\n"), + ); - w.write_all(code).unwrap(); + w.write_all(code.as_bytes()).unwrap(); for rfc_name in rfc_names { w.write_all(format!("use crate::core::{};\n", rfc_name).as_bytes()) @@ -331,7 +350,7 @@ fn generate_attribute_code( RadiusAttributeValueType::Integer => { match value_defined_attributes_set.contains(&attr_name) { true => match attr.has_tag { - true => generate_value_tagged_defined_integer_attribute_code( + true => generate_tagged_value_defined_integer_attribute_code( w, &method_identifier, &type_identifier, @@ -373,6 +392,7 @@ fn generate_common_attribute_code( let code = format!( " pub const {type_identifier}: AVPType = {type_value}; +/// Delete all of `{method_identifier}` values from a packet. pub fn delete_{method_identifier}(packet: &mut Packet) {{ packet.delete({type_identifier}); }} @@ -390,12 +410,17 @@ fn generate_string_attribute_code( type_identifier: &str, ) { let code = format!( - "pub fn add_{method_identifier}(packet: &mut Packet, value: &str) {{ + "/// Add `{method_identifier}` string value to a packet. +pub fn add_{method_identifier}(packet: &mut Packet, value: &str) {{ packet.add(AVP::from_string({type_identifier}, value)); }} +/// Lookup a `{method_identifier}` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `{method_identifier}`, it returns `None`. pub fn lookup_{method_identifier}(packet: &Packet) -> Option> {{ packet.lookup({type_identifier}).map(|v| v.encode_string()) }} +/// Lookup all of the `{method_identifier}` string value from a packet. pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result, AVPError> {{ let mut vec = Vec::new(); for avp in packet.lookup_all({type_identifier}) {{ @@ -416,12 +441,17 @@ fn generate_tagged_string_attribute_code( type_identifier: &str, ) { let code = format!( - "pub fn add_{method_identifier}(packet: &mut Packet, tag: Option<&Tag>, value: &str) {{ + "/// Add `{method_identifier}` tagged string value to a packet. +pub fn add_{method_identifier}(packet: &mut Packet, tag: Option<&Tag>, value: &str) {{ packet.add(AVP::from_tagged_string({type_identifier}, tag, value)); }} +/// Lookup a `{method_identifier}` tagged string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `{method_identifier}`, it returns `None`. pub fn lookup_{method_identifier}(packet: &Packet) -> Option), AVPError>> {{ packet.lookup({type_identifier}).map(|v| v.encode_tagged_string()) }} +/// Lookup all of the `{method_identifier}` tagged string value from a packet. pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result)>, AVPError> {{ let mut vec = Vec::new(); for avp in packet.lookup_all({type_identifier}) {{ @@ -442,13 +472,18 @@ fn generate_user_password_attribute_code( type_identifier: &str, ) { let code = format!( - "pub fn add_{method_identifier}(packet: &mut Packet, value: &[u8]) -> Result<(), AVPError> {{ + "/// Add `{method_identifier}` user-password value to a packet. +pub fn add_{method_identifier}(packet: &mut Packet, value: &[u8]) -> Result<(), AVPError> {{ packet.add(AVP::from_user_password({type_identifier}, value, packet.get_secret(), packet.get_authenticator())?); Ok(()) }} +/// Lookup a `{method_identifier}` user-password value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `{method_identifier}`, it returns `None`. pub fn lookup_{method_identifier}(packet: &Packet) -> Option, AVPError>> {{ packet.lookup({type_identifier}).map(|v| v.encode_user_password(packet.get_secret(), packet.get_authenticator())) }} +/// Lookup all of the `{method_identifier}` user-password value from a packet. pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result>, AVPError> {{ let mut vec = Vec::new(); for avp in packet.lookup_all({type_identifier}) {{ @@ -469,13 +504,18 @@ fn generate_tunnel_password_attribute_code( type_identifier: &str, ) { let code = format!( - "pub fn add_{method_identifier}(packet: &mut Packet, tag: Option<&Tag>, value: &[u8]) -> Result<(), AVPError> {{ + "/// Add `{method_identifier}` tunnel-password value to a packet. +pub fn add_{method_identifier}(packet: &mut Packet, tag: Option<&Tag>, value: &[u8]) -> Result<(), AVPError> {{ packet.add(AVP::from_tunnel_password({type_identifier}, tag, value, packet.get_secret(), packet.get_authenticator())?); Ok(()) }} +/// Lookup a `{method_identifier}` tunnel-password value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `{method_identifier}`, it returns `None`. pub fn lookup_{method_identifier}(packet: &Packet) -> Option, Tag), AVPError>> {{ packet.lookup({type_identifier}).map(|v| v.encode_tunnel_password(packet.get_secret(), packet.get_authenticator())) }} +/// Lookup all of the `{method_identifier}` tunnel-password value from a packet. pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result, Tag)>, AVPError> {{ let mut vec = Vec::new(); for avp in packet.lookup_all({type_identifier}) {{ @@ -496,12 +536,17 @@ fn generate_octets_attribute_code( type_identifier: &str, ) { let code = format!( - "pub fn add_{method_identifier}(packet: &mut Packet, value: &[u8]) {{ + "/// Add `{method_identifier}` octets value to a packet. +pub fn add_{method_identifier}(packet: &mut Packet, value: &[u8]) {{ packet.add(AVP::from_bytes({type_identifier}, value)); }} +/// Lookup a `{method_identifier}` octets value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `{method_identifier}`, it returns `None`. pub fn lookup_{method_identifier}(packet: &Packet) -> Option> {{ packet.lookup({type_identifier}).map(|v| v.encode_bytes()) }} +/// Lookup all of the `{method_identifier}` octets value from a packet. pub fn lookup_all_{method_identifier}(packet: &Packet) -> Vec> {{ let mut vec = Vec::new(); for avp in packet.lookup_all({type_identifier}) {{ @@ -554,16 +599,21 @@ fn generate_fixed_length_octets_attribute_code( fixed_octets_length: usize, ) { let code = format!( - "pub fn add_{method_identifier}(packet: &mut Packet, value: &[u8]) -> Result<(), AVPError> {{ + "/// Add `{method_identifier}` fixed-length octets value to a packet. +pub fn add_{method_identifier}(packet: &mut Packet, value: &[u8]) -> Result<(), AVPError> {{ if value.len() != {fixed_octets_length} {{ return Err(AVPError::InvalidAttributeLengthError(\"{fixed_octets_length} bytes\".to_owned(), value.len())); }} packet.add(AVP::from_bytes({type_identifier}, value)); Ok(()) }} +/// Lookup a `{method_identifier}` fixed-length octets value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `{method_identifier}`, it returns `None`. pub fn lookup_{method_identifier}(packet: &Packet) -> Option> {{ packet.lookup({type_identifier}).map(|v| v.encode_bytes()) }} +/// Lookup all of the `{method_identifier}` fixed-length octets value from a packet. pub fn lookup_all_{method_identifier}(packet: &Packet) -> Vec> {{ let mut vec = Vec::new(); for avp in packet.lookup_all({type_identifier}) {{ @@ -585,12 +635,17 @@ fn generate_ipaddr_attribute_code( type_identifier: &str, ) { let code = format!( - "pub fn add_{method_identifier}(packet: &mut Packet, value: &Ipv4Addr) {{ + "/// Add `{method_identifier}` ipaddr value to a packet. +pub fn add_{method_identifier}(packet: &mut Packet, value: &Ipv4Addr) {{ packet.add(AVP::from_ipv4({type_identifier}, value)); }} +/// Lookup a `{method_identifier}` ipaddr value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `{method_identifier}`, it returns `None`. pub fn lookup_{method_identifier}(packet: &Packet) -> Option> {{ packet.lookup({type_identifier}).map(|v| v.encode_ipv4()) }} +/// Lookup all of the `{method_identifier}` ipaddr value from a packet. pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result, AVPError> {{ let mut vec = Vec::new(); for avp in packet.lookup_all({type_identifier}) {{ @@ -611,13 +666,18 @@ fn generate_ipv4_prefix_attribute_code( type_identifier: &str, ) { let code = format!( - "pub fn add_{method_identifier}(packet: &mut Packet, value: &[u8]) -> Result<(), AVPError> {{ + "/// Add `{method_identifier}` ipv4 prefix value to a packet. +pub fn add_{method_identifier}(packet: &mut Packet, value: &[u8]) -> Result<(), AVPError> {{ packet.add(AVP::from_ipv4_prefix({type_identifier}, value)?); Ok(()) }} +/// Lookup a `{method_identifier}` ipv4 prefix value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `{method_identifier}`, it returns `None`. pub fn lookup_{method_identifier}(packet: &Packet) -> Option, AVPError>> {{ packet.lookup({type_identifier}).map(|v| v.encode_ipv4_prefix()) }} +/// Lookup all of the `{method_identifier}` ipv4 prefix value from a packet. pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result>, AVPError> {{ let mut vec = Vec::new(); for avp in packet.lookup_all({type_identifier}) {{ @@ -638,12 +698,17 @@ fn generate_ipv6addr_attribute_code( type_identifier: &str, ) { let code = format!( - "pub fn add_{method_identifier}(packet: &mut Packet, value: &Ipv6Addr) {{ + "/// Add `{method_identifier}` ipv6addr value to a packet. +pub fn add_{method_identifier}(packet: &mut Packet, value: &Ipv6Addr) {{ packet.add(AVP::from_ipv6({type_identifier}, value)); }} +/// Lookup a `{method_identifier}` ipv6addr value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `{method_identifier}`, it returns `None`. pub fn lookup_{method_identifier}(packet: &Packet) -> Option> {{ packet.lookup({type_identifier}).map(|v| v.encode_ipv6()) }} +/// Lookup all of the `{method_identifier}` ipv6addr value from a packet. pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result, AVPError> {{ let mut vec = Vec::new(); for avp in packet.lookup_all({type_identifier}) {{ @@ -664,13 +729,18 @@ fn generate_ipv6_prefix_attribute_code( type_identifier: &str, ) { let code = format!( - "pub fn add_{method_identifier}(packet: &mut Packet, value: &[u8]) -> Result<(), AVPError> {{ + "/// Add `{method_identifier}` ipv6 prefix value to a packet. +pub fn add_{method_identifier}(packet: &mut Packet, value: &[u8]) -> Result<(), AVPError> {{ packet.add(AVP::from_ipv6_prefix({type_identifier}, value)?); Ok(()) }} +/// Lookup a `{method_identifier}` ipv6 prefix value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `{method_identifier}`, it returns `None`. pub fn lookup_{method_identifier}(packet: &Packet) -> Option, AVPError>> {{ packet.lookup({type_identifier}).map(|v| v.encode_ipv6_prefix()) }} +/// Lookup all of the `{method_identifier}` ipv6 prefix value from a packet. pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result>, AVPError> {{ let mut vec = Vec::new(); for avp in packet.lookup_all({type_identifier}) {{ @@ -691,12 +761,17 @@ fn generate_date_attribute_code( type_identifier: &str, ) { let code = format!( - "pub fn add_{method_identifier}(packet: &mut Packet, value: &DateTime) {{ + "/// Add `{method_identifier}` date value to a packet. +pub fn add_{method_identifier}(packet: &mut Packet, value: &DateTime) {{ packet.add(AVP::from_date({type_identifier}, value)); }} +/// Lookup a `{method_identifier}` date value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `{method_identifier}`, it returns `None`. pub fn lookup_{method_identifier}(packet: &Packet) -> Option, AVPError>> {{ packet.lookup({type_identifier}).map(|v| v.encode_date()) }} +/// Lookup all of the `{method_identifier}` date value from a packet. pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result>, AVPError> {{ let mut vec = Vec::new(); for avp in packet.lookup_all({type_identifier}) {{ @@ -717,12 +792,17 @@ fn generate_integer_attribute_code( type_identifier: &str, ) { let code = format!( - "pub fn add_{method_identifier}(packet: &mut Packet, value: u32) {{ + "/// Add `{method_identifier}` integer value to a packet. +pub fn add_{method_identifier}(packet: &mut Packet, value: u32) {{ packet.add(AVP::from_u32({type_identifier}, value)); }} +/// Lookup a `{method_identifier}` integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `{method_identifier}`, it returns `None`. pub fn lookup_{method_identifier}(packet: &Packet) -> Option> {{ packet.lookup({type_identifier}).map(|v| v.encode_u32()) }} +/// Lookup all of the `{method_identifier}` integer value from a packet. pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result, AVPError> {{ let mut vec = Vec::new(); for avp in packet.lookup_all({type_identifier}) {{ @@ -743,12 +823,17 @@ fn generate_tagged_integer_attribute_code( type_identifier: &str, ) { let code = format!( - "pub fn add_{method_identifier}(packet: &mut Packet, tag: Option<&Tag>, value: u32) {{ + "/// Add `{method_identifier}` tagged integer value to a packet. +pub fn add_{method_identifier}(packet: &mut Packet, tag: Option<&Tag>, value: u32) {{ packet.add(AVP::from_tagged_u32({type_identifier}, tag, value)); }} +/// Lookup a `{method_identifier}` tagged integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `{method_identifier}`, it returns `None`. pub fn lookup_{method_identifier}(packet: &Packet) -> Option> {{ packet.lookup({type_identifier}).map(|v| v.encode_tagged_u32()) }} +/// Lookup all of the `{method_identifier}` tagged integer value from a packet. pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result, AVPError> {{ let mut vec = Vec::new(); for avp in packet.lookup_all({type_identifier}) {{ @@ -770,12 +855,17 @@ fn generate_value_defined_integer_attribute_code( value_type: &str, ) { let code = format!( - "pub fn add_{method_identifier}(packet: &mut Packet, value: {value_type}) {{ + "/// Add `{method_identifier}` value-defined integer value to a packet. +pub fn add_{method_identifier}(packet: &mut Packet, value: {value_type}) {{ packet.add(AVP::from_u32({type_identifier}, value as u32)); }} +/// Lookup a `{method_identifier}` value-defined integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `{method_identifier}`, it returns `None`. pub fn lookup_{method_identifier}(packet: &Packet) -> Option> {{ packet.lookup({type_identifier}).map(|v| Ok(v.encode_u32()? as {value_type})) }} +/// Lookup all of the `{method_identifier}` value-defined integer value from a packet. pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result, AVPError> {{ let mut vec = Vec::new(); for avp in packet.lookup_all({type_identifier}) {{ @@ -791,22 +881,27 @@ pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result, method_identifier: &str, type_identifier: &str, value_type: &str, ) { let code = format!( - "pub fn add_{method_identifier}(packet: &mut Packet, tag: Option<&Tag>, value: {value_type}) {{ + "/// Add `{method_identifier}` tagged value-defined integer value to a packet. +pub fn add_{method_identifier}(packet: &mut Packet, tag: Option<&Tag>, value: {value_type}) {{ packet.add(AVP::from_tagged_u32({type_identifier}, tag, value as u32)); }} +/// Lookup a `{method_identifier}` tagged value-defined integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `{method_identifier}`, it returns `None`. pub fn lookup_{method_identifier}(packet: &Packet) -> Option> {{ packet.lookup({type_identifier}).map(|v| {{ let (v, t) = v.encode_tagged_u32()?; Ok((v as {value_type}, t)) }}) }} +/// Lookup all of the `{method_identifier}` tagged value-defined integer value from a packet. pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result, AVPError> {{ let mut vec = Vec::new(); for avp in packet.lookup_all({type_identifier}) {{ @@ -829,12 +924,17 @@ fn generate_short_attribute_code( type_identifier: &str, ) { let code = format!( - "pub fn add_{method_identifier}(packet: &mut Packet, value: u16) {{ + "/// Add `{method_identifier}` short integer value to a packet. +pub fn add_{method_identifier}(packet: &mut Packet, value: u16) {{ packet.add(AVP::from_u16({type_identifier}, value)); }} +/// Lookup a `{method_identifier}` short integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `{method_identifier}`, it returns `None`. pub fn lookup_{method_identifier}(packet: &Packet) -> Option> {{ packet.lookup({type_identifier}).map(|v| v.encode_u16()) }} +/// Lookup all of the `{method_identifier}` short integer value from a packet. pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result, AVPError> {{ let mut vec = Vec::new(); for avp in packet.lookup_all({type_identifier}) {{ @@ -855,7 +955,9 @@ fn generate_vsa_attribute_code() { type DictParsed = (Vec, BTreeMap>); -fn parse_dict_file(dict_file_path: &Path) -> Result { +fn parse_dict_file( + dict_file_path: &Path, +) -> Result<(DictParsed, io::Lines>), String> { let line_filter_re = Regex::new(r"^(?:#.*|)$").unwrap(); let tabs_re = Regex::new(r"\t+").unwrap(); let trailing_comment_re = Regex::new(r"\s*?#.+?$").unwrap(); @@ -937,8 +1039,6 @@ fn parse_dict_file(dict_file_path: &Path) -> Result { } }; - // TODO - radius_attributes.push(RadiusAttribute { name: items[1].to_string(), typ: items[2].parse().unwrap(), @@ -972,5 +1072,8 @@ fn parse_dict_file(dict_file_path: &Path) -> Result { } } - Ok((radius_attributes, radius_attribute_to_values)) + Ok(( + (radius_attributes, radius_attribute_to_values), + read_lines(dict_file_path).unwrap(), + )) } diff --git a/radius/src/client.rs b/radius/src/client.rs index 8a739c8..ccdb55c 100644 --- a/radius/src/client.rs +++ b/radius/src/client.rs @@ -1,3 +1,5 @@ +//! RADIUS client implementation. + use std::net::SocketAddr; use std::time::Duration; diff --git a/radius/src/core/mod.rs b/radius/src/core/mod.rs index 91eeeeb..b137f92 100644 --- a/radius/src/core/mod.rs +++ b/radius/src/core/mod.rs @@ -1,3 +1,5 @@ +//! RADIUS core implementation for server, client and application. + pub(crate) mod attributes; pub mod avp; pub mod code; diff --git a/radius/src/core/rfc2865.rs b/radius/src/core/rfc2865.rs index 73b9917..82373ae 100644 --- a/radius/src/core/rfc2865.rs +++ b/radius/src/core/rfc2865.rs @@ -1,20 +1,172 @@ // Code generated by machine generator; DO NOT EDIT. +//! Utility for rfc2865 packet. +//! +//! This module handles the packet according to the following definition: +//! ```text +//! //! # -*- text -*- +//! # Copyright (C) 2020 The FreeRADIUS Server project and contributors +//! # This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0 +//! # Version $Id$ +//! # +//! # Attributes and values defined in RFC 2865. +//! # http://www.ietf.org/rfc/rfc2865.txt +//! # +//! # $Id$ +//! # +//! ATTRIBUTE User-Name 1 string +//! ATTRIBUTE User-Password 2 string encrypt=1 +//! ATTRIBUTE CHAP-Password 3 octets +//! ATTRIBUTE NAS-IP-Address 4 ipaddr +//! ATTRIBUTE NAS-Port 5 integer +//! ATTRIBUTE Service-Type 6 integer +//! ATTRIBUTE Framed-Protocol 7 integer +//! ATTRIBUTE Framed-IP-Address 8 ipaddr +//! ATTRIBUTE Framed-IP-Netmask 9 ipaddr +//! ATTRIBUTE Framed-Routing 10 integer +//! ATTRIBUTE Filter-Id 11 string +//! ATTRIBUTE Framed-MTU 12 integer +//! ATTRIBUTE Framed-Compression 13 integer +//! ATTRIBUTE Login-IP-Host 14 ipaddr +//! ATTRIBUTE Login-Service 15 integer +//! ATTRIBUTE Login-TCP-Port 16 integer +//! # Attribute 17 is undefined +//! ATTRIBUTE Reply-Message 18 string +//! ATTRIBUTE Callback-Number 19 string +//! ATTRIBUTE Callback-Id 20 string +//! # Attribute 21 is undefined +//! ATTRIBUTE Framed-Route 22 string +//! ATTRIBUTE Framed-IPX-Network 23 ipaddr +//! ATTRIBUTE State 24 octets +//! ATTRIBUTE Class 25 octets +//! ATTRIBUTE Vendor-Specific 26 vsa +//! ATTRIBUTE Session-Timeout 27 integer +//! ATTRIBUTE Idle-Timeout 28 integer +//! ATTRIBUTE Termination-Action 29 integer +//! ATTRIBUTE Called-Station-Id 30 string +//! ATTRIBUTE Calling-Station-Id 31 string +//! ATTRIBUTE NAS-Identifier 32 string +//! ATTRIBUTE Proxy-State 33 octets +//! ATTRIBUTE Login-LAT-Service 34 string +//! ATTRIBUTE Login-LAT-Node 35 string +//! ATTRIBUTE Login-LAT-Group 36 octets +//! ATTRIBUTE Framed-AppleTalk-Link 37 integer +//! ATTRIBUTE Framed-AppleTalk-Network 38 integer +//! ATTRIBUTE Framed-AppleTalk-Zone 39 string +//! +//! ATTRIBUTE CHAP-Challenge 60 octets +//! ATTRIBUTE NAS-Port-Type 61 integer +//! ATTRIBUTE Port-Limit 62 integer +//! ATTRIBUTE Login-LAT-Port 63 string +//! +//! # +//! # Integer Translations +//! # +//! +//! # Service types +//! +//! VALUE Service-Type Login-User 1 +//! VALUE Service-Type Framed-User 2 +//! VALUE Service-Type Callback-Login-User 3 +//! VALUE Service-Type Callback-Framed-User 4 +//! VALUE Service-Type Outbound-User 5 +//! VALUE Service-Type Administrative-User 6 +//! VALUE Service-Type NAS-Prompt-User 7 +//! VALUE Service-Type Authenticate-Only 8 +//! VALUE Service-Type Callback-NAS-Prompt 9 +//! VALUE Service-Type Call-Check 10 +//! VALUE Service-Type Callback-Administrative 11 +//! +//! # Framed Protocols +//! +//! VALUE Framed-Protocol PPP 1 +//! VALUE Framed-Protocol SLIP 2 +//! VALUE Framed-Protocol ARAP 3 +//! VALUE Framed-Protocol Gandalf-SLML 4 +//! VALUE Framed-Protocol Xylogics-IPX-SLIP 5 +//! VALUE Framed-Protocol X.75-Synchronous 6 +//! +//! # Framed Routing Values +//! +//! VALUE Framed-Routing None 0 +//! VALUE Framed-Routing Broadcast 1 +//! VALUE Framed-Routing Listen 2 +//! VALUE Framed-Routing Broadcast-Listen 3 +//! +//! # Framed Compression Types +//! +//! VALUE Framed-Compression None 0 +//! VALUE Framed-Compression Van-Jacobson-TCP-IP 1 +//! VALUE Framed-Compression IPX-Header-Compression 2 +//! VALUE Framed-Compression Stac-LZS 3 +//! +//! # Login Services +//! +//! VALUE Login-Service Telnet 0 +//! VALUE Login-Service Rlogin 1 +//! VALUE Login-Service TCP-Clear 2 +//! VALUE Login-Service PortMaster 3 +//! VALUE Login-Service LAT 4 +//! VALUE Login-Service X25-PAD 5 +//! VALUE Login-Service X25-T3POS 6 +//! VALUE Login-Service TCP-Clear-Quiet 8 +//! +//! # Login-TCP-Port (see /etc/services for more examples) +//! +//! VALUE Login-TCP-Port Telnet 23 +//! VALUE Login-TCP-Port Rlogin 513 +//! VALUE Login-TCP-Port Rsh 514 +//! +//! # Termination Options +//! +//! VALUE Termination-Action Default 0 +//! VALUE Termination-Action RADIUS-Request 1 +//! +//! # NAS Port Types +//! +//! VALUE NAS-Port-Type Async 0 +//! VALUE NAS-Port-Type Sync 1 +//! VALUE NAS-Port-Type ISDN 2 +//! VALUE NAS-Port-Type ISDN-V120 3 +//! VALUE NAS-Port-Type ISDN-V110 4 +//! VALUE NAS-Port-Type Virtual 5 +//! VALUE NAS-Port-Type PIAFS 6 +//! VALUE NAS-Port-Type HDLC-Clear-Channel 7 +//! VALUE NAS-Port-Type X.25 8 +//! VALUE NAS-Port-Type X.75 9 +//! VALUE NAS-Port-Type G.3-Fax 10 +//! VALUE NAS-Port-Type SDSL 11 +//! VALUE NAS-Port-Type ADSL-CAP 12 +//! VALUE NAS-Port-Type ADSL-DMT 13 +//! VALUE NAS-Port-Type IDSL 14 +//! VALUE NAS-Port-Type Ethernet 15 +//! VALUE NAS-Port-Type xDSL 16 +//! VALUE NAS-Port-Type Cable 17 +//! VALUE NAS-Port-Type Wireless-Other 18 +//! VALUE NAS-Port-Type Wireless-802.11 19 +//! ``` + use std::net::Ipv4Addr; use crate::core::avp::{AVPError, AVPType, AVP}; use crate::core::packet::Packet; pub const USER_NAME_TYPE: AVPType = 1; +/// Delete all of `user_name` values from a packet. pub fn delete_user_name(packet: &mut Packet) { packet.delete(USER_NAME_TYPE); } +/// Add `user_name` string value to a packet. pub fn add_user_name(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(USER_NAME_TYPE, value)); } +/// Lookup a `user_name` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `user_name`, it returns `None`. pub fn lookup_user_name(packet: &Packet) -> Option> { packet.lookup(USER_NAME_TYPE).map(|v| v.encode_string()) } +/// Lookup all of the `user_name` string value from a packet. pub fn lookup_all_user_name(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(USER_NAME_TYPE) { @@ -24,9 +176,11 @@ pub fn lookup_all_user_name(packet: &Packet) -> Result, AVPError> { } pub const USER_PASSWORD_TYPE: AVPType = 2; +/// Delete all of `user_password` values from a packet. pub fn delete_user_password(packet: &mut Packet) { packet.delete(USER_PASSWORD_TYPE); } +/// Add `user_password` user-password value to a packet. pub fn add_user_password(packet: &mut Packet, value: &[u8]) -> Result<(), AVPError> { packet.add(AVP::from_user_password( USER_PASSWORD_TYPE, @@ -36,11 +190,15 @@ pub fn add_user_password(packet: &mut Packet, value: &[u8]) -> Result<(), AVPErr )?); Ok(()) } +/// Lookup a `user_password` user-password value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `user_password`, it returns `None`. pub fn lookup_user_password(packet: &Packet) -> Option, AVPError>> { packet .lookup(USER_PASSWORD_TYPE) .map(|v| v.encode_user_password(packet.get_secret(), packet.get_authenticator())) } +/// Lookup all of the `user_password` user-password value from a packet. pub fn lookup_all_user_password(packet: &Packet) -> Result>, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(USER_PASSWORD_TYPE) { @@ -50,15 +208,21 @@ pub fn lookup_all_user_password(packet: &Packet) -> Result>, AVPErro } pub const CHAP_PASSWORD_TYPE: AVPType = 3; +/// Delete all of `chap_password` values from a packet. pub fn delete_chap_password(packet: &mut Packet) { packet.delete(CHAP_PASSWORD_TYPE); } +/// Add `chap_password` octets value to a packet. pub fn add_chap_password(packet: &mut Packet, value: &[u8]) { packet.add(AVP::from_bytes(CHAP_PASSWORD_TYPE, value)); } +/// Lookup a `chap_password` octets value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `chap_password`, it returns `None`. pub fn lookup_chap_password(packet: &Packet) -> Option> { packet.lookup(CHAP_PASSWORD_TYPE).map(|v| v.encode_bytes()) } +/// Lookup all of the `chap_password` octets value from a packet. pub fn lookup_all_chap_password(packet: &Packet) -> Vec> { let mut vec = Vec::new(); for avp in packet.lookup_all(CHAP_PASSWORD_TYPE) { @@ -68,15 +232,21 @@ pub fn lookup_all_chap_password(packet: &Packet) -> Vec> { } pub const NAS_IP_ADDRESS_TYPE: AVPType = 4; +/// Delete all of `nas_ip_address` values from a packet. pub fn delete_nas_ip_address(packet: &mut Packet) { packet.delete(NAS_IP_ADDRESS_TYPE); } +/// Add `nas_ip_address` ipaddr value to a packet. pub fn add_nas_ip_address(packet: &mut Packet, value: &Ipv4Addr) { packet.add(AVP::from_ipv4(NAS_IP_ADDRESS_TYPE, value)); } +/// Lookup a `nas_ip_address` ipaddr value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `nas_ip_address`, it returns `None`. pub fn lookup_nas_ip_address(packet: &Packet) -> Option> { packet.lookup(NAS_IP_ADDRESS_TYPE).map(|v| v.encode_ipv4()) } +/// Lookup all of the `nas_ip_address` ipaddr value from a packet. pub fn lookup_all_nas_ip_address(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(NAS_IP_ADDRESS_TYPE) { @@ -86,15 +256,21 @@ pub fn lookup_all_nas_ip_address(packet: &Packet) -> Result, AVPEr } pub const NAS_PORT_TYPE: AVPType = 5; +/// Delete all of `nas_port` values from a packet. pub fn delete_nas_port(packet: &mut Packet) { packet.delete(NAS_PORT_TYPE); } +/// Add `nas_port` integer value to a packet. pub fn add_nas_port(packet: &mut Packet, value: u32) { packet.add(AVP::from_u32(NAS_PORT_TYPE, value)); } +/// Lookup a `nas_port` integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `nas_port`, it returns `None`. pub fn lookup_nas_port(packet: &Packet) -> Option> { packet.lookup(NAS_PORT_TYPE).map(|v| v.encode_u32()) } +/// Lookup all of the `nas_port` integer value from a packet. pub fn lookup_all_nas_port(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(NAS_PORT_TYPE) { @@ -104,17 +280,23 @@ pub fn lookup_all_nas_port(packet: &Packet) -> Result, AVPError> { } pub const SERVICE_TYPE_TYPE: AVPType = 6; +/// Delete all of `service_type` values from a packet. pub fn delete_service_type(packet: &mut Packet) { packet.delete(SERVICE_TYPE_TYPE); } +/// Add `service_type` value-defined integer value to a packet. pub fn add_service_type(packet: &mut Packet, value: ServiceType) { packet.add(AVP::from_u32(SERVICE_TYPE_TYPE, value as u32)); } +/// Lookup a `service_type` value-defined integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `service_type`, it returns `None`. pub fn lookup_service_type(packet: &Packet) -> Option> { packet .lookup(SERVICE_TYPE_TYPE) .map(|v| Ok(v.encode_u32()? as ServiceType)) } +/// Lookup all of the `service_type` value-defined integer value from a packet. pub fn lookup_all_service_type(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(SERVICE_TYPE_TYPE) { @@ -124,17 +306,23 @@ pub fn lookup_all_service_type(packet: &Packet) -> Result, AVPE } pub const FRAMED_PROTOCOL_TYPE: AVPType = 7; +/// Delete all of `framed_protocol` values from a packet. pub fn delete_framed_protocol(packet: &mut Packet) { packet.delete(FRAMED_PROTOCOL_TYPE); } +/// Add `framed_protocol` value-defined integer value to a packet. pub fn add_framed_protocol(packet: &mut Packet, value: FramedProtocol) { packet.add(AVP::from_u32(FRAMED_PROTOCOL_TYPE, value as u32)); } +/// Lookup a `framed_protocol` value-defined integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `framed_protocol`, it returns `None`. pub fn lookup_framed_protocol(packet: &Packet) -> Option> { packet .lookup(FRAMED_PROTOCOL_TYPE) .map(|v| Ok(v.encode_u32()? as FramedProtocol)) } +/// Lookup all of the `framed_protocol` value-defined integer value from a packet. pub fn lookup_all_framed_protocol(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(FRAMED_PROTOCOL_TYPE) { @@ -144,17 +332,23 @@ pub fn lookup_all_framed_protocol(packet: &Packet) -> Result } pub const FRAMED_IP_ADDRESS_TYPE: AVPType = 8; +/// Delete all of `framed_ip_address` values from a packet. pub fn delete_framed_ip_address(packet: &mut Packet) { packet.delete(FRAMED_IP_ADDRESS_TYPE); } +/// Add `framed_ip_address` ipaddr value to a packet. pub fn add_framed_ip_address(packet: &mut Packet, value: &Ipv4Addr) { packet.add(AVP::from_ipv4(FRAMED_IP_ADDRESS_TYPE, value)); } +/// Lookup a `framed_ip_address` ipaddr value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `framed_ip_address`, it returns `None`. pub fn lookup_framed_ip_address(packet: &Packet) -> Option> { packet .lookup(FRAMED_IP_ADDRESS_TYPE) .map(|v| v.encode_ipv4()) } +/// Lookup all of the `framed_ip_address` ipaddr value from a packet. pub fn lookup_all_framed_ip_address(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(FRAMED_IP_ADDRESS_TYPE) { @@ -164,17 +358,23 @@ pub fn lookup_all_framed_ip_address(packet: &Packet) -> Result, AV } pub const FRAMED_IP_NETMASK_TYPE: AVPType = 9; +/// Delete all of `framed_ip_netmask` values from a packet. pub fn delete_framed_ip_netmask(packet: &mut Packet) { packet.delete(FRAMED_IP_NETMASK_TYPE); } +/// Add `framed_ip_netmask` ipaddr value to a packet. pub fn add_framed_ip_netmask(packet: &mut Packet, value: &Ipv4Addr) { packet.add(AVP::from_ipv4(FRAMED_IP_NETMASK_TYPE, value)); } +/// Lookup a `framed_ip_netmask` ipaddr value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `framed_ip_netmask`, it returns `None`. pub fn lookup_framed_ip_netmask(packet: &Packet) -> Option> { packet .lookup(FRAMED_IP_NETMASK_TYPE) .map(|v| v.encode_ipv4()) } +/// Lookup all of the `framed_ip_netmask` ipaddr value from a packet. pub fn lookup_all_framed_ip_netmask(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(FRAMED_IP_NETMASK_TYPE) { @@ -184,17 +384,23 @@ pub fn lookup_all_framed_ip_netmask(packet: &Packet) -> Result, AV } pub const FRAMED_ROUTING_TYPE: AVPType = 10; +/// Delete all of `framed_routing` values from a packet. pub fn delete_framed_routing(packet: &mut Packet) { packet.delete(FRAMED_ROUTING_TYPE); } +/// Add `framed_routing` value-defined integer value to a packet. pub fn add_framed_routing(packet: &mut Packet, value: FramedRouting) { packet.add(AVP::from_u32(FRAMED_ROUTING_TYPE, value as u32)); } +/// Lookup a `framed_routing` value-defined integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `framed_routing`, it returns `None`. pub fn lookup_framed_routing(packet: &Packet) -> Option> { packet .lookup(FRAMED_ROUTING_TYPE) .map(|v| Ok(v.encode_u32()? as FramedRouting)) } +/// Lookup all of the `framed_routing` value-defined integer value from a packet. pub fn lookup_all_framed_routing(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(FRAMED_ROUTING_TYPE) { @@ -204,15 +410,21 @@ pub fn lookup_all_framed_routing(packet: &Packet) -> Result, } pub const FILTER_ID_TYPE: AVPType = 11; +/// Delete all of `filter_id` values from a packet. pub fn delete_filter_id(packet: &mut Packet) { packet.delete(FILTER_ID_TYPE); } +/// Add `filter_id` string value to a packet. pub fn add_filter_id(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(FILTER_ID_TYPE, value)); } +/// Lookup a `filter_id` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `filter_id`, it returns `None`. pub fn lookup_filter_id(packet: &Packet) -> Option> { packet.lookup(FILTER_ID_TYPE).map(|v| v.encode_string()) } +/// Lookup all of the `filter_id` string value from a packet. pub fn lookup_all_filter_id(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(FILTER_ID_TYPE) { @@ -222,15 +434,21 @@ pub fn lookup_all_filter_id(packet: &Packet) -> Result, AVPError> { } pub const FRAMED_MTU_TYPE: AVPType = 12; +/// Delete all of `framed_mtu` values from a packet. pub fn delete_framed_mtu(packet: &mut Packet) { packet.delete(FRAMED_MTU_TYPE); } +/// Add `framed_mtu` integer value to a packet. pub fn add_framed_mtu(packet: &mut Packet, value: u32) { packet.add(AVP::from_u32(FRAMED_MTU_TYPE, value)); } +/// Lookup a `framed_mtu` integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `framed_mtu`, it returns `None`. pub fn lookup_framed_mtu(packet: &Packet) -> Option> { packet.lookup(FRAMED_MTU_TYPE).map(|v| v.encode_u32()) } +/// Lookup all of the `framed_mtu` integer value from a packet. pub fn lookup_all_framed_mtu(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(FRAMED_MTU_TYPE) { @@ -240,17 +458,23 @@ pub fn lookup_all_framed_mtu(packet: &Packet) -> Result, AVPError> { } pub const FRAMED_COMPRESSION_TYPE: AVPType = 13; +/// Delete all of `framed_compression` values from a packet. pub fn delete_framed_compression(packet: &mut Packet) { packet.delete(FRAMED_COMPRESSION_TYPE); } +/// Add `framed_compression` value-defined integer value to a packet. pub fn add_framed_compression(packet: &mut Packet, value: FramedCompression) { packet.add(AVP::from_u32(FRAMED_COMPRESSION_TYPE, value as u32)); } +/// Lookup a `framed_compression` value-defined integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `framed_compression`, it returns `None`. pub fn lookup_framed_compression(packet: &Packet) -> Option> { packet .lookup(FRAMED_COMPRESSION_TYPE) .map(|v| Ok(v.encode_u32()? as FramedCompression)) } +/// Lookup all of the `framed_compression` value-defined integer value from a packet. pub fn lookup_all_framed_compression(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(FRAMED_COMPRESSION_TYPE) { @@ -260,15 +484,21 @@ pub fn lookup_all_framed_compression(packet: &Packet) -> Result Option> { packet.lookup(LOGIN_IP_HOST_TYPE).map(|v| v.encode_ipv4()) } +/// Lookup all of the `login_ip_host` ipaddr value from a packet. pub fn lookup_all_login_ip_host(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(LOGIN_IP_HOST_TYPE) { @@ -278,17 +508,23 @@ pub fn lookup_all_login_ip_host(packet: &Packet) -> Result, AVPErr } pub const LOGIN_SERVICE_TYPE: AVPType = 15; +/// Delete all of `login_service` values from a packet. pub fn delete_login_service(packet: &mut Packet) { packet.delete(LOGIN_SERVICE_TYPE); } +/// Add `login_service` value-defined integer value to a packet. pub fn add_login_service(packet: &mut Packet, value: LoginService) { packet.add(AVP::from_u32(LOGIN_SERVICE_TYPE, value as u32)); } +/// Lookup a `login_service` value-defined integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `login_service`, it returns `None`. pub fn lookup_login_service(packet: &Packet) -> Option> { packet .lookup(LOGIN_SERVICE_TYPE) .map(|v| Ok(v.encode_u32()? as LoginService)) } +/// Lookup all of the `login_service` value-defined integer value from a packet. pub fn lookup_all_login_service(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(LOGIN_SERVICE_TYPE) { @@ -298,17 +534,23 @@ pub fn lookup_all_login_service(packet: &Packet) -> Result, AV } pub const LOGIN_TCP_PORT_TYPE: AVPType = 16; +/// Delete all of `login_tcp_port` values from a packet. pub fn delete_login_tcp_port(packet: &mut Packet) { packet.delete(LOGIN_TCP_PORT_TYPE); } +/// Add `login_tcp_port` value-defined integer value to a packet. pub fn add_login_tcp_port(packet: &mut Packet, value: LoginTCPPort) { packet.add(AVP::from_u32(LOGIN_TCP_PORT_TYPE, value as u32)); } +/// Lookup a `login_tcp_port` value-defined integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `login_tcp_port`, it returns `None`. pub fn lookup_login_tcp_port(packet: &Packet) -> Option> { packet .lookup(LOGIN_TCP_PORT_TYPE) .map(|v| Ok(v.encode_u32()? as LoginTCPPort)) } +/// Lookup all of the `login_tcp_port` value-defined integer value from a packet. pub fn lookup_all_login_tcp_port(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(LOGIN_TCP_PORT_TYPE) { @@ -318,15 +560,21 @@ pub fn lookup_all_login_tcp_port(packet: &Packet) -> Result, A } pub const REPLY_MESSAGE_TYPE: AVPType = 18; +/// Delete all of `reply_message` values from a packet. pub fn delete_reply_message(packet: &mut Packet) { packet.delete(REPLY_MESSAGE_TYPE); } +/// Add `reply_message` string value to a packet. pub fn add_reply_message(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(REPLY_MESSAGE_TYPE, value)); } +/// Lookup a `reply_message` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `reply_message`, it returns `None`. pub fn lookup_reply_message(packet: &Packet) -> Option> { packet.lookup(REPLY_MESSAGE_TYPE).map(|v| v.encode_string()) } +/// Lookup all of the `reply_message` string value from a packet. pub fn lookup_all_reply_message(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(REPLY_MESSAGE_TYPE) { @@ -336,17 +584,23 @@ pub fn lookup_all_reply_message(packet: &Packet) -> Result, AVPError } pub const CALLBACK_NUMBER_TYPE: AVPType = 19; +/// Delete all of `callback_number` values from a packet. pub fn delete_callback_number(packet: &mut Packet) { packet.delete(CALLBACK_NUMBER_TYPE); } +/// Add `callback_number` string value to a packet. pub fn add_callback_number(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(CALLBACK_NUMBER_TYPE, value)); } +/// Lookup a `callback_number` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `callback_number`, it returns `None`. pub fn lookup_callback_number(packet: &Packet) -> Option> { packet .lookup(CALLBACK_NUMBER_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `callback_number` string value from a packet. pub fn lookup_all_callback_number(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(CALLBACK_NUMBER_TYPE) { @@ -356,15 +610,21 @@ pub fn lookup_all_callback_number(packet: &Packet) -> Result, AVPErr } pub const CALLBACK_ID_TYPE: AVPType = 20; +/// Delete all of `callback_id` values from a packet. pub fn delete_callback_id(packet: &mut Packet) { packet.delete(CALLBACK_ID_TYPE); } +/// Add `callback_id` string value to a packet. pub fn add_callback_id(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(CALLBACK_ID_TYPE, value)); } +/// Lookup a `callback_id` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `callback_id`, it returns `None`. pub fn lookup_callback_id(packet: &Packet) -> Option> { packet.lookup(CALLBACK_ID_TYPE).map(|v| v.encode_string()) } +/// Lookup all of the `callback_id` string value from a packet. pub fn lookup_all_callback_id(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(CALLBACK_ID_TYPE) { @@ -374,15 +634,21 @@ pub fn lookup_all_callback_id(packet: &Packet) -> Result, AVPError> } pub const FRAMED_ROUTE_TYPE: AVPType = 22; +/// Delete all of `framed_route` values from a packet. pub fn delete_framed_route(packet: &mut Packet) { packet.delete(FRAMED_ROUTE_TYPE); } +/// Add `framed_route` string value to a packet. pub fn add_framed_route(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(FRAMED_ROUTE_TYPE, value)); } +/// Lookup a `framed_route` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `framed_route`, it returns `None`. pub fn lookup_framed_route(packet: &Packet) -> Option> { packet.lookup(FRAMED_ROUTE_TYPE).map(|v| v.encode_string()) } +/// Lookup all of the `framed_route` string value from a packet. pub fn lookup_all_framed_route(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(FRAMED_ROUTE_TYPE) { @@ -392,17 +658,23 @@ pub fn lookup_all_framed_route(packet: &Packet) -> Result, AVPError> } pub const FRAMED_IPX_NETWORK_TYPE: AVPType = 23; +/// Delete all of `framed_ipx_network` values from a packet. pub fn delete_framed_ipx_network(packet: &mut Packet) { packet.delete(FRAMED_IPX_NETWORK_TYPE); } +/// Add `framed_ipx_network` ipaddr value to a packet. pub fn add_framed_ipx_network(packet: &mut Packet, value: &Ipv4Addr) { packet.add(AVP::from_ipv4(FRAMED_IPX_NETWORK_TYPE, value)); } +/// Lookup a `framed_ipx_network` ipaddr value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `framed_ipx_network`, it returns `None`. pub fn lookup_framed_ipx_network(packet: &Packet) -> Option> { packet .lookup(FRAMED_IPX_NETWORK_TYPE) .map(|v| v.encode_ipv4()) } +/// Lookup all of the `framed_ipx_network` ipaddr value from a packet. pub fn lookup_all_framed_ipx_network(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(FRAMED_IPX_NETWORK_TYPE) { @@ -412,15 +684,21 @@ pub fn lookup_all_framed_ipx_network(packet: &Packet) -> Result, A } pub const STATE_TYPE: AVPType = 24; +/// Delete all of `state` values from a packet. pub fn delete_state(packet: &mut Packet) { packet.delete(STATE_TYPE); } +/// Add `state` octets value to a packet. pub fn add_state(packet: &mut Packet, value: &[u8]) { packet.add(AVP::from_bytes(STATE_TYPE, value)); } +/// Lookup a `state` octets value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `state`, it returns `None`. pub fn lookup_state(packet: &Packet) -> Option> { packet.lookup(STATE_TYPE).map(|v| v.encode_bytes()) } +/// Lookup all of the `state` octets value from a packet. pub fn lookup_all_state(packet: &Packet) -> Vec> { let mut vec = Vec::new(); for avp in packet.lookup_all(STATE_TYPE) { @@ -430,15 +708,21 @@ pub fn lookup_all_state(packet: &Packet) -> Vec> { } pub const CLASS_TYPE: AVPType = 25; +/// Delete all of `class` values from a packet. pub fn delete_class(packet: &mut Packet) { packet.delete(CLASS_TYPE); } +/// Add `class` octets value to a packet. pub fn add_class(packet: &mut Packet, value: &[u8]) { packet.add(AVP::from_bytes(CLASS_TYPE, value)); } +/// Lookup a `class` octets value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `class`, it returns `None`. pub fn lookup_class(packet: &Packet) -> Option> { packet.lookup(CLASS_TYPE).map(|v| v.encode_bytes()) } +/// Lookup all of the `class` octets value from a packet. pub fn lookup_all_class(packet: &Packet) -> Vec> { let mut vec = Vec::new(); for avp in packet.lookup_all(CLASS_TYPE) { @@ -448,20 +732,27 @@ pub fn lookup_all_class(packet: &Packet) -> Vec> { } pub const VENDOR_SPECIFIC_TYPE: AVPType = 26; +/// Delete all of `vendor_specific` values from a packet. pub fn delete_vendor_specific(packet: &mut Packet) { packet.delete(VENDOR_SPECIFIC_TYPE); } pub const SESSION_TIMEOUT_TYPE: AVPType = 27; +/// Delete all of `session_timeout` values from a packet. pub fn delete_session_timeout(packet: &mut Packet) { packet.delete(SESSION_TIMEOUT_TYPE); } +/// Add `session_timeout` integer value to a packet. pub fn add_session_timeout(packet: &mut Packet, value: u32) { packet.add(AVP::from_u32(SESSION_TIMEOUT_TYPE, value)); } +/// Lookup a `session_timeout` integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `session_timeout`, it returns `None`. pub fn lookup_session_timeout(packet: &Packet) -> Option> { packet.lookup(SESSION_TIMEOUT_TYPE).map(|v| v.encode_u32()) } +/// Lookup all of the `session_timeout` integer value from a packet. pub fn lookup_all_session_timeout(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(SESSION_TIMEOUT_TYPE) { @@ -471,15 +762,21 @@ pub fn lookup_all_session_timeout(packet: &Packet) -> Result, AVPError> } pub const IDLE_TIMEOUT_TYPE: AVPType = 28; +/// Delete all of `idle_timeout` values from a packet. pub fn delete_idle_timeout(packet: &mut Packet) { packet.delete(IDLE_TIMEOUT_TYPE); } +/// Add `idle_timeout` integer value to a packet. pub fn add_idle_timeout(packet: &mut Packet, value: u32) { packet.add(AVP::from_u32(IDLE_TIMEOUT_TYPE, value)); } +/// Lookup a `idle_timeout` integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `idle_timeout`, it returns `None`. pub fn lookup_idle_timeout(packet: &Packet) -> Option> { packet.lookup(IDLE_TIMEOUT_TYPE).map(|v| v.encode_u32()) } +/// Lookup all of the `idle_timeout` integer value from a packet. pub fn lookup_all_idle_timeout(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(IDLE_TIMEOUT_TYPE) { @@ -489,17 +786,23 @@ pub fn lookup_all_idle_timeout(packet: &Packet) -> Result, AVPError> { } pub const TERMINATION_ACTION_TYPE: AVPType = 29; +/// Delete all of `termination_action` values from a packet. pub fn delete_termination_action(packet: &mut Packet) { packet.delete(TERMINATION_ACTION_TYPE); } +/// Add `termination_action` value-defined integer value to a packet. pub fn add_termination_action(packet: &mut Packet, value: TerminationAction) { packet.add(AVP::from_u32(TERMINATION_ACTION_TYPE, value as u32)); } +/// Lookup a `termination_action` value-defined integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `termination_action`, it returns `None`. pub fn lookup_termination_action(packet: &Packet) -> Option> { packet .lookup(TERMINATION_ACTION_TYPE) .map(|v| Ok(v.encode_u32()? as TerminationAction)) } +/// Lookup all of the `termination_action` value-defined integer value from a packet. pub fn lookup_all_termination_action(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(TERMINATION_ACTION_TYPE) { @@ -509,17 +812,23 @@ pub fn lookup_all_termination_action(packet: &Packet) -> Result Option> { packet .lookup(CALLED_STATION_ID_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `called_station_id` string value from a packet. pub fn lookup_all_called_station_id(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(CALLED_STATION_ID_TYPE) { @@ -529,17 +838,23 @@ pub fn lookup_all_called_station_id(packet: &Packet) -> Result, AVPE } pub const CALLING_STATION_ID_TYPE: AVPType = 31; +/// Delete all of `calling_station_id` values from a packet. pub fn delete_calling_station_id(packet: &mut Packet) { packet.delete(CALLING_STATION_ID_TYPE); } +/// Add `calling_station_id` string value to a packet. pub fn add_calling_station_id(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(CALLING_STATION_ID_TYPE, value)); } +/// Lookup a `calling_station_id` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `calling_station_id`, it returns `None`. pub fn lookup_calling_station_id(packet: &Packet) -> Option> { packet .lookup(CALLING_STATION_ID_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `calling_station_id` string value from a packet. pub fn lookup_all_calling_station_id(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(CALLING_STATION_ID_TYPE) { @@ -549,17 +864,23 @@ pub fn lookup_all_calling_station_id(packet: &Packet) -> Result, AVP } pub const NAS_IDENTIFIER_TYPE: AVPType = 32; +/// Delete all of `nas_identifier` values from a packet. pub fn delete_nas_identifier(packet: &mut Packet) { packet.delete(NAS_IDENTIFIER_TYPE); } +/// Add `nas_identifier` string value to a packet. pub fn add_nas_identifier(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(NAS_IDENTIFIER_TYPE, value)); } +/// Lookup a `nas_identifier` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `nas_identifier`, it returns `None`. pub fn lookup_nas_identifier(packet: &Packet) -> Option> { packet .lookup(NAS_IDENTIFIER_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `nas_identifier` string value from a packet. pub fn lookup_all_nas_identifier(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(NAS_IDENTIFIER_TYPE) { @@ -569,15 +890,21 @@ pub fn lookup_all_nas_identifier(packet: &Packet) -> Result, AVPErro } pub const PROXY_STATE_TYPE: AVPType = 33; +/// Delete all of `proxy_state` values from a packet. pub fn delete_proxy_state(packet: &mut Packet) { packet.delete(PROXY_STATE_TYPE); } +/// Add `proxy_state` octets value to a packet. pub fn add_proxy_state(packet: &mut Packet, value: &[u8]) { packet.add(AVP::from_bytes(PROXY_STATE_TYPE, value)); } +/// Lookup a `proxy_state` octets value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `proxy_state`, it returns `None`. pub fn lookup_proxy_state(packet: &Packet) -> Option> { packet.lookup(PROXY_STATE_TYPE).map(|v| v.encode_bytes()) } +/// Lookup all of the `proxy_state` octets value from a packet. pub fn lookup_all_proxy_state(packet: &Packet) -> Vec> { let mut vec = Vec::new(); for avp in packet.lookup_all(PROXY_STATE_TYPE) { @@ -587,17 +914,23 @@ pub fn lookup_all_proxy_state(packet: &Packet) -> Vec> { } pub const LOGIN_LAT_SERVICE_TYPE: AVPType = 34; +/// Delete all of `login_lat_service` values from a packet. pub fn delete_login_lat_service(packet: &mut Packet) { packet.delete(LOGIN_LAT_SERVICE_TYPE); } +/// Add `login_lat_service` string value to a packet. pub fn add_login_lat_service(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(LOGIN_LAT_SERVICE_TYPE, value)); } +/// Lookup a `login_lat_service` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `login_lat_service`, it returns `None`. pub fn lookup_login_lat_service(packet: &Packet) -> Option> { packet .lookup(LOGIN_LAT_SERVICE_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `login_lat_service` string value from a packet. pub fn lookup_all_login_lat_service(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(LOGIN_LAT_SERVICE_TYPE) { @@ -607,17 +940,23 @@ pub fn lookup_all_login_lat_service(packet: &Packet) -> Result, AVPE } pub const LOGIN_LAT_NODE_TYPE: AVPType = 35; +/// Delete all of `login_lat_node` values from a packet. pub fn delete_login_lat_node(packet: &mut Packet) { packet.delete(LOGIN_LAT_NODE_TYPE); } +/// Add `login_lat_node` string value to a packet. pub fn add_login_lat_node(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(LOGIN_LAT_NODE_TYPE, value)); } +/// Lookup a `login_lat_node` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `login_lat_node`, it returns `None`. pub fn lookup_login_lat_node(packet: &Packet) -> Option> { packet .lookup(LOGIN_LAT_NODE_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `login_lat_node` string value from a packet. pub fn lookup_all_login_lat_node(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(LOGIN_LAT_NODE_TYPE) { @@ -627,17 +966,23 @@ pub fn lookup_all_login_lat_node(packet: &Packet) -> Result, AVPErro } pub const LOGIN_LAT_GROUP_TYPE: AVPType = 36; +/// Delete all of `login_lat_group` values from a packet. pub fn delete_login_lat_group(packet: &mut Packet) { packet.delete(LOGIN_LAT_GROUP_TYPE); } +/// Add `login_lat_group` octets value to a packet. pub fn add_login_lat_group(packet: &mut Packet, value: &[u8]) { packet.add(AVP::from_bytes(LOGIN_LAT_GROUP_TYPE, value)); } +/// Lookup a `login_lat_group` octets value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `login_lat_group`, it returns `None`. pub fn lookup_login_lat_group(packet: &Packet) -> Option> { packet .lookup(LOGIN_LAT_GROUP_TYPE) .map(|v| v.encode_bytes()) } +/// Lookup all of the `login_lat_group` octets value from a packet. pub fn lookup_all_login_lat_group(packet: &Packet) -> Vec> { let mut vec = Vec::new(); for avp in packet.lookup_all(LOGIN_LAT_GROUP_TYPE) { @@ -647,17 +992,23 @@ pub fn lookup_all_login_lat_group(packet: &Packet) -> Vec> { } pub const FRAMED_APPLE_TALK_LINK_TYPE: AVPType = 37; +/// Delete all of `framed_apple_talk_link` values from a packet. pub fn delete_framed_apple_talk_link(packet: &mut Packet) { packet.delete(FRAMED_APPLE_TALK_LINK_TYPE); } +/// Add `framed_apple_talk_link` integer value to a packet. pub fn add_framed_apple_talk_link(packet: &mut Packet, value: u32) { packet.add(AVP::from_u32(FRAMED_APPLE_TALK_LINK_TYPE, value)); } +/// Lookup a `framed_apple_talk_link` integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `framed_apple_talk_link`, it returns `None`. pub fn lookup_framed_apple_talk_link(packet: &Packet) -> Option> { packet .lookup(FRAMED_APPLE_TALK_LINK_TYPE) .map(|v| v.encode_u32()) } +/// Lookup all of the `framed_apple_talk_link` integer value from a packet. pub fn lookup_all_framed_apple_talk_link(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(FRAMED_APPLE_TALK_LINK_TYPE) { @@ -667,17 +1018,23 @@ pub fn lookup_all_framed_apple_talk_link(packet: &Packet) -> Result, AV } pub const FRAMED_APPLE_TALK_NETWORK_TYPE: AVPType = 38; +/// Delete all of `framed_apple_talk_network` values from a packet. pub fn delete_framed_apple_talk_network(packet: &mut Packet) { packet.delete(FRAMED_APPLE_TALK_NETWORK_TYPE); } +/// Add `framed_apple_talk_network` integer value to a packet. pub fn add_framed_apple_talk_network(packet: &mut Packet, value: u32) { packet.add(AVP::from_u32(FRAMED_APPLE_TALK_NETWORK_TYPE, value)); } +/// Lookup a `framed_apple_talk_network` integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `framed_apple_talk_network`, it returns `None`. pub fn lookup_framed_apple_talk_network(packet: &Packet) -> Option> { packet .lookup(FRAMED_APPLE_TALK_NETWORK_TYPE) .map(|v| v.encode_u32()) } +/// Lookup all of the `framed_apple_talk_network` integer value from a packet. pub fn lookup_all_framed_apple_talk_network(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(FRAMED_APPLE_TALK_NETWORK_TYPE) { @@ -687,17 +1044,23 @@ pub fn lookup_all_framed_apple_talk_network(packet: &Packet) -> Result, } pub const FRAMED_APPLE_TALK_ZONE_TYPE: AVPType = 39; +/// Delete all of `framed_apple_talk_zone` values from a packet. pub fn delete_framed_apple_talk_zone(packet: &mut Packet) { packet.delete(FRAMED_APPLE_TALK_ZONE_TYPE); } +/// Add `framed_apple_talk_zone` string value to a packet. pub fn add_framed_apple_talk_zone(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(FRAMED_APPLE_TALK_ZONE_TYPE, value)); } +/// Lookup a `framed_apple_talk_zone` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `framed_apple_talk_zone`, it returns `None`. pub fn lookup_framed_apple_talk_zone(packet: &Packet) -> Option> { packet .lookup(FRAMED_APPLE_TALK_ZONE_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `framed_apple_talk_zone` string value from a packet. pub fn lookup_all_framed_apple_talk_zone(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(FRAMED_APPLE_TALK_ZONE_TYPE) { @@ -707,15 +1070,21 @@ pub fn lookup_all_framed_apple_talk_zone(packet: &Packet) -> Result, } pub const CHAP_CHALLENGE_TYPE: AVPType = 60; +/// Delete all of `chap_challenge` values from a packet. pub fn delete_chap_challenge(packet: &mut Packet) { packet.delete(CHAP_CHALLENGE_TYPE); } +/// Add `chap_challenge` octets value to a packet. pub fn add_chap_challenge(packet: &mut Packet, value: &[u8]) { packet.add(AVP::from_bytes(CHAP_CHALLENGE_TYPE, value)); } +/// Lookup a `chap_challenge` octets value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `chap_challenge`, it returns `None`. pub fn lookup_chap_challenge(packet: &Packet) -> Option> { packet.lookup(CHAP_CHALLENGE_TYPE).map(|v| v.encode_bytes()) } +/// Lookup all of the `chap_challenge` octets value from a packet. pub fn lookup_all_chap_challenge(packet: &Packet) -> Vec> { let mut vec = Vec::new(); for avp in packet.lookup_all(CHAP_CHALLENGE_TYPE) { @@ -725,17 +1094,23 @@ pub fn lookup_all_chap_challenge(packet: &Packet) -> Vec> { } pub const NAS_PORT_TYPE_TYPE: AVPType = 61; +/// Delete all of `nas_port_type` values from a packet. pub fn delete_nas_port_type(packet: &mut Packet) { packet.delete(NAS_PORT_TYPE_TYPE); } +/// Add `nas_port_type` value-defined integer value to a packet. pub fn add_nas_port_type(packet: &mut Packet, value: NasPortType) { packet.add(AVP::from_u32(NAS_PORT_TYPE_TYPE, value as u32)); } +/// Lookup a `nas_port_type` value-defined integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `nas_port_type`, it returns `None`. pub fn lookup_nas_port_type(packet: &Packet) -> Option> { packet .lookup(NAS_PORT_TYPE_TYPE) .map(|v| Ok(v.encode_u32()? as NasPortType)) } +/// Lookup all of the `nas_port_type` value-defined integer value from a packet. pub fn lookup_all_nas_port_type(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(NAS_PORT_TYPE_TYPE) { @@ -745,15 +1120,21 @@ pub fn lookup_all_nas_port_type(packet: &Packet) -> Result, AVP } pub const PORT_LIMIT_TYPE: AVPType = 62; +/// Delete all of `port_limit` values from a packet. pub fn delete_port_limit(packet: &mut Packet) { packet.delete(PORT_LIMIT_TYPE); } +/// Add `port_limit` integer value to a packet. pub fn add_port_limit(packet: &mut Packet, value: u32) { packet.add(AVP::from_u32(PORT_LIMIT_TYPE, value)); } +/// Lookup a `port_limit` integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `port_limit`, it returns `None`. pub fn lookup_port_limit(packet: &Packet) -> Option> { packet.lookup(PORT_LIMIT_TYPE).map(|v| v.encode_u32()) } +/// Lookup all of the `port_limit` integer value from a packet. pub fn lookup_all_port_limit(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(PORT_LIMIT_TYPE) { @@ -763,17 +1144,23 @@ pub fn lookup_all_port_limit(packet: &Packet) -> Result, AVPError> { } pub const LOGIN_LAT_PORT_TYPE: AVPType = 63; +/// Delete all of `login_lat_port` values from a packet. pub fn delete_login_lat_port(packet: &mut Packet) { packet.delete(LOGIN_LAT_PORT_TYPE); } +/// Add `login_lat_port` string value to a packet. pub fn add_login_lat_port(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(LOGIN_LAT_PORT_TYPE, value)); } +/// Lookup a `login_lat_port` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `login_lat_port`, it returns `None`. pub fn lookup_login_lat_port(packet: &Packet) -> Option> { packet .lookup(LOGIN_LAT_PORT_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `login_lat_port` string value from a packet. pub fn lookup_all_login_lat_port(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(LOGIN_LAT_PORT_TYPE) { diff --git a/radius/src/core/rfc2866.rs b/radius/src/core/rfc2866.rs index 02bdcb3..358aa9f 100644 --- a/radius/src/core/rfc2866.rs +++ b/radius/src/core/rfc2866.rs @@ -1,20 +1,92 @@ // Code generated by machine generator; DO NOT EDIT. +//! Utility for rfc2866 packet. +//! +//! This module handles the packet according to the following definition: +//! ```text +//! //! # -*- text -*- +//! # Copyright (C) 2020 The FreeRADIUS Server project and contributors +//! # This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0 +//! # Version $Id$ +//! # +//! # Attributes and values defined in RFC 2866. +//! # http://www.ietf.org/rfc/rfc2866.txt +//! # +//! # $Id$ +//! # +//! ATTRIBUTE Acct-Status-Type 40 integer +//! ATTRIBUTE Acct-Delay-Time 41 integer +//! ATTRIBUTE Acct-Input-Octets 42 integer +//! ATTRIBUTE Acct-Output-Octets 43 integer +//! ATTRIBUTE Acct-Session-Id 44 string +//! ATTRIBUTE Acct-Authentic 45 integer +//! ATTRIBUTE Acct-Session-Time 46 integer +//! ATTRIBUTE Acct-Input-Packets 47 integer +//! ATTRIBUTE Acct-Output-Packets 48 integer +//! ATTRIBUTE Acct-Terminate-Cause 49 integer +//! ATTRIBUTE Acct-Multi-Session-Id 50 string +//! ATTRIBUTE Acct-Link-Count 51 integer +//! +//! # Accounting Status Types +//! +//! VALUE Acct-Status-Type Start 1 +//! VALUE Acct-Status-Type Stop 2 +//! VALUE Acct-Status-Type Alive 3 # dup +//! VALUE Acct-Status-Type Interim-Update 3 +//! VALUE Acct-Status-Type Accounting-On 7 +//! VALUE Acct-Status-Type Accounting-Off 8 +//! VALUE Acct-Status-Type Failed 15 +//! +//! # Authentication Types +//! +//! VALUE Acct-Authentic RADIUS 1 +//! VALUE Acct-Authentic Local 2 +//! VALUE Acct-Authentic Remote 3 +//! VALUE Acct-Authentic Diameter 4 +//! +//! # Acct Terminate Causes +//! +//! VALUE Acct-Terminate-Cause User-Request 1 +//! VALUE Acct-Terminate-Cause Lost-Carrier 2 +//! VALUE Acct-Terminate-Cause Lost-Service 3 +//! VALUE Acct-Terminate-Cause Idle-Timeout 4 +//! VALUE Acct-Terminate-Cause Session-Timeout 5 +//! VALUE Acct-Terminate-Cause Admin-Reset 6 +//! VALUE Acct-Terminate-Cause Admin-Reboot 7 +//! VALUE Acct-Terminate-Cause Port-Error 8 +//! VALUE Acct-Terminate-Cause NAS-Error 9 +//! VALUE Acct-Terminate-Cause NAS-Request 10 +//! VALUE Acct-Terminate-Cause NAS-Reboot 11 +//! VALUE Acct-Terminate-Cause Port-Unneeded 12 +//! VALUE Acct-Terminate-Cause Port-Preempted 13 +//! VALUE Acct-Terminate-Cause Port-Suspended 14 +//! VALUE Acct-Terminate-Cause Service-Unavailable 15 +//! VALUE Acct-Terminate-Cause Callback 16 +//! VALUE Acct-Terminate-Cause User-Error 17 +//! VALUE Acct-Terminate-Cause Host-Request 18 +//! ``` + use crate::core::avp::{AVPError, AVPType, AVP}; use crate::core::packet::Packet; pub const ACCT_STATUS_TYPE_TYPE: AVPType = 40; +/// Delete all of `acct_status_type` values from a packet. pub fn delete_acct_status_type(packet: &mut Packet) { packet.delete(ACCT_STATUS_TYPE_TYPE); } +/// Add `acct_status_type` value-defined integer value to a packet. pub fn add_acct_status_type(packet: &mut Packet, value: AcctStatusType) { packet.add(AVP::from_u32(ACCT_STATUS_TYPE_TYPE, value as u32)); } +/// Lookup a `acct_status_type` value-defined integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `acct_status_type`, it returns `None`. pub fn lookup_acct_status_type(packet: &Packet) -> Option> { packet .lookup(ACCT_STATUS_TYPE_TYPE) .map(|v| Ok(v.encode_u32()? as AcctStatusType)) } +/// Lookup all of the `acct_status_type` value-defined integer value from a packet. pub fn lookup_all_acct_status_type(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(ACCT_STATUS_TYPE_TYPE) { @@ -24,15 +96,21 @@ pub fn lookup_all_acct_status_type(packet: &Packet) -> Result Option> { packet.lookup(ACCT_DELAY_TIME_TYPE).map(|v| v.encode_u32()) } +/// Lookup all of the `acct_delay_time` integer value from a packet. pub fn lookup_all_acct_delay_time(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(ACCT_DELAY_TIME_TYPE) { @@ -42,17 +120,23 @@ pub fn lookup_all_acct_delay_time(packet: &Packet) -> Result, AVPError> } pub const ACCT_INPUT_OCTETS_TYPE: AVPType = 42; +/// Delete all of `acct_input_octets` values from a packet. pub fn delete_acct_input_octets(packet: &mut Packet) { packet.delete(ACCT_INPUT_OCTETS_TYPE); } +/// Add `acct_input_octets` integer value to a packet. pub fn add_acct_input_octets(packet: &mut Packet, value: u32) { packet.add(AVP::from_u32(ACCT_INPUT_OCTETS_TYPE, value)); } +/// Lookup a `acct_input_octets` integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `acct_input_octets`, it returns `None`. pub fn lookup_acct_input_octets(packet: &Packet) -> Option> { packet .lookup(ACCT_INPUT_OCTETS_TYPE) .map(|v| v.encode_u32()) } +/// Lookup all of the `acct_input_octets` integer value from a packet. pub fn lookup_all_acct_input_octets(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(ACCT_INPUT_OCTETS_TYPE) { @@ -62,17 +146,23 @@ pub fn lookup_all_acct_input_octets(packet: &Packet) -> Result, AVPErro } pub const ACCT_OUTPUT_OCTETS_TYPE: AVPType = 43; +/// Delete all of `acct_output_octets` values from a packet. pub fn delete_acct_output_octets(packet: &mut Packet) { packet.delete(ACCT_OUTPUT_OCTETS_TYPE); } +/// Add `acct_output_octets` integer value to a packet. pub fn add_acct_output_octets(packet: &mut Packet, value: u32) { packet.add(AVP::from_u32(ACCT_OUTPUT_OCTETS_TYPE, value)); } +/// Lookup a `acct_output_octets` integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `acct_output_octets`, it returns `None`. pub fn lookup_acct_output_octets(packet: &Packet) -> Option> { packet .lookup(ACCT_OUTPUT_OCTETS_TYPE) .map(|v| v.encode_u32()) } +/// Lookup all of the `acct_output_octets` integer value from a packet. pub fn lookup_all_acct_output_octets(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(ACCT_OUTPUT_OCTETS_TYPE) { @@ -82,17 +172,23 @@ pub fn lookup_all_acct_output_octets(packet: &Packet) -> Result, AVPErr } pub const ACCT_SESSION_ID_TYPE: AVPType = 44; +/// Delete all of `acct_session_id` values from a packet. pub fn delete_acct_session_id(packet: &mut Packet) { packet.delete(ACCT_SESSION_ID_TYPE); } +/// Add `acct_session_id` string value to a packet. pub fn add_acct_session_id(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(ACCT_SESSION_ID_TYPE, value)); } +/// Lookup a `acct_session_id` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `acct_session_id`, it returns `None`. pub fn lookup_acct_session_id(packet: &Packet) -> Option> { packet .lookup(ACCT_SESSION_ID_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `acct_session_id` string value from a packet. pub fn lookup_all_acct_session_id(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(ACCT_SESSION_ID_TYPE) { @@ -102,17 +198,23 @@ pub fn lookup_all_acct_session_id(packet: &Packet) -> Result, AVPErr } pub const ACCT_AUTHENTIC_TYPE: AVPType = 45; +/// Delete all of `acct_authentic` values from a packet. pub fn delete_acct_authentic(packet: &mut Packet) { packet.delete(ACCT_AUTHENTIC_TYPE); } +/// Add `acct_authentic` value-defined integer value to a packet. pub fn add_acct_authentic(packet: &mut Packet, value: AcctAuthentic) { packet.add(AVP::from_u32(ACCT_AUTHENTIC_TYPE, value as u32)); } +/// Lookup a `acct_authentic` value-defined integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `acct_authentic`, it returns `None`. pub fn lookup_acct_authentic(packet: &Packet) -> Option> { packet .lookup(ACCT_AUTHENTIC_TYPE) .map(|v| Ok(v.encode_u32()? as AcctAuthentic)) } +/// Lookup all of the `acct_authentic` value-defined integer value from a packet. pub fn lookup_all_acct_authentic(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(ACCT_AUTHENTIC_TYPE) { @@ -122,17 +224,23 @@ pub fn lookup_all_acct_authentic(packet: &Packet) -> Result, } pub const ACCT_SESSION_TIME_TYPE: AVPType = 46; +/// Delete all of `acct_session_time` values from a packet. pub fn delete_acct_session_time(packet: &mut Packet) { packet.delete(ACCT_SESSION_TIME_TYPE); } +/// Add `acct_session_time` integer value to a packet. pub fn add_acct_session_time(packet: &mut Packet, value: u32) { packet.add(AVP::from_u32(ACCT_SESSION_TIME_TYPE, value)); } +/// Lookup a `acct_session_time` integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `acct_session_time`, it returns `None`. pub fn lookup_acct_session_time(packet: &Packet) -> Option> { packet .lookup(ACCT_SESSION_TIME_TYPE) .map(|v| v.encode_u32()) } +/// Lookup all of the `acct_session_time` integer value from a packet. pub fn lookup_all_acct_session_time(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(ACCT_SESSION_TIME_TYPE) { @@ -142,17 +250,23 @@ pub fn lookup_all_acct_session_time(packet: &Packet) -> Result, AVPErro } pub const ACCT_INPUT_PACKETS_TYPE: AVPType = 47; +/// Delete all of `acct_input_packets` values from a packet. pub fn delete_acct_input_packets(packet: &mut Packet) { packet.delete(ACCT_INPUT_PACKETS_TYPE); } +/// Add `acct_input_packets` integer value to a packet. pub fn add_acct_input_packets(packet: &mut Packet, value: u32) { packet.add(AVP::from_u32(ACCT_INPUT_PACKETS_TYPE, value)); } +/// Lookup a `acct_input_packets` integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `acct_input_packets`, it returns `None`. pub fn lookup_acct_input_packets(packet: &Packet) -> Option> { packet .lookup(ACCT_INPUT_PACKETS_TYPE) .map(|v| v.encode_u32()) } +/// Lookup all of the `acct_input_packets` integer value from a packet. pub fn lookup_all_acct_input_packets(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(ACCT_INPUT_PACKETS_TYPE) { @@ -162,17 +276,23 @@ pub fn lookup_all_acct_input_packets(packet: &Packet) -> Result, AVPErr } pub const ACCT_OUTPUT_PACKETS_TYPE: AVPType = 48; +/// Delete all of `acct_output_packets` values from a packet. pub fn delete_acct_output_packets(packet: &mut Packet) { packet.delete(ACCT_OUTPUT_PACKETS_TYPE); } +/// Add `acct_output_packets` integer value to a packet. pub fn add_acct_output_packets(packet: &mut Packet, value: u32) { packet.add(AVP::from_u32(ACCT_OUTPUT_PACKETS_TYPE, value)); } +/// Lookup a `acct_output_packets` integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `acct_output_packets`, it returns `None`. pub fn lookup_acct_output_packets(packet: &Packet) -> Option> { packet .lookup(ACCT_OUTPUT_PACKETS_TYPE) .map(|v| v.encode_u32()) } +/// Lookup all of the `acct_output_packets` integer value from a packet. pub fn lookup_all_acct_output_packets(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(ACCT_OUTPUT_PACKETS_TYPE) { @@ -182,12 +302,17 @@ pub fn lookup_all_acct_output_packets(packet: &Packet) -> Result, AVPEr } pub const ACCT_TERMINATE_CAUSE_TYPE: AVPType = 49; +/// Delete all of `acct_terminate_cause` values from a packet. pub fn delete_acct_terminate_cause(packet: &mut Packet) { packet.delete(ACCT_TERMINATE_CAUSE_TYPE); } +/// Add `acct_terminate_cause` value-defined integer value to a packet. pub fn add_acct_terminate_cause(packet: &mut Packet, value: AcctTerminateCause) { packet.add(AVP::from_u32(ACCT_TERMINATE_CAUSE_TYPE, value as u32)); } +/// Lookup a `acct_terminate_cause` value-defined integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `acct_terminate_cause`, it returns `None`. pub fn lookup_acct_terminate_cause( packet: &Packet, ) -> Option> { @@ -195,6 +320,7 @@ pub fn lookup_acct_terminate_cause( .lookup(ACCT_TERMINATE_CAUSE_TYPE) .map(|v| Ok(v.encode_u32()? as AcctTerminateCause)) } +/// Lookup all of the `acct_terminate_cause` value-defined integer value from a packet. pub fn lookup_all_acct_terminate_cause( packet: &Packet, ) -> Result, AVPError> { @@ -206,17 +332,23 @@ pub fn lookup_all_acct_terminate_cause( } pub const ACCT_MULTI_SESSION_ID_TYPE: AVPType = 50; +/// Delete all of `acct_multi_session_id` values from a packet. pub fn delete_acct_multi_session_id(packet: &mut Packet) { packet.delete(ACCT_MULTI_SESSION_ID_TYPE); } +/// Add `acct_multi_session_id` string value to a packet. pub fn add_acct_multi_session_id(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(ACCT_MULTI_SESSION_ID_TYPE, value)); } +/// Lookup a `acct_multi_session_id` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `acct_multi_session_id`, it returns `None`. pub fn lookup_acct_multi_session_id(packet: &Packet) -> Option> { packet .lookup(ACCT_MULTI_SESSION_ID_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `acct_multi_session_id` string value from a packet. pub fn lookup_all_acct_multi_session_id(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(ACCT_MULTI_SESSION_ID_TYPE) { @@ -226,15 +358,21 @@ pub fn lookup_all_acct_multi_session_id(packet: &Packet) -> Result, } pub const ACCT_LINK_COUNT_TYPE: AVPType = 51; +/// Delete all of `acct_link_count` values from a packet. pub fn delete_acct_link_count(packet: &mut Packet) { packet.delete(ACCT_LINK_COUNT_TYPE); } +/// Add `acct_link_count` integer value to a packet. pub fn add_acct_link_count(packet: &mut Packet, value: u32) { packet.add(AVP::from_u32(ACCT_LINK_COUNT_TYPE, value)); } +/// Lookup a `acct_link_count` integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `acct_link_count`, it returns `None`. pub fn lookup_acct_link_count(packet: &Packet) -> Option> { packet.lookup(ACCT_LINK_COUNT_TYPE).map(|v| v.encode_u32()) } +/// Lookup all of the `acct_link_count` integer value from a packet. pub fn lookup_all_acct_link_count(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(ACCT_LINK_COUNT_TYPE) { diff --git a/radius/src/core/rfc2867.rs b/radius/src/core/rfc2867.rs index 28461fb..6441afd 100644 --- a/radius/src/core/rfc2867.rs +++ b/radius/src/core/rfc2867.rs @@ -1,22 +1,53 @@ // Code generated by machine generator; DO NOT EDIT. +//! Utility for rfc2867 packet. +//! +//! This module handles the packet according to the following definition: +//! ```text +//! //! # -*- text -*- +//! # Copyright (C) 2020 The FreeRADIUS Server project and contributors +//! # This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0 +//! # Version $Id$ +//! # +//! # Attributes and values defined in RFC 2867. +//! # http://www.ietf.org/rfc/rfc2867.txt +//! # +//! # $Id$ +//! # +//! ATTRIBUTE Acct-Tunnel-Connection 68 string +//! ATTRIBUTE Acct-Tunnel-Packets-Lost 86 integer +//! +//! VALUE Acct-Status-Type Tunnel-Start 9 +//! VALUE Acct-Status-Type Tunnel-Stop 10 +//! VALUE Acct-Status-Type Tunnel-Reject 11 +//! VALUE Acct-Status-Type Tunnel-Link-Start 12 +//! VALUE Acct-Status-Type Tunnel-Link-Stop 13 +//! VALUE Acct-Status-Type Tunnel-Link-Reject 14 +//! ``` + use crate::core::avp::{AVPError, AVPType, AVP}; use crate::core::packet::Packet; use crate::core::rfc2866; pub const ACCT_TUNNEL_CONNECTION_TYPE: AVPType = 68; +/// Delete all of `acct_tunnel_connection` values from a packet. pub fn delete_acct_tunnel_connection(packet: &mut Packet) { packet.delete(ACCT_TUNNEL_CONNECTION_TYPE); } +/// Add `acct_tunnel_connection` string value to a packet. pub fn add_acct_tunnel_connection(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(ACCT_TUNNEL_CONNECTION_TYPE, value)); } +/// Lookup a `acct_tunnel_connection` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `acct_tunnel_connection`, it returns `None`. pub fn lookup_acct_tunnel_connection(packet: &Packet) -> Option> { packet .lookup(ACCT_TUNNEL_CONNECTION_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `acct_tunnel_connection` string value from a packet. pub fn lookup_all_acct_tunnel_connection(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(ACCT_TUNNEL_CONNECTION_TYPE) { @@ -26,17 +57,23 @@ pub fn lookup_all_acct_tunnel_connection(packet: &Packet) -> Result, } pub const ACCT_TUNNEL_PACKETS_LOST_TYPE: AVPType = 86; +/// Delete all of `acct_tunnel_packets_lost` values from a packet. pub fn delete_acct_tunnel_packets_lost(packet: &mut Packet) { packet.delete(ACCT_TUNNEL_PACKETS_LOST_TYPE); } +/// Add `acct_tunnel_packets_lost` integer value to a packet. pub fn add_acct_tunnel_packets_lost(packet: &mut Packet, value: u32) { packet.add(AVP::from_u32(ACCT_TUNNEL_PACKETS_LOST_TYPE, value)); } +/// Lookup a `acct_tunnel_packets_lost` integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `acct_tunnel_packets_lost`, it returns `None`. pub fn lookup_acct_tunnel_packets_lost(packet: &Packet) -> Option> { packet .lookup(ACCT_TUNNEL_PACKETS_LOST_TYPE) .map(|v| v.encode_u32()) } +/// Lookup all of the `acct_tunnel_packets_lost` integer value from a packet. pub fn lookup_all_acct_tunnel_packets_lost(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(ACCT_TUNNEL_PACKETS_LOST_TYPE) { diff --git a/radius/src/core/rfc2868.rs b/radius/src/core/rfc2868.rs index db7744c..1802a78 100644 --- a/radius/src/core/rfc2868.rs +++ b/radius/src/core/rfc2868.rs @@ -1,22 +1,91 @@ // Code generated by machine generator; DO NOT EDIT. +//! Utility for rfc2868 packet. +//! +//! This module handles the packet according to the following definition: +//! ```text +//! //! # -*- text -*- +//! # Copyright (C) 2020 The FreeRADIUS Server project and contributors +//! # This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0 +//! # Version $Id$ +//! # +//! # Attributes and values defined in RFC 2868. +//! # http://www.ietf.org/rfc/rfc2868.txt +//! # +//! # $Id$ +//! # +//! ATTRIBUTE Tunnel-Type 64 integer has_tag +//! ATTRIBUTE Tunnel-Medium-Type 65 integer has_tag +//! ATTRIBUTE Tunnel-Client-Endpoint 66 string has_tag +//! ATTRIBUTE Tunnel-Server-Endpoint 67 string has_tag +//! +//! ATTRIBUTE Tunnel-Password 69 string has_tag,encrypt=2 +//! +//! ATTRIBUTE Tunnel-Private-Group-Id 81 string has_tag +//! ATTRIBUTE Tunnel-Assignment-Id 82 string has_tag +//! ATTRIBUTE Tunnel-Preference 83 integer has_tag +//! +//! ATTRIBUTE Tunnel-Client-Auth-Id 90 string has_tag +//! ATTRIBUTE Tunnel-Server-Auth-Id 91 string has_tag +//! +//! # Tunnel Type +//! +//! VALUE Tunnel-Type PPTP 1 +//! VALUE Tunnel-Type L2F 2 +//! VALUE Tunnel-Type L2TP 3 +//! VALUE Tunnel-Type ATMP 4 +//! VALUE Tunnel-Type VTP 5 +//! VALUE Tunnel-Type AH 6 +//! VALUE Tunnel-Type IP 7 +//! VALUE Tunnel-Type MIN-IP 8 +//! VALUE Tunnel-Type ESP 9 +//! VALUE Tunnel-Type GRE 10 +//! VALUE Tunnel-Type DVS 11 +//! VALUE Tunnel-Type IP-in-IP 12 +//! +//! # Tunnel Medium Type +//! +//! VALUE Tunnel-Medium-Type IP 1 +//! VALUE Tunnel-Medium-Type IPv4 1 +//! VALUE Tunnel-Medium-Type IPv6 2 +//! VALUE Tunnel-Medium-Type NSAP 3 +//! VALUE Tunnel-Medium-Type HDLC 4 +//! VALUE Tunnel-Medium-Type BBN-1822 5 +//! VALUE Tunnel-Medium-Type IEEE-802 6 +//! VALUE Tunnel-Medium-Type E.163 7 +//! VALUE Tunnel-Medium-Type E.164 8 +//! VALUE Tunnel-Medium-Type F.69 9 +//! VALUE Tunnel-Medium-Type X.121 10 +//! VALUE Tunnel-Medium-Type IPX 11 +//! VALUE Tunnel-Medium-Type Appletalk 12 +//! VALUE Tunnel-Medium-Type DecNet-IV 13 +//! VALUE Tunnel-Medium-Type Banyan-Vines 14 +//! VALUE Tunnel-Medium-Type E.164-NSAP 15 +//! ``` + use crate::core::avp::{AVPError, AVPType, AVP}; use crate::core::packet::Packet; use crate::core::tag::Tag; pub const TUNNEL_TYPE_TYPE: AVPType = 64; +/// Delete all of `tunnel_type` values from a packet. pub fn delete_tunnel_type(packet: &mut Packet) { packet.delete(TUNNEL_TYPE_TYPE); } +/// Add `tunnel_type` tagged value-defined integer value to a packet. pub fn add_tunnel_type(packet: &mut Packet, tag: Option<&Tag>, value: TunnelType) { packet.add(AVP::from_tagged_u32(TUNNEL_TYPE_TYPE, tag, value as u32)); } +/// Lookup a `tunnel_type` tagged value-defined integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `tunnel_type`, it returns `None`. pub fn lookup_tunnel_type(packet: &Packet) -> Option> { packet.lookup(TUNNEL_TYPE_TYPE).map(|v| { let (v, t) = v.encode_tagged_u32()?; Ok((v as TunnelType, t)) }) } +/// Lookup all of the `tunnel_type` tagged value-defined integer value from a packet. pub fn lookup_all_tunnel_type(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(TUNNEL_TYPE_TYPE) { @@ -27,9 +96,11 @@ pub fn lookup_all_tunnel_type(packet: &Packet) -> Result, } pub const TUNNEL_MEDIUM_TYPE_TYPE: AVPType = 65; +/// Delete all of `tunnel_medium_type` values from a packet. pub fn delete_tunnel_medium_type(packet: &mut Packet) { packet.delete(TUNNEL_MEDIUM_TYPE_TYPE); } +/// Add `tunnel_medium_type` tagged value-defined integer value to a packet. pub fn add_tunnel_medium_type(packet: &mut Packet, tag: Option<&Tag>, value: TunnelMediumType) { packet.add(AVP::from_tagged_u32( TUNNEL_MEDIUM_TYPE_TYPE, @@ -37,6 +108,9 @@ pub fn add_tunnel_medium_type(packet: &mut Packet, tag: Option<&Tag>, value: Tun value as u32, )); } +/// Lookup a `tunnel_medium_type` tagged value-defined integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `tunnel_medium_type`, it returns `None`. pub fn lookup_tunnel_medium_type( packet: &Packet, ) -> Option> { @@ -45,6 +119,7 @@ pub fn lookup_tunnel_medium_type( Ok((v as TunnelMediumType, t)) }) } +/// Lookup all of the `tunnel_medium_type` tagged value-defined integer value from a packet. pub fn lookup_all_tunnel_medium_type( packet: &Packet, ) -> Result, AVPError> { @@ -57,9 +132,11 @@ pub fn lookup_all_tunnel_medium_type( } pub const TUNNEL_CLIENT_ENDPOINT_TYPE: AVPType = 66; +/// Delete all of `tunnel_client_endpoint` values from a packet. pub fn delete_tunnel_client_endpoint(packet: &mut Packet) { packet.delete(TUNNEL_CLIENT_ENDPOINT_TYPE); } +/// Add `tunnel_client_endpoint` tagged string value to a packet. pub fn add_tunnel_client_endpoint(packet: &mut Packet, tag: Option<&Tag>, value: &str) { packet.add(AVP::from_tagged_string( TUNNEL_CLIENT_ENDPOINT_TYPE, @@ -67,6 +144,9 @@ pub fn add_tunnel_client_endpoint(packet: &mut Packet, tag: Option<&Tag>, value: value, )); } +/// Lookup a `tunnel_client_endpoint` tagged string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `tunnel_client_endpoint`, it returns `None`. pub fn lookup_tunnel_client_endpoint( packet: &Packet, ) -> Option), AVPError>> { @@ -74,6 +154,7 @@ pub fn lookup_tunnel_client_endpoint( .lookup(TUNNEL_CLIENT_ENDPOINT_TYPE) .map(|v| v.encode_tagged_string()) } +/// Lookup all of the `tunnel_client_endpoint` tagged string value from a packet. pub fn lookup_all_tunnel_client_endpoint( packet: &Packet, ) -> Result)>, AVPError> { @@ -85,9 +166,11 @@ pub fn lookup_all_tunnel_client_endpoint( } pub const TUNNEL_SERVER_ENDPOINT_TYPE: AVPType = 67; +/// Delete all of `tunnel_server_endpoint` values from a packet. pub fn delete_tunnel_server_endpoint(packet: &mut Packet) { packet.delete(TUNNEL_SERVER_ENDPOINT_TYPE); } +/// Add `tunnel_server_endpoint` tagged string value to a packet. pub fn add_tunnel_server_endpoint(packet: &mut Packet, tag: Option<&Tag>, value: &str) { packet.add(AVP::from_tagged_string( TUNNEL_SERVER_ENDPOINT_TYPE, @@ -95,6 +178,9 @@ pub fn add_tunnel_server_endpoint(packet: &mut Packet, tag: Option<&Tag>, value: value, )); } +/// Lookup a `tunnel_server_endpoint` tagged string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `tunnel_server_endpoint`, it returns `None`. pub fn lookup_tunnel_server_endpoint( packet: &Packet, ) -> Option), AVPError>> { @@ -102,6 +188,7 @@ pub fn lookup_tunnel_server_endpoint( .lookup(TUNNEL_SERVER_ENDPOINT_TYPE) .map(|v| v.encode_tagged_string()) } +/// Lookup all of the `tunnel_server_endpoint` tagged string value from a packet. pub fn lookup_all_tunnel_server_endpoint( packet: &Packet, ) -> Result)>, AVPError> { @@ -113,9 +200,11 @@ pub fn lookup_all_tunnel_server_endpoint( } pub const TUNNEL_PASSWORD_TYPE: AVPType = 69; +/// Delete all of `tunnel_password` values from a packet. pub fn delete_tunnel_password(packet: &mut Packet) { packet.delete(TUNNEL_PASSWORD_TYPE); } +/// Add `tunnel_password` tunnel-password value to a packet. pub fn add_tunnel_password( packet: &mut Packet, tag: Option<&Tag>, @@ -130,11 +219,15 @@ pub fn add_tunnel_password( )?); Ok(()) } +/// Lookup a `tunnel_password` tunnel-password value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `tunnel_password`, it returns `None`. pub fn lookup_tunnel_password(packet: &Packet) -> Option, Tag), AVPError>> { packet .lookup(TUNNEL_PASSWORD_TYPE) .map(|v| v.encode_tunnel_password(packet.get_secret(), packet.get_authenticator())) } +/// Lookup all of the `tunnel_password` tunnel-password value from a packet. pub fn lookup_all_tunnel_password(packet: &Packet) -> Result, Tag)>, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(TUNNEL_PASSWORD_TYPE) { @@ -144,9 +237,11 @@ pub fn lookup_all_tunnel_password(packet: &Packet) -> Result, Tag)> } pub const TUNNEL_PRIVATE_GROUP_ID_TYPE: AVPType = 81; +/// Delete all of `tunnel_private_group_id` values from a packet. pub fn delete_tunnel_private_group_id(packet: &mut Packet) { packet.delete(TUNNEL_PRIVATE_GROUP_ID_TYPE); } +/// Add `tunnel_private_group_id` tagged string value to a packet. pub fn add_tunnel_private_group_id(packet: &mut Packet, tag: Option<&Tag>, value: &str) { packet.add(AVP::from_tagged_string( TUNNEL_PRIVATE_GROUP_ID_TYPE, @@ -154,6 +249,9 @@ pub fn add_tunnel_private_group_id(packet: &mut Packet, tag: Option<&Tag>, value value, )); } +/// Lookup a `tunnel_private_group_id` tagged string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `tunnel_private_group_id`, it returns `None`. pub fn lookup_tunnel_private_group_id( packet: &Packet, ) -> Option), AVPError>> { @@ -161,6 +259,7 @@ pub fn lookup_tunnel_private_group_id( .lookup(TUNNEL_PRIVATE_GROUP_ID_TYPE) .map(|v| v.encode_tagged_string()) } +/// Lookup all of the `tunnel_private_group_id` tagged string value from a packet. pub fn lookup_all_tunnel_private_group_id( packet: &Packet, ) -> Result)>, AVPError> { @@ -172,9 +271,11 @@ pub fn lookup_all_tunnel_private_group_id( } pub const TUNNEL_ASSIGNMENT_ID_TYPE: AVPType = 82; +/// Delete all of `tunnel_assignment_id` values from a packet. pub fn delete_tunnel_assignment_id(packet: &mut Packet) { packet.delete(TUNNEL_ASSIGNMENT_ID_TYPE); } +/// Add `tunnel_assignment_id` tagged string value to a packet. pub fn add_tunnel_assignment_id(packet: &mut Packet, tag: Option<&Tag>, value: &str) { packet.add(AVP::from_tagged_string( TUNNEL_ASSIGNMENT_ID_TYPE, @@ -182,6 +283,9 @@ pub fn add_tunnel_assignment_id(packet: &mut Packet, tag: Option<&Tag>, value: & value, )); } +/// Lookup a `tunnel_assignment_id` tagged string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `tunnel_assignment_id`, it returns `None`. pub fn lookup_tunnel_assignment_id( packet: &Packet, ) -> Option), AVPError>> { @@ -189,6 +293,7 @@ pub fn lookup_tunnel_assignment_id( .lookup(TUNNEL_ASSIGNMENT_ID_TYPE) .map(|v| v.encode_tagged_string()) } +/// Lookup all of the `tunnel_assignment_id` tagged string value from a packet. pub fn lookup_all_tunnel_assignment_id( packet: &Packet, ) -> Result)>, AVPError> { @@ -200,17 +305,23 @@ pub fn lookup_all_tunnel_assignment_id( } pub const TUNNEL_PREFERENCE_TYPE: AVPType = 83; +/// Delete all of `tunnel_preference` values from a packet. pub fn delete_tunnel_preference(packet: &mut Packet) { packet.delete(TUNNEL_PREFERENCE_TYPE); } +/// Add `tunnel_preference` tagged integer value to a packet. pub fn add_tunnel_preference(packet: &mut Packet, tag: Option<&Tag>, value: u32) { packet.add(AVP::from_tagged_u32(TUNNEL_PREFERENCE_TYPE, tag, value)); } +/// Lookup a `tunnel_preference` tagged integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `tunnel_preference`, it returns `None`. pub fn lookup_tunnel_preference(packet: &Packet) -> Option> { packet .lookup(TUNNEL_PREFERENCE_TYPE) .map(|v| v.encode_tagged_u32()) } +/// Lookup all of the `tunnel_preference` tagged integer value from a packet. pub fn lookup_all_tunnel_preference(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(TUNNEL_PREFERENCE_TYPE) { @@ -220,9 +331,11 @@ pub fn lookup_all_tunnel_preference(packet: &Packet) -> Result, } pub const TUNNEL_CLIENT_AUTH_ID_TYPE: AVPType = 90; +/// Delete all of `tunnel_client_auth_id` values from a packet. pub fn delete_tunnel_client_auth_id(packet: &mut Packet) { packet.delete(TUNNEL_CLIENT_AUTH_ID_TYPE); } +/// Add `tunnel_client_auth_id` tagged string value to a packet. pub fn add_tunnel_client_auth_id(packet: &mut Packet, tag: Option<&Tag>, value: &str) { packet.add(AVP::from_tagged_string( TUNNEL_CLIENT_AUTH_ID_TYPE, @@ -230,6 +343,9 @@ pub fn add_tunnel_client_auth_id(packet: &mut Packet, tag: Option<&Tag>, value: value, )); } +/// Lookup a `tunnel_client_auth_id` tagged string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `tunnel_client_auth_id`, it returns `None`. pub fn lookup_tunnel_client_auth_id( packet: &Packet, ) -> Option), AVPError>> { @@ -237,6 +353,7 @@ pub fn lookup_tunnel_client_auth_id( .lookup(TUNNEL_CLIENT_AUTH_ID_TYPE) .map(|v| v.encode_tagged_string()) } +/// Lookup all of the `tunnel_client_auth_id` tagged string value from a packet. pub fn lookup_all_tunnel_client_auth_id( packet: &Packet, ) -> Result)>, AVPError> { @@ -248,9 +365,11 @@ pub fn lookup_all_tunnel_client_auth_id( } pub const TUNNEL_SERVER_AUTH_ID_TYPE: AVPType = 91; +/// Delete all of `tunnel_server_auth_id` values from a packet. pub fn delete_tunnel_server_auth_id(packet: &mut Packet) { packet.delete(TUNNEL_SERVER_AUTH_ID_TYPE); } +/// Add `tunnel_server_auth_id` tagged string value to a packet. pub fn add_tunnel_server_auth_id(packet: &mut Packet, tag: Option<&Tag>, value: &str) { packet.add(AVP::from_tagged_string( TUNNEL_SERVER_AUTH_ID_TYPE, @@ -258,6 +377,9 @@ pub fn add_tunnel_server_auth_id(packet: &mut Packet, tag: Option<&Tag>, value: value, )); } +/// Lookup a `tunnel_server_auth_id` tagged string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `tunnel_server_auth_id`, it returns `None`. pub fn lookup_tunnel_server_auth_id( packet: &Packet, ) -> Option), AVPError>> { @@ -265,6 +387,7 @@ pub fn lookup_tunnel_server_auth_id( .lookup(TUNNEL_SERVER_AUTH_ID_TYPE) .map(|v| v.encode_tagged_string()) } +/// Lookup all of the `tunnel_server_auth_id` tagged string value from a packet. pub fn lookup_all_tunnel_server_auth_id( packet: &Packet, ) -> Result)>, AVPError> { diff --git a/radius/src/core/rfc2869.rs b/radius/src/core/rfc2869.rs index e97400f..5b6e2b4 100644 --- a/radius/src/core/rfc2869.rs +++ b/radius/src/core/rfc2869.rs @@ -1,22 +1,76 @@ // Code generated by machine generator; DO NOT EDIT. +//! Utility for rfc2869 packet. +//! +//! This module handles the packet according to the following definition: +//! ```text +//! //! # -*- text -*- +//! # Copyright (C) 2020 The FreeRADIUS Server project and contributors +//! # This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0 +//! # Version $Id$ +//! # +//! # Attributes and values defined in RFC 2869. +//! # http://www.ietf.org/rfc/rfc2869.txt +//! # +//! # $Id$ +//! # +//! ATTRIBUTE Acct-Input-Gigawords 52 integer +//! ATTRIBUTE Acct-Output-Gigawords 53 integer +//! +//! ATTRIBUTE Event-Timestamp 55 date +//! +//! ATTRIBUTE ARAP-Password 70 octets[16] +//! ATTRIBUTE ARAP-Features 71 octets[14] +//! ATTRIBUTE ARAP-Zone-Access 72 integer +//! ATTRIBUTE ARAP-Security 73 integer +//! ATTRIBUTE ARAP-Security-Data 74 string +//! ATTRIBUTE Password-Retry 75 integer +//! ATTRIBUTE Prompt 76 integer +//! ATTRIBUTE Connect-Info 77 string +//! ATTRIBUTE Configuration-Token 78 string +//! ATTRIBUTE EAP-Message 79 octets concat +//! ATTRIBUTE Message-Authenticator 80 octets +//! +//! ATTRIBUTE ARAP-Challenge-Response 84 octets[8] +//! ATTRIBUTE Acct-Interim-Interval 85 integer +//! # 86: RFC 2867 +//! ATTRIBUTE NAS-Port-Id 87 string +//! ATTRIBUTE Framed-Pool 88 string +//! +//! # ARAP Zone Access +//! +//! VALUE ARAP-Zone-Access Default-Zone 1 +//! VALUE ARAP-Zone-Access Zone-Filter-Inclusive 2 +//! VALUE ARAP-Zone-Access Zone-Filter-Exclusive 4 +//! +//! # Prompt +//! VALUE Prompt No-Echo 0 +//! VALUE Prompt Echo 1 +//! ``` + use chrono::{DateTime, Utc}; use crate::core::avp::{AVPError, AVPType, AVP}; use crate::core::packet::Packet; pub const ACCT_INPUT_GIGAWORDS_TYPE: AVPType = 52; +/// Delete all of `acct_input_gigawords` values from a packet. pub fn delete_acct_input_gigawords(packet: &mut Packet) { packet.delete(ACCT_INPUT_GIGAWORDS_TYPE); } +/// Add `acct_input_gigawords` integer value to a packet. pub fn add_acct_input_gigawords(packet: &mut Packet, value: u32) { packet.add(AVP::from_u32(ACCT_INPUT_GIGAWORDS_TYPE, value)); } +/// Lookup a `acct_input_gigawords` integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `acct_input_gigawords`, it returns `None`. pub fn lookup_acct_input_gigawords(packet: &Packet) -> Option> { packet .lookup(ACCT_INPUT_GIGAWORDS_TYPE) .map(|v| v.encode_u32()) } +/// Lookup all of the `acct_input_gigawords` integer value from a packet. pub fn lookup_all_acct_input_gigawords(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(ACCT_INPUT_GIGAWORDS_TYPE) { @@ -26,17 +80,23 @@ pub fn lookup_all_acct_input_gigawords(packet: &Packet) -> Result, AVPE } pub const ACCT_OUTPUT_GIGAWORDS_TYPE: AVPType = 53; +/// Delete all of `acct_output_gigawords` values from a packet. pub fn delete_acct_output_gigawords(packet: &mut Packet) { packet.delete(ACCT_OUTPUT_GIGAWORDS_TYPE); } +/// Add `acct_output_gigawords` integer value to a packet. pub fn add_acct_output_gigawords(packet: &mut Packet, value: u32) { packet.add(AVP::from_u32(ACCT_OUTPUT_GIGAWORDS_TYPE, value)); } +/// Lookup a `acct_output_gigawords` integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `acct_output_gigawords`, it returns `None`. pub fn lookup_acct_output_gigawords(packet: &Packet) -> Option> { packet .lookup(ACCT_OUTPUT_GIGAWORDS_TYPE) .map(|v| v.encode_u32()) } +/// Lookup all of the `acct_output_gigawords` integer value from a packet. pub fn lookup_all_acct_output_gigawords(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(ACCT_OUTPUT_GIGAWORDS_TYPE) { @@ -46,15 +106,21 @@ pub fn lookup_all_acct_output_gigawords(packet: &Packet) -> Result, AVP } pub const EVENT_TIMESTAMP_TYPE: AVPType = 55; +/// Delete all of `event_timestamp` values from a packet. pub fn delete_event_timestamp(packet: &mut Packet) { packet.delete(EVENT_TIMESTAMP_TYPE); } +/// Add `event_timestamp` date value to a packet. pub fn add_event_timestamp(packet: &mut Packet, value: &DateTime) { packet.add(AVP::from_date(EVENT_TIMESTAMP_TYPE, value)); } +/// Lookup a `event_timestamp` date value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `event_timestamp`, it returns `None`. pub fn lookup_event_timestamp(packet: &Packet) -> Option, AVPError>> { packet.lookup(EVENT_TIMESTAMP_TYPE).map(|v| v.encode_date()) } +/// Lookup all of the `event_timestamp` date value from a packet. pub fn lookup_all_event_timestamp(packet: &Packet) -> Result>, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(EVENT_TIMESTAMP_TYPE) { @@ -64,9 +130,11 @@ pub fn lookup_all_event_timestamp(packet: &Packet) -> Result>, } pub const ARAP_PASSWORD_TYPE: AVPType = 70; +/// Delete all of `arap_password` values from a packet. pub fn delete_arap_password(packet: &mut Packet) { packet.delete(ARAP_PASSWORD_TYPE); } +/// Add `arap_password` fixed-length octets value to a packet. pub fn add_arap_password(packet: &mut Packet, value: &[u8]) -> Result<(), AVPError> { if value.len() != 16 { return Err(AVPError::InvalidAttributeLengthError( @@ -77,9 +145,13 @@ pub fn add_arap_password(packet: &mut Packet, value: &[u8]) -> Result<(), AVPErr packet.add(AVP::from_bytes(ARAP_PASSWORD_TYPE, value)); Ok(()) } +/// Lookup a `arap_password` fixed-length octets value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `arap_password`, it returns `None`. pub fn lookup_arap_password(packet: &Packet) -> Option> { packet.lookup(ARAP_PASSWORD_TYPE).map(|v| v.encode_bytes()) } +/// Lookup all of the `arap_password` fixed-length octets value from a packet. pub fn lookup_all_arap_password(packet: &Packet) -> Vec> { let mut vec = Vec::new(); for avp in packet.lookup_all(ARAP_PASSWORD_TYPE) { @@ -89,9 +161,11 @@ pub fn lookup_all_arap_password(packet: &Packet) -> Vec> { } pub const ARAP_FEATURES_TYPE: AVPType = 71; +/// Delete all of `arap_features` values from a packet. pub fn delete_arap_features(packet: &mut Packet) { packet.delete(ARAP_FEATURES_TYPE); } +/// Add `arap_features` fixed-length octets value to a packet. pub fn add_arap_features(packet: &mut Packet, value: &[u8]) -> Result<(), AVPError> { if value.len() != 14 { return Err(AVPError::InvalidAttributeLengthError( @@ -102,9 +176,13 @@ pub fn add_arap_features(packet: &mut Packet, value: &[u8]) -> Result<(), AVPErr packet.add(AVP::from_bytes(ARAP_FEATURES_TYPE, value)); Ok(()) } +/// Lookup a `arap_features` fixed-length octets value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `arap_features`, it returns `None`. pub fn lookup_arap_features(packet: &Packet) -> Option> { packet.lookup(ARAP_FEATURES_TYPE).map(|v| v.encode_bytes()) } +/// Lookup all of the `arap_features` fixed-length octets value from a packet. pub fn lookup_all_arap_features(packet: &Packet) -> Vec> { let mut vec = Vec::new(); for avp in packet.lookup_all(ARAP_FEATURES_TYPE) { @@ -114,17 +192,23 @@ pub fn lookup_all_arap_features(packet: &Packet) -> Vec> { } pub const ARAP_ZONE_ACCESS_TYPE: AVPType = 72; +/// Delete all of `arap_zone_access` values from a packet. pub fn delete_arap_zone_access(packet: &mut Packet) { packet.delete(ARAP_ZONE_ACCESS_TYPE); } +/// Add `arap_zone_access` value-defined integer value to a packet. pub fn add_arap_zone_access(packet: &mut Packet, value: ArapZoneAccess) { packet.add(AVP::from_u32(ARAP_ZONE_ACCESS_TYPE, value as u32)); } +/// Lookup a `arap_zone_access` value-defined integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `arap_zone_access`, it returns `None`. pub fn lookup_arap_zone_access(packet: &Packet) -> Option> { packet .lookup(ARAP_ZONE_ACCESS_TYPE) .map(|v| Ok(v.encode_u32()? as ArapZoneAccess)) } +/// Lookup all of the `arap_zone_access` value-defined integer value from a packet. pub fn lookup_all_arap_zone_access(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(ARAP_ZONE_ACCESS_TYPE) { @@ -134,15 +218,21 @@ pub fn lookup_all_arap_zone_access(packet: &Packet) -> Result Option> { packet.lookup(ARAP_SECURITY_TYPE).map(|v| v.encode_u32()) } +/// Lookup all of the `arap_security` integer value from a packet. pub fn lookup_all_arap_security(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(ARAP_SECURITY_TYPE) { @@ -152,17 +242,23 @@ pub fn lookup_all_arap_security(packet: &Packet) -> Result, AVPError> { } pub const ARAP_SECURITY_DATA_TYPE: AVPType = 74; +/// Delete all of `arap_security_data` values from a packet. pub fn delete_arap_security_data(packet: &mut Packet) { packet.delete(ARAP_SECURITY_DATA_TYPE); } +/// Add `arap_security_data` string value to a packet. pub fn add_arap_security_data(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(ARAP_SECURITY_DATA_TYPE, value)); } +/// Lookup a `arap_security_data` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `arap_security_data`, it returns `None`. pub fn lookup_arap_security_data(packet: &Packet) -> Option> { packet .lookup(ARAP_SECURITY_DATA_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `arap_security_data` string value from a packet. pub fn lookup_all_arap_security_data(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(ARAP_SECURITY_DATA_TYPE) { @@ -172,15 +268,21 @@ pub fn lookup_all_arap_security_data(packet: &Packet) -> Result, AVP } pub const PASSWORD_RETRY_TYPE: AVPType = 75; +/// Delete all of `password_retry` values from a packet. pub fn delete_password_retry(packet: &mut Packet) { packet.delete(PASSWORD_RETRY_TYPE); } +/// Add `password_retry` integer value to a packet. pub fn add_password_retry(packet: &mut Packet, value: u32) { packet.add(AVP::from_u32(PASSWORD_RETRY_TYPE, value)); } +/// Lookup a `password_retry` integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `password_retry`, it returns `None`. pub fn lookup_password_retry(packet: &Packet) -> Option> { packet.lookup(PASSWORD_RETRY_TYPE).map(|v| v.encode_u32()) } +/// Lookup all of the `password_retry` integer value from a packet. pub fn lookup_all_password_retry(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(PASSWORD_RETRY_TYPE) { @@ -190,17 +292,23 @@ pub fn lookup_all_password_retry(packet: &Packet) -> Result, AVPError> } pub const PROMPT_TYPE: AVPType = 76; +/// Delete all of `prompt` values from a packet. pub fn delete_prompt(packet: &mut Packet) { packet.delete(PROMPT_TYPE); } +/// Add `prompt` value-defined integer value to a packet. pub fn add_prompt(packet: &mut Packet, value: Prompt) { packet.add(AVP::from_u32(PROMPT_TYPE, value as u32)); } +/// Lookup a `prompt` value-defined integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `prompt`, it returns `None`. pub fn lookup_prompt(packet: &Packet) -> Option> { packet .lookup(PROMPT_TYPE) .map(|v| Ok(v.encode_u32()? as Prompt)) } +/// Lookup all of the `prompt` value-defined integer value from a packet. pub fn lookup_all_prompt(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(PROMPT_TYPE) { @@ -210,15 +318,21 @@ pub fn lookup_all_prompt(packet: &Packet) -> Result, AVPError> { } pub const CONNECT_INFO_TYPE: AVPType = 77; +/// Delete all of `connect_info` values from a packet. pub fn delete_connect_info(packet: &mut Packet) { packet.delete(CONNECT_INFO_TYPE); } +/// Add `connect_info` string value to a packet. pub fn add_connect_info(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(CONNECT_INFO_TYPE, value)); } +/// Lookup a `connect_info` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `connect_info`, it returns `None`. pub fn lookup_connect_info(packet: &Packet) -> Option> { packet.lookup(CONNECT_INFO_TYPE).map(|v| v.encode_string()) } +/// Lookup all of the `connect_info` string value from a packet. pub fn lookup_all_connect_info(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(CONNECT_INFO_TYPE) { @@ -228,17 +342,23 @@ pub fn lookup_all_connect_info(packet: &Packet) -> Result, AVPError> } pub const CONFIGURATION_TOKEN_TYPE: AVPType = 78; +/// Delete all of `configuration_token` values from a packet. pub fn delete_configuration_token(packet: &mut Packet) { packet.delete(CONFIGURATION_TOKEN_TYPE); } +/// Add `configuration_token` string value to a packet. pub fn add_configuration_token(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(CONFIGURATION_TOKEN_TYPE, value)); } +/// Lookup a `configuration_token` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `configuration_token`, it returns `None`. pub fn lookup_configuration_token(packet: &Packet) -> Option> { packet .lookup(CONFIGURATION_TOKEN_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `configuration_token` string value from a packet. pub fn lookup_all_configuration_token(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(CONFIGURATION_TOKEN_TYPE) { @@ -248,6 +368,7 @@ pub fn lookup_all_configuration_token(packet: &Packet) -> Result, AV } pub const EAP_MESSAGE_TYPE: AVPType = 79; +/// Delete all of `eap_message` values from a packet. pub fn delete_eap_message(packet: &mut Packet) { packet.delete(EAP_MESSAGE_TYPE); } @@ -271,17 +392,23 @@ pub fn lookup_eap_message(packet: &Packet) -> Option> { } pub const MESSAGE_AUTHENTICATOR_TYPE: AVPType = 80; +/// Delete all of `message_authenticator` values from a packet. pub fn delete_message_authenticator(packet: &mut Packet) { packet.delete(MESSAGE_AUTHENTICATOR_TYPE); } +/// Add `message_authenticator` octets value to a packet. pub fn add_message_authenticator(packet: &mut Packet, value: &[u8]) { packet.add(AVP::from_bytes(MESSAGE_AUTHENTICATOR_TYPE, value)); } +/// Lookup a `message_authenticator` octets value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `message_authenticator`, it returns `None`. pub fn lookup_message_authenticator(packet: &Packet) -> Option> { packet .lookup(MESSAGE_AUTHENTICATOR_TYPE) .map(|v| v.encode_bytes()) } +/// Lookup all of the `message_authenticator` octets value from a packet. pub fn lookup_all_message_authenticator(packet: &Packet) -> Vec> { let mut vec = Vec::new(); for avp in packet.lookup_all(MESSAGE_AUTHENTICATOR_TYPE) { @@ -291,9 +418,11 @@ pub fn lookup_all_message_authenticator(packet: &Packet) -> Vec> { } pub const ARAP_CHALLENGE_RESPONSE_TYPE: AVPType = 84; +/// Delete all of `arap_challenge_response` values from a packet. pub fn delete_arap_challenge_response(packet: &mut Packet) { packet.delete(ARAP_CHALLENGE_RESPONSE_TYPE); } +/// Add `arap_challenge_response` fixed-length octets value to a packet. pub fn add_arap_challenge_response(packet: &mut Packet, value: &[u8]) -> Result<(), AVPError> { if value.len() != 8 { return Err(AVPError::InvalidAttributeLengthError( @@ -304,11 +433,15 @@ pub fn add_arap_challenge_response(packet: &mut Packet, value: &[u8]) -> Result< packet.add(AVP::from_bytes(ARAP_CHALLENGE_RESPONSE_TYPE, value)); Ok(()) } +/// Lookup a `arap_challenge_response` fixed-length octets value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `arap_challenge_response`, it returns `None`. pub fn lookup_arap_challenge_response(packet: &Packet) -> Option> { packet .lookup(ARAP_CHALLENGE_RESPONSE_TYPE) .map(|v| v.encode_bytes()) } +/// Lookup all of the `arap_challenge_response` fixed-length octets value from a packet. pub fn lookup_all_arap_challenge_response(packet: &Packet) -> Vec> { let mut vec = Vec::new(); for avp in packet.lookup_all(ARAP_CHALLENGE_RESPONSE_TYPE) { @@ -318,17 +451,23 @@ pub fn lookup_all_arap_challenge_response(packet: &Packet) -> Vec> { } pub const ACCT_INTERIM_INTERVAL_TYPE: AVPType = 85; +/// Delete all of `acct_interim_interval` values from a packet. pub fn delete_acct_interim_interval(packet: &mut Packet) { packet.delete(ACCT_INTERIM_INTERVAL_TYPE); } +/// Add `acct_interim_interval` integer value to a packet. pub fn add_acct_interim_interval(packet: &mut Packet, value: u32) { packet.add(AVP::from_u32(ACCT_INTERIM_INTERVAL_TYPE, value)); } +/// Lookup a `acct_interim_interval` integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `acct_interim_interval`, it returns `None`. pub fn lookup_acct_interim_interval(packet: &Packet) -> Option> { packet .lookup(ACCT_INTERIM_INTERVAL_TYPE) .map(|v| v.encode_u32()) } +/// Lookup all of the `acct_interim_interval` integer value from a packet. pub fn lookup_all_acct_interim_interval(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(ACCT_INTERIM_INTERVAL_TYPE) { @@ -338,15 +477,21 @@ pub fn lookup_all_acct_interim_interval(packet: &Packet) -> Result, AVP } pub const NAS_PORT_ID_TYPE: AVPType = 87; +/// Delete all of `nas_port_id` values from a packet. pub fn delete_nas_port_id(packet: &mut Packet) { packet.delete(NAS_PORT_ID_TYPE); } +/// Add `nas_port_id` string value to a packet. pub fn add_nas_port_id(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(NAS_PORT_ID_TYPE, value)); } +/// Lookup a `nas_port_id` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `nas_port_id`, it returns `None`. pub fn lookup_nas_port_id(packet: &Packet) -> Option> { packet.lookup(NAS_PORT_ID_TYPE).map(|v| v.encode_string()) } +/// Lookup all of the `nas_port_id` string value from a packet. pub fn lookup_all_nas_port_id(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(NAS_PORT_ID_TYPE) { @@ -356,15 +501,21 @@ pub fn lookup_all_nas_port_id(packet: &Packet) -> Result, AVPError> } pub const FRAMED_POOL_TYPE: AVPType = 88; +/// Delete all of `framed_pool` values from a packet. pub fn delete_framed_pool(packet: &mut Packet) { packet.delete(FRAMED_POOL_TYPE); } +/// Add `framed_pool` string value to a packet. pub fn add_framed_pool(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(FRAMED_POOL_TYPE, value)); } +/// Lookup a `framed_pool` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `framed_pool`, it returns `None`. pub fn lookup_framed_pool(packet: &Packet) -> Option> { packet.lookup(FRAMED_POOL_TYPE).map(|v| v.encode_string()) } +/// Lookup all of the `framed_pool` string value from a packet. pub fn lookup_all_framed_pool(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(FRAMED_POOL_TYPE) { diff --git a/radius/src/core/rfc3162.rs b/radius/src/core/rfc3162.rs index 6598e25..f380a45 100644 --- a/radius/src/core/rfc3162.rs +++ b/radius/src/core/rfc3162.rs @@ -1,22 +1,50 @@ // Code generated by machine generator; DO NOT EDIT. +//! Utility for rfc3162 packet. +//! +//! This module handles the packet according to the following definition: +//! ```text +//! //! # -*- text -*- +//! # Copyright (C) 2020 The FreeRADIUS Server project and contributors +//! # This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0 +//! # Version $Id$ +//! # +//! # Attributes and values defined in RFC 3162. +//! # http://www.ietf.org/rfc/rfc3162.txt +//! # +//! # $Id$ +//! # +//! ATTRIBUTE NAS-IPV6-Address 95 ipv6addr +//! ATTRIBUTE Framed-Interface-Id 96 ifid +//! ATTRIBUTE Framed-IPV6-Prefix 97 ipv6prefix +//! ATTRIBUTE Login-IPV6-Host 98 ipv6addr +//! ATTRIBUTE Framed-IPV6-Route 99 string +//! ATTRIBUTE Framed-IPV6-Pool 100 string +//! ``` + use std::net::Ipv6Addr; use crate::core::avp::{AVPError, AVPType, AVP}; use crate::core::packet::Packet; pub const NAS_IPV6_ADDRESS_TYPE: AVPType = 95; +/// Delete all of `nas_ipv6_address` values from a packet. pub fn delete_nas_ipv6_address(packet: &mut Packet) { packet.delete(NAS_IPV6_ADDRESS_TYPE); } +/// Add `nas_ipv6_address` ipv6addr value to a packet. pub fn add_nas_ipv6_address(packet: &mut Packet, value: &Ipv6Addr) { packet.add(AVP::from_ipv6(NAS_IPV6_ADDRESS_TYPE, value)); } +/// Lookup a `nas_ipv6_address` ipv6addr value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `nas_ipv6_address`, it returns `None`. pub fn lookup_nas_ipv6_address(packet: &Packet) -> Option> { packet .lookup(NAS_IPV6_ADDRESS_TYPE) .map(|v| v.encode_ipv6()) } +/// Lookup all of the `nas_ipv6_address` ipv6addr value from a packet. pub fn lookup_all_nas_ipv6_address(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(NAS_IPV6_ADDRESS_TYPE) { @@ -26,9 +54,11 @@ pub fn lookup_all_nas_ipv6_address(packet: &Packet) -> Result, AVP } pub const FRAMED_INTERFACE_ID_TYPE: AVPType = 96; +/// Delete all of `framed_interface_id` values from a packet. pub fn delete_framed_interface_id(packet: &mut Packet) { packet.delete(FRAMED_INTERFACE_ID_TYPE); } +/// Add `framed_interface_id` fixed-length octets value to a packet. pub fn add_framed_interface_id(packet: &mut Packet, value: &[u8]) -> Result<(), AVPError> { if value.len() != 8 { return Err(AVPError::InvalidAttributeLengthError( @@ -39,11 +69,15 @@ pub fn add_framed_interface_id(packet: &mut Packet, value: &[u8]) -> Result<(), packet.add(AVP::from_bytes(FRAMED_INTERFACE_ID_TYPE, value)); Ok(()) } +/// Lookup a `framed_interface_id` fixed-length octets value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `framed_interface_id`, it returns `None`. pub fn lookup_framed_interface_id(packet: &Packet) -> Option> { packet .lookup(FRAMED_INTERFACE_ID_TYPE) .map(|v| v.encode_bytes()) } +/// Lookup all of the `framed_interface_id` fixed-length octets value from a packet. pub fn lookup_all_framed_interface_id(packet: &Packet) -> Vec> { let mut vec = Vec::new(); for avp in packet.lookup_all(FRAMED_INTERFACE_ID_TYPE) { @@ -53,18 +87,24 @@ pub fn lookup_all_framed_interface_id(packet: &Packet) -> Vec> { } pub const FRAMED_IPV6_PREFIX_TYPE: AVPType = 97; +/// Delete all of `framed_ipv6_prefix` values from a packet. pub fn delete_framed_ipv6_prefix(packet: &mut Packet) { packet.delete(FRAMED_IPV6_PREFIX_TYPE); } +/// Add `framed_ipv6_prefix` ipv6 prefix value to a packet. pub fn add_framed_ipv6_prefix(packet: &mut Packet, value: &[u8]) -> Result<(), AVPError> { packet.add(AVP::from_ipv6_prefix(FRAMED_IPV6_PREFIX_TYPE, value)?); Ok(()) } +/// Lookup a `framed_ipv6_prefix` ipv6 prefix value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `framed_ipv6_prefix`, it returns `None`. pub fn lookup_framed_ipv6_prefix(packet: &Packet) -> Option, AVPError>> { packet .lookup(FRAMED_IPV6_PREFIX_TYPE) .map(|v| v.encode_ipv6_prefix()) } +/// Lookup all of the `framed_ipv6_prefix` ipv6 prefix value from a packet. pub fn lookup_all_framed_ipv6_prefix(packet: &Packet) -> Result>, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(FRAMED_IPV6_PREFIX_TYPE) { @@ -74,15 +114,21 @@ pub fn lookup_all_framed_ipv6_prefix(packet: &Packet) -> Result>, AV } pub const LOGIN_IPV6_HOST_TYPE: AVPType = 98; +/// Delete all of `login_ipv6_host` values from a packet. pub fn delete_login_ipv6_host(packet: &mut Packet) { packet.delete(LOGIN_IPV6_HOST_TYPE); } +/// Add `login_ipv6_host` ipv6addr value to a packet. pub fn add_login_ipv6_host(packet: &mut Packet, value: &Ipv6Addr) { packet.add(AVP::from_ipv6(LOGIN_IPV6_HOST_TYPE, value)); } +/// Lookup a `login_ipv6_host` ipv6addr value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `login_ipv6_host`, it returns `None`. pub fn lookup_login_ipv6_host(packet: &Packet) -> Option> { packet.lookup(LOGIN_IPV6_HOST_TYPE).map(|v| v.encode_ipv6()) } +/// Lookup all of the `login_ipv6_host` ipv6addr value from a packet. pub fn lookup_all_login_ipv6_host(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(LOGIN_IPV6_HOST_TYPE) { @@ -92,17 +138,23 @@ pub fn lookup_all_login_ipv6_host(packet: &Packet) -> Result, AVPE } pub const FRAMED_IPV6_ROUTE_TYPE: AVPType = 99; +/// Delete all of `framed_ipv6_route` values from a packet. pub fn delete_framed_ipv6_route(packet: &mut Packet) { packet.delete(FRAMED_IPV6_ROUTE_TYPE); } +/// Add `framed_ipv6_route` string value to a packet. pub fn add_framed_ipv6_route(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(FRAMED_IPV6_ROUTE_TYPE, value)); } +/// Lookup a `framed_ipv6_route` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `framed_ipv6_route`, it returns `None`. pub fn lookup_framed_ipv6_route(packet: &Packet) -> Option> { packet .lookup(FRAMED_IPV6_ROUTE_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `framed_ipv6_route` string value from a packet. pub fn lookup_all_framed_ipv6_route(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(FRAMED_IPV6_ROUTE_TYPE) { @@ -112,17 +164,23 @@ pub fn lookup_all_framed_ipv6_route(packet: &Packet) -> Result, AVPE } pub const FRAMED_IPV6_POOL_TYPE: AVPType = 100; +/// Delete all of `framed_ipv6_pool` values from a packet. pub fn delete_framed_ipv6_pool(packet: &mut Packet) { packet.delete(FRAMED_IPV6_POOL_TYPE); } +/// Add `framed_ipv6_pool` string value to a packet. pub fn add_framed_ipv6_pool(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(FRAMED_IPV6_POOL_TYPE, value)); } +/// Lookup a `framed_ipv6_pool` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `framed_ipv6_pool`, it returns `None`. pub fn lookup_framed_ipv6_pool(packet: &Packet) -> Option> { packet .lookup(FRAMED_IPV6_POOL_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `framed_ipv6_pool` string value from a packet. pub fn lookup_all_framed_ipv6_pool(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(FRAMED_IPV6_POOL_TYPE) { diff --git a/radius/src/core/rfc3576.rs b/radius/src/core/rfc3576.rs index 7a47e8d..8d9510f 100644 --- a/radius/src/core/rfc3576.rs +++ b/radius/src/core/rfc3576.rs @@ -1,22 +1,67 @@ // Code generated by machine generator; DO NOT EDIT. +//! Utility for rfc3576 packet. +//! +//! This module handles the packet according to the following definition: +//! ```text +//! //! # -*- text -*- +//! # Copyright (C) 2020 The FreeRADIUS Server project and contributors +//! # This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0 +//! # Version $Id$ +//! # +//! # Attributes and values defined in RFC 3576. +//! # http://www.ietf.org/rfc/rfc3576.txt +//! # +//! # $Id$ +//! # +//! ATTRIBUTE Error-Cause 101 integer +//! +//! # Service Types +//! +//! VALUE Service-Type Authorize-Only 17 +//! +//! # Error causes +//! +//! VALUE Error-Cause Residual-Context-Removed 201 +//! VALUE Error-Cause Invalid-EAP-Packet 202 +//! VALUE Error-Cause Unsupported-Attribute 401 +//! VALUE Error-Cause Missing-Attribute 402 +//! VALUE Error-Cause NAS-Identification-Mismatch 403 +//! VALUE Error-Cause Invalid-Request 404 +//! VALUE Error-Cause Unsupported-Service 405 +//! VALUE Error-Cause Unsupported-Extension 406 +//! VALUE Error-Cause Administratively-Prohibited 501 +//! VALUE Error-Cause Proxy-Request-Not-Routable 502 +//! VALUE Error-Cause Session-Context-Not-Found 503 +//! VALUE Error-Cause Session-Context-Not-Removable 504 +//! VALUE Error-Cause Proxy-Processing-Error 505 +//! VALUE Error-Cause Resources-Unavailable 506 +//! VALUE Error-Cause Request-Initiated 507 +//! ``` + use crate::core::avp::{AVPError, AVPType, AVP}; use crate::core::packet::Packet; use crate::core::rfc2865; pub const ERROR_CAUSE_TYPE: AVPType = 101; +/// Delete all of `error_cause` values from a packet. pub fn delete_error_cause(packet: &mut Packet) { packet.delete(ERROR_CAUSE_TYPE); } +/// Add `error_cause` value-defined integer value to a packet. pub fn add_error_cause(packet: &mut Packet, value: ErrorCause) { packet.add(AVP::from_u32(ERROR_CAUSE_TYPE, value as u32)); } +/// Lookup a `error_cause` value-defined integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `error_cause`, it returns `None`. pub fn lookup_error_cause(packet: &Packet) -> Option> { packet .lookup(ERROR_CAUSE_TYPE) .map(|v| Ok(v.encode_u32()? as ErrorCause)) } +/// Lookup all of the `error_cause` value-defined integer value from a packet. pub fn lookup_all_error_cause(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(ERROR_CAUSE_TYPE) { diff --git a/radius/src/core/rfc3580.rs b/radius/src/core/rfc3580.rs index dd268c0..0c25d78 100644 --- a/radius/src/core/rfc3580.rs +++ b/radius/src/core/rfc3580.rs @@ -1,5 +1,30 @@ // Code generated by machine generator; DO NOT EDIT. +//! Utility for rfc3580 packet. +//! +//! This module handles the packet according to the following definition: +//! ```text +//! //! # -*- text -*- +//! # Copyright (C) 2020 The FreeRADIUS Server project and contributors +//! # This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0 +//! # Version $Id$ +//! # +//! # Attributes and values defined in RFC 3580. +//! # http://www.ietf.org/rfc/rfc3580.txt +//! # +//! # $Id$ +//! # +//! VALUE Acct-Terminate-Cause Supplicant-Restart 19 +//! VALUE Acct-Terminate-Cause Reauthentication-Failure 20 +//! VALUE Acct-Terminate-Cause Port-Reinit 21 +//! VALUE Acct-Terminate-Cause Port-Disabled 22 +//! +//! VALUE NAS-Port-Type Token-Ring 20 +//! VALUE NAS-Port-Type FDDI 21 +//! +//! VALUE Tunnel-Type VLAN 13 +//! ``` + use crate::core::rfc2865; use crate::core::rfc2866; diff --git a/radius/src/core/rfc4072.rs b/radius/src/core/rfc4072.rs index 6a9df1e..d9b241c 100644 --- a/radius/src/core/rfc4072.rs +++ b/radius/src/core/rfc4072.rs @@ -1,18 +1,42 @@ // Code generated by machine generator; DO NOT EDIT. +//! Utility for rfc4072 packet. +//! +//! This module handles the packet according to the following definition: +//! ```text +//! //! # -*- text -*- +//! # Copyright (C) 2020 The FreeRADIUS Server project and contributors +//! # This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0 +//! # Version $Id$ +//! # +//! # Attributes and values defined in RFC 4072 +//! # http://www.ietf.org/rfc/rfc4072.txt +//! # +//! # $Id$ +//! # +//! +//! ATTRIBUTE EAP-Key-Name 102 octets +//! ``` + use crate::core::avp::{AVPType, AVP}; use crate::core::packet::Packet; pub const EAP_KEY_NAME_TYPE: AVPType = 102; +/// Delete all of `eap_key_name` values from a packet. pub fn delete_eap_key_name(packet: &mut Packet) { packet.delete(EAP_KEY_NAME_TYPE); } +/// Add `eap_key_name` octets value to a packet. pub fn add_eap_key_name(packet: &mut Packet, value: &[u8]) { packet.add(AVP::from_bytes(EAP_KEY_NAME_TYPE, value)); } +/// Lookup a `eap_key_name` octets value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `eap_key_name`, it returns `None`. pub fn lookup_eap_key_name(packet: &Packet) -> Option> { packet.lookup(EAP_KEY_NAME_TYPE).map(|v| v.encode_bytes()) } +/// Lookup all of the `eap_key_name` octets value from a packet. pub fn lookup_all_eap_key_name(packet: &Packet) -> Vec> { let mut vec = Vec::new(); for avp in packet.lookup_all(EAP_KEY_NAME_TYPE) { diff --git a/radius/src/core/rfc4372.rs b/radius/src/core/rfc4372.rs index 451a0bb..d24657e 100644 --- a/radius/src/core/rfc4372.rs +++ b/radius/src/core/rfc4372.rs @@ -1,20 +1,43 @@ // Code generated by machine generator; DO NOT EDIT. +//! Utility for rfc4372 packet. +//! +//! This module handles the packet according to the following definition: +//! ```text +//! //! # -*- text -*- +//! # Copyright (C) 2020 The FreeRADIUS Server project and contributors +//! # This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0 +//! # Version $Id$ +//! # +//! # Attributes and values defined in RFC 4372. +//! # http://www.ietf.org/rfc/rfc4372.txt +//! # +//! # $Id$ +//! # +//! ATTRIBUTE Chargeable-User-Identity 89 octets +//! ``` + use crate::core::avp::{AVPType, AVP}; use crate::core::packet::Packet; pub const CHARGEABLE_USER_IDENTITY_TYPE: AVPType = 89; +/// Delete all of `chargeable_user_identity` values from a packet. pub fn delete_chargeable_user_identity(packet: &mut Packet) { packet.delete(CHARGEABLE_USER_IDENTITY_TYPE); } +/// Add `chargeable_user_identity` octets value to a packet. pub fn add_chargeable_user_identity(packet: &mut Packet, value: &[u8]) { packet.add(AVP::from_bytes(CHARGEABLE_USER_IDENTITY_TYPE, value)); } +/// Lookup a `chargeable_user_identity` octets value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `chargeable_user_identity`, it returns `None`. pub fn lookup_chargeable_user_identity(packet: &Packet) -> Option> { packet .lookup(CHARGEABLE_USER_IDENTITY_TYPE) .map(|v| v.encode_bytes()) } +/// Lookup all of the `chargeable_user_identity` octets value from a packet. pub fn lookup_all_chargeable_user_identity(packet: &Packet) -> Vec> { let mut vec = Vec::new(); for avp in packet.lookup_all(CHARGEABLE_USER_IDENTITY_TYPE) { diff --git a/radius/src/core/rfc4603.rs b/radius/src/core/rfc4603.rs index f7fdb4c..6d3e80e 100644 --- a/radius/src/core/rfc4603.rs +++ b/radius/src/core/rfc4603.rs @@ -1,5 +1,30 @@ // Code generated by machine generator; DO NOT EDIT. +//! Utility for rfc4603 packet. +//! +//! This module handles the packet according to the following definition: +//! ```text +//! //! # -*- text -*- +//! # Copyright (C) 2020 The FreeRADIUS Server project and contributors +//! # This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0 +//! # Version $Id$ +//! ############################################################################## +//! # +//! # Attributes and values defined in RFC 4603. +//! # http://www.ietf.org/rfc/rfc4603.txt +//! # +//! # $Id$ +//! # +//! ############################################################################## +//! +//! VALUE NAS-Port-Type PPPoA 30 +//! VALUE NAS-Port-Type PPPoEoA 31 +//! VALUE NAS-Port-Type PPPoEoE 32 +//! VALUE NAS-Port-Type PPPoEoVLAN 33 +//! VALUE NAS-Port-Type PPPoEoQinQ 34 +//! +//! ``` + use crate::core::rfc2865; pub const NAS_PORT_TYPE_PP_PO_A: rfc2865::NasPortType = 30; diff --git a/radius/src/core/rfc4675.rs b/radius/src/core/rfc4675.rs index 4173a04..73c1b74 100644 --- a/radius/src/core/rfc4675.rs +++ b/radius/src/core/rfc4675.rs @@ -1,18 +1,61 @@ // Code generated by machine generator; DO NOT EDIT. +//! Utility for rfc4675 packet. +//! +//! This module handles the packet according to the following definition: +//! ```text +//! //! # -*- text -*- +//! # Copyright (C) 2020 The FreeRADIUS Server project and contributors +//! # This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0 +//! # Version $Id$ +//! # +//! # Attributes and values defined in RFC 4675. +//! # http://www.ietf.org/rfc/rfc4675.txt +//! # +//! # $Id$ +//! # +//! +//! # +//! # High byte = '1' (0x31) means the frames are tagged. +//! # High byte = '2' (0x32) means the frames are untagged. +//! # +//! # Next 12 bits MUST be zero. +//! # +//! # Lower 12 bits is the IEEE-802.1Q VLAN VID. +//! # +//! ATTRIBUTE Egress-VLANID 56 integer +//! ATTRIBUTE Ingress-Filters 57 integer +//! +//! # +//! # First byte == '1' (0x31) means that the frames are tagged. +//! # First byte == '2' (0x32) means that the frames are untagged. +//! # +//! ATTRIBUTE Egress-VLAN-Name 58 string +//! ATTRIBUTE User-Priority-Table 59 octets +//! +//! VALUE Ingress-Filters Enabled 1 +//! VALUE Ingress-Filters Disabled 2 +//! ``` + use crate::core::avp::{AVPError, AVPType, AVP}; use crate::core::packet::Packet; pub const EGRESS_VLANID_TYPE: AVPType = 56; +/// Delete all of `egress_vlanid` values from a packet. pub fn delete_egress_vlanid(packet: &mut Packet) { packet.delete(EGRESS_VLANID_TYPE); } +/// Add `egress_vlanid` integer value to a packet. pub fn add_egress_vlanid(packet: &mut Packet, value: u32) { packet.add(AVP::from_u32(EGRESS_VLANID_TYPE, value)); } +/// Lookup a `egress_vlanid` integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `egress_vlanid`, it returns `None`. pub fn lookup_egress_vlanid(packet: &Packet) -> Option> { packet.lookup(EGRESS_VLANID_TYPE).map(|v| v.encode_u32()) } +/// Lookup all of the `egress_vlanid` integer value from a packet. pub fn lookup_all_egress_vlanid(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(EGRESS_VLANID_TYPE) { @@ -22,17 +65,23 @@ pub fn lookup_all_egress_vlanid(packet: &Packet) -> Result, AVPError> { } pub const INGRESS_FILTERS_TYPE: AVPType = 57; +/// Delete all of `ingress_filters` values from a packet. pub fn delete_ingress_filters(packet: &mut Packet) { packet.delete(INGRESS_FILTERS_TYPE); } +/// Add `ingress_filters` value-defined integer value to a packet. pub fn add_ingress_filters(packet: &mut Packet, value: IngressFilters) { packet.add(AVP::from_u32(INGRESS_FILTERS_TYPE, value as u32)); } +/// Lookup a `ingress_filters` value-defined integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `ingress_filters`, it returns `None`. pub fn lookup_ingress_filters(packet: &Packet) -> Option> { packet .lookup(INGRESS_FILTERS_TYPE) .map(|v| Ok(v.encode_u32()? as IngressFilters)) } +/// Lookup all of the `ingress_filters` value-defined integer value from a packet. pub fn lookup_all_ingress_filters(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(INGRESS_FILTERS_TYPE) { @@ -42,17 +91,23 @@ pub fn lookup_all_ingress_filters(packet: &Packet) -> Result } pub const EGRESS_VLAN_NAME_TYPE: AVPType = 58; +/// Delete all of `egress_vlan_name` values from a packet. pub fn delete_egress_vlan_name(packet: &mut Packet) { packet.delete(EGRESS_VLAN_NAME_TYPE); } +/// Add `egress_vlan_name` string value to a packet. pub fn add_egress_vlan_name(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(EGRESS_VLAN_NAME_TYPE, value)); } +/// Lookup a `egress_vlan_name` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `egress_vlan_name`, it returns `None`. pub fn lookup_egress_vlan_name(packet: &Packet) -> Option> { packet .lookup(EGRESS_VLAN_NAME_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `egress_vlan_name` string value from a packet. pub fn lookup_all_egress_vlan_name(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(EGRESS_VLAN_NAME_TYPE) { @@ -62,17 +117,23 @@ pub fn lookup_all_egress_vlan_name(packet: &Packet) -> Result, AVPEr } pub const USER_PRIORITY_TABLE_TYPE: AVPType = 59; +/// Delete all of `user_priority_table` values from a packet. pub fn delete_user_priority_table(packet: &mut Packet) { packet.delete(USER_PRIORITY_TABLE_TYPE); } +/// Add `user_priority_table` octets value to a packet. pub fn add_user_priority_table(packet: &mut Packet, value: &[u8]) { packet.add(AVP::from_bytes(USER_PRIORITY_TABLE_TYPE, value)); } +/// Lookup a `user_priority_table` octets value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `user_priority_table`, it returns `None`. pub fn lookup_user_priority_table(packet: &Packet) -> Option> { packet .lookup(USER_PRIORITY_TABLE_TYPE) .map(|v| v.encode_bytes()) } +/// Lookup all of the `user_priority_table` octets value from a packet. pub fn lookup_all_user_priority_table(packet: &Packet) -> Vec> { let mut vec = Vec::new(); for avp in packet.lookup_all(USER_PRIORITY_TABLE_TYPE) { diff --git a/radius/src/core/rfc4818.rs b/radius/src/core/rfc4818.rs index 643ce23..c38fb3d 100644 --- a/radius/src/core/rfc4818.rs +++ b/radius/src/core/rfc4818.rs @@ -1,21 +1,47 @@ // Code generated by machine generator; DO NOT EDIT. +//! Utility for rfc4818 packet. +//! +//! This module handles the packet according to the following definition: +//! ```text +//! //! # -*- text -*- +//! # Copyright (C) 2020 The FreeRADIUS Server project and contributors +//! # This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0 +//! # Version $Id$ +//! ############################################################################## +//! # +//! # Attributes and values defined in RFC 4818. +//! # http://www.ietf.org/rfc/rfc4818.txt +//! # +//! # $Id$ +//! # +//! ############################################################################## +//! +//! ATTRIBUTE Delegated-IPV6-Prefix 123 ipv6prefix +//! ``` + use crate::core::avp::{AVPError, AVPType, AVP}; use crate::core::packet::Packet; pub const DELEGATED_IPV6_PREFIX_TYPE: AVPType = 123; +/// Delete all of `delegated_ipv6_prefix` values from a packet. pub fn delete_delegated_ipv6_prefix(packet: &mut Packet) { packet.delete(DELEGATED_IPV6_PREFIX_TYPE); } +/// Add `delegated_ipv6_prefix` ipv6 prefix value to a packet. pub fn add_delegated_ipv6_prefix(packet: &mut Packet, value: &[u8]) -> Result<(), AVPError> { packet.add(AVP::from_ipv6_prefix(DELEGATED_IPV6_PREFIX_TYPE, value)?); Ok(()) } +/// Lookup a `delegated_ipv6_prefix` ipv6 prefix value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `delegated_ipv6_prefix`, it returns `None`. pub fn lookup_delegated_ipv6_prefix(packet: &Packet) -> Option, AVPError>> { packet .lookup(DELEGATED_IPV6_PREFIX_TYPE) .map(|v| v.encode_ipv6_prefix()) } +/// Lookup all of the `delegated_ipv6_prefix` ipv6 prefix value from a packet. pub fn lookup_all_delegated_ipv6_prefix(packet: &Packet) -> Result>, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(DELEGATED_IPV6_PREFIX_TYPE) { diff --git a/radius/src/core/rfc4849.rs b/radius/src/core/rfc4849.rs index 2973a1b..464b937 100644 --- a/radius/src/core/rfc4849.rs +++ b/radius/src/core/rfc4849.rs @@ -1,20 +1,43 @@ // Code generated by machine generator; DO NOT EDIT. +//! Utility for rfc4849 packet. +//! +//! This module handles the packet according to the following definition: +//! ```text +//! //! # -*- text -*- +//! # Copyright (C) 2020 The FreeRADIUS Server project and contributors +//! # This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0 +//! # Version $Id$ +//! # +//! # Attributes and values defined in RFC 4849. +//! # http://www.ietf.org/rfc/rfc4849.txt +//! # +//! # $Id$ +//! # +//! ATTRIBUTE NAS-Filter-Rule 92 string +//! ``` + use crate::core::avp::{AVPError, AVPType, AVP}; use crate::core::packet::Packet; pub const NAS_FILTER_RULE_TYPE: AVPType = 92; +/// Delete all of `nas_filter_rule` values from a packet. pub fn delete_nas_filter_rule(packet: &mut Packet) { packet.delete(NAS_FILTER_RULE_TYPE); } +/// Add `nas_filter_rule` string value to a packet. pub fn add_nas_filter_rule(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(NAS_FILTER_RULE_TYPE, value)); } +/// Lookup a `nas_filter_rule` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `nas_filter_rule`, it returns `None`. pub fn lookup_nas_filter_rule(packet: &Packet) -> Option> { packet .lookup(NAS_FILTER_RULE_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `nas_filter_rule` string value from a packet. pub fn lookup_all_nas_filter_rule(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(NAS_FILTER_RULE_TYPE) { diff --git a/radius/src/core/rfc5090.rs b/radius/src/core/rfc5090.rs index 5685176..4792b01 100644 --- a/radius/src/core/rfc5090.rs +++ b/radius/src/core/rfc5090.rs @@ -1,20 +1,62 @@ // Code generated by machine generator; DO NOT EDIT. +//! Utility for rfc5090 packet. +//! +//! This module handles the packet according to the following definition: +//! ```text +//! //! # -*- text -*- +//! # Copyright (C) 2020 The FreeRADIUS Server project and contributors +//! # This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0 +//! # Version $Id$ +//! # +//! # Attributes and values defined in RFC 5090. +//! # http://www.ietf.org/rfc/rfc5090.txt +//! # +//! # $Id$ +//! # +//! ATTRIBUTE Digest-Response 103 string +//! ATTRIBUTE Digest-Realm 104 string +//! ATTRIBUTE Digest-Nonce 105 string +//! ATTRIBUTE Digest-Response-Auth 106 string +//! ATTRIBUTE Digest-Nextnonce 107 string +//! ATTRIBUTE Digest-Method 108 string +//! ATTRIBUTE Digest-URI 109 string +//! ATTRIBUTE Digest-Qop 110 string +//! ATTRIBUTE Digest-Algorithm 111 string +//! ATTRIBUTE Digest-Entity-Body-Hash 112 string +//! ATTRIBUTE Digest-CNonce 113 string +//! ATTRIBUTE Digest-Nonce-Count 114 string +//! ATTRIBUTE Digest-Username 115 string +//! ATTRIBUTE Digest-Opaque 116 string +//! ATTRIBUTE Digest-Auth-Param 117 string +//! ATTRIBUTE Digest-AKA-Auts 118 string +//! ATTRIBUTE Digest-Domain 119 string +//! ATTRIBUTE Digest-Stale 120 string +//! ATTRIBUTE Digest-HA1 121 string +//! ATTRIBUTE SIP-AOR 122 string +//! ``` + use crate::core::avp::{AVPError, AVPType, AVP}; use crate::core::packet::Packet; pub const DIGEST_RESPONSE_TYPE: AVPType = 103; +/// Delete all of `digest_response` values from a packet. pub fn delete_digest_response(packet: &mut Packet) { packet.delete(DIGEST_RESPONSE_TYPE); } +/// Add `digest_response` string value to a packet. pub fn add_digest_response(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(DIGEST_RESPONSE_TYPE, value)); } +/// Lookup a `digest_response` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `digest_response`, it returns `None`. pub fn lookup_digest_response(packet: &Packet) -> Option> { packet .lookup(DIGEST_RESPONSE_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `digest_response` string value from a packet. pub fn lookup_all_digest_response(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(DIGEST_RESPONSE_TYPE) { @@ -24,15 +66,21 @@ pub fn lookup_all_digest_response(packet: &Packet) -> Result, AVPErr } pub const DIGEST_REALM_TYPE: AVPType = 104; +/// Delete all of `digest_realm` values from a packet. pub fn delete_digest_realm(packet: &mut Packet) { packet.delete(DIGEST_REALM_TYPE); } +/// Add `digest_realm` string value to a packet. pub fn add_digest_realm(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(DIGEST_REALM_TYPE, value)); } +/// Lookup a `digest_realm` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `digest_realm`, it returns `None`. pub fn lookup_digest_realm(packet: &Packet) -> Option> { packet.lookup(DIGEST_REALM_TYPE).map(|v| v.encode_string()) } +/// Lookup all of the `digest_realm` string value from a packet. pub fn lookup_all_digest_realm(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(DIGEST_REALM_TYPE) { @@ -42,15 +90,21 @@ pub fn lookup_all_digest_realm(packet: &Packet) -> Result, AVPError> } pub const DIGEST_NONCE_TYPE: AVPType = 105; +/// Delete all of `digest_nonce` values from a packet. pub fn delete_digest_nonce(packet: &mut Packet) { packet.delete(DIGEST_NONCE_TYPE); } +/// Add `digest_nonce` string value to a packet. pub fn add_digest_nonce(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(DIGEST_NONCE_TYPE, value)); } +/// Lookup a `digest_nonce` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `digest_nonce`, it returns `None`. pub fn lookup_digest_nonce(packet: &Packet) -> Option> { packet.lookup(DIGEST_NONCE_TYPE).map(|v| v.encode_string()) } +/// Lookup all of the `digest_nonce` string value from a packet. pub fn lookup_all_digest_nonce(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(DIGEST_NONCE_TYPE) { @@ -60,17 +114,23 @@ pub fn lookup_all_digest_nonce(packet: &Packet) -> Result, AVPError> } pub const DIGEST_RESPONSE_AUTH_TYPE: AVPType = 106; +/// Delete all of `digest_response_auth` values from a packet. pub fn delete_digest_response_auth(packet: &mut Packet) { packet.delete(DIGEST_RESPONSE_AUTH_TYPE); } +/// Add `digest_response_auth` string value to a packet. pub fn add_digest_response_auth(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(DIGEST_RESPONSE_AUTH_TYPE, value)); } +/// Lookup a `digest_response_auth` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `digest_response_auth`, it returns `None`. pub fn lookup_digest_response_auth(packet: &Packet) -> Option> { packet .lookup(DIGEST_RESPONSE_AUTH_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `digest_response_auth` string value from a packet. pub fn lookup_all_digest_response_auth(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(DIGEST_RESPONSE_AUTH_TYPE) { @@ -80,17 +140,23 @@ pub fn lookup_all_digest_response_auth(packet: &Packet) -> Result, A } pub const DIGEST_NEXTNONCE_TYPE: AVPType = 107; +/// Delete all of `digest_nextnonce` values from a packet. pub fn delete_digest_nextnonce(packet: &mut Packet) { packet.delete(DIGEST_NEXTNONCE_TYPE); } +/// Add `digest_nextnonce` string value to a packet. pub fn add_digest_nextnonce(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(DIGEST_NEXTNONCE_TYPE, value)); } +/// Lookup a `digest_nextnonce` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `digest_nextnonce`, it returns `None`. pub fn lookup_digest_nextnonce(packet: &Packet) -> Option> { packet .lookup(DIGEST_NEXTNONCE_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `digest_nextnonce` string value from a packet. pub fn lookup_all_digest_nextnonce(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(DIGEST_NEXTNONCE_TYPE) { @@ -100,15 +166,21 @@ pub fn lookup_all_digest_nextnonce(packet: &Packet) -> Result, AVPEr } pub const DIGEST_METHOD_TYPE: AVPType = 108; +/// Delete all of `digest_method` values from a packet. pub fn delete_digest_method(packet: &mut Packet) { packet.delete(DIGEST_METHOD_TYPE); } +/// Add `digest_method` string value to a packet. pub fn add_digest_method(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(DIGEST_METHOD_TYPE, value)); } +/// Lookup a `digest_method` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `digest_method`, it returns `None`. pub fn lookup_digest_method(packet: &Packet) -> Option> { packet.lookup(DIGEST_METHOD_TYPE).map(|v| v.encode_string()) } +/// Lookup all of the `digest_method` string value from a packet. pub fn lookup_all_digest_method(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(DIGEST_METHOD_TYPE) { @@ -118,15 +190,21 @@ pub fn lookup_all_digest_method(packet: &Packet) -> Result, AVPError } pub const DIGEST_URI_TYPE: AVPType = 109; +/// Delete all of `digest_uri` values from a packet. pub fn delete_digest_uri(packet: &mut Packet) { packet.delete(DIGEST_URI_TYPE); } +/// Add `digest_uri` string value to a packet. pub fn add_digest_uri(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(DIGEST_URI_TYPE, value)); } +/// Lookup a `digest_uri` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `digest_uri`, it returns `None`. pub fn lookup_digest_uri(packet: &Packet) -> Option> { packet.lookup(DIGEST_URI_TYPE).map(|v| v.encode_string()) } +/// Lookup all of the `digest_uri` string value from a packet. pub fn lookup_all_digest_uri(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(DIGEST_URI_TYPE) { @@ -136,15 +214,21 @@ pub fn lookup_all_digest_uri(packet: &Packet) -> Result, AVPError> { } pub const DIGEST_QOP_TYPE: AVPType = 110; +/// Delete all of `digest_qop` values from a packet. pub fn delete_digest_qop(packet: &mut Packet) { packet.delete(DIGEST_QOP_TYPE); } +/// Add `digest_qop` string value to a packet. pub fn add_digest_qop(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(DIGEST_QOP_TYPE, value)); } +/// Lookup a `digest_qop` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `digest_qop`, it returns `None`. pub fn lookup_digest_qop(packet: &Packet) -> Option> { packet.lookup(DIGEST_QOP_TYPE).map(|v| v.encode_string()) } +/// Lookup all of the `digest_qop` string value from a packet. pub fn lookup_all_digest_qop(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(DIGEST_QOP_TYPE) { @@ -154,17 +238,23 @@ pub fn lookup_all_digest_qop(packet: &Packet) -> Result, AVPError> { } pub const DIGEST_ALGORITHM_TYPE: AVPType = 111; +/// Delete all of `digest_algorithm` values from a packet. pub fn delete_digest_algorithm(packet: &mut Packet) { packet.delete(DIGEST_ALGORITHM_TYPE); } +/// Add `digest_algorithm` string value to a packet. pub fn add_digest_algorithm(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(DIGEST_ALGORITHM_TYPE, value)); } +/// Lookup a `digest_algorithm` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `digest_algorithm`, it returns `None`. pub fn lookup_digest_algorithm(packet: &Packet) -> Option> { packet .lookup(DIGEST_ALGORITHM_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `digest_algorithm` string value from a packet. pub fn lookup_all_digest_algorithm(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(DIGEST_ALGORITHM_TYPE) { @@ -174,17 +264,23 @@ pub fn lookup_all_digest_algorithm(packet: &Packet) -> Result, AVPEr } pub const DIGEST_ENTITY_BODY_HASH_TYPE: AVPType = 112; +/// Delete all of `digest_entity_body_hash` values from a packet. pub fn delete_digest_entity_body_hash(packet: &mut Packet) { packet.delete(DIGEST_ENTITY_BODY_HASH_TYPE); } +/// Add `digest_entity_body_hash` string value to a packet. pub fn add_digest_entity_body_hash(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(DIGEST_ENTITY_BODY_HASH_TYPE, value)); } +/// Lookup a `digest_entity_body_hash` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `digest_entity_body_hash`, it returns `None`. pub fn lookup_digest_entity_body_hash(packet: &Packet) -> Option> { packet .lookup(DIGEST_ENTITY_BODY_HASH_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `digest_entity_body_hash` string value from a packet. pub fn lookup_all_digest_entity_body_hash(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(DIGEST_ENTITY_BODY_HASH_TYPE) { @@ -194,17 +290,23 @@ pub fn lookup_all_digest_entity_body_hash(packet: &Packet) -> Result } pub const DIGEST_C_NONCE_TYPE: AVPType = 113; +/// Delete all of `digest_c_nonce` values from a packet. pub fn delete_digest_c_nonce(packet: &mut Packet) { packet.delete(DIGEST_C_NONCE_TYPE); } +/// Add `digest_c_nonce` string value to a packet. pub fn add_digest_c_nonce(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(DIGEST_C_NONCE_TYPE, value)); } +/// Lookup a `digest_c_nonce` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `digest_c_nonce`, it returns `None`. pub fn lookup_digest_c_nonce(packet: &Packet) -> Option> { packet .lookup(DIGEST_C_NONCE_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `digest_c_nonce` string value from a packet. pub fn lookup_all_digest_c_nonce(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(DIGEST_C_NONCE_TYPE) { @@ -214,17 +316,23 @@ pub fn lookup_all_digest_c_nonce(packet: &Packet) -> Result, AVPErro } pub const DIGEST_NONCE_COUNT_TYPE: AVPType = 114; +/// Delete all of `digest_nonce_count` values from a packet. pub fn delete_digest_nonce_count(packet: &mut Packet) { packet.delete(DIGEST_NONCE_COUNT_TYPE); } +/// Add `digest_nonce_count` string value to a packet. pub fn add_digest_nonce_count(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(DIGEST_NONCE_COUNT_TYPE, value)); } +/// Lookup a `digest_nonce_count` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `digest_nonce_count`, it returns `None`. pub fn lookup_digest_nonce_count(packet: &Packet) -> Option> { packet .lookup(DIGEST_NONCE_COUNT_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `digest_nonce_count` string value from a packet. pub fn lookup_all_digest_nonce_count(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(DIGEST_NONCE_COUNT_TYPE) { @@ -234,17 +342,23 @@ pub fn lookup_all_digest_nonce_count(packet: &Packet) -> Result, AVP } pub const DIGEST_USERNAME_TYPE: AVPType = 115; +/// Delete all of `digest_username` values from a packet. pub fn delete_digest_username(packet: &mut Packet) { packet.delete(DIGEST_USERNAME_TYPE); } +/// Add `digest_username` string value to a packet. pub fn add_digest_username(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(DIGEST_USERNAME_TYPE, value)); } +/// Lookup a `digest_username` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `digest_username`, it returns `None`. pub fn lookup_digest_username(packet: &Packet) -> Option> { packet .lookup(DIGEST_USERNAME_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `digest_username` string value from a packet. pub fn lookup_all_digest_username(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(DIGEST_USERNAME_TYPE) { @@ -254,15 +368,21 @@ pub fn lookup_all_digest_username(packet: &Packet) -> Result, AVPErr } pub const DIGEST_OPAQUE_TYPE: AVPType = 116; +/// Delete all of `digest_opaque` values from a packet. pub fn delete_digest_opaque(packet: &mut Packet) { packet.delete(DIGEST_OPAQUE_TYPE); } +/// Add `digest_opaque` string value to a packet. pub fn add_digest_opaque(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(DIGEST_OPAQUE_TYPE, value)); } +/// Lookup a `digest_opaque` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `digest_opaque`, it returns `None`. pub fn lookup_digest_opaque(packet: &Packet) -> Option> { packet.lookup(DIGEST_OPAQUE_TYPE).map(|v| v.encode_string()) } +/// Lookup all of the `digest_opaque` string value from a packet. pub fn lookup_all_digest_opaque(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(DIGEST_OPAQUE_TYPE) { @@ -272,17 +392,23 @@ pub fn lookup_all_digest_opaque(packet: &Packet) -> Result, AVPError } pub const DIGEST_AUTH_PARAM_TYPE: AVPType = 117; +/// Delete all of `digest_auth_param` values from a packet. pub fn delete_digest_auth_param(packet: &mut Packet) { packet.delete(DIGEST_AUTH_PARAM_TYPE); } +/// Add `digest_auth_param` string value to a packet. pub fn add_digest_auth_param(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(DIGEST_AUTH_PARAM_TYPE, value)); } +/// Lookup a `digest_auth_param` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `digest_auth_param`, it returns `None`. pub fn lookup_digest_auth_param(packet: &Packet) -> Option> { packet .lookup(DIGEST_AUTH_PARAM_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `digest_auth_param` string value from a packet. pub fn lookup_all_digest_auth_param(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(DIGEST_AUTH_PARAM_TYPE) { @@ -292,17 +418,23 @@ pub fn lookup_all_digest_auth_param(packet: &Packet) -> Result, AVPE } pub const DIGEST_AKA_AUTS_TYPE: AVPType = 118; +/// Delete all of `digest_aka_auts` values from a packet. pub fn delete_digest_aka_auts(packet: &mut Packet) { packet.delete(DIGEST_AKA_AUTS_TYPE); } +/// Add `digest_aka_auts` string value to a packet. pub fn add_digest_aka_auts(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(DIGEST_AKA_AUTS_TYPE, value)); } +/// Lookup a `digest_aka_auts` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `digest_aka_auts`, it returns `None`. pub fn lookup_digest_aka_auts(packet: &Packet) -> Option> { packet .lookup(DIGEST_AKA_AUTS_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `digest_aka_auts` string value from a packet. pub fn lookup_all_digest_aka_auts(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(DIGEST_AKA_AUTS_TYPE) { @@ -312,15 +444,21 @@ pub fn lookup_all_digest_aka_auts(packet: &Packet) -> Result, AVPErr } pub const DIGEST_DOMAIN_TYPE: AVPType = 119; +/// Delete all of `digest_domain` values from a packet. pub fn delete_digest_domain(packet: &mut Packet) { packet.delete(DIGEST_DOMAIN_TYPE); } +/// Add `digest_domain` string value to a packet. pub fn add_digest_domain(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(DIGEST_DOMAIN_TYPE, value)); } +/// Lookup a `digest_domain` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `digest_domain`, it returns `None`. pub fn lookup_digest_domain(packet: &Packet) -> Option> { packet.lookup(DIGEST_DOMAIN_TYPE).map(|v| v.encode_string()) } +/// Lookup all of the `digest_domain` string value from a packet. pub fn lookup_all_digest_domain(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(DIGEST_DOMAIN_TYPE) { @@ -330,15 +468,21 @@ pub fn lookup_all_digest_domain(packet: &Packet) -> Result, AVPError } pub const DIGEST_STALE_TYPE: AVPType = 120; +/// Delete all of `digest_stale` values from a packet. pub fn delete_digest_stale(packet: &mut Packet) { packet.delete(DIGEST_STALE_TYPE); } +/// Add `digest_stale` string value to a packet. pub fn add_digest_stale(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(DIGEST_STALE_TYPE, value)); } +/// Lookup a `digest_stale` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `digest_stale`, it returns `None`. pub fn lookup_digest_stale(packet: &Packet) -> Option> { packet.lookup(DIGEST_STALE_TYPE).map(|v| v.encode_string()) } +/// Lookup all of the `digest_stale` string value from a packet. pub fn lookup_all_digest_stale(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(DIGEST_STALE_TYPE) { @@ -348,15 +492,21 @@ pub fn lookup_all_digest_stale(packet: &Packet) -> Result, AVPError> } pub const DIGEST_HA1_TYPE: AVPType = 121; +/// Delete all of `digest_ha1` values from a packet. pub fn delete_digest_ha1(packet: &mut Packet) { packet.delete(DIGEST_HA1_TYPE); } +/// Add `digest_ha1` string value to a packet. pub fn add_digest_ha1(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(DIGEST_HA1_TYPE, value)); } +/// Lookup a `digest_ha1` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `digest_ha1`, it returns `None`. pub fn lookup_digest_ha1(packet: &Packet) -> Option> { packet.lookup(DIGEST_HA1_TYPE).map(|v| v.encode_string()) } +/// Lookup all of the `digest_ha1` string value from a packet. pub fn lookup_all_digest_ha1(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(DIGEST_HA1_TYPE) { @@ -366,15 +516,21 @@ pub fn lookup_all_digest_ha1(packet: &Packet) -> Result, AVPError> { } pub const SIP_AOR_TYPE: AVPType = 122; +/// Delete all of `sip_aor` values from a packet. pub fn delete_sip_aor(packet: &mut Packet) { packet.delete(SIP_AOR_TYPE); } +/// Add `sip_aor` string value to a packet. pub fn add_sip_aor(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(SIP_AOR_TYPE, value)); } +/// Lookup a `sip_aor` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `sip_aor`, it returns `None`. pub fn lookup_sip_aor(packet: &Packet) -> Option> { packet.lookup(SIP_AOR_TYPE).map(|v| v.encode_string()) } +/// Lookup all of the `sip_aor` string value from a packet. pub fn lookup_all_sip_aor(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(SIP_AOR_TYPE) { diff --git a/radius/src/core/rfc5176.rs b/radius/src/core/rfc5176.rs index 2706698..ced0012 100644 --- a/radius/src/core/rfc5176.rs +++ b/radius/src/core/rfc5176.rs @@ -1,5 +1,23 @@ // Code generated by machine generator; DO NOT EDIT. +//! Utility for rfc5176 packet. +//! +//! This module handles the packet according to the following definition: +//! ```text +//! //! # -*- text -*- +//! # Copyright (C) 2020 The FreeRADIUS Server project and contributors +//! # This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0 +//! # Version $Id$ +//! # +//! # Attributes and values defined in RFC 5176. +//! # http://www.ietf.org/rfc/rfc5176.txt +//! # +//! # $Id$ +//! # +//! VALUE Error-Cause Invalid-Attribute-Value 407 +//! VALUE Error-Cause Multiple-Session-Selection-Unsupported 508 +//! ``` + use crate::core::rfc3576; pub const ERROR_CAUSE_INVALID_ATTRIBUTE_VALUE: rfc3576::ErrorCause = 407; diff --git a/radius/src/core/rfc5607.rs b/radius/src/core/rfc5607.rs index 5a102b8..304573c 100644 --- a/radius/src/core/rfc5607.rs +++ b/radius/src/core/rfc5607.rs @@ -1,22 +1,67 @@ // Code generated by machine generator; DO NOT EDIT. +//! Utility for rfc5607 packet. +//! +//! This module handles the packet according to the following definition: +//! ```text +//! //! # -*- text -*- +//! # Copyright (C) 2020 The FreeRADIUS Server project and contributors +//! # This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0 +//! # Version $Id$ +//! # +//! # Attributes and values defined in RFC 5607. +//! # http://www.ietf.org/rfc/rfc5607.txt +//! # +//! # $Id$ +//! # +//! +//! VALUE Service-Type Framed-Management 18 +//! +//! ATTRIBUTE Framed-Management 133 integer +//! +//! VALUE Framed-Management SNMP 1 +//! VALUE Framed-Management Web-Based 2 +//! VALUE Framed-Management Netconf 3 +//! VALUE Framed-Management FTP 4 +//! VALUE Framed-Management TFTP 5 +//! VALUE Framed-Management SFTP 6 +//! VALUE Framed-Management RCP 7 +//! VALUE Framed-Management SCP 8 +//! +//! ATTRIBUTE Management-Transport-Protection 134 integer +//! +//! VALUE Management-Transport-Protection No-Protection 1 +//! VALUE Management-Transport-Protection Integrity-Protection 2 +//! VALUE Management-Transport-Protection Integrity-Confidentiality-Protection 3 +//! +//! ATTRIBUTE Management-Policy-Id 135 string +//! +//! ATTRIBUTE Management-Privilege-Level 136 integer +//! ``` + use crate::core::avp::{AVPError, AVPType, AVP}; use crate::core::packet::Packet; use crate::core::rfc2865; pub const FRAMED_MANAGEMENT_TYPE: AVPType = 133; +/// Delete all of `framed_management` values from a packet. pub fn delete_framed_management(packet: &mut Packet) { packet.delete(FRAMED_MANAGEMENT_TYPE); } +/// Add `framed_management` value-defined integer value to a packet. pub fn add_framed_management(packet: &mut Packet, value: FramedManagement) { packet.add(AVP::from_u32(FRAMED_MANAGEMENT_TYPE, value as u32)); } +/// Lookup a `framed_management` value-defined integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `framed_management`, it returns `None`. pub fn lookup_framed_management(packet: &Packet) -> Option> { packet .lookup(FRAMED_MANAGEMENT_TYPE) .map(|v| Ok(v.encode_u32()? as FramedManagement)) } +/// Lookup all of the `framed_management` value-defined integer value from a packet. pub fn lookup_all_framed_management(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(FRAMED_MANAGEMENT_TYPE) { @@ -26,9 +71,11 @@ pub fn lookup_all_framed_management(packet: &Packet) -> Result Option> { @@ -45,6 +95,7 @@ pub fn lookup_management_transport_protection( .lookup(MANAGEMENT_TRANSPORT_PROTECTION_TYPE) .map(|v| Ok(v.encode_u32()? as ManagementTransportProtection)) } +/// Lookup all of the `management_transport_protection` value-defined integer value from a packet. pub fn lookup_all_management_transport_protection( packet: &Packet, ) -> Result, AVPError> { @@ -56,17 +107,23 @@ pub fn lookup_all_management_transport_protection( } pub const MANAGEMENT_POLICY_ID_TYPE: AVPType = 135; +/// Delete all of `management_policy_id` values from a packet. pub fn delete_management_policy_id(packet: &mut Packet) { packet.delete(MANAGEMENT_POLICY_ID_TYPE); } +/// Add `management_policy_id` string value to a packet. pub fn add_management_policy_id(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(MANAGEMENT_POLICY_ID_TYPE, value)); } +/// Lookup a `management_policy_id` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `management_policy_id`, it returns `None`. pub fn lookup_management_policy_id(packet: &Packet) -> Option> { packet .lookup(MANAGEMENT_POLICY_ID_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `management_policy_id` string value from a packet. pub fn lookup_all_management_policy_id(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(MANAGEMENT_POLICY_ID_TYPE) { @@ -76,17 +133,23 @@ pub fn lookup_all_management_policy_id(packet: &Packet) -> Result, A } pub const MANAGEMENT_PRIVILEGE_LEVEL_TYPE: AVPType = 136; +/// Delete all of `management_privilege_level` values from a packet. pub fn delete_management_privilege_level(packet: &mut Packet) { packet.delete(MANAGEMENT_PRIVILEGE_LEVEL_TYPE); } +/// Add `management_privilege_level` integer value to a packet. pub fn add_management_privilege_level(packet: &mut Packet, value: u32) { packet.add(AVP::from_u32(MANAGEMENT_PRIVILEGE_LEVEL_TYPE, value)); } +/// Lookup a `management_privilege_level` integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `management_privilege_level`, it returns `None`. pub fn lookup_management_privilege_level(packet: &Packet) -> Option> { packet .lookup(MANAGEMENT_PRIVILEGE_LEVEL_TYPE) .map(|v| v.encode_u32()) } +/// Lookup all of the `management_privilege_level` integer value from a packet. pub fn lookup_all_management_privilege_level(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(MANAGEMENT_PRIVILEGE_LEVEL_TYPE) { diff --git a/radius/src/core/rfc5904.rs b/radius/src/core/rfc5904.rs index dba8d8c..026bc7d 100644 --- a/radius/src/core/rfc5904.rs +++ b/radius/src/core/rfc5904.rs @@ -1,9 +1,41 @@ // Code generated by machine generator; DO NOT EDIT. +//! Utility for rfc5904 packet. +//! +//! This module handles the packet according to the following definition: +//! ```text +//! //! # -*- text -*- +//! # Copyright (C) 2020 The FreeRADIUS Server project and contributors +//! # This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0 +//! # Version $Id$ +//! # +//! # Attributes and values defined in RFC 5904. +//! # http://www.ietf.org/rfc/rfc5904.txt +//! # +//! # $Id$ +//! # +//! +//! # The next two attributes are continued, like EAP-Message +//! ATTRIBUTE PKM-SS-Cert 137 octets concat +//! ATTRIBUTE PKM-CA-Cert 138 octets concat +//! +//! # 28 bytes of data, 7 integers +//! ATTRIBUTE PKM-Config-Settings 139 octets +//! ATTRIBUTE PKM-Cryptosuite-List 140 octets +//! ATTRIBUTE PKM-SAID 141 short +//! +//! # 6 bytes of data: SAID, 1 byte of type, 3 of cryptosuite +//! ATTRIBUTE PKM-SA-Descriptor 142 octets +//! +//! # 133 bytes of data: integer lifetime, 1 byte sequence, 128 bytes of key +//! ATTRIBUTE PKM-Auth-Key 143 octets +//! ``` + use crate::core::avp::{AVPError, AVPType, AVP}; use crate::core::packet::Packet; pub const PKM_SS_CERT_TYPE: AVPType = 137; +/// Delete all of `pkm_ss_cert` values from a packet. pub fn delete_pkm_ss_cert(packet: &mut Packet) { packet.delete(PKM_SS_CERT_TYPE); } @@ -27,6 +59,7 @@ pub fn lookup_pkm_ss_cert(packet: &Packet) -> Option> { } pub const PKM_CA_CERT_TYPE: AVPType = 138; +/// Delete all of `pkm_ca_cert` values from a packet. pub fn delete_pkm_ca_cert(packet: &mut Packet) { packet.delete(PKM_CA_CERT_TYPE); } @@ -50,17 +83,23 @@ pub fn lookup_pkm_ca_cert(packet: &Packet) -> Option> { } pub const PKM_CONFIG_SETTINGS_TYPE: AVPType = 139; +/// Delete all of `pkm_config_settings` values from a packet. pub fn delete_pkm_config_settings(packet: &mut Packet) { packet.delete(PKM_CONFIG_SETTINGS_TYPE); } +/// Add `pkm_config_settings` octets value to a packet. pub fn add_pkm_config_settings(packet: &mut Packet, value: &[u8]) { packet.add(AVP::from_bytes(PKM_CONFIG_SETTINGS_TYPE, value)); } +/// Lookup a `pkm_config_settings` octets value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `pkm_config_settings`, it returns `None`. pub fn lookup_pkm_config_settings(packet: &Packet) -> Option> { packet .lookup(PKM_CONFIG_SETTINGS_TYPE) .map(|v| v.encode_bytes()) } +/// Lookup all of the `pkm_config_settings` octets value from a packet. pub fn lookup_all_pkm_config_settings(packet: &Packet) -> Vec> { let mut vec = Vec::new(); for avp in packet.lookup_all(PKM_CONFIG_SETTINGS_TYPE) { @@ -70,17 +109,23 @@ pub fn lookup_all_pkm_config_settings(packet: &Packet) -> Vec> { } pub const PKM_CRYPTOSUITE_LIST_TYPE: AVPType = 140; +/// Delete all of `pkm_cryptosuite_list` values from a packet. pub fn delete_pkm_cryptosuite_list(packet: &mut Packet) { packet.delete(PKM_CRYPTOSUITE_LIST_TYPE); } +/// Add `pkm_cryptosuite_list` octets value to a packet. pub fn add_pkm_cryptosuite_list(packet: &mut Packet, value: &[u8]) { packet.add(AVP::from_bytes(PKM_CRYPTOSUITE_LIST_TYPE, value)); } +/// Lookup a `pkm_cryptosuite_list` octets value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `pkm_cryptosuite_list`, it returns `None`. pub fn lookup_pkm_cryptosuite_list(packet: &Packet) -> Option> { packet .lookup(PKM_CRYPTOSUITE_LIST_TYPE) .map(|v| v.encode_bytes()) } +/// Lookup all of the `pkm_cryptosuite_list` octets value from a packet. pub fn lookup_all_pkm_cryptosuite_list(packet: &Packet) -> Vec> { let mut vec = Vec::new(); for avp in packet.lookup_all(PKM_CRYPTOSUITE_LIST_TYPE) { @@ -90,15 +135,21 @@ pub fn lookup_all_pkm_cryptosuite_list(packet: &Packet) -> Vec> { } pub const PKM_SAID_TYPE: AVPType = 141; +/// Delete all of `pkm_said` values from a packet. pub fn delete_pkm_said(packet: &mut Packet) { packet.delete(PKM_SAID_TYPE); } +/// Add `pkm_said` short integer value to a packet. pub fn add_pkm_said(packet: &mut Packet, value: u16) { packet.add(AVP::from_u16(PKM_SAID_TYPE, value)); } +/// Lookup a `pkm_said` short integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `pkm_said`, it returns `None`. pub fn lookup_pkm_said(packet: &Packet) -> Option> { packet.lookup(PKM_SAID_TYPE).map(|v| v.encode_u16()) } +/// Lookup all of the `pkm_said` short integer value from a packet. pub fn lookup_all_pkm_said(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(PKM_SAID_TYPE) { @@ -108,17 +159,23 @@ pub fn lookup_all_pkm_said(packet: &Packet) -> Result, AVPError> { } pub const PKM_SA_DESCRIPTOR_TYPE: AVPType = 142; +/// Delete all of `pkm_sa_descriptor` values from a packet. pub fn delete_pkm_sa_descriptor(packet: &mut Packet) { packet.delete(PKM_SA_DESCRIPTOR_TYPE); } +/// Add `pkm_sa_descriptor` octets value to a packet. pub fn add_pkm_sa_descriptor(packet: &mut Packet, value: &[u8]) { packet.add(AVP::from_bytes(PKM_SA_DESCRIPTOR_TYPE, value)); } +/// Lookup a `pkm_sa_descriptor` octets value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `pkm_sa_descriptor`, it returns `None`. pub fn lookup_pkm_sa_descriptor(packet: &Packet) -> Option> { packet .lookup(PKM_SA_DESCRIPTOR_TYPE) .map(|v| v.encode_bytes()) } +/// Lookup all of the `pkm_sa_descriptor` octets value from a packet. pub fn lookup_all_pkm_sa_descriptor(packet: &Packet) -> Vec> { let mut vec = Vec::new(); for avp in packet.lookup_all(PKM_SA_DESCRIPTOR_TYPE) { @@ -128,15 +185,21 @@ pub fn lookup_all_pkm_sa_descriptor(packet: &Packet) -> Vec> { } pub const PKM_AUTH_KEY_TYPE: AVPType = 143; +/// Delete all of `pkm_auth_key` values from a packet. pub fn delete_pkm_auth_key(packet: &mut Packet) { packet.delete(PKM_AUTH_KEY_TYPE); } +/// Add `pkm_auth_key` octets value to a packet. pub fn add_pkm_auth_key(packet: &mut Packet, value: &[u8]) { packet.add(AVP::from_bytes(PKM_AUTH_KEY_TYPE, value)); } +/// Lookup a `pkm_auth_key` octets value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `pkm_auth_key`, it returns `None`. pub fn lookup_pkm_auth_key(packet: &Packet) -> Option> { packet.lookup(PKM_AUTH_KEY_TYPE).map(|v| v.encode_bytes()) } +/// Lookup all of the `pkm_auth_key` octets value from a packet. pub fn lookup_all_pkm_auth_key(packet: &Packet) -> Vec> { let mut vec = Vec::new(); for avp in packet.lookup_all(PKM_AUTH_KEY_TYPE) { diff --git a/radius/src/core/rfc6519.rs b/radius/src/core/rfc6519.rs index 8b4a917..c8ee213 100644 --- a/radius/src/core/rfc6519.rs +++ b/radius/src/core/rfc6519.rs @@ -1,20 +1,44 @@ // Code generated by machine generator; DO NOT EDIT. +//! Utility for rfc6519 packet. +//! +//! This module handles the packet according to the following definition: +//! ```text +//! //! # -*- text -*- +//! # Copyright (C) 2020 The FreeRADIUS Server project and contributors +//! # This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0 +//! # Version $Id$ +//! # +//! # Attributes and values defined in RFC 6519. +//! # http://www.ietf.org/rfc/rfc6519.txt +//! # +//! # $Id$ +//! # +//! +//! ATTRIBUTE DS-Lite-Tunnel-Name 144 string +//! ``` + use crate::core::avp::{AVPError, AVPType, AVP}; use crate::core::packet::Packet; pub const DS_LITE_TUNNEL_NAME_TYPE: AVPType = 144; +/// Delete all of `ds_lite_tunnel_name` values from a packet. pub fn delete_ds_lite_tunnel_name(packet: &mut Packet) { packet.delete(DS_LITE_TUNNEL_NAME_TYPE); } +/// Add `ds_lite_tunnel_name` string value to a packet. pub fn add_ds_lite_tunnel_name(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(DS_LITE_TUNNEL_NAME_TYPE, value)); } +/// Lookup a `ds_lite_tunnel_name` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `ds_lite_tunnel_name`, it returns `None`. pub fn lookup_ds_lite_tunnel_name(packet: &Packet) -> Option> { packet .lookup(DS_LITE_TUNNEL_NAME_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `ds_lite_tunnel_name` string value from a packet. pub fn lookup_all_ds_lite_tunnel_name(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(DS_LITE_TUNNEL_NAME_TYPE) { diff --git a/radius/src/core/rfc6572.rs b/radius/src/core/rfc6572.rs index 19106d5..78497a6 100644 --- a/radius/src/core/rfc6572.rs +++ b/radius/src/core/rfc6572.rs @@ -1,22 +1,63 @@ // Code generated by machine generator; DO NOT EDIT. +//! Utility for rfc6572 packet. +//! +//! This module handles the packet according to the following definition: +//! ```text +//! //! # -*- text -*- +//! # Copyright (C) 2020 The FreeRADIUS Server project and contributors +//! # This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0 +//! # Version $Id$ +//! # +//! # Attributes and values defined in RFC 6572. +//! # http://www.ietf.org/rfc/rfc6572.txt +//! # +//! # $Id$ +//! # +//! +//! ATTRIBUTE Mobile-Node-Identifier 145 octets +//! ATTRIBUTE Service-Selection 146 string +//! ATTRIBUTE PMIP6-Home-LMA-IPV6-Address 147 ipv6addr +//! ATTRIBUTE PMIP6-Visited-LMA-IPV6-Address 148 ipv6addr +//! ATTRIBUTE PMIP6-Home-LMA-IPV4-Address 149 ipaddr +//! ATTRIBUTE PMIP6-Visited-LMA-IPV4-Address 150 ipaddr +//! ATTRIBUTE PMIP6-Home-HN-Prefix 151 ipv6prefix +//! ATTRIBUTE PMIP6-Visited-HN-Prefix 152 ipv6prefix +//! ATTRIBUTE PMIP6-Home-Interface-ID 153 ifid +//! ATTRIBUTE PMIP6-Visited-Interface-ID 154 ifid +//! ATTRIBUTE PMIP6-Home-IPV4-HoA 155 ipv4prefix +//! ATTRIBUTE PMIP6-Visited-IPV4-HoA 156 ipv4prefix +//! ATTRIBUTE PMIP6-Home-DHCP4-Server-Address 157 ipaddr +//! ATTRIBUTE PMIP6-Visited-DHCP4-Server-Address 158 ipaddr +//! ATTRIBUTE PMIP6-Home-DHCP6-Server-Address 159 ipv6addr +//! ATTRIBUTE PMIP6-Visited-DHCP6-Server-Address 160 ipv6addr +//! ATTRIBUTE PMIP6-Home-IPV4-Gateway 161 ipaddr +//! ATTRIBUTE PMIP6-Visited-IPV4-Gateway 162 ipaddr +//! ``` + use std::net::{Ipv4Addr, Ipv6Addr}; use crate::core::avp::{AVPError, AVPType, AVP}; use crate::core::packet::Packet; pub const MOBILE_NODE_IDENTIFIER_TYPE: AVPType = 145; +/// Delete all of `mobile_node_identifier` values from a packet. pub fn delete_mobile_node_identifier(packet: &mut Packet) { packet.delete(MOBILE_NODE_IDENTIFIER_TYPE); } +/// Add `mobile_node_identifier` octets value to a packet. pub fn add_mobile_node_identifier(packet: &mut Packet, value: &[u8]) { packet.add(AVP::from_bytes(MOBILE_NODE_IDENTIFIER_TYPE, value)); } +/// Lookup a `mobile_node_identifier` octets value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `mobile_node_identifier`, it returns `None`. pub fn lookup_mobile_node_identifier(packet: &Packet) -> Option> { packet .lookup(MOBILE_NODE_IDENTIFIER_TYPE) .map(|v| v.encode_bytes()) } +/// Lookup all of the `mobile_node_identifier` octets value from a packet. pub fn lookup_all_mobile_node_identifier(packet: &Packet) -> Vec> { let mut vec = Vec::new(); for avp in packet.lookup_all(MOBILE_NODE_IDENTIFIER_TYPE) { @@ -26,17 +67,23 @@ pub fn lookup_all_mobile_node_identifier(packet: &Packet) -> Vec> { } pub const SERVICE_SELECTION_TYPE: AVPType = 146; +/// Delete all of `service_selection` values from a packet. pub fn delete_service_selection(packet: &mut Packet) { packet.delete(SERVICE_SELECTION_TYPE); } +/// Add `service_selection` string value to a packet. pub fn add_service_selection(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(SERVICE_SELECTION_TYPE, value)); } +/// Lookup a `service_selection` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `service_selection`, it returns `None`. pub fn lookup_service_selection(packet: &Packet) -> Option> { packet .lookup(SERVICE_SELECTION_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `service_selection` string value from a packet. pub fn lookup_all_service_selection(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(SERVICE_SELECTION_TYPE) { @@ -46,17 +93,23 @@ pub fn lookup_all_service_selection(packet: &Packet) -> Result, AVPE } pub const PMIP6_HOME_LMA_IPV6_ADDRESS_TYPE: AVPType = 147; +/// Delete all of `pmip6_home_lma_ipv6_address` values from a packet. pub fn delete_pmip6_home_lma_ipv6_address(packet: &mut Packet) { packet.delete(PMIP6_HOME_LMA_IPV6_ADDRESS_TYPE); } +/// Add `pmip6_home_lma_ipv6_address` ipv6addr value to a packet. pub fn add_pmip6_home_lma_ipv6_address(packet: &mut Packet, value: &Ipv6Addr) { packet.add(AVP::from_ipv6(PMIP6_HOME_LMA_IPV6_ADDRESS_TYPE, value)); } +/// Lookup a `pmip6_home_lma_ipv6_address` ipv6addr value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `pmip6_home_lma_ipv6_address`, it returns `None`. pub fn lookup_pmip6_home_lma_ipv6_address(packet: &Packet) -> Option> { packet .lookup(PMIP6_HOME_LMA_IPV6_ADDRESS_TYPE) .map(|v| v.encode_ipv6()) } +/// Lookup all of the `pmip6_home_lma_ipv6_address` ipv6addr value from a packet. pub fn lookup_all_pmip6_home_lma_ipv6_address(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(PMIP6_HOME_LMA_IPV6_ADDRESS_TYPE) { @@ -66,12 +119,17 @@ pub fn lookup_all_pmip6_home_lma_ipv6_address(packet: &Packet) -> Result Option> { @@ -79,6 +137,7 @@ pub fn lookup_pmip6_visited_lma_ipv6_address( .lookup(PMIP6_VISITED_LMA_IPV6_ADDRESS_TYPE) .map(|v| v.encode_ipv6()) } +/// Lookup all of the `pmip6_visited_lma_ipv6_address` ipv6addr value from a packet. pub fn lookup_all_pmip6_visited_lma_ipv6_address( packet: &Packet, ) -> Result, AVPError> { @@ -90,17 +149,23 @@ pub fn lookup_all_pmip6_visited_lma_ipv6_address( } pub const PMIP6_HOME_LMA_IPV4_ADDRESS_TYPE: AVPType = 149; +/// Delete all of `pmip6_home_lma_ipv4_address` values from a packet. pub fn delete_pmip6_home_lma_ipv4_address(packet: &mut Packet) { packet.delete(PMIP6_HOME_LMA_IPV4_ADDRESS_TYPE); } +/// Add `pmip6_home_lma_ipv4_address` ipaddr value to a packet. pub fn add_pmip6_home_lma_ipv4_address(packet: &mut Packet, value: &Ipv4Addr) { packet.add(AVP::from_ipv4(PMIP6_HOME_LMA_IPV4_ADDRESS_TYPE, value)); } +/// Lookup a `pmip6_home_lma_ipv4_address` ipaddr value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `pmip6_home_lma_ipv4_address`, it returns `None`. pub fn lookup_pmip6_home_lma_ipv4_address(packet: &Packet) -> Option> { packet .lookup(PMIP6_HOME_LMA_IPV4_ADDRESS_TYPE) .map(|v| v.encode_ipv4()) } +/// Lookup all of the `pmip6_home_lma_ipv4_address` ipaddr value from a packet. pub fn lookup_all_pmip6_home_lma_ipv4_address(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(PMIP6_HOME_LMA_IPV4_ADDRESS_TYPE) { @@ -110,12 +175,17 @@ pub fn lookup_all_pmip6_home_lma_ipv4_address(packet: &Packet) -> Result Option> { @@ -123,6 +193,7 @@ pub fn lookup_pmip6_visited_lma_ipv4_address( .lookup(PMIP6_VISITED_LMA_IPV4_ADDRESS_TYPE) .map(|v| v.encode_ipv4()) } +/// Lookup all of the `pmip6_visited_lma_ipv4_address` ipaddr value from a packet. pub fn lookup_all_pmip6_visited_lma_ipv4_address( packet: &Packet, ) -> Result, AVPError> { @@ -134,18 +205,24 @@ pub fn lookup_all_pmip6_visited_lma_ipv4_address( } pub const PMIP6_HOME_HN_PREFIX_TYPE: AVPType = 151; +/// Delete all of `pmip6_home_hn_prefix` values from a packet. pub fn delete_pmip6_home_hn_prefix(packet: &mut Packet) { packet.delete(PMIP6_HOME_HN_PREFIX_TYPE); } +/// Add `pmip6_home_hn_prefix` ipv6 prefix value to a packet. pub fn add_pmip6_home_hn_prefix(packet: &mut Packet, value: &[u8]) -> Result<(), AVPError> { packet.add(AVP::from_ipv6_prefix(PMIP6_HOME_HN_PREFIX_TYPE, value)?); Ok(()) } +/// Lookup a `pmip6_home_hn_prefix` ipv6 prefix value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `pmip6_home_hn_prefix`, it returns `None`. pub fn lookup_pmip6_home_hn_prefix(packet: &Packet) -> Option, AVPError>> { packet .lookup(PMIP6_HOME_HN_PREFIX_TYPE) .map(|v| v.encode_ipv6_prefix()) } +/// Lookup all of the `pmip6_home_hn_prefix` ipv6 prefix value from a packet. pub fn lookup_all_pmip6_home_hn_prefix(packet: &Packet) -> Result>, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(PMIP6_HOME_HN_PREFIX_TYPE) { @@ -155,18 +232,24 @@ pub fn lookup_all_pmip6_home_hn_prefix(packet: &Packet) -> Result>, } pub const PMIP6_VISITED_HN_PREFIX_TYPE: AVPType = 152; +/// Delete all of `pmip6_visited_hn_prefix` values from a packet. pub fn delete_pmip6_visited_hn_prefix(packet: &mut Packet) { packet.delete(PMIP6_VISITED_HN_PREFIX_TYPE); } +/// Add `pmip6_visited_hn_prefix` ipv6 prefix value to a packet. pub fn add_pmip6_visited_hn_prefix(packet: &mut Packet, value: &[u8]) -> Result<(), AVPError> { packet.add(AVP::from_ipv6_prefix(PMIP6_VISITED_HN_PREFIX_TYPE, value)?); Ok(()) } +/// Lookup a `pmip6_visited_hn_prefix` ipv6 prefix value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `pmip6_visited_hn_prefix`, it returns `None`. pub fn lookup_pmip6_visited_hn_prefix(packet: &Packet) -> Option, AVPError>> { packet .lookup(PMIP6_VISITED_HN_PREFIX_TYPE) .map(|v| v.encode_ipv6_prefix()) } +/// Lookup all of the `pmip6_visited_hn_prefix` ipv6 prefix value from a packet. pub fn lookup_all_pmip6_visited_hn_prefix(packet: &Packet) -> Result>, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(PMIP6_VISITED_HN_PREFIX_TYPE) { @@ -176,9 +259,11 @@ pub fn lookup_all_pmip6_visited_hn_prefix(packet: &Packet) -> Result } pub const PMIP6_HOME_INTERFACE_ID_TYPE: AVPType = 153; +/// Delete all of `pmip6_home_interface_id` values from a packet. pub fn delete_pmip6_home_interface_id(packet: &mut Packet) { packet.delete(PMIP6_HOME_INTERFACE_ID_TYPE); } +/// Add `pmip6_home_interface_id` fixed-length octets value to a packet. pub fn add_pmip6_home_interface_id(packet: &mut Packet, value: &[u8]) -> Result<(), AVPError> { if value.len() != 8 { return Err(AVPError::InvalidAttributeLengthError( @@ -189,11 +274,15 @@ pub fn add_pmip6_home_interface_id(packet: &mut Packet, value: &[u8]) -> Result< packet.add(AVP::from_bytes(PMIP6_HOME_INTERFACE_ID_TYPE, value)); Ok(()) } +/// Lookup a `pmip6_home_interface_id` fixed-length octets value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `pmip6_home_interface_id`, it returns `None`. pub fn lookup_pmip6_home_interface_id(packet: &Packet) -> Option> { packet .lookup(PMIP6_HOME_INTERFACE_ID_TYPE) .map(|v| v.encode_bytes()) } +/// Lookup all of the `pmip6_home_interface_id` fixed-length octets value from a packet. pub fn lookup_all_pmip6_home_interface_id(packet: &Packet) -> Vec> { let mut vec = Vec::new(); for avp in packet.lookup_all(PMIP6_HOME_INTERFACE_ID_TYPE) { @@ -203,9 +292,11 @@ pub fn lookup_all_pmip6_home_interface_id(packet: &Packet) -> Vec> { } pub const PMIP6_VISITED_INTERFACE_ID_TYPE: AVPType = 154; +/// Delete all of `pmip6_visited_interface_id` values from a packet. pub fn delete_pmip6_visited_interface_id(packet: &mut Packet) { packet.delete(PMIP6_VISITED_INTERFACE_ID_TYPE); } +/// Add `pmip6_visited_interface_id` fixed-length octets value to a packet. pub fn add_pmip6_visited_interface_id(packet: &mut Packet, value: &[u8]) -> Result<(), AVPError> { if value.len() != 8 { return Err(AVPError::InvalidAttributeLengthError( @@ -216,11 +307,15 @@ pub fn add_pmip6_visited_interface_id(packet: &mut Packet, value: &[u8]) -> Resu packet.add(AVP::from_bytes(PMIP6_VISITED_INTERFACE_ID_TYPE, value)); Ok(()) } +/// Lookup a `pmip6_visited_interface_id` fixed-length octets value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `pmip6_visited_interface_id`, it returns `None`. pub fn lookup_pmip6_visited_interface_id(packet: &Packet) -> Option> { packet .lookup(PMIP6_VISITED_INTERFACE_ID_TYPE) .map(|v| v.encode_bytes()) } +/// Lookup all of the `pmip6_visited_interface_id` fixed-length octets value from a packet. pub fn lookup_all_pmip6_visited_interface_id(packet: &Packet) -> Vec> { let mut vec = Vec::new(); for avp in packet.lookup_all(PMIP6_VISITED_INTERFACE_ID_TYPE) { @@ -230,18 +325,24 @@ pub fn lookup_all_pmip6_visited_interface_id(packet: &Packet) -> Vec> { } pub const PMIP6_HOME_IPV4_HO_A_TYPE: AVPType = 155; +/// Delete all of `pmip6_home_ipv4_ho_a` values from a packet. pub fn delete_pmip6_home_ipv4_ho_a(packet: &mut Packet) { packet.delete(PMIP6_HOME_IPV4_HO_A_TYPE); } +/// Add `pmip6_home_ipv4_ho_a` ipv4 prefix value to a packet. pub fn add_pmip6_home_ipv4_ho_a(packet: &mut Packet, value: &[u8]) -> Result<(), AVPError> { packet.add(AVP::from_ipv4_prefix(PMIP6_HOME_IPV4_HO_A_TYPE, value)?); Ok(()) } +/// Lookup a `pmip6_home_ipv4_ho_a` ipv4 prefix value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `pmip6_home_ipv4_ho_a`, it returns `None`. pub fn lookup_pmip6_home_ipv4_ho_a(packet: &Packet) -> Option, AVPError>> { packet .lookup(PMIP6_HOME_IPV4_HO_A_TYPE) .map(|v| v.encode_ipv4_prefix()) } +/// Lookup all of the `pmip6_home_ipv4_ho_a` ipv4 prefix value from a packet. pub fn lookup_all_pmip6_home_ipv4_ho_a(packet: &Packet) -> Result>, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(PMIP6_HOME_IPV4_HO_A_TYPE) { @@ -251,18 +352,24 @@ pub fn lookup_all_pmip6_home_ipv4_ho_a(packet: &Packet) -> Result>, } pub const PMIP6_VISITED_IPV4_HO_A_TYPE: AVPType = 156; +/// Delete all of `pmip6_visited_ipv4_ho_a` values from a packet. pub fn delete_pmip6_visited_ipv4_ho_a(packet: &mut Packet) { packet.delete(PMIP6_VISITED_IPV4_HO_A_TYPE); } +/// Add `pmip6_visited_ipv4_ho_a` ipv4 prefix value to a packet. pub fn add_pmip6_visited_ipv4_ho_a(packet: &mut Packet, value: &[u8]) -> Result<(), AVPError> { packet.add(AVP::from_ipv4_prefix(PMIP6_VISITED_IPV4_HO_A_TYPE, value)?); Ok(()) } +/// Lookup a `pmip6_visited_ipv4_ho_a` ipv4 prefix value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `pmip6_visited_ipv4_ho_a`, it returns `None`. pub fn lookup_pmip6_visited_ipv4_ho_a(packet: &Packet) -> Option, AVPError>> { packet .lookup(PMIP6_VISITED_IPV4_HO_A_TYPE) .map(|v| v.encode_ipv4_prefix()) } +/// Lookup all of the `pmip6_visited_ipv4_ho_a` ipv4 prefix value from a packet. pub fn lookup_all_pmip6_visited_ipv4_ho_a(packet: &Packet) -> Result>, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(PMIP6_VISITED_IPV4_HO_A_TYPE) { @@ -272,12 +379,17 @@ pub fn lookup_all_pmip6_visited_ipv4_ho_a(packet: &Packet) -> Result } pub const PMIP6_HOME_DHCP4_SERVER_ADDRESS_TYPE: AVPType = 157; +/// Delete all of `pmip6_home_dhcp4_server_address` values from a packet. pub fn delete_pmip6_home_dhcp4_server_address(packet: &mut Packet) { packet.delete(PMIP6_HOME_DHCP4_SERVER_ADDRESS_TYPE); } +/// Add `pmip6_home_dhcp4_server_address` ipaddr value to a packet. pub fn add_pmip6_home_dhcp4_server_address(packet: &mut Packet, value: &Ipv4Addr) { packet.add(AVP::from_ipv4(PMIP6_HOME_DHCP4_SERVER_ADDRESS_TYPE, value)); } +/// Lookup a `pmip6_home_dhcp4_server_address` ipaddr value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `pmip6_home_dhcp4_server_address`, it returns `None`. pub fn lookup_pmip6_home_dhcp4_server_address( packet: &Packet, ) -> Option> { @@ -285,6 +397,7 @@ pub fn lookup_pmip6_home_dhcp4_server_address( .lookup(PMIP6_HOME_DHCP4_SERVER_ADDRESS_TYPE) .map(|v| v.encode_ipv4()) } +/// Lookup all of the `pmip6_home_dhcp4_server_address` ipaddr value from a packet. pub fn lookup_all_pmip6_home_dhcp4_server_address( packet: &Packet, ) -> Result, AVPError> { @@ -296,15 +409,20 @@ pub fn lookup_all_pmip6_home_dhcp4_server_address( } pub const PMIP6_VISITED_DHCP4_SERVER_ADDRESS_TYPE: AVPType = 158; +/// Delete all of `pmip6_visited_dhcp4_server_address` values from a packet. pub fn delete_pmip6_visited_dhcp4_server_address(packet: &mut Packet) { packet.delete(PMIP6_VISITED_DHCP4_SERVER_ADDRESS_TYPE); } +/// Add `pmip6_visited_dhcp4_server_address` ipaddr value to a packet. pub fn add_pmip6_visited_dhcp4_server_address(packet: &mut Packet, value: &Ipv4Addr) { packet.add(AVP::from_ipv4( PMIP6_VISITED_DHCP4_SERVER_ADDRESS_TYPE, value, )); } +/// Lookup a `pmip6_visited_dhcp4_server_address` ipaddr value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `pmip6_visited_dhcp4_server_address`, it returns `None`. pub fn lookup_pmip6_visited_dhcp4_server_address( packet: &Packet, ) -> Option> { @@ -312,6 +430,7 @@ pub fn lookup_pmip6_visited_dhcp4_server_address( .lookup(PMIP6_VISITED_DHCP4_SERVER_ADDRESS_TYPE) .map(|v| v.encode_ipv4()) } +/// Lookup all of the `pmip6_visited_dhcp4_server_address` ipaddr value from a packet. pub fn lookup_all_pmip6_visited_dhcp4_server_address( packet: &Packet, ) -> Result, AVPError> { @@ -323,12 +442,17 @@ pub fn lookup_all_pmip6_visited_dhcp4_server_address( } pub const PMIP6_HOME_DHCP6_SERVER_ADDRESS_TYPE: AVPType = 159; +/// Delete all of `pmip6_home_dhcp6_server_address` values from a packet. pub fn delete_pmip6_home_dhcp6_server_address(packet: &mut Packet) { packet.delete(PMIP6_HOME_DHCP6_SERVER_ADDRESS_TYPE); } +/// Add `pmip6_home_dhcp6_server_address` ipv6addr value to a packet. pub fn add_pmip6_home_dhcp6_server_address(packet: &mut Packet, value: &Ipv6Addr) { packet.add(AVP::from_ipv6(PMIP6_HOME_DHCP6_SERVER_ADDRESS_TYPE, value)); } +/// Lookup a `pmip6_home_dhcp6_server_address` ipv6addr value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `pmip6_home_dhcp6_server_address`, it returns `None`. pub fn lookup_pmip6_home_dhcp6_server_address( packet: &Packet, ) -> Option> { @@ -336,6 +460,7 @@ pub fn lookup_pmip6_home_dhcp6_server_address( .lookup(PMIP6_HOME_DHCP6_SERVER_ADDRESS_TYPE) .map(|v| v.encode_ipv6()) } +/// Lookup all of the `pmip6_home_dhcp6_server_address` ipv6addr value from a packet. pub fn lookup_all_pmip6_home_dhcp6_server_address( packet: &Packet, ) -> Result, AVPError> { @@ -347,15 +472,20 @@ pub fn lookup_all_pmip6_home_dhcp6_server_address( } pub const PMIP6_VISITED_DHCP6_SERVER_ADDRESS_TYPE: AVPType = 160; +/// Delete all of `pmip6_visited_dhcp6_server_address` values from a packet. pub fn delete_pmip6_visited_dhcp6_server_address(packet: &mut Packet) { packet.delete(PMIP6_VISITED_DHCP6_SERVER_ADDRESS_TYPE); } +/// Add `pmip6_visited_dhcp6_server_address` ipv6addr value to a packet. pub fn add_pmip6_visited_dhcp6_server_address(packet: &mut Packet, value: &Ipv6Addr) { packet.add(AVP::from_ipv6( PMIP6_VISITED_DHCP6_SERVER_ADDRESS_TYPE, value, )); } +/// Lookup a `pmip6_visited_dhcp6_server_address` ipv6addr value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `pmip6_visited_dhcp6_server_address`, it returns `None`. pub fn lookup_pmip6_visited_dhcp6_server_address( packet: &Packet, ) -> Option> { @@ -363,6 +493,7 @@ pub fn lookup_pmip6_visited_dhcp6_server_address( .lookup(PMIP6_VISITED_DHCP6_SERVER_ADDRESS_TYPE) .map(|v| v.encode_ipv6()) } +/// Lookup all of the `pmip6_visited_dhcp6_server_address` ipv6addr value from a packet. pub fn lookup_all_pmip6_visited_dhcp6_server_address( packet: &Packet, ) -> Result, AVPError> { @@ -374,17 +505,23 @@ pub fn lookup_all_pmip6_visited_dhcp6_server_address( } pub const PMIP6_HOME_IPV4_GATEWAY_TYPE: AVPType = 161; +/// Delete all of `pmip6_home_ipv4_gateway` values from a packet. pub fn delete_pmip6_home_ipv4_gateway(packet: &mut Packet) { packet.delete(PMIP6_HOME_IPV4_GATEWAY_TYPE); } +/// Add `pmip6_home_ipv4_gateway` ipaddr value to a packet. pub fn add_pmip6_home_ipv4_gateway(packet: &mut Packet, value: &Ipv4Addr) { packet.add(AVP::from_ipv4(PMIP6_HOME_IPV4_GATEWAY_TYPE, value)); } +/// Lookup a `pmip6_home_ipv4_gateway` ipaddr value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `pmip6_home_ipv4_gateway`, it returns `None`. pub fn lookup_pmip6_home_ipv4_gateway(packet: &Packet) -> Option> { packet .lookup(PMIP6_HOME_IPV4_GATEWAY_TYPE) .map(|v| v.encode_ipv4()) } +/// Lookup all of the `pmip6_home_ipv4_gateway` ipaddr value from a packet. pub fn lookup_all_pmip6_home_ipv4_gateway(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(PMIP6_HOME_IPV4_GATEWAY_TYPE) { @@ -394,17 +531,23 @@ pub fn lookup_all_pmip6_home_ipv4_gateway(packet: &Packet) -> Result Option> { packet .lookup(PMIP6_VISITED_IPV4_GATEWAY_TYPE) .map(|v| v.encode_ipv4()) } +/// Lookup all of the `pmip6_visited_ipv4_gateway` ipaddr value from a packet. pub fn lookup_all_pmip6_visited_ipv4_gateway(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(PMIP6_VISITED_IPV4_GATEWAY_TYPE) { diff --git a/radius/src/core/rfc6677.rs b/radius/src/core/rfc6677.rs index d9bf83b..28257ea 100644 --- a/radius/src/core/rfc6677.rs +++ b/radius/src/core/rfc6677.rs @@ -1,20 +1,52 @@ // Code generated by machine generator; DO NOT EDIT. +//! Utility for rfc6677 packet. +//! +//! This module handles the packet according to the following definition: +//! ```text +//! //! # -*- text -*- +//! # Copyright (C) 2020 The FreeRADIUS Server project and contributors +//! # This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0 +//! # Version $Id$ +//! # +//! # Attributes and values defined in RFC 6677 +//! # http://www.ietf.org/rfc/rfc6677.txt +//! # +//! +//! ATTRIBUTE EAP-Lower-Layer 163 integer +//! +//! VALUE EAP-Lower-Layer Wired-IEEE-802.1X 1 +//! VALUE EAP-Lower-Layer IEEE-802.1X-No-Preauth 2 +//! VALUE EAP-Lower-Layer IEEE-802.1X-Preauth 3 +//! VALUE EAP-Lower-Layer IEEE-802.16e 4 +//! VALUE EAP-Lower-Layer IKEv2 5 +//! VALUE EAP-Lower-Layer PPP 6 +//! VALUE EAP-Lower-Layer PANA-No-Preauth 7 +//! VALUE EAP-Lower-Layer GSS-API 8 +//! VALUE EAP-Lower-Layer PANA-Preauth 9 +//! ``` + use crate::core::avp::{AVPError, AVPType, AVP}; use crate::core::packet::Packet; pub const EAP_LOWER_LAYER_TYPE: AVPType = 163; +/// Delete all of `eap_lower_layer` values from a packet. pub fn delete_eap_lower_layer(packet: &mut Packet) { packet.delete(EAP_LOWER_LAYER_TYPE); } +/// Add `eap_lower_layer` value-defined integer value to a packet. pub fn add_eap_lower_layer(packet: &mut Packet, value: EapLowerLayer) { packet.add(AVP::from_u32(EAP_LOWER_LAYER_TYPE, value as u32)); } +/// Lookup a `eap_lower_layer` value-defined integer value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `eap_lower_layer`, it returns `None`. pub fn lookup_eap_lower_layer(packet: &Packet) -> Option> { packet .lookup(EAP_LOWER_LAYER_TYPE) .map(|v| Ok(v.encode_u32()? as EapLowerLayer)) } +/// Lookup all of the `eap_lower_layer` value-defined integer value from a packet. pub fn lookup_all_eap_lower_layer(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(EAP_LOWER_LAYER_TYPE) { diff --git a/radius/src/core/rfc6911.rs b/radius/src/core/rfc6911.rs index 5dfe69b..8be2803 100644 --- a/radius/src/core/rfc6911.rs +++ b/radius/src/core/rfc6911.rs @@ -1,22 +1,48 @@ // Code generated by machine generator; DO NOT EDIT. +//! Utility for rfc6911 packet. +//! +//! This module handles the packet according to the following definition: +//! ```text +//! //! # -*- text -*- +//! # Copyright (C) 2020 The FreeRADIUS Server project and contributors +//! # This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0 +//! # Version $Id$ +//! # +//! # Attributes and values defined in RFC 6911 +//! # http://www.ietf.org/rfc/rfc6911.txt +//! # +//! +//! ATTRIBUTE Framed-IPV6-Address 168 ipv6addr +//! ATTRIBUTE DNS-Server-IPV6-Address 169 ipv6addr +//! ATTRIBUTE Route-IPV6-Information 170 ipv6prefix +//! ATTRIBUTE Delegated-IPV6-Prefix-Pool 171 string +//! ATTRIBUTE Stateful-IPV6-Address-Pool 172 string +//! ``` + use std::net::Ipv6Addr; use crate::core::avp::{AVPError, AVPType, AVP}; use crate::core::packet::Packet; pub const FRAMED_IPV6_ADDRESS_TYPE: AVPType = 168; +/// Delete all of `framed_ipv6_address` values from a packet. pub fn delete_framed_ipv6_address(packet: &mut Packet) { packet.delete(FRAMED_IPV6_ADDRESS_TYPE); } +/// Add `framed_ipv6_address` ipv6addr value to a packet. pub fn add_framed_ipv6_address(packet: &mut Packet, value: &Ipv6Addr) { packet.add(AVP::from_ipv6(FRAMED_IPV6_ADDRESS_TYPE, value)); } +/// Lookup a `framed_ipv6_address` ipv6addr value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `framed_ipv6_address`, it returns `None`. pub fn lookup_framed_ipv6_address(packet: &Packet) -> Option> { packet .lookup(FRAMED_IPV6_ADDRESS_TYPE) .map(|v| v.encode_ipv6()) } +/// Lookup all of the `framed_ipv6_address` ipv6addr value from a packet. pub fn lookup_all_framed_ipv6_address(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(FRAMED_IPV6_ADDRESS_TYPE) { @@ -26,17 +52,23 @@ pub fn lookup_all_framed_ipv6_address(packet: &Packet) -> Result, } pub const DNS_SERVER_IPV6_ADDRESS_TYPE: AVPType = 169; +/// Delete all of `dns_server_ipv6_address` values from a packet. pub fn delete_dns_server_ipv6_address(packet: &mut Packet) { packet.delete(DNS_SERVER_IPV6_ADDRESS_TYPE); } +/// Add `dns_server_ipv6_address` ipv6addr value to a packet. pub fn add_dns_server_ipv6_address(packet: &mut Packet, value: &Ipv6Addr) { packet.add(AVP::from_ipv6(DNS_SERVER_IPV6_ADDRESS_TYPE, value)); } +/// Lookup a `dns_server_ipv6_address` ipv6addr value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `dns_server_ipv6_address`, it returns `None`. pub fn lookup_dns_server_ipv6_address(packet: &Packet) -> Option> { packet .lookup(DNS_SERVER_IPV6_ADDRESS_TYPE) .map(|v| v.encode_ipv6()) } +/// Lookup all of the `dns_server_ipv6_address` ipv6addr value from a packet. pub fn lookup_all_dns_server_ipv6_address(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(DNS_SERVER_IPV6_ADDRESS_TYPE) { @@ -46,18 +78,24 @@ pub fn lookup_all_dns_server_ipv6_address(packet: &Packet) -> Result Result<(), AVPError> { packet.add(AVP::from_ipv6_prefix(ROUTE_IPV6_INFORMATION_TYPE, value)?); Ok(()) } +/// Lookup a `route_ipv6_information` ipv6 prefix value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `route_ipv6_information`, it returns `None`. pub fn lookup_route_ipv6_information(packet: &Packet) -> Option, AVPError>> { packet .lookup(ROUTE_IPV6_INFORMATION_TYPE) .map(|v| v.encode_ipv6_prefix()) } +/// Lookup all of the `route_ipv6_information` ipv6 prefix value from a packet. pub fn lookup_all_route_ipv6_information(packet: &Packet) -> Result>, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(ROUTE_IPV6_INFORMATION_TYPE) { @@ -67,17 +105,23 @@ pub fn lookup_all_route_ipv6_information(packet: &Packet) -> Result> } pub const DELEGATED_IPV6_PREFIX_POOL_TYPE: AVPType = 171; +/// Delete all of `delegated_ipv6_prefix_pool` values from a packet. pub fn delete_delegated_ipv6_prefix_pool(packet: &mut Packet) { packet.delete(DELEGATED_IPV6_PREFIX_POOL_TYPE); } +/// Add `delegated_ipv6_prefix_pool` string value to a packet. pub fn add_delegated_ipv6_prefix_pool(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(DELEGATED_IPV6_PREFIX_POOL_TYPE, value)); } +/// Lookup a `delegated_ipv6_prefix_pool` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `delegated_ipv6_prefix_pool`, it returns `None`. pub fn lookup_delegated_ipv6_prefix_pool(packet: &Packet) -> Option> { packet .lookup(DELEGATED_IPV6_PREFIX_POOL_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `delegated_ipv6_prefix_pool` string value from a packet. pub fn lookup_all_delegated_ipv6_prefix_pool(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(DELEGATED_IPV6_PREFIX_POOL_TYPE) { @@ -87,17 +131,23 @@ pub fn lookup_all_delegated_ipv6_prefix_pool(packet: &Packet) -> Result Option> { packet .lookup(STATEFUL_IPV6_ADDRESS_POOL_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `stateful_ipv6_address_pool` string value from a packet. pub fn lookup_all_stateful_ipv6_address_pool(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(STATEFUL_IPV6_ADDRESS_POOL_TYPE) { diff --git a/radius/src/core/rfc7055.rs b/radius/src/core/rfc7055.rs index 8aec1d2..e248cfe 100644 --- a/radius/src/core/rfc7055.rs +++ b/radius/src/core/rfc7055.rs @@ -1,20 +1,45 @@ // Code generated by machine generator; DO NOT EDIT. +//! Utility for rfc7055 packet. +//! +//! This module handles the packet according to the following definition: +//! ```text +//! //! # -*- text -*- +//! # Copyright (C) 2020 The FreeRADIUS Server project and contributors +//! # This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0 +//! # Version $Id$ +//! # +//! # Attributes and values defined in RFC 7055 +//! # http://www.ietf.org/rfc/rfc7055.txt +//! # +//! +//! ATTRIBUTE GSS-Acceptor-Service-Name 164 string +//! ATTRIBUTE GSS-Acceptor-Host-Name 165 string +//! ATTRIBUTE GSS-Acceptor-Service-Specifics 166 string +//! ATTRIBUTE GSS-Acceptor-Realm-Name 167 string +//! ``` + use crate::core::avp::{AVPError, AVPType, AVP}; use crate::core::packet::Packet; pub const GSS_ACCEPTOR_SERVICE_NAME_TYPE: AVPType = 164; +/// Delete all of `gss_acceptor_service_name` values from a packet. pub fn delete_gss_acceptor_service_name(packet: &mut Packet) { packet.delete(GSS_ACCEPTOR_SERVICE_NAME_TYPE); } +/// Add `gss_acceptor_service_name` string value to a packet. pub fn add_gss_acceptor_service_name(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(GSS_ACCEPTOR_SERVICE_NAME_TYPE, value)); } +/// Lookup a `gss_acceptor_service_name` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `gss_acceptor_service_name`, it returns `None`. pub fn lookup_gss_acceptor_service_name(packet: &Packet) -> Option> { packet .lookup(GSS_ACCEPTOR_SERVICE_NAME_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `gss_acceptor_service_name` string value from a packet. pub fn lookup_all_gss_acceptor_service_name(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(GSS_ACCEPTOR_SERVICE_NAME_TYPE) { @@ -24,17 +49,23 @@ pub fn lookup_all_gss_acceptor_service_name(packet: &Packet) -> Result Option> { packet .lookup(GSS_ACCEPTOR_HOST_NAME_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `gss_acceptor_host_name` string value from a packet. pub fn lookup_all_gss_acceptor_host_name(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(GSS_ACCEPTOR_HOST_NAME_TYPE) { @@ -44,17 +75,23 @@ pub fn lookup_all_gss_acceptor_host_name(packet: &Packet) -> Result, } pub const GSS_ACCEPTOR_SERVICE_SPECIFICS_TYPE: AVPType = 166; +/// Delete all of `gss_acceptor_service_specifics` values from a packet. pub fn delete_gss_acceptor_service_specifics(packet: &mut Packet) { packet.delete(GSS_ACCEPTOR_SERVICE_SPECIFICS_TYPE); } +/// Add `gss_acceptor_service_specifics` string value to a packet. pub fn add_gss_acceptor_service_specifics(packet: &mut Packet, value: &str) { packet.add(AVP::from_string(GSS_ACCEPTOR_SERVICE_SPECIFICS_TYPE, value)); } +/// Lookup a `gss_acceptor_service_specifics` string value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `gss_acceptor_service_specifics`, it returns `None`. pub fn lookup_gss_acceptor_service_specifics(packet: &Packet) -> Option> { packet .lookup(GSS_ACCEPTOR_SERVICE_SPECIFICS_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `gss_acceptor_service_specifics` string value from a packet. pub fn lookup_all_gss_acceptor_service_specifics(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(GSS_ACCEPTOR_SERVICE_SPECIFICS_TYPE) { @@ -64,17 +101,23 @@ pub fn lookup_all_gss_acceptor_service_specifics(packet: &Packet) -> Result Option> { packet .lookup(GSS_ACCEPTOR_REALM_NAME_TYPE) .map(|v| v.encode_string()) } +/// Lookup all of the `gss_acceptor_realm_name` string value from a packet. pub fn lookup_all_gss_acceptor_realm_name(packet: &Packet) -> Result, AVPError> { let mut vec = Vec::new(); for avp in packet.lookup_all(GSS_ACCEPTOR_REALM_NAME_TYPE) { diff --git a/radius/src/core/rfc7155.rs b/radius/src/core/rfc7155.rs index ebfe8fc..1e122fb 100644 --- a/radius/src/core/rfc7155.rs +++ b/radius/src/core/rfc7155.rs @@ -1,12 +1,33 @@ // Code generated by machine generator; DO NOT EDIT. +//! Utility for rfc7155 packet. +//! +//! This module handles the packet according to the following definition: +//! ```text +//! //! # -*- text -*- +//! # Copyright (C) 2020 The FreeRADIUS Server project and contributors +//! # This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0 +//! # Version $Id$ +//! # +//! # Attributes and values defined in RFC 7155 +//! # http://www.ietf.org/rfc/rfc7155.txt +//! # +//! +//! # The Value field contains two octets (00 - 99). ANSI T1.113 and +//! # BELLCORE 394 can be used for additional information about these +//! # values and their use. +//! ATTRIBUTE Originating-Line-Info 94 octets[2] +//! ``` + use crate::core::avp::{AVPError, AVPType, AVP}; use crate::core::packet::Packet; pub const ORIGINATING_LINE_INFO_TYPE: AVPType = 94; +/// Delete all of `originating_line_info` values from a packet. pub fn delete_originating_line_info(packet: &mut Packet) { packet.delete(ORIGINATING_LINE_INFO_TYPE); } +/// Add `originating_line_info` fixed-length octets value to a packet. pub fn add_originating_line_info(packet: &mut Packet, value: &[u8]) -> Result<(), AVPError> { if value.len() != 2 { return Err(AVPError::InvalidAttributeLengthError( @@ -17,11 +38,15 @@ pub fn add_originating_line_info(packet: &mut Packet, value: &[u8]) -> Result<() packet.add(AVP::from_bytes(ORIGINATING_LINE_INFO_TYPE, value)); Ok(()) } +/// Lookup a `originating_line_info` fixed-length octets value from a packet. +/// +/// It returns the first looked up value. If there is no associated value with `originating_line_info`, it returns `None`. pub fn lookup_originating_line_info(packet: &Packet) -> Option> { packet .lookup(ORIGINATING_LINE_INFO_TYPE) .map(|v| v.encode_bytes()) } +/// Lookup all of the `originating_line_info` fixed-length octets value from a packet. pub fn lookup_all_originating_line_info(packet: &Packet) -> Vec> { let mut vec = Vec::new(); for avp in packet.lookup_all(ORIGINATING_LINE_INFO_TYPE) { diff --git a/radius/src/server.rs b/radius/src/server.rs index bdc69aa..7794eb3 100644 --- a/radius/src/server.rs +++ b/radius/src/server.rs @@ -1,3 +1,5 @@ +//! RADIUS server implementation. + use async_trait::async_trait; use std::borrow::Borrow; use std::collections::HashSet;