Messages in this thread Patch in this message | | | From | Sam Protsenko <> | Subject | [PATCH 2/2] l2tp: Add Protocol field compression | Date | Fri, 14 Dec 2018 23:12:42 +0200 |
| |
When Protocol Field Compression (PFC) is enabled, the "Protocol" field in PPP packet should be transmitted without leading 0x00. See section 6.5 in RFC 1661 for details. Let's compress protocol field if needed, the same way it's done in drivers/net/ppp/pptp.c.
To actually enable PFC, one should issue corresponding ioctl to L2TP driver from user-space, like this:
ioctl(fd, PPPIOCGFLAGS, &flags); flags |= SC_COMP_PROT; ioctl(fd, PPPIOCSFLAGS, &flags);
It can be done e.g. from pppol2tp plugin (pppd), when pcomp option was negotiated with peer.
Of course, we don't compress Protocol field when sending LCP packets. As stated in RFC 1661, section 6.5:
The Protocol field is never compressed when sending any LCP packet. This rule guarantees unambiguous recognition of LCP packets.
Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org> --- net/l2tp/l2tp_ppp.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c index 145435977b21..7860b219af07 100644 --- a/net/l2tp/l2tp_ppp.c +++ b/net/l2tp/l2tp_ppp.c @@ -363,7 +363,10 @@ static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb) struct sock *sk = (struct sock *) chan->private; struct l2tp_session *session; struct l2tp_tunnel *tunnel; + struct pppol2tp_session *ps; int uhlen, headroom; + unsigned char *data; + bool is_lcp; if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED)) goto abort; @@ -384,6 +387,15 @@ static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb) if (skb_cow_head(skb, headroom)) goto abort_put_sess; + ps = l2tp_session_priv(session); + data = skb->data; + is_lcp = ((data[0] << 8) + data[1]) == PPP_LCP && + data[2] >= 1 && data[2] <= 7; + + /* Compress protocol field if PFC is enabled */ + if ((ps->flags & SC_COMP_PROT) && data[0] == 0x00 && !is_lcp) + __skb_pull(skb, 1); + /* Setup PPP header */ __skb_push(skb, 2); skb->data[0] = PPP_ALLSTATIONS; -- 2.19.1
| |