Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Packetdrill_tarr_ext
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stefan Gense
Packetdrill_tarr_ext
Commits
d22cbc18
Commit
d22cbc18
authored
9 years ago
by
Julian Cordes
Browse files
Options
Downloads
Patches
Plain Diff
first impl of os specific ifdefs in lexer
parent
ceb1a101
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gtests/net/packetdrill/lexer.l
+78
-0
78 additions, 0 deletions
gtests/net/packetdrill/lexer.l
gtests/net/packetdrill/tests/bsd/sctp/ifdef_testcase.pkt
+26
-0
26 additions, 0 deletions
gtests/net/packetdrill/tests/bsd/sctp/ifdef_testcase.pkt
with
104 additions
and
0 deletions
gtests/net/packetdrill/lexer.l
+
78
−
0
View file @
d22cbc18
...
@@ -103,6 +103,63 @@ static s64 hextol(const char *s)
...
@@ -103,6 +103,63 @@ static s64 hextol(const char *s)
return strtol(yytext + 2, NULL, 16);
return strtol(yytext + 2, NULL, 16);
}
}
enum ifdef_os {
Linux_IFDEF = 1, FreeBSD_IFDEF, NetBSD_IFDEF
};
#define MAX_IFDEF_DEPTH 10
YY_BUFFER_STATE ifdef_stack[MAX_IFDEF_DEPTH];
int ifdef_stack_ptr = 0;
static void handle_ifdef(enum ifdef_os os, const char *s) {
char *code = strdup(s);
unsigned int ifdef_length = 10;
unsigned int endif_length = 10;
unsigned int os_name_length = 0;
switch (os) {
case Linux_IFDEF:
printf("ifdef linux called:");
os_name_length = 5;
break;
case FreeBSD_IFDEF:
printf("ifdef freebsd called:");
os_name_length = 7;
break;
case NetBSD_IFDEF:
printf("ifdef netbsd called:");
os_name_length = 6;
break;
}
#ifdef linux
if (os != Linux_IFDEF) {
return;
}
#endif
#ifdef __FreeBSD__
if (os != FreeBSD_IFDEF) {
return;
}
#endif
char *code_without_ifdef = code+ifdef_length+os_name_length;
code_without_ifdef[strlen(code_without_ifdef) - (endif_length + os_name_length)] = (char) 0;
// fprintf( stdout, "\n%s\n", code_without_ifdef);
if (ifdef_stack_ptr >= MAX_IFDEF_DEPTH) {
fprintf(stderr, "Ifdefs nested too deeply");
exit(1);
}
ifdef_stack[ifdef_stack_ptr++] = YY_CURRENT_BUFFER;
YY_BUFFER_STATE state = yy_scan_string(code_without_ifdef);
yy_switch_to_buffer(state);
free(code);
}
%}
%}
%{
%{
...
@@ -122,6 +179,13 @@ cpp_comment \/\/[^\n]*\n
...
@@ -122,6 +179,13 @@ cpp_comment \/\/[^\n]*\n
*/
*/
c_comment \/\*(([^*])|(\*[^\/]))*\*\/
c_comment \/\*(([^*])|(\*[^\/]))*\*\/
ifdef_begin __ifdef__
ifdef_end __endif__
ifdef_regex_freebsd {ifdef_begin}FreeBSD(.|\n)*{ifdef_end}FreeBSD
ifdef_regex_linux {ifdef_begin}Linux(.|\n)*{ifdef_end}Linux
/* The regexp for code snippets is analogous to that for C comments.
/* The regexp for code snippets is analogous to that for C comments.
* Here is a summary of the regexp for code snippets:
* Here is a summary of the regexp for code snippets:
* %{
* %{
...
@@ -452,7 +516,21 @@ NULL return NULL_;
...
@@ -452,7 +516,21 @@ NULL return NULL_;
[ \t\n]+ /* ignore whitespace */;
[ \t\n]+ /* ignore whitespace */;
{cpp_comment} /* ignore C++-style comment */;
{cpp_comment} /* ignore C++-style comment */;
{c_comment} /* ignore C-style comment */;
{c_comment} /* ignore C-style comment */;
{ifdef_regex_freebsd} handle_ifdef(FreeBSD_IFDEF, yytext);
{ifdef_regex_linux} handle_ifdef(Linux_IFDEF, yytext);
{code} yylval.string = code(yytext); return CODE;
{code} yylval.string = code(yytext); return CODE;
{ipv4_addr} yylval.string = strdup(yytext); return IPV4_ADDR;
{ipv4_addr} yylval.string = strdup(yytext); return IPV4_ADDR;
{ipv6_addr} yylval.string = strdup(yytext); return IPV6_ADDR;
{ipv6_addr} yylval.string = strdup(yytext); return IPV6_ADDR;
<<EOF>> {
if ( --ifdef_stack_ptr < 0 )
{
yyterminate();
}
else
{
yy_delete_buffer(YY_CURRENT_BUFFER);
yy_switch_to_buffer(ifdef_stack[ifdef_stack_ptr]);
}
}
%%
%%
This diff is collapsed.
Click to expand it.
gtests/net/packetdrill/tests/bsd/sctp/ifdef_testcase.pkt
0 → 100644
+
26
−
0
View file @
d22cbc18
// Create a non-blocking 1-to-1 style socket
0.0 socket(..., SOCK_STREAM, IPPROTO_SCTP) = 3
+0.0 bind(3, ..., ...) = 0
+0.0 fcntl(3, F_GETFL) = 0x02 (flags O_RDWR)
+0.0 fcntl(3, F_SETFL, O_RDWR | O_NONBLOCK) = 0
// Trigger the active associtation setup
+0.1 connect(3, ..., ...) = -1 EINPROGRESS (Operation now in progress)
+0.0 > sctp: INIT[flgs=0, tag=1, a_rwnd=..., os=..., is=..., tsn=0, ...]
+0.0 < sctp: INIT_ACK[flgs=0, tag=2, a_rwnd=1500, os=1, is=1, tsn=1, STATE_COOKIE[len=4, val=...]]
+0.0 > sctp: COOKIE_ECHO[flgs=0, len=4, val=...]
+0.0 < sctp: COOKIE_ACK[flgs=0]
// Check if the setup was sucessful
+0.0 getsockopt(3, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
// inject sack-chunk(type=3) with invalid len=8| cumulative tsn ack |
+0.0 < sctp: CHUNK[type=3, flgs=0, len=8, val=[0x00, 0x00, 0x00, 0x01]]
__ifdef__Linux
// expect protocol violation
+0.0 > sctp: ABORT[flgs=..., PROTOCOL_VIOLATION[info=...]]
__endif__Linux
__ifdef__FreeBSD
+0.0 getsockopt(3, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
+0.0 close(3) = 0
+0.0 > sctp: SHUTDOWN[flgs=0, cum_tsn=0]
+0.1 < sctp: SHUTDOWN_ACK[flgs=0]
+0.0 > sctp: SHUTDOWN_COMPLETE[flgs=0]
__endif__FreeBSD
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment