From 393271185ac0ac9a33dd181adec532bce453673d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= <linus@mullvad.net> Date: Wed, 21 Feb 2018 17:39:49 +0100 Subject: [PATCH] Add NLA_ALIGN(TO) constant/function --- src/unix/notbsd/android/mod.rs | 6 ++++++ src/unix/notbsd/linux/mips/mod.rs | 8 ++++++++ src/unix/notbsd/linux/other/mod.rs | 8 ++++++++ 3 files changed, 22 insertions(+) diff --git a/src/unix/notbsd/android/mod.rs b/src/unix/notbsd/android/mod.rs index b735b366..499c7d95 100644 --- a/src/unix/notbsd/android/mod.rs +++ b/src/unix/notbsd/android/mod.rs @@ -923,6 +923,8 @@ pub const NLA_F_NESTED: ::c_int = 1 << 15; pub const NLA_F_NET_BYTEORDER: ::c_int = 1 << 14; pub const NLA_TYPE_MASK: ::c_int = !(NLA_F_NESTED | NLA_F_NET_BYTEORDER); +pub const NLA_ALIGNTO: ::c_int = 4; + pub const SIGEV_THREAD_ID: ::c_int = 4; pub const CIBAUD: ::tcflag_t = 0o02003600000; @@ -1067,6 +1069,10 @@ f! { let mi = mi as ::dev_t; ((ma & 0xfff) << 8) | (mi & 0xff) | ((mi & 0xfff00) << 12) } + + pub fn NLA_ALIGN(len: ::c_int) -> ::c_int { + return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1) + } } extern { diff --git a/src/unix/notbsd/linux/mips/mod.rs b/src/unix/notbsd/linux/mips/mod.rs index f4bed915..d4093819 100644 --- a/src/unix/notbsd/linux/mips/mod.rs +++ b/src/unix/notbsd/linux/mips/mod.rs @@ -700,6 +700,8 @@ pub const EHWPOISON: ::c_int = 168; pub const SIGEV_THREAD_ID: ::c_int = 4; pub const EPOLLWAKEUP: ::c_int = 0x20000000; +pub const NLA_ALIGNTO: ::c_int = 4; + pub const NFT_TABLE_MAXNAMELEN: ::c_int = 32; pub const NFT_CHAIN_MAXNAMELEN: ::c_int = 32; pub const NFT_SET_MAXNAMELEN: ::c_int = 32; @@ -735,6 +737,12 @@ pub const AF_MAX: ::c_int = 42; #[doc(hidden)] pub const PF_MAX: ::c_int = AF_MAX; +f! { + pub fn NLA_ALIGN(len: ::c_int) -> ::c_int { + return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1) + } +} + #[link(name = "util")] extern { pub fn sysctl(name: *mut ::c_int, diff --git a/src/unix/notbsd/linux/other/mod.rs b/src/unix/notbsd/linux/other/mod.rs index 5fcfa3ad..f9607a7d 100644 --- a/src/unix/notbsd/linux/other/mod.rs +++ b/src/unix/notbsd/linux/other/mod.rs @@ -576,6 +576,8 @@ pub const NLA_F_NESTED: ::c_int = 1 << 15; pub const NLA_F_NET_BYTEORDER: ::c_int = 1 << 14; pub const NLA_TYPE_MASK: ::c_int = !(NLA_F_NESTED | NLA_F_NET_BYTEORDER); +pub const NLA_ALIGNTO: ::c_int = 4; + pub const TIOCM_LE: ::c_int = 0x001; pub const TIOCM_DTR: ::c_int = 0x002; pub const TIOCM_RTS: ::c_int = 0x004; @@ -681,6 +683,12 @@ cfg_if! { } } +f! { + pub fn NLA_ALIGN(len: ::c_int) -> ::c_int { + return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1) + } +} + extern { pub fn utmpxname(file: *const ::c_char) -> ::c_int; pub fn getutxent() -> *mut utmpx; -- GitLab