summaryrefslogtreecommitdiff
path: root/src/pppoe-server.h (plain)
blob: ba4635fc326ffd65281b484031b44508cb8e4577
1/**********************************************************************
2*
3* pppoe-server.h
4*
5* Definitions for PPPoE server
6*
7* Copyright (C) 2001-2006 Roaring Penguin Software Inc.
8*
9* This program may be distributed according to the terms of the GNU
10* General Public License, version 2 or (at your option) any later version.
11*
12* LIC: GPL
13*
14* $Id$
15*
16***********************************************************************/
17
18#include "pppoe.h"
19#include "event.h"
20
21#ifdef HAVE_L2TP
22#include "l2tp/l2tp.h"
23#endif
24
25#define MAX_USERNAME_LEN 31
26/* An Ethernet interface */
27typedef struct {
28 char name[IFNAMSIZ+1]; /* Interface name */
29 int sock; /* Socket for discovery frames */
30 unsigned char mac[ETH_ALEN]; /* MAC address */
31 EventHandler *eh; /* Event handler for this interface */
32
33 /* Next fields are used only if we're an L2TP LAC */
34#ifdef HAVE_L2TP
35 int session_sock; /* Session socket */
36 EventHandler *lac_eh; /* LAC's event-handler */
37#endif
38} Interface;
39
40#define FLAG_RECVD_PADT 1
41#define FLAG_USER_SET 2
42#define FLAG_IP_SET 4
43#define FLAG_SENT_PADT 8
44
45/* Only used if we are an L2TP LAC or LNS */
46#define FLAG_ACT_AS_LAC 256
47#define FLAG_ACT_AS_LNS 512
48
49/* Forward declaration */
50struct ClientSessionStruct;
51
52/* Dispatch table for session-related functions. We call different
53 functions for L2TP-terminated sessions than for locally-terminated
54 sessions. */
55typedef struct PppoeSessionFunctionTable_t {
56 /* Stop the session */
57 void (*stop)(struct ClientSessionStruct *ses, char const *reason);
58
59 /* Return 1 if session is active, 0 otherwise */
60 int (*isActive)(struct ClientSessionStruct *ses);
61
62 /* Describe a session in human-readable form */
63 char const * (*describe)(struct ClientSessionStruct *ses);
64} PppoeSessionFunctionTable;
65
66extern PppoeSessionFunctionTable DefaultSessionFunctionTable;
67
68/* A client session */
69typedef struct ClientSessionStruct {
70 struct ClientSessionStruct *next; /* In list of free or active sessions */
71 PppoeSessionFunctionTable *funcs; /* Function table */
72 pid_t pid; /* PID of child handling session */
73 Interface *ethif; /* Ethernet interface */
74 unsigned char myip[IPV4ALEN]; /* Local IP address */
75 unsigned char peerip[IPV4ALEN]; /* Desired IP address of peer */
76 UINT16_t sess; /* Session number */
77 unsigned char eth[ETH_ALEN]; /* Peer's Ethernet address */
78 unsigned int flags; /* Various flags */
79 time_t startTime; /* When session started */
80 char const *serviceName; /* Service name */
81#ifdef HAVE_LICENSE
82 char user[MAX_USERNAME_LEN+1]; /* Authenticated user-name */
83 char realm[MAX_USERNAME_LEN+1]; /* Realm */
84 unsigned char realpeerip[IPV4ALEN]; /* Actual IP address -- may be assigned
85 by RADIUS server */
86 int maxSessionsPerUser; /* Max sessions for this user */
87#endif
88#ifdef HAVE_L2TP
89 l2tp_session *l2tp_ses; /* L2TP session */
90 struct sockaddr_in tunnel_endpoint; /* L2TP endpoint */
91#endif
92} ClientSession;
93
94/* Hack for daemonizing */
95#define CLOSEFD 64
96
97/* Max. number of interfaces to listen on */
98#define MAX_INTERFACES 64
99
100/* Max. 64 sessions by default */
101#define DEFAULT_MAX_SESSIONS 64
102
103/* An array of client sessions */
104extern ClientSession *Sessions;
105
106/* Interfaces we're listening on */
107extern Interface interfaces[MAX_INTERFACES];
108extern int NumInterfaces;
109
110/* The number of session slots */
111extern size_t NumSessionSlots;
112
113/* The number of active sessions */
114extern size_t NumActiveSessions;
115
116/* Offset of first session */
117extern size_t SessOffset;
118
119/* Access concentrator name */
120extern char *ACName;
121
122extern unsigned char LocalIP[IPV4ALEN];
123extern unsigned char RemoteIP[IPV4ALEN];
124
125/* Do not create new sessions if free RAM < 10MB (on Linux only!) */
126#define MIN_FREE_MEMORY 10000
127
128/* Do we increment local IP for each connection? */
129extern int IncrLocalIP;
130
131/* Free sessions */
132extern ClientSession *FreeSessions;
133
134/* When a session is freed, it is added to the end of the free list */
135extern ClientSession *LastFreeSession;
136
137/* Busy sessions */
138extern ClientSession *BusySessions;
139
140extern EventSelector *event_selector;
141extern int GotAlarm;
142
143extern void setAlarm(unsigned int secs);
144extern void killAllSessions(void);
145extern void serverProcessPacket(Interface *i);
146extern void processPADT(Interface *ethif, PPPoEPacket *packet, int len);
147extern void processPADR(Interface *ethif, PPPoEPacket *packet, int len);
148extern void processPADI(Interface *ethif, PPPoEPacket *packet, int len);
149extern void usage(char const *msg);
150extern ClientSession *pppoe_alloc_session(void);
151extern int pppoe_free_session(ClientSession *ses);
152extern void sendHURLorMOTM(PPPoEConnection *conn, char const *url, UINT16_t tag);
153
154#ifdef HAVE_LICENSE
155extern int getFreeMem(void);
156#endif
157