summaryrefslogtreecommitdiff
path: root/src/relay.h (plain)
blob: 36d89a7cc73573bb32b256d314f4f3baa0917c53
1/**********************************************************************
2*
3* relay.h
4*
5* Definitions for PPPoE relay
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
20/* Description for each active Ethernet interface */
21typedef struct InterfaceStruct {
22 char name[IFNAMSIZ+1]; /* Interface name */
23 int discoverySock; /* Socket for discovery frames */
24 int sessionSock; /* Socket for session frames */
25 int clientOK; /* Client requests allowed (PADI, PADR) */
26 int acOK; /* AC replies allowed (PADO, PADS) */
27 unsigned char mac[ETH_ALEN]; /* MAC address */
28} PPPoEInterface;
29
30/* Session state for relay */
31struct SessionHashStruct;
32typedef struct SessionStruct {
33 struct SessionStruct *next; /* Free list link */
34 struct SessionStruct *prev; /* Free list link */
35 struct SessionHashStruct *acHash; /* Hash bucket for AC MAC/Session */
36 struct SessionHashStruct *clientHash; /* Hash bucket for client MAC/Session */
37 unsigned int epoch; /* Epoch when last activity was seen */
38 UINT16_t sesNum; /* Session number assigned by relay */
39} PPPoESession;
40
41/* Hash table entry to find sessions */
42typedef struct SessionHashStruct {
43 struct SessionHashStruct *next; /* Link in hash chain */
44 struct SessionHashStruct *prev; /* Link in hash chain */
45 struct SessionHashStruct *peer; /* Peer for this session */
46 PPPoEInterface const *interface; /* Interface */
47 unsigned char peerMac[ETH_ALEN]; /* Peer's MAC address */
48 UINT16_t sesNum; /* Session number */
49 PPPoESession *ses; /* Session data */
50} SessionHash;
51
52/* Function prototypes */
53
54void relayGotSessionPacket(PPPoEInterface const *i);
55void relayGotDiscoveryPacket(PPPoEInterface const *i);
56PPPoEInterface *findInterface(int sock);
57unsigned int hash(unsigned char const *mac, UINT16_t sesNum);
58SessionHash *findSession(unsigned char const *mac, UINT16_t sesNum);
59void deleteHash(SessionHash *hash);
60PPPoESession *createSession(PPPoEInterface const *ac,
61 PPPoEInterface const *cli,
62 unsigned char const *acMac,
63 unsigned char const *cliMac,
64 UINT16_t acSes);
65void freeSession(PPPoESession *ses, char const *msg);
66void addInterface(char const *ifname, int clientOK, int acOK);
67void usage(char const *progname);
68void initRelay(int nsess);
69void relayLoop(void);
70void addHash(SessionHash *sh);
71void unhash(SessionHash *sh);
72
73void relayHandlePADT(PPPoEInterface const *iface, PPPoEPacket *packet, int size);
74void relayHandlePADI(PPPoEInterface const *iface, PPPoEPacket *packet, int size);
75void relayHandlePADO(PPPoEInterface const *iface, PPPoEPacket *packet, int size);
76void relayHandlePADR(PPPoEInterface const *iface, PPPoEPacket *packet, int size);
77void relayHandlePADS(PPPoEInterface const *iface, PPPoEPacket *packet, int size);
78
79int addTag(PPPoEPacket *packet, PPPoETag const *tag);
80int insertBytes(PPPoEPacket *packet, unsigned char *loc,
81 void const *bytes, int length);
82int removeBytes(PPPoEPacket *packet, unsigned char *loc,
83 int length);
84void relaySendError(unsigned char code,
85 UINT16_t session,
86 PPPoEInterface const *iface,
87 unsigned char const *mac,
88 PPPoETag const *hostUniq,
89 char const *errMsg);
90
91void alarmHandler(int sig);
92void cleanSessions(void);
93
94#define MAX_INTERFACES 8
95#define DEFAULT_SESSIONS 5000
96
97/* Hash table size -- a prime number; gives load factor of around 6
98 for 65534 sessions */
99#define HASHTAB_SIZE 18917
100