Shin, Byung-Cheol wrote:
> Hello all,
> In Linux ppp.c source code, I am specially interested in
>
> ppp_async_encode( )
>
> module, where I cannot grasp the meaning of some source codes as shown
> below .
Well, I didn't write it, but I'll describe it to the best of my
knowledge...
> /*
> * Start of a new packet - insert the leading FLAG
> * character if necessary.
> */
> if (islcp || flag_time == 0
> || jiffies - ppp->last_xmit >= flag_time)
> *buf++ = PPP_FLAG;
See RFC1662. The flag character is put at the beginning and end of
each packet, however if you have two back-to-back packets you only
need a single flag byte seperating them (i.e. the end flag on
one counts as the begining flag on the next one). "flag_time"
is a module paramater indicating how long we can go between packets
and still be considered "back-to-back" (default: one second).
So if this is disabled (i.e. flag_time paramater was set to zero) OR
it's an LCP packet, OR this packet isn't back-to-back with the
last one, add a starting flag.
> (2)
> /*
> * Do address/control compression
> */
> if ((ppp->flags & SC_COMP_AC) != 0 && !islcp
> && PPP_ADDRESS(data) == PPP_ALLSTATIONS
> && PPP_CONTROL(data) == PPP_UI)
> i += 2;
>
> <Question2 >
> * role or meaning of " i += 2" above :
If the address/control bytes are notrmal, and that type of compression
is enabled, skip those first two bytes of the PPP packet.
> 3)
> /*
> * Once we put in the last byte, we need to put in the FCS
> * and closing flag, so make sure there is at least 7 bytes
> * of free space in the output buffer.
> */
> buflim = buf + OBUFSIZE - 6;
> while (i < count && buf < buflim) {
> c = data[i++];
> if (i == 3 && c == 0 && (ppp->flags & SC_COMP_PROT))
> continue; /* compress protocol field */
>
> < Question3 >
> *usual space requirement is FCS: 2 bytes, flag: 1 byte
> -- why 7 bytes space in output buffer here?
I suspect it's incase we need to escape the characters in the FCS and flag.
I bet we only really need 5 bytes in the worst case (4 for FCS, flag is
always 1)
> * role/meaning of " c == 0 " ? Does it mean there is no more data ?
No - if the PPP session has negotiated "protocol compression" then if the
two-byte network-byte-order protocol field (bytes 3 and 4) is less than 256
(i.e. byte 3 is zero) then that zero can be skipped. Thus the (i == 3
&& c == 0) requirement.
> / *
> * We have finished the packet. Add the FCS and flag.
> */
> fcs = ~fcs;
> c = fcs & 0xff;
> if (in_xmap(ppp, c) || (islcp && c < 0x20)) {
> *buf++ = PPP_ESCAPE;
> c ^= 0x20;
> }
>
> <Question4 >
> * what is the meaning of in_xmap(ppp,c) ?
The in_xmap macro holds the set of bytes which need to be escaped (which
vary based on the LCP negotiations
> * What is the necessity of " c< 0x20 " ?
Since we need to use LCP to negotiate what characters to escape, we
should assume that all characters 0x00-0x1F need to be escaped if
we're sending an LCP packet, in order to make sure that it gets
through.
See section 7.1 of RFC 1662 for details on control-character escaping.
-Mitch
-
To unsubscribe from this list: send the line "unsubscribe linux-ppp" in
the body of a message to [EMAIL PROTECTED]