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 */ |
21 | typedef 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 */ |
31 | struct SessionHashStruct; |
32 | typedef 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 */ |
42 | typedef 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 | |
54 | void relayGotSessionPacket(PPPoEInterface const *i); |
55 | void relayGotDiscoveryPacket(PPPoEInterface const *i); |
56 | PPPoEInterface *findInterface(int sock); |
57 | unsigned int hash(unsigned char const *mac, UINT16_t sesNum); |
58 | SessionHash *findSession(unsigned char const *mac, UINT16_t sesNum); |
59 | void deleteHash(SessionHash *hash); |
60 | PPPoESession *createSession(PPPoEInterface const *ac, |
61 | PPPoEInterface const *cli, |
62 | unsigned char const *acMac, |
63 | unsigned char const *cliMac, |
64 | UINT16_t acSes); |
65 | void freeSession(PPPoESession *ses, char const *msg); |
66 | void addInterface(char const *ifname, int clientOK, int acOK); |
67 | void usage(char const *progname); |
68 | void initRelay(int nsess); |
69 | void relayLoop(void); |
70 | void addHash(SessionHash *sh); |
71 | void unhash(SessionHash *sh); |
72 | |
73 | void relayHandlePADT(PPPoEInterface const *iface, PPPoEPacket *packet, int size); |
74 | void relayHandlePADI(PPPoEInterface const *iface, PPPoEPacket *packet, int size); |
75 | void relayHandlePADO(PPPoEInterface const *iface, PPPoEPacket *packet, int size); |
76 | void relayHandlePADR(PPPoEInterface const *iface, PPPoEPacket *packet, int size); |
77 | void relayHandlePADS(PPPoEInterface const *iface, PPPoEPacket *packet, int size); |
78 | |
79 | int addTag(PPPoEPacket *packet, PPPoETag const *tag); |
80 | int insertBytes(PPPoEPacket *packet, unsigned char *loc, |
81 | void const *bytes, int length); |
82 | int removeBytes(PPPoEPacket *packet, unsigned char *loc, |
83 | int length); |
84 | void 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 | |
91 | void alarmHandler(int sig); |
92 | void 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 |