if_pppox.h 5.8 KB

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