tcp: minor cleanup

Fix two KASSERTs to catch the condition they are intended to,
add two asserts to ensure that the appropriate locking is in
place and fix some things related to style.
No functional change intended.

MFC after:	1 week
Sponsored by:	Netflix, Inc.
This commit is contained in:
Michael Tuexen 2024-06-29 11:06:35 +02:00
parent 8d5c8e21c6
commit 811d831050

View file

@ -394,23 +394,25 @@ static struct tcp_function_block *
find_tcp_functions_locked(struct tcp_function_set *fs)
{
struct tcp_function *f;
struct tcp_function_block *blk=NULL;
struct tcp_function_block *blk = NULL;
rw_assert(&tcp_function_lock, RA_LOCKED);
TAILQ_FOREACH(f, &t_functions, tf_next) {
if (strcmp(f->tf_name, fs->function_set_name) == 0) {
blk = f->tf_fb;
break;
}
}
return(blk);
return (blk);
}
static struct tcp_function_block *
find_tcp_fb_locked(struct tcp_function_block *blk, struct tcp_function **s)
{
struct tcp_function_block *rblk=NULL;
struct tcp_function_block *rblk = NULL;
struct tcp_function *f;
rw_assert(&tcp_function_lock, RA_LOCKED);
TAILQ_FOREACH(f, &t_functions, tf_next) {
if (f->tf_fb == blk) {
rblk = blk;
@ -433,7 +435,7 @@ find_and_ref_tcp_functions(struct tcp_function_set *fs)
if (blk)
refcount_acquire(&blk->tfb_refcnt);
rw_runlock(&tcp_function_lock);
return(blk);
return (blk);
}
struct tcp_function_block *
@ -446,7 +448,7 @@ find_and_ref_tcp_fb(struct tcp_function_block *blk)
if (rblk)
refcount_acquire(&rblk->tfb_refcnt);
rw_runlock(&tcp_function_lock);
return(rblk);
return (rblk);
}
/* Find a matching alias for the given tcp_function_block. */
@ -647,7 +649,7 @@ tcp_recv_udp_tunneled_packet(struct mbuf *m, int off, struct inpcb *inp,
static int
sysctl_net_inet_default_tcp_functions(SYSCTL_HANDLER_ARGS)
{
int error=ENOENT;
int error = ENOENT;
struct tcp_function_set fs;
struct tcp_function_block *blk;
@ -665,7 +667,7 @@ sysctl_net_inet_default_tcp_functions(SYSCTL_HANDLER_ARGS)
/* Check for error or no change */
if (error != 0 || req->newptr == NULL)
return(error);
return (error);
rw_wlock(&tcp_function_lock);
blk = find_tcp_functions_locked(&fs);
@ -1174,9 +1176,9 @@ register_tcp_functions_as_names(struct tcp_function_block *blk, int wait,
struct tcp_function_set fs;
int error, i;
KASSERT(names != NULL && *num_names > 0,
("%s: Called with 0-length name list", __func__));
KASSERT(names != NULL, ("%s: Called with NULL name list", __func__));
KASSERT(*num_names > 0,
("%s: Called with non-positive length of name list", __func__));
KASSERT(rw_initialized(&tcp_function_lock),
("%s: called too early", __func__));
@ -1223,7 +1225,7 @@ register_tcp_functions_as_names(struct tcp_function_block *blk, int wait,
tcp_fb_cnt++;
rw_wunlock(&tcp_function_lock);
}
return(0);
return (0);
cleanup:
/*
@ -4385,7 +4387,7 @@ tcp_req_check_for_stale_entries(struct tcpcb *tp, uint64_t ts, int rm_oldest)
uint64_t time_delta, oldest_delta;
int i, oldest, oldest_set = 0, cnt_rm = 0;
for(i = 0; i < MAX_TCP_TRK_REQ; i++) {
for (i = 0; i < MAX_TCP_TRK_REQ; i++) {
ent = &tp->t_tcpreq_info[i];
if (ent->flags != TCP_TRK_TRACK_FLG_USED) {
/*
@ -4428,15 +4430,15 @@ tcp_req_check_for_stale_entries(struct tcpcb *tp, uint64_t ts, int rm_oldest)
int
tcp_req_check_for_comp(struct tcpcb *tp, tcp_seq ack_point)
{
int i, ret=0;
int i, ret = 0;
struct tcp_sendfile_track *ent;
/* Clean up any old closed end requests that are now completed */
if (tp->t_tcpreq_req == 0)
return(0);
return (0);
if (tp->t_tcpreq_closed == 0)
return(0);
for(i = 0; i < MAX_TCP_TRK_REQ; i++) {
return (0);
for (i = 0; i < MAX_TCP_TRK_REQ; i++) {
ent = &tp->t_tcpreq_info[i];
/* Skip empty ones */
if (ent->flags == TCP_TRK_TRACK_FLG_EMPTY)
@ -4459,11 +4461,11 @@ int
tcp_req_is_entry_comp(struct tcpcb *tp, struct tcp_sendfile_track *ent, tcp_seq ack_point)
{
if (tp->t_tcpreq_req == 0)
return(-1);
return (-1);
if (tp->t_tcpreq_closed == 0)
return(-1);
return (-1);
if (ent->flags == TCP_TRK_TRACK_FLG_EMPTY)
return(-1);
return (-1);
if (SEQ_GEQ(ack_point, ent->end_seq)) {
return (1);
}
@ -4485,7 +4487,7 @@ tcp_req_find_a_req_that_is_completed_by(struct tcpcb *tp, tcp_seq th_ack, int *i
/* none open */
return (NULL);
}
for(i = 0; i < MAX_TCP_TRK_REQ; i++) {
for (i = 0; i < MAX_TCP_TRK_REQ; i++) {
ent = &tp->t_tcpreq_info[i];
if (ent->flags == TCP_TRK_TRACK_FLG_EMPTY)
continue;
@ -4509,7 +4511,7 @@ tcp_req_find_req_for_seq(struct tcpcb *tp, tcp_seq seq)
/* none open */
return (NULL);
}
for(i = 0; i < MAX_TCP_TRK_REQ; i++) {
for (i = 0; i < MAX_TCP_TRK_REQ; i++) {
ent = &tp->t_tcpreq_info[i];
tcp_req_log_req_info(tp, ent, i, TCP_TRK_REQ_LOG_SEARCH,
(uint64_t)seq, 0);
@ -4557,7 +4559,7 @@ tcp_req_alloc_req_full(struct tcpcb *tp, struct tcp_snd_req *req, uint64_t ts, i
(tp->t_tcpreq_req >= MAX_TCP_TRK_REQ));
/* Check to see if this is a duplicate of one not started */
if (tp->t_tcpreq_req) {
for(i = 0, allocated = 0; i < MAX_TCP_TRK_REQ; i++) {
for (i = 0, allocated = 0; i < MAX_TCP_TRK_REQ; i++) {
fil = &tp->t_tcpreq_info[i];
if ((fil->flags & TCP_TRK_TRACK_FLG_USED) == 0)
continue;
@ -4572,20 +4574,20 @@ tcp_req_alloc_req_full(struct tcpcb *tp, struct tcp_snd_req *req, uint64_t ts, i
* a 4xx of some sort and its going to age
* out, lets not duplicate it.
*/
return(fil);
return (fil);
}
}
}
/* Ok if there is no room at the inn we are in trouble */
if (tp->t_tcpreq_req >= MAX_TCP_TRK_REQ) {
tcp_trace_point(tp, TCP_TP_REQ_LOG_FAIL);
for(i = 0; i < MAX_TCP_TRK_REQ; i++) {
for (i = 0; i < MAX_TCP_TRK_REQ; i++) {
tcp_req_log_req_info(tp, &tp->t_tcpreq_info[i],
i, TCP_TRK_REQ_LOG_ALLOCFAIL, 0, 0);
}
return (NULL);
}
for(i = 0, allocated = 0; i < MAX_TCP_TRK_REQ; i++) {
for (i = 0, allocated = 0; i < MAX_TCP_TRK_REQ; i++) {
fil = &tp->t_tcpreq_info[i];
if (fil->flags == TCP_TRK_TRACK_FLG_EMPTY) {
allocated = 1;