Skip to main content

vpp_plugin/
bindings.rs

1// Allow all sorts of warnings triggered by bindgen-generated code
2#![allow(
3    clippy::all,
4    clippy::undocumented_unsafe_blocks,
5    missing_docs,
6    non_camel_case_types,
7    non_upper_case_globals,
8    non_snake_case,
9    improper_ctypes,
10    unreachable_pub,
11    unsafe_op_in_unsafe_fn,
12    missing_copy_implementations
13)]
14
15//! Bindings to VPP's C API
16//!
17//! These are low-level bindings to VPP's C API and are primarily intended for internal use by
18//! higher-level abstractions in this crate. Direct use of these bindings is generally discouraged
19//! unless absolutely necessary, as they are unsafe and do not provide any safety guarantees.
20//!
21//! This isn't intended to be a complete set of bindings to all of VPP's C API, only the parts that are
22//! necessary for implementing the higher-level abstractions in this crate. They should be
23//! considered an unstable part of the API and, as such, bindings may be removed over time without
24//! incrementing the major version number or prior deprecation.
25//!
26//! Note that these bindings may vary between VPP versions and targets, and care should be taken
27//! to ensure compatibility when using them directly.
28
29#[cfg(all(pregenerated_bindings, target_arch = "x86_64", target_os = "linux"))]
30include!(concat!(
31    env!("CARGO_MANIFEST_DIR"),
32    "/src/bindings/x86_64-unknown-linux-gnu.rs"
33));
34
35#[cfg(not(pregenerated_bindings))]
36include!(concat!(env!("OUT_DIR"), "/vlib_bindings.rs"));
37
38// bindgen generates duplicate definitions for these types due to forward declarations in vlib/trace.h, so we blocklist them and declare them manually here
39
40#[repr(C)]
41#[derive(Debug, Copy, Clone)]
42pub struct vlib_trace_main_t {
43    pub trace_buffer_pool: *mut *mut vlib_trace_header_t,
44    pub last_main_loop_count: u32_,
45    pub filter_node_index: u32_,
46    pub filter_flag: u32_,
47    pub filter_count: u32_,
48    pub trace_enable: u32_,
49    pub nodes: *mut vlib_trace_node_t,
50    pub verbose: ::std::os::raw::c_int,
51    pub trace_buffer_callback: vlib_trace_buffer_callback_t,
52    pub add_trace_callback: vlib_add_trace_callback_t,
53    pub current_trace_filter_function: vlib_is_packet_traced_fn_t,
54}
55
56#[repr(C)]
57#[repr(align(64))]
58#[derive(Copy, Clone)]
59pub struct vlib_buffer_t {
60    pub cacheline0: __BindgenUnionField<[u8_; 0usize]>,
61    pub __bindgen_anon_1: __BindgenUnionField<vlib_buffer_t__bindgen_ty_1>,
62    pub bindgen_union_field: [u8; 256usize],
63}
64
65impl Default for vlib_buffer_t {
66    fn default() -> Self {
67        let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
68        unsafe {
69            ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
70            s.assume_init()
71        }
72    }
73}
74
75// bindgen generates duplicate definitions for these types due to forward declarations in vnet/interface.h, so we blocklist them and declare them manually here
76
77#[repr(C)]
78#[derive(Copy, Clone)]
79pub struct vnet_sw_interface_t {
80    pub _bitfield_align_1: [u16; 0],
81    pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>,
82    pub flags: vnet_sw_interface_flags_t,
83    pub sw_if_index: u32_,
84    pub sup_sw_if_index: u32_,
85    pub unnumbered_sw_if_index: u32_,
86    pub hw_if_index: u32_,
87    pub mtu: [u32_; 4usize],
88    pub sub: vnet_sub_interface_t,
89    pub p2p: vnet_p2p_sub_interface_t,
90    pub flood_class: vnet_flood_class_t,
91}
92#[allow(clippy::unnecessary_operation, clippy::identity_op)]
93const _: () = {
94    ["Size of vnet_sw_interface_t"][::std::mem::size_of::<vnet_sw_interface_t>() - 68usize];
95    ["Alignment of vnet_sw_interface_t"][::std::mem::align_of::<vnet_sw_interface_t>() - 4usize];
96    ["Offset of field: vnet_sw_interface_t::flags"]
97        [::std::mem::offset_of!(vnet_sw_interface_t, flags) - 2usize];
98    ["Offset of field: vnet_sw_interface_t::sw_if_index"]
99        [::std::mem::offset_of!(vnet_sw_interface_t, sw_if_index) - 4usize];
100    ["Offset of field: vnet_sw_interface_t::sup_sw_if_index"]
101        [::std::mem::offset_of!(vnet_sw_interface_t, sup_sw_if_index) - 8usize];
102    ["Offset of field: vnet_sw_interface_t::unnumbered_sw_if_index"]
103        [::std::mem::offset_of!(vnet_sw_interface_t, unnumbered_sw_if_index) - 12usize];
104    ["Offset of field: vnet_sw_interface_t::hw_if_index"]
105        [::std::mem::offset_of!(vnet_sw_interface_t, hw_if_index) - 16usize];
106    ["Offset of field: vnet_sw_interface_t::mtu"]
107        [::std::mem::offset_of!(vnet_sw_interface_t, mtu) - 20usize];
108    ["Offset of field: vnet_sw_interface_t::sub"]
109        [::std::mem::offset_of!(vnet_sw_interface_t, sub) - 36usize];
110    ["Offset of field: vnet_sw_interface_t::p2p"]
111        [::std::mem::offset_of!(vnet_sw_interface_t, p2p) - 48usize];
112    ["Offset of field: vnet_sw_interface_t::flood_class"]
113        [::std::mem::offset_of!(vnet_sw_interface_t, flood_class) - 64usize];
114};
115impl Default for vnet_sw_interface_t {
116    fn default() -> Self {
117        let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
118        unsafe {
119            ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
120            s.assume_init()
121        }
122    }
123}
124impl vnet_sw_interface_t {
125    #[inline]
126    pub fn type_(&self) -> vnet_sw_interface_type_t {
127        unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 16u8) as u32) }
128    }
129    #[inline]
130    pub fn set_type(&mut self, val: vnet_sw_interface_type_t) {
131        unsafe {
132            let val: u32 = ::std::mem::transmute(val);
133            self._bitfield_1.set(0usize, 16u8, val as u64)
134        }
135    }
136    #[inline]
137    pub unsafe fn type__raw(this: *const Self) -> vnet_sw_interface_type_t {
138        unsafe {
139            ::std::mem::transmute(<__BindgenBitfieldUnit<[u8; 2usize]>>::raw_get(
140                ::std::ptr::addr_of!((*this)._bitfield_1),
141                0usize,
142                16u8,
143            ) as u32)
144        }
145    }
146    #[inline]
147    pub unsafe fn set_type_raw(this: *mut Self, val: vnet_sw_interface_type_t) {
148        unsafe {
149            let val: u32 = ::std::mem::transmute(val);
150            <__BindgenBitfieldUnit<[u8; 2usize]>>::raw_set(
151                ::std::ptr::addr_of_mut!((*this)._bitfield_1),
152                0usize,
153                16u8,
154                val as u64,
155            )
156        }
157    }
158    #[inline]
159    pub fn new_bitfield_1(type_: vnet_sw_interface_type_t) -> __BindgenBitfieldUnit<[u8; 2usize]> {
160        let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = Default::default();
161        __bindgen_bitfield_unit.set(0usize, 16u8, {
162            let type_: u32 = unsafe { ::std::mem::transmute(type_) };
163            type_ as u64
164        });
165        __bindgen_bitfield_unit
166    }
167}
168
169// Avoid bindgen-generated code causing this to have an alignment of 8 instead of 1
170
171#[repr(C)]
172#[repr(packed)]
173#[derive(Copy, Clone)]
174pub union ip6_address_t {
175    pub as_u8: [u8_; 16usize],
176    //    pub as_u16: [u16_; 8usize],
177    //    pub as_u32: [u32_; 4usize],
178    //    pub as_u64: [u64_; 2usize],
179    //    pub as_u128: u64x2,
180    //    pub as_uword: [uword; 2usize],
181}
182#[allow(clippy::unnecessary_operation, clippy::identity_op)]
183const _: () = {
184    ["Size of ip6_address_t"][::std::mem::size_of::<ip6_address_t>() - 16usize];
185    ["Alignment of ip6_address_t"][::std::mem::align_of::<ip6_address_t>() - 1usize];
186    ["Offset of field: ip6_address_t::as_u8"]
187        [::std::mem::offset_of!(ip6_address_t, as_u8) - 0usize];
188    // ["Offset of field: ip6_address_t::as_u16"]
189    //     [::std::mem::offset_of!(ip6_address_t, as_u16) - 0usize];
190    // ["Offset of field: ip6_address_t::as_u32"]
191    //     [::std::mem::offset_of!(ip6_address_t, as_u32) - 0usize];
192    // ["Offset of field: ip6_address_t::as_u64"]
193    //     [::std::mem::offset_of!(ip6_address_t, as_u64) - 0usize];
194    // ["Offset of field: ip6_address_t::as_u128"]
195    //     [::std::mem::offset_of!(ip6_address_t, as_u128) - 0usize];
196    // ["Offset of field: ip6_address_t::as_uword"]
197    //     [::std::mem::offset_of!(ip6_address_t, as_uword) - 0usize];
198};
199impl Default for ip6_address_t {
200    fn default() -> Self {
201        let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
202        unsafe {
203            ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
204            s.assume_init()
205        }
206    }
207}
208
209impl<const N: usize> _vlib_node_registration<[*mut ::std::os::raw::c_char; N]> {
210    pub const fn new() -> Self {
211        let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
212        unsafe {
213            ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
214            s.assume_init()
215        }
216    }
217}
218
219impl vlib_cli_command_t {
220    pub const fn new() -> Self {
221        let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
222        unsafe {
223            ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
224            s.assume_init()
225        }
226    }
227}
228
229impl vnet_feature_registration_t {
230    pub const fn new() -> Self {
231        let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
232        unsafe {
233            ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
234            s.assume_init()
235        }
236    }
237}
238
239impl vlib_plugin_registration_t {
240    pub const fn new() -> Self {
241        let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
242        unsafe {
243            ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
244            s.assume_init()
245        }
246    }
247}