1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
// 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<Result<(TunnelType, Tag), AVPError>> {
    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<Vec<(TunnelType, Tag)>, AVPError> {
    let mut vec = Vec::new();
    for avp in packet.lookup_all(TUNNEL_TYPE_TYPE) {
        let (v, t) = avp.encode_tagged_u32()?;
        vec.push((v as TunnelType, t))
    }
    Ok(vec)
}

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,
        tag,
        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<Result<(TunnelMediumType, Tag), AVPError>> {
    packet.lookup(TUNNEL_MEDIUM_TYPE_TYPE).map(|v| {
        let (v, t) = v.encode_tagged_u32()?;
        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<Vec<(TunnelMediumType, Tag)>, AVPError> {
    let mut vec = Vec::new();
    for avp in packet.lookup_all(TUNNEL_MEDIUM_TYPE_TYPE) {
        let (v, t) = avp.encode_tagged_u32()?;
        vec.push((v as TunnelMediumType, t))
    }
    Ok(vec)
}

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,
        tag,
        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<Result<(String, Option<Tag>), AVPError>> {
    packet
        .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<Vec<(String, Option<Tag>)>, AVPError> {
    let mut vec = Vec::new();
    for avp in packet.lookup_all(TUNNEL_CLIENT_ENDPOINT_TYPE) {
        vec.push(avp.encode_tagged_string()?)
    }
    Ok(vec)
}

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,
        tag,
        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<Result<(String, Option<Tag>), AVPError>> {
    packet
        .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<Vec<(String, Option<Tag>)>, AVPError> {
    let mut vec = Vec::new();
    for avp in packet.lookup_all(TUNNEL_SERVER_ENDPOINT_TYPE) {
        vec.push(avp.encode_tagged_string()?)
    }
    Ok(vec)
}

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>,
    value: &[u8],
) -> Result<(), AVPError> {
    packet.add(AVP::from_tunnel_password(
        TUNNEL_PASSWORD_TYPE,
        tag,
        value,
        packet.get_secret(),
        packet.get_authenticator(),
    )?);
    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<Result<(Vec<u8>, 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<Vec<(Vec<u8>, Tag)>, AVPError> {
    let mut vec = Vec::new();
    for avp in packet.lookup_all(TUNNEL_PASSWORD_TYPE) {
        vec.push(avp.encode_tunnel_password(packet.get_secret(), packet.get_authenticator())?)
    }
    Ok(vec)
}

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,
        tag,
        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<Result<(String, Option<Tag>), AVPError>> {
    packet
        .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<Vec<(String, Option<Tag>)>, AVPError> {
    let mut vec = Vec::new();
    for avp in packet.lookup_all(TUNNEL_PRIVATE_GROUP_ID_TYPE) {
        vec.push(avp.encode_tagged_string()?)
    }
    Ok(vec)
}

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,
        tag,
        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<Result<(String, Option<Tag>), AVPError>> {
    packet
        .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<Vec<(String, Option<Tag>)>, AVPError> {
    let mut vec = Vec::new();
    for avp in packet.lookup_all(TUNNEL_ASSIGNMENT_ID_TYPE) {
        vec.push(avp.encode_tagged_string()?)
    }
    Ok(vec)
}

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<Result<(u32, Tag), AVPError>> {
    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<Vec<(u32, Tag)>, AVPError> {
    let mut vec = Vec::new();
    for avp in packet.lookup_all(TUNNEL_PREFERENCE_TYPE) {
        vec.push(avp.encode_tagged_u32()?)
    }
    Ok(vec)
}

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,
        tag,
        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<Result<(String, Option<Tag>), AVPError>> {
    packet
        .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<Vec<(String, Option<Tag>)>, AVPError> {
    let mut vec = Vec::new();
    for avp in packet.lookup_all(TUNNEL_CLIENT_AUTH_ID_TYPE) {
        vec.push(avp.encode_tagged_string()?)
    }
    Ok(vec)
}

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,
        tag,
        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<Result<(String, Option<Tag>), AVPError>> {
    packet
        .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<Vec<(String, Option<Tag>)>, AVPError> {
    let mut vec = Vec::new();
    for avp in packet.lookup_all(TUNNEL_SERVER_AUTH_ID_TYPE) {
        vec.push(avp.encode_tagged_string()?)
    }
    Ok(vec)
}

pub type TunnelMediumType = u32;
pub const TUNNEL_MEDIUM_TYPE_IP: TunnelMediumType = 1;
pub const TUNNEL_MEDIUM_TYPE_I_PV_4: TunnelMediumType = 1;
pub const TUNNEL_MEDIUM_TYPE_I_PV_6: TunnelMediumType = 2;
pub const TUNNEL_MEDIUM_TYPE_NSAP: TunnelMediumType = 3;
pub const TUNNEL_MEDIUM_TYPE_HDLC: TunnelMediumType = 4;
pub const TUNNEL_MEDIUM_TYPE_BBN_1822: TunnelMediumType = 5;
pub const TUNNEL_MEDIUM_TYPE_IEEE_802: TunnelMediumType = 6;
pub const TUNNEL_MEDIUM_TYPE_E_163: TunnelMediumType = 7;
pub const TUNNEL_MEDIUM_TYPE_E_164: TunnelMediumType = 8;
pub const TUNNEL_MEDIUM_TYPE_F_69: TunnelMediumType = 9;
pub const TUNNEL_MEDIUM_TYPE_X_121: TunnelMediumType = 10;
pub const TUNNEL_MEDIUM_TYPE_IPX: TunnelMediumType = 11;
pub const TUNNEL_MEDIUM_TYPE_APPLETALK: TunnelMediumType = 12;
pub const TUNNEL_MEDIUM_TYPE_DEC_NET_IV: TunnelMediumType = 13;
pub const TUNNEL_MEDIUM_TYPE_BANYAN_VINES: TunnelMediumType = 14;
pub const TUNNEL_MEDIUM_TYPE_E_164_NSAP: TunnelMediumType = 15;

pub type TunnelType = u32;
pub const TUNNEL_TYPE_PPTP: TunnelType = 1;
pub const TUNNEL_TYPE_L2F: TunnelType = 2;
pub const TUNNEL_TYPE_L2TP: TunnelType = 3;
pub const TUNNEL_TYPE_ATMP: TunnelType = 4;
pub const TUNNEL_TYPE_VTP: TunnelType = 5;
pub const TUNNEL_TYPE_AH: TunnelType = 6;
pub const TUNNEL_TYPE_IP: TunnelType = 7;
pub const TUNNEL_TYPE_MIN_IP: TunnelType = 8;
pub const TUNNEL_TYPE_ESP: TunnelType = 9;
pub const TUNNEL_TYPE_GRE: TunnelType = 10;
pub const TUNNEL_TYPE_DVS: TunnelType = 11;
pub const TUNNEL_TYPE_IP_IN_IP: TunnelType = 12;