Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
W
wr-switch-sw
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
white-rabbit
wr-switch-sw
Commits
5181075e
Commit
5181075e
authored
Jun 12, 2014
by
Alessandro Rubini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools/wrsw_vlans: added error checks, simplify allocation
Signed-off-by:
Alessandro Rubini
<
rubini@gnudd.com
>
parent
91dc866a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
23 deletions
+33
-23
wrsw_vlans.c
userspace/tools/wrsw_vlans.c
+32
-22
wrsw_vlans.h
userspace/tools/wrsw_vlans.h
+1
-1
No files found.
userspace/tools/wrsw_vlans.c
View file @
5181075e
...
...
@@ -204,7 +204,8 @@ int main(int argc, char *argv[])
/****************************************************/
/* Other settings */
case
OPT_CLEAR
:
clear_all
();
if
(
clear_all
())
exit
(
1
);
/* message already printed */
break
;
case
OPT_DEBUG
:
case
0
:
...
...
@@ -296,7 +297,7 @@ int config_rtud(void)
struct
rtu_vlans_t
*
old_list
,
*
old_entry
;
int
ret
,
val
;
old_list
=
rtu_re
ad
_config
();
old_list
=
rtu_re
trieve
_config
();
cur
=
rtu_vlans
;
while
(
cur
)
{
...
...
@@ -363,7 +364,13 @@ int clear_all()
int
idx
=
0
,
i
,
val
;
do
{
minipc_call
(
rtud_ch
,
MINIPC_TIMEOUT
,
&
rtud_export_get_vd_list
,
&
vlist
,
idx
);
if
(
minipc_call
(
rtud_ch
,
MINIPC_TIMEOUT
,
&
rtud_export_get_vd_list
,
&
vlist
,
idx
)
<
0
)
{
/* Duplicated from above */
fprintf
(
stderr
,
"%s: minipc_call: %s
\n
"
,
prgname
,
strerror
(
errno
));
return
-
1
;
}
/*remove vlans from the list*/
for
(
i
=
0
;
i
<
vlist
.
num_entries
;
++
i
)
{
ventry
=
&
vlist
.
list
[
i
];
...
...
@@ -453,33 +460,36 @@ void free_rtu_vlans(struct rtu_vlans_t *ptr)
}
}
struct
rtu_vlans_t
*
rtu_re
ad_config
(
)
struct
rtu_vlans_t
*
rtu_re
trieve_config
(
void
)
{
rtudexp_vd_list_t
vlist
;
rtudexp_vd_entry_t
*
ventry
;
int
idx
=
0
,
i
;
struct
rtu_vlans_t
*
config
=
NULL
,
*
cur
=
NULL
;
struct
rtu_vlans_t
*
config
=
NULL
,
*
cur
=
NULL
,
*
ptr
;
do
{
minipc_call
(
rtud_ch
,
MINIPC_TIMEOUT
,
&
rtud_export_get_vd_list
,
&
vlist
,
idx
);
if
(
minipc_call
(
rtud_ch
,
MINIPC_TIMEOUT
,
&
rtud_export_get_vd_list
,
&
vlist
,
idx
)
<
0
)
{
/* Duplicated from above */
fprintf
(
stderr
,
"%s: minipc_call: %s
\n
"
,
prgname
,
strerror
(
errno
));
return
config
;
/* maybe partly good */
}
for
(
i
=
0
;
i
<
vlist
.
num_entries
;
++
i
)
{
ventry
=
&
vlist
.
list
[
i
];
if
(
config
==
NULL
)
{
config
=
(
struct
rtu_vlans_t
*
)
malloc
(
sizeof
(
struct
rtu_vlans_t
));
cur
=
config
;
if
(
config
==
NULL
)
{
fprintf
(
stderr
,
"Could not allocate memory for reading RTUd VLAN tab
\n
"
);
return
NULL
;
}
ptr
=
malloc
(
sizeof
(
struct
rtu_vlans_t
));
if
(
!
ptr
)
{
fprintf
(
stderr
,
"%s: reading RTUd table: %s
\n
"
,
prgname
,
strerror
(
errno
));
return
config
;
/* may be partly good */
}
else
{
cur
->
next
=
(
struct
rtu_vlans_t
*
)
malloc
(
sizeof
(
struct
rtu_vlans_t
))
;
if
(
cur
->
next
==
NULL
)
{
fprintf
(
stderr
,
"Could not allocate memory for reading RTUd VLAN tab
\n
"
);
free_rtu_vlans
(
config
)
;
return
NULL
;
}
cur
=
cur
->
next
;
ventry
=
&
vlist
.
list
[
i
]
;
if
(
config
==
NULL
)
{
/* first item */
config
=
cur
=
ptr
;
}
else
{
cur
->
next
=
ptr
;
cur
=
ptr
;
}
cur
->
vid
=
ventry
->
vid
;
cur
->
fid
=
ventry
->
fid
;
...
...
userspace/tools/wrsw_vlans.h
View file @
5181075e
...
...
@@ -88,7 +88,7 @@ int clear_all();
int
set_rtu_vlan
(
int
vid
,
int
fid
,
int
pmask
,
int
drop
,
int
prio
,
int
del
,
int
flags
);
void
free_rtu_vlans
(
struct
rtu_vlans_t
*
ptr
);
void
list_rtu_vlans
(
void
);
struct
rtu_vlans_t
*
rtu_re
ad_config
(
);
struct
rtu_vlans_t
*
rtu_re
trieve_config
(
void
);
struct
rtu_vlans_t
*
rtu_find_vlan
(
struct
rtu_vlans_t
*
conf
,
int
vid
,
int
fid
);
int
config_rtud
(
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