1/***************************************************************************
2 * Linux PPP over X - Generic PPP transport layer sockets
3 * Linux PPP over Ethernet (PPPoE) Socket Implementation (RFC 2516)
4 *
5 * This file supplies definitions required by the PPP over Ethernet driver
6 * (pppox.c).  All version information wrt this file is located in pppox.c
7 *
8 * License:
9 *		This program is free software; you can redistribute it and/or
10 *		modify it under the terms of the GNU General Public License
11 *		as published by the Free Software Foundation; either version
12 *		2 of the License, or (at your option) any later version.
13 *
14 */
15
16#ifndef __LINUX_IF_PPPOX_H
17#define __LINUX_IF_PPPOX_H
18
19
20#include <asm/types.h>
21#include <asm/byteorder.h>
22#include <linux/version.h>
23
24#ifdef  __KERNEL__
25#include <linux/in.h>
26#include <linux/if_ether.h>
27#include <linux/if.h>
28#include <linux/netdevice.h>
29#include <linux/ppp_channel.h>
30#endif /* __KERNEL__ */
31
32/* For user-space programs to pick up these definitions
33 * which they wouldn't get otherwise without defining __KERNEL__
34 */
35#ifndef AF_PPPOX
36#define AF_PPPOX	24
37#define PF_PPPOX	AF_PPPOX
38#endif /* !(AF_PPPOX) */
39
40/************************************************************************
41 * PPPoE addressing definition
42 */
43typedef __u16 sid_t;
44struct pppoe_addr{
45       sid_t           sid;                    /* Session identifier */
46       unsigned char   remote[ETH_ALEN];       /* Remote address */
47       char            dev[IFNAMSIZ];          /* Local device to use */
48};
49
50struct pptp_addr{
51       __u16           call_id;
52       struct in_addr  sin_addr;
53};
54/************************************************************************
55 * Protocols supported by AF_PPPOX
56 */
57#define PX_PROTO_OE    0 /* Currently just PPPoE */
58#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,22)
59#define PX_PROTO_PPTP  1
60#define PX_MAX_PROTO   2
61#else
62#define PX_PROTO_PPTP  2
63#define PX_MAX_PROTO   3
64#endif
65
66struct sockaddr_pppox {
67       sa_family_t     sa_family;            /* address family, AF_PPPOX */
68       unsigned int    sa_protocol;          /* protocol identifier */
69       union{
70               struct pppoe_addr       pppoe;
71	       			 struct pptp_addr        pptp;
72       }sa_addr;
73}__attribute__ ((packed));
74
75
76/*********************************************************************
77 *
78 * ioctl interface for defining forwarding of connections
79 *
80 ********************************************************************/
81
82#define PPPOEIOCSFWD	_IOW(0xB1 ,0, size_t)
83#define PPPOEIOCDFWD	_IO(0xB1 ,1)
84/*#define PPPOEIOCGFWD	_IOWR(0xB1,2, size_t)*/
85
86/* Codes to identify message types */
87#define PADI_CODE	0x09
88#define PADO_CODE	0x07
89#define PADR_CODE	0x19
90#define PADS_CODE	0x65
91#define PADT_CODE	0xa7
92struct pppoe_tag {
93	__u16 tag_type;
94	__u16 tag_len;
95	char tag_data[0];
96} __attribute ((packed));
97
98/* Tag identifiers */
99#define PTT_EOL		__constant_htons(0x0000)
100#define PTT_SRV_NAME	__constant_htons(0x0101)
101#define PTT_AC_NAME	__constant_htons(0x0102)
102#define PTT_HOST_UNIQ	__constant_htons(0x0103)
103#define PTT_AC_COOKIE	__constant_htons(0x0104)
104#define PTT_VENDOR 	__constant_htons(0x0105)
105#define PTT_RELAY_SID	__constant_htons(0x0110)
106#define PTT_SRV_ERR     __constant_htons(0x0201)
107#define PTT_SYS_ERR  	__constant_htons(0x0202)
108#define PTT_GEN_ERR  	__constant_htons(0x0203)
109
110struct pppoe_hdr {
111#if defined(__LITTLE_ENDIAN_BITFIELD)
112	__u8 ver : 4;
113	__u8 type : 4;
114#elif defined(__BIG_ENDIAN_BITFIELD)
115	__u8 type : 4;
116	__u8 ver : 4;
117#else
118#error	"Please fix <asm/byteorder.h>"
119#endif
120	__u8 code;
121	__u16 sid;
122	__u16 length;
123	struct pppoe_tag tag[0];
124} __attribute__ ((packed));
125
126
127/* Socket options */
128#define PPTP_SO_TIMEOUT 1
129
130
131#ifdef __KERNEL__
132#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
133struct pppoe_opt {
134	struct net_device      *dev;	  /* device associated with socket*/
135	struct pppoe_addr	pa;	  /* what this socket is bound to*/
136	struct sockaddr_pppox	relay;	  /* what socket data will be
137					     relayed to (PPPoE relaying) */
138};
139#endif
140struct pptp_opt {
141	struct pptp_addr	src_addr;
142	struct pptp_addr	dst_addr;
143	__u32 ack_sent, ack_recv;
144	__u32 seq_sent, seq_recv;
145	int ppp_flags;
146};
147#define PPTP_FLAG_PAUSE 0
148#define PPTP_FLAG_PROC 1
149
150#include <net/sock.h>
151
152struct pppox_sock {
153	/* struct sock must be the first member of pppox_sock */
154	#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
155	struct ppp_channel	chan;
156	struct sock		*sk;
157	#else
158	struct sock		sk;
159	struct ppp_channel	chan;
160	#endif
161	struct pppox_sock	*next;	  /* for hash table */
162	union {
163		struct pppoe_opt pppoe;
164		struct pptp_opt pptp;
165	} proto;
166	unsigned short		num;
167};
168#define pppoe_dev	proto.pppoe.dev
169#define pppoe_pa	proto.pppoe.pa
170#define pppoe_relay	proto.pppoe.relay
171
172static inline struct pppox_sock *pppox_sk(struct sock *sk)
173{
174	#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
175	return (struct pppox_sock *)sk->protinfo.pppox;
176	#else
177	return (struct pppox_sock *)sk;
178	#endif
179}
180
181static inline struct sock *sk_pppox(struct pppox_sock *po)
182{
183	#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
184	return po->sk;
185	#else
186	return (struct sock *)po;
187	#endif
188}
189
190struct module;
191
192struct pppox_proto {
193	#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
194	int		(*create)(struct socket *sock);
195	#else
196	int		(*create)(struct net *net, struct socket *sock);
197	#endif
198	int		(*ioctl)(struct socket *sock, unsigned int cmd,
199				 unsigned long arg);
200  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)
201	struct module	*owner;
202	#endif
203};
204
205extern int register_pppox_proto(int proto_num, struct pppox_proto *pp);
206extern void unregister_pppox_proto(int proto_num);
207extern void pppox_unbind_sock(struct sock *sk);/* delete ppp-channel binding */
208extern int pppox_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
209
210/* PPPoX socket states */
211enum {
212    PPPOX_NONE		= 0,  /* initial state */
213    PPPOX_CONNECTED	= 1,  /* connection established ==TCP_ESTABLISHED */
214    PPPOX_BOUND		= 2,  /* bound to ppp device */
215    PPPOX_RELAY		= 4,  /* forwarding is enabled */
216    PPPOX_ZOMBIE	= 8,  /* dead, but still bound to ppp device */
217    PPPOX_DEAD		= 16  /* dead, useless, please clean me up!*/
218};
219
220#endif /* __KERNEL__ */
221
222#endif /* !(__LINUX_IF_PPPOX_H) */
223