Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
babeld
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
babeld
Commits
21b9773f
Commit
21b9773f
authored
May 19, 2008
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sources table into a linked list.
parent
c9b1416d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
58 deletions
+35
-58
babel.h
babel.h
+0
-2
source.c
source.c
+33
-54
source.h
source.h
+2
-2
No files found.
babel.h
View file @
21b9773f
...
...
@@ -20,8 +20,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#define MAXSRCS 256
#define INFINITY ((unsigned short)(~0))
#ifndef RTPROT_BABEL
...
...
source.c
View file @
21b9773f
...
...
@@ -30,61 +30,42 @@ THE SOFTWARE.
#include "network.h"
#include "route.h"
struct
source
srcs
[
MAXSRCS
];
int
numsrcs
=
0
;
struct
source
*
srcs
=
NULL
;
struct
source
*
struct
source
*
find_source
(
const
unsigned
char
*
id
,
const
unsigned
char
*
p
,
unsigned
char
plen
,
int
create
,
unsigned
short
seqno
)
{
struct
source
*
src
;
int
i
,
rc
;
for
(
i
=
0
;
i
<
numsrcs
;
i
++
)
{
if
(
!
srcs
[
i
].
valid
)
continue
;
for
(
src
=
srcs
;
src
;
src
=
src
->
next
)
{
/* This should really be a hash table. For now, check the
last byte first. */
if
(
src
s
[
i
].
id
[
15
]
!=
id
[
15
])
if
(
src
->
id
[
15
]
!=
id
[
15
])
continue
;
if
(
memcmp
(
src
s
[
i
].
id
,
id
,
16
)
!=
0
)
if
(
memcmp
(
src
->
id
,
id
,
16
)
!=
0
)
continue
;
if
(
source_match
(
&
srcs
[
i
]
,
p
,
plen
))
return
&
srcs
[
i
]
;
if
(
source_match
(
src
,
p
,
plen
))
return
src
;
}
if
(
!
create
)
return
NULL
;
again:
src
=
NULL
;
for
(
i
=
0
;
i
<
numsrcs
;
i
++
)
{
if
(
srcs
[
i
].
valid
==
0
)
{
src
=
&
srcs
[
i
];
break
;
}
}
if
(
!
src
)
{
if
(
numsrcs
>=
MAXSRCS
)
{
rc
=
expire_sources
();
if
(
rc
)
goto
again
;
fprintf
(
stderr
,
"Too many sources.
\n
"
);
src
=
malloc
(
sizeof
(
struct
source
));
if
(
src
==
NULL
)
{
perror
(
"malloc(source)"
);
return
NULL
;
}
src
=
&
srcs
[
numsrcs
++
];
}
src
->
valid
=
1
;
memcpy
(
src
->
id
,
id
,
16
);
memcpy
(
src
->
prefix
,
p
,
16
);
src
->
plen
=
plen
;
src
->
seqno
=
seqno
;
src
->
metric
=
INFINITY
;
src
->
time
=
now
.
tv_sec
;
src
->
next
=
srcs
;
srcs
=
src
;
return
src
;
}
...
...
@@ -92,21 +73,21 @@ int
flush_source
(
struct
source
*
src
)
{
int
i
;
for
(
i
=
0
;
i
<
numroutes
;
i
++
)
{
if
(
routes
[
i
].
src
==
src
)
return
0
;
}
memset
(
src
,
0
,
sizeof
(
*
src
));
VALGRIND_MAKE_MEM_UNDEFINED
(
src
,
sizeof
(
*
src
))
;
src
->
valid
=
0
;
while
(
numsrcs
>
0
&&
!
srcs
[
numsrcs
-
1
].
valid
)
{
numsrcs
--
;
VALGRIND_MAKE_MEM_UNDEFINED
(
&
srcs
[
numsrcs
],
sizeof
(
srcs
[
numsrcs
]))
;
if
(
srcs
==
src
)
{
srcs
=
src
->
next
;
}
else
{
struct
source
*
previous
=
src
;
while
(
previous
->
next
!=
src
)
previous
=
previous
->
next
;
previous
->
next
=
src
->
next
;
}
free
(
src
);
return
1
;
}
...
...
@@ -139,24 +120,22 @@ update_source(struct source *src,
src
->
time
=
now
.
tv_sec
;
}
int
void
expire_sources
()
{
int
i
,
changed
,
rc
;
changed
=
0
;
struct
source
*
src
;
for
(
i
=
0
;
i
<
numsrcs
;
i
++
)
{
if
(
!
srcs
[
i
].
valid
)
continue
;
if
(
srcs
[
i
].
time
>
now
.
tv_sec
)
src
=
srcs
;
while
(
src
)
{
if
(
src
->
time
>
now
.
tv_sec
)
/* clock stepped */
srcs
[
i
].
time
=
now
.
tv_sec
;
if
(
srcs
[
i
].
time
<
now
.
tv_sec
-
SOURCE_GC_TIME
)
{
rc
=
flush_source
(
&
srcs
[
i
]);
changed
=
changed
||
rc
;
src
->
time
=
now
.
tv_sec
;
if
(
src
->
time
<
now
.
tv_sec
-
SOURCE_GC_TIME
)
{
struct
source
*
old
=
src
;
src
=
src
->
next
;
flush_source
(
old
);
continue
;
}
src
=
src
->
next
;
}
return
changed
;
}
source.h
View file @
21b9773f
...
...
@@ -23,10 +23,10 @@ THE SOFTWARE.
#define SOURCE_GC_TIME 200
struct
source
{
struct
source
*
next
;
unsigned
char
id
[
16
];
unsigned
char
prefix
[
16
];
unsigned
char
plen
;
unsigned
char
valid
;
unsigned
short
seqno
;
unsigned
short
metric
;
time_t
time
;
...
...
@@ -41,4 +41,4 @@ struct source *find_source(const unsigned char *id,
int
flush_source
(
struct
source
*
src
);
void
update_source
(
struct
source
*
src
,
unsigned
short
seqno
,
unsigned
short
metric
);
int
expire_sources
(
void
);
void
expire_sources
(
void
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment