mirror of
https://github.com/google/nsjail.git
synced 2026-08-30 18:41:30 -07:00
make indent
This commit is contained in:
@@ -108,8 +108,8 @@ static void icmp_destroy_flow(Context* ctx, IcmpFlow* flow) {
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] static bool icmp_send_packet4(Context* ctx, uint32_t saddr, uint32_t daddr, uint8_t type,
|
||||
uint8_t code, uint16_t id, uint16_t seq, const void* data, size_t len) {
|
||||
[[nodiscard]] static bool icmp_send_packet4(Context* ctx, uint32_t saddr, uint32_t daddr,
|
||||
uint8_t type, uint8_t code, uint16_t id, uint16_t seq, const void* data, size_t len) {
|
||||
if (len > NSTUN_MTU) {
|
||||
LOG_W("icmp_send_packet4: data length too large");
|
||||
return false;
|
||||
@@ -160,8 +160,9 @@ static void icmp_destroy_flow(Context* ctx, IcmpFlow* flow) {
|
||||
ctx, &vh, header_buf, sizeof(header_buf), static_cast<const uint8_t*>(data), len);
|
||||
}
|
||||
|
||||
[[nodiscard]] static bool icmp_send_packet6(Context* ctx, const uint8_t* saddr, const uint8_t* daddr,
|
||||
uint8_t type, uint8_t code, uint16_t id, uint16_t seq, const void* data, size_t len) {
|
||||
[[nodiscard]] static bool icmp_send_packet6(Context* ctx, const uint8_t* saddr,
|
||||
const uint8_t* daddr, uint8_t type, uint8_t code, uint16_t id, uint16_t seq, const void* data,
|
||||
size_t len) {
|
||||
if (len > NSTUN_MTU) {
|
||||
LOG_W("icmp_send_packet6: data length too large");
|
||||
return false;
|
||||
|
||||
@@ -260,7 +260,8 @@ static void tapCb(int fd, uint32_t events, void* data) {
|
||||
if (events & EPOLLIN) {
|
||||
/* Use a loop to read until EAGAIN, but limit iterations to prevent starvation */
|
||||
for (int i = 0; i < nstun::kMaxReadIterations; ++i) {
|
||||
ssize_t n = TEMP_FAILURE_RETRY(read(fd, ctx->tun_buf, sizeof(ctx->tun_buf)));
|
||||
ssize_t n =
|
||||
TEMP_FAILURE_RETRY(read(fd, ctx->tun_buf, sizeof(ctx->tun_buf)));
|
||||
if (n <= 0) {
|
||||
if (n < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
|
||||
return;
|
||||
@@ -492,7 +493,6 @@ void nstun_periodic() {
|
||||
|
||||
[[nodiscard]] static bool parse_rules4(nstun::Context* ctx, nsj_t* nsj) {
|
||||
for (const auto& r : nsj->njc.user_net().rule4()) {
|
||||
|
||||
nstun_rule_t nr = {};
|
||||
nstun::RuleParseStatus status = nstun::fill_rule_common(r, &nr);
|
||||
if (status == nstun::RuleParseStatus::ABORT) {
|
||||
@@ -535,7 +535,6 @@ void nstun_periodic() {
|
||||
|
||||
[[nodiscard]] static bool parse_rules6(nstun::Context* ctx, nsj_t* nsj) {
|
||||
for (const auto& r : nsj->njc.user_net().rule6()) {
|
||||
|
||||
nstun_rule_t nr = {};
|
||||
nr.is_ipv6 = true;
|
||||
nstun::RuleParseStatus status = nstun::fill_rule_common(r, &nr);
|
||||
|
||||
@@ -19,7 +19,8 @@ enum class RuleParseStatus {
|
||||
[[nodiscard]] RuleResult evaluate_rules6(Context* ctx, nstun_direction_t dir, nstun_proto_t proto,
|
||||
const uint8_t* src_ip6, const uint8_t* dst_ip6, uint16_t sport, uint16_t dport);
|
||||
|
||||
[[nodiscard]] RuleParseStatus fill_rule_common(const nsjail::NsJailConfig_UserNet_NstunRule& r, nstun_rule_t* nr);
|
||||
[[nodiscard]] RuleParseStatus fill_rule_common(
|
||||
const nsjail::NsJailConfig_UserNet_NstunRule& r, nstun_rule_t* nr);
|
||||
|
||||
} /* namespace nstun */
|
||||
|
||||
|
||||
@@ -490,7 +490,8 @@ bool push_to_guest(Context* ctx, TcpFlow* flow) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||
LOG_D("push_to_guest: TUN device full (EAGAIN)");
|
||||
if (!monitor::modFd(ctx->tap_fd, EPOLLIN | EPOLLOUT)) {
|
||||
LOG_E("Failed to modify tap_fd events to EPOLLIN | EPOLLOUT");
|
||||
LOG_E(
|
||||
"Failed to modify tap_fd events to EPOLLIN | EPOLLOUT");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -774,7 +775,8 @@ static void tcp_process_active_packet(Context* ctx, TcpFlow* flow, const tcp_hdr
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] static bool handle_inbound_syn_ack(Context* ctx, TcpFlow* flow, uint32_t seq, uint32_t ack) {
|
||||
[[nodiscard]] static bool handle_inbound_syn_ack(
|
||||
Context* ctx, TcpFlow* flow, uint32_t seq, uint32_t ack) {
|
||||
flow->tcp_state = TcpState::ESTABLISHED;
|
||||
LOG_D("Flow %d: SYN_SENT -> ESTABLISHED (inbound)", flow->header.host_fd);
|
||||
flow->ack_from_guest = ack;
|
||||
|
||||
@@ -115,7 +115,8 @@ void handle_socks5_connecting_host(Context* ctx, TcpFlow* flow, int fd) {
|
||||
return;
|
||||
}
|
||||
expected_len = sizeof(socks5_req_domain) +
|
||||
flow->c_proxy_rx_buf[nstun::SOCKS5_OFF_DOMAIN_LEN] + sizeof(uint16_t);
|
||||
flow->c_proxy_rx_buf[nstun::SOCKS5_OFF_DOMAIN_LEN] +
|
||||
sizeof(uint16_t);
|
||||
if (expected_len > PROXY_RX_BUF_CAP) {
|
||||
LOG_E("SOCKS5 expected length exceeds buffer size");
|
||||
tcp_rst_and_destroy(ctx, flow);
|
||||
|
||||
10
nstun/udp.cc
10
nstun/udp.cc
@@ -153,8 +153,8 @@ void udp_destroy_flow(Context* ctx, UdpFlow* flow) {
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] static bool udp_send_packet4(Context* ctx, uint32_t saddr, uint32_t daddr, uint16_t sport,
|
||||
uint16_t dport, const uint8_t* data, size_t len) {
|
||||
[[nodiscard]] static bool udp_send_packet4(Context* ctx, uint32_t saddr, uint32_t daddr,
|
||||
uint16_t sport, uint16_t dport, const uint8_t* data, size_t len) {
|
||||
if (len > NSTUN_MTU) {
|
||||
LOG_W("udp_send_packet4: data length too large");
|
||||
return false;
|
||||
@@ -477,7 +477,8 @@ static void handle_udp_socks5_associate(Context* ctx, UdpFlow* flow, uint32_t ev
|
||||
msg.msg_iov = iov;
|
||||
msg.msg_iovlen = 2;
|
||||
|
||||
if (TEMP_FAILURE_RETRY(sendmsg(flow->header.host_fd, &msg, MSG_NOSIGNAL)) == -1) {
|
||||
if (TEMP_FAILURE_RETRY(sendmsg(flow->header.host_fd, &msg, MSG_NOSIGNAL)) ==
|
||||
-1) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||
break;
|
||||
}
|
||||
@@ -503,7 +504,8 @@ static void handle_udp_socks5_associate(Context* ctx, UdpFlow* flow, uint32_t ev
|
||||
msg.msg_iov = iov;
|
||||
msg.msg_iovlen = 2;
|
||||
|
||||
if (TEMP_FAILURE_RETRY(sendmsg(flow->header.host_fd, &msg, MSG_NOSIGNAL)) == -1) {
|
||||
if (TEMP_FAILURE_RETRY(sendmsg(flow->header.host_fd, &msg, MSG_NOSIGNAL)) ==
|
||||
-1) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ struct channel_t {
|
||||
void closeAndUnregister() {
|
||||
if (pipe_fd >= 0) {
|
||||
if (registered) {
|
||||
monitor::removeFd(pipe_fd);
|
||||
(void)monitor::removeFd(pipe_fd);
|
||||
registered = false;
|
||||
}
|
||||
close(pipe_fd);
|
||||
@@ -76,7 +76,7 @@ struct conn_t {
|
||||
pipe_to_sock.closeAndUnregister();
|
||||
if (sock_fd >= 0) {
|
||||
if (sock_registered) {
|
||||
monitor::removeFd(sock_fd);
|
||||
(void)monitor::removeFd(sock_fd);
|
||||
sock_registered = false;
|
||||
}
|
||||
close(sock_fd);
|
||||
@@ -174,7 +174,7 @@ static void proxyPumpCb(int fd, uint32_t events, void* data);
|
||||
|
||||
if (events == 0) {
|
||||
if (*registered) {
|
||||
monitor::removeFd(fd);
|
||||
(void)monitor::removeFd(fd);
|
||||
*registered = false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -63,7 +63,7 @@ static thread_local unotifyCtx_t current_ctx;
|
||||
|
||||
static void closeAndUnregister(int fd) {
|
||||
if (fd >= 0) {
|
||||
monitor::removeFd(fd);
|
||||
(void)monitor::removeFd(fd);
|
||||
close(fd);
|
||||
current_ctx.fd = -1;
|
||||
}
|
||||
|
||||
4
user.h
4
user.h
@@ -32,8 +32,8 @@ namespace user {
|
||||
|
||||
bool initNsFromParent(nsj_t* nsj, pid_t pid);
|
||||
bool initNs(nsj_t* nsj);
|
||||
[[nodiscard]] bool parseId(nsj_t* nsj, const std::string& i_id, const std::string& o_id, size_t cnt, bool is_gid,
|
||||
bool is_newidmap);
|
||||
[[nodiscard]] bool parseId(nsj_t* nsj, const std::string& i_id, const std::string& o_id, size_t cnt,
|
||||
bool is_gid, bool is_newidmap);
|
||||
|
||||
} // namespace user
|
||||
|
||||
|
||||
Reference in New Issue
Block a user