Skip to content

Commit

Permalink
Add RTF_*, RTA_*, RTAX_*, RTM_* definitions on BSDs
Browse files Browse the repository at this point in the history
* Unify RTM_ADD and friends under bsd namespace
* Keeps RTAX_MAX as it is used to loop over alternate internal encoding.
  • Loading branch information
tesuji committed Sep 4, 2024
1 parent 72c4000 commit c57486c
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 37 deletions.
25 changes: 25 additions & 0 deletions libc-test/semver/dragonfly.txt
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,31 @@ RLIMIT_STACK
RLIMIT_VMEM
RLIM_INFINITY
RLIM_NLIMITS
RTF_XRESOLVE
RTF_LLINFO
RTF_PROTO3
RTF_PINNED
RTF_LOCAL
RTF_BROADCAST
RTF_MULTICAST
RTM_LOCK
RTM_RESOLVE
RTM_NEWADDR
RTM_DELADDR
RTM_IFINFO
RTM_NEWMADDR
RTM_DELMADDR
RTM_IFANNOUNCE
RTM_IEEE80211
RTF_CLONING
RTF_PRCLONING
RTF_WASCLONED
RTF_MPLSOPS
RTM_VERSION
RTAX_MPLS1
RTAX_MPLS2
RTAX_MPLS3
RTAX_MAX
RTLD_NEXT
RTLD_NODELETE
RTLD_NOLOAD
Expand Down
20 changes: 20 additions & 0 deletions libc-test/semver/freebsd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,26 @@ RLIMIT_UMTXP
RLIMIT_VMEM
RLIM_INFINITY
RLIM_NLIMITS
RTF_XRESOLVE
RTF_LLINFO
RTF_PROTO3
RTF_PINNED
RTF_LOCAL
RTF_BROADCAST
RTF_MULTICAST
RTM_LOCK
RTM_RESOLVE
RTM_NEWADDR
RTM_DELADDR
RTM_IFINFO
RTM_NEWMADDR
RTM_DELMADDR
RTM_IFANNOUNCE
RTM_IEEE80211
RTF_LLDATA
RTF_FIXEDMTU
RTM_VERSION
RTAX_MAX
RTLD_NEXT
RTLD_NODELETE
RTLD_NOLOAD
Expand Down
22 changes: 22 additions & 0 deletions libc-test/semver/netbsd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,28 @@ RLIM_INFINITY
RLIM_NLIMITS
RLIM_SAVED_CUR
RLIM_SAVED_MAX
RTF_MASK
RTF_CONNECTED
RTF_ANNOUNCE
RTF_SRC
RTF_LOCAL
RTF_BROADCAST
RTF_UPDATING
RTF_DONTCHANGEIFA
RTM_VERSION
RTM_LOCK
RTM_IFANNOUNCE
RTM_IEEE80211
RTM_SETGATE
RTM_LLINFO_UPD
RTM_IFINFO
RTM_OCHGADDR
RTM_NEWADDR
RTM_DELADDR
RTM_CHGADDR
RTA_TAG
RTAX_TAG
RTAX_MAX
RTLD_NEXT
RTLD_NOLOAD
RTLD_SELF
Expand Down
42 changes: 42 additions & 0 deletions libc-test/semver/openbsd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,50 @@ RLIM_INFINITY
RLIM_NLIMITS
RLIM_SAVED_CUR
RLIM_SAVED_MAX
RTA_BFD
RTA_DNS
RTA_LABEL
RTA_SEARCH
RTA_SRC
RTA_SRCMASK
RTA_STATIC
RTAX_BFD
RTAX_DNS
RTAX_LABEL
RTAX_MAX
RTAX_SEARCH
RTAX_SRC
RTAX_SRCMASK
RTAX_STATIC
RTF_ANNOUNCE
RTF_BFD
RTF_BROADCAST
RTF_CACHED
RTF_CLONED
RTF_CLONING
RTF_CONNECTED
RTF_FMASK
RTF_LLINFO
RTF_LOCAL
RTF_MPATH
RTF_MPLS
RTF_MULTICAST
RTF_PROTO3
RTLD_NEXT
RTLD_SELF
RTM_80211INFO
RTM_BFD
RTM_CHGADDRATTR
RTM_DELADDR
RTM_DESYNC
RTM_IFANNOUNCE
RTM_IFINFO
RTM_INVALIDATE
RTM_NEWADDR
RTM_PROPOSAL
RTM_RESOLVE
RTM_SOURCE
RTM_VERSION
RUSAGE_CHILDREN
RUSAGE_SELF
RUSAGE_THREAD
Expand Down
37 changes: 0 additions & 37 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4893,22 +4893,11 @@ pub const XATTR_SHOWCOMPRESSION: ::c_int = 0x0020;
pub const NET_RT_IFLIST2: ::c_int = 0x0006;

// net/route.h
pub const RTF_UP: ::c_int = 0x1;
pub const RTF_GATEWAY: ::c_int = 0x2;
pub const RTF_HOST: ::c_int = 0x4;
pub const RTF_REJECT: ::c_int = 0x8;
pub const RTF_DYNAMIC: ::c_int = 0x10;
pub const RTF_MODIFIED: ::c_int = 0x20;
pub const RTF_DONE: ::c_int = 0x40;
pub const RTF_DELCLONE: ::c_int = 0x80;
pub const RTF_CLONING: ::c_int = 0x100;
pub const RTF_XRESOLVE: ::c_int = 0x200;
pub const RTF_LLINFO: ::c_int = 0x400;
pub const RTF_STATIC: ::c_int = 0x800;
pub const RTF_BLACKHOLE: ::c_int = 0x1000;
pub const RTF_NOIFREF: ::c_int = 0x2000;
pub const RTF_PROTO2: ::c_int = 0x4000;
pub const RTF_PROTO1: ::c_int = 0x8000;
pub const RTF_PRCLONING: ::c_int = 0x10000;
pub const RTF_WASCLONED: ::c_int = 0x20000;
pub const RTF_PROTO3: ::c_int = 0x40000;
Expand All @@ -4927,13 +4916,6 @@ pub const RTF_GLOBAL: ::c_int = 0x40000000;
pub const RTM_VERSION: ::c_int = 5;

// Message types
pub const RTM_ADD: ::c_int = 0x1;
pub const RTM_DELETE: ::c_int = 0x2;
pub const RTM_CHANGE: ::c_int = 0x3;
pub const RTM_GET: ::c_int = 0x4;
pub const RTM_LOSING: ::c_int = 0x5;
pub const RTM_REDIRECT: ::c_int = 0x6;
pub const RTM_MISS: ::c_int = 0x7;
pub const RTM_LOCK: ::c_int = 0x8;
pub const RTM_OLDADD: ::c_int = 0x9;
pub const RTM_OLDDEL: ::c_int = 0xa;
Expand All @@ -4957,25 +4939,6 @@ pub const RTV_SSTHRESH: ::c_int = 0x20;
pub const RTV_RTT: ::c_int = 0x40;
pub const RTV_RTTVAR: ::c_int = 0x80;

// Bitmask values for rtm_addrs.
pub const RTA_DST: ::c_int = 0x1;
pub const RTA_GATEWAY: ::c_int = 0x2;
pub const RTA_NETMASK: ::c_int = 0x4;
pub const RTA_GENMASK: ::c_int = 0x8;
pub const RTA_IFP: ::c_int = 0x10;
pub const RTA_IFA: ::c_int = 0x20;
pub const RTA_AUTHOR: ::c_int = 0x40;
pub const RTA_BRD: ::c_int = 0x80;

// Index offsets for sockaddr array for alternate internal encoding.
pub const RTAX_DST: ::c_int = 0;
pub const RTAX_GATEWAY: ::c_int = 1;
pub const RTAX_NETMASK: ::c_int = 2;
pub const RTAX_GENMASK: ::c_int = 3;
pub const RTAX_IFP: ::c_int = 4;
pub const RTAX_IFA: ::c_int = 5;
pub const RTAX_AUTHOR: ::c_int = 6;
pub const RTAX_BRD: ::c_int = 7;
pub const RTAX_MAX: ::c_int = 8;

pub const KERN_PROCARGS2: ::c_int = 49;
Expand Down
13 changes: 13 additions & 0 deletions src/unix/bsd/freebsdlike/dragonfly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1522,6 +1522,19 @@ pub const NGROUPS: usize = 16;
pub const RB_PAUSE: ::c_int = 0x40000;
pub const RB_VIDEO: ::c_int = 0x20000000;

// net/route.h
pub const RTF_CLONING: ::c_int = 0x100;
pub const RTF_PRCLONING: ::c_int = 0x10000;
pub const RTF_WASCLONED: ::c_int = 0x20000;
pub const RTF_MPLSOPS: ::c_int = 0x1000000;

pub const RTM_VERSION: ::c_int = 7;

pub const RTAX_MPLS1: ::c_int = 8;
pub const RTAX_MPLS2: ::c_int = 9;
pub const RTAX_MPLS3: ::c_int = 10;
pub const RTAX_MAX: ::c_int = 11;

const_fn! {
{const} fn _CMSG_ALIGN(n: usize) -> usize {
(n + (::mem::size_of::<::c_long>() - 1)) & !(::mem::size_of::<::c_long>() - 1)
Expand Down
8 changes: 8 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4677,6 +4677,14 @@ pub const CPU_WHICH_CPUSET: ::c_int = 3;
pub const CPU_WHICH_IRQ: ::c_int = 4;
pub const CPU_WHICH_JAIL: ::c_int = 5;

// net/route.h
pub const RTF_LLDATA: ::c_int = 0x400;
pub const RTF_FIXEDMTU: ::c_int = 0x80000;

pub const RTM_VERSION: ::c_int = 5;

pub const RTAX_MAX: ::c_int = 8;

// sys/signal.h
pub const SIGTHR: ::c_int = 32;
pub const SIGLWP: ::c_int = SIGTHR;
Expand Down
19 changes: 19 additions & 0 deletions src/unix/bsd/freebsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,25 @@ pub const SO_TYPE: ::c_int = 0x1008;

pub const LOCAL_PEERCRED: ::c_int = 1;

// net/route.h
pub const RTF_XRESOLVE: ::c_int = 0x200;
pub const RTF_LLINFO: ::c_int = 0x400;
pub const RTF_PROTO3: ::c_int = 0x40000;
pub const RTF_PINNED: ::c_int = 0x100000;
pub const RTF_LOCAL: ::c_int = 0x200000;
pub const RTF_BROADCAST: ::c_int = 0x400000;
pub const RTF_MULTICAST: ::c_int = 0x800000;

pub const RTM_LOCK: ::c_int = 0x8;
pub const RTM_RESOLVE: ::c_int = 0xb;
pub const RTM_NEWADDR: ::c_int = 0xc;
pub const RTM_DELADDR: ::c_int = 0xd;
pub const RTM_IFINFO: ::c_int = 0xe;
pub const RTM_NEWMADDR: ::c_int = 0xf;
pub const RTM_DELMADDR: ::c_int = 0x10;
pub const RTM_IFANNOUNCE: ::c_int = 0x11;
pub const RTM_IEEE80211: ::c_int = 0x12;

pub const SHUT_RD: ::c_int = 0;
pub const SHUT_WR: ::c_int = 1;
pub const SHUT_RDWR: ::c_int = 2;
Expand Down
43 changes: 43 additions & 0 deletions src/unix/bsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,49 @@ pub const ITIMER_REAL: ::c_int = 0;
pub const ITIMER_VIRTUAL: ::c_int = 1;
pub const ITIMER_PROF: ::c_int = 2;

// net/route.h

pub const RTF_UP: ::c_int = 0x1;
pub const RTF_GATEWAY: ::c_int = 0x2;
pub const RTF_HOST: ::c_int = 0x4;
pub const RTF_REJECT: ::c_int = 0x8;
pub const RTF_DYNAMIC: ::c_int = 0x10;
pub const RTF_MODIFIED: ::c_int = 0x20;
pub const RTF_DONE: ::c_int = 0x40;
pub const RTF_STATIC: ::c_int = 0x800;
pub const RTF_BLACKHOLE: ::c_int = 0x1000;
pub const RTF_PROTO2: ::c_int = 0x4000;
pub const RTF_PROTO1: ::c_int = 0x8000;

// Message types
pub const RTM_ADD: ::c_int = 0x1;
pub const RTM_DELETE: ::c_int = 0x2;
pub const RTM_CHANGE: ::c_int = 0x3;
pub const RTM_GET: ::c_int = 0x4;
pub const RTM_LOSING: ::c_int = 0x5;
pub const RTM_REDIRECT: ::c_int = 0x6;
pub const RTM_MISS: ::c_int = 0x7;

// Bitmask values for rtm_addrs.
pub const RTA_DST: ::c_int = 0x1;
pub const RTA_GATEWAY: ::c_int = 0x2;
pub const RTA_NETMASK: ::c_int = 0x4;
pub const RTA_GENMASK: ::c_int = 0x8;
pub const RTA_IFP: ::c_int = 0x10;
pub const RTA_IFA: ::c_int = 0x20;
pub const RTA_AUTHOR: ::c_int = 0x40;
pub const RTA_BRD: ::c_int = 0x80;

// Index offsets for sockaddr array for alternate internal encoding.
pub const RTAX_DST: ::c_int = 0;
pub const RTAX_GATEWAY: ::c_int = 1;
pub const RTAX_NETMASK: ::c_int = 2;
pub const RTAX_GENMASK: ::c_int = 3;
pub const RTAX_IFP: ::c_int = 4;
pub const RTAX_IFA: ::c_int = 5;
pub const RTAX_AUTHOR: ::c_int = 6;
pub const RTAX_BRD: ::c_int = 7;

f! {
pub fn CMSG_FIRSTHDR(mhdr: *const ::msghdr) -> *mut ::cmsghdr {
if (*mhdr).msg_controllen as usize >= ::mem::size_of::<::cmsghdr>() {
Expand Down
27 changes: 27 additions & 0 deletions src/unix/bsd/netbsdlike/netbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2400,6 +2400,33 @@ pub const fn MAP_ALIGNED(alignment: ::c_int) -> ::c_int {
alignment << MAP_ALIGNMENT_SHIFT
}

// net/route.h
pub const RTF_MASK: ::c_int = 0x80;
pub const RTF_CONNECTED: ::c_int = 0x100;
pub const RTF_ANNOUNCE: ::c_int = 0x20000;
pub const RTF_SRC: ::c_int = 0x10000;
pub const RTF_LOCAL: ::c_int = 0x40000;
pub const RTF_BROADCAST: ::c_int = 0x80000;
pub const RTF_UPDATING: ::c_int = 0x100000;
pub const RTF_DONTCHANGEIFA: ::c_int = 0x200000;

pub const RTM_VERSION: ::c_int = 4;
pub const RTM_LOCK: ::c_int = 0x8;
pub const RTM_IFANNOUNCE: ::c_int = 0x10;
pub const RTM_IEEE80211: ::c_int = 0x11;
pub const RTM_SETGATE: ::c_int = 0x12;
pub const RTM_LLINFO_UPD: ::c_int = 0x13;
pub const RTM_IFINFO: ::c_int = 0x14;
pub const RTM_OCHGADDR: ::c_int = 0x15;
pub const RTM_NEWADDR: ::c_int = 0x16;
pub const RTM_DELADDR: ::c_int = 0x17;
pub const RTM_CHGADDR: ::c_int = 0x18;

pub const RTA_TAG: ::c_int = 0x100;

pub const RTAX_TAG: ::c_int = 8;
pub const RTAX_MAX: ::c_int = 9;

const_fn! {
{const} fn _ALIGN(p: usize) -> usize {
(p + _ALIGNBYTES) & !_ALIGNBYTES
Expand Down
Loading

0 comments on commit c57486c

Please sign in to comment.