1use crate::ffi;
7#[cfg(feature = "v1_18")]
8#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
9use glib::translate::*;
10
11glib::wrapper! {
12 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
13 pub struct IPRoutingRule(Shared<ffi::NMIPRoutingRule>);
14
15 match fn {
16 ref => |ptr| ffi::nm_ip_routing_rule_ref(ptr),
17 unref => |ptr| ffi::nm_ip_routing_rule_unref(ptr),
18 type_ => || ffi::nm_ip_routing_rule_get_type(),
19 }
20}
21
22impl IPRoutingRule {
23 #[cfg(feature = "v1_18")]
32 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
33 #[doc(alias = "nm_ip_routing_rule_new")]
34 pub fn new(addr_family: i32) -> IPRoutingRule {
35 assert_initialized_main_thread!();
36 unsafe { from_glib_full(ffi::nm_ip_routing_rule_new(addr_family)) }
37 }
38
39 #[cfg(feature = "v1_18")]
47 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
48 #[doc(alias = "nm_ip_routing_rule_cmp")]
49 pub fn cmp(&self, other: Option<&IPRoutingRule>) -> i32 {
50 unsafe { ffi::nm_ip_routing_rule_cmp(self.to_glib_none().0, other.to_glib_none().0) }
51 }
52
53 #[cfg(feature = "v1_18")]
58 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
59 #[doc(alias = "nm_ip_routing_rule_get_action")]
60 #[doc(alias = "get_action")]
61 pub fn action(&self) -> u8 {
62 unsafe { ffi::nm_ip_routing_rule_get_action(self.to_glib_none().0) }
63 }
64
65 #[cfg(feature = "v1_18")]
70 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
71 #[doc(alias = "nm_ip_routing_rule_get_addr_family")]
72 #[doc(alias = "get_addr_family")]
73 pub fn addr_family(&self) -> i32 {
74 unsafe { ffi::nm_ip_routing_rule_get_addr_family(self.to_glib_none().0) }
75 }
76
77 #[cfg(feature = "v1_18")]
82 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
83 #[doc(alias = "nm_ip_routing_rule_get_destination_port_end")]
84 #[doc(alias = "get_destination_port_end")]
85 pub fn destination_port_end(&self) -> u16 {
86 unsafe { ffi::nm_ip_routing_rule_get_destination_port_end(self.to_glib_none().0) }
87 }
88
89 #[cfg(feature = "v1_18")]
94 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
95 #[doc(alias = "nm_ip_routing_rule_get_destination_port_start")]
96 #[doc(alias = "get_destination_port_start")]
97 pub fn destination_port_start(&self) -> u16 {
98 unsafe { ffi::nm_ip_routing_rule_get_destination_port_start(self.to_glib_none().0) }
99 }
100
101 #[cfg(feature = "v1_18")]
107 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
108 #[doc(alias = "nm_ip_routing_rule_get_from")]
109 #[doc(alias = "get_from")]
110 pub fn from(&self) -> glib::GString {
111 unsafe { from_glib_none(ffi::nm_ip_routing_rule_get_from(self.to_glib_none().0)) }
112 }
113
114 #[cfg(feature = "v1_18")]
119 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
120 #[doc(alias = "nm_ip_routing_rule_get_from_len")]
121 #[doc(alias = "get_from_len")]
122 pub fn from_len(&self) -> u8 {
123 unsafe { ffi::nm_ip_routing_rule_get_from_len(self.to_glib_none().0) }
124 }
125
126 #[cfg(feature = "v1_18")]
131 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
132 #[doc(alias = "nm_ip_routing_rule_get_fwmark")]
133 #[doc(alias = "get_fwmark")]
134 pub fn fwmark(&self) -> u32 {
135 unsafe { ffi::nm_ip_routing_rule_get_fwmark(self.to_glib_none().0) }
136 }
137
138 #[cfg(feature = "v1_18")]
143 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
144 #[doc(alias = "nm_ip_routing_rule_get_fwmask")]
145 #[doc(alias = "get_fwmask")]
146 pub fn fwmask(&self) -> u32 {
147 unsafe { ffi::nm_ip_routing_rule_get_fwmask(self.to_glib_none().0) }
148 }
149
150 #[cfg(feature = "v1_18")]
155 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
156 #[doc(alias = "nm_ip_routing_rule_get_iifname")]
157 #[doc(alias = "get_iifname")]
158 pub fn iifname(&self) -> glib::GString {
159 unsafe { from_glib_none(ffi::nm_ip_routing_rule_get_iifname(self.to_glib_none().0)) }
160 }
161
162 #[cfg(feature = "v1_18")]
167 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
168 #[doc(alias = "nm_ip_routing_rule_get_invert")]
169 #[doc(alias = "get_invert")]
170 pub fn inverts(&self) -> bool {
171 unsafe { from_glib(ffi::nm_ip_routing_rule_get_invert(self.to_glib_none().0)) }
172 }
173
174 #[cfg(feature = "v1_18")]
179 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
180 #[doc(alias = "nm_ip_routing_rule_get_ipproto")]
181 #[doc(alias = "get_ipproto")]
182 pub fn ipproto(&self) -> u8 {
183 unsafe { ffi::nm_ip_routing_rule_get_ipproto(self.to_glib_none().0) }
184 }
185
186 #[cfg(feature = "v1_18")]
191 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
192 #[doc(alias = "nm_ip_routing_rule_get_oifname")]
193 #[doc(alias = "get_oifname")]
194 pub fn oifname(&self) -> glib::GString {
195 unsafe { from_glib_none(ffi::nm_ip_routing_rule_get_oifname(self.to_glib_none().0)) }
196 }
197
198 #[cfg(feature = "v1_18")]
204 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
205 #[doc(alias = "nm_ip_routing_rule_get_priority")]
206 #[doc(alias = "get_priority")]
207 pub fn priority(&self) -> i64 {
208 unsafe { ffi::nm_ip_routing_rule_get_priority(self.to_glib_none().0) }
209 }
210
211 #[cfg(feature = "v1_18")]
216 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
217 #[doc(alias = "nm_ip_routing_rule_get_source_port_end")]
218 #[doc(alias = "get_source_port_end")]
219 pub fn source_port_end(&self) -> u16 {
220 unsafe { ffi::nm_ip_routing_rule_get_source_port_end(self.to_glib_none().0) }
221 }
222
223 #[cfg(feature = "v1_18")]
228 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
229 #[doc(alias = "nm_ip_routing_rule_get_source_port_start")]
230 #[doc(alias = "get_source_port_start")]
231 pub fn source_port_start(&self) -> u16 {
232 unsafe { ffi::nm_ip_routing_rule_get_source_port_start(self.to_glib_none().0) }
233 }
234
235 #[cfg(feature = "v1_20")]
240 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
241 #[doc(alias = "nm_ip_routing_rule_get_suppress_prefixlength")]
242 #[doc(alias = "get_suppress_prefixlength")]
243 pub fn suppress_prefixlength(&self) -> i32 {
244 unsafe { ffi::nm_ip_routing_rule_get_suppress_prefixlength(self.to_glib_none().0) }
245 }
246
247 #[cfg(feature = "v1_18")]
252 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
253 #[doc(alias = "nm_ip_routing_rule_get_table")]
254 #[doc(alias = "get_table")]
255 pub fn table(&self) -> u32 {
256 unsafe { ffi::nm_ip_routing_rule_get_table(self.to_glib_none().0) }
257 }
258
259 #[cfg(feature = "v1_18")]
265 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
266 #[doc(alias = "nm_ip_routing_rule_get_to")]
267 #[doc(alias = "get_to")]
268 pub fn to(&self) -> glib::GString {
269 unsafe { from_glib_none(ffi::nm_ip_routing_rule_get_to(self.to_glib_none().0)) }
270 }
271
272 #[cfg(feature = "v1_18")]
277 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
278 #[doc(alias = "nm_ip_routing_rule_get_to_len")]
279 #[doc(alias = "get_to_len")]
280 pub fn to_len(&self) -> u8 {
281 unsafe { ffi::nm_ip_routing_rule_get_to_len(self.to_glib_none().0) }
282 }
283
284 #[cfg(feature = "v1_18")]
289 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
290 #[doc(alias = "nm_ip_routing_rule_get_tos")]
291 #[doc(alias = "get_tos")]
292 pub fn tos(&self) -> u8 {
293 unsafe { ffi::nm_ip_routing_rule_get_tos(self.to_glib_none().0) }
294 }
295
296 #[cfg(feature = "v1_34")]
312 #[cfg_attr(docsrs, doc(cfg(feature = "v1_34")))]
313 #[doc(alias = "nm_ip_routing_rule_get_uid_range")]
314 #[doc(alias = "get_uid_range")]
315 pub fn uid_range(&self) -> Option<(u32, u32)> {
316 unsafe {
317 let mut out_range_start = std::mem::MaybeUninit::uninit();
318 let mut out_range_end = std::mem::MaybeUninit::uninit();
319 let ret = from_glib(ffi::nm_ip_routing_rule_get_uid_range(
320 self.to_glib_none().0,
321 out_range_start.as_mut_ptr(),
322 out_range_end.as_mut_ptr(),
323 ));
324 if ret {
325 Some((out_range_start.assume_init(), out_range_end.assume_init()))
326 } else {
327 None
328 }
329 }
330 }
331
332 #[cfg(feature = "v1_18")]
338 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
339 #[doc(alias = "nm_ip_routing_rule_is_sealed")]
340 pub fn is_sealed(&self) -> bool {
341 unsafe { from_glib(ffi::nm_ip_routing_rule_is_sealed(self.to_glib_none().0)) }
342 }
343
344 #[cfg(feature = "v1_18")]
352 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
353 #[doc(alias = "nm_ip_routing_rule_new_clone")]
354 #[must_use]
355 pub fn new_clone(&self) -> IPRoutingRule {
356 unsafe { from_glib_full(ffi::nm_ip_routing_rule_new_clone(self.to_glib_none().0)) }
357 }
358
359 #[cfg(feature = "v1_18")]
363 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
364 #[doc(alias = "nm_ip_routing_rule_seal")]
365 pub fn seal(&self) {
366 unsafe {
367 ffi::nm_ip_routing_rule_seal(self.to_glib_none().0);
368 }
369 }
370
371 #[cfg(feature = "v1_18")]
376 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
377 #[doc(alias = "nm_ip_routing_rule_set_action")]
378 pub fn set_action(&self, action: u8) {
379 unsafe {
380 ffi::nm_ip_routing_rule_set_action(self.to_glib_none().0, action);
381 }
382 }
383
384 #[cfg(feature = "v1_18")]
389 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
390 #[doc(alias = "nm_ip_routing_rule_set_destination_port")]
391 pub fn set_destination_port(&self, start: u16, end: u16) {
392 unsafe {
393 ffi::nm_ip_routing_rule_set_destination_port(self.to_glib_none().0, start, end);
394 }
395 }
396
397 #[cfg(feature = "v1_18")]
405 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
406 #[doc(alias = "nm_ip_routing_rule_set_from")]
407 pub fn set_from(&self, from: Option<&str>) {
408 if let Some(s) = from {
409 let len = s.len() as _;
410 unsafe {
411 ffi::nm_ip_routing_rule_set_from(self.to_glib_none().0, s.to_glib_none().0, len);
412 }
413 }
414 }
415
416 #[cfg(feature = "v1_18")]
421 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
422 #[doc(alias = "nm_ip_routing_rule_set_fwmark")]
423 pub fn set_fwmark(&self, fwmark: u32, fwmask: u32) {
424 unsafe {
425 ffi::nm_ip_routing_rule_set_fwmark(self.to_glib_none().0, fwmark, fwmask);
426 }
427 }
428
429 #[cfg(feature = "v1_18")]
436 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
437 #[doc(alias = "nm_ip_routing_rule_set_iifname")]
438 pub fn set_iifname(&self, iifname: Option<&str>) {
439 unsafe {
440 ffi::nm_ip_routing_rule_set_iifname(self.to_glib_none().0, iifname.to_glib_none().0);
441 }
442 }
443
444 #[cfg(feature = "v1_18")]
447 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
448 #[doc(alias = "nm_ip_routing_rule_set_invert")]
449 pub fn set_invert(&self, invert: bool) {
450 unsafe {
451 ffi::nm_ip_routing_rule_set_invert(self.to_glib_none().0, invert.into_glib());
452 }
453 }
454
455 #[cfg(feature = "v1_18")]
458 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
459 #[doc(alias = "nm_ip_routing_rule_set_ipproto")]
460 pub fn set_ipproto(&self, ipproto: u8) {
461 unsafe {
462 ffi::nm_ip_routing_rule_set_ipproto(self.to_glib_none().0, ipproto);
463 }
464 }
465
466 #[cfg(feature = "v1_18")]
473 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
474 #[doc(alias = "nm_ip_routing_rule_set_oifname")]
475 pub fn set_oifname(&self, oifname: Option<&str>) {
476 unsafe {
477 ffi::nm_ip_routing_rule_set_oifname(self.to_glib_none().0, oifname.to_glib_none().0);
478 }
479 }
480
481 #[cfg(feature = "v1_18")]
487 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
488 #[doc(alias = "nm_ip_routing_rule_set_priority")]
489 pub fn set_priority(&self, priority: i64) {
490 unsafe {
491 ffi::nm_ip_routing_rule_set_priority(self.to_glib_none().0, priority);
492 }
493 }
494
495 #[cfg(feature = "v1_18")]
500 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
501 #[doc(alias = "nm_ip_routing_rule_set_source_port")]
502 pub fn set_source_port(&self, start: u16, end: u16) {
503 unsafe {
504 ffi::nm_ip_routing_rule_set_source_port(self.to_glib_none().0, start, end);
505 }
506 }
507
508 #[cfg(feature = "v1_20")]
512 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
513 #[doc(alias = "nm_ip_routing_rule_set_suppress_prefixlength")]
514 pub fn set_suppress_prefixlength(&self, suppress_prefixlength: i32) {
515 unsafe {
516 ffi::nm_ip_routing_rule_set_suppress_prefixlength(
517 self.to_glib_none().0,
518 suppress_prefixlength,
519 );
520 }
521 }
522
523 #[cfg(feature = "v1_18")]
526 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
527 #[doc(alias = "nm_ip_routing_rule_set_table")]
528 pub fn set_table(&self, table: u32) {
529 unsafe {
530 ffi::nm_ip_routing_rule_set_table(self.to_glib_none().0, table);
531 }
532 }
533
534 #[cfg(feature = "v1_18")]
543 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
544 #[doc(alias = "nm_ip_routing_rule_set_to")]
545 pub fn set_to(&self, to: Option<&str>) {
546 if let Some(s) = to {
547 let len = s.len() as _;
548 unsafe {
549 ffi::nm_ip_routing_rule_set_to(self.to_glib_none().0, s.to_glib_none().0, len);
550 }
551 }
552 }
553
554 #[cfg(feature = "v1_18")]
557 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
558 #[doc(alias = "nm_ip_routing_rule_set_tos")]
559 pub fn set_tos(&self, tos: u8) {
560 unsafe {
561 ffi::nm_ip_routing_rule_set_tos(self.to_glib_none().0, tos);
562 }
563 }
564
565 #[cfg(feature = "v1_34")]
575 #[cfg_attr(docsrs, doc(cfg(feature = "v1_34")))]
576 #[doc(alias = "nm_ip_routing_rule_set_uid_range")]
577 pub fn set_uid_range(&self, uid_range_start: u32, uid_range_end: u32) {
578 unsafe {
579 ffi::nm_ip_routing_rule_set_uid_range(
580 self.to_glib_none().0,
581 uid_range_start,
582 uid_range_end,
583 );
584 }
585 }
586
587 #[cfg(feature = "v1_18")]
599 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
600 #[doc(alias = "nm_ip_routing_rule_validate")]
601 pub fn validate(&self) -> Result<(), glib::Error> {
602 unsafe {
603 let mut error = std::ptr::null_mut();
604 let is_ok = ffi::nm_ip_routing_rule_validate(self.to_glib_none().0, &mut error);
605 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
606 if error.is_null() {
607 Ok(())
608 } else {
609 Err(from_glib_full(error))
610 }
611 }
612 }
613
614 }