13 #include <linux/string.h>
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/slab.h>
17 #include <linux/errno.h>
18 #include <linux/netdevice.h>
19 #include <linux/net.h>
24 #include <linux/ppp_defs.h>
25 #include <linux/if_pppox.h>
31 #include <linux/netfilter.h>
32 #include <linux/netfilter_ipv4.h>
45 #define PPTP_DRIVER_VERSION "0.8.5"
47 #define MAX_CALLID 65535
58 #define PPP_LCP_ECHOREQ 0x09
59 #define PPP_LCP_ECHOREP 0x0A
60 #define SC_RCV_BITS (SC_RCV_B7_1|SC_RCV_B7_0|SC_RCV_ODDP|SC_RCV_EVNP)
62 #define MISSING_WINDOW 20
63 #define WRAPPED(curseq, lastseq)\
64 ((((curseq) & 0xffffff00) == 0) &&\
65 (((lastseq) & 0xffffff00) == 0xffffff00))
67 #define PPTP_GRE_PROTO 0x880B
68 #define PPTP_GRE_VER 0x1
70 #define PPTP_GRE_FLAG_C 0x80
71 #define PPTP_GRE_FLAG_R 0x40
72 #define PPTP_GRE_FLAG_K 0x20
73 #define PPTP_GRE_FLAG_S 0x10
74 #define PPTP_GRE_FLAG_A 0x80
76 #define PPTP_GRE_IS_C(f) ((f)&PPTP_GRE_FLAG_C)
77 #define PPTP_GRE_IS_R(f) ((f)&PPTP_GRE_FLAG_R)
78 #define PPTP_GRE_IS_K(f) ((f)&PPTP_GRE_FLAG_K)
79 #define PPTP_GRE_IS_S(f) ((f)&PPTP_GRE_FLAG_S)
80 #define PPTP_GRE_IS_A(f) ((f)&PPTP_GRE_FLAG_A)
82 #define PPTP_HEADER_OVERHEAD (2+sizeof(struct pptp_gre_header))
102 if (opt->
dst_addr.sin_addr.s_addr != s_addr)
105 sock_hold(sk_pppox(sock));
112 static int lookup_chan_dst(
u16 call_id,
__be32 d_addr)
125 if (opt->
dst_addr.call_id == call_id &&
126 opt->
dst_addr.sin_addr.s_addr == d_addr)
138 spin_lock(&chan_lock);
139 if (!sock->
proto.
pptp.src_addr.call_id) {
146 sock->
proto.
pptp.src_addr.call_id = call_id;
152 spin_unlock(&chan_lock);
157 spin_unlock(&chan_lock);
163 spin_lock(&chan_lock);
166 spin_unlock(&chan_lock);
172 struct sock *
sk = (
struct sock *) chan->
private;
174 struct pptp_opt *opt = &po->proto.pptp;
192 rt = ip_route_output_ports(sock_net(sk), &fl4,
NULL,
204 if (skb_headroom(skb) < max_headroom || skb_cloned(skb) || skb_shared(skb)) {
211 skb_set_owner_w(new_skb, skb->
sk);
217 islcp = ((data[0] << 8) + data[1]) ==
PPP_LCP && 1 <= data[2] && data[2] <= 7;
235 header_len -=
sizeof(hdr->ack);
251 hdr->ack =
htonl(seq_recv);
254 hdr->payload_len =
htons(len);
258 skb_reset_transport_header(skb);
260 skb_reset_network_header(skb);
266 iph->ihl =
sizeof(
struct iphdr) >> 2;
267 if (ip_dont_fragment(sk, &rt->
dst))
273 iph->
daddr = fl4.daddr;
274 iph->
saddr = fl4.saddr;
275 iph->
ttl = ip4_dst_hoplimit(&rt->
dst);
279 skb_dst_set(skb, &rt->
dst);
284 ip_select_ident(iph, &rt->
dst,
NULL);
295 static int pptp_rcv_core(
struct sock *sk,
struct sk_buff *skb)
310 headersize =
sizeof(*header);
316 if (!pskb_may_pull(skb, headersize))
331 headersize -=
sizeof(header->
ack);
341 if (!pskb_may_pull(skb, headersize + payload_len))
344 payload = skb->
data + headersize;
363 if ((*skb->
data) & 1) {
369 skb_set_network_header(skb, skb->
head-skb->
data);
379 static int pptp_rcv(
struct sk_buff *skb)
388 if (!pskb_may_pull(skb, 12))
399 (header->
flags&0xF) != 0)
414 static int pptp_bind(
struct socket *sock,
struct sockaddr *uservaddr,
417 struct sock *sk = sock->
sk;
433 static int pptp_connect(
struct socket *sock,
struct sockaddr *uservaddr,
434 int sockaddr_len,
int flags)
436 struct sock *sk = sock->
sk;
469 po->
chan.ops = &pptp_chan_ops;
471 rt = ip_route_output_ports(sock_net(sk), &fl4, sk,
482 po->
chan.mtu = dst_mtu(&rt->
dst);
491 pr_err(
"PPTP: failed to register PPP channel (%d)\n", error);
504 int *usockaddr_len,
int peer)
515 *usockaddr_len = len;
520 static int pptp_release(
struct socket *sock)
522 struct sock *sk = sock->
sk;
553 static void pptp_sock_destruct(
struct sock *sk)
556 del_chan(pppox_sk(sk));
562 static int pptp_create(
struct net *
net,
struct socket *sock)
576 sock->
ops = &pptp_ops;
596 static int pptp_ppp_ioctl(
struct ppp_channel *chan,
unsigned int cmd,
599 struct sock *sk = (
struct sock *) chan->
private;
628 .start_xmit = pptp_xmit,
629 .ioctl = pptp_ppp_ioctl,
638 static const struct proto_ops pptp_ops = {
641 .release = pptp_release,
643 .connect = pptp_connect,
646 .getname = pptp_getname,
658 static const struct pppox_proto pppox_pptp_proto = {
659 .create = pptp_create,
667 static int __init pptp_init_module(
void)
678 pr_err(
"PPTP: can't add gre protocol\n");
684 pr_err(
"PPTP: can't register sk_proto\n");
685 goto out_gre_del_protocol;
690 pr_err(
"PPTP: can't register pppox_proto\n");
691 goto out_unregister_sk_proto;
696 out_unregister_sk_proto:
698 out_gre_del_protocol:
706 static void __exit pptp_exit_module(
void)