if_pppox.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. #ifndef __LINUX_IF_PPPOX_H
  16. #define __LINUX_IF_PPPOX_H
  17. #include <linux/types.h>
  18. #include <asm/byteorder.h>
  19. #include <linux/socket.h>
  20. #include <linux/if_ether.h>
  21. #ifdef __KERNEL__
  22. #include <linux/if.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/ppp_channel.h>
  25. #endif /* __KERNEL__ */
  26. #include <linux/if_pppol2tp.h>
  27. #include <linux/if_pppolac.h>
  28. #include <linux/if_pppopns.h>
  29. /* For user-space programs to pick up these definitions
  30. * which they wouldn't get otherwise without defining __KERNEL__
  31. */
  32. #ifndef AF_PPPOX
  33. #define AF_PPPOX 24
  34. #define PF_PPPOX AF_PPPOX
  35. #endif /* !(AF_PPPOX) */
  36. /************************************************************************
  37. * PPPoE addressing definition
  38. */
  39. typedef __be16 sid_t;
  40. struct pppoe_addr {
  41. sid_t sid; /* Session identifier */
  42. unsigned char remote[ETH_ALEN]; /* Remote address */
  43. char dev[IFNAMSIZ]; /* Local device to use */
  44. };
  45. /************************************************************************
  46. * PPTP addressing definition
  47. */
  48. struct pptp_addr {
  49. __be16 call_id;
  50. struct in_addr sin_addr;
  51. };
  52. /************************************************************************
  53. * Protocols supported by AF_PPPOX
  54. */
  55. #define PX_PROTO_OE 0 /* Currently just PPPoE */
  56. #define PX_PROTO_OL2TP 1 /* Now L2TP also */
  57. #define PX_PROTO_PPTP 2
  58. #define PX_PROTO_OLAC 3
  59. #define PX_PROTO_OPNS 4
  60. #define PX_MAX_PROTO 5
  61. struct sockaddr_pppox {
  62. __kernel_sa_family_t sa_family; /* address family, AF_PPPOX */
  63. unsigned int sa_protocol; /* protocol identifier */
  64. union {
  65. struct pppoe_addr pppoe;
  66. struct pptp_addr pptp;
  67. } sa_addr;
  68. } __attribute__((packed));
  69. /* The use of the above union isn't viable because the size of this
  70. * struct must stay fixed over time -- applications use sizeof(struct
  71. * sockaddr_pppox) to fill it. We use a protocol specific sockaddr
  72. * type instead.
  73. */
  74. struct sockaddr_pppol2tp {
  75. __kernel_sa_family_t sa_family; /* address family, AF_PPPOX */
  76. unsigned int sa_protocol; /* protocol identifier */
  77. struct pppol2tp_addr pppol2tp;
  78. } __attribute__((packed));
  79. /* The L2TPv3 protocol changes tunnel and session ids from 16 to 32
  80. * bits. So we need a different sockaddr structure.
  81. */
  82. struct sockaddr_pppol2tpv3 {
  83. __kernel_sa_family_t sa_family; /* address family, AF_PPPOX */
  84. unsigned int sa_protocol; /* protocol identifier */
  85. struct pppol2tpv3_addr pppol2tp;
  86. } __attribute__((packed));
  87. /*********************************************************************
  88. *
  89. * ioctl interface for defining forwarding of connections
  90. *
  91. ********************************************************************/
  92. #define PPPOEIOCSFWD _IOW(0xB1 ,0, size_t)
  93. #define PPPOEIOCDFWD _IO(0xB1 ,1)
  94. /*#define PPPOEIOCGFWD _IOWR(0xB1,2, size_t)*/
  95. /* Codes to identify message types */
  96. #define PADI_CODE 0x09
  97. #define PADO_CODE 0x07
  98. #define PADR_CODE 0x19
  99. #define PADS_CODE 0x65
  100. #define PADT_CODE 0xa7
  101. struct pppoe_tag {
  102. __be16 tag_type;
  103. __be16 tag_len;
  104. char tag_data[0];
  105. } __attribute__ ((packed));
  106. /* Tag identifiers */
  107. #define PTT_EOL __cpu_to_be16(0x0000)
  108. #define PTT_SRV_NAME __cpu_to_be16(0x0101)
  109. #define PTT_AC_NAME __cpu_to_be16(0x0102)
  110. #define PTT_HOST_UNIQ __cpu_to_be16(0x0103)
  111. #define PTT_AC_COOKIE __cpu_to_be16(0x0104)
  112. #define PTT_VENDOR __cpu_to_be16(0x0105)
  113. #define PTT_RELAY_SID __cpu_to_be16(0x0110)
  114. #define PTT_SRV_ERR __cpu_to_be16(0x0201)
  115. #define PTT_SYS_ERR __cpu_to_be16(0x0202)
  116. #define PTT_GEN_ERR __cpu_to_be16(0x0203)
  117. struct pppoe_hdr {
  118. #if defined(__LITTLE_ENDIAN_BITFIELD)
  119. __u8 type : 4;
  120. __u8 ver : 4;
  121. #elif defined(__BIG_ENDIAN_BITFIELD)
  122. __u8 ver : 4;
  123. __u8 type : 4;
  124. #else
  125. #error "Please fix <asm/byteorder.h>"
  126. #endif
  127. __u8 code;
  128. __be16 sid;
  129. __be16 length;
  130. struct pppoe_tag tag[0];
  131. } __attribute__((packed));
  132. /* Length of entire PPPoE + PPP header */
  133. #define PPPOE_SES_HLEN 8
  134. #ifdef __KERNEL__
  135. #include <linux/skbuff.h>
  136. static inline struct pppoe_hdr *pppoe_hdr(const struct sk_buff *skb)
  137. {
  138. return (struct pppoe_hdr *)skb_network_header(skb);
  139. }
  140. struct pppoe_opt {
  141. struct net_device *dev; /* device associated with socket*/
  142. int ifindex; /* ifindex of device associated with socket */
  143. struct pppoe_addr pa; /* what this socket is bound to*/
  144. struct sockaddr_pppox relay; /* what socket data will be
  145. relayed to (PPPoE relaying) */
  146. };
  147. struct pptp_opt {
  148. struct pptp_addr src_addr;
  149. struct pptp_addr dst_addr;
  150. u32 ack_sent, ack_recv;
  151. u32 seq_sent, seq_recv;
  152. int ppp_flags;
  153. };
  154. struct pppolac_opt {
  155. __u32 local;
  156. __u32 remote;
  157. __u32 recv_sequence;
  158. __u32 xmit_sequence;
  159. atomic_t sequencing;
  160. int (*backlog_rcv)(struct sock *sk_udp, struct sk_buff *skb);
  161. };
  162. struct pppopns_opt {
  163. __u16 local;
  164. __u16 remote;
  165. __u32 recv_sequence;
  166. __u32 xmit_sequence;
  167. void (*data_ready)(struct sock *sk_raw, int length);
  168. int (*backlog_rcv)(struct sock *sk_raw, struct sk_buff *skb);
  169. int ppp_flags;
  170. };
  171. #include <net/sock.h>
  172. struct pppox_sock {
  173. /* struct sock must be the first member of pppox_sock */
  174. struct sock sk;
  175. struct ppp_channel chan;
  176. struct pppox_sock *next; /* for hash table */
  177. union {
  178. struct pppoe_opt pppoe;
  179. struct pptp_opt pptp;
  180. struct pppolac_opt lac;
  181. struct pppopns_opt pns;
  182. } proto;
  183. struct timer_list recv_queue_timer;
  184. spinlock_t recv_queue_lock;
  185. __be16 num;
  186. };
  187. #define pppoe_dev proto.pppoe.dev
  188. #define pppoe_ifindex proto.pppoe.ifindex
  189. #define pppoe_pa proto.pppoe.pa
  190. #define pppoe_relay proto.pppoe.relay
  191. static inline struct pppox_sock *pppox_sk(struct sock *sk)
  192. {
  193. return (struct pppox_sock *)sk;
  194. }
  195. static inline struct sock *sk_pppox(struct pppox_sock *po)
  196. {
  197. return (struct sock *)po;
  198. }
  199. struct module;
  200. struct pppox_proto {
  201. int (*create)(struct net *net, struct socket *sock);
  202. int (*ioctl)(struct socket *sock, unsigned int cmd,
  203. unsigned long arg);
  204. struct module *owner;
  205. };
  206. extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
  207. extern void unregister_pppox_proto(int proto_num);
  208. extern void pppox_unbind_sock(struct sock *sk);/* delete ppp-channel binding */
  209. extern int pppox_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
  210. /* PPPoX socket states */
  211. enum {
  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. #endif /* __KERNEL__ */
  220. #endif /* !(__LINUX_IF_PPPOX_H) */