Support ipv4 attribute type

This commit is contained in:
moznion
2020-11-25 01:18:11 +09:00
parent cb9876940c
commit d108309629
2 changed files with 99 additions and 2 deletions

View File

@@ -95,6 +95,8 @@ fn generate_header(w: &mut BufWriter<File>, struct_name: &String) {
let code = format!(
"// Code generated by machine generator; DO NOT EDIT.
use std::net::{{Ipv4Addr, Ipv6Addr}};
use crate::attribute::Attribute;
use crate::attributes::AVPType;
use crate::packet::Packet;
@@ -133,7 +135,10 @@ fn generate_attribute_code(w: &mut BufWriter<File>, attr: &RadiusAttribute) {
generate_common_attribute_code(w, attr);
generate_octets_attribute_code(w, attr);
}
// RadiusAttributeValueType::IPADDR => generate_ipaddr_attribute_code(w, attr),
RadiusAttributeValueType::IPADDR => {
generate_common_attribute_code(w, attr);
generate_ipaddr_attribute_code(w, attr);
}
// RadiusAttributeValueType::INTEGER => generate_integer_attribute_code(w, attr),
// RadiusAttributeValueType::VSA => generate_vsa_attribute_code(w, attr),
_ => {}
@@ -227,7 +232,22 @@ fn generate_octets_attribute_code(w: &mut BufWriter<File>, attr: &RadiusAttribut
}
fn generate_ipaddr_attribute_code(w: &mut BufWriter<File>, attr: &RadiusAttribute) {
unimplemented!()
let attr_name = attr.name.clone();
let type_identifier = format!("{}_TYPE", attr_name.to_screaming_snake_case());
let type_calling = format!("Self::{}", type_identifier);
let code = format!(
"pub fn add_{method_identifier}(packet: &mut Packet, value: &Ipv4Addr) {{
let attr = Attribute::from_ipv4(value);
packet.add({type_calling}, &attr);
}}
",
method_identifier = attr_name.to_snake_case(),
type_calling = type_calling,
);
w.write_all(code.as_bytes()).unwrap();
}
fn generate_integer_attribute_code(w: &mut BufWriter<File>, attr: &RadiusAttribute) {

View File

@@ -1,5 +1,7 @@
// Code generated by machine generator; DO NOT EDIT.
use std::net::{Ipv4Addr, Ipv6Addr};
use crate::attribute::Attribute;
use crate::attributes::AVPType;
use crate::packet::Packet;
@@ -53,6 +55,51 @@ impl RFC2865 {
packet.add(Self::CHAP_PASSWORD_TYPE, &attr);
}
pub const NAS_IP_ADDRESS_TYPE: AVPType = 4;
pub fn delete_nas_ip_address(packet: &mut Packet) {
packet.delete(Self::NAS_IP_ADDRESS_TYPE);
}
pub fn lookup_nas_ip_address(packet: &Packet) -> Option<&Attribute> {
packet.lookup(Self::NAS_IP_ADDRESS_TYPE)
}
pub fn lookup_all_nas_ip_address(packet: &Packet) -> Vec<&Attribute> {
packet.lookup_all(Self::NAS_IP_ADDRESS_TYPE)
}
pub fn add_nas_ip_address(packet: &mut Packet, value: &Ipv4Addr) {
let attr = Attribute::from_ipv4(value);
packet.add(Self::NAS_IP_ADDRESS_TYPE, &attr);
}
pub const FRAMED_IP_ADDRESS_TYPE: AVPType = 8;
pub fn delete_framed_ip_address(packet: &mut Packet) {
packet.delete(Self::FRAMED_IP_ADDRESS_TYPE);
}
pub fn lookup_framed_ip_address(packet: &Packet) -> Option<&Attribute> {
packet.lookup(Self::FRAMED_IP_ADDRESS_TYPE)
}
pub fn lookup_all_framed_ip_address(packet: &Packet) -> Vec<&Attribute> {
packet.lookup_all(Self::FRAMED_IP_ADDRESS_TYPE)
}
pub fn add_framed_ip_address(packet: &mut Packet, value: &Ipv4Addr) {
let attr = Attribute::from_ipv4(value);
packet.add(Self::FRAMED_IP_ADDRESS_TYPE, &attr);
}
pub const FRAMED_IP_NETMASK_TYPE: AVPType = 9;
pub fn delete_framed_ip_netmask(packet: &mut Packet) {
packet.delete(Self::FRAMED_IP_NETMASK_TYPE);
}
pub fn lookup_framed_ip_netmask(packet: &Packet) -> Option<&Attribute> {
packet.lookup(Self::FRAMED_IP_NETMASK_TYPE)
}
pub fn lookup_all_framed_ip_netmask(packet: &Packet) -> Vec<&Attribute> {
packet.lookup_all(Self::FRAMED_IP_NETMASK_TYPE)
}
pub fn add_framed_ip_netmask(packet: &mut Packet, value: &Ipv4Addr) {
let attr = Attribute::from_ipv4(value);
packet.add(Self::FRAMED_IP_NETMASK_TYPE, &attr);
}
pub const FILTER_ID_TYPE: AVPType = 11;
pub fn delete_filter_id(packet: &mut Packet) {
packet.delete(Self::FILTER_ID_TYPE);
@@ -68,6 +115,21 @@ impl RFC2865 {
packet.add(Self::FILTER_ID_TYPE, &attr);
}
pub const LOGIN_IP_HOST_TYPE: AVPType = 14;
pub fn delete_login_ip_host(packet: &mut Packet) {
packet.delete(Self::LOGIN_IP_HOST_TYPE);
}
pub fn lookup_login_ip_host(packet: &Packet) -> Option<&Attribute> {
packet.lookup(Self::LOGIN_IP_HOST_TYPE)
}
pub fn lookup_all_login_ip_host(packet: &Packet) -> Vec<&Attribute> {
packet.lookup_all(Self::LOGIN_IP_HOST_TYPE)
}
pub fn add_login_ip_host(packet: &mut Packet, value: &Ipv4Addr) {
let attr = Attribute::from_ipv4(value);
packet.add(Self::LOGIN_IP_HOST_TYPE, &attr);
}
pub const REPLY_MESSAGE_TYPE: AVPType = 18;
pub fn delete_reply_message(packet: &mut Packet) {
packet.delete(Self::REPLY_MESSAGE_TYPE);
@@ -128,6 +190,21 @@ impl RFC2865 {
packet.add(Self::FRAMED_ROUTE_TYPE, &attr);
}
pub const FRAMED_IPX_NETWORK_TYPE: AVPType = 23;
pub fn delete_framed_ipx_network(packet: &mut Packet) {
packet.delete(Self::FRAMED_IPX_NETWORK_TYPE);
}
pub fn lookup_framed_ipx_network(packet: &Packet) -> Option<&Attribute> {
packet.lookup(Self::FRAMED_IPX_NETWORK_TYPE)
}
pub fn lookup_all_framed_ipx_network(packet: &Packet) -> Vec<&Attribute> {
packet.lookup_all(Self::FRAMED_IPX_NETWORK_TYPE)
}
pub fn add_framed_ipx_network(packet: &mut Packet, value: &Ipv4Addr) {
let attr = Attribute::from_ipv4(value);
packet.add(Self::FRAMED_IPX_NETWORK_TYPE, &attr);
}
pub const STATE_TYPE: AVPType = 24;
pub fn delete_state(packet: &mut Packet) {
packet.delete(Self::STATE_TYPE);