Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  Point-to-Point Tunneling Protocol for Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *	Authors: Dmitry Kozlov <xeb@mail.ru>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/ppp_channel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/ppp_defs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/if_pppox.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/ppp-ioctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/rcupdate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <net/protocol.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <net/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <net/icmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <net/route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <net/gre.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <net/pptp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define PPTP_DRIVER_VERSION "0.8.5"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define MAX_CALLID 65535
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static DECLARE_BITMAP(callid_bitmap, MAX_CALLID + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static struct pppox_sock __rcu **callid_sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static DEFINE_SPINLOCK(chan_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static struct proto pptp_sk_proto __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static const struct ppp_channel_ops pptp_chan_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) static const struct proto_ops pptp_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static struct pppox_sock *lookup_chan(u16 call_id, __be32 s_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	struct pppox_sock *sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	struct pptp_opt *opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	sock = rcu_dereference(callid_sock[call_id]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	if (sock) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		opt = &sock->proto.pptp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		if (opt->dst_addr.sin_addr.s_addr != s_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 			sock = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			sock_hold(sk_pppox(sock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	return sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static int lookup_chan_dst(u16 call_id, __be32 d_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct pppox_sock *sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	struct pptp_opt *opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	i = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	for_each_set_bit_from(i, callid_bitmap, MAX_CALLID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		sock = rcu_dereference(callid_sock[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		if (!sock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		opt = &sock->proto.pptp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		if (opt->dst_addr.call_id == call_id &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			  opt->dst_addr.sin_addr.s_addr == d_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	return i < MAX_CALLID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) static int add_chan(struct pppox_sock *sock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		    struct pptp_addr *sa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	static int call_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	spin_lock(&chan_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (!sa->call_id)	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		call_id = find_next_zero_bit(callid_bitmap, MAX_CALLID, call_id + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		if (call_id == MAX_CALLID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			call_id = find_next_zero_bit(callid_bitmap, MAX_CALLID, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			if (call_id == MAX_CALLID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 				goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		sa->call_id = call_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	} else if (test_bit(sa->call_id, callid_bitmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	sock->proto.pptp.src_addr = *sa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	set_bit(sa->call_id, callid_bitmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	rcu_assign_pointer(callid_sock[sa->call_id], sock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	spin_unlock(&chan_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	spin_unlock(&chan_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static void del_chan(struct pppox_sock *sock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	spin_lock(&chan_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	clear_bit(sock->proto.pptp.src_addr.call_id, callid_bitmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	RCU_INIT_POINTER(callid_sock[sock->proto.pptp.src_addr.call_id], NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	spin_unlock(&chan_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static int pptp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	struct sock *sk = (struct sock *) chan->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	struct pppox_sock *po = pppox_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	struct net *net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	struct pptp_opt *opt = &po->proto.pptp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	struct pptp_gre_header *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	unsigned int header_len = sizeof(*hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	struct flowi4 fl4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	int islcp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	unsigned char *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	__u32 seq_recv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	struct rtable *rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	struct net_device *tdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	struct iphdr  *iph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	int    max_headroom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	if (sk_pppox(po)->sk_state & PPPOX_DEAD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		goto tx_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	rt = ip_route_output_ports(net, &fl4, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 				   opt->dst_addr.sin_addr.s_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 				   opt->src_addr.sin_addr.s_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 				   0, 0, IPPROTO_GRE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 				   RT_TOS(0), sk->sk_bound_dev_if);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	if (IS_ERR(rt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		goto tx_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	tdev = rt->dst.dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	max_headroom = LL_RESERVED_SPACE(tdev) + sizeof(*iph) + sizeof(*hdr) + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (skb_headroom(skb) < max_headroom || skb_cloned(skb) || skb_shared(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		if (!new_skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			ip_rt_put(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			goto tx_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		if (skb->sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			skb_set_owner_w(new_skb, skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		consume_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		skb = new_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	data = skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	islcp = ((data[0] << 8) + data[1]) == PPP_LCP && 1 <= data[2] && data[2] <= 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	/* compress protocol field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	if ((opt->ppp_flags & SC_COMP_PROT) && data[0] == 0 && !islcp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		skb_pull(skb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	/* Put in the address/control bytes if necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	if ((opt->ppp_flags & SC_COMP_AC) == 0 || islcp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		data = skb_push(skb, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		data[0] = PPP_ALLSTATIONS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		data[1] = PPP_UI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	len = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	seq_recv = opt->seq_recv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	if (opt->ack_sent == seq_recv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		header_len -= sizeof(hdr->ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	/* Push down and install GRE header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	skb_push(skb, header_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	hdr = (struct pptp_gre_header *)(skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	hdr->gre_hd.flags = GRE_KEY | GRE_VERSION_1 | GRE_SEQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	hdr->gre_hd.protocol = GRE_PROTO_PPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	hdr->call_id = htons(opt->dst_addr.call_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	hdr->seq = htonl(++opt->seq_sent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	if (opt->ack_sent != seq_recv)	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		/* send ack with this message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		hdr->gre_hd.flags |= GRE_ACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		hdr->ack  = htonl(seq_recv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		opt->ack_sent = seq_recv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	hdr->payload_len = htons(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	/*	Push down and install the IP header. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	skb_reset_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	skb_push(skb, sizeof(*iph));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	skb_reset_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED | IPSKB_REROUTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	iph =	ip_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	iph->version =	4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	iph->ihl =	sizeof(struct iphdr) >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	if (ip_dont_fragment(sk, &rt->dst))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		iph->frag_off	=	htons(IP_DF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		iph->frag_off	=	0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	iph->protocol = IPPROTO_GRE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	iph->tos      = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	iph->daddr    = fl4.daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	iph->saddr    = fl4.saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	iph->ttl      = ip4_dst_hoplimit(&rt->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	iph->tot_len  = htons(skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	skb_dst_drop(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	skb_dst_set(skb, &rt->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	nf_reset_ct(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	skb->ip_summed = CHECKSUM_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	ip_select_ident(net, skb, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	ip_send_check(iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	ip_local_out(net, skb->sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) tx_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static int pptp_rcv_core(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	struct pppox_sock *po = pppox_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	struct pptp_opt *opt = &po->proto.pptp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	int headersize, payload_len, seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	__u8 *payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	struct pptp_gre_header *header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	if (!(sk->sk_state & PPPOX_CONNECTED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		if (sock_queue_rcv_skb(sk, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		return NET_RX_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	header = (struct pptp_gre_header *)(skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	headersize  = sizeof(*header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	/* test if acknowledgement present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	if (GRE_IS_ACK(header->gre_hd.flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		__u32 ack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		if (!pskb_may_pull(skb, headersize))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		header = (struct pptp_gre_header *)(skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		/* ack in different place if S = 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		ack = GRE_IS_SEQ(header->gre_hd.flags) ? header->ack : header->seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		ack = ntohl(ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		if (ack > opt->ack_recv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			opt->ack_recv = ack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		/* also handle sequence number wrap-around  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		if (WRAPPED(ack, opt->ack_recv))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			opt->ack_recv = ack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		headersize -= sizeof(header->ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	/* test if payload present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	if (!GRE_IS_SEQ(header->gre_hd.flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	payload_len = ntohs(header->payload_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	seq         = ntohl(header->seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	/* check for incomplete packet (length smaller than expected) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	if (!pskb_may_pull(skb, headersize + payload_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	payload = skb->data + headersize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	/* check for expected sequence number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	if (seq < opt->seq_recv + 1 || WRAPPED(opt->seq_recv, seq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		if ((payload[0] == PPP_ALLSTATIONS) && (payload[1] == PPP_UI) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 				(PPP_PROTOCOL(payload) == PPP_LCP) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 				((payload[4] == PPP_LCP_ECHOREQ) || (payload[4] == PPP_LCP_ECHOREP)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 			goto allow_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		opt->seq_recv = seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) allow_packet:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		skb_pull(skb, headersize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		if (payload[0] == PPP_ALLSTATIONS && payload[1] == PPP_UI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 			/* chop off address/control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 			if (skb->len < 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 				goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 			skb_pull(skb, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		skb->ip_summed = CHECKSUM_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		skb_set_network_header(skb, skb->head-skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		ppp_input(&po->chan, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		return NET_RX_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	return NET_RX_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) static int pptp_rcv(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	struct pppox_sock *po;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	struct pptp_gre_header *header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	struct iphdr *iph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	if (skb->pkt_type != PACKET_HOST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	if (!pskb_may_pull(skb, 12))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	iph = ip_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	header = (struct pptp_gre_header *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	if (header->gre_hd.protocol != GRE_PROTO_PPP || /* PPTP-GRE protocol for PPTP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		GRE_IS_CSUM(header->gre_hd.flags) ||    /* flag CSUM should be clear */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		GRE_IS_ROUTING(header->gre_hd.flags) || /* flag ROUTING should be clear */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		!GRE_IS_KEY(header->gre_hd.flags) ||    /* flag KEY should be set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		(header->gre_hd.flags & GRE_FLAGS))     /* flag Recursion Ctrl should be clear */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		/* if invalid, discard this packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	po = lookup_chan(htons(header->call_id), iph->saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	if (po) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		skb_dst_drop(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		nf_reset_ct(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		return sk_receive_skb(sk_pppox(po), skb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	return NET_RX_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) static int pptp_bind(struct socket *sock, struct sockaddr *uservaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	int sockaddr_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	struct sockaddr_pppox *sp = (struct sockaddr_pppox *) uservaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	struct pppox_sock *po = pppox_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	if (sockaddr_len < sizeof(struct sockaddr_pppox))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	if (sk->sk_state & PPPOX_DEAD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		error = -EALREADY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	if (sk->sk_state & PPPOX_BOUND) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		error = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	if (add_chan(po, &sp->sa_addr.pptp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		error = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		sk->sk_state |= PPPOX_BOUND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) static int pptp_connect(struct socket *sock, struct sockaddr *uservaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	int sockaddr_len, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	struct sockaddr_pppox *sp = (struct sockaddr_pppox *) uservaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	struct pppox_sock *po = pppox_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	struct pptp_opt *opt = &po->proto.pptp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	struct rtable *rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	struct flowi4 fl4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	if (sockaddr_len < sizeof(struct sockaddr_pppox))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	if (sp->sa_protocol != PX_PROTO_PPTP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	if (lookup_chan_dst(sp->sa_addr.pptp.call_id, sp->sa_addr.pptp.sin_addr.s_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		return -EALREADY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	/* Check for already bound sockets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	if (sk->sk_state & PPPOX_CONNECTED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		error = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	/* Check for already disconnected sockets, on attempts to disconnect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	if (sk->sk_state & PPPOX_DEAD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		error = -EALREADY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	if (!opt->src_addr.sin_addr.s_addr || !sp->sa_addr.pptp.sin_addr.s_addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	po->chan.private = sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	po->chan.ops = &pptp_chan_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	rt = ip_route_output_ports(sock_net(sk), &fl4, sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 				   opt->dst_addr.sin_addr.s_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 				   opt->src_addr.sin_addr.s_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 				   0, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 				   IPPROTO_GRE, RT_CONN_FLAGS(sk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 				   sk->sk_bound_dev_if);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	if (IS_ERR(rt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		error = -EHOSTUNREACH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	sk_setup_caps(sk, &rt->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	po->chan.mtu = dst_mtu(&rt->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	if (!po->chan.mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		po->chan.mtu = PPP_MRU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	po->chan.mtu -= PPTP_HEADER_OVERHEAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	po->chan.hdrlen = 2 + sizeof(struct pptp_gre_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	error = ppp_register_channel(&po->chan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		pr_err("PPTP: failed to register PPP channel (%d)\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	opt->dst_addr = sp->sa_addr.pptp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	sk->sk_state |= PPPOX_CONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)  end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) static int pptp_getname(struct socket *sock, struct sockaddr *uaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	int peer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	int len = sizeof(struct sockaddr_pppox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	struct sockaddr_pppox sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	memset(&sp.sa_addr, 0, sizeof(sp.sa_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	sp.sa_family    = AF_PPPOX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	sp.sa_protocol  = PX_PROTO_PPTP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	sp.sa_addr.pptp = pppox_sk(sock->sk)->proto.pptp.src_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	memcpy(uaddr, &sp, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) static int pptp_release(struct socket *sock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	struct pppox_sock *po;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	if (!sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	if (sock_flag(sk, SOCK_DEAD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		return -EBADF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	po = pppox_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	del_chan(po);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	pppox_unbind_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	sk->sk_state = PPPOX_DEAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	sock_orphan(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	sock->sk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	sock_put(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) static void pptp_sock_destruct(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	if (!(sk->sk_state & PPPOX_DEAD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		del_chan(pppox_sk(sk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 		pppox_unbind_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	skb_queue_purge(&sk->sk_receive_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	dst_release(rcu_dereference_protected(sk->sk_dst_cache, 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) static int pptp_create(struct net *net, struct socket *sock, int kern)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	int error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	struct pppox_sock *po;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	struct pptp_opt *opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	sk = sk_alloc(net, PF_PPPOX, GFP_KERNEL, &pptp_sk_proto, kern);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	if (!sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	sock_init_data(sock, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	sock->state = SS_UNCONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	sock->ops   = &pptp_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	sk->sk_backlog_rcv = pptp_rcv_core;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	sk->sk_state       = PPPOX_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	sk->sk_type        = SOCK_STREAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	sk->sk_family      = PF_PPPOX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	sk->sk_protocol    = PX_PROTO_PPTP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	sk->sk_destruct    = pptp_sock_destruct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	po = pppox_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	opt = &po->proto.pptp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	opt->seq_sent = 0; opt->seq_recv = 0xffffffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	opt->ack_recv = 0; opt->ack_sent = 0xffffffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) static int pptp_ppp_ioctl(struct ppp_channel *chan, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	struct sock *sk = (struct sock *) chan->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	struct pppox_sock *po = pppox_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	struct pptp_opt *opt = &po->proto.pptp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	void __user *argp = (void __user *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	int __user *p = argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	int err, val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	case PPPIOCGFLAGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 		val = opt->ppp_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 		if (put_user(val, p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 		err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	case PPPIOCSFLAGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 		if (get_user(val, p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 		opt->ppp_flags = val & ~SC_RCV_BITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 		err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 		err = -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) static const struct ppp_channel_ops pptp_chan_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	.start_xmit = pptp_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	.ioctl      = pptp_ppp_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) static struct proto pptp_sk_proto __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	.name     = "PPTP",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	.owner    = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	.obj_size = sizeof(struct pppox_sock),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) static const struct proto_ops pptp_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	.family     = AF_PPPOX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	.owner      = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	.release    = pptp_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	.bind       = pptp_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	.connect    = pptp_connect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	.socketpair = sock_no_socketpair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	.accept     = sock_no_accept,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	.getname    = pptp_getname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	.listen     = sock_no_listen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	.shutdown   = sock_no_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	.sendmsg    = sock_no_sendmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	.recvmsg    = sock_no_recvmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	.mmap       = sock_no_mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	.ioctl      = pppox_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	.compat_ioctl = pppox_compat_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) static const struct pppox_proto pppox_pptp_proto = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	.create = pptp_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 	.owner  = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) static const struct gre_protocol gre_pptp_protocol = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	.handler = pptp_rcv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) static int __init pptp_init_module(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	pr_info("PPTP driver version " PPTP_DRIVER_VERSION "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	callid_sock = vzalloc(array_size(sizeof(void *), (MAX_CALLID + 1)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	if (!callid_sock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	err = gre_add_protocol(&gre_pptp_protocol, GREPROTO_PPTP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 		pr_err("PPTP: can't add gre protocol\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 		goto out_mem_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	err = proto_register(&pptp_sk_proto, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 		pr_err("PPTP: can't register sk_proto\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 		goto out_gre_del_protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	err = register_pppox_proto(PX_PROTO_PPTP, &pppox_pptp_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 		pr_err("PPTP: can't register pppox_proto\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 		goto out_unregister_sk_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) out_unregister_sk_proto:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 	proto_unregister(&pptp_sk_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) out_gre_del_protocol:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	gre_del_protocol(&gre_pptp_protocol, GREPROTO_PPTP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) out_mem_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	vfree(callid_sock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) static void __exit pptp_exit_module(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	unregister_pppox_proto(PX_PROTO_PPTP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 	proto_unregister(&pptp_sk_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	gre_del_protocol(&gre_pptp_protocol, GREPROTO_PPTP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	vfree(callid_sock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) module_init(pptp_init_module);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) module_exit(pptp_exit_module);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) MODULE_DESCRIPTION("Point-to-Point Tunneling Protocol");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) MODULE_AUTHOR("D. Kozlov (xeb@mail.ru)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) MODULE_ALIAS_NET_PF_PROTO(PF_PPPOX, PX_PROTO_PPTP);