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#ifdef __KERNEL__
22#include <asm/byteorder.h>
23#else
24#include <endian.h>
25#include <byteswap.h>
26#if __BYTE_ORDER == __LITTLE_ENDIAN
27#define __LITTLE_ENDIAN_BITFIELD
28#elif __BYTE_ORDER == __BIG_ENDIAN
29#define __BIG_ENDIAN_BITFIELD
30#else
31#error "Adjust your <endian.h> defines."
32#endif
33#endif
34
35#ifdef	__KERNEL__
36#include <linux/if_ether.h>
37#include <linux/if.h>
38#include <linux/netdevice.h>
39#include <asm/semaphore.h>
40#include <linux/ppp_channel.h>
41#endif /* __KERNEL__ */
42#include <linux/if_pppol2tp.h>
43
44/* For user-space programs to pick up these definitions
45 * which they wouldn't get otherwise without defining __KERNEL__
46 */
47#ifndef AF_PPPOX
48#define AF_PPPOX	24
49#define PF_PPPOX	AF_PPPOX
50#endif /* !(AF_PPPOX) */
51
52/************************************************************************
53 * PPPoE addressing definition
54 */
55typedef __u16 sid_t;
56struct pppoe_addr{
57       sid_t           sid;                    /* Session identifier */
58       unsigned char   remote[ETH_ALEN];       /* Remote address */
59       char            dev[IFNAMSIZ];          /* Local device to use */
60};
61
62/************************************************************************
63 * Protocols supported by AF_PPPOX
64 */
65#define PX_PROTO_OE    0 /* Currently just PPPoE */
66#define PX_PROTO_OL2TP 1 /* Now L2TP also */
67#define PX_MAX_PROTO   2
68
69struct sockaddr_pppox {
70       sa_family_t     sa_family;            /* address family, AF_PPPOX */
71       unsigned int    sa_protocol;          /* protocol identifier */
72       union{
73               struct pppoe_addr       pppoe;
74       }sa_addr;
75}__attribute__ ((packed));
76
77/* The use of the above union isn't viable because the size of this
78 * struct must stay fixed over time -- applications use sizeof(struct
79 * sockaddr_pppox) to fill it. We use a protocol specific sockaddr
80 * type instead.
81 */
82struct sockaddr_pppol2tp {
83	sa_family_t     sa_family;      /* address family, AF_PPPOX */
84	unsigned int    sa_protocol;    /* protocol identifier */
85	struct pppol2tp_addr pppol2tp;
86}__attribute__ ((packed));
87
88/*********************************************************************
89 *
90 * ioctl interface for defining forwarding of connections
91 *
92 ********************************************************************/
93
94#define PPPOEIOCSFWD	_IOW(0xB1 ,0, size_t)
95#define PPPOEIOCDFWD	_IO(0xB1 ,1)
96/*#define PPPOEIOCGFWD	_IOWR(0xB1,2, size_t)*/
97
98/* Codes to identify message types */
99#define PADI_CODE	0x09
100#define PADO_CODE	0x07
101#define PADR_CODE	0x19
102#define PADS_CODE	0x65
103#define PADT_CODE	0xa7
104struct pppoe_tag {
105	__u16 tag_type;
106	__u16 tag_len;
107	char tag_data[0];
108} __attribute ((packed));
109
110/* Tag identifiers */
111#define PTT_EOL		__constant_htons(0x0000)
112#define PTT_SRV_NAME	__constant_htons(0x0101)
113#define PTT_AC_NAME	__constant_htons(0x0102)
114#define PTT_HOST_UNIQ	__constant_htons(0x0103)
115#define PTT_AC_COOKIE	__constant_htons(0x0104)
116#define PTT_VENDOR 	__constant_htons(0x0105)
117#define PTT_RELAY_SID	__constant_htons(0x0110)
118#define PTT_SRV_ERR     __constant_htons(0x0201)
119#define PTT_SYS_ERR  	__constant_htons(0x0202)
120#define PTT_GEN_ERR  	__constant_htons(0x0203)
121
122struct pppoe_hdr {
123#if defined(__LITTLE_ENDIAN_BITFIELD)
124	__u8 ver : 4;
125	__u8 type : 4;
126#elif defined(__BIG_ENDIAN_BITFIELD)
127	__u8 type : 4;
128	__u8 ver : 4;
129#else
130#error	"Please fix <asm/byteorder.h>"
131#endif
132	__u8 code;
133	__u16 sid;
134	__u16 length;
135	struct pppoe_tag tag[0];
136} __attribute__ ((packed));
137
138#ifdef __KERNEL__
139struct pppoe_opt {
140	struct net_device	*dev;	  /* device associated with socket*/
141	struct pppoe_addr	pa;	  /* what this socket is bound to*/
142	struct sockaddr_pppox	relay;	  /* what socket data will be
143					     relayed to (PPPoE relaying) */
144};
145
146#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12))
147#include <net/sock.h>
148
149struct pppox_sock {
150	/* struct sock must be the first member of pppox_sock */
151	struct sock		sk;
152	struct ppp_channel	chan;
153	struct pppox_sock	*next;	  /* for hash table */
154	union {
155		struct pppoe_opt pppoe;
156	} proto;
157	unsigned short		num;
158};
159#else
160
161struct pppol2tp_tunnel;
162struct pppol2tp_session;
163
164struct pppol2tp_opt {
165	struct pppol2tp_tunnel	*tunnel;
166	struct pppol2tp_session	*session;
167};
168
169struct pppox_opt {
170	struct ppp_channel	chan;
171	struct sock		*sk;
172	struct pppox_opt	*next;	  /* for hash table */
173	union {
174		struct pppoe_opt pppoe;
175		struct pppol2tp_opt pppol2tp;
176	} proto;
177	unsigned short		num;
178};
179#endif
180#define pppoe_dev	proto.pppoe.dev
181#define pppoe_pa	proto.pppoe.pa
182#define pppoe_relay	proto.pppoe.relay
183
184#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12))
185static inline struct pppox_sock *pppox_sk(struct sock *sk)
186{
187	return (struct pppox_sock *)sk;
188}
189
190static inline struct sock *sk_pppox(struct pppox_sock *po)
191{
192	return (struct sock *)po;
193}
194#else
195#define pppox_sk(__sk) ((struct pppox_opt *)(__sk)->sk_protinfo)
196#endif
197
198struct module;
199
200struct pppox_proto {
201	int		(*create)(struct socket *sock);
202	int		(*ioctl)(struct socket *sock, unsigned int cmd,
203				 unsigned long arg);
204	struct module	*owner;
205};
206
207extern int register_pppox_proto(int proto_num, struct pppox_proto *pp);
208extern void unregister_pppox_proto(int proto_num);
209extern void pppox_unbind_sock(struct sock *sk);/* delete ppp-channel binding */
210#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16))
211extern int pppox_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
212#endif
213
214/* PPPoX socket states */
215enum {
216	PPPOX_NONE	= 0,  /* initial state */
217	PPPOX_CONNECTED	= 1,  /* connection established ==TCP_ESTABLISHED */
218	PPPOX_BOUND	= 2,  /* bound to ppp device */
219	PPPOX_RELAY	= 4,  /* forwarding is enabled */
220	PPPOX_ZOMBIE	= 8,  /* dead, but still bound to ppp device */
221	PPPOX_DEAD	= 16  /* dead, useless, please clean me up!*/
222};
223
224#endif /* __KERNEL__ */
225
226#endif /* !(__LINUX_IF_PPPOX_H) */
227