rama_haproxy/protocol/
ip.rs

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
//! Models for storing IP v4 and v6 addresses and ports.

use std::net::{Ipv4Addr, Ipv6Addr};

/// The source and destination IPv4 addresses and TCP ports of a header.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct IPv4 {
    /// The source IPv4 address.
    pub source_address: Ipv4Addr,
    /// The source TCP/UDP port.
    pub source_port: u16,
    /// The destination IPv4 address.
    pub destination_address: Ipv4Addr,
    /// The destination TCP/UDP port.
    pub destination_port: u16,
}

impl IPv4 {
    /// Create a new IPv4 addresses.
    pub fn new<T: Into<Ipv4Addr>>(
        source_address: T,
        destination_address: T,
        source_port: u16,
        destination_port: u16,
    ) -> Self {
        IPv4 {
            source_address: source_address.into(),
            source_port,
            destination_address: destination_address.into(),
            destination_port,
        }
    }
}
/// The source and destination IPv6 addresses and TCP ports of a header.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct IPv6 {
    /// The source IPv6 address.
    pub source_address: Ipv6Addr,
    /// The source TCP/UDP port.
    pub source_port: u16,
    /// The destination IPv6 address.
    pub destination_address: Ipv6Addr,
    /// The destination TCP/UDP port.
    pub destination_port: u16,
}

impl IPv6 {
    /// Create a new IPv6 addresses.
    pub fn new<T: Into<Ipv6Addr>>(
        source_address: T,
        destination_address: T,
        source_port: u16,
        destination_port: u16,
    ) -> Self {
        IPv6 {
            source_address: source_address.into(),
            source_port,
            destination_address: destination_address.into(),
            destination_port,
        }
    }
}