ReactOS 0.4.16-dev-297-gc569aee
FDB example code
Collaboration diagram for FDB example code:

Functions

void bridgeif_fdb_update_src (void *fdb_ptr, struct eth_addr *src_addr, u8_t port_idx)
 
bridgeif_portmask_t bridgeif_fdb_get_dst_ports (void *fdb_ptr, struct eth_addr *dst_addr)
 
static void bridgeif_fdb_age_one_second (void *fdb_ptr)
 
voidbridgeif_fdb_init (u16_t max_fdb_entries)
 

Detailed Description

This file implements an example for an FDB (Forwarding DataBase)

Function Documentation

◆ bridgeif_fdb_age_one_second()

static void bridgeif_fdb_age_one_second ( void fdb_ptr)
static

Aging implementation of our simple fdb

Definition at line 153 of file bridgeif_fdb.c.

154{
155 int i;
156 bridgeif_dfdb_t *fdb;
158
159 fdb = (bridgeif_dfdb_t *)fdb_ptr;
161
162 for (i = 0; i < fdb->max_fdb_entries; i++) {
163 bridgeif_dfdb_entry_t *e = &fdb->fdb[i];
164 if (e->used && e->ts) {
166 /* check again when protected */
167 if (e->used && e->ts) {
168 if (--e->ts == 0) {
169 e->used = 0;
170 }
171 }
173 }
174 }
176}
#define BRIDGEIF_READ_UNPROTECT(lev)
Definition: bridgeif.h:118
#define BRIDGEIF_DECL_PROTECT(lev)
Definition: bridgeif.h:116
#define BRIDGEIF_READ_PROTECT(lev)
Definition: bridgeif.h:117
#define BRIDGEIF_WRITE_UNPROTECT(lev)
Definition: bridgeif.h:120
#define BRIDGEIF_WRITE_PROTECT(lev)
Definition: bridgeif.h:119
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define e
Definition: ke_i.h:82
Definition: bridgeif_fdb.c:54
u16_t max_fdb_entries
Definition: bridgeif_fdb.c:62
bridgeif_dfdb_entry_t * fdb
Definition: bridgeif_fdb.c:63

Referenced by bridgeif_age_tmr().

◆ bridgeif_fdb_get_dst_ports()

bridgeif_portmask_t bridgeif_fdb_get_dst_ports ( void fdb_ptr,
struct eth_addr dst_addr 
)

Walk our list of auto-learnt fdb entries and return a port to forward or BR_FLOOD if unknown

Definition at line 128 of file bridgeif_fdb.c.

129{
130 int i;
131 bridgeif_dfdb_t *fdb = (bridgeif_dfdb_t *)fdb_ptr;
134 for (i = 0; i < fdb->max_fdb_entries; i++) {
135 bridgeif_dfdb_entry_t *e = &fdb->fdb[i];
136 if (e->used && e->ts) {
137 if (!memcmp(&e->addr, dst_addr, sizeof(struct eth_addr))) {
140 return ret;
141 }
142 }
143 }
145 return BR_FLOOD;
146}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define BR_FLOOD
Definition: bridgeif.h:63
u8_t bridgeif_portmask_t
Definition: bridgeif.h:54
int ret

◆ bridgeif_fdb_init()

void * bridgeif_fdb_init ( u16_t  max_fdb_entries)

Init our simple fdb list

Definition at line 195 of file bridgeif_fdb.c.

196{
197 bridgeif_dfdb_t *fdb;
198 size_t alloc_len_sizet = sizeof(bridgeif_dfdb_t) + (max_fdb_entries * sizeof(bridgeif_dfdb_entry_t));
199 mem_size_t alloc_len = (mem_size_t)alloc_len_sizet;
200 LWIP_ASSERT("alloc_len == alloc_len_sizet", alloc_len == alloc_len_sizet);
201 LWIP_DEBUGF(BRIDGEIF_DEBUG, ("bridgeif_fdb_init: allocating %d bytes for private FDB data\n", (int)alloc_len));
202 fdb = (bridgeif_dfdb_t *)mem_calloc(1, alloc_len);
203 if (fdb == NULL) {
204 return NULL;
205 }
206 fdb->max_fdb_entries = max_fdb_entries;
207 fdb->fdb = (bridgeif_dfdb_entry_t *)(fdb + 1);
208
209 sys_timeout(BRIDGEIF_AGE_TIMER_MS, bridgeif_age_tmr, fdb);
210
211 return fdb;
212}
struct bridgeif_dfdb_s bridgeif_dfdb_t
#define BRIDGEIF_AGE_TIMER_MS
Definition: bridgeif_fdb.c:50
static void bridgeif_age_tmr(void *arg)
Definition: bridgeif_fdb.c:180
#define NULL
Definition: types.h:112
void * mem_calloc(mem_size_t count, mem_size_t size)
Definition: mem.c:999
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:158
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:116
u16_t mem_size_t
Definition: mem.h:67
#define BRIDGEIF_DEBUG
Definition: bridgeif_opts.h:73

◆ bridgeif_fdb_update_src()

void bridgeif_fdb_update_src ( void fdb_ptr,
struct eth_addr src_addr,
u8_t  port_idx 
)

A real simple and slow implementation of an auto-learning forwarding database that remembers known src mac addresses to know which port to send frames destined for that mac address.

ATTENTION: This is meant as an example only, in real-world use, you should provide a better implementation :-)

Definition at line 76 of file bridgeif_fdb.c.

77{
78 int i;
79 bridgeif_dfdb_t *fdb = (bridgeif_dfdb_t *)fdb_ptr;
82 for (i = 0; i < fdb->max_fdb_entries; i++) {
83 bridgeif_dfdb_entry_t *e = &fdb->fdb[i];
84 if (e->used && e->ts) {
85 if (!memcmp(&e->addr, src_addr, sizeof(struct eth_addr))) {
86 LWIP_DEBUGF(BRIDGEIF_FDB_DEBUG, ("br: update src %02x:%02x:%02x:%02x:%02x:%02x (from %d) @ idx %d\n",
87 src_addr->addr[0], src_addr->addr[1], src_addr->addr[2], src_addr->addr[3], src_addr->addr[4], src_addr->addr[5],
88 port_idx, i));
91 e->port = port_idx;
94 return;
95 }
96 }
97 }
98 /* not found, allocate new entry from free */
99 for (i = 0; i < fdb->max_fdb_entries; i++) {
100 bridgeif_dfdb_entry_t *e = &fdb->fdb[i];
101 if (!e->used || !e->ts) {
103 /* check again when protected */
104 if (!e->used || !e->ts) {
105 LWIP_DEBUGF(BRIDGEIF_FDB_DEBUG, ("br: create src %02x:%02x:%02x:%02x:%02x:%02x (from %d) @ idx %d\n",
106 src_addr->addr[0], src_addr->addr[1], src_addr->addr[2], src_addr->addr[3], src_addr->addr[4], src_addr->addr[5],
107 port_idx, i));
108 memcpy(&e->addr, src_addr, sizeof(struct eth_addr));
109 e->ts = BR_FDB_TIMEOUT_SEC;
110 e->port = port_idx;
111 e->used = 1;
114 return;
115 }
117 }
118 }
120 /* not found, no free entry -> flood */
121}
#define BR_FDB_TIMEOUT_SEC
Definition: bridgeif_fdb.c:52
#define BRIDGEIF_FDB_DEBUG
Definition: bridgeif_opts.h:78
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878