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#include "pppd.h" 58 59#define CONNECTED 1 60#define DISCONNECTED 0 61 62#ifndef _PATH_PPPD 63#define _PATH_PPPD "/usr/sbin/pppd" 64#endif 65 66#ifndef LOG_PPPOE 67#define LOG_PPPOE LOG_DAEMON 68#endif 69 70 71#define VERSION_MAJOR 0 72#define VERSION_MINOR 4 73#define VERSION_DATE 991120 74 75/* Bigger than the biggest ethernet packet we'll ever see, in bytes */ 76#define MAX_PACKET 2000 77 78/* references: RFC 2516 */ 79/* ETHER_TYPE fields for PPPoE */ 80 81#define ETH_P_PPPOE_DISC 0x8863 /* discovery stage */ 82#define ETH_P_PPPOE_SESS 0x8864 83 84/* ethernet broadcast address */ 85#define MAC_BCAST_ADDR "\xff\xff\xff\xff\xff\xff" 86 87/* Format for parsing long device-name */ 88#define _STR(x) #x 89#define FMTSTRING(size) "%x:%x:%x:%x:%x:%x/%x/%" _STR(size) "s" 90 91/* maximum payload length */ 92#define MAX_PAYLOAD 1484 93 94 95 96/* PPPoE tag types */ 97#define MAX_TAGS 11 98 99 100/* PPPoE packet; includes Ethernet headers and such */ 101struct pppoe_packet{ 102 struct sockaddr_ll addr; 103 struct pppoe_tag *tags[MAX_TAGS]; 104 struct pppoe_hdr *hdr; 105 char buf[MAX_PAYLOAD]; /* buffer in which tags are held */ 106}; 107/* Defines meaning of each "tags" element */ 108 109#define TAG_SRV_NAME 0 110#define TAG_AC_NAME 1 111#define TAG_HOST_UNIQ 2 112#define TAG_AC_COOKIE 3 113#define TAG_VENDOR 4 114#define TAG_RELAY_SID 5 115#define TAG_SRV_ERR 6 116#define TAG_SYS_ERR 7 117#define TAG_GEN_ERR 8 118#define TAG_EOL 9 119 120/* Debug flags */ 121int DEB_DISC,DEB_DISC2; 122/* 123 #define DEB_DISC (opt_debug & 0x0002) 124 #define DEB_DISC2 (opt_debug & 0x0004) 125*/ 126#define MAX_FNAME 256 127 128 129struct session; 130 131/* return <0 --> fatal error; abor 132 return =0 --> ok, proceed 133 return >0 --> ok, qui 134*/ 135typedef int (*packet_cb_t)(struct session* ses, 136 struct pppoe_packet *p_in, 137 struct pppoe_packet **p_out); 138 139/* various override filter tags */ 140struct filter { 141 struct pppoe_tag *stag; /* service name tag override */ 142 struct pppoe_tag *ntag; /*AC name override */ 143 struct pppoe_tag *htag; /* hostuniq override */ 144 int num_restart; 145 int peermode; 146 char *fname; 147 char *pppd; 148} __attribute__ ((packed)); 149 150 151struct pppoe_tag *make_filter_tag(short type, short length, char* data); 152 153/* Session type definitions */ 154#define SESSION_CLIENT 0 155#define SESSION_SERVER 1 156#define SESSION_RELAY 2 157 158struct session { 159 160 /* Administrative */ 161 int type; 162 int opt_debug; 163 int detached; 164 int np; 165 int log_to_fd; 166 int ifindex; /* index of device */ 167 char name[IFNAMSIZ]; /*dev name */ 168 struct pppoe_packet curr_pkt; 169 170 packet_cb_t init_disc; 171 packet_cb_t rcv_pado; 172 packet_cb_t rcv_padi; 173 packet_cb_t rcv_pads; 174 packet_cb_t rcv_padr; 175 packet_cb_t rcv_padt; 176 packet_cb_t timeout; 177 178 179 /* Generic */ 180 struct filter *filt; 181 struct sockaddr_ll local; 182 struct sockaddr_ll remote; 183 struct sockaddr_pppox sp; 184 int fd; /* fd of PPPoE socket */ 185 186 187 /* For client */ 188 int retransmits; /* Number of retransmission performed 189 if < 0 , retransmissions disabled */ 190 int retries; 191 int state; 192 int opt_daemonize; 193 194 /* For server */ 195 int fork; 196 197 /* For forwarding */ 198 int fwd_sock; 199 char fwd_name[IFNAMSIZ]; /* Name of device to forward to */ 200} __attribute__ ((packed)); 201 202/* 203 retransmit retries for the PADR and PADI packets 204 during discovery 205*/ 206int PADR_ret; 207int PADI_ret; 208 209int log_to_fd; 210int ctrl_fd; 211int opt_debug; 212int opt_daemonize; 213 214 215/* Structure for keeping track of connection relays */ 216struct pppoe_con{ 217 struct pppoe_con *next; 218 int id; 219 int connected; 220 int cl_sock; 221 int sv_sock; 222 int ref_count; 223 char client[ETH_ALEN]; 224 char server[ETH_ALEN]; 225 char key_len; 226 char key[32]; 227}; 228 229/* Functions exported from utils.c. */ 230 231/* Functions exported from pppoehash.c */ 232struct pppoe_con *get_con(int len, char *key); 233int store_con(struct pppoe_con *pc); 234struct pppoe_con *delete_con(unsigned long len, char *key); 235 236/* exported by lib.c */ 237 238extern int init_lib(); 239 240extern int get_sockaddr_ll(const char *devnam,struct sockaddr_ll* sll); 241 242extern int client_init_ses (struct session *ses, char* devnam); 243extern int relay_init_ses(struct session *ses, char* from, char* to); 244extern int srv_init_ses(struct session *ses, char* from); 245extern int session_connect(struct session *ses); 246extern int session_disconnect(struct session*ses); 247 248extern int verify_packet( struct session *ses, struct pppoe_packet *p); 249 250extern void copy_tag(struct pppoe_packet *dest, struct pppoe_tag *pt); 251extern struct pppoe_tag *get_tag(struct pppoe_hdr *ph, u_int16_t idx); 252extern int send_disc(struct session *ses, struct pppoe_packet *p); 253 254 255extern int add_client(char *addr); 256 257/* Make connections (including spawning pppd) as server/client */ 258extern int ppp_connect(struct session *ses); 259 260#include <pppd.h> 261 262#define poe_die die 263 264#ifdef DEBUG 265#define poe_dbglog(ses,a,b...) dbglog(a, ## b) 266#define poe_info(ses,a,b...) info(a, ## b) 267#define poe_notice(ses,a,b...) notice(a, ## b) 268#define poe_warn(ses,a,b...) warn(a, ## b) 269#define poe_error(ses,a,b...) error(a, ## b) 270#define poe_fatal(ses,a,b...) fatal(a, ## b) 271#else 272#define poe_dbglog(a,b...) 273#define poe_info(a,b...) 274#define poe_notice(a,b...) 275#define poe_warn(a,b...) 276#define poe_error(a,b...) 277#define poe_fatal(a,b...) 278#endif 279 280#endif 281