2021-12-13 22:21:06 +00:00
|
|
|
#!/usr/bin/env bash
|
2022-09-13 17:55:17 +00:00
|
|
|
# Copyright 2022 The ChromiumOS Authors
|
2021-12-13 22:21:06 +00:00
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
2022-09-13 19:37:28 +00:00
|
|
|
|
2021-12-13 22:21:06 +00:00
|
|
|
# Regenerate net_sys bindgen bindings.
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")/.."
|
|
|
|
|
|
|
|
source tools/impl/bindgen-common.sh
|
|
|
|
|
|
|
|
# Replace definition of struct sockaddr with an import of libc::sockaddr.
|
|
|
|
replace_sockaddr_libc() {
|
|
|
|
# Match the following structure definition across multiple lines:
|
|
|
|
#
|
|
|
|
# #[repr(C)]
|
|
|
|
# #[derive(Debug, Default, Copy, Clone)]
|
|
|
|
# pub struct sockaddr {
|
|
|
|
# pub sa_family: sa_family_t,
|
|
|
|
# pub sa_data: [::std::os::raw::c_char; 14usize],
|
|
|
|
# }
|
|
|
|
sed -E \
|
|
|
|
-e '1h;2,$H;$!d;g' \
|
|
|
|
-e 's/#\[repr\(C\)\]\n#\[derive\([^)]+\)\]\npub struct sockaddr \{\n( pub [^\n]+\n)+\}/\nuse libc::sockaddr;\n/'
|
|
|
|
}
|
|
|
|
|
|
|
|
# Remove custom sa_family_t type in favor of libc::sa_family_t.
|
|
|
|
remove_sa_family_t() {
|
|
|
|
grep -v "pub type sa_family_t = "
|
|
|
|
}
|
|
|
|
|
|
|
|
bindgen_generate \
|
|
|
|
--allowlist-type='ifreq' \
|
|
|
|
--allowlist-type='net_device_flags' \
|
|
|
|
--bitfield-enum='net_device_flags' \
|
|
|
|
"${BINDGEN_LINUX_X86_HEADERS}/include/linux/if.h" \
|
|
|
|
| replace_linux_int_types \
|
|
|
|
| replace_sockaddr_libc \
|
|
|
|
| remove_sa_family_t \
|
|
|
|
| rustfmt \
|
|
|
|
> net_sys/src/iff.rs
|
|
|
|
|
|
|
|
bindgen_generate \
|
|
|
|
--allowlist-type='sock_fprog' \
|
|
|
|
--allowlist-var='TUN_.*' \
|
2022-04-27 04:07:46 +00:00
|
|
|
--allowlist-var='IFF_NO_PI' \
|
|
|
|
--allowlist-var='IFF_MULTI_QUEUE' \
|
|
|
|
--allowlist-var='IFF_TAP' \
|
|
|
|
--allowlist-var='IFF_VNET_HDR' \
|
2021-12-13 22:21:06 +00:00
|
|
|
"${BINDGEN_LINUX}/include/uapi/linux/if_tun.h" \
|
|
|
|
| replace_linux_int_types \
|
|
|
|
> net_sys/src/if_tun.rs
|
|
|
|
|
|
|
|
bindgen_generate \
|
|
|
|
--allowlist-var='SIOC.*' \
|
|
|
|
"${BINDGEN_LINUX}/include/uapi/linux/sockios.h" \
|
|
|
|
| replace_linux_int_types \
|
|
|
|
> net_sys/src/sockios.rs
|