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 23#ifdef __KERNEL__ 24#include <linux/if_ether.h> 25#include <linux/if.h> 26#include <linux/netdevice.h> 27#include <asm/semaphore.h> 28#include <linux/ppp_channel.h> 29/* Foxconn, add start by MJ. for pppol2tp. 01/21/2010 */ 30#ifdef INCLUDE_L2TP 31#include <linux/if_pppol2tp.h> 32#endif 33/* Foxconn, add end by MJ. for pppol2tp. 01/21/2010 */ 34#endif /* __KERNEL__ */ 35 36/* For user-space programs to pick up these definitions 37 * which they wouldn't get otherwise without defining __KERNEL__ 38 */ 39#ifndef AF_PPPOX 40#define AF_PPPOX 24 41#define PF_PPPOX AF_PPPOX 42#endif /* !(AF_PPPOX) */ 43 44/************************************************************************ 45 * PPPoE addressing definition 46 */ 47typedef __u16 sid_t; 48struct pppoe_addr{ 49 sid_t sid; /* Session identifier */ 50 unsigned char remote[ETH_ALEN]; /* Remote address */ 51 char dev[IFNAMSIZ]; /* Local device to use */ 52}; 53 54/* Foxconn added start, pptp, Winster Chan, 06/26/2006 */ 55/************************************************************************ 56 * PPTP addressing definition 57 */ 58struct pptp_addr{ 59 unsigned char remote[ETH_ALEN]; /* Remote address */ 60 unsigned short cid; /* PPTP call id */ 61 unsigned short pcid; /* PPTP peer call id */ 62 unsigned long seq_num; /* Seq number of PPP packet */ 63 unsigned long ack_num; /* Ack number of PPP packet */ 64 unsigned long srcaddr; /* Source IP address */ 65 unsigned long dstaddr; /* Destination IP address */ 66 char dev[IFNAMSIZ]; /* Local device to use */ 67}; 68/* Foxconn added end, pptp, Winster Chan, 06/26/2006 */ 69 70/************************************************************************ 71 * Protocols supported by AF_PPPOX 72 */ 73#define PX_PROTO_OE 0 /* Currently just PPPoE */ 74#if 0 /* Foxconn modified start, pptp, Winster Chan, 06/26/2006 */ 75#define PX_MAX_PROTO 1 76#else 77#define PX_PROTO_TP 1 /* Add PPTP */ 78#ifdef INCLUDE_L2TP 79#define PX_PROTO_OL2TP 2 /* Add L2TP */ 80#define PX_MAX_PROTO 3 81#else 82#define PX_MAX_PROTO 2 83#endif 84#endif /* Foxconn modified end, pptp, Winster Chan, 06/26/2006 */ 85 86struct sockaddr_pppox { 87 sa_family_t sa_family; /* address family, AF_PPPOX */ 88 unsigned int sa_protocol; /* protocol identifier */ 89 union{ 90 struct pppoe_addr pppoe; 91 }sa_addr; 92}__attribute__ ((packed)); 93 94/* Foxconn added start, pptp, Winster Chan, 06/26/2006 */ 95struct sockaddr_pptpox { 96 sa_family_t sa_family; /* address family, AF_PPPOX */ 97 unsigned int sa_protocol; /* protocol identifier */ 98 union{ 99 struct pptp_addr pptp; 100 }sa_addr; 101}__attribute__ ((packed)); 102/* Foxconn added end, pptp, Winster Chan, 06/26/2006 */ 103/* Foxconn, add start by MJ. for pppol2tp. 01/21/2010 */ 104#ifdef INCLUDE_L2TP 105struct sockaddr_pppol2tp { 106 sa_family_t sa_family; /* address family, AF_PPPOX */ 107 unsigned int sa_protocol; /* protocol identifier */ 108 struct pppol2tp_addr pppol2tp; 109}__attribute__ ((packed)); 110#endif 111/* Foxconn, add end by MJ. for pppol2tp. 01/21/2010 */ 112 113/********************************************************************* 114 * 115 * ioctl interface for defining forwarding of connections 116 * 117 ********************************************************************/ 118 119#define PPPOEIOCSFWD _IOW(0xB1 ,0, size_t) 120#define PPPOEIOCDFWD _IO(0xB1 ,1) 121/*#define PPPOEIOCGFWD _IOWR(0xB1,2, size_t)*/ 122/* Foxconn added start, pptp, Winster Chan, 06/26/2006 */ 123#define PPTPIOCSFWD _IOW(0xB1 ,0, size_t) 124#define PPTPIOCDFWD _IO(0xB1 ,1) 125/* Foxconn added end, pptp, Winster Chan, 06/26/2006 */ 126 127/* foxconn wklin added start, 12/09/2010 */ 128#define PPTPIOCGGRESEQ _IOR('t', 54, unsigned long) /* get GRE sequence number */ 129/* foxconn wklin added end, 12/09/2010 */ 130 131/* Codes to identify message types */ 132#define PADI_CODE 0x09 133#define PADO_CODE 0x07 134#define PADR_CODE 0x19 135#define PADS_CODE 0x65 136#define PADT_CODE 0xa7 137struct pppoe_tag { 138 __u16 tag_type; 139 __u16 tag_len; 140 char tag_data[0]; 141} __attribute ((packed)); 142 143/* Tag identifiers */ 144#define PTT_EOL __constant_htons(0x0000) 145#define PTT_SRV_NAME __constant_htons(0x0101) 146#define PTT_AC_NAME __constant_htons(0x0102) 147#define PTT_HOST_UNIQ __constant_htons(0x0103) 148#define PTT_AC_COOKIE __constant_htons(0x0104) 149#define PTT_VENDOR __constant_htons(0x0105) 150#define PTT_RELAY_SID __constant_htons(0x0110) 151#define PTT_SRV_ERR __constant_htons(0x0201) 152#define PTT_SYS_ERR __constant_htons(0x0202) 153#define PTT_GEN_ERR __constant_htons(0x0203) 154 155struct pppoe_hdr { 156#if defined(__LITTLE_ENDIAN_BITFIELD) 157 __u8 ver : 4; 158 __u8 type : 4; 159#elif defined(__BIG_ENDIAN_BITFIELD) 160 __u8 type : 4; 161 __u8 ver : 4; 162#else 163#error "Please fix <asm/byteorder.h>" 164#endif 165 __u8 code; 166 __u16 sid; 167 __u16 length; 168 struct pppoe_tag tag[0]; 169} __attribute__ ((packed)); 170 171/* Length of entire PPPoE + PPP header */ 172#define PPPOE_SES_HLEN 8 173 174/* Foxconn added start, pptp, Winster Chan, 06/26/2006 */ 175/* IP PROTOCOL HEADER */ 176 177/* GRE Protocol field */ 178#define IP_PROTOCOL_ICMP 0x01 179#define IP_PROTOCOL_GRE 0x2f 180 181struct pptp_ip_hdr { 182#if defined(__LITTLE_ENDIAN_BITFIELD) 183 __u8 ihl:4, /* Header length */ 184 version:4; /* Version */ 185#elif defined (__BIG_ENDIAN_BITFIELD) 186 __u8 version:4, /* Version */ 187 ihl:4; /* Header length */ 188#else 189#error "Please fix <asm/byteorder.h>" 190#endif 191 __u8 tos; /* Differentiated services field */ 192 __u16 tot_len; /* Total length */ 193 __u16 id; /* Identification */ 194 __u16 frag_off; /* Fragment flags & offset */ 195 __u8 ttl; /* Time to live */ 196 __u8 protocol; /* Protocol: GRE(0x2f), ICMP(0x01) */ 197 __u16 check; /* Header checksum */ 198 __u32 saddr; /* Source IP address */ 199 __u32 daddr; /* Destination IP address */ 200 /*The options start here. */ 201} __attribute__ ((packed)); 202 203/* GRE PROTOCOL HEADER */ 204 205/* GRE Version field */ 206//#define GRE_VERSION_1701 0x0 207#define GRE_VERSION_PPTP 0x1 208 209/* GRE Protocol field */ 210#define GRE_PROTOCOL_PPTP __constant_htons(0x880B) 211 212/* GRE Flags */ 213#define GRE_FLAG_C 0x80 214#define GRE_FLAG_R 0x40 215#define GRE_FLAG_K 0x20 216#define GRE_FLAG_S 0x10 217#define GRE_FLAG_A 0x80 218 219#define GRE_IS_C(f) ((f)&GRE_FLAG_C) 220#define GRE_IS_R(f) ((f)&GRE_FLAG_R) 221#define GRE_IS_K(f) ((f)&GRE_FLAG_K) 222#define GRE_IS_S(f) ((f)&GRE_FLAG_S) 223#define GRE_IS_A(f) ((f)&GRE_FLAG_A) 224 225/* GRE is a mess: Four different standards */ 226/* modified GRE header for PPTP */ 227struct pptp_gre_hdr { 228 __u8 flags; /* bitfield */ 229 __u8 version; /* should be GRE_VERSION_PPTP */ 230 __u16 protocol; /* should be GRE_PROTOCOL_PPTP */ 231 __u16 payload_len; /* size of ppp payload, not inc. gre header */ 232 __u16 call_id; /* peer's call_id for this session */ 233 __u32 seq; /* sequence number. Present if S==1 */ 234 __u32 ack; /* seq number of highest packet recieved by */ 235 /* sender in this session */ 236} __attribute__ ((packed)); 237 238/* PPTP packet (IP & GRE) header */ 239struct pptp_hdr { 240 struct pptp_ip_hdr iphdr; /* IP header */ 241 struct pptp_gre_hdr grehdr; /* GRE header */ 242} __attribute__ ((packed)); 243/* Foxconn added end, pptp, Winster Chan, 06/26/2006 */ 244 245#ifdef __KERNEL__ 246#include <linux/skbuff.h> 247 248static inline struct pppoe_hdr *pppoe_hdr(const struct sk_buff *skb) 249{ 250 return (struct pppoe_hdr *)skb_network_header(skb); 251} 252 253struct pppoe_opt { 254 struct net_device *dev; /* device associated with socket*/ 255 int ifindex; /* ifindex of device associated with socket */ 256 struct pppoe_addr pa; /* what this socket is bound to*/ 257 struct sockaddr_pppox relay; /* what socket data will be 258 relayed to (PPPoE relaying) */ 259}; 260 261struct pptp_opt { 262 struct net_device *dev; /* device associated with socket*/ 263 int ifindex; /* ifindex of device associated with socket */ 264 struct pptp_addr pa; /* what this socket is bound to*/ 265 struct sockaddr_pppox relay; /* what socket data will be 266 relayed to (PPTP relaying) */ 267}; 268 269#include <net/sock.h> 270 271struct pppox_sock { 272 /* struct sock must be the first member of pppox_sock */ 273 struct sock sk; 274 struct ppp_channel chan; 275 struct pppox_sock *next; /* for hash table */ 276 union { 277 struct pppoe_opt pppoe; 278 struct pptp_opt pptp; 279 } proto; 280 unsigned short num; 281}; 282#define pppoe_dev proto.pppoe.dev 283#define pppoe_ifindex proto.pppoe.ifindex 284#define pppoe_pa proto.pppoe.pa 285#define pppoe_relay proto.pppoe.relay 286#define pptp_dev proto.pptp.dev 287#define pptp_ifindex proto.pptp.ifindex 288#define pptp_pa proto.pptp.pa 289#define pptp_relay proto.pptp.relay 290 291static inline struct pppox_sock *pppox_sk(struct sock *sk) 292{ 293 return (struct pppox_sock *)sk; 294} 295 296static inline struct sock *sk_pppox(struct pppox_sock *po) 297{ 298 return (struct sock *)po; 299} 300 301struct module; 302 303struct pppox_proto { 304 int (*create)(struct socket *sock); 305 int (*ioctl)(struct socket *sock, unsigned int cmd, 306 unsigned long arg); 307 struct module *owner; 308}; 309 310extern int register_pppox_proto(int proto_num, struct pppox_proto *pp); 311extern void unregister_pppox_proto(int proto_num); 312extern void pppox_unbind_sock(struct sock *sk);/* delete ppp-channel binding */ 313extern int pppox_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg); 314 315/* PPPoX socket states */ 316enum { 317 PPPOX_NONE = 0, /* initial state */ 318 PPPOX_CONNECTED = 1, /* connection established ==TCP_ESTABLISHED */ 319 PPPOX_BOUND = 2, /* bound to ppp device */ 320 PPPOX_RELAY = 4, /* forwarding is enabled */ 321 PPPOX_ZOMBIE = 8, /* dead, but still bound to ppp device */ 322 PPPOX_DEAD = 16 /* dead, useless, please clean me up!*/ 323}; 324 325#endif /* __KERNEL__ */ 326 327#endif /* !(__LINUX_IF_PPPOX_H) */ 328