-
Notifications
You must be signed in to change notification settings - Fork 0
/
ns3-dce.patch
268 lines (252 loc) · 8 KB
/
ns3-dce.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
diff --git a/model/dce-fd.cc b/model/dce-fd.cc
index 708ef69..65194f9 100644
--- a/model/dce-fd.cc
+++ b/model/dce-fd.cc
@@ -853,3 +853,41 @@ int dce_fsync (int fd)
NS_LOG_FUNCTION (current << UtilsGetNodeId () << fd);
OPENED_FD_METHOD (int, Fsync ())
}
+int dce_dprintf(int fd, const char *f, ...)
+{
+ Thread *current = Current ();
+ NS_LOG_FUNCTION (current << UtilsGetNodeId () << fd << f);
+ NS_ASSERT (current != 0);
+
+ char *s = NULL;
+ va_list vl;
+ va_start (vl, f);
+ int r = vasprintf(&s, f, vl);
+ va_end (vl);
+
+ if (r != -1) {
+ std::map < int,FileUsage * > ::iterator it = current->process->openFiles.find (fd);
+ if (current->process->openFiles.end () == it)
+ {
+ current->err = EBADF;
+ return -1;
+ }
+ FileUsage *fu = it->second;
+ if (fu->IsClosed ())
+ {
+ current->err = EBADF;
+ return -1;
+ }
+ UnixFd *unixFd = fu->GetFileInc ();
+ int r = unixFd->Write(s, strlen(s));
+ if (fu && fu->DecUsage ())
+ {
+ current->process->openFiles.erase (fd);
+ delete fu;
+ fu = 0;
+ }
+ free(s);
+ }
+
+ return r;
+}
diff --git a/model/dce-poll.cc b/model/dce-poll.cc
index 0cac665..e130fed 100644
--- a/model/dce-poll.cc
+++ b/model/dce-poll.cc
@@ -15,6 +15,17 @@ NS_LOG_COMPONENT_DEFINE ("DcePollSelect");
using namespace ns3;
+long int dce___fdelt_chk(long int d)
+{
+ if (d < 0 || d >= FD_SETSIZE) {
+ fprintf(stderr, "fdelt_chk: buffer overflow detected\n");
+ fflush(stderr);
+ exit(-1);
+ }
+
+ return d / __NFDBITS;
+}
+
int dce_poll (struct pollfd *fds, nfds_t nfds, int timeout)
{
int count = -1;
@@ -208,6 +219,7 @@ int dce_select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
if (timeout)
{
+ if (timeout->tv_sec == 0 && timeout->tv_usec > 0 && timeout->tv_usec < 1000) { timeout->tv_usec = 1000; }
pollTo = timeout->tv_sec * 1000 + timeout->tv_usec / 1000;
}
diff --git a/model/dce-stdlib.cc b/model/dce-stdlib.cc
index 162c512..8a0b4ff 100644
--- a/model/dce-stdlib.cc
+++ b/model/dce-stdlib.cc
@@ -108,7 +108,6 @@ int dce_mkstemp (char *temp)
if (realFd == -1)
{
current->err = errno;
- delete c_fullpath;
return -1;
}
@@ -116,7 +115,6 @@ int dce_mkstemp (char *temp)
if (fd == -1)
{
current->err = EMFILE;
- delete c_fullpath;
return -1;
}
UnixFd *unixFd = 0;
@@ -125,7 +123,6 @@ int dce_mkstemp (char *temp)
current->process->openFiles[fd] = new FileUsage (fd, unixFd);
strncpy (temp, &c_fullpath[strlen(c_fullpath)-strlen(temp)], strlen(temp));
- delete c_fullpath;
return fd;
}
diff --git a/model/dce-stdlib.h b/model/dce-stdlib.h
index ab30172..401b228 100644
--- a/model/dce-stdlib.h
+++ b/model/dce-stdlib.h
@@ -26,6 +26,7 @@ int dce_clearenv (void);
int dce_mkstemp (char *temp);
FILE * dce_tmpfile(void);
int dce_rename (const char *oldpath, const char *newpath);
+int dce_dprintf(int fd, const char *format, ...);
#ifdef __cplusplus
}
diff --git a/model/libc-dce.cc b/model/libc-dce.cc
index f130ec5..492e46e 100644
--- a/model/libc-dce.cc
+++ b/model/libc-dce.cc
@@ -120,7 +120,7 @@ extern int (*__gxx_personality_v0)(int a, int b,
// extern int __gxx_personality_v0 (int a, int b,
// unsigned c, struct _Unwind_Exception *d, struct _Unwind_Context *e);
// extern int __xpg_strerror_r (int __errnum, char *__buf, size_t __buflen);
-extern int __xpg_strerror_r (int __errnum, char *__buf, size_t __buflen);
+// extern int __xpg_strerror_r (int __errnum, char *__buf, size_t __buflen);
// from glibc's string.h
extern char * __strcpy_chk (char *__restrict __dest,
diff --git a/model/libc-ns3.h b/model/libc-ns3.h
index 3294921..3d32422 100644
--- a/model/libc-ns3.h
+++ b/model/libc-ns3.h
@@ -49,9 +49,9 @@
// // not really a libc function, but we still need to get pointer from DCE to this function
NATIVE (dce_global_variables_setup)
-// Not sure where it is defined and implemented
-// NATIVE (__xpg_strerror_r)
-
+// Let's go crazy
+NATIVE (syscall)
+DCE (__fdelt_chk)
DCE (__cxa_finalize)
DCE (__cxa_atexit)
@@ -124,7 +124,7 @@ NATIVE (bzero)
NATIVE_WITH_ALIAS2 (explicit_bzero, __explicit_bzero_chk)
#endif /* HAVE___EXPLICIT_BZERO */
NATIVE (strerror)
-NATIVE (strerror_r)
+NATIVE_WITH_ALIAS2 (strerror_r, __xpg_strerror_r)
NATIVE (strcoll)
NATIVE (memset)
NATIVE (memcpy)
@@ -135,7 +135,7 @@ NATIVE (memmove)
NATIVE_EXPLICIT (memchr, void * (*)(void *, int, size_t))
NATIVE_EXPLICIT (memrchr, void * (*)(void *, int, size_t))
NATIVE (strcpy)
-NATIVE (strncpy)
+NATIVE_WITH_ALIAS2 (strncpy, __strncpy_chk)
NATIVE (__stpncpy)
NATIVE (strcat)
NATIVE (strncat)
@@ -159,7 +159,6 @@ NATIVE_EXPLICIT (strtok_r, char * (*)(char *, const char *, char **))
NATIVE (strsep)
NATIVE (strsignal)
-
// LOCALE.H
DCE (setlocale)
NATIVE_WITH_ALIAS (newlocale)
@@ -334,7 +333,7 @@ NATIVE (fprintf)
NATIVE (sprintf)
DCE (asprintf)
DCE (vasprintf)
-NATIVE (dprintf)
+DCE (dprintf)
NATIVE (vdprintf)
DCE_WITH_ALIAS2 (fgetc,fgetc_unlocked)
NATIVE (getc)
diff --git a/model/libc.h b/model/libc.h
index 264a5c4..f192bb7 100644
--- a/model/libc.h
+++ b/model/libc.h
@@ -4,6 +4,7 @@
#include <stdarg.h>
#define _SYS_SELECT_H
#include <sys/types.h>
+#include <bits/select2.h>
#undef _SYS_SELECT_H
struct Libc
diff --git a/model/sys/dce-select.h b/model/sys/dce-select.h
index d695242..07b8538 100644
--- a/model/sys/dce-select.h
+++ b/model/sys/dce-select.h
@@ -10,6 +10,7 @@ extern "C" {
int dce_select (int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout);
+long int dce___fdelt_chk (long int __d);
#ifdef __cplusplus
}
#endif
diff --git a/wutils.py b/wutils.py
index 1455196..9a8a5a9 100644
--- a/wutils.py
+++ b/wutils.py
@@ -146,7 +146,7 @@ def run_argv(argv, env, os_env=None, cwd=None, force_no_valgrind=False):
raise WafError("Options --command-template and --valgrind are conflicting")
if not env['VALGRIND']:
raise WafError("valgrind is not installed")
- argv = [env['VALGRIND'], "--leak-check=full", "--show-reachable=yes", "--error-exitcode=1"] + argv
+ argv = [''.join(env['VALGRIND']), "--leak-check=full", "--show-reachable=yes", "--error-exitcode=1"] + argv
proc = subprocess.Popen(argv, env=proc_env, cwd=cwd, stderr=subprocess.PIPE)
error = False
for line in proc.stderr:
diff --git a/model/unix-datagram-socket-fd.cc b/model/unix-datagram-socket-fd.cc
index 5aca622..cea520c 100644
--- a/model/unix-datagram-socket-fd.cc
+++ b/model/unix-datagram-socket-fd.cc
@@ -260,6 +260,14 @@ UnixDatagramSocketFd::DoRecvmsg (struct msghdr *msg, int flags)
}
}
+ if (m_socket->IsIpRecvTos()) {
+ SocketIpTosTag ipTosTag;
+ bool isTagPresent = packet->PeekPacketTag(ipTosTag);
+ if (isTagPresent) {
+ int tos = ipTosTag.GetTos();
+ cmsg.Add(SOL_IP, IP_TOS, sizeof(int), (const uint8_t*) &tos);
+ }
+ }
cmsg.Finish ();
}
diff --git a/model/unix-socket-fd.cc b/model/unix-socket-fd.cc
index 4f66419..6b16b79 100644
--- a/model/unix-socket-fd.cc
+++ b/model/unix-socket-fd.cc
@@ -387,6 +387,26 @@ UnixSocketFd::Setsockopt (int level, int optname,
int *v = (int*)optval;
m_socket->SetRecvPktInfo (*v ? true : false);
} break;
+ case IP_TOS:
+ {
+ if (optlen != sizeof (int))
+ {
+ current->err = EINVAL;
+ return -1;
+ }
+ int *v = (int *)optval;
+ m_socket->SetIpTos((uint8_t) *v);
+ } break;
+ case IP_RECVTOS:
+ {
+ if (optlen != sizeof (int))
+ {
+ current->err = EINVAL;
+ return -1;
+ }
+ int *v = (int *)optval;
+ m_socket->SetIpRecvTos(*v ? true : false);
+ } break;
default:
NS_LOG_WARN ("Unsupported setsockopt requested. level: SOL_IP, optname: " << optname);
break;