Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ycai
simbricks
Commits
4d0690d1
"vscode:/vscode.git/clone" did not exist on "6130394165d2fe0e5013db93b2aa8cac7f3ef3d9"
Commit
4d0690d1
authored
Apr 22, 2022
by
Antoine Kaufmann
Browse files
sims/net/tap: new API refactor
parent
2f308d01
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
17 deletions
+25
-17
sims/net/tap/net_tap.c
sims/net/tap/net_tap.c
+24
-16
sims/net/tap/rules.mk
sims/net/tap/rules.mk
+1
-1
No files found.
sims/net/tap/net_tap.c
View file @
4d0690d1
...
@@ -33,7 +33,7 @@
...
@@ -33,7 +33,7 @@
#include <sys/mman.h>
#include <sys/mman.h>
#include <unistd.h>
#include <unistd.h>
#include <simbricks/net
if/net
if.h>
#include <simbricks/net
work/
if.h>
// #define DEBUG_PKTMETA
// #define DEBUG_PKTMETA
...
@@ -51,7 +51,13 @@ static int tap_open(const char *name) {
...
@@ -51,7 +51,13 @@ static int tap_open(const char *name) {
memset
(
&
ifr
,
0
,
sizeof
(
ifr
));
memset
(
&
ifr
,
0
,
sizeof
(
ifr
));
ifr
.
ifr_flags
=
IFF_TAP
|
IFF_NO_PI
;
ifr
.
ifr_flags
=
IFF_TAP
|
IFF_NO_PI
;
/* fix gcc warning here: this is okay, kernel will nul-terminate ifr name,
if neeeded, no need for us to worry */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-truncation"
strncpy
(
ifr
.
ifr_name
,
name
,
IFNAMSIZ
);
strncpy
(
ifr
.
ifr_name
,
name
,
IFNAMSIZ
);
#pragma GCC diagnostic pop
if
(
ioctl
(
fd
,
TUNSETIFF
,
&
ifr
)
!=
0
)
{
if
(
ioctl
(
fd
,
TUNSETIFF
,
&
ifr
)
!=
0
)
{
perror
(
"tap_open: ioctl failed"
);
perror
(
"tap_open: ioctl failed"
);
...
@@ -62,7 +68,7 @@ static int tap_open(const char *name) {
...
@@ -62,7 +68,7 @@ static int tap_open(const char *name) {
return
fd
;
return
fd
;
}
}
static
void
d2n_send
(
volatile
struct
SimbricksProtoNet
D2NSend
*
s
)
{
static
void
d2n_send
(
volatile
struct
SimbricksProtoNet
MsgPacket
*
s
)
{
#ifdef DEBUG_PKTMETA
#ifdef DEBUG_PKTMETA
printf
(
"sent packet: len=%u
\n
"
,
s
->
len
);
printf
(
"sent packet: len=%u
\n
"
,
s
->
len
);
#endif
#endif
...
@@ -73,40 +79,41 @@ static void d2n_send(volatile struct SimbricksProtoNetD2NSend *s) {
...
@@ -73,40 +79,41 @@ static void d2n_send(volatile struct SimbricksProtoNetD2NSend *s) {
}
}
static
void
poll_d2n
(
void
)
{
static
void
poll_d2n
(
void
)
{
volatile
union
SimbricksProtoNet
D2N
*
msg
=
SimbricksNetIf
D2N
Poll
(
&
nsif
,
0
);
volatile
union
SimbricksProtoNet
Msg
*
msg
=
SimbricksNetIf
In
Poll
(
&
nsif
,
0
);
uint8_t
type
;
uint8_t
type
;
/* message not ready */
/* message not ready */
if
(
msg
==
NULL
)
if
(
msg
==
NULL
)
return
;
return
;
type
=
msg
->
dummy
.
own_type
&
SIMBRICKS_PROTO_NET_D2N_MSG_MASK
;
type
=
SimbricksNetIfInType
(
&
nsif
,
msg
)
;
switch
(
type
)
{
switch
(
type
)
{
case
SIMBRICKS_PROTO_NET_
D2N_MSG_SEND
:
case
SIMBRICKS_PROTO_NET_
MSG_PACKET
:
d2n_send
(
&
msg
->
send
);
d2n_send
(
&
msg
->
packet
);
break
;
break
;
default:
default:
fprintf
(
stderr
,
"poll_d2n: unsupported type=%u
\n
"
,
type
);
fprintf
(
stderr
,
"poll_d2n: unsupported type=%u
\n
"
,
type
);
}
}
SimbricksNetIf
D2N
Done
(
&
nsif
,
msg
);
SimbricksNetIf
In
Done
(
&
nsif
,
msg
);
}
}
static
void
*
rx_handler
(
void
*
arg
)
{
static
void
*
rx_handler
(
void
*
arg
)
{
volatile
union
SimbricksProtoNet
N2D
*
msg
;
volatile
union
SimbricksProtoNet
Msg
*
msg
;
volatile
struct
SimbricksProtoNet
N2DRecv
*
rx
;
volatile
struct
SimbricksProtoNet
MsgPacket
*
rx
;
ssize_t
len
;
ssize_t
len
;
while
(
1
)
{
while
(
1
)
{
msg
=
SimbricksNetIf
N2D
Alloc
(
&
nsif
,
0
,
0
);
msg
=
SimbricksNetIf
Out
Alloc
(
&
nsif
,
0
);
if
(
msg
==
NULL
)
{
if
(
msg
==
NULL
)
{
fprintf
(
stderr
,
"coudl not allocate message for rx
\n
"
);
fprintf
(
stderr
,
"coudl not allocate message for rx
\n
"
);
abort
();
abort
();
}
}
rx
=
&
msg
->
recv
;
rx
=
&
msg
->
packet
;
len
=
read
(
tap_fd
,
(
void
*
)
rx
->
data
,
nsif
.
n2d_elen
-
sizeof
(
*
msg
));
len
=
read
(
tap_fd
,
(
void
*
)
rx
->
data
,
SimbricksBaseIfOutMsgLen
(
&
nsif
.
base
)
-
sizeof
(
*
msg
));
if
(
len
<=
0
)
{
if
(
len
<=
0
)
{
perror
(
"rx handler: read failed"
);
perror
(
"rx handler: read failed"
);
}
}
...
@@ -116,9 +123,7 @@ static void *rx_handler(void *arg) {
...
@@ -116,9 +123,7 @@ static void *rx_handler(void *arg) {
printf
(
"received packet: len=%u
\n
"
,
rx
->
len
);
printf
(
"received packet: len=%u
\n
"
,
rx
->
len
);
#endif
#endif
// WMB();
SimbricksNetIfOutSend
(
&
nsif
,
msg
,
SIMBRICKS_PROTO_NET_MSG_PACKET
);
rx
->
own_type
=
SIMBRICKS_PROTO_NET_N2D_MSG_RECV
|
SIMBRICKS_PROTO_NET_N2D_OWN_DEV
;
}
}
}
}
...
@@ -134,8 +139,11 @@ int main(int argc, char *argv[]) {
...
@@ -134,8 +139,11 @@ int main(int argc, char *argv[]) {
return
-
1
;
return
-
1
;
}
}
struct
SimbricksBaseIfParams
params
;
SimbricksNetIfDefaultParams
(
&
params
);
sync
=
0
;
sync
=
0
;
if
(
SimbricksNetIfInit
(
&
nsif
,
argv
[
2
],
&
sync
)
!=
0
)
{
if
(
SimbricksNetIfInit
(
&
nsif
,
&
params
,
argv
[
2
],
&
sync
)
!=
0
)
{
close
(
tap_fd
);
close
(
tap_fd
);
return
-
1
;
return
-
1
;
}
}
...
...
sims/net/tap/rules.mk
View file @
4d0690d1
...
@@ -28,7 +28,7 @@ OBJS := $(d)net_tap.o
...
@@ -28,7 +28,7 @@ OBJS := $(d)net_tap.o
$(OBJS)
:
CPPFLAGS := $(CPPFLAGS) -I$(d)include/
$(OBJS)
:
CPPFLAGS := $(CPPFLAGS) -I$(d)include/
$(bin_net_tap)
:
$(OBJS) $(lib_netif) -lpcap -lpthread
$(bin_net_tap)
:
$(OBJS) $(lib_netif)
$(lib_base)
-lpcap -lpthread
CLEAN
:=
$(bin_net_tap)
$(OBJS)
CLEAN
:=
$(bin_net_tap)
$(OBJS)
ALL
:=
$(bin_net_tap)
ALL
:=
$(bin_net_tap)
...
...
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