Skip to content

Commit b2f2178

Browse files
authored
Merge branch 'apache:master' into ostest
2 parents d3419a9 + 2b0a4a2 commit b2f2178

File tree

23 files changed

+586
-248
lines changed

23 files changed

+586
-248
lines changed

examples/buttons/buttons_main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,11 @@ static int button_daemon(int argc, char *argv[])
219219
goto errout_with_fd;
220220
}
221221

222+
#ifdef CONFIG_ENABLE_ALL_SIGNALS
222223
/* Ignore the default signal action */
223224

224225
signal(CONFIG_EXAMPLES_BUTTONS_SIGNO, SIG_IGN);
226+
#endif /* CONFIG_ENABLE_ALL_SIGNALS */
225227
#endif
226228

227229
/* Now loop forever, waiting BUTTONs events */

examples/chrono/chrono_main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,11 @@ static int chrono_daemon(int argc, char *argv[])
165165
goto errout_with_fd;
166166
}
167167

168+
#ifdef CONFIG_ENABLE_ALL_SIGNALS
168169
/* Ignore the default signal action */
169170

170171
signal(BUTTON_SIGNO, SIG_IGN);
172+
#endif
171173

172174
/* Now loop forever, waiting BUTTONs events */
173175

graphics/libyuv/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ if(CONFIG_LIBYUV)
4141
FetchContent_GetProperties(libyuv_fetch)
4242

4343
if(NOT libyuv_fetch_POPULATED)
44-
FetchContent_Populate(llibyuv_fetch)
44+
FetchContent_Populate(libyuv_fetch)
4545
endif()
4646
endif()
4747

include/netutils/netlib.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@
5656
#include <nuttx/net/netdev.h>
5757
#include <nuttx/net/netconfig.h>
5858

59+
#ifdef CONFIG_NET_IPTABLES
60+
# include <nuttx/net/netfilter/ip_tables.h>
61+
# include <nuttx/net/netfilter/ip6_tables.h>
62+
#endif
63+
5964
/****************************************************************************
6065
* Pre-processor Definitions
6166
****************************************************************************/

netutils/dhcpc/dhcpc.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,16 @@ static void *dhcpc_run(void *args)
533533
struct dhcpc_state result;
534534
int ret;
535535

536+
#ifndef CONFIG_ENABLE_ALL_SIGNALS
537+
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
538+
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
539+
#endif
540+
536541
while (1)
537542
{
543+
#ifndef CONFIG_ENABLE_ALL_SIGNALS
544+
pthread_testcancel();
545+
#endif
538546
ret = dhcpc_request(pdhcpc, &result);
539547
if (ret == OK)
540548
{
@@ -701,7 +709,9 @@ void dhcpc_close(FAR void *handle)
701709
void dhcpc_cancel(FAR void *handle)
702710
{
703711
struct dhcpc_state_s *pdhcpc = (struct dhcpc_state_s *)handle;
712+
#ifdef CONFIG_ENABLE_ALL_SIGNALS
704713
sighandler_t old;
714+
#endif
705715
int ret;
706716

707717
if (pdhcpc)
@@ -710,6 +720,7 @@ void dhcpc_cancel(FAR void *handle)
710720

711721
if (pdhcpc->thread)
712722
{
723+
#ifdef CONFIG_ENABLE_ALL_SIGNALS
713724
old = signal(SIGQUIT, SIG_IGN);
714725

715726
/* Signal the dhcpc_run */
@@ -719,6 +730,9 @@ void dhcpc_cancel(FAR void *handle)
719730
{
720731
nerr("ERROR: pthread_kill DHCPC thread\n");
721732
}
733+
#else
734+
pthread_cancel(pdhcpc->thread);
735+
#endif
722736

723737
/* Wait for the end of dhcpc_run */
724738

@@ -729,7 +743,9 @@ void dhcpc_cancel(FAR void *handle)
729743
}
730744

731745
pdhcpc->thread = 0;
746+
#ifdef CONFIG_ENABLE_ALL_SIGNALS
732747
signal(SIGQUIT, old);
748+
#endif
733749
}
734750
}
735751
}

netutils/dhcpd/dhcpd.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1555,13 +1555,15 @@ static pid_t dhcpd_get_pid(void)
15551555
*
15561556
****************************************************************************/
15571557

1558+
#ifdef CONFIG_ENABLE_ALL_SIGNALS
15581559
static void
15591560
dhcpd_signal_handler(int signo, FAR siginfo_t *info, FAR void *ctx)
15601561
{
15611562
/* Set global flag to indicate stop request */
15621563

15631564
g_dhcpd_daemon.ds_state = DHCPD_STOP_REQUESTED;
15641565
}
1566+
#endif
15651567

15661568
/****************************************************************************
15671569
* Public Functions
@@ -1573,7 +1575,9 @@ dhcpd_signal_handler(int signo, FAR siginfo_t *info, FAR void *ctx)
15731575

15741576
int dhcpd_run(FAR const char *interface)
15751577
{
1578+
#ifdef CONFIG_ENABLE_ALL_SIGNALS
15761579
struct sigaction act;
1580+
#endif
15771581
int sockfd = -1;
15781582
int nbytes;
15791583

@@ -1602,11 +1606,12 @@ int dhcpd_run(FAR const char *interface)
16021606

16031607
/* Install signal handler for CONFIG_NETUTILS_DHCPD_SIGWAKEUP */
16041608

1609+
#ifdef CONFIG_ENABLE_ALL_SIGNALS
16051610
memset(&act, 0, sizeof(act));
16061611
act.sa_sigaction = dhcpd_signal_handler;
16071612
act.sa_flags = SA_SIGINFO;
16081613
sigaction(CONFIG_NETUTILS_DHCPD_SIGWAKEUP, &act, NULL);
1609-
1614+
#endif
16101615
/* Indicate that we have started */
16111616

16121617
g_dhcpd_daemon.ds_state = DHCPD_RUNNING;

netutils/ping/icmp_ping.c

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
#include <nuttx/clock.h>
4747
#include <nuttx/net/icmp.h>
48+
#include <nuttx/net/ip.h>
4849

4950
#include "netutils/icmp_ping.h"
5051

@@ -64,7 +65,6 @@ struct ping_priv_s
6465
{
6566
struct sockaddr_in destaddr;
6667
struct sockaddr_in fromaddr;
67-
struct icmp_hdr_s outhdr;
6868
struct pollfd recvfd;
6969
socklen_t addrlen;
7070
clock_t kickoff;
@@ -74,6 +74,7 @@ struct ping_priv_s
7474
long elapsed;
7575
bool retry;
7676
int sockfd;
77+
struct icmp_hdr_s outhdr;
7778
};
7879

7980
/****************************************************************************
@@ -91,6 +92,7 @@ static volatile bool g_exiting;
9192
* Private Functions
9293
****************************************************************************/
9394

95+
#ifdef CONFIG_ENABLE_ALL_SIGNALS
9496
/****************************************************************************
9597
* Name: sigexit
9698
****************************************************************************/
@@ -99,6 +101,7 @@ static void sigexit(int signo)
99101
{
100102
g_exiting = true;
101103
}
104+
#endif
102105

103106
/****************************************************************************
104107
* Name: ping_newid
@@ -179,6 +182,31 @@ static void icmp_callback(FAR struct ping_result_s *result,
179182
result->info->callback(result);
180183
}
181184

185+
/****************************************************************************
186+
* Name: icmp_checksum
187+
****************************************************************************/
188+
189+
static uint16_t icmp_checksum(FAR const void *buffer, size_t datalen)
190+
{
191+
FAR const uint16_t *wptr = (FAR const uint16_t *)buffer;
192+
size_t words = (sizeof(struct icmp_hdr_s) + datalen + 1) / 2;
193+
uint32_t sum = 0;
194+
size_t i;
195+
196+
for (i = 0; i < words; i++)
197+
{
198+
sum += *wptr++;
199+
if (sum & 0x80000000)
200+
{
201+
sum = (sum & 0XFFFF) + (sum >> 16);
202+
}
203+
}
204+
205+
sum = (sum >> 16) + (sum & 0XFFFF);
206+
sum += (sum >> 16);
207+
return (uint16_t)(~sum);
208+
}
209+
182210
/****************************************************************************
183211
* Public Functions
184212
****************************************************************************/
@@ -194,12 +222,15 @@ void icmp_ping(FAR const struct ping_info_s *info)
194222
FAR struct icmp_hdr_s *inhdr;
195223
FAR uint8_t *iobuffer;
196224
FAR uint8_t *ptr;
225+
int recvlen;
197226
int ret;
198227
int ch;
199228
int i;
200229

201230
g_exiting = false;
231+
#ifdef CONFIG_ENABLE_ALL_SIGNALS
202232
signal(SIGINT, sigexit);
233+
#endif
203234

204235
/* Initialize result structure */
205236

@@ -215,16 +246,17 @@ void icmp_ping(FAR const struct ping_info_s *info)
215246

216247
/* Allocate memory to hold private data and ping buffer */
217248

218-
priv = malloc(sizeof(*priv) + result.outsize);
249+
priv = malloc(sizeof(*priv) + sizeof(struct ipv4_hdr_s) + result.outsize);
250+
219251
if (priv == NULL)
220252
{
221253
icmp_callback(&result, ICMP_E_MEMORY, 0);
222254
return;
223255
}
224256

225-
iobuffer = (FAR uint8_t *)(priv + 1);
257+
iobuffer = (FAR uint8_t *)(&priv->outhdr);
226258

227-
priv->sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP);
259+
priv->sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
228260
if (priv->sockfd < 0)
229261
{
230262
icmp_callback(&result, ICMP_E_SOCKET, errno);
@@ -253,11 +285,6 @@ void icmp_ping(FAR const struct ping_info_s *info)
253285
priv->destaddr.sin_port = 0;
254286
priv->destaddr.sin_addr.s_addr = result.dest.s_addr;
255287

256-
memset(&priv->outhdr, 0, sizeof(struct icmp_hdr_s));
257-
priv->outhdr.type = ICMP_ECHO_REQUEST;
258-
priv->outhdr.id = htons(result.id);
259-
priv->outhdr.seqno = htons(result.seqno);
260-
261288
icmp_callback(&result, ICMP_I_BEGIN, 0);
262289

263290
while (result.nrequests < info->count)
@@ -267,9 +294,10 @@ void icmp_ping(FAR const struct ping_info_s *info)
267294
break;
268295
}
269296

270-
/* Copy the ICMP header into the I/O buffer */
271-
272-
memcpy(iobuffer, &priv->outhdr, sizeof(struct icmp_hdr_s));
297+
memset(&priv->outhdr, 0, sizeof(struct icmp_hdr_s));
298+
priv->outhdr.type = ICMP_ECHO_REQUEST;
299+
priv->outhdr.id = htons(result.id);
300+
priv->outhdr.seqno = htons(result.seqno);
273301

274302
/* Add some easily verifiable payload data */
275303

@@ -285,6 +313,10 @@ void icmp_ping(FAR const struct ping_info_s *info)
285313
}
286314
}
287315

316+
/* Calculate checksum after data padding */
317+
318+
priv->outhdr.icmpchksum = icmp_checksum(iobuffer, info->datalen);
319+
288320
priv->start = clock();
289321
result.nrequests++;
290322
priv->nsent = sendto(priv->sockfd, iobuffer, result.outsize, 0,
@@ -330,9 +362,10 @@ void icmp_ping(FAR const struct ping_info_s *info)
330362

331363
/* Get the ICMP response (ignoring the sender) */
332364

365+
recvlen = sizeof(struct ipv4_hdr_s) + result.outsize;
333366
priv->addrlen = sizeof(struct sockaddr_in);
334367
priv->nrecvd = recvfrom(priv->sockfd, iobuffer,
335-
result.outsize, 0,
368+
recvlen, 0,
336369
(FAR struct sockaddr *)&priv->fromaddr,
337370
&priv->addrlen);
338371
if (priv->nrecvd < 0)
@@ -346,8 +379,11 @@ void icmp_ping(FAR const struct ping_info_s *info)
346379
goto wait;
347380
}
348381

382+
/* Skip IP header, IP header length including options */
383+
349384
priv->elapsed = TICK2USEC(clock() - priv->start);
350-
inhdr = (FAR struct icmp_hdr_s *)iobuffer;
385+
inhdr = (FAR struct icmp_hdr_s *)
386+
(iobuffer + sizeof(struct ipv4_hdr_s));
351387

352388
if (inhdr->type == ICMP_ECHO_REPLY)
353389
{
@@ -379,16 +415,17 @@ void icmp_ping(FAR const struct ping_info_s *info)
379415

380416
/* Verify the payload data */
381417

382-
if (priv->nrecvd != result.outsize)
418+
if (priv->nrecvd != recvlen)
383419
{
384420
icmp_callback(&result, ICMP_W_RECVBIG, priv->nrecvd);
385421
verified = false;
386422
}
387423
else
388424
{
389-
ptr = &iobuffer[sizeof(struct icmp_hdr_s)];
390-
ch = 0x20;
425+
/* Data start offset: IP header + ICMP header */
391426

427+
ptr = (FAR uint8_t *)(inhdr + 1);
428+
ch = 0x20;
392429
for (i = 0; i < info->datalen; i++, ptr++)
393430
{
394431
if (*ptr != ch)

netutils/telnetd/telnetd_daemon.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ int telnetd_daemon(FAR const struct telnetd_config_s *config)
7474
#endif
7575
} addr;
7676

77-
#ifdef CONFIG_SCHED_HAVE_PARENT
77+
#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_ENABLE_ALL_SIGNALS)
7878
struct sigaction sa;
7979
sigset_t blockset;
8080
#endif
@@ -85,7 +85,7 @@ int telnetd_daemon(FAR const struct telnetd_config_s *config)
8585
int optval;
8686
#endif
8787

88-
#ifdef CONFIG_SCHED_HAVE_PARENT
88+
#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_ENABLE_ALL_SIGNALS)
8989
/* Call sigaction with the SA_NOCLDWAIT flag so that we do not transform
9090
* children into "zombies" when they terminate: Child exit status will
9191
* not be retained.
@@ -113,7 +113,7 @@ int telnetd_daemon(FAR const struct telnetd_config_s *config)
113113
nerr("ERROR: sigprocmask failed: %d\n", errno);
114114
goto errout;
115115
}
116-
#endif /* CONFIG_SCHED_HAVE_PARENT */
116+
#endif /* CONFIG_SCHED_HAVE_PARENT && CONFIG_ENABLE_ALL_SIGNALS */
117117

118118
/* Create a new TCP socket to use to listen for connections */
119119

0 commit comments

Comments
 (0)