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
// SPDX-License-Identifier: MIT
//! ipvs control messages
//!
//! [ipvs (IP Virtual Server)](https://kb.linuxvirtualserver.org/wiki/IPVS) is a Linux kernel module designed for load balancing at Layer 4 (the transport layer).
//!
//! ipvs can distribute incoming TCP and UDP connections across multiple real servers,
//! making a cluster of servers appear as a single virtual service exposed on one IP address.
//! This allows for scalable and highly available network services.
//!
//! ipvs is controllable via the generic netlink interface.
//! The main implementation of ipvs control messages via generic netlink is [ipvsadm](https://git.kernel.org/pub/scm/utils/kernel/ipvsadm/ipvsadm.git)
//!
//! Be carefull, user sending ipvs control messages need to be root or [CAP_NET_ADMIN](https://www.man7.org/linux/man-pages/man7/capabilities.7.html).
//!
//! ## Getting started
//!
//! Here is a simple example getting ipvs informations:
//!
//! ```rust
//! use nlrs::{
//! genetlink::socket::{GenericNetlinkSocket, GenericRequestBuilder},
//! ipvs::{IPVS_FAMILY, info::GetInfoMessageBuilder},
//! socket::NetlinkSocket,
//! };
//!
//! // creating a classic netlink socket
//! let netlink_socket =
//! NetlinkSocket::new_vectored(nlrs::netlink::socket::NlSocketType::NETLINK_GENERIC);
//!
//! if let Ok(netlink_socket) = netlink_socket {
//! // upgrading to a generic netlink socket to send ipvs message
//! let generic_netlink_socket =
//! GenericNetlinkSocket::from_netlink_socket(netlink_socket, IPVS_FAMILY.to_string());
//!
//! if let Ok(mut ipvs_socket) = generic_netlink_socket {
//! // getting ipvs module infos
//! let message_builder: GetInfoMessageBuilder<_> = ipvs_socket.message_builder(());
//!
//! // request can fail (example: user is not allowed to use ipvs)
//! if let Ok(ipvs_infos) = message_builder.call() {
//! println!(
//! "IP Virtual Server version {}.{}.{} (size={})",
//! ipvs_infos.version_major,
//! ipvs_infos.version_minor,
//! ipvs_infos.version_patch,
//! ipvs_infos.connection_table_size
//! );
//! } else {
//! println!("ipvs info request has failed")
//! }
//! }
//! }
//! ```
/// `IPVS`, the generic netlink family name
pub const IPVS_FAMILY: &str = "IPVS";
/// `1`, the generic netlink ipvs protocol version
pub const IPVS_GENL_VERSION: u8 = 1;
/// layer 4 protocol
/// ip address family (ipv4 or ipv6)
/// an ipvs service (frontend)
/// ipvs nested attributes numbers