1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
/*
* Copyright c Realtek Semiconductor Corporation, 2008
* All rights reserved.
*
* Program : ip table driver
* Abstract :
* Author : hyking (hyking_liu@realsil.com.cn)
*/
/* @doc RTL_LAYEREDDRV_API
@module rtl865x_ip.c - RTL865x Home gateway controller Layered driver API documentation |
This document explains the API interface of the table driver module. Functions with rtl865x prefix
are external functions.
@normal Hyking Liu (Hyking_liu@realsil.com.cn) <date>
Copyright <cp>2008 Realtek<tm> Semiconductor Cooperation, All Rights Reserved.
@head3 List of Symbols |
Here is a list of all functions and variables in this module.
@index | RTL_LAYEREDDRV_API
*/
#include <net/rtl/rtl_types.h>
#include <net/rtl/rtl_glue.h>
#include "common/rtl_errno.h"
//#include "rtl_utils.h"
//#include <net/rtl/rtl865x_ip_api.h>
#include "rtl865x_ip.h"
#if defined (CONFIG_RTL_LOCAL_PUBLIC)
#include <net/rtl/rtl865x_localPublic.h>
#endif
#include "common/rtl865x_eventMgr.h" /*call back function....*/
#ifdef CONFIG_RTL_LAYERED_ASIC_DRIVER
#include "AsicDriver/rtl865x_asicCom.h"
#include "AsicDriver/rtl865x_asicL3.h"
#else
#include "AsicDriver/rtl865xC_tblAsicDrv.h"
#endif
static rtl865x_ip_entry_t *rtl865x_ipTable;
#define IP_TABLE_INDEX(entry) (entry - rtl865x_ipTable)
static RTL_DECLARE_MUTEX(ip_sem);
static int32 _rtl865x_delIp(ipaddr_t extIp);
/*
@func int32 | rtl865x_initIpTable | initialize ip table.
@rvalue SUCCESS | Success.
@rvalue FAILED | Failed,system should be reboot.
*/
int32 rtl865x_initIpTable(void)
{
TBL_MEM_ALLOC(rtl865x_ipTable, rtl865x_ip_entry_t, IP_NUMBER);
memset(rtl865x_ipTable,0,sizeof(rtl865x_ip_entry_t)*IP_NUMBER);
return SUCCESS;
}
/*
@func int32 | rtl865x_initIpTable | reinitialize ip table.
@rvalue SUCCESS | Success.
@rvalue FAILED | Failed.
*/
int32 rtl865x_reinitIpTable(void)
{
int32 i ;
for(i = 0; i < IP_NUMBER; i++)
{
if(rtl865x_ipTable[i].valid)
_rtl865x_delIp(rtl865x_ipTable[i].extIp);
}
return SUCCESS;
}
static int32 _rtl865x_addIp(ipaddr_t intIp, ipaddr_t extIp, uint32 ip_type)
{
int i;
rtl865x_ip_entry_t *entry = NULL;
rtl865x_tblAsicDrv_extIntIpParam_t asicIp;
int32 retval = FAILED;
if(ip_type < IP_TYPE_NAPT || ip_type > IP_TYPE_LOCALSERVER)
return RTL_EINVALIDINPUT;
/*duplicate check*/
/*found a valid entry*/
for(i = 0; i < IP_NUMBER; i++)
{
if(rtl865x_ipTable[i].valid == 0)
{
entry = &rtl865x_ipTable[i];
break;
}
else
{
if(rtl865x_ipTable[i].extIp == extIp)
return RTL_EENTRYALREADYEXIST;
if(ip_type == IP_TYPE_NAPT && rtl865x_ipTable[i].type == IP_TYPE_NAPT && rtl865x_ipTable[i].defNaptIp == 1)
return RTL_EENTRYALREADYEXIST;
}
}
if(entry == NULL)
return RTL_ENOFREEBUFFER;
/*update releated information*/
entry->valid = 1;
entry->intIp = intIp;
entry->extIp = extIp;
entry->type = ip_type;
/*from 865xC, this field is invalid...*/
entry->nexthop = NULL;
/*add this ip entry to asic*/
/* Set asic */
bzero(&asicIp, sizeof(rtl865x_tblAsicDrv_extIntIpParam_t));
asicIp.extIpAddr = extIp;
asicIp.intIpAddr = intIp;
asicIp.localPublic = (ip_type == IP_TYPE_LOCALSERVER)? TRUE: FALSE;
asicIp.nat = (ip_type == IP_TYPE_NAT)? TRUE: FALSE;
asicIp.nhIndex = 0;
retval = rtl8651_setAsicExtIntIpTable(IP_TABLE_INDEX(entry), &asicIp);
if(ip_type == IP_TYPE_NAPT)
rtl8651_setAsicOperationLayer(4);
return SUCCESS;
}
static int32 _rtl865x_ipTableIsNull(void)
{
int i;
/*found the entry*/
for(i = 0; i < IP_NUMBER; i++)
{
if(rtl865x_ipTable[i].valid == 1)
{
return FAILED;
}
}
return SUCCESS;
}
static int32 _rtl865x_delIp(ipaddr_t extIp)
{
int i;
rtl865x_ip_entry_t *entry = NULL;
/*found the entry*/
for(i = 0; i < IP_NUMBER; i++)
{
if(rtl865x_ipTable[i].valid == 1 && rtl865x_ipTable[i].extIp == extIp)
{
entry = &rtl865x_ipTable[i];
break;
}
}
/*update asic ip table*/
if(entry!=NULL)
{
rtl8651_delAsicExtIntIpTable(IP_TABLE_INDEX(entry));
memset(entry,0,sizeof(rtl865x_ip_entry_t));
}
else
return RTL_EENTRYNOTFOUND;
//no entry in ip table, set operation to layer 2
if(_rtl865x_ipTableIsNull() == SUCCESS)
{
#if defined(CONFIG_RTL_HARDWARE_MULTICAST)
rtl8651_setAsicOperationLayer(3);
#else
rtl8651_setAsicOperationLayer(2);
#endif
}
return SUCCESS;
}
static rtl865x_ip_entry_t* _rtl865x_getIpEntryByExtIp(ipaddr_t extIp)
{
int32 i;
rtl865x_ip_entry_t *entry = NULL;
for(i = 0; i < IP_NUMBER; i++)
if(rtl865x_ipTable[i].valid == 1 && rtl865x_ipTable[i].extIp == extIp)
{
entry = &rtl865x_ipTable[i];
break;
}
return entry;
}
/*
@func rtl865x_ip_entry_t* | rtl865x_getIpEntryByIp | get ip entry .
@parm ipaddr_t | extIp | ip address
@rvalue ip_entry | Success.
@rvalue NULL | Failed
*/
rtl865x_ip_entry_t* rtl865x_getIpEntryByIp(ipaddr_t extIp)
{
return _rtl865x_getIpEntryByExtIp(extIp);
}
/*
@func int32 | rtl865x_getIpIdxByExtIp | get asic idex .
@parm ipaddr_t | extIp | ip address
@parm int32* | idx | index
@rvalue SUCCESS | Success.
@rvalue FAILED | Failed
*/
int32 rtl865x_getIpIdxByExtIp(ipaddr_t extIp, int32 *idx)
{
int32 retval = FAILED;
rtl865x_ip_entry_t *entry = NULL;
entry = _rtl865x_getIpEntryByExtIp(extIp);
if(entry)
{
if(idx)
*idx = IP_TABLE_INDEX(entry);
retval = SUCCESS;
}
return retval;
}
/*
@func int32 | rtl865x_addIp | add ip table entry.
@parm ipaddr_t | intIp | internal ip address
@parm ipaddr_t | extIp | external ip address
@parm uint32 | ip_type | entry type. support IP_TYPE_NAPT/IP_TYPE_NAT/IP_TYPE_LOCALSERVER
@rvalue SUCCESS | Success.
@rvalue RTL_EINVALIDINPUT | Invalid input.
@rvalue RTL_EENTRYALREADYEXIST | entry already exist.
@rvalue RTL_ENOFREEBUFFER | not enough buffer in System.
@rvalue FAILED | Failed.
@comm
the extIp is the primary key of the ip table.
*/
int32 rtl865x_addIp(ipaddr_t intIp, ipaddr_t extIp, uint32 ip_type)
{
int32 retval = FAILED;
unsigned long flags;
//rtl_down_interruptible(&ip_sem);
local_irq_save(flags);
retval = _rtl865x_addIp(intIp, extIp, ip_type);
//rtl_up(&ip_sem);
local_irq_restore(flags);
return retval;
}
/*
@func int32 | rtl865x_delIp | delete ip table entry.
@parm ipaddr_t | extIp | external ip address
@rvalue SUCCESS | Success.
@rvalue RTL_EINVALIDINPUT | Invalid input.
@rvalue RTL_EENTRYNOTFOUND | not found.
@rvalue FAILED | Failed.
@comm
the extIp is the primary key of the ip table.
*/
int32 rtl865x_delIp(ipaddr_t extIp)
{
int32 retval = FAILED;
unsigned long flags;
//rtl_down_interruptible(&ip_sem);
local_irq_save(flags);
retval = _rtl865x_delIp(extIp);
//rtl_up(&ip_sem);
local_irq_restore(flags);
return retval;
}
int32 rtl865x_getIPIdx(rtl865x_ip_entry_t *entry, int32 *idx)
{
if(idx)
{
*idx =IP_TABLE_INDEX(entry);
return SUCCESS;
}
return FAILED;
}
|