blob: 2b9730e5f721d928770499f519a3614617318d15 [file] [log] [blame]
Nicholas Flintham1e3d3112013-04-10 10:48:38 +01001/***************************************************************************
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 <linux/types.h>
21#include <asm/byteorder.h>
22
23#include <linux/socket.h>
24#include <linux/if_ether.h>
25#ifdef __KERNEL__
26#include <linux/if.h>
27#include <linux/netdevice.h>
28#include <linux/ppp_channel.h>
29#endif
30#include <linux/if_pppol2tp.h>
31#include <linux/if_pppolac.h>
32#include <linux/if_pppopns.h>
33
34#ifndef AF_PPPOX
35#define AF_PPPOX 24
36#define PF_PPPOX AF_PPPOX
37#endif
38
39
40typedef __be16 sid_t;
41struct pppoe_addr {
42 sid_t sid;
43 unsigned char remote[ETH_ALEN];
44 char dev[IFNAMSIZ];
45};
46
47struct pptp_addr {
48 __be16 call_id;
49 struct in_addr sin_addr;
50};
51
52#define PX_PROTO_OE 0
53#define PX_PROTO_OL2TP 1
54#define PX_PROTO_PPTP 2
55#define PX_PROTO_OLAC 3
56#define PX_PROTO_OPNS 4
57#define PX_MAX_PROTO 5
58
59struct sockaddr_pppox {
60 __kernel_sa_family_t sa_family;
61 unsigned int sa_protocol;
62 union {
63 struct pppoe_addr pppoe;
64 struct pptp_addr pptp;
65 } sa_addr;
66} __attribute__((packed));
67
68struct sockaddr_pppol2tp {
69 __kernel_sa_family_t sa_family;
70 unsigned int sa_protocol;
71 struct pppol2tp_addr pppol2tp;
72} __attribute__((packed));
73
74struct sockaddr_pppol2tpv3 {
75 __kernel_sa_family_t sa_family;
76 unsigned int sa_protocol;
77 struct pppol2tpv3_addr pppol2tp;
78} __attribute__((packed));
79
80
81#define PPPOEIOCSFWD _IOW(0xB1 ,0, size_t)
82#define PPPOEIOCDFWD _IO(0xB1 ,1)
83
84#define PADI_CODE 0x09
85#define PADO_CODE 0x07
86#define PADR_CODE 0x19
87#define PADS_CODE 0x65
88#define PADT_CODE 0xa7
89struct pppoe_tag {
90 __be16 tag_type;
91 __be16 tag_len;
92 char tag_data[0];
93} __attribute__ ((packed));
94
95#define PTT_EOL __cpu_to_be16(0x0000)
96#define PTT_SRV_NAME __cpu_to_be16(0x0101)
97#define PTT_AC_NAME __cpu_to_be16(0x0102)
98#define PTT_HOST_UNIQ __cpu_to_be16(0x0103)
99#define PTT_AC_COOKIE __cpu_to_be16(0x0104)
100#define PTT_VENDOR __cpu_to_be16(0x0105)
101#define PTT_RELAY_SID __cpu_to_be16(0x0110)
102#define PTT_SRV_ERR __cpu_to_be16(0x0201)
103#define PTT_SYS_ERR __cpu_to_be16(0x0202)
104#define PTT_GEN_ERR __cpu_to_be16(0x0203)
105
106struct pppoe_hdr {
107#if defined(__LITTLE_ENDIAN_BITFIELD)
108 __u8 ver : 4;
109 __u8 type : 4;
110#elif defined(__BIG_ENDIAN_BITFIELD)
111 __u8 type : 4;
112 __u8 ver : 4;
113#else
114#error "Please fix <asm/byteorder.h>"
115#endif
116 __u8 code;
117 __be16 sid;
118 __be16 length;
119 struct pppoe_tag tag[0];
120} __attribute__((packed));
121
122#define PPPOE_SES_HLEN 8
123
124#ifdef __KERNEL__
125#include <linux/skbuff.h>
126
127static inline struct pppoe_hdr *pppoe_hdr(const struct sk_buff *skb)
128{
129 return (struct pppoe_hdr *)skb_network_header(skb);
130}
131
132struct pppoe_opt {
133 struct net_device *dev;
134 int ifindex;
135 struct pppoe_addr pa;
136 struct sockaddr_pppox relay;
137};
138
139struct pptp_opt {
140 struct pptp_addr src_addr;
141 struct pptp_addr dst_addr;
142 u32 ack_sent, ack_recv;
143 u32 seq_sent, seq_recv;
144 int ppp_flags;
145};
146
147struct pppolac_opt {
148 __u32 local;
149 __u32 remote;
150 __u32 recv_sequence;
151 __u32 xmit_sequence;
152 atomic_t sequencing;
153 int (*backlog_rcv)(struct sock *sk_udp, struct sk_buff *skb);
154};
155
156struct pppopns_opt {
157 __u16 local;
158 __u16 remote;
159 __u32 recv_sequence;
160 __u32 xmit_sequence;
161 void (*data_ready)(struct sock *sk_raw, int length);
162 int (*backlog_rcv)(struct sock *sk_raw, struct sk_buff *skb);
163};
164
165#include <net/sock.h>
166
167struct pppox_sock {
168
169 struct sock sk;
170 struct ppp_channel chan;
171 struct pppox_sock *next;
172 union {
173 struct pppoe_opt pppoe;
174 struct pptp_opt pptp;
175 struct pppolac_opt lac;
176 struct pppopns_opt pns;
177 } proto;
178 __be16 num;
179};
180#define pppoe_dev proto.pppoe.dev
181#define pppoe_ifindex proto.pppoe.ifindex
182#define pppoe_pa proto.pppoe.pa
183#define pppoe_relay proto.pppoe.relay
184
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
195struct module;
196
197struct pppox_proto {
198 int (*create)(struct net *net, struct socket *sock);
199 int (*ioctl)(struct socket *sock, unsigned int cmd,
200 unsigned long arg);
201 struct module *owner;
202};
203
204extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
205extern void unregister_pppox_proto(int proto_num);
206extern void pppox_unbind_sock(struct sock *sk);
207extern int pppox_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
208
209enum {
210 PPPOX_NONE = 0,
211 PPPOX_CONNECTED = 1,
212 PPPOX_BOUND = 2,
213 PPPOX_RELAY = 4,
214 PPPOX_ZOMBIE = 8,
215 PPPOX_DEAD = 16
216};
217
218#endif
219
220#endif