Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 25 Jan 2000 23:01:27 -0800
From:      Don Lewis <Don.Lewis@tsc.tdk.com>
To:        Brett Glass <brett@lariat.org>, Don Lewis <Don.Lewis@tsc.tdk.com>, Matthew Dillon <dillon@apollo.backplane.com>
Cc:        freebsd-net@FreeBSD.ORG
Subject:   Re: Merged patches
Message-ID:  <200001260701.XAA29038@salsa.gv.tsc.tdk.com>
In-Reply-To: <4.2.2.20000125232750.04074b50@localhost>
References:  <200001251722.KAA04527@harmony.village.org> <4.2.2.20000125113518.01a59100@localhost> <4.2.2.20000125232750.04074b50@localhost>

next in thread | previous in thread | raw e-mail | index | archive | help
On Jan 25, 11:38pm, Brett Glass wrote:
} Subject: Re: Merged patches
} At 11:05 PM 1/25/2000 , Don Lewis wrote:
} 
} >A switch based on the TCP flags would be a very unnatural implementation.
} >For instance, most of the processing done on a packet received on an
} >established connection is the same whether the FIN bit is set or not.
} 
} A switch statement can allow the same group of statements to be executed
} for more than one combination of the flags.

Yes, but the processing has to be identical unless you add extra flags
tests inside the case block.

} >If the switch expression was based on the flags, then a large part of
} >the code would be duplicated between these two cases.
} 
} It is also possible to "fall through" from one case to another. This makes
} the switch statement a very powerful tool for this sort of situation.

This only works if one case is preamble for the next.  You have to
add extra tests if you want to exit the case early for some sets
of flags values.

And don't forget the /* fall through */.

} It
} is also possible to call a common subroutine. The overhead of a fixed
} subroutine call is often less than that of a conditional branch on
} today's CPUs.

Don't forget about all the nice unstructured "goto drop" statements
that bail out of deeply nested blocks in tcp_input().  It would be
pretty inconvenient if you wanted to bail out from the middle of
a subroutine.

} >   Also, the code
} >may do some processing on the segment, clear the SYN and/or FIN bits,
} >and then continue.
} 
} I'd think it would be unusual -- perhaps bad form -- to alter the flags,
} as it would make the code harder to follow. In what situation(s) would
} you do this?

You have to do this if the flags fall outside the window.

        if (todrop > 0) {      
                if (thflags & TH_SYN) {  
                        thflags &= ~TH_SYN;
                        th->th_seq++;
                        if (th->th_urp > 1)
                                th->th_urp--;
                        else   
                                thflags &= ~TH_URG;
                        todrop--;
                }       
                /*      
                 * Following if statement from Stevens, vol. 2, p. 960.
                 */
                if (todrop > tlen
                    || (todrop == tlen && (thflags & TH_FIN) == 0)) {
                        /*    
                         * Any valid FIN must be to the left of the window.
                         * At this point the FIN must be a duplicate or out
                         * of sequence; drop it.
                         */    
                        thflags &= ~TH_FIN;


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200001260701.XAA29038>