1/* PPPoE support library "libpppoe" 2 * 3 * Copyright 2000 Michal Ostrowski <mostrows@styx.uwaterloo.ca>, 4 * Jamal Hadi Salim <hadi@cyberus.ca> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 9 * 2 of the License, or (at your option) any later version. 10 */ 11 12#ifndef PPPOE_H 13#define PPPOE_H 1 14#include <stdio.h> /* stdio */ 15#include <stdlib.h> /* strtoul(), realloc() */ 16#include <unistd.h> /* STDIN_FILENO,exec */ 17#include <string.h> /* memcpy() */ 18#include <errno.h> /* errno */ 19#include <signal.h> 20#include <getopt.h> 21#include <stdarg.h> 22#include <syslog.h> 23#include <paths.h> 24 25#include <sys/types.h> /* socket types */ 26#include <asm/types.h> 27#include <sys/time.h> 28#include <sys/wait.h> 29#include <sys/fcntl.h> 30#include <sys/ioctl.h> /* ioctl() */ 31#include <sys/select.h> 32#include <sys/socket.h> /* socket() */ 33#include <net/if.h> /* ifreq struct */ 34#include <net/if_arp.h> 35#include <netinet/in.h> 36 37#if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1 38#include <netpacket/packet.h> 39//#include <net/ethernet.h> 40#else 41#include <asm/types.h> 42#include <linux/if_packet.h> 43#include <linux/if_ether.h> 44#endif 45 46 47#include <asm/byteorder.h> 48 49/* 50 jamal: we really have to change this 51 to make it compatible to the 2.2 and 52 2.3 kernel 53*/ 54 55#include <linux/if_pppox.h> 56 57 58#define CONNECTED 1 59#define DISCONNECTED 0 60 61#ifndef _PATH_PPPD 62#define _PATH_PPPD "/usr/sbin/pppd" 63#endif 64 65#ifndef LOG_PPPOE 66#define LOG_PPPOE LOG_DAEMON 67#endif 68 69 70#define VERSION_MAJOR 0 71#define VERSION_MINOR 4 72#define VERSION_DATE 991120 73 74/* Bigger than the biggest ethernet packet we'll ever see, in bytes */ 75#define MAX_PACKET 2000 76 77/* references: RFC 2516 */ 78/* ETHER_TYPE fields for PPPoE */ 79 80#define ETH_P_PPPOE_DISC 0x8863 /* discovery stage */ 81#define ETH_P_PPPOE_SESS 0x8864 82 83/* ethernet broadcast address */ 84#define MAC_BCAST_ADDR "\xff\xff\xff\xff\xff\xff" 85 86/* Format for parsing long device-name */ 87#define _STR(x) #x 88#define FMTSTRING(size) "%x:%x:%x:%x:%x:%x/%x/%" _STR(size) "s" 89 90/* maximum payload length */ 91#define MAX_PAYLOAD 1484 92 93 94 95/* PPPoE tag types */ 96#define MAX_TAGS 11 97 98 99/* PPPoE packet; includes Ethernet headers and such */ 100struct pppoe_packet{ 101 struct sockaddr_ll addr; 102 struct pppoe_tag *tags[MAX_TAGS]; 103 struct pppoe_hdr *hdr; 104 char buf[MAX_PAYLOAD]; /* buffer in which tags are held */ 105}; 106/* Defines meaning of each "tags" element */ 107 108#define TAG_SRV_NAME 0 109#define TAG_AC_NAME 1 110#define TAG_HOST_UNIQ 2 111#define TAG_AC_COOKIE 3 112#define TAG_VENDOR 4 113#define TAG_RELAY_SID 5 114#define TAG_SRV_ERR 6 115#define TAG_SYS_ERR 7 116#define TAG_GEN_ERR 8 117#define TAG_EOL 9 118 119/* Debug flags */ 120int DEB_DISC,DEB_DISC2; 121/* 122 #define DEB_DISC (opt_debug & 0x0002) 123 #define DEB_DISC2 (opt_debug & 0x0004) 124*/ 125#define MAX_FNAME 256 126 127 128struct session; 129 130/* return <0 --> fatal error; abor 131 return =0 --> ok, proceed 132 return >0 --> ok, qui 133*/ 134typedef int (*packet_cb_t)(struct session* ses, 135 struct pppoe_packet *p_in, 136 struct pppoe_packet **p_out); 137 138/* various override filter tags */ 139struct filter { 140 struct pppoe_tag *stag; /* service name tag override */ 141 struct pppoe_tag *ntag; /*AC name override */ 142 struct pppoe_tag *htag; /* hostuniq override */ 143 int num_restart; 144 int peermode; 145 char *fname; 146 char *pppd; 147} __attribute__ ((packed)); 148 149 150struct pppoe_tag *make_filter_tag(short type, short length, char* data); 151 152/* Session type definitions */ 153#define SESSION_CLIENT 0 154#define SESSION_SERVER 1 155#define SESSION_RELAY 2 156 157struct session { 158 159 /* Administrative */ 160 int type; 161 int opt_debug; 162 int detached; 163 int np; 164 int log_to_fd; 165 int ifindex; /* index of device */ 166 char name[IFNAMSIZ]; /*dev name */ 167 struct pppoe_packet curr_pkt; 168 169 packet_cb_t init_disc; 170 packet_cb_t rcv_pado; 171 packet_cb_t rcv_padi; 172 packet_cb_t rcv_pads; 173 packet_cb_t rcv_padr; 174 packet_cb_t rcv_padt; 175 packet_cb_t timeout; 176 177 178 /* Generic */ 179 struct filter *filt; 180 struct sockaddr_ll local; 181 struct sockaddr_ll remote; 182 struct sockaddr_pppox sp; 183 int fd; /* fd of PPPoE socket */ 184 185 186 /* For client */ 187 int retransmits; /* Number of retransmission performed 188 if < 0 , retransmissions disabled */ 189 int retries; 190 int state; 191 int opt_daemonize; 192 193 /* For server */ 194 int fork; 195 196 /* For forwarding */ 197 int fwd_sock; 198 char fwd_name[IFNAMSIZ]; /* Name of device to forward to */ 199} __attribute__ ((packed)); 200 201/* 202 retransmit retries for the PADR and PADI packets 203 during discovery 204*/ 205int PADR_ret; 206int PADI_ret; 207 208int log_to_fd; 209int ctrl_fd; 210int opt_debug; 211int opt_daemonize; 212 213 214/* Structure for keeping track of connection relays */ 215struct pppoe_con{ 216 struct pppoe_con *next; 217 int id; 218 int connected; 219 int cl_sock; 220 int sv_sock; 221 int ref_count; 222 char client[ETH_ALEN]; 223 char server[ETH_ALEN]; 224 char key_len; 225 char key[32]; 226}; 227 228/* Functions exported from utils.c. */ 229 230/* Functions exported from pppoehash.c */ 231struct pppoe_con *get_con(int len, char *key); 232int store_con(struct pppoe_con *pc); 233struct pppoe_con *delete_con(unsigned long len, char *key); 234 235/* exported by lib.c */ 236 237extern int init_lib(); 238 239extern int get_sockaddr_ll(const char *devnam,struct sockaddr_ll* sll); 240 241extern int client_init_ses (struct session *ses, char* devnam); 242extern int relay_init_ses(struct session *ses, char* from, char* to); 243extern int srv_init_ses(struct session *ses, char* from); 244extern int session_connect(struct session *ses); 245extern int session_disconnect(struct session*ses); 246 247extern int verify_packet( struct session *ses, struct pppoe_packet *p); 248 249extern void copy_tag(struct pppoe_packet *dest, struct pppoe_tag *pt); 250extern struct pppoe_tag *get_tag(struct pppoe_hdr *ph, u_int16_t idx); 251extern int send_disc(struct session *ses, struct pppoe_packet *p); 252 253 254extern int add_client(char *addr); 255 256/* Make connections (including spawning pppd) as server/client */ 257extern ppp_connect(struct session *ses); 258 259 260#endif 261